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