summaryrefslogtreecommitdiff
path: root/usr/src/uts/common/sys/dld_ioc.h
blob: 093a4dc0c3e570b29776f3046063b51e8dc87e25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
 * Copyright 2015 Joyent, Inc.
 */

#ifndef	_SYS_DLD_IOC_H
#define	_SYS_DLD_IOC_H

#include <sys/types.h>
#include <sys/cred.h>

#ifdef	__cplusplus
extern "C" {
#endif

/*
 * The name of the dld control device.  All GLDv3 control ioctls are
 * performed on this device.
 */
#define	DLD_CONTROL_DEV		"/dev/dld"

/*
 * GLDv3 ioctl values are structured as follows:
 *
 * |    16-bits     |     16-bits    |
 * +----------------+----------------+
 * |   module-id    |   command-id   |
 * +----------------+----------------+
 */
#define	DLD_IOC_CMD(modid, cmdid)	(((uint_t)(modid) << 16) | (cmdid))
#define	DLD_IOC_MODID(cmd)		(((cmd) & 0xffff0000) >> 16)
/*
 * GLDv3 module ids to be passed in as the first argument to
 * dld_ioc_register() and dld_ioc_unregister().
 */
#define	DLD_IOC		0x0D1D
#define	AGGR_IOC	0x0A66
#define	VNIC_IOC	0x0171
#define	SIMNET_IOC	0x5132
#define	IPTUN_IOC	0x454A
#define	BRIDGE_IOC	0xB81D
#define	IBPART_IOC	0x6171
#define	OVERLAY_IOC	0x2005

/* GLDv3 modules use these macros to generate unique ioctl commands */
#define	DLDIOC(cmdid)		DLD_IOC_CMD(DLD_IOC, (cmdid))
#define	AGGRIOC(cmdid)		DLD_IOC_CMD(AGGR_IOC, (cmdid))
#define	VNICIOC(cmdid)		DLD_IOC_CMD(VNIC_IOC, (cmdid))
#define	SIMNETIOC(cmdid)	DLD_IOC_CMD(SIMNET_IOC, (cmdid))
#define	IPTUNIOC(cmdid)		DLD_IOC_CMD(IPTUN_IOC, (cmdid))
#define	BRIDGEIOC(cmdid)	DLD_IOC_CMD(BRIDGE_IOC, (cmdid))
#define	IBPARTIOC(cmdid)	DLD_IOC_CMD(IBPART_IOC, (cmdid))
#define	OVERLAYIOC(cmdid)	DLD_IOC_CMD(OVERLAY_IOC, (cmdid))

#ifdef _KERNEL

/*
 * GLDv3 modules register the ioctls they're interested in by passing
 * in an array of dld_ioc_info_t to dld_ioc_register().  Modules
 * should call dld_ioc_register() either in _init() or attach().  The
 * dld module assumes that ddi_hold_devi_by_instance(<module>, 0, 0)
 * will cause the module to load and call dld_ioc_register().
 *
 * The di_cmd field is an ioctl command generated using one of the
 * macros above.  The di_argsize value is used by dld to copyin or
 * copyout the correct amount of data depending on whether the
 * DLDCOPYIN or DLDCOPYOUT flags are set so that every di_func()
 * callback function does not need to copyin/out its own data.
 */

typedef int (dld_ioc_func_t)(void *, intptr_t, int, cred_t *, int *);
typedef int (dld_ioc_priv_func_t)(const cred_t *);
typedef struct dld_ioc_info {
	uint_t		di_cmd;
	uint_t		di_flags;
	size_t		di_argsize;
	dld_ioc_func_t	*di_func;
	dld_ioc_priv_func_t *di_priv_func;
} dld_ioc_info_t;

/* Values for di_flags */
#define	DLDCOPYIN	0x00000001 /* copyin di_argsize amount of data */
#define	DLDCOPYOUT	0x00000002 /* copyout di_argsize amount of data */
#define	DLDCOPYINOUT	(DLDCOPYIN | DLDCOPYOUT)

#define	DLDIOCCNT(l)	(sizeof (l) / sizeof (dld_ioc_info_t))
int	dld_ioc_register(uint16_t, dld_ioc_info_t *, uint_t);
void	dld_ioc_unregister(uint16_t);

#endif /* _KERNEL */

#ifdef	__cplusplus
}
#endif

#endif	/* _SYS_DLD_IOC_H */