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