xref: /onnv-gate/usr/src/uts/common/sys/mac.h (revision 8833:8adf20bc60e3)
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 /*
23*8833SVenu.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>
310Sstevel@tonic-gate #include <sys/ddi.h>
320Sstevel@tonic-gate #include <sys/sunddi.h>
330Sstevel@tonic-gate #include <sys/stream.h>
348275SEric Cheng #include <sys/mac_flow.h>
350Sstevel@tonic-gate 
360Sstevel@tonic-gate /*
370Sstevel@tonic-gate  * MAC Services Module
380Sstevel@tonic-gate  */
390Sstevel@tonic-gate 
400Sstevel@tonic-gate #ifdef	__cplusplus
410Sstevel@tonic-gate extern "C" {
420Sstevel@tonic-gate #endif
430Sstevel@tonic-gate 
440Sstevel@tonic-gate /*
450Sstevel@tonic-gate  * MAC Information (text emitted by modinfo(1m))
460Sstevel@tonic-gate  */
478275SEric Cheng #define	MAC_INFO	"MAC Services v1.20"
482311Sseb 
492311Sseb /*
502311Sseb  * MAC-Type version identifier.  This is used by mactype_alloc() and
512311Sseb  * mactype_register() to verify that incompatible MAC-Type plugins don't
522311Sseb  * register.
532311Sseb  */
542311Sseb #define	MACTYPE_VERSION	0x1
552311Sseb 
562311Sseb /*
578275SEric Cheng  * Opaque handle types
580Sstevel@tonic-gate  */
598275SEric Cheng typedef struct __mac_handle		*mac_handle_t;
608275SEric Cheng typedef struct __mac_resource_handle	*mac_resource_handle_t;
618275SEric Cheng typedef struct __mac_notify_handle	*mac_notify_handle_t;
628275SEric Cheng typedef struct __mac_tx_notify_handle	*mac_tx_notify_handle_t;
638275SEric Cheng typedef	struct __mac_intr_handle	*mac_intr_handle_t;
648275SEric Cheng typedef	struct __mac_ring_handle	*mac_ring_handle_t;
658275SEric Cheng typedef	struct __mac_group_handle	*mac_group_handle_t;
660Sstevel@tonic-gate 
678275SEric Cheng #define	DATALINK_INVALID_LINKID	0
688275SEric Cheng #define	DATALINK_ALL_LINKID	0
698275SEric Cheng #define	DATALINK_MAX_LINKID	0xffffffff
708275SEric Cheng 
718275SEric Cheng #define	MAC_MAX_MINOR	1000
728275SEric Cheng 
738275SEric Cheng typedef	uint32_t		datalink_id_t;
740Sstevel@tonic-gate 
750Sstevel@tonic-gate typedef enum {
760Sstevel@tonic-gate 	LINK_STATE_UNKNOWN = -1,
770Sstevel@tonic-gate 	LINK_STATE_DOWN,
780Sstevel@tonic-gate 	LINK_STATE_UP
790Sstevel@tonic-gate } link_state_t;
800Sstevel@tonic-gate 
810Sstevel@tonic-gate typedef enum {
820Sstevel@tonic-gate 	LINK_DUPLEX_UNKNOWN = 0,
830Sstevel@tonic-gate 	LINK_DUPLEX_HALF,
840Sstevel@tonic-gate 	LINK_DUPLEX_FULL
850Sstevel@tonic-gate } link_duplex_t;
860Sstevel@tonic-gate 
875903Ssowmini typedef enum {
885903Ssowmini 	LINK_FLOWCTRL_NONE = 0,
895903Ssowmini 	LINK_FLOWCTRL_RX,
905903Ssowmini 	LINK_FLOWCTRL_TX,
915903Ssowmini 	LINK_FLOWCTRL_BI
925903Ssowmini } link_flowctrl_t;
935903Ssowmini 
948275SEric Cheng /*
958275SEric Cheng  * Maximum MAC address length
968275SEric Cheng  */
978275SEric Cheng #define	MAXMACADDRLEN		20
988275SEric Cheng 
998275SEric Cheng typedef enum {
1008275SEric Cheng 	MAC_LOGTYPE_LINK = 1,
1018275SEric Cheng 	MAC_LOGTYPE_FLOW
1028275SEric Cheng } mac_logtype_t;
1036789Sam223141 
1046789Sam223141 /*
1056789Sam223141  * Encodings for public properties.
1066789Sam223141  * A most significant bit value of 1 indicates private property, intended
1076789Sam223141  * to allow private property implementations to use internal encodings
1086789Sam223141  * if desired.
1096789Sam223141  *
1106789Sam223141  * Note that there are 2 sets of parameters: the *_EN_*
1116789Sam223141  * values are those that the Administrator configures for autonegotiation.
1126789Sam223141  * The _ADV_* values are those that are currently exposed over the wire.
1136789Sam223141  */
1146789Sam223141 #define	MAXLINKPROPNAME		256
1156789Sam223141 #define	MAC_PROP_DEFAULT	0x0001
1166789Sam223141 typedef enum {
1176789Sam223141 	MAC_PROP_DUPLEX = 0x00000001,
1186789Sam223141 	MAC_PROP_SPEED,
1196789Sam223141 	MAC_PROP_STATUS,
1206789Sam223141 	MAC_PROP_AUTONEG,
1216789Sam223141 	MAC_PROP_EN_AUTONEG,
1226789Sam223141 	MAC_PROP_MTU,
1237342SAruna.Ramakrishna@Sun.COM 	MAC_PROP_ZONE,
1247342SAruna.Ramakrishna@Sun.COM 	MAC_PROP_AUTOPUSH,
1256789Sam223141 	MAC_PROP_FLOWCTRL,
1266789Sam223141 	MAC_PROP_ADV_1000FDX_CAP,
1276789Sam223141 	MAC_PROP_EN_1000FDX_CAP,
1286789Sam223141 	MAC_PROP_ADV_1000HDX_CAP,
1296789Sam223141 	MAC_PROP_EN_1000HDX_CAP,
1306789Sam223141 	MAC_PROP_ADV_100FDX_CAP,
1316789Sam223141 	MAC_PROP_EN_100FDX_CAP,
1326789Sam223141 	MAC_PROP_ADV_100HDX_CAP,
1336789Sam223141 	MAC_PROP_EN_100HDX_CAP,
1346789Sam223141 	MAC_PROP_ADV_10FDX_CAP,
1356789Sam223141 	MAC_PROP_EN_10FDX_CAP,
1366789Sam223141 	MAC_PROP_ADV_10HDX_CAP,
1376789Sam223141 	MAC_PROP_EN_10HDX_CAP,
1386789Sam223141 	MAC_PROP_ADV_100T4_CAP,
1396789Sam223141 	MAC_PROP_EN_100T4_CAP,
1407663SSowmini.Varadhan@Sun.COM 	MAC_PROP_WL_ESSID,
1417663SSowmini.Varadhan@Sun.COM 	MAC_PROP_WL_BSSID,
1427663SSowmini.Varadhan@Sun.COM 	MAC_PROP_WL_BSSTYPE,
1437663SSowmini.Varadhan@Sun.COM 	MAC_PROP_WL_LINKSTATUS,
1447663SSowmini.Varadhan@Sun.COM 	MAC_PROP_WL_DESIRED_RATES,
1457663SSowmini.Varadhan@Sun.COM 	MAC_PROP_WL_SUPPORTED_RATES,
1467663SSowmini.Varadhan@Sun.COM 	MAC_PROP_WL_AUTH_MODE,
1477663SSowmini.Varadhan@Sun.COM 	MAC_PROP_WL_ENCRYPTION,
1487663SSowmini.Varadhan@Sun.COM 	MAC_PROP_WL_RSSI,
1497663SSowmini.Varadhan@Sun.COM 	MAC_PROP_WL_PHY_CONFIG,
1507663SSowmini.Varadhan@Sun.COM 	MAC_PROP_WL_CAPABILITY,
1517663SSowmini.Varadhan@Sun.COM 	MAC_PROP_WL_WPA,
1527663SSowmini.Varadhan@Sun.COM 	MAC_PROP_WL_SCANRESULTS,
1537663SSowmini.Varadhan@Sun.COM 	MAC_PROP_WL_POWER_MODE,
1547663SSowmini.Varadhan@Sun.COM 	MAC_PROP_WL_RADIO,
1557663SSowmini.Varadhan@Sun.COM 	MAC_PROP_WL_ESS_LIST,
1567663SSowmini.Varadhan@Sun.COM 	MAC_PROP_WL_KEY_TAB,
1577663SSowmini.Varadhan@Sun.COM 	MAC_PROP_WL_CREATE_IBSS,
1587663SSowmini.Varadhan@Sun.COM 	MAC_PROP_WL_SETOPTIE,
1597663SSowmini.Varadhan@Sun.COM 	MAC_PROP_WL_DELKEY,
1607663SSowmini.Varadhan@Sun.COM 	MAC_PROP_WL_KEY,
1617663SSowmini.Varadhan@Sun.COM 	MAC_PROP_WL_MLME,
1628275SEric Cheng 	MAC_PROP_MAXBW,
1638275SEric Cheng 	MAC_PROP_PRIO,
1648275SEric Cheng 	MAC_PROP_BIND_CPU,
1656789Sam223141 	MAC_PROP_PRIVATE = -1
1666789Sam223141 } mac_prop_id_t;
1676789Sam223141 
1685084Sjohnlev /*
1698118SVasumathi.Sundaram@Sun.COM  * Flags to figure out r/w status of legacy ndd props.
1708118SVasumathi.Sundaram@Sun.COM  */
1718118SVasumathi.Sundaram@Sun.COM #define	MAC_PROP_PERM_READ		0x0001
1728118SVasumathi.Sundaram@Sun.COM #define	MAC_PROP_PERM_WRITE		0x0010
1738118SVasumathi.Sundaram@Sun.COM #define	MAC_PROP_MAP_KSTAT		0x0100
1748118SVasumathi.Sundaram@Sun.COM #define	MAC_PROP_PERM_RW		(MAC_PROP_PERM_READ|MAC_PROP_PERM_WRITE)
1758118SVasumathi.Sundaram@Sun.COM #define	MAC_PROP_FLAGS_RK		(MAC_PROP_PERM_READ|MAC_PROP_MAP_KSTAT)
1768118SVasumathi.Sundaram@Sun.COM 
1770Sstevel@tonic-gate #ifdef	_KERNEL
1780Sstevel@tonic-gate 
1792311Sseb /*
1802311Sseb  * There are three ranges of statistics values.  0 to 1 - MAC_STAT_MIN are
1812311Sseb  * interface statistics maintained by the mac module.  MAC_STAT_MIN to 1 -
1822311Sseb  * MACTYPE_STAT_MIN are common MAC statistics defined by the mac module and
1832311Sseb  * maintained by each driver.  MACTYPE_STAT_MIN and above are statistics
1842311Sseb  * defined by MAC-Type plugins and maintained by each driver.
1852311Sseb  */
1862311Sseb #define	MAC_STAT_MIN		1000
1872311Sseb #define	MACTYPE_STAT_MIN	2000
1882311Sseb 
1892311Sseb #define	IS_MAC_STAT(stat)	\
1902311Sseb 	(stat >= MAC_STAT_MIN && stat < MACTYPE_STAT_MIN)
1912311Sseb #define	IS_MACTYPE_STAT(stat)	(stat >= MACTYPE_STAT_MIN)
1922311Sseb 
1934089Sgd78059 /*
1945895Syz147064  * Statistics maintained by the mac module, and possibly populated as link
1955895Syz147064  * statistics.
1965895Syz147064  */
1975895Syz147064 enum mac_mod_stat {
1985895Syz147064 	MAC_STAT_LINK_STATE,
1995895Syz147064 	MAC_STAT_LINK_UP,
2005895Syz147064 	MAC_STAT_PROMISC
2015895Syz147064 };
2025895Syz147064 
2035895Syz147064 /*
2044089Sgd78059  * Do not reorder, and add only to the end of this list.
2054089Sgd78059  */
2062311Sseb enum mac_driver_stat {
2072311Sseb 	/* MIB-II stats (RFC 1213 and RFC 1573) */
2082311Sseb 	MAC_STAT_IFSPEED = MAC_STAT_MIN,
2090Sstevel@tonic-gate 	MAC_STAT_MULTIRCV,
2100Sstevel@tonic-gate 	MAC_STAT_BRDCSTRCV,
2110Sstevel@tonic-gate 	MAC_STAT_MULTIXMT,
2120Sstevel@tonic-gate 	MAC_STAT_BRDCSTXMT,
2130Sstevel@tonic-gate 	MAC_STAT_NORCVBUF,
2140Sstevel@tonic-gate 	MAC_STAT_IERRORS,
2150Sstevel@tonic-gate 	MAC_STAT_UNKNOWNS,
2160Sstevel@tonic-gate 	MAC_STAT_NOXMTBUF,
2170Sstevel@tonic-gate 	MAC_STAT_OERRORS,
2180Sstevel@tonic-gate 	MAC_STAT_COLLISIONS,
2190Sstevel@tonic-gate 	MAC_STAT_RBYTES,
2200Sstevel@tonic-gate 	MAC_STAT_IPACKETS,
2210Sstevel@tonic-gate 	MAC_STAT_OBYTES,
2224089Sgd78059 	MAC_STAT_OPACKETS,
2234089Sgd78059 	MAC_STAT_UNDERFLOWS,
2244089Sgd78059 	MAC_STAT_OVERFLOWS
2252311Sseb };
2260Sstevel@tonic-gate 
2274089Sgd78059 #define	MAC_NSTAT	(MAC_STAT_OVERFLOWS - MAC_STAT_IFSPEED + 1)
2280Sstevel@tonic-gate 
2292311Sseb #define	MAC_STAT_ISACOUNTER(_stat) (		\
2302311Sseb 	    (_stat) == MAC_STAT_MULTIRCV ||	\
2312311Sseb 	    (_stat) == MAC_STAT_BRDCSTRCV ||	\
2322311Sseb 	    (_stat) == MAC_STAT_MULTIXMT ||	\
2332311Sseb 	    (_stat) == MAC_STAT_BRDCSTXMT ||	\
2342311Sseb 	    (_stat) == MAC_STAT_NORCVBUF ||	\
2352311Sseb 	    (_stat) == MAC_STAT_IERRORS ||	\
2362311Sseb 	    (_stat) == MAC_STAT_UNKNOWNS ||	\
2372311Sseb 	    (_stat) == MAC_STAT_NOXMTBUF ||	\
2382311Sseb 	    (_stat) == MAC_STAT_OERRORS ||	\
2392311Sseb 	    (_stat) == MAC_STAT_COLLISIONS ||	\
2402311Sseb 	    (_stat) == MAC_STAT_RBYTES ||	\
2412311Sseb 	    (_stat) == MAC_STAT_IPACKETS ||	\
2422311Sseb 	    (_stat) == MAC_STAT_OBYTES ||	\
2434089Sgd78059 	    (_stat) == MAC_STAT_OPACKETS ||	\
2444089Sgd78059 	    (_stat) == MAC_STAT_UNDERFLOWS ||	\
2454089Sgd78059 	    (_stat) == MAC_STAT_OVERFLOWS)
2460Sstevel@tonic-gate 
2470Sstevel@tonic-gate /*
2480Sstevel@tonic-gate  * Immutable information. (This may not be modified after registration).
2490Sstevel@tonic-gate  */
2500Sstevel@tonic-gate typedef struct mac_info_s {
2510Sstevel@tonic-gate 	uint_t		mi_media;
2523147Sxc151355 	uint_t		mi_nativemedia;
2530Sstevel@tonic-gate 	uint_t		mi_addr_length;
2542311Sseb 	uint8_t		*mi_unicst_addr;
2552311Sseb 	uint8_t		*mi_brdcst_addr;
2560Sstevel@tonic-gate } mac_info_t;
2570Sstevel@tonic-gate 
2580Sstevel@tonic-gate /*
2595895Syz147064  * Information for legacy devices.
2605895Syz147064  */
2615895Syz147064 typedef struct mac_capab_legacy_s {
2625895Syz147064 	/*
2635895Syz147064 	 * Notifications that the legacy device does not support.
2645895Syz147064 	 */
2655895Syz147064 	uint32_t	ml_unsup_note;
2665895Syz147064 	/*
2675895Syz147064 	 * dev_t of the legacy device; can be held to force attach.
2685895Syz147064 	 */
2695895Syz147064 	dev_t		ml_dev;
2705895Syz147064 } mac_capab_legacy_t;
2715895Syz147064 
2725895Syz147064 /*
2738275SEric Cheng  * When VNICs are created on top of the NIC, there are two levels
2748275SEric Cheng  * of MAC layer, a lower MAC, which is the MAC layer at the level of the
2758275SEric Cheng  * physical NIC, and an upper MAC, which is the MAC layer at the level
2768275SEric Cheng  * of the VNIC. Each VNIC maps to a MAC client at the lower MAC, and
2778275SEric Cheng  * the SRS and classification is done at the lower MAC level. The upper
2788275SEric Cheng  * MAC is therefore for the most part pass-through, and therefore
2798275SEric Cheng  * special processing needs to be done at the upper MAC layer when
2808275SEric Cheng  * dealing with a VNIC.
2818275SEric Cheng  *
2828275SEric Cheng  * This capability allows the MAC layer to detect when a VNIC is being
2838275SEric Cheng  * access, and implement the required shortcuts.
2840Sstevel@tonic-gate  */
2856495Sspeer 
2868275SEric Cheng typedef void *(*mac_client_handle_fn_t)(void *);
2876495Sspeer 
2888275SEric Cheng typedef struct mac_capab_vnic_s {
2898275SEric Cheng 	void			*mcv_arg;
2908275SEric Cheng 	mac_client_handle_fn_t	mcv_mac_client_handle;
2918275SEric Cheng } mac_capab_vnic_t;
2926495Sspeer 
2938275SEric Cheng typedef void (*mac_rename_fn_t)(const char *, void *);
2948275SEric Cheng typedef struct mac_capab_aggr_s {
2958275SEric Cheng 	mac_rename_fn_t mca_rename_fn;
2968275SEric Cheng 	int (*mca_unicst)(void *, const uint8_t *);
2978275SEric Cheng } mac_capab_aggr_t;
2986495Sspeer 
2990Sstevel@tonic-gate typedef enum {
3000Sstevel@tonic-gate 	MAC_NOTE_LINK,
3010Sstevel@tonic-gate 	MAC_NOTE_PROMISC,
3020Sstevel@tonic-gate 	MAC_NOTE_UNICST,
3030Sstevel@tonic-gate 	MAC_NOTE_TX,
3040Sstevel@tonic-gate 	MAC_NOTE_RESOURCE,
3050Sstevel@tonic-gate 	MAC_NOTE_DEVPROMISC,
3062311Sseb 	MAC_NOTE_FASTPATH_FLUSH,
3075903Ssowmini 	MAC_NOTE_SDU_SIZE,
3085895Syz147064 	MAC_NOTE_MARGIN,
3098275SEric Cheng 	MAC_NOTE_CAPAB_CHG,
3100Sstevel@tonic-gate 	MAC_NNOTE	/* must be the last entry */
3110Sstevel@tonic-gate } mac_notify_type_t;
3120Sstevel@tonic-gate 
3130Sstevel@tonic-gate typedef void		(*mac_notify_t)(void *, mac_notify_type_t);
3148275SEric Cheng typedef void		(*mac_rx_t)(void *, mac_resource_handle_t, mblk_t *,
3158275SEric Cheng 			    boolean_t);
3168275SEric Cheng typedef	mblk_t		*(*mac_receive_t)(void *, int);
3170Sstevel@tonic-gate 
3180Sstevel@tonic-gate /*
3190Sstevel@tonic-gate  * MAC promiscuous types
3200Sstevel@tonic-gate  */
3210Sstevel@tonic-gate typedef enum {
3220Sstevel@tonic-gate 	MAC_PROMISC = 0x01,		/* MAC instance is promiscuous */
3230Sstevel@tonic-gate 	MAC_DEVPROMISC = 0x02		/* Device is promiscuous */
3240Sstevel@tonic-gate } mac_promisc_type_t;
3250Sstevel@tonic-gate 
3260Sstevel@tonic-gate /*
3270Sstevel@tonic-gate  * MAC resource types
3280Sstevel@tonic-gate  */
3290Sstevel@tonic-gate typedef enum {
3300Sstevel@tonic-gate 	MAC_RX_FIFO = 1
3310Sstevel@tonic-gate } mac_resource_type_t;
3320Sstevel@tonic-gate 
3338275SEric Cheng typedef	int	(*mac_intr_enable_t)(mac_intr_handle_t);
3348275SEric Cheng typedef	int	(*mac_intr_disable_t)(mac_intr_handle_t);
3358275SEric Cheng 
3368275SEric Cheng typedef	struct mac_intr_s {
3378275SEric Cheng 	mac_intr_handle_t	mi_handle;
3388275SEric Cheng 	mac_intr_enable_t	mi_enable;
3398275SEric Cheng 	mac_intr_disable_t	mi_disable;
3408275SEric Cheng } mac_intr_t;
3418275SEric Cheng 
3420Sstevel@tonic-gate typedef struct mac_rx_fifo_s {
3430Sstevel@tonic-gate 	mac_resource_type_t	mrf_type;	/* MAC_RX_FIFO */
3448275SEric Cheng 	mac_intr_t		mrf_intr;
3458275SEric Cheng 	mac_receive_t		mrf_receive;
3468275SEric Cheng 	void			*mrf_rx_arg;
3478275SEric Cheng 	uint32_t		mrf_flow_priority;
3488275SEric Cheng 	/*
3498275SEric Cheng 	 * The CPU this flow is to be processed on. With intrd and future
3508275SEric Cheng 	 * things, we should know which CPU the flow needs to be processed
3518275SEric Cheng 	 * and get a squeue assigned on that CPU.
3528275SEric Cheng 	 */
3538275SEric Cheng 	uint_t			mrf_cpu_id;
3540Sstevel@tonic-gate } mac_rx_fifo_t;
3550Sstevel@tonic-gate 
3568275SEric Cheng #define	mrf_intr_handle		mrf_intr.mi_handle
3578275SEric Cheng #define	mrf_intr_enable		mrf_intr.mi_enable
3588275SEric Cheng #define	mrf_intr_disable	mrf_intr.mi_disable
35956Smeem 
3600Sstevel@tonic-gate typedef union mac_resource_u {
3610Sstevel@tonic-gate 	mac_resource_type_t	mr_type;
3620Sstevel@tonic-gate 	mac_rx_fifo_t		mr_fifo;
3630Sstevel@tonic-gate } mac_resource_t;
3640Sstevel@tonic-gate 
3652311Sseb typedef enum {
3662311Sseb 	MAC_ADDRTYPE_UNICAST,
3672311Sseb 	MAC_ADDRTYPE_MULTICAST,
3682311Sseb 	MAC_ADDRTYPE_BROADCAST
3692311Sseb } mac_addrtype_t;
3702311Sseb 
3712311Sseb typedef struct mac_header_info_s {
3722311Sseb 	size_t		mhi_hdrsize;
3732311Sseb 	size_t		mhi_pktsize;
3742311Sseb 	const uint8_t	*mhi_daddr;
3752311Sseb 	const uint8_t	*mhi_saddr;
3762311Sseb 	uint32_t	mhi_origsap;
3772311Sseb 	uint32_t	mhi_bindsap;
3782311Sseb 	mac_addrtype_t	mhi_dsttype;
3792760Sdg199075 	uint16_t	mhi_tci;
3808275SEric Cheng 	boolean_t	mhi_istagged;
3812311Sseb } mac_header_info_t;
3822311Sseb 
3832311Sseb /*
3848275SEric Cheng  * Function pointer to match dls client signature. Should be same as
3858275SEric Cheng  * dls_rx_t to allow a soft ring to bypass DLS layer and call a DLS
3868275SEric Cheng  * client directly.
3878275SEric Cheng  */
3888275SEric Cheng typedef	void		(*mac_direct_rx_t)(void *, mac_resource_handle_t,
3898275SEric Cheng 				mblk_t *, mac_header_info_t *);
3908275SEric Cheng 
3918275SEric Cheng typedef mac_resource_handle_t	(*mac_resource_add_t)(void *, mac_resource_t *);
3928275SEric Cheng typedef int			(*mac_resource_bind_t)(void *,
3938275SEric Cheng     mac_resource_handle_t, processorid_t);
3948275SEric Cheng typedef void			(*mac_resource_remove_t)(void *, void *);
3958275SEric Cheng typedef void			(*mac_resource_quiesce_t)(void *, void *);
3968275SEric Cheng typedef void			(*mac_resource_restart_t)(void *, void *);
3978275SEric Cheng typedef int			(*mac_resource_modify_t)(void *, void *,
3988275SEric Cheng 				    mac_resource_t *);
3998275SEric Cheng typedef	void			(*mac_change_upcall_t)(void *, mac_direct_rx_t,
4008275SEric Cheng     void *);
4018275SEric Cheng 
4028275SEric Cheng /*
4032311Sseb  * MAC-Type plugin interfaces
4042311Sseb  */
4052311Sseb 
4062311Sseb typedef int		(*mtops_addr_verify_t)(const void *, void *);
4072311Sseb typedef boolean_t	(*mtops_sap_verify_t)(uint32_t, uint32_t *, void *);
4082311Sseb typedef mblk_t		*(*mtops_header_t)(const void *, const void *,
4092311Sseb     uint32_t, void *, mblk_t *, size_t);
4102311Sseb typedef int		(*mtops_header_info_t)(mblk_t *, void *,
4112311Sseb     mac_header_info_t *);
4122311Sseb typedef boolean_t	(*mtops_pdata_verify_t)(void *, size_t);
4132311Sseb typedef	mblk_t		*(*mtops_header_modify_t)(mblk_t *, void *);
4144403Sgd78059 typedef void		(*mtops_link_details_t)(char *, size_t, mac_handle_t,
4154403Sgd78059     void *);
4162311Sseb 
4172311Sseb typedef struct mactype_ops_s {
4182311Sseb 	uint_t			mtops_ops;
4192311Sseb 	/*
4202311Sseb 	 * mtops_unicst_verify() returns 0 if the given address is a valid
4212311Sseb 	 * unicast address, or a non-zero errno otherwise.
4222311Sseb 	 */
4232311Sseb 	mtops_addr_verify_t	mtops_unicst_verify;
4242311Sseb 	/*
4252311Sseb 	 * mtops_multicst_verify() returns 0 if the given address is a
4262311Sseb 	 * valid multicast address, or a non-zero errno otherwise.  If the
4272311Sseb 	 * media doesn't support multicast, ENOTSUP should be returned (for
4282311Sseb 	 * example).
4292311Sseb 	 */
4302311Sseb 	mtops_addr_verify_t	mtops_multicst_verify;
4312311Sseb 	/*
4322311Sseb 	 * mtops_sap_verify() returns B_TRUE if the given SAP is a valid
4332311Sseb 	 * SAP value, or B_FALSE otherwise.
4342311Sseb 	 */
4352311Sseb 	mtops_sap_verify_t	mtops_sap_verify;
4362311Sseb 	/*
4372311Sseb 	 * mtops_header() is used to allocate and construct a MAC header.
4382311Sseb 	 */
4392311Sseb 	mtops_header_t		mtops_header;
4402311Sseb 	/*
4412311Sseb 	 * mtops_header_info() is used to gather information on a given MAC
4422311Sseb 	 * header.
4432311Sseb 	 */
4442311Sseb 	mtops_header_info_t	mtops_header_info;
4452311Sseb 	/*
4462311Sseb 	 * mtops_pdata_verify() is used to verify the validity of MAC
4472311Sseb 	 * plugin data.  It is called by mac_register() if the driver has
4482311Sseb 	 * supplied MAC plugin data, and also by mac_pdata_update() when
4492311Sseb 	 * drivers update the data.
4502311Sseb 	 */
4512311Sseb 	mtops_pdata_verify_t	mtops_pdata_verify;
4522311Sseb 	/*
4532311Sseb 	 * mtops_header_cook() is an optional callback that converts (or
4542311Sseb 	 * "cooks") the given raw header (as sent by a raw DLPI consumer)
4552311Sseb 	 * into one that is appropriate to send down to the MAC driver.
4562311Sseb 	 * Following the example above, an Ethernet header sent down by a
4572311Sseb 	 * DLPI consumer would be converted to whatever header the MAC
4582311Sseb 	 * driver expects.
4592311Sseb 	 */
4602311Sseb 	mtops_header_modify_t	mtops_header_cook;
4612311Sseb 	/*
4622311Sseb 	 * mtops_header_uncook() is an optional callback that does the
4632311Sseb 	 * opposite of mtops_header_cook().  It "uncooks" a given MAC
4642311Sseb 	 * header (as received from the driver) for consumption by raw DLPI
4652311Sseb 	 * consumers.  For example, for a non-Ethernet plugin that wants
4662311Sseb 	 * raw DLPI consumers to be fooled into thinking that the device
4672311Sseb 	 * provides Ethernet access, this callback would modify the given
4682311Sseb 	 * mblk_t such that the MAC header is converted to an Ethernet
4692311Sseb 	 * header.
4702311Sseb 	 */
4712311Sseb 	mtops_header_modify_t	mtops_header_uncook;
4724403Sgd78059 	/*
4734403Sgd78059 	 * mtops_link_details() is an optional callback that provides
4744403Sgd78059 	 * extended information about the link state.  Its primary purpose
4754403Sgd78059 	 * is to provide type-specific support for syslog contents on
4764403Sgd78059 	 * link up events.  If no implementation is provided, then a default
4774403Sgd78059 	 * implementation will be used.
4784403Sgd78059 	 */
4794403Sgd78059 	mtops_link_details_t	mtops_link_details;
4802311Sseb } mactype_ops_t;
4812311Sseb 
4822311Sseb /*
4832311Sseb  * mtops_ops exists for the plugin to enumerate the optional callback
4842311Sseb  * entrypoints it has defined.  This allows the mac module to define
4852311Sseb  * additional plugin entrypoints in mactype_ops_t without breaking backward
4862311Sseb  * compatibility with old plugins.
4872311Sseb  */
4882311Sseb #define	MTOPS_PDATA_VERIFY	0x001
4892311Sseb #define	MTOPS_HEADER_COOK	0x002
4902311Sseb #define	MTOPS_HEADER_UNCOOK	0x004
4914403Sgd78059 #define	MTOPS_LINK_DETAILS	0x008
4922311Sseb 
4936512Ssowmini /*
4946512Ssowmini  * Provide mapping for legacy ndd ioctls relevant to that mactype.
4956512Ssowmini  * Note that the ndd ioctls are obsolete, and may be removed in a future
4966512Ssowmini  * release of Solaris. The ndd ioctls are not typically used in legacy
4976512Ssowmini  * ethernet drivers. New datalink drivers of all link-types should use
4986512Ssowmini  * dladm(1m) interfaces for administering tunables and not have to provide
4996512Ssowmini  * a mapping.
5006512Ssowmini  */
5016512Ssowmini typedef struct mac_ndd_mapping_s {
5026512Ssowmini 	char		*mp_name;
5036512Ssowmini 	union {
5046512Ssowmini 		mac_prop_id_t   u_id;
5056512Ssowmini 		uint_t		u_kstat;
5066512Ssowmini 	} u_mp_id;
5076512Ssowmini 	long		mp_minval;
5086512Ssowmini 	long		mp_maxval;
5096512Ssowmini 	size_t		mp_valsize;
5106512Ssowmini 	int		mp_flags;
5116512Ssowmini } mac_ndd_mapping_t;
5126512Ssowmini 
5136512Ssowmini #define	mp_prop_id	u_mp_id.u_id
5146512Ssowmini #define	mp_kstat	u_mp_id.u_kstat
5156512Ssowmini 
5168275SEric Cheng typedef struct mac_stat_info_s {
5178275SEric Cheng 	uint_t		msi_stat;
5188275SEric Cheng 	char		*msi_name;
5198275SEric Cheng 	uint_t		msi_type;	/* as defined in kstat_named_init(9F) */
5208275SEric Cheng 	uint64_t	msi_default;
5218275SEric Cheng } mac_stat_info_t;
5228275SEric Cheng 
5232311Sseb typedef struct mactype_register_s {
5242311Sseb 	uint_t		mtr_version;	/* set by mactype_alloc() */
5252311Sseb 	const char	*mtr_ident;
5262311Sseb 	mactype_ops_t	*mtr_ops;
5272311Sseb 	uint_t		mtr_mactype;
5283147Sxc151355 	uint_t		mtr_nativetype;
5292311Sseb 	uint_t		mtr_addrlen;
5302311Sseb 	uint8_t		*mtr_brdcst_addr;
5312311Sseb 	mac_stat_info_t	*mtr_stats;
5322311Sseb 	size_t		mtr_statcount;
5336512Ssowmini 	mac_ndd_mapping_t *mtr_mapping;
5346512Ssowmini 	size_t		mtr_mappingcount;
5352311Sseb } mactype_register_t;
5362311Sseb 
5375903Ssowmini typedef struct mac_prop_s {
5385903Ssowmini 	mac_prop_id_t	mp_id;
5395903Ssowmini 	char		*mp_name;
5406512Ssowmini 	uint_t		mp_flags;
5415903Ssowmini } mac_prop_t;
5425903Ssowmini 
5430Sstevel@tonic-gate /*
5448275SEric Cheng  * Driver interface functions.
5450Sstevel@tonic-gate  */
5465895Syz147064 extern int			mac_open_by_linkid(datalink_id_t,
5475895Syz147064 				    mac_handle_t *);
5485895Syz147064 extern int			mac_open_by_linkname(const char *,
5495895Syz147064 				    mac_handle_t *);
5505895Syz147064 extern const char		*mac_name(mac_handle_t);
5515895Syz147064 extern minor_t			mac_minor(mac_handle_t);
5525895Syz147064 extern minor_t			mac_minor_hold(boolean_t);
5535895Syz147064 extern void			mac_minor_rele(minor_t);
5548275SEric Cheng extern void			mac_sdu_get(mac_handle_t, uint_t *, uint_t *);
5558275SEric Cheng extern int			mac_maxsdu_update(mac_handle_t, uint_t);
5560Sstevel@tonic-gate 
5572311Sseb extern void 			mac_unicst_update(mac_handle_t,
5585895Syz147064 				    const uint8_t *);
5592311Sseb extern void			mac_resource_update(mac_handle_t);
5608275SEric Cheng extern void			mac_capab_update(mac_handle_t);
5612311Sseb extern int			mac_pdata_update(mac_handle_t, void *,
5625895Syz147064 				    size_t);
5635895Syz147064 extern boolean_t		mac_margin_update(mac_handle_t, uint32_t);
5645895Syz147064 extern void			mac_margin_get(mac_handle_t, uint32_t *);
5655895Syz147064 extern int			mac_margin_remove(mac_handle_t, uint32_t);
5665895Syz147064 extern int			mac_margin_add(mac_handle_t, uint32_t *,
5675895Syz147064 				    boolean_t);
5685895Syz147064 
5692311Sseb extern mactype_register_t	*mactype_alloc(uint_t);
5702311Sseb extern void			mactype_free(mactype_register_t *);
5712311Sseb extern int			mactype_register(mactype_register_t *);
5722311Sseb extern int			mactype_unregister(const char *);
5738275SEric Cheng 
5748275SEric Cheng extern void			mac_start_logusage(mac_logtype_t, uint_t);
5758275SEric Cheng extern void			mac_stop_logusage(mac_logtype_t);
5768275SEric Cheng 
5778275SEric Cheng extern mac_handle_t		mac_get_lower_mac_handle(mac_handle_t);
5780Sstevel@tonic-gate 
579*8833SVenu.Iyer@Sun.COM /*
580*8833SVenu.Iyer@Sun.COM  * Packet hashing for distribution to multiple ports and rings.
581*8833SVenu.Iyer@Sun.COM  */
582*8833SVenu.Iyer@Sun.COM 
583*8833SVenu.Iyer@Sun.COM #define	MAC_PKT_HASH_L2		0x01
584*8833SVenu.Iyer@Sun.COM #define	MAC_PKT_HASH_L3		0x02
585*8833SVenu.Iyer@Sun.COM #define	MAC_PKT_HASH_L4		0x04
586*8833SVenu.Iyer@Sun.COM 
587*8833SVenu.Iyer@Sun.COM extern uint64_t			mac_pkt_hash(uint_t, mblk_t *, uint8_t,
588*8833SVenu.Iyer@Sun.COM 				    boolean_t);
589*8833SVenu.Iyer@Sun.COM 
5900Sstevel@tonic-gate #endif	/* _KERNEL */
5910Sstevel@tonic-gate 
5920Sstevel@tonic-gate #ifdef	__cplusplus
5930Sstevel@tonic-gate }
5940Sstevel@tonic-gate #endif
5950Sstevel@tonic-gate 
5960Sstevel@tonic-gate #endif /* _SYS_MAC_H */
597