xref: /illumos-gate/usr/src/uts/common/sys/mac.h (revision 2aaafd60)
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_MEDIA,
254 	MAC_PROP_ADV_200GFDX_CAP,
255 	MAC_PROP_EN_200GFDX_CAP,
256 	MAC_PROP_ADV_400GFDX_CAP,
257 	MAC_PROP_EN_400GFDX_CAP,
258 } mac_prop_id_t;
259 
260 /*
261  * Flags to figure out r/w status of legacy ndd props.
262  */
263 #define	MAC_PROP_PERM_READ		0x0001
264 #define	MAC_PROP_PERM_WRITE		0x0010
265 #define	MAC_PROP_MAP_KSTAT		0x0100
266 #define	MAC_PROP_PERM_RW		(MAC_PROP_PERM_READ|MAC_PROP_PERM_WRITE)
267 #define	MAC_PROP_FLAGS_RK		(MAC_PROP_PERM_READ|MAC_PROP_MAP_KSTAT)
268 
269 /*
270  * Valid LED mode bits
271  */
272 typedef enum mac_led_mode {
273 	MAC_LED_DEFAULT	= (1 << 0),
274 	MAC_LED_OFF	= (1 << 1),
275 	MAC_LED_IDENT	= (1 << 2),
276 	MAC_LED_ON	= (1 << 3)
277 } mac_led_mode_t;
278 
279 
280 #ifdef	_KERNEL
281 
282 /*
283  * There are three ranges of statistics values.  0 to 1 - MAC_STAT_MIN are
284  * interface statistics maintained by the mac module.  MAC_STAT_MIN to 1 -
285  * MACTYPE_STAT_MIN are common MAC statistics defined by the mac module and
286  * maintained by each driver.  MACTYPE_STAT_MIN and above are statistics
287  * defined by MAC-Type plugins and maintained by each driver.
288  */
289 #define	MAC_STAT_MIN		1000
290 #define	MACTYPE_STAT_MIN	2000
291 
292 #define	IS_MAC_STAT(stat)	\
293 	(stat >= MAC_STAT_MIN && stat < MACTYPE_STAT_MIN)
294 #define	IS_MACTYPE_STAT(stat)	(stat >= MACTYPE_STAT_MIN)
295 
296 /*
297  * Statistics maintained by the mac module, and possibly populated as link
298  * statistics.
299  */
300 enum mac_mod_stat {
301 	MAC_STAT_LINK_STATE,
302 	MAC_STAT_LINK_UP,
303 	MAC_STAT_PROMISC,
304 	MAC_STAT_LOWLINK_STATE,
305 	MAC_STAT_HDROPS
306 };
307 
308 /*
309  * Do not reorder, and add only to the end of this list.
310  */
311 enum mac_driver_stat {
312 	/* MIB-II stats (RFC 1213 and RFC 1573) */
313 	MAC_STAT_IFSPEED = MAC_STAT_MIN,
314 	MAC_STAT_MULTIRCV,
315 	MAC_STAT_BRDCSTRCV,
316 	MAC_STAT_MULTIXMT,
317 	MAC_STAT_BRDCSTXMT,
318 	MAC_STAT_NORCVBUF,
319 	MAC_STAT_IERRORS,
320 	MAC_STAT_UNKNOWNS,
321 	MAC_STAT_NOXMTBUF,
322 	MAC_STAT_OERRORS,
323 	MAC_STAT_COLLISIONS,
324 	MAC_STAT_RBYTES,
325 	MAC_STAT_IPACKETS,
326 	MAC_STAT_OBYTES,
327 	MAC_STAT_OPACKETS,
328 	MAC_STAT_UNDERFLOWS,
329 	MAC_STAT_OVERFLOWS
330 };
331 
332 #define	MAC_NSTAT	(MAC_STAT_OVERFLOWS - MAC_STAT_IFSPEED + 1)
333 
334 #define	MAC_STAT_ISACOUNTER(_stat) (		\
335 	    (_stat) == MAC_STAT_MULTIRCV ||	\
336 	    (_stat) == MAC_STAT_BRDCSTRCV ||	\
337 	    (_stat) == MAC_STAT_MULTIXMT ||	\
338 	    (_stat) == MAC_STAT_BRDCSTXMT ||	\
339 	    (_stat) == MAC_STAT_NORCVBUF ||	\
340 	    (_stat) == MAC_STAT_IERRORS ||	\
341 	    (_stat) == MAC_STAT_UNKNOWNS ||	\
342 	    (_stat) == MAC_STAT_NOXMTBUF ||	\
343 	    (_stat) == MAC_STAT_OERRORS ||	\
344 	    (_stat) == MAC_STAT_COLLISIONS ||	\
345 	    (_stat) == MAC_STAT_RBYTES ||	\
346 	    (_stat) == MAC_STAT_IPACKETS ||	\
347 	    (_stat) == MAC_STAT_OBYTES ||	\
348 	    (_stat) == MAC_STAT_OPACKETS ||	\
349 	    (_stat) == MAC_STAT_UNDERFLOWS ||	\
350 	    (_stat) == MAC_STAT_OVERFLOWS)
351 
352 /*
353  * Immutable information. (This may not be modified after registration).
354  */
355 typedef struct mac_info_s {
356 	uint_t		mi_media;
357 	uint_t		mi_nativemedia;
358 	uint_t		mi_addr_length;
359 	uint8_t		*mi_unicst_addr;
360 	uint8_t		*mi_brdcst_addr;
361 } mac_info_t;
362 
363 /*
364  * When VNICs are created on top of the NIC, there are two levels
365  * of MAC layer, a lower MAC, which is the MAC layer at the level of the
366  * physical NIC, and an upper MAC, which is the MAC layer at the level
367  * of the VNIC. Each VNIC maps to a MAC client at the lower MAC, and
368  * the SRS and classification is done at the lower MAC level. The upper
369  * MAC is therefore for the most part pass-through, and therefore
370  * special processing needs to be done at the upper MAC layer when
371  * dealing with a VNIC.
372  *
373  * This capability allows the MAC layer to detect when a VNIC is being
374  * access, and implement the required shortcuts.
375  *
376  * In addition, this capability is used to keep the VNIC's secondary
377  * mac_clients in sync when the primary MAC is updated.
378  */
379 
380 typedef void *(*mac_client_handle_fn_t)(void *);
381 typedef void (*mac_client_update_fn_t)(void *);
382 
383 typedef struct mac_capab_vnic_s {
384 	void			*mcv_arg;
385 	mac_client_handle_fn_t	mcv_mac_client_handle;
386 	mac_client_update_fn_t	mcv_mac_secondary_update;
387 } mac_capab_vnic_t;
388 
389 typedef void (*mac_rename_fn_t)(const char *, void *);
390 typedef mblk_t *(*mac_tx_ring_fn_t)(void *, mblk_t *, uintptr_t,
391     mac_ring_handle_t *);
392 typedef struct mac_capab_aggr_s {
393 	mac_rename_fn_t mca_rename_fn;
394 	int (*mca_unicst)(void *, const uint8_t *);
395 	mac_tx_ring_fn_t mca_find_tx_ring_fn;
396 	void *mca_arg;
397 } mac_capab_aggr_t;
398 
399 /* Bridge transmit and receive function signatures */
400 typedef mblk_t *(*mac_bridge_tx_t)(mac_handle_t, mac_ring_handle_t, mblk_t *);
401 typedef void (*mac_bridge_rx_t)(mac_handle_t, mac_resource_handle_t, mblk_t *);
402 typedef void (*mac_bridge_ref_t)(mac_handle_t, boolean_t);
403 typedef link_state_t (*mac_bridge_ls_t)(mac_handle_t, link_state_t);
404 
405 /* must change mac_notify_cb_list[] in mac_provider.c if this is changed */
406 typedef enum {
407 	MAC_NOTE_LINK,
408 	MAC_NOTE_UNICST,
409 	MAC_NOTE_TX,
410 	MAC_NOTE_DEVPROMISC,
411 	MAC_NOTE_FASTPATH_FLUSH,
412 	MAC_NOTE_SDU_SIZE,
413 	MAC_NOTE_DEST,
414 	MAC_NOTE_MARGIN,
415 	MAC_NOTE_CAPAB_CHG,
416 	MAC_NOTE_LOWLINK,
417 	MAC_NOTE_ALLOWED_IPS,
418 	MAC_NNOTE	/* must be the last entry */
419 } mac_notify_type_t;
420 
421 typedef void		(*mac_notify_t)(void *, mac_notify_type_t);
422 typedef void		(*mac_rx_t)(void *, mac_resource_handle_t, mblk_t *,
423 			    boolean_t);
424 typedef	mblk_t		*(*mac_receive_t)(void *, size_t);
425 
426 /*
427  * MAC resource types
428  */
429 typedef enum {
430 	MAC_RX_FIFO = 1
431 } mac_resource_type_t;
432 
433 typedef	int	(*mac_intr_enable_t)(mac_intr_handle_t);
434 typedef	int	(*mac_intr_disable_t)(mac_intr_handle_t);
435 
436 typedef	struct mac_intr_s {
437 	mac_intr_handle_t	mi_handle;
438 	mac_intr_enable_t	mi_enable;
439 	mac_intr_disable_t	mi_disable;
440 	ddi_intr_handle_t	mi_ddi_handle;
441 	boolean_t		mi_ddi_shared;
442 } mac_intr_t;
443 
444 typedef struct mac_rx_fifo_s {
445 	mac_resource_type_t	mrf_type;	/* MAC_RX_FIFO */
446 	mac_intr_t		mrf_intr;
447 	mac_receive_t		mrf_receive;
448 	void			*mrf_rx_arg;
449 	uint32_t		mrf_flow_priority;
450 	/*
451 	 * The CPU this flow is to be processed on. With intrd and future
452 	 * things, we should know which CPU the flow needs to be processed
453 	 * and get a squeue assigned on that CPU.
454 	 */
455 	uint_t			mrf_cpu_id;
456 } mac_rx_fifo_t;
457 
458 #define	mrf_intr_handle		mrf_intr.mi_handle
459 #define	mrf_intr_enable		mrf_intr.mi_enable
460 #define	mrf_intr_disable	mrf_intr.mi_disable
461 
462 typedef union mac_resource_u {
463 	mac_resource_type_t	mr_type;
464 	mac_rx_fifo_t		mr_fifo;
465 } mac_resource_t;
466 
467 typedef enum {
468 	MAC_ADDRTYPE_UNICAST,
469 	MAC_ADDRTYPE_MULTICAST,
470 	MAC_ADDRTYPE_BROADCAST
471 } mac_addrtype_t;
472 
473 typedef struct mac_header_info_s {
474 	size_t		mhi_hdrsize;
475 	size_t		mhi_pktsize;
476 	const uint8_t	*mhi_daddr;
477 	const uint8_t	*mhi_saddr;
478 	uint32_t	mhi_origsap;
479 	uint32_t	mhi_bindsap;
480 	mac_addrtype_t	mhi_dsttype;
481 	uint16_t	mhi_tci;
482 	boolean_t	mhi_istagged;
483 	boolean_t	mhi_ispvid;
484 } mac_header_info_t;
485 
486 /*
487  * Function pointer to match dls client signature. Should be same as
488  * dls_rx_t to allow a soft ring to bypass DLS layer and call a DLS
489  * client directly.
490  */
491 typedef	void		(*mac_direct_rx_t)(void *, mac_resource_handle_t,
492 				mblk_t *, mac_header_info_t *);
493 
494 typedef mac_resource_handle_t	(*mac_resource_add_t)(void *, mac_resource_t *);
495 typedef int			(*mac_resource_bind_t)(void *,
496     mac_resource_handle_t, processorid_t);
497 typedef void			(*mac_resource_remove_t)(void *, void *);
498 typedef void			(*mac_resource_quiesce_t)(void *, void *);
499 typedef void			(*mac_resource_restart_t)(void *, void *);
500 typedef int			(*mac_resource_modify_t)(void *, void *,
501 				    mac_resource_t *);
502 typedef	void			(*mac_change_upcall_t)(void *, mac_direct_rx_t,
503     void *);
504 
505 /*
506  * MAC-Type plugin interfaces
507  */
508 
509 typedef int		(*mtops_addr_verify_t)(const void *, void *);
510 typedef boolean_t	(*mtops_sap_verify_t)(uint32_t, uint32_t *, void *);
511 typedef mblk_t		*(*mtops_header_t)(const void *, const void *,
512     uint32_t, void *, mblk_t *, size_t);
513 typedef int		(*mtops_header_info_t)(mblk_t *, void *,
514     mac_header_info_t *);
515 typedef boolean_t	(*mtops_pdata_verify_t)(void *, size_t);
516 typedef	mblk_t		*(*mtops_header_modify_t)(mblk_t *, void *);
517 typedef void		(*mtops_link_details_t)(char *, size_t, mac_handle_t,
518     void *);
519 
520 typedef struct mactype_ops_s {
521 	uint_t			mtops_ops;
522 	/*
523 	 * mtops_unicst_verify() returns 0 if the given address is a valid
524 	 * unicast address, or a non-zero errno otherwise.
525 	 */
526 	mtops_addr_verify_t	mtops_unicst_verify;
527 	/*
528 	 * mtops_multicst_verify() returns 0 if the given address is a
529 	 * valid multicast address, or a non-zero errno otherwise.  If the
530 	 * media doesn't support multicast, ENOTSUP should be returned (for
531 	 * example).
532 	 */
533 	mtops_addr_verify_t	mtops_multicst_verify;
534 	/*
535 	 * mtops_sap_verify() returns B_TRUE if the given SAP is a valid
536 	 * SAP value, or B_FALSE otherwise.
537 	 */
538 	mtops_sap_verify_t	mtops_sap_verify;
539 	/*
540 	 * mtops_header() is used to allocate and construct a MAC header.
541 	 */
542 	mtops_header_t		mtops_header;
543 	/*
544 	 * mtops_header_info() is used to gather information on a given MAC
545 	 * header.
546 	 */
547 	mtops_header_info_t	mtops_header_info;
548 	/*
549 	 * mtops_pdata_verify() is used to verify the validity of MAC
550 	 * plugin data.  It is called by mac_register() if the driver has
551 	 * supplied MAC plugin data, and also by mac_pdata_update() when
552 	 * drivers update the data.
553 	 */
554 	mtops_pdata_verify_t	mtops_pdata_verify;
555 	/*
556 	 * mtops_header_cook() is an optional callback that converts (or
557 	 * "cooks") the given raw header (as sent by a raw DLPI consumer)
558 	 * into one that is appropriate to send down to the MAC driver.
559 	 * Following the example above, an Ethernet header sent down by a
560 	 * DLPI consumer would be converted to whatever header the MAC
561 	 * driver expects.
562 	 */
563 	mtops_header_modify_t	mtops_header_cook;
564 	/*
565 	 * mtops_header_uncook() is an optional callback that does the
566 	 * opposite of mtops_header_cook().  It "uncooks" a given MAC
567 	 * header (as received from the driver) for consumption by raw DLPI
568 	 * consumers.  For example, for a non-Ethernet plugin that wants
569 	 * raw DLPI consumers to be fooled into thinking that the device
570 	 * provides Ethernet access, this callback would modify the given
571 	 * mblk_t such that the MAC header is converted to an Ethernet
572 	 * header.
573 	 */
574 	mtops_header_modify_t	mtops_header_uncook;
575 	/*
576 	 * mtops_link_details() is an optional callback that provides
577 	 * extended information about the link state.  Its primary purpose
578 	 * is to provide type-specific support for syslog contents on
579 	 * link up events.  If no implementation is provided, then a default
580 	 * implementation will be used.
581 	 */
582 	mtops_link_details_t	mtops_link_details;
583 } mactype_ops_t;
584 
585 /*
586  * mtops_ops exists for the plugin to enumerate the optional callback
587  * entrypoints it has defined.  This allows the mac module to define
588  * additional plugin entrypoints in mactype_ops_t without breaking backward
589  * compatibility with old plugins.
590  */
591 #define	MTOPS_PDATA_VERIFY	0x001
592 #define	MTOPS_HEADER_COOK	0x002
593 #define	MTOPS_HEADER_UNCOOK	0x004
594 #define	MTOPS_LINK_DETAILS	0x008
595 
596 /*
597  * Provide mapping for legacy ndd ioctls relevant to that mactype.
598  * Note that the ndd ioctls are obsolete, and may be removed in a future
599  * release of Solaris. The ndd ioctls are not typically used in legacy
600  * ethernet drivers. New datalink drivers of all link-types should use
601  * dladm(8) interfaces for administering tunables and not have to provide
602  * a mapping.
603  */
604 typedef struct mac_ndd_mapping_s {
605 	char		*mp_name;
606 	union {
607 		mac_prop_id_t   u_id;
608 		uint_t		u_kstat;
609 	} u_mp_id;
610 	long		mp_minval;
611 	long		mp_maxval;
612 	size_t		mp_valsize;
613 	int		mp_flags;
614 } mac_ndd_mapping_t;
615 
616 #define	mp_prop_id	u_mp_id.u_id
617 #define	mp_kstat	u_mp_id.u_kstat
618 
619 typedef struct mac_stat_info_s {
620 	uint_t		msi_stat;
621 	char		*msi_name;
622 	uint_t		msi_type;	/* as defined in kstat_named_init(9F) */
623 	uint64_t	msi_default;
624 } mac_stat_info_t;
625 
626 typedef struct mactype_register_s {
627 	uint_t		mtr_version;	/* set by mactype_alloc() */
628 	const char	*mtr_ident;
629 	mactype_ops_t	*mtr_ops;
630 	uint_t		mtr_mactype;
631 	uint_t		mtr_nativetype;
632 	uint_t		mtr_addrlen;
633 	uint8_t		*mtr_brdcst_addr;
634 	mac_stat_info_t	*mtr_stats;
635 	size_t		mtr_statcount;
636 	mac_ndd_mapping_t *mtr_mapping;
637 	size_t		mtr_mappingcount;
638 } mactype_register_t;
639 
640 /*
641  * Flags to describe the hardware emulation desired from a client when
642  * calling mac_hw_emul().
643  *
644  * MAC_HWCKSUM_EMUL
645  *
646  *	If an mblk is marked with HCK_* flags, then calculate those
647  *	checksums and update the checksum flags.
648  *
649  * MAC_IPCKSUM_EMUL
650  *
651  *	Like MAC_HWCKSUM_EMUL, except only calculate the IPv4 header
652  *	checksum. We still update both the IPv4 and ULP checksum
653  *	flags.
654  *
655  * MAC_LSO_EMUL
656  *
657  *	If an mblk is marked with HW_LSO, then segment the LSO mblk
658  *	into a new chain of mblks which reference the original data
659  *	block. This flag DOES NOT imply MAC_HWCKSUM_EMUL. If the
660  *	caller needs both then it must set both.
661  */
662 typedef enum mac_emul {
663 	MAC_HWCKSUM_EMUL = (1 << 0),
664 	MAC_IPCKSUM_EMUL = (1 << 1),
665 	MAC_LSO_EMUL = (1 << 2)
666 } mac_emul_t;
667 
668 #define	MAC_HWCKSUM_EMULS	(MAC_HWCKSUM_EMUL | MAC_IPCKSUM_EMUL)
669 #define	MAC_ALL_EMULS		(MAC_HWCKSUM_EMUL | MAC_IPCKSUM_EMUL | \
670 				MAC_LSO_EMUL)
671 
672 /*
673  * Driver interface functions.
674  */
675 extern int			mac_open_by_linkid(datalink_id_t,
676 				    mac_handle_t *);
677 extern int			mac_open_by_linkname(const char *,
678 				    mac_handle_t *);
679 extern const char		*mac_name(mac_handle_t);
680 extern minor_t			mac_minor(mac_handle_t);
681 extern minor_t			mac_minor_hold(boolean_t);
682 extern void			mac_minor_rele(minor_t);
683 extern void			mac_sdu_get(mac_handle_t, uint_t *, uint_t *);
684 extern void			mac_sdu_get2(mac_handle_t, uint_t *, uint_t *,
685 				    uint_t *);
686 extern int			mac_maxsdu_update(mac_handle_t, uint_t);
687 extern int			mac_maxsdu_update2(mac_handle_t, uint_t,
688 				    uint_t);
689 extern uint_t			mac_addr_len(mac_handle_t);
690 extern int			mac_type(mac_handle_t);
691 extern int			mac_nativetype(mac_handle_t);
692 
693 extern void			mac_unicst_update(mac_handle_t,
694 				    const uint8_t *);
695 extern void			mac_capab_update(mac_handle_t);
696 extern int			mac_pdata_update(mac_handle_t, void *,
697 				    size_t);
698 extern boolean_t		mac_margin_update(mac_handle_t, uint32_t);
699 extern void			mac_margin_get(mac_handle_t, uint32_t *);
700 extern int			mac_margin_remove(mac_handle_t, uint32_t);
701 extern int			mac_margin_add(mac_handle_t, uint32_t *,
702 				    boolean_t);
703 extern int			mac_mtu_add(mac_handle_t, uint32_t *,
704 				    boolean_t);
705 extern int			mac_mtu_remove(mac_handle_t, uint32_t);
706 extern int			mac_fastpath_disable(mac_handle_t);
707 extern void			mac_fastpath_enable(mac_handle_t);
708 extern void			mac_no_active(mac_handle_t);
709 
710 extern mactype_register_t	*mactype_alloc(uint_t);
711 extern void			mactype_free(mactype_register_t *);
712 extern int			mactype_register(mactype_register_t *);
713 extern int			mactype_unregister(const char *);
714 
715 extern int			mac_start_logusage(mac_logtype_t, uint_t);
716 extern void			mac_stop_logusage(mac_logtype_t);
717 
718 extern mac_handle_t		mac_get_lower_mac_handle(mac_handle_t);
719 extern boolean_t		mac_is_vnic_primary(mac_handle_t);
720 
721 /*
722  * Packet hashing for distribution to multiple ports and rings.
723  */
724 
725 #define	MAC_PKT_HASH_L2		0x01
726 #define	MAC_PKT_HASH_L3		0x02
727 #define	MAC_PKT_HASH_L4		0x04
728 
729 extern uint64_t			mac_pkt_hash(uint_t, mblk_t *, uint8_t,
730 				    boolean_t);
731 
732 /*
733  * Bridging linkage
734  */
735 extern void			mac_rx_common(mac_handle_t,
736 				    mac_resource_handle_t, mblk_t *);
737 extern int			mac_bridge_set(mac_handle_t, mac_handle_t);
738 extern void			mac_bridge_clear(mac_handle_t, mac_handle_t);
739 extern void			mac_bridge_vectors(mac_bridge_tx_t,
740 				    mac_bridge_rx_t, mac_bridge_ref_t,
741 				    mac_bridge_ls_t);
742 
743 /* special case function for TRILL observability */
744 extern void			mac_trill_snoop(mac_handle_t, mblk_t *);
745 
746 #endif	/* _KERNEL */
747 
748 #ifdef	__cplusplus
749 }
750 #endif
751 
752 #endif /* _SYS_MAC_H */
753