xref: /illumos-gate/usr/src/uts/common/sys/dld_ioc.h (revision 36589d6bb0cdae89e166b57b0d64ae56d53247d9)
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 (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
23  * Copyright 2015 Joyent, Inc.
24  */
25 
26 #ifndef	_SYS_DLD_IOC_H
27 #define	_SYS_DLD_IOC_H
28 
29 #include <sys/types.h>
30 #include <sys/cred.h>
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 /*
37  * The name of the dld control device.  All GLDv3 control ioctls are
38  * performed on this device.
39  */
40 #define	DLD_CONTROL_DEV		"/dev/dld"
41 
42 /*
43  * GLDv3 ioctl values are structured as follows:
44  *
45  * |    16-bits     |     16-bits    |
46  * +----------------+----------------+
47  * |   module-id    |   command-id   |
48  * +----------------+----------------+
49  */
50 #define	DLD_IOC_CMD(modid, cmdid)	(((uint_t)(modid) << 16) | (cmdid))
51 #define	DLD_IOC_MODID(cmd)		(((cmd) & 0xffff0000) >> 16)
52 /*
53  * GLDv3 module ids to be passed in as the first argument to
54  * dld_ioc_register() and dld_ioc_unregister().
55  */
56 #define	DLD_IOC		0x0D1D
57 #define	AGGR_IOC	0x0A66
58 #define	VNIC_IOC	0x0171
59 #define	SIMNET_IOC	0x5132
60 #define	IPTUN_IOC	0x454A
61 #define	BRIDGE_IOC	0xB81D
62 #define	IBPART_IOC	0x6171
63 #define	OVERLAY_IOC	0x2005
64 
65 /* GLDv3 modules use these macros to generate unique ioctl commands */
66 #define	DLDIOC(cmdid)		DLD_IOC_CMD(DLD_IOC, (cmdid))
67 #define	AGGRIOC(cmdid)		DLD_IOC_CMD(AGGR_IOC, (cmdid))
68 #define	VNICIOC(cmdid)		DLD_IOC_CMD(VNIC_IOC, (cmdid))
69 #define	SIMNETIOC(cmdid)	DLD_IOC_CMD(SIMNET_IOC, (cmdid))
70 #define	IPTUNIOC(cmdid)		DLD_IOC_CMD(IPTUN_IOC, (cmdid))
71 #define	BRIDGEIOC(cmdid)	DLD_IOC_CMD(BRIDGE_IOC, (cmdid))
72 #define	IBPARTIOC(cmdid)	DLD_IOC_CMD(IBPART_IOC, (cmdid))
73 #define	OVERLAYIOC(cmdid)	DLD_IOC_CMD(OVERLAY_IOC, (cmdid))
74 
75 #ifdef _KERNEL
76 
77 /*
78  * GLDv3 modules register the ioctls they're interested in by passing
79  * in an array of dld_ioc_info_t to dld_ioc_register().  Modules
80  * should call dld_ioc_register() either in _init() or attach().  The
81  * dld module assumes that ddi_hold_devi_by_instance(<module>, 0, 0)
82  * will cause the module to load and call dld_ioc_register().
83  *
84  * The di_cmd field is an ioctl command generated using one of the
85  * macros above.  The di_argsize value is used by dld to copyin or
86  * copyout the correct amount of data depending on whether the
87  * DLDCOPYIN or DLDCOPYOUT flags are set so that every di_func()
88  * callback function does not need to copyin/out its own data.
89  */
90 
91 typedef int (dld_ioc_func_t)(void *, intptr_t, int, cred_t *, int *);
92 typedef int (dld_ioc_priv_func_t)(const cred_t *);
93 typedef struct dld_ioc_info {
94 	uint_t		di_cmd;
95 	uint_t		di_flags;
96 	size_t		di_argsize;
97 	dld_ioc_func_t	*di_func;
98 	dld_ioc_priv_func_t *di_priv_func;
99 } dld_ioc_info_t;
100 
101 /* Values for di_flags */
102 #define	DLDCOPYIN	0x00000001 /* copyin di_argsize amount of data */
103 #define	DLDCOPYOUT	0x00000002 /* copyout di_argsize amount of data */
104 #define	DLDCOPYINOUT	(DLDCOPYIN | DLDCOPYOUT)
105 
106 #define	DLDIOCCNT(l)	(sizeof (l) / sizeof (dld_ioc_info_t))
107 int	dld_ioc_register(uint16_t, dld_ioc_info_t *, uint_t);
108 void	dld_ioc_unregister(uint16_t);
109 
110 #endif /* _KERNEL */
111 
112 #ifdef	__cplusplus
113 }
114 #endif
115 
116 #endif	/* _SYS_DLD_IOC_H */
117