xref: /titanic_51/usr/src/uts/common/sys/mac_impl.h (revision 9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bb)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_MAC_IMPL_H
27 #define	_SYS_MAC_IMPL_H
28 
29 #include <sys/modhash.h>
30 #include <sys/mac_client.h>
31 #include <sys/mac_provider.h>
32 #include <sys/note.h>
33 #include <net/if.h>
34 #include <sys/mac_flow_impl.h>
35 #include <netinet/ip6.h>
36 
37 #ifdef	__cplusplus
38 extern "C" {
39 #endif
40 
41 typedef struct mac_margin_req_s	mac_margin_req_t;
42 
43 struct mac_margin_req_s {
44 	mac_margin_req_t	*mmr_nextp;
45 	uint_t			mmr_ref;
46 	uint32_t		mmr_margin;
47 };
48 
49 /* Generic linked chain type */
50 typedef	struct mac_chain_s {
51 	struct mac_chain_s	*next;
52 	void			*item;
53 } mac_chain_t;
54 
55 /*
56  * Generic mac callback list manipulation structures and macros. The mac_cb_t
57  * represents a general callback list element embedded in a particular
58  * data structure such as a mac_notify_cb_t or a mac_promisc_impl_t.
59  * The mac_cb_info_t represents general information about list walkers.
60  * Please see the comments above mac_callback_add for more information.
61  */
62 /* mcb_flags */
63 #define	MCB_CONDEMNED		0x1		/* Logically deleted */
64 #define	MCB_NOTIFY_CB_T		0x2
65 #define	MCB_TX_NOTIFY_CB_T	0x4
66 
67 typedef struct mac_cb_s {
68 	struct mac_cb_s		*mcb_nextp;	/* Linked list of callbacks */
69 	void			*mcb_objp;	/* Ptr to enclosing object  */
70 	size_t			mcb_objsize;	/* Sizeof the enclosing obj */
71 	uint_t			mcb_flags;
72 } mac_cb_t;
73 
74 typedef struct mac_cb_info_s {
75 	kmutex_t	*mcbi_lockp;
76 	kcondvar_t	mcbi_cv;
77 	uint_t		mcbi_del_cnt;		/* Deleted callback cnt */
78 	uint_t		mcbi_walker_cnt;	/* List walker count */
79 } mac_cb_info_t;
80 
81 typedef struct mac_notify_cb_s {
82 	mac_cb_t	mncb_link;		/* Linked list of callbacks */
83 	mac_notify_t	mncb_fn;		/* callback function */
84 	void		*mncb_arg;		/* callback argument */
85 	struct mac_impl_s *mncb_mip;
86 } mac_notify_cb_t;
87 
88 /*
89  * mac_callback_add(listinfo, listhead, listelement)
90  * mac_callback_remove(listinfo, listhead, listelement)
91  */
92 typedef boolean_t (*mcb_func_t)(mac_cb_info_t *, mac_cb_t **, mac_cb_t *);
93 
94 #define	MAC_CALLBACK_WALKER_INC(mcbi) {				\
95 	mutex_enter((mcbi)->mcbi_lockp);			\
96 	(mcbi)->mcbi_walker_cnt++;				\
97 	mutex_exit((mcbi)->mcbi_lockp);				\
98 }
99 
100 #define	MAC_CALLBACK_WALKER_INC_HELD(mcbi)	(mcbi)->mcbi_walker_cnt++;
101 
102 #define	MAC_CALLBACK_WALKER_DCR(mcbi, headp) {			\
103 	mac_cb_t	*rmlist;				\
104 								\
105 	mutex_enter((mcbi)->mcbi_lockp);			\
106 	if (--(mcbi)->mcbi_walker_cnt == 0 && (mcbi)->mcbi_del_cnt != 0) { \
107 		rmlist = mac_callback_walker_cleanup((mcbi), headp);	\
108 		mac_callback_free(rmlist);			\
109 		cv_broadcast(&(mcbi)->mcbi_cv);			\
110 	}							\
111 	mutex_exit((mcbi)->mcbi_lockp);				\
112 }
113 
114 #define	MAC_PROMISC_WALKER_INC(mip)				\
115 	MAC_CALLBACK_WALKER_INC(&(mip)->mi_promisc_cb_info)
116 
117 #define	MAC_PROMISC_WALKER_DCR(mip) {				\
118 	mac_cb_info_t	*mcbi;					\
119 								\
120 	mcbi = &(mip)->mi_promisc_cb_info;			\
121 	mutex_enter(mcbi->mcbi_lockp);				\
122 	if (--mcbi->mcbi_walker_cnt == 0 && mcbi->mcbi_del_cnt != 0) { \
123 		i_mac_promisc_walker_cleanup(mip);		\
124 		cv_broadcast(&mcbi->mcbi_cv);			\
125 	}							\
126 	mutex_exit(mcbi->mcbi_lockp);				\
127 }
128 
129 typedef struct mactype_s {
130 	const char	*mt_ident;
131 	uint32_t	mt_ref;
132 	uint_t		mt_type;
133 	uint_t		mt_nativetype;
134 	size_t		mt_addr_length;
135 	uint8_t		*mt_brdcst_addr;
136 	mactype_ops_t	mt_ops;
137 	mac_stat_info_t	*mt_stats;	/* array of mac_stat_info_t elements */
138 	size_t		mt_statcount;	/* number of elements in mt_stats */
139 	mac_ndd_mapping_t *mt_mapping;
140 	size_t		mt_mappingcount;
141 } mactype_t;
142 
143 /*
144  * Multiple rings implementation.
145  */
146 typedef	enum {
147 	MAC_GROUP_STATE_UNINIT	= 0,	/* initial state of data structure */
148 	MAC_GROUP_STATE_REGISTERED,	/* hooked with h/w group */
149 	MAC_GROUP_STATE_RESERVED,	/* group is reserved and opened */
150 	MAC_GROUP_STATE_SHARED		/* default group shared among */
151 					/* multiple mac clients */
152 } mac_group_state_t;
153 
154 typedef	struct mac_ring_s mac_ring_t;
155 typedef	struct mac_group_s mac_group_t;
156 
157 /*
158  * Ring data structure for ring control and management.
159  */
160 typedef enum {
161 	MR_FREE,		/* Available for assignment to flows */
162 	MR_NEWLY_ADDED,		/* Just assigned to another group */
163 	MR_INUSE		/* Assigned to an SRS */
164 } mac_ring_state_t;
165 
166 /* mr_flag values */
167 #define	MR_INCIPIENT	0x1
168 #define	MR_CONDEMNED	0x2
169 #define	MR_QUIESCE	0x4
170 
171 struct mac_ring_s {
172 	int			mr_index;	/* index in the original list */
173 	mac_ring_type_t		mr_type;	/* ring type */
174 	mac_ring_t		*mr_next;	/* next ring in the chain */
175 	mac_group_handle_t	mr_gh;		/* reference to group */
176 
177 	mac_classify_type_t	mr_classify_type;	/* HW vs SW */
178 	struct mac_soft_ring_set_s *mr_srs;		/* associated SRS */
179 	uint_t			mr_refcnt;		/* Ring references */
180 	/* ring generation no. to guard against drivers using stale rings */
181 	uint64_t		mr_gen_num;
182 
183 	kmutex_t		mr_lock;
184 	kcondvar_t		mr_cv;			/* mr_lock */
185 	mac_ring_state_t	mr_state;		/* mr_lock */
186 	uint_t			mr_flag;		/* mr_lock */
187 
188 	mac_ring_info_t		mr_info;	/* driver supplied info */
189 };
190 #define	mr_driver		mr_info.mri_driver
191 #define	mr_start		mr_info.mri_start
192 #define	mr_stop			mr_info.mri_stop
193 
194 #define	MAC_RING_MARK(mr, flag)		\
195 	(mr)->mr_flag |= flag;
196 
197 #define	MAC_RING_UNMARK(mr, flag)	\
198 	(mr)->mr_flag &= ~flag;
199 
200 /*
201  * Reference hold and release on mac_ring_t 'mr'
202  */
203 #define	MR_REFHOLD_LOCKED(mr)		{		\
204 	ASSERT(MUTEX_HELD(&mr->mr_lock));		\
205 	(mr)->mr_refcnt++;				\
206 }
207 
208 #define	MR_REFRELE(mr)		{	 		\
209 	mutex_enter(&(mr)->mr_lock);			\
210 	ASSERT((mr)->mr_refcnt != 0);			\
211 	(mr)->mr_refcnt--;				\
212 	if ((mr)->mr_refcnt == 0 &&			\
213 	    ((mr)->mr_flag & (MR_CONDEMNED | MR_QUIESCE))) \
214 		cv_signal(&(mr)->mr_cv);		\
215 	mutex_exit(&(mr)->mr_lock);			\
216 }
217 
218 /*
219  * Per mac client flow information associated with a RX group.
220  * The entire structure is SL protected.
221  */
222 typedef struct mac_grp_client {
223 	struct mac_grp_client		*mgc_next;
224 	struct mac_client_impl_s	*mgc_client;
225 } mac_grp_client_t;
226 
227 #define	MAC_RX_GROUP_NO_CLIENT(g)	((g)->mrg_clients == NULL)
228 
229 #define	MAC_RX_GROUP_ONLY_CLIENT(g)			\
230 	((((g)->mrg_clients != NULL) &&			\
231 	((g)->mrg_clients->mgc_next == NULL)) ?		\
232 	(g)->mrg_clients->mgc_client : NULL)
233 
234 /*
235  * Common ring group data structure for ring control and management.
236  * The entire structure is SL protected
237  */
238 struct mac_group_s {
239 	int			mrg_index;	/* index in the list */
240 	mac_ring_type_t		mrg_type;	/* ring type */
241 	mac_group_state_t	mrg_state;	/* state of the group */
242 	mac_group_t		*mrg_next;	/* next ring in the chain */
243 	mac_handle_t		mrg_mh;		/* reference to MAC */
244 	mac_ring_t		*mrg_rings;	/* grouped rings */
245 	uint_t			mrg_cur_count;	/* actual size of group */
246 
247 	mac_grp_client_t	*mrg_clients;	/* clients list */
248 
249 	struct mac_client_impl_s *mrg_tx_client; /* TX client pointer */
250 	mac_group_info_t	mrg_info;	/* driver supplied info */
251 };
252 
253 #define	mrg_driver		mrg_info.mgi_driver
254 #define	mrg_start		mrg_info.mgi_start
255 #define	mrg_stop		mrg_info.mgi_stop
256 
257 #define	GROUP_INTR_HANDLE(g)		(g)->mrg_info.mgi_intr.mi_handle
258 #define	GROUP_INTR_ENABLE_FUNC(g)	(g)->mrg_info.mgi_intr.mi_enable
259 #define	GROUP_INTR_DISABLE_FUNC(g)	(g)->mrg_info.mgi_intr.mi_disable
260 
261 #define	MAC_DEFAULT_GROUP(mh)		(((mac_impl_t *)mh)->mi_rx_groups)
262 
263 #define	MAC_RING_TX(mhp, rh, mp, rest) {				\
264 	mac_ring_handle_t mrh = rh;					\
265 	mac_impl_t *mimpl = (mac_impl_t *)mhp;				\
266 	/*								\
267 	 * Send packets through a selected tx ring, or through the 	\
268 	 * default handler if there is no selected ring.		\
269 	 */								\
270 	if (mrh == NULL)						\
271 		mrh = mimpl->mi_default_tx_ring;			\
272 	if (mrh == NULL) {						\
273 		rest = mimpl->mi_tx(mimpl->mi_driver, mp);		\
274 	} else {							\
275 		rest = mac_hwring_tx(mrh, mp);				\
276 	}								\
277 }
278 
279 /*
280  * This is the final stop before reaching the underlying driver
281  * or aggregation, so this is where the bridging hook is implemented.
282  * Packets that are bridged will return through mac_bridge_tx(), with
283  * rh nulled out if the bridge chooses to send output on a different
284  * link due to forwarding.
285  */
286 #define	MAC_TX(mip, rh, mp, share_bound) {				\
287 	/*								\
288 	 * If there is a bound Hybrid I/O share, send packets through 	\
289 	 * the default tx ring. (When there's a bound Hybrid I/O share,	\
290 	 * the tx rings of this client are mapped in the guest domain 	\
291 	 * and not accessible from here.)				\
292 	 */								\
293 	_NOTE(CONSTANTCONDITION)					\
294 	if (share_bound)						\
295 		rh = NULL;						\
296 	/*								\
297 	 * Grab the proper transmit pointer and handle. Special 	\
298 	 * optimization: we can test mi_bridge_link itself atomically,	\
299 	 * and if that indicates no bridge send packets through tx ring.\
300 	 */								\
301 	if (mip->mi_bridge_link == NULL) {				\
302 		MAC_RING_TX(mip, rh, mp, mp);				\
303 	} else {							\
304 		mp = mac_bridge_tx(mip, rh, mp);			\
305 	}								\
306 }
307 
308 /* mci_tx_flag */
309 #define	MCI_TX_QUIESCE	0x1
310 
311 typedef struct mac_factory_addr_s {
312 	boolean_t		mfa_in_use;
313 	uint8_t			mfa_addr[MAXMACADDRLEN];
314 	struct mac_client_impl_s	*mfa_client;
315 } mac_factory_addr_t;
316 
317 typedef struct mac_mcast_addrs_s {
318 	struct mac_mcast_addrs_s	*mma_next;
319 	uint8_t				mma_addr[MAXMACADDRLEN];
320 	int				mma_ref;
321 } mac_mcast_addrs_t;
322 
323 typedef enum {
324 	MAC_ADDRESS_TYPE_UNICAST_CLASSIFIED = 1,	/* hardware steering */
325 	MAC_ADDRESS_TYPE_UNICAST_PROMISC		/* promiscuous mode */
326 } mac_address_type_t;
327 
328 typedef struct mac_impl_s mac_impl_t;
329 
330 typedef struct mac_address_s {
331 	mac_address_type_t	ma_type;		/* address type */
332 	int			ma_nusers;		/* number of users */
333 							/* of that address */
334 	struct mac_address_s	*ma_next;		/* next address */
335 	uint8_t			ma_addr[MAXMACADDRLEN];	/* address value */
336 	size_t			ma_len;			/* address length */
337 	mac_group_t		*ma_group;		/* asscociated group */
338 	mac_impl_t		*ma_mip;		/* MAC handle */
339 } mac_address_t;
340 
341 extern krwlock_t i_mac_impl_lock;
342 extern mod_hash_t *i_mac_impl_hash;
343 extern kmem_cache_t *i_mac_impl_cachep;
344 extern uint_t i_mac_impl_count;
345 
346 /*
347  * Each registered MAC is associated with a mac_impl_t structure. The
348  * structure represents the undelying hardware, in terms of definition,
349  * resources (transmit, receive rings etc.), callback functions etc. It
350  * also holds the table of MAC clients that are configured on the device.
351  * The table is used for classifying incoming packets in software.
352  *
353  * The protection scheme uses 2 elements, a coarse serialization mechanism
354  * called perimeter and a finer traditional lock based scheme. More details
355  * can be found in the big block comment in mac.c.
356  *
357  * The protection scheme for each member of the mac_impl_t is described below.
358  *
359  * Write Once Only (WO): Typically these don't change for the lifetime of the
360  * data structure. For example something in mac_impl_t that stays the same
361  * from mac_register to mac_unregister, or something in a mac_client_impl_t
362  * that stays the same from mac_client_open to mac_client_close.
363  *
364  * Serializer (SL): Protected by the Serializer. All SLOP operations on a
365  * mac endpoint go through the serializer. MTOPs don't care about reading
366  * these fields atomically.
367  *
368  * Lock: Traditional mutex/rw lock. Modify operations still go through the
369  * mac serializer, the lock helps synchronize readers with writers.
370  */
371 struct mac_impl_s {
372 	krwlock_t		mi_rw_lock;
373 	char			mi_name[LIFNAMSIZ];	/* WO */
374 	uint32_t		mi_state_flags;
375 	void			*mi_driver;		/* Driver private, WO */
376 	mac_info_t		mi_info;		/* WO */
377 	mactype_t		*mi_type;		/* WO */
378 	void			*mi_pdata;		/* WO */
379 	size_t			mi_pdata_size;		/* WO */
380 	mac_callbacks_t		*mi_callbacks;		/* WO */
381 	dev_info_t		*mi_dip;		/* WO */
382 	uint32_t		mi_ref;			/* i_mac_impl_lock */
383 	uint_t			mi_active;		/* SL */
384 	link_state_t		mi_linkstate;		/* none */
385 	link_state_t		mi_lowlinkstate;	/* none */
386 	link_state_t		mi_lastlowlinkstate;	/* none */
387 	uint_t			mi_devpromisc;		/* SL */
388 	kmutex_t		mi_lock;
389 	uint8_t			mi_addr[MAXMACADDRLEN];	/* mi_rw_lock */
390 	uint8_t			mi_dstaddr[MAXMACADDRLEN]; /* mi_rw_lock */
391 	boolean_t		mi_dstaddr_set;
392 
393 	/*
394 	 * The mac perimeter. All client initiated create/modify operations
395 	 * on a mac end point go through this.
396 	 */
397 	kmutex_t		mi_perim_lock;
398 	kthread_t		*mi_perim_owner;	/* mi_perim_lock */
399 	uint_t			mi_perim_ocnt;		/* mi_perim_lock */
400 	kcondvar_t		mi_perim_cv;		/* mi_perim_lock */
401 
402 	/* mac notification callbacks */
403 	kmutex_t		mi_notify_lock;
404 	mac_cb_info_t		mi_notify_cb_info;	/* mi_notify_lock */
405 	mac_cb_t		*mi_notify_cb_list;	/* mi_notify_lock */
406 	kthread_t		*mi_notify_thread;	/* mi_notify_lock */
407 	uint_t			mi_notify_bits;		/* mi_notify_lock */
408 
409 	uint32_t		mi_v12n_level;		/* Virt'ion readiness */
410 
411 	/*
412 	 * RX groups, ring capability
413 	 * Fields of this block are SL protected.
414 	 */
415 	mac_group_type_t	mi_rx_group_type;	/* grouping type */
416 	uint_t			mi_rx_group_count;
417 	mac_group_t		*mi_rx_groups;
418 
419 	mac_capab_rings_t	mi_rx_rings_cap;
420 
421 	/*
422 	 * TX groups and ring capability, SL Protected.
423 	 */
424 	mac_group_type_t	mi_tx_group_type;	/* grouping type */
425 	uint_t			mi_tx_group_count;
426 	uint_t			mi_tx_group_free;
427 	mac_group_t		*mi_tx_groups;
428 
429 	mac_capab_rings_t	mi_tx_rings_cap;
430 
431 	mac_ring_handle_t	mi_default_tx_ring;
432 
433 	/*
434 	 * MAC address list. SL protected.
435 	 */
436 	mac_address_t		*mi_addresses;
437 
438 	/*
439 	 * This MAC's table of sub-flows
440 	 */
441 	flow_tab_t		*mi_flow_tab;		/* WO */
442 
443 	kstat_t			*mi_ksp;		/* WO */
444 	uint_t			mi_kstat_count;		/* WO */
445 	uint_t			mi_nactiveclients;	/* SL */
446 
447 	/* for broadcast and multicast support */
448 	struct mac_mcast_addrs_s *mi_mcast_addrs;	/* mi_rw_lock */
449 	struct mac_bcast_grp_s *mi_bcast_grp;		/* mi_rw_lock */
450 	uint_t			mi_bcast_ngrps;		/* mi_rw_lock */
451 
452 	/* list of MAC clients which opened this MAC */
453 	struct mac_client_impl_s *mi_clients_list;	/* mi_rw_lock */
454 	uint_t			mi_nclients;		/* mi_rw_lock */
455 	struct mac_client_impl_s *mi_single_active_client; /* mi_rw_lock */
456 
457 	uint32_t		mi_margin;		/* mi_rw_lock */
458 	uint_t			mi_sdu_min;		/* mi_rw_lock */
459 	uint_t			mi_sdu_max;		/* mi_rw_lock */
460 
461 	/*
462 	 * Cache of factory MAC addresses provided by the driver. If
463 	 * the driver doesn't provide multiple factory MAC addresses,
464 	 * the mi_factory_addr is set to NULL, and mi_factory_addr_num
465 	 * is set to zero.
466 	 */
467 	mac_factory_addr_t	*mi_factory_addr;	/* mi_rw_lock */
468 	uint_t			mi_factory_addr_num;	/* mi_rw_lock */
469 
470 	/* for promiscuous mode support */
471 	kmutex_t		mi_promisc_lock;
472 	mac_cb_t		*mi_promisc_list;	/* mi_promisc_lock */
473 	mac_cb_info_t		mi_promisc_cb_info;	/* mi_promisc_lock */
474 
475 	/* cache of rings over this mac_impl */
476 	kmutex_t		mi_ring_lock;
477 	mac_ring_t		*mi_ring_freelist;	/* mi_ring_lock */
478 
479 	/*
480 	 * These are used for caching the properties, if any, for the
481 	 * primary MAC client. If the MAC client is not yet in place
482 	 * when the properties are set then we cache them here to be
483 	 * applied to the MAC client when it is created.
484 	 */
485 	mac_resource_props_t	mi_resource_props;	/* SL */
486 	uint16_t		mi_pvid;		/* SL */
487 
488 	minor_t			mi_minor;		/* WO */
489 	uint32_t		mi_oref;		/* SL */
490 	mac_capab_legacy_t	mi_capab_legacy;	/* WO */
491 	dev_t			mi_phy_dev;		/* WO */
492 
493 	/*
494 	 * List of margin value requests added by mac clients. This list is
495 	 * sorted: the first one has the greatest value.
496 	 */
497 	mac_margin_req_t	*mi_mmrp;
498 	mac_priv_prop_t		*mi_priv_prop;
499 	uint_t			mi_priv_prop_count;
500 
501 	/*
502 	 * Hybrid I/O related definitions.
503 	 */
504 	mac_capab_share_t	mi_share_capab;
505 
506 	/*
507 	 * Bridging hooks and limit values.  Uses mutex and reference counts
508 	 * (bridging only) for data path.  Limits need no synchronization.
509 	 */
510 	mac_handle_t		mi_bridge_link;
511 	kmutex_t		mi_bridge_lock;
512 	uint32_t		mi_llimit;
513 	uint32_t		mi_ldecay;
514 
515 /* This should be the last block in this structure */
516 #ifdef DEBUG
517 #define	MAC_PERIM_STACK_DEPTH	15
518 	int			mi_perim_stack_depth;
519 	pc_t			mi_perim_stack[MAC_PERIM_STACK_DEPTH];
520 #endif
521 };
522 
523 /* for mi_state_flags */
524 #define	MIS_DISABLED		0x0001
525 #define	MIS_IS_VNIC		0x0002
526 #define	MIS_IS_AGGR		0x0004
527 #define	MIS_NOTIFY_DONE		0x0008
528 #define	MIS_EXCLUSIVE		0x0010
529 #define	MIS_EXCLUSIVE_HELD	0x0020
530 #define	MIS_LEGACY		0x0040
531 #define	MIS_NO_ACTIVE		0x0080
532 #define	MIS_POLL_DISABLE	0x0100
533 
534 #define	mi_getstat	mi_callbacks->mc_getstat
535 #define	mi_start	mi_callbacks->mc_start
536 #define	mi_stop		mi_callbacks->mc_stop
537 #define	mi_open		mi_callbacks->mc_open
538 #define	mi_close	mi_callbacks->mc_close
539 #define	mi_setpromisc	mi_callbacks->mc_setpromisc
540 #define	mi_multicst	mi_callbacks->mc_multicst
541 #define	mi_unicst	mi_callbacks->mc_unicst
542 #define	mi_tx		mi_callbacks->mc_tx
543 #define	mi_ioctl	mi_callbacks->mc_ioctl
544 #define	mi_getcapab	mi_callbacks->mc_getcapab
545 
546 typedef struct mac_notify_task_arg {
547 	mac_impl_t		*mnt_mip;
548 	mac_notify_type_t	mnt_type;
549 	mac_ring_t		*mnt_ring;
550 } mac_notify_task_arg_t;
551 
552 typedef enum {
553 	MAC_RX_NO_RESERVE,
554 	MAC_RX_RESERVE_DEFAULT,
555 	MAC_RX_RESERVE_NONDEFAULT
556 } mac_rx_group_reserve_type_t;
557 
558 /*
559  * XXX All MAC_DBG_PRTs must be replaced with call to dtrace probes. For now
560  * it may be easier to have these printfs for easier debugging
561  */
562 #ifdef DEBUG
563 extern int mac_dbg;
564 #define	MAC_DBG_PRT(a)	if (mac_dbg > 0) {(void) printf a; }
565 #else
566 #define	MAC_DBG_PRT(a)
567 #endif
568 
569 /*
570  * The mac_perim_handle_t is an opaque type that encodes the 'mip' pointer
571  * and whether internally a mac_open was done when acquiring the perimeter.
572  */
573 #define	MAC_ENCODE_MPH(mph, mh, need_close)		\
574 	(mph) = (mac_perim_handle_t)((uintptr_t)(mh) | need_close)
575 
576 #define	MAC_DECODE_MPH(mph, mip, need_close) {		\
577 	mip = (mac_impl_t *)(((uintptr_t)mph) & ~0x1);	\
578 	(need_close) = ((uintptr_t)mph & 0x1);		\
579 }
580 
581 typedef struct mac_client_impl_s mac_client_impl_t;
582 
583 extern void	mac_init(void);
584 extern int	mac_fini(void);
585 
586 extern void	mac_stat_create(mac_impl_t *);
587 extern void	mac_stat_destroy(mac_impl_t *);
588 extern uint64_t	mac_stat_default(mac_impl_t *, uint_t);
589 extern void	mac_ndd_ioctl(mac_impl_t *, queue_t *, mblk_t *);
590 extern void	mac_create_soft_ring_kstats(mac_impl_t *, int32_t);
591 extern boolean_t mac_ip_hdr_length_v6(mblk_t *, ip6_t *, uint16_t *,
592     uint8_t *);
593 
594 extern mblk_t *mac_copymsgchain_cksum(mblk_t *);
595 extern mblk_t *mac_fix_cksum(mblk_t *);
596 extern void mac_packet_print(mac_handle_t, mblk_t *);
597 extern void mac_rx_deliver(void *, mac_resource_handle_t, mblk_t *,
598     mac_header_info_t *);
599 extern void mac_tx_notify(mac_impl_t *);
600 
601 extern	boolean_t mac_callback_find(mac_cb_info_t *, mac_cb_t **, mac_cb_t *);
602 extern	void	mac_callback_add(mac_cb_info_t *, mac_cb_t **, mac_cb_t *);
603 extern	boolean_t mac_callback_remove(mac_cb_info_t *, mac_cb_t **, mac_cb_t *);
604 extern	void	mac_callback_remove_wait(mac_cb_info_t *);
605 extern	void	mac_callback_free(mac_cb_t *);
606 extern	mac_cb_t *mac_callback_walker_cleanup(mac_cb_info_t *, mac_cb_t **);
607 
608 /* in mac_bcast.c */
609 extern void mac_bcast_init(void);
610 extern void mac_bcast_fini(void);
611 extern mac_impl_t *mac_bcast_grp_mip(void *);
612 extern int mac_bcast_add(mac_client_impl_t *, const uint8_t *, uint16_t,
613     mac_addrtype_t);
614 extern void mac_bcast_delete(mac_client_impl_t *, const uint8_t *, uint16_t);
615 extern void mac_bcast_send(void *, void *, mblk_t *, boolean_t);
616 extern void mac_bcast_grp_free(void *);
617 extern void mac_bcast_refresh(mac_impl_t *, mac_multicst_t, void *,
618     boolean_t);
619 extern void mac_client_bcast_refresh(mac_client_impl_t *, mac_multicst_t,
620     void *, boolean_t);
621 
622 /*
623  * Grouping functions are used internally by MAC layer.
624  */
625 extern int mac_group_addmac(mac_group_t *, const uint8_t *);
626 extern int mac_group_remmac(mac_group_t *, const uint8_t *);
627 extern int mac_rx_group_add_flow(mac_client_impl_t *, flow_entry_t *,
628     mac_group_t *);
629 extern mblk_t *mac_hwring_tx(mac_ring_handle_t, mblk_t *);
630 extern mblk_t *mac_bridge_tx(mac_impl_t *, mac_ring_handle_t, mblk_t *);
631 extern mac_ring_t *mac_reserve_tx_ring(mac_impl_t *, mac_ring_t *);
632 extern void mac_release_tx_ring(mac_ring_handle_t);
633 extern mac_group_t *mac_reserve_tx_group(mac_impl_t *, mac_share_handle_t);
634 extern void mac_release_tx_group(mac_impl_t *, mac_group_t *);
635 
636 /*
637  * MAC address functions are used internally by MAC layer.
638  */
639 extern mac_address_t *mac_find_macaddr(mac_impl_t *, uint8_t *);
640 extern boolean_t mac_check_macaddr_shared(mac_address_t *);
641 extern int mac_update_macaddr(mac_address_t *, uint8_t *);
642 extern void mac_freshen_macaddr(mac_address_t *, uint8_t *);
643 extern void mac_retrieve_macaddr(mac_address_t *, uint8_t *);
644 extern void mac_init_macaddr(mac_impl_t *);
645 extern void mac_fini_macaddr(mac_impl_t *);
646 
647 /*
648  * Flow construction/destruction routines.
649  * Not meant to be used by mac clients.
650  */
651 extern int mac_link_flow_init(mac_client_handle_t, flow_entry_t *);
652 extern void mac_link_flow_clean(mac_client_handle_t, flow_entry_t *);
653 
654 /*
655  * Fanout update routines called when the link speed of the NIC changes
656  * or when a MAC client's share is unbound.
657  */
658 extern void mac_fanout_recompute_client(mac_client_impl_t *);
659 extern void mac_fanout_recompute(mac_impl_t *);
660 
661 /*
662  * The following functions are used internally by the MAC layer to
663  * add/remove/update flows associated with a mac_impl_t. They should
664  * never be used directly by MAC clients.
665  */
666 extern int mac_datapath_setup(mac_client_impl_t *, flow_entry_t *, uint32_t);
667 extern void mac_datapath_teardown(mac_client_impl_t *, flow_entry_t *,
668     uint32_t);
669 extern void mac_srs_group_setup(mac_client_impl_t *, flow_entry_t *,
670     mac_group_t *, uint32_t);
671 extern void mac_srs_group_teardown(mac_client_impl_t *, flow_entry_t *,
672 	    uint32_t);
673 extern int mac_rx_classify_flow_quiesce(flow_entry_t *, void *);
674 extern int mac_rx_classify_flow_restart(flow_entry_t *, void *);
675 extern void mac_tx_client_quiesce(mac_client_impl_t *, uint_t);
676 extern void mac_tx_client_restart(mac_client_impl_t *);
677 extern void mac_client_quiesce(mac_client_impl_t *);
678 extern void mac_client_restart(mac_client_impl_t *);
679 
680 extern void mac_flow_update_priority(mac_client_impl_t *, flow_entry_t *);
681 
682 extern void mac_flow_rem_subflow(flow_entry_t *);
683 extern void mac_rename_flow(flow_entry_t *, const char *);
684 extern void mac_flow_set_name(flow_entry_t *, const char *);
685 
686 extern mblk_t *mac_add_vlan_tag(mblk_t *, uint_t, uint16_t);
687 extern mblk_t *mac_add_vlan_tag_chain(mblk_t *, uint_t, uint16_t);
688 extern mblk_t *mac_strip_vlan_tag_chain(mblk_t *);
689 extern void mac_pkt_drop(void *, mac_resource_handle_t, mblk_t *, boolean_t);
690 extern mblk_t *mac_rx_flow(mac_handle_t, mac_resource_handle_t, mblk_t *);
691 
692 extern void i_mac_share_alloc(mac_client_impl_t *);
693 extern void i_mac_share_free(mac_client_impl_t *);
694 extern void i_mac_perim_enter(mac_impl_t *);
695 extern void i_mac_perim_exit(mac_impl_t *);
696 extern int i_mac_perim_enter_nowait(mac_impl_t *);
697 extern void i_mac_tx_srs_notify(mac_impl_t *, mac_ring_handle_t);
698 extern int mac_hold(const char *, mac_impl_t **);
699 extern void mac_rele(mac_impl_t *);
700 extern int i_mac_disable(mac_impl_t *);
701 extern void i_mac_notify(mac_impl_t *, mac_notify_type_t);
702 extern void i_mac_notify_exit(mac_impl_t *);
703 extern void mac_rx_group_unmark(mac_group_t *, uint_t);
704 extern void mac_tx_client_flush(mac_client_impl_t *);
705 extern void mac_tx_client_block(mac_client_impl_t *);
706 extern void mac_tx_client_unblock(mac_client_impl_t *);
707 extern int i_mac_promisc_set(mac_impl_t *, boolean_t);
708 extern void i_mac_promisc_walker_cleanup(mac_impl_t *);
709 extern mactype_t *mactype_getplugin(const char *);
710 extern void mac_addr_factory_init(mac_impl_t *);
711 extern void mac_addr_factory_fini(mac_impl_t *);
712 extern void mac_register_priv_prop(mac_impl_t *, mac_priv_prop_t *, uint_t);
713 extern void mac_unregister_priv_prop(mac_impl_t *);
714 extern int mac_init_rings(mac_impl_t *, mac_ring_type_t);
715 extern void mac_free_rings(mac_impl_t *, mac_ring_type_t);
716 
717 extern int mac_start_group(mac_group_t *);
718 extern void mac_stop_group(mac_group_t *);
719 extern int mac_start_ring(mac_ring_t *);
720 extern void mac_stop_ring(mac_ring_t *);
721 extern int mac_add_macaddr(mac_impl_t *, mac_group_t *, uint8_t *, boolean_t);
722 extern int mac_remove_macaddr(mac_address_t *);
723 
724 extern void mac_set_rx_group_state(mac_group_t *, mac_group_state_t);
725 extern void mac_rx_group_add_client(mac_group_t *, mac_client_impl_t *);
726 extern void mac_rx_group_remove_client(mac_group_t *, mac_client_impl_t *)
727 ;
728 extern int i_mac_group_add_ring(mac_group_t *, mac_ring_t *, int);
729 extern void i_mac_group_rem_ring(mac_group_t *, mac_ring_t *, boolean_t);
730 
731 extern void mac_poll_state_change(mac_handle_t, boolean_t);
732 
733 /* Global callbacks into the bridging module (when loaded) */
734 extern mac_bridge_tx_t mac_bridge_tx_cb;
735 extern mac_bridge_rx_t mac_bridge_rx_cb;
736 extern mac_bridge_ref_t mac_bridge_ref_cb;
737 extern mac_bridge_ls_t mac_bridge_ls_cb;
738 
739 #ifdef	__cplusplus
740 }
741 #endif
742 
743 #endif	/* _SYS_MAC_IMPL_H */
744