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> 481ae08745Sheppo 4906db247cSraghuram #define DRV_NAME "vsw" 501ae08745Sheppo 511ae08745Sheppo /* 521ae08745Sheppo * Only support ETHER mtu at moment. 531ae08745Sheppo */ 541ae08745Sheppo #define VSW_MTU ETHERMAX 551ae08745Sheppo 561ae08745Sheppo /* ID of the source of a frame being switched */ 571ae08745Sheppo #define VSW_PHYSDEV 1 /* physical device associated */ 581ae08745Sheppo #define VSW_VNETPORT 2 /* port connected to vnet (over ldc) */ 591ae08745Sheppo #define VSW_LOCALDEV 4 /* vsw configured as an eth interface */ 601ae08745Sheppo 611ae08745Sheppo /* 627636cb21Slm66018 * Vsw queue -- largely modeled after squeue 6334683adeSsg70180 * 6434683adeSsg70180 * VSW_QUEUE_RUNNING, vqueue thread for queue is running. 6534683adeSsg70180 * VSW_QUEUE_DRAINED, vqueue thread has drained current work and is exiting. 6634683adeSsg70180 * VSW_QUEUE_STOP, request for the vqueue thread to stop. 6734683adeSsg70180 * VSW_QUEUE_STOPPED, vqueue thread is not running. 687636cb21Slm66018 */ 697636cb21Slm66018 #define VSW_QUEUE_RUNNING 0x01 7034683adeSsg70180 #define VSW_QUEUE_DRAINED 0x02 7134683adeSsg70180 #define VSW_QUEUE_STOP 0x04 7234683adeSsg70180 #define VSW_QUEUE_STOPPED 0x08 737636cb21Slm66018 747636cb21Slm66018 typedef struct vsw_queue_s { 757636cb21Slm66018 kmutex_t vq_lock; /* Lock, before using any member. */ 767636cb21Slm66018 kcondvar_t vq_cv; /* Async threads block on. */ 777636cb21Slm66018 uint32_t vq_state; /* State flags. */ 787636cb21Slm66018 797636cb21Slm66018 mblk_t *vq_first; /* First mblk chain or NULL. */ 807636cb21Slm66018 mblk_t *vq_last; /* Last mblk chain. */ 817636cb21Slm66018 827636cb21Slm66018 processorid_t vq_bind; /* Process to bind to */ 837636cb21Slm66018 kthread_t *vq_worker; /* Queue's thread */ 847636cb21Slm66018 } vsw_queue_t; 857636cb21Slm66018 867636cb21Slm66018 /* 877636cb21Slm66018 * VSW MAC Ring Resources. 887636cb21Slm66018 * MAC Ring resource is composed of this state structure and 897636cb21Slm66018 * a kernel thread to perform the processing of the ring. 907636cb21Slm66018 */ 917636cb21Slm66018 typedef struct vsw_mac_ring_s { 927636cb21Slm66018 uint32_t ring_state; 937636cb21Slm66018 947636cb21Slm66018 mac_blank_t ring_blank; 957636cb21Slm66018 void *ring_arg; 967636cb21Slm66018 977636cb21Slm66018 vsw_queue_t *ring_vqp; 987636cb21Slm66018 struct vsw *ring_vswp; 997636cb21Slm66018 } vsw_mac_ring_t; 1007636cb21Slm66018 1017636cb21Slm66018 /* 1027636cb21Slm66018 * Maximum Ring Resources. 1037636cb21Slm66018 */ 1047636cb21Slm66018 #define VSW_MAC_RX_RINGS 0x40 1057636cb21Slm66018 1067636cb21Slm66018 /* 1077636cb21Slm66018 * States for entry in ring table. 1087636cb21Slm66018 */ 1097636cb21Slm66018 #define VSW_MAC_RING_FREE 1 1107636cb21Slm66018 #define VSW_MAC_RING_INUSE 2 1117636cb21Slm66018 1127636cb21Slm66018 /* 1131ae08745Sheppo * Number of hash chains in the multicast forwarding database. 1141ae08745Sheppo */ 1151ae08745Sheppo #define VSW_NCHAINS 8 1161ae08745Sheppo 117f0ca1d9aSsb155480 /* Number of transmit descriptors - must be power of 2 */ 118f0ca1d9aSsb155480 #define VSW_RING_NUM_EL 512 119f0ca1d9aSsb155480 1201ae08745Sheppo /* 1211ae08745Sheppo * State of interface if switch plumbed as network device. 1221ae08745Sheppo */ 123ba2e4443Sseb #define VSW_IF_REG 0x1 /* interface was registered */ 124ba2e4443Sseb #define VSW_IF_UP 0x2 /* Interface UP */ 125ba2e4443Sseb #define VSW_IF_PROMISC 0x4 /* Interface in promiscious mode */ 1261ae08745Sheppo 1271ae08745Sheppo #define VSW_U_P(state) \ 1281ae08745Sheppo (state == (VSW_IF_UP | VSW_IF_PROMISC)) 1291ae08745Sheppo 1301ae08745Sheppo /* 1311ae08745Sheppo * Switching modes. 1321ae08745Sheppo */ 1331ae08745Sheppo #define VSW_LAYER2 0x1 /* Layer 2 - MAC switching */ 1341ae08745Sheppo #define VSW_LAYER2_PROMISC 0x2 /* Layer 2 + promisc mode */ 1351ae08745Sheppo #define VSW_LAYER3 0x4 /* Layer 3 - IP switching */ 1361ae08745Sheppo 1371ae08745Sheppo #define NUM_SMODES 3 /* number of switching modes */ 1381ae08745Sheppo 139f0ca1d9aSsb155480 #define VSW_PRI_ETH_DEFINED(vswp) ((vswp)->pri_num_types != 0) 140f0ca1d9aSsb155480 1411ae08745Sheppo /* 1421ae08745Sheppo * vsw instance state information. 1431ae08745Sheppo */ 1441ae08745Sheppo typedef struct vsw { 1451ae08745Sheppo int instance; /* instance # */ 1461ae08745Sheppo dev_info_t *dip; /* associated dev_info */ 14719b65a69Ssb155480 uint64_t regprop; /* "reg" property */ 1481ae08745Sheppo struct vsw *next; /* next in list */ 1491ae08745Sheppo char physname[LIFNAMSIZ]; /* phys-dev */ 1501ae08745Sheppo uint8_t smode[NUM_SMODES]; /* switching mode */ 1511ae08745Sheppo int smode_idx; /* curr pos in smode array */ 152e1ebb9ecSlm66018 int smode_num; /* # of modes specified */ 15319b65a69Ssb155480 kmutex_t swtmout_lock; /* setup switching tmout lock */ 15419b65a69Ssb155480 boolean_t swtmout_enabled; /* setup switching tmout on */ 15519b65a69Ssb155480 timeout_id_t swtmout_id; /* setup switching tmout id */ 15619b65a69Ssb155480 uint32_t switching_setup_done; /* setup switching done */ 15719b65a69Ssb155480 int mac_open_retries; /* mac_open() retry count */ 1581ae08745Sheppo vsw_port_list_t plist; /* associated ports */ 1591ae08745Sheppo ddi_taskq_t *taskq_p; /* VIO ctrl msg taskq */ 160*c1c61f44Ssb155480 mod_hash_t *fdb_hashp; /* forwarding database */ 161*c1c61f44Ssb155480 uint32_t fdb_nchains; /* # of hash chains in fdb */ 162*c1c61f44Ssb155480 mod_hash_t *vlan_hashp; /* vlan hash table */ 163*c1c61f44Ssb155480 uint32_t vlan_nchains; /* # of vlan hash chains */ 164*c1c61f44Ssb155480 uint32_t max_frame_size; /* max frame size supported */ 1651ae08745Sheppo 1661ae08745Sheppo mod_hash_t *mfdb; /* multicast FDB */ 1671ae08745Sheppo krwlock_t mfdbrw; /* rwlock for mFDB */ 1681ae08745Sheppo 169d10e4ef2Snarayan vio_mblk_pool_t *rxh; /* Receive pool handle */ 17034683adeSsg70180 void (*vsw_switch_frame) 17134683adeSsg70180 (struct vsw *, mblk_t *, int, 17234683adeSsg70180 vsw_port_t *, mac_resource_handle_t); 173d10e4ef2Snarayan 1741ae08745Sheppo /* mac layer */ 17534683adeSsg70180 kmutex_t mac_lock; /* protect fields below */ 1761ae08745Sheppo mac_handle_t mh; 1771ae08745Sheppo mac_rx_handle_t mrh; 178e1ebb9ecSlm66018 multiaddress_capab_t maddr; /* Multiple uni addr capable */ 1791ae08745Sheppo const mac_txinfo_t *txinfo; /* MAC tx routine */ 1807636cb21Slm66018 boolean_t mstarted; /* Mac Started? */ 1817636cb21Slm66018 boolean_t mresources; /* Mac Resources cb? */ 1827636cb21Slm66018 1837636cb21Slm66018 /* 1847636cb21Slm66018 * MAC Ring Resources. 1857636cb21Slm66018 */ 1867636cb21Slm66018 kmutex_t mac_ring_lock; /* Lock for the table. */ 1877636cb21Slm66018 uint32_t mac_ring_tbl_sz; 1887636cb21Slm66018 vsw_mac_ring_t *mac_ring_tbl; /* Mac ring table. */ 1891ae08745Sheppo 1905f94e909Ssg70180 kmutex_t hw_lock; /* sync access to HW */ 191e1ebb9ecSlm66018 boolean_t recfg_reqd; /* Reconfig of addrs needed */ 192e1ebb9ecSlm66018 int promisc_cnt; 1931ae08745Sheppo 1941ae08745Sheppo /* Machine Description updates */ 1951ae08745Sheppo mdeg_node_spec_t *inst_spec; 1961ae08745Sheppo mdeg_handle_t mdeg_hdl; 19734683adeSsg70180 mdeg_handle_t mdeg_port_hdl; 1981ae08745Sheppo 1991ae08745Sheppo /* if configured as an ethernet interface */ 200ba2e4443Sseb mac_handle_t if_mh; /* MAC handle */ 2011ae08745Sheppo struct ether_addr if_addr; /* interface address */ 2021ae08745Sheppo krwlock_t if_lockrw; 2031ae08745Sheppo uint8_t if_state; /* interface state */ 2041ae08745Sheppo 2055f94e909Ssg70180 mac_addr_slot_t addr_slot; /* Unicast address slot */ 2065f94e909Ssg70180 int addr_set; /* Addr set where */ 2075f94e909Ssg70180 2081ae08745Sheppo /* multicast addresses when configured as eth interface */ 2091ae08745Sheppo kmutex_t mca_lock; /* multicast lock */ 2101ae08745Sheppo mcst_addr_t *mcap; /* list of multicast addrs */ 21106db247cSraghuram 212f0ca1d9aSsb155480 uint32_t pri_num_types; /* # of priority eth types */ 213f0ca1d9aSsb155480 uint16_t *pri_types; /* priority eth types */ 214f0ca1d9aSsb155480 vio_mblk_pool_t *pri_tx_vmp; /* tx priority mblk pool */ 215*c1c61f44Ssb155480 uint16_t default_vlan_id; /* default vlan id */ 216*c1c61f44Ssb155480 uint16_t pvid; /* port vlan id (untagged) */ 217*c1c61f44Ssb155480 uint16_t *vids; /* vlan ids (tagged) */ 218*c1c61f44Ssb155480 uint16_t nvids; /* # of vids */ 219*c1c61f44Ssb155480 uint32_t vids_size; /* size alloc'd for vids list */ 2201ae08745Sheppo } vsw_t; 2211ae08745Sheppo 2221ae08745Sheppo /* 22306db247cSraghuram * The flags that are used by vsw_mac_rx(). 2241ae08745Sheppo */ 22506db247cSraghuram typedef enum { 22606db247cSraghuram VSW_MACRX_PROMISC = 0x01, 22706db247cSraghuram VSW_MACRX_COPYMSG = 0x02, 22806db247cSraghuram VSW_MACRX_FREEMSG = 0x04 22906db247cSraghuram } vsw_macrx_flags_t; 2301ae08745Sheppo 2311ae08745Sheppo 23206db247cSraghuram #ifdef DEBUG 23306db247cSraghuram 23406db247cSraghuram extern int vswdbg; 23506db247cSraghuram extern void vswdebug(vsw_t *vswp, const char *fmt, ...); 23606db247cSraghuram 23706db247cSraghuram #define D1(...) \ 23806db247cSraghuram if (vswdbg & 0x01) \ 23906db247cSraghuram vswdebug(__VA_ARGS__) 24006db247cSraghuram 24106db247cSraghuram #define D2(...) \ 24206db247cSraghuram if (vswdbg & 0x02) \ 24306db247cSraghuram vswdebug(__VA_ARGS__) 24406db247cSraghuram 24506db247cSraghuram #define D3(...) \ 24606db247cSraghuram if (vswdbg & 0x04) \ 24706db247cSraghuram vswdebug(__VA_ARGS__) 24806db247cSraghuram 24906db247cSraghuram #define DWARN(...) \ 25006db247cSraghuram if (vswdbg & 0x08) \ 25106db247cSraghuram vswdebug(__VA_ARGS__) 25206db247cSraghuram 25306db247cSraghuram #define DERR(...) \ 25406db247cSraghuram if (vswdbg & 0x10) \ 25506db247cSraghuram vswdebug(__VA_ARGS__) 25606db247cSraghuram 25706db247cSraghuram #else 25806db247cSraghuram 25906db247cSraghuram #define DERR(...) if (0) do { } while (0) 26006db247cSraghuram #define DWARN(...) if (0) do { } while (0) 26106db247cSraghuram #define D1(...) if (0) do { } while (0) 26206db247cSraghuram #define D2(...) if (0) do { } while (0) 26306db247cSraghuram #define D3(...) if (0) do { } while (0) 26406db247cSraghuram 26506db247cSraghuram #endif /* DEBUG */ 26606db247cSraghuram 2671ae08745Sheppo 2681ae08745Sheppo #ifdef __cplusplus 2691ae08745Sheppo } 2701ae08745Sheppo #endif 2711ae08745Sheppo 2721ae08745Sheppo #endif /* _VSW_H */ 273