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