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 /* 235903Ssowmini * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 241369Sdduvall * Use is subject to license terms. 251369Sdduvall */ 261369Sdduvall 272675Szh199473 #include "bge_impl.h" 281369Sdduvall 291369Sdduvall #define PIO_ADDR(bgep, offset) ((void *)((caddr_t)(bgep)->io_regs+(offset))) 301369Sdduvall 311369Sdduvall /* 321369Sdduvall * Future features ... ? 331369Sdduvall */ 342135Szh199473 #define BGE_CFG_IO8 1 /* 8/16-bit cfg space BIS/BIC */ 353918Sml149210 #define BGE_IND_IO32 1 /* indirect access code */ 361369Sdduvall #define BGE_SEE_IO32 1 /* SEEPROM access code */ 371369Sdduvall #define BGE_FLASH_IO32 1 /* FLASH access code */ 381369Sdduvall 391369Sdduvall /* 401369Sdduvall * BGE MSI tunable: 411369Sdduvall * 421369Sdduvall * By default MSI is enabled on all supported platforms but it is disabled 431369Sdduvall * for some Broadcom chips due to known MSI hardware issues. Currently MSI 441369Sdduvall * is enabled only for 5714C A2 and 5715C A2 broadcom chips. 451369Sdduvall */ 461369Sdduvall boolean_t bge_enable_msi = B_TRUE; 471369Sdduvall 481369Sdduvall /* 493907Szh199473 * PCI-X/PCI-E relaxed ordering tunable for OS/Nexus driver 503907Szh199473 */ 513907Szh199473 boolean_t bge_relaxed_ordering = B_TRUE; 523907Szh199473 533907Szh199473 /* 541369Sdduvall * Property names 551369Sdduvall */ 561369Sdduvall static char knownids_propname[] = "bge-known-subsystems"; 571369Sdduvall 581369Sdduvall /* 591369Sdduvall * Patchable globals: 601369Sdduvall * 611369Sdduvall * bge_autorecover 621369Sdduvall * Enables/disables automatic recovery after fault detection 631369Sdduvall * 641369Sdduvall * bge_mlcr_default 651369Sdduvall * Value to program into the MLCR; controls the chip's GPIO pins 661369Sdduvall * 671369Sdduvall * bge_dma_{rd,wr}prio 681369Sdduvall * Relative priorities of DMA reads & DMA writes respectively. 691369Sdduvall * These may each be patched to any value 0-3. Equal values 701369Sdduvall * will give "fair" (round-robin) arbitration for PCI access. 711369Sdduvall * Unequal values will give one or the other function priority. 721369Sdduvall * 731369Sdduvall * bge_dma_rwctrl 741369Sdduvall * Value to put in the Read/Write DMA control register. See 751369Sdduvall * the Broadcom PRM for things you can fiddle with in this 761369Sdduvall * register ... 771369Sdduvall * 781369Sdduvall * bge_{tx,rx}_{count,ticks}_{norm,intr} 791369Sdduvall * Send/receive interrupt coalescing parameters. Counts are 801369Sdduvall * #s of descriptors, ticks are in microseconds. *norm* values 811369Sdduvall * apply between status updates/interrupts; the *intr* values 821369Sdduvall * refer to the 'during-interrupt' versions - see the PRM. 831369Sdduvall * 841369Sdduvall * NOTE: these values have been determined by measurement. They 851369Sdduvall * differ significantly from the values recommended in the PRM. 861369Sdduvall */ 871369Sdduvall static uint32_t bge_autorecover = 1; 881369Sdduvall static uint32_t bge_mlcr_default_5714 = MLCR_DEFAULT_5714; 891369Sdduvall 901369Sdduvall static uint32_t bge_dma_rdprio = 1; 911369Sdduvall static uint32_t bge_dma_wrprio = 0; 921369Sdduvall static uint32_t bge_dma_rwctrl = PDRWCR_VAR_DEFAULT; 931369Sdduvall static uint32_t bge_dma_rwctrl_5721 = PDRWCR_VAR_5721; 941369Sdduvall static uint32_t bge_dma_rwctrl_5714 = PDRWCR_VAR_5714; 951369Sdduvall static uint32_t bge_dma_rwctrl_5715 = PDRWCR_VAR_5715; 961369Sdduvall 971369Sdduvall uint32_t bge_rx_ticks_norm = 128; 981369Sdduvall uint32_t bge_tx_ticks_norm = 2048; /* 8 for FJ2+ !?!? */ 991369Sdduvall uint32_t bge_rx_count_norm = 8; 1001369Sdduvall uint32_t bge_tx_count_norm = 128; 1011369Sdduvall 1021369Sdduvall static uint32_t bge_rx_ticks_intr = 128; 1031369Sdduvall static uint32_t bge_tx_ticks_intr = 0; /* 8 for FJ2+ !?!? */ 1041369Sdduvall static uint32_t bge_rx_count_intr = 2; 1051369Sdduvall static uint32_t bge_tx_count_intr = 0; 1061369Sdduvall 1071369Sdduvall /* 1081369Sdduvall * Memory pool configuration parameters. 1091369Sdduvall * 1101369Sdduvall * These are generally specific to each member of the chip family, since 1111369Sdduvall * each one may have a different memory size/configuration. 1121369Sdduvall * 1131369Sdduvall * Setting the mbuf pool length for a specific type of chip to 0 inhibits 1141369Sdduvall * the driver from programming the various registers; instead they are left 1151369Sdduvall * at their hardware defaults. This is the preferred option for later chips 1161369Sdduvall * (5705+), whereas the older chips *required* these registers to be set, 1171369Sdduvall * since the h/w default was 0 ;-( 1181369Sdduvall */ 1191369Sdduvall static uint32_t bge_mbuf_pool_base = MBUF_POOL_BASE_DEFAULT; 1201369Sdduvall static uint32_t bge_mbuf_pool_base_5704 = MBUF_POOL_BASE_5704; 1211369Sdduvall static uint32_t bge_mbuf_pool_base_5705 = MBUF_POOL_BASE_5705; 1221369Sdduvall static uint32_t bge_mbuf_pool_base_5721 = MBUF_POOL_BASE_5721; 1231369Sdduvall static uint32_t bge_mbuf_pool_len = MBUF_POOL_LENGTH_DEFAULT; 1241369Sdduvall static uint32_t bge_mbuf_pool_len_5704 = MBUF_POOL_LENGTH_5704; 1251369Sdduvall static uint32_t bge_mbuf_pool_len_5705 = 0; /* use h/w default */ 1261369Sdduvall static uint32_t bge_mbuf_pool_len_5721 = 0; 1271369Sdduvall 1281369Sdduvall /* 1291369Sdduvall * Various high and low water marks, thresholds, etc ... 1301369Sdduvall * 1311369Sdduvall * Note: these are taken from revision 7 of the PRM, and some are different 1321369Sdduvall * from both the values in earlier PRMs *and* those determined experimentally 1331369Sdduvall * and used in earlier versions of this driver ... 1341369Sdduvall */ 1351369Sdduvall static uint32_t bge_mbuf_hi_water = MBUF_HIWAT_DEFAULT; 1361369Sdduvall static uint32_t bge_mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_DEFAULT; 1371369Sdduvall static uint32_t bge_mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_DEFAULT; 1381369Sdduvall 1391369Sdduvall static uint32_t bge_dmad_lo_water = DMAD_POOL_LOWAT_DEFAULT; 1401369Sdduvall static uint32_t bge_dmad_hi_water = DMAD_POOL_HIWAT_DEFAULT; 1411369Sdduvall static uint32_t bge_lowat_recv_frames = LOWAT_MAX_RECV_FRAMES_DEFAULT; 1421369Sdduvall 1431369Sdduvall static uint32_t bge_replenish_std = STD_RCV_BD_REPLENISH_DEFAULT; 1441369Sdduvall static uint32_t bge_replenish_mini = MINI_RCV_BD_REPLENISH_DEFAULT; 1451369Sdduvall static uint32_t bge_replenish_jumbo = JUMBO_RCV_BD_REPLENISH_DEFAULT; 1461369Sdduvall 1471369Sdduvall static uint32_t bge_watchdog_count = 1 << 16; 1481369Sdduvall static uint16_t bge_dma_miss_limit = 20; 1491369Sdduvall 1501369Sdduvall static uint32_t bge_stop_start_on_sync = 0; 1511369Sdduvall 1521369Sdduvall boolean_t bge_jumbo_enable = B_TRUE; 1531369Sdduvall 1541369Sdduvall /* 1553918Sml149210 * bge_intr_max_loop controls the maximum loop number within bge_intr. 1563918Sml149210 * When loading NIC with heavy network traffic, it is useful. 1573918Sml149210 * Increasing this value could have positive effect to throughput, 1583918Sml149210 * but it might also increase ticks of a bge ISR stick on CPU, which might 1593918Sml149210 * lead to bad UI interactive experience. So tune this with caution. 1603918Sml149210 */ 1613918Sml149210 static int bge_intr_max_loop = 1; 1623918Sml149210 1633918Sml149210 /* 1641369Sdduvall * ========== Low-level chip & ring buffer manipulation ========== 1651369Sdduvall */ 1661369Sdduvall 1671369Sdduvall #define BGE_DBG BGE_DBG_REGS /* debug flag for this code */ 1681369Sdduvall 1691369Sdduvall 1701369Sdduvall /* 1711369Sdduvall * Config space read-modify-write routines 1721369Sdduvall */ 1731369Sdduvall 1741369Sdduvall #if BGE_CFG_IO8 1751369Sdduvall 1761369Sdduvall static void bge_cfg_clr16(bge_t *bgep, bge_regno_t regno, uint16_t bits); 1771369Sdduvall #pragma inline(bge_cfg_clr16) 1781369Sdduvall 1791369Sdduvall static void 1801369Sdduvall bge_cfg_clr16(bge_t *bgep, bge_regno_t regno, uint16_t bits) 1811369Sdduvall { 1821369Sdduvall uint16_t regval; 1831369Sdduvall 1841369Sdduvall BGE_TRACE(("bge_cfg_clr16($%p, 0x%lx, 0x%x)", 1854588Sml149210 (void *)bgep, regno, bits)); 1861369Sdduvall 1871369Sdduvall regval = pci_config_get16(bgep->cfg_handle, regno); 1881369Sdduvall 1891369Sdduvall BGE_DEBUG(("bge_cfg_clr16($%p, 0x%lx, 0x%x): 0x%x => 0x%x", 1904588Sml149210 (void *)bgep, regno, bits, regval, regval & ~bits)); 1911369Sdduvall 1921369Sdduvall regval &= ~bits; 1931369Sdduvall pci_config_put16(bgep->cfg_handle, regno, regval); 1941369Sdduvall } 1951369Sdduvall 1961369Sdduvall #endif /* BGE_CFG_IO8 */ 1971369Sdduvall 1981369Sdduvall static void bge_cfg_clr32(bge_t *bgep, bge_regno_t regno, uint32_t bits); 1991369Sdduvall #pragma inline(bge_cfg_clr32) 2001369Sdduvall 2011369Sdduvall static void 2021369Sdduvall bge_cfg_clr32(bge_t *bgep, bge_regno_t regno, uint32_t bits) 2031369Sdduvall { 2041369Sdduvall uint32_t regval; 2051369Sdduvall 2061369Sdduvall BGE_TRACE(("bge_cfg_clr32($%p, 0x%lx, 0x%x)", 2074588Sml149210 (void *)bgep, regno, bits)); 2081369Sdduvall 2091369Sdduvall regval = pci_config_get32(bgep->cfg_handle, regno); 2101369Sdduvall 2111369Sdduvall BGE_DEBUG(("bge_cfg_clr32($%p, 0x%lx, 0x%x): 0x%x => 0x%x", 2124588Sml149210 (void *)bgep, regno, bits, regval, regval & ~bits)); 2131369Sdduvall 2141369Sdduvall regval &= ~bits; 2151369Sdduvall pci_config_put32(bgep->cfg_handle, regno, regval); 2161369Sdduvall } 2171369Sdduvall 2181369Sdduvall #if BGE_IND_IO32 2191369Sdduvall 2201369Sdduvall /* 2211369Sdduvall * Indirect access to registers & RISC scratchpads, using config space 2221369Sdduvall * accesses only. 2231369Sdduvall * 2241369Sdduvall * This isn't currently used, but someday we might want to use it for 2251369Sdduvall * restoring the Subsystem Device/Vendor registers (which aren't directly 2261369Sdduvall * writable in Config Space), or for downloading firmware into the RISCs 2271369Sdduvall * 2281369Sdduvall * In any case there are endian issues to be resolved before this code is 2291369Sdduvall * enabled; the bizarre way that bytes get twisted by this chip AND by 2301369Sdduvall * the PCI bridge in SPARC systems mean that we shouldn't enable it until 2311369Sdduvall * it's been thoroughly tested for all access sizes on all supported 2321369Sdduvall * architectures (SPARC *and* x86!). 2331369Sdduvall */ 2343918Sml149210 uint32_t bge_ind_get32(bge_t *bgep, bge_regno_t regno); 2351369Sdduvall #pragma inline(bge_ind_get32) 2361369Sdduvall 2373918Sml149210 uint32_t 2381369Sdduvall bge_ind_get32(bge_t *bgep, bge_regno_t regno) 2391369Sdduvall { 2401369Sdduvall uint32_t val; 2411369Sdduvall 2421369Sdduvall BGE_TRACE(("bge_ind_get32($%p, 0x%lx)", (void *)bgep, regno)); 2431369Sdduvall 2441369Sdduvall pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_RIAAR, regno); 2451369Sdduvall val = pci_config_get32(bgep->cfg_handle, PCI_CONF_BGE_RIADR); 2461369Sdduvall 2471369Sdduvall BGE_DEBUG(("bge_ind_get32($%p, 0x%lx) => 0x%x", 2484588Sml149210 (void *)bgep, regno, val)); 2491369Sdduvall 2503918Sml149210 val = LE_32(val); 2513918Sml149210 2521369Sdduvall return (val); 2531369Sdduvall } 2541369Sdduvall 2553918Sml149210 void bge_ind_put32(bge_t *bgep, bge_regno_t regno, uint32_t val); 2561369Sdduvall #pragma inline(bge_ind_put32) 2571369Sdduvall 2583918Sml149210 void 2591369Sdduvall bge_ind_put32(bge_t *bgep, bge_regno_t regno, uint32_t val) 2601369Sdduvall { 2611369Sdduvall BGE_TRACE(("bge_ind_put32($%p, 0x%lx, 0x%x)", 2624588Sml149210 (void *)bgep, regno, val)); 2631369Sdduvall 2643918Sml149210 val = LE_32(val); 2651369Sdduvall pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_RIAAR, regno); 2661369Sdduvall pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_RIADR, val); 2671369Sdduvall } 2681369Sdduvall 2691369Sdduvall #endif /* BGE_IND_IO32 */ 2701369Sdduvall 2711369Sdduvall #if BGE_DEBUGGING 2721369Sdduvall 2731369Sdduvall static void bge_pci_check(bge_t *bgep); 2741369Sdduvall #pragma no_inline(bge_pci_check) 2751369Sdduvall 2761369Sdduvall static void 2771369Sdduvall bge_pci_check(bge_t *bgep) 2781369Sdduvall { 2791369Sdduvall uint16_t pcistatus; 2801369Sdduvall 2811369Sdduvall pcistatus = pci_config_get16(bgep->cfg_handle, PCI_CONF_STAT); 2821369Sdduvall if ((pcistatus & (PCI_STAT_R_MAST_AB | PCI_STAT_R_TARG_AB)) != 0) 2831369Sdduvall BGE_DEBUG(("bge_pci_check($%p): PCI status 0x%x", 2844588Sml149210 (void *)bgep, pcistatus)); 2851369Sdduvall } 2861369Sdduvall 2871369Sdduvall #endif /* BGE_DEBUGGING */ 2881369Sdduvall 2891369Sdduvall /* 2901369Sdduvall * Perform first-stage chip (re-)initialisation, using only config-space 2911369Sdduvall * accesses: 2921369Sdduvall * 2931369Sdduvall * + Read the vendor/device/revision/subsystem/cache-line-size registers, 2941369Sdduvall * returning the data in the structure pointed to by <idp>. 2951369Sdduvall * + Configure the target-mode endianness (swap) options. 2961369Sdduvall * + Disable interrupts and enable Memory Space accesses. 2971369Sdduvall * + Enable or disable Bus Mastering according to the <enable_dma> flag. 2981369Sdduvall * 2991369Sdduvall * This sequence is adapted from Broadcom document 570X-PG102-R, 3001369Sdduvall * page 102, steps 1-3, 6-8 and 11-13. The omitted parts of the sequence 3011369Sdduvall * are 4 and 5 (Reset Core and wait) which are handled elsewhere. 3021369Sdduvall * 3031369Sdduvall * This function MUST be called before any non-config-space accesses 3041369Sdduvall * are made; on this first call <enable_dma> is B_FALSE, and it 3051369Sdduvall * effectively performs steps 3-1(!) of the initialisation sequence 3061369Sdduvall * (the rest are not required but should be harmless). 3071369Sdduvall * 3082135Szh199473 * It MUST also be called after a chip reset, as this disables 3091369Sdduvall * Memory Space cycles! In this case, <enable_dma> is B_TRUE, and 3101369Sdduvall * it is effectively performing steps 6-8. 3111369Sdduvall */ 3121369Sdduvall void bge_chip_cfg_init(bge_t *bgep, chip_id_t *cidp, boolean_t enable_dma); 3131369Sdduvall #pragma no_inline(bge_chip_cfg_init) 3141369Sdduvall 3151369Sdduvall void 3161369Sdduvall bge_chip_cfg_init(bge_t *bgep, chip_id_t *cidp, boolean_t enable_dma) 3171369Sdduvall { 3181369Sdduvall ddi_acc_handle_t handle; 3191369Sdduvall uint16_t command; 3201369Sdduvall uint32_t mhcr; 3211369Sdduvall uint16_t value16; 3221369Sdduvall int i; 3231369Sdduvall 3241369Sdduvall BGE_TRACE(("bge_chip_cfg_init($%p, $%p, %d)", 3254588Sml149210 (void *)bgep, (void *)cidp, enable_dma)); 3261369Sdduvall 3271369Sdduvall /* 3281369Sdduvall * Step 3: save PCI cache line size and subsystem vendor ID 3291369Sdduvall * 3301369Sdduvall * Read all the config-space registers that characterise the 3311369Sdduvall * chip, specifically vendor/device/revision/subsystem vendor 3321369Sdduvall * and subsystem device id. We expect (but don't check) that 3331369Sdduvall * (vendor == VENDOR_ID_BROADCOM) && (device == DEVICE_ID_5704) 3341369Sdduvall * 3352135Szh199473 * Also save all bus-transaction related registers (cache-line 3361369Sdduvall * size, bus-grant/latency parameters, etc). Some of these are 3371369Sdduvall * cleared by reset, so we'll have to restore them later. This 3381369Sdduvall * comes from the Broadcom document 570X-PG102-R ... 3391369Sdduvall * 3401369Sdduvall * Note: Broadcom document 570X-PG102-R seems to be in error 3411369Sdduvall * here w.r.t. the offsets of the Subsystem Vendor ID and 3421369Sdduvall * Subsystem (Device) ID registers, which are the opposite way 3431369Sdduvall * round according to the PCI standard. For good measure, we 3441369Sdduvall * save/restore both anyway. 3451369Sdduvall */ 3461369Sdduvall handle = bgep->cfg_handle; 3471369Sdduvall 3481369Sdduvall mhcr = pci_config_get32(handle, PCI_CONF_BGE_MHCR); 3491369Sdduvall cidp->asic_rev = mhcr & MHCR_CHIP_REV_MASK; 3501369Sdduvall cidp->businfo = pci_config_get32(handle, PCI_CONF_BGE_PCISTATE); 3511369Sdduvall cidp->command = pci_config_get16(handle, PCI_CONF_COMM); 3521369Sdduvall 3531369Sdduvall cidp->vendor = pci_config_get16(handle, PCI_CONF_VENID); 3541369Sdduvall cidp->device = pci_config_get16(handle, PCI_CONF_DEVID); 3551369Sdduvall cidp->subven = pci_config_get16(handle, PCI_CONF_SUBVENID); 3561369Sdduvall cidp->subdev = pci_config_get16(handle, PCI_CONF_SUBSYSID); 3571369Sdduvall cidp->revision = pci_config_get8(handle, PCI_CONF_REVID); 3581369Sdduvall cidp->clsize = pci_config_get8(handle, PCI_CONF_CACHE_LINESZ); 3591369Sdduvall cidp->latency = pci_config_get8(handle, PCI_CONF_LATENCY_TIMER); 3601369Sdduvall 3611369Sdduvall BGE_DEBUG(("bge_chip_cfg_init: %s bus is %s and %s; #INTA is %s", 3624588Sml149210 cidp->businfo & PCISTATE_BUS_IS_PCI ? "PCI" : "PCI-X", 3634588Sml149210 cidp->businfo & PCISTATE_BUS_IS_FAST ? "fast" : "slow", 3644588Sml149210 cidp->businfo & PCISTATE_BUS_IS_32_BIT ? "narrow" : "wide", 3654588Sml149210 cidp->businfo & PCISTATE_INTA_STATE ? "high" : "low")); 3661369Sdduvall BGE_DEBUG(("bge_chip_cfg_init: vendor 0x%x device 0x%x revision 0x%x", 3674588Sml149210 cidp->vendor, cidp->device, cidp->revision)); 3681369Sdduvall BGE_DEBUG(("bge_chip_cfg_init: subven 0x%x subdev 0x%x asic_rev 0x%x", 3694588Sml149210 cidp->subven, cidp->subdev, cidp->asic_rev)); 3701369Sdduvall BGE_DEBUG(("bge_chip_cfg_init: clsize %d latency %d command 0x%x", 3714588Sml149210 cidp->clsize, cidp->latency, cidp->command)); 3721369Sdduvall 3731369Sdduvall /* 3741369Sdduvall * Step 2 (also step 6): disable and clear interrupts. 3751369Sdduvall * Steps 11-13: configure PIO endianness options, and enable 3761369Sdduvall * indirect register access. We'll also select any other 3772135Szh199473 * options controlled by the MHCR (e.g. tagged status, mask 3781369Sdduvall * interrupt mode) at this stage ... 3791369Sdduvall * 3801369Sdduvall * Note: internally, the chip is 64-bit and BIG-endian, but 3811369Sdduvall * since it talks to the host over a (LITTLE-endian) PCI bus, 3821369Sdduvall * it normally swaps bytes around at the PCI interface. 3831369Sdduvall * However, the PCI host bridge on SPARC systems normally 3841369Sdduvall * swaps the byte lanes around too, since SPARCs are also 3851369Sdduvall * BIG-endian. So it turns out that on SPARC, the right 3861369Sdduvall * option is to tell the chip to swap (and the host bridge 3871369Sdduvall * will swap back again), whereas on x86 we ask the chip 3881369Sdduvall * NOT to swap, so the natural little-endianness of the 3891369Sdduvall * PCI bus is assumed. Then the only thing that doesn't 3901369Sdduvall * automatically work right is access to an 8-byte register 3911369Sdduvall * by a little-endian host; but we don't want to set the 3921369Sdduvall * MHCR_ENABLE_REGISTER_WORD_SWAP bit because then 4-byte 3931369Sdduvall * accesses don't go where expected ;-( So we live with 3941369Sdduvall * that, and perform word-swaps in software in the few cases 3951369Sdduvall * where a chip register is defined as an 8-byte value -- 3961369Sdduvall * see the code below for details ... 3971369Sdduvall * 3981369Sdduvall * Note: the meaning of the 'MASK_INTERRUPT_MODE' bit isn't 3991369Sdduvall * very clear in the register description in the PRM, but 4001369Sdduvall * Broadcom document 570X-PG104-R page 248 explains a little 4011369Sdduvall * more (under "Broadcom Mask Mode"). The bit changes the way 4021369Sdduvall * the MASK_PCI_INT_OUTPUT bit works: with MASK_INTERRUPT_MODE 4031369Sdduvall * clear, the chip interprets MASK_PCI_INT_OUTPUT in the same 4041369Sdduvall * way as the 5700 did, which isn't very convenient. Setting 4051369Sdduvall * the MASK_INTERRUPT_MODE bit makes the MASK_PCI_INT_OUTPUT 4061369Sdduvall * bit do just what its name says -- MASK the PCI #INTA output 4071369Sdduvall * (i.e. deassert the signal at the pin) leaving all internal 4081369Sdduvall * state unchanged. This is much more convenient for our 4091369Sdduvall * interrupt handler, so we set MASK_INTERRUPT_MODE here. 4101369Sdduvall * 4111369Sdduvall * Note: the inconvenient semantics of the interrupt mailbox 4121369Sdduvall * (nonzero disables and acknowledges/clears the interrupt, 4131369Sdduvall * zero enables AND CLEARS it) would make race conditions 4141369Sdduvall * likely in the interrupt handler: 4151369Sdduvall * 4161369Sdduvall * (1) acknowledge & disable interrupts 4171369Sdduvall * (2) while (more to do) 4181369Sdduvall * process packets 4191369Sdduvall * (3) enable interrupts -- also clears pending 4201369Sdduvall * 4211369Sdduvall * If the chip received more packets and internally generated 4221369Sdduvall * an interrupt between the check at (2) and the mbox write 4231369Sdduvall * at (3), this interrupt would be lost :-( 4241369Sdduvall * 4251369Sdduvall * The best way to avoid this is to use TAGGED STATUS mode, 4261369Sdduvall * where the chip includes a unique tag in each status block 4271369Sdduvall * update, and the host, when re-enabling interrupts, passes 4281369Sdduvall * the last tag it saw back to the chip; then the chip can 4291369Sdduvall * see whether the host is truly up to date, and regenerate 4301369Sdduvall * its interrupt if not. 4311369Sdduvall */ 4321369Sdduvall mhcr = MHCR_ENABLE_INDIRECT_ACCESS | 4334588Sml149210 MHCR_ENABLE_TAGGED_STATUS_MODE | 4344588Sml149210 MHCR_MASK_INTERRUPT_MODE | 4354588Sml149210 MHCR_CLEAR_INTERRUPT_INTA; 4361369Sdduvall 4371369Sdduvall if (bgep->intr_type == DDI_INTR_TYPE_FIXED) 4381369Sdduvall mhcr |= MHCR_MASK_PCI_INT_OUTPUT; 4391369Sdduvall 4401369Sdduvall #ifdef _BIG_ENDIAN 4411369Sdduvall mhcr |= MHCR_ENABLE_ENDIAN_WORD_SWAP | MHCR_ENABLE_ENDIAN_BYTE_SWAP; 4421369Sdduvall #endif /* _BIG_ENDIAN */ 4431369Sdduvall 4441369Sdduvall pci_config_put32(handle, PCI_CONF_BGE_MHCR, mhcr); 4451369Sdduvall 4461408Srandyf #ifdef BGE_IPMI_ASF 4471408Srandyf bgep->asf_wordswapped = B_FALSE; 4481408Srandyf #endif 4491369Sdduvall /* 4501369Sdduvall * Step 1 (also step 7): Enable PCI Memory Space accesses 4511369Sdduvall * Disable Memory Write/Invalidate 4521369Sdduvall * Enable or disable Bus Mastering 4531369Sdduvall * 4541369Sdduvall * Note that all other bits are taken from the original value saved 4551369Sdduvall * the first time through here, rather than from the current register 4561369Sdduvall * value, 'cos that will have been cleared by a soft RESET since. 4571369Sdduvall * In this way we preserve the OBP/nexus-parent's preferred settings 4581369Sdduvall * of the parity-error and system-error enable bits across multiple 4591369Sdduvall * chip RESETs. 4601369Sdduvall */ 4611369Sdduvall command = bgep->chipid.command | PCI_COMM_MAE; 4621369Sdduvall command &= ~(PCI_COMM_ME|PCI_COMM_MEMWR_INVAL); 4631369Sdduvall if (enable_dma) 4641369Sdduvall command |= PCI_COMM_ME; 4651369Sdduvall /* 4661369Sdduvall * on BCM5714 revision A0, false parity error gets generated 4672135Szh199473 * due to a logic bug. Provide a workaround by disabling parity 4681369Sdduvall * error. 4691369Sdduvall */ 4701369Sdduvall if (((cidp->device == DEVICE_ID_5714C) || 4711369Sdduvall (cidp->device == DEVICE_ID_5714S)) && 4721369Sdduvall (cidp->revision == REVISION_ID_5714_A0)) { 4731369Sdduvall command &= ~PCI_COMM_PARITY_DETECT; 4741369Sdduvall } 4751369Sdduvall pci_config_put16(handle, PCI_CONF_COMM, command); 4761369Sdduvall 4771369Sdduvall /* 4781369Sdduvall * On some PCI-E device, there were instances when 4791369Sdduvall * the device was still link training. 4801369Sdduvall */ 4811369Sdduvall if (bgep->chipid.pci_type == BGE_PCI_E) { 4821369Sdduvall i = 0; 4831369Sdduvall value16 = pci_config_get16(handle, PCI_CONF_COMM); 4841369Sdduvall while ((value16 != command) && (i < 100)) { 4851369Sdduvall drv_usecwait(200); 4861369Sdduvall value16 = pci_config_get16(handle, PCI_CONF_COMM); 4871369Sdduvall ++i; 4881369Sdduvall } 4891369Sdduvall } 4901369Sdduvall 4911369Sdduvall /* 4921369Sdduvall * Clear any remaining error status bits 4931369Sdduvall */ 4941369Sdduvall pci_config_put16(handle, PCI_CONF_STAT, ~0); 4951369Sdduvall 4961369Sdduvall /* 4972073Svivek * Do following if and only if the device is NOT BCM5714C OR 4982073Svivek * BCM5715C 4991369Sdduvall */ 5002073Svivek if (!((cidp->device == DEVICE_ID_5714C) || 5014588Sml149210 (cidp->device == DEVICE_ID_5715C))) { 5022073Svivek /* 5032073Svivek * Make sure these indirect-access registers are sane 5042073Svivek * rather than random after power-up or reset 5052073Svivek */ 5062073Svivek pci_config_put32(handle, PCI_CONF_BGE_RIAAR, 0); 5072073Svivek pci_config_put32(handle, PCI_CONF_BGE_MWBAR, 0); 5082073Svivek } 5092135Szh199473 /* 5102135Szh199473 * Step 8: Disable PCI-X/PCI-E Relaxed Ordering 5112135Szh199473 */ 5122135Szh199473 bge_cfg_clr16(bgep, PCIX_CONF_COMM, PCIX_COMM_RELAXED); 5132135Szh199473 5142135Szh199473 if (cidp->pci_type == BGE_PCI_E) 5152135Szh199473 bge_cfg_clr16(bgep, PCI_CONF_DEV_CTRL, 5164588Sml149210 DEV_CTRL_NO_SNOOP | DEV_CTRL_RELAXED); 5171369Sdduvall } 5181369Sdduvall 5191369Sdduvall #ifdef __amd64 5201369Sdduvall /* 5211369Sdduvall * Distinguish CPU types 5221369Sdduvall * 5231369Sdduvall * These use to distinguish AMD64 or Intel EM64T of CPU running mode. 5241369Sdduvall * If CPU runs on Intel EM64T mode,the 64bit operation cannot works fine 5251369Sdduvall * for PCI-Express based network interface card. This is the work-around 5261369Sdduvall * for those nics. 5271369Sdduvall */ 5281369Sdduvall static boolean_t bge_get_em64t_type(void); 5291369Sdduvall #pragma inline(bge_get_em64t_type) 5301369Sdduvall 5311369Sdduvall static boolean_t 5321369Sdduvall bge_get_em64t_type(void) 5331369Sdduvall { 5341369Sdduvall 5351369Sdduvall return (x86_vendor == X86_VENDOR_Intel); 5361369Sdduvall } 5371369Sdduvall #endif 5381369Sdduvall 5391369Sdduvall /* 5401369Sdduvall * Operating register get/set access routines 5411369Sdduvall */ 5421369Sdduvall 5431369Sdduvall uint32_t bge_reg_get32(bge_t *bgep, bge_regno_t regno); 5441369Sdduvall #pragma inline(bge_reg_get32) 5451369Sdduvall 5461369Sdduvall uint32_t 5471369Sdduvall bge_reg_get32(bge_t *bgep, bge_regno_t regno) 5481369Sdduvall { 5491369Sdduvall BGE_TRACE(("bge_reg_get32($%p, 0x%lx)", 5504588Sml149210 (void *)bgep, regno)); 5511369Sdduvall 5521369Sdduvall return (ddi_get32(bgep->io_handle, PIO_ADDR(bgep, regno))); 5531369Sdduvall } 5541369Sdduvall 5551369Sdduvall void bge_reg_put32(bge_t *bgep, bge_regno_t regno, uint32_t data); 5561369Sdduvall #pragma inline(bge_reg_put32) 5571369Sdduvall 5581369Sdduvall void 5591369Sdduvall bge_reg_put32(bge_t *bgep, bge_regno_t regno, uint32_t data) 5601369Sdduvall { 5611369Sdduvall BGE_TRACE(("bge_reg_put32($%p, 0x%lx, 0x%x)", 5624588Sml149210 (void *)bgep, regno, data)); 5631369Sdduvall 5641369Sdduvall ddi_put32(bgep->io_handle, PIO_ADDR(bgep, regno), data); 5651369Sdduvall BGE_PCICHK(bgep); 5661369Sdduvall } 5671369Sdduvall 5681369Sdduvall void bge_reg_set32(bge_t *bgep, bge_regno_t regno, uint32_t bits); 5691369Sdduvall #pragma inline(bge_reg_set32) 5701369Sdduvall 5711369Sdduvall void 5721369Sdduvall bge_reg_set32(bge_t *bgep, bge_regno_t regno, uint32_t bits) 5731369Sdduvall { 5741369Sdduvall uint32_t regval; 5751369Sdduvall 5761369Sdduvall BGE_TRACE(("bge_reg_set32($%p, 0x%lx, 0x%x)", 5774588Sml149210 (void *)bgep, regno, bits)); 5781369Sdduvall 5791369Sdduvall regval = bge_reg_get32(bgep, regno); 5801369Sdduvall regval |= bits; 5811369Sdduvall bge_reg_put32(bgep, regno, regval); 5821369Sdduvall } 5831369Sdduvall 5841369Sdduvall void bge_reg_clr32(bge_t *bgep, bge_regno_t regno, uint32_t bits); 5851369Sdduvall #pragma inline(bge_reg_clr32) 5861369Sdduvall 5871369Sdduvall void 5881369Sdduvall bge_reg_clr32(bge_t *bgep, bge_regno_t regno, uint32_t bits) 5891369Sdduvall { 5901369Sdduvall uint32_t regval; 5911369Sdduvall 5921369Sdduvall BGE_TRACE(("bge_reg_clr32($%p, 0x%lx, 0x%x)", 5934588Sml149210 (void *)bgep, regno, bits)); 5941369Sdduvall 5951369Sdduvall regval = bge_reg_get32(bgep, regno); 5961369Sdduvall regval &= ~bits; 5971369Sdduvall bge_reg_put32(bgep, regno, regval); 5981369Sdduvall } 5991369Sdduvall 6001369Sdduvall static uint64_t bge_reg_get64(bge_t *bgep, bge_regno_t regno); 6011369Sdduvall #pragma inline(bge_reg_get64) 6021369Sdduvall 6031369Sdduvall static uint64_t 6041369Sdduvall bge_reg_get64(bge_t *bgep, bge_regno_t regno) 6051369Sdduvall { 6061369Sdduvall uint64_t regval; 6071369Sdduvall 6081369Sdduvall #ifdef __amd64 6091369Sdduvall if (bge_get_em64t_type()) { 6101369Sdduvall regval = ddi_get32(bgep->io_handle, PIO_ADDR(bgep, regno + 4)); 6111369Sdduvall regval <<= 32; 6121369Sdduvall regval |= ddi_get32(bgep->io_handle, PIO_ADDR(bgep, regno)); 6131369Sdduvall } else { 6141369Sdduvall regval = ddi_get64(bgep->io_handle, PIO_ADDR(bgep, regno)); 6151369Sdduvall } 6161369Sdduvall #else 6171369Sdduvall regval = ddi_get64(bgep->io_handle, PIO_ADDR(bgep, regno)); 6181369Sdduvall #endif 6191369Sdduvall 6201369Sdduvall #ifdef _LITTLE_ENDIAN 6211369Sdduvall regval = (regval >> 32) | (regval << 32); 6221369Sdduvall #endif /* _LITTLE_ENDIAN */ 6231369Sdduvall 6241369Sdduvall BGE_TRACE(("bge_reg_get64($%p, 0x%lx) = 0x%016llx", 6254588Sml149210 (void *)bgep, regno, regval)); 6261369Sdduvall 6271369Sdduvall return (regval); 6281369Sdduvall } 6291369Sdduvall 6301369Sdduvall static void bge_reg_put64(bge_t *bgep, bge_regno_t regno, uint64_t data); 6311369Sdduvall #pragma inline(bge_reg_put64) 6321369Sdduvall 6331369Sdduvall static void 6341369Sdduvall bge_reg_put64(bge_t *bgep, bge_regno_t regno, uint64_t data) 6351369Sdduvall { 6361369Sdduvall BGE_TRACE(("bge_reg_put64($%p, 0x%lx, 0x%016llx)", 6374588Sml149210 (void *)bgep, regno, data)); 6381369Sdduvall 6391369Sdduvall #ifdef _LITTLE_ENDIAN 6401369Sdduvall data = ((data >> 32) | (data << 32)); 6411369Sdduvall #endif /* _LITTLE_ENDIAN */ 6421369Sdduvall 6431369Sdduvall #ifdef __amd64 6441369Sdduvall if (bge_get_em64t_type()) { 6451369Sdduvall ddi_put32(bgep->io_handle, 6464588Sml149210 PIO_ADDR(bgep, regno), (uint32_t)data); 6471369Sdduvall BGE_PCICHK(bgep); 6481369Sdduvall ddi_put32(bgep->io_handle, 6494588Sml149210 PIO_ADDR(bgep, regno + 4), (uint32_t)(data >> 32)); 6501369Sdduvall 6511369Sdduvall } else { 6521369Sdduvall ddi_put64(bgep->io_handle, PIO_ADDR(bgep, regno), data); 6531369Sdduvall } 6541369Sdduvall #else 6551369Sdduvall ddi_put64(bgep->io_handle, PIO_ADDR(bgep, regno), data); 6561369Sdduvall #endif 6571369Sdduvall 6581369Sdduvall BGE_PCICHK(bgep); 6591369Sdduvall } 6601369Sdduvall 6611369Sdduvall /* 6621369Sdduvall * The DDI doesn't provide get/put functions for 128 bit data 6631369Sdduvall * so we put RCBs out as two 64-bit chunks instead. 6641369Sdduvall */ 6651369Sdduvall static void bge_reg_putrcb(bge_t *bgep, bge_regno_t addr, bge_rcb_t *rcbp); 6661369Sdduvall #pragma inline(bge_reg_putrcb) 6671369Sdduvall 6681369Sdduvall static void 6691369Sdduvall bge_reg_putrcb(bge_t *bgep, bge_regno_t addr, bge_rcb_t *rcbp) 6701369Sdduvall { 6711369Sdduvall uint64_t *p; 6721369Sdduvall 6731369Sdduvall BGE_TRACE(("bge_reg_putrcb($%p, 0x%lx, 0x%016llx:%04x:%04x:%08x)", 6744588Sml149210 (void *)bgep, addr, rcbp->host_ring_addr, 6754588Sml149210 rcbp->max_len, rcbp->flags, rcbp->nic_ring_addr)); 6761369Sdduvall 6771369Sdduvall ASSERT((addr % sizeof (*rcbp)) == 0); 6781369Sdduvall 6791369Sdduvall p = (void *)rcbp; 6801369Sdduvall bge_reg_put64(bgep, addr, *p++); 6811369Sdduvall bge_reg_put64(bgep, addr+8, *p); 6821369Sdduvall } 6831369Sdduvall 6841369Sdduvall void bge_mbx_put(bge_t *bgep, bge_regno_t regno, uint64_t data); 6851369Sdduvall #pragma inline(bge_mbx_put) 6861369Sdduvall 6871369Sdduvall void 6881369Sdduvall bge_mbx_put(bge_t *bgep, bge_regno_t regno, uint64_t data) 6891369Sdduvall { 6901369Sdduvall BGE_TRACE(("bge_mbx_put($%p, 0x%lx, 0x%016llx)", 6914588Sml149210 (void *)bgep, regno, data)); 6921369Sdduvall 6931369Sdduvall /* 6941369Sdduvall * Mailbox registers are nominally 64 bits on the 5701, but 6951369Sdduvall * the MSW isn't used. On the 5703, they're only 32 bits 6961369Sdduvall * anyway. So here we just write the lower(!) 32 bits - 6971369Sdduvall * remembering that the chip is big-endian, even though the 6981369Sdduvall * PCI bus is little-endian ... 6991369Sdduvall */ 7001369Sdduvall #ifdef _BIG_ENDIAN 7011369Sdduvall ddi_put32(bgep->io_handle, PIO_ADDR(bgep, regno+4), (uint32_t)data); 7021369Sdduvall #else 7031369Sdduvall ddi_put32(bgep->io_handle, PIO_ADDR(bgep, regno), (uint32_t)data); 7041369Sdduvall #endif /* _BIG_ENDIAN */ 7051369Sdduvall BGE_PCICHK(bgep); 7061369Sdduvall } 7071369Sdduvall 7086546Sgh162552 uint32_t bge_mbx_get(bge_t *bgep, bge_regno_t regno); 7096546Sgh162552 #pragma inline(bge_mbx_get) 7106546Sgh162552 7116546Sgh162552 uint32_t 7126546Sgh162552 bge_mbx_get(bge_t *bgep, bge_regno_t regno) 7136546Sgh162552 { 7146546Sgh162552 uint32_t val32; 7156546Sgh162552 7166546Sgh162552 BGE_TRACE(("bge_mbx_get($%p, 0x%lx)", 7176546Sgh162552 (void *)bgep, regno)); 7186546Sgh162552 7196546Sgh162552 #ifdef _BIG_ENDIAN 7206546Sgh162552 val32 = ddi_get32(bgep->io_handle, PIO_ADDR(bgep, regno+4)); 7216546Sgh162552 #else 7226546Sgh162552 val32 = ddi_get32(bgep->io_handle, PIO_ADDR(bgep, regno)); 7236546Sgh162552 #endif /* _BIG_ENDIAN */ 7246546Sgh162552 BGE_PCICHK(bgep); 7256546Sgh162552 7266546Sgh162552 return (val32); 7276546Sgh162552 } 7286546Sgh162552 7296546Sgh162552 7301369Sdduvall #if BGE_DEBUGGING 7311369Sdduvall 7321369Sdduvall void bge_led_mark(bge_t *bgep); 7331369Sdduvall #pragma no_inline(bge_led_mark) 7341369Sdduvall 7351369Sdduvall void 7361369Sdduvall bge_led_mark(bge_t *bgep) 7371369Sdduvall { 7381369Sdduvall uint32_t led_ctrl = LED_CONTROL_OVERRIDE_LINK | 7394588Sml149210 LED_CONTROL_1000MBPS_LED | 7404588Sml149210 LED_CONTROL_100MBPS_LED | 7414588Sml149210 LED_CONTROL_10MBPS_LED; 7421369Sdduvall 7431369Sdduvall /* 7441369Sdduvall * Blink all three LINK LEDs on simultaneously, then all off, 7451369Sdduvall * then restore to automatic hardware control. This is used 7461369Sdduvall * in laboratory testing to trigger a logic analyser or scope. 7471369Sdduvall */ 7481369Sdduvall bge_reg_set32(bgep, ETHERNET_MAC_LED_CONTROL_REG, led_ctrl); 7491369Sdduvall led_ctrl ^= LED_CONTROL_OVERRIDE_LINK; 7501369Sdduvall bge_reg_clr32(bgep, ETHERNET_MAC_LED_CONTROL_REG, led_ctrl); 7511369Sdduvall led_ctrl = LED_CONTROL_OVERRIDE_LINK; 7521369Sdduvall bge_reg_clr32(bgep, ETHERNET_MAC_LED_CONTROL_REG, led_ctrl); 7531369Sdduvall } 7541369Sdduvall 7551369Sdduvall #endif /* BGE_DEBUGGING */ 7561369Sdduvall 7571369Sdduvall /* 7581369Sdduvall * NIC on-chip memory access routines 7591369Sdduvall * 7601369Sdduvall * Only 32K of NIC memory is visible at a time, controlled by the 7611369Sdduvall * Memory Window Base Address Register (in PCI config space). Once 7621369Sdduvall * this is set, the 32K region of NIC-local memory that it refers 7631369Sdduvall * to can be directly addressed in the upper 32K of the 64K of PCI 7641369Sdduvall * memory space used for the device. 7651369Sdduvall */ 7661369Sdduvall 7671369Sdduvall static void bge_nic_setwin(bge_t *bgep, bge_regno_t base); 7681369Sdduvall #pragma inline(bge_nic_setwin) 7691369Sdduvall 7701369Sdduvall static void 7711369Sdduvall bge_nic_setwin(bge_t *bgep, bge_regno_t base) 7721369Sdduvall { 7732073Svivek chip_id_t *cidp; 7742073Svivek 7751369Sdduvall BGE_TRACE(("bge_nic_setwin($%p, 0x%lx)", 7764588Sml149210 (void *)bgep, base)); 7771369Sdduvall 7781369Sdduvall ASSERT((base & MWBAR_GRANULE_MASK) == 0); 7792073Svivek 7802073Svivek /* 7812073Svivek * Don't do repeated zero data writes, 7822073Svivek * if the device is BCM5714C/15C. 7832073Svivek */ 7842073Svivek cidp = &bgep->chipid; 7852073Svivek if ((cidp->device == DEVICE_ID_5714C) || 7864588Sml149210 (cidp->device == DEVICE_ID_5715C)) { 7872073Svivek if (bgep->lastWriteZeroData && (base == (bge_regno_t)0)) 7882073Svivek return; 7892073Svivek /* Adjust lastWriteZeroData */ 7902073Svivek bgep->lastWriteZeroData = ((base == (bge_regno_t)0) ? 7914588Sml149210 B_TRUE : B_FALSE); 7922073Svivek } 7931369Sdduvall pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_MWBAR, base); 7941369Sdduvall } 7951369Sdduvall 7961369Sdduvall static uint32_t bge_nic_get32(bge_t *bgep, bge_regno_t addr); 7971369Sdduvall #pragma inline(bge_nic_get32) 7981369Sdduvall 7991369Sdduvall static uint32_t 8001369Sdduvall bge_nic_get32(bge_t *bgep, bge_regno_t addr) 8011369Sdduvall { 8021369Sdduvall uint32_t data; 8031369Sdduvall 8043918Sml149210 #if defined(BGE_IPMI_ASF) && !defined(__sparc) 8051408Srandyf if (bgep->asf_enabled && !bgep->asf_wordswapped) { 8061408Srandyf /* workaround for word swap error */ 8071408Srandyf if (addr & 4) 8081408Srandyf addr = addr - 4; 8091408Srandyf else 8101408Srandyf addr = addr + 4; 8111408Srandyf } 8121408Srandyf #endif 8131408Srandyf 8143918Sml149210 #ifdef __sparc 8153918Sml149210 data = bge_nic_read32(bgep, addr); 8163918Sml149210 #else 8171369Sdduvall bge_nic_setwin(bgep, addr & ~MWBAR_GRANULE_MASK); 8181369Sdduvall addr &= MWBAR_GRANULE_MASK; 8191369Sdduvall addr += NIC_MEM_WINDOW_OFFSET; 8201369Sdduvall 8211369Sdduvall data = ddi_get32(bgep->io_handle, PIO_ADDR(bgep, addr)); 8223918Sml149210 #endif 8231369Sdduvall 8241369Sdduvall BGE_TRACE(("bge_nic_get32($%p, 0x%lx) = 0x%08x", 8254588Sml149210 (void *)bgep, addr, data)); 8261369Sdduvall 8271369Sdduvall return (data); 8281369Sdduvall } 8291369Sdduvall 8301408Srandyf void bge_nic_put32(bge_t *bgep, bge_regno_t addr, uint32_t data); 8311408Srandyf #pragma inline(bge_nic_put32) 8321408Srandyf 8331408Srandyf void 8341369Sdduvall bge_nic_put32(bge_t *bgep, bge_regno_t addr, uint32_t data) 8351369Sdduvall { 8361369Sdduvall BGE_TRACE(("bge_nic_put32($%p, 0x%lx, 0x%08x)", 8374588Sml149210 (void *)bgep, addr, data)); 8381369Sdduvall 8393918Sml149210 #if defined(BGE_IPMI_ASF) && !defined(__sparc) 8401408Srandyf if (bgep->asf_enabled && !bgep->asf_wordswapped) { 8411408Srandyf /* workaround for word swap error */ 8421408Srandyf if (addr & 4) 8431408Srandyf addr = addr - 4; 8441408Srandyf else 8451408Srandyf addr = addr + 4; 8461408Srandyf } 8471408Srandyf #endif 8481408Srandyf 8493918Sml149210 #ifdef __sparc 8503918Sml149210 pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_MWBAR, addr); 8513918Sml149210 data = LE_32(data); 8523918Sml149210 pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_MWDAR, data); 8533918Sml149210 pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_MWBAR, 0); 8543918Sml149210 #else 8551369Sdduvall bge_nic_setwin(bgep, addr & ~MWBAR_GRANULE_MASK); 8561369Sdduvall addr &= MWBAR_GRANULE_MASK; 8571369Sdduvall addr += NIC_MEM_WINDOW_OFFSET; 8581369Sdduvall ddi_put32(bgep->io_handle, PIO_ADDR(bgep, addr), data); 8591369Sdduvall BGE_PCICHK(bgep); 8603918Sml149210 #endif 8611369Sdduvall } 8621369Sdduvall 8631369Sdduvall static uint64_t bge_nic_get64(bge_t *bgep, bge_regno_t addr); 8641369Sdduvall #pragma inline(bge_nic_get64) 8651369Sdduvall 8661369Sdduvall static uint64_t 8671369Sdduvall bge_nic_get64(bge_t *bgep, bge_regno_t addr) 8681369Sdduvall { 8691369Sdduvall uint64_t data; 8701369Sdduvall 8711369Sdduvall bge_nic_setwin(bgep, addr & ~MWBAR_GRANULE_MASK); 8721369Sdduvall addr &= MWBAR_GRANULE_MASK; 8731369Sdduvall addr += NIC_MEM_WINDOW_OFFSET; 8741369Sdduvall 8751369Sdduvall #ifdef __amd64 8761369Sdduvall if (bge_get_em64t_type()) { 8771369Sdduvall data = ddi_get32(bgep->io_handle, PIO_ADDR(bgep, addr)); 8781369Sdduvall data <<= 32; 8791369Sdduvall data |= ddi_get32(bgep->io_handle, 8804588Sml149210 PIO_ADDR(bgep, addr + 4)); 8811369Sdduvall } else { 8821369Sdduvall data = ddi_get64(bgep->io_handle, PIO_ADDR(bgep, addr)); 8831369Sdduvall } 8841369Sdduvall #else 8851369Sdduvall data = ddi_get64(bgep->io_handle, PIO_ADDR(bgep, addr)); 8861369Sdduvall #endif 8871369Sdduvall 8881369Sdduvall BGE_TRACE(("bge_nic_get64($%p, 0x%lx) = 0x%016llx", 8894588Sml149210 (void *)bgep, addr, data)); 8901369Sdduvall 8911369Sdduvall return (data); 8921369Sdduvall } 8931369Sdduvall 8941369Sdduvall static void bge_nic_put64(bge_t *bgep, bge_regno_t addr, uint64_t data); 8951369Sdduvall #pragma inline(bge_nic_put64) 8961369Sdduvall 8971369Sdduvall static void 8981369Sdduvall bge_nic_put64(bge_t *bgep, bge_regno_t addr, uint64_t data) 8991369Sdduvall { 9001369Sdduvall BGE_TRACE(("bge_nic_put64($%p, 0x%lx, 0x%016llx)", 9014588Sml149210 (void *)bgep, addr, data)); 9021369Sdduvall 9031369Sdduvall bge_nic_setwin(bgep, addr & ~MWBAR_GRANULE_MASK); 9041369Sdduvall addr &= MWBAR_GRANULE_MASK; 9051369Sdduvall addr += NIC_MEM_WINDOW_OFFSET; 9061369Sdduvall 9071369Sdduvall #ifdef __amd64 9081369Sdduvall if (bge_get_em64t_type()) { 9091369Sdduvall ddi_put32(bgep->io_handle, 9104588Sml149210 PIO_ADDR(bgep, addr), (uint32_t)data); 9111369Sdduvall BGE_PCICHK(bgep); 9121369Sdduvall ddi_put32(bgep->io_handle, 9134588Sml149210 PIO_ADDR(bgep, addr + 4), (uint32_t)(data >> 32)); 9141369Sdduvall } else { 9151369Sdduvall ddi_put64(bgep->io_handle, PIO_ADDR(bgep, addr), data); 9161369Sdduvall } 9171369Sdduvall #else 9181369Sdduvall ddi_put64(bgep->io_handle, PIO_ADDR(bgep, addr), data); 9191369Sdduvall #endif 9201369Sdduvall 9211369Sdduvall BGE_PCICHK(bgep); 9221369Sdduvall } 9231369Sdduvall 9241369Sdduvall /* 9251369Sdduvall * The DDI doesn't provide get/put functions for 128 bit data 9261369Sdduvall * so we put RCBs out as two 64-bit chunks instead. 9271369Sdduvall */ 9281369Sdduvall static void bge_nic_putrcb(bge_t *bgep, bge_regno_t addr, bge_rcb_t *rcbp); 9291369Sdduvall #pragma inline(bge_nic_putrcb) 9301369Sdduvall 9311369Sdduvall static void 9321369Sdduvall bge_nic_putrcb(bge_t *bgep, bge_regno_t addr, bge_rcb_t *rcbp) 9331369Sdduvall { 9341369Sdduvall uint64_t *p; 9351369Sdduvall 9361369Sdduvall BGE_TRACE(("bge_nic_putrcb($%p, 0x%lx, 0x%016llx:%04x:%04x:%08x)", 9374588Sml149210 (void *)bgep, addr, rcbp->host_ring_addr, 9384588Sml149210 rcbp->max_len, rcbp->flags, rcbp->nic_ring_addr)); 9391369Sdduvall 9401369Sdduvall ASSERT((addr % sizeof (*rcbp)) == 0); 9411369Sdduvall 9421369Sdduvall bge_nic_setwin(bgep, addr & ~MWBAR_GRANULE_MASK); 9431369Sdduvall addr &= MWBAR_GRANULE_MASK; 9441369Sdduvall addr += NIC_MEM_WINDOW_OFFSET; 9451369Sdduvall 9461369Sdduvall p = (void *)rcbp; 9471369Sdduvall #ifdef __amd64 9481369Sdduvall if (bge_get_em64t_type()) { 9491369Sdduvall ddi_put32(bgep->io_handle, PIO_ADDR(bgep, addr), 9504588Sml149210 (uint32_t)(*p)); 9511369Sdduvall ddi_put32(bgep->io_handle, PIO_ADDR(bgep, addr + 4), 9524588Sml149210 (uint32_t)(*p >> 32)); 9531369Sdduvall ddi_put32(bgep->io_handle, PIO_ADDR(bgep, addr + 8), 9544588Sml149210 (uint32_t)(*(p + 1))); 9551369Sdduvall ddi_put32(bgep->io_handle, PIO_ADDR(bgep, addr + 12), 9564588Sml149210 (uint32_t)(*p >> 32)); 9571369Sdduvall 9581369Sdduvall } else { 9591369Sdduvall ddi_put64(bgep->io_handle, PIO_ADDR(bgep, addr), *p++); 9601369Sdduvall ddi_put64(bgep->io_handle, PIO_ADDR(bgep, addr+8), *p); 9611369Sdduvall } 9621369Sdduvall #else 9631369Sdduvall ddi_put64(bgep->io_handle, PIO_ADDR(bgep, addr), *p++); 9641369Sdduvall ddi_put64(bgep->io_handle, PIO_ADDR(bgep, addr + 8), *p); 9651369Sdduvall #endif 9661369Sdduvall 9671369Sdduvall BGE_PCICHK(bgep); 9681369Sdduvall } 9691369Sdduvall 9701369Sdduvall static void bge_nic_zero(bge_t *bgep, bge_regno_t addr, uint32_t nbytes); 9711369Sdduvall #pragma inline(bge_nic_zero) 9721369Sdduvall 9731369Sdduvall static void 9741369Sdduvall bge_nic_zero(bge_t *bgep, bge_regno_t addr, uint32_t nbytes) 9751369Sdduvall { 9761369Sdduvall BGE_TRACE(("bge_nic_zero($%p, 0x%lx, 0x%x)", 9774588Sml149210 (void *)bgep, addr, nbytes)); 9781369Sdduvall 9791369Sdduvall ASSERT((addr & ~MWBAR_GRANULE_MASK) == 9804588Sml149210 ((addr+nbytes) & ~MWBAR_GRANULE_MASK)); 9811369Sdduvall 9821369Sdduvall bge_nic_setwin(bgep, addr & ~MWBAR_GRANULE_MASK); 9831369Sdduvall addr &= MWBAR_GRANULE_MASK; 9841369Sdduvall addr += NIC_MEM_WINDOW_OFFSET; 9851369Sdduvall 9861369Sdduvall (void) ddi_device_zero(bgep->io_handle, PIO_ADDR(bgep, addr), 9874588Sml149210 nbytes, 1, DDI_DATA_SZ08_ACC); 9881369Sdduvall BGE_PCICHK(bgep); 9891369Sdduvall } 9901369Sdduvall 9911369Sdduvall /* 9921369Sdduvall * MII (PHY) register get/set access routines 9931369Sdduvall * 9941369Sdduvall * These use the chip's MII auto-access method, controlled by the 9951369Sdduvall * MII Communication register at 0x044c, so the CPU doesn't have 9961369Sdduvall * to fiddle with the individual bits. 9971369Sdduvall */ 9981369Sdduvall 9991369Sdduvall #undef BGE_DBG 10001369Sdduvall #define BGE_DBG BGE_DBG_MII /* debug flag for this code */ 10011369Sdduvall 10021369Sdduvall static uint16_t bge_mii_access(bge_t *bgep, bge_regno_t regno, 10031369Sdduvall uint16_t data, uint32_t cmd); 10041369Sdduvall #pragma no_inline(bge_mii_access) 10051369Sdduvall 10061369Sdduvall static uint16_t 10071369Sdduvall bge_mii_access(bge_t *bgep, bge_regno_t regno, uint16_t data, uint32_t cmd) 10081369Sdduvall { 10091369Sdduvall uint32_t timeout; 10101369Sdduvall uint32_t regval1; 10111369Sdduvall uint32_t regval2; 10121369Sdduvall 10131369Sdduvall BGE_TRACE(("bge_mii_access($%p, 0x%lx, 0x%x, 0x%x)", 10144588Sml149210 (void *)bgep, regno, data, cmd)); 10151369Sdduvall 10161369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 10171369Sdduvall 10181369Sdduvall /* 10191369Sdduvall * Assemble the command ... 10201369Sdduvall */ 10211369Sdduvall cmd |= data << MI_COMMS_DATA_SHIFT; 10221369Sdduvall cmd |= regno << MI_COMMS_REGISTER_SHIFT; 10231369Sdduvall cmd |= bgep->phy_mii_addr << MI_COMMS_ADDRESS_SHIFT; 10241369Sdduvall cmd |= MI_COMMS_START; 10251369Sdduvall 10261369Sdduvall /* 10271369Sdduvall * Wait for any command already in progress ... 10281369Sdduvall * 10291369Sdduvall * Note: this *shouldn't* ever find that there is a command 10301369Sdduvall * in progress, because we already hold the <genlock> mutex. 10311369Sdduvall * Nonetheless, we have sometimes seen the MI_COMMS_START 10321369Sdduvall * bit set here -- it seems that the chip can initiate MII 10331369Sdduvall * accesses internally, even with polling OFF. 10341369Sdduvall */ 10351369Sdduvall regval1 = regval2 = bge_reg_get32(bgep, MI_COMMS_REG); 10361865Sdilpreet for (timeout = 100; ; ) { 10371369Sdduvall if ((regval2 & MI_COMMS_START) == 0) { 10381369Sdduvall bge_reg_put32(bgep, MI_COMMS_REG, cmd); 10391369Sdduvall break; 10401369Sdduvall } 10411369Sdduvall if (--timeout == 0) 10421369Sdduvall break; 10431369Sdduvall drv_usecwait(10); 10441369Sdduvall regval2 = bge_reg_get32(bgep, MI_COMMS_REG); 10451369Sdduvall } 10461369Sdduvall 10471865Sdilpreet if (timeout == 0) 10481865Sdilpreet return ((uint16_t)~0u); 10491865Sdilpreet 10501865Sdilpreet if (timeout != 100) 10511369Sdduvall BGE_REPORT((bgep, "bge_mii_access: cmd 0x%x -- " 10524588Sml149210 "MI_COMMS_START set for %d us; 0x%x->0x%x", 10534588Sml149210 cmd, 10*(100-timeout), regval1, regval2)); 10541369Sdduvall 10551369Sdduvall regval1 = bge_reg_get32(bgep, MI_COMMS_REG); 10561369Sdduvall for (timeout = 1000; ; ) { 10571369Sdduvall if ((regval1 & MI_COMMS_START) == 0) 10581369Sdduvall break; 10591369Sdduvall if (--timeout == 0) 10601369Sdduvall break; 10611369Sdduvall drv_usecwait(10); 10621369Sdduvall regval1 = bge_reg_get32(bgep, MI_COMMS_REG); 10631369Sdduvall } 10641369Sdduvall 10651369Sdduvall /* 10661369Sdduvall * Drop out early if the READ FAILED bit is set -- this chip 10671369Sdduvall * could be a 5703/4S, with a SerDes instead of a PHY! 10681369Sdduvall */ 10691369Sdduvall if (regval2 & MI_COMMS_READ_FAILED) 10701369Sdduvall return ((uint16_t)~0u); 10711369Sdduvall 10721369Sdduvall if (timeout == 0) 10731369Sdduvall return ((uint16_t)~0u); 10741369Sdduvall 10751369Sdduvall /* 10761369Sdduvall * The PRM says to wait 5us after seeing the START bit clear 10771369Sdduvall * and then re-read the register to get the final value of the 10781369Sdduvall * data field, in order to avoid a race condition where the 10791369Sdduvall * START bit is clear but the data field isn't yet valid. 10801369Sdduvall * 10811369Sdduvall * Note: we don't actually seem to be encounter this race; 10821369Sdduvall * except when the START bit is seen set again (see below), 10831369Sdduvall * the data field doesn't change during this 5us interval. 10841369Sdduvall */ 10851369Sdduvall drv_usecwait(5); 10861369Sdduvall regval2 = bge_reg_get32(bgep, MI_COMMS_REG); 10871369Sdduvall 10881369Sdduvall /* 10891369Sdduvall * Unfortunately, when following the PRMs instructions above, 10901369Sdduvall * we have occasionally seen the START bit set again(!) in the 10911369Sdduvall * value read after the 5us delay. This seems to be due to the 10921369Sdduvall * chip autonomously starting another MII access internally. 10931369Sdduvall * In such cases, the command/data/etc fields relate to the 10941369Sdduvall * internal command, rather than the one that we thought had 10951369Sdduvall * just finished. So in this case, we fall back to returning 10961369Sdduvall * the data from the original read that showed START clear. 10971369Sdduvall */ 10981369Sdduvall if (regval2 & MI_COMMS_START) { 10991369Sdduvall BGE_REPORT((bgep, "bge_mii_access: cmd 0x%x -- " 11004588Sml149210 "MI_COMMS_START set after transaction; 0x%x->0x%x", 11014588Sml149210 cmd, regval1, regval2)); 11021369Sdduvall regval2 = regval1; 11031369Sdduvall } 11041369Sdduvall 11051369Sdduvall if (regval2 & MI_COMMS_START) 11061369Sdduvall return ((uint16_t)~0u); 11071369Sdduvall 11081369Sdduvall if (regval2 & MI_COMMS_READ_FAILED) 11091369Sdduvall return ((uint16_t)~0u); 11101369Sdduvall 11111369Sdduvall return ((regval2 & MI_COMMS_DATA_MASK) >> MI_COMMS_DATA_SHIFT); 11121369Sdduvall } 11131369Sdduvall 11141369Sdduvall uint16_t bge_mii_get16(bge_t *bgep, bge_regno_t regno); 11151369Sdduvall #pragma no_inline(bge_mii_get16) 11161369Sdduvall 11171369Sdduvall uint16_t 11181369Sdduvall bge_mii_get16(bge_t *bgep, bge_regno_t regno) 11191369Sdduvall { 11201369Sdduvall BGE_TRACE(("bge_mii_get16($%p, 0x%lx)", 11214588Sml149210 (void *)bgep, regno)); 11221369Sdduvall 11231369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 11241369Sdduvall 11251369Sdduvall return (bge_mii_access(bgep, regno, 0, MI_COMMS_COMMAND_READ)); 11261369Sdduvall } 11271369Sdduvall 11281369Sdduvall void bge_mii_put16(bge_t *bgep, bge_regno_t regno, uint16_t data); 11291369Sdduvall #pragma no_inline(bge_mii_put16) 11301369Sdduvall 11311369Sdduvall void 11321369Sdduvall bge_mii_put16(bge_t *bgep, bge_regno_t regno, uint16_t data) 11331369Sdduvall { 11341369Sdduvall BGE_TRACE(("bge_mii_put16($%p, 0x%lx, 0x%x)", 11354588Sml149210 (void *)bgep, regno, data)); 11361369Sdduvall 11371369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 11381369Sdduvall 11391369Sdduvall (void) bge_mii_access(bgep, regno, data, MI_COMMS_COMMAND_WRITE); 11401369Sdduvall } 11411369Sdduvall 11421369Sdduvall #undef BGE_DBG 11431369Sdduvall #define BGE_DBG BGE_DBG_SEEPROM /* debug flag for this code */ 11441369Sdduvall 11451369Sdduvall #if BGE_SEE_IO32 || BGE_FLASH_IO32 11461369Sdduvall 11471369Sdduvall /* 11481369Sdduvall * Basic SEEPROM get/set access routine 11491369Sdduvall * 11501369Sdduvall * This uses the chip's SEEPROM auto-access method, controlled by the 11511369Sdduvall * Serial EEPROM Address/Data Registers at 0x6838/683c, so the CPU 11521369Sdduvall * doesn't have to fiddle with the individual bits. 11531369Sdduvall * 11541369Sdduvall * The caller should hold <genlock> and *also* have already acquired 11551369Sdduvall * the right to access the SEEPROM, via bge_nvmem_acquire() above. 11561369Sdduvall * 11571369Sdduvall * Return value: 11581369Sdduvall * 0 on success, 11591369Sdduvall * ENODATA on access timeout (maybe retryable: device may just be busy) 11601369Sdduvall * EPROTO on other h/w or s/w errors. 11611369Sdduvall * 11621369Sdduvall * <*dp> is an input to a SEEPROM_ACCESS_WRITE operation, or an output 11631369Sdduvall * from a (successful) SEEPROM_ACCESS_READ. 11641369Sdduvall */ 11651369Sdduvall static int bge_seeprom_access(bge_t *bgep, uint32_t cmd, bge_regno_t addr, 11661369Sdduvall uint32_t *dp); 11671369Sdduvall #pragma no_inline(bge_seeprom_access) 11681369Sdduvall 11691369Sdduvall static int 11701369Sdduvall bge_seeprom_access(bge_t *bgep, uint32_t cmd, bge_regno_t addr, uint32_t *dp) 11711369Sdduvall { 11721369Sdduvall uint32_t tries; 11731369Sdduvall uint32_t regval; 11741369Sdduvall 11751369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 11761369Sdduvall 11771369Sdduvall /* 11781369Sdduvall * On the newer chips that support both SEEPROM & Flash, we need 11791369Sdduvall * to specifically enable SEEPROM access (Flash is the default). 11801369Sdduvall * On older chips, we don't; SEEPROM is the only NVtype supported, 11811369Sdduvall * and the NVM control registers don't exist ... 11821369Sdduvall */ 11831369Sdduvall switch (bgep->chipid.nvtype) { 11841369Sdduvall case BGE_NVTYPE_NONE: 11851369Sdduvall case BGE_NVTYPE_UNKNOWN: 11861369Sdduvall _NOTE(NOTREACHED) 11871369Sdduvall case BGE_NVTYPE_SEEPROM: 11881369Sdduvall break; 11891369Sdduvall 11901369Sdduvall case BGE_NVTYPE_LEGACY_SEEPROM: 11911369Sdduvall case BGE_NVTYPE_UNBUFFERED_FLASH: 11921369Sdduvall case BGE_NVTYPE_BUFFERED_FLASH: 11931369Sdduvall default: 11941369Sdduvall bge_reg_set32(bgep, NVM_CONFIG1_REG, 11954588Sml149210 NVM_CFG1_LEGACY_SEEPROM_MODE); 11961369Sdduvall break; 11971369Sdduvall } 11981369Sdduvall 11991369Sdduvall /* 12001369Sdduvall * Check there's no command in progress. 12011369Sdduvall * 12021369Sdduvall * Note: this *shouldn't* ever find that there is a command 12031369Sdduvall * in progress, because we already hold the <genlock> mutex. 12041369Sdduvall * Also, to ensure we don't have a conflict with the chip's 12051369Sdduvall * internal firmware or a process accessing the same (shared) 12061369Sdduvall * SEEPROM through the other port of a 5704, we've already 12071369Sdduvall * been through the "software arbitration" protocol. 12081369Sdduvall * So this is just a final consistency check: we shouldn't 12091369Sdduvall * see EITHER the START bit (command started but not complete) 12101369Sdduvall * OR the COMPLETE bit (command completed but not cleared). 12111369Sdduvall */ 12121369Sdduvall regval = bge_reg_get32(bgep, SERIAL_EEPROM_ADDRESS_REG); 12131369Sdduvall if (regval & SEEPROM_ACCESS_START) 12141369Sdduvall return (EPROTO); 12151369Sdduvall if (regval & SEEPROM_ACCESS_COMPLETE) 12161369Sdduvall return (EPROTO); 12171369Sdduvall 12181369Sdduvall /* 12191369Sdduvall * Assemble the command ... 12201369Sdduvall */ 12211369Sdduvall cmd |= addr & SEEPROM_ACCESS_ADDRESS_MASK; 12221369Sdduvall addr >>= SEEPROM_ACCESS_ADDRESS_SIZE; 12231369Sdduvall addr <<= SEEPROM_ACCESS_DEVID_SHIFT; 12241369Sdduvall cmd |= addr & SEEPROM_ACCESS_DEVID_MASK; 12251369Sdduvall cmd |= SEEPROM_ACCESS_START; 12261369Sdduvall cmd |= SEEPROM_ACCESS_COMPLETE; 12271369Sdduvall cmd |= regval & SEEPROM_ACCESS_HALFCLOCK_MASK; 12281369Sdduvall 12291369Sdduvall bge_reg_put32(bgep, SERIAL_EEPROM_DATA_REG, *dp); 12301369Sdduvall bge_reg_put32(bgep, SERIAL_EEPROM_ADDRESS_REG, cmd); 12311369Sdduvall 12321369Sdduvall /* 12331369Sdduvall * By observation, a successful access takes ~20us on a 5703/4, 12341369Sdduvall * but apparently much longer (up to 1000us) on the obsolescent 12351369Sdduvall * BCM5700/BCM5701. We want to be sure we don't get any false 12361369Sdduvall * timeouts here; but OTOH, we don't want a bogus access to lock 12371369Sdduvall * out interrupts for longer than necessary. So we'll allow up 12381369Sdduvall * to 1000us ... 12391369Sdduvall */ 12401369Sdduvall for (tries = 0; tries < 1000; ++tries) { 12411369Sdduvall regval = bge_reg_get32(bgep, SERIAL_EEPROM_ADDRESS_REG); 12421369Sdduvall if (regval & SEEPROM_ACCESS_COMPLETE) 12431369Sdduvall break; 12441369Sdduvall drv_usecwait(1); 12451369Sdduvall } 12461369Sdduvall 12471369Sdduvall if (regval & SEEPROM_ACCESS_COMPLETE) { 12481369Sdduvall /* 12491369Sdduvall * All OK; read the SEEPROM data register, then write back 12501369Sdduvall * the value read from the address register in order to 12511369Sdduvall * clear the <complete> bit and leave the SEEPROM access 12521369Sdduvall * state machine idle, ready for the next access ... 12531369Sdduvall */ 12541369Sdduvall BGE_DEBUG(("bge_seeprom_access: complete after %d us", tries)); 12551369Sdduvall *dp = bge_reg_get32(bgep, SERIAL_EEPROM_DATA_REG); 12561369Sdduvall bge_reg_put32(bgep, SERIAL_EEPROM_ADDRESS_REG, regval); 12571369Sdduvall return (0); 12581369Sdduvall } 12591369Sdduvall 12601369Sdduvall /* 12611369Sdduvall * Hmm ... what happened here? 12621369Sdduvall * 12632135Szh199473 * Most likely, the user addressed a non-existent SEEPROM. Or 12641369Sdduvall * maybe the SEEPROM was busy internally (e.g. processing a write) 12651369Sdduvall * and didn't respond to being addressed. Either way, it's left 12661369Sdduvall * the SEEPROM access state machine wedged. So we'll reset it 12671369Sdduvall * before we leave, so it's ready for next time ... 12681369Sdduvall */ 12691369Sdduvall BGE_DEBUG(("bge_seeprom_access: timed out after %d us", tries)); 12701369Sdduvall bge_reg_set32(bgep, SERIAL_EEPROM_ADDRESS_REG, SEEPROM_ACCESS_INIT); 12711369Sdduvall return (ENODATA); 12721369Sdduvall } 12731369Sdduvall 12741369Sdduvall /* 12751369Sdduvall * Basic Flash get/set access routine 12761369Sdduvall * 12771369Sdduvall * These use the chip's Flash auto-access method, controlled by the 12781369Sdduvall * Flash Access Registers at 0x7000-701c, so the CPU doesn't have to 12791369Sdduvall * fiddle with the individual bits. 12801369Sdduvall * 12811369Sdduvall * The caller should hold <genlock> and *also* have already acquired 12821369Sdduvall * the right to access the Flash, via bge_nvmem_acquire() above. 12831369Sdduvall * 12841369Sdduvall * Return value: 12851369Sdduvall * 0 on success, 12861369Sdduvall * ENODATA on access timeout (maybe retryable: device may just be busy) 12871369Sdduvall * ENODEV if the NVmem device is missing or otherwise unusable 12881369Sdduvall * 12891369Sdduvall * <*dp> is an input to a NVM_FLASH_CMD_WR operation, or an output 12901369Sdduvall * from a (successful) NVM_FLASH_CMD_RD. 12911369Sdduvall */ 12921369Sdduvall static int bge_flash_access(bge_t *bgep, uint32_t cmd, bge_regno_t addr, 12931369Sdduvall uint32_t *dp); 12941369Sdduvall #pragma no_inline(bge_flash_access) 12951369Sdduvall 12961369Sdduvall static int 12971369Sdduvall bge_flash_access(bge_t *bgep, uint32_t cmd, bge_regno_t addr, uint32_t *dp) 12981369Sdduvall { 12991369Sdduvall uint32_t tries; 13001369Sdduvall uint32_t regval; 13011369Sdduvall 13021369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 13031369Sdduvall 13041369Sdduvall /* 13051369Sdduvall * On the newer chips that support both SEEPROM & Flash, we need 13061369Sdduvall * to specifically disable SEEPROM access while accessing Flash. 13071369Sdduvall * The older chips don't support Flash, and the NVM registers don't 13081369Sdduvall * exist, so we shouldn't be here at all! 13091369Sdduvall */ 13101369Sdduvall switch (bgep->chipid.nvtype) { 13111369Sdduvall case BGE_NVTYPE_NONE: 13121369Sdduvall case BGE_NVTYPE_UNKNOWN: 13131369Sdduvall _NOTE(NOTREACHED) 13141369Sdduvall case BGE_NVTYPE_SEEPROM: 13151369Sdduvall return (ENODEV); 13161369Sdduvall 13171369Sdduvall case BGE_NVTYPE_LEGACY_SEEPROM: 13181369Sdduvall case BGE_NVTYPE_UNBUFFERED_FLASH: 13191369Sdduvall case BGE_NVTYPE_BUFFERED_FLASH: 13201369Sdduvall default: 13211369Sdduvall bge_reg_clr32(bgep, NVM_CONFIG1_REG, 13224588Sml149210 NVM_CFG1_LEGACY_SEEPROM_MODE); 13231369Sdduvall break; 13241369Sdduvall } 13251369Sdduvall 13261369Sdduvall /* 13271369Sdduvall * Assemble the command ... 13281369Sdduvall */ 13291369Sdduvall addr &= NVM_FLASH_ADDR_MASK; 13301369Sdduvall cmd |= NVM_FLASH_CMD_DOIT; 13311369Sdduvall cmd |= NVM_FLASH_CMD_FIRST; 13321369Sdduvall cmd |= NVM_FLASH_CMD_LAST; 13331369Sdduvall cmd |= NVM_FLASH_CMD_DONE; 13341369Sdduvall 13351369Sdduvall bge_reg_put32(bgep, NVM_FLASH_WRITE_REG, *dp); 13361369Sdduvall bge_reg_put32(bgep, NVM_FLASH_ADDR_REG, addr); 13371369Sdduvall bge_reg_put32(bgep, NVM_FLASH_CMD_REG, cmd); 13381369Sdduvall 13391369Sdduvall /* 13401369Sdduvall * Allow up to 1000ms ... 13411369Sdduvall */ 13421369Sdduvall for (tries = 0; tries < 1000; ++tries) { 13431369Sdduvall regval = bge_reg_get32(bgep, NVM_FLASH_CMD_REG); 13441369Sdduvall if (regval & NVM_FLASH_CMD_DONE) 13451369Sdduvall break; 13461369Sdduvall drv_usecwait(1); 13471369Sdduvall } 13481369Sdduvall 13491369Sdduvall if (regval & NVM_FLASH_CMD_DONE) { 13501369Sdduvall /* 13511369Sdduvall * All OK; read the data from the Flash read register 13521369Sdduvall */ 13531369Sdduvall BGE_DEBUG(("bge_flash_access: complete after %d us", tries)); 13541369Sdduvall *dp = bge_reg_get32(bgep, NVM_FLASH_READ_REG); 13551369Sdduvall return (0); 13561369Sdduvall } 13571369Sdduvall 13581369Sdduvall /* 13591369Sdduvall * Hmm ... what happened here? 13601369Sdduvall * 13612135Szh199473 * Most likely, the user addressed a non-existent Flash. Or 13621369Sdduvall * maybe the Flash was busy internally (e.g. processing a write) 13631369Sdduvall * and didn't respond to being addressed. Either way, there's 13641369Sdduvall * nothing we can here ... 13651369Sdduvall */ 13661369Sdduvall BGE_DEBUG(("bge_flash_access: timed out after %d us", tries)); 13671369Sdduvall return (ENODATA); 13681369Sdduvall } 13691369Sdduvall 13701369Sdduvall /* 13711369Sdduvall * The next two functions regulate access to the NVram (if fitted). 13721369Sdduvall * 13731369Sdduvall * On a 5704 (dual core) chip, there's only one SEEPROM and one Flash 13741369Sdduvall * (SPI) interface, but they can be accessed through either port. These 13751369Sdduvall * are managed by different instance of this driver and have no software 13761369Sdduvall * state in common. 13771369Sdduvall * 13781369Sdduvall * In addition (and even on a single core chip) the chip's internal 13791369Sdduvall * firmware can access the SEEPROM/Flash, most notably after a RESET 13801369Sdduvall * when it may download code to run internally. 13811369Sdduvall * 13821369Sdduvall * So we need to arbitrate between these various software agents. For 13831369Sdduvall * this purpose, the chip provides the Software Arbitration Register, 13841369Sdduvall * which implements hardware(!) arbitration. 13851369Sdduvall * 13861369Sdduvall * This functionality didn't exist on older (5700/5701) chips, so there's 13871369Sdduvall * nothing we can do by way of arbitration on those; also, if there's no 13881369Sdduvall * SEEPROM/Flash fitted (or we couldn't determine what type), there's also 13891369Sdduvall * nothing to do. 13901369Sdduvall * 13911369Sdduvall * The internal firmware appears to use Request 0, which is the highest 13921369Sdduvall * priority. So we'd like to use Request 2, leaving one higher and one 13931369Sdduvall * lower for any future developments ... but apparently this doesn't 13941369Sdduvall * always work. So for now, the code uses Request 1 ;-( 13951369Sdduvall */ 13961369Sdduvall 13971369Sdduvall #define NVM_READ_REQ NVM_READ_REQ1 13981369Sdduvall #define NVM_RESET_REQ NVM_RESET_REQ1 13991369Sdduvall #define NVM_SET_REQ NVM_SET_REQ1 14001369Sdduvall 14011369Sdduvall static void bge_nvmem_relinquish(bge_t *bgep); 14021369Sdduvall #pragma no_inline(bge_nvmem_relinquish) 14031369Sdduvall 14041369Sdduvall static void 14051369Sdduvall bge_nvmem_relinquish(bge_t *bgep) 14061369Sdduvall { 14071369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 14081369Sdduvall 14091369Sdduvall switch (bgep->chipid.nvtype) { 14101369Sdduvall case BGE_NVTYPE_NONE: 14111369Sdduvall case BGE_NVTYPE_UNKNOWN: 14121369Sdduvall _NOTE(NOTREACHED) 14131369Sdduvall return; 14141369Sdduvall 14151369Sdduvall case BGE_NVTYPE_SEEPROM: 14161369Sdduvall /* 14171369Sdduvall * No arbitration performed, no release needed 14181369Sdduvall */ 14191369Sdduvall return; 14201369Sdduvall 14211369Sdduvall case BGE_NVTYPE_LEGACY_SEEPROM: 14221369Sdduvall case BGE_NVTYPE_UNBUFFERED_FLASH: 14231369Sdduvall case BGE_NVTYPE_BUFFERED_FLASH: 14241369Sdduvall default: 14251369Sdduvall break; 14261369Sdduvall } 14271369Sdduvall 14281369Sdduvall /* 14291369Sdduvall * Our own request should be present (whether or not granted) ... 14301369Sdduvall */ 14311865Sdilpreet (void) bge_reg_get32(bgep, NVM_SW_ARBITRATION_REG); 14321369Sdduvall 14331369Sdduvall /* 14341369Sdduvall * ... this will make it go away. 14351369Sdduvall */ 14361369Sdduvall bge_reg_put32(bgep, NVM_SW_ARBITRATION_REG, NVM_RESET_REQ); 14371865Sdilpreet (void) bge_reg_get32(bgep, NVM_SW_ARBITRATION_REG); 14381369Sdduvall } 14391369Sdduvall 14401369Sdduvall /* 14411369Sdduvall * Arbitrate for access to the NVmem, if necessary 14421369Sdduvall * 14431369Sdduvall * Return value: 14441369Sdduvall * 0 on success 14451369Sdduvall * EAGAIN if the device is in use (retryable) 14461369Sdduvall * ENODEV if the NVmem device is missing or otherwise unusable 14471369Sdduvall */ 14481369Sdduvall static int bge_nvmem_acquire(bge_t *bgep); 14491369Sdduvall #pragma no_inline(bge_nvmem_acquire) 14501369Sdduvall 14511369Sdduvall static int 14521369Sdduvall bge_nvmem_acquire(bge_t *bgep) 14531369Sdduvall { 14541369Sdduvall uint32_t regval; 14551369Sdduvall uint32_t tries; 14561369Sdduvall 14571369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 14581369Sdduvall 14591369Sdduvall switch (bgep->chipid.nvtype) { 14601369Sdduvall case BGE_NVTYPE_NONE: 14611369Sdduvall case BGE_NVTYPE_UNKNOWN: 14621369Sdduvall /* 14631369Sdduvall * Access denied: no (recognisable) device fitted 14641369Sdduvall */ 14651369Sdduvall return (ENODEV); 14661369Sdduvall 14671369Sdduvall case BGE_NVTYPE_SEEPROM: 14681369Sdduvall /* 14691369Sdduvall * Access granted: no arbitration needed (or possible) 14701369Sdduvall */ 14711369Sdduvall return (0); 14721369Sdduvall 14731369Sdduvall case BGE_NVTYPE_LEGACY_SEEPROM: 14741369Sdduvall case BGE_NVTYPE_UNBUFFERED_FLASH: 14751369Sdduvall case BGE_NVTYPE_BUFFERED_FLASH: 14761369Sdduvall default: 14771369Sdduvall /* 14781369Sdduvall * Access conditional: conduct arbitration protocol 14791369Sdduvall */ 14801369Sdduvall break; 14811369Sdduvall } 14821369Sdduvall 14831369Sdduvall /* 14841369Sdduvall * We're holding the per-port mutex <genlock>, so no-one other 14852135Szh199473 * thread can be attempting to access the NVmem through *this* 14861369Sdduvall * port. But it could be in use by the *other* port (of a 5704), 14871369Sdduvall * or by the chip's internal firmware, so we have to go through 14881369Sdduvall * the full (hardware) arbitration protocol ... 14891369Sdduvall * 14901369Sdduvall * Note that *because* we're holding <genlock>, the interrupt handler 14911369Sdduvall * won't be able to progress. So we're only willing to spin for a 14921369Sdduvall * fairly short time. Specifically: 14931369Sdduvall * 14941369Sdduvall * We *must* wait long enough for the hardware to resolve all 14951369Sdduvall * requests and determine the winner. Fortunately, this is 14961369Sdduvall * "almost instantaneous", even as observed by GHz CPUs. 14971369Sdduvall * 14981369Sdduvall * A successful access by another Solaris thread (via either 14991369Sdduvall * port) typically takes ~20us. So waiting a bit longer than 15001369Sdduvall * that will give a good chance of success, if the other user 15011369Sdduvall * *is* another thread on the other port. 15021369Sdduvall * 15031369Sdduvall * However, the internal firmware can hold on to the NVmem 15041369Sdduvall * for *much* longer: at least 10 milliseconds just after a 15051369Sdduvall * RESET, and maybe even longer if the NVmem actually contains 15061369Sdduvall * code to download and run on the internal CPUs. 15071369Sdduvall * 15081369Sdduvall * So, we'll allow 50us; if that's not enough then it's up to the 15091369Sdduvall * caller to retry later (hence the choice of return code EAGAIN). 15101369Sdduvall */ 15111369Sdduvall regval = bge_reg_get32(bgep, NVM_SW_ARBITRATION_REG); 15121369Sdduvall bge_reg_put32(bgep, NVM_SW_ARBITRATION_REG, NVM_SET_REQ); 15131369Sdduvall 15141369Sdduvall for (tries = 0; tries < 50; ++tries) { 15151369Sdduvall regval = bge_reg_get32(bgep, NVM_SW_ARBITRATION_REG); 15161369Sdduvall if (regval & NVM_WON_REQ1) 15171369Sdduvall break; 15181369Sdduvall drv_usecwait(1); 15191369Sdduvall } 15201369Sdduvall 15211369Sdduvall if (regval & NVM_WON_REQ1) { 15221369Sdduvall BGE_DEBUG(("bge_nvmem_acquire: won after %d us", tries)); 15231369Sdduvall return (0); 15241369Sdduvall } 15251369Sdduvall 15261369Sdduvall /* 15271369Sdduvall * Somebody else must be accessing the NVmem, so abandon our 15281369Sdduvall * attempt take control of it. The caller can try again later ... 15291369Sdduvall */ 15301369Sdduvall BGE_DEBUG(("bge_nvmem_acquire: lost after %d us", tries)); 15311369Sdduvall bge_nvmem_relinquish(bgep); 15321369Sdduvall return (EAGAIN); 15331369Sdduvall } 15341369Sdduvall 15351369Sdduvall /* 15361369Sdduvall * This code assumes that the GPIO1 bit has been wired up to the NVmem 15371369Sdduvall * write protect line in such a way that the NVmem is protected when 15381369Sdduvall * GPIO1 is an input, or is an output but driven high. Thus, to make the 15391369Sdduvall * NVmem writable we have to change GPIO1 to an output AND drive it low. 15401369Sdduvall * 15411369Sdduvall * Note: there's only one set of GPIO pins on a 5704, even though they 15421369Sdduvall * can be accessed through either port. So the chip has to resolve what 15431369Sdduvall * happens if the two ports program a single pin differently ... the rule 15441369Sdduvall * it uses is that if the ports disagree about the *direction* of a pin, 15451369Sdduvall * "output" wins over "input", but if they disagree about its *value* as 15461369Sdduvall * an output, then the pin is TRISTATED instead! In such a case, no-one 15471369Sdduvall * wins, and the external signal does whatever the external circuitry 15481369Sdduvall * defines as the default -- which we've assumed is the PROTECTED state. 15491369Sdduvall * So, we always change GPIO1 back to being an *input* whenever we're not 15501369Sdduvall * specifically using it to unprotect the NVmem. This allows either port 15512135Szh199473 * to update the NVmem, although obviously only one at a time! 15521369Sdduvall * 15531369Sdduvall * The caller should hold <genlock> and *also* have already acquired the 15541369Sdduvall * right to access the NVmem, via bge_nvmem_acquire() above. 15551369Sdduvall */ 15561369Sdduvall static void bge_nvmem_protect(bge_t *bgep, boolean_t protect); 15571369Sdduvall #pragma inline(bge_nvmem_protect) 15581369Sdduvall 15591369Sdduvall static void 15601369Sdduvall bge_nvmem_protect(bge_t *bgep, boolean_t protect) 15611369Sdduvall { 15621369Sdduvall uint32_t regval; 15631369Sdduvall 15641369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 15651369Sdduvall 15661369Sdduvall regval = bge_reg_get32(bgep, MISC_LOCAL_CONTROL_REG); 15671369Sdduvall if (protect) { 15681369Sdduvall regval |= MLCR_MISC_PINS_OUTPUT_1; 15691369Sdduvall regval &= ~MLCR_MISC_PINS_OUTPUT_ENABLE_1; 15701369Sdduvall } else { 15711369Sdduvall regval &= ~MLCR_MISC_PINS_OUTPUT_1; 15721369Sdduvall regval |= MLCR_MISC_PINS_OUTPUT_ENABLE_1; 15731369Sdduvall } 15741369Sdduvall bge_reg_put32(bgep, MISC_LOCAL_CONTROL_REG, regval); 15751369Sdduvall } 15761369Sdduvall 15771369Sdduvall /* 15781369Sdduvall * Now put it all together ... 15791369Sdduvall * 15801369Sdduvall * Try to acquire control of the NVmem; if successful, then: 15811369Sdduvall * unprotect it (if we want to write to it) 15821369Sdduvall * perform the requested access 15831369Sdduvall * reprotect it (after a write) 15841369Sdduvall * relinquish control 15851369Sdduvall * 15861369Sdduvall * Return value: 15871369Sdduvall * 0 on success, 15881369Sdduvall * EAGAIN if the device is in use (retryable) 15891369Sdduvall * ENODATA on access timeout (maybe retryable: device may just be busy) 15901369Sdduvall * ENODEV if the NVmem device is missing or otherwise unusable 15911369Sdduvall * EPROTO on other h/w or s/w errors. 15921369Sdduvall */ 15931369Sdduvall static int 15941369Sdduvall bge_nvmem_rw32(bge_t *bgep, uint32_t cmd, bge_regno_t addr, uint32_t *dp) 15951369Sdduvall { 15961369Sdduvall int err; 15971369Sdduvall 15981369Sdduvall if ((err = bge_nvmem_acquire(bgep)) == 0) { 15991369Sdduvall switch (cmd) { 16001369Sdduvall case BGE_SEE_READ: 16011369Sdduvall err = bge_seeprom_access(bgep, 16021369Sdduvall SEEPROM_ACCESS_READ, addr, dp); 16031369Sdduvall break; 16041369Sdduvall 16051369Sdduvall case BGE_SEE_WRITE: 16061369Sdduvall bge_nvmem_protect(bgep, B_FALSE); 16071369Sdduvall err = bge_seeprom_access(bgep, 16081369Sdduvall SEEPROM_ACCESS_WRITE, addr, dp); 16091369Sdduvall bge_nvmem_protect(bgep, B_TRUE); 16101369Sdduvall break; 16111369Sdduvall 16121369Sdduvall case BGE_FLASH_READ: 16131369Sdduvall if (DEVICE_5721_SERIES_CHIPSETS(bgep) || 16141369Sdduvall DEVICE_5714_SERIES_CHIPSETS(bgep)) { 16151369Sdduvall bge_reg_set32(bgep, NVM_ACCESS_REG, 16161369Sdduvall NVM_ACCESS_ENABLE); 16171369Sdduvall } 16181369Sdduvall err = bge_flash_access(bgep, 16191369Sdduvall NVM_FLASH_CMD_RD, addr, dp); 16201369Sdduvall if (DEVICE_5721_SERIES_CHIPSETS(bgep) || 16211369Sdduvall DEVICE_5714_SERIES_CHIPSETS(bgep)) { 16221369Sdduvall bge_reg_clr32(bgep, NVM_ACCESS_REG, 16231369Sdduvall NVM_ACCESS_ENABLE); 16241369Sdduvall } 16251369Sdduvall break; 16261369Sdduvall 16271369Sdduvall case BGE_FLASH_WRITE: 16281369Sdduvall if (DEVICE_5721_SERIES_CHIPSETS(bgep) || 16291369Sdduvall DEVICE_5714_SERIES_CHIPSETS(bgep)) { 16301369Sdduvall bge_reg_set32(bgep, NVM_ACCESS_REG, 16311369Sdduvall NVM_WRITE_ENABLE|NVM_ACCESS_ENABLE); 16321369Sdduvall } 16331369Sdduvall bge_nvmem_protect(bgep, B_FALSE); 16341369Sdduvall err = bge_flash_access(bgep, 16351369Sdduvall NVM_FLASH_CMD_WR, addr, dp); 16361369Sdduvall bge_nvmem_protect(bgep, B_TRUE); 16371369Sdduvall if (DEVICE_5721_SERIES_CHIPSETS(bgep) || 16381369Sdduvall DEVICE_5714_SERIES_CHIPSETS(bgep)) { 16391369Sdduvall bge_reg_clr32(bgep, NVM_ACCESS_REG, 16401369Sdduvall NVM_WRITE_ENABLE|NVM_ACCESS_ENABLE); 16411369Sdduvall } 16421369Sdduvall 16431369Sdduvall break; 16441369Sdduvall 16451369Sdduvall default: 16461369Sdduvall _NOTE(NOTREACHED) 16471369Sdduvall break; 16481369Sdduvall } 16491369Sdduvall bge_nvmem_relinquish(bgep); 16501369Sdduvall } 16511369Sdduvall 16521369Sdduvall BGE_DEBUG(("bge_nvmem_rw32: err %d", err)); 16531369Sdduvall return (err); 16541369Sdduvall } 16551369Sdduvall 16561369Sdduvall /* 16571369Sdduvall * Attempt to get a MAC address from the SEEPROM or Flash, if any 16581369Sdduvall */ 16591369Sdduvall static uint64_t bge_get_nvmac(bge_t *bgep); 16601369Sdduvall #pragma no_inline(bge_get_nvmac) 16611369Sdduvall 16621369Sdduvall static uint64_t 16631369Sdduvall bge_get_nvmac(bge_t *bgep) 16641369Sdduvall { 16651369Sdduvall uint32_t mac_high; 16661369Sdduvall uint32_t mac_low; 16671369Sdduvall uint32_t addr; 16681369Sdduvall uint32_t cmd; 16691369Sdduvall uint64_t mac; 16701369Sdduvall 16711369Sdduvall BGE_TRACE(("bge_get_nvmac($%p)", 16724588Sml149210 (void *)bgep)); 16731369Sdduvall 16741369Sdduvall switch (bgep->chipid.nvtype) { 16751369Sdduvall case BGE_NVTYPE_NONE: 16761369Sdduvall case BGE_NVTYPE_UNKNOWN: 16771369Sdduvall default: 16781369Sdduvall return (0ULL); 16791369Sdduvall 16801369Sdduvall case BGE_NVTYPE_SEEPROM: 16811369Sdduvall case BGE_NVTYPE_LEGACY_SEEPROM: 16821369Sdduvall cmd = BGE_SEE_READ; 16831369Sdduvall break; 16841369Sdduvall 16851369Sdduvall case BGE_NVTYPE_UNBUFFERED_FLASH: 16861369Sdduvall case BGE_NVTYPE_BUFFERED_FLASH: 16871369Sdduvall cmd = BGE_FLASH_READ; 16881369Sdduvall break; 16891369Sdduvall } 16901369Sdduvall 16911369Sdduvall addr = NVMEM_DATA_MAC_ADDRESS; 16921369Sdduvall if (bge_nvmem_rw32(bgep, cmd, addr, &mac_high)) 16931369Sdduvall return (0ULL); 16941369Sdduvall addr += 4; 16951369Sdduvall if (bge_nvmem_rw32(bgep, cmd, addr, &mac_low)) 16961369Sdduvall return (0ULL); 16971369Sdduvall 16981369Sdduvall /* 16991369Sdduvall * The Broadcom chip is natively BIG-endian, so that's how the 17001369Sdduvall * MAC address is represented in NVmem. We may need to swap it 17011369Sdduvall * around on a little-endian host ... 17021369Sdduvall */ 17031369Sdduvall #ifdef _BIG_ENDIAN 17041369Sdduvall mac = mac_high; 17051369Sdduvall mac = mac << 32; 17061369Sdduvall mac |= mac_low; 17071369Sdduvall #else 17081369Sdduvall mac = BGE_BSWAP_32(mac_high); 17091369Sdduvall mac = mac << 32; 17101369Sdduvall mac |= BGE_BSWAP_32(mac_low); 17111369Sdduvall #endif /* _BIG_ENDIAN */ 17121369Sdduvall 17131369Sdduvall return (mac); 17141369Sdduvall } 17151369Sdduvall 17161369Sdduvall #else /* BGE_SEE_IO32 || BGE_FLASH_IO32 */ 17171369Sdduvall 17181369Sdduvall /* 17191369Sdduvall * Dummy version for when we're not supporting NVmem access 17201369Sdduvall */ 17211369Sdduvall static uint64_t bge_get_nvmac(bge_t *bgep); 17221369Sdduvall #pragma inline(bge_get_nvmac) 17231369Sdduvall 17241369Sdduvall static uint64_t 17251369Sdduvall bge_get_nvmac(bge_t *bgep) 17261369Sdduvall { 17271369Sdduvall _NOTE(ARGUNUSED(bgep)) 17281369Sdduvall return (0ULL); 17291369Sdduvall } 17301369Sdduvall 17311369Sdduvall #endif /* BGE_SEE_IO32 || BGE_FLASH_IO32 */ 17321369Sdduvall 17331369Sdduvall /* 17341369Sdduvall * Determine the type of NVmem that is (or may be) attached to this chip, 17351369Sdduvall */ 17361369Sdduvall static enum bge_nvmem_type bge_nvmem_id(bge_t *bgep); 17371369Sdduvall #pragma no_inline(bge_nvmem_id) 17381369Sdduvall 17391369Sdduvall static enum bge_nvmem_type 17401369Sdduvall bge_nvmem_id(bge_t *bgep) 17411369Sdduvall { 17421369Sdduvall enum bge_nvmem_type nvtype; 17431369Sdduvall uint32_t config1; 17441369Sdduvall 17451369Sdduvall BGE_TRACE(("bge_nvmem_id($%p)", 17464588Sml149210 (void *)bgep)); 17471369Sdduvall 17481369Sdduvall switch (bgep->chipid.device) { 17491369Sdduvall default: 17501369Sdduvall /* 17511369Sdduvall * We shouldn't get here; it means we don't recognise 17521369Sdduvall * the chip, which means we don't know how to determine 17531369Sdduvall * what sort of NVmem (if any) it has. So we'll say 17541369Sdduvall * NONE, to disable the NVmem access code ... 17551369Sdduvall */ 17561369Sdduvall nvtype = BGE_NVTYPE_NONE; 17571369Sdduvall break; 17581369Sdduvall 17591369Sdduvall case DEVICE_ID_5700: 17601369Sdduvall case DEVICE_ID_5700x: 17611369Sdduvall case DEVICE_ID_5701: 17621369Sdduvall /* 17631369Sdduvall * These devices support *only* SEEPROMs 17641369Sdduvall */ 17651369Sdduvall nvtype = BGE_NVTYPE_SEEPROM; 17661369Sdduvall break; 17671369Sdduvall 17681369Sdduvall case DEVICE_ID_5702: 17691369Sdduvall case DEVICE_ID_5702fe: 17701369Sdduvall case DEVICE_ID_5703C: 17711369Sdduvall case DEVICE_ID_5703S: 17721369Sdduvall case DEVICE_ID_5704C: 17731369Sdduvall case DEVICE_ID_5704S: 17741369Sdduvall case DEVICE_ID_5704: 17751369Sdduvall case DEVICE_ID_5705M: 17761369Sdduvall case DEVICE_ID_5705C: 17773170Sml149210 case DEVICE_ID_5705_2: 17781369Sdduvall case DEVICE_ID_5706: 17791369Sdduvall case DEVICE_ID_5782: 17806989Sml40262 case DEVICE_ID_5787: 17816989Sml40262 case DEVICE_ID_5787M: 17821369Sdduvall case DEVICE_ID_5788: 17832135Szh199473 case DEVICE_ID_5789: 17841369Sdduvall case DEVICE_ID_5751: 17851369Sdduvall case DEVICE_ID_5751M: 17862675Szh199473 case DEVICE_ID_5752: 17872675Szh199473 case DEVICE_ID_5752M: 17883771Sml149210 case DEVICE_ID_5754: 17894330Sml149210 case DEVICE_ID_5755: 17906546Sgh162552 case DEVICE_ID_5755M: 17911369Sdduvall case DEVICE_ID_5721: 1792*7316SCrisson.Hu@Sun.COM case DEVICE_ID_5722: 17931369Sdduvall case DEVICE_ID_5714C: 17941369Sdduvall case DEVICE_ID_5714S: 17951369Sdduvall case DEVICE_ID_5715C: 17963170Sml149210 case DEVICE_ID_5715S: 17971369Sdduvall config1 = bge_reg_get32(bgep, NVM_CONFIG1_REG); 17981369Sdduvall if (config1 & NVM_CFG1_FLASH_MODE) 17991369Sdduvall if (config1 & NVM_CFG1_BUFFERED_MODE) 18001369Sdduvall nvtype = BGE_NVTYPE_BUFFERED_FLASH; 18011369Sdduvall else 18021369Sdduvall nvtype = BGE_NVTYPE_UNBUFFERED_FLASH; 18031369Sdduvall else 18041369Sdduvall nvtype = BGE_NVTYPE_LEGACY_SEEPROM; 18051369Sdduvall break; 18061369Sdduvall } 18071369Sdduvall 18081369Sdduvall return (nvtype); 18091369Sdduvall } 18101369Sdduvall 18111369Sdduvall #undef BGE_DBG 18121369Sdduvall #define BGE_DBG BGE_DBG_CHIP /* debug flag for this code */ 18131369Sdduvall 18141369Sdduvall static void 18151369Sdduvall bge_init_recv_rule(bge_t *bgep) 18161369Sdduvall { 18171369Sdduvall bge_recv_rule_t *rulep; 18181369Sdduvall uint32_t i; 18191369Sdduvall 18201369Sdduvall /* 18211369Sdduvall * receive rule: direct all TCP traffic to ring RULE_MATCH_TO_RING 18221369Sdduvall * 1. to direct UDP traffic, set: 18231369Sdduvall * rulep->control = RULE_PROTO_CONTROL; 18241369Sdduvall * rulep->mask_value = RULE_UDP_MASK_VALUE; 18251369Sdduvall * 2. to direct ICMP traffic, set: 18261369Sdduvall * rulep->control = RULE_PROTO_CONTROL; 18271369Sdduvall * rulep->mask_value = RULE_ICMP_MASK_VALUE; 18281369Sdduvall * 3. to direct traffic by source ip, set: 18291369Sdduvall * rulep->control = RULE_SIP_CONTROL; 18301369Sdduvall * rulep->mask_value = RULE_SIP_MASK_VALUE; 18311369Sdduvall */ 18321369Sdduvall rulep = bgep->recv_rules; 18331369Sdduvall rulep->control = RULE_PROTO_CONTROL; 18341369Sdduvall rulep->mask_value = RULE_TCP_MASK_VALUE; 18351369Sdduvall 18361369Sdduvall /* 18371369Sdduvall * set receive rule registers 18381369Sdduvall */ 18391369Sdduvall rulep = bgep->recv_rules; 18401369Sdduvall for (i = 0; i < RECV_RULES_NUM_MAX; i++, rulep++) { 18411369Sdduvall bge_reg_put32(bgep, RECV_RULE_MASK_REG(i), rulep->mask_value); 18421369Sdduvall bge_reg_put32(bgep, RECV_RULE_CONTROL_REG(i), rulep->control); 18431369Sdduvall } 18441369Sdduvall } 18451369Sdduvall 18461369Sdduvall /* 18471369Sdduvall * Using the values captured by bge_chip_cfg_init(), and additional probes 18481369Sdduvall * as required, characterise the chip fully: determine the label by which 18491369Sdduvall * to refer to this chip, the correct settings for various registers, and 18501369Sdduvall * of course whether the device and/or subsystem are supported! 18511369Sdduvall */ 18521865Sdilpreet int bge_chip_id_init(bge_t *bgep); 18531369Sdduvall #pragma no_inline(bge_chip_id_init) 18541369Sdduvall 18551865Sdilpreet int 18561369Sdduvall bge_chip_id_init(bge_t *bgep) 18571369Sdduvall { 18581369Sdduvall char buf[MAXPATHLEN]; /* any risk of stack overflow? */ 18591369Sdduvall boolean_t sys_ok; 18601369Sdduvall boolean_t dev_ok; 18611369Sdduvall chip_id_t *cidp; 18621369Sdduvall uint32_t subid; 18631369Sdduvall char *devname; 18641369Sdduvall char *sysname; 18651369Sdduvall int *ids; 18661369Sdduvall int err; 18671369Sdduvall uint_t i; 18681369Sdduvall 18691369Sdduvall sys_ok = dev_ok = B_FALSE; 18701369Sdduvall cidp = &bgep->chipid; 18711369Sdduvall 18721369Sdduvall /* 18731369Sdduvall * Check the PCI device ID to determine the generic chip type and 18741369Sdduvall * select parameters that depend on this. 18751369Sdduvall * 18761369Sdduvall * Note: because the SPARC platforms in general don't fit the 18771369Sdduvall * SEEPROM 'behind' the chip, the PCI revision ID register reads 18781369Sdduvall * as zero - which is why we use <asic_rev> rather than <revision> 18791369Sdduvall * below ... 18801369Sdduvall * 18811369Sdduvall * Note: in general we can't distinguish between the Copper/SerDes 18821369Sdduvall * versions by ID alone, as some Copper devices (e.g. some but not 18831369Sdduvall * all 5703Cs) have the same ID as the SerDes equivalents. So we 18841369Sdduvall * treat them the same here, and the MII code works out the media 18851369Sdduvall * type later on ... 18861369Sdduvall */ 18871369Sdduvall cidp->mbuf_base = bge_mbuf_pool_base; 18881369Sdduvall cidp->mbuf_length = bge_mbuf_pool_len; 18891369Sdduvall cidp->recv_slots = BGE_RECV_SLOTS_USED; 18901369Sdduvall cidp->bge_dma_rwctrl = bge_dma_rwctrl; 18911369Sdduvall cidp->pci_type = BGE_PCI_X; 18921369Sdduvall cidp->statistic_type = BGE_STAT_BLK; 18931908Sly149593 cidp->mbuf_lo_water_rdma = bge_mbuf_lo_water_rdma; 18941908Sly149593 cidp->mbuf_lo_water_rmac = bge_mbuf_lo_water_rmac; 18951908Sly149593 cidp->mbuf_hi_water = bge_mbuf_hi_water; 18965903Ssowmini cidp->rx_ticks_norm = bge_rx_ticks_norm; 18975903Ssowmini cidp->rx_count_norm = bge_rx_count_norm; 18981369Sdduvall 18991369Sdduvall if (cidp->rx_rings == 0 || cidp->rx_rings > BGE_RECV_RINGS_MAX) 19001369Sdduvall cidp->rx_rings = BGE_RECV_RINGS_DEFAULT; 19011369Sdduvall if (cidp->tx_rings == 0 || cidp->tx_rings > BGE_SEND_RINGS_MAX) 19021369Sdduvall cidp->tx_rings = BGE_SEND_RINGS_DEFAULT; 19031369Sdduvall 19041369Sdduvall cidp->msi_enabled = B_FALSE; 19051369Sdduvall 19061369Sdduvall switch (cidp->device) { 19071369Sdduvall case DEVICE_ID_5700: 19081369Sdduvall case DEVICE_ID_5700x: 19091369Sdduvall cidp->chip_label = 5700; 19102135Szh199473 cidp->flags |= CHIP_FLAG_PARTIAL_CSUM; 19111369Sdduvall break; 19121369Sdduvall 19131369Sdduvall case DEVICE_ID_5701: 19141369Sdduvall cidp->chip_label = 5701; 19151369Sdduvall dev_ok = B_TRUE; 19162135Szh199473 cidp->flags |= CHIP_FLAG_PARTIAL_CSUM; 19171369Sdduvall break; 19181369Sdduvall 19191369Sdduvall case DEVICE_ID_5702: 19201369Sdduvall case DEVICE_ID_5702fe: 19211369Sdduvall cidp->chip_label = 5702; 19221369Sdduvall dev_ok = B_TRUE; 19232135Szh199473 cidp->flags |= CHIP_FLAG_PARTIAL_CSUM; 19242135Szh199473 cidp->pci_type = BGE_PCI; 19251369Sdduvall break; 19261369Sdduvall 19271369Sdduvall case DEVICE_ID_5703C: 19281369Sdduvall case DEVICE_ID_5703S: 19291369Sdduvall case DEVICE_ID_5703: 19301369Sdduvall /* 19311369Sdduvall * Revision A0 of the 5703/5793 had various errata 19321369Sdduvall * that we can't or don't work around, so it's not 19331369Sdduvall * supported, but all later versions are 19341369Sdduvall */ 19351369Sdduvall cidp->chip_label = cidp->subven == VENDOR_ID_SUN ? 5793 : 5703; 19361369Sdduvall if (bgep->chipid.asic_rev != MHCR_CHIP_REV_5703_A0) 19371369Sdduvall dev_ok = B_TRUE; 19382135Szh199473 cidp->flags |= CHIP_FLAG_PARTIAL_CSUM; 19391369Sdduvall break; 19401369Sdduvall 19411369Sdduvall case DEVICE_ID_5704C: 19421369Sdduvall case DEVICE_ID_5704S: 19431369Sdduvall case DEVICE_ID_5704: 19441369Sdduvall cidp->chip_label = cidp->subven == VENDOR_ID_SUN ? 5794 : 5704; 19451369Sdduvall cidp->mbuf_base = bge_mbuf_pool_base_5704; 19461369Sdduvall cidp->mbuf_length = bge_mbuf_pool_len_5704; 19471369Sdduvall dev_ok = B_TRUE; 19486133Sgh162552 cidp->flags |= CHIP_FLAG_PARTIAL_CSUM; 19491369Sdduvall break; 19501369Sdduvall 19511369Sdduvall case DEVICE_ID_5705C: 19521369Sdduvall case DEVICE_ID_5705M: 19531369Sdduvall case DEVICE_ID_5705MA3: 19541369Sdduvall case DEVICE_ID_5705F: 19553170Sml149210 case DEVICE_ID_5705_2: 19563771Sml149210 case DEVICE_ID_5754: 19573771Sml149210 if (cidp->device == DEVICE_ID_5754) { 19583771Sml149210 cidp->chip_label = 5754; 19593771Sml149210 cidp->pci_type = BGE_PCI_E; 19603771Sml149210 } else { 19613771Sml149210 cidp->chip_label = 5705; 19623771Sml149210 cidp->pci_type = BGE_PCI; 19633771Sml149210 } 19641908Sly149593 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 19651908Sly149593 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 19661908Sly149593 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 19671369Sdduvall cidp->mbuf_base = bge_mbuf_pool_base_5705; 19681369Sdduvall cidp->mbuf_length = bge_mbuf_pool_len_5705; 19691369Sdduvall cidp->recv_slots = BGE_RECV_SLOTS_5705; 19701369Sdduvall cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 19711908Sly149593 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 19721369Sdduvall cidp->flags |= CHIP_FLAG_NO_JUMBO; 19732135Szh199473 cidp->flags |= CHIP_FLAG_PARTIAL_CSUM; 19741369Sdduvall cidp->statistic_type = BGE_STAT_REG; 19751369Sdduvall dev_ok = B_TRUE; 19761369Sdduvall break; 19771369Sdduvall 19784588Sml149210 case DEVICE_ID_5753: 19794588Sml149210 cidp->chip_label = 5753; 19804588Sml149210 cidp->pci_type = BGE_PCI_E; 19814588Sml149210 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 19824588Sml149210 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 19834588Sml149210 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 19844588Sml149210 cidp->mbuf_base = bge_mbuf_pool_base_5705; 19854588Sml149210 cidp->mbuf_length = bge_mbuf_pool_len_5705; 19864588Sml149210 cidp->recv_slots = BGE_RECV_SLOTS_5705; 19874588Sml149210 cidp->bge_mlcr_default |= MLCR_MISC_PINS_OUTPUT_ENABLE_1; 19884588Sml149210 cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 19894588Sml149210 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 19904588Sml149210 cidp->flags |= CHIP_FLAG_NO_JUMBO; 19914588Sml149210 cidp->statistic_type = BGE_STAT_REG; 19924588Sml149210 dev_ok = B_TRUE; 19934588Sml149210 break; 19944588Sml149210 19954330Sml149210 case DEVICE_ID_5755: 19966546Sgh162552 case DEVICE_ID_5755M: 19974330Sml149210 cidp->chip_label = 5755; 19984330Sml149210 cidp->pci_type = BGE_PCI_E; 19994330Sml149210 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 20004330Sml149210 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 20014330Sml149210 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 20024330Sml149210 cidp->mbuf_base = bge_mbuf_pool_base_5705; 20034330Sml149210 cidp->mbuf_length = bge_mbuf_pool_len_5705; 20044330Sml149210 cidp->recv_slots = BGE_RECV_SLOTS_5705; 20054330Sml149210 cidp->bge_mlcr_default |= MLCR_MISC_PINS_OUTPUT_ENABLE_1; 20064330Sml149210 cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 20074330Sml149210 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 20084330Sml149210 cidp->flags |= CHIP_FLAG_NO_JUMBO; 20094330Sml149210 cidp->flags |= CHIP_FLAG_PARTIAL_CSUM; 20104330Sml149210 cidp->statistic_type = BGE_STAT_REG; 20114330Sml149210 dev_ok = B_TRUE; 20124330Sml149210 break; 20134330Sml149210 20146989Sml40262 case DEVICE_ID_5787: 20156989Sml40262 case DEVICE_ID_5787M: 20166989Sml40262 cidp->chip_label = 5787; 20176989Sml40262 cidp->pci_type = BGE_PCI_E; 20186989Sml40262 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 20196989Sml40262 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 20206989Sml40262 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 20216989Sml40262 cidp->mbuf_base = bge_mbuf_pool_base_5705; 20226989Sml40262 cidp->mbuf_length = bge_mbuf_pool_len_5705; 20236989Sml40262 cidp->recv_slots = BGE_RECV_SLOTS_5705; 20246989Sml40262 cidp->bge_mlcr_default |= MLCR_MISC_PINS_OUTPUT_ENABLE_1; 20256989Sml40262 cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 20266989Sml40262 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 20276989Sml40262 cidp->flags |= CHIP_FLAG_NO_JUMBO; 20286989Sml40262 cidp->statistic_type = BGE_STAT_REG; 20296989Sml40262 dev_ok = B_TRUE; 20306989Sml40262 break; 20316989Sml40262 20321369Sdduvall case DEVICE_ID_5706: 20331369Sdduvall cidp->chip_label = 5706; 20341369Sdduvall cidp->flags |= CHIP_FLAG_NO_JUMBO; 20351369Sdduvall break; 20361369Sdduvall 20371369Sdduvall case DEVICE_ID_5782: 20381369Sdduvall /* 20391369Sdduvall * Apart from the label, we treat this as a 5705(?) 20401369Sdduvall */ 20411369Sdduvall cidp->chip_label = 5782; 20421908Sly149593 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 20431908Sly149593 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 20441908Sly149593 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 20451369Sdduvall cidp->mbuf_base = bge_mbuf_pool_base_5705; 20461369Sdduvall cidp->mbuf_length = bge_mbuf_pool_len_5705; 20471369Sdduvall cidp->recv_slots = BGE_RECV_SLOTS_5705; 20481369Sdduvall cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 20491908Sly149593 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 20501369Sdduvall cidp->flags |= CHIP_FLAG_NO_JUMBO; 20512135Szh199473 cidp->flags |= CHIP_FLAG_PARTIAL_CSUM; 20521369Sdduvall cidp->statistic_type = BGE_STAT_REG; 20531369Sdduvall dev_ok = B_TRUE; 20541369Sdduvall break; 20551369Sdduvall 20561369Sdduvall case DEVICE_ID_5788: 20571369Sdduvall /* 20581369Sdduvall * Apart from the label, we treat this as a 5705(?) 20591369Sdduvall */ 20601369Sdduvall cidp->chip_label = 5788; 20611908Sly149593 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 20621908Sly149593 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 20631908Sly149593 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 20641369Sdduvall cidp->mbuf_base = bge_mbuf_pool_base_5705; 20651369Sdduvall cidp->mbuf_length = bge_mbuf_pool_len_5705; 20661369Sdduvall cidp->recv_slots = BGE_RECV_SLOTS_5705; 20671369Sdduvall cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 20681908Sly149593 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 20691369Sdduvall cidp->statistic_type = BGE_STAT_REG; 20701369Sdduvall cidp->flags |= CHIP_FLAG_NO_JUMBO; 20711369Sdduvall dev_ok = B_TRUE; 20721369Sdduvall break; 20731369Sdduvall 20741369Sdduvall case DEVICE_ID_5714C: 20751369Sdduvall if (cidp->revision >= REVISION_ID_5714_A2) 20761369Sdduvall cidp->msi_enabled = bge_enable_msi; 20771369Sdduvall /* FALLTHRU */ 20781369Sdduvall case DEVICE_ID_5714S: 20791369Sdduvall cidp->chip_label = 5714; 20801908Sly149593 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 20811908Sly149593 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 20821908Sly149593 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 20831369Sdduvall cidp->mbuf_base = bge_mbuf_pool_base_5721; 20841369Sdduvall cidp->mbuf_length = bge_mbuf_pool_len_5721; 20851369Sdduvall cidp->recv_slots = BGE_RECV_SLOTS_5721; 20861369Sdduvall cidp->bge_dma_rwctrl = bge_dma_rwctrl_5714; 20871369Sdduvall cidp->bge_mlcr_default = bge_mlcr_default_5714; 20881369Sdduvall cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 20891908Sly149593 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 20901369Sdduvall cidp->pci_type = BGE_PCI_E; 20911369Sdduvall cidp->statistic_type = BGE_STAT_REG; 20921369Sdduvall dev_ok = B_TRUE; 20931369Sdduvall break; 20941369Sdduvall 20951369Sdduvall case DEVICE_ID_5715C: 20963170Sml149210 case DEVICE_ID_5715S: 20971369Sdduvall cidp->chip_label = 5715; 20981908Sly149593 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 20991908Sly149593 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 21001908Sly149593 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 21011369Sdduvall cidp->mbuf_base = bge_mbuf_pool_base_5721; 21021369Sdduvall cidp->mbuf_length = bge_mbuf_pool_len_5721; 21031369Sdduvall cidp->recv_slots = BGE_RECV_SLOTS_5721; 21041369Sdduvall cidp->bge_dma_rwctrl = bge_dma_rwctrl_5715; 21051369Sdduvall cidp->bge_mlcr_default = bge_mlcr_default_5714; 21061369Sdduvall cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 21071908Sly149593 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 21081369Sdduvall cidp->pci_type = BGE_PCI_E; 21091369Sdduvall cidp->statistic_type = BGE_STAT_REG; 21101908Sly149593 if (cidp->revision >= REVISION_ID_5715_A2) 21111908Sly149593 cidp->msi_enabled = bge_enable_msi; 21121369Sdduvall dev_ok = B_TRUE; 21131369Sdduvall break; 21141369Sdduvall 21151369Sdduvall case DEVICE_ID_5721: 21161369Sdduvall cidp->chip_label = 5721; 21171908Sly149593 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 21181908Sly149593 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 21191908Sly149593 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 21201369Sdduvall cidp->mbuf_base = bge_mbuf_pool_base_5721; 21211369Sdduvall cidp->mbuf_length = bge_mbuf_pool_len_5721; 21221369Sdduvall cidp->recv_slots = BGE_RECV_SLOTS_5721; 21231369Sdduvall cidp->bge_dma_rwctrl = bge_dma_rwctrl_5721; 21241369Sdduvall cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 21251908Sly149593 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 21261369Sdduvall cidp->pci_type = BGE_PCI_E; 21271369Sdduvall cidp->statistic_type = BGE_STAT_REG; 21281369Sdduvall cidp->flags |= CHIP_FLAG_NO_JUMBO; 21291369Sdduvall dev_ok = B_TRUE; 21301369Sdduvall break; 21311369Sdduvall 2132*7316SCrisson.Hu@Sun.COM case DEVICE_ID_5722: 2133*7316SCrisson.Hu@Sun.COM cidp->chip_label = 5722; 2134*7316SCrisson.Hu@Sun.COM cidp->pci_type = BGE_PCI_E; 2135*7316SCrisson.Hu@Sun.COM cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 2136*7316SCrisson.Hu@Sun.COM cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 2137*7316SCrisson.Hu@Sun.COM cidp->mbuf_hi_water = MBUF_HIWAT_5705; 2138*7316SCrisson.Hu@Sun.COM cidp->mbuf_base = bge_mbuf_pool_base_5705; 2139*7316SCrisson.Hu@Sun.COM cidp->mbuf_length = bge_mbuf_pool_len_5705; 2140*7316SCrisson.Hu@Sun.COM cidp->recv_slots = BGE_RECV_SLOTS_5705; 2141*7316SCrisson.Hu@Sun.COM cidp->bge_mlcr_default |= MLCR_MISC_PINS_OUTPUT_ENABLE_1; 2142*7316SCrisson.Hu@Sun.COM cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 2143*7316SCrisson.Hu@Sun.COM cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 2144*7316SCrisson.Hu@Sun.COM cidp->flags |= CHIP_FLAG_NO_JUMBO; 2145*7316SCrisson.Hu@Sun.COM cidp->statistic_type = BGE_STAT_REG; 2146*7316SCrisson.Hu@Sun.COM dev_ok = B_TRUE; 2147*7316SCrisson.Hu@Sun.COM break; 2148*7316SCrisson.Hu@Sun.COM 21491369Sdduvall case DEVICE_ID_5751: 21501369Sdduvall case DEVICE_ID_5751M: 21511369Sdduvall cidp->chip_label = 5751; 21521908Sly149593 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 21531908Sly149593 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 21541908Sly149593 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 21551369Sdduvall cidp->mbuf_base = bge_mbuf_pool_base_5721; 21561369Sdduvall cidp->mbuf_length = bge_mbuf_pool_len_5721; 21571369Sdduvall cidp->recv_slots = BGE_RECV_SLOTS_5721; 21581369Sdduvall cidp->bge_dma_rwctrl = bge_dma_rwctrl_5721; 21591369Sdduvall cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 21601908Sly149593 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 21611369Sdduvall cidp->pci_type = BGE_PCI_E; 21621369Sdduvall cidp->statistic_type = BGE_STAT_REG; 21631369Sdduvall cidp->flags |= CHIP_FLAG_NO_JUMBO; 21641369Sdduvall dev_ok = B_TRUE; 21651369Sdduvall break; 21661369Sdduvall 21672675Szh199473 case DEVICE_ID_5752: 21682675Szh199473 case DEVICE_ID_5752M: 21692675Szh199473 cidp->chip_label = 5752; 21702675Szh199473 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 21712675Szh199473 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 21722675Szh199473 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 21732675Szh199473 cidp->mbuf_base = bge_mbuf_pool_base_5721; 21742675Szh199473 cidp->mbuf_length = bge_mbuf_pool_len_5721; 21752675Szh199473 cidp->recv_slots = BGE_RECV_SLOTS_5721; 21762675Szh199473 cidp->bge_dma_rwctrl = bge_dma_rwctrl_5721; 21772675Szh199473 cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 21782675Szh199473 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 21792675Szh199473 cidp->pci_type = BGE_PCI_E; 21802675Szh199473 cidp->statistic_type = BGE_STAT_REG; 21812675Szh199473 cidp->flags |= CHIP_FLAG_NO_JUMBO; 21822675Szh199473 dev_ok = B_TRUE; 21832675Szh199473 break; 21842675Szh199473 21852135Szh199473 case DEVICE_ID_5789: 21862135Szh199473 cidp->chip_label = 5789; 21872135Szh199473 cidp->mbuf_base = bge_mbuf_pool_base_5721; 21882135Szh199473 cidp->mbuf_length = bge_mbuf_pool_len_5721; 21892135Szh199473 cidp->recv_slots = BGE_RECV_SLOTS_5721; 21902135Szh199473 cidp->bge_dma_rwctrl = bge_dma_rwctrl_5721; 21912135Szh199473 cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 21922135Szh199473 cidp->tx_rings = BGE_RECV_RINGS_MAX_5705; 21932135Szh199473 cidp->pci_type = BGE_PCI_E; 21942135Szh199473 cidp->statistic_type = BGE_STAT_REG; 21952135Szh199473 cidp->flags |= CHIP_FLAG_PARTIAL_CSUM; 21962135Szh199473 cidp->flags |= CHIP_FLAG_NO_JUMBO; 21972135Szh199473 cidp->msi_enabled = B_TRUE; 21982135Szh199473 dev_ok = B_TRUE; 21992135Szh199473 break; 22002135Szh199473 22011369Sdduvall } 22021369Sdduvall 22031369Sdduvall /* 22041369Sdduvall * Setup the default jumbo parameter. 22051369Sdduvall */ 22061369Sdduvall cidp->ethmax_size = ETHERMAX; 22071369Sdduvall cidp->snd_buff_size = BGE_SEND_BUFF_SIZE_DEFAULT; 22081908Sly149593 cidp->std_buf_size = BGE_STD_BUFF_SIZE; 22091369Sdduvall 22101369Sdduvall /* 22111369Sdduvall * If jumbo is enabled and this kind of chipset supports jumbo feature, 22121369Sdduvall * setup below jumbo specific parameters. 22131908Sly149593 * 22141908Sly149593 * For BCM5714/5715, there is only one standard receive ring. So the 22151908Sly149593 * std buffer size should be set to BGE_JUMBO_BUFF_SIZE when jumbo 22161908Sly149593 * feature is enabled. 22171369Sdduvall */ 22181369Sdduvall if (bge_jumbo_enable && 22191369Sdduvall !(cidp->flags & CHIP_FLAG_NO_JUMBO) && 22201369Sdduvall (cidp->default_mtu > BGE_DEFAULT_MTU) && 22211369Sdduvall (cidp->default_mtu <= BGE_MAXIMUM_MTU)) { 22224588Sml149210 if (DEVICE_5714_SERIES_CHIPSETS(bgep)) { 22231908Sly149593 cidp->mbuf_lo_water_rdma = 22241908Sly149593 RDMA_MBUF_LOWAT_5714_JUMBO; 22251908Sly149593 cidp->mbuf_lo_water_rmac = 22261908Sly149593 MAC_RX_MBUF_LOWAT_5714_JUMBO; 22271908Sly149593 cidp->mbuf_hi_water = MBUF_HIWAT_5714_JUMBO; 22281908Sly149593 cidp->jumbo_slots = 0; 22291908Sly149593 cidp->std_buf_size = BGE_JUMBO_BUFF_SIZE; 22304588Sml149210 } else { 22311908Sly149593 cidp->mbuf_lo_water_rdma = 22321908Sly149593 RDMA_MBUF_LOWAT_JUMBO; 22331908Sly149593 cidp->mbuf_lo_water_rmac = 22341908Sly149593 MAC_RX_MBUF_LOWAT_JUMBO; 22351908Sly149593 cidp->mbuf_hi_water = MBUF_HIWAT_JUMBO; 22361908Sly149593 cidp->jumbo_slots = BGE_JUMBO_SLOTS_USED; 22371908Sly149593 } 22381369Sdduvall cidp->recv_jumbo_size = BGE_JUMBO_BUFF_SIZE; 22391369Sdduvall cidp->snd_buff_size = BGE_SEND_BUFF_SIZE_JUMBO; 22401369Sdduvall cidp->ethmax_size = cidp->default_mtu + 22411369Sdduvall sizeof (struct ether_header); 22421369Sdduvall } 22431369Sdduvall 22441369Sdduvall /* 22451369Sdduvall * Identify the NV memory type: SEEPROM or Flash? 22461369Sdduvall */ 22471369Sdduvall cidp->nvtype = bge_nvmem_id(bgep); 22481369Sdduvall 22491369Sdduvall /* 22501369Sdduvall * Now, we want to check whether this device is part of a 22511369Sdduvall * supported subsystem (e.g., on the motherboard of a Sun 22521369Sdduvall * branded platform). 22531369Sdduvall * 22541369Sdduvall * Rule 1: If the Subsystem Vendor ID is "Sun", then it's OK ;-) 22551369Sdduvall */ 22561369Sdduvall if (cidp->subven == VENDOR_ID_SUN) 22571369Sdduvall sys_ok = B_TRUE; 22581369Sdduvall 22591369Sdduvall /* 22601369Sdduvall * Rule 2: If it's on the list on known subsystems, then it's OK. 22611369Sdduvall * Note: 0x14e41647 should *not* appear in the list, but the code 22621369Sdduvall * doesn't enforce that. 22631369Sdduvall */ 22641369Sdduvall err = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, bgep->devinfo, 22654588Sml149210 DDI_PROP_DONTPASS, knownids_propname, &ids, &i); 22661369Sdduvall if (err == DDI_PROP_SUCCESS) { 22671369Sdduvall /* 22681369Sdduvall * Got the list; scan for a matching subsystem vendor/device 22691369Sdduvall */ 22701369Sdduvall subid = (cidp->subven << 16) | cidp->subdev; 22711369Sdduvall while (i--) 22721369Sdduvall if (ids[i] == subid) 22731369Sdduvall sys_ok = B_TRUE; 22741369Sdduvall ddi_prop_free(ids); 22751369Sdduvall } 22761369Sdduvall 22771369Sdduvall /* 22781369Sdduvall * Rule 3: If it's a Taco/ENWS motherboard device, then it's OK 22791369Sdduvall * 22801369Sdduvall * Unfortunately, early SunBlade 1500s and 2500s didn't reprogram 22811369Sdduvall * the Subsystem Vendor ID, so it defaults to Broadcom. Therefore, 22821369Sdduvall * we have to check specially for the exact device paths to the 22831369Sdduvall * motherboard devices on those platforms ;-( 22841369Sdduvall * 22851369Sdduvall * Note: we can't just use the "supported-subsystems" mechanism 22861369Sdduvall * above, because the entry would have to be 0x14e41647 -- which 22871369Sdduvall * would then accept *any* plugin card that *didn't* contain a 22881369Sdduvall * (valid) SEEPROM ;-( 22891369Sdduvall */ 22901369Sdduvall sysname = ddi_node_name(ddi_root_node()); 22911369Sdduvall devname = ddi_pathname(bgep->devinfo, buf); 22921369Sdduvall ASSERT(strlen(devname) > 0); 22931369Sdduvall if (strcmp(sysname, "SUNW,Sun-Blade-1500") == 0) /* Taco */ 22941369Sdduvall if (strcmp(devname, "/pci@1f,700000/network@2") == 0) 22951369Sdduvall sys_ok = B_TRUE; 22961369Sdduvall if (strcmp(sysname, "SUNW,Sun-Blade-2500") == 0) /* ENWS */ 22971369Sdduvall if (strcmp(devname, "/pci@1c,600000/network@3") == 0) 22981369Sdduvall sys_ok = B_TRUE; 22991369Sdduvall 23001369Sdduvall /* 23011369Sdduvall * Now check what we've discovered: is this truly a supported 23021369Sdduvall * chip on (the motherboard of) a supported platform? 23031369Sdduvall * 23041369Sdduvall * Possible problems here: 23051369Sdduvall * 1) it's a completely unheard-of chip (e.g. 5761) 23061369Sdduvall * 2) it's a recognised but unsupported chip (e.g. 5701, 5703C-A0) 23071369Sdduvall * 3) it's a chip we would support if it were on the motherboard 23081369Sdduvall * of a Sun platform, but this one isn't ;-( 23091369Sdduvall */ 23101369Sdduvall if (cidp->chip_label == 0) 23111369Sdduvall bge_problem(bgep, 23124588Sml149210 "Device 'pci%04x,%04x' not recognized (%d?)", 23134588Sml149210 cidp->vendor, cidp->device, cidp->device); 23141369Sdduvall else if (!dev_ok) 23151369Sdduvall bge_problem(bgep, 23164588Sml149210 "Device 'pci%04x,%04x' (%d) revision %d not supported", 23174588Sml149210 cidp->vendor, cidp->device, cidp->chip_label, 23184588Sml149210 cidp->revision); 23191369Sdduvall #if BGE_DEBUGGING 23201369Sdduvall else if (!sys_ok) 23211369Sdduvall bge_problem(bgep, 23224588Sml149210 "%d-based subsystem 'pci%04x,%04x' not validated", 23234588Sml149210 cidp->chip_label, cidp->subven, cidp->subdev); 23241369Sdduvall #endif 23251369Sdduvall else 23261369Sdduvall cidp->flags |= CHIP_FLAG_SUPPORTED; 23271865Sdilpreet if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) 23281865Sdilpreet return (EIO); 23291865Sdilpreet return (0); 23301369Sdduvall } 23311369Sdduvall 23321369Sdduvall void 23331369Sdduvall bge_chip_msi_trig(bge_t *bgep) 23341369Sdduvall { 23351369Sdduvall uint32_t regval; 23361369Sdduvall 23371369Sdduvall regval = bgep->param_msi_cnt<<4; 23381369Sdduvall bge_reg_set32(bgep, HOST_COALESCE_MODE_REG, regval); 23391369Sdduvall BGE_DEBUG(("bge_chip_msi_trig:data = %d", regval)); 23401369Sdduvall } 23411369Sdduvall 23421369Sdduvall /* 23431369Sdduvall * Various registers that control the chip's internal engines (state 23441369Sdduvall * machines) have a <reset> and <enable> bits (fortunately, in the 23451369Sdduvall * same place in each such register :-). 23461369Sdduvall * 23471369Sdduvall * To reset the state machine, the <reset> bit must be written with 1; 23481369Sdduvall * it will then read back as 1 while the reset is in progress, but 23491369Sdduvall * self-clear to 0 when the reset completes. 23501369Sdduvall * 23511369Sdduvall * To enable a state machine, one must set the <enable> bit, which 23521369Sdduvall * will continue to read back as 0 until the state machine is running. 23531369Sdduvall * 23541369Sdduvall * To disable a state machine, the <enable> bit must be cleared, but 23551369Sdduvall * it will continue to read back as 1 until the state machine actually 23561369Sdduvall * stops. 23571369Sdduvall * 23581369Sdduvall * This routine implements polling for completion of a reset, enable 23591369Sdduvall * or disable operation, returning B_TRUE on success (bit reached the 23601369Sdduvall * required state) or B_FALSE on timeout (200*100us == 20ms). 23611369Sdduvall */ 23621369Sdduvall static boolean_t bge_chip_poll_engine(bge_t *bgep, bge_regno_t regno, 23631369Sdduvall uint32_t mask, uint32_t val); 23641369Sdduvall #pragma no_inline(bge_chip_poll_engine) 23651369Sdduvall 23661369Sdduvall static boolean_t 23671369Sdduvall bge_chip_poll_engine(bge_t *bgep, bge_regno_t regno, 23681369Sdduvall uint32_t mask, uint32_t val) 23691369Sdduvall { 23701369Sdduvall uint32_t regval; 23711369Sdduvall uint32_t n; 23721369Sdduvall 23731369Sdduvall BGE_TRACE(("bge_chip_poll_engine($%p, 0x%lx, 0x%x, 0x%x)", 23744588Sml149210 (void *)bgep, regno, mask, val)); 23751369Sdduvall 23761369Sdduvall for (n = 200; n; --n) { 23771369Sdduvall regval = bge_reg_get32(bgep, regno); 23781369Sdduvall if ((regval & mask) == val) 23791369Sdduvall return (B_TRUE); 23801369Sdduvall drv_usecwait(100); 23811369Sdduvall } 23821369Sdduvall 23831865Sdilpreet bge_fm_ereport(bgep, DDI_FM_DEVICE_NO_RESPONSE); 23841369Sdduvall return (B_FALSE); 23851369Sdduvall } 23861369Sdduvall 23871369Sdduvall /* 23881369Sdduvall * Various registers that control the chip's internal engines (state 23891369Sdduvall * machines) have a <reset> bit (fortunately, in the same place in 23901369Sdduvall * each such register :-). To reset the state machine, this bit must 23911369Sdduvall * be written with 1; it will then read back as 1 while the reset is 23921369Sdduvall * in progress, but self-clear to 0 when the reset completes. 23931369Sdduvall * 23941369Sdduvall * This code sets the bit, then polls for it to read back as zero. 23951369Sdduvall * The return value is B_TRUE on success (reset bit cleared itself), 23961369Sdduvall * or B_FALSE if the state machine didn't recover :( 23971369Sdduvall * 23981369Sdduvall * NOTE: the Core reset is similar to other resets, except that we 23991369Sdduvall * can't poll for completion, since the Core reset disables memory 24001369Sdduvall * access! So we just have to assume that it will all complete in 24011369Sdduvall * 100us. See Broadcom document 570X-PG102-R, p102, steps 4-5. 24021369Sdduvall */ 24031369Sdduvall static boolean_t bge_chip_reset_engine(bge_t *bgep, bge_regno_t regno); 24041369Sdduvall #pragma no_inline(bge_chip_reset_engine) 24051369Sdduvall 24061369Sdduvall static boolean_t 24071369Sdduvall bge_chip_reset_engine(bge_t *bgep, bge_regno_t regno) 24081369Sdduvall { 24091369Sdduvall uint32_t regval; 24101369Sdduvall uint32_t val32; 24111369Sdduvall 24121369Sdduvall regval = bge_reg_get32(bgep, regno); 24131369Sdduvall 24141369Sdduvall BGE_TRACE(("bge_chip_reset_engine($%p, 0x%lx)", 24154588Sml149210 (void *)bgep, regno)); 24161369Sdduvall BGE_DEBUG(("bge_chip_reset_engine: 0x%lx before reset = 0x%08x", 24174588Sml149210 regno, regval)); 24181369Sdduvall 24191369Sdduvall regval |= STATE_MACHINE_RESET_BIT; 24201369Sdduvall 24211369Sdduvall switch (regno) { 24221369Sdduvall case MISC_CONFIG_REG: 24231369Sdduvall /* 24241369Sdduvall * BCM5714/5721/5751 pcie chip special case. In order to avoid 24251369Sdduvall * resetting PCIE block and bringing PCIE link down, bit 29 24261369Sdduvall * in the register needs to be set first, and then set it again 24271369Sdduvall * while the reset bit is written. 24281369Sdduvall * See:P500 of 57xx-PG102-RDS.pdf. 24291369Sdduvall */ 24301369Sdduvall if (DEVICE_5705_SERIES_CHIPSETS(bgep)|| 24311369Sdduvall DEVICE_5721_SERIES_CHIPSETS(bgep)|| 24321369Sdduvall DEVICE_5714_SERIES_CHIPSETS(bgep)) { 24331369Sdduvall regval |= MISC_CONFIG_GPHY_POWERDOWN_OVERRIDE; 24341369Sdduvall if (bgep->chipid.pci_type == BGE_PCI_E) { 24351369Sdduvall if (bgep->chipid.asic_rev == 24361369Sdduvall MHCR_CHIP_REV_5751_A0 || 24371369Sdduvall bgep->chipid.asic_rev == 24384330Sml149210 MHCR_CHIP_REV_5721_A0 || 24394330Sml149210 bgep->chipid.asic_rev == 24404330Sml149210 MHCR_CHIP_REV_5755_A0) { 24411369Sdduvall val32 = bge_reg_get32(bgep, 24421369Sdduvall PHY_TEST_CTRL_REG); 24431369Sdduvall if (val32 == (PHY_PCIE_SCRAM_MODE | 24441369Sdduvall PHY_PCIE_LTASS_MODE)) 24451369Sdduvall bge_reg_put32(bgep, 24461369Sdduvall PHY_TEST_CTRL_REG, 24471369Sdduvall PHY_PCIE_SCRAM_MODE); 24481369Sdduvall val32 = pci_config_get32 24491369Sdduvall (bgep->cfg_handle, 24501369Sdduvall PCI_CONF_BGE_CLKCTL); 24511369Sdduvall val32 |= CLKCTL_PCIE_A0_FIX; 24521369Sdduvall pci_config_put32(bgep->cfg_handle, 24531369Sdduvall PCI_CONF_BGE_CLKCTL, val32); 24541369Sdduvall } 24551369Sdduvall bge_reg_set32(bgep, regno, 24564588Sml149210 MISC_CONFIG_GRC_RESET_DISABLE); 24571369Sdduvall regval |= MISC_CONFIG_GRC_RESET_DISABLE; 24581369Sdduvall } 24591369Sdduvall } 24601369Sdduvall 24611369Sdduvall /* 24621369Sdduvall * Special case - causes Core reset 24631369Sdduvall * 24641369Sdduvall * On SPARC v9 we want to ensure that we don't start 24651369Sdduvall * timing until the I/O access has actually reached 24661369Sdduvall * the chip, otherwise we might make the next access 24671369Sdduvall * too early. And we can't just force the write out 24681369Sdduvall * by following it with a read (even to config space) 24691369Sdduvall * because that would cause the fault we're trying 24701369Sdduvall * to avoid. Hence the need for membar_sync() here. 24711369Sdduvall */ 24721369Sdduvall ddi_put32(bgep->io_handle, PIO_ADDR(bgep, regno), regval); 24731369Sdduvall #ifdef __sparcv9 24741369Sdduvall membar_sync(); 24751369Sdduvall #endif /* __sparcv9 */ 24761369Sdduvall /* 24771369Sdduvall * On some platforms,system need about 300us for 24781369Sdduvall * link setup. 24791369Sdduvall */ 24801369Sdduvall drv_usecwait(300); 24811369Sdduvall 24821369Sdduvall if (bgep->chipid.pci_type == BGE_PCI_E) { 24831369Sdduvall /* PCI-E device need more reset time */ 24841369Sdduvall drv_usecwait(120000); 24851369Sdduvall 24861369Sdduvall /* Set PCIE max payload size and clear error status. */ 24872135Szh199473 if ((bgep->chipid.chip_label == 5721) || 24882135Szh199473 (bgep->chipid.chip_label == 5751) || 24892675Szh199473 (bgep->chipid.chip_label == 5752) || 24902135Szh199473 (bgep->chipid.chip_label == 5789)) { 24911369Sdduvall pci_config_put16(bgep->cfg_handle, 24924588Sml149210 PCI_CONF_DEV_CTRL, READ_REQ_SIZE_MAX); 24931369Sdduvall pci_config_put16(bgep->cfg_handle, 24944588Sml149210 PCI_CONF_DEV_STUS, DEVICE_ERROR_STUS); 24951369Sdduvall } 24961369Sdduvall } 24971369Sdduvall 24981369Sdduvall BGE_PCICHK(bgep); 24991369Sdduvall return (B_TRUE); 25001369Sdduvall 25011369Sdduvall default: 25021369Sdduvall bge_reg_put32(bgep, regno, regval); 25031369Sdduvall return (bge_chip_poll_engine(bgep, regno, 25041865Sdilpreet STATE_MACHINE_RESET_BIT, 0)); 25051369Sdduvall } 25061369Sdduvall } 25071369Sdduvall 25081369Sdduvall /* 25091369Sdduvall * Various registers that control the chip's internal engines (state 25101369Sdduvall * machines) have an <enable> bit (fortunately, in the same place in 25111369Sdduvall * each such register :-). To stop the state machine, this bit must 25121369Sdduvall * be written with 0, then polled to see when the state machine has 25131369Sdduvall * actually stopped. 25141369Sdduvall * 25151369Sdduvall * The return value is B_TRUE on success (enable bit cleared), or 25161369Sdduvall * B_FALSE if the state machine didn't stop :( 25171369Sdduvall */ 25181369Sdduvall static boolean_t bge_chip_disable_engine(bge_t *bgep, bge_regno_t regno, 25191369Sdduvall uint32_t morebits); 25201369Sdduvall #pragma no_inline(bge_chip_disable_engine) 25211369Sdduvall 25221369Sdduvall static boolean_t 25231369Sdduvall bge_chip_disable_engine(bge_t *bgep, bge_regno_t regno, uint32_t morebits) 25241369Sdduvall { 25251369Sdduvall uint32_t regval; 25261369Sdduvall 25271369Sdduvall BGE_TRACE(("bge_chip_disable_engine($%p, 0x%lx, 0x%x)", 25284588Sml149210 (void *)bgep, regno, morebits)); 25291369Sdduvall 25301369Sdduvall switch (regno) { 25311369Sdduvall case FTQ_RESET_REG: 25321369Sdduvall /* 25333918Sml149210 * For Schumacher's bugfix CR6490108 25343918Sml149210 */ 25353918Sml149210 #ifdef BGE_IPMI_ASF 25363918Sml149210 #ifdef BGE_NETCONSOLE 25373918Sml149210 if (bgep->asf_enabled) 25383918Sml149210 return (B_TRUE); 25393918Sml149210 #endif 25403918Sml149210 #endif 25413918Sml149210 /* 25421369Sdduvall * Not quite like the others; it doesn't 25431369Sdduvall * have an <enable> bit, but instead we 25441369Sdduvall * have to set and then clear all the bits 25451369Sdduvall */ 25461369Sdduvall bge_reg_put32(bgep, regno, ~(uint32_t)0); 25471369Sdduvall drv_usecwait(100); 25481369Sdduvall bge_reg_put32(bgep, regno, 0); 25491369Sdduvall return (B_TRUE); 25501369Sdduvall 25511369Sdduvall default: 25521369Sdduvall regval = bge_reg_get32(bgep, regno); 25531369Sdduvall regval &= ~STATE_MACHINE_ENABLE_BIT; 25541369Sdduvall regval &= ~morebits; 25551369Sdduvall bge_reg_put32(bgep, regno, regval); 25561369Sdduvall return (bge_chip_poll_engine(bgep, regno, 25571865Sdilpreet STATE_MACHINE_ENABLE_BIT, 0)); 25581369Sdduvall } 25591369Sdduvall } 25601369Sdduvall 25611369Sdduvall /* 25621369Sdduvall * Various registers that control the chip's internal engines (state 25631369Sdduvall * machines) have an <enable> bit (fortunately, in the same place in 25641369Sdduvall * each such register :-). To start the state machine, this bit must 25651369Sdduvall * be written with 1, then polled to see when the state machine has 25661369Sdduvall * actually started. 25671369Sdduvall * 25681369Sdduvall * The return value is B_TRUE on success (enable bit set), or 25691369Sdduvall * B_FALSE if the state machine didn't start :( 25701369Sdduvall */ 25711369Sdduvall static boolean_t bge_chip_enable_engine(bge_t *bgep, bge_regno_t regno, 25721369Sdduvall uint32_t morebits); 25731369Sdduvall #pragma no_inline(bge_chip_enable_engine) 25741369Sdduvall 25751369Sdduvall static boolean_t 25761369Sdduvall bge_chip_enable_engine(bge_t *bgep, bge_regno_t regno, uint32_t morebits) 25771369Sdduvall { 25781369Sdduvall uint32_t regval; 25791369Sdduvall 25801369Sdduvall BGE_TRACE(("bge_chip_enable_engine($%p, 0x%lx, 0x%x)", 25814588Sml149210 (void *)bgep, regno, morebits)); 25821369Sdduvall 25831369Sdduvall switch (regno) { 25841369Sdduvall case FTQ_RESET_REG: 25853918Sml149210 #ifdef BGE_IPMI_ASF 25863918Sml149210 #ifdef BGE_NETCONSOLE 25873918Sml149210 if (bgep->asf_enabled) 25883918Sml149210 return (B_TRUE); 25893918Sml149210 #endif 25903918Sml149210 #endif 25911369Sdduvall /* 25921369Sdduvall * Not quite like the others; it doesn't 25931369Sdduvall * have an <enable> bit, but instead we 25941369Sdduvall * have to set and then clear all the bits 25951369Sdduvall */ 25961369Sdduvall bge_reg_put32(bgep, regno, ~(uint32_t)0); 25971369Sdduvall drv_usecwait(100); 25981369Sdduvall bge_reg_put32(bgep, regno, 0); 25991369Sdduvall return (B_TRUE); 26001369Sdduvall 26011369Sdduvall default: 26021369Sdduvall regval = bge_reg_get32(bgep, regno); 26031369Sdduvall regval |= STATE_MACHINE_ENABLE_BIT; 26041369Sdduvall regval |= morebits; 26051369Sdduvall bge_reg_put32(bgep, regno, regval); 26061369Sdduvall return (bge_chip_poll_engine(bgep, regno, 26071865Sdilpreet STATE_MACHINE_ENABLE_BIT, STATE_MACHINE_ENABLE_BIT)); 26081369Sdduvall } 26091369Sdduvall } 26101369Sdduvall 26111369Sdduvall /* 26121369Sdduvall * Reprogram the Ethernet, Transmit, and Receive MAC 26131369Sdduvall * modes to match the param_* variables 26141369Sdduvall */ 26155903Ssowmini void bge_sync_mac_modes(bge_t *bgep); 26161369Sdduvall #pragma no_inline(bge_sync_mac_modes) 26171369Sdduvall 26185903Ssowmini void 26191369Sdduvall bge_sync_mac_modes(bge_t *bgep) 26201369Sdduvall { 26211369Sdduvall uint32_t macmode; 26221369Sdduvall uint32_t regval; 26231369Sdduvall 26241369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 26251369Sdduvall 26261369Sdduvall /* 26271369Sdduvall * Reprogram the Ethernet MAC mode ... 26281369Sdduvall */ 26291369Sdduvall macmode = regval = bge_reg_get32(bgep, ETHERNET_MAC_MODE_REG); 26301369Sdduvall if ((bgep->chipid.flags & CHIP_FLAG_SERDES) && 26314588Sml149210 (bgep->param_loop_mode != BGE_LOOP_INTERNAL_MAC)) 26321369Sdduvall macmode &= ~ETHERNET_MODE_LINK_POLARITY; 26331369Sdduvall else 26341369Sdduvall macmode |= ETHERNET_MODE_LINK_POLARITY; 26351369Sdduvall macmode &= ~ETHERNET_MODE_PORTMODE_MASK; 26361369Sdduvall if ((bgep->chipid.flags & CHIP_FLAG_SERDES) && 26374588Sml149210 (bgep->param_loop_mode != BGE_LOOP_INTERNAL_MAC)) 26381369Sdduvall macmode |= ETHERNET_MODE_PORTMODE_TBI; 26391369Sdduvall else if (bgep->param_link_speed == 10 || bgep->param_link_speed == 100) 26401369Sdduvall macmode |= ETHERNET_MODE_PORTMODE_MII; 26411369Sdduvall else 26421369Sdduvall macmode |= ETHERNET_MODE_PORTMODE_GMII; 26431369Sdduvall if (bgep->param_link_duplex == LINK_DUPLEX_HALF) 26441369Sdduvall macmode |= ETHERNET_MODE_HALF_DUPLEX; 26451369Sdduvall else 26461369Sdduvall macmode &= ~ETHERNET_MODE_HALF_DUPLEX; 26471369Sdduvall if (bgep->param_loop_mode == BGE_LOOP_INTERNAL_MAC) 26481369Sdduvall macmode |= ETHERNET_MODE_MAC_LOOPBACK; 26491369Sdduvall else 26501369Sdduvall macmode &= ~ETHERNET_MODE_MAC_LOOPBACK; 26511369Sdduvall bge_reg_put32(bgep, ETHERNET_MAC_MODE_REG, macmode); 26521369Sdduvall BGE_DEBUG(("bge_sync_mac_modes($%p) Ethernet MAC mode 0x%x => 0x%x", 26534588Sml149210 (void *)bgep, regval, macmode)); 26541369Sdduvall 26551369Sdduvall /* 26561369Sdduvall * ... the Transmit MAC mode ... 26571369Sdduvall */ 26581369Sdduvall macmode = regval = bge_reg_get32(bgep, TRANSMIT_MAC_MODE_REG); 26591369Sdduvall if (bgep->param_link_tx_pause) 26601369Sdduvall macmode |= TRANSMIT_MODE_FLOW_CONTROL; 26611369Sdduvall else 26621369Sdduvall macmode &= ~TRANSMIT_MODE_FLOW_CONTROL; 26631369Sdduvall bge_reg_put32(bgep, TRANSMIT_MAC_MODE_REG, macmode); 26641369Sdduvall BGE_DEBUG(("bge_sync_mac_modes($%p) Transmit MAC mode 0x%x => 0x%x", 26654588Sml149210 (void *)bgep, regval, macmode)); 26661369Sdduvall 26671369Sdduvall /* 26681369Sdduvall * ... and the Receive MAC mode 26691369Sdduvall */ 26701369Sdduvall macmode = regval = bge_reg_get32(bgep, RECEIVE_MAC_MODE_REG); 26711369Sdduvall if (bgep->param_link_rx_pause) 26721369Sdduvall macmode |= RECEIVE_MODE_FLOW_CONTROL; 26731369Sdduvall else 26741369Sdduvall macmode &= ~RECEIVE_MODE_FLOW_CONTROL; 26751369Sdduvall bge_reg_put32(bgep, RECEIVE_MAC_MODE_REG, macmode); 26761369Sdduvall BGE_DEBUG(("bge_sync_mac_modes($%p) Receive MAC mode 0x%x => 0x%x", 26774588Sml149210 (void *)bgep, regval, macmode)); 26781369Sdduvall } 26791369Sdduvall 26801369Sdduvall /* 26811369Sdduvall * bge_chip_sync() -- program the chip with the unicast MAC address, 26821369Sdduvall * the multicast hash table, the required level of promiscuity, and 26831369Sdduvall * the current loopback mode ... 26841369Sdduvall */ 26851408Srandyf #ifdef BGE_IPMI_ASF 26861865Sdilpreet int bge_chip_sync(bge_t *bgep, boolean_t asf_keeplive); 26871408Srandyf #else 26881865Sdilpreet int bge_chip_sync(bge_t *bgep); 26891408Srandyf #endif 26901369Sdduvall #pragma no_inline(bge_chip_sync) 26911369Sdduvall 26921865Sdilpreet int 26931408Srandyf #ifdef BGE_IPMI_ASF 26941408Srandyf bge_chip_sync(bge_t *bgep, boolean_t asf_keeplive) 26951408Srandyf #else 26961369Sdduvall bge_chip_sync(bge_t *bgep) 26971408Srandyf #endif 26981369Sdduvall { 26991369Sdduvall void (*opfn)(bge_t *bgep, bge_regno_t reg, uint32_t bits); 27001369Sdduvall boolean_t promisc; 27011369Sdduvall uint64_t macaddr; 27021369Sdduvall uint32_t fill; 27032331Skrgopi int i, j; 27041865Sdilpreet int retval = DDI_SUCCESS; 27051369Sdduvall 27061369Sdduvall BGE_TRACE(("bge_chip_sync($%p)", 27075903Ssowmini (void *)bgep)); 27081369Sdduvall 27091369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 27101369Sdduvall 27111369Sdduvall promisc = B_FALSE; 27121369Sdduvall fill = ~(uint32_t)0; 27131369Sdduvall 27141369Sdduvall if (bgep->promisc) 27151369Sdduvall promisc = B_TRUE; 27161369Sdduvall else 27171369Sdduvall fill = (uint32_t)0; 27181369Sdduvall 27191369Sdduvall /* 27201369Sdduvall * If the TX/RX MAC engines are already running, we should stop 27211369Sdduvall * them (and reset the RX engine) before changing the parameters. 27221369Sdduvall * If they're not running, this will have no effect ... 27231369Sdduvall * 27241369Sdduvall * NOTE: this is currently disabled by default because stopping 27251369Sdduvall * and restarting the Tx engine may cause an outgoing packet in 27261369Sdduvall * transit to be truncated. Also, stopping and restarting the 27271369Sdduvall * Rx engine seems to not work correctly on the 5705. Testing 27281369Sdduvall * has not (yet!) revealed any problems with NOT stopping and 27291369Sdduvall * restarting these engines (and Broadcom say their drivers don't 27301369Sdduvall * do this), but if it is found to cause problems, this variable 27311369Sdduvall * can be patched to re-enable the old behaviour ... 27321369Sdduvall */ 27331369Sdduvall if (bge_stop_start_on_sync) { 27341408Srandyf #ifdef BGE_IPMI_ASF 27351865Sdilpreet if (!bgep->asf_enabled) { 27361865Sdilpreet if (!bge_chip_disable_engine(bgep, 27371865Sdilpreet RECEIVE_MAC_MODE_REG, RECEIVE_MODE_KEEP_VLAN_TAG)) 27381865Sdilpreet retval = DDI_FAILURE; 27391408Srandyf } else { 27401865Sdilpreet if (!bge_chip_disable_engine(bgep, 27411865Sdilpreet RECEIVE_MAC_MODE_REG, 0)) 27421865Sdilpreet retval = DDI_FAILURE; 27431408Srandyf } 27441408Srandyf #else 27451865Sdilpreet if (!bge_chip_disable_engine(bgep, RECEIVE_MAC_MODE_REG, 27461865Sdilpreet RECEIVE_MODE_KEEP_VLAN_TAG)) 27471865Sdilpreet retval = DDI_FAILURE; 27481408Srandyf #endif 27491865Sdilpreet if (!bge_chip_disable_engine(bgep, TRANSMIT_MAC_MODE_REG, 0)) 27501865Sdilpreet retval = DDI_FAILURE; 27511865Sdilpreet if (!bge_chip_reset_engine(bgep, RECEIVE_MAC_MODE_REG)) 27521865Sdilpreet retval = DDI_FAILURE; 27531369Sdduvall } 27541369Sdduvall 27551369Sdduvall /* 27561369Sdduvall * Reprogram the hashed multicast address table ... 27571369Sdduvall */ 27581369Sdduvall for (i = 0; i < BGE_HASH_TABLE_SIZE/32; ++i) 27596546Sgh162552 bge_reg_put32(bgep, MAC_HASH_REG(i), 0); 27606546Sgh162552 27616546Sgh162552 for (i = 0; i < BGE_HASH_TABLE_SIZE/32; ++i) 27621369Sdduvall bge_reg_put32(bgep, MAC_HASH_REG(i), 27631369Sdduvall bgep->mcast_hash[i] | fill); 27641369Sdduvall 27651408Srandyf #ifdef BGE_IPMI_ASF 27661408Srandyf if (!bgep->asf_enabled || !asf_keeplive) { 27671408Srandyf #endif 27681408Srandyf /* 27692331Skrgopi * Transform the MAC address(es) from host to chip format, then 27701408Srandyf * reprogram the transmit random backoff seed and the unicast 27711408Srandyf * MAC address(es) ... 27721408Srandyf */ 27732331Skrgopi for (j = 0; j < MAC_ADDRESS_REGS_MAX; j++) { 27742331Skrgopi for (i = 0, fill = 0, macaddr = 0ull; 27752331Skrgopi i < ETHERADDRL; ++i) { 27762331Skrgopi macaddr <<= 8; 27772331Skrgopi macaddr |= bgep->curr_addr[j].addr[i]; 27782331Skrgopi fill += bgep->curr_addr[j].addr[i]; 27792331Skrgopi } 27802331Skrgopi bge_reg_put32(bgep, MAC_TX_RANDOM_BACKOFF_REG, fill); 27812331Skrgopi bge_reg_put64(bgep, MAC_ADDRESS_REG(j), macaddr); 27821408Srandyf } 27831408Srandyf 27841408Srandyf BGE_DEBUG(("bge_chip_sync($%p) setting MAC address %012llx", 27851408Srandyf (void *)bgep, macaddr)); 27861408Srandyf #ifdef BGE_IPMI_ASF 27871369Sdduvall } 27881408Srandyf #endif 27891369Sdduvall 27901369Sdduvall /* 27911369Sdduvall * Set or clear the PROMISCUOUS mode bit 27921369Sdduvall */ 27931369Sdduvall opfn = promisc ? bge_reg_set32 : bge_reg_clr32; 27941369Sdduvall (*opfn)(bgep, RECEIVE_MAC_MODE_REG, RECEIVE_MODE_PROMISCUOUS); 27951369Sdduvall 27961369Sdduvall /* 27971369Sdduvall * Sync the rest of the MAC modes too ... 27981369Sdduvall */ 27991369Sdduvall bge_sync_mac_modes(bgep); 28001369Sdduvall 28011369Sdduvall /* 28021369Sdduvall * Restart RX/TX MAC engines if required ... 28031369Sdduvall */ 28041369Sdduvall if (bgep->bge_chip_state == BGE_CHIP_RUNNING) { 28051865Sdilpreet if (!bge_chip_enable_engine(bgep, TRANSMIT_MAC_MODE_REG, 0)) 28061865Sdilpreet retval = DDI_FAILURE; 28071408Srandyf #ifdef BGE_IPMI_ASF 28081865Sdilpreet if (!bgep->asf_enabled) { 28091865Sdilpreet if (!bge_chip_enable_engine(bgep, 28101865Sdilpreet RECEIVE_MAC_MODE_REG, RECEIVE_MODE_KEEP_VLAN_TAG)) 28111865Sdilpreet retval = DDI_FAILURE; 28121408Srandyf } else { 28131865Sdilpreet if (!bge_chip_enable_engine(bgep, 28141865Sdilpreet RECEIVE_MAC_MODE_REG, 0)) 28151865Sdilpreet retval = DDI_FAILURE; 28161408Srandyf } 28171408Srandyf #else 28181865Sdilpreet if (!bge_chip_enable_engine(bgep, RECEIVE_MAC_MODE_REG, 28191865Sdilpreet RECEIVE_MODE_KEEP_VLAN_TAG)) 28201865Sdilpreet retval = DDI_FAILURE; 28211408Srandyf #endif 28221369Sdduvall } 28231865Sdilpreet return (retval); 28241369Sdduvall } 28251369Sdduvall 28261369Sdduvall /* 28271369Sdduvall * This array defines the sequence of state machine control registers 28281369Sdduvall * in which the <enable> bit must be cleared to bring the chip to a 28291369Sdduvall * clean stop. Taken from Broadcom document 570X-PG102-R, p116. 28301369Sdduvall */ 28311369Sdduvall static bge_regno_t shutdown_engine_regs[] = { 28321369Sdduvall RECEIVE_MAC_MODE_REG, 28331369Sdduvall RCV_BD_INITIATOR_MODE_REG, 28341369Sdduvall RCV_LIST_PLACEMENT_MODE_REG, 28351369Sdduvall RCV_LIST_SELECTOR_MODE_REG, /* BCM5704 series only */ 28361369Sdduvall RCV_DATA_BD_INITIATOR_MODE_REG, 28371369Sdduvall RCV_DATA_COMPLETION_MODE_REG, 28381369Sdduvall RCV_BD_COMPLETION_MODE_REG, 28391369Sdduvall 28401369Sdduvall SEND_BD_SELECTOR_MODE_REG, 28411369Sdduvall SEND_BD_INITIATOR_MODE_REG, 28421369Sdduvall SEND_DATA_INITIATOR_MODE_REG, 28431369Sdduvall READ_DMA_MODE_REG, 28441369Sdduvall SEND_DATA_COMPLETION_MODE_REG, 28451369Sdduvall DMA_COMPLETION_MODE_REG, /* BCM5704 series only */ 28461369Sdduvall SEND_BD_COMPLETION_MODE_REG, 28471369Sdduvall TRANSMIT_MAC_MODE_REG, 28481369Sdduvall 28491369Sdduvall HOST_COALESCE_MODE_REG, 28501369Sdduvall WRITE_DMA_MODE_REG, 28511369Sdduvall MBUF_CLUSTER_FREE_MODE_REG, /* BCM5704 series only */ 28521369Sdduvall FTQ_RESET_REG, /* special - see code */ 28531369Sdduvall BUFFER_MANAGER_MODE_REG, /* BCM5704 series only */ 28541369Sdduvall MEMORY_ARBITER_MODE_REG, /* BCM5704 series only */ 28551369Sdduvall BGE_REGNO_NONE /* terminator */ 28561369Sdduvall }; 28571369Sdduvall 28581369Sdduvall /* 28591369Sdduvall * bge_chip_stop() -- stop all chip processing 28601369Sdduvall * 28611369Sdduvall * If the <fault> parameter is B_TRUE, we're stopping the chip because 28621369Sdduvall * we've detected a problem internally; otherwise, this is a normal 28631369Sdduvall * (clean) stop (at user request i.e. the last STREAM has been closed). 28641369Sdduvall */ 28651369Sdduvall void bge_chip_stop(bge_t *bgep, boolean_t fault); 28661369Sdduvall #pragma no_inline(bge_chip_stop) 28671369Sdduvall 28681369Sdduvall void 28691369Sdduvall bge_chip_stop(bge_t *bgep, boolean_t fault) 28701369Sdduvall { 28711369Sdduvall bge_regno_t regno; 28721369Sdduvall bge_regno_t *rbp; 28731369Sdduvall boolean_t ok; 28741369Sdduvall 28751369Sdduvall BGE_TRACE(("bge_chip_stop($%p)", 28764588Sml149210 (void *)bgep)); 28771369Sdduvall 28781369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 28791369Sdduvall 28801369Sdduvall rbp = shutdown_engine_regs; 28811369Sdduvall /* 28821369Sdduvall * When driver try to shutdown the BCM5705/5788/5721/5751/ 28831369Sdduvall * 5752/5714 and 5715 chipsets,the buffer manager and the mem 28841369Sdduvall * -ory arbiter should not be disabled. 28851369Sdduvall */ 28861369Sdduvall for (ok = B_TRUE; (regno = *rbp) != BGE_REGNO_NONE; ++rbp) { 28871369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) 28884588Sml149210 ok &= bge_chip_disable_engine(bgep, regno, 0); 28891369Sdduvall else if ((regno != RCV_LIST_SELECTOR_MODE_REG) && 28904588Sml149210 (regno != DMA_COMPLETION_MODE_REG) && 28914588Sml149210 (regno != MBUF_CLUSTER_FREE_MODE_REG)&& 28924588Sml149210 (regno != BUFFER_MANAGER_MODE_REG) && 28934588Sml149210 (regno != MEMORY_ARBITER_MODE_REG)) 28944588Sml149210 ok &= bge_chip_disable_engine(bgep, 28954588Sml149210 regno, 0); 28961369Sdduvall } 28971369Sdduvall 28981865Sdilpreet if (!ok && !fault) 28991865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_UNAFFECTED); 29001865Sdilpreet 29011369Sdduvall /* 29021369Sdduvall * Finally, disable (all) MAC events & clear the MAC status 29031369Sdduvall */ 29041369Sdduvall bge_reg_put32(bgep, ETHERNET_MAC_EVENT_ENABLE_REG, 0); 29051369Sdduvall bge_reg_put32(bgep, ETHERNET_MAC_STATUS_REG, ~0); 29061369Sdduvall 29071369Sdduvall /* 29081865Sdilpreet * if we're stopping the chip because of a detected fault then do 29091865Sdilpreet * appropriate actions 29101369Sdduvall */ 29111865Sdilpreet if (fault) { 29121865Sdilpreet if (bgep->bge_chip_state != BGE_CHIP_FAULT) { 29131865Sdilpreet bgep->bge_chip_state = BGE_CHIP_FAULT; 29145903Ssowmini if (!bgep->manual_reset) 29155903Ssowmini ddi_fm_service_impact(bgep->devinfo, 29165903Ssowmini DDI_SERVICE_LOST); 29171865Sdilpreet if (bgep->bge_dma_error) { 29181865Sdilpreet /* 29191865Sdilpreet * need to free buffers in case the fault was 29201865Sdilpreet * due to a memory error in a buffer - got to 29211865Sdilpreet * do a fair bit of tidying first 29221865Sdilpreet */ 29231865Sdilpreet if (bgep->progress & PROGRESS_KSTATS) { 29241865Sdilpreet bge_fini_kstats(bgep); 29251865Sdilpreet bgep->progress &= ~PROGRESS_KSTATS; 29261865Sdilpreet } 29271865Sdilpreet if (bgep->progress & PROGRESS_INTR) { 29281865Sdilpreet bge_intr_disable(bgep); 29291865Sdilpreet rw_enter(bgep->errlock, RW_WRITER); 29301865Sdilpreet bge_fini_rings(bgep); 29311865Sdilpreet rw_exit(bgep->errlock); 29321865Sdilpreet bgep->progress &= ~PROGRESS_INTR; 29331865Sdilpreet } 29341865Sdilpreet if (bgep->progress & PROGRESS_BUFS) { 29351865Sdilpreet bge_free_bufs(bgep); 29361865Sdilpreet bgep->progress &= ~PROGRESS_BUFS; 29371865Sdilpreet } 29381865Sdilpreet bgep->bge_dma_error = B_FALSE; 29391865Sdilpreet } 29401865Sdilpreet } 29411865Sdilpreet } else 29421369Sdduvall bgep->bge_chip_state = BGE_CHIP_STOPPED; 29431369Sdduvall } 29441369Sdduvall 29451369Sdduvall /* 29461369Sdduvall * Poll for completion of chip's ROM firmware; also, at least on the 29471369Sdduvall * first time through, find and return the hardware MAC address, if any. 29481369Sdduvall */ 29491369Sdduvall static uint64_t bge_poll_firmware(bge_t *bgep); 29501369Sdduvall #pragma no_inline(bge_poll_firmware) 29511369Sdduvall 29521369Sdduvall static uint64_t 29531369Sdduvall bge_poll_firmware(bge_t *bgep) 29541369Sdduvall { 29551369Sdduvall uint64_t magic; 29561369Sdduvall uint64_t mac; 29571369Sdduvall uint32_t gen; 29581369Sdduvall uint32_t i; 29591369Sdduvall 29601369Sdduvall /* 29611369Sdduvall * Step 19: poll for firmware completion (GENCOMM port set 29621369Sdduvall * to the ones complement of T3_MAGIC_NUMBER). 29631369Sdduvall * 29641369Sdduvall * While we're at it, we also read the MAC address register; 29652135Szh199473 * at some stage the firmware will load this with the 29661369Sdduvall * factory-set value. 29671369Sdduvall * 29681369Sdduvall * When both the magic number and the MAC address are set, 29691369Sdduvall * we're done; but we impose a time limit of one second 29701369Sdduvall * (1000*1000us) in case the firmware fails in some fashion 29711369Sdduvall * or the SEEPROM that provides that MAC address isn't fitted. 29721369Sdduvall * 29731369Sdduvall * After the first time through (chip state != INITIAL), we 29741369Sdduvall * don't need the MAC address to be set (we've already got it 29751369Sdduvall * or not, from the first time), so we don't wait for it, but 29761369Sdduvall * we still have to wait for the T3_MAGIC_NUMBER. 29771369Sdduvall * 29781369Sdduvall * Note: the magic number is only a 32-bit quantity, but the NIC 29791369Sdduvall * memory is 64-bit (and big-endian) internally. Addressing the 29801369Sdduvall * GENCOMM word as "the upper half of a 64-bit quantity" makes 29811369Sdduvall * it work correctly on both big- and little-endian hosts. 29821369Sdduvall */ 29831369Sdduvall for (i = 0; i < 1000; ++i) { 29841369Sdduvall drv_usecwait(1000); 29851369Sdduvall gen = bge_nic_get64(bgep, NIC_MEM_GENCOMM) >> 32; 29867217Sgh162552 if (i == 0 && DEVICE_5704_SERIES_CHIPSETS(bgep)) 29877125Sgh162552 drv_usecwait(100000); 29881369Sdduvall mac = bge_reg_get64(bgep, MAC_ADDRESS_REG(0)); 29891408Srandyf #ifdef BGE_IPMI_ASF 29901408Srandyf if (!bgep->asf_enabled) { 29911408Srandyf #endif 29921408Srandyf if (gen != ~T3_MAGIC_NUMBER) 29931408Srandyf continue; 29941408Srandyf #ifdef BGE_IPMI_ASF 29951408Srandyf } 29961408Srandyf #endif 29971369Sdduvall if (mac != 0ULL) 29981369Sdduvall break; 29991369Sdduvall if (bgep->bge_chip_state != BGE_CHIP_INITIAL) 30001369Sdduvall break; 30011369Sdduvall } 30021369Sdduvall 30031369Sdduvall magic = bge_nic_get64(bgep, NIC_MEM_GENCOMM); 30041369Sdduvall BGE_DEBUG(("bge_poll_firmware($%p): PXE magic 0x%x after %d loops", 30054588Sml149210 (void *)bgep, gen, i)); 30061369Sdduvall BGE_DEBUG(("bge_poll_firmware: MAC %016llx, GENCOMM %016llx", 30074588Sml149210 mac, magic)); 30081369Sdduvall 30091369Sdduvall return (mac); 30101369Sdduvall } 30111369Sdduvall 30123390Szh199473 /* 30133390Szh199473 * Maximum times of trying to get the NVRAM access lock 30143390Szh199473 * by calling bge_nvmem_acquire() 30153390Szh199473 */ 30163390Szh199473 #define MAX_TRY_NVMEM_ACQUIRE 10000 30173390Szh199473 30181408Srandyf #ifdef BGE_IPMI_ASF 30191865Sdilpreet int bge_chip_reset(bge_t *bgep, boolean_t enable_dma, uint_t asf_mode); 30201408Srandyf #else 30211865Sdilpreet int bge_chip_reset(bge_t *bgep, boolean_t enable_dma); 30221408Srandyf #endif 30231369Sdduvall #pragma no_inline(bge_chip_reset) 30241369Sdduvall 30251865Sdilpreet int 30261408Srandyf #ifdef BGE_IPMI_ASF 30271408Srandyf bge_chip_reset(bge_t *bgep, boolean_t enable_dma, uint_t asf_mode) 30281408Srandyf #else 30291369Sdduvall bge_chip_reset(bge_t *bgep, boolean_t enable_dma) 30301408Srandyf #endif 30311369Sdduvall { 30321369Sdduvall chip_id_t chipid; 30331369Sdduvall uint64_t mac; 30341908Sly149593 uint64_t magic; 30351369Sdduvall uint32_t modeflags; 30361369Sdduvall uint32_t mhcr; 30371369Sdduvall uint32_t sx0; 30383390Szh199473 uint32_t i, tries; 30391408Srandyf #ifdef BGE_IPMI_ASF 30401408Srandyf uint32_t mailbox; 30411408Srandyf #endif 30421865Sdilpreet int retval = DDI_SUCCESS; 30431369Sdduvall 30441369Sdduvall BGE_TRACE(("bge_chip_reset($%p, %d)", 30451369Sdduvall (void *)bgep, enable_dma)); 30461369Sdduvall 30471369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 30481369Sdduvall 30491369Sdduvall BGE_DEBUG(("bge_chip_reset($%p, %d): current state is %d", 30501369Sdduvall (void *)bgep, enable_dma, bgep->bge_chip_state)); 30511369Sdduvall 30521369Sdduvall /* 30531369Sdduvall * Do we need to stop the chip cleanly before resetting? 30541369Sdduvall */ 30551369Sdduvall switch (bgep->bge_chip_state) { 30561369Sdduvall default: 30571369Sdduvall _NOTE(NOTREACHED) 30581865Sdilpreet return (DDI_FAILURE); 30591369Sdduvall 30601369Sdduvall case BGE_CHIP_INITIAL: 30611369Sdduvall case BGE_CHIP_STOPPED: 30621369Sdduvall case BGE_CHIP_RESET: 30631369Sdduvall break; 30641369Sdduvall 30651369Sdduvall case BGE_CHIP_RUNNING: 30661369Sdduvall case BGE_CHIP_ERROR: 30671369Sdduvall case BGE_CHIP_FAULT: 30681369Sdduvall bge_chip_stop(bgep, B_FALSE); 30691369Sdduvall break; 30701369Sdduvall } 30711369Sdduvall 30721408Srandyf #ifdef BGE_IPMI_ASF 30731408Srandyf if (bgep->asf_enabled) { 30743918Sml149210 #ifdef __sparc 30753918Sml149210 mhcr = MHCR_ENABLE_INDIRECT_ACCESS | 30763918Sml149210 MHCR_ENABLE_TAGGED_STATUS_MODE | 30773918Sml149210 MHCR_MASK_INTERRUPT_MODE | 30783918Sml149210 MHCR_MASK_PCI_INT_OUTPUT | 30793918Sml149210 MHCR_CLEAR_INTERRUPT_INTA | 30803918Sml149210 MHCR_ENABLE_ENDIAN_WORD_SWAP | 30813918Sml149210 MHCR_ENABLE_ENDIAN_BYTE_SWAP; 30823918Sml149210 pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_MHCR, mhcr); 30833918Sml149210 bge_reg_put32(bgep, MEMORY_ARBITER_MODE_REG, 30843918Sml149210 bge_reg_get32(bgep, MEMORY_ARBITER_MODE_REG) | 30853918Sml149210 MEMORY_ARBITER_ENABLE); 30863918Sml149210 #endif 30871408Srandyf if (asf_mode == ASF_MODE_INIT) { 30881408Srandyf bge_asf_pre_reset_operations(bgep, BGE_INIT_RESET); 30891408Srandyf } else if (asf_mode == ASF_MODE_SHUTDOWN) { 30901408Srandyf bge_asf_pre_reset_operations(bgep, BGE_SHUTDOWN_RESET); 30911408Srandyf } 30921408Srandyf } 30931408Srandyf #endif 30941369Sdduvall /* 30951369Sdduvall * Adapted from Broadcom document 570X-PG102-R, pp 102-116. 30961369Sdduvall * Updated to reflect Broadcom document 570X-PG104-R, pp 146-159. 30971369Sdduvall * 30981369Sdduvall * Before reset Core clock,it is 30991369Sdduvall * also required to initialize the Memory Arbiter as specified in step9 31001369Sdduvall * and Misc Host Control Register as specified in step-13 31011369Sdduvall * Step 4-5: reset Core clock & wait for completion 31021369Sdduvall * Steps 6-8: are done by bge_chip_cfg_init() 31031908Sly149593 * put the T3_MAGIC_NUMBER into the GENCOMM port before reset 31041369Sdduvall */ 31051865Sdilpreet if (!bge_chip_enable_engine(bgep, MEMORY_ARBITER_MODE_REG, 0)) 31061865Sdilpreet retval = DDI_FAILURE; 31071369Sdduvall 31081369Sdduvall mhcr = MHCR_ENABLE_INDIRECT_ACCESS | 31091369Sdduvall MHCR_ENABLE_TAGGED_STATUS_MODE | 31101369Sdduvall MHCR_MASK_INTERRUPT_MODE | 31111369Sdduvall MHCR_MASK_PCI_INT_OUTPUT | 31121369Sdduvall MHCR_CLEAR_INTERRUPT_INTA; 31131369Sdduvall #ifdef _BIG_ENDIAN 31141369Sdduvall mhcr |= MHCR_ENABLE_ENDIAN_WORD_SWAP | MHCR_ENABLE_ENDIAN_BYTE_SWAP; 31151369Sdduvall #endif /* _BIG_ENDIAN */ 31161369Sdduvall pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_MHCR, mhcr); 31171408Srandyf #ifdef BGE_IPMI_ASF 31181408Srandyf if (bgep->asf_enabled) 31191408Srandyf bgep->asf_wordswapped = B_FALSE; 31201408Srandyf #endif 31212675Szh199473 /* 31222675Szh199473 * NVRAM Corruption Workaround 31232675Szh199473 */ 31243390Szh199473 for (tries = 0; tries < MAX_TRY_NVMEM_ACQUIRE; tries++) 31253534Szh199473 if (bge_nvmem_acquire(bgep) != EAGAIN) 31262675Szh199473 break; 31273440Szh199473 if (tries >= MAX_TRY_NVMEM_ACQUIRE) 31282675Szh199473 BGE_DEBUG(("%s: fail to acquire nvram lock", 31292675Szh199473 bgep->ifname)); 31302675Szh199473 31311908Sly149593 #ifdef BGE_IPMI_ASF 31321908Sly149593 if (!bgep->asf_enabled) { 31331908Sly149593 #endif 31341908Sly149593 magic = (uint64_t)T3_MAGIC_NUMBER << 32; 31351908Sly149593 bge_nic_put64(bgep, NIC_MEM_GENCOMM, magic); 31361908Sly149593 #ifdef BGE_IPMI_ASF 31371908Sly149593 } 31381908Sly149593 #endif 31391908Sly149593 31401865Sdilpreet if (!bge_chip_reset_engine(bgep, MISC_CONFIG_REG)) 31411865Sdilpreet retval = DDI_FAILURE; 31421369Sdduvall bge_chip_cfg_init(bgep, &chipid, enable_dma); 31431369Sdduvall 31441369Sdduvall /* 31451369Sdduvall * Step 8a: This may belong elsewhere, but BCM5721 needs 31461369Sdduvall * a bit set to avoid a fifo overflow/underflow bug. 31471369Sdduvall */ 31482135Szh199473 if ((bgep->chipid.chip_label == 5721) || 31492135Szh199473 (bgep->chipid.chip_label == 5751) || 31502675Szh199473 (bgep->chipid.chip_label == 5752) || 31514330Sml149210 (bgep->chipid.chip_label == 5755) || 31522135Szh199473 (bgep->chipid.chip_label == 5789)) 31531369Sdduvall bge_reg_set32(bgep, TLP_CONTROL_REG, TLP_DATA_FIFO_PROTECT); 31541369Sdduvall 31551369Sdduvall 31561369Sdduvall /* 31571369Sdduvall * Step 9: enable MAC memory arbiter,bit30 and bit31 of 5714/5715 should 31581369Sdduvall * not be changed. 31591369Sdduvall */ 31601865Sdilpreet if (!bge_chip_enable_engine(bgep, MEMORY_ARBITER_MODE_REG, 0)) 31611865Sdilpreet retval = DDI_FAILURE; 31621369Sdduvall 31631369Sdduvall /* 31641369Sdduvall * Steps 10-11: configure PIO endianness options and 31651369Sdduvall * enable indirect register access -- already done 31661369Sdduvall * Steps 12-13: enable writing to the PCI state & clock 31671369Sdduvall * control registers -- not required; we aren't going to 31681369Sdduvall * use those features. 31691369Sdduvall * Steps 14-15: Configure DMA endianness options. See 31701369Sdduvall * the comments on the setting of the MHCR above. 31711369Sdduvall */ 31721369Sdduvall #ifdef _BIG_ENDIAN 31731369Sdduvall modeflags = MODE_WORD_SWAP_FRAME | MODE_BYTE_SWAP_FRAME | 31741369Sdduvall MODE_WORD_SWAP_NONFRAME | MODE_BYTE_SWAP_NONFRAME; 31751369Sdduvall #else 31761369Sdduvall modeflags = MODE_WORD_SWAP_FRAME | MODE_BYTE_SWAP_FRAME; 31771369Sdduvall #endif /* _BIG_ENDIAN */ 31781408Srandyf #ifdef BGE_IPMI_ASF 31791408Srandyf if (bgep->asf_enabled) 31801408Srandyf modeflags |= MODE_HOST_STACK_UP; 31811408Srandyf #endif 31821369Sdduvall bge_reg_put32(bgep, MODE_CONTROL_REG, modeflags); 31831369Sdduvall 31841408Srandyf #ifdef BGE_IPMI_ASF 31851408Srandyf if (bgep->asf_enabled) { 31863918Sml149210 #ifdef __sparc 31873918Sml149210 bge_reg_put32(bgep, MEMORY_ARBITER_MODE_REG, 31883918Sml149210 MEMORY_ARBITER_ENABLE | 31893918Sml149210 bge_reg_get32(bgep, MEMORY_ARBITER_MODE_REG)); 31903918Sml149210 #endif 31913918Sml149210 31923918Sml149210 #ifdef BGE_NETCONSOLE 31933918Sml149210 if (!bgep->asf_newhandshake) { 31943918Sml149210 if ((asf_mode == ASF_MODE_INIT) || 31953918Sml149210 (asf_mode == ASF_MODE_POST_INIT)) { 31963918Sml149210 bge_asf_post_reset_old_mode(bgep, 31973918Sml149210 BGE_INIT_RESET); 31983918Sml149210 } else { 31993918Sml149210 bge_asf_post_reset_old_mode(bgep, 32003918Sml149210 BGE_SHUTDOWN_RESET); 32011408Srandyf } 32021408Srandyf } 32033918Sml149210 #endif 32043918Sml149210 32053918Sml149210 /* Wait for NVRAM init */ 32063918Sml149210 i = 0; 32073918Sml149210 drv_usecwait(5000); 32083918Sml149210 mailbox = bge_nic_get32(bgep, BGE_FIRMWARE_MAILBOX); 32093918Sml149210 32103918Sml149210 while ((mailbox != (uint32_t) 32113918Sml149210 ~BGE_MAGIC_NUM_FIRMWARE_INIT_DONE) && 32123918Sml149210 (i < 10000)) { 32133918Sml149210 drv_usecwait(100); 32143918Sml149210 mailbox = bge_nic_get32(bgep, 32153918Sml149210 BGE_FIRMWARE_MAILBOX); 32163918Sml149210 i++; 32173918Sml149210 } 32183918Sml149210 32193918Sml149210 #ifndef BGE_NETCONSOLE 32203918Sml149210 if (!bgep->asf_newhandshake) { 32213918Sml149210 if ((asf_mode == ASF_MODE_INIT) || 32223918Sml149210 (asf_mode == ASF_MODE_POST_INIT)) { 32233918Sml149210 32243918Sml149210 bge_asf_post_reset_old_mode(bgep, 32253918Sml149210 BGE_INIT_RESET); 32263918Sml149210 } else { 32273918Sml149210 bge_asf_post_reset_old_mode(bgep, 32283918Sml149210 BGE_SHUTDOWN_RESET); 32293918Sml149210 } 32303918Sml149210 } 32313918Sml149210 #endif 32321408Srandyf } 32331408Srandyf #endif 32341369Sdduvall /* 32351369Sdduvall * Steps 16-17: poll for firmware completion 32361369Sdduvall */ 32371369Sdduvall mac = bge_poll_firmware(bgep); 32381369Sdduvall 32391369Sdduvall /* 32401369Sdduvall * Step 18: enable external memory -- doesn't apply. 32411369Sdduvall * 32421369Sdduvall * However we take the opportunity to set the MLCR anyway, as 32431369Sdduvall * this register also controls the SEEPROM auto-access method 32441369Sdduvall * which we may want to use later ... 32451369Sdduvall * 32461369Sdduvall * The proper value here depends on the way the chip is wired 32471369Sdduvall * into the circuit board, as this register *also* controls which 32481369Sdduvall * of the "Miscellaneous I/O" pins are driven as outputs and the 32491369Sdduvall * values driven onto those pins! 32501369Sdduvall * 32511369Sdduvall * See also step 74 in the PRM ... 32521369Sdduvall */ 32531369Sdduvall bge_reg_put32(bgep, MISC_LOCAL_CONTROL_REG, 32541369Sdduvall bgep->chipid.bge_mlcr_default); 32551369Sdduvall bge_reg_set32(bgep, SERIAL_EEPROM_ADDRESS_REG, SEEPROM_ACCESS_INIT); 32561369Sdduvall 32571369Sdduvall /* 32581369Sdduvall * Step 20: clear the Ethernet MAC mode register 32591369Sdduvall */ 32601369Sdduvall bge_reg_put32(bgep, ETHERNET_MAC_MODE_REG, 0); 32611369Sdduvall 32621369Sdduvall /* 32631369Sdduvall * Step 21: restore cache-line-size, latency timer, and 32641369Sdduvall * subsystem ID registers to their original values (not 32651369Sdduvall * those read into the local structure <chipid>, 'cos 32661369Sdduvall * that was after they were cleared by the RESET). 32671369Sdduvall * 32681369Sdduvall * Note: the Subsystem Vendor/Device ID registers are not 32691369Sdduvall * directly writable in config space, so we use the shadow 32701369Sdduvall * copy in "Page Zero" of register space to restore them 32711369Sdduvall * both in one go ... 32721369Sdduvall */ 32731369Sdduvall pci_config_put8(bgep->cfg_handle, PCI_CONF_CACHE_LINESZ, 32741369Sdduvall bgep->chipid.clsize); 32751369Sdduvall pci_config_put8(bgep->cfg_handle, PCI_CONF_LATENCY_TIMER, 32761369Sdduvall bgep->chipid.latency); 32771369Sdduvall bge_reg_put32(bgep, PCI_CONF_SUBVENID, 32781369Sdduvall (bgep->chipid.subdev << 16) | bgep->chipid.subven); 32791369Sdduvall 32801369Sdduvall /* 32811369Sdduvall * The SEND INDEX registers should be reset to zero by the 32821369Sdduvall * global chip reset; if they're not, there'll be trouble 32831865Sdilpreet * later on. 32841369Sdduvall */ 32851369Sdduvall sx0 = bge_reg_get32(bgep, NIC_DIAG_SEND_INDEX_REG(0)); 32861865Sdilpreet if (sx0 != 0) { 32871865Sdilpreet BGE_REPORT((bgep, "SEND INDEX - device didn't RESET")); 32881865Sdilpreet bge_fm_ereport(bgep, DDI_FM_DEVICE_INVAL_STATE); 32893170Sml149210 retval = DDI_FAILURE; 32901865Sdilpreet } 32911369Sdduvall 32921369Sdduvall /* Enable MSI code */ 32931369Sdduvall if (bgep->intr_type == DDI_INTR_TYPE_MSI) 32941369Sdduvall bge_reg_set32(bgep, MSI_MODE_REG, 32953907Szh199473 MSI_PRI_HIGHEST|MSI_MSI_ENABLE|MSI_ERROR_ATTENTION); 32961369Sdduvall 32971369Sdduvall /* 32981369Sdduvall * On the first time through, save the factory-set MAC address 32991369Sdduvall * (if any). If bge_poll_firmware() above didn't return one 33001369Sdduvall * (from a chip register) consider looking in the attached NV 33011369Sdduvall * memory device, if any. Once we have it, we save it in both 33021369Sdduvall * register-image (64-bit) and byte-array forms. All-zero and 33031369Sdduvall * all-one addresses are not valid, and we refuse to stash those. 33041369Sdduvall */ 33051369Sdduvall if (bgep->bge_chip_state == BGE_CHIP_INITIAL) { 33061369Sdduvall if (mac == 0ULL) 33071369Sdduvall mac = bge_get_nvmac(bgep); 33081369Sdduvall if (mac != 0ULL && mac != ~0ULL) { 33091369Sdduvall bgep->chipid.hw_mac_addr = mac; 33101369Sdduvall for (i = ETHERADDRL; i-- != 0; ) { 33111369Sdduvall bgep->chipid.vendor_addr.addr[i] = (uchar_t)mac; 33121369Sdduvall mac >>= 8; 33131369Sdduvall } 33142331Skrgopi bgep->chipid.vendor_addr.set = B_TRUE; 33151369Sdduvall } 33161369Sdduvall } 33171369Sdduvall 33181408Srandyf #ifdef BGE_IPMI_ASF 33191408Srandyf if (bgep->asf_enabled && bgep->asf_newhandshake) { 33201408Srandyf if (asf_mode != ASF_MODE_NONE) { 33211408Srandyf if ((asf_mode == ASF_MODE_INIT) || 33221408Srandyf (asf_mode == ASF_MODE_POST_INIT)) { 33231408Srandyf 33241408Srandyf bge_asf_post_reset_new_mode(bgep, 33251408Srandyf BGE_INIT_RESET); 33261408Srandyf } else { 33271408Srandyf bge_asf_post_reset_new_mode(bgep, 33281408Srandyf BGE_SHUTDOWN_RESET); 33291408Srandyf } 33301408Srandyf } 33311408Srandyf } 33321408Srandyf #endif 33331408Srandyf 33341369Sdduvall /* 33351369Sdduvall * Record the new state 33361369Sdduvall */ 33371369Sdduvall bgep->chip_resets += 1; 33381369Sdduvall bgep->bge_chip_state = BGE_CHIP_RESET; 33391865Sdilpreet return (retval); 33401369Sdduvall } 33411369Sdduvall 33421369Sdduvall /* 33431369Sdduvall * bge_chip_start() -- start the chip transmitting and/or receiving, 33441369Sdduvall * including enabling interrupts 33451369Sdduvall */ 33461865Sdilpreet int bge_chip_start(bge_t *bgep, boolean_t reset_phys); 33471369Sdduvall #pragma no_inline(bge_chip_start) 33481369Sdduvall 33491865Sdilpreet int 33501369Sdduvall bge_chip_start(bge_t *bgep, boolean_t reset_phys) 33511369Sdduvall { 33521369Sdduvall uint32_t coalmode; 33531369Sdduvall uint32_t ledctl; 33541369Sdduvall uint32_t mtu; 33551369Sdduvall uint32_t maxring; 33563534Szh199473 uint32_t stats_mask; 33574330Sml149210 uint32_t dma_wrprio; 33581369Sdduvall uint64_t ring; 33591865Sdilpreet int retval = DDI_SUCCESS; 33601369Sdduvall 33611369Sdduvall BGE_TRACE(("bge_chip_start($%p)", 33624588Sml149210 (void *)bgep)); 33631369Sdduvall 33641369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 33651369Sdduvall ASSERT(bgep->bge_chip_state == BGE_CHIP_RESET); 33661369Sdduvall 33671369Sdduvall /* 33681369Sdduvall * Taken from Broadcom document 570X-PG102-R, pp 102-116. 33691369Sdduvall * The document specifies 95 separate steps to fully 33701369Sdduvall * initialise the chip!!!! 33711369Sdduvall * 33721369Sdduvall * The reset code above has already got us as far as step 33731369Sdduvall * 21, so we continue with ... 33741369Sdduvall * 33751369Sdduvall * Step 22: clear the MAC statistics block 33761369Sdduvall * (0x0300-0x0aff in NIC-local memory) 33771369Sdduvall */ 33781369Sdduvall if (bgep->chipid.statistic_type == BGE_STAT_BLK) 33791369Sdduvall bge_nic_zero(bgep, NIC_MEM_STATISTICS, 33801369Sdduvall NIC_MEM_STATISTICS_SIZE); 33811369Sdduvall 33821369Sdduvall /* 33831369Sdduvall * Step 23: clear the status block (in host memory) 33841369Sdduvall */ 33851369Sdduvall DMA_ZERO(bgep->status_block); 33861369Sdduvall 33871369Sdduvall /* 33881369Sdduvall * Step 24: set DMA read/write control register 33891369Sdduvall */ 33901369Sdduvall pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_PDRWCR, 33914588Sml149210 bgep->chipid.bge_dma_rwctrl); 33921369Sdduvall 33931369Sdduvall /* 33941369Sdduvall * Step 25: Configure DMA endianness -- already done (16/17) 33951369Sdduvall * Step 26: Configure Host-Based Send Rings 33961369Sdduvall * Step 27: Indicate Host Stack Up 33971369Sdduvall */ 33981369Sdduvall bge_reg_set32(bgep, MODE_CONTROL_REG, 33994588Sml149210 MODE_HOST_SEND_BDS | 34004588Sml149210 MODE_HOST_STACK_UP); 34011369Sdduvall 34021369Sdduvall /* 34031369Sdduvall * Step 28: Configure checksum options: 34041611Szh199473 * Solaris supports the hardware default checksum options. 34051611Szh199473 * 34061611Szh199473 * Workaround for Incorrect pseudo-header checksum calculation. 34071369Sdduvall */ 34082135Szh199473 if (bgep->chipid.flags & CHIP_FLAG_PARTIAL_CSUM) 34091611Szh199473 bge_reg_set32(bgep, MODE_CONTROL_REG, 34102311Sseb MODE_SEND_NO_PSEUDO_HDR_CSUM); 34111369Sdduvall 34121369Sdduvall /* 34131369Sdduvall * Step 29: configure Timer Prescaler. The value is always the 34141369Sdduvall * same: the Core Clock frequency in MHz (66), minus 1, shifted 34151369Sdduvall * into bits 7-1. Don't set bit 0, 'cos that's the RESET bit 34161369Sdduvall * for the whole chip! 34171369Sdduvall */ 34181369Sdduvall bge_reg_put32(bgep, MISC_CONFIG_REG, MISC_CONFIG_DEFAULT); 34191369Sdduvall 34201369Sdduvall /* 34211369Sdduvall * Steps 30-31: Configure MAC local memory pool & DMA pool registers 34221369Sdduvall * 34231369Sdduvall * If the mbuf_length is specified as 0, we just leave these at 34241369Sdduvall * their hardware defaults, rather than explicitly setting them. 34251369Sdduvall * As the Broadcom HRM,driver better not change the parameters 34261369Sdduvall * when the chipsets is 5705/5788/5721/5751/5714 and 5715. 34271369Sdduvall */ 34281369Sdduvall if ((bgep->chipid.mbuf_length != 0) && 34294588Sml149210 (DEVICE_5704_SERIES_CHIPSETS(bgep))) { 34301369Sdduvall bge_reg_put32(bgep, MBUF_POOL_BASE_REG, 34314588Sml149210 bgep->chipid.mbuf_base); 34321369Sdduvall bge_reg_put32(bgep, MBUF_POOL_LENGTH_REG, 34334588Sml149210 bgep->chipid.mbuf_length); 34341369Sdduvall bge_reg_put32(bgep, DMAD_POOL_BASE_REG, 34354588Sml149210 DMAD_POOL_BASE_DEFAULT); 34361369Sdduvall bge_reg_put32(bgep, DMAD_POOL_LENGTH_REG, 34374588Sml149210 DMAD_POOL_LENGTH_DEFAULT); 34381369Sdduvall } 34391369Sdduvall 34401369Sdduvall /* 34411369Sdduvall * Step 32: configure MAC memory pool watermarks 34421369Sdduvall */ 34431369Sdduvall bge_reg_put32(bgep, RDMA_MBUF_LOWAT_REG, 34444588Sml149210 bgep->chipid.mbuf_lo_water_rdma); 34451369Sdduvall bge_reg_put32(bgep, MAC_RX_MBUF_LOWAT_REG, 34464588Sml149210 bgep->chipid.mbuf_lo_water_rmac); 34471369Sdduvall bge_reg_put32(bgep, MBUF_HIWAT_REG, 34484588Sml149210 bgep->chipid.mbuf_hi_water); 34491369Sdduvall 34501369Sdduvall /* 34511369Sdduvall * Step 33: configure DMA resource watermarks 34521369Sdduvall */ 34531369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) { 34541369Sdduvall bge_reg_put32(bgep, DMAD_POOL_LOWAT_REG, 34551369Sdduvall bge_dmad_lo_water); 34561369Sdduvall bge_reg_put32(bgep, DMAD_POOL_HIWAT_REG, 34571369Sdduvall bge_dmad_hi_water); 34581369Sdduvall } 34591369Sdduvall bge_reg_put32(bgep, LOWAT_MAX_RECV_FRAMES_REG, bge_lowat_recv_frames); 34601369Sdduvall 34611369Sdduvall /* 34621369Sdduvall * Steps 34-36: enable buffer manager & internal h/w queues 34631369Sdduvall */ 34641865Sdilpreet if (!bge_chip_enable_engine(bgep, BUFFER_MANAGER_MODE_REG, 34651865Sdilpreet STATE_MACHINE_ATTN_ENABLE_BIT)) 34661865Sdilpreet retval = DDI_FAILURE; 34671865Sdilpreet if (!bge_chip_enable_engine(bgep, FTQ_RESET_REG, 0)) 34681865Sdilpreet retval = DDI_FAILURE; 34691369Sdduvall 34701369Sdduvall /* 34711369Sdduvall * Steps 37-39: initialise Receive Buffer (Producer) RCBs 34721369Sdduvall */ 34731369Sdduvall bge_reg_putrcb(bgep, STD_RCV_BD_RING_RCB_REG, 34744588Sml149210 &bgep->buff[BGE_STD_BUFF_RING].hw_rcb); 34751369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) { 34761369Sdduvall bge_reg_putrcb(bgep, JUMBO_RCV_BD_RING_RCB_REG, 34774588Sml149210 &bgep->buff[BGE_JUMBO_BUFF_RING].hw_rcb); 34781369Sdduvall bge_reg_putrcb(bgep, MINI_RCV_BD_RING_RCB_REG, 34794588Sml149210 &bgep->buff[BGE_MINI_BUFF_RING].hw_rcb); 34801369Sdduvall } 34811369Sdduvall 34821369Sdduvall /* 34831369Sdduvall * Step 40: set Receive Buffer Descriptor Ring replenish thresholds 34841369Sdduvall */ 34851369Sdduvall bge_reg_put32(bgep, STD_RCV_BD_REPLENISH_REG, bge_replenish_std); 34861369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) { 34871369Sdduvall bge_reg_put32(bgep, JUMBO_RCV_BD_REPLENISH_REG, 34881369Sdduvall bge_replenish_jumbo); 34891369Sdduvall bge_reg_put32(bgep, MINI_RCV_BD_REPLENISH_REG, 34901369Sdduvall bge_replenish_mini); 34911369Sdduvall } 34921369Sdduvall 34931369Sdduvall /* 34941369Sdduvall * Steps 41-43: clear Send Ring Producer Indices and initialise 34951369Sdduvall * Send Producer Rings (0x0100-0x01ff in NIC-local memory) 34961369Sdduvall */ 34971369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) 34981369Sdduvall maxring = BGE_SEND_RINGS_MAX; 34991369Sdduvall else 35001369Sdduvall maxring = BGE_SEND_RINGS_MAX_5705; 35011369Sdduvall for (ring = 0; ring < maxring; ++ring) { 35021369Sdduvall bge_mbx_put(bgep, SEND_RING_HOST_INDEX_REG(ring), 0); 35031369Sdduvall bge_mbx_put(bgep, SEND_RING_NIC_INDEX_REG(ring), 0); 35041369Sdduvall bge_nic_putrcb(bgep, NIC_MEM_SEND_RING(ring), 35054588Sml149210 &bgep->send[ring].hw_rcb); 35061369Sdduvall } 35071369Sdduvall 35081369Sdduvall /* 35091369Sdduvall * Steps 44-45: initialise Receive Return Rings 35101369Sdduvall * (0x0200-0x02ff in NIC-local memory) 35111369Sdduvall */ 35121369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) 35131369Sdduvall maxring = BGE_RECV_RINGS_MAX; 35141369Sdduvall else 35151369Sdduvall maxring = BGE_RECV_RINGS_MAX_5705; 35161369Sdduvall for (ring = 0; ring < maxring; ++ring) 35171369Sdduvall bge_nic_putrcb(bgep, NIC_MEM_RECV_RING(ring), 35184588Sml149210 &bgep->recv[ring].hw_rcb); 35191369Sdduvall 35201369Sdduvall /* 35211369Sdduvall * Step 46: initialise Receive Buffer (Producer) Ring indexes 35221369Sdduvall */ 35231369Sdduvall bge_mbx_put(bgep, RECV_STD_PROD_INDEX_REG, 0); 35241369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) { 35251369Sdduvall bge_mbx_put(bgep, RECV_JUMBO_PROD_INDEX_REG, 0); 35261369Sdduvall bge_mbx_put(bgep, RECV_MINI_PROD_INDEX_REG, 0); 35271369Sdduvall } 35281369Sdduvall /* 35291369Sdduvall * Step 47: configure the MAC unicast address 35301369Sdduvall * Step 48: configure the random backoff seed 35311369Sdduvall * Step 96: set up multicast filters 35321369Sdduvall */ 35331408Srandyf #ifdef BGE_IPMI_ASF 35341865Sdilpreet if (bge_chip_sync(bgep, B_FALSE) == DDI_FAILURE) 35351408Srandyf #else 35361865Sdilpreet if (bge_chip_sync(bgep) == DDI_FAILURE) 35371408Srandyf #endif 35381865Sdilpreet retval = DDI_FAILURE; 35391369Sdduvall 35401369Sdduvall /* 35411369Sdduvall * Step 49: configure the MTU 35421369Sdduvall */ 35431369Sdduvall mtu = bgep->chipid.ethmax_size+ETHERFCSL+VLAN_TAGSZ; 35441369Sdduvall bge_reg_put32(bgep, MAC_RX_MTU_SIZE_REG, mtu); 35451369Sdduvall 35461369Sdduvall /* 35471369Sdduvall * Step 50: configure the IPG et al 35481369Sdduvall */ 35491369Sdduvall bge_reg_put32(bgep, MAC_TX_LENGTHS_REG, MAC_TX_LENGTHS_DEFAULT); 35501369Sdduvall 35511369Sdduvall /* 35521369Sdduvall * Step 51: configure the default Rx Return Ring 35531369Sdduvall */ 35541369Sdduvall bge_reg_put32(bgep, RCV_RULES_CONFIG_REG, RCV_RULES_CONFIG_DEFAULT); 35551369Sdduvall 35561369Sdduvall /* 35571369Sdduvall * Steps 52-54: configure Receive List Placement, 35581369Sdduvall * and enable Receive List Placement Statistics 35591369Sdduvall */ 35601369Sdduvall bge_reg_put32(bgep, RCV_LP_CONFIG_REG, 35614588Sml149210 RCV_LP_CONFIG(bgep->chipid.rx_rings)); 35623534Szh199473 switch (MHCR_CHIP_ASIC_REV(bgep->chipid.asic_rev)) { 35633534Szh199473 case MHCR_CHIP_ASIC_REV_5700: 35643534Szh199473 case MHCR_CHIP_ASIC_REV_5701: 35653534Szh199473 case MHCR_CHIP_ASIC_REV_5703: 35663534Szh199473 case MHCR_CHIP_ASIC_REV_5704: 35673534Szh199473 bge_reg_put32(bgep, RCV_LP_STATS_ENABLE_MASK_REG, ~0); 35683534Szh199473 break; 35693534Szh199473 case MHCR_CHIP_ASIC_REV_5705: 35703534Szh199473 break; 35713534Szh199473 default: 35723534Szh199473 stats_mask = bge_reg_get32(bgep, RCV_LP_STATS_ENABLE_MASK_REG); 35733534Szh199473 stats_mask &= ~RCV_LP_STATS_DISABLE_MACTQ; 35743534Szh199473 bge_reg_put32(bgep, RCV_LP_STATS_ENABLE_MASK_REG, stats_mask); 35753534Szh199473 break; 35763534Szh199473 } 35771369Sdduvall bge_reg_set32(bgep, RCV_LP_STATS_CONTROL_REG, RCV_LP_STATS_ENABLE); 35781369Sdduvall 35791369Sdduvall if (bgep->chipid.rx_rings > 1) 35801369Sdduvall bge_init_recv_rule(bgep); 35811369Sdduvall 35821369Sdduvall /* 35831369Sdduvall * Steps 55-56: enable Send Data Initiator Statistics 35841369Sdduvall */ 35851369Sdduvall bge_reg_put32(bgep, SEND_INIT_STATS_ENABLE_MASK_REG, ~0); 35861369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) { 35871369Sdduvall bge_reg_put32(bgep, SEND_INIT_STATS_CONTROL_REG, 35881369Sdduvall SEND_INIT_STATS_ENABLE | SEND_INIT_STATS_FASTER); 35891369Sdduvall } else { 35901369Sdduvall bge_reg_put32(bgep, SEND_INIT_STATS_CONTROL_REG, 35911369Sdduvall SEND_INIT_STATS_ENABLE); 35921369Sdduvall } 35931369Sdduvall /* 35941369Sdduvall * Steps 57-58: stop (?) the Host Coalescing Engine 35951369Sdduvall */ 35961865Sdilpreet if (!bge_chip_disable_engine(bgep, HOST_COALESCE_MODE_REG, ~0)) 35971865Sdilpreet retval = DDI_FAILURE; 35981369Sdduvall 35991369Sdduvall /* 36001369Sdduvall * Steps 59-62: initialise Host Coalescing parameters 36011369Sdduvall */ 36021369Sdduvall bge_reg_put32(bgep, SEND_COALESCE_MAX_BD_REG, bge_tx_count_norm); 36031369Sdduvall bge_reg_put32(bgep, SEND_COALESCE_TICKS_REG, bge_tx_ticks_norm); 36041369Sdduvall bge_reg_put32(bgep, RCV_COALESCE_MAX_BD_REG, bge_rx_count_norm); 36051369Sdduvall bge_reg_put32(bgep, RCV_COALESCE_TICKS_REG, bge_rx_ticks_norm); 36061369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) { 36071369Sdduvall bge_reg_put32(bgep, SEND_COALESCE_INT_BD_REG, 36081369Sdduvall bge_tx_count_intr); 36091369Sdduvall bge_reg_put32(bgep, SEND_COALESCE_INT_TICKS_REG, 36101369Sdduvall bge_tx_ticks_intr); 36111369Sdduvall bge_reg_put32(bgep, RCV_COALESCE_INT_BD_REG, 36121369Sdduvall bge_rx_count_intr); 36131369Sdduvall bge_reg_put32(bgep, RCV_COALESCE_INT_TICKS_REG, 36141369Sdduvall bge_rx_ticks_intr); 36151369Sdduvall } 36161369Sdduvall 36171369Sdduvall /* 36181369Sdduvall * Steps 63-64: initialise status block & statistics 36191369Sdduvall * host memory addresses 36201369Sdduvall * The statistic block does not exist in some chipsets 36211369Sdduvall * Step 65: initialise Statistics Coalescing Tick Counter 36221369Sdduvall */ 36231369Sdduvall bge_reg_put64(bgep, STATUS_BLOCK_HOST_ADDR_REG, 36244588Sml149210 bgep->status_block.cookie.dmac_laddress); 36251369Sdduvall 36261369Sdduvall /* 36271369Sdduvall * Steps 66-67: initialise status block & statistics 36281369Sdduvall * NIC-local memory addresses 36291369Sdduvall */ 36301369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) { 36311369Sdduvall bge_reg_put64(bgep, STATISTICS_HOST_ADDR_REG, 36321369Sdduvall bgep->statistics.cookie.dmac_laddress); 36331369Sdduvall bge_reg_put32(bgep, STATISTICS_TICKS_REG, 36341369Sdduvall STATISTICS_TICKS_DEFAULT); 36351369Sdduvall bge_reg_put32(bgep, STATUS_BLOCK_BASE_ADDR_REG, 36361369Sdduvall NIC_MEM_STATUS_BLOCK); 36371369Sdduvall bge_reg_put32(bgep, STATISTICS_BASE_ADDR_REG, 36381369Sdduvall NIC_MEM_STATISTICS); 36391369Sdduvall } 36401369Sdduvall 36411369Sdduvall /* 36421369Sdduvall * Steps 68-71: start the Host Coalescing Engine, the Receive BD 36431369Sdduvall * Completion Engine, the Receive List Placement Engine, and the 36441369Sdduvall * Receive List selector.Pay attention:0x3400 is not exist in BCM5714 36451369Sdduvall * and BCM5715. 36461369Sdduvall */ 36471369Sdduvall if (bgep->chipid.tx_rings <= COALESCE_64_BYTE_RINGS && 36481369Sdduvall bgep->chipid.rx_rings <= COALESCE_64_BYTE_RINGS) 36491369Sdduvall coalmode = COALESCE_64_BYTE_STATUS; 36501369Sdduvall else 36511369Sdduvall coalmode = 0; 36521865Sdilpreet if (!bge_chip_enable_engine(bgep, HOST_COALESCE_MODE_REG, coalmode)) 36531865Sdilpreet retval = DDI_FAILURE; 36541865Sdilpreet if (!bge_chip_enable_engine(bgep, RCV_BD_COMPLETION_MODE_REG, 36551865Sdilpreet STATE_MACHINE_ATTN_ENABLE_BIT)) 36561865Sdilpreet retval = DDI_FAILURE; 36571865Sdilpreet if (!bge_chip_enable_engine(bgep, RCV_LIST_PLACEMENT_MODE_REG, 0)) 36581865Sdilpreet retval = DDI_FAILURE; 36591369Sdduvall 36601369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) 36611865Sdilpreet if (!bge_chip_enable_engine(bgep, RCV_LIST_SELECTOR_MODE_REG, 36621865Sdilpreet STATE_MACHINE_ATTN_ENABLE_BIT)) 36631865Sdilpreet retval = DDI_FAILURE; 36641369Sdduvall 36651369Sdduvall /* 36661369Sdduvall * Step 72: Enable MAC DMA engines 36671369Sdduvall * Step 73: Clear & enable MAC statistics 36681369Sdduvall */ 36691369Sdduvall bge_reg_set32(bgep, ETHERNET_MAC_MODE_REG, 36704588Sml149210 ETHERNET_MODE_ENABLE_FHDE | 36714588Sml149210 ETHERNET_MODE_ENABLE_RDE | 36724588Sml149210 ETHERNET_MODE_ENABLE_TDE); 36731369Sdduvall bge_reg_set32(bgep, ETHERNET_MAC_MODE_REG, 36744588Sml149210 ETHERNET_MODE_ENABLE_TX_STATS | 36754588Sml149210 ETHERNET_MODE_ENABLE_RX_STATS | 36764588Sml149210 ETHERNET_MODE_CLEAR_TX_STATS | 36774588Sml149210 ETHERNET_MODE_CLEAR_RX_STATS); 36781369Sdduvall 36791369Sdduvall /* 36801369Sdduvall * Step 74: configure the MLCR (Miscellaneous Local Control 36811369Sdduvall * Register); not required, as we set up the MLCR in step 10 36821369Sdduvall * (part of the reset code) above. 36831369Sdduvall * 36841369Sdduvall * Step 75: clear Interrupt Mailbox 0 36851369Sdduvall */ 36861369Sdduvall bge_mbx_put(bgep, INTERRUPT_MBOX_0_REG, 0); 36871369Sdduvall 36881369Sdduvall /* 36891369Sdduvall * Steps 76-87: Gentlemen, start your engines ... 36901369Sdduvall * 36911369Sdduvall * Enable the DMA Completion Engine, the Write DMA Engine, 36921369Sdduvall * the Read DMA Engine, Receive Data Completion Engine, 36931369Sdduvall * the MBuf Cluster Free Engine, the Send Data Completion Engine, 36941369Sdduvall * the Send BD Completion Engine, the Receive BD Initiator Engine, 36951369Sdduvall * the Receive Data Initiator Engine, the Send Data Initiator Engine, 36961369Sdduvall * the Send BD Initiator Engine, and the Send BD Selector Engine. 36971369Sdduvall * 36981369Sdduvall * Beware exhaust fumes? 36991369Sdduvall */ 37001369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) 37011865Sdilpreet if (!bge_chip_enable_engine(bgep, DMA_COMPLETION_MODE_REG, 0)) 37021865Sdilpreet retval = DDI_FAILURE; 37034330Sml149210 dma_wrprio = (bge_dma_wrprio << DMA_PRIORITY_SHIFT) | 37044588Sml149210 ALL_DMA_ATTN_BITS; 37054330Sml149210 if (MHCR_CHIP_ASIC_REV(bgep->chipid.asic_rev) == 37064588Sml149210 MHCR_CHIP_ASIC_REV_5755) { 37074330Sml149210 dma_wrprio |= DMA_STATUS_TAG_FIX_CQ12384; 37084330Sml149210 } 37091865Sdilpreet if (!bge_chip_enable_engine(bgep, WRITE_DMA_MODE_REG, 37104588Sml149210 dma_wrprio)) 37111865Sdilpreet retval = DDI_FAILURE; 37121865Sdilpreet if (!bge_chip_enable_engine(bgep, READ_DMA_MODE_REG, 37131865Sdilpreet (bge_dma_rdprio << DMA_PRIORITY_SHIFT) | ALL_DMA_ATTN_BITS)) 37141865Sdilpreet retval = DDI_FAILURE; 37151865Sdilpreet if (!bge_chip_enable_engine(bgep, RCV_DATA_COMPLETION_MODE_REG, 37161865Sdilpreet STATE_MACHINE_ATTN_ENABLE_BIT)) 37171865Sdilpreet retval = DDI_FAILURE; 37181369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) 37191865Sdilpreet if (!bge_chip_enable_engine(bgep, 37201865Sdilpreet MBUF_CLUSTER_FREE_MODE_REG, 0)) 37211865Sdilpreet retval = DDI_FAILURE; 37221865Sdilpreet if (!bge_chip_enable_engine(bgep, SEND_DATA_COMPLETION_MODE_REG, 0)) 37231865Sdilpreet retval = DDI_FAILURE; 37241865Sdilpreet if (!bge_chip_enable_engine(bgep, SEND_BD_COMPLETION_MODE_REG, 37251865Sdilpreet STATE_MACHINE_ATTN_ENABLE_BIT)) 37261865Sdilpreet retval = DDI_FAILURE; 37271865Sdilpreet if (!bge_chip_enable_engine(bgep, RCV_BD_INITIATOR_MODE_REG, 37281865Sdilpreet RCV_BD_DISABLED_RING_ATTN)) 37291865Sdilpreet retval = DDI_FAILURE; 37301865Sdilpreet if (!bge_chip_enable_engine(bgep, RCV_DATA_BD_INITIATOR_MODE_REG, 37311865Sdilpreet RCV_DATA_BD_ILL_RING_ATTN)) 37321865Sdilpreet retval = DDI_FAILURE; 37331865Sdilpreet if (!bge_chip_enable_engine(bgep, SEND_DATA_INITIATOR_MODE_REG, 0)) 37341865Sdilpreet retval = DDI_FAILURE; 37351865Sdilpreet if (!bge_chip_enable_engine(bgep, SEND_BD_INITIATOR_MODE_REG, 37361865Sdilpreet STATE_MACHINE_ATTN_ENABLE_BIT)) 37371865Sdilpreet retval = DDI_FAILURE; 37381865Sdilpreet if (!bge_chip_enable_engine(bgep, SEND_BD_SELECTOR_MODE_REG, 37391865Sdilpreet STATE_MACHINE_ATTN_ENABLE_BIT)) 37401865Sdilpreet retval = DDI_FAILURE; 37411369Sdduvall 37421369Sdduvall /* 37431369Sdduvall * Step 88: download firmware -- doesn't apply 37441369Sdduvall * Steps 89-90: enable Transmit & Receive MAC Engines 37451369Sdduvall */ 37461865Sdilpreet if (!bge_chip_enable_engine(bgep, TRANSMIT_MAC_MODE_REG, 0)) 37471865Sdilpreet retval = DDI_FAILURE; 37481408Srandyf #ifdef BGE_IPMI_ASF 37491865Sdilpreet if (!bgep->asf_enabled) { 37501865Sdilpreet if (!bge_chip_enable_engine(bgep, RECEIVE_MAC_MODE_REG, 37511865Sdilpreet RECEIVE_MODE_KEEP_VLAN_TAG)) 37521865Sdilpreet retval = DDI_FAILURE; 37531408Srandyf } else { 37541865Sdilpreet if (!bge_chip_enable_engine(bgep, RECEIVE_MAC_MODE_REG, 0)) 37551865Sdilpreet retval = DDI_FAILURE; 37561408Srandyf } 37571408Srandyf #else 37581865Sdilpreet if (!bge_chip_enable_engine(bgep, RECEIVE_MAC_MODE_REG, 37591865Sdilpreet RECEIVE_MODE_KEEP_VLAN_TAG)) 37601865Sdilpreet retval = DDI_FAILURE; 37611408Srandyf #endif 37621369Sdduvall 37631369Sdduvall /* 37641369Sdduvall * Step 91: disable auto-polling of PHY status 37651369Sdduvall */ 37661369Sdduvall bge_reg_put32(bgep, MI_MODE_REG, MI_MODE_DEFAULT); 37671369Sdduvall 37681369Sdduvall /* 37691369Sdduvall * Step 92: configure D0 power state (not required) 37701369Sdduvall * Step 93: initialise LED control register () 37711369Sdduvall */ 37721369Sdduvall ledctl = LED_CONTROL_DEFAULT; 37731369Sdduvall switch (bgep->chipid.device) { 37741369Sdduvall case DEVICE_ID_5700: 37751369Sdduvall case DEVICE_ID_5700x: 37761369Sdduvall case DEVICE_ID_5701: 37771369Sdduvall /* 37781369Sdduvall * Switch to 5700 (MAC) mode on these older chips 37791369Sdduvall */ 37801369Sdduvall ledctl &= ~LED_CONTROL_LED_MODE_MASK; 37811369Sdduvall ledctl |= LED_CONTROL_LED_MODE_5700; 37821369Sdduvall break; 37831369Sdduvall 37841369Sdduvall default: 37851369Sdduvall break; 37861369Sdduvall } 37871369Sdduvall bge_reg_put32(bgep, ETHERNET_MAC_LED_CONTROL_REG, ledctl); 37881369Sdduvall 37891369Sdduvall /* 37901369Sdduvall * Step 94: activate link 37911369Sdduvall */ 37921369Sdduvall bge_reg_put32(bgep, MI_STATUS_REG, MI_STATUS_LINK); 37931369Sdduvall 37941369Sdduvall /* 37951369Sdduvall * Step 95: set up physical layer (PHY/SerDes) 37961369Sdduvall * restart autoneg (if required) 37971369Sdduvall */ 37981369Sdduvall if (reset_phys) 37991865Sdilpreet if (bge_phys_update(bgep) == DDI_FAILURE) 38001865Sdilpreet retval = DDI_FAILURE; 38011369Sdduvall 38021369Sdduvall /* 38031369Sdduvall * Extra step (DSG): hand over all the Receive Buffers to the chip 38041369Sdduvall */ 38051369Sdduvall for (ring = 0; ring < BGE_BUFF_RINGS_USED; ++ring) 38061369Sdduvall bge_mbx_put(bgep, bgep->buff[ring].chip_mbx_reg, 38074588Sml149210 bgep->buff[ring].rf_next); 38081369Sdduvall 38091369Sdduvall /* 38101369Sdduvall * MSI bits:The least significant MSI 16-bit word. 38111369Sdduvall * ISR will be triggered different. 38121369Sdduvall */ 38131369Sdduvall if (bgep->intr_type == DDI_INTR_TYPE_MSI) 38141369Sdduvall bge_reg_set32(bgep, HOST_COALESCE_MODE_REG, 0x70); 38151369Sdduvall 38161369Sdduvall /* 38171369Sdduvall * Extra step (DSG): select which interrupts are enabled 38181369Sdduvall * 38191369Sdduvall * Program the Ethernet MAC engine to signal attention on 38201369Sdduvall * Link Change events, then enable interrupts on MAC, DMA, 38211369Sdduvall * and FLOW attention signals. 38221369Sdduvall */ 38231369Sdduvall bge_reg_set32(bgep, ETHERNET_MAC_EVENT_ENABLE_REG, 38244588Sml149210 ETHERNET_EVENT_LINK_INT | 38254588Sml149210 ETHERNET_STATUS_PCS_ERROR_INT); 38261408Srandyf #ifdef BGE_IPMI_ASF 38271408Srandyf if (bgep->asf_enabled) { 38281408Srandyf bge_reg_set32(bgep, MODE_CONTROL_REG, 38294588Sml149210 MODE_INT_ON_FLOW_ATTN | 38304588Sml149210 MODE_INT_ON_DMA_ATTN | 38314588Sml149210 MODE_HOST_STACK_UP| 38324588Sml149210 MODE_INT_ON_MAC_ATTN); 38331408Srandyf } else { 38341408Srandyf #endif 38351408Srandyf bge_reg_set32(bgep, MODE_CONTROL_REG, 38364588Sml149210 MODE_INT_ON_FLOW_ATTN | 38374588Sml149210 MODE_INT_ON_DMA_ATTN | 38384588Sml149210 MODE_INT_ON_MAC_ATTN); 38391408Srandyf #ifdef BGE_IPMI_ASF 38401408Srandyf } 38411408Srandyf #endif 38421369Sdduvall 38431369Sdduvall /* 38441369Sdduvall * Step 97: enable PCI interrupts!!! 38451369Sdduvall */ 38461369Sdduvall if (bgep->intr_type == DDI_INTR_TYPE_FIXED) 38471369Sdduvall bge_cfg_clr32(bgep, PCI_CONF_BGE_MHCR, 38481369Sdduvall MHCR_MASK_PCI_INT_OUTPUT); 38491369Sdduvall 38501369Sdduvall /* 38511369Sdduvall * All done! 38521369Sdduvall */ 38531369Sdduvall bgep->bge_chip_state = BGE_CHIP_RUNNING; 38541865Sdilpreet return (retval); 38551369Sdduvall } 38561369Sdduvall 38571369Sdduvall 38581369Sdduvall /* 38591369Sdduvall * ========== Hardware interrupt handler ========== 38601369Sdduvall */ 38611369Sdduvall 38621369Sdduvall #undef BGE_DBG 38631369Sdduvall #define BGE_DBG BGE_DBG_INT /* debug flag for this code */ 38641369Sdduvall 38651369Sdduvall /* 38661369Sdduvall * Sync the status block, then atomically clear the specified bits in 38671369Sdduvall * the <flags-and-tag> field of the status block. 38681369Sdduvall * the <flags> word of the status block, returning the value of the 38691369Sdduvall * <tag> and the <flags> before the bits were cleared. 38701369Sdduvall */ 38711865Sdilpreet static int bge_status_sync(bge_t *bgep, uint64_t bits, uint64_t *flags); 38721369Sdduvall #pragma inline(bge_status_sync) 38731369Sdduvall 38741865Sdilpreet static int 38751865Sdilpreet bge_status_sync(bge_t *bgep, uint64_t bits, uint64_t *flags) 38761369Sdduvall { 38771369Sdduvall bge_status_t *bsp; 38781865Sdilpreet int retval; 38791369Sdduvall 38801369Sdduvall BGE_TRACE(("bge_status_sync($%p, 0x%llx)", 38814588Sml149210 (void *)bgep, bits)); 38821369Sdduvall 38831369Sdduvall ASSERT(bgep->bge_guard == BGE_GUARD); 38841369Sdduvall 38851369Sdduvall DMA_SYNC(bgep->status_block, DDI_DMA_SYNC_FORKERNEL); 38861865Sdilpreet retval = bge_check_dma_handle(bgep, bgep->status_block.dma_hdl); 38871865Sdilpreet if (retval != DDI_FM_OK) 38881865Sdilpreet return (retval); 38891865Sdilpreet 38901369Sdduvall bsp = DMA_VPTR(bgep->status_block); 38911865Sdilpreet *flags = bge_atomic_clr64(&bsp->flags_n_tag, bits); 38921369Sdduvall 38931369Sdduvall BGE_DEBUG(("bge_status_sync($%p, 0x%llx) returning 0x%llx", 38944588Sml149210 (void *)bgep, bits, *flags)); 38951865Sdilpreet 38961865Sdilpreet return (retval); 38971369Sdduvall } 38981369Sdduvall 38995903Ssowmini void bge_wake_factotum(bge_t *bgep); 39001369Sdduvall #pragma inline(bge_wake_factotum) 39011369Sdduvall 39025903Ssowmini void 39031369Sdduvall bge_wake_factotum(bge_t *bgep) 39041369Sdduvall { 39051369Sdduvall mutex_enter(bgep->softintrlock); 39061369Sdduvall if (bgep->factotum_flag == 0) { 39071369Sdduvall bgep->factotum_flag = 1; 39081369Sdduvall ddi_trigger_softintr(bgep->factotum_id); 39091369Sdduvall } 39101369Sdduvall mutex_exit(bgep->softintrlock); 39111369Sdduvall } 39121369Sdduvall 39131369Sdduvall /* 39141369Sdduvall * bge_intr() -- handle chip interrupts 39151369Sdduvall */ 39161369Sdduvall uint_t bge_intr(caddr_t arg1, caddr_t arg2); 39171369Sdduvall #pragma no_inline(bge_intr) 39181369Sdduvall 39191369Sdduvall uint_t 39201369Sdduvall bge_intr(caddr_t arg1, caddr_t arg2) 39211369Sdduvall { 39227099Syt223700 bge_t *bgep = (void *)arg1; /* private device info */ 39231369Sdduvall bge_status_t *bsp; 39241369Sdduvall uint64_t flags; 39253907Szh199473 uint32_t regval; 39261369Sdduvall uint_t result; 39273918Sml149210 int retval, loop_cnt = 0; 39281369Sdduvall 39291369Sdduvall BGE_TRACE(("bge_intr($%p) ($%p)", arg1, arg2)); 39301369Sdduvall 39311369Sdduvall /* 39321369Sdduvall * GLD v2 checks that s/w setup is complete before passing 39331369Sdduvall * interrupts to this routine, thus eliminating the old 39341369Sdduvall * (and well-known) race condition around ddi_add_intr() 39351369Sdduvall */ 39361369Sdduvall ASSERT(bgep->progress & PROGRESS_HWINT); 39371369Sdduvall 39381369Sdduvall result = DDI_INTR_UNCLAIMED; 39391369Sdduvall mutex_enter(bgep->genlock); 39401369Sdduvall 39413907Szh199473 if (bgep->intr_type == DDI_INTR_TYPE_FIXED) { 39421369Sdduvall /* 39433907Szh199473 * Check whether chip's says it's asserting #INTA; 39443907Szh199473 * if not, don't process or claim the interrupt. 39453907Szh199473 * 39463907Szh199473 * Note that the PCI signal is active low, so the 39473907Szh199473 * bit is *zero* when the interrupt is asserted. 39481369Sdduvall */ 39493907Szh199473 regval = bge_reg_get32(bgep, MISC_LOCAL_CONTROL_REG); 39503907Szh199473 if (regval & MLCR_INTA_STATE) { 39513907Szh199473 if (bge_check_acc_handle(bgep, bgep->io_handle) 39523907Szh199473 != DDI_FM_OK) 39531865Sdilpreet goto chip_stop; 39543907Szh199473 mutex_exit(bgep->genlock); 39553907Szh199473 return (result); 39561865Sdilpreet } 39571369Sdduvall 39581369Sdduvall /* 39593907Szh199473 * Block further PCI interrupts ... 39603907Szh199473 */ 39613907Szh199473 bge_reg_set32(bgep, PCI_CONF_BGE_MHCR, 39623907Szh199473 MHCR_MASK_PCI_INT_OUTPUT); 39633907Szh199473 39643907Szh199473 } else { 39653907Szh199473 /* 39663907Szh199473 * Check MSI status 39671369Sdduvall */ 39683907Szh199473 regval = bge_reg_get32(bgep, MSI_STATUS_REG); 39693907Szh199473 if (regval & MSI_ERROR_ATTENTION) { 39703907Szh199473 BGE_REPORT((bgep, "msi error attention," 39713907Szh199473 " status=0x%x", regval)); 39723907Szh199473 bge_reg_put32(bgep, MSI_STATUS_REG, regval); 39733907Szh199473 } 39743907Szh199473 } 39753907Szh199473 39763907Szh199473 result = DDI_INTR_CLAIMED; 39773907Szh199473 39783907Szh199473 BGE_DEBUG(("bge_intr($%p) ($%p) regval 0x%08x", arg1, arg2, regval)); 39793907Szh199473 39803907Szh199473 /* 39813907Szh199473 * Sync the status block and grab the flags-n-tag from it. 39823907Szh199473 * We count the number of interrupts where there doesn't 39833907Szh199473 * seem to have been a DMA update of the status block; if 39843907Szh199473 * it *has* been updated, the counter will be cleared in 39853907Szh199473 * the while() loop below ... 39863907Szh199473 */ 39873907Szh199473 bgep->missed_dmas += 1; 39883907Szh199473 bsp = DMA_VPTR(bgep->status_block); 39893918Sml149210 for (loop_cnt = 0; loop_cnt < bge_intr_max_loop; loop_cnt++) { 39903907Szh199473 if (bgep->bge_chip_state != BGE_CHIP_RUNNING) { 39911369Sdduvall /* 39923907Szh199473 * bge_chip_stop() may have freed dma area etc 39933907Szh199473 * while we were in this interrupt handler - 39943907Szh199473 * better not call bge_status_sync() 39951369Sdduvall */ 39963907Szh199473 (void) bge_check_acc_handle(bgep, 39973907Szh199473 bgep->io_handle); 39981369Sdduvall mutex_exit(bgep->genlock); 39993907Szh199473 return (DDI_INTR_CLAIMED); 40003907Szh199473 } 40013907Szh199473 retval = bge_status_sync(bgep, STATUS_FLAG_UPDATED, 40023907Szh199473 &flags); 40033907Szh199473 if (retval != DDI_FM_OK) { 40043907Szh199473 bgep->bge_dma_error = B_TRUE; 40053907Szh199473 goto chip_stop; 40061369Sdduvall } 40071369Sdduvall 40083907Szh199473 if (!(flags & STATUS_FLAG_UPDATED)) 40093907Szh199473 break; 40103907Szh199473 40113907Szh199473 /* 40123907Szh199473 * Tell the chip that we're processing the interrupt 40133907Szh199473 */ 40143907Szh199473 bge_mbx_put(bgep, INTERRUPT_MBOX_0_REG, 40153907Szh199473 INTERRUPT_MBOX_DISABLE(flags)); 40163907Szh199473 if (bge_check_acc_handle(bgep, bgep->io_handle) != 40173907Szh199473 DDI_FM_OK) 40183907Szh199473 goto chip_stop; 40193907Szh199473 40201369Sdduvall /* 40213907Szh199473 * Drop the mutex while we: 40223907Szh199473 * Receive any newly-arrived packets 40233907Szh199473 * Recycle any newly-finished send buffers 40241369Sdduvall */ 40253907Szh199473 bgep->bge_intr_running = B_TRUE; 40263907Szh199473 mutex_exit(bgep->genlock); 40273907Szh199473 bge_receive(bgep, bsp); 40283907Szh199473 bge_recycle(bgep, bsp); 40293907Szh199473 mutex_enter(bgep->genlock); 40303907Szh199473 bgep->bge_intr_running = B_FALSE; 40311369Sdduvall 40321369Sdduvall /* 40333907Szh199473 * Tell the chip we've finished processing, and 40343907Szh199473 * give it the tag that we got from the status 40353907Szh199473 * block earlier, so that it knows just how far 40363907Szh199473 * we've gone. If it's got more for us to do, 40373907Szh199473 * it will now update the status block and try 40383907Szh199473 * to assert an interrupt (but we've got the 40393907Szh199473 * #INTA blocked at present). If we see the 40403907Szh199473 * update, we'll loop around to do some more. 40413907Szh199473 * Eventually we'll get out of here ... 40423907Szh199473 */ 40433907Szh199473 bge_mbx_put(bgep, INTERRUPT_MBOX_0_REG, 40443907Szh199473 INTERRUPT_MBOX_ENABLE(flags)); 40456546Sgh162552 if (bgep->chipid.pci_type == BGE_PCI_E) 40466546Sgh162552 (void) bge_mbx_get(bgep, INTERRUPT_MBOX_0_REG); 40473907Szh199473 bgep->missed_dmas = 0; 40483907Szh199473 } 40493907Szh199473 40503907Szh199473 /* 40513907Szh199473 * Check for exceptional conditions that we need to handle 40523907Szh199473 * 40533907Szh199473 * Link status changed 40543907Szh199473 * Status block not updated 40553907Szh199473 */ 40563907Szh199473 if (flags & STATUS_FLAG_LINK_CHANGED) 40573907Szh199473 bge_wake_factotum(bgep); 40583907Szh199473 40593907Szh199473 if (bgep->missed_dmas) { 40603907Szh199473 /* 40613907Szh199473 * Probably due to the internal status tag not 40623907Szh199473 * being reset. Force a status block update now; 40633907Szh199473 * this should ensure that we get an update and 40643907Szh199473 * a new interrupt. After that, we should be in 40653907Szh199473 * sync again ... 40661369Sdduvall */ 40673907Szh199473 BGE_REPORT((bgep, "interrupt: flags 0x%llx - " 40683907Szh199473 "not updated?", flags)); 40693907Szh199473 bgep->missed_updates++; 40703907Szh199473 bge_reg_set32(bgep, HOST_COALESCE_MODE_REG, 40713907Szh199473 COALESCE_NOW); 40723907Szh199473 40733907Szh199473 if (bgep->missed_dmas >= bge_dma_miss_limit) { 40743907Szh199473 /* 40753907Szh199473 * If this happens multiple times in a row, 40763907Szh199473 * it means DMA is just not working. Maybe 40773907Szh199473 * the chip's failed, or maybe there's a 40783907Szh199473 * problem on the PCI bus or in the host-PCI 40793907Szh199473 * bridge (Tomatillo). 40803907Szh199473 * 40813907Szh199473 * At all events, we want to stop further 40823907Szh199473 * interrupts and let the recovery code take 40833907Szh199473 * over to see whether anything can be done 40843907Szh199473 * about it ... 40853907Szh199473 */ 40863907Szh199473 bge_fm_ereport(bgep, 40873907Szh199473 DDI_FM_DEVICE_BADINT_LIMIT); 40883907Szh199473 goto chip_stop; 40891369Sdduvall } 40901369Sdduvall } 40911369Sdduvall 40923907Szh199473 /* 40933907Szh199473 * Reenable assertion of #INTA, unless there's a DMA fault 40943907Szh199473 */ 40953907Szh199473 if (bgep->intr_type == DDI_INTR_TYPE_FIXED) { 40963907Szh199473 bge_reg_clr32(bgep, PCI_CONF_BGE_MHCR, 40973907Szh199473 MHCR_MASK_PCI_INT_OUTPUT); 40983907Szh199473 if (bge_check_acc_handle(bgep, bgep->cfg_handle) != 40993907Szh199473 DDI_FM_OK) 41003907Szh199473 goto chip_stop; 41013907Szh199473 } 41023907Szh199473 41031865Sdilpreet if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) 41041865Sdilpreet goto chip_stop; 41051865Sdilpreet 41061865Sdilpreet mutex_exit(bgep->genlock); 41071865Sdilpreet return (result); 41081865Sdilpreet 41091865Sdilpreet chip_stop: 41101865Sdilpreet #ifdef BGE_IPMI_ASF 41111865Sdilpreet if (bgep->asf_enabled && bgep->asf_status == ASF_STAT_RUN) { 41121865Sdilpreet /* 41131865Sdilpreet * We must stop ASF heart beat before 41141865Sdilpreet * bge_chip_stop(), otherwise some 41151865Sdilpreet * computers (ex. IBM HS20 blade 41161865Sdilpreet * server) may crash. 41171865Sdilpreet */ 41181865Sdilpreet bge_asf_update_status(bgep); 41191865Sdilpreet bge_asf_stop_timer(bgep); 41201865Sdilpreet bgep->asf_status = ASF_STAT_STOP; 41211865Sdilpreet 41221865Sdilpreet bge_asf_pre_reset_operations(bgep, BGE_INIT_RESET); 41231865Sdilpreet (void) bge_check_acc_handle(bgep, bgep->cfg_handle); 41241865Sdilpreet } 41251865Sdilpreet #endif 41261865Sdilpreet bge_chip_stop(bgep, B_TRUE); 41271865Sdilpreet (void) bge_check_acc_handle(bgep, bgep->io_handle); 41281369Sdduvall mutex_exit(bgep->genlock); 41291369Sdduvall return (result); 41301369Sdduvall } 41311369Sdduvall 41321369Sdduvall /* 41331369Sdduvall * ========== Factotum, implemented as a softint handler ========== 41341369Sdduvall */ 41351369Sdduvall 41361369Sdduvall #undef BGE_DBG 41371369Sdduvall #define BGE_DBG BGE_DBG_FACT /* debug flag for this code */ 41381369Sdduvall 41391369Sdduvall static void bge_factotum_error_handler(bge_t *bgep); 41401369Sdduvall #pragma no_inline(bge_factotum_error_handler) 41411369Sdduvall 41421369Sdduvall static void 41431369Sdduvall bge_factotum_error_handler(bge_t *bgep) 41441369Sdduvall { 41451369Sdduvall uint32_t flow; 41461369Sdduvall uint32_t rdma; 41471369Sdduvall uint32_t wdma; 41481369Sdduvall uint32_t tmac; 41491369Sdduvall uint32_t rmac; 41501369Sdduvall uint32_t rxrs; 41511369Sdduvall uint32_t txrs = 0; 41521369Sdduvall 41531369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 41541369Sdduvall 41551369Sdduvall /* 41561369Sdduvall * Read all the registers that show the possible 41571369Sdduvall * reasons for the ERROR bit to be asserted 41581369Sdduvall */ 41591369Sdduvall flow = bge_reg_get32(bgep, FLOW_ATTN_REG); 41601369Sdduvall rdma = bge_reg_get32(bgep, READ_DMA_STATUS_REG); 41611369Sdduvall wdma = bge_reg_get32(bgep, WRITE_DMA_STATUS_REG); 41621369Sdduvall tmac = bge_reg_get32(bgep, TRANSMIT_MAC_STATUS_REG); 41631369Sdduvall rmac = bge_reg_get32(bgep, RECEIVE_MAC_STATUS_REG); 41641369Sdduvall rxrs = bge_reg_get32(bgep, RX_RISC_STATE_REG); 41651369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) 41661369Sdduvall txrs = bge_reg_get32(bgep, TX_RISC_STATE_REG); 41671369Sdduvall 41681369Sdduvall BGE_DEBUG(("factotum($%p) flow 0x%x rdma 0x%x wdma 0x%x", 41694588Sml149210 (void *)bgep, flow, rdma, wdma)); 41701369Sdduvall BGE_DEBUG(("factotum($%p) tmac 0x%x rmac 0x%x rxrs 0x%08x txrs 0x%08x", 41714588Sml149210 (void *)bgep, tmac, rmac, rxrs, txrs)); 41721369Sdduvall 41731369Sdduvall /* 41741369Sdduvall * For now, just clear all the errors ... 41751369Sdduvall */ 41761369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) 41771369Sdduvall bge_reg_put32(bgep, TX_RISC_STATE_REG, ~0); 41781369Sdduvall bge_reg_put32(bgep, RX_RISC_STATE_REG, ~0); 41791369Sdduvall bge_reg_put32(bgep, RECEIVE_MAC_STATUS_REG, ~0); 41801369Sdduvall bge_reg_put32(bgep, WRITE_DMA_STATUS_REG, ~0); 41811369Sdduvall bge_reg_put32(bgep, READ_DMA_STATUS_REG, ~0); 41821369Sdduvall bge_reg_put32(bgep, FLOW_ATTN_REG, ~0); 41831369Sdduvall } 41841369Sdduvall 41851369Sdduvall /* 41861369Sdduvall * Handler for hardware link state change. 41871369Sdduvall * 41881369Sdduvall * When this routine is called, the hardware link state has changed 41891369Sdduvall * and the new state is reflected in the param_* variables. Here 41904403Sgd78059 * we must update the softstate and reprogram the MAC to match. 41911369Sdduvall */ 41921369Sdduvall static void bge_factotum_link_handler(bge_t *bgep); 41931369Sdduvall #pragma no_inline(bge_factotum_link_handler) 41941369Sdduvall 41951369Sdduvall static void 41961369Sdduvall bge_factotum_link_handler(bge_t *bgep) 41971369Sdduvall { 41981369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 41991369Sdduvall 42001369Sdduvall /* 42011369Sdduvall * Update the s/w link_state 42021369Sdduvall */ 42031369Sdduvall if (bgep->param_link_up) 42041369Sdduvall bgep->link_state = LINK_STATE_UP; 42051369Sdduvall else 42061369Sdduvall bgep->link_state = LINK_STATE_DOWN; 42071369Sdduvall 42081369Sdduvall /* 42091369Sdduvall * Reprogram the MAC modes to match 42101369Sdduvall */ 42111369Sdduvall bge_sync_mac_modes(bgep); 42121369Sdduvall } 42131369Sdduvall 42141865Sdilpreet static boolean_t bge_factotum_link_check(bge_t *bgep, int *dma_state); 42151369Sdduvall #pragma no_inline(bge_factotum_link_check) 42161369Sdduvall 42171369Sdduvall static boolean_t 42181865Sdilpreet bge_factotum_link_check(bge_t *bgep, int *dma_state) 42191369Sdduvall { 42201369Sdduvall boolean_t check; 42211369Sdduvall uint64_t flags; 42221369Sdduvall uint32_t tmac_status; 42231369Sdduvall 42241369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 42251369Sdduvall 42261369Sdduvall /* 42271369Sdduvall * Get & clear the writable status bits in the Tx status register 42281369Sdduvall * (some bits are write-1-to-clear, others are just readonly). 42291369Sdduvall */ 42301369Sdduvall tmac_status = bge_reg_get32(bgep, TRANSMIT_MAC_STATUS_REG); 42311369Sdduvall bge_reg_put32(bgep, TRANSMIT_MAC_STATUS_REG, tmac_status); 42321369Sdduvall 42331369Sdduvall /* 42341369Sdduvall * Get & clear the ERROR and LINK_CHANGED bits from the status block 42351369Sdduvall */ 42361865Sdilpreet *dma_state = bge_status_sync(bgep, STATUS_FLAG_ERROR | 42371865Sdilpreet STATUS_FLAG_LINK_CHANGED, &flags); 42381865Sdilpreet if (*dma_state != DDI_FM_OK) 42391865Sdilpreet return (B_FALSE); 42401369Sdduvall 42411369Sdduvall /* 42421369Sdduvall * Clear any errors flagged in the status block ... 42431369Sdduvall */ 42441369Sdduvall if (flags & STATUS_FLAG_ERROR) 42451369Sdduvall bge_factotum_error_handler(bgep); 42461369Sdduvall 42471369Sdduvall /* 42481369Sdduvall * We need to check the link status if: 42491369Sdduvall * the status block says there's been a link change 42501369Sdduvall * or there's any discrepancy between the various 42511369Sdduvall * flags indicating the link state (link_state, 42521369Sdduvall * param_link_up, and the LINK STATE bit in the 42531369Sdduvall * Transmit MAC status register). 42541369Sdduvall */ 42551369Sdduvall check = (flags & STATUS_FLAG_LINK_CHANGED) != 0; 42561369Sdduvall switch (bgep->link_state) { 42571369Sdduvall case LINK_STATE_UP: 42581369Sdduvall check |= (bgep->param_link_up == B_FALSE); 42591369Sdduvall check |= ((tmac_status & TRANSMIT_STATUS_LINK_UP) == 0); 42601369Sdduvall break; 42611369Sdduvall 42621369Sdduvall case LINK_STATE_DOWN: 42631369Sdduvall check |= (bgep->param_link_up != B_FALSE); 42641369Sdduvall check |= ((tmac_status & TRANSMIT_STATUS_LINK_UP) != 0); 42651369Sdduvall break; 42661369Sdduvall 42671369Sdduvall default: 42681369Sdduvall check = B_TRUE; 42691369Sdduvall break; 42701369Sdduvall } 42711369Sdduvall 42721369Sdduvall /* 42731369Sdduvall * If <check> is false, we're sure the link hasn't changed. 42741369Sdduvall * If true, however, it's not yet definitive; we have to call 42751369Sdduvall * bge_phys_check() to determine whether the link has settled 42761369Sdduvall * into a new state yet ... and if it has, then call the link 42771369Sdduvall * state change handler.But when the chip is 5700 in Dell 6650 42781369Sdduvall * ,even if check is false, the link may have changed.So we 42791369Sdduvall * have to call bge_phys_check() to determine the link state. 42801369Sdduvall */ 42811369Sdduvall if (check || bgep->chipid.device == DEVICE_ID_5700) { 42821369Sdduvall check = bge_phys_check(bgep); 42831369Sdduvall if (check) 42841369Sdduvall bge_factotum_link_handler(bgep); 42851369Sdduvall } 42861369Sdduvall 42871369Sdduvall return (check); 42881369Sdduvall } 42891369Sdduvall 42901369Sdduvall /* 42911369Sdduvall * Factotum routine to check for Tx stall, using the 'watchdog' counter 42921369Sdduvall */ 42931369Sdduvall static boolean_t bge_factotum_stall_check(bge_t *bgep); 42941369Sdduvall #pragma no_inline(bge_factotum_stall_check) 42951369Sdduvall 42961369Sdduvall static boolean_t 42971369Sdduvall bge_factotum_stall_check(bge_t *bgep) 42981369Sdduvall { 42991369Sdduvall uint32_t dogval; 43001369Sdduvall 43011369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 43021369Sdduvall 43031369Sdduvall /* 43041369Sdduvall * Specific check for Tx stall ... 43051369Sdduvall * 43061369Sdduvall * The 'watchdog' counter is incremented whenever a packet 43071369Sdduvall * is queued, reset to 1 when some (but not all) buffers 43081369Sdduvall * are reclaimed, reset to 0 (disabled) when all buffers 43091369Sdduvall * are reclaimed, and shifted left here. If it exceeds the 43101369Sdduvall * threshold value, the chip is assumed to have stalled and 43111369Sdduvall * is put into the ERROR state. The factotum will then reset 43121369Sdduvall * it on the next pass. 43131369Sdduvall * 43141369Sdduvall * All of which should ensure that we don't get into a state 43151369Sdduvall * where packets are left pending indefinitely! 43161369Sdduvall */ 43171369Sdduvall dogval = bge_atomic_shl32(&bgep->watchdog, 1); 43181369Sdduvall if (dogval < bge_watchdog_count) 43191369Sdduvall return (B_FALSE); 43201369Sdduvall 43213918Sml149210 #if !defined(BGE_NETCONSOLE) 43221369Sdduvall BGE_REPORT((bgep, "Tx stall detected, watchdog code 0x%x", dogval)); 43233918Sml149210 #endif 43241865Sdilpreet bge_fm_ereport(bgep, DDI_FM_DEVICE_STALL); 43251369Sdduvall return (B_TRUE); 43261369Sdduvall } 43271369Sdduvall 43281369Sdduvall /* 43291369Sdduvall * The factotum is woken up when there's something to do that we'd rather 43301369Sdduvall * not do from inside a hardware interrupt handler or high-level cyclic. 43311369Sdduvall * Its two main tasks are: 43321369Sdduvall * reset & restart the chip after an error 43331369Sdduvall * check the link status whenever necessary 43341369Sdduvall */ 43351369Sdduvall uint_t bge_chip_factotum(caddr_t arg); 43361369Sdduvall #pragma no_inline(bge_chip_factotum) 43371369Sdduvall 43381369Sdduvall uint_t 43391369Sdduvall bge_chip_factotum(caddr_t arg) 43401369Sdduvall { 43411369Sdduvall bge_t *bgep; 43421369Sdduvall uint_t result; 43431369Sdduvall boolean_t error; 43441369Sdduvall boolean_t linkchg; 43451865Sdilpreet int dma_state; 43461369Sdduvall 43477099Syt223700 bgep = (void *)arg; 43481369Sdduvall 43491369Sdduvall BGE_TRACE(("bge_chip_factotum($%p)", (void *)bgep)); 43501369Sdduvall 43511369Sdduvall mutex_enter(bgep->softintrlock); 43521369Sdduvall if (bgep->factotum_flag == 0) { 43531369Sdduvall mutex_exit(bgep->softintrlock); 43541369Sdduvall return (DDI_INTR_UNCLAIMED); 43551369Sdduvall } 43561504Sly149593 bgep->factotum_flag = 0; 43571369Sdduvall mutex_exit(bgep->softintrlock); 43581369Sdduvall 43591369Sdduvall result = DDI_INTR_CLAIMED; 43601369Sdduvall error = B_FALSE; 43611369Sdduvall linkchg = B_FALSE; 43621369Sdduvall 43631369Sdduvall mutex_enter(bgep->genlock); 43641369Sdduvall switch (bgep->bge_chip_state) { 43651369Sdduvall default: 43661369Sdduvall break; 43671369Sdduvall 43681369Sdduvall case BGE_CHIP_RUNNING: 43691865Sdilpreet linkchg = bge_factotum_link_check(bgep, &dma_state); 43701369Sdduvall error = bge_factotum_stall_check(bgep); 43711865Sdilpreet if (dma_state != DDI_FM_OK) { 43721865Sdilpreet bgep->bge_dma_error = B_TRUE; 43731865Sdilpreet error = B_TRUE; 43741865Sdilpreet } 43751865Sdilpreet if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) 43761865Sdilpreet error = B_TRUE; 43771865Sdilpreet if (error) 43781865Sdilpreet bgep->bge_chip_state = BGE_CHIP_ERROR; 43791369Sdduvall break; 43801369Sdduvall 43811369Sdduvall case BGE_CHIP_ERROR: 43821369Sdduvall error = B_TRUE; 43831369Sdduvall break; 43841369Sdduvall 43851369Sdduvall case BGE_CHIP_FAULT: 43861369Sdduvall /* 43871369Sdduvall * Fault detected, time to reset ... 43881369Sdduvall */ 43891369Sdduvall if (bge_autorecover) { 43901865Sdilpreet if (!(bgep->progress & PROGRESS_BUFS)) { 43911865Sdilpreet /* 43921865Sdilpreet * if we can't allocate the ring buffers, 43931865Sdilpreet * try later 43941865Sdilpreet */ 43951865Sdilpreet if (bge_alloc_bufs(bgep) != DDI_SUCCESS) { 43961865Sdilpreet mutex_exit(bgep->genlock); 43971865Sdilpreet return (result); 43981865Sdilpreet } 43991865Sdilpreet bgep->progress |= PROGRESS_BUFS; 44001865Sdilpreet } 44011865Sdilpreet if (!(bgep->progress & PROGRESS_INTR)) { 44021865Sdilpreet bge_init_rings(bgep); 44031865Sdilpreet bge_intr_enable(bgep); 44041865Sdilpreet bgep->progress |= PROGRESS_INTR; 44051865Sdilpreet } 44061865Sdilpreet if (!(bgep->progress & PROGRESS_KSTATS)) { 44071865Sdilpreet bge_init_kstats(bgep, 44081865Sdilpreet ddi_get_instance(bgep->devinfo)); 44091865Sdilpreet bgep->progress |= PROGRESS_KSTATS; 44101865Sdilpreet } 44111865Sdilpreet 44121369Sdduvall BGE_REPORT((bgep, "automatic recovery activated")); 44131865Sdilpreet 44141865Sdilpreet if (bge_restart(bgep, B_FALSE) != DDI_SUCCESS) { 44151865Sdilpreet bgep->bge_chip_state = BGE_CHIP_ERROR; 44161865Sdilpreet error = B_TRUE; 44171865Sdilpreet } 44181865Sdilpreet if (bge_check_acc_handle(bgep, bgep->cfg_handle) != 44191865Sdilpreet DDI_FM_OK) { 44201865Sdilpreet bgep->bge_chip_state = BGE_CHIP_ERROR; 44211865Sdilpreet error = B_TRUE; 44221865Sdilpreet } 44231865Sdilpreet if (bge_check_acc_handle(bgep, bgep->io_handle) != 44241865Sdilpreet DDI_FM_OK) { 44251865Sdilpreet bgep->bge_chip_state = BGE_CHIP_ERROR; 44261865Sdilpreet error = B_TRUE; 44271865Sdilpreet } 44281865Sdilpreet if (error == B_FALSE) { 44291408Srandyf #ifdef BGE_IPMI_ASF 44301865Sdilpreet if (bgep->asf_enabled && 44311865Sdilpreet bgep->asf_status != ASF_STAT_RUN) { 44321408Srandyf bgep->asf_timeout_id = timeout( 44331865Sdilpreet bge_asf_heartbeat, (void *)bgep, 44341865Sdilpreet drv_usectohz( 44351865Sdilpreet BGE_ASF_HEARTBEAT_INTERVAL)); 44361408Srandyf bgep->asf_status = ASF_STAT_RUN; 44371408Srandyf } 44381865Sdilpreet #endif 44395903Ssowmini if (!bgep->manual_reset) { 44405903Ssowmini ddi_fm_service_impact(bgep->devinfo, 44415903Ssowmini DDI_SERVICE_RESTORED); 44425903Ssowmini } 44431408Srandyf } 44441369Sdduvall } 44451369Sdduvall break; 44461369Sdduvall } 44471369Sdduvall 44481865Sdilpreet 44491369Sdduvall /* 44501369Sdduvall * If an error is detected, stop the chip now, marking it as 44511369Sdduvall * faulty, so that it will be reset next time through ... 44521865Sdilpreet * 44531865Sdilpreet * Note that if intr_running is set, then bge_intr() has dropped 44541865Sdilpreet * genlock to call bge_receive/bge_recycle. Can't stop the chip at 44551865Sdilpreet * this point so have to wait until the next time the factotum runs. 44561369Sdduvall */ 44571865Sdilpreet if (error && !bgep->bge_intr_running) { 44581408Srandyf #ifdef BGE_IPMI_ASF 44591408Srandyf if (bgep->asf_enabled && (bgep->asf_status == ASF_STAT_RUN)) { 44601408Srandyf /* 44611408Srandyf * We must stop ASF heart beat before bge_chip_stop(), 44621408Srandyf * otherwise some computers (ex. IBM HS20 blade server) 44631408Srandyf * may crash. 44641408Srandyf */ 44651408Srandyf bge_asf_update_status(bgep); 44661408Srandyf bge_asf_stop_timer(bgep); 44671408Srandyf bgep->asf_status = ASF_STAT_STOP; 44681408Srandyf 44691408Srandyf bge_asf_pre_reset_operations(bgep, BGE_INIT_RESET); 44701865Sdilpreet (void) bge_check_acc_handle(bgep, bgep->cfg_handle); 44711408Srandyf } 44721408Srandyf #endif 44731369Sdduvall bge_chip_stop(bgep, B_TRUE); 44741865Sdilpreet (void) bge_check_acc_handle(bgep, bgep->io_handle); 44751408Srandyf } 44761369Sdduvall mutex_exit(bgep->genlock); 44771369Sdduvall 44781369Sdduvall /* 44791369Sdduvall * If the link state changed, tell the world about it. 44801369Sdduvall * Note: can't do this while still holding the mutex. 44811369Sdduvall */ 44826546Sgh162552 if (bgep->link_update_timer == BGE_LINK_UPDATE_TIMEOUT && 44836546Sgh162552 bgep->link_state != LINK_STATE_UNKNOWN) 44846546Sgh162552 linkchg = B_TRUE; 44856546Sgh162552 else if (bgep->link_update_timer < BGE_LINK_UPDATE_TIMEOUT && 44866546Sgh162552 bgep->link_state == LINK_STATE_DOWN) 44876546Sgh162552 linkchg = B_FALSE; 44886546Sgh162552 44896546Sgh162552 if (linkchg) { 44902311Sseb mac_link_update(bgep->mh, bgep->link_state); 44916546Sgh162552 bgep->link_update_timer = BGE_LINK_UPDATE_DONE; 44926546Sgh162552 } 44935903Ssowmini if (bgep->manual_reset) { 44945903Ssowmini bgep->manual_reset = B_FALSE; 44955903Ssowmini } 44961369Sdduvall 44971369Sdduvall return (result); 44981369Sdduvall } 44991369Sdduvall 45001369Sdduvall /* 45011369Sdduvall * High-level cyclic handler 45021369Sdduvall * 45031369Sdduvall * This routine schedules a (low-level) softint callback to the 45041369Sdduvall * factotum, and prods the chip to update the status block (which 45051369Sdduvall * will cause a hardware interrupt when complete). 45061369Sdduvall */ 45071369Sdduvall void bge_chip_cyclic(void *arg); 45081369Sdduvall #pragma no_inline(bge_chip_cyclic) 45091369Sdduvall 45101369Sdduvall void 45111369Sdduvall bge_chip_cyclic(void *arg) 45121369Sdduvall { 45131369Sdduvall bge_t *bgep; 45141369Sdduvall 45151369Sdduvall bgep = arg; 45161369Sdduvall 45171369Sdduvall switch (bgep->bge_chip_state) { 45181369Sdduvall default: 45191369Sdduvall return; 45201369Sdduvall 45211369Sdduvall case BGE_CHIP_RUNNING: 45221369Sdduvall bge_reg_set32(bgep, HOST_COALESCE_MODE_REG, COALESCE_NOW); 45231865Sdilpreet if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) 45241865Sdilpreet ddi_fm_service_impact(bgep->devinfo, 45251865Sdilpreet DDI_SERVICE_UNAFFECTED); 45266546Sgh162552 45276546Sgh162552 if (bgep->link_update_timer < BGE_LINK_UPDATE_TIMEOUT) 45286546Sgh162552 bgep->link_update_timer++; 45296546Sgh162552 45301369Sdduvall break; 45311369Sdduvall 45321369Sdduvall case BGE_CHIP_FAULT: 45331369Sdduvall case BGE_CHIP_ERROR: 45341369Sdduvall break; 45351369Sdduvall } 45361369Sdduvall 45371369Sdduvall bge_wake_factotum(bgep); 45381369Sdduvall } 45391369Sdduvall 45401369Sdduvall 45411369Sdduvall /* 45421369Sdduvall * ========== Ioctl subfunctions ========== 45431369Sdduvall */ 45441369Sdduvall 45451369Sdduvall #undef BGE_DBG 45461369Sdduvall #define BGE_DBG BGE_DBG_PPIO /* debug flag for this code */ 45471369Sdduvall 45481369Sdduvall #if BGE_DEBUGGING || BGE_DO_PPIO 45491369Sdduvall 45501369Sdduvall static void bge_chip_peek_cfg(bge_t *bgep, bge_peekpoke_t *ppd); 45511369Sdduvall #pragma no_inline(bge_chip_peek_cfg) 45521369Sdduvall 45531369Sdduvall static void 45541369Sdduvall bge_chip_peek_cfg(bge_t *bgep, bge_peekpoke_t *ppd) 45551369Sdduvall { 45561369Sdduvall uint64_t regval; 45571369Sdduvall uint64_t regno; 45581369Sdduvall 45591369Sdduvall BGE_TRACE(("bge_chip_peek_cfg($%p, $%p)", 45604588Sml149210 (void *)bgep, (void *)ppd)); 45611369Sdduvall 45621369Sdduvall regno = ppd->pp_acc_offset; 45631369Sdduvall 45641369Sdduvall switch (ppd->pp_acc_size) { 45651369Sdduvall case 1: 45661369Sdduvall regval = pci_config_get8(bgep->cfg_handle, regno); 45671369Sdduvall break; 45681369Sdduvall 45691369Sdduvall case 2: 45701369Sdduvall regval = pci_config_get16(bgep->cfg_handle, regno); 45711369Sdduvall break; 45721369Sdduvall 45731369Sdduvall case 4: 45741369Sdduvall regval = pci_config_get32(bgep->cfg_handle, regno); 45751369Sdduvall break; 45761369Sdduvall 45771369Sdduvall case 8: 45781369Sdduvall regval = pci_config_get64(bgep->cfg_handle, regno); 45791369Sdduvall break; 45801369Sdduvall } 45811369Sdduvall 45821369Sdduvall ppd->pp_acc_data = regval; 45831369Sdduvall } 45841369Sdduvall 45851369Sdduvall static void bge_chip_poke_cfg(bge_t *bgep, bge_peekpoke_t *ppd); 45861369Sdduvall #pragma no_inline(bge_chip_poke_cfg) 45871369Sdduvall 45881369Sdduvall static void 45891369Sdduvall bge_chip_poke_cfg(bge_t *bgep, bge_peekpoke_t *ppd) 45901369Sdduvall { 45911369Sdduvall uint64_t regval; 45921369Sdduvall uint64_t regno; 45931369Sdduvall 45941369Sdduvall BGE_TRACE(("bge_chip_poke_cfg($%p, $%p)", 45954588Sml149210 (void *)bgep, (void *)ppd)); 45961369Sdduvall 45971369Sdduvall regno = ppd->pp_acc_offset; 45981369Sdduvall regval = ppd->pp_acc_data; 45991369Sdduvall 46001369Sdduvall switch (ppd->pp_acc_size) { 46011369Sdduvall case 1: 46021369Sdduvall pci_config_put8(bgep->cfg_handle, regno, regval); 46031369Sdduvall break; 46041369Sdduvall 46051369Sdduvall case 2: 46061369Sdduvall pci_config_put16(bgep->cfg_handle, regno, regval); 46071369Sdduvall break; 46081369Sdduvall 46091369Sdduvall case 4: 46101369Sdduvall pci_config_put32(bgep->cfg_handle, regno, regval); 46111369Sdduvall break; 46121369Sdduvall 46131369Sdduvall case 8: 46141369Sdduvall pci_config_put64(bgep->cfg_handle, regno, regval); 46151369Sdduvall break; 46161369Sdduvall } 46171369Sdduvall } 46181369Sdduvall 46191369Sdduvall static void bge_chip_peek_reg(bge_t *bgep, bge_peekpoke_t *ppd); 46201369Sdduvall #pragma no_inline(bge_chip_peek_reg) 46211369Sdduvall 46221369Sdduvall static void 46231369Sdduvall bge_chip_peek_reg(bge_t *bgep, bge_peekpoke_t *ppd) 46241369Sdduvall { 46251369Sdduvall uint64_t regval; 46261369Sdduvall void *regaddr; 46271369Sdduvall 46281369Sdduvall BGE_TRACE(("bge_chip_peek_reg($%p, $%p)", 46294588Sml149210 (void *)bgep, (void *)ppd)); 46301369Sdduvall 46311369Sdduvall regaddr = PIO_ADDR(bgep, ppd->pp_acc_offset); 46321369Sdduvall 46331369Sdduvall switch (ppd->pp_acc_size) { 46341369Sdduvall case 1: 46351369Sdduvall regval = ddi_get8(bgep->io_handle, regaddr); 46361369Sdduvall break; 46371369Sdduvall 46381369Sdduvall case 2: 46391369Sdduvall regval = ddi_get16(bgep->io_handle, regaddr); 46401369Sdduvall break; 46411369Sdduvall 46421369Sdduvall case 4: 46431369Sdduvall regval = ddi_get32(bgep->io_handle, regaddr); 46441369Sdduvall break; 46451369Sdduvall 46461369Sdduvall case 8: 46471369Sdduvall regval = ddi_get64(bgep->io_handle, regaddr); 46481369Sdduvall break; 46491369Sdduvall } 46501369Sdduvall 46511369Sdduvall ppd->pp_acc_data = regval; 46521369Sdduvall } 46531369Sdduvall 46541369Sdduvall static void bge_chip_poke_reg(bge_t *bgep, bge_peekpoke_t *ppd); 46551369Sdduvall #pragma no_inline(bge_chip_peek_reg) 46561369Sdduvall 46571369Sdduvall static void 46581369Sdduvall bge_chip_poke_reg(bge_t *bgep, bge_peekpoke_t *ppd) 46591369Sdduvall { 46601369Sdduvall uint64_t regval; 46611369Sdduvall void *regaddr; 46621369Sdduvall 46631369Sdduvall BGE_TRACE(("bge_chip_poke_reg($%p, $%p)", 46644588Sml149210 (void *)bgep, (void *)ppd)); 46651369Sdduvall 46661369Sdduvall regaddr = PIO_ADDR(bgep, ppd->pp_acc_offset); 46671369Sdduvall regval = ppd->pp_acc_data; 46681369Sdduvall 46691369Sdduvall switch (ppd->pp_acc_size) { 46701369Sdduvall case 1: 46711369Sdduvall ddi_put8(bgep->io_handle, regaddr, regval); 46721369Sdduvall break; 46731369Sdduvall 46741369Sdduvall case 2: 46751369Sdduvall ddi_put16(bgep->io_handle, regaddr, regval); 46761369Sdduvall break; 46771369Sdduvall 46781369Sdduvall case 4: 46791369Sdduvall ddi_put32(bgep->io_handle, regaddr, regval); 46801369Sdduvall break; 46811369Sdduvall 46821369Sdduvall case 8: 46831369Sdduvall ddi_put64(bgep->io_handle, regaddr, regval); 46841369Sdduvall break; 46851369Sdduvall } 46861369Sdduvall BGE_PCICHK(bgep); 46871369Sdduvall } 46881369Sdduvall 46891369Sdduvall static void bge_chip_peek_nic(bge_t *bgep, bge_peekpoke_t *ppd); 46901369Sdduvall #pragma no_inline(bge_chip_peek_nic) 46911369Sdduvall 46921369Sdduvall static void 46931369Sdduvall bge_chip_peek_nic(bge_t *bgep, bge_peekpoke_t *ppd) 46941369Sdduvall { 46951369Sdduvall uint64_t regoff; 46961369Sdduvall uint64_t regval; 46971369Sdduvall void *regaddr; 46981369Sdduvall 46991369Sdduvall BGE_TRACE(("bge_chip_peek_nic($%p, $%p)", 47004588Sml149210 (void *)bgep, (void *)ppd)); 47011369Sdduvall 47021369Sdduvall regoff = ppd->pp_acc_offset; 47031369Sdduvall bge_nic_setwin(bgep, regoff & ~MWBAR_GRANULE_MASK); 47041369Sdduvall regoff &= MWBAR_GRANULE_MASK; 47051369Sdduvall regoff += NIC_MEM_WINDOW_OFFSET; 47061369Sdduvall regaddr = PIO_ADDR(bgep, regoff); 47071369Sdduvall 47081369Sdduvall switch (ppd->pp_acc_size) { 47091369Sdduvall case 1: 47101369Sdduvall regval = ddi_get8(bgep->io_handle, regaddr); 47111369Sdduvall break; 47121369Sdduvall 47131369Sdduvall case 2: 47141369Sdduvall regval = ddi_get16(bgep->io_handle, regaddr); 47151369Sdduvall break; 47161369Sdduvall 47171369Sdduvall case 4: 47181369Sdduvall regval = ddi_get32(bgep->io_handle, regaddr); 47191369Sdduvall break; 47201369Sdduvall 47211369Sdduvall case 8: 47221369Sdduvall regval = ddi_get64(bgep->io_handle, regaddr); 47231369Sdduvall break; 47241369Sdduvall } 47251369Sdduvall 47261369Sdduvall ppd->pp_acc_data = regval; 47271369Sdduvall } 47281369Sdduvall 47291369Sdduvall static void bge_chip_poke_nic(bge_t *bgep, bge_peekpoke_t *ppd); 47301369Sdduvall #pragma no_inline(bge_chip_poke_nic) 47311369Sdduvall 47321369Sdduvall static void 47331369Sdduvall bge_chip_poke_nic(bge_t *bgep, bge_peekpoke_t *ppd) 47341369Sdduvall { 47351369Sdduvall uint64_t regoff; 47361369Sdduvall uint64_t regval; 47371369Sdduvall void *regaddr; 47381369Sdduvall 47391369Sdduvall BGE_TRACE(("bge_chip_poke_nic($%p, $%p)", 47404588Sml149210 (void *)bgep, (void *)ppd)); 47411369Sdduvall 47421369Sdduvall regoff = ppd->pp_acc_offset; 47431369Sdduvall bge_nic_setwin(bgep, regoff & ~MWBAR_GRANULE_MASK); 47441369Sdduvall regoff &= MWBAR_GRANULE_MASK; 47451369Sdduvall regoff += NIC_MEM_WINDOW_OFFSET; 47461369Sdduvall regaddr = PIO_ADDR(bgep, regoff); 47471369Sdduvall regval = ppd->pp_acc_data; 47481369Sdduvall 47491369Sdduvall switch (ppd->pp_acc_size) { 47501369Sdduvall case 1: 47511369Sdduvall ddi_put8(bgep->io_handle, regaddr, regval); 47521369Sdduvall break; 47531369Sdduvall 47541369Sdduvall case 2: 47551369Sdduvall ddi_put16(bgep->io_handle, regaddr, regval); 47561369Sdduvall break; 47571369Sdduvall 47581369Sdduvall case 4: 47591369Sdduvall ddi_put32(bgep->io_handle, regaddr, regval); 47601369Sdduvall break; 47611369Sdduvall 47621369Sdduvall case 8: 47631369Sdduvall ddi_put64(bgep->io_handle, regaddr, regval); 47641369Sdduvall break; 47651369Sdduvall } 47661369Sdduvall BGE_PCICHK(bgep); 47671369Sdduvall } 47681369Sdduvall 47691369Sdduvall static void bge_chip_peek_mii(bge_t *bgep, bge_peekpoke_t *ppd); 47701369Sdduvall #pragma no_inline(bge_chip_peek_mii) 47711369Sdduvall 47721369Sdduvall static void 47731369Sdduvall bge_chip_peek_mii(bge_t *bgep, bge_peekpoke_t *ppd) 47741369Sdduvall { 47751369Sdduvall BGE_TRACE(("bge_chip_peek_mii($%p, $%p)", 47764588Sml149210 (void *)bgep, (void *)ppd)); 47771369Sdduvall 47781369Sdduvall ppd->pp_acc_data = bge_mii_get16(bgep, ppd->pp_acc_offset/2); 47791369Sdduvall } 47801369Sdduvall 47811369Sdduvall static void bge_chip_poke_mii(bge_t *bgep, bge_peekpoke_t *ppd); 47821369Sdduvall #pragma no_inline(bge_chip_poke_mii) 47831369Sdduvall 47841369Sdduvall static void 47851369Sdduvall bge_chip_poke_mii(bge_t *bgep, bge_peekpoke_t *ppd) 47861369Sdduvall { 47871369Sdduvall BGE_TRACE(("bge_chip_poke_mii($%p, $%p)", 47884588Sml149210 (void *)bgep, (void *)ppd)); 47891369Sdduvall 47901369Sdduvall bge_mii_put16(bgep, ppd->pp_acc_offset/2, ppd->pp_acc_data); 47911369Sdduvall } 47921369Sdduvall 47931369Sdduvall #if BGE_SEE_IO32 47941369Sdduvall 47951369Sdduvall static void bge_chip_peek_seeprom(bge_t *bgep, bge_peekpoke_t *ppd); 47961369Sdduvall #pragma no_inline(bge_chip_peek_seeprom) 47971369Sdduvall 47981369Sdduvall static void 47991369Sdduvall bge_chip_peek_seeprom(bge_t *bgep, bge_peekpoke_t *ppd) 48001369Sdduvall { 48011369Sdduvall uint32_t data; 48021369Sdduvall int err; 48031369Sdduvall 48041369Sdduvall BGE_TRACE(("bge_chip_peek_seeprom($%p, $%p)", 48054588Sml149210 (void *)bgep, (void *)ppd)); 48061369Sdduvall 48071369Sdduvall err = bge_nvmem_rw32(bgep, BGE_SEE_READ, ppd->pp_acc_offset, &data); 48081369Sdduvall ppd->pp_acc_data = err ? ~0ull : data; 48091369Sdduvall } 48101369Sdduvall 48111369Sdduvall static void bge_chip_poke_seeprom(bge_t *bgep, bge_peekpoke_t *ppd); 48121369Sdduvall #pragma no_inline(bge_chip_poke_seeprom) 48131369Sdduvall 48141369Sdduvall static void 48151369Sdduvall bge_chip_poke_seeprom(bge_t *bgep, bge_peekpoke_t *ppd) 48161369Sdduvall { 48171369Sdduvall uint32_t data; 48181369Sdduvall 48191369Sdduvall BGE_TRACE(("bge_chip_poke_seeprom($%p, $%p)", 48204588Sml149210 (void *)bgep, (void *)ppd)); 48211369Sdduvall 48221369Sdduvall data = ppd->pp_acc_data; 48231369Sdduvall (void) bge_nvmem_rw32(bgep, BGE_SEE_WRITE, ppd->pp_acc_offset, &data); 48241369Sdduvall } 48251369Sdduvall #endif /* BGE_SEE_IO32 */ 48261369Sdduvall 48271369Sdduvall #if BGE_FLASH_IO32 48281369Sdduvall 48291369Sdduvall static void bge_chip_peek_flash(bge_t *bgep, bge_peekpoke_t *ppd); 48301369Sdduvall #pragma no_inline(bge_chip_peek_flash) 48311369Sdduvall 48321369Sdduvall static void 48331369Sdduvall bge_chip_peek_flash(bge_t *bgep, bge_peekpoke_t *ppd) 48341369Sdduvall { 48351369Sdduvall uint32_t data; 48361369Sdduvall int err; 48371369Sdduvall 48381369Sdduvall BGE_TRACE(("bge_chip_peek_flash($%p, $%p)", 48394588Sml149210 (void *)bgep, (void *)ppd)); 48401369Sdduvall 48411369Sdduvall err = bge_nvmem_rw32(bgep, BGE_FLASH_READ, ppd->pp_acc_offset, &data); 48421369Sdduvall ppd->pp_acc_data = err ? ~0ull : data; 48431369Sdduvall } 48441369Sdduvall 48451369Sdduvall static void bge_chip_poke_flash(bge_t *bgep, bge_peekpoke_t *ppd); 48461369Sdduvall #pragma no_inline(bge_chip_poke_flash) 48471369Sdduvall 48481369Sdduvall static void 48491369Sdduvall bge_chip_poke_flash(bge_t *bgep, bge_peekpoke_t *ppd) 48501369Sdduvall { 48511369Sdduvall uint32_t data; 48521369Sdduvall 48531369Sdduvall BGE_TRACE(("bge_chip_poke_flash($%p, $%p)", 48544588Sml149210 (void *)bgep, (void *)ppd)); 48551369Sdduvall 48561369Sdduvall data = ppd->pp_acc_data; 48571369Sdduvall (void) bge_nvmem_rw32(bgep, BGE_FLASH_WRITE, 48581369Sdduvall ppd->pp_acc_offset, &data); 48591369Sdduvall } 48601369Sdduvall #endif /* BGE_FLASH_IO32 */ 48611369Sdduvall 48621369Sdduvall static void bge_chip_peek_mem(bge_t *bgep, bge_peekpoke_t *ppd); 48631369Sdduvall #pragma no_inline(bge_chip_peek_mem) 48641369Sdduvall 48651369Sdduvall static void 48661369Sdduvall bge_chip_peek_mem(bge_t *bgep, bge_peekpoke_t *ppd) 48671369Sdduvall { 48681369Sdduvall uint64_t regval; 48691369Sdduvall void *vaddr; 48701369Sdduvall 48711369Sdduvall BGE_TRACE(("bge_chip_peek_bge($%p, $%p)", 48724588Sml149210 (void *)bgep, (void *)ppd)); 48731369Sdduvall 48741369Sdduvall vaddr = (void *)(uintptr_t)ppd->pp_acc_offset; 48751369Sdduvall 48761369Sdduvall switch (ppd->pp_acc_size) { 48771369Sdduvall case 1: 48781369Sdduvall regval = *(uint8_t *)vaddr; 48791369Sdduvall break; 48801369Sdduvall 48811369Sdduvall case 2: 48821369Sdduvall regval = *(uint16_t *)vaddr; 48831369Sdduvall break; 48841369Sdduvall 48851369Sdduvall case 4: 48861369Sdduvall regval = *(uint32_t *)vaddr; 48871369Sdduvall break; 48881369Sdduvall 48891369Sdduvall case 8: 48901369Sdduvall regval = *(uint64_t *)vaddr; 48911369Sdduvall break; 48921369Sdduvall } 48931369Sdduvall 48941369Sdduvall BGE_DEBUG(("bge_chip_peek_mem($%p, $%p) peeked 0x%llx from $%p", 48954588Sml149210 (void *)bgep, (void *)ppd, regval, vaddr)); 48961369Sdduvall 48971369Sdduvall ppd->pp_acc_data = regval; 48981369Sdduvall } 48991369Sdduvall 49001369Sdduvall static void bge_chip_poke_mem(bge_t *bgep, bge_peekpoke_t *ppd); 49011369Sdduvall #pragma no_inline(bge_chip_poke_mem) 49021369Sdduvall 49031369Sdduvall static void 49041369Sdduvall bge_chip_poke_mem(bge_t *bgep, bge_peekpoke_t *ppd) 49051369Sdduvall { 49061369Sdduvall uint64_t regval; 49071369Sdduvall void *vaddr; 49081369Sdduvall 49091369Sdduvall BGE_TRACE(("bge_chip_poke_mem($%p, $%p)", 49104588Sml149210 (void *)bgep, (void *)ppd)); 49111369Sdduvall 49121369Sdduvall vaddr = (void *)(uintptr_t)ppd->pp_acc_offset; 49131369Sdduvall regval = ppd->pp_acc_data; 49141369Sdduvall 49151369Sdduvall BGE_DEBUG(("bge_chip_poke_mem($%p, $%p) poking 0x%llx at $%p", 49164588Sml149210 (void *)bgep, (void *)ppd, regval, vaddr)); 49171369Sdduvall 49181369Sdduvall switch (ppd->pp_acc_size) { 49191369Sdduvall case 1: 49201369Sdduvall *(uint8_t *)vaddr = (uint8_t)regval; 49211369Sdduvall break; 49221369Sdduvall 49231369Sdduvall case 2: 49241369Sdduvall *(uint16_t *)vaddr = (uint16_t)regval; 49251369Sdduvall break; 49261369Sdduvall 49271369Sdduvall case 4: 49281369Sdduvall *(uint32_t *)vaddr = (uint32_t)regval; 49291369Sdduvall break; 49301369Sdduvall 49311369Sdduvall case 8: 49321369Sdduvall *(uint64_t *)vaddr = (uint64_t)regval; 49331369Sdduvall break; 49341369Sdduvall } 49351369Sdduvall } 49361369Sdduvall 49371369Sdduvall static enum ioc_reply bge_pp_ioctl(bge_t *bgep, int cmd, mblk_t *mp, 49381369Sdduvall struct iocblk *iocp); 49391369Sdduvall #pragma no_inline(bge_pp_ioctl) 49401369Sdduvall 49411369Sdduvall static enum ioc_reply 49421369Sdduvall bge_pp_ioctl(bge_t *bgep, int cmd, mblk_t *mp, struct iocblk *iocp) 49431369Sdduvall { 49441369Sdduvall void (*ppfn)(bge_t *bgep, bge_peekpoke_t *ppd); 49451369Sdduvall bge_peekpoke_t *ppd; 49461369Sdduvall dma_area_t *areap; 49471369Sdduvall uint64_t sizemask; 49481369Sdduvall uint64_t mem_va; 49491369Sdduvall uint64_t maxoff; 49501369Sdduvall boolean_t peek; 49511369Sdduvall 49521369Sdduvall switch (cmd) { 49531369Sdduvall default: 49541369Sdduvall /* NOTREACHED */ 49551369Sdduvall bge_error(bgep, "bge_pp_ioctl: invalid cmd 0x%x", cmd); 49561369Sdduvall return (IOC_INVAL); 49571369Sdduvall 49581369Sdduvall case BGE_PEEK: 49591369Sdduvall peek = B_TRUE; 49601369Sdduvall break; 49611369Sdduvall 49621369Sdduvall case BGE_POKE: 49631369Sdduvall peek = B_FALSE; 49641369Sdduvall break; 49651369Sdduvall } 49661369Sdduvall 49671369Sdduvall /* 49681369Sdduvall * Validate format of ioctl 49691369Sdduvall */ 49701369Sdduvall if (iocp->ioc_count != sizeof (bge_peekpoke_t)) 49711369Sdduvall return (IOC_INVAL); 49721369Sdduvall if (mp->b_cont == NULL) 49731369Sdduvall return (IOC_INVAL); 49747099Syt223700 ppd = (void *)mp->b_cont->b_rptr; 49751369Sdduvall 49761369Sdduvall /* 49771369Sdduvall * Validate request parameters 49781369Sdduvall */ 49791369Sdduvall switch (ppd->pp_acc_space) { 49801369Sdduvall default: 49811369Sdduvall return (IOC_INVAL); 49821369Sdduvall 49831369Sdduvall case BGE_PP_SPACE_CFG: 49841369Sdduvall /* 49851369Sdduvall * Config space 49861369Sdduvall */ 49871369Sdduvall sizemask = 8|4|2|1; 49881369Sdduvall mem_va = 0; 49891369Sdduvall maxoff = PCI_CONF_HDR_SIZE; 49901369Sdduvall ppfn = peek ? bge_chip_peek_cfg : bge_chip_poke_cfg; 49911369Sdduvall break; 49921369Sdduvall 49931369Sdduvall case BGE_PP_SPACE_REG: 49941369Sdduvall /* 49951369Sdduvall * Memory-mapped I/O space 49961369Sdduvall */ 49971369Sdduvall sizemask = 8|4|2|1; 49981369Sdduvall mem_va = 0; 49991369Sdduvall maxoff = RIAAR_REGISTER_MAX; 50001369Sdduvall ppfn = peek ? bge_chip_peek_reg : bge_chip_poke_reg; 50011369Sdduvall break; 50021369Sdduvall 50031369Sdduvall case BGE_PP_SPACE_NIC: 50041369Sdduvall /* 50051369Sdduvall * NIC on-chip memory 50061369Sdduvall */ 50071369Sdduvall sizemask = 8|4|2|1; 50081369Sdduvall mem_va = 0; 50091369Sdduvall maxoff = MWBAR_ONCHIP_MAX; 50101369Sdduvall ppfn = peek ? bge_chip_peek_nic : bge_chip_poke_nic; 50111369Sdduvall break; 50121369Sdduvall 50131369Sdduvall case BGE_PP_SPACE_MII: 50141369Sdduvall /* 50151369Sdduvall * PHY's MII registers 50161369Sdduvall * NB: all PHY registers are two bytes, but the 50171369Sdduvall * addresses increment in ones (word addressing). 50181369Sdduvall * So we scale the address here, then undo the 50191369Sdduvall * transformation inside the peek/poke functions. 50201369Sdduvall */ 50211369Sdduvall ppd->pp_acc_offset *= 2; 50221369Sdduvall sizemask = 2; 50231369Sdduvall mem_va = 0; 50241369Sdduvall maxoff = (MII_MAXREG+1)*2; 50251369Sdduvall ppfn = peek ? bge_chip_peek_mii : bge_chip_poke_mii; 50261369Sdduvall break; 50271369Sdduvall 50281369Sdduvall #if BGE_SEE_IO32 50291369Sdduvall case BGE_PP_SPACE_SEEPROM: 50301369Sdduvall /* 50311369Sdduvall * Attached SEEPROM(s), if any. 50321369Sdduvall * NB: we use the high-order bits of the 'address' as 50331369Sdduvall * a device select to accommodate multiple SEEPROMS, 50341369Sdduvall * If each one is the maximum size (64kbytes), this 50351369Sdduvall * makes them appear contiguous. Otherwise, there may 50361369Sdduvall * be holes in the mapping. ENxS doesn't have any 50371369Sdduvall * SEEPROMs anyway ... 50381369Sdduvall */ 50391369Sdduvall sizemask = 4; 50401369Sdduvall mem_va = 0; 50411369Sdduvall maxoff = SEEPROM_DEV_AND_ADDR_MASK; 50421369Sdduvall ppfn = peek ? bge_chip_peek_seeprom : bge_chip_poke_seeprom; 50431369Sdduvall break; 50441369Sdduvall #endif /* BGE_SEE_IO32 */ 50451369Sdduvall 50461369Sdduvall #if BGE_FLASH_IO32 50471369Sdduvall case BGE_PP_SPACE_FLASH: 50481369Sdduvall /* 50491369Sdduvall * Attached Flash device (if any); a maximum of one device 50501369Sdduvall * is currently supported. But it can be up to 1MB (unlike 50511369Sdduvall * the 64k limit on SEEPROMs) so why would you need more ;-) 50521369Sdduvall */ 50531369Sdduvall sizemask = 4; 50541369Sdduvall mem_va = 0; 50551369Sdduvall maxoff = NVM_FLASH_ADDR_MASK; 50561369Sdduvall ppfn = peek ? bge_chip_peek_flash : bge_chip_poke_flash; 50571369Sdduvall break; 50581369Sdduvall #endif /* BGE_FLASH_IO32 */ 50591369Sdduvall 50601369Sdduvall case BGE_PP_SPACE_BGE: 50611369Sdduvall /* 50621369Sdduvall * BGE data structure! 50631369Sdduvall */ 50641369Sdduvall sizemask = 8|4|2|1; 50651369Sdduvall mem_va = (uintptr_t)bgep; 50661369Sdduvall maxoff = sizeof (*bgep); 50671369Sdduvall ppfn = peek ? bge_chip_peek_mem : bge_chip_poke_mem; 50681369Sdduvall break; 50691369Sdduvall 50701369Sdduvall case BGE_PP_SPACE_STATUS: 50711369Sdduvall case BGE_PP_SPACE_STATISTICS: 50721369Sdduvall case BGE_PP_SPACE_TXDESC: 50731369Sdduvall case BGE_PP_SPACE_TXBUFF: 50741369Sdduvall case BGE_PP_SPACE_RXDESC: 50751369Sdduvall case BGE_PP_SPACE_RXBUFF: 50761369Sdduvall /* 50771369Sdduvall * Various DMA_AREAs 50781369Sdduvall */ 50791369Sdduvall switch (ppd->pp_acc_space) { 50801369Sdduvall case BGE_PP_SPACE_TXDESC: 50811369Sdduvall areap = &bgep->tx_desc; 50821369Sdduvall break; 50831369Sdduvall case BGE_PP_SPACE_TXBUFF: 50841369Sdduvall areap = &bgep->tx_buff[0]; 50851369Sdduvall break; 50861369Sdduvall case BGE_PP_SPACE_RXDESC: 50871369Sdduvall areap = &bgep->rx_desc[0]; 50881369Sdduvall break; 50891369Sdduvall case BGE_PP_SPACE_RXBUFF: 50901369Sdduvall areap = &bgep->rx_buff[0]; 50911369Sdduvall break; 50921369Sdduvall case BGE_PP_SPACE_STATUS: 50931369Sdduvall areap = &bgep->status_block; 50941369Sdduvall break; 50951369Sdduvall case BGE_PP_SPACE_STATISTICS: 50961369Sdduvall if (bgep->chipid.statistic_type == BGE_STAT_BLK) 50971369Sdduvall areap = &bgep->statistics; 50981369Sdduvall break; 50991369Sdduvall } 51001369Sdduvall 51011369Sdduvall sizemask = 8|4|2|1; 51021369Sdduvall mem_va = (uintptr_t)areap->mem_va; 51031369Sdduvall maxoff = areap->alength; 51041369Sdduvall ppfn = peek ? bge_chip_peek_mem : bge_chip_poke_mem; 51051369Sdduvall break; 51061369Sdduvall } 51071369Sdduvall 51081369Sdduvall switch (ppd->pp_acc_size) { 51091369Sdduvall default: 51101369Sdduvall return (IOC_INVAL); 51111369Sdduvall 51121369Sdduvall case 8: 51131369Sdduvall case 4: 51141369Sdduvall case 2: 51151369Sdduvall case 1: 51161369Sdduvall if ((ppd->pp_acc_size & sizemask) == 0) 51171369Sdduvall return (IOC_INVAL); 51181369Sdduvall break; 51191369Sdduvall } 51201369Sdduvall 51211369Sdduvall if ((ppd->pp_acc_offset % ppd->pp_acc_size) != 0) 51221369Sdduvall return (IOC_INVAL); 51231369Sdduvall 51241369Sdduvall if (ppd->pp_acc_offset >= maxoff) 51251369Sdduvall return (IOC_INVAL); 51261369Sdduvall 51271369Sdduvall if (ppd->pp_acc_offset+ppd->pp_acc_size > maxoff) 51281369Sdduvall return (IOC_INVAL); 51291369Sdduvall 51301369Sdduvall /* 51311369Sdduvall * All OK - go do it! 51321369Sdduvall */ 51331369Sdduvall ppd->pp_acc_offset += mem_va; 51341369Sdduvall (*ppfn)(bgep, ppd); 51351369Sdduvall return (peek ? IOC_REPLY : IOC_ACK); 51361369Sdduvall } 51371369Sdduvall 51381369Sdduvall static enum ioc_reply bge_diag_ioctl(bge_t *bgep, int cmd, mblk_t *mp, 51391369Sdduvall struct iocblk *iocp); 51401369Sdduvall #pragma no_inline(bge_diag_ioctl) 51411369Sdduvall 51421369Sdduvall static enum ioc_reply 51431369Sdduvall bge_diag_ioctl(bge_t *bgep, int cmd, mblk_t *mp, struct iocblk *iocp) 51441369Sdduvall { 51451369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 51461369Sdduvall 51471369Sdduvall switch (cmd) { 51481369Sdduvall default: 51491369Sdduvall /* NOTREACHED */ 51501369Sdduvall bge_error(bgep, "bge_diag_ioctl: invalid cmd 0x%x", cmd); 51511369Sdduvall return (IOC_INVAL); 51521369Sdduvall 51531369Sdduvall case BGE_DIAG: 51541369Sdduvall /* 51551369Sdduvall * Currently a no-op 51561369Sdduvall */ 51571369Sdduvall return (IOC_ACK); 51581369Sdduvall 51591369Sdduvall case BGE_PEEK: 51601369Sdduvall case BGE_POKE: 51611369Sdduvall return (bge_pp_ioctl(bgep, cmd, mp, iocp)); 51621369Sdduvall 51631369Sdduvall case BGE_PHY_RESET: 51641369Sdduvall return (IOC_RESTART_ACK); 51651369Sdduvall 51661369Sdduvall case BGE_SOFT_RESET: 51671369Sdduvall case BGE_HARD_RESET: 51681369Sdduvall /* 51691369Sdduvall * Reset and reinitialise the 570x hardware 51701369Sdduvall */ 51713918Sml149210 bgep->bge_chip_state = BGE_CHIP_FAULT; 51723918Sml149210 ddi_trigger_softintr(bgep->factotum_id); 51731865Sdilpreet (void) bge_restart(bgep, cmd == BGE_HARD_RESET); 51741369Sdduvall return (IOC_ACK); 51751369Sdduvall } 51761369Sdduvall 51771369Sdduvall /* NOTREACHED */ 51781369Sdduvall } 51791369Sdduvall 51801369Sdduvall #endif /* BGE_DEBUGGING || BGE_DO_PPIO */ 51811369Sdduvall 51821369Sdduvall static enum ioc_reply bge_mii_ioctl(bge_t *bgep, int cmd, mblk_t *mp, 51831369Sdduvall struct iocblk *iocp); 51841369Sdduvall #pragma no_inline(bge_mii_ioctl) 51851369Sdduvall 51861369Sdduvall static enum ioc_reply 51871369Sdduvall bge_mii_ioctl(bge_t *bgep, int cmd, mblk_t *mp, struct iocblk *iocp) 51881369Sdduvall { 51891369Sdduvall struct bge_mii_rw *miirwp; 51901369Sdduvall 51911369Sdduvall /* 51921369Sdduvall * Validate format of ioctl 51931369Sdduvall */ 51941369Sdduvall if (iocp->ioc_count != sizeof (struct bge_mii_rw)) 51951369Sdduvall return (IOC_INVAL); 51961369Sdduvall if (mp->b_cont == NULL) 51971369Sdduvall return (IOC_INVAL); 51987099Syt223700 miirwp = (void *)mp->b_cont->b_rptr; 51991369Sdduvall 52001369Sdduvall /* 52011369Sdduvall * Validate request parameters ... 52021369Sdduvall */ 52031369Sdduvall if (miirwp->mii_reg > MII_MAXREG) 52041369Sdduvall return (IOC_INVAL); 52051369Sdduvall 52061369Sdduvall switch (cmd) { 52071369Sdduvall default: 52081369Sdduvall /* NOTREACHED */ 52091369Sdduvall bge_error(bgep, "bge_mii_ioctl: invalid cmd 0x%x", cmd); 52101369Sdduvall return (IOC_INVAL); 52111369Sdduvall 52121369Sdduvall case BGE_MII_READ: 52131369Sdduvall miirwp->mii_data = bge_mii_get16(bgep, miirwp->mii_reg); 52141369Sdduvall return (IOC_REPLY); 52151369Sdduvall 52161369Sdduvall case BGE_MII_WRITE: 52171369Sdduvall bge_mii_put16(bgep, miirwp->mii_reg, miirwp->mii_data); 52181369Sdduvall return (IOC_ACK); 52191369Sdduvall } 52201369Sdduvall 52211369Sdduvall /* NOTREACHED */ 52221369Sdduvall } 52231369Sdduvall 52241369Sdduvall #if BGE_SEE_IO32 52251369Sdduvall 52261369Sdduvall static enum ioc_reply bge_see_ioctl(bge_t *bgep, int cmd, mblk_t *mp, 52271369Sdduvall struct iocblk *iocp); 52281369Sdduvall #pragma no_inline(bge_see_ioctl) 52291369Sdduvall 52301369Sdduvall static enum ioc_reply 52311369Sdduvall bge_see_ioctl(bge_t *bgep, int cmd, mblk_t *mp, struct iocblk *iocp) 52321369Sdduvall { 52331369Sdduvall struct bge_see_rw *seerwp; 52341369Sdduvall 52351369Sdduvall /* 52361369Sdduvall * Validate format of ioctl 52371369Sdduvall */ 52381369Sdduvall if (iocp->ioc_count != sizeof (struct bge_see_rw)) 52391369Sdduvall return (IOC_INVAL); 52401369Sdduvall if (mp->b_cont == NULL) 52411369Sdduvall return (IOC_INVAL); 52427099Syt223700 seerwp = (void *)mp->b_cont->b_rptr; 52431369Sdduvall 52441369Sdduvall /* 52451369Sdduvall * Validate request parameters ... 52461369Sdduvall */ 52471369Sdduvall if (seerwp->see_addr & ~SEEPROM_DEV_AND_ADDR_MASK) 52481369Sdduvall return (IOC_INVAL); 52491369Sdduvall 52501369Sdduvall switch (cmd) { 52511369Sdduvall default: 52521369Sdduvall /* NOTREACHED */ 52531369Sdduvall bge_error(bgep, "bge_see_ioctl: invalid cmd 0x%x", cmd); 52541369Sdduvall return (IOC_INVAL); 52551369Sdduvall 52561369Sdduvall case BGE_SEE_READ: 52571369Sdduvall case BGE_SEE_WRITE: 52581369Sdduvall iocp->ioc_error = bge_nvmem_rw32(bgep, cmd, 52591369Sdduvall seerwp->see_addr, &seerwp->see_data); 52601369Sdduvall return (IOC_REPLY); 52611369Sdduvall } 52621369Sdduvall 52631369Sdduvall /* NOTREACHED */ 52641369Sdduvall } 52651369Sdduvall 52661369Sdduvall #endif /* BGE_SEE_IO32 */ 52671369Sdduvall 52681369Sdduvall #if BGE_FLASH_IO32 52691369Sdduvall 52701369Sdduvall static enum ioc_reply bge_flash_ioctl(bge_t *bgep, int cmd, mblk_t *mp, 52711369Sdduvall struct iocblk *iocp); 52721369Sdduvall #pragma no_inline(bge_flash_ioctl) 52731369Sdduvall 52741369Sdduvall static enum ioc_reply 52751369Sdduvall bge_flash_ioctl(bge_t *bgep, int cmd, mblk_t *mp, struct iocblk *iocp) 52761369Sdduvall { 52771369Sdduvall struct bge_flash_rw *flashrwp; 52781369Sdduvall 52791369Sdduvall /* 52801369Sdduvall * Validate format of ioctl 52811369Sdduvall */ 52821369Sdduvall if (iocp->ioc_count != sizeof (struct bge_flash_rw)) 52831369Sdduvall return (IOC_INVAL); 52841369Sdduvall if (mp->b_cont == NULL) 52851369Sdduvall return (IOC_INVAL); 52867099Syt223700 flashrwp = (void *)mp->b_cont->b_rptr; 52871369Sdduvall 52881369Sdduvall /* 52891369Sdduvall * Validate request parameters ... 52901369Sdduvall */ 52911369Sdduvall if (flashrwp->flash_addr & ~NVM_FLASH_ADDR_MASK) 52921369Sdduvall return (IOC_INVAL); 52931369Sdduvall 52941369Sdduvall switch (cmd) { 52951369Sdduvall default: 52961369Sdduvall /* NOTREACHED */ 52971369Sdduvall bge_error(bgep, "bge_flash_ioctl: invalid cmd 0x%x", cmd); 52981369Sdduvall return (IOC_INVAL); 52991369Sdduvall 53001369Sdduvall case BGE_FLASH_READ: 53011369Sdduvall case BGE_FLASH_WRITE: 53021369Sdduvall iocp->ioc_error = bge_nvmem_rw32(bgep, cmd, 53031369Sdduvall flashrwp->flash_addr, &flashrwp->flash_data); 53041369Sdduvall return (IOC_REPLY); 53051369Sdduvall } 53061369Sdduvall 53071369Sdduvall /* NOTREACHED */ 53081369Sdduvall } 53091369Sdduvall 53101369Sdduvall #endif /* BGE_FLASH_IO32 */ 53111369Sdduvall 53121369Sdduvall enum ioc_reply bge_chip_ioctl(bge_t *bgep, queue_t *wq, mblk_t *mp, 53131369Sdduvall struct iocblk *iocp); 53141369Sdduvall #pragma no_inline(bge_chip_ioctl) 53151369Sdduvall 53161369Sdduvall enum ioc_reply 53171369Sdduvall bge_chip_ioctl(bge_t *bgep, queue_t *wq, mblk_t *mp, struct iocblk *iocp) 53181369Sdduvall { 53191369Sdduvall int cmd; 53201369Sdduvall 53211369Sdduvall BGE_TRACE(("bge_chip_ioctl($%p, $%p, $%p, $%p)", 53224588Sml149210 (void *)bgep, (void *)wq, (void *)mp, (void *)iocp)); 53231369Sdduvall 53241369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 53251369Sdduvall 53261369Sdduvall cmd = iocp->ioc_cmd; 53271369Sdduvall switch (cmd) { 53281369Sdduvall default: 53291369Sdduvall /* NOTREACHED */ 53301369Sdduvall bge_error(bgep, "bge_chip_ioctl: invalid cmd 0x%x", cmd); 53311369Sdduvall return (IOC_INVAL); 53321369Sdduvall 53331369Sdduvall case BGE_DIAG: 53341369Sdduvall case BGE_PEEK: 53351369Sdduvall case BGE_POKE: 53361369Sdduvall case BGE_PHY_RESET: 53371369Sdduvall case BGE_SOFT_RESET: 53381369Sdduvall case BGE_HARD_RESET: 53391369Sdduvall #if BGE_DEBUGGING || BGE_DO_PPIO 53401369Sdduvall return (bge_diag_ioctl(bgep, cmd, mp, iocp)); 53411369Sdduvall #else 53421369Sdduvall return (IOC_INVAL); 53431369Sdduvall #endif /* BGE_DEBUGGING || BGE_DO_PPIO */ 53441369Sdduvall 53451369Sdduvall case BGE_MII_READ: 53461369Sdduvall case BGE_MII_WRITE: 53471369Sdduvall return (bge_mii_ioctl(bgep, cmd, mp, iocp)); 53481369Sdduvall 53491369Sdduvall #if BGE_SEE_IO32 53501369Sdduvall case BGE_SEE_READ: 53511369Sdduvall case BGE_SEE_WRITE: 53521369Sdduvall return (bge_see_ioctl(bgep, cmd, mp, iocp)); 53531369Sdduvall #endif /* BGE_SEE_IO32 */ 53541369Sdduvall 53551369Sdduvall #if BGE_FLASH_IO32 53561369Sdduvall case BGE_FLASH_READ: 53571369Sdduvall case BGE_FLASH_WRITE: 53581369Sdduvall return (bge_flash_ioctl(bgep, cmd, mp, iocp)); 53591369Sdduvall #endif /* BGE_FLASH_IO32 */ 53601369Sdduvall } 53611369Sdduvall 53621369Sdduvall /* NOTREACHED */ 53631369Sdduvall } 53641369Sdduvall 53651369Sdduvall void 53661369Sdduvall bge_chip_blank(void *arg, time_t ticks, uint_t count) 53671369Sdduvall { 53681369Sdduvall bge_t *bgep = arg; 53691369Sdduvall 53701865Sdilpreet mutex_enter(bgep->genlock); 53711369Sdduvall bge_reg_put32(bgep, RCV_COALESCE_TICKS_REG, ticks); 53721369Sdduvall bge_reg_put32(bgep, RCV_COALESCE_MAX_BD_REG, count); 53731865Sdilpreet if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) 53741865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_UNAFFECTED); 53751865Sdilpreet mutex_exit(bgep->genlock); 53761369Sdduvall } 53771408Srandyf 53781408Srandyf #ifdef BGE_IPMI_ASF 53791408Srandyf 53801408Srandyf uint32_t 53811408Srandyf bge_nic_read32(bge_t *bgep, bge_regno_t addr) 53821408Srandyf { 53831408Srandyf uint32_t data; 53841408Srandyf 53853918Sml149210 #ifndef __sparc 53861408Srandyf if (!bgep->asf_wordswapped) { 53871408Srandyf /* a workaround word swap error */ 53881408Srandyf if (addr & 4) 53891408Srandyf addr = addr - 4; 53901408Srandyf else 53911408Srandyf addr = addr + 4; 53921408Srandyf } 53933918Sml149210 #endif 53941408Srandyf 53951408Srandyf pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_MWBAR, addr); 53961408Srandyf data = pci_config_get32(bgep->cfg_handle, PCI_CONF_BGE_MWDAR); 53971408Srandyf pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_MWBAR, 0); 53981408Srandyf 53993918Sml149210 data = LE_32(data); 54001408Srandyf return (data); 54011408Srandyf } 54021408Srandyf 54031408Srandyf void 54041408Srandyf bge_asf_update_status(bge_t *bgep) 54051408Srandyf { 54061408Srandyf uint32_t event; 54071408Srandyf 54081408Srandyf bge_nic_put32(bgep, BGE_CMD_MAILBOX, BGE_CMD_NICDRV_ALIVE); 54091408Srandyf bge_nic_put32(bgep, BGE_CMD_LENGTH_MAILBOX, 4); 54101408Srandyf bge_nic_put32(bgep, BGE_CMD_DATA_MAILBOX, 3); 54111408Srandyf 54121408Srandyf event = bge_reg_get32(bgep, RX_RISC_EVENT_REG); 54131408Srandyf bge_reg_put32(bgep, RX_RISC_EVENT_REG, event | RRER_ASF_EVENT); 54141408Srandyf } 54151408Srandyf 54161408Srandyf 54171408Srandyf /* 54181408Srandyf * The driver is supposed to notify ASF that the OS is still running 54191408Srandyf * every three seconds, otherwise the management server may attempt 54201408Srandyf * to reboot the machine. If it hasn't actually failed, this is 54212135Szh199473 * not a desirable result. However, this isn't running as a real-time 54221408Srandyf * thread, and even if it were, it might not be able to generate the 54231408Srandyf * heartbeat in a timely manner due to system load. As it isn't a 54241408Srandyf * significant strain on the machine, we will set the interval to half 54251408Srandyf * of the required value. 54261408Srandyf */ 54271408Srandyf void 54281865Sdilpreet bge_asf_heartbeat(void *arg) 54291408Srandyf { 54301865Sdilpreet bge_t *bgep = (bge_t *)arg; 54311865Sdilpreet 54321865Sdilpreet mutex_enter(bgep->genlock); 54331408Srandyf bge_asf_update_status((bge_t *)bgep); 54341865Sdilpreet if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) 54351865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_DEGRADED); 54361865Sdilpreet if (bge_check_acc_handle(bgep, bgep->cfg_handle) != DDI_FM_OK) 54371865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_DEGRADED); 54381865Sdilpreet mutex_exit(bgep->genlock); 54391408Srandyf ((bge_t *)bgep)->asf_timeout_id = timeout(bge_asf_heartbeat, bgep, 54404588Sml149210 drv_usectohz(BGE_ASF_HEARTBEAT_INTERVAL)); 54411408Srandyf } 54421408Srandyf 54431408Srandyf 54441408Srandyf void 54451408Srandyf bge_asf_stop_timer(bge_t *bgep) 54461408Srandyf { 54471408Srandyf timeout_id_t tmp_id = 0; 54481408Srandyf 54491408Srandyf while ((bgep->asf_timeout_id != 0) && 54504588Sml149210 (tmp_id != bgep->asf_timeout_id)) { 54511408Srandyf tmp_id = bgep->asf_timeout_id; 54521408Srandyf (void) untimeout(tmp_id); 54531408Srandyf } 54541408Srandyf bgep->asf_timeout_id = 0; 54551408Srandyf } 54561408Srandyf 54571408Srandyf 54581408Srandyf 54591408Srandyf /* 54602135Szh199473 * This function should be placed at the earliest position of bge_attach(). 54611408Srandyf */ 54621408Srandyf void 54631408Srandyf bge_asf_get_config(bge_t *bgep) 54641408Srandyf { 54651408Srandyf uint32_t nicsig; 54661408Srandyf uint32_t niccfg; 54671408Srandyf 54683918Sml149210 bgep->asf_enabled = B_FALSE; 54691408Srandyf nicsig = bge_nic_read32(bgep, BGE_NIC_DATA_SIG_ADDR); 54701408Srandyf if (nicsig == BGE_NIC_DATA_SIG) { 54711408Srandyf niccfg = bge_nic_read32(bgep, BGE_NIC_DATA_NIC_CFG_ADDR); 54721408Srandyf if (niccfg & BGE_NIC_CFG_ENABLE_ASF) 54731408Srandyf /* 54741408Srandyf * Here, we don't consider BAXTER, because BGE haven't 54751408Srandyf * supported BAXTER (that is 5752). Also, as I know, 54761408Srandyf * BAXTER doesn't support ASF feature. 54771408Srandyf */ 54781408Srandyf bgep->asf_enabled = B_TRUE; 54791408Srandyf else 54801408Srandyf bgep->asf_enabled = B_FALSE; 54811408Srandyf } else 54821408Srandyf bgep->asf_enabled = B_FALSE; 54831408Srandyf } 54841408Srandyf 54851408Srandyf 54861408Srandyf void 54871408Srandyf bge_asf_pre_reset_operations(bge_t *bgep, uint32_t mode) 54881408Srandyf { 54891408Srandyf uint32_t tries; 54901408Srandyf uint32_t event; 54911408Srandyf 54921408Srandyf ASSERT(bgep->asf_enabled); 54931408Srandyf 54941408Srandyf /* Issues "pause firmware" command and wait for ACK */ 54951408Srandyf bge_nic_put32(bgep, BGE_CMD_MAILBOX, BGE_CMD_NICDRV_PAUSE_FW); 54961408Srandyf event = bge_reg_get32(bgep, RX_RISC_EVENT_REG); 54971408Srandyf bge_reg_put32(bgep, RX_RISC_EVENT_REG, event | RRER_ASF_EVENT); 54981408Srandyf 54991408Srandyf event = bge_reg_get32(bgep, RX_RISC_EVENT_REG); 55001408Srandyf tries = 0; 55011408Srandyf while ((event & RRER_ASF_EVENT) && (tries < 100)) { 55021408Srandyf drv_usecwait(1); 55031408Srandyf tries ++; 55041408Srandyf event = bge_reg_get32(bgep, RX_RISC_EVENT_REG); 55051408Srandyf } 55061408Srandyf 55071408Srandyf bge_nic_put32(bgep, BGE_FIRMWARE_MAILBOX, 55084588Sml149210 BGE_MAGIC_NUM_FIRMWARE_INIT_DONE); 55091408Srandyf 55101408Srandyf if (bgep->asf_newhandshake) { 55111408Srandyf switch (mode) { 55121408Srandyf case BGE_INIT_RESET: 55131408Srandyf bge_nic_put32(bgep, BGE_DRV_STATE_MAILBOX, 55144588Sml149210 BGE_DRV_STATE_START); 55151408Srandyf break; 55161408Srandyf case BGE_SHUTDOWN_RESET: 55171408Srandyf bge_nic_put32(bgep, BGE_DRV_STATE_MAILBOX, 55184588Sml149210 BGE_DRV_STATE_UNLOAD); 55191408Srandyf break; 55201408Srandyf case BGE_SUSPEND_RESET: 55211408Srandyf bge_nic_put32(bgep, BGE_DRV_STATE_MAILBOX, 55224588Sml149210 BGE_DRV_STATE_SUSPEND); 55231408Srandyf break; 55241408Srandyf default: 55251408Srandyf break; 55261408Srandyf } 55271408Srandyf } 55281408Srandyf } 55291408Srandyf 55301408Srandyf 55311408Srandyf void 55321408Srandyf bge_asf_post_reset_old_mode(bge_t *bgep, uint32_t mode) 55331408Srandyf { 55341408Srandyf switch (mode) { 55351408Srandyf case BGE_INIT_RESET: 55361408Srandyf bge_nic_put32(bgep, BGE_DRV_STATE_MAILBOX, 55374588Sml149210 BGE_DRV_STATE_START); 55381408Srandyf break; 55391408Srandyf case BGE_SHUTDOWN_RESET: 55401408Srandyf bge_nic_put32(bgep, BGE_DRV_STATE_MAILBOX, 55414588Sml149210 BGE_DRV_STATE_UNLOAD); 55421408Srandyf break; 55431408Srandyf case BGE_SUSPEND_RESET: 55441408Srandyf bge_nic_put32(bgep, BGE_DRV_STATE_MAILBOX, 55454588Sml149210 BGE_DRV_STATE_SUSPEND); 55461408Srandyf break; 55471408Srandyf default: 55481408Srandyf break; 55491408Srandyf } 55501408Srandyf } 55511408Srandyf 55521408Srandyf 55531408Srandyf void 55541408Srandyf bge_asf_post_reset_new_mode(bge_t *bgep, uint32_t mode) 55551408Srandyf { 55561408Srandyf switch (mode) { 55571408Srandyf case BGE_INIT_RESET: 55581408Srandyf bge_nic_put32(bgep, BGE_DRV_STATE_MAILBOX, 55594588Sml149210 BGE_DRV_STATE_START_DONE); 55601408Srandyf break; 55611408Srandyf case BGE_SHUTDOWN_RESET: 55621408Srandyf bge_nic_put32(bgep, BGE_DRV_STATE_MAILBOX, 55634588Sml149210 BGE_DRV_STATE_UNLOAD_DONE); 55641408Srandyf break; 55651408Srandyf default: 55661408Srandyf break; 55671408Srandyf } 55681408Srandyf } 55691408Srandyf 55701408Srandyf #endif /* BGE_IPMI_ASF */ 5571