xref: /illumos-gate/usr/src/uts/common/sys/dls.h (revision 1b83305cfc332b1e19ad6a194b73b2975e6bf79a)
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 
92 /*
93  * Link attributes used by the kernel.
94  */
95 /*
96  * The major number and instance number of the underlying physical device
97  * are kept as FPHYMAJ and FPHYINST (major, instance + 1).
98  *
99  * Set for physical links only.
100  */
101 #define	FPHYMAJ		"phymaj"	/* uint64_t */
102 #define	FPHYINST	"phyinst"	/* uint64_t */
103 
104 /*
105  * The devname of the physical link. For example, bge0, ce1. Set for physical
106  * links only.
107  */
108 #define	FDEVNAME	"devname"	/* string */
109 
110 #define	DLMGMT_DOOR	"/etc/.dlmgmt_door"
111 /*
112  * Door upcall command.
113  */
114 #define	DLMGMT_CMD_DLS_CREATE	1
115 #define	DLMGMT_CMD_DLS_GETATTR	2
116 #define	DLMGMT_CMD_DLS_DESTROY	3
117 #define	DLMGMT_CMD_GETNAME	4
118 #define	DLMGMT_CMD_GETLINKID	5
119 #define	DLMGMT_CMD_GETNEXT	6
120 #define	DLMGMT_CMD_DLS_UPDATE	7
121 #define	DLMGMT_CMD_BASE		128
122 
123 /*
124  * Indicate the link mapping is active or persistent
125  */
126 #define	DLMGMT_ACTIVE		0x01
127 #define	DLMGMT_PERSIST		0x02
128 
129 /* upcall argument */
130 typedef struct dlmgmt_upcall_arg_create {
131 	int			ld_cmd;
132 	datalink_class_t	ld_class;
133 	uint32_t		ld_media;
134 	boolean_t		ld_persist;
135 	uint64_t		ld_phymaj;
136 	uint64_t		ld_phyinst;
137 	char			ld_devname[MAXNAMELEN];
138 } dlmgmt_upcall_arg_create_t;
139 
140 typedef struct dlmgmt_upcall_arg_destroy {
141 	int			ld_cmd;
142 	datalink_id_t		ld_linkid;
143 	boolean_t		ld_persist;
144 	int			ld_reserved;
145 } dlmgmt_upcall_arg_destroy_t;
146 
147 typedef struct dlmgmt_upcall_arg_update {
148 	int			ld_cmd;
149 	boolean_t		ld_novanity;
150 	uint32_t		ld_media;
151 	uint32_t		ld_reserved;
152 	char			ld_devname[MAXNAMELEN];
153 } dlmgmt_upcall_arg_update_t;
154 
155 typedef struct dlmgmt_upcall_arg_getattr {
156 	int			ld_cmd;
157 	datalink_id_t		ld_linkid;
158 	char			ld_attr[MAXLINKATTRLEN];
159 } dlmgmt_upcall_arg_getattr_t;
160 
161 typedef struct dlmgmt_door_getname {
162 	int			ld_cmd;
163 	datalink_id_t		ld_linkid;
164 } dlmgmt_door_getname_t;
165 
166 typedef struct dlmgmt_door_getlinkid {
167 	int			ld_cmd;
168 	char			ld_link[MAXLINKNAMELEN];
169 } dlmgmt_door_getlinkid_t;
170 
171 typedef struct dlmgmt_door_getnext_s {
172 	int			ld_cmd;
173 	datalink_id_t		ld_linkid;
174 	datalink_class_t	ld_class;
175 	uint32_t		ld_flags;
176 	datalink_media_t	ld_dmedia;
177 } dlmgmt_door_getnext_t;
178 
179 /* upcall return value */
180 struct dlmgmt_linkid_retval_s {
181 	uint_t			lr_err;
182 	datalink_id_t		lr_linkid;
183 	uint32_t		lr_flags;
184 	datalink_class_t	lr_class;
185 	uint32_t		lr_media;
186 	uint32_t		lr_reserved;
187 };
188 
189 typedef struct dlmgmt_linkid_retval_s	dlmgmt_create_retval_t,
190 					dlmgmt_update_retval_t,
191 					dlmgmt_getlinkid_retval_t,
192 					dlmgmt_getnext_retval_t;
193 
194 typedef struct dlmgmt_getname_retval_s {
195 	uint_t			lr_err;
196 	char			lr_link[MAXLINKNAMELEN];
197 	datalink_class_t	lr_class;
198 	uint32_t		lr_media;
199 	uint32_t		lr_flags;
200 } dlmgmt_getname_retval_t;
201 
202 struct dlmgmt_null_retval_s {
203 	uint_t			lr_err;
204 };
205 
206 typedef struct dlmgmt_null_retval_s	dlmgmt_destroy_retval_t;
207 
208 typedef struct dlmgmt_getattr_retval_s {
209 	uint_t			lr_err;
210 	uint_t			lr_type;
211 	char			lr_attr[1];
212 } dlmgmt_getattr_retval_t;
213 
214 #ifdef	_KERNEL
215 
216 #define	DLS_MAX_PPA	999
217 #define	DLS_MAX_MINOR	(DLS_MAX_PPA + 1)
218 
219 typedef	struct dls_t		*dls_channel_t;
220 
221 extern int		dls_open_style2_vlan(major_t, uint_t, dls_channel_t *);
222 extern int		dls_open_by_dev(dev_t, dls_channel_t *);
223 extern void		dls_close(dls_channel_t);
224 
225 extern mac_handle_t	dls_mac(dls_channel_t);
226 extern uint16_t		dls_vid(dls_channel_t);
227 
228 #define	DLS_SAP_LLC	0
229 #define	DLS_SAP_PROMISC	(1 << 16)
230 
231 extern int		dls_bind(dls_channel_t, uint32_t);
232 extern void		dls_unbind(dls_channel_t);
233 
234 #define	DLS_PROMISC_SAP		0x00000001
235 #define	DLS_PROMISC_MULTI	0x00000002
236 #define	DLS_PROMISC_PHYS	0x00000004
237 
238 extern int		dls_promisc(dls_channel_t, uint32_t);
239 
240 extern int		dls_multicst_add(dls_channel_t, const uint8_t *);
241 extern int		dls_multicst_remove(dls_channel_t, const uint8_t *);
242 
243 extern mblk_t		*dls_header(dls_channel_t, const uint8_t *,
244 			    uint16_t, uint_t, mblk_t **);
245 extern int		dls_header_info(dls_channel_t, mblk_t *,
246 			    mac_header_info_t *);
247 
248 typedef	void		(*dls_rx_t)(void *, mac_resource_handle_t, mblk_t *,
249 			    mac_header_info_t *);
250 
251 extern void		dls_rx_set(dls_channel_t, dls_rx_t, void *);
252 
253 extern mblk_t		*dls_tx(dls_channel_t, mblk_t *);
254 
255 extern boolean_t	dls_active_set(dls_channel_t);
256 extern void		dls_active_clear(dls_channel_t);
257 
258 extern dev_info_t	*dls_finddevinfo(dev_t);
259 
260 typedef struct dls_devnet_s	*dls_dl_handle_t;
261 typedef struct dls_dev_t	*dls_dev_handle_t;
262 
263 extern int		dls_devnet_open(const char *,
264 			    dls_dl_handle_t *, dev_t *);
265 extern void		dls_devnet_close(dls_dl_handle_t);
266 extern boolean_t	dls_devnet_rebuild();
267 
268 extern int		dls_devnet_rename(datalink_id_t, datalink_id_t,
269 			    const char *);
270 extern int		dls_devnet_create(mac_handle_t, datalink_id_t);
271 extern int		dls_devnet_destroy(mac_handle_t, datalink_id_t *);
272 extern int		dls_devnet_recreate(mac_handle_t, datalink_id_t);
273 extern int		dls_devnet_create_vlan(datalink_id_t,
274 			    datalink_id_t, uint16_t, boolean_t);
275 extern int		dls_devnet_destroy_vlan(datalink_id_t);
276 extern int		dls_devnet_hold_tmp(datalink_id_t, dls_dl_handle_t *);
277 extern void		dls_devnet_rele_tmp(dls_dl_handle_t);
278 
279 extern const char	*dls_devnet_mac(dls_dl_handle_t);
280 extern uint16_t		dls_devnet_vid(dls_dl_handle_t);
281 extern datalink_id_t	dls_devnet_linkid(dls_dl_handle_t);
282 extern boolean_t	dls_devnet_is_explicit(dls_dl_handle_t);
283 extern int		dls_devnet_dev2linkid(dev_t, datalink_id_t *);
284 extern int		dls_devnet_phydev(datalink_id_t, dev_t *);
285 extern int		dls_devnet_setzid(const char *, zoneid_t);
286 extern int		dls_devnet_getzid(datalink_id_t, zoneid_t *);
287 
288 extern int		dls_mgmt_door_set(boolean_t);
289 extern int		dls_mgmt_create(const char *, dev_t, datalink_class_t,
290 			    uint32_t, boolean_t, datalink_id_t *);
291 extern int		dls_mgmt_destroy(datalink_id_t, boolean_t);
292 extern int		dls_mgmt_update(const char *, uint32_t, boolean_t,
293 			    uint32_t *, datalink_id_t *);
294 extern int		dls_mgmt_get_linkinfo(datalink_id_t, char *,
295 			    datalink_class_t *, uint32_t *, uint32_t *);
296 extern int		dls_mgmt_get_linkid(const char *, datalink_id_t *);
297 extern datalink_id_t	dls_mgmt_get_next(datalink_id_t, datalink_class_t,
298 			    datalink_media_t, uint32_t);
299 
300 #endif	/* _KERNEL */
301 
302 #ifdef	__cplusplus
303 }
304 #endif
305 
306 #endif	/* _SYS_DLS_H */
307