xref: /onnv-gate/usr/src/uts/common/sys/mac.h (revision 2760:38f12e308f6d)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
52311Sseb  * Common Development and Distribution License (the "License").
62311Sseb  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
222311Sseb  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef	_SYS_MAC_H
270Sstevel@tonic-gate #define	_SYS_MAC_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
300Sstevel@tonic-gate 
31*2760Sdg199075 #include <sys/types.h>
320Sstevel@tonic-gate #include <sys/ddi.h>
330Sstevel@tonic-gate #include <sys/sunddi.h>
340Sstevel@tonic-gate #include <sys/stream.h>
350Sstevel@tonic-gate 
360Sstevel@tonic-gate /*
370Sstevel@tonic-gate  * MAC Services Module
380Sstevel@tonic-gate  */
390Sstevel@tonic-gate 
400Sstevel@tonic-gate #ifdef	__cplusplus
410Sstevel@tonic-gate extern "C" {
420Sstevel@tonic-gate #endif
430Sstevel@tonic-gate 
440Sstevel@tonic-gate /*
450Sstevel@tonic-gate  * MAC Information (text emitted by modinfo(1m))
460Sstevel@tonic-gate  */
470Sstevel@tonic-gate #define	MAC_INFO	"MAC Services v%I%"
480Sstevel@tonic-gate 
490Sstevel@tonic-gate /*
502311Sseb  * MAC version identifier.  This is used by mac_alloc() mac_register() to
512311Sseb  * verify that incompatible drivers don't register.
522311Sseb  */
532311Sseb #define	MAC_VERSION	0x1
542311Sseb 
552311Sseb /*
562311Sseb  * MAC-Type version identifier.  This is used by mactype_alloc() and
572311Sseb  * mactype_register() to verify that incompatible MAC-Type plugins don't
582311Sseb  * register.
592311Sseb  */
602311Sseb #define	MACTYPE_VERSION	0x1
612311Sseb 
622311Sseb /*
630Sstevel@tonic-gate  * Statistics
640Sstevel@tonic-gate  */
650Sstevel@tonic-gate 
660Sstevel@tonic-gate #define	XCVR_UNDEFINED		0
670Sstevel@tonic-gate #define	XCVR_NONE		1
680Sstevel@tonic-gate #define	XCVR_10			2
690Sstevel@tonic-gate #define	XCVR_100T4		3
700Sstevel@tonic-gate #define	XCVR_100X		4
710Sstevel@tonic-gate #define	XCVR_100T2		5
720Sstevel@tonic-gate #define	XCVR_1000X		6
730Sstevel@tonic-gate #define	XCVR_1000T		7
740Sstevel@tonic-gate 
750Sstevel@tonic-gate typedef enum {
760Sstevel@tonic-gate 	LINK_STATE_UNKNOWN = -1,
770Sstevel@tonic-gate 	LINK_STATE_DOWN,
780Sstevel@tonic-gate 	LINK_STATE_UP
790Sstevel@tonic-gate } link_state_t;
800Sstevel@tonic-gate 
810Sstevel@tonic-gate typedef enum {
820Sstevel@tonic-gate 	LINK_DUPLEX_UNKNOWN = 0,
830Sstevel@tonic-gate 	LINK_DUPLEX_HALF,
840Sstevel@tonic-gate 	LINK_DUPLEX_FULL
850Sstevel@tonic-gate } link_duplex_t;
860Sstevel@tonic-gate 
870Sstevel@tonic-gate #ifdef	_KERNEL
880Sstevel@tonic-gate 
892311Sseb typedef struct mac_stat_info_s {
902311Sseb 	uint_t		msi_stat;
912311Sseb 	char		*msi_name;
922311Sseb 	uint_t		msi_type;	/* as defined in kstat_named_init(9F) */
932311Sseb 	uint64_t	msi_default;
942311Sseb } mac_stat_info_t;
952311Sseb 
962311Sseb /*
972311Sseb  * There are three ranges of statistics values.  0 to 1 - MAC_STAT_MIN are
982311Sseb  * interface statistics maintained by the mac module.  MAC_STAT_MIN to 1 -
992311Sseb  * MACTYPE_STAT_MIN are common MAC statistics defined by the mac module and
1002311Sseb  * maintained by each driver.  MACTYPE_STAT_MIN and above are statistics
1012311Sseb  * defined by MAC-Type plugins and maintained by each driver.
1022311Sseb  */
1032311Sseb #define	MAC_STAT_MIN		1000
1042311Sseb #define	MACTYPE_STAT_MIN	2000
1052311Sseb 
1062311Sseb #define	IS_MAC_STAT(stat)	\
1072311Sseb 	(stat >= MAC_STAT_MIN && stat < MACTYPE_STAT_MIN)
1082311Sseb #define	IS_MACTYPE_STAT(stat)	(stat >= MACTYPE_STAT_MIN)
1092311Sseb 
1102311Sseb enum mac_driver_stat {
1112311Sseb 	/* MIB-II stats (RFC 1213 and RFC 1573) */
1122311Sseb 	MAC_STAT_IFSPEED = MAC_STAT_MIN,
1130Sstevel@tonic-gate 	MAC_STAT_MULTIRCV,
1140Sstevel@tonic-gate 	MAC_STAT_BRDCSTRCV,
1150Sstevel@tonic-gate 	MAC_STAT_MULTIXMT,
1160Sstevel@tonic-gate 	MAC_STAT_BRDCSTXMT,
1170Sstevel@tonic-gate 	MAC_STAT_NORCVBUF,
1180Sstevel@tonic-gate 	MAC_STAT_IERRORS,
1190Sstevel@tonic-gate 	MAC_STAT_UNKNOWNS,
1200Sstevel@tonic-gate 	MAC_STAT_NOXMTBUF,
1210Sstevel@tonic-gate 	MAC_STAT_OERRORS,
1220Sstevel@tonic-gate 	MAC_STAT_COLLISIONS,
1230Sstevel@tonic-gate 	MAC_STAT_RBYTES,
1240Sstevel@tonic-gate 	MAC_STAT_IPACKETS,
1250Sstevel@tonic-gate 	MAC_STAT_OBYTES,
1262311Sseb 	MAC_STAT_OPACKETS
1272311Sseb };
1280Sstevel@tonic-gate 
1292311Sseb #define	MAC_NSTAT	(MAC_STAT_OPACKETS - MAC_STAT_IFSPEED + 1)
1300Sstevel@tonic-gate 
1312311Sseb #define	MAC_STAT_ISACOUNTER(_stat) (		\
1322311Sseb 	    (_stat) == MAC_STAT_MULTIRCV ||	\
1332311Sseb 	    (_stat) == MAC_STAT_BRDCSTRCV ||	\
1342311Sseb 	    (_stat) == MAC_STAT_MULTIXMT ||	\
1352311Sseb 	    (_stat) == MAC_STAT_BRDCSTXMT ||	\
1362311Sseb 	    (_stat) == MAC_STAT_NORCVBUF ||	\
1372311Sseb 	    (_stat) == MAC_STAT_IERRORS ||	\
1382311Sseb 	    (_stat) == MAC_STAT_UNKNOWNS ||	\
1392311Sseb 	    (_stat) == MAC_STAT_NOXMTBUF ||	\
1402311Sseb 	    (_stat) == MAC_STAT_OERRORS ||	\
1412311Sseb 	    (_stat) == MAC_STAT_COLLISIONS ||	\
1422311Sseb 	    (_stat) == MAC_STAT_RBYTES ||	\
1432311Sseb 	    (_stat) == MAC_STAT_IPACKETS ||	\
1442311Sseb 	    (_stat) == MAC_STAT_OBYTES ||	\
1452311Sseb 	    (_stat) == MAC_STAT_OPACKETS)
1460Sstevel@tonic-gate 
1470Sstevel@tonic-gate /*
1480Sstevel@tonic-gate  * Maximum MAC address length
1490Sstevel@tonic-gate  */
1502311Sseb #define	MAXMACADDRLEN	20
1510Sstevel@tonic-gate 
1520Sstevel@tonic-gate /*
1530Sstevel@tonic-gate  * Immutable information. (This may not be modified after registration).
1540Sstevel@tonic-gate  */
1550Sstevel@tonic-gate typedef struct mac_info_s {
1560Sstevel@tonic-gate 	uint_t		mi_media;
1570Sstevel@tonic-gate 	uint_t		mi_sdu_min;
1580Sstevel@tonic-gate 	uint_t		mi_sdu_max;
1590Sstevel@tonic-gate 	uint_t		mi_addr_length;
1602311Sseb 	uint8_t		*mi_unicst_addr;
1612311Sseb 	uint8_t		*mi_brdcst_addr;
1620Sstevel@tonic-gate } mac_info_t;
1630Sstevel@tonic-gate 
1640Sstevel@tonic-gate /*
1652311Sseb  * MAC layer capabilities.  These capabilities are handled by the drivers'
1662311Sseb  * mc_capab_get() callbacks.  Some capabilities require the driver to fill
1672311Sseb  * in a given data structure, and others are simply boolean capabilities.
1682311Sseb  * Note that capability values must be powers of 2 so that consumers and
1692311Sseb  * providers of this interface can keep track of which capabilities they
1702311Sseb  * care about by keeping a bitfield of these things around somewhere.
1710Sstevel@tonic-gate  */
1722311Sseb typedef enum {
1732311Sseb 	MAC_CAPAB_HCKSUM	= 0x01,	/* data is a uint32_t for the txflags */
1742331Skrgopi 	MAC_CAPAB_POLL		= 0x02,	/* boolean only, no data */
1752406Skrgopi 	MAC_CAPAB_MULTIADDRESS	= 0x04	/* data is multiaddress_capab_t */
1762311Sseb 	/* add new capabilities here */
1772311Sseb } mac_capab_t;
1780Sstevel@tonic-gate 
1792331Skrgopi typedef int mac_addr_slot_t;
1802331Skrgopi 
1812331Skrgopi /* mma_flags values */
1822331Skrgopi #define	MMAC_SLOT_USED		0x1   /* address slot used */
1832331Skrgopi #define	MMAC_SLOT_UNUSED	0x2   /* free address slot */
1842331Skrgopi #define	MMAC_VENDOR_ADDR	0x4   /* address returned is vendor supplied */
1852331Skrgopi 
1862331Skrgopi typedef struct mac_multi_address_s {
1872331Skrgopi 	mac_addr_slot_t	mma_slot;	/* slot for add/remove/get/set */
1882331Skrgopi 	uint_t		mma_addrlen;
1892331Skrgopi 	uint8_t		mma_addr[MAXMACADDRLEN];
1902331Skrgopi 	uint_t		mma_flags;
1912331Skrgopi } mac_multi_addr_t;
1922331Skrgopi 
1932331Skrgopi typedef int	(*maddr_reserve_t)(void *, mac_multi_addr_t *);
1942331Skrgopi typedef int	(*maddr_add_t)(void *, mac_multi_addr_t *);
1952331Skrgopi typedef int	(*maddr_remove_t)(void *, mac_addr_slot_t);
1962331Skrgopi typedef int	(*maddr_modify_t)(void *, mac_multi_addr_t *);
1972331Skrgopi typedef int	(*maddr_get_t)(void *, mac_multi_addr_t *);
1982331Skrgopi 
1992331Skrgopi /* maddr_flag values */
2002331Skrgopi #define	MADDR_VENDOR_ADDR	0x01	/* addr returned is vendor supplied */
2012331Skrgopi 
2022331Skrgopi /* multiple mac address: add/remove/set/get mac address */
2032331Skrgopi typedef struct multiaddress_capab_s {
2042331Skrgopi 	int		maddr_naddr;	/* total addresses */
2052331Skrgopi 	int		maddr_naddrfree;	/* free address slots */
2062331Skrgopi 	uint_t		maddr_flag;	/* MADDR_VENDOR_ADDR bit can be set */
2072331Skrgopi 	/* driver entry points */
2082331Skrgopi 	void		*maddr_handle;	/* cookie to be used for the calls */
2092331Skrgopi 	maddr_reserve_t	maddr_reserve;	/* reserve a factory address */
2102331Skrgopi 	maddr_add_t	maddr_add;	/* add a new unicst address */
2112331Skrgopi 	maddr_remove_t	maddr_remove;	/* remove an added address */
2122331Skrgopi 	maddr_modify_t	maddr_modify;	/* modify an added address */
2132331Skrgopi 	maddr_get_t	maddr_get;	/* get address from specified slot */
2142331Skrgopi } multiaddress_capab_t;
2152331Skrgopi 
2160Sstevel@tonic-gate /*
2170Sstevel@tonic-gate  * MAC driver entry point types.
2180Sstevel@tonic-gate  */
2192311Sseb typedef int		(*mac_getstat_t)(void *, uint_t, uint64_t *);
2200Sstevel@tonic-gate typedef	int		(*mac_start_t)(void *);
2210Sstevel@tonic-gate typedef void		(*mac_stop_t)(void *);
2222311Sseb typedef int		(*mac_setpromisc_t)(void *, boolean_t);
2230Sstevel@tonic-gate typedef int		(*mac_multicst_t)(void *, boolean_t, const uint8_t *);
2240Sstevel@tonic-gate typedef int		(*mac_unicst_t)(void *, const uint8_t *);
2252311Sseb typedef void		(*mac_ioctl_t)(void *, queue_t *, mblk_t *);
2260Sstevel@tonic-gate typedef void		(*mac_resources_t)(void *);
2270Sstevel@tonic-gate typedef mblk_t		*(*mac_tx_t)(void *, mblk_t *);
2282311Sseb typedef	boolean_t	(*mac_getcapab_t)(void *, mac_capab_t, void *);
2290Sstevel@tonic-gate 
2300Sstevel@tonic-gate /*
2312311Sseb  * Drivers must set all of these callbacks except for mc_resources,
2322311Sseb  * mc_ioctl, and mc_getcapab, which are optional.  If any of these optional
2332311Sseb  * callbacks are set, their appropriate flags must be set in mc_callbacks.
2342311Sseb  * Any future additions to this list must also be accompanied by an
2352311Sseb  * associated mc_callbacks flag so that the framework can grow without
2362311Sseb  * affecting the binary compatibility of the interface.
2370Sstevel@tonic-gate  */
2382311Sseb typedef struct mac_callbacks_s {
2392311Sseb 	uint_t		mc_callbacks;	/* Denotes which callbacks are set */
2402311Sseb 	mac_getstat_t	mc_getstat;	/* Get the value of a statistic */
2412311Sseb 	mac_start_t	mc_start;	/* Start the device */
2422311Sseb 	mac_stop_t	mc_stop;	/* Stop the device */
2432311Sseb 	mac_setpromisc_t mc_setpromisc;	/* Enable or disable promiscuous mode */
2442311Sseb 	mac_multicst_t	mc_multicst;	/* Enable or disable a multicast addr */
2452311Sseb 	mac_unicst_t	mc_unicst;	/* Set the unicast MAC address */
2462311Sseb 	mac_tx_t	mc_tx;		/* Transmit a packet */
2472311Sseb 	mac_resources_t	mc_resources;	/* Get the device resources */
2482311Sseb 	mac_ioctl_t	mc_ioctl;	/* Process an unknown ioctl */
2492311Sseb 	mac_getcapab_t	mc_getcapab;	/* Get capability information */
2502311Sseb } mac_callbacks_t;
2510Sstevel@tonic-gate 
2520Sstevel@tonic-gate /*
2532311Sseb  * Flags for mc_callbacks.  Requiring drivers to set the flags associated
2542311Sseb  * with optional callbacks initialized in the structure allows the mac
2552311Sseb  * module to add optional callbacks in the future without requiring drivers
2562311Sseb  * to recompile.
2570Sstevel@tonic-gate  */
2582311Sseb #define	MC_RESOURCES	0x001
2592311Sseb #define	MC_IOCTL	0x002
2602311Sseb #define	MC_GETCAPAB	0x004
2612311Sseb 
2622311Sseb typedef struct mac_register_s {
2632311Sseb 	uint_t		m_version;	/* set by mac_alloc() */
2642311Sseb 	const char	*m_type_ident;
2652311Sseb 	void		*m_driver;	/* Driver private data */
2662311Sseb 	dev_info_t	*m_dip;
2672311Sseb 	uint_t		m_instance;
2682311Sseb 	uint8_t		*m_src_addr;
2692311Sseb 	uint8_t		*m_dst_addr;
2702311Sseb 	mac_callbacks_t	*m_callbacks;
2712311Sseb 	uint_t		m_min_sdu;
2722311Sseb 	uint_t		m_max_sdu;
2732311Sseb 	void		*m_pdata;
2742311Sseb 	size_t		m_pdata_size;
2752311Sseb } mac_register_t;
2760Sstevel@tonic-gate 
2770Sstevel@tonic-gate /*
2780Sstevel@tonic-gate  * Opaque handle types.
2790Sstevel@tonic-gate  */
2802311Sseb typedef	struct mac_t			*mac_handle_t;
2810Sstevel@tonic-gate typedef struct __mac_notify_handle	*mac_notify_handle_t;
2820Sstevel@tonic-gate typedef struct __mac_rx_handle		*mac_rx_handle_t;
2830Sstevel@tonic-gate typedef struct __mac_txloop_handle	*mac_txloop_handle_t;
2840Sstevel@tonic-gate typedef struct __mac_resource_handle	*mac_resource_handle_t;
2850Sstevel@tonic-gate 
2860Sstevel@tonic-gate /*
2870Sstevel@tonic-gate  * MAC interface callback types.
2880Sstevel@tonic-gate  */
2890Sstevel@tonic-gate typedef enum {
2900Sstevel@tonic-gate 	MAC_NOTE_LINK,
2910Sstevel@tonic-gate 	MAC_NOTE_PROMISC,
2920Sstevel@tonic-gate 	MAC_NOTE_UNICST,
2930Sstevel@tonic-gate 	MAC_NOTE_TX,
2940Sstevel@tonic-gate 	MAC_NOTE_RESOURCE,
2950Sstevel@tonic-gate 	MAC_NOTE_DEVPROMISC,
2962311Sseb 	MAC_NOTE_FASTPATH_FLUSH,
2970Sstevel@tonic-gate 	MAC_NNOTE	/* must be the last entry */
2980Sstevel@tonic-gate } mac_notify_type_t;
2990Sstevel@tonic-gate 
3000Sstevel@tonic-gate typedef void		(*mac_notify_t)(void *, mac_notify_type_t);
3010Sstevel@tonic-gate typedef void		(*mac_rx_t)(void *, mac_resource_handle_t, mblk_t *);
3020Sstevel@tonic-gate typedef void		(*mac_txloop_t)(void *, mblk_t *);
3030Sstevel@tonic-gate typedef void		(*mac_blank_t)(void *, time_t, uint_t);
3040Sstevel@tonic-gate 
3050Sstevel@tonic-gate /*
3060Sstevel@tonic-gate  * MAC promiscuous types
3070Sstevel@tonic-gate  */
3080Sstevel@tonic-gate typedef enum {
3090Sstevel@tonic-gate 	MAC_PROMISC = 0x01,		/* MAC instance is promiscuous */
3100Sstevel@tonic-gate 	MAC_DEVPROMISC = 0x02		/* Device is promiscuous */
3110Sstevel@tonic-gate } mac_promisc_type_t;
3120Sstevel@tonic-gate 
3130Sstevel@tonic-gate /*
3140Sstevel@tonic-gate  * MAC resource types
3150Sstevel@tonic-gate  */
3160Sstevel@tonic-gate typedef enum {
3170Sstevel@tonic-gate 	MAC_RX_FIFO = 1
3180Sstevel@tonic-gate } mac_resource_type_t;
3190Sstevel@tonic-gate 
3200Sstevel@tonic-gate typedef struct mac_rx_fifo_s {
3210Sstevel@tonic-gate 	mac_resource_type_t	mrf_type;	/* MAC_RX_FIFO */
3220Sstevel@tonic-gate 	mac_blank_t		mrf_blank;
3230Sstevel@tonic-gate 	void			*mrf_arg;
3240Sstevel@tonic-gate 	time_t			mrf_normal_blank_time;
3250Sstevel@tonic-gate 	uint_t			mrf_normal_pkt_count;
3260Sstevel@tonic-gate } mac_rx_fifo_t;
3270Sstevel@tonic-gate 
32856Smeem typedef struct mac_txinfo_s {
32956Smeem 	mac_tx_t		mt_fn;
33056Smeem 	void			*mt_arg;
33156Smeem } mac_txinfo_t;
33256Smeem 
3330Sstevel@tonic-gate typedef union mac_resource_u {
3340Sstevel@tonic-gate 	mac_resource_type_t	mr_type;
3350Sstevel@tonic-gate 	mac_rx_fifo_t		mr_fifo;
3360Sstevel@tonic-gate } mac_resource_t;
3370Sstevel@tonic-gate 
3380Sstevel@tonic-gate typedef mac_resource_handle_t	(*mac_resource_add_t)(void *, mac_resource_t *);
3390Sstevel@tonic-gate 
3402311Sseb typedef enum {
3412311Sseb 	MAC_ADDRTYPE_UNICAST,
3422311Sseb 	MAC_ADDRTYPE_MULTICAST,
3432311Sseb 	MAC_ADDRTYPE_BROADCAST
3442311Sseb } mac_addrtype_t;
3452311Sseb 
3462311Sseb typedef struct mac_header_info_s {
3472311Sseb 	size_t		mhi_hdrsize;
3482311Sseb 	size_t		mhi_pktsize;
3492311Sseb 	const uint8_t	*mhi_daddr;
3502311Sseb 	const uint8_t	*mhi_saddr;
3512311Sseb 	uint32_t	mhi_origsap;
3522311Sseb 	uint32_t	mhi_bindsap;
3532311Sseb 	mac_addrtype_t	mhi_dsttype;
354*2760Sdg199075 	boolean_t	mhi_istagged;
355*2760Sdg199075 	uint16_t	mhi_tci;
3562311Sseb } mac_header_info_t;
3572311Sseb 
3582311Sseb /*
3592311Sseb  * MAC-Type plugin interfaces
3602311Sseb  */
3612311Sseb 
3622311Sseb typedef int		(*mtops_addr_verify_t)(const void *, void *);
3632311Sseb typedef boolean_t	(*mtops_sap_verify_t)(uint32_t, uint32_t *, void *);
3642311Sseb typedef mblk_t		*(*mtops_header_t)(const void *, const void *,
3652311Sseb     uint32_t, void *, mblk_t *, size_t);
3662311Sseb typedef int		(*mtops_header_info_t)(mblk_t *, void *,
3672311Sseb     mac_header_info_t *);
3682311Sseb typedef boolean_t	(*mtops_pdata_verify_t)(void *, size_t);
3692311Sseb typedef	mblk_t		*(*mtops_header_modify_t)(mblk_t *, void *);
3702311Sseb 
3712311Sseb typedef struct mactype_ops_s {
3722311Sseb 	uint_t			mtops_ops;
3732311Sseb 	/*
3742311Sseb 	 * mtops_unicst_verify() returns 0 if the given address is a valid
3752311Sseb 	 * unicast address, or a non-zero errno otherwise.
3762311Sseb 	 */
3772311Sseb 	mtops_addr_verify_t	mtops_unicst_verify;
3782311Sseb 	/*
3792311Sseb 	 * mtops_multicst_verify() returns 0 if the given address is a
3802311Sseb 	 * valid multicast address, or a non-zero errno otherwise.  If the
3812311Sseb 	 * media doesn't support multicast, ENOTSUP should be returned (for
3822311Sseb 	 * example).
3832311Sseb 	 */
3842311Sseb 	mtops_addr_verify_t	mtops_multicst_verify;
3852311Sseb 	/*
3862311Sseb 	 * mtops_sap_verify() returns B_TRUE if the given SAP is a valid
3872311Sseb 	 * SAP value, or B_FALSE otherwise.
3882311Sseb 	 */
3892311Sseb 	mtops_sap_verify_t	mtops_sap_verify;
3902311Sseb 	/*
3912311Sseb 	 * mtops_header() is used to allocate and construct a MAC header.
3922311Sseb 	 */
3932311Sseb 	mtops_header_t		mtops_header;
3942311Sseb 	/*
3952311Sseb 	 * mtops_header_info() is used to gather information on a given MAC
3962311Sseb 	 * header.
3972311Sseb 	 */
3982311Sseb 	mtops_header_info_t	mtops_header_info;
3992311Sseb 	/*
4002311Sseb 	 * mtops_pdata_verify() is used to verify the validity of MAC
4012311Sseb 	 * plugin data.  It is called by mac_register() if the driver has
4022311Sseb 	 * supplied MAC plugin data, and also by mac_pdata_update() when
4032311Sseb 	 * drivers update the data.
4042311Sseb 	 */
4052311Sseb 	mtops_pdata_verify_t	mtops_pdata_verify;
4062311Sseb 	/*
4072311Sseb 	 * mtops_header_cook() is an optional callback that converts (or
4082311Sseb 	 * "cooks") the given raw header (as sent by a raw DLPI consumer)
4092311Sseb 	 * into one that is appropriate to send down to the MAC driver.
4102311Sseb 	 * Following the example above, an Ethernet header sent down by a
4112311Sseb 	 * DLPI consumer would be converted to whatever header the MAC
4122311Sseb 	 * driver expects.
4132311Sseb 	 */
4142311Sseb 	mtops_header_modify_t	mtops_header_cook;
4152311Sseb 	/*
4162311Sseb 	 * mtops_header_uncook() is an optional callback that does the
4172311Sseb 	 * opposite of mtops_header_cook().  It "uncooks" a given MAC
4182311Sseb 	 * header (as received from the driver) for consumption by raw DLPI
4192311Sseb 	 * consumers.  For example, for a non-Ethernet plugin that wants
4202311Sseb 	 * raw DLPI consumers to be fooled into thinking that the device
4212311Sseb 	 * provides Ethernet access, this callback would modify the given
4222311Sseb 	 * mblk_t such that the MAC header is converted to an Ethernet
4232311Sseb 	 * header.
4242311Sseb 	 */
4252311Sseb 	mtops_header_modify_t	mtops_header_uncook;
4262311Sseb } mactype_ops_t;
4272311Sseb 
4282311Sseb /*
4292311Sseb  * mtops_ops exists for the plugin to enumerate the optional callback
4302311Sseb  * entrypoints it has defined.  This allows the mac module to define
4312311Sseb  * additional plugin entrypoints in mactype_ops_t without breaking backward
4322311Sseb  * compatibility with old plugins.
4332311Sseb  */
4342311Sseb #define	MTOPS_PDATA_VERIFY	0x001
4352311Sseb #define	MTOPS_HEADER_COOK	0x002
4362311Sseb #define	MTOPS_HEADER_UNCOOK	0x004
4372311Sseb 
4382311Sseb typedef struct mactype_register_s {
4392311Sseb 	uint_t		mtr_version;	/* set by mactype_alloc() */
4402311Sseb 	const char	*mtr_ident;
4412311Sseb 	mactype_ops_t	*mtr_ops;
4422311Sseb 	uint_t		mtr_mactype;
4432311Sseb 	uint_t		mtr_addrlen;
4442311Sseb 	uint8_t		*mtr_brdcst_addr;
4452311Sseb 	mac_stat_info_t	*mtr_stats;
4462311Sseb 	size_t		mtr_statcount;
4472311Sseb } mactype_register_t;
4482311Sseb 
4490Sstevel@tonic-gate /*
4500Sstevel@tonic-gate  * Client interface functions.
4510Sstevel@tonic-gate  */
4520Sstevel@tonic-gate extern int			mac_open(const char *, uint_t, mac_handle_t *);
4530Sstevel@tonic-gate extern void			mac_close(mac_handle_t);
4540Sstevel@tonic-gate extern const mac_info_t		*mac_info(mac_handle_t);
455269Sericheng extern boolean_t		mac_info_get(const char *, mac_info_t *);
4562311Sseb extern uint64_t			mac_stat_get(mac_handle_t, uint_t);
4570Sstevel@tonic-gate extern int			mac_start(mac_handle_t);
4580Sstevel@tonic-gate extern void			mac_stop(mac_handle_t);
4590Sstevel@tonic-gate extern int			mac_promisc_set(mac_handle_t, boolean_t,
4600Sstevel@tonic-gate     mac_promisc_type_t);
4610Sstevel@tonic-gate extern boolean_t		mac_promisc_get(mac_handle_t,
4620Sstevel@tonic-gate     mac_promisc_type_t);
4630Sstevel@tonic-gate extern int 			mac_multicst_add(mac_handle_t, const uint8_t *);
4640Sstevel@tonic-gate extern int 			mac_multicst_remove(mac_handle_t,
4650Sstevel@tonic-gate     const uint8_t *);
4662331Skrgopi extern boolean_t		mac_unicst_verify(mac_handle_t,
4672331Skrgopi     const uint8_t *, uint_t);
4680Sstevel@tonic-gate extern int			mac_unicst_set(mac_handle_t, const uint8_t *);
4690Sstevel@tonic-gate extern void			mac_unicst_get(mac_handle_t, uint8_t *);
4702311Sseb extern void			mac_dest_get(mac_handle_t, uint8_t *);
4710Sstevel@tonic-gate extern void			mac_resources(mac_handle_t);
4720Sstevel@tonic-gate extern void			mac_ioctl(mac_handle_t, queue_t *, mblk_t *);
47356Smeem extern const mac_txinfo_t	*mac_tx_get(mac_handle_t);
4740Sstevel@tonic-gate extern link_state_t		mac_link_get(mac_handle_t);
4750Sstevel@tonic-gate extern mac_notify_handle_t	mac_notify_add(mac_handle_t, mac_notify_t,
4760Sstevel@tonic-gate     void *);
4770Sstevel@tonic-gate extern void			mac_notify_remove(mac_handle_t,
4780Sstevel@tonic-gate     mac_notify_handle_t);
4790Sstevel@tonic-gate extern void			mac_notify(mac_handle_t);
4800Sstevel@tonic-gate extern mac_rx_handle_t		mac_rx_add(mac_handle_t, mac_rx_t, void *);
4810Sstevel@tonic-gate extern void			mac_rx_remove(mac_handle_t, mac_rx_handle_t);
4820Sstevel@tonic-gate extern mblk_t			*mac_txloop(void *, mblk_t *);
4830Sstevel@tonic-gate extern mac_txloop_handle_t	mac_txloop_add(mac_handle_t, mac_txloop_t,
4840Sstevel@tonic-gate     void *);
4850Sstevel@tonic-gate extern void			mac_txloop_remove(mac_handle_t,
4860Sstevel@tonic-gate     mac_txloop_handle_t);
4870Sstevel@tonic-gate extern boolean_t		mac_active_set(mac_handle_t);
4880Sstevel@tonic-gate extern void			mac_active_clear(mac_handle_t);
4890Sstevel@tonic-gate extern void			mac_resource_set(mac_handle_t,
4900Sstevel@tonic-gate     mac_resource_add_t, void *);
491269Sericheng extern dev_info_t		*mac_devinfo_get(mac_handle_t);
4922311Sseb extern boolean_t		mac_capab_get(mac_handle_t, mac_capab_t,
4932311Sseb     void *);
4942311Sseb extern boolean_t		mac_sap_verify(mac_handle_t, uint32_t,
4952311Sseb     uint32_t *);
4962311Sseb extern mblk_t			*mac_header(mac_handle_t, const uint8_t *,
4972311Sseb     uint32_t, mblk_t *, size_t);
4982311Sseb extern int			mac_header_info(mac_handle_t, mblk_t *,
4992311Sseb     mac_header_info_t *);
5002311Sseb extern mblk_t			*mac_header_cook(mac_handle_t, mblk_t *);
5012311Sseb extern mblk_t			*mac_header_uncook(mac_handle_t, mblk_t *);
5020Sstevel@tonic-gate 
5030Sstevel@tonic-gate /*
5040Sstevel@tonic-gate  * Driver interface functions.
5050Sstevel@tonic-gate  */
5062311Sseb extern mac_register_t		*mac_alloc(uint_t);
5072311Sseb extern void			mac_free(mac_register_t *);
5082311Sseb extern int			mac_register(mac_register_t *, mac_handle_t *);
5092311Sseb extern int  			mac_unregister(mac_handle_t);
5102311Sseb extern void 			mac_rx(mac_handle_t, mac_resource_handle_t,
5110Sstevel@tonic-gate     mblk_t *);
5122311Sseb extern void 			mac_link_update(mac_handle_t, link_state_t);
5132311Sseb extern void 			mac_unicst_update(mac_handle_t,
5142311Sseb     const uint8_t *);
5152311Sseb extern void			mac_tx_update(mac_handle_t);
5162311Sseb extern void			mac_resource_update(mac_handle_t);
5172311Sseb extern mac_resource_handle_t	mac_resource_add(mac_handle_t,
5182311Sseb     mac_resource_t *);
5192311Sseb extern int			mac_pdata_update(mac_handle_t, void *,
5202311Sseb     size_t);
5212311Sseb extern void			mac_multicst_refresh(mac_handle_t,
5222311Sseb     mac_multicst_t, void *, boolean_t);
5232311Sseb extern void			mac_unicst_refresh(mac_handle_t, mac_unicst_t,
5240Sstevel@tonic-gate     void *);
5252311Sseb extern void			mac_promisc_refresh(mac_handle_t,
5262311Sseb     mac_setpromisc_t, void *);
527269Sericheng extern void			mac_init_ops(struct dev_ops *, const char *);
528269Sericheng extern void			mac_fini_ops(struct dev_ops *);
5292311Sseb extern mactype_register_t	*mactype_alloc(uint_t);
5302311Sseb extern void			mactype_free(mactype_register_t *);
5312311Sseb extern int			mactype_register(mactype_register_t *);
5322311Sseb extern int			mactype_unregister(const char *);
5330Sstevel@tonic-gate 
5340Sstevel@tonic-gate #endif	/* _KERNEL */
5350Sstevel@tonic-gate 
5360Sstevel@tonic-gate #ifdef	__cplusplus
5370Sstevel@tonic-gate }
5380Sstevel@tonic-gate #endif
5390Sstevel@tonic-gate 
5400Sstevel@tonic-gate #endif /* _SYS_MAC_H */
541