1da14cebeSEric Cheng /*
2da14cebeSEric Cheng  * CDDL HEADER START
3da14cebeSEric Cheng  *
4da14cebeSEric Cheng  * The contents of this file are subject to the terms of the
5da14cebeSEric Cheng  * Common Development and Distribution License (the "License").
6da14cebeSEric Cheng  * You may not use this file except in compliance with the License.
7da14cebeSEric Cheng  *
8da14cebeSEric Cheng  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9da14cebeSEric Cheng  * or http://www.opensolaris.org/os/licensing.
10da14cebeSEric Cheng  * See the License for the specific language governing permissions
11da14cebeSEric Cheng  * and limitations under the License.
12da14cebeSEric Cheng  *
13da14cebeSEric Cheng  * When distributing Covered Code, include this CDDL HEADER in each
14da14cebeSEric Cheng  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15da14cebeSEric Cheng  * If applicable, add the following below this CDDL HEADER, with the
16da14cebeSEric Cheng  * fields enclosed by brackets "[]" replaced with your own identifying
17da14cebeSEric Cheng  * information: Portions Copyright [yyyy] [name of copyright owner]
18da14cebeSEric Cheng  *
19da14cebeSEric Cheng  * CDDL HEADER END
20da14cebeSEric Cheng  */
21da14cebeSEric Cheng /*
220dc2366fSVenugopal Iyer  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
23da14cebeSEric Cheng  * Use is subject to license terms.
2410a40492SRobert Mustacchi  * Copyright (c) 2012, Joyent, Inc.  All rights reserved.
25da14cebeSEric Cheng  */
263bb0cb70SBryan Cantrill /*
2784de666eSRyan Zezeski  * Copyright 2018 Joyent, Inc.
283bb0cb70SBryan Cantrill  */
29da14cebeSEric Cheng 
30da14cebeSEric Cheng #ifndef	_SYS_MAC_CLIENT_IMPL_H
31da14cebeSEric Cheng #define	_SYS_MAC_CLIENT_IMPL_H
32da14cebeSEric Cheng 
33da14cebeSEric Cheng #include <sys/modhash.h>
34da14cebeSEric Cheng #include <sys/mac_client.h>
35da14cebeSEric Cheng #include <sys/mac_provider.h>
36da14cebeSEric Cheng #include <sys/mac.h>
37da14cebeSEric Cheng #include <sys/mac_impl.h>
380dc2366fSVenugopal Iyer #include <sys/mac_stat.h>
39da14cebeSEric Cheng #include <net/if.h>
40da14cebeSEric Cheng #include <sys/mac_flow_impl.h>
41da14cebeSEric Cheng 
42da14cebeSEric Cheng #ifdef	__cplusplus
43da14cebeSEric Cheng extern "C" {
44da14cebeSEric Cheng #endif
45da14cebeSEric Cheng 
46da14cebeSEric Cheng extern kmem_cache_t	*mac_client_impl_cache;
47da14cebeSEric Cheng extern kmem_cache_t	*mac_unicast_impl_cache;
48da14cebeSEric Cheng extern kmem_cache_t	*mac_promisc_impl_cache;
49da14cebeSEric Cheng 
50da14cebeSEric Cheng /*
51da14cebeSEric Cheng  * Need a list to chain all VIDs assigned to a client. Normally, one
52da14cebeSEric Cheng  * MAC client only has one VID. But vsw might need multiple VIDs.
53da14cebeSEric Cheng  */
54da14cebeSEric Cheng typedef struct mac_unicast_impl_s {			/* Protected by */
55da14cebeSEric Cheng 	struct mac_unicast_impl_s	*mui_next;	/* SL */
56da14cebeSEric Cheng 	mac_address_t			*mui_map;	/* SL */
57da14cebeSEric Cheng 	uint16_t			mui_vid;	/* SL */
58da14cebeSEric Cheng } mac_unicast_impl_t;
59da14cebeSEric Cheng 
6084de666eSRyan Zezeski #define	MAC_CLIENT_FLAGS_PRIMARY		0x0001
61da14cebeSEric Cheng #define	MAC_CLIENT_FLAGS_VNIC_PRIMARY		0x0002
62fc4e975dSVenugopal Iyer #define	MAC_CLIENT_FLAGS_MULTI_PRIMARY		0x0004
63fc4e975dSVenugopal Iyer #define	MAC_CLIENT_FLAGS_PASSIVE_PRIMARY	0x0008
64da14cebeSEric Cheng 
65da14cebeSEric Cheng /*
66da14cebeSEric Cheng  * One of these is instantiated per MAC client promiscuous callback.
67da14cebeSEric Cheng  *
68da14cebeSEric Cheng  * Each element of this structure belongs to two linked list. One
69da14cebeSEric Cheng  * for the mac_client_impl_t (mci_promisc_list) which created allocated
70da14cebeSEric Cheng  * the callback, the other for the mac_impl_t (mi_promisc_list) corresponding
71da14cebeSEric Cheng  * to the MAC client.
72da14cebeSEric Cheng  * The former allows us to do bookkeeping, the latter allows us
73da14cebeSEric Cheng  * to more efficiently dispatch packets to the promiscuous callbacks.
74da14cebeSEric Cheng  */
75da14cebeSEric Cheng typedef struct mac_promisc_impl_s {			/* Protected by */
76da14cebeSEric Cheng 	mac_cb_t			mpi_mci_link;	/* mi_promisc_lock */
77da14cebeSEric Cheng 	mac_cb_t			mpi_mi_link;	/* mi_promisc_lock */
78da14cebeSEric Cheng 	mac_client_promisc_type_t	mpi_type;	/* WO */
79da14cebeSEric Cheng 	mac_rx_t			mpi_fn;		/* WO */
80da14cebeSEric Cheng 	void				*mpi_arg;	/* WO */
81da14cebeSEric Cheng 	struct mac_client_impl_s	*mpi_mcip;	/* WO */
82da14cebeSEric Cheng 	boolean_t			mpi_no_tx_loop;	/* WO */
83da14cebeSEric Cheng 	boolean_t			mpi_no_phys;	/* WO */
84ae6aa22aSVenugopal Iyer 	boolean_t			mpi_strip_vlan_tag;	/* WO */
850a0e9771SDarren Reed 	boolean_t			mpi_no_copy;	/* WO */
86da14cebeSEric Cheng } mac_promisc_impl_t;
87da14cebeSEric Cheng 
88da14cebeSEric Cheng typedef union mac_tx_percpu_s {
89da14cebeSEric Cheng 	struct {
90da14cebeSEric Cheng 		kmutex_t	_pcpu_tx_lock;
91da14cebeSEric Cheng 		uint_t		_pcpu_tx_refcnt;
92da14cebeSEric Cheng 	} pcpu_lr;
93da14cebeSEric Cheng 	uchar_t		pcpu_pad[64];
94da14cebeSEric Cheng } mac_tx_percpu_t;
95da14cebeSEric Cheng 
96da14cebeSEric Cheng #define	pcpu_tx_lock	pcpu_lr._pcpu_tx_lock
97da14cebeSEric Cheng #define	pcpu_tx_refcnt	pcpu_lr._pcpu_tx_refcnt
98da14cebeSEric Cheng 
99da14cebeSEric Cheng /*
100797f979dSCody Peter Mello  * One of these is instantiated for each MAC client.
101da14cebeSEric Cheng  */
102da14cebeSEric Cheng struct mac_client_impl_s {			/* Protected by */
103da14cebeSEric Cheng 	struct mac_client_impl_s *mci_client_next;	/* mi_rw_lock */
104da14cebeSEric Cheng 	char			mci_name[MAXNAMELEN];	/* mi_rw_lock */
105da14cebeSEric Cheng 	/*
106da14cebeSEric Cheng 	 * This flow entry will contain all the internal constructs
107da14cebeSEric Cheng 	 * such as SRS etc. for this MAC client. The MAC client may
108da14cebeSEric Cheng 	 * have more than one flow corresponding to each upper client
109da14cebeSEric Cheng 	 * sharing this mac_client_impl_t.
110da14cebeSEric Cheng 	 */
111da14cebeSEric Cheng 	flow_entry_t		*mci_flent;		/* mi_rw_lock */
112da14cebeSEric Cheng 	struct mac_impl_s	*mci_mip;		/* WO */
113da14cebeSEric Cheng 	/*
114da14cebeSEric Cheng 	 * If this is a client that has a pass thru MAC (e.g. a VNIC),
115da14cebeSEric Cheng 	 * then we also keep the handle for the client's upper MAC.
116da14cebeSEric Cheng 	 */
117da14cebeSEric Cheng 	struct mac_impl_s	*mci_upper_mip;		/* WO */
118da14cebeSEric Cheng 
119da14cebeSEric Cheng 	uint32_t		mci_state_flags;	/* WO */
120da14cebeSEric Cheng 	mac_rx_t		mci_rx_fn;		/* Rx Quiescence */
121da14cebeSEric Cheng 	void			*mci_rx_arg;		/* Rx Quiescence */
122da14cebeSEric Cheng 	mac_direct_rx_t		mci_direct_rx_fn;	/* SL */
123da14cebeSEric Cheng 	void			*mci_direct_rx_arg;	/* SL */
124fc4e975dSVenugopal Iyer 	mac_rx_t		mci_rx_p_fn;		/* Rx Quiescence */
125fc4e975dSVenugopal Iyer 	void			*mci_rx_p_arg;		/* Rx Quiescence */
126fc4e975dSVenugopal Iyer 	void			*mci_p_unicast_list;
127da14cebeSEric Cheng 
128da14cebeSEric Cheng 	mac_cb_t		*mci_promisc_list;	/* mi_promisc_lock */
129da14cebeSEric Cheng 
130da14cebeSEric Cheng 	mac_address_t		*mci_unicast;
131da14cebeSEric Cheng 	uint32_t		mci_flags;		/* SL */
132da14cebeSEric Cheng 	krwlock_t		mci_rw_lock;
133da14cebeSEric Cheng 	mac_unicast_impl_t	*mci_unicast_list;	/* mci_rw_lock */
13484de666eSRyan Zezeski 
135da14cebeSEric Cheng 	/*
136da14cebeSEric Cheng 	 * The mac_client_impl_t may be shared by multiple clients, i.e
137da14cebeSEric Cheng 	 * multiple VLANs sharing the same MAC client. In this case the
13884de666eSRyan Zezeski 	 * address/vid tuples differ and are each associated with their
139da14cebeSEric Cheng 	 * own flow entry, but the rest underlying components SRS, etc,
140da14cebeSEric Cheng 	 * are common.
14184de666eSRyan Zezeski 	 *
14284de666eSRyan Zezeski 	 * This is only needed to support sun4v vsw. There are several
14384de666eSRyan Zezeski 	 * places in MAC we could simplify the code if we removed
14484de666eSRyan Zezeski 	 * sun4v support.
145da14cebeSEric Cheng 	 */
146da14cebeSEric Cheng 	flow_entry_t		*mci_flent_list;	/* mci_rw_lock */
147da14cebeSEric Cheng 	uint_t			mci_nflents;		/* mci_rw_lock */
148da14cebeSEric Cheng 	uint_t			mci_nvids;		/* mci_rw_lock */
1493bb0cb70SBryan Cantrill 	volatile uint32_t	mci_vidcache;		/* VID cache */
150da14cebeSEric Cheng 
151da14cebeSEric Cheng 	/* Resource Management Functions */
152da14cebeSEric Cheng 	mac_resource_add_t	mci_resource_add;	/* SL */
153da14cebeSEric Cheng 	mac_resource_remove_t	mci_resource_remove;	/* SL */
154da14cebeSEric Cheng 	mac_resource_quiesce_t	mci_resource_quiesce;	/* SL */
155da14cebeSEric Cheng 	mac_resource_restart_t	mci_resource_restart;	/* SL */
156da14cebeSEric Cheng 	mac_resource_bind_t	mci_resource_bind;	/* SL */
157da14cebeSEric Cheng 	void			*mci_resource_arg;	/* SL */
158da14cebeSEric Cheng 
159da14cebeSEric Cheng 
160da14cebeSEric Cheng 	/* Tx notify callback */
161da14cebeSEric Cheng 	kmutex_t		mci_tx_cb_lock;
162da14cebeSEric Cheng 	mac_cb_info_t		mci_tx_notify_cb_info;	/* cb list info */
163da14cebeSEric Cheng 	mac_cb_t		*mci_tx_notify_cb_list;	/* The cb list */
164da14cebeSEric Cheng 	uintptr_t		mci_tx_notify_id;
165da14cebeSEric Cheng 
166da14cebeSEric Cheng 	/* per MAC client stats */			/* None */
1670dc2366fSVenugopal Iyer 	mac_misc_stats_t	mci_misc_stat;
168da14cebeSEric Cheng 
169da14cebeSEric Cheng 	flow_tab_t		*mci_subflow_tab;	/* Rx quiescence */
170da14cebeSEric Cheng 
171da14cebeSEric Cheng 	/*
172da14cebeSEric Cheng 	 * Priority range for this MAC client. This the range
173da14cebeSEric Cheng 	 * corresponding to the priority configured (nr_flow_priority).
174da14cebeSEric Cheng 	 */
175da14cebeSEric Cheng 	pri_t			mci_min_pri;
176da14cebeSEric Cheng 	pri_t			mci_max_pri;
177da14cebeSEric Cheng 
178da14cebeSEric Cheng 	/*
179da14cebeSEric Cheng 	 * Hybrid I/O related definitions.
180da14cebeSEric Cheng 	 */
181da14cebeSEric Cheng 	mac_share_handle_t	mci_share;
182da14cebeSEric Cheng 
183da14cebeSEric Cheng 	/* for multicast support */
184da14cebeSEric Cheng 	struct mac_mcast_addrs_s *mci_mcast_addrs;	/* mi_rw_lock */
185da14cebeSEric Cheng 
186da14cebeSEric Cheng 	/*
1870dc2366fSVenugopal Iyer 	 * Mac protection related fields
1880dc2366fSVenugopal Iyer 	 */
1890dc2366fSVenugopal Iyer 	kmutex_t		mci_protect_lock;
1900dc2366fSVenugopal Iyer 	uint32_t		mci_protect_flags;	/* SL */
191797f979dSCody Peter Mello 	in6_addr_t		mci_v6_mac_token;	/* SL */
1920dc2366fSVenugopal Iyer 	in6_addr_t		mci_v6_local_addr;	/* SL */
1930dc2366fSVenugopal Iyer 	avl_tree_t		mci_v4_pending_txn;	/* mci_protect_lock */
1940dc2366fSVenugopal Iyer 	avl_tree_t		mci_v4_completed_txn;	/* mci_protect_lock */
1950dc2366fSVenugopal Iyer 	avl_tree_t		mci_v4_dyn_ip;		/* mci_protect_lock */
1960dc2366fSVenugopal Iyer 	avl_tree_t		mci_v6_pending_txn;	/* mci_protect_lock */
1970dc2366fSVenugopal Iyer 	avl_tree_t		mci_v6_cid;		/* mci_protect_lock */
1980dc2366fSVenugopal Iyer 	avl_tree_t		mci_v6_dyn_ip;		/* mci_protect_lock */
199797f979dSCody Peter Mello 	avl_tree_t		mci_v6_slaac_ip;	/* mci_protect_lock */
2000dc2366fSVenugopal Iyer 	timeout_id_t		mci_txn_cleanup_tid;	/* mci_protect_lock */
2010dc2366fSVenugopal Iyer 
2020dc2366fSVenugopal Iyer 	/*
203da14cebeSEric Cheng 	 * Protected by mci_tx_pcpu[0].pcpu_tx_lock
204da14cebeSEric Cheng 	 */
205da14cebeSEric Cheng 	uint_t			mci_tx_flag;
206da14cebeSEric Cheng 	kcondvar_t		mci_tx_cv;
207da14cebeSEric Cheng 
208da14cebeSEric Cheng 	/* Must be last in the structure for dynamic sizing */
209da14cebeSEric Cheng 	mac_tx_percpu_t		mci_tx_pcpu[1];		/* SL */
210da14cebeSEric Cheng };
211da14cebeSEric Cheng 
212da14cebeSEric Cheng #define	MAC_CLIENT_IMPL_SIZE						\
213da14cebeSEric Cheng 	(sizeof (mac_client_impl_t) +					\
214da14cebeSEric Cheng 	    (mac_tx_percpu_cnt * sizeof (mac_tx_percpu_t)))
215da14cebeSEric Cheng 
216da14cebeSEric Cheng extern	int	mac_tx_percpu_cnt;
217da14cebeSEric Cheng 
218da14cebeSEric Cheng #define	MCIP_TX_SRS(mcip)	\
219da14cebeSEric Cheng 	((mcip)->mci_flent == NULL ? NULL : (mcip)->mci_flent->fe_tx_srs)
220da14cebeSEric Cheng 
221da14cebeSEric Cheng /* Defensive coding, non-null mcip_flent could be an assert */
222da14cebeSEric Cheng 
223da14cebeSEric Cheng #define	MCIP_DATAPATH_SETUP(mcip)		\
224da14cebeSEric Cheng 	((mcip)->mci_flent == NULL ? B_FALSE :	\
225da14cebeSEric Cheng 	!((mcip)->mci_flent->fe_flags & FE_MC_NO_DATAPATH))
226da14cebeSEric Cheng 
227da14cebeSEric Cheng #define	MCIP_RESOURCE_PROPS(mcip)		\
228da14cebeSEric Cheng 	((mcip)->mci_flent == NULL ? NULL :	\
229da14cebeSEric Cheng 	&(mcip)->mci_flent->fe_resource_props)
230da14cebeSEric Cheng 
231da14cebeSEric Cheng #define	MCIP_EFFECTIVE_PROPS(mcip)		\
232da14cebeSEric Cheng 	(mcip->mci_flent == NULL ? NULL :	\
233da14cebeSEric Cheng 	&(mcip)->mci_flent->fe_effective_props)
234da14cebeSEric Cheng 
235da14cebeSEric Cheng #define	MCIP_RESOURCE_PROPS_MASK(mcip)		\
236da14cebeSEric Cheng 	((mcip)->mci_flent == NULL ? 0 :	\
237da14cebeSEric Cheng 	(mcip)->mci_flent->fe_resource_props.mrp_mask)
238da14cebeSEric Cheng 
239da14cebeSEric Cheng #define	MCIP_RESOURCE_PROPS_MAXBW(mcip)		\
240da14cebeSEric Cheng 	((mcip)->mci_flent == NULL ? 0 :	\
241da14cebeSEric Cheng 	(mcip)->mci_flent->fe_resource_props.mrp_maxbw)
242da14cebeSEric Cheng 
243da14cebeSEric Cheng #define	MCIP_RESOURCE_PROPS_PRIORITY(mcip)		\
244da14cebeSEric Cheng 	((mcip)->mci_flent == NULL ? 0 :	\
245da14cebeSEric Cheng 	(mcip)->mci_flent->fe_resource_props.mrp_priority)
246da14cebeSEric Cheng 
247da14cebeSEric Cheng #define	MCIP_RESOURCE_PROPS_CPUS(mcip)		\
248da14cebeSEric Cheng 	((mcip)->mci_flent == NULL ? 0 :	\
249da14cebeSEric Cheng 	&(mcip)->mci_flent->fe_resource_props.mrp_cpus)
250da14cebeSEric Cheng 
251da14cebeSEric Cheng #define	MCIP_RESOURCE_PROPS_NCPUS(mcip)		\
252da14cebeSEric Cheng 	((mcip)->mci_flent == NULL ? 0 :	\
253da14cebeSEric Cheng 	(mcip)->mci_flent->fe_resource_props.mrp_ncpus)
254da14cebeSEric Cheng 
255da14cebeSEric Cheng #define	MCIP_RESOURCE_PROPS_CPU(mcip)		\
256da14cebeSEric Cheng 	((mcip)->mci_flent == NULL ? 0 :	\
257da14cebeSEric Cheng 	(mcip)->mci_flent->fe_resource_props.mrp_ncpu)
258da14cebeSEric Cheng 
259da14cebeSEric Cheng /*
260da14cebeSEric Cheng  * We validate the VLAN id of the packet w.r.t the client's vid,
261da14cebeSEric Cheng  * if required (i.e. !MCIS_DISABLE_TX_VID_CHECK). DLS clients
262da14cebeSEric Cheng  * will have MCIS_DISABLE_TX_VID_CHECK set.
263da14cebeSEric Cheng  * (In the case of aggr when we get back packets, due to
264da14cebeSEric Cheng  * the underlying driver being flow controlled, we won't
265da14cebeSEric Cheng  * drop the packet even if it is VLAN tagged as we
266da14cebeSEric Cheng  * don't set MCIS_DISABLE_TX_VID_CHECK for an aggr.)
267da14cebeSEric Cheng  */
268da14cebeSEric Cheng #define	MAC_VID_CHECK_NEEDED(mcip)					\
269da14cebeSEric Cheng 	(((mcip)->mci_state_flags & MCIS_DISABLE_TX_VID_CHECK) == 0 &&	\
270da14cebeSEric Cheng 	(mcip)->mci_mip->mi_info.mi_nativemedia == DL_ETHER)
271da14cebeSEric Cheng 
272da14cebeSEric Cheng #define	MAC_VID_CHECK(mcip, mp, err) {					\
273da14cebeSEric Cheng 	if (ntohs(((struct ether_header *)(mp)->b_rptr)->ether_type) ==	\
274da14cebeSEric Cheng 	    ETHERTYPE_VLAN) {						\
275da14cebeSEric Cheng 		/*							\
276da14cebeSEric Cheng 		 * err is set to EINVAL (so the caller can take the	\
277da14cebeSEric Cheng 		 * appropriate action. e.g. freemsg()) for two cases:	\
278da14cebeSEric Cheng 		 * -client is not responsible for filling in the vid.	\
279da14cebeSEric Cheng 		 * -client is responsible for filling in the vid, but	\
280da14cebeSEric Cheng 		 *  the vid doesn't match the vid of the MAC client.	\
281da14cebeSEric Cheng 		 */							\
282da14cebeSEric Cheng 		(err) = EINVAL;						\
283da14cebeSEric Cheng 		if (((mcip)->mci_state_flags & MCIS_TAG_DISABLE) != 0) {\
284da14cebeSEric Cheng 			struct ether_vlan_header	*evhp;		\
285da14cebeSEric Cheng 			uint16_t			vlanid;		\
286da14cebeSEric Cheng 									\
287da14cebeSEric Cheng 			evhp = (struct ether_vlan_header *)(mp)->b_rptr;\
288da14cebeSEric Cheng 			vlanid = VLAN_ID(ntohs(evhp->ether_tci));	\
289da14cebeSEric Cheng 			if (mac_client_check_flow_vid((mcip), vlanid))	\
290da14cebeSEric Cheng 				(err) = 0;				\
291da14cebeSEric Cheng 		}							\
292da14cebeSEric Cheng 	}								\
293da14cebeSEric Cheng }
294da14cebeSEric Cheng 
2953bb0cb70SBryan Cantrill /*
2963bb0cb70SBryan Cantrill  * To allow the hot path to not grab any additional locks, we keep a single
2973bb0cb70SBryan Cantrill  * entry VLAN ID cache that caches whether or not a given VID belongs to a
2983bb0cb70SBryan Cantrill  * MAC client.
2993bb0cb70SBryan Cantrill  */
3003bb0cb70SBryan Cantrill #define	MCIP_VIDCACHE_VALIDSHIFT	31
3013bb0cb70SBryan Cantrill #define	MCIP_VIDCACHE_VIDSHIFT		1
3023bb0cb70SBryan Cantrill #define	MCIP_VIDCACHE_VIDMASK		(UINT16_MAX << MCIP_VIDCACHE_VIDSHIFT)
3033bb0cb70SBryan Cantrill #define	MCIP_VIDCACHE_BOOLSHIFT		0
3043bb0cb70SBryan Cantrill 
3053bb0cb70SBryan Cantrill #define	MCIP_VIDCACHE_INVALID		0
3063bb0cb70SBryan Cantrill 
3073bb0cb70SBryan Cantrill #define	MCIP_VIDCACHE_CACHE(vid, bool)	\
3083bb0cb70SBryan Cantrill 	((1U << MCIP_VIDCACHE_VALIDSHIFT) | \
3093bb0cb70SBryan Cantrill 	((vid) << MCIP_VIDCACHE_VIDSHIFT) | \
3103bb0cb70SBryan Cantrill 	((bool) ? (1U << MCIP_VIDCACHE_BOOLSHIFT) : 0))
3113bb0cb70SBryan Cantrill 
3123bb0cb70SBryan Cantrill #define	MCIP_VIDCACHE_ISVALID(v)	((v) & (1U << MCIP_VIDCACHE_VALIDSHIFT))
3133bb0cb70SBryan Cantrill #define	MCIP_VIDCACHE_VID(v)		\
3143bb0cb70SBryan Cantrill 	(((v) & MCIP_VIDCACHE_VIDMASK) >> MCIP_VIDCACHE_VIDSHIFT)
3153bb0cb70SBryan Cantrill #define	MCIP_VIDCACHE_BOOL(v)		((v) & (1U << MCIP_VIDCACHE_BOOLSHIFT))
3163bb0cb70SBryan Cantrill 
317da14cebeSEric Cheng #define	MAC_TAG_NEEDED(mcip)						\
318da14cebeSEric Cheng 	(((mcip)->mci_state_flags & MCIS_TAG_DISABLE) == 0 &&		\
319da14cebeSEric Cheng 	(mcip)->mci_nvids == 1)						\
320da14cebeSEric Cheng 
32184de666eSRyan Zezeski /*
32284de666eSRyan Zezeski  * MAC Client Implementation State (mci_state_flags)
32384de666eSRyan Zezeski  *
32484de666eSRyan Zezeski  * MCIS_IS_VNIC
32584de666eSRyan Zezeski  *
32684de666eSRyan Zezeski  *	The client is a VNIC.
32784de666eSRyan Zezeski  *
32884de666eSRyan Zezeski  * MCIS_EXCLUSIVE
32984de666eSRyan Zezeski  *
33084de666eSRyan Zezeski  *	The client has exclusive control over the MAC, such that it is
33184de666eSRyan Zezeski  *	the sole client of the MAC.
33284de666eSRyan Zezeski  *
33384de666eSRyan Zezeski  * MCIS_TAG_DISABLE
33484de666eSRyan Zezeski  *
33584de666eSRyan Zezeski  *	MAC will not add VLAN tags to outgoing traffic. If this flag
33684de666eSRyan Zezeski  *	is set it is up to the client to add the correct VLAN tag.
33784de666eSRyan Zezeski  *
33884de666eSRyan Zezeski  * MCIS_STRIP_DISABLE
33984de666eSRyan Zezeski  *
34084de666eSRyan Zezeski  *	MAC will not strip the VLAN tags on incoming traffic before
34184de666eSRyan Zezeski  *	passing it to mci_rx_fn. This only applies to non-bypass
34284de666eSRyan Zezeski  *	traffic.
34384de666eSRyan Zezeski  *
34484de666eSRyan Zezeski  * MCIS_IS_AGGR_PORT
34584de666eSRyan Zezeski  *
34684de666eSRyan Zezeski  *	The client represents a port on an aggr.
34784de666eSRyan Zezeski  *
34884de666eSRyan Zezeski  * MCIS_CLIENT_POLL_CAPABLE
34984de666eSRyan Zezeski  *
35084de666eSRyan Zezeski  *	The client is capable of polling the Rx TCP/UDP softrings.
35184de666eSRyan Zezeski  *
35284de666eSRyan Zezeski  * MCIS_DESC_LOGGED
35384de666eSRyan Zezeski  *
35484de666eSRyan Zezeski  *	This flag is set when the client's link info has been logged
35584de666eSRyan Zezeski  *	by the mac_log_linkinfo() timer. This ensures that the
35684de666eSRyan Zezeski  *	client's link info is only logged once.
35784de666eSRyan Zezeski  *
35884de666eSRyan Zezeski  * MCIS_SHARE_BOUND
35984de666eSRyan Zezeski  *
36084de666eSRyan Zezeski  *	This client has an HIO share bound to it.
36184de666eSRyan Zezeski  *
36284de666eSRyan Zezeski  * MCIS_DISABLE_TX_VID_CHECK
36384de666eSRyan Zezeski  *
36484de666eSRyan Zezeski  *	MAC will not check the VID of the client's Tx traffic.
36584de666eSRyan Zezeski  *
36684de666eSRyan Zezeski  * MCIS_USE_DATALINK_NAME
36784de666eSRyan Zezeski  *
36884de666eSRyan Zezeski  *	The client is using the same name as its underlying MAC. This
36984de666eSRyan Zezeski  *	happens when dlmgmtd is unreachable during client creation.
37084de666eSRyan Zezeski  *
37184de666eSRyan Zezeski  * MCIS_UNICAST_HW
37284de666eSRyan Zezeski  *
37384de666eSRyan Zezeski  *	The client requires MAC address hardware classification. This
37484de666eSRyan Zezeski  *	is only used by sun4v vsw.
37584de666eSRyan Zezeski  *
37684de666eSRyan Zezeski  * MCIS_IS_AGGR_CLIENT
37784de666eSRyan Zezeski  *
37884de666eSRyan Zezeski  *	The client sits atop an aggr.
37984de666eSRyan Zezeski  *
38084de666eSRyan Zezeski  * MCIS_RX_BYPASS_DISABLE
38184de666eSRyan Zezeski  *
38284de666eSRyan Zezeski  *	Do not allow the client to enable DLS bypass.
38384de666eSRyan Zezeski  *
38484de666eSRyan Zezeski  * MCIS_NO_UNICAST_ADDR
38584de666eSRyan Zezeski  *
38684de666eSRyan Zezeski  *	This client has no MAC unicast addresss associated with it.
38784de666eSRyan Zezeski  *
38884de666eSRyan Zezeski  */
389da14cebeSEric Cheng /* MCI state flags */
390da14cebeSEric Cheng #define	MCIS_IS_VNIC			0x0001
391da14cebeSEric Cheng #define	MCIS_EXCLUSIVE			0x0002
392da14cebeSEric Cheng #define	MCIS_TAG_DISABLE		0x0004
393da14cebeSEric Cheng #define	MCIS_STRIP_DISABLE		0x0008
394da14cebeSEric Cheng #define	MCIS_IS_AGGR_PORT		0x0010
395da14cebeSEric Cheng #define	MCIS_CLIENT_POLL_CAPABLE	0x0020
396da14cebeSEric Cheng #define	MCIS_DESC_LOGGED		0x0040
397da14cebeSEric Cheng #define	MCIS_SHARE_BOUND		0x0080
3980dc2366fSVenugopal Iyer #define	MCIS_DISABLE_TX_VID_CHECK	0x0100
3990dc2366fSVenugopal Iyer #define	MCIS_USE_DATALINK_NAME		0x0200
4000dc2366fSVenugopal Iyer #define	MCIS_UNICAST_HW			0x0400
40184de666eSRyan Zezeski #define	MCIS_IS_AGGR_CLIENT		0x0800
4020dc2366fSVenugopal Iyer #define	MCIS_RX_BYPASS_DISABLE		0x1000
4030dc2366fSVenugopal Iyer #define	MCIS_NO_UNICAST_ADDR		0x2000
4040dc2366fSVenugopal Iyer 
4050dc2366fSVenugopal Iyer /* Mac protection flags */
4060dc2366fSVenugopal Iyer #define	MPT_FLAG_V6_LOCAL_ADDR_SET	0x0001
40710a40492SRobert Mustacchi #define	MPT_FLAG_PROMISC_FILTERED	0x0002
408da14cebeSEric Cheng 
409da14cebeSEric Cheng /* in mac_client.c */
410da14cebeSEric Cheng extern void mac_promisc_client_dispatch(mac_client_impl_t *, mblk_t *);
411da14cebeSEric Cheng extern void mac_client_init(void);
412da14cebeSEric Cheng extern void mac_client_fini(void);
413*c61a1653SRyan Zezeski extern void mac_promisc_dispatch(mac_impl_t *, mblk_t *, mac_client_impl_t *,
414*c61a1653SRyan Zezeski     boolean_t);
415da14cebeSEric Cheng 
4160dc2366fSVenugopal Iyer extern int mac_validate_props(mac_impl_t *, mac_resource_props_t *);
417da14cebeSEric Cheng 
418da14cebeSEric Cheng extern mac_client_impl_t *mac_vnic_lower(mac_impl_t *);
419da14cebeSEric Cheng extern mac_client_impl_t *mac_primary_client_handle(mac_impl_t *);
420da14cebeSEric Cheng extern uint16_t i_mac_flow_vid(flow_entry_t *);
421da14cebeSEric Cheng extern boolean_t i_mac_capab_get(mac_handle_t, mac_capab_t, void *);
422da14cebeSEric Cheng 
423da14cebeSEric Cheng extern void mac_unicast_update_clients(mac_impl_t *, mac_address_t *);
424da14cebeSEric Cheng extern void mac_update_resources(mac_resource_props_t *,
425da14cebeSEric Cheng     mac_resource_props_t *, boolean_t);
426da14cebeSEric Cheng 
427da14cebeSEric Cheng boolean_t mac_client_check_flow_vid(mac_client_impl_t *, uint16_t);
428da14cebeSEric Cheng 
429da14cebeSEric Cheng extern boolean_t mac_is_primary_client(mac_client_impl_t *);
430da14cebeSEric Cheng 
4310dc2366fSVenugopal Iyer extern int mac_client_set_rings_prop(mac_client_impl_t *,
4320dc2366fSVenugopal Iyer     mac_resource_props_t *, mac_resource_props_t *);
4330dc2366fSVenugopal Iyer extern void mac_set_prim_vlan_rings(mac_impl_t *, mac_resource_props_t *);
4340dc2366fSVenugopal Iyer 
435da14cebeSEric Cheng #ifdef	__cplusplus
436da14cebeSEric Cheng }
437da14cebeSEric Cheng #endif
438da14cebeSEric Cheng 
439da14cebeSEric Cheng #endif	/* _SYS_MAC_CLIENT_IMPL_H */
440