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
51852Syz147064  * Common Development and Distribution License (the "License").
61852Syz147064  * 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 /*
225895Syz147064  * Copyright 2008 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_IMPL_H
270Sstevel@tonic-gate #define	_SYS_MAC_IMPL_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
300Sstevel@tonic-gate 
310Sstevel@tonic-gate #include <sys/mac.h>
322311Sseb #include <net/if.h>
330Sstevel@tonic-gate 
340Sstevel@tonic-gate #ifdef	__cplusplus
350Sstevel@tonic-gate extern "C" {
360Sstevel@tonic-gate #endif
370Sstevel@tonic-gate 
380Sstevel@tonic-gate typedef struct mac_multicst_addr_s	mac_multicst_addr_t;
390Sstevel@tonic-gate 
400Sstevel@tonic-gate struct mac_multicst_addr_s {
410Sstevel@tonic-gate 	mac_multicst_addr_t	*mma_nextp;
420Sstevel@tonic-gate 	uint_t			mma_ref;
432311Sseb 	uint8_t			mma_addr[MAXMACADDRLEN];
440Sstevel@tonic-gate };
450Sstevel@tonic-gate 
465895Syz147064 typedef struct mac_margin_req_s	mac_margin_req_t;
475895Syz147064 
485895Syz147064 struct mac_margin_req_s {
495895Syz147064 	mac_margin_req_t	*mmr_nextp;
505895Syz147064 	uint_t			mmr_ref;
515895Syz147064 	uint32_t		mmr_margin;
525895Syz147064 };
535895Syz147064 
540Sstevel@tonic-gate typedef struct mac_notify_fn_s		mac_notify_fn_t;
550Sstevel@tonic-gate 
560Sstevel@tonic-gate struct mac_notify_fn_s {
570Sstevel@tonic-gate 	mac_notify_fn_t		*mnf_nextp;
580Sstevel@tonic-gate 	mac_notify_t		mnf_fn;
590Sstevel@tonic-gate 	void			*mnf_arg;
600Sstevel@tonic-gate };
610Sstevel@tonic-gate 
620Sstevel@tonic-gate typedef struct mac_rx_fn_s		mac_rx_fn_t;
630Sstevel@tonic-gate 
640Sstevel@tonic-gate struct mac_rx_fn_s {
650Sstevel@tonic-gate 	mac_rx_fn_t		*mrf_nextp;
660Sstevel@tonic-gate 	mac_rx_t		mrf_fn;
670Sstevel@tonic-gate 	void			*mrf_arg;
684913Sethindra 	boolean_t		mrf_inuse;
695084Sjohnlev 	boolean_t		mrf_active;
700Sstevel@tonic-gate };
710Sstevel@tonic-gate 
720Sstevel@tonic-gate typedef struct mac_txloop_fn_s		mac_txloop_fn_t;
730Sstevel@tonic-gate 
740Sstevel@tonic-gate struct mac_txloop_fn_s {
750Sstevel@tonic-gate 	mac_txloop_fn_t		*mtf_nextp;
760Sstevel@tonic-gate 	mac_txloop_t		mtf_fn;
770Sstevel@tonic-gate 	void			*mtf_arg;
780Sstevel@tonic-gate };
790Sstevel@tonic-gate 
802311Sseb typedef struct mactype_s {
812311Sseb 	const char	*mt_ident;
822311Sseb 	uint32_t	mt_ref;
832311Sseb 	uint_t		mt_type;
843147Sxc151355 	uint_t		mt_nativetype;
852311Sseb 	size_t		mt_addr_length;
862311Sseb 	uint8_t		*mt_brdcst_addr;
872311Sseb 	mactype_ops_t	mt_ops;
882311Sseb 	mac_stat_info_t	*mt_stats;	/* array of mac_stat_info_t elements */
892311Sseb 	size_t		mt_statcount;	/* number of elements in mt_stats */
90*6512Ssowmini 	mac_ndd_mapping_t *mt_mapping;
91*6512Ssowmini 	size_t		mt_mappingcount;
922311Sseb } mactype_t;
930Sstevel@tonic-gate 
945084Sjohnlev 
955084Sjohnlev #define	MAC_VNIC_TXINFO_REFHOLD(mvt) {				\
965084Sjohnlev 	mutex_enter(&(mvt)->mv_lock);				\
975084Sjohnlev 	(mvt)->mv_refs++;					\
985084Sjohnlev 	mutex_exit(&(mvt)->mv_lock);				\
995084Sjohnlev }
1005084Sjohnlev 
1015084Sjohnlev #define	MAC_VNIC_TXINFO_REFRELE(mvt) {				\
1025084Sjohnlev 	mutex_enter(&(mvt)->mv_lock);				\
1035084Sjohnlev 	if (--(mvt)->mv_refs == 0 && (mvt)->mv_clearing) {	\
1045084Sjohnlev 	    (mvt)->mv_clearing = B_FALSE;			\
1055084Sjohnlev 	    cv_signal(&(mvt)->mv_cv);				\
1065084Sjohnlev 	}							\
1075084Sjohnlev 	mutex_exit(&(mvt)->mv_lock);				\
1085084Sjohnlev }
1095084Sjohnlev 
1105084Sjohnlev typedef struct mac_vnic_tx_s {
1115084Sjohnlev 	mac_txinfo_t	mv_txinfo;	/* provided by VNIC */
1125084Sjohnlev 	uint32_t	mv_refs;
1135084Sjohnlev 	kmutex_t	mv_lock;
1145084Sjohnlev 	kcondvar_t	mv_cv;
1155084Sjohnlev 	boolean_t	mv_clearing;
1165084Sjohnlev } mac_vnic_tx_t;
1175084Sjohnlev 
118*6512Ssowmini 
1192311Sseb /*
1202311Sseb  * Each registered MAC is associated with a mac_t structure.
1212311Sseb  */
1222311Sseb typedef struct mac_impl_s {
1235895Syz147064 	/*
1245895Syz147064 	 * The following fields are set in mac_register() and will not be
1255895Syz147064 	 * changed until mac_unregister(). No lock is needed to access them.
1265895Syz147064 	 */
1272311Sseb 	char			mi_name[LIFNAMSIZ];
1282311Sseb 	void			*mi_driver;	/* Driver private data */
1292311Sseb 	mac_info_t		mi_info;
1302311Sseb 	mactype_t		*mi_type;
1312311Sseb 	void			*mi_pdata;
1322311Sseb 	size_t			mi_pdata_size;
1332311Sseb 	mac_callbacks_t		*mi_callbacks;
1342311Sseb 	dev_info_t		*mi_dip;
1355895Syz147064 	minor_t			mi_minor;
1365895Syz147064 	dev_t			mi_phy_dev;
1375895Syz147064 	kstat_t			*mi_ksp;
1385895Syz147064 	uint_t			mi_kstat_count;
1395895Syz147064 	mac_txinfo_t		mi_txinfo;
1405895Syz147064 	mac_txinfo_t		mi_txloopinfo;
1415895Syz147064 
1425895Syz147064 	krwlock_t		mi_gen_lock;
1435895Syz147064 	uint32_t		mi_oref;
1440Sstevel@tonic-gate 	uint32_t		mi_ref;
1451852Syz147064 	boolean_t		mi_disabled;
1465895Syz147064 	boolean_t		mi_exclusive;
1475895Syz147064 
1480Sstevel@tonic-gate 	krwlock_t		mi_state_lock;
1490Sstevel@tonic-gate 	uint_t			mi_active;
1505895Syz147064 
1510Sstevel@tonic-gate 	krwlock_t		mi_data_lock;
1522311Sseb 	link_state_t		mi_linkstate;
1534403Sgd78059 	link_state_t		mi_lastlinkstate;
1540Sstevel@tonic-gate 	uint_t			mi_promisc;
1550Sstevel@tonic-gate 	uint_t			mi_devpromisc;
1562311Sseb 	uint8_t			mi_addr[MAXMACADDRLEN];
1572311Sseb 	uint8_t			mi_dstaddr[MAXMACADDRLEN];
1585903Ssowmini 	uint_t			mi_sdu_min;
1595903Ssowmini 	uint_t			mi_sdu_max;
1600Sstevel@tonic-gate 	mac_multicst_addr_t	*mi_mmap;
1615895Syz147064 
1620Sstevel@tonic-gate 	krwlock_t		mi_notify_lock;
1635009Sgd78059 	uint32_t		mi_notify_bits;
1645009Sgd78059 	kmutex_t		mi_notify_bits_lock;
1655009Sgd78059 	kthread_t		*mi_notify_thread;
1660Sstevel@tonic-gate 	mac_notify_fn_t		*mi_mnfp;
1671852Syz147064 	kcondvar_t		mi_notify_cv;
1685895Syz147064 
1690Sstevel@tonic-gate 	krwlock_t		mi_rx_lock;
1700Sstevel@tonic-gate 	mac_rx_fn_t		*mi_mrfp;
1715084Sjohnlev 	krwlock_t		mi_tx_lock;
1720Sstevel@tonic-gate 	mac_txloop_fn_t		*mi_mtfp;
1735895Syz147064 
1740Sstevel@tonic-gate 	krwlock_t		mi_resource_lock;
1750Sstevel@tonic-gate 	mac_resource_add_t	mi_resource_add;
1760Sstevel@tonic-gate 	void			*mi_resource_add_arg;
1775895Syz147064 
1780Sstevel@tonic-gate 	kmutex_t		mi_activelink_lock;
1790Sstevel@tonic-gate 	boolean_t		mi_activelink;
1805895Syz147064 
1814913Sethindra 	uint32_t		mi_rx_ref;	/* #threads in mac_rx() */
1824913Sethindra 	uint32_t		mi_rx_removed;	/* #callbacks marked */
1834913Sethindra 						/* for removal */
1844913Sethindra 	kmutex_t		mi_lock;
1854913Sethindra 	kcondvar_t		mi_rx_cv;
1865084Sjohnlev 	boolean_t		mi_shareable;
1875084Sjohnlev 	boolean_t		mi_vnic_present;
1885084Sjohnlev 	mac_vnic_tx_t		*mi_vnic_tx;
1895084Sjohnlev 	mac_txinfo_t		mi_vnic_txinfo;
1905084Sjohnlev 	mac_txinfo_t		mi_vnic_txloopinfo;
1915084Sjohnlev 	mac_getcapab_t		mi_vnic_getcapab_fn;
1925084Sjohnlev 	void			*mi_vnic_getcapab_arg;
1935895Syz147064 
1945895Syz147064 	boolean_t		mi_legacy;
1955895Syz147064 	uint32_t		mi_unsup_note;
1965895Syz147064 	uint32_t		mi_margin;
1975895Syz147064 
1985895Syz147064 	/*
1995895Syz147064 	 * List of margin value requests added by mac clients. This list is
2005895Syz147064 	 * sorted: the first one has the greatest value.
2015895Syz147064 	 */
2025895Syz147064 	mac_margin_req_t	*mi_mmrp;
203*6512Ssowmini 	mac_priv_prop_t		*mi_priv_prop;
204*6512Ssowmini 	uint_t			mi_priv_prop_count;
2052311Sseb } mac_impl_t;
2062311Sseb 
2072311Sseb #define	mi_getstat	mi_callbacks->mc_getstat
2082311Sseb #define	mi_start	mi_callbacks->mc_start
2092311Sseb #define	mi_stop		mi_callbacks->mc_stop
2105895Syz147064 #define	mi_open		mi_callbacks->mc_open
2115895Syz147064 #define	mi_close	mi_callbacks->mc_close
2122311Sseb #define	mi_setpromisc	mi_callbacks->mc_setpromisc
2132311Sseb #define	mi_multicst	mi_callbacks->mc_multicst
2142311Sseb #define	mi_unicst	mi_callbacks->mc_unicst
2152311Sseb #define	mi_resources	mi_callbacks->mc_resources
2162311Sseb #define	mi_tx		mi_callbacks->mc_tx
2172311Sseb #define	mi_ioctl	mi_callbacks->mc_ioctl
2182311Sseb #define	mi_getcapab	mi_callbacks->mc_getcapab
2190Sstevel@tonic-gate 
2200Sstevel@tonic-gate extern void	mac_init(void);
2210Sstevel@tonic-gate extern int	mac_fini(void);
2220Sstevel@tonic-gate 
2230Sstevel@tonic-gate extern void	mac_stat_create(mac_impl_t *);
2240Sstevel@tonic-gate extern void	mac_stat_destroy(mac_impl_t *);
2252311Sseb extern uint64_t	mac_stat_default(mac_impl_t *, uint_t);
2260Sstevel@tonic-gate 
227*6512Ssowmini extern void mac_ndd_ioctl(mac_impl_t *, queue_t *, mblk_t *);
228*6512Ssowmini 
2290Sstevel@tonic-gate #ifdef	__cplusplus
2300Sstevel@tonic-gate }
2310Sstevel@tonic-gate #endif
2320Sstevel@tonic-gate 
2330Sstevel@tonic-gate #endif	/* _SYS_MAC_IMPL_H */
234