11369Sdduvall /* 21369Sdduvall * CDDL HEADER START 31369Sdduvall * 41369Sdduvall * The contents of this file are subject to the terms of the 51369Sdduvall * Common Development and Distribution License (the "License"). 61369Sdduvall * You may not use this file except in compliance with the License. 71369Sdduvall * 81369Sdduvall * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 91369Sdduvall * or http://www.opensolaris.org/os/licensing. 101369Sdduvall * See the License for the specific language governing permissions 111369Sdduvall * and limitations under the License. 121369Sdduvall * 131369Sdduvall * When distributing Covered Code, include this CDDL HEADER in each 141369Sdduvall * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 151369Sdduvall * If applicable, add the following below this CDDL HEADER, with the 161369Sdduvall * fields enclosed by brackets "[]" replaced with your own identifying 171369Sdduvall * information: Portions Copyright [yyyy] [name of copyright owner] 181369Sdduvall * 191369Sdduvall * CDDL HEADER END 201369Sdduvall */ 211369Sdduvall 221369Sdduvall /* 235895Syz147064 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 241369Sdduvall * Use is subject to license terms. 251369Sdduvall */ 261369Sdduvall 271369Sdduvall #pragma ident "%Z%%M% %I% %E% SMI" 281369Sdduvall 292675Szh199473 #include "bge_impl.h" 301369Sdduvall #include <sys/sdt.h> 31*5903Ssowmini #include <sys/dld.h> 321369Sdduvall 331369Sdduvall /* 341369Sdduvall * This is the string displayed by modinfo, etc. 351369Sdduvall * Make sure you keep the version ID up to date! 361369Sdduvall */ 375107Seota static char bge_ident[] = "Broadcom Gb Ethernet v0.60"; 381369Sdduvall 391369Sdduvall /* 401369Sdduvall * Property names 411369Sdduvall */ 421369Sdduvall static char debug_propname[] = "bge-debug-flags"; 431369Sdduvall static char clsize_propname[] = "cache-line-size"; 441369Sdduvall static char latency_propname[] = "latency-timer"; 451369Sdduvall static char localmac_boolname[] = "local-mac-address?"; 461369Sdduvall static char localmac_propname[] = "local-mac-address"; 471369Sdduvall static char macaddr_propname[] = "mac-address"; 481369Sdduvall static char subdev_propname[] = "subsystem-id"; 491369Sdduvall static char subven_propname[] = "subsystem-vendor-id"; 501369Sdduvall static char rxrings_propname[] = "bge-rx-rings"; 511369Sdduvall static char txrings_propname[] = "bge-tx-rings"; 521865Sdilpreet static char fm_cap[] = "fm-capable"; 531908Sly149593 static char default_mtu[] = "default_mtu"; 541369Sdduvall 551369Sdduvall static int bge_add_intrs(bge_t *, int); 561369Sdduvall static void bge_rem_intrs(bge_t *); 571369Sdduvall 581369Sdduvall /* 591369Sdduvall * Describes the chip's DMA engine 601369Sdduvall */ 611369Sdduvall static ddi_dma_attr_t dma_attr = { 621369Sdduvall DMA_ATTR_V0, /* dma_attr version */ 631369Sdduvall 0x0000000000000000ull, /* dma_attr_addr_lo */ 641369Sdduvall 0xFFFFFFFFFFFFFFFFull, /* dma_attr_addr_hi */ 651369Sdduvall 0x00000000FFFFFFFFull, /* dma_attr_count_max */ 661369Sdduvall 0x0000000000000001ull, /* dma_attr_align */ 671369Sdduvall 0x00000FFF, /* dma_attr_burstsizes */ 681369Sdduvall 0x00000001, /* dma_attr_minxfer */ 691369Sdduvall 0x000000000000FFFFull, /* dma_attr_maxxfer */ 701369Sdduvall 0xFFFFFFFFFFFFFFFFull, /* dma_attr_seg */ 711369Sdduvall 1, /* dma_attr_sgllen */ 721369Sdduvall 0x00000001, /* dma_attr_granular */ 731865Sdilpreet DDI_DMA_FLAGERR /* dma_attr_flags */ 741369Sdduvall }; 751369Sdduvall 761369Sdduvall /* 771369Sdduvall * PIO access attributes for registers 781369Sdduvall */ 791369Sdduvall static ddi_device_acc_attr_t bge_reg_accattr = { 801369Sdduvall DDI_DEVICE_ATTR_V0, 811369Sdduvall DDI_NEVERSWAP_ACC, 821865Sdilpreet DDI_STRICTORDER_ACC, 831865Sdilpreet DDI_FLAGERR_ACC 841369Sdduvall }; 851369Sdduvall 861369Sdduvall /* 871369Sdduvall * DMA access attributes for descriptors: NOT to be byte swapped. 881369Sdduvall */ 891369Sdduvall static ddi_device_acc_attr_t bge_desc_accattr = { 901369Sdduvall DDI_DEVICE_ATTR_V0, 911369Sdduvall DDI_NEVERSWAP_ACC, 921865Sdilpreet DDI_STRICTORDER_ACC, 931865Sdilpreet DDI_FLAGERR_ACC 941369Sdduvall }; 951369Sdduvall 961369Sdduvall /* 971369Sdduvall * DMA access attributes for data: NOT to be byte swapped. 981369Sdduvall */ 991369Sdduvall static ddi_device_acc_attr_t bge_data_accattr = { 1001369Sdduvall DDI_DEVICE_ATTR_V0, 1011369Sdduvall DDI_NEVERSWAP_ACC, 1021369Sdduvall DDI_STRICTORDER_ACC 1031369Sdduvall }; 1041369Sdduvall 1051369Sdduvall /* 1061369Sdduvall * Versions of the O/S up to Solaris 8 didn't support network booting 1071369Sdduvall * from any network interface except the first (NET0). Patching this 1081369Sdduvall * flag to a non-zero value will tell the driver to work around this 1091369Sdduvall * limitation by creating an extra (internal) pathname node. To do 1101369Sdduvall * this, just add a line like the following to the CLIENT'S etc/system 1111369Sdduvall * file ON THE ROOT FILESYSTEM SERVER before booting the client: 1121369Sdduvall * 1131369Sdduvall * set bge:bge_net1_boot_support = 1; 1141369Sdduvall */ 1151369Sdduvall static uint32_t bge_net1_boot_support = 1; 1161369Sdduvall 1172311Sseb static int bge_m_start(void *); 1182311Sseb static void bge_m_stop(void *); 1192311Sseb static int bge_m_promisc(void *, boolean_t); 1202311Sseb static int bge_m_multicst(void *, boolean_t, const uint8_t *); 1212311Sseb static int bge_m_unicst(void *, const uint8_t *); 1222311Sseb static void bge_m_resources(void *); 1232311Sseb static void bge_m_ioctl(void *, queue_t *, mblk_t *); 1242311Sseb static boolean_t bge_m_getcapab(void *, mac_capab_t, void *); 1252331Skrgopi static int bge_unicst_set(void *, const uint8_t *, 1262331Skrgopi mac_addr_slot_t); 1272331Skrgopi static int bge_m_unicst_add(void *, mac_multi_addr_t *); 1282331Skrgopi static int bge_m_unicst_remove(void *, mac_addr_slot_t); 1292331Skrgopi static int bge_m_unicst_modify(void *, mac_multi_addr_t *); 1302331Skrgopi static int bge_m_unicst_get(void *, mac_multi_addr_t *); 131*5903Ssowmini static int bge_m_setprop(void *, const char *, mac_prop_id_t, 132*5903Ssowmini uint_t, const void *); 133*5903Ssowmini static int bge_m_getprop(void *, const char *, mac_prop_id_t, 134*5903Ssowmini uint_t, void *); 135*5903Ssowmini static int bge_set_priv_prop(bge_t *, const char *, uint_t, 136*5903Ssowmini const void *); 137*5903Ssowmini static int bge_get_priv_prop(bge_t *, const char *, uint_t, 138*5903Ssowmini void *); 139*5903Ssowmini 140*5903Ssowmini #define BGE_M_CALLBACK_FLAGS\ 141*5903Ssowmini (MC_RESOURCES | MC_IOCTL | MC_GETCAPAB | MC_SETPROP | MC_GETPROP) 1422311Sseb 1432311Sseb static mac_callbacks_t bge_m_callbacks = { 1442311Sseb BGE_M_CALLBACK_FLAGS, 1452311Sseb bge_m_stat, 1462311Sseb bge_m_start, 1472311Sseb bge_m_stop, 1482311Sseb bge_m_promisc, 1492311Sseb bge_m_multicst, 1502311Sseb bge_m_unicst, 1512311Sseb bge_m_tx, 1522311Sseb bge_m_resources, 1532311Sseb bge_m_ioctl, 154*5903Ssowmini bge_m_getcapab, 155*5903Ssowmini NULL, 156*5903Ssowmini NULL, 157*5903Ssowmini bge_m_setprop, 158*5903Ssowmini bge_m_getprop 1592311Sseb }; 1602311Sseb 1611369Sdduvall /* 1621369Sdduvall * ========== Transmit and receive ring reinitialisation ========== 1631369Sdduvall */ 1641369Sdduvall 1651369Sdduvall /* 1661369Sdduvall * These <reinit> routines each reset the specified ring to an initial 1671369Sdduvall * state, assuming that the corresponding <init> routine has already 1681369Sdduvall * been called exactly once. 1691369Sdduvall */ 1701369Sdduvall 1711369Sdduvall static void 1721369Sdduvall bge_reinit_send_ring(send_ring_t *srp) 1731369Sdduvall { 1743334Sgs150176 bge_queue_t *txbuf_queue; 1753334Sgs150176 bge_queue_item_t *txbuf_head; 1763334Sgs150176 sw_txbuf_t *txbuf; 1773334Sgs150176 sw_sbd_t *ssbdp; 1783334Sgs150176 uint32_t slot; 1793334Sgs150176 1801369Sdduvall /* 1811369Sdduvall * Reinitialise control variables ... 1821369Sdduvall */ 1833334Sgs150176 srp->tx_flow = 0; 1841369Sdduvall srp->tx_next = 0; 1853334Sgs150176 srp->txfill_next = 0; 1861369Sdduvall srp->tx_free = srp->desc.nslots; 1871369Sdduvall ASSERT(mutex_owned(srp->tc_lock)); 1881369Sdduvall srp->tc_next = 0; 1893334Sgs150176 srp->txpkt_next = 0; 1903334Sgs150176 srp->tx_block = 0; 1913334Sgs150176 srp->tx_nobd = 0; 1923334Sgs150176 srp->tx_nobuf = 0; 1933334Sgs150176 1943334Sgs150176 /* 1953334Sgs150176 * Initialize the tx buffer push queue 1963334Sgs150176 */ 1973334Sgs150176 mutex_enter(srp->freetxbuf_lock); 1983334Sgs150176 mutex_enter(srp->txbuf_lock); 1993334Sgs150176 txbuf_queue = &srp->freetxbuf_queue; 2003334Sgs150176 txbuf_queue->head = NULL; 2013334Sgs150176 txbuf_queue->count = 0; 2023334Sgs150176 txbuf_queue->lock = srp->freetxbuf_lock; 2033334Sgs150176 srp->txbuf_push_queue = txbuf_queue; 2043334Sgs150176 2053334Sgs150176 /* 2063334Sgs150176 * Initialize the tx buffer pop queue 2073334Sgs150176 */ 2083334Sgs150176 txbuf_queue = &srp->txbuf_queue; 2093334Sgs150176 txbuf_queue->head = NULL; 2103334Sgs150176 txbuf_queue->count = 0; 2113334Sgs150176 txbuf_queue->lock = srp->txbuf_lock; 2123334Sgs150176 srp->txbuf_pop_queue = txbuf_queue; 2133334Sgs150176 txbuf_head = srp->txbuf_head; 2143334Sgs150176 txbuf = srp->txbuf; 2153334Sgs150176 for (slot = 0; slot < srp->tx_buffers; ++slot) { 2163334Sgs150176 txbuf_head->item = txbuf; 2173334Sgs150176 txbuf_head->next = txbuf_queue->head; 2183334Sgs150176 txbuf_queue->head = txbuf_head; 2193334Sgs150176 txbuf_queue->count++; 2203334Sgs150176 txbuf++; 2213334Sgs150176 txbuf_head++; 2223334Sgs150176 } 2233334Sgs150176 mutex_exit(srp->txbuf_lock); 2243334Sgs150176 mutex_exit(srp->freetxbuf_lock); 2251369Sdduvall 2261369Sdduvall /* 2271369Sdduvall * Zero and sync all the h/w Send Buffer Descriptors 2281369Sdduvall */ 2291369Sdduvall DMA_ZERO(srp->desc); 2301369Sdduvall DMA_SYNC(srp->desc, DDI_DMA_SYNC_FORDEV); 2313334Sgs150176 bzero(srp->pktp, BGE_SEND_BUF_MAX * sizeof (*srp->pktp)); 2323334Sgs150176 ssbdp = srp->sw_sbds; 2333334Sgs150176 for (slot = 0; slot < srp->desc.nslots; ++ssbdp, ++slot) 2343334Sgs150176 ssbdp->pbuf = NULL; 2351369Sdduvall } 2361369Sdduvall 2371369Sdduvall static void 2381369Sdduvall bge_reinit_recv_ring(recv_ring_t *rrp) 2391369Sdduvall { 2401369Sdduvall /* 2411369Sdduvall * Reinitialise control variables ... 2421369Sdduvall */ 2431369Sdduvall rrp->rx_next = 0; 2441369Sdduvall } 2451369Sdduvall 2461369Sdduvall static void 2473334Sgs150176 bge_reinit_buff_ring(buff_ring_t *brp, uint32_t ring) 2481369Sdduvall { 2491369Sdduvall bge_rbd_t *hw_rbd_p; 2501369Sdduvall sw_rbd_t *srbdp; 2511369Sdduvall uint32_t bufsize; 2521369Sdduvall uint32_t nslots; 2531369Sdduvall uint32_t slot; 2541369Sdduvall 2551369Sdduvall static uint16_t ring_type_flag[BGE_BUFF_RINGS_MAX] = { 2561369Sdduvall RBD_FLAG_STD_RING, 2571369Sdduvall RBD_FLAG_JUMBO_RING, 2581369Sdduvall RBD_FLAG_MINI_RING 2591369Sdduvall }; 2601369Sdduvall 2611369Sdduvall /* 2621369Sdduvall * Zero, initialise and sync all the h/w Receive Buffer Descriptors 2631369Sdduvall * Note: all the remaining fields (<type>, <flags>, <ip_cksum>, 2641369Sdduvall * <tcp_udp_cksum>, <error_flag>, <vlan_tag>, and <reserved>) 2651369Sdduvall * should be zeroed, and so don't need to be set up specifically 2661369Sdduvall * once the whole area has been cleared. 2671369Sdduvall */ 2681369Sdduvall DMA_ZERO(brp->desc); 2691369Sdduvall 2701369Sdduvall hw_rbd_p = DMA_VPTR(brp->desc); 2711369Sdduvall nslots = brp->desc.nslots; 2721369Sdduvall ASSERT(brp->buf[0].nslots == nslots/BGE_SPLIT); 2731369Sdduvall bufsize = brp->buf[0].size; 2741369Sdduvall srbdp = brp->sw_rbds; 2751369Sdduvall for (slot = 0; slot < nslots; ++hw_rbd_p, ++srbdp, ++slot) { 2761369Sdduvall hw_rbd_p->host_buf_addr = srbdp->pbuf.cookie.dmac_laddress; 2771369Sdduvall hw_rbd_p->index = slot; 2781369Sdduvall hw_rbd_p->len = bufsize; 2791369Sdduvall hw_rbd_p->opaque = srbdp->pbuf.token; 2801369Sdduvall hw_rbd_p->flags |= ring_type_flag[ring]; 2811369Sdduvall } 2821369Sdduvall 2831369Sdduvall DMA_SYNC(brp->desc, DDI_DMA_SYNC_FORDEV); 2841369Sdduvall 2851369Sdduvall /* 2861369Sdduvall * Finally, reinitialise the ring control variables ... 2871369Sdduvall */ 2881369Sdduvall brp->rf_next = (nslots != 0) ? (nslots-1) : 0; 2891369Sdduvall } 2901369Sdduvall 2911369Sdduvall /* 2921369Sdduvall * Reinitialize all rings 2931369Sdduvall */ 2941369Sdduvall static void 2951369Sdduvall bge_reinit_rings(bge_t *bgep) 2961369Sdduvall { 2973334Sgs150176 uint32_t ring; 2981369Sdduvall 2991369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 3001369Sdduvall 3011369Sdduvall /* 3021369Sdduvall * Send Rings ... 3031369Sdduvall */ 3041369Sdduvall for (ring = 0; ring < bgep->chipid.tx_rings; ++ring) 3051369Sdduvall bge_reinit_send_ring(&bgep->send[ring]); 3061369Sdduvall 3071369Sdduvall /* 3081369Sdduvall * Receive Return Rings ... 3091369Sdduvall */ 3101369Sdduvall for (ring = 0; ring < bgep->chipid.rx_rings; ++ring) 3111369Sdduvall bge_reinit_recv_ring(&bgep->recv[ring]); 3121369Sdduvall 3131369Sdduvall /* 3141369Sdduvall * Receive Producer Rings ... 3151369Sdduvall */ 3161369Sdduvall for (ring = 0; ring < BGE_BUFF_RINGS_USED; ++ring) 3171369Sdduvall bge_reinit_buff_ring(&bgep->buff[ring], ring); 3181369Sdduvall } 3191369Sdduvall 3201369Sdduvall /* 3211369Sdduvall * ========== Internal state management entry points ========== 3221369Sdduvall */ 3231369Sdduvall 3241369Sdduvall #undef BGE_DBG 3251369Sdduvall #define BGE_DBG BGE_DBG_NEMO /* debug flag for this code */ 3261369Sdduvall 3271369Sdduvall /* 3281369Sdduvall * These routines provide all the functionality required by the 3291369Sdduvall * corresponding GLD entry points, but don't update the GLD state 3301369Sdduvall * so they can be called internally without disturbing our record 3311369Sdduvall * of what GLD thinks we should be doing ... 3321369Sdduvall */ 3331369Sdduvall 3341369Sdduvall /* 3351369Sdduvall * bge_reset() -- reset h/w & rings to initial state 3361369Sdduvall */ 3371865Sdilpreet static int 3381408Srandyf #ifdef BGE_IPMI_ASF 3391408Srandyf bge_reset(bge_t *bgep, uint_t asf_mode) 3401408Srandyf #else 3411369Sdduvall bge_reset(bge_t *bgep) 3421408Srandyf #endif 3431369Sdduvall { 3443334Sgs150176 uint32_t ring; 3451865Sdilpreet int retval; 3461369Sdduvall 3471369Sdduvall BGE_TRACE(("bge_reset($%p)", (void *)bgep)); 3481369Sdduvall 3491369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 3501369Sdduvall 3511369Sdduvall /* 3521369Sdduvall * Grab all the other mutexes in the world (this should 3531369Sdduvall * ensure no other threads are manipulating driver state) 3541369Sdduvall */ 3551369Sdduvall for (ring = 0; ring < BGE_RECV_RINGS_MAX; ++ring) 3561369Sdduvall mutex_enter(bgep->recv[ring].rx_lock); 3571369Sdduvall for (ring = 0; ring < BGE_BUFF_RINGS_MAX; ++ring) 3581369Sdduvall mutex_enter(bgep->buff[ring].rf_lock); 3591369Sdduvall rw_enter(bgep->errlock, RW_WRITER); 3601369Sdduvall for (ring = 0; ring < BGE_SEND_RINGS_MAX; ++ring) 3613334Sgs150176 mutex_enter(bgep->send[ring].tx_lock); 3623334Sgs150176 for (ring = 0; ring < BGE_SEND_RINGS_MAX; ++ring) 3631369Sdduvall mutex_enter(bgep->send[ring].tc_lock); 3641369Sdduvall 3651408Srandyf #ifdef BGE_IPMI_ASF 3661865Sdilpreet retval = bge_chip_reset(bgep, B_TRUE, asf_mode); 3671408Srandyf #else 3681865Sdilpreet retval = bge_chip_reset(bgep, B_TRUE); 3691408Srandyf #endif 3701369Sdduvall bge_reinit_rings(bgep); 3711369Sdduvall 3721369Sdduvall /* 3731369Sdduvall * Free the world ... 3741369Sdduvall */ 3751369Sdduvall for (ring = BGE_SEND_RINGS_MAX; ring-- > 0; ) 3761369Sdduvall mutex_exit(bgep->send[ring].tc_lock); 3773334Sgs150176 for (ring = 0; ring < BGE_SEND_RINGS_MAX; ++ring) 3783334Sgs150176 mutex_exit(bgep->send[ring].tx_lock); 3791369Sdduvall rw_exit(bgep->errlock); 3801369Sdduvall for (ring = BGE_BUFF_RINGS_MAX; ring-- > 0; ) 3811369Sdduvall mutex_exit(bgep->buff[ring].rf_lock); 3821369Sdduvall for (ring = BGE_RECV_RINGS_MAX; ring-- > 0; ) 3831369Sdduvall mutex_exit(bgep->recv[ring].rx_lock); 3841369Sdduvall 3851369Sdduvall BGE_DEBUG(("bge_reset($%p) done", (void *)bgep)); 3861865Sdilpreet return (retval); 3871369Sdduvall } 3881369Sdduvall 3891369Sdduvall /* 3901369Sdduvall * bge_stop() -- stop processing, don't reset h/w or rings 3911369Sdduvall */ 3921369Sdduvall static void 3931369Sdduvall bge_stop(bge_t *bgep) 3941369Sdduvall { 3951369Sdduvall BGE_TRACE(("bge_stop($%p)", (void *)bgep)); 3961369Sdduvall 3971369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 3981369Sdduvall 3991408Srandyf #ifdef BGE_IPMI_ASF 4001408Srandyf if (bgep->asf_enabled) { 4011408Srandyf bgep->asf_pseudostop = B_TRUE; 4021408Srandyf } else { 4031408Srandyf #endif 4041408Srandyf bge_chip_stop(bgep, B_FALSE); 4051408Srandyf #ifdef BGE_IPMI_ASF 4061408Srandyf } 4071408Srandyf #endif 4081369Sdduvall 4091369Sdduvall BGE_DEBUG(("bge_stop($%p) done", (void *)bgep)); 4101369Sdduvall } 4111369Sdduvall 4121369Sdduvall /* 4131369Sdduvall * bge_start() -- start transmitting/receiving 4141369Sdduvall */ 4151865Sdilpreet static int 4161369Sdduvall bge_start(bge_t *bgep, boolean_t reset_phys) 4171369Sdduvall { 4181865Sdilpreet int retval; 4191865Sdilpreet 4201369Sdduvall BGE_TRACE(("bge_start($%p, %d)", (void *)bgep, reset_phys)); 4211369Sdduvall 4221369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 4231369Sdduvall 4241369Sdduvall /* 4251369Sdduvall * Start chip processing, including enabling interrupts 4261369Sdduvall */ 4271865Sdilpreet retval = bge_chip_start(bgep, reset_phys); 4281369Sdduvall 4291369Sdduvall BGE_DEBUG(("bge_start($%p, %d) done", (void *)bgep, reset_phys)); 4301865Sdilpreet return (retval); 4311369Sdduvall } 4321369Sdduvall 4331369Sdduvall /* 4341369Sdduvall * bge_restart - restart transmitting/receiving after error or suspend 4351369Sdduvall */ 4361865Sdilpreet int 4371369Sdduvall bge_restart(bge_t *bgep, boolean_t reset_phys) 4381369Sdduvall { 4391865Sdilpreet int retval = DDI_SUCCESS; 4401369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 4411369Sdduvall 4421408Srandyf #ifdef BGE_IPMI_ASF 4431408Srandyf if (bgep->asf_enabled) { 4441865Sdilpreet if (bge_reset(bgep, ASF_MODE_POST_INIT) != DDI_SUCCESS) 4451865Sdilpreet retval = DDI_FAILURE; 4461408Srandyf } else 4471865Sdilpreet if (bge_reset(bgep, ASF_MODE_NONE) != DDI_SUCCESS) 4481865Sdilpreet retval = DDI_FAILURE; 4491408Srandyf #else 4501865Sdilpreet if (bge_reset(bgep) != DDI_SUCCESS) 4511865Sdilpreet retval = DDI_FAILURE; 4521408Srandyf #endif 4533440Szh199473 if (bgep->bge_mac_state == BGE_MAC_STARTED) { 4541865Sdilpreet if (bge_start(bgep, reset_phys) != DDI_SUCCESS) 4551865Sdilpreet retval = DDI_FAILURE; 4561369Sdduvall bgep->watchdog = 0; 4573334Sgs150176 ddi_trigger_softintr(bgep->drain_id); 4581369Sdduvall } 4591369Sdduvall 4601369Sdduvall BGE_DEBUG(("bge_restart($%p, %d) done", (void *)bgep, reset_phys)); 4611865Sdilpreet return (retval); 4621369Sdduvall } 4631369Sdduvall 4641369Sdduvall 4651369Sdduvall /* 4661369Sdduvall * ========== Nemo-required management entry points ========== 4671369Sdduvall */ 4681369Sdduvall 4691369Sdduvall #undef BGE_DBG 4701369Sdduvall #define BGE_DBG BGE_DBG_NEMO /* debug flag for this code */ 4711369Sdduvall 4721369Sdduvall /* 4731369Sdduvall * bge_m_stop() -- stop transmitting/receiving 4741369Sdduvall */ 4751369Sdduvall static void 4761369Sdduvall bge_m_stop(void *arg) 4771369Sdduvall { 4781369Sdduvall bge_t *bgep = arg; /* private device info */ 4793334Sgs150176 send_ring_t *srp; 4803334Sgs150176 uint32_t ring; 4811369Sdduvall 4821369Sdduvall BGE_TRACE(("bge_m_stop($%p)", arg)); 4831369Sdduvall 4841369Sdduvall /* 4851369Sdduvall * Just stop processing, then record new GLD state 4861369Sdduvall */ 4871369Sdduvall mutex_enter(bgep->genlock); 4881865Sdilpreet if (!(bgep->progress & PROGRESS_INTR)) { 4891865Sdilpreet /* can happen during autorecovery */ 4901865Sdilpreet mutex_exit(bgep->genlock); 4911865Sdilpreet return; 4921865Sdilpreet } 4931369Sdduvall bge_stop(bgep); 4943334Sgs150176 /* 4953334Sgs150176 * Free the possible tx buffers allocated in tx process. 4963334Sgs150176 */ 4973334Sgs150176 #ifdef BGE_IPMI_ASF 4983334Sgs150176 if (!bgep->asf_pseudostop) 4993334Sgs150176 #endif 5003334Sgs150176 { 5013334Sgs150176 rw_enter(bgep->errlock, RW_WRITER); 5023334Sgs150176 for (ring = 0; ring < bgep->chipid.tx_rings; ++ring) { 5033334Sgs150176 srp = &bgep->send[ring]; 5043334Sgs150176 mutex_enter(srp->tx_lock); 5053334Sgs150176 if (srp->tx_array > 1) 5063334Sgs150176 bge_free_txbuf_arrays(srp); 5073334Sgs150176 mutex_exit(srp->tx_lock); 5083334Sgs150176 } 5093334Sgs150176 rw_exit(bgep->errlock); 5103334Sgs150176 } 5111369Sdduvall bgep->bge_mac_state = BGE_MAC_STOPPED; 5121369Sdduvall BGE_DEBUG(("bge_m_stop($%p) done", arg)); 5131865Sdilpreet if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) 5141865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_UNAFFECTED); 5151369Sdduvall mutex_exit(bgep->genlock); 5161369Sdduvall } 5171369Sdduvall 5181369Sdduvall /* 5191369Sdduvall * bge_m_start() -- start transmitting/receiving 5201369Sdduvall */ 5211369Sdduvall static int 5221369Sdduvall bge_m_start(void *arg) 5231369Sdduvall { 5241369Sdduvall bge_t *bgep = arg; /* private device info */ 5251369Sdduvall 5261369Sdduvall BGE_TRACE(("bge_m_start($%p)", arg)); 5271369Sdduvall 5281369Sdduvall /* 5291369Sdduvall * Start processing and record new GLD state 5301369Sdduvall */ 5311369Sdduvall mutex_enter(bgep->genlock); 5321865Sdilpreet if (!(bgep->progress & PROGRESS_INTR)) { 5331865Sdilpreet /* can happen during autorecovery */ 5341865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_DEGRADED); 5351865Sdilpreet mutex_exit(bgep->genlock); 5361865Sdilpreet return (EIO); 5371865Sdilpreet } 5381408Srandyf #ifdef BGE_IPMI_ASF 5391408Srandyf if (bgep->asf_enabled) { 5401408Srandyf if ((bgep->asf_status == ASF_STAT_RUN) && 5414588Sml149210 (bgep->asf_pseudostop)) { 5421408Srandyf bgep->bge_mac_state = BGE_MAC_STARTED; 5431408Srandyf mutex_exit(bgep->genlock); 5441408Srandyf return (0); 5451408Srandyf } 5461408Srandyf } 5471865Sdilpreet if (bge_reset(bgep, ASF_MODE_INIT) != DDI_SUCCESS) { 5481408Srandyf #else 5491865Sdilpreet if (bge_reset(bgep) != DDI_SUCCESS) { 5501408Srandyf #endif 5511865Sdilpreet (void) bge_check_acc_handle(bgep, bgep->cfg_handle); 5521865Sdilpreet (void) bge_check_acc_handle(bgep, bgep->io_handle); 5531865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_DEGRADED); 5541865Sdilpreet mutex_exit(bgep->genlock); 5551865Sdilpreet return (EIO); 5561865Sdilpreet } 5571865Sdilpreet if (bge_start(bgep, B_TRUE) != DDI_SUCCESS) { 5581865Sdilpreet (void) bge_check_acc_handle(bgep, bgep->cfg_handle); 5591865Sdilpreet (void) bge_check_acc_handle(bgep, bgep->io_handle); 5601865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_DEGRADED); 5611865Sdilpreet mutex_exit(bgep->genlock); 5621865Sdilpreet return (EIO); 5631865Sdilpreet } 5641369Sdduvall bgep->bge_mac_state = BGE_MAC_STARTED; 5651369Sdduvall BGE_DEBUG(("bge_m_start($%p) done", arg)); 5661408Srandyf 5671865Sdilpreet if (bge_check_acc_handle(bgep, bgep->cfg_handle) != DDI_FM_OK) { 5681865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_DEGRADED); 5691865Sdilpreet mutex_exit(bgep->genlock); 5701865Sdilpreet return (EIO); 5711865Sdilpreet } 5721865Sdilpreet if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) { 5731865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_DEGRADED); 5741865Sdilpreet mutex_exit(bgep->genlock); 5751865Sdilpreet return (EIO); 5761865Sdilpreet } 5771408Srandyf #ifdef BGE_IPMI_ASF 5781408Srandyf if (bgep->asf_enabled) { 5791408Srandyf if (bgep->asf_status != ASF_STAT_RUN) { 5801408Srandyf /* start ASF heart beat */ 5811408Srandyf bgep->asf_timeout_id = timeout(bge_asf_heartbeat, 5824588Sml149210 (void *)bgep, 5834588Sml149210 drv_usectohz(BGE_ASF_HEARTBEAT_INTERVAL)); 5841408Srandyf bgep->asf_status = ASF_STAT_RUN; 5851408Srandyf } 5861408Srandyf } 5871408Srandyf #endif 5881369Sdduvall mutex_exit(bgep->genlock); 5891369Sdduvall 5901369Sdduvall return (0); 5911369Sdduvall } 5921369Sdduvall 5931369Sdduvall /* 5942331Skrgopi * bge_m_unicst() -- set the physical network address 5951369Sdduvall */ 5961369Sdduvall static int 5971369Sdduvall bge_m_unicst(void *arg, const uint8_t *macaddr) 5981369Sdduvall { 5992331Skrgopi /* 6002331Skrgopi * Request to set address in 6012331Skrgopi * address slot 0, i.e., default address 6022331Skrgopi */ 6032331Skrgopi return (bge_unicst_set(arg, macaddr, 0)); 6042331Skrgopi } 6052331Skrgopi 6062331Skrgopi /* 6072331Skrgopi * bge_unicst_set() -- set the physical network address 6082331Skrgopi */ 6092331Skrgopi static int 6102331Skrgopi bge_unicst_set(void *arg, const uint8_t *macaddr, mac_addr_slot_t slot) 6112331Skrgopi { 6121369Sdduvall bge_t *bgep = arg; /* private device info */ 6131369Sdduvall 6141369Sdduvall BGE_TRACE(("bge_m_unicst_set($%p, %s)", arg, 6154588Sml149210 ether_sprintf((void *)macaddr))); 6161369Sdduvall /* 6171369Sdduvall * Remember the new current address in the driver state 6181369Sdduvall * Sync the chip's idea of the address too ... 6191369Sdduvall */ 6201369Sdduvall mutex_enter(bgep->genlock); 6211865Sdilpreet if (!(bgep->progress & PROGRESS_INTR)) { 6221865Sdilpreet /* can happen during autorecovery */ 6231865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_DEGRADED); 6241865Sdilpreet mutex_exit(bgep->genlock); 6251865Sdilpreet return (EIO); 6261865Sdilpreet } 6272331Skrgopi ethaddr_copy(macaddr, bgep->curr_addr[slot].addr); 6281408Srandyf #ifdef BGE_IPMI_ASF 6291865Sdilpreet if (bge_chip_sync(bgep, B_FALSE) == DDI_FAILURE) { 6301865Sdilpreet #else 6311865Sdilpreet if (bge_chip_sync(bgep) == DDI_FAILURE) { 6321865Sdilpreet #endif 6331865Sdilpreet (void) bge_check_acc_handle(bgep, bgep->cfg_handle); 6341865Sdilpreet (void) bge_check_acc_handle(bgep, bgep->io_handle); 6351865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_DEGRADED); 6361865Sdilpreet mutex_exit(bgep->genlock); 6371865Sdilpreet return (EIO); 6381865Sdilpreet } 6391865Sdilpreet #ifdef BGE_IPMI_ASF 6401408Srandyf if (bgep->asf_enabled) { 6411408Srandyf /* 6421408Srandyf * The above bge_chip_sync() function wrote the ethernet MAC 6431408Srandyf * addresses registers which destroyed the IPMI/ASF sideband. 6441408Srandyf * Here, we have to reset chip to make IPMI/ASF sideband work. 6451408Srandyf */ 6461408Srandyf if (bgep->asf_status == ASF_STAT_RUN) { 6471408Srandyf /* 6481408Srandyf * We must stop ASF heart beat before bge_chip_stop(), 6491408Srandyf * otherwise some computers (ex. IBM HS20 blade server) 6501408Srandyf * may crash. 6511408Srandyf */ 6521408Srandyf bge_asf_update_status(bgep); 6531408Srandyf bge_asf_stop_timer(bgep); 6541408Srandyf bgep->asf_status = ASF_STAT_STOP; 6551408Srandyf 6561408Srandyf bge_asf_pre_reset_operations(bgep, BGE_INIT_RESET); 6571408Srandyf } 6581865Sdilpreet bge_chip_stop(bgep, B_FALSE); 6591408Srandyf 6601865Sdilpreet if (bge_restart(bgep, B_FALSE) == DDI_FAILURE) { 6611865Sdilpreet (void) bge_check_acc_handle(bgep, bgep->cfg_handle); 6621865Sdilpreet (void) bge_check_acc_handle(bgep, bgep->io_handle); 6631865Sdilpreet ddi_fm_service_impact(bgep->devinfo, 6641865Sdilpreet DDI_SERVICE_DEGRADED); 6651865Sdilpreet mutex_exit(bgep->genlock); 6661865Sdilpreet return (EIO); 6671865Sdilpreet } 6681865Sdilpreet 6691408Srandyf /* 6701408Srandyf * Start our ASF heartbeat counter as soon as possible. 6711408Srandyf */ 6721408Srandyf if (bgep->asf_status != ASF_STAT_RUN) { 6731408Srandyf /* start ASF heart beat */ 6741408Srandyf bgep->asf_timeout_id = timeout(bge_asf_heartbeat, 6754588Sml149210 (void *)bgep, 6764588Sml149210 drv_usectohz(BGE_ASF_HEARTBEAT_INTERVAL)); 6771408Srandyf bgep->asf_status = ASF_STAT_RUN; 6781408Srandyf } 6791408Srandyf } 6801408Srandyf #endif 6811369Sdduvall BGE_DEBUG(("bge_m_unicst_set($%p) done", arg)); 6821865Sdilpreet if (bge_check_acc_handle(bgep, bgep->cfg_handle) != DDI_FM_OK) { 6831865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_DEGRADED); 6841865Sdilpreet mutex_exit(bgep->genlock); 6851865Sdilpreet return (EIO); 6861865Sdilpreet } 6871865Sdilpreet if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) { 6881865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_DEGRADED); 6891865Sdilpreet mutex_exit(bgep->genlock); 6901865Sdilpreet return (EIO); 6911865Sdilpreet } 6921369Sdduvall mutex_exit(bgep->genlock); 6931369Sdduvall 6941369Sdduvall return (0); 6951369Sdduvall } 6961369Sdduvall 6971369Sdduvall /* 6982331Skrgopi * The following four routines are used as callbacks for multiple MAC 6992331Skrgopi * address support: 7002331Skrgopi * - bge_m_unicst_add(void *, mac_multi_addr_t *); 7012331Skrgopi * - bge_m_unicst_remove(void *, mac_addr_slot_t); 7022331Skrgopi * - bge_m_unicst_modify(void *, mac_multi_addr_t *); 7032331Skrgopi * - bge_m_unicst_get(void *, mac_multi_addr_t *); 7042331Skrgopi */ 7052331Skrgopi 7062331Skrgopi /* 7072331Skrgopi * bge_m_unicst_add() - will find an unused address slot, set the 7082331Skrgopi * address value to the one specified, reserve that slot and enable 7092331Skrgopi * the NIC to start filtering on the new MAC address. 7102331Skrgopi * address slot. Returns 0 on success. 7112331Skrgopi */ 7122331Skrgopi static int 7132331Skrgopi bge_m_unicst_add(void *arg, mac_multi_addr_t *maddr) 7142331Skrgopi { 7152331Skrgopi bge_t *bgep = arg; /* private device info */ 7162331Skrgopi mac_addr_slot_t slot; 7172406Skrgopi int err; 7182331Skrgopi 7192331Skrgopi if (mac_unicst_verify(bgep->mh, 7202331Skrgopi maddr->mma_addr, maddr->mma_addrlen) == B_FALSE) 7212331Skrgopi return (EINVAL); 7222331Skrgopi 7232331Skrgopi mutex_enter(bgep->genlock); 7242331Skrgopi if (bgep->unicst_addr_avail == 0) { 7252331Skrgopi /* no slots available */ 7262331Skrgopi mutex_exit(bgep->genlock); 7272331Skrgopi return (ENOSPC); 7282331Skrgopi } 7292331Skrgopi 7302331Skrgopi /* 7312331Skrgopi * Primary/default address is in slot 0. The next three 7322331Skrgopi * addresses are the multiple MAC addresses. So multiple 7332331Skrgopi * MAC address 0 is in slot 1, 1 in slot 2, and so on. 7342406Skrgopi * So the first multiple MAC address resides in slot 1. 7352331Skrgopi */ 7362406Skrgopi for (slot = 1; slot < bgep->unicst_addr_total; slot++) { 7372406Skrgopi if (bgep->curr_addr[slot].set == B_FALSE) { 7382406Skrgopi bgep->curr_addr[slot].set = B_TRUE; 7392331Skrgopi break; 7402331Skrgopi } 7412331Skrgopi } 7422331Skrgopi 7432406Skrgopi ASSERT(slot < bgep->unicst_addr_total); 7442331Skrgopi bgep->unicst_addr_avail--; 7452331Skrgopi mutex_exit(bgep->genlock); 7462331Skrgopi maddr->mma_slot = slot; 7472331Skrgopi 7482331Skrgopi if ((err = bge_unicst_set(bgep, maddr->mma_addr, slot)) != 0) { 7492331Skrgopi mutex_enter(bgep->genlock); 7502406Skrgopi bgep->curr_addr[slot].set = B_FALSE; 7512331Skrgopi bgep->unicst_addr_avail++; 7522331Skrgopi mutex_exit(bgep->genlock); 7532331Skrgopi } 7542331Skrgopi return (err); 7552331Skrgopi } 7562331Skrgopi 7572331Skrgopi /* 7582331Skrgopi * bge_m_unicst_remove() - removes a MAC address that was added by a 7592331Skrgopi * call to bge_m_unicst_add(). The slot number that was returned in 7602331Skrgopi * add() is passed in the call to remove the address. 7612331Skrgopi * Returns 0 on success. 7622331Skrgopi */ 7632331Skrgopi static int 7642331Skrgopi bge_m_unicst_remove(void *arg, mac_addr_slot_t slot) 7652331Skrgopi { 7662331Skrgopi bge_t *bgep = arg; /* private device info */ 7672331Skrgopi 7682406Skrgopi if (slot <= 0 || slot >= bgep->unicst_addr_total) 7692406Skrgopi return (EINVAL); 7702406Skrgopi 7712331Skrgopi mutex_enter(bgep->genlock); 7722406Skrgopi if (bgep->curr_addr[slot].set == B_TRUE) { 7732406Skrgopi bgep->curr_addr[slot].set = B_FALSE; 7742331Skrgopi bgep->unicst_addr_avail++; 7752331Skrgopi mutex_exit(bgep->genlock); 7762331Skrgopi /* 7772331Skrgopi * Copy the default address to the passed slot 7782331Skrgopi */ 7792406Skrgopi return (bge_unicst_set(bgep, bgep->curr_addr[0].addr, slot)); 7802331Skrgopi } 7812331Skrgopi mutex_exit(bgep->genlock); 7822331Skrgopi return (EINVAL); 7832331Skrgopi } 7842331Skrgopi 7852331Skrgopi /* 7862331Skrgopi * bge_m_unicst_modify() - modifies the value of an address that 7872331Skrgopi * has been added by bge_m_unicst_add(). The new address, address 7882331Skrgopi * length and the slot number that was returned in the call to add 7892331Skrgopi * should be passed to bge_m_unicst_modify(). mma_flags should be 7902331Skrgopi * set to 0. Returns 0 on success. 7912331Skrgopi */ 7922331Skrgopi static int 7932331Skrgopi bge_m_unicst_modify(void *arg, mac_multi_addr_t *maddr) 7942331Skrgopi { 7952331Skrgopi bge_t *bgep = arg; /* private device info */ 7962331Skrgopi mac_addr_slot_t slot; 7972331Skrgopi 7982331Skrgopi if (mac_unicst_verify(bgep->mh, 7992331Skrgopi maddr->mma_addr, maddr->mma_addrlen) == B_FALSE) 8002331Skrgopi return (EINVAL); 8012331Skrgopi 8022331Skrgopi slot = maddr->mma_slot; 8032331Skrgopi 8042406Skrgopi if (slot <= 0 || slot >= bgep->unicst_addr_total) 8052406Skrgopi return (EINVAL); 8062406Skrgopi 8072331Skrgopi mutex_enter(bgep->genlock); 8082406Skrgopi if (bgep->curr_addr[slot].set == B_TRUE) { 8092331Skrgopi mutex_exit(bgep->genlock); 8102331Skrgopi return (bge_unicst_set(bgep, maddr->mma_addr, slot)); 8112331Skrgopi } 8122331Skrgopi mutex_exit(bgep->genlock); 8132331Skrgopi 8142331Skrgopi return (EINVAL); 8152331Skrgopi } 8162331Skrgopi 8172331Skrgopi /* 8182331Skrgopi * bge_m_unicst_get() - will get the MAC address and all other 8192331Skrgopi * information related to the address slot passed in mac_multi_addr_t. 8202331Skrgopi * mma_flags should be set to 0 in the call. 8212331Skrgopi * On return, mma_flags can take the following values: 8222331Skrgopi * 1) MMAC_SLOT_UNUSED 8232331Skrgopi * 2) MMAC_SLOT_USED | MMAC_VENDOR_ADDR 8242331Skrgopi * 3) MMAC_SLOT_UNUSED | MMAC_VENDOR_ADDR 8252331Skrgopi * 4) MMAC_SLOT_USED 8262331Skrgopi */ 8272331Skrgopi static int 8282331Skrgopi bge_m_unicst_get(void *arg, mac_multi_addr_t *maddr) 8292331Skrgopi { 8302331Skrgopi bge_t *bgep = arg; /* private device info */ 8312331Skrgopi mac_addr_slot_t slot; 8322331Skrgopi 8332331Skrgopi slot = maddr->mma_slot; 8342331Skrgopi 8352406Skrgopi if (slot <= 0 || slot >= bgep->unicst_addr_total) 8362331Skrgopi return (EINVAL); 8372331Skrgopi 8382331Skrgopi mutex_enter(bgep->genlock); 8392406Skrgopi if (bgep->curr_addr[slot].set == B_TRUE) { 8402406Skrgopi ethaddr_copy(bgep->curr_addr[slot].addr, 8412331Skrgopi maddr->mma_addr); 8422331Skrgopi maddr->mma_flags = MMAC_SLOT_USED; 8432331Skrgopi } else { 8442331Skrgopi maddr->mma_flags = MMAC_SLOT_UNUSED; 8452331Skrgopi } 8462331Skrgopi mutex_exit(bgep->genlock); 8472331Skrgopi 8482331Skrgopi return (0); 8492331Skrgopi } 8502331Skrgopi 851*5903Ssowmini extern void bge_wake_factotum(bge_t *); 852*5903Ssowmini 853*5903Ssowmini static boolean_t 854*5903Ssowmini bge_param_locked(mac_prop_id_t pr_num) 855*5903Ssowmini { 856*5903Ssowmini /* 857*5903Ssowmini * All adv_* parameters are locked (read-only) while 858*5903Ssowmini * the device is in any sort of loopback mode ... 859*5903Ssowmini */ 860*5903Ssowmini switch (pr_num) { 861*5903Ssowmini case DLD_PROP_ADV_1000FDX_CAP: 862*5903Ssowmini case DLD_PROP_EN_1000FDX_CAP: 863*5903Ssowmini case DLD_PROP_ADV_1000HDX_CAP: 864*5903Ssowmini case DLD_PROP_EN_1000HDX_CAP: 865*5903Ssowmini case DLD_PROP_ADV_100FDX_CAP: 866*5903Ssowmini case DLD_PROP_EN_100FDX_CAP: 867*5903Ssowmini case DLD_PROP_ADV_100HDX_CAP: 868*5903Ssowmini case DLD_PROP_EN_100HDX_CAP: 869*5903Ssowmini case DLD_PROP_ADV_10FDX_CAP: 870*5903Ssowmini case DLD_PROP_EN_10FDX_CAP: 871*5903Ssowmini case DLD_PROP_ADV_10HDX_CAP: 872*5903Ssowmini case DLD_PROP_EN_10HDX_CAP: 873*5903Ssowmini case DLD_PROP_AUTONEG: 874*5903Ssowmini case DLD_PROP_FLOWCTRL: 875*5903Ssowmini return (B_TRUE); 876*5903Ssowmini } 877*5903Ssowmini return (B_FALSE); 878*5903Ssowmini } 879*5903Ssowmini /* 880*5903Ssowmini * callback functions for set/get of properties 881*5903Ssowmini */ 882*5903Ssowmini static int 883*5903Ssowmini bge_m_setprop(void *barg, const char *pr_name, mac_prop_id_t pr_num, 884*5903Ssowmini uint_t pr_valsize, const void *pr_val) 885*5903Ssowmini { 886*5903Ssowmini bge_t *bgep = barg; 887*5903Ssowmini int err = 0; 888*5903Ssowmini uint64_t cur_mtu, new_mtu; 889*5903Ssowmini uint_t maxsdu; 890*5903Ssowmini link_flowctrl_t fl; 891*5903Ssowmini 892*5903Ssowmini mutex_enter(bgep->genlock); 893*5903Ssowmini if (bgep->param_loop_mode != BGE_LOOP_NONE && 894*5903Ssowmini bge_param_locked(pr_num)) { 895*5903Ssowmini /* 896*5903Ssowmini * All adv_* parameters are locked (read-only) 897*5903Ssowmini * while the device is in any sort of loopback mode. 898*5903Ssowmini */ 899*5903Ssowmini mutex_exit(bgep->genlock); 900*5903Ssowmini return (EBUSY); 901*5903Ssowmini } 902*5903Ssowmini switch (pr_num) { 903*5903Ssowmini case DLD_PROP_EN_1000FDX_CAP: 904*5903Ssowmini bgep->param_en_1000fdx = *(uint8_t *)pr_val; 905*5903Ssowmini bgep->param_adv_1000fdx = *(uint8_t *)pr_val; 906*5903Ssowmini goto reprogram; 907*5903Ssowmini case DLD_PROP_EN_1000HDX_CAP: 908*5903Ssowmini bgep->param_en_1000hdx = *(uint8_t *)pr_val; 909*5903Ssowmini bgep->param_adv_1000hdx = *(uint8_t *)pr_val; 910*5903Ssowmini goto reprogram; 911*5903Ssowmini case DLD_PROP_EN_100FDX_CAP: 912*5903Ssowmini bgep->param_en_100fdx = *(uint8_t *)pr_val; 913*5903Ssowmini bgep->param_adv_100fdx = *(uint8_t *)pr_val; 914*5903Ssowmini goto reprogram; 915*5903Ssowmini case DLD_PROP_EN_100HDX_CAP: 916*5903Ssowmini bgep->param_en_100hdx = *(uint8_t *)pr_val; 917*5903Ssowmini bgep->param_adv_100hdx = *(uint8_t *)pr_val; 918*5903Ssowmini goto reprogram; 919*5903Ssowmini case DLD_PROP_EN_10FDX_CAP: 920*5903Ssowmini bgep->param_en_10fdx = *(uint8_t *)pr_val; 921*5903Ssowmini bgep->param_adv_10fdx = *(uint8_t *)pr_val; 922*5903Ssowmini goto reprogram; 923*5903Ssowmini case DLD_PROP_EN_10HDX_CAP: 924*5903Ssowmini bgep->param_en_10hdx = *(uint8_t *)pr_val; 925*5903Ssowmini bgep->param_adv_10hdx = *(uint8_t *)pr_val; 926*5903Ssowmini reprogram: 927*5903Ssowmini if (err == 0 && bge_reprogram(bgep) == IOC_INVAL) 928*5903Ssowmini err = EINVAL; 929*5903Ssowmini break; 930*5903Ssowmini case DLD_PROP_ADV_1000FDX_CAP: 931*5903Ssowmini case DLD_PROP_ADV_1000HDX_CAP: 932*5903Ssowmini case DLD_PROP_ADV_100FDX_CAP: 933*5903Ssowmini case DLD_PROP_ADV_100HDX_CAP: 934*5903Ssowmini case DLD_PROP_ADV_10FDX_CAP: 935*5903Ssowmini case DLD_PROP_ADV_10HDX_CAP: 936*5903Ssowmini case DLD_PROP_STATUS: 937*5903Ssowmini case DLD_PROP_SPEED: 938*5903Ssowmini case DLD_PROP_DUPLEX: 939*5903Ssowmini err = EINVAL; /* read-only prop. Can't set this */ 940*5903Ssowmini break; 941*5903Ssowmini case DLD_PROP_AUTONEG: 942*5903Ssowmini bgep->param_adv_autoneg = *(uint8_t *)pr_val; 943*5903Ssowmini if (bge_reprogram(bgep) == IOC_INVAL) 944*5903Ssowmini err = EINVAL; 945*5903Ssowmini break; 946*5903Ssowmini case DLD_PROP_DEFMTU: 947*5903Ssowmini cur_mtu = bgep->chipid.default_mtu; 948*5903Ssowmini bcopy(pr_val, &new_mtu, sizeof (new_mtu)); 949*5903Ssowmini if (new_mtu == cur_mtu) { 950*5903Ssowmini err = 0; 951*5903Ssowmini break; 952*5903Ssowmini } 953*5903Ssowmini if (new_mtu < BGE_DEFAULT_MTU || 954*5903Ssowmini new_mtu > BGE_MAXIMUM_MTU) { 955*5903Ssowmini err = EINVAL; 956*5903Ssowmini break; 957*5903Ssowmini } 958*5903Ssowmini if ((new_mtu > BGE_DEFAULT_MTU) && 959*5903Ssowmini (bgep->chipid.flags & CHIP_FLAG_NO_JUMBO)) { 960*5903Ssowmini err = EINVAL; 961*5903Ssowmini break; 962*5903Ssowmini } 963*5903Ssowmini if (bgep->bge_mac_state == BGE_MAC_STARTED) { 964*5903Ssowmini err = EBUSY; 965*5903Ssowmini break; 966*5903Ssowmini } 967*5903Ssowmini bgep->chipid.default_mtu = new_mtu; 968*5903Ssowmini if (bge_chip_id_init(bgep)) { 969*5903Ssowmini err = EINVAL; 970*5903Ssowmini break; 971*5903Ssowmini } 972*5903Ssowmini maxsdu = bgep->chipid.ethmax_size - 973*5903Ssowmini sizeof (struct ether_header); 974*5903Ssowmini err = mac_maxsdu_update(bgep->mh, maxsdu); 975*5903Ssowmini if (err == 0) { 976*5903Ssowmini bgep->bge_dma_error = B_TRUE; 977*5903Ssowmini bgep->manual_reset = B_TRUE; 978*5903Ssowmini bge_chip_stop(bgep, B_TRUE); 979*5903Ssowmini bge_wake_factotum(bgep); 980*5903Ssowmini err = 0; 981*5903Ssowmini } 982*5903Ssowmini break; 983*5903Ssowmini case DLD_PROP_FLOWCTRL: 984*5903Ssowmini bcopy(pr_val, &fl, sizeof (fl)); 985*5903Ssowmini switch (fl) { 986*5903Ssowmini default: 987*5903Ssowmini err = EINVAL; 988*5903Ssowmini break; 989*5903Ssowmini case LINK_FLOWCTRL_NONE: 990*5903Ssowmini bgep->param_adv_pause = 0; 991*5903Ssowmini bgep->param_adv_asym_pause = 0; 992*5903Ssowmini 993*5903Ssowmini bgep->param_link_rx_pause = B_FALSE; 994*5903Ssowmini bgep->param_link_tx_pause = B_FALSE; 995*5903Ssowmini break; 996*5903Ssowmini case LINK_FLOWCTRL_RX: 997*5903Ssowmini if (!((bgep->param_lp_pause == 0) && 998*5903Ssowmini (bgep->param_lp_asym_pause == 1))) { 999*5903Ssowmini err = EINVAL; 1000*5903Ssowmini break; 1001*5903Ssowmini } 1002*5903Ssowmini bgep->param_adv_pause = 1; 1003*5903Ssowmini bgep->param_adv_asym_pause = 1; 1004*5903Ssowmini 1005*5903Ssowmini bgep->param_link_rx_pause = B_TRUE; 1006*5903Ssowmini bgep->param_link_tx_pause = B_FALSE; 1007*5903Ssowmini break; 1008*5903Ssowmini case LINK_FLOWCTRL_TX: 1009*5903Ssowmini if (!((bgep->param_lp_pause == 1) && 1010*5903Ssowmini (bgep->param_lp_asym_pause == 1))) { 1011*5903Ssowmini err = EINVAL; 1012*5903Ssowmini break; 1013*5903Ssowmini } 1014*5903Ssowmini bgep->param_adv_pause = 0; 1015*5903Ssowmini bgep->param_adv_asym_pause = 1; 1016*5903Ssowmini 1017*5903Ssowmini bgep->param_link_rx_pause = B_FALSE; 1018*5903Ssowmini bgep->param_link_tx_pause = B_TRUE; 1019*5903Ssowmini break; 1020*5903Ssowmini case LINK_FLOWCTRL_BI: 1021*5903Ssowmini if (bgep->param_lp_pause != 1) { 1022*5903Ssowmini err = EINVAL; 1023*5903Ssowmini break; 1024*5903Ssowmini } 1025*5903Ssowmini bgep->param_adv_pause = 1; 1026*5903Ssowmini 1027*5903Ssowmini bgep->param_link_rx_pause = B_TRUE; 1028*5903Ssowmini bgep->param_link_tx_pause = B_TRUE; 1029*5903Ssowmini break; 1030*5903Ssowmini } 1031*5903Ssowmini 1032*5903Ssowmini if (err == 0) { 1033*5903Ssowmini if (bge_reprogram(bgep) == IOC_INVAL) 1034*5903Ssowmini err = EINVAL; 1035*5903Ssowmini } 1036*5903Ssowmini 1037*5903Ssowmini break; 1038*5903Ssowmini default: 1039*5903Ssowmini err = bge_set_priv_prop(bgep, pr_name, pr_valsize, 1040*5903Ssowmini pr_val); 1041*5903Ssowmini break; 1042*5903Ssowmini } 1043*5903Ssowmini mutex_exit(bgep->genlock); 1044*5903Ssowmini return (err); 1045*5903Ssowmini } 1046*5903Ssowmini static int 1047*5903Ssowmini bge_m_getprop(void *barg, const char *pr_name, mac_prop_id_t pr_num, 1048*5903Ssowmini uint_t pr_valsize, void *pr_val) 1049*5903Ssowmini { 1050*5903Ssowmini bge_t *bgep = barg; 1051*5903Ssowmini int err = 0; 1052*5903Ssowmini link_flowctrl_t fl; 1053*5903Ssowmini 1054*5903Ssowmini bzero(pr_val, pr_valsize); 1055*5903Ssowmini switch (pr_num) { 1056*5903Ssowmini case DLD_PROP_DUPLEX: 1057*5903Ssowmini if (pr_valsize < sizeof (uint8_t)) 1058*5903Ssowmini return (EINVAL); 1059*5903Ssowmini *(uint8_t *)pr_val = bgep->param_link_duplex; 1060*5903Ssowmini break; 1061*5903Ssowmini case DLD_PROP_SPEED: 1062*5903Ssowmini if (pr_valsize < sizeof (uint_t)) 1063*5903Ssowmini return (EINVAL); 1064*5903Ssowmini bcopy(&(bgep->param_link_speed), pr_val, 1065*5903Ssowmini sizeof (bgep->param_link_speed)); 1066*5903Ssowmini break; 1067*5903Ssowmini case DLD_PROP_STATUS: 1068*5903Ssowmini if (pr_valsize < sizeof (uint8_t)) 1069*5903Ssowmini return (EINVAL); 1070*5903Ssowmini *(uint8_t *)pr_val = bgep->param_link_up; 1071*5903Ssowmini break; 1072*5903Ssowmini case DLD_PROP_AUTONEG: 1073*5903Ssowmini if (pr_valsize < sizeof (uint8_t)) 1074*5903Ssowmini return (EINVAL); 1075*5903Ssowmini *(uint8_t *)pr_val = bgep->param_adv_autoneg; 1076*5903Ssowmini break; 1077*5903Ssowmini case DLD_PROP_DEFMTU: { 1078*5903Ssowmini uint64_t tmp = 0; 1079*5903Ssowmini 1080*5903Ssowmini if (pr_valsize < sizeof (uint64_t)) 1081*5903Ssowmini return (EINVAL); 1082*5903Ssowmini tmp = bgep->chipid.default_mtu; 1083*5903Ssowmini bcopy(&tmp, pr_val, sizeof (tmp)); 1084*5903Ssowmini break; 1085*5903Ssowmini } 1086*5903Ssowmini case DLD_PROP_FLOWCTRL: 1087*5903Ssowmini if (pr_valsize < sizeof (link_flowctrl_t)) 1088*5903Ssowmini return (EINVAL); 1089*5903Ssowmini if (bgep->param_link_rx_pause && 1090*5903Ssowmini !bgep->param_link_tx_pause) 1091*5903Ssowmini fl = LINK_FLOWCTRL_RX; 1092*5903Ssowmini 1093*5903Ssowmini if (!bgep->param_link_rx_pause && 1094*5903Ssowmini !bgep->param_link_tx_pause) 1095*5903Ssowmini fl = LINK_FLOWCTRL_NONE; 1096*5903Ssowmini 1097*5903Ssowmini if (!bgep->param_link_rx_pause && 1098*5903Ssowmini bgep->param_link_tx_pause) 1099*5903Ssowmini fl = LINK_FLOWCTRL_TX; 1100*5903Ssowmini 1101*5903Ssowmini if (bgep->param_link_rx_pause && 1102*5903Ssowmini bgep->param_link_tx_pause) 1103*5903Ssowmini fl = LINK_FLOWCTRL_BI; 1104*5903Ssowmini bcopy(&fl, pr_val, sizeof (fl)); 1105*5903Ssowmini break; 1106*5903Ssowmini case DLD_PROP_ADV_1000FDX_CAP: 1107*5903Ssowmini if (pr_valsize < sizeof (uint8_t)) 1108*5903Ssowmini return (EINVAL); 1109*5903Ssowmini *(uint8_t *)pr_val = bgep->param_adv_1000fdx; 1110*5903Ssowmini break; 1111*5903Ssowmini case DLD_PROP_EN_1000FDX_CAP: 1112*5903Ssowmini if (pr_valsize < sizeof (uint8_t)) 1113*5903Ssowmini return (EINVAL); 1114*5903Ssowmini *(uint8_t *)pr_val = bgep->param_en_1000fdx; 1115*5903Ssowmini break; 1116*5903Ssowmini case DLD_PROP_ADV_1000HDX_CAP: 1117*5903Ssowmini if (pr_valsize < sizeof (uint8_t)) 1118*5903Ssowmini return (EINVAL); 1119*5903Ssowmini *(uint8_t *)pr_val = bgep->param_adv_1000hdx; 1120*5903Ssowmini break; 1121*5903Ssowmini case DLD_PROP_EN_1000HDX_CAP: 1122*5903Ssowmini if (pr_valsize < sizeof (uint8_t)) 1123*5903Ssowmini return (EINVAL); 1124*5903Ssowmini *(uint8_t *)pr_val = bgep->param_en_1000hdx; 1125*5903Ssowmini break; 1126*5903Ssowmini case DLD_PROP_ADV_100FDX_CAP: 1127*5903Ssowmini if (pr_valsize < sizeof (uint8_t)) 1128*5903Ssowmini return (EINVAL); 1129*5903Ssowmini *(uint8_t *)pr_val = bgep->param_adv_100fdx; 1130*5903Ssowmini break; 1131*5903Ssowmini case DLD_PROP_EN_100FDX_CAP: 1132*5903Ssowmini if (pr_valsize < sizeof (uint8_t)) 1133*5903Ssowmini return (EINVAL); 1134*5903Ssowmini *(uint8_t *)pr_val = bgep->param_en_100fdx; 1135*5903Ssowmini break; 1136*5903Ssowmini case DLD_PROP_ADV_100HDX_CAP: 1137*5903Ssowmini if (pr_valsize < sizeof (uint8_t)) 1138*5903Ssowmini return (EINVAL); 1139*5903Ssowmini *(uint8_t *)pr_val = bgep->param_adv_100hdx; 1140*5903Ssowmini break; 1141*5903Ssowmini case DLD_PROP_EN_100HDX_CAP: 1142*5903Ssowmini if (pr_valsize < sizeof (uint8_t)) 1143*5903Ssowmini return (EINVAL); 1144*5903Ssowmini *(uint8_t *)pr_val = bgep->param_en_100hdx; 1145*5903Ssowmini break; 1146*5903Ssowmini case DLD_PROP_ADV_10FDX_CAP: 1147*5903Ssowmini if (pr_valsize < sizeof (uint8_t)) 1148*5903Ssowmini return (EINVAL); 1149*5903Ssowmini *(uint8_t *)pr_val = bgep->param_adv_10fdx; 1150*5903Ssowmini break; 1151*5903Ssowmini case DLD_PROP_EN_10FDX_CAP: 1152*5903Ssowmini if (pr_valsize < sizeof (uint8_t)) 1153*5903Ssowmini return (EINVAL); 1154*5903Ssowmini *(uint8_t *)pr_val = bgep->param_en_10fdx; 1155*5903Ssowmini break; 1156*5903Ssowmini case DLD_PROP_ADV_10HDX_CAP: 1157*5903Ssowmini if (pr_valsize < sizeof (uint8_t)) 1158*5903Ssowmini return (EINVAL); 1159*5903Ssowmini *(uint8_t *)pr_val = bgep->param_adv_10hdx; 1160*5903Ssowmini break; 1161*5903Ssowmini case DLD_PROP_EN_10HDX_CAP: 1162*5903Ssowmini if (pr_valsize < sizeof (uint8_t)) 1163*5903Ssowmini return (EINVAL); 1164*5903Ssowmini *(uint8_t *)pr_val = bgep->param_en_10hdx; 1165*5903Ssowmini break; 1166*5903Ssowmini default: 1167*5903Ssowmini err = bge_get_priv_prop(bgep, pr_name, pr_valsize, 1168*5903Ssowmini pr_val); 1169*5903Ssowmini return (err); 1170*5903Ssowmini } 1171*5903Ssowmini return (0); 1172*5903Ssowmini } 1173*5903Ssowmini 1174*5903Ssowmini /* ARGSUSED */ 1175*5903Ssowmini static int 1176*5903Ssowmini bge_set_priv_prop(bge_t *bgep, const char *pr_name, uint_t pr_valsize, 1177*5903Ssowmini const void *pr_val) 1178*5903Ssowmini { 1179*5903Ssowmini int err = 0; 1180*5903Ssowmini long result; 1181*5903Ssowmini 1182*5903Ssowmini if (strcmp(pr_name, "_drain_max") == 0) { 1183*5903Ssowmini 1184*5903Ssowmini /* 1185*5903Ssowmini * on the Tx side, we need to update the h/w register for 1186*5903Ssowmini * real packet transmission per packet. The drain_max parameter 1187*5903Ssowmini * is used to reduce the register access. This parameter 1188*5903Ssowmini * controls the max number of packets that we will hold before 1189*5903Ssowmini * updating the bge h/w to trigger h/w transmit. The bge 1190*5903Ssowmini * chipset usually has a max of 512 Tx descriptors, thus 1191*5903Ssowmini * the upper bound on drain_max is 512. 1192*5903Ssowmini */ 1193*5903Ssowmini if (pr_val == NULL) { 1194*5903Ssowmini err = EINVAL; 1195*5903Ssowmini return (err); 1196*5903Ssowmini } 1197*5903Ssowmini (void) ddi_strtol(pr_val, (char **)NULL, 0, &result); 1198*5903Ssowmini if (result > 512 || result < 1) 1199*5903Ssowmini err = EINVAL; 1200*5903Ssowmini else { 1201*5903Ssowmini bgep->param_drain_max = (uint32_t)result; 1202*5903Ssowmini if (bge_reprogram(bgep) == IOC_INVAL) 1203*5903Ssowmini err = EINVAL; 1204*5903Ssowmini } 1205*5903Ssowmini return (err); 1206*5903Ssowmini } 1207*5903Ssowmini if (strcmp(pr_name, "_msi_cnt") == 0) { 1208*5903Ssowmini 1209*5903Ssowmini if (pr_val == NULL) { 1210*5903Ssowmini err = EINVAL; 1211*5903Ssowmini return (err); 1212*5903Ssowmini } 1213*5903Ssowmini (void) ddi_strtol(pr_val, (char **)NULL, 0, &result); 1214*5903Ssowmini if (result > 7 || result < 0) 1215*5903Ssowmini err = EINVAL; 1216*5903Ssowmini else { 1217*5903Ssowmini bgep->param_msi_cnt = (uint32_t)result; 1218*5903Ssowmini if (bge_reprogram(bgep) == IOC_INVAL) 1219*5903Ssowmini err = EINVAL; 1220*5903Ssowmini } 1221*5903Ssowmini return (err); 1222*5903Ssowmini } 1223*5903Ssowmini if (strcmp(pr_name, "_intr_coalesce_blank_time") == 0) { 1224*5903Ssowmini if (ddi_strtol(pr_val, (char **)NULL, 0, &result) != 0) { 1225*5903Ssowmini return (EINVAL); 1226*5903Ssowmini } 1227*5903Ssowmini 1228*5903Ssowmini bgep->chipid.rx_ticks_norm = result; 1229*5903Ssowmini return (0); 1230*5903Ssowmini } 1231*5903Ssowmini 1232*5903Ssowmini if (strcmp(pr_name, "_intr_coalesce_pkt_cnt") == 0) { 1233*5903Ssowmini if (ddi_strtol(pr_val, (char **)NULL, 0, &result) != 0) 1234*5903Ssowmini return (EINVAL); 1235*5903Ssowmini 1236*5903Ssowmini bgep->chipid.rx_count_norm = result; 1237*5903Ssowmini return (0); 1238*5903Ssowmini } 1239*5903Ssowmini return (EINVAL); 1240*5903Ssowmini } 1241*5903Ssowmini 1242*5903Ssowmini static int 1243*5903Ssowmini bge_get_priv_prop(bge_t *bge, const char *pr_name, uint_t pr_valsize, 1244*5903Ssowmini void *pr_val) 1245*5903Ssowmini { 1246*5903Ssowmini char valstr[MAXNAMELEN]; 1247*5903Ssowmini int err = EINVAL; 1248*5903Ssowmini uint_t strsize; 1249*5903Ssowmini 1250*5903Ssowmini 1251*5903Ssowmini if (strcmp(pr_name, "_drain_max") == 0) { 1252*5903Ssowmini (void) sprintf(valstr, "%d", bge->param_drain_max); 1253*5903Ssowmini err = 0; 1254*5903Ssowmini goto done; 1255*5903Ssowmini } 1256*5903Ssowmini if (strcmp(pr_name, "_msi_cnt") == 0) { 1257*5903Ssowmini (void) sprintf(valstr, "%d", bge->param_msi_cnt); 1258*5903Ssowmini err = 0; 1259*5903Ssowmini goto done; 1260*5903Ssowmini } 1261*5903Ssowmini 1262*5903Ssowmini if (strcmp(pr_name, "_intr_coalesce_blank_time") == 0) { 1263*5903Ssowmini (void) sprintf(valstr, "%d", bge->chipid.rx_ticks_norm); 1264*5903Ssowmini err = 0; 1265*5903Ssowmini goto done; 1266*5903Ssowmini } 1267*5903Ssowmini 1268*5903Ssowmini if (strcmp(pr_name, "_intr_coalesce_pkt_cnt") == 0) { 1269*5903Ssowmini (void) sprintf(valstr, "%d", bge->chipid.rx_count_norm); 1270*5903Ssowmini err = 0; 1271*5903Ssowmini goto done; 1272*5903Ssowmini } 1273*5903Ssowmini 1274*5903Ssowmini done: 1275*5903Ssowmini strsize = (uint_t)strlen(valstr); 1276*5903Ssowmini if (pr_valsize < strsize) { 1277*5903Ssowmini err = ENOBUFS; 1278*5903Ssowmini } else { 1279*5903Ssowmini (void) strlcpy(pr_val, valstr, pr_valsize); 1280*5903Ssowmini } 1281*5903Ssowmini return (err); 1282*5903Ssowmini } 1283*5903Ssowmini 12842331Skrgopi /* 12851369Sdduvall * Compute the index of the required bit in the multicast hash map. 12861369Sdduvall * This must mirror the way the hardware actually does it! 12871369Sdduvall * See Broadcom document 570X-PG102-R page 125. 12881369Sdduvall */ 12891369Sdduvall static uint32_t 12901369Sdduvall bge_hash_index(const uint8_t *mca) 12911369Sdduvall { 12921369Sdduvall uint32_t hash; 12931369Sdduvall 12941369Sdduvall CRC32(hash, mca, ETHERADDRL, -1U, crc32_table); 12951369Sdduvall 12961369Sdduvall return (hash); 12971369Sdduvall } 12981369Sdduvall 12991369Sdduvall /* 13001369Sdduvall * bge_m_multicst_add() -- enable/disable a multicast address 13011369Sdduvall */ 13021369Sdduvall static int 13031369Sdduvall bge_m_multicst(void *arg, boolean_t add, const uint8_t *mca) 13041369Sdduvall { 13051369Sdduvall bge_t *bgep = arg; /* private device info */ 13061369Sdduvall uint32_t hash; 13071369Sdduvall uint32_t index; 13081369Sdduvall uint32_t word; 13091369Sdduvall uint32_t bit; 13101369Sdduvall uint8_t *refp; 13111369Sdduvall 13121369Sdduvall BGE_TRACE(("bge_m_multicst($%p, %s, %s)", arg, 13134588Sml149210 (add) ? "add" : "remove", ether_sprintf((void *)mca))); 13141369Sdduvall 13151369Sdduvall /* 13161369Sdduvall * Precalculate all required masks, pointers etc ... 13171369Sdduvall */ 13181369Sdduvall hash = bge_hash_index(mca); 13191369Sdduvall index = hash % BGE_HASH_TABLE_SIZE; 13201369Sdduvall word = index/32u; 13211369Sdduvall bit = 1 << (index % 32u); 13221369Sdduvall refp = &bgep->mcast_refs[index]; 13231369Sdduvall 13241369Sdduvall BGE_DEBUG(("bge_m_multicst: hash 0x%x index %d (%d:0x%x) = %d", 13254588Sml149210 hash, index, word, bit, *refp)); 13261369Sdduvall 13271369Sdduvall /* 13281369Sdduvall * We must set the appropriate bit in the hash map (and the 13291369Sdduvall * corresponding h/w register) when the refcount goes from 0 13301369Sdduvall * to >0, and clear it when the last ref goes away (refcount 13311369Sdduvall * goes from >0 back to 0). If we change the hash map, we 13321369Sdduvall * must also update the chip's hardware map registers. 13331369Sdduvall */ 13341369Sdduvall mutex_enter(bgep->genlock); 13351865Sdilpreet if (!(bgep->progress & PROGRESS_INTR)) { 13361865Sdilpreet /* can happen during autorecovery */ 13371865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_DEGRADED); 13381865Sdilpreet mutex_exit(bgep->genlock); 13391865Sdilpreet return (EIO); 13401865Sdilpreet } 13411369Sdduvall if (add) { 13421369Sdduvall if ((*refp)++ == 0) { 13431369Sdduvall bgep->mcast_hash[word] |= bit; 13441408Srandyf #ifdef BGE_IPMI_ASF 13451865Sdilpreet if (bge_chip_sync(bgep, B_TRUE) == DDI_FAILURE) { 13461408Srandyf #else 13471865Sdilpreet if (bge_chip_sync(bgep) == DDI_FAILURE) { 13481408Srandyf #endif 13491865Sdilpreet (void) bge_check_acc_handle(bgep, 13501865Sdilpreet bgep->cfg_handle); 13511865Sdilpreet (void) bge_check_acc_handle(bgep, 13521865Sdilpreet bgep->io_handle); 13531865Sdilpreet ddi_fm_service_impact(bgep->devinfo, 13541865Sdilpreet DDI_SERVICE_DEGRADED); 13551865Sdilpreet mutex_exit(bgep->genlock); 13561865Sdilpreet return (EIO); 13571865Sdilpreet } 13581369Sdduvall } 13591369Sdduvall } else { 13601369Sdduvall if (--(*refp) == 0) { 13611369Sdduvall bgep->mcast_hash[word] &= ~bit; 13621408Srandyf #ifdef BGE_IPMI_ASF 13631865Sdilpreet if (bge_chip_sync(bgep, B_TRUE) == DDI_FAILURE) { 13641408Srandyf #else 13651865Sdilpreet if (bge_chip_sync(bgep) == DDI_FAILURE) { 13661408Srandyf #endif 13671865Sdilpreet (void) bge_check_acc_handle(bgep, 13681865Sdilpreet bgep->cfg_handle); 13691865Sdilpreet (void) bge_check_acc_handle(bgep, 13701865Sdilpreet bgep->io_handle); 13711865Sdilpreet ddi_fm_service_impact(bgep->devinfo, 13721865Sdilpreet DDI_SERVICE_DEGRADED); 13731865Sdilpreet mutex_exit(bgep->genlock); 13741865Sdilpreet return (EIO); 13751865Sdilpreet } 13761369Sdduvall } 13771369Sdduvall } 13781369Sdduvall BGE_DEBUG(("bge_m_multicst($%p) done", arg)); 13791865Sdilpreet if (bge_check_acc_handle(bgep, bgep->cfg_handle) != DDI_FM_OK) { 13801865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_DEGRADED); 13811865Sdilpreet mutex_exit(bgep->genlock); 13821865Sdilpreet return (EIO); 13831865Sdilpreet } 13841865Sdilpreet if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) { 13851865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_DEGRADED); 13861865Sdilpreet mutex_exit(bgep->genlock); 13871865Sdilpreet return (EIO); 13881865Sdilpreet } 13891369Sdduvall mutex_exit(bgep->genlock); 13901369Sdduvall 13911369Sdduvall return (0); 13921369Sdduvall } 13931369Sdduvall 13941369Sdduvall /* 13951369Sdduvall * bge_m_promisc() -- set or reset promiscuous mode on the board 13961369Sdduvall * 13971369Sdduvall * Program the hardware to enable/disable promiscuous and/or 13981369Sdduvall * receive-all-multicast modes. 13991369Sdduvall */ 14001369Sdduvall static int 14011369Sdduvall bge_m_promisc(void *arg, boolean_t on) 14021369Sdduvall { 14031369Sdduvall bge_t *bgep = arg; 14041369Sdduvall 14051369Sdduvall BGE_TRACE(("bge_m_promisc_set($%p, %d)", arg, on)); 14061369Sdduvall 14071369Sdduvall /* 14081369Sdduvall * Store MAC layer specified mode and pass to chip layer to update h/w 14091369Sdduvall */ 14101369Sdduvall mutex_enter(bgep->genlock); 14111865Sdilpreet if (!(bgep->progress & PROGRESS_INTR)) { 14121865Sdilpreet /* can happen during autorecovery */ 14131865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_DEGRADED); 14141865Sdilpreet mutex_exit(bgep->genlock); 14151865Sdilpreet return (EIO); 14161865Sdilpreet } 14171369Sdduvall bgep->promisc = on; 14181408Srandyf #ifdef BGE_IPMI_ASF 14191865Sdilpreet if (bge_chip_sync(bgep, B_TRUE) == DDI_FAILURE) { 14201408Srandyf #else 14211865Sdilpreet if (bge_chip_sync(bgep) == DDI_FAILURE) { 14221408Srandyf #endif 14231865Sdilpreet (void) bge_check_acc_handle(bgep, bgep->cfg_handle); 14241865Sdilpreet (void) bge_check_acc_handle(bgep, bgep->io_handle); 14251865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_DEGRADED); 14261865Sdilpreet mutex_exit(bgep->genlock); 14271865Sdilpreet return (EIO); 14281865Sdilpreet } 14291369Sdduvall BGE_DEBUG(("bge_m_promisc_set($%p) done", arg)); 14301865Sdilpreet if (bge_check_acc_handle(bgep, bgep->cfg_handle) != DDI_FM_OK) { 14311865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_DEGRADED); 14321865Sdilpreet mutex_exit(bgep->genlock); 14331865Sdilpreet return (EIO); 14341865Sdilpreet } 14351865Sdilpreet if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) { 14361865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_DEGRADED); 14371865Sdilpreet mutex_exit(bgep->genlock); 14381865Sdilpreet return (EIO); 14391865Sdilpreet } 14401369Sdduvall mutex_exit(bgep->genlock); 14411369Sdduvall return (0); 14421369Sdduvall } 14431369Sdduvall 14442311Sseb /*ARGSUSED*/ 14452311Sseb static boolean_t 14462311Sseb bge_m_getcapab(void *arg, mac_capab_t cap, void *cap_data) 14472311Sseb { 14482331Skrgopi bge_t *bgep = arg; 14492331Skrgopi 14502311Sseb switch (cap) { 14512311Sseb case MAC_CAPAB_HCKSUM: { 14522311Sseb uint32_t *txflags = cap_data; 14532311Sseb 14542311Sseb *txflags = HCKSUM_INET_FULL_V4 | HCKSUM_IPHDRCKSUM; 14552311Sseb break; 14562311Sseb } 14572331Skrgopi 14582311Sseb case MAC_CAPAB_POLL: 14592311Sseb /* 14602311Sseb * There's nothing for us to fill in, simply returning 14612311Sseb * B_TRUE stating that we support polling is sufficient. 14622311Sseb */ 14632311Sseb break; 14642331Skrgopi 14652331Skrgopi case MAC_CAPAB_MULTIADDRESS: { 14662331Skrgopi multiaddress_capab_t *mmacp = cap_data; 14672331Skrgopi 14682331Skrgopi mutex_enter(bgep->genlock); 14692406Skrgopi /* 14702406Skrgopi * The number of MAC addresses made available by 14712406Skrgopi * this capability is one less than the total as 14722406Skrgopi * the primary address in slot 0 is counted in 14732406Skrgopi * the total. 14742406Skrgopi */ 14752406Skrgopi mmacp->maddr_naddr = bgep->unicst_addr_total - 1; 14762331Skrgopi mmacp->maddr_naddrfree = bgep->unicst_addr_avail; 14772331Skrgopi /* No multiple factory addresses, set mma_flag to 0 */ 14782331Skrgopi mmacp->maddr_flag = 0; 14792331Skrgopi mmacp->maddr_handle = bgep; 14802331Skrgopi mmacp->maddr_add = bge_m_unicst_add; 14812331Skrgopi mmacp->maddr_remove = bge_m_unicst_remove; 14822331Skrgopi mmacp->maddr_modify = bge_m_unicst_modify; 14832331Skrgopi mmacp->maddr_get = bge_m_unicst_get; 14842331Skrgopi mmacp->maddr_reserve = NULL; 14852331Skrgopi mutex_exit(bgep->genlock); 14862331Skrgopi break; 14872331Skrgopi } 14882331Skrgopi 14892311Sseb default: 14902311Sseb return (B_FALSE); 14912311Sseb } 14922311Sseb return (B_TRUE); 14932311Sseb } 14942311Sseb 14951369Sdduvall /* 14961369Sdduvall * Loopback ioctl code 14971369Sdduvall */ 14981369Sdduvall 14991369Sdduvall static lb_property_t loopmodes[] = { 15001369Sdduvall { normal, "normal", BGE_LOOP_NONE }, 15011369Sdduvall { external, "1000Mbps", BGE_LOOP_EXTERNAL_1000 }, 15021369Sdduvall { external, "100Mbps", BGE_LOOP_EXTERNAL_100 }, 15031369Sdduvall { external, "10Mbps", BGE_LOOP_EXTERNAL_10 }, 15041369Sdduvall { internal, "PHY", BGE_LOOP_INTERNAL_PHY }, 15051369Sdduvall { internal, "MAC", BGE_LOOP_INTERNAL_MAC } 15061369Sdduvall }; 15071369Sdduvall 15081369Sdduvall static enum ioc_reply 15091369Sdduvall bge_set_loop_mode(bge_t *bgep, uint32_t mode) 15101369Sdduvall { 15111369Sdduvall /* 15121369Sdduvall * If the mode isn't being changed, there's nothing to do ... 15131369Sdduvall */ 15141369Sdduvall if (mode == bgep->param_loop_mode) 15151369Sdduvall return (IOC_ACK); 15161369Sdduvall 15171369Sdduvall /* 15181369Sdduvall * Validate the requested mode and prepare a suitable message 15191369Sdduvall * to explain the link down/up cycle that the change will 15201369Sdduvall * probably induce ... 15211369Sdduvall */ 15221369Sdduvall switch (mode) { 15231369Sdduvall default: 15241369Sdduvall return (IOC_INVAL); 15251369Sdduvall 15261369Sdduvall case BGE_LOOP_NONE: 15271369Sdduvall case BGE_LOOP_EXTERNAL_1000: 15281369Sdduvall case BGE_LOOP_EXTERNAL_100: 15291369Sdduvall case BGE_LOOP_EXTERNAL_10: 15301369Sdduvall case BGE_LOOP_INTERNAL_PHY: 15311369Sdduvall case BGE_LOOP_INTERNAL_MAC: 15321369Sdduvall break; 15331369Sdduvall } 15341369Sdduvall 15351369Sdduvall /* 15361369Sdduvall * All OK; tell the caller to reprogram 15371369Sdduvall * the PHY and/or MAC for the new mode ... 15381369Sdduvall */ 15391369Sdduvall bgep->param_loop_mode = mode; 15401369Sdduvall return (IOC_RESTART_ACK); 15411369Sdduvall } 15421369Sdduvall 15431369Sdduvall static enum ioc_reply 15441369Sdduvall bge_loop_ioctl(bge_t *bgep, queue_t *wq, mblk_t *mp, struct iocblk *iocp) 15451369Sdduvall { 15461369Sdduvall lb_info_sz_t *lbsp; 15471369Sdduvall lb_property_t *lbpp; 15481369Sdduvall uint32_t *lbmp; 15491369Sdduvall int cmd; 15501369Sdduvall 15511369Sdduvall _NOTE(ARGUNUSED(wq)) 15521369Sdduvall 15531369Sdduvall /* 15541369Sdduvall * Validate format of ioctl 15551369Sdduvall */ 15561369Sdduvall if (mp->b_cont == NULL) 15571369Sdduvall return (IOC_INVAL); 15581369Sdduvall 15591369Sdduvall cmd = iocp->ioc_cmd; 15601369Sdduvall switch (cmd) { 15611369Sdduvall default: 15621369Sdduvall /* NOTREACHED */ 15631369Sdduvall bge_error(bgep, "bge_loop_ioctl: invalid cmd 0x%x", cmd); 15641369Sdduvall return (IOC_INVAL); 15651369Sdduvall 15661369Sdduvall case LB_GET_INFO_SIZE: 15671369Sdduvall if (iocp->ioc_count != sizeof (lb_info_sz_t)) 15681369Sdduvall return (IOC_INVAL); 15691369Sdduvall lbsp = (lb_info_sz_t *)mp->b_cont->b_rptr; 15701369Sdduvall *lbsp = sizeof (loopmodes); 15711369Sdduvall return (IOC_REPLY); 15721369Sdduvall 15731369Sdduvall case LB_GET_INFO: 15741369Sdduvall if (iocp->ioc_count != sizeof (loopmodes)) 15751369Sdduvall return (IOC_INVAL); 15761369Sdduvall lbpp = (lb_property_t *)mp->b_cont->b_rptr; 15771369Sdduvall bcopy(loopmodes, lbpp, sizeof (loopmodes)); 15781369Sdduvall return (IOC_REPLY); 15791369Sdduvall 15801369Sdduvall case LB_GET_MODE: 15811369Sdduvall if (iocp->ioc_count != sizeof (uint32_t)) 15821369Sdduvall return (IOC_INVAL); 15831369Sdduvall lbmp = (uint32_t *)mp->b_cont->b_rptr; 15841369Sdduvall *lbmp = bgep->param_loop_mode; 15851369Sdduvall return (IOC_REPLY); 15861369Sdduvall 15871369Sdduvall case LB_SET_MODE: 15881369Sdduvall if (iocp->ioc_count != sizeof (uint32_t)) 15891369Sdduvall return (IOC_INVAL); 15901369Sdduvall lbmp = (uint32_t *)mp->b_cont->b_rptr; 15911369Sdduvall return (bge_set_loop_mode(bgep, *lbmp)); 15921369Sdduvall } 15931369Sdduvall } 15941369Sdduvall 15951369Sdduvall /* 15961369Sdduvall * Specific bge IOCTLs, the gld module handles the generic ones. 15971369Sdduvall */ 15981369Sdduvall static void 15991369Sdduvall bge_m_ioctl(void *arg, queue_t *wq, mblk_t *mp) 16001369Sdduvall { 16011369Sdduvall bge_t *bgep = arg; 16021369Sdduvall struct iocblk *iocp; 16031369Sdduvall enum ioc_reply status; 16041369Sdduvall boolean_t need_privilege; 16051369Sdduvall int err; 16061369Sdduvall int cmd; 16071369Sdduvall 16081369Sdduvall /* 16091369Sdduvall * Validate the command before bothering with the mutex ... 16101369Sdduvall */ 16111369Sdduvall iocp = (struct iocblk *)mp->b_rptr; 16121369Sdduvall iocp->ioc_error = 0; 16131369Sdduvall need_privilege = B_TRUE; 16141369Sdduvall cmd = iocp->ioc_cmd; 16151369Sdduvall switch (cmd) { 16161369Sdduvall default: 16171369Sdduvall miocnak(wq, mp, 0, EINVAL); 16181369Sdduvall return; 16191369Sdduvall 16201369Sdduvall case BGE_MII_READ: 16211369Sdduvall case BGE_MII_WRITE: 16221369Sdduvall case BGE_SEE_READ: 16231369Sdduvall case BGE_SEE_WRITE: 16242675Szh199473 case BGE_FLASH_READ: 16252675Szh199473 case BGE_FLASH_WRITE: 16261369Sdduvall case BGE_DIAG: 16271369Sdduvall case BGE_PEEK: 16281369Sdduvall case BGE_POKE: 16291369Sdduvall case BGE_PHY_RESET: 16301369Sdduvall case BGE_SOFT_RESET: 16311369Sdduvall case BGE_HARD_RESET: 16321369Sdduvall break; 16331369Sdduvall 16341369Sdduvall case LB_GET_INFO_SIZE: 16351369Sdduvall case LB_GET_INFO: 16361369Sdduvall case LB_GET_MODE: 16371369Sdduvall need_privilege = B_FALSE; 16381369Sdduvall /* FALLTHRU */ 16391369Sdduvall case LB_SET_MODE: 16401369Sdduvall break; 16411369Sdduvall 16421369Sdduvall case ND_GET: 16431369Sdduvall need_privilege = B_FALSE; 16441369Sdduvall /* FALLTHRU */ 16451369Sdduvall case ND_SET: 16461369Sdduvall break; 16471369Sdduvall } 16481369Sdduvall 16491369Sdduvall if (need_privilege) { 16501369Sdduvall /* 16511369Sdduvall * Check for specific net_config privilege on Solaris 10+. 16521369Sdduvall */ 16532681Sgs150176 err = secpolicy_net_config(iocp->ioc_cr, B_FALSE); 16541369Sdduvall if (err != 0) { 16551369Sdduvall miocnak(wq, mp, 0, err); 16561369Sdduvall return; 16571369Sdduvall } 16581369Sdduvall } 16591369Sdduvall 16601369Sdduvall mutex_enter(bgep->genlock); 16611865Sdilpreet if (!(bgep->progress & PROGRESS_INTR)) { 16621865Sdilpreet /* can happen during autorecovery */ 16631865Sdilpreet mutex_exit(bgep->genlock); 16641865Sdilpreet miocnak(wq, mp, 0, EIO); 16651865Sdilpreet return; 16661865Sdilpreet } 16671369Sdduvall 16681369Sdduvall switch (cmd) { 16691369Sdduvall default: 16701369Sdduvall _NOTE(NOTREACHED) 16711369Sdduvall status = IOC_INVAL; 16721369Sdduvall break; 16731369Sdduvall 16741369Sdduvall case BGE_MII_READ: 16751369Sdduvall case BGE_MII_WRITE: 16761369Sdduvall case BGE_SEE_READ: 16771369Sdduvall case BGE_SEE_WRITE: 16782675Szh199473 case BGE_FLASH_READ: 16792675Szh199473 case BGE_FLASH_WRITE: 16801369Sdduvall case BGE_DIAG: 16811369Sdduvall case BGE_PEEK: 16821369Sdduvall case BGE_POKE: 16831369Sdduvall case BGE_PHY_RESET: 16841369Sdduvall case BGE_SOFT_RESET: 16851369Sdduvall case BGE_HARD_RESET: 16861369Sdduvall status = bge_chip_ioctl(bgep, wq, mp, iocp); 16871369Sdduvall break; 16881369Sdduvall 16891369Sdduvall case LB_GET_INFO_SIZE: 16901369Sdduvall case LB_GET_INFO: 16911369Sdduvall case LB_GET_MODE: 16921369Sdduvall case LB_SET_MODE: 16931369Sdduvall status = bge_loop_ioctl(bgep, wq, mp, iocp); 16941369Sdduvall break; 16951369Sdduvall 16961369Sdduvall case ND_GET: 16971369Sdduvall case ND_SET: 16981369Sdduvall status = bge_nd_ioctl(bgep, wq, mp, iocp); 16991369Sdduvall break; 17001369Sdduvall } 17011369Sdduvall 17021369Sdduvall /* 17031369Sdduvall * Do we need to reprogram the PHY and/or the MAC? 17041369Sdduvall * Do it now, while we still have the mutex. 17051369Sdduvall * 17061369Sdduvall * Note: update the PHY first, 'cos it controls the 17071369Sdduvall * speed/duplex parameters that the MAC code uses. 17081369Sdduvall */ 17091369Sdduvall switch (status) { 17101369Sdduvall case IOC_RESTART_REPLY: 17111369Sdduvall case IOC_RESTART_ACK: 1712*5903Ssowmini if (bge_reprogram(bgep) == IOC_INVAL) 17131865Sdilpreet status = IOC_INVAL; 17141369Sdduvall break; 17151369Sdduvall } 17161369Sdduvall 17171865Sdilpreet if (bge_check_acc_handle(bgep, bgep->cfg_handle) != DDI_FM_OK) { 17181865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_DEGRADED); 17191865Sdilpreet status = IOC_INVAL; 17201865Sdilpreet } 17211865Sdilpreet if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) { 17221865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_DEGRADED); 17231865Sdilpreet status = IOC_INVAL; 17241865Sdilpreet } 17251369Sdduvall mutex_exit(bgep->genlock); 17261369Sdduvall 17271369Sdduvall /* 17281369Sdduvall * Finally, decide how to reply 17291369Sdduvall */ 17301369Sdduvall switch (status) { 17311369Sdduvall default: 17321369Sdduvall case IOC_INVAL: 17331369Sdduvall /* 17341369Sdduvall * Error, reply with a NAK and EINVAL or the specified error 17351369Sdduvall */ 17361369Sdduvall miocnak(wq, mp, 0, iocp->ioc_error == 0 ? 17374588Sml149210 EINVAL : iocp->ioc_error); 17381369Sdduvall break; 17391369Sdduvall 17401369Sdduvall case IOC_DONE: 17411369Sdduvall /* 17421369Sdduvall * OK, reply already sent 17431369Sdduvall */ 17441369Sdduvall break; 17451369Sdduvall 17461369Sdduvall case IOC_RESTART_ACK: 17471369Sdduvall case IOC_ACK: 17481369Sdduvall /* 17491369Sdduvall * OK, reply with an ACK 17501369Sdduvall */ 17511369Sdduvall miocack(wq, mp, 0, 0); 17521369Sdduvall break; 17531369Sdduvall 17541369Sdduvall case IOC_RESTART_REPLY: 17551369Sdduvall case IOC_REPLY: 17561369Sdduvall /* 17571369Sdduvall * OK, send prepared reply as ACK or NAK 17581369Sdduvall */ 17591369Sdduvall mp->b_datap->db_type = iocp->ioc_error == 0 ? 17604588Sml149210 M_IOCACK : M_IOCNAK; 17611369Sdduvall qreply(wq, mp); 17621369Sdduvall break; 17631369Sdduvall } 17641369Sdduvall } 17651369Sdduvall 17661369Sdduvall static void 1767*5903Ssowmini bge_resources_add(bge_t *bgep, time_t time, uint_t pkt_cnt) 17681369Sdduvall { 1769*5903Ssowmini 17701369Sdduvall recv_ring_t *rrp; 17711369Sdduvall mac_rx_fifo_t mrf; 17721369Sdduvall int ring; 17731369Sdduvall 17741369Sdduvall /* 17751369Sdduvall * Register Rx rings as resources and save mac 17761369Sdduvall * resource id for future reference 17771369Sdduvall */ 17781369Sdduvall mrf.mrf_type = MAC_RX_FIFO; 17791369Sdduvall mrf.mrf_blank = bge_chip_blank; 17801369Sdduvall mrf.mrf_arg = (void *)bgep; 1781*5903Ssowmini mrf.mrf_normal_blank_time = time; 1782*5903Ssowmini mrf.mrf_normal_pkt_count = pkt_cnt; 17831369Sdduvall 17841369Sdduvall for (ring = 0; ring < bgep->chipid.rx_rings; ring++) { 17851369Sdduvall rrp = &bgep->recv[ring]; 17862311Sseb rrp->handle = mac_resource_add(bgep->mh, 17871369Sdduvall (mac_resource_t *)&mrf); 17881369Sdduvall } 1789*5903Ssowmini } 1790*5903Ssowmini 1791*5903Ssowmini static void 1792*5903Ssowmini bge_m_resources(void *arg) 1793*5903Ssowmini { 1794*5903Ssowmini bge_t *bgep = arg; 1795*5903Ssowmini 1796*5903Ssowmini mutex_enter(bgep->genlock); 1797*5903Ssowmini 1798*5903Ssowmini bge_resources_add(bgep, bgep->chipid.rx_ticks_norm, 1799*5903Ssowmini bgep->chipid.rx_count_norm); 18001369Sdduvall mutex_exit(bgep->genlock); 18011369Sdduvall } 18021369Sdduvall 18031369Sdduvall /* 18041369Sdduvall * ========== Per-instance setup/teardown code ========== 18051369Sdduvall */ 18061369Sdduvall 18071369Sdduvall #undef BGE_DBG 18081369Sdduvall #define BGE_DBG BGE_DBG_INIT /* debug flag for this code */ 18093334Sgs150176 /* 18103334Sgs150176 * Allocate an area of memory and a DMA handle for accessing it 18113334Sgs150176 */ 18123334Sgs150176 static int 18133334Sgs150176 bge_alloc_dma_mem(bge_t *bgep, size_t memsize, ddi_device_acc_attr_t *attr_p, 18143334Sgs150176 uint_t dma_flags, dma_area_t *dma_p) 18153334Sgs150176 { 18163334Sgs150176 caddr_t va; 18173334Sgs150176 int err; 18183334Sgs150176 18193334Sgs150176 BGE_TRACE(("bge_alloc_dma_mem($%p, %ld, $%p, 0x%x, $%p)", 18204588Sml149210 (void *)bgep, memsize, attr_p, dma_flags, dma_p)); 18213334Sgs150176 18223334Sgs150176 /* 18233334Sgs150176 * Allocate handle 18243334Sgs150176 */ 18253334Sgs150176 err = ddi_dma_alloc_handle(bgep->devinfo, &dma_attr, 18264588Sml149210 DDI_DMA_DONTWAIT, NULL, &dma_p->dma_hdl); 18273334Sgs150176 if (err != DDI_SUCCESS) 18283334Sgs150176 return (DDI_FAILURE); 18293334Sgs150176 18303334Sgs150176 /* 18313334Sgs150176 * Allocate memory 18323334Sgs150176 */ 18333334Sgs150176 err = ddi_dma_mem_alloc(dma_p->dma_hdl, memsize, attr_p, 18344588Sml149210 dma_flags, DDI_DMA_DONTWAIT, NULL, &va, &dma_p->alength, 18354588Sml149210 &dma_p->acc_hdl); 18363334Sgs150176 if (err != DDI_SUCCESS) 18373334Sgs150176 return (DDI_FAILURE); 18383334Sgs150176 18393334Sgs150176 /* 18403334Sgs150176 * Bind the two together 18413334Sgs150176 */ 18423334Sgs150176 dma_p->mem_va = va; 18433334Sgs150176 err = ddi_dma_addr_bind_handle(dma_p->dma_hdl, NULL, 18444588Sml149210 va, dma_p->alength, dma_flags, DDI_DMA_DONTWAIT, NULL, 18454588Sml149210 &dma_p->cookie, &dma_p->ncookies); 18463334Sgs150176 18473334Sgs150176 BGE_DEBUG(("bge_alloc_dma_mem(): bind %d bytes; err %d, %d cookies", 18484588Sml149210 dma_p->alength, err, dma_p->ncookies)); 18493334Sgs150176 18503334Sgs150176 if (err != DDI_DMA_MAPPED || dma_p->ncookies != 1) 18513334Sgs150176 return (DDI_FAILURE); 18523334Sgs150176 18533334Sgs150176 dma_p->nslots = ~0U; 18543334Sgs150176 dma_p->size = ~0U; 18553334Sgs150176 dma_p->token = ~0U; 18563334Sgs150176 dma_p->offset = 0; 18573334Sgs150176 return (DDI_SUCCESS); 18583334Sgs150176 } 18593334Sgs150176 18603334Sgs150176 /* 18613334Sgs150176 * Free one allocated area of DMAable memory 18623334Sgs150176 */ 18633334Sgs150176 static void 18643334Sgs150176 bge_free_dma_mem(dma_area_t *dma_p) 18653334Sgs150176 { 18663334Sgs150176 if (dma_p->dma_hdl != NULL) { 18673334Sgs150176 if (dma_p->ncookies) { 18683334Sgs150176 (void) ddi_dma_unbind_handle(dma_p->dma_hdl); 18693334Sgs150176 dma_p->ncookies = 0; 18703334Sgs150176 } 18713334Sgs150176 ddi_dma_free_handle(&dma_p->dma_hdl); 18723334Sgs150176 dma_p->dma_hdl = NULL; 18733334Sgs150176 } 18743334Sgs150176 18753334Sgs150176 if (dma_p->acc_hdl != NULL) { 18763334Sgs150176 ddi_dma_mem_free(&dma_p->acc_hdl); 18773334Sgs150176 dma_p->acc_hdl = NULL; 18783334Sgs150176 } 18793334Sgs150176 } 18801369Sdduvall /* 18811369Sdduvall * Utility routine to carve a slice off a chunk of allocated memory, 18821369Sdduvall * updating the chunk descriptor accordingly. The size of the slice 18831369Sdduvall * is given by the product of the <qty> and <size> parameters. 18841369Sdduvall */ 18851369Sdduvall static void 18861369Sdduvall bge_slice_chunk(dma_area_t *slice, dma_area_t *chunk, 18871369Sdduvall uint32_t qty, uint32_t size) 18881369Sdduvall { 18891369Sdduvall static uint32_t sequence = 0xbcd5704a; 18901369Sdduvall size_t totsize; 18911369Sdduvall 18921369Sdduvall totsize = qty*size; 18931369Sdduvall ASSERT(size >= 0); 18941369Sdduvall ASSERT(totsize <= chunk->alength); 18951369Sdduvall 18961369Sdduvall *slice = *chunk; 18971369Sdduvall slice->nslots = qty; 18981369Sdduvall slice->size = size; 18991369Sdduvall slice->alength = totsize; 19001369Sdduvall slice->token = ++sequence; 19011369Sdduvall 19021369Sdduvall chunk->mem_va = (caddr_t)chunk->mem_va + totsize; 19031369Sdduvall chunk->alength -= totsize; 19041369Sdduvall chunk->offset += totsize; 19051369Sdduvall chunk->cookie.dmac_laddress += totsize; 19061369Sdduvall chunk->cookie.dmac_size -= totsize; 19071369Sdduvall } 19081369Sdduvall 19091369Sdduvall /* 19101369Sdduvall * Initialise the specified Receive Producer (Buffer) Ring, using 19111369Sdduvall * the information in the <dma_area> descriptors that it contains 19121369Sdduvall * to set up all the other fields. This routine should be called 19131369Sdduvall * only once for each ring. 19141369Sdduvall */ 19151369Sdduvall static void 19161369Sdduvall bge_init_buff_ring(bge_t *bgep, uint64_t ring) 19171369Sdduvall { 19181369Sdduvall buff_ring_t *brp; 19191369Sdduvall bge_status_t *bsp; 19201369Sdduvall sw_rbd_t *srbdp; 19211369Sdduvall dma_area_t pbuf; 19221369Sdduvall uint32_t bufsize; 19231369Sdduvall uint32_t nslots; 19241369Sdduvall uint32_t slot; 19251369Sdduvall uint32_t split; 19261369Sdduvall 19271369Sdduvall static bge_regno_t nic_ring_addrs[BGE_BUFF_RINGS_MAX] = { 19281369Sdduvall NIC_MEM_SHADOW_BUFF_STD, 19291369Sdduvall NIC_MEM_SHADOW_BUFF_JUMBO, 19301369Sdduvall NIC_MEM_SHADOW_BUFF_MINI 19311369Sdduvall }; 19321369Sdduvall static bge_regno_t mailbox_regs[BGE_BUFF_RINGS_MAX] = { 19331369Sdduvall RECV_STD_PROD_INDEX_REG, 19341369Sdduvall RECV_JUMBO_PROD_INDEX_REG, 19351369Sdduvall RECV_MINI_PROD_INDEX_REG 19361369Sdduvall }; 19371369Sdduvall static bge_regno_t buff_cons_xref[BGE_BUFF_RINGS_MAX] = { 19381369Sdduvall STATUS_STD_BUFF_CONS_INDEX, 19391369Sdduvall STATUS_JUMBO_BUFF_CONS_INDEX, 19401369Sdduvall STATUS_MINI_BUFF_CONS_INDEX 19411369Sdduvall }; 19421369Sdduvall 19431369Sdduvall BGE_TRACE(("bge_init_buff_ring($%p, %d)", 19444588Sml149210 (void *)bgep, ring)); 19451369Sdduvall 19461369Sdduvall brp = &bgep->buff[ring]; 19471369Sdduvall nslots = brp->desc.nslots; 19481369Sdduvall ASSERT(brp->buf[0].nslots == nslots/BGE_SPLIT); 19491369Sdduvall bufsize = brp->buf[0].size; 19501369Sdduvall 19511369Sdduvall /* 19521369Sdduvall * Set up the copy of the h/w RCB 19531369Sdduvall * 19541369Sdduvall * Note: unlike Send & Receive Return Rings, (where the max_len 19551369Sdduvall * field holds the number of slots), in a Receive Buffer Ring 19561369Sdduvall * this field indicates the size of each buffer in the ring. 19571369Sdduvall */ 19581369Sdduvall brp->hw_rcb.host_ring_addr = brp->desc.cookie.dmac_laddress; 19591369Sdduvall brp->hw_rcb.max_len = bufsize; 19601369Sdduvall brp->hw_rcb.flags = nslots > 0 ? 0 : RCB_FLAG_RING_DISABLED; 19611369Sdduvall brp->hw_rcb.nic_ring_addr = nic_ring_addrs[ring]; 19621369Sdduvall 19631369Sdduvall /* 19641369Sdduvall * Other one-off initialisation of per-ring data 19651369Sdduvall */ 19661369Sdduvall brp->bgep = bgep; 19671369Sdduvall bsp = DMA_VPTR(bgep->status_block); 19681369Sdduvall brp->cons_index_p = &bsp->buff_cons_index[buff_cons_xref[ring]]; 19691369Sdduvall brp->chip_mbx_reg = mailbox_regs[ring]; 19701369Sdduvall mutex_init(brp->rf_lock, NULL, MUTEX_DRIVER, 19711369Sdduvall DDI_INTR_PRI(bgep->intr_pri)); 19721369Sdduvall 19731369Sdduvall /* 19741369Sdduvall * Allocate the array of s/w Receive Buffer Descriptors 19751369Sdduvall */ 19761369Sdduvall srbdp = kmem_zalloc(nslots*sizeof (*srbdp), KM_SLEEP); 19771369Sdduvall brp->sw_rbds = srbdp; 19781369Sdduvall 19791369Sdduvall /* 19801369Sdduvall * Now initialise each array element once and for all 19811369Sdduvall */ 19821369Sdduvall for (split = 0; split < BGE_SPLIT; ++split) { 19831369Sdduvall pbuf = brp->buf[split]; 19841369Sdduvall for (slot = 0; slot < nslots/BGE_SPLIT; ++srbdp, ++slot) 19851369Sdduvall bge_slice_chunk(&srbdp->pbuf, &pbuf, 1, bufsize); 19861369Sdduvall ASSERT(pbuf.alength == 0); 19871369Sdduvall } 19881369Sdduvall } 19891369Sdduvall 19901369Sdduvall /* 19911369Sdduvall * Clean up initialisation done above before the memory is freed 19921369Sdduvall */ 19931369Sdduvall static void 19941369Sdduvall bge_fini_buff_ring(bge_t *bgep, uint64_t ring) 19951369Sdduvall { 19961369Sdduvall buff_ring_t *brp; 19971369Sdduvall sw_rbd_t *srbdp; 19981369Sdduvall 19991369Sdduvall BGE_TRACE(("bge_fini_buff_ring($%p, %d)", 20004588Sml149210 (void *)bgep, ring)); 20011369Sdduvall 20021369Sdduvall brp = &bgep->buff[ring]; 20031369Sdduvall srbdp = brp->sw_rbds; 20041369Sdduvall kmem_free(srbdp, brp->desc.nslots*sizeof (*srbdp)); 20051369Sdduvall 20061369Sdduvall mutex_destroy(brp->rf_lock); 20071369Sdduvall } 20081369Sdduvall 20091369Sdduvall /* 20101369Sdduvall * Initialise the specified Receive (Return) Ring, using the 20111369Sdduvall * information in the <dma_area> descriptors that it contains 20121369Sdduvall * to set up all the other fields. This routine should be called 20131369Sdduvall * only once for each ring. 20141369Sdduvall */ 20151369Sdduvall static void 20161369Sdduvall bge_init_recv_ring(bge_t *bgep, uint64_t ring) 20171369Sdduvall { 20181369Sdduvall recv_ring_t *rrp; 20191369Sdduvall bge_status_t *bsp; 20201369Sdduvall uint32_t nslots; 20211369Sdduvall 20221369Sdduvall BGE_TRACE(("bge_init_recv_ring($%p, %d)", 20234588Sml149210 (void *)bgep, ring)); 20241369Sdduvall 20251369Sdduvall /* 20261369Sdduvall * The chip architecture requires that receive return rings have 20271369Sdduvall * 512 or 1024 or 2048 elements per ring. See 570X-PG108-R page 103. 20281369Sdduvall */ 20291369Sdduvall rrp = &bgep->recv[ring]; 20301369Sdduvall nslots = rrp->desc.nslots; 20311369Sdduvall ASSERT(nslots == 0 || nslots == 512 || 20324588Sml149210 nslots == 1024 || nslots == 2048); 20331369Sdduvall 20341369Sdduvall /* 20351369Sdduvall * Set up the copy of the h/w RCB 20361369Sdduvall */ 20371369Sdduvall rrp->hw_rcb.host_ring_addr = rrp->desc.cookie.dmac_laddress; 20381369Sdduvall rrp->hw_rcb.max_len = nslots; 20391369Sdduvall rrp->hw_rcb.flags = nslots > 0 ? 0 : RCB_FLAG_RING_DISABLED; 20401369Sdduvall rrp->hw_rcb.nic_ring_addr = 0; 20411369Sdduvall 20421369Sdduvall /* 20431369Sdduvall * Other one-off initialisation of per-ring data 20441369Sdduvall */ 20451369Sdduvall rrp->bgep = bgep; 20461369Sdduvall bsp = DMA_VPTR(bgep->status_block); 20471369Sdduvall rrp->prod_index_p = RECV_INDEX_P(bsp, ring); 20481369Sdduvall rrp->chip_mbx_reg = RECV_RING_CONS_INDEX_REG(ring); 20491369Sdduvall mutex_init(rrp->rx_lock, NULL, MUTEX_DRIVER, 20501369Sdduvall DDI_INTR_PRI(bgep->intr_pri)); 20511369Sdduvall } 20521369Sdduvall 20531369Sdduvall 20541369Sdduvall /* 20551369Sdduvall * Clean up initialisation done above before the memory is freed 20561369Sdduvall */ 20571369Sdduvall static void 20581369Sdduvall bge_fini_recv_ring(bge_t *bgep, uint64_t ring) 20591369Sdduvall { 20601369Sdduvall recv_ring_t *rrp; 20611369Sdduvall 20621369Sdduvall BGE_TRACE(("bge_fini_recv_ring($%p, %d)", 20634588Sml149210 (void *)bgep, ring)); 20641369Sdduvall 20651369Sdduvall rrp = &bgep->recv[ring]; 20661369Sdduvall if (rrp->rx_softint) 20671369Sdduvall ddi_remove_softintr(rrp->rx_softint); 20681369Sdduvall mutex_destroy(rrp->rx_lock); 20691369Sdduvall } 20701369Sdduvall 20711369Sdduvall /* 20721369Sdduvall * Initialise the specified Send Ring, using the information in the 20731369Sdduvall * <dma_area> descriptors that it contains to set up all the other 20741369Sdduvall * fields. This routine should be called only once for each ring. 20751369Sdduvall */ 20761369Sdduvall static void 20771369Sdduvall bge_init_send_ring(bge_t *bgep, uint64_t ring) 20781369Sdduvall { 20791369Sdduvall send_ring_t *srp; 20801369Sdduvall bge_status_t *bsp; 20811369Sdduvall sw_sbd_t *ssbdp; 20821369Sdduvall dma_area_t desc; 20831369Sdduvall dma_area_t pbuf; 20841369Sdduvall uint32_t nslots; 20851369Sdduvall uint32_t slot; 20861369Sdduvall uint32_t split; 20873334Sgs150176 sw_txbuf_t *txbuf; 20881369Sdduvall 20891369Sdduvall BGE_TRACE(("bge_init_send_ring($%p, %d)", 20904588Sml149210 (void *)bgep, ring)); 20911369Sdduvall 20921369Sdduvall /* 20931369Sdduvall * The chip architecture requires that host-based send rings 20941369Sdduvall * have 512 elements per ring. See 570X-PG102-R page 56. 20951369Sdduvall */ 20961369Sdduvall srp = &bgep->send[ring]; 20971369Sdduvall nslots = srp->desc.nslots; 20981369Sdduvall ASSERT(nslots == 0 || nslots == 512); 20991369Sdduvall 21001369Sdduvall /* 21011369Sdduvall * Set up the copy of the h/w RCB 21021369Sdduvall */ 21031369Sdduvall srp->hw_rcb.host_ring_addr = srp->desc.cookie.dmac_laddress; 21041369Sdduvall srp->hw_rcb.max_len = nslots; 21051369Sdduvall srp->hw_rcb.flags = nslots > 0 ? 0 : RCB_FLAG_RING_DISABLED; 21061369Sdduvall srp->hw_rcb.nic_ring_addr = NIC_MEM_SHADOW_SEND_RING(ring, nslots); 21071369Sdduvall 21081369Sdduvall /* 21091369Sdduvall * Other one-off initialisation of per-ring data 21101369Sdduvall */ 21111369Sdduvall srp->bgep = bgep; 21121369Sdduvall bsp = DMA_VPTR(bgep->status_block); 21131369Sdduvall srp->cons_index_p = SEND_INDEX_P(bsp, ring); 21141369Sdduvall srp->chip_mbx_reg = SEND_RING_HOST_INDEX_REG(ring); 21151369Sdduvall mutex_init(srp->tx_lock, NULL, MUTEX_DRIVER, 21161369Sdduvall DDI_INTR_PRI(bgep->intr_pri)); 21173334Sgs150176 mutex_init(srp->txbuf_lock, NULL, MUTEX_DRIVER, 21183334Sgs150176 DDI_INTR_PRI(bgep->intr_pri)); 21193334Sgs150176 mutex_init(srp->freetxbuf_lock, NULL, MUTEX_DRIVER, 21203334Sgs150176 DDI_INTR_PRI(bgep->intr_pri)); 21211369Sdduvall mutex_init(srp->tc_lock, NULL, MUTEX_DRIVER, 21221369Sdduvall DDI_INTR_PRI(bgep->intr_pri)); 21233334Sgs150176 if (nslots == 0) 21243334Sgs150176 return; 21251369Sdduvall 21261369Sdduvall /* 21271369Sdduvall * Allocate the array of s/w Send Buffer Descriptors 21281369Sdduvall */ 21291369Sdduvall ssbdp = kmem_zalloc(nslots*sizeof (*ssbdp), KM_SLEEP); 21303334Sgs150176 txbuf = kmem_zalloc(BGE_SEND_BUF_MAX*sizeof (*txbuf), KM_SLEEP); 21313334Sgs150176 srp->txbuf_head = 21323334Sgs150176 kmem_zalloc(BGE_SEND_BUF_MAX*sizeof (bge_queue_item_t), KM_SLEEP); 21333334Sgs150176 srp->pktp = kmem_zalloc(BGE_SEND_BUF_MAX*sizeof (send_pkt_t), KM_SLEEP); 21341369Sdduvall srp->sw_sbds = ssbdp; 21353334Sgs150176 srp->txbuf = txbuf; 21363334Sgs150176 srp->tx_buffers = BGE_SEND_BUF_NUM; 21373334Sgs150176 srp->tx_buffers_low = srp->tx_buffers / 4; 21383334Sgs150176 if (bgep->chipid.snd_buff_size > BGE_SEND_BUFF_SIZE_DEFAULT) 21393334Sgs150176 srp->tx_array_max = BGE_SEND_BUF_ARRAY_JUMBO; 21403334Sgs150176 else 21413334Sgs150176 srp->tx_array_max = BGE_SEND_BUF_ARRAY; 21423334Sgs150176 srp->tx_array = 1; 21431369Sdduvall 21441369Sdduvall /* 21453334Sgs150176 * Chunk tx desc area 21461369Sdduvall */ 21471369Sdduvall desc = srp->desc; 21483334Sgs150176 for (slot = 0; slot < nslots; ++ssbdp, ++slot) { 21493334Sgs150176 bge_slice_chunk(&ssbdp->desc, &desc, 1, 21503334Sgs150176 sizeof (bge_sbd_t)); 21513334Sgs150176 } 21523334Sgs150176 ASSERT(desc.alength == 0); 21533334Sgs150176 21543334Sgs150176 /* 21553334Sgs150176 * Chunk tx buffer area 21563334Sgs150176 */ 21571369Sdduvall for (split = 0; split < BGE_SPLIT; ++split) { 21583334Sgs150176 pbuf = srp->buf[0][split]; 21593334Sgs150176 for (slot = 0; slot < BGE_SEND_BUF_NUM/BGE_SPLIT; ++slot) { 21603334Sgs150176 bge_slice_chunk(&txbuf->buf, &pbuf, 1, 21613334Sgs150176 bgep->chipid.snd_buff_size); 21623334Sgs150176 txbuf++; 21631369Sdduvall } 21641369Sdduvall ASSERT(pbuf.alength == 0); 21651369Sdduvall } 21661369Sdduvall } 21671369Sdduvall 21681369Sdduvall /* 21691369Sdduvall * Clean up initialisation done above before the memory is freed 21701369Sdduvall */ 21711369Sdduvall static void 21721369Sdduvall bge_fini_send_ring(bge_t *bgep, uint64_t ring) 21731369Sdduvall { 21741369Sdduvall send_ring_t *srp; 21753334Sgs150176 uint32_t array; 21763334Sgs150176 uint32_t split; 21773334Sgs150176 uint32_t nslots; 21781369Sdduvall 21791369Sdduvall BGE_TRACE(("bge_fini_send_ring($%p, %d)", 21804588Sml149210 (void *)bgep, ring)); 21811369Sdduvall 21821369Sdduvall srp = &bgep->send[ring]; 21833334Sgs150176 mutex_destroy(srp->tc_lock); 21843334Sgs150176 mutex_destroy(srp->freetxbuf_lock); 21853334Sgs150176 mutex_destroy(srp->txbuf_lock); 21861369Sdduvall mutex_destroy(srp->tx_lock); 21873334Sgs150176 nslots = srp->desc.nslots; 21883334Sgs150176 if (nslots == 0) 21893334Sgs150176 return; 21903334Sgs150176 21913334Sgs150176 for (array = 1; array < srp->tx_array; ++array) 21923334Sgs150176 for (split = 0; split < BGE_SPLIT; ++split) 21933334Sgs150176 bge_free_dma_mem(&srp->buf[array][split]); 21943334Sgs150176 kmem_free(srp->sw_sbds, nslots*sizeof (*srp->sw_sbds)); 21953334Sgs150176 kmem_free(srp->txbuf_head, BGE_SEND_BUF_MAX*sizeof (*srp->txbuf_head)); 21963334Sgs150176 kmem_free(srp->txbuf, BGE_SEND_BUF_MAX*sizeof (*srp->txbuf)); 21973334Sgs150176 kmem_free(srp->pktp, BGE_SEND_BUF_MAX*sizeof (*srp->pktp)); 21983334Sgs150176 srp->sw_sbds = NULL; 21993334Sgs150176 srp->txbuf_head = NULL; 22003334Sgs150176 srp->txbuf = NULL; 22013334Sgs150176 srp->pktp = NULL; 22021369Sdduvall } 22031369Sdduvall 22041369Sdduvall /* 22051369Sdduvall * Initialise all transmit, receive, and buffer rings. 22061369Sdduvall */ 22071865Sdilpreet void 22081369Sdduvall bge_init_rings(bge_t *bgep) 22091369Sdduvall { 22103334Sgs150176 uint32_t ring; 22111369Sdduvall 22121369Sdduvall BGE_TRACE(("bge_init_rings($%p)", (void *)bgep)); 22131369Sdduvall 22141369Sdduvall /* 22151369Sdduvall * Perform one-off initialisation of each ring ... 22161369Sdduvall */ 22171369Sdduvall for (ring = 0; ring < BGE_SEND_RINGS_MAX; ++ring) 22181369Sdduvall bge_init_send_ring(bgep, ring); 22191369Sdduvall for (ring = 0; ring < BGE_RECV_RINGS_MAX; ++ring) 22201369Sdduvall bge_init_recv_ring(bgep, ring); 22211369Sdduvall for (ring = 0; ring < BGE_BUFF_RINGS_MAX; ++ring) 22221369Sdduvall bge_init_buff_ring(bgep, ring); 22231369Sdduvall } 22241369Sdduvall 22251369Sdduvall /* 22261369Sdduvall * Undo the work of bge_init_rings() above before the memory is freed 22271369Sdduvall */ 22281865Sdilpreet void 22291369Sdduvall bge_fini_rings(bge_t *bgep) 22301369Sdduvall { 22313334Sgs150176 uint32_t ring; 22321369Sdduvall 22331369Sdduvall BGE_TRACE(("bge_fini_rings($%p)", (void *)bgep)); 22341369Sdduvall 22351369Sdduvall for (ring = 0; ring < BGE_BUFF_RINGS_MAX; ++ring) 22361369Sdduvall bge_fini_buff_ring(bgep, ring); 22371369Sdduvall for (ring = 0; ring < BGE_RECV_RINGS_MAX; ++ring) 22381369Sdduvall bge_fini_recv_ring(bgep, ring); 22391369Sdduvall for (ring = 0; ring < BGE_SEND_RINGS_MAX; ++ring) 22401369Sdduvall bge_fini_send_ring(bgep, ring); 22411369Sdduvall } 22421369Sdduvall 22431369Sdduvall /* 22443334Sgs150176 * Called from the bge_m_stop() to free the tx buffers which are 22453334Sgs150176 * allocated from the tx process. 22461369Sdduvall */ 22473334Sgs150176 void 22483334Sgs150176 bge_free_txbuf_arrays(send_ring_t *srp) 22491369Sdduvall { 22503334Sgs150176 uint32_t array; 22513334Sgs150176 uint32_t split; 22523334Sgs150176 22533334Sgs150176 ASSERT(mutex_owned(srp->tx_lock)); 22541369Sdduvall 22551369Sdduvall /* 22563334Sgs150176 * Free the extra tx buffer DMA area 22571369Sdduvall */ 22583334Sgs150176 for (array = 1; array < srp->tx_array; ++array) 22593334Sgs150176 for (split = 0; split < BGE_SPLIT; ++split) 22603334Sgs150176 bge_free_dma_mem(&srp->buf[array][split]); 22611369Sdduvall 22621369Sdduvall /* 22633334Sgs150176 * Restore initial tx buffer numbers 22641369Sdduvall */ 22653334Sgs150176 srp->tx_array = 1; 22663334Sgs150176 srp->tx_buffers = BGE_SEND_BUF_NUM; 22673334Sgs150176 srp->tx_buffers_low = srp->tx_buffers / 4; 22683334Sgs150176 srp->tx_flow = 0; 22693334Sgs150176 bzero(srp->pktp, BGE_SEND_BUF_MAX * sizeof (*srp->pktp)); 22701369Sdduvall } 22711369Sdduvall 22721369Sdduvall /* 22733334Sgs150176 * Called from tx process to allocate more tx buffers 22741369Sdduvall */ 22753334Sgs150176 bge_queue_item_t * 22763334Sgs150176 bge_alloc_txbuf_array(bge_t *bgep, send_ring_t *srp) 22771369Sdduvall { 22783334Sgs150176 bge_queue_t *txbuf_queue; 22793334Sgs150176 bge_queue_item_t *txbuf_item_last; 22803334Sgs150176 bge_queue_item_t *txbuf_item; 22813334Sgs150176 bge_queue_item_t *txbuf_item_rtn; 22823334Sgs150176 sw_txbuf_t *txbuf; 22833334Sgs150176 dma_area_t area; 22843334Sgs150176 size_t txbuffsize; 22853334Sgs150176 uint32_t slot; 22863334Sgs150176 uint32_t array; 22873334Sgs150176 uint32_t split; 22883334Sgs150176 uint32_t err; 22893334Sgs150176 22903334Sgs150176 ASSERT(mutex_owned(srp->tx_lock)); 22913334Sgs150176 22923334Sgs150176 array = srp->tx_array; 22933334Sgs150176 if (array >= srp->tx_array_max) 22943334Sgs150176 return (NULL); 22953334Sgs150176 22963334Sgs150176 /* 22973334Sgs150176 * Allocate memory & handles for TX buffers 22983334Sgs150176 */ 22993334Sgs150176 txbuffsize = BGE_SEND_BUF_NUM*bgep->chipid.snd_buff_size; 23003334Sgs150176 ASSERT((txbuffsize % BGE_SPLIT) == 0); 23013334Sgs150176 for (split = 0; split < BGE_SPLIT; ++split) { 23023334Sgs150176 err = bge_alloc_dma_mem(bgep, txbuffsize/BGE_SPLIT, 23034588Sml149210 &bge_data_accattr, DDI_DMA_WRITE | BGE_DMA_MODE, 23044588Sml149210 &srp->buf[array][split]); 23053334Sgs150176 if (err != DDI_SUCCESS) { 23063334Sgs150176 /* Free the last already allocated OK chunks */ 23073334Sgs150176 for (slot = 0; slot <= split; ++slot) 23083334Sgs150176 bge_free_dma_mem(&srp->buf[array][slot]); 23093334Sgs150176 srp->tx_alloc_fail++; 23103334Sgs150176 return (NULL); 23111369Sdduvall } 23123334Sgs150176 } 23133334Sgs150176 23143334Sgs150176 /* 23153334Sgs150176 * Chunk tx buffer area 23163334Sgs150176 */ 23173334Sgs150176 txbuf = srp->txbuf + array*BGE_SEND_BUF_NUM; 23183334Sgs150176 for (split = 0; split < BGE_SPLIT; ++split) { 23193334Sgs150176 area = srp->buf[array][split]; 23203334Sgs150176 for (slot = 0; slot < BGE_SEND_BUF_NUM/BGE_SPLIT; ++slot) { 23213334Sgs150176 bge_slice_chunk(&txbuf->buf, &area, 1, 23223334Sgs150176 bgep->chipid.snd_buff_size); 23233334Sgs150176 txbuf++; 23243334Sgs150176 } 23251369Sdduvall } 23261369Sdduvall 23273334Sgs150176 /* 23283334Sgs150176 * Add above buffers to the tx buffer pop queue 23293334Sgs150176 */ 23303334Sgs150176 txbuf_item = srp->txbuf_head + array*BGE_SEND_BUF_NUM; 23313334Sgs150176 txbuf = srp->txbuf + array*BGE_SEND_BUF_NUM; 23323334Sgs150176 txbuf_item_last = NULL; 23333334Sgs150176 for (slot = 0; slot < BGE_SEND_BUF_NUM; ++slot) { 23343334Sgs150176 txbuf_item->item = txbuf; 23353334Sgs150176 txbuf_item->next = txbuf_item_last; 23363334Sgs150176 txbuf_item_last = txbuf_item; 23373334Sgs150176 txbuf++; 23383334Sgs150176 txbuf_item++; 23391369Sdduvall } 23403334Sgs150176 txbuf_item = srp->txbuf_head + array*BGE_SEND_BUF_NUM; 23413334Sgs150176 txbuf_item_rtn = txbuf_item; 23423334Sgs150176 txbuf_item++; 23433334Sgs150176 txbuf_queue = srp->txbuf_pop_queue; 23443334Sgs150176 mutex_enter(txbuf_queue->lock); 23453334Sgs150176 txbuf_item->next = txbuf_queue->head; 23463334Sgs150176 txbuf_queue->head = txbuf_item_last; 23473334Sgs150176 txbuf_queue->count += BGE_SEND_BUF_NUM - 1; 23483334Sgs150176 mutex_exit(txbuf_queue->lock); 23493334Sgs150176 23503334Sgs150176 srp->tx_array++; 23513334Sgs150176 srp->tx_buffers += BGE_SEND_BUF_NUM; 23523334Sgs150176 srp->tx_buffers_low = srp->tx_buffers / 4; 23533334Sgs150176 23543334Sgs150176 return (txbuf_item_rtn); 23551369Sdduvall } 23561369Sdduvall 23571369Sdduvall /* 23581369Sdduvall * This function allocates all the transmit and receive buffers 23593334Sgs150176 * and descriptors, in four chunks. 23601369Sdduvall */ 23611865Sdilpreet int 23621369Sdduvall bge_alloc_bufs(bge_t *bgep) 23631369Sdduvall { 23641369Sdduvall dma_area_t area; 23651369Sdduvall size_t rxbuffsize; 23661369Sdduvall size_t txbuffsize; 23671369Sdduvall size_t rxbuffdescsize; 23681369Sdduvall size_t rxdescsize; 23691369Sdduvall size_t txdescsize; 23703334Sgs150176 uint32_t ring; 23713334Sgs150176 uint32_t rx_rings = bgep->chipid.rx_rings; 23723334Sgs150176 uint32_t tx_rings = bgep->chipid.tx_rings; 23731369Sdduvall int split; 23741369Sdduvall int err; 23751369Sdduvall 23761369Sdduvall BGE_TRACE(("bge_alloc_bufs($%p)", 23774588Sml149210 (void *)bgep)); 23781369Sdduvall 23791908Sly149593 rxbuffsize = BGE_STD_SLOTS_USED*bgep->chipid.std_buf_size; 23801369Sdduvall rxbuffsize += bgep->chipid.jumbo_slots*bgep->chipid.recv_jumbo_size; 23811369Sdduvall rxbuffsize += BGE_MINI_SLOTS_USED*BGE_MINI_BUFF_SIZE; 23821369Sdduvall 23833334Sgs150176 txbuffsize = BGE_SEND_BUF_NUM*bgep->chipid.snd_buff_size; 23841369Sdduvall txbuffsize *= tx_rings; 23851369Sdduvall 23861369Sdduvall rxdescsize = rx_rings*bgep->chipid.recv_slots; 23871369Sdduvall rxdescsize *= sizeof (bge_rbd_t); 23881369Sdduvall 23891369Sdduvall rxbuffdescsize = BGE_STD_SLOTS_USED; 23901369Sdduvall rxbuffdescsize += bgep->chipid.jumbo_slots; 23911369Sdduvall rxbuffdescsize += BGE_MINI_SLOTS_USED; 23921369Sdduvall rxbuffdescsize *= sizeof (bge_rbd_t); 23931369Sdduvall 23941369Sdduvall txdescsize = tx_rings*BGE_SEND_SLOTS_USED; 23951369Sdduvall txdescsize *= sizeof (bge_sbd_t); 23961369Sdduvall txdescsize += sizeof (bge_statistics_t); 23971369Sdduvall txdescsize += sizeof (bge_status_t); 23981369Sdduvall txdescsize += BGE_STATUS_PADDING; 23991369Sdduvall 24001369Sdduvall /* 24013907Szh199473 * Enable PCI relaxed ordering only for RX/TX data buffers 24023907Szh199473 */ 24033907Szh199473 if (bge_relaxed_ordering) 24043907Szh199473 dma_attr.dma_attr_flags |= DDI_DMA_RELAXED_ORDERING; 24053907Szh199473 24063907Szh199473 /* 24071369Sdduvall * Allocate memory & handles for RX buffers 24081369Sdduvall */ 24091369Sdduvall ASSERT((rxbuffsize % BGE_SPLIT) == 0); 24101369Sdduvall for (split = 0; split < BGE_SPLIT; ++split) { 24111369Sdduvall err = bge_alloc_dma_mem(bgep, rxbuffsize/BGE_SPLIT, 24124588Sml149210 &bge_data_accattr, DDI_DMA_READ | BGE_DMA_MODE, 24134588Sml149210 &bgep->rx_buff[split]); 24141369Sdduvall if (err != DDI_SUCCESS) 24151369Sdduvall return (DDI_FAILURE); 24161369Sdduvall } 24171369Sdduvall 24181369Sdduvall /* 24191369Sdduvall * Allocate memory & handles for TX buffers 24201369Sdduvall */ 24211369Sdduvall ASSERT((txbuffsize % BGE_SPLIT) == 0); 24221369Sdduvall for (split = 0; split < BGE_SPLIT; ++split) { 24231369Sdduvall err = bge_alloc_dma_mem(bgep, txbuffsize/BGE_SPLIT, 24244588Sml149210 &bge_data_accattr, DDI_DMA_WRITE | BGE_DMA_MODE, 24254588Sml149210 &bgep->tx_buff[split]); 24261369Sdduvall if (err != DDI_SUCCESS) 24271369Sdduvall return (DDI_FAILURE); 24281369Sdduvall } 24291369Sdduvall 24303907Szh199473 dma_attr.dma_attr_flags &= ~DDI_DMA_RELAXED_ORDERING; 24313907Szh199473 24321369Sdduvall /* 24331369Sdduvall * Allocate memory & handles for receive return rings 24341369Sdduvall */ 24351369Sdduvall ASSERT((rxdescsize % rx_rings) == 0); 24361369Sdduvall for (split = 0; split < rx_rings; ++split) { 24371369Sdduvall err = bge_alloc_dma_mem(bgep, rxdescsize/rx_rings, 24384588Sml149210 &bge_desc_accattr, DDI_DMA_RDWR | DDI_DMA_CONSISTENT, 24394588Sml149210 &bgep->rx_desc[split]); 24401369Sdduvall if (err != DDI_SUCCESS) 24411369Sdduvall return (DDI_FAILURE); 24421369Sdduvall } 24431369Sdduvall 24441369Sdduvall /* 24451369Sdduvall * Allocate memory & handles for buffer (producer) descriptor rings 24461369Sdduvall */ 24471369Sdduvall err = bge_alloc_dma_mem(bgep, rxbuffdescsize, &bge_desc_accattr, 24484588Sml149210 DDI_DMA_RDWR | DDI_DMA_CONSISTENT, &bgep->rx_desc[split]); 24491369Sdduvall if (err != DDI_SUCCESS) 24501369Sdduvall return (DDI_FAILURE); 24511369Sdduvall 24521369Sdduvall /* 24531369Sdduvall * Allocate memory & handles for TX descriptor rings, 24541369Sdduvall * status block, and statistics area 24551369Sdduvall */ 24561369Sdduvall err = bge_alloc_dma_mem(bgep, txdescsize, &bge_desc_accattr, 24574588Sml149210 DDI_DMA_RDWR | DDI_DMA_CONSISTENT, &bgep->tx_desc); 24581369Sdduvall if (err != DDI_SUCCESS) 24591369Sdduvall return (DDI_FAILURE); 24601369Sdduvall 24611369Sdduvall /* 24621369Sdduvall * Now carve up each of the allocated areas ... 24631369Sdduvall */ 24641369Sdduvall for (split = 0; split < BGE_SPLIT; ++split) { 24651369Sdduvall area = bgep->rx_buff[split]; 24661369Sdduvall bge_slice_chunk(&bgep->buff[BGE_STD_BUFF_RING].buf[split], 24674588Sml149210 &area, BGE_STD_SLOTS_USED/BGE_SPLIT, 24684588Sml149210 bgep->chipid.std_buf_size); 24691369Sdduvall bge_slice_chunk(&bgep->buff[BGE_JUMBO_BUFF_RING].buf[split], 24704588Sml149210 &area, bgep->chipid.jumbo_slots/BGE_SPLIT, 24714588Sml149210 bgep->chipid.recv_jumbo_size); 24721369Sdduvall bge_slice_chunk(&bgep->buff[BGE_MINI_BUFF_RING].buf[split], 24734588Sml149210 &area, BGE_MINI_SLOTS_USED/BGE_SPLIT, 24744588Sml149210 BGE_MINI_BUFF_SIZE); 24751369Sdduvall ASSERT(area.alength >= 0); 24761369Sdduvall } 24771369Sdduvall 24781369Sdduvall for (split = 0; split < BGE_SPLIT; ++split) { 24791369Sdduvall area = bgep->tx_buff[split]; 24801369Sdduvall for (ring = 0; ring < tx_rings; ++ring) 24813334Sgs150176 bge_slice_chunk(&bgep->send[ring].buf[0][split], 24824588Sml149210 &area, BGE_SEND_BUF_NUM/BGE_SPLIT, 24834588Sml149210 bgep->chipid.snd_buff_size); 24841369Sdduvall for (; ring < BGE_SEND_RINGS_MAX; ++ring) 24853334Sgs150176 bge_slice_chunk(&bgep->send[ring].buf[0][split], 24864588Sml149210 &area, 0, bgep->chipid.snd_buff_size); 24871369Sdduvall ASSERT(area.alength >= 0); 24881369Sdduvall } 24891369Sdduvall 24901369Sdduvall for (ring = 0; ring < rx_rings; ++ring) 24911369Sdduvall bge_slice_chunk(&bgep->recv[ring].desc, &bgep->rx_desc[ring], 24924588Sml149210 bgep->chipid.recv_slots, sizeof (bge_rbd_t)); 24931369Sdduvall 24941369Sdduvall area = bgep->rx_desc[rx_rings]; 24951369Sdduvall for (; ring < BGE_RECV_RINGS_MAX; ++ring) 24961369Sdduvall bge_slice_chunk(&bgep->recv[ring].desc, &area, 24974588Sml149210 0, sizeof (bge_rbd_t)); 24981369Sdduvall bge_slice_chunk(&bgep->buff[BGE_STD_BUFF_RING].desc, &area, 24994588Sml149210 BGE_STD_SLOTS_USED, sizeof (bge_rbd_t)); 25001369Sdduvall bge_slice_chunk(&bgep->buff[BGE_JUMBO_BUFF_RING].desc, &area, 25014588Sml149210 bgep->chipid.jumbo_slots, sizeof (bge_rbd_t)); 25021369Sdduvall bge_slice_chunk(&bgep->buff[BGE_MINI_BUFF_RING].desc, &area, 25034588Sml149210 BGE_MINI_SLOTS_USED, sizeof (bge_rbd_t)); 25041369Sdduvall ASSERT(area.alength == 0); 25051369Sdduvall 25061369Sdduvall area = bgep->tx_desc; 25071369Sdduvall for (ring = 0; ring < tx_rings; ++ring) 25081369Sdduvall bge_slice_chunk(&bgep->send[ring].desc, &area, 25094588Sml149210 BGE_SEND_SLOTS_USED, sizeof (bge_sbd_t)); 25101369Sdduvall for (; ring < BGE_SEND_RINGS_MAX; ++ring) 25111369Sdduvall bge_slice_chunk(&bgep->send[ring].desc, &area, 25124588Sml149210 0, sizeof (bge_sbd_t)); 25131369Sdduvall bge_slice_chunk(&bgep->statistics, &area, 1, sizeof (bge_statistics_t)); 25141369Sdduvall bge_slice_chunk(&bgep->status_block, &area, 1, sizeof (bge_status_t)); 25151369Sdduvall ASSERT(area.alength == BGE_STATUS_PADDING); 25161369Sdduvall DMA_ZERO(bgep->status_block); 25171369Sdduvall 25181369Sdduvall return (DDI_SUCCESS); 25191369Sdduvall } 25201369Sdduvall 25211369Sdduvall /* 25221369Sdduvall * This routine frees the transmit and receive buffers and descriptors. 25231369Sdduvall * Make sure the chip is stopped before calling it! 25241369Sdduvall */ 25251865Sdilpreet void 25261369Sdduvall bge_free_bufs(bge_t *bgep) 25271369Sdduvall { 25281369Sdduvall int split; 25291369Sdduvall 25301369Sdduvall BGE_TRACE(("bge_free_bufs($%p)", 25314588Sml149210 (void *)bgep)); 25321369Sdduvall 25331369Sdduvall bge_free_dma_mem(&bgep->tx_desc); 25341369Sdduvall for (split = 0; split < BGE_RECV_RINGS_SPLIT; ++split) 25351369Sdduvall bge_free_dma_mem(&bgep->rx_desc[split]); 25361369Sdduvall for (split = 0; split < BGE_SPLIT; ++split) 25371369Sdduvall bge_free_dma_mem(&bgep->tx_buff[split]); 25381369Sdduvall for (split = 0; split < BGE_SPLIT; ++split) 25391369Sdduvall bge_free_dma_mem(&bgep->rx_buff[split]); 25401369Sdduvall } 25411369Sdduvall 25421369Sdduvall /* 25431369Sdduvall * Determine (initial) MAC address ("BIA") to use for this interface 25441369Sdduvall */ 25451369Sdduvall 25461369Sdduvall static void 25471369Sdduvall bge_find_mac_address(bge_t *bgep, chip_id_t *cidp) 25481369Sdduvall { 25491369Sdduvall struct ether_addr sysaddr; 25501369Sdduvall char propbuf[8]; /* "true" or "false", plus NUL */ 25511369Sdduvall uchar_t *bytes; 25521369Sdduvall int *ints; 25531369Sdduvall uint_t nelts; 25541369Sdduvall int err; 25551369Sdduvall 25561369Sdduvall BGE_TRACE(("bge_find_mac_address($%p)", 25574588Sml149210 (void *)bgep)); 25581369Sdduvall 25591369Sdduvall BGE_DEBUG(("bge_find_mac_address: hw_mac_addr %012llx, => %s (%sset)", 25604588Sml149210 cidp->hw_mac_addr, 25614588Sml149210 ether_sprintf((void *)cidp->vendor_addr.addr), 25624588Sml149210 cidp->vendor_addr.set ? "" : "not ")); 25631369Sdduvall 25641369Sdduvall /* 25651369Sdduvall * The "vendor's factory-set address" may already have 25661369Sdduvall * been extracted from the chip, but if the property 25671369Sdduvall * "local-mac-address" is set we use that instead. It 25681369Sdduvall * will normally be set by OBP, but it could also be 25691369Sdduvall * specified in a .conf file(!) 25701369Sdduvall * 25711369Sdduvall * There doesn't seem to be a way to define byte-array 25721369Sdduvall * properties in a .conf, so we check whether it looks 25731369Sdduvall * like an array of 6 ints instead. 25741369Sdduvall * 25751369Sdduvall * Then, we check whether it looks like an array of 6 25761369Sdduvall * bytes (which it should, if OBP set it). If we can't 25771369Sdduvall * make sense of it either way, we'll ignore it. 25781369Sdduvall */ 25791369Sdduvall err = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, bgep->devinfo, 25804588Sml149210 DDI_PROP_DONTPASS, localmac_propname, &ints, &nelts); 25811369Sdduvall if (err == DDI_PROP_SUCCESS) { 25821369Sdduvall if (nelts == ETHERADDRL) { 25831369Sdduvall while (nelts--) 25841369Sdduvall cidp->vendor_addr.addr[nelts] = ints[nelts]; 25852331Skrgopi cidp->vendor_addr.set = B_TRUE; 25861369Sdduvall } 25871369Sdduvall ddi_prop_free(ints); 25881369Sdduvall } 25891369Sdduvall 25901369Sdduvall err = ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, bgep->devinfo, 25914588Sml149210 DDI_PROP_DONTPASS, localmac_propname, &bytes, &nelts); 25921369Sdduvall if (err == DDI_PROP_SUCCESS) { 25931369Sdduvall if (nelts == ETHERADDRL) { 25941369Sdduvall while (nelts--) 25951369Sdduvall cidp->vendor_addr.addr[nelts] = bytes[nelts]; 25962331Skrgopi cidp->vendor_addr.set = B_TRUE; 25971369Sdduvall } 25981369Sdduvall ddi_prop_free(bytes); 25991369Sdduvall } 26001369Sdduvall 26011369Sdduvall BGE_DEBUG(("bge_find_mac_address: +local %s (%sset)", 26024588Sml149210 ether_sprintf((void *)cidp->vendor_addr.addr), 26034588Sml149210 cidp->vendor_addr.set ? "" : "not ")); 26041369Sdduvall 26051369Sdduvall /* 26061369Sdduvall * Look up the OBP property "local-mac-address?". Note that even 26071369Sdduvall * though its value is a string (which should be "true" or "false"), 26081369Sdduvall * it can't be decoded by ddi_prop_lookup_string(9F). So, we zero 26091369Sdduvall * the buffer first and then fetch the property as an untyped array; 26101369Sdduvall * this may or may not include a final NUL, but since there will 26111369Sdduvall * always be one left at the end of the buffer we can now treat it 26121369Sdduvall * as a string anyway. 26131369Sdduvall */ 26141369Sdduvall nelts = sizeof (propbuf); 26151369Sdduvall bzero(propbuf, nelts--); 26161369Sdduvall err = ddi_getlongprop_buf(DDI_DEV_T_ANY, bgep->devinfo, 26174588Sml149210 DDI_PROP_CANSLEEP, localmac_boolname, propbuf, (int *)&nelts); 26181369Sdduvall 26191369Sdduvall /* 26201369Sdduvall * Now, if the address still isn't set from the hardware (SEEPROM) 26211369Sdduvall * or the OBP or .conf property, OR if the user has foolishly set 26221369Sdduvall * 'local-mac-address? = false', use "the system address" instead 26231369Sdduvall * (but only if it's non-null i.e. has been set from the IDPROM). 26241369Sdduvall */ 26252331Skrgopi if (cidp->vendor_addr.set == B_FALSE || strcmp(propbuf, "false") == 0) 26261369Sdduvall if (localetheraddr(NULL, &sysaddr) != 0) { 26271369Sdduvall ethaddr_copy(&sysaddr, cidp->vendor_addr.addr); 26282331Skrgopi cidp->vendor_addr.set = B_TRUE; 26291369Sdduvall } 26301369Sdduvall 26311369Sdduvall BGE_DEBUG(("bge_find_mac_address: +system %s (%sset)", 26324588Sml149210 ether_sprintf((void *)cidp->vendor_addr.addr), 26334588Sml149210 cidp->vendor_addr.set ? "" : "not ")); 26341369Sdduvall 26351369Sdduvall /* 26361369Sdduvall * Finally(!), if there's a valid "mac-address" property (created 26371369Sdduvall * if we netbooted from this interface), we must use this instead 26381369Sdduvall * of any of the above to ensure that the NFS/install server doesn't 26391369Sdduvall * get confused by the address changing as Solaris takes over! 26401369Sdduvall */ 26411369Sdduvall err = ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, bgep->devinfo, 26424588Sml149210 DDI_PROP_DONTPASS, macaddr_propname, &bytes, &nelts); 26431369Sdduvall if (err == DDI_PROP_SUCCESS) { 26441369Sdduvall if (nelts == ETHERADDRL) { 26451369Sdduvall while (nelts--) 26461369Sdduvall cidp->vendor_addr.addr[nelts] = bytes[nelts]; 26472331Skrgopi cidp->vendor_addr.set = B_TRUE; 26481369Sdduvall } 26491369Sdduvall ddi_prop_free(bytes); 26501369Sdduvall } 26511369Sdduvall 26521369Sdduvall BGE_DEBUG(("bge_find_mac_address: =final %s (%sset)", 26534588Sml149210 ether_sprintf((void *)cidp->vendor_addr.addr), 26544588Sml149210 cidp->vendor_addr.set ? "" : "not ")); 26551369Sdduvall } 26561369Sdduvall 26571865Sdilpreet 26581865Sdilpreet /*ARGSUSED*/ 26591865Sdilpreet int 26601865Sdilpreet bge_check_acc_handle(bge_t *bgep, ddi_acc_handle_t handle) 26611865Sdilpreet { 26621865Sdilpreet ddi_fm_error_t de; 26631865Sdilpreet 26641865Sdilpreet ddi_fm_acc_err_get(handle, &de, DDI_FME_VERSION); 26651865Sdilpreet ddi_fm_acc_err_clear(handle, DDI_FME_VERSION); 26661865Sdilpreet return (de.fme_status); 26671865Sdilpreet } 26681865Sdilpreet 26691865Sdilpreet /*ARGSUSED*/ 26701865Sdilpreet int 26711865Sdilpreet bge_check_dma_handle(bge_t *bgep, ddi_dma_handle_t handle) 26721865Sdilpreet { 26731865Sdilpreet ddi_fm_error_t de; 26741865Sdilpreet 26751865Sdilpreet ASSERT(bgep->progress & PROGRESS_BUFS); 26761865Sdilpreet ddi_fm_dma_err_get(handle, &de, DDI_FME_VERSION); 26771865Sdilpreet return (de.fme_status); 26781865Sdilpreet } 26791865Sdilpreet 26801865Sdilpreet /* 26811865Sdilpreet * The IO fault service error handling callback function 26821865Sdilpreet */ 26831865Sdilpreet /*ARGSUSED*/ 26841865Sdilpreet static int 26851865Sdilpreet bge_fm_error_cb(dev_info_t *dip, ddi_fm_error_t *err, const void *impl_data) 26861865Sdilpreet { 26871865Sdilpreet /* 26881865Sdilpreet * as the driver can always deal with an error in any dma or 26891865Sdilpreet * access handle, we can just return the fme_status value. 26901865Sdilpreet */ 26911865Sdilpreet pci_ereport_post(dip, err, NULL); 26921865Sdilpreet return (err->fme_status); 26931865Sdilpreet } 26941865Sdilpreet 26951865Sdilpreet static void 26961865Sdilpreet bge_fm_init(bge_t *bgep) 26971865Sdilpreet { 26981865Sdilpreet ddi_iblock_cookie_t iblk; 26991865Sdilpreet 27001865Sdilpreet /* Only register with IO Fault Services if we have some capability */ 27011865Sdilpreet if (bgep->fm_capabilities) { 27021865Sdilpreet bge_reg_accattr.devacc_attr_access = DDI_FLAGERR_ACC; 27031865Sdilpreet bge_desc_accattr.devacc_attr_access = DDI_FLAGERR_ACC; 27041865Sdilpreet dma_attr.dma_attr_flags = DDI_DMA_FLAGERR; 27051865Sdilpreet 27061865Sdilpreet /* Register capabilities with IO Fault Services */ 27071865Sdilpreet ddi_fm_init(bgep->devinfo, &bgep->fm_capabilities, &iblk); 27081865Sdilpreet 27091865Sdilpreet /* 27101865Sdilpreet * Initialize pci ereport capabilities if ereport capable 27111865Sdilpreet */ 27121865Sdilpreet if (DDI_FM_EREPORT_CAP(bgep->fm_capabilities) || 27131865Sdilpreet DDI_FM_ERRCB_CAP(bgep->fm_capabilities)) 27141865Sdilpreet pci_ereport_setup(bgep->devinfo); 27151865Sdilpreet 27161865Sdilpreet /* 27171865Sdilpreet * Register error callback if error callback capable 27181865Sdilpreet */ 27191865Sdilpreet if (DDI_FM_ERRCB_CAP(bgep->fm_capabilities)) 27201865Sdilpreet ddi_fm_handler_register(bgep->devinfo, 27214588Sml149210 bge_fm_error_cb, (void*) bgep); 27221865Sdilpreet } else { 27231865Sdilpreet /* 27241865Sdilpreet * These fields have to be cleared of FMA if there are no 27251865Sdilpreet * FMA capabilities at runtime. 27261865Sdilpreet */ 27271865Sdilpreet bge_reg_accattr.devacc_attr_access = DDI_DEFAULT_ACC; 27281865Sdilpreet bge_desc_accattr.devacc_attr_access = DDI_DEFAULT_ACC; 27291865Sdilpreet dma_attr.dma_attr_flags = 0; 27301865Sdilpreet } 27311865Sdilpreet } 27321865Sdilpreet 27331865Sdilpreet static void 27341865Sdilpreet bge_fm_fini(bge_t *bgep) 27351865Sdilpreet { 27361865Sdilpreet /* Only unregister FMA capabilities if we registered some */ 27371865Sdilpreet if (bgep->fm_capabilities) { 27381865Sdilpreet 27391865Sdilpreet /* 27401865Sdilpreet * Release any resources allocated by pci_ereport_setup() 27411865Sdilpreet */ 27421865Sdilpreet if (DDI_FM_EREPORT_CAP(bgep->fm_capabilities) || 27431865Sdilpreet DDI_FM_ERRCB_CAP(bgep->fm_capabilities)) 27441865Sdilpreet pci_ereport_teardown(bgep->devinfo); 27451865Sdilpreet 27461865Sdilpreet /* 27471865Sdilpreet * Un-register error callback if error callback capable 27481865Sdilpreet */ 27491865Sdilpreet if (DDI_FM_ERRCB_CAP(bgep->fm_capabilities)) 27501865Sdilpreet ddi_fm_handler_unregister(bgep->devinfo); 27511865Sdilpreet 27521865Sdilpreet /* Unregister from IO Fault Services */ 27531865Sdilpreet ddi_fm_fini(bgep->devinfo); 27541865Sdilpreet } 27551865Sdilpreet } 27561865Sdilpreet 27571369Sdduvall static void 27581408Srandyf #ifdef BGE_IPMI_ASF 27591408Srandyf bge_unattach(bge_t *bgep, uint_t asf_mode) 27601408Srandyf #else 27611369Sdduvall bge_unattach(bge_t *bgep) 27621408Srandyf #endif 27631369Sdduvall { 27641369Sdduvall BGE_TRACE(("bge_unattach($%p)", 27651369Sdduvall (void *)bgep)); 27661369Sdduvall 27671369Sdduvall /* 27681369Sdduvall * Flag that no more activity may be initiated 27691369Sdduvall */ 27701369Sdduvall bgep->progress &= ~PROGRESS_READY; 27711369Sdduvall 27721369Sdduvall /* 27731369Sdduvall * Quiesce the PHY and MAC (leave it reset but still powered). 27741369Sdduvall * Clean up and free all BGE data structures 27751369Sdduvall */ 27765107Seota if (bgep->periodic_id != NULL) { 27775107Seota ddi_periodic_delete(bgep->periodic_id); 27785107Seota bgep->periodic_id = NULL; 27791369Sdduvall } 27801369Sdduvall if (bgep->progress & PROGRESS_KSTATS) 27811369Sdduvall bge_fini_kstats(bgep); 27821369Sdduvall if (bgep->progress & PROGRESS_NDD) 27831369Sdduvall bge_nd_cleanup(bgep); 27841369Sdduvall if (bgep->progress & PROGRESS_PHY) 27851369Sdduvall bge_phys_reset(bgep); 27861369Sdduvall if (bgep->progress & PROGRESS_HWINT) { 27871369Sdduvall mutex_enter(bgep->genlock); 27881408Srandyf #ifdef BGE_IPMI_ASF 27891865Sdilpreet if (bge_chip_reset(bgep, B_FALSE, asf_mode) != DDI_SUCCESS) 27901865Sdilpreet #else 27911865Sdilpreet if (bge_chip_reset(bgep, B_FALSE) != DDI_SUCCESS) 27921865Sdilpreet #endif 27931865Sdilpreet ddi_fm_service_impact(bgep->devinfo, 27941865Sdilpreet DDI_SERVICE_UNAFFECTED); 27951865Sdilpreet #ifdef BGE_IPMI_ASF 27961408Srandyf if (bgep->asf_enabled) { 27971408Srandyf /* 27981408Srandyf * This register has been overlaid. We restore its 27991408Srandyf * initial value here. 28001408Srandyf */ 28011408Srandyf bge_nic_put32(bgep, BGE_NIC_DATA_SIG_ADDR, 28021408Srandyf BGE_NIC_DATA_SIG); 28031408Srandyf } 28041408Srandyf #endif 28051865Sdilpreet if (bge_check_acc_handle(bgep, bgep->cfg_handle) != DDI_FM_OK) 28061865Sdilpreet ddi_fm_service_impact(bgep->devinfo, 28071865Sdilpreet DDI_SERVICE_UNAFFECTED); 28081865Sdilpreet if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) 28091865Sdilpreet ddi_fm_service_impact(bgep->devinfo, 28101865Sdilpreet DDI_SERVICE_UNAFFECTED); 28111369Sdduvall mutex_exit(bgep->genlock); 28121369Sdduvall } 28131369Sdduvall if (bgep->progress & PROGRESS_INTR) { 28141865Sdilpreet bge_intr_disable(bgep); 28151369Sdduvall bge_fini_rings(bgep); 28161369Sdduvall } 28171865Sdilpreet if (bgep->progress & PROGRESS_HWINT) { 28181865Sdilpreet bge_rem_intrs(bgep); 28191865Sdilpreet rw_destroy(bgep->errlock); 28201865Sdilpreet mutex_destroy(bgep->softintrlock); 28211865Sdilpreet mutex_destroy(bgep->genlock); 28221865Sdilpreet } 28231369Sdduvall if (bgep->progress & PROGRESS_FACTOTUM) 28241369Sdduvall ddi_remove_softintr(bgep->factotum_id); 28251369Sdduvall if (bgep->progress & PROGRESS_RESCHED) 28263334Sgs150176 ddi_remove_softintr(bgep->drain_id); 28271865Sdilpreet if (bgep->progress & PROGRESS_BUFS) 28281865Sdilpreet bge_free_bufs(bgep); 28291369Sdduvall if (bgep->progress & PROGRESS_REGS) 28301369Sdduvall ddi_regs_map_free(&bgep->io_handle); 28311369Sdduvall if (bgep->progress & PROGRESS_CFG) 28321369Sdduvall pci_config_teardown(&bgep->cfg_handle); 28331369Sdduvall 28341865Sdilpreet bge_fm_fini(bgep); 28351865Sdilpreet 28361369Sdduvall ddi_remove_minor_node(bgep->devinfo, NULL); 28373334Sgs150176 kmem_free(bgep->pstats, sizeof (bge_statistics_reg_t)); 28383334Sgs150176 kmem_free(bgep->nd_params, PARAM_COUNT * sizeof (nd_param_t)); 28391369Sdduvall kmem_free(bgep, sizeof (*bgep)); 28401369Sdduvall } 28411369Sdduvall 28421369Sdduvall static int 28431369Sdduvall bge_resume(dev_info_t *devinfo) 28441369Sdduvall { 28451369Sdduvall bge_t *bgep; /* Our private data */ 28461369Sdduvall chip_id_t *cidp; 28471369Sdduvall chip_id_t chipid; 28481369Sdduvall 28491369Sdduvall bgep = ddi_get_driver_private(devinfo); 28501369Sdduvall if (bgep == NULL) 28511369Sdduvall return (DDI_FAILURE); 28521369Sdduvall 28531369Sdduvall /* 28541369Sdduvall * Refuse to resume if the data structures aren't consistent 28551369Sdduvall */ 28561369Sdduvall if (bgep->devinfo != devinfo) 28571369Sdduvall return (DDI_FAILURE); 28581369Sdduvall 28591408Srandyf #ifdef BGE_IPMI_ASF 28601408Srandyf /* 28611408Srandyf * Power management hasn't been supported in BGE now. If you 28621408Srandyf * want to implement it, please add the ASF/IPMI related 28631408Srandyf * code here. 28641408Srandyf */ 28651408Srandyf 28661408Srandyf #endif 28671408Srandyf 28681369Sdduvall /* 28691369Sdduvall * Read chip ID & set up config space command register(s) 28701369Sdduvall * Refuse to resume if the chip has changed its identity! 28711369Sdduvall */ 28721369Sdduvall cidp = &bgep->chipid; 28731865Sdilpreet mutex_enter(bgep->genlock); 28741369Sdduvall bge_chip_cfg_init(bgep, &chipid, B_FALSE); 28751865Sdilpreet if (bge_check_acc_handle(bgep, bgep->cfg_handle) != DDI_FM_OK) { 28761865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_LOST); 28771865Sdilpreet mutex_exit(bgep->genlock); 28781865Sdilpreet return (DDI_FAILURE); 28791865Sdilpreet } 28801865Sdilpreet mutex_exit(bgep->genlock); 28811369Sdduvall if (chipid.vendor != cidp->vendor) 28821369Sdduvall return (DDI_FAILURE); 28831369Sdduvall if (chipid.device != cidp->device) 28841369Sdduvall return (DDI_FAILURE); 28851369Sdduvall if (chipid.revision != cidp->revision) 28861369Sdduvall return (DDI_FAILURE); 28871369Sdduvall if (chipid.asic_rev != cidp->asic_rev) 28881369Sdduvall return (DDI_FAILURE); 28891369Sdduvall 28901369Sdduvall /* 28911369Sdduvall * All OK, reinitialise h/w & kick off GLD scheduling 28921369Sdduvall */ 28931369Sdduvall mutex_enter(bgep->genlock); 28941865Sdilpreet if (bge_restart(bgep, B_TRUE) != DDI_SUCCESS) { 28951865Sdilpreet (void) bge_check_acc_handle(bgep, bgep->cfg_handle); 28961865Sdilpreet (void) bge_check_acc_handle(bgep, bgep->io_handle); 28971865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_LOST); 28981865Sdilpreet mutex_exit(bgep->genlock); 28991865Sdilpreet return (DDI_FAILURE); 29001865Sdilpreet } 29011865Sdilpreet if (bge_check_acc_handle(bgep, bgep->cfg_handle) != DDI_FM_OK) { 29021865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_LOST); 29031865Sdilpreet mutex_exit(bgep->genlock); 29041865Sdilpreet return (DDI_FAILURE); 29051865Sdilpreet } 29061865Sdilpreet if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) { 29071865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_LOST); 29081865Sdilpreet mutex_exit(bgep->genlock); 29091865Sdilpreet return (DDI_FAILURE); 29101865Sdilpreet } 29111369Sdduvall mutex_exit(bgep->genlock); 29121369Sdduvall return (DDI_SUCCESS); 29131369Sdduvall } 29141369Sdduvall 29151369Sdduvall /* 29161369Sdduvall * attach(9E) -- Attach a device to the system 29171369Sdduvall * 29181369Sdduvall * Called once for each board successfully probed. 29191369Sdduvall */ 29201369Sdduvall static int 29211369Sdduvall bge_attach(dev_info_t *devinfo, ddi_attach_cmd_t cmd) 29221369Sdduvall { 29231369Sdduvall bge_t *bgep; /* Our private data */ 29242311Sseb mac_register_t *macp; 29251369Sdduvall chip_id_t *cidp; 29261369Sdduvall caddr_t regs; 29271369Sdduvall int instance; 29281369Sdduvall int err; 29291369Sdduvall int intr_types; 29301408Srandyf #ifdef BGE_IPMI_ASF 29311408Srandyf uint32_t mhcrValue; 29323918Sml149210 #ifdef __sparc 29333918Sml149210 uint16_t value16; 29343918Sml149210 #endif 29353918Sml149210 #ifdef BGE_NETCONSOLE 29363918Sml149210 int retval; 29373918Sml149210 #endif 29381408Srandyf #endif 29391369Sdduvall 29401369Sdduvall instance = ddi_get_instance(devinfo); 29411369Sdduvall 29421369Sdduvall BGE_GTRACE(("bge_attach($%p, %d) instance %d", 29434588Sml149210 (void *)devinfo, cmd, instance)); 29441369Sdduvall BGE_BRKPT(NULL, "bge_attach"); 29451369Sdduvall 29461369Sdduvall switch (cmd) { 29471369Sdduvall default: 29481369Sdduvall return (DDI_FAILURE); 29491369Sdduvall 29501369Sdduvall case DDI_RESUME: 29511369Sdduvall return (bge_resume(devinfo)); 29521369Sdduvall 29531369Sdduvall case DDI_ATTACH: 29541369Sdduvall break; 29551369Sdduvall } 29561369Sdduvall 29571369Sdduvall bgep = kmem_zalloc(sizeof (*bgep), KM_SLEEP); 29583334Sgs150176 bgep->pstats = kmem_zalloc(sizeof (bge_statistics_reg_t), KM_SLEEP); 29593334Sgs150176 bgep->nd_params = 29603334Sgs150176 kmem_zalloc(PARAM_COUNT * sizeof (nd_param_t), KM_SLEEP); 29611369Sdduvall ddi_set_driver_private(devinfo, bgep); 29621369Sdduvall bgep->bge_guard = BGE_GUARD; 29631369Sdduvall bgep->devinfo = devinfo; 2964*5903Ssowmini bgep->param_drain_max = 64; 2965*5903Ssowmini bgep->param_msi_cnt = 0; 2966*5903Ssowmini bgep->param_loop_mode = 0; 29671369Sdduvall 29681369Sdduvall /* 29691369Sdduvall * Initialize more fields in BGE private data 29701369Sdduvall */ 29711369Sdduvall bgep->debug = ddi_prop_get_int(DDI_DEV_T_ANY, devinfo, 29724588Sml149210 DDI_PROP_DONTPASS, debug_propname, bge_debug); 29731369Sdduvall (void) snprintf(bgep->ifname, sizeof (bgep->ifname), "%s%d", 29744588Sml149210 BGE_DRIVER_NAME, instance); 29751369Sdduvall 29761369Sdduvall /* 29771865Sdilpreet * Initialize for fma support 29781865Sdilpreet */ 29791865Sdilpreet bgep->fm_capabilities = ddi_prop_get_int(DDI_DEV_T_ANY, devinfo, 29801865Sdilpreet DDI_PROP_DONTPASS, fm_cap, 29811865Sdilpreet DDI_FM_EREPORT_CAPABLE | DDI_FM_ACCCHK_CAPABLE | 29821865Sdilpreet DDI_FM_DMACHK_CAPABLE | DDI_FM_ERRCB_CAPABLE); 29831865Sdilpreet BGE_DEBUG(("bgep->fm_capabilities = %d", bgep->fm_capabilities)); 29841865Sdilpreet bge_fm_init(bgep); 29851865Sdilpreet 29861865Sdilpreet /* 29871369Sdduvall * Look up the IOMMU's page size for DVMA mappings (must be 29881369Sdduvall * a power of 2) and convert to a mask. This can be used to 29891369Sdduvall * determine whether a message buffer crosses a page boundary. 29901369Sdduvall * Note: in 2s complement binary notation, if X is a power of 29911369Sdduvall * 2, then -X has the representation "11...1100...00". 29921369Sdduvall */ 29931369Sdduvall bgep->pagemask = dvma_pagesize(devinfo); 29941369Sdduvall ASSERT(ddi_ffs(bgep->pagemask) == ddi_fls(bgep->pagemask)); 29951369Sdduvall bgep->pagemask = -bgep->pagemask; 29961369Sdduvall 29971369Sdduvall /* 29981369Sdduvall * Map config space registers 29991369Sdduvall * Read chip ID & set up config space command register(s) 30001369Sdduvall * 30011369Sdduvall * Note: this leaves the chip accessible by Memory Space 30021369Sdduvall * accesses, but with interrupts and Bus Mastering off. 30031369Sdduvall * This should ensure that nothing untoward will happen 30041369Sdduvall * if it has been left active by the (net-)bootloader. 30051369Sdduvall * We'll re-enable Bus Mastering once we've reset the chip, 30061369Sdduvall * and allow interrupts only when everything else is set up. 30071369Sdduvall */ 30081369Sdduvall err = pci_config_setup(devinfo, &bgep->cfg_handle); 30091408Srandyf #ifdef BGE_IPMI_ASF 30103918Sml149210 #ifdef __sparc 30113918Sml149210 value16 = pci_config_get16(bgep->cfg_handle, PCI_CONF_COMM); 30123918Sml149210 value16 = value16 | (PCI_COMM_MAE | PCI_COMM_ME); 30133918Sml149210 pci_config_put16(bgep->cfg_handle, PCI_CONF_COMM, value16); 30143918Sml149210 mhcrValue = MHCR_ENABLE_INDIRECT_ACCESS | 30154588Sml149210 MHCR_ENABLE_TAGGED_STATUS_MODE | 30164588Sml149210 MHCR_MASK_INTERRUPT_MODE | 30174588Sml149210 MHCR_MASK_PCI_INT_OUTPUT | 30184588Sml149210 MHCR_CLEAR_INTERRUPT_INTA | 30194588Sml149210 MHCR_ENABLE_ENDIAN_WORD_SWAP | 30204588Sml149210 MHCR_ENABLE_ENDIAN_BYTE_SWAP; 30213918Sml149210 pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_MHCR, mhcrValue); 30223918Sml149210 bge_ind_put32(bgep, MEMORY_ARBITER_MODE_REG, 30234588Sml149210 bge_ind_get32(bgep, MEMORY_ARBITER_MODE_REG) | 30244588Sml149210 MEMORY_ARBITER_ENABLE); 30253918Sml149210 #else 30261408Srandyf mhcrValue = pci_config_get32(bgep->cfg_handle, PCI_CONF_BGE_MHCR); 30273918Sml149210 #endif 30281408Srandyf if (mhcrValue & MHCR_ENABLE_ENDIAN_WORD_SWAP) { 30291408Srandyf bgep->asf_wordswapped = B_TRUE; 30301408Srandyf } else { 30311408Srandyf bgep->asf_wordswapped = B_FALSE; 30321408Srandyf } 30331408Srandyf bge_asf_get_config(bgep); 30341408Srandyf #endif 30351369Sdduvall if (err != DDI_SUCCESS) { 30361369Sdduvall bge_problem(bgep, "pci_config_setup() failed"); 30371369Sdduvall goto attach_fail; 30381369Sdduvall } 30391369Sdduvall bgep->progress |= PROGRESS_CFG; 30401369Sdduvall cidp = &bgep->chipid; 30411369Sdduvall bzero(cidp, sizeof (*cidp)); 30421369Sdduvall bge_chip_cfg_init(bgep, cidp, B_FALSE); 30431865Sdilpreet if (bge_check_acc_handle(bgep, bgep->cfg_handle) != DDI_FM_OK) { 30441865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_LOST); 30451865Sdilpreet goto attach_fail; 30461865Sdilpreet } 30471369Sdduvall 30481408Srandyf #ifdef BGE_IPMI_ASF 30491408Srandyf if (DEVICE_5721_SERIES_CHIPSETS(bgep) || 30501408Srandyf DEVICE_5714_SERIES_CHIPSETS(bgep)) { 30511408Srandyf bgep->asf_newhandshake = B_TRUE; 30521408Srandyf } else { 30531408Srandyf bgep->asf_newhandshake = B_FALSE; 30541408Srandyf } 30551408Srandyf #endif 30561408Srandyf 30571369Sdduvall /* 30581369Sdduvall * Update those parts of the chip ID derived from volatile 30591369Sdduvall * registers with the values seen by OBP (in case the chip 30601369Sdduvall * has been reset externally and therefore lost them). 30611369Sdduvall */ 30621369Sdduvall cidp->subven = ddi_prop_get_int(DDI_DEV_T_ANY, devinfo, 30634588Sml149210 DDI_PROP_DONTPASS, subven_propname, cidp->subven); 30641369Sdduvall cidp->subdev = ddi_prop_get_int(DDI_DEV_T_ANY, devinfo, 30654588Sml149210 DDI_PROP_DONTPASS, subdev_propname, cidp->subdev); 30661369Sdduvall cidp->clsize = ddi_prop_get_int(DDI_DEV_T_ANY, devinfo, 30674588Sml149210 DDI_PROP_DONTPASS, clsize_propname, cidp->clsize); 30681369Sdduvall cidp->latency = ddi_prop_get_int(DDI_DEV_T_ANY, devinfo, 30694588Sml149210 DDI_PROP_DONTPASS, latency_propname, cidp->latency); 30701369Sdduvall cidp->rx_rings = ddi_prop_get_int(DDI_DEV_T_ANY, devinfo, 30714588Sml149210 DDI_PROP_DONTPASS, rxrings_propname, cidp->rx_rings); 30721369Sdduvall cidp->tx_rings = ddi_prop_get_int(DDI_DEV_T_ANY, devinfo, 30734588Sml149210 DDI_PROP_DONTPASS, txrings_propname, cidp->tx_rings); 30741369Sdduvall 30751369Sdduvall if (bge_jumbo_enable == B_TRUE) { 30761369Sdduvall cidp->default_mtu = ddi_prop_get_int(DDI_DEV_T_ANY, devinfo, 30774588Sml149210 DDI_PROP_DONTPASS, default_mtu, BGE_DEFAULT_MTU); 30781369Sdduvall if ((cidp->default_mtu < BGE_DEFAULT_MTU)|| 30794588Sml149210 (cidp->default_mtu > BGE_MAXIMUM_MTU)) { 30801369Sdduvall cidp->default_mtu = BGE_DEFAULT_MTU; 30811369Sdduvall } 30821369Sdduvall } 30831369Sdduvall /* 30841369Sdduvall * Map operating registers 30851369Sdduvall */ 30861369Sdduvall err = ddi_regs_map_setup(devinfo, BGE_PCI_OPREGS_RNUMBER, 30874588Sml149210 ®s, 0, 0, &bge_reg_accattr, &bgep->io_handle); 30881369Sdduvall if (err != DDI_SUCCESS) { 30891369Sdduvall bge_problem(bgep, "ddi_regs_map_setup() failed"); 30901369Sdduvall goto attach_fail; 30911369Sdduvall } 30921369Sdduvall bgep->io_regs = regs; 30931369Sdduvall bgep->progress |= PROGRESS_REGS; 30941369Sdduvall 30951369Sdduvall /* 30961369Sdduvall * Characterise the device, so we know its requirements. 30971369Sdduvall * Then allocate the appropriate TX and RX descriptors & buffers. 30981369Sdduvall */ 30991865Sdilpreet if (bge_chip_id_init(bgep) == EIO) { 31001865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_LOST); 31011865Sdilpreet goto attach_fail; 31021865Sdilpreet } 31031369Sdduvall err = bge_alloc_bufs(bgep); 31041369Sdduvall if (err != DDI_SUCCESS) { 31051369Sdduvall bge_problem(bgep, "DMA buffer allocation failed"); 31061369Sdduvall goto attach_fail; 31071369Sdduvall } 31081865Sdilpreet bgep->progress |= PROGRESS_BUFS; 31091369Sdduvall 31101369Sdduvall /* 31111369Sdduvall * Add the softint handlers: 31121369Sdduvall * 31131369Sdduvall * Both of these handlers are used to avoid restrictions on the 31141369Sdduvall * context and/or mutexes required for some operations. In 31151369Sdduvall * particular, the hardware interrupt handler and its subfunctions 31161369Sdduvall * can detect a number of conditions that we don't want to handle 31171369Sdduvall * in that context or with that set of mutexes held. So, these 31181369Sdduvall * softints are triggered instead: 31191369Sdduvall * 31202135Szh199473 * the <resched> softint is triggered if we have previously 31211369Sdduvall * had to refuse to send a packet because of resource shortage 31221369Sdduvall * (we've run out of transmit buffers), but the send completion 31231369Sdduvall * interrupt handler has now detected that more buffers have 31241369Sdduvall * become available. 31251369Sdduvall * 31261369Sdduvall * the <factotum> is triggered if the h/w interrupt handler 31271369Sdduvall * sees the <link state changed> or <error> bits in the status 31281369Sdduvall * block. It's also triggered periodically to poll the link 31291369Sdduvall * state, just in case we aren't getting link status change 31301369Sdduvall * interrupts ... 31311369Sdduvall */ 31323334Sgs150176 err = ddi_add_softintr(devinfo, DDI_SOFTINT_LOW, &bgep->drain_id, 31334588Sml149210 NULL, NULL, bge_send_drain, (caddr_t)bgep); 31341369Sdduvall if (err != DDI_SUCCESS) { 31351369Sdduvall bge_problem(bgep, "ddi_add_softintr() failed"); 31361369Sdduvall goto attach_fail; 31371369Sdduvall } 31381369Sdduvall bgep->progress |= PROGRESS_RESCHED; 31391369Sdduvall err = ddi_add_softintr(devinfo, DDI_SOFTINT_LOW, &bgep->factotum_id, 31404588Sml149210 NULL, NULL, bge_chip_factotum, (caddr_t)bgep); 31411369Sdduvall if (err != DDI_SUCCESS) { 31421369Sdduvall bge_problem(bgep, "ddi_add_softintr() failed"); 31431369Sdduvall goto attach_fail; 31441369Sdduvall } 31451369Sdduvall bgep->progress |= PROGRESS_FACTOTUM; 31461369Sdduvall 31471369Sdduvall /* Get supported interrupt types */ 31481369Sdduvall if (ddi_intr_get_supported_types(devinfo, &intr_types) != DDI_SUCCESS) { 31491369Sdduvall bge_error(bgep, "ddi_intr_get_supported_types failed\n"); 31501369Sdduvall 31511369Sdduvall goto attach_fail; 31521369Sdduvall } 31531369Sdduvall 31542675Szh199473 BGE_DEBUG(("%s: ddi_intr_get_supported_types() returned: %x", 31554588Sml149210 bgep->ifname, intr_types)); 31561369Sdduvall 31571369Sdduvall if ((intr_types & DDI_INTR_TYPE_MSI) && bgep->chipid.msi_enabled) { 31581369Sdduvall if (bge_add_intrs(bgep, DDI_INTR_TYPE_MSI) != DDI_SUCCESS) { 31591369Sdduvall bge_error(bgep, "MSI registration failed, " 31601369Sdduvall "trying FIXED interrupt type\n"); 31611369Sdduvall } else { 31622675Szh199473 BGE_DEBUG(("%s: Using MSI interrupt type", 31634588Sml149210 bgep->ifname)); 31641369Sdduvall bgep->intr_type = DDI_INTR_TYPE_MSI; 31651865Sdilpreet bgep->progress |= PROGRESS_HWINT; 31661369Sdduvall } 31671369Sdduvall } 31681369Sdduvall 31691865Sdilpreet if (!(bgep->progress & PROGRESS_HWINT) && 31701369Sdduvall (intr_types & DDI_INTR_TYPE_FIXED)) { 31711369Sdduvall if (bge_add_intrs(bgep, DDI_INTR_TYPE_FIXED) != DDI_SUCCESS) { 31721369Sdduvall bge_error(bgep, "FIXED interrupt " 31731369Sdduvall "registration failed\n"); 31741369Sdduvall goto attach_fail; 31751369Sdduvall } 31761369Sdduvall 31772675Szh199473 BGE_DEBUG(("%s: Using FIXED interrupt type", bgep->ifname)); 31781369Sdduvall 31791369Sdduvall bgep->intr_type = DDI_INTR_TYPE_FIXED; 31801865Sdilpreet bgep->progress |= PROGRESS_HWINT; 31811369Sdduvall } 31821369Sdduvall 31831865Sdilpreet if (!(bgep->progress & PROGRESS_HWINT)) { 31841369Sdduvall bge_error(bgep, "No interrupts registered\n"); 31851369Sdduvall goto attach_fail; 31861369Sdduvall } 31871369Sdduvall 31881369Sdduvall /* 31891369Sdduvall * Note that interrupts are not enabled yet as 31901865Sdilpreet * mutex locks are not initialized. Initialize mutex locks. 31911865Sdilpreet */ 31921865Sdilpreet mutex_init(bgep->genlock, NULL, MUTEX_DRIVER, 31931865Sdilpreet DDI_INTR_PRI(bgep->intr_pri)); 31941865Sdilpreet mutex_init(bgep->softintrlock, NULL, MUTEX_DRIVER, 31951865Sdilpreet DDI_INTR_PRI(bgep->intr_pri)); 31961865Sdilpreet rw_init(bgep->errlock, NULL, RW_DRIVER, 31971865Sdilpreet DDI_INTR_PRI(bgep->intr_pri)); 31981865Sdilpreet 31991865Sdilpreet /* 32001865Sdilpreet * Initialize rings. 32011369Sdduvall */ 32021369Sdduvall bge_init_rings(bgep); 32031369Sdduvall 32041369Sdduvall /* 32051369Sdduvall * Now that mutex locks are initialized, enable interrupts. 32061369Sdduvall */ 32071865Sdilpreet bge_intr_enable(bgep); 32081865Sdilpreet bgep->progress |= PROGRESS_INTR; 32091369Sdduvall 32101369Sdduvall /* 32111369Sdduvall * Initialise link state variables 32121369Sdduvall * Stop, reset & reinitialise the chip. 32131369Sdduvall * Initialise the (internal) PHY. 32141369Sdduvall */ 32151369Sdduvall bgep->link_state = LINK_STATE_UNKNOWN; 32161369Sdduvall 32171369Sdduvall mutex_enter(bgep->genlock); 32181369Sdduvall 32191369Sdduvall /* 32201369Sdduvall * Reset chip & rings to initial state; also reset address 32211369Sdduvall * filtering, promiscuity, loopback mode. 32221369Sdduvall */ 32231408Srandyf #ifdef BGE_IPMI_ASF 32243918Sml149210 #ifdef BGE_NETCONSOLE 32253918Sml149210 if (bge_reset(bgep, ASF_MODE_INIT) != DDI_SUCCESS) { 32263918Sml149210 #else 32271865Sdilpreet if (bge_reset(bgep, ASF_MODE_SHUTDOWN) != DDI_SUCCESS) { 32283918Sml149210 #endif 32291408Srandyf #else 32301865Sdilpreet if (bge_reset(bgep) != DDI_SUCCESS) { 32311408Srandyf #endif 32321865Sdilpreet (void) bge_check_acc_handle(bgep, bgep->cfg_handle); 32331865Sdilpreet (void) bge_check_acc_handle(bgep, bgep->io_handle); 32341865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_LOST); 32351865Sdilpreet mutex_exit(bgep->genlock); 32361865Sdilpreet goto attach_fail; 32371865Sdilpreet } 32381369Sdduvall 32392675Szh199473 #ifdef BGE_IPMI_ASF 32402675Szh199473 if (bgep->asf_enabled) { 32412675Szh199473 bgep->asf_status = ASF_STAT_RUN_INIT; 32422675Szh199473 } 32432675Szh199473 #endif 32442675Szh199473 32451369Sdduvall bzero(bgep->mcast_hash, sizeof (bgep->mcast_hash)); 32461369Sdduvall bzero(bgep->mcast_refs, sizeof (bgep->mcast_refs)); 32471369Sdduvall bgep->promisc = B_FALSE; 32481369Sdduvall bgep->param_loop_mode = BGE_LOOP_NONE; 32491865Sdilpreet if (bge_check_acc_handle(bgep, bgep->cfg_handle) != DDI_FM_OK) { 32501865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_LOST); 32511865Sdilpreet mutex_exit(bgep->genlock); 32521865Sdilpreet goto attach_fail; 32531865Sdilpreet } 32541865Sdilpreet if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) { 32551865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_LOST); 32561865Sdilpreet mutex_exit(bgep->genlock); 32571865Sdilpreet goto attach_fail; 32581865Sdilpreet } 32591369Sdduvall 32601369Sdduvall mutex_exit(bgep->genlock); 32611369Sdduvall 32621865Sdilpreet if (bge_phys_init(bgep) == EIO) { 32631865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_LOST); 32641865Sdilpreet goto attach_fail; 32651865Sdilpreet } 32661369Sdduvall bgep->progress |= PROGRESS_PHY; 32671369Sdduvall 32681369Sdduvall /* 32691369Sdduvall * Register NDD-tweakable parameters 32701369Sdduvall */ 32711369Sdduvall if (bge_nd_init(bgep)) { 32721369Sdduvall bge_problem(bgep, "bge_nd_init() failed"); 32731369Sdduvall goto attach_fail; 32741369Sdduvall } 32751369Sdduvall bgep->progress |= PROGRESS_NDD; 32761369Sdduvall 32771369Sdduvall /* 32781369Sdduvall * Create & initialise named kstats 32791369Sdduvall */ 32801369Sdduvall bge_init_kstats(bgep, instance); 32811369Sdduvall bgep->progress |= PROGRESS_KSTATS; 32821369Sdduvall 32831369Sdduvall /* 32841369Sdduvall * Determine whether to override the chip's own MAC address 32851369Sdduvall */ 32861369Sdduvall bge_find_mac_address(bgep, cidp); 32872331Skrgopi ethaddr_copy(cidp->vendor_addr.addr, bgep->curr_addr[0].addr); 32882331Skrgopi bgep->curr_addr[0].set = B_TRUE; 32892331Skrgopi 32902406Skrgopi bgep->unicst_addr_total = MAC_ADDRESS_REGS_MAX; 32912406Skrgopi /* 32922406Skrgopi * Address available is one less than MAX 32932406Skrgopi * as primary address is not advertised 32942406Skrgopi * as a multiple MAC address. 32952406Skrgopi */ 32962331Skrgopi bgep->unicst_addr_avail = MAC_ADDRESS_REGS_MAX - 1; 32971369Sdduvall 32982311Sseb if ((macp = mac_alloc(MAC_VERSION)) == NULL) 32992311Sseb goto attach_fail; 33002311Sseb macp->m_type_ident = MAC_PLUGIN_IDENT_ETHER; 33012311Sseb macp->m_driver = bgep; 33021369Sdduvall macp->m_dip = devinfo; 33032331Skrgopi macp->m_src_addr = bgep->curr_addr[0].addr; 33042311Sseb macp->m_callbacks = &bge_m_callbacks; 33052311Sseb macp->m_min_sdu = 0; 33062311Sseb macp->m_max_sdu = cidp->ethmax_size - sizeof (struct ether_header); 33075895Syz147064 macp->m_margin = VLAN_TAGSZ; 33081369Sdduvall /* 33091369Sdduvall * Finally, we're ready to register ourselves with the MAC layer 33101369Sdduvall * interface; if this succeeds, we're all ready to start() 33111369Sdduvall */ 33122311Sseb err = mac_register(macp, &bgep->mh); 33132311Sseb mac_free(macp); 33142311Sseb if (err != 0) 33151369Sdduvall goto attach_fail; 33161369Sdduvall 33175107Seota /* 33185107Seota * Register a periodical handler. 33195107Seota * bge_chip_cyclic() is invoked in kernel context. 33205107Seota */ 33215107Seota bgep->periodic_id = ddi_periodic_add(bge_chip_cyclic, bgep, 33225107Seota BGE_CYCLIC_PERIOD, DDI_IPL_0); 33231369Sdduvall 33241369Sdduvall bgep->progress |= PROGRESS_READY; 33251369Sdduvall ASSERT(bgep->bge_guard == BGE_GUARD); 33263918Sml149210 #ifdef BGE_IPMI_ASF 33273918Sml149210 #ifdef BGE_NETCONSOLE 33283918Sml149210 if (bgep->asf_enabled) { 33293918Sml149210 mutex_enter(bgep->genlock); 33303918Sml149210 retval = bge_chip_start(bgep, B_TRUE); 33313918Sml149210 mutex_exit(bgep->genlock); 33323918Sml149210 if (retval != DDI_SUCCESS) 33333918Sml149210 goto attach_fail; 33343918Sml149210 } 33353918Sml149210 #endif 33363918Sml149210 #endif 33371369Sdduvall return (DDI_SUCCESS); 33381369Sdduvall 33391369Sdduvall attach_fail: 33401408Srandyf #ifdef BGE_IPMI_ASF 33412675Szh199473 bge_unattach(bgep, ASF_MODE_SHUTDOWN); 33421408Srandyf #else 33431369Sdduvall bge_unattach(bgep); 33441408Srandyf #endif 33451369Sdduvall return (DDI_FAILURE); 33461369Sdduvall } 33471369Sdduvall 33481369Sdduvall /* 33491369Sdduvall * bge_suspend() -- suspend transmit/receive for powerdown 33501369Sdduvall */ 33511369Sdduvall static int 33521369Sdduvall bge_suspend(bge_t *bgep) 33531369Sdduvall { 33541369Sdduvall /* 33551369Sdduvall * Stop processing and idle (powerdown) the PHY ... 33561369Sdduvall */ 33571369Sdduvall mutex_enter(bgep->genlock); 33581408Srandyf #ifdef BGE_IPMI_ASF 33591408Srandyf /* 33601408Srandyf * Power management hasn't been supported in BGE now. If you 33611408Srandyf * want to implement it, please add the ASF/IPMI related 33621408Srandyf * code here. 33631408Srandyf */ 33641408Srandyf #endif 33651369Sdduvall bge_stop(bgep); 33661865Sdilpreet if (bge_phys_idle(bgep) != DDI_SUCCESS) { 33671865Sdilpreet (void) bge_check_acc_handle(bgep, bgep->io_handle); 33681865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_DEGRADED); 33691865Sdilpreet mutex_exit(bgep->genlock); 33701865Sdilpreet return (DDI_FAILURE); 33711865Sdilpreet } 33721865Sdilpreet if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) { 33731865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_DEGRADED); 33741865Sdilpreet mutex_exit(bgep->genlock); 33751865Sdilpreet return (DDI_FAILURE); 33761865Sdilpreet } 33771369Sdduvall mutex_exit(bgep->genlock); 33781369Sdduvall 33791369Sdduvall return (DDI_SUCCESS); 33801369Sdduvall } 33811369Sdduvall 33821369Sdduvall /* 33831369Sdduvall * detach(9E) -- Detach a device from the system 33841369Sdduvall */ 33851369Sdduvall static int 33861369Sdduvall bge_detach(dev_info_t *devinfo, ddi_detach_cmd_t cmd) 33871369Sdduvall { 33881369Sdduvall bge_t *bgep; 33891408Srandyf #ifdef BGE_IPMI_ASF 33901408Srandyf uint_t asf_mode; 33911408Srandyf asf_mode = ASF_MODE_NONE; 33921408Srandyf #endif 33931369Sdduvall 33941369Sdduvall BGE_GTRACE(("bge_detach($%p, %d)", (void *)devinfo, cmd)); 33951369Sdduvall 33961369Sdduvall bgep = ddi_get_driver_private(devinfo); 33971369Sdduvall 33981369Sdduvall switch (cmd) { 33991369Sdduvall default: 34001369Sdduvall return (DDI_FAILURE); 34011369Sdduvall 34021369Sdduvall case DDI_SUSPEND: 34031369Sdduvall return (bge_suspend(bgep)); 34041369Sdduvall 34051369Sdduvall case DDI_DETACH: 34061369Sdduvall break; 34071369Sdduvall } 34081369Sdduvall 34091408Srandyf #ifdef BGE_IPMI_ASF 34101408Srandyf mutex_enter(bgep->genlock); 34112675Szh199473 if (bgep->asf_enabled && ((bgep->asf_status == ASF_STAT_RUN) || 34124588Sml149210 (bgep->asf_status == ASF_STAT_RUN_INIT))) { 34131408Srandyf 34141408Srandyf bge_asf_update_status(bgep); 34152675Szh199473 if (bgep->asf_status == ASF_STAT_RUN) { 34162675Szh199473 bge_asf_stop_timer(bgep); 34172675Szh199473 } 34181408Srandyf bgep->asf_status = ASF_STAT_STOP; 34191408Srandyf 34201408Srandyf bge_asf_pre_reset_operations(bgep, BGE_SHUTDOWN_RESET); 34211408Srandyf 34221408Srandyf if (bgep->asf_pseudostop) { 34231408Srandyf bge_chip_stop(bgep, B_FALSE); 34241408Srandyf bgep->bge_mac_state = BGE_MAC_STOPPED; 34251408Srandyf bgep->asf_pseudostop = B_FALSE; 34261408Srandyf } 34271408Srandyf 34281408Srandyf asf_mode = ASF_MODE_POST_SHUTDOWN; 34291865Sdilpreet 34301865Sdilpreet if (bge_check_acc_handle(bgep, bgep->cfg_handle) != DDI_FM_OK) 34311865Sdilpreet ddi_fm_service_impact(bgep->devinfo, 34321865Sdilpreet DDI_SERVICE_UNAFFECTED); 34331865Sdilpreet if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) 34341865Sdilpreet ddi_fm_service_impact(bgep->devinfo, 34351865Sdilpreet DDI_SERVICE_UNAFFECTED); 34361408Srandyf } 34371408Srandyf mutex_exit(bgep->genlock); 34381408Srandyf #endif 34391408Srandyf 34401369Sdduvall /* 34411369Sdduvall * Unregister from the GLD subsystem. This can fail, in 34421369Sdduvall * particular if there are DLPI style-2 streams still open - 34431369Sdduvall * in which case we just return failure without shutting 34441369Sdduvall * down chip operations. 34451369Sdduvall */ 34462311Sseb if (mac_unregister(bgep->mh) != 0) 34471369Sdduvall return (DDI_FAILURE); 34481369Sdduvall 34491369Sdduvall /* 34501369Sdduvall * All activity stopped, so we can clean up & exit 34511369Sdduvall */ 34521408Srandyf #ifdef BGE_IPMI_ASF 34531408Srandyf bge_unattach(bgep, asf_mode); 34541408Srandyf #else 34551369Sdduvall bge_unattach(bgep); 34561408Srandyf #endif 34571369Sdduvall return (DDI_SUCCESS); 34581369Sdduvall } 34591369Sdduvall 34601369Sdduvall 34611369Sdduvall /* 34621369Sdduvall * ========== Module Loading Data & Entry Points ========== 34631369Sdduvall */ 34641369Sdduvall 34651369Sdduvall #undef BGE_DBG 34661369Sdduvall #define BGE_DBG BGE_DBG_INIT /* debug flag for this code */ 34671369Sdduvall 34681369Sdduvall DDI_DEFINE_STREAM_OPS(bge_dev_ops, nulldev, nulldev, bge_attach, bge_detach, 34691369Sdduvall nodev, NULL, D_MP, NULL); 34701369Sdduvall 34711369Sdduvall static struct modldrv bge_modldrv = { 34721369Sdduvall &mod_driverops, /* Type of module. This one is a driver */ 34731369Sdduvall bge_ident, /* short description */ 34741369Sdduvall &bge_dev_ops /* driver specific ops */ 34751369Sdduvall }; 34761369Sdduvall 34771369Sdduvall static struct modlinkage modlinkage = { 34781369Sdduvall MODREV_1, (void *)&bge_modldrv, NULL 34791369Sdduvall }; 34801369Sdduvall 34811369Sdduvall 34821369Sdduvall int 34831369Sdduvall _info(struct modinfo *modinfop) 34841369Sdduvall { 34851369Sdduvall return (mod_info(&modlinkage, modinfop)); 34861369Sdduvall } 34871369Sdduvall 34881369Sdduvall int 34891369Sdduvall _init(void) 34901369Sdduvall { 34911369Sdduvall int status; 34921369Sdduvall 34931369Sdduvall mac_init_ops(&bge_dev_ops, "bge"); 34941369Sdduvall status = mod_install(&modlinkage); 34951369Sdduvall if (status == DDI_SUCCESS) 34961369Sdduvall mutex_init(bge_log_mutex, NULL, MUTEX_DRIVER, NULL); 34971369Sdduvall else 34981369Sdduvall mac_fini_ops(&bge_dev_ops); 34991369Sdduvall return (status); 35001369Sdduvall } 35011369Sdduvall 35021369Sdduvall int 35031369Sdduvall _fini(void) 35041369Sdduvall { 35051369Sdduvall int status; 35061369Sdduvall 35071369Sdduvall status = mod_remove(&modlinkage); 35081369Sdduvall if (status == DDI_SUCCESS) { 35091369Sdduvall mac_fini_ops(&bge_dev_ops); 35101369Sdduvall mutex_destroy(bge_log_mutex); 35111369Sdduvall } 35121369Sdduvall return (status); 35131369Sdduvall } 35141369Sdduvall 35151369Sdduvall 35161369Sdduvall /* 35171369Sdduvall * bge_add_intrs: 35181369Sdduvall * 35191369Sdduvall * Register FIXED or MSI interrupts. 35201369Sdduvall */ 35211369Sdduvall static int 35221369Sdduvall bge_add_intrs(bge_t *bgep, int intr_type) 35231369Sdduvall { 35241369Sdduvall dev_info_t *dip = bgep->devinfo; 35251369Sdduvall int avail, actual, intr_size, count = 0; 35261369Sdduvall int i, flag, ret; 35271369Sdduvall 35282675Szh199473 BGE_DEBUG(("bge_add_intrs($%p, 0x%x)", (void *)bgep, intr_type)); 35291369Sdduvall 35301369Sdduvall /* Get number of interrupts */ 35311369Sdduvall ret = ddi_intr_get_nintrs(dip, intr_type, &count); 35321369Sdduvall if ((ret != DDI_SUCCESS) || (count == 0)) { 35331369Sdduvall bge_error(bgep, "ddi_intr_get_nintrs() failure, ret: %d, " 35341369Sdduvall "count: %d", ret, count); 35351369Sdduvall 35361369Sdduvall return (DDI_FAILURE); 35371369Sdduvall } 35381369Sdduvall 35391369Sdduvall /* Get number of available interrupts */ 35401369Sdduvall ret = ddi_intr_get_navail(dip, intr_type, &avail); 35411369Sdduvall if ((ret != DDI_SUCCESS) || (avail == 0)) { 35421369Sdduvall bge_error(bgep, "ddi_intr_get_navail() failure, " 35431369Sdduvall "ret: %d, avail: %d\n", ret, avail); 35441369Sdduvall 35451369Sdduvall return (DDI_FAILURE); 35461369Sdduvall } 35471369Sdduvall 35481369Sdduvall if (avail < count) { 35492675Szh199473 BGE_DEBUG(("%s: nintrs() returned %d, navail returned %d", 35502675Szh199473 bgep->ifname, count, avail)); 35511369Sdduvall } 35521369Sdduvall 35531369Sdduvall /* 35541369Sdduvall * BGE hardware generates only single MSI even though it claims 35551369Sdduvall * to support multiple MSIs. So, hard code MSI count value to 1. 35561369Sdduvall */ 35571369Sdduvall if (intr_type == DDI_INTR_TYPE_MSI) { 35581369Sdduvall count = 1; 35591369Sdduvall flag = DDI_INTR_ALLOC_STRICT; 35601369Sdduvall } else { 35611369Sdduvall flag = DDI_INTR_ALLOC_NORMAL; 35621369Sdduvall } 35631369Sdduvall 35641369Sdduvall /* Allocate an array of interrupt handles */ 35651369Sdduvall intr_size = count * sizeof (ddi_intr_handle_t); 35661369Sdduvall bgep->htable = kmem_alloc(intr_size, KM_SLEEP); 35671369Sdduvall 35681369Sdduvall /* Call ddi_intr_alloc() */ 35691369Sdduvall ret = ddi_intr_alloc(dip, bgep->htable, intr_type, 0, 35701369Sdduvall count, &actual, flag); 35711369Sdduvall 35721369Sdduvall if ((ret != DDI_SUCCESS) || (actual == 0)) { 35731369Sdduvall bge_error(bgep, "ddi_intr_alloc() failed %d\n", ret); 35741369Sdduvall 35751369Sdduvall kmem_free(bgep->htable, intr_size); 35761369Sdduvall return (DDI_FAILURE); 35771369Sdduvall } 35781369Sdduvall 35791369Sdduvall if (actual < count) { 35802675Szh199473 BGE_DEBUG(("%s: Requested: %d, Received: %d", 35814588Sml149210 bgep->ifname, count, actual)); 35821369Sdduvall } 35831369Sdduvall 35841369Sdduvall bgep->intr_cnt = actual; 35851369Sdduvall 35861369Sdduvall /* 35871369Sdduvall * Get priority for first msi, assume remaining are all the same 35881369Sdduvall */ 35891369Sdduvall if ((ret = ddi_intr_get_pri(bgep->htable[0], &bgep->intr_pri)) != 35901369Sdduvall DDI_SUCCESS) { 35911369Sdduvall bge_error(bgep, "ddi_intr_get_pri() failed %d\n", ret); 35921369Sdduvall 35931369Sdduvall /* Free already allocated intr */ 35941369Sdduvall for (i = 0; i < actual; i++) { 35951369Sdduvall (void) ddi_intr_free(bgep->htable[i]); 35961369Sdduvall } 35971369Sdduvall 35981369Sdduvall kmem_free(bgep->htable, intr_size); 35991369Sdduvall return (DDI_FAILURE); 36001369Sdduvall } 36011369Sdduvall 36021369Sdduvall /* Call ddi_intr_add_handler() */ 36031369Sdduvall for (i = 0; i < actual; i++) { 36041369Sdduvall if ((ret = ddi_intr_add_handler(bgep->htable[i], bge_intr, 36051369Sdduvall (caddr_t)bgep, (caddr_t)(uintptr_t)i)) != DDI_SUCCESS) { 36061369Sdduvall bge_error(bgep, "ddi_intr_add_handler() " 36071369Sdduvall "failed %d\n", ret); 36081369Sdduvall 36091369Sdduvall /* Free already allocated intr */ 36101369Sdduvall for (i = 0; i < actual; i++) { 36111369Sdduvall (void) ddi_intr_free(bgep->htable[i]); 36121369Sdduvall } 36131369Sdduvall 36141369Sdduvall kmem_free(bgep->htable, intr_size); 36151369Sdduvall return (DDI_FAILURE); 36161369Sdduvall } 36171369Sdduvall } 36181369Sdduvall 36191369Sdduvall if ((ret = ddi_intr_get_cap(bgep->htable[0], &bgep->intr_cap)) 36204588Sml149210 != DDI_SUCCESS) { 36211369Sdduvall bge_error(bgep, "ddi_intr_get_cap() failed %d\n", ret); 36221369Sdduvall 36231369Sdduvall for (i = 0; i < actual; i++) { 36241369Sdduvall (void) ddi_intr_remove_handler(bgep->htable[i]); 36251369Sdduvall (void) ddi_intr_free(bgep->htable[i]); 36261369Sdduvall } 36271369Sdduvall 36281369Sdduvall kmem_free(bgep->htable, intr_size); 36291369Sdduvall return (DDI_FAILURE); 36301369Sdduvall } 36311369Sdduvall 36321369Sdduvall return (DDI_SUCCESS); 36331369Sdduvall } 36341369Sdduvall 36351369Sdduvall /* 36361369Sdduvall * bge_rem_intrs: 36371369Sdduvall * 36381369Sdduvall * Unregister FIXED or MSI interrupts 36391369Sdduvall */ 36401369Sdduvall static void 36411369Sdduvall bge_rem_intrs(bge_t *bgep) 36421369Sdduvall { 36431369Sdduvall int i; 36441369Sdduvall 36452675Szh199473 BGE_DEBUG(("bge_rem_intrs($%p)", (void *)bgep)); 36461369Sdduvall 36471865Sdilpreet /* Call ddi_intr_remove_handler() */ 36481865Sdilpreet for (i = 0; i < bgep->intr_cnt; i++) { 36491865Sdilpreet (void) ddi_intr_remove_handler(bgep->htable[i]); 36501865Sdilpreet (void) ddi_intr_free(bgep->htable[i]); 36511865Sdilpreet } 36521865Sdilpreet 36531865Sdilpreet kmem_free(bgep->htable, bgep->intr_cnt * sizeof (ddi_intr_handle_t)); 36541865Sdilpreet } 36551865Sdilpreet 36561865Sdilpreet 36571865Sdilpreet void 36581865Sdilpreet bge_intr_enable(bge_t *bgep) 36591865Sdilpreet { 36601865Sdilpreet int i; 36611865Sdilpreet 36621865Sdilpreet if (bgep->intr_cap & DDI_INTR_FLAG_BLOCK) { 36631865Sdilpreet /* Call ddi_intr_block_enable() for MSI interrupts */ 36641865Sdilpreet (void) ddi_intr_block_enable(bgep->htable, bgep->intr_cnt); 36651865Sdilpreet } else { 36661865Sdilpreet /* Call ddi_intr_enable for MSI or FIXED interrupts */ 36671865Sdilpreet for (i = 0; i < bgep->intr_cnt; i++) { 36681865Sdilpreet (void) ddi_intr_enable(bgep->htable[i]); 36691865Sdilpreet } 36701865Sdilpreet } 36711865Sdilpreet } 36721865Sdilpreet 36731865Sdilpreet 36741865Sdilpreet void 36751865Sdilpreet bge_intr_disable(bge_t *bgep) 36761865Sdilpreet { 36771865Sdilpreet int i; 36781865Sdilpreet 36791369Sdduvall if (bgep->intr_cap & DDI_INTR_FLAG_BLOCK) { 36801369Sdduvall /* Call ddi_intr_block_disable() */ 36811369Sdduvall (void) ddi_intr_block_disable(bgep->htable, bgep->intr_cnt); 36821369Sdduvall } else { 36831369Sdduvall for (i = 0; i < bgep->intr_cnt; i++) { 36841369Sdduvall (void) ddi_intr_disable(bgep->htable[i]); 36851369Sdduvall } 36861369Sdduvall } 36871369Sdduvall } 3688*5903Ssowmini 3689*5903Ssowmini int 3690*5903Ssowmini bge_reprogram(bge_t *bgep) 3691*5903Ssowmini { 3692*5903Ssowmini int status = 0; 3693*5903Ssowmini 3694*5903Ssowmini ASSERT(mutex_owned(bgep->genlock)); 3695*5903Ssowmini 3696*5903Ssowmini if (bge_phys_update(bgep) != DDI_SUCCESS) { 3697*5903Ssowmini ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_DEGRADED); 3698*5903Ssowmini status = IOC_INVAL; 3699*5903Ssowmini } 3700*5903Ssowmini #ifdef BGE_IPMI_ASF 3701*5903Ssowmini if (bge_chip_sync(bgep, B_TRUE) == DDI_FAILURE) { 3702*5903Ssowmini #else 3703*5903Ssowmini if (bge_chip_sync(bgep) == DDI_FAILURE) { 3704*5903Ssowmini #endif 3705*5903Ssowmini ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_DEGRADED); 3706*5903Ssowmini status = IOC_INVAL; 3707*5903Ssowmini } 3708*5903Ssowmini if (bgep->intr_type == DDI_INTR_TYPE_MSI) 3709*5903Ssowmini bge_chip_msi_trig(bgep); 3710*5903Ssowmini return (status); 3711*5903Ssowmini } 3712