xref: /titanic_53/usr/src/uts/sun4v/sys/vsw.h (revision 3c1bce15918aed7fd25ce57449e5ca2c718cbc1e)
11ae08745Sheppo /*
21ae08745Sheppo  * CDDL HEADER START
31ae08745Sheppo  *
41ae08745Sheppo  * The contents of this file are subject to the terms of the
51ae08745Sheppo  * Common Development and Distribution License (the "License").
61ae08745Sheppo  * You may not use this file except in compliance with the License.
71ae08745Sheppo  *
81ae08745Sheppo  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
91ae08745Sheppo  * or http://www.opensolaris.org/os/licensing.
101ae08745Sheppo  * See the License for the specific language governing permissions
111ae08745Sheppo  * and limitations under the License.
121ae08745Sheppo  *
131ae08745Sheppo  * When distributing Covered Code, include this CDDL HEADER in each
141ae08745Sheppo  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
151ae08745Sheppo  * If applicable, add the following below this CDDL HEADER, with the
161ae08745Sheppo  * fields enclosed by brackets "[]" replaced with your own identifying
171ae08745Sheppo  * information: Portions Copyright [yyyy] [name of copyright owner]
181ae08745Sheppo  *
191ae08745Sheppo  * CDDL HEADER END
201ae08745Sheppo  */
211ae08745Sheppo 
221ae08745Sheppo /*
23f0ca1d9aSsb155480  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
241ae08745Sheppo  * Use is subject to license terms.
251ae08745Sheppo  */
261ae08745Sheppo 
271ae08745Sheppo /*
2806db247cSraghuram  * This header file contains the data structures which the
291ae08745Sheppo  * virtual switch (vsw) uses to communicate with its clients and
301ae08745Sheppo  * the outside world.
311ae08745Sheppo  */
321ae08745Sheppo 
331ae08745Sheppo #ifndef	_VSW_H
341ae08745Sheppo #define	_VSW_H
351ae08745Sheppo 
361ae08745Sheppo #pragma ident	"%Z%%M%	%I%	%E% SMI"
371ae08745Sheppo 
381ae08745Sheppo #ifdef	__cplusplus
391ae08745Sheppo extern "C" {
401ae08745Sheppo #endif
411ae08745Sheppo 
421ae08745Sheppo #include <sys/vio_mailbox.h>
431ae08745Sheppo #include <sys/vnet_common.h>
441ae08745Sheppo #include <sys/ethernet.h>
45d10e4ef2Snarayan #include <sys/vio_util.h>
4606db247cSraghuram #include <sys/vgen_stats.h>
4706db247cSraghuram #include <sys/vsw_ldc.h>
48678453a8Sspeer #include <sys/vsw_hio.h>
491ae08745Sheppo 
5006db247cSraghuram #define	DRV_NAME	"vsw"
511ae08745Sheppo 
521ae08745Sheppo /*
531ae08745Sheppo  * Only support ETHER mtu at moment.
541ae08745Sheppo  */
551ae08745Sheppo #define	VSW_MTU		ETHERMAX
561ae08745Sheppo 
571ae08745Sheppo /* ID of the source of a frame being switched */
581ae08745Sheppo #define	VSW_PHYSDEV		1	/* physical device associated */
591ae08745Sheppo #define	VSW_VNETPORT		2	/* port connected to vnet (over ldc) */
601ae08745Sheppo #define	VSW_LOCALDEV		4	/* vsw configured as an eth interface */
611ae08745Sheppo 
621ae08745Sheppo /*
637636cb21Slm66018  * Vsw queue -- largely modeled after squeue
6434683adeSsg70180  *
6534683adeSsg70180  * VSW_QUEUE_RUNNING, vqueue thread for queue is running.
6634683adeSsg70180  * VSW_QUEUE_DRAINED, vqueue thread has drained current work and is exiting.
6734683adeSsg70180  * VSW_QUEUE_STOP, request for the vqueue thread to stop.
6834683adeSsg70180  * VSW_QUEUE_STOPPED, vqueue thread is not running.
697636cb21Slm66018  */
707636cb21Slm66018 #define	VSW_QUEUE_RUNNING	0x01
7134683adeSsg70180 #define	VSW_QUEUE_DRAINED	0x02
7234683adeSsg70180 #define	VSW_QUEUE_STOP		0x04
7334683adeSsg70180 #define	VSW_QUEUE_STOPPED	0x08
747636cb21Slm66018 
757636cb21Slm66018 typedef struct vsw_queue_s {
767636cb21Slm66018 	kmutex_t	vq_lock;	/* Lock, before using any member. */
777636cb21Slm66018 	kcondvar_t	vq_cv;		/* Async threads block on. */
787636cb21Slm66018 	uint32_t	vq_state;	/* State flags. */
797636cb21Slm66018 
807636cb21Slm66018 	mblk_t		*vq_first;	/* First mblk chain or NULL. */
817636cb21Slm66018 	mblk_t		*vq_last;	/* Last mblk chain. */
827636cb21Slm66018 
837636cb21Slm66018 	processorid_t	vq_bind;	/* Process to bind to */
847636cb21Slm66018 	kthread_t	*vq_worker;	/* Queue's thread */
857636cb21Slm66018 } vsw_queue_t;
867636cb21Slm66018 
877636cb21Slm66018 /*
887636cb21Slm66018  * VSW MAC Ring Resources.
897636cb21Slm66018  *	MAC Ring resource is composed of this state structure and
907636cb21Slm66018  *	a kernel thread to perform the processing of the ring.
917636cb21Slm66018  */
927636cb21Slm66018 typedef struct vsw_mac_ring_s {
937636cb21Slm66018 	uint32_t	ring_state;
947636cb21Slm66018 
957636cb21Slm66018 	mac_blank_t	ring_blank;
967636cb21Slm66018 	void		*ring_arg;
977636cb21Slm66018 
987636cb21Slm66018 	vsw_queue_t	*ring_vqp;
997636cb21Slm66018 	struct vsw	*ring_vswp;
1007636cb21Slm66018 } vsw_mac_ring_t;
1017636cb21Slm66018 
1027636cb21Slm66018 /*
1037636cb21Slm66018  * Maximum Ring Resources.
1047636cb21Slm66018  */
1057636cb21Slm66018 #define	VSW_MAC_RX_RINGS	0x40
1067636cb21Slm66018 
1077636cb21Slm66018 /*
1087636cb21Slm66018  * States for entry in ring table.
1097636cb21Slm66018  */
1107636cb21Slm66018 #define	VSW_MAC_RING_FREE	1
1117636cb21Slm66018 #define	VSW_MAC_RING_INUSE	2
1127636cb21Slm66018 
1137636cb21Slm66018 /*
1141ae08745Sheppo  * Number of hash chains in the multicast forwarding database.
1151ae08745Sheppo  */
1161ae08745Sheppo #define		VSW_NCHAINS	8
1171ae08745Sheppo 
118f0ca1d9aSsb155480 /* Number of transmit descriptors -  must be power of 2 */
119f0ca1d9aSsb155480 #define		VSW_RING_NUM_EL	512
120f0ca1d9aSsb155480 
1211ae08745Sheppo /*
1221ae08745Sheppo  * State of interface if switch plumbed as network device.
1231ae08745Sheppo  */
124ba2e4443Sseb #define		VSW_IF_REG	0x1	/* interface was registered */
125ba2e4443Sseb #define		VSW_IF_UP	0x2	/* Interface UP */
126ba2e4443Sseb #define		VSW_IF_PROMISC	0x4	/* Interface in promiscious mode */
1271ae08745Sheppo 
1281ae08745Sheppo #define		VSW_U_P(state)	\
1291ae08745Sheppo 			(state == (VSW_IF_UP | VSW_IF_PROMISC))
1301ae08745Sheppo 
1311ae08745Sheppo /*
1321ae08745Sheppo  * Switching modes.
1331ae08745Sheppo  */
1341ae08745Sheppo #define		VSW_LAYER2		0x1	/* Layer 2 - MAC switching */
1351ae08745Sheppo #define		VSW_LAYER2_PROMISC	0x2	/* Layer 2 + promisc mode */
1361ae08745Sheppo #define		VSW_LAYER3		0x4	/* Layer 3 - IP switching */
1371ae08745Sheppo 
1381ae08745Sheppo #define		NUM_SMODES	3	/* number of switching modes */
1391ae08745Sheppo 
140f0ca1d9aSsb155480 #define	VSW_PRI_ETH_DEFINED(vswp)	((vswp)->pri_num_types != 0)
141f0ca1d9aSsb155480 
1421ae08745Sheppo /*
1431ae08745Sheppo  * vsw instance state information.
1441ae08745Sheppo  */
1451ae08745Sheppo typedef struct	vsw {
1461ae08745Sheppo 	int			instance;	/* instance # */
1471ae08745Sheppo 	dev_info_t		*dip;		/* associated dev_info */
14819b65a69Ssb155480 	uint64_t		regprop;	/* "reg" property */
1491ae08745Sheppo 	struct vsw		*next;		/* next in list */
1501ae08745Sheppo 	char			physname[LIFNAMSIZ];	/* phys-dev */
1511ae08745Sheppo 	uint8_t			smode[NUM_SMODES];	/* switching mode */
1521ae08745Sheppo 	int			smode_idx;	/* curr pos in smode array */
153e1ebb9ecSlm66018 	int			smode_num;	/* # of modes specified */
15419b65a69Ssb155480 	kmutex_t		swtmout_lock;	/* setup switching tmout lock */
15519b65a69Ssb155480 	boolean_t		swtmout_enabled; /* setup switching tmout on */
15619b65a69Ssb155480 	timeout_id_t		swtmout_id;	/* setup switching tmout id */
15719b65a69Ssb155480 	uint32_t		switching_setup_done; /* setup switching done */
15819b65a69Ssb155480 	int			mac_open_retries; /* mac_open() retry count */
1591ae08745Sheppo 	vsw_port_list_t		plist;		/* associated ports */
1601ae08745Sheppo 	ddi_taskq_t		*taskq_p;	/* VIO ctrl msg taskq */
161c1c61f44Ssb155480 	mod_hash_t		*fdb_hashp;	/* forwarding database */
162c1c61f44Ssb155480 	uint32_t		fdb_nchains;	/* # of hash chains in fdb */
163c1c61f44Ssb155480 	mod_hash_t		*vlan_hashp;	/* vlan hash table */
164c1c61f44Ssb155480 	uint32_t		vlan_nchains;	/* # of vlan hash chains */
165c1c61f44Ssb155480 	uint32_t		max_frame_size;	/* max frame size supported */
1661ae08745Sheppo 
1671ae08745Sheppo 	mod_hash_t		*mfdb;		/* multicast FDB */
1681ae08745Sheppo 	krwlock_t		mfdbrw;		/* rwlock for mFDB */
1691ae08745Sheppo 
170d10e4ef2Snarayan 	vio_mblk_pool_t		*rxh;		/* Receive pool handle */
17134683adeSsg70180 	void			(*vsw_switch_frame)
17234683adeSsg70180 					(struct vsw *, mblk_t *, int,
17334683adeSsg70180 					vsw_port_t *, mac_resource_handle_t);
174d10e4ef2Snarayan 
1751ae08745Sheppo 	/* mac layer */
176*3c1bce15Swentaoy 	krwlock_t		mac_rwlock;	/* protect fields below */
1771ae08745Sheppo 	mac_handle_t		mh;
1781ae08745Sheppo 	mac_rx_handle_t		mrh;
179e1ebb9ecSlm66018 	multiaddress_capab_t	maddr;		/* Multiple uni addr capable */
1801ae08745Sheppo 	const mac_txinfo_t	*txinfo;	/* MAC tx routine */
1817636cb21Slm66018 	boolean_t		mstarted;	/* Mac Started? */
1827636cb21Slm66018 	boolean_t		mresources;	/* Mac Resources cb? */
1837636cb21Slm66018 
1847636cb21Slm66018 	/*
1857636cb21Slm66018 	 * MAC Ring Resources.
1867636cb21Slm66018 	 */
1877636cb21Slm66018 	kmutex_t		mac_ring_lock;	/* Lock for the table. */
1887636cb21Slm66018 	uint32_t		mac_ring_tbl_sz;
1897636cb21Slm66018 	vsw_mac_ring_t		*mac_ring_tbl;	/* Mac ring table. */
1901ae08745Sheppo 
1915f94e909Ssg70180 	kmutex_t		hw_lock;	/* sync access to HW */
192e1ebb9ecSlm66018 	boolean_t		recfg_reqd;	/* Reconfig of addrs needed */
193e1ebb9ecSlm66018 	int			promisc_cnt;
1941ae08745Sheppo 
1951ae08745Sheppo 	/* Machine Description updates  */
1961ae08745Sheppo 	mdeg_node_spec_t	*inst_spec;
1971ae08745Sheppo 	mdeg_handle_t		mdeg_hdl;
19834683adeSsg70180 	mdeg_handle_t		mdeg_port_hdl;
1991ae08745Sheppo 
2001ae08745Sheppo 	/* if configured as an ethernet interface */
201ba2e4443Sseb 	mac_handle_t		if_mh;		/* MAC handle */
2021ae08745Sheppo 	struct ether_addr	if_addr;	/* interface address */
2031ae08745Sheppo 	krwlock_t		if_lockrw;
2041ae08745Sheppo 	uint8_t			if_state;	/* interface state */
2051ae08745Sheppo 
2065f94e909Ssg70180 	mac_addr_slot_t		addr_slot;	/* Unicast address slot */
2075f94e909Ssg70180 	int			addr_set;	/* Addr set where */
2085f94e909Ssg70180 
2091ae08745Sheppo 	/* multicast addresses when configured as eth interface */
2101ae08745Sheppo 	kmutex_t		mca_lock;	/* multicast lock */
2111ae08745Sheppo 	mcst_addr_t		*mcap;		/* list of multicast addrs */
21206db247cSraghuram 
213f0ca1d9aSsb155480 	uint32_t		pri_num_types;	/* # of priority eth types */
214f0ca1d9aSsb155480 	uint16_t		*pri_types;	/* priority eth types */
215f0ca1d9aSsb155480 	vio_mblk_pool_t		*pri_tx_vmp;	/* tx priority mblk pool */
216c1c61f44Ssb155480 	uint16_t		default_vlan_id; /* default vlan id */
217c1c61f44Ssb155480 	uint16_t		pvid;	/* port vlan id (untagged) */
218c1c61f44Ssb155480 	uint16_t		*vids;	/* vlan ids (tagged) */
219c1c61f44Ssb155480 	uint16_t		nvids;	/* # of vids */
220c1c61f44Ssb155480 	uint32_t		vids_size; /* size alloc'd for vids list */
221678453a8Sspeer 
222678453a8Sspeer 	/* HybridIO related fields */
223678453a8Sspeer 	boolean_t		hio_capable;	/* Phys dev HIO capable */
224678453a8Sspeer 	vsw_hio_t		vhio;		/* HybridIO info */
2251ae08745Sheppo } vsw_t;
2261ae08745Sheppo 
2271ae08745Sheppo /*
22806db247cSraghuram  * The flags that are used by vsw_mac_rx().
2291ae08745Sheppo  */
23006db247cSraghuram typedef enum {
23106db247cSraghuram 	VSW_MACRX_PROMISC = 0x01,
23206db247cSraghuram 	VSW_MACRX_COPYMSG = 0x02,
23306db247cSraghuram 	VSW_MACRX_FREEMSG = 0x04
23406db247cSraghuram } vsw_macrx_flags_t;
2351ae08745Sheppo 
2361ae08745Sheppo 
23706db247cSraghuram #ifdef DEBUG
23806db247cSraghuram 
23906db247cSraghuram extern int vswdbg;
24006db247cSraghuram extern void vswdebug(vsw_t *vswp, const char *fmt, ...);
24106db247cSraghuram 
24206db247cSraghuram #define	D1(...)		\
24306db247cSraghuram if (vswdbg & 0x01)	\
24406db247cSraghuram 	vswdebug(__VA_ARGS__)
24506db247cSraghuram 
24606db247cSraghuram #define	D2(...)		\
24706db247cSraghuram if (vswdbg & 0x02)	\
24806db247cSraghuram 	vswdebug(__VA_ARGS__)
24906db247cSraghuram 
25006db247cSraghuram #define	D3(...)		\
25106db247cSraghuram if (vswdbg & 0x04)	\
25206db247cSraghuram 	vswdebug(__VA_ARGS__)
25306db247cSraghuram 
25406db247cSraghuram #define	DWARN(...)	\
25506db247cSraghuram if (vswdbg & 0x08)	\
25606db247cSraghuram 	vswdebug(__VA_ARGS__)
25706db247cSraghuram 
25806db247cSraghuram #define	DERR(...)	\
25906db247cSraghuram if (vswdbg & 0x10)	\
26006db247cSraghuram 	vswdebug(__VA_ARGS__)
26106db247cSraghuram 
26206db247cSraghuram #else
26306db247cSraghuram 
26406db247cSraghuram #define	DERR(...)	if (0)	do { } while (0)
26506db247cSraghuram #define	DWARN(...)	if (0)	do { } while (0)
26606db247cSraghuram #define	D1(...)		if (0)	do { } while (0)
26706db247cSraghuram #define	D2(...)		if (0)	do { } while (0)
26806db247cSraghuram #define	D3(...)		if (0)	do { } while (0)
26906db247cSraghuram 
27006db247cSraghuram #endif	/* DEBUG */
27106db247cSraghuram 
2721ae08745Sheppo 
2731ae08745Sheppo #ifdef	__cplusplus
2741ae08745Sheppo }
2751ae08745Sheppo #endif
2761ae08745Sheppo 
2771ae08745Sheppo #endif	/* _VSW_H */
278