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 /* 23ae6aa22aSVenugopal Iyer * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 24da14cebeSEric Cheng * Use is subject to license terms. 25da14cebeSEric Cheng */ 26da14cebeSEric Cheng 27da14cebeSEric Cheng #include <sys/types.h> 28da14cebeSEric Cheng #include <sys/conf.h> 29da14cebeSEric Cheng #include <sys/id_space.h> 30da14cebeSEric Cheng #include <sys/esunddi.h> 31da14cebeSEric Cheng #include <sys/stat.h> 32da14cebeSEric Cheng #include <sys/mkdev.h> 33da14cebeSEric Cheng #include <sys/stream.h> 34da14cebeSEric Cheng #include <sys/strsubr.h> 35da14cebeSEric Cheng #include <sys/dlpi.h> 36da14cebeSEric Cheng #include <sys/modhash.h> 37da14cebeSEric Cheng #include <sys/mac.h> 38da14cebeSEric Cheng #include <sys/mac_provider.h> 39da14cebeSEric Cheng #include <sys/mac_impl.h> 40da14cebeSEric Cheng #include <sys/mac_client_impl.h> 41da14cebeSEric Cheng #include <sys/mac_client_priv.h> 42da14cebeSEric Cheng #include <sys/mac_soft_ring.h> 43*61af1958SGarrett D'Amore #include <sys/dld.h> 44da14cebeSEric Cheng #include <sys/modctl.h> 45da14cebeSEric Cheng #include <sys/fs/dv_node.h> 46da14cebeSEric Cheng #include <sys/thread.h> 47da14cebeSEric Cheng #include <sys/proc.h> 48da14cebeSEric Cheng #include <sys/callb.h> 49da14cebeSEric Cheng #include <sys/cpuvar.h> 50da14cebeSEric Cheng #include <sys/atomic.h> 51da14cebeSEric Cheng #include <sys/sdt.h> 52da14cebeSEric Cheng #include <sys/mac_flow.h> 53da14cebeSEric Cheng #include <sys/ddi_intr_impl.h> 54da14cebeSEric Cheng #include <sys/disp.h> 55da14cebeSEric Cheng #include <sys/sdt.h> 56da14cebeSEric Cheng 57da14cebeSEric Cheng /* 58da14cebeSEric Cheng * MAC Provider Interface. 59da14cebeSEric Cheng * 60da14cebeSEric Cheng * Interface for GLDv3 compatible NIC drivers. 61da14cebeSEric Cheng */ 62da14cebeSEric Cheng 63da14cebeSEric Cheng static void i_mac_notify_thread(void *); 64da14cebeSEric Cheng 65da14cebeSEric Cheng typedef void (*mac_notify_default_cb_fn_t)(mac_impl_t *); 66da14cebeSEric Cheng 674eaa4710SRishi Srivatsavai static const mac_notify_default_cb_fn_t mac_notify_cb_list[MAC_NNOTE] = { 684eaa4710SRishi Srivatsavai mac_fanout_recompute, /* MAC_NOTE_LINK */ 694eaa4710SRishi Srivatsavai NULL, /* MAC_NOTE_UNICST */ 704eaa4710SRishi Srivatsavai NULL, /* MAC_NOTE_TX */ 714eaa4710SRishi Srivatsavai NULL, /* MAC_NOTE_DEVPROMISC */ 724eaa4710SRishi Srivatsavai NULL, /* MAC_NOTE_FASTPATH_FLUSH */ 734eaa4710SRishi Srivatsavai NULL, /* MAC_NOTE_SDU_SIZE */ 744eaa4710SRishi Srivatsavai NULL, /* MAC_NOTE_MARGIN */ 754eaa4710SRishi Srivatsavai NULL, /* MAC_NOTE_CAPAB_CHG */ 764eaa4710SRishi Srivatsavai NULL /* MAC_NOTE_LOWLINK */ 77da14cebeSEric Cheng }; 78da14cebeSEric Cheng 79da14cebeSEric Cheng /* 80da14cebeSEric Cheng * Driver support functions. 81da14cebeSEric Cheng */ 82da14cebeSEric Cheng 83da14cebeSEric Cheng /* REGISTRATION */ 84da14cebeSEric Cheng 85da14cebeSEric Cheng mac_register_t * 86da14cebeSEric Cheng mac_alloc(uint_t mac_version) 87da14cebeSEric Cheng { 88da14cebeSEric Cheng mac_register_t *mregp; 89da14cebeSEric Cheng 90da14cebeSEric Cheng /* 91da14cebeSEric Cheng * Make sure there isn't a version mismatch between the driver and 92da14cebeSEric Cheng * the framework. In the future, if multiple versions are 93da14cebeSEric Cheng * supported, this check could become more sophisticated. 94da14cebeSEric Cheng */ 95da14cebeSEric Cheng if (mac_version != MAC_VERSION) 96da14cebeSEric Cheng return (NULL); 97da14cebeSEric Cheng 98da14cebeSEric Cheng mregp = kmem_zalloc(sizeof (mac_register_t), KM_SLEEP); 99da14cebeSEric Cheng mregp->m_version = mac_version; 100da14cebeSEric Cheng return (mregp); 101da14cebeSEric Cheng } 102da14cebeSEric Cheng 103da14cebeSEric Cheng void 104da14cebeSEric Cheng mac_free(mac_register_t *mregp) 105da14cebeSEric Cheng { 106da14cebeSEric Cheng kmem_free(mregp, sizeof (mac_register_t)); 107da14cebeSEric Cheng } 108da14cebeSEric Cheng 109da14cebeSEric Cheng /* 110da14cebeSEric Cheng * mac_register() is how drivers register new MACs with the GLDv3 111da14cebeSEric Cheng * framework. The mregp argument is allocated by drivers using the 112da14cebeSEric Cheng * mac_alloc() function, and can be freed using mac_free() immediately upon 113da14cebeSEric Cheng * return from mac_register(). Upon success (0 return value), the mhp 114da14cebeSEric Cheng * opaque pointer becomes the driver's handle to its MAC interface, and is 115da14cebeSEric Cheng * the argument to all other mac module entry points. 116da14cebeSEric Cheng */ 117da14cebeSEric Cheng /* ARGSUSED */ 118da14cebeSEric Cheng int 119da14cebeSEric Cheng mac_register(mac_register_t *mregp, mac_handle_t *mhp) 120da14cebeSEric Cheng { 121da14cebeSEric Cheng mac_impl_t *mip; 122da14cebeSEric Cheng mactype_t *mtype; 123da14cebeSEric Cheng int err = EINVAL; 124da14cebeSEric Cheng struct devnames *dnp = NULL; 125da14cebeSEric Cheng uint_t instance; 126da14cebeSEric Cheng boolean_t style1_created = B_FALSE; 127da14cebeSEric Cheng boolean_t style2_created = B_FALSE; 128da14cebeSEric Cheng char *driver; 129da14cebeSEric Cheng minor_t minor = 0; 130da14cebeSEric Cheng 131da14cebeSEric Cheng /* Find the required MAC-Type plugin. */ 132da14cebeSEric Cheng if ((mtype = mactype_getplugin(mregp->m_type_ident)) == NULL) 133da14cebeSEric Cheng return (EINVAL); 134da14cebeSEric Cheng 135da14cebeSEric Cheng /* Create a mac_impl_t to represent this MAC. */ 136da14cebeSEric Cheng mip = kmem_cache_alloc(i_mac_impl_cachep, KM_SLEEP); 137da14cebeSEric Cheng 138da14cebeSEric Cheng /* 139da14cebeSEric Cheng * The mac is not ready for open yet. 140da14cebeSEric Cheng */ 141da14cebeSEric Cheng mip->mi_state_flags |= MIS_DISABLED; 142da14cebeSEric Cheng 143da14cebeSEric Cheng /* 144da14cebeSEric Cheng * When a mac is registered, the m_instance field can be set to: 145da14cebeSEric Cheng * 146da14cebeSEric Cheng * 0: Get the mac's instance number from m_dip. 147da14cebeSEric Cheng * This is usually used for physical device dips. 148da14cebeSEric Cheng * 149da14cebeSEric Cheng * [1 .. MAC_MAX_MINOR-1]: Use the value as the mac's instance number. 150da14cebeSEric Cheng * For example, when an aggregation is created with the key option, 151da14cebeSEric Cheng * "key" will be used as the instance number. 152da14cebeSEric Cheng * 153da14cebeSEric Cheng * -1: Assign an instance number from [MAC_MAX_MINOR .. MAXMIN-1]. 154da14cebeSEric Cheng * This is often used when a MAC of a virtual link is registered 155da14cebeSEric Cheng * (e.g., aggregation when "key" is not specified, or vnic). 156da14cebeSEric Cheng * 157da14cebeSEric Cheng * Note that the instance number is used to derive the mi_minor field 158da14cebeSEric Cheng * of mac_impl_t, which will then be used to derive the name of kstats 159da14cebeSEric Cheng * and the devfs nodes. The first 2 cases are needed to preserve 160da14cebeSEric Cheng * backward compatibility. 161da14cebeSEric Cheng */ 162da14cebeSEric Cheng switch (mregp->m_instance) { 163da14cebeSEric Cheng case 0: 164da14cebeSEric Cheng instance = ddi_get_instance(mregp->m_dip); 165da14cebeSEric Cheng break; 166da14cebeSEric Cheng case ((uint_t)-1): 167da14cebeSEric Cheng minor = mac_minor_hold(B_TRUE); 168da14cebeSEric Cheng if (minor == 0) { 169da14cebeSEric Cheng err = ENOSPC; 170da14cebeSEric Cheng goto fail; 171da14cebeSEric Cheng } 172da14cebeSEric Cheng instance = minor - 1; 173da14cebeSEric Cheng break; 174da14cebeSEric Cheng default: 175da14cebeSEric Cheng instance = mregp->m_instance; 176da14cebeSEric Cheng if (instance >= MAC_MAX_MINOR) { 177da14cebeSEric Cheng err = EINVAL; 178da14cebeSEric Cheng goto fail; 179da14cebeSEric Cheng } 180da14cebeSEric Cheng break; 181da14cebeSEric Cheng } 182da14cebeSEric Cheng 183da14cebeSEric Cheng mip->mi_minor = (minor_t)(instance + 1); 184da14cebeSEric Cheng mip->mi_dip = mregp->m_dip; 185da14cebeSEric Cheng mip->mi_clients_list = NULL; 186da14cebeSEric Cheng mip->mi_nclients = 0; 187da14cebeSEric Cheng 1884eaa4710SRishi Srivatsavai /* Set the default IEEE Port VLAN Identifier */ 1894eaa4710SRishi Srivatsavai mip->mi_pvid = 1; 1904eaa4710SRishi Srivatsavai 1914eaa4710SRishi Srivatsavai /* Default bridge link learning protection values */ 1924eaa4710SRishi Srivatsavai mip->mi_llimit = 1000; 1934eaa4710SRishi Srivatsavai mip->mi_ldecay = 200; 1944eaa4710SRishi Srivatsavai 195da14cebeSEric Cheng driver = (char *)ddi_driver_name(mip->mi_dip); 196da14cebeSEric Cheng 197da14cebeSEric Cheng /* Construct the MAC name as <drvname><instance> */ 198da14cebeSEric Cheng (void) snprintf(mip->mi_name, sizeof (mip->mi_name), "%s%d", 199da14cebeSEric Cheng driver, instance); 200da14cebeSEric Cheng 201da14cebeSEric Cheng mip->mi_driver = mregp->m_driver; 202da14cebeSEric Cheng 203da14cebeSEric Cheng mip->mi_type = mtype; 204da14cebeSEric Cheng mip->mi_margin = mregp->m_margin; 205da14cebeSEric Cheng mip->mi_info.mi_media = mtype->mt_type; 206da14cebeSEric Cheng mip->mi_info.mi_nativemedia = mtype->mt_nativetype; 207da14cebeSEric Cheng if (mregp->m_max_sdu <= mregp->m_min_sdu) 208da14cebeSEric Cheng goto fail; 209da14cebeSEric Cheng mip->mi_sdu_min = mregp->m_min_sdu; 210da14cebeSEric Cheng mip->mi_sdu_max = mregp->m_max_sdu; 211da14cebeSEric Cheng mip->mi_info.mi_addr_length = mip->mi_type->mt_addr_length; 212da14cebeSEric Cheng /* 213da14cebeSEric Cheng * If the media supports a broadcast address, cache a pointer to it 214da14cebeSEric Cheng * in the mac_info_t so that upper layers can use it. 215da14cebeSEric Cheng */ 216da14cebeSEric Cheng mip->mi_info.mi_brdcst_addr = mip->mi_type->mt_brdcst_addr; 217da14cebeSEric Cheng 218da14cebeSEric Cheng mip->mi_v12n_level = mregp->m_v12n; 219da14cebeSEric Cheng 220da14cebeSEric Cheng /* 221da14cebeSEric Cheng * Copy the unicast source address into the mac_info_t, but only if 222da14cebeSEric Cheng * the MAC-Type defines a non-zero address length. We need to 223da14cebeSEric Cheng * handle MAC-Types that have an address length of 0 224da14cebeSEric Cheng * (point-to-point protocol MACs for example). 225da14cebeSEric Cheng */ 226da14cebeSEric Cheng if (mip->mi_type->mt_addr_length > 0) { 227da14cebeSEric Cheng if (mregp->m_src_addr == NULL) 228da14cebeSEric Cheng goto fail; 229da14cebeSEric Cheng mip->mi_info.mi_unicst_addr = 230da14cebeSEric Cheng kmem_alloc(mip->mi_type->mt_addr_length, KM_SLEEP); 231da14cebeSEric Cheng bcopy(mregp->m_src_addr, mip->mi_info.mi_unicst_addr, 232da14cebeSEric Cheng mip->mi_type->mt_addr_length); 233da14cebeSEric Cheng 234da14cebeSEric Cheng /* 235da14cebeSEric Cheng * Copy the fixed 'factory' MAC address from the immutable 236da14cebeSEric Cheng * info. This is taken to be the MAC address currently in 237da14cebeSEric Cheng * use. 238da14cebeSEric Cheng */ 239da14cebeSEric Cheng bcopy(mip->mi_info.mi_unicst_addr, mip->mi_addr, 240da14cebeSEric Cheng mip->mi_type->mt_addr_length); 241da14cebeSEric Cheng 242da14cebeSEric Cheng /* 243da14cebeSEric Cheng * At this point, we should set up the classification 244da14cebeSEric Cheng * rules etc but we delay it till mac_open() so that 245da14cebeSEric Cheng * the resource discovery has taken place and we 246da14cebeSEric Cheng * know someone wants to use the device. Otherwise 247da14cebeSEric Cheng * memory gets allocated for Rx ring structures even 248da14cebeSEric Cheng * during probe. 249da14cebeSEric Cheng */ 250da14cebeSEric Cheng 251da14cebeSEric Cheng /* Copy the destination address if one is provided. */ 252da14cebeSEric Cheng if (mregp->m_dst_addr != NULL) { 253da14cebeSEric Cheng bcopy(mregp->m_dst_addr, mip->mi_dstaddr, 254da14cebeSEric Cheng mip->mi_type->mt_addr_length); 2552b24ab6bSSebastien Roy mip->mi_dstaddr_set = B_TRUE; 256da14cebeSEric Cheng } 257da14cebeSEric Cheng } else if (mregp->m_src_addr != NULL) { 258da14cebeSEric Cheng goto fail; 259da14cebeSEric Cheng } 260da14cebeSEric Cheng 261da14cebeSEric Cheng /* 262da14cebeSEric Cheng * The format of the m_pdata is specific to the plugin. It is 263da14cebeSEric Cheng * passed in as an argument to all of the plugin callbacks. The 264da14cebeSEric Cheng * driver can update this information by calling 265da14cebeSEric Cheng * mac_pdata_update(). 266da14cebeSEric Cheng */ 2672b24ab6bSSebastien Roy if (mip->mi_type->mt_ops.mtops_ops & MTOPS_PDATA_VERIFY) { 268da14cebeSEric Cheng /* 2692b24ab6bSSebastien Roy * Verify if the supplied plugin data is valid. Note that 2702b24ab6bSSebastien Roy * even if the caller passed in a NULL pointer as plugin data, 2712b24ab6bSSebastien Roy * we still need to verify if that's valid as the plugin may 2722b24ab6bSSebastien Roy * require plugin data to function. 273da14cebeSEric Cheng */ 274da14cebeSEric Cheng if (!mip->mi_type->mt_ops.mtops_pdata_verify(mregp->m_pdata, 275da14cebeSEric Cheng mregp->m_pdata_size)) { 276da14cebeSEric Cheng goto fail; 277da14cebeSEric Cheng } 2782b24ab6bSSebastien Roy if (mregp->m_pdata != NULL) { 2792b24ab6bSSebastien Roy mip->mi_pdata = 2802b24ab6bSSebastien Roy kmem_alloc(mregp->m_pdata_size, KM_SLEEP); 2812b24ab6bSSebastien Roy bcopy(mregp->m_pdata, mip->mi_pdata, 2822b24ab6bSSebastien Roy mregp->m_pdata_size); 2832b24ab6bSSebastien Roy mip->mi_pdata_size = mregp->m_pdata_size; 2842b24ab6bSSebastien Roy } 2852b24ab6bSSebastien Roy } else if (mregp->m_pdata != NULL) { 2862b24ab6bSSebastien Roy /* 2872b24ab6bSSebastien Roy * The caller supplied non-NULL plugin data, but the plugin 2882b24ab6bSSebastien Roy * does not recognize plugin data. 2892b24ab6bSSebastien Roy */ 2902b24ab6bSSebastien Roy err = EINVAL; 2912b24ab6bSSebastien Roy goto fail; 292da14cebeSEric Cheng } 293da14cebeSEric Cheng 294da14cebeSEric Cheng /* 295da14cebeSEric Cheng * Register the private properties. 296da14cebeSEric Cheng */ 297da14cebeSEric Cheng mac_register_priv_prop(mip, mregp->m_priv_props, 298da14cebeSEric Cheng mregp->m_priv_prop_count); 299da14cebeSEric Cheng 300da14cebeSEric Cheng /* 301da14cebeSEric Cheng * Stash the driver callbacks into the mac_impl_t, but first sanity 302da14cebeSEric Cheng * check to make sure all mandatory callbacks are set. 303da14cebeSEric Cheng */ 304da14cebeSEric Cheng if (mregp->m_callbacks->mc_getstat == NULL || 305da14cebeSEric Cheng mregp->m_callbacks->mc_start == NULL || 306da14cebeSEric Cheng mregp->m_callbacks->mc_stop == NULL || 307da14cebeSEric Cheng mregp->m_callbacks->mc_setpromisc == NULL || 308da14cebeSEric Cheng mregp->m_callbacks->mc_multicst == NULL) { 309da14cebeSEric Cheng goto fail; 310da14cebeSEric Cheng } 311da14cebeSEric Cheng mip->mi_callbacks = mregp->m_callbacks; 312da14cebeSEric Cheng 3135d460eafSCathy Zhou if (mac_capab_get((mac_handle_t)mip, MAC_CAPAB_LEGACY, 3145d460eafSCathy Zhou &mip->mi_capab_legacy)) { 315da14cebeSEric Cheng mip->mi_state_flags |= MIS_LEGACY; 3165d460eafSCathy Zhou mip->mi_phy_dev = mip->mi_capab_legacy.ml_dev; 317da14cebeSEric Cheng } else { 318da14cebeSEric Cheng mip->mi_phy_dev = makedevice(ddi_driver_major(mip->mi_dip), 319*61af1958SGarrett D'Amore mip->mi_minor); 320da14cebeSEric Cheng } 321da14cebeSEric Cheng 322da14cebeSEric Cheng /* 323da14cebeSEric Cheng * Allocate a notification thread. thread_create blocks for memory 324da14cebeSEric Cheng * if needed, it never fails. 325da14cebeSEric Cheng */ 326da14cebeSEric Cheng mip->mi_notify_thread = thread_create(NULL, 0, i_mac_notify_thread, 327da14cebeSEric Cheng mip, 0, &p0, TS_RUN, minclsyspri); 328da14cebeSEric Cheng 329da14cebeSEric Cheng /* 330da14cebeSEric Cheng * Initialize the capabilities 331da14cebeSEric Cheng */ 332da14cebeSEric Cheng 333da14cebeSEric Cheng if (i_mac_capab_get((mac_handle_t)mip, MAC_CAPAB_VNIC, NULL)) 334da14cebeSEric Cheng mip->mi_state_flags |= MIS_IS_VNIC; 335da14cebeSEric Cheng 336da14cebeSEric Cheng if (i_mac_capab_get((mac_handle_t)mip, MAC_CAPAB_AGGR, NULL)) 337da14cebeSEric Cheng mip->mi_state_flags |= MIS_IS_AGGR; 338da14cebeSEric Cheng 339da14cebeSEric Cheng mac_addr_factory_init(mip); 340da14cebeSEric Cheng 341da14cebeSEric Cheng /* 342da14cebeSEric Cheng * Enforce the virtrualization level registered. 343da14cebeSEric Cheng */ 344da14cebeSEric Cheng if (mip->mi_v12n_level & MAC_VIRT_LEVEL1) { 345da14cebeSEric Cheng if (mac_init_rings(mip, MAC_RING_TYPE_RX) != 0 || 346da14cebeSEric Cheng mac_init_rings(mip, MAC_RING_TYPE_TX) != 0) 347da14cebeSEric Cheng goto fail; 348da14cebeSEric Cheng 349da14cebeSEric Cheng /* 350da14cebeSEric Cheng * The driver needs to register at least rx rings for this 351da14cebeSEric Cheng * virtualization level. 352da14cebeSEric Cheng */ 353da14cebeSEric Cheng if (mip->mi_rx_groups == NULL) 354da14cebeSEric Cheng goto fail; 355da14cebeSEric Cheng } 356da14cebeSEric Cheng 357da14cebeSEric Cheng /* 358da14cebeSEric Cheng * The driver must set mc_unicst entry point to NULL when it advertises 359da14cebeSEric Cheng * CAP_RINGS for rx groups. 360da14cebeSEric Cheng */ 361da14cebeSEric Cheng if (mip->mi_rx_groups != NULL) { 362da14cebeSEric Cheng if (mregp->m_callbacks->mc_unicst != NULL) 363da14cebeSEric Cheng goto fail; 364da14cebeSEric Cheng } else { 365da14cebeSEric Cheng if (mregp->m_callbacks->mc_unicst == NULL) 366da14cebeSEric Cheng goto fail; 367da14cebeSEric Cheng } 368da14cebeSEric Cheng 369da14cebeSEric Cheng /* 370da14cebeSEric Cheng * The driver must set mc_tx entry point to NULL when it advertises 371da14cebeSEric Cheng * CAP_RINGS for tx rings. 372da14cebeSEric Cheng */ 373da14cebeSEric Cheng if (mip->mi_tx_groups != NULL) { 374da14cebeSEric Cheng if (mregp->m_callbacks->mc_tx != NULL) 375da14cebeSEric Cheng goto fail; 376da14cebeSEric Cheng } else { 377da14cebeSEric Cheng if (mregp->m_callbacks->mc_tx == NULL) 378da14cebeSEric Cheng goto fail; 379da14cebeSEric Cheng } 380da14cebeSEric Cheng 381da14cebeSEric Cheng /* 382da14cebeSEric Cheng * Initialize MAC addresses. Must be called after mac_init_rings(). 383da14cebeSEric Cheng */ 384da14cebeSEric Cheng mac_init_macaddr(mip); 385da14cebeSEric Cheng 386da14cebeSEric Cheng mip->mi_share_capab.ms_snum = 0; 387da14cebeSEric Cheng if (mip->mi_v12n_level & MAC_VIRT_HIO) { 388da14cebeSEric Cheng (void) mac_capab_get((mac_handle_t)mip, MAC_CAPAB_SHARES, 389da14cebeSEric Cheng &mip->mi_share_capab); 390da14cebeSEric Cheng } 391da14cebeSEric Cheng 392da14cebeSEric Cheng /* 393da14cebeSEric Cheng * Initialize the kstats for this device. 394da14cebeSEric Cheng */ 395da14cebeSEric Cheng mac_stat_create(mip); 396da14cebeSEric Cheng 397da14cebeSEric Cheng /* Zero out any properties. */ 398da14cebeSEric Cheng bzero(&mip->mi_resource_props, sizeof (mac_resource_props_t)); 399da14cebeSEric Cheng 400da14cebeSEric Cheng /* set the gldv3 flag in dn_flags */ 401da14cebeSEric Cheng dnp = &devnamesp[ddi_driver_major(mip->mi_dip)]; 402da14cebeSEric Cheng LOCK_DEV_OPS(&dnp->dn_lock); 403da14cebeSEric Cheng dnp->dn_flags |= (DN_GLDV3_DRIVER | DN_NETWORK_DRIVER); 404da14cebeSEric Cheng UNLOCK_DEV_OPS(&dnp->dn_lock); 405da14cebeSEric Cheng 406da14cebeSEric Cheng if (mip->mi_minor < MAC_MAX_MINOR + 1) { 407da14cebeSEric Cheng /* Create a style-2 DLPI device */ 408da14cebeSEric Cheng if (ddi_create_minor_node(mip->mi_dip, driver, S_IFCHR, 0, 409da14cebeSEric Cheng DDI_NT_NET, CLONE_DEV) != DDI_SUCCESS) 410da14cebeSEric Cheng goto fail; 411da14cebeSEric Cheng style2_created = B_TRUE; 412da14cebeSEric Cheng 413da14cebeSEric Cheng /* Create a style-1 DLPI device */ 414da14cebeSEric Cheng if (ddi_create_minor_node(mip->mi_dip, mip->mi_name, S_IFCHR, 415da14cebeSEric Cheng mip->mi_minor, DDI_NT_NET, 0) != DDI_SUCCESS) 416da14cebeSEric Cheng goto fail; 417da14cebeSEric Cheng style1_created = B_TRUE; 418da14cebeSEric Cheng } 419da14cebeSEric Cheng 420da14cebeSEric Cheng mac_flow_l2tab_create(mip, &mip->mi_flow_tab); 421da14cebeSEric Cheng 422da14cebeSEric Cheng rw_enter(&i_mac_impl_lock, RW_WRITER); 423da14cebeSEric Cheng if (mod_hash_insert(i_mac_impl_hash, 424da14cebeSEric Cheng (mod_hash_key_t)mip->mi_name, (mod_hash_val_t)mip) != 0) { 425da14cebeSEric Cheng rw_exit(&i_mac_impl_lock); 426da14cebeSEric Cheng err = EEXIST; 427da14cebeSEric Cheng goto fail; 428da14cebeSEric Cheng } 429da14cebeSEric Cheng 430da14cebeSEric Cheng DTRACE_PROBE2(mac__register, struct devnames *, dnp, 431da14cebeSEric Cheng (mac_impl_t *), mip); 432da14cebeSEric Cheng 433da14cebeSEric Cheng /* 434da14cebeSEric Cheng * Mark the MAC to be ready for open. 435da14cebeSEric Cheng */ 436da14cebeSEric Cheng mip->mi_state_flags &= ~MIS_DISABLED; 437da14cebeSEric Cheng rw_exit(&i_mac_impl_lock); 438da14cebeSEric Cheng 439da14cebeSEric Cheng atomic_inc_32(&i_mac_impl_count); 440da14cebeSEric Cheng 441da14cebeSEric Cheng cmn_err(CE_NOTE, "!%s registered", mip->mi_name); 442da14cebeSEric Cheng *mhp = (mac_handle_t)mip; 443da14cebeSEric Cheng return (0); 444da14cebeSEric Cheng 445da14cebeSEric Cheng fail: 446da14cebeSEric Cheng if (style1_created) 447da14cebeSEric Cheng ddi_remove_minor_node(mip->mi_dip, mip->mi_name); 448da14cebeSEric Cheng 449da14cebeSEric Cheng if (style2_created) 450da14cebeSEric Cheng ddi_remove_minor_node(mip->mi_dip, driver); 451da14cebeSEric Cheng 452da14cebeSEric Cheng mac_addr_factory_fini(mip); 453da14cebeSEric Cheng 454da14cebeSEric Cheng /* Clean up registered MAC addresses */ 455da14cebeSEric Cheng mac_fini_macaddr(mip); 456da14cebeSEric Cheng 457da14cebeSEric Cheng /* Clean up registered rings */ 458da14cebeSEric Cheng mac_free_rings(mip, MAC_RING_TYPE_RX); 459da14cebeSEric Cheng mac_free_rings(mip, MAC_RING_TYPE_TX); 460da14cebeSEric Cheng 461da14cebeSEric Cheng /* Clean up notification thread */ 462da14cebeSEric Cheng if (mip->mi_notify_thread != NULL) 463da14cebeSEric Cheng i_mac_notify_exit(mip); 464da14cebeSEric Cheng 465da14cebeSEric Cheng if (mip->mi_info.mi_unicst_addr != NULL) { 466da14cebeSEric Cheng kmem_free(mip->mi_info.mi_unicst_addr, 467da14cebeSEric Cheng mip->mi_type->mt_addr_length); 468da14cebeSEric Cheng mip->mi_info.mi_unicst_addr = NULL; 469da14cebeSEric Cheng } 470da14cebeSEric Cheng 471da14cebeSEric Cheng mac_stat_destroy(mip); 472da14cebeSEric Cheng 473da14cebeSEric Cheng if (mip->mi_type != NULL) { 474da14cebeSEric Cheng atomic_dec_32(&mip->mi_type->mt_ref); 475da14cebeSEric Cheng mip->mi_type = NULL; 476da14cebeSEric Cheng } 477da14cebeSEric Cheng 478da14cebeSEric Cheng if (mip->mi_pdata != NULL) { 479da14cebeSEric Cheng kmem_free(mip->mi_pdata, mip->mi_pdata_size); 480da14cebeSEric Cheng mip->mi_pdata = NULL; 481da14cebeSEric Cheng mip->mi_pdata_size = 0; 482da14cebeSEric Cheng } 483da14cebeSEric Cheng 484da14cebeSEric Cheng if (minor != 0) { 485da14cebeSEric Cheng ASSERT(minor > MAC_MAX_MINOR); 486da14cebeSEric Cheng mac_minor_rele(minor); 487da14cebeSEric Cheng } 488da14cebeSEric Cheng 489da14cebeSEric Cheng mac_unregister_priv_prop(mip); 490da14cebeSEric Cheng 491da14cebeSEric Cheng kmem_cache_free(i_mac_impl_cachep, mip); 492da14cebeSEric Cheng return (err); 493da14cebeSEric Cheng } 494da14cebeSEric Cheng 495da14cebeSEric Cheng /* 496da14cebeSEric Cheng * Unregister from the GLDv3 framework 497da14cebeSEric Cheng */ 498da14cebeSEric Cheng int 499da14cebeSEric Cheng mac_unregister(mac_handle_t mh) 500da14cebeSEric Cheng { 501da14cebeSEric Cheng int err; 502da14cebeSEric Cheng mac_impl_t *mip = (mac_impl_t *)mh; 503da14cebeSEric Cheng mod_hash_val_t val; 504da14cebeSEric Cheng mac_margin_req_t *mmr, *nextmmr; 505da14cebeSEric Cheng 506da14cebeSEric Cheng /* Fail the unregister if there are any open references to this mac. */ 507da14cebeSEric Cheng if ((err = mac_disable_nowait(mh)) != 0) 508da14cebeSEric Cheng return (err); 509da14cebeSEric Cheng 510da14cebeSEric Cheng /* 511da14cebeSEric Cheng * Clean up notification thread and wait for it to exit. 512da14cebeSEric Cheng */ 513da14cebeSEric Cheng i_mac_notify_exit(mip); 514da14cebeSEric Cheng 515da14cebeSEric Cheng i_mac_perim_enter(mip); 516da14cebeSEric Cheng 5175d460eafSCathy Zhou /* 5185d460eafSCathy Zhou * There is still resource properties configured over this mac. 5195d460eafSCathy Zhou */ 5205d460eafSCathy Zhou if (mip->mi_resource_props.mrp_mask != 0) 5215d460eafSCathy Zhou mac_fastpath_enable((mac_handle_t)mip); 5225d460eafSCathy Zhou 523da14cebeSEric Cheng if (mip->mi_minor < MAC_MAX_MINOR + 1) { 524da14cebeSEric Cheng ddi_remove_minor_node(mip->mi_dip, mip->mi_name); 525da14cebeSEric Cheng ddi_remove_minor_node(mip->mi_dip, 526da14cebeSEric Cheng (char *)ddi_driver_name(mip->mi_dip)); 527da14cebeSEric Cheng } 528da14cebeSEric Cheng 529da14cebeSEric Cheng ASSERT(mip->mi_nactiveclients == 0 && !(mip->mi_state_flags & 530da14cebeSEric Cheng MIS_EXCLUSIVE)); 531da14cebeSEric Cheng 532da14cebeSEric Cheng mac_stat_destroy(mip); 533da14cebeSEric Cheng 534da14cebeSEric Cheng (void) mod_hash_remove(i_mac_impl_hash, 535da14cebeSEric Cheng (mod_hash_key_t)mip->mi_name, &val); 536da14cebeSEric Cheng ASSERT(mip == (mac_impl_t *)val); 537da14cebeSEric Cheng 538da14cebeSEric Cheng ASSERT(i_mac_impl_count > 0); 539da14cebeSEric Cheng atomic_dec_32(&i_mac_impl_count); 540da14cebeSEric Cheng 541da14cebeSEric Cheng if (mip->mi_pdata != NULL) 542da14cebeSEric Cheng kmem_free(mip->mi_pdata, mip->mi_pdata_size); 543da14cebeSEric Cheng mip->mi_pdata = NULL; 544da14cebeSEric Cheng mip->mi_pdata_size = 0; 545da14cebeSEric Cheng 546da14cebeSEric Cheng /* 547da14cebeSEric Cheng * Free the list of margin request. 548da14cebeSEric Cheng */ 549da14cebeSEric Cheng for (mmr = mip->mi_mmrp; mmr != NULL; mmr = nextmmr) { 550da14cebeSEric Cheng nextmmr = mmr->mmr_nextp; 551da14cebeSEric Cheng kmem_free(mmr, sizeof (mac_margin_req_t)); 552da14cebeSEric Cheng } 553da14cebeSEric Cheng mip->mi_mmrp = NULL; 554da14cebeSEric Cheng 5554eaa4710SRishi Srivatsavai mip->mi_linkstate = mip->mi_lowlinkstate = LINK_STATE_UNKNOWN; 556da14cebeSEric Cheng kmem_free(mip->mi_info.mi_unicst_addr, mip->mi_type->mt_addr_length); 557da14cebeSEric Cheng mip->mi_info.mi_unicst_addr = NULL; 558da14cebeSEric Cheng 559da14cebeSEric Cheng atomic_dec_32(&mip->mi_type->mt_ref); 560da14cebeSEric Cheng mip->mi_type = NULL; 561da14cebeSEric Cheng 562da14cebeSEric Cheng /* 563da14cebeSEric Cheng * Free the primary MAC address. 564da14cebeSEric Cheng */ 565da14cebeSEric Cheng mac_fini_macaddr(mip); 566da14cebeSEric Cheng 567da14cebeSEric Cheng /* 568da14cebeSEric Cheng * free all rings 569da14cebeSEric Cheng */ 570da14cebeSEric Cheng mac_free_rings(mip, MAC_RING_TYPE_RX); 571da14cebeSEric Cheng mac_free_rings(mip, MAC_RING_TYPE_TX); 572da14cebeSEric Cheng 573da14cebeSEric Cheng mac_addr_factory_fini(mip); 574da14cebeSEric Cheng 575da14cebeSEric Cheng bzero(mip->mi_addr, MAXMACADDRLEN); 576da14cebeSEric Cheng bzero(mip->mi_dstaddr, MAXMACADDRLEN); 577da14cebeSEric Cheng 578da14cebeSEric Cheng /* and the flows */ 579da14cebeSEric Cheng mac_flow_tab_destroy(mip->mi_flow_tab); 580da14cebeSEric Cheng mip->mi_flow_tab = NULL; 581da14cebeSEric Cheng 582da14cebeSEric Cheng if (mip->mi_minor > MAC_MAX_MINOR) 583da14cebeSEric Cheng mac_minor_rele(mip->mi_minor); 584da14cebeSEric Cheng 585da14cebeSEric Cheng cmn_err(CE_NOTE, "!%s unregistered", mip->mi_name); 586da14cebeSEric Cheng 587da14cebeSEric Cheng /* 588da14cebeSEric Cheng * Reset the perim related fields to default values before 589da14cebeSEric Cheng * kmem_cache_free 590da14cebeSEric Cheng */ 591da14cebeSEric Cheng i_mac_perim_exit(mip); 592da14cebeSEric Cheng mip->mi_state_flags = 0; 593da14cebeSEric Cheng 594da14cebeSEric Cheng mac_unregister_priv_prop(mip); 5954eaa4710SRishi Srivatsavai 5964eaa4710SRishi Srivatsavai ASSERT(mip->mi_bridge_link == NULL); 597da14cebeSEric Cheng kmem_cache_free(i_mac_impl_cachep, mip); 598da14cebeSEric Cheng 599da14cebeSEric Cheng return (0); 600da14cebeSEric Cheng } 601da14cebeSEric Cheng 602da14cebeSEric Cheng /* DATA RECEPTION */ 603da14cebeSEric Cheng 604da14cebeSEric Cheng /* 605da14cebeSEric Cheng * This function is invoked for packets received by the MAC driver in 606da14cebeSEric Cheng * interrupt context. The ring generation number provided by the driver 607da14cebeSEric Cheng * is matched with the ring generation number held in MAC. If they do not 608da14cebeSEric Cheng * match, received packets are considered stale packets coming from an older 609da14cebeSEric Cheng * assignment of the ring. Drop them. 610da14cebeSEric Cheng */ 611da14cebeSEric Cheng void 612da14cebeSEric Cheng mac_rx_ring(mac_handle_t mh, mac_ring_handle_t mrh, mblk_t *mp_chain, 613da14cebeSEric Cheng uint64_t mr_gen_num) 614da14cebeSEric Cheng { 615da14cebeSEric Cheng mac_ring_t *mr = (mac_ring_t *)mrh; 616da14cebeSEric Cheng 617da14cebeSEric Cheng if ((mr != NULL) && (mr->mr_gen_num != mr_gen_num)) { 618da14cebeSEric Cheng DTRACE_PROBE2(mac__rx__rings__stale__packet, uint64_t, 619da14cebeSEric Cheng mr->mr_gen_num, uint64_t, mr_gen_num); 620da14cebeSEric Cheng freemsgchain(mp_chain); 621da14cebeSEric Cheng return; 622da14cebeSEric Cheng } 623da14cebeSEric Cheng mac_rx(mh, (mac_resource_handle_t)mrh, mp_chain); 624da14cebeSEric Cheng } 625da14cebeSEric Cheng 626da14cebeSEric Cheng /* 6274eaa4710SRishi Srivatsavai * This function is invoked for each packet received by the underlying driver. 628da14cebeSEric Cheng */ 629da14cebeSEric Cheng void 630da14cebeSEric Cheng mac_rx(mac_handle_t mh, mac_resource_handle_t mrh, mblk_t *mp_chain) 6314eaa4710SRishi Srivatsavai { 6324eaa4710SRishi Srivatsavai mac_impl_t *mip = (mac_impl_t *)mh; 6334eaa4710SRishi Srivatsavai 6344eaa4710SRishi Srivatsavai /* 6354eaa4710SRishi Srivatsavai * Check if the link is part of a bridge. If not, then we don't need 6364eaa4710SRishi Srivatsavai * to take the lock to remain consistent. Make this common case 6374eaa4710SRishi Srivatsavai * lock-free and tail-call optimized. 6384eaa4710SRishi Srivatsavai */ 6394eaa4710SRishi Srivatsavai if (mip->mi_bridge_link == NULL) { 6404eaa4710SRishi Srivatsavai mac_rx_common(mh, mrh, mp_chain); 6414eaa4710SRishi Srivatsavai } else { 6424eaa4710SRishi Srivatsavai /* 6434eaa4710SRishi Srivatsavai * Once we take a reference on the bridge link, the bridge 6444eaa4710SRishi Srivatsavai * module itself can't unload, so the callback pointers are 6454eaa4710SRishi Srivatsavai * stable. 6464eaa4710SRishi Srivatsavai */ 6474eaa4710SRishi Srivatsavai mutex_enter(&mip->mi_bridge_lock); 6484eaa4710SRishi Srivatsavai if ((mh = mip->mi_bridge_link) != NULL) 6494eaa4710SRishi Srivatsavai mac_bridge_ref_cb(mh, B_TRUE); 6504eaa4710SRishi Srivatsavai mutex_exit(&mip->mi_bridge_lock); 6514eaa4710SRishi Srivatsavai if (mh == NULL) { 6524eaa4710SRishi Srivatsavai mac_rx_common((mac_handle_t)mip, mrh, mp_chain); 6534eaa4710SRishi Srivatsavai } else { 6544eaa4710SRishi Srivatsavai mac_bridge_rx_cb(mh, mrh, mp_chain); 6554eaa4710SRishi Srivatsavai mac_bridge_ref_cb(mh, B_FALSE); 6564eaa4710SRishi Srivatsavai } 6574eaa4710SRishi Srivatsavai } 6584eaa4710SRishi Srivatsavai } 6594eaa4710SRishi Srivatsavai 6604eaa4710SRishi Srivatsavai /* 6614eaa4710SRishi Srivatsavai * Special case function: this allows snooping of packets transmitted and 6624eaa4710SRishi Srivatsavai * received by TRILL. By design, they go directly into the TRILL module. 6634eaa4710SRishi Srivatsavai */ 6644eaa4710SRishi Srivatsavai void 6654eaa4710SRishi Srivatsavai mac_trill_snoop(mac_handle_t mh, mblk_t *mp) 6664eaa4710SRishi Srivatsavai { 6674eaa4710SRishi Srivatsavai mac_impl_t *mip = (mac_impl_t *)mh; 6684eaa4710SRishi Srivatsavai 6694eaa4710SRishi Srivatsavai if (mip->mi_promisc_list != NULL) 6704eaa4710SRishi Srivatsavai mac_promisc_dispatch(mip, mp, NULL); 6714eaa4710SRishi Srivatsavai } 6724eaa4710SRishi Srivatsavai 6734eaa4710SRishi Srivatsavai /* 6744eaa4710SRishi Srivatsavai * This is the upward reentry point for packets arriving from the bridging 6754eaa4710SRishi Srivatsavai * module and from mac_rx for links not part of a bridge. 6764eaa4710SRishi Srivatsavai */ 6774eaa4710SRishi Srivatsavai void 6784eaa4710SRishi Srivatsavai mac_rx_common(mac_handle_t mh, mac_resource_handle_t mrh, mblk_t *mp_chain) 679da14cebeSEric Cheng { 680da14cebeSEric Cheng mac_impl_t *mip = (mac_impl_t *)mh; 681da14cebeSEric Cheng mac_ring_t *mr = (mac_ring_t *)mrh; 682da14cebeSEric Cheng mac_soft_ring_set_t *mac_srs; 683da14cebeSEric Cheng mblk_t *bp = mp_chain; 684da14cebeSEric Cheng boolean_t hw_classified = B_FALSE; 685da14cebeSEric Cheng 686da14cebeSEric Cheng /* 687da14cebeSEric Cheng * If there are any promiscuous mode callbacks defined for 688da14cebeSEric Cheng * this MAC, pass them a copy if appropriate. 689da14cebeSEric Cheng */ 690da14cebeSEric Cheng if (mip->mi_promisc_list != NULL) 691da14cebeSEric Cheng mac_promisc_dispatch(mip, mp_chain, NULL); 692da14cebeSEric Cheng 693da14cebeSEric Cheng if (mr != NULL) { 694da14cebeSEric Cheng /* 695da14cebeSEric Cheng * If the SRS teardown has started, just return. The 'mr' 696da14cebeSEric Cheng * continues to be valid until the driver unregisters the mac. 697da14cebeSEric Cheng * Hardware classified packets will not make their way up 698da14cebeSEric Cheng * beyond this point once the teardown has started. The driver 699da14cebeSEric Cheng * is never passed a pointer to a flow entry or SRS or any 700da14cebeSEric Cheng * structure that can be freed much before mac_unregister. 701da14cebeSEric Cheng */ 702da14cebeSEric Cheng mutex_enter(&mr->mr_lock); 703da14cebeSEric Cheng if ((mr->mr_state != MR_INUSE) || (mr->mr_flag & 704da14cebeSEric Cheng (MR_INCIPIENT | MR_CONDEMNED | MR_QUIESCE))) { 705da14cebeSEric Cheng mutex_exit(&mr->mr_lock); 706da14cebeSEric Cheng freemsgchain(mp_chain); 707da14cebeSEric Cheng return; 708da14cebeSEric Cheng } 709da14cebeSEric Cheng if (mr->mr_classify_type == MAC_HW_CLASSIFIER) { 710da14cebeSEric Cheng hw_classified = B_TRUE; 711da14cebeSEric Cheng MR_REFHOLD_LOCKED(mr); 712da14cebeSEric Cheng } 713da14cebeSEric Cheng mutex_exit(&mr->mr_lock); 714da14cebeSEric Cheng 715da14cebeSEric Cheng /* 716da14cebeSEric Cheng * We check if an SRS is controlling this ring. 717da14cebeSEric Cheng * If so, we can directly call the srs_lower_proc 718da14cebeSEric Cheng * routine otherwise we need to go through mac_rx_classify 719da14cebeSEric Cheng * to reach the right place. 720da14cebeSEric Cheng */ 721da14cebeSEric Cheng if (hw_classified) { 722da14cebeSEric Cheng mac_srs = mr->mr_srs; 723da14cebeSEric Cheng /* 724da14cebeSEric Cheng * This is supposed to be the fast path. 725da14cebeSEric Cheng * All packets received though here were steered by 726da14cebeSEric Cheng * the hardware classifier, and share the same 727da14cebeSEric Cheng * MAC header info. 728da14cebeSEric Cheng */ 729da14cebeSEric Cheng mac_srs->srs_rx.sr_lower_proc(mh, 730da14cebeSEric Cheng (mac_resource_handle_t)mac_srs, mp_chain, B_FALSE); 731da14cebeSEric Cheng MR_REFRELE(mr); 732da14cebeSEric Cheng return; 733da14cebeSEric Cheng } 734da14cebeSEric Cheng /* We'll fall through to software classification */ 735ae6aa22aSVenugopal Iyer } else { 736ae6aa22aSVenugopal Iyer flow_entry_t *flent; 737ae6aa22aSVenugopal Iyer int err; 738ae6aa22aSVenugopal Iyer 739ae6aa22aSVenugopal Iyer rw_enter(&mip->mi_rw_lock, RW_READER); 740ae6aa22aSVenugopal Iyer if (mip->mi_single_active_client != NULL) { 741ae6aa22aSVenugopal Iyer flent = mip->mi_single_active_client->mci_flent_list; 742ae6aa22aSVenugopal Iyer FLOW_TRY_REFHOLD(flent, err); 743ae6aa22aSVenugopal Iyer rw_exit(&mip->mi_rw_lock); 744ae6aa22aSVenugopal Iyer if (err == 0) { 745ae6aa22aSVenugopal Iyer (flent->fe_cb_fn)(flent->fe_cb_arg1, 746ae6aa22aSVenugopal Iyer flent->fe_cb_arg2, mp_chain, B_FALSE); 747ae6aa22aSVenugopal Iyer FLOW_REFRELE(flent); 748ae6aa22aSVenugopal Iyer return; 749ae6aa22aSVenugopal Iyer } 750ae6aa22aSVenugopal Iyer } else { 751ae6aa22aSVenugopal Iyer rw_exit(&mip->mi_rw_lock); 752ae6aa22aSVenugopal Iyer } 753da14cebeSEric Cheng } 754da14cebeSEric Cheng 755da14cebeSEric Cheng if (!FLOW_TAB_EMPTY(mip->mi_flow_tab)) { 756da14cebeSEric Cheng if ((bp = mac_rx_flow(mh, mrh, bp)) == NULL) 757da14cebeSEric Cheng return; 758da14cebeSEric Cheng } 759da14cebeSEric Cheng 760da14cebeSEric Cheng freemsgchain(bp); 761da14cebeSEric Cheng } 762da14cebeSEric Cheng 763da14cebeSEric Cheng /* DATA TRANSMISSION */ 764da14cebeSEric Cheng 765da14cebeSEric Cheng /* 766da14cebeSEric Cheng * A driver's notification to resume transmission, in case of a provider 767da14cebeSEric Cheng * without TX rings. 768da14cebeSEric Cheng */ 769da14cebeSEric Cheng void 770da14cebeSEric Cheng mac_tx_update(mac_handle_t mh) 771da14cebeSEric Cheng { 772da14cebeSEric Cheng /* 773da14cebeSEric Cheng * Walk the list of MAC clients (mac_client_handle) 774da14cebeSEric Cheng * and update 775da14cebeSEric Cheng */ 776da14cebeSEric Cheng i_mac_tx_srs_notify((mac_impl_t *)mh, NULL); 777da14cebeSEric Cheng } 778da14cebeSEric Cheng 779da14cebeSEric Cheng /* 780da14cebeSEric Cheng * A driver's notification to resume transmission on the specified TX ring. 781da14cebeSEric Cheng */ 782da14cebeSEric Cheng void 783da14cebeSEric Cheng mac_tx_ring_update(mac_handle_t mh, mac_ring_handle_t rh) 784da14cebeSEric Cheng { 785da14cebeSEric Cheng i_mac_tx_srs_notify((mac_impl_t *)mh, rh); 786da14cebeSEric Cheng } 787da14cebeSEric Cheng 788da14cebeSEric Cheng /* LINK STATE */ 789da14cebeSEric Cheng /* 790da14cebeSEric Cheng * Notify the MAC layer about a link state change 791da14cebeSEric Cheng */ 792da14cebeSEric Cheng void 793da14cebeSEric Cheng mac_link_update(mac_handle_t mh, link_state_t link) 794da14cebeSEric Cheng { 795da14cebeSEric Cheng mac_impl_t *mip = (mac_impl_t *)mh; 796da14cebeSEric Cheng 7974eaa4710SRishi Srivatsavai /* 7984eaa4710SRishi Srivatsavai * Save the link state. 7994eaa4710SRishi Srivatsavai */ 8004eaa4710SRishi Srivatsavai mip->mi_lowlinkstate = link; 8014eaa4710SRishi Srivatsavai 8024eaa4710SRishi Srivatsavai /* 8034eaa4710SRishi Srivatsavai * Send a MAC_NOTE_LOWLINK notification. This tells the notification 8044eaa4710SRishi Srivatsavai * thread to deliver both lower and upper notifications. 8054eaa4710SRishi Srivatsavai */ 8064eaa4710SRishi Srivatsavai i_mac_notify(mip, MAC_NOTE_LOWLINK); 8074eaa4710SRishi Srivatsavai } 8084eaa4710SRishi Srivatsavai 8094eaa4710SRishi Srivatsavai /* 8104eaa4710SRishi Srivatsavai * Notify the MAC layer about a link state change due to bridging. 8114eaa4710SRishi Srivatsavai */ 8124eaa4710SRishi Srivatsavai void 8134eaa4710SRishi Srivatsavai mac_link_redo(mac_handle_t mh, link_state_t link) 8144eaa4710SRishi Srivatsavai { 8154eaa4710SRishi Srivatsavai mac_impl_t *mip = (mac_impl_t *)mh; 8164eaa4710SRishi Srivatsavai 817da14cebeSEric Cheng /* 818da14cebeSEric Cheng * Save the link state. 819da14cebeSEric Cheng */ 820da14cebeSEric Cheng mip->mi_linkstate = link; 821da14cebeSEric Cheng 822da14cebeSEric Cheng /* 8234eaa4710SRishi Srivatsavai * Send a MAC_NOTE_LINK notification. Only upper notifications are 8244eaa4710SRishi Srivatsavai * made. 825da14cebeSEric Cheng */ 826da14cebeSEric Cheng i_mac_notify(mip, MAC_NOTE_LINK); 827da14cebeSEric Cheng } 828da14cebeSEric Cheng 829*61af1958SGarrett D'Amore /* MINOR NODE HANDLING */ 830*61af1958SGarrett D'Amore 831*61af1958SGarrett D'Amore /* 832*61af1958SGarrett D'Amore * Given a dev_t, return the instance number (PPA) associated with it. 833*61af1958SGarrett D'Amore * Drivers can use this in their getinfo(9e) implementation to lookup 834*61af1958SGarrett D'Amore * the instance number (i.e. PPA) of the device, to use as an index to 835*61af1958SGarrett D'Amore * their own array of soft state structures. 836*61af1958SGarrett D'Amore * 837*61af1958SGarrett D'Amore * Returns -1 on error. 838*61af1958SGarrett D'Amore */ 839*61af1958SGarrett D'Amore int 840*61af1958SGarrett D'Amore mac_devt_to_instance(dev_t devt) 841*61af1958SGarrett D'Amore { 842*61af1958SGarrett D'Amore return (dld_devt_to_instance(devt)); 843*61af1958SGarrett D'Amore } 844*61af1958SGarrett D'Amore 845*61af1958SGarrett D'Amore /* 846*61af1958SGarrett D'Amore * This function returns the first minor number that is available for 847*61af1958SGarrett D'Amore * driver private use. All minor numbers smaller than this are 848*61af1958SGarrett D'Amore * reserved for GLDv3 use. 849*61af1958SGarrett D'Amore */ 850*61af1958SGarrett D'Amore minor_t 851*61af1958SGarrett D'Amore mac_private_minor(void) 852*61af1958SGarrett D'Amore { 853*61af1958SGarrett D'Amore return (MAC_PRIVATE_MINOR); 854*61af1958SGarrett D'Amore } 855*61af1958SGarrett D'Amore 856da14cebeSEric Cheng /* OTHER CONTROL INFORMATION */ 857da14cebeSEric Cheng 858da14cebeSEric Cheng /* 859da14cebeSEric Cheng * A driver notified us that its primary MAC address has changed. 860da14cebeSEric Cheng */ 861da14cebeSEric Cheng void 862da14cebeSEric Cheng mac_unicst_update(mac_handle_t mh, const uint8_t *addr) 863da14cebeSEric Cheng { 864da14cebeSEric Cheng mac_impl_t *mip = (mac_impl_t *)mh; 865da14cebeSEric Cheng 866da14cebeSEric Cheng if (mip->mi_type->mt_addr_length == 0) 867da14cebeSEric Cheng return; 868da14cebeSEric Cheng 869da14cebeSEric Cheng i_mac_perim_enter(mip); 870da14cebeSEric Cheng /* 871da14cebeSEric Cheng * If address doesn't change, do nothing. 872da14cebeSEric Cheng */ 873da14cebeSEric Cheng if (bcmp(addr, mip->mi_addr, mip->mi_type->mt_addr_length) == 0) { 874da14cebeSEric Cheng i_mac_perim_exit(mip); 875da14cebeSEric Cheng return; 876da14cebeSEric Cheng } 877da14cebeSEric Cheng 878da14cebeSEric Cheng /* 879da14cebeSEric Cheng * Freshen the MAC address value and update all MAC clients that 880da14cebeSEric Cheng * share this MAC address. 881da14cebeSEric Cheng */ 882da14cebeSEric Cheng mac_freshen_macaddr(mac_find_macaddr(mip, mip->mi_addr), 883da14cebeSEric Cheng (uint8_t *)addr); 884da14cebeSEric Cheng 885da14cebeSEric Cheng i_mac_perim_exit(mip); 886da14cebeSEric Cheng 887da14cebeSEric Cheng /* 888da14cebeSEric Cheng * Send a MAC_NOTE_UNICST notification. 889da14cebeSEric Cheng */ 890da14cebeSEric Cheng i_mac_notify(mip, MAC_NOTE_UNICST); 891da14cebeSEric Cheng } 892da14cebeSEric Cheng 8932b24ab6bSSebastien Roy void 8942b24ab6bSSebastien Roy mac_dst_update(mac_handle_t mh, const uint8_t *addr) 8952b24ab6bSSebastien Roy { 8962b24ab6bSSebastien Roy mac_impl_t *mip = (mac_impl_t *)mh; 8972b24ab6bSSebastien Roy 8982b24ab6bSSebastien Roy if (mip->mi_type->mt_addr_length == 0) 8992b24ab6bSSebastien Roy return; 9002b24ab6bSSebastien Roy 9012b24ab6bSSebastien Roy i_mac_perim_enter(mip); 9022b24ab6bSSebastien Roy bcopy(addr, mip->mi_dstaddr, mip->mi_type->mt_addr_length); 9032b24ab6bSSebastien Roy i_mac_perim_exit(mip); 9042b24ab6bSSebastien Roy i_mac_notify(mip, MAC_NOTE_DEST); 9052b24ab6bSSebastien Roy } 9062b24ab6bSSebastien Roy 907da14cebeSEric Cheng /* 908da14cebeSEric Cheng * MAC plugin information changed. 909da14cebeSEric Cheng */ 910da14cebeSEric Cheng int 911da14cebeSEric Cheng mac_pdata_update(mac_handle_t mh, void *mac_pdata, size_t dsize) 912da14cebeSEric Cheng { 913da14cebeSEric Cheng mac_impl_t *mip = (mac_impl_t *)mh; 914da14cebeSEric Cheng 915da14cebeSEric Cheng /* 916da14cebeSEric Cheng * Verify that the plugin supports MAC plugin data and that the 917da14cebeSEric Cheng * supplied data is valid. 918da14cebeSEric Cheng */ 919da14cebeSEric Cheng if (!(mip->mi_type->mt_ops.mtops_ops & MTOPS_PDATA_VERIFY)) 920da14cebeSEric Cheng return (EINVAL); 921da14cebeSEric Cheng if (!mip->mi_type->mt_ops.mtops_pdata_verify(mac_pdata, dsize)) 922da14cebeSEric Cheng return (EINVAL); 923da14cebeSEric Cheng 924da14cebeSEric Cheng if (mip->mi_pdata != NULL) 925da14cebeSEric Cheng kmem_free(mip->mi_pdata, mip->mi_pdata_size); 926da14cebeSEric Cheng 927da14cebeSEric Cheng mip->mi_pdata = kmem_alloc(dsize, KM_SLEEP); 928da14cebeSEric Cheng bcopy(mac_pdata, mip->mi_pdata, dsize); 929da14cebeSEric Cheng mip->mi_pdata_size = dsize; 930da14cebeSEric Cheng 931da14cebeSEric Cheng /* 932da14cebeSEric Cheng * Since the MAC plugin data is used to construct MAC headers that 933da14cebeSEric Cheng * were cached in fast-path headers, we need to flush fast-path 934da14cebeSEric Cheng * information for links associated with this mac. 935da14cebeSEric Cheng */ 936da14cebeSEric Cheng i_mac_notify(mip, MAC_NOTE_FASTPATH_FLUSH); 937da14cebeSEric Cheng return (0); 938da14cebeSEric Cheng } 939da14cebeSEric Cheng 940da14cebeSEric Cheng /* 941da14cebeSEric Cheng * Invoked by driver as well as the framework to notify its capability change. 942da14cebeSEric Cheng */ 943da14cebeSEric Cheng void 944da14cebeSEric Cheng mac_capab_update(mac_handle_t mh) 945da14cebeSEric Cheng { 946da14cebeSEric Cheng /* Send MAC_NOTE_CAPAB_CHG notification */ 947da14cebeSEric Cheng i_mac_notify((mac_impl_t *)mh, MAC_NOTE_CAPAB_CHG); 948da14cebeSEric Cheng } 949da14cebeSEric Cheng 950da14cebeSEric Cheng int 951da14cebeSEric Cheng mac_maxsdu_update(mac_handle_t mh, uint_t sdu_max) 952da14cebeSEric Cheng { 953da14cebeSEric Cheng mac_impl_t *mip = (mac_impl_t *)mh; 954da14cebeSEric Cheng 955f0f2c3a5SGirish Moodalbail if (sdu_max == 0 || sdu_max < mip->mi_sdu_min) 956da14cebeSEric Cheng return (EINVAL); 957da14cebeSEric Cheng mip->mi_sdu_max = sdu_max; 958da14cebeSEric Cheng 959da14cebeSEric Cheng /* Send a MAC_NOTE_SDU_SIZE notification. */ 960da14cebeSEric Cheng i_mac_notify(mip, MAC_NOTE_SDU_SIZE); 961da14cebeSEric Cheng return (0); 962da14cebeSEric Cheng } 963da14cebeSEric Cheng 964da14cebeSEric Cheng /* PRIVATE FUNCTIONS, FOR INTERNAL USE ONLY */ 965da14cebeSEric Cheng 966da14cebeSEric Cheng /* 967da14cebeSEric Cheng * Updates the mac_impl structure with the current state of the link 968da14cebeSEric Cheng */ 969da14cebeSEric Cheng static void 970da14cebeSEric Cheng i_mac_log_link_state(mac_impl_t *mip) 971da14cebeSEric Cheng { 972da14cebeSEric Cheng /* 973da14cebeSEric Cheng * If no change, then it is not interesting. 974da14cebeSEric Cheng */ 9754eaa4710SRishi Srivatsavai if (mip->mi_lastlowlinkstate == mip->mi_lowlinkstate) 976da14cebeSEric Cheng return; 977da14cebeSEric Cheng 9784eaa4710SRishi Srivatsavai switch (mip->mi_lowlinkstate) { 979da14cebeSEric Cheng case LINK_STATE_UP: 980da14cebeSEric Cheng if (mip->mi_type->mt_ops.mtops_ops & MTOPS_LINK_DETAILS) { 981da14cebeSEric Cheng char det[200]; 982da14cebeSEric Cheng 983da14cebeSEric Cheng mip->mi_type->mt_ops.mtops_link_details(det, 984da14cebeSEric Cheng sizeof (det), (mac_handle_t)mip, mip->mi_pdata); 985da14cebeSEric Cheng 986da14cebeSEric Cheng cmn_err(CE_NOTE, "!%s link up, %s", mip->mi_name, det); 987da14cebeSEric Cheng } else { 988da14cebeSEric Cheng cmn_err(CE_NOTE, "!%s link up", mip->mi_name); 989da14cebeSEric Cheng } 990da14cebeSEric Cheng break; 991da14cebeSEric Cheng 992da14cebeSEric Cheng case LINK_STATE_DOWN: 993da14cebeSEric Cheng /* 994da14cebeSEric Cheng * Only transitions from UP to DOWN are interesting 995da14cebeSEric Cheng */ 9964eaa4710SRishi Srivatsavai if (mip->mi_lastlowlinkstate != LINK_STATE_UNKNOWN) 997da14cebeSEric Cheng cmn_err(CE_NOTE, "!%s link down", mip->mi_name); 998da14cebeSEric Cheng break; 999da14cebeSEric Cheng 1000da14cebeSEric Cheng case LINK_STATE_UNKNOWN: 1001da14cebeSEric Cheng /* 1002da14cebeSEric Cheng * This case is normally not interesting. 1003da14cebeSEric Cheng */ 1004da14cebeSEric Cheng break; 1005da14cebeSEric Cheng } 10064eaa4710SRishi Srivatsavai mip->mi_lastlowlinkstate = mip->mi_lowlinkstate; 1007da14cebeSEric Cheng } 1008da14cebeSEric Cheng 1009da14cebeSEric Cheng /* 1010da14cebeSEric Cheng * Main routine for the callbacks notifications thread 1011da14cebeSEric Cheng */ 1012da14cebeSEric Cheng static void 1013da14cebeSEric Cheng i_mac_notify_thread(void *arg) 1014da14cebeSEric Cheng { 1015da14cebeSEric Cheng mac_impl_t *mip = arg; 1016da14cebeSEric Cheng callb_cpr_t cprinfo; 1017da14cebeSEric Cheng mac_cb_t *mcb; 1018da14cebeSEric Cheng mac_cb_info_t *mcbi; 1019da14cebeSEric Cheng mac_notify_cb_t *mncb; 1020da14cebeSEric Cheng 1021da14cebeSEric Cheng mcbi = &mip->mi_notify_cb_info; 1022da14cebeSEric Cheng CALLB_CPR_INIT(&cprinfo, mcbi->mcbi_lockp, callb_generic_cpr, 1023da14cebeSEric Cheng "i_mac_notify_thread"); 1024da14cebeSEric Cheng 1025da14cebeSEric Cheng mutex_enter(mcbi->mcbi_lockp); 1026da14cebeSEric Cheng 1027da14cebeSEric Cheng for (;;) { 1028da14cebeSEric Cheng uint32_t bits; 1029da14cebeSEric Cheng uint32_t type; 1030da14cebeSEric Cheng 1031da14cebeSEric Cheng bits = mip->mi_notify_bits; 1032da14cebeSEric Cheng if (bits == 0) { 1033da14cebeSEric Cheng CALLB_CPR_SAFE_BEGIN(&cprinfo); 1034da14cebeSEric Cheng cv_wait(&mcbi->mcbi_cv, mcbi->mcbi_lockp); 1035da14cebeSEric Cheng CALLB_CPR_SAFE_END(&cprinfo, mcbi->mcbi_lockp); 1036da14cebeSEric Cheng continue; 1037da14cebeSEric Cheng } 1038da14cebeSEric Cheng mip->mi_notify_bits = 0; 1039da14cebeSEric Cheng if ((bits & (1 << MAC_NNOTE)) != 0) { 1040da14cebeSEric Cheng /* request to quit */ 1041da14cebeSEric Cheng ASSERT(mip->mi_state_flags & MIS_DISABLED); 1042da14cebeSEric Cheng break; 1043da14cebeSEric Cheng } 1044da14cebeSEric Cheng 1045da14cebeSEric Cheng mutex_exit(mcbi->mcbi_lockp); 1046da14cebeSEric Cheng 1047da14cebeSEric Cheng /* 10484eaa4710SRishi Srivatsavai * Log link changes on the actual link, but then do reports on 10494eaa4710SRishi Srivatsavai * synthetic state (if part of a bridge). 1050da14cebeSEric Cheng */ 10514eaa4710SRishi Srivatsavai if ((bits & (1 << MAC_NOTE_LOWLINK)) != 0) { 10524eaa4710SRishi Srivatsavai link_state_t newstate; 10534eaa4710SRishi Srivatsavai mac_handle_t mh; 10544eaa4710SRishi Srivatsavai 1055da14cebeSEric Cheng i_mac_log_link_state(mip); 10564eaa4710SRishi Srivatsavai newstate = mip->mi_lowlinkstate; 10574eaa4710SRishi Srivatsavai if (mip->mi_bridge_link != NULL) { 10584eaa4710SRishi Srivatsavai mutex_enter(&mip->mi_bridge_lock); 10594eaa4710SRishi Srivatsavai if ((mh = mip->mi_bridge_link) != NULL) { 10604eaa4710SRishi Srivatsavai newstate = mac_bridge_ls_cb(mh, 10614eaa4710SRishi Srivatsavai newstate); 10624eaa4710SRishi Srivatsavai } 10634eaa4710SRishi Srivatsavai mutex_exit(&mip->mi_bridge_lock); 10644eaa4710SRishi Srivatsavai } 10654eaa4710SRishi Srivatsavai if (newstate != mip->mi_linkstate) { 10664eaa4710SRishi Srivatsavai mip->mi_linkstate = newstate; 10674eaa4710SRishi Srivatsavai bits |= 1 << MAC_NOTE_LINK; 10684eaa4710SRishi Srivatsavai } 10694eaa4710SRishi Srivatsavai } 1070da14cebeSEric Cheng 1071da14cebeSEric Cheng /* 1072da14cebeSEric Cheng * Do notification callbacks for each notification type. 1073da14cebeSEric Cheng */ 1074da14cebeSEric Cheng for (type = 0; type < MAC_NNOTE; type++) { 1075da14cebeSEric Cheng if ((bits & (1 << type)) == 0) { 1076da14cebeSEric Cheng continue; 1077da14cebeSEric Cheng } 1078da14cebeSEric Cheng 10794eaa4710SRishi Srivatsavai if (mac_notify_cb_list[type] != NULL) 10804eaa4710SRishi Srivatsavai (*mac_notify_cb_list[type])(mip); 1081da14cebeSEric Cheng 1082da14cebeSEric Cheng /* 1083da14cebeSEric Cheng * Walk the list of notifications. 1084da14cebeSEric Cheng */ 1085da14cebeSEric Cheng MAC_CALLBACK_WALKER_INC(&mip->mi_notify_cb_info); 1086da14cebeSEric Cheng for (mcb = mip->mi_notify_cb_list; mcb != NULL; 1087da14cebeSEric Cheng mcb = mcb->mcb_nextp) { 1088da14cebeSEric Cheng mncb = (mac_notify_cb_t *)mcb->mcb_objp; 1089da14cebeSEric Cheng mncb->mncb_fn(mncb->mncb_arg, type); 1090da14cebeSEric Cheng } 1091da14cebeSEric Cheng MAC_CALLBACK_WALKER_DCR(&mip->mi_notify_cb_info, 1092da14cebeSEric Cheng &mip->mi_notify_cb_list); 1093da14cebeSEric Cheng } 1094da14cebeSEric Cheng 1095da14cebeSEric Cheng mutex_enter(mcbi->mcbi_lockp); 1096da14cebeSEric Cheng } 1097da14cebeSEric Cheng 1098da14cebeSEric Cheng mip->mi_state_flags |= MIS_NOTIFY_DONE; 1099da14cebeSEric Cheng cv_broadcast(&mcbi->mcbi_cv); 1100da14cebeSEric Cheng 1101da14cebeSEric Cheng /* CALLB_CPR_EXIT drops the lock */ 1102da14cebeSEric Cheng CALLB_CPR_EXIT(&cprinfo); 1103da14cebeSEric Cheng thread_exit(); 1104da14cebeSEric Cheng } 1105da14cebeSEric Cheng 1106da14cebeSEric Cheng /* 1107da14cebeSEric Cheng * Signal the i_mac_notify_thread asking it to quit. 1108da14cebeSEric Cheng * Then wait till it is done. 1109da14cebeSEric Cheng */ 1110da14cebeSEric Cheng void 1111da14cebeSEric Cheng i_mac_notify_exit(mac_impl_t *mip) 1112da14cebeSEric Cheng { 1113da14cebeSEric Cheng mac_cb_info_t *mcbi; 1114da14cebeSEric Cheng 1115da14cebeSEric Cheng mcbi = &mip->mi_notify_cb_info; 1116da14cebeSEric Cheng 1117da14cebeSEric Cheng mutex_enter(mcbi->mcbi_lockp); 1118da14cebeSEric Cheng mip->mi_notify_bits = (1 << MAC_NNOTE); 1119da14cebeSEric Cheng cv_broadcast(&mcbi->mcbi_cv); 1120da14cebeSEric Cheng 1121da14cebeSEric Cheng 1122da14cebeSEric Cheng while ((mip->mi_notify_thread != NULL) && 1123da14cebeSEric Cheng !(mip->mi_state_flags & MIS_NOTIFY_DONE)) { 1124da14cebeSEric Cheng cv_wait(&mcbi->mcbi_cv, mcbi->mcbi_lockp); 1125da14cebeSEric Cheng } 1126da14cebeSEric Cheng 1127da14cebeSEric Cheng /* Necessary clean up before doing kmem_cache_free */ 1128da14cebeSEric Cheng mip->mi_state_flags &= ~MIS_NOTIFY_DONE; 1129da14cebeSEric Cheng mip->mi_notify_bits = 0; 1130da14cebeSEric Cheng mip->mi_notify_thread = NULL; 1131da14cebeSEric Cheng mutex_exit(mcbi->mcbi_lockp); 1132da14cebeSEric Cheng } 1133da14cebeSEric Cheng 1134da14cebeSEric Cheng /* 1135da14cebeSEric Cheng * Entry point invoked by drivers to dynamically add a ring to an 1136da14cebeSEric Cheng * existing group. 1137da14cebeSEric Cheng */ 1138da14cebeSEric Cheng int 1139da14cebeSEric Cheng mac_group_add_ring(mac_group_handle_t gh, int index) 1140da14cebeSEric Cheng { 1141da14cebeSEric Cheng mac_group_t *group = (mac_group_t *)gh; 1142da14cebeSEric Cheng mac_impl_t *mip = (mac_impl_t *)group->mrg_mh; 1143da14cebeSEric Cheng int ret; 1144da14cebeSEric Cheng 1145da14cebeSEric Cheng i_mac_perim_enter(mip); 1146da14cebeSEric Cheng 1147da14cebeSEric Cheng /* 1148da14cebeSEric Cheng * Only RX rings can be added or removed by drivers currently. 1149da14cebeSEric Cheng */ 1150da14cebeSEric Cheng ASSERT(group->mrg_type == MAC_RING_TYPE_RX); 1151da14cebeSEric Cheng 1152da14cebeSEric Cheng ret = i_mac_group_add_ring(group, NULL, index); 1153da14cebeSEric Cheng 1154da14cebeSEric Cheng i_mac_perim_exit(mip); 1155da14cebeSEric Cheng 1156da14cebeSEric Cheng return (ret); 1157da14cebeSEric Cheng } 1158da14cebeSEric Cheng 1159da14cebeSEric Cheng /* 1160da14cebeSEric Cheng * Entry point invoked by drivers to dynamically remove a ring 1161da14cebeSEric Cheng * from an existing group. The specified ring handle must no longer 1162da14cebeSEric Cheng * be used by the driver after a call to this function. 1163da14cebeSEric Cheng */ 1164da14cebeSEric Cheng void 1165da14cebeSEric Cheng mac_group_rem_ring(mac_group_handle_t gh, mac_ring_handle_t rh) 1166da14cebeSEric Cheng { 1167da14cebeSEric Cheng mac_group_t *group = (mac_group_t *)gh; 1168da14cebeSEric Cheng mac_impl_t *mip = (mac_impl_t *)group->mrg_mh; 1169da14cebeSEric Cheng 1170da14cebeSEric Cheng i_mac_perim_enter(mip); 1171da14cebeSEric Cheng 1172da14cebeSEric Cheng /* 1173da14cebeSEric Cheng * Only RX rings can be added or removed by drivers currently. 1174da14cebeSEric Cheng */ 1175da14cebeSEric Cheng ASSERT(group->mrg_type == MAC_RING_TYPE_RX); 1176da14cebeSEric Cheng 1177da14cebeSEric Cheng i_mac_group_rem_ring(group, (mac_ring_t *)rh, B_TRUE); 1178da14cebeSEric Cheng 1179da14cebeSEric Cheng i_mac_perim_exit(mip); 1180da14cebeSEric Cheng } 1181