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 /* 231ae08745Sheppo * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 241ae08745Sheppo * Use is subject to license terms. 251ae08745Sheppo */ 261ae08745Sheppo 271ae08745Sheppo /* 281ae08745Sheppo * This header file contains the basic data structures which the 291ae08745Sheppo * virtual switch (vsw) uses to communicate with its clients and 301ae08745Sheppo * the outside world. 311ae08745Sheppo * 321ae08745Sheppo * The virtual switch reads the machine description (MD) to 331ae08745Sheppo * determine how many port_t structures to create (each port_t 341ae08745Sheppo * can support communications to a single network device). The 351ae08745Sheppo * port_t's are maintained in a linked list. 361ae08745Sheppo * 371ae08745Sheppo * Each port in turn contains a number of logical domain channels 381ae08745Sheppo * (ldc's) which are inter domain communications channels which 391ae08745Sheppo * are used for passing small messages between the domains. Their 401ae08745Sheppo * may be an unlimited number of channels associated with each port, 411ae08745Sheppo * though most devices only use a single channel. 421ae08745Sheppo * 431ae08745Sheppo * The ldc is a bi-directional channel, which is divided up into 441ae08745Sheppo * two directional 'lanes', one outbound from the switch to the 451ae08745Sheppo * virtual network device, the other inbound to the switch. 461ae08745Sheppo * Depending on the type of device each lane may have seperate 471ae08745Sheppo * communication paramaters (such as mtu etc). 481ae08745Sheppo * 491ae08745Sheppo * For those network clients which use descriptor rings the 501ae08745Sheppo * rings are associated with the appropriate lane. I.e. rings 511ae08745Sheppo * which the switch exports are associated with the outbound lanes 521ae08745Sheppo * while those which the network clients are exporting to the switch 531ae08745Sheppo * are associated with the inbound lane. 541ae08745Sheppo * 551ae08745Sheppo * In diagram form the data structures look as follows: 561ae08745Sheppo * 571ae08745Sheppo * vsw instance 581ae08745Sheppo * | 591ae08745Sheppo * +----->port_t----->port_t----->port_t-----> 601ae08745Sheppo * | 611ae08745Sheppo * +--->ldc_t--->ldc_t--->ldc_t---> 621ae08745Sheppo * | 631ae08745Sheppo * +--->lane_t (inbound) 641ae08745Sheppo * | | 651ae08745Sheppo * | +--->dring--->dring---> 661ae08745Sheppo * | 671ae08745Sheppo * +--->lane_t (outbound) 681ae08745Sheppo * | 691ae08745Sheppo * +--->dring--->dring---> 701ae08745Sheppo * 711ae08745Sheppo */ 721ae08745Sheppo 731ae08745Sheppo #ifndef _VSW_H 741ae08745Sheppo #define _VSW_H 751ae08745Sheppo 761ae08745Sheppo #pragma ident "%Z%%M% %I% %E% SMI" 771ae08745Sheppo 781ae08745Sheppo #ifdef __cplusplus 791ae08745Sheppo extern "C" { 801ae08745Sheppo #endif 811ae08745Sheppo 821ae08745Sheppo #include <sys/vio_mailbox.h> 831ae08745Sheppo #include <sys/vnet_common.h> 841ae08745Sheppo #include <sys/ethernet.h> 85d10e4ef2Snarayan #include <sys/vio_util.h> 861ae08745Sheppo 871ae08745Sheppo /* 881ae08745Sheppo * Default message type. 891ae08745Sheppo */ 901ae08745Sheppo typedef struct def_msg { 911ae08745Sheppo uint64_t data[8]; 921ae08745Sheppo } def_msg_t; 931ae08745Sheppo 941ae08745Sheppo /* 951ae08745Sheppo * Currently only support one major/minor pair. 961ae08745Sheppo */ 971ae08745Sheppo #define VSW_NUM_VER 1 981ae08745Sheppo 991ae08745Sheppo typedef struct ver_sup { 1001ae08745Sheppo uint32_t ver_major:16, 1011ae08745Sheppo ver_minor:16; 1021ae08745Sheppo } ver_sup_t; 1031ae08745Sheppo 1041ae08745Sheppo /* 1051ae08745Sheppo * Only support ETHER mtu at moment. 1061ae08745Sheppo */ 1071ae08745Sheppo #define VSW_MTU ETHERMAX 1081ae08745Sheppo 1091ae08745Sheppo /* 1101ae08745Sheppo * Lane states. 1111ae08745Sheppo */ 1121ae08745Sheppo #define VSW_LANE_INACTIV 0x0 /* No params set for lane */ 1131ae08745Sheppo 1141ae08745Sheppo #define VSW_VER_INFO_SENT 0x1 /* Version # sent to peer */ 1151ae08745Sheppo #define VSW_VER_INFO_RECV 0x2 /* Version # recv from peer */ 1161ae08745Sheppo #define VSW_VER_ACK_RECV 0x4 1171ae08745Sheppo #define VSW_VER_ACK_SENT 0x8 1181ae08745Sheppo #define VSW_VER_NACK_RECV 0x10 1191ae08745Sheppo #define VSW_VER_NACK_SENT 0x20 1201ae08745Sheppo 1211ae08745Sheppo #define VSW_ATTR_INFO_SENT 0x40 /* Attributes sent to peer */ 1221ae08745Sheppo #define VSW_ATTR_INFO_RECV 0x80 /* Peer attributes received */ 1231ae08745Sheppo #define VSW_ATTR_ACK_SENT 0x100 1241ae08745Sheppo #define VSW_ATTR_ACK_RECV 0x200 1251ae08745Sheppo #define VSW_ATTR_NACK_SENT 0x400 1261ae08745Sheppo #define VSW_ATTR_NACK_RECV 0x800 1271ae08745Sheppo 1281ae08745Sheppo #define VSW_DRING_INFO_SENT 0x1000 /* Dring info sent to peer */ 1291ae08745Sheppo #define VSW_DRING_INFO_RECV 0x2000 /* Dring info received */ 1301ae08745Sheppo #define VSW_DRING_ACK_SENT 0x4000 1311ae08745Sheppo #define VSW_DRING_ACK_RECV 0x8000 1321ae08745Sheppo #define VSW_DRING_NACK_SENT 0x10000 1331ae08745Sheppo #define VSW_DRING_NACK_RECV 0x20000 1341ae08745Sheppo 1351ae08745Sheppo #define VSW_RDX_INFO_SENT 0x40000 /* RDX sent to peer */ 1361ae08745Sheppo #define VSW_RDX_INFO_RECV 0x80000 /* RDX received from peer */ 1371ae08745Sheppo #define VSW_RDX_ACK_SENT 0x100000 1381ae08745Sheppo #define VSW_RDX_ACK_RECV 0x200000 1391ae08745Sheppo #define VSW_RDX_NACK_SENT 0x400000 1401ae08745Sheppo #define VSW_RDX_NACK_RECV 0x800000 1411ae08745Sheppo 1421ae08745Sheppo #define VSW_MCST_INFO_SENT 0x1000000 1431ae08745Sheppo #define VSW_MCST_INFO_RECV 0x2000000 1441ae08745Sheppo #define VSW_MCST_ACK_SENT 0x4000000 1451ae08745Sheppo #define VSW_MCST_ACK_RECV 0x8000000 1461ae08745Sheppo #define VSW_MCST_NACK_SENT 0x10000000 1471ae08745Sheppo #define VSW_MCST_NACK_RECV 0x20000000 1481ae08745Sheppo 1491ae08745Sheppo #define VSW_LANE_ACTIVE 0x40000000 /* Lane open to xmit data */ 1501ae08745Sheppo 1511ae08745Sheppo /* Handshake milestones */ 1521ae08745Sheppo #define VSW_MILESTONE0 0x1 /* ver info exchanged */ 1531ae08745Sheppo #define VSW_MILESTONE1 0x2 /* attribute exchanged */ 1541ae08745Sheppo #define VSW_MILESTONE2 0x4 /* dring info exchanged */ 1551ae08745Sheppo #define VSW_MILESTONE3 0x8 /* rdx exchanged */ 1561ae08745Sheppo #define VSW_MILESTONE4 0x10 /* handshake complete */ 1571ae08745Sheppo 1581ae08745Sheppo /* 1591ae08745Sheppo * Lane direction (relative to ourselves). 1601ae08745Sheppo */ 1611ae08745Sheppo #define INBOUND 0x1 1621ae08745Sheppo #define OUTBOUND 0x2 1631ae08745Sheppo 1641ae08745Sheppo /* Peer session id received */ 1651ae08745Sheppo #define VSW_PEER_SESSION 0x1 1661ae08745Sheppo 1671ae08745Sheppo /* 1681ae08745Sheppo * Maximum number of consecutive reads of data from channel 1691ae08745Sheppo */ 1701ae08745Sheppo #define VSW_MAX_CHAN_READ 50 1711ae08745Sheppo 1721ae08745Sheppo /* 1731ae08745Sheppo * Currently only support one ldc per port. 1741ae08745Sheppo */ 1751ae08745Sheppo #define VSW_PORT_MAX_LDCS 1 /* max # of ldcs per port */ 1761ae08745Sheppo 1771ae08745Sheppo /* 1781ae08745Sheppo * Used for port add/deletion. 1791ae08745Sheppo */ 1801ae08745Sheppo #define VSW_PORT_UPDATED 0x1 1811ae08745Sheppo 1821ae08745Sheppo #define LDC_TX_SUCCESS 0 /* ldc transmit success */ 1831ae08745Sheppo #define LDC_TX_FAILURE 1 /* ldc transmit failure */ 1841ae08745Sheppo #define LDC_TX_NORESOURCES 2 /* out of descriptors */ 1851ae08745Sheppo 1861ae08745Sheppo /* ID of the source of a frame being switched */ 1871ae08745Sheppo #define VSW_PHYSDEV 1 /* physical device associated */ 1881ae08745Sheppo #define VSW_VNETPORT 2 /* port connected to vnet (over ldc) */ 1891ae08745Sheppo #define VSW_LOCALDEV 4 /* vsw configured as an eth interface */ 1901ae08745Sheppo 1911ae08745Sheppo /* 1921ae08745Sheppo * Descriptor ring info 1931ae08745Sheppo * 1941ae08745Sheppo * Each descriptor element has a pre-allocated data buffer 1951ae08745Sheppo * associated with it, into which data being transmitted is 1961ae08745Sheppo * copied. By pre-allocating we speed up the copying process. 1971ae08745Sheppo * The buffer is re-used once the peer has indicated that it is 1981ae08745Sheppo * finished with the descriptor. 1991ae08745Sheppo */ 2001ae08745Sheppo #define VSW_RING_NUM_EL 512 /* Num of entries in ring */ 2011ae08745Sheppo #define VSW_RING_EL_DATA_SZ 2048 /* Size of data section (bytes) */ 2021ae08745Sheppo #define VSW_PRIV_SIZE sizeof (vnet_private_desc_t) 2031ae08745Sheppo #define VSW_PUB_SIZE sizeof (vnet_public_desc_t) 2041ae08745Sheppo 2051ae08745Sheppo #define VSW_MAX_COOKIES ((ETHERMTU >> MMU_PAGESHIFT) + 2) 2061ae08745Sheppo 2071ae08745Sheppo /* 208e1ebb9ecSlm66018 * LDC pkt tranfer MTU 209e1ebb9ecSlm66018 */ 210e1ebb9ecSlm66018 #define VSW_LDC_MTU sizeof (def_msg_t) 211e1ebb9ecSlm66018 212e1ebb9ecSlm66018 /* 213d10e4ef2Snarayan * Size and number of mblks to be created in free pool. 214d10e4ef2Snarayan */ 215d10e4ef2Snarayan #define VSW_MBLK_SIZE 2048 216d10e4ef2Snarayan #define VSW_NUM_MBLKS 1024 217d10e4ef2Snarayan 218d10e4ef2Snarayan /* 2191ae08745Sheppo * Private descriptor 2201ae08745Sheppo */ 2211ae08745Sheppo typedef struct vsw_private_desc { 222d10e4ef2Snarayan /* 223d10e4ef2Snarayan * Below lock must be held when accessing the state of 224d10e4ef2Snarayan * a descriptor on either the private or public sections 225d10e4ef2Snarayan * of the ring. 226d10e4ef2Snarayan */ 227d10e4ef2Snarayan kmutex_t dstate_lock; 2281ae08745Sheppo uint64_t dstate; 2291ae08745Sheppo vnet_public_desc_t *descp; 2301ae08745Sheppo ldc_mem_handle_t memhandle; 2311ae08745Sheppo void *datap; 2321ae08745Sheppo uint64_t datalen; 2331ae08745Sheppo uint64_t ncookies; 2341ae08745Sheppo ldc_mem_cookie_t memcookie[VSW_MAX_COOKIES]; 2351ae08745Sheppo int bound; 2361ae08745Sheppo } vsw_private_desc_t; 2371ae08745Sheppo 2381ae08745Sheppo /* 2391ae08745Sheppo * Descriptor ring structure 2401ae08745Sheppo */ 2411ae08745Sheppo typedef struct dring_info { 2421ae08745Sheppo struct dring_info *next; /* next ring in chain */ 2431ae08745Sheppo kmutex_t dlock; 2441ae08745Sheppo uint32_t num_descriptors; 2451ae08745Sheppo uint32_t descriptor_size; 2461ae08745Sheppo uint32_t options; 2471ae08745Sheppo uint32_t ncookies; 2481ae08745Sheppo ldc_mem_cookie_t cookie[1]; 2491ae08745Sheppo 2501ae08745Sheppo ldc_dring_handle_t handle; 2511ae08745Sheppo uint64_t ident; /* identifier sent to peer */ 2521ae08745Sheppo uint64_t end_idx; /* last idx processed */ 253d10e4ef2Snarayan int64_t last_ack_recv; 254d10e4ef2Snarayan 255d10e4ef2Snarayan kmutex_t restart_lock; 256d10e4ef2Snarayan boolean_t restart_reqd; /* send restart msg */ 2571ae08745Sheppo 2581ae08745Sheppo /* 2591ae08745Sheppo * base address of private and public portions of the 2601ae08745Sheppo * ring (where appropriate), and data block. 2611ae08745Sheppo */ 2621ae08745Sheppo void *pub_addr; /* base of public section */ 2631ae08745Sheppo void *priv_addr; /* base of private section */ 2641ae08745Sheppo void *data_addr; /* base of data section */ 2651ae08745Sheppo size_t data_sz; /* size of data section */ 2661ae08745Sheppo } dring_info_t; 2671ae08745Sheppo 2681ae08745Sheppo /* 2691ae08745Sheppo * Each ldc connection is comprised of two lanes, incoming 2701ae08745Sheppo * from a peer, and outgoing to that peer. Each lane shares 2711ae08745Sheppo * common ldc parameters and also has private lane-specific 2721ae08745Sheppo * parameters. 2731ae08745Sheppo */ 2741ae08745Sheppo typedef struct lane { 2751ae08745Sheppo uint64_t lstate; /* Lane state */ 2761ae08745Sheppo uint32_t ver_major:16, /* Version major number */ 2771ae08745Sheppo ver_minor:16; /* Version minor number */ 278d10e4ef2Snarayan kmutex_t seq_lock; 2791ae08745Sheppo uint64_t seq_num; /* Sequence number */ 2801ae08745Sheppo uint64_t mtu; /* ETHERMTU */ 2811ae08745Sheppo uint64_t addr; /* Unique physical address */ 2821ae08745Sheppo uint8_t addr_type; /* Only MAC address at moment */ 2831ae08745Sheppo uint8_t xfer_mode; /* Dring or Pkt based */ 2841ae08745Sheppo uint8_t ack_freq; /* Only non zero for Pkt based xfer */ 2851ae08745Sheppo dring_info_t *dringp; /* List of drings for this lane */ 2861ae08745Sheppo } lane_t; 2871ae08745Sheppo 2881ae08745Sheppo /* channel drain states */ 2891ae08745Sheppo #define VSW_LDC_INIT 0x1 /* Initial non-drain state */ 2901ae08745Sheppo #define VSW_LDC_DRAINING 0x2 /* Channel draining */ 2911ae08745Sheppo 2921ae08745Sheppo /* ldc information associated with a vsw-port */ 2931ae08745Sheppo typedef struct vsw_ldc { 2941ae08745Sheppo struct vsw_ldc *ldc_next; /* next ldc in the list */ 2951ae08745Sheppo struct vsw_port *ldc_port; /* associated port */ 2961ae08745Sheppo struct vsw *ldc_vswp; /* associated vsw */ 2971ae08745Sheppo kmutex_t ldc_cblock; /* sync callback processing */ 2981ae08745Sheppo kmutex_t ldc_txlock; /* sync transmits */ 2991ae08745Sheppo uint64_t ldc_id; /* channel number */ 3001ae08745Sheppo ldc_handle_t ldc_handle; /* channel handle */ 3011ae08745Sheppo kmutex_t drain_cv_lock; 3021ae08745Sheppo kcondvar_t drain_cv; /* channel draining */ 3031ae08745Sheppo int drain_state; 3041ae08745Sheppo uint32_t hphase; /* handshake phase */ 3051ae08745Sheppo int hcnt; /* # handshake attempts */ 3063af08d82Slm66018 kmutex_t status_lock; 3071ae08745Sheppo ldc_status_t ldc_status; /* channel status */ 3081ae08745Sheppo uint64_t local_session; /* Our session id */ 3091ae08745Sheppo uint64_t peer_session; /* Our peers session id */ 3101ae08745Sheppo uint8_t session_status; /* Session recv'd, sent */ 3111ae08745Sheppo kmutex_t hss_lock; 3121ae08745Sheppo uint32_t hss_id; /* Handshake session id */ 3131ae08745Sheppo uint64_t next_ident; /* Next dring ident # to use */ 3141ae08745Sheppo lane_t lane_in; /* Inbound lane */ 3151ae08745Sheppo lane_t lane_out; /* Outbound lane */ 3161ae08745Sheppo uint8_t dev_class; /* Peer device class */ 317d10e4ef2Snarayan vio_mblk_pool_t *rxh; /* Receive pool handle */ 3181ae08745Sheppo } vsw_ldc_t; 3191ae08745Sheppo 3201ae08745Sheppo /* list of ldcs per port */ 3211ae08745Sheppo typedef struct vsw_ldc_list { 3221ae08745Sheppo vsw_ldc_t *head; /* head of the list */ 3231ae08745Sheppo krwlock_t lockrw; /* sync access(rw) to the list */ 3241ae08745Sheppo int num_ldcs; /* number of ldcs in the list */ 3251ae08745Sheppo } vsw_ldc_list_t; 3261ae08745Sheppo 3271ae08745Sheppo /* multicast addresses port is interested in */ 3281ae08745Sheppo typedef struct mcst_addr { 3291ae08745Sheppo struct mcst_addr *nextp; 3301ae08745Sheppo uint64_t addr; 3311ae08745Sheppo } mcst_addr_t; 3321ae08745Sheppo 3331ae08745Sheppo /* Port detach states */ 3341ae08745Sheppo #define VSW_PORT_INIT 0x1 /* Initial non-detach state */ 3351ae08745Sheppo #define VSW_PORT_DETACHING 0x2 /* In process of being detached */ 3361ae08745Sheppo #define VSW_PORT_DETACHABLE 0x4 /* Safe to detach */ 3371ae08745Sheppo 338e1ebb9ecSlm66018 #define VSW_ADDR_UNSET 0x0 /* Addr not set */ 339e1ebb9ecSlm66018 #define VSW_ADDR_HW 0x1 /* Addr programmed in HW */ 340e1ebb9ecSlm66018 #define VSW_ADDR_PROMISC 0x2 /* Card in promisc to see addr */ 341e1ebb9ecSlm66018 3421ae08745Sheppo /* port information associated with a vsw */ 3431ae08745Sheppo typedef struct vsw_port { 3441ae08745Sheppo int p_instance; /* port instance */ 3451ae08745Sheppo struct vsw_port *p_next; /* next port in the list */ 3461ae08745Sheppo struct vsw *p_vswp; /* associated vsw */ 3471ae08745Sheppo vsw_ldc_list_t p_ldclist; /* list of ldcs for this port */ 3481ae08745Sheppo 3491ae08745Sheppo kmutex_t tx_lock; /* transmit lock */ 3501ae08745Sheppo int (*transmit)(vsw_ldc_t *, mblk_t *); 3511ae08745Sheppo 3521ae08745Sheppo int state; /* port state */ 3531ae08745Sheppo kmutex_t state_lock; 3541ae08745Sheppo kcondvar_t state_cv; 3551ae08745Sheppo 3561ae08745Sheppo int ref_cnt; /* # of active references */ 3571ae08745Sheppo kmutex_t ref_lock; 3581ae08745Sheppo kcondvar_t ref_cv; 3591ae08745Sheppo 3601ae08745Sheppo kmutex_t mca_lock; /* multicast lock */ 3611ae08745Sheppo mcst_addr_t *mcap; /* list of multicast addrs */ 3621ae08745Sheppo 363e1ebb9ecSlm66018 mac_addr_slot_t addr_slot; /* Unicast address slot */ 364e1ebb9ecSlm66018 int addr_set; /* Addr set where */ 365e1ebb9ecSlm66018 3661ae08745Sheppo /* 3671ae08745Sheppo * mac address of the port & connected device 3681ae08745Sheppo */ 3691ae08745Sheppo struct ether_addr p_macaddr; 3701ae08745Sheppo } vsw_port_t; 3711ae08745Sheppo 3721ae08745Sheppo /* list of ports per vsw */ 3731ae08745Sheppo typedef struct vsw_port_list { 3741ae08745Sheppo vsw_port_t *head; /* head of the list */ 3751ae08745Sheppo krwlock_t lockrw; /* sync access(rw) to the list */ 3761ae08745Sheppo int num_ports; /* number of ports in the list */ 3771ae08745Sheppo } vsw_port_list_t; 3781ae08745Sheppo 3791ae08745Sheppo /* 3801ae08745Sheppo * Taskq control message 3811ae08745Sheppo */ 3821ae08745Sheppo typedef struct vsw_ctrl_task { 3831ae08745Sheppo vsw_ldc_t *ldcp; 3841ae08745Sheppo def_msg_t pktp; 3851ae08745Sheppo uint32_t hss_id; 3861ae08745Sheppo } vsw_ctrl_task_t; 3871ae08745Sheppo 3881ae08745Sheppo /* 3897636cb21Slm66018 * Vsw queue -- largely modeled after squeue 390*34683adeSsg70180 * 391*34683adeSsg70180 * VSW_QUEUE_RUNNING, vqueue thread for queue is running. 392*34683adeSsg70180 * VSW_QUEUE_DRAINED, vqueue thread has drained current work and is exiting. 393*34683adeSsg70180 * VSW_QUEUE_STOP, request for the vqueue thread to stop. 394*34683adeSsg70180 * VSW_QUEUE_STOPPED, vqueue thread is not running. 3957636cb21Slm66018 */ 3967636cb21Slm66018 #define VSW_QUEUE_RUNNING 0x01 397*34683adeSsg70180 #define VSW_QUEUE_DRAINED 0x02 398*34683adeSsg70180 #define VSW_QUEUE_STOP 0x04 399*34683adeSsg70180 #define VSW_QUEUE_STOPPED 0x08 4007636cb21Slm66018 4017636cb21Slm66018 typedef struct vsw_queue_s { 4027636cb21Slm66018 kmutex_t vq_lock; /* Lock, before using any member. */ 4037636cb21Slm66018 kcondvar_t vq_cv; /* Async threads block on. */ 4047636cb21Slm66018 uint32_t vq_state; /* State flags. */ 4057636cb21Slm66018 4067636cb21Slm66018 mblk_t *vq_first; /* First mblk chain or NULL. */ 4077636cb21Slm66018 mblk_t *vq_last; /* Last mblk chain. */ 4087636cb21Slm66018 4097636cb21Slm66018 processorid_t vq_bind; /* Process to bind to */ 4107636cb21Slm66018 kthread_t *vq_worker; /* Queue's thread */ 4117636cb21Slm66018 } vsw_queue_t; 4127636cb21Slm66018 4137636cb21Slm66018 /* 4147636cb21Slm66018 * VSW MAC Ring Resources. 4157636cb21Slm66018 * MAC Ring resource is composed of this state structure and 4167636cb21Slm66018 * a kernel thread to perform the processing of the ring. 4177636cb21Slm66018 */ 4187636cb21Slm66018 typedef struct vsw_mac_ring_s { 4197636cb21Slm66018 uint32_t ring_state; 4207636cb21Slm66018 4217636cb21Slm66018 mac_blank_t ring_blank; 4227636cb21Slm66018 void *ring_arg; 4237636cb21Slm66018 4247636cb21Slm66018 vsw_queue_t *ring_vqp; 4257636cb21Slm66018 struct vsw *ring_vswp; 4267636cb21Slm66018 } vsw_mac_ring_t; 4277636cb21Slm66018 4287636cb21Slm66018 /* 4297636cb21Slm66018 * Maximum Ring Resources. 4307636cb21Slm66018 */ 4317636cb21Slm66018 #define VSW_MAC_RX_RINGS 0x40 4327636cb21Slm66018 4337636cb21Slm66018 /* 4347636cb21Slm66018 * States for entry in ring table. 4357636cb21Slm66018 */ 4367636cb21Slm66018 #define VSW_MAC_RING_FREE 1 4377636cb21Slm66018 #define VSW_MAC_RING_INUSE 2 4387636cb21Slm66018 4397636cb21Slm66018 /* 4401ae08745Sheppo * Number of hash chains in the multicast forwarding database. 4411ae08745Sheppo */ 4421ae08745Sheppo #define VSW_NCHAINS 8 4431ae08745Sheppo 4441ae08745Sheppo /* 4451ae08745Sheppo * State of interface if switch plumbed as network device. 4461ae08745Sheppo */ 447ba2e4443Sseb #define VSW_IF_REG 0x1 /* interface was registered */ 448ba2e4443Sseb #define VSW_IF_UP 0x2 /* Interface UP */ 449ba2e4443Sseb #define VSW_IF_PROMISC 0x4 /* Interface in promiscious mode */ 4501ae08745Sheppo 4511ae08745Sheppo #define VSW_U_P(state) \ 4521ae08745Sheppo (state == (VSW_IF_UP | VSW_IF_PROMISC)) 4531ae08745Sheppo 4541ae08745Sheppo /* 4551ae08745Sheppo * Switching modes. 4561ae08745Sheppo */ 4571ae08745Sheppo #define VSW_LAYER2 0x1 /* Layer 2 - MAC switching */ 4581ae08745Sheppo #define VSW_LAYER2_PROMISC 0x2 /* Layer 2 + promisc mode */ 4591ae08745Sheppo #define VSW_LAYER3 0x4 /* Layer 3 - IP switching */ 4601ae08745Sheppo 4611ae08745Sheppo #define NUM_SMODES 3 /* number of switching modes */ 4621ae08745Sheppo 4631ae08745Sheppo /* 464e1ebb9ecSlm66018 * Bits indicating which properties we've read from MD or physical device. 4651ae08745Sheppo */ 4661ae08745Sheppo #define VSW_MD_PHYSNAME 0x1 4671ae08745Sheppo #define VSW_MD_MACADDR 0x2 468e1ebb9ecSlm66018 #define VSW_DEV_MACADDR 0x4 469e1ebb9ecSlm66018 #define VSW_MD_SMODE 0x8 4701ae08745Sheppo 4711ae08745Sheppo /* 4721ae08745Sheppo * vsw instance state information. 4731ae08745Sheppo */ 4741ae08745Sheppo typedef struct vsw { 4751ae08745Sheppo int instance; /* instance # */ 4761ae08745Sheppo dev_info_t *dip; /* associated dev_info */ 4771ae08745Sheppo struct vsw *next; /* next in list */ 4781ae08745Sheppo char physname[LIFNAMSIZ]; /* phys-dev */ 4791ae08745Sheppo uint8_t smode[NUM_SMODES]; /* switching mode */ 4801ae08745Sheppo int smode_idx; /* curr pos in smode array */ 481e1ebb9ecSlm66018 int smode_num; /* # of modes specified */ 4821ae08745Sheppo uint8_t mdprops; /* bitmask of props found */ 4831ae08745Sheppo vsw_port_list_t plist; /* associated ports */ 4841ae08745Sheppo ddi_taskq_t *taskq_p; /* VIO ctrl msg taskq */ 4851ae08745Sheppo mod_hash_t *fdb; /* forwarding database */ 4861ae08745Sheppo 4871ae08745Sheppo mod_hash_t *mfdb; /* multicast FDB */ 4881ae08745Sheppo krwlock_t mfdbrw; /* rwlock for mFDB */ 4891ae08745Sheppo 490d10e4ef2Snarayan vio_mblk_pool_t *rxh; /* Receive pool handle */ 491*34683adeSsg70180 void (*vsw_switch_frame) 492*34683adeSsg70180 (struct vsw *, mblk_t *, int, 493*34683adeSsg70180 vsw_port_t *, mac_resource_handle_t); 494d10e4ef2Snarayan 4951ae08745Sheppo /* mac layer */ 496*34683adeSsg70180 kmutex_t mac_lock; /* protect fields below */ 4971ae08745Sheppo mac_handle_t mh; 4981ae08745Sheppo mac_rx_handle_t mrh; 499e1ebb9ecSlm66018 multiaddress_capab_t maddr; /* Multiple uni addr capable */ 5001ae08745Sheppo const mac_txinfo_t *txinfo; /* MAC tx routine */ 5017636cb21Slm66018 boolean_t mstarted; /* Mac Started? */ 5027636cb21Slm66018 boolean_t mresources; /* Mac Resources cb? */ 5037636cb21Slm66018 5047636cb21Slm66018 /* 5057636cb21Slm66018 * MAC Ring Resources. 5067636cb21Slm66018 */ 5077636cb21Slm66018 kmutex_t mac_ring_lock; /* Lock for the table. */ 5087636cb21Slm66018 uint32_t mac_ring_tbl_sz; 5097636cb21Slm66018 vsw_mac_ring_t *mac_ring_tbl; /* Mac ring table. */ 5101ae08745Sheppo 511e1ebb9ecSlm66018 boolean_t recfg_reqd; /* Reconfig of addrs needed */ 512e1ebb9ecSlm66018 int promisc_cnt; 5131ae08745Sheppo 5141ae08745Sheppo /* Machine Description updates */ 5151ae08745Sheppo mdeg_node_spec_t *inst_spec; 5161ae08745Sheppo mdeg_handle_t mdeg_hdl; 517*34683adeSsg70180 mdeg_handle_t mdeg_port_hdl; 5181ae08745Sheppo 5191ae08745Sheppo /* if configured as an ethernet interface */ 520ba2e4443Sseb mac_handle_t if_mh; /* MAC handle */ 5211ae08745Sheppo struct ether_addr if_addr; /* interface address */ 5221ae08745Sheppo krwlock_t if_lockrw; 5231ae08745Sheppo uint8_t if_state; /* interface state */ 5241ae08745Sheppo 5251ae08745Sheppo /* multicast addresses when configured as eth interface */ 5261ae08745Sheppo kmutex_t mca_lock; /* multicast lock */ 5271ae08745Sheppo mcst_addr_t *mcap; /* list of multicast addrs */ 5281ae08745Sheppo } vsw_t; 5291ae08745Sheppo 5301ae08745Sheppo 5311ae08745Sheppo /* 5321ae08745Sheppo * Ethernet broadcast address definition. 5331ae08745Sheppo */ 5341ae08745Sheppo static struct ether_addr etherbroadcastaddr = { 5351ae08745Sheppo 0xff, 0xff, 0xff, 0xff, 0xff, 0xff 5361ae08745Sheppo }; 5371ae08745Sheppo 5381ae08745Sheppo #define IS_BROADCAST(ehp) \ 5391ae08745Sheppo (ether_cmp(&ehp->ether_dhost, ðerbroadcastaddr) == 0) 5401ae08745Sheppo #define IS_MULTICAST(ehp) \ 5411ae08745Sheppo ((ehp->ether_dhost.ether_addr_octet[0] & 01) == 1) 5421ae08745Sheppo 5431ae08745Sheppo #define READ_ENTER(x) rw_enter(x, RW_READER) 5441ae08745Sheppo #define WRITE_ENTER(x) rw_enter(x, RW_WRITER) 5451ae08745Sheppo #define RW_EXIT(x) rw_exit(x) 5461ae08745Sheppo 5471ae08745Sheppo #ifdef __cplusplus 5481ae08745Sheppo } 5491ae08745Sheppo #endif 5501ae08745Sheppo 5511ae08745Sheppo #endif /* _VSW_H */ 552