xref: /titanic_52/usr/src/uts/common/sys/mac_impl.h (revision 4d86dd30d2f1154ded30a45ac7c3a29f7febabac)
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 } mactype_t;
91 
92 
93 #define	MAC_VNIC_TXINFO_REFHOLD(mvt) {				\
94 	mutex_enter(&(mvt)->mv_lock);				\
95 	(mvt)->mv_refs++;					\
96 	mutex_exit(&(mvt)->mv_lock);				\
97 }
98 
99 #define	MAC_VNIC_TXINFO_REFRELE(mvt) {				\
100 	mutex_enter(&(mvt)->mv_lock);				\
101 	if (--(mvt)->mv_refs == 0 && (mvt)->mv_clearing) {	\
102 	    (mvt)->mv_clearing = B_FALSE;			\
103 	    cv_signal(&(mvt)->mv_cv);				\
104 	}							\
105 	mutex_exit(&(mvt)->mv_lock);				\
106 }
107 
108 typedef struct mac_vnic_tx_s {
109 	mac_txinfo_t	mv_txinfo;	/* provided by VNIC */
110 	uint32_t	mv_refs;
111 	kmutex_t	mv_lock;
112 	kcondvar_t	mv_cv;
113 	boolean_t	mv_clearing;
114 } mac_vnic_tx_t;
115 
116 /*
117  * Each registered MAC is associated with a mac_t structure.
118  */
119 typedef struct mac_impl_s {
120 	/*
121 	 * The following fields are set in mac_register() and will not be
122 	 * changed until mac_unregister(). No lock is needed to access them.
123 	 */
124 	char			mi_name[LIFNAMSIZ];
125 	void			*mi_driver;	/* Driver private data */
126 	mac_info_t		mi_info;
127 	mactype_t		*mi_type;
128 	void			*mi_pdata;
129 	size_t			mi_pdata_size;
130 	mac_callbacks_t		*mi_callbacks;
131 	dev_info_t		*mi_dip;
132 	minor_t			mi_minor;
133 	dev_t			mi_phy_dev;
134 	kstat_t			*mi_ksp;
135 	uint_t			mi_kstat_count;
136 	mac_txinfo_t		mi_txinfo;
137 	mac_txinfo_t		mi_txloopinfo;
138 
139 	krwlock_t		mi_gen_lock;
140 	uint32_t		mi_oref;
141 	uint32_t		mi_ref;
142 	boolean_t		mi_disabled;
143 	boolean_t		mi_exclusive;
144 
145 	krwlock_t		mi_state_lock;
146 	uint_t			mi_active;
147 
148 	krwlock_t		mi_data_lock;
149 	link_state_t		mi_linkstate;
150 	link_state_t		mi_lastlinkstate;
151 	uint_t			mi_promisc;
152 	uint_t			mi_devpromisc;
153 	uint8_t			mi_addr[MAXMACADDRLEN];
154 	uint8_t			mi_dstaddr[MAXMACADDRLEN];
155 	uint_t			mi_sdu_min;
156 	uint_t			mi_sdu_max;
157 	mac_multicst_addr_t	*mi_mmap;
158 
159 	krwlock_t		mi_notify_lock;
160 	uint32_t		mi_notify_bits;
161 	kmutex_t		mi_notify_bits_lock;
162 	kthread_t		*mi_notify_thread;
163 	mac_notify_fn_t		*mi_mnfp;
164 	kcondvar_t		mi_notify_cv;
165 
166 	krwlock_t		mi_rx_lock;
167 	mac_rx_fn_t		*mi_mrfp;
168 	krwlock_t		mi_tx_lock;
169 	mac_txloop_fn_t		*mi_mtfp;
170 
171 	krwlock_t		mi_resource_lock;
172 	mac_resource_add_t	mi_resource_add;
173 	void			*mi_resource_add_arg;
174 
175 	kmutex_t		mi_activelink_lock;
176 	boolean_t		mi_activelink;
177 
178 	uint32_t		mi_rx_ref;	/* #threads in mac_rx() */
179 	uint32_t		mi_rx_removed;	/* #callbacks marked */
180 						/* for removal */
181 	kmutex_t		mi_lock;
182 	kcondvar_t		mi_rx_cv;
183 	boolean_t		mi_shareable;
184 	boolean_t		mi_vnic_present;
185 	mac_vnic_tx_t		*mi_vnic_tx;
186 	mac_txinfo_t		mi_vnic_txinfo;
187 	mac_txinfo_t		mi_vnic_txloopinfo;
188 	mac_getcapab_t		mi_vnic_getcapab_fn;
189 	void			*mi_vnic_getcapab_arg;
190 
191 	boolean_t		mi_legacy;
192 	uint32_t		mi_unsup_note;
193 	uint32_t		mi_margin;
194 
195 	/*
196 	 * List of margin value requests added by mac clients. This list is
197 	 * sorted: the first one has the greatest value.
198 	 */
199 	mac_margin_req_t	*mi_mmrp;
200 } mac_impl_t;
201 
202 #define	mi_getstat	mi_callbacks->mc_getstat
203 #define	mi_start	mi_callbacks->mc_start
204 #define	mi_stop		mi_callbacks->mc_stop
205 #define	mi_open		mi_callbacks->mc_open
206 #define	mi_close	mi_callbacks->mc_close
207 #define	mi_setpromisc	mi_callbacks->mc_setpromisc
208 #define	mi_multicst	mi_callbacks->mc_multicst
209 #define	mi_unicst	mi_callbacks->mc_unicst
210 #define	mi_resources	mi_callbacks->mc_resources
211 #define	mi_tx		mi_callbacks->mc_tx
212 #define	mi_ioctl	mi_callbacks->mc_ioctl
213 #define	mi_getcapab	mi_callbacks->mc_getcapab
214 
215 extern void	mac_init(void);
216 extern int	mac_fini(void);
217 
218 extern void	mac_stat_create(mac_impl_t *);
219 extern void	mac_stat_destroy(mac_impl_t *);
220 extern uint64_t	mac_stat_default(mac_impl_t *, uint_t);
221 
222 #ifdef	__cplusplus
223 }
224 #endif
225 
226 #endif	/* _SYS_MAC_IMPL_H */
227