xref: /titanic_44/usr/src/uts/common/sys/dld_impl.h (revision b81bb599d2182818b41e3bbe6d4d1771b9d484d4)
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 *, mac_header_info_t *);
220 extern void		dld_str_rx_fastpath(void *, mac_resource_handle_t,
221     mblk_t *, mac_header_info_t *);
222 extern void		dld_str_rx_unitdata(void *, mac_resource_handle_t,
223     mblk_t *, mac_header_info_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 extern void		str_mdata_fastpath_put(dld_str_t *, mblk_t *);
228 extern void		dld_tx_single(dld_str_t *, mblk_t *);
229 
230 /*
231  * dld_proto.c
232  */
233 extern void		dld_proto(dld_str_t *, mblk_t *);
234 extern void		dld_finish_pending_ops(dld_str_t *);
235 
236 /*
237  * Options: there should be a separate bit defined here for each
238  *          DLD_PROP... defined in dld.h.
239  */
240 #define	DLD_OPT_NO_FASTPATH	0x00000001
241 #define	DLD_OPT_NO_POLL		0x00000002
242 #define	DLD_OPT_NO_ZEROCOPY	0x00000004
243 
244 extern uint32_t		dld_opt;
245 
246 /*
247  * Useful macros.
248  */
249 
250 #define	IMPLY(p, c)	(!(p) || (c))
251 
252 #define	DLD_ENTER(dsp) {					\
253 	mutex_enter(&dsp->ds_thr_lock);				\
254 	++dsp->ds_thr;						\
255 	ASSERT(dsp->ds_thr != 0);				\
256 	mutex_exit(&dsp->ds_thr_lock);				\
257 }
258 
259 #define	DLD_EXIT(dsp) {							\
260 	mutex_enter(&dsp->ds_thr_lock);					\
261 	ASSERT(dsp->ds_thr > 0);					\
262 	if (--dsp->ds_thr == 0 && dsp->ds_pending_req != NULL)		\
263 		dld_finish_pending_ops(dsp);				\
264 	else								\
265 		mutex_exit(&dsp->ds_thr_lock);				\
266 }
267 
268 #define	DLD_WAKEUP(dsp) {						\
269 	mutex_enter(&dsp->ds_thr_lock);					\
270 	ASSERT(dsp->ds_pending_cnt > 0);				\
271 	if (--dsp->ds_pending_cnt == 0)					\
272 		cv_signal(&dsp->ds_pending_cv);				\
273 	mutex_exit(&dsp->ds_thr_lock);					\
274 }
275 
276 #ifdef DEBUG
277 #define	DLD_DBG		cmn_err
278 #else
279 #define	DLD_DBG		if (0) cmn_err
280 #endif
281 
282 #ifdef	__cplusplus
283 }
284 #endif
285 
286 #endif	/* _SYS_DLD_IMPL_H */
287