xref: /titanic_41/usr/src/uts/common/sys/mac.h (revision 2f0fcb93196badcdd803715656c809058d9f3114)
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  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_MAC_H
27 #define	_SYS_MAC_H
28 
29 #include <sys/types.h>
30 #include <sys/ddi.h>
31 #include <sys/sunddi.h>
32 #include <sys/stream.h>
33 
34 /*
35  * MAC Services Module
36  */
37 
38 #ifdef	__cplusplus
39 extern "C" {
40 #endif
41 
42 /*
43  * MAC Information (text emitted by modinfo(1m))
44  */
45 #define	MAC_INFO	"MAC Services"
46 
47 /*
48  * MAC version identifier.  This is used by mac_alloc() mac_register() to
49  * verify that incompatible drivers don't register.
50  */
51 #define	MAC_VERSION	0x1
52 
53 /*
54  * MAC-Type version identifier.  This is used by mactype_alloc() and
55  * mactype_register() to verify that incompatible MAC-Type plugins don't
56  * register.
57  */
58 #define	MACTYPE_VERSION	0x1
59 
60 /*
61  * Statistics
62  */
63 
64 #define	XCVR_UNDEFINED		0
65 #define	XCVR_NONE		1
66 #define	XCVR_10			2
67 #define	XCVR_100T4		3
68 #define	XCVR_100X		4
69 #define	XCVR_100T2		5
70 #define	XCVR_1000X		6
71 #define	XCVR_1000T		7
72 
73 typedef enum {
74 	LINK_STATE_UNKNOWN = -1,
75 	LINK_STATE_DOWN,
76 	LINK_STATE_UP
77 } link_state_t;
78 
79 typedef enum {
80 	LINK_DUPLEX_UNKNOWN = 0,
81 	LINK_DUPLEX_HALF,
82 	LINK_DUPLEX_FULL
83 } link_duplex_t;
84 
85 #define	DATALINK_INVALID_LINKID	0
86 #define	DATALINK_ALL_LINKID	0
87 #define	DATALINK_MAX_LINKID	0xffffffff
88 
89 typedef enum {
90 	LINK_FLOWCTRL_NONE = 0,
91 	LINK_FLOWCTRL_RX,
92 	LINK_FLOWCTRL_TX,
93 	LINK_FLOWCTRL_BI
94 } link_flowctrl_t;
95 
96 typedef uint32_t datalink_id_t;
97 
98 /*
99  * Encodings for public properties.
100  * A most significant bit value of 1 indicates private property, intended
101  * to allow private property implementations to use internal encodings
102  * if desired.
103  *
104  * Note that there are 2 sets of parameters: the *_EN_*
105  * values are those that the Administrator configures for autonegotiation.
106  * The _ADV_* values are those that are currently exposed over the wire.
107  */
108 #define	MAXLINKPROPNAME		256
109 #define	MAC_PROP_DEFAULT	0x0001
110 typedef enum {
111 	MAC_PROP_DUPLEX = 0x00000001,
112 	MAC_PROP_SPEED,
113 	MAC_PROP_STATUS,
114 	MAC_PROP_AUTONEG,
115 	MAC_PROP_EN_AUTONEG,
116 	MAC_PROP_MTU,
117 	MAC_PROP_ZONE,
118 	MAC_PROP_AUTOPUSH,
119 	MAC_PROP_FLOWCTRL,
120 	MAC_PROP_ADV_1000FDX_CAP,
121 	MAC_PROP_EN_1000FDX_CAP,
122 	MAC_PROP_ADV_1000HDX_CAP,
123 	MAC_PROP_EN_1000HDX_CAP,
124 	MAC_PROP_ADV_100FDX_CAP,
125 	MAC_PROP_EN_100FDX_CAP,
126 	MAC_PROP_ADV_100HDX_CAP,
127 	MAC_PROP_EN_100HDX_CAP,
128 	MAC_PROP_ADV_10FDX_CAP,
129 	MAC_PROP_EN_10FDX_CAP,
130 	MAC_PROP_ADV_10HDX_CAP,
131 	MAC_PROP_EN_10HDX_CAP,
132 	MAC_PROP_ADV_100T4_CAP,
133 	MAC_PROP_EN_100T4_CAP,
134 	MAC_PROP_WL_ESSID,
135 	MAC_PROP_WL_BSSID,
136 	MAC_PROP_WL_BSSTYPE,
137 	MAC_PROP_WL_LINKSTATUS,
138 	MAC_PROP_WL_DESIRED_RATES,
139 	MAC_PROP_WL_SUPPORTED_RATES,
140 	MAC_PROP_WL_AUTH_MODE,
141 	MAC_PROP_WL_ENCRYPTION,
142 	MAC_PROP_WL_RSSI,
143 	MAC_PROP_WL_PHY_CONFIG,
144 	MAC_PROP_WL_CAPABILITY,
145 	MAC_PROP_WL_WPA,
146 	MAC_PROP_WL_SCANRESULTS,
147 	MAC_PROP_WL_POWER_MODE,
148 	MAC_PROP_WL_RADIO,
149 	MAC_PROP_WL_ESS_LIST,
150 	MAC_PROP_WL_KEY_TAB,
151 	MAC_PROP_WL_CREATE_IBSS,
152 	MAC_PROP_WL_SETOPTIE,
153 	MAC_PROP_WL_DELKEY,
154 	MAC_PROP_WL_KEY,
155 	MAC_PROP_WL_MLME,
156 	MAC_PROP_PRIVATE = -1
157 } mac_prop_id_t;
158 
159 /*
160  * Maximum MAC address length
161  */
162 #define	MAXMACADDRLEN	20
163 
164 #ifdef	_KERNEL
165 
166 typedef struct mac_stat_info_s {
167 	uint_t		msi_stat;
168 	char		*msi_name;
169 	uint_t		msi_type;	/* as defined in kstat_named_init(9F) */
170 	uint64_t	msi_default;
171 } mac_stat_info_t;
172 
173 /*
174  * There are three ranges of statistics values.  0 to 1 - MAC_STAT_MIN are
175  * interface statistics maintained by the mac module.  MAC_STAT_MIN to 1 -
176  * MACTYPE_STAT_MIN are common MAC statistics defined by the mac module and
177  * maintained by each driver.  MACTYPE_STAT_MIN and above are statistics
178  * defined by MAC-Type plugins and maintained by each driver.
179  */
180 #define	MAC_STAT_MIN		1000
181 #define	MACTYPE_STAT_MIN	2000
182 
183 #define	IS_MAC_STAT(stat)	\
184 	(stat >= MAC_STAT_MIN && stat < MACTYPE_STAT_MIN)
185 #define	IS_MACTYPE_STAT(stat)	(stat >= MACTYPE_STAT_MIN)
186 
187 /*
188  * Statistics maintained by the mac module, and possibly populated as link
189  * statistics.
190  */
191 enum mac_mod_stat {
192 	MAC_STAT_LINK_STATE,
193 	MAC_STAT_LINK_UP,
194 	MAC_STAT_PROMISC
195 };
196 
197 /*
198  * Do not reorder, and add only to the end of this list.
199  */
200 enum mac_driver_stat {
201 	/* MIB-II stats (RFC 1213 and RFC 1573) */
202 	MAC_STAT_IFSPEED = MAC_STAT_MIN,
203 	MAC_STAT_MULTIRCV,
204 	MAC_STAT_BRDCSTRCV,
205 	MAC_STAT_MULTIXMT,
206 	MAC_STAT_BRDCSTXMT,
207 	MAC_STAT_NORCVBUF,
208 	MAC_STAT_IERRORS,
209 	MAC_STAT_UNKNOWNS,
210 	MAC_STAT_NOXMTBUF,
211 	MAC_STAT_OERRORS,
212 	MAC_STAT_COLLISIONS,
213 	MAC_STAT_RBYTES,
214 	MAC_STAT_IPACKETS,
215 	MAC_STAT_OBYTES,
216 	MAC_STAT_OPACKETS,
217 	MAC_STAT_UNDERFLOWS,
218 	MAC_STAT_OVERFLOWS
219 };
220 
221 #define	MAC_NSTAT	(MAC_STAT_OVERFLOWS - MAC_STAT_IFSPEED + 1)
222 
223 #define	MAC_STAT_ISACOUNTER(_stat) (		\
224 	    (_stat) == MAC_STAT_MULTIRCV ||	\
225 	    (_stat) == MAC_STAT_BRDCSTRCV ||	\
226 	    (_stat) == MAC_STAT_MULTIXMT ||	\
227 	    (_stat) == MAC_STAT_BRDCSTXMT ||	\
228 	    (_stat) == MAC_STAT_NORCVBUF ||	\
229 	    (_stat) == MAC_STAT_IERRORS ||	\
230 	    (_stat) == MAC_STAT_UNKNOWNS ||	\
231 	    (_stat) == MAC_STAT_NOXMTBUF ||	\
232 	    (_stat) == MAC_STAT_OERRORS ||	\
233 	    (_stat) == MAC_STAT_COLLISIONS ||	\
234 	    (_stat) == MAC_STAT_RBYTES ||	\
235 	    (_stat) == MAC_STAT_IPACKETS ||	\
236 	    (_stat) == MAC_STAT_OBYTES ||	\
237 	    (_stat) == MAC_STAT_OPACKETS ||	\
238 	    (_stat) == MAC_STAT_UNDERFLOWS ||	\
239 	    (_stat) == MAC_STAT_OVERFLOWS)
240 
241 /*
242  * Immutable information. (This may not be modified after registration).
243  */
244 typedef struct mac_info_s {
245 	uint_t		mi_media;
246 	uint_t		mi_nativemedia;
247 	uint_t		mi_addr_length;
248 	uint8_t		*mi_unicst_addr;
249 	uint8_t		*mi_brdcst_addr;
250 } mac_info_t;
251 
252 /*
253  * LSO capability
254  */
255 typedef struct lso_basic_tcp_ipv4_s {
256 	t_uscalar_t	lso_max;		/* maximum payload */
257 } lso_basic_tcp_ipv4_t;
258 
259 /*
260  * Future LSO capabilities can be added at the end of the mac_capab_lso_t.
261  * When such capability is added to the GLDv3 framework, the size of the
262  * mac_capab_lso_t it allocates and passes to the drivers increases. Older
263  * drivers wil access only the (upper) sections of that structure, that is the
264  * sections carrying the capabilities they understand. This ensures the
265  * interface can be safely extended in a binary compatible way.
266  */
267 typedef	struct mac_capab_lso_s {
268 	t_uscalar_t		lso_flags;
269 	lso_basic_tcp_ipv4_t	lso_basic_tcp_ipv4;
270 	/* Add future lso capabilities here */
271 } mac_capab_lso_t;
272 
273 /*
274  * Information for legacy devices.
275  */
276 typedef struct mac_capab_legacy_s {
277 	/*
278 	 * Notifications that the legacy device does not support.
279 	 */
280 	uint32_t	ml_unsup_note;
281 	/*
282 	 * dev_t of the legacy device; can be held to force attach.
283 	 */
284 	dev_t		ml_dev;
285 } mac_capab_legacy_t;
286 
287 /*
288  * MAC layer capabilities.  These capabilities are handled by the drivers'
289  * mc_capab_get() callbacks.  Some capabilities require the driver to fill
290  * in a given data structure, and others are simply boolean capabilities.
291  * Note that capability values must be powers of 2 so that consumers and
292  * providers of this interface can keep track of which capabilities they
293  * care about by keeping a bitfield of these things around somewhere.
294  */
295 typedef enum {
296 	MAC_CAPAB_HCKSUM	= 0x01, /* data is a uint32_t for the txflags */
297 	MAC_CAPAB_POLL		= 0x02,	/* boolean only, no data */
298 	MAC_CAPAB_MULTIADDRESS	= 0x04, /* data is multiaddress_capab_t */
299 	MAC_CAPAB_LSO		= 0x08, /* data is mac_capab_lso_t */
300 	MAC_CAPAB_NO_NATIVEVLAN	= 0x10, /* boolean only, no data */
301 	MAC_CAPAB_NO_ZCOPY	= 0x20, /* boolean only, no data */
302 	/* add new capabilities here */
303 	MAC_CAPAB_RINGS		= 0x100, /* data is mac_capab_rings_t */
304 	MAC_CAPAB_SHARES	= 0x200, /* data is mac_capab_share_t */
305 
306 	/* The following capabilities are specific to softmac. */
307 	MAC_CAPAB_LEGACY	= 0x8000 /* data is mac_capab_legacy_t */
308 } mac_capab_t;
309 
310 typedef int mac_addr_slot_t;
311 
312 /* mma_flags values */
313 #define	MMAC_SLOT_USED		0x1   /* address slot used */
314 #define	MMAC_SLOT_UNUSED	0x2   /* free address slot */
315 #define	MMAC_VENDOR_ADDR	0x4   /* address returned is vendor supplied */
316 
317 typedef struct mac_multi_address_s {
318 	mac_addr_slot_t	mma_slot;	/* slot for add/remove/get/set */
319 	uint_t		mma_addrlen;
320 	uint8_t		mma_addr[MAXMACADDRLEN];
321 	uint_t		mma_flags;
322 } mac_multi_addr_t;
323 
324 typedef int	(*maddr_reserve_t)(void *, mac_multi_addr_t *);
325 typedef int	(*maddr_add_t)(void *, mac_multi_addr_t *);
326 typedef int	(*maddr_remove_t)(void *, mac_addr_slot_t);
327 typedef int	(*maddr_modify_t)(void *, mac_multi_addr_t *);
328 typedef int	(*maddr_get_t)(void *, mac_multi_addr_t *);
329 
330 /* maddr_flag values */
331 #define	MADDR_VENDOR_ADDR	0x01	/* addr returned is vendor supplied */
332 
333 /* multiple mac address: add/remove/set/get mac address */
334 typedef struct multiaddress_capab_s {
335 	int		maddr_naddr;	/* total addresses */
336 	int		maddr_naddrfree;	/* free address slots */
337 	uint_t		maddr_flag;	/* MADDR_VENDOR_ADDR bit can be set */
338 	/* driver entry points */
339 	void		*maddr_handle;	/* cookie to be used for the calls */
340 	maddr_reserve_t	maddr_reserve;	/* reserve a factory address */
341 	maddr_add_t	maddr_add;	/* add a new unicst address */
342 	maddr_remove_t	maddr_remove;	/* remove an added address */
343 	maddr_modify_t	maddr_modify;	/* modify an added address */
344 	maddr_get_t	maddr_get;	/* get address from specified slot */
345 } multiaddress_capab_t;
346 
347 /*
348  * MAC driver entry point types.
349  */
350 typedef int		(*mac_getstat_t)(void *, uint_t, uint64_t *);
351 typedef	int		(*mac_start_t)(void *);
352 typedef void		(*mac_stop_t)(void *);
353 typedef int		(*mac_setpromisc_t)(void *, boolean_t);
354 typedef int		(*mac_multicst_t)(void *, boolean_t, const uint8_t *);
355 typedef int		(*mac_unicst_t)(void *, const uint8_t *);
356 typedef void		(*mac_ioctl_t)(void *, queue_t *, mblk_t *);
357 typedef void		(*mac_resources_t)(void *);
358 typedef mblk_t		*(*mac_tx_t)(void *, mblk_t *);
359 typedef	boolean_t	(*mac_getcapab_t)(void *, mac_capab_t, void *);
360 typedef	int		(*mac_open_t)(void *);
361 typedef void		(*mac_close_t)(void *);
362 typedef	int		(*mac_set_prop_t)(void *, const char *, mac_prop_id_t,
363     uint_t, const void *);
364 typedef	int		(*mac_get_prop_t)(void *, const char *, mac_prop_id_t,
365     uint_t, uint_t, void *);
366 
367 /*
368  * Drivers must set all of these callbacks except for mc_resources,
369  * mc_ioctl, and mc_getcapab, which are optional.  If any of these optional
370  * callbacks are set, their appropriate flags must be set in mc_callbacks.
371  * Any future additions to this list must also be accompanied by an
372  * associated mc_callbacks flag so that the framework can grow without
373  * affecting the binary compatibility of the interface.
374  */
375 typedef struct mac_callbacks_s {
376 	uint_t		mc_callbacks;	/* Denotes which callbacks are set */
377 	mac_getstat_t	mc_getstat;	/* Get the value of a statistic */
378 	mac_start_t	mc_start;	/* Start the device */
379 	mac_stop_t	mc_stop;	/* Stop the device */
380 	mac_setpromisc_t mc_setpromisc;	/* Enable or disable promiscuous mode */
381 	mac_multicst_t	mc_multicst;	/* Enable or disable a multicast addr */
382 	mac_unicst_t	mc_unicst;	/* Set the unicast MAC address */
383 	mac_tx_t	mc_tx;		/* Transmit a packet */
384 	mac_resources_t	mc_resources;	/* Get the device resources */
385 	mac_ioctl_t	mc_ioctl;	/* Process an unknown ioctl */
386 	mac_getcapab_t	mc_getcapab;	/* Get capability information */
387 	mac_open_t	mc_open;	/* Open the device */
388 	mac_close_t	mc_close;	/* Close the device */
389 	mac_set_prop_t	mc_setprop;
390 	mac_get_prop_t	mc_getprop;
391 } mac_callbacks_t;
392 
393 typedef struct mac_priv_prop_s {
394 	char	mpp_name[MAXLINKPROPNAME];
395 	uint_t	mpp_flags;
396 } mac_priv_prop_t;
397 
398 /*
399  * Multiple Rings capability
400  */
401 typedef enum {
402 	MAC_RING_TYPE_RX	= 1,	/* Receive ring */
403 	MAC_RING_TYPE_TX	= 2	/* Transmit ring */
404 } mac_ring_type_t;
405 
406 /*
407  * Grouping type of a ring group
408  *
409  * MAC_GROUP_TYPE_STATIC: The ring group can not be re-grouped.
410  * MAC_GROUP_TYPE_DYNAMIC: The ring group support dynamic re-grouping
411  */
412 typedef enum {
413 	MAC_GROUP_TYPE_STATIC	= 1,	/* Static ring group */
414 	MAC_GROUP_TYPE_DYNAMIC	= 2	/* Dynamic ring group */
415 } mac_group_type_t;
416 
417 typedef	struct __mac_ring_driver	*mac_ring_driver_t;
418 typedef	struct __mac_ring_handle	*mac_ring_handle_t;
419 typedef	struct __mac_group_driver	*mac_group_driver_t;
420 typedef	struct __mac_group_handle	*mac_group_handle_t;
421 typedef	struct __mac_intr_handle	*mac_intr_handle_t;
422 
423 typedef	struct mac_ring_info_s mac_ring_info_t;
424 typedef	struct mac_group_info_s mac_group_info_t;
425 
426 typedef	int	(*mac_intr_enable_t)(mac_intr_handle_t);
427 typedef	int	(*mac_intr_disable_t)(mac_intr_handle_t);
428 
429 typedef	struct mac_intr_s {
430 	mac_intr_handle_t	mi_handle;
431 	mac_intr_enable_t	mi_enable;
432 	mac_intr_disable_t	mi_disable;
433 } mac_intr_t;
434 
435 typedef void	(*mac_get_ring_t)(void *, mac_ring_type_t, const int, const int,
436     mac_ring_info_t *, mac_ring_handle_t);
437 typedef void	(*mac_get_group_t)(void *, mac_ring_type_t, const int,
438     mac_group_info_t *, mac_group_handle_t);
439 
440 typedef void	(*mac_group_add_ring_t)(mac_group_driver_t,
441     mac_ring_driver_t, mac_ring_type_t);
442 typedef void	(*mac_group_rem_ring_t)(mac_group_driver_t,
443     mac_ring_driver_t, mac_ring_type_t);
444 
445 /*
446  * Multiple Rings Capability
447  */
448 typedef struct	mac_capab_rings_s {
449 	mac_ring_type_t		mr_type;	/* Ring type */
450 	mac_group_type_t	mr_group_type;	/* Grouping type */
451 	void			*mr_handle;	/* Group Driver Handle. */
452 	uint_t			mr_rnum;	/* Number of rings */
453 	uint_t			mr_gnum;	/* Number of ring groups */
454 	mac_get_ring_t		mr_rget;	/* Get ring from driver */
455 	mac_get_group_t		mr_gget;	/* Get ring group from driver */
456 	mac_group_add_ring_t	mr_gadd_ring;	/* Add ring into a group */
457 	mac_group_rem_ring_t	mr_grem_ring;	/* Remove ring from a group */
458 } mac_capab_rings_t;
459 
460 /*
461  * Common ring functions and driver interfaces
462  */
463 typedef	int	(*mac_ring_start_t)(mac_ring_driver_t);
464 typedef	void	(*mac_ring_stop_t)(mac_ring_driver_t);
465 
466 typedef	mblk_t	*(*mac_ring_send_t)(void *, mblk_t *);
467 typedef	mblk_t *(*mac_ring_poll_t)(void *, int);
468 
469 typedef struct mac_ring_info_s {
470 	mac_ring_driver_t	mr_driver;
471 	mac_ring_start_t	mr_start;
472 	mac_ring_stop_t		mr_stop;
473 	mac_intr_t		mr_intr;
474 	union {
475 		mac_ring_send_t	send;
476 		mac_ring_poll_t	poll;
477 	} mrfunion;
478 } mac_ring_info_s;
479 
480 #define	mr_send		mrfunion.send
481 #define	mr_poll		mrfunion.poll
482 
483 typedef	int	(*mac_group_start_t)(mac_group_driver_t);
484 typedef	void	(*mac_group_stop_t)(mac_group_driver_t);
485 typedef	int	(*mac_add_mac_addr_t)(void *, const uint8_t *);
486 typedef	int	(*mac_rem_mac_addr_t)(void *, const uint8_t *);
487 
488 struct mac_group_info_s {
489 	mac_group_driver_t	mrg_driver;	/* Driver reference */
490 	mac_group_start_t	mrg_start;	/* Start the group */
491 	mac_group_stop_t	mrg_stop;	/* Stop the group */
492 	uint_t			mrg_count;	/* Count of rings */
493 	mac_intr_t		mrg_intr;	/* Optional per-group intr */
494 
495 	/* Only used for rx groups */
496 	mac_add_mac_addr_t	mrg_addmac;	/* Add a MAC address */
497 	mac_rem_mac_addr_t	mrg_remmac;	/* Remove a MAC address */
498 };
499 
500 /*
501  * Share management functions.
502  */
503 typedef uint64_t mac_share_handle_t;
504 
505 /*
506  * Returns a Share handle to the client calling from above.
507  */
508 typedef int    (*mac_alloc_share_t)(void *, uint64_t cookie,
509     uint64_t *rcookie, mac_share_handle_t *);
510 
511 /*
512  * Destroys the share previously allocated and unallocates
513  * all share resources (e.g. DMA's assigned to the share).
514  */
515 typedef void (*mac_free_share_t)(mac_share_handle_t);
516 
517 typedef void (*mac_share_query_t)(mac_share_handle_t shdl,
518     mac_ring_type_t type, uint32_t *rmin, uint32_t *rmax,
519     uint64_t *rmap, uint64_t *gnum);
520 
521 /*
522  * Basic idea, bind previously created ring groups to shares
523  * for them to be exported (or shared) by another domain.
524  * These interfaces bind/unbind the ring group to a share.  The
525  * of doing such causes the resources to be shared with the guest.
526  */
527 typedef int (*mac_share_add_group_t)(mac_share_handle_t,
528     mac_group_handle_t);
529 typedef int (*mac_share_rem_group_t)(mac_share_handle_t,
530     mac_group_handle_t);
531 
532 typedef struct  mac_capab_share_s {
533 	uint_t			ms_snum;	/* Number of shares (vr's) */
534 	void			*ms_handle;	/* Handle to driver. */
535 	mac_alloc_share_t	ms_salloc;	/* Get a share from driver. */
536 	mac_free_share_t	ms_sfree;	/* Return a share to driver. */
537 	mac_share_add_group_t	ms_sadd;	/* Add a group to the share. */
538 	mac_share_rem_group_t	ms_sremove;	/* Remove group from share. */
539 	mac_share_query_t	ms_squery;	/* Query share constraints */
540 } mac_capab_share_t;
541 
542 /*
543  * Flags for mc_callbacks.  Requiring drivers to set the flags associated
544  * with optional callbacks initialized in the structure allows the mac
545  * module to add optional callbacks in the future without requiring drivers
546  * to recompile.
547  */
548 #define	MC_RESOURCES	0x001
549 #define	MC_IOCTL	0x002
550 #define	MC_GETCAPAB	0x004
551 #define	MC_OPEN		0x008
552 #define	MC_CLOSE	0x010
553 #define	MC_SETPROP	0x020
554 #define	MC_GETPROP	0x040
555 
556 #define	MAC_MAX_MINOR	1000
557 
558 typedef struct mac_register_s {
559 	uint_t			m_version;	/* set by mac_alloc() */
560 	const char		*m_type_ident;
561 	void			*m_driver;	/* Driver private data */
562 	dev_info_t		*m_dip;
563 	uint_t			m_instance;
564 	uint8_t			*m_src_addr;
565 	uint8_t			*m_dst_addr;
566 	mac_callbacks_t		*m_callbacks;
567 	uint_t			m_min_sdu;
568 	uint_t			m_max_sdu;
569 	void			*m_pdata;
570 	size_t			m_pdata_size;
571 	uint32_t		m_margin;
572 	mac_priv_prop_t		*m_priv_props;
573 	size_t			m_priv_prop_count;
574 } mac_register_t;
575 
576 
577 /*
578  * Opaque handle types.
579  */
580 typedef	struct mac_t			*mac_handle_t;
581 typedef struct __mac_notify_handle	*mac_notify_handle_t;
582 typedef struct __mac_rx_handle		*mac_rx_handle_t;
583 typedef struct __mac_txloop_handle	*mac_txloop_handle_t;
584 typedef struct __mac_resource_handle	*mac_resource_handle_t;
585 
586 /*
587  * MAC interface callback types.
588  */
589 typedef enum {
590 	MAC_NOTE_LINK,
591 	MAC_NOTE_PROMISC,
592 	MAC_NOTE_UNICST,
593 	MAC_NOTE_TX,
594 	MAC_NOTE_RESOURCE,
595 	MAC_NOTE_DEVPROMISC,
596 	MAC_NOTE_FASTPATH_FLUSH,
597 	MAC_NOTE_SDU_SIZE,
598 	MAC_NOTE_VNIC,
599 	MAC_NOTE_MARGIN,
600 	MAC_NNOTE	/* must be the last entry */
601 } mac_notify_type_t;
602 
603 typedef void		(*mac_notify_t)(void *, mac_notify_type_t);
604 typedef void		(*mac_rx_t)(void *, mac_resource_handle_t, mblk_t *);
605 typedef void		(*mac_txloop_t)(void *, mblk_t *);
606 typedef void		(*mac_blank_t)(void *, time_t, uint_t);
607 
608 /*
609  * MAC promiscuous types
610  */
611 typedef enum {
612 	MAC_PROMISC = 0x01,		/* MAC instance is promiscuous */
613 	MAC_DEVPROMISC = 0x02		/* Device is promiscuous */
614 } mac_promisc_type_t;
615 
616 /*
617  * MAC resource types
618  */
619 typedef enum {
620 	MAC_RX_FIFO = 1
621 } mac_resource_type_t;
622 
623 typedef struct mac_rx_fifo_s {
624 	mac_resource_type_t	mrf_type;	/* MAC_RX_FIFO */
625 	mac_blank_t		mrf_blank;
626 	void			*mrf_arg;
627 	time_t			mrf_normal_blank_time;
628 	uint_t			mrf_normal_pkt_count;
629 } mac_rx_fifo_t;
630 
631 typedef struct mac_txinfo_s {
632 	mac_tx_t		mt_fn;
633 	void			*mt_arg;
634 } mac_txinfo_t;
635 
636 typedef union mac_resource_u {
637 	mac_resource_type_t	mr_type;
638 	mac_rx_fifo_t		mr_fifo;
639 } mac_resource_t;
640 
641 typedef mac_resource_handle_t	(*mac_resource_add_t)(void *, mac_resource_t *);
642 
643 typedef enum {
644 	MAC_ADDRTYPE_UNICAST,
645 	MAC_ADDRTYPE_MULTICAST,
646 	MAC_ADDRTYPE_BROADCAST
647 } mac_addrtype_t;
648 
649 typedef struct mac_header_info_s {
650 	size_t		mhi_hdrsize;
651 	size_t		mhi_pktsize;
652 	const uint8_t	*mhi_daddr;
653 	const uint8_t	*mhi_saddr;
654 	uint32_t	mhi_origsap;
655 	uint32_t	mhi_bindsap;
656 	mac_addrtype_t	mhi_dsttype;
657 	uint16_t	mhi_tci;
658 	uint_t		mhi_istagged:1,
659 			mhi_prom_looped:1;
660 } mac_header_info_t;
661 
662 /*
663  * MAC-Type plugin interfaces
664  */
665 
666 typedef int		(*mtops_addr_verify_t)(const void *, void *);
667 typedef boolean_t	(*mtops_sap_verify_t)(uint32_t, uint32_t *, void *);
668 typedef mblk_t		*(*mtops_header_t)(const void *, const void *,
669     uint32_t, void *, mblk_t *, size_t);
670 typedef int		(*mtops_header_info_t)(mblk_t *, void *,
671     mac_header_info_t *);
672 typedef boolean_t	(*mtops_pdata_verify_t)(void *, size_t);
673 typedef	mblk_t		*(*mtops_header_modify_t)(mblk_t *, void *);
674 typedef void		(*mtops_link_details_t)(char *, size_t, mac_handle_t,
675     void *);
676 
677 typedef struct mactype_ops_s {
678 	uint_t			mtops_ops;
679 	/*
680 	 * mtops_unicst_verify() returns 0 if the given address is a valid
681 	 * unicast address, or a non-zero errno otherwise.
682 	 */
683 	mtops_addr_verify_t	mtops_unicst_verify;
684 	/*
685 	 * mtops_multicst_verify() returns 0 if the given address is a
686 	 * valid multicast address, or a non-zero errno otherwise.  If the
687 	 * media doesn't support multicast, ENOTSUP should be returned (for
688 	 * example).
689 	 */
690 	mtops_addr_verify_t	mtops_multicst_verify;
691 	/*
692 	 * mtops_sap_verify() returns B_TRUE if the given SAP is a valid
693 	 * SAP value, or B_FALSE otherwise.
694 	 */
695 	mtops_sap_verify_t	mtops_sap_verify;
696 	/*
697 	 * mtops_header() is used to allocate and construct a MAC header.
698 	 */
699 	mtops_header_t		mtops_header;
700 	/*
701 	 * mtops_header_info() is used to gather information on a given MAC
702 	 * header.
703 	 */
704 	mtops_header_info_t	mtops_header_info;
705 	/*
706 	 * mtops_pdata_verify() is used to verify the validity of MAC
707 	 * plugin data.  It is called by mac_register() if the driver has
708 	 * supplied MAC plugin data, and also by mac_pdata_update() when
709 	 * drivers update the data.
710 	 */
711 	mtops_pdata_verify_t	mtops_pdata_verify;
712 	/*
713 	 * mtops_header_cook() is an optional callback that converts (or
714 	 * "cooks") the given raw header (as sent by a raw DLPI consumer)
715 	 * into one that is appropriate to send down to the MAC driver.
716 	 * Following the example above, an Ethernet header sent down by a
717 	 * DLPI consumer would be converted to whatever header the MAC
718 	 * driver expects.
719 	 */
720 	mtops_header_modify_t	mtops_header_cook;
721 	/*
722 	 * mtops_header_uncook() is an optional callback that does the
723 	 * opposite of mtops_header_cook().  It "uncooks" a given MAC
724 	 * header (as received from the driver) for consumption by raw DLPI
725 	 * consumers.  For example, for a non-Ethernet plugin that wants
726 	 * raw DLPI consumers to be fooled into thinking that the device
727 	 * provides Ethernet access, this callback would modify the given
728 	 * mblk_t such that the MAC header is converted to an Ethernet
729 	 * header.
730 	 */
731 	mtops_header_modify_t	mtops_header_uncook;
732 	/*
733 	 * mtops_link_details() is an optional callback that provides
734 	 * extended information about the link state.  Its primary purpose
735 	 * is to provide type-specific support for syslog contents on
736 	 * link up events.  If no implementation is provided, then a default
737 	 * implementation will be used.
738 	 */
739 	mtops_link_details_t	mtops_link_details;
740 } mactype_ops_t;
741 
742 /*
743  * mtops_ops exists for the plugin to enumerate the optional callback
744  * entrypoints it has defined.  This allows the mac module to define
745  * additional plugin entrypoints in mactype_ops_t without breaking backward
746  * compatibility with old plugins.
747  */
748 #define	MTOPS_PDATA_VERIFY	0x001
749 #define	MTOPS_HEADER_COOK	0x002
750 #define	MTOPS_HEADER_UNCOOK	0x004
751 #define	MTOPS_LINK_DETAILS	0x008
752 
753 /*
754  * Provide mapping for legacy ndd ioctls relevant to that mactype.
755  * Note that the ndd ioctls are obsolete, and may be removed in a future
756  * release of Solaris. The ndd ioctls are not typically used in legacy
757  * ethernet drivers. New datalink drivers of all link-types should use
758  * dladm(1m) interfaces for administering tunables and not have to provide
759  * a mapping.
760  */
761 typedef struct mac_ndd_mapping_s {
762 	char		*mp_name;
763 	union {
764 		mac_prop_id_t   u_id;
765 		uint_t		u_kstat;
766 	} u_mp_id;
767 	long		mp_minval;
768 	long		mp_maxval;
769 	size_t		mp_valsize;
770 	int		mp_flags;
771 } mac_ndd_mapping_t;
772 
773 #define	mp_prop_id	u_mp_id.u_id
774 #define	mp_kstat	u_mp_id.u_kstat
775 
776 /*
777  * Flags to figure out r/w status of legacy ndd props.
778  */
779 #define	MAC_PROP_PERM_READ		0x0001
780 #define	MAC_PROP_PERM_WRITE		0x0010
781 #define	MAC_PROP_MAP_KSTAT		0x0100
782 #define	MAC_PROP_PERM_RW		(MAC_PROP_PERM_READ|MAC_PROP_PERM_WRITE)
783 #define	MAC_PROP_FLAGS_RK		(MAC_PROP_PERM_READ|MAC_PROP_MAP_KSTAT)
784 
785 typedef struct mactype_register_s {
786 	uint_t		mtr_version;	/* set by mactype_alloc() */
787 	const char	*mtr_ident;
788 	mactype_ops_t	*mtr_ops;
789 	uint_t		mtr_mactype;
790 	uint_t		mtr_nativetype;
791 	uint_t		mtr_addrlen;
792 	uint8_t		*mtr_brdcst_addr;
793 	mac_stat_info_t	*mtr_stats;
794 	size_t		mtr_statcount;
795 	mac_ndd_mapping_t *mtr_mapping;
796 	size_t		mtr_mappingcount;
797 } mactype_register_t;
798 
799 typedef struct mac_prop_s {
800 	mac_prop_id_t	mp_id;
801 	char		*mp_name;
802 	uint_t		mp_flags;
803 } mac_prop_t;
804 
805 /*
806  * Client interface functions.
807  */
808 extern int			mac_open(const char *, mac_handle_t *);
809 extern int			mac_open_by_linkid(datalink_id_t,
810 				    mac_handle_t *);
811 extern int			mac_open_by_linkname(const char *,
812 				    mac_handle_t *);
813 extern void			mac_close(mac_handle_t);
814 extern const mac_info_t		*mac_info(mac_handle_t);
815 extern boolean_t		mac_info_get(const char *, mac_info_t *);
816 extern uint64_t			mac_stat_get(mac_handle_t, uint_t);
817 extern int			mac_start(mac_handle_t);
818 extern void			mac_stop(mac_handle_t);
819 extern int			mac_promisc_set(mac_handle_t, boolean_t,
820 				    mac_promisc_type_t);
821 extern boolean_t		mac_promisc_get(mac_handle_t,
822 				    mac_promisc_type_t);
823 extern int 			mac_multicst_add(mac_handle_t, const uint8_t *);
824 extern int 			mac_multicst_remove(mac_handle_t,
825 				    const uint8_t *);
826 extern boolean_t		mac_unicst_verify(mac_handle_t,
827 				    const uint8_t *, uint_t);
828 extern int			mac_unicst_set(mac_handle_t, const uint8_t *);
829 extern void			mac_unicst_get(mac_handle_t, uint8_t *);
830 extern void			mac_dest_get(mac_handle_t, uint8_t *);
831 extern void			mac_sdu_get(mac_handle_t, uint_t *, uint_t *);
832 extern void			mac_resources(mac_handle_t);
833 extern void			mac_ioctl(mac_handle_t, queue_t *, mblk_t *);
834 extern const mac_txinfo_t	*mac_tx_get(mac_handle_t);
835 extern const mac_txinfo_t	*mac_vnic_tx_get(mac_handle_t);
836 extern link_state_t		mac_link_get(mac_handle_t);
837 extern mac_notify_handle_t	mac_notify_add(mac_handle_t, mac_notify_t,
838 				    void *);
839 extern void			mac_notify_remove(mac_handle_t,
840 				    mac_notify_handle_t);
841 extern void			mac_notify(mac_handle_t);
842 extern mac_rx_handle_t		mac_rx_add(mac_handle_t, mac_rx_t, void *);
843 extern mac_rx_handle_t		mac_active_rx_add(mac_handle_t, mac_rx_t,
844 				    void *);
845 extern void			mac_rx_remove(mac_handle_t, mac_rx_handle_t,
846 				    boolean_t);
847 extern void			mac_rx_remove_wait(mac_handle_t);
848 extern mblk_t			*mac_txloop(void *, mblk_t *);
849 extern mac_txloop_handle_t	mac_txloop_add(mac_handle_t, mac_txloop_t,
850 				    void *);
851 extern void			mac_txloop_remove(mac_handle_t,
852 				    mac_txloop_handle_t);
853 extern boolean_t		mac_active_set(mac_handle_t);
854 extern boolean_t		mac_active_shareable_set(mac_handle_t);
855 extern void			mac_active_clear(mac_handle_t);
856 extern void			mac_active_rx(void *, mac_resource_handle_t,
857 				    mblk_t *);
858 extern boolean_t		mac_vnic_set(mac_handle_t, mac_txinfo_t *,
859 				    mac_getcapab_t, void *);
860 extern void			mac_vnic_clear(mac_handle_t);
861 extern void			mac_resource_set(mac_handle_t,
862 				    mac_resource_add_t, void *);
863 extern dev_info_t		*mac_devinfo_get(mac_handle_t);
864 extern const char		*mac_name(mac_handle_t);
865 extern minor_t			mac_minor(mac_handle_t);
866 extern boolean_t		mac_capab_get(mac_handle_t, mac_capab_t,
867 				    void *);
868 extern boolean_t		mac_vnic_capab_get(mac_handle_t, mac_capab_t,
869 				    void *);
870 extern boolean_t		mac_sap_verify(mac_handle_t, uint32_t,
871 				    uint32_t *);
872 extern mblk_t			*mac_header(mac_handle_t, const uint8_t *,
873 				    uint32_t, mblk_t *, size_t);
874 extern int			mac_header_info(mac_handle_t, mblk_t *,
875 				    mac_header_info_t *);
876 extern mblk_t			*mac_header_cook(mac_handle_t, mblk_t *);
877 extern mblk_t			*mac_header_uncook(mac_handle_t, mblk_t *);
878 extern minor_t			mac_minor_hold(boolean_t);
879 extern void			mac_minor_rele(minor_t);
880 
881 /*
882  * Driver interface functions.
883  */
884 extern mac_register_t		*mac_alloc(uint_t);
885 extern void			mac_free(mac_register_t *);
886 extern int			mac_register(mac_register_t *, mac_handle_t *);
887 extern int			mac_disable(mac_handle_t);
888 extern int  			mac_unregister(mac_handle_t);
889 extern void 			mac_rx(mac_handle_t, mac_resource_handle_t,
890 				    mblk_t *);
891 extern void 			mac_link_update(mac_handle_t, link_state_t);
892 extern void 			mac_unicst_update(mac_handle_t,
893 				    const uint8_t *);
894 extern void			mac_tx_update(mac_handle_t);
895 extern void			mac_resource_update(mac_handle_t);
896 extern mac_resource_handle_t	mac_resource_add(mac_handle_t,
897 				    mac_resource_t *);
898 extern int			mac_maxsdu_update(mac_handle_t, uint_t);
899 extern int			mac_pdata_update(mac_handle_t, void *,
900 				    size_t);
901 extern void			mac_multicst_refresh(mac_handle_t,
902 				    mac_multicst_t, void *, boolean_t);
903 extern void			mac_unicst_refresh(mac_handle_t, mac_unicst_t,
904 				    void *);
905 extern void			mac_promisc_refresh(mac_handle_t,
906 				    mac_setpromisc_t, void *);
907 extern boolean_t		mac_margin_update(mac_handle_t, uint32_t);
908 extern void			mac_margin_get(mac_handle_t, uint32_t *);
909 extern int			mac_margin_remove(mac_handle_t, uint32_t);
910 extern int			mac_margin_add(mac_handle_t, uint32_t *,
911 				    boolean_t);
912 extern void			mac_init_ops(struct dev_ops *, const char *);
913 extern void			mac_fini_ops(struct dev_ops *);
914 extern uint32_t			mac_no_notification(mac_handle_t);
915 extern boolean_t		mac_is_legacy(mac_handle_t);
916 extern int			mac_hold_exclusive(mac_handle_t);
917 extern void			mac_rele_exclusive(mac_handle_t);
918 
919 extern mactype_register_t	*mactype_alloc(uint_t);
920 extern void			mactype_free(mactype_register_t *);
921 extern int			mactype_register(mactype_register_t *);
922 extern int			mactype_unregister(const char *);
923 extern int			mac_set_prop(mac_handle_t, mac_prop_t *,
924 				    void *, uint_t);
925 extern int			mac_get_prop(mac_handle_t, mac_prop_t *,
926 				    void *, uint_t);
927 
928 #endif	/* _KERNEL */
929 
930 #ifdef	__cplusplus
931 }
932 #endif
933 
934 #endif /* _SYS_MAC_H */
935