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