1da14cebeSEric Cheng /* 2da14cebeSEric Cheng * CDDL HEADER START 3da14cebeSEric Cheng * 4da14cebeSEric Cheng * The contents of this file are subject to the terms of the 5da14cebeSEric Cheng * Common Development and Distribution License (the "License"). 6da14cebeSEric Cheng * You may not use this file except in compliance with the License. 7da14cebeSEric Cheng * 8da14cebeSEric Cheng * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9da14cebeSEric Cheng * or http://www.opensolaris.org/os/licensing. 10da14cebeSEric Cheng * See the License for the specific language governing permissions 11da14cebeSEric Cheng * and limitations under the License. 12da14cebeSEric Cheng * 13da14cebeSEric Cheng * When distributing Covered Code, include this CDDL HEADER in each 14da14cebeSEric Cheng * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15da14cebeSEric Cheng * If applicable, add the following below this CDDL HEADER, with the 16da14cebeSEric Cheng * fields enclosed by brackets "[]" replaced with your own identifying 17da14cebeSEric Cheng * information: Portions Copyright [yyyy] [name of copyright owner] 18da14cebeSEric Cheng * 19da14cebeSEric Cheng * CDDL HEADER END 20da14cebeSEric Cheng */ 21da14cebeSEric Cheng /* 22ae6aa22aSVenugopal Iyer * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23da14cebeSEric Cheng * Use is subject to license terms. 24da14cebeSEric Cheng */ 25da14cebeSEric Cheng 26da14cebeSEric Cheng #ifndef _SYS_MAC_CLIENT_IMPL_H 27da14cebeSEric Cheng #define _SYS_MAC_CLIENT_IMPL_H 28da14cebeSEric Cheng 29da14cebeSEric Cheng #include <sys/modhash.h> 30da14cebeSEric Cheng #include <sys/mac_client.h> 31da14cebeSEric Cheng #include <sys/mac_provider.h> 32da14cebeSEric Cheng #include <sys/mac.h> 33da14cebeSEric Cheng #include <sys/mac_impl.h> 34da14cebeSEric Cheng #include <net/if.h> 35da14cebeSEric Cheng #include <sys/mac_flow_impl.h> 36da14cebeSEric Cheng 37da14cebeSEric Cheng #ifdef __cplusplus 38da14cebeSEric Cheng extern "C" { 39da14cebeSEric Cheng #endif 40da14cebeSEric Cheng 41da14cebeSEric Cheng extern kmem_cache_t *mac_client_impl_cache; 42da14cebeSEric Cheng extern kmem_cache_t *mac_unicast_impl_cache; 43da14cebeSEric Cheng extern kmem_cache_t *mac_promisc_impl_cache; 44da14cebeSEric Cheng 45da14cebeSEric Cheng /* 46da14cebeSEric Cheng * Need a list to chain all VIDs assigned to a client. Normally, one 47da14cebeSEric Cheng * MAC client only has one VID. But vsw might need multiple VIDs. 48da14cebeSEric Cheng */ 49da14cebeSEric Cheng typedef struct mac_unicast_impl_s { /* Protected by */ 50da14cebeSEric Cheng struct mac_unicast_impl_s *mui_next; /* SL */ 51da14cebeSEric Cheng mac_address_t *mui_map; /* SL */ 52da14cebeSEric Cheng uint16_t mui_vid; /* SL */ 53da14cebeSEric Cheng } mac_unicast_impl_t; 54da14cebeSEric Cheng 55da14cebeSEric Cheng #define MAC_CLIENT_FLAGS_PRIMARY 0X0001 56da14cebeSEric Cheng #define MAC_CLIENT_FLAGS_VNIC_PRIMARY 0x0002 57*fc4e975dSVenugopal Iyer #define MAC_CLIENT_FLAGS_MULTI_PRIMARY 0x0004 58*fc4e975dSVenugopal Iyer #define MAC_CLIENT_FLAGS_PASSIVE_PRIMARY 0x0008 59da14cebeSEric Cheng 60da14cebeSEric Cheng /* 61da14cebeSEric Cheng * One of these is instantiated per MAC client promiscuous callback. 62da14cebeSEric Cheng * 63da14cebeSEric Cheng * Each element of this structure belongs to two linked list. One 64da14cebeSEric Cheng * for the mac_client_impl_t (mci_promisc_list) which created allocated 65da14cebeSEric Cheng * the callback, the other for the mac_impl_t (mi_promisc_list) corresponding 66da14cebeSEric Cheng * to the MAC client. 67da14cebeSEric Cheng * The former allows us to do bookkeeping, the latter allows us 68da14cebeSEric Cheng * to more efficiently dispatch packets to the promiscuous callbacks. 69da14cebeSEric Cheng */ 70da14cebeSEric Cheng typedef struct mac_promisc_impl_s { /* Protected by */ 71da14cebeSEric Cheng mac_cb_t mpi_mci_link; /* mi_promisc_lock */ 72da14cebeSEric Cheng mac_cb_t mpi_mi_link; /* mi_promisc_lock */ 73da14cebeSEric Cheng mac_client_promisc_type_t mpi_type; /* WO */ 74da14cebeSEric Cheng mac_rx_t mpi_fn; /* WO */ 75da14cebeSEric Cheng void *mpi_arg; /* WO */ 76da14cebeSEric Cheng struct mac_client_impl_s *mpi_mcip; /* WO */ 77da14cebeSEric Cheng boolean_t mpi_no_tx_loop; /* WO */ 78da14cebeSEric Cheng boolean_t mpi_no_phys; /* WO */ 79ae6aa22aSVenugopal Iyer boolean_t mpi_strip_vlan_tag; /* WO */ 80da14cebeSEric Cheng } mac_promisc_impl_t; 81da14cebeSEric Cheng 82da14cebeSEric Cheng typedef union mac_tx_percpu_s { 83da14cebeSEric Cheng struct { 84da14cebeSEric Cheng kmutex_t _pcpu_tx_lock; 85da14cebeSEric Cheng uint_t _pcpu_tx_refcnt; 86da14cebeSEric Cheng } pcpu_lr; 87da14cebeSEric Cheng uchar_t pcpu_pad[64]; 88da14cebeSEric Cheng } mac_tx_percpu_t; 89da14cebeSEric Cheng 90da14cebeSEric Cheng #define pcpu_tx_lock pcpu_lr._pcpu_tx_lock 91da14cebeSEric Cheng #define pcpu_tx_refcnt pcpu_lr._pcpu_tx_refcnt 92da14cebeSEric Cheng 93da14cebeSEric Cheng /* 94da14cebeSEric Cheng * One of these is instanciated for each MAC client. 95da14cebeSEric Cheng */ 96da14cebeSEric Cheng struct mac_client_impl_s { /* Protected by */ 97da14cebeSEric Cheng struct mac_client_impl_s *mci_client_next; /* mi_rw_lock */ 98da14cebeSEric Cheng char mci_name[MAXNAMELEN]; /* mi_rw_lock */ 99da14cebeSEric Cheng /* 100da14cebeSEric Cheng * This flow entry will contain all the internal constructs 101da14cebeSEric Cheng * such as SRS etc. for this MAC client. The MAC client may 102da14cebeSEric Cheng * have more than one flow corresponding to each upper client 103da14cebeSEric Cheng * sharing this mac_client_impl_t. 104da14cebeSEric Cheng */ 105da14cebeSEric Cheng flow_entry_t *mci_flent; /* mi_rw_lock */ 106da14cebeSEric Cheng struct mac_impl_s *mci_mip; /* WO */ 107da14cebeSEric Cheng /* 108da14cebeSEric Cheng * If this is a client that has a pass thru MAC (e.g. a VNIC), 109da14cebeSEric Cheng * then we also keep the handle for the client's upper MAC. 110da14cebeSEric Cheng */ 111da14cebeSEric Cheng struct mac_impl_s *mci_upper_mip; /* WO */ 112da14cebeSEric Cheng 113da14cebeSEric Cheng uint32_t mci_state_flags; /* WO */ 114da14cebeSEric Cheng mac_rx_t mci_rx_fn; /* Rx Quiescence */ 115da14cebeSEric Cheng void *mci_rx_arg; /* Rx Quiescence */ 116da14cebeSEric Cheng mac_direct_rx_t mci_direct_rx_fn; /* SL */ 117da14cebeSEric Cheng void *mci_direct_rx_arg; /* SL */ 118*fc4e975dSVenugopal Iyer mac_rx_t mci_rx_p_fn; /* Rx Quiescence */ 119*fc4e975dSVenugopal Iyer void *mci_rx_p_arg; /* Rx Quiescence */ 120*fc4e975dSVenugopal Iyer void *mci_p_unicast_list; 121da14cebeSEric Cheng 122da14cebeSEric Cheng mac_cb_t *mci_promisc_list; /* mi_promisc_lock */ 123da14cebeSEric Cheng 124da14cebeSEric Cheng mac_address_t *mci_unicast; 125da14cebeSEric Cheng uint32_t mci_flags; /* SL */ 126da14cebeSEric Cheng krwlock_t mci_rw_lock; 127da14cebeSEric Cheng mac_unicast_impl_t *mci_unicast_list; /* mci_rw_lock */ 128da14cebeSEric Cheng /* 129da14cebeSEric Cheng * The mac_client_impl_t may be shared by multiple clients, i.e 130da14cebeSEric Cheng * multiple VLANs sharing the same MAC client. In this case the 131da14cebeSEric Cheng * address/vid tubles differ and are each associated with their 132da14cebeSEric Cheng * own flow entry, but the rest underlying components SRS, etc, 133da14cebeSEric Cheng * are common. 134da14cebeSEric Cheng */ 135da14cebeSEric Cheng flow_entry_t *mci_flent_list; /* mci_rw_lock */ 136da14cebeSEric Cheng uint_t mci_nflents; /* mci_rw_lock */ 137da14cebeSEric Cheng uint_t mci_nvids; /* mci_rw_lock */ 138da14cebeSEric Cheng 139da14cebeSEric Cheng /* Resource Management Functions */ 140da14cebeSEric Cheng mac_resource_add_t mci_resource_add; /* SL */ 141da14cebeSEric Cheng mac_resource_remove_t mci_resource_remove; /* SL */ 142da14cebeSEric Cheng mac_resource_quiesce_t mci_resource_quiesce; /* SL */ 143da14cebeSEric Cheng mac_resource_restart_t mci_resource_restart; /* SL */ 144da14cebeSEric Cheng mac_resource_bind_t mci_resource_bind; /* SL */ 145da14cebeSEric Cheng void *mci_resource_arg; /* SL */ 146da14cebeSEric Cheng 147da14cebeSEric Cheng 148da14cebeSEric Cheng /* Tx notify callback */ 149da14cebeSEric Cheng kmutex_t mci_tx_cb_lock; 150da14cebeSEric Cheng mac_cb_info_t mci_tx_notify_cb_info; /* cb list info */ 151da14cebeSEric Cheng mac_cb_t *mci_tx_notify_cb_list; /* The cb list */ 152da14cebeSEric Cheng uintptr_t mci_tx_notify_id; 153da14cebeSEric Cheng 154da14cebeSEric Cheng /* per MAC client stats */ /* None */ 155da14cebeSEric Cheng uint64_t mci_stat_multircv; 156da14cebeSEric Cheng uint64_t mci_stat_brdcstrcv; 157da14cebeSEric Cheng uint64_t mci_stat_multixmt; 158da14cebeSEric Cheng uint64_t mci_stat_brdcstxmt; 159da14cebeSEric Cheng uint64_t mci_stat_obytes; 160da14cebeSEric Cheng uint64_t mci_stat_opackets; 161da14cebeSEric Cheng uint64_t mci_stat_oerrors; 162da14cebeSEric Cheng uint64_t mci_stat_ibytes; 163da14cebeSEric Cheng uint64_t mci_stat_ipackets; 164da14cebeSEric Cheng uint64_t mci_stat_ierrors; 165da14cebeSEric Cheng 166da14cebeSEric Cheng flow_tab_t *mci_subflow_tab; /* Rx quiescence */ 167da14cebeSEric Cheng 168da14cebeSEric Cheng /* 169da14cebeSEric Cheng * Priority range for this MAC client. This the range 170da14cebeSEric Cheng * corresponding to the priority configured (nr_flow_priority). 171da14cebeSEric Cheng */ 172da14cebeSEric Cheng pri_t mci_min_pri; 173da14cebeSEric Cheng pri_t mci_max_pri; 174da14cebeSEric Cheng 175da14cebeSEric Cheng /* 176da14cebeSEric Cheng * Hybrid I/O related definitions. 177da14cebeSEric Cheng */ 178da14cebeSEric Cheng mac_share_handle_t mci_share; 179da14cebeSEric Cheng 180da14cebeSEric Cheng /* for multicast support */ 181da14cebeSEric Cheng struct mac_mcast_addrs_s *mci_mcast_addrs; /* mi_rw_lock */ 182da14cebeSEric Cheng 183da14cebeSEric Cheng /* 184da14cebeSEric Cheng * Protected by mci_tx_pcpu[0].pcpu_tx_lock 185da14cebeSEric Cheng */ 186da14cebeSEric Cheng uint_t mci_tx_flag; 187da14cebeSEric Cheng kcondvar_t mci_tx_cv; 188da14cebeSEric Cheng 189da14cebeSEric Cheng /* Must be last in the structure for dynamic sizing */ 190da14cebeSEric Cheng mac_tx_percpu_t mci_tx_pcpu[1]; /* SL */ 191da14cebeSEric Cheng }; 192da14cebeSEric Cheng 193da14cebeSEric Cheng #define MAC_CLIENT_IMPL_SIZE \ 194da14cebeSEric Cheng (sizeof (mac_client_impl_t) + \ 195da14cebeSEric Cheng (mac_tx_percpu_cnt * sizeof (mac_tx_percpu_t))) 196da14cebeSEric Cheng 197da14cebeSEric Cheng extern int mac_tx_percpu_cnt; 198da14cebeSEric Cheng 199da14cebeSEric Cheng #define MCIP_TX_SRS(mcip) \ 200da14cebeSEric Cheng ((mcip)->mci_flent == NULL ? NULL : (mcip)->mci_flent->fe_tx_srs) 201da14cebeSEric Cheng 202da14cebeSEric Cheng /* Defensive coding, non-null mcip_flent could be an assert */ 203da14cebeSEric Cheng 204da14cebeSEric Cheng #define MCIP_DATAPATH_SETUP(mcip) \ 205da14cebeSEric Cheng ((mcip)->mci_flent == NULL ? B_FALSE : \ 206da14cebeSEric Cheng !((mcip)->mci_flent->fe_flags & FE_MC_NO_DATAPATH)) 207da14cebeSEric Cheng 208da14cebeSEric Cheng #define MCIP_RESOURCE_PROPS(mcip) \ 209da14cebeSEric Cheng ((mcip)->mci_flent == NULL ? NULL : \ 210da14cebeSEric Cheng &(mcip)->mci_flent->fe_resource_props) 211da14cebeSEric Cheng 212da14cebeSEric Cheng #define MCIP_EFFECTIVE_PROPS(mcip) \ 213da14cebeSEric Cheng (mcip->mci_flent == NULL ? NULL : \ 214da14cebeSEric Cheng &(mcip)->mci_flent->fe_effective_props) 215da14cebeSEric Cheng 216da14cebeSEric Cheng #define MCIP_RESOURCE_PROPS_MASK(mcip) \ 217da14cebeSEric Cheng ((mcip)->mci_flent == NULL ? 0 : \ 218da14cebeSEric Cheng (mcip)->mci_flent->fe_resource_props.mrp_mask) 219da14cebeSEric Cheng 220da14cebeSEric Cheng #define MCIP_RESOURCE_PROPS_MAXBW(mcip) \ 221da14cebeSEric Cheng ((mcip)->mci_flent == NULL ? 0 : \ 222da14cebeSEric Cheng (mcip)->mci_flent->fe_resource_props.mrp_maxbw) 223da14cebeSEric Cheng 224da14cebeSEric Cheng #define MCIP_RESOURCE_PROPS_PRIORITY(mcip) \ 225da14cebeSEric Cheng ((mcip)->mci_flent == NULL ? 0 : \ 226da14cebeSEric Cheng (mcip)->mci_flent->fe_resource_props.mrp_priority) 227da14cebeSEric Cheng 228da14cebeSEric Cheng #define MCIP_RESOURCE_PROPS_CPUS(mcip) \ 229da14cebeSEric Cheng ((mcip)->mci_flent == NULL ? 0 : \ 230da14cebeSEric Cheng &(mcip)->mci_flent->fe_resource_props.mrp_cpus) 231da14cebeSEric Cheng 232da14cebeSEric Cheng #define MCIP_RESOURCE_PROPS_NCPUS(mcip) \ 233da14cebeSEric Cheng ((mcip)->mci_flent == NULL ? 0 : \ 234da14cebeSEric Cheng (mcip)->mci_flent->fe_resource_props.mrp_ncpus) 235da14cebeSEric Cheng 236da14cebeSEric Cheng #define MCIP_RESOURCE_PROPS_CPU(mcip) \ 237da14cebeSEric Cheng ((mcip)->mci_flent == NULL ? 0 : \ 238da14cebeSEric Cheng (mcip)->mci_flent->fe_resource_props.mrp_ncpu) 239da14cebeSEric Cheng 240da14cebeSEric Cheng /* 241da14cebeSEric Cheng * We validate the VLAN id of the packet w.r.t the client's vid, 242da14cebeSEric Cheng * if required (i.e. !MCIS_DISABLE_TX_VID_CHECK). DLS clients 243da14cebeSEric Cheng * will have MCIS_DISABLE_TX_VID_CHECK set. 244da14cebeSEric Cheng * (In the case of aggr when we get back packets, due to 245da14cebeSEric Cheng * the underlying driver being flow controlled, we won't 246da14cebeSEric Cheng * drop the packet even if it is VLAN tagged as we 247da14cebeSEric Cheng * don't set MCIS_DISABLE_TX_VID_CHECK for an aggr.) 248da14cebeSEric Cheng */ 249da14cebeSEric Cheng #define MAC_VID_CHECK_NEEDED(mcip) \ 250da14cebeSEric Cheng (((mcip)->mci_state_flags & MCIS_DISABLE_TX_VID_CHECK) == 0 && \ 251da14cebeSEric Cheng (mcip)->mci_mip->mi_info.mi_nativemedia == DL_ETHER) 252da14cebeSEric Cheng 253da14cebeSEric Cheng #define MAC_VID_CHECK(mcip, mp, err) { \ 254da14cebeSEric Cheng if (ntohs(((struct ether_header *)(mp)->b_rptr)->ether_type) == \ 255da14cebeSEric Cheng ETHERTYPE_VLAN) { \ 256da14cebeSEric Cheng /* \ 257da14cebeSEric Cheng * err is set to EINVAL (so the caller can take the \ 258da14cebeSEric Cheng * appropriate action. e.g. freemsg()) for two cases: \ 259da14cebeSEric Cheng * -client is not responsible for filling in the vid. \ 260da14cebeSEric Cheng * -client is responsible for filling in the vid, but \ 261da14cebeSEric Cheng * the vid doesn't match the vid of the MAC client. \ 262da14cebeSEric Cheng */ \ 263da14cebeSEric Cheng (err) = EINVAL; \ 264da14cebeSEric Cheng if (((mcip)->mci_state_flags & MCIS_TAG_DISABLE) != 0) {\ 265da14cebeSEric Cheng struct ether_vlan_header *evhp; \ 266da14cebeSEric Cheng uint16_t vlanid; \ 267da14cebeSEric Cheng \ 268da14cebeSEric Cheng evhp = (struct ether_vlan_header *)(mp)->b_rptr;\ 269da14cebeSEric Cheng vlanid = VLAN_ID(ntohs(evhp->ether_tci)); \ 270da14cebeSEric Cheng if (mac_client_check_flow_vid((mcip), vlanid)) \ 271da14cebeSEric Cheng (err) = 0; \ 272da14cebeSEric Cheng } \ 273da14cebeSEric Cheng } \ 274da14cebeSEric Cheng } 275da14cebeSEric Cheng 276da14cebeSEric Cheng #define MAC_TAG_NEEDED(mcip) \ 277da14cebeSEric Cheng (((mcip)->mci_state_flags & MCIS_TAG_DISABLE) == 0 && \ 278da14cebeSEric Cheng (mcip)->mci_nvids == 1) \ 279da14cebeSEric Cheng 280da14cebeSEric Cheng /* MCI state flags */ 281da14cebeSEric Cheng #define MCIS_IS_VNIC 0x0001 282da14cebeSEric Cheng #define MCIS_EXCLUSIVE 0x0002 283da14cebeSEric Cheng #define MCIS_TAG_DISABLE 0x0004 284da14cebeSEric Cheng #define MCIS_STRIP_DISABLE 0x0008 285da14cebeSEric Cheng #define MCIS_IS_AGGR_PORT 0x0010 286da14cebeSEric Cheng #define MCIS_CLIENT_POLL_CAPABLE 0x0020 287da14cebeSEric Cheng #define MCIS_DESC_LOGGED 0x0040 288da14cebeSEric Cheng #define MCIS_SHARE_BOUND 0x0080 289da14cebeSEric Cheng #define MCIS_NO_HWRINGS 0x0100 290da14cebeSEric Cheng #define MCIS_DISABLE_TX_VID_CHECK 0x0200 291da14cebeSEric Cheng #define MCIS_USE_DATALINK_NAME 0x0400 29208ac1c49SNicolas Droux #define MCIS_UNICAST_HW 0x0800 29308ac1c49SNicolas Droux #define MCIS_REQ_HWRINGS 0x1000 294da14cebeSEric Cheng 295da14cebeSEric Cheng /* in mac_client.c */ 296da14cebeSEric Cheng extern void mac_promisc_client_dispatch(mac_client_impl_t *, mblk_t *); 297da14cebeSEric Cheng extern void mac_client_init(void); 298da14cebeSEric Cheng extern void mac_client_fini(void); 299da14cebeSEric Cheng extern void mac_promisc_dispatch(mac_impl_t *, mblk_t *, 300da14cebeSEric Cheng mac_client_impl_t *); 301da14cebeSEric Cheng 302da14cebeSEric Cheng extern int mac_validate_props(mac_resource_props_t *); 303da14cebeSEric Cheng 304da14cebeSEric Cheng extern mac_client_impl_t *mac_vnic_lower(mac_impl_t *); 305da14cebeSEric Cheng extern mac_client_impl_t *mac_primary_client_handle(mac_impl_t *); 306da14cebeSEric Cheng extern uint16_t i_mac_flow_vid(flow_entry_t *); 307da14cebeSEric Cheng extern boolean_t i_mac_capab_get(mac_handle_t, mac_capab_t, void *); 308da14cebeSEric Cheng 309da14cebeSEric Cheng extern void mac_unicast_update_clients(mac_impl_t *, mac_address_t *); 310da14cebeSEric Cheng extern void mac_update_resources(mac_resource_props_t *, 311da14cebeSEric Cheng mac_resource_props_t *, boolean_t); 312da14cebeSEric Cheng 313da14cebeSEric Cheng boolean_t mac_client_check_flow_vid(mac_client_impl_t *, uint16_t); 314da14cebeSEric Cheng 315da14cebeSEric Cheng extern boolean_t mac_is_primary_client(mac_client_impl_t *); 316da14cebeSEric Cheng 317da14cebeSEric Cheng #ifdef __cplusplus 318da14cebeSEric Cheng } 319da14cebeSEric Cheng #endif 320da14cebeSEric Cheng 321da14cebeSEric Cheng #endif /* _SYS_MAC_CLIENT_IMPL_H */ 322