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*7bd3a2e2SSriharsha Basavapatna * Copyright 2010 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 67*7bd3a2e2SSriharsha Basavapatna /* Number of descriptors - must be power of 2 */ 68*7bd3a2e2SSriharsha Basavapatna #define VSW_NUM_DESCRIPTORS 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 956f09f0feSWENTAO YANG typedef enum { 966f09f0feSWENTAO YANG PROG_init = 0x00, 976f09f0feSWENTAO YANG PROG_locks = 0x01, 986f09f0feSWENTAO YANG PROG_readmd = 0x02, 996f09f0feSWENTAO YANG PROG_fdb = 0x04, 1006f09f0feSWENTAO YANG PROG_mfdb = 0x08, 1016f09f0feSWENTAO YANG PROG_taskq = 0x10, 10234b64c01SWENTAO YANG PROG_rxp_taskq = 0x20, 10334b64c01SWENTAO YANG PROG_swmode = 0x40, 10434b64c01SWENTAO YANG PROG_macreg = 0x80, 10534b64c01SWENTAO YANG PROG_mdreg = 0x100 1066f09f0feSWENTAO YANG } vsw_attach_progress_t; 1076f09f0feSWENTAO YANG 1081ae08745Sheppo /* 109da14cebeSEric Cheng * vlan-id information. 110da14cebeSEric Cheng */ 111da14cebeSEric Cheng typedef struct vsw_vlanid { 112da14cebeSEric Cheng uint16_t vl_vid; /* vlan-id */ 113da14cebeSEric Cheng mac_unicast_handle_t vl_muh; /* mac unicast handle */ 114da14cebeSEric Cheng boolean_t vl_set; /* set? */ 115da14cebeSEric Cheng } vsw_vlanid_t; 116da14cebeSEric Cheng 117da14cebeSEric Cheng /* 1181ae08745Sheppo * vsw instance state information. 1191ae08745Sheppo */ 1201ae08745Sheppo typedef struct vsw { 1211ae08745Sheppo int instance; /* instance # */ 1221ae08745Sheppo dev_info_t *dip; /* associated dev_info */ 12319b65a69Ssb155480 uint64_t regprop; /* "reg" property */ 1246f09f0feSWENTAO YANG vsw_attach_progress_t attach_progress; /* attach progress flags */ 1251ae08745Sheppo struct vsw *next; /* next in list */ 1261ae08745Sheppo char physname[LIFNAMSIZ]; /* phys-dev */ 127da14cebeSEric Cheng uint8_t smode; /* switching mode */ 128808f26a8SSriharsha Basavapatna kmutex_t sw_thr_lock; /* setup switching thr lock */ 129808f26a8SSriharsha Basavapatna kcondvar_t sw_thr_cv; /* cv for setup switching thr */ 130808f26a8SSriharsha Basavapatna kthread_t *sw_thread; /* setup switching thread */ 131808f26a8SSriharsha Basavapatna sw_thr_flags_t sw_thr_flags; /* setup switching thr flags */ 13219b65a69Ssb155480 uint32_t switching_setup_done; /* setup switching done */ 13319b65a69Ssb155480 int mac_open_retries; /* mac_open() retry count */ 1341ae08745Sheppo vsw_port_list_t plist; /* associated ports */ 1351ae08745Sheppo ddi_taskq_t *taskq_p; /* VIO ctrl msg taskq */ 136c1c61f44Ssb155480 mod_hash_t *fdb_hashp; /* forwarding database */ 137c1c61f44Ssb155480 uint32_t fdb_nchains; /* # of hash chains in fdb */ 138c1c61f44Ssb155480 mod_hash_t *vlan_hashp; /* vlan hash table */ 139c1c61f44Ssb155480 uint32_t vlan_nchains; /* # of vlan hash chains */ 1407b1f684aSSriharsha Basavapatna uint32_t mtu; /* mtu of the device */ 141c1c61f44Ssb155480 uint32_t max_frame_size; /* max frame size supported */ 1427b1f684aSSriharsha Basavapatna uint32_t mtu_physdev_orig; /* orig mtu of the physdev */ 1431ae08745Sheppo 1441ae08745Sheppo mod_hash_t *mfdb; /* multicast FDB */ 1451ae08745Sheppo krwlock_t mfdbrw; /* rwlock for mFDB */ 1461ae08745Sheppo 14734b64c01SWENTAO YANG ddi_taskq_t *rxp_taskq; /* VIO rx pool taskq */ 14834683adeSsg70180 void (*vsw_switch_frame) 14934683adeSsg70180 (struct vsw *, mblk_t *, int, 15034683adeSsg70180 vsw_port_t *, mac_resource_handle_t); 151d10e4ef2Snarayan 1521ae08745Sheppo /* mac layer */ 153da14cebeSEric Cheng kmutex_t mac_lock; /* protect mh */ 1541ae08745Sheppo mac_handle_t mh; 155da14cebeSEric Cheng krwlock_t maccl_rwlock; /* protect fields below */ 156da14cebeSEric Cheng mac_client_handle_t mch; /* mac client handle */ 157da14cebeSEric Cheng mac_unicast_handle_t muh; /* mac unicast handle */ 1581107ea93SSriharsha Basavapatna mac_notify_handle_t mnh; /* mac notify handle */ 1597636cb21Slm66018 160e1ebb9ecSlm66018 boolean_t recfg_reqd; /* Reconfig of addrs needed */ 161da14cebeSEric Cheng 162da14cebeSEric Cheng /* mac layer switching flag */ 163da14cebeSEric Cheng boolean_t mac_cl_switching; 1641ae08745Sheppo 1651ae08745Sheppo /* Machine Description updates */ 1661ae08745Sheppo mdeg_node_spec_t *inst_spec; 1671ae08745Sheppo mdeg_handle_t mdeg_hdl; 16834683adeSsg70180 mdeg_handle_t mdeg_port_hdl; 1691ae08745Sheppo 1701ae08745Sheppo /* if configured as an ethernet interface */ 171ba2e4443Sseb mac_handle_t if_mh; /* MAC handle */ 1721ae08745Sheppo struct ether_addr if_addr; /* interface address */ 1731ae08745Sheppo krwlock_t if_lockrw; 1741ae08745Sheppo uint8_t if_state; /* interface state */ 1751ae08745Sheppo 176da14cebeSEric Cheng boolean_t addr_set; /* is addr set to HW */ 1775f94e909Ssg70180 1781ae08745Sheppo /* multicast addresses when configured as eth interface */ 1791ae08745Sheppo kmutex_t mca_lock; /* multicast lock */ 1801ae08745Sheppo mcst_addr_t *mcap; /* list of multicast addrs */ 18106db247cSraghuram 182f0ca1d9aSsb155480 uint32_t pri_num_types; /* # of priority eth types */ 183f0ca1d9aSsb155480 uint16_t *pri_types; /* priority eth types */ 184f0ca1d9aSsb155480 vio_mblk_pool_t *pri_tx_vmp; /* tx priority mblk pool */ 185c1c61f44Ssb155480 uint16_t default_vlan_id; /* default vlan id */ 186c1c61f44Ssb155480 uint16_t pvid; /* port vlan id (untagged) */ 187da14cebeSEric Cheng vsw_vlanid_t *vids; /* vlan ids (tagged) */ 188c1c61f44Ssb155480 uint16_t nvids; /* # of vids */ 189c1c61f44Ssb155480 uint32_t vids_size; /* size alloc'd for vids list */ 190678453a8Sspeer 191678453a8Sspeer /* HybridIO related fields */ 192678453a8Sspeer boolean_t hio_capable; /* Phys dev HIO capable */ 193678453a8Sspeer vsw_hio_t vhio; /* HybridIO info */ 194cdfc78adSraghuram callb_id_t hio_reboot_cb_id; /* Reboot callb ID */ 195cdfc78adSraghuram callb_id_t hio_panic_cb_id; /* Panic callb ID */ 1961107ea93SSriharsha Basavapatna 1971107ea93SSriharsha Basavapatna /* Link-state related fields */ 1981107ea93SSriharsha Basavapatna boolean_t phys_no_link_update; /* no link-update supp */ 1991107ea93SSriharsha Basavapatna boolean_t pls_update; /* phys link state update ? */ 2001107ea93SSriharsha Basavapatna link_state_t phys_link_state; /* physical link state */ 201bce0a86eSWENTAO YANG 202bce0a86eSWENTAO YANG /* bandwidth related fields */ 203bce0a86eSWENTAO YANG uint64_t bandwidth; /* bandwidth limit */ 2041ae08745Sheppo } vsw_t; 2051ae08745Sheppo 2061ae08745Sheppo /* 20706db247cSraghuram * The flags that are used by vsw_mac_rx(). 2081ae08745Sheppo */ 20906db247cSraghuram typedef enum { 21006db247cSraghuram VSW_MACRX_PROMISC = 0x01, 21106db247cSraghuram VSW_MACRX_COPYMSG = 0x02, 21206db247cSraghuram VSW_MACRX_FREEMSG = 0x04 21306db247cSraghuram } vsw_macrx_flags_t; 2141ae08745Sheppo 2151ae08745Sheppo 21606db247cSraghuram #ifdef DEBUG 21706db247cSraghuram 21806db247cSraghuram extern int vswdbg; 21906db247cSraghuram extern void vswdebug(vsw_t *vswp, const char *fmt, ...); 22006db247cSraghuram 22106db247cSraghuram #define D1(...) \ 22206db247cSraghuram if (vswdbg & 0x01) \ 22306db247cSraghuram vswdebug(__VA_ARGS__) 22406db247cSraghuram 22506db247cSraghuram #define D2(...) \ 22606db247cSraghuram if (vswdbg & 0x02) \ 22706db247cSraghuram vswdebug(__VA_ARGS__) 22806db247cSraghuram 22906db247cSraghuram #define D3(...) \ 23006db247cSraghuram if (vswdbg & 0x04) \ 23106db247cSraghuram vswdebug(__VA_ARGS__) 23206db247cSraghuram 23306db247cSraghuram #define DWARN(...) \ 23406db247cSraghuram if (vswdbg & 0x08) \ 23506db247cSraghuram vswdebug(__VA_ARGS__) 23606db247cSraghuram 23706db247cSraghuram #define DERR(...) \ 23806db247cSraghuram if (vswdbg & 0x10) \ 23906db247cSraghuram vswdebug(__VA_ARGS__) 24006db247cSraghuram 24106db247cSraghuram #else 24206db247cSraghuram 24306db247cSraghuram #define DERR(...) if (0) do { } while (0) 24406db247cSraghuram #define DWARN(...) if (0) do { } while (0) 24506db247cSraghuram #define D1(...) if (0) do { } while (0) 24606db247cSraghuram #define D2(...) if (0) do { } while (0) 24706db247cSraghuram #define D3(...) if (0) do { } while (0) 24806db247cSraghuram 24906db247cSraghuram #endif /* DEBUG */ 25006db247cSraghuram 2511ae08745Sheppo 2521ae08745Sheppo #ifdef __cplusplus 2531ae08745Sheppo } 2541ae08745Sheppo #endif 2551ae08745Sheppo 2561ae08745Sheppo #endif /* _VSW_H */ 257