xref: /illumos-gate/usr/src/uts/common/sys/dls.h (revision 6a604193b70017bd933cd973200b3f13803674b2)
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_DLS_H
27 #define	_SYS_DLS_H
28 
29 #include <sys/types.h>
30 #include <sys/stream.h>
31 #include <net/if.h>
32 #include <sys/mac.h>
33 
34 /*
35  * Data-Link Services Module
36  */
37 
38 #ifdef	__cplusplus
39 extern "C" {
40 #endif
41 
42 /*
43  * Module name.
44  */
45 #define	DLS_MODULE_NAME	"dls"
46 
47 /*
48  * Data-Link Services Information (text emitted by modinfo(1m))
49  */
50 #define	DLS_INFO	"Data-Link Services"
51 
52 /*
53  * Macros for converting ppas to instance #s, Vlan ID, or minor.
54  */
55 #define	DLS_PPA2INST(ppa)	((int)((ppa) % 1000))
56 #define	DLS_PPA2VID(ppa)	((ppa) / 1000)
57 
58 /*
59  * Converts a minor to an instance#; makes sense only when minor <= 1000.
60  */
61 #define	DLS_MINOR2INST(minor)	((int)((minor) - 1))
62 
63 typedef enum {
64 	DATALINK_CLASS_PHYS		= 0x01,
65 	DATALINK_CLASS_VLAN		= 0x02,
66 	DATALINK_CLASS_AGGR		= 0x04,
67 	DATALINK_CLASS_VNIC		= 0x08
68 } datalink_class_t;
69 
70 #define	DATALINK_CLASS_ALL	(DATALINK_CLASS_PHYS |	\
71 	DATALINK_CLASS_VLAN | DATALINK_CLASS_AGGR | DATALINK_CLASS_VNIC)
72 
73 /*
74  * A combination of flags and media.
75  *   flags is the higher 32 bits, and if it is 0x01, it indicates all media
76  *   types can be accepted; otherwise, only the given media type (specified
77  *   in the lower 32 bits) is accepted.
78  */
79 typedef uint64_t	datalink_media_t;
80 
81 #define	DATALINK_ANY_MEDIATYPE		\
82 	((datalink_media_t)(((datalink_media_t)0x01) << 32))
83 
84 #define	DATALINK_MEDIA_ACCEPTED(dmedia, media)				\
85 	(((uint32_t)(((dmedia) >> 32) & 0xfffffffful) & 0x01) ?		\
86 	B_TRUE : ((uint32_t)((dmedia) & 0xfffffffful) == (media)))
87 
88 #define	MAXLINKATTRLEN		32
89 #define	MAXLINKATTRVALLEN	1024
90 
91 /*
92  * Link attributes used by the kernel.
93  */
94 /*
95  * The major number and instance number of the underlying physical device
96  * are kept as FPHYMAJ and FPHYINST (major, instance + 1).
97  *
98  * Set for physical links only.
99  */
100 #define	FPHYMAJ		"phymaj"	/* uint64_t */
101 #define	FPHYINST	"phyinst"	/* uint64_t */
102 
103 /*
104  * The devname of the physical link. For example, bge0, ce1. Set for physical
105  * links only.
106  */
107 #define	FDEVNAME	"devname"	/* string */
108 
109 /*
110  * The door file for the dlmgmtd (data-link management) daemon.
111  */
112 #define	DLMGMT_DOOR	"/etc/svc/volatile/dladm/dlmgmt_door"
113 
114 /*
115  * Door upcall commands.
116  */
117 #define	DLMGMT_CMD_DLS_CREATE		1
118 #define	DLMGMT_CMD_DLS_GETATTR		2
119 #define	DLMGMT_CMD_DLS_DESTROY		3
120 #define	DLMGMT_CMD_GETNAME		4
121 #define	DLMGMT_CMD_GETLINKID		5
122 #define	DLMGMT_CMD_GETNEXT		6
123 #define	DLMGMT_CMD_DLS_UPDATE		7
124 #define	DLMGMT_CMD_LINKPROP_INIT	8
125 #define	DLMGMT_CMD_BASE			128
126 
127 /*
128  * Indicate the link mapping is active or persistent
129  */
130 #define	DLMGMT_ACTIVE		0x01
131 #define	DLMGMT_PERSIST		0x02
132 
133 /* upcall argument */
134 typedef struct dlmgmt_door_arg {
135 	uint_t			ld_cmd;
136 } dlmgmt_door_arg_t;
137 
138 typedef struct dlmgmt_upcall_arg_create {
139 	int			ld_cmd;
140 	datalink_class_t	ld_class;
141 	uint32_t		ld_media;
142 	boolean_t		ld_persist;
143 	uint64_t		ld_phymaj;
144 	uint64_t		ld_phyinst;
145 	char			ld_devname[MAXNAMELEN];
146 } dlmgmt_upcall_arg_create_t;
147 
148 /*
149  * Note: ld_padding is necessary to keep the size of the structure the
150  * same on amd64 and i386.  The same note applies to other ld_padding
151  * and lr_paddding fields in structures throughout this file.
152  */
153 typedef struct dlmgmt_upcall_arg_destroy {
154 	int			ld_cmd;
155 	datalink_id_t		ld_linkid;
156 	boolean_t		ld_persist;
157 	int			ld_padding;
158 } dlmgmt_upcall_arg_destroy_t;
159 
160 typedef struct dlmgmt_upcall_arg_update {
161 	int			ld_cmd;
162 	boolean_t		ld_novanity;
163 	uint32_t		ld_media;
164 	uint32_t		ld_padding;
165 	char			ld_devname[MAXNAMELEN];
166 } dlmgmt_upcall_arg_update_t;
167 
168 typedef struct dlmgmt_upcall_arg_getattr {
169 	int			ld_cmd;
170 	datalink_id_t		ld_linkid;
171 	char			ld_attr[MAXLINKATTRLEN];
172 } dlmgmt_upcall_arg_getattr_t;
173 
174 typedef struct dlmgmt_door_getname {
175 	int			ld_cmd;
176 	datalink_id_t		ld_linkid;
177 } dlmgmt_door_getname_t;
178 
179 typedef struct dlmgmt_door_getlinkid {
180 	int			ld_cmd;
181 	char			ld_link[MAXLINKNAMELEN];
182 } dlmgmt_door_getlinkid_t;
183 
184 typedef struct dlmgmt_door_getnext_s {
185 	int			ld_cmd;
186 	datalink_id_t		ld_linkid;
187 	datalink_class_t	ld_class;
188 	uint32_t		ld_flags;
189 	datalink_media_t	ld_dmedia;
190 } dlmgmt_door_getnext_t;
191 
192 typedef struct dlmgmt_door_linkprop_init {
193 	int			ld_cmd;
194 	datalink_id_t		ld_linkid;
195 } dlmgmt_door_linkprop_init_t;
196 
197 /* upcall return value */
198 typedef struct dlmgmt_retval_s {
199 	uint_t			lr_err; /* return error code */
200 } dlmgmt_retval_t;
201 
202 typedef dlmgmt_retval_t	dlmgmt_destroy_retval_t,
203 			dlmgmt_linkprop_init_retval_t;
204 
205 struct dlmgmt_linkid_retval_s {
206 	uint_t			lr_err;
207 	datalink_id_t		lr_linkid;
208 	uint32_t		lr_flags;
209 	datalink_class_t	lr_class;
210 	uint32_t		lr_media;
211 	uint32_t		lr_padding;
212 };
213 
214 typedef struct dlmgmt_linkid_retval_s	dlmgmt_create_retval_t,
215 					dlmgmt_update_retval_t,
216 					dlmgmt_getlinkid_retval_t,
217 					dlmgmt_getnext_retval_t;
218 
219 typedef struct dlmgmt_getname_retval_s {
220 	uint_t			lr_err;
221 	char			lr_link[MAXLINKNAMELEN];
222 	datalink_class_t	lr_class;
223 	uint32_t		lr_media;
224 	uint32_t		lr_flags;
225 } dlmgmt_getname_retval_t;
226 
227 typedef struct dlmgmt_getattr_retval_s {
228 	uint_t			lr_err;
229 	uint_t			lr_type;
230 	uint_t			lr_attrsz;
231 	uint_t			lr_padding;
232 	char			lr_attrval[MAXLINKATTRVALLEN];
233 } dlmgmt_getattr_retval_t;
234 
235 #ifdef	_KERNEL
236 
237 #define	DLS_MAX_PPA	999
238 #define	DLS_MAX_MINOR	(DLS_MAX_PPA + 1)
239 
240 typedef	struct dls_t		*dls_channel_t;
241 
242 extern int		dls_open_style2_vlan(major_t, uint_t, dls_channel_t *);
243 extern int		dls_open_by_dev(dev_t, dls_channel_t *);
244 extern void		dls_close(dls_channel_t);
245 
246 extern mac_handle_t	dls_mac(dls_channel_t);
247 extern uint16_t		dls_vid(dls_channel_t);
248 
249 #define	DLS_SAP_LLC	0
250 #define	DLS_SAP_PROMISC	(1 << 16)
251 
252 extern int		dls_bind(dls_channel_t, uint32_t);
253 extern void		dls_unbind(dls_channel_t);
254 
255 #define	DLS_PROMISC_SAP		0x00000001
256 #define	DLS_PROMISC_MULTI	0x00000002
257 #define	DLS_PROMISC_PHYS	0x00000004
258 
259 extern int		dls_promisc(dls_channel_t, uint32_t);
260 
261 extern int		dls_multicst_add(dls_channel_t, const uint8_t *);
262 extern int		dls_multicst_remove(dls_channel_t, const uint8_t *);
263 
264 extern mblk_t		*dls_header(dls_channel_t, const uint8_t *,
265 			    uint16_t, uint_t, mblk_t **);
266 extern int		dls_header_info(dls_channel_t, mblk_t *,
267 			    mac_header_info_t *);
268 
269 typedef	void		(*dls_rx_t)(void *, mac_resource_handle_t, mblk_t *,
270 			    mac_header_info_t *);
271 
272 extern void		dls_rx_set(dls_channel_t, dls_rx_t, void *);
273 
274 extern mblk_t		*dls_tx(dls_channel_t, mblk_t *);
275 
276 extern boolean_t	dls_active_set(dls_channel_t);
277 extern void		dls_active_clear(dls_channel_t);
278 
279 extern dev_info_t	*dls_finddevinfo(dev_t);
280 
281 typedef struct dls_devnet_s	*dls_dl_handle_t;
282 typedef struct dls_dev_t	*dls_dev_handle_t;
283 
284 extern int		dls_devnet_open(const char *,
285 			    dls_dl_handle_t *, dev_t *);
286 extern void		dls_devnet_close(dls_dl_handle_t);
287 extern boolean_t	dls_devnet_rebuild();
288 
289 extern int		dls_devnet_rename(datalink_id_t, datalink_id_t,
290 			    const char *);
291 extern int		dls_devnet_create(mac_handle_t, datalink_id_t);
292 extern int		dls_devnet_destroy(mac_handle_t, datalink_id_t *);
293 extern int		dls_devnet_recreate(mac_handle_t, datalink_id_t);
294 extern int		dls_devnet_create_vlan(datalink_id_t,
295 			    datalink_id_t, uint16_t, boolean_t);
296 extern int		dls_devnet_destroy_vlan(datalink_id_t);
297 extern int		dls_devnet_hold_tmp(datalink_id_t, dls_dl_handle_t *);
298 extern void		dls_devnet_rele_tmp(dls_dl_handle_t);
299 extern void		dls_devnet_prop_task_wait(dls_dl_handle_t);
300 
301 extern const char	*dls_devnet_mac(dls_dl_handle_t);
302 extern uint16_t		dls_devnet_vid(dls_dl_handle_t);
303 extern datalink_id_t	dls_devnet_linkid(dls_dl_handle_t);
304 extern boolean_t	dls_devnet_is_explicit(dls_dl_handle_t);
305 extern int		dls_devnet_dev2linkid(dev_t, datalink_id_t *);
306 extern int		dls_devnet_phydev(datalink_id_t, dev_t *);
307 extern int		dls_devnet_setzid(const char *, zoneid_t);
308 extern int		dls_devnet_getzid(datalink_id_t, zoneid_t *);
309 
310 extern int		dls_mgmt_door_set(boolean_t);
311 extern int		dls_mgmt_create(const char *, dev_t, datalink_class_t,
312 			    uint32_t, boolean_t, datalink_id_t *);
313 extern int		dls_mgmt_destroy(datalink_id_t, boolean_t);
314 extern int		dls_mgmt_update(const char *, uint32_t, boolean_t,
315 			    uint32_t *, datalink_id_t *);
316 extern int		dls_mgmt_get_linkinfo(datalink_id_t, char *,
317 			    datalink_class_t *, uint32_t *, uint32_t *);
318 extern int		dls_mgmt_get_linkid(const char *, datalink_id_t *);
319 extern datalink_id_t	dls_mgmt_get_next(datalink_id_t, datalink_class_t,
320 			    datalink_media_t, uint32_t);
321 
322 #endif	/* _KERNEL */
323 
324 #ifdef	__cplusplus
325 }
326 #endif
327 
328 #endif	/* _SYS_DLS_H */
329