xref: /illumos-gate/usr/src/uts/common/sys/dld.h (revision 72888e72b624f86b06ea05b1de2287dcf9f40d23)
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 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_DLD_H
27 #define	_SYS_DLD_H
28 
29 /*
30  * Data-Link Driver (public header).
31  *
32  * Note that the datastructures defined here define an ioctl interface
33  * that is shared betwen user and kernel space.  The dld driver thus
34  * assumes that the structures have identical layout and size when
35  * compiled in either IPL32 or LP64.
36  */
37 
38 #include <sys/types.h>
39 #include <sys/stream.h>
40 #include <sys/dld_ioc.h>
41 #include <sys/mac_flow.h>
42 #include <sys/conf.h>
43 #include <sys/sad.h>
44 #include <net/if.h>
45 #include <sys/ddi.h>
46 #include <sys/sunddi.h>
47 #include <sys/mac.h>
48 
49 #ifdef	__cplusplus
50 extern "C" {
51 #endif
52 
53 /*
54  * Data-Link Driver Information (text emitted by modinfo(1m))
55  */
56 #define	DLD_INFO	"Data-Link Driver"
57 
58 /*
59  * Options: To enable an option set the property name to a non-zero value
60  *	    in kernel/drv/dld.conf.
61  */
62 
63 /*
64  * Prevent use of the IP fast-path (direct M_DATA transmit).
65  */
66 #define	DLD_PROP_NO_FASTPATH	"no-fastpath"
67 
68 /*
69  * Prevent advertising of the DL_CAPAB_POLL capability.
70  */
71 #define	DLD_PROP_NO_POLL	"no-poll"
72 
73 /*
74  * Prevent advertising of the DL_CAPAB_ZEROCOPY capability.
75  */
76 #define	DLD_PROP_NO_ZEROCOPY	"no-zerocopy"
77 
78 /*
79  * Prevent advertising of the DL_CAPAB_SOFTRING capability.
80  */
81 #define	DLD_PROP_NO_SOFTRING	"no-softring"
82 
83 /*
84  * The name of the driver.
85  */
86 #define	DLD_DRIVER_NAME		"dld"
87 
88 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
89 #pragma pack(4)
90 #endif
91 
92 /*
93  * IOCTL codes and data structures.
94  */
95 #define	DLDIOC_ATTR	DLDIOC(0x03)
96 
97 typedef struct dld_ioc_attr {
98 	datalink_id_t		dia_linkid;
99 	uint_t			dia_max_sdu;
100 } dld_ioc_attr_t;
101 
102 #define	DLDIOC_VLAN_ATTR	DLDIOC(0x04)
103 typedef struct dld_ioc_vlan_attr {
104 	datalink_id_t	div_vlanid;
105 	uint16_t	div_vid;
106 	datalink_id_t	div_linkid;
107 	boolean_t	div_force;
108 } dld_ioc_vlan_attr_t;
109 
110 #define	DLDIOC_PHYS_ATTR	DLDIOC(0x05)
111 #define	DLPI_LINKNAME_MAX	32
112 
113 typedef struct dld_ioc_phys_attr {
114 	datalink_id_t	dip_linkid;
115 	/*
116 	 * Whether this physical link supports vanity naming. Note that
117 	 * physical links whose media type is not supported by GLDv3
118 	 * can not support vanity naming.
119 	 */
120 	boolean_t	dip_novanity;
121 	char		dip_dev[MAXLINKNAMELEN];
122 } dld_ioc_phys_attr_t;
123 
124 /*
125  * Secure objects ioctls
126  */
127 typedef enum {
128 	DLD_SECOBJ_CLASS_WEP = 1,
129 	DLD_SECOBJ_CLASS_WPA
130 } dld_secobj_class_t;
131 
132 #define	DLD_SECOBJ_OPT_CREATE	0x00000001
133 #define	DLD_SECOBJ_NAME_MAX	32
134 #define	DLD_SECOBJ_VAL_MAX	256
135 typedef struct dld_secobj {
136 	char			so_name[DLD_SECOBJ_NAME_MAX];
137 	dld_secobj_class_t	so_class;
138 	uint8_t			so_val[DLD_SECOBJ_VAL_MAX];
139 	uint_t			so_len;
140 } dld_secobj_t;
141 
142 #define	DLDIOC_SECOBJ_SET	DLDIOC(0x06)
143 typedef struct dld_ioc_secobj_set {
144 	dld_secobj_t		ss_obj;
145 	uint_t			ss_flags;
146 } dld_ioc_secobj_set_t;
147 
148 #define	DLDIOC_SECOBJ_GET	DLDIOC(0x07)
149 typedef struct dld_ioc_secobj_get {
150 	dld_secobj_t		sg_obj;
151 	uint_t			sg_count;
152 	uint_t			sg_size;
153 } dld_ioc_secobj_get_t;
154 
155 /*
156  * The following two slots were used outside of ON, so don't reuse them.
157  *
158  * #define DLDIOCHOLDVLAN DLDIOC(0x08)
159  * #define DLDIOCRELEVLAN DLDIOC(0x09)
160  */
161 
162 #define	DLDIOC_SECOBJ_UNSET	DLDIOC(0x0a)
163 typedef struct dld_ioc_secobj_unset {
164 	char			su_name[DLD_SECOBJ_NAME_MAX];
165 } dld_ioc_secobj_unset_t;
166 
167 #define	DLDIOC_CREATE_VLAN	DLDIOC(0x0b)
168 typedef struct dld_ioc_create_vlan {
169 	datalink_id_t	dic_vlanid;
170 	datalink_id_t	dic_linkid;
171 	uint16_t	dic_vid;
172 	boolean_t	dic_force;
173 } dld_ioc_create_vlan_t;
174 
175 #define	DLDIOC_DELETE_VLAN	DLDIOC(0x0c)
176 typedef struct dld_ioc_delete_vlan {
177 	datalink_id_t	did_linkid;
178 } dld_ioc_delete_vlan_t;
179 
180 /*
181  * The following constants have been removed, and the slots are open:
182  *
183  * #define DLDIOC_SETAUTOPUSH	DLDIOC(0x0d)
184  * #define DLDIOC_GETAUTOPUSH	DLDIOC(0x0e)
185  * #define DLDIOC_CLRAUTOPUSH	DLDIOC(0x0f)
186  */
187 
188 #define	DLDIOC_DOORSERVER	DLDIOC(0x10)
189 typedef struct dld_ioc_door {
190 	boolean_t	did_start_door;
191 } dld_ioc_door_t;
192 
193 #define	DLDIOC_RENAME		DLDIOC(0x11)
194 typedef struct dld_ioc_rename {
195 	datalink_id_t	dir_linkid1;
196 	datalink_id_t	dir_linkid2;
197 	char		dir_link[MAXLINKNAMELEN];
198 } dld_ioc_rename_t;
199 
200 /*
201  * The following constants have been removed, and the slots are open:
202  *
203  * #define DLDIOC_SETZID	DLDIOC(0x12)
204  * #define DLDIOC_GETZID	DLDIOC(0x13)
205  */
206 
207 typedef struct dld_ioc_zid {
208 	zoneid_t	diz_zid;
209 	char		diz_link[MAXLINKNAMELEN];
210 } dld_ioc_zid_t;
211 
212 /*
213  * data-link autopush configuration.
214  */
215 struct dlautopush {
216 	uint_t	dap_anchor;
217 	uint_t	dap_npush;
218 	char	dap_aplist[MAXAPUSH][FMNAMESZ+1];
219 };
220 
221 #define	DLDIOC_MACADDRGET	DLDIOC(0x15)
222 typedef struct dld_ioc_macaddrget {
223 	datalink_id_t	dig_linkid;
224 	uint_t		dig_count;
225 	uint_t		dig_size;
226 } dld_ioc_macaddrget_t;
227 
228 /* possible flags for dmi_flags below */
229 #define	DLDIOCMACADDR_USED	0x1	/* address slot used */
230 
231 typedef struct dld_macaddrinfo {
232 	uint_t		dmi_slot;
233 	uint_t		dmi_flags;
234 	uint_t		dmi_addrlen;
235 	uchar_t		dmi_addr[MAXMACADDRLEN];
236 	char		dmi_client_name[MAXNAMELEN];
237 	datalink_id_t	dma_client_linkid;
238 } dld_macaddrinfo_t;
239 
240 /*
241  * IOCTL codes and data structures for flowadm.
242  */
243 #define	DLDIOC_ADDFLOW		DLDIOC(0x16)
244 typedef struct dld_ioc_addflow {
245 	datalink_id_t		af_linkid;
246 	flow_desc_t		af_flow_desc;
247 	mac_resource_props_t	af_resource_props;
248 	char			af_name[MAXNAMELEN];
249 } dld_ioc_addflow_t;
250 
251 #define	DLDIOC_REMOVEFLOW	DLDIOC(0x17)
252 typedef struct dld_ioc_removeflow {
253 	char			rf_name[MAXNAMELEN];
254 } dld_ioc_removeflow_t;
255 
256 #define	DLDIOC_MODIFYFLOW	DLDIOC(0x18)
257 typedef struct dld_ioc_modifyflow {
258 	char			mf_name[MAXNAMELEN];
259 	mac_resource_props_t	mf_resource_props;
260 } dld_ioc_modifyflow_t;
261 
262 #define	DLDIOC_WALKFLOW		DLDIOC(0x19)
263 typedef struct dld_ioc_walkflow {
264 	datalink_id_t		wf_linkid;
265 	char			wf_name[MAXNAMELEN];
266 	uint32_t		wf_nflows;
267 	uint_t			wf_len;
268 } dld_ioc_walkflow_t;
269 
270 typedef struct dld_flowinfo {
271 	datalink_id_t		fi_linkid;
272 	flow_desc_t		fi_flow_desc;
273 	mac_resource_props_t	fi_resource_props;
274 	char			fi_flowname[MAXNAMELEN];
275 	uint32_t		fi_pad;
276 } dld_flowinfo_t;
277 
278 #define	DLDIOC_USAGELOG		DLDIOC(0x1a)
279 typedef struct dld_ioc_usagelog {
280 	mac_logtype_t	ul_type;
281 	boolean_t	ul_onoff;
282 	uint_t		ul_interval;
283 } dld_ioc_usagelog_t;
284 
285 #define	DLDIOC_SETMACPROP	DLDIOC(0x1b)
286 #define	DLDIOC_GETMACPROP	DLDIOC(0x1c)
287 #define	MAC_PROP_VERSION	1
288 
289 typedef struct dld_ioc_macprop_s {
290 	int		pr_version;
291 	uint_t		pr_flags;
292 	datalink_id_t	pr_linkid;
293 	mac_prop_id_t	pr_num;
294 	uint_t		pr_perm_flags;
295 	char    	pr_name[MAXLINKPROPNAME];
296 	uint_t		pr_valsize;		/* sizeof pr_val */
297 	char		pr_val[1];
298 } dld_ioc_macprop_t;
299 
300 #define	DLDIOC_GETHWGRP		DLDIOC(0x1d)
301 
302 typedef struct dld_ioc_hwgrpget {
303 	datalink_id_t	dih_linkid;
304 	uint_t		dih_n_groups;	/* number of groups included in ioc */
305 	uint_t		dih_size;
306 } dld_ioc_hwgrpget_t;
307 
308 #define	MAXCLIENTNAMELEN	1024
309 typedef struct dld_hwgrpinfo {
310 	char	dhi_link_name[MAXLINKNAMELEN];
311 	uint_t	dhi_grp_num;
312 	uint_t	dhi_grp_type;
313 	uint_t	dhi_n_rings;
314 	uint_t	dhi_n_clnts;
315 	/* XXXX later we should use dhi_n_clnts * MAXNAMELEN for dhi_clnts */
316 	char	dhi_clnts[MAXCLIENTNAMELEN];
317 } dld_hwgrpinfo_t;
318 
319 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
320 #pragma pack()
321 #endif
322 
323 #ifdef _KERNEL
324 
325 #define	DLD_CAPAB_DIRECT	0x00000001
326 #define	DLD_CAPAB_POLL		0x00000002
327 #define	DLD_CAPAB_PERIM		0x00000003
328 #define	DLD_CAPAB_LSO		0x00000004
329 
330 #define	DLD_ENABLE		0x00000001
331 #define	DLD_DISABLE		0x00000002
332 #define	DLD_QUERY		0x00000003
333 
334 /*
335  * GLDv3 entry point for negotiating capabilities.
336  * This is exposed to IP after negotiation of DL_CAPAB_DLD.
337  *
338  * This function takes the following arguments:
339  * handle: used for identifying the interface to operate on (provided by dld).
340  * type: capability type.
341  * arg: points to a capability-specific structure.
342  * flags: used for indicating whether to enable or disable a capability.
343  *
344  * With this function, capability negotiation is reduced from a multi-step
345  * process to just one single function call.
346  * e.g. the following code would pass 'x' from IP to dld and obtain
347  * arg.output_arg from dld:
348  *
349  * arg.input_arg = x;
350  * rc = (*dld_capab)(handle, DLD_CAPAB_XXX, &arg, DLD_ENABLE);
351  * ill->info1 = arg.output_arg;
352  */
353 typedef	int	(*dld_capab_func_t)(void *, uint_t, void *, uint_t);
354 
355 /*
356  * Direct Tx/Rx capability.
357  */
358 typedef struct dld_capab_direct_s {
359 	/*
360 	 * Rx entry point and handle, owned by IP.
361 	 */
362 	uintptr_t	di_rx_cf;
363 	void		*di_rx_ch;
364 
365 	/*
366 	 * Tx entry points and handle, owned by DLD.
367 	 */
368 	/* Entry point for transmitting packets */
369 	uintptr_t	di_tx_df;
370 	void		*di_tx_dh;
371 
372 	/* flow control notification callback */
373 	uintptr_t	di_tx_cb_df; /* callback registration/de-registration */
374 	void		*di_tx_cb_dh;
375 } dld_capab_direct_t;
376 
377 /*
378  * Polling/softring capability.
379  */
380 #define	POLL_SOFTRING		0x00000001
381 typedef struct dld_capab_poll_s {
382 	uintptr_t	poll_ring_add_cf;
383 	uintptr_t	poll_ring_remove_cf;
384 	uintptr_t	poll_ring_quiesce_cf;
385 	uintptr_t	poll_ring_restart_cf;
386 	uintptr_t	poll_ring_bind_cf;
387 	void		*poll_ring_ch;
388 	uintptr_t	poll_mac_accept_df;
389 	void		*poll_mac_dh;
390 } dld_capab_poll_t;
391 
392 /*
393  * LSO capability
394  */
395 /*
396  * Currently supported flags for LSO.
397  */
398 #define	DLD_LSO_TX_BASIC_TCP_IPV4	0x01	/* TCP LSO capability */
399 
400 typedef struct dld_capab_lso_s {
401 	uint_t  lso_flags;	/* capability flags */
402 	uint_t  lso_max;	/* maximum payload */
403 } dld_capab_lso_t;
404 
405 int	dld_getinfo(dev_info_t *, ddi_info_cmd_t, void *, void **);
406 int	dld_open(queue_t *, dev_t *, int, int, cred_t *);
407 int	dld_close(queue_t *);
408 void	dld_wput(queue_t *, mblk_t *);
409 void	dld_wsrv(queue_t *);
410 void	dld_init_ops(struct dev_ops *, const char *);
411 void	dld_fini_ops(struct dev_ops *);
412 int	dld_autopush(dev_t *, struct dlautopush *);
413 
414 int	dld_add_flow(datalink_id_t, char *, flow_desc_t *,
415     mac_resource_props_t *);
416 int	dld_remove_flow(char *);
417 int	dld_modify_flow(char *, mac_resource_props_t *);
418 int	dld_walk_flow(dld_ioc_walkflow_t *, intptr_t);
419 
420 #endif
421 
422 #ifdef	__cplusplus
423 }
424 #endif
425 
426 #endif	/* _SYS_DLD_H */
427