xref: /onnv-gate/usr/src/uts/common/sys/mac.h (revision 9449:53d84bc6a35a)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
52311Sseb  * Common Development and Distribution License (the "License").
62311Sseb  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
218275SEric Cheng 
220Sstevel@tonic-gate /*
238833SVenu.Iyer@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #ifndef	_SYS_MAC_H
280Sstevel@tonic-gate #define	_SYS_MAC_H
290Sstevel@tonic-gate 
302760Sdg199075 #include <sys/types.h>
319107Sjames.d.carlson@sun.com #ifdef	_KERNEL
320Sstevel@tonic-gate #include <sys/sunddi.h>
339107Sjames.d.carlson@sun.com #endif
340Sstevel@tonic-gate 
350Sstevel@tonic-gate /*
360Sstevel@tonic-gate  * MAC Services Module
370Sstevel@tonic-gate  */
380Sstevel@tonic-gate 
390Sstevel@tonic-gate #ifdef	__cplusplus
400Sstevel@tonic-gate extern "C" {
410Sstevel@tonic-gate #endif
420Sstevel@tonic-gate 
430Sstevel@tonic-gate /*
440Sstevel@tonic-gate  * MAC Information (text emitted by modinfo(1m))
450Sstevel@tonic-gate  */
468275SEric Cheng #define	MAC_INFO	"MAC Services v1.20"
472311Sseb 
482311Sseb /*
492311Sseb  * MAC-Type version identifier.  This is used by mactype_alloc() and
502311Sseb  * mactype_register() to verify that incompatible MAC-Type plugins don't
512311Sseb  * register.
522311Sseb  */
532311Sseb #define	MACTYPE_VERSION	0x1
542311Sseb 
552311Sseb /*
568275SEric Cheng  * Opaque handle types
570Sstevel@tonic-gate  */
588275SEric Cheng typedef struct __mac_handle		*mac_handle_t;
598275SEric Cheng typedef struct __mac_resource_handle	*mac_resource_handle_t;
608275SEric Cheng typedef struct __mac_notify_handle	*mac_notify_handle_t;
618275SEric Cheng typedef struct __mac_tx_notify_handle	*mac_tx_notify_handle_t;
628275SEric Cheng typedef	struct __mac_intr_handle	*mac_intr_handle_t;
638275SEric Cheng typedef	struct __mac_ring_handle	*mac_ring_handle_t;
648275SEric Cheng typedef	struct __mac_group_handle	*mac_group_handle_t;
650Sstevel@tonic-gate 
668275SEric Cheng #define	DATALINK_INVALID_LINKID	0
678275SEric Cheng #define	DATALINK_ALL_LINKID	0
688275SEric Cheng #define	DATALINK_MAX_LINKID	0xffffffff
698275SEric Cheng 
708275SEric Cheng #define	MAC_MAX_MINOR	1000
718275SEric Cheng 
720Sstevel@tonic-gate typedef enum {
730Sstevel@tonic-gate 	LINK_STATE_UNKNOWN = -1,
740Sstevel@tonic-gate 	LINK_STATE_DOWN,
750Sstevel@tonic-gate 	LINK_STATE_UP
760Sstevel@tonic-gate } link_state_t;
770Sstevel@tonic-gate 
780Sstevel@tonic-gate typedef enum {
790Sstevel@tonic-gate 	LINK_DUPLEX_UNKNOWN = 0,
800Sstevel@tonic-gate 	LINK_DUPLEX_HALF,
810Sstevel@tonic-gate 	LINK_DUPLEX_FULL
820Sstevel@tonic-gate } link_duplex_t;
830Sstevel@tonic-gate 
845903Ssowmini typedef enum {
855903Ssowmini 	LINK_FLOWCTRL_NONE = 0,
865903Ssowmini 	LINK_FLOWCTRL_RX,
875903Ssowmini 	LINK_FLOWCTRL_TX,
885903Ssowmini 	LINK_FLOWCTRL_BI
895903Ssowmini } link_flowctrl_t;
905903Ssowmini 
918874SSebastien.Roy@Sun.COM typedef enum {
928874SSebastien.Roy@Sun.COM 	LINK_TAGMODE_VLANONLY = 0,
938874SSebastien.Roy@Sun.COM 	LINK_TAGMODE_NORMAL
948874SSebastien.Roy@Sun.COM } link_tagmode_t;
958874SSebastien.Roy@Sun.COM 
968275SEric Cheng /*
978275SEric Cheng  * Maximum MAC address length
988275SEric Cheng  */
998275SEric Cheng #define	MAXMACADDRLEN		20
1008275SEric Cheng 
1018275SEric Cheng typedef enum {
1028275SEric Cheng 	MAC_LOGTYPE_LINK = 1,
1038275SEric Cheng 	MAC_LOGTYPE_FLOW
1048275SEric Cheng } mac_logtype_t;
1056789Sam223141 
1066789Sam223141 /*
1076789Sam223141  * Encodings for public properties.
1086789Sam223141  * A most significant bit value of 1 indicates private property, intended
1096789Sam223141  * to allow private property implementations to use internal encodings
1106789Sam223141  * if desired.
1116789Sam223141  *
1126789Sam223141  * Note that there are 2 sets of parameters: the *_EN_*
1136789Sam223141  * values are those that the Administrator configures for autonegotiation.
1146789Sam223141  * The _ADV_* values are those that are currently exposed over the wire.
1156789Sam223141  */
1166789Sam223141 #define	MAXLINKPROPNAME		256
1176789Sam223141 #define	MAC_PROP_DEFAULT	0x0001
1186789Sam223141 typedef enum {
1196789Sam223141 	MAC_PROP_DUPLEX = 0x00000001,
1206789Sam223141 	MAC_PROP_SPEED,
1216789Sam223141 	MAC_PROP_STATUS,
1226789Sam223141 	MAC_PROP_AUTONEG,
1236789Sam223141 	MAC_PROP_EN_AUTONEG,
1246789Sam223141 	MAC_PROP_MTU,
1257342SAruna.Ramakrishna@Sun.COM 	MAC_PROP_ZONE,
1267342SAruna.Ramakrishna@Sun.COM 	MAC_PROP_AUTOPUSH,
1276789Sam223141 	MAC_PROP_FLOWCTRL,
1286789Sam223141 	MAC_PROP_ADV_1000FDX_CAP,
1296789Sam223141 	MAC_PROP_EN_1000FDX_CAP,
1306789Sam223141 	MAC_PROP_ADV_1000HDX_CAP,
1316789Sam223141 	MAC_PROP_EN_1000HDX_CAP,
1326789Sam223141 	MAC_PROP_ADV_100FDX_CAP,
1336789Sam223141 	MAC_PROP_EN_100FDX_CAP,
1346789Sam223141 	MAC_PROP_ADV_100HDX_CAP,
1356789Sam223141 	MAC_PROP_EN_100HDX_CAP,
1366789Sam223141 	MAC_PROP_ADV_10FDX_CAP,
1376789Sam223141 	MAC_PROP_EN_10FDX_CAP,
1386789Sam223141 	MAC_PROP_ADV_10HDX_CAP,
1396789Sam223141 	MAC_PROP_EN_10HDX_CAP,
1406789Sam223141 	MAC_PROP_ADV_100T4_CAP,
1416789Sam223141 	MAC_PROP_EN_100T4_CAP,
1427663SSowmini.Varadhan@Sun.COM 	MAC_PROP_WL_ESSID,
1437663SSowmini.Varadhan@Sun.COM 	MAC_PROP_WL_BSSID,
1447663SSowmini.Varadhan@Sun.COM 	MAC_PROP_WL_BSSTYPE,
1457663SSowmini.Varadhan@Sun.COM 	MAC_PROP_WL_LINKSTATUS,
1467663SSowmini.Varadhan@Sun.COM 	MAC_PROP_WL_DESIRED_RATES,
1477663SSowmini.Varadhan@Sun.COM 	MAC_PROP_WL_SUPPORTED_RATES,
1487663SSowmini.Varadhan@Sun.COM 	MAC_PROP_WL_AUTH_MODE,
1497663SSowmini.Varadhan@Sun.COM 	MAC_PROP_WL_ENCRYPTION,
1507663SSowmini.Varadhan@Sun.COM 	MAC_PROP_WL_RSSI,
1517663SSowmini.Varadhan@Sun.COM 	MAC_PROP_WL_PHY_CONFIG,
1527663SSowmini.Varadhan@Sun.COM 	MAC_PROP_WL_CAPABILITY,
1537663SSowmini.Varadhan@Sun.COM 	MAC_PROP_WL_WPA,
1547663SSowmini.Varadhan@Sun.COM 	MAC_PROP_WL_SCANRESULTS,
1557663SSowmini.Varadhan@Sun.COM 	MAC_PROP_WL_POWER_MODE,
1567663SSowmini.Varadhan@Sun.COM 	MAC_PROP_WL_RADIO,
1577663SSowmini.Varadhan@Sun.COM 	MAC_PROP_WL_ESS_LIST,
1587663SSowmini.Varadhan@Sun.COM 	MAC_PROP_WL_KEY_TAB,
1597663SSowmini.Varadhan@Sun.COM 	MAC_PROP_WL_CREATE_IBSS,
1607663SSowmini.Varadhan@Sun.COM 	MAC_PROP_WL_SETOPTIE,
1617663SSowmini.Varadhan@Sun.COM 	MAC_PROP_WL_DELKEY,
1627663SSowmini.Varadhan@Sun.COM 	MAC_PROP_WL_KEY,
1637663SSowmini.Varadhan@Sun.COM 	MAC_PROP_WL_MLME,
1648275SEric Cheng 	MAC_PROP_MAXBW,
1658275SEric Cheng 	MAC_PROP_PRIO,
1668275SEric Cheng 	MAC_PROP_BIND_CPU,
1678874SSebastien.Roy@Sun.COM 	MAC_PROP_TAGMODE,
168*9449Sxiuyan.wang@Sun.COM 	MAC_PROP_ADV_10GFDX_CAP,
169*9449Sxiuyan.wang@Sun.COM 	MAC_PROP_EN_10GFDX_CAP,
1706789Sam223141 	MAC_PROP_PRIVATE = -1
1716789Sam223141 } mac_prop_id_t;
1726789Sam223141 
1735084Sjohnlev /*
1748118SVasumathi.Sundaram@Sun.COM  * Flags to figure out r/w status of legacy ndd props.
1758118SVasumathi.Sundaram@Sun.COM  */
1768118SVasumathi.Sundaram@Sun.COM #define	MAC_PROP_PERM_READ		0x0001
1778118SVasumathi.Sundaram@Sun.COM #define	MAC_PROP_PERM_WRITE		0x0010
1788118SVasumathi.Sundaram@Sun.COM #define	MAC_PROP_MAP_KSTAT		0x0100
1798118SVasumathi.Sundaram@Sun.COM #define	MAC_PROP_PERM_RW		(MAC_PROP_PERM_READ|MAC_PROP_PERM_WRITE)
1808118SVasumathi.Sundaram@Sun.COM #define	MAC_PROP_FLAGS_RK		(MAC_PROP_PERM_READ|MAC_PROP_MAP_KSTAT)
1818118SVasumathi.Sundaram@Sun.COM 
1820Sstevel@tonic-gate #ifdef	_KERNEL
1830Sstevel@tonic-gate 
1842311Sseb /*
1852311Sseb  * There are three ranges of statistics values.  0 to 1 - MAC_STAT_MIN are
1862311Sseb  * interface statistics maintained by the mac module.  MAC_STAT_MIN to 1 -
1872311Sseb  * MACTYPE_STAT_MIN are common MAC statistics defined by the mac module and
1882311Sseb  * maintained by each driver.  MACTYPE_STAT_MIN and above are statistics
1892311Sseb  * defined by MAC-Type plugins and maintained by each driver.
1902311Sseb  */
1912311Sseb #define	MAC_STAT_MIN		1000
1922311Sseb #define	MACTYPE_STAT_MIN	2000
1932311Sseb 
1942311Sseb #define	IS_MAC_STAT(stat)	\
1952311Sseb 	(stat >= MAC_STAT_MIN && stat < MACTYPE_STAT_MIN)
1962311Sseb #define	IS_MACTYPE_STAT(stat)	(stat >= MACTYPE_STAT_MIN)
1972311Sseb 
1984089Sgd78059 /*
1995895Syz147064  * Statistics maintained by the mac module, and possibly populated as link
2005895Syz147064  * statistics.
2015895Syz147064  */
2025895Syz147064 enum mac_mod_stat {
2035895Syz147064 	MAC_STAT_LINK_STATE,
2045895Syz147064 	MAC_STAT_LINK_UP,
2055895Syz147064 	MAC_STAT_PROMISC
2065895Syz147064 };
2075895Syz147064 
2085895Syz147064 /*
2094089Sgd78059  * Do not reorder, and add only to the end of this list.
2104089Sgd78059  */
2112311Sseb enum mac_driver_stat {
2122311Sseb 	/* MIB-II stats (RFC 1213 and RFC 1573) */
2132311Sseb 	MAC_STAT_IFSPEED = MAC_STAT_MIN,
2140Sstevel@tonic-gate 	MAC_STAT_MULTIRCV,
2150Sstevel@tonic-gate 	MAC_STAT_BRDCSTRCV,
2160Sstevel@tonic-gate 	MAC_STAT_MULTIXMT,
2170Sstevel@tonic-gate 	MAC_STAT_BRDCSTXMT,
2180Sstevel@tonic-gate 	MAC_STAT_NORCVBUF,
2190Sstevel@tonic-gate 	MAC_STAT_IERRORS,
2200Sstevel@tonic-gate 	MAC_STAT_UNKNOWNS,
2210Sstevel@tonic-gate 	MAC_STAT_NOXMTBUF,
2220Sstevel@tonic-gate 	MAC_STAT_OERRORS,
2230Sstevel@tonic-gate 	MAC_STAT_COLLISIONS,
2240Sstevel@tonic-gate 	MAC_STAT_RBYTES,
2250Sstevel@tonic-gate 	MAC_STAT_IPACKETS,
2260Sstevel@tonic-gate 	MAC_STAT_OBYTES,
2274089Sgd78059 	MAC_STAT_OPACKETS,
2284089Sgd78059 	MAC_STAT_UNDERFLOWS,
2294089Sgd78059 	MAC_STAT_OVERFLOWS
2302311Sseb };
2310Sstevel@tonic-gate 
2324089Sgd78059 #define	MAC_NSTAT	(MAC_STAT_OVERFLOWS - MAC_STAT_IFSPEED + 1)
2330Sstevel@tonic-gate 
2342311Sseb #define	MAC_STAT_ISACOUNTER(_stat) (		\
2352311Sseb 	    (_stat) == MAC_STAT_MULTIRCV ||	\
2362311Sseb 	    (_stat) == MAC_STAT_BRDCSTRCV ||	\
2372311Sseb 	    (_stat) == MAC_STAT_MULTIXMT ||	\
2382311Sseb 	    (_stat) == MAC_STAT_BRDCSTXMT ||	\
2392311Sseb 	    (_stat) == MAC_STAT_NORCVBUF ||	\
2402311Sseb 	    (_stat) == MAC_STAT_IERRORS ||	\
2412311Sseb 	    (_stat) == MAC_STAT_UNKNOWNS ||	\
2422311Sseb 	    (_stat) == MAC_STAT_NOXMTBUF ||	\
2432311Sseb 	    (_stat) == MAC_STAT_OERRORS ||	\
2442311Sseb 	    (_stat) == MAC_STAT_COLLISIONS ||	\
2452311Sseb 	    (_stat) == MAC_STAT_RBYTES ||	\
2462311Sseb 	    (_stat) == MAC_STAT_IPACKETS ||	\
2472311Sseb 	    (_stat) == MAC_STAT_OBYTES ||	\
2484089Sgd78059 	    (_stat) == MAC_STAT_OPACKETS ||	\
2494089Sgd78059 	    (_stat) == MAC_STAT_UNDERFLOWS ||	\
2504089Sgd78059 	    (_stat) == MAC_STAT_OVERFLOWS)
2510Sstevel@tonic-gate 
2520Sstevel@tonic-gate /*
2530Sstevel@tonic-gate  * Immutable information. (This may not be modified after registration).
2540Sstevel@tonic-gate  */
2550Sstevel@tonic-gate typedef struct mac_info_s {
2560Sstevel@tonic-gate 	uint_t		mi_media;
2573147Sxc151355 	uint_t		mi_nativemedia;
2580Sstevel@tonic-gate 	uint_t		mi_addr_length;
2592311Sseb 	uint8_t		*mi_unicst_addr;
2602311Sseb 	uint8_t		*mi_brdcst_addr;
2610Sstevel@tonic-gate } mac_info_t;
2620Sstevel@tonic-gate 
2630Sstevel@tonic-gate /*
2648275SEric Cheng  * When VNICs are created on top of the NIC, there are two levels
2658275SEric Cheng  * of MAC layer, a lower MAC, which is the MAC layer at the level of the
2668275SEric Cheng  * physical NIC, and an upper MAC, which is the MAC layer at the level
2678275SEric Cheng  * of the VNIC. Each VNIC maps to a MAC client at the lower MAC, and
2688275SEric Cheng  * the SRS and classification is done at the lower MAC level. The upper
2698275SEric Cheng  * MAC is therefore for the most part pass-through, and therefore
2708275SEric Cheng  * special processing needs to be done at the upper MAC layer when
2718275SEric Cheng  * dealing with a VNIC.
2728275SEric Cheng  *
2738275SEric Cheng  * This capability allows the MAC layer to detect when a VNIC is being
2748275SEric Cheng  * access, and implement the required shortcuts.
2750Sstevel@tonic-gate  */
2766495Sspeer 
2778275SEric Cheng typedef void *(*mac_client_handle_fn_t)(void *);
2786495Sspeer 
2798275SEric Cheng typedef struct mac_capab_vnic_s {
2808275SEric Cheng 	void			*mcv_arg;
2818275SEric Cheng 	mac_client_handle_fn_t	mcv_mac_client_handle;
2828275SEric Cheng } mac_capab_vnic_t;
2836495Sspeer 
2848275SEric Cheng typedef void (*mac_rename_fn_t)(const char *, void *);
2858275SEric Cheng typedef struct mac_capab_aggr_s {
2868275SEric Cheng 	mac_rename_fn_t mca_rename_fn;
2878275SEric Cheng 	int (*mca_unicst)(void *, const uint8_t *);
2888275SEric Cheng } mac_capab_aggr_t;
2896495Sspeer 
2900Sstevel@tonic-gate typedef enum {
2910Sstevel@tonic-gate 	MAC_NOTE_LINK,
2920Sstevel@tonic-gate 	MAC_NOTE_PROMISC,
2930Sstevel@tonic-gate 	MAC_NOTE_UNICST,
2940Sstevel@tonic-gate 	MAC_NOTE_TX,
2950Sstevel@tonic-gate 	MAC_NOTE_RESOURCE,
2960Sstevel@tonic-gate 	MAC_NOTE_DEVPROMISC,
2972311Sseb 	MAC_NOTE_FASTPATH_FLUSH,
2985903Ssowmini 	MAC_NOTE_SDU_SIZE,
2995895Syz147064 	MAC_NOTE_MARGIN,
3008275SEric Cheng 	MAC_NOTE_CAPAB_CHG,
3010Sstevel@tonic-gate 	MAC_NNOTE	/* must be the last entry */
3020Sstevel@tonic-gate } mac_notify_type_t;
3030Sstevel@tonic-gate 
3040Sstevel@tonic-gate typedef void		(*mac_notify_t)(void *, mac_notify_type_t);
3058275SEric Cheng typedef void		(*mac_rx_t)(void *, mac_resource_handle_t, mblk_t *,
3068275SEric Cheng 			    boolean_t);
3078275SEric Cheng typedef	mblk_t		*(*mac_receive_t)(void *, int);
3080Sstevel@tonic-gate 
3090Sstevel@tonic-gate /*
3100Sstevel@tonic-gate  * MAC promiscuous types
3110Sstevel@tonic-gate  */
3120Sstevel@tonic-gate typedef enum {
3130Sstevel@tonic-gate 	MAC_PROMISC = 0x01,		/* MAC instance is promiscuous */
3140Sstevel@tonic-gate 	MAC_DEVPROMISC = 0x02		/* Device is promiscuous */
3150Sstevel@tonic-gate } mac_promisc_type_t;
3160Sstevel@tonic-gate 
3170Sstevel@tonic-gate /*
3180Sstevel@tonic-gate  * MAC resource types
3190Sstevel@tonic-gate  */
3200Sstevel@tonic-gate typedef enum {
3210Sstevel@tonic-gate 	MAC_RX_FIFO = 1
3220Sstevel@tonic-gate } mac_resource_type_t;
3230Sstevel@tonic-gate 
3248275SEric Cheng typedef	int	(*mac_intr_enable_t)(mac_intr_handle_t);
3258275SEric Cheng typedef	int	(*mac_intr_disable_t)(mac_intr_handle_t);
3268275SEric Cheng 
3278275SEric Cheng typedef	struct mac_intr_s {
3288275SEric Cheng 	mac_intr_handle_t	mi_handle;
3298275SEric Cheng 	mac_intr_enable_t	mi_enable;
3308275SEric Cheng 	mac_intr_disable_t	mi_disable;
3318275SEric Cheng } mac_intr_t;
3328275SEric Cheng 
3330Sstevel@tonic-gate typedef struct mac_rx_fifo_s {
3340Sstevel@tonic-gate 	mac_resource_type_t	mrf_type;	/* MAC_RX_FIFO */
3358275SEric Cheng 	mac_intr_t		mrf_intr;
3368275SEric Cheng 	mac_receive_t		mrf_receive;
3378275SEric Cheng 	void			*mrf_rx_arg;
3388275SEric Cheng 	uint32_t		mrf_flow_priority;
3398275SEric Cheng 	/*
3408275SEric Cheng 	 * The CPU this flow is to be processed on. With intrd and future
3418275SEric Cheng 	 * things, we should know which CPU the flow needs to be processed
3428275SEric Cheng 	 * and get a squeue assigned on that CPU.
3438275SEric Cheng 	 */
3448275SEric Cheng 	uint_t			mrf_cpu_id;
3450Sstevel@tonic-gate } mac_rx_fifo_t;
3460Sstevel@tonic-gate 
3478275SEric Cheng #define	mrf_intr_handle		mrf_intr.mi_handle
3488275SEric Cheng #define	mrf_intr_enable		mrf_intr.mi_enable
3498275SEric Cheng #define	mrf_intr_disable	mrf_intr.mi_disable
35056Smeem 
3510Sstevel@tonic-gate typedef union mac_resource_u {
3520Sstevel@tonic-gate 	mac_resource_type_t	mr_type;
3530Sstevel@tonic-gate 	mac_rx_fifo_t		mr_fifo;
3540Sstevel@tonic-gate } mac_resource_t;
3550Sstevel@tonic-gate 
3562311Sseb typedef enum {
3572311Sseb 	MAC_ADDRTYPE_UNICAST,
3582311Sseb 	MAC_ADDRTYPE_MULTICAST,
3592311Sseb 	MAC_ADDRTYPE_BROADCAST
3602311Sseb } mac_addrtype_t;
3612311Sseb 
3622311Sseb typedef struct mac_header_info_s {
3632311Sseb 	size_t		mhi_hdrsize;
3642311Sseb 	size_t		mhi_pktsize;
3652311Sseb 	const uint8_t	*mhi_daddr;
3662311Sseb 	const uint8_t	*mhi_saddr;
3672311Sseb 	uint32_t	mhi_origsap;
3682311Sseb 	uint32_t	mhi_bindsap;
3692311Sseb 	mac_addrtype_t	mhi_dsttype;
3702760Sdg199075 	uint16_t	mhi_tci;
3718275SEric Cheng 	boolean_t	mhi_istagged;
3722311Sseb } mac_header_info_t;
3732311Sseb 
3742311Sseb /*
3758275SEric Cheng  * Function pointer to match dls client signature. Should be same as
3768275SEric Cheng  * dls_rx_t to allow a soft ring to bypass DLS layer and call a DLS
3778275SEric Cheng  * client directly.
3788275SEric Cheng  */
3798275SEric Cheng typedef	void		(*mac_direct_rx_t)(void *, mac_resource_handle_t,
3808275SEric Cheng 				mblk_t *, mac_header_info_t *);
3818275SEric Cheng 
3828275SEric Cheng typedef mac_resource_handle_t	(*mac_resource_add_t)(void *, mac_resource_t *);
3838275SEric Cheng typedef int			(*mac_resource_bind_t)(void *,
3848275SEric Cheng     mac_resource_handle_t, processorid_t);
3858275SEric Cheng typedef void			(*mac_resource_remove_t)(void *, void *);
3868275SEric Cheng typedef void			(*mac_resource_quiesce_t)(void *, void *);
3878275SEric Cheng typedef void			(*mac_resource_restart_t)(void *, void *);
3888275SEric Cheng typedef int			(*mac_resource_modify_t)(void *, void *,
3898275SEric Cheng 				    mac_resource_t *);
3908275SEric Cheng typedef	void			(*mac_change_upcall_t)(void *, mac_direct_rx_t,
3918275SEric Cheng     void *);
3928275SEric Cheng 
3938275SEric Cheng /*
3942311Sseb  * MAC-Type plugin interfaces
3952311Sseb  */
3962311Sseb 
3972311Sseb typedef int		(*mtops_addr_verify_t)(const void *, void *);
3982311Sseb typedef boolean_t	(*mtops_sap_verify_t)(uint32_t, uint32_t *, void *);
3992311Sseb typedef mblk_t		*(*mtops_header_t)(const void *, const void *,
4002311Sseb     uint32_t, void *, mblk_t *, size_t);
4012311Sseb typedef int		(*mtops_header_info_t)(mblk_t *, void *,
4022311Sseb     mac_header_info_t *);
4032311Sseb typedef boolean_t	(*mtops_pdata_verify_t)(void *, size_t);
4042311Sseb typedef	mblk_t		*(*mtops_header_modify_t)(mblk_t *, void *);
4054403Sgd78059 typedef void		(*mtops_link_details_t)(char *, size_t, mac_handle_t,
4064403Sgd78059     void *);
4072311Sseb 
4082311Sseb typedef struct mactype_ops_s {
4092311Sseb 	uint_t			mtops_ops;
4102311Sseb 	/*
4112311Sseb 	 * mtops_unicst_verify() returns 0 if the given address is a valid
4122311Sseb 	 * unicast address, or a non-zero errno otherwise.
4132311Sseb 	 */
4142311Sseb 	mtops_addr_verify_t	mtops_unicst_verify;
4152311Sseb 	/*
4162311Sseb 	 * mtops_multicst_verify() returns 0 if the given address is a
4172311Sseb 	 * valid multicast address, or a non-zero errno otherwise.  If the
4182311Sseb 	 * media doesn't support multicast, ENOTSUP should be returned (for
4192311Sseb 	 * example).
4202311Sseb 	 */
4212311Sseb 	mtops_addr_verify_t	mtops_multicst_verify;
4222311Sseb 	/*
4232311Sseb 	 * mtops_sap_verify() returns B_TRUE if the given SAP is a valid
4242311Sseb 	 * SAP value, or B_FALSE otherwise.
4252311Sseb 	 */
4262311Sseb 	mtops_sap_verify_t	mtops_sap_verify;
4272311Sseb 	/*
4282311Sseb 	 * mtops_header() is used to allocate and construct a MAC header.
4292311Sseb 	 */
4302311Sseb 	mtops_header_t		mtops_header;
4312311Sseb 	/*
4322311Sseb 	 * mtops_header_info() is used to gather information on a given MAC
4332311Sseb 	 * header.
4342311Sseb 	 */
4352311Sseb 	mtops_header_info_t	mtops_header_info;
4362311Sseb 	/*
4372311Sseb 	 * mtops_pdata_verify() is used to verify the validity of MAC
4382311Sseb 	 * plugin data.  It is called by mac_register() if the driver has
4392311Sseb 	 * supplied MAC plugin data, and also by mac_pdata_update() when
4402311Sseb 	 * drivers update the data.
4412311Sseb 	 */
4422311Sseb 	mtops_pdata_verify_t	mtops_pdata_verify;
4432311Sseb 	/*
4442311Sseb 	 * mtops_header_cook() is an optional callback that converts (or
4452311Sseb 	 * "cooks") the given raw header (as sent by a raw DLPI consumer)
4462311Sseb 	 * into one that is appropriate to send down to the MAC driver.
4472311Sseb 	 * Following the example above, an Ethernet header sent down by a
4482311Sseb 	 * DLPI consumer would be converted to whatever header the MAC
4492311Sseb 	 * driver expects.
4502311Sseb 	 */
4512311Sseb 	mtops_header_modify_t	mtops_header_cook;
4522311Sseb 	/*
4532311Sseb 	 * mtops_header_uncook() is an optional callback that does the
4542311Sseb 	 * opposite of mtops_header_cook().  It "uncooks" a given MAC
4552311Sseb 	 * header (as received from the driver) for consumption by raw DLPI
4562311Sseb 	 * consumers.  For example, for a non-Ethernet plugin that wants
4572311Sseb 	 * raw DLPI consumers to be fooled into thinking that the device
4582311Sseb 	 * provides Ethernet access, this callback would modify the given
4592311Sseb 	 * mblk_t such that the MAC header is converted to an Ethernet
4602311Sseb 	 * header.
4612311Sseb 	 */
4622311Sseb 	mtops_header_modify_t	mtops_header_uncook;
4634403Sgd78059 	/*
4644403Sgd78059 	 * mtops_link_details() is an optional callback that provides
4654403Sgd78059 	 * extended information about the link state.  Its primary purpose
4664403Sgd78059 	 * is to provide type-specific support for syslog contents on
4674403Sgd78059 	 * link up events.  If no implementation is provided, then a default
4684403Sgd78059 	 * implementation will be used.
4694403Sgd78059 	 */
4704403Sgd78059 	mtops_link_details_t	mtops_link_details;
4712311Sseb } mactype_ops_t;
4722311Sseb 
4732311Sseb /*
4742311Sseb  * mtops_ops exists for the plugin to enumerate the optional callback
4752311Sseb  * entrypoints it has defined.  This allows the mac module to define
4762311Sseb  * additional plugin entrypoints in mactype_ops_t without breaking backward
4772311Sseb  * compatibility with old plugins.
4782311Sseb  */
4792311Sseb #define	MTOPS_PDATA_VERIFY	0x001
4802311Sseb #define	MTOPS_HEADER_COOK	0x002
4812311Sseb #define	MTOPS_HEADER_UNCOOK	0x004
4824403Sgd78059 #define	MTOPS_LINK_DETAILS	0x008
4832311Sseb 
4846512Ssowmini /*
4856512Ssowmini  * Provide mapping for legacy ndd ioctls relevant to that mactype.
4866512Ssowmini  * Note that the ndd ioctls are obsolete, and may be removed in a future
4876512Ssowmini  * release of Solaris. The ndd ioctls are not typically used in legacy
4886512Ssowmini  * ethernet drivers. New datalink drivers of all link-types should use
4896512Ssowmini  * dladm(1m) interfaces for administering tunables and not have to provide
4906512Ssowmini  * a mapping.
4916512Ssowmini  */
4926512Ssowmini typedef struct mac_ndd_mapping_s {
4936512Ssowmini 	char		*mp_name;
4946512Ssowmini 	union {
4956512Ssowmini 		mac_prop_id_t   u_id;
4966512Ssowmini 		uint_t		u_kstat;
4976512Ssowmini 	} u_mp_id;
4986512Ssowmini 	long		mp_minval;
4996512Ssowmini 	long		mp_maxval;
5006512Ssowmini 	size_t		mp_valsize;
5016512Ssowmini 	int		mp_flags;
5026512Ssowmini } mac_ndd_mapping_t;
5036512Ssowmini 
5046512Ssowmini #define	mp_prop_id	u_mp_id.u_id
5056512Ssowmini #define	mp_kstat	u_mp_id.u_kstat
5066512Ssowmini 
5078275SEric Cheng typedef struct mac_stat_info_s {
5088275SEric Cheng 	uint_t		msi_stat;
5098275SEric Cheng 	char		*msi_name;
5108275SEric Cheng 	uint_t		msi_type;	/* as defined in kstat_named_init(9F) */
5118275SEric Cheng 	uint64_t	msi_default;
5128275SEric Cheng } mac_stat_info_t;
5138275SEric Cheng 
5142311Sseb typedef struct mactype_register_s {
5152311Sseb 	uint_t		mtr_version;	/* set by mactype_alloc() */
5162311Sseb 	const char	*mtr_ident;
5172311Sseb 	mactype_ops_t	*mtr_ops;
5182311Sseb 	uint_t		mtr_mactype;
5193147Sxc151355 	uint_t		mtr_nativetype;
5202311Sseb 	uint_t		mtr_addrlen;
5212311Sseb 	uint8_t		*mtr_brdcst_addr;
5222311Sseb 	mac_stat_info_t	*mtr_stats;
5232311Sseb 	size_t		mtr_statcount;
5246512Ssowmini 	mac_ndd_mapping_t *mtr_mapping;
5256512Ssowmini 	size_t		mtr_mappingcount;
5262311Sseb } mactype_register_t;
5272311Sseb 
5285903Ssowmini typedef struct mac_prop_s {
5295903Ssowmini 	mac_prop_id_t	mp_id;
5305903Ssowmini 	char		*mp_name;
5316512Ssowmini 	uint_t		mp_flags;
5325903Ssowmini } mac_prop_t;
5335903Ssowmini 
5340Sstevel@tonic-gate /*
5358275SEric Cheng  * Driver interface functions.
5360Sstevel@tonic-gate  */
5375895Syz147064 extern int			mac_open_by_linkid(datalink_id_t,
5385895Syz147064 				    mac_handle_t *);
5395895Syz147064 extern int			mac_open_by_linkname(const char *,
5405895Syz147064 				    mac_handle_t *);
5415895Syz147064 extern const char		*mac_name(mac_handle_t);
5425895Syz147064 extern minor_t			mac_minor(mac_handle_t);
5435895Syz147064 extern minor_t			mac_minor_hold(boolean_t);
5445895Syz147064 extern void			mac_minor_rele(minor_t);
5458275SEric Cheng extern void			mac_sdu_get(mac_handle_t, uint_t *, uint_t *);
5468275SEric Cheng extern int			mac_maxsdu_update(mac_handle_t, uint_t);
5470Sstevel@tonic-gate 
5482311Sseb extern void 			mac_unicst_update(mac_handle_t,
5495895Syz147064 				    const uint8_t *);
5502311Sseb extern void			mac_resource_update(mac_handle_t);
5518275SEric Cheng extern void			mac_capab_update(mac_handle_t);
5522311Sseb extern int			mac_pdata_update(mac_handle_t, void *,
5535895Syz147064 				    size_t);
5545895Syz147064 extern boolean_t		mac_margin_update(mac_handle_t, uint32_t);
5555895Syz147064 extern void			mac_margin_get(mac_handle_t, uint32_t *);
5565895Syz147064 extern int			mac_margin_remove(mac_handle_t, uint32_t);
5575895Syz147064 extern int			mac_margin_add(mac_handle_t, uint32_t *,
5585895Syz147064 				    boolean_t);
5599073SCathy.Zhou@Sun.COM extern int			mac_fastpath_disable(mac_handle_t);
5609073SCathy.Zhou@Sun.COM extern void			mac_fastpath_enable(mac_handle_t);
5615895Syz147064 
5622311Sseb extern mactype_register_t	*mactype_alloc(uint_t);
5632311Sseb extern void			mactype_free(mactype_register_t *);
5642311Sseb extern int			mactype_register(mactype_register_t *);
5652311Sseb extern int			mactype_unregister(const char *);
5668275SEric Cheng 
5679073SCathy.Zhou@Sun.COM extern int			mac_start_logusage(mac_logtype_t, uint_t);
5688275SEric Cheng extern void			mac_stop_logusage(mac_logtype_t);
5698275SEric Cheng 
5708275SEric Cheng extern mac_handle_t		mac_get_lower_mac_handle(mac_handle_t);
5710Sstevel@tonic-gate 
5728833SVenu.Iyer@Sun.COM /*
5738833SVenu.Iyer@Sun.COM  * Packet hashing for distribution to multiple ports and rings.
5748833SVenu.Iyer@Sun.COM  */
5758833SVenu.Iyer@Sun.COM 
5768833SVenu.Iyer@Sun.COM #define	MAC_PKT_HASH_L2		0x01
5778833SVenu.Iyer@Sun.COM #define	MAC_PKT_HASH_L3		0x02
5788833SVenu.Iyer@Sun.COM #define	MAC_PKT_HASH_L4		0x04
5798833SVenu.Iyer@Sun.COM 
5808833SVenu.Iyer@Sun.COM extern uint64_t			mac_pkt_hash(uint_t, mblk_t *, uint8_t,
5818833SVenu.Iyer@Sun.COM 				    boolean_t);
5828833SVenu.Iyer@Sun.COM 
5830Sstevel@tonic-gate #endif	/* _KERNEL */
5840Sstevel@tonic-gate 
5850Sstevel@tonic-gate #ifdef	__cplusplus
5860Sstevel@tonic-gate }
5870Sstevel@tonic-gate #endif
5880Sstevel@tonic-gate 
5890Sstevel@tonic-gate #endif /* _SYS_MAC_H */
590