xref: /titanic_50/usr/src/uts/sun4v/sys/vsw.h (revision 0c19630b1592aa30d3e4d9db1a2a8cf9a91c0e72)
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 /*
23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  * This header file contains the data structures which the
29  * virtual switch (vsw) uses to communicate with its clients and
30  * the outside world.
31  */
32 
33 #ifndef	_VSW_H
34 #define	_VSW_H
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 #include <sys/vio_mailbox.h>
41 #include <sys/vnet_common.h>
42 #include <sys/ethernet.h>
43 #include <sys/mac_client.h>
44 #include <sys/vio_util.h>
45 #include <sys/vgen_stats.h>
46 #include <sys/vsw_ldc.h>
47 #include <sys/vsw_hio.h>
48 #include <sys/callb.h>
49 
50 #define	DRV_NAME	"vsw"
51 
52 /*
53  * Only support ETHER mtu at moment.
54  */
55 #define	VSW_MTU		ETHERMAX
56 
57 /* ID of the source of a frame being switched */
58 #define	VSW_PHYSDEV		1	/* physical device associated */
59 #define	VSW_VNETPORT		2	/* port connected to vnet (over ldc) */
60 #define	VSW_LOCALDEV		4	/* vsw configured as an eth interface */
61 
62 /*
63  * Number of hash chains in the multicast forwarding database.
64  */
65 #define		VSW_NCHAINS	8
66 
67 /* Number of transmit descriptors -  must be power of 2 */
68 #define		VSW_RING_NUM_EL	512
69 
70 /*
71  * State of interface if switch plumbed as network device.
72  */
73 #define		VSW_IF_REG	0x1	/* interface was registered */
74 #define		VSW_IF_UP	0x2	/* Interface UP */
75 #define		VSW_IF_PROMISC	0x4	/* Interface in promiscious mode */
76 
77 #define		VSW_U_P(state)	\
78 			(state == (VSW_IF_UP | VSW_IF_PROMISC))
79 
80 /*
81  * Switching modes.
82  */
83 #define		VSW_LAYER2		0x1	/* Layer 2 - MAC switching */
84 #define		VSW_LAYER2_PROMISC	0x2	/* Layer 2 + promisc mode */
85 #define		VSW_LAYER3		0x4	/* Layer 3 - IP switching */
86 
87 #define		NUM_SMODES	3	/* number of switching modes */
88 
89 #define	VSW_PRI_ETH_DEFINED(vswp)	((vswp)->pri_num_types != 0)
90 
91 typedef enum {
92 	VSW_SWTHR_STOP = 0x1
93 } sw_thr_flags_t;
94 
95 typedef enum {
96 	PROG_init = 0x00,
97 	PROG_locks = 0x01,
98 	PROG_readmd = 0x02,
99 	PROG_fdb = 0x04,
100 	PROG_mfdb = 0x08,
101 	PROG_taskq = 0x10,
102 	PROG_rxp_taskq = 0x20,
103 	PROG_swmode = 0x40,
104 	PROG_macreg = 0x80,
105 	PROG_mdreg = 0x100
106 } vsw_attach_progress_t;
107 
108 /*
109  * vlan-id information.
110  */
111 typedef struct vsw_vlanid {
112 	uint16_t		vl_vid;		/* vlan-id */
113 	mac_unicast_handle_t	vl_muh;		/* mac unicast handle */
114 	boolean_t		vl_set;		/* set? */
115 } vsw_vlanid_t;
116 
117 /*
118  * vsw instance state information.
119  */
120 typedef struct	vsw {
121 	int			instance;	/* instance # */
122 	dev_info_t		*dip;		/* associated dev_info */
123 	uint64_t		regprop;	/* "reg" property */
124 	vsw_attach_progress_t	attach_progress; /* attach progress flags */
125 	struct vsw		*next;		/* next in list */
126 	char			physname[LIFNAMSIZ];	/* phys-dev */
127 	uint8_t			smode;		/* switching mode */
128 	kmutex_t		sw_thr_lock;	/* setup switching thr lock */
129 	kcondvar_t		sw_thr_cv;	/* cv for setup switching thr */
130 	kthread_t		*sw_thread;	/* setup switching thread */
131 	sw_thr_flags_t		sw_thr_flags; 	/* setup switching thr flags */
132 	uint32_t		switching_setup_done; /* setup switching done */
133 	int			mac_open_retries; /* mac_open() retry count */
134 	vsw_port_list_t		plist;		/* associated ports */
135 	ddi_taskq_t		*taskq_p;	/* VIO ctrl msg taskq */
136 	mod_hash_t		*fdb_hashp;	/* forwarding database */
137 	uint32_t		fdb_nchains;	/* # of hash chains in fdb */
138 	mod_hash_t		*vlan_hashp;	/* vlan hash table */
139 	uint32_t		vlan_nchains;	/* # of vlan hash chains */
140 	uint32_t		mtu;		/* mtu of the device */
141 	uint32_t		max_frame_size;	/* max frame size supported */
142 	uint32_t		mtu_physdev_orig; /* orig mtu of the physdev */
143 
144 	mod_hash_t		*mfdb;		/* multicast FDB */
145 	krwlock_t		mfdbrw;		/* rwlock for mFDB */
146 
147 	ddi_taskq_t		*rxp_taskq;	/* VIO rx pool taskq */
148 	void			(*vsw_switch_frame)
149 					(struct vsw *, mblk_t *, int,
150 					vsw_port_t *, mac_resource_handle_t);
151 
152 	/* mac layer */
153 	kmutex_t		mac_lock;	/* protect mh */
154 	mac_handle_t		mh;
155 	krwlock_t		maccl_rwlock;	/* protect fields below */
156 	mac_client_handle_t	mch;		/* mac client handle */
157 	mac_unicast_handle_t	muh;		/* mac unicast handle */
158 	mac_notify_handle_t	mnh;		/* mac notify handle */
159 
160 	boolean_t		recfg_reqd;	/* Reconfig of addrs needed */
161 
162 	/* mac layer switching flag */
163 	boolean_t		mac_cl_switching;
164 
165 	/* Machine Description updates  */
166 	mdeg_node_spec_t	*inst_spec;
167 	mdeg_handle_t		mdeg_hdl;
168 	mdeg_handle_t		mdeg_port_hdl;
169 
170 	/* if configured as an ethernet interface */
171 	mac_handle_t		if_mh;		/* MAC handle */
172 	struct ether_addr	if_addr;	/* interface address */
173 	krwlock_t		if_lockrw;
174 	uint8_t			if_state;	/* interface state */
175 
176 	boolean_t		addr_set;	/* is addr set to HW */
177 
178 	/* multicast addresses when configured as eth interface */
179 	kmutex_t		mca_lock;	/* multicast lock */
180 	mcst_addr_t		*mcap;		/* list of multicast addrs */
181 
182 	uint32_t		pri_num_types;	/* # of priority eth types */
183 	uint16_t		*pri_types;	/* priority eth types */
184 	vio_mblk_pool_t		*pri_tx_vmp;	/* tx priority mblk pool */
185 	uint16_t		default_vlan_id; /* default vlan id */
186 	uint16_t		pvid;	/* port vlan id (untagged) */
187 	vsw_vlanid_t		*vids;	/* vlan ids (tagged) */
188 	uint16_t		nvids;	/* # of vids */
189 	uint32_t		vids_size; /* size alloc'd for vids list */
190 
191 	/* HybridIO related fields */
192 	boolean_t		hio_capable;	/* Phys dev HIO capable */
193 	vsw_hio_t		vhio;		/* HybridIO info */
194 	callb_id_t		hio_reboot_cb_id; /* Reboot callb ID */
195 	callb_id_t		hio_panic_cb_id; /* Panic callb ID */
196 
197 	/* Link-state related fields */
198 	boolean_t		phys_no_link_update; /* no link-update supp */
199 	boolean_t		pls_update;	/* phys link state update ? */
200 	link_state_t		phys_link_state;    /* physical link state */
201 } vsw_t;
202 
203 /*
204  * The flags that are used by vsw_mac_rx().
205  */
206 typedef enum {
207 	VSW_MACRX_PROMISC = 0x01,
208 	VSW_MACRX_COPYMSG = 0x02,
209 	VSW_MACRX_FREEMSG = 0x04
210 } vsw_macrx_flags_t;
211 
212 
213 #ifdef DEBUG
214 
215 extern int vswdbg;
216 extern void vswdebug(vsw_t *vswp, const char *fmt, ...);
217 
218 #define	D1(...)		\
219 if (vswdbg & 0x01)	\
220 	vswdebug(__VA_ARGS__)
221 
222 #define	D2(...)		\
223 if (vswdbg & 0x02)	\
224 	vswdebug(__VA_ARGS__)
225 
226 #define	D3(...)		\
227 if (vswdbg & 0x04)	\
228 	vswdebug(__VA_ARGS__)
229 
230 #define	DWARN(...)	\
231 if (vswdbg & 0x08)	\
232 	vswdebug(__VA_ARGS__)
233 
234 #define	DERR(...)	\
235 if (vswdbg & 0x10)	\
236 	vswdebug(__VA_ARGS__)
237 
238 #else
239 
240 #define	DERR(...)	if (0)	do { } while (0)
241 #define	DWARN(...)	if (0)	do { } while (0)
242 #define	D1(...)		if (0)	do { } while (0)
243 #define	D2(...)		if (0)	do { } while (0)
244 #define	D3(...)		if (0)	do { } while (0)
245 
246 #endif	/* DEBUG */
247 
248 
249 #ifdef	__cplusplus
250 }
251 #endif
252 
253 #endif	/* _VSW_H */
254