xref: /titanic_50/usr/src/uts/common/sys/dld_impl.h (revision 02e56f3f1bfc8d9977bafb8cb5202f576dcded27)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_DLD_IMPL_H
28 #define	_SYS_DLD_IMPL_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/types.h>
33 #include <sys/ethernet.h>
34 #include <sys/stream.h>
35 #include <sys/dlpi.h>
36 #include <sys/mac.h>
37 #include <sys/dls.h>
38 #include <sys/dld.h>
39 
40 #ifdef	__cplusplus
41 extern "C" {
42 #endif
43 
44 #define	DLD_CONTROL	0x00000001
45 #define	DLD_DLPI	0x00000002
46 
47 typedef enum {
48 	DLD_UNITDATA,
49 	DLD_FASTPATH,
50 	DLD_RAW
51 } dld_str_mode_t;
52 
53 typedef enum {
54 	DLD_UNINITIALIZED,
55 	DLD_PASSIVE,
56 	DLD_ACTIVE
57 } dld_passivestate_t;
58 
59 typedef struct dld_str	dld_str_t;
60 
61 /*
62  * dld_str_t object definition.
63  */
64 struct dld_str {
65 	/*
66 	 * Major number of the device
67 	 */
68 	major_t			ds_major;
69 
70 	/*
71 	 * Ephemeral minor number for the object.
72 	 */
73 	minor_t			ds_minor;
74 
75 	/*
76 	 * Read/write queues for the stream which the object represents.
77 	 */
78 	queue_t			*ds_rq;
79 	queue_t			*ds_wq;
80 
81 	/*
82 	 * Lock to protect this structure.
83 	 */
84 	krwlock_t		ds_lock;
85 
86 	/*
87 	 * Stream is open to DLD_CONTROL (control node) or
88 	 * DLD_DLPI (DLS provider) node.
89 	 */
90 	uint_t			ds_type;
91 
92 	/*
93 	 * The following fields are only used for DLD_DLPI type objects.
94 	 */
95 
96 	/*
97 	 * Current DLPI state.
98 	 */
99 	t_uscalar_t		ds_dlstate;
100 
101 	/*
102 	 * DLPI style
103 	 */
104 	t_uscalar_t		ds_style;
105 
106 	/*
107 	 * Currently bound DLSAP.
108 	 */
109 	uint16_t		ds_sap;
110 
111 	/*
112 	 * Handle of the data-link channel that is used by this object.
113 	 */
114 	dls_channel_t		ds_dc;
115 
116 	/*
117 	 * Handle of the MAC that is used by the data-link interface.
118 	 */
119 	mac_handle_t		ds_mh;
120 
121 	/*
122 	 * VLAN identifier of the data-link interface.
123 	 */
124 	uint16_t		ds_vid;
125 
126 	/*
127 	 * Promiscuity level information.
128 	 */
129 	uint32_t		ds_promisc;
130 
131 	/*
132 	 * Immutable information of the MAC which the channel is using.
133 	 */
134 	const mac_info_t	*ds_mip;
135 
136 	/*
137 	 * Current packet priority.
138 	 */
139 	uint_t			ds_pri;
140 
141 	/*
142 	 * Handle of our MAC notification callback.
143 	 */
144 	mac_notify_handle_t	ds_mnh;
145 
146 	/*
147 	 * Set of enabled DL_NOTE... notifications. (See dlpi.h).
148 	 */
149 	uint32_t		ds_notifications;
150 
151 	/*
152 	 * Cached MAC unicast addresses.
153 	 */
154 	uint8_t			ds_fact_addr[MAXADDRLEN];
155 	uint8_t			ds_curr_addr[MAXADDRLEN];
156 
157 	/*
158 	 * Mode: unitdata, fast-path or raw.
159 	 */
160 	dld_str_mode_t		ds_mode;
161 
162 	/*
163 	 * IP polling is operational if this flag is set.
164 	 */
165 	boolean_t		ds_polling;
166 
167 	/*
168 	 * State of DLPI user: may be active (regular network layer),
169 	 * passive (snoop-like monitoring), or unknown (not yet
170 	 * determined).
171 	 */
172 	dld_passivestate_t	ds_passivestate;
173 
174 	/*
175 	 * Dummy mblk used for flow-control.
176 	 */
177 	mblk_t			*ds_tx_flow_mp;
178 
179 	/*
180 	 * Internal transmit queue and its parameters.
181 	 */
182 	kmutex_t		ds_tx_list_lock;
183 	mblk_t			*ds_tx_list_head;
184 	mblk_t			*ds_tx_list_tail;
185 	uint_t			ds_tx_cnt;
186 	uint_t			ds_tx_msgcnt;
187 	boolean_t		ds_tx_qbusy;
188 
189 	/*
190 	 * Number of threads currently in dld.  If there is a pending
191 	 * DL_DETACH_REQ, the request is placed in the ds_detach_req
192 	 * and the operation will be finished when the driver goes
193 	 * single-threaded.
194 	 */
195 	kmutex_t		ds_thr_lock;
196 	uint_t			ds_thr;
197 	mblk_t			*ds_detach_req;
198 } dld_str;
199 
200 /*
201  * dld_str.c module.
202  */
203 
204 extern void		dld_str_init(void);
205 extern int		dld_str_fini(void);
206 extern dld_str_t	*dld_str_create(queue_t *, uint_t, major_t,
207     t_uscalar_t);
208 extern void		dld_str_destroy(dld_str_t *);
209 extern int		dld_str_attach(dld_str_t *, t_uscalar_t);
210 extern void		dld_str_detach(dld_str_t *);
211 extern void		dld_str_rx_raw(void *, mac_resource_handle_t,
212     mblk_t *, size_t);
213 extern void		dld_str_rx_fastpath(void *, mac_resource_handle_t,
214     mblk_t *, size_t);
215 extern void		dld_str_rx_unitdata(void *, mac_resource_handle_t,
216     mblk_t *, size_t);
217 extern void		dld_tx_flush(dld_str_t *);
218 extern void		dld_tx_enqueue(dld_str_t *, mblk_t *, boolean_t);
219 extern void		dld_str_notify_ind(dld_str_t *);
220 
221 extern void		str_mdata_fastpath_put(dld_str_t *, mblk_t *);
222 extern void		str_mdata_raw_put(dld_str_t *, mblk_t *);
223 
224 /*
225  * dld_proto.c
226  */
227 extern void		dld_proto(dld_str_t *, mblk_t *);
228 extern void		dld_finish_pending_ops(dld_str_t *);
229 
230 /*
231  * Options: there should be a separate bit defined here for each
232  *          DLD_PROP... defined in dld.h.
233  */
234 #define	DLD_OPT_NO_FASTPATH	0x00000001
235 #define	DLD_OPT_NO_POLL		0x00000002
236 #define	DLD_OPT_NO_ZEROCOPY	0x00000004
237 
238 extern uint32_t		dld_opt;
239 
240 /*
241  * Useful macros.
242  */
243 
244 #define	IMPLY(p, c)	(!(p) || (c))
245 #define	AGGR_DEV	"aggr0"
246 
247 #define	DLD_ENTER(dsp) {					\
248 	mutex_enter(&dsp->ds_thr_lock);				\
249 	++dsp->ds_thr;						\
250 	ASSERT(dsp->ds_thr != 0);				\
251 	mutex_exit(&dsp->ds_thr_lock);				\
252 }
253 
254 #define	DLD_EXIT(dsp) {							\
255 	mutex_enter(&dsp->ds_thr_lock);					\
256 	ASSERT(dsp->ds_thr > 0);					\
257 	if (--dsp->ds_thr == 0 && dsp->ds_detach_req != NULL)		\
258 		dld_finish_pending_ops(dsp);				\
259 	else								\
260 		mutex_exit(&dsp->ds_thr_lock);				\
261 }
262 
263 #ifdef DEBUG
264 #define	DLD_DBG		cmn_err
265 #else
266 #define	DLD_DBG		if (0) cmn_err
267 #endif
268 
269 #ifdef	__cplusplus
270 }
271 #endif
272 
273 #endif	/* _SYS_DLD_IMPL_H */
274