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> 49*cdfc78adSraghuram #include <sys/callb.h> 501ae08745Sheppo 5106db247cSraghuram #define DRV_NAME "vsw" 521ae08745Sheppo 531ae08745Sheppo /* 541ae08745Sheppo * Only support ETHER mtu at moment. 551ae08745Sheppo */ 561ae08745Sheppo #define VSW_MTU ETHERMAX 571ae08745Sheppo 581ae08745Sheppo /* ID of the source of a frame being switched */ 591ae08745Sheppo #define VSW_PHYSDEV 1 /* physical device associated */ 601ae08745Sheppo #define VSW_VNETPORT 2 /* port connected to vnet (over ldc) */ 611ae08745Sheppo #define VSW_LOCALDEV 4 /* vsw configured as an eth interface */ 621ae08745Sheppo 631ae08745Sheppo /* 647636cb21Slm66018 * Vsw queue -- largely modeled after squeue 6534683adeSsg70180 * 6634683adeSsg70180 * VSW_QUEUE_RUNNING, vqueue thread for queue is running. 6734683adeSsg70180 * VSW_QUEUE_DRAINED, vqueue thread has drained current work and is exiting. 6834683adeSsg70180 * VSW_QUEUE_STOP, request for the vqueue thread to stop. 6934683adeSsg70180 * VSW_QUEUE_STOPPED, vqueue thread is not running. 707636cb21Slm66018 */ 717636cb21Slm66018 #define VSW_QUEUE_RUNNING 0x01 7234683adeSsg70180 #define VSW_QUEUE_DRAINED 0x02 7334683adeSsg70180 #define VSW_QUEUE_STOP 0x04 7434683adeSsg70180 #define VSW_QUEUE_STOPPED 0x08 757636cb21Slm66018 767636cb21Slm66018 typedef struct vsw_queue_s { 777636cb21Slm66018 kmutex_t vq_lock; /* Lock, before using any member. */ 787636cb21Slm66018 kcondvar_t vq_cv; /* Async threads block on. */ 797636cb21Slm66018 uint32_t vq_state; /* State flags. */ 807636cb21Slm66018 817636cb21Slm66018 mblk_t *vq_first; /* First mblk chain or NULL. */ 827636cb21Slm66018 mblk_t *vq_last; /* Last mblk chain. */ 837636cb21Slm66018 847636cb21Slm66018 processorid_t vq_bind; /* Process to bind to */ 857636cb21Slm66018 kthread_t *vq_worker; /* Queue's thread */ 867636cb21Slm66018 } vsw_queue_t; 877636cb21Slm66018 887636cb21Slm66018 /* 897636cb21Slm66018 * VSW MAC Ring Resources. 907636cb21Slm66018 * MAC Ring resource is composed of this state structure and 917636cb21Slm66018 * a kernel thread to perform the processing of the ring. 927636cb21Slm66018 */ 937636cb21Slm66018 typedef struct vsw_mac_ring_s { 947636cb21Slm66018 uint32_t ring_state; 957636cb21Slm66018 967636cb21Slm66018 mac_blank_t ring_blank; 977636cb21Slm66018 void *ring_arg; 987636cb21Slm66018 997636cb21Slm66018 vsw_queue_t *ring_vqp; 1007636cb21Slm66018 struct vsw *ring_vswp; 1017636cb21Slm66018 } vsw_mac_ring_t; 1027636cb21Slm66018 1037636cb21Slm66018 /* 1047636cb21Slm66018 * Maximum Ring Resources. 1057636cb21Slm66018 */ 1067636cb21Slm66018 #define VSW_MAC_RX_RINGS 0x40 1077636cb21Slm66018 1087636cb21Slm66018 /* 1097636cb21Slm66018 * States for entry in ring table. 1107636cb21Slm66018 */ 1117636cb21Slm66018 #define VSW_MAC_RING_FREE 1 1127636cb21Slm66018 #define VSW_MAC_RING_INUSE 2 1137636cb21Slm66018 1147636cb21Slm66018 /* 1151ae08745Sheppo * Number of hash chains in the multicast forwarding database. 1161ae08745Sheppo */ 1171ae08745Sheppo #define VSW_NCHAINS 8 1181ae08745Sheppo 119f0ca1d9aSsb155480 /* Number of transmit descriptors - must be power of 2 */ 120f0ca1d9aSsb155480 #define VSW_RING_NUM_EL 512 121f0ca1d9aSsb155480 1221ae08745Sheppo /* 1231ae08745Sheppo * State of interface if switch plumbed as network device. 1241ae08745Sheppo */ 125ba2e4443Sseb #define VSW_IF_REG 0x1 /* interface was registered */ 126ba2e4443Sseb #define VSW_IF_UP 0x2 /* Interface UP */ 127ba2e4443Sseb #define VSW_IF_PROMISC 0x4 /* Interface in promiscious mode */ 1281ae08745Sheppo 1291ae08745Sheppo #define VSW_U_P(state) \ 1301ae08745Sheppo (state == (VSW_IF_UP | VSW_IF_PROMISC)) 1311ae08745Sheppo 1321ae08745Sheppo /* 1331ae08745Sheppo * Switching modes. 1341ae08745Sheppo */ 1351ae08745Sheppo #define VSW_LAYER2 0x1 /* Layer 2 - MAC switching */ 1361ae08745Sheppo #define VSW_LAYER2_PROMISC 0x2 /* Layer 2 + promisc mode */ 1371ae08745Sheppo #define VSW_LAYER3 0x4 /* Layer 3 - IP switching */ 1381ae08745Sheppo 1391ae08745Sheppo #define NUM_SMODES 3 /* number of switching modes */ 1401ae08745Sheppo 141f0ca1d9aSsb155480 #define VSW_PRI_ETH_DEFINED(vswp) ((vswp)->pri_num_types != 0) 142f0ca1d9aSsb155480 1431ae08745Sheppo /* 1441ae08745Sheppo * vsw instance state information. 1451ae08745Sheppo */ 1461ae08745Sheppo typedef struct vsw { 1471ae08745Sheppo int instance; /* instance # */ 1481ae08745Sheppo dev_info_t *dip; /* associated dev_info */ 14919b65a69Ssb155480 uint64_t regprop; /* "reg" property */ 1501ae08745Sheppo struct vsw *next; /* next in list */ 1511ae08745Sheppo char physname[LIFNAMSIZ]; /* phys-dev */ 1521ae08745Sheppo uint8_t smode[NUM_SMODES]; /* switching mode */ 1531ae08745Sheppo int smode_idx; /* curr pos in smode array */ 154e1ebb9ecSlm66018 int smode_num; /* # of modes specified */ 15519b65a69Ssb155480 kmutex_t swtmout_lock; /* setup switching tmout lock */ 15619b65a69Ssb155480 boolean_t swtmout_enabled; /* setup switching tmout on */ 15719b65a69Ssb155480 timeout_id_t swtmout_id; /* setup switching tmout id */ 15819b65a69Ssb155480 uint32_t switching_setup_done; /* setup switching done */ 15919b65a69Ssb155480 int mac_open_retries; /* mac_open() retry count */ 1601ae08745Sheppo vsw_port_list_t plist; /* associated ports */ 1611ae08745Sheppo ddi_taskq_t *taskq_p; /* VIO ctrl msg taskq */ 162c1c61f44Ssb155480 mod_hash_t *fdb_hashp; /* forwarding database */ 163c1c61f44Ssb155480 uint32_t fdb_nchains; /* # of hash chains in fdb */ 164c1c61f44Ssb155480 mod_hash_t *vlan_hashp; /* vlan hash table */ 165c1c61f44Ssb155480 uint32_t vlan_nchains; /* # of vlan hash chains */ 166c1c61f44Ssb155480 uint32_t max_frame_size; /* max frame size supported */ 1671ae08745Sheppo 1681ae08745Sheppo mod_hash_t *mfdb; /* multicast FDB */ 1691ae08745Sheppo krwlock_t mfdbrw; /* rwlock for mFDB */ 1701ae08745Sheppo 171d10e4ef2Snarayan vio_mblk_pool_t *rxh; /* Receive pool handle */ 17234683adeSsg70180 void (*vsw_switch_frame) 17334683adeSsg70180 (struct vsw *, mblk_t *, int, 17434683adeSsg70180 vsw_port_t *, mac_resource_handle_t); 175d10e4ef2Snarayan 1761ae08745Sheppo /* mac layer */ 1773c1bce15Swentaoy krwlock_t mac_rwlock; /* protect fields below */ 1781ae08745Sheppo mac_handle_t mh; 1791ae08745Sheppo mac_rx_handle_t mrh; 180e1ebb9ecSlm66018 multiaddress_capab_t maddr; /* Multiple uni addr capable */ 1811ae08745Sheppo const mac_txinfo_t *txinfo; /* MAC tx routine */ 1827636cb21Slm66018 boolean_t mstarted; /* Mac Started? */ 1837636cb21Slm66018 boolean_t mresources; /* Mac Resources cb? */ 1847636cb21Slm66018 1857636cb21Slm66018 /* 1867636cb21Slm66018 * MAC Ring Resources. 1877636cb21Slm66018 */ 1887636cb21Slm66018 kmutex_t mac_ring_lock; /* Lock for the table. */ 1897636cb21Slm66018 uint32_t mac_ring_tbl_sz; 1907636cb21Slm66018 vsw_mac_ring_t *mac_ring_tbl; /* Mac ring table. */ 1911ae08745Sheppo 1925f94e909Ssg70180 kmutex_t hw_lock; /* sync access to HW */ 193e1ebb9ecSlm66018 boolean_t recfg_reqd; /* Reconfig of addrs needed */ 194e1ebb9ecSlm66018 int promisc_cnt; 1951ae08745Sheppo 1961ae08745Sheppo /* Machine Description updates */ 1971ae08745Sheppo mdeg_node_spec_t *inst_spec; 1981ae08745Sheppo mdeg_handle_t mdeg_hdl; 19934683adeSsg70180 mdeg_handle_t mdeg_port_hdl; 2001ae08745Sheppo 2011ae08745Sheppo /* if configured as an ethernet interface */ 202ba2e4443Sseb mac_handle_t if_mh; /* MAC handle */ 2031ae08745Sheppo struct ether_addr if_addr; /* interface address */ 2041ae08745Sheppo krwlock_t if_lockrw; 2051ae08745Sheppo uint8_t if_state; /* interface state */ 2061ae08745Sheppo 2075f94e909Ssg70180 mac_addr_slot_t addr_slot; /* Unicast address slot */ 2085f94e909Ssg70180 int addr_set; /* Addr set where */ 2095f94e909Ssg70180 2101ae08745Sheppo /* multicast addresses when configured as eth interface */ 2111ae08745Sheppo kmutex_t mca_lock; /* multicast lock */ 2121ae08745Sheppo mcst_addr_t *mcap; /* list of multicast addrs */ 21306db247cSraghuram 214f0ca1d9aSsb155480 uint32_t pri_num_types; /* # of priority eth types */ 215f0ca1d9aSsb155480 uint16_t *pri_types; /* priority eth types */ 216f0ca1d9aSsb155480 vio_mblk_pool_t *pri_tx_vmp; /* tx priority mblk pool */ 217c1c61f44Ssb155480 uint16_t default_vlan_id; /* default vlan id */ 218c1c61f44Ssb155480 uint16_t pvid; /* port vlan id (untagged) */ 219c1c61f44Ssb155480 uint16_t *vids; /* vlan ids (tagged) */ 220c1c61f44Ssb155480 uint16_t nvids; /* # of vids */ 221c1c61f44Ssb155480 uint32_t vids_size; /* size alloc'd for vids list */ 222678453a8Sspeer 223678453a8Sspeer /* HybridIO related fields */ 224678453a8Sspeer boolean_t hio_capable; /* Phys dev HIO capable */ 225678453a8Sspeer vsw_hio_t vhio; /* HybridIO info */ 226*cdfc78adSraghuram callb_id_t hio_reboot_cb_id; /* Reboot callb ID */ 227*cdfc78adSraghuram callb_id_t hio_panic_cb_id; /* Panic callb ID */ 2281ae08745Sheppo } vsw_t; 2291ae08745Sheppo 2301ae08745Sheppo /* 23106db247cSraghuram * The flags that are used by vsw_mac_rx(). 2321ae08745Sheppo */ 23306db247cSraghuram typedef enum { 23406db247cSraghuram VSW_MACRX_PROMISC = 0x01, 23506db247cSraghuram VSW_MACRX_COPYMSG = 0x02, 23606db247cSraghuram VSW_MACRX_FREEMSG = 0x04 23706db247cSraghuram } vsw_macrx_flags_t; 2381ae08745Sheppo 2391ae08745Sheppo 24006db247cSraghuram #ifdef DEBUG 24106db247cSraghuram 24206db247cSraghuram extern int vswdbg; 24306db247cSraghuram extern void vswdebug(vsw_t *vswp, const char *fmt, ...); 24406db247cSraghuram 24506db247cSraghuram #define D1(...) \ 24606db247cSraghuram if (vswdbg & 0x01) \ 24706db247cSraghuram vswdebug(__VA_ARGS__) 24806db247cSraghuram 24906db247cSraghuram #define D2(...) \ 25006db247cSraghuram if (vswdbg & 0x02) \ 25106db247cSraghuram vswdebug(__VA_ARGS__) 25206db247cSraghuram 25306db247cSraghuram #define D3(...) \ 25406db247cSraghuram if (vswdbg & 0x04) \ 25506db247cSraghuram vswdebug(__VA_ARGS__) 25606db247cSraghuram 25706db247cSraghuram #define DWARN(...) \ 25806db247cSraghuram if (vswdbg & 0x08) \ 25906db247cSraghuram vswdebug(__VA_ARGS__) 26006db247cSraghuram 26106db247cSraghuram #define DERR(...) \ 26206db247cSraghuram if (vswdbg & 0x10) \ 26306db247cSraghuram vswdebug(__VA_ARGS__) 26406db247cSraghuram 26506db247cSraghuram #else 26606db247cSraghuram 26706db247cSraghuram #define DERR(...) if (0) do { } while (0) 26806db247cSraghuram #define DWARN(...) if (0) do { } while (0) 26906db247cSraghuram #define D1(...) if (0) do { } while (0) 27006db247cSraghuram #define D2(...) if (0) do { } while (0) 27106db247cSraghuram #define D3(...) if (0) do { } while (0) 27206db247cSraghuram 27306db247cSraghuram #endif /* DEBUG */ 27406db247cSraghuram 2751ae08745Sheppo 2761ae08745Sheppo #ifdef __cplusplus 2771ae08745Sheppo } 2781ae08745Sheppo #endif 2791ae08745Sheppo 2801ae08745Sheppo #endif /* _VSW_H */ 281