xref: /illumos-gate/usr/src/uts/common/sys/mac_provider.h (revision 1007fd6fd24227460e77ce89f5ca85641a85a576)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24  */
25 
26 #ifndef	_SYS_MAC_PROVIDER_H
27 #define	_SYS_MAC_PROVIDER_H
28 
29 #include <sys/types.h>
30 #include <sys/ddi.h>
31 #include <sys/sunddi.h>
32 #include <sys/stream.h>
33 #include <sys/mkdev.h>
34 #include <sys/mac.h>
35 #include <sys/mac_flow.h>
36 
37 /*
38  * MAC Provider Interface
39  */
40 
41 #ifdef	__cplusplus
42 extern "C" {
43 #endif
44 
45 /*
46  * MAC version identifiers. Drivers compiled against the stable V1 version
47  * of the API should register with MAC_VERSION_V1. ON drivers should use
48  * MAC_VERSION. This is used by mac_alloc() mac_register() to
49  * verify that incompatible drivers don't register.
50  */
51 #define	MAC_VERSION_V1	0x1
52 #define	MAC_VERSION	MAC_VERSION_V1
53 
54 /*
55  * Possible values for ETHER_STAT_XCVR_INUSE statistic.
56  */
57 
58 #define	XCVR_UNDEFINED		0
59 #define	XCVR_NONE		1
60 #define	XCVR_10			2
61 #define	XCVR_100T4		3
62 #define	XCVR_100X		4
63 #define	XCVR_100T2		5
64 #define	XCVR_1000X		6
65 #define	XCVR_1000T		7
66 
67 #ifdef	_KERNEL
68 
69 /*
70  * Definitions for MAC Drivers Capabilities
71  */
72 /*
73  * MAC layer capabilities.  These capabilities are handled by the drivers'
74  * mc_capab_get() callbacks.  Some capabilities require the driver to fill
75  * in a given data structure, and others are simply boolean capabilities.
76  * Note that capability values must be powers of 2 so that consumers and
77  * providers of this interface can keep track of which capabilities they
78  * care about by keeping a bitfield of these things around somewhere.
79  */
80 typedef enum {
81 	/*
82 	 * Public Capabilities (MAC_VERSION_V1)
83 	 */
84 	MAC_CAPAB_HCKSUM	= 0x00000001, /* data is a uint32_t */
85 	MAC_CAPAB_LSO		= 0x00000008, /* data is mac_capab_lso_t */
86 
87 	/*
88 	 * Reserved capabilities, do not use
89 	 */
90 	MAC_CAPAB_RESERVED1	= 0x00000002,
91 	MAC_CAPAB_RESERVED2	= 0x00000004,
92 
93 	/*
94 	 * Private driver capabilities
95 	 */
96 	MAC_CAPAB_RINGS		= 0x00000010, /* data is mac_capab_rings_t */
97 	MAC_CAPAB_SHARES	= 0x00000020, /* data is mac_capab_share_t */
98 	MAC_CAPAB_MULTIFACTADDR = 0x00000040, /* mac_data_multifactaddr_t */
99 
100 	/*
101 	 * Private driver capabilities for use by the GLDv3 framework only
102 	 */
103 	MAC_CAPAB_VNIC		= 0x00010000, /* data is mac_capab_vnic_t */
104 	MAC_CAPAB_ANCHOR_VNIC	= 0x00020000, /* boolean only, no data */
105 	MAC_CAPAB_AGGR		= 0x00040000, /* data is mac_capab_aggr_t */
106 	MAC_CAPAB_NO_NATIVEVLAN	= 0x00080000, /* boolean only, no data */
107 	MAC_CAPAB_NO_ZCOPY	= 0x00100000, /* boolean only, no data */
108 	MAC_CAPAB_LEGACY	= 0x00200000, /* data is mac_capab_legacy_t */
109 	MAC_CAPAB_VRRP		= 0x00400000  /* data is mac_capab_vrrp_t */
110 } mac_capab_t;
111 
112 /*
113  * LSO capability
114  */
115 typedef struct lso_basic_tcp_ipv4_s {
116 	t_uscalar_t	lso_max;		/* maximum payload */
117 } lso_basic_tcp_ipv4_t;
118 
119 /*
120  * Currently supported flags for LSO.
121  */
122 #define	LSO_TX_BASIC_TCP_IPV4	0x01		/* TCP LSO capability */
123 
124 /*
125  * Future LSO capabilities can be added at the end of the mac_capab_lso_t.
126  * When such capability is added to the GLDv3 framework, the size of the
127  * mac_capab_lso_t it allocates and passes to the drivers increases. Older
128  * drivers wil access only the (upper) sections of that structure, that is the
129  * sections carrying the capabilities they understand. This ensures the
130  * interface can be safely extended in a binary compatible way.
131  */
132 typedef	struct mac_capab_lso_s {
133 	t_uscalar_t		lso_flags;
134 	lso_basic_tcp_ipv4_t	lso_basic_tcp_ipv4;
135 	/* Add future lso capabilities here */
136 } mac_capab_lso_t;
137 
138 /*
139  * Multiple Factory MAC Addresses Capability
140  */
141 typedef struct mac_capab_multifactaddr_s {
142 	/*
143 	 * Number of factory addresses
144 	 */
145 	uint_t		mcm_naddr;
146 
147 	/*
148 	 * Callbacks to query all the factory addresses.
149 	 */
150 	void		(*mcm_getaddr)(void *, uint_t, uint8_t *);
151 } mac_capab_multifactaddr_t;
152 
153 /*
154  * Info and callbacks of legacy devices.
155  */
156 typedef struct mac_capab_legacy_s {
157 	/*
158 	 * Notifications that the legacy device does not support.
159 	 */
160 	uint32_t	ml_unsup_note;
161 	/*
162 	 * dev_t of the legacy device; can be held to force attach.
163 	 */
164 	dev_t		ml_dev;
165 	boolean_t	(*ml_active_set)(void *);
166 	void		(*ml_active_clear)(void *);
167 	int		(*ml_fastpath_disable)(void *);
168 	void		(*ml_fastpath_enable)(void *);
169 } mac_capab_legacy_t;
170 
171 typedef struct __mac_prop_info_handle *mac_prop_info_handle_t;
172 
173 /*
174  * MAC driver entry point types.
175  */
176 typedef int		(*mac_getstat_t)(void *, uint_t, uint64_t *);
177 typedef	int		(*mac_start_t)(void *);
178 typedef void		(*mac_stop_t)(void *);
179 typedef int		(*mac_setpromisc_t)(void *, boolean_t);
180 typedef int		(*mac_multicst_t)(void *, boolean_t, const uint8_t *);
181 typedef int		(*mac_unicst_t)(void *, const uint8_t *);
182 typedef void		(*mac_ioctl_t)(void *, queue_t *, mblk_t *);
183 typedef void		(*mac_resources_t)(void *);
184 typedef mblk_t		*(*mac_tx_t)(void *, mblk_t *);
185 typedef	boolean_t	(*mac_getcapab_t)(void *, mac_capab_t, void *);
186 typedef	int		(*mac_open_t)(void *);
187 typedef void		(*mac_close_t)(void *);
188 typedef	int		(*mac_set_prop_t)(void *, const char *, mac_prop_id_t,
189 			    uint_t, const void *);
190 typedef	int		(*mac_get_prop_t)(void *, const char *, mac_prop_id_t,
191 			    uint_t, void *);
192 typedef void		(*mac_prop_info_t)(void *, const char *, mac_prop_id_t,
193 			    mac_prop_info_handle_t);
194 
195 /*
196  * Driver callbacks. The following capabilities are optional, and if
197  * implemented by the driver, must have a corresponding MC_ flag set
198  * in the mc_callbacks field.
199  *
200  * Any future additions to this list must also be accompanied by an
201  * associated mc_callbacks flag so that the framework can grow without
202  * affecting the binary compatibility of the interface.
203  */
204 typedef struct mac_callbacks_s {
205 	uint_t		mc_callbacks;	/* Denotes which callbacks are set */
206 	mac_getstat_t	mc_getstat;	/* Get the value of a statistic */
207 	mac_start_t	mc_start;	/* Start the device */
208 	mac_stop_t	mc_stop;	/* Stop the device */
209 	mac_setpromisc_t mc_setpromisc;	/* Enable or disable promiscuous mode */
210 	mac_multicst_t	mc_multicst;	/* Enable or disable a multicast addr */
211 	mac_unicst_t	mc_unicst;	/* Set the unicast MAC address */
212 	mac_tx_t	mc_tx;		/* Transmit a packet */
213 	void		*mc_reserved;	/* Reserved, do not use */
214 	mac_ioctl_t	mc_ioctl;	/* Process an unknown ioctl */
215 	mac_getcapab_t	mc_getcapab;	/* Get capability information */
216 	mac_open_t	mc_open;	/* Open the device */
217 	mac_close_t	mc_close;	/* Close the device */
218 	mac_set_prop_t	mc_setprop;
219 	mac_get_prop_t	mc_getprop;
220 	mac_prop_info_t	mc_propinfo;
221 } mac_callbacks_t;
222 
223 /*
224  * Flags for mc_callbacks.  Requiring drivers to set the flags associated
225  * with optional callbacks initialized in the structure allows the mac
226  * module to add optional callbacks in the future without requiring drivers
227  * to recompile.
228  */
229 #define	MC_RESERVED	0x0001
230 #define	MC_IOCTL	0x0002
231 #define	MC_GETCAPAB	0x0004
232 #define	MC_OPEN		0x0008
233 #define	MC_CLOSE	0x0010
234 #define	MC_SETPROP	0x0020
235 #define	MC_GETPROP	0x0040
236 #define	MC_PROPINFO	0x0080
237 #define	MC_PROPERTIES	(MC_SETPROP | MC_GETPROP | MC_PROPINFO)
238 
239 /*
240  * Virtualization Capabilities
241  */
242 /*
243  * The ordering of entries below is important. MAC_HW_CLASSIFIER
244  * is the cutoff below which are entries which don't depend on
245  * H/W. MAC_HW_CLASSIFIER and entries after that are cases where
246  * H/W has been updated through add/modify/delete APIs.
247  */
248 typedef enum {
249 	MAC_NO_CLASSIFIER = 0,
250 	MAC_SW_CLASSIFIER,
251 	MAC_HW_CLASSIFIER
252 } mac_classify_type_t;
253 
254 typedef	void	(*mac_rx_func_t)(void *, mac_resource_handle_t, mblk_t *,
255     boolean_t);
256 
257 /*
258  * The virtualization level conveys the extent of the NIC hardware assistance
259  * for traffic steering employed for virtualization:
260  *
261  * MAC_VIRT_NONE:	No assist for v12n.
262  *
263  * MAC_VIRT_LEVEL1:	Multiple Rx rings with MAC address level
264  *			classification between groups of rings.
265  *			Requires the support of the MAC_CAPAB_RINGS
266  *			capability.
267  *
268  * MAC_VIRT_HIO:	Hybrid I/O capable MAC. Require the support
269  *			of the MAC_CAPAB_SHARES capability.
270  */
271 #define	MAC_VIRT_NONE		0x0
272 #define	MAC_VIRT_LEVEL1		0x1
273 #define	MAC_VIRT_HIO		0x2
274 
275 typedef enum {
276 	MAC_RING_TYPE_RX = 1,	/* Receive ring */
277 	MAC_RING_TYPE_TX	/* Transmit ring */
278 } mac_ring_type_t;
279 
280 /*
281  * Grouping type of a ring group
282  *
283  * MAC_GROUP_TYPE_STATIC: The ring group can not be re-grouped.
284  * MAC_GROUP_TYPE_DYNAMIC: The ring group support dynamic re-grouping
285  */
286 typedef enum {
287 	MAC_GROUP_TYPE_STATIC = 1,	/* Static ring group */
288 	MAC_GROUP_TYPE_DYNAMIC		/* Dynamic ring group */
289 } mac_group_type_t;
290 
291 typedef	struct __mac_ring_driver	*mac_ring_driver_t;
292 typedef	struct __mac_group_driver	*mac_group_driver_t;
293 
294 typedef	struct mac_ring_info_s mac_ring_info_t;
295 typedef	struct mac_group_info_s mac_group_info_t;
296 
297 typedef void	(*mac_get_ring_t)(void *, mac_ring_type_t, const int, const int,
298     mac_ring_info_t *, mac_ring_handle_t);
299 typedef void	(*mac_get_group_t)(void *, mac_ring_type_t, const int,
300     mac_group_info_t *, mac_group_handle_t);
301 
302 typedef void	(*mac_group_add_ring_t)(mac_group_driver_t,
303     mac_ring_driver_t, mac_ring_type_t);
304 typedef void	(*mac_group_rem_ring_t)(mac_group_driver_t,
305     mac_ring_driver_t, mac_ring_type_t);
306 
307 /*
308  * Multiple Rings Capability
309  */
310 typedef struct	mac_capab_rings_s {
311 	mac_ring_type_t		mr_type;	/* Ring type: Rx vs Tx */
312 	mac_group_type_t	mr_group_type;	/* Dynamic vs static grouping */
313 	uint_t			mr_rnum;	/* Number of rings */
314 	uint_t			mr_gnum;	/* Number of ring groups */
315 	mac_get_ring_t		mr_rget;	/* Get ring from driver */
316 	mac_get_group_t		mr_gget;	/* Get ring group from driver */
317 	mac_group_add_ring_t	mr_gaddring;	/* Add ring into a group */
318 	mac_group_rem_ring_t	mr_gremring;	/* Remove ring from a group */
319 } mac_capab_rings_t;
320 
321 /*
322  * Common ring functions and driver interfaces
323  */
324 typedef	int	(*mac_ring_start_t)(mac_ring_driver_t, uint64_t);
325 typedef	void	(*mac_ring_stop_t)(mac_ring_driver_t);
326 
327 typedef	mblk_t	*(*mac_ring_send_t)(void *, mblk_t *);
328 typedef	mblk_t	*(*mac_ring_poll_t)(void *, int);
329 
330 typedef int	(*mac_ring_stat_t)(mac_ring_driver_t, uint_t, uint64_t *);
331 
332 typedef struct mac_ring_info_s {
333 	mac_ring_driver_t	mri_driver;
334 	mac_ring_start_t	mri_start;
335 	mac_ring_stop_t		mri_stop;
336 	mac_intr_t		mri_intr;
337 	union {
338 		mac_ring_send_t	send;
339 		mac_ring_poll_t	poll;
340 	} mrfunion;
341 	mac_ring_stat_t		mri_stat;
342 	/*
343 	 * mri_flags will have some bits set to indicate some special
344 	 * property/feature of a ring like serialization needed for a
345 	 * Tx ring or packets should always need enqueuing on Rx side,
346 	 * etc.
347 	 */
348 	uint_t			mri_flags;
349 } mac_ring_info_s;
350 
351 #define	mri_tx			mrfunion.send
352 #define	mri_poll		mrfunion.poll
353 
354 /*
355  * #defines for mri_flags. The flags are temporary flags that are provided
356  * only to workaround issues in specific drivers, and they will be
357  * removed in the future.
358  */
359 #define	MAC_RING_TX_SERIALIZE		0x1
360 #define	MAC_RING_RX_ENQUEUE		0x2
361 
362 typedef	int	(*mac_group_start_t)(mac_group_driver_t);
363 typedef	void	(*mac_group_stop_t)(mac_group_driver_t);
364 typedef	int	(*mac_add_mac_addr_t)(void *, const uint8_t *);
365 typedef	int	(*mac_rem_mac_addr_t)(void *, const uint8_t *);
366 
367 struct mac_group_info_s {
368 	mac_group_driver_t	mgi_driver;	/* Driver reference */
369 	mac_group_start_t	mgi_start;	/* Start the group */
370 	mac_group_stop_t	mgi_stop;	/* Stop the group */
371 	uint_t			mgi_count;	/* Count of rings */
372 	mac_intr_t		mgi_intr;	/* Optional per-group intr */
373 
374 	/* Only used for rx groups */
375 	mac_add_mac_addr_t	mgi_addmac;	/* Add a MAC address */
376 	mac_rem_mac_addr_t	mgi_remmac;	/* Remove a MAC address */
377 };
378 
379 /*
380  * Share management functions.
381  */
382 typedef uint64_t mac_share_handle_t;
383 
384 /*
385  * Allocate and free a share. Returns ENOSPC if all shares have been
386  * previously allocated.
387  */
388 typedef int (*mac_alloc_share_t)(void *, mac_share_handle_t *);
389 typedef void (*mac_free_share_t)(mac_share_handle_t);
390 
391 /*
392  * Bind and unbind a share. Binding a share allows a domain
393  * to have direct access to the groups and rings associated with
394  * that share.
395  */
396 typedef int (*mac_bind_share_t)(mac_share_handle_t, uint64_t, uint64_t *);
397 typedef void (*mac_unbind_share_t)(mac_share_handle_t);
398 
399 /*
400  * Return information on about a share.
401  */
402 typedef void (*mac_share_query_t)(mac_share_handle_t, mac_ring_type_t,
403     mac_ring_handle_t *, uint_t *);
404 
405 /*
406  * Basic idea, bind previously created ring groups to shares
407  * for them to be exported (or shared) by another domain.
408  * These interfaces bind/unbind the ring group to a share.
409  * The groups and their rings will be shared with the guest
410  * as soon as the share is bound.
411  */
412 typedef int (*mac_share_add_group_t)(mac_share_handle_t,
413     mac_group_driver_t);
414 typedef int (*mac_share_rem_group_t)(mac_share_handle_t,
415     mac_group_driver_t);
416 
417 typedef struct  mac_capab_share_s {
418 	uint_t			ms_snum;	/* Number of shares (vr's) */
419 	void			*ms_handle;	/* Handle to driver. */
420 	mac_alloc_share_t	ms_salloc;	/* Get a share from driver. */
421 	mac_free_share_t	ms_sfree;	/* Return a share to driver. */
422 	mac_share_add_group_t	ms_sadd;	/* Add a group to the share. */
423 	mac_share_rem_group_t	ms_sremove;	/* Remove group from share. */
424 	mac_share_query_t	ms_squery;	/* Query share constraints */
425 	mac_bind_share_t	ms_sbind;	/* Bind a share */
426 	mac_unbind_share_t	ms_sunbind;	/* Unbind a share */
427 } mac_capab_share_t;
428 
429 typedef struct mac_capab_vrrp_s {
430 	/* IPv6 or IPv4? */
431 	int		mcv_af;
432 } mac_capab_vrrp_t;
433 
434 /*
435  * MAC registration interface
436  */
437 typedef struct mac_register_s {
438 	uint_t			m_version;	/* set by mac_alloc() */
439 	const char		*m_type_ident;
440 	void			*m_driver;	/* Driver private data */
441 	dev_info_t		*m_dip;
442 	uint_t			m_instance;
443 	uint8_t			*m_src_addr;
444 	uint8_t			*m_dst_addr;
445 	mac_callbacks_t		*m_callbacks;
446 	uint_t			m_min_sdu;
447 	uint_t			m_max_sdu;
448 	void			*m_pdata;
449 	size_t			m_pdata_size;
450 	char			**m_priv_props;
451 	uint32_t		m_margin;
452 	uint32_t		m_v12n;		/* Virtualization level */
453 } mac_register_t;
454 
455 /*
456  * Driver interface functions.
457  */
458 extern mac_protect_t		*mac_protect_get(mac_handle_t);
459 extern void			mac_sdu_get(mac_handle_t, uint_t *, uint_t *);
460 extern int			mac_maxsdu_update(mac_handle_t, uint_t);
461 
462 extern mac_register_t		*mac_alloc(uint_t);
463 extern void			mac_free(mac_register_t *);
464 extern int			mac_register(mac_register_t *, mac_handle_t *);
465 extern int			mac_disable_nowait(mac_handle_t);
466 extern int			mac_disable(mac_handle_t);
467 extern int  			mac_unregister(mac_handle_t);
468 extern void 			mac_rx(mac_handle_t, mac_resource_handle_t,
469 				    mblk_t *);
470 extern void 			mac_rx_ring(mac_handle_t, mac_ring_handle_t,
471 				    mblk_t *, uint64_t);
472 extern void 			mac_link_update(mac_handle_t, link_state_t);
473 extern void 			mac_link_redo(mac_handle_t, link_state_t);
474 extern void 			mac_unicst_update(mac_handle_t,
475 				    const uint8_t *);
476 extern void			mac_dst_update(mac_handle_t, const uint8_t *);
477 extern void			mac_tx_update(mac_handle_t);
478 extern void			mac_tx_ring_update(mac_handle_t,
479 				    mac_ring_handle_t);
480 extern void			mac_capab_update(mac_handle_t);
481 extern int			mac_pdata_update(mac_handle_t, void *,
482 				    size_t);
483 extern void			mac_multicast_refresh(mac_handle_t,
484 				    mac_multicst_t, void *, boolean_t);
485 extern void			mac_unicst_refresh(mac_handle_t, mac_unicst_t,
486 				    void *);
487 extern void			mac_promisc_refresh(mac_handle_t,
488 				    mac_setpromisc_t, void *);
489 extern boolean_t		mac_margin_update(mac_handle_t, uint32_t);
490 extern void			mac_margin_get(mac_handle_t, uint32_t *);
491 extern int			mac_margin_remove(mac_handle_t, uint32_t);
492 extern int			mac_margin_add(mac_handle_t, uint32_t *,
493 				    boolean_t);
494 extern void			mac_init_ops(struct dev_ops *, const char *);
495 extern void			mac_fini_ops(struct dev_ops *);
496 extern int			mac_devt_to_instance(dev_t);
497 extern minor_t			mac_private_minor(void);
498 extern void			mac_ring_intr_set(mac_ring_handle_t,
499 				    ddi_intr_handle_t);
500 
501 
502 extern mactype_register_t	*mactype_alloc(uint_t);
503 extern void			mactype_free(mactype_register_t *);
504 extern int			mactype_register(mactype_register_t *);
505 extern int			mactype_unregister(const char *);
506 
507 extern boolean_t		mac_unicst_verify(mac_handle_t,
508 				    const uint8_t *, uint_t);
509 
510 extern int			mac_group_add_ring(mac_group_handle_t, int);
511 extern void			mac_group_rem_ring(mac_group_handle_t,
512 				    mac_ring_handle_t);
513 extern mac_ring_handle_t	mac_find_ring(mac_group_handle_t, int);
514 
515 extern void			mac_prop_info_set_default_uint8(
516 				    mac_prop_info_handle_t, uint8_t);
517 extern void			mac_prop_info_set_default_str(
518 				    mac_prop_info_handle_t, const char *);
519 extern void			mac_prop_info_set_default_uint64(
520 				    mac_prop_info_handle_t, uint64_t);
521 extern void			mac_prop_info_set_default_uint32(
522 				    mac_prop_info_handle_t, uint32_t);
523 extern void			mac_prop_info_set_default_link_flowctrl(
524 				    mac_prop_info_handle_t, link_flowctrl_t);
525 extern void			mac_prop_info_set_range_uint32(
526 				    mac_prop_info_handle_t,
527 				    uint32_t, uint32_t);
528 extern void			mac_prop_info_set_perm(mac_prop_info_handle_t,
529 				    uint8_t);
530 
531 extern void			mac_hcksum_get(mblk_t *, uint32_t *,
532 				    uint32_t *, uint32_t *, uint32_t *,
533 				    uint32_t *);
534 extern void			mac_hcksum_set(mblk_t *, uint32_t, uint32_t,
535 				    uint32_t, uint32_t, uint32_t);
536 
537 extern void			mac_lso_get(mblk_t *, uint32_t *, uint32_t *);
538 
539 #endif	/* _KERNEL */
540 
541 #ifdef	__cplusplus
542 }
543 #endif
544 
545 #endif /* _SYS_MAC_PROVIDER_H */
546