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 /* 23*11479SYong.Tan@Sun.COM * Copyright 2010 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 /* 1533918Sml149210 * bge_intr_max_loop controls the maximum loop number within bge_intr. 1543918Sml149210 * When loading NIC with heavy network traffic, it is useful. 1553918Sml149210 * Increasing this value could have positive effect to throughput, 1563918Sml149210 * but it might also increase ticks of a bge ISR stick on CPU, which might 1573918Sml149210 * lead to bad UI interactive experience. So tune this with caution. 1583918Sml149210 */ 1593918Sml149210 static int bge_intr_max_loop = 1; 1603918Sml149210 1613918Sml149210 /* 1621369Sdduvall * ========== Low-level chip & ring buffer manipulation ========== 1631369Sdduvall */ 1641369Sdduvall 1651369Sdduvall #define BGE_DBG BGE_DBG_REGS /* debug flag for this code */ 1661369Sdduvall 1671369Sdduvall 1681369Sdduvall /* 1691369Sdduvall * Config space read-modify-write routines 1701369Sdduvall */ 1711369Sdduvall 1721369Sdduvall #if BGE_CFG_IO8 1731369Sdduvall 1741369Sdduvall static void bge_cfg_clr16(bge_t *bgep, bge_regno_t regno, uint16_t bits); 1751369Sdduvall #pragma inline(bge_cfg_clr16) 1761369Sdduvall 1771369Sdduvall static void 1781369Sdduvall bge_cfg_clr16(bge_t *bgep, bge_regno_t regno, uint16_t bits) 1791369Sdduvall { 1801369Sdduvall uint16_t regval; 1811369Sdduvall 1821369Sdduvall BGE_TRACE(("bge_cfg_clr16($%p, 0x%lx, 0x%x)", 1834588Sml149210 (void *)bgep, regno, bits)); 1841369Sdduvall 1851369Sdduvall regval = pci_config_get16(bgep->cfg_handle, regno); 1861369Sdduvall 1871369Sdduvall BGE_DEBUG(("bge_cfg_clr16($%p, 0x%lx, 0x%x): 0x%x => 0x%x", 1884588Sml149210 (void *)bgep, regno, bits, regval, regval & ~bits)); 1891369Sdduvall 1901369Sdduvall regval &= ~bits; 1911369Sdduvall pci_config_put16(bgep->cfg_handle, regno, regval); 1921369Sdduvall } 1931369Sdduvall 1941369Sdduvall #endif /* BGE_CFG_IO8 */ 1951369Sdduvall 1961369Sdduvall static void bge_cfg_clr32(bge_t *bgep, bge_regno_t regno, uint32_t bits); 1971369Sdduvall #pragma inline(bge_cfg_clr32) 1981369Sdduvall 1991369Sdduvall static void 2001369Sdduvall bge_cfg_clr32(bge_t *bgep, bge_regno_t regno, uint32_t bits) 2011369Sdduvall { 2021369Sdduvall uint32_t regval; 2031369Sdduvall 2041369Sdduvall BGE_TRACE(("bge_cfg_clr32($%p, 0x%lx, 0x%x)", 2054588Sml149210 (void *)bgep, regno, bits)); 2061369Sdduvall 2071369Sdduvall regval = pci_config_get32(bgep->cfg_handle, regno); 2081369Sdduvall 2091369Sdduvall BGE_DEBUG(("bge_cfg_clr32($%p, 0x%lx, 0x%x): 0x%x => 0x%x", 2104588Sml149210 (void *)bgep, regno, bits, regval, regval & ~bits)); 2111369Sdduvall 2121369Sdduvall regval &= ~bits; 2131369Sdduvall pci_config_put32(bgep->cfg_handle, regno, regval); 2141369Sdduvall } 2151369Sdduvall 2161369Sdduvall #if BGE_IND_IO32 2171369Sdduvall 2181369Sdduvall /* 2191369Sdduvall * Indirect access to registers & RISC scratchpads, using config space 2201369Sdduvall * accesses only. 2211369Sdduvall * 2221369Sdduvall * This isn't currently used, but someday we might want to use it for 2231369Sdduvall * restoring the Subsystem Device/Vendor registers (which aren't directly 2241369Sdduvall * writable in Config Space), or for downloading firmware into the RISCs 2251369Sdduvall * 2261369Sdduvall * In any case there are endian issues to be resolved before this code is 2271369Sdduvall * enabled; the bizarre way that bytes get twisted by this chip AND by 2281369Sdduvall * the PCI bridge in SPARC systems mean that we shouldn't enable it until 2291369Sdduvall * it's been thoroughly tested for all access sizes on all supported 2301369Sdduvall * architectures (SPARC *and* x86!). 2311369Sdduvall */ 2323918Sml149210 uint32_t bge_ind_get32(bge_t *bgep, bge_regno_t regno); 2331369Sdduvall #pragma inline(bge_ind_get32) 2341369Sdduvall 2353918Sml149210 uint32_t 2361369Sdduvall bge_ind_get32(bge_t *bgep, bge_regno_t regno) 2371369Sdduvall { 2381369Sdduvall uint32_t val; 2391369Sdduvall 2401369Sdduvall BGE_TRACE(("bge_ind_get32($%p, 0x%lx)", (void *)bgep, regno)); 2411369Sdduvall 2421369Sdduvall pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_RIAAR, regno); 2431369Sdduvall val = pci_config_get32(bgep->cfg_handle, PCI_CONF_BGE_RIADR); 2441369Sdduvall 2451369Sdduvall BGE_DEBUG(("bge_ind_get32($%p, 0x%lx) => 0x%x", 2464588Sml149210 (void *)bgep, regno, val)); 2471369Sdduvall 2483918Sml149210 val = LE_32(val); 2493918Sml149210 2501369Sdduvall return (val); 2511369Sdduvall } 2521369Sdduvall 2533918Sml149210 void bge_ind_put32(bge_t *bgep, bge_regno_t regno, uint32_t val); 2541369Sdduvall #pragma inline(bge_ind_put32) 2551369Sdduvall 2563918Sml149210 void 2571369Sdduvall bge_ind_put32(bge_t *bgep, bge_regno_t regno, uint32_t val) 2581369Sdduvall { 2591369Sdduvall BGE_TRACE(("bge_ind_put32($%p, 0x%lx, 0x%x)", 2604588Sml149210 (void *)bgep, regno, val)); 2611369Sdduvall 2623918Sml149210 val = LE_32(val); 2631369Sdduvall pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_RIAAR, regno); 2641369Sdduvall pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_RIADR, val); 2651369Sdduvall } 2661369Sdduvall 2671369Sdduvall #endif /* BGE_IND_IO32 */ 2681369Sdduvall 2691369Sdduvall #if BGE_DEBUGGING 2701369Sdduvall 2711369Sdduvall static void bge_pci_check(bge_t *bgep); 2721369Sdduvall #pragma no_inline(bge_pci_check) 2731369Sdduvall 2741369Sdduvall static void 2751369Sdduvall bge_pci_check(bge_t *bgep) 2761369Sdduvall { 2771369Sdduvall uint16_t pcistatus; 2781369Sdduvall 2791369Sdduvall pcistatus = pci_config_get16(bgep->cfg_handle, PCI_CONF_STAT); 2801369Sdduvall if ((pcistatus & (PCI_STAT_R_MAST_AB | PCI_STAT_R_TARG_AB)) != 0) 2811369Sdduvall BGE_DEBUG(("bge_pci_check($%p): PCI status 0x%x", 2824588Sml149210 (void *)bgep, pcistatus)); 2831369Sdduvall } 2841369Sdduvall 2851369Sdduvall #endif /* BGE_DEBUGGING */ 2861369Sdduvall 2871369Sdduvall /* 2881369Sdduvall * Perform first-stage chip (re-)initialisation, using only config-space 2891369Sdduvall * accesses: 2901369Sdduvall * 2911369Sdduvall * + Read the vendor/device/revision/subsystem/cache-line-size registers, 2921369Sdduvall * returning the data in the structure pointed to by <idp>. 2931369Sdduvall * + Configure the target-mode endianness (swap) options. 2941369Sdduvall * + Disable interrupts and enable Memory Space accesses. 2951369Sdduvall * + Enable or disable Bus Mastering according to the <enable_dma> flag. 2961369Sdduvall * 2971369Sdduvall * This sequence is adapted from Broadcom document 570X-PG102-R, 2981369Sdduvall * page 102, steps 1-3, 6-8 and 11-13. The omitted parts of the sequence 2991369Sdduvall * are 4 and 5 (Reset Core and wait) which are handled elsewhere. 3001369Sdduvall * 3011369Sdduvall * This function MUST be called before any non-config-space accesses 3021369Sdduvall * are made; on this first call <enable_dma> is B_FALSE, and it 3031369Sdduvall * effectively performs steps 3-1(!) of the initialisation sequence 3041369Sdduvall * (the rest are not required but should be harmless). 3051369Sdduvall * 3062135Szh199473 * It MUST also be called after a chip reset, as this disables 3071369Sdduvall * Memory Space cycles! In this case, <enable_dma> is B_TRUE, and 3081369Sdduvall * it is effectively performing steps 6-8. 3091369Sdduvall */ 3101369Sdduvall void bge_chip_cfg_init(bge_t *bgep, chip_id_t *cidp, boolean_t enable_dma); 3111369Sdduvall #pragma no_inline(bge_chip_cfg_init) 3121369Sdduvall 3131369Sdduvall void 3141369Sdduvall bge_chip_cfg_init(bge_t *bgep, chip_id_t *cidp, boolean_t enable_dma) 3151369Sdduvall { 3161369Sdduvall ddi_acc_handle_t handle; 3171369Sdduvall uint16_t command; 3181369Sdduvall uint32_t mhcr; 3191369Sdduvall uint16_t value16; 3201369Sdduvall int i; 3211369Sdduvall 3221369Sdduvall BGE_TRACE(("bge_chip_cfg_init($%p, $%p, %d)", 3234588Sml149210 (void *)bgep, (void *)cidp, enable_dma)); 3241369Sdduvall 3251369Sdduvall /* 3261369Sdduvall * Step 3: save PCI cache line size and subsystem vendor ID 3271369Sdduvall * 3281369Sdduvall * Read all the config-space registers that characterise the 3291369Sdduvall * chip, specifically vendor/device/revision/subsystem vendor 3301369Sdduvall * and subsystem device id. We expect (but don't check) that 3311369Sdduvall * (vendor == VENDOR_ID_BROADCOM) && (device == DEVICE_ID_5704) 3321369Sdduvall * 3332135Szh199473 * Also save all bus-transaction related registers (cache-line 3341369Sdduvall * size, bus-grant/latency parameters, etc). Some of these are 3351369Sdduvall * cleared by reset, so we'll have to restore them later. This 3361369Sdduvall * comes from the Broadcom document 570X-PG102-R ... 3371369Sdduvall * 3381369Sdduvall * Note: Broadcom document 570X-PG102-R seems to be in error 3391369Sdduvall * here w.r.t. the offsets of the Subsystem Vendor ID and 3401369Sdduvall * Subsystem (Device) ID registers, which are the opposite way 3411369Sdduvall * round according to the PCI standard. For good measure, we 3421369Sdduvall * save/restore both anyway. 3431369Sdduvall */ 3441369Sdduvall handle = bgep->cfg_handle; 3451369Sdduvall 3461369Sdduvall mhcr = pci_config_get32(handle, PCI_CONF_BGE_MHCR); 3471369Sdduvall cidp->asic_rev = mhcr & MHCR_CHIP_REV_MASK; 3481369Sdduvall cidp->businfo = pci_config_get32(handle, PCI_CONF_BGE_PCISTATE); 3491369Sdduvall cidp->command = pci_config_get16(handle, PCI_CONF_COMM); 3501369Sdduvall 3511369Sdduvall cidp->vendor = pci_config_get16(handle, PCI_CONF_VENID); 3521369Sdduvall cidp->device = pci_config_get16(handle, PCI_CONF_DEVID); 3531369Sdduvall cidp->subven = pci_config_get16(handle, PCI_CONF_SUBVENID); 3541369Sdduvall cidp->subdev = pci_config_get16(handle, PCI_CONF_SUBSYSID); 3551369Sdduvall cidp->revision = pci_config_get8(handle, PCI_CONF_REVID); 3561369Sdduvall cidp->clsize = pci_config_get8(handle, PCI_CONF_CACHE_LINESZ); 3571369Sdduvall cidp->latency = pci_config_get8(handle, PCI_CONF_LATENCY_TIMER); 3581369Sdduvall 3591369Sdduvall BGE_DEBUG(("bge_chip_cfg_init: %s bus is %s and %s; #INTA is %s", 3604588Sml149210 cidp->businfo & PCISTATE_BUS_IS_PCI ? "PCI" : "PCI-X", 3614588Sml149210 cidp->businfo & PCISTATE_BUS_IS_FAST ? "fast" : "slow", 3624588Sml149210 cidp->businfo & PCISTATE_BUS_IS_32_BIT ? "narrow" : "wide", 3634588Sml149210 cidp->businfo & PCISTATE_INTA_STATE ? "high" : "low")); 3641369Sdduvall BGE_DEBUG(("bge_chip_cfg_init: vendor 0x%x device 0x%x revision 0x%x", 3654588Sml149210 cidp->vendor, cidp->device, cidp->revision)); 3661369Sdduvall BGE_DEBUG(("bge_chip_cfg_init: subven 0x%x subdev 0x%x asic_rev 0x%x", 3674588Sml149210 cidp->subven, cidp->subdev, cidp->asic_rev)); 3681369Sdduvall BGE_DEBUG(("bge_chip_cfg_init: clsize %d latency %d command 0x%x", 3694588Sml149210 cidp->clsize, cidp->latency, cidp->command)); 3701369Sdduvall 3711369Sdduvall /* 3721369Sdduvall * Step 2 (also step 6): disable and clear interrupts. 3731369Sdduvall * Steps 11-13: configure PIO endianness options, and enable 3741369Sdduvall * indirect register access. We'll also select any other 3752135Szh199473 * options controlled by the MHCR (e.g. tagged status, mask 3761369Sdduvall * interrupt mode) at this stage ... 3771369Sdduvall * 3781369Sdduvall * Note: internally, the chip is 64-bit and BIG-endian, but 3791369Sdduvall * since it talks to the host over a (LITTLE-endian) PCI bus, 3801369Sdduvall * it normally swaps bytes around at the PCI interface. 3811369Sdduvall * However, the PCI host bridge on SPARC systems normally 3821369Sdduvall * swaps the byte lanes around too, since SPARCs are also 3831369Sdduvall * BIG-endian. So it turns out that on SPARC, the right 3841369Sdduvall * option is to tell the chip to swap (and the host bridge 3851369Sdduvall * will swap back again), whereas on x86 we ask the chip 3861369Sdduvall * NOT to swap, so the natural little-endianness of the 3871369Sdduvall * PCI bus is assumed. Then the only thing that doesn't 3881369Sdduvall * automatically work right is access to an 8-byte register 3891369Sdduvall * by a little-endian host; but we don't want to set the 3901369Sdduvall * MHCR_ENABLE_REGISTER_WORD_SWAP bit because then 4-byte 3911369Sdduvall * accesses don't go where expected ;-( So we live with 3921369Sdduvall * that, and perform word-swaps in software in the few cases 3931369Sdduvall * where a chip register is defined as an 8-byte value -- 3941369Sdduvall * see the code below for details ... 3951369Sdduvall * 3961369Sdduvall * Note: the meaning of the 'MASK_INTERRUPT_MODE' bit isn't 3971369Sdduvall * very clear in the register description in the PRM, but 3981369Sdduvall * Broadcom document 570X-PG104-R page 248 explains a little 3991369Sdduvall * more (under "Broadcom Mask Mode"). The bit changes the way 4001369Sdduvall * the MASK_PCI_INT_OUTPUT bit works: with MASK_INTERRUPT_MODE 4011369Sdduvall * clear, the chip interprets MASK_PCI_INT_OUTPUT in the same 4021369Sdduvall * way as the 5700 did, which isn't very convenient. Setting 4031369Sdduvall * the MASK_INTERRUPT_MODE bit makes the MASK_PCI_INT_OUTPUT 4041369Sdduvall * bit do just what its name says -- MASK the PCI #INTA output 4051369Sdduvall * (i.e. deassert the signal at the pin) leaving all internal 4061369Sdduvall * state unchanged. This is much more convenient for our 4071369Sdduvall * interrupt handler, so we set MASK_INTERRUPT_MODE here. 4081369Sdduvall * 4091369Sdduvall * Note: the inconvenient semantics of the interrupt mailbox 4101369Sdduvall * (nonzero disables and acknowledges/clears the interrupt, 4111369Sdduvall * zero enables AND CLEARS it) would make race conditions 4121369Sdduvall * likely in the interrupt handler: 4131369Sdduvall * 4141369Sdduvall * (1) acknowledge & disable interrupts 4151369Sdduvall * (2) while (more to do) 4161369Sdduvall * process packets 4171369Sdduvall * (3) enable interrupts -- also clears pending 4181369Sdduvall * 4191369Sdduvall * If the chip received more packets and internally generated 4201369Sdduvall * an interrupt between the check at (2) and the mbox write 4211369Sdduvall * at (3), this interrupt would be lost :-( 4221369Sdduvall * 4231369Sdduvall * The best way to avoid this is to use TAGGED STATUS mode, 4241369Sdduvall * where the chip includes a unique tag in each status block 4251369Sdduvall * update, and the host, when re-enabling interrupts, passes 4261369Sdduvall * the last tag it saw back to the chip; then the chip can 4271369Sdduvall * see whether the host is truly up to date, and regenerate 4281369Sdduvall * its interrupt if not. 4291369Sdduvall */ 4301369Sdduvall mhcr = MHCR_ENABLE_INDIRECT_ACCESS | 4314588Sml149210 MHCR_ENABLE_TAGGED_STATUS_MODE | 4324588Sml149210 MHCR_MASK_INTERRUPT_MODE | 4334588Sml149210 MHCR_CLEAR_INTERRUPT_INTA; 4341369Sdduvall 4351369Sdduvall if (bgep->intr_type == DDI_INTR_TYPE_FIXED) 4361369Sdduvall mhcr |= MHCR_MASK_PCI_INT_OUTPUT; 4371369Sdduvall 4381369Sdduvall #ifdef _BIG_ENDIAN 4391369Sdduvall mhcr |= MHCR_ENABLE_ENDIAN_WORD_SWAP | MHCR_ENABLE_ENDIAN_BYTE_SWAP; 4401369Sdduvall #endif /* _BIG_ENDIAN */ 4411369Sdduvall 4421369Sdduvall pci_config_put32(handle, PCI_CONF_BGE_MHCR, mhcr); 4431369Sdduvall 4441408Srandyf #ifdef BGE_IPMI_ASF 4451408Srandyf bgep->asf_wordswapped = B_FALSE; 4461408Srandyf #endif 4471369Sdduvall /* 4481369Sdduvall * Step 1 (also step 7): Enable PCI Memory Space accesses 4491369Sdduvall * Disable Memory Write/Invalidate 4501369Sdduvall * Enable or disable Bus Mastering 4511369Sdduvall * 4521369Sdduvall * Note that all other bits are taken from the original value saved 4531369Sdduvall * the first time through here, rather than from the current register 4541369Sdduvall * value, 'cos that will have been cleared by a soft RESET since. 4551369Sdduvall * In this way we preserve the OBP/nexus-parent's preferred settings 4561369Sdduvall * of the parity-error and system-error enable bits across multiple 4571369Sdduvall * chip RESETs. 4581369Sdduvall */ 4591369Sdduvall command = bgep->chipid.command | PCI_COMM_MAE; 4601369Sdduvall command &= ~(PCI_COMM_ME|PCI_COMM_MEMWR_INVAL); 4611369Sdduvall if (enable_dma) 4621369Sdduvall command |= PCI_COMM_ME; 4631369Sdduvall /* 4641369Sdduvall * on BCM5714 revision A0, false parity error gets generated 4652135Szh199473 * due to a logic bug. Provide a workaround by disabling parity 4661369Sdduvall * error. 4671369Sdduvall */ 4681369Sdduvall if (((cidp->device == DEVICE_ID_5714C) || 4691369Sdduvall (cidp->device == DEVICE_ID_5714S)) && 4701369Sdduvall (cidp->revision == REVISION_ID_5714_A0)) { 4711369Sdduvall command &= ~PCI_COMM_PARITY_DETECT; 4721369Sdduvall } 4731369Sdduvall pci_config_put16(handle, PCI_CONF_COMM, command); 4741369Sdduvall 4751369Sdduvall /* 4761369Sdduvall * On some PCI-E device, there were instances when 4771369Sdduvall * the device was still link training. 4781369Sdduvall */ 4791369Sdduvall if (bgep->chipid.pci_type == BGE_PCI_E) { 4801369Sdduvall i = 0; 4811369Sdduvall value16 = pci_config_get16(handle, PCI_CONF_COMM); 4821369Sdduvall while ((value16 != command) && (i < 100)) { 4831369Sdduvall drv_usecwait(200); 4841369Sdduvall value16 = pci_config_get16(handle, PCI_CONF_COMM); 4851369Sdduvall ++i; 4861369Sdduvall } 4871369Sdduvall } 4881369Sdduvall 4891369Sdduvall /* 4901369Sdduvall * Clear any remaining error status bits 4911369Sdduvall */ 4921369Sdduvall pci_config_put16(handle, PCI_CONF_STAT, ~0); 4931369Sdduvall 4941369Sdduvall /* 4952073Svivek * Do following if and only if the device is NOT BCM5714C OR 4962073Svivek * BCM5715C 4971369Sdduvall */ 4982073Svivek if (!((cidp->device == DEVICE_ID_5714C) || 4994588Sml149210 (cidp->device == DEVICE_ID_5715C))) { 5002073Svivek /* 5012073Svivek * Make sure these indirect-access registers are sane 5022073Svivek * rather than random after power-up or reset 5032073Svivek */ 5042073Svivek pci_config_put32(handle, PCI_CONF_BGE_RIAAR, 0); 5052073Svivek pci_config_put32(handle, PCI_CONF_BGE_MWBAR, 0); 5062073Svivek } 5072135Szh199473 /* 5082135Szh199473 * Step 8: Disable PCI-X/PCI-E Relaxed Ordering 5092135Szh199473 */ 5102135Szh199473 bge_cfg_clr16(bgep, PCIX_CONF_COMM, PCIX_COMM_RELAXED); 5112135Szh199473 5129042SYong.Tan@Sun.COM if (cidp->pci_type == BGE_PCI_E) { 5139042SYong.Tan@Sun.COM if (DEVICE_5723_SERIES_CHIPSETS(bgep)) { 5149042SYong.Tan@Sun.COM bge_cfg_clr16(bgep, PCI_CONF_DEV_CTRL_5723, 5159042SYong.Tan@Sun.COM DEV_CTRL_NO_SNOOP | DEV_CTRL_RELAXED); 5169042SYong.Tan@Sun.COM } else 5179042SYong.Tan@Sun.COM bge_cfg_clr16(bgep, PCI_CONF_DEV_CTRL, 5189042SYong.Tan@Sun.COM DEV_CTRL_NO_SNOOP | DEV_CTRL_RELAXED); 5199042SYong.Tan@Sun.COM } 5201369Sdduvall } 5211369Sdduvall 5221369Sdduvall #ifdef __amd64 5231369Sdduvall /* 5241369Sdduvall * Distinguish CPU types 5251369Sdduvall * 5261369Sdduvall * These use to distinguish AMD64 or Intel EM64T of CPU running mode. 5271369Sdduvall * If CPU runs on Intel EM64T mode,the 64bit operation cannot works fine 5281369Sdduvall * for PCI-Express based network interface card. This is the work-around 5291369Sdduvall * for those nics. 5301369Sdduvall */ 5311369Sdduvall static boolean_t bge_get_em64t_type(void); 5321369Sdduvall #pragma inline(bge_get_em64t_type) 5331369Sdduvall 5341369Sdduvall static boolean_t 5351369Sdduvall bge_get_em64t_type(void) 5361369Sdduvall { 5371369Sdduvall 5381369Sdduvall return (x86_vendor == X86_VENDOR_Intel); 5391369Sdduvall } 5401369Sdduvall #endif 5411369Sdduvall 5421369Sdduvall /* 5431369Sdduvall * Operating register get/set access routines 5441369Sdduvall */ 5451369Sdduvall 5461369Sdduvall uint32_t bge_reg_get32(bge_t *bgep, bge_regno_t regno); 5471369Sdduvall #pragma inline(bge_reg_get32) 5481369Sdduvall 5491369Sdduvall uint32_t 5501369Sdduvall bge_reg_get32(bge_t *bgep, bge_regno_t regno) 5511369Sdduvall { 5521369Sdduvall BGE_TRACE(("bge_reg_get32($%p, 0x%lx)", 5534588Sml149210 (void *)bgep, regno)); 5541369Sdduvall 5551369Sdduvall return (ddi_get32(bgep->io_handle, PIO_ADDR(bgep, regno))); 5561369Sdduvall } 5571369Sdduvall 5581369Sdduvall void bge_reg_put32(bge_t *bgep, bge_regno_t regno, uint32_t data); 5591369Sdduvall #pragma inline(bge_reg_put32) 5601369Sdduvall 5611369Sdduvall void 5621369Sdduvall bge_reg_put32(bge_t *bgep, bge_regno_t regno, uint32_t data) 5631369Sdduvall { 5641369Sdduvall BGE_TRACE(("bge_reg_put32($%p, 0x%lx, 0x%x)", 5654588Sml149210 (void *)bgep, regno, data)); 5661369Sdduvall 5671369Sdduvall ddi_put32(bgep->io_handle, PIO_ADDR(bgep, regno), data); 5681369Sdduvall BGE_PCICHK(bgep); 5691369Sdduvall } 5701369Sdduvall 5711369Sdduvall void bge_reg_set32(bge_t *bgep, bge_regno_t regno, uint32_t bits); 5721369Sdduvall #pragma inline(bge_reg_set32) 5731369Sdduvall 5741369Sdduvall void 5751369Sdduvall bge_reg_set32(bge_t *bgep, bge_regno_t regno, uint32_t bits) 5761369Sdduvall { 5771369Sdduvall uint32_t regval; 5781369Sdduvall 5791369Sdduvall BGE_TRACE(("bge_reg_set32($%p, 0x%lx, 0x%x)", 5804588Sml149210 (void *)bgep, regno, bits)); 5811369Sdduvall 5821369Sdduvall regval = bge_reg_get32(bgep, regno); 5831369Sdduvall regval |= bits; 5841369Sdduvall bge_reg_put32(bgep, regno, regval); 5851369Sdduvall } 5861369Sdduvall 5871369Sdduvall void bge_reg_clr32(bge_t *bgep, bge_regno_t regno, uint32_t bits); 5881369Sdduvall #pragma inline(bge_reg_clr32) 5891369Sdduvall 5901369Sdduvall void 5911369Sdduvall bge_reg_clr32(bge_t *bgep, bge_regno_t regno, uint32_t bits) 5921369Sdduvall { 5931369Sdduvall uint32_t regval; 5941369Sdduvall 5951369Sdduvall BGE_TRACE(("bge_reg_clr32($%p, 0x%lx, 0x%x)", 5964588Sml149210 (void *)bgep, regno, bits)); 5971369Sdduvall 5981369Sdduvall regval = bge_reg_get32(bgep, regno); 5991369Sdduvall regval &= ~bits; 6001369Sdduvall bge_reg_put32(bgep, regno, regval); 6011369Sdduvall } 6021369Sdduvall 6031369Sdduvall static uint64_t bge_reg_get64(bge_t *bgep, bge_regno_t regno); 6041369Sdduvall #pragma inline(bge_reg_get64) 6051369Sdduvall 6061369Sdduvall static uint64_t 6071369Sdduvall bge_reg_get64(bge_t *bgep, bge_regno_t regno) 6081369Sdduvall { 6091369Sdduvall uint64_t regval; 6101369Sdduvall 6111369Sdduvall #ifdef __amd64 6129042SYong.Tan@Sun.COM if (DEVICE_5723_SERIES_CHIPSETS(bgep) || bge_get_em64t_type()) { 6131369Sdduvall regval = ddi_get32(bgep->io_handle, PIO_ADDR(bgep, regno + 4)); 6141369Sdduvall regval <<= 32; 6151369Sdduvall regval |= ddi_get32(bgep->io_handle, PIO_ADDR(bgep, regno)); 6161369Sdduvall } else { 6171369Sdduvall regval = ddi_get64(bgep->io_handle, PIO_ADDR(bgep, regno)); 6181369Sdduvall } 6199042SYong.Tan@Sun.COM #elif defined(__sparc) 6209042SYong.Tan@Sun.COM if (DEVICE_5723_SERIES_CHIPSETS(bgep)) { 6219042SYong.Tan@Sun.COM regval = ddi_get32(bgep->io_handle, PIO_ADDR(bgep, regno)); 6229042SYong.Tan@Sun.COM regval <<= 32; 6239042SYong.Tan@Sun.COM regval |= ddi_get32(bgep->io_handle, PIO_ADDR(bgep, regno + 4)); 6249042SYong.Tan@Sun.COM } else { 6259042SYong.Tan@Sun.COM regval = ddi_get64(bgep->io_handle, PIO_ADDR(bgep, regno)); 6269042SYong.Tan@Sun.COM } 6271369Sdduvall #else 6281369Sdduvall regval = ddi_get64(bgep->io_handle, PIO_ADDR(bgep, regno)); 6291369Sdduvall #endif 6301369Sdduvall 6311369Sdduvall #ifdef _LITTLE_ENDIAN 6321369Sdduvall regval = (regval >> 32) | (regval << 32); 6331369Sdduvall #endif /* _LITTLE_ENDIAN */ 6341369Sdduvall 6351369Sdduvall BGE_TRACE(("bge_reg_get64($%p, 0x%lx) = 0x%016llx", 6364588Sml149210 (void *)bgep, regno, regval)); 6371369Sdduvall 6381369Sdduvall return (regval); 6391369Sdduvall } 6401369Sdduvall 6411369Sdduvall static void bge_reg_put64(bge_t *bgep, bge_regno_t regno, uint64_t data); 6421369Sdduvall #pragma inline(bge_reg_put64) 6431369Sdduvall 6441369Sdduvall static void 6451369Sdduvall bge_reg_put64(bge_t *bgep, bge_regno_t regno, uint64_t data) 6461369Sdduvall { 6471369Sdduvall BGE_TRACE(("bge_reg_put64($%p, 0x%lx, 0x%016llx)", 6484588Sml149210 (void *)bgep, regno, data)); 6491369Sdduvall 6501369Sdduvall #ifdef _LITTLE_ENDIAN 6511369Sdduvall data = ((data >> 32) | (data << 32)); 6521369Sdduvall #endif /* _LITTLE_ENDIAN */ 6531369Sdduvall 6541369Sdduvall #ifdef __amd64 6559042SYong.Tan@Sun.COM if (DEVICE_5723_SERIES_CHIPSETS(bgep) || bge_get_em64t_type()) { 6561369Sdduvall ddi_put32(bgep->io_handle, 6574588Sml149210 PIO_ADDR(bgep, regno), (uint32_t)data); 6581369Sdduvall BGE_PCICHK(bgep); 6591369Sdduvall ddi_put32(bgep->io_handle, 6604588Sml149210 PIO_ADDR(bgep, regno + 4), (uint32_t)(data >> 32)); 6611369Sdduvall 6621369Sdduvall } else { 6631369Sdduvall ddi_put64(bgep->io_handle, PIO_ADDR(bgep, regno), data); 6641369Sdduvall } 6659042SYong.Tan@Sun.COM #elif defined(__sparc) 6669042SYong.Tan@Sun.COM if (DEVICE_5723_SERIES_CHIPSETS(bgep)) { 6679042SYong.Tan@Sun.COM ddi_put32(bgep->io_handle, 6689042SYong.Tan@Sun.COM PIO_ADDR(bgep, regno + 4), (uint32_t)data); 6699042SYong.Tan@Sun.COM BGE_PCICHK(bgep); 6709042SYong.Tan@Sun.COM ddi_put32(bgep->io_handle, 6719042SYong.Tan@Sun.COM PIO_ADDR(bgep, regno), (uint32_t)(data >> 32)); 6729042SYong.Tan@Sun.COM } else { 6739042SYong.Tan@Sun.COM ddi_put64(bgep->io_handle, PIO_ADDR(bgep, regno), data); 6749042SYong.Tan@Sun.COM } 6751369Sdduvall #else 6761369Sdduvall ddi_put64(bgep->io_handle, PIO_ADDR(bgep, regno), data); 6771369Sdduvall #endif 6781369Sdduvall 6791369Sdduvall BGE_PCICHK(bgep); 6801369Sdduvall } 6811369Sdduvall 6821369Sdduvall /* 6831369Sdduvall * The DDI doesn't provide get/put functions for 128 bit data 6841369Sdduvall * so we put RCBs out as two 64-bit chunks instead. 6851369Sdduvall */ 6861369Sdduvall static void bge_reg_putrcb(bge_t *bgep, bge_regno_t addr, bge_rcb_t *rcbp); 6871369Sdduvall #pragma inline(bge_reg_putrcb) 6881369Sdduvall 6891369Sdduvall static void 6901369Sdduvall bge_reg_putrcb(bge_t *bgep, bge_regno_t addr, bge_rcb_t *rcbp) 6911369Sdduvall { 6921369Sdduvall uint64_t *p; 6931369Sdduvall 6941369Sdduvall BGE_TRACE(("bge_reg_putrcb($%p, 0x%lx, 0x%016llx:%04x:%04x:%08x)", 6954588Sml149210 (void *)bgep, addr, rcbp->host_ring_addr, 6964588Sml149210 rcbp->max_len, rcbp->flags, rcbp->nic_ring_addr)); 6971369Sdduvall 6981369Sdduvall ASSERT((addr % sizeof (*rcbp)) == 0); 6991369Sdduvall 7001369Sdduvall p = (void *)rcbp; 7011369Sdduvall bge_reg_put64(bgep, addr, *p++); 7021369Sdduvall bge_reg_put64(bgep, addr+8, *p); 7031369Sdduvall } 7041369Sdduvall 7051369Sdduvall void bge_mbx_put(bge_t *bgep, bge_regno_t regno, uint64_t data); 7061369Sdduvall #pragma inline(bge_mbx_put) 7071369Sdduvall 7081369Sdduvall void 7091369Sdduvall bge_mbx_put(bge_t *bgep, bge_regno_t regno, uint64_t data) 7101369Sdduvall { 7117678SYong.Tan@Sun.COM if (DEVICE_5906_SERIES_CHIPSETS(bgep)) 7127678SYong.Tan@Sun.COM regno += INTERRUPT_LP_MBOX_0_REG - INTERRUPT_MBOX_0_REG + 4; 7137678SYong.Tan@Sun.COM 7141369Sdduvall BGE_TRACE(("bge_mbx_put($%p, 0x%lx, 0x%016llx)", 7154588Sml149210 (void *)bgep, regno, data)); 7161369Sdduvall 7171369Sdduvall /* 7181369Sdduvall * Mailbox registers are nominally 64 bits on the 5701, but 7191369Sdduvall * the MSW isn't used. On the 5703, they're only 32 bits 7201369Sdduvall * anyway. So here we just write the lower(!) 32 bits - 7211369Sdduvall * remembering that the chip is big-endian, even though the 7221369Sdduvall * PCI bus is little-endian ... 7231369Sdduvall */ 7241369Sdduvall #ifdef _BIG_ENDIAN 7251369Sdduvall ddi_put32(bgep->io_handle, PIO_ADDR(bgep, regno+4), (uint32_t)data); 7261369Sdduvall #else 7271369Sdduvall ddi_put32(bgep->io_handle, PIO_ADDR(bgep, regno), (uint32_t)data); 7281369Sdduvall #endif /* _BIG_ENDIAN */ 7291369Sdduvall BGE_PCICHK(bgep); 7301369Sdduvall } 7311369Sdduvall 7326546Sgh162552 uint32_t bge_mbx_get(bge_t *bgep, bge_regno_t regno); 7336546Sgh162552 #pragma inline(bge_mbx_get) 7346546Sgh162552 7356546Sgh162552 uint32_t 7366546Sgh162552 bge_mbx_get(bge_t *bgep, bge_regno_t regno) 7376546Sgh162552 { 7386546Sgh162552 uint32_t val32; 7396546Sgh162552 7407678SYong.Tan@Sun.COM if (DEVICE_5906_SERIES_CHIPSETS(bgep)) 7417678SYong.Tan@Sun.COM regno += INTERRUPT_LP_MBOX_0_REG - INTERRUPT_MBOX_0_REG + 4; 7427678SYong.Tan@Sun.COM 7436546Sgh162552 BGE_TRACE(("bge_mbx_get($%p, 0x%lx)", 7446546Sgh162552 (void *)bgep, regno)); 7456546Sgh162552 7466546Sgh162552 #ifdef _BIG_ENDIAN 7476546Sgh162552 val32 = ddi_get32(bgep->io_handle, PIO_ADDR(bgep, regno+4)); 7486546Sgh162552 #else 7496546Sgh162552 val32 = ddi_get32(bgep->io_handle, PIO_ADDR(bgep, regno)); 7506546Sgh162552 #endif /* _BIG_ENDIAN */ 7516546Sgh162552 BGE_PCICHK(bgep); 7526546Sgh162552 7536546Sgh162552 return (val32); 7546546Sgh162552 } 7556546Sgh162552 7566546Sgh162552 7571369Sdduvall #if BGE_DEBUGGING 7581369Sdduvall 7591369Sdduvall void bge_led_mark(bge_t *bgep); 7601369Sdduvall #pragma no_inline(bge_led_mark) 7611369Sdduvall 7621369Sdduvall void 7631369Sdduvall bge_led_mark(bge_t *bgep) 7641369Sdduvall { 7651369Sdduvall uint32_t led_ctrl = LED_CONTROL_OVERRIDE_LINK | 7664588Sml149210 LED_CONTROL_1000MBPS_LED | 7674588Sml149210 LED_CONTROL_100MBPS_LED | 7684588Sml149210 LED_CONTROL_10MBPS_LED; 7691369Sdduvall 7701369Sdduvall /* 7711369Sdduvall * Blink all three LINK LEDs on simultaneously, then all off, 7721369Sdduvall * then restore to automatic hardware control. This is used 7731369Sdduvall * in laboratory testing to trigger a logic analyser or scope. 7741369Sdduvall */ 7751369Sdduvall bge_reg_set32(bgep, ETHERNET_MAC_LED_CONTROL_REG, led_ctrl); 7761369Sdduvall led_ctrl ^= LED_CONTROL_OVERRIDE_LINK; 7771369Sdduvall bge_reg_clr32(bgep, ETHERNET_MAC_LED_CONTROL_REG, led_ctrl); 7781369Sdduvall led_ctrl = LED_CONTROL_OVERRIDE_LINK; 7791369Sdduvall bge_reg_clr32(bgep, ETHERNET_MAC_LED_CONTROL_REG, led_ctrl); 7801369Sdduvall } 7811369Sdduvall 7821369Sdduvall #endif /* BGE_DEBUGGING */ 7831369Sdduvall 7841369Sdduvall /* 7851369Sdduvall * NIC on-chip memory access routines 7861369Sdduvall * 7871369Sdduvall * Only 32K of NIC memory is visible at a time, controlled by the 7881369Sdduvall * Memory Window Base Address Register (in PCI config space). Once 7891369Sdduvall * this is set, the 32K region of NIC-local memory that it refers 7901369Sdduvall * to can be directly addressed in the upper 32K of the 64K of PCI 7911369Sdduvall * memory space used for the device. 7921369Sdduvall */ 7931369Sdduvall 7941369Sdduvall static void bge_nic_setwin(bge_t *bgep, bge_regno_t base); 7951369Sdduvall #pragma inline(bge_nic_setwin) 7961369Sdduvall 7971369Sdduvall static void 7981369Sdduvall bge_nic_setwin(bge_t *bgep, bge_regno_t base) 7991369Sdduvall { 8002073Svivek chip_id_t *cidp; 8012073Svivek 8021369Sdduvall BGE_TRACE(("bge_nic_setwin($%p, 0x%lx)", 8034588Sml149210 (void *)bgep, base)); 8041369Sdduvall 8051369Sdduvall ASSERT((base & MWBAR_GRANULE_MASK) == 0); 8062073Svivek 8072073Svivek /* 8082073Svivek * Don't do repeated zero data writes, 8092073Svivek * if the device is BCM5714C/15C. 8102073Svivek */ 8112073Svivek cidp = &bgep->chipid; 8122073Svivek if ((cidp->device == DEVICE_ID_5714C) || 8134588Sml149210 (cidp->device == DEVICE_ID_5715C)) { 8142073Svivek if (bgep->lastWriteZeroData && (base == (bge_regno_t)0)) 8152073Svivek return; 8162073Svivek /* Adjust lastWriteZeroData */ 8172073Svivek bgep->lastWriteZeroData = ((base == (bge_regno_t)0) ? 8184588Sml149210 B_TRUE : B_FALSE); 8192073Svivek } 8201369Sdduvall pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_MWBAR, base); 8211369Sdduvall } 8221369Sdduvall 8231369Sdduvall static uint32_t bge_nic_get32(bge_t *bgep, bge_regno_t addr); 8241369Sdduvall #pragma inline(bge_nic_get32) 8251369Sdduvall 8261369Sdduvall static uint32_t 8271369Sdduvall bge_nic_get32(bge_t *bgep, bge_regno_t addr) 8281369Sdduvall { 8291369Sdduvall uint32_t data; 8301369Sdduvall 8313918Sml149210 #if defined(BGE_IPMI_ASF) && !defined(__sparc) 8321408Srandyf if (bgep->asf_enabled && !bgep->asf_wordswapped) { 8331408Srandyf /* workaround for word swap error */ 8341408Srandyf if (addr & 4) 8351408Srandyf addr = addr - 4; 8361408Srandyf else 8371408Srandyf addr = addr + 4; 8381408Srandyf } 8391408Srandyf #endif 8401408Srandyf 8413918Sml149210 #ifdef __sparc 8423918Sml149210 data = bge_nic_read32(bgep, addr); 8433918Sml149210 #else 8441369Sdduvall bge_nic_setwin(bgep, addr & ~MWBAR_GRANULE_MASK); 8451369Sdduvall addr &= MWBAR_GRANULE_MASK; 8461369Sdduvall addr += NIC_MEM_WINDOW_OFFSET; 8471369Sdduvall 8481369Sdduvall data = ddi_get32(bgep->io_handle, PIO_ADDR(bgep, addr)); 8493918Sml149210 #endif 8501369Sdduvall 8511369Sdduvall BGE_TRACE(("bge_nic_get32($%p, 0x%lx) = 0x%08x", 8524588Sml149210 (void *)bgep, addr, data)); 8531369Sdduvall 8541369Sdduvall return (data); 8551369Sdduvall } 8561369Sdduvall 8571408Srandyf void bge_nic_put32(bge_t *bgep, bge_regno_t addr, uint32_t data); 8581408Srandyf #pragma inline(bge_nic_put32) 8591408Srandyf 8601408Srandyf void 8611369Sdduvall bge_nic_put32(bge_t *bgep, bge_regno_t addr, uint32_t data) 8621369Sdduvall { 8631369Sdduvall BGE_TRACE(("bge_nic_put32($%p, 0x%lx, 0x%08x)", 8644588Sml149210 (void *)bgep, addr, data)); 8651369Sdduvall 8663918Sml149210 #if defined(BGE_IPMI_ASF) && !defined(__sparc) 8671408Srandyf if (bgep->asf_enabled && !bgep->asf_wordswapped) { 8681408Srandyf /* workaround for word swap error */ 8691408Srandyf if (addr & 4) 8701408Srandyf addr = addr - 4; 8711408Srandyf else 8721408Srandyf addr = addr + 4; 8731408Srandyf } 8741408Srandyf #endif 8751408Srandyf 8763918Sml149210 #ifdef __sparc 8773918Sml149210 pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_MWBAR, addr); 8783918Sml149210 data = LE_32(data); 8793918Sml149210 pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_MWDAR, data); 8803918Sml149210 pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_MWBAR, 0); 8813918Sml149210 #else 8821369Sdduvall bge_nic_setwin(bgep, addr & ~MWBAR_GRANULE_MASK); 8831369Sdduvall addr &= MWBAR_GRANULE_MASK; 8841369Sdduvall addr += NIC_MEM_WINDOW_OFFSET; 8851369Sdduvall ddi_put32(bgep->io_handle, PIO_ADDR(bgep, addr), data); 8861369Sdduvall BGE_PCICHK(bgep); 8873918Sml149210 #endif 8881369Sdduvall } 8891369Sdduvall 8901369Sdduvall static uint64_t bge_nic_get64(bge_t *bgep, bge_regno_t addr); 8911369Sdduvall #pragma inline(bge_nic_get64) 8921369Sdduvall 8931369Sdduvall static uint64_t 8941369Sdduvall bge_nic_get64(bge_t *bgep, bge_regno_t addr) 8951369Sdduvall { 8961369Sdduvall uint64_t data; 8971369Sdduvall 8981369Sdduvall bge_nic_setwin(bgep, addr & ~MWBAR_GRANULE_MASK); 8991369Sdduvall addr &= MWBAR_GRANULE_MASK; 9001369Sdduvall addr += NIC_MEM_WINDOW_OFFSET; 9011369Sdduvall 9021369Sdduvall #ifdef __amd64 9039042SYong.Tan@Sun.COM if (DEVICE_5723_SERIES_CHIPSETS(bgep) || bge_get_em64t_type()) { 9049042SYong.Tan@Sun.COM data = ddi_get32(bgep->io_handle, PIO_ADDR(bgep, addr)); 9059042SYong.Tan@Sun.COM data <<= 32; 9069042SYong.Tan@Sun.COM data |= ddi_get32(bgep->io_handle, 9079042SYong.Tan@Sun.COM PIO_ADDR(bgep, addr + 4)); 9089042SYong.Tan@Sun.COM } else { 9099042SYong.Tan@Sun.COM data = ddi_get64(bgep->io_handle, PIO_ADDR(bgep, addr)); 9109042SYong.Tan@Sun.COM } 9119042SYong.Tan@Sun.COM #elif defined(__sparc) 9129042SYong.Tan@Sun.COM if (DEVICE_5723_SERIES_CHIPSETS(bgep)) { 9131369Sdduvall data = ddi_get32(bgep->io_handle, PIO_ADDR(bgep, addr)); 9141369Sdduvall data <<= 32; 9151369Sdduvall data |= ddi_get32(bgep->io_handle, 9164588Sml149210 PIO_ADDR(bgep, addr + 4)); 9171369Sdduvall } else { 9181369Sdduvall data = ddi_get64(bgep->io_handle, PIO_ADDR(bgep, addr)); 9191369Sdduvall } 9201369Sdduvall #else 9211369Sdduvall data = ddi_get64(bgep->io_handle, PIO_ADDR(bgep, addr)); 9221369Sdduvall #endif 9231369Sdduvall 9241369Sdduvall BGE_TRACE(("bge_nic_get64($%p, 0x%lx) = 0x%016llx", 9254588Sml149210 (void *)bgep, addr, data)); 9261369Sdduvall 9271369Sdduvall return (data); 9281369Sdduvall } 9291369Sdduvall 9301369Sdduvall static void bge_nic_put64(bge_t *bgep, bge_regno_t addr, uint64_t data); 9311369Sdduvall #pragma inline(bge_nic_put64) 9321369Sdduvall 9331369Sdduvall static void 9341369Sdduvall bge_nic_put64(bge_t *bgep, bge_regno_t addr, uint64_t data) 9351369Sdduvall { 9361369Sdduvall BGE_TRACE(("bge_nic_put64($%p, 0x%lx, 0x%016llx)", 9374588Sml149210 (void *)bgep, addr, data)); 9381369Sdduvall 9391369Sdduvall bge_nic_setwin(bgep, addr & ~MWBAR_GRANULE_MASK); 9401369Sdduvall addr &= MWBAR_GRANULE_MASK; 9411369Sdduvall addr += NIC_MEM_WINDOW_OFFSET; 9421369Sdduvall 9431369Sdduvall #ifdef __amd64 9449042SYong.Tan@Sun.COM if (DEVICE_5723_SERIES_CHIPSETS(bgep) || bge_get_em64t_type()) { 9451369Sdduvall ddi_put32(bgep->io_handle, 9464588Sml149210 PIO_ADDR(bgep, addr), (uint32_t)data); 9471369Sdduvall BGE_PCICHK(bgep); 9481369Sdduvall ddi_put32(bgep->io_handle, 9494588Sml149210 PIO_ADDR(bgep, addr + 4), (uint32_t)(data >> 32)); 9501369Sdduvall } else { 9511369Sdduvall ddi_put64(bgep->io_handle, PIO_ADDR(bgep, addr), data); 9521369Sdduvall } 9539042SYong.Tan@Sun.COM #elif defined(__sparc) 9549042SYong.Tan@Sun.COM if (DEVICE_5723_SERIES_CHIPSETS(bgep)) { 9559042SYong.Tan@Sun.COM ddi_put32(bgep->io_handle, 9569042SYong.Tan@Sun.COM PIO_ADDR(bgep, addr + 4), (uint32_t)data); 9579042SYong.Tan@Sun.COM BGE_PCICHK(bgep); 9589042SYong.Tan@Sun.COM ddi_put32(bgep->io_handle, 9599042SYong.Tan@Sun.COM PIO_ADDR(bgep, addr), (uint32_t)(data >> 32)); 9609042SYong.Tan@Sun.COM } else { 9619042SYong.Tan@Sun.COM ddi_put64(bgep->io_handle, PIO_ADDR(bgep, addr), data); 9629042SYong.Tan@Sun.COM } 9631369Sdduvall #else 9641369Sdduvall ddi_put64(bgep->io_handle, PIO_ADDR(bgep, addr), data); 9651369Sdduvall #endif 9661369Sdduvall 9671369Sdduvall BGE_PCICHK(bgep); 9681369Sdduvall } 9691369Sdduvall 9701369Sdduvall /* 9711369Sdduvall * The DDI doesn't provide get/put functions for 128 bit data 9721369Sdduvall * so we put RCBs out as two 64-bit chunks instead. 9731369Sdduvall */ 9741369Sdduvall static void bge_nic_putrcb(bge_t *bgep, bge_regno_t addr, bge_rcb_t *rcbp); 9751369Sdduvall #pragma inline(bge_nic_putrcb) 9761369Sdduvall 9771369Sdduvall static void 9781369Sdduvall bge_nic_putrcb(bge_t *bgep, bge_regno_t addr, bge_rcb_t *rcbp) 9791369Sdduvall { 9801369Sdduvall uint64_t *p; 9811369Sdduvall 9821369Sdduvall BGE_TRACE(("bge_nic_putrcb($%p, 0x%lx, 0x%016llx:%04x:%04x:%08x)", 9834588Sml149210 (void *)bgep, addr, rcbp->host_ring_addr, 9844588Sml149210 rcbp->max_len, rcbp->flags, rcbp->nic_ring_addr)); 9851369Sdduvall 9861369Sdduvall ASSERT((addr % sizeof (*rcbp)) == 0); 9871369Sdduvall 9881369Sdduvall bge_nic_setwin(bgep, addr & ~MWBAR_GRANULE_MASK); 9891369Sdduvall addr &= MWBAR_GRANULE_MASK; 9901369Sdduvall addr += NIC_MEM_WINDOW_OFFSET; 9911369Sdduvall 9921369Sdduvall p = (void *)rcbp; 9931369Sdduvall #ifdef __amd64 9949042SYong.Tan@Sun.COM if (DEVICE_5723_SERIES_CHIPSETS(bgep) || bge_get_em64t_type()) { 9951369Sdduvall ddi_put32(bgep->io_handle, PIO_ADDR(bgep, addr), 9964588Sml149210 (uint32_t)(*p)); 9971369Sdduvall ddi_put32(bgep->io_handle, PIO_ADDR(bgep, addr + 4), 9984588Sml149210 (uint32_t)(*p >> 32)); 9991369Sdduvall ddi_put32(bgep->io_handle, PIO_ADDR(bgep, addr + 8), 10004588Sml149210 (uint32_t)(*(p + 1))); 10011369Sdduvall ddi_put32(bgep->io_handle, PIO_ADDR(bgep, addr + 12), 10024588Sml149210 (uint32_t)(*p >> 32)); 10031369Sdduvall 10041369Sdduvall } else { 10051369Sdduvall ddi_put64(bgep->io_handle, PIO_ADDR(bgep, addr), *p++); 10061369Sdduvall ddi_put64(bgep->io_handle, PIO_ADDR(bgep, addr+8), *p); 10071369Sdduvall } 10089042SYong.Tan@Sun.COM #elif defined(__sparc) 10099042SYong.Tan@Sun.COM if (DEVICE_5723_SERIES_CHIPSETS(bgep)) { 10109042SYong.Tan@Sun.COM ddi_put32(bgep->io_handle, PIO_ADDR(bgep, addr + 4), 10119042SYong.Tan@Sun.COM (uint32_t)(*p)); 10129042SYong.Tan@Sun.COM ddi_put32(bgep->io_handle, PIO_ADDR(bgep, addr), 10139042SYong.Tan@Sun.COM (uint32_t)(*p >> 32)); 10149042SYong.Tan@Sun.COM ddi_put32(bgep->io_handle, PIO_ADDR(bgep, addr + 12), 10159042SYong.Tan@Sun.COM (uint32_t)(*(p + 1))); 10169042SYong.Tan@Sun.COM ddi_put32(bgep->io_handle, PIO_ADDR(bgep, addr + 8), 10179042SYong.Tan@Sun.COM (uint32_t)(*p >> 32)); 10189042SYong.Tan@Sun.COM } else { 10199042SYong.Tan@Sun.COM ddi_put64(bgep->io_handle, PIO_ADDR(bgep, addr), *p++); 10209042SYong.Tan@Sun.COM ddi_put64(bgep->io_handle, PIO_ADDR(bgep, addr + 8), *p); 10219042SYong.Tan@Sun.COM } 10221369Sdduvall #else 10231369Sdduvall ddi_put64(bgep->io_handle, PIO_ADDR(bgep, addr), *p++); 10241369Sdduvall ddi_put64(bgep->io_handle, PIO_ADDR(bgep, addr + 8), *p); 10251369Sdduvall #endif 10261369Sdduvall 10271369Sdduvall BGE_PCICHK(bgep); 10281369Sdduvall } 10291369Sdduvall 10301369Sdduvall static void bge_nic_zero(bge_t *bgep, bge_regno_t addr, uint32_t nbytes); 10311369Sdduvall #pragma inline(bge_nic_zero) 10321369Sdduvall 10331369Sdduvall static void 10341369Sdduvall bge_nic_zero(bge_t *bgep, bge_regno_t addr, uint32_t nbytes) 10351369Sdduvall { 10361369Sdduvall BGE_TRACE(("bge_nic_zero($%p, 0x%lx, 0x%x)", 10374588Sml149210 (void *)bgep, addr, nbytes)); 10381369Sdduvall 10391369Sdduvall ASSERT((addr & ~MWBAR_GRANULE_MASK) == 10404588Sml149210 ((addr+nbytes) & ~MWBAR_GRANULE_MASK)); 10411369Sdduvall 10421369Sdduvall bge_nic_setwin(bgep, addr & ~MWBAR_GRANULE_MASK); 10431369Sdduvall addr &= MWBAR_GRANULE_MASK; 10441369Sdduvall addr += NIC_MEM_WINDOW_OFFSET; 10451369Sdduvall 10461369Sdduvall (void) ddi_device_zero(bgep->io_handle, PIO_ADDR(bgep, addr), 10474588Sml149210 nbytes, 1, DDI_DATA_SZ08_ACC); 10481369Sdduvall BGE_PCICHK(bgep); 10491369Sdduvall } 10501369Sdduvall 10511369Sdduvall /* 10521369Sdduvall * MII (PHY) register get/set access routines 10531369Sdduvall * 10541369Sdduvall * These use the chip's MII auto-access method, controlled by the 10551369Sdduvall * MII Communication register at 0x044c, so the CPU doesn't have 10561369Sdduvall * to fiddle with the individual bits. 10571369Sdduvall */ 10581369Sdduvall 10591369Sdduvall #undef BGE_DBG 10601369Sdduvall #define BGE_DBG BGE_DBG_MII /* debug flag for this code */ 10611369Sdduvall 10621369Sdduvall static uint16_t bge_mii_access(bge_t *bgep, bge_regno_t regno, 10631369Sdduvall uint16_t data, uint32_t cmd); 10641369Sdduvall #pragma no_inline(bge_mii_access) 10651369Sdduvall 10661369Sdduvall static uint16_t 10671369Sdduvall bge_mii_access(bge_t *bgep, bge_regno_t regno, uint16_t data, uint32_t cmd) 10681369Sdduvall { 10691369Sdduvall uint32_t timeout; 10701369Sdduvall uint32_t regval1; 10711369Sdduvall uint32_t regval2; 10721369Sdduvall 10731369Sdduvall BGE_TRACE(("bge_mii_access($%p, 0x%lx, 0x%x, 0x%x)", 10744588Sml149210 (void *)bgep, regno, data, cmd)); 10751369Sdduvall 10761369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 10771369Sdduvall 10781369Sdduvall /* 10791369Sdduvall * Assemble the command ... 10801369Sdduvall */ 10811369Sdduvall cmd |= data << MI_COMMS_DATA_SHIFT; 10821369Sdduvall cmd |= regno << MI_COMMS_REGISTER_SHIFT; 10831369Sdduvall cmd |= bgep->phy_mii_addr << MI_COMMS_ADDRESS_SHIFT; 10841369Sdduvall cmd |= MI_COMMS_START; 10851369Sdduvall 10861369Sdduvall /* 10871369Sdduvall * Wait for any command already in progress ... 10881369Sdduvall * 10891369Sdduvall * Note: this *shouldn't* ever find that there is a command 10901369Sdduvall * in progress, because we already hold the <genlock> mutex. 10911369Sdduvall * Nonetheless, we have sometimes seen the MI_COMMS_START 10921369Sdduvall * bit set here -- it seems that the chip can initiate MII 10931369Sdduvall * accesses internally, even with polling OFF. 10941369Sdduvall */ 10951369Sdduvall regval1 = regval2 = bge_reg_get32(bgep, MI_COMMS_REG); 10961865Sdilpreet for (timeout = 100; ; ) { 10971369Sdduvall if ((regval2 & MI_COMMS_START) == 0) { 10981369Sdduvall bge_reg_put32(bgep, MI_COMMS_REG, cmd); 10991369Sdduvall break; 11001369Sdduvall } 11011369Sdduvall if (--timeout == 0) 11021369Sdduvall break; 11031369Sdduvall drv_usecwait(10); 11041369Sdduvall regval2 = bge_reg_get32(bgep, MI_COMMS_REG); 11051369Sdduvall } 11061369Sdduvall 11071865Sdilpreet if (timeout == 0) 11081865Sdilpreet return ((uint16_t)~0u); 11091865Sdilpreet 11101865Sdilpreet if (timeout != 100) 11111369Sdduvall BGE_REPORT((bgep, "bge_mii_access: cmd 0x%x -- " 11124588Sml149210 "MI_COMMS_START set for %d us; 0x%x->0x%x", 11134588Sml149210 cmd, 10*(100-timeout), regval1, regval2)); 11141369Sdduvall 11151369Sdduvall regval1 = bge_reg_get32(bgep, MI_COMMS_REG); 11161369Sdduvall for (timeout = 1000; ; ) { 11171369Sdduvall if ((regval1 & MI_COMMS_START) == 0) 11181369Sdduvall break; 11191369Sdduvall if (--timeout == 0) 11201369Sdduvall break; 11211369Sdduvall drv_usecwait(10); 11221369Sdduvall regval1 = bge_reg_get32(bgep, MI_COMMS_REG); 11231369Sdduvall } 11241369Sdduvall 11251369Sdduvall /* 11261369Sdduvall * Drop out early if the READ FAILED bit is set -- this chip 11271369Sdduvall * could be a 5703/4S, with a SerDes instead of a PHY! 11281369Sdduvall */ 11291369Sdduvall if (regval2 & MI_COMMS_READ_FAILED) 11301369Sdduvall return ((uint16_t)~0u); 11311369Sdduvall 11321369Sdduvall if (timeout == 0) 11331369Sdduvall return ((uint16_t)~0u); 11341369Sdduvall 11351369Sdduvall /* 11361369Sdduvall * The PRM says to wait 5us after seeing the START bit clear 11371369Sdduvall * and then re-read the register to get the final value of the 11381369Sdduvall * data field, in order to avoid a race condition where the 11391369Sdduvall * START bit is clear but the data field isn't yet valid. 11401369Sdduvall * 11411369Sdduvall * Note: we don't actually seem to be encounter this race; 11421369Sdduvall * except when the START bit is seen set again (see below), 11431369Sdduvall * the data field doesn't change during this 5us interval. 11441369Sdduvall */ 11451369Sdduvall drv_usecwait(5); 11461369Sdduvall regval2 = bge_reg_get32(bgep, MI_COMMS_REG); 11471369Sdduvall 11481369Sdduvall /* 11491369Sdduvall * Unfortunately, when following the PRMs instructions above, 11501369Sdduvall * we have occasionally seen the START bit set again(!) in the 11511369Sdduvall * value read after the 5us delay. This seems to be due to the 11521369Sdduvall * chip autonomously starting another MII access internally. 11531369Sdduvall * In such cases, the command/data/etc fields relate to the 11541369Sdduvall * internal command, rather than the one that we thought had 11551369Sdduvall * just finished. So in this case, we fall back to returning 11561369Sdduvall * the data from the original read that showed START clear. 11571369Sdduvall */ 11581369Sdduvall if (regval2 & MI_COMMS_START) { 11591369Sdduvall BGE_REPORT((bgep, "bge_mii_access: cmd 0x%x -- " 11604588Sml149210 "MI_COMMS_START set after transaction; 0x%x->0x%x", 11614588Sml149210 cmd, regval1, regval2)); 11621369Sdduvall regval2 = regval1; 11631369Sdduvall } 11641369Sdduvall 11651369Sdduvall if (regval2 & MI_COMMS_START) 11661369Sdduvall return ((uint16_t)~0u); 11671369Sdduvall 11681369Sdduvall if (regval2 & MI_COMMS_READ_FAILED) 11691369Sdduvall return ((uint16_t)~0u); 11701369Sdduvall 11711369Sdduvall return ((regval2 & MI_COMMS_DATA_MASK) >> MI_COMMS_DATA_SHIFT); 11721369Sdduvall } 11731369Sdduvall 11741369Sdduvall uint16_t bge_mii_get16(bge_t *bgep, bge_regno_t regno); 11751369Sdduvall #pragma no_inline(bge_mii_get16) 11761369Sdduvall 11771369Sdduvall uint16_t 11781369Sdduvall bge_mii_get16(bge_t *bgep, bge_regno_t regno) 11791369Sdduvall { 11801369Sdduvall BGE_TRACE(("bge_mii_get16($%p, 0x%lx)", 11814588Sml149210 (void *)bgep, regno)); 11821369Sdduvall 11831369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 11841369Sdduvall 11857678SYong.Tan@Sun.COM if (DEVICE_5906_SERIES_CHIPSETS(bgep) && ((regno == MII_AUX_CONTROL) || 11869860Sgdamore@opensolaris.org (regno == MII_MSCONTROL))) 11877678SYong.Tan@Sun.COM return (0); 11887678SYong.Tan@Sun.COM 11891369Sdduvall return (bge_mii_access(bgep, regno, 0, MI_COMMS_COMMAND_READ)); 11901369Sdduvall } 11911369Sdduvall 11921369Sdduvall void bge_mii_put16(bge_t *bgep, bge_regno_t regno, uint16_t data); 11931369Sdduvall #pragma no_inline(bge_mii_put16) 11941369Sdduvall 11951369Sdduvall void 11961369Sdduvall bge_mii_put16(bge_t *bgep, bge_regno_t regno, uint16_t data) 11971369Sdduvall { 11981369Sdduvall BGE_TRACE(("bge_mii_put16($%p, 0x%lx, 0x%x)", 11994588Sml149210 (void *)bgep, regno, data)); 12001369Sdduvall 12011369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 12021369Sdduvall 12037678SYong.Tan@Sun.COM if (DEVICE_5906_SERIES_CHIPSETS(bgep) && ((regno == MII_AUX_CONTROL) || 12049860Sgdamore@opensolaris.org (regno == MII_MSCONTROL))) 12057678SYong.Tan@Sun.COM return; 12067678SYong.Tan@Sun.COM 12071369Sdduvall (void) bge_mii_access(bgep, regno, data, MI_COMMS_COMMAND_WRITE); 12081369Sdduvall } 12091369Sdduvall 12101369Sdduvall #undef BGE_DBG 12111369Sdduvall #define BGE_DBG BGE_DBG_SEEPROM /* debug flag for this code */ 12121369Sdduvall 12131369Sdduvall #if BGE_SEE_IO32 || BGE_FLASH_IO32 12141369Sdduvall 12151369Sdduvall /* 12161369Sdduvall * Basic SEEPROM get/set access routine 12171369Sdduvall * 12181369Sdduvall * This uses the chip's SEEPROM auto-access method, controlled by the 12191369Sdduvall * Serial EEPROM Address/Data Registers at 0x6838/683c, so the CPU 12201369Sdduvall * doesn't have to fiddle with the individual bits. 12211369Sdduvall * 12221369Sdduvall * The caller should hold <genlock> and *also* have already acquired 12231369Sdduvall * the right to access the SEEPROM, via bge_nvmem_acquire() above. 12241369Sdduvall * 12251369Sdduvall * Return value: 12261369Sdduvall * 0 on success, 12271369Sdduvall * ENODATA on access timeout (maybe retryable: device may just be busy) 12281369Sdduvall * EPROTO on other h/w or s/w errors. 12291369Sdduvall * 12301369Sdduvall * <*dp> is an input to a SEEPROM_ACCESS_WRITE operation, or an output 12311369Sdduvall * from a (successful) SEEPROM_ACCESS_READ. 12321369Sdduvall */ 12331369Sdduvall static int bge_seeprom_access(bge_t *bgep, uint32_t cmd, bge_regno_t addr, 12341369Sdduvall uint32_t *dp); 12351369Sdduvall #pragma no_inline(bge_seeprom_access) 12361369Sdduvall 12371369Sdduvall static int 12381369Sdduvall bge_seeprom_access(bge_t *bgep, uint32_t cmd, bge_regno_t addr, uint32_t *dp) 12391369Sdduvall { 12401369Sdduvall uint32_t tries; 12411369Sdduvall uint32_t regval; 12421369Sdduvall 12431369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 12441369Sdduvall 12451369Sdduvall /* 12461369Sdduvall * On the newer chips that support both SEEPROM & Flash, we need 12471369Sdduvall * to specifically enable SEEPROM access (Flash is the default). 12481369Sdduvall * On older chips, we don't; SEEPROM is the only NVtype supported, 12491369Sdduvall * and the NVM control registers don't exist ... 12501369Sdduvall */ 12511369Sdduvall switch (bgep->chipid.nvtype) { 12521369Sdduvall case BGE_NVTYPE_NONE: 12531369Sdduvall case BGE_NVTYPE_UNKNOWN: 12541369Sdduvall _NOTE(NOTREACHED) 12551369Sdduvall case BGE_NVTYPE_SEEPROM: 12561369Sdduvall break; 12571369Sdduvall 12581369Sdduvall case BGE_NVTYPE_LEGACY_SEEPROM: 12591369Sdduvall case BGE_NVTYPE_UNBUFFERED_FLASH: 12601369Sdduvall case BGE_NVTYPE_BUFFERED_FLASH: 12611369Sdduvall default: 12621369Sdduvall bge_reg_set32(bgep, NVM_CONFIG1_REG, 12634588Sml149210 NVM_CFG1_LEGACY_SEEPROM_MODE); 12641369Sdduvall break; 12651369Sdduvall } 12661369Sdduvall 12671369Sdduvall /* 12681369Sdduvall * Check there's no command in progress. 12691369Sdduvall * 12701369Sdduvall * Note: this *shouldn't* ever find that there is a command 12711369Sdduvall * in progress, because we already hold the <genlock> mutex. 12721369Sdduvall * Also, to ensure we don't have a conflict with the chip's 12731369Sdduvall * internal firmware or a process accessing the same (shared) 12741369Sdduvall * SEEPROM through the other port of a 5704, we've already 12751369Sdduvall * been through the "software arbitration" protocol. 12761369Sdduvall * So this is just a final consistency check: we shouldn't 12771369Sdduvall * see EITHER the START bit (command started but not complete) 12781369Sdduvall * OR the COMPLETE bit (command completed but not cleared). 12791369Sdduvall */ 12801369Sdduvall regval = bge_reg_get32(bgep, SERIAL_EEPROM_ADDRESS_REG); 12811369Sdduvall if (regval & SEEPROM_ACCESS_START) 12821369Sdduvall return (EPROTO); 12831369Sdduvall if (regval & SEEPROM_ACCESS_COMPLETE) 12841369Sdduvall return (EPROTO); 12851369Sdduvall 12861369Sdduvall /* 12871369Sdduvall * Assemble the command ... 12881369Sdduvall */ 12891369Sdduvall cmd |= addr & SEEPROM_ACCESS_ADDRESS_MASK; 12901369Sdduvall addr >>= SEEPROM_ACCESS_ADDRESS_SIZE; 12911369Sdduvall addr <<= SEEPROM_ACCESS_DEVID_SHIFT; 12921369Sdduvall cmd |= addr & SEEPROM_ACCESS_DEVID_MASK; 12931369Sdduvall cmd |= SEEPROM_ACCESS_START; 12941369Sdduvall cmd |= SEEPROM_ACCESS_COMPLETE; 12951369Sdduvall cmd |= regval & SEEPROM_ACCESS_HALFCLOCK_MASK; 12961369Sdduvall 12971369Sdduvall bge_reg_put32(bgep, SERIAL_EEPROM_DATA_REG, *dp); 12981369Sdduvall bge_reg_put32(bgep, SERIAL_EEPROM_ADDRESS_REG, cmd); 12991369Sdduvall 13001369Sdduvall /* 13011369Sdduvall * By observation, a successful access takes ~20us on a 5703/4, 13021369Sdduvall * but apparently much longer (up to 1000us) on the obsolescent 13031369Sdduvall * BCM5700/BCM5701. We want to be sure we don't get any false 13041369Sdduvall * timeouts here; but OTOH, we don't want a bogus access to lock 13051369Sdduvall * out interrupts for longer than necessary. So we'll allow up 13061369Sdduvall * to 1000us ... 13071369Sdduvall */ 13081369Sdduvall for (tries = 0; tries < 1000; ++tries) { 13091369Sdduvall regval = bge_reg_get32(bgep, SERIAL_EEPROM_ADDRESS_REG); 13101369Sdduvall if (regval & SEEPROM_ACCESS_COMPLETE) 13111369Sdduvall break; 13121369Sdduvall drv_usecwait(1); 13131369Sdduvall } 13141369Sdduvall 13151369Sdduvall if (regval & SEEPROM_ACCESS_COMPLETE) { 13161369Sdduvall /* 13171369Sdduvall * All OK; read the SEEPROM data register, then write back 13181369Sdduvall * the value read from the address register in order to 13191369Sdduvall * clear the <complete> bit and leave the SEEPROM access 13201369Sdduvall * state machine idle, ready for the next access ... 13211369Sdduvall */ 13221369Sdduvall BGE_DEBUG(("bge_seeprom_access: complete after %d us", tries)); 13231369Sdduvall *dp = bge_reg_get32(bgep, SERIAL_EEPROM_DATA_REG); 13241369Sdduvall bge_reg_put32(bgep, SERIAL_EEPROM_ADDRESS_REG, regval); 13251369Sdduvall return (0); 13261369Sdduvall } 13271369Sdduvall 13281369Sdduvall /* 13291369Sdduvall * Hmm ... what happened here? 13301369Sdduvall * 13312135Szh199473 * Most likely, the user addressed a non-existent SEEPROM. Or 13321369Sdduvall * maybe the SEEPROM was busy internally (e.g. processing a write) 13331369Sdduvall * and didn't respond to being addressed. Either way, it's left 13341369Sdduvall * the SEEPROM access state machine wedged. So we'll reset it 13351369Sdduvall * before we leave, so it's ready for next time ... 13361369Sdduvall */ 13371369Sdduvall BGE_DEBUG(("bge_seeprom_access: timed out after %d us", tries)); 13381369Sdduvall bge_reg_set32(bgep, SERIAL_EEPROM_ADDRESS_REG, SEEPROM_ACCESS_INIT); 13391369Sdduvall return (ENODATA); 13401369Sdduvall } 13411369Sdduvall 13421369Sdduvall /* 13431369Sdduvall * Basic Flash get/set access routine 13441369Sdduvall * 13451369Sdduvall * These use the chip's Flash auto-access method, controlled by the 13461369Sdduvall * Flash Access Registers at 0x7000-701c, so the CPU doesn't have to 13471369Sdduvall * fiddle with the individual bits. 13481369Sdduvall * 13491369Sdduvall * The caller should hold <genlock> and *also* have already acquired 13501369Sdduvall * the right to access the Flash, via bge_nvmem_acquire() above. 13511369Sdduvall * 13521369Sdduvall * Return value: 13531369Sdduvall * 0 on success, 13541369Sdduvall * ENODATA on access timeout (maybe retryable: device may just be busy) 13551369Sdduvall * ENODEV if the NVmem device is missing or otherwise unusable 13561369Sdduvall * 13571369Sdduvall * <*dp> is an input to a NVM_FLASH_CMD_WR operation, or an output 13581369Sdduvall * from a (successful) NVM_FLASH_CMD_RD. 13591369Sdduvall */ 13601369Sdduvall static int bge_flash_access(bge_t *bgep, uint32_t cmd, bge_regno_t addr, 13611369Sdduvall uint32_t *dp); 13621369Sdduvall #pragma no_inline(bge_flash_access) 13631369Sdduvall 13641369Sdduvall static int 13651369Sdduvall bge_flash_access(bge_t *bgep, uint32_t cmd, bge_regno_t addr, uint32_t *dp) 13661369Sdduvall { 13671369Sdduvall uint32_t tries; 13681369Sdduvall uint32_t regval; 13691369Sdduvall 13701369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 13711369Sdduvall 13721369Sdduvall /* 13731369Sdduvall * On the newer chips that support both SEEPROM & Flash, we need 13741369Sdduvall * to specifically disable SEEPROM access while accessing Flash. 13751369Sdduvall * The older chips don't support Flash, and the NVM registers don't 13761369Sdduvall * exist, so we shouldn't be here at all! 13771369Sdduvall */ 13781369Sdduvall switch (bgep->chipid.nvtype) { 13791369Sdduvall case BGE_NVTYPE_NONE: 13801369Sdduvall case BGE_NVTYPE_UNKNOWN: 13811369Sdduvall _NOTE(NOTREACHED) 13821369Sdduvall case BGE_NVTYPE_SEEPROM: 13831369Sdduvall return (ENODEV); 13841369Sdduvall 13851369Sdduvall case BGE_NVTYPE_LEGACY_SEEPROM: 13861369Sdduvall case BGE_NVTYPE_UNBUFFERED_FLASH: 13871369Sdduvall case BGE_NVTYPE_BUFFERED_FLASH: 13881369Sdduvall default: 13891369Sdduvall bge_reg_clr32(bgep, NVM_CONFIG1_REG, 13904588Sml149210 NVM_CFG1_LEGACY_SEEPROM_MODE); 13911369Sdduvall break; 13921369Sdduvall } 13931369Sdduvall 13941369Sdduvall /* 13951369Sdduvall * Assemble the command ... 13961369Sdduvall */ 13971369Sdduvall addr &= NVM_FLASH_ADDR_MASK; 13981369Sdduvall cmd |= NVM_FLASH_CMD_DOIT; 13991369Sdduvall cmd |= NVM_FLASH_CMD_FIRST; 14001369Sdduvall cmd |= NVM_FLASH_CMD_LAST; 14011369Sdduvall cmd |= NVM_FLASH_CMD_DONE; 14021369Sdduvall 14031369Sdduvall bge_reg_put32(bgep, NVM_FLASH_WRITE_REG, *dp); 14041369Sdduvall bge_reg_put32(bgep, NVM_FLASH_ADDR_REG, addr); 14051369Sdduvall bge_reg_put32(bgep, NVM_FLASH_CMD_REG, cmd); 14061369Sdduvall 14071369Sdduvall /* 14081369Sdduvall * Allow up to 1000ms ... 14091369Sdduvall */ 14101369Sdduvall for (tries = 0; tries < 1000; ++tries) { 14111369Sdduvall regval = bge_reg_get32(bgep, NVM_FLASH_CMD_REG); 14121369Sdduvall if (regval & NVM_FLASH_CMD_DONE) 14131369Sdduvall break; 14141369Sdduvall drv_usecwait(1); 14151369Sdduvall } 14161369Sdduvall 14171369Sdduvall if (regval & NVM_FLASH_CMD_DONE) { 14181369Sdduvall /* 14191369Sdduvall * All OK; read the data from the Flash read register 14201369Sdduvall */ 14211369Sdduvall BGE_DEBUG(("bge_flash_access: complete after %d us", tries)); 14221369Sdduvall *dp = bge_reg_get32(bgep, NVM_FLASH_READ_REG); 14231369Sdduvall return (0); 14241369Sdduvall } 14251369Sdduvall 14261369Sdduvall /* 14271369Sdduvall * Hmm ... what happened here? 14281369Sdduvall * 14292135Szh199473 * Most likely, the user addressed a non-existent Flash. Or 14301369Sdduvall * maybe the Flash was busy internally (e.g. processing a write) 14311369Sdduvall * and didn't respond to being addressed. Either way, there's 14321369Sdduvall * nothing we can here ... 14331369Sdduvall */ 14341369Sdduvall BGE_DEBUG(("bge_flash_access: timed out after %d us", tries)); 14351369Sdduvall return (ENODATA); 14361369Sdduvall } 14371369Sdduvall 14381369Sdduvall /* 14391369Sdduvall * The next two functions regulate access to the NVram (if fitted). 14401369Sdduvall * 14411369Sdduvall * On a 5704 (dual core) chip, there's only one SEEPROM and one Flash 14421369Sdduvall * (SPI) interface, but they can be accessed through either port. These 14431369Sdduvall * are managed by different instance of this driver and have no software 14441369Sdduvall * state in common. 14451369Sdduvall * 14461369Sdduvall * In addition (and even on a single core chip) the chip's internal 14471369Sdduvall * firmware can access the SEEPROM/Flash, most notably after a RESET 14481369Sdduvall * when it may download code to run internally. 14491369Sdduvall * 14501369Sdduvall * So we need to arbitrate between these various software agents. For 14511369Sdduvall * this purpose, the chip provides the Software Arbitration Register, 14521369Sdduvall * which implements hardware(!) arbitration. 14531369Sdduvall * 14541369Sdduvall * This functionality didn't exist on older (5700/5701) chips, so there's 14551369Sdduvall * nothing we can do by way of arbitration on those; also, if there's no 14561369Sdduvall * SEEPROM/Flash fitted (or we couldn't determine what type), there's also 14571369Sdduvall * nothing to do. 14581369Sdduvall * 14591369Sdduvall * The internal firmware appears to use Request 0, which is the highest 14601369Sdduvall * priority. So we'd like to use Request 2, leaving one higher and one 14611369Sdduvall * lower for any future developments ... but apparently this doesn't 14621369Sdduvall * always work. So for now, the code uses Request 1 ;-( 14631369Sdduvall */ 14641369Sdduvall 14651369Sdduvall #define NVM_READ_REQ NVM_READ_REQ1 14661369Sdduvall #define NVM_RESET_REQ NVM_RESET_REQ1 14671369Sdduvall #define NVM_SET_REQ NVM_SET_REQ1 14681369Sdduvall 14691369Sdduvall static void bge_nvmem_relinquish(bge_t *bgep); 14701369Sdduvall #pragma no_inline(bge_nvmem_relinquish) 14711369Sdduvall 14721369Sdduvall static void 14731369Sdduvall bge_nvmem_relinquish(bge_t *bgep) 14741369Sdduvall { 14751369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 14761369Sdduvall 14771369Sdduvall switch (bgep->chipid.nvtype) { 14781369Sdduvall case BGE_NVTYPE_NONE: 14791369Sdduvall case BGE_NVTYPE_UNKNOWN: 14801369Sdduvall _NOTE(NOTREACHED) 14811369Sdduvall return; 14821369Sdduvall 14831369Sdduvall case BGE_NVTYPE_SEEPROM: 14841369Sdduvall /* 14851369Sdduvall * No arbitration performed, no release needed 14861369Sdduvall */ 14871369Sdduvall return; 14881369Sdduvall 14891369Sdduvall case BGE_NVTYPE_LEGACY_SEEPROM: 14901369Sdduvall case BGE_NVTYPE_UNBUFFERED_FLASH: 14911369Sdduvall case BGE_NVTYPE_BUFFERED_FLASH: 14921369Sdduvall default: 14931369Sdduvall break; 14941369Sdduvall } 14951369Sdduvall 14961369Sdduvall /* 14971369Sdduvall * Our own request should be present (whether or not granted) ... 14981369Sdduvall */ 14991865Sdilpreet (void) bge_reg_get32(bgep, NVM_SW_ARBITRATION_REG); 15001369Sdduvall 15011369Sdduvall /* 15021369Sdduvall * ... this will make it go away. 15031369Sdduvall */ 15041369Sdduvall bge_reg_put32(bgep, NVM_SW_ARBITRATION_REG, NVM_RESET_REQ); 15051865Sdilpreet (void) bge_reg_get32(bgep, NVM_SW_ARBITRATION_REG); 15061369Sdduvall } 15071369Sdduvall 15081369Sdduvall /* 15091369Sdduvall * Arbitrate for access to the NVmem, if necessary 15101369Sdduvall * 15111369Sdduvall * Return value: 15121369Sdduvall * 0 on success 15131369Sdduvall * EAGAIN if the device is in use (retryable) 15141369Sdduvall * ENODEV if the NVmem device is missing or otherwise unusable 15151369Sdduvall */ 15161369Sdduvall static int bge_nvmem_acquire(bge_t *bgep); 15171369Sdduvall #pragma no_inline(bge_nvmem_acquire) 15181369Sdduvall 15191369Sdduvall static int 15201369Sdduvall bge_nvmem_acquire(bge_t *bgep) 15211369Sdduvall { 15221369Sdduvall uint32_t regval; 15231369Sdduvall uint32_t tries; 15241369Sdduvall 15251369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 15261369Sdduvall 15271369Sdduvall switch (bgep->chipid.nvtype) { 15281369Sdduvall case BGE_NVTYPE_NONE: 15291369Sdduvall case BGE_NVTYPE_UNKNOWN: 15301369Sdduvall /* 15311369Sdduvall * Access denied: no (recognisable) device fitted 15321369Sdduvall */ 15331369Sdduvall return (ENODEV); 15341369Sdduvall 15351369Sdduvall case BGE_NVTYPE_SEEPROM: 15361369Sdduvall /* 15371369Sdduvall * Access granted: no arbitration needed (or possible) 15381369Sdduvall */ 15391369Sdduvall return (0); 15401369Sdduvall 15411369Sdduvall case BGE_NVTYPE_LEGACY_SEEPROM: 15421369Sdduvall case BGE_NVTYPE_UNBUFFERED_FLASH: 15431369Sdduvall case BGE_NVTYPE_BUFFERED_FLASH: 15441369Sdduvall default: 15451369Sdduvall /* 15461369Sdduvall * Access conditional: conduct arbitration protocol 15471369Sdduvall */ 15481369Sdduvall break; 15491369Sdduvall } 15501369Sdduvall 15511369Sdduvall /* 15521369Sdduvall * We're holding the per-port mutex <genlock>, so no-one other 15532135Szh199473 * thread can be attempting to access the NVmem through *this* 15541369Sdduvall * port. But it could be in use by the *other* port (of a 5704), 15551369Sdduvall * or by the chip's internal firmware, so we have to go through 15561369Sdduvall * the full (hardware) arbitration protocol ... 15571369Sdduvall * 15581369Sdduvall * Note that *because* we're holding <genlock>, the interrupt handler 15591369Sdduvall * won't be able to progress. So we're only willing to spin for a 15601369Sdduvall * fairly short time. Specifically: 15611369Sdduvall * 15621369Sdduvall * We *must* wait long enough for the hardware to resolve all 15631369Sdduvall * requests and determine the winner. Fortunately, this is 15641369Sdduvall * "almost instantaneous", even as observed by GHz CPUs. 15651369Sdduvall * 15661369Sdduvall * A successful access by another Solaris thread (via either 15671369Sdduvall * port) typically takes ~20us. So waiting a bit longer than 15681369Sdduvall * that will give a good chance of success, if the other user 15691369Sdduvall * *is* another thread on the other port. 15701369Sdduvall * 15711369Sdduvall * However, the internal firmware can hold on to the NVmem 15721369Sdduvall * for *much* longer: at least 10 milliseconds just after a 15731369Sdduvall * RESET, and maybe even longer if the NVmem actually contains 15741369Sdduvall * code to download and run on the internal CPUs. 15751369Sdduvall * 15761369Sdduvall * So, we'll allow 50us; if that's not enough then it's up to the 15771369Sdduvall * caller to retry later (hence the choice of return code EAGAIN). 15781369Sdduvall */ 15791369Sdduvall regval = bge_reg_get32(bgep, NVM_SW_ARBITRATION_REG); 15801369Sdduvall bge_reg_put32(bgep, NVM_SW_ARBITRATION_REG, NVM_SET_REQ); 15811369Sdduvall 15821369Sdduvall for (tries = 0; tries < 50; ++tries) { 15831369Sdduvall regval = bge_reg_get32(bgep, NVM_SW_ARBITRATION_REG); 15841369Sdduvall if (regval & NVM_WON_REQ1) 15851369Sdduvall break; 15861369Sdduvall drv_usecwait(1); 15871369Sdduvall } 15881369Sdduvall 15891369Sdduvall if (regval & NVM_WON_REQ1) { 15901369Sdduvall BGE_DEBUG(("bge_nvmem_acquire: won after %d us", tries)); 15911369Sdduvall return (0); 15921369Sdduvall } 15931369Sdduvall 15941369Sdduvall /* 15951369Sdduvall * Somebody else must be accessing the NVmem, so abandon our 15961369Sdduvall * attempt take control of it. The caller can try again later ... 15971369Sdduvall */ 15981369Sdduvall BGE_DEBUG(("bge_nvmem_acquire: lost after %d us", tries)); 15991369Sdduvall bge_nvmem_relinquish(bgep); 16001369Sdduvall return (EAGAIN); 16011369Sdduvall } 16021369Sdduvall 16031369Sdduvall /* 16041369Sdduvall * This code assumes that the GPIO1 bit has been wired up to the NVmem 16051369Sdduvall * write protect line in such a way that the NVmem is protected when 16061369Sdduvall * GPIO1 is an input, or is an output but driven high. Thus, to make the 16071369Sdduvall * NVmem writable we have to change GPIO1 to an output AND drive it low. 16081369Sdduvall * 16091369Sdduvall * Note: there's only one set of GPIO pins on a 5704, even though they 16101369Sdduvall * can be accessed through either port. So the chip has to resolve what 16111369Sdduvall * happens if the two ports program a single pin differently ... the rule 16121369Sdduvall * it uses is that if the ports disagree about the *direction* of a pin, 16131369Sdduvall * "output" wins over "input", but if they disagree about its *value* as 16141369Sdduvall * an output, then the pin is TRISTATED instead! In such a case, no-one 16151369Sdduvall * wins, and the external signal does whatever the external circuitry 16161369Sdduvall * defines as the default -- which we've assumed is the PROTECTED state. 16171369Sdduvall * So, we always change GPIO1 back to being an *input* whenever we're not 16181369Sdduvall * specifically using it to unprotect the NVmem. This allows either port 16192135Szh199473 * to update the NVmem, although obviously only one at a time! 16201369Sdduvall * 16211369Sdduvall * The caller should hold <genlock> and *also* have already acquired the 16221369Sdduvall * right to access the NVmem, via bge_nvmem_acquire() above. 16231369Sdduvall */ 16241369Sdduvall static void bge_nvmem_protect(bge_t *bgep, boolean_t protect); 16251369Sdduvall #pragma inline(bge_nvmem_protect) 16261369Sdduvall 16271369Sdduvall static void 16281369Sdduvall bge_nvmem_protect(bge_t *bgep, boolean_t protect) 16291369Sdduvall { 16301369Sdduvall uint32_t regval; 16311369Sdduvall 16321369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 16331369Sdduvall 16341369Sdduvall regval = bge_reg_get32(bgep, MISC_LOCAL_CONTROL_REG); 16351369Sdduvall if (protect) { 16361369Sdduvall regval |= MLCR_MISC_PINS_OUTPUT_1; 16371369Sdduvall regval &= ~MLCR_MISC_PINS_OUTPUT_ENABLE_1; 16381369Sdduvall } else { 16391369Sdduvall regval &= ~MLCR_MISC_PINS_OUTPUT_1; 16401369Sdduvall regval |= MLCR_MISC_PINS_OUTPUT_ENABLE_1; 16411369Sdduvall } 16421369Sdduvall bge_reg_put32(bgep, MISC_LOCAL_CONTROL_REG, regval); 16431369Sdduvall } 16441369Sdduvall 16451369Sdduvall /* 16461369Sdduvall * Now put it all together ... 16471369Sdduvall * 16481369Sdduvall * Try to acquire control of the NVmem; if successful, then: 16491369Sdduvall * unprotect it (if we want to write to it) 16501369Sdduvall * perform the requested access 16511369Sdduvall * reprotect it (after a write) 16521369Sdduvall * relinquish control 16531369Sdduvall * 16541369Sdduvall * Return value: 16551369Sdduvall * 0 on success, 16561369Sdduvall * EAGAIN if the device is in use (retryable) 16571369Sdduvall * ENODATA on access timeout (maybe retryable: device may just be busy) 16581369Sdduvall * ENODEV if the NVmem device is missing or otherwise unusable 16591369Sdduvall * EPROTO on other h/w or s/w errors. 16601369Sdduvall */ 16611369Sdduvall static int 16621369Sdduvall bge_nvmem_rw32(bge_t *bgep, uint32_t cmd, bge_regno_t addr, uint32_t *dp) 16631369Sdduvall { 16641369Sdduvall int err; 16651369Sdduvall 16661369Sdduvall if ((err = bge_nvmem_acquire(bgep)) == 0) { 16671369Sdduvall switch (cmd) { 16681369Sdduvall case BGE_SEE_READ: 16691369Sdduvall err = bge_seeprom_access(bgep, 16701369Sdduvall SEEPROM_ACCESS_READ, addr, dp); 16711369Sdduvall break; 16721369Sdduvall 16731369Sdduvall case BGE_SEE_WRITE: 16741369Sdduvall bge_nvmem_protect(bgep, B_FALSE); 16751369Sdduvall err = bge_seeprom_access(bgep, 16761369Sdduvall SEEPROM_ACCESS_WRITE, addr, dp); 16771369Sdduvall bge_nvmem_protect(bgep, B_TRUE); 16781369Sdduvall break; 16791369Sdduvall 16801369Sdduvall case BGE_FLASH_READ: 16811369Sdduvall if (DEVICE_5721_SERIES_CHIPSETS(bgep) || 16829042SYong.Tan@Sun.COM DEVICE_5723_SERIES_CHIPSETS(bgep) || 16831369Sdduvall DEVICE_5714_SERIES_CHIPSETS(bgep)) { 16841369Sdduvall bge_reg_set32(bgep, NVM_ACCESS_REG, 16851369Sdduvall NVM_ACCESS_ENABLE); 16861369Sdduvall } 16871369Sdduvall err = bge_flash_access(bgep, 16881369Sdduvall NVM_FLASH_CMD_RD, addr, dp); 16891369Sdduvall if (DEVICE_5721_SERIES_CHIPSETS(bgep) || 16909042SYong.Tan@Sun.COM DEVICE_5723_SERIES_CHIPSETS(bgep) || 16911369Sdduvall DEVICE_5714_SERIES_CHIPSETS(bgep)) { 16921369Sdduvall bge_reg_clr32(bgep, NVM_ACCESS_REG, 16931369Sdduvall NVM_ACCESS_ENABLE); 16941369Sdduvall } 16951369Sdduvall break; 16961369Sdduvall 16971369Sdduvall case BGE_FLASH_WRITE: 16981369Sdduvall if (DEVICE_5721_SERIES_CHIPSETS(bgep) || 16999042SYong.Tan@Sun.COM DEVICE_5723_SERIES_CHIPSETS(bgep) || 17001369Sdduvall DEVICE_5714_SERIES_CHIPSETS(bgep)) { 17011369Sdduvall bge_reg_set32(bgep, NVM_ACCESS_REG, 17021369Sdduvall NVM_WRITE_ENABLE|NVM_ACCESS_ENABLE); 17031369Sdduvall } 17041369Sdduvall bge_nvmem_protect(bgep, B_FALSE); 17051369Sdduvall err = bge_flash_access(bgep, 17061369Sdduvall NVM_FLASH_CMD_WR, addr, dp); 17071369Sdduvall bge_nvmem_protect(bgep, B_TRUE); 17081369Sdduvall if (DEVICE_5721_SERIES_CHIPSETS(bgep) || 17099042SYong.Tan@Sun.COM DEVICE_5723_SERIES_CHIPSETS(bgep) || 17101369Sdduvall DEVICE_5714_SERIES_CHIPSETS(bgep)) { 17111369Sdduvall bge_reg_clr32(bgep, NVM_ACCESS_REG, 17121369Sdduvall NVM_WRITE_ENABLE|NVM_ACCESS_ENABLE); 17131369Sdduvall } 17141369Sdduvall 17151369Sdduvall break; 17161369Sdduvall 17171369Sdduvall default: 17181369Sdduvall _NOTE(NOTREACHED) 17191369Sdduvall break; 17201369Sdduvall } 17211369Sdduvall bge_nvmem_relinquish(bgep); 17221369Sdduvall } 17231369Sdduvall 17241369Sdduvall BGE_DEBUG(("bge_nvmem_rw32: err %d", err)); 17251369Sdduvall return (err); 17261369Sdduvall } 17271369Sdduvall 17281369Sdduvall /* 17291369Sdduvall * Attempt to get a MAC address from the SEEPROM or Flash, if any 17301369Sdduvall */ 17311369Sdduvall static uint64_t bge_get_nvmac(bge_t *bgep); 17321369Sdduvall #pragma no_inline(bge_get_nvmac) 17331369Sdduvall 17341369Sdduvall static uint64_t 17351369Sdduvall bge_get_nvmac(bge_t *bgep) 17361369Sdduvall { 17371369Sdduvall uint32_t mac_high; 17381369Sdduvall uint32_t mac_low; 17391369Sdduvall uint32_t addr; 17401369Sdduvall uint32_t cmd; 17411369Sdduvall uint64_t mac; 17421369Sdduvall 17431369Sdduvall BGE_TRACE(("bge_get_nvmac($%p)", 17444588Sml149210 (void *)bgep)); 17451369Sdduvall 17461369Sdduvall switch (bgep->chipid.nvtype) { 17471369Sdduvall case BGE_NVTYPE_NONE: 17481369Sdduvall case BGE_NVTYPE_UNKNOWN: 17491369Sdduvall default: 17501369Sdduvall return (0ULL); 17511369Sdduvall 17521369Sdduvall case BGE_NVTYPE_SEEPROM: 17531369Sdduvall case BGE_NVTYPE_LEGACY_SEEPROM: 17541369Sdduvall cmd = BGE_SEE_READ; 17551369Sdduvall break; 17561369Sdduvall 17571369Sdduvall case BGE_NVTYPE_UNBUFFERED_FLASH: 17581369Sdduvall case BGE_NVTYPE_BUFFERED_FLASH: 17591369Sdduvall cmd = BGE_FLASH_READ; 17601369Sdduvall break; 17611369Sdduvall } 17621369Sdduvall 17637678SYong.Tan@Sun.COM if (DEVICE_5906_SERIES_CHIPSETS(bgep)) 17647678SYong.Tan@Sun.COM addr = NVMEM_DATA_MAC_ADDRESS_5906; 17657678SYong.Tan@Sun.COM else 17667678SYong.Tan@Sun.COM addr = NVMEM_DATA_MAC_ADDRESS; 17677678SYong.Tan@Sun.COM 17681369Sdduvall if (bge_nvmem_rw32(bgep, cmd, addr, &mac_high)) 17691369Sdduvall return (0ULL); 17701369Sdduvall addr += 4; 17711369Sdduvall if (bge_nvmem_rw32(bgep, cmd, addr, &mac_low)) 17721369Sdduvall return (0ULL); 17731369Sdduvall 17741369Sdduvall /* 17751369Sdduvall * The Broadcom chip is natively BIG-endian, so that's how the 17761369Sdduvall * MAC address is represented in NVmem. We may need to swap it 17771369Sdduvall * around on a little-endian host ... 17781369Sdduvall */ 17791369Sdduvall #ifdef _BIG_ENDIAN 17801369Sdduvall mac = mac_high; 17811369Sdduvall mac = mac << 32; 17821369Sdduvall mac |= mac_low; 17831369Sdduvall #else 17841369Sdduvall mac = BGE_BSWAP_32(mac_high); 17851369Sdduvall mac = mac << 32; 17861369Sdduvall mac |= BGE_BSWAP_32(mac_low); 17871369Sdduvall #endif /* _BIG_ENDIAN */ 17881369Sdduvall 17891369Sdduvall return (mac); 17901369Sdduvall } 17911369Sdduvall 17921369Sdduvall #else /* BGE_SEE_IO32 || BGE_FLASH_IO32 */ 17931369Sdduvall 17941369Sdduvall /* 17951369Sdduvall * Dummy version for when we're not supporting NVmem access 17961369Sdduvall */ 17971369Sdduvall static uint64_t bge_get_nvmac(bge_t *bgep); 17981369Sdduvall #pragma inline(bge_get_nvmac) 17991369Sdduvall 18001369Sdduvall static uint64_t 18011369Sdduvall bge_get_nvmac(bge_t *bgep) 18021369Sdduvall { 18031369Sdduvall _NOTE(ARGUNUSED(bgep)) 18041369Sdduvall return (0ULL); 18051369Sdduvall } 18061369Sdduvall 18071369Sdduvall #endif /* BGE_SEE_IO32 || BGE_FLASH_IO32 */ 18081369Sdduvall 18091369Sdduvall /* 18101369Sdduvall * Determine the type of NVmem that is (or may be) attached to this chip, 18111369Sdduvall */ 18121369Sdduvall static enum bge_nvmem_type bge_nvmem_id(bge_t *bgep); 18131369Sdduvall #pragma no_inline(bge_nvmem_id) 18141369Sdduvall 18151369Sdduvall static enum bge_nvmem_type 18161369Sdduvall bge_nvmem_id(bge_t *bgep) 18171369Sdduvall { 18181369Sdduvall enum bge_nvmem_type nvtype; 18191369Sdduvall uint32_t config1; 18201369Sdduvall 18211369Sdduvall BGE_TRACE(("bge_nvmem_id($%p)", 18224588Sml149210 (void *)bgep)); 18231369Sdduvall 18241369Sdduvall switch (bgep->chipid.device) { 18251369Sdduvall default: 18261369Sdduvall /* 18271369Sdduvall * We shouldn't get here; it means we don't recognise 18281369Sdduvall * the chip, which means we don't know how to determine 18291369Sdduvall * what sort of NVmem (if any) it has. So we'll say 18301369Sdduvall * NONE, to disable the NVmem access code ... 18311369Sdduvall */ 18321369Sdduvall nvtype = BGE_NVTYPE_NONE; 18331369Sdduvall break; 18341369Sdduvall 18351369Sdduvall case DEVICE_ID_5700: 18361369Sdduvall case DEVICE_ID_5700x: 18371369Sdduvall case DEVICE_ID_5701: 18381369Sdduvall /* 18391369Sdduvall * These devices support *only* SEEPROMs 18401369Sdduvall */ 18411369Sdduvall nvtype = BGE_NVTYPE_SEEPROM; 18421369Sdduvall break; 18431369Sdduvall 18441369Sdduvall case DEVICE_ID_5702: 18451369Sdduvall case DEVICE_ID_5702fe: 18461369Sdduvall case DEVICE_ID_5703C: 18471369Sdduvall case DEVICE_ID_5703S: 18481369Sdduvall case DEVICE_ID_5704C: 18491369Sdduvall case DEVICE_ID_5704S: 18501369Sdduvall case DEVICE_ID_5704: 18511369Sdduvall case DEVICE_ID_5705M: 18521369Sdduvall case DEVICE_ID_5705C: 18533170Sml149210 case DEVICE_ID_5705_2: 18547871SGarrett.Damore@Sun.COM case DEVICE_ID_5780: 18551369Sdduvall case DEVICE_ID_5782: 1856*11479SYong.Tan@Sun.COM case DEVICE_ID_5785: 18576989Sml40262 case DEVICE_ID_5787: 18586989Sml40262 case DEVICE_ID_5787M: 18591369Sdduvall case DEVICE_ID_5788: 18602135Szh199473 case DEVICE_ID_5789: 18611369Sdduvall case DEVICE_ID_5751: 18621369Sdduvall case DEVICE_ID_5751M: 18632675Szh199473 case DEVICE_ID_5752: 18642675Szh199473 case DEVICE_ID_5752M: 18653771Sml149210 case DEVICE_ID_5754: 18664330Sml149210 case DEVICE_ID_5755: 18676546Sgh162552 case DEVICE_ID_5755M: 18688207SGordon.Ross@Sun.COM case DEVICE_ID_5756M: 18691369Sdduvall case DEVICE_ID_5721: 18707316SCrisson.Hu@Sun.COM case DEVICE_ID_5722: 18719042SYong.Tan@Sun.COM case DEVICE_ID_5723: 18729165SYong.Tan@Sun.COM case DEVICE_ID_5761: 18739165SYong.Tan@Sun.COM case DEVICE_ID_5761E: 187410862SYong.Tan@Sun.COM case DEVICE_ID_5764: 18751369Sdduvall case DEVICE_ID_5714C: 18761369Sdduvall case DEVICE_ID_5714S: 18771369Sdduvall case DEVICE_ID_5715C: 18783170Sml149210 case DEVICE_ID_5715S: 18791369Sdduvall config1 = bge_reg_get32(bgep, NVM_CONFIG1_REG); 18801369Sdduvall if (config1 & NVM_CFG1_FLASH_MODE) 18811369Sdduvall if (config1 & NVM_CFG1_BUFFERED_MODE) 18821369Sdduvall nvtype = BGE_NVTYPE_BUFFERED_FLASH; 18831369Sdduvall else 18841369Sdduvall nvtype = BGE_NVTYPE_UNBUFFERED_FLASH; 18851369Sdduvall else 18861369Sdduvall nvtype = BGE_NVTYPE_LEGACY_SEEPROM; 18871369Sdduvall break; 18887678SYong.Tan@Sun.COM case DEVICE_ID_5906: 18897678SYong.Tan@Sun.COM case DEVICE_ID_5906M: 18907678SYong.Tan@Sun.COM nvtype = BGE_NVTYPE_BUFFERED_FLASH; 18917678SYong.Tan@Sun.COM break; 18921369Sdduvall } 18931369Sdduvall 18941369Sdduvall return (nvtype); 18951369Sdduvall } 18961369Sdduvall 18971369Sdduvall #undef BGE_DBG 18981369Sdduvall #define BGE_DBG BGE_DBG_CHIP /* debug flag for this code */ 18991369Sdduvall 19001369Sdduvall static void 19011369Sdduvall bge_init_recv_rule(bge_t *bgep) 19021369Sdduvall { 19038275SEric Cheng bge_recv_rule_t *rulep = bgep->recv_rules; 19041369Sdduvall uint32_t i; 19051369Sdduvall 19061369Sdduvall /* 19078275SEric Cheng * Initialize receive rule registers. 19088275SEric Cheng * Note that rules may persist across each bge_m_start/stop() call. 19091369Sdduvall */ 19101369Sdduvall for (i = 0; i < RECV_RULES_NUM_MAX; i++, rulep++) { 19111369Sdduvall bge_reg_put32(bgep, RECV_RULE_MASK_REG(i), rulep->mask_value); 19121369Sdduvall bge_reg_put32(bgep, RECV_RULE_CONTROL_REG(i), rulep->control); 19131369Sdduvall } 19141369Sdduvall } 19151369Sdduvall 19161369Sdduvall /* 19171369Sdduvall * Using the values captured by bge_chip_cfg_init(), and additional probes 19181369Sdduvall * as required, characterise the chip fully: determine the label by which 19191369Sdduvall * to refer to this chip, the correct settings for various registers, and 19201369Sdduvall * of course whether the device and/or subsystem are supported! 19211369Sdduvall */ 19221865Sdilpreet int bge_chip_id_init(bge_t *bgep); 19231369Sdduvall #pragma no_inline(bge_chip_id_init) 19241369Sdduvall 19251865Sdilpreet int 19261369Sdduvall bge_chip_id_init(bge_t *bgep) 19271369Sdduvall { 19281369Sdduvall char buf[MAXPATHLEN]; /* any risk of stack overflow? */ 19291369Sdduvall boolean_t sys_ok; 19301369Sdduvall boolean_t dev_ok; 19311369Sdduvall chip_id_t *cidp; 19321369Sdduvall uint32_t subid; 19331369Sdduvall char *devname; 19341369Sdduvall char *sysname; 19351369Sdduvall int *ids; 19361369Sdduvall int err; 19371369Sdduvall uint_t i; 19381369Sdduvall 19391369Sdduvall sys_ok = dev_ok = B_FALSE; 19401369Sdduvall cidp = &bgep->chipid; 19411369Sdduvall 19421369Sdduvall /* 19431369Sdduvall * Check the PCI device ID to determine the generic chip type and 19441369Sdduvall * select parameters that depend on this. 19451369Sdduvall * 19461369Sdduvall * Note: because the SPARC platforms in general don't fit the 19471369Sdduvall * SEEPROM 'behind' the chip, the PCI revision ID register reads 19481369Sdduvall * as zero - which is why we use <asic_rev> rather than <revision> 19491369Sdduvall * below ... 19501369Sdduvall * 19511369Sdduvall * Note: in general we can't distinguish between the Copper/SerDes 19521369Sdduvall * versions by ID alone, as some Copper devices (e.g. some but not 19531369Sdduvall * all 5703Cs) have the same ID as the SerDes equivalents. So we 19541369Sdduvall * treat them the same here, and the MII code works out the media 19551369Sdduvall * type later on ... 19561369Sdduvall */ 19571369Sdduvall cidp->mbuf_base = bge_mbuf_pool_base; 19581369Sdduvall cidp->mbuf_length = bge_mbuf_pool_len; 19591369Sdduvall cidp->recv_slots = BGE_RECV_SLOTS_USED; 19601369Sdduvall cidp->bge_dma_rwctrl = bge_dma_rwctrl; 19611369Sdduvall cidp->pci_type = BGE_PCI_X; 19621369Sdduvall cidp->statistic_type = BGE_STAT_BLK; 19631908Sly149593 cidp->mbuf_lo_water_rdma = bge_mbuf_lo_water_rdma; 19641908Sly149593 cidp->mbuf_lo_water_rmac = bge_mbuf_lo_water_rmac; 19651908Sly149593 cidp->mbuf_hi_water = bge_mbuf_hi_water; 19665903Ssowmini cidp->rx_ticks_norm = bge_rx_ticks_norm; 19675903Ssowmini cidp->rx_count_norm = bge_rx_count_norm; 19689731SYong.Tan@Sun.COM cidp->tx_ticks_norm = bge_tx_ticks_norm; 19699731SYong.Tan@Sun.COM cidp->tx_count_norm = bge_tx_count_norm; 19701369Sdduvall 19711369Sdduvall if (cidp->rx_rings == 0 || cidp->rx_rings > BGE_RECV_RINGS_MAX) 19721369Sdduvall cidp->rx_rings = BGE_RECV_RINGS_DEFAULT; 19731369Sdduvall if (cidp->tx_rings == 0 || cidp->tx_rings > BGE_SEND_RINGS_MAX) 19741369Sdduvall cidp->tx_rings = BGE_SEND_RINGS_DEFAULT; 19751369Sdduvall 19761369Sdduvall cidp->msi_enabled = B_FALSE; 19771369Sdduvall 19781369Sdduvall switch (cidp->device) { 19791369Sdduvall case DEVICE_ID_5700: 19801369Sdduvall case DEVICE_ID_5700x: 19811369Sdduvall cidp->chip_label = 5700; 19822135Szh199473 cidp->flags |= CHIP_FLAG_PARTIAL_CSUM; 19831369Sdduvall break; 19841369Sdduvall 19851369Sdduvall case DEVICE_ID_5701: 19861369Sdduvall cidp->chip_label = 5701; 19871369Sdduvall dev_ok = B_TRUE; 19882135Szh199473 cidp->flags |= CHIP_FLAG_PARTIAL_CSUM; 19891369Sdduvall break; 19901369Sdduvall 19911369Sdduvall case DEVICE_ID_5702: 19921369Sdduvall case DEVICE_ID_5702fe: 19931369Sdduvall cidp->chip_label = 5702; 19941369Sdduvall dev_ok = B_TRUE; 19952135Szh199473 cidp->flags |= CHIP_FLAG_PARTIAL_CSUM; 19962135Szh199473 cidp->pci_type = BGE_PCI; 19971369Sdduvall break; 19981369Sdduvall 19991369Sdduvall case DEVICE_ID_5703C: 20001369Sdduvall case DEVICE_ID_5703S: 20011369Sdduvall case DEVICE_ID_5703: 20021369Sdduvall /* 20031369Sdduvall * Revision A0 of the 5703/5793 had various errata 20041369Sdduvall * that we can't or don't work around, so it's not 20051369Sdduvall * supported, but all later versions are 20061369Sdduvall */ 20071369Sdduvall cidp->chip_label = cidp->subven == VENDOR_ID_SUN ? 5793 : 5703; 20081369Sdduvall if (bgep->chipid.asic_rev != MHCR_CHIP_REV_5703_A0) 20091369Sdduvall dev_ok = B_TRUE; 20102135Szh199473 cidp->flags |= CHIP_FLAG_PARTIAL_CSUM; 20111369Sdduvall break; 20121369Sdduvall 20131369Sdduvall case DEVICE_ID_5704C: 20141369Sdduvall case DEVICE_ID_5704S: 20151369Sdduvall case DEVICE_ID_5704: 20161369Sdduvall cidp->chip_label = cidp->subven == VENDOR_ID_SUN ? 5794 : 5704; 20171369Sdduvall cidp->mbuf_base = bge_mbuf_pool_base_5704; 20181369Sdduvall cidp->mbuf_length = bge_mbuf_pool_len_5704; 20191369Sdduvall dev_ok = B_TRUE; 20206133Sgh162552 cidp->flags |= CHIP_FLAG_PARTIAL_CSUM; 20211369Sdduvall break; 20221369Sdduvall 20231369Sdduvall case DEVICE_ID_5705C: 20241369Sdduvall case DEVICE_ID_5705M: 20251369Sdduvall case DEVICE_ID_5705MA3: 20261369Sdduvall case DEVICE_ID_5705F: 20273170Sml149210 case DEVICE_ID_5705_2: 20283771Sml149210 case DEVICE_ID_5754: 20293771Sml149210 if (cidp->device == DEVICE_ID_5754) { 20303771Sml149210 cidp->chip_label = 5754; 20313771Sml149210 cidp->pci_type = BGE_PCI_E; 20323771Sml149210 } else { 20333771Sml149210 cidp->chip_label = 5705; 20343771Sml149210 cidp->pci_type = BGE_PCI; 203510845SYong.Tan@Sun.COM cidp->flags |= CHIP_FLAG_PARTIAL_CSUM; 20363771Sml149210 } 20371908Sly149593 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 20381908Sly149593 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 20391908Sly149593 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 20401369Sdduvall cidp->mbuf_base = bge_mbuf_pool_base_5705; 20411369Sdduvall cidp->mbuf_length = bge_mbuf_pool_len_5705; 20421369Sdduvall cidp->recv_slots = BGE_RECV_SLOTS_5705; 20431369Sdduvall cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 20441908Sly149593 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 20451369Sdduvall cidp->flags |= CHIP_FLAG_NO_JUMBO; 20461369Sdduvall cidp->statistic_type = BGE_STAT_REG; 20471369Sdduvall dev_ok = B_TRUE; 20481369Sdduvall break; 20491369Sdduvall 20507678SYong.Tan@Sun.COM case DEVICE_ID_5906: 20517678SYong.Tan@Sun.COM case DEVICE_ID_5906M: 20527678SYong.Tan@Sun.COM cidp->chip_label = 5906; 20537678SYong.Tan@Sun.COM cidp->pci_type = BGE_PCI_E; 20547678SYong.Tan@Sun.COM cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5906; 20557678SYong.Tan@Sun.COM cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5906; 20567678SYong.Tan@Sun.COM cidp->mbuf_hi_water = MBUF_HIWAT_5906; 20577678SYong.Tan@Sun.COM cidp->mbuf_base = bge_mbuf_pool_base; 20587678SYong.Tan@Sun.COM cidp->mbuf_length = bge_mbuf_pool_len; 20597678SYong.Tan@Sun.COM cidp->recv_slots = BGE_RECV_SLOTS_5705; 20607678SYong.Tan@Sun.COM cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 20617678SYong.Tan@Sun.COM cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 20627678SYong.Tan@Sun.COM cidp->flags |= CHIP_FLAG_NO_JUMBO; 20637678SYong.Tan@Sun.COM cidp->statistic_type = BGE_STAT_REG; 20647678SYong.Tan@Sun.COM dev_ok = B_TRUE; 20657678SYong.Tan@Sun.COM break; 20667678SYong.Tan@Sun.COM 20674588Sml149210 case DEVICE_ID_5753: 20684588Sml149210 cidp->chip_label = 5753; 20694588Sml149210 cidp->pci_type = BGE_PCI_E; 20704588Sml149210 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 20714588Sml149210 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 20724588Sml149210 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 20734588Sml149210 cidp->mbuf_base = bge_mbuf_pool_base_5705; 20744588Sml149210 cidp->mbuf_length = bge_mbuf_pool_len_5705; 20754588Sml149210 cidp->recv_slots = BGE_RECV_SLOTS_5705; 20764588Sml149210 cidp->bge_mlcr_default |= MLCR_MISC_PINS_OUTPUT_ENABLE_1; 20774588Sml149210 cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 20784588Sml149210 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 20794588Sml149210 cidp->flags |= CHIP_FLAG_NO_JUMBO; 20804588Sml149210 cidp->statistic_type = BGE_STAT_REG; 20814588Sml149210 dev_ok = B_TRUE; 20824588Sml149210 break; 20834588Sml149210 20844330Sml149210 case DEVICE_ID_5755: 20856546Sgh162552 case DEVICE_ID_5755M: 20864330Sml149210 cidp->chip_label = 5755; 20874330Sml149210 cidp->pci_type = BGE_PCI_E; 20884330Sml149210 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 20894330Sml149210 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 20904330Sml149210 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 20914330Sml149210 cidp->mbuf_base = bge_mbuf_pool_base_5705; 20924330Sml149210 cidp->mbuf_length = bge_mbuf_pool_len_5705; 20934330Sml149210 cidp->recv_slots = BGE_RECV_SLOTS_5705; 20944330Sml149210 cidp->bge_mlcr_default |= MLCR_MISC_PINS_OUTPUT_ENABLE_1; 20954330Sml149210 cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 20964330Sml149210 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 20974330Sml149210 cidp->flags |= CHIP_FLAG_NO_JUMBO; 209810845SYong.Tan@Sun.COM if (cidp->device == DEVICE_ID_5755M) 209910845SYong.Tan@Sun.COM cidp->flags |= CHIP_FLAG_PARTIAL_CSUM; 21004330Sml149210 cidp->statistic_type = BGE_STAT_REG; 21014330Sml149210 dev_ok = B_TRUE; 21024330Sml149210 break; 21034330Sml149210 21048207SGordon.Ross@Sun.COM case DEVICE_ID_5756M: 21058207SGordon.Ross@Sun.COM /* 21068207SGordon.Ross@Sun.COM * This is nearly identical to the 5755M. 21078207SGordon.Ross@Sun.COM * (Actually reports the 5755 chip ID.) 21088207SGordon.Ross@Sun.COM */ 21098207SGordon.Ross@Sun.COM cidp->chip_label = 5756; 21108207SGordon.Ross@Sun.COM cidp->pci_type = BGE_PCI_E; 21118207SGordon.Ross@Sun.COM cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 21128207SGordon.Ross@Sun.COM cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 21138207SGordon.Ross@Sun.COM cidp->mbuf_hi_water = MBUF_HIWAT_5705; 21148207SGordon.Ross@Sun.COM cidp->mbuf_base = bge_mbuf_pool_base_5705; 21158207SGordon.Ross@Sun.COM cidp->mbuf_length = bge_mbuf_pool_len_5705; 21168207SGordon.Ross@Sun.COM cidp->recv_slots = BGE_RECV_SLOTS_5705; 21178207SGordon.Ross@Sun.COM cidp->bge_mlcr_default |= MLCR_MISC_PINS_OUTPUT_ENABLE_1; 21188207SGordon.Ross@Sun.COM cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 21198207SGordon.Ross@Sun.COM cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 21208207SGordon.Ross@Sun.COM cidp->flags |= CHIP_FLAG_NO_JUMBO; 21218207SGordon.Ross@Sun.COM cidp->statistic_type = BGE_STAT_REG; 21228207SGordon.Ross@Sun.COM dev_ok = B_TRUE; 21238207SGordon.Ross@Sun.COM break; 21248207SGordon.Ross@Sun.COM 21256989Sml40262 case DEVICE_ID_5787: 21266989Sml40262 case DEVICE_ID_5787M: 21276989Sml40262 cidp->chip_label = 5787; 21286989Sml40262 cidp->pci_type = BGE_PCI_E; 21296989Sml40262 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 21306989Sml40262 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 21316989Sml40262 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 21326989Sml40262 cidp->mbuf_base = bge_mbuf_pool_base_5705; 21336989Sml40262 cidp->mbuf_length = bge_mbuf_pool_len_5705; 21346989Sml40262 cidp->recv_slots = BGE_RECV_SLOTS_5705; 21356989Sml40262 cidp->bge_mlcr_default |= MLCR_MISC_PINS_OUTPUT_ENABLE_1; 21366989Sml40262 cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 21376989Sml40262 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 21386989Sml40262 cidp->flags |= CHIP_FLAG_NO_JUMBO; 21396989Sml40262 cidp->statistic_type = BGE_STAT_REG; 21406989Sml40262 dev_ok = B_TRUE; 21416989Sml40262 break; 21426989Sml40262 21439042SYong.Tan@Sun.COM case DEVICE_ID_5723: 21449165SYong.Tan@Sun.COM case DEVICE_ID_5761: 21459165SYong.Tan@Sun.COM case DEVICE_ID_5761E: 214610862SYong.Tan@Sun.COM cidp->msi_enabled = bge_enable_msi; 214710862SYong.Tan@Sun.COM /* 2148*11479SYong.Tan@Sun.COM * We don't use MSI for BCM5764 and BCM5785, as the 2149*11479SYong.Tan@Sun.COM * status block may fail to update when the network 2150*11479SYong.Tan@Sun.COM * traffic is heavy. 215110862SYong.Tan@Sun.COM */ 215210862SYong.Tan@Sun.COM /* FALLTHRU */ 2153*11479SYong.Tan@Sun.COM case DEVICE_ID_5785: 215410862SYong.Tan@Sun.COM case DEVICE_ID_5764: 215510862SYong.Tan@Sun.COM if (cidp->device == DEVICE_ID_5723) 215610862SYong.Tan@Sun.COM cidp->chip_label = 5723; 215710862SYong.Tan@Sun.COM else if (cidp->device == DEVICE_ID_5764) 215810862SYong.Tan@Sun.COM cidp->chip_label = 5764; 2159*11479SYong.Tan@Sun.COM else if (cidp->device == DEVICE_ID_5785) 2160*11479SYong.Tan@Sun.COM cidp->chip_label = 5785; 216110862SYong.Tan@Sun.COM else 216210862SYong.Tan@Sun.COM cidp->chip_label = 5761; 21639042SYong.Tan@Sun.COM cidp->bge_dma_rwctrl = bge_dma_rwctrl_5721; 21649042SYong.Tan@Sun.COM cidp->pci_type = BGE_PCI_E; 21659042SYong.Tan@Sun.COM cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 21669042SYong.Tan@Sun.COM cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 21679042SYong.Tan@Sun.COM cidp->mbuf_hi_water = MBUF_HIWAT_5705; 21689042SYong.Tan@Sun.COM cidp->mbuf_base = bge_mbuf_pool_base_5705; 21699042SYong.Tan@Sun.COM cidp->mbuf_length = bge_mbuf_pool_len_5705; 21709042SYong.Tan@Sun.COM cidp->recv_slots = BGE_RECV_SLOTS_5705; 21719042SYong.Tan@Sun.COM cidp->bge_mlcr_default |= MLCR_MISC_PINS_OUTPUT_ENABLE_1; 21729042SYong.Tan@Sun.COM cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 21739042SYong.Tan@Sun.COM cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 21741369Sdduvall cidp->flags |= CHIP_FLAG_NO_JUMBO; 21759042SYong.Tan@Sun.COM cidp->statistic_type = BGE_STAT_REG; 21769042SYong.Tan@Sun.COM dev_ok = B_TRUE; 21771369Sdduvall break; 21781369Sdduvall 21799548SCrisson.Hu@Sun.COM /* PCI-X device, identical to 5714 */ 21807871SGarrett.Damore@Sun.COM case DEVICE_ID_5780: 21817871SGarrett.Damore@Sun.COM cidp->chip_label = 5780; 21827871SGarrett.Damore@Sun.COM cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 21837871SGarrett.Damore@Sun.COM cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 21847871SGarrett.Damore@Sun.COM cidp->mbuf_hi_water = MBUF_HIWAT_5705; 21859548SCrisson.Hu@Sun.COM cidp->mbuf_base = bge_mbuf_pool_base_5721; 21869548SCrisson.Hu@Sun.COM cidp->mbuf_length = bge_mbuf_pool_len_5721; 21879548SCrisson.Hu@Sun.COM cidp->recv_slots = BGE_RECV_SLOTS_5721; 21887871SGarrett.Damore@Sun.COM cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 21897871SGarrett.Damore@Sun.COM cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 21907871SGarrett.Damore@Sun.COM cidp->statistic_type = BGE_STAT_REG; 21917871SGarrett.Damore@Sun.COM dev_ok = B_TRUE; 21927871SGarrett.Damore@Sun.COM break; 21937871SGarrett.Damore@Sun.COM 21941369Sdduvall case DEVICE_ID_5782: 21951369Sdduvall /* 21961369Sdduvall * Apart from the label, we treat this as a 5705(?) 21971369Sdduvall */ 21981369Sdduvall cidp->chip_label = 5782; 21991908Sly149593 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 22001908Sly149593 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 22011908Sly149593 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 22021369Sdduvall cidp->mbuf_base = bge_mbuf_pool_base_5705; 22031369Sdduvall cidp->mbuf_length = bge_mbuf_pool_len_5705; 22041369Sdduvall cidp->recv_slots = BGE_RECV_SLOTS_5705; 22051369Sdduvall cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 22061908Sly149593 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 22071369Sdduvall cidp->flags |= CHIP_FLAG_NO_JUMBO; 22082135Szh199473 cidp->flags |= CHIP_FLAG_PARTIAL_CSUM; 22091369Sdduvall cidp->statistic_type = BGE_STAT_REG; 22101369Sdduvall dev_ok = B_TRUE; 22111369Sdduvall break; 22121369Sdduvall 22131369Sdduvall case DEVICE_ID_5788: 22141369Sdduvall /* 22151369Sdduvall * Apart from the label, we treat this as a 5705(?) 22161369Sdduvall */ 22171369Sdduvall cidp->chip_label = 5788; 22181908Sly149593 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 22191908Sly149593 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 22201908Sly149593 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 22211369Sdduvall cidp->mbuf_base = bge_mbuf_pool_base_5705; 22221369Sdduvall cidp->mbuf_length = bge_mbuf_pool_len_5705; 22231369Sdduvall cidp->recv_slots = BGE_RECV_SLOTS_5705; 22241369Sdduvall cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 22251908Sly149593 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 22261369Sdduvall cidp->statistic_type = BGE_STAT_REG; 22271369Sdduvall cidp->flags |= CHIP_FLAG_NO_JUMBO; 22281369Sdduvall dev_ok = B_TRUE; 22291369Sdduvall break; 22301369Sdduvall 22311369Sdduvall case DEVICE_ID_5714C: 22321369Sdduvall if (cidp->revision >= REVISION_ID_5714_A2) 22331369Sdduvall cidp->msi_enabled = bge_enable_msi; 22341369Sdduvall /* FALLTHRU */ 22351369Sdduvall case DEVICE_ID_5714S: 22361369Sdduvall cidp->chip_label = 5714; 22371908Sly149593 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 22381908Sly149593 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 22391908Sly149593 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 22401369Sdduvall cidp->mbuf_base = bge_mbuf_pool_base_5721; 22411369Sdduvall cidp->mbuf_length = bge_mbuf_pool_len_5721; 22421369Sdduvall cidp->recv_slots = BGE_RECV_SLOTS_5721; 22431369Sdduvall cidp->bge_dma_rwctrl = bge_dma_rwctrl_5714; 22441369Sdduvall cidp->bge_mlcr_default = bge_mlcr_default_5714; 22451369Sdduvall cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 22461908Sly149593 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 22471369Sdduvall cidp->pci_type = BGE_PCI_E; 22481369Sdduvall cidp->statistic_type = BGE_STAT_REG; 22491369Sdduvall dev_ok = B_TRUE; 22501369Sdduvall break; 22511369Sdduvall 22521369Sdduvall case DEVICE_ID_5715C: 22533170Sml149210 case DEVICE_ID_5715S: 22541369Sdduvall cidp->chip_label = 5715; 22551908Sly149593 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 22561908Sly149593 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 22571908Sly149593 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 22581369Sdduvall cidp->mbuf_base = bge_mbuf_pool_base_5721; 22591369Sdduvall cidp->mbuf_length = bge_mbuf_pool_len_5721; 22601369Sdduvall cidp->recv_slots = BGE_RECV_SLOTS_5721; 22611369Sdduvall cidp->bge_dma_rwctrl = bge_dma_rwctrl_5715; 22621369Sdduvall cidp->bge_mlcr_default = bge_mlcr_default_5714; 22631369Sdduvall cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 22641908Sly149593 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 22651369Sdduvall cidp->pci_type = BGE_PCI_E; 22661369Sdduvall cidp->statistic_type = BGE_STAT_REG; 22671908Sly149593 if (cidp->revision >= REVISION_ID_5715_A2) 22681908Sly149593 cidp->msi_enabled = bge_enable_msi; 22691369Sdduvall dev_ok = B_TRUE; 22701369Sdduvall break; 22711369Sdduvall 22721369Sdduvall case DEVICE_ID_5721: 22731369Sdduvall cidp->chip_label = 5721; 22741908Sly149593 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 22751908Sly149593 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 22761908Sly149593 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 22771369Sdduvall cidp->mbuf_base = bge_mbuf_pool_base_5721; 22781369Sdduvall cidp->mbuf_length = bge_mbuf_pool_len_5721; 22791369Sdduvall cidp->recv_slots = BGE_RECV_SLOTS_5721; 22801369Sdduvall cidp->bge_dma_rwctrl = bge_dma_rwctrl_5721; 22811369Sdduvall cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 22821908Sly149593 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 22831369Sdduvall cidp->pci_type = BGE_PCI_E; 22841369Sdduvall cidp->statistic_type = BGE_STAT_REG; 22851369Sdduvall cidp->flags |= CHIP_FLAG_NO_JUMBO; 22861369Sdduvall dev_ok = B_TRUE; 22871369Sdduvall break; 22881369Sdduvall 22897316SCrisson.Hu@Sun.COM case DEVICE_ID_5722: 22907316SCrisson.Hu@Sun.COM cidp->chip_label = 5722; 22917316SCrisson.Hu@Sun.COM cidp->pci_type = BGE_PCI_E; 22927316SCrisson.Hu@Sun.COM cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 22937316SCrisson.Hu@Sun.COM cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 22947316SCrisson.Hu@Sun.COM cidp->mbuf_hi_water = MBUF_HIWAT_5705; 22957316SCrisson.Hu@Sun.COM cidp->mbuf_base = bge_mbuf_pool_base_5705; 22967316SCrisson.Hu@Sun.COM cidp->mbuf_length = bge_mbuf_pool_len_5705; 22977316SCrisson.Hu@Sun.COM cidp->recv_slots = BGE_RECV_SLOTS_5705; 22987316SCrisson.Hu@Sun.COM cidp->bge_mlcr_default |= MLCR_MISC_PINS_OUTPUT_ENABLE_1; 22997316SCrisson.Hu@Sun.COM cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 23007316SCrisson.Hu@Sun.COM cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 23017316SCrisson.Hu@Sun.COM cidp->flags |= CHIP_FLAG_NO_JUMBO; 23027316SCrisson.Hu@Sun.COM cidp->statistic_type = BGE_STAT_REG; 23037316SCrisson.Hu@Sun.COM dev_ok = B_TRUE; 23047316SCrisson.Hu@Sun.COM break; 23057316SCrisson.Hu@Sun.COM 23061369Sdduvall case DEVICE_ID_5751: 23071369Sdduvall case DEVICE_ID_5751M: 23081369Sdduvall cidp->chip_label = 5751; 23091908Sly149593 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 23101908Sly149593 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 23111908Sly149593 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 23121369Sdduvall cidp->mbuf_base = bge_mbuf_pool_base_5721; 23131369Sdduvall cidp->mbuf_length = bge_mbuf_pool_len_5721; 23141369Sdduvall cidp->recv_slots = BGE_RECV_SLOTS_5721; 23151369Sdduvall cidp->bge_dma_rwctrl = bge_dma_rwctrl_5721; 23161369Sdduvall cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 23171908Sly149593 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 23181369Sdduvall cidp->pci_type = BGE_PCI_E; 23191369Sdduvall cidp->statistic_type = BGE_STAT_REG; 23201369Sdduvall cidp->flags |= CHIP_FLAG_NO_JUMBO; 23211369Sdduvall dev_ok = B_TRUE; 23221369Sdduvall break; 23231369Sdduvall 23242675Szh199473 case DEVICE_ID_5752: 23252675Szh199473 case DEVICE_ID_5752M: 23262675Szh199473 cidp->chip_label = 5752; 23272675Szh199473 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 23282675Szh199473 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 23292675Szh199473 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 23302675Szh199473 cidp->mbuf_base = bge_mbuf_pool_base_5721; 23312675Szh199473 cidp->mbuf_length = bge_mbuf_pool_len_5721; 23322675Szh199473 cidp->recv_slots = BGE_RECV_SLOTS_5721; 23332675Szh199473 cidp->bge_dma_rwctrl = bge_dma_rwctrl_5721; 23342675Szh199473 cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 23352675Szh199473 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 23362675Szh199473 cidp->pci_type = BGE_PCI_E; 23372675Szh199473 cidp->statistic_type = BGE_STAT_REG; 23382675Szh199473 cidp->flags |= CHIP_FLAG_NO_JUMBO; 23392675Szh199473 dev_ok = B_TRUE; 23402675Szh199473 break; 23412675Szh199473 23422135Szh199473 case DEVICE_ID_5789: 23432135Szh199473 cidp->chip_label = 5789; 23442135Szh199473 cidp->mbuf_base = bge_mbuf_pool_base_5721; 23452135Szh199473 cidp->mbuf_length = bge_mbuf_pool_len_5721; 23462135Szh199473 cidp->recv_slots = BGE_RECV_SLOTS_5721; 23472135Szh199473 cidp->bge_dma_rwctrl = bge_dma_rwctrl_5721; 23482135Szh199473 cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 23492135Szh199473 cidp->tx_rings = BGE_RECV_RINGS_MAX_5705; 23502135Szh199473 cidp->pci_type = BGE_PCI_E; 23512135Szh199473 cidp->statistic_type = BGE_STAT_REG; 23522135Szh199473 cidp->flags |= CHIP_FLAG_PARTIAL_CSUM; 23532135Szh199473 cidp->flags |= CHIP_FLAG_NO_JUMBO; 23542135Szh199473 cidp->msi_enabled = B_TRUE; 23552135Szh199473 dev_ok = B_TRUE; 23562135Szh199473 break; 23572135Szh199473 23581369Sdduvall } 23591369Sdduvall 23601369Sdduvall /* 23611369Sdduvall * Setup the default jumbo parameter. 23621369Sdduvall */ 23631369Sdduvall cidp->ethmax_size = ETHERMAX; 23641369Sdduvall cidp->snd_buff_size = BGE_SEND_BUFF_SIZE_DEFAULT; 23651908Sly149593 cidp->std_buf_size = BGE_STD_BUFF_SIZE; 23661369Sdduvall 23671369Sdduvall /* 23681369Sdduvall * If jumbo is enabled and this kind of chipset supports jumbo feature, 23691369Sdduvall * setup below jumbo specific parameters. 23701908Sly149593 * 23711908Sly149593 * For BCM5714/5715, there is only one standard receive ring. So the 23721908Sly149593 * std buffer size should be set to BGE_JUMBO_BUFF_SIZE when jumbo 23731908Sly149593 * feature is enabled. 23741369Sdduvall */ 237510162SYong.Tan@Sun.COM if (!(cidp->flags & CHIP_FLAG_NO_JUMBO) && 237610464SYong.Tan@Sun.COM (cidp->default_mtu > BGE_DEFAULT_MTU)) { 23774588Sml149210 if (DEVICE_5714_SERIES_CHIPSETS(bgep)) { 23781908Sly149593 cidp->mbuf_lo_water_rdma = 23791908Sly149593 RDMA_MBUF_LOWAT_5714_JUMBO; 23801908Sly149593 cidp->mbuf_lo_water_rmac = 23811908Sly149593 MAC_RX_MBUF_LOWAT_5714_JUMBO; 23821908Sly149593 cidp->mbuf_hi_water = MBUF_HIWAT_5714_JUMBO; 23831908Sly149593 cidp->jumbo_slots = 0; 23841908Sly149593 cidp->std_buf_size = BGE_JUMBO_BUFF_SIZE; 23854588Sml149210 } else { 23861908Sly149593 cidp->mbuf_lo_water_rdma = 23871908Sly149593 RDMA_MBUF_LOWAT_JUMBO; 23881908Sly149593 cidp->mbuf_lo_water_rmac = 23891908Sly149593 MAC_RX_MBUF_LOWAT_JUMBO; 23901908Sly149593 cidp->mbuf_hi_water = MBUF_HIWAT_JUMBO; 23911908Sly149593 cidp->jumbo_slots = BGE_JUMBO_SLOTS_USED; 23921908Sly149593 } 23931369Sdduvall cidp->recv_jumbo_size = BGE_JUMBO_BUFF_SIZE; 23941369Sdduvall cidp->snd_buff_size = BGE_SEND_BUFF_SIZE_JUMBO; 23951369Sdduvall cidp->ethmax_size = cidp->default_mtu + 23961369Sdduvall sizeof (struct ether_header); 23971369Sdduvall } 23981369Sdduvall 23991369Sdduvall /* 24001369Sdduvall * Identify the NV memory type: SEEPROM or Flash? 24011369Sdduvall */ 24021369Sdduvall cidp->nvtype = bge_nvmem_id(bgep); 24031369Sdduvall 24041369Sdduvall /* 24051369Sdduvall * Now, we want to check whether this device is part of a 24061369Sdduvall * supported subsystem (e.g., on the motherboard of a Sun 24071369Sdduvall * branded platform). 24081369Sdduvall * 24091369Sdduvall * Rule 1: If the Subsystem Vendor ID is "Sun", then it's OK ;-) 24101369Sdduvall */ 24111369Sdduvall if (cidp->subven == VENDOR_ID_SUN) 24121369Sdduvall sys_ok = B_TRUE; 24131369Sdduvall 24141369Sdduvall /* 24151369Sdduvall * Rule 2: If it's on the list on known subsystems, then it's OK. 24161369Sdduvall * Note: 0x14e41647 should *not* appear in the list, but the code 24171369Sdduvall * doesn't enforce that. 24181369Sdduvall */ 24191369Sdduvall err = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, bgep->devinfo, 24204588Sml149210 DDI_PROP_DONTPASS, knownids_propname, &ids, &i); 24211369Sdduvall if (err == DDI_PROP_SUCCESS) { 24221369Sdduvall /* 24231369Sdduvall * Got the list; scan for a matching subsystem vendor/device 24241369Sdduvall */ 24251369Sdduvall subid = (cidp->subven << 16) | cidp->subdev; 24261369Sdduvall while (i--) 24271369Sdduvall if (ids[i] == subid) 24281369Sdduvall sys_ok = B_TRUE; 24291369Sdduvall ddi_prop_free(ids); 24301369Sdduvall } 24311369Sdduvall 24321369Sdduvall /* 24331369Sdduvall * Rule 3: If it's a Taco/ENWS motherboard device, then it's OK 24341369Sdduvall * 24351369Sdduvall * Unfortunately, early SunBlade 1500s and 2500s didn't reprogram 24361369Sdduvall * the Subsystem Vendor ID, so it defaults to Broadcom. Therefore, 24371369Sdduvall * we have to check specially for the exact device paths to the 24381369Sdduvall * motherboard devices on those platforms ;-( 24391369Sdduvall * 24401369Sdduvall * Note: we can't just use the "supported-subsystems" mechanism 24411369Sdduvall * above, because the entry would have to be 0x14e41647 -- which 24421369Sdduvall * would then accept *any* plugin card that *didn't* contain a 24431369Sdduvall * (valid) SEEPROM ;-( 24441369Sdduvall */ 24451369Sdduvall sysname = ddi_node_name(ddi_root_node()); 24461369Sdduvall devname = ddi_pathname(bgep->devinfo, buf); 24471369Sdduvall ASSERT(strlen(devname) > 0); 24481369Sdduvall if (strcmp(sysname, "SUNW,Sun-Blade-1500") == 0) /* Taco */ 24491369Sdduvall if (strcmp(devname, "/pci@1f,700000/network@2") == 0) 24501369Sdduvall sys_ok = B_TRUE; 24511369Sdduvall if (strcmp(sysname, "SUNW,Sun-Blade-2500") == 0) /* ENWS */ 24521369Sdduvall if (strcmp(devname, "/pci@1c,600000/network@3") == 0) 24531369Sdduvall sys_ok = B_TRUE; 24541369Sdduvall 24551369Sdduvall /* 24561369Sdduvall * Now check what we've discovered: is this truly a supported 24571369Sdduvall * chip on (the motherboard of) a supported platform? 24581369Sdduvall * 24591369Sdduvall * Possible problems here: 24609165SYong.Tan@Sun.COM * 1) it's a completely unheard-of chip 24611369Sdduvall * 2) it's a recognised but unsupported chip (e.g. 5701, 5703C-A0) 24621369Sdduvall * 3) it's a chip we would support if it were on the motherboard 24631369Sdduvall * of a Sun platform, but this one isn't ;-( 24641369Sdduvall */ 24651369Sdduvall if (cidp->chip_label == 0) 24661369Sdduvall bge_problem(bgep, 24674588Sml149210 "Device 'pci%04x,%04x' not recognized (%d?)", 24684588Sml149210 cidp->vendor, cidp->device, cidp->device); 24691369Sdduvall else if (!dev_ok) 24701369Sdduvall bge_problem(bgep, 24714588Sml149210 "Device 'pci%04x,%04x' (%d) revision %d not supported", 24724588Sml149210 cidp->vendor, cidp->device, cidp->chip_label, 24734588Sml149210 cidp->revision); 24741369Sdduvall #if BGE_DEBUGGING 24751369Sdduvall else if (!sys_ok) 24761369Sdduvall bge_problem(bgep, 24774588Sml149210 "%d-based subsystem 'pci%04x,%04x' not validated", 24784588Sml149210 cidp->chip_label, cidp->subven, cidp->subdev); 24791369Sdduvall #endif 24801369Sdduvall else 24811369Sdduvall cidp->flags |= CHIP_FLAG_SUPPORTED; 24821865Sdilpreet if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) 24831865Sdilpreet return (EIO); 24841865Sdilpreet return (0); 24851369Sdduvall } 24861369Sdduvall 24871369Sdduvall void 24881369Sdduvall bge_chip_msi_trig(bge_t *bgep) 24891369Sdduvall { 24901369Sdduvall uint32_t regval; 24911369Sdduvall 24921369Sdduvall regval = bgep->param_msi_cnt<<4; 24931369Sdduvall bge_reg_set32(bgep, HOST_COALESCE_MODE_REG, regval); 24941369Sdduvall BGE_DEBUG(("bge_chip_msi_trig:data = %d", regval)); 24951369Sdduvall } 24961369Sdduvall 24971369Sdduvall /* 24981369Sdduvall * Various registers that control the chip's internal engines (state 24991369Sdduvall * machines) have a <reset> and <enable> bits (fortunately, in the 25001369Sdduvall * same place in each such register :-). 25011369Sdduvall * 25021369Sdduvall * To reset the state machine, the <reset> bit must be written with 1; 25031369Sdduvall * it will then read back as 1 while the reset is in progress, but 25041369Sdduvall * self-clear to 0 when the reset completes. 25051369Sdduvall * 25061369Sdduvall * To enable a state machine, one must set the <enable> bit, which 25071369Sdduvall * will continue to read back as 0 until the state machine is running. 25081369Sdduvall * 25091369Sdduvall * To disable a state machine, the <enable> bit must be cleared, but 25101369Sdduvall * it will continue to read back as 1 until the state machine actually 25111369Sdduvall * stops. 25121369Sdduvall * 25131369Sdduvall * This routine implements polling for completion of a reset, enable 25141369Sdduvall * or disable operation, returning B_TRUE on success (bit reached the 25151369Sdduvall * required state) or B_FALSE on timeout (200*100us == 20ms). 25161369Sdduvall */ 25171369Sdduvall static boolean_t bge_chip_poll_engine(bge_t *bgep, bge_regno_t regno, 25181369Sdduvall uint32_t mask, uint32_t val); 25191369Sdduvall #pragma no_inline(bge_chip_poll_engine) 25201369Sdduvall 25211369Sdduvall static boolean_t 25221369Sdduvall bge_chip_poll_engine(bge_t *bgep, bge_regno_t regno, 25231369Sdduvall uint32_t mask, uint32_t val) 25241369Sdduvall { 25251369Sdduvall uint32_t regval; 25261369Sdduvall uint32_t n; 25271369Sdduvall 25281369Sdduvall BGE_TRACE(("bge_chip_poll_engine($%p, 0x%lx, 0x%x, 0x%x)", 25294588Sml149210 (void *)bgep, regno, mask, val)); 25301369Sdduvall 25311369Sdduvall for (n = 200; n; --n) { 25321369Sdduvall regval = bge_reg_get32(bgep, regno); 25331369Sdduvall if ((regval & mask) == val) 25341369Sdduvall return (B_TRUE); 25351369Sdduvall drv_usecwait(100); 25361369Sdduvall } 25371369Sdduvall 25381865Sdilpreet bge_fm_ereport(bgep, DDI_FM_DEVICE_NO_RESPONSE); 25391369Sdduvall return (B_FALSE); 25401369Sdduvall } 25411369Sdduvall 25421369Sdduvall /* 25431369Sdduvall * Various registers that control the chip's internal engines (state 25441369Sdduvall * machines) have a <reset> bit (fortunately, in the same place in 25451369Sdduvall * each such register :-). To reset the state machine, this bit must 25461369Sdduvall * be written with 1; it will then read back as 1 while the reset is 25471369Sdduvall * in progress, but self-clear to 0 when the reset completes. 25481369Sdduvall * 25491369Sdduvall * This code sets the bit, then polls for it to read back as zero. 25501369Sdduvall * The return value is B_TRUE on success (reset bit cleared itself), 25511369Sdduvall * or B_FALSE if the state machine didn't recover :( 25521369Sdduvall * 25531369Sdduvall * NOTE: the Core reset is similar to other resets, except that we 25541369Sdduvall * can't poll for completion, since the Core reset disables memory 25551369Sdduvall * access! So we just have to assume that it will all complete in 25561369Sdduvall * 100us. See Broadcom document 570X-PG102-R, p102, steps 4-5. 25571369Sdduvall */ 25581369Sdduvall static boolean_t bge_chip_reset_engine(bge_t *bgep, bge_regno_t regno); 25591369Sdduvall #pragma no_inline(bge_chip_reset_engine) 25601369Sdduvall 25611369Sdduvall static boolean_t 25621369Sdduvall bge_chip_reset_engine(bge_t *bgep, bge_regno_t regno) 25631369Sdduvall { 25641369Sdduvall uint32_t regval; 25651369Sdduvall uint32_t val32; 25661369Sdduvall 25671369Sdduvall regval = bge_reg_get32(bgep, regno); 25681369Sdduvall 25691369Sdduvall BGE_TRACE(("bge_chip_reset_engine($%p, 0x%lx)", 25704588Sml149210 (void *)bgep, regno)); 25711369Sdduvall BGE_DEBUG(("bge_chip_reset_engine: 0x%lx before reset = 0x%08x", 25724588Sml149210 regno, regval)); 25731369Sdduvall 25741369Sdduvall regval |= STATE_MACHINE_RESET_BIT; 25751369Sdduvall 25761369Sdduvall switch (regno) { 25771369Sdduvall case MISC_CONFIG_REG: 25781369Sdduvall /* 25791369Sdduvall * BCM5714/5721/5751 pcie chip special case. In order to avoid 25801369Sdduvall * resetting PCIE block and bringing PCIE link down, bit 29 25811369Sdduvall * in the register needs to be set first, and then set it again 25821369Sdduvall * while the reset bit is written. 25831369Sdduvall * See:P500 of 57xx-PG102-RDS.pdf. 25841369Sdduvall */ 25851369Sdduvall if (DEVICE_5705_SERIES_CHIPSETS(bgep)|| 25861369Sdduvall DEVICE_5721_SERIES_CHIPSETS(bgep)|| 25879042SYong.Tan@Sun.COM DEVICE_5723_SERIES_CHIPSETS(bgep)|| 25887678SYong.Tan@Sun.COM DEVICE_5714_SERIES_CHIPSETS(bgep)|| 25897678SYong.Tan@Sun.COM DEVICE_5906_SERIES_CHIPSETS(bgep)) { 25901369Sdduvall regval |= MISC_CONFIG_GPHY_POWERDOWN_OVERRIDE; 25911369Sdduvall if (bgep->chipid.pci_type == BGE_PCI_E) { 25921369Sdduvall if (bgep->chipid.asic_rev == 25931369Sdduvall MHCR_CHIP_REV_5751_A0 || 25941369Sdduvall bgep->chipid.asic_rev == 25954330Sml149210 MHCR_CHIP_REV_5721_A0 || 25964330Sml149210 bgep->chipid.asic_rev == 25974330Sml149210 MHCR_CHIP_REV_5755_A0) { 25981369Sdduvall val32 = bge_reg_get32(bgep, 25991369Sdduvall PHY_TEST_CTRL_REG); 26001369Sdduvall if (val32 == (PHY_PCIE_SCRAM_MODE | 26011369Sdduvall PHY_PCIE_LTASS_MODE)) 26021369Sdduvall bge_reg_put32(bgep, 26031369Sdduvall PHY_TEST_CTRL_REG, 26041369Sdduvall PHY_PCIE_SCRAM_MODE); 26051369Sdduvall val32 = pci_config_get32 26061369Sdduvall (bgep->cfg_handle, 26071369Sdduvall PCI_CONF_BGE_CLKCTL); 26081369Sdduvall val32 |= CLKCTL_PCIE_A0_FIX; 26091369Sdduvall pci_config_put32(bgep->cfg_handle, 26101369Sdduvall PCI_CONF_BGE_CLKCTL, val32); 26111369Sdduvall } 26121369Sdduvall bge_reg_set32(bgep, regno, 26134588Sml149210 MISC_CONFIG_GRC_RESET_DISABLE); 26141369Sdduvall regval |= MISC_CONFIG_GRC_RESET_DISABLE; 26151369Sdduvall } 26161369Sdduvall } 26171369Sdduvall 26181369Sdduvall /* 26191369Sdduvall * Special case - causes Core reset 26201369Sdduvall * 26211369Sdduvall * On SPARC v9 we want to ensure that we don't start 26221369Sdduvall * timing until the I/O access has actually reached 26231369Sdduvall * the chip, otherwise we might make the next access 26241369Sdduvall * too early. And we can't just force the write out 26251369Sdduvall * by following it with a read (even to config space) 26261369Sdduvall * because that would cause the fault we're trying 26271369Sdduvall * to avoid. Hence the need for membar_sync() here. 26281369Sdduvall */ 26291369Sdduvall ddi_put32(bgep->io_handle, PIO_ADDR(bgep, regno), regval); 26301369Sdduvall #ifdef __sparcv9 26311369Sdduvall membar_sync(); 26321369Sdduvall #endif /* __sparcv9 */ 26331369Sdduvall /* 26341369Sdduvall * On some platforms,system need about 300us for 26351369Sdduvall * link setup. 26361369Sdduvall */ 26371369Sdduvall drv_usecwait(300); 26387678SYong.Tan@Sun.COM if (DEVICE_5906_SERIES_CHIPSETS(bgep)) { 26397678SYong.Tan@Sun.COM bge_reg_set32(bgep, VCPU_STATUS_REG, VCPU_DRV_RESET); 26407678SYong.Tan@Sun.COM bge_reg_clr32( 26417678SYong.Tan@Sun.COM bgep, VCPU_EXT_CTL, VCPU_EXT_CTL_HALF); 26427678SYong.Tan@Sun.COM } 26431369Sdduvall 26441369Sdduvall if (bgep->chipid.pci_type == BGE_PCI_E) { 26451369Sdduvall /* PCI-E device need more reset time */ 26461369Sdduvall drv_usecwait(120000); 26471369Sdduvall 26481369Sdduvall /* Set PCIE max payload size and clear error status. */ 26492135Szh199473 if ((bgep->chipid.chip_label == 5721) || 26502135Szh199473 (bgep->chipid.chip_label == 5751) || 26512675Szh199473 (bgep->chipid.chip_label == 5752) || 26527678SYong.Tan@Sun.COM (bgep->chipid.chip_label == 5789) || 26537678SYong.Tan@Sun.COM (bgep->chipid.chip_label == 5906)) { 26541369Sdduvall pci_config_put16(bgep->cfg_handle, 26554588Sml149210 PCI_CONF_DEV_CTRL, READ_REQ_SIZE_MAX); 26561369Sdduvall pci_config_put16(bgep->cfg_handle, 26574588Sml149210 PCI_CONF_DEV_STUS, DEVICE_ERROR_STUS); 26581369Sdduvall } 26599042SYong.Tan@Sun.COM 26609165SYong.Tan@Sun.COM if ((bgep->chipid.chip_label == 5723) || 26619165SYong.Tan@Sun.COM (bgep->chipid.chip_label == 5761)) { 26629042SYong.Tan@Sun.COM pci_config_put16(bgep->cfg_handle, 26639042SYong.Tan@Sun.COM PCI_CONF_DEV_CTRL_5723, READ_REQ_SIZE_MAX); 26649042SYong.Tan@Sun.COM pci_config_put16(bgep->cfg_handle, 26659042SYong.Tan@Sun.COM PCI_CONF_DEV_STUS_5723, DEVICE_ERROR_STUS); 26669042SYong.Tan@Sun.COM } 26671369Sdduvall } 26681369Sdduvall 26691369Sdduvall BGE_PCICHK(bgep); 26701369Sdduvall return (B_TRUE); 26711369Sdduvall 26721369Sdduvall default: 26731369Sdduvall bge_reg_put32(bgep, regno, regval); 26741369Sdduvall return (bge_chip_poll_engine(bgep, regno, 26751865Sdilpreet STATE_MACHINE_RESET_BIT, 0)); 26761369Sdduvall } 26771369Sdduvall } 26781369Sdduvall 26791369Sdduvall /* 26801369Sdduvall * Various registers that control the chip's internal engines (state 26811369Sdduvall * machines) have an <enable> bit (fortunately, in the same place in 26821369Sdduvall * each such register :-). To stop the state machine, this bit must 26831369Sdduvall * be written with 0, then polled to see when the state machine has 26841369Sdduvall * actually stopped. 26851369Sdduvall * 26861369Sdduvall * The return value is B_TRUE on success (enable bit cleared), or 26871369Sdduvall * B_FALSE if the state machine didn't stop :( 26881369Sdduvall */ 26891369Sdduvall static boolean_t bge_chip_disable_engine(bge_t *bgep, bge_regno_t regno, 26901369Sdduvall uint32_t morebits); 26911369Sdduvall #pragma no_inline(bge_chip_disable_engine) 26921369Sdduvall 26931369Sdduvall static boolean_t 26941369Sdduvall bge_chip_disable_engine(bge_t *bgep, bge_regno_t regno, uint32_t morebits) 26951369Sdduvall { 26961369Sdduvall uint32_t regval; 26971369Sdduvall 26981369Sdduvall BGE_TRACE(("bge_chip_disable_engine($%p, 0x%lx, 0x%x)", 26994588Sml149210 (void *)bgep, regno, morebits)); 27001369Sdduvall 27011369Sdduvall switch (regno) { 27021369Sdduvall case FTQ_RESET_REG: 27031369Sdduvall /* 27043918Sml149210 * For Schumacher's bugfix CR6490108 27053918Sml149210 */ 27063918Sml149210 #ifdef BGE_IPMI_ASF 27073918Sml149210 #ifdef BGE_NETCONSOLE 27083918Sml149210 if (bgep->asf_enabled) 27093918Sml149210 return (B_TRUE); 27103918Sml149210 #endif 27113918Sml149210 #endif 27123918Sml149210 /* 27131369Sdduvall * Not quite like the others; it doesn't 27141369Sdduvall * have an <enable> bit, but instead we 27151369Sdduvall * have to set and then clear all the bits 27161369Sdduvall */ 27171369Sdduvall bge_reg_put32(bgep, regno, ~(uint32_t)0); 27181369Sdduvall drv_usecwait(100); 27191369Sdduvall bge_reg_put32(bgep, regno, 0); 27201369Sdduvall return (B_TRUE); 27211369Sdduvall 27221369Sdduvall default: 27231369Sdduvall regval = bge_reg_get32(bgep, regno); 27241369Sdduvall regval &= ~STATE_MACHINE_ENABLE_BIT; 27251369Sdduvall regval &= ~morebits; 27261369Sdduvall bge_reg_put32(bgep, regno, regval); 27271369Sdduvall return (bge_chip_poll_engine(bgep, regno, 27281865Sdilpreet STATE_MACHINE_ENABLE_BIT, 0)); 27291369Sdduvall } 27301369Sdduvall } 27311369Sdduvall 27321369Sdduvall /* 27331369Sdduvall * Various registers that control the chip's internal engines (state 27341369Sdduvall * machines) have an <enable> bit (fortunately, in the same place in 27351369Sdduvall * each such register :-). To start the state machine, this bit must 27361369Sdduvall * be written with 1, then polled to see when the state machine has 27371369Sdduvall * actually started. 27381369Sdduvall * 27391369Sdduvall * The return value is B_TRUE on success (enable bit set), or 27401369Sdduvall * B_FALSE if the state machine didn't start :( 27411369Sdduvall */ 27421369Sdduvall static boolean_t bge_chip_enable_engine(bge_t *bgep, bge_regno_t regno, 27431369Sdduvall uint32_t morebits); 27441369Sdduvall #pragma no_inline(bge_chip_enable_engine) 27451369Sdduvall 27461369Sdduvall static boolean_t 27471369Sdduvall bge_chip_enable_engine(bge_t *bgep, bge_regno_t regno, uint32_t morebits) 27481369Sdduvall { 27491369Sdduvall uint32_t regval; 27501369Sdduvall 27511369Sdduvall BGE_TRACE(("bge_chip_enable_engine($%p, 0x%lx, 0x%x)", 27524588Sml149210 (void *)bgep, regno, morebits)); 27531369Sdduvall 27541369Sdduvall switch (regno) { 27551369Sdduvall case FTQ_RESET_REG: 27563918Sml149210 #ifdef BGE_IPMI_ASF 27573918Sml149210 #ifdef BGE_NETCONSOLE 27583918Sml149210 if (bgep->asf_enabled) 27593918Sml149210 return (B_TRUE); 27603918Sml149210 #endif 27613918Sml149210 #endif 27621369Sdduvall /* 27631369Sdduvall * Not quite like the others; it doesn't 27641369Sdduvall * have an <enable> bit, but instead we 27651369Sdduvall * have to set and then clear all the bits 27661369Sdduvall */ 27671369Sdduvall bge_reg_put32(bgep, regno, ~(uint32_t)0); 27681369Sdduvall drv_usecwait(100); 27691369Sdduvall bge_reg_put32(bgep, regno, 0); 27701369Sdduvall return (B_TRUE); 27711369Sdduvall 27721369Sdduvall default: 27731369Sdduvall regval = bge_reg_get32(bgep, regno); 27741369Sdduvall regval |= STATE_MACHINE_ENABLE_BIT; 27751369Sdduvall regval |= morebits; 27761369Sdduvall bge_reg_put32(bgep, regno, regval); 27771369Sdduvall return (bge_chip_poll_engine(bgep, regno, 27781865Sdilpreet STATE_MACHINE_ENABLE_BIT, STATE_MACHINE_ENABLE_BIT)); 27791369Sdduvall } 27801369Sdduvall } 27811369Sdduvall 27821369Sdduvall /* 27831369Sdduvall * Reprogram the Ethernet, Transmit, and Receive MAC 27841369Sdduvall * modes to match the param_* variables 27851369Sdduvall */ 27865903Ssowmini void bge_sync_mac_modes(bge_t *bgep); 27871369Sdduvall #pragma no_inline(bge_sync_mac_modes) 27881369Sdduvall 27895903Ssowmini void 27901369Sdduvall bge_sync_mac_modes(bge_t *bgep) 27911369Sdduvall { 27921369Sdduvall uint32_t macmode; 27931369Sdduvall uint32_t regval; 27941369Sdduvall 27951369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 27961369Sdduvall 27971369Sdduvall /* 27981369Sdduvall * Reprogram the Ethernet MAC mode ... 27991369Sdduvall */ 28001369Sdduvall macmode = regval = bge_reg_get32(bgep, ETHERNET_MAC_MODE_REG); 28011369Sdduvall if ((bgep->chipid.flags & CHIP_FLAG_SERDES) && 28024588Sml149210 (bgep->param_loop_mode != BGE_LOOP_INTERNAL_MAC)) 28037561SCrisson.Hu@Sun.COM if (DEVICE_5714_SERIES_CHIPSETS(bgep)) 28047561SCrisson.Hu@Sun.COM macmode |= ETHERNET_MODE_LINK_POLARITY; 28057561SCrisson.Hu@Sun.COM else 28067561SCrisson.Hu@Sun.COM macmode &= ~ETHERNET_MODE_LINK_POLARITY; 28071369Sdduvall else 28081369Sdduvall macmode |= ETHERNET_MODE_LINK_POLARITY; 28091369Sdduvall macmode &= ~ETHERNET_MODE_PORTMODE_MASK; 28101369Sdduvall if ((bgep->chipid.flags & CHIP_FLAG_SERDES) && 28117561SCrisson.Hu@Sun.COM (bgep->param_loop_mode != BGE_LOOP_INTERNAL_MAC)) { 28127561SCrisson.Hu@Sun.COM if (DEVICE_5714_SERIES_CHIPSETS(bgep)) 28137561SCrisson.Hu@Sun.COM macmode |= ETHERNET_MODE_PORTMODE_GMII; 28147561SCrisson.Hu@Sun.COM else 28157561SCrisson.Hu@Sun.COM macmode |= ETHERNET_MODE_PORTMODE_TBI; 28167561SCrisson.Hu@Sun.COM } else if (bgep->param_link_speed == 10 || 28177561SCrisson.Hu@Sun.COM bgep->param_link_speed == 100) 28181369Sdduvall macmode |= ETHERNET_MODE_PORTMODE_MII; 28191369Sdduvall else 28201369Sdduvall macmode |= ETHERNET_MODE_PORTMODE_GMII; 28211369Sdduvall if (bgep->param_link_duplex == LINK_DUPLEX_HALF) 28221369Sdduvall macmode |= ETHERNET_MODE_HALF_DUPLEX; 28231369Sdduvall else 28241369Sdduvall macmode &= ~ETHERNET_MODE_HALF_DUPLEX; 28251369Sdduvall if (bgep->param_loop_mode == BGE_LOOP_INTERNAL_MAC) 28261369Sdduvall macmode |= ETHERNET_MODE_MAC_LOOPBACK; 28271369Sdduvall else 28281369Sdduvall macmode &= ~ETHERNET_MODE_MAC_LOOPBACK; 28291369Sdduvall bge_reg_put32(bgep, ETHERNET_MAC_MODE_REG, macmode); 28301369Sdduvall BGE_DEBUG(("bge_sync_mac_modes($%p) Ethernet MAC mode 0x%x => 0x%x", 28314588Sml149210 (void *)bgep, regval, macmode)); 28321369Sdduvall 28331369Sdduvall /* 28341369Sdduvall * ... the Transmit MAC mode ... 28351369Sdduvall */ 28361369Sdduvall macmode = regval = bge_reg_get32(bgep, TRANSMIT_MAC_MODE_REG); 28371369Sdduvall if (bgep->param_link_tx_pause) 28381369Sdduvall macmode |= TRANSMIT_MODE_FLOW_CONTROL; 28391369Sdduvall else 28401369Sdduvall macmode &= ~TRANSMIT_MODE_FLOW_CONTROL; 28411369Sdduvall bge_reg_put32(bgep, TRANSMIT_MAC_MODE_REG, macmode); 28421369Sdduvall BGE_DEBUG(("bge_sync_mac_modes($%p) Transmit MAC mode 0x%x => 0x%x", 28434588Sml149210 (void *)bgep, regval, macmode)); 28441369Sdduvall 28451369Sdduvall /* 28461369Sdduvall * ... and the Receive MAC mode 28471369Sdduvall */ 28481369Sdduvall macmode = regval = bge_reg_get32(bgep, RECEIVE_MAC_MODE_REG); 28491369Sdduvall if (bgep->param_link_rx_pause) 28501369Sdduvall macmode |= RECEIVE_MODE_FLOW_CONTROL; 28511369Sdduvall else 28521369Sdduvall macmode &= ~RECEIVE_MODE_FLOW_CONTROL; 28531369Sdduvall bge_reg_put32(bgep, RECEIVE_MAC_MODE_REG, macmode); 28541369Sdduvall BGE_DEBUG(("bge_sync_mac_modes($%p) Receive MAC mode 0x%x => 0x%x", 28554588Sml149210 (void *)bgep, regval, macmode)); 2856*11479SYong.Tan@Sun.COM 2857*11479SYong.Tan@Sun.COM /* 2858*11479SYong.Tan@Sun.COM * For BCM5785, we need to configure the link status in the MI Status 2859*11479SYong.Tan@Sun.COM * register with a write command when auto-polling is disabled. 2860*11479SYong.Tan@Sun.COM */ 2861*11479SYong.Tan@Sun.COM if (bgep->chipid.device == DEVICE_ID_5785) 2862*11479SYong.Tan@Sun.COM if (bgep->param_link_speed == 10) 2863*11479SYong.Tan@Sun.COM bge_reg_put32(bgep, MI_STATUS_REG, MI_STATUS_LINK 2864*11479SYong.Tan@Sun.COM | MI_STATUS_10MBPS); 2865*11479SYong.Tan@Sun.COM else 2866*11479SYong.Tan@Sun.COM bge_reg_put32(bgep, MI_STATUS_REG, MI_STATUS_LINK); 28671369Sdduvall } 28681369Sdduvall 28691369Sdduvall /* 28701369Sdduvall * bge_chip_sync() -- program the chip with the unicast MAC address, 28711369Sdduvall * the multicast hash table, the required level of promiscuity, and 28721369Sdduvall * the current loopback mode ... 28731369Sdduvall */ 28741408Srandyf #ifdef BGE_IPMI_ASF 28751865Sdilpreet int bge_chip_sync(bge_t *bgep, boolean_t asf_keeplive); 28761408Srandyf #else 28771865Sdilpreet int bge_chip_sync(bge_t *bgep); 28781408Srandyf #endif 28791369Sdduvall #pragma no_inline(bge_chip_sync) 28801369Sdduvall 28811865Sdilpreet int 28821408Srandyf #ifdef BGE_IPMI_ASF 28831408Srandyf bge_chip_sync(bge_t *bgep, boolean_t asf_keeplive) 28841408Srandyf #else 28851369Sdduvall bge_chip_sync(bge_t *bgep) 28861408Srandyf #endif 28871369Sdduvall { 28881369Sdduvall void (*opfn)(bge_t *bgep, bge_regno_t reg, uint32_t bits); 28891369Sdduvall boolean_t promisc; 28901369Sdduvall uint64_t macaddr; 28918922SYong.Tan@Sun.COM uint32_t fill = 0; 28922331Skrgopi int i, j; 28931865Sdilpreet int retval = DDI_SUCCESS; 28941369Sdduvall 28951369Sdduvall BGE_TRACE(("bge_chip_sync($%p)", 28965903Ssowmini (void *)bgep)); 28971369Sdduvall 28981369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 28991369Sdduvall 29001369Sdduvall promisc = B_FALSE; 29011369Sdduvall fill = ~(uint32_t)0; 29021369Sdduvall 29031369Sdduvall if (bgep->promisc) 29041369Sdduvall promisc = B_TRUE; 29051369Sdduvall else 29061369Sdduvall fill = (uint32_t)0; 29071369Sdduvall 29081369Sdduvall /* 29091369Sdduvall * If the TX/RX MAC engines are already running, we should stop 29101369Sdduvall * them (and reset the RX engine) before changing the parameters. 29111369Sdduvall * If they're not running, this will have no effect ... 29121369Sdduvall * 29131369Sdduvall * NOTE: this is currently disabled by default because stopping 29141369Sdduvall * and restarting the Tx engine may cause an outgoing packet in 29151369Sdduvall * transit to be truncated. Also, stopping and restarting the 29161369Sdduvall * Rx engine seems to not work correctly on the 5705. Testing 29171369Sdduvall * has not (yet!) revealed any problems with NOT stopping and 29181369Sdduvall * restarting these engines (and Broadcom say their drivers don't 29191369Sdduvall * do this), but if it is found to cause problems, this variable 29201369Sdduvall * can be patched to re-enable the old behaviour ... 29211369Sdduvall */ 29221369Sdduvall if (bge_stop_start_on_sync) { 29231408Srandyf #ifdef BGE_IPMI_ASF 29241865Sdilpreet if (!bgep->asf_enabled) { 29251865Sdilpreet if (!bge_chip_disable_engine(bgep, 29261865Sdilpreet RECEIVE_MAC_MODE_REG, RECEIVE_MODE_KEEP_VLAN_TAG)) 29271865Sdilpreet retval = DDI_FAILURE; 29281408Srandyf } else { 29291865Sdilpreet if (!bge_chip_disable_engine(bgep, 29301865Sdilpreet RECEIVE_MAC_MODE_REG, 0)) 29311865Sdilpreet retval = DDI_FAILURE; 29321408Srandyf } 29331408Srandyf #else 29341865Sdilpreet if (!bge_chip_disable_engine(bgep, RECEIVE_MAC_MODE_REG, 29351865Sdilpreet RECEIVE_MODE_KEEP_VLAN_TAG)) 29361865Sdilpreet retval = DDI_FAILURE; 29371408Srandyf #endif 29381865Sdilpreet if (!bge_chip_disable_engine(bgep, TRANSMIT_MAC_MODE_REG, 0)) 29391865Sdilpreet retval = DDI_FAILURE; 29401865Sdilpreet if (!bge_chip_reset_engine(bgep, RECEIVE_MAC_MODE_REG)) 29411865Sdilpreet retval = DDI_FAILURE; 29421369Sdduvall } 29431369Sdduvall 29441369Sdduvall /* 29451369Sdduvall * Reprogram the hashed multicast address table ... 29461369Sdduvall */ 29471369Sdduvall for (i = 0; i < BGE_HASH_TABLE_SIZE/32; ++i) 29486546Sgh162552 bge_reg_put32(bgep, MAC_HASH_REG(i), 0); 29496546Sgh162552 29506546Sgh162552 for (i = 0; i < BGE_HASH_TABLE_SIZE/32; ++i) 29511369Sdduvall bge_reg_put32(bgep, MAC_HASH_REG(i), 29521369Sdduvall bgep->mcast_hash[i] | fill); 29531369Sdduvall 29541408Srandyf #ifdef BGE_IPMI_ASF 29551408Srandyf if (!bgep->asf_enabled || !asf_keeplive) { 29561408Srandyf #endif 29571408Srandyf /* 29582331Skrgopi * Transform the MAC address(es) from host to chip format, then 29591408Srandyf * reprogram the transmit random backoff seed and the unicast 29601408Srandyf * MAC address(es) ... 29611408Srandyf */ 29622331Skrgopi for (j = 0; j < MAC_ADDRESS_REGS_MAX; j++) { 29638922SYong.Tan@Sun.COM for (i = 0, macaddr = 0ull; 29642331Skrgopi i < ETHERADDRL; ++i) { 29652331Skrgopi macaddr <<= 8; 29662331Skrgopi macaddr |= bgep->curr_addr[j].addr[i]; 29672331Skrgopi } 29688922SYong.Tan@Sun.COM fill += (macaddr >> 16) + (macaddr & 0xffffffff); 29692331Skrgopi bge_reg_put64(bgep, MAC_ADDRESS_REG(j), macaddr); 29708275SEric Cheng 29718275SEric Cheng BGE_DEBUG(("bge_chip_sync($%p) " 29728275SEric Cheng "setting MAC address %012llx", 29738275SEric Cheng (void *)bgep, macaddr)); 29741408Srandyf } 29751408Srandyf #ifdef BGE_IPMI_ASF 29761369Sdduvall } 29771408Srandyf #endif 29788922SYong.Tan@Sun.COM /* 29798922SYong.Tan@Sun.COM * Set random seed of backoff interval 29808922SYong.Tan@Sun.COM * - Writing zero means no backoff interval 29818922SYong.Tan@Sun.COM */ 29828922SYong.Tan@Sun.COM fill = ((fill >> 20) + (fill >> 10) + fill) & 0x3ff; 29838922SYong.Tan@Sun.COM if (fill == 0) 29848922SYong.Tan@Sun.COM fill = 1; 29858922SYong.Tan@Sun.COM bge_reg_put32(bgep, MAC_TX_RANDOM_BACKOFF_REG, fill); 29861369Sdduvall 29871369Sdduvall /* 29881369Sdduvall * Set or clear the PROMISCUOUS mode bit 29891369Sdduvall */ 29901369Sdduvall opfn = promisc ? bge_reg_set32 : bge_reg_clr32; 29911369Sdduvall (*opfn)(bgep, RECEIVE_MAC_MODE_REG, RECEIVE_MODE_PROMISCUOUS); 29921369Sdduvall 29931369Sdduvall /* 29941369Sdduvall * Sync the rest of the MAC modes too ... 29951369Sdduvall */ 29961369Sdduvall bge_sync_mac_modes(bgep); 29971369Sdduvall 29981369Sdduvall /* 29991369Sdduvall * Restart RX/TX MAC engines if required ... 30001369Sdduvall */ 30011369Sdduvall if (bgep->bge_chip_state == BGE_CHIP_RUNNING) { 30021865Sdilpreet if (!bge_chip_enable_engine(bgep, TRANSMIT_MAC_MODE_REG, 0)) 30031865Sdilpreet retval = DDI_FAILURE; 30041408Srandyf #ifdef BGE_IPMI_ASF 30051865Sdilpreet if (!bgep->asf_enabled) { 30061865Sdilpreet if (!bge_chip_enable_engine(bgep, 30071865Sdilpreet RECEIVE_MAC_MODE_REG, RECEIVE_MODE_KEEP_VLAN_TAG)) 30081865Sdilpreet retval = DDI_FAILURE; 30091408Srandyf } else { 30101865Sdilpreet if (!bge_chip_enable_engine(bgep, 30111865Sdilpreet RECEIVE_MAC_MODE_REG, 0)) 30121865Sdilpreet retval = DDI_FAILURE; 30131408Srandyf } 30141408Srandyf #else 30151865Sdilpreet if (!bge_chip_enable_engine(bgep, RECEIVE_MAC_MODE_REG, 30161865Sdilpreet RECEIVE_MODE_KEEP_VLAN_TAG)) 30171865Sdilpreet retval = DDI_FAILURE; 30181408Srandyf #endif 30191369Sdduvall } 30201865Sdilpreet return (retval); 30211369Sdduvall } 30221369Sdduvall 30231369Sdduvall /* 30241369Sdduvall * This array defines the sequence of state machine control registers 30251369Sdduvall * in which the <enable> bit must be cleared to bring the chip to a 30261369Sdduvall * clean stop. Taken from Broadcom document 570X-PG102-R, p116. 30271369Sdduvall */ 30281369Sdduvall static bge_regno_t shutdown_engine_regs[] = { 30291369Sdduvall RECEIVE_MAC_MODE_REG, 30301369Sdduvall RCV_BD_INITIATOR_MODE_REG, 30311369Sdduvall RCV_LIST_PLACEMENT_MODE_REG, 30321369Sdduvall RCV_LIST_SELECTOR_MODE_REG, /* BCM5704 series only */ 30331369Sdduvall RCV_DATA_BD_INITIATOR_MODE_REG, 30341369Sdduvall RCV_DATA_COMPLETION_MODE_REG, 30351369Sdduvall RCV_BD_COMPLETION_MODE_REG, 30361369Sdduvall 30371369Sdduvall SEND_BD_SELECTOR_MODE_REG, 30381369Sdduvall SEND_BD_INITIATOR_MODE_REG, 30391369Sdduvall SEND_DATA_INITIATOR_MODE_REG, 30401369Sdduvall READ_DMA_MODE_REG, 30411369Sdduvall SEND_DATA_COMPLETION_MODE_REG, 30421369Sdduvall DMA_COMPLETION_MODE_REG, /* BCM5704 series only */ 30431369Sdduvall SEND_BD_COMPLETION_MODE_REG, 30441369Sdduvall TRANSMIT_MAC_MODE_REG, 30451369Sdduvall 30461369Sdduvall HOST_COALESCE_MODE_REG, 30471369Sdduvall WRITE_DMA_MODE_REG, 30481369Sdduvall MBUF_CLUSTER_FREE_MODE_REG, /* BCM5704 series only */ 30491369Sdduvall FTQ_RESET_REG, /* special - see code */ 30501369Sdduvall BUFFER_MANAGER_MODE_REG, /* BCM5704 series only */ 30511369Sdduvall MEMORY_ARBITER_MODE_REG, /* BCM5704 series only */ 30521369Sdduvall BGE_REGNO_NONE /* terminator */ 30531369Sdduvall }; 30541369Sdduvall 30557656SSherry.Moore@Sun.COM #ifndef __sparc 30567656SSherry.Moore@Sun.COM static bge_regno_t quiesce_regs[] = { 30577656SSherry.Moore@Sun.COM READ_DMA_MODE_REG, 30587656SSherry.Moore@Sun.COM DMA_COMPLETION_MODE_REG, 30597656SSherry.Moore@Sun.COM WRITE_DMA_MODE_REG, 30607656SSherry.Moore@Sun.COM BGE_REGNO_NONE 30617656SSherry.Moore@Sun.COM }; 30627656SSherry.Moore@Sun.COM 30637656SSherry.Moore@Sun.COM void bge_chip_stop_nonblocking(bge_t *bgep); 30647656SSherry.Moore@Sun.COM #pragma no_inline(bge_chip_stop_nonblocking) 30657656SSherry.Moore@Sun.COM 30667656SSherry.Moore@Sun.COM /* 30677656SSherry.Moore@Sun.COM * This function is called by bge_quiesce(). We 30687656SSherry.Moore@Sun.COM * turn off all the DMA engines here. 30697656SSherry.Moore@Sun.COM */ 30707656SSherry.Moore@Sun.COM void 30717656SSherry.Moore@Sun.COM bge_chip_stop_nonblocking(bge_t *bgep) 30727656SSherry.Moore@Sun.COM { 30737656SSherry.Moore@Sun.COM bge_regno_t *rbp; 30747656SSherry.Moore@Sun.COM 30757656SSherry.Moore@Sun.COM /* 30767656SSherry.Moore@Sun.COM * Flag that no more activity may be initiated 30777656SSherry.Moore@Sun.COM */ 30787656SSherry.Moore@Sun.COM bgep->progress &= ~PROGRESS_READY; 30797656SSherry.Moore@Sun.COM 30807656SSherry.Moore@Sun.COM rbp = quiesce_regs; 30817656SSherry.Moore@Sun.COM while (*rbp != BGE_REGNO_NONE) { 30827656SSherry.Moore@Sun.COM (void) bge_chip_disable_engine(bgep, *rbp, 0); 30837656SSherry.Moore@Sun.COM ++rbp; 30847656SSherry.Moore@Sun.COM } 30857656SSherry.Moore@Sun.COM 30867656SSherry.Moore@Sun.COM bgep->bge_chip_state = BGE_CHIP_STOPPED; 30877656SSherry.Moore@Sun.COM } 30887656SSherry.Moore@Sun.COM 30897656SSherry.Moore@Sun.COM #endif 30907656SSherry.Moore@Sun.COM 30911369Sdduvall /* 30921369Sdduvall * bge_chip_stop() -- stop all chip processing 30931369Sdduvall * 30941369Sdduvall * If the <fault> parameter is B_TRUE, we're stopping the chip because 30951369Sdduvall * we've detected a problem internally; otherwise, this is a normal 30961369Sdduvall * (clean) stop (at user request i.e. the last STREAM has been closed). 30971369Sdduvall */ 30981369Sdduvall void bge_chip_stop(bge_t *bgep, boolean_t fault); 30991369Sdduvall #pragma no_inline(bge_chip_stop) 31001369Sdduvall 31011369Sdduvall void 31021369Sdduvall bge_chip_stop(bge_t *bgep, boolean_t fault) 31031369Sdduvall { 31041369Sdduvall bge_regno_t regno; 31051369Sdduvall bge_regno_t *rbp; 31061369Sdduvall boolean_t ok; 31071369Sdduvall 31081369Sdduvall BGE_TRACE(("bge_chip_stop($%p)", 31094588Sml149210 (void *)bgep)); 31101369Sdduvall 31111369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 31121369Sdduvall 31131369Sdduvall rbp = shutdown_engine_regs; 31141369Sdduvall /* 31151369Sdduvall * When driver try to shutdown the BCM5705/5788/5721/5751/ 31161369Sdduvall * 5752/5714 and 5715 chipsets,the buffer manager and the mem 31171369Sdduvall * -ory arbiter should not be disabled. 31181369Sdduvall */ 31191369Sdduvall for (ok = B_TRUE; (regno = *rbp) != BGE_REGNO_NONE; ++rbp) { 31201369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) 31214588Sml149210 ok &= bge_chip_disable_engine(bgep, regno, 0); 31221369Sdduvall else if ((regno != RCV_LIST_SELECTOR_MODE_REG) && 31234588Sml149210 (regno != DMA_COMPLETION_MODE_REG) && 31244588Sml149210 (regno != MBUF_CLUSTER_FREE_MODE_REG)&& 31254588Sml149210 (regno != BUFFER_MANAGER_MODE_REG) && 31264588Sml149210 (regno != MEMORY_ARBITER_MODE_REG)) 31274588Sml149210 ok &= bge_chip_disable_engine(bgep, 31284588Sml149210 regno, 0); 31291369Sdduvall } 31301369Sdduvall 31311865Sdilpreet if (!ok && !fault) 31321865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_UNAFFECTED); 31331865Sdilpreet 31341369Sdduvall /* 31351369Sdduvall * Finally, disable (all) MAC events & clear the MAC status 31361369Sdduvall */ 31371369Sdduvall bge_reg_put32(bgep, ETHERNET_MAC_EVENT_ENABLE_REG, 0); 31381369Sdduvall bge_reg_put32(bgep, ETHERNET_MAC_STATUS_REG, ~0); 31391369Sdduvall 31401369Sdduvall /* 31411865Sdilpreet * if we're stopping the chip because of a detected fault then do 31421865Sdilpreet * appropriate actions 31431369Sdduvall */ 31441865Sdilpreet if (fault) { 31451865Sdilpreet if (bgep->bge_chip_state != BGE_CHIP_FAULT) { 31461865Sdilpreet bgep->bge_chip_state = BGE_CHIP_FAULT; 31475903Ssowmini if (!bgep->manual_reset) 31485903Ssowmini ddi_fm_service_impact(bgep->devinfo, 31495903Ssowmini DDI_SERVICE_LOST); 31501865Sdilpreet if (bgep->bge_dma_error) { 31511865Sdilpreet /* 31521865Sdilpreet * need to free buffers in case the fault was 31531865Sdilpreet * due to a memory error in a buffer - got to 31541865Sdilpreet * do a fair bit of tidying first 31551865Sdilpreet */ 31561865Sdilpreet if (bgep->progress & PROGRESS_KSTATS) { 31571865Sdilpreet bge_fini_kstats(bgep); 31581865Sdilpreet bgep->progress &= ~PROGRESS_KSTATS; 31591865Sdilpreet } 31601865Sdilpreet if (bgep->progress & PROGRESS_INTR) { 31611865Sdilpreet bge_intr_disable(bgep); 31621865Sdilpreet rw_enter(bgep->errlock, RW_WRITER); 31631865Sdilpreet bge_fini_rings(bgep); 31641865Sdilpreet rw_exit(bgep->errlock); 31651865Sdilpreet bgep->progress &= ~PROGRESS_INTR; 31661865Sdilpreet } 31671865Sdilpreet if (bgep->progress & PROGRESS_BUFS) { 31681865Sdilpreet bge_free_bufs(bgep); 31691865Sdilpreet bgep->progress &= ~PROGRESS_BUFS; 31701865Sdilpreet } 31711865Sdilpreet bgep->bge_dma_error = B_FALSE; 31721865Sdilpreet } 31731865Sdilpreet } 31741865Sdilpreet } else 31751369Sdduvall bgep->bge_chip_state = BGE_CHIP_STOPPED; 31761369Sdduvall } 31771369Sdduvall 31781369Sdduvall /* 31791369Sdduvall * Poll for completion of chip's ROM firmware; also, at least on the 31801369Sdduvall * first time through, find and return the hardware MAC address, if any. 31811369Sdduvall */ 31821369Sdduvall static uint64_t bge_poll_firmware(bge_t *bgep); 31831369Sdduvall #pragma no_inline(bge_poll_firmware) 31841369Sdduvall 31851369Sdduvall static uint64_t 31861369Sdduvall bge_poll_firmware(bge_t *bgep) 31871369Sdduvall { 31881369Sdduvall uint64_t magic; 31891369Sdduvall uint64_t mac; 31907678SYong.Tan@Sun.COM uint32_t gen, val; 31911369Sdduvall uint32_t i; 31921369Sdduvall 31931369Sdduvall /* 31941369Sdduvall * Step 19: poll for firmware completion (GENCOMM port set 31951369Sdduvall * to the ones complement of T3_MAGIC_NUMBER). 31961369Sdduvall * 31971369Sdduvall * While we're at it, we also read the MAC address register; 31982135Szh199473 * at some stage the firmware will load this with the 31991369Sdduvall * factory-set value. 32001369Sdduvall * 32011369Sdduvall * When both the magic number and the MAC address are set, 32021369Sdduvall * we're done; but we impose a time limit of one second 32031369Sdduvall * (1000*1000us) in case the firmware fails in some fashion 32041369Sdduvall * or the SEEPROM that provides that MAC address isn't fitted. 32051369Sdduvall * 32061369Sdduvall * After the first time through (chip state != INITIAL), we 32071369Sdduvall * don't need the MAC address to be set (we've already got it 32081369Sdduvall * or not, from the first time), so we don't wait for it, but 32091369Sdduvall * we still have to wait for the T3_MAGIC_NUMBER. 32101369Sdduvall * 32111369Sdduvall * Note: the magic number is only a 32-bit quantity, but the NIC 32121369Sdduvall * memory is 64-bit (and big-endian) internally. Addressing the 32131369Sdduvall * GENCOMM word as "the upper half of a 64-bit quantity" makes 32141369Sdduvall * it work correctly on both big- and little-endian hosts. 32151369Sdduvall */ 32167678SYong.Tan@Sun.COM if (MHCR_CHIP_ASIC_REV(bgep->chipid.asic_rev) == 32177678SYong.Tan@Sun.COM MHCR_CHIP_ASIC_REV_5906) { 32187678SYong.Tan@Sun.COM for (i = 0; i < 1000; ++i) { 32197678SYong.Tan@Sun.COM drv_usecwait(1000); 32207678SYong.Tan@Sun.COM val = bge_reg_get32(bgep, VCPU_STATUS_REG); 32217678SYong.Tan@Sun.COM if (val & VCPU_INIT_DONE) 32227678SYong.Tan@Sun.COM break; 32237678SYong.Tan@Sun.COM } 32247678SYong.Tan@Sun.COM BGE_DEBUG(("bge_poll_firmware($%p): return after %d loops", 32257678SYong.Tan@Sun.COM (void *)bgep, i)); 32261369Sdduvall mac = bge_reg_get64(bgep, MAC_ADDRESS_REG(0)); 32277678SYong.Tan@Sun.COM } else { 32287678SYong.Tan@Sun.COM for (i = 0; i < 1000; ++i) { 32297678SYong.Tan@Sun.COM drv_usecwait(1000); 32307678SYong.Tan@Sun.COM gen = bge_nic_get64(bgep, NIC_MEM_GENCOMM) >> 32; 32317678SYong.Tan@Sun.COM if (i == 0 && DEVICE_5704_SERIES_CHIPSETS(bgep)) 32327678SYong.Tan@Sun.COM drv_usecwait(100000); 32337678SYong.Tan@Sun.COM mac = bge_reg_get64(bgep, MAC_ADDRESS_REG(0)); 32341408Srandyf #ifdef BGE_IPMI_ASF 32357678SYong.Tan@Sun.COM if (!bgep->asf_enabled) { 32361408Srandyf #endif 32377678SYong.Tan@Sun.COM if (gen != ~T3_MAGIC_NUMBER) 32387678SYong.Tan@Sun.COM continue; 32391408Srandyf #ifdef BGE_IPMI_ASF 32407678SYong.Tan@Sun.COM } 32411408Srandyf #endif 32427678SYong.Tan@Sun.COM if (mac != 0ULL) 32437678SYong.Tan@Sun.COM break; 32447678SYong.Tan@Sun.COM if (bgep->bge_chip_state != BGE_CHIP_INITIAL) 32457678SYong.Tan@Sun.COM break; 32467678SYong.Tan@Sun.COM } 32471369Sdduvall } 32481369Sdduvall 32491369Sdduvall magic = bge_nic_get64(bgep, NIC_MEM_GENCOMM); 32501369Sdduvall BGE_DEBUG(("bge_poll_firmware($%p): PXE magic 0x%x after %d loops", 32514588Sml149210 (void *)bgep, gen, i)); 32521369Sdduvall BGE_DEBUG(("bge_poll_firmware: MAC %016llx, GENCOMM %016llx", 32534588Sml149210 mac, magic)); 32541369Sdduvall 32551369Sdduvall return (mac); 32561369Sdduvall } 32571369Sdduvall 32583390Szh199473 /* 32593390Szh199473 * Maximum times of trying to get the NVRAM access lock 32603390Szh199473 * by calling bge_nvmem_acquire() 32613390Szh199473 */ 32623390Szh199473 #define MAX_TRY_NVMEM_ACQUIRE 10000 32633390Szh199473 32641408Srandyf #ifdef BGE_IPMI_ASF 32651865Sdilpreet int bge_chip_reset(bge_t *bgep, boolean_t enable_dma, uint_t asf_mode); 32661408Srandyf #else 32671865Sdilpreet int bge_chip_reset(bge_t *bgep, boolean_t enable_dma); 32681408Srandyf #endif 32691369Sdduvall #pragma no_inline(bge_chip_reset) 32701369Sdduvall 32711865Sdilpreet int 32721408Srandyf #ifdef BGE_IPMI_ASF 32731408Srandyf bge_chip_reset(bge_t *bgep, boolean_t enable_dma, uint_t asf_mode) 32741408Srandyf #else 32751369Sdduvall bge_chip_reset(bge_t *bgep, boolean_t enable_dma) 32761408Srandyf #endif 32771369Sdduvall { 32781369Sdduvall chip_id_t chipid; 32791369Sdduvall uint64_t mac; 32801908Sly149593 uint64_t magic; 32811369Sdduvall uint32_t modeflags; 32821369Sdduvall uint32_t mhcr; 32831369Sdduvall uint32_t sx0; 32843390Szh199473 uint32_t i, tries; 32851408Srandyf #ifdef BGE_IPMI_ASF 32861408Srandyf uint32_t mailbox; 32871408Srandyf #endif 32881865Sdilpreet int retval = DDI_SUCCESS; 32891369Sdduvall 32901369Sdduvall BGE_TRACE(("bge_chip_reset($%p, %d)", 32911369Sdduvall (void *)bgep, enable_dma)); 32921369Sdduvall 32931369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 32941369Sdduvall 32951369Sdduvall BGE_DEBUG(("bge_chip_reset($%p, %d): current state is %d", 32961369Sdduvall (void *)bgep, enable_dma, bgep->bge_chip_state)); 32971369Sdduvall 32981369Sdduvall /* 32991369Sdduvall * Do we need to stop the chip cleanly before resetting? 33001369Sdduvall */ 33011369Sdduvall switch (bgep->bge_chip_state) { 33021369Sdduvall default: 33031369Sdduvall _NOTE(NOTREACHED) 33041865Sdilpreet return (DDI_FAILURE); 33051369Sdduvall 33061369Sdduvall case BGE_CHIP_INITIAL: 33071369Sdduvall case BGE_CHIP_STOPPED: 33081369Sdduvall case BGE_CHIP_RESET: 33091369Sdduvall break; 33101369Sdduvall 33111369Sdduvall case BGE_CHIP_RUNNING: 33121369Sdduvall case BGE_CHIP_ERROR: 33131369Sdduvall case BGE_CHIP_FAULT: 33141369Sdduvall bge_chip_stop(bgep, B_FALSE); 33151369Sdduvall break; 33161369Sdduvall } 33171369Sdduvall 33181408Srandyf #ifdef BGE_IPMI_ASF 33191408Srandyf if (bgep->asf_enabled) { 33203918Sml149210 #ifdef __sparc 33213918Sml149210 mhcr = MHCR_ENABLE_INDIRECT_ACCESS | 33223918Sml149210 MHCR_ENABLE_TAGGED_STATUS_MODE | 33233918Sml149210 MHCR_MASK_INTERRUPT_MODE | 33243918Sml149210 MHCR_MASK_PCI_INT_OUTPUT | 33253918Sml149210 MHCR_CLEAR_INTERRUPT_INTA | 33263918Sml149210 MHCR_ENABLE_ENDIAN_WORD_SWAP | 33273918Sml149210 MHCR_ENABLE_ENDIAN_BYTE_SWAP; 33283918Sml149210 pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_MHCR, mhcr); 33293918Sml149210 bge_reg_put32(bgep, MEMORY_ARBITER_MODE_REG, 33303918Sml149210 bge_reg_get32(bgep, MEMORY_ARBITER_MODE_REG) | 33313918Sml149210 MEMORY_ARBITER_ENABLE); 33323918Sml149210 #endif 33331408Srandyf if (asf_mode == ASF_MODE_INIT) { 33341408Srandyf bge_asf_pre_reset_operations(bgep, BGE_INIT_RESET); 33351408Srandyf } else if (asf_mode == ASF_MODE_SHUTDOWN) { 33361408Srandyf bge_asf_pre_reset_operations(bgep, BGE_SHUTDOWN_RESET); 33371408Srandyf } 33381408Srandyf } 33391408Srandyf #endif 33401369Sdduvall /* 33411369Sdduvall * Adapted from Broadcom document 570X-PG102-R, pp 102-116. 33421369Sdduvall * Updated to reflect Broadcom document 570X-PG104-R, pp 146-159. 33431369Sdduvall * 33441369Sdduvall * Before reset Core clock,it is 33451369Sdduvall * also required to initialize the Memory Arbiter as specified in step9 33461369Sdduvall * and Misc Host Control Register as specified in step-13 33471369Sdduvall * Step 4-5: reset Core clock & wait for completion 33481369Sdduvall * Steps 6-8: are done by bge_chip_cfg_init() 33491908Sly149593 * put the T3_MAGIC_NUMBER into the GENCOMM port before reset 33501369Sdduvall */ 33511865Sdilpreet if (!bge_chip_enable_engine(bgep, MEMORY_ARBITER_MODE_REG, 0)) 33521865Sdilpreet retval = DDI_FAILURE; 33531369Sdduvall 33541369Sdduvall mhcr = MHCR_ENABLE_INDIRECT_ACCESS | 33551369Sdduvall MHCR_ENABLE_TAGGED_STATUS_MODE | 33561369Sdduvall MHCR_MASK_INTERRUPT_MODE | 33571369Sdduvall MHCR_MASK_PCI_INT_OUTPUT | 33581369Sdduvall MHCR_CLEAR_INTERRUPT_INTA; 33591369Sdduvall #ifdef _BIG_ENDIAN 33601369Sdduvall mhcr |= MHCR_ENABLE_ENDIAN_WORD_SWAP | MHCR_ENABLE_ENDIAN_BYTE_SWAP; 33611369Sdduvall #endif /* _BIG_ENDIAN */ 33621369Sdduvall pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_MHCR, mhcr); 33631408Srandyf #ifdef BGE_IPMI_ASF 33641408Srandyf if (bgep->asf_enabled) 33651408Srandyf bgep->asf_wordswapped = B_FALSE; 33661408Srandyf #endif 33672675Szh199473 /* 33682675Szh199473 * NVRAM Corruption Workaround 33692675Szh199473 */ 33703390Szh199473 for (tries = 0; tries < MAX_TRY_NVMEM_ACQUIRE; tries++) 33713534Szh199473 if (bge_nvmem_acquire(bgep) != EAGAIN) 33722675Szh199473 break; 33733440Szh199473 if (tries >= MAX_TRY_NVMEM_ACQUIRE) 33742675Szh199473 BGE_DEBUG(("%s: fail to acquire nvram lock", 33752675Szh199473 bgep->ifname)); 33762675Szh199473 33771908Sly149593 #ifdef BGE_IPMI_ASF 33781908Sly149593 if (!bgep->asf_enabled) { 33791908Sly149593 #endif 33801908Sly149593 magic = (uint64_t)T3_MAGIC_NUMBER << 32; 33811908Sly149593 bge_nic_put64(bgep, NIC_MEM_GENCOMM, magic); 33821908Sly149593 #ifdef BGE_IPMI_ASF 33831908Sly149593 } 33841908Sly149593 #endif 33851908Sly149593 33861865Sdilpreet if (!bge_chip_reset_engine(bgep, MISC_CONFIG_REG)) 33871865Sdilpreet retval = DDI_FAILURE; 33881369Sdduvall bge_chip_cfg_init(bgep, &chipid, enable_dma); 33891369Sdduvall 33901369Sdduvall /* 33911369Sdduvall * Step 8a: This may belong elsewhere, but BCM5721 needs 33921369Sdduvall * a bit set to avoid a fifo overflow/underflow bug. 33931369Sdduvall */ 33942135Szh199473 if ((bgep->chipid.chip_label == 5721) || 33952135Szh199473 (bgep->chipid.chip_label == 5751) || 33962675Szh199473 (bgep->chipid.chip_label == 5752) || 33974330Sml149210 (bgep->chipid.chip_label == 5755) || 33988207SGordon.Ross@Sun.COM (bgep->chipid.chip_label == 5756) || 33997678SYong.Tan@Sun.COM (bgep->chipid.chip_label == 5789) || 34007678SYong.Tan@Sun.COM (bgep->chipid.chip_label == 5906)) 34011369Sdduvall bge_reg_set32(bgep, TLP_CONTROL_REG, TLP_DATA_FIFO_PROTECT); 34021369Sdduvall 34031369Sdduvall 34041369Sdduvall /* 34051369Sdduvall * Step 9: enable MAC memory arbiter,bit30 and bit31 of 5714/5715 should 34061369Sdduvall * not be changed. 34071369Sdduvall */ 34081865Sdilpreet if (!bge_chip_enable_engine(bgep, MEMORY_ARBITER_MODE_REG, 0)) 34091865Sdilpreet retval = DDI_FAILURE; 34101369Sdduvall 34111369Sdduvall /* 34121369Sdduvall * Steps 10-11: configure PIO endianness options and 34131369Sdduvall * enable indirect register access -- already done 34141369Sdduvall * Steps 12-13: enable writing to the PCI state & clock 34151369Sdduvall * control registers -- not required; we aren't going to 34161369Sdduvall * use those features. 34171369Sdduvall * Steps 14-15: Configure DMA endianness options. See 34181369Sdduvall * the comments on the setting of the MHCR above. 34191369Sdduvall */ 34201369Sdduvall #ifdef _BIG_ENDIAN 34211369Sdduvall modeflags = MODE_WORD_SWAP_FRAME | MODE_BYTE_SWAP_FRAME | 34221369Sdduvall MODE_WORD_SWAP_NONFRAME | MODE_BYTE_SWAP_NONFRAME; 34231369Sdduvall #else 34241369Sdduvall modeflags = MODE_WORD_SWAP_FRAME | MODE_BYTE_SWAP_FRAME; 34251369Sdduvall #endif /* _BIG_ENDIAN */ 34261408Srandyf #ifdef BGE_IPMI_ASF 34271408Srandyf if (bgep->asf_enabled) 34281408Srandyf modeflags |= MODE_HOST_STACK_UP; 34291408Srandyf #endif 34301369Sdduvall bge_reg_put32(bgep, MODE_CONTROL_REG, modeflags); 34311369Sdduvall 34321408Srandyf #ifdef BGE_IPMI_ASF 34331408Srandyf if (bgep->asf_enabled) { 34343918Sml149210 #ifdef __sparc 34353918Sml149210 bge_reg_put32(bgep, MEMORY_ARBITER_MODE_REG, 34363918Sml149210 MEMORY_ARBITER_ENABLE | 34373918Sml149210 bge_reg_get32(bgep, MEMORY_ARBITER_MODE_REG)); 34383918Sml149210 #endif 34393918Sml149210 34403918Sml149210 #ifdef BGE_NETCONSOLE 34413918Sml149210 if (!bgep->asf_newhandshake) { 34423918Sml149210 if ((asf_mode == ASF_MODE_INIT) || 34433918Sml149210 (asf_mode == ASF_MODE_POST_INIT)) { 34443918Sml149210 bge_asf_post_reset_old_mode(bgep, 34453918Sml149210 BGE_INIT_RESET); 34463918Sml149210 } else { 34473918Sml149210 bge_asf_post_reset_old_mode(bgep, 34483918Sml149210 BGE_SHUTDOWN_RESET); 34491408Srandyf } 34501408Srandyf } 34513918Sml149210 #endif 34523918Sml149210 34533918Sml149210 /* Wait for NVRAM init */ 34543918Sml149210 i = 0; 34553918Sml149210 drv_usecwait(5000); 34563918Sml149210 mailbox = bge_nic_get32(bgep, BGE_FIRMWARE_MAILBOX); 34573918Sml149210 34583918Sml149210 while ((mailbox != (uint32_t) 34593918Sml149210 ~BGE_MAGIC_NUM_FIRMWARE_INIT_DONE) && 34603918Sml149210 (i < 10000)) { 34613918Sml149210 drv_usecwait(100); 34623918Sml149210 mailbox = bge_nic_get32(bgep, 34633918Sml149210 BGE_FIRMWARE_MAILBOX); 34643918Sml149210 i++; 34653918Sml149210 } 34663918Sml149210 34673918Sml149210 #ifndef BGE_NETCONSOLE 34683918Sml149210 if (!bgep->asf_newhandshake) { 34693918Sml149210 if ((asf_mode == ASF_MODE_INIT) || 34703918Sml149210 (asf_mode == ASF_MODE_POST_INIT)) { 34713918Sml149210 34723918Sml149210 bge_asf_post_reset_old_mode(bgep, 34733918Sml149210 BGE_INIT_RESET); 34743918Sml149210 } else { 34753918Sml149210 bge_asf_post_reset_old_mode(bgep, 34763918Sml149210 BGE_SHUTDOWN_RESET); 34773918Sml149210 } 34783918Sml149210 } 34793918Sml149210 #endif 34801408Srandyf } 34811408Srandyf #endif 34821369Sdduvall /* 34831369Sdduvall * Steps 16-17: poll for firmware completion 34841369Sdduvall */ 34851369Sdduvall mac = bge_poll_firmware(bgep); 34861369Sdduvall 34871369Sdduvall /* 34881369Sdduvall * Step 18: enable external memory -- doesn't apply. 34891369Sdduvall * 34901369Sdduvall * However we take the opportunity to set the MLCR anyway, as 34911369Sdduvall * this register also controls the SEEPROM auto-access method 34921369Sdduvall * which we may want to use later ... 34931369Sdduvall * 34941369Sdduvall * The proper value here depends on the way the chip is wired 34951369Sdduvall * into the circuit board, as this register *also* controls which 34961369Sdduvall * of the "Miscellaneous I/O" pins are driven as outputs and the 34971369Sdduvall * values driven onto those pins! 34981369Sdduvall * 34991369Sdduvall * See also step 74 in the PRM ... 35001369Sdduvall */ 35011369Sdduvall bge_reg_put32(bgep, MISC_LOCAL_CONTROL_REG, 35021369Sdduvall bgep->chipid.bge_mlcr_default); 35031369Sdduvall bge_reg_set32(bgep, SERIAL_EEPROM_ADDRESS_REG, SEEPROM_ACCESS_INIT); 35041369Sdduvall 35051369Sdduvall /* 35061369Sdduvall * Step 20: clear the Ethernet MAC mode register 35071369Sdduvall */ 35081369Sdduvall bge_reg_put32(bgep, ETHERNET_MAC_MODE_REG, 0); 35091369Sdduvall 35101369Sdduvall /* 35111369Sdduvall * Step 21: restore cache-line-size, latency timer, and 35121369Sdduvall * subsystem ID registers to their original values (not 35131369Sdduvall * those read into the local structure <chipid>, 'cos 35141369Sdduvall * that was after they were cleared by the RESET). 35151369Sdduvall * 35161369Sdduvall * Note: the Subsystem Vendor/Device ID registers are not 35171369Sdduvall * directly writable in config space, so we use the shadow 35181369Sdduvall * copy in "Page Zero" of register space to restore them 35191369Sdduvall * both in one go ... 35201369Sdduvall */ 35211369Sdduvall pci_config_put8(bgep->cfg_handle, PCI_CONF_CACHE_LINESZ, 35221369Sdduvall bgep->chipid.clsize); 35231369Sdduvall pci_config_put8(bgep->cfg_handle, PCI_CONF_LATENCY_TIMER, 35241369Sdduvall bgep->chipid.latency); 35251369Sdduvall bge_reg_put32(bgep, PCI_CONF_SUBVENID, 35261369Sdduvall (bgep->chipid.subdev << 16) | bgep->chipid.subven); 35271369Sdduvall 35281369Sdduvall /* 35291369Sdduvall * The SEND INDEX registers should be reset to zero by the 35301369Sdduvall * global chip reset; if they're not, there'll be trouble 35311865Sdilpreet * later on. 35321369Sdduvall */ 35331369Sdduvall sx0 = bge_reg_get32(bgep, NIC_DIAG_SEND_INDEX_REG(0)); 35341865Sdilpreet if (sx0 != 0) { 35351865Sdilpreet BGE_REPORT((bgep, "SEND INDEX - device didn't RESET")); 35361865Sdilpreet bge_fm_ereport(bgep, DDI_FM_DEVICE_INVAL_STATE); 35373170Sml149210 retval = DDI_FAILURE; 35381865Sdilpreet } 35391369Sdduvall 35401369Sdduvall /* Enable MSI code */ 35411369Sdduvall if (bgep->intr_type == DDI_INTR_TYPE_MSI) 35421369Sdduvall bge_reg_set32(bgep, MSI_MODE_REG, 35433907Szh199473 MSI_PRI_HIGHEST|MSI_MSI_ENABLE|MSI_ERROR_ATTENTION); 35441369Sdduvall 35451369Sdduvall /* 35461369Sdduvall * On the first time through, save the factory-set MAC address 35471369Sdduvall * (if any). If bge_poll_firmware() above didn't return one 35481369Sdduvall * (from a chip register) consider looking in the attached NV 35491369Sdduvall * memory device, if any. Once we have it, we save it in both 35501369Sdduvall * register-image (64-bit) and byte-array forms. All-zero and 35511369Sdduvall * all-one addresses are not valid, and we refuse to stash those. 35521369Sdduvall */ 35531369Sdduvall if (bgep->bge_chip_state == BGE_CHIP_INITIAL) { 35541369Sdduvall if (mac == 0ULL) 35551369Sdduvall mac = bge_get_nvmac(bgep); 35561369Sdduvall if (mac != 0ULL && mac != ~0ULL) { 35571369Sdduvall bgep->chipid.hw_mac_addr = mac; 35581369Sdduvall for (i = ETHERADDRL; i-- != 0; ) { 35591369Sdduvall bgep->chipid.vendor_addr.addr[i] = (uchar_t)mac; 35601369Sdduvall mac >>= 8; 35611369Sdduvall } 35622331Skrgopi bgep->chipid.vendor_addr.set = B_TRUE; 35631369Sdduvall } 35641369Sdduvall } 35651369Sdduvall 35661408Srandyf #ifdef BGE_IPMI_ASF 35671408Srandyf if (bgep->asf_enabled && bgep->asf_newhandshake) { 35681408Srandyf if (asf_mode != ASF_MODE_NONE) { 35691408Srandyf if ((asf_mode == ASF_MODE_INIT) || 35701408Srandyf (asf_mode == ASF_MODE_POST_INIT)) { 35711408Srandyf 35721408Srandyf bge_asf_post_reset_new_mode(bgep, 35731408Srandyf BGE_INIT_RESET); 35741408Srandyf } else { 35751408Srandyf bge_asf_post_reset_new_mode(bgep, 35761408Srandyf BGE_SHUTDOWN_RESET); 35771408Srandyf } 35781408Srandyf } 35791408Srandyf } 35801408Srandyf #endif 35811408Srandyf 35821369Sdduvall /* 35831369Sdduvall * Record the new state 35841369Sdduvall */ 35851369Sdduvall bgep->chip_resets += 1; 35861369Sdduvall bgep->bge_chip_state = BGE_CHIP_RESET; 35871865Sdilpreet return (retval); 35881369Sdduvall } 35891369Sdduvall 35901369Sdduvall /* 35911369Sdduvall * bge_chip_start() -- start the chip transmitting and/or receiving, 35921369Sdduvall * including enabling interrupts 35931369Sdduvall */ 35941865Sdilpreet int bge_chip_start(bge_t *bgep, boolean_t reset_phys); 35951369Sdduvall #pragma no_inline(bge_chip_start) 35961369Sdduvall 35979731SYong.Tan@Sun.COM void 35989731SYong.Tan@Sun.COM bge_chip_coalesce_update(bge_t *bgep) 35999731SYong.Tan@Sun.COM { 36009731SYong.Tan@Sun.COM bge_reg_put32(bgep, SEND_COALESCE_MAX_BD_REG, 36019731SYong.Tan@Sun.COM bgep->chipid.tx_count_norm); 36029731SYong.Tan@Sun.COM bge_reg_put32(bgep, SEND_COALESCE_TICKS_REG, 36039731SYong.Tan@Sun.COM bgep->chipid.tx_ticks_norm); 36049731SYong.Tan@Sun.COM bge_reg_put32(bgep, RCV_COALESCE_MAX_BD_REG, 36059731SYong.Tan@Sun.COM bgep->chipid.rx_count_norm); 36069731SYong.Tan@Sun.COM bge_reg_put32(bgep, RCV_COALESCE_TICKS_REG, 36079731SYong.Tan@Sun.COM bgep->chipid.rx_ticks_norm); 36089731SYong.Tan@Sun.COM } 36099731SYong.Tan@Sun.COM 36101865Sdilpreet int 36111369Sdduvall bge_chip_start(bge_t *bgep, boolean_t reset_phys) 36121369Sdduvall { 36131369Sdduvall uint32_t coalmode; 36141369Sdduvall uint32_t ledctl; 36151369Sdduvall uint32_t mtu; 36161369Sdduvall uint32_t maxring; 36173534Szh199473 uint32_t stats_mask; 36184330Sml149210 uint32_t dma_wrprio; 36191369Sdduvall uint64_t ring; 36201865Sdilpreet int retval = DDI_SUCCESS; 36211369Sdduvall 36221369Sdduvall BGE_TRACE(("bge_chip_start($%p)", 36234588Sml149210 (void *)bgep)); 36241369Sdduvall 36251369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 36261369Sdduvall ASSERT(bgep->bge_chip_state == BGE_CHIP_RESET); 36271369Sdduvall 36281369Sdduvall /* 36291369Sdduvall * Taken from Broadcom document 570X-PG102-R, pp 102-116. 36301369Sdduvall * The document specifies 95 separate steps to fully 36311369Sdduvall * initialise the chip!!!! 36321369Sdduvall * 36331369Sdduvall * The reset code above has already got us as far as step 36341369Sdduvall * 21, so we continue with ... 36351369Sdduvall * 36361369Sdduvall * Step 22: clear the MAC statistics block 36371369Sdduvall * (0x0300-0x0aff in NIC-local memory) 36381369Sdduvall */ 36391369Sdduvall if (bgep->chipid.statistic_type == BGE_STAT_BLK) 36401369Sdduvall bge_nic_zero(bgep, NIC_MEM_STATISTICS, 36411369Sdduvall NIC_MEM_STATISTICS_SIZE); 36421369Sdduvall 36431369Sdduvall /* 36441369Sdduvall * Step 23: clear the status block (in host memory) 36451369Sdduvall */ 36461369Sdduvall DMA_ZERO(bgep->status_block); 36471369Sdduvall 36481369Sdduvall /* 36491369Sdduvall * Step 24: set DMA read/write control register 36501369Sdduvall */ 36511369Sdduvall pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_PDRWCR, 36524588Sml149210 bgep->chipid.bge_dma_rwctrl); 36531369Sdduvall 36541369Sdduvall /* 36551369Sdduvall * Step 25: Configure DMA endianness -- already done (16/17) 36561369Sdduvall * Step 26: Configure Host-Based Send Rings 36571369Sdduvall * Step 27: Indicate Host Stack Up 36581369Sdduvall */ 36591369Sdduvall bge_reg_set32(bgep, MODE_CONTROL_REG, 36604588Sml149210 MODE_HOST_SEND_BDS | 36614588Sml149210 MODE_HOST_STACK_UP); 36621369Sdduvall 36631369Sdduvall /* 36641369Sdduvall * Step 28: Configure checksum options: 36651611Szh199473 * Solaris supports the hardware default checksum options. 36661611Szh199473 * 36671611Szh199473 * Workaround for Incorrect pseudo-header checksum calculation. 36681369Sdduvall */ 36692135Szh199473 if (bgep->chipid.flags & CHIP_FLAG_PARTIAL_CSUM) 36701611Szh199473 bge_reg_set32(bgep, MODE_CONTROL_REG, 36712311Sseb MODE_SEND_NO_PSEUDO_HDR_CSUM); 36721369Sdduvall 36731369Sdduvall /* 36741369Sdduvall * Step 29: configure Timer Prescaler. The value is always the 36751369Sdduvall * same: the Core Clock frequency in MHz (66), minus 1, shifted 36761369Sdduvall * into bits 7-1. Don't set bit 0, 'cos that's the RESET bit 36771369Sdduvall * for the whole chip! 36781369Sdduvall */ 36791369Sdduvall bge_reg_put32(bgep, MISC_CONFIG_REG, MISC_CONFIG_DEFAULT); 36801369Sdduvall 36817678SYong.Tan@Sun.COM if (DEVICE_5906_SERIES_CHIPSETS(bgep)) { 36827678SYong.Tan@Sun.COM drv_usecwait(40); 36837678SYong.Tan@Sun.COM /* put PHY into ready state */ 36847678SYong.Tan@Sun.COM bge_reg_clr32(bgep, MISC_CONFIG_REG, MISC_CONFIG_EPHY_IDDQ); 36857678SYong.Tan@Sun.COM (void) bge_reg_get32(bgep, MISC_CONFIG_REG); /* flush */ 36867678SYong.Tan@Sun.COM drv_usecwait(40); 36877678SYong.Tan@Sun.COM } 36887678SYong.Tan@Sun.COM 36891369Sdduvall /* 36901369Sdduvall * Steps 30-31: Configure MAC local memory pool & DMA pool registers 36911369Sdduvall * 36921369Sdduvall * If the mbuf_length is specified as 0, we just leave these at 36931369Sdduvall * their hardware defaults, rather than explicitly setting them. 36941369Sdduvall * As the Broadcom HRM,driver better not change the parameters 36951369Sdduvall * when the chipsets is 5705/5788/5721/5751/5714 and 5715. 36961369Sdduvall */ 36971369Sdduvall if ((bgep->chipid.mbuf_length != 0) && 36984588Sml149210 (DEVICE_5704_SERIES_CHIPSETS(bgep))) { 36991369Sdduvall bge_reg_put32(bgep, MBUF_POOL_BASE_REG, 37004588Sml149210 bgep->chipid.mbuf_base); 37011369Sdduvall bge_reg_put32(bgep, MBUF_POOL_LENGTH_REG, 37024588Sml149210 bgep->chipid.mbuf_length); 37031369Sdduvall bge_reg_put32(bgep, DMAD_POOL_BASE_REG, 37044588Sml149210 DMAD_POOL_BASE_DEFAULT); 37051369Sdduvall bge_reg_put32(bgep, DMAD_POOL_LENGTH_REG, 37064588Sml149210 DMAD_POOL_LENGTH_DEFAULT); 37071369Sdduvall } 37081369Sdduvall 37091369Sdduvall /* 37101369Sdduvall * Step 32: configure MAC memory pool watermarks 37111369Sdduvall */ 37121369Sdduvall bge_reg_put32(bgep, RDMA_MBUF_LOWAT_REG, 37134588Sml149210 bgep->chipid.mbuf_lo_water_rdma); 37141369Sdduvall bge_reg_put32(bgep, MAC_RX_MBUF_LOWAT_REG, 37154588Sml149210 bgep->chipid.mbuf_lo_water_rmac); 37161369Sdduvall bge_reg_put32(bgep, MBUF_HIWAT_REG, 37174588Sml149210 bgep->chipid.mbuf_hi_water); 37181369Sdduvall 37191369Sdduvall /* 37201369Sdduvall * Step 33: configure DMA resource watermarks 37211369Sdduvall */ 37221369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) { 37231369Sdduvall bge_reg_put32(bgep, DMAD_POOL_LOWAT_REG, 37241369Sdduvall bge_dmad_lo_water); 37251369Sdduvall bge_reg_put32(bgep, DMAD_POOL_HIWAT_REG, 37261369Sdduvall bge_dmad_hi_water); 37271369Sdduvall } 37281369Sdduvall bge_reg_put32(bgep, LOWAT_MAX_RECV_FRAMES_REG, bge_lowat_recv_frames); 37291369Sdduvall 37301369Sdduvall /* 37311369Sdduvall * Steps 34-36: enable buffer manager & internal h/w queues 37321369Sdduvall */ 37331865Sdilpreet if (!bge_chip_enable_engine(bgep, BUFFER_MANAGER_MODE_REG, 37341865Sdilpreet STATE_MACHINE_ATTN_ENABLE_BIT)) 37351865Sdilpreet retval = DDI_FAILURE; 37361865Sdilpreet if (!bge_chip_enable_engine(bgep, FTQ_RESET_REG, 0)) 37371865Sdilpreet retval = DDI_FAILURE; 37381369Sdduvall 37391369Sdduvall /* 37401369Sdduvall * Steps 37-39: initialise Receive Buffer (Producer) RCBs 37411369Sdduvall */ 37421369Sdduvall bge_reg_putrcb(bgep, STD_RCV_BD_RING_RCB_REG, 37434588Sml149210 &bgep->buff[BGE_STD_BUFF_RING].hw_rcb); 37441369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) { 37451369Sdduvall bge_reg_putrcb(bgep, JUMBO_RCV_BD_RING_RCB_REG, 37464588Sml149210 &bgep->buff[BGE_JUMBO_BUFF_RING].hw_rcb); 37471369Sdduvall bge_reg_putrcb(bgep, MINI_RCV_BD_RING_RCB_REG, 37484588Sml149210 &bgep->buff[BGE_MINI_BUFF_RING].hw_rcb); 37491369Sdduvall } 37501369Sdduvall 37511369Sdduvall /* 37521369Sdduvall * Step 40: set Receive Buffer Descriptor Ring replenish thresholds 37531369Sdduvall */ 37541369Sdduvall bge_reg_put32(bgep, STD_RCV_BD_REPLENISH_REG, bge_replenish_std); 37551369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) { 37561369Sdduvall bge_reg_put32(bgep, JUMBO_RCV_BD_REPLENISH_REG, 37571369Sdduvall bge_replenish_jumbo); 37581369Sdduvall bge_reg_put32(bgep, MINI_RCV_BD_REPLENISH_REG, 37591369Sdduvall bge_replenish_mini); 37601369Sdduvall } 37611369Sdduvall 37621369Sdduvall /* 37631369Sdduvall * Steps 41-43: clear Send Ring Producer Indices and initialise 37641369Sdduvall * Send Producer Rings (0x0100-0x01ff in NIC-local memory) 37651369Sdduvall */ 37661369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) 37671369Sdduvall maxring = BGE_SEND_RINGS_MAX; 37681369Sdduvall else 37691369Sdduvall maxring = BGE_SEND_RINGS_MAX_5705; 37701369Sdduvall for (ring = 0; ring < maxring; ++ring) { 37711369Sdduvall bge_mbx_put(bgep, SEND_RING_HOST_INDEX_REG(ring), 0); 37721369Sdduvall bge_mbx_put(bgep, SEND_RING_NIC_INDEX_REG(ring), 0); 37731369Sdduvall bge_nic_putrcb(bgep, NIC_MEM_SEND_RING(ring), 37744588Sml149210 &bgep->send[ring].hw_rcb); 37751369Sdduvall } 37761369Sdduvall 37771369Sdduvall /* 37781369Sdduvall * Steps 44-45: initialise Receive Return Rings 37791369Sdduvall * (0x0200-0x02ff in NIC-local memory) 37801369Sdduvall */ 37811369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) 37821369Sdduvall maxring = BGE_RECV_RINGS_MAX; 37831369Sdduvall else 37841369Sdduvall maxring = BGE_RECV_RINGS_MAX_5705; 37851369Sdduvall for (ring = 0; ring < maxring; ++ring) 37861369Sdduvall bge_nic_putrcb(bgep, NIC_MEM_RECV_RING(ring), 37874588Sml149210 &bgep->recv[ring].hw_rcb); 37881369Sdduvall 37891369Sdduvall /* 37901369Sdduvall * Step 46: initialise Receive Buffer (Producer) Ring indexes 37911369Sdduvall */ 37921369Sdduvall bge_mbx_put(bgep, RECV_STD_PROD_INDEX_REG, 0); 37931369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) { 37941369Sdduvall bge_mbx_put(bgep, RECV_JUMBO_PROD_INDEX_REG, 0); 37951369Sdduvall bge_mbx_put(bgep, RECV_MINI_PROD_INDEX_REG, 0); 37961369Sdduvall } 37971369Sdduvall /* 37981369Sdduvall * Step 47: configure the MAC unicast address 37991369Sdduvall * Step 48: configure the random backoff seed 38001369Sdduvall * Step 96: set up multicast filters 38011369Sdduvall */ 38021408Srandyf #ifdef BGE_IPMI_ASF 38031865Sdilpreet if (bge_chip_sync(bgep, B_FALSE) == DDI_FAILURE) 38041408Srandyf #else 38051865Sdilpreet if (bge_chip_sync(bgep) == DDI_FAILURE) 38061408Srandyf #endif 38071865Sdilpreet retval = DDI_FAILURE; 38081369Sdduvall 38091369Sdduvall /* 38101369Sdduvall * Step 49: configure the MTU 38111369Sdduvall */ 38121369Sdduvall mtu = bgep->chipid.ethmax_size+ETHERFCSL+VLAN_TAGSZ; 38131369Sdduvall bge_reg_put32(bgep, MAC_RX_MTU_SIZE_REG, mtu); 38141369Sdduvall 38151369Sdduvall /* 38161369Sdduvall * Step 50: configure the IPG et al 38171369Sdduvall */ 38181369Sdduvall bge_reg_put32(bgep, MAC_TX_LENGTHS_REG, MAC_TX_LENGTHS_DEFAULT); 38191369Sdduvall 38201369Sdduvall /* 38211369Sdduvall * Step 51: configure the default Rx Return Ring 38221369Sdduvall */ 38231369Sdduvall bge_reg_put32(bgep, RCV_RULES_CONFIG_REG, RCV_RULES_CONFIG_DEFAULT); 38241369Sdduvall 38251369Sdduvall /* 38261369Sdduvall * Steps 52-54: configure Receive List Placement, 38271369Sdduvall * and enable Receive List Placement Statistics 38281369Sdduvall */ 38291369Sdduvall bge_reg_put32(bgep, RCV_LP_CONFIG_REG, 38304588Sml149210 RCV_LP_CONFIG(bgep->chipid.rx_rings)); 38313534Szh199473 switch (MHCR_CHIP_ASIC_REV(bgep->chipid.asic_rev)) { 38323534Szh199473 case MHCR_CHIP_ASIC_REV_5700: 38333534Szh199473 case MHCR_CHIP_ASIC_REV_5701: 38343534Szh199473 case MHCR_CHIP_ASIC_REV_5703: 38353534Szh199473 case MHCR_CHIP_ASIC_REV_5704: 38363534Szh199473 bge_reg_put32(bgep, RCV_LP_STATS_ENABLE_MASK_REG, ~0); 38373534Szh199473 break; 38383534Szh199473 case MHCR_CHIP_ASIC_REV_5705: 38393534Szh199473 break; 38403534Szh199473 default: 38413534Szh199473 stats_mask = bge_reg_get32(bgep, RCV_LP_STATS_ENABLE_MASK_REG); 38423534Szh199473 stats_mask &= ~RCV_LP_STATS_DISABLE_MACTQ; 38433534Szh199473 bge_reg_put32(bgep, RCV_LP_STATS_ENABLE_MASK_REG, stats_mask); 38443534Szh199473 break; 38453534Szh199473 } 38461369Sdduvall bge_reg_set32(bgep, RCV_LP_STATS_CONTROL_REG, RCV_LP_STATS_ENABLE); 38471369Sdduvall 38481369Sdduvall if (bgep->chipid.rx_rings > 1) 38491369Sdduvall bge_init_recv_rule(bgep); 38501369Sdduvall 38511369Sdduvall /* 38521369Sdduvall * Steps 55-56: enable Send Data Initiator Statistics 38531369Sdduvall */ 38541369Sdduvall bge_reg_put32(bgep, SEND_INIT_STATS_ENABLE_MASK_REG, ~0); 38551369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) { 38561369Sdduvall bge_reg_put32(bgep, SEND_INIT_STATS_CONTROL_REG, 38571369Sdduvall SEND_INIT_STATS_ENABLE | SEND_INIT_STATS_FASTER); 38581369Sdduvall } else { 38591369Sdduvall bge_reg_put32(bgep, SEND_INIT_STATS_CONTROL_REG, 38601369Sdduvall SEND_INIT_STATS_ENABLE); 38611369Sdduvall } 38621369Sdduvall /* 38631369Sdduvall * Steps 57-58: stop (?) the Host Coalescing Engine 38641369Sdduvall */ 38651865Sdilpreet if (!bge_chip_disable_engine(bgep, HOST_COALESCE_MODE_REG, ~0)) 38661865Sdilpreet retval = DDI_FAILURE; 38671369Sdduvall 38681369Sdduvall /* 38691369Sdduvall * Steps 59-62: initialise Host Coalescing parameters 38701369Sdduvall */ 38719731SYong.Tan@Sun.COM bge_chip_coalesce_update(bgep); 38721369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) { 38731369Sdduvall bge_reg_put32(bgep, SEND_COALESCE_INT_BD_REG, 38741369Sdduvall bge_tx_count_intr); 38751369Sdduvall bge_reg_put32(bgep, SEND_COALESCE_INT_TICKS_REG, 38761369Sdduvall bge_tx_ticks_intr); 38771369Sdduvall bge_reg_put32(bgep, RCV_COALESCE_INT_BD_REG, 38781369Sdduvall bge_rx_count_intr); 38791369Sdduvall bge_reg_put32(bgep, RCV_COALESCE_INT_TICKS_REG, 38801369Sdduvall bge_rx_ticks_intr); 38811369Sdduvall } 38821369Sdduvall 38831369Sdduvall /* 38841369Sdduvall * Steps 63-64: initialise status block & statistics 38851369Sdduvall * host memory addresses 38861369Sdduvall * The statistic block does not exist in some chipsets 38871369Sdduvall * Step 65: initialise Statistics Coalescing Tick Counter 38881369Sdduvall */ 38891369Sdduvall bge_reg_put64(bgep, STATUS_BLOCK_HOST_ADDR_REG, 38904588Sml149210 bgep->status_block.cookie.dmac_laddress); 38911369Sdduvall 38921369Sdduvall /* 38931369Sdduvall * Steps 66-67: initialise status block & statistics 38941369Sdduvall * NIC-local memory addresses 38951369Sdduvall */ 38961369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) { 38971369Sdduvall bge_reg_put64(bgep, STATISTICS_HOST_ADDR_REG, 38981369Sdduvall bgep->statistics.cookie.dmac_laddress); 38991369Sdduvall bge_reg_put32(bgep, STATISTICS_TICKS_REG, 39001369Sdduvall STATISTICS_TICKS_DEFAULT); 39011369Sdduvall bge_reg_put32(bgep, STATUS_BLOCK_BASE_ADDR_REG, 39021369Sdduvall NIC_MEM_STATUS_BLOCK); 39031369Sdduvall bge_reg_put32(bgep, STATISTICS_BASE_ADDR_REG, 39041369Sdduvall NIC_MEM_STATISTICS); 39051369Sdduvall } 39061369Sdduvall 39071369Sdduvall /* 39081369Sdduvall * Steps 68-71: start the Host Coalescing Engine, the Receive BD 39091369Sdduvall * Completion Engine, the Receive List Placement Engine, and the 39101369Sdduvall * Receive List selector.Pay attention:0x3400 is not exist in BCM5714 39111369Sdduvall * and BCM5715. 39121369Sdduvall */ 39131369Sdduvall if (bgep->chipid.tx_rings <= COALESCE_64_BYTE_RINGS && 39141369Sdduvall bgep->chipid.rx_rings <= COALESCE_64_BYTE_RINGS) 39151369Sdduvall coalmode = COALESCE_64_BYTE_STATUS; 39161369Sdduvall else 39171369Sdduvall coalmode = 0; 39181865Sdilpreet if (!bge_chip_enable_engine(bgep, HOST_COALESCE_MODE_REG, coalmode)) 39191865Sdilpreet retval = DDI_FAILURE; 39201865Sdilpreet if (!bge_chip_enable_engine(bgep, RCV_BD_COMPLETION_MODE_REG, 39211865Sdilpreet STATE_MACHINE_ATTN_ENABLE_BIT)) 39221865Sdilpreet retval = DDI_FAILURE; 39231865Sdilpreet if (!bge_chip_enable_engine(bgep, RCV_LIST_PLACEMENT_MODE_REG, 0)) 39241865Sdilpreet retval = DDI_FAILURE; 39251369Sdduvall 39261369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) 39271865Sdilpreet if (!bge_chip_enable_engine(bgep, RCV_LIST_SELECTOR_MODE_REG, 39281865Sdilpreet STATE_MACHINE_ATTN_ENABLE_BIT)) 39291865Sdilpreet retval = DDI_FAILURE; 39301369Sdduvall 39311369Sdduvall /* 39321369Sdduvall * Step 72: Enable MAC DMA engines 39331369Sdduvall * Step 73: Clear & enable MAC statistics 39341369Sdduvall */ 39351369Sdduvall bge_reg_set32(bgep, ETHERNET_MAC_MODE_REG, 39364588Sml149210 ETHERNET_MODE_ENABLE_FHDE | 39374588Sml149210 ETHERNET_MODE_ENABLE_RDE | 39384588Sml149210 ETHERNET_MODE_ENABLE_TDE); 39391369Sdduvall bge_reg_set32(bgep, ETHERNET_MAC_MODE_REG, 39404588Sml149210 ETHERNET_MODE_ENABLE_TX_STATS | 39414588Sml149210 ETHERNET_MODE_ENABLE_RX_STATS | 39424588Sml149210 ETHERNET_MODE_CLEAR_TX_STATS | 39434588Sml149210 ETHERNET_MODE_CLEAR_RX_STATS); 39441369Sdduvall 39451369Sdduvall /* 39461369Sdduvall * Step 74: configure the MLCR (Miscellaneous Local Control 39471369Sdduvall * Register); not required, as we set up the MLCR in step 10 39481369Sdduvall * (part of the reset code) above. 39491369Sdduvall * 39501369Sdduvall * Step 75: clear Interrupt Mailbox 0 39511369Sdduvall */ 39521369Sdduvall bge_mbx_put(bgep, INTERRUPT_MBOX_0_REG, 0); 39531369Sdduvall 39541369Sdduvall /* 39551369Sdduvall * Steps 76-87: Gentlemen, start your engines ... 39561369Sdduvall * 39571369Sdduvall * Enable the DMA Completion Engine, the Write DMA Engine, 39581369Sdduvall * the Read DMA Engine, Receive Data Completion Engine, 39591369Sdduvall * the MBuf Cluster Free Engine, the Send Data Completion Engine, 39601369Sdduvall * the Send BD Completion Engine, the Receive BD Initiator Engine, 39611369Sdduvall * the Receive Data Initiator Engine, the Send Data Initiator Engine, 39621369Sdduvall * the Send BD Initiator Engine, and the Send BD Selector Engine. 39631369Sdduvall * 39641369Sdduvall * Beware exhaust fumes? 39651369Sdduvall */ 39661369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) 39671865Sdilpreet if (!bge_chip_enable_engine(bgep, DMA_COMPLETION_MODE_REG, 0)) 39681865Sdilpreet retval = DDI_FAILURE; 39694330Sml149210 dma_wrprio = (bge_dma_wrprio << DMA_PRIORITY_SHIFT) | 39704588Sml149210 ALL_DMA_ATTN_BITS; 39717678SYong.Tan@Sun.COM if ((MHCR_CHIP_ASIC_REV(bgep->chipid.asic_rev) == 39727678SYong.Tan@Sun.COM MHCR_CHIP_ASIC_REV_5755) || 39737678SYong.Tan@Sun.COM (MHCR_CHIP_ASIC_REV(bgep->chipid.asic_rev) == 39747678SYong.Tan@Sun.COM MHCR_CHIP_ASIC_REV_5906)) { 39754330Sml149210 dma_wrprio |= DMA_STATUS_TAG_FIX_CQ12384; 39764330Sml149210 } 39771865Sdilpreet if (!bge_chip_enable_engine(bgep, WRITE_DMA_MODE_REG, 39784588Sml149210 dma_wrprio)) 39791865Sdilpreet retval = DDI_FAILURE; 3980*11479SYong.Tan@Sun.COM if (DEVICE_5723_SERIES_CHIPSETS(bgep)) 3981*11479SYong.Tan@Sun.COM bge_dma_rdprio = 0; 39821865Sdilpreet if (!bge_chip_enable_engine(bgep, READ_DMA_MODE_REG, 39831865Sdilpreet (bge_dma_rdprio << DMA_PRIORITY_SHIFT) | ALL_DMA_ATTN_BITS)) 39841865Sdilpreet retval = DDI_FAILURE; 39851865Sdilpreet if (!bge_chip_enable_engine(bgep, RCV_DATA_COMPLETION_MODE_REG, 39861865Sdilpreet STATE_MACHINE_ATTN_ENABLE_BIT)) 39871865Sdilpreet retval = DDI_FAILURE; 39881369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) 39891865Sdilpreet if (!bge_chip_enable_engine(bgep, 39901865Sdilpreet MBUF_CLUSTER_FREE_MODE_REG, 0)) 39911865Sdilpreet retval = DDI_FAILURE; 39921865Sdilpreet if (!bge_chip_enable_engine(bgep, SEND_DATA_COMPLETION_MODE_REG, 0)) 39931865Sdilpreet retval = DDI_FAILURE; 39941865Sdilpreet if (!bge_chip_enable_engine(bgep, SEND_BD_COMPLETION_MODE_REG, 39951865Sdilpreet STATE_MACHINE_ATTN_ENABLE_BIT)) 39961865Sdilpreet retval = DDI_FAILURE; 39971865Sdilpreet if (!bge_chip_enable_engine(bgep, RCV_BD_INITIATOR_MODE_REG, 39981865Sdilpreet RCV_BD_DISABLED_RING_ATTN)) 39991865Sdilpreet retval = DDI_FAILURE; 40001865Sdilpreet if (!bge_chip_enable_engine(bgep, RCV_DATA_BD_INITIATOR_MODE_REG, 40011865Sdilpreet RCV_DATA_BD_ILL_RING_ATTN)) 40021865Sdilpreet retval = DDI_FAILURE; 40031865Sdilpreet if (!bge_chip_enable_engine(bgep, SEND_DATA_INITIATOR_MODE_REG, 0)) 40041865Sdilpreet retval = DDI_FAILURE; 40051865Sdilpreet if (!bge_chip_enable_engine(bgep, SEND_BD_INITIATOR_MODE_REG, 40061865Sdilpreet STATE_MACHINE_ATTN_ENABLE_BIT)) 40071865Sdilpreet retval = DDI_FAILURE; 40081865Sdilpreet if (!bge_chip_enable_engine(bgep, SEND_BD_SELECTOR_MODE_REG, 40091865Sdilpreet STATE_MACHINE_ATTN_ENABLE_BIT)) 40101865Sdilpreet retval = DDI_FAILURE; 40111369Sdduvall 40121369Sdduvall /* 40131369Sdduvall * Step 88: download firmware -- doesn't apply 40141369Sdduvall * Steps 89-90: enable Transmit & Receive MAC Engines 40151369Sdduvall */ 40161865Sdilpreet if (!bge_chip_enable_engine(bgep, TRANSMIT_MAC_MODE_REG, 0)) 40171865Sdilpreet retval = DDI_FAILURE; 40181408Srandyf #ifdef BGE_IPMI_ASF 40191865Sdilpreet if (!bgep->asf_enabled) { 40201865Sdilpreet if (!bge_chip_enable_engine(bgep, RECEIVE_MAC_MODE_REG, 40211865Sdilpreet RECEIVE_MODE_KEEP_VLAN_TAG)) 40221865Sdilpreet retval = DDI_FAILURE; 40231408Srandyf } else { 40241865Sdilpreet if (!bge_chip_enable_engine(bgep, RECEIVE_MAC_MODE_REG, 0)) 40251865Sdilpreet retval = DDI_FAILURE; 40261408Srandyf } 40271408Srandyf #else 40281865Sdilpreet if (!bge_chip_enable_engine(bgep, RECEIVE_MAC_MODE_REG, 40291865Sdilpreet RECEIVE_MODE_KEEP_VLAN_TAG)) 40301865Sdilpreet retval = DDI_FAILURE; 40311408Srandyf #endif 40321369Sdduvall 40331369Sdduvall /* 40341369Sdduvall * Step 91: disable auto-polling of PHY status 40351369Sdduvall */ 40361369Sdduvall bge_reg_put32(bgep, MI_MODE_REG, MI_MODE_DEFAULT); 40371369Sdduvall 40381369Sdduvall /* 40391369Sdduvall * Step 92: configure D0 power state (not required) 40401369Sdduvall * Step 93: initialise LED control register () 40411369Sdduvall */ 40421369Sdduvall ledctl = LED_CONTROL_DEFAULT; 40431369Sdduvall switch (bgep->chipid.device) { 40441369Sdduvall case DEVICE_ID_5700: 40451369Sdduvall case DEVICE_ID_5700x: 40461369Sdduvall case DEVICE_ID_5701: 40471369Sdduvall /* 40481369Sdduvall * Switch to 5700 (MAC) mode on these older chips 40491369Sdduvall */ 40501369Sdduvall ledctl &= ~LED_CONTROL_LED_MODE_MASK; 40511369Sdduvall ledctl |= LED_CONTROL_LED_MODE_5700; 40521369Sdduvall break; 40531369Sdduvall 40541369Sdduvall default: 40551369Sdduvall break; 40561369Sdduvall } 40571369Sdduvall bge_reg_put32(bgep, ETHERNET_MAC_LED_CONTROL_REG, ledctl); 40581369Sdduvall 40591369Sdduvall /* 40601369Sdduvall * Step 94: activate link 40611369Sdduvall */ 40621369Sdduvall bge_reg_put32(bgep, MI_STATUS_REG, MI_STATUS_LINK); 40631369Sdduvall 40641369Sdduvall /* 40651369Sdduvall * Step 95: set up physical layer (PHY/SerDes) 40661369Sdduvall * restart autoneg (if required) 40671369Sdduvall */ 40681369Sdduvall if (reset_phys) 40691865Sdilpreet if (bge_phys_update(bgep) == DDI_FAILURE) 40701865Sdilpreet retval = DDI_FAILURE; 40711369Sdduvall 40721369Sdduvall /* 40731369Sdduvall * Extra step (DSG): hand over all the Receive Buffers to the chip 40741369Sdduvall */ 40751369Sdduvall for (ring = 0; ring < BGE_BUFF_RINGS_USED; ++ring) 40761369Sdduvall bge_mbx_put(bgep, bgep->buff[ring].chip_mbx_reg, 40774588Sml149210 bgep->buff[ring].rf_next); 40781369Sdduvall 40791369Sdduvall /* 40801369Sdduvall * MSI bits:The least significant MSI 16-bit word. 40811369Sdduvall * ISR will be triggered different. 40821369Sdduvall */ 40831369Sdduvall if (bgep->intr_type == DDI_INTR_TYPE_MSI) 40841369Sdduvall bge_reg_set32(bgep, HOST_COALESCE_MODE_REG, 0x70); 40851369Sdduvall 40861369Sdduvall /* 40871369Sdduvall * Extra step (DSG): select which interrupts are enabled 40881369Sdduvall * 40891369Sdduvall * Program the Ethernet MAC engine to signal attention on 40901369Sdduvall * Link Change events, then enable interrupts on MAC, DMA, 40911369Sdduvall * and FLOW attention signals. 40921369Sdduvall */ 40931369Sdduvall bge_reg_set32(bgep, ETHERNET_MAC_EVENT_ENABLE_REG, 40944588Sml149210 ETHERNET_EVENT_LINK_INT | 40954588Sml149210 ETHERNET_STATUS_PCS_ERROR_INT); 40961408Srandyf #ifdef BGE_IPMI_ASF 40971408Srandyf if (bgep->asf_enabled) { 40981408Srandyf bge_reg_set32(bgep, MODE_CONTROL_REG, 40994588Sml149210 MODE_INT_ON_FLOW_ATTN | 41004588Sml149210 MODE_INT_ON_DMA_ATTN | 41014588Sml149210 MODE_HOST_STACK_UP| 41024588Sml149210 MODE_INT_ON_MAC_ATTN); 41031408Srandyf } else { 41041408Srandyf #endif 41051408Srandyf bge_reg_set32(bgep, MODE_CONTROL_REG, 41064588Sml149210 MODE_INT_ON_FLOW_ATTN | 41074588Sml149210 MODE_INT_ON_DMA_ATTN | 41084588Sml149210 MODE_INT_ON_MAC_ATTN); 41091408Srandyf #ifdef BGE_IPMI_ASF 41101408Srandyf } 41111408Srandyf #endif 41121369Sdduvall 41131369Sdduvall /* 41141369Sdduvall * Step 97: enable PCI interrupts!!! 41151369Sdduvall */ 41161369Sdduvall if (bgep->intr_type == DDI_INTR_TYPE_FIXED) 41171369Sdduvall bge_cfg_clr32(bgep, PCI_CONF_BGE_MHCR, 41181369Sdduvall MHCR_MASK_PCI_INT_OUTPUT); 41191369Sdduvall 41201369Sdduvall /* 41211369Sdduvall * All done! 41221369Sdduvall */ 41231369Sdduvall bgep->bge_chip_state = BGE_CHIP_RUNNING; 41241865Sdilpreet return (retval); 41251369Sdduvall } 41261369Sdduvall 41271369Sdduvall 41281369Sdduvall /* 41291369Sdduvall * ========== Hardware interrupt handler ========== 41301369Sdduvall */ 41311369Sdduvall 41321369Sdduvall #undef BGE_DBG 41331369Sdduvall #define BGE_DBG BGE_DBG_INT /* debug flag for this code */ 41341369Sdduvall 41351369Sdduvall /* 41361369Sdduvall * Sync the status block, then atomically clear the specified bits in 41371369Sdduvall * the <flags-and-tag> field of the status block. 41381369Sdduvall * the <flags> word of the status block, returning the value of the 41391369Sdduvall * <tag> and the <flags> before the bits were cleared. 41401369Sdduvall */ 41411865Sdilpreet static int bge_status_sync(bge_t *bgep, uint64_t bits, uint64_t *flags); 41421369Sdduvall #pragma inline(bge_status_sync) 41431369Sdduvall 41441865Sdilpreet static int 41451865Sdilpreet bge_status_sync(bge_t *bgep, uint64_t bits, uint64_t *flags) 41461369Sdduvall { 41471369Sdduvall bge_status_t *bsp; 41481865Sdilpreet int retval; 41491369Sdduvall 41501369Sdduvall BGE_TRACE(("bge_status_sync($%p, 0x%llx)", 41514588Sml149210 (void *)bgep, bits)); 41521369Sdduvall 41531369Sdduvall ASSERT(bgep->bge_guard == BGE_GUARD); 41541369Sdduvall 41551369Sdduvall DMA_SYNC(bgep->status_block, DDI_DMA_SYNC_FORKERNEL); 41561865Sdilpreet retval = bge_check_dma_handle(bgep, bgep->status_block.dma_hdl); 41571865Sdilpreet if (retval != DDI_FM_OK) 41581865Sdilpreet return (retval); 41591865Sdilpreet 41601369Sdduvall bsp = DMA_VPTR(bgep->status_block); 41611865Sdilpreet *flags = bge_atomic_clr64(&bsp->flags_n_tag, bits); 41621369Sdduvall 41631369Sdduvall BGE_DEBUG(("bge_status_sync($%p, 0x%llx) returning 0x%llx", 41644588Sml149210 (void *)bgep, bits, *flags)); 41651865Sdilpreet 41661865Sdilpreet return (retval); 41671369Sdduvall } 41681369Sdduvall 41695903Ssowmini void bge_wake_factotum(bge_t *bgep); 41701369Sdduvall #pragma inline(bge_wake_factotum) 41711369Sdduvall 41725903Ssowmini void 41731369Sdduvall bge_wake_factotum(bge_t *bgep) 41741369Sdduvall { 41751369Sdduvall mutex_enter(bgep->softintrlock); 41761369Sdduvall if (bgep->factotum_flag == 0) { 41771369Sdduvall bgep->factotum_flag = 1; 41781369Sdduvall ddi_trigger_softintr(bgep->factotum_id); 41791369Sdduvall } 41801369Sdduvall mutex_exit(bgep->softintrlock); 41811369Sdduvall } 41821369Sdduvall 41831369Sdduvall /* 41841369Sdduvall * bge_intr() -- handle chip interrupts 41851369Sdduvall */ 41861369Sdduvall uint_t bge_intr(caddr_t arg1, caddr_t arg2); 41871369Sdduvall #pragma no_inline(bge_intr) 41881369Sdduvall 41891369Sdduvall uint_t 41901369Sdduvall bge_intr(caddr_t arg1, caddr_t arg2) 41911369Sdduvall { 41927099Syt223700 bge_t *bgep = (void *)arg1; /* private device info */ 41931369Sdduvall bge_status_t *bsp; 41941369Sdduvall uint64_t flags; 41953907Szh199473 uint32_t regval; 41961369Sdduvall uint_t result; 41973918Sml149210 int retval, loop_cnt = 0; 41981369Sdduvall 41991369Sdduvall BGE_TRACE(("bge_intr($%p) ($%p)", arg1, arg2)); 42001369Sdduvall 42011369Sdduvall /* 42021369Sdduvall * GLD v2 checks that s/w setup is complete before passing 42031369Sdduvall * interrupts to this routine, thus eliminating the old 42041369Sdduvall * (and well-known) race condition around ddi_add_intr() 42051369Sdduvall */ 42061369Sdduvall ASSERT(bgep->progress & PROGRESS_HWINT); 42071369Sdduvall 42081369Sdduvall result = DDI_INTR_UNCLAIMED; 42091369Sdduvall mutex_enter(bgep->genlock); 42101369Sdduvall 42113907Szh199473 if (bgep->intr_type == DDI_INTR_TYPE_FIXED) { 42121369Sdduvall /* 42133907Szh199473 * Check whether chip's says it's asserting #INTA; 42143907Szh199473 * if not, don't process or claim the interrupt. 42153907Szh199473 * 42163907Szh199473 * Note that the PCI signal is active low, so the 42173907Szh199473 * bit is *zero* when the interrupt is asserted. 42181369Sdduvall */ 42193907Szh199473 regval = bge_reg_get32(bgep, MISC_LOCAL_CONTROL_REG); 42203907Szh199473 if (regval & MLCR_INTA_STATE) { 42213907Szh199473 if (bge_check_acc_handle(bgep, bgep->io_handle) 42223907Szh199473 != DDI_FM_OK) 42231865Sdilpreet goto chip_stop; 42243907Szh199473 mutex_exit(bgep->genlock); 42253907Szh199473 return (result); 42261865Sdilpreet } 42271369Sdduvall 42281369Sdduvall /* 42293907Szh199473 * Block further PCI interrupts ... 42303907Szh199473 */ 42313907Szh199473 bge_reg_set32(bgep, PCI_CONF_BGE_MHCR, 42323907Szh199473 MHCR_MASK_PCI_INT_OUTPUT); 42333907Szh199473 42343907Szh199473 } else { 42353907Szh199473 /* 42363907Szh199473 * Check MSI status 42371369Sdduvall */ 42383907Szh199473 regval = bge_reg_get32(bgep, MSI_STATUS_REG); 42393907Szh199473 if (regval & MSI_ERROR_ATTENTION) { 42403907Szh199473 BGE_REPORT((bgep, "msi error attention," 42413907Szh199473 " status=0x%x", regval)); 42423907Szh199473 bge_reg_put32(bgep, MSI_STATUS_REG, regval); 42433907Szh199473 } 42443907Szh199473 } 42453907Szh199473 42463907Szh199473 result = DDI_INTR_CLAIMED; 42473907Szh199473 42483907Szh199473 BGE_DEBUG(("bge_intr($%p) ($%p) regval 0x%08x", arg1, arg2, regval)); 42493907Szh199473 42503907Szh199473 /* 42513907Szh199473 * Sync the status block and grab the flags-n-tag from it. 42523907Szh199473 * We count the number of interrupts where there doesn't 42533907Szh199473 * seem to have been a DMA update of the status block; if 42543907Szh199473 * it *has* been updated, the counter will be cleared in 42553907Szh199473 * the while() loop below ... 42563907Szh199473 */ 42573907Szh199473 bgep->missed_dmas += 1; 42583907Szh199473 bsp = DMA_VPTR(bgep->status_block); 42593918Sml149210 for (loop_cnt = 0; loop_cnt < bge_intr_max_loop; loop_cnt++) { 42603907Szh199473 if (bgep->bge_chip_state != BGE_CHIP_RUNNING) { 42611369Sdduvall /* 42623907Szh199473 * bge_chip_stop() may have freed dma area etc 42633907Szh199473 * while we were in this interrupt handler - 42643907Szh199473 * better not call bge_status_sync() 42651369Sdduvall */ 42663907Szh199473 (void) bge_check_acc_handle(bgep, 42673907Szh199473 bgep->io_handle); 42681369Sdduvall mutex_exit(bgep->genlock); 42693907Szh199473 return (DDI_INTR_CLAIMED); 42703907Szh199473 } 42713907Szh199473 retval = bge_status_sync(bgep, STATUS_FLAG_UPDATED, 42723907Szh199473 &flags); 42733907Szh199473 if (retval != DDI_FM_OK) { 42743907Szh199473 bgep->bge_dma_error = B_TRUE; 42753907Szh199473 goto chip_stop; 42761369Sdduvall } 42771369Sdduvall 42783907Szh199473 if (!(flags & STATUS_FLAG_UPDATED)) 42793907Szh199473 break; 42803907Szh199473 42813907Szh199473 /* 42823907Szh199473 * Tell the chip that we're processing the interrupt 42833907Szh199473 */ 42843907Szh199473 bge_mbx_put(bgep, INTERRUPT_MBOX_0_REG, 42853907Szh199473 INTERRUPT_MBOX_DISABLE(flags)); 42863907Szh199473 if (bge_check_acc_handle(bgep, bgep->io_handle) != 42873907Szh199473 DDI_FM_OK) 42883907Szh199473 goto chip_stop; 42893907Szh199473 42901369Sdduvall /* 42913907Szh199473 * Drop the mutex while we: 42923907Szh199473 * Receive any newly-arrived packets 42933907Szh199473 * Recycle any newly-finished send buffers 42941369Sdduvall */ 42953907Szh199473 bgep->bge_intr_running = B_TRUE; 42963907Szh199473 mutex_exit(bgep->genlock); 42973907Szh199473 bge_receive(bgep, bsp); 42983907Szh199473 bge_recycle(bgep, bsp); 42993907Szh199473 mutex_enter(bgep->genlock); 43003907Szh199473 bgep->bge_intr_running = B_FALSE; 43011369Sdduvall 43021369Sdduvall /* 43033907Szh199473 * Tell the chip we've finished processing, and 43043907Szh199473 * give it the tag that we got from the status 43053907Szh199473 * block earlier, so that it knows just how far 43063907Szh199473 * we've gone. If it's got more for us to do, 43073907Szh199473 * it will now update the status block and try 43083907Szh199473 * to assert an interrupt (but we've got the 43093907Szh199473 * #INTA blocked at present). If we see the 43103907Szh199473 * update, we'll loop around to do some more. 43113907Szh199473 * Eventually we'll get out of here ... 43123907Szh199473 */ 43133907Szh199473 bge_mbx_put(bgep, INTERRUPT_MBOX_0_REG, 43143907Szh199473 INTERRUPT_MBOX_ENABLE(flags)); 43156546Sgh162552 if (bgep->chipid.pci_type == BGE_PCI_E) 43166546Sgh162552 (void) bge_mbx_get(bgep, INTERRUPT_MBOX_0_REG); 43173907Szh199473 bgep->missed_dmas = 0; 43183907Szh199473 } 43193907Szh199473 43203907Szh199473 /* 43213907Szh199473 * Check for exceptional conditions that we need to handle 43223907Szh199473 * 43233907Szh199473 * Link status changed 43243907Szh199473 * Status block not updated 43253907Szh199473 */ 43263907Szh199473 if (flags & STATUS_FLAG_LINK_CHANGED) 43273907Szh199473 bge_wake_factotum(bgep); 43283907Szh199473 43293907Szh199473 if (bgep->missed_dmas) { 43303907Szh199473 /* 43313907Szh199473 * Probably due to the internal status tag not 43323907Szh199473 * being reset. Force a status block update now; 43333907Szh199473 * this should ensure that we get an update and 43343907Szh199473 * a new interrupt. After that, we should be in 43353907Szh199473 * sync again ... 43361369Sdduvall */ 43373907Szh199473 BGE_REPORT((bgep, "interrupt: flags 0x%llx - " 43383907Szh199473 "not updated?", flags)); 43393907Szh199473 bgep->missed_updates++; 43403907Szh199473 bge_reg_set32(bgep, HOST_COALESCE_MODE_REG, 43413907Szh199473 COALESCE_NOW); 43423907Szh199473 43433907Szh199473 if (bgep->missed_dmas >= bge_dma_miss_limit) { 43443907Szh199473 /* 43453907Szh199473 * If this happens multiple times in a row, 43463907Szh199473 * it means DMA is just not working. Maybe 43473907Szh199473 * the chip's failed, or maybe there's a 43483907Szh199473 * problem on the PCI bus or in the host-PCI 43493907Szh199473 * bridge (Tomatillo). 43503907Szh199473 * 43513907Szh199473 * At all events, we want to stop further 43523907Szh199473 * interrupts and let the recovery code take 43533907Szh199473 * over to see whether anything can be done 43543907Szh199473 * about it ... 43553907Szh199473 */ 43563907Szh199473 bge_fm_ereport(bgep, 43573907Szh199473 DDI_FM_DEVICE_BADINT_LIMIT); 43583907Szh199473 goto chip_stop; 43591369Sdduvall } 43601369Sdduvall } 43611369Sdduvall 43623907Szh199473 /* 43633907Szh199473 * Reenable assertion of #INTA, unless there's a DMA fault 43643907Szh199473 */ 43653907Szh199473 if (bgep->intr_type == DDI_INTR_TYPE_FIXED) { 43663907Szh199473 bge_reg_clr32(bgep, PCI_CONF_BGE_MHCR, 43673907Szh199473 MHCR_MASK_PCI_INT_OUTPUT); 43683907Szh199473 if (bge_check_acc_handle(bgep, bgep->cfg_handle) != 43693907Szh199473 DDI_FM_OK) 43703907Szh199473 goto chip_stop; 43713907Szh199473 } 43723907Szh199473 43731865Sdilpreet if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) 43741865Sdilpreet goto chip_stop; 43751865Sdilpreet 43761865Sdilpreet mutex_exit(bgep->genlock); 43771865Sdilpreet return (result); 43781865Sdilpreet 43791865Sdilpreet chip_stop: 43801865Sdilpreet #ifdef BGE_IPMI_ASF 43811865Sdilpreet if (bgep->asf_enabled && bgep->asf_status == ASF_STAT_RUN) { 43821865Sdilpreet /* 43831865Sdilpreet * We must stop ASF heart beat before 43841865Sdilpreet * bge_chip_stop(), otherwise some 43851865Sdilpreet * computers (ex. IBM HS20 blade 43861865Sdilpreet * server) may crash. 43871865Sdilpreet */ 43881865Sdilpreet bge_asf_update_status(bgep); 43891865Sdilpreet bge_asf_stop_timer(bgep); 43901865Sdilpreet bgep->asf_status = ASF_STAT_STOP; 43911865Sdilpreet 43921865Sdilpreet bge_asf_pre_reset_operations(bgep, BGE_INIT_RESET); 43931865Sdilpreet (void) bge_check_acc_handle(bgep, bgep->cfg_handle); 43941865Sdilpreet } 43951865Sdilpreet #endif 43961865Sdilpreet bge_chip_stop(bgep, B_TRUE); 43971865Sdilpreet (void) bge_check_acc_handle(bgep, bgep->io_handle); 43981369Sdduvall mutex_exit(bgep->genlock); 43991369Sdduvall return (result); 44001369Sdduvall } 44011369Sdduvall 44021369Sdduvall /* 44031369Sdduvall * ========== Factotum, implemented as a softint handler ========== 44041369Sdduvall */ 44051369Sdduvall 44061369Sdduvall #undef BGE_DBG 44071369Sdduvall #define BGE_DBG BGE_DBG_FACT /* debug flag for this code */ 44081369Sdduvall 44091369Sdduvall static void bge_factotum_error_handler(bge_t *bgep); 44101369Sdduvall #pragma no_inline(bge_factotum_error_handler) 44111369Sdduvall 44121369Sdduvall static void 44131369Sdduvall bge_factotum_error_handler(bge_t *bgep) 44141369Sdduvall { 44151369Sdduvall uint32_t flow; 44161369Sdduvall uint32_t rdma; 44171369Sdduvall uint32_t wdma; 44181369Sdduvall uint32_t tmac; 44191369Sdduvall uint32_t rmac; 44201369Sdduvall uint32_t rxrs; 44211369Sdduvall uint32_t txrs = 0; 44221369Sdduvall 44231369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 44241369Sdduvall 44251369Sdduvall /* 44261369Sdduvall * Read all the registers that show the possible 44271369Sdduvall * reasons for the ERROR bit to be asserted 44281369Sdduvall */ 44291369Sdduvall flow = bge_reg_get32(bgep, FLOW_ATTN_REG); 44301369Sdduvall rdma = bge_reg_get32(bgep, READ_DMA_STATUS_REG); 44311369Sdduvall wdma = bge_reg_get32(bgep, WRITE_DMA_STATUS_REG); 44321369Sdduvall tmac = bge_reg_get32(bgep, TRANSMIT_MAC_STATUS_REG); 44331369Sdduvall rmac = bge_reg_get32(bgep, RECEIVE_MAC_STATUS_REG); 44341369Sdduvall rxrs = bge_reg_get32(bgep, RX_RISC_STATE_REG); 44351369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) 44361369Sdduvall txrs = bge_reg_get32(bgep, TX_RISC_STATE_REG); 44371369Sdduvall 44381369Sdduvall BGE_DEBUG(("factotum($%p) flow 0x%x rdma 0x%x wdma 0x%x", 44394588Sml149210 (void *)bgep, flow, rdma, wdma)); 44401369Sdduvall BGE_DEBUG(("factotum($%p) tmac 0x%x rmac 0x%x rxrs 0x%08x txrs 0x%08x", 44414588Sml149210 (void *)bgep, tmac, rmac, rxrs, txrs)); 44421369Sdduvall 44431369Sdduvall /* 44441369Sdduvall * For now, just clear all the errors ... 44451369Sdduvall */ 44461369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) 44471369Sdduvall bge_reg_put32(bgep, TX_RISC_STATE_REG, ~0); 44481369Sdduvall bge_reg_put32(bgep, RX_RISC_STATE_REG, ~0); 44491369Sdduvall bge_reg_put32(bgep, RECEIVE_MAC_STATUS_REG, ~0); 44501369Sdduvall bge_reg_put32(bgep, WRITE_DMA_STATUS_REG, ~0); 44511369Sdduvall bge_reg_put32(bgep, READ_DMA_STATUS_REG, ~0); 44521369Sdduvall bge_reg_put32(bgep, FLOW_ATTN_REG, ~0); 44531369Sdduvall } 44541369Sdduvall 44551369Sdduvall /* 44561369Sdduvall * Handler for hardware link state change. 44571369Sdduvall * 44581369Sdduvall * When this routine is called, the hardware link state has changed 44591369Sdduvall * and the new state is reflected in the param_* variables. Here 44604403Sgd78059 * we must update the softstate and reprogram the MAC to match. 44611369Sdduvall */ 44621369Sdduvall static void bge_factotum_link_handler(bge_t *bgep); 44631369Sdduvall #pragma no_inline(bge_factotum_link_handler) 44641369Sdduvall 44651369Sdduvall static void 44661369Sdduvall bge_factotum_link_handler(bge_t *bgep) 44671369Sdduvall { 44681369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 44691369Sdduvall 44701369Sdduvall /* 44711369Sdduvall * Update the s/w link_state 44721369Sdduvall */ 44731369Sdduvall if (bgep->param_link_up) 44741369Sdduvall bgep->link_state = LINK_STATE_UP; 44751369Sdduvall else 44761369Sdduvall bgep->link_state = LINK_STATE_DOWN; 44771369Sdduvall 44781369Sdduvall /* 44791369Sdduvall * Reprogram the MAC modes to match 44801369Sdduvall */ 44811369Sdduvall bge_sync_mac_modes(bgep); 44821369Sdduvall } 44831369Sdduvall 44841865Sdilpreet static boolean_t bge_factotum_link_check(bge_t *bgep, int *dma_state); 44851369Sdduvall #pragma no_inline(bge_factotum_link_check) 44861369Sdduvall 44871369Sdduvall static boolean_t 44881865Sdilpreet bge_factotum_link_check(bge_t *bgep, int *dma_state) 44891369Sdduvall { 44901369Sdduvall boolean_t check; 44911369Sdduvall uint64_t flags; 44921369Sdduvall uint32_t tmac_status; 44931369Sdduvall 44941369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 44951369Sdduvall 44961369Sdduvall /* 44971369Sdduvall * Get & clear the writable status bits in the Tx status register 44981369Sdduvall * (some bits are write-1-to-clear, others are just readonly). 44991369Sdduvall */ 45001369Sdduvall tmac_status = bge_reg_get32(bgep, TRANSMIT_MAC_STATUS_REG); 45011369Sdduvall bge_reg_put32(bgep, TRANSMIT_MAC_STATUS_REG, tmac_status); 45021369Sdduvall 45031369Sdduvall /* 45041369Sdduvall * Get & clear the ERROR and LINK_CHANGED bits from the status block 45051369Sdduvall */ 45061865Sdilpreet *dma_state = bge_status_sync(bgep, STATUS_FLAG_ERROR | 45071865Sdilpreet STATUS_FLAG_LINK_CHANGED, &flags); 45081865Sdilpreet if (*dma_state != DDI_FM_OK) 45091865Sdilpreet return (B_FALSE); 45101369Sdduvall 45111369Sdduvall /* 45121369Sdduvall * Clear any errors flagged in the status block ... 45131369Sdduvall */ 45141369Sdduvall if (flags & STATUS_FLAG_ERROR) 45151369Sdduvall bge_factotum_error_handler(bgep); 45161369Sdduvall 45171369Sdduvall /* 45181369Sdduvall * We need to check the link status if: 45191369Sdduvall * the status block says there's been a link change 45201369Sdduvall * or there's any discrepancy between the various 45211369Sdduvall * flags indicating the link state (link_state, 45221369Sdduvall * param_link_up, and the LINK STATE bit in the 45231369Sdduvall * Transmit MAC status register). 45241369Sdduvall */ 45251369Sdduvall check = (flags & STATUS_FLAG_LINK_CHANGED) != 0; 45261369Sdduvall switch (bgep->link_state) { 45271369Sdduvall case LINK_STATE_UP: 45281369Sdduvall check |= (bgep->param_link_up == B_FALSE); 45291369Sdduvall check |= ((tmac_status & TRANSMIT_STATUS_LINK_UP) == 0); 45301369Sdduvall break; 45311369Sdduvall 45321369Sdduvall case LINK_STATE_DOWN: 45331369Sdduvall check |= (bgep->param_link_up != B_FALSE); 45341369Sdduvall check |= ((tmac_status & TRANSMIT_STATUS_LINK_UP) != 0); 45351369Sdduvall break; 45361369Sdduvall 45371369Sdduvall default: 45381369Sdduvall check = B_TRUE; 45391369Sdduvall break; 45401369Sdduvall } 45411369Sdduvall 45421369Sdduvall /* 45431369Sdduvall * If <check> is false, we're sure the link hasn't changed. 45441369Sdduvall * If true, however, it's not yet definitive; we have to call 45451369Sdduvall * bge_phys_check() to determine whether the link has settled 45461369Sdduvall * into a new state yet ... and if it has, then call the link 45471369Sdduvall * state change handler.But when the chip is 5700 in Dell 6650 45481369Sdduvall * ,even if check is false, the link may have changed.So we 45491369Sdduvall * have to call bge_phys_check() to determine the link state. 45501369Sdduvall */ 45511369Sdduvall if (check || bgep->chipid.device == DEVICE_ID_5700) { 45521369Sdduvall check = bge_phys_check(bgep); 45531369Sdduvall if (check) 45541369Sdduvall bge_factotum_link_handler(bgep); 45551369Sdduvall } 45561369Sdduvall 45571369Sdduvall return (check); 45581369Sdduvall } 45591369Sdduvall 45601369Sdduvall /* 45611369Sdduvall * Factotum routine to check for Tx stall, using the 'watchdog' counter 45621369Sdduvall */ 45631369Sdduvall static boolean_t bge_factotum_stall_check(bge_t *bgep); 45641369Sdduvall #pragma no_inline(bge_factotum_stall_check) 45651369Sdduvall 45661369Sdduvall static boolean_t 45671369Sdduvall bge_factotum_stall_check(bge_t *bgep) 45681369Sdduvall { 45691369Sdduvall uint32_t dogval; 45701369Sdduvall 45711369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 45721369Sdduvall 45731369Sdduvall /* 45741369Sdduvall * Specific check for Tx stall ... 45751369Sdduvall * 45761369Sdduvall * The 'watchdog' counter is incremented whenever a packet 45771369Sdduvall * is queued, reset to 1 when some (but not all) buffers 45781369Sdduvall * are reclaimed, reset to 0 (disabled) when all buffers 45791369Sdduvall * are reclaimed, and shifted left here. If it exceeds the 45801369Sdduvall * threshold value, the chip is assumed to have stalled and 45811369Sdduvall * is put into the ERROR state. The factotum will then reset 45821369Sdduvall * it on the next pass. 45831369Sdduvall * 45841369Sdduvall * All of which should ensure that we don't get into a state 45851369Sdduvall * where packets are left pending indefinitely! 45861369Sdduvall */ 45871369Sdduvall dogval = bge_atomic_shl32(&bgep->watchdog, 1); 45881369Sdduvall if (dogval < bge_watchdog_count) 45891369Sdduvall return (B_FALSE); 45901369Sdduvall 45913918Sml149210 #if !defined(BGE_NETCONSOLE) 45921369Sdduvall BGE_REPORT((bgep, "Tx stall detected, watchdog code 0x%x", dogval)); 45933918Sml149210 #endif 45941865Sdilpreet bge_fm_ereport(bgep, DDI_FM_DEVICE_STALL); 45951369Sdduvall return (B_TRUE); 45961369Sdduvall } 45971369Sdduvall 45981369Sdduvall /* 45991369Sdduvall * The factotum is woken up when there's something to do that we'd rather 46001369Sdduvall * not do from inside a hardware interrupt handler or high-level cyclic. 46011369Sdduvall * Its two main tasks are: 46021369Sdduvall * reset & restart the chip after an error 46031369Sdduvall * check the link status whenever necessary 46041369Sdduvall */ 46051369Sdduvall uint_t bge_chip_factotum(caddr_t arg); 46061369Sdduvall #pragma no_inline(bge_chip_factotum) 46071369Sdduvall 46081369Sdduvall uint_t 46091369Sdduvall bge_chip_factotum(caddr_t arg) 46101369Sdduvall { 46111369Sdduvall bge_t *bgep; 46121369Sdduvall uint_t result; 46131369Sdduvall boolean_t error; 46141369Sdduvall boolean_t linkchg; 46151865Sdilpreet int dma_state; 46161369Sdduvall 46177099Syt223700 bgep = (void *)arg; 46181369Sdduvall 46191369Sdduvall BGE_TRACE(("bge_chip_factotum($%p)", (void *)bgep)); 46201369Sdduvall 46211369Sdduvall mutex_enter(bgep->softintrlock); 46221369Sdduvall if (bgep->factotum_flag == 0) { 46231369Sdduvall mutex_exit(bgep->softintrlock); 46241369Sdduvall return (DDI_INTR_UNCLAIMED); 46251369Sdduvall } 46261504Sly149593 bgep->factotum_flag = 0; 46271369Sdduvall mutex_exit(bgep->softintrlock); 46281369Sdduvall 46291369Sdduvall result = DDI_INTR_CLAIMED; 46301369Sdduvall error = B_FALSE; 46311369Sdduvall linkchg = B_FALSE; 46321369Sdduvall 46331369Sdduvall mutex_enter(bgep->genlock); 46341369Sdduvall switch (bgep->bge_chip_state) { 46351369Sdduvall default: 46361369Sdduvall break; 46371369Sdduvall 46381369Sdduvall case BGE_CHIP_RUNNING: 46391865Sdilpreet linkchg = bge_factotum_link_check(bgep, &dma_state); 46401369Sdduvall error = bge_factotum_stall_check(bgep); 46411865Sdilpreet if (dma_state != DDI_FM_OK) { 46421865Sdilpreet bgep->bge_dma_error = B_TRUE; 46431865Sdilpreet error = B_TRUE; 46441865Sdilpreet } 46451865Sdilpreet if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) 46461865Sdilpreet error = B_TRUE; 46471865Sdilpreet if (error) 46481865Sdilpreet bgep->bge_chip_state = BGE_CHIP_ERROR; 46491369Sdduvall break; 46501369Sdduvall 46511369Sdduvall case BGE_CHIP_ERROR: 46521369Sdduvall error = B_TRUE; 46531369Sdduvall break; 46541369Sdduvall 46551369Sdduvall case BGE_CHIP_FAULT: 46561369Sdduvall /* 46571369Sdduvall * Fault detected, time to reset ... 46581369Sdduvall */ 46591369Sdduvall if (bge_autorecover) { 46601865Sdilpreet if (!(bgep->progress & PROGRESS_BUFS)) { 46611865Sdilpreet /* 46621865Sdilpreet * if we can't allocate the ring buffers, 46631865Sdilpreet * try later 46641865Sdilpreet */ 46651865Sdilpreet if (bge_alloc_bufs(bgep) != DDI_SUCCESS) { 46661865Sdilpreet mutex_exit(bgep->genlock); 46671865Sdilpreet return (result); 46681865Sdilpreet } 46691865Sdilpreet bgep->progress |= PROGRESS_BUFS; 46701865Sdilpreet } 46711865Sdilpreet if (!(bgep->progress & PROGRESS_INTR)) { 46721865Sdilpreet bge_init_rings(bgep); 46731865Sdilpreet bge_intr_enable(bgep); 46741865Sdilpreet bgep->progress |= PROGRESS_INTR; 46751865Sdilpreet } 46761865Sdilpreet if (!(bgep->progress & PROGRESS_KSTATS)) { 46771865Sdilpreet bge_init_kstats(bgep, 46781865Sdilpreet ddi_get_instance(bgep->devinfo)); 46791865Sdilpreet bgep->progress |= PROGRESS_KSTATS; 46801865Sdilpreet } 46811865Sdilpreet 46821369Sdduvall BGE_REPORT((bgep, "automatic recovery activated")); 46831865Sdilpreet 46841865Sdilpreet if (bge_restart(bgep, B_FALSE) != DDI_SUCCESS) { 46851865Sdilpreet bgep->bge_chip_state = BGE_CHIP_ERROR; 46861865Sdilpreet error = B_TRUE; 46871865Sdilpreet } 46881865Sdilpreet if (bge_check_acc_handle(bgep, bgep->cfg_handle) != 46891865Sdilpreet DDI_FM_OK) { 46901865Sdilpreet bgep->bge_chip_state = BGE_CHIP_ERROR; 46911865Sdilpreet error = B_TRUE; 46921865Sdilpreet } 46931865Sdilpreet if (bge_check_acc_handle(bgep, bgep->io_handle) != 46941865Sdilpreet DDI_FM_OK) { 46951865Sdilpreet bgep->bge_chip_state = BGE_CHIP_ERROR; 46961865Sdilpreet error = B_TRUE; 46971865Sdilpreet } 46981865Sdilpreet if (error == B_FALSE) { 46991408Srandyf #ifdef BGE_IPMI_ASF 47001865Sdilpreet if (bgep->asf_enabled && 47011865Sdilpreet bgep->asf_status != ASF_STAT_RUN) { 47021408Srandyf bgep->asf_timeout_id = timeout( 47031865Sdilpreet bge_asf_heartbeat, (void *)bgep, 47041865Sdilpreet drv_usectohz( 47051865Sdilpreet BGE_ASF_HEARTBEAT_INTERVAL)); 47061408Srandyf bgep->asf_status = ASF_STAT_RUN; 47071408Srandyf } 47081865Sdilpreet #endif 47095903Ssowmini if (!bgep->manual_reset) { 47105903Ssowmini ddi_fm_service_impact(bgep->devinfo, 47115903Ssowmini DDI_SERVICE_RESTORED); 47125903Ssowmini } 47131408Srandyf } 47141369Sdduvall } 47151369Sdduvall break; 47161369Sdduvall } 47171369Sdduvall 47181865Sdilpreet 47191369Sdduvall /* 47201369Sdduvall * If an error is detected, stop the chip now, marking it as 47211369Sdduvall * faulty, so that it will be reset next time through ... 47221865Sdilpreet * 47231865Sdilpreet * Note that if intr_running is set, then bge_intr() has dropped 47241865Sdilpreet * genlock to call bge_receive/bge_recycle. Can't stop the chip at 47251865Sdilpreet * this point so have to wait until the next time the factotum runs. 47261369Sdduvall */ 47271865Sdilpreet if (error && !bgep->bge_intr_running) { 47281408Srandyf #ifdef BGE_IPMI_ASF 47291408Srandyf if (bgep->asf_enabled && (bgep->asf_status == ASF_STAT_RUN)) { 47301408Srandyf /* 47311408Srandyf * We must stop ASF heart beat before bge_chip_stop(), 47321408Srandyf * otherwise some computers (ex. IBM HS20 blade server) 47331408Srandyf * may crash. 47341408Srandyf */ 47351408Srandyf bge_asf_update_status(bgep); 47361408Srandyf bge_asf_stop_timer(bgep); 47371408Srandyf bgep->asf_status = ASF_STAT_STOP; 47381408Srandyf 47391408Srandyf bge_asf_pre_reset_operations(bgep, BGE_INIT_RESET); 47401865Sdilpreet (void) bge_check_acc_handle(bgep, bgep->cfg_handle); 47411408Srandyf } 47421408Srandyf #endif 47431369Sdduvall bge_chip_stop(bgep, B_TRUE); 47441865Sdilpreet (void) bge_check_acc_handle(bgep, bgep->io_handle); 47451408Srandyf } 47461369Sdduvall mutex_exit(bgep->genlock); 47471369Sdduvall 47481369Sdduvall /* 47491369Sdduvall * If the link state changed, tell the world about it. 47501369Sdduvall * Note: can't do this while still holding the mutex. 47511369Sdduvall */ 47526546Sgh162552 if (bgep->link_update_timer == BGE_LINK_UPDATE_TIMEOUT && 47536546Sgh162552 bgep->link_state != LINK_STATE_UNKNOWN) 47546546Sgh162552 linkchg = B_TRUE; 47556546Sgh162552 else if (bgep->link_update_timer < BGE_LINK_UPDATE_TIMEOUT && 47566546Sgh162552 bgep->link_state == LINK_STATE_DOWN) 47576546Sgh162552 linkchg = B_FALSE; 47586546Sgh162552 47596546Sgh162552 if (linkchg) { 47602311Sseb mac_link_update(bgep->mh, bgep->link_state); 47616546Sgh162552 bgep->link_update_timer = BGE_LINK_UPDATE_DONE; 47626546Sgh162552 } 47635903Ssowmini if (bgep->manual_reset) { 47645903Ssowmini bgep->manual_reset = B_FALSE; 47655903Ssowmini } 47661369Sdduvall 47671369Sdduvall return (result); 47681369Sdduvall } 47691369Sdduvall 47701369Sdduvall /* 47711369Sdduvall * High-level cyclic handler 47721369Sdduvall * 47731369Sdduvall * This routine schedules a (low-level) softint callback to the 47741369Sdduvall * factotum, and prods the chip to update the status block (which 47751369Sdduvall * will cause a hardware interrupt when complete). 47761369Sdduvall */ 47771369Sdduvall void bge_chip_cyclic(void *arg); 47781369Sdduvall #pragma no_inline(bge_chip_cyclic) 47791369Sdduvall 47801369Sdduvall void 47811369Sdduvall bge_chip_cyclic(void *arg) 47821369Sdduvall { 47831369Sdduvall bge_t *bgep; 47841369Sdduvall 47851369Sdduvall bgep = arg; 47861369Sdduvall 47871369Sdduvall switch (bgep->bge_chip_state) { 47881369Sdduvall default: 47891369Sdduvall return; 47901369Sdduvall 47911369Sdduvall case BGE_CHIP_RUNNING: 47921369Sdduvall bge_reg_set32(bgep, HOST_COALESCE_MODE_REG, COALESCE_NOW); 47931865Sdilpreet if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) 47941865Sdilpreet ddi_fm_service_impact(bgep->devinfo, 47951865Sdilpreet DDI_SERVICE_UNAFFECTED); 47966546Sgh162552 47976546Sgh162552 if (bgep->link_update_timer < BGE_LINK_UPDATE_TIMEOUT) 47986546Sgh162552 bgep->link_update_timer++; 47996546Sgh162552 48001369Sdduvall break; 48011369Sdduvall 48021369Sdduvall case BGE_CHIP_FAULT: 48031369Sdduvall case BGE_CHIP_ERROR: 48041369Sdduvall break; 48051369Sdduvall } 48061369Sdduvall 48071369Sdduvall bge_wake_factotum(bgep); 48081369Sdduvall } 48091369Sdduvall 48101369Sdduvall 48111369Sdduvall /* 48121369Sdduvall * ========== Ioctl subfunctions ========== 48131369Sdduvall */ 48141369Sdduvall 48151369Sdduvall #undef BGE_DBG 48161369Sdduvall #define BGE_DBG BGE_DBG_PPIO /* debug flag for this code */ 48171369Sdduvall 48181369Sdduvall #if BGE_DEBUGGING || BGE_DO_PPIO 48191369Sdduvall 48201369Sdduvall static void bge_chip_peek_cfg(bge_t *bgep, bge_peekpoke_t *ppd); 48211369Sdduvall #pragma no_inline(bge_chip_peek_cfg) 48221369Sdduvall 48231369Sdduvall static void 48241369Sdduvall bge_chip_peek_cfg(bge_t *bgep, bge_peekpoke_t *ppd) 48251369Sdduvall { 48261369Sdduvall uint64_t regval; 48271369Sdduvall uint64_t regno; 48281369Sdduvall 48291369Sdduvall BGE_TRACE(("bge_chip_peek_cfg($%p, $%p)", 48304588Sml149210 (void *)bgep, (void *)ppd)); 48311369Sdduvall 48321369Sdduvall regno = ppd->pp_acc_offset; 48331369Sdduvall 48341369Sdduvall switch (ppd->pp_acc_size) { 48351369Sdduvall case 1: 48361369Sdduvall regval = pci_config_get8(bgep->cfg_handle, regno); 48371369Sdduvall break; 48381369Sdduvall 48391369Sdduvall case 2: 48401369Sdduvall regval = pci_config_get16(bgep->cfg_handle, regno); 48411369Sdduvall break; 48421369Sdduvall 48431369Sdduvall case 4: 48441369Sdduvall regval = pci_config_get32(bgep->cfg_handle, regno); 48451369Sdduvall break; 48461369Sdduvall 48471369Sdduvall case 8: 48481369Sdduvall regval = pci_config_get64(bgep->cfg_handle, regno); 48491369Sdduvall break; 48501369Sdduvall } 48511369Sdduvall 48521369Sdduvall ppd->pp_acc_data = regval; 48531369Sdduvall } 48541369Sdduvall 48551369Sdduvall static void bge_chip_poke_cfg(bge_t *bgep, bge_peekpoke_t *ppd); 48561369Sdduvall #pragma no_inline(bge_chip_poke_cfg) 48571369Sdduvall 48581369Sdduvall static void 48591369Sdduvall bge_chip_poke_cfg(bge_t *bgep, bge_peekpoke_t *ppd) 48601369Sdduvall { 48611369Sdduvall uint64_t regval; 48621369Sdduvall uint64_t regno; 48631369Sdduvall 48641369Sdduvall BGE_TRACE(("bge_chip_poke_cfg($%p, $%p)", 48654588Sml149210 (void *)bgep, (void *)ppd)); 48661369Sdduvall 48671369Sdduvall regno = ppd->pp_acc_offset; 48681369Sdduvall regval = ppd->pp_acc_data; 48691369Sdduvall 48701369Sdduvall switch (ppd->pp_acc_size) { 48711369Sdduvall case 1: 48721369Sdduvall pci_config_put8(bgep->cfg_handle, regno, regval); 48731369Sdduvall break; 48741369Sdduvall 48751369Sdduvall case 2: 48761369Sdduvall pci_config_put16(bgep->cfg_handle, regno, regval); 48771369Sdduvall break; 48781369Sdduvall 48791369Sdduvall case 4: 48801369Sdduvall pci_config_put32(bgep->cfg_handle, regno, regval); 48811369Sdduvall break; 48821369Sdduvall 48831369Sdduvall case 8: 48841369Sdduvall pci_config_put64(bgep->cfg_handle, regno, regval); 48851369Sdduvall break; 48861369Sdduvall } 48871369Sdduvall } 48881369Sdduvall 48891369Sdduvall static void bge_chip_peek_reg(bge_t *bgep, bge_peekpoke_t *ppd); 48901369Sdduvall #pragma no_inline(bge_chip_peek_reg) 48911369Sdduvall 48921369Sdduvall static void 48931369Sdduvall bge_chip_peek_reg(bge_t *bgep, bge_peekpoke_t *ppd) 48941369Sdduvall { 48951369Sdduvall uint64_t regval; 48961369Sdduvall void *regaddr; 48971369Sdduvall 48981369Sdduvall BGE_TRACE(("bge_chip_peek_reg($%p, $%p)", 48994588Sml149210 (void *)bgep, (void *)ppd)); 49001369Sdduvall 49011369Sdduvall regaddr = PIO_ADDR(bgep, ppd->pp_acc_offset); 49021369Sdduvall 49031369Sdduvall switch (ppd->pp_acc_size) { 49041369Sdduvall case 1: 49051369Sdduvall regval = ddi_get8(bgep->io_handle, regaddr); 49061369Sdduvall break; 49071369Sdduvall 49081369Sdduvall case 2: 49091369Sdduvall regval = ddi_get16(bgep->io_handle, regaddr); 49101369Sdduvall break; 49111369Sdduvall 49121369Sdduvall case 4: 49131369Sdduvall regval = ddi_get32(bgep->io_handle, regaddr); 49141369Sdduvall break; 49151369Sdduvall 49161369Sdduvall case 8: 49171369Sdduvall regval = ddi_get64(bgep->io_handle, regaddr); 49181369Sdduvall break; 49191369Sdduvall } 49201369Sdduvall 49211369Sdduvall ppd->pp_acc_data = regval; 49221369Sdduvall } 49231369Sdduvall 49241369Sdduvall static void bge_chip_poke_reg(bge_t *bgep, bge_peekpoke_t *ppd); 49251369Sdduvall #pragma no_inline(bge_chip_peek_reg) 49261369Sdduvall 49271369Sdduvall static void 49281369Sdduvall bge_chip_poke_reg(bge_t *bgep, bge_peekpoke_t *ppd) 49291369Sdduvall { 49301369Sdduvall uint64_t regval; 49311369Sdduvall void *regaddr; 49321369Sdduvall 49331369Sdduvall BGE_TRACE(("bge_chip_poke_reg($%p, $%p)", 49344588Sml149210 (void *)bgep, (void *)ppd)); 49351369Sdduvall 49361369Sdduvall regaddr = PIO_ADDR(bgep, ppd->pp_acc_offset); 49371369Sdduvall regval = ppd->pp_acc_data; 49381369Sdduvall 49391369Sdduvall switch (ppd->pp_acc_size) { 49401369Sdduvall case 1: 49411369Sdduvall ddi_put8(bgep->io_handle, regaddr, regval); 49421369Sdduvall break; 49431369Sdduvall 49441369Sdduvall case 2: 49451369Sdduvall ddi_put16(bgep->io_handle, regaddr, regval); 49461369Sdduvall break; 49471369Sdduvall 49481369Sdduvall case 4: 49491369Sdduvall ddi_put32(bgep->io_handle, regaddr, regval); 49501369Sdduvall break; 49511369Sdduvall 49521369Sdduvall case 8: 49531369Sdduvall ddi_put64(bgep->io_handle, regaddr, regval); 49541369Sdduvall break; 49551369Sdduvall } 49561369Sdduvall BGE_PCICHK(bgep); 49571369Sdduvall } 49581369Sdduvall 49591369Sdduvall static void bge_chip_peek_nic(bge_t *bgep, bge_peekpoke_t *ppd); 49601369Sdduvall #pragma no_inline(bge_chip_peek_nic) 49611369Sdduvall 49621369Sdduvall static void 49631369Sdduvall bge_chip_peek_nic(bge_t *bgep, bge_peekpoke_t *ppd) 49641369Sdduvall { 49651369Sdduvall uint64_t regoff; 49661369Sdduvall uint64_t regval; 49671369Sdduvall void *regaddr; 49681369Sdduvall 49691369Sdduvall BGE_TRACE(("bge_chip_peek_nic($%p, $%p)", 49704588Sml149210 (void *)bgep, (void *)ppd)); 49711369Sdduvall 49721369Sdduvall regoff = ppd->pp_acc_offset; 49731369Sdduvall bge_nic_setwin(bgep, regoff & ~MWBAR_GRANULE_MASK); 49741369Sdduvall regoff &= MWBAR_GRANULE_MASK; 49751369Sdduvall regoff += NIC_MEM_WINDOW_OFFSET; 49761369Sdduvall regaddr = PIO_ADDR(bgep, regoff); 49771369Sdduvall 49781369Sdduvall switch (ppd->pp_acc_size) { 49791369Sdduvall case 1: 49801369Sdduvall regval = ddi_get8(bgep->io_handle, regaddr); 49811369Sdduvall break; 49821369Sdduvall 49831369Sdduvall case 2: 49841369Sdduvall regval = ddi_get16(bgep->io_handle, regaddr); 49851369Sdduvall break; 49861369Sdduvall 49871369Sdduvall case 4: 49881369Sdduvall regval = ddi_get32(bgep->io_handle, regaddr); 49891369Sdduvall break; 49901369Sdduvall 49911369Sdduvall case 8: 49921369Sdduvall regval = ddi_get64(bgep->io_handle, regaddr); 49931369Sdduvall break; 49941369Sdduvall } 49951369Sdduvall 49961369Sdduvall ppd->pp_acc_data = regval; 49971369Sdduvall } 49981369Sdduvall 49991369Sdduvall static void bge_chip_poke_nic(bge_t *bgep, bge_peekpoke_t *ppd); 50001369Sdduvall #pragma no_inline(bge_chip_poke_nic) 50011369Sdduvall 50021369Sdduvall static void 50031369Sdduvall bge_chip_poke_nic(bge_t *bgep, bge_peekpoke_t *ppd) 50041369Sdduvall { 50051369Sdduvall uint64_t regoff; 50061369Sdduvall uint64_t regval; 50071369Sdduvall void *regaddr; 50081369Sdduvall 50091369Sdduvall BGE_TRACE(("bge_chip_poke_nic($%p, $%p)", 50104588Sml149210 (void *)bgep, (void *)ppd)); 50111369Sdduvall 50121369Sdduvall regoff = ppd->pp_acc_offset; 50131369Sdduvall bge_nic_setwin(bgep, regoff & ~MWBAR_GRANULE_MASK); 50141369Sdduvall regoff &= MWBAR_GRANULE_MASK; 50151369Sdduvall regoff += NIC_MEM_WINDOW_OFFSET; 50161369Sdduvall regaddr = PIO_ADDR(bgep, regoff); 50171369Sdduvall regval = ppd->pp_acc_data; 50181369Sdduvall 50191369Sdduvall switch (ppd->pp_acc_size) { 50201369Sdduvall case 1: 50211369Sdduvall ddi_put8(bgep->io_handle, regaddr, regval); 50221369Sdduvall break; 50231369Sdduvall 50241369Sdduvall case 2: 50251369Sdduvall ddi_put16(bgep->io_handle, regaddr, regval); 50261369Sdduvall break; 50271369Sdduvall 50281369Sdduvall case 4: 50291369Sdduvall ddi_put32(bgep->io_handle, regaddr, regval); 50301369Sdduvall break; 50311369Sdduvall 50321369Sdduvall case 8: 50331369Sdduvall ddi_put64(bgep->io_handle, regaddr, regval); 50341369Sdduvall break; 50351369Sdduvall } 50361369Sdduvall BGE_PCICHK(bgep); 50371369Sdduvall } 50381369Sdduvall 50391369Sdduvall static void bge_chip_peek_mii(bge_t *bgep, bge_peekpoke_t *ppd); 50401369Sdduvall #pragma no_inline(bge_chip_peek_mii) 50411369Sdduvall 50421369Sdduvall static void 50431369Sdduvall bge_chip_peek_mii(bge_t *bgep, bge_peekpoke_t *ppd) 50441369Sdduvall { 50451369Sdduvall BGE_TRACE(("bge_chip_peek_mii($%p, $%p)", 50464588Sml149210 (void *)bgep, (void *)ppd)); 50471369Sdduvall 50481369Sdduvall ppd->pp_acc_data = bge_mii_get16(bgep, ppd->pp_acc_offset/2); 50491369Sdduvall } 50501369Sdduvall 50511369Sdduvall static void bge_chip_poke_mii(bge_t *bgep, bge_peekpoke_t *ppd); 50521369Sdduvall #pragma no_inline(bge_chip_poke_mii) 50531369Sdduvall 50541369Sdduvall static void 50551369Sdduvall bge_chip_poke_mii(bge_t *bgep, bge_peekpoke_t *ppd) 50561369Sdduvall { 50571369Sdduvall BGE_TRACE(("bge_chip_poke_mii($%p, $%p)", 50584588Sml149210 (void *)bgep, (void *)ppd)); 50591369Sdduvall 50601369Sdduvall bge_mii_put16(bgep, ppd->pp_acc_offset/2, ppd->pp_acc_data); 50611369Sdduvall } 50621369Sdduvall 50631369Sdduvall #if BGE_SEE_IO32 50641369Sdduvall 50651369Sdduvall static void bge_chip_peek_seeprom(bge_t *bgep, bge_peekpoke_t *ppd); 50661369Sdduvall #pragma no_inline(bge_chip_peek_seeprom) 50671369Sdduvall 50681369Sdduvall static void 50691369Sdduvall bge_chip_peek_seeprom(bge_t *bgep, bge_peekpoke_t *ppd) 50701369Sdduvall { 50711369Sdduvall uint32_t data; 50721369Sdduvall int err; 50731369Sdduvall 50741369Sdduvall BGE_TRACE(("bge_chip_peek_seeprom($%p, $%p)", 50754588Sml149210 (void *)bgep, (void *)ppd)); 50761369Sdduvall 50771369Sdduvall err = bge_nvmem_rw32(bgep, BGE_SEE_READ, ppd->pp_acc_offset, &data); 50781369Sdduvall ppd->pp_acc_data = err ? ~0ull : data; 50791369Sdduvall } 50801369Sdduvall 50811369Sdduvall static void bge_chip_poke_seeprom(bge_t *bgep, bge_peekpoke_t *ppd); 50821369Sdduvall #pragma no_inline(bge_chip_poke_seeprom) 50831369Sdduvall 50841369Sdduvall static void 50851369Sdduvall bge_chip_poke_seeprom(bge_t *bgep, bge_peekpoke_t *ppd) 50861369Sdduvall { 50871369Sdduvall uint32_t data; 50881369Sdduvall 50891369Sdduvall BGE_TRACE(("bge_chip_poke_seeprom($%p, $%p)", 50904588Sml149210 (void *)bgep, (void *)ppd)); 50911369Sdduvall 50921369Sdduvall data = ppd->pp_acc_data; 50931369Sdduvall (void) bge_nvmem_rw32(bgep, BGE_SEE_WRITE, ppd->pp_acc_offset, &data); 50941369Sdduvall } 50951369Sdduvall #endif /* BGE_SEE_IO32 */ 50961369Sdduvall 50971369Sdduvall #if BGE_FLASH_IO32 50981369Sdduvall 50991369Sdduvall static void bge_chip_peek_flash(bge_t *bgep, bge_peekpoke_t *ppd); 51001369Sdduvall #pragma no_inline(bge_chip_peek_flash) 51011369Sdduvall 51021369Sdduvall static void 51031369Sdduvall bge_chip_peek_flash(bge_t *bgep, bge_peekpoke_t *ppd) 51041369Sdduvall { 51051369Sdduvall uint32_t data; 51061369Sdduvall int err; 51071369Sdduvall 51081369Sdduvall BGE_TRACE(("bge_chip_peek_flash($%p, $%p)", 51094588Sml149210 (void *)bgep, (void *)ppd)); 51101369Sdduvall 51111369Sdduvall err = bge_nvmem_rw32(bgep, BGE_FLASH_READ, ppd->pp_acc_offset, &data); 51121369Sdduvall ppd->pp_acc_data = err ? ~0ull : data; 51131369Sdduvall } 51141369Sdduvall 51151369Sdduvall static void bge_chip_poke_flash(bge_t *bgep, bge_peekpoke_t *ppd); 51161369Sdduvall #pragma no_inline(bge_chip_poke_flash) 51171369Sdduvall 51181369Sdduvall static void 51191369Sdduvall bge_chip_poke_flash(bge_t *bgep, bge_peekpoke_t *ppd) 51201369Sdduvall { 51211369Sdduvall uint32_t data; 51221369Sdduvall 51231369Sdduvall BGE_TRACE(("bge_chip_poke_flash($%p, $%p)", 51244588Sml149210 (void *)bgep, (void *)ppd)); 51251369Sdduvall 51261369Sdduvall data = ppd->pp_acc_data; 51271369Sdduvall (void) bge_nvmem_rw32(bgep, BGE_FLASH_WRITE, 51281369Sdduvall ppd->pp_acc_offset, &data); 51291369Sdduvall } 51301369Sdduvall #endif /* BGE_FLASH_IO32 */ 51311369Sdduvall 51321369Sdduvall static void bge_chip_peek_mem(bge_t *bgep, bge_peekpoke_t *ppd); 51331369Sdduvall #pragma no_inline(bge_chip_peek_mem) 51341369Sdduvall 51351369Sdduvall static void 51361369Sdduvall bge_chip_peek_mem(bge_t *bgep, bge_peekpoke_t *ppd) 51371369Sdduvall { 51381369Sdduvall uint64_t regval; 51391369Sdduvall void *vaddr; 51401369Sdduvall 51411369Sdduvall BGE_TRACE(("bge_chip_peek_bge($%p, $%p)", 51424588Sml149210 (void *)bgep, (void *)ppd)); 51431369Sdduvall 51441369Sdduvall vaddr = (void *)(uintptr_t)ppd->pp_acc_offset; 51451369Sdduvall 51461369Sdduvall switch (ppd->pp_acc_size) { 51471369Sdduvall case 1: 51481369Sdduvall regval = *(uint8_t *)vaddr; 51491369Sdduvall break; 51501369Sdduvall 51511369Sdduvall case 2: 51521369Sdduvall regval = *(uint16_t *)vaddr; 51531369Sdduvall break; 51541369Sdduvall 51551369Sdduvall case 4: 51561369Sdduvall regval = *(uint32_t *)vaddr; 51571369Sdduvall break; 51581369Sdduvall 51591369Sdduvall case 8: 51601369Sdduvall regval = *(uint64_t *)vaddr; 51611369Sdduvall break; 51621369Sdduvall } 51631369Sdduvall 51641369Sdduvall BGE_DEBUG(("bge_chip_peek_mem($%p, $%p) peeked 0x%llx from $%p", 51654588Sml149210 (void *)bgep, (void *)ppd, regval, vaddr)); 51661369Sdduvall 51671369Sdduvall ppd->pp_acc_data = regval; 51681369Sdduvall } 51691369Sdduvall 51701369Sdduvall static void bge_chip_poke_mem(bge_t *bgep, bge_peekpoke_t *ppd); 51711369Sdduvall #pragma no_inline(bge_chip_poke_mem) 51721369Sdduvall 51731369Sdduvall static void 51741369Sdduvall bge_chip_poke_mem(bge_t *bgep, bge_peekpoke_t *ppd) 51751369Sdduvall { 51761369Sdduvall uint64_t regval; 51771369Sdduvall void *vaddr; 51781369Sdduvall 51791369Sdduvall BGE_TRACE(("bge_chip_poke_mem($%p, $%p)", 51804588Sml149210 (void *)bgep, (void *)ppd)); 51811369Sdduvall 51821369Sdduvall vaddr = (void *)(uintptr_t)ppd->pp_acc_offset; 51831369Sdduvall regval = ppd->pp_acc_data; 51841369Sdduvall 51851369Sdduvall BGE_DEBUG(("bge_chip_poke_mem($%p, $%p) poking 0x%llx at $%p", 51864588Sml149210 (void *)bgep, (void *)ppd, regval, vaddr)); 51871369Sdduvall 51881369Sdduvall switch (ppd->pp_acc_size) { 51891369Sdduvall case 1: 51901369Sdduvall *(uint8_t *)vaddr = (uint8_t)regval; 51911369Sdduvall break; 51921369Sdduvall 51931369Sdduvall case 2: 51941369Sdduvall *(uint16_t *)vaddr = (uint16_t)regval; 51951369Sdduvall break; 51961369Sdduvall 51971369Sdduvall case 4: 51981369Sdduvall *(uint32_t *)vaddr = (uint32_t)regval; 51991369Sdduvall break; 52001369Sdduvall 52011369Sdduvall case 8: 52021369Sdduvall *(uint64_t *)vaddr = (uint64_t)regval; 52031369Sdduvall break; 52041369Sdduvall } 52051369Sdduvall } 52061369Sdduvall 52071369Sdduvall static enum ioc_reply bge_pp_ioctl(bge_t *bgep, int cmd, mblk_t *mp, 52081369Sdduvall struct iocblk *iocp); 52091369Sdduvall #pragma no_inline(bge_pp_ioctl) 52101369Sdduvall 52111369Sdduvall static enum ioc_reply 52121369Sdduvall bge_pp_ioctl(bge_t *bgep, int cmd, mblk_t *mp, struct iocblk *iocp) 52131369Sdduvall { 52141369Sdduvall void (*ppfn)(bge_t *bgep, bge_peekpoke_t *ppd); 52151369Sdduvall bge_peekpoke_t *ppd; 52161369Sdduvall dma_area_t *areap; 52171369Sdduvall uint64_t sizemask; 52181369Sdduvall uint64_t mem_va; 52191369Sdduvall uint64_t maxoff; 52201369Sdduvall boolean_t peek; 52211369Sdduvall 52221369Sdduvall switch (cmd) { 52231369Sdduvall default: 52241369Sdduvall /* NOTREACHED */ 52251369Sdduvall bge_error(bgep, "bge_pp_ioctl: invalid cmd 0x%x", cmd); 52261369Sdduvall return (IOC_INVAL); 52271369Sdduvall 52281369Sdduvall case BGE_PEEK: 52291369Sdduvall peek = B_TRUE; 52301369Sdduvall break; 52311369Sdduvall 52321369Sdduvall case BGE_POKE: 52331369Sdduvall peek = B_FALSE; 52341369Sdduvall break; 52351369Sdduvall } 52361369Sdduvall 52371369Sdduvall /* 52381369Sdduvall * Validate format of ioctl 52391369Sdduvall */ 52401369Sdduvall if (iocp->ioc_count != sizeof (bge_peekpoke_t)) 52411369Sdduvall return (IOC_INVAL); 52421369Sdduvall if (mp->b_cont == NULL) 52431369Sdduvall return (IOC_INVAL); 52447099Syt223700 ppd = (void *)mp->b_cont->b_rptr; 52451369Sdduvall 52461369Sdduvall /* 52471369Sdduvall * Validate request parameters 52481369Sdduvall */ 52491369Sdduvall switch (ppd->pp_acc_space) { 52501369Sdduvall default: 52511369Sdduvall return (IOC_INVAL); 52521369Sdduvall 52531369Sdduvall case BGE_PP_SPACE_CFG: 52541369Sdduvall /* 52551369Sdduvall * Config space 52561369Sdduvall */ 52571369Sdduvall sizemask = 8|4|2|1; 52581369Sdduvall mem_va = 0; 52591369Sdduvall maxoff = PCI_CONF_HDR_SIZE; 52601369Sdduvall ppfn = peek ? bge_chip_peek_cfg : bge_chip_poke_cfg; 52611369Sdduvall break; 52621369Sdduvall 52631369Sdduvall case BGE_PP_SPACE_REG: 52641369Sdduvall /* 52651369Sdduvall * Memory-mapped I/O space 52661369Sdduvall */ 52671369Sdduvall sizemask = 8|4|2|1; 52681369Sdduvall mem_va = 0; 52691369Sdduvall maxoff = RIAAR_REGISTER_MAX; 52701369Sdduvall ppfn = peek ? bge_chip_peek_reg : bge_chip_poke_reg; 52711369Sdduvall break; 52721369Sdduvall 52731369Sdduvall case BGE_PP_SPACE_NIC: 52741369Sdduvall /* 52751369Sdduvall * NIC on-chip memory 52761369Sdduvall */ 52771369Sdduvall sizemask = 8|4|2|1; 52781369Sdduvall mem_va = 0; 52791369Sdduvall maxoff = MWBAR_ONCHIP_MAX; 52801369Sdduvall ppfn = peek ? bge_chip_peek_nic : bge_chip_poke_nic; 52811369Sdduvall break; 52821369Sdduvall 52831369Sdduvall case BGE_PP_SPACE_MII: 52841369Sdduvall /* 52851369Sdduvall * PHY's MII registers 52861369Sdduvall * NB: all PHY registers are two bytes, but the 52871369Sdduvall * addresses increment in ones (word addressing). 52881369Sdduvall * So we scale the address here, then undo the 52891369Sdduvall * transformation inside the peek/poke functions. 52901369Sdduvall */ 52911369Sdduvall ppd->pp_acc_offset *= 2; 52921369Sdduvall sizemask = 2; 52931369Sdduvall mem_va = 0; 52941369Sdduvall maxoff = (MII_MAXREG+1)*2; 52951369Sdduvall ppfn = peek ? bge_chip_peek_mii : bge_chip_poke_mii; 52961369Sdduvall break; 52971369Sdduvall 52981369Sdduvall #if BGE_SEE_IO32 52991369Sdduvall case BGE_PP_SPACE_SEEPROM: 53001369Sdduvall /* 53011369Sdduvall * Attached SEEPROM(s), if any. 53021369Sdduvall * NB: we use the high-order bits of the 'address' as 53031369Sdduvall * a device select to accommodate multiple SEEPROMS, 53041369Sdduvall * If each one is the maximum size (64kbytes), this 53051369Sdduvall * makes them appear contiguous. Otherwise, there may 53061369Sdduvall * be holes in the mapping. ENxS doesn't have any 53071369Sdduvall * SEEPROMs anyway ... 53081369Sdduvall */ 53091369Sdduvall sizemask = 4; 53101369Sdduvall mem_va = 0; 53111369Sdduvall maxoff = SEEPROM_DEV_AND_ADDR_MASK; 53121369Sdduvall ppfn = peek ? bge_chip_peek_seeprom : bge_chip_poke_seeprom; 53131369Sdduvall break; 53141369Sdduvall #endif /* BGE_SEE_IO32 */ 53151369Sdduvall 53161369Sdduvall #if BGE_FLASH_IO32 53171369Sdduvall case BGE_PP_SPACE_FLASH: 53181369Sdduvall /* 53191369Sdduvall * Attached Flash device (if any); a maximum of one device 53201369Sdduvall * is currently supported. But it can be up to 1MB (unlike 53211369Sdduvall * the 64k limit on SEEPROMs) so why would you need more ;-) 53221369Sdduvall */ 53231369Sdduvall sizemask = 4; 53241369Sdduvall mem_va = 0; 53251369Sdduvall maxoff = NVM_FLASH_ADDR_MASK; 53261369Sdduvall ppfn = peek ? bge_chip_peek_flash : bge_chip_poke_flash; 53271369Sdduvall break; 53281369Sdduvall #endif /* BGE_FLASH_IO32 */ 53291369Sdduvall 53301369Sdduvall case BGE_PP_SPACE_BGE: 53311369Sdduvall /* 53321369Sdduvall * BGE data structure! 53331369Sdduvall */ 53341369Sdduvall sizemask = 8|4|2|1; 53351369Sdduvall mem_va = (uintptr_t)bgep; 53361369Sdduvall maxoff = sizeof (*bgep); 53371369Sdduvall ppfn = peek ? bge_chip_peek_mem : bge_chip_poke_mem; 53381369Sdduvall break; 53391369Sdduvall 53401369Sdduvall case BGE_PP_SPACE_STATUS: 53411369Sdduvall case BGE_PP_SPACE_STATISTICS: 53421369Sdduvall case BGE_PP_SPACE_TXDESC: 53431369Sdduvall case BGE_PP_SPACE_TXBUFF: 53441369Sdduvall case BGE_PP_SPACE_RXDESC: 53451369Sdduvall case BGE_PP_SPACE_RXBUFF: 53461369Sdduvall /* 53471369Sdduvall * Various DMA_AREAs 53481369Sdduvall */ 53491369Sdduvall switch (ppd->pp_acc_space) { 53501369Sdduvall case BGE_PP_SPACE_TXDESC: 53511369Sdduvall areap = &bgep->tx_desc; 53521369Sdduvall break; 53531369Sdduvall case BGE_PP_SPACE_TXBUFF: 53541369Sdduvall areap = &bgep->tx_buff[0]; 53551369Sdduvall break; 53561369Sdduvall case BGE_PP_SPACE_RXDESC: 53571369Sdduvall areap = &bgep->rx_desc[0]; 53581369Sdduvall break; 53591369Sdduvall case BGE_PP_SPACE_RXBUFF: 53601369Sdduvall areap = &bgep->rx_buff[0]; 53611369Sdduvall break; 53621369Sdduvall case BGE_PP_SPACE_STATUS: 53631369Sdduvall areap = &bgep->status_block; 53641369Sdduvall break; 53651369Sdduvall case BGE_PP_SPACE_STATISTICS: 53661369Sdduvall if (bgep->chipid.statistic_type == BGE_STAT_BLK) 53671369Sdduvall areap = &bgep->statistics; 53681369Sdduvall break; 53691369Sdduvall } 53701369Sdduvall 53711369Sdduvall sizemask = 8|4|2|1; 53721369Sdduvall mem_va = (uintptr_t)areap->mem_va; 53731369Sdduvall maxoff = areap->alength; 53741369Sdduvall ppfn = peek ? bge_chip_peek_mem : bge_chip_poke_mem; 53751369Sdduvall break; 53761369Sdduvall } 53771369Sdduvall 53781369Sdduvall switch (ppd->pp_acc_size) { 53791369Sdduvall default: 53801369Sdduvall return (IOC_INVAL); 53811369Sdduvall 53821369Sdduvall case 8: 53831369Sdduvall case 4: 53841369Sdduvall case 2: 53851369Sdduvall case 1: 53861369Sdduvall if ((ppd->pp_acc_size & sizemask) == 0) 53871369Sdduvall return (IOC_INVAL); 53881369Sdduvall break; 53891369Sdduvall } 53901369Sdduvall 53911369Sdduvall if ((ppd->pp_acc_offset % ppd->pp_acc_size) != 0) 53921369Sdduvall return (IOC_INVAL); 53931369Sdduvall 53941369Sdduvall if (ppd->pp_acc_offset >= maxoff) 53951369Sdduvall return (IOC_INVAL); 53961369Sdduvall 53971369Sdduvall if (ppd->pp_acc_offset+ppd->pp_acc_size > maxoff) 53981369Sdduvall return (IOC_INVAL); 53991369Sdduvall 54001369Sdduvall /* 54011369Sdduvall * All OK - go do it! 54021369Sdduvall */ 54031369Sdduvall ppd->pp_acc_offset += mem_va; 54041369Sdduvall (*ppfn)(bgep, ppd); 54051369Sdduvall return (peek ? IOC_REPLY : IOC_ACK); 54061369Sdduvall } 54071369Sdduvall 54081369Sdduvall static enum ioc_reply bge_diag_ioctl(bge_t *bgep, int cmd, mblk_t *mp, 54091369Sdduvall struct iocblk *iocp); 54101369Sdduvall #pragma no_inline(bge_diag_ioctl) 54111369Sdduvall 54121369Sdduvall static enum ioc_reply 54131369Sdduvall bge_diag_ioctl(bge_t *bgep, int cmd, mblk_t *mp, struct iocblk *iocp) 54141369Sdduvall { 54151369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 54161369Sdduvall 54171369Sdduvall switch (cmd) { 54181369Sdduvall default: 54191369Sdduvall /* NOTREACHED */ 54201369Sdduvall bge_error(bgep, "bge_diag_ioctl: invalid cmd 0x%x", cmd); 54211369Sdduvall return (IOC_INVAL); 54221369Sdduvall 54231369Sdduvall case BGE_DIAG: 54241369Sdduvall /* 54251369Sdduvall * Currently a no-op 54261369Sdduvall */ 54271369Sdduvall return (IOC_ACK); 54281369Sdduvall 54291369Sdduvall case BGE_PEEK: 54301369Sdduvall case BGE_POKE: 54311369Sdduvall return (bge_pp_ioctl(bgep, cmd, mp, iocp)); 54321369Sdduvall 54331369Sdduvall case BGE_PHY_RESET: 54341369Sdduvall return (IOC_RESTART_ACK); 54351369Sdduvall 54361369Sdduvall case BGE_SOFT_RESET: 54371369Sdduvall case BGE_HARD_RESET: 54381369Sdduvall /* 54391369Sdduvall * Reset and reinitialise the 570x hardware 54401369Sdduvall */ 54413918Sml149210 bgep->bge_chip_state = BGE_CHIP_FAULT; 54423918Sml149210 ddi_trigger_softintr(bgep->factotum_id); 54431865Sdilpreet (void) bge_restart(bgep, cmd == BGE_HARD_RESET); 54441369Sdduvall return (IOC_ACK); 54451369Sdduvall } 54461369Sdduvall 54471369Sdduvall /* NOTREACHED */ 54481369Sdduvall } 54491369Sdduvall 54501369Sdduvall #endif /* BGE_DEBUGGING || BGE_DO_PPIO */ 54511369Sdduvall 54521369Sdduvall static enum ioc_reply bge_mii_ioctl(bge_t *bgep, int cmd, mblk_t *mp, 54531369Sdduvall struct iocblk *iocp); 54541369Sdduvall #pragma no_inline(bge_mii_ioctl) 54551369Sdduvall 54561369Sdduvall static enum ioc_reply 54571369Sdduvall bge_mii_ioctl(bge_t *bgep, int cmd, mblk_t *mp, struct iocblk *iocp) 54581369Sdduvall { 54591369Sdduvall struct bge_mii_rw *miirwp; 54601369Sdduvall 54611369Sdduvall /* 54621369Sdduvall * Validate format of ioctl 54631369Sdduvall */ 54641369Sdduvall if (iocp->ioc_count != sizeof (struct bge_mii_rw)) 54651369Sdduvall return (IOC_INVAL); 54661369Sdduvall if (mp->b_cont == NULL) 54671369Sdduvall return (IOC_INVAL); 54687099Syt223700 miirwp = (void *)mp->b_cont->b_rptr; 54691369Sdduvall 54701369Sdduvall /* 54711369Sdduvall * Validate request parameters ... 54721369Sdduvall */ 54731369Sdduvall if (miirwp->mii_reg > MII_MAXREG) 54741369Sdduvall return (IOC_INVAL); 54751369Sdduvall 54761369Sdduvall switch (cmd) { 54771369Sdduvall default: 54781369Sdduvall /* NOTREACHED */ 54791369Sdduvall bge_error(bgep, "bge_mii_ioctl: invalid cmd 0x%x", cmd); 54801369Sdduvall return (IOC_INVAL); 54811369Sdduvall 54821369Sdduvall case BGE_MII_READ: 54831369Sdduvall miirwp->mii_data = bge_mii_get16(bgep, miirwp->mii_reg); 54841369Sdduvall return (IOC_REPLY); 54851369Sdduvall 54861369Sdduvall case BGE_MII_WRITE: 54871369Sdduvall bge_mii_put16(bgep, miirwp->mii_reg, miirwp->mii_data); 54881369Sdduvall return (IOC_ACK); 54891369Sdduvall } 54901369Sdduvall 54911369Sdduvall /* NOTREACHED */ 54921369Sdduvall } 54931369Sdduvall 54941369Sdduvall #if BGE_SEE_IO32 54951369Sdduvall 54961369Sdduvall static enum ioc_reply bge_see_ioctl(bge_t *bgep, int cmd, mblk_t *mp, 54971369Sdduvall struct iocblk *iocp); 54981369Sdduvall #pragma no_inline(bge_see_ioctl) 54991369Sdduvall 55001369Sdduvall static enum ioc_reply 55011369Sdduvall bge_see_ioctl(bge_t *bgep, int cmd, mblk_t *mp, struct iocblk *iocp) 55021369Sdduvall { 55031369Sdduvall struct bge_see_rw *seerwp; 55041369Sdduvall 55051369Sdduvall /* 55061369Sdduvall * Validate format of ioctl 55071369Sdduvall */ 55081369Sdduvall if (iocp->ioc_count != sizeof (struct bge_see_rw)) 55091369Sdduvall return (IOC_INVAL); 55101369Sdduvall if (mp->b_cont == NULL) 55111369Sdduvall return (IOC_INVAL); 55127099Syt223700 seerwp = (void *)mp->b_cont->b_rptr; 55131369Sdduvall 55141369Sdduvall /* 55151369Sdduvall * Validate request parameters ... 55161369Sdduvall */ 55171369Sdduvall if (seerwp->see_addr & ~SEEPROM_DEV_AND_ADDR_MASK) 55181369Sdduvall return (IOC_INVAL); 55191369Sdduvall 55201369Sdduvall switch (cmd) { 55211369Sdduvall default: 55221369Sdduvall /* NOTREACHED */ 55231369Sdduvall bge_error(bgep, "bge_see_ioctl: invalid cmd 0x%x", cmd); 55241369Sdduvall return (IOC_INVAL); 55251369Sdduvall 55261369Sdduvall case BGE_SEE_READ: 55271369Sdduvall case BGE_SEE_WRITE: 55281369Sdduvall iocp->ioc_error = bge_nvmem_rw32(bgep, cmd, 55291369Sdduvall seerwp->see_addr, &seerwp->see_data); 55301369Sdduvall return (IOC_REPLY); 55311369Sdduvall } 55321369Sdduvall 55331369Sdduvall /* NOTREACHED */ 55341369Sdduvall } 55351369Sdduvall 55361369Sdduvall #endif /* BGE_SEE_IO32 */ 55371369Sdduvall 55381369Sdduvall #if BGE_FLASH_IO32 55391369Sdduvall 55401369Sdduvall static enum ioc_reply bge_flash_ioctl(bge_t *bgep, int cmd, mblk_t *mp, 55411369Sdduvall struct iocblk *iocp); 55421369Sdduvall #pragma no_inline(bge_flash_ioctl) 55431369Sdduvall 55441369Sdduvall static enum ioc_reply 55451369Sdduvall bge_flash_ioctl(bge_t *bgep, int cmd, mblk_t *mp, struct iocblk *iocp) 55461369Sdduvall { 55471369Sdduvall struct bge_flash_rw *flashrwp; 55481369Sdduvall 55491369Sdduvall /* 55501369Sdduvall * Validate format of ioctl 55511369Sdduvall */ 55521369Sdduvall if (iocp->ioc_count != sizeof (struct bge_flash_rw)) 55531369Sdduvall return (IOC_INVAL); 55541369Sdduvall if (mp->b_cont == NULL) 55551369Sdduvall return (IOC_INVAL); 55567099Syt223700 flashrwp = (void *)mp->b_cont->b_rptr; 55571369Sdduvall 55581369Sdduvall /* 55591369Sdduvall * Validate request parameters ... 55601369Sdduvall */ 55611369Sdduvall if (flashrwp->flash_addr & ~NVM_FLASH_ADDR_MASK) 55621369Sdduvall return (IOC_INVAL); 55631369Sdduvall 55641369Sdduvall switch (cmd) { 55651369Sdduvall default: 55661369Sdduvall /* NOTREACHED */ 55671369Sdduvall bge_error(bgep, "bge_flash_ioctl: invalid cmd 0x%x", cmd); 55681369Sdduvall return (IOC_INVAL); 55691369Sdduvall 55701369Sdduvall case BGE_FLASH_READ: 55711369Sdduvall case BGE_FLASH_WRITE: 55721369Sdduvall iocp->ioc_error = bge_nvmem_rw32(bgep, cmd, 55731369Sdduvall flashrwp->flash_addr, &flashrwp->flash_data); 55741369Sdduvall return (IOC_REPLY); 55751369Sdduvall } 55761369Sdduvall 55771369Sdduvall /* NOTREACHED */ 55781369Sdduvall } 55791369Sdduvall 55801369Sdduvall #endif /* BGE_FLASH_IO32 */ 55811369Sdduvall 55821369Sdduvall enum ioc_reply bge_chip_ioctl(bge_t *bgep, queue_t *wq, mblk_t *mp, 55831369Sdduvall struct iocblk *iocp); 55841369Sdduvall #pragma no_inline(bge_chip_ioctl) 55851369Sdduvall 55861369Sdduvall enum ioc_reply 55871369Sdduvall bge_chip_ioctl(bge_t *bgep, queue_t *wq, mblk_t *mp, struct iocblk *iocp) 55881369Sdduvall { 55891369Sdduvall int cmd; 55901369Sdduvall 55911369Sdduvall BGE_TRACE(("bge_chip_ioctl($%p, $%p, $%p, $%p)", 55924588Sml149210 (void *)bgep, (void *)wq, (void *)mp, (void *)iocp)); 55931369Sdduvall 55941369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 55951369Sdduvall 55961369Sdduvall cmd = iocp->ioc_cmd; 55971369Sdduvall switch (cmd) { 55981369Sdduvall default: 55991369Sdduvall /* NOTREACHED */ 56001369Sdduvall bge_error(bgep, "bge_chip_ioctl: invalid cmd 0x%x", cmd); 56011369Sdduvall return (IOC_INVAL); 56021369Sdduvall 56031369Sdduvall case BGE_DIAG: 56041369Sdduvall case BGE_PEEK: 56051369Sdduvall case BGE_POKE: 56061369Sdduvall case BGE_PHY_RESET: 56071369Sdduvall case BGE_SOFT_RESET: 56081369Sdduvall case BGE_HARD_RESET: 56091369Sdduvall #if BGE_DEBUGGING || BGE_DO_PPIO 56101369Sdduvall return (bge_diag_ioctl(bgep, cmd, mp, iocp)); 56111369Sdduvall #else 56121369Sdduvall return (IOC_INVAL); 56131369Sdduvall #endif /* BGE_DEBUGGING || BGE_DO_PPIO */ 56141369Sdduvall 56151369Sdduvall case BGE_MII_READ: 56161369Sdduvall case BGE_MII_WRITE: 56171369Sdduvall return (bge_mii_ioctl(bgep, cmd, mp, iocp)); 56181369Sdduvall 56191369Sdduvall #if BGE_SEE_IO32 56201369Sdduvall case BGE_SEE_READ: 56211369Sdduvall case BGE_SEE_WRITE: 56221369Sdduvall return (bge_see_ioctl(bgep, cmd, mp, iocp)); 56231369Sdduvall #endif /* BGE_SEE_IO32 */ 56241369Sdduvall 56251369Sdduvall #if BGE_FLASH_IO32 56261369Sdduvall case BGE_FLASH_READ: 56271369Sdduvall case BGE_FLASH_WRITE: 56281369Sdduvall return (bge_flash_ioctl(bgep, cmd, mp, iocp)); 56291369Sdduvall #endif /* BGE_FLASH_IO32 */ 56301369Sdduvall } 56311369Sdduvall 56321369Sdduvall /* NOTREACHED */ 56331369Sdduvall } 56341369Sdduvall 56358275SEric Cheng /* ARGSUSED */ 56361369Sdduvall void 56378275SEric Cheng bge_chip_blank(void *arg, time_t ticks, uint_t count, int flag) 56381369Sdduvall { 56398275SEric Cheng recv_ring_t *rrp = arg; 56408275SEric Cheng bge_t *bgep = rrp->bgep; 56411369Sdduvall 56421865Sdilpreet mutex_enter(bgep->genlock); 56438275SEric Cheng rrp->poll_flag = flag; 56448275SEric Cheng #ifdef NOT_YET 56458275SEric Cheng /* 56468275SEric Cheng * XXX-Sunay: Since most broadcom cards support only one 56478275SEric Cheng * interrupt but multiple rx rings, we can't disable the 56488275SEric Cheng * physical interrupt. This need to be done via capability 56498275SEric Cheng * negotiation depending on the NIC. 56508275SEric Cheng */ 56511369Sdduvall bge_reg_put32(bgep, RCV_COALESCE_TICKS_REG, ticks); 56521369Sdduvall bge_reg_put32(bgep, RCV_COALESCE_MAX_BD_REG, count); 56538275SEric Cheng #endif 56541865Sdilpreet if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) 56551865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_UNAFFECTED); 56561865Sdilpreet mutex_exit(bgep->genlock); 56571369Sdduvall } 56581408Srandyf 56591408Srandyf #ifdef BGE_IPMI_ASF 56601408Srandyf 56611408Srandyf uint32_t 56621408Srandyf bge_nic_read32(bge_t *bgep, bge_regno_t addr) 56631408Srandyf { 56641408Srandyf uint32_t data; 56651408Srandyf 56663918Sml149210 #ifndef __sparc 56671408Srandyf if (!bgep->asf_wordswapped) { 56681408Srandyf /* a workaround word swap error */ 56691408Srandyf if (addr & 4) 56701408Srandyf addr = addr - 4; 56711408Srandyf else 56721408Srandyf addr = addr + 4; 56731408Srandyf } 56743918Sml149210 #endif 56751408Srandyf 56761408Srandyf pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_MWBAR, addr); 56771408Srandyf data = pci_config_get32(bgep->cfg_handle, PCI_CONF_BGE_MWDAR); 56781408Srandyf pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_MWBAR, 0); 56791408Srandyf 56803918Sml149210 data = LE_32(data); 56811408Srandyf return (data); 56821408Srandyf } 56831408Srandyf 56841408Srandyf void 56851408Srandyf bge_asf_update_status(bge_t *bgep) 56861408Srandyf { 56871408Srandyf uint32_t event; 56881408Srandyf 56891408Srandyf bge_nic_put32(bgep, BGE_CMD_MAILBOX, BGE_CMD_NICDRV_ALIVE); 56901408Srandyf bge_nic_put32(bgep, BGE_CMD_LENGTH_MAILBOX, 4); 56911408Srandyf bge_nic_put32(bgep, BGE_CMD_DATA_MAILBOX, 3); 56921408Srandyf 56931408Srandyf event = bge_reg_get32(bgep, RX_RISC_EVENT_REG); 56941408Srandyf bge_reg_put32(bgep, RX_RISC_EVENT_REG, event | RRER_ASF_EVENT); 56951408Srandyf } 56961408Srandyf 56971408Srandyf 56981408Srandyf /* 56991408Srandyf * The driver is supposed to notify ASF that the OS is still running 57001408Srandyf * every three seconds, otherwise the management server may attempt 57011408Srandyf * to reboot the machine. If it hasn't actually failed, this is 57022135Szh199473 * not a desirable result. However, this isn't running as a real-time 57031408Srandyf * thread, and even if it were, it might not be able to generate the 57041408Srandyf * heartbeat in a timely manner due to system load. As it isn't a 57051408Srandyf * significant strain on the machine, we will set the interval to half 57061408Srandyf * of the required value. 57071408Srandyf */ 57081408Srandyf void 57091865Sdilpreet bge_asf_heartbeat(void *arg) 57101408Srandyf { 57111865Sdilpreet bge_t *bgep = (bge_t *)arg; 57121865Sdilpreet 57131865Sdilpreet mutex_enter(bgep->genlock); 57141408Srandyf bge_asf_update_status((bge_t *)bgep); 57151865Sdilpreet if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) 57161865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_DEGRADED); 57171865Sdilpreet if (bge_check_acc_handle(bgep, bgep->cfg_handle) != DDI_FM_OK) 57181865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_DEGRADED); 57191865Sdilpreet mutex_exit(bgep->genlock); 57201408Srandyf ((bge_t *)bgep)->asf_timeout_id = timeout(bge_asf_heartbeat, bgep, 57214588Sml149210 drv_usectohz(BGE_ASF_HEARTBEAT_INTERVAL)); 57221408Srandyf } 57231408Srandyf 57241408Srandyf 57251408Srandyf void 57261408Srandyf bge_asf_stop_timer(bge_t *bgep) 57271408Srandyf { 57281408Srandyf timeout_id_t tmp_id = 0; 57291408Srandyf 57301408Srandyf while ((bgep->asf_timeout_id != 0) && 57314588Sml149210 (tmp_id != bgep->asf_timeout_id)) { 57321408Srandyf tmp_id = bgep->asf_timeout_id; 57331408Srandyf (void) untimeout(tmp_id); 57341408Srandyf } 57351408Srandyf bgep->asf_timeout_id = 0; 57361408Srandyf } 57371408Srandyf 57381408Srandyf 57391408Srandyf 57401408Srandyf /* 57412135Szh199473 * This function should be placed at the earliest position of bge_attach(). 57421408Srandyf */ 57431408Srandyf void 57441408Srandyf bge_asf_get_config(bge_t *bgep) 57451408Srandyf { 57461408Srandyf uint32_t nicsig; 57471408Srandyf uint32_t niccfg; 57481408Srandyf 57493918Sml149210 bgep->asf_enabled = B_FALSE; 57501408Srandyf nicsig = bge_nic_read32(bgep, BGE_NIC_DATA_SIG_ADDR); 57511408Srandyf if (nicsig == BGE_NIC_DATA_SIG) { 57521408Srandyf niccfg = bge_nic_read32(bgep, BGE_NIC_DATA_NIC_CFG_ADDR); 57531408Srandyf if (niccfg & BGE_NIC_CFG_ENABLE_ASF) 57541408Srandyf /* 57551408Srandyf * Here, we don't consider BAXTER, because BGE haven't 57561408Srandyf * supported BAXTER (that is 5752). Also, as I know, 57571408Srandyf * BAXTER doesn't support ASF feature. 57581408Srandyf */ 57591408Srandyf bgep->asf_enabled = B_TRUE; 57601408Srandyf else 57611408Srandyf bgep->asf_enabled = B_FALSE; 57621408Srandyf } else 57631408Srandyf bgep->asf_enabled = B_FALSE; 57641408Srandyf } 57651408Srandyf 57661408Srandyf 57671408Srandyf void 57681408Srandyf bge_asf_pre_reset_operations(bge_t *bgep, uint32_t mode) 57691408Srandyf { 57701408Srandyf uint32_t tries; 57711408Srandyf uint32_t event; 57721408Srandyf 57731408Srandyf ASSERT(bgep->asf_enabled); 57741408Srandyf 57751408Srandyf /* Issues "pause firmware" command and wait for ACK */ 57761408Srandyf bge_nic_put32(bgep, BGE_CMD_MAILBOX, BGE_CMD_NICDRV_PAUSE_FW); 57771408Srandyf event = bge_reg_get32(bgep, RX_RISC_EVENT_REG); 57781408Srandyf bge_reg_put32(bgep, RX_RISC_EVENT_REG, event | RRER_ASF_EVENT); 57791408Srandyf 57801408Srandyf event = bge_reg_get32(bgep, RX_RISC_EVENT_REG); 57811408Srandyf tries = 0; 57821408Srandyf while ((event & RRER_ASF_EVENT) && (tries < 100)) { 57831408Srandyf drv_usecwait(1); 57841408Srandyf tries ++; 57851408Srandyf event = bge_reg_get32(bgep, RX_RISC_EVENT_REG); 57861408Srandyf } 57871408Srandyf 57881408Srandyf bge_nic_put32(bgep, BGE_FIRMWARE_MAILBOX, 57894588Sml149210 BGE_MAGIC_NUM_FIRMWARE_INIT_DONE); 57901408Srandyf 57911408Srandyf if (bgep->asf_newhandshake) { 57921408Srandyf switch (mode) { 57931408Srandyf case BGE_INIT_RESET: 57941408Srandyf bge_nic_put32(bgep, BGE_DRV_STATE_MAILBOX, 57954588Sml149210 BGE_DRV_STATE_START); 57961408Srandyf break; 57971408Srandyf case BGE_SHUTDOWN_RESET: 57981408Srandyf bge_nic_put32(bgep, BGE_DRV_STATE_MAILBOX, 57994588Sml149210 BGE_DRV_STATE_UNLOAD); 58001408Srandyf break; 58011408Srandyf case BGE_SUSPEND_RESET: 58021408Srandyf bge_nic_put32(bgep, BGE_DRV_STATE_MAILBOX, 58034588Sml149210 BGE_DRV_STATE_SUSPEND); 58041408Srandyf break; 58051408Srandyf default: 58061408Srandyf break; 58071408Srandyf } 58081408Srandyf } 58091408Srandyf } 58101408Srandyf 58111408Srandyf 58121408Srandyf void 58131408Srandyf bge_asf_post_reset_old_mode(bge_t *bgep, uint32_t mode) 58141408Srandyf { 58151408Srandyf switch (mode) { 58161408Srandyf case BGE_INIT_RESET: 58171408Srandyf bge_nic_put32(bgep, BGE_DRV_STATE_MAILBOX, 58184588Sml149210 BGE_DRV_STATE_START); 58191408Srandyf break; 58201408Srandyf case BGE_SHUTDOWN_RESET: 58211408Srandyf bge_nic_put32(bgep, BGE_DRV_STATE_MAILBOX, 58224588Sml149210 BGE_DRV_STATE_UNLOAD); 58231408Srandyf break; 58241408Srandyf case BGE_SUSPEND_RESET: 58251408Srandyf bge_nic_put32(bgep, BGE_DRV_STATE_MAILBOX, 58264588Sml149210 BGE_DRV_STATE_SUSPEND); 58271408Srandyf break; 58281408Srandyf default: 58291408Srandyf break; 58301408Srandyf } 58311408Srandyf } 58321408Srandyf 58331408Srandyf 58341408Srandyf void 58351408Srandyf bge_asf_post_reset_new_mode(bge_t *bgep, uint32_t mode) 58361408Srandyf { 58371408Srandyf switch (mode) { 58381408Srandyf case BGE_INIT_RESET: 58391408Srandyf bge_nic_put32(bgep, BGE_DRV_STATE_MAILBOX, 58404588Sml149210 BGE_DRV_STATE_START_DONE); 58411408Srandyf break; 58421408Srandyf case BGE_SHUTDOWN_RESET: 58431408Srandyf bge_nic_put32(bgep, BGE_DRV_STATE_MAILBOX, 58444588Sml149210 BGE_DRV_STATE_UNLOAD_DONE); 58451408Srandyf break; 58461408Srandyf default: 58471408Srandyf break; 58481408Srandyf } 58491408Srandyf } 58501408Srandyf 58511408Srandyf #endif /* BGE_IPMI_ASF */ 5852