xref: /titanic_50/usr/src/uts/common/sys/dld_impl.h (revision 554ff184129088135ad2643c1c9832174a17be88)
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 /*
45  * dld_ppa_t object definition.
46  */
47 typedef	struct dld_node	dld_node_t;
48 
49 typedef struct dld_ppa {
50 	/*
51 	 * Name of the data-link.
52 	 */
53 	char		dp_name[IFNAMSIZ];
54 
55 	/*
56 	 * The device and port of the MAC interface.
57 	 */
58 	char		dp_dev[MAXNAMELEN];
59 	uint_t		dp_port;
60 
61 	/*
62 	 * The VLAN identifier of the data-link interface.
63 	 */
64 	uint_t		dp_vid;
65 
66 	/*
67 	 * Style 1 and style 2 provider nodes that reference the object.
68 	 */
69 	dld_node_t	*dp_style1;
70 	dld_node_t	*dp_style2;
71 
72 	/*
73 	 * Style 2 PPA index number of the object.
74 	 */
75 	t_scalar_t	dp_index;
76 } dld_ppa_t;
77 
78 /*
79  * dld_node_t object definition.
80  */
81 struct dld_node {
82 	/*
83 	 * Name of the node, this will be the name of the dev_t in the
84 	 * file system.
85 	 */
86 	char		dn_name[IFNAMSIZ];
87 
88 	/*
89 	 * DL_STYLE1 or DL_STYLE2.
90 	 */
91 	t_uscalar_t	dn_style;
92 
93 	/*
94 	 * Minor number of the dev_t.
95 	 */
96 	minor_t		dn_minor;
97 
98 	/*
99 	 * Global hash table entries that reference the object.
100 	 */
101 	ghte_t		dn_byminor_hte;
102 	ghte_t		dn_byname_hte;
103 
104 	/*
105 	 * Number of dld_ppa_t objects referencing the object.
106 	 */
107 	uint32_t	dn_ref;
108 
109 	/*
110 	 * For style 1 nodes there is only a single dld_ppa_t object reference.
111 	 * This field is used for that purpose.
112 	 */
113 	dld_ppa_t	*dn_dpp;
114 
115 	/*
116 	 * For style 2 nodes there may be many dld_ppa_t references, keyed
117 	 * by a PPA index number. The following hash table stores the
118 	 * references and the subsequent methods are used to manage the table.
119 	 */
120 	ght_t		dn_hash;
121 };
122 
123 #define	DLD_CONTROL	0x00000001
124 #define	DLD_DLPI	0x00000002
125 
126 typedef enum {
127 	DLD_UNITDATA,
128 	DLD_FASTPATH,
129 	DLD_RAW
130 } dld_str_mode_t;
131 
132 typedef enum {
133 	DLD_UNINITIALIZED,
134 	DLD_PASSIVE,
135 	DLD_ACTIVE
136 } dld_passivestate_t;
137 
138 typedef struct dld_str	dld_str_t;
139 
140 /*
141  * dld_str_t object definition.
142  */
143 struct dld_str {
144 	/*
145 	 * Ephemeral minor number for the object.
146 	 */
147 	minor_t			ds_minor;
148 
149 	/*
150 	 * Read/write queues for the stream which the object represents.
151 	 */
152 	queue_t			*ds_rq;
153 	queue_t			*ds_wq;
154 
155 	/*
156 	 * Stream is open to DLD_CONTROL (control node) or
157 	 * DLD_DLPI (DLS provider) node.
158 	 */
159 	uint_t			ds_type;
160 
161 	/*
162 	 * The following fields are only used for DLD_DLPI type objects.
163 	 */
164 
165 	/*
166 	 * dld_node_t of the node that was opened.
167 	 */
168 	dld_node_t		*ds_dnp;
169 
170 	/*
171 	 * Current DLPI state.
172 	 */
173 	t_uscalar_t		ds_dlstate;
174 
175 	/*
176 	 * Currently bound DLSAP.
177 	 */
178 	uint16_t		ds_sap;
179 
180 	/*
181 	 * Handle of the data-link channel that is used by this object.
182 	 */
183 	dls_channel_t		ds_dc;
184 
185 	/*
186 	 * Handle of the MAC that is used by the data-link interface.
187 	 */
188 	mac_handle_t		ds_mh;
189 
190 	/*
191 	 * VLAN identifier of the data-link interface.
192 	 */
193 	uint16_t		ds_vid;
194 
195 	/*
196 	 * Promiscuity level information.
197 	 */
198 	uint32_t		ds_promisc;
199 
200 	/*
201 	 * Immutable information of the MAC which the channel is using.
202 	 */
203 	const mac_info_t	*ds_mip;
204 
205 	/*
206 	 * Current packet priority.
207 	 */
208 	uint_t			ds_pri;
209 
210 	/*
211 	 * Handle of our MAC notification callback.
212 	 */
213 	mac_notify_handle_t	ds_mnh;
214 
215 	/*
216 	 * Set of enabled DL_NOTE... notifications. (See dlpi.h).
217 	 */
218 	uint32_t		ds_notifications;
219 
220 	/*
221 	 * Cached MAC unicast addresses.
222 	 */
223 	uint8_t			ds_fact_addr[MAXADDRLEN];
224 	uint8_t			ds_curr_addr[MAXADDRLEN];
225 
226 	/*
227 	 * Mode: unitdata, fast-path or raw.
228 	 */
229 	dld_str_mode_t		ds_mode;
230 
231 	/*
232 	 * IP polling is operational if this flag is set.
233 	 */
234 	boolean_t		ds_polling;
235 
236 	/*
237 	 * State of DLPI user: may be active (regular network layer),
238 	 * passive (snoop-like monitoring), or unknown (not yet
239 	 * determined).
240 	 */
241 	dld_passivestate_t	ds_passivestate;
242 
243 	/*
244 	 * Message handler jump tables.
245 	 */
246 	struct str_msg_info	*ds_mi;
247 	struct str_msg_info	*ds_pmi;
248 } dld_str;
249 
250 /*
251  * dld_str.c module.
252  */
253 
254 extern void		dld_str_init(void);
255 extern int		dld_str_fini(void);
256 extern dld_str_t	*dld_str_create(queue_t *);
257 extern void		dld_str_destroy(dld_str_t *);
258 extern int		dld_str_attach(dld_str_t *, dld_ppa_t *);
259 extern void		dld_str_detach(dld_str_t *);
260 extern void		dld_str_tx_raw(dld_str_t *);
261 extern void		dld_str_tx_fastpath(dld_str_t *);
262 extern void		dld_str_tx_drop(dld_str_t *);
263 extern void		dld_str_rx_raw(void *, mac_resource_handle_t,
264     mblk_t *, size_t);
265 extern void		dld_str_rx_fastpath(void *, mac_resource_handle_t,
266     mblk_t *, size_t);
267 extern void		dld_str_rx_unitdata(void *, mac_resource_handle_t,
268     mblk_t *, size_t);
269 extern void		dld_str_put(dld_str_t *, mblk_t *);
270 extern void		dld_str_srv(dld_str_t *, mblk_t *);
271 extern void		dld_str_notify_ind(dld_str_t *);
272 
273 /*
274  * dld_proto.c
275  */
276 extern void		dld_proto(dld_str_t *, mblk_t *);
277 
278 /*
279  * dld_ppa.c module.
280  */
281 extern void		dld_ppa_init(void);
282 extern int		dld_ppa_fini(void);
283 extern int		dld_ppa_create(const char *, const char *, uint_t,
284     uint16_t);
285 extern int		dld_ppa_destroy(const char *);
286 extern int		dld_ppa_attr(const char *, char *, uint_t *,
287     uint16_t *);
288 
289 /*
290  * dld_node.c module.
291  */
292 extern void		dld_node_init(void);
293 extern int		dld_node_fini(void);
294 extern dld_node_t	*dld_node_hold(const char *, t_uscalar_t);
295 extern void		dld_node_rele(dld_node_t *);
296 extern dld_node_t	*dld_node_find(minor_t);
297 extern int		dld_node_ppa_add(dld_node_t *, t_scalar_t,
298     dld_ppa_t *);
299 extern int		dld_node_ppa_remove(dld_node_t *, t_scalar_t);
300 extern dld_ppa_t	*dld_node_ppa_find(dld_node_t *, t_scalar_t);
301 
302 /*
303  * dld_minor.c module.
304  */
305 extern void		dld_minor_init(void);
306 extern int		dld_minor_fini(void);
307 extern minor_t		dld_minor_hold(boolean_t);
308 extern void		dld_minor_rele(minor_t);
309 
310 /*
311  * dld_ioc.c module.
312  */
313 extern void		dld_ioc(dld_str_t *, mblk_t *);
314 
315 /*
316  * dld_drv.c module.
317  */
318 extern dev_info_t	*dld_dip;
319 
320 /*
321  * Options: there should be a separate bit defined here for each
322  *          DLD_PROP... defined in dld.h.
323  */
324 #define	DLD_OPT_NO_STYLE1	0x00000001
325 #define	DLD_OPT_NO_FASTPATH	0x00000002
326 #define	DLD_OPT_NO_POLL		0x00000004
327 #define	DLD_OPT_NO_ZEROCOPY	0x00000008
328 
329 extern uint32_t		dld_opt;
330 
331 /*
332  * Useful macros.
333  */
334 
335 #define	IMPLY(p, c)	(!(p) || (c))
336 #define	AGGR_DEV	"aggr0"
337 
338 #ifdef	__cplusplus
339 }
340 #endif
341 
342 #endif	/* _SYS_DLD_IMPL_H */
343