xref: /titanic_41/usr/src/uts/common/sys/dld_impl.h (revision 82b5053fd84070f027436bc66665b7c0fd416e85)
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_DLD_IMPL_H
27 #define	_SYS_DLD_IMPL_H
28 
29 #include <sys/types.h>
30 #include <sys/conf.h>
31 #include <sys/ethernet.h>
32 #include <sys/stream.h>
33 #include <sys/dlpi.h>
34 #include <sys/mac.h>
35 #include <sys/dls.h>
36 #include <sys/dld.h>
37 
38 #ifdef	__cplusplus
39 extern "C" {
40 #endif
41 
42 #define	DLD_CONTROL_MINOR_NAME	"ctl"
43 #define	DLD_CONTROL_MINOR	0
44 
45 #define	DLD_CONTROL	0x00000001
46 #define	DLD_DLPI	0x00000002
47 
48 typedef enum {
49 	DLD_UNITDATA,
50 	DLD_FASTPATH,
51 	DLD_RAW
52 } dld_str_mode_t;
53 
54 typedef enum {
55 	DLD_UNINITIALIZED,
56 	DLD_PASSIVE,
57 	DLD_ACTIVE
58 } dld_passivestate_t;
59 
60 typedef struct dld_str	dld_str_t;
61 typedef void		(*dld_tx_t)(struct dld_str *, mblk_t *);
62 
63 /*
64  * dld_str_t object definition.
65  */
66 struct dld_str {
67 	/*
68 	 * Major number of the device
69 	 */
70 	major_t			ds_major;
71 
72 	/*
73 	 * Ephemeral minor number for the object.
74 	 */
75 	minor_t			ds_minor;
76 
77 	/*
78 	 * Read/write queues for the stream which the object represents.
79 	 */
80 	queue_t			*ds_rq;
81 	queue_t			*ds_wq;
82 
83 	/*
84 	 * Lock to protect this structure.
85 	 */
86 	krwlock_t		ds_lock;
87 
88 	/*
89 	 * Stream is open to DLD_CONTROL (control node) or
90 	 * DLD_DLPI (DLS provider) node.
91 	 */
92 	uint_t			ds_type;
93 
94 	/*
95 	 * The following fields are only used for DLD_DLPI type objects.
96 	 */
97 
98 	/*
99 	 * Current DLPI state.
100 	 */
101 	t_uscalar_t		ds_dlstate;
102 
103 	/*
104 	 * DLPI style
105 	 */
106 	t_uscalar_t		ds_style;
107 
108 	/*
109 	 * Currently bound DLSAP.
110 	 */
111 	uint16_t		ds_sap;
112 
113 	/*
114 	 * Handle of the data-link channel that is used by this object.
115 	 */
116 	dls_channel_t		ds_dc;
117 
118 	/*
119 	 * Handle of the MAC that is used by the data-link interface.
120 	 */
121 	mac_handle_t		ds_mh;
122 
123 	/*
124 	 * VLAN identifier of the data-link interface.
125 	 */
126 	uint16_t		ds_vid;
127 
128 	/*
129 	 * Promiscuity level information.
130 	 */
131 	uint32_t		ds_promisc;
132 
133 	/*
134 	 * Immutable information of the MAC which the channel is using.
135 	 */
136 	const mac_info_t	*ds_mip;
137 
138 	/*
139 	 * Current packet priority.
140 	 */
141 	uint_t			ds_pri;
142 
143 	/*
144 	 * Handle of our MAC notification callback.
145 	 */
146 	mac_notify_handle_t	ds_mnh;
147 
148 	/*
149 	 * Set of enabled DL_NOTE... notifications. (See dlpi.h).
150 	 */
151 	uint32_t		ds_notifications;
152 
153 	/*
154 	 * Cached MAC unicast addresses.
155 	 */
156 	uint8_t			ds_fact_addr[MAXMACADDRLEN];
157 	uint8_t			ds_curr_addr[MAXMACADDRLEN];
158 
159 	/*
160 	 * Mode: unitdata, fast-path or raw.
161 	 */
162 	dld_str_mode_t		ds_mode;
163 
164 	/*
165 	 * Native mode state.
166 	 */
167 	boolean_t		ds_native;
168 
169 	/*
170 	 * IP polling is operational if this flag is set.
171 	 */
172 	boolean_t		ds_polling;
173 	boolean_t		ds_soft_ring;
174 
175 	/*
176 	 * LSO is enabled if ds_lso is set.
177 	 */
178 	boolean_t		ds_lso;
179 	uint64_t		ds_lso_max;
180 
181 	/*
182 	 * State of DLPI user: may be active (regular network layer),
183 	 * passive (snoop-like monitoring), or unknown (not yet
184 	 * determined).
185 	 */
186 	dld_passivestate_t	ds_passivestate;
187 
188 	/*
189 	 * Dummy mblk used for flow-control.
190 	 */
191 	mblk_t			*ds_tx_flow_mp;
192 
193 	/*
194 	 * Internal transmit queue and its parameters.
195 	 */
196 	kmutex_t		ds_tx_list_lock;
197 	mblk_t			*ds_tx_list_head;
198 	mblk_t			*ds_tx_list_tail;
199 	uint_t			ds_tx_cnt;
200 	uint_t			ds_tx_msgcnt;
201 	timeout_id_t		ds_tx_qdepth_tid;
202 	boolean_t		ds_tx_qbusy;
203 
204 	dld_tx_t		ds_tx;
205 	dld_tx_t		ds_unitdata_tx;
206 	kmutex_t		ds_tx_lock;
207 	kcondvar_t		ds_tx_cv;
208 	uint32_t		ds_intx_cnt;
209 	boolean_t		ds_detaching;
210 
211 	/*
212 	 * Pending control messages to be processed.
213 	 */
214 	mblk_t			*ds_pending_head;
215 	mblk_t			*ds_pending_tail;
216 
217 	taskqid_t		ds_tid;
218 	kmutex_t		ds_disp_lock;
219 	kcondvar_t		ds_disp_cv;
220 	boolean_t		ds_closing;
221 
222 	/*
223 	 * Used to process ioctl message for control node. See comments
224 	 * above dld_ioctl().
225 	 */
226 	void			(*ds_ioctl)(queue_t *, mblk_t *);
227 };
228 
229 #define	DLD_TX_ENTER(dsp) {					\
230 	mutex_enter(&(dsp)->ds_tx_lock);			\
231 	(dsp)->ds_intx_cnt++;					\
232 	mutex_exit(&(dsp)->ds_tx_lock);				\
233 }
234 
235 #define	DLD_TX_EXIT(dsp) {					\
236 	mutex_enter(&(dsp)->ds_tx_lock);			\
237 	if ((--(dsp)->ds_intx_cnt == 0) && (dsp)->ds_detaching)	\
238 		cv_signal(&(dsp)->ds_tx_cv);			\
239 	mutex_exit(&(dsp)->ds_tx_lock);				\
240 }
241 
242 /*
243  * Quiesce the traffic.
244  */
245 #define	DLD_TX_QUIESCE(dsp) {						\
246 	mutex_enter(&(dsp)->ds_tx_lock);				\
247 	(dsp)->ds_tx = (dsp)->ds_unitdata_tx = NULL;			\
248 	(dsp)->ds_detaching = B_TRUE;					\
249 	while ((dsp)->ds_intx_cnt != 0)					\
250 		cv_wait(&(dsp)->ds_tx_cv, &(dsp)->ds_tx_lock);		\
251 	(dsp)->ds_detaching = B_FALSE;					\
252 	mutex_exit(&(dsp)->ds_tx_lock);					\
253 }
254 
255 /*
256  * dld_str.c module.
257  */
258 
259 extern void		dld_str_init(void);
260 extern int		dld_str_fini(void);
261 extern dld_str_t	*dld_str_create(queue_t *, uint_t, major_t,
262     t_uscalar_t);
263 extern void		dld_str_destroy(dld_str_t *);
264 extern int		dld_str_attach(dld_str_t *, t_uscalar_t);
265 extern void		dld_str_detach(dld_str_t *);
266 extern void		dld_str_rx_raw(void *, mac_resource_handle_t,
267     mblk_t *, mac_header_info_t *);
268 extern void		dld_str_rx_fastpath(void *, mac_resource_handle_t,
269     mblk_t *, mac_header_info_t *);
270 extern void		dld_str_rx_unitdata(void *, mac_resource_handle_t,
271     mblk_t *, mac_header_info_t *);
272 
273 extern void		dld_tx_flush(dld_str_t *);
274 extern void		dld_str_notify_ind(dld_str_t *);
275 extern void		dld_tx_single(dld_str_t *, mblk_t *);
276 extern void		str_mdata_fastpath_put(dld_str_t *, mblk_t *);
277 extern void		str_mdata_raw_put(dld_str_t *, mblk_t *);
278 
279 extern void		dld_ioctl(queue_t *, mblk_t *);
280 extern void		dld_finish_pending_task(dld_str_t *);
281 
282 /*
283  * dld_proto.c
284  */
285 extern void		dld_wput_proto_nondata(dld_str_t *, mblk_t *);
286 extern void		dld_wput_proto_data(dld_str_t *, mblk_t *);
287 extern void		dld_capabilities_disable(dld_str_t *);
288 
289 /*
290  * Options: there should be a separate bit defined here for each
291  *	  DLD_PROP... defined in dld.h.
292  */
293 #define	DLD_OPT_NO_FASTPATH	0x00000001
294 #define	DLD_OPT_NO_POLL		0x00000002
295 #define	DLD_OPT_NO_ZEROCOPY	0x00000004
296 #define	DLD_OPT_NO_SOFTRING	0x00000008
297 
298 extern uint32_t		dld_opt;
299 
300 /*
301  * autopush information
302  */
303 typedef struct dld_ap {
304 	datalink_id_t		da_linkid;
305 	struct dlautopush	da_ap;
306 
307 #define	da_anchor		da_ap.dap_anchor
308 #define	da_npush		da_ap.dap_npush
309 #define	da_aplist		da_ap.dap_aplist
310 
311 } dld_ap_t;
312 
313 /*
314  * Useful macros.
315  */
316 
317 #define	IMPLY(p, c)	(!(p) || (c))
318 
319 #ifdef DEBUG
320 #define	DLD_DBG		cmn_err
321 #else
322 #define	DLD_DBG		if (0) cmn_err
323 #endif
324 
325 #ifdef	__cplusplus
326 }
327 #endif
328 
329 #endif	/* _SYS_DLD_IMPL_H */
330