xref: /titanic_51/usr/src/uts/common/sys/mac.h (revision 308903890e892f9c21ee582e3a52fdd67e52870b)
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 
297c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate 
31605445d5Sdg199075 #include <sys/types.h>
327c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
337c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
347c478bd9Sstevel@tonic-gate #include <sys/stream.h>
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate /*
377c478bd9Sstevel@tonic-gate  * MAC Services Module
387c478bd9Sstevel@tonic-gate  */
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
417c478bd9Sstevel@tonic-gate extern "C" {
427c478bd9Sstevel@tonic-gate #endif
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate /*
457c478bd9Sstevel@tonic-gate  * MAC Information (text emitted by modinfo(1m))
467c478bd9Sstevel@tonic-gate  */
474045d941Ssowmini #define	MAC_INFO	"MAC Services"
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate /*
50ba2e4443Sseb  * MAC version identifier.  This is used by mac_alloc() mac_register() to
51ba2e4443Sseb  * verify that incompatible drivers don't register.
52ba2e4443Sseb  */
53ba2e4443Sseb #define	MAC_VERSION	0x1
54ba2e4443Sseb 
55ba2e4443Sseb /*
56ba2e4443Sseb  * MAC-Type version identifier.  This is used by mactype_alloc() and
57ba2e4443Sseb  * mactype_register() to verify that incompatible MAC-Type plugins don't
58ba2e4443Sseb  * register.
59ba2e4443Sseb  */
60ba2e4443Sseb #define	MACTYPE_VERSION	0x1
61ba2e4443Sseb 
62ba2e4443Sseb /*
637c478bd9Sstevel@tonic-gate  * Statistics
647c478bd9Sstevel@tonic-gate  */
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate #define	XCVR_UNDEFINED		0
677c478bd9Sstevel@tonic-gate #define	XCVR_NONE		1
687c478bd9Sstevel@tonic-gate #define	XCVR_10			2
697c478bd9Sstevel@tonic-gate #define	XCVR_100T4		3
707c478bd9Sstevel@tonic-gate #define	XCVR_100X		4
717c478bd9Sstevel@tonic-gate #define	XCVR_100T2		5
727c478bd9Sstevel@tonic-gate #define	XCVR_1000X		6
737c478bd9Sstevel@tonic-gate #define	XCVR_1000T		7
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate typedef enum {
767c478bd9Sstevel@tonic-gate 	LINK_STATE_UNKNOWN = -1,
777c478bd9Sstevel@tonic-gate 	LINK_STATE_DOWN,
787c478bd9Sstevel@tonic-gate 	LINK_STATE_UP
797c478bd9Sstevel@tonic-gate } link_state_t;
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate typedef enum {
827c478bd9Sstevel@tonic-gate 	LINK_DUPLEX_UNKNOWN = 0,
837c478bd9Sstevel@tonic-gate 	LINK_DUPLEX_HALF,
847c478bd9Sstevel@tonic-gate 	LINK_DUPLEX_FULL
857c478bd9Sstevel@tonic-gate } link_duplex_t;
867c478bd9Sstevel@tonic-gate 
87d62bc4baSyz147064 #define	DATALINK_INVALID_LINKID	0
88d62bc4baSyz147064 #define	DATALINK_ALL_LINKID	0
89d62bc4baSyz147064 #define	DATALINK_MAX_LINKID	0xffffffff
90d62bc4baSyz147064 
91e7801d59Ssowmini typedef enum {
92e7801d59Ssowmini 	LINK_FLOWCTRL_NONE = 0,
93e7801d59Ssowmini 	LINK_FLOWCTRL_RX,
94e7801d59Ssowmini 	LINK_FLOWCTRL_TX,
95e7801d59Ssowmini 	LINK_FLOWCTRL_BI
96e7801d59Ssowmini } link_flowctrl_t;
97e7801d59Ssowmini 
983fd94f8cSam223141 typedef uint32_t datalink_id_t;
993fd94f8cSam223141 
1003fd94f8cSam223141 /*
1013fd94f8cSam223141  * Encodings for public properties.
1023fd94f8cSam223141  * A most significant bit value of 1 indicates private property, intended
1033fd94f8cSam223141  * to allow private property implementations to use internal encodings
1043fd94f8cSam223141  * if desired.
1053fd94f8cSam223141  *
1063fd94f8cSam223141  * Note that there are 2 sets of parameters: the *_EN_*
1073fd94f8cSam223141  * values are those that the Administrator configures for autonegotiation.
1083fd94f8cSam223141  * The _ADV_* values are those that are currently exposed over the wire.
1093fd94f8cSam223141  */
1103fd94f8cSam223141 #define	MAXLINKPROPNAME		256
1113fd94f8cSam223141 #define	MAC_PROP_DEFAULT	0x0001
1123fd94f8cSam223141 typedef enum {
1133fd94f8cSam223141 	MAC_PROP_DUPLEX = 0x00000001,
1143fd94f8cSam223141 	MAC_PROP_SPEED,
1153fd94f8cSam223141 	MAC_PROP_STATUS,
1163fd94f8cSam223141 	MAC_PROP_AUTONEG,
1173fd94f8cSam223141 	MAC_PROP_EN_AUTONEG,
1183fd94f8cSam223141 	MAC_PROP_MTU,
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,
1343fd94f8cSam223141 	MAC_PROP_PRIVATE = -1
1353fd94f8cSam223141 } mac_prop_id_t;
1363fd94f8cSam223141 
137843e1988Sjohnlev /*
138843e1988Sjohnlev  * Maximum MAC address length
139843e1988Sjohnlev  */
140843e1988Sjohnlev #define	MAXMACADDRLEN	20
141843e1988Sjohnlev 
1427c478bd9Sstevel@tonic-gate #ifdef	_KERNEL
1437c478bd9Sstevel@tonic-gate 
144ba2e4443Sseb typedef struct mac_stat_info_s {
145ba2e4443Sseb 	uint_t		msi_stat;
146ba2e4443Sseb 	char		*msi_name;
147ba2e4443Sseb 	uint_t		msi_type;	/* as defined in kstat_named_init(9F) */
148ba2e4443Sseb 	uint64_t	msi_default;
149ba2e4443Sseb } mac_stat_info_t;
150ba2e4443Sseb 
1517c478bd9Sstevel@tonic-gate /*
152ba2e4443Sseb  * There are three ranges of statistics values.  0 to 1 - MAC_STAT_MIN are
153ba2e4443Sseb  * interface statistics maintained by the mac module.  MAC_STAT_MIN to 1 -
154ba2e4443Sseb  * MACTYPE_STAT_MIN are common MAC statistics defined by the mac module and
155ba2e4443Sseb  * maintained by each driver.  MACTYPE_STAT_MIN and above are statistics
156ba2e4443Sseb  * defined by MAC-Type plugins and maintained by each driver.
1577c478bd9Sstevel@tonic-gate  */
158ba2e4443Sseb #define	MAC_STAT_MIN		1000
159ba2e4443Sseb #define	MACTYPE_STAT_MIN	2000
160ba2e4443Sseb 
161ba2e4443Sseb #define	IS_MAC_STAT(stat)	\
162ba2e4443Sseb 	(stat >= MAC_STAT_MIN && stat < MACTYPE_STAT_MIN)
163ba2e4443Sseb #define	IS_MACTYPE_STAT(stat)	(stat >= MACTYPE_STAT_MIN)
164ba2e4443Sseb 
1659b14cf1dSgd78059 /*
166d62bc4baSyz147064  * Statistics maintained by the mac module, and possibly populated as link
167d62bc4baSyz147064  * statistics.
168d62bc4baSyz147064  */
169d62bc4baSyz147064 enum mac_mod_stat {
170d62bc4baSyz147064 	MAC_STAT_LINK_STATE,
171d62bc4baSyz147064 	MAC_STAT_LINK_UP,
172d62bc4baSyz147064 	MAC_STAT_PROMISC
173d62bc4baSyz147064 };
174d62bc4baSyz147064 
175d62bc4baSyz147064 /*
1769b14cf1dSgd78059  * Do not reorder, and add only to the end of this list.
1779b14cf1dSgd78059  */
178ba2e4443Sseb enum mac_driver_stat {
179ba2e4443Sseb 	/* MIB-II stats (RFC 1213 and RFC 1573) */
180ba2e4443Sseb 	MAC_STAT_IFSPEED = MAC_STAT_MIN,
1817c478bd9Sstevel@tonic-gate 	MAC_STAT_MULTIRCV,
1827c478bd9Sstevel@tonic-gate 	MAC_STAT_BRDCSTRCV,
1837c478bd9Sstevel@tonic-gate 	MAC_STAT_MULTIXMT,
1847c478bd9Sstevel@tonic-gate 	MAC_STAT_BRDCSTXMT,
1857c478bd9Sstevel@tonic-gate 	MAC_STAT_NORCVBUF,
1867c478bd9Sstevel@tonic-gate 	MAC_STAT_IERRORS,
1877c478bd9Sstevel@tonic-gate 	MAC_STAT_UNKNOWNS,
1887c478bd9Sstevel@tonic-gate 	MAC_STAT_NOXMTBUF,
1897c478bd9Sstevel@tonic-gate 	MAC_STAT_OERRORS,
1907c478bd9Sstevel@tonic-gate 	MAC_STAT_COLLISIONS,
1917c478bd9Sstevel@tonic-gate 	MAC_STAT_RBYTES,
1927c478bd9Sstevel@tonic-gate 	MAC_STAT_IPACKETS,
1937c478bd9Sstevel@tonic-gate 	MAC_STAT_OBYTES,
1949b14cf1dSgd78059 	MAC_STAT_OPACKETS,
1959b14cf1dSgd78059 	MAC_STAT_UNDERFLOWS,
1969b14cf1dSgd78059 	MAC_STAT_OVERFLOWS
1977c478bd9Sstevel@tonic-gate };
1987c478bd9Sstevel@tonic-gate 
1999b14cf1dSgd78059 #define	MAC_NSTAT	(MAC_STAT_OVERFLOWS - MAC_STAT_IFSPEED + 1)
200ba2e4443Sseb 
201ba2e4443Sseb #define	MAC_STAT_ISACOUNTER(_stat) (		\
202ba2e4443Sseb 	    (_stat) == MAC_STAT_MULTIRCV ||	\
203ba2e4443Sseb 	    (_stat) == MAC_STAT_BRDCSTRCV ||	\
204ba2e4443Sseb 	    (_stat) == MAC_STAT_MULTIXMT ||	\
205ba2e4443Sseb 	    (_stat) == MAC_STAT_BRDCSTXMT ||	\
206ba2e4443Sseb 	    (_stat) == MAC_STAT_NORCVBUF ||	\
207ba2e4443Sseb 	    (_stat) == MAC_STAT_IERRORS ||	\
208ba2e4443Sseb 	    (_stat) == MAC_STAT_UNKNOWNS ||	\
209ba2e4443Sseb 	    (_stat) == MAC_STAT_NOXMTBUF ||	\
210ba2e4443Sseb 	    (_stat) == MAC_STAT_OERRORS ||	\
211ba2e4443Sseb 	    (_stat) == MAC_STAT_COLLISIONS ||	\
212ba2e4443Sseb 	    (_stat) == MAC_STAT_RBYTES ||	\
213ba2e4443Sseb 	    (_stat) == MAC_STAT_IPACKETS ||	\
214ba2e4443Sseb 	    (_stat) == MAC_STAT_OBYTES ||	\
2159b14cf1dSgd78059 	    (_stat) == MAC_STAT_OPACKETS ||	\
2169b14cf1dSgd78059 	    (_stat) == MAC_STAT_UNDERFLOWS ||	\
2179b14cf1dSgd78059 	    (_stat) == MAC_STAT_OVERFLOWS)
218ba2e4443Sseb 
2197c478bd9Sstevel@tonic-gate /*
2207c478bd9Sstevel@tonic-gate  * Immutable information. (This may not be modified after registration).
2217c478bd9Sstevel@tonic-gate  */
2227c478bd9Sstevel@tonic-gate typedef struct mac_info_s {
2237c478bd9Sstevel@tonic-gate 	uint_t		mi_media;
2240ba2cbe9Sxc151355 	uint_t		mi_nativemedia;
2257c478bd9Sstevel@tonic-gate 	uint_t		mi_addr_length;
226ba2e4443Sseb 	uint8_t		*mi_unicst_addr;
227ba2e4443Sseb 	uint8_t		*mi_brdcst_addr;
2287c478bd9Sstevel@tonic-gate } mac_info_t;
2297c478bd9Sstevel@tonic-gate 
2307c478bd9Sstevel@tonic-gate /*
2318347601bSyl150051  * LSO capability
2328347601bSyl150051  */
2338347601bSyl150051 typedef struct lso_basic_tcp_ipv4_s {
2348347601bSyl150051 	t_uscalar_t	lso_max;		/* maximum payload */
2358347601bSyl150051 } lso_basic_tcp_ipv4_t;
2368347601bSyl150051 
2378347601bSyl150051 /*
2388347601bSyl150051  * Future LSO capabilities can be added at the end of the mac_capab_lso_t.
2398347601bSyl150051  * When such capability is added to the GLDv3 framework, the size of the
2408347601bSyl150051  * mac_capab_lso_t it allocates and passes to the drivers increases. Older
2418347601bSyl150051  * drivers wil access only the (upper) sections of that structure, that is the
2428347601bSyl150051  * sections carrying the capabilities they understand. This ensures the
2438347601bSyl150051  * interface can be safely extended in a binary compatible way.
2448347601bSyl150051  */
2458347601bSyl150051 typedef	struct mac_capab_lso_s {
2468347601bSyl150051 	t_uscalar_t		lso_flags;
2478347601bSyl150051 	lso_basic_tcp_ipv4_t	lso_basic_tcp_ipv4;
2488347601bSyl150051 	/* Add future lso capabilities here */
2498347601bSyl150051 } mac_capab_lso_t;
2508347601bSyl150051 
2518347601bSyl150051 /*
252d62bc4baSyz147064  * Information for legacy devices.
253d62bc4baSyz147064  */
254d62bc4baSyz147064 typedef struct mac_capab_legacy_s {
255d62bc4baSyz147064 	/*
256d62bc4baSyz147064 	 * Notifications that the legacy device does not support.
257d62bc4baSyz147064 	 */
258d62bc4baSyz147064 	uint32_t	ml_unsup_note;
259d62bc4baSyz147064 	/*
260d62bc4baSyz147064 	 * dev_t of the legacy device; can be held to force attach.
261d62bc4baSyz147064 	 */
262d62bc4baSyz147064 	dev_t		ml_dev;
263d62bc4baSyz147064 } mac_capab_legacy_t;
264d62bc4baSyz147064 
265d62bc4baSyz147064 /*
266ba2e4443Sseb  * MAC layer capabilities.  These capabilities are handled by the drivers'
267ba2e4443Sseb  * mc_capab_get() callbacks.  Some capabilities require the driver to fill
268ba2e4443Sseb  * in a given data structure, and others are simply boolean capabilities.
269ba2e4443Sseb  * Note that capability values must be powers of 2 so that consumers and
270ba2e4443Sseb  * providers of this interface can keep track of which capabilities they
271ba2e4443Sseb  * care about by keeping a bitfield of these things around somewhere.
2727c478bd9Sstevel@tonic-gate  */
273ba2e4443Sseb typedef enum {
274ba2e4443Sseb 	MAC_CAPAB_HCKSUM	= 0x01, /* data is a uint32_t for the txflags */
275ed8845d8Skrgopi 	MAC_CAPAB_POLL		= 0x02,	/* boolean only, no data */
2768347601bSyl150051 	MAC_CAPAB_MULTIADDRESS	= 0x04, /* data is multiaddress_capab_t */
277d62bc4baSyz147064 	MAC_CAPAB_LSO		= 0x08, /* data is mac_capab_lso_t */
278d62bc4baSyz147064 	MAC_CAPAB_NO_NATIVEVLAN	= 0x10, /* boolean only, no data */
279d62bc4baSyz147064 	MAC_CAPAB_NO_ZCOPY	= 0x20, /* boolean only, no data */
280ba2e4443Sseb 	/* add new capabilities here */
281678453a8Sspeer 	MAC_CAPAB_RINGS		= 0x100, /* data is mac_capab_rings_t */
282678453a8Sspeer 	MAC_CAPAB_SHARES	= 0x200, /* data is mac_capab_share_t */
283d62bc4baSyz147064 
284d62bc4baSyz147064 	/* The following capabilities are specific to softmac. */
285*30890389Sartem 	MAC_CAPAB_LEGACY	= 0x8000 /* data is mac_capab_legacy_t */
286ba2e4443Sseb } mac_capab_t;
2877c478bd9Sstevel@tonic-gate 
288ed8845d8Skrgopi typedef int mac_addr_slot_t;
289ed8845d8Skrgopi 
290ed8845d8Skrgopi /* mma_flags values */
291ed8845d8Skrgopi #define	MMAC_SLOT_USED		0x1   /* address slot used */
292ed8845d8Skrgopi #define	MMAC_SLOT_UNUSED	0x2   /* free address slot */
293ed8845d8Skrgopi #define	MMAC_VENDOR_ADDR	0x4   /* address returned is vendor supplied */
294ed8845d8Skrgopi 
295ed8845d8Skrgopi typedef struct mac_multi_address_s {
296ed8845d8Skrgopi 	mac_addr_slot_t	mma_slot;	/* slot for add/remove/get/set */
297ed8845d8Skrgopi 	uint_t		mma_addrlen;
298ed8845d8Skrgopi 	uint8_t		mma_addr[MAXMACADDRLEN];
299ed8845d8Skrgopi 	uint_t		mma_flags;
300ed8845d8Skrgopi } mac_multi_addr_t;
301ed8845d8Skrgopi 
302ed8845d8Skrgopi typedef int	(*maddr_reserve_t)(void *, mac_multi_addr_t *);
303ed8845d8Skrgopi typedef int	(*maddr_add_t)(void *, mac_multi_addr_t *);
304ed8845d8Skrgopi typedef int	(*maddr_remove_t)(void *, mac_addr_slot_t);
305ed8845d8Skrgopi typedef int	(*maddr_modify_t)(void *, mac_multi_addr_t *);
306ed8845d8Skrgopi typedef int	(*maddr_get_t)(void *, mac_multi_addr_t *);
307ed8845d8Skrgopi 
308ed8845d8Skrgopi /* maddr_flag values */
309ed8845d8Skrgopi #define	MADDR_VENDOR_ADDR	0x01	/* addr returned is vendor supplied */
310ed8845d8Skrgopi 
311ed8845d8Skrgopi /* multiple mac address: add/remove/set/get mac address */
312ed8845d8Skrgopi typedef struct multiaddress_capab_s {
313ed8845d8Skrgopi 	int		maddr_naddr;	/* total addresses */
314ed8845d8Skrgopi 	int		maddr_naddrfree;	/* free address slots */
315ed8845d8Skrgopi 	uint_t		maddr_flag;	/* MADDR_VENDOR_ADDR bit can be set */
316ed8845d8Skrgopi 	/* driver entry points */
317ed8845d8Skrgopi 	void		*maddr_handle;	/* cookie to be used for the calls */
318ed8845d8Skrgopi 	maddr_reserve_t	maddr_reserve;	/* reserve a factory address */
319ed8845d8Skrgopi 	maddr_add_t	maddr_add;	/* add a new unicst address */
320ed8845d8Skrgopi 	maddr_remove_t	maddr_remove;	/* remove an added address */
321ed8845d8Skrgopi 	maddr_modify_t	maddr_modify;	/* modify an added address */
322ed8845d8Skrgopi 	maddr_get_t	maddr_get;	/* get address from specified slot */
323ed8845d8Skrgopi } multiaddress_capab_t;
324ed8845d8Skrgopi 
3257c478bd9Sstevel@tonic-gate /*
3267c478bd9Sstevel@tonic-gate  * MAC driver entry point types.
3277c478bd9Sstevel@tonic-gate  */
328ba2e4443Sseb typedef int		(*mac_getstat_t)(void *, uint_t, uint64_t *);
3297c478bd9Sstevel@tonic-gate typedef	int		(*mac_start_t)(void *);
3307c478bd9Sstevel@tonic-gate typedef void		(*mac_stop_t)(void *);
331ba2e4443Sseb typedef int		(*mac_setpromisc_t)(void *, boolean_t);
3327c478bd9Sstevel@tonic-gate typedef int		(*mac_multicst_t)(void *, boolean_t, const uint8_t *);
3337c478bd9Sstevel@tonic-gate typedef int		(*mac_unicst_t)(void *, const uint8_t *);
3347c478bd9Sstevel@tonic-gate typedef void		(*mac_ioctl_t)(void *, queue_t *, mblk_t *);
335ba2e4443Sseb typedef void		(*mac_resources_t)(void *);
3367c478bd9Sstevel@tonic-gate typedef mblk_t		*(*mac_tx_t)(void *, mblk_t *);
337ba2e4443Sseb typedef	boolean_t	(*mac_getcapab_t)(void *, mac_capab_t, void *);
338d62bc4baSyz147064 typedef	int		(*mac_open_t)(void *);
339d62bc4baSyz147064 typedef void		(*mac_close_t)(void *);
340e7801d59Ssowmini typedef	int		(*mac_set_prop_t)(void *, const char *, mac_prop_id_t,
341e7801d59Ssowmini     uint_t, const void *);
342e7801d59Ssowmini typedef	int		(*mac_get_prop_t)(void *, const char *, mac_prop_id_t,
3434045d941Ssowmini     uint_t, uint_t, void *);
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate /*
346ba2e4443Sseb  * Drivers must set all of these callbacks except for mc_resources,
347ba2e4443Sseb  * mc_ioctl, and mc_getcapab, which are optional.  If any of these optional
348ba2e4443Sseb  * callbacks are set, their appropriate flags must be set in mc_callbacks.
349ba2e4443Sseb  * Any future additions to this list must also be accompanied by an
350ba2e4443Sseb  * associated mc_callbacks flag so that the framework can grow without
351ba2e4443Sseb  * affecting the binary compatibility of the interface.
3527c478bd9Sstevel@tonic-gate  */
353ba2e4443Sseb typedef struct mac_callbacks_s {
354ba2e4443Sseb 	uint_t		mc_callbacks;	/* Denotes which callbacks are set */
355ba2e4443Sseb 	mac_getstat_t	mc_getstat;	/* Get the value of a statistic */
356ba2e4443Sseb 	mac_start_t	mc_start;	/* Start the device */
357ba2e4443Sseb 	mac_stop_t	mc_stop;	/* Stop the device */
358ba2e4443Sseb 	mac_setpromisc_t mc_setpromisc;	/* Enable or disable promiscuous mode */
359ba2e4443Sseb 	mac_multicst_t	mc_multicst;	/* Enable or disable a multicast addr */
360ba2e4443Sseb 	mac_unicst_t	mc_unicst;	/* Set the unicast MAC address */
361ba2e4443Sseb 	mac_tx_t	mc_tx;		/* Transmit a packet */
362ba2e4443Sseb 	mac_resources_t	mc_resources;	/* Get the device resources */
363ba2e4443Sseb 	mac_ioctl_t	mc_ioctl;	/* Process an unknown ioctl */
364ba2e4443Sseb 	mac_getcapab_t	mc_getcapab;	/* Get capability information */
365d62bc4baSyz147064 	mac_open_t	mc_open;	/* Open the device */
366d62bc4baSyz147064 	mac_close_t	mc_close;	/* Close the device */
367e7801d59Ssowmini 	mac_set_prop_t	mc_setprop;
368e7801d59Ssowmini 	mac_get_prop_t	mc_getprop;
369ba2e4443Sseb } mac_callbacks_t;
3707c478bd9Sstevel@tonic-gate 
3714045d941Ssowmini typedef struct mac_priv_prop_s {
3724045d941Ssowmini 	char	mpp_name[MAXLINKPROPNAME];
3734045d941Ssowmini 	uint_t	mpp_flags;
3744045d941Ssowmini } mac_priv_prop_t;
3754045d941Ssowmini 
3767c478bd9Sstevel@tonic-gate /*
377678453a8Sspeer  * Multiple Rings capability
378678453a8Sspeer  */
379678453a8Sspeer typedef enum {
380678453a8Sspeer 	MAC_RING_TYPE_RX	= 1,	/* Receive ring */
381678453a8Sspeer 	MAC_RING_TYPE_TX	= 2	/* Transmit ring */
382678453a8Sspeer } mac_ring_type_t;
383678453a8Sspeer 
384678453a8Sspeer /*
385678453a8Sspeer  * Grouping type of a ring group
386678453a8Sspeer  *
387678453a8Sspeer  * MAC_GROUP_TYPE_STATIC: The ring group can not be re-grouped.
388678453a8Sspeer  * MAC_GROUP_TYPE_DYNAMIC: The ring group support dynamic re-grouping
389678453a8Sspeer  */
390678453a8Sspeer typedef enum {
391678453a8Sspeer 	MAC_GROUP_TYPE_STATIC	= 1,	/* Static ring group */
392678453a8Sspeer 	MAC_GROUP_TYPE_DYNAMIC	= 2	/* Dynamic ring group */
393678453a8Sspeer } mac_group_type_t;
394678453a8Sspeer 
395678453a8Sspeer typedef	struct __mac_ring_driver	*mac_ring_driver_t;
396678453a8Sspeer typedef	struct __mac_ring_handle	*mac_ring_handle_t;
397678453a8Sspeer typedef	struct __mac_group_driver	*mac_group_driver_t;
398678453a8Sspeer typedef	struct __mac_group_handle	*mac_group_handle_t;
399678453a8Sspeer typedef	struct __mac_intr_handle	*mac_intr_handle_t;
400678453a8Sspeer 
401678453a8Sspeer typedef	struct mac_ring_info_s mac_ring_info_t;
402678453a8Sspeer typedef	struct mac_group_info_s mac_group_info_t;
403678453a8Sspeer 
404678453a8Sspeer typedef	int	(*mac_intr_enable_t)(mac_intr_handle_t);
405678453a8Sspeer typedef	int	(*mac_intr_disable_t)(mac_intr_handle_t);
406678453a8Sspeer 
407678453a8Sspeer typedef	struct mac_intr_s {
408678453a8Sspeer 	mac_intr_handle_t	mi_handle;
409678453a8Sspeer 	mac_intr_enable_t	mi_enable;
410678453a8Sspeer 	mac_intr_disable_t	mi_disable;
411678453a8Sspeer } mac_intr_t;
412678453a8Sspeer 
413678453a8Sspeer typedef void	(*mac_get_ring_t)(void *, mac_ring_type_t, const int, const int,
414678453a8Sspeer     mac_ring_info_t *, mac_ring_handle_t);
415678453a8Sspeer typedef void	(*mac_get_group_t)(void *, mac_ring_type_t, const int,
416678453a8Sspeer     mac_group_info_t *, mac_group_handle_t);
417678453a8Sspeer 
418678453a8Sspeer typedef void	(*mac_group_add_ring_t)(mac_group_driver_t,
419678453a8Sspeer     mac_ring_driver_t, mac_ring_type_t);
420678453a8Sspeer typedef void	(*mac_group_rem_ring_t)(mac_group_driver_t,
421678453a8Sspeer     mac_ring_driver_t, mac_ring_type_t);
422678453a8Sspeer 
423678453a8Sspeer /*
424678453a8Sspeer  * Multiple Rings Capability
425678453a8Sspeer  */
426678453a8Sspeer typedef struct	mac_capab_rings_s {
427678453a8Sspeer 	mac_ring_type_t		mr_type;	/* Ring type */
428678453a8Sspeer 	mac_group_type_t	mr_group_type;	/* Grouping type */
429678453a8Sspeer 	void			*mr_handle;	/* Group Driver Handle. */
430678453a8Sspeer 	uint_t			mr_rnum;	/* Number of rings */
431678453a8Sspeer 	uint_t			mr_gnum;	/* Number of ring groups */
432678453a8Sspeer 	mac_get_ring_t		mr_rget;	/* Get ring from driver */
433678453a8Sspeer 	mac_get_group_t		mr_gget;	/* Get ring group from driver */
434678453a8Sspeer 	mac_group_add_ring_t	mr_gadd_ring;	/* Add ring into a group */
435678453a8Sspeer 	mac_group_rem_ring_t	mr_grem_ring;	/* Remove ring from a group */
436678453a8Sspeer } mac_capab_rings_t;
437678453a8Sspeer 
438678453a8Sspeer /*
439678453a8Sspeer  * Common ring functions and driver interfaces
440678453a8Sspeer  */
441678453a8Sspeer typedef	int	(*mac_ring_start_t)(mac_ring_driver_t);
442678453a8Sspeer typedef	void	(*mac_ring_stop_t)(mac_ring_driver_t);
443678453a8Sspeer 
444678453a8Sspeer typedef	mblk_t	*(*mac_ring_send_t)(void *, mblk_t *);
445678453a8Sspeer typedef	mblk_t *(*mac_ring_poll_t)(void *, int);
446678453a8Sspeer 
447678453a8Sspeer typedef struct mac_ring_info_s {
448678453a8Sspeer 	mac_ring_driver_t	mr_driver;
449678453a8Sspeer 	mac_ring_start_t	mr_start;
450678453a8Sspeer 	mac_ring_stop_t		mr_stop;
451678453a8Sspeer 	mac_intr_t		mr_intr;
452678453a8Sspeer 	union {
453678453a8Sspeer 		mac_ring_send_t	send;
454678453a8Sspeer 		mac_ring_poll_t	poll;
455678453a8Sspeer 	} mrfunion;
456678453a8Sspeer } mac_ring_info_s;
457678453a8Sspeer 
458678453a8Sspeer #define	mr_send		mrfunion.send
459678453a8Sspeer #define	mr_poll		mrfunion.poll
460678453a8Sspeer 
461678453a8Sspeer typedef	int	(*mac_group_start_t)(mac_group_driver_t);
462678453a8Sspeer typedef	void	(*mac_group_stop_t)(mac_group_driver_t);
463678453a8Sspeer typedef	int	(*mac_add_mac_addr_t)(void *, const uint8_t *);
464678453a8Sspeer typedef	int	(*mac_rem_mac_addr_t)(void *, const uint8_t *);
465678453a8Sspeer 
466678453a8Sspeer struct mac_group_info_s {
467678453a8Sspeer 	mac_group_driver_t	mrg_driver;	/* Driver reference */
468678453a8Sspeer 	mac_group_start_t	mrg_start;	/* Start the group */
469678453a8Sspeer 	mac_group_stop_t	mrg_stop;	/* Stop the group */
470678453a8Sspeer 	uint_t			mrg_count;	/* Count of rings */
471678453a8Sspeer 	mac_intr_t		mrg_intr;	/* Optional per-group intr */
472678453a8Sspeer 
473678453a8Sspeer 	/* Only used for rx groups */
474678453a8Sspeer 	mac_add_mac_addr_t	mrg_addmac;	/* Add a MAC address */
475678453a8Sspeer 	mac_rem_mac_addr_t	mrg_remmac;	/* Remove a MAC address */
476678453a8Sspeer };
477678453a8Sspeer 
478678453a8Sspeer /*
479678453a8Sspeer  * Share management functions.
480678453a8Sspeer  */
481678453a8Sspeer typedef uint64_t mac_share_handle_t;
482678453a8Sspeer 
483678453a8Sspeer /*
484678453a8Sspeer  * Returns a Share handle to the client calling from above.
485678453a8Sspeer  */
486678453a8Sspeer typedef int    (*mac_alloc_share_t)(void *, uint64_t cookie,
487678453a8Sspeer     uint64_t *rcookie, mac_share_handle_t *);
488678453a8Sspeer 
489678453a8Sspeer /*
490678453a8Sspeer  * Destroys the share previously allocated and unallocates
491678453a8Sspeer  * all share resources (e.g. DMA's assigned to the share).
492678453a8Sspeer  */
493678453a8Sspeer typedef void (*mac_free_share_t)(mac_share_handle_t);
494678453a8Sspeer 
495678453a8Sspeer typedef void (*mac_share_query_t)(mac_share_handle_t shdl,
496678453a8Sspeer     mac_ring_type_t type, uint32_t *rmin, uint32_t *rmax,
497678453a8Sspeer     uint64_t *rmap, uint64_t *gnum);
498678453a8Sspeer 
499678453a8Sspeer /*
500678453a8Sspeer  * Basic idea, bind previously created ring groups to shares
501678453a8Sspeer  * for them to be exported (or shared) by another domain.
502678453a8Sspeer  * These interfaces bind/unbind the ring group to a share.  The
503678453a8Sspeer  * of doing such causes the resources to be shared with the guest.
504678453a8Sspeer  */
505678453a8Sspeer typedef int (*mac_share_add_group_t)(mac_share_handle_t,
506678453a8Sspeer     mac_group_handle_t);
507678453a8Sspeer typedef int (*mac_share_rem_group_t)(mac_share_handle_t,
508678453a8Sspeer     mac_group_handle_t);
509678453a8Sspeer 
510678453a8Sspeer typedef struct  mac_capab_share_s {
511678453a8Sspeer 	uint_t			ms_snum;	/* Number of shares (vr's) */
512678453a8Sspeer 	void			*ms_handle;	/* Handle to driver. */
513678453a8Sspeer 	mac_alloc_share_t	ms_salloc;	/* Get a share from driver. */
514678453a8Sspeer 	mac_free_share_t	ms_sfree;	/* Return a share to driver. */
515678453a8Sspeer 	mac_share_add_group_t	ms_sadd;	/* Add a group to the share. */
516678453a8Sspeer 	mac_share_rem_group_t	ms_sremove;	/* Remove group from share. */
517678453a8Sspeer 	mac_share_query_t	ms_squery;	/* Query share constraints */
518678453a8Sspeer } mac_capab_share_t;
519678453a8Sspeer 
520678453a8Sspeer /*
521ba2e4443Sseb  * Flags for mc_callbacks.  Requiring drivers to set the flags associated
522ba2e4443Sseb  * with optional callbacks initialized in the structure allows the mac
523ba2e4443Sseb  * module to add optional callbacks in the future without requiring drivers
524ba2e4443Sseb  * to recompile.
5257c478bd9Sstevel@tonic-gate  */
526ba2e4443Sseb #define	MC_RESOURCES	0x001
527ba2e4443Sseb #define	MC_IOCTL	0x002
528ba2e4443Sseb #define	MC_GETCAPAB	0x004
529d62bc4baSyz147064 #define	MC_OPEN		0x008
530d62bc4baSyz147064 #define	MC_CLOSE	0x010
531e7801d59Ssowmini #define	MC_SETPROP	0x020
532e7801d59Ssowmini #define	MC_GETPROP	0x040
533d62bc4baSyz147064 
534d62bc4baSyz147064 #define	MAC_MAX_MINOR	1000
5357c478bd9Sstevel@tonic-gate 
536ba2e4443Sseb typedef struct mac_register_s {
537ba2e4443Sseb 	uint_t			m_version;	/* set by mac_alloc() */
538ba2e4443Sseb 	const char		*m_type_ident;
5397c478bd9Sstevel@tonic-gate 	void			*m_driver;	/* Driver private data */
5407c478bd9Sstevel@tonic-gate 	dev_info_t		*m_dip;
541ba2e4443Sseb 	uint_t			m_instance;
542ba2e4443Sseb 	uint8_t			*m_src_addr;
543ba2e4443Sseb 	uint8_t			*m_dst_addr;
544ba2e4443Sseb 	mac_callbacks_t		*m_callbacks;
545ba2e4443Sseb 	uint_t			m_min_sdu;
546ba2e4443Sseb 	uint_t			m_max_sdu;
547ba2e4443Sseb 	void			*m_pdata;
548ba2e4443Sseb 	size_t			m_pdata_size;
549d62bc4baSyz147064 	uint32_t		m_margin;
5504045d941Ssowmini 	mac_priv_prop_t		*m_priv_props;
5514045d941Ssowmini 	size_t			m_priv_prop_count;
552ba2e4443Sseb } mac_register_t;
5537c478bd9Sstevel@tonic-gate 
5544045d941Ssowmini 
5557c478bd9Sstevel@tonic-gate /*
5567c478bd9Sstevel@tonic-gate  * Opaque handle types.
5577c478bd9Sstevel@tonic-gate  */
558ba2e4443Sseb typedef	struct mac_t			*mac_handle_t;
5597c478bd9Sstevel@tonic-gate typedef struct __mac_notify_handle	*mac_notify_handle_t;
5607c478bd9Sstevel@tonic-gate typedef struct __mac_rx_handle		*mac_rx_handle_t;
5617c478bd9Sstevel@tonic-gate typedef struct __mac_txloop_handle	*mac_txloop_handle_t;
5627c478bd9Sstevel@tonic-gate typedef struct __mac_resource_handle	*mac_resource_handle_t;
5637c478bd9Sstevel@tonic-gate 
5647c478bd9Sstevel@tonic-gate /*
5657c478bd9Sstevel@tonic-gate  * MAC interface callback types.
5667c478bd9Sstevel@tonic-gate  */
5677c478bd9Sstevel@tonic-gate typedef enum {
5687c478bd9Sstevel@tonic-gate 	MAC_NOTE_LINK,
5697c478bd9Sstevel@tonic-gate 	MAC_NOTE_PROMISC,
5707c478bd9Sstevel@tonic-gate 	MAC_NOTE_UNICST,
5717c478bd9Sstevel@tonic-gate 	MAC_NOTE_TX,
5727c478bd9Sstevel@tonic-gate 	MAC_NOTE_RESOURCE,
5737c478bd9Sstevel@tonic-gate 	MAC_NOTE_DEVPROMISC,
574ba2e4443Sseb 	MAC_NOTE_FASTPATH_FLUSH,
575e7801d59Ssowmini 	MAC_NOTE_SDU_SIZE,
576843e1988Sjohnlev 	MAC_NOTE_VNIC,
577d62bc4baSyz147064 	MAC_NOTE_MARGIN,
5787c478bd9Sstevel@tonic-gate 	MAC_NNOTE	/* must be the last entry */
5797c478bd9Sstevel@tonic-gate } mac_notify_type_t;
5807c478bd9Sstevel@tonic-gate 
5817c478bd9Sstevel@tonic-gate typedef void		(*mac_notify_t)(void *, mac_notify_type_t);
5827c478bd9Sstevel@tonic-gate typedef void		(*mac_rx_t)(void *, mac_resource_handle_t, mblk_t *);
5837c478bd9Sstevel@tonic-gate typedef void		(*mac_txloop_t)(void *, mblk_t *);
5847c478bd9Sstevel@tonic-gate typedef void		(*mac_blank_t)(void *, time_t, uint_t);
5857c478bd9Sstevel@tonic-gate 
5867c478bd9Sstevel@tonic-gate /*
5877c478bd9Sstevel@tonic-gate  * MAC promiscuous types
5887c478bd9Sstevel@tonic-gate  */
5897c478bd9Sstevel@tonic-gate typedef enum {
5907c478bd9Sstevel@tonic-gate 	MAC_PROMISC = 0x01,		/* MAC instance is promiscuous */
5917c478bd9Sstevel@tonic-gate 	MAC_DEVPROMISC = 0x02		/* Device is promiscuous */
5927c478bd9Sstevel@tonic-gate } mac_promisc_type_t;
5937c478bd9Sstevel@tonic-gate 
5947c478bd9Sstevel@tonic-gate /*
5957c478bd9Sstevel@tonic-gate  * MAC resource types
5967c478bd9Sstevel@tonic-gate  */
5977c478bd9Sstevel@tonic-gate typedef enum {
5987c478bd9Sstevel@tonic-gate 	MAC_RX_FIFO = 1
5997c478bd9Sstevel@tonic-gate } mac_resource_type_t;
6007c478bd9Sstevel@tonic-gate 
6017c478bd9Sstevel@tonic-gate typedef struct mac_rx_fifo_s {
6027c478bd9Sstevel@tonic-gate 	mac_resource_type_t	mrf_type;	/* MAC_RX_FIFO */
6037c478bd9Sstevel@tonic-gate 	mac_blank_t		mrf_blank;
6047c478bd9Sstevel@tonic-gate 	void			*mrf_arg;
6057c478bd9Sstevel@tonic-gate 	time_t			mrf_normal_blank_time;
6067c478bd9Sstevel@tonic-gate 	uint_t			mrf_normal_pkt_count;
6077c478bd9Sstevel@tonic-gate } mac_rx_fifo_t;
6087c478bd9Sstevel@tonic-gate 
60998b1442aSmeem typedef struct mac_txinfo_s {
61098b1442aSmeem 	mac_tx_t		mt_fn;
61198b1442aSmeem 	void			*mt_arg;
61298b1442aSmeem } mac_txinfo_t;
61398b1442aSmeem 
6147c478bd9Sstevel@tonic-gate typedef union mac_resource_u {
6157c478bd9Sstevel@tonic-gate 	mac_resource_type_t	mr_type;
6167c478bd9Sstevel@tonic-gate 	mac_rx_fifo_t		mr_fifo;
6177c478bd9Sstevel@tonic-gate } mac_resource_t;
6187c478bd9Sstevel@tonic-gate 
6197c478bd9Sstevel@tonic-gate typedef mac_resource_handle_t	(*mac_resource_add_t)(void *, mac_resource_t *);
6207c478bd9Sstevel@tonic-gate 
621ba2e4443Sseb typedef enum {
622ba2e4443Sseb 	MAC_ADDRTYPE_UNICAST,
623ba2e4443Sseb 	MAC_ADDRTYPE_MULTICAST,
624ba2e4443Sseb 	MAC_ADDRTYPE_BROADCAST
625ba2e4443Sseb } mac_addrtype_t;
626ba2e4443Sseb 
627ba2e4443Sseb typedef struct mac_header_info_s {
628ba2e4443Sseb 	size_t		mhi_hdrsize;
629ba2e4443Sseb 	size_t		mhi_pktsize;
630ba2e4443Sseb 	const uint8_t	*mhi_daddr;
631ba2e4443Sseb 	const uint8_t	*mhi_saddr;
632ba2e4443Sseb 	uint32_t	mhi_origsap;
633ba2e4443Sseb 	uint32_t	mhi_bindsap;
634ba2e4443Sseb 	mac_addrtype_t	mhi_dsttype;
635605445d5Sdg199075 	uint16_t	mhi_tci;
636d62bc4baSyz147064 	uint_t		mhi_istagged:1,
637d62bc4baSyz147064 			mhi_prom_looped:1;
638ba2e4443Sseb } mac_header_info_t;
639ba2e4443Sseb 
640ba2e4443Sseb /*
641ba2e4443Sseb  * MAC-Type plugin interfaces
642ba2e4443Sseb  */
643ba2e4443Sseb 
644ba2e4443Sseb typedef int		(*mtops_addr_verify_t)(const void *, void *);
645ba2e4443Sseb typedef boolean_t	(*mtops_sap_verify_t)(uint32_t, uint32_t *, void *);
646ba2e4443Sseb typedef mblk_t		*(*mtops_header_t)(const void *, const void *,
647ba2e4443Sseb     uint32_t, void *, mblk_t *, size_t);
648ba2e4443Sseb typedef int		(*mtops_header_info_t)(mblk_t *, void *,
649ba2e4443Sseb     mac_header_info_t *);
650ba2e4443Sseb typedef boolean_t	(*mtops_pdata_verify_t)(void *, size_t);
651ba2e4443Sseb typedef	mblk_t		*(*mtops_header_modify_t)(mblk_t *, void *);
6520d2a8e5eSgd78059 typedef void		(*mtops_link_details_t)(char *, size_t, mac_handle_t,
6530d2a8e5eSgd78059     void *);
654ba2e4443Sseb 
655ba2e4443Sseb typedef struct mactype_ops_s {
656ba2e4443Sseb 	uint_t			mtops_ops;
657ba2e4443Sseb 	/*
658ba2e4443Sseb 	 * mtops_unicst_verify() returns 0 if the given address is a valid
659ba2e4443Sseb 	 * unicast address, or a non-zero errno otherwise.
660ba2e4443Sseb 	 */
661ba2e4443Sseb 	mtops_addr_verify_t	mtops_unicst_verify;
662ba2e4443Sseb 	/*
663ba2e4443Sseb 	 * mtops_multicst_verify() returns 0 if the given address is a
664ba2e4443Sseb 	 * valid multicast address, or a non-zero errno otherwise.  If the
665ba2e4443Sseb 	 * media doesn't support multicast, ENOTSUP should be returned (for
666ba2e4443Sseb 	 * example).
667ba2e4443Sseb 	 */
668ba2e4443Sseb 	mtops_addr_verify_t	mtops_multicst_verify;
669ba2e4443Sseb 	/*
670ba2e4443Sseb 	 * mtops_sap_verify() returns B_TRUE if the given SAP is a valid
671ba2e4443Sseb 	 * SAP value, or B_FALSE otherwise.
672ba2e4443Sseb 	 */
673ba2e4443Sseb 	mtops_sap_verify_t	mtops_sap_verify;
674ba2e4443Sseb 	/*
675ba2e4443Sseb 	 * mtops_header() is used to allocate and construct a MAC header.
676ba2e4443Sseb 	 */
677ba2e4443Sseb 	mtops_header_t		mtops_header;
678ba2e4443Sseb 	/*
679ba2e4443Sseb 	 * mtops_header_info() is used to gather information on a given MAC
680ba2e4443Sseb 	 * header.
681ba2e4443Sseb 	 */
682ba2e4443Sseb 	mtops_header_info_t	mtops_header_info;
683ba2e4443Sseb 	/*
684ba2e4443Sseb 	 * mtops_pdata_verify() is used to verify the validity of MAC
685ba2e4443Sseb 	 * plugin data.  It is called by mac_register() if the driver has
686ba2e4443Sseb 	 * supplied MAC plugin data, and also by mac_pdata_update() when
687ba2e4443Sseb 	 * drivers update the data.
688ba2e4443Sseb 	 */
689ba2e4443Sseb 	mtops_pdata_verify_t	mtops_pdata_verify;
690ba2e4443Sseb 	/*
691ba2e4443Sseb 	 * mtops_header_cook() is an optional callback that converts (or
692ba2e4443Sseb 	 * "cooks") the given raw header (as sent by a raw DLPI consumer)
693ba2e4443Sseb 	 * into one that is appropriate to send down to the MAC driver.
694ba2e4443Sseb 	 * Following the example above, an Ethernet header sent down by a
695ba2e4443Sseb 	 * DLPI consumer would be converted to whatever header the MAC
696ba2e4443Sseb 	 * driver expects.
697ba2e4443Sseb 	 */
698ba2e4443Sseb 	mtops_header_modify_t	mtops_header_cook;
699ba2e4443Sseb 	/*
700ba2e4443Sseb 	 * mtops_header_uncook() is an optional callback that does the
701ba2e4443Sseb 	 * opposite of mtops_header_cook().  It "uncooks" a given MAC
702ba2e4443Sseb 	 * header (as received from the driver) for consumption by raw DLPI
703ba2e4443Sseb 	 * consumers.  For example, for a non-Ethernet plugin that wants
704ba2e4443Sseb 	 * raw DLPI consumers to be fooled into thinking that the device
705ba2e4443Sseb 	 * provides Ethernet access, this callback would modify the given
706ba2e4443Sseb 	 * mblk_t such that the MAC header is converted to an Ethernet
707ba2e4443Sseb 	 * header.
708ba2e4443Sseb 	 */
709ba2e4443Sseb 	mtops_header_modify_t	mtops_header_uncook;
7100d2a8e5eSgd78059 	/*
7110d2a8e5eSgd78059 	 * mtops_link_details() is an optional callback that provides
7120d2a8e5eSgd78059 	 * extended information about the link state.  Its primary purpose
7130d2a8e5eSgd78059 	 * is to provide type-specific support for syslog contents on
7140d2a8e5eSgd78059 	 * link up events.  If no implementation is provided, then a default
7150d2a8e5eSgd78059 	 * implementation will be used.
7160d2a8e5eSgd78059 	 */
7170d2a8e5eSgd78059 	mtops_link_details_t	mtops_link_details;
718ba2e4443Sseb } mactype_ops_t;
719ba2e4443Sseb 
720ba2e4443Sseb /*
721ba2e4443Sseb  * mtops_ops exists for the plugin to enumerate the optional callback
722ba2e4443Sseb  * entrypoints it has defined.  This allows the mac module to define
723ba2e4443Sseb  * additional plugin entrypoints in mactype_ops_t without breaking backward
724ba2e4443Sseb  * compatibility with old plugins.
725ba2e4443Sseb  */
726ba2e4443Sseb #define	MTOPS_PDATA_VERIFY	0x001
727ba2e4443Sseb #define	MTOPS_HEADER_COOK	0x002
728ba2e4443Sseb #define	MTOPS_HEADER_UNCOOK	0x004
7290d2a8e5eSgd78059 #define	MTOPS_LINK_DETAILS	0x008
730ba2e4443Sseb 
7314045d941Ssowmini /*
7324045d941Ssowmini  * Provide mapping for legacy ndd ioctls relevant to that mactype.
7334045d941Ssowmini  * Note that the ndd ioctls are obsolete, and may be removed in a future
7344045d941Ssowmini  * release of Solaris. The ndd ioctls are not typically used in legacy
7354045d941Ssowmini  * ethernet drivers. New datalink drivers of all link-types should use
7364045d941Ssowmini  * dladm(1m) interfaces for administering tunables and not have to provide
7374045d941Ssowmini  * a mapping.
7384045d941Ssowmini  */
7394045d941Ssowmini typedef struct mac_ndd_mapping_s {
7404045d941Ssowmini 	char		*mp_name;
7414045d941Ssowmini 	union {
7424045d941Ssowmini 		mac_prop_id_t   u_id;
7434045d941Ssowmini 		uint_t		u_kstat;
7444045d941Ssowmini 	} u_mp_id;
7454045d941Ssowmini 	long		mp_minval;
7464045d941Ssowmini 	long		mp_maxval;
7474045d941Ssowmini 	size_t		mp_valsize;
7484045d941Ssowmini 	int		mp_flags;
7494045d941Ssowmini } mac_ndd_mapping_t;
7504045d941Ssowmini 
7514045d941Ssowmini #define	mp_prop_id	u_mp_id.u_id
7524045d941Ssowmini #define	mp_kstat	u_mp_id.u_kstat
7534045d941Ssowmini 
7544045d941Ssowmini /*
7554045d941Ssowmini  * Flags to figure out r/w status of legacy ndd props.
7564045d941Ssowmini  */
7574045d941Ssowmini #define	MAC_PROP_PERM_READ		0x0001
7584045d941Ssowmini #define	MAC_PROP_PERM_WRITE		0x0010
7594045d941Ssowmini #define	MAC_PROP_MAP_KSTAT		0x0100
7604045d941Ssowmini #define	MAC_PROP_PERM_RW		(MAC_PROP_PERM_READ|MAC_PROP_PERM_WRITE)
7614045d941Ssowmini #define	MAC_PROP_FLAGS_RK		(MAC_PROP_PERM_READ|MAC_PROP_MAP_KSTAT)
7624045d941Ssowmini 
763ba2e4443Sseb typedef struct mactype_register_s {
764ba2e4443Sseb 	uint_t		mtr_version;	/* set by mactype_alloc() */
765ba2e4443Sseb 	const char	*mtr_ident;
766ba2e4443Sseb 	mactype_ops_t	*mtr_ops;
767ba2e4443Sseb 	uint_t		mtr_mactype;
7680ba2cbe9Sxc151355 	uint_t		mtr_nativetype;
769ba2e4443Sseb 	uint_t		mtr_addrlen;
770ba2e4443Sseb 	uint8_t		*mtr_brdcst_addr;
771ba2e4443Sseb 	mac_stat_info_t	*mtr_stats;
772ba2e4443Sseb 	size_t		mtr_statcount;
7734045d941Ssowmini 	mac_ndd_mapping_t *mtr_mapping;
7744045d941Ssowmini 	size_t		mtr_mappingcount;
775ba2e4443Sseb } mactype_register_t;
776ba2e4443Sseb 
777e7801d59Ssowmini typedef struct mac_prop_s {
778e7801d59Ssowmini 	mac_prop_id_t	mp_id;
779e7801d59Ssowmini 	char		*mp_name;
7804045d941Ssowmini 	uint_t		mp_flags;
781e7801d59Ssowmini } mac_prop_t;
782e7801d59Ssowmini 
7837c478bd9Sstevel@tonic-gate /*
7847c478bd9Sstevel@tonic-gate  * Client interface functions.
7857c478bd9Sstevel@tonic-gate  */
786a08fa175Syz147064 extern int			mac_open(const char *, mac_handle_t *);
787d62bc4baSyz147064 extern int			mac_open_by_linkid(datalink_id_t,
788d62bc4baSyz147064 				    mac_handle_t *);
789d62bc4baSyz147064 extern int			mac_open_by_linkname(const char *,
790d62bc4baSyz147064 				    mac_handle_t *);
7917c478bd9Sstevel@tonic-gate extern void			mac_close(mac_handle_t);
7927c478bd9Sstevel@tonic-gate extern const mac_info_t		*mac_info(mac_handle_t);
793210db224Sericheng extern boolean_t		mac_info_get(const char *, mac_info_t *);
794ba2e4443Sseb extern uint64_t			mac_stat_get(mac_handle_t, uint_t);
7957c478bd9Sstevel@tonic-gate extern int			mac_start(mac_handle_t);
7967c478bd9Sstevel@tonic-gate extern void			mac_stop(mac_handle_t);
7977c478bd9Sstevel@tonic-gate extern int			mac_promisc_set(mac_handle_t, boolean_t,
7987c478bd9Sstevel@tonic-gate 				    mac_promisc_type_t);
7997c478bd9Sstevel@tonic-gate extern boolean_t		mac_promisc_get(mac_handle_t,
8007c478bd9Sstevel@tonic-gate 				    mac_promisc_type_t);
8017c478bd9Sstevel@tonic-gate extern int 			mac_multicst_add(mac_handle_t, const uint8_t *);
8027c478bd9Sstevel@tonic-gate extern int 			mac_multicst_remove(mac_handle_t,
8037c478bd9Sstevel@tonic-gate 				    const uint8_t *);
804ed8845d8Skrgopi extern boolean_t		mac_unicst_verify(mac_handle_t,
805ed8845d8Skrgopi 				    const uint8_t *, uint_t);
8067c478bd9Sstevel@tonic-gate extern int			mac_unicst_set(mac_handle_t, const uint8_t *);
8077c478bd9Sstevel@tonic-gate extern void			mac_unicst_get(mac_handle_t, uint8_t *);
808ba2e4443Sseb extern void			mac_dest_get(mac_handle_t, uint8_t *);
809e7801d59Ssowmini extern void			mac_sdu_get(mac_handle_t, uint_t *, uint_t *);
8107c478bd9Sstevel@tonic-gate extern void			mac_resources(mac_handle_t);
8117c478bd9Sstevel@tonic-gate extern void			mac_ioctl(mac_handle_t, queue_t *, mblk_t *);
81298b1442aSmeem extern const mac_txinfo_t	*mac_tx_get(mac_handle_t);
813843e1988Sjohnlev extern const mac_txinfo_t	*mac_vnic_tx_get(mac_handle_t);
8147c478bd9Sstevel@tonic-gate extern link_state_t		mac_link_get(mac_handle_t);
8157c478bd9Sstevel@tonic-gate extern mac_notify_handle_t	mac_notify_add(mac_handle_t, mac_notify_t,
8167c478bd9Sstevel@tonic-gate 				    void *);
8177c478bd9Sstevel@tonic-gate extern void			mac_notify_remove(mac_handle_t,
8187c478bd9Sstevel@tonic-gate 				    mac_notify_handle_t);
8197c478bd9Sstevel@tonic-gate extern void			mac_notify(mac_handle_t);
8207c478bd9Sstevel@tonic-gate extern mac_rx_handle_t		mac_rx_add(mac_handle_t, mac_rx_t, void *);
821843e1988Sjohnlev extern mac_rx_handle_t		mac_active_rx_add(mac_handle_t, mac_rx_t,
822843e1988Sjohnlev 				    void *);
8231f8aaf0dSethindra extern void			mac_rx_remove(mac_handle_t, mac_rx_handle_t,
8241f8aaf0dSethindra 				    boolean_t);
8251f8aaf0dSethindra extern void			mac_rx_remove_wait(mac_handle_t);
8267c478bd9Sstevel@tonic-gate extern mblk_t			*mac_txloop(void *, mblk_t *);
8277c478bd9Sstevel@tonic-gate extern mac_txloop_handle_t	mac_txloop_add(mac_handle_t, mac_txloop_t,
8287c478bd9Sstevel@tonic-gate 				    void *);
8297c478bd9Sstevel@tonic-gate extern void			mac_txloop_remove(mac_handle_t,
8307c478bd9Sstevel@tonic-gate 				    mac_txloop_handle_t);
8317c478bd9Sstevel@tonic-gate extern boolean_t		mac_active_set(mac_handle_t);
832843e1988Sjohnlev extern boolean_t		mac_active_shareable_set(mac_handle_t);
8337c478bd9Sstevel@tonic-gate extern void			mac_active_clear(mac_handle_t);
834843e1988Sjohnlev extern void			mac_active_rx(void *, mac_resource_handle_t,
835843e1988Sjohnlev 				    mblk_t *);
836843e1988Sjohnlev extern boolean_t		mac_vnic_set(mac_handle_t, mac_txinfo_t *,
837843e1988Sjohnlev 				    mac_getcapab_t, void *);
838843e1988Sjohnlev extern void			mac_vnic_clear(mac_handle_t);
8397c478bd9Sstevel@tonic-gate extern void			mac_resource_set(mac_handle_t,
8407c478bd9Sstevel@tonic-gate 				    mac_resource_add_t, void *);
841210db224Sericheng extern dev_info_t		*mac_devinfo_get(mac_handle_t);
842d62bc4baSyz147064 extern const char		*mac_name(mac_handle_t);
843d62bc4baSyz147064 extern minor_t			mac_minor(mac_handle_t);
844ba2e4443Sseb extern boolean_t		mac_capab_get(mac_handle_t, mac_capab_t,
845ba2e4443Sseb 				    void *);
846843e1988Sjohnlev extern boolean_t		mac_vnic_capab_get(mac_handle_t, mac_capab_t,
847843e1988Sjohnlev 				    void *);
848ba2e4443Sseb extern boolean_t		mac_sap_verify(mac_handle_t, uint32_t,
849ba2e4443Sseb 				    uint32_t *);
850ba2e4443Sseb extern mblk_t			*mac_header(mac_handle_t, const uint8_t *,
851ba2e4443Sseb 				    uint32_t, mblk_t *, size_t);
852ba2e4443Sseb extern int			mac_header_info(mac_handle_t, mblk_t *,
853ba2e4443Sseb 				    mac_header_info_t *);
854ba2e4443Sseb extern mblk_t			*mac_header_cook(mac_handle_t, mblk_t *);
855ba2e4443Sseb extern mblk_t			*mac_header_uncook(mac_handle_t, mblk_t *);
856d62bc4baSyz147064 extern minor_t			mac_minor_hold(boolean_t);
857d62bc4baSyz147064 extern void			mac_minor_rele(minor_t);
8587c478bd9Sstevel@tonic-gate 
8597c478bd9Sstevel@tonic-gate /*
8607c478bd9Sstevel@tonic-gate  * Driver interface functions.
8617c478bd9Sstevel@tonic-gate  */
862ba2e4443Sseb extern mac_register_t		*mac_alloc(uint_t);
863ba2e4443Sseb extern void			mac_free(mac_register_t *);
864ba2e4443Sseb extern int			mac_register(mac_register_t *, mac_handle_t *);
865843e1988Sjohnlev extern int			mac_disable(mac_handle_t);
866ba2e4443Sseb extern int  			mac_unregister(mac_handle_t);
867ba2e4443Sseb extern void 			mac_rx(mac_handle_t, mac_resource_handle_t,
8687c478bd9Sstevel@tonic-gate 				    mblk_t *);
869ba2e4443Sseb extern void 			mac_link_update(mac_handle_t, link_state_t);
870ba2e4443Sseb extern void 			mac_unicst_update(mac_handle_t,
871ba2e4443Sseb 				    const uint8_t *);
872ba2e4443Sseb extern void			mac_tx_update(mac_handle_t);
873ba2e4443Sseb extern void			mac_resource_update(mac_handle_t);
874ba2e4443Sseb extern mac_resource_handle_t	mac_resource_add(mac_handle_t,
875ba2e4443Sseb 				    mac_resource_t *);
876e7801d59Ssowmini extern int			mac_maxsdu_update(mac_handle_t, uint_t);
877ba2e4443Sseb extern int			mac_pdata_update(mac_handle_t, void *,
878ba2e4443Sseb 				    size_t);
879ba2e4443Sseb extern void			mac_multicst_refresh(mac_handle_t,
880ba2e4443Sseb 				    mac_multicst_t, void *, boolean_t);
881ba2e4443Sseb extern void			mac_unicst_refresh(mac_handle_t, mac_unicst_t,
8827c478bd9Sstevel@tonic-gate 				    void *);
883ba2e4443Sseb extern void			mac_promisc_refresh(mac_handle_t,
884ba2e4443Sseb 				    mac_setpromisc_t, void *);
885d62bc4baSyz147064 extern boolean_t		mac_margin_update(mac_handle_t, uint32_t);
886d62bc4baSyz147064 extern void			mac_margin_get(mac_handle_t, uint32_t *);
887d62bc4baSyz147064 extern int			mac_margin_remove(mac_handle_t, uint32_t);
888d62bc4baSyz147064 extern int			mac_margin_add(mac_handle_t, uint32_t *,
889d62bc4baSyz147064 				    boolean_t);
890210db224Sericheng extern void			mac_init_ops(struct dev_ops *, const char *);
891210db224Sericheng extern void			mac_fini_ops(struct dev_ops *);
892d62bc4baSyz147064 extern uint32_t			mac_no_notification(mac_handle_t);
893d62bc4baSyz147064 extern boolean_t		mac_is_legacy(mac_handle_t);
894d62bc4baSyz147064 extern int			mac_hold_exclusive(mac_handle_t);
895d62bc4baSyz147064 extern void			mac_rele_exclusive(mac_handle_t);
896d62bc4baSyz147064 
897ba2e4443Sseb extern mactype_register_t	*mactype_alloc(uint_t);
898ba2e4443Sseb extern void			mactype_free(mactype_register_t *);
899ba2e4443Sseb extern int			mactype_register(mactype_register_t *);
900ba2e4443Sseb extern int			mactype_unregister(const char *);
901e7801d59Ssowmini extern int			mac_set_prop(mac_handle_t, mac_prop_t *,
902e7801d59Ssowmini 				    void *, uint_t);
903e7801d59Ssowmini extern int			mac_get_prop(mac_handle_t, mac_prop_t *,
904e7801d59Ssowmini 				    void *, uint_t);
9057c478bd9Sstevel@tonic-gate 
9067c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
9077c478bd9Sstevel@tonic-gate 
9087c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
9097c478bd9Sstevel@tonic-gate }
9107c478bd9Sstevel@tonic-gate #endif
9117c478bd9Sstevel@tonic-gate 
9127c478bd9Sstevel@tonic-gate #endif /* _SYS_MAC_H */
913