xref: /titanic_52/usr/src/uts/common/sys/dld_impl.h (revision 9512fe850e98fdd448c638ca63fdd92a8a510255)
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 	 * State of DLPI user: may be active (regular network layer),
174 	 * passive (snoop-like monitoring), or unknown (not yet
175 	 * determined).
176 	 */
177 	dld_passivestate_t	ds_passivestate;
178 
179 	/*
180 	 * Dummy mblk used for flow-control.
181 	 */
182 	mblk_t			*ds_tx_flow_mp;
183 
184 	/*
185 	 * Internal transmit queue and its parameters.
186 	 */
187 	kmutex_t		ds_tx_list_lock;
188 	mblk_t			*ds_tx_list_head;
189 	mblk_t			*ds_tx_list_tail;
190 	uint_t			ds_tx_cnt;
191 	uint_t			ds_tx_msgcnt;
192 	boolean_t		ds_tx_qbusy;
193 
194 	/*
195 	 * Number of threads currently in dld.  If there is a pending
196 	 * request, it is placed in ds_pending_req and the operation
197 	 * will finish when dld becomes single-threaded.
198 	 */
199 	kmutex_t		ds_thr_lock;
200 	uint_t			ds_thr;
201 	uint_t			ds_pending_cnt;
202 	mblk_t			*ds_pending_req;
203 	task_func_t		*ds_pending_op;
204 	kcondvar_t		ds_pending_cv;
205 } dld_str;
206 
207 /*
208  * dld_str.c module.
209  */
210 
211 extern void		dld_str_init(void);
212 extern int		dld_str_fini(void);
213 extern dld_str_t	*dld_str_create(queue_t *, uint_t, major_t,
214     t_uscalar_t);
215 extern void		dld_str_destroy(dld_str_t *);
216 extern int		dld_str_attach(dld_str_t *, t_uscalar_t);
217 extern void		dld_str_detach(dld_str_t *);
218 extern void		dld_str_rx_raw(void *, mac_resource_handle_t,
219     mblk_t *, size_t);
220 extern void		dld_str_rx_fastpath(void *, mac_resource_handle_t,
221     mblk_t *, size_t);
222 extern void		dld_str_rx_unitdata(void *, mac_resource_handle_t,
223     mblk_t *, size_t);
224 extern void		dld_tx_flush(dld_str_t *);
225 extern void		dld_tx_enqueue(dld_str_t *, mblk_t *, boolean_t);
226 extern void		dld_str_notify_ind(dld_str_t *);
227 
228 extern void		str_mdata_fastpath_put(dld_str_t *, mblk_t *);
229 extern void		str_mdata_raw_put(dld_str_t *, mblk_t *);
230 
231 /*
232  * dld_proto.c
233  */
234 extern void		dld_proto(dld_str_t *, mblk_t *);
235 extern void		dld_finish_pending_ops(dld_str_t *);
236 
237 /*
238  * Options: there should be a separate bit defined here for each
239  *          DLD_PROP... defined in dld.h.
240  */
241 #define	DLD_OPT_NO_FASTPATH	0x00000001
242 #define	DLD_OPT_NO_POLL		0x00000002
243 #define	DLD_OPT_NO_ZEROCOPY	0x00000004
244 
245 extern uint32_t		dld_opt;
246 
247 /*
248  * Useful macros.
249  */
250 
251 #define	IMPLY(p, c)	(!(p) || (c))
252 
253 #define	DLD_ENTER(dsp) {					\
254 	mutex_enter(&dsp->ds_thr_lock);				\
255 	++dsp->ds_thr;						\
256 	ASSERT(dsp->ds_thr != 0);				\
257 	mutex_exit(&dsp->ds_thr_lock);				\
258 }
259 
260 #define	DLD_EXIT(dsp) {							\
261 	mutex_enter(&dsp->ds_thr_lock);					\
262 	ASSERT(dsp->ds_thr > 0);					\
263 	if (--dsp->ds_thr == 0 && dsp->ds_pending_req != NULL)		\
264 		dld_finish_pending_ops(dsp);				\
265 	else								\
266 		mutex_exit(&dsp->ds_thr_lock);				\
267 }
268 
269 #define	DLD_WAKEUP(dsp) {						\
270 	mutex_enter(&dsp->ds_thr_lock);					\
271 	ASSERT(dsp->ds_pending_cnt > 0);				\
272 	if (--dsp->ds_pending_cnt == 0)					\
273 		cv_signal(&dsp->ds_pending_cv);				\
274 	mutex_exit(&dsp->ds_thr_lock);					\
275 }
276 
277 #ifdef DEBUG
278 #define	DLD_DBG		cmn_err
279 #else
280 #define	DLD_DBG		if (0) cmn_err
281 #endif
282 
283 #ifdef	__cplusplus
284 }
285 #endif
286 
287 #endif	/* _SYS_DLD_IMPL_H */
288