xref: /titanic_51/usr/src/uts/common/sys/mac.h (revision bcb5c89da22515e2ccf139578bad3caebcd716ad)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5ba2e4443Sseb  * Common Development and Distribution License (the "License").
6ba2e4443Sseb  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22d62bc4baSyz147064  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_SYS_MAC_H
277c478bd9Sstevel@tonic-gate #define	_SYS_MAC_H
287c478bd9Sstevel@tonic-gate 
29605445d5Sdg199075 #include <sys/types.h>
307c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
317c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
327c478bd9Sstevel@tonic-gate #include <sys/stream.h>
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate /*
357c478bd9Sstevel@tonic-gate  * MAC Services Module
367c478bd9Sstevel@tonic-gate  */
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
397c478bd9Sstevel@tonic-gate extern "C" {
407c478bd9Sstevel@tonic-gate #endif
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate /*
437c478bd9Sstevel@tonic-gate  * MAC Information (text emitted by modinfo(1m))
447c478bd9Sstevel@tonic-gate  */
454045d941Ssowmini #define	MAC_INFO	"MAC Services"
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate /*
48ba2e4443Sseb  * MAC version identifier.  This is used by mac_alloc() mac_register() to
49ba2e4443Sseb  * verify that incompatible drivers don't register.
50ba2e4443Sseb  */
51ba2e4443Sseb #define	MAC_VERSION	0x1
52ba2e4443Sseb 
53ba2e4443Sseb /*
54ba2e4443Sseb  * MAC-Type version identifier.  This is used by mactype_alloc() and
55ba2e4443Sseb  * mactype_register() to verify that incompatible MAC-Type plugins don't
56ba2e4443Sseb  * register.
57ba2e4443Sseb  */
58ba2e4443Sseb #define	MACTYPE_VERSION	0x1
59ba2e4443Sseb 
60ba2e4443Sseb /*
617c478bd9Sstevel@tonic-gate  * Statistics
627c478bd9Sstevel@tonic-gate  */
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate #define	XCVR_UNDEFINED		0
657c478bd9Sstevel@tonic-gate #define	XCVR_NONE		1
667c478bd9Sstevel@tonic-gate #define	XCVR_10			2
677c478bd9Sstevel@tonic-gate #define	XCVR_100T4		3
687c478bd9Sstevel@tonic-gate #define	XCVR_100X		4
697c478bd9Sstevel@tonic-gate #define	XCVR_100T2		5
707c478bd9Sstevel@tonic-gate #define	XCVR_1000X		6
717c478bd9Sstevel@tonic-gate #define	XCVR_1000T		7
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate typedef enum {
747c478bd9Sstevel@tonic-gate 	LINK_STATE_UNKNOWN = -1,
757c478bd9Sstevel@tonic-gate 	LINK_STATE_DOWN,
767c478bd9Sstevel@tonic-gate 	LINK_STATE_UP
777c478bd9Sstevel@tonic-gate } link_state_t;
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate typedef enum {
807c478bd9Sstevel@tonic-gate 	LINK_DUPLEX_UNKNOWN = 0,
817c478bd9Sstevel@tonic-gate 	LINK_DUPLEX_HALF,
827c478bd9Sstevel@tonic-gate 	LINK_DUPLEX_FULL
837c478bd9Sstevel@tonic-gate } link_duplex_t;
847c478bd9Sstevel@tonic-gate 
85d62bc4baSyz147064 #define	DATALINK_INVALID_LINKID	0
86d62bc4baSyz147064 #define	DATALINK_ALL_LINKID	0
87d62bc4baSyz147064 #define	DATALINK_MAX_LINKID	0xffffffff
88d62bc4baSyz147064 
89e7801d59Ssowmini typedef enum {
90e7801d59Ssowmini 	LINK_FLOWCTRL_NONE = 0,
91e7801d59Ssowmini 	LINK_FLOWCTRL_RX,
92e7801d59Ssowmini 	LINK_FLOWCTRL_TX,
93e7801d59Ssowmini 	LINK_FLOWCTRL_BI
94e7801d59Ssowmini } link_flowctrl_t;
95e7801d59Ssowmini 
963fd94f8cSam223141 typedef uint32_t datalink_id_t;
973fd94f8cSam223141 
983fd94f8cSam223141 /*
993fd94f8cSam223141  * Encodings for public properties.
1003fd94f8cSam223141  * A most significant bit value of 1 indicates private property, intended
1013fd94f8cSam223141  * to allow private property implementations to use internal encodings
1023fd94f8cSam223141  * if desired.
1033fd94f8cSam223141  *
1043fd94f8cSam223141  * Note that there are 2 sets of parameters: the *_EN_*
1053fd94f8cSam223141  * values are those that the Administrator configures for autonegotiation.
1063fd94f8cSam223141  * The _ADV_* values are those that are currently exposed over the wire.
1073fd94f8cSam223141  */
1083fd94f8cSam223141 #define	MAXLINKPROPNAME		256
1093fd94f8cSam223141 #define	MAC_PROP_DEFAULT	0x0001
1103fd94f8cSam223141 typedef enum {
1113fd94f8cSam223141 	MAC_PROP_DUPLEX = 0x00000001,
1123fd94f8cSam223141 	MAC_PROP_SPEED,
1133fd94f8cSam223141 	MAC_PROP_STATUS,
1143fd94f8cSam223141 	MAC_PROP_AUTONEG,
1153fd94f8cSam223141 	MAC_PROP_EN_AUTONEG,
1163fd94f8cSam223141 	MAC_PROP_MTU,
1173bc21d0aSAruna Ramakrishna - Sun Microsystems 	MAC_PROP_ZONE,
1183bc21d0aSAruna Ramakrishna - Sun Microsystems 	MAC_PROP_AUTOPUSH,
1193fd94f8cSam223141 	MAC_PROP_FLOWCTRL,
1203fd94f8cSam223141 	MAC_PROP_ADV_1000FDX_CAP,
1213fd94f8cSam223141 	MAC_PROP_EN_1000FDX_CAP,
1223fd94f8cSam223141 	MAC_PROP_ADV_1000HDX_CAP,
1233fd94f8cSam223141 	MAC_PROP_EN_1000HDX_CAP,
1243fd94f8cSam223141 	MAC_PROP_ADV_100FDX_CAP,
1253fd94f8cSam223141 	MAC_PROP_EN_100FDX_CAP,
1263fd94f8cSam223141 	MAC_PROP_ADV_100HDX_CAP,
1273fd94f8cSam223141 	MAC_PROP_EN_100HDX_CAP,
1283fd94f8cSam223141 	MAC_PROP_ADV_10FDX_CAP,
1293fd94f8cSam223141 	MAC_PROP_EN_10FDX_CAP,
1303fd94f8cSam223141 	MAC_PROP_ADV_10HDX_CAP,
1313fd94f8cSam223141 	MAC_PROP_EN_10HDX_CAP,
1323fd94f8cSam223141 	MAC_PROP_ADV_100T4_CAP,
1333fd94f8cSam223141 	MAC_PROP_EN_100T4_CAP,
134*bcb5c89dSSowmini Varadhan 	MAC_PROP_WL_ESSID,
135*bcb5c89dSSowmini Varadhan 	MAC_PROP_WL_BSSID,
136*bcb5c89dSSowmini Varadhan 	MAC_PROP_WL_BSSTYPE,
137*bcb5c89dSSowmini Varadhan 	MAC_PROP_WL_LINKSTATUS,
138*bcb5c89dSSowmini Varadhan 	MAC_PROP_WL_DESIRED_RATES,
139*bcb5c89dSSowmini Varadhan 	MAC_PROP_WL_SUPPORTED_RATES,
140*bcb5c89dSSowmini Varadhan 	MAC_PROP_WL_AUTH_MODE,
141*bcb5c89dSSowmini Varadhan 	MAC_PROP_WL_ENCRYPTION,
142*bcb5c89dSSowmini Varadhan 	MAC_PROP_WL_RSSI,
143*bcb5c89dSSowmini Varadhan 	MAC_PROP_WL_PHY_CONFIG,
144*bcb5c89dSSowmini Varadhan 	MAC_PROP_WL_CAPABILITY,
145*bcb5c89dSSowmini Varadhan 	MAC_PROP_WL_WPA,
146*bcb5c89dSSowmini Varadhan 	MAC_PROP_WL_SCANRESULTS,
147*bcb5c89dSSowmini Varadhan 	MAC_PROP_WL_POWER_MODE,
148*bcb5c89dSSowmini Varadhan 	MAC_PROP_WL_RADIO,
149*bcb5c89dSSowmini Varadhan 	MAC_PROP_WL_ESS_LIST,
150*bcb5c89dSSowmini Varadhan 	MAC_PROP_WL_KEY_TAB,
151*bcb5c89dSSowmini Varadhan 	MAC_PROP_WL_CREATE_IBSS,
152*bcb5c89dSSowmini Varadhan 	MAC_PROP_WL_SETOPTIE,
153*bcb5c89dSSowmini Varadhan 	MAC_PROP_WL_DELKEY,
154*bcb5c89dSSowmini Varadhan 	MAC_PROP_WL_KEY,
155*bcb5c89dSSowmini Varadhan 	MAC_PROP_WL_MLME,
1563fd94f8cSam223141 	MAC_PROP_PRIVATE = -1
1573fd94f8cSam223141 } mac_prop_id_t;
1583fd94f8cSam223141 
159843e1988Sjohnlev /*
160843e1988Sjohnlev  * Maximum MAC address length
161843e1988Sjohnlev  */
162843e1988Sjohnlev #define	MAXMACADDRLEN	20
163843e1988Sjohnlev 
1647c478bd9Sstevel@tonic-gate #ifdef	_KERNEL
1657c478bd9Sstevel@tonic-gate 
166ba2e4443Sseb typedef struct mac_stat_info_s {
167ba2e4443Sseb 	uint_t		msi_stat;
168ba2e4443Sseb 	char		*msi_name;
169ba2e4443Sseb 	uint_t		msi_type;	/* as defined in kstat_named_init(9F) */
170ba2e4443Sseb 	uint64_t	msi_default;
171ba2e4443Sseb } mac_stat_info_t;
172ba2e4443Sseb 
1737c478bd9Sstevel@tonic-gate /*
174ba2e4443Sseb  * There are three ranges of statistics values.  0 to 1 - MAC_STAT_MIN are
175ba2e4443Sseb  * interface statistics maintained by the mac module.  MAC_STAT_MIN to 1 -
176ba2e4443Sseb  * MACTYPE_STAT_MIN are common MAC statistics defined by the mac module and
177ba2e4443Sseb  * maintained by each driver.  MACTYPE_STAT_MIN and above are statistics
178ba2e4443Sseb  * defined by MAC-Type plugins and maintained by each driver.
1797c478bd9Sstevel@tonic-gate  */
180ba2e4443Sseb #define	MAC_STAT_MIN		1000
181ba2e4443Sseb #define	MACTYPE_STAT_MIN	2000
182ba2e4443Sseb 
183ba2e4443Sseb #define	IS_MAC_STAT(stat)	\
184ba2e4443Sseb 	(stat >= MAC_STAT_MIN && stat < MACTYPE_STAT_MIN)
185ba2e4443Sseb #define	IS_MACTYPE_STAT(stat)	(stat >= MACTYPE_STAT_MIN)
186ba2e4443Sseb 
1879b14cf1dSgd78059 /*
188d62bc4baSyz147064  * Statistics maintained by the mac module, and possibly populated as link
189d62bc4baSyz147064  * statistics.
190d62bc4baSyz147064  */
191d62bc4baSyz147064 enum mac_mod_stat {
192d62bc4baSyz147064 	MAC_STAT_LINK_STATE,
193d62bc4baSyz147064 	MAC_STAT_LINK_UP,
194d62bc4baSyz147064 	MAC_STAT_PROMISC
195d62bc4baSyz147064 };
196d62bc4baSyz147064 
197d62bc4baSyz147064 /*
1989b14cf1dSgd78059  * Do not reorder, and add only to the end of this list.
1999b14cf1dSgd78059  */
200ba2e4443Sseb enum mac_driver_stat {
201ba2e4443Sseb 	/* MIB-II stats (RFC 1213 and RFC 1573) */
202ba2e4443Sseb 	MAC_STAT_IFSPEED = MAC_STAT_MIN,
2037c478bd9Sstevel@tonic-gate 	MAC_STAT_MULTIRCV,
2047c478bd9Sstevel@tonic-gate 	MAC_STAT_BRDCSTRCV,
2057c478bd9Sstevel@tonic-gate 	MAC_STAT_MULTIXMT,
2067c478bd9Sstevel@tonic-gate 	MAC_STAT_BRDCSTXMT,
2077c478bd9Sstevel@tonic-gate 	MAC_STAT_NORCVBUF,
2087c478bd9Sstevel@tonic-gate 	MAC_STAT_IERRORS,
2097c478bd9Sstevel@tonic-gate 	MAC_STAT_UNKNOWNS,
2107c478bd9Sstevel@tonic-gate 	MAC_STAT_NOXMTBUF,
2117c478bd9Sstevel@tonic-gate 	MAC_STAT_OERRORS,
2127c478bd9Sstevel@tonic-gate 	MAC_STAT_COLLISIONS,
2137c478bd9Sstevel@tonic-gate 	MAC_STAT_RBYTES,
2147c478bd9Sstevel@tonic-gate 	MAC_STAT_IPACKETS,
2157c478bd9Sstevel@tonic-gate 	MAC_STAT_OBYTES,
2169b14cf1dSgd78059 	MAC_STAT_OPACKETS,
2179b14cf1dSgd78059 	MAC_STAT_UNDERFLOWS,
2189b14cf1dSgd78059 	MAC_STAT_OVERFLOWS
2197c478bd9Sstevel@tonic-gate };
2207c478bd9Sstevel@tonic-gate 
2219b14cf1dSgd78059 #define	MAC_NSTAT	(MAC_STAT_OVERFLOWS - MAC_STAT_IFSPEED + 1)
222ba2e4443Sseb 
223ba2e4443Sseb #define	MAC_STAT_ISACOUNTER(_stat) (		\
224ba2e4443Sseb 	    (_stat) == MAC_STAT_MULTIRCV ||	\
225ba2e4443Sseb 	    (_stat) == MAC_STAT_BRDCSTRCV ||	\
226ba2e4443Sseb 	    (_stat) == MAC_STAT_MULTIXMT ||	\
227ba2e4443Sseb 	    (_stat) == MAC_STAT_BRDCSTXMT ||	\
228ba2e4443Sseb 	    (_stat) == MAC_STAT_NORCVBUF ||	\
229ba2e4443Sseb 	    (_stat) == MAC_STAT_IERRORS ||	\
230ba2e4443Sseb 	    (_stat) == MAC_STAT_UNKNOWNS ||	\
231ba2e4443Sseb 	    (_stat) == MAC_STAT_NOXMTBUF ||	\
232ba2e4443Sseb 	    (_stat) == MAC_STAT_OERRORS ||	\
233ba2e4443Sseb 	    (_stat) == MAC_STAT_COLLISIONS ||	\
234ba2e4443Sseb 	    (_stat) == MAC_STAT_RBYTES ||	\
235ba2e4443Sseb 	    (_stat) == MAC_STAT_IPACKETS ||	\
236ba2e4443Sseb 	    (_stat) == MAC_STAT_OBYTES ||	\
2379b14cf1dSgd78059 	    (_stat) == MAC_STAT_OPACKETS ||	\
2389b14cf1dSgd78059 	    (_stat) == MAC_STAT_UNDERFLOWS ||	\
2399b14cf1dSgd78059 	    (_stat) == MAC_STAT_OVERFLOWS)
240ba2e4443Sseb 
2417c478bd9Sstevel@tonic-gate /*
2427c478bd9Sstevel@tonic-gate  * Immutable information. (This may not be modified after registration).
2437c478bd9Sstevel@tonic-gate  */
2447c478bd9Sstevel@tonic-gate typedef struct mac_info_s {
2457c478bd9Sstevel@tonic-gate 	uint_t		mi_media;
2460ba2cbe9Sxc151355 	uint_t		mi_nativemedia;
2477c478bd9Sstevel@tonic-gate 	uint_t		mi_addr_length;
248ba2e4443Sseb 	uint8_t		*mi_unicst_addr;
249ba2e4443Sseb 	uint8_t		*mi_brdcst_addr;
2507c478bd9Sstevel@tonic-gate } mac_info_t;
2517c478bd9Sstevel@tonic-gate 
2527c478bd9Sstevel@tonic-gate /*
2538347601bSyl150051  * LSO capability
2548347601bSyl150051  */
2558347601bSyl150051 typedef struct lso_basic_tcp_ipv4_s {
2568347601bSyl150051 	t_uscalar_t	lso_max;		/* maximum payload */
2578347601bSyl150051 } lso_basic_tcp_ipv4_t;
2588347601bSyl150051 
2598347601bSyl150051 /*
2608347601bSyl150051  * Future LSO capabilities can be added at the end of the mac_capab_lso_t.
2618347601bSyl150051  * When such capability is added to the GLDv3 framework, the size of the
2628347601bSyl150051  * mac_capab_lso_t it allocates and passes to the drivers increases. Older
2638347601bSyl150051  * drivers wil access only the (upper) sections of that structure, that is the
2648347601bSyl150051  * sections carrying the capabilities they understand. This ensures the
2658347601bSyl150051  * interface can be safely extended in a binary compatible way.
2668347601bSyl150051  */
2678347601bSyl150051 typedef	struct mac_capab_lso_s {
2688347601bSyl150051 	t_uscalar_t		lso_flags;
2698347601bSyl150051 	lso_basic_tcp_ipv4_t	lso_basic_tcp_ipv4;
2708347601bSyl150051 	/* Add future lso capabilities here */
2718347601bSyl150051 } mac_capab_lso_t;
2728347601bSyl150051 
2738347601bSyl150051 /*
274d62bc4baSyz147064  * Information for legacy devices.
275d62bc4baSyz147064  */
276d62bc4baSyz147064 typedef struct mac_capab_legacy_s {
277d62bc4baSyz147064 	/*
278d62bc4baSyz147064 	 * Notifications that the legacy device does not support.
279d62bc4baSyz147064 	 */
280d62bc4baSyz147064 	uint32_t	ml_unsup_note;
281d62bc4baSyz147064 	/*
282d62bc4baSyz147064 	 * dev_t of the legacy device; can be held to force attach.
283d62bc4baSyz147064 	 */
284d62bc4baSyz147064 	dev_t		ml_dev;
285d62bc4baSyz147064 } mac_capab_legacy_t;
286d62bc4baSyz147064 
287d62bc4baSyz147064 /*
288ba2e4443Sseb  * MAC layer capabilities.  These capabilities are handled by the drivers'
289ba2e4443Sseb  * mc_capab_get() callbacks.  Some capabilities require the driver to fill
290ba2e4443Sseb  * in a given data structure, and others are simply boolean capabilities.
291ba2e4443Sseb  * Note that capability values must be powers of 2 so that consumers and
292ba2e4443Sseb  * providers of this interface can keep track of which capabilities they
293ba2e4443Sseb  * care about by keeping a bitfield of these things around somewhere.
2947c478bd9Sstevel@tonic-gate  */
295ba2e4443Sseb typedef enum {
296ba2e4443Sseb 	MAC_CAPAB_HCKSUM	= 0x01, /* data is a uint32_t for the txflags */
297ed8845d8Skrgopi 	MAC_CAPAB_POLL		= 0x02,	/* boolean only, no data */
2988347601bSyl150051 	MAC_CAPAB_MULTIADDRESS	= 0x04, /* data is multiaddress_capab_t */
299d62bc4baSyz147064 	MAC_CAPAB_LSO		= 0x08, /* data is mac_capab_lso_t */
300d62bc4baSyz147064 	MAC_CAPAB_NO_NATIVEVLAN	= 0x10, /* boolean only, no data */
301d62bc4baSyz147064 	MAC_CAPAB_NO_ZCOPY	= 0x20, /* boolean only, no data */
302ba2e4443Sseb 	/* add new capabilities here */
303678453a8Sspeer 	MAC_CAPAB_RINGS		= 0x100, /* data is mac_capab_rings_t */
304678453a8Sspeer 	MAC_CAPAB_SHARES	= 0x200, /* data is mac_capab_share_t */
305d62bc4baSyz147064 
306d62bc4baSyz147064 	/* The following capabilities are specific to softmac. */
30730890389Sartem 	MAC_CAPAB_LEGACY	= 0x8000 /* data is mac_capab_legacy_t */
308ba2e4443Sseb } mac_capab_t;
3097c478bd9Sstevel@tonic-gate 
310ed8845d8Skrgopi typedef int mac_addr_slot_t;
311ed8845d8Skrgopi 
312ed8845d8Skrgopi /* mma_flags values */
313ed8845d8Skrgopi #define	MMAC_SLOT_USED		0x1   /* address slot used */
314ed8845d8Skrgopi #define	MMAC_SLOT_UNUSED	0x2   /* free address slot */
315ed8845d8Skrgopi #define	MMAC_VENDOR_ADDR	0x4   /* address returned is vendor supplied */
316ed8845d8Skrgopi 
317ed8845d8Skrgopi typedef struct mac_multi_address_s {
318ed8845d8Skrgopi 	mac_addr_slot_t	mma_slot;	/* slot for add/remove/get/set */
319ed8845d8Skrgopi 	uint_t		mma_addrlen;
320ed8845d8Skrgopi 	uint8_t		mma_addr[MAXMACADDRLEN];
321ed8845d8Skrgopi 	uint_t		mma_flags;
322ed8845d8Skrgopi } mac_multi_addr_t;
323ed8845d8Skrgopi 
324ed8845d8Skrgopi typedef int	(*maddr_reserve_t)(void *, mac_multi_addr_t *);
325ed8845d8Skrgopi typedef int	(*maddr_add_t)(void *, mac_multi_addr_t *);
326ed8845d8Skrgopi typedef int	(*maddr_remove_t)(void *, mac_addr_slot_t);
327ed8845d8Skrgopi typedef int	(*maddr_modify_t)(void *, mac_multi_addr_t *);
328ed8845d8Skrgopi typedef int	(*maddr_get_t)(void *, mac_multi_addr_t *);
329ed8845d8Skrgopi 
330ed8845d8Skrgopi /* maddr_flag values */
331ed8845d8Skrgopi #define	MADDR_VENDOR_ADDR	0x01	/* addr returned is vendor supplied */
332ed8845d8Skrgopi 
333ed8845d8Skrgopi /* multiple mac address: add/remove/set/get mac address */
334ed8845d8Skrgopi typedef struct multiaddress_capab_s {
335ed8845d8Skrgopi 	int		maddr_naddr;	/* total addresses */
336ed8845d8Skrgopi 	int		maddr_naddrfree;	/* free address slots */
337ed8845d8Skrgopi 	uint_t		maddr_flag;	/* MADDR_VENDOR_ADDR bit can be set */
338ed8845d8Skrgopi 	/* driver entry points */
339ed8845d8Skrgopi 	void		*maddr_handle;	/* cookie to be used for the calls */
340ed8845d8Skrgopi 	maddr_reserve_t	maddr_reserve;	/* reserve a factory address */
341ed8845d8Skrgopi 	maddr_add_t	maddr_add;	/* add a new unicst address */
342ed8845d8Skrgopi 	maddr_remove_t	maddr_remove;	/* remove an added address */
343ed8845d8Skrgopi 	maddr_modify_t	maddr_modify;	/* modify an added address */
344ed8845d8Skrgopi 	maddr_get_t	maddr_get;	/* get address from specified slot */
345ed8845d8Skrgopi } multiaddress_capab_t;
346ed8845d8Skrgopi 
3477c478bd9Sstevel@tonic-gate /*
3487c478bd9Sstevel@tonic-gate  * MAC driver entry point types.
3497c478bd9Sstevel@tonic-gate  */
350ba2e4443Sseb typedef int		(*mac_getstat_t)(void *, uint_t, uint64_t *);
3517c478bd9Sstevel@tonic-gate typedef	int		(*mac_start_t)(void *);
3527c478bd9Sstevel@tonic-gate typedef void		(*mac_stop_t)(void *);
353ba2e4443Sseb typedef int		(*mac_setpromisc_t)(void *, boolean_t);
3547c478bd9Sstevel@tonic-gate typedef int		(*mac_multicst_t)(void *, boolean_t, const uint8_t *);
3557c478bd9Sstevel@tonic-gate typedef int		(*mac_unicst_t)(void *, const uint8_t *);
3567c478bd9Sstevel@tonic-gate typedef void		(*mac_ioctl_t)(void *, queue_t *, mblk_t *);
357ba2e4443Sseb typedef void		(*mac_resources_t)(void *);
3587c478bd9Sstevel@tonic-gate typedef mblk_t		*(*mac_tx_t)(void *, mblk_t *);
359ba2e4443Sseb typedef	boolean_t	(*mac_getcapab_t)(void *, mac_capab_t, void *);
360d62bc4baSyz147064 typedef	int		(*mac_open_t)(void *);
361d62bc4baSyz147064 typedef void		(*mac_close_t)(void *);
362e7801d59Ssowmini typedef	int		(*mac_set_prop_t)(void *, const char *, mac_prop_id_t,
363e7801d59Ssowmini     uint_t, const void *);
364e7801d59Ssowmini typedef	int		(*mac_get_prop_t)(void *, const char *, mac_prop_id_t,
3654045d941Ssowmini     uint_t, uint_t, void *);
3667c478bd9Sstevel@tonic-gate 
3677c478bd9Sstevel@tonic-gate /*
368ba2e4443Sseb  * Drivers must set all of these callbacks except for mc_resources,
369ba2e4443Sseb  * mc_ioctl, and mc_getcapab, which are optional.  If any of these optional
370ba2e4443Sseb  * callbacks are set, their appropriate flags must be set in mc_callbacks.
371ba2e4443Sseb  * Any future additions to this list must also be accompanied by an
372ba2e4443Sseb  * associated mc_callbacks flag so that the framework can grow without
373ba2e4443Sseb  * affecting the binary compatibility of the interface.
3747c478bd9Sstevel@tonic-gate  */
375ba2e4443Sseb typedef struct mac_callbacks_s {
376ba2e4443Sseb 	uint_t		mc_callbacks;	/* Denotes which callbacks are set */
377ba2e4443Sseb 	mac_getstat_t	mc_getstat;	/* Get the value of a statistic */
378ba2e4443Sseb 	mac_start_t	mc_start;	/* Start the device */
379ba2e4443Sseb 	mac_stop_t	mc_stop;	/* Stop the device */
380ba2e4443Sseb 	mac_setpromisc_t mc_setpromisc;	/* Enable or disable promiscuous mode */
381ba2e4443Sseb 	mac_multicst_t	mc_multicst;	/* Enable or disable a multicast addr */
382ba2e4443Sseb 	mac_unicst_t	mc_unicst;	/* Set the unicast MAC address */
383ba2e4443Sseb 	mac_tx_t	mc_tx;		/* Transmit a packet */
384ba2e4443Sseb 	mac_resources_t	mc_resources;	/* Get the device resources */
385ba2e4443Sseb 	mac_ioctl_t	mc_ioctl;	/* Process an unknown ioctl */
386ba2e4443Sseb 	mac_getcapab_t	mc_getcapab;	/* Get capability information */
387d62bc4baSyz147064 	mac_open_t	mc_open;	/* Open the device */
388d62bc4baSyz147064 	mac_close_t	mc_close;	/* Close the device */
389e7801d59Ssowmini 	mac_set_prop_t	mc_setprop;
390e7801d59Ssowmini 	mac_get_prop_t	mc_getprop;
391ba2e4443Sseb } mac_callbacks_t;
3927c478bd9Sstevel@tonic-gate 
3934045d941Ssowmini typedef struct mac_priv_prop_s {
3944045d941Ssowmini 	char	mpp_name[MAXLINKPROPNAME];
3954045d941Ssowmini 	uint_t	mpp_flags;
3964045d941Ssowmini } mac_priv_prop_t;
3974045d941Ssowmini 
3987c478bd9Sstevel@tonic-gate /*
399678453a8Sspeer  * Multiple Rings capability
400678453a8Sspeer  */
401678453a8Sspeer typedef enum {
402678453a8Sspeer 	MAC_RING_TYPE_RX	= 1,	/* Receive ring */
403678453a8Sspeer 	MAC_RING_TYPE_TX	= 2	/* Transmit ring */
404678453a8Sspeer } mac_ring_type_t;
405678453a8Sspeer 
406678453a8Sspeer /*
407678453a8Sspeer  * Grouping type of a ring group
408678453a8Sspeer  *
409678453a8Sspeer  * MAC_GROUP_TYPE_STATIC: The ring group can not be re-grouped.
410678453a8Sspeer  * MAC_GROUP_TYPE_DYNAMIC: The ring group support dynamic re-grouping
411678453a8Sspeer  */
412678453a8Sspeer typedef enum {
413678453a8Sspeer 	MAC_GROUP_TYPE_STATIC	= 1,	/* Static ring group */
414678453a8Sspeer 	MAC_GROUP_TYPE_DYNAMIC	= 2	/* Dynamic ring group */
415678453a8Sspeer } mac_group_type_t;
416678453a8Sspeer 
417678453a8Sspeer typedef	struct __mac_ring_driver	*mac_ring_driver_t;
418678453a8Sspeer typedef	struct __mac_ring_handle	*mac_ring_handle_t;
419678453a8Sspeer typedef	struct __mac_group_driver	*mac_group_driver_t;
420678453a8Sspeer typedef	struct __mac_group_handle	*mac_group_handle_t;
421678453a8Sspeer typedef	struct __mac_intr_handle	*mac_intr_handle_t;
422678453a8Sspeer 
423678453a8Sspeer typedef	struct mac_ring_info_s mac_ring_info_t;
424678453a8Sspeer typedef	struct mac_group_info_s mac_group_info_t;
425678453a8Sspeer 
426678453a8Sspeer typedef	int	(*mac_intr_enable_t)(mac_intr_handle_t);
427678453a8Sspeer typedef	int	(*mac_intr_disable_t)(mac_intr_handle_t);
428678453a8Sspeer 
429678453a8Sspeer typedef	struct mac_intr_s {
430678453a8Sspeer 	mac_intr_handle_t	mi_handle;
431678453a8Sspeer 	mac_intr_enable_t	mi_enable;
432678453a8Sspeer 	mac_intr_disable_t	mi_disable;
433678453a8Sspeer } mac_intr_t;
434678453a8Sspeer 
435678453a8Sspeer typedef void	(*mac_get_ring_t)(void *, mac_ring_type_t, const int, const int,
436678453a8Sspeer     mac_ring_info_t *, mac_ring_handle_t);
437678453a8Sspeer typedef void	(*mac_get_group_t)(void *, mac_ring_type_t, const int,
438678453a8Sspeer     mac_group_info_t *, mac_group_handle_t);
439678453a8Sspeer 
440678453a8Sspeer typedef void	(*mac_group_add_ring_t)(mac_group_driver_t,
441678453a8Sspeer     mac_ring_driver_t, mac_ring_type_t);
442678453a8Sspeer typedef void	(*mac_group_rem_ring_t)(mac_group_driver_t,
443678453a8Sspeer     mac_ring_driver_t, mac_ring_type_t);
444678453a8Sspeer 
445678453a8Sspeer /*
446678453a8Sspeer  * Multiple Rings Capability
447678453a8Sspeer  */
448678453a8Sspeer typedef struct	mac_capab_rings_s {
449678453a8Sspeer 	mac_ring_type_t		mr_type;	/* Ring type */
450678453a8Sspeer 	mac_group_type_t	mr_group_type;	/* Grouping type */
451678453a8Sspeer 	void			*mr_handle;	/* Group Driver Handle. */
452678453a8Sspeer 	uint_t			mr_rnum;	/* Number of rings */
453678453a8Sspeer 	uint_t			mr_gnum;	/* Number of ring groups */
454678453a8Sspeer 	mac_get_ring_t		mr_rget;	/* Get ring from driver */
455678453a8Sspeer 	mac_get_group_t		mr_gget;	/* Get ring group from driver */
456678453a8Sspeer 	mac_group_add_ring_t	mr_gadd_ring;	/* Add ring into a group */
457678453a8Sspeer 	mac_group_rem_ring_t	mr_grem_ring;	/* Remove ring from a group */
458678453a8Sspeer } mac_capab_rings_t;
459678453a8Sspeer 
460678453a8Sspeer /*
461678453a8Sspeer  * Common ring functions and driver interfaces
462678453a8Sspeer  */
463678453a8Sspeer typedef	int	(*mac_ring_start_t)(mac_ring_driver_t);
464678453a8Sspeer typedef	void	(*mac_ring_stop_t)(mac_ring_driver_t);
465678453a8Sspeer 
466678453a8Sspeer typedef	mblk_t	*(*mac_ring_send_t)(void *, mblk_t *);
467678453a8Sspeer typedef	mblk_t *(*mac_ring_poll_t)(void *, int);
468678453a8Sspeer 
469678453a8Sspeer typedef struct mac_ring_info_s {
470678453a8Sspeer 	mac_ring_driver_t	mr_driver;
471678453a8Sspeer 	mac_ring_start_t	mr_start;
472678453a8Sspeer 	mac_ring_stop_t		mr_stop;
473678453a8Sspeer 	mac_intr_t		mr_intr;
474678453a8Sspeer 	union {
475678453a8Sspeer 		mac_ring_send_t	send;
476678453a8Sspeer 		mac_ring_poll_t	poll;
477678453a8Sspeer 	} mrfunion;
478678453a8Sspeer } mac_ring_info_s;
479678453a8Sspeer 
480678453a8Sspeer #define	mr_send		mrfunion.send
481678453a8Sspeer #define	mr_poll		mrfunion.poll
482678453a8Sspeer 
483678453a8Sspeer typedef	int	(*mac_group_start_t)(mac_group_driver_t);
484678453a8Sspeer typedef	void	(*mac_group_stop_t)(mac_group_driver_t);
485678453a8Sspeer typedef	int	(*mac_add_mac_addr_t)(void *, const uint8_t *);
486678453a8Sspeer typedef	int	(*mac_rem_mac_addr_t)(void *, const uint8_t *);
487678453a8Sspeer 
488678453a8Sspeer struct mac_group_info_s {
489678453a8Sspeer 	mac_group_driver_t	mrg_driver;	/* Driver reference */
490678453a8Sspeer 	mac_group_start_t	mrg_start;	/* Start the group */
491678453a8Sspeer 	mac_group_stop_t	mrg_stop;	/* Stop the group */
492678453a8Sspeer 	uint_t			mrg_count;	/* Count of rings */
493678453a8Sspeer 	mac_intr_t		mrg_intr;	/* Optional per-group intr */
494678453a8Sspeer 
495678453a8Sspeer 	/* Only used for rx groups */
496678453a8Sspeer 	mac_add_mac_addr_t	mrg_addmac;	/* Add a MAC address */
497678453a8Sspeer 	mac_rem_mac_addr_t	mrg_remmac;	/* Remove a MAC address */
498678453a8Sspeer };
499678453a8Sspeer 
500678453a8Sspeer /*
501678453a8Sspeer  * Share management functions.
502678453a8Sspeer  */
503678453a8Sspeer typedef uint64_t mac_share_handle_t;
504678453a8Sspeer 
505678453a8Sspeer /*
506678453a8Sspeer  * Returns a Share handle to the client calling from above.
507678453a8Sspeer  */
508678453a8Sspeer typedef int    (*mac_alloc_share_t)(void *, uint64_t cookie,
509678453a8Sspeer     uint64_t *rcookie, mac_share_handle_t *);
510678453a8Sspeer 
511678453a8Sspeer /*
512678453a8Sspeer  * Destroys the share previously allocated and unallocates
513678453a8Sspeer  * all share resources (e.g. DMA's assigned to the share).
514678453a8Sspeer  */
515678453a8Sspeer typedef void (*mac_free_share_t)(mac_share_handle_t);
516678453a8Sspeer 
517678453a8Sspeer typedef void (*mac_share_query_t)(mac_share_handle_t shdl,
518678453a8Sspeer     mac_ring_type_t type, uint32_t *rmin, uint32_t *rmax,
519678453a8Sspeer     uint64_t *rmap, uint64_t *gnum);
520678453a8Sspeer 
521678453a8Sspeer /*
522678453a8Sspeer  * Basic idea, bind previously created ring groups to shares
523678453a8Sspeer  * for them to be exported (or shared) by another domain.
524678453a8Sspeer  * These interfaces bind/unbind the ring group to a share.  The
525678453a8Sspeer  * of doing such causes the resources to be shared with the guest.
526678453a8Sspeer  */
527678453a8Sspeer typedef int (*mac_share_add_group_t)(mac_share_handle_t,
528678453a8Sspeer     mac_group_handle_t);
529678453a8Sspeer typedef int (*mac_share_rem_group_t)(mac_share_handle_t,
530678453a8Sspeer     mac_group_handle_t);
531678453a8Sspeer 
532678453a8Sspeer typedef struct  mac_capab_share_s {
533678453a8Sspeer 	uint_t			ms_snum;	/* Number of shares (vr's) */
534678453a8Sspeer 	void			*ms_handle;	/* Handle to driver. */
535678453a8Sspeer 	mac_alloc_share_t	ms_salloc;	/* Get a share from driver. */
536678453a8Sspeer 	mac_free_share_t	ms_sfree;	/* Return a share to driver. */
537678453a8Sspeer 	mac_share_add_group_t	ms_sadd;	/* Add a group to the share. */
538678453a8Sspeer 	mac_share_rem_group_t	ms_sremove;	/* Remove group from share. */
539678453a8Sspeer 	mac_share_query_t	ms_squery;	/* Query share constraints */
540678453a8Sspeer } mac_capab_share_t;
541678453a8Sspeer 
542678453a8Sspeer /*
543ba2e4443Sseb  * Flags for mc_callbacks.  Requiring drivers to set the flags associated
544ba2e4443Sseb  * with optional callbacks initialized in the structure allows the mac
545ba2e4443Sseb  * module to add optional callbacks in the future without requiring drivers
546ba2e4443Sseb  * to recompile.
5477c478bd9Sstevel@tonic-gate  */
548ba2e4443Sseb #define	MC_RESOURCES	0x001
549ba2e4443Sseb #define	MC_IOCTL	0x002
550ba2e4443Sseb #define	MC_GETCAPAB	0x004
551d62bc4baSyz147064 #define	MC_OPEN		0x008
552d62bc4baSyz147064 #define	MC_CLOSE	0x010
553e7801d59Ssowmini #define	MC_SETPROP	0x020
554e7801d59Ssowmini #define	MC_GETPROP	0x040
555d62bc4baSyz147064 
556d62bc4baSyz147064 #define	MAC_MAX_MINOR	1000
5577c478bd9Sstevel@tonic-gate 
558ba2e4443Sseb typedef struct mac_register_s {
559ba2e4443Sseb 	uint_t			m_version;	/* set by mac_alloc() */
560ba2e4443Sseb 	const char		*m_type_ident;
5617c478bd9Sstevel@tonic-gate 	void			*m_driver;	/* Driver private data */
5627c478bd9Sstevel@tonic-gate 	dev_info_t		*m_dip;
563ba2e4443Sseb 	uint_t			m_instance;
564ba2e4443Sseb 	uint8_t			*m_src_addr;
565ba2e4443Sseb 	uint8_t			*m_dst_addr;
566ba2e4443Sseb 	mac_callbacks_t		*m_callbacks;
567ba2e4443Sseb 	uint_t			m_min_sdu;
568ba2e4443Sseb 	uint_t			m_max_sdu;
569ba2e4443Sseb 	void			*m_pdata;
570ba2e4443Sseb 	size_t			m_pdata_size;
571d62bc4baSyz147064 	uint32_t		m_margin;
5724045d941Ssowmini 	mac_priv_prop_t		*m_priv_props;
5734045d941Ssowmini 	size_t			m_priv_prop_count;
574ba2e4443Sseb } mac_register_t;
5757c478bd9Sstevel@tonic-gate 
5764045d941Ssowmini 
5777c478bd9Sstevel@tonic-gate /*
5787c478bd9Sstevel@tonic-gate  * Opaque handle types.
5797c478bd9Sstevel@tonic-gate  */
580ba2e4443Sseb typedef	struct mac_t			*mac_handle_t;
5817c478bd9Sstevel@tonic-gate typedef struct __mac_notify_handle	*mac_notify_handle_t;
5827c478bd9Sstevel@tonic-gate typedef struct __mac_rx_handle		*mac_rx_handle_t;
5837c478bd9Sstevel@tonic-gate typedef struct __mac_txloop_handle	*mac_txloop_handle_t;
5847c478bd9Sstevel@tonic-gate typedef struct __mac_resource_handle	*mac_resource_handle_t;
5857c478bd9Sstevel@tonic-gate 
5867c478bd9Sstevel@tonic-gate /*
5877c478bd9Sstevel@tonic-gate  * MAC interface callback types.
5887c478bd9Sstevel@tonic-gate  */
5897c478bd9Sstevel@tonic-gate typedef enum {
5907c478bd9Sstevel@tonic-gate 	MAC_NOTE_LINK,
5917c478bd9Sstevel@tonic-gate 	MAC_NOTE_PROMISC,
5927c478bd9Sstevel@tonic-gate 	MAC_NOTE_UNICST,
5937c478bd9Sstevel@tonic-gate 	MAC_NOTE_TX,
5947c478bd9Sstevel@tonic-gate 	MAC_NOTE_RESOURCE,
5957c478bd9Sstevel@tonic-gate 	MAC_NOTE_DEVPROMISC,
596ba2e4443Sseb 	MAC_NOTE_FASTPATH_FLUSH,
597e7801d59Ssowmini 	MAC_NOTE_SDU_SIZE,
598843e1988Sjohnlev 	MAC_NOTE_VNIC,
599d62bc4baSyz147064 	MAC_NOTE_MARGIN,
6007c478bd9Sstevel@tonic-gate 	MAC_NNOTE	/* must be the last entry */
6017c478bd9Sstevel@tonic-gate } mac_notify_type_t;
6027c478bd9Sstevel@tonic-gate 
6037c478bd9Sstevel@tonic-gate typedef void		(*mac_notify_t)(void *, mac_notify_type_t);
6047c478bd9Sstevel@tonic-gate typedef void		(*mac_rx_t)(void *, mac_resource_handle_t, mblk_t *);
6057c478bd9Sstevel@tonic-gate typedef void		(*mac_txloop_t)(void *, mblk_t *);
6067c478bd9Sstevel@tonic-gate typedef void		(*mac_blank_t)(void *, time_t, uint_t);
6077c478bd9Sstevel@tonic-gate 
6087c478bd9Sstevel@tonic-gate /*
6097c478bd9Sstevel@tonic-gate  * MAC promiscuous types
6107c478bd9Sstevel@tonic-gate  */
6117c478bd9Sstevel@tonic-gate typedef enum {
6127c478bd9Sstevel@tonic-gate 	MAC_PROMISC = 0x01,		/* MAC instance is promiscuous */
6137c478bd9Sstevel@tonic-gate 	MAC_DEVPROMISC = 0x02		/* Device is promiscuous */
6147c478bd9Sstevel@tonic-gate } mac_promisc_type_t;
6157c478bd9Sstevel@tonic-gate 
6167c478bd9Sstevel@tonic-gate /*
6177c478bd9Sstevel@tonic-gate  * MAC resource types
6187c478bd9Sstevel@tonic-gate  */
6197c478bd9Sstevel@tonic-gate typedef enum {
6207c478bd9Sstevel@tonic-gate 	MAC_RX_FIFO = 1
6217c478bd9Sstevel@tonic-gate } mac_resource_type_t;
6227c478bd9Sstevel@tonic-gate 
6237c478bd9Sstevel@tonic-gate typedef struct mac_rx_fifo_s {
6247c478bd9Sstevel@tonic-gate 	mac_resource_type_t	mrf_type;	/* MAC_RX_FIFO */
6257c478bd9Sstevel@tonic-gate 	mac_blank_t		mrf_blank;
6267c478bd9Sstevel@tonic-gate 	void			*mrf_arg;
6277c478bd9Sstevel@tonic-gate 	time_t			mrf_normal_blank_time;
6287c478bd9Sstevel@tonic-gate 	uint_t			mrf_normal_pkt_count;
6297c478bd9Sstevel@tonic-gate } mac_rx_fifo_t;
6307c478bd9Sstevel@tonic-gate 
63198b1442aSmeem typedef struct mac_txinfo_s {
63298b1442aSmeem 	mac_tx_t		mt_fn;
63398b1442aSmeem 	void			*mt_arg;
63498b1442aSmeem } mac_txinfo_t;
63598b1442aSmeem 
6367c478bd9Sstevel@tonic-gate typedef union mac_resource_u {
6377c478bd9Sstevel@tonic-gate 	mac_resource_type_t	mr_type;
6387c478bd9Sstevel@tonic-gate 	mac_rx_fifo_t		mr_fifo;
6397c478bd9Sstevel@tonic-gate } mac_resource_t;
6407c478bd9Sstevel@tonic-gate 
6417c478bd9Sstevel@tonic-gate typedef mac_resource_handle_t	(*mac_resource_add_t)(void *, mac_resource_t *);
6427c478bd9Sstevel@tonic-gate 
643ba2e4443Sseb typedef enum {
644ba2e4443Sseb 	MAC_ADDRTYPE_UNICAST,
645ba2e4443Sseb 	MAC_ADDRTYPE_MULTICAST,
646ba2e4443Sseb 	MAC_ADDRTYPE_BROADCAST
647ba2e4443Sseb } mac_addrtype_t;
648ba2e4443Sseb 
649ba2e4443Sseb typedef struct mac_header_info_s {
650ba2e4443Sseb 	size_t		mhi_hdrsize;
651ba2e4443Sseb 	size_t		mhi_pktsize;
652ba2e4443Sseb 	const uint8_t	*mhi_daddr;
653ba2e4443Sseb 	const uint8_t	*mhi_saddr;
654ba2e4443Sseb 	uint32_t	mhi_origsap;
655ba2e4443Sseb 	uint32_t	mhi_bindsap;
656ba2e4443Sseb 	mac_addrtype_t	mhi_dsttype;
657605445d5Sdg199075 	uint16_t	mhi_tci;
658d62bc4baSyz147064 	uint_t		mhi_istagged:1,
659d62bc4baSyz147064 			mhi_prom_looped:1;
660ba2e4443Sseb } mac_header_info_t;
661ba2e4443Sseb 
662ba2e4443Sseb /*
663ba2e4443Sseb  * MAC-Type plugin interfaces
664ba2e4443Sseb  */
665ba2e4443Sseb 
666ba2e4443Sseb typedef int		(*mtops_addr_verify_t)(const void *, void *);
667ba2e4443Sseb typedef boolean_t	(*mtops_sap_verify_t)(uint32_t, uint32_t *, void *);
668ba2e4443Sseb typedef mblk_t		*(*mtops_header_t)(const void *, const void *,
669ba2e4443Sseb     uint32_t, void *, mblk_t *, size_t);
670ba2e4443Sseb typedef int		(*mtops_header_info_t)(mblk_t *, void *,
671ba2e4443Sseb     mac_header_info_t *);
672ba2e4443Sseb typedef boolean_t	(*mtops_pdata_verify_t)(void *, size_t);
673ba2e4443Sseb typedef	mblk_t		*(*mtops_header_modify_t)(mblk_t *, void *);
6740d2a8e5eSgd78059 typedef void		(*mtops_link_details_t)(char *, size_t, mac_handle_t,
6750d2a8e5eSgd78059     void *);
676ba2e4443Sseb 
677ba2e4443Sseb typedef struct mactype_ops_s {
678ba2e4443Sseb 	uint_t			mtops_ops;
679ba2e4443Sseb 	/*
680ba2e4443Sseb 	 * mtops_unicst_verify() returns 0 if the given address is a valid
681ba2e4443Sseb 	 * unicast address, or a non-zero errno otherwise.
682ba2e4443Sseb 	 */
683ba2e4443Sseb 	mtops_addr_verify_t	mtops_unicst_verify;
684ba2e4443Sseb 	/*
685ba2e4443Sseb 	 * mtops_multicst_verify() returns 0 if the given address is a
686ba2e4443Sseb 	 * valid multicast address, or a non-zero errno otherwise.  If the
687ba2e4443Sseb 	 * media doesn't support multicast, ENOTSUP should be returned (for
688ba2e4443Sseb 	 * example).
689ba2e4443Sseb 	 */
690ba2e4443Sseb 	mtops_addr_verify_t	mtops_multicst_verify;
691ba2e4443Sseb 	/*
692ba2e4443Sseb 	 * mtops_sap_verify() returns B_TRUE if the given SAP is a valid
693ba2e4443Sseb 	 * SAP value, or B_FALSE otherwise.
694ba2e4443Sseb 	 */
695ba2e4443Sseb 	mtops_sap_verify_t	mtops_sap_verify;
696ba2e4443Sseb 	/*
697ba2e4443Sseb 	 * mtops_header() is used to allocate and construct a MAC header.
698ba2e4443Sseb 	 */
699ba2e4443Sseb 	mtops_header_t		mtops_header;
700ba2e4443Sseb 	/*
701ba2e4443Sseb 	 * mtops_header_info() is used to gather information on a given MAC
702ba2e4443Sseb 	 * header.
703ba2e4443Sseb 	 */
704ba2e4443Sseb 	mtops_header_info_t	mtops_header_info;
705ba2e4443Sseb 	/*
706ba2e4443Sseb 	 * mtops_pdata_verify() is used to verify the validity of MAC
707ba2e4443Sseb 	 * plugin data.  It is called by mac_register() if the driver has
708ba2e4443Sseb 	 * supplied MAC plugin data, and also by mac_pdata_update() when
709ba2e4443Sseb 	 * drivers update the data.
710ba2e4443Sseb 	 */
711ba2e4443Sseb 	mtops_pdata_verify_t	mtops_pdata_verify;
712ba2e4443Sseb 	/*
713ba2e4443Sseb 	 * mtops_header_cook() is an optional callback that converts (or
714ba2e4443Sseb 	 * "cooks") the given raw header (as sent by a raw DLPI consumer)
715ba2e4443Sseb 	 * into one that is appropriate to send down to the MAC driver.
716ba2e4443Sseb 	 * Following the example above, an Ethernet header sent down by a
717ba2e4443Sseb 	 * DLPI consumer would be converted to whatever header the MAC
718ba2e4443Sseb 	 * driver expects.
719ba2e4443Sseb 	 */
720ba2e4443Sseb 	mtops_header_modify_t	mtops_header_cook;
721ba2e4443Sseb 	/*
722ba2e4443Sseb 	 * mtops_header_uncook() is an optional callback that does the
723ba2e4443Sseb 	 * opposite of mtops_header_cook().  It "uncooks" a given MAC
724ba2e4443Sseb 	 * header (as received from the driver) for consumption by raw DLPI
725ba2e4443Sseb 	 * consumers.  For example, for a non-Ethernet plugin that wants
726ba2e4443Sseb 	 * raw DLPI consumers to be fooled into thinking that the device
727ba2e4443Sseb 	 * provides Ethernet access, this callback would modify the given
728ba2e4443Sseb 	 * mblk_t such that the MAC header is converted to an Ethernet
729ba2e4443Sseb 	 * header.
730ba2e4443Sseb 	 */
731ba2e4443Sseb 	mtops_header_modify_t	mtops_header_uncook;
7320d2a8e5eSgd78059 	/*
7330d2a8e5eSgd78059 	 * mtops_link_details() is an optional callback that provides
7340d2a8e5eSgd78059 	 * extended information about the link state.  Its primary purpose
7350d2a8e5eSgd78059 	 * is to provide type-specific support for syslog contents on
7360d2a8e5eSgd78059 	 * link up events.  If no implementation is provided, then a default
7370d2a8e5eSgd78059 	 * implementation will be used.
7380d2a8e5eSgd78059 	 */
7390d2a8e5eSgd78059 	mtops_link_details_t	mtops_link_details;
740ba2e4443Sseb } mactype_ops_t;
741ba2e4443Sseb 
742ba2e4443Sseb /*
743ba2e4443Sseb  * mtops_ops exists for the plugin to enumerate the optional callback
744ba2e4443Sseb  * entrypoints it has defined.  This allows the mac module to define
745ba2e4443Sseb  * additional plugin entrypoints in mactype_ops_t without breaking backward
746ba2e4443Sseb  * compatibility with old plugins.
747ba2e4443Sseb  */
748ba2e4443Sseb #define	MTOPS_PDATA_VERIFY	0x001
749ba2e4443Sseb #define	MTOPS_HEADER_COOK	0x002
750ba2e4443Sseb #define	MTOPS_HEADER_UNCOOK	0x004
7510d2a8e5eSgd78059 #define	MTOPS_LINK_DETAILS	0x008
752ba2e4443Sseb 
7534045d941Ssowmini /*
7544045d941Ssowmini  * Provide mapping for legacy ndd ioctls relevant to that mactype.
7554045d941Ssowmini  * Note that the ndd ioctls are obsolete, and may be removed in a future
7564045d941Ssowmini  * release of Solaris. The ndd ioctls are not typically used in legacy
7574045d941Ssowmini  * ethernet drivers. New datalink drivers of all link-types should use
7584045d941Ssowmini  * dladm(1m) interfaces for administering tunables and not have to provide
7594045d941Ssowmini  * a mapping.
7604045d941Ssowmini  */
7614045d941Ssowmini typedef struct mac_ndd_mapping_s {
7624045d941Ssowmini 	char		*mp_name;
7634045d941Ssowmini 	union {
7644045d941Ssowmini 		mac_prop_id_t   u_id;
7654045d941Ssowmini 		uint_t		u_kstat;
7664045d941Ssowmini 	} u_mp_id;
7674045d941Ssowmini 	long		mp_minval;
7684045d941Ssowmini 	long		mp_maxval;
7694045d941Ssowmini 	size_t		mp_valsize;
7704045d941Ssowmini 	int		mp_flags;
7714045d941Ssowmini } mac_ndd_mapping_t;
7724045d941Ssowmini 
7734045d941Ssowmini #define	mp_prop_id	u_mp_id.u_id
7744045d941Ssowmini #define	mp_kstat	u_mp_id.u_kstat
7754045d941Ssowmini 
7764045d941Ssowmini /*
7774045d941Ssowmini  * Flags to figure out r/w status of legacy ndd props.
7784045d941Ssowmini  */
7794045d941Ssowmini #define	MAC_PROP_PERM_READ		0x0001
7804045d941Ssowmini #define	MAC_PROP_PERM_WRITE		0x0010
7814045d941Ssowmini #define	MAC_PROP_MAP_KSTAT		0x0100
7824045d941Ssowmini #define	MAC_PROP_PERM_RW		(MAC_PROP_PERM_READ|MAC_PROP_PERM_WRITE)
7834045d941Ssowmini #define	MAC_PROP_FLAGS_RK		(MAC_PROP_PERM_READ|MAC_PROP_MAP_KSTAT)
7844045d941Ssowmini 
785ba2e4443Sseb typedef struct mactype_register_s {
786ba2e4443Sseb 	uint_t		mtr_version;	/* set by mactype_alloc() */
787ba2e4443Sseb 	const char	*mtr_ident;
788ba2e4443Sseb 	mactype_ops_t	*mtr_ops;
789ba2e4443Sseb 	uint_t		mtr_mactype;
7900ba2cbe9Sxc151355 	uint_t		mtr_nativetype;
791ba2e4443Sseb 	uint_t		mtr_addrlen;
792ba2e4443Sseb 	uint8_t		*mtr_brdcst_addr;
793ba2e4443Sseb 	mac_stat_info_t	*mtr_stats;
794ba2e4443Sseb 	size_t		mtr_statcount;
7954045d941Ssowmini 	mac_ndd_mapping_t *mtr_mapping;
7964045d941Ssowmini 	size_t		mtr_mappingcount;
797ba2e4443Sseb } mactype_register_t;
798ba2e4443Sseb 
799e7801d59Ssowmini typedef struct mac_prop_s {
800e7801d59Ssowmini 	mac_prop_id_t	mp_id;
801e7801d59Ssowmini 	char		*mp_name;
8024045d941Ssowmini 	uint_t		mp_flags;
803e7801d59Ssowmini } mac_prop_t;
804e7801d59Ssowmini 
8057c478bd9Sstevel@tonic-gate /*
8067c478bd9Sstevel@tonic-gate  * Client interface functions.
8077c478bd9Sstevel@tonic-gate  */
808a08fa175Syz147064 extern int			mac_open(const char *, mac_handle_t *);
809d62bc4baSyz147064 extern int			mac_open_by_linkid(datalink_id_t,
810d62bc4baSyz147064 				    mac_handle_t *);
811d62bc4baSyz147064 extern int			mac_open_by_linkname(const char *,
812d62bc4baSyz147064 				    mac_handle_t *);
8137c478bd9Sstevel@tonic-gate extern void			mac_close(mac_handle_t);
8147c478bd9Sstevel@tonic-gate extern const mac_info_t		*mac_info(mac_handle_t);
815210db224Sericheng extern boolean_t		mac_info_get(const char *, mac_info_t *);
816ba2e4443Sseb extern uint64_t			mac_stat_get(mac_handle_t, uint_t);
8177c478bd9Sstevel@tonic-gate extern int			mac_start(mac_handle_t);
8187c478bd9Sstevel@tonic-gate extern void			mac_stop(mac_handle_t);
8197c478bd9Sstevel@tonic-gate extern int			mac_promisc_set(mac_handle_t, boolean_t,
8207c478bd9Sstevel@tonic-gate 				    mac_promisc_type_t);
8217c478bd9Sstevel@tonic-gate extern boolean_t		mac_promisc_get(mac_handle_t,
8227c478bd9Sstevel@tonic-gate 				    mac_promisc_type_t);
8237c478bd9Sstevel@tonic-gate extern int 			mac_multicst_add(mac_handle_t, const uint8_t *);
8247c478bd9Sstevel@tonic-gate extern int 			mac_multicst_remove(mac_handle_t,
8257c478bd9Sstevel@tonic-gate 				    const uint8_t *);
826ed8845d8Skrgopi extern boolean_t		mac_unicst_verify(mac_handle_t,
827ed8845d8Skrgopi 				    const uint8_t *, uint_t);
8287c478bd9Sstevel@tonic-gate extern int			mac_unicst_set(mac_handle_t, const uint8_t *);
8297c478bd9Sstevel@tonic-gate extern void			mac_unicst_get(mac_handle_t, uint8_t *);
830ba2e4443Sseb extern void			mac_dest_get(mac_handle_t, uint8_t *);
831e7801d59Ssowmini extern void			mac_sdu_get(mac_handle_t, uint_t *, uint_t *);
8327c478bd9Sstevel@tonic-gate extern void			mac_resources(mac_handle_t);
8337c478bd9Sstevel@tonic-gate extern void			mac_ioctl(mac_handle_t, queue_t *, mblk_t *);
83498b1442aSmeem extern const mac_txinfo_t	*mac_tx_get(mac_handle_t);
835843e1988Sjohnlev extern const mac_txinfo_t	*mac_vnic_tx_get(mac_handle_t);
8367c478bd9Sstevel@tonic-gate extern link_state_t		mac_link_get(mac_handle_t);
8377c478bd9Sstevel@tonic-gate extern mac_notify_handle_t	mac_notify_add(mac_handle_t, mac_notify_t,
8387c478bd9Sstevel@tonic-gate 				    void *);
8397c478bd9Sstevel@tonic-gate extern void			mac_notify_remove(mac_handle_t,
8407c478bd9Sstevel@tonic-gate 				    mac_notify_handle_t);
8417c478bd9Sstevel@tonic-gate extern void			mac_notify(mac_handle_t);
8427c478bd9Sstevel@tonic-gate extern mac_rx_handle_t		mac_rx_add(mac_handle_t, mac_rx_t, void *);
843843e1988Sjohnlev extern mac_rx_handle_t		mac_active_rx_add(mac_handle_t, mac_rx_t,
844843e1988Sjohnlev 				    void *);
8451f8aaf0dSethindra extern void			mac_rx_remove(mac_handle_t, mac_rx_handle_t,
8461f8aaf0dSethindra 				    boolean_t);
8471f8aaf0dSethindra extern void			mac_rx_remove_wait(mac_handle_t);
8487c478bd9Sstevel@tonic-gate extern mblk_t			*mac_txloop(void *, mblk_t *);
8497c478bd9Sstevel@tonic-gate extern mac_txloop_handle_t	mac_txloop_add(mac_handle_t, mac_txloop_t,
8507c478bd9Sstevel@tonic-gate 				    void *);
8517c478bd9Sstevel@tonic-gate extern void			mac_txloop_remove(mac_handle_t,
8527c478bd9Sstevel@tonic-gate 				    mac_txloop_handle_t);
8537c478bd9Sstevel@tonic-gate extern boolean_t		mac_active_set(mac_handle_t);
854843e1988Sjohnlev extern boolean_t		mac_active_shareable_set(mac_handle_t);
8557c478bd9Sstevel@tonic-gate extern void			mac_active_clear(mac_handle_t);
856843e1988Sjohnlev extern void			mac_active_rx(void *, mac_resource_handle_t,
857843e1988Sjohnlev 				    mblk_t *);
858843e1988Sjohnlev extern boolean_t		mac_vnic_set(mac_handle_t, mac_txinfo_t *,
859843e1988Sjohnlev 				    mac_getcapab_t, void *);
860843e1988Sjohnlev extern void			mac_vnic_clear(mac_handle_t);
8617c478bd9Sstevel@tonic-gate extern void			mac_resource_set(mac_handle_t,
8627c478bd9Sstevel@tonic-gate 				    mac_resource_add_t, void *);
863210db224Sericheng extern dev_info_t		*mac_devinfo_get(mac_handle_t);
864d62bc4baSyz147064 extern const char		*mac_name(mac_handle_t);
865d62bc4baSyz147064 extern minor_t			mac_minor(mac_handle_t);
866ba2e4443Sseb extern boolean_t		mac_capab_get(mac_handle_t, mac_capab_t,
867ba2e4443Sseb 				    void *);
868843e1988Sjohnlev extern boolean_t		mac_vnic_capab_get(mac_handle_t, mac_capab_t,
869843e1988Sjohnlev 				    void *);
870ba2e4443Sseb extern boolean_t		mac_sap_verify(mac_handle_t, uint32_t,
871ba2e4443Sseb 				    uint32_t *);
872ba2e4443Sseb extern mblk_t			*mac_header(mac_handle_t, const uint8_t *,
873ba2e4443Sseb 				    uint32_t, mblk_t *, size_t);
874ba2e4443Sseb extern int			mac_header_info(mac_handle_t, mblk_t *,
875ba2e4443Sseb 				    mac_header_info_t *);
876ba2e4443Sseb extern mblk_t			*mac_header_cook(mac_handle_t, mblk_t *);
877ba2e4443Sseb extern mblk_t			*mac_header_uncook(mac_handle_t, mblk_t *);
878d62bc4baSyz147064 extern minor_t			mac_minor_hold(boolean_t);
879d62bc4baSyz147064 extern void			mac_minor_rele(minor_t);
8807c478bd9Sstevel@tonic-gate 
8817c478bd9Sstevel@tonic-gate /*
8827c478bd9Sstevel@tonic-gate  * Driver interface functions.
8837c478bd9Sstevel@tonic-gate  */
884ba2e4443Sseb extern mac_register_t		*mac_alloc(uint_t);
885ba2e4443Sseb extern void			mac_free(mac_register_t *);
886ba2e4443Sseb extern int			mac_register(mac_register_t *, mac_handle_t *);
887843e1988Sjohnlev extern int			mac_disable(mac_handle_t);
888ba2e4443Sseb extern int  			mac_unregister(mac_handle_t);
889ba2e4443Sseb extern void 			mac_rx(mac_handle_t, mac_resource_handle_t,
8907c478bd9Sstevel@tonic-gate 				    mblk_t *);
891ba2e4443Sseb extern void 			mac_link_update(mac_handle_t, link_state_t);
892ba2e4443Sseb extern void 			mac_unicst_update(mac_handle_t,
893ba2e4443Sseb 				    const uint8_t *);
894ba2e4443Sseb extern void			mac_tx_update(mac_handle_t);
895ba2e4443Sseb extern void			mac_resource_update(mac_handle_t);
896ba2e4443Sseb extern mac_resource_handle_t	mac_resource_add(mac_handle_t,
897ba2e4443Sseb 				    mac_resource_t *);
898e7801d59Ssowmini extern int			mac_maxsdu_update(mac_handle_t, uint_t);
899ba2e4443Sseb extern int			mac_pdata_update(mac_handle_t, void *,
900ba2e4443Sseb 				    size_t);
901ba2e4443Sseb extern void			mac_multicst_refresh(mac_handle_t,
902ba2e4443Sseb 				    mac_multicst_t, void *, boolean_t);
903ba2e4443Sseb extern void			mac_unicst_refresh(mac_handle_t, mac_unicst_t,
9047c478bd9Sstevel@tonic-gate 				    void *);
905ba2e4443Sseb extern void			mac_promisc_refresh(mac_handle_t,
906ba2e4443Sseb 				    mac_setpromisc_t, void *);
907d62bc4baSyz147064 extern boolean_t		mac_margin_update(mac_handle_t, uint32_t);
908d62bc4baSyz147064 extern void			mac_margin_get(mac_handle_t, uint32_t *);
909d62bc4baSyz147064 extern int			mac_margin_remove(mac_handle_t, uint32_t);
910d62bc4baSyz147064 extern int			mac_margin_add(mac_handle_t, uint32_t *,
911d62bc4baSyz147064 				    boolean_t);
912210db224Sericheng extern void			mac_init_ops(struct dev_ops *, const char *);
913210db224Sericheng extern void			mac_fini_ops(struct dev_ops *);
914d62bc4baSyz147064 extern uint32_t			mac_no_notification(mac_handle_t);
915d62bc4baSyz147064 extern boolean_t		mac_is_legacy(mac_handle_t);
916d62bc4baSyz147064 extern int			mac_hold_exclusive(mac_handle_t);
917d62bc4baSyz147064 extern void			mac_rele_exclusive(mac_handle_t);
918d62bc4baSyz147064 
919ba2e4443Sseb extern mactype_register_t	*mactype_alloc(uint_t);
920ba2e4443Sseb extern void			mactype_free(mactype_register_t *);
921ba2e4443Sseb extern int			mactype_register(mactype_register_t *);
922ba2e4443Sseb extern int			mactype_unregister(const char *);
923e7801d59Ssowmini extern int			mac_set_prop(mac_handle_t, mac_prop_t *,
924e7801d59Ssowmini 				    void *, uint_t);
925e7801d59Ssowmini extern int			mac_get_prop(mac_handle_t, mac_prop_t *,
926e7801d59Ssowmini 				    void *, uint_t);
9277c478bd9Sstevel@tonic-gate 
9287c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
9297c478bd9Sstevel@tonic-gate 
9307c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
9317c478bd9Sstevel@tonic-gate }
9327c478bd9Sstevel@tonic-gate #endif
9337c478bd9Sstevel@tonic-gate 
9347c478bd9Sstevel@tonic-gate #endif /* _SYS_MAC_H */
935