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 /* 23c1c61f44Ssb155480 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 241ae08745Sheppo * Use is subject to license terms. 251ae08745Sheppo */ 261ae08745Sheppo 271ae08745Sheppo #ifndef _VNET_H 281ae08745Sheppo #define _VNET_H 291ae08745Sheppo 301ae08745Sheppo #ifdef __cplusplus 311ae08745Sheppo extern "C" { 321ae08745Sheppo #endif 331ae08745Sheppo 34678453a8Sspeer #include <sys/vnet_res.h> 35678453a8Sspeer #include <sys/vnet_mailbox.h> 363fd94f8cSam223141 #include <sys/modhash.h> 37678453a8Sspeer 381ae08745Sheppo #define VNET_SUCCESS (0) /* successful return */ 391ae08745Sheppo #define VNET_FAILURE (-1) /* unsuccessful return */ 401ae08745Sheppo 411ae08745Sheppo #define KMEM_FREE(_p) kmem_free((_p), sizeof (*(_p))) 421ae08745Sheppo 431ae08745Sheppo #define VNET_NTXDS 512 /* power of 2 tx descriptors */ 441ae08745Sheppo #define VNET_LDCWD_INTERVAL 1000 /* watchdog freq in msec */ 451ae08745Sheppo #define VNET_LDCWD_TXTIMEOUT 1000 /* tx timeout in msec */ 46e1ebb9ecSlm66018 #define VNET_LDC_MTU 64 /* ldc mtu */ 471ae08745Sheppo 48678453a8Sspeer 49678453a8Sspeer #define IS_BROADCAST(ehp) \ 50678453a8Sspeer (ether_cmp(&ehp->ether_dhost, ðerbroadcastaddr) == 0) 51678453a8Sspeer #define IS_MULTICAST(ehp) \ 52678453a8Sspeer ((ehp->ether_dhost.ether_addr_octet[0] & 01) == 1) 53678453a8Sspeer 54678453a8Sspeer #define VNET_MATCH_RES(vresp, vnetp) \ 55678453a8Sspeer (ether_cmp(vresp->local_macaddr, vnetp->curr_macaddr) == 0) 56c1c61f44Ssb155480 571ae08745Sheppo /* 58678453a8Sspeer * A vnet resource structure. 591ae08745Sheppo */ 60678453a8Sspeer typedef struct vnet_res { 61678453a8Sspeer struct vnet_res *nextp; /* next resource in the list */ 62678453a8Sspeer mac_register_t macreg; /* resource's mac_reg */ 63678453a8Sspeer vio_net_res_type_t type; /* resource type */ 64678453a8Sspeer ether_addr_t local_macaddr; /* resource's macaddr */ 65678453a8Sspeer ether_addr_t rem_macaddr; /* resource's remote macaddr */ 66678453a8Sspeer uint32_t flags; /* resource flags */ 67c1c61f44Ssb155480 uint32_t refcnt; /* reference count */ 68678453a8Sspeer struct vnet *vnetp; /* back pointer to vnet */ 69678453a8Sspeer } vnet_res_t; 70678453a8Sspeer 71678453a8Sspeer #define VNET_DDS_TASK_ADD_SHARE 0x01 72678453a8Sspeer #define VNET_DDS_TASK_DEL_SHARE 0x02 73678453a8Sspeer #define VNET_DDS_TASK_REL_SHARE 0x04 74678453a8Sspeer 75678453a8Sspeer /* An instance specific DDS structure */ 76678453a8Sspeer typedef struct vnet_dds_info { 77678453a8Sspeer kmutex_t lock; /* lock for this structure */ 78678453a8Sspeer uint8_t task_flags; /* flags for taskq */ 79678453a8Sspeer uint8_t dds_req_id; /* DDS message request id */ 80678453a8Sspeer vio_dds_msg_t dmsg; /* Pending DDS message */ 81678453a8Sspeer dev_info_t *hio_dip; /* Hybrid device's dip */ 82678453a8Sspeer uint64_t hio_cookie; /* Hybrid device's cookie */ 83678453a8Sspeer ddi_taskq_t *dds_taskqp; /* Taskq's used for DDS */ 84678453a8Sspeer struct vnet *vnetp; /* Back pointer to vnetp */ 85678453a8Sspeer } vnet_dds_info_t; 861ae08745Sheppo 87c1c61f44Ssb155480 #define VNET_NFDB_HASH 64 881ae08745Sheppo 89c1c61f44Ssb155480 #define KEY_HASH(key, addr) \ 90678453a8Sspeer (key = (((uint64_t)(addr[0])) << 40) | \ 91678453a8Sspeer (((uint64_t)(addr[1])) << 32) | \ 92678453a8Sspeer (((uint64_t)(addr[2])) << 24) | \ 93678453a8Sspeer (((uint64_t)(addr[3])) << 16) | \ 94678453a8Sspeer (((uint64_t)(addr[4])) << 8) | \ 95678453a8Sspeer ((uint64_t)(addr[5]))); 96678453a8Sspeer 971ae08745Sheppo 981ae08745Sheppo /* rwlock macros */ 991ae08745Sheppo #define READ_ENTER(x) rw_enter(x, RW_READER) 1001ae08745Sheppo #define WRITE_ENTER(x) rw_enter(x, RW_WRITER) 1011ae08745Sheppo #define RW_EXIT(x) rw_exit(x) 1021ae08745Sheppo 103c1c61f44Ssb155480 #define VLAN_ID_KEY(key) ((mod_hash_key_t)(uintptr_t)(key)) 104c1c61f44Ssb155480 1051ae08745Sheppo /* 1061ae08745Sheppo * vnet instance state information 1071ae08745Sheppo */ 1081ae08745Sheppo typedef struct vnet { 1091ae08745Sheppo int instance; /* instance # */ 1101ae08745Sheppo dev_info_t *dip; /* dev_info */ 111678453a8Sspeer uint64_t reg; /* reg prop value */ 1121ae08745Sheppo struct vnet *nextp; /* next in list */ 113ba2e4443Sseb mac_handle_t mh; /* handle to GLDv3 mac module */ 1141ae08745Sheppo uchar_t vendor_addr[ETHERADDRL]; /* orig macadr */ 1151ae08745Sheppo uchar_t curr_macaddr[ETHERADDRL]; /* current macadr */ 116678453a8Sspeer void *vgenhdl; /* Handle for vgen */ 117c1c61f44Ssb155480 118c1c61f44Ssb155480 uint32_t fdb_nchains; /* # of hash chains in fdbtbl */ 119c1c61f44Ssb155480 mod_hash_t *fdb_hashp; /* forwarding database */ 120678453a8Sspeer vnet_res_t *vsw_fp; /* cached fdb entry of vsw */ 121c1c61f44Ssb155480 krwlock_t vsw_fp_rw; /* lock to protect vsw_fp */ 122*7b1f684aSSriharsha Basavapatna uint32_t mtu; /* mtu of the device */ 123c1c61f44Ssb155480 124c1c61f44Ssb155480 uint16_t default_vlan_id; /* default vlan id */ 125c1c61f44Ssb155480 uint16_t pvid; /* port vlan id (untagged) */ 126c1c61f44Ssb155480 uint16_t *vids; /* vlan ids (tagged) */ 127c1c61f44Ssb155480 uint16_t nvids; /* # of vids */ 128678453a8Sspeer 129678453a8Sspeer uint32_t flags; /* interface flags */ 130678453a8Sspeer vnet_res_t *hio_fp; /* Hybrid IO resource */ 131678453a8Sspeer vnet_res_t *vres_list; /* Resource list */ 132678453a8Sspeer vnet_dds_info_t vdds_info; /* DDS related info */ 133678453a8Sspeer krwlock_t vrwlock; /* Resource list lock */ 134678453a8Sspeer ddi_taskq_t *taskqp; /* Resource taskq */ 1351ae08745Sheppo } vnet_t; 1361ae08745Sheppo 137678453a8Sspeer #define VNET_STARTED 0x01 138678453a8Sspeer 139844e62a3Sraghuram #ifdef DEBUG 140844e62a3Sraghuram /* 141844e62a3Sraghuram * debug levels: 142844e62a3Sraghuram * DBG_LEVEL1: Function entry/exit tracing 143844e62a3Sraghuram * DBG_LEVEL2: Info messages 144844e62a3Sraghuram * DBG_LEVEL3: Warning messages 145844e62a3Sraghuram * DBG_LEVEL4: Error messages 146844e62a3Sraghuram */ 147844e62a3Sraghuram 148844e62a3Sraghuram enum { DBG_LEVEL1 = 0x01, DBG_LEVEL2 = 0x02, DBG_WARN = 0x04, 149844e62a3Sraghuram DBG_ERR = 0x08 }; 150844e62a3Sraghuram 151844e62a3Sraghuram #define DBG1(...) do { \ 152844e62a3Sraghuram if ((vnet_dbglevel & DBG_LEVEL1) != 0) { \ 153844e62a3Sraghuram debug_printf(__func__, __VA_ARGS__); \ 154844e62a3Sraghuram } \ 155844e62a3Sraghuram _NOTE(CONSTCOND) } while (0) 156844e62a3Sraghuram 157844e62a3Sraghuram #define DBG2(...) do { \ 158844e62a3Sraghuram if ((vnet_dbglevel & DBG_LEVEL2) != 0) { \ 159844e62a3Sraghuram debug_printf(__func__, __VA_ARGS__); \ 160844e62a3Sraghuram } \ 161844e62a3Sraghuram _NOTE(CONSTCOND) } while (0) 162844e62a3Sraghuram 163844e62a3Sraghuram #define DWARN(...) do { \ 164844e62a3Sraghuram if ((vnet_dbglevel & DBG_WARN) != 0) { \ 165844e62a3Sraghuram debug_printf(__func__, __VA_ARGS__); \ 166844e62a3Sraghuram } \ 167844e62a3Sraghuram _NOTE(CONSTCOND) } while (0) 168844e62a3Sraghuram 169844e62a3Sraghuram #define DERR(...) do { \ 170844e62a3Sraghuram if ((vnet_dbglevel & DBG_ERR) != 0) { \ 171844e62a3Sraghuram debug_printf(__func__, __VA_ARGS__); \ 172844e62a3Sraghuram } \ 173844e62a3Sraghuram _NOTE(CONSTCOND) } while (0) 174844e62a3Sraghuram 175844e62a3Sraghuram #else 176844e62a3Sraghuram 177844e62a3Sraghuram #define DBG1(...) if (0) do { } while (0) 178844e62a3Sraghuram #define DBG2(...) if (0) do { } while (0) 179844e62a3Sraghuram #define DWARN(...) if (0) do { } while (0) 180844e62a3Sraghuram #define DERR(...) if (0) do { } while (0) 181844e62a3Sraghuram 182844e62a3Sraghuram #endif 183844e62a3Sraghuram 1841ae08745Sheppo #ifdef __cplusplus 1851ae08745Sheppo } 1861ae08745Sheppo #endif 1871ae08745Sheppo 1881ae08745Sheppo #endif /* _VNET_H */ 189