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 22da14cebeSEric Cheng /* 230591ddd0SPrakash Jalan * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. 2484de666eSRyan Zezeski * Copyright 2018 Joyent, Inc. 258241ccbbSDan McDonald * Copyright 2017 OmniTI Computer Consulting, Inc. All rights reserved. 26da14cebeSEric Cheng */ 27da14cebeSEric Cheng 28da14cebeSEric Cheng #include <sys/types.h> 29da14cebeSEric Cheng #include <sys/conf.h> 30da14cebeSEric Cheng #include <sys/id_space.h> 31da14cebeSEric Cheng #include <sys/esunddi.h> 32da14cebeSEric Cheng #include <sys/stat.h> 33da14cebeSEric Cheng #include <sys/mkdev.h> 34da14cebeSEric Cheng #include <sys/stream.h> 35da14cebeSEric Cheng #include <sys/strsubr.h> 36da14cebeSEric Cheng #include <sys/dlpi.h> 37da14cebeSEric Cheng #include <sys/modhash.h> 38da14cebeSEric Cheng #include <sys/mac.h> 39da14cebeSEric Cheng #include <sys/mac_provider.h> 40da14cebeSEric Cheng #include <sys/mac_impl.h> 41da14cebeSEric Cheng #include <sys/mac_client_impl.h> 42da14cebeSEric Cheng #include <sys/mac_client_priv.h> 43da14cebeSEric Cheng #include <sys/mac_soft_ring.h> 440dc2366fSVenugopal Iyer #include <sys/mac_stat.h> 4561af1958SGarrett D'Amore #include <sys/dld.h> 46da14cebeSEric Cheng #include <sys/modctl.h> 47da14cebeSEric Cheng #include <sys/fs/dv_node.h> 48da14cebeSEric Cheng #include <sys/thread.h> 49da14cebeSEric Cheng #include <sys/proc.h> 50da14cebeSEric Cheng #include <sys/callb.h> 51da14cebeSEric Cheng #include <sys/cpuvar.h> 52da14cebeSEric Cheng #include <sys/atomic.h> 53da14cebeSEric Cheng #include <sys/sdt.h> 54da14cebeSEric Cheng #include <sys/mac_flow.h> 55da14cebeSEric Cheng #include <sys/ddi_intr_impl.h> 56da14cebeSEric Cheng #include <sys/disp.h> 57da14cebeSEric Cheng #include <sys/sdt.h> 580dc2366fSVenugopal Iyer #include <sys/pattr.h> 590dc2366fSVenugopal Iyer #include <sys/strsun.h> 6084de666eSRyan Zezeski #include <sys/vlan.h> 61*d240edafSRobert Mustacchi #include <inet/ip.h> 62*d240edafSRobert Mustacchi #include <inet/tcp.h> 63*d240edafSRobert Mustacchi #include <netinet/udp.h> 64*d240edafSRobert Mustacchi #include <netinet/sctp.h> 65da14cebeSEric Cheng 66da14cebeSEric Cheng /* 67da14cebeSEric Cheng * MAC Provider Interface. 68da14cebeSEric Cheng * 69da14cebeSEric Cheng * Interface for GLDv3 compatible NIC drivers. 70da14cebeSEric Cheng */ 71da14cebeSEric Cheng 72da14cebeSEric Cheng static void i_mac_notify_thread(void *); 73da14cebeSEric Cheng 74da14cebeSEric Cheng typedef void (*mac_notify_default_cb_fn_t)(mac_impl_t *); 75da14cebeSEric Cheng 764eaa4710SRishi Srivatsavai static const mac_notify_default_cb_fn_t mac_notify_cb_list[MAC_NNOTE] = { 774eaa4710SRishi Srivatsavai mac_fanout_recompute, /* MAC_NOTE_LINK */ 784eaa4710SRishi Srivatsavai NULL, /* MAC_NOTE_UNICST */ 794eaa4710SRishi Srivatsavai NULL, /* MAC_NOTE_TX */ 804eaa4710SRishi Srivatsavai NULL, /* MAC_NOTE_DEVPROMISC */ 814eaa4710SRishi Srivatsavai NULL, /* MAC_NOTE_FASTPATH_FLUSH */ 824eaa4710SRishi Srivatsavai NULL, /* MAC_NOTE_SDU_SIZE */ 834eaa4710SRishi Srivatsavai NULL, /* MAC_NOTE_MARGIN */ 844eaa4710SRishi Srivatsavai NULL, /* MAC_NOTE_CAPAB_CHG */ 854eaa4710SRishi Srivatsavai NULL /* MAC_NOTE_LOWLINK */ 86da14cebeSEric Cheng }; 87da14cebeSEric Cheng 88da14cebeSEric Cheng /* 89da14cebeSEric Cheng * Driver support functions. 90da14cebeSEric Cheng */ 91da14cebeSEric Cheng 92da14cebeSEric Cheng /* REGISTRATION */ 93da14cebeSEric Cheng 94da14cebeSEric Cheng mac_register_t * 95da14cebeSEric Cheng mac_alloc(uint_t mac_version) 96da14cebeSEric Cheng { 97da14cebeSEric Cheng mac_register_t *mregp; 98da14cebeSEric Cheng 99da14cebeSEric Cheng /* 100da14cebeSEric Cheng * Make sure there isn't a version mismatch between the driver and 101da14cebeSEric Cheng * the framework. In the future, if multiple versions are 102da14cebeSEric Cheng * supported, this check could become more sophisticated. 103da14cebeSEric Cheng */ 104da14cebeSEric Cheng if (mac_version != MAC_VERSION) 105da14cebeSEric Cheng return (NULL); 106da14cebeSEric Cheng 107da14cebeSEric Cheng mregp = kmem_zalloc(sizeof (mac_register_t), KM_SLEEP); 108da14cebeSEric Cheng mregp->m_version = mac_version; 109da14cebeSEric Cheng return (mregp); 110da14cebeSEric Cheng } 111da14cebeSEric Cheng 112da14cebeSEric Cheng void 113da14cebeSEric Cheng mac_free(mac_register_t *mregp) 114da14cebeSEric Cheng { 115da14cebeSEric Cheng kmem_free(mregp, sizeof (mac_register_t)); 116da14cebeSEric Cheng } 117da14cebeSEric Cheng 118da14cebeSEric Cheng /* 119da14cebeSEric Cheng * mac_register() is how drivers register new MACs with the GLDv3 120da14cebeSEric Cheng * framework. The mregp argument is allocated by drivers using the 121da14cebeSEric Cheng * mac_alloc() function, and can be freed using mac_free() immediately upon 122da14cebeSEric Cheng * return from mac_register(). Upon success (0 return value), the mhp 123da14cebeSEric Cheng * opaque pointer becomes the driver's handle to its MAC interface, and is 124da14cebeSEric Cheng * the argument to all other mac module entry points. 125da14cebeSEric Cheng */ 126da14cebeSEric Cheng /* ARGSUSED */ 127da14cebeSEric Cheng int 128da14cebeSEric Cheng mac_register(mac_register_t *mregp, mac_handle_t *mhp) 129da14cebeSEric Cheng { 130da14cebeSEric Cheng mac_impl_t *mip; 131da14cebeSEric Cheng mactype_t *mtype; 132da14cebeSEric Cheng int err = EINVAL; 133da14cebeSEric Cheng struct devnames *dnp = NULL; 134da14cebeSEric Cheng uint_t instance; 135da14cebeSEric Cheng boolean_t style1_created = B_FALSE; 136da14cebeSEric Cheng boolean_t style2_created = B_FALSE; 137da14cebeSEric Cheng char *driver; 138da14cebeSEric Cheng minor_t minor = 0; 139da14cebeSEric Cheng 140ee94b1c3SSebastien Roy /* A successful call to mac_init_ops() sets the DN_GLDV3_DRIVER flag. */ 141ee94b1c3SSebastien Roy if (!GLDV3_DRV(ddi_driver_major(mregp->m_dip))) 142ee94b1c3SSebastien Roy return (EINVAL); 143ee94b1c3SSebastien Roy 144da14cebeSEric Cheng /* Find the required MAC-Type plugin. */ 145da14cebeSEric Cheng if ((mtype = mactype_getplugin(mregp->m_type_ident)) == NULL) 146da14cebeSEric Cheng return (EINVAL); 147da14cebeSEric Cheng 148da14cebeSEric Cheng /* Create a mac_impl_t to represent this MAC. */ 149da14cebeSEric Cheng mip = kmem_cache_alloc(i_mac_impl_cachep, KM_SLEEP); 150da14cebeSEric Cheng 151da14cebeSEric Cheng /* 152da14cebeSEric Cheng * The mac is not ready for open yet. 153da14cebeSEric Cheng */ 154da14cebeSEric Cheng mip->mi_state_flags |= MIS_DISABLED; 155da14cebeSEric Cheng 156da14cebeSEric Cheng /* 157da14cebeSEric Cheng * When a mac is registered, the m_instance field can be set to: 158da14cebeSEric Cheng * 159da14cebeSEric Cheng * 0: Get the mac's instance number from m_dip. 160da14cebeSEric Cheng * This is usually used for physical device dips. 161da14cebeSEric Cheng * 162da14cebeSEric Cheng * [1 .. MAC_MAX_MINOR-1]: Use the value as the mac's instance number. 163da14cebeSEric Cheng * For example, when an aggregation is created with the key option, 164da14cebeSEric Cheng * "key" will be used as the instance number. 165da14cebeSEric Cheng * 166da14cebeSEric Cheng * -1: Assign an instance number from [MAC_MAX_MINOR .. MAXMIN-1]. 167da14cebeSEric Cheng * This is often used when a MAC of a virtual link is registered 168da14cebeSEric Cheng * (e.g., aggregation when "key" is not specified, or vnic). 169da14cebeSEric Cheng * 170da14cebeSEric Cheng * Note that the instance number is used to derive the mi_minor field 171da14cebeSEric Cheng * of mac_impl_t, which will then be used to derive the name of kstats 172da14cebeSEric Cheng * and the devfs nodes. The first 2 cases are needed to preserve 173da14cebeSEric Cheng * backward compatibility. 174da14cebeSEric Cheng */ 175da14cebeSEric Cheng switch (mregp->m_instance) { 176da14cebeSEric Cheng case 0: 177da14cebeSEric Cheng instance = ddi_get_instance(mregp->m_dip); 178da14cebeSEric Cheng break; 179da14cebeSEric Cheng case ((uint_t)-1): 180da14cebeSEric Cheng minor = mac_minor_hold(B_TRUE); 181da14cebeSEric Cheng if (minor == 0) { 182da14cebeSEric Cheng err = ENOSPC; 183da14cebeSEric Cheng goto fail; 184da14cebeSEric Cheng } 185da14cebeSEric Cheng instance = minor - 1; 186da14cebeSEric Cheng break; 187da14cebeSEric Cheng default: 188da14cebeSEric Cheng instance = mregp->m_instance; 189da14cebeSEric Cheng if (instance >= MAC_MAX_MINOR) { 190da14cebeSEric Cheng err = EINVAL; 191da14cebeSEric Cheng goto fail; 192da14cebeSEric Cheng } 193da14cebeSEric Cheng break; 194da14cebeSEric Cheng } 195da14cebeSEric Cheng 196da14cebeSEric Cheng mip->mi_minor = (minor_t)(instance + 1); 197da14cebeSEric Cheng mip->mi_dip = mregp->m_dip; 198da14cebeSEric Cheng mip->mi_clients_list = NULL; 199da14cebeSEric Cheng mip->mi_nclients = 0; 200da14cebeSEric Cheng 2014eaa4710SRishi Srivatsavai /* Set the default IEEE Port VLAN Identifier */ 2024eaa4710SRishi Srivatsavai mip->mi_pvid = 1; 2034eaa4710SRishi Srivatsavai 2044eaa4710SRishi Srivatsavai /* Default bridge link learning protection values */ 2054eaa4710SRishi Srivatsavai mip->mi_llimit = 1000; 2064eaa4710SRishi Srivatsavai mip->mi_ldecay = 200; 2074eaa4710SRishi Srivatsavai 208da14cebeSEric Cheng driver = (char *)ddi_driver_name(mip->mi_dip); 209da14cebeSEric Cheng 210da14cebeSEric Cheng /* Construct the MAC name as <drvname><instance> */ 211da14cebeSEric Cheng (void) snprintf(mip->mi_name, sizeof (mip->mi_name), "%s%d", 212da14cebeSEric Cheng driver, instance); 213da14cebeSEric Cheng 214da14cebeSEric Cheng mip->mi_driver = mregp->m_driver; 215da14cebeSEric Cheng 216da14cebeSEric Cheng mip->mi_type = mtype; 217da14cebeSEric Cheng mip->mi_margin = mregp->m_margin; 218da14cebeSEric Cheng mip->mi_info.mi_media = mtype->mt_type; 219da14cebeSEric Cheng mip->mi_info.mi_nativemedia = mtype->mt_nativetype; 220da14cebeSEric Cheng if (mregp->m_max_sdu <= mregp->m_min_sdu) 221da14cebeSEric Cheng goto fail; 2221eee170aSErik Nordmark if (mregp->m_multicast_sdu == 0) 2231eee170aSErik Nordmark mregp->m_multicast_sdu = mregp->m_max_sdu; 2241eee170aSErik Nordmark if (mregp->m_multicast_sdu < mregp->m_min_sdu || 2251eee170aSErik Nordmark mregp->m_multicast_sdu > mregp->m_max_sdu) 2261eee170aSErik Nordmark goto fail; 227da14cebeSEric Cheng mip->mi_sdu_min = mregp->m_min_sdu; 228da14cebeSEric Cheng mip->mi_sdu_max = mregp->m_max_sdu; 2291eee170aSErik Nordmark mip->mi_sdu_multicast = mregp->m_multicast_sdu; 230da14cebeSEric Cheng mip->mi_info.mi_addr_length = mip->mi_type->mt_addr_length; 231da14cebeSEric Cheng /* 232da14cebeSEric Cheng * If the media supports a broadcast address, cache a pointer to it 233da14cebeSEric Cheng * in the mac_info_t so that upper layers can use it. 234da14cebeSEric Cheng */ 235da14cebeSEric Cheng mip->mi_info.mi_brdcst_addr = mip->mi_type->mt_brdcst_addr; 236da14cebeSEric Cheng 237da14cebeSEric Cheng mip->mi_v12n_level = mregp->m_v12n; 238da14cebeSEric Cheng 239da14cebeSEric Cheng /* 240da14cebeSEric Cheng * Copy the unicast source address into the mac_info_t, but only if 241da14cebeSEric Cheng * the MAC-Type defines a non-zero address length. We need to 242da14cebeSEric Cheng * handle MAC-Types that have an address length of 0 243da14cebeSEric Cheng * (point-to-point protocol MACs for example). 244da14cebeSEric Cheng */ 245da14cebeSEric Cheng if (mip->mi_type->mt_addr_length > 0) { 246da14cebeSEric Cheng if (mregp->m_src_addr == NULL) 247da14cebeSEric Cheng goto fail; 248da14cebeSEric Cheng mip->mi_info.mi_unicst_addr = 249da14cebeSEric Cheng kmem_alloc(mip->mi_type->mt_addr_length, KM_SLEEP); 250da14cebeSEric Cheng bcopy(mregp->m_src_addr, mip->mi_info.mi_unicst_addr, 251da14cebeSEric Cheng mip->mi_type->mt_addr_length); 252da14cebeSEric Cheng 253da14cebeSEric Cheng /* 254da14cebeSEric Cheng * Copy the fixed 'factory' MAC address from the immutable 255da14cebeSEric Cheng * info. This is taken to be the MAC address currently in 256da14cebeSEric Cheng * use. 257da14cebeSEric Cheng */ 258da14cebeSEric Cheng bcopy(mip->mi_info.mi_unicst_addr, mip->mi_addr, 259da14cebeSEric Cheng mip->mi_type->mt_addr_length); 260da14cebeSEric Cheng 261da14cebeSEric Cheng /* 262da14cebeSEric Cheng * At this point, we should set up the classification 263da14cebeSEric Cheng * rules etc but we delay it till mac_open() so that 264da14cebeSEric Cheng * the resource discovery has taken place and we 265da14cebeSEric Cheng * know someone wants to use the device. Otherwise 266da14cebeSEric Cheng * memory gets allocated for Rx ring structures even 267da14cebeSEric Cheng * during probe. 268da14cebeSEric Cheng */ 269da14cebeSEric Cheng 270da14cebeSEric Cheng /* Copy the destination address if one is provided. */ 271da14cebeSEric Cheng if (mregp->m_dst_addr != NULL) { 272da14cebeSEric Cheng bcopy(mregp->m_dst_addr, mip->mi_dstaddr, 273da14cebeSEric Cheng mip->mi_type->mt_addr_length); 2742b24ab6bSSebastien Roy mip->mi_dstaddr_set = B_TRUE; 275da14cebeSEric Cheng } 276da14cebeSEric Cheng } else if (mregp->m_src_addr != NULL) { 277da14cebeSEric Cheng goto fail; 278da14cebeSEric Cheng } 279da14cebeSEric Cheng 280da14cebeSEric Cheng /* 281da14cebeSEric Cheng * The format of the m_pdata is specific to the plugin. It is 282da14cebeSEric Cheng * passed in as an argument to all of the plugin callbacks. The 283da14cebeSEric Cheng * driver can update this information by calling 284da14cebeSEric Cheng * mac_pdata_update(). 285da14cebeSEric Cheng */ 2862b24ab6bSSebastien Roy if (mip->mi_type->mt_ops.mtops_ops & MTOPS_PDATA_VERIFY) { 287da14cebeSEric Cheng /* 2882b24ab6bSSebastien Roy * Verify if the supplied plugin data is valid. Note that 2892b24ab6bSSebastien Roy * even if the caller passed in a NULL pointer as plugin data, 2902b24ab6bSSebastien Roy * we still need to verify if that's valid as the plugin may 2912b24ab6bSSebastien Roy * require plugin data to function. 292da14cebeSEric Cheng */ 293da14cebeSEric Cheng if (!mip->mi_type->mt_ops.mtops_pdata_verify(mregp->m_pdata, 294da14cebeSEric Cheng mregp->m_pdata_size)) { 295da14cebeSEric Cheng goto fail; 296da14cebeSEric Cheng } 2972b24ab6bSSebastien Roy if (mregp->m_pdata != NULL) { 2982b24ab6bSSebastien Roy mip->mi_pdata = 2992b24ab6bSSebastien Roy kmem_alloc(mregp->m_pdata_size, KM_SLEEP); 3002b24ab6bSSebastien Roy bcopy(mregp->m_pdata, mip->mi_pdata, 3012b24ab6bSSebastien Roy mregp->m_pdata_size); 3022b24ab6bSSebastien Roy mip->mi_pdata_size = mregp->m_pdata_size; 3032b24ab6bSSebastien Roy } 3042b24ab6bSSebastien Roy } else if (mregp->m_pdata != NULL) { 3052b24ab6bSSebastien Roy /* 3062b24ab6bSSebastien Roy * The caller supplied non-NULL plugin data, but the plugin 3072b24ab6bSSebastien Roy * does not recognize plugin data. 3082b24ab6bSSebastien Roy */ 3092b24ab6bSSebastien Roy err = EINVAL; 3102b24ab6bSSebastien Roy goto fail; 311da14cebeSEric Cheng } 312da14cebeSEric Cheng 313da14cebeSEric Cheng /* 314da14cebeSEric Cheng * Register the private properties. 315da14cebeSEric Cheng */ 3160dc2366fSVenugopal Iyer mac_register_priv_prop(mip, mregp->m_priv_props); 317da14cebeSEric Cheng 318da14cebeSEric Cheng /* 319da14cebeSEric Cheng * Stash the driver callbacks into the mac_impl_t, but first sanity 320da14cebeSEric Cheng * check to make sure all mandatory callbacks are set. 321da14cebeSEric Cheng */ 322da14cebeSEric Cheng if (mregp->m_callbacks->mc_getstat == NULL || 323da14cebeSEric Cheng mregp->m_callbacks->mc_start == NULL || 324da14cebeSEric Cheng mregp->m_callbacks->mc_stop == NULL || 325da14cebeSEric Cheng mregp->m_callbacks->mc_setpromisc == NULL || 326da14cebeSEric Cheng mregp->m_callbacks->mc_multicst == NULL) { 327da14cebeSEric Cheng goto fail; 328da14cebeSEric Cheng } 329da14cebeSEric Cheng mip->mi_callbacks = mregp->m_callbacks; 330da14cebeSEric Cheng 3315d460eafSCathy Zhou if (mac_capab_get((mac_handle_t)mip, MAC_CAPAB_LEGACY, 3325d460eafSCathy Zhou &mip->mi_capab_legacy)) { 333da14cebeSEric Cheng mip->mi_state_flags |= MIS_LEGACY; 3345d460eafSCathy Zhou mip->mi_phy_dev = mip->mi_capab_legacy.ml_dev; 335da14cebeSEric Cheng } else { 336da14cebeSEric Cheng mip->mi_phy_dev = makedevice(ddi_driver_major(mip->mi_dip), 33761af1958SGarrett D'Amore mip->mi_minor); 338da14cebeSEric Cheng } 339da14cebeSEric Cheng 340da14cebeSEric Cheng /* 341da14cebeSEric Cheng * Allocate a notification thread. thread_create blocks for memory 342da14cebeSEric Cheng * if needed, it never fails. 343da14cebeSEric Cheng */ 344da14cebeSEric Cheng mip->mi_notify_thread = thread_create(NULL, 0, i_mac_notify_thread, 345da14cebeSEric Cheng mip, 0, &p0, TS_RUN, minclsyspri); 346da14cebeSEric Cheng 347da14cebeSEric Cheng /* 348da14cebeSEric Cheng * Initialize the capabilities 349da14cebeSEric Cheng */ 350da14cebeSEric Cheng 3510dc2366fSVenugopal Iyer bzero(&mip->mi_rx_rings_cap, sizeof (mac_capab_rings_t)); 3520dc2366fSVenugopal Iyer bzero(&mip->mi_tx_rings_cap, sizeof (mac_capab_rings_t)); 3530dc2366fSVenugopal Iyer 354da14cebeSEric Cheng if (i_mac_capab_get((mac_handle_t)mip, MAC_CAPAB_VNIC, NULL)) 355da14cebeSEric Cheng mip->mi_state_flags |= MIS_IS_VNIC; 356da14cebeSEric Cheng 357da14cebeSEric Cheng if (i_mac_capab_get((mac_handle_t)mip, MAC_CAPAB_AGGR, NULL)) 358da14cebeSEric Cheng mip->mi_state_flags |= MIS_IS_AGGR; 359da14cebeSEric Cheng 360da14cebeSEric Cheng mac_addr_factory_init(mip); 361da14cebeSEric Cheng 36245d3dd98SRobert Mustacchi mac_transceiver_init(mip); 36345d3dd98SRobert Mustacchi 364c1e9c696SRobert Mustacchi mac_led_init(mip); 365c1e9c696SRobert Mustacchi 366da14cebeSEric Cheng /* 367da14cebeSEric Cheng * Enforce the virtrualization level registered. 368da14cebeSEric Cheng */ 369da14cebeSEric Cheng if (mip->mi_v12n_level & MAC_VIRT_LEVEL1) { 370da14cebeSEric Cheng if (mac_init_rings(mip, MAC_RING_TYPE_RX) != 0 || 371da14cebeSEric Cheng mac_init_rings(mip, MAC_RING_TYPE_TX) != 0) 372da14cebeSEric Cheng goto fail; 373da14cebeSEric Cheng 374da14cebeSEric Cheng /* 375da14cebeSEric Cheng * The driver needs to register at least rx rings for this 376da14cebeSEric Cheng * virtualization level. 377da14cebeSEric Cheng */ 378da14cebeSEric Cheng if (mip->mi_rx_groups == NULL) 379da14cebeSEric Cheng goto fail; 380da14cebeSEric Cheng } 381da14cebeSEric Cheng 382da14cebeSEric Cheng /* 383da14cebeSEric Cheng * The driver must set mc_unicst entry point to NULL when it advertises 384da14cebeSEric Cheng * CAP_RINGS for rx groups. 385da14cebeSEric Cheng */ 386da14cebeSEric Cheng if (mip->mi_rx_groups != NULL) { 387da14cebeSEric Cheng if (mregp->m_callbacks->mc_unicst != NULL) 388da14cebeSEric Cheng goto fail; 389da14cebeSEric Cheng } else { 390da14cebeSEric Cheng if (mregp->m_callbacks->mc_unicst == NULL) 391da14cebeSEric Cheng goto fail; 392da14cebeSEric Cheng } 393da14cebeSEric Cheng 394da14cebeSEric Cheng /* 395da14cebeSEric Cheng * Initialize MAC addresses. Must be called after mac_init_rings(). 396da14cebeSEric Cheng */ 397da14cebeSEric Cheng mac_init_macaddr(mip); 398da14cebeSEric Cheng 399da14cebeSEric Cheng mip->mi_share_capab.ms_snum = 0; 400da14cebeSEric Cheng if (mip->mi_v12n_level & MAC_VIRT_HIO) { 401da14cebeSEric Cheng (void) mac_capab_get((mac_handle_t)mip, MAC_CAPAB_SHARES, 402da14cebeSEric Cheng &mip->mi_share_capab); 403da14cebeSEric Cheng } 404da14cebeSEric Cheng 405da14cebeSEric Cheng /* 406da14cebeSEric Cheng * Initialize the kstats for this device. 407da14cebeSEric Cheng */ 4080dc2366fSVenugopal Iyer mac_driver_stat_create(mip); 409da14cebeSEric Cheng 410da14cebeSEric Cheng /* Zero out any properties. */ 411da14cebeSEric Cheng bzero(&mip->mi_resource_props, sizeof (mac_resource_props_t)); 412da14cebeSEric Cheng 4133ade6e84SGarrett D'Amore if (mip->mi_minor <= MAC_MAX_MINOR) { 414da14cebeSEric Cheng /* Create a style-2 DLPI device */ 415da14cebeSEric Cheng if (ddi_create_minor_node(mip->mi_dip, driver, S_IFCHR, 0, 416da14cebeSEric Cheng DDI_NT_NET, CLONE_DEV) != DDI_SUCCESS) 417da14cebeSEric Cheng goto fail; 418da14cebeSEric Cheng style2_created = B_TRUE; 419da14cebeSEric Cheng 420da14cebeSEric Cheng /* Create a style-1 DLPI device */ 421da14cebeSEric Cheng if (ddi_create_minor_node(mip->mi_dip, mip->mi_name, S_IFCHR, 422da14cebeSEric Cheng mip->mi_minor, DDI_NT_NET, 0) != DDI_SUCCESS) 423da14cebeSEric Cheng goto fail; 424da14cebeSEric Cheng style1_created = B_TRUE; 425da14cebeSEric Cheng } 426da14cebeSEric Cheng 427da14cebeSEric Cheng mac_flow_l2tab_create(mip, &mip->mi_flow_tab); 428da14cebeSEric Cheng 429da14cebeSEric Cheng rw_enter(&i_mac_impl_lock, RW_WRITER); 430da14cebeSEric Cheng if (mod_hash_insert(i_mac_impl_hash, 431da14cebeSEric Cheng (mod_hash_key_t)mip->mi_name, (mod_hash_val_t)mip) != 0) { 432da14cebeSEric Cheng rw_exit(&i_mac_impl_lock); 433da14cebeSEric Cheng err = EEXIST; 434da14cebeSEric Cheng goto fail; 435da14cebeSEric Cheng } 436da14cebeSEric Cheng 437da14cebeSEric Cheng DTRACE_PROBE2(mac__register, struct devnames *, dnp, 438da14cebeSEric Cheng (mac_impl_t *), mip); 439da14cebeSEric Cheng 440da14cebeSEric Cheng /* 441da14cebeSEric Cheng * Mark the MAC to be ready for open. 442da14cebeSEric Cheng */ 443da14cebeSEric Cheng mip->mi_state_flags &= ~MIS_DISABLED; 444da14cebeSEric Cheng rw_exit(&i_mac_impl_lock); 445da14cebeSEric Cheng 446da14cebeSEric Cheng atomic_inc_32(&i_mac_impl_count); 447da14cebeSEric Cheng 448da14cebeSEric Cheng cmn_err(CE_NOTE, "!%s registered", mip->mi_name); 449da14cebeSEric Cheng *mhp = (mac_handle_t)mip; 450da14cebeSEric Cheng return (0); 451da14cebeSEric Cheng 452da14cebeSEric Cheng fail: 453da14cebeSEric Cheng if (style1_created) 454da14cebeSEric Cheng ddi_remove_minor_node(mip->mi_dip, mip->mi_name); 455da14cebeSEric Cheng 456da14cebeSEric Cheng if (style2_created) 457da14cebeSEric Cheng ddi_remove_minor_node(mip->mi_dip, driver); 458da14cebeSEric Cheng 459da14cebeSEric Cheng mac_addr_factory_fini(mip); 460da14cebeSEric Cheng 461da14cebeSEric Cheng /* Clean up registered MAC addresses */ 462da14cebeSEric Cheng mac_fini_macaddr(mip); 463da14cebeSEric Cheng 464da14cebeSEric Cheng /* Clean up registered rings */ 465da14cebeSEric Cheng mac_free_rings(mip, MAC_RING_TYPE_RX); 466da14cebeSEric Cheng mac_free_rings(mip, MAC_RING_TYPE_TX); 467da14cebeSEric Cheng 468da14cebeSEric Cheng /* Clean up notification thread */ 469da14cebeSEric Cheng if (mip->mi_notify_thread != NULL) 470da14cebeSEric Cheng i_mac_notify_exit(mip); 471da14cebeSEric Cheng 472da14cebeSEric Cheng if (mip->mi_info.mi_unicst_addr != NULL) { 473da14cebeSEric Cheng kmem_free(mip->mi_info.mi_unicst_addr, 474da14cebeSEric Cheng mip->mi_type->mt_addr_length); 475da14cebeSEric Cheng mip->mi_info.mi_unicst_addr = NULL; 476da14cebeSEric Cheng } 477da14cebeSEric Cheng 4780dc2366fSVenugopal Iyer mac_driver_stat_delete(mip); 479da14cebeSEric Cheng 480da14cebeSEric Cheng if (mip->mi_type != NULL) { 481da14cebeSEric Cheng atomic_dec_32(&mip->mi_type->mt_ref); 482da14cebeSEric Cheng mip->mi_type = NULL; 483da14cebeSEric Cheng } 484da14cebeSEric Cheng 485da14cebeSEric Cheng if (mip->mi_pdata != NULL) { 486da14cebeSEric Cheng kmem_free(mip->mi_pdata, mip->mi_pdata_size); 487da14cebeSEric Cheng mip->mi_pdata = NULL; 488da14cebeSEric Cheng mip->mi_pdata_size = 0; 489da14cebeSEric Cheng } 490da14cebeSEric Cheng 491da14cebeSEric Cheng if (minor != 0) { 492da14cebeSEric Cheng ASSERT(minor > MAC_MAX_MINOR); 493da14cebeSEric Cheng mac_minor_rele(minor); 494da14cebeSEric Cheng } 495da14cebeSEric Cheng 4960dc2366fSVenugopal Iyer mip->mi_state_flags = 0; 497da14cebeSEric Cheng mac_unregister_priv_prop(mip); 498da14cebeSEric Cheng 499783f25ceSMichael Speer /* 500783f25ceSMichael Speer * Clear the state before destroying the mac_impl_t 501783f25ceSMichael Speer */ 502783f25ceSMichael Speer mip->mi_state_flags = 0; 503783f25ceSMichael Speer 504da14cebeSEric Cheng kmem_cache_free(i_mac_impl_cachep, mip); 505da14cebeSEric Cheng return (err); 506da14cebeSEric Cheng } 507da14cebeSEric Cheng 508da14cebeSEric Cheng /* 509da14cebeSEric Cheng * Unregister from the GLDv3 framework 510da14cebeSEric Cheng */ 511da14cebeSEric Cheng int 512da14cebeSEric Cheng mac_unregister(mac_handle_t mh) 513da14cebeSEric Cheng { 514da14cebeSEric Cheng int err; 515da14cebeSEric Cheng mac_impl_t *mip = (mac_impl_t *)mh; 516da14cebeSEric Cheng mod_hash_val_t val; 517da14cebeSEric Cheng mac_margin_req_t *mmr, *nextmmr; 518da14cebeSEric Cheng 519da14cebeSEric Cheng /* Fail the unregister if there are any open references to this mac. */ 520da14cebeSEric Cheng if ((err = mac_disable_nowait(mh)) != 0) 521da14cebeSEric Cheng return (err); 522da14cebeSEric Cheng 523da14cebeSEric Cheng /* 524da14cebeSEric Cheng * Clean up notification thread and wait for it to exit. 525da14cebeSEric Cheng */ 526da14cebeSEric Cheng i_mac_notify_exit(mip); 527da14cebeSEric Cheng 5288241ccbbSDan McDonald /* 5298241ccbbSDan McDonald * Prior to acquiring the MAC perimeter, remove the MAC instance from 5308241ccbbSDan McDonald * the internal hash table. Such removal means table-walkers that 5318241ccbbSDan McDonald * acquire the perimeter will not do so on behalf of what we are 5328241ccbbSDan McDonald * unregistering, which prevents a deadlock. 5338241ccbbSDan McDonald */ 5348241ccbbSDan McDonald rw_enter(&i_mac_impl_lock, RW_WRITER); 5358241ccbbSDan McDonald (void) mod_hash_remove(i_mac_impl_hash, 5368241ccbbSDan McDonald (mod_hash_key_t)mip->mi_name, &val); 5378241ccbbSDan McDonald rw_exit(&i_mac_impl_lock); 5388241ccbbSDan McDonald ASSERT(mip == (mac_impl_t *)val); 5398241ccbbSDan McDonald 540da14cebeSEric Cheng i_mac_perim_enter(mip); 541da14cebeSEric Cheng 5425d460eafSCathy Zhou /* 5435d460eafSCathy Zhou * There is still resource properties configured over this mac. 5445d460eafSCathy Zhou */ 5455d460eafSCathy Zhou if (mip->mi_resource_props.mrp_mask != 0) 5465d460eafSCathy Zhou mac_fastpath_enable((mac_handle_t)mip); 5475d460eafSCathy Zhou 548da14cebeSEric Cheng if (mip->mi_minor < MAC_MAX_MINOR + 1) { 549da14cebeSEric Cheng ddi_remove_minor_node(mip->mi_dip, mip->mi_name); 550da14cebeSEric Cheng ddi_remove_minor_node(mip->mi_dip, 551da14cebeSEric Cheng (char *)ddi_driver_name(mip->mi_dip)); 552da14cebeSEric Cheng } 553da14cebeSEric Cheng 554da14cebeSEric Cheng ASSERT(mip->mi_nactiveclients == 0 && !(mip->mi_state_flags & 555da14cebeSEric Cheng MIS_EXCLUSIVE)); 556da14cebeSEric Cheng 5570dc2366fSVenugopal Iyer mac_driver_stat_delete(mip); 558da14cebeSEric Cheng 559da14cebeSEric Cheng ASSERT(i_mac_impl_count > 0); 560da14cebeSEric Cheng atomic_dec_32(&i_mac_impl_count); 561da14cebeSEric Cheng 562da14cebeSEric Cheng if (mip->mi_pdata != NULL) 563da14cebeSEric Cheng kmem_free(mip->mi_pdata, mip->mi_pdata_size); 564da14cebeSEric Cheng mip->mi_pdata = NULL; 565da14cebeSEric Cheng mip->mi_pdata_size = 0; 566da14cebeSEric Cheng 567da14cebeSEric Cheng /* 568da14cebeSEric Cheng * Free the list of margin request. 569da14cebeSEric Cheng */ 570da14cebeSEric Cheng for (mmr = mip->mi_mmrp; mmr != NULL; mmr = nextmmr) { 571da14cebeSEric Cheng nextmmr = mmr->mmr_nextp; 572da14cebeSEric Cheng kmem_free(mmr, sizeof (mac_margin_req_t)); 573da14cebeSEric Cheng } 574da14cebeSEric Cheng mip->mi_mmrp = NULL; 575da14cebeSEric Cheng 5764eaa4710SRishi Srivatsavai mip->mi_linkstate = mip->mi_lowlinkstate = LINK_STATE_UNKNOWN; 577da14cebeSEric Cheng kmem_free(mip->mi_info.mi_unicst_addr, mip->mi_type->mt_addr_length); 578da14cebeSEric Cheng mip->mi_info.mi_unicst_addr = NULL; 579da14cebeSEric Cheng 580da14cebeSEric Cheng atomic_dec_32(&mip->mi_type->mt_ref); 581da14cebeSEric Cheng mip->mi_type = NULL; 582da14cebeSEric Cheng 583da14cebeSEric Cheng /* 584da14cebeSEric Cheng * Free the primary MAC address. 585da14cebeSEric Cheng */ 586da14cebeSEric Cheng mac_fini_macaddr(mip); 587da14cebeSEric Cheng 588da14cebeSEric Cheng /* 589da14cebeSEric Cheng * free all rings 590da14cebeSEric Cheng */ 591da14cebeSEric Cheng mac_free_rings(mip, MAC_RING_TYPE_RX); 592da14cebeSEric Cheng mac_free_rings(mip, MAC_RING_TYPE_TX); 593da14cebeSEric Cheng 594da14cebeSEric Cheng mac_addr_factory_fini(mip); 595da14cebeSEric Cheng 596da14cebeSEric Cheng bzero(mip->mi_addr, MAXMACADDRLEN); 597da14cebeSEric Cheng bzero(mip->mi_dstaddr, MAXMACADDRLEN); 5989b41bdc4SRobert Mustacchi mip->mi_dstaddr_set = B_FALSE; 599da14cebeSEric Cheng 600da14cebeSEric Cheng /* and the flows */ 601da14cebeSEric Cheng mac_flow_tab_destroy(mip->mi_flow_tab); 602da14cebeSEric Cheng mip->mi_flow_tab = NULL; 603da14cebeSEric Cheng 604da14cebeSEric Cheng if (mip->mi_minor > MAC_MAX_MINOR) 605da14cebeSEric Cheng mac_minor_rele(mip->mi_minor); 606da14cebeSEric Cheng 607da14cebeSEric Cheng cmn_err(CE_NOTE, "!%s unregistered", mip->mi_name); 608da14cebeSEric Cheng 609da14cebeSEric Cheng /* 610da14cebeSEric Cheng * Reset the perim related fields to default values before 611da14cebeSEric Cheng * kmem_cache_free 612da14cebeSEric Cheng */ 613da14cebeSEric Cheng i_mac_perim_exit(mip); 614da14cebeSEric Cheng mip->mi_state_flags = 0; 615da14cebeSEric Cheng 616da14cebeSEric Cheng mac_unregister_priv_prop(mip); 6174eaa4710SRishi Srivatsavai 6184eaa4710SRishi Srivatsavai ASSERT(mip->mi_bridge_link == NULL); 619da14cebeSEric Cheng kmem_cache_free(i_mac_impl_cachep, mip); 620da14cebeSEric Cheng 621da14cebeSEric Cheng return (0); 622da14cebeSEric Cheng } 623da14cebeSEric Cheng 624da14cebeSEric Cheng /* DATA RECEPTION */ 625da14cebeSEric Cheng 626da14cebeSEric Cheng /* 627da14cebeSEric Cheng * This function is invoked for packets received by the MAC driver in 628da14cebeSEric Cheng * interrupt context. The ring generation number provided by the driver 629da14cebeSEric Cheng * is matched with the ring generation number held in MAC. If they do not 630da14cebeSEric Cheng * match, received packets are considered stale packets coming from an older 631da14cebeSEric Cheng * assignment of the ring. Drop them. 632da14cebeSEric Cheng */ 633da14cebeSEric Cheng void 634da14cebeSEric Cheng mac_rx_ring(mac_handle_t mh, mac_ring_handle_t mrh, mblk_t *mp_chain, 635da14cebeSEric Cheng uint64_t mr_gen_num) 636da14cebeSEric Cheng { 637da14cebeSEric Cheng mac_ring_t *mr = (mac_ring_t *)mrh; 638da14cebeSEric Cheng 639da14cebeSEric Cheng if ((mr != NULL) && (mr->mr_gen_num != mr_gen_num)) { 640da14cebeSEric Cheng DTRACE_PROBE2(mac__rx__rings__stale__packet, uint64_t, 641da14cebeSEric Cheng mr->mr_gen_num, uint64_t, mr_gen_num); 642da14cebeSEric Cheng freemsgchain(mp_chain); 643da14cebeSEric Cheng return; 644da14cebeSEric Cheng } 645da14cebeSEric Cheng mac_rx(mh, (mac_resource_handle_t)mrh, mp_chain); 646da14cebeSEric Cheng } 647da14cebeSEric Cheng 648da14cebeSEric Cheng /* 6494eaa4710SRishi Srivatsavai * This function is invoked for each packet received by the underlying driver. 650da14cebeSEric Cheng */ 651da14cebeSEric Cheng void 652da14cebeSEric Cheng mac_rx(mac_handle_t mh, mac_resource_handle_t mrh, mblk_t *mp_chain) 6534eaa4710SRishi Srivatsavai { 6544eaa4710SRishi Srivatsavai mac_impl_t *mip = (mac_impl_t *)mh; 6554eaa4710SRishi Srivatsavai 6564eaa4710SRishi Srivatsavai /* 6574eaa4710SRishi Srivatsavai * Check if the link is part of a bridge. If not, then we don't need 6584eaa4710SRishi Srivatsavai * to take the lock to remain consistent. Make this common case 6594eaa4710SRishi Srivatsavai * lock-free and tail-call optimized. 6604eaa4710SRishi Srivatsavai */ 6614eaa4710SRishi Srivatsavai if (mip->mi_bridge_link == NULL) { 6624eaa4710SRishi Srivatsavai mac_rx_common(mh, mrh, mp_chain); 6634eaa4710SRishi Srivatsavai } else { 6644eaa4710SRishi Srivatsavai /* 6654eaa4710SRishi Srivatsavai * Once we take a reference on the bridge link, the bridge 6664eaa4710SRishi Srivatsavai * module itself can't unload, so the callback pointers are 6674eaa4710SRishi Srivatsavai * stable. 6684eaa4710SRishi Srivatsavai */ 6694eaa4710SRishi Srivatsavai mutex_enter(&mip->mi_bridge_lock); 6704eaa4710SRishi Srivatsavai if ((mh = mip->mi_bridge_link) != NULL) 6714eaa4710SRishi Srivatsavai mac_bridge_ref_cb(mh, B_TRUE); 6724eaa4710SRishi Srivatsavai mutex_exit(&mip->mi_bridge_lock); 6734eaa4710SRishi Srivatsavai if (mh == NULL) { 6744eaa4710SRishi Srivatsavai mac_rx_common((mac_handle_t)mip, mrh, mp_chain); 6754eaa4710SRishi Srivatsavai } else { 6764eaa4710SRishi Srivatsavai mac_bridge_rx_cb(mh, mrh, mp_chain); 6774eaa4710SRishi Srivatsavai mac_bridge_ref_cb(mh, B_FALSE); 6784eaa4710SRishi Srivatsavai } 6794eaa4710SRishi Srivatsavai } 6804eaa4710SRishi Srivatsavai } 6814eaa4710SRishi Srivatsavai 6824eaa4710SRishi Srivatsavai /* 6834eaa4710SRishi Srivatsavai * Special case function: this allows snooping of packets transmitted and 6844eaa4710SRishi Srivatsavai * received by TRILL. By design, they go directly into the TRILL module. 6854eaa4710SRishi Srivatsavai */ 6864eaa4710SRishi Srivatsavai void 6874eaa4710SRishi Srivatsavai mac_trill_snoop(mac_handle_t mh, mblk_t *mp) 6884eaa4710SRishi Srivatsavai { 6894eaa4710SRishi Srivatsavai mac_impl_t *mip = (mac_impl_t *)mh; 6904eaa4710SRishi Srivatsavai 6914eaa4710SRishi Srivatsavai if (mip->mi_promisc_list != NULL) 6924eaa4710SRishi Srivatsavai mac_promisc_dispatch(mip, mp, NULL); 6934eaa4710SRishi Srivatsavai } 6944eaa4710SRishi Srivatsavai 6954eaa4710SRishi Srivatsavai /* 6964eaa4710SRishi Srivatsavai * This is the upward reentry point for packets arriving from the bridging 6974eaa4710SRishi Srivatsavai * module and from mac_rx for links not part of a bridge. 6984eaa4710SRishi Srivatsavai */ 6994eaa4710SRishi Srivatsavai void 7004eaa4710SRishi Srivatsavai mac_rx_common(mac_handle_t mh, mac_resource_handle_t mrh, mblk_t *mp_chain) 701da14cebeSEric Cheng { 702da14cebeSEric Cheng mac_impl_t *mip = (mac_impl_t *)mh; 703da14cebeSEric Cheng mac_ring_t *mr = (mac_ring_t *)mrh; 70484de666eSRyan Zezeski mac_soft_ring_set_t *mac_srs; 705da14cebeSEric Cheng mblk_t *bp = mp_chain; 706da14cebeSEric Cheng 707da14cebeSEric Cheng /* 708da14cebeSEric Cheng * If there are any promiscuous mode callbacks defined for 709da14cebeSEric Cheng * this MAC, pass them a copy if appropriate. 710da14cebeSEric Cheng */ 711da14cebeSEric Cheng if (mip->mi_promisc_list != NULL) 712da14cebeSEric Cheng mac_promisc_dispatch(mip, mp_chain, NULL); 713da14cebeSEric Cheng 714da14cebeSEric Cheng if (mr != NULL) { 715da14cebeSEric Cheng /* 716da14cebeSEric Cheng * If the SRS teardown has started, just return. The 'mr' 71745948e49SRyan Zezeski * continues to be valid until the driver unregisters the MAC. 718da14cebeSEric Cheng * Hardware classified packets will not make their way up 719da14cebeSEric Cheng * beyond this point once the teardown has started. The driver 720da14cebeSEric Cheng * is never passed a pointer to a flow entry or SRS or any 721da14cebeSEric Cheng * structure that can be freed much before mac_unregister. 722da14cebeSEric Cheng */ 723da14cebeSEric Cheng mutex_enter(&mr->mr_lock); 724da14cebeSEric Cheng if ((mr->mr_state != MR_INUSE) || (mr->mr_flag & 725da14cebeSEric Cheng (MR_INCIPIENT | MR_CONDEMNED | MR_QUIESCE))) { 726da14cebeSEric Cheng mutex_exit(&mr->mr_lock); 727da14cebeSEric Cheng freemsgchain(mp_chain); 728da14cebeSEric Cheng return; 729da14cebeSEric Cheng } 73045948e49SRyan Zezeski 73145948e49SRyan Zezeski /* 73245948e49SRyan Zezeski * The ring is in passthru mode; pass the chain up to 73345948e49SRyan Zezeski * the pseudo ring. 73445948e49SRyan Zezeski */ 73545948e49SRyan Zezeski if (mr->mr_classify_type == MAC_PASSTHRU_CLASSIFIER) { 736da14cebeSEric Cheng MR_REFHOLD_LOCKED(mr); 73745948e49SRyan Zezeski mutex_exit(&mr->mr_lock); 73845948e49SRyan Zezeski mr->mr_pt_fn(mr->mr_pt_arg1, mr->mr_pt_arg2, mp_chain, 73945948e49SRyan Zezeski B_FALSE); 74045948e49SRyan Zezeski MR_REFRELE(mr); 74145948e49SRyan Zezeski return; 742da14cebeSEric Cheng } 74345948e49SRyan Zezeski 74445948e49SRyan Zezeski /* 74545948e49SRyan Zezeski * The passthru callback should only be set when in 74645948e49SRyan Zezeski * MAC_PASSTHRU_CLASSIFIER mode. 74745948e49SRyan Zezeski */ 74845948e49SRyan Zezeski ASSERT3P(mr->mr_pt_fn, ==, NULL); 749da14cebeSEric Cheng 750da14cebeSEric Cheng /* 751da14cebeSEric Cheng * We check if an SRS is controlling this ring. 752da14cebeSEric Cheng * If so, we can directly call the srs_lower_proc 753da14cebeSEric Cheng * routine otherwise we need to go through mac_rx_classify 754da14cebeSEric Cheng * to reach the right place. 755da14cebeSEric Cheng */ 75645948e49SRyan Zezeski if (mr->mr_classify_type == MAC_HW_CLASSIFIER) { 75745948e49SRyan Zezeski MR_REFHOLD_LOCKED(mr); 75845948e49SRyan Zezeski mutex_exit(&mr->mr_lock); 75945948e49SRyan Zezeski ASSERT3P(mr->mr_srs, !=, NULL); 760da14cebeSEric Cheng mac_srs = mr->mr_srs; 76145948e49SRyan Zezeski 762da14cebeSEric Cheng /* 76345948e49SRyan Zezeski * This is the fast path. All packets received 76445948e49SRyan Zezeski * on this ring are hardware classified and 76545948e49SRyan Zezeski * share the same MAC header info. 766da14cebeSEric Cheng */ 767da14cebeSEric Cheng mac_srs->srs_rx.sr_lower_proc(mh, 768da14cebeSEric Cheng (mac_resource_handle_t)mac_srs, mp_chain, B_FALSE); 769da14cebeSEric Cheng MR_REFRELE(mr); 770da14cebeSEric Cheng return; 771da14cebeSEric Cheng } 77245948e49SRyan Zezeski 77345948e49SRyan Zezeski mutex_exit(&mr->mr_lock); 774da14cebeSEric Cheng /* We'll fall through to software classification */ 775ae6aa22aSVenugopal Iyer } else { 776ae6aa22aSVenugopal Iyer flow_entry_t *flent; 777ae6aa22aSVenugopal Iyer int err; 778ae6aa22aSVenugopal Iyer 779ae6aa22aSVenugopal Iyer rw_enter(&mip->mi_rw_lock, RW_READER); 780ae6aa22aSVenugopal Iyer if (mip->mi_single_active_client != NULL) { 781ae6aa22aSVenugopal Iyer flent = mip->mi_single_active_client->mci_flent_list; 782ae6aa22aSVenugopal Iyer FLOW_TRY_REFHOLD(flent, err); 783ae6aa22aSVenugopal Iyer rw_exit(&mip->mi_rw_lock); 784ae6aa22aSVenugopal Iyer if (err == 0) { 785ae6aa22aSVenugopal Iyer (flent->fe_cb_fn)(flent->fe_cb_arg1, 786ae6aa22aSVenugopal Iyer flent->fe_cb_arg2, mp_chain, B_FALSE); 787ae6aa22aSVenugopal Iyer FLOW_REFRELE(flent); 788ae6aa22aSVenugopal Iyer return; 789ae6aa22aSVenugopal Iyer } 790ae6aa22aSVenugopal Iyer } else { 791ae6aa22aSVenugopal Iyer rw_exit(&mip->mi_rw_lock); 792ae6aa22aSVenugopal Iyer } 793da14cebeSEric Cheng } 794da14cebeSEric Cheng 795da14cebeSEric Cheng if (!FLOW_TAB_EMPTY(mip->mi_flow_tab)) { 796da14cebeSEric Cheng if ((bp = mac_rx_flow(mh, mrh, bp)) == NULL) 797da14cebeSEric Cheng return; 798da14cebeSEric Cheng } 799da14cebeSEric Cheng 800da14cebeSEric Cheng freemsgchain(bp); 801da14cebeSEric Cheng } 802da14cebeSEric Cheng 803da14cebeSEric Cheng /* DATA TRANSMISSION */ 804da14cebeSEric Cheng 805da14cebeSEric Cheng /* 806da14cebeSEric Cheng * A driver's notification to resume transmission, in case of a provider 807da14cebeSEric Cheng * without TX rings. 808da14cebeSEric Cheng */ 809da14cebeSEric Cheng void 810da14cebeSEric Cheng mac_tx_update(mac_handle_t mh) 811da14cebeSEric Cheng { 8120dc2366fSVenugopal Iyer mac_tx_ring_update(mh, NULL); 813da14cebeSEric Cheng } 814da14cebeSEric Cheng 815da14cebeSEric Cheng /* 816da14cebeSEric Cheng * A driver's notification to resume transmission on the specified TX ring. 817da14cebeSEric Cheng */ 818da14cebeSEric Cheng void 819da14cebeSEric Cheng mac_tx_ring_update(mac_handle_t mh, mac_ring_handle_t rh) 820da14cebeSEric Cheng { 821da14cebeSEric Cheng i_mac_tx_srs_notify((mac_impl_t *)mh, rh); 822da14cebeSEric Cheng } 823da14cebeSEric Cheng 824da14cebeSEric Cheng /* LINK STATE */ 825da14cebeSEric Cheng /* 826da14cebeSEric Cheng * Notify the MAC layer about a link state change 827da14cebeSEric Cheng */ 828da14cebeSEric Cheng void 829da14cebeSEric Cheng mac_link_update(mac_handle_t mh, link_state_t link) 830da14cebeSEric Cheng { 831da14cebeSEric Cheng mac_impl_t *mip = (mac_impl_t *)mh; 832da14cebeSEric Cheng 8334eaa4710SRishi Srivatsavai /* 8344eaa4710SRishi Srivatsavai * Save the link state. 8354eaa4710SRishi Srivatsavai */ 8364eaa4710SRishi Srivatsavai mip->mi_lowlinkstate = link; 8374eaa4710SRishi Srivatsavai 8384eaa4710SRishi Srivatsavai /* 8394eaa4710SRishi Srivatsavai * Send a MAC_NOTE_LOWLINK notification. This tells the notification 8404eaa4710SRishi Srivatsavai * thread to deliver both lower and upper notifications. 8414eaa4710SRishi Srivatsavai */ 8424eaa4710SRishi Srivatsavai i_mac_notify(mip, MAC_NOTE_LOWLINK); 8434eaa4710SRishi Srivatsavai } 8444eaa4710SRishi Srivatsavai 8454eaa4710SRishi Srivatsavai /* 8464eaa4710SRishi Srivatsavai * Notify the MAC layer about a link state change due to bridging. 8474eaa4710SRishi Srivatsavai */ 8484eaa4710SRishi Srivatsavai void 8494eaa4710SRishi Srivatsavai mac_link_redo(mac_handle_t mh, link_state_t link) 8504eaa4710SRishi Srivatsavai { 8514eaa4710SRishi Srivatsavai mac_impl_t *mip = (mac_impl_t *)mh; 8524eaa4710SRishi Srivatsavai 853da14cebeSEric Cheng /* 854da14cebeSEric Cheng * Save the link state. 855da14cebeSEric Cheng */ 856da14cebeSEric Cheng mip->mi_linkstate = link; 857da14cebeSEric Cheng 858da14cebeSEric Cheng /* 8594eaa4710SRishi Srivatsavai * Send a MAC_NOTE_LINK notification. Only upper notifications are 8604eaa4710SRishi Srivatsavai * made. 861da14cebeSEric Cheng */ 862da14cebeSEric Cheng i_mac_notify(mip, MAC_NOTE_LINK); 863da14cebeSEric Cheng } 864da14cebeSEric Cheng 86561af1958SGarrett D'Amore /* MINOR NODE HANDLING */ 86661af1958SGarrett D'Amore 86761af1958SGarrett D'Amore /* 86861af1958SGarrett D'Amore * Given a dev_t, return the instance number (PPA) associated with it. 86961af1958SGarrett D'Amore * Drivers can use this in their getinfo(9e) implementation to lookup 87061af1958SGarrett D'Amore * the instance number (i.e. PPA) of the device, to use as an index to 87161af1958SGarrett D'Amore * their own array of soft state structures. 87261af1958SGarrett D'Amore * 87361af1958SGarrett D'Amore * Returns -1 on error. 87461af1958SGarrett D'Amore */ 87561af1958SGarrett D'Amore int 87661af1958SGarrett D'Amore mac_devt_to_instance(dev_t devt) 87761af1958SGarrett D'Amore { 87861af1958SGarrett D'Amore return (dld_devt_to_instance(devt)); 87961af1958SGarrett D'Amore } 88061af1958SGarrett D'Amore 88161af1958SGarrett D'Amore /* 88261af1958SGarrett D'Amore * This function returns the first minor number that is available for 88361af1958SGarrett D'Amore * driver private use. All minor numbers smaller than this are 88461af1958SGarrett D'Amore * reserved for GLDv3 use. 88561af1958SGarrett D'Amore */ 88661af1958SGarrett D'Amore minor_t 88761af1958SGarrett D'Amore mac_private_minor(void) 88861af1958SGarrett D'Amore { 88961af1958SGarrett D'Amore return (MAC_PRIVATE_MINOR); 89061af1958SGarrett D'Amore } 89161af1958SGarrett D'Amore 892da14cebeSEric Cheng /* OTHER CONTROL INFORMATION */ 893da14cebeSEric Cheng 894da14cebeSEric Cheng /* 895da14cebeSEric Cheng * A driver notified us that its primary MAC address has changed. 896da14cebeSEric Cheng */ 897da14cebeSEric Cheng void 898da14cebeSEric Cheng mac_unicst_update(mac_handle_t mh, const uint8_t *addr) 899da14cebeSEric Cheng { 900da14cebeSEric Cheng mac_impl_t *mip = (mac_impl_t *)mh; 901da14cebeSEric Cheng 902da14cebeSEric Cheng if (mip->mi_type->mt_addr_length == 0) 903da14cebeSEric Cheng return; 904da14cebeSEric Cheng 905da14cebeSEric Cheng i_mac_perim_enter(mip); 906da14cebeSEric Cheng 907da14cebeSEric Cheng /* 908fd0939efSDavid Edmondson * If address changes, freshen the MAC address value and update 909fd0939efSDavid Edmondson * all MAC clients that share this MAC address. 910da14cebeSEric Cheng */ 911fd0939efSDavid Edmondson if (bcmp(addr, mip->mi_addr, mip->mi_type->mt_addr_length) != 0) { 912fd0939efSDavid Edmondson mac_freshen_macaddr(mac_find_macaddr(mip, mip->mi_addr), 913fd0939efSDavid Edmondson (uint8_t *)addr); 914fd0939efSDavid Edmondson } 915da14cebeSEric Cheng 916da14cebeSEric Cheng i_mac_perim_exit(mip); 917da14cebeSEric Cheng 918da14cebeSEric Cheng /* 919da14cebeSEric Cheng * Send a MAC_NOTE_UNICST notification. 920da14cebeSEric Cheng */ 921da14cebeSEric Cheng i_mac_notify(mip, MAC_NOTE_UNICST); 922da14cebeSEric Cheng } 923da14cebeSEric Cheng 9242b24ab6bSSebastien Roy void 9252b24ab6bSSebastien Roy mac_dst_update(mac_handle_t mh, const uint8_t *addr) 9262b24ab6bSSebastien Roy { 9272b24ab6bSSebastien Roy mac_impl_t *mip = (mac_impl_t *)mh; 9282b24ab6bSSebastien Roy 9292b24ab6bSSebastien Roy if (mip->mi_type->mt_addr_length == 0) 9302b24ab6bSSebastien Roy return; 9312b24ab6bSSebastien Roy 9322b24ab6bSSebastien Roy i_mac_perim_enter(mip); 9332b24ab6bSSebastien Roy bcopy(addr, mip->mi_dstaddr, mip->mi_type->mt_addr_length); 9342b24ab6bSSebastien Roy i_mac_perim_exit(mip); 9352b24ab6bSSebastien Roy i_mac_notify(mip, MAC_NOTE_DEST); 9362b24ab6bSSebastien Roy } 9372b24ab6bSSebastien Roy 938da14cebeSEric Cheng /* 939da14cebeSEric Cheng * MAC plugin information changed. 940da14cebeSEric Cheng */ 941da14cebeSEric Cheng int 942da14cebeSEric Cheng mac_pdata_update(mac_handle_t mh, void *mac_pdata, size_t dsize) 943da14cebeSEric Cheng { 944da14cebeSEric Cheng mac_impl_t *mip = (mac_impl_t *)mh; 945da14cebeSEric Cheng 946da14cebeSEric Cheng /* 947da14cebeSEric Cheng * Verify that the plugin supports MAC plugin data and that the 948da14cebeSEric Cheng * supplied data is valid. 949da14cebeSEric Cheng */ 950da14cebeSEric Cheng if (!(mip->mi_type->mt_ops.mtops_ops & MTOPS_PDATA_VERIFY)) 951da14cebeSEric Cheng return (EINVAL); 952da14cebeSEric Cheng if (!mip->mi_type->mt_ops.mtops_pdata_verify(mac_pdata, dsize)) 953da14cebeSEric Cheng return (EINVAL); 954da14cebeSEric Cheng 955da14cebeSEric Cheng if (mip->mi_pdata != NULL) 956da14cebeSEric Cheng kmem_free(mip->mi_pdata, mip->mi_pdata_size); 957da14cebeSEric Cheng 958da14cebeSEric Cheng mip->mi_pdata = kmem_alloc(dsize, KM_SLEEP); 959da14cebeSEric Cheng bcopy(mac_pdata, mip->mi_pdata, dsize); 960da14cebeSEric Cheng mip->mi_pdata_size = dsize; 961da14cebeSEric Cheng 962da14cebeSEric Cheng /* 963da14cebeSEric Cheng * Since the MAC plugin data is used to construct MAC headers that 964da14cebeSEric Cheng * were cached in fast-path headers, we need to flush fast-path 965da14cebeSEric Cheng * information for links associated with this mac. 966da14cebeSEric Cheng */ 967da14cebeSEric Cheng i_mac_notify(mip, MAC_NOTE_FASTPATH_FLUSH); 968da14cebeSEric Cheng return (0); 969da14cebeSEric Cheng } 970da14cebeSEric Cheng 971da14cebeSEric Cheng /* 972da14cebeSEric Cheng * Invoked by driver as well as the framework to notify its capability change. 973da14cebeSEric Cheng */ 974da14cebeSEric Cheng void 975da14cebeSEric Cheng mac_capab_update(mac_handle_t mh) 976da14cebeSEric Cheng { 977da14cebeSEric Cheng /* Send MAC_NOTE_CAPAB_CHG notification */ 978da14cebeSEric Cheng i_mac_notify((mac_impl_t *)mh, MAC_NOTE_CAPAB_CHG); 979da14cebeSEric Cheng } 980da14cebeSEric Cheng 9811eee170aSErik Nordmark /* 9821eee170aSErik Nordmark * Used by normal drivers to update the max sdu size. 9831eee170aSErik Nordmark * We need to handle the case of a smaller mi_sdu_multicast 9841eee170aSErik Nordmark * since this is called by mac_set_mtu() even for drivers that 9851eee170aSErik Nordmark * have differing unicast and multicast mtu and we don't want to 9861eee170aSErik Nordmark * increase the multicast mtu by accident in that case. 9871eee170aSErik Nordmark */ 988da14cebeSEric Cheng int 989da14cebeSEric Cheng mac_maxsdu_update(mac_handle_t mh, uint_t sdu_max) 990da14cebeSEric Cheng { 991da14cebeSEric Cheng mac_impl_t *mip = (mac_impl_t *)mh; 992da14cebeSEric Cheng 993f0f2c3a5SGirish Moodalbail if (sdu_max == 0 || sdu_max < mip->mi_sdu_min) 994da14cebeSEric Cheng return (EINVAL); 995da14cebeSEric Cheng mip->mi_sdu_max = sdu_max; 9961eee170aSErik Nordmark if (mip->mi_sdu_multicast > mip->mi_sdu_max) 9971eee170aSErik Nordmark mip->mi_sdu_multicast = mip->mi_sdu_max; 9981eee170aSErik Nordmark 9991eee170aSErik Nordmark /* Send a MAC_NOTE_SDU_SIZE notification. */ 10001eee170aSErik Nordmark i_mac_notify(mip, MAC_NOTE_SDU_SIZE); 10011eee170aSErik Nordmark return (0); 10021eee170aSErik Nordmark } 10031eee170aSErik Nordmark 10041eee170aSErik Nordmark /* 10051eee170aSErik Nordmark * Version of the above function that is used by drivers that have a different 10061eee170aSErik Nordmark * max sdu size for multicast/broadcast vs. unicast. 10071eee170aSErik Nordmark */ 10081eee170aSErik Nordmark int 10091eee170aSErik Nordmark mac_maxsdu_update2(mac_handle_t mh, uint_t sdu_max, uint_t sdu_multicast) 10101eee170aSErik Nordmark { 10111eee170aSErik Nordmark mac_impl_t *mip = (mac_impl_t *)mh; 10121eee170aSErik Nordmark 10131eee170aSErik Nordmark if (sdu_max == 0 || sdu_max < mip->mi_sdu_min) 10141eee170aSErik Nordmark return (EINVAL); 10151eee170aSErik Nordmark if (sdu_multicast == 0) 10161eee170aSErik Nordmark sdu_multicast = sdu_max; 10171eee170aSErik Nordmark if (sdu_multicast > sdu_max || sdu_multicast < mip->mi_sdu_min) 10181eee170aSErik Nordmark return (EINVAL); 10191eee170aSErik Nordmark mip->mi_sdu_max = sdu_max; 10201eee170aSErik Nordmark mip->mi_sdu_multicast = sdu_multicast; 1021da14cebeSEric Cheng 1022da14cebeSEric Cheng /* Send a MAC_NOTE_SDU_SIZE notification. */ 1023da14cebeSEric Cheng i_mac_notify(mip, MAC_NOTE_SDU_SIZE); 1024da14cebeSEric Cheng return (0); 1025da14cebeSEric Cheng } 1026da14cebeSEric Cheng 10270dc2366fSVenugopal Iyer static void 10280dc2366fSVenugopal Iyer mac_ring_intr_retarget(mac_group_t *group, mac_ring_t *ring) 10290dc2366fSVenugopal Iyer { 10300dc2366fSVenugopal Iyer mac_client_impl_t *mcip; 10310dc2366fSVenugopal Iyer flow_entry_t *flent; 10320dc2366fSVenugopal Iyer mac_soft_ring_set_t *mac_rx_srs; 10330dc2366fSVenugopal Iyer mac_cpus_t *srs_cpu; 10340dc2366fSVenugopal Iyer int i; 10350dc2366fSVenugopal Iyer 10360dc2366fSVenugopal Iyer if (((mcip = MAC_GROUP_ONLY_CLIENT(group)) != NULL) && 10370dc2366fSVenugopal Iyer (!ring->mr_info.mri_intr.mi_ddi_shared)) { 10380dc2366fSVenugopal Iyer /* interrupt can be re-targeted */ 10390dc2366fSVenugopal Iyer ASSERT(group->mrg_state == MAC_GROUP_STATE_RESERVED); 10400dc2366fSVenugopal Iyer flent = mcip->mci_flent; 10410dc2366fSVenugopal Iyer if (ring->mr_type == MAC_RING_TYPE_RX) { 10420dc2366fSVenugopal Iyer for (i = 0; i < flent->fe_rx_srs_cnt; i++) { 10430dc2366fSVenugopal Iyer mac_rx_srs = flent->fe_rx_srs[i]; 10440dc2366fSVenugopal Iyer if (mac_rx_srs->srs_ring != ring) 10450dc2366fSVenugopal Iyer continue; 10460dc2366fSVenugopal Iyer srs_cpu = &mac_rx_srs->srs_cpu; 10470dc2366fSVenugopal Iyer mutex_enter(&cpu_lock); 10480dc2366fSVenugopal Iyer mac_rx_srs_retarget_intr(mac_rx_srs, 10490dc2366fSVenugopal Iyer srs_cpu->mc_rx_intr_cpu); 10500dc2366fSVenugopal Iyer mutex_exit(&cpu_lock); 10510dc2366fSVenugopal Iyer break; 10520dc2366fSVenugopal Iyer } 10530dc2366fSVenugopal Iyer } else { 10540dc2366fSVenugopal Iyer if (flent->fe_tx_srs != NULL) { 10550dc2366fSVenugopal Iyer mutex_enter(&cpu_lock); 10560dc2366fSVenugopal Iyer mac_tx_srs_retarget_intr( 10570dc2366fSVenugopal Iyer flent->fe_tx_srs); 10580dc2366fSVenugopal Iyer mutex_exit(&cpu_lock); 10590dc2366fSVenugopal Iyer } 10600dc2366fSVenugopal Iyer } 10610dc2366fSVenugopal Iyer } 10620dc2366fSVenugopal Iyer } 10630dc2366fSVenugopal Iyer 10640dc2366fSVenugopal Iyer /* 10650dc2366fSVenugopal Iyer * Clients like aggr create pseudo rings (mac_ring_t) and expose them to 10660dc2366fSVenugopal Iyer * their clients. There is a 1-1 mapping pseudo ring and the hardware 10670dc2366fSVenugopal Iyer * ring. ddi interrupt handles are exported from the hardware ring to 10680dc2366fSVenugopal Iyer * the pseudo ring. Thus when the interrupt handle changes, clients of 10690dc2366fSVenugopal Iyer * aggr that are using the handle need to use the new handle and 10700dc2366fSVenugopal Iyer * re-target their interrupts. 10710dc2366fSVenugopal Iyer */ 10720dc2366fSVenugopal Iyer static void 10730dc2366fSVenugopal Iyer mac_pseudo_ring_intr_retarget(mac_impl_t *mip, mac_ring_t *ring, 10740dc2366fSVenugopal Iyer ddi_intr_handle_t ddh) 10750dc2366fSVenugopal Iyer { 10760dc2366fSVenugopal Iyer mac_ring_t *pring; 10770dc2366fSVenugopal Iyer mac_group_t *pgroup; 10780dc2366fSVenugopal Iyer mac_impl_t *pmip; 10790dc2366fSVenugopal Iyer char macname[MAXNAMELEN]; 10800dc2366fSVenugopal Iyer mac_perim_handle_t p_mph; 10810dc2366fSVenugopal Iyer uint64_t saved_gen_num; 10820dc2366fSVenugopal Iyer 10830dc2366fSVenugopal Iyer again: 10840dc2366fSVenugopal Iyer pring = (mac_ring_t *)ring->mr_prh; 10850dc2366fSVenugopal Iyer pgroup = (mac_group_t *)pring->mr_gh; 10860dc2366fSVenugopal Iyer pmip = (mac_impl_t *)pgroup->mrg_mh; 10870dc2366fSVenugopal Iyer saved_gen_num = ring->mr_gen_num; 10880dc2366fSVenugopal Iyer (void) strlcpy(macname, pmip->mi_name, MAXNAMELEN); 10890dc2366fSVenugopal Iyer /* 10900dc2366fSVenugopal Iyer * We need to enter aggr's perimeter. The locking hierarchy 10910dc2366fSVenugopal Iyer * dictates that aggr's perimeter should be entered first 10920dc2366fSVenugopal Iyer * and then the port's perimeter. So drop the port's 10930dc2366fSVenugopal Iyer * perimeter, enter aggr's and then re-enter port's 10940dc2366fSVenugopal Iyer * perimeter. 10950dc2366fSVenugopal Iyer */ 10960dc2366fSVenugopal Iyer i_mac_perim_exit(mip); 10970dc2366fSVenugopal Iyer /* 10980dc2366fSVenugopal Iyer * While we know pmip is the aggr's mip, there is a 10990dc2366fSVenugopal Iyer * possibility that aggr could have unregistered by 11000dc2366fSVenugopal Iyer * the time we exit port's perimeter (mip) and 11010dc2366fSVenugopal Iyer * enter aggr's perimeter (pmip). To avoid that 11020dc2366fSVenugopal Iyer * scenario, enter aggr's perimeter using its name. 11030dc2366fSVenugopal Iyer */ 11040dc2366fSVenugopal Iyer if (mac_perim_enter_by_macname(macname, &p_mph) != 0) 11050dc2366fSVenugopal Iyer return; 11060dc2366fSVenugopal Iyer i_mac_perim_enter(mip); 11070dc2366fSVenugopal Iyer /* 11080dc2366fSVenugopal Iyer * Check if the ring got assigned to another aggregation before 11090dc2366fSVenugopal Iyer * be could enter aggr's and the port's perimeter. When a ring 11100dc2366fSVenugopal Iyer * gets deleted from an aggregation, it calls mac_stop_ring() 11110dc2366fSVenugopal Iyer * which increments the generation number. So checking 11120dc2366fSVenugopal Iyer * generation number will be enough. 11130dc2366fSVenugopal Iyer */ 11140dc2366fSVenugopal Iyer if (ring->mr_gen_num != saved_gen_num && ring->mr_prh != NULL) { 11150dc2366fSVenugopal Iyer i_mac_perim_exit(mip); 11160dc2366fSVenugopal Iyer mac_perim_exit(p_mph); 11170dc2366fSVenugopal Iyer i_mac_perim_enter(mip); 11180dc2366fSVenugopal Iyer goto again; 11190dc2366fSVenugopal Iyer } 11200dc2366fSVenugopal Iyer 11210dc2366fSVenugopal Iyer /* Check if pseudo ring is still present */ 11220dc2366fSVenugopal Iyer if (ring->mr_prh != NULL) { 11230dc2366fSVenugopal Iyer pring->mr_info.mri_intr.mi_ddi_handle = ddh; 11240dc2366fSVenugopal Iyer pring->mr_info.mri_intr.mi_ddi_shared = 11250dc2366fSVenugopal Iyer ring->mr_info.mri_intr.mi_ddi_shared; 11260dc2366fSVenugopal Iyer if (ddh != NULL) 11270dc2366fSVenugopal Iyer mac_ring_intr_retarget(pgroup, pring); 11280dc2366fSVenugopal Iyer } 11290dc2366fSVenugopal Iyer i_mac_perim_exit(mip); 11300dc2366fSVenugopal Iyer mac_perim_exit(p_mph); 11310dc2366fSVenugopal Iyer } 11320dc2366fSVenugopal Iyer /* 11330dc2366fSVenugopal Iyer * API called by driver to provide new interrupt handle for TX/RX rings. 11340dc2366fSVenugopal Iyer * This usually happens when IRM (Interrupt Resource Manangement) 11350dc2366fSVenugopal Iyer * framework either gives the driver more MSI-x interrupts or takes 11360dc2366fSVenugopal Iyer * away MSI-x interrupts from the driver. 11370dc2366fSVenugopal Iyer */ 11380dc2366fSVenugopal Iyer void 11390dc2366fSVenugopal Iyer mac_ring_intr_set(mac_ring_handle_t mrh, ddi_intr_handle_t ddh) 11400dc2366fSVenugopal Iyer { 11410dc2366fSVenugopal Iyer mac_ring_t *ring = (mac_ring_t *)mrh; 11420dc2366fSVenugopal Iyer mac_group_t *group = (mac_group_t *)ring->mr_gh; 11430dc2366fSVenugopal Iyer mac_impl_t *mip = (mac_impl_t *)group->mrg_mh; 11440dc2366fSVenugopal Iyer 11450dc2366fSVenugopal Iyer i_mac_perim_enter(mip); 11460dc2366fSVenugopal Iyer ring->mr_info.mri_intr.mi_ddi_handle = ddh; 11470dc2366fSVenugopal Iyer if (ddh == NULL) { 11480dc2366fSVenugopal Iyer /* Interrupts being reset */ 11490dc2366fSVenugopal Iyer ring->mr_info.mri_intr.mi_ddi_shared = B_FALSE; 11500dc2366fSVenugopal Iyer if (ring->mr_prh != NULL) { 11510dc2366fSVenugopal Iyer mac_pseudo_ring_intr_retarget(mip, ring, ddh); 11520dc2366fSVenugopal Iyer return; 11530dc2366fSVenugopal Iyer } 11540dc2366fSVenugopal Iyer } else { 11550dc2366fSVenugopal Iyer /* New interrupt handle */ 11560dc2366fSVenugopal Iyer mac_compare_ddi_handle(mip->mi_rx_groups, 11570dc2366fSVenugopal Iyer mip->mi_rx_group_count, ring); 11580dc2366fSVenugopal Iyer if (!ring->mr_info.mri_intr.mi_ddi_shared) { 11590dc2366fSVenugopal Iyer mac_compare_ddi_handle(mip->mi_tx_groups, 11600dc2366fSVenugopal Iyer mip->mi_tx_group_count, ring); 11610dc2366fSVenugopal Iyer } 11620dc2366fSVenugopal Iyer if (ring->mr_prh != NULL) { 11630dc2366fSVenugopal Iyer mac_pseudo_ring_intr_retarget(mip, ring, ddh); 11640dc2366fSVenugopal Iyer return; 11650dc2366fSVenugopal Iyer } else { 11660dc2366fSVenugopal Iyer mac_ring_intr_retarget(group, ring); 11670dc2366fSVenugopal Iyer } 11680dc2366fSVenugopal Iyer } 11690dc2366fSVenugopal Iyer i_mac_perim_exit(mip); 11700dc2366fSVenugopal Iyer } 11710dc2366fSVenugopal Iyer 1172da14cebeSEric Cheng /* PRIVATE FUNCTIONS, FOR INTERNAL USE ONLY */ 1173da14cebeSEric Cheng 1174da14cebeSEric Cheng /* 1175da14cebeSEric Cheng * Updates the mac_impl structure with the current state of the link 1176da14cebeSEric Cheng */ 1177da14cebeSEric Cheng static void 1178da14cebeSEric Cheng i_mac_log_link_state(mac_impl_t *mip) 1179da14cebeSEric Cheng { 1180da14cebeSEric Cheng /* 1181da14cebeSEric Cheng * If no change, then it is not interesting. 1182da14cebeSEric Cheng */ 11834eaa4710SRishi Srivatsavai if (mip->mi_lastlowlinkstate == mip->mi_lowlinkstate) 1184da14cebeSEric Cheng return; 1185da14cebeSEric Cheng 11864eaa4710SRishi Srivatsavai switch (mip->mi_lowlinkstate) { 1187da14cebeSEric Cheng case LINK_STATE_UP: 1188da14cebeSEric Cheng if (mip->mi_type->mt_ops.mtops_ops & MTOPS_LINK_DETAILS) { 1189da14cebeSEric Cheng char det[200]; 1190da14cebeSEric Cheng 1191da14cebeSEric Cheng mip->mi_type->mt_ops.mtops_link_details(det, 1192da14cebeSEric Cheng sizeof (det), (mac_handle_t)mip, mip->mi_pdata); 1193da14cebeSEric Cheng 1194da14cebeSEric Cheng cmn_err(CE_NOTE, "!%s link up, %s", mip->mi_name, det); 1195da14cebeSEric Cheng } else { 1196da14cebeSEric Cheng cmn_err(CE_NOTE, "!%s link up", mip->mi_name); 1197da14cebeSEric Cheng } 1198da14cebeSEric Cheng break; 1199da14cebeSEric Cheng 1200da14cebeSEric Cheng case LINK_STATE_DOWN: 1201da14cebeSEric Cheng /* 1202da14cebeSEric Cheng * Only transitions from UP to DOWN are interesting 1203da14cebeSEric Cheng */ 12044eaa4710SRishi Srivatsavai if (mip->mi_lastlowlinkstate != LINK_STATE_UNKNOWN) 1205da14cebeSEric Cheng cmn_err(CE_NOTE, "!%s link down", mip->mi_name); 1206da14cebeSEric Cheng break; 1207da14cebeSEric Cheng 1208da14cebeSEric Cheng case LINK_STATE_UNKNOWN: 1209da14cebeSEric Cheng /* 1210da14cebeSEric Cheng * This case is normally not interesting. 1211da14cebeSEric Cheng */ 1212da14cebeSEric Cheng break; 1213da14cebeSEric Cheng } 12144eaa4710SRishi Srivatsavai mip->mi_lastlowlinkstate = mip->mi_lowlinkstate; 1215da14cebeSEric Cheng } 1216da14cebeSEric Cheng 1217da14cebeSEric Cheng /* 1218da14cebeSEric Cheng * Main routine for the callbacks notifications thread 1219da14cebeSEric Cheng */ 1220da14cebeSEric Cheng static void 1221da14cebeSEric Cheng i_mac_notify_thread(void *arg) 1222da14cebeSEric Cheng { 1223da14cebeSEric Cheng mac_impl_t *mip = arg; 1224da14cebeSEric Cheng callb_cpr_t cprinfo; 1225da14cebeSEric Cheng mac_cb_t *mcb; 1226da14cebeSEric Cheng mac_cb_info_t *mcbi; 1227da14cebeSEric Cheng mac_notify_cb_t *mncb; 1228da14cebeSEric Cheng 1229da14cebeSEric Cheng mcbi = &mip->mi_notify_cb_info; 1230da14cebeSEric Cheng CALLB_CPR_INIT(&cprinfo, mcbi->mcbi_lockp, callb_generic_cpr, 1231da14cebeSEric Cheng "i_mac_notify_thread"); 1232da14cebeSEric Cheng 1233da14cebeSEric Cheng mutex_enter(mcbi->mcbi_lockp); 1234da14cebeSEric Cheng 1235da14cebeSEric Cheng for (;;) { 1236da14cebeSEric Cheng uint32_t bits; 1237da14cebeSEric Cheng uint32_t type; 1238da14cebeSEric Cheng 1239da14cebeSEric Cheng bits = mip->mi_notify_bits; 1240da14cebeSEric Cheng if (bits == 0) { 1241da14cebeSEric Cheng CALLB_CPR_SAFE_BEGIN(&cprinfo); 1242da14cebeSEric Cheng cv_wait(&mcbi->mcbi_cv, mcbi->mcbi_lockp); 1243da14cebeSEric Cheng CALLB_CPR_SAFE_END(&cprinfo, mcbi->mcbi_lockp); 1244da14cebeSEric Cheng continue; 1245da14cebeSEric Cheng } 1246da14cebeSEric Cheng mip->mi_notify_bits = 0; 1247da14cebeSEric Cheng if ((bits & (1 << MAC_NNOTE)) != 0) { 1248da14cebeSEric Cheng /* request to quit */ 1249da14cebeSEric Cheng ASSERT(mip->mi_state_flags & MIS_DISABLED); 1250da14cebeSEric Cheng break; 1251da14cebeSEric Cheng } 1252da14cebeSEric Cheng 1253da14cebeSEric Cheng mutex_exit(mcbi->mcbi_lockp); 1254da14cebeSEric Cheng 1255da14cebeSEric Cheng /* 12564eaa4710SRishi Srivatsavai * Log link changes on the actual link, but then do reports on 12574eaa4710SRishi Srivatsavai * synthetic state (if part of a bridge). 1258da14cebeSEric Cheng */ 12594eaa4710SRishi Srivatsavai if ((bits & (1 << MAC_NOTE_LOWLINK)) != 0) { 12604eaa4710SRishi Srivatsavai link_state_t newstate; 12614eaa4710SRishi Srivatsavai mac_handle_t mh; 12624eaa4710SRishi Srivatsavai 1263da14cebeSEric Cheng i_mac_log_link_state(mip); 12644eaa4710SRishi Srivatsavai newstate = mip->mi_lowlinkstate; 12654eaa4710SRishi Srivatsavai if (mip->mi_bridge_link != NULL) { 12664eaa4710SRishi Srivatsavai mutex_enter(&mip->mi_bridge_lock); 12674eaa4710SRishi Srivatsavai if ((mh = mip->mi_bridge_link) != NULL) { 12684eaa4710SRishi Srivatsavai newstate = mac_bridge_ls_cb(mh, 12694eaa4710SRishi Srivatsavai newstate); 12704eaa4710SRishi Srivatsavai } 12714eaa4710SRishi Srivatsavai mutex_exit(&mip->mi_bridge_lock); 12724eaa4710SRishi Srivatsavai } 12734eaa4710SRishi Srivatsavai if (newstate != mip->mi_linkstate) { 12744eaa4710SRishi Srivatsavai mip->mi_linkstate = newstate; 12754eaa4710SRishi Srivatsavai bits |= 1 << MAC_NOTE_LINK; 12764eaa4710SRishi Srivatsavai } 12774eaa4710SRishi Srivatsavai } 1278da14cebeSEric Cheng 1279da14cebeSEric Cheng /* 1280da14cebeSEric Cheng * Do notification callbacks for each notification type. 1281da14cebeSEric Cheng */ 1282da14cebeSEric Cheng for (type = 0; type < MAC_NNOTE; type++) { 1283da14cebeSEric Cheng if ((bits & (1 << type)) == 0) { 1284da14cebeSEric Cheng continue; 1285da14cebeSEric Cheng } 1286da14cebeSEric Cheng 12874eaa4710SRishi Srivatsavai if (mac_notify_cb_list[type] != NULL) 12884eaa4710SRishi Srivatsavai (*mac_notify_cb_list[type])(mip); 1289da14cebeSEric Cheng 1290da14cebeSEric Cheng /* 1291da14cebeSEric Cheng * Walk the list of notifications. 1292da14cebeSEric Cheng */ 1293da14cebeSEric Cheng MAC_CALLBACK_WALKER_INC(&mip->mi_notify_cb_info); 1294da14cebeSEric Cheng for (mcb = mip->mi_notify_cb_list; mcb != NULL; 1295da14cebeSEric Cheng mcb = mcb->mcb_nextp) { 1296da14cebeSEric Cheng mncb = (mac_notify_cb_t *)mcb->mcb_objp; 1297da14cebeSEric Cheng mncb->mncb_fn(mncb->mncb_arg, type); 1298da14cebeSEric Cheng } 1299da14cebeSEric Cheng MAC_CALLBACK_WALKER_DCR(&mip->mi_notify_cb_info, 1300da14cebeSEric Cheng &mip->mi_notify_cb_list); 1301da14cebeSEric Cheng } 1302da14cebeSEric Cheng 1303da14cebeSEric Cheng mutex_enter(mcbi->mcbi_lockp); 1304da14cebeSEric Cheng } 1305da14cebeSEric Cheng 1306da14cebeSEric Cheng mip->mi_state_flags |= MIS_NOTIFY_DONE; 1307da14cebeSEric Cheng cv_broadcast(&mcbi->mcbi_cv); 1308da14cebeSEric Cheng 1309da14cebeSEric Cheng /* CALLB_CPR_EXIT drops the lock */ 1310da14cebeSEric Cheng CALLB_CPR_EXIT(&cprinfo); 1311da14cebeSEric Cheng thread_exit(); 1312da14cebeSEric Cheng } 1313da14cebeSEric Cheng 1314da14cebeSEric Cheng /* 1315da14cebeSEric Cheng * Signal the i_mac_notify_thread asking it to quit. 1316da14cebeSEric Cheng * Then wait till it is done. 1317da14cebeSEric Cheng */ 1318da14cebeSEric Cheng void 1319da14cebeSEric Cheng i_mac_notify_exit(mac_impl_t *mip) 1320da14cebeSEric Cheng { 1321da14cebeSEric Cheng mac_cb_info_t *mcbi; 1322da14cebeSEric Cheng 1323da14cebeSEric Cheng mcbi = &mip->mi_notify_cb_info; 1324da14cebeSEric Cheng 1325da14cebeSEric Cheng mutex_enter(mcbi->mcbi_lockp); 1326da14cebeSEric Cheng mip->mi_notify_bits = (1 << MAC_NNOTE); 1327da14cebeSEric Cheng cv_broadcast(&mcbi->mcbi_cv); 1328da14cebeSEric Cheng 1329da14cebeSEric Cheng 1330da14cebeSEric Cheng while ((mip->mi_notify_thread != NULL) && 1331da14cebeSEric Cheng !(mip->mi_state_flags & MIS_NOTIFY_DONE)) { 1332da14cebeSEric Cheng cv_wait(&mcbi->mcbi_cv, mcbi->mcbi_lockp); 1333da14cebeSEric Cheng } 1334da14cebeSEric Cheng 1335da14cebeSEric Cheng /* Necessary clean up before doing kmem_cache_free */ 1336da14cebeSEric Cheng mip->mi_state_flags &= ~MIS_NOTIFY_DONE; 1337da14cebeSEric Cheng mip->mi_notify_bits = 0; 1338da14cebeSEric Cheng mip->mi_notify_thread = NULL; 1339da14cebeSEric Cheng mutex_exit(mcbi->mcbi_lockp); 1340da14cebeSEric Cheng } 1341da14cebeSEric Cheng 1342da14cebeSEric Cheng /* 1343da14cebeSEric Cheng * Entry point invoked by drivers to dynamically add a ring to an 1344da14cebeSEric Cheng * existing group. 1345da14cebeSEric Cheng */ 1346da14cebeSEric Cheng int 1347da14cebeSEric Cheng mac_group_add_ring(mac_group_handle_t gh, int index) 1348da14cebeSEric Cheng { 1349da14cebeSEric Cheng mac_group_t *group = (mac_group_t *)gh; 1350da14cebeSEric Cheng mac_impl_t *mip = (mac_impl_t *)group->mrg_mh; 1351da14cebeSEric Cheng int ret; 1352da14cebeSEric Cheng 1353da14cebeSEric Cheng i_mac_perim_enter(mip); 1354da14cebeSEric Cheng ret = i_mac_group_add_ring(group, NULL, index); 1355da14cebeSEric Cheng i_mac_perim_exit(mip); 1356da14cebeSEric Cheng return (ret); 1357da14cebeSEric Cheng } 1358da14cebeSEric Cheng 1359da14cebeSEric Cheng /* 1360da14cebeSEric Cheng * Entry point invoked by drivers to dynamically remove a ring 1361da14cebeSEric Cheng * from an existing group. The specified ring handle must no longer 1362da14cebeSEric Cheng * be used by the driver after a call to this function. 1363da14cebeSEric Cheng */ 1364da14cebeSEric Cheng void 1365da14cebeSEric Cheng mac_group_rem_ring(mac_group_handle_t gh, mac_ring_handle_t rh) 1366da14cebeSEric Cheng { 1367da14cebeSEric Cheng mac_group_t *group = (mac_group_t *)gh; 1368da14cebeSEric Cheng mac_impl_t *mip = (mac_impl_t *)group->mrg_mh; 1369da14cebeSEric Cheng 1370da14cebeSEric Cheng i_mac_perim_enter(mip); 13710dc2366fSVenugopal Iyer i_mac_group_rem_ring(group, (mac_ring_t *)rh, B_TRUE); 13720dc2366fSVenugopal Iyer i_mac_perim_exit(mip); 13730dc2366fSVenugopal Iyer } 1374da14cebeSEric Cheng 13750dc2366fSVenugopal Iyer /* 13760dc2366fSVenugopal Iyer * mac_prop_info_*() callbacks called from the driver's prefix_propinfo() 13770dc2366fSVenugopal Iyer * entry points. 13780dc2366fSVenugopal Iyer */ 1379da14cebeSEric Cheng 13800dc2366fSVenugopal Iyer void 13810dc2366fSVenugopal Iyer mac_prop_info_set_default_uint8(mac_prop_info_handle_t ph, uint8_t val) 13820dc2366fSVenugopal Iyer { 13830dc2366fSVenugopal Iyer mac_prop_info_state_t *pr = (mac_prop_info_state_t *)ph; 1384da14cebeSEric Cheng 13850dc2366fSVenugopal Iyer /* nothing to do if the caller doesn't want the default value */ 13860dc2366fSVenugopal Iyer if (pr->pr_default == NULL) 13870dc2366fSVenugopal Iyer return; 13880dc2366fSVenugopal Iyer 13890dc2366fSVenugopal Iyer ASSERT(pr->pr_default_size >= sizeof (uint8_t)); 13900dc2366fSVenugopal Iyer 13910dc2366fSVenugopal Iyer *(uint8_t *)(pr->pr_default) = val; 13920dc2366fSVenugopal Iyer pr->pr_flags |= MAC_PROP_INFO_DEFAULT; 13930dc2366fSVenugopal Iyer } 13940dc2366fSVenugopal Iyer 13950dc2366fSVenugopal Iyer void 13960dc2366fSVenugopal Iyer mac_prop_info_set_default_uint64(mac_prop_info_handle_t ph, uint64_t val) 13970dc2366fSVenugopal Iyer { 13980dc2366fSVenugopal Iyer mac_prop_info_state_t *pr = (mac_prop_info_state_t *)ph; 13990dc2366fSVenugopal Iyer 14000dc2366fSVenugopal Iyer /* nothing to do if the caller doesn't want the default value */ 14010dc2366fSVenugopal Iyer if (pr->pr_default == NULL) 14020dc2366fSVenugopal Iyer return; 14030dc2366fSVenugopal Iyer 14040dc2366fSVenugopal Iyer ASSERT(pr->pr_default_size >= sizeof (uint64_t)); 14050dc2366fSVenugopal Iyer 14060dc2366fSVenugopal Iyer bcopy(&val, pr->pr_default, sizeof (val)); 14070dc2366fSVenugopal Iyer 14080dc2366fSVenugopal Iyer pr->pr_flags |= MAC_PROP_INFO_DEFAULT; 14090dc2366fSVenugopal Iyer } 14100dc2366fSVenugopal Iyer 14110dc2366fSVenugopal Iyer void 14120dc2366fSVenugopal Iyer mac_prop_info_set_default_uint32(mac_prop_info_handle_t ph, uint32_t val) 14130dc2366fSVenugopal Iyer { 14140dc2366fSVenugopal Iyer mac_prop_info_state_t *pr = (mac_prop_info_state_t *)ph; 14150dc2366fSVenugopal Iyer 14160dc2366fSVenugopal Iyer /* nothing to do if the caller doesn't want the default value */ 14170dc2366fSVenugopal Iyer if (pr->pr_default == NULL) 14180dc2366fSVenugopal Iyer return; 14190dc2366fSVenugopal Iyer 14200dc2366fSVenugopal Iyer ASSERT(pr->pr_default_size >= sizeof (uint32_t)); 14210dc2366fSVenugopal Iyer 14220dc2366fSVenugopal Iyer bcopy(&val, pr->pr_default, sizeof (val)); 14230dc2366fSVenugopal Iyer 14240dc2366fSVenugopal Iyer pr->pr_flags |= MAC_PROP_INFO_DEFAULT; 14250dc2366fSVenugopal Iyer } 14260dc2366fSVenugopal Iyer 14270dc2366fSVenugopal Iyer void 14280dc2366fSVenugopal Iyer mac_prop_info_set_default_str(mac_prop_info_handle_t ph, const char *str) 14290dc2366fSVenugopal Iyer { 14300dc2366fSVenugopal Iyer mac_prop_info_state_t *pr = (mac_prop_info_state_t *)ph; 14310dc2366fSVenugopal Iyer 14320dc2366fSVenugopal Iyer /* nothing to do if the caller doesn't want the default value */ 14330dc2366fSVenugopal Iyer if (pr->pr_default == NULL) 14340dc2366fSVenugopal Iyer return; 14350dc2366fSVenugopal Iyer 1436f689bed1SRishi Srivatsavai if (strlen(str) >= pr->pr_default_size) 14370591ddd0SPrakash Jalan pr->pr_errno = ENOBUFS; 14380dc2366fSVenugopal Iyer else 1439f689bed1SRishi Srivatsavai (void) strlcpy(pr->pr_default, str, pr->pr_default_size); 14400dc2366fSVenugopal Iyer pr->pr_flags |= MAC_PROP_INFO_DEFAULT; 14410dc2366fSVenugopal Iyer } 14420dc2366fSVenugopal Iyer 14430dc2366fSVenugopal Iyer void 14440dc2366fSVenugopal Iyer mac_prop_info_set_default_link_flowctrl(mac_prop_info_handle_t ph, 14450dc2366fSVenugopal Iyer link_flowctrl_t val) 14460dc2366fSVenugopal Iyer { 14470dc2366fSVenugopal Iyer mac_prop_info_state_t *pr = (mac_prop_info_state_t *)ph; 14480dc2366fSVenugopal Iyer 14490dc2366fSVenugopal Iyer /* nothing to do if the caller doesn't want the default value */ 14500dc2366fSVenugopal Iyer if (pr->pr_default == NULL) 14510dc2366fSVenugopal Iyer return; 14520dc2366fSVenugopal Iyer 14530dc2366fSVenugopal Iyer ASSERT(pr->pr_default_size >= sizeof (link_flowctrl_t)); 14540dc2366fSVenugopal Iyer 14550dc2366fSVenugopal Iyer bcopy(&val, pr->pr_default, sizeof (val)); 14560dc2366fSVenugopal Iyer 14570dc2366fSVenugopal Iyer pr->pr_flags |= MAC_PROP_INFO_DEFAULT; 14580dc2366fSVenugopal Iyer } 14590dc2366fSVenugopal Iyer 14600dc2366fSVenugopal Iyer void 14610dc2366fSVenugopal Iyer mac_prop_info_set_range_uint32(mac_prop_info_handle_t ph, uint32_t min, 14620dc2366fSVenugopal Iyer uint32_t max) 14630dc2366fSVenugopal Iyer { 14640dc2366fSVenugopal Iyer mac_prop_info_state_t *pr = (mac_prop_info_state_t *)ph; 14650dc2366fSVenugopal Iyer mac_propval_range_t *range = pr->pr_range; 14660591ddd0SPrakash Jalan mac_propval_uint32_range_t *range32; 14670dc2366fSVenugopal Iyer 14680dc2366fSVenugopal Iyer /* nothing to do if the caller doesn't want the range info */ 14690dc2366fSVenugopal Iyer if (range == NULL) 14700dc2366fSVenugopal Iyer return; 14710dc2366fSVenugopal Iyer 14720591ddd0SPrakash Jalan if (pr->pr_range_cur_count++ == 0) { 14730591ddd0SPrakash Jalan /* first range */ 14740591ddd0SPrakash Jalan pr->pr_flags |= MAC_PROP_INFO_RANGE; 14750591ddd0SPrakash Jalan range->mpr_type = MAC_PROPVAL_UINT32; 14760591ddd0SPrakash Jalan } else { 14770591ddd0SPrakash Jalan /* all ranges of a property should be of the same type */ 14780591ddd0SPrakash Jalan ASSERT(range->mpr_type == MAC_PROPVAL_UINT32); 14790591ddd0SPrakash Jalan if (pr->pr_range_cur_count > range->mpr_count) { 14800591ddd0SPrakash Jalan pr->pr_errno = ENOSPC; 14810591ddd0SPrakash Jalan return; 14820591ddd0SPrakash Jalan } 14830591ddd0SPrakash Jalan } 14840591ddd0SPrakash Jalan 14850591ddd0SPrakash Jalan range32 = range->mpr_range_uint32; 14860591ddd0SPrakash Jalan range32[pr->pr_range_cur_count - 1].mpur_min = min; 14870591ddd0SPrakash Jalan range32[pr->pr_range_cur_count - 1].mpur_max = max; 14880dc2366fSVenugopal Iyer } 14890dc2366fSVenugopal Iyer 14900dc2366fSVenugopal Iyer void 14910dc2366fSVenugopal Iyer mac_prop_info_set_perm(mac_prop_info_handle_t ph, uint8_t perm) 14920dc2366fSVenugopal Iyer { 14930dc2366fSVenugopal Iyer mac_prop_info_state_t *pr = (mac_prop_info_state_t *)ph; 14940dc2366fSVenugopal Iyer 14950dc2366fSVenugopal Iyer pr->pr_perm = perm; 14960dc2366fSVenugopal Iyer pr->pr_flags |= MAC_PROP_INFO_PERM; 14970dc2366fSVenugopal Iyer } 14980dc2366fSVenugopal Iyer 14990dc2366fSVenugopal Iyer void mac_hcksum_get(mblk_t *mp, uint32_t *start, uint32_t *stuff, 15000dc2366fSVenugopal Iyer uint32_t *end, uint32_t *value, uint32_t *flags_ptr) 15010dc2366fSVenugopal Iyer { 15020dc2366fSVenugopal Iyer uint32_t flags; 15030dc2366fSVenugopal Iyer 15040dc2366fSVenugopal Iyer ASSERT(DB_TYPE(mp) == M_DATA); 15050dc2366fSVenugopal Iyer 15060dc2366fSVenugopal Iyer flags = DB_CKSUMFLAGS(mp) & HCK_FLAGS; 15070dc2366fSVenugopal Iyer if ((flags & (HCK_PARTIALCKSUM | HCK_FULLCKSUM)) != 0) { 15080dc2366fSVenugopal Iyer if (value != NULL) 15090dc2366fSVenugopal Iyer *value = (uint32_t)DB_CKSUM16(mp); 15100dc2366fSVenugopal Iyer if ((flags & HCK_PARTIALCKSUM) != 0) { 15110dc2366fSVenugopal Iyer if (start != NULL) 15120dc2366fSVenugopal Iyer *start = (uint32_t)DB_CKSUMSTART(mp); 15130dc2366fSVenugopal Iyer if (stuff != NULL) 15140dc2366fSVenugopal Iyer *stuff = (uint32_t)DB_CKSUMSTUFF(mp); 15150dc2366fSVenugopal Iyer if (end != NULL) 15160dc2366fSVenugopal Iyer *end = (uint32_t)DB_CKSUMEND(mp); 15170dc2366fSVenugopal Iyer } 15180dc2366fSVenugopal Iyer } 15190dc2366fSVenugopal Iyer 15200dc2366fSVenugopal Iyer if (flags_ptr != NULL) 15210dc2366fSVenugopal Iyer *flags_ptr = flags; 15220dc2366fSVenugopal Iyer } 15230dc2366fSVenugopal Iyer 15240dc2366fSVenugopal Iyer void mac_hcksum_set(mblk_t *mp, uint32_t start, uint32_t stuff, 15250dc2366fSVenugopal Iyer uint32_t end, uint32_t value, uint32_t flags) 15260dc2366fSVenugopal Iyer { 15270dc2366fSVenugopal Iyer ASSERT(DB_TYPE(mp) == M_DATA); 15280dc2366fSVenugopal Iyer 15290dc2366fSVenugopal Iyer DB_CKSUMSTART(mp) = (intptr_t)start; 15300dc2366fSVenugopal Iyer DB_CKSUMSTUFF(mp) = (intptr_t)stuff; 15310dc2366fSVenugopal Iyer DB_CKSUMEND(mp) = (intptr_t)end; 15320dc2366fSVenugopal Iyer DB_CKSUMFLAGS(mp) = (uint16_t)flags; 15330dc2366fSVenugopal Iyer DB_CKSUM16(mp) = (uint16_t)value; 15340dc2366fSVenugopal Iyer } 15350dc2366fSVenugopal Iyer 15360dc2366fSVenugopal Iyer void 15370dc2366fSVenugopal Iyer mac_lso_get(mblk_t *mp, uint32_t *mss, uint32_t *flags) 15380dc2366fSVenugopal Iyer { 15390dc2366fSVenugopal Iyer ASSERT(DB_TYPE(mp) == M_DATA); 15400dc2366fSVenugopal Iyer 15410dc2366fSVenugopal Iyer if (flags != NULL) { 15420dc2366fSVenugopal Iyer *flags = DB_CKSUMFLAGS(mp) & HW_LSO; 15430dc2366fSVenugopal Iyer if ((*flags != 0) && (mss != NULL)) 15440dc2366fSVenugopal Iyer *mss = (uint32_t)DB_LSOMSS(mp); 15450dc2366fSVenugopal Iyer } 1546da14cebeSEric Cheng } 154745d3dd98SRobert Mustacchi 154845d3dd98SRobert Mustacchi void 154945d3dd98SRobert Mustacchi mac_transceiver_info_set_present(mac_transceiver_info_t *infop, 155045d3dd98SRobert Mustacchi boolean_t present) 155145d3dd98SRobert Mustacchi { 155245d3dd98SRobert Mustacchi infop->mti_present = present; 155345d3dd98SRobert Mustacchi } 155445d3dd98SRobert Mustacchi 155545d3dd98SRobert Mustacchi void 155645d3dd98SRobert Mustacchi mac_transceiver_info_set_usable(mac_transceiver_info_t *infop, 155745d3dd98SRobert Mustacchi boolean_t usable) 155845d3dd98SRobert Mustacchi { 155945d3dd98SRobert Mustacchi infop->mti_usable = usable; 156045d3dd98SRobert Mustacchi } 1561*d240edafSRobert Mustacchi 1562*d240edafSRobert Mustacchi /* 1563*d240edafSRobert Mustacchi * We should really keep track of our offset and not walk everything every 1564*d240edafSRobert Mustacchi * time. I can't imagine that this will be kind to us at high packet rates; 1565*d240edafSRobert Mustacchi * however, for the moment, let's leave that. 1566*d240edafSRobert Mustacchi * 1567*d240edafSRobert Mustacchi * This walks a message block chain without pulling up to fill in the context 1568*d240edafSRobert Mustacchi * information. Note that the data we care about could be hidden across more 1569*d240edafSRobert Mustacchi * than one mblk_t. 1570*d240edafSRobert Mustacchi */ 1571*d240edafSRobert Mustacchi static int 1572*d240edafSRobert Mustacchi mac_meoi_get_uint8(mblk_t *mp, off_t off, uint8_t *out) 1573*d240edafSRobert Mustacchi { 1574*d240edafSRobert Mustacchi size_t mpsize; 1575*d240edafSRobert Mustacchi uint8_t *bp; 1576*d240edafSRobert Mustacchi 1577*d240edafSRobert Mustacchi mpsize = msgsize(mp); 1578*d240edafSRobert Mustacchi /* Check for overflow */ 1579*d240edafSRobert Mustacchi if (off + sizeof (uint16_t) > mpsize) 1580*d240edafSRobert Mustacchi return (-1); 1581*d240edafSRobert Mustacchi 1582*d240edafSRobert Mustacchi mpsize = MBLKL(mp); 1583*d240edafSRobert Mustacchi while (off >= mpsize) { 1584*d240edafSRobert Mustacchi mp = mp->b_cont; 1585*d240edafSRobert Mustacchi off -= mpsize; 1586*d240edafSRobert Mustacchi mpsize = MBLKL(mp); 1587*d240edafSRobert Mustacchi } 1588*d240edafSRobert Mustacchi 1589*d240edafSRobert Mustacchi bp = mp->b_rptr + off; 1590*d240edafSRobert Mustacchi *out = *bp; 1591*d240edafSRobert Mustacchi return (0); 1592*d240edafSRobert Mustacchi 1593*d240edafSRobert Mustacchi } 1594*d240edafSRobert Mustacchi 1595*d240edafSRobert Mustacchi static int 1596*d240edafSRobert Mustacchi mac_meoi_get_uint16(mblk_t *mp, off_t off, uint16_t *out) 1597*d240edafSRobert Mustacchi { 1598*d240edafSRobert Mustacchi size_t mpsize; 1599*d240edafSRobert Mustacchi uint8_t *bp; 1600*d240edafSRobert Mustacchi 1601*d240edafSRobert Mustacchi mpsize = msgsize(mp); 1602*d240edafSRobert Mustacchi /* Check for overflow */ 1603*d240edafSRobert Mustacchi if (off + sizeof (uint16_t) > mpsize) 1604*d240edafSRobert Mustacchi return (-1); 1605*d240edafSRobert Mustacchi 1606*d240edafSRobert Mustacchi mpsize = MBLKL(mp); 1607*d240edafSRobert Mustacchi while (off >= mpsize) { 1608*d240edafSRobert Mustacchi mp = mp->b_cont; 1609*d240edafSRobert Mustacchi off -= mpsize; 1610*d240edafSRobert Mustacchi mpsize = MBLKL(mp); 1611*d240edafSRobert Mustacchi } 1612*d240edafSRobert Mustacchi 1613*d240edafSRobert Mustacchi /* 1614*d240edafSRobert Mustacchi * Data is in network order. Note the second byte of data might be in 1615*d240edafSRobert Mustacchi * the next mp. 1616*d240edafSRobert Mustacchi */ 1617*d240edafSRobert Mustacchi bp = mp->b_rptr + off; 1618*d240edafSRobert Mustacchi *out = *bp << 8; 1619*d240edafSRobert Mustacchi if (off + 1 == mpsize) { 1620*d240edafSRobert Mustacchi mp = mp->b_cont; 1621*d240edafSRobert Mustacchi bp = mp->b_rptr; 1622*d240edafSRobert Mustacchi } else { 1623*d240edafSRobert Mustacchi bp++; 1624*d240edafSRobert Mustacchi } 1625*d240edafSRobert Mustacchi 1626*d240edafSRobert Mustacchi *out |= *bp; 1627*d240edafSRobert Mustacchi return (0); 1628*d240edafSRobert Mustacchi 1629*d240edafSRobert Mustacchi } 1630*d240edafSRobert Mustacchi 1631*d240edafSRobert Mustacchi 1632*d240edafSRobert Mustacchi int 1633*d240edafSRobert Mustacchi mac_ether_offload_info(mblk_t *mp, mac_ether_offload_info_t *meoi) 1634*d240edafSRobert Mustacchi { 1635*d240edafSRobert Mustacchi size_t off; 1636*d240edafSRobert Mustacchi uint16_t ether; 1637*d240edafSRobert Mustacchi uint8_t ipproto, iplen, l4len, maclen; 1638*d240edafSRobert Mustacchi 1639*d240edafSRobert Mustacchi bzero(meoi, sizeof (mac_ether_offload_info_t)); 1640*d240edafSRobert Mustacchi 1641*d240edafSRobert Mustacchi meoi->meoi_len = msgsize(mp); 1642*d240edafSRobert Mustacchi off = offsetof(struct ether_header, ether_type); 1643*d240edafSRobert Mustacchi if (mac_meoi_get_uint16(mp, off, ðer) != 0) 1644*d240edafSRobert Mustacchi return (-1); 1645*d240edafSRobert Mustacchi 1646*d240edafSRobert Mustacchi if (ether == ETHERTYPE_VLAN) { 1647*d240edafSRobert Mustacchi off = offsetof(struct ether_vlan_header, ether_type); 1648*d240edafSRobert Mustacchi if (mac_meoi_get_uint16(mp, off, ðer) != 0) 1649*d240edafSRobert Mustacchi return (-1); 1650*d240edafSRobert Mustacchi meoi->meoi_flags |= MEOI_VLAN_TAGGED; 1651*d240edafSRobert Mustacchi maclen = sizeof (struct ether_vlan_header); 1652*d240edafSRobert Mustacchi } else { 1653*d240edafSRobert Mustacchi maclen = sizeof (struct ether_header); 1654*d240edafSRobert Mustacchi } 1655*d240edafSRobert Mustacchi meoi->meoi_flags |= MEOI_L2INFO_SET; 1656*d240edafSRobert Mustacchi meoi->meoi_l2hlen = maclen; 1657*d240edafSRobert Mustacchi meoi->meoi_l3proto = ether; 1658*d240edafSRobert Mustacchi 1659*d240edafSRobert Mustacchi switch (ether) { 1660*d240edafSRobert Mustacchi case ETHERTYPE_IP: 1661*d240edafSRobert Mustacchi /* 1662*d240edafSRobert Mustacchi * For IPv4 we need to get the length of the header, as it can 1663*d240edafSRobert Mustacchi * be variable. 1664*d240edafSRobert Mustacchi */ 1665*d240edafSRobert Mustacchi off = offsetof(ipha_t, ipha_version_and_hdr_length) + maclen; 1666*d240edafSRobert Mustacchi if (mac_meoi_get_uint8(mp, off, &iplen) != 0) 1667*d240edafSRobert Mustacchi return (-1); 1668*d240edafSRobert Mustacchi iplen &= 0x0f; 1669*d240edafSRobert Mustacchi if (iplen < 5 || iplen > 0x0f) 1670*d240edafSRobert Mustacchi return (-1); 1671*d240edafSRobert Mustacchi iplen *= 4; 1672*d240edafSRobert Mustacchi off = offsetof(ipha_t, ipha_protocol) + maclen; 1673*d240edafSRobert Mustacchi if (mac_meoi_get_uint8(mp, off, &ipproto) == -1) 1674*d240edafSRobert Mustacchi return (-1); 1675*d240edafSRobert Mustacchi break; 1676*d240edafSRobert Mustacchi case ETHERTYPE_IPV6: 1677*d240edafSRobert Mustacchi iplen = 40; 1678*d240edafSRobert Mustacchi off = offsetof(ip6_t, ip6_nxt) + maclen; 1679*d240edafSRobert Mustacchi if (mac_meoi_get_uint8(mp, off, &ipproto) == -1) 1680*d240edafSRobert Mustacchi return (-1); 1681*d240edafSRobert Mustacchi break; 1682*d240edafSRobert Mustacchi default: 1683*d240edafSRobert Mustacchi return (0); 1684*d240edafSRobert Mustacchi } 1685*d240edafSRobert Mustacchi meoi->meoi_l3hlen = iplen; 1686*d240edafSRobert Mustacchi meoi->meoi_l4proto = ipproto; 1687*d240edafSRobert Mustacchi meoi->meoi_flags |= MEOI_L3INFO_SET; 1688*d240edafSRobert Mustacchi 1689*d240edafSRobert Mustacchi switch (ipproto) { 1690*d240edafSRobert Mustacchi case IPPROTO_TCP: 1691*d240edafSRobert Mustacchi off = offsetof(tcph_t, th_offset_and_rsrvd) + maclen + iplen; 1692*d240edafSRobert Mustacchi if (mac_meoi_get_uint8(mp, off, &l4len) == -1) 1693*d240edafSRobert Mustacchi return (-1); 1694*d240edafSRobert Mustacchi l4len = (l4len & 0xf0) >> 4; 1695*d240edafSRobert Mustacchi if (l4len < 5 || l4len > 0xf) 1696*d240edafSRobert Mustacchi return (-1); 1697*d240edafSRobert Mustacchi l4len *= 4; 1698*d240edafSRobert Mustacchi break; 1699*d240edafSRobert Mustacchi case IPPROTO_UDP: 1700*d240edafSRobert Mustacchi l4len = sizeof (struct udphdr); 1701*d240edafSRobert Mustacchi break; 1702*d240edafSRobert Mustacchi case IPPROTO_SCTP: 1703*d240edafSRobert Mustacchi l4len = sizeof (sctp_hdr_t); 1704*d240edafSRobert Mustacchi break; 1705*d240edafSRobert Mustacchi default: 1706*d240edafSRobert Mustacchi return (0); 1707*d240edafSRobert Mustacchi } 1708*d240edafSRobert Mustacchi 1709*d240edafSRobert Mustacchi meoi->meoi_l4hlen = l4len; 1710*d240edafSRobert Mustacchi meoi->meoi_flags |= MEOI_L4INFO_SET; 1711*d240edafSRobert Mustacchi return (0); 1712*d240edafSRobert Mustacchi } 1713