xref: /illumos-gate/usr/src/uts/common/sys/mac_impl.h (revision 628e3cbed6489fa1db545d8524a06cd6535af456)
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 2008 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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <sys/mac.h>
32 #include <net/if.h>
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 typedef struct mac_multicst_addr_s	mac_multicst_addr_t;
39 
40 struct mac_multicst_addr_s {
41 	mac_multicst_addr_t	*mma_nextp;
42 	uint_t			mma_ref;
43 	uint8_t			mma_addr[MAXMACADDRLEN];
44 };
45 
46 typedef struct mac_margin_req_s	mac_margin_req_t;
47 
48 struct mac_margin_req_s {
49 	mac_margin_req_t	*mmr_nextp;
50 	uint_t			mmr_ref;
51 	uint32_t		mmr_margin;
52 };
53 
54 typedef struct mac_notify_fn_s		mac_notify_fn_t;
55 
56 struct mac_notify_fn_s {
57 	mac_notify_fn_t		*mnf_nextp;
58 	mac_notify_t		mnf_fn;
59 	void			*mnf_arg;
60 };
61 
62 typedef struct mac_rx_fn_s		mac_rx_fn_t;
63 
64 struct mac_rx_fn_s {
65 	mac_rx_fn_t		*mrf_nextp;
66 	mac_rx_t		mrf_fn;
67 	void			*mrf_arg;
68 	boolean_t		mrf_inuse;
69 	boolean_t		mrf_active;
70 };
71 
72 typedef struct mac_txloop_fn_s		mac_txloop_fn_t;
73 
74 struct mac_txloop_fn_s {
75 	mac_txloop_fn_t		*mtf_nextp;
76 	mac_txloop_t		mtf_fn;
77 	void			*mtf_arg;
78 };
79 
80 typedef struct mactype_s {
81 	const char	*mt_ident;
82 	uint32_t	mt_ref;
83 	uint_t		mt_type;
84 	uint_t		mt_nativetype;
85 	size_t		mt_addr_length;
86 	uint8_t		*mt_brdcst_addr;
87 	mactype_ops_t	mt_ops;
88 	mac_stat_info_t	*mt_stats;	/* array of mac_stat_info_t elements */
89 	size_t		mt_statcount;	/* number of elements in mt_stats */
90 	mac_ndd_mapping_t *mt_mapping;
91 	size_t		mt_mappingcount;
92 } mactype_t;
93 
94 
95 #define	MAC_VNIC_TXINFO_REFHOLD(mvt) {				\
96 	mutex_enter(&(mvt)->mv_lock);				\
97 	(mvt)->mv_refs++;					\
98 	mutex_exit(&(mvt)->mv_lock);				\
99 }
100 
101 #define	MAC_VNIC_TXINFO_REFRELE(mvt) {				\
102 	mutex_enter(&(mvt)->mv_lock);				\
103 	if (--(mvt)->mv_refs == 0 && (mvt)->mv_clearing) {	\
104 	    (mvt)->mv_clearing = B_FALSE;			\
105 	    cv_signal(&(mvt)->mv_cv);				\
106 	}							\
107 	mutex_exit(&(mvt)->mv_lock);				\
108 }
109 
110 typedef struct mac_vnic_tx_s {
111 	mac_txinfo_t	mv_txinfo;	/* provided by VNIC */
112 	uint32_t	mv_refs;
113 	kmutex_t	mv_lock;
114 	kcondvar_t	mv_cv;
115 	boolean_t	mv_clearing;
116 } mac_vnic_tx_t;
117 
118 
119 /*
120  * Each registered MAC is associated with a mac_t structure.
121  */
122 typedef struct mac_impl_s {
123 	/*
124 	 * The following fields are set in mac_register() and will not be
125 	 * changed until mac_unregister(). No lock is needed to access them.
126 	 */
127 	char			mi_name[LIFNAMSIZ];
128 	void			*mi_driver;	/* Driver private data */
129 	mac_info_t		mi_info;
130 	mactype_t		*mi_type;
131 	void			*mi_pdata;
132 	size_t			mi_pdata_size;
133 	mac_callbacks_t		*mi_callbacks;
134 	dev_info_t		*mi_dip;
135 	minor_t			mi_minor;
136 	dev_t			mi_phy_dev;
137 	kstat_t			*mi_ksp;
138 	uint_t			mi_kstat_count;
139 	mac_txinfo_t		mi_txinfo;
140 	mac_txinfo_t		mi_txloopinfo;
141 
142 	krwlock_t		mi_gen_lock;
143 	uint32_t		mi_oref;
144 	uint32_t		mi_ref;
145 	boolean_t		mi_disabled;
146 	boolean_t		mi_exclusive;
147 
148 	krwlock_t		mi_state_lock;
149 	uint_t			mi_active;
150 
151 	krwlock_t		mi_data_lock;
152 	link_state_t		mi_linkstate;
153 	link_state_t		mi_lastlinkstate;
154 	uint_t			mi_promisc;
155 	uint_t			mi_devpromisc;
156 	uint8_t			mi_addr[MAXMACADDRLEN];
157 	uint8_t			mi_dstaddr[MAXMACADDRLEN];
158 	uint_t			mi_sdu_min;
159 	uint_t			mi_sdu_max;
160 	mac_multicst_addr_t	*mi_mmap;
161 
162 	krwlock_t		mi_notify_lock;
163 	uint32_t		mi_notify_bits;
164 	kmutex_t		mi_notify_bits_lock;
165 	kthread_t		*mi_notify_thread;
166 	mac_notify_fn_t		*mi_mnfp;
167 	kcondvar_t		mi_notify_cv;
168 
169 	krwlock_t		mi_rx_lock;
170 	mac_rx_fn_t		*mi_mrfp;
171 	krwlock_t		mi_tx_lock;
172 	mac_txloop_fn_t		*mi_mtfp;
173 
174 	krwlock_t		mi_resource_lock;
175 	mac_resource_add_t	mi_resource_add;
176 	void			*mi_resource_add_arg;
177 
178 	kmutex_t		mi_activelink_lock;
179 	boolean_t		mi_activelink;
180 
181 	uint32_t		mi_rx_ref;	/* #threads in mac_rx() */
182 	uint32_t		mi_rx_removed;	/* #callbacks marked */
183 						/* for removal */
184 	kmutex_t		mi_lock;
185 	kcondvar_t		mi_rx_cv;
186 	boolean_t		mi_shareable;
187 	boolean_t		mi_vnic_present;
188 	mac_vnic_tx_t		*mi_vnic_tx;
189 	mac_txinfo_t		mi_vnic_txinfo;
190 	mac_txinfo_t		mi_vnic_txloopinfo;
191 	mac_getcapab_t		mi_vnic_getcapab_fn;
192 	void			*mi_vnic_getcapab_arg;
193 
194 	boolean_t		mi_legacy;
195 	uint32_t		mi_unsup_note;
196 	uint32_t		mi_margin;
197 
198 	/*
199 	 * List of margin value requests added by mac clients. This list is
200 	 * sorted: the first one has the greatest value.
201 	 */
202 	mac_margin_req_t	*mi_mmrp;
203 	mac_priv_prop_t		*mi_priv_prop;
204 	uint_t			mi_priv_prop_count;
205 } mac_impl_t;
206 
207 #define	mi_getstat	mi_callbacks->mc_getstat
208 #define	mi_start	mi_callbacks->mc_start
209 #define	mi_stop		mi_callbacks->mc_stop
210 #define	mi_open		mi_callbacks->mc_open
211 #define	mi_close	mi_callbacks->mc_close
212 #define	mi_setpromisc	mi_callbacks->mc_setpromisc
213 #define	mi_multicst	mi_callbacks->mc_multicst
214 #define	mi_unicst	mi_callbacks->mc_unicst
215 #define	mi_resources	mi_callbacks->mc_resources
216 #define	mi_tx		mi_callbacks->mc_tx
217 #define	mi_ioctl	mi_callbacks->mc_ioctl
218 #define	mi_getcapab	mi_callbacks->mc_getcapab
219 
220 extern void	mac_init(void);
221 extern int	mac_fini(void);
222 
223 extern void	mac_stat_create(mac_impl_t *);
224 extern void	mac_stat_destroy(mac_impl_t *);
225 extern uint64_t	mac_stat_default(mac_impl_t *, uint_t);
226 
227 extern void mac_ndd_ioctl(mac_impl_t *, queue_t *, mblk_t *);
228 
229 #ifdef	__cplusplus
230 }
231 #endif
232 
233 #endif	/* _SYS_MAC_IMPL_H */
234