xref: /titanic_53/usr/src/uts/sun4v/sys/vsw.h (revision 6f09f0fef8e4582cfa771d87fe2a1f777bfb5cf0)
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 /*
23*6f09f0feSWENTAO YANG  * Copyright 2009 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 #ifdef	__cplusplus
371ae08745Sheppo extern "C" {
381ae08745Sheppo #endif
391ae08745Sheppo 
401ae08745Sheppo #include <sys/vio_mailbox.h>
411ae08745Sheppo #include <sys/vnet_common.h>
421ae08745Sheppo #include <sys/ethernet.h>
43da14cebeSEric Cheng #include <sys/mac_client.h>
44d10e4ef2Snarayan #include <sys/vio_util.h>
4506db247cSraghuram #include <sys/vgen_stats.h>
4606db247cSraghuram #include <sys/vsw_ldc.h>
47678453a8Sspeer #include <sys/vsw_hio.h>
48cdfc78adSraghuram #include <sys/callb.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 /*
631ae08745Sheppo  * Number of hash chains in the multicast forwarding database.
641ae08745Sheppo  */
651ae08745Sheppo #define		VSW_NCHAINS	8
661ae08745Sheppo 
67f0ca1d9aSsb155480 /* Number of transmit descriptors -  must be power of 2 */
68f0ca1d9aSsb155480 #define		VSW_RING_NUM_EL	512
69f0ca1d9aSsb155480 
701ae08745Sheppo /*
711ae08745Sheppo  * State of interface if switch plumbed as network device.
721ae08745Sheppo  */
73ba2e4443Sseb #define		VSW_IF_REG	0x1	/* interface was registered */
74ba2e4443Sseb #define		VSW_IF_UP	0x2	/* Interface UP */
75ba2e4443Sseb #define		VSW_IF_PROMISC	0x4	/* Interface in promiscious mode */
761ae08745Sheppo 
771ae08745Sheppo #define		VSW_U_P(state)	\
781ae08745Sheppo 			(state == (VSW_IF_UP | VSW_IF_PROMISC))
791ae08745Sheppo 
801ae08745Sheppo /*
811ae08745Sheppo  * Switching modes.
821ae08745Sheppo  */
831ae08745Sheppo #define		VSW_LAYER2		0x1	/* Layer 2 - MAC switching */
841ae08745Sheppo #define		VSW_LAYER2_PROMISC	0x2	/* Layer 2 + promisc mode */
851ae08745Sheppo #define		VSW_LAYER3		0x4	/* Layer 3 - IP switching */
861ae08745Sheppo 
871ae08745Sheppo #define		NUM_SMODES	3	/* number of switching modes */
881ae08745Sheppo 
89f0ca1d9aSsb155480 #define	VSW_PRI_ETH_DEFINED(vswp)	((vswp)->pri_num_types != 0)
90f0ca1d9aSsb155480 
91808f26a8SSriharsha Basavapatna typedef enum {
92808f26a8SSriharsha Basavapatna 	VSW_SWTHR_STOP = 0x1
93808f26a8SSriharsha Basavapatna } sw_thr_flags_t;
94808f26a8SSriharsha Basavapatna 
95*6f09f0feSWENTAO YANG typedef enum {
96*6f09f0feSWENTAO YANG 	PROG_init = 0x00,
97*6f09f0feSWENTAO YANG 	PROG_locks = 0x01,
98*6f09f0feSWENTAO YANG 	PROG_readmd = 0x02,
99*6f09f0feSWENTAO YANG 	PROG_fdb = 0x04,
100*6f09f0feSWENTAO YANG 	PROG_mfdb = 0x08,
101*6f09f0feSWENTAO YANG 	PROG_taskq = 0x10,
102*6f09f0feSWENTAO YANG 	PROG_swmode = 0x20,
103*6f09f0feSWENTAO YANG 	PROG_macreg = 0x40,
104*6f09f0feSWENTAO YANG 	PROG_mdreg = 0x80
105*6f09f0feSWENTAO YANG } vsw_attach_progress_t;
106*6f09f0feSWENTAO YANG 
1071ae08745Sheppo /*
108da14cebeSEric Cheng  * vlan-id information.
109da14cebeSEric Cheng  */
110da14cebeSEric Cheng typedef struct vsw_vlanid {
111da14cebeSEric Cheng 	uint16_t		vl_vid;		/* vlan-id */
112da14cebeSEric Cheng 	mac_unicast_handle_t	vl_muh;		/* mac unicast handle */
113da14cebeSEric Cheng 	boolean_t		vl_set;		/* set? */
114da14cebeSEric Cheng } vsw_vlanid_t;
115da14cebeSEric Cheng 
116da14cebeSEric Cheng /*
1171ae08745Sheppo  * vsw instance state information.
1181ae08745Sheppo  */
1191ae08745Sheppo typedef struct	vsw {
1201ae08745Sheppo 	int			instance;	/* instance # */
1211ae08745Sheppo 	dev_info_t		*dip;		/* associated dev_info */
12219b65a69Ssb155480 	uint64_t		regprop;	/* "reg" property */
123*6f09f0feSWENTAO YANG 	vsw_attach_progress_t	attach_progress; /* attach progress flags */
1241ae08745Sheppo 	struct vsw		*next;		/* next in list */
1251ae08745Sheppo 	char			physname[LIFNAMSIZ];	/* phys-dev */
126da14cebeSEric Cheng 	uint8_t			smode;		/* switching mode */
127808f26a8SSriharsha Basavapatna 	kmutex_t		sw_thr_lock;	/* setup switching thr lock */
128808f26a8SSriharsha Basavapatna 	kcondvar_t		sw_thr_cv;	/* cv for setup switching thr */
129808f26a8SSriharsha Basavapatna 	kthread_t		*sw_thread;	/* setup switching thread */
130808f26a8SSriharsha Basavapatna 	sw_thr_flags_t		sw_thr_flags; 	/* setup switching thr flags */
13119b65a69Ssb155480 	uint32_t		switching_setup_done; /* setup switching done */
13219b65a69Ssb155480 	int			mac_open_retries; /* mac_open() retry count */
1331ae08745Sheppo 	vsw_port_list_t		plist;		/* associated ports */
1341ae08745Sheppo 	ddi_taskq_t		*taskq_p;	/* VIO ctrl msg taskq */
135c1c61f44Ssb155480 	mod_hash_t		*fdb_hashp;	/* forwarding database */
136c1c61f44Ssb155480 	uint32_t		fdb_nchains;	/* # of hash chains in fdb */
137c1c61f44Ssb155480 	mod_hash_t		*vlan_hashp;	/* vlan hash table */
138c1c61f44Ssb155480 	uint32_t		vlan_nchains;	/* # of vlan hash chains */
1397b1f684aSSriharsha Basavapatna 	uint32_t		mtu;		/* mtu of the device */
140c1c61f44Ssb155480 	uint32_t		max_frame_size;	/* max frame size supported */
1417b1f684aSSriharsha Basavapatna 	uint32_t		mtu_physdev_orig; /* orig mtu of the physdev */
1421ae08745Sheppo 
1431ae08745Sheppo 	mod_hash_t		*mfdb;		/* multicast FDB */
1441ae08745Sheppo 	krwlock_t		mfdbrw;		/* rwlock for mFDB */
1451ae08745Sheppo 
146d10e4ef2Snarayan 	vio_mblk_pool_t		*rxh;		/* Receive pool handle */
14734683adeSsg70180 	void			(*vsw_switch_frame)
14834683adeSsg70180 					(struct vsw *, mblk_t *, int,
14934683adeSsg70180 					vsw_port_t *, mac_resource_handle_t);
150d10e4ef2Snarayan 
1511ae08745Sheppo 	/* mac layer */
152da14cebeSEric Cheng 	kmutex_t		mac_lock;	/* protect mh */
1531ae08745Sheppo 	mac_handle_t		mh;
154da14cebeSEric Cheng 	krwlock_t		maccl_rwlock;	/* protect fields below */
155da14cebeSEric Cheng 	mac_client_handle_t	mch;		/* mac client handle */
156da14cebeSEric Cheng 	mac_unicast_handle_t	muh;		/* mac unicast handle */
1577636cb21Slm66018 
158e1ebb9ecSlm66018 	boolean_t		recfg_reqd;	/* Reconfig of addrs needed */
159da14cebeSEric Cheng 
160da14cebeSEric Cheng 	/* mac layer switching flag */
161da14cebeSEric Cheng 	boolean_t		mac_cl_switching;
1621ae08745Sheppo 
1631ae08745Sheppo 	/* Machine Description updates  */
1641ae08745Sheppo 	mdeg_node_spec_t	*inst_spec;
1651ae08745Sheppo 	mdeg_handle_t		mdeg_hdl;
16634683adeSsg70180 	mdeg_handle_t		mdeg_port_hdl;
1671ae08745Sheppo 
1681ae08745Sheppo 	/* if configured as an ethernet interface */
169ba2e4443Sseb 	mac_handle_t		if_mh;		/* MAC handle */
1701ae08745Sheppo 	struct ether_addr	if_addr;	/* interface address */
1711ae08745Sheppo 	krwlock_t		if_lockrw;
1721ae08745Sheppo 	uint8_t			if_state;	/* interface state */
1731ae08745Sheppo 
174da14cebeSEric Cheng 	boolean_t		addr_set;	/* is addr set to HW */
1755f94e909Ssg70180 
1761ae08745Sheppo 	/* multicast addresses when configured as eth interface */
1771ae08745Sheppo 	kmutex_t		mca_lock;	/* multicast lock */
1781ae08745Sheppo 	mcst_addr_t		*mcap;		/* list of multicast addrs */
17906db247cSraghuram 
180f0ca1d9aSsb155480 	uint32_t		pri_num_types;	/* # of priority eth types */
181f0ca1d9aSsb155480 	uint16_t		*pri_types;	/* priority eth types */
182f0ca1d9aSsb155480 	vio_mblk_pool_t		*pri_tx_vmp;	/* tx priority mblk pool */
183c1c61f44Ssb155480 	uint16_t		default_vlan_id; /* default vlan id */
184c1c61f44Ssb155480 	uint16_t		pvid;	/* port vlan id (untagged) */
185da14cebeSEric Cheng 	vsw_vlanid_t		*vids;	/* vlan ids (tagged) */
186c1c61f44Ssb155480 	uint16_t		nvids;	/* # of vids */
187c1c61f44Ssb155480 	uint32_t		vids_size; /* size alloc'd for vids list */
188678453a8Sspeer 
189678453a8Sspeer 	/* HybridIO related fields */
190678453a8Sspeer 	boolean_t		hio_capable;	/* Phys dev HIO capable */
191678453a8Sspeer 	vsw_hio_t		vhio;		/* HybridIO info */
192cdfc78adSraghuram 	callb_id_t		hio_reboot_cb_id; /* Reboot callb ID */
193cdfc78adSraghuram 	callb_id_t		hio_panic_cb_id; /* Panic callb ID */
1941ae08745Sheppo } vsw_t;
1951ae08745Sheppo 
1961ae08745Sheppo /*
19706db247cSraghuram  * The flags that are used by vsw_mac_rx().
1981ae08745Sheppo  */
19906db247cSraghuram typedef enum {
20006db247cSraghuram 	VSW_MACRX_PROMISC = 0x01,
20106db247cSraghuram 	VSW_MACRX_COPYMSG = 0x02,
20206db247cSraghuram 	VSW_MACRX_FREEMSG = 0x04
20306db247cSraghuram } vsw_macrx_flags_t;
2041ae08745Sheppo 
2051ae08745Sheppo 
20606db247cSraghuram #ifdef DEBUG
20706db247cSraghuram 
20806db247cSraghuram extern int vswdbg;
20906db247cSraghuram extern void vswdebug(vsw_t *vswp, const char *fmt, ...);
21006db247cSraghuram 
21106db247cSraghuram #define	D1(...)		\
21206db247cSraghuram if (vswdbg & 0x01)	\
21306db247cSraghuram 	vswdebug(__VA_ARGS__)
21406db247cSraghuram 
21506db247cSraghuram #define	D2(...)		\
21606db247cSraghuram if (vswdbg & 0x02)	\
21706db247cSraghuram 	vswdebug(__VA_ARGS__)
21806db247cSraghuram 
21906db247cSraghuram #define	D3(...)		\
22006db247cSraghuram if (vswdbg & 0x04)	\
22106db247cSraghuram 	vswdebug(__VA_ARGS__)
22206db247cSraghuram 
22306db247cSraghuram #define	DWARN(...)	\
22406db247cSraghuram if (vswdbg & 0x08)	\
22506db247cSraghuram 	vswdebug(__VA_ARGS__)
22606db247cSraghuram 
22706db247cSraghuram #define	DERR(...)	\
22806db247cSraghuram if (vswdbg & 0x10)	\
22906db247cSraghuram 	vswdebug(__VA_ARGS__)
23006db247cSraghuram 
23106db247cSraghuram #else
23206db247cSraghuram 
23306db247cSraghuram #define	DERR(...)	if (0)	do { } while (0)
23406db247cSraghuram #define	DWARN(...)	if (0)	do { } while (0)
23506db247cSraghuram #define	D1(...)		if (0)	do { } while (0)
23606db247cSraghuram #define	D2(...)		if (0)	do { } while (0)
23706db247cSraghuram #define	D3(...)		if (0)	do { } while (0)
23806db247cSraghuram 
23906db247cSraghuram #endif	/* DEBUG */
24006db247cSraghuram 
2411ae08745Sheppo 
2421ae08745Sheppo #ifdef	__cplusplus
2431ae08745Sheppo }
2441ae08745Sheppo #endif
2451ae08745Sheppo 
2461ae08745Sheppo #endif	/* _VSW_H */
247