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