xref: /titanic_52/usr/src/uts/sun4v/sys/vsw.h (revision c1ecd8b9404ee0d96d93f02e82c441b9bb149a3d)
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 2008 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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
37 
38 #ifdef	__cplusplus
39 extern "C" {
40 #endif
41 
42 #include <sys/vio_mailbox.h>
43 #include <sys/vnet_common.h>
44 #include <sys/ethernet.h>
45 #include <sys/vio_util.h>
46 #include <sys/vgen_stats.h>
47 #include <sys/vsw_ldc.h>
48 #include <sys/vsw_hio.h>
49 #include <sys/callb.h>
50 
51 #define	DRV_NAME	"vsw"
52 
53 /*
54  * Only support ETHER mtu at moment.
55  */
56 #define	VSW_MTU		ETHERMAX
57 
58 /* ID of the source of a frame being switched */
59 #define	VSW_PHYSDEV		1	/* physical device associated */
60 #define	VSW_VNETPORT		2	/* port connected to vnet (over ldc) */
61 #define	VSW_LOCALDEV		4	/* vsw configured as an eth interface */
62 
63 /*
64  * Vsw queue -- largely modeled after squeue
65  *
66  * VSW_QUEUE_RUNNING, vqueue thread for queue is running.
67  * VSW_QUEUE_DRAINED, vqueue thread has drained current work and is exiting.
68  * VSW_QUEUE_STOP, request for the vqueue thread to stop.
69  * VSW_QUEUE_STOPPED, vqueue thread is not running.
70  */
71 #define	VSW_QUEUE_RUNNING	0x01
72 #define	VSW_QUEUE_DRAINED	0x02
73 #define	VSW_QUEUE_STOP		0x04
74 #define	VSW_QUEUE_STOPPED	0x08
75 
76 typedef struct vsw_queue_s {
77 	kmutex_t	vq_lock;	/* Lock, before using any member. */
78 	kcondvar_t	vq_cv;		/* Async threads block on. */
79 	uint32_t	vq_state;	/* State flags. */
80 
81 	mblk_t		*vq_first;	/* First mblk chain or NULL. */
82 	mblk_t		*vq_last;	/* Last mblk chain. */
83 
84 	processorid_t	vq_bind;	/* Process to bind to */
85 	kthread_t	*vq_worker;	/* Queue's thread */
86 } vsw_queue_t;
87 
88 /*
89  * VSW MAC Ring Resources.
90  *	MAC Ring resource is composed of this state structure and
91  *	a kernel thread to perform the processing of the ring.
92  */
93 typedef struct vsw_mac_ring_s {
94 	uint32_t	ring_state;
95 
96 	mac_blank_t	ring_blank;
97 	void		*ring_arg;
98 
99 	vsw_queue_t	*ring_vqp;
100 	struct vsw	*ring_vswp;
101 } vsw_mac_ring_t;
102 
103 /*
104  * Maximum Ring Resources.
105  */
106 #define	VSW_MAC_RX_RINGS	0x40
107 
108 /*
109  * States for entry in ring table.
110  */
111 #define	VSW_MAC_RING_FREE	1
112 #define	VSW_MAC_RING_INUSE	2
113 
114 /*
115  * Number of hash chains in the multicast forwarding database.
116  */
117 #define		VSW_NCHAINS	8
118 
119 /* Number of transmit descriptors -  must be power of 2 */
120 #define		VSW_RING_NUM_EL	512
121 
122 /*
123  * State of interface if switch plumbed as network device.
124  */
125 #define		VSW_IF_REG	0x1	/* interface was registered */
126 #define		VSW_IF_UP	0x2	/* Interface UP */
127 #define		VSW_IF_PROMISC	0x4	/* Interface in promiscious mode */
128 
129 #define		VSW_U_P(state)	\
130 			(state == (VSW_IF_UP | VSW_IF_PROMISC))
131 
132 /*
133  * Switching modes.
134  */
135 #define		VSW_LAYER2		0x1	/* Layer 2 - MAC switching */
136 #define		VSW_LAYER2_PROMISC	0x2	/* Layer 2 + promisc mode */
137 #define		VSW_LAYER3		0x4	/* Layer 3 - IP switching */
138 
139 #define		NUM_SMODES	3	/* number of switching modes */
140 
141 #define	VSW_PRI_ETH_DEFINED(vswp)	((vswp)->pri_num_types != 0)
142 
143 /*
144  * vsw instance state information.
145  */
146 typedef struct	vsw {
147 	int			instance;	/* instance # */
148 	dev_info_t		*dip;		/* associated dev_info */
149 	uint64_t		regprop;	/* "reg" property */
150 	struct vsw		*next;		/* next in list */
151 	char			physname[LIFNAMSIZ];	/* phys-dev */
152 	uint8_t			smode[NUM_SMODES];	/* switching mode */
153 	int			smode_idx;	/* curr pos in smode array */
154 	int			smode_num;	/* # of modes specified */
155 	kmutex_t		swtmout_lock;	/* setup switching tmout lock */
156 	boolean_t		swtmout_enabled; /* setup switching tmout on */
157 	timeout_id_t		swtmout_id;	/* setup switching tmout id */
158 	uint32_t		switching_setup_done; /* setup switching done */
159 	int			mac_open_retries; /* mac_open() retry count */
160 	vsw_port_list_t		plist;		/* associated ports */
161 	ddi_taskq_t		*taskq_p;	/* VIO ctrl msg taskq */
162 	mod_hash_t		*fdb_hashp;	/* forwarding database */
163 	uint32_t		fdb_nchains;	/* # of hash chains in fdb */
164 	mod_hash_t		*vlan_hashp;	/* vlan hash table */
165 	uint32_t		vlan_nchains;	/* # of vlan hash chains */
166 	uint32_t		max_frame_size;	/* max frame size supported */
167 
168 	mod_hash_t		*mfdb;		/* multicast FDB */
169 	krwlock_t		mfdbrw;		/* rwlock for mFDB */
170 
171 	vio_mblk_pool_t		*rxh;		/* Receive pool handle */
172 	void			(*vsw_switch_frame)
173 					(struct vsw *, mblk_t *, int,
174 					vsw_port_t *, mac_resource_handle_t);
175 
176 	/* mac layer */
177 	krwlock_t		mac_rwlock;	/* protect fields below */
178 	mac_handle_t		mh;
179 	mac_rx_handle_t		mrh;
180 	multiaddress_capab_t	maddr;		/* Multiple uni addr capable */
181 	const mac_txinfo_t	*txinfo;	/* MAC tx routine */
182 	boolean_t		mstarted;	/* Mac Started? */
183 	boolean_t		mresources;	/* Mac Resources cb? */
184 
185 	/*
186 	 * MAC Ring Resources.
187 	 */
188 	kmutex_t		mac_ring_lock;	/* Lock for the table. */
189 	uint32_t		mac_ring_tbl_sz;
190 	vsw_mac_ring_t		*mac_ring_tbl;	/* Mac ring table. */
191 
192 	kmutex_t		hw_lock;	/* sync access to HW */
193 	boolean_t		recfg_reqd;	/* Reconfig of addrs needed */
194 	int			promisc_cnt;
195 
196 	/* Machine Description updates  */
197 	mdeg_node_spec_t	*inst_spec;
198 	mdeg_handle_t		mdeg_hdl;
199 	mdeg_handle_t		mdeg_port_hdl;
200 
201 	/* if configured as an ethernet interface */
202 	mac_handle_t		if_mh;		/* MAC handle */
203 	struct ether_addr	if_addr;	/* interface address */
204 	krwlock_t		if_lockrw;
205 	uint8_t			if_state;	/* interface state */
206 
207 	mac_addr_slot_t		addr_slot;	/* Unicast address slot */
208 	int			addr_set;	/* Addr set where */
209 
210 	/* multicast addresses when configured as eth interface */
211 	kmutex_t		mca_lock;	/* multicast lock */
212 	mcst_addr_t		*mcap;		/* list of multicast addrs */
213 
214 	uint32_t		pri_num_types;	/* # of priority eth types */
215 	uint16_t		*pri_types;	/* priority eth types */
216 	vio_mblk_pool_t		*pri_tx_vmp;	/* tx priority mblk pool */
217 	uint16_t		default_vlan_id; /* default vlan id */
218 	uint16_t		pvid;	/* port vlan id (untagged) */
219 	uint16_t		*vids;	/* vlan ids (tagged) */
220 	uint16_t		nvids;	/* # of vids */
221 	uint32_t		vids_size; /* size alloc'd for vids list */
222 
223 	/* HybridIO related fields */
224 	boolean_t		hio_capable;	/* Phys dev HIO capable */
225 	vsw_hio_t		vhio;		/* HybridIO info */
226 	callb_id_t		hio_reboot_cb_id; /* Reboot callb ID */
227 	callb_id_t		hio_panic_cb_id; /* Panic callb ID */
228 } vsw_t;
229 
230 /*
231  * The flags that are used by vsw_mac_rx().
232  */
233 typedef enum {
234 	VSW_MACRX_PROMISC = 0x01,
235 	VSW_MACRX_COPYMSG = 0x02,
236 	VSW_MACRX_FREEMSG = 0x04
237 } vsw_macrx_flags_t;
238 
239 
240 #ifdef DEBUG
241 
242 extern int vswdbg;
243 extern void vswdebug(vsw_t *vswp, const char *fmt, ...);
244 
245 #define	D1(...)		\
246 if (vswdbg & 0x01)	\
247 	vswdebug(__VA_ARGS__)
248 
249 #define	D2(...)		\
250 if (vswdbg & 0x02)	\
251 	vswdebug(__VA_ARGS__)
252 
253 #define	D3(...)		\
254 if (vswdbg & 0x04)	\
255 	vswdebug(__VA_ARGS__)
256 
257 #define	DWARN(...)	\
258 if (vswdbg & 0x08)	\
259 	vswdebug(__VA_ARGS__)
260 
261 #define	DERR(...)	\
262 if (vswdbg & 0x10)	\
263 	vswdebug(__VA_ARGS__)
264 
265 #else
266 
267 #define	DERR(...)	if (0)	do { } while (0)
268 #define	DWARN(...)	if (0)	do { } while (0)
269 #define	D1(...)		if (0)	do { } while (0)
270 #define	D2(...)		if (0)	do { } while (0)
271 #define	D3(...)		if (0)	do { } while (0)
272 
273 #endif	/* DEBUG */
274 
275 
276 #ifdef	__cplusplus
277 }
278 #endif
279 
280 #endif	/* _VSW_H */
281