xref: /titanic_51/usr/src/uts/common/sys/dld_impl.h (revision 00687e57f8c568d4f8fb446b6530a2942842292f)
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 2006 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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <sys/types.h>
32 #include <sys/ethernet.h>
33 #include <sys/stream.h>
34 #include <sys/dlpi.h>
35 #include <sys/mac.h>
36 #include <sys/dls.h>
37 #include <sys/dld.h>
38 
39 #ifdef	__cplusplus
40 extern "C" {
41 #endif
42 
43 #define	DLD_CONTROL	0x00000001
44 #define	DLD_DLPI	0x00000002
45 
46 typedef enum {
47 	DLD_UNITDATA,
48 	DLD_FASTPATH,
49 	DLD_RAW
50 } dld_str_mode_t;
51 
52 typedef enum {
53 	DLD_UNINITIALIZED,
54 	DLD_PASSIVE,
55 	DLD_ACTIVE
56 } dld_passivestate_t;
57 
58 typedef struct dld_str	dld_str_t;
59 
60 /*
61  * dld_str_t object definition.
62  */
63 struct dld_str {
64 	/*
65 	 * Major number of the device
66 	 */
67 	major_t			ds_major;
68 
69 	/*
70 	 * Ephemeral minor number for the object.
71 	 */
72 	minor_t			ds_minor;
73 
74 	/*
75 	 * PPA number this stream is attached to.
76 	 */
77 	t_uscalar_t		ds_ppa;
78 
79 	/*
80 	 * Read/write queues for the stream which the object represents.
81 	 */
82 	queue_t			*ds_rq;
83 	queue_t			*ds_wq;
84 
85 	/*
86 	 * Lock to protect this structure.
87 	 */
88 	krwlock_t		ds_lock;
89 
90 	/*
91 	 * Stream is open to DLD_CONTROL (control node) or
92 	 * DLD_DLPI (DLS provider) node.
93 	 */
94 	uint_t			ds_type;
95 
96 	/*
97 	 * The following fields are only used for DLD_DLPI type objects.
98 	 */
99 
100 	/*
101 	 * Current DLPI state.
102 	 */
103 	t_uscalar_t		ds_dlstate;
104 
105 	/*
106 	 * DLPI style
107 	 */
108 	t_uscalar_t		ds_style;
109 
110 	/*
111 	 * Currently bound DLSAP.
112 	 */
113 	uint16_t		ds_sap;
114 
115 	/*
116 	 * Handle of the data-link channel that is used by this object.
117 	 */
118 	dls_channel_t		ds_dc;
119 
120 	/*
121 	 * Handle of the MAC that is used by the data-link interface.
122 	 */
123 	mac_handle_t		ds_mh;
124 
125 	/*
126 	 * VLAN identifier of the data-link interface.
127 	 */
128 	uint16_t		ds_vid;
129 
130 	/*
131 	 * Promiscuity level information.
132 	 */
133 	uint32_t		ds_promisc;
134 
135 	/*
136 	 * Immutable information of the MAC which the channel is using.
137 	 */
138 	const mac_info_t	*ds_mip;
139 
140 	/*
141 	 * Current packet priority.
142 	 */
143 	uint_t			ds_pri;
144 
145 	/*
146 	 * Handle of our MAC notification callback.
147 	 */
148 	mac_notify_handle_t	ds_mnh;
149 
150 	/*
151 	 * Set of enabled DL_NOTE... notifications. (See dlpi.h).
152 	 */
153 	uint32_t		ds_notifications;
154 
155 	/*
156 	 * Cached MAC unicast addresses.
157 	 */
158 	uint8_t			ds_fact_addr[MAXMACADDRLEN];
159 	uint8_t			ds_curr_addr[MAXMACADDRLEN];
160 
161 	/*
162 	 * Mode: unitdata, fast-path or raw.
163 	 */
164 	dld_str_mode_t		ds_mode;
165 
166 	/*
167 	 * IP polling is operational if this flag is set.
168 	 */
169 	boolean_t		ds_polling;
170 	boolean_t		ds_soft_ring;
171 
172 	/*
173 	 * LSO is enabled if ds_lso is set.
174 	 */
175 	boolean_t		ds_lso;
176 	uint64_t		ds_lso_max;
177 
178 	/*
179 	 * State of DLPI user: may be active (regular network layer),
180 	 * passive (snoop-like monitoring), or unknown (not yet
181 	 * determined).
182 	 */
183 	dld_passivestate_t	ds_passivestate;
184 
185 	/*
186 	 * Dummy mblk used for flow-control.
187 	 */
188 	mblk_t			*ds_tx_flow_mp;
189 
190 	/*
191 	 * Internal transmit queue and its parameters.
192 	 */
193 	kmutex_t		ds_tx_list_lock;
194 	mblk_t			*ds_tx_list_head;
195 	mblk_t			*ds_tx_list_tail;
196 	uint_t			ds_tx_cnt;
197 	uint_t			ds_tx_msgcnt;
198 	boolean_t		ds_tx_qbusy;
199 
200 	/*
201 	 * Number of threads currently in dld.  If there is a pending
202 	 * request, it is placed in ds_pending_req and the operation
203 	 * will finish when dld becomes single-threaded.
204 	 */
205 	kmutex_t		ds_thr_lock;
206 	uint_t			ds_thr;
207 	uint_t			ds_pending_cnt;
208 	mblk_t			*ds_pending_req;
209 	task_func_t		*ds_pending_op;
210 	kcondvar_t		ds_pending_cv;
211 } dld_str;
212 
213 /*
214  * dld_str.c module.
215  */
216 
217 extern void		dld_str_init(void);
218 extern int		dld_str_fini(void);
219 extern dld_str_t	*dld_str_create(queue_t *, uint_t, major_t,
220     t_uscalar_t);
221 extern void		dld_str_destroy(dld_str_t *);
222 extern int		dld_str_attach(dld_str_t *, t_uscalar_t);
223 extern void		dld_str_detach(dld_str_t *);
224 extern void		dld_str_rx_raw(void *, mac_resource_handle_t,
225     mblk_t *, mac_header_info_t *);
226 extern void		dld_str_rx_fastpath(void *, mac_resource_handle_t,
227     mblk_t *, mac_header_info_t *);
228 extern void		dld_str_rx_unitdata(void *, mac_resource_handle_t,
229     mblk_t *, mac_header_info_t *);
230 extern void		dld_tx_flush(dld_str_t *);
231 extern void		dld_tx_enqueue(dld_str_t *, mblk_t *, boolean_t);
232 extern void		dld_str_notify_ind(dld_str_t *);
233 extern void		str_mdata_fastpath_put(dld_str_t *, mblk_t *);
234 extern void		dld_tx_single(dld_str_t *, mblk_t *);
235 
236 /*
237  * dld_proto.c
238  */
239 extern void		dld_proto(dld_str_t *, mblk_t *);
240 extern void		dld_finish_pending_ops(dld_str_t *);
241 
242 /*
243  * Options: there should be a separate bit defined here for each
244  *          DLD_PROP... defined in dld.h.
245  */
246 #define	DLD_OPT_NO_FASTPATH	0x00000001
247 #define	DLD_OPT_NO_POLL		0x00000002
248 #define	DLD_OPT_NO_ZEROCOPY	0x00000004
249 
250 extern uint32_t		dld_opt;
251 
252 /*
253  * Useful macros.
254  */
255 
256 #define	IMPLY(p, c)	(!(p) || (c))
257 
258 #define	DLD_ENTER(dsp) {					\
259 	mutex_enter(&dsp->ds_thr_lock);				\
260 	++dsp->ds_thr;						\
261 	ASSERT(dsp->ds_thr != 0);				\
262 	mutex_exit(&dsp->ds_thr_lock);				\
263 }
264 
265 #define	DLD_EXIT(dsp) {							\
266 	mutex_enter(&dsp->ds_thr_lock);					\
267 	ASSERT(dsp->ds_thr > 0);					\
268 	if (--dsp->ds_thr == 0 && dsp->ds_pending_req != NULL)		\
269 		dld_finish_pending_ops(dsp);				\
270 	else								\
271 		mutex_exit(&dsp->ds_thr_lock);				\
272 }
273 
274 #define	DLD_WAKEUP(dsp) {						\
275 	mutex_enter(&dsp->ds_thr_lock);					\
276 	ASSERT(dsp->ds_pending_cnt > 0);				\
277 	if (--dsp->ds_pending_cnt == 0)					\
278 		cv_signal(&dsp->ds_pending_cv);				\
279 	mutex_exit(&dsp->ds_thr_lock);					\
280 }
281 
282 #ifdef DEBUG
283 #define	DLD_DBG		cmn_err
284 #else
285 #define	DLD_DBG		if (0) cmn_err
286 #endif
287 
288 #ifdef	__cplusplus
289 }
290 #endif
291 
292 #endif	/* _SYS_DLD_IMPL_H */
293