xref: /onnv-gate/usr/src/uts/sun4v/sys/vsw.h (revision 12011:2377022c7a2d)
11991Sheppo /*
21991Sheppo  * CDDL HEADER START
31991Sheppo  *
41991Sheppo  * The contents of this file are subject to the terms of the
51991Sheppo  * Common Development and Distribution License (the "License").
61991Sheppo  * You may not use this file except in compliance with the License.
71991Sheppo  *
81991Sheppo  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
91991Sheppo  * or http://www.opensolaris.org/os/licensing.
101991Sheppo  * See the License for the specific language governing permissions
111991Sheppo  * and limitations under the License.
121991Sheppo  *
131991Sheppo  * When distributing Covered Code, include this CDDL HEADER in each
141991Sheppo  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
151991Sheppo  * If applicable, add the following below this CDDL HEADER, with the
161991Sheppo  * fields enclosed by brackets "[]" replaced with your own identifying
171991Sheppo  * information: Portions Copyright [yyyy] [name of copyright owner]
181991Sheppo  *
191991Sheppo  * CDDL HEADER END
201991Sheppo  */
211991Sheppo 
221991Sheppo /*
23*12011SSriharsha.Basavapatna@Sun.COM  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
241991Sheppo  * Use is subject to license terms.
251991Sheppo  */
261991Sheppo 
271991Sheppo /*
285373Sraghuram  * This header file contains the data structures which the
291991Sheppo  * virtual switch (vsw) uses to communicate with its clients and
301991Sheppo  * the outside world.
311991Sheppo  */
321991Sheppo 
331991Sheppo #ifndef	_VSW_H
341991Sheppo #define	_VSW_H
351991Sheppo 
361991Sheppo #ifdef	__cplusplus
371991Sheppo extern "C" {
381991Sheppo #endif
391991Sheppo 
401991Sheppo #include <sys/vio_mailbox.h>
411991Sheppo #include <sys/vnet_common.h>
421991Sheppo #include <sys/ethernet.h>
438275SEric Cheng #include <sys/mac_client.h>
442336Snarayan #include <sys/vio_util.h>
455373Sraghuram #include <sys/vgen_stats.h>
465373Sraghuram #include <sys/vsw_ldc.h>
476495Sspeer #include <sys/vsw_hio.h>
486724Sraghuram #include <sys/callb.h>
491991Sheppo 
505373Sraghuram #define	DRV_NAME	"vsw"
511991Sheppo 
521991Sheppo /*
531991Sheppo  * Only support ETHER mtu at moment.
541991Sheppo  */
551991Sheppo #define	VSW_MTU		ETHERMAX
561991Sheppo 
571991Sheppo /* ID of the source of a frame being switched */
581991Sheppo #define	VSW_PHYSDEV		1	/* physical device associated */
591991Sheppo #define	VSW_VNETPORT		2	/* port connected to vnet (over ldc) */
601991Sheppo #define	VSW_LOCALDEV		4	/* vsw configured as an eth interface */
611991Sheppo 
621991Sheppo /*
631991Sheppo  * Number of hash chains in the multicast forwarding database.
641991Sheppo  */
651991Sheppo #define		VSW_NCHAINS	8
661991Sheppo 
67*12011SSriharsha.Basavapatna@Sun.COM /* Number of descriptors -  must be power of 2 */
68*12011SSriharsha.Basavapatna@Sun.COM #define		VSW_NUM_DESCRIPTORS	512
695935Ssb155480 
701991Sheppo /*
711991Sheppo  * State of interface if switch plumbed as network device.
721991Sheppo  */
732311Sseb #define		VSW_IF_REG	0x1	/* interface was registered */
742311Sseb #define		VSW_IF_UP	0x2	/* Interface UP */
752311Sseb #define		VSW_IF_PROMISC	0x4	/* Interface in promiscious mode */
761991Sheppo 
771991Sheppo #define		VSW_U_P(state)	\
781991Sheppo 			(state == (VSW_IF_UP | VSW_IF_PROMISC))
791991Sheppo 
801991Sheppo /*
811991Sheppo  * Switching modes.
821991Sheppo  */
831991Sheppo #define		VSW_LAYER2		0x1	/* Layer 2 - MAC switching */
841991Sheppo #define		VSW_LAYER2_PROMISC	0x2	/* Layer 2 + promisc mode */
851991Sheppo #define		VSW_LAYER3		0x4	/* Layer 3 - IP switching */
861991Sheppo 
871991Sheppo #define		NUM_SMODES	3	/* number of switching modes */
881991Sheppo 
895935Ssb155480 #define	VSW_PRI_ETH_DEFINED(vswp)	((vswp)->pri_num_types != 0)
905935Ssb155480 
918370SSriharsha.Basavapatna@Sun.COM typedef enum {
928370SSriharsha.Basavapatna@Sun.COM 	VSW_SWTHR_STOP = 0x1
938370SSriharsha.Basavapatna@Sun.COM } sw_thr_flags_t;
948370SSriharsha.Basavapatna@Sun.COM 
959217SWentao.Yang@Sun.COM typedef enum {
969217SWentao.Yang@Sun.COM 	PROG_init = 0x00,
979217SWentao.Yang@Sun.COM 	PROG_locks = 0x01,
989217SWentao.Yang@Sun.COM 	PROG_readmd = 0x02,
999217SWentao.Yang@Sun.COM 	PROG_fdb = 0x04,
1009217SWentao.Yang@Sun.COM 	PROG_mfdb = 0x08,
1019217SWentao.Yang@Sun.COM 	PROG_taskq = 0x10,
10210041SWentao.Yang@Sun.COM 	PROG_rxp_taskq = 0x20,
10310041SWentao.Yang@Sun.COM 	PROG_swmode = 0x40,
10410041SWentao.Yang@Sun.COM 	PROG_macreg = 0x80,
10510041SWentao.Yang@Sun.COM 	PROG_mdreg = 0x100
1069217SWentao.Yang@Sun.COM } vsw_attach_progress_t;
1079217SWentao.Yang@Sun.COM 
1081991Sheppo /*
1098275SEric Cheng  * vlan-id information.
1108275SEric Cheng  */
1118275SEric Cheng typedef struct vsw_vlanid {
1128275SEric Cheng 	uint16_t		vl_vid;		/* vlan-id */
1138275SEric Cheng 	mac_unicast_handle_t	vl_muh;		/* mac unicast handle */
1148275SEric Cheng 	boolean_t		vl_set;		/* set? */
1158275SEric Cheng } vsw_vlanid_t;
1168275SEric Cheng 
1178275SEric Cheng /*
1181991Sheppo  * vsw instance state information.
1191991Sheppo  */
1201991Sheppo typedef struct	vsw {
1211991Sheppo 	int			instance;	/* instance # */
1221991Sheppo 	dev_info_t		*dip;		/* associated dev_info */
1235171Ssb155480 	uint64_t		regprop;	/* "reg" property */
1249217SWentao.Yang@Sun.COM 	vsw_attach_progress_t	attach_progress; /* attach progress flags */
1251991Sheppo 	struct vsw		*next;		/* next in list */
1261991Sheppo 	char			physname[LIFNAMSIZ];	/* phys-dev */
1278275SEric Cheng 	uint8_t			smode;		/* switching mode */
1288370SSriharsha.Basavapatna@Sun.COM 	kmutex_t		sw_thr_lock;	/* setup switching thr lock */
1298370SSriharsha.Basavapatna@Sun.COM 	kcondvar_t		sw_thr_cv;	/* cv for setup switching thr */
1308370SSriharsha.Basavapatna@Sun.COM 	kthread_t		*sw_thread;	/* setup switching thread */
1318370SSriharsha.Basavapatna@Sun.COM 	sw_thr_flags_t		sw_thr_flags; 	/* setup switching thr flags */
1325171Ssb155480 	uint32_t		switching_setup_done; /* setup switching done */
1335171Ssb155480 	int			mac_open_retries; /* mac_open() retry count */
1341991Sheppo 	vsw_port_list_t		plist;		/* associated ports */
1351991Sheppo 	ddi_taskq_t		*taskq_p;	/* VIO ctrl msg taskq */
1366419Ssb155480 	mod_hash_t		*fdb_hashp;	/* forwarding database */
1376419Ssb155480 	uint32_t		fdb_nchains;	/* # of hash chains in fdb */
1386419Ssb155480 	mod_hash_t		*vlan_hashp;	/* vlan hash table */
1396419Ssb155480 	uint32_t		vlan_nchains;	/* # of vlan hash chains */
1407529SSriharsha.Basavapatna@Sun.COM 	uint32_t		mtu;		/* mtu of the device */
1416419Ssb155480 	uint32_t		max_frame_size;	/* max frame size supported */
1427529SSriharsha.Basavapatna@Sun.COM 	uint32_t		mtu_physdev_orig; /* orig mtu of the physdev */
1431991Sheppo 
1441991Sheppo 	mod_hash_t		*mfdb;		/* multicast FDB */
1451991Sheppo 	krwlock_t		mfdbrw;		/* rwlock for mFDB */
1461991Sheppo 
14710041SWentao.Yang@Sun.COM 	ddi_taskq_t		*rxp_taskq;	/* VIO rx pool taskq */
1483166Ssg70180 	void			(*vsw_switch_frame)
1493166Ssg70180 					(struct vsw *, mblk_t *, int,
1503166Ssg70180 					vsw_port_t *, mac_resource_handle_t);
1512336Snarayan 
1521991Sheppo 	/* mac layer */
1538275SEric Cheng 	kmutex_t		mac_lock;	/* protect mh */
1541991Sheppo 	mac_handle_t		mh;
1558275SEric Cheng 	krwlock_t		maccl_rwlock;	/* protect fields below */
1568275SEric Cheng 	mac_client_handle_t	mch;		/* mac client handle */
1578275SEric Cheng 	mac_unicast_handle_t	muh;		/* mac unicast handle */
1589336SSriharsha.Basavapatna@Sun.COM 	mac_notify_handle_t	mnh;		/* mac notify handle */
1592748Slm66018 
1608275SEric Cheng 	boolean_t		recfg_reqd;	/* Reconfig of addrs needed */
1611991Sheppo 
1628275SEric Cheng 	/* mac layer switching flag */
1638275SEric Cheng 	boolean_t		mac_cl_switching;
1641991Sheppo 
1651991Sheppo 	/* Machine Description updates  */
1661991Sheppo 	mdeg_node_spec_t	*inst_spec;
1671991Sheppo 	mdeg_handle_t		mdeg_hdl;
1683166Ssg70180 	mdeg_handle_t		mdeg_port_hdl;
1691991Sheppo 
1701991Sheppo 	/* if configured as an ethernet interface */
1712311Sseb 	mac_handle_t		if_mh;		/* MAC handle */
1721991Sheppo 	struct ether_addr	if_addr;	/* interface address */
1731991Sheppo 	krwlock_t		if_lockrw;
1741991Sheppo 	uint8_t			if_state;	/* interface state */
1751991Sheppo 
1768275SEric Cheng 	boolean_t		addr_set;	/* is addr set to HW */
1773784Ssg70180 
1781991Sheppo 	/* multicast addresses when configured as eth interface */
1791991Sheppo 	kmutex_t		mca_lock;	/* multicast lock */
1801991Sheppo 	mcst_addr_t		*mcap;		/* list of multicast addrs */
1815373Sraghuram 
1825935Ssb155480 	uint32_t		pri_num_types;	/* # of priority eth types */
1835935Ssb155480 	uint16_t		*pri_types;	/* priority eth types */
1845935Ssb155480 	vio_mblk_pool_t		*pri_tx_vmp;	/* tx priority mblk pool */
1856419Ssb155480 	uint16_t		default_vlan_id; /* default vlan id */
1866419Ssb155480 	uint16_t		pvid;	/* port vlan id (untagged) */
1878275SEric Cheng 	vsw_vlanid_t		*vids;	/* vlan ids (tagged) */
1886419Ssb155480 	uint16_t		nvids;	/* # of vids */
1896419Ssb155480 	uint32_t		vids_size; /* size alloc'd for vids list */
1906495Sspeer 
1916495Sspeer 	/* HybridIO related fields */
1926495Sspeer 	boolean_t		hio_capable;	/* Phys dev HIO capable */
1936495Sspeer 	vsw_hio_t		vhio;		/* HybridIO info */
1946724Sraghuram 	callb_id_t		hio_reboot_cb_id; /* Reboot callb ID */
1956724Sraghuram 	callb_id_t		hio_panic_cb_id; /* Panic callb ID */
1969336SSriharsha.Basavapatna@Sun.COM 
1979336SSriharsha.Basavapatna@Sun.COM 	/* Link-state related fields */
1989336SSriharsha.Basavapatna@Sun.COM 	boolean_t		phys_no_link_update; /* no link-update supp */
1999336SSriharsha.Basavapatna@Sun.COM 	boolean_t		pls_update;	/* phys link state update ? */
2009336SSriharsha.Basavapatna@Sun.COM 	link_state_t		phys_link_state;    /* physical link state */
20110795SWentao.Yang@Sun.COM 
20210795SWentao.Yang@Sun.COM 	/* bandwidth related fields */
20310795SWentao.Yang@Sun.COM 	uint64_t		bandwidth;	/* bandwidth limit */
2041991Sheppo } vsw_t;
2051991Sheppo 
2061991Sheppo /*
2075373Sraghuram  * The flags that are used by vsw_mac_rx().
2081991Sheppo  */
2095373Sraghuram typedef enum {
2105373Sraghuram 	VSW_MACRX_PROMISC = 0x01,
2115373Sraghuram 	VSW_MACRX_COPYMSG = 0x02,
2125373Sraghuram 	VSW_MACRX_FREEMSG = 0x04
2135373Sraghuram } vsw_macrx_flags_t;
2145373Sraghuram 
2155373Sraghuram 
2165373Sraghuram #ifdef DEBUG
2175373Sraghuram 
2185373Sraghuram extern int vswdbg;
2195373Sraghuram extern void vswdebug(vsw_t *vswp, const char *fmt, ...);
2205373Sraghuram 
2215373Sraghuram #define	D1(...)		\
2225373Sraghuram if (vswdbg & 0x01)	\
2235373Sraghuram 	vswdebug(__VA_ARGS__)
2245373Sraghuram 
2255373Sraghuram #define	D2(...)		\
2265373Sraghuram if (vswdbg & 0x02)	\
2275373Sraghuram 	vswdebug(__VA_ARGS__)
2281991Sheppo 
2295373Sraghuram #define	D3(...)		\
2305373Sraghuram if (vswdbg & 0x04)	\
2315373Sraghuram 	vswdebug(__VA_ARGS__)
2325373Sraghuram 
2335373Sraghuram #define	DWARN(...)	\
2345373Sraghuram if (vswdbg & 0x08)	\
2355373Sraghuram 	vswdebug(__VA_ARGS__)
2361991Sheppo 
2375373Sraghuram #define	DERR(...)	\
2385373Sraghuram if (vswdbg & 0x10)	\
2395373Sraghuram 	vswdebug(__VA_ARGS__)
2405373Sraghuram 
2415373Sraghuram #else
2425373Sraghuram 
2435373Sraghuram #define	DERR(...)	if (0)	do { } while (0)
2445373Sraghuram #define	DWARN(...)	if (0)	do { } while (0)
2455373Sraghuram #define	D1(...)		if (0)	do { } while (0)
2465373Sraghuram #define	D2(...)		if (0)	do { } while (0)
2475373Sraghuram #define	D3(...)		if (0)	do { } while (0)
2485373Sraghuram 
2495373Sraghuram #endif	/* DEBUG */
2505373Sraghuram 
2511991Sheppo 
2521991Sheppo #ifdef	__cplusplus
2531991Sheppo }
2541991Sheppo #endif
2551991Sheppo 
2561991Sheppo #endif	/* _VSW_H */
257