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