xref: /illumos-gate/usr/src/uts/common/sys/mac.h (revision 2a690de65126520928618d79f73d5c0e4e573351)
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) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Copyright 2018 Joyent, Inc.
25  * Copyright (c) 2015 Garrett D'Amore <garrett@damore.org>
26  * Copyright 2020 RackTop Systems, Inc.
27  */
28 
29 #ifndef	_SYS_MAC_H
30 #define	_SYS_MAC_H
31 
32 #include <sys/types.h>
33 #ifdef	_KERNEL
34 #include <sys/sunddi.h>
35 #endif
36 
37 /*
38  * MAC Services Module
39  */
40 
41 #ifdef	__cplusplus
42 extern "C" {
43 #endif
44 
45 /*
46  * MAC Information (text emitted by modinfo(8))
47  */
48 #define	MAC_INFO	"MAC Services"
49 
50 /*
51  * MAC-Type version identifier.  This is used by mactype_alloc() and
52  * mactype_register() to verify that incompatible MAC-Type plugins don't
53  * register.
54  */
55 #define	MACTYPE_VERSION	0x1
56 
57 /*
58  * Opaque handle types
59  */
60 typedef struct __mac_handle		*mac_handle_t;
61 typedef struct __mac_resource_handle	*mac_resource_handle_t;
62 typedef struct __mac_notify_handle	*mac_notify_handle_t;
63 typedef struct __mac_tx_notify_handle	*mac_tx_notify_handle_t;
64 typedef	struct __mac_intr_handle	*mac_intr_handle_t;
65 typedef	struct __mac_ring_handle	*mac_ring_handle_t;
66 typedef	struct __mac_group_handle	*mac_group_handle_t;
67 
68 #define	DATALINK_INVALID_LINKID	0
69 #define	DATALINK_ALL_LINKID	0
70 #define	DATALINK_MAX_LINKID	0xffffffff
71 
72 typedef enum {
73 	LINK_STATE_UNKNOWN = -1,
74 	LINK_STATE_DOWN,
75 	LINK_STATE_UP
76 } link_state_t;
77 
78 typedef enum {
79 	LINK_DUPLEX_UNKNOWN = 0,
80 	LINK_DUPLEX_HALF,
81 	LINK_DUPLEX_FULL
82 } link_duplex_t;
83 
84 typedef enum {
85 	LINK_FLOWCTRL_NONE = 0,
86 	LINK_FLOWCTRL_RX,
87 	LINK_FLOWCTRL_TX,
88 	LINK_FLOWCTRL_BI
89 } link_flowctrl_t;
90 
91 typedef enum {
92 	LINK_FEC_NONE		= 1 << 0,
93 	LINK_FEC_AUTO		= 1 << 1,
94 	LINK_FEC_RS		= 1 << 2,
95 	LINK_FEC_BASE_R		= 1 << 3
96 } link_fec_t;
97 
98 typedef enum {
99 	LINK_TAGMODE_VLANONLY = 0,
100 	LINK_TAGMODE_NORMAL
101 } link_tagmode_t;
102 
103 /*
104  * Defines range of uint32_t values
105  */
106 typedef struct mac_propval_uint32_range_s {
107 	uint32_t mpur_min;
108 	uint32_t mpur_max;
109 } mac_propval_uint32_range_t;
110 
111 /*
112  * Defines ranges which are a series of C style strings.
113  */
114 typedef struct mac_propval_str_range_s {
115 	uint32_t mpur_nextbyte;
116 	char mpur_data[];
117 } mac_propval_str_range_t;
118 
119 /*
120  * Data type of property values.
121  */
122 typedef enum {
123 	MAC_PROPVAL_UINT8,
124 	MAC_PROPVAL_UINT32,
125 	MAC_PROPVAL_STR
126 } mac_propval_type_t;
127 
128 /*
129  * Captures possible values for a given property. A property can have
130  * range of values (int32, int64, uint32, uint64, et al) or collection/
131  * enumeration of values (strings).
132  * Can be used as a value-result parameter.
133  */
134 typedef struct mac_propval_range_s {
135 	uint_t mpr_count;			/* count of ranges */
136 	mac_propval_type_t mpr_type;		/* type of value */
137 	union {
138 		mac_propval_uint32_range_t mpr_uint32[1];
139 		mac_propval_str_range_t mpr_str;
140 	} u;
141 } mac_propval_range_t;
142 
143 #define	mpr_range_uint32	u.mpr_uint32
144 
145 /*
146  * Maximum MAC address length
147  */
148 #define	MAXMACADDRLEN		20
149 
150 #define	MPT_MAXMACADDR		32
151 
152 typedef struct mac_secondary_addr_s {
153 	uint32_t	ms_addrcnt;
154 	uint8_t		ms_addrs[MPT_MAXMACADDR][MAXMACADDRLEN];
155 } mac_secondary_addr_t;
156 
157 typedef enum {
158 	MAC_LOGTYPE_LINK = 1,
159 	MAC_LOGTYPE_FLOW
160 } mac_logtype_t;
161 
162 #define	MAXLINKPROPNAME		256		/* max property name len */
163 
164 /*
165  * Public properties.
166  *
167  * Note that there are 2 sets of parameters: the *_EN_* values are
168  * those that the Administrator configures for autonegotiation. The
169  * _ADV_* values are those that are currently exposed over the wire.
170  *
171  * Please append properties to the end of this list. Do not reorder the list.
172  */
173 typedef enum {
174 	MAC_PROP_PRIVATE = -1,
175 	MAC_PROP_DUPLEX = 0x00000001,
176 	MAC_PROP_SPEED,
177 	MAC_PROP_STATUS,
178 	MAC_PROP_AUTONEG,
179 	MAC_PROP_EN_AUTONEG,
180 	MAC_PROP_MTU,
181 	MAC_PROP_ZONE,
182 	MAC_PROP_AUTOPUSH,
183 	MAC_PROP_FLOWCTRL,
184 	MAC_PROP_ADV_1000FDX_CAP,
185 	MAC_PROP_EN_1000FDX_CAP,
186 	MAC_PROP_ADV_1000HDX_CAP,
187 	MAC_PROP_EN_1000HDX_CAP,
188 	MAC_PROP_ADV_100FDX_CAP,
189 	MAC_PROP_EN_100FDX_CAP,
190 	MAC_PROP_ADV_100HDX_CAP,
191 	MAC_PROP_EN_100HDX_CAP,
192 	MAC_PROP_ADV_10FDX_CAP,
193 	MAC_PROP_EN_10FDX_CAP,
194 	MAC_PROP_ADV_10HDX_CAP,
195 	MAC_PROP_EN_10HDX_CAP,
196 	MAC_PROP_ADV_100T4_CAP,
197 	MAC_PROP_EN_100T4_CAP,
198 	MAC_PROP_IPTUN_HOPLIMIT,
199 	MAC_PROP_IPTUN_ENCAPLIMIT,
200 	MAC_PROP_WL_ESSID,
201 	MAC_PROP_WL_BSSID,
202 	MAC_PROP_WL_BSSTYPE,
203 	MAC_PROP_WL_LINKSTATUS,
204 	MAC_PROP_WL_DESIRED_RATES,
205 	MAC_PROP_WL_SUPPORTED_RATES,
206 	MAC_PROP_WL_AUTH_MODE,
207 	MAC_PROP_WL_ENCRYPTION,
208 	MAC_PROP_WL_RSSI,
209 	MAC_PROP_WL_PHY_CONFIG,
210 	MAC_PROP_WL_CAPABILITY,
211 	MAC_PROP_WL_WPA,
212 	MAC_PROP_WL_SCANRESULTS,
213 	MAC_PROP_WL_POWER_MODE,
214 	MAC_PROP_WL_RADIO,
215 	MAC_PROP_WL_ESS_LIST,
216 	MAC_PROP_WL_KEY_TAB,
217 	MAC_PROP_WL_CREATE_IBSS,
218 	MAC_PROP_WL_SETOPTIE,
219 	MAC_PROP_WL_DELKEY,
220 	MAC_PROP_WL_KEY,
221 	MAC_PROP_WL_MLME,
222 	MAC_PROP_TAGMODE,
223 	MAC_PROP_ADV_10GFDX_CAP,
224 	MAC_PROP_EN_10GFDX_CAP,
225 	MAC_PROP_PVID,
226 	MAC_PROP_LLIMIT,
227 	MAC_PROP_LDECAY,
228 	MAC_PROP_RESOURCE,
229 	MAC_PROP_RESOURCE_EFF,
230 	MAC_PROP_RXRINGSRANGE,
231 	MAC_PROP_TXRINGSRANGE,
232 	MAC_PROP_MAX_TX_RINGS_AVAIL,
233 	MAC_PROP_MAX_RX_RINGS_AVAIL,
234 	MAC_PROP_MAX_RXHWCLNT_AVAIL,
235 	MAC_PROP_MAX_TXHWCLNT_AVAIL,
236 	MAC_PROP_IB_LINKMODE,
237 	MAC_PROP_VN_PROMISC_FILTERED,
238 	MAC_PROP_SECONDARY_ADDRS,
239 	MAC_PROP_ADV_40GFDX_CAP,
240 	MAC_PROP_EN_40GFDX_CAP,
241 	MAC_PROP_ADV_100GFDX_CAP,
242 	MAC_PROP_EN_100GFDX_CAP,
243 	MAC_PROP_ADV_2500FDX_CAP,
244 	MAC_PROP_EN_2500FDX_CAP,
245 	MAC_PROP_ADV_5000FDX_CAP,
246 	MAC_PROP_EN_5000FDX_CAP,
247 	MAC_PROP_ADV_25GFDX_CAP,
248 	MAC_PROP_EN_25GFDX_CAP,
249 	MAC_PROP_ADV_50GFDX_CAP,
250 	MAC_PROP_EN_50GFDX_CAP,
251 	MAC_PROP_EN_FEC_CAP,
252 	MAC_PROP_ADV_FEC_CAP
253 } mac_prop_id_t;
254 
255 /*
256  * Flags to figure out r/w status of legacy ndd props.
257  */
258 #define	MAC_PROP_PERM_READ		0x0001
259 #define	MAC_PROP_PERM_WRITE		0x0010
260 #define	MAC_PROP_MAP_KSTAT		0x0100
261 #define	MAC_PROP_PERM_RW		(MAC_PROP_PERM_READ|MAC_PROP_PERM_WRITE)
262 #define	MAC_PROP_FLAGS_RK		(MAC_PROP_PERM_READ|MAC_PROP_MAP_KSTAT)
263 
264 /*
265  * Valid LED mode bits
266  */
267 typedef enum mac_led_mode {
268 	MAC_LED_DEFAULT	= (1 << 0),
269 	MAC_LED_OFF	= (1 << 1),
270 	MAC_LED_IDENT	= (1 << 2),
271 	MAC_LED_ON	= (1 << 3)
272 } mac_led_mode_t;
273 
274 
275 #ifdef	_KERNEL
276 
277 /*
278  * There are three ranges of statistics values.  0 to 1 - MAC_STAT_MIN are
279  * interface statistics maintained by the mac module.  MAC_STAT_MIN to 1 -
280  * MACTYPE_STAT_MIN are common MAC statistics defined by the mac module and
281  * maintained by each driver.  MACTYPE_STAT_MIN and above are statistics
282  * defined by MAC-Type plugins and maintained by each driver.
283  */
284 #define	MAC_STAT_MIN		1000
285 #define	MACTYPE_STAT_MIN	2000
286 
287 #define	IS_MAC_STAT(stat)	\
288 	(stat >= MAC_STAT_MIN && stat < MACTYPE_STAT_MIN)
289 #define	IS_MACTYPE_STAT(stat)	(stat >= MACTYPE_STAT_MIN)
290 
291 /*
292  * Statistics maintained by the mac module, and possibly populated as link
293  * statistics.
294  */
295 enum mac_mod_stat {
296 	MAC_STAT_LINK_STATE,
297 	MAC_STAT_LINK_UP,
298 	MAC_STAT_PROMISC,
299 	MAC_STAT_LOWLINK_STATE,
300 	MAC_STAT_HDROPS
301 };
302 
303 /*
304  * Do not reorder, and add only to the end of this list.
305  */
306 enum mac_driver_stat {
307 	/* MIB-II stats (RFC 1213 and RFC 1573) */
308 	MAC_STAT_IFSPEED = MAC_STAT_MIN,
309 	MAC_STAT_MULTIRCV,
310 	MAC_STAT_BRDCSTRCV,
311 	MAC_STAT_MULTIXMT,
312 	MAC_STAT_BRDCSTXMT,
313 	MAC_STAT_NORCVBUF,
314 	MAC_STAT_IERRORS,
315 	MAC_STAT_UNKNOWNS,
316 	MAC_STAT_NOXMTBUF,
317 	MAC_STAT_OERRORS,
318 	MAC_STAT_COLLISIONS,
319 	MAC_STAT_RBYTES,
320 	MAC_STAT_IPACKETS,
321 	MAC_STAT_OBYTES,
322 	MAC_STAT_OPACKETS,
323 	MAC_STAT_UNDERFLOWS,
324 	MAC_STAT_OVERFLOWS
325 };
326 
327 #define	MAC_NSTAT	(MAC_STAT_OVERFLOWS - MAC_STAT_IFSPEED + 1)
328 
329 #define	MAC_STAT_ISACOUNTER(_stat) (		\
330 	    (_stat) == MAC_STAT_MULTIRCV ||	\
331 	    (_stat) == MAC_STAT_BRDCSTRCV ||	\
332 	    (_stat) == MAC_STAT_MULTIXMT ||	\
333 	    (_stat) == MAC_STAT_BRDCSTXMT ||	\
334 	    (_stat) == MAC_STAT_NORCVBUF ||	\
335 	    (_stat) == MAC_STAT_IERRORS ||	\
336 	    (_stat) == MAC_STAT_UNKNOWNS ||	\
337 	    (_stat) == MAC_STAT_NOXMTBUF ||	\
338 	    (_stat) == MAC_STAT_OERRORS ||	\
339 	    (_stat) == MAC_STAT_COLLISIONS ||	\
340 	    (_stat) == MAC_STAT_RBYTES ||	\
341 	    (_stat) == MAC_STAT_IPACKETS ||	\
342 	    (_stat) == MAC_STAT_OBYTES ||	\
343 	    (_stat) == MAC_STAT_OPACKETS ||	\
344 	    (_stat) == MAC_STAT_UNDERFLOWS ||	\
345 	    (_stat) == MAC_STAT_OVERFLOWS)
346 
347 /*
348  * Immutable information. (This may not be modified after registration).
349  */
350 typedef struct mac_info_s {
351 	uint_t		mi_media;
352 	uint_t		mi_nativemedia;
353 	uint_t		mi_addr_length;
354 	uint8_t		*mi_unicst_addr;
355 	uint8_t		*mi_brdcst_addr;
356 } mac_info_t;
357 
358 /*
359  * When VNICs are created on top of the NIC, there are two levels
360  * of MAC layer, a lower MAC, which is the MAC layer at the level of the
361  * physical NIC, and an upper MAC, which is the MAC layer at the level
362  * of the VNIC. Each VNIC maps to a MAC client at the lower MAC, and
363  * the SRS and classification is done at the lower MAC level. The upper
364  * MAC is therefore for the most part pass-through, and therefore
365  * special processing needs to be done at the upper MAC layer when
366  * dealing with a VNIC.
367  *
368  * This capability allows the MAC layer to detect when a VNIC is being
369  * access, and implement the required shortcuts.
370  *
371  * In addition, this capability is used to keep the VNIC's secondary
372  * mac_clients in sync when the primary MAC is updated.
373  */
374 
375 typedef void *(*mac_client_handle_fn_t)(void *);
376 typedef void (*mac_client_update_fn_t)(void *);
377 
378 typedef struct mac_capab_vnic_s {
379 	void			*mcv_arg;
380 	mac_client_handle_fn_t	mcv_mac_client_handle;
381 	mac_client_update_fn_t	mcv_mac_secondary_update;
382 } mac_capab_vnic_t;
383 
384 typedef void (*mac_rename_fn_t)(const char *, void *);
385 typedef mblk_t *(*mac_tx_ring_fn_t)(void *, mblk_t *, uintptr_t,
386     mac_ring_handle_t *);
387 typedef struct mac_capab_aggr_s {
388 	mac_rename_fn_t mca_rename_fn;
389 	int (*mca_unicst)(void *, const uint8_t *);
390 	mac_tx_ring_fn_t mca_find_tx_ring_fn;
391 	void *mca_arg;
392 } mac_capab_aggr_t;
393 
394 /* Bridge transmit and receive function signatures */
395 typedef mblk_t *(*mac_bridge_tx_t)(mac_handle_t, mac_ring_handle_t, mblk_t *);
396 typedef void (*mac_bridge_rx_t)(mac_handle_t, mac_resource_handle_t, mblk_t *);
397 typedef void (*mac_bridge_ref_t)(mac_handle_t, boolean_t);
398 typedef link_state_t (*mac_bridge_ls_t)(mac_handle_t, link_state_t);
399 
400 /* must change mac_notify_cb_list[] in mac_provider.c if this is changed */
401 typedef enum {
402 	MAC_NOTE_LINK,
403 	MAC_NOTE_UNICST,
404 	MAC_NOTE_TX,
405 	MAC_NOTE_DEVPROMISC,
406 	MAC_NOTE_FASTPATH_FLUSH,
407 	MAC_NOTE_SDU_SIZE,
408 	MAC_NOTE_DEST,
409 	MAC_NOTE_MARGIN,
410 	MAC_NOTE_CAPAB_CHG,
411 	MAC_NOTE_LOWLINK,
412 	MAC_NOTE_ALLOWED_IPS,
413 	MAC_NNOTE	/* must be the last entry */
414 } mac_notify_type_t;
415 
416 typedef void		(*mac_notify_t)(void *, mac_notify_type_t);
417 typedef void		(*mac_rx_t)(void *, mac_resource_handle_t, mblk_t *,
418 			    boolean_t);
419 typedef	mblk_t		*(*mac_receive_t)(void *, size_t);
420 
421 /*
422  * MAC resource types
423  */
424 typedef enum {
425 	MAC_RX_FIFO = 1
426 } mac_resource_type_t;
427 
428 typedef	int	(*mac_intr_enable_t)(mac_intr_handle_t);
429 typedef	int	(*mac_intr_disable_t)(mac_intr_handle_t);
430 
431 typedef	struct mac_intr_s {
432 	mac_intr_handle_t	mi_handle;
433 	mac_intr_enable_t	mi_enable;
434 	mac_intr_disable_t	mi_disable;
435 	ddi_intr_handle_t	mi_ddi_handle;
436 	boolean_t		mi_ddi_shared;
437 } mac_intr_t;
438 
439 typedef struct mac_rx_fifo_s {
440 	mac_resource_type_t	mrf_type;	/* MAC_RX_FIFO */
441 	mac_intr_t		mrf_intr;
442 	mac_receive_t		mrf_receive;
443 	void			*mrf_rx_arg;
444 	uint32_t		mrf_flow_priority;
445 	/*
446 	 * The CPU this flow is to be processed on. With intrd and future
447 	 * things, we should know which CPU the flow needs to be processed
448 	 * and get a squeue assigned on that CPU.
449 	 */
450 	uint_t			mrf_cpu_id;
451 } mac_rx_fifo_t;
452 
453 #define	mrf_intr_handle		mrf_intr.mi_handle
454 #define	mrf_intr_enable		mrf_intr.mi_enable
455 #define	mrf_intr_disable	mrf_intr.mi_disable
456 
457 typedef union mac_resource_u {
458 	mac_resource_type_t	mr_type;
459 	mac_rx_fifo_t		mr_fifo;
460 } mac_resource_t;
461 
462 typedef enum {
463 	MAC_ADDRTYPE_UNICAST,
464 	MAC_ADDRTYPE_MULTICAST,
465 	MAC_ADDRTYPE_BROADCAST
466 } mac_addrtype_t;
467 
468 typedef struct mac_header_info_s {
469 	size_t		mhi_hdrsize;
470 	size_t		mhi_pktsize;
471 	const uint8_t	*mhi_daddr;
472 	const uint8_t	*mhi_saddr;
473 	uint32_t	mhi_origsap;
474 	uint32_t	mhi_bindsap;
475 	mac_addrtype_t	mhi_dsttype;
476 	uint16_t	mhi_tci;
477 	boolean_t	mhi_istagged;
478 	boolean_t	mhi_ispvid;
479 } mac_header_info_t;
480 
481 /*
482  * Function pointer to match dls client signature. Should be same as
483  * dls_rx_t to allow a soft ring to bypass DLS layer and call a DLS
484  * client directly.
485  */
486 typedef	void		(*mac_direct_rx_t)(void *, mac_resource_handle_t,
487 				mblk_t *, mac_header_info_t *);
488 
489 typedef mac_resource_handle_t	(*mac_resource_add_t)(void *, mac_resource_t *);
490 typedef int			(*mac_resource_bind_t)(void *,
491     mac_resource_handle_t, processorid_t);
492 typedef void			(*mac_resource_remove_t)(void *, void *);
493 typedef void			(*mac_resource_quiesce_t)(void *, void *);
494 typedef void			(*mac_resource_restart_t)(void *, void *);
495 typedef int			(*mac_resource_modify_t)(void *, void *,
496 				    mac_resource_t *);
497 typedef	void			(*mac_change_upcall_t)(void *, mac_direct_rx_t,
498     void *);
499 
500 /*
501  * MAC-Type plugin interfaces
502  */
503 
504 typedef int		(*mtops_addr_verify_t)(const void *, void *);
505 typedef boolean_t	(*mtops_sap_verify_t)(uint32_t, uint32_t *, void *);
506 typedef mblk_t		*(*mtops_header_t)(const void *, const void *,
507     uint32_t, void *, mblk_t *, size_t);
508 typedef int		(*mtops_header_info_t)(mblk_t *, void *,
509     mac_header_info_t *);
510 typedef boolean_t	(*mtops_pdata_verify_t)(void *, size_t);
511 typedef	mblk_t		*(*mtops_header_modify_t)(mblk_t *, void *);
512 typedef void		(*mtops_link_details_t)(char *, size_t, mac_handle_t,
513     void *);
514 
515 typedef struct mactype_ops_s {
516 	uint_t			mtops_ops;
517 	/*
518 	 * mtops_unicst_verify() returns 0 if the given address is a valid
519 	 * unicast address, or a non-zero errno otherwise.
520 	 */
521 	mtops_addr_verify_t	mtops_unicst_verify;
522 	/*
523 	 * mtops_multicst_verify() returns 0 if the given address is a
524 	 * valid multicast address, or a non-zero errno otherwise.  If the
525 	 * media doesn't support multicast, ENOTSUP should be returned (for
526 	 * example).
527 	 */
528 	mtops_addr_verify_t	mtops_multicst_verify;
529 	/*
530 	 * mtops_sap_verify() returns B_TRUE if the given SAP is a valid
531 	 * SAP value, or B_FALSE otherwise.
532 	 */
533 	mtops_sap_verify_t	mtops_sap_verify;
534 	/*
535 	 * mtops_header() is used to allocate and construct a MAC header.
536 	 */
537 	mtops_header_t		mtops_header;
538 	/*
539 	 * mtops_header_info() is used to gather information on a given MAC
540 	 * header.
541 	 */
542 	mtops_header_info_t	mtops_header_info;
543 	/*
544 	 * mtops_pdata_verify() is used to verify the validity of MAC
545 	 * plugin data.  It is called by mac_register() if the driver has
546 	 * supplied MAC plugin data, and also by mac_pdata_update() when
547 	 * drivers update the data.
548 	 */
549 	mtops_pdata_verify_t	mtops_pdata_verify;
550 	/*
551 	 * mtops_header_cook() is an optional callback that converts (or
552 	 * "cooks") the given raw header (as sent by a raw DLPI consumer)
553 	 * into one that is appropriate to send down to the MAC driver.
554 	 * Following the example above, an Ethernet header sent down by a
555 	 * DLPI consumer would be converted to whatever header the MAC
556 	 * driver expects.
557 	 */
558 	mtops_header_modify_t	mtops_header_cook;
559 	/*
560 	 * mtops_header_uncook() is an optional callback that does the
561 	 * opposite of mtops_header_cook().  It "uncooks" a given MAC
562 	 * header (as received from the driver) for consumption by raw DLPI
563 	 * consumers.  For example, for a non-Ethernet plugin that wants
564 	 * raw DLPI consumers to be fooled into thinking that the device
565 	 * provides Ethernet access, this callback would modify the given
566 	 * mblk_t such that the MAC header is converted to an Ethernet
567 	 * header.
568 	 */
569 	mtops_header_modify_t	mtops_header_uncook;
570 	/*
571 	 * mtops_link_details() is an optional callback that provides
572 	 * extended information about the link state.  Its primary purpose
573 	 * is to provide type-specific support for syslog contents on
574 	 * link up events.  If no implementation is provided, then a default
575 	 * implementation will be used.
576 	 */
577 	mtops_link_details_t	mtops_link_details;
578 } mactype_ops_t;
579 
580 /*
581  * mtops_ops exists for the plugin to enumerate the optional callback
582  * entrypoints it has defined.  This allows the mac module to define
583  * additional plugin entrypoints in mactype_ops_t without breaking backward
584  * compatibility with old plugins.
585  */
586 #define	MTOPS_PDATA_VERIFY	0x001
587 #define	MTOPS_HEADER_COOK	0x002
588 #define	MTOPS_HEADER_UNCOOK	0x004
589 #define	MTOPS_LINK_DETAILS	0x008
590 
591 /*
592  * Provide mapping for legacy ndd ioctls relevant to that mactype.
593  * Note that the ndd ioctls are obsolete, and may be removed in a future
594  * release of Solaris. The ndd ioctls are not typically used in legacy
595  * ethernet drivers. New datalink drivers of all link-types should use
596  * dladm(8) interfaces for administering tunables and not have to provide
597  * a mapping.
598  */
599 typedef struct mac_ndd_mapping_s {
600 	char		*mp_name;
601 	union {
602 		mac_prop_id_t   u_id;
603 		uint_t		u_kstat;
604 	} u_mp_id;
605 	long		mp_minval;
606 	long		mp_maxval;
607 	size_t		mp_valsize;
608 	int		mp_flags;
609 } mac_ndd_mapping_t;
610 
611 #define	mp_prop_id	u_mp_id.u_id
612 #define	mp_kstat	u_mp_id.u_kstat
613 
614 typedef struct mac_stat_info_s {
615 	uint_t		msi_stat;
616 	char		*msi_name;
617 	uint_t		msi_type;	/* as defined in kstat_named_init(9F) */
618 	uint64_t	msi_default;
619 } mac_stat_info_t;
620 
621 typedef struct mactype_register_s {
622 	uint_t		mtr_version;	/* set by mactype_alloc() */
623 	const char	*mtr_ident;
624 	mactype_ops_t	*mtr_ops;
625 	uint_t		mtr_mactype;
626 	uint_t		mtr_nativetype;
627 	uint_t		mtr_addrlen;
628 	uint8_t		*mtr_brdcst_addr;
629 	mac_stat_info_t	*mtr_stats;
630 	size_t		mtr_statcount;
631 	mac_ndd_mapping_t *mtr_mapping;
632 	size_t		mtr_mappingcount;
633 } mactype_register_t;
634 
635 /*
636  * Flags to describe the hardware emulation desired from a client when
637  * calling mac_hw_emul().
638  *
639  * MAC_HWCKSUM_EMUL
640  *
641  *	If an mblk is marked with HCK_* flags, then calculate those
642  *	checksums and update the checksum flags.
643  *
644  * MAC_IPCKSUM_EMUL
645  *
646  *	Like MAC_HWCKSUM_EMUL, except only calculate the IPv4 header
647  *	checksum. We still update both the IPv4 and ULP checksum
648  *	flags.
649  *
650  * MAC_LSO_EMUL
651  *
652  *	If an mblk is marked with HW_LSO, then segment the LSO mblk
653  *	into a new chain of mblks which reference the original data
654  *	block. This flag DOES NOT imply MAC_HWCKSUM_EMUL. If the
655  *	caller needs both then it must set both.
656  */
657 typedef enum mac_emul {
658 	MAC_HWCKSUM_EMUL = (1 << 0),
659 	MAC_IPCKSUM_EMUL = (1 << 1),
660 	MAC_LSO_EMUL = (1 << 2)
661 } mac_emul_t;
662 
663 #define	MAC_HWCKSUM_EMULS	(MAC_HWCKSUM_EMUL | MAC_IPCKSUM_EMUL)
664 #define	MAC_ALL_EMULS		(MAC_HWCKSUM_EMUL | MAC_IPCKSUM_EMUL | \
665 				MAC_LSO_EMUL)
666 
667 /*
668  * Driver interface functions.
669  */
670 extern int			mac_open_by_linkid(datalink_id_t,
671 				    mac_handle_t *);
672 extern int			mac_open_by_linkname(const char *,
673 				    mac_handle_t *);
674 extern const char		*mac_name(mac_handle_t);
675 extern minor_t			mac_minor(mac_handle_t);
676 extern minor_t			mac_minor_hold(boolean_t);
677 extern void			mac_minor_rele(minor_t);
678 extern void			mac_sdu_get(mac_handle_t, uint_t *, uint_t *);
679 extern void			mac_sdu_get2(mac_handle_t, uint_t *, uint_t *,
680 				    uint_t *);
681 extern int			mac_maxsdu_update(mac_handle_t, uint_t);
682 extern int			mac_maxsdu_update2(mac_handle_t, uint_t,
683 				    uint_t);
684 extern uint_t			mac_addr_len(mac_handle_t);
685 extern int			mac_type(mac_handle_t);
686 extern int			mac_nativetype(mac_handle_t);
687 
688 extern void			mac_unicst_update(mac_handle_t,
689 				    const uint8_t *);
690 extern void			mac_capab_update(mac_handle_t);
691 extern int			mac_pdata_update(mac_handle_t, void *,
692 				    size_t);
693 extern boolean_t		mac_margin_update(mac_handle_t, uint32_t);
694 extern void			mac_margin_get(mac_handle_t, uint32_t *);
695 extern int			mac_margin_remove(mac_handle_t, uint32_t);
696 extern int			mac_margin_add(mac_handle_t, uint32_t *,
697 				    boolean_t);
698 extern int			mac_mtu_add(mac_handle_t, uint32_t *,
699 				    boolean_t);
700 extern int			mac_mtu_remove(mac_handle_t, uint32_t);
701 extern int			mac_fastpath_disable(mac_handle_t);
702 extern void			mac_fastpath_enable(mac_handle_t);
703 extern void			mac_no_active(mac_handle_t);
704 
705 extern mactype_register_t	*mactype_alloc(uint_t);
706 extern void			mactype_free(mactype_register_t *);
707 extern int			mactype_register(mactype_register_t *);
708 extern int			mactype_unregister(const char *);
709 
710 extern int			mac_start_logusage(mac_logtype_t, uint_t);
711 extern void			mac_stop_logusage(mac_logtype_t);
712 
713 extern mac_handle_t		mac_get_lower_mac_handle(mac_handle_t);
714 extern boolean_t		mac_is_vnic_primary(mac_handle_t);
715 
716 /*
717  * Packet hashing for distribution to multiple ports and rings.
718  */
719 
720 #define	MAC_PKT_HASH_L2		0x01
721 #define	MAC_PKT_HASH_L3		0x02
722 #define	MAC_PKT_HASH_L4		0x04
723 
724 extern uint64_t			mac_pkt_hash(uint_t, mblk_t *, uint8_t,
725 				    boolean_t);
726 
727 /*
728  * Bridging linkage
729  */
730 extern void			mac_rx_common(mac_handle_t,
731 				    mac_resource_handle_t, mblk_t *);
732 extern int			mac_bridge_set(mac_handle_t, mac_handle_t);
733 extern void			mac_bridge_clear(mac_handle_t, mac_handle_t);
734 extern void			mac_bridge_vectors(mac_bridge_tx_t,
735 				    mac_bridge_rx_t, mac_bridge_ref_t,
736 				    mac_bridge_ls_t);
737 
738 /* special case function for TRILL observability */
739 extern void			mac_trill_snoop(mac_handle_t, mblk_t *);
740 
741 #endif	/* _KERNEL */
742 
743 #ifdef	__cplusplus
744 }
745 #endif
746 
747 #endif /* _SYS_MAC_H */
748