xref: /titanic_44/usr/src/uts/common/sys/dls_impl.h (revision ea01bd62c06264135e67699c4e213c6de9313abe)
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_IMPL_H
27 #define	_SYS_DLS_IMPL_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <sys/stream.h>
32 #include <sys/dls.h>
33 #include <sys/mac.h>
34 #include <sys/modhash.h>
35 #include <sys/kstat.h>
36 #include <net/if.h>
37 #include <sys/dlpi.h>
38 #include <sys/dls_soft_ring.h>
39 
40 #ifdef	__cplusplus
41 extern "C" {
42 #endif
43 
44 typedef struct dls_multicst_addr_s	dls_multicst_addr_t;
45 
46 struct dls_multicst_addr_s {
47 	dls_multicst_addr_t	*dma_nextp;
48 	uint8_t			dma_addr[MAXMACADDRLEN];
49 };
50 
51 typedef	struct dls_link_s	dls_link_t;
52 
53 struct dls_link_s {
54 	char			dl_name[MAXNAMELEN];
55 	mac_handle_t		dl_mh;
56 	const mac_info_t	*dl_mip;
57 	mac_rx_handle_t		dl_mrh;
58 	mac_txloop_handle_t	dl_mth;
59 	uint_t			dl_ref;
60 	uint_t			dl_macref;
61 	mod_hash_t		*dl_impl_hash;
62 	krwlock_t		dl_impl_lock;
63 	uint_t			dl_impl_count;
64 	kmutex_t		dl_promisc_lock;
65 	uint_t			dl_npromisc;
66 	uint_t			dl_nactive;
67 	uint32_t		dl_unknowns;
68 	kmutex_t		dl_lock;
69 };
70 
71 typedef struct dls_impl_s dls_impl_t;
72 typedef struct dls_head_s dls_head_t;
73 
74 /*
75  * The maximum length of an SPA (subnetwork point of attachment).  It is of
76  * the form <macname/vid>.
77  */
78 #define	MAXSPALEN		(MAXNAMELEN + 5)
79 
80 typedef struct dls_vlan_s {
81 	/*
82 	 * The following fields will not change after dls_vlan_t creation.
83 	 */
84 	dls_link_t		*dv_dlp;
85 	uint16_t		dv_id;
86 
87 	/*
88 	 * Unique SPA (of the form <macname/vid>) identifying a data-link;
89 	 * is needed to avoid name collisions between an explicitly and
90 	 * implicitly created VLANs.
91 	 */
92 	char			dv_spa[MAXSPALEN];
93 
94 	/*
95 	 * The ppa value of the associated device. Used to derive this link's
96 	 * devfs node name.
97 	 */
98 	uint_t			dv_ppa;
99 
100 	/*
101 	 * The dev_t used to access this dls_vlan_t.
102 	 */
103 	dev_t			dv_dev;
104 
105 	dev_info_t		*dv_dip;
106 	kstat_t			*dv_ksp;
107 	uint32_t		dv_force : 1;
108 
109 	/*
110 	 * The following fields are protected by dv_lock.
111 	 */
112 	kmutex_t		dv_lock;
113 
114 	/*
115 	 * Reference count of dls_impl_t plus explicit creation of the link
116 	 */
117 	uint_t			dv_ref;
118 
119 	/*
120 	 * The reference count of this vlan is opened in its own zone.
121 	 */
122 	uint_t			dv_zone_ref;
123 	zoneid_t		dv_zid;
124 } dls_vlan_t;
125 
126 struct dls_impl_s {
127 	dls_impl_t			*di_nextp;
128 	dls_head_t			*di_headp;
129 	dls_vlan_t			*di_dvp;
130 	mac_handle_t			di_mh;
131 	mac_notify_handle_t		di_mnh;
132 	const mac_info_t		*di_mip;
133 	krwlock_t			di_lock;
134 	uint16_t			di_sap;
135 	uint_t				di_promisc;
136 	dls_multicst_addr_t		*di_dmap;
137 	dls_rx_t			di_rx;
138 	void				*di_rx_arg;
139 	mac_resource_add_t		di_ring_add;
140 	const mac_txinfo_t		*di_txinfo;
141 	uint_t				di_bound : 1,
142 					di_removing : 1,
143 					di_active : 1,
144 					di_local : 1;
145 
146 	uint8_t				di_unicst_addr[MAXMACADDRLEN];
147 	soft_ring_t			**di_soft_ring_list;
148 	uint_t				di_soft_ring_size;
149 	dls_dl_handle_t			di_ddh;
150 };
151 
152 struct dls_head_s {
153 	dls_impl_t			*dh_list;
154 	uint_t				dh_ref;
155 	mod_hash_key_t			dh_key;
156 };
157 
158 extern void		dls_link_init(void);
159 extern int		dls_link_fini(void);
160 extern int		dls_link_hold(const char *, dls_link_t **);
161 extern void		dls_link_rele(dls_link_t *);
162 extern void		dls_link_add(dls_link_t *, uint32_t, dls_impl_t *);
163 extern void		dls_link_remove(dls_link_t *, dls_impl_t *);
164 extern int		dls_link_header_info(dls_link_t *, mblk_t *,
165 			    mac_header_info_t *);
166 extern int		dls_mac_hold(dls_link_t *);
167 extern void		dls_mac_rele(dls_link_t *);
168 extern boolean_t	dls_mac_active_set(dls_link_t *);
169 extern void		dls_mac_active_clear(dls_link_t *);
170 
171 extern void		dls_mac_stat_create(dls_vlan_t *);
172 extern void		dls_mac_stat_destroy(dls_vlan_t *);
173 
174 extern void		dls_vlan_init(void);
175 extern int		dls_vlan_fini(void);
176 extern int		dls_vlan_hold(const char *, uint16_t, dls_vlan_t **,
177 			    boolean_t, boolean_t);
178 extern int		dls_vlan_hold_by_dev(dev_t, dls_vlan_t **);
179 extern void		dls_vlan_rele(dls_vlan_t *);
180 extern int		dls_vlan_destroy(const char *, uint16_t);
181 extern int		dls_vlan_create(const char *, uint16_t, boolean_t);
182 extern int		dls_vlan_setzid(const char *, uint16_t, zoneid_t);
183 extern int		dls_stat_update(kstat_t *, dls_vlan_t *, int);
184 extern int		dls_stat_create(const char *, int, const char *,
185 			    int (*)(struct kstat *, int), void *, kstat_t **);
186 
187 extern int		dls_devnet_open_by_dev(dev_t, dls_vlan_t **,
188 			    dls_dl_handle_t *);
189 
190 extern void		dls_init(void);
191 extern int		dls_fini(void);
192 extern void		dls_link_txloop(void *, mblk_t *);
193 extern boolean_t	dls_accept(dls_impl_t *, mac_header_info_t *,
194 			    dls_rx_t *, void **);
195 extern boolean_t	dls_accept_loopback(dls_impl_t *, mac_header_info_t *,
196 			    dls_rx_t *, void **);
197 
198 extern void		dls_mgmt_init(void);
199 extern void		dls_mgmt_fini(void);
200 
201 extern int		dls_mgmt_get_phydev(datalink_id_t, dev_t *);
202 
203 #ifdef	__cplusplus
204 }
205 #endif
206 
207 #endif	/* _SYS_DLS_IMPL_H */
208