xref: /illumos-gate/usr/src/uts/common/sys/mac_impl.h (revision 36589d6b)
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
5490ed22dSyz147064  * Common Development and Distribution License (the "License").
6490ed22dSyz147064  * 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 /*
220591ddd0SPrakash Jalan  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23b237158dSPatrick Mooney  * Copyright 2019 Joyent, Inc.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_SYS_MAC_IMPL_H
277c478bd9Sstevel@tonic-gate #define	_SYS_MAC_IMPL_H
287c478bd9Sstevel@tonic-gate 
290dc2366fSVenugopal Iyer #include <sys/cpupart.h>
30da14cebeSEric Cheng #include <sys/modhash.h>
31da14cebeSEric Cheng #include <sys/mac_client.h>
32da14cebeSEric Cheng #include <sys/mac_provider.h>
334eaa4710SRishi Srivatsavai #include <sys/note.h>
340dc2366fSVenugopal Iyer #include <sys/avl.h>
35ba2e4443Sseb #include <net/if.h>
36da14cebeSEric Cheng #include <sys/mac_flow_impl.h>
37da14cebeSEric Cheng #include <netinet/ip6.h>
38c61a1653SRyan Zezeski #include <sys/pattr.h>
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
417c478bd9Sstevel@tonic-gate extern "C" {
427c478bd9Sstevel@tonic-gate #endif
437c478bd9Sstevel@tonic-gate 
4461af1958SGarrett D'Amore /*
4561af1958SGarrett D'Amore  * This is the first minor number available for MAC provider private
4661af1958SGarrett D'Amore  * use.  This makes it possible to deliver a driver that is both a MAC
4761af1958SGarrett D'Amore  * provider and a regular character/block device.  See PSARC 2009/380
4861af1958SGarrett D'Amore  * for more detail about the construction of such devices.  The value
4961af1958SGarrett D'Amore  * chosen leaves half of the 32-bit minor numbers (which are really
5061af1958SGarrett D'Amore  * only 18 bits wide) available for driver private use.  Drivers can
5161af1958SGarrett D'Amore  * easily identify their private number by the presence of this value
5261af1958SGarrett D'Amore  * in the bits that make up the minor number, since its just the
5361af1958SGarrett D'Amore  * highest bit available for such minor numbers.
5461af1958SGarrett D'Amore  */
5561af1958SGarrett D'Amore #define	MAC_PRIVATE_MINOR		((MAXMIN32 + 1) / 2)
5661af1958SGarrett D'Amore 
5761af1958SGarrett D'Amore /*
5861af1958SGarrett D'Amore  * The maximum minor number that corresponds to a real instance.  This
5961af1958SGarrett D'Amore  * limits the number of physical ports that a mac provider can offer.
6061af1958SGarrett D'Amore  * Note that this macro must be synchronized with DLS_MAX_MINOR in
6161af1958SGarrett D'Amore  * <sys/dls.h>
6261af1958SGarrett D'Amore  */
6361af1958SGarrett D'Amore #define	MAC_MAX_MINOR			1000
6461af1958SGarrett D'Amore 
65d62bc4baSyz147064 typedef struct mac_margin_req_s	mac_margin_req_t;
66d62bc4baSyz147064 
67d62bc4baSyz147064 struct mac_margin_req_s {
68d62bc4baSyz147064 	mac_margin_req_t	*mmr_nextp;
69d62bc4baSyz147064 	uint_t			mmr_ref;
70d62bc4baSyz147064 	uint32_t		mmr_margin;
71d62bc4baSyz147064 };
72d62bc4baSyz147064 
73a776d98eSRobert Mustacchi typedef struct mac_mtu_req_s mac_mtu_req_t;
74a776d98eSRobert Mustacchi struct mac_mtu_req_s {
75a776d98eSRobert Mustacchi 	mac_mtu_req_t		*mtr_nextp;
76a776d98eSRobert Mustacchi 	uint_t			mtr_ref;
77a776d98eSRobert Mustacchi 	uint32_t		mtr_mtu;
78a776d98eSRobert Mustacchi };
79a776d98eSRobert Mustacchi 
80da14cebeSEric Cheng /* Generic linked chain type */
81da14cebeSEric Cheng typedef	struct mac_chain_s {
82da14cebeSEric Cheng 	struct mac_chain_s	*next;
83da14cebeSEric Cheng 	void			*item;
84da14cebeSEric Cheng } mac_chain_t;
857c478bd9Sstevel@tonic-gate 
86da14cebeSEric Cheng /*
87da14cebeSEric Cheng  * Generic mac callback list manipulation structures and macros. The mac_cb_t
88da14cebeSEric Cheng  * represents a general callback list element embedded in a particular
89da14cebeSEric Cheng  * data structure such as a mac_notify_cb_t or a mac_promisc_impl_t.
90da14cebeSEric Cheng  * The mac_cb_info_t represents general information about list walkers.
91da14cebeSEric Cheng  * Please see the comments above mac_callback_add for more information.
92da14cebeSEric Cheng  */
93da14cebeSEric Cheng /* mcb_flags */
94da14cebeSEric Cheng #define	MCB_CONDEMNED		0x1		/* Logically deleted */
95da14cebeSEric Cheng #define	MCB_NOTIFY_CB_T		0x2
96da14cebeSEric Cheng #define	MCB_TX_NOTIFY_CB_T	0x4
977c478bd9Sstevel@tonic-gate 
980dc2366fSVenugopal Iyer extern boolean_t	mac_tx_serialize;
990dc2366fSVenugopal Iyer 
100da14cebeSEric Cheng typedef struct mac_cb_s {
101da14cebeSEric Cheng 	struct mac_cb_s		*mcb_nextp;	/* Linked list of callbacks */
102da14cebeSEric Cheng 	void			*mcb_objp;	/* Ptr to enclosing object  */
103da14cebeSEric Cheng 	size_t			mcb_objsize;	/* Sizeof the enclosing obj */
104da14cebeSEric Cheng 	uint_t			mcb_flags;
105da14cebeSEric Cheng } mac_cb_t;
1067c478bd9Sstevel@tonic-gate 
107da14cebeSEric Cheng typedef struct mac_cb_info_s {
108da14cebeSEric Cheng 	kmutex_t	*mcbi_lockp;
109da14cebeSEric Cheng 	kcondvar_t	mcbi_cv;
110da14cebeSEric Cheng 	uint_t		mcbi_del_cnt;		/* Deleted callback cnt */
111da14cebeSEric Cheng 	uint_t		mcbi_walker_cnt;	/* List walker count */
112b237158dSPatrick Mooney 	uint_t		mcbi_barrier_cnt;	/* Barrier waiter count */
113da14cebeSEric Cheng } mac_cb_info_t;
1147c478bd9Sstevel@tonic-gate 
115da14cebeSEric Cheng typedef struct mac_notify_cb_s {
116da14cebeSEric Cheng 	mac_cb_t	mncb_link;		/* Linked list of callbacks */
117da14cebeSEric Cheng 	mac_notify_t	mncb_fn;		/* callback function */
118da14cebeSEric Cheng 	void		*mncb_arg;		/* callback argument */
119da14cebeSEric Cheng 	struct mac_impl_s *mncb_mip;
120da14cebeSEric Cheng } mac_notify_cb_t;
1217c478bd9Sstevel@tonic-gate 
122da14cebeSEric Cheng /*
123da14cebeSEric Cheng  * mac_callback_add(listinfo, listhead, listelement)
124da14cebeSEric Cheng  * mac_callback_remove(listinfo, listhead, listelement)
125da14cebeSEric Cheng  */
126da14cebeSEric Cheng typedef boolean_t (*mcb_func_t)(mac_cb_info_t *, mac_cb_t **, mac_cb_t *);
127da14cebeSEric Cheng 
128b237158dSPatrick Mooney #define	MAC_CALLBACK_WALKER_INC(mcbi) \
129b237158dSPatrick Mooney 	mac_callback_walker_enter(mcbi)
130da14cebeSEric Cheng 
131b237158dSPatrick Mooney #define	MAC_CALLBACK_WALKER_DCR(mcbi, headp) \
132b237158dSPatrick Mooney 	mac_callback_walker_exit(mcbi, headp, B_FALSE)
133da14cebeSEric Cheng 
134da14cebeSEric Cheng #define	MAC_PROMISC_WALKER_INC(mip) \
135b237158dSPatrick Mooney 	mac_callback_walker_enter(&(mip)->mi_promisc_cb_info)
136da14cebeSEric Cheng 
137b237158dSPatrick Mooney #define	MAC_PROMISC_WALKER_DCR(mip) \
138b237158dSPatrick Mooney 	mac_callback_walker_exit(&(mip)->mi_promisc_cb_info, \
139b237158dSPatrick Mooney 	    &(mip)->mi_promisc_list, B_TRUE)
1407c478bd9Sstevel@tonic-gate 
141ba2e4443Sseb typedef struct mactype_s {
142ba2e4443Sseb 	const char	*mt_ident;
143ba2e4443Sseb 	uint32_t	mt_ref;
144ba2e4443Sseb 	uint_t		mt_type;
1450ba2cbe9Sxc151355 	uint_t		mt_nativetype;
146ba2e4443Sseb 	size_t		mt_addr_length;
147ba2e4443Sseb 	uint8_t		*mt_brdcst_addr;
148ba2e4443Sseb 	mactype_ops_t	mt_ops;
149ba2e4443Sseb 	mac_stat_info_t	*mt_stats;	/* array of mac_stat_info_t elements */
150ba2e4443Sseb 	size_t		mt_statcount;	/* number of elements in mt_stats */
1514045d941Ssowmini 	mac_ndd_mapping_t *mt_mapping;
1524045d941Ssowmini 	size_t		mt_mappingcount;
153ba2e4443Sseb } mactype_t;
1547c478bd9Sstevel@tonic-gate 
155da14cebeSEric Cheng /*
156da14cebeSEric Cheng  * Multiple rings implementation.
157da14cebeSEric Cheng  */
158da14cebeSEric Cheng typedef	enum {
159da14cebeSEric Cheng 	MAC_GROUP_STATE_UNINIT	= 0,	/* initial state of data structure */
160da14cebeSEric Cheng 	MAC_GROUP_STATE_REGISTERED,	/* hooked with h/w group */
161da14cebeSEric Cheng 	MAC_GROUP_STATE_RESERVED,	/* group is reserved and opened */
162da14cebeSEric Cheng 	MAC_GROUP_STATE_SHARED		/* default group shared among */
163da14cebeSEric Cheng 					/* multiple mac clients */
164da14cebeSEric Cheng } mac_group_state_t;
165843e1988Sjohnlev 
166da14cebeSEric Cheng typedef	struct mac_ring_s mac_ring_t;
167da14cebeSEric Cheng typedef	struct mac_group_s mac_group_t;
1684045d941Ssowmini 
169ba2e4443Sseb /*
170da14cebeSEric Cheng  * Ring data structure for ring control and management.
171ba2e4443Sseb  */
172da14cebeSEric Cheng typedef enum {
173da14cebeSEric Cheng 	MR_FREE,		/* Available for assignment to flows */
174da14cebeSEric Cheng 	MR_NEWLY_ADDED,		/* Just assigned to another group */
175da14cebeSEric Cheng 	MR_INUSE		/* Assigned to an SRS */
176da14cebeSEric Cheng } mac_ring_state_t;
177da14cebeSEric Cheng 
178da14cebeSEric Cheng /* mr_flag values */
179da14cebeSEric Cheng #define	MR_INCIPIENT	0x1
180da14cebeSEric Cheng #define	MR_CONDEMNED	0x2
181da14cebeSEric Cheng #define	MR_QUIESCE	0x4
182da14cebeSEric Cheng 
1830dc2366fSVenugopal Iyer typedef struct mac_impl_s mac_impl_t;
1840dc2366fSVenugopal Iyer 
185da14cebeSEric Cheng struct mac_ring_s {
186da14cebeSEric Cheng 	int			mr_index;	/* index in the original list */
187da14cebeSEric Cheng 	mac_ring_type_t		mr_type;	/* ring type */
188da14cebeSEric Cheng 	mac_ring_t		*mr_next;	/* next ring in the chain */
189da14cebeSEric Cheng 	mac_group_handle_t	mr_gh;		/* reference to group */
190da14cebeSEric Cheng 
19145948e49SRyan Zezeski 	mac_classify_type_t	mr_classify_type;
192da14cebeSEric Cheng 	struct mac_soft_ring_set_s *mr_srs;	/* associated SRS */
1930dc2366fSVenugopal Iyer 	mac_ring_handle_t	mr_prh;	/* associated pseudo ring hdl */
19445948e49SRyan Zezeski 
19545948e49SRyan Zezeski 	/*
19645948e49SRyan Zezeski 	 * Ring passthru callback and arguments. See the
19745948e49SRyan Zezeski 	 * MAC_PASSTHRU_CLASSIFIER comment in mac_provider.h.
19845948e49SRyan Zezeski 	 */
19945948e49SRyan Zezeski 	mac_rx_t		mr_pt_fn;
20045948e49SRyan Zezeski 	void			*mr_pt_arg1;
20145948e49SRyan Zezeski 	mac_resource_handle_t	mr_pt_arg2;
20245948e49SRyan Zezeski 
203da14cebeSEric Cheng 	uint_t			mr_refcnt;	/* Ring references */
204da14cebeSEric Cheng 	/* ring generation no. to guard against drivers using stale rings */
205da14cebeSEric Cheng 	uint64_t		mr_gen_num;
206da14cebeSEric Cheng 
2070dc2366fSVenugopal Iyer 	kstat_t			*mr_ksp;	/* ring kstats */
2080dc2366fSVenugopal Iyer 	mac_impl_t		*mr_mip;	/* pointer to primary's mip */
2090dc2366fSVenugopal Iyer 
210da14cebeSEric Cheng 	kmutex_t		mr_lock;
211da14cebeSEric Cheng 	kcondvar_t		mr_cv;			/* mr_lock */
212da14cebeSEric Cheng 	mac_ring_state_t	mr_state;		/* mr_lock */
213da14cebeSEric Cheng 	uint_t			mr_flag;		/* mr_lock */
214da14cebeSEric Cheng 
215da14cebeSEric Cheng 	mac_ring_info_t		mr_info;	/* driver supplied info */
216da14cebeSEric Cheng };
217da14cebeSEric Cheng #define	mr_driver		mr_info.mri_driver
218da14cebeSEric Cheng #define	mr_start		mr_info.mri_start
219da14cebeSEric Cheng #define	mr_stop			mr_info.mri_stop
2200dc2366fSVenugopal Iyer #define	mr_stat			mr_info.mri_stat
221da14cebeSEric Cheng 
222da14cebeSEric Cheng #define	MAC_RING_MARK(mr, flag)		\
223da14cebeSEric Cheng 	(mr)->mr_flag |= flag;
224da14cebeSEric Cheng 
225da14cebeSEric Cheng #define	MAC_RING_UNMARK(mr, flag)	\
226da14cebeSEric Cheng 	(mr)->mr_flag &= ~flag;
227da14cebeSEric Cheng 
228d62bc4baSyz147064 /*
229da14cebeSEric Cheng  * Reference hold and release on mac_ring_t 'mr'
230d62bc4baSyz147064  */
231da14cebeSEric Cheng #define	MR_REFHOLD_LOCKED(mr)		{		\
232da14cebeSEric Cheng 	ASSERT(MUTEX_HELD(&mr->mr_lock));		\
233da14cebeSEric Cheng 	(mr)->mr_refcnt++;				\
234da14cebeSEric Cheng }
235d62bc4baSyz147064 
236da14cebeSEric Cheng #define	MR_REFRELE(mr)		{			\
237da14cebeSEric Cheng 	mutex_enter(&(mr)->mr_lock);			\
238da14cebeSEric Cheng 	ASSERT((mr)->mr_refcnt != 0);			\
239da14cebeSEric Cheng 	(mr)->mr_refcnt--;				\
240da14cebeSEric Cheng 	if ((mr)->mr_refcnt == 0 &&			\
241da14cebeSEric Cheng 	    ((mr)->mr_flag & (MR_CONDEMNED | MR_QUIESCE))) \
242da14cebeSEric Cheng 		cv_signal(&(mr)->mr_cv);		\
243da14cebeSEric Cheng 	mutex_exit(&(mr)->mr_lock);			\
244da14cebeSEric Cheng }
245d62bc4baSyz147064 
246da14cebeSEric Cheng /*
24784de666eSRyan Zezeski  * Used to attach MAC clients to an Rx group. The members are SL
24884de666eSRyan Zezeski  * protected.
249da14cebeSEric Cheng  */
250da14cebeSEric Cheng typedef struct mac_grp_client {
251da14cebeSEric Cheng 	struct mac_grp_client		*mgc_next;
252da14cebeSEric Cheng 	struct mac_client_impl_s	*mgc_client;
253da14cebeSEric Cheng } mac_grp_client_t;
254d62bc4baSyz147064 
2550dc2366fSVenugopal Iyer #define	MAC_GROUP_NO_CLIENT(g)	((g)->mrg_clients == NULL)
256d62bc4baSyz147064 
2570dc2366fSVenugopal Iyer #define	MAC_GROUP_ONLY_CLIENT(g)			\
258da14cebeSEric Cheng 	((((g)->mrg_clients != NULL) &&			\
259da14cebeSEric Cheng 	((g)->mrg_clients->mgc_next == NULL)) ?		\
260da14cebeSEric Cheng 	(g)->mrg_clients->mgc_client : NULL)
261d62bc4baSyz147064 
26284de666eSRyan Zezeski #define	MAC_GROUP_HW_VLAN(g)				\
26384de666eSRyan Zezeski 	(((g) != NULL) &&				\
26484de666eSRyan Zezeski 	((g)->mrg_info.mgi_addvlan != NULL) &&		\
26584de666eSRyan Zezeski 	((g)->mrg_info.mgi_remvlan != NULL))
26684de666eSRyan Zezeski 
267da14cebeSEric Cheng /*
268da14cebeSEric Cheng  * Common ring group data structure for ring control and management.
26984de666eSRyan Zezeski  * The entire structure is SL protected.
270da14cebeSEric Cheng  */
271da14cebeSEric Cheng struct mac_group_s {
272da14cebeSEric Cheng 	int			mrg_index;	/* index in the list */
273da14cebeSEric Cheng 	mac_ring_type_t		mrg_type;	/* ring type */
274da14cebeSEric Cheng 	mac_group_state_t	mrg_state;	/* state of the group */
27584de666eSRyan Zezeski 	mac_group_t		*mrg_next;	/* next group in the chain */
276da14cebeSEric Cheng 	mac_handle_t		mrg_mh;		/* reference to MAC */
277da14cebeSEric Cheng 	mac_ring_t		*mrg_rings;	/* grouped rings */
278da14cebeSEric Cheng 	uint_t			mrg_cur_count;	/* actual size of group */
279d62bc4baSyz147064 
280da14cebeSEric Cheng 	mac_grp_client_t	*mrg_clients;	/* clients list */
281d62bc4baSyz147064 
282da14cebeSEric Cheng 	mac_group_info_t	mrg_info;	/* driver supplied info */
283da14cebeSEric Cheng };
284d62bc4baSyz147064 
285da14cebeSEric Cheng #define	mrg_driver		mrg_info.mgi_driver
286da14cebeSEric Cheng #define	mrg_start		mrg_info.mgi_start
287da14cebeSEric Cheng #define	mrg_stop		mrg_info.mgi_stop
288da14cebeSEric Cheng 
289da14cebeSEric Cheng #define	GROUP_INTR_HANDLE(g)		(g)->mrg_info.mgi_intr.mi_handle
290da14cebeSEric Cheng #define	GROUP_INTR_ENABLE_FUNC(g)	(g)->mrg_info.mgi_intr.mi_enable
291da14cebeSEric Cheng #define	GROUP_INTR_DISABLE_FUNC(g)	(g)->mrg_info.mgi_intr.mi_disable
292da14cebeSEric Cheng 
293da14cebeSEric Cheng /* mci_tx_flag */
294da14cebeSEric Cheng #define	MCI_TX_QUIESCE	0x1
295da14cebeSEric Cheng 
296da14cebeSEric Cheng typedef struct mac_factory_addr_s {
297da14cebeSEric Cheng 	boolean_t		mfa_in_use;
298da14cebeSEric Cheng 	uint8_t			mfa_addr[MAXMACADDRLEN];
299da14cebeSEric Cheng 	struct mac_client_impl_s	*mfa_client;
300da14cebeSEric Cheng } mac_factory_addr_t;
301da14cebeSEric Cheng 
302da14cebeSEric Cheng typedef struct mac_mcast_addrs_s {
303da14cebeSEric Cheng 	struct mac_mcast_addrs_s	*mma_next;
304da14cebeSEric Cheng 	uint8_t				mma_addr[MAXMACADDRLEN];
305da14cebeSEric Cheng 	int				mma_ref;
306da14cebeSEric Cheng } mac_mcast_addrs_t;
307da14cebeSEric Cheng 
308da14cebeSEric Cheng typedef enum {
30984de666eSRyan Zezeski 	MAC_ADDRESS_TYPE_UNICAST_CLASSIFIED = 1,	/* HW classification */
310da14cebeSEric Cheng 	MAC_ADDRESS_TYPE_UNICAST_PROMISC		/* promiscuous mode */
311da14cebeSEric Cheng } mac_address_type_t;
312da14cebeSEric Cheng 
31384de666eSRyan Zezeski typedef struct mac_vlan_s {
31484de666eSRyan Zezeski 	struct mac_vlan_s	*mv_next;
31584de666eSRyan Zezeski 	uint16_t		mv_vid;
31684de666eSRyan Zezeski } mac_vlan_t;
31784de666eSRyan Zezeski 
318da14cebeSEric Cheng typedef struct mac_address_s {
319da14cebeSEric Cheng 	mac_address_type_t	ma_type;		/* address type */
32084de666eSRyan Zezeski 	int			ma_nusers;		/* num users of addr */
321da14cebeSEric Cheng 	struct mac_address_s	*ma_next;		/* next address */
322da14cebeSEric Cheng 	uint8_t			ma_addr[MAXMACADDRLEN];	/* address value */
323da14cebeSEric Cheng 	size_t			ma_len;			/* address length */
32484de666eSRyan Zezeski 	mac_vlan_t		*ma_vlans;		/* VLANs on this addr */
32584de666eSRyan Zezeski 	boolean_t		ma_untagged;		/* accept untagged? */
326da14cebeSEric Cheng 	mac_group_t		*ma_group;		/* asscociated group */
327da14cebeSEric Cheng 	mac_impl_t		*ma_mip;		/* MAC handle */
328da14cebeSEric Cheng } mac_address_t;
329da14cebeSEric Cheng 
330da14cebeSEric Cheng extern krwlock_t i_mac_impl_lock;
331da14cebeSEric Cheng extern mod_hash_t *i_mac_impl_hash;
332da14cebeSEric Cheng extern kmem_cache_t *i_mac_impl_cachep;
333da14cebeSEric Cheng extern uint_t i_mac_impl_count;
334da14cebeSEric Cheng 
335da14cebeSEric Cheng /*
336da14cebeSEric Cheng  * Each registered MAC is associated with a mac_impl_t structure. The
337da14cebeSEric Cheng  * structure represents the undelying hardware, in terms of definition,
338da14cebeSEric Cheng  * resources (transmit, receive rings etc.), callback functions etc. It
339da14cebeSEric Cheng  * also holds the table of MAC clients that are configured on the device.
340da14cebeSEric Cheng  * The table is used for classifying incoming packets in software.
341da14cebeSEric Cheng  *
342da14cebeSEric Cheng  * The protection scheme uses 2 elements, a coarse serialization mechanism
343da14cebeSEric Cheng  * called perimeter and a finer traditional lock based scheme. More details
344da14cebeSEric Cheng  * can be found in the big block comment in mac.c.
345da14cebeSEric Cheng  *
346da14cebeSEric Cheng  * The protection scheme for each member of the mac_impl_t is described below.
347da14cebeSEric Cheng  *
348da14cebeSEric Cheng  * Write Once Only (WO): Typically these don't change for the lifetime of the
349da14cebeSEric Cheng  * data structure. For example something in mac_impl_t that stays the same
350da14cebeSEric Cheng  * from mac_register to mac_unregister, or something in a mac_client_impl_t
351da14cebeSEric Cheng  * that stays the same from mac_client_open to mac_client_close.
352da14cebeSEric Cheng  *
353da14cebeSEric Cheng  * Serializer (SL): Protected by the Serializer. All SLOP operations on a
354da14cebeSEric Cheng  * mac endpoint go through the serializer. MTOPs don't care about reading
355da14cebeSEric Cheng  * these fields atomically.
356da14cebeSEric Cheng  *
357da14cebeSEric Cheng  * Lock: Traditional mutex/rw lock. Modify operations still go through the
358da14cebeSEric Cheng  * mac serializer, the lock helps synchronize readers with writers.
359da14cebeSEric Cheng  */
360da14cebeSEric Cheng struct mac_impl_s {
361da14cebeSEric Cheng 	krwlock_t		mi_rw_lock;
362c228408bSMichael Lim 	list_node_t		mi_node;
363da14cebeSEric Cheng 	char			mi_name[LIFNAMSIZ];	/* WO */
364da14cebeSEric Cheng 	uint32_t		mi_state_flags;
365da14cebeSEric Cheng 	void			*mi_driver;		/* Driver private, WO */
366da14cebeSEric Cheng 	mac_info_t		mi_info;		/* WO */
367da14cebeSEric Cheng 	mactype_t		*mi_type;		/* WO */
368da14cebeSEric Cheng 	void			*mi_pdata;		/* WO */
369da14cebeSEric Cheng 	size_t			mi_pdata_size;		/* WO */
370da14cebeSEric Cheng 	mac_callbacks_t		*mi_callbacks;		/* WO */
371da14cebeSEric Cheng 	dev_info_t		*mi_dip;		/* WO */
372da14cebeSEric Cheng 	uint32_t		mi_ref;			/* i_mac_impl_lock */
373da14cebeSEric Cheng 	uint_t			mi_active;		/* SL */
374da14cebeSEric Cheng 	link_state_t		mi_linkstate;		/* none */
3754eaa4710SRishi Srivatsavai 	link_state_t		mi_lowlinkstate;	/* none */
3764eaa4710SRishi Srivatsavai 	link_state_t		mi_lastlowlinkstate;	/* none */
377da14cebeSEric Cheng 	uint_t			mi_devpromisc;		/* SL */
378da14cebeSEric Cheng 	uint8_t			mi_addr[MAXMACADDRLEN];	/* mi_rw_lock */
379da14cebeSEric Cheng 	uint8_t			mi_dstaddr[MAXMACADDRLEN]; /* mi_rw_lock */
3802b24ab6bSSebastien Roy 	boolean_t		mi_dstaddr_set;
381d62bc4baSyz147064 
382da14cebeSEric Cheng 	/*
383da14cebeSEric Cheng 	 * The mac perimeter. All client initiated create/modify operations
384da14cebeSEric Cheng 	 * on a mac end point go through this.
385da14cebeSEric Cheng 	 */
386da14cebeSEric Cheng 	kmutex_t		mi_perim_lock;
387da14cebeSEric Cheng 	kthread_t		*mi_perim_owner;	/* mi_perim_lock */
388da14cebeSEric Cheng 	uint_t			mi_perim_ocnt;		/* mi_perim_lock */
389da14cebeSEric Cheng 	kcondvar_t		mi_perim_cv;		/* mi_perim_lock */
390d62bc4baSyz147064 
391da14cebeSEric Cheng 	/* mac notification callbacks */
392da14cebeSEric Cheng 	kmutex_t		mi_notify_lock;
393da14cebeSEric Cheng 	mac_cb_info_t		mi_notify_cb_info;	/* mi_notify_lock */
394da14cebeSEric Cheng 	mac_cb_t		*mi_notify_cb_list;	/* mi_notify_lock */
395da14cebeSEric Cheng 	kthread_t		*mi_notify_thread;	/* mi_notify_lock */
396da14cebeSEric Cheng 	uint_t			mi_notify_bits;		/* mi_notify_lock */
397da14cebeSEric Cheng 
398da14cebeSEric Cheng 	uint32_t		mi_v12n_level;		/* Virt'ion readiness */
399da14cebeSEric Cheng 
400da14cebeSEric Cheng 	/*
401da14cebeSEric Cheng 	 * RX groups, ring capability
402da14cebeSEric Cheng 	 * Fields of this block are SL protected.
403da14cebeSEric Cheng 	 */
404da14cebeSEric Cheng 	mac_group_type_t	mi_rx_group_type;	/* grouping type */
405da14cebeSEric Cheng 	uint_t			mi_rx_group_count;
406da14cebeSEric Cheng 	mac_group_t		*mi_rx_groups;
4070dc2366fSVenugopal Iyer 	mac_group_t		*mi_rx_donor_grp;
4080dc2366fSVenugopal Iyer 	uint_t			mi_rxrings_rsvd;
4090dc2366fSVenugopal Iyer 	uint_t			mi_rxrings_avail;
4100dc2366fSVenugopal Iyer 	uint_t			mi_rxhwclnt_avail;
4110dc2366fSVenugopal Iyer 	uint_t			mi_rxhwclnt_used;
412da14cebeSEric Cheng 
413da14cebeSEric Cheng 	mac_capab_rings_t	mi_rx_rings_cap;
414da14cebeSEric Cheng 
415da14cebeSEric Cheng 	/*
416da14cebeSEric Cheng 	 * TX groups and ring capability, SL Protected.
417da14cebeSEric Cheng 	 */
418da14cebeSEric Cheng 	mac_group_type_t	mi_tx_group_type;	/* grouping type */
419da14cebeSEric Cheng 	uint_t			mi_tx_group_count;
420da14cebeSEric Cheng 	uint_t			mi_tx_group_free;
421da14cebeSEric Cheng 	mac_group_t		*mi_tx_groups;
422da14cebeSEric Cheng 	mac_capab_rings_t	mi_tx_rings_cap;
4230dc2366fSVenugopal Iyer 	uint_t			mi_txrings_rsvd;
4240dc2366fSVenugopal Iyer 	uint_t			mi_txrings_avail;
4250dc2366fSVenugopal Iyer 	uint_t			mi_txhwclnt_avail;
4260dc2366fSVenugopal Iyer 	uint_t			mi_txhwclnt_used;
427da14cebeSEric Cheng 
428da14cebeSEric Cheng 	mac_ring_handle_t	mi_default_tx_ring;
429da14cebeSEric Cheng 
430da14cebeSEric Cheng 	/*
43145d3dd98SRobert Mustacchi 	 * Transceiver capabilities. SL protected.
43245d3dd98SRobert Mustacchi 	 */
43345d3dd98SRobert Mustacchi 	mac_capab_transceiver_t	mi_transceiver;
43445d3dd98SRobert Mustacchi 
43545d3dd98SRobert Mustacchi 	/*
436c1e9c696SRobert Mustacchi 	 * LED Capability information. SL protected.
437c1e9c696SRobert Mustacchi 	 */
438c1e9c696SRobert Mustacchi 	mac_led_mode_t		mi_led_modes;
439c1e9c696SRobert Mustacchi 	mac_capab_led_t		mi_led;
440c1e9c696SRobert Mustacchi 
441c61a1653SRyan Zezeski 	/* Cache of the Tx DB_CKSUMFLAGS that this MAC supports. */
442c61a1653SRyan Zezeski 	uint16_t		mi_tx_cksum_flags; /* SL */
443c61a1653SRyan Zezeski 
444c1e9c696SRobert Mustacchi 	/*
44584de666eSRyan Zezeski 	 * MAC address and VLAN lists. SL protected.
446da14cebeSEric Cheng 	 */
447da14cebeSEric Cheng 	mac_address_t		*mi_addresses;
448da14cebeSEric Cheng 
449da14cebeSEric Cheng 	/*
450da14cebeSEric Cheng 	 * This MAC's table of sub-flows
451da14cebeSEric Cheng 	 */
452da14cebeSEric Cheng 	flow_tab_t		*mi_flow_tab;		/* WO */
453da14cebeSEric Cheng 
454da14cebeSEric Cheng 	kstat_t			*mi_ksp;		/* WO */
455da14cebeSEric Cheng 	uint_t			mi_kstat_count;		/* WO */
456da14cebeSEric Cheng 	uint_t			mi_nactiveclients;	/* SL */
457da14cebeSEric Cheng 
458da14cebeSEric Cheng 	/* for broadcast and multicast support */
459da14cebeSEric Cheng 	struct mac_mcast_addrs_s *mi_mcast_addrs;	/* mi_rw_lock */
460da14cebeSEric Cheng 	struct mac_bcast_grp_s *mi_bcast_grp;		/* mi_rw_lock */
461da14cebeSEric Cheng 	uint_t			mi_bcast_ngrps;		/* mi_rw_lock */
462da14cebeSEric Cheng 
463da14cebeSEric Cheng 	/* list of MAC clients which opened this MAC */
464da14cebeSEric Cheng 	struct mac_client_impl_s *mi_clients_list;	/* mi_rw_lock */
465da14cebeSEric Cheng 	uint_t			mi_nclients;		/* mi_rw_lock */
466ae6aa22aSVenugopal Iyer 	struct mac_client_impl_s *mi_single_active_client; /* mi_rw_lock */
467da14cebeSEric Cheng 
468da14cebeSEric Cheng 	uint32_t		mi_margin;		/* mi_rw_lock */
469da14cebeSEric Cheng 	uint_t			mi_sdu_min;		/* mi_rw_lock */
470da14cebeSEric Cheng 	uint_t			mi_sdu_max;		/* mi_rw_lock */
4711eee170aSErik Nordmark 	uint_t			mi_sdu_multicast;	/* mi_rw_lock */
472da14cebeSEric Cheng 
473da14cebeSEric Cheng 	/*
474da14cebeSEric Cheng 	 * Cache of factory MAC addresses provided by the driver. If
475da14cebeSEric Cheng 	 * the driver doesn't provide multiple factory MAC addresses,
476da14cebeSEric Cheng 	 * the mi_factory_addr is set to NULL, and mi_factory_addr_num
477da14cebeSEric Cheng 	 * is set to zero.
478da14cebeSEric Cheng 	 */
479da14cebeSEric Cheng 	mac_factory_addr_t	*mi_factory_addr;	/* mi_rw_lock */
480da14cebeSEric Cheng 	uint_t			mi_factory_addr_num;	/* mi_rw_lock */
481da14cebeSEric Cheng 
482da14cebeSEric Cheng 	/* for promiscuous mode support */
483da14cebeSEric Cheng 	kmutex_t		mi_promisc_lock;
484da14cebeSEric Cheng 	mac_cb_t		*mi_promisc_list;	/* mi_promisc_lock */
485da14cebeSEric Cheng 	mac_cb_info_t		mi_promisc_cb_info;	/* mi_promisc_lock */
486da14cebeSEric Cheng 
487da14cebeSEric Cheng 	/* cache of rings over this mac_impl */
488da14cebeSEric Cheng 	kmutex_t		mi_ring_lock;
489da14cebeSEric Cheng 	mac_ring_t		*mi_ring_freelist;	/* mi_ring_lock */
490da14cebeSEric Cheng 
491da14cebeSEric Cheng 	/*
492da14cebeSEric Cheng 	 * These are used for caching the properties, if any, for the
493da14cebeSEric Cheng 	 * primary MAC client. If the MAC client is not yet in place
494da14cebeSEric Cheng 	 * when the properties are set then we cache them here to be
495da14cebeSEric Cheng 	 * applied to the MAC client when it is created.
496da14cebeSEric Cheng 	 */
497da14cebeSEric Cheng 	mac_resource_props_t	mi_resource_props;	/* SL */
4984eaa4710SRishi Srivatsavai 	uint16_t		mi_pvid;		/* SL */
499da14cebeSEric Cheng 
500da14cebeSEric Cheng 	minor_t			mi_minor;		/* WO */
501da14cebeSEric Cheng 	uint32_t		mi_oref;		/* SL */
5025d460eafSCathy Zhou 	mac_capab_legacy_t	mi_capab_legacy;	/* WO */
5035d460eafSCathy Zhou 	dev_t			mi_phy_dev;		/* WO */
5045d460eafSCathy Zhou 
505d62bc4baSyz147064 	/*
506d62bc4baSyz147064 	 * List of margin value requests added by mac clients. This list is
507d62bc4baSyz147064 	 * sorted: the first one has the greatest value.
508d62bc4baSyz147064 	 */
509d62bc4baSyz147064 	mac_margin_req_t	*mi_mmrp;
510a776d98eSRobert Mustacchi 	mac_mtu_req_t		*mi_mtrp;
5110dc2366fSVenugopal Iyer 	char			**mi_priv_prop;
5124045d941Ssowmini 	uint_t			mi_priv_prop_count;
513da14cebeSEric Cheng 
514da14cebeSEric Cheng 	/*
515da14cebeSEric Cheng 	 * Hybrid I/O related definitions.
516da14cebeSEric Cheng 	 */
517da14cebeSEric Cheng 	mac_capab_share_t	mi_share_capab;
518da14cebeSEric Cheng 
5194eaa4710SRishi Srivatsavai 	/*
5204eaa4710SRishi Srivatsavai 	 * Bridging hooks and limit values.  Uses mutex and reference counts
5214eaa4710SRishi Srivatsavai 	 * (bridging only) for data path.  Limits need no synchronization.
5224eaa4710SRishi Srivatsavai 	 */
5234eaa4710SRishi Srivatsavai 	mac_handle_t		mi_bridge_link;
5244eaa4710SRishi Srivatsavai 	kmutex_t		mi_bridge_lock;
5254eaa4710SRishi Srivatsavai 	uint32_t		mi_llimit;
5264eaa4710SRishi Srivatsavai 	uint32_t		mi_ldecay;
5274eaa4710SRishi Srivatsavai 
528da14cebeSEric Cheng /* This should be the last block in this structure */
529da14cebeSEric Cheng #ifdef DEBUG
530da14cebeSEric Cheng #define	MAC_PERIM_STACK_DEPTH	15
531da14cebeSEric Cheng 	int			mi_perim_stack_depth;
532da14cebeSEric Cheng 	pc_t			mi_perim_stack[MAC_PERIM_STACK_DEPTH];
533da14cebeSEric Cheng #endif
534da14cebeSEric Cheng };
535da14cebeSEric Cheng 
5360dc2366fSVenugopal Iyer /*
5370dc2366fSVenugopal Iyer  * The default TX group is the last one in the list.
5380dc2366fSVenugopal Iyer  */
5390dc2366fSVenugopal Iyer #define	MAC_DEFAULT_TX_GROUP(mip)	\
5400dc2366fSVenugopal Iyer 	(mip)->mi_tx_groups + (mip)->mi_tx_group_count
5410dc2366fSVenugopal Iyer 
5420dc2366fSVenugopal Iyer /*
5430dc2366fSVenugopal Iyer  * The default RX group is the first one in the list
5440dc2366fSVenugopal Iyer  */
5450dc2366fSVenugopal Iyer #define	MAC_DEFAULT_RX_GROUP(mip)	(mip)->mi_rx_groups
5460dc2366fSVenugopal Iyer 
5470dc2366fSVenugopal Iyer /* Reserved RX rings */
5480dc2366fSVenugopal Iyer #define	MAC_RX_RING_RESERVED(m, cnt)	{	\
5490dc2366fSVenugopal Iyer 	ASSERT((m)->mi_rxrings_avail >= (cnt));	\
5500dc2366fSVenugopal Iyer 	(m)->mi_rxrings_rsvd += (cnt);		\
5510dc2366fSVenugopal Iyer 	(m)->mi_rxrings_avail -= (cnt);		\
5520dc2366fSVenugopal Iyer }
5530dc2366fSVenugopal Iyer 
5540dc2366fSVenugopal Iyer /* Released RX rings */
5550dc2366fSVenugopal Iyer #define	MAC_RX_RING_RELEASED(m, cnt)	{	\
5560dc2366fSVenugopal Iyer 	ASSERT((m)->mi_rxrings_rsvd >= (cnt));	\
5570dc2366fSVenugopal Iyer 	(m)->mi_rxrings_rsvd -= (cnt);		\
5580dc2366fSVenugopal Iyer 	(m)->mi_rxrings_avail += (cnt);		\
5590dc2366fSVenugopal Iyer }
5600dc2366fSVenugopal Iyer 
5610dc2366fSVenugopal Iyer /* Reserved a RX group */
5620dc2366fSVenugopal Iyer #define	MAC_RX_GRP_RESERVED(m)	{		\
5630dc2366fSVenugopal Iyer 	ASSERT((m)->mi_rxhwclnt_avail > 0);	\
5640dc2366fSVenugopal Iyer 	(m)->mi_rxhwclnt_avail--;		\
5650dc2366fSVenugopal Iyer 	(m)->mi_rxhwclnt_used++;		\
5660dc2366fSVenugopal Iyer }
5670dc2366fSVenugopal Iyer 
5680dc2366fSVenugopal Iyer /* Released a RX group */
5690dc2366fSVenugopal Iyer #define	MAC_RX_GRP_RELEASED(m)	{		\
5700dc2366fSVenugopal Iyer 	ASSERT((m)->mi_rxhwclnt_used > 0);	\
5710dc2366fSVenugopal Iyer 	(m)->mi_rxhwclnt_avail++;		\
5720dc2366fSVenugopal Iyer 	(m)->mi_rxhwclnt_used--;		\
5730dc2366fSVenugopal Iyer }
5740dc2366fSVenugopal Iyer 
5750dc2366fSVenugopal Iyer /* Reserved TX rings */
5760dc2366fSVenugopal Iyer #define	MAC_TX_RING_RESERVED(m, cnt)	{	\
5770dc2366fSVenugopal Iyer 	ASSERT((m)->mi_txrings_avail >= (cnt));	\
5780dc2366fSVenugopal Iyer 	(m)->mi_txrings_rsvd += (cnt);		\
5790dc2366fSVenugopal Iyer 	(m)->mi_txrings_avail -= (cnt);		\
5800dc2366fSVenugopal Iyer }
5810dc2366fSVenugopal Iyer /* Released TX rings */
5820dc2366fSVenugopal Iyer #define	MAC_TX_RING_RELEASED(m, cnt)	{	\
5830dc2366fSVenugopal Iyer 	ASSERT((m)->mi_txrings_rsvd >= (cnt));	\
5840dc2366fSVenugopal Iyer 	(m)->mi_txrings_rsvd -= (cnt);		\
5850dc2366fSVenugopal Iyer 	(m)->mi_txrings_avail += (cnt);		\
5860dc2366fSVenugopal Iyer }
5870dc2366fSVenugopal Iyer 
5880dc2366fSVenugopal Iyer /* Reserved a TX group */
5890dc2366fSVenugopal Iyer #define	MAC_TX_GRP_RESERVED(m)	{		\
5900dc2366fSVenugopal Iyer 	ASSERT((m)->mi_txhwclnt_avail > 0);	\
5910dc2366fSVenugopal Iyer 	(m)->mi_txhwclnt_avail--;		\
5920dc2366fSVenugopal Iyer 	(m)->mi_txhwclnt_used++;		\
5930dc2366fSVenugopal Iyer }
5940dc2366fSVenugopal Iyer 
5950dc2366fSVenugopal Iyer /* Released a TX group */
5960dc2366fSVenugopal Iyer #define	MAC_TX_GRP_RELEASED(m)	{		\
5970dc2366fSVenugopal Iyer 	ASSERT((m)->mi_txhwclnt_used > 0);	\
5980dc2366fSVenugopal Iyer 	(m)->mi_txhwclnt_avail++;		\
5990dc2366fSVenugopal Iyer 	(m)->mi_txhwclnt_used--;		\
6000dc2366fSVenugopal Iyer }
6010dc2366fSVenugopal Iyer 
602da14cebeSEric Cheng /* for mi_state_flags */
603da14cebeSEric Cheng #define	MIS_DISABLED		0x0001
604da14cebeSEric Cheng #define	MIS_IS_VNIC		0x0002
605da14cebeSEric Cheng #define	MIS_IS_AGGR		0x0004
606da14cebeSEric Cheng #define	MIS_NOTIFY_DONE		0x0008
607da14cebeSEric Cheng #define	MIS_EXCLUSIVE		0x0010
608da14cebeSEric Cheng #define	MIS_EXCLUSIVE_HELD	0x0020
609da14cebeSEric Cheng #define	MIS_LEGACY		0x0040
6104eaa4710SRishi Srivatsavai #define	MIS_NO_ACTIVE		0x0080
6114eaa4710SRishi Srivatsavai #define	MIS_POLL_DISABLE	0x0100
612*36589d6bSRobert Mustacchi #define	MIS_IS_OVERLAY		0x0200
613ba2e4443Sseb 
614ba2e4443Sseb #define	mi_getstat	mi_callbacks->mc_getstat
615ba2e4443Sseb #define	mi_start	mi_callbacks->mc_start
616ba2e4443Sseb #define	mi_stop		mi_callbacks->mc_stop
617d62bc4baSyz147064 #define	mi_open		mi_callbacks->mc_open
618d62bc4baSyz147064 #define	mi_close	mi_callbacks->mc_close
619ba2e4443Sseb #define	mi_setpromisc	mi_callbacks->mc_setpromisc
620ba2e4443Sseb #define	mi_multicst	mi_callbacks->mc_multicst
621ba2e4443Sseb #define	mi_unicst	mi_callbacks->mc_unicst
622ba2e4443Sseb #define	mi_tx		mi_callbacks->mc_tx
623ba2e4443Sseb #define	mi_ioctl	mi_callbacks->mc_ioctl
624ba2e4443Sseb #define	mi_getcapab	mi_callbacks->mc_getcapab
6257c478bd9Sstevel@tonic-gate 
626da14cebeSEric Cheng typedef struct mac_notify_task_arg {
627da14cebeSEric Cheng 	mac_impl_t		*mnt_mip;
628da14cebeSEric Cheng 	mac_notify_type_t	mnt_type;
629da14cebeSEric Cheng 	mac_ring_t		*mnt_ring;
630da14cebeSEric Cheng } mac_notify_task_arg_t;
631da14cebeSEric Cheng 
632da14cebeSEric Cheng /*
633da14cebeSEric Cheng  * The mac_perim_handle_t is an opaque type that encodes the 'mip' pointer
634da14cebeSEric Cheng  * and whether internally a mac_open was done when acquiring the perimeter.
635da14cebeSEric Cheng  */
636da14cebeSEric Cheng #define	MAC_ENCODE_MPH(mph, mh, need_close)		\
637da14cebeSEric Cheng 	(mph) = (mac_perim_handle_t)((uintptr_t)(mh) | need_close)
638da14cebeSEric Cheng 
639da14cebeSEric Cheng #define	MAC_DECODE_MPH(mph, mip, need_close) {		\
640da14cebeSEric Cheng 	mip = (mac_impl_t *)(((uintptr_t)mph) & ~0x1);	\
641da14cebeSEric Cheng 	(need_close) = ((uintptr_t)mph & 0x1);		\
642da14cebeSEric Cheng }
643da14cebeSEric Cheng 
6440dc2366fSVenugopal Iyer /*
6450dc2366fSVenugopal Iyer  * Type of property information that can be returned by a driver.
6460dc2366fSVenugopal Iyer  * Valid flags of the pr_flags of the mac_prop_info_t data structure.
6470dc2366fSVenugopal Iyer  */
6480dc2366fSVenugopal Iyer #define	MAC_PROP_INFO_DEFAULT	0x0001
6490dc2366fSVenugopal Iyer #define	MAC_PROP_INFO_RANGE	0x0002
6500dc2366fSVenugopal Iyer #define	MAC_PROP_INFO_PERM	0x0004
6510dc2366fSVenugopal Iyer 
6520dc2366fSVenugopal Iyer /*
6530dc2366fSVenugopal Iyer  * Property information. pr_flags is a combination of one of the
6540dc2366fSVenugopal Iyer  * MAC_PROP_INFO_* flags, it is reset by the framework before invoking
6550dc2366fSVenugopal Iyer  * the driver's prefix_propinfo() entry point.
6560dc2366fSVenugopal Iyer  *
6570dc2366fSVenugopal Iyer  * Drivers should use MAC_PROP_INFO_SET_*() macros to provide
6580dc2366fSVenugopal Iyer  * information about a property.
6590dc2366fSVenugopal Iyer  */
6600dc2366fSVenugopal Iyer typedef struct mac_prop_info_state_s {
6610dc2366fSVenugopal Iyer 	uint8_t			pr_flags;
6620dc2366fSVenugopal Iyer 	uint8_t			pr_perm;
6630591ddd0SPrakash Jalan 	uint8_t			pr_errno;
6640dc2366fSVenugopal Iyer 	void			*pr_default;
6650dc2366fSVenugopal Iyer 	size_t			pr_default_size;
6660dc2366fSVenugopal Iyer 	mac_propval_range_t	*pr_range;
6670591ddd0SPrakash Jalan 	uint_t			pr_range_cur_count;
6680dc2366fSVenugopal Iyer } mac_prop_info_state_t;
6690dc2366fSVenugopal Iyer 
6700dc2366fSVenugopal Iyer #define	MAC_PROTECT_ENABLED(mcip, type) \
6710dc2366fSVenugopal Iyer 	(((mcip)->mci_flent-> \
6720dc2366fSVenugopal Iyer 	fe_resource_props.mrp_mask & MRP_PROTECT) != 0 && \
6730dc2366fSVenugopal Iyer 	((mcip)->mci_flent-> \
6740dc2366fSVenugopal Iyer 	fe_resource_props.mrp_protect.mp_types & (type)) != 0)
6750dc2366fSVenugopal Iyer 
676da14cebeSEric Cheng typedef struct mac_client_impl_s mac_client_impl_t;
677da14cebeSEric Cheng 
6787c478bd9Sstevel@tonic-gate extern void	mac_init(void);
6797c478bd9Sstevel@tonic-gate extern int	mac_fini(void);
6807c478bd9Sstevel@tonic-gate 
681c61a1653SRyan Zezeski /*
682c61a1653SRyan Zezeski  * MAC packet/chain drop functions to aggregate all dropped-packet
683c61a1653SRyan Zezeski  * debugging to a single surface.
684c61a1653SRyan Zezeski  */
685c61a1653SRyan Zezeski /*PRINTFLIKE2*/
686c61a1653SRyan Zezeski extern void	mac_drop_pkt(mblk_t *, const char *, ...)
687c61a1653SRyan Zezeski     __KPRINTFLIKE(2);
688c61a1653SRyan Zezeski 
689c61a1653SRyan Zezeski /*PRINTFLIKE2*/
690c61a1653SRyan Zezeski extern void	mac_drop_chain(mblk_t *, const char *, ...)
691c61a1653SRyan Zezeski     __KPRINTFLIKE(2);
692c61a1653SRyan Zezeski 
6934045d941Ssowmini extern void	mac_ndd_ioctl(mac_impl_t *, queue_t *, mblk_t *);
6940dc2366fSVenugopal Iyer extern boolean_t mac_ip_hdr_length_v6(ip6_t *, uint8_t *, uint16_t *,
6950dc2366fSVenugopal Iyer     uint8_t *, ip6_frag_t **);
696da14cebeSEric Cheng 
697da14cebeSEric Cheng extern mblk_t *mac_copymsgchain_cksum(mblk_t *);
698da14cebeSEric Cheng extern void mac_packet_print(mac_handle_t, mblk_t *);
699da14cebeSEric Cheng extern void mac_rx_deliver(void *, mac_resource_handle_t, mblk_t *,
700da14cebeSEric Cheng     mac_header_info_t *);
701da14cebeSEric Cheng extern void mac_tx_notify(mac_impl_t *);
702c61a1653SRyan Zezeski extern mblk_t *mac_ring_tx(mac_handle_t, mac_ring_handle_t, mblk_t *);
703c61a1653SRyan Zezeski extern mblk_t *mac_provider_tx(mac_impl_t *, mac_ring_handle_t, mblk_t *,
704c61a1653SRyan Zezeski     mac_client_impl_t *);
705da14cebeSEric Cheng 
706da14cebeSEric Cheng extern void mac_callback_add(mac_cb_info_t *, mac_cb_t **, mac_cb_t *);
707da14cebeSEric Cheng extern boolean_t mac_callback_remove(mac_cb_info_t *, mac_cb_t **, mac_cb_t *);
708da14cebeSEric Cheng extern void mac_callback_remove_wait(mac_cb_info_t *);
709b237158dSPatrick Mooney extern void mac_callback_barrier(mac_cb_info_t *);
710da14cebeSEric Cheng extern void mac_callback_free(mac_cb_t *);
711b237158dSPatrick Mooney extern void mac_callback_walker_enter(mac_cb_info_t *);
712b237158dSPatrick Mooney extern void mac_callback_walker_exit(mac_cb_info_t *, mac_cb_t **, boolean_t);
713da14cebeSEric Cheng 
714da14cebeSEric Cheng /* in mac_bcast.c */
715da14cebeSEric Cheng extern void mac_bcast_init(void);
716da14cebeSEric Cheng extern void mac_bcast_fini(void);
717da14cebeSEric Cheng extern mac_impl_t *mac_bcast_grp_mip(void *);
718da14cebeSEric Cheng extern int mac_bcast_add(mac_client_impl_t *, const uint8_t *, uint16_t,
719da14cebeSEric Cheng     mac_addrtype_t);
720da14cebeSEric Cheng extern void mac_bcast_delete(mac_client_impl_t *, const uint8_t *, uint16_t);
721da14cebeSEric Cheng extern void mac_bcast_send(void *, void *, mblk_t *, boolean_t);
722da14cebeSEric Cheng extern void mac_bcast_grp_free(void *);
723da14cebeSEric Cheng extern void mac_bcast_refresh(mac_impl_t *, mac_multicst_t, void *,
724da14cebeSEric Cheng     boolean_t);
725da14cebeSEric Cheng extern void mac_client_bcast_refresh(mac_client_impl_t *, mac_multicst_t,
726da14cebeSEric Cheng     void *, boolean_t);
727da14cebeSEric Cheng 
728da14cebeSEric Cheng /*
729da14cebeSEric Cheng  * Grouping functions are used internally by MAC layer.
730da14cebeSEric Cheng  */
731da14cebeSEric Cheng extern int mac_group_addmac(mac_group_t *, const uint8_t *);
732da14cebeSEric Cheng extern int mac_group_remmac(mac_group_t *, const uint8_t *);
73384de666eSRyan Zezeski extern int mac_group_addvlan(mac_group_t *, uint16_t);
73484de666eSRyan Zezeski extern int mac_group_remvlan(mac_group_t *, uint16_t);
735da14cebeSEric Cheng extern int mac_rx_group_add_flow(mac_client_impl_t *, flow_entry_t *,
736da14cebeSEric Cheng     mac_group_t *);
73763f531d1SSriharsha Basavapatna extern mblk_t *mac_hwring_tx(mac_ring_handle_t, mblk_t *);
7384eaa4710SRishi Srivatsavai extern mblk_t *mac_bridge_tx(mac_impl_t *, mac_ring_handle_t, mblk_t *);
7390dc2366fSVenugopal Iyer extern mac_group_t *mac_reserve_rx_group(mac_client_impl_t *, uint8_t *,
7400dc2366fSVenugopal Iyer     boolean_t);
7410dc2366fSVenugopal Iyer extern void mac_release_rx_group(mac_client_impl_t *, mac_group_t *);
7420dc2366fSVenugopal Iyer extern int mac_rx_switch_group(mac_client_impl_t *, mac_group_t *,
7430dc2366fSVenugopal Iyer     mac_group_t *);
744da14cebeSEric Cheng extern mac_ring_t *mac_reserve_tx_ring(mac_impl_t *, mac_ring_t *);
7450dc2366fSVenugopal Iyer extern mac_group_t *mac_reserve_tx_group(mac_client_impl_t *, boolean_t);
7460dc2366fSVenugopal Iyer extern void mac_release_tx_group(mac_client_impl_t *, mac_group_t *);
7470dc2366fSVenugopal Iyer extern void mac_tx_switch_group(mac_client_impl_t *, mac_group_t *,
7480dc2366fSVenugopal Iyer     mac_group_t *);
7490dc2366fSVenugopal Iyer extern void mac_rx_switch_grp_to_sw(mac_group_t *);
750da14cebeSEric Cheng 
751da14cebeSEric Cheng /*
752da14cebeSEric Cheng  * MAC address functions are used internally by MAC layer.
753da14cebeSEric Cheng  */
754da14cebeSEric Cheng extern mac_address_t *mac_find_macaddr(mac_impl_t *, uint8_t *);
75584de666eSRyan Zezeski extern mac_address_t *mac_find_macaddr_vlan(mac_impl_t *, uint8_t *, uint16_t);
756da14cebeSEric Cheng extern boolean_t mac_check_macaddr_shared(mac_address_t *);
757da14cebeSEric Cheng extern int mac_update_macaddr(mac_address_t *, uint8_t *);
758da14cebeSEric Cheng extern void mac_freshen_macaddr(mac_address_t *, uint8_t *);
759da14cebeSEric Cheng extern void mac_retrieve_macaddr(mac_address_t *, uint8_t *);
760da14cebeSEric Cheng extern void mac_init_macaddr(mac_impl_t *);
761da14cebeSEric Cheng extern void mac_fini_macaddr(mac_impl_t *);
762da14cebeSEric Cheng 
763da14cebeSEric Cheng /*
764da14cebeSEric Cheng  * Flow construction/destruction routines.
765da14cebeSEric Cheng  * Not meant to be used by mac clients.
766da14cebeSEric Cheng  */
767da14cebeSEric Cheng extern int mac_link_flow_init(mac_client_handle_t, flow_entry_t *);
768da14cebeSEric Cheng extern void mac_link_flow_clean(mac_client_handle_t, flow_entry_t *);
769da14cebeSEric Cheng 
770da14cebeSEric Cheng /*
77108ac1c49SNicolas Droux  * Fanout update routines called when the link speed of the NIC changes
77208ac1c49SNicolas Droux  * or when a MAC client's share is unbound.
773da14cebeSEric Cheng  */
7740dc2366fSVenugopal Iyer extern void mac_fanout_recompute_client(mac_client_impl_t *, cpupart_t *);
775da14cebeSEric Cheng extern void mac_fanout_recompute(mac_impl_t *);
776da14cebeSEric Cheng 
777da14cebeSEric Cheng /*
778da14cebeSEric Cheng  * The following functions are used internally by the MAC layer to
779da14cebeSEric Cheng  * add/remove/update flows associated with a mac_impl_t. They should
780da14cebeSEric Cheng  * never be used directly by MAC clients.
781da14cebeSEric Cheng  */
782da14cebeSEric Cheng extern int mac_datapath_setup(mac_client_impl_t *, flow_entry_t *, uint32_t);
783da14cebeSEric Cheng extern void mac_datapath_teardown(mac_client_impl_t *, flow_entry_t *,
784da14cebeSEric Cheng     uint32_t);
7850dc2366fSVenugopal Iyer extern void mac_rx_srs_group_setup(mac_client_impl_t *, flow_entry_t *,
7860dc2366fSVenugopal Iyer     uint32_t);
7870dc2366fSVenugopal Iyer extern void mac_tx_srs_group_setup(mac_client_impl_t *, flow_entry_t *,
7880dc2366fSVenugopal Iyer     uint32_t);
7890dc2366fSVenugopal Iyer extern void mac_rx_srs_group_teardown(flow_entry_t *, boolean_t);
7900dc2366fSVenugopal Iyer extern void mac_tx_srs_group_teardown(mac_client_impl_t *, flow_entry_t *,
791da14cebeSEric Cheng 	    uint32_t);
792da14cebeSEric Cheng extern int mac_rx_classify_flow_quiesce(flow_entry_t *, void *);
793da14cebeSEric Cheng extern int mac_rx_classify_flow_restart(flow_entry_t *, void *);
794da14cebeSEric Cheng extern void mac_client_quiesce(mac_client_impl_t *);
795da14cebeSEric Cheng extern void mac_client_restart(mac_client_impl_t *);
796da14cebeSEric Cheng 
797da14cebeSEric Cheng extern void mac_flow_update_priority(mac_client_impl_t *, flow_entry_t *);
798da14cebeSEric Cheng 
799da14cebeSEric Cheng extern void mac_flow_rem_subflow(flow_entry_t *);
800da14cebeSEric Cheng extern void mac_rename_flow(flow_entry_t *, const char *);
801da14cebeSEric Cheng extern void mac_flow_set_name(flow_entry_t *, const char *);
802da14cebeSEric Cheng 
803da14cebeSEric Cheng extern mblk_t *mac_add_vlan_tag(mblk_t *, uint_t, uint16_t);
804da14cebeSEric Cheng extern mblk_t *mac_add_vlan_tag_chain(mblk_t *, uint_t, uint16_t);
805da14cebeSEric Cheng extern mblk_t *mac_strip_vlan_tag_chain(mblk_t *);
806c61a1653SRyan Zezeski extern void mac_rx_def(void *, mac_resource_handle_t, mblk_t *, boolean_t);
807da14cebeSEric Cheng extern mblk_t *mac_rx_flow(mac_handle_t, mac_resource_handle_t, mblk_t *);
808da14cebeSEric Cheng 
809da14cebeSEric Cheng extern void i_mac_share_alloc(mac_client_impl_t *);
810da14cebeSEric Cheng extern void i_mac_share_free(mac_client_impl_t *);
811da14cebeSEric Cheng extern void i_mac_perim_enter(mac_impl_t *);
812da14cebeSEric Cheng extern void i_mac_perim_exit(mac_impl_t *);
813da14cebeSEric Cheng extern int i_mac_perim_enter_nowait(mac_impl_t *);
814da14cebeSEric Cheng extern void i_mac_tx_srs_notify(mac_impl_t *, mac_ring_handle_t);
815da14cebeSEric Cheng extern int mac_hold(const char *, mac_impl_t **);
816da14cebeSEric Cheng extern void mac_rele(mac_impl_t *);
817da14cebeSEric Cheng extern int i_mac_disable(mac_impl_t *);
818da14cebeSEric Cheng extern void i_mac_notify(mac_impl_t *, mac_notify_type_t);
819da14cebeSEric Cheng extern void i_mac_notify_exit(mac_impl_t *);
820da14cebeSEric Cheng extern void mac_rx_group_unmark(mac_group_t *, uint_t);
821da14cebeSEric Cheng extern void mac_tx_client_flush(mac_client_impl_t *);
822da14cebeSEric Cheng extern void mac_tx_client_block(mac_client_impl_t *);
823da14cebeSEric Cheng extern void mac_tx_client_unblock(mac_client_impl_t *);
8240dc2366fSVenugopal Iyer extern void mac_tx_invoke_callbacks(mac_client_impl_t *, mac_tx_cookie_t);
825d91a22bfSGirish Moodalbail extern int i_mac_promisc_set(mac_impl_t *, boolean_t);
826da14cebeSEric Cheng extern mactype_t *mactype_getplugin(const char *);
827da14cebeSEric Cheng extern void mac_addr_factory_init(mac_impl_t *);
828da14cebeSEric Cheng extern void mac_addr_factory_fini(mac_impl_t *);
8290dc2366fSVenugopal Iyer extern void mac_register_priv_prop(mac_impl_t *, char **);
830da14cebeSEric Cheng extern void mac_unregister_priv_prop(mac_impl_t *);
831da14cebeSEric Cheng extern int mac_init_rings(mac_impl_t *, mac_ring_type_t);
832da14cebeSEric Cheng extern void mac_free_rings(mac_impl_t *, mac_ring_type_t);
8330dc2366fSVenugopal Iyer extern void mac_compare_ddi_handle(mac_group_t *, uint_t, mac_ring_t *);
834da14cebeSEric Cheng 
835da14cebeSEric Cheng extern int mac_start_group(mac_group_t *);
836da14cebeSEric Cheng extern void mac_stop_group(mac_group_t *);
837da14cebeSEric Cheng extern int mac_start_ring(mac_ring_t *);
838da14cebeSEric Cheng extern void mac_stop_ring(mac_ring_t *);
83984de666eSRyan Zezeski extern int mac_add_macaddr_vlan(mac_impl_t *, mac_group_t *, uint8_t *,
84084de666eSRyan Zezeski     uint16_t, boolean_t);
84184de666eSRyan Zezeski extern int mac_remove_macaddr_vlan(mac_address_t *, uint16_t);
842da14cebeSEric Cheng 
8430dc2366fSVenugopal Iyer extern void mac_set_group_state(mac_group_t *, mac_group_state_t);
8440dc2366fSVenugopal Iyer extern void mac_group_add_client(mac_group_t *, mac_client_impl_t *);
8450dc2366fSVenugopal Iyer extern void mac_group_remove_client(mac_group_t *, mac_client_impl_t *);
8460dc2366fSVenugopal Iyer 
847da14cebeSEric Cheng extern int i_mac_group_add_ring(mac_group_t *, mac_ring_t *, int);
848da14cebeSEric Cheng extern void i_mac_group_rem_ring(mac_group_t *, mac_ring_t *, boolean_t);
8490dc2366fSVenugopal Iyer extern int mac_group_ring_modify(mac_client_impl_t *, mac_group_t *,
8500dc2366fSVenugopal Iyer     mac_group_t *);
8514eaa4710SRishi Srivatsavai extern void mac_poll_state_change(mac_handle_t, boolean_t);
8524eaa4710SRishi Srivatsavai 
8530dc2366fSVenugopal Iyer extern mac_group_state_t mac_group_next_state(mac_group_t *,
8540dc2366fSVenugopal Iyer     mac_client_impl_t **, mac_group_t *, boolean_t);
8550dc2366fSVenugopal Iyer 
85625ec3e3dSEric Cheng extern mblk_t *mac_protect_check(mac_client_handle_t, mblk_t *);
85725ec3e3dSEric Cheng extern int mac_protect_set(mac_client_handle_t, mac_resource_props_t *);
85825ec3e3dSEric Cheng extern boolean_t mac_protect_enabled(mac_client_handle_t, uint32_t);
85925ec3e3dSEric Cheng extern int mac_protect_validate(mac_resource_props_t *);
86025ec3e3dSEric Cheng extern void mac_protect_update(mac_resource_props_t *, mac_resource_props_t *);
861797f979dSCody Peter Mello extern void mac_protect_update_mac_token(mac_client_impl_t *);
862797f979dSCody Peter Mello extern void mac_protect_intercept_dynamic(mac_client_impl_t *, mblk_t *);
863797f979dSCody Peter Mello extern void mac_protect_flush_dynamic(mac_client_impl_t *);
8640dc2366fSVenugopal Iyer extern void mac_protect_cancel_timer(mac_client_impl_t *);
8650dc2366fSVenugopal Iyer extern void mac_protect_init(mac_client_impl_t *);
8660dc2366fSVenugopal Iyer extern void mac_protect_fini(mac_client_impl_t *);
8670dc2366fSVenugopal Iyer 
8680dc2366fSVenugopal Iyer extern int mac_set_resources(mac_handle_t, mac_resource_props_t *);
8690dc2366fSVenugopal Iyer extern void mac_get_resources(mac_handle_t, mac_resource_props_t *);
8700dc2366fSVenugopal Iyer extern void mac_get_effective_resources(mac_handle_t, mac_resource_props_t *);
87110a40492SRobert Mustacchi extern void mac_set_promisc_filtered(mac_client_handle_t, boolean_t);
87210a40492SRobert Mustacchi extern boolean_t mac_get_promisc_filtered(mac_client_handle_t);
8730dc2366fSVenugopal Iyer 
8740dc2366fSVenugopal Iyer extern cpupart_t *mac_pset_find(mac_resource_props_t *, boolean_t *);
8750dc2366fSVenugopal Iyer extern void mac_set_pool_effective(boolean_t, cpupart_t *,
8760dc2366fSVenugopal Iyer     mac_resource_props_t *, mac_resource_props_t *);
8770dc2366fSVenugopal Iyer extern void mac_set_rings_effective(mac_client_impl_t *);
8780dc2366fSVenugopal Iyer extern mac_client_impl_t *mac_check_primary_relocation(mac_client_impl_t *,
8790dc2366fSVenugopal Iyer     boolean_t);
88025ec3e3dSEric Cheng 
8814eaa4710SRishi Srivatsavai /* Global callbacks into the bridging module (when loaded) */
8824eaa4710SRishi Srivatsavai extern mac_bridge_tx_t mac_bridge_tx_cb;
8834eaa4710SRishi Srivatsavai extern mac_bridge_rx_t mac_bridge_rx_cb;
8844eaa4710SRishi Srivatsavai extern mac_bridge_ref_t mac_bridge_ref_cb;
8854eaa4710SRishi Srivatsavai extern mac_bridge_ls_t mac_bridge_ls_cb;
8864eaa4710SRishi Srivatsavai 
88745d3dd98SRobert Mustacchi /*
88845d3dd98SRobert Mustacchi  * MAC Transceiver related functions
88945d3dd98SRobert Mustacchi  */
89045d3dd98SRobert Mustacchi struct mac_transceiver_info {
89145d3dd98SRobert Mustacchi 	boolean_t		mti_present;
89245d3dd98SRobert Mustacchi 	boolean_t		mti_usable;
89345d3dd98SRobert Mustacchi };
89445d3dd98SRobert Mustacchi 
89545d3dd98SRobert Mustacchi extern void mac_transceiver_init(mac_impl_t *);
89645d3dd98SRobert Mustacchi extern int mac_transceiver_count(mac_handle_t, uint_t *);
89745d3dd98SRobert Mustacchi extern int mac_transceiver_info(mac_handle_t, uint_t, boolean_t *, boolean_t *);
89845d3dd98SRobert Mustacchi extern int mac_transceiver_read(mac_handle_t, uint_t, uint_t, void *, size_t,
89945d3dd98SRobert Mustacchi     off_t, size_t *);
9000dc2366fSVenugopal Iyer 
901c1e9c696SRobert Mustacchi /*
902c1e9c696SRobert Mustacchi  * MAC LED related functions
903c1e9c696SRobert Mustacchi  */
904c1e9c696SRobert Mustacchi #define	MAC_LED_ALL	(MAC_LED_DEFAULT | MAC_LED_OFF | MAC_LED_IDENT | \
905c1e9c696SRobert Mustacchi 			    MAC_LED_ON)
906c1e9c696SRobert Mustacchi extern void mac_led_init(mac_impl_t *);
907c1e9c696SRobert Mustacchi extern int mac_led_get(mac_handle_t, mac_led_mode_t *, mac_led_mode_t *);
908c1e9c696SRobert Mustacchi extern int mac_led_set(mac_handle_t, mac_led_mode_t);
909c1e9c696SRobert Mustacchi 
9107c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
9117c478bd9Sstevel@tonic-gate }
9127c478bd9Sstevel@tonic-gate #endif
9137c478bd9Sstevel@tonic-gate 
9147c478bd9Sstevel@tonic-gate #endif	/* _SYS_MAC_IMPL_H */
915