xref: /titanic_50/usr/src/uts/common/sys/dls.h (revision 4045d94132614e1de2073685a6cdd4fbd86bec33)
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_BASE		128
127 
128 /*
129  * Indicate the link mapping is active or persistent
130  */
131 #define	DLMGMT_ACTIVE		0x01
132 #define	DLMGMT_PERSIST		0x02
133 
134 /* upcall argument */
135 typedef struct dlmgmt_door_arg {
136 	uint_t			ld_cmd;
137 } dlmgmt_door_arg_t;
138 
139 typedef struct dlmgmt_upcall_arg_create {
140 	int			ld_cmd;
141 	datalink_class_t	ld_class;
142 	uint32_t		ld_media;
143 	boolean_t		ld_persist;
144 	uint64_t		ld_phymaj;
145 	uint64_t		ld_phyinst;
146 	char			ld_devname[MAXNAMELEN];
147 } dlmgmt_upcall_arg_create_t;
148 
149 /*
150  * Note: ld_padding is necessary to keep the size of the structure the
151  * same on amd64 and i386.  The same note applies to other ld_padding
152  * and lr_paddding fields in structures throughout this file.
153  */
154 typedef struct dlmgmt_upcall_arg_destroy {
155 	int			ld_cmd;
156 	datalink_id_t		ld_linkid;
157 	boolean_t		ld_persist;
158 	int			ld_padding;
159 } dlmgmt_upcall_arg_destroy_t;
160 
161 typedef struct dlmgmt_upcall_arg_update {
162 	int			ld_cmd;
163 	boolean_t		ld_novanity;
164 	uint32_t		ld_media;
165 	uint32_t		ld_padding;
166 	char			ld_devname[MAXNAMELEN];
167 } dlmgmt_upcall_arg_update_t;
168 
169 typedef struct dlmgmt_upcall_arg_getattr {
170 	int			ld_cmd;
171 	datalink_id_t		ld_linkid;
172 	char			ld_attr[MAXLINKATTRLEN];
173 } dlmgmt_upcall_arg_getattr_t;
174 
175 typedef struct dlmgmt_door_getname {
176 	int			ld_cmd;
177 	datalink_id_t		ld_linkid;
178 } dlmgmt_door_getname_t;
179 
180 typedef struct dlmgmt_door_getlinkid {
181 	int			ld_cmd;
182 	char			ld_link[MAXLINKNAMELEN];
183 } dlmgmt_door_getlinkid_t;
184 
185 typedef struct dlmgmt_door_getnext_s {
186 	int			ld_cmd;
187 	datalink_id_t		ld_linkid;
188 	datalink_class_t	ld_class;
189 	uint32_t		ld_flags;
190 	datalink_media_t	ld_dmedia;
191 } dlmgmt_door_getnext_t;
192 
193 /* upcall return value */
194 typedef struct dlmgmt_retval_s {
195 	uint_t			lr_err; /* return error code */
196 } dlmgmt_retval_t;
197 
198 typedef dlmgmt_retval_t	dlmgmt_destroy_retval_t;
199 
200 struct dlmgmt_linkid_retval_s {
201 	uint_t			lr_err;
202 	datalink_id_t		lr_linkid;
203 	uint32_t		lr_flags;
204 	datalink_class_t	lr_class;
205 	uint32_t		lr_media;
206 	uint32_t		lr_padding;
207 };
208 
209 typedef struct dlmgmt_linkid_retval_s	dlmgmt_create_retval_t,
210 					dlmgmt_update_retval_t,
211 					dlmgmt_getlinkid_retval_t,
212 					dlmgmt_getnext_retval_t;
213 
214 typedef struct dlmgmt_getname_retval_s {
215 	uint_t			lr_err;
216 	char			lr_link[MAXLINKNAMELEN];
217 	datalink_class_t	lr_class;
218 	uint32_t		lr_media;
219 	uint32_t		lr_flags;
220 } dlmgmt_getname_retval_t;
221 
222 typedef struct dlmgmt_getattr_retval_s {
223 	uint_t			lr_err;
224 	uint_t			lr_type;
225 	uint_t			lr_attrsz;
226 	uint_t			lr_padding;
227 	char			lr_attrval[MAXLINKATTRVALLEN];
228 } dlmgmt_getattr_retval_t;
229 
230 #ifdef	_KERNEL
231 
232 #define	DLS_MAX_PPA	999
233 #define	DLS_MAX_MINOR	(DLS_MAX_PPA + 1)
234 
235 typedef	struct dls_t		*dls_channel_t;
236 
237 extern int		dls_open_style2_vlan(major_t, uint_t, dls_channel_t *);
238 extern int		dls_open_by_dev(dev_t, dls_channel_t *);
239 extern void		dls_close(dls_channel_t);
240 
241 extern mac_handle_t	dls_mac(dls_channel_t);
242 extern uint16_t		dls_vid(dls_channel_t);
243 
244 #define	DLS_SAP_LLC	0
245 #define	DLS_SAP_PROMISC	(1 << 16)
246 
247 extern int		dls_bind(dls_channel_t, uint32_t);
248 extern void		dls_unbind(dls_channel_t);
249 
250 #define	DLS_PROMISC_SAP		0x00000001
251 #define	DLS_PROMISC_MULTI	0x00000002
252 #define	DLS_PROMISC_PHYS	0x00000004
253 
254 extern int		dls_promisc(dls_channel_t, uint32_t);
255 
256 extern int		dls_multicst_add(dls_channel_t, const uint8_t *);
257 extern int		dls_multicst_remove(dls_channel_t, const uint8_t *);
258 
259 extern mblk_t		*dls_header(dls_channel_t, const uint8_t *,
260 			    uint16_t, uint_t, mblk_t **);
261 extern int		dls_header_info(dls_channel_t, mblk_t *,
262 			    mac_header_info_t *);
263 
264 typedef	void		(*dls_rx_t)(void *, mac_resource_handle_t, mblk_t *,
265 			    mac_header_info_t *);
266 
267 extern void		dls_rx_set(dls_channel_t, dls_rx_t, void *);
268 
269 extern mblk_t		*dls_tx(dls_channel_t, mblk_t *);
270 
271 extern boolean_t	dls_active_set(dls_channel_t);
272 extern void		dls_active_clear(dls_channel_t);
273 
274 extern dev_info_t	*dls_finddevinfo(dev_t);
275 
276 typedef struct dls_devnet_s	*dls_dl_handle_t;
277 typedef struct dls_dev_t	*dls_dev_handle_t;
278 
279 extern int		dls_devnet_open(const char *,
280 			    dls_dl_handle_t *, dev_t *);
281 extern void		dls_devnet_close(dls_dl_handle_t);
282 extern boolean_t	dls_devnet_rebuild();
283 
284 extern int		dls_devnet_rename(datalink_id_t, datalink_id_t,
285 			    const char *);
286 extern int		dls_devnet_create(mac_handle_t, datalink_id_t);
287 extern int		dls_devnet_destroy(mac_handle_t, datalink_id_t *);
288 extern int		dls_devnet_recreate(mac_handle_t, datalink_id_t);
289 extern int		dls_devnet_create_vlan(datalink_id_t,
290 			    datalink_id_t, uint16_t, boolean_t);
291 extern int		dls_devnet_destroy_vlan(datalink_id_t);
292 extern int		dls_devnet_hold_tmp(datalink_id_t, dls_dl_handle_t *);
293 extern void		dls_devnet_rele_tmp(dls_dl_handle_t);
294 
295 extern const char	*dls_devnet_mac(dls_dl_handle_t);
296 extern uint16_t		dls_devnet_vid(dls_dl_handle_t);
297 extern datalink_id_t	dls_devnet_linkid(dls_dl_handle_t);
298 extern boolean_t	dls_devnet_is_explicit(dls_dl_handle_t);
299 extern int		dls_devnet_dev2linkid(dev_t, datalink_id_t *);
300 extern int		dls_devnet_phydev(datalink_id_t, dev_t *);
301 extern int		dls_devnet_setzid(const char *, zoneid_t);
302 extern int		dls_devnet_getzid(datalink_id_t, zoneid_t *);
303 
304 extern int		dls_mgmt_door_set(boolean_t);
305 extern int		dls_mgmt_create(const char *, dev_t, datalink_class_t,
306 			    uint32_t, boolean_t, datalink_id_t *);
307 extern int		dls_mgmt_destroy(datalink_id_t, boolean_t);
308 extern int		dls_mgmt_update(const char *, uint32_t, boolean_t,
309 			    uint32_t *, datalink_id_t *);
310 extern int		dls_mgmt_get_linkinfo(datalink_id_t, char *,
311 			    datalink_class_t *, uint32_t *, uint32_t *);
312 extern int		dls_mgmt_get_linkid(const char *, datalink_id_t *);
313 extern datalink_id_t	dls_mgmt_get_next(datalink_id_t, datalink_class_t,
314 			    datalink_media_t, uint32_t);
315 
316 #endif	/* _KERNEL */
317 
318 #ifdef	__cplusplus
319 }
320 #endif
321 
322 #endif	/* _SYS_DLS_H */
323