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 /* 231369Sdduvall * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 241369Sdduvall * Use is subject to license terms. 251369Sdduvall */ 261369Sdduvall 271369Sdduvall #pragma ident "%Z%%M% %I% %E% SMI" 281369Sdduvall 291369Sdduvall #include "sys/bge_impl2.h" 301369Sdduvall 311369Sdduvall #define PIO_ADDR(bgep, offset) ((void *)((caddr_t)(bgep)->io_regs+(offset))) 321369Sdduvall 331369Sdduvall /* 341369Sdduvall * Future features ... ? 351369Sdduvall */ 36*2135Szh199473 #define BGE_CFG_IO8 1 /* 8/16-bit cfg space BIS/BIC */ 371369Sdduvall #define BGE_IND_IO32 0 /* indirect access code */ 381369Sdduvall #define BGE_SEE_IO32 1 /* SEEPROM access code */ 391369Sdduvall #define BGE_FLASH_IO32 1 /* FLASH access code */ 401369Sdduvall 411369Sdduvall /* 421369Sdduvall * BGE MSI tunable: 431369Sdduvall * 441369Sdduvall * By default MSI is enabled on all supported platforms but it is disabled 451369Sdduvall * for some Broadcom chips due to known MSI hardware issues. Currently MSI 461369Sdduvall * is enabled only for 5714C A2 and 5715C A2 broadcom chips. 471369Sdduvall */ 481369Sdduvall #if defined(__sparc) 491369Sdduvall boolean_t bge_enable_msi = B_TRUE; 501369Sdduvall #else 511369Sdduvall boolean_t bge_enable_msi = B_FALSE; 521369Sdduvall #endif 531369Sdduvall 541369Sdduvall /* 551369Sdduvall * Property names 561369Sdduvall */ 571369Sdduvall static char knownids_propname[] = "bge-known-subsystems"; 581369Sdduvall 591369Sdduvall /* 601369Sdduvall * Patchable globals: 611369Sdduvall * 621369Sdduvall * bge_autorecover 631369Sdduvall * Enables/disables automatic recovery after fault detection 641369Sdduvall * 651369Sdduvall * bge_mlcr_default 661369Sdduvall * Value to program into the MLCR; controls the chip's GPIO pins 671369Sdduvall * 681369Sdduvall * bge_dma_{rd,wr}prio 691369Sdduvall * Relative priorities of DMA reads & DMA writes respectively. 701369Sdduvall * These may each be patched to any value 0-3. Equal values 711369Sdduvall * will give "fair" (round-robin) arbitration for PCI access. 721369Sdduvall * Unequal values will give one or the other function priority. 731369Sdduvall * 741369Sdduvall * bge_dma_rwctrl 751369Sdduvall * Value to put in the Read/Write DMA control register. See 761369Sdduvall * the Broadcom PRM for things you can fiddle with in this 771369Sdduvall * register ... 781369Sdduvall * 791369Sdduvall * bge_{tx,rx}_{count,ticks}_{norm,intr} 801369Sdduvall * Send/receive interrupt coalescing parameters. Counts are 811369Sdduvall * #s of descriptors, ticks are in microseconds. *norm* values 821369Sdduvall * apply between status updates/interrupts; the *intr* values 831369Sdduvall * refer to the 'during-interrupt' versions - see the PRM. 841369Sdduvall * 851369Sdduvall * NOTE: these values have been determined by measurement. They 861369Sdduvall * differ significantly from the values recommended in the PRM. 871369Sdduvall */ 881369Sdduvall static uint32_t bge_autorecover = 1; 891369Sdduvall static uint32_t bge_mlcr_default = MLCR_DEFAULT; 901369Sdduvall static uint32_t bge_mlcr_default_5714 = MLCR_DEFAULT_5714; 911369Sdduvall 921369Sdduvall static uint32_t bge_dma_rdprio = 1; 931369Sdduvall static uint32_t bge_dma_wrprio = 0; 941369Sdduvall static uint32_t bge_dma_rwctrl = PDRWCR_VAR_DEFAULT; 951369Sdduvall static uint32_t bge_dma_rwctrl_5721 = PDRWCR_VAR_5721; 961369Sdduvall static uint32_t bge_dma_rwctrl_5714 = PDRWCR_VAR_5714; 971369Sdduvall static uint32_t bge_dma_rwctrl_5715 = PDRWCR_VAR_5715; 981369Sdduvall 991369Sdduvall uint32_t bge_rx_ticks_norm = 128; 1001369Sdduvall uint32_t bge_tx_ticks_norm = 2048; /* 8 for FJ2+ !?!? */ 1011369Sdduvall uint32_t bge_rx_count_norm = 8; 1021369Sdduvall uint32_t bge_tx_count_norm = 128; 1031369Sdduvall 1041369Sdduvall static uint32_t bge_rx_ticks_intr = 128; 1051369Sdduvall static uint32_t bge_tx_ticks_intr = 0; /* 8 for FJ2+ !?!? */ 1061369Sdduvall static uint32_t bge_rx_count_intr = 2; 1071369Sdduvall static uint32_t bge_tx_count_intr = 0; 1081369Sdduvall 1091369Sdduvall /* 1101369Sdduvall * Memory pool configuration parameters. 1111369Sdduvall * 1121369Sdduvall * These are generally specific to each member of the chip family, since 1131369Sdduvall * each one may have a different memory size/configuration. 1141369Sdduvall * 1151369Sdduvall * Setting the mbuf pool length for a specific type of chip to 0 inhibits 1161369Sdduvall * the driver from programming the various registers; instead they are left 1171369Sdduvall * at their hardware defaults. This is the preferred option for later chips 1181369Sdduvall * (5705+), whereas the older chips *required* these registers to be set, 1191369Sdduvall * since the h/w default was 0 ;-( 1201369Sdduvall */ 1211369Sdduvall static uint32_t bge_mbuf_pool_base = MBUF_POOL_BASE_DEFAULT; 1221369Sdduvall static uint32_t bge_mbuf_pool_base_5704 = MBUF_POOL_BASE_5704; 1231369Sdduvall static uint32_t bge_mbuf_pool_base_5705 = MBUF_POOL_BASE_5705; 1241369Sdduvall static uint32_t bge_mbuf_pool_base_5721 = MBUF_POOL_BASE_5721; 1251369Sdduvall static uint32_t bge_mbuf_pool_len = MBUF_POOL_LENGTH_DEFAULT; 1261369Sdduvall static uint32_t bge_mbuf_pool_len_5704 = MBUF_POOL_LENGTH_5704; 1271369Sdduvall static uint32_t bge_mbuf_pool_len_5705 = 0; /* use h/w default */ 1281369Sdduvall static uint32_t bge_mbuf_pool_len_5721 = 0; 1291369Sdduvall 1301369Sdduvall /* 1311369Sdduvall * Various high and low water marks, thresholds, etc ... 1321369Sdduvall * 1331369Sdduvall * Note: these are taken from revision 7 of the PRM, and some are different 1341369Sdduvall * from both the values in earlier PRMs *and* those determined experimentally 1351369Sdduvall * and used in earlier versions of this driver ... 1361369Sdduvall */ 1371369Sdduvall static uint32_t bge_mbuf_hi_water = MBUF_HIWAT_DEFAULT; 1381369Sdduvall static uint32_t bge_mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_DEFAULT; 1391369Sdduvall static uint32_t bge_mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_DEFAULT; 1401369Sdduvall 1411369Sdduvall static uint32_t bge_dmad_lo_water = DMAD_POOL_LOWAT_DEFAULT; 1421369Sdduvall static uint32_t bge_dmad_hi_water = DMAD_POOL_HIWAT_DEFAULT; 1431369Sdduvall static uint32_t bge_lowat_recv_frames = LOWAT_MAX_RECV_FRAMES_DEFAULT; 1441369Sdduvall 1451369Sdduvall static uint32_t bge_replenish_std = STD_RCV_BD_REPLENISH_DEFAULT; 1461369Sdduvall static uint32_t bge_replenish_mini = MINI_RCV_BD_REPLENISH_DEFAULT; 1471369Sdduvall static uint32_t bge_replenish_jumbo = JUMBO_RCV_BD_REPLENISH_DEFAULT; 1481369Sdduvall 1491369Sdduvall static uint32_t bge_watchdog_count = 1 << 16; 1501369Sdduvall static uint16_t bge_dma_miss_limit = 20; 1511369Sdduvall 1521369Sdduvall static uint32_t bge_stop_start_on_sync = 0; 1531369Sdduvall 1541369Sdduvall boolean_t bge_jumbo_enable = B_TRUE; 1551369Sdduvall static uint32_t bge_default_jumbo_size = BGE_JUMBO_BUFF_SIZE; 1561369Sdduvall 1571369Sdduvall /* 1581369Sdduvall * ========== Low-level chip & ring buffer manipulation ========== 1591369Sdduvall */ 1601369Sdduvall 1611369Sdduvall #define BGE_DBG BGE_DBG_REGS /* debug flag for this code */ 1621369Sdduvall 1631369Sdduvall 1641369Sdduvall /* 1651369Sdduvall * Config space read-modify-write routines 1661369Sdduvall */ 1671369Sdduvall 1681369Sdduvall #if BGE_CFG_IO8 1691369Sdduvall 1701369Sdduvall /* 1711369Sdduvall * 8- and 16-bit set/clr operations are not used; all the config registers 1721369Sdduvall * that we need to do bit-twiddling on are 32 bits wide. I'll leave the 1731369Sdduvall * code here, though, in case we ever find that we do want it after all ... 1741369Sdduvall */ 1751369Sdduvall 1761369Sdduvall static void bge_cfg_set8(bge_t *bgep, bge_regno_t regno, uint8_t bits); 1771369Sdduvall #pragma inline(bge_cfg_set8) 1781369Sdduvall 1791369Sdduvall static void 1801369Sdduvall bge_cfg_set8(bge_t *bgep, bge_regno_t regno, uint8_t bits) 1811369Sdduvall { 1821369Sdduvall uint8_t regval; 1831369Sdduvall 1841369Sdduvall BGE_TRACE(("bge_cfg_set8($%p, 0x%lx, 0x%x)", 1851369Sdduvall (void *)bgep, regno, bits)); 1861369Sdduvall 1871369Sdduvall regval = pci_config_get8(bgep->cfg_handle, regno); 1881369Sdduvall 1891369Sdduvall BGE_DEBUG(("bge_cfg_set8($%p, 0x%lx, 0x%x): 0x%x => 0x%x", 1901369Sdduvall (void *)bgep, regno, bits, regval, regval | bits)); 1911369Sdduvall 1921369Sdduvall regval |= bits; 1931369Sdduvall pci_config_put8(bgep->cfg_handle, regno, regval); 1941369Sdduvall } 1951369Sdduvall 1961369Sdduvall static void bge_cfg_clr8(bge_t *bgep, bge_regno_t regno, uint8_t bits); 1971369Sdduvall #pragma inline(bge_cfg_clr8) 1981369Sdduvall 1991369Sdduvall static void 2001369Sdduvall bge_cfg_clr8(bge_t *bgep, bge_regno_t regno, uint8_t bits) 2011369Sdduvall { 2021369Sdduvall uint8_t regval; 2031369Sdduvall 2041369Sdduvall BGE_TRACE(("bge_cfg_clr8($%p, 0x%lx, 0x%x)", 2051369Sdduvall (void *)bgep, regno, bits)); 2061369Sdduvall 2071369Sdduvall regval = pci_config_get8(bgep->cfg_handle, regno); 2081369Sdduvall 2091369Sdduvall BGE_DEBUG(("bge_cfg_clr8($%p, 0x%lx, 0x%x): 0x%x => 0x%x", 2101369Sdduvall (void *)bgep, regno, bits, regval, regval & ~bits)); 2111369Sdduvall 2121369Sdduvall regval &= ~bits; 2131369Sdduvall pci_config_put8(bgep->cfg_handle, regno, regval); 2141369Sdduvall } 2151369Sdduvall 2161369Sdduvall static void bge_cfg_set16(bge_t *bgep, bge_regno_t regno, uint16_t bits); 2171369Sdduvall #pragma inline(bge_cfg_set16) 2181369Sdduvall 2191369Sdduvall static void 2201369Sdduvall bge_cfg_set16(bge_t *bgep, bge_regno_t regno, uint16_t bits) 2211369Sdduvall { 2221369Sdduvall uint16_t regval; 2231369Sdduvall 2241369Sdduvall BGE_TRACE(("bge_cfg_set16($%p, 0x%lx, 0x%x)", 2251369Sdduvall (void *)bgep, regno, bits)); 2261369Sdduvall 2271369Sdduvall regval = pci_config_get16(bgep->cfg_handle, regno); 2281369Sdduvall 2291369Sdduvall BGE_DEBUG(("bge_cfg_set16($%p, 0x%lx, 0x%x): 0x%x => 0x%x", 2301369Sdduvall (void *)bgep, regno, bits, regval, regval | bits)); 2311369Sdduvall 2321369Sdduvall regval |= bits; 2331369Sdduvall pci_config_put16(bgep->cfg_handle, regno, regval); 2341369Sdduvall } 2351369Sdduvall 2361369Sdduvall static void bge_cfg_clr16(bge_t *bgep, bge_regno_t regno, uint16_t bits); 2371369Sdduvall #pragma inline(bge_cfg_clr16) 2381369Sdduvall 2391369Sdduvall static void 2401369Sdduvall bge_cfg_clr16(bge_t *bgep, bge_regno_t regno, uint16_t bits) 2411369Sdduvall { 2421369Sdduvall uint16_t regval; 2431369Sdduvall 2441369Sdduvall BGE_TRACE(("bge_cfg_clr16($%p, 0x%lx, 0x%x)", 2451369Sdduvall (void *)bgep, regno, bits)); 2461369Sdduvall 2471369Sdduvall regval = pci_config_get16(bgep->cfg_handle, regno); 2481369Sdduvall 2491369Sdduvall BGE_DEBUG(("bge_cfg_clr16($%p, 0x%lx, 0x%x): 0x%x => 0x%x", 2501369Sdduvall (void *)bgep, regno, bits, regval, regval & ~bits)); 2511369Sdduvall 2521369Sdduvall regval &= ~bits; 2531369Sdduvall pci_config_put16(bgep->cfg_handle, regno, regval); 2541369Sdduvall } 2551369Sdduvall 2561369Sdduvall #endif /* BGE_CFG_IO8 */ 2571369Sdduvall 2581369Sdduvall static void bge_cfg_set32(bge_t *bgep, bge_regno_t regno, uint32_t bits); 2591369Sdduvall #pragma inline(bge_cfg_set32) 2601369Sdduvall 2611369Sdduvall static void 2621369Sdduvall bge_cfg_set32(bge_t *bgep, bge_regno_t regno, uint32_t bits) 2631369Sdduvall { 2641369Sdduvall uint32_t regval; 2651369Sdduvall 2661369Sdduvall BGE_TRACE(("bge_cfg_set32($%p, 0x%lx, 0x%x)", 2671369Sdduvall (void *)bgep, regno, bits)); 2681369Sdduvall 2691369Sdduvall regval = pci_config_get32(bgep->cfg_handle, regno); 2701369Sdduvall 2711369Sdduvall BGE_DEBUG(("bge_cfg_set32($%p, 0x%lx, 0x%x): 0x%x => 0x%x", 2721369Sdduvall (void *)bgep, regno, bits, regval, regval | bits)); 2731369Sdduvall 2741369Sdduvall regval |= bits; 2751369Sdduvall pci_config_put32(bgep->cfg_handle, regno, regval); 2761369Sdduvall } 2771369Sdduvall 2781369Sdduvall static void bge_cfg_clr32(bge_t *bgep, bge_regno_t regno, uint32_t bits); 2791369Sdduvall #pragma inline(bge_cfg_clr32) 2801369Sdduvall 2811369Sdduvall static void 2821369Sdduvall bge_cfg_clr32(bge_t *bgep, bge_regno_t regno, uint32_t bits) 2831369Sdduvall { 2841369Sdduvall uint32_t regval; 2851369Sdduvall 2861369Sdduvall BGE_TRACE(("bge_cfg_clr32($%p, 0x%lx, 0x%x)", 2871369Sdduvall (void *)bgep, regno, bits)); 2881369Sdduvall 2891369Sdduvall regval = pci_config_get32(bgep->cfg_handle, regno); 2901369Sdduvall 2911369Sdduvall BGE_DEBUG(("bge_cfg_clr32($%p, 0x%lx, 0x%x): 0x%x => 0x%x", 2921369Sdduvall (void *)bgep, regno, bits, regval, regval & ~bits)); 2931369Sdduvall 2941369Sdduvall regval &= ~bits; 2951369Sdduvall pci_config_put32(bgep->cfg_handle, regno, regval); 2961369Sdduvall } 2971369Sdduvall 2981369Sdduvall #if BGE_IND_IO32 2991369Sdduvall 3001369Sdduvall /* 3011369Sdduvall * Indirect access to registers & RISC scratchpads, using config space 3021369Sdduvall * accesses only. 3031369Sdduvall * 3041369Sdduvall * This isn't currently used, but someday we might want to use it for 3051369Sdduvall * restoring the Subsystem Device/Vendor registers (which aren't directly 3061369Sdduvall * writable in Config Space), or for downloading firmware into the RISCs 3071369Sdduvall * 3081369Sdduvall * In any case there are endian issues to be resolved before this code is 3091369Sdduvall * enabled; the bizarre way that bytes get twisted by this chip AND by 3101369Sdduvall * the PCI bridge in SPARC systems mean that we shouldn't enable it until 3111369Sdduvall * it's been thoroughly tested for all access sizes on all supported 3121369Sdduvall * architectures (SPARC *and* x86!). 3131369Sdduvall */ 3141369Sdduvall static uint32_t bge_ind_get32(bge_t *bgep, bge_regno_t regno); 3151369Sdduvall #pragma inline(bge_ind_get32) 3161369Sdduvall 3171369Sdduvall static uint32_t 3181369Sdduvall bge_ind_get32(bge_t *bgep, bge_regno_t regno) 3191369Sdduvall { 3201369Sdduvall uint32_t val; 3211369Sdduvall 3221369Sdduvall BGE_TRACE(("bge_ind_get32($%p, 0x%lx)", (void *)bgep, regno)); 3231369Sdduvall 3241369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 3251369Sdduvall 3261369Sdduvall pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_RIAAR, regno); 3271369Sdduvall val = pci_config_get32(bgep->cfg_handle, PCI_CONF_BGE_RIADR); 3281369Sdduvall 3291369Sdduvall BGE_DEBUG(("bge_ind_get32($%p, 0x%lx) => 0x%x", 3301369Sdduvall (void *)bgep, regno, val)); 3311369Sdduvall 3321369Sdduvall return (val); 3331369Sdduvall } 3341369Sdduvall 3351369Sdduvall static void bge_ind_put32(bge_t *bgep, bge_regno_t regno, uint32_t val); 3361369Sdduvall #pragma inline(bge_ind_put32) 3371369Sdduvall 3381369Sdduvall static void 3391369Sdduvall bge_ind_put32(bge_t *bgep, bge_regno_t regno, uint32_t val) 3401369Sdduvall { 3411369Sdduvall BGE_TRACE(("bge_ind_put32($%p, 0x%lx, 0x%x)", 3421369Sdduvall (void *)bgep, regno, val)); 3431369Sdduvall 3441369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 3451369Sdduvall 3461369Sdduvall pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_RIAAR, regno); 3471369Sdduvall pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_RIADR, val); 3481369Sdduvall } 3491369Sdduvall 3501369Sdduvall #endif /* BGE_IND_IO32 */ 3511369Sdduvall 3521369Sdduvall #if BGE_DEBUGGING 3531369Sdduvall 3541369Sdduvall static void bge_pci_check(bge_t *bgep); 3551369Sdduvall #pragma no_inline(bge_pci_check) 3561369Sdduvall 3571369Sdduvall static void 3581369Sdduvall bge_pci_check(bge_t *bgep) 3591369Sdduvall { 3601369Sdduvall uint16_t pcistatus; 3611369Sdduvall 3621369Sdduvall pcistatus = pci_config_get16(bgep->cfg_handle, PCI_CONF_STAT); 3631369Sdduvall if ((pcistatus & (PCI_STAT_R_MAST_AB | PCI_STAT_R_TARG_AB)) != 0) 3641369Sdduvall BGE_DEBUG(("bge_pci_check($%p): PCI status 0x%x", 3651369Sdduvall (void *)bgep, pcistatus)); 3661369Sdduvall } 3671369Sdduvall 3681369Sdduvall #endif /* BGE_DEBUGGING */ 3691369Sdduvall 3701369Sdduvall /* 3711369Sdduvall * Perform first-stage chip (re-)initialisation, using only config-space 3721369Sdduvall * accesses: 3731369Sdduvall * 3741369Sdduvall * + Read the vendor/device/revision/subsystem/cache-line-size registers, 3751369Sdduvall * returning the data in the structure pointed to by <idp>. 3761369Sdduvall * + Configure the target-mode endianness (swap) options. 3771369Sdduvall * + Disable interrupts and enable Memory Space accesses. 3781369Sdduvall * + Enable or disable Bus Mastering according to the <enable_dma> flag. 3791369Sdduvall * 3801369Sdduvall * This sequence is adapted from Broadcom document 570X-PG102-R, 3811369Sdduvall * page 102, steps 1-3, 6-8 and 11-13. The omitted parts of the sequence 3821369Sdduvall * are 4 and 5 (Reset Core and wait) which are handled elsewhere. 3831369Sdduvall * 3841369Sdduvall * This function MUST be called before any non-config-space accesses 3851369Sdduvall * are made; on this first call <enable_dma> is B_FALSE, and it 3861369Sdduvall * effectively performs steps 3-1(!) of the initialisation sequence 3871369Sdduvall * (the rest are not required but should be harmless). 3881369Sdduvall * 389*2135Szh199473 * It MUST also be called after a chip reset, as this disables 3901369Sdduvall * Memory Space cycles! In this case, <enable_dma> is B_TRUE, and 3911369Sdduvall * it is effectively performing steps 6-8. 3921369Sdduvall */ 3931369Sdduvall void bge_chip_cfg_init(bge_t *bgep, chip_id_t *cidp, boolean_t enable_dma); 3941369Sdduvall #pragma no_inline(bge_chip_cfg_init) 3951369Sdduvall 3961369Sdduvall void 3971369Sdduvall bge_chip_cfg_init(bge_t *bgep, chip_id_t *cidp, boolean_t enable_dma) 3981369Sdduvall { 3991369Sdduvall ddi_acc_handle_t handle; 4001369Sdduvall uint16_t command; 4011369Sdduvall uint32_t mhcr; 4021369Sdduvall uint16_t value16; 4031369Sdduvall int i; 4041369Sdduvall 4051369Sdduvall BGE_TRACE(("bge_chip_cfg_init($%p, $%p, %d)", 4061369Sdduvall (void *)bgep, (void *)cidp, enable_dma)); 4071369Sdduvall 4081369Sdduvall /* 4091369Sdduvall * Step 3: save PCI cache line size and subsystem vendor ID 4101369Sdduvall * 4111369Sdduvall * Read all the config-space registers that characterise the 4121369Sdduvall * chip, specifically vendor/device/revision/subsystem vendor 4131369Sdduvall * and subsystem device id. We expect (but don't check) that 4141369Sdduvall * (vendor == VENDOR_ID_BROADCOM) && (device == DEVICE_ID_5704) 4151369Sdduvall * 416*2135Szh199473 * Also save all bus-transaction related registers (cache-line 4171369Sdduvall * size, bus-grant/latency parameters, etc). Some of these are 4181369Sdduvall * cleared by reset, so we'll have to restore them later. This 4191369Sdduvall * comes from the Broadcom document 570X-PG102-R ... 4201369Sdduvall * 4211369Sdduvall * Note: Broadcom document 570X-PG102-R seems to be in error 4221369Sdduvall * here w.r.t. the offsets of the Subsystem Vendor ID and 4231369Sdduvall * Subsystem (Device) ID registers, which are the opposite way 4241369Sdduvall * round according to the PCI standard. For good measure, we 4251369Sdduvall * save/restore both anyway. 4261369Sdduvall */ 4271369Sdduvall handle = bgep->cfg_handle; 4281369Sdduvall 4291369Sdduvall mhcr = pci_config_get32(handle, PCI_CONF_BGE_MHCR); 4301369Sdduvall cidp->asic_rev = mhcr & MHCR_CHIP_REV_MASK; 4311369Sdduvall cidp->businfo = pci_config_get32(handle, PCI_CONF_BGE_PCISTATE); 4321369Sdduvall cidp->command = pci_config_get16(handle, PCI_CONF_COMM); 4331369Sdduvall 4341369Sdduvall cidp->vendor = pci_config_get16(handle, PCI_CONF_VENID); 4351369Sdduvall cidp->device = pci_config_get16(handle, PCI_CONF_DEVID); 4361369Sdduvall cidp->subven = pci_config_get16(handle, PCI_CONF_SUBVENID); 4371369Sdduvall cidp->subdev = pci_config_get16(handle, PCI_CONF_SUBSYSID); 4381369Sdduvall cidp->revision = pci_config_get8(handle, PCI_CONF_REVID); 4391369Sdduvall cidp->clsize = pci_config_get8(handle, PCI_CONF_CACHE_LINESZ); 4401369Sdduvall cidp->latency = pci_config_get8(handle, PCI_CONF_LATENCY_TIMER); 4411369Sdduvall 4421369Sdduvall BGE_DEBUG(("bge_chip_cfg_init: %s bus is %s and %s; #INTA is %s", 4431369Sdduvall cidp->businfo & PCISTATE_BUS_IS_PCI ? "PCI" : "PCI-X", 4441369Sdduvall cidp->businfo & PCISTATE_BUS_IS_FAST ? "fast" : "slow", 4451369Sdduvall cidp->businfo & PCISTATE_BUS_IS_32_BIT ? "narrow" : "wide", 4461369Sdduvall cidp->businfo & PCISTATE_INTA_STATE ? "high" : "low")); 4471369Sdduvall BGE_DEBUG(("bge_chip_cfg_init: vendor 0x%x device 0x%x revision 0x%x", 4481369Sdduvall cidp->vendor, cidp->device, cidp->revision)); 4491369Sdduvall BGE_DEBUG(("bge_chip_cfg_init: subven 0x%x subdev 0x%x asic_rev 0x%x", 4501369Sdduvall cidp->subven, cidp->subdev, cidp->asic_rev)); 4511369Sdduvall BGE_DEBUG(("bge_chip_cfg_init: clsize %d latency %d command 0x%x", 4521369Sdduvall cidp->clsize, cidp->latency, cidp->command)); 4531369Sdduvall 4541369Sdduvall /* 4551369Sdduvall * Step 2 (also step 6): disable and clear interrupts. 4561369Sdduvall * Steps 11-13: configure PIO endianness options, and enable 4571369Sdduvall * indirect register access. We'll also select any other 458*2135Szh199473 * options controlled by the MHCR (e.g. tagged status, mask 4591369Sdduvall * interrupt mode) at this stage ... 4601369Sdduvall * 4611369Sdduvall * Note: internally, the chip is 64-bit and BIG-endian, but 4621369Sdduvall * since it talks to the host over a (LITTLE-endian) PCI bus, 4631369Sdduvall * it normally swaps bytes around at the PCI interface. 4641369Sdduvall * However, the PCI host bridge on SPARC systems normally 4651369Sdduvall * swaps the byte lanes around too, since SPARCs are also 4661369Sdduvall * BIG-endian. So it turns out that on SPARC, the right 4671369Sdduvall * option is to tell the chip to swap (and the host bridge 4681369Sdduvall * will swap back again), whereas on x86 we ask the chip 4691369Sdduvall * NOT to swap, so the natural little-endianness of the 4701369Sdduvall * PCI bus is assumed. Then the only thing that doesn't 4711369Sdduvall * automatically work right is access to an 8-byte register 4721369Sdduvall * by a little-endian host; but we don't want to set the 4731369Sdduvall * MHCR_ENABLE_REGISTER_WORD_SWAP bit because then 4-byte 4741369Sdduvall * accesses don't go where expected ;-( So we live with 4751369Sdduvall * that, and perform word-swaps in software in the few cases 4761369Sdduvall * where a chip register is defined as an 8-byte value -- 4771369Sdduvall * see the code below for details ... 4781369Sdduvall * 4791369Sdduvall * Note: the meaning of the 'MASK_INTERRUPT_MODE' bit isn't 4801369Sdduvall * very clear in the register description in the PRM, but 4811369Sdduvall * Broadcom document 570X-PG104-R page 248 explains a little 4821369Sdduvall * more (under "Broadcom Mask Mode"). The bit changes the way 4831369Sdduvall * the MASK_PCI_INT_OUTPUT bit works: with MASK_INTERRUPT_MODE 4841369Sdduvall * clear, the chip interprets MASK_PCI_INT_OUTPUT in the same 4851369Sdduvall * way as the 5700 did, which isn't very convenient. Setting 4861369Sdduvall * the MASK_INTERRUPT_MODE bit makes the MASK_PCI_INT_OUTPUT 4871369Sdduvall * bit do just what its name says -- MASK the PCI #INTA output 4881369Sdduvall * (i.e. deassert the signal at the pin) leaving all internal 4891369Sdduvall * state unchanged. This is much more convenient for our 4901369Sdduvall * interrupt handler, so we set MASK_INTERRUPT_MODE here. 4911369Sdduvall * 4921369Sdduvall * Note: the inconvenient semantics of the interrupt mailbox 4931369Sdduvall * (nonzero disables and acknowledges/clears the interrupt, 4941369Sdduvall * zero enables AND CLEARS it) would make race conditions 4951369Sdduvall * likely in the interrupt handler: 4961369Sdduvall * 4971369Sdduvall * (1) acknowledge & disable interrupts 4981369Sdduvall * (2) while (more to do) 4991369Sdduvall * process packets 5001369Sdduvall * (3) enable interrupts -- also clears pending 5011369Sdduvall * 5021369Sdduvall * If the chip received more packets and internally generated 5031369Sdduvall * an interrupt between the check at (2) and the mbox write 5041369Sdduvall * at (3), this interrupt would be lost :-( 5051369Sdduvall * 5061369Sdduvall * The best way to avoid this is to use TAGGED STATUS mode, 5071369Sdduvall * where the chip includes a unique tag in each status block 5081369Sdduvall * update, and the host, when re-enabling interrupts, passes 5091369Sdduvall * the last tag it saw back to the chip; then the chip can 5101369Sdduvall * see whether the host is truly up to date, and regenerate 5111369Sdduvall * its interrupt if not. 5121369Sdduvall */ 5131369Sdduvall mhcr = MHCR_ENABLE_INDIRECT_ACCESS | 5141369Sdduvall MHCR_ENABLE_TAGGED_STATUS_MODE | 5151369Sdduvall MHCR_MASK_INTERRUPT_MODE | 5161369Sdduvall MHCR_CLEAR_INTERRUPT_INTA; 5171369Sdduvall 5181369Sdduvall if (bgep->intr_type == DDI_INTR_TYPE_FIXED) 5191369Sdduvall mhcr |= MHCR_MASK_PCI_INT_OUTPUT; 5201369Sdduvall 5211369Sdduvall #ifdef _BIG_ENDIAN 5221369Sdduvall mhcr |= MHCR_ENABLE_ENDIAN_WORD_SWAP | MHCR_ENABLE_ENDIAN_BYTE_SWAP; 5231369Sdduvall #endif /* _BIG_ENDIAN */ 5241369Sdduvall 5251369Sdduvall pci_config_put32(handle, PCI_CONF_BGE_MHCR, mhcr); 5261369Sdduvall 5271408Srandyf #ifdef BGE_IPMI_ASF 5281408Srandyf bgep->asf_wordswapped = B_FALSE; 5291408Srandyf #endif 5301369Sdduvall /* 5311369Sdduvall * Step 1 (also step 7): Enable PCI Memory Space accesses 5321369Sdduvall * Disable Memory Write/Invalidate 5331369Sdduvall * Enable or disable Bus Mastering 5341369Sdduvall * 5351369Sdduvall * Note that all other bits are taken from the original value saved 5361369Sdduvall * the first time through here, rather than from the current register 5371369Sdduvall * value, 'cos that will have been cleared by a soft RESET since. 5381369Sdduvall * In this way we preserve the OBP/nexus-parent's preferred settings 5391369Sdduvall * of the parity-error and system-error enable bits across multiple 5401369Sdduvall * chip RESETs. 5411369Sdduvall */ 5421369Sdduvall command = bgep->chipid.command | PCI_COMM_MAE; 5431369Sdduvall command &= ~(PCI_COMM_ME|PCI_COMM_MEMWR_INVAL); 5441369Sdduvall if (enable_dma) 5451369Sdduvall command |= PCI_COMM_ME; 5461369Sdduvall /* 5471369Sdduvall * on BCM5714 revision A0, false parity error gets generated 548*2135Szh199473 * due to a logic bug. Provide a workaround by disabling parity 5491369Sdduvall * error. 5501369Sdduvall */ 5511369Sdduvall if (((cidp->device == DEVICE_ID_5714C) || 5521369Sdduvall (cidp->device == DEVICE_ID_5714S)) && 5531369Sdduvall (cidp->revision == REVISION_ID_5714_A0)) { 5541369Sdduvall command &= ~PCI_COMM_PARITY_DETECT; 5551369Sdduvall } 5561369Sdduvall pci_config_put16(handle, PCI_CONF_COMM, command); 5571369Sdduvall 5581369Sdduvall /* 5591369Sdduvall * On some PCI-E device, there were instances when 5601369Sdduvall * the device was still link training. 5611369Sdduvall */ 5621369Sdduvall if (bgep->chipid.pci_type == BGE_PCI_E) { 5631369Sdduvall i = 0; 5641369Sdduvall value16 = pci_config_get16(handle, PCI_CONF_COMM); 5651369Sdduvall while ((value16 != command) && (i < 100)) { 5661369Sdduvall drv_usecwait(200); 5671369Sdduvall value16 = pci_config_get16(handle, PCI_CONF_COMM); 5681369Sdduvall ++i; 5691369Sdduvall } 5701369Sdduvall } 5711369Sdduvall 5721369Sdduvall /* 5731369Sdduvall * Clear any remaining error status bits 5741369Sdduvall */ 5751369Sdduvall pci_config_put16(handle, PCI_CONF_STAT, ~0); 5761369Sdduvall 5771369Sdduvall /* 5782073Svivek * Do following if and only if the device is NOT BCM5714C OR 5792073Svivek * BCM5715C 5801369Sdduvall */ 5812073Svivek if (!((cidp->device == DEVICE_ID_5714C) || 5822073Svivek (cidp->device == DEVICE_ID_5715C))) { 5832073Svivek /* 5842073Svivek * Make sure these indirect-access registers are sane 5852073Svivek * rather than random after power-up or reset 5862073Svivek */ 5872073Svivek pci_config_put32(handle, PCI_CONF_BGE_RIAAR, 0); 5882073Svivek pci_config_put32(handle, PCI_CONF_BGE_MWBAR, 0); 5892073Svivek } 590*2135Szh199473 /* 591*2135Szh199473 * Step 8: Disable PCI-X/PCI-E Relaxed Ordering 592*2135Szh199473 */ 593*2135Szh199473 bge_cfg_clr16(bgep, PCIX_CONF_COMM, PCIX_COMM_RELAXED); 594*2135Szh199473 595*2135Szh199473 if (cidp->pci_type == BGE_PCI_E) 596*2135Szh199473 bge_cfg_clr16(bgep, PCI_CONF_DEV_CTRL, 597*2135Szh199473 DEV_CTRL_NO_SNOOP | DEV_CTRL_RELAXED); 5981369Sdduvall } 5991369Sdduvall 6001369Sdduvall #ifdef __amd64 6011369Sdduvall /* 6021369Sdduvall * Distinguish CPU types 6031369Sdduvall * 6041369Sdduvall * These use to distinguish AMD64 or Intel EM64T of CPU running mode. 6051369Sdduvall * If CPU runs on Intel EM64T mode,the 64bit operation cannot works fine 6061369Sdduvall * for PCI-Express based network interface card. This is the work-around 6071369Sdduvall * for those nics. 6081369Sdduvall */ 6091369Sdduvall static boolean_t bge_get_em64t_type(void); 6101369Sdduvall #pragma inline(bge_get_em64t_type) 6111369Sdduvall 6121369Sdduvall static boolean_t 6131369Sdduvall bge_get_em64t_type(void) 6141369Sdduvall { 6151369Sdduvall 6161369Sdduvall return (x86_vendor == X86_VENDOR_Intel); 6171369Sdduvall } 6181369Sdduvall #endif 6191369Sdduvall 6201369Sdduvall /* 6211369Sdduvall * Operating register get/set access routines 6221369Sdduvall */ 6231369Sdduvall 6241369Sdduvall uint32_t bge_reg_get32(bge_t *bgep, bge_regno_t regno); 6251369Sdduvall #pragma inline(bge_reg_get32) 6261369Sdduvall 6271369Sdduvall uint32_t 6281369Sdduvall bge_reg_get32(bge_t *bgep, bge_regno_t regno) 6291369Sdduvall { 6301369Sdduvall BGE_TRACE(("bge_reg_get32($%p, 0x%lx)", 6311369Sdduvall (void *)bgep, regno)); 6321369Sdduvall 6331369Sdduvall return (ddi_get32(bgep->io_handle, PIO_ADDR(bgep, regno))); 6341369Sdduvall } 6351369Sdduvall 6361369Sdduvall void bge_reg_put32(bge_t *bgep, bge_regno_t regno, uint32_t data); 6371369Sdduvall #pragma inline(bge_reg_put32) 6381369Sdduvall 6391369Sdduvall void 6401369Sdduvall bge_reg_put32(bge_t *bgep, bge_regno_t regno, uint32_t data) 6411369Sdduvall { 6421369Sdduvall BGE_TRACE(("bge_reg_put32($%p, 0x%lx, 0x%x)", 6431369Sdduvall (void *)bgep, regno, data)); 6441369Sdduvall 6451369Sdduvall ddi_put32(bgep->io_handle, PIO_ADDR(bgep, regno), data); 6461369Sdduvall BGE_PCICHK(bgep); 6471369Sdduvall } 6481369Sdduvall 6491369Sdduvall void bge_reg_set32(bge_t *bgep, bge_regno_t regno, uint32_t bits); 6501369Sdduvall #pragma inline(bge_reg_set32) 6511369Sdduvall 6521369Sdduvall void 6531369Sdduvall bge_reg_set32(bge_t *bgep, bge_regno_t regno, uint32_t bits) 6541369Sdduvall { 6551369Sdduvall uint32_t regval; 6561369Sdduvall 6571369Sdduvall BGE_TRACE(("bge_reg_set32($%p, 0x%lx, 0x%x)", 6581369Sdduvall (void *)bgep, regno, bits)); 6591369Sdduvall 6601369Sdduvall regval = bge_reg_get32(bgep, regno); 6611369Sdduvall regval |= bits; 6621369Sdduvall bge_reg_put32(bgep, regno, regval); 6631369Sdduvall } 6641369Sdduvall 6651369Sdduvall void bge_reg_clr32(bge_t *bgep, bge_regno_t regno, uint32_t bits); 6661369Sdduvall #pragma inline(bge_reg_clr32) 6671369Sdduvall 6681369Sdduvall void 6691369Sdduvall bge_reg_clr32(bge_t *bgep, bge_regno_t regno, uint32_t bits) 6701369Sdduvall { 6711369Sdduvall uint32_t regval; 6721369Sdduvall 6731369Sdduvall BGE_TRACE(("bge_reg_clr32($%p, 0x%lx, 0x%x)", 6741369Sdduvall (void *)bgep, regno, bits)); 6751369Sdduvall 6761369Sdduvall regval = bge_reg_get32(bgep, regno); 6771369Sdduvall regval &= ~bits; 6781369Sdduvall bge_reg_put32(bgep, regno, regval); 6791369Sdduvall } 6801369Sdduvall 6811369Sdduvall static uint64_t bge_reg_get64(bge_t *bgep, bge_regno_t regno); 6821369Sdduvall #pragma inline(bge_reg_get64) 6831369Sdduvall 6841369Sdduvall static uint64_t 6851369Sdduvall bge_reg_get64(bge_t *bgep, bge_regno_t regno) 6861369Sdduvall { 6871369Sdduvall uint64_t regval; 6881369Sdduvall 6891369Sdduvall #ifdef __amd64 6901369Sdduvall if (bge_get_em64t_type()) { 6911369Sdduvall regval = ddi_get32(bgep->io_handle, PIO_ADDR(bgep, regno + 4)); 6921369Sdduvall regval <<= 32; 6931369Sdduvall regval |= ddi_get32(bgep->io_handle, PIO_ADDR(bgep, regno)); 6941369Sdduvall } else { 6951369Sdduvall regval = ddi_get64(bgep->io_handle, PIO_ADDR(bgep, regno)); 6961369Sdduvall } 6971369Sdduvall #else 6981369Sdduvall regval = ddi_get64(bgep->io_handle, PIO_ADDR(bgep, regno)); 6991369Sdduvall #endif 7001369Sdduvall 7011369Sdduvall #ifdef _LITTLE_ENDIAN 7021369Sdduvall regval = (regval >> 32) | (regval << 32); 7031369Sdduvall #endif /* _LITTLE_ENDIAN */ 7041369Sdduvall 7051369Sdduvall BGE_TRACE(("bge_reg_get64($%p, 0x%lx) = 0x%016llx", 7061369Sdduvall (void *)bgep, regno, regval)); 7071369Sdduvall 7081369Sdduvall return (regval); 7091369Sdduvall } 7101369Sdduvall 7111369Sdduvall static void bge_reg_put64(bge_t *bgep, bge_regno_t regno, uint64_t data); 7121369Sdduvall #pragma inline(bge_reg_put64) 7131369Sdduvall 7141369Sdduvall static void 7151369Sdduvall bge_reg_put64(bge_t *bgep, bge_regno_t regno, uint64_t data) 7161369Sdduvall { 7171369Sdduvall BGE_TRACE(("bge_reg_put64($%p, 0x%lx, 0x%016llx)", 7181369Sdduvall (void *)bgep, regno, data)); 7191369Sdduvall 7201369Sdduvall #ifdef _LITTLE_ENDIAN 7211369Sdduvall data = ((data >> 32) | (data << 32)); 7221369Sdduvall #endif /* _LITTLE_ENDIAN */ 7231369Sdduvall 7241369Sdduvall #ifdef __amd64 7251369Sdduvall if (bge_get_em64t_type()) { 7261369Sdduvall ddi_put32(bgep->io_handle, 7271369Sdduvall PIO_ADDR(bgep, regno), (uint32_t)data); 7281369Sdduvall BGE_PCICHK(bgep); 7291369Sdduvall ddi_put32(bgep->io_handle, 7301369Sdduvall PIO_ADDR(bgep, regno + 4), (uint32_t)(data >> 32)); 7311369Sdduvall 7321369Sdduvall } else { 7331369Sdduvall ddi_put64(bgep->io_handle, PIO_ADDR(bgep, regno), data); 7341369Sdduvall } 7351369Sdduvall #else 7361369Sdduvall ddi_put64(bgep->io_handle, PIO_ADDR(bgep, regno), data); 7371369Sdduvall #endif 7381369Sdduvall 7391369Sdduvall BGE_PCICHK(bgep); 7401369Sdduvall } 7411369Sdduvall 7421369Sdduvall /* 7431369Sdduvall * The DDI doesn't provide get/put functions for 128 bit data 7441369Sdduvall * so we put RCBs out as two 64-bit chunks instead. 7451369Sdduvall */ 7461369Sdduvall static void bge_reg_putrcb(bge_t *bgep, bge_regno_t addr, bge_rcb_t *rcbp); 7471369Sdduvall #pragma inline(bge_reg_putrcb) 7481369Sdduvall 7491369Sdduvall static void 7501369Sdduvall bge_reg_putrcb(bge_t *bgep, bge_regno_t addr, bge_rcb_t *rcbp) 7511369Sdduvall { 7521369Sdduvall uint64_t *p; 7531369Sdduvall 7541369Sdduvall BGE_TRACE(("bge_reg_putrcb($%p, 0x%lx, 0x%016llx:%04x:%04x:%08x)", 7551369Sdduvall (void *)bgep, addr, rcbp->host_ring_addr, 7561369Sdduvall rcbp->max_len, rcbp->flags, rcbp->nic_ring_addr)); 7571369Sdduvall 7581369Sdduvall ASSERT((addr % sizeof (*rcbp)) == 0); 7591369Sdduvall 7601369Sdduvall p = (void *)rcbp; 7611369Sdduvall bge_reg_put64(bgep, addr, *p++); 7621369Sdduvall bge_reg_put64(bgep, addr+8, *p); 7631369Sdduvall } 7641369Sdduvall 7651369Sdduvall void bge_mbx_put(bge_t *bgep, bge_regno_t regno, uint64_t data); 7661369Sdduvall #pragma inline(bge_mbx_put) 7671369Sdduvall 7681369Sdduvall void 7691369Sdduvall bge_mbx_put(bge_t *bgep, bge_regno_t regno, uint64_t data) 7701369Sdduvall { 7711369Sdduvall BGE_TRACE(("bge_mbx_put($%p, 0x%lx, 0x%016llx)", 7721369Sdduvall (void *)bgep, regno, data)); 7731369Sdduvall 7741369Sdduvall /* 7751369Sdduvall * Mailbox registers are nominally 64 bits on the 5701, but 7761369Sdduvall * the MSW isn't used. On the 5703, they're only 32 bits 7771369Sdduvall * anyway. So here we just write the lower(!) 32 bits - 7781369Sdduvall * remembering that the chip is big-endian, even though the 7791369Sdduvall * PCI bus is little-endian ... 7801369Sdduvall */ 7811369Sdduvall #ifdef _BIG_ENDIAN 7821369Sdduvall ddi_put32(bgep->io_handle, PIO_ADDR(bgep, regno+4), (uint32_t)data); 7831369Sdduvall #else 7841369Sdduvall ddi_put32(bgep->io_handle, PIO_ADDR(bgep, regno), (uint32_t)data); 7851369Sdduvall #endif /* _BIG_ENDIAN */ 7861369Sdduvall BGE_PCICHK(bgep); 7871369Sdduvall } 7881369Sdduvall 7891369Sdduvall #if BGE_DEBUGGING 7901369Sdduvall 7911369Sdduvall void bge_led_mark(bge_t *bgep); 7921369Sdduvall #pragma no_inline(bge_led_mark) 7931369Sdduvall 7941369Sdduvall void 7951369Sdduvall bge_led_mark(bge_t *bgep) 7961369Sdduvall { 7971369Sdduvall uint32_t led_ctrl = LED_CONTROL_OVERRIDE_LINK | 7981369Sdduvall LED_CONTROL_1000MBPS_LED | 7991369Sdduvall LED_CONTROL_100MBPS_LED | 8001369Sdduvall LED_CONTROL_10MBPS_LED; 8011369Sdduvall 8021369Sdduvall /* 8031369Sdduvall * Blink all three LINK LEDs on simultaneously, then all off, 8041369Sdduvall * then restore to automatic hardware control. This is used 8051369Sdduvall * in laboratory testing to trigger a logic analyser or scope. 8061369Sdduvall */ 8071369Sdduvall bge_reg_set32(bgep, ETHERNET_MAC_LED_CONTROL_REG, led_ctrl); 8081369Sdduvall led_ctrl ^= LED_CONTROL_OVERRIDE_LINK; 8091369Sdduvall bge_reg_clr32(bgep, ETHERNET_MAC_LED_CONTROL_REG, led_ctrl); 8101369Sdduvall led_ctrl = LED_CONTROL_OVERRIDE_LINK; 8111369Sdduvall bge_reg_clr32(bgep, ETHERNET_MAC_LED_CONTROL_REG, led_ctrl); 8121369Sdduvall } 8131369Sdduvall 8141369Sdduvall #endif /* BGE_DEBUGGING */ 8151369Sdduvall 8161369Sdduvall /* 8171369Sdduvall * NIC on-chip memory access routines 8181369Sdduvall * 8191369Sdduvall * Only 32K of NIC memory is visible at a time, controlled by the 8201369Sdduvall * Memory Window Base Address Register (in PCI config space). Once 8211369Sdduvall * this is set, the 32K region of NIC-local memory that it refers 8221369Sdduvall * to can be directly addressed in the upper 32K of the 64K of PCI 8231369Sdduvall * memory space used for the device. 8241369Sdduvall */ 8251369Sdduvall 8261369Sdduvall static void bge_nic_setwin(bge_t *bgep, bge_regno_t base); 8271369Sdduvall #pragma inline(bge_nic_setwin) 8281369Sdduvall 8291369Sdduvall static void 8301369Sdduvall bge_nic_setwin(bge_t *bgep, bge_regno_t base) 8311369Sdduvall { 8322073Svivek chip_id_t *cidp; 8332073Svivek 8341369Sdduvall BGE_TRACE(("bge_nic_setwin($%p, 0x%lx)", 8351369Sdduvall (void *)bgep, base)); 8361369Sdduvall 8371369Sdduvall ASSERT((base & MWBAR_GRANULE_MASK) == 0); 8382073Svivek 8392073Svivek /* 8402073Svivek * Don't do repeated zero data writes, 8412073Svivek * if the device is BCM5714C/15C. 8422073Svivek */ 8432073Svivek cidp = &bgep->chipid; 8442073Svivek if ((cidp->device == DEVICE_ID_5714C) || 8452073Svivek (cidp->device == DEVICE_ID_5715C)) { 8462073Svivek if (bgep->lastWriteZeroData && (base == (bge_regno_t)0)) 8472073Svivek return; 8482073Svivek /* Adjust lastWriteZeroData */ 8492073Svivek bgep->lastWriteZeroData = ((base == (bge_regno_t)0) ? 8502073Svivek B_TRUE : B_FALSE); 8512073Svivek } 8521369Sdduvall pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_MWBAR, base); 8531369Sdduvall } 8541369Sdduvall 8551369Sdduvall 8561369Sdduvall static uint32_t bge_nic_get32(bge_t *bgep, bge_regno_t addr); 8571369Sdduvall #pragma inline(bge_nic_get32) 8581369Sdduvall 8591369Sdduvall static uint32_t 8601369Sdduvall bge_nic_get32(bge_t *bgep, bge_regno_t addr) 8611369Sdduvall { 8621369Sdduvall uint32_t data; 8631369Sdduvall 8641408Srandyf #ifdef BGE_IPMI_ASF 8651408Srandyf if (bgep->asf_enabled && !bgep->asf_wordswapped) { 8661408Srandyf /* workaround for word swap error */ 8671408Srandyf if (addr & 4) 8681408Srandyf addr = addr - 4; 8691408Srandyf else 8701408Srandyf addr = addr + 4; 8711408Srandyf } 8721408Srandyf #endif 8731408Srandyf 8741369Sdduvall bge_nic_setwin(bgep, addr & ~MWBAR_GRANULE_MASK); 8751369Sdduvall addr &= MWBAR_GRANULE_MASK; 8761369Sdduvall addr += NIC_MEM_WINDOW_OFFSET; 8771369Sdduvall 8781369Sdduvall data = ddi_get32(bgep->io_handle, PIO_ADDR(bgep, addr)); 8791369Sdduvall 8801369Sdduvall BGE_TRACE(("bge_nic_get32($%p, 0x%lx) = 0x%08x", 8811369Sdduvall (void *)bgep, addr, data)); 8821369Sdduvall 8831369Sdduvall return (data); 8841369Sdduvall } 8851369Sdduvall 8861408Srandyf void bge_nic_put32(bge_t *bgep, bge_regno_t addr, uint32_t data); 8871408Srandyf #pragma inline(bge_nic_put32) 8881408Srandyf 8891408Srandyf void 8901369Sdduvall bge_nic_put32(bge_t *bgep, bge_regno_t addr, uint32_t data) 8911369Sdduvall { 8921369Sdduvall BGE_TRACE(("bge_nic_put32($%p, 0x%lx, 0x%08x)", 8931369Sdduvall (void *)bgep, addr, data)); 8941369Sdduvall 8951408Srandyf #ifdef BGE_IPMI_ASF 8961408Srandyf if (bgep->asf_enabled && !bgep->asf_wordswapped) { 8971408Srandyf /* workaround for word swap error */ 8981408Srandyf if (addr & 4) 8991408Srandyf addr = addr - 4; 9001408Srandyf else 9011408Srandyf addr = addr + 4; 9021408Srandyf } 9031408Srandyf #endif 9041408Srandyf 9051369Sdduvall bge_nic_setwin(bgep, addr & ~MWBAR_GRANULE_MASK); 9061369Sdduvall addr &= MWBAR_GRANULE_MASK; 9071369Sdduvall addr += NIC_MEM_WINDOW_OFFSET; 9081369Sdduvall ddi_put32(bgep->io_handle, PIO_ADDR(bgep, addr), data); 9091369Sdduvall BGE_PCICHK(bgep); 9101369Sdduvall } 9111369Sdduvall 9121369Sdduvall 9131369Sdduvall static uint64_t bge_nic_get64(bge_t *bgep, bge_regno_t addr); 9141369Sdduvall #pragma inline(bge_nic_get64) 9151369Sdduvall 9161369Sdduvall static uint64_t 9171369Sdduvall bge_nic_get64(bge_t *bgep, bge_regno_t addr) 9181369Sdduvall { 9191369Sdduvall uint64_t data; 9201369Sdduvall 9211369Sdduvall bge_nic_setwin(bgep, addr & ~MWBAR_GRANULE_MASK); 9221369Sdduvall addr &= MWBAR_GRANULE_MASK; 9231369Sdduvall addr += NIC_MEM_WINDOW_OFFSET; 9241369Sdduvall 9251369Sdduvall #ifdef __amd64 9261369Sdduvall if (bge_get_em64t_type()) { 9271369Sdduvall data = ddi_get32(bgep->io_handle, PIO_ADDR(bgep, addr)); 9281369Sdduvall data <<= 32; 9291369Sdduvall data |= ddi_get32(bgep->io_handle, 9301369Sdduvall PIO_ADDR(bgep, addr + 4)); 9311369Sdduvall } else { 9321369Sdduvall data = ddi_get64(bgep->io_handle, PIO_ADDR(bgep, addr)); 9331369Sdduvall } 9341369Sdduvall #else 9351369Sdduvall data = ddi_get64(bgep->io_handle, PIO_ADDR(bgep, addr)); 9361369Sdduvall #endif 9371369Sdduvall 9381369Sdduvall BGE_TRACE(("bge_nic_get64($%p, 0x%lx) = 0x%016llx", 9391369Sdduvall (void *)bgep, addr, data)); 9401369Sdduvall 9411369Sdduvall return (data); 9421369Sdduvall } 9431369Sdduvall 9441369Sdduvall static void bge_nic_put64(bge_t *bgep, bge_regno_t addr, uint64_t data); 9451369Sdduvall #pragma inline(bge_nic_put64) 9461369Sdduvall 9471369Sdduvall static void 9481369Sdduvall bge_nic_put64(bge_t *bgep, bge_regno_t addr, uint64_t data) 9491369Sdduvall { 9501369Sdduvall BGE_TRACE(("bge_nic_put64($%p, 0x%lx, 0x%016llx)", 9511369Sdduvall (void *)bgep, addr, data)); 9521369Sdduvall 9531369Sdduvall bge_nic_setwin(bgep, addr & ~MWBAR_GRANULE_MASK); 9541369Sdduvall addr &= MWBAR_GRANULE_MASK; 9551369Sdduvall addr += NIC_MEM_WINDOW_OFFSET; 9561369Sdduvall 9571369Sdduvall #ifdef __amd64 9581369Sdduvall if (bge_get_em64t_type()) { 9591369Sdduvall ddi_put32(bgep->io_handle, 9601369Sdduvall PIO_ADDR(bgep, addr), (uint32_t)data); 9611369Sdduvall BGE_PCICHK(bgep); 9621369Sdduvall ddi_put32(bgep->io_handle, 9631369Sdduvall PIO_ADDR(bgep, addr + 4), (uint32_t)(data >> 32)); 9641369Sdduvall } else { 9651369Sdduvall ddi_put64(bgep->io_handle, PIO_ADDR(bgep, addr), data); 9661369Sdduvall } 9671369Sdduvall #else 9681369Sdduvall ddi_put64(bgep->io_handle, PIO_ADDR(bgep, addr), data); 9691369Sdduvall #endif 9701369Sdduvall 9711369Sdduvall BGE_PCICHK(bgep); 9721369Sdduvall } 9731369Sdduvall 9741369Sdduvall /* 9751369Sdduvall * The DDI doesn't provide get/put functions for 128 bit data 9761369Sdduvall * so we put RCBs out as two 64-bit chunks instead. 9771369Sdduvall */ 9781369Sdduvall static void bge_nic_putrcb(bge_t *bgep, bge_regno_t addr, bge_rcb_t *rcbp); 9791369Sdduvall #pragma inline(bge_nic_putrcb) 9801369Sdduvall 9811369Sdduvall static void 9821369Sdduvall bge_nic_putrcb(bge_t *bgep, bge_regno_t addr, bge_rcb_t *rcbp) 9831369Sdduvall { 9841369Sdduvall uint64_t *p; 9851369Sdduvall 9861369Sdduvall BGE_TRACE(("bge_nic_putrcb($%p, 0x%lx, 0x%016llx:%04x:%04x:%08x)", 9871369Sdduvall (void *)bgep, addr, rcbp->host_ring_addr, 9881369Sdduvall rcbp->max_len, rcbp->flags, rcbp->nic_ring_addr)); 9891369Sdduvall 9901369Sdduvall ASSERT((addr % sizeof (*rcbp)) == 0); 9911369Sdduvall 9921369Sdduvall bge_nic_setwin(bgep, addr & ~MWBAR_GRANULE_MASK); 9931369Sdduvall addr &= MWBAR_GRANULE_MASK; 9941369Sdduvall addr += NIC_MEM_WINDOW_OFFSET; 9951369Sdduvall 9961369Sdduvall p = (void *)rcbp; 9971369Sdduvall #ifdef __amd64 9981369Sdduvall if (bge_get_em64t_type()) { 9991369Sdduvall ddi_put32(bgep->io_handle, PIO_ADDR(bgep, addr), 10001369Sdduvall (uint32_t)(*p)); 10011369Sdduvall ddi_put32(bgep->io_handle, PIO_ADDR(bgep, addr + 4), 10021369Sdduvall (uint32_t)(*p >> 32)); 10031369Sdduvall ddi_put32(bgep->io_handle, PIO_ADDR(bgep, addr + 8), 10041369Sdduvall (uint32_t)(*(p + 1))); 10051369Sdduvall ddi_put32(bgep->io_handle, PIO_ADDR(bgep, addr + 12), 10061369Sdduvall (uint32_t)(*p >> 32)); 10071369Sdduvall 10081369Sdduvall } else { 10091369Sdduvall ddi_put64(bgep->io_handle, PIO_ADDR(bgep, addr), *p++); 10101369Sdduvall ddi_put64(bgep->io_handle, PIO_ADDR(bgep, addr+8), *p); 10111369Sdduvall } 10121369Sdduvall #else 10131369Sdduvall ddi_put64(bgep->io_handle, PIO_ADDR(bgep, addr), *p++); 10141369Sdduvall ddi_put64(bgep->io_handle, PIO_ADDR(bgep, addr + 8), *p); 10151369Sdduvall #endif 10161369Sdduvall 10171369Sdduvall BGE_PCICHK(bgep); 10181369Sdduvall } 10191369Sdduvall 10201369Sdduvall static void bge_nic_zero(bge_t *bgep, bge_regno_t addr, uint32_t nbytes); 10211369Sdduvall #pragma inline(bge_nic_zero) 10221369Sdduvall 10231369Sdduvall static void 10241369Sdduvall bge_nic_zero(bge_t *bgep, bge_regno_t addr, uint32_t nbytes) 10251369Sdduvall { 10261369Sdduvall BGE_TRACE(("bge_nic_zero($%p, 0x%lx, 0x%x)", 10271369Sdduvall (void *)bgep, addr, nbytes)); 10281369Sdduvall 10291369Sdduvall ASSERT((addr & ~MWBAR_GRANULE_MASK) == 10301369Sdduvall ((addr+nbytes) & ~MWBAR_GRANULE_MASK)); 10311369Sdduvall 10321369Sdduvall bge_nic_setwin(bgep, addr & ~MWBAR_GRANULE_MASK); 10331369Sdduvall addr &= MWBAR_GRANULE_MASK; 10341369Sdduvall addr += NIC_MEM_WINDOW_OFFSET; 10351369Sdduvall 10361369Sdduvall (void) ddi_device_zero(bgep->io_handle, PIO_ADDR(bgep, addr), 10371369Sdduvall nbytes, 1, DDI_DATA_SZ08_ACC); 10381369Sdduvall BGE_PCICHK(bgep); 10391369Sdduvall } 10401369Sdduvall 10411369Sdduvall /* 10421369Sdduvall * MII (PHY) register get/set access routines 10431369Sdduvall * 10441369Sdduvall * These use the chip's MII auto-access method, controlled by the 10451369Sdduvall * MII Communication register at 0x044c, so the CPU doesn't have 10461369Sdduvall * to fiddle with the individual bits. 10471369Sdduvall */ 10481369Sdduvall 10491369Sdduvall #undef BGE_DBG 10501369Sdduvall #define BGE_DBG BGE_DBG_MII /* debug flag for this code */ 10511369Sdduvall 10521369Sdduvall static uint16_t bge_mii_access(bge_t *bgep, bge_regno_t regno, 10531369Sdduvall uint16_t data, uint32_t cmd); 10541369Sdduvall #pragma no_inline(bge_mii_access) 10551369Sdduvall 10561369Sdduvall static uint16_t 10571369Sdduvall bge_mii_access(bge_t *bgep, bge_regno_t regno, uint16_t data, uint32_t cmd) 10581369Sdduvall { 10591369Sdduvall uint32_t timeout; 10601369Sdduvall uint32_t regval1; 10611369Sdduvall uint32_t regval2; 10621369Sdduvall 10631369Sdduvall BGE_TRACE(("bge_mii_access($%p, 0x%lx, 0x%x, 0x%x)", 10641369Sdduvall (void *)bgep, regno, data, cmd)); 10651369Sdduvall 10661369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 10671369Sdduvall 10681369Sdduvall /* 10691369Sdduvall * Assemble the command ... 10701369Sdduvall */ 10711369Sdduvall cmd |= data << MI_COMMS_DATA_SHIFT; 10721369Sdduvall cmd |= regno << MI_COMMS_REGISTER_SHIFT; 10731369Sdduvall cmd |= bgep->phy_mii_addr << MI_COMMS_ADDRESS_SHIFT; 10741369Sdduvall cmd |= MI_COMMS_START; 10751369Sdduvall 10761369Sdduvall /* 10771369Sdduvall * Wait for any command already in progress ... 10781369Sdduvall * 10791369Sdduvall * Note: this *shouldn't* ever find that there is a command 10801369Sdduvall * in progress, because we already hold the <genlock> mutex. 10811369Sdduvall * Nonetheless, we have sometimes seen the MI_COMMS_START 10821369Sdduvall * bit set here -- it seems that the chip can initiate MII 10831369Sdduvall * accesses internally, even with polling OFF. 10841369Sdduvall */ 10851369Sdduvall regval1 = regval2 = bge_reg_get32(bgep, MI_COMMS_REG); 10861865Sdilpreet for (timeout = 100; ; ) { 10871369Sdduvall if ((regval2 & MI_COMMS_START) == 0) { 10881369Sdduvall bge_reg_put32(bgep, MI_COMMS_REG, cmd); 10891369Sdduvall break; 10901369Sdduvall } 10911369Sdduvall if (--timeout == 0) 10921369Sdduvall break; 10931369Sdduvall drv_usecwait(10); 10941369Sdduvall regval2 = bge_reg_get32(bgep, MI_COMMS_REG); 10951369Sdduvall } 10961369Sdduvall 10971865Sdilpreet if (timeout == 0) 10981865Sdilpreet return ((uint16_t)~0u); 10991865Sdilpreet 11001865Sdilpreet if (timeout != 100) 11011369Sdduvall BGE_REPORT((bgep, "bge_mii_access: cmd 0x%x -- " 11021369Sdduvall "MI_COMMS_START set for %d us; 0x%x->0x%x", 11031865Sdilpreet cmd, 10*(100-timeout), regval1, regval2)); 11041369Sdduvall 11051369Sdduvall regval1 = bge_reg_get32(bgep, MI_COMMS_REG); 11061369Sdduvall for (timeout = 1000; ; ) { 11071369Sdduvall if ((regval1 & MI_COMMS_START) == 0) 11081369Sdduvall break; 11091369Sdduvall if (--timeout == 0) 11101369Sdduvall break; 11111369Sdduvall drv_usecwait(10); 11121369Sdduvall regval1 = bge_reg_get32(bgep, MI_COMMS_REG); 11131369Sdduvall } 11141369Sdduvall 11151369Sdduvall /* 11161369Sdduvall * Drop out early if the READ FAILED bit is set -- this chip 11171369Sdduvall * could be a 5703/4S, with a SerDes instead of a PHY! 11181369Sdduvall */ 11191369Sdduvall if (regval2 & MI_COMMS_READ_FAILED) 11201369Sdduvall return ((uint16_t)~0u); 11211369Sdduvall 11221369Sdduvall if (timeout == 0) 11231369Sdduvall return ((uint16_t)~0u); 11241369Sdduvall 11251369Sdduvall /* 11261369Sdduvall * The PRM says to wait 5us after seeing the START bit clear 11271369Sdduvall * and then re-read the register to get the final value of the 11281369Sdduvall * data field, in order to avoid a race condition where the 11291369Sdduvall * START bit is clear but the data field isn't yet valid. 11301369Sdduvall * 11311369Sdduvall * Note: we don't actually seem to be encounter this race; 11321369Sdduvall * except when the START bit is seen set again (see below), 11331369Sdduvall * the data field doesn't change during this 5us interval. 11341369Sdduvall */ 11351369Sdduvall drv_usecwait(5); 11361369Sdduvall regval2 = bge_reg_get32(bgep, MI_COMMS_REG); 11371369Sdduvall 11381369Sdduvall /* 11391369Sdduvall * Unfortunately, when following the PRMs instructions above, 11401369Sdduvall * we have occasionally seen the START bit set again(!) in the 11411369Sdduvall * value read after the 5us delay. This seems to be due to the 11421369Sdduvall * chip autonomously starting another MII access internally. 11431369Sdduvall * In such cases, the command/data/etc fields relate to the 11441369Sdduvall * internal command, rather than the one that we thought had 11451369Sdduvall * just finished. So in this case, we fall back to returning 11461369Sdduvall * the data from the original read that showed START clear. 11471369Sdduvall */ 11481369Sdduvall if (regval2 & MI_COMMS_START) { 11491369Sdduvall BGE_REPORT((bgep, "bge_mii_access: cmd 0x%x -- " 11501369Sdduvall "MI_COMMS_START set after transaction; 0x%x->0x%x", 11511369Sdduvall cmd, regval1, regval2)); 11521369Sdduvall regval2 = regval1; 11531369Sdduvall } 11541369Sdduvall 11551369Sdduvall if (regval2 & MI_COMMS_START) 11561369Sdduvall return ((uint16_t)~0u); 11571369Sdduvall 11581369Sdduvall if (regval2 & MI_COMMS_READ_FAILED) 11591369Sdduvall return ((uint16_t)~0u); 11601369Sdduvall 11611369Sdduvall return ((regval2 & MI_COMMS_DATA_MASK) >> MI_COMMS_DATA_SHIFT); 11621369Sdduvall } 11631369Sdduvall 11641369Sdduvall uint16_t bge_mii_get16(bge_t *bgep, bge_regno_t regno); 11651369Sdduvall #pragma no_inline(bge_mii_get16) 11661369Sdduvall 11671369Sdduvall uint16_t 11681369Sdduvall bge_mii_get16(bge_t *bgep, bge_regno_t regno) 11691369Sdduvall { 11701369Sdduvall BGE_TRACE(("bge_mii_get16($%p, 0x%lx)", 11711369Sdduvall (void *)bgep, regno)); 11721369Sdduvall 11731369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 11741369Sdduvall 11751369Sdduvall return (bge_mii_access(bgep, regno, 0, MI_COMMS_COMMAND_READ)); 11761369Sdduvall } 11771369Sdduvall 11781369Sdduvall void bge_mii_put16(bge_t *bgep, bge_regno_t regno, uint16_t data); 11791369Sdduvall #pragma no_inline(bge_mii_put16) 11801369Sdduvall 11811369Sdduvall void 11821369Sdduvall bge_mii_put16(bge_t *bgep, bge_regno_t regno, uint16_t data) 11831369Sdduvall { 11841369Sdduvall BGE_TRACE(("bge_mii_put16($%p, 0x%lx, 0x%x)", 11851369Sdduvall (void *)bgep, regno, data)); 11861369Sdduvall 11871369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 11881369Sdduvall 11891369Sdduvall (void) bge_mii_access(bgep, regno, data, MI_COMMS_COMMAND_WRITE); 11901369Sdduvall } 11911369Sdduvall 11921369Sdduvall #undef BGE_DBG 11931369Sdduvall #define BGE_DBG BGE_DBG_SEEPROM /* debug flag for this code */ 11941369Sdduvall 11951369Sdduvall #if BGE_SEE_IO32 || BGE_FLASH_IO32 11961369Sdduvall 11971369Sdduvall /* 11981369Sdduvall * Basic SEEPROM get/set access routine 11991369Sdduvall * 12001369Sdduvall * This uses the chip's SEEPROM auto-access method, controlled by the 12011369Sdduvall * Serial EEPROM Address/Data Registers at 0x6838/683c, so the CPU 12021369Sdduvall * doesn't have to fiddle with the individual bits. 12031369Sdduvall * 12041369Sdduvall * The caller should hold <genlock> and *also* have already acquired 12051369Sdduvall * the right to access the SEEPROM, via bge_nvmem_acquire() above. 12061369Sdduvall * 12071369Sdduvall * Return value: 12081369Sdduvall * 0 on success, 12091369Sdduvall * ENODATA on access timeout (maybe retryable: device may just be busy) 12101369Sdduvall * EPROTO on other h/w or s/w errors. 12111369Sdduvall * 12121369Sdduvall * <*dp> is an input to a SEEPROM_ACCESS_WRITE operation, or an output 12131369Sdduvall * from a (successful) SEEPROM_ACCESS_READ. 12141369Sdduvall */ 12151369Sdduvall static int bge_seeprom_access(bge_t *bgep, uint32_t cmd, bge_regno_t addr, 12161369Sdduvall uint32_t *dp); 12171369Sdduvall #pragma no_inline(bge_seeprom_access) 12181369Sdduvall 12191369Sdduvall static int 12201369Sdduvall bge_seeprom_access(bge_t *bgep, uint32_t cmd, bge_regno_t addr, uint32_t *dp) 12211369Sdduvall { 12221369Sdduvall uint32_t tries; 12231369Sdduvall uint32_t regval; 12241369Sdduvall 12251369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 12261369Sdduvall 12271369Sdduvall /* 12281369Sdduvall * On the newer chips that support both SEEPROM & Flash, we need 12291369Sdduvall * to specifically enable SEEPROM access (Flash is the default). 12301369Sdduvall * On older chips, we don't; SEEPROM is the only NVtype supported, 12311369Sdduvall * and the NVM control registers don't exist ... 12321369Sdduvall */ 12331369Sdduvall switch (bgep->chipid.nvtype) { 12341369Sdduvall case BGE_NVTYPE_NONE: 12351369Sdduvall case BGE_NVTYPE_UNKNOWN: 12361369Sdduvall _NOTE(NOTREACHED) 12371369Sdduvall case BGE_NVTYPE_SEEPROM: 12381369Sdduvall break; 12391369Sdduvall 12401369Sdduvall case BGE_NVTYPE_LEGACY_SEEPROM: 12411369Sdduvall case BGE_NVTYPE_UNBUFFERED_FLASH: 12421369Sdduvall case BGE_NVTYPE_BUFFERED_FLASH: 12431369Sdduvall default: 12441369Sdduvall bge_reg_set32(bgep, NVM_CONFIG1_REG, 12451369Sdduvall NVM_CFG1_LEGACY_SEEPROM_MODE); 12461369Sdduvall break; 12471369Sdduvall } 12481369Sdduvall 12491369Sdduvall /* 12501369Sdduvall * Check there's no command in progress. 12511369Sdduvall * 12521369Sdduvall * Note: this *shouldn't* ever find that there is a command 12531369Sdduvall * in progress, because we already hold the <genlock> mutex. 12541369Sdduvall * Also, to ensure we don't have a conflict with the chip's 12551369Sdduvall * internal firmware or a process accessing the same (shared) 12561369Sdduvall * SEEPROM through the other port of a 5704, we've already 12571369Sdduvall * been through the "software arbitration" protocol. 12581369Sdduvall * So this is just a final consistency check: we shouldn't 12591369Sdduvall * see EITHER the START bit (command started but not complete) 12601369Sdduvall * OR the COMPLETE bit (command completed but not cleared). 12611369Sdduvall */ 12621369Sdduvall regval = bge_reg_get32(bgep, SERIAL_EEPROM_ADDRESS_REG); 12631369Sdduvall if (regval & SEEPROM_ACCESS_START) 12641369Sdduvall return (EPROTO); 12651369Sdduvall if (regval & SEEPROM_ACCESS_COMPLETE) 12661369Sdduvall return (EPROTO); 12671369Sdduvall 12681369Sdduvall /* 12691369Sdduvall * Assemble the command ... 12701369Sdduvall */ 12711369Sdduvall cmd |= addr & SEEPROM_ACCESS_ADDRESS_MASK; 12721369Sdduvall addr >>= SEEPROM_ACCESS_ADDRESS_SIZE; 12731369Sdduvall addr <<= SEEPROM_ACCESS_DEVID_SHIFT; 12741369Sdduvall cmd |= addr & SEEPROM_ACCESS_DEVID_MASK; 12751369Sdduvall cmd |= SEEPROM_ACCESS_START; 12761369Sdduvall cmd |= SEEPROM_ACCESS_COMPLETE; 12771369Sdduvall cmd |= regval & SEEPROM_ACCESS_HALFCLOCK_MASK; 12781369Sdduvall 12791369Sdduvall bge_reg_put32(bgep, SERIAL_EEPROM_DATA_REG, *dp); 12801369Sdduvall bge_reg_put32(bgep, SERIAL_EEPROM_ADDRESS_REG, cmd); 12811369Sdduvall 12821369Sdduvall /* 12831369Sdduvall * By observation, a successful access takes ~20us on a 5703/4, 12841369Sdduvall * but apparently much longer (up to 1000us) on the obsolescent 12851369Sdduvall * BCM5700/BCM5701. We want to be sure we don't get any false 12861369Sdduvall * timeouts here; but OTOH, we don't want a bogus access to lock 12871369Sdduvall * out interrupts for longer than necessary. So we'll allow up 12881369Sdduvall * to 1000us ... 12891369Sdduvall */ 12901369Sdduvall for (tries = 0; tries < 1000; ++tries) { 12911369Sdduvall regval = bge_reg_get32(bgep, SERIAL_EEPROM_ADDRESS_REG); 12921369Sdduvall if (regval & SEEPROM_ACCESS_COMPLETE) 12931369Sdduvall break; 12941369Sdduvall drv_usecwait(1); 12951369Sdduvall } 12961369Sdduvall 12971369Sdduvall if (regval & SEEPROM_ACCESS_COMPLETE) { 12981369Sdduvall /* 12991369Sdduvall * All OK; read the SEEPROM data register, then write back 13001369Sdduvall * the value read from the address register in order to 13011369Sdduvall * clear the <complete> bit and leave the SEEPROM access 13021369Sdduvall * state machine idle, ready for the next access ... 13031369Sdduvall */ 13041369Sdduvall BGE_DEBUG(("bge_seeprom_access: complete after %d us", tries)); 13051369Sdduvall *dp = bge_reg_get32(bgep, SERIAL_EEPROM_DATA_REG); 13061369Sdduvall bge_reg_put32(bgep, SERIAL_EEPROM_ADDRESS_REG, regval); 13071369Sdduvall return (0); 13081369Sdduvall } 13091369Sdduvall 13101369Sdduvall /* 13111369Sdduvall * Hmm ... what happened here? 13121369Sdduvall * 1313*2135Szh199473 * Most likely, the user addressed a non-existent SEEPROM. Or 13141369Sdduvall * maybe the SEEPROM was busy internally (e.g. processing a write) 13151369Sdduvall * and didn't respond to being addressed. Either way, it's left 13161369Sdduvall * the SEEPROM access state machine wedged. So we'll reset it 13171369Sdduvall * before we leave, so it's ready for next time ... 13181369Sdduvall */ 13191369Sdduvall BGE_DEBUG(("bge_seeprom_access: timed out after %d us", tries)); 13201369Sdduvall bge_reg_set32(bgep, SERIAL_EEPROM_ADDRESS_REG, SEEPROM_ACCESS_INIT); 13211369Sdduvall return (ENODATA); 13221369Sdduvall } 13231369Sdduvall 13241369Sdduvall /* 13251369Sdduvall * Basic Flash get/set access routine 13261369Sdduvall * 13271369Sdduvall * These use the chip's Flash auto-access method, controlled by the 13281369Sdduvall * Flash Access Registers at 0x7000-701c, so the CPU doesn't have to 13291369Sdduvall * fiddle with the individual bits. 13301369Sdduvall * 13311369Sdduvall * The caller should hold <genlock> and *also* have already acquired 13321369Sdduvall * the right to access the Flash, via bge_nvmem_acquire() above. 13331369Sdduvall * 13341369Sdduvall * Return value: 13351369Sdduvall * 0 on success, 13361369Sdduvall * ENODATA on access timeout (maybe retryable: device may just be busy) 13371369Sdduvall * ENODEV if the NVmem device is missing or otherwise unusable 13381369Sdduvall * 13391369Sdduvall * <*dp> is an input to a NVM_FLASH_CMD_WR operation, or an output 13401369Sdduvall * from a (successful) NVM_FLASH_CMD_RD. 13411369Sdduvall */ 13421369Sdduvall static int bge_flash_access(bge_t *bgep, uint32_t cmd, bge_regno_t addr, 13431369Sdduvall uint32_t *dp); 13441369Sdduvall #pragma no_inline(bge_flash_access) 13451369Sdduvall 13461369Sdduvall static int 13471369Sdduvall bge_flash_access(bge_t *bgep, uint32_t cmd, bge_regno_t addr, uint32_t *dp) 13481369Sdduvall { 13491369Sdduvall uint32_t tries; 13501369Sdduvall uint32_t regval; 13511369Sdduvall 13521369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 13531369Sdduvall 13541369Sdduvall /* 13551369Sdduvall * On the newer chips that support both SEEPROM & Flash, we need 13561369Sdduvall * to specifically disable SEEPROM access while accessing Flash. 13571369Sdduvall * The older chips don't support Flash, and the NVM registers don't 13581369Sdduvall * exist, so we shouldn't be here at all! 13591369Sdduvall */ 13601369Sdduvall switch (bgep->chipid.nvtype) { 13611369Sdduvall case BGE_NVTYPE_NONE: 13621369Sdduvall case BGE_NVTYPE_UNKNOWN: 13631369Sdduvall _NOTE(NOTREACHED) 13641369Sdduvall case BGE_NVTYPE_SEEPROM: 13651369Sdduvall return (ENODEV); 13661369Sdduvall 13671369Sdduvall case BGE_NVTYPE_LEGACY_SEEPROM: 13681369Sdduvall case BGE_NVTYPE_UNBUFFERED_FLASH: 13691369Sdduvall case BGE_NVTYPE_BUFFERED_FLASH: 13701369Sdduvall default: 13711369Sdduvall bge_reg_clr32(bgep, NVM_CONFIG1_REG, 13721369Sdduvall NVM_CFG1_LEGACY_SEEPROM_MODE); 13731369Sdduvall break; 13741369Sdduvall } 13751369Sdduvall 13761369Sdduvall /* 13771369Sdduvall * Assemble the command ... 13781369Sdduvall */ 13791369Sdduvall addr &= NVM_FLASH_ADDR_MASK; 13801369Sdduvall cmd |= NVM_FLASH_CMD_DOIT; 13811369Sdduvall cmd |= NVM_FLASH_CMD_FIRST; 13821369Sdduvall cmd |= NVM_FLASH_CMD_LAST; 13831369Sdduvall cmd |= NVM_FLASH_CMD_DONE; 13841369Sdduvall 13851369Sdduvall bge_reg_put32(bgep, NVM_FLASH_WRITE_REG, *dp); 13861369Sdduvall bge_reg_put32(bgep, NVM_FLASH_ADDR_REG, addr); 13871369Sdduvall bge_reg_put32(bgep, NVM_FLASH_CMD_REG, cmd); 13881369Sdduvall 13891369Sdduvall /* 13901369Sdduvall * Allow up to 1000ms ... 13911369Sdduvall */ 13921369Sdduvall for (tries = 0; tries < 1000; ++tries) { 13931369Sdduvall regval = bge_reg_get32(bgep, NVM_FLASH_CMD_REG); 13941369Sdduvall if (regval & NVM_FLASH_CMD_DONE) 13951369Sdduvall break; 13961369Sdduvall drv_usecwait(1); 13971369Sdduvall } 13981369Sdduvall 13991369Sdduvall if (regval & NVM_FLASH_CMD_DONE) { 14001369Sdduvall /* 14011369Sdduvall * All OK; read the data from the Flash read register 14021369Sdduvall */ 14031369Sdduvall BGE_DEBUG(("bge_flash_access: complete after %d us", tries)); 14041369Sdduvall *dp = bge_reg_get32(bgep, NVM_FLASH_READ_REG); 14051369Sdduvall return (0); 14061369Sdduvall } 14071369Sdduvall 14081369Sdduvall /* 14091369Sdduvall * Hmm ... what happened here? 14101369Sdduvall * 1411*2135Szh199473 * Most likely, the user addressed a non-existent Flash. Or 14121369Sdduvall * maybe the Flash was busy internally (e.g. processing a write) 14131369Sdduvall * and didn't respond to being addressed. Either way, there's 14141369Sdduvall * nothing we can here ... 14151369Sdduvall */ 14161369Sdduvall BGE_DEBUG(("bge_flash_access: timed out after %d us", tries)); 14171369Sdduvall return (ENODATA); 14181369Sdduvall } 14191369Sdduvall 14201369Sdduvall /* 14211369Sdduvall * The next two functions regulate access to the NVram (if fitted). 14221369Sdduvall * 14231369Sdduvall * On a 5704 (dual core) chip, there's only one SEEPROM and one Flash 14241369Sdduvall * (SPI) interface, but they can be accessed through either port. These 14251369Sdduvall * are managed by different instance of this driver and have no software 14261369Sdduvall * state in common. 14271369Sdduvall * 14281369Sdduvall * In addition (and even on a single core chip) the chip's internal 14291369Sdduvall * firmware can access the SEEPROM/Flash, most notably after a RESET 14301369Sdduvall * when it may download code to run internally. 14311369Sdduvall * 14321369Sdduvall * So we need to arbitrate between these various software agents. For 14331369Sdduvall * this purpose, the chip provides the Software Arbitration Register, 14341369Sdduvall * which implements hardware(!) arbitration. 14351369Sdduvall * 14361369Sdduvall * This functionality didn't exist on older (5700/5701) chips, so there's 14371369Sdduvall * nothing we can do by way of arbitration on those; also, if there's no 14381369Sdduvall * SEEPROM/Flash fitted (or we couldn't determine what type), there's also 14391369Sdduvall * nothing to do. 14401369Sdduvall * 14411369Sdduvall * The internal firmware appears to use Request 0, which is the highest 14421369Sdduvall * priority. So we'd like to use Request 2, leaving one higher and one 14431369Sdduvall * lower for any future developments ... but apparently this doesn't 14441369Sdduvall * always work. So for now, the code uses Request 1 ;-( 14451369Sdduvall */ 14461369Sdduvall 14471369Sdduvall #define NVM_READ_REQ NVM_READ_REQ1 14481369Sdduvall #define NVM_RESET_REQ NVM_RESET_REQ1 14491369Sdduvall #define NVM_SET_REQ NVM_SET_REQ1 14501369Sdduvall 14511369Sdduvall static void bge_nvmem_relinquish(bge_t *bgep); 14521369Sdduvall #pragma no_inline(bge_nvmem_relinquish) 14531369Sdduvall 14541369Sdduvall static void 14551369Sdduvall bge_nvmem_relinquish(bge_t *bgep) 14561369Sdduvall { 14571369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 14581369Sdduvall 14591369Sdduvall switch (bgep->chipid.nvtype) { 14601369Sdduvall case BGE_NVTYPE_NONE: 14611369Sdduvall case BGE_NVTYPE_UNKNOWN: 14621369Sdduvall _NOTE(NOTREACHED) 14631369Sdduvall return; 14641369Sdduvall 14651369Sdduvall case BGE_NVTYPE_SEEPROM: 14661369Sdduvall /* 14671369Sdduvall * No arbitration performed, no release needed 14681369Sdduvall */ 14691369Sdduvall return; 14701369Sdduvall 14711369Sdduvall case BGE_NVTYPE_LEGACY_SEEPROM: 14721369Sdduvall case BGE_NVTYPE_UNBUFFERED_FLASH: 14731369Sdduvall case BGE_NVTYPE_BUFFERED_FLASH: 14741369Sdduvall default: 14751369Sdduvall break; 14761369Sdduvall } 14771369Sdduvall 14781369Sdduvall /* 14791369Sdduvall * Our own request should be present (whether or not granted) ... 14801369Sdduvall */ 14811865Sdilpreet (void) bge_reg_get32(bgep, NVM_SW_ARBITRATION_REG); 14821369Sdduvall 14831369Sdduvall /* 14841369Sdduvall * ... this will make it go away. 14851369Sdduvall */ 14861369Sdduvall bge_reg_put32(bgep, NVM_SW_ARBITRATION_REG, NVM_RESET_REQ); 14871865Sdilpreet (void) bge_reg_get32(bgep, NVM_SW_ARBITRATION_REG); 14881369Sdduvall } 14891369Sdduvall 14901369Sdduvall /* 14911369Sdduvall * Arbitrate for access to the NVmem, if necessary 14921369Sdduvall * 14931369Sdduvall * Return value: 14941369Sdduvall * 0 on success 14951369Sdduvall * EAGAIN if the device is in use (retryable) 14961369Sdduvall * ENODEV if the NVmem device is missing or otherwise unusable 14971369Sdduvall */ 14981369Sdduvall static int bge_nvmem_acquire(bge_t *bgep); 14991369Sdduvall #pragma no_inline(bge_nvmem_acquire) 15001369Sdduvall 15011369Sdduvall static int 15021369Sdduvall bge_nvmem_acquire(bge_t *bgep) 15031369Sdduvall { 15041369Sdduvall uint32_t regval; 15051369Sdduvall uint32_t tries; 15061369Sdduvall 15071369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 15081369Sdduvall 15091369Sdduvall switch (bgep->chipid.nvtype) { 15101369Sdduvall case BGE_NVTYPE_NONE: 15111369Sdduvall case BGE_NVTYPE_UNKNOWN: 15121369Sdduvall /* 15131369Sdduvall * Access denied: no (recognisable) device fitted 15141369Sdduvall */ 15151369Sdduvall return (ENODEV); 15161369Sdduvall 15171369Sdduvall case BGE_NVTYPE_SEEPROM: 15181369Sdduvall /* 15191369Sdduvall * Access granted: no arbitration needed (or possible) 15201369Sdduvall */ 15211369Sdduvall return (0); 15221369Sdduvall 15231369Sdduvall case BGE_NVTYPE_LEGACY_SEEPROM: 15241369Sdduvall case BGE_NVTYPE_UNBUFFERED_FLASH: 15251369Sdduvall case BGE_NVTYPE_BUFFERED_FLASH: 15261369Sdduvall default: 15271369Sdduvall /* 15281369Sdduvall * Access conditional: conduct arbitration protocol 15291369Sdduvall */ 15301369Sdduvall break; 15311369Sdduvall } 15321369Sdduvall 15331369Sdduvall /* 15341369Sdduvall * We're holding the per-port mutex <genlock>, so no-one other 1535*2135Szh199473 * thread can be attempting to access the NVmem through *this* 15361369Sdduvall * port. But it could be in use by the *other* port (of a 5704), 15371369Sdduvall * or by the chip's internal firmware, so we have to go through 15381369Sdduvall * the full (hardware) arbitration protocol ... 15391369Sdduvall * 15401369Sdduvall * Note that *because* we're holding <genlock>, the interrupt handler 15411369Sdduvall * won't be able to progress. So we're only willing to spin for a 15421369Sdduvall * fairly short time. Specifically: 15431369Sdduvall * 15441369Sdduvall * We *must* wait long enough for the hardware to resolve all 15451369Sdduvall * requests and determine the winner. Fortunately, this is 15461369Sdduvall * "almost instantaneous", even as observed by GHz CPUs. 15471369Sdduvall * 15481369Sdduvall * A successful access by another Solaris thread (via either 15491369Sdduvall * port) typically takes ~20us. So waiting a bit longer than 15501369Sdduvall * that will give a good chance of success, if the other user 15511369Sdduvall * *is* another thread on the other port. 15521369Sdduvall * 15531369Sdduvall * However, the internal firmware can hold on to the NVmem 15541369Sdduvall * for *much* longer: at least 10 milliseconds just after a 15551369Sdduvall * RESET, and maybe even longer if the NVmem actually contains 15561369Sdduvall * code to download and run on the internal CPUs. 15571369Sdduvall * 15581369Sdduvall * So, we'll allow 50us; if that's not enough then it's up to the 15591369Sdduvall * caller to retry later (hence the choice of return code EAGAIN). 15601369Sdduvall */ 15611369Sdduvall regval = bge_reg_get32(bgep, NVM_SW_ARBITRATION_REG); 15621369Sdduvall bge_reg_put32(bgep, NVM_SW_ARBITRATION_REG, NVM_SET_REQ); 15631369Sdduvall 15641369Sdduvall for (tries = 0; tries < 50; ++tries) { 15651369Sdduvall regval = bge_reg_get32(bgep, NVM_SW_ARBITRATION_REG); 15661369Sdduvall if (regval & NVM_WON_REQ1) 15671369Sdduvall break; 15681369Sdduvall drv_usecwait(1); 15691369Sdduvall } 15701369Sdduvall 15711369Sdduvall if (regval & NVM_WON_REQ1) { 15721369Sdduvall BGE_DEBUG(("bge_nvmem_acquire: won after %d us", tries)); 15731369Sdduvall return (0); 15741369Sdduvall } 15751369Sdduvall 15761369Sdduvall /* 15771369Sdduvall * Somebody else must be accessing the NVmem, so abandon our 15781369Sdduvall * attempt take control of it. The caller can try again later ... 15791369Sdduvall */ 15801369Sdduvall BGE_DEBUG(("bge_nvmem_acquire: lost after %d us", tries)); 15811369Sdduvall bge_nvmem_relinquish(bgep); 15821369Sdduvall return (EAGAIN); 15831369Sdduvall } 15841369Sdduvall 15851369Sdduvall /* 15861369Sdduvall * This code assumes that the GPIO1 bit has been wired up to the NVmem 15871369Sdduvall * write protect line in such a way that the NVmem is protected when 15881369Sdduvall * GPIO1 is an input, or is an output but driven high. Thus, to make the 15891369Sdduvall * NVmem writable we have to change GPIO1 to an output AND drive it low. 15901369Sdduvall * 15911369Sdduvall * Note: there's only one set of GPIO pins on a 5704, even though they 15921369Sdduvall * can be accessed through either port. So the chip has to resolve what 15931369Sdduvall * happens if the two ports program a single pin differently ... the rule 15941369Sdduvall * it uses is that if the ports disagree about the *direction* of a pin, 15951369Sdduvall * "output" wins over "input", but if they disagree about its *value* as 15961369Sdduvall * an output, then the pin is TRISTATED instead! In such a case, no-one 15971369Sdduvall * wins, and the external signal does whatever the external circuitry 15981369Sdduvall * defines as the default -- which we've assumed is the PROTECTED state. 15991369Sdduvall * So, we always change GPIO1 back to being an *input* whenever we're not 16001369Sdduvall * specifically using it to unprotect the NVmem. This allows either port 1601*2135Szh199473 * to update the NVmem, although obviously only one at a time! 16021369Sdduvall * 16031369Sdduvall * The caller should hold <genlock> and *also* have already acquired the 16041369Sdduvall * right to access the NVmem, via bge_nvmem_acquire() above. 16051369Sdduvall */ 16061369Sdduvall static void bge_nvmem_protect(bge_t *bgep, boolean_t protect); 16071369Sdduvall #pragma inline(bge_nvmem_protect) 16081369Sdduvall 16091369Sdduvall static void 16101369Sdduvall bge_nvmem_protect(bge_t *bgep, boolean_t protect) 16111369Sdduvall { 16121369Sdduvall uint32_t regval; 16131369Sdduvall 16141369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 16151369Sdduvall 16161369Sdduvall regval = bge_reg_get32(bgep, MISC_LOCAL_CONTROL_REG); 16171369Sdduvall if (protect) { 16181369Sdduvall regval |= MLCR_MISC_PINS_OUTPUT_1; 16191369Sdduvall regval &= ~MLCR_MISC_PINS_OUTPUT_ENABLE_1; 16201369Sdduvall } else { 16211369Sdduvall regval &= ~MLCR_MISC_PINS_OUTPUT_1; 16221369Sdduvall regval |= MLCR_MISC_PINS_OUTPUT_ENABLE_1; 16231369Sdduvall } 16241369Sdduvall bge_reg_put32(bgep, MISC_LOCAL_CONTROL_REG, regval); 16251369Sdduvall } 16261369Sdduvall 16271369Sdduvall /* 16281369Sdduvall * Now put it all together ... 16291369Sdduvall * 16301369Sdduvall * Try to acquire control of the NVmem; if successful, then: 16311369Sdduvall * unprotect it (if we want to write to it) 16321369Sdduvall * perform the requested access 16331369Sdduvall * reprotect it (after a write) 16341369Sdduvall * relinquish control 16351369Sdduvall * 16361369Sdduvall * Return value: 16371369Sdduvall * 0 on success, 16381369Sdduvall * EAGAIN if the device is in use (retryable) 16391369Sdduvall * ENODATA on access timeout (maybe retryable: device may just be busy) 16401369Sdduvall * ENODEV if the NVmem device is missing or otherwise unusable 16411369Sdduvall * EPROTO on other h/w or s/w errors. 16421369Sdduvall */ 16431369Sdduvall static int 16441369Sdduvall bge_nvmem_rw32(bge_t *bgep, uint32_t cmd, bge_regno_t addr, uint32_t *dp) 16451369Sdduvall { 16461369Sdduvall int err; 16471369Sdduvall 16481369Sdduvall if ((err = bge_nvmem_acquire(bgep)) == 0) { 16491369Sdduvall switch (cmd) { 16501369Sdduvall case BGE_SEE_READ: 16511369Sdduvall err = bge_seeprom_access(bgep, 16521369Sdduvall SEEPROM_ACCESS_READ, addr, dp); 16531369Sdduvall break; 16541369Sdduvall 16551369Sdduvall case BGE_SEE_WRITE: 16561369Sdduvall bge_nvmem_protect(bgep, B_FALSE); 16571369Sdduvall err = bge_seeprom_access(bgep, 16581369Sdduvall SEEPROM_ACCESS_WRITE, addr, dp); 16591369Sdduvall bge_nvmem_protect(bgep, B_TRUE); 16601369Sdduvall break; 16611369Sdduvall 16621369Sdduvall case BGE_FLASH_READ: 16631369Sdduvall if (DEVICE_5721_SERIES_CHIPSETS(bgep) || 16641369Sdduvall DEVICE_5714_SERIES_CHIPSETS(bgep)) { 16651369Sdduvall bge_reg_set32(bgep, NVM_ACCESS_REG, 16661369Sdduvall NVM_ACCESS_ENABLE); 16671369Sdduvall } 16681369Sdduvall err = bge_flash_access(bgep, 16691369Sdduvall NVM_FLASH_CMD_RD, addr, dp); 16701369Sdduvall if (DEVICE_5721_SERIES_CHIPSETS(bgep) || 16711369Sdduvall DEVICE_5714_SERIES_CHIPSETS(bgep)) { 16721369Sdduvall bge_reg_clr32(bgep, NVM_ACCESS_REG, 16731369Sdduvall NVM_ACCESS_ENABLE); 16741369Sdduvall } 16751369Sdduvall break; 16761369Sdduvall 16771369Sdduvall case BGE_FLASH_WRITE: 16781369Sdduvall if (DEVICE_5721_SERIES_CHIPSETS(bgep) || 16791369Sdduvall DEVICE_5714_SERIES_CHIPSETS(bgep)) { 16801369Sdduvall bge_reg_set32(bgep, NVM_ACCESS_REG, 16811369Sdduvall NVM_WRITE_ENABLE|NVM_ACCESS_ENABLE); 16821369Sdduvall } 16831369Sdduvall bge_nvmem_protect(bgep, B_FALSE); 16841369Sdduvall err = bge_flash_access(bgep, 16851369Sdduvall NVM_FLASH_CMD_WR, addr, dp); 16861369Sdduvall bge_nvmem_protect(bgep, B_TRUE); 16871369Sdduvall if (DEVICE_5721_SERIES_CHIPSETS(bgep) || 16881369Sdduvall DEVICE_5714_SERIES_CHIPSETS(bgep)) { 16891369Sdduvall bge_reg_clr32(bgep, NVM_ACCESS_REG, 16901369Sdduvall NVM_WRITE_ENABLE|NVM_ACCESS_ENABLE); 16911369Sdduvall } 16921369Sdduvall 16931369Sdduvall break; 16941369Sdduvall 16951369Sdduvall default: 16961369Sdduvall _NOTE(NOTREACHED) 16971369Sdduvall break; 16981369Sdduvall } 16991369Sdduvall bge_nvmem_relinquish(bgep); 17001369Sdduvall } 17011369Sdduvall 17021369Sdduvall BGE_DEBUG(("bge_nvmem_rw32: err %d", err)); 17031369Sdduvall return (err); 17041369Sdduvall } 17051369Sdduvall 17061369Sdduvall /* 17071369Sdduvall * Attempt to get a MAC address from the SEEPROM or Flash, if any 17081369Sdduvall */ 17091369Sdduvall static uint64_t bge_get_nvmac(bge_t *bgep); 17101369Sdduvall #pragma no_inline(bge_get_nvmac) 17111369Sdduvall 17121369Sdduvall static uint64_t 17131369Sdduvall bge_get_nvmac(bge_t *bgep) 17141369Sdduvall { 17151369Sdduvall uint32_t mac_high; 17161369Sdduvall uint32_t mac_low; 17171369Sdduvall uint32_t addr; 17181369Sdduvall uint32_t cmd; 17191369Sdduvall uint64_t mac; 17201369Sdduvall 17211369Sdduvall BGE_TRACE(("bge_get_nvmac($%p)", 17221369Sdduvall (void *)bgep)); 17231369Sdduvall 17241369Sdduvall switch (bgep->chipid.nvtype) { 17251369Sdduvall case BGE_NVTYPE_NONE: 17261369Sdduvall case BGE_NVTYPE_UNKNOWN: 17271369Sdduvall default: 17281369Sdduvall return (0ULL); 17291369Sdduvall 17301369Sdduvall case BGE_NVTYPE_SEEPROM: 17311369Sdduvall case BGE_NVTYPE_LEGACY_SEEPROM: 17321369Sdduvall cmd = BGE_SEE_READ; 17331369Sdduvall break; 17341369Sdduvall 17351369Sdduvall case BGE_NVTYPE_UNBUFFERED_FLASH: 17361369Sdduvall case BGE_NVTYPE_BUFFERED_FLASH: 17371369Sdduvall cmd = BGE_FLASH_READ; 17381369Sdduvall break; 17391369Sdduvall } 17401369Sdduvall 17411369Sdduvall addr = NVMEM_DATA_MAC_ADDRESS; 17421369Sdduvall if (bge_nvmem_rw32(bgep, cmd, addr, &mac_high)) 17431369Sdduvall return (0ULL); 17441369Sdduvall addr += 4; 17451369Sdduvall if (bge_nvmem_rw32(bgep, cmd, addr, &mac_low)) 17461369Sdduvall return (0ULL); 17471369Sdduvall 17481369Sdduvall /* 17491369Sdduvall * The Broadcom chip is natively BIG-endian, so that's how the 17501369Sdduvall * MAC address is represented in NVmem. We may need to swap it 17511369Sdduvall * around on a little-endian host ... 17521369Sdduvall */ 17531369Sdduvall #ifdef _BIG_ENDIAN 17541369Sdduvall mac = mac_high; 17551369Sdduvall mac = mac << 32; 17561369Sdduvall mac |= mac_low; 17571369Sdduvall #else 17581369Sdduvall mac = BGE_BSWAP_32(mac_high); 17591369Sdduvall mac = mac << 32; 17601369Sdduvall mac |= BGE_BSWAP_32(mac_low); 17611369Sdduvall #endif /* _BIG_ENDIAN */ 17621369Sdduvall 17631369Sdduvall return (mac); 17641369Sdduvall } 17651369Sdduvall 17661369Sdduvall #else /* BGE_SEE_IO32 || BGE_FLASH_IO32 */ 17671369Sdduvall 17681369Sdduvall /* 17691369Sdduvall * Dummy version for when we're not supporting NVmem access 17701369Sdduvall */ 17711369Sdduvall static uint64_t bge_get_nvmac(bge_t *bgep); 17721369Sdduvall #pragma inline(bge_get_nvmac) 17731369Sdduvall 17741369Sdduvall static uint64_t 17751369Sdduvall bge_get_nvmac(bge_t *bgep) 17761369Sdduvall { 17771369Sdduvall _NOTE(ARGUNUSED(bgep)) 17781369Sdduvall return (0ULL); 17791369Sdduvall } 17801369Sdduvall 17811369Sdduvall #endif /* BGE_SEE_IO32 || BGE_FLASH_IO32 */ 17821369Sdduvall 17831369Sdduvall /* 17841369Sdduvall * Determine the type of NVmem that is (or may be) attached to this chip, 17851369Sdduvall */ 17861369Sdduvall static enum bge_nvmem_type bge_nvmem_id(bge_t *bgep); 17871369Sdduvall #pragma no_inline(bge_nvmem_id) 17881369Sdduvall 17891369Sdduvall static enum bge_nvmem_type 17901369Sdduvall bge_nvmem_id(bge_t *bgep) 17911369Sdduvall { 17921369Sdduvall enum bge_nvmem_type nvtype; 17931369Sdduvall uint32_t config1; 17941369Sdduvall 17951369Sdduvall BGE_TRACE(("bge_nvmem_id($%p)", 17961369Sdduvall (void *)bgep)); 17971369Sdduvall 17981369Sdduvall switch (bgep->chipid.device) { 17991369Sdduvall default: 18001369Sdduvall /* 18011369Sdduvall * We shouldn't get here; it means we don't recognise 18021369Sdduvall * the chip, which means we don't know how to determine 18031369Sdduvall * what sort of NVmem (if any) it has. So we'll say 18041369Sdduvall * NONE, to disable the NVmem access code ... 18051369Sdduvall */ 18061369Sdduvall nvtype = BGE_NVTYPE_NONE; 18071369Sdduvall break; 18081369Sdduvall 18091369Sdduvall case DEVICE_ID_5700: 18101369Sdduvall case DEVICE_ID_5700x: 18111369Sdduvall case DEVICE_ID_5701: 18121369Sdduvall /* 18131369Sdduvall * These devices support *only* SEEPROMs 18141369Sdduvall */ 18151369Sdduvall nvtype = BGE_NVTYPE_SEEPROM; 18161369Sdduvall break; 18171369Sdduvall 18181369Sdduvall case DEVICE_ID_5702: 18191369Sdduvall case DEVICE_ID_5702fe: 18201369Sdduvall case DEVICE_ID_5703C: 18211369Sdduvall case DEVICE_ID_5703S: 18221369Sdduvall case DEVICE_ID_5704C: 18231369Sdduvall case DEVICE_ID_5704S: 18241369Sdduvall case DEVICE_ID_5704: 18251369Sdduvall case DEVICE_ID_5705M: 18261369Sdduvall case DEVICE_ID_5705C: 18271369Sdduvall case DEVICE_ID_5706: 18281369Sdduvall case DEVICE_ID_5782: 18291369Sdduvall case DEVICE_ID_5788: 1830*2135Szh199473 case DEVICE_ID_5789: 18311369Sdduvall case DEVICE_ID_5751: 18321369Sdduvall case DEVICE_ID_5751M: 18331369Sdduvall case DEVICE_ID_5721: 18341369Sdduvall case DEVICE_ID_5714C: 18351369Sdduvall case DEVICE_ID_5714S: 18361369Sdduvall case DEVICE_ID_5715C: 18371369Sdduvall config1 = bge_reg_get32(bgep, NVM_CONFIG1_REG); 18381369Sdduvall if (config1 & NVM_CFG1_FLASH_MODE) 18391369Sdduvall if (config1 & NVM_CFG1_BUFFERED_MODE) 18401369Sdduvall nvtype = BGE_NVTYPE_BUFFERED_FLASH; 18411369Sdduvall else 18421369Sdduvall nvtype = BGE_NVTYPE_UNBUFFERED_FLASH; 18431369Sdduvall else 18441369Sdduvall nvtype = BGE_NVTYPE_LEGACY_SEEPROM; 18451369Sdduvall break; 18461369Sdduvall } 18471369Sdduvall 18481369Sdduvall return (nvtype); 18491369Sdduvall } 18501369Sdduvall 18511369Sdduvall #undef BGE_DBG 18521369Sdduvall #define BGE_DBG BGE_DBG_CHIP /* debug flag for this code */ 18531369Sdduvall 18541369Sdduvall static void 18551369Sdduvall bge_init_recv_rule(bge_t *bgep) 18561369Sdduvall { 18571369Sdduvall bge_recv_rule_t *rulep; 18581369Sdduvall uint32_t i; 18591369Sdduvall 18601369Sdduvall /* 18611369Sdduvall * receive rule: direct all TCP traffic to ring RULE_MATCH_TO_RING 18621369Sdduvall * 1. to direct UDP traffic, set: 18631369Sdduvall * rulep->control = RULE_PROTO_CONTROL; 18641369Sdduvall * rulep->mask_value = RULE_UDP_MASK_VALUE; 18651369Sdduvall * 2. to direct ICMP traffic, set: 18661369Sdduvall * rulep->control = RULE_PROTO_CONTROL; 18671369Sdduvall * rulep->mask_value = RULE_ICMP_MASK_VALUE; 18681369Sdduvall * 3. to direct traffic by source ip, set: 18691369Sdduvall * rulep->control = RULE_SIP_CONTROL; 18701369Sdduvall * rulep->mask_value = RULE_SIP_MASK_VALUE; 18711369Sdduvall */ 18721369Sdduvall rulep = bgep->recv_rules; 18731369Sdduvall rulep->control = RULE_PROTO_CONTROL; 18741369Sdduvall rulep->mask_value = RULE_TCP_MASK_VALUE; 18751369Sdduvall 18761369Sdduvall /* 18771369Sdduvall * set receive rule registers 18781369Sdduvall */ 18791369Sdduvall rulep = bgep->recv_rules; 18801369Sdduvall for (i = 0; i < RECV_RULES_NUM_MAX; i++, rulep++) { 18811369Sdduvall bge_reg_put32(bgep, RECV_RULE_MASK_REG(i), rulep->mask_value); 18821369Sdduvall bge_reg_put32(bgep, RECV_RULE_CONTROL_REG(i), rulep->control); 18831369Sdduvall } 18841369Sdduvall } 18851369Sdduvall 18861369Sdduvall /* 18871369Sdduvall * Using the values captured by bge_chip_cfg_init(), and additional probes 18881369Sdduvall * as required, characterise the chip fully: determine the label by which 18891369Sdduvall * to refer to this chip, the correct settings for various registers, and 18901369Sdduvall * of course whether the device and/or subsystem are supported! 18911369Sdduvall */ 18921865Sdilpreet int bge_chip_id_init(bge_t *bgep); 18931369Sdduvall #pragma no_inline(bge_chip_id_init) 18941369Sdduvall 18951865Sdilpreet int 18961369Sdduvall bge_chip_id_init(bge_t *bgep) 18971369Sdduvall { 18981369Sdduvall char buf[MAXPATHLEN]; /* any risk of stack overflow? */ 18991369Sdduvall boolean_t sys_ok; 19001369Sdduvall boolean_t dev_ok; 19011369Sdduvall chip_id_t *cidp; 19021369Sdduvall uint32_t subid; 19031369Sdduvall char *devname; 19041369Sdduvall char *sysname; 19051369Sdduvall int *ids; 19061369Sdduvall int err; 19071369Sdduvall uint_t i; 19081369Sdduvall 19091369Sdduvall ASSERT(bgep->bge_chip_state == BGE_CHIP_INITIAL); 19101369Sdduvall 19111369Sdduvall sys_ok = dev_ok = B_FALSE; 19121369Sdduvall cidp = &bgep->chipid; 19131369Sdduvall 19141369Sdduvall /* 19151369Sdduvall * Check the PCI device ID to determine the generic chip type and 19161369Sdduvall * select parameters that depend on this. 19171369Sdduvall * 19181369Sdduvall * Note: because the SPARC platforms in general don't fit the 19191369Sdduvall * SEEPROM 'behind' the chip, the PCI revision ID register reads 19201369Sdduvall * as zero - which is why we use <asic_rev> rather than <revision> 19211369Sdduvall * below ... 19221369Sdduvall * 19231369Sdduvall * Note: in general we can't distinguish between the Copper/SerDes 19241369Sdduvall * versions by ID alone, as some Copper devices (e.g. some but not 19251369Sdduvall * all 5703Cs) have the same ID as the SerDes equivalents. So we 19261369Sdduvall * treat them the same here, and the MII code works out the media 19271369Sdduvall * type later on ... 19281369Sdduvall */ 19291369Sdduvall cidp->mbuf_base = bge_mbuf_pool_base; 19301369Sdduvall cidp->mbuf_length = bge_mbuf_pool_len; 19311369Sdduvall cidp->recv_slots = BGE_RECV_SLOTS_USED; 19321369Sdduvall cidp->bge_dma_rwctrl = bge_dma_rwctrl; 19331369Sdduvall cidp->pci_type = BGE_PCI_X; 19341369Sdduvall cidp->statistic_type = BGE_STAT_BLK; 19351908Sly149593 cidp->mbuf_lo_water_rdma = bge_mbuf_lo_water_rdma; 19361908Sly149593 cidp->mbuf_lo_water_rmac = bge_mbuf_lo_water_rmac; 19371908Sly149593 cidp->mbuf_hi_water = bge_mbuf_hi_water; 19381369Sdduvall 19391369Sdduvall if (cidp->rx_rings == 0 || cidp->rx_rings > BGE_RECV_RINGS_MAX) 19401369Sdduvall cidp->rx_rings = BGE_RECV_RINGS_DEFAULT; 19411369Sdduvall if (cidp->tx_rings == 0 || cidp->tx_rings > BGE_SEND_RINGS_MAX) 19421369Sdduvall cidp->tx_rings = BGE_SEND_RINGS_DEFAULT; 19431369Sdduvall 19441369Sdduvall cidp->msi_enabled = B_FALSE; 19451369Sdduvall 19461369Sdduvall switch (cidp->device) { 19471369Sdduvall case DEVICE_ID_5700: 19481369Sdduvall case DEVICE_ID_5700x: 19491369Sdduvall cidp->chip_label = 5700; 1950*2135Szh199473 cidp->flags |= CHIP_FLAG_PARTIAL_CSUM; 19511369Sdduvall break; 19521369Sdduvall 19531369Sdduvall case DEVICE_ID_5701: 19541369Sdduvall cidp->chip_label = 5701; 19551369Sdduvall dev_ok = B_TRUE; 1956*2135Szh199473 cidp->flags |= CHIP_FLAG_PARTIAL_CSUM; 19571369Sdduvall break; 19581369Sdduvall 19591369Sdduvall case DEVICE_ID_5702: 19601369Sdduvall case DEVICE_ID_5702fe: 19611369Sdduvall cidp->chip_label = 5702; 19621369Sdduvall dev_ok = B_TRUE; 1963*2135Szh199473 cidp->flags |= CHIP_FLAG_PARTIAL_CSUM; 1964*2135Szh199473 cidp->pci_type = BGE_PCI; 19651369Sdduvall break; 19661369Sdduvall 19671369Sdduvall case DEVICE_ID_5703C: 19681369Sdduvall case DEVICE_ID_5703S: 19691369Sdduvall case DEVICE_ID_5703: 19701369Sdduvall /* 19711369Sdduvall * Revision A0 of the 5703/5793 had various errata 19721369Sdduvall * that we can't or don't work around, so it's not 19731369Sdduvall * supported, but all later versions are 19741369Sdduvall */ 19751369Sdduvall cidp->chip_label = cidp->subven == VENDOR_ID_SUN ? 5793 : 5703; 19761369Sdduvall if (bgep->chipid.asic_rev != MHCR_CHIP_REV_5703_A0) 19771369Sdduvall dev_ok = B_TRUE; 1978*2135Szh199473 cidp->flags |= CHIP_FLAG_PARTIAL_CSUM; 19791369Sdduvall break; 19801369Sdduvall 19811369Sdduvall case DEVICE_ID_5704C: 19821369Sdduvall case DEVICE_ID_5704S: 19831369Sdduvall case DEVICE_ID_5704: 19841369Sdduvall /* 19851369Sdduvall * Revision A0 of the 5704/5794 had various errata 19861369Sdduvall * but we have workarounds, so it *is* supported. 19871369Sdduvall */ 19881369Sdduvall cidp->chip_label = cidp->subven == VENDOR_ID_SUN ? 5794 : 5704; 19891369Sdduvall cidp->mbuf_base = bge_mbuf_pool_base_5704; 19901369Sdduvall cidp->mbuf_length = bge_mbuf_pool_len_5704; 19911369Sdduvall dev_ok = B_TRUE; 1992*2135Szh199473 if (cidp->asic_rev < MHCR_CHIP_REV_5704_B0) 1993*2135Szh199473 cidp->flags |= CHIP_FLAG_PARTIAL_CSUM; 19941369Sdduvall break; 19951369Sdduvall 19961369Sdduvall case DEVICE_ID_5705C: 19971369Sdduvall case DEVICE_ID_5705M: 19981369Sdduvall case DEVICE_ID_5705MA3: 19991369Sdduvall case DEVICE_ID_5705F: 20001369Sdduvall cidp->chip_label = 5705; 20011908Sly149593 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 20021908Sly149593 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 20031908Sly149593 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 20041369Sdduvall cidp->mbuf_base = bge_mbuf_pool_base_5705; 20051369Sdduvall cidp->mbuf_length = bge_mbuf_pool_len_5705; 20061369Sdduvall cidp->recv_slots = BGE_RECV_SLOTS_5705; 20071369Sdduvall cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 20081908Sly149593 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 20091369Sdduvall cidp->flags |= CHIP_FLAG_NO_JUMBO; 2010*2135Szh199473 cidp->flags |= CHIP_FLAG_PARTIAL_CSUM; 2011*2135Szh199473 cidp->pci_type = BGE_PCI; 20121369Sdduvall cidp->statistic_type = BGE_STAT_REG; 20131369Sdduvall dev_ok = B_TRUE; 20141369Sdduvall break; 20151369Sdduvall 20161369Sdduvall case DEVICE_ID_5706: 20171369Sdduvall cidp->chip_label = 5706; 20181369Sdduvall cidp->flags |= CHIP_FLAG_NO_JUMBO; 20191369Sdduvall break; 20201369Sdduvall 20211369Sdduvall case DEVICE_ID_5782: 20221369Sdduvall /* 20231369Sdduvall * Apart from the label, we treat this as a 5705(?) 20241369Sdduvall */ 20251369Sdduvall cidp->chip_label = 5782; 20261908Sly149593 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 20271908Sly149593 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 20281908Sly149593 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 20291369Sdduvall cidp->mbuf_base = bge_mbuf_pool_base_5705; 20301369Sdduvall cidp->mbuf_length = bge_mbuf_pool_len_5705; 20311369Sdduvall cidp->recv_slots = BGE_RECV_SLOTS_5705; 20321369Sdduvall cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 20331908Sly149593 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 20341369Sdduvall cidp->flags |= CHIP_FLAG_NO_JUMBO; 2035*2135Szh199473 cidp->flags |= CHIP_FLAG_PARTIAL_CSUM; 20361369Sdduvall cidp->statistic_type = BGE_STAT_REG; 20371369Sdduvall dev_ok = B_TRUE; 20381369Sdduvall break; 20391369Sdduvall 20401369Sdduvall case DEVICE_ID_5788: 20411369Sdduvall /* 20421369Sdduvall * Apart from the label, we treat this as a 5705(?) 20431369Sdduvall */ 20441369Sdduvall cidp->chip_label = 5788; 20451908Sly149593 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 20461908Sly149593 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 20471908Sly149593 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 20481369Sdduvall cidp->mbuf_base = bge_mbuf_pool_base_5705; 20491369Sdduvall cidp->mbuf_length = bge_mbuf_pool_len_5705; 20501369Sdduvall cidp->recv_slots = BGE_RECV_SLOTS_5705; 20511369Sdduvall cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 20521908Sly149593 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 20531369Sdduvall cidp->statistic_type = BGE_STAT_REG; 20541369Sdduvall cidp->flags |= CHIP_FLAG_NO_JUMBO; 20551369Sdduvall dev_ok = B_TRUE; 20561369Sdduvall break; 20571369Sdduvall 20581369Sdduvall case DEVICE_ID_5714C: 20591369Sdduvall if (cidp->revision >= REVISION_ID_5714_A2) 20601369Sdduvall cidp->msi_enabled = bge_enable_msi; 20611369Sdduvall /* FALLTHRU */ 20621369Sdduvall case DEVICE_ID_5714S: 20631369Sdduvall cidp->chip_label = 5714; 20641908Sly149593 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 20651908Sly149593 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 20661908Sly149593 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 20671369Sdduvall cidp->mbuf_base = bge_mbuf_pool_base_5721; 20681369Sdduvall cidp->mbuf_length = bge_mbuf_pool_len_5721; 20691369Sdduvall cidp->recv_slots = BGE_RECV_SLOTS_5721; 20701369Sdduvall cidp->bge_dma_rwctrl = bge_dma_rwctrl_5714; 20711369Sdduvall cidp->bge_mlcr_default = bge_mlcr_default_5714; 20721369Sdduvall cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 20731908Sly149593 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 20741369Sdduvall cidp->pci_type = BGE_PCI_E; 20751369Sdduvall cidp->statistic_type = BGE_STAT_REG; 20761369Sdduvall dev_ok = B_TRUE; 20771369Sdduvall break; 20781369Sdduvall 20791369Sdduvall case DEVICE_ID_5715C: 20801369Sdduvall cidp->chip_label = 5715; 20811908Sly149593 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 20821908Sly149593 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 20831908Sly149593 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 20841369Sdduvall cidp->mbuf_base = bge_mbuf_pool_base_5721; 20851369Sdduvall cidp->mbuf_length = bge_mbuf_pool_len_5721; 20861369Sdduvall cidp->recv_slots = BGE_RECV_SLOTS_5721; 20871369Sdduvall cidp->bge_dma_rwctrl = bge_dma_rwctrl_5715; 20881369Sdduvall cidp->bge_mlcr_default = bge_mlcr_default_5714; 20891369Sdduvall cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 20901908Sly149593 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 20911369Sdduvall cidp->pci_type = BGE_PCI_E; 20921369Sdduvall cidp->statistic_type = BGE_STAT_REG; 20931908Sly149593 if (cidp->revision >= REVISION_ID_5715_A2) 20941908Sly149593 cidp->msi_enabled = bge_enable_msi; 20951369Sdduvall dev_ok = B_TRUE; 20961369Sdduvall break; 20971369Sdduvall 20981369Sdduvall case DEVICE_ID_5721: 20991369Sdduvall cidp->chip_label = 5721; 21001908Sly149593 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 21011908Sly149593 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 21021908Sly149593 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 21031369Sdduvall cidp->mbuf_base = bge_mbuf_pool_base_5721; 21041369Sdduvall cidp->mbuf_length = bge_mbuf_pool_len_5721; 21051369Sdduvall cidp->recv_slots = BGE_RECV_SLOTS_5721; 21061369Sdduvall cidp->bge_dma_rwctrl = bge_dma_rwctrl_5721; 21071369Sdduvall cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 21081908Sly149593 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 21091369Sdduvall cidp->pci_type = BGE_PCI_E; 21101369Sdduvall cidp->statistic_type = BGE_STAT_REG; 21111369Sdduvall cidp->flags |= CHIP_FLAG_NO_JUMBO; 21121369Sdduvall dev_ok = B_TRUE; 21131369Sdduvall break; 21141369Sdduvall 21151369Sdduvall case DEVICE_ID_5751: 21161369Sdduvall case DEVICE_ID_5751M: 21171369Sdduvall cidp->chip_label = 5751; 21181908Sly149593 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 21191908Sly149593 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 21201908Sly149593 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 21211369Sdduvall cidp->mbuf_base = bge_mbuf_pool_base_5721; 21221369Sdduvall cidp->mbuf_length = bge_mbuf_pool_len_5721; 21231369Sdduvall cidp->recv_slots = BGE_RECV_SLOTS_5721; 21241369Sdduvall cidp->bge_dma_rwctrl = bge_dma_rwctrl_5721; 21251369Sdduvall cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 21261908Sly149593 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 21271369Sdduvall cidp->pci_type = BGE_PCI_E; 21281369Sdduvall cidp->statistic_type = BGE_STAT_REG; 21291369Sdduvall cidp->flags |= CHIP_FLAG_NO_JUMBO; 21301369Sdduvall dev_ok = B_TRUE; 21311369Sdduvall break; 21321369Sdduvall 2133*2135Szh199473 case DEVICE_ID_5789: 2134*2135Szh199473 cidp->chip_label = 5789; 2135*2135Szh199473 cidp->mbuf_base = bge_mbuf_pool_base_5721; 2136*2135Szh199473 cidp->mbuf_length = bge_mbuf_pool_len_5721; 2137*2135Szh199473 cidp->recv_slots = BGE_RECV_SLOTS_5721; 2138*2135Szh199473 cidp->bge_dma_rwctrl = bge_dma_rwctrl_5721; 2139*2135Szh199473 cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 2140*2135Szh199473 cidp->tx_rings = BGE_RECV_RINGS_MAX_5705; 2141*2135Szh199473 cidp->pci_type = BGE_PCI_E; 2142*2135Szh199473 cidp->statistic_type = BGE_STAT_REG; 2143*2135Szh199473 cidp->flags |= CHIP_FLAG_PARTIAL_CSUM; 2144*2135Szh199473 cidp->flags |= CHIP_FLAG_NO_JUMBO; 2145*2135Szh199473 cidp->msi_enabled = B_TRUE; 2146*2135Szh199473 dev_ok = B_TRUE; 2147*2135Szh199473 break; 2148*2135Szh199473 21491369Sdduvall } 21501369Sdduvall 21511369Sdduvall /* 21521369Sdduvall * Setup the default jumbo parameter. 21531369Sdduvall */ 21541369Sdduvall cidp->ethmax_size = ETHERMAX; 21551369Sdduvall cidp->snd_buff_size = BGE_SEND_BUFF_SIZE_DEFAULT; 21561908Sly149593 cidp->std_buf_size = BGE_STD_BUFF_SIZE; 21571369Sdduvall 21581369Sdduvall /* 21591369Sdduvall * If jumbo is enabled and this kind of chipset supports jumbo feature, 21601369Sdduvall * setup below jumbo specific parameters. 21611908Sly149593 * 21621908Sly149593 * For BCM5714/5715, there is only one standard receive ring. So the 21631908Sly149593 * std buffer size should be set to BGE_JUMBO_BUFF_SIZE when jumbo 21641908Sly149593 * feature is enabled. 21651369Sdduvall */ 21661369Sdduvall if (bge_jumbo_enable && 21671369Sdduvall !(cidp->flags & CHIP_FLAG_NO_JUMBO) && 21681369Sdduvall (cidp->default_mtu > BGE_DEFAULT_MTU) && 21691369Sdduvall (cidp->default_mtu <= BGE_MAXIMUM_MTU)) { 21701908Sly149593 if (DEVICE_5714_SERIES_CHIPSETS(bgep)) { 21711908Sly149593 cidp->mbuf_lo_water_rdma = 21721908Sly149593 RDMA_MBUF_LOWAT_5714_JUMBO; 21731908Sly149593 cidp->mbuf_lo_water_rmac = 21741908Sly149593 MAC_RX_MBUF_LOWAT_5714_JUMBO; 21751908Sly149593 cidp->mbuf_hi_water = MBUF_HIWAT_5714_JUMBO; 21761908Sly149593 cidp->jumbo_slots = 0; 21771908Sly149593 cidp->std_buf_size = BGE_JUMBO_BUFF_SIZE; 21781908Sly149593 } else { 21791908Sly149593 cidp->mbuf_lo_water_rdma = 21801908Sly149593 RDMA_MBUF_LOWAT_JUMBO; 21811908Sly149593 cidp->mbuf_lo_water_rmac = 21821908Sly149593 MAC_RX_MBUF_LOWAT_JUMBO; 21831908Sly149593 cidp->mbuf_hi_water = MBUF_HIWAT_JUMBO; 21841908Sly149593 cidp->jumbo_slots = BGE_JUMBO_SLOTS_USED; 21851908Sly149593 } 21861369Sdduvall cidp->recv_jumbo_size = BGE_JUMBO_BUFF_SIZE; 21871369Sdduvall cidp->snd_buff_size = BGE_SEND_BUFF_SIZE_JUMBO; 21881369Sdduvall cidp->ethmax_size = cidp->default_mtu + 21891369Sdduvall sizeof (struct ether_header); 21901369Sdduvall } 21911369Sdduvall 21921369Sdduvall /* 21931369Sdduvall * Identify the NV memory type: SEEPROM or Flash? 21941369Sdduvall */ 21951369Sdduvall cidp->nvtype = bge_nvmem_id(bgep); 21961369Sdduvall 21971369Sdduvall /* 21981369Sdduvall * Now, we want to check whether this device is part of a 21991369Sdduvall * supported subsystem (e.g., on the motherboard of a Sun 22001369Sdduvall * branded platform). 22011369Sdduvall * 22021369Sdduvall * Rule 1: If the Subsystem Vendor ID is "Sun", then it's OK ;-) 22031369Sdduvall */ 22041369Sdduvall if (cidp->subven == VENDOR_ID_SUN) 22051369Sdduvall sys_ok = B_TRUE; 22061369Sdduvall 22071369Sdduvall /* 22081369Sdduvall * Rule 2: If it's on the list on known subsystems, then it's OK. 22091369Sdduvall * Note: 0x14e41647 should *not* appear in the list, but the code 22101369Sdduvall * doesn't enforce that. 22111369Sdduvall */ 22121369Sdduvall err = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, bgep->devinfo, 22131369Sdduvall DDI_PROP_DONTPASS, knownids_propname, &ids, &i); 22141369Sdduvall if (err == DDI_PROP_SUCCESS) { 22151369Sdduvall /* 22161369Sdduvall * Got the list; scan for a matching subsystem vendor/device 22171369Sdduvall */ 22181369Sdduvall subid = (cidp->subven << 16) | cidp->subdev; 22191369Sdduvall while (i--) 22201369Sdduvall if (ids[i] == subid) 22211369Sdduvall sys_ok = B_TRUE; 22221369Sdduvall ddi_prop_free(ids); 22231369Sdduvall } 22241369Sdduvall 22251369Sdduvall /* 22261369Sdduvall * Rule 3: If it's a Taco/ENWS motherboard device, then it's OK 22271369Sdduvall * 22281369Sdduvall * Unfortunately, early SunBlade 1500s and 2500s didn't reprogram 22291369Sdduvall * the Subsystem Vendor ID, so it defaults to Broadcom. Therefore, 22301369Sdduvall * we have to check specially for the exact device paths to the 22311369Sdduvall * motherboard devices on those platforms ;-( 22321369Sdduvall * 22331369Sdduvall * Note: we can't just use the "supported-subsystems" mechanism 22341369Sdduvall * above, because the entry would have to be 0x14e41647 -- which 22351369Sdduvall * would then accept *any* plugin card that *didn't* contain a 22361369Sdduvall * (valid) SEEPROM ;-( 22371369Sdduvall */ 22381369Sdduvall sysname = ddi_node_name(ddi_root_node()); 22391369Sdduvall devname = ddi_pathname(bgep->devinfo, buf); 22401369Sdduvall ASSERT(strlen(devname) > 0); 22411369Sdduvall if (strcmp(sysname, "SUNW,Sun-Blade-1500") == 0) /* Taco */ 22421369Sdduvall if (strcmp(devname, "/pci@1f,700000/network@2") == 0) 22431369Sdduvall sys_ok = B_TRUE; 22441369Sdduvall if (strcmp(sysname, "SUNW,Sun-Blade-2500") == 0) /* ENWS */ 22451369Sdduvall if (strcmp(devname, "/pci@1c,600000/network@3") == 0) 22461369Sdduvall sys_ok = B_TRUE; 22471369Sdduvall 22481369Sdduvall /* 22491369Sdduvall * Now check what we've discovered: is this truly a supported 22501369Sdduvall * chip on (the motherboard of) a supported platform? 22511369Sdduvall * 22521369Sdduvall * Possible problems here: 22531369Sdduvall * 1) it's a completely unheard-of chip (e.g. 5761) 22541369Sdduvall * 2) it's a recognised but unsupported chip (e.g. 5701, 5703C-A0) 22551369Sdduvall * 3) it's a chip we would support if it were on the motherboard 22561369Sdduvall * of a Sun platform, but this one isn't ;-( 22571369Sdduvall */ 22581369Sdduvall if (cidp->chip_label == 0) 22591369Sdduvall bge_problem(bgep, 22601369Sdduvall "Device 'pci%04x,%04x' not recognized (%d?)", 22611369Sdduvall cidp->vendor, cidp->device, cidp->device); 22621369Sdduvall else if (!dev_ok) 22631369Sdduvall bge_problem(bgep, 22641369Sdduvall "Device 'pci%04x,%04x' (%d) revision %d not supported", 22651369Sdduvall cidp->vendor, cidp->device, cidp->chip_label, 22661369Sdduvall cidp->revision); 22671369Sdduvall #if BGE_DEBUGGING 22681369Sdduvall else if (!sys_ok) 22691369Sdduvall bge_problem(bgep, 22701369Sdduvall "%d-based subsystem 'pci%04x,%04x' not validated", 22711369Sdduvall cidp->chip_label, cidp->subven, cidp->subdev); 22721369Sdduvall #endif 22731369Sdduvall else 22741369Sdduvall cidp->flags |= CHIP_FLAG_SUPPORTED; 22751865Sdilpreet if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) 22761865Sdilpreet return (EIO); 22771865Sdilpreet return (0); 22781369Sdduvall } 22791369Sdduvall 22801369Sdduvall void 22811369Sdduvall bge_chip_msi_trig(bge_t *bgep) 22821369Sdduvall { 22831369Sdduvall uint32_t regval; 22841369Sdduvall 22851369Sdduvall regval = bgep->param_msi_cnt<<4; 22861369Sdduvall bge_reg_set32(bgep, HOST_COALESCE_MODE_REG, regval); 22871369Sdduvall BGE_DEBUG(("bge_chip_msi_trig:data = %d", regval)); 22881369Sdduvall } 22891369Sdduvall 22901369Sdduvall /* 22911369Sdduvall * Various registers that control the chip's internal engines (state 22921369Sdduvall * machines) have a <reset> and <enable> bits (fortunately, in the 22931369Sdduvall * same place in each such register :-). 22941369Sdduvall * 22951369Sdduvall * To reset the state machine, the <reset> bit must be written with 1; 22961369Sdduvall * it will then read back as 1 while the reset is in progress, but 22971369Sdduvall * self-clear to 0 when the reset completes. 22981369Sdduvall * 22991369Sdduvall * To enable a state machine, one must set the <enable> bit, which 23001369Sdduvall * will continue to read back as 0 until the state machine is running. 23011369Sdduvall * 23021369Sdduvall * To disable a state machine, the <enable> bit must be cleared, but 23031369Sdduvall * it will continue to read back as 1 until the state machine actually 23041369Sdduvall * stops. 23051369Sdduvall * 23061369Sdduvall * This routine implements polling for completion of a reset, enable 23071369Sdduvall * or disable operation, returning B_TRUE on success (bit reached the 23081369Sdduvall * required state) or B_FALSE on timeout (200*100us == 20ms). 23091369Sdduvall */ 23101369Sdduvall static boolean_t bge_chip_poll_engine(bge_t *bgep, bge_regno_t regno, 23111369Sdduvall uint32_t mask, uint32_t val); 23121369Sdduvall #pragma no_inline(bge_chip_poll_engine) 23131369Sdduvall 23141369Sdduvall static boolean_t 23151369Sdduvall bge_chip_poll_engine(bge_t *bgep, bge_regno_t regno, 23161369Sdduvall uint32_t mask, uint32_t val) 23171369Sdduvall { 23181369Sdduvall uint32_t regval; 23191369Sdduvall uint32_t n; 23201369Sdduvall 23211369Sdduvall BGE_TRACE(("bge_chip_poll_engine($%p, 0x%lx, 0x%x, 0x%x)", 23221369Sdduvall (void *)bgep, regno, mask, val)); 23231369Sdduvall 23241369Sdduvall for (n = 200; n; --n) { 23251369Sdduvall regval = bge_reg_get32(bgep, regno); 23261369Sdduvall if ((regval & mask) == val) 23271369Sdduvall return (B_TRUE); 23281369Sdduvall drv_usecwait(100); 23291369Sdduvall } 23301369Sdduvall 23311865Sdilpreet bge_fm_ereport(bgep, DDI_FM_DEVICE_NO_RESPONSE); 23321369Sdduvall return (B_FALSE); 23331369Sdduvall } 23341369Sdduvall 23351369Sdduvall /* 23361369Sdduvall * Various registers that control the chip's internal engines (state 23371369Sdduvall * machines) have a <reset> bit (fortunately, in the same place in 23381369Sdduvall * each such register :-). To reset the state machine, this bit must 23391369Sdduvall * be written with 1; it will then read back as 1 while the reset is 23401369Sdduvall * in progress, but self-clear to 0 when the reset completes. 23411369Sdduvall * 23421369Sdduvall * This code sets the bit, then polls for it to read back as zero. 23431369Sdduvall * The return value is B_TRUE on success (reset bit cleared itself), 23441369Sdduvall * or B_FALSE if the state machine didn't recover :( 23451369Sdduvall * 23461369Sdduvall * NOTE: the Core reset is similar to other resets, except that we 23471369Sdduvall * can't poll for completion, since the Core reset disables memory 23481369Sdduvall * access! So we just have to assume that it will all complete in 23491369Sdduvall * 100us. See Broadcom document 570X-PG102-R, p102, steps 4-5. 23501369Sdduvall */ 23511369Sdduvall static boolean_t bge_chip_reset_engine(bge_t *bgep, bge_regno_t regno); 23521369Sdduvall #pragma no_inline(bge_chip_reset_engine) 23531369Sdduvall 23541369Sdduvall static boolean_t 23551369Sdduvall bge_chip_reset_engine(bge_t *bgep, bge_regno_t regno) 23561369Sdduvall { 23571369Sdduvall uint32_t regval; 23581369Sdduvall uint32_t val32; 23591369Sdduvall 23601369Sdduvall regval = bge_reg_get32(bgep, regno); 23611369Sdduvall 23621369Sdduvall BGE_TRACE(("bge_chip_reset_engine($%p, 0x%lx)", 23631369Sdduvall (void *)bgep, regno)); 23641369Sdduvall BGE_DEBUG(("bge_chip_reset_engine: 0x%lx before reset = 0x%08x", 23651369Sdduvall regno, regval)); 23661369Sdduvall 23671369Sdduvall regval |= STATE_MACHINE_RESET_BIT; 23681369Sdduvall 23691369Sdduvall switch (regno) { 23701369Sdduvall case MISC_CONFIG_REG: 23711369Sdduvall /* 23721369Sdduvall * BCM5714/5721/5751 pcie chip special case. In order to avoid 23731369Sdduvall * resetting PCIE block and bringing PCIE link down, bit 29 23741369Sdduvall * in the register needs to be set first, and then set it again 23751369Sdduvall * while the reset bit is written. 23761369Sdduvall * See:P500 of 57xx-PG102-RDS.pdf. 23771369Sdduvall */ 23781369Sdduvall if (DEVICE_5705_SERIES_CHIPSETS(bgep)|| 23791369Sdduvall DEVICE_5721_SERIES_CHIPSETS(bgep)|| 23801369Sdduvall DEVICE_5714_SERIES_CHIPSETS(bgep)) { 23811369Sdduvall regval |= MISC_CONFIG_GPHY_POWERDOWN_OVERRIDE; 23821369Sdduvall if (bgep->chipid.pci_type == BGE_PCI_E) { 23831369Sdduvall if (bgep->chipid.asic_rev == 23841369Sdduvall MHCR_CHIP_REV_5751_A0 || 23851369Sdduvall bgep->chipid.asic_rev == 23861369Sdduvall MHCR_CHIP_REV_5721_A0) { 23871369Sdduvall val32 = bge_reg_get32(bgep, 23881369Sdduvall PHY_TEST_CTRL_REG); 23891369Sdduvall if (val32 == (PHY_PCIE_SCRAM_MODE | 23901369Sdduvall PHY_PCIE_LTASS_MODE)) 23911369Sdduvall bge_reg_put32(bgep, 23921369Sdduvall PHY_TEST_CTRL_REG, 23931369Sdduvall PHY_PCIE_SCRAM_MODE); 23941369Sdduvall val32 = pci_config_get32 23951369Sdduvall (bgep->cfg_handle, 23961369Sdduvall PCI_CONF_BGE_CLKCTL); 23971369Sdduvall val32 |= CLKCTL_PCIE_A0_FIX; 23981369Sdduvall pci_config_put32(bgep->cfg_handle, 23991369Sdduvall PCI_CONF_BGE_CLKCTL, val32); 24001369Sdduvall } 24011369Sdduvall bge_reg_set32(bgep, regno, 24021369Sdduvall MISC_CONFIG_GRC_RESET_DISABLE); 24031369Sdduvall regval |= MISC_CONFIG_GRC_RESET_DISABLE; 24041369Sdduvall } 24051369Sdduvall } 24061369Sdduvall 24071369Sdduvall /* 24081369Sdduvall * Special case - causes Core reset 24091369Sdduvall * 24101369Sdduvall * On SPARC v9 we want to ensure that we don't start 24111369Sdduvall * timing until the I/O access has actually reached 24121369Sdduvall * the chip, otherwise we might make the next access 24131369Sdduvall * too early. And we can't just force the write out 24141369Sdduvall * by following it with a read (even to config space) 24151369Sdduvall * because that would cause the fault we're trying 24161369Sdduvall * to avoid. Hence the need for membar_sync() here. 24171369Sdduvall */ 24181369Sdduvall ddi_put32(bgep->io_handle, PIO_ADDR(bgep, regno), regval); 24191369Sdduvall #ifdef __sparcv9 24201369Sdduvall membar_sync(); 24211369Sdduvall #endif /* __sparcv9 */ 24221369Sdduvall /* 24231369Sdduvall * On some platforms,system need about 300us for 24241369Sdduvall * link setup. 24251369Sdduvall */ 24261369Sdduvall drv_usecwait(300); 24271369Sdduvall 24281369Sdduvall if (bgep->chipid.pci_type == BGE_PCI_E) { 24291369Sdduvall /* PCI-E device need more reset time */ 24301369Sdduvall drv_usecwait(120000); 24311369Sdduvall 24321369Sdduvall /* Set PCIE max payload size and clear error status. */ 2433*2135Szh199473 if ((bgep->chipid.chip_label == 5721) || 2434*2135Szh199473 (bgep->chipid.chip_label == 5751) || 2435*2135Szh199473 (bgep->chipid.chip_label == 5789)) { 24361369Sdduvall pci_config_put16(bgep->cfg_handle, 24371369Sdduvall PCI_CONF_DEV_CTRL, READ_REQ_SIZE_MAX); 24381369Sdduvall pci_config_put16(bgep->cfg_handle, 24391369Sdduvall PCI_CONF_DEV_STUS, DEVICE_ERROR_STUS); 24401369Sdduvall } 24411369Sdduvall } 24421369Sdduvall 24431369Sdduvall BGE_PCICHK(bgep); 24441369Sdduvall return (B_TRUE); 24451369Sdduvall 24461369Sdduvall default: 24471369Sdduvall bge_reg_put32(bgep, regno, regval); 24481369Sdduvall return (bge_chip_poll_engine(bgep, regno, 24491865Sdilpreet STATE_MACHINE_RESET_BIT, 0)); 24501369Sdduvall } 24511369Sdduvall } 24521369Sdduvall 24531369Sdduvall /* 24541369Sdduvall * Various registers that control the chip's internal engines (state 24551369Sdduvall * machines) have an <enable> bit (fortunately, in the same place in 24561369Sdduvall * each such register :-). To stop the state machine, this bit must 24571369Sdduvall * be written with 0, then polled to see when the state machine has 24581369Sdduvall * actually stopped. 24591369Sdduvall * 24601369Sdduvall * The return value is B_TRUE on success (enable bit cleared), or 24611369Sdduvall * B_FALSE if the state machine didn't stop :( 24621369Sdduvall */ 24631369Sdduvall static boolean_t bge_chip_disable_engine(bge_t *bgep, bge_regno_t regno, 24641369Sdduvall uint32_t morebits); 24651369Sdduvall #pragma no_inline(bge_chip_disable_engine) 24661369Sdduvall 24671369Sdduvall static boolean_t 24681369Sdduvall bge_chip_disable_engine(bge_t *bgep, bge_regno_t regno, uint32_t morebits) 24691369Sdduvall { 24701369Sdduvall uint32_t regval; 24711369Sdduvall 24721369Sdduvall BGE_TRACE(("bge_chip_disable_engine($%p, 0x%lx, 0x%x)", 24731369Sdduvall (void *)bgep, regno, morebits)); 24741369Sdduvall 24751369Sdduvall switch (regno) { 24761369Sdduvall case FTQ_RESET_REG: 24771369Sdduvall /* 24781369Sdduvall * Not quite like the others; it doesn't 24791369Sdduvall * have an <enable> bit, but instead we 24801369Sdduvall * have to set and then clear all the bits 24811369Sdduvall */ 24821369Sdduvall bge_reg_put32(bgep, regno, ~(uint32_t)0); 24831369Sdduvall drv_usecwait(100); 24841369Sdduvall bge_reg_put32(bgep, regno, 0); 24851369Sdduvall return (B_TRUE); 24861369Sdduvall 24871369Sdduvall default: 24881369Sdduvall regval = bge_reg_get32(bgep, regno); 24891369Sdduvall regval &= ~STATE_MACHINE_ENABLE_BIT; 24901369Sdduvall regval &= ~morebits; 24911369Sdduvall bge_reg_put32(bgep, regno, regval); 24921369Sdduvall return (bge_chip_poll_engine(bgep, regno, 24931865Sdilpreet STATE_MACHINE_ENABLE_BIT, 0)); 24941369Sdduvall } 24951369Sdduvall } 24961369Sdduvall 24971369Sdduvall /* 24981369Sdduvall * Various registers that control the chip's internal engines (state 24991369Sdduvall * machines) have an <enable> bit (fortunately, in the same place in 25001369Sdduvall * each such register :-). To start the state machine, this bit must 25011369Sdduvall * be written with 1, then polled to see when the state machine has 25021369Sdduvall * actually started. 25031369Sdduvall * 25041369Sdduvall * The return value is B_TRUE on success (enable bit set), or 25051369Sdduvall * B_FALSE if the state machine didn't start :( 25061369Sdduvall */ 25071369Sdduvall static boolean_t bge_chip_enable_engine(bge_t *bgep, bge_regno_t regno, 25081369Sdduvall uint32_t morebits); 25091369Sdduvall #pragma no_inline(bge_chip_enable_engine) 25101369Sdduvall 25111369Sdduvall static boolean_t 25121369Sdduvall bge_chip_enable_engine(bge_t *bgep, bge_regno_t regno, uint32_t morebits) 25131369Sdduvall { 25141369Sdduvall uint32_t regval; 25151369Sdduvall 25161369Sdduvall BGE_TRACE(("bge_chip_enable_engine($%p, 0x%lx, 0x%x)", 25171369Sdduvall (void *)bgep, regno, morebits)); 25181369Sdduvall 25191369Sdduvall switch (regno) { 25201369Sdduvall case FTQ_RESET_REG: 25211369Sdduvall /* 25221369Sdduvall * Not quite like the others; it doesn't 25231369Sdduvall * have an <enable> bit, but instead we 25241369Sdduvall * have to set and then clear all the bits 25251369Sdduvall */ 25261369Sdduvall bge_reg_put32(bgep, regno, ~(uint32_t)0); 25271369Sdduvall drv_usecwait(100); 25281369Sdduvall bge_reg_put32(bgep, regno, 0); 25291369Sdduvall return (B_TRUE); 25301369Sdduvall 25311369Sdduvall default: 25321369Sdduvall regval = bge_reg_get32(bgep, regno); 25331369Sdduvall regval |= STATE_MACHINE_ENABLE_BIT; 25341369Sdduvall regval |= morebits; 25351369Sdduvall bge_reg_put32(bgep, regno, regval); 25361369Sdduvall return (bge_chip_poll_engine(bgep, regno, 25371865Sdilpreet STATE_MACHINE_ENABLE_BIT, STATE_MACHINE_ENABLE_BIT)); 25381369Sdduvall } 25391369Sdduvall } 25401369Sdduvall 25411369Sdduvall /* 25421369Sdduvall * Reprogram the Ethernet, Transmit, and Receive MAC 25431369Sdduvall * modes to match the param_* variables 25441369Sdduvall */ 25451369Sdduvall static void bge_sync_mac_modes(bge_t *bgep); 25461369Sdduvall #pragma no_inline(bge_sync_mac_modes) 25471369Sdduvall 25481369Sdduvall static void 25491369Sdduvall bge_sync_mac_modes(bge_t *bgep) 25501369Sdduvall { 25511369Sdduvall uint32_t macmode; 25521369Sdduvall uint32_t regval; 25531369Sdduvall 25541369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 25551369Sdduvall 25561369Sdduvall /* 25571369Sdduvall * Reprogram the Ethernet MAC mode ... 25581369Sdduvall */ 25591369Sdduvall macmode = regval = bge_reg_get32(bgep, ETHERNET_MAC_MODE_REG); 25601369Sdduvall if ((bgep->chipid.flags & CHIP_FLAG_SERDES) && 25611369Sdduvall (bgep->param_loop_mode != BGE_LOOP_INTERNAL_MAC)) 25621369Sdduvall macmode &= ~ETHERNET_MODE_LINK_POLARITY; 25631369Sdduvall else 25641369Sdduvall macmode |= ETHERNET_MODE_LINK_POLARITY; 25651369Sdduvall macmode &= ~ETHERNET_MODE_PORTMODE_MASK; 25661369Sdduvall if ((bgep->chipid.flags & CHIP_FLAG_SERDES) && 25671369Sdduvall (bgep->param_loop_mode != BGE_LOOP_INTERNAL_MAC)) 25681369Sdduvall macmode |= ETHERNET_MODE_PORTMODE_TBI; 25691369Sdduvall else if (bgep->param_link_speed == 10 || bgep->param_link_speed == 100) 25701369Sdduvall macmode |= ETHERNET_MODE_PORTMODE_MII; 25711369Sdduvall else 25721369Sdduvall macmode |= ETHERNET_MODE_PORTMODE_GMII; 25731369Sdduvall if (bgep->param_link_duplex == LINK_DUPLEX_HALF) 25741369Sdduvall macmode |= ETHERNET_MODE_HALF_DUPLEX; 25751369Sdduvall else 25761369Sdduvall macmode &= ~ETHERNET_MODE_HALF_DUPLEX; 25771369Sdduvall if (bgep->param_loop_mode == BGE_LOOP_INTERNAL_MAC) 25781369Sdduvall macmode |= ETHERNET_MODE_MAC_LOOPBACK; 25791369Sdduvall else 25801369Sdduvall macmode &= ~ETHERNET_MODE_MAC_LOOPBACK; 25811369Sdduvall bge_reg_put32(bgep, ETHERNET_MAC_MODE_REG, macmode); 25821369Sdduvall BGE_DEBUG(("bge_sync_mac_modes($%p) Ethernet MAC mode 0x%x => 0x%x", 25831369Sdduvall (void *)bgep, regval, macmode)); 25841369Sdduvall 25851369Sdduvall /* 25861369Sdduvall * ... the Transmit MAC mode ... 25871369Sdduvall */ 25881369Sdduvall macmode = regval = bge_reg_get32(bgep, TRANSMIT_MAC_MODE_REG); 25891369Sdduvall if (bgep->param_link_tx_pause) 25901369Sdduvall macmode |= TRANSMIT_MODE_FLOW_CONTROL; 25911369Sdduvall else 25921369Sdduvall macmode &= ~TRANSMIT_MODE_FLOW_CONTROL; 25931369Sdduvall bge_reg_put32(bgep, TRANSMIT_MAC_MODE_REG, macmode); 25941369Sdduvall BGE_DEBUG(("bge_sync_mac_modes($%p) Transmit MAC mode 0x%x => 0x%x", 25951369Sdduvall (void *)bgep, regval, macmode)); 25961369Sdduvall 25971369Sdduvall /* 25981369Sdduvall * ... and the Receive MAC mode 25991369Sdduvall */ 26001369Sdduvall macmode = regval = bge_reg_get32(bgep, RECEIVE_MAC_MODE_REG); 26011369Sdduvall if (bgep->param_link_rx_pause) 26021369Sdduvall macmode |= RECEIVE_MODE_FLOW_CONTROL; 26031369Sdduvall else 26041369Sdduvall macmode &= ~RECEIVE_MODE_FLOW_CONTROL; 26051369Sdduvall bge_reg_put32(bgep, RECEIVE_MAC_MODE_REG, macmode); 26061369Sdduvall BGE_DEBUG(("bge_sync_mac_modes($%p) Receive MAC mode 0x%x => 0x%x", 26071369Sdduvall (void *)bgep, regval, macmode)); 26081369Sdduvall } 26091369Sdduvall 26101369Sdduvall /* 26111369Sdduvall * bge_chip_sync() -- program the chip with the unicast MAC address, 26121369Sdduvall * the multicast hash table, the required level of promiscuity, and 26131369Sdduvall * the current loopback mode ... 26141369Sdduvall */ 26151408Srandyf #ifdef BGE_IPMI_ASF 26161865Sdilpreet int bge_chip_sync(bge_t *bgep, boolean_t asf_keeplive); 26171408Srandyf #else 26181865Sdilpreet int bge_chip_sync(bge_t *bgep); 26191408Srandyf #endif 26201369Sdduvall #pragma no_inline(bge_chip_sync) 26211369Sdduvall 26221865Sdilpreet int 26231408Srandyf #ifdef BGE_IPMI_ASF 26241408Srandyf bge_chip_sync(bge_t *bgep, boolean_t asf_keeplive) 26251408Srandyf #else 26261369Sdduvall bge_chip_sync(bge_t *bgep) 26271408Srandyf #endif 26281369Sdduvall { 26291369Sdduvall void (*opfn)(bge_t *bgep, bge_regno_t reg, uint32_t bits); 26301369Sdduvall boolean_t promisc; 26311369Sdduvall uint64_t macaddr; 26321369Sdduvall uint32_t fill; 26331369Sdduvall int i; 26341865Sdilpreet int retval = DDI_SUCCESS; 26351369Sdduvall 26361369Sdduvall BGE_TRACE(("bge_chip_sync($%p)", 26371369Sdduvall (void *)bgep)); 26381369Sdduvall 26391369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 26401369Sdduvall 26411369Sdduvall promisc = B_FALSE; 26421369Sdduvall fill = ~(uint32_t)0; 26431369Sdduvall 26441369Sdduvall if (bgep->promisc) 26451369Sdduvall promisc = B_TRUE; 26461369Sdduvall else 26471369Sdduvall fill = (uint32_t)0; 26481369Sdduvall 26491369Sdduvall /* 26501369Sdduvall * If the TX/RX MAC engines are already running, we should stop 26511369Sdduvall * them (and reset the RX engine) before changing the parameters. 26521369Sdduvall * If they're not running, this will have no effect ... 26531369Sdduvall * 26541369Sdduvall * NOTE: this is currently disabled by default because stopping 26551369Sdduvall * and restarting the Tx engine may cause an outgoing packet in 26561369Sdduvall * transit to be truncated. Also, stopping and restarting the 26571369Sdduvall * Rx engine seems to not work correctly on the 5705. Testing 26581369Sdduvall * has not (yet!) revealed any problems with NOT stopping and 26591369Sdduvall * restarting these engines (and Broadcom say their drivers don't 26601369Sdduvall * do this), but if it is found to cause problems, this variable 26611369Sdduvall * can be patched to re-enable the old behaviour ... 26621369Sdduvall */ 26631369Sdduvall if (bge_stop_start_on_sync) { 26641408Srandyf #ifdef BGE_IPMI_ASF 26651865Sdilpreet if (!bgep->asf_enabled) { 26661865Sdilpreet if (!bge_chip_disable_engine(bgep, 26671865Sdilpreet RECEIVE_MAC_MODE_REG, RECEIVE_MODE_KEEP_VLAN_TAG)) 26681865Sdilpreet retval = DDI_FAILURE; 26691408Srandyf } else { 26701865Sdilpreet if (!bge_chip_disable_engine(bgep, 26711865Sdilpreet RECEIVE_MAC_MODE_REG, 0)) 26721865Sdilpreet retval = DDI_FAILURE; 26731408Srandyf } 26741408Srandyf #else 26751865Sdilpreet if (!bge_chip_disable_engine(bgep, RECEIVE_MAC_MODE_REG, 26761865Sdilpreet RECEIVE_MODE_KEEP_VLAN_TAG)) 26771865Sdilpreet retval = DDI_FAILURE; 26781408Srandyf #endif 26791865Sdilpreet if (!bge_chip_disable_engine(bgep, TRANSMIT_MAC_MODE_REG, 0)) 26801865Sdilpreet retval = DDI_FAILURE; 26811865Sdilpreet if (!bge_chip_reset_engine(bgep, RECEIVE_MAC_MODE_REG)) 26821865Sdilpreet retval = DDI_FAILURE; 26831369Sdduvall } 26841369Sdduvall 26851369Sdduvall /* 26861369Sdduvall * Reprogram the hashed multicast address table ... 26871369Sdduvall */ 26881369Sdduvall for (i = 0; i < BGE_HASH_TABLE_SIZE/32; ++i) 26891369Sdduvall bge_reg_put32(bgep, MAC_HASH_REG(i), 26901369Sdduvall bgep->mcast_hash[i] | fill); 26911369Sdduvall 26921408Srandyf #ifdef BGE_IPMI_ASF 26931408Srandyf if (!bgep->asf_enabled || !asf_keeplive) { 26941408Srandyf #endif 26951408Srandyf /* 26961408Srandyf * Transform the MAC address from host to chip format, then 26971408Srandyf * reprogram the transmit random backoff seed and the unicast 26981408Srandyf * MAC address(es) ... 26991408Srandyf */ 27001408Srandyf for (i = 0, fill = 0, macaddr = 0ull; i < ETHERADDRL; ++i) { 27011408Srandyf macaddr <<= 8; 27021408Srandyf macaddr |= bgep->curr_addr.addr[i]; 27031408Srandyf fill += bgep->curr_addr.addr[i]; 27041408Srandyf } 27051408Srandyf bge_reg_put32(bgep, MAC_TX_RANDOM_BACKOFF_REG, fill); 27061408Srandyf for (i = 0; i < MAC_ADDRESS_REGS_MAX; ++i) 27071408Srandyf bge_reg_put64(bgep, MAC_ADDRESS_REG(i), macaddr); 27081408Srandyf 27091408Srandyf BGE_DEBUG(("bge_chip_sync($%p) setting MAC address %012llx", 27101408Srandyf (void *)bgep, macaddr)); 27111408Srandyf #ifdef BGE_IPMI_ASF 27121369Sdduvall } 27131408Srandyf #endif 27141369Sdduvall 27151369Sdduvall /* 27161369Sdduvall * Set or clear the PROMISCUOUS mode bit 27171369Sdduvall */ 27181369Sdduvall opfn = promisc ? bge_reg_set32 : bge_reg_clr32; 27191369Sdduvall (*opfn)(bgep, RECEIVE_MAC_MODE_REG, RECEIVE_MODE_PROMISCUOUS); 27201369Sdduvall 27211369Sdduvall /* 27221369Sdduvall * Sync the rest of the MAC modes too ... 27231369Sdduvall */ 27241369Sdduvall bge_sync_mac_modes(bgep); 27251369Sdduvall 27261369Sdduvall /* 27271369Sdduvall * Restart RX/TX MAC engines if required ... 27281369Sdduvall */ 27291369Sdduvall if (bgep->bge_chip_state == BGE_CHIP_RUNNING) { 27301865Sdilpreet if (!bge_chip_enable_engine(bgep, TRANSMIT_MAC_MODE_REG, 0)) 27311865Sdilpreet retval = DDI_FAILURE; 27321408Srandyf #ifdef BGE_IPMI_ASF 27331865Sdilpreet if (!bgep->asf_enabled) { 27341865Sdilpreet if (!bge_chip_enable_engine(bgep, 27351865Sdilpreet RECEIVE_MAC_MODE_REG, RECEIVE_MODE_KEEP_VLAN_TAG)) 27361865Sdilpreet retval = DDI_FAILURE; 27371408Srandyf } else { 27381865Sdilpreet if (!bge_chip_enable_engine(bgep, 27391865Sdilpreet RECEIVE_MAC_MODE_REG, 0)) 27401865Sdilpreet retval = DDI_FAILURE; 27411408Srandyf } 27421408Srandyf #else 27431865Sdilpreet if (!bge_chip_enable_engine(bgep, RECEIVE_MAC_MODE_REG, 27441865Sdilpreet RECEIVE_MODE_KEEP_VLAN_TAG)) 27451865Sdilpreet retval = DDI_FAILURE; 27461408Srandyf #endif 27471369Sdduvall } 27481865Sdilpreet return (retval); 27491369Sdduvall } 27501369Sdduvall 27511369Sdduvall /* 27521369Sdduvall * This array defines the sequence of state machine control registers 27531369Sdduvall * in which the <enable> bit must be cleared to bring the chip to a 27541369Sdduvall * clean stop. Taken from Broadcom document 570X-PG102-R, p116. 27551369Sdduvall */ 27561369Sdduvall static bge_regno_t shutdown_engine_regs[] = { 27571369Sdduvall RECEIVE_MAC_MODE_REG, 27581369Sdduvall RCV_BD_INITIATOR_MODE_REG, 27591369Sdduvall RCV_LIST_PLACEMENT_MODE_REG, 27601369Sdduvall RCV_LIST_SELECTOR_MODE_REG, /* BCM5704 series only */ 27611369Sdduvall RCV_DATA_BD_INITIATOR_MODE_REG, 27621369Sdduvall RCV_DATA_COMPLETION_MODE_REG, 27631369Sdduvall RCV_BD_COMPLETION_MODE_REG, 27641369Sdduvall 27651369Sdduvall SEND_BD_SELECTOR_MODE_REG, 27661369Sdduvall SEND_BD_INITIATOR_MODE_REG, 27671369Sdduvall SEND_DATA_INITIATOR_MODE_REG, 27681369Sdduvall READ_DMA_MODE_REG, 27691369Sdduvall SEND_DATA_COMPLETION_MODE_REG, 27701369Sdduvall DMA_COMPLETION_MODE_REG, /* BCM5704 series only */ 27711369Sdduvall SEND_BD_COMPLETION_MODE_REG, 27721369Sdduvall TRANSMIT_MAC_MODE_REG, 27731369Sdduvall 27741369Sdduvall HOST_COALESCE_MODE_REG, 27751369Sdduvall WRITE_DMA_MODE_REG, 27761369Sdduvall MBUF_CLUSTER_FREE_MODE_REG, /* BCM5704 series only */ 27771369Sdduvall FTQ_RESET_REG, /* special - see code */ 27781369Sdduvall BUFFER_MANAGER_MODE_REG, /* BCM5704 series only */ 27791369Sdduvall MEMORY_ARBITER_MODE_REG, /* BCM5704 series only */ 27801369Sdduvall BGE_REGNO_NONE /* terminator */ 27811369Sdduvall }; 27821369Sdduvall 27831369Sdduvall /* 27841369Sdduvall * bge_chip_stop() -- stop all chip processing 27851369Sdduvall * 27861369Sdduvall * If the <fault> parameter is B_TRUE, we're stopping the chip because 27871369Sdduvall * we've detected a problem internally; otherwise, this is a normal 27881369Sdduvall * (clean) stop (at user request i.e. the last STREAM has been closed). 27891369Sdduvall */ 27901369Sdduvall void bge_chip_stop(bge_t *bgep, boolean_t fault); 27911369Sdduvall #pragma no_inline(bge_chip_stop) 27921369Sdduvall 27931369Sdduvall void 27941369Sdduvall bge_chip_stop(bge_t *bgep, boolean_t fault) 27951369Sdduvall { 27961369Sdduvall bge_regno_t regno; 27971369Sdduvall bge_regno_t *rbp; 27981369Sdduvall boolean_t ok; 27991369Sdduvall 28001369Sdduvall BGE_TRACE(("bge_chip_stop($%p)", 28011369Sdduvall (void *)bgep)); 28021369Sdduvall 28031369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 28041369Sdduvall 28051369Sdduvall rbp = shutdown_engine_regs; 28061369Sdduvall /* 28071369Sdduvall * When driver try to shutdown the BCM5705/5788/5721/5751/ 28081369Sdduvall * 5752/5714 and 5715 chipsets,the buffer manager and the mem 28091369Sdduvall * -ory arbiter should not be disabled. 28101369Sdduvall */ 28111369Sdduvall for (ok = B_TRUE; (regno = *rbp) != BGE_REGNO_NONE; ++rbp) { 28121369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) 28131369Sdduvall ok &= bge_chip_disable_engine(bgep, regno, 0); 28141369Sdduvall else if ((regno != RCV_LIST_SELECTOR_MODE_REG) && 28151369Sdduvall (regno != DMA_COMPLETION_MODE_REG) && 28161369Sdduvall (regno != MBUF_CLUSTER_FREE_MODE_REG)&& 28171369Sdduvall (regno != BUFFER_MANAGER_MODE_REG) && 28181369Sdduvall (regno != MEMORY_ARBITER_MODE_REG)) 28191369Sdduvall ok &= bge_chip_disable_engine(bgep, 28201369Sdduvall regno, 0); 28211369Sdduvall } 28221369Sdduvall 28231865Sdilpreet if (!ok && !fault) 28241865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_UNAFFECTED); 28251865Sdilpreet 28261369Sdduvall /* 28271369Sdduvall * Finally, disable (all) MAC events & clear the MAC status 28281369Sdduvall */ 28291369Sdduvall bge_reg_put32(bgep, ETHERNET_MAC_EVENT_ENABLE_REG, 0); 28301369Sdduvall bge_reg_put32(bgep, ETHERNET_MAC_STATUS_REG, ~0); 28311369Sdduvall 28321369Sdduvall /* 28331865Sdilpreet * if we're stopping the chip because of a detected fault then do 28341865Sdilpreet * appropriate actions 28351369Sdduvall */ 28361865Sdilpreet if (fault) { 28371865Sdilpreet if (bgep->bge_chip_state != BGE_CHIP_FAULT) { 28381865Sdilpreet bgep->bge_chip_state = BGE_CHIP_FAULT; 28391865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_LOST); 28401865Sdilpreet if (bgep->bge_dma_error) { 28411865Sdilpreet /* 28421865Sdilpreet * need to free buffers in case the fault was 28431865Sdilpreet * due to a memory error in a buffer - got to 28441865Sdilpreet * do a fair bit of tidying first 28451865Sdilpreet */ 28461865Sdilpreet if (bgep->progress & PROGRESS_KSTATS) { 28471865Sdilpreet bge_fini_kstats(bgep); 28481865Sdilpreet bgep->progress &= ~PROGRESS_KSTATS; 28491865Sdilpreet } 28501865Sdilpreet if (bgep->progress & PROGRESS_INTR) { 28511865Sdilpreet bge_intr_disable(bgep); 28521865Sdilpreet rw_enter(bgep->errlock, RW_WRITER); 28531865Sdilpreet bge_fini_rings(bgep); 28541865Sdilpreet rw_exit(bgep->errlock); 28551865Sdilpreet bgep->progress &= ~PROGRESS_INTR; 28561865Sdilpreet } 28571865Sdilpreet if (bgep->progress & PROGRESS_BUFS) { 28581865Sdilpreet bge_free_bufs(bgep); 28591865Sdilpreet bgep->progress &= ~PROGRESS_BUFS; 28601865Sdilpreet } 28611865Sdilpreet bgep->bge_dma_error = B_FALSE; 28621865Sdilpreet } 28631865Sdilpreet } 28641865Sdilpreet } else 28651369Sdduvall bgep->bge_chip_state = BGE_CHIP_STOPPED; 28661369Sdduvall } 28671369Sdduvall 28681369Sdduvall /* 28691369Sdduvall * Poll for completion of chip's ROM firmware; also, at least on the 28701369Sdduvall * first time through, find and return the hardware MAC address, if any. 28711369Sdduvall */ 28721369Sdduvall static uint64_t bge_poll_firmware(bge_t *bgep); 28731369Sdduvall #pragma no_inline(bge_poll_firmware) 28741369Sdduvall 28751369Sdduvall static uint64_t 28761369Sdduvall bge_poll_firmware(bge_t *bgep) 28771369Sdduvall { 28781369Sdduvall uint64_t magic; 28791369Sdduvall uint64_t mac; 28801369Sdduvall uint32_t gen; 28811369Sdduvall uint32_t i; 28821369Sdduvall 28831369Sdduvall /* 28841369Sdduvall * Step 19: poll for firmware completion (GENCOMM port set 28851369Sdduvall * to the ones complement of T3_MAGIC_NUMBER). 28861369Sdduvall * 28871369Sdduvall * While we're at it, we also read the MAC address register; 2888*2135Szh199473 * at some stage the firmware will load this with the 28891369Sdduvall * factory-set value. 28901369Sdduvall * 28911369Sdduvall * When both the magic number and the MAC address are set, 28921369Sdduvall * we're done; but we impose a time limit of one second 28931369Sdduvall * (1000*1000us) in case the firmware fails in some fashion 28941369Sdduvall * or the SEEPROM that provides that MAC address isn't fitted. 28951369Sdduvall * 28961369Sdduvall * After the first time through (chip state != INITIAL), we 28971369Sdduvall * don't need the MAC address to be set (we've already got it 28981369Sdduvall * or not, from the first time), so we don't wait for it, but 28991369Sdduvall * we still have to wait for the T3_MAGIC_NUMBER. 29001369Sdduvall * 29011369Sdduvall * Note: the magic number is only a 32-bit quantity, but the NIC 29021369Sdduvall * memory is 64-bit (and big-endian) internally. Addressing the 29031369Sdduvall * GENCOMM word as "the upper half of a 64-bit quantity" makes 29041369Sdduvall * it work correctly on both big- and little-endian hosts. 29051369Sdduvall */ 29061369Sdduvall for (i = 0; i < 1000; ++i) { 29071369Sdduvall drv_usecwait(1000); 29081369Sdduvall gen = bge_nic_get64(bgep, NIC_MEM_GENCOMM) >> 32; 29091369Sdduvall mac = bge_reg_get64(bgep, MAC_ADDRESS_REG(0)); 29101408Srandyf #ifdef BGE_IPMI_ASF 29111408Srandyf if (!bgep->asf_enabled) { 29121408Srandyf #endif 29131408Srandyf if (gen != ~T3_MAGIC_NUMBER) 29141408Srandyf continue; 29151408Srandyf #ifdef BGE_IPMI_ASF 29161408Srandyf } 29171408Srandyf #endif 29181369Sdduvall if (mac != 0ULL) 29191369Sdduvall break; 29201369Sdduvall if (bgep->bge_chip_state != BGE_CHIP_INITIAL) 29211369Sdduvall break; 29221369Sdduvall } 29231369Sdduvall 29241369Sdduvall magic = bge_nic_get64(bgep, NIC_MEM_GENCOMM); 29251369Sdduvall BGE_DEBUG(("bge_poll_firmware($%p): PXE magic 0x%x after %d loops", 29261369Sdduvall (void *)bgep, gen, i)); 29271369Sdduvall BGE_DEBUG(("bge_poll_firmware: MAC %016llx, GENCOMM %016llx", 29281369Sdduvall mac, magic)); 29291369Sdduvall 29301369Sdduvall return (mac); 29311369Sdduvall } 29321369Sdduvall 29331408Srandyf #ifdef BGE_IPMI_ASF 29341865Sdilpreet int bge_chip_reset(bge_t *bgep, boolean_t enable_dma, uint_t asf_mode); 29351408Srandyf #else 29361865Sdilpreet int bge_chip_reset(bge_t *bgep, boolean_t enable_dma); 29371408Srandyf #endif 29381369Sdduvall #pragma no_inline(bge_chip_reset) 29391369Sdduvall 29401865Sdilpreet int 29411408Srandyf #ifdef BGE_IPMI_ASF 29421408Srandyf bge_chip_reset(bge_t *bgep, boolean_t enable_dma, uint_t asf_mode) 29431408Srandyf #else 29441369Sdduvall bge_chip_reset(bge_t *bgep, boolean_t enable_dma) 29451408Srandyf #endif 29461369Sdduvall { 29471369Sdduvall chip_id_t chipid; 29481369Sdduvall uint64_t mac; 29491908Sly149593 uint64_t magic; 29501369Sdduvall uint32_t modeflags; 29511369Sdduvall uint32_t mhcr; 29521369Sdduvall uint32_t sx0; 29531369Sdduvall uint32_t i; 29541408Srandyf #ifdef BGE_IPMI_ASF 29551408Srandyf uint32_t mailbox; 29561408Srandyf #endif 29571865Sdilpreet int retval = DDI_SUCCESS; 29581369Sdduvall 29591369Sdduvall BGE_TRACE(("bge_chip_reset($%p, %d)", 29601369Sdduvall (void *)bgep, enable_dma)); 29611369Sdduvall 29621369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 29631369Sdduvall 29641369Sdduvall BGE_DEBUG(("bge_chip_reset($%p, %d): current state is %d", 29651369Sdduvall (void *)bgep, enable_dma, bgep->bge_chip_state)); 29661369Sdduvall 29671369Sdduvall /* 29681369Sdduvall * Do we need to stop the chip cleanly before resetting? 29691369Sdduvall */ 29701369Sdduvall switch (bgep->bge_chip_state) { 29711369Sdduvall default: 29721369Sdduvall _NOTE(NOTREACHED) 29731865Sdilpreet return (DDI_FAILURE); 29741369Sdduvall 29751369Sdduvall case BGE_CHIP_INITIAL: 29761369Sdduvall case BGE_CHIP_STOPPED: 29771369Sdduvall case BGE_CHIP_RESET: 29781369Sdduvall break; 29791369Sdduvall 29801369Sdduvall case BGE_CHIP_RUNNING: 29811369Sdduvall case BGE_CHIP_ERROR: 29821369Sdduvall case BGE_CHIP_FAULT: 29831369Sdduvall bge_chip_stop(bgep, B_FALSE); 29841369Sdduvall break; 29851369Sdduvall } 29861369Sdduvall 29871408Srandyf #ifdef BGE_IPMI_ASF 29881408Srandyf if (bgep->asf_enabled) { 29891408Srandyf if (asf_mode == ASF_MODE_INIT) { 29901408Srandyf bge_asf_pre_reset_operations(bgep, BGE_INIT_RESET); 29911408Srandyf } else if (asf_mode == ASF_MODE_SHUTDOWN) { 29921408Srandyf bge_asf_pre_reset_operations(bgep, BGE_SHUTDOWN_RESET); 29931408Srandyf } 29941408Srandyf } 29951408Srandyf #endif 29961369Sdduvall /* 29971369Sdduvall * Adapted from Broadcom document 570X-PG102-R, pp 102-116. 29981369Sdduvall * Updated to reflect Broadcom document 570X-PG104-R, pp 146-159. 29991369Sdduvall * 30001369Sdduvall * Before reset Core clock,it is 30011369Sdduvall * also required to initialize the Memory Arbiter as specified in step9 30021369Sdduvall * and Misc Host Control Register as specified in step-13 30031369Sdduvall * Step 4-5: reset Core clock & wait for completion 30041369Sdduvall * Steps 6-8: are done by bge_chip_cfg_init() 30051908Sly149593 * put the T3_MAGIC_NUMBER into the GENCOMM port before reset 30061369Sdduvall */ 30071865Sdilpreet if (!bge_chip_enable_engine(bgep, MEMORY_ARBITER_MODE_REG, 0)) 30081865Sdilpreet retval = DDI_FAILURE; 30091369Sdduvall 30101369Sdduvall mhcr = MHCR_ENABLE_INDIRECT_ACCESS | 30111369Sdduvall MHCR_ENABLE_TAGGED_STATUS_MODE | 30121369Sdduvall MHCR_MASK_INTERRUPT_MODE | 30131369Sdduvall MHCR_MASK_PCI_INT_OUTPUT | 30141369Sdduvall MHCR_CLEAR_INTERRUPT_INTA; 30151369Sdduvall #ifdef _BIG_ENDIAN 30161369Sdduvall mhcr |= MHCR_ENABLE_ENDIAN_WORD_SWAP | MHCR_ENABLE_ENDIAN_BYTE_SWAP; 30171369Sdduvall #endif /* _BIG_ENDIAN */ 30181369Sdduvall pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_MHCR, mhcr); 30191408Srandyf #ifdef BGE_IPMI_ASF 30201408Srandyf if (bgep->asf_enabled) 30211408Srandyf bgep->asf_wordswapped = B_FALSE; 30221408Srandyf #endif 30231908Sly149593 #ifdef BGE_IPMI_ASF 30241908Sly149593 if (!bgep->asf_enabled) { 30251908Sly149593 #endif 30261908Sly149593 magic = (uint64_t)T3_MAGIC_NUMBER << 32; 30271908Sly149593 bge_nic_put64(bgep, NIC_MEM_GENCOMM, magic); 30281908Sly149593 #ifdef BGE_IPMI_ASF 30291908Sly149593 } 30301908Sly149593 #endif 30311908Sly149593 30321865Sdilpreet if (!bge_chip_reset_engine(bgep, MISC_CONFIG_REG)) 30331865Sdilpreet retval = DDI_FAILURE; 30341369Sdduvall bge_chip_cfg_init(bgep, &chipid, enable_dma); 30351369Sdduvall 30361369Sdduvall /* 30371369Sdduvall * Step 8a: This may belong elsewhere, but BCM5721 needs 30381369Sdduvall * a bit set to avoid a fifo overflow/underflow bug. 30391369Sdduvall */ 3040*2135Szh199473 if ((bgep->chipid.chip_label == 5721) || 3041*2135Szh199473 (bgep->chipid.chip_label == 5751) || 3042*2135Szh199473 (bgep->chipid.chip_label == 5789)) 30431369Sdduvall bge_reg_set32(bgep, TLP_CONTROL_REG, TLP_DATA_FIFO_PROTECT); 30441369Sdduvall 30451369Sdduvall 30461369Sdduvall /* 30471369Sdduvall * Step 9: enable MAC memory arbiter,bit30 and bit31 of 5714/5715 should 30481369Sdduvall * not be changed. 30491369Sdduvall */ 30501865Sdilpreet if (!bge_chip_enable_engine(bgep, MEMORY_ARBITER_MODE_REG, 0)) 30511865Sdilpreet retval = DDI_FAILURE; 30521369Sdduvall 30531369Sdduvall /* 30541369Sdduvall * Steps 10-11: configure PIO endianness options and 30551369Sdduvall * enable indirect register access -- already done 30561369Sdduvall * Steps 12-13: enable writing to the PCI state & clock 30571369Sdduvall * control registers -- not required; we aren't going to 30581369Sdduvall * use those features. 30591369Sdduvall * Steps 14-15: Configure DMA endianness options. See 30601369Sdduvall * the comments on the setting of the MHCR above. 30611369Sdduvall */ 30621369Sdduvall #ifdef _BIG_ENDIAN 30631369Sdduvall modeflags = MODE_WORD_SWAP_FRAME | MODE_BYTE_SWAP_FRAME | 30641369Sdduvall MODE_WORD_SWAP_NONFRAME | MODE_BYTE_SWAP_NONFRAME; 30651369Sdduvall #else 30661369Sdduvall modeflags = MODE_WORD_SWAP_FRAME | MODE_BYTE_SWAP_FRAME; 30671369Sdduvall #endif /* _BIG_ENDIAN */ 30681408Srandyf #ifdef BGE_IPMI_ASF 30691408Srandyf if (bgep->asf_enabled) 30701408Srandyf modeflags |= MODE_HOST_STACK_UP; 30711408Srandyf #endif 30721369Sdduvall bge_reg_put32(bgep, MODE_CONTROL_REG, modeflags); 30731369Sdduvall 30741408Srandyf #ifdef BGE_IPMI_ASF 30751408Srandyf if (bgep->asf_enabled) { 30761408Srandyf if (asf_mode != ASF_MODE_NONE) { 30771408Srandyf /* Wait for NVRAM init */ 30781408Srandyf i = 0; 30791408Srandyf drv_usecwait(5000); 30801408Srandyf mailbox = bge_nic_get32(bgep, BGE_FIRMWARE_MAILBOX); 30811408Srandyf while ((mailbox != (uint32_t) 30821408Srandyf ~BGE_MAGIC_NUM_FIRMWARE_INIT_DONE) && 30831408Srandyf (i < 10000)) { 30841408Srandyf drv_usecwait(100); 30851408Srandyf mailbox = bge_nic_get32(bgep, 30861408Srandyf BGE_FIRMWARE_MAILBOX); 30871408Srandyf i++; 30881408Srandyf } 30891408Srandyf if (!bgep->asf_newhandshake) { 30901408Srandyf if ((asf_mode == ASF_MODE_INIT) || 30911408Srandyf (asf_mode == ASF_MODE_POST_INIT)) { 30921408Srandyf 30931408Srandyf bge_asf_post_reset_old_mode(bgep, 30941408Srandyf BGE_INIT_RESET); 30951408Srandyf } else { 30961408Srandyf bge_asf_post_reset_old_mode(bgep, 30971408Srandyf BGE_SHUTDOWN_RESET); 30981408Srandyf } 30991408Srandyf } 31001408Srandyf } 31011408Srandyf } 31021408Srandyf #endif 31031369Sdduvall /* 31041369Sdduvall * Steps 16-17: poll for firmware completion 31051369Sdduvall */ 31061369Sdduvall mac = bge_poll_firmware(bgep); 31071369Sdduvall 31081369Sdduvall /* 31091369Sdduvall * Step 18: enable external memory -- doesn't apply. 31101369Sdduvall * 31111369Sdduvall * However we take the opportunity to set the MLCR anyway, as 31121369Sdduvall * this register also controls the SEEPROM auto-access method 31131369Sdduvall * which we may want to use later ... 31141369Sdduvall * 31151369Sdduvall * The proper value here depends on the way the chip is wired 31161369Sdduvall * into the circuit board, as this register *also* controls which 31171369Sdduvall * of the "Miscellaneous I/O" pins are driven as outputs and the 31181369Sdduvall * values driven onto those pins! 31191369Sdduvall * 31201369Sdduvall * See also step 74 in the PRM ... 31211369Sdduvall */ 31221369Sdduvall bge_reg_put32(bgep, MISC_LOCAL_CONTROL_REG, 31231369Sdduvall bgep->chipid.bge_mlcr_default); 31241369Sdduvall bge_reg_set32(bgep, SERIAL_EEPROM_ADDRESS_REG, SEEPROM_ACCESS_INIT); 31251369Sdduvall 31261369Sdduvall /* 31271369Sdduvall * Step 20: clear the Ethernet MAC mode register 31281369Sdduvall */ 31291369Sdduvall bge_reg_put32(bgep, ETHERNET_MAC_MODE_REG, 0); 31301369Sdduvall 31311369Sdduvall /* 31321369Sdduvall * Step 21: restore cache-line-size, latency timer, and 31331369Sdduvall * subsystem ID registers to their original values (not 31341369Sdduvall * those read into the local structure <chipid>, 'cos 31351369Sdduvall * that was after they were cleared by the RESET). 31361369Sdduvall * 31371369Sdduvall * Note: the Subsystem Vendor/Device ID registers are not 31381369Sdduvall * directly writable in config space, so we use the shadow 31391369Sdduvall * copy in "Page Zero" of register space to restore them 31401369Sdduvall * both in one go ... 31411369Sdduvall */ 31421369Sdduvall pci_config_put8(bgep->cfg_handle, PCI_CONF_CACHE_LINESZ, 31431369Sdduvall bgep->chipid.clsize); 31441369Sdduvall pci_config_put8(bgep->cfg_handle, PCI_CONF_LATENCY_TIMER, 31451369Sdduvall bgep->chipid.latency); 31461369Sdduvall bge_reg_put32(bgep, PCI_CONF_SUBVENID, 31471369Sdduvall (bgep->chipid.subdev << 16) | bgep->chipid.subven); 31481369Sdduvall 31491369Sdduvall /* 31501369Sdduvall * The SEND INDEX registers should be reset to zero by the 31511369Sdduvall * global chip reset; if they're not, there'll be trouble 31521865Sdilpreet * later on. 31531369Sdduvall */ 31541369Sdduvall sx0 = bge_reg_get32(bgep, NIC_DIAG_SEND_INDEX_REG(0)); 31551865Sdilpreet if (sx0 != 0) { 31561865Sdilpreet BGE_REPORT((bgep, "SEND INDEX - device didn't RESET")); 31571865Sdilpreet bge_fm_ereport(bgep, DDI_FM_DEVICE_INVAL_STATE); 31581865Sdilpreet return (DDI_FAILURE); 31591865Sdilpreet } 31601369Sdduvall 31611369Sdduvall /* Enable MSI code */ 31621369Sdduvall if (bgep->intr_type == DDI_INTR_TYPE_MSI) 31631369Sdduvall bge_reg_set32(bgep, MSI_MODE_REG, 31641369Sdduvall MSI_PRI_HIGHEST|MSI_MSI_ENABLE); 31651369Sdduvall 31661369Sdduvall /* 31671369Sdduvall * On the first time through, save the factory-set MAC address 31681369Sdduvall * (if any). If bge_poll_firmware() above didn't return one 31691369Sdduvall * (from a chip register) consider looking in the attached NV 31701369Sdduvall * memory device, if any. Once we have it, we save it in both 31711369Sdduvall * register-image (64-bit) and byte-array forms. All-zero and 31721369Sdduvall * all-one addresses are not valid, and we refuse to stash those. 31731369Sdduvall */ 31741369Sdduvall if (bgep->bge_chip_state == BGE_CHIP_INITIAL) { 31751369Sdduvall if (mac == 0ULL) 31761369Sdduvall mac = bge_get_nvmac(bgep); 31771369Sdduvall if (mac != 0ULL && mac != ~0ULL) { 31781369Sdduvall bgep->chipid.hw_mac_addr = mac; 31791369Sdduvall for (i = ETHERADDRL; i-- != 0; ) { 31801369Sdduvall bgep->chipid.vendor_addr.addr[i] = (uchar_t)mac; 31811369Sdduvall mac >>= 8; 31821369Sdduvall } 31831369Sdduvall bgep->chipid.vendor_addr.set = 1; 31841369Sdduvall } 31851369Sdduvall } 31861369Sdduvall 31871408Srandyf #ifdef BGE_IPMI_ASF 31881408Srandyf if (bgep->asf_enabled && bgep->asf_newhandshake) { 31891408Srandyf if (asf_mode != ASF_MODE_NONE) { 31901408Srandyf if ((asf_mode == ASF_MODE_INIT) || 31911408Srandyf (asf_mode == ASF_MODE_POST_INIT)) { 31921408Srandyf 31931408Srandyf bge_asf_post_reset_new_mode(bgep, 31941408Srandyf BGE_INIT_RESET); 31951408Srandyf } else { 31961408Srandyf bge_asf_post_reset_new_mode(bgep, 31971408Srandyf BGE_SHUTDOWN_RESET); 31981408Srandyf } 31991408Srandyf } 32001408Srandyf } 32011408Srandyf #endif 32021408Srandyf 32031369Sdduvall /* 32041369Sdduvall * Record the new state 32051369Sdduvall */ 32061369Sdduvall bgep->chip_resets += 1; 32071369Sdduvall bgep->bge_chip_state = BGE_CHIP_RESET; 32081865Sdilpreet return (retval); 32091369Sdduvall } 32101369Sdduvall 32111369Sdduvall /* 32121369Sdduvall * bge_chip_start() -- start the chip transmitting and/or receiving, 32131369Sdduvall * including enabling interrupts 32141369Sdduvall */ 32151865Sdilpreet int bge_chip_start(bge_t *bgep, boolean_t reset_phys); 32161369Sdduvall #pragma no_inline(bge_chip_start) 32171369Sdduvall 32181865Sdilpreet int 32191369Sdduvall bge_chip_start(bge_t *bgep, boolean_t reset_phys) 32201369Sdduvall { 32211369Sdduvall uint32_t coalmode; 32221369Sdduvall uint32_t ledctl; 32231369Sdduvall uint32_t mtu; 32241369Sdduvall uint32_t maxring; 32251369Sdduvall uint64_t ring; 32261865Sdilpreet int retval = DDI_SUCCESS; 32271369Sdduvall 32281369Sdduvall BGE_TRACE(("bge_chip_start($%p)", 32291369Sdduvall (void *)bgep)); 32301369Sdduvall 32311369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 32321369Sdduvall ASSERT(bgep->bge_chip_state == BGE_CHIP_RESET); 32331369Sdduvall 32341369Sdduvall /* 32351369Sdduvall * Taken from Broadcom document 570X-PG102-R, pp 102-116. 32361369Sdduvall * The document specifies 95 separate steps to fully 32371369Sdduvall * initialise the chip!!!! 32381369Sdduvall * 32391369Sdduvall * The reset code above has already got us as far as step 32401369Sdduvall * 21, so we continue with ... 32411369Sdduvall * 32421369Sdduvall * Step 22: clear the MAC statistics block 32431369Sdduvall * (0x0300-0x0aff in NIC-local memory) 32441369Sdduvall */ 32451369Sdduvall if (bgep->chipid.statistic_type == BGE_STAT_BLK) 32461369Sdduvall bge_nic_zero(bgep, NIC_MEM_STATISTICS, 32471369Sdduvall NIC_MEM_STATISTICS_SIZE); 32481369Sdduvall 32491369Sdduvall /* 32501369Sdduvall * Step 23: clear the status block (in host memory) 32511369Sdduvall */ 32521369Sdduvall DMA_ZERO(bgep->status_block); 32531369Sdduvall 32541369Sdduvall /* 32551369Sdduvall * Step 24: set DMA read/write control register 32561369Sdduvall */ 32571369Sdduvall pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_PDRWCR, 32581369Sdduvall bgep->chipid.bge_dma_rwctrl); 32591369Sdduvall 32601369Sdduvall /* 32611369Sdduvall * Step 25: Configure DMA endianness -- already done (16/17) 32621369Sdduvall * Step 26: Configure Host-Based Send Rings 32631369Sdduvall * Step 27: Indicate Host Stack Up 32641369Sdduvall */ 32651369Sdduvall bge_reg_set32(bgep, MODE_CONTROL_REG, 32661369Sdduvall MODE_HOST_SEND_BDS | 32671369Sdduvall MODE_HOST_STACK_UP); 32681369Sdduvall 32691369Sdduvall /* 32701369Sdduvall * Step 28: Configure checksum options: 32711611Szh199473 * Solaris supports the hardware default checksum options. 32721611Szh199473 * 32731611Szh199473 * Workaround for Incorrect pseudo-header checksum calculation. 32741369Sdduvall */ 3275*2135Szh199473 if (bgep->chipid.flags & CHIP_FLAG_PARTIAL_CSUM) 32761611Szh199473 bge_reg_set32(bgep, MODE_CONTROL_REG, 32771611Szh199473 MODE_SEND_NO_PSEUDO_HDR_CSUM); 32781369Sdduvall 32791369Sdduvall /* 32801369Sdduvall * Step 29: configure Timer Prescaler. The value is always the 32811369Sdduvall * same: the Core Clock frequency in MHz (66), minus 1, shifted 32821369Sdduvall * into bits 7-1. Don't set bit 0, 'cos that's the RESET bit 32831369Sdduvall * for the whole chip! 32841369Sdduvall */ 32851369Sdduvall bge_reg_put32(bgep, MISC_CONFIG_REG, MISC_CONFIG_DEFAULT); 32861369Sdduvall 32871369Sdduvall /* 32881369Sdduvall * Steps 30-31: Configure MAC local memory pool & DMA pool registers 32891369Sdduvall * 32901369Sdduvall * If the mbuf_length is specified as 0, we just leave these at 32911369Sdduvall * their hardware defaults, rather than explicitly setting them. 32921369Sdduvall * As the Broadcom HRM,driver better not change the parameters 32931369Sdduvall * when the chipsets is 5705/5788/5721/5751/5714 and 5715. 32941369Sdduvall */ 32951369Sdduvall if ((bgep->chipid.mbuf_length != 0) && 32961369Sdduvall (DEVICE_5704_SERIES_CHIPSETS(bgep))) { 32971369Sdduvall bge_reg_put32(bgep, MBUF_POOL_BASE_REG, 32981369Sdduvall bgep->chipid.mbuf_base); 32991369Sdduvall bge_reg_put32(bgep, MBUF_POOL_LENGTH_REG, 33001369Sdduvall bgep->chipid.mbuf_length); 33011369Sdduvall bge_reg_put32(bgep, DMAD_POOL_BASE_REG, 33021369Sdduvall DMAD_POOL_BASE_DEFAULT); 33031369Sdduvall bge_reg_put32(bgep, DMAD_POOL_LENGTH_REG, 33041369Sdduvall DMAD_POOL_LENGTH_DEFAULT); 33051369Sdduvall } 33061369Sdduvall 33071369Sdduvall /* 33081369Sdduvall * Step 32: configure MAC memory pool watermarks 33091369Sdduvall */ 33101369Sdduvall bge_reg_put32(bgep, RDMA_MBUF_LOWAT_REG, 33111369Sdduvall bgep->chipid.mbuf_lo_water_rdma); 33121369Sdduvall bge_reg_put32(bgep, MAC_RX_MBUF_LOWAT_REG, 33131369Sdduvall bgep->chipid.mbuf_lo_water_rmac); 33141369Sdduvall bge_reg_put32(bgep, MBUF_HIWAT_REG, 33151369Sdduvall bgep->chipid.mbuf_hi_water); 33161369Sdduvall 33171369Sdduvall /* 33181369Sdduvall * Step 33: configure DMA resource watermarks 33191369Sdduvall */ 33201369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) { 33211369Sdduvall bge_reg_put32(bgep, DMAD_POOL_LOWAT_REG, 33221369Sdduvall bge_dmad_lo_water); 33231369Sdduvall bge_reg_put32(bgep, DMAD_POOL_HIWAT_REG, 33241369Sdduvall bge_dmad_hi_water); 33251369Sdduvall } 33261369Sdduvall bge_reg_put32(bgep, LOWAT_MAX_RECV_FRAMES_REG, bge_lowat_recv_frames); 33271369Sdduvall 33281369Sdduvall /* 33291369Sdduvall * Steps 34-36: enable buffer manager & internal h/w queues 33301369Sdduvall */ 33311865Sdilpreet if (!bge_chip_enable_engine(bgep, BUFFER_MANAGER_MODE_REG, 33321865Sdilpreet STATE_MACHINE_ATTN_ENABLE_BIT)) 33331865Sdilpreet retval = DDI_FAILURE; 33341865Sdilpreet if (!bge_chip_enable_engine(bgep, FTQ_RESET_REG, 0)) 33351865Sdilpreet retval = DDI_FAILURE; 33361369Sdduvall 33371369Sdduvall /* 33381369Sdduvall * Steps 37-39: initialise Receive Buffer (Producer) RCBs 33391369Sdduvall */ 33401369Sdduvall bge_reg_putrcb(bgep, STD_RCV_BD_RING_RCB_REG, 33411369Sdduvall &bgep->buff[BGE_STD_BUFF_RING].hw_rcb); 33421369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) { 33431369Sdduvall bge_reg_putrcb(bgep, JUMBO_RCV_BD_RING_RCB_REG, 33441369Sdduvall &bgep->buff[BGE_JUMBO_BUFF_RING].hw_rcb); 33451369Sdduvall bge_reg_putrcb(bgep, MINI_RCV_BD_RING_RCB_REG, 33461369Sdduvall &bgep->buff[BGE_MINI_BUFF_RING].hw_rcb); 33471369Sdduvall } 33481369Sdduvall 33491369Sdduvall /* 33501369Sdduvall * Step 40: set Receive Buffer Descriptor Ring replenish thresholds 33511369Sdduvall */ 33521369Sdduvall bge_reg_put32(bgep, STD_RCV_BD_REPLENISH_REG, bge_replenish_std); 33531369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) { 33541369Sdduvall bge_reg_put32(bgep, JUMBO_RCV_BD_REPLENISH_REG, 33551369Sdduvall bge_replenish_jumbo); 33561369Sdduvall bge_reg_put32(bgep, MINI_RCV_BD_REPLENISH_REG, 33571369Sdduvall bge_replenish_mini); 33581369Sdduvall } 33591369Sdduvall 33601369Sdduvall /* 33611369Sdduvall * Steps 41-43: clear Send Ring Producer Indices and initialise 33621369Sdduvall * Send Producer Rings (0x0100-0x01ff in NIC-local memory) 33631369Sdduvall */ 33641369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) 33651369Sdduvall maxring = BGE_SEND_RINGS_MAX; 33661369Sdduvall else 33671369Sdduvall maxring = BGE_SEND_RINGS_MAX_5705; 33681369Sdduvall for (ring = 0; ring < maxring; ++ring) { 33691369Sdduvall bge_mbx_put(bgep, SEND_RING_HOST_INDEX_REG(ring), 0); 33701369Sdduvall bge_mbx_put(bgep, SEND_RING_NIC_INDEX_REG(ring), 0); 33711369Sdduvall bge_nic_putrcb(bgep, NIC_MEM_SEND_RING(ring), 33721369Sdduvall &bgep->send[ring].hw_rcb); 33731369Sdduvall } 33741369Sdduvall 33751369Sdduvall /* 33761369Sdduvall * Steps 44-45: initialise Receive Return Rings 33771369Sdduvall * (0x0200-0x02ff in NIC-local memory) 33781369Sdduvall */ 33791369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) 33801369Sdduvall maxring = BGE_RECV_RINGS_MAX; 33811369Sdduvall else 33821369Sdduvall maxring = BGE_RECV_RINGS_MAX_5705; 33831369Sdduvall for (ring = 0; ring < maxring; ++ring) 33841369Sdduvall bge_nic_putrcb(bgep, NIC_MEM_RECV_RING(ring), 33851369Sdduvall &bgep->recv[ring].hw_rcb); 33861369Sdduvall 33871369Sdduvall /* 33881369Sdduvall * Step 46: initialise Receive Buffer (Producer) Ring indexes 33891369Sdduvall */ 33901369Sdduvall bge_mbx_put(bgep, RECV_STD_PROD_INDEX_REG, 0); 33911369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) { 33921369Sdduvall bge_mbx_put(bgep, RECV_JUMBO_PROD_INDEX_REG, 0); 33931369Sdduvall bge_mbx_put(bgep, RECV_MINI_PROD_INDEX_REG, 0); 33941369Sdduvall } 33951369Sdduvall /* 33961369Sdduvall * Step 47: configure the MAC unicast address 33971369Sdduvall * Step 48: configure the random backoff seed 33981369Sdduvall * Step 96: set up multicast filters 33991369Sdduvall */ 34001408Srandyf #ifdef BGE_IPMI_ASF 34011865Sdilpreet if (bge_chip_sync(bgep, B_FALSE) == DDI_FAILURE) 34021408Srandyf #else 34031865Sdilpreet if (bge_chip_sync(bgep) == DDI_FAILURE) 34041408Srandyf #endif 34051865Sdilpreet retval = DDI_FAILURE; 34061369Sdduvall 34071369Sdduvall /* 34081369Sdduvall * Step 49: configure the MTU 34091369Sdduvall */ 34101369Sdduvall mtu = bgep->chipid.ethmax_size+ETHERFCSL+VLAN_TAGSZ; 34111369Sdduvall bge_reg_put32(bgep, MAC_RX_MTU_SIZE_REG, mtu); 34121369Sdduvall 34131369Sdduvall /* 34141369Sdduvall * Step 50: configure the IPG et al 34151369Sdduvall */ 34161369Sdduvall bge_reg_put32(bgep, MAC_TX_LENGTHS_REG, MAC_TX_LENGTHS_DEFAULT); 34171369Sdduvall 34181369Sdduvall /* 34191369Sdduvall * Step 51: configure the default Rx Return Ring 34201369Sdduvall */ 34211369Sdduvall bge_reg_put32(bgep, RCV_RULES_CONFIG_REG, RCV_RULES_CONFIG_DEFAULT); 34221369Sdduvall 34231369Sdduvall /* 34241369Sdduvall * Steps 52-54: configure Receive List Placement, 34251369Sdduvall * and enable Receive List Placement Statistics 34261369Sdduvall */ 34271369Sdduvall bge_reg_put32(bgep, RCV_LP_CONFIG_REG, 34281369Sdduvall RCV_LP_CONFIG(bgep->chipid.rx_rings)); 34291369Sdduvall bge_reg_put32(bgep, RCV_LP_STATS_ENABLE_MASK_REG, ~0); 34301369Sdduvall bge_reg_set32(bgep, RCV_LP_STATS_CONTROL_REG, RCV_LP_STATS_ENABLE); 34311369Sdduvall 34321369Sdduvall if (bgep->chipid.rx_rings > 1) 34331369Sdduvall bge_init_recv_rule(bgep); 34341369Sdduvall 34351369Sdduvall /* 34361369Sdduvall * Steps 55-56: enable Send Data Initiator Statistics 34371369Sdduvall */ 34381369Sdduvall bge_reg_put32(bgep, SEND_INIT_STATS_ENABLE_MASK_REG, ~0); 34391369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) { 34401369Sdduvall bge_reg_put32(bgep, SEND_INIT_STATS_CONTROL_REG, 34411369Sdduvall SEND_INIT_STATS_ENABLE | SEND_INIT_STATS_FASTER); 34421369Sdduvall } else { 34431369Sdduvall bge_reg_put32(bgep, SEND_INIT_STATS_CONTROL_REG, 34441369Sdduvall SEND_INIT_STATS_ENABLE); 34451369Sdduvall } 34461369Sdduvall /* 34471369Sdduvall * Steps 57-58: stop (?) the Host Coalescing Engine 34481369Sdduvall */ 34491865Sdilpreet if (!bge_chip_disable_engine(bgep, HOST_COALESCE_MODE_REG, ~0)) 34501865Sdilpreet retval = DDI_FAILURE; 34511369Sdduvall 34521369Sdduvall /* 34531369Sdduvall * Steps 59-62: initialise Host Coalescing parameters 34541369Sdduvall */ 34551369Sdduvall bge_reg_put32(bgep, SEND_COALESCE_MAX_BD_REG, bge_tx_count_norm); 34561369Sdduvall bge_reg_put32(bgep, SEND_COALESCE_TICKS_REG, bge_tx_ticks_norm); 34571369Sdduvall bge_reg_put32(bgep, RCV_COALESCE_MAX_BD_REG, bge_rx_count_norm); 34581369Sdduvall bge_reg_put32(bgep, RCV_COALESCE_TICKS_REG, bge_rx_ticks_norm); 34591369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) { 34601369Sdduvall bge_reg_put32(bgep, SEND_COALESCE_INT_BD_REG, 34611369Sdduvall bge_tx_count_intr); 34621369Sdduvall bge_reg_put32(bgep, SEND_COALESCE_INT_TICKS_REG, 34631369Sdduvall bge_tx_ticks_intr); 34641369Sdduvall bge_reg_put32(bgep, RCV_COALESCE_INT_BD_REG, 34651369Sdduvall bge_rx_count_intr); 34661369Sdduvall bge_reg_put32(bgep, RCV_COALESCE_INT_TICKS_REG, 34671369Sdduvall bge_rx_ticks_intr); 34681369Sdduvall } 34691369Sdduvall 34701369Sdduvall /* 34711369Sdduvall * Steps 63-64: initialise status block & statistics 34721369Sdduvall * host memory addresses 34731369Sdduvall * The statistic block does not exist in some chipsets 34741369Sdduvall * Step 65: initialise Statistics Coalescing Tick Counter 34751369Sdduvall */ 34761369Sdduvall bge_reg_put64(bgep, STATUS_BLOCK_HOST_ADDR_REG, 34771369Sdduvall bgep->status_block.cookie.dmac_laddress); 34781369Sdduvall 34791369Sdduvall /* 34801369Sdduvall * Steps 66-67: initialise status block & statistics 34811369Sdduvall * NIC-local memory addresses 34821369Sdduvall */ 34831369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) { 34841369Sdduvall bge_reg_put64(bgep, STATISTICS_HOST_ADDR_REG, 34851369Sdduvall bgep->statistics.cookie.dmac_laddress); 34861369Sdduvall bge_reg_put32(bgep, STATISTICS_TICKS_REG, 34871369Sdduvall STATISTICS_TICKS_DEFAULT); 34881369Sdduvall bge_reg_put32(bgep, STATUS_BLOCK_BASE_ADDR_REG, 34891369Sdduvall NIC_MEM_STATUS_BLOCK); 34901369Sdduvall bge_reg_put32(bgep, STATISTICS_BASE_ADDR_REG, 34911369Sdduvall NIC_MEM_STATISTICS); 34921369Sdduvall } 34931369Sdduvall 34941369Sdduvall /* 34951369Sdduvall * Steps 68-71: start the Host Coalescing Engine, the Receive BD 34961369Sdduvall * Completion Engine, the Receive List Placement Engine, and the 34971369Sdduvall * Receive List selector.Pay attention:0x3400 is not exist in BCM5714 34981369Sdduvall * and BCM5715. 34991369Sdduvall */ 35001369Sdduvall if (bgep->chipid.tx_rings <= COALESCE_64_BYTE_RINGS && 35011369Sdduvall bgep->chipid.rx_rings <= COALESCE_64_BYTE_RINGS) 35021369Sdduvall coalmode = COALESCE_64_BYTE_STATUS; 35031369Sdduvall else 35041369Sdduvall coalmode = 0; 35051865Sdilpreet if (!bge_chip_enable_engine(bgep, HOST_COALESCE_MODE_REG, coalmode)) 35061865Sdilpreet retval = DDI_FAILURE; 35071865Sdilpreet if (!bge_chip_enable_engine(bgep, RCV_BD_COMPLETION_MODE_REG, 35081865Sdilpreet STATE_MACHINE_ATTN_ENABLE_BIT)) 35091865Sdilpreet retval = DDI_FAILURE; 35101865Sdilpreet if (!bge_chip_enable_engine(bgep, RCV_LIST_PLACEMENT_MODE_REG, 0)) 35111865Sdilpreet retval = DDI_FAILURE; 35121369Sdduvall 35131369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) 35141865Sdilpreet if (!bge_chip_enable_engine(bgep, RCV_LIST_SELECTOR_MODE_REG, 35151865Sdilpreet STATE_MACHINE_ATTN_ENABLE_BIT)) 35161865Sdilpreet retval = DDI_FAILURE; 35171369Sdduvall 35181369Sdduvall /* 35191369Sdduvall * Step 72: Enable MAC DMA engines 35201369Sdduvall * Step 73: Clear & enable MAC statistics 35211369Sdduvall */ 35221369Sdduvall bge_reg_set32(bgep, ETHERNET_MAC_MODE_REG, 35231369Sdduvall ETHERNET_MODE_ENABLE_FHDE | 35241369Sdduvall ETHERNET_MODE_ENABLE_RDE | 35251369Sdduvall ETHERNET_MODE_ENABLE_TDE); 35261369Sdduvall bge_reg_set32(bgep, ETHERNET_MAC_MODE_REG, 35271369Sdduvall ETHERNET_MODE_ENABLE_TX_STATS | 35281369Sdduvall ETHERNET_MODE_ENABLE_RX_STATS | 35291369Sdduvall ETHERNET_MODE_CLEAR_TX_STATS | 35301369Sdduvall ETHERNET_MODE_CLEAR_RX_STATS); 35311369Sdduvall 35321369Sdduvall /* 35331369Sdduvall * Step 74: configure the MLCR (Miscellaneous Local Control 35341369Sdduvall * Register); not required, as we set up the MLCR in step 10 35351369Sdduvall * (part of the reset code) above. 35361369Sdduvall * 35371369Sdduvall * Step 75: clear Interrupt Mailbox 0 35381369Sdduvall */ 35391369Sdduvall bge_mbx_put(bgep, INTERRUPT_MBOX_0_REG, 0); 35401369Sdduvall 35411369Sdduvall /* 35421369Sdduvall * Steps 76-87: Gentlemen, start your engines ... 35431369Sdduvall * 35441369Sdduvall * Enable the DMA Completion Engine, the Write DMA Engine, 35451369Sdduvall * the Read DMA Engine, Receive Data Completion Engine, 35461369Sdduvall * the MBuf Cluster Free Engine, the Send Data Completion Engine, 35471369Sdduvall * the Send BD Completion Engine, the Receive BD Initiator Engine, 35481369Sdduvall * the Receive Data Initiator Engine, the Send Data Initiator Engine, 35491369Sdduvall * the Send BD Initiator Engine, and the Send BD Selector Engine. 35501369Sdduvall * 35511369Sdduvall * Beware exhaust fumes? 35521369Sdduvall */ 35531369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) 35541865Sdilpreet if (!bge_chip_enable_engine(bgep, DMA_COMPLETION_MODE_REG, 0)) 35551865Sdilpreet retval = DDI_FAILURE; 35561865Sdilpreet if (!bge_chip_enable_engine(bgep, WRITE_DMA_MODE_REG, 35571865Sdilpreet (bge_dma_wrprio << DMA_PRIORITY_SHIFT) | ALL_DMA_ATTN_BITS)) 35581865Sdilpreet retval = DDI_FAILURE; 35591865Sdilpreet if (!bge_chip_enable_engine(bgep, READ_DMA_MODE_REG, 35601865Sdilpreet (bge_dma_rdprio << DMA_PRIORITY_SHIFT) | ALL_DMA_ATTN_BITS)) 35611865Sdilpreet retval = DDI_FAILURE; 35621865Sdilpreet if (!bge_chip_enable_engine(bgep, RCV_DATA_COMPLETION_MODE_REG, 35631865Sdilpreet STATE_MACHINE_ATTN_ENABLE_BIT)) 35641865Sdilpreet retval = DDI_FAILURE; 35651369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) 35661865Sdilpreet if (!bge_chip_enable_engine(bgep, 35671865Sdilpreet MBUF_CLUSTER_FREE_MODE_REG, 0)) 35681865Sdilpreet retval = DDI_FAILURE; 35691865Sdilpreet if (!bge_chip_enable_engine(bgep, SEND_DATA_COMPLETION_MODE_REG, 0)) 35701865Sdilpreet retval = DDI_FAILURE; 35711865Sdilpreet if (!bge_chip_enable_engine(bgep, SEND_BD_COMPLETION_MODE_REG, 35721865Sdilpreet STATE_MACHINE_ATTN_ENABLE_BIT)) 35731865Sdilpreet retval = DDI_FAILURE; 35741865Sdilpreet if (!bge_chip_enable_engine(bgep, RCV_BD_INITIATOR_MODE_REG, 35751865Sdilpreet RCV_BD_DISABLED_RING_ATTN)) 35761865Sdilpreet retval = DDI_FAILURE; 35771865Sdilpreet if (!bge_chip_enable_engine(bgep, RCV_DATA_BD_INITIATOR_MODE_REG, 35781865Sdilpreet RCV_DATA_BD_ILL_RING_ATTN)) 35791865Sdilpreet retval = DDI_FAILURE; 35801865Sdilpreet if (!bge_chip_enable_engine(bgep, SEND_DATA_INITIATOR_MODE_REG, 0)) 35811865Sdilpreet retval = DDI_FAILURE; 35821865Sdilpreet if (!bge_chip_enable_engine(bgep, SEND_BD_INITIATOR_MODE_REG, 35831865Sdilpreet STATE_MACHINE_ATTN_ENABLE_BIT)) 35841865Sdilpreet retval = DDI_FAILURE; 35851865Sdilpreet if (!bge_chip_enable_engine(bgep, SEND_BD_SELECTOR_MODE_REG, 35861865Sdilpreet STATE_MACHINE_ATTN_ENABLE_BIT)) 35871865Sdilpreet retval = DDI_FAILURE; 35881369Sdduvall 35891369Sdduvall /* 35901369Sdduvall * Step 88: download firmware -- doesn't apply 35911369Sdduvall * Steps 89-90: enable Transmit & Receive MAC Engines 35921369Sdduvall */ 35931865Sdilpreet if (!bge_chip_enable_engine(bgep, TRANSMIT_MAC_MODE_REG, 0)) 35941865Sdilpreet retval = DDI_FAILURE; 35951408Srandyf #ifdef BGE_IPMI_ASF 35961865Sdilpreet if (!bgep->asf_enabled) { 35971865Sdilpreet if (!bge_chip_enable_engine(bgep, RECEIVE_MAC_MODE_REG, 35981865Sdilpreet RECEIVE_MODE_KEEP_VLAN_TAG)) 35991865Sdilpreet retval = DDI_FAILURE; 36001408Srandyf } else { 36011865Sdilpreet if (!bge_chip_enable_engine(bgep, RECEIVE_MAC_MODE_REG, 0)) 36021865Sdilpreet retval = DDI_FAILURE; 36031408Srandyf } 36041408Srandyf #else 36051865Sdilpreet if (!bge_chip_enable_engine(bgep, RECEIVE_MAC_MODE_REG, 36061865Sdilpreet RECEIVE_MODE_KEEP_VLAN_TAG)) 36071865Sdilpreet retval = DDI_FAILURE; 36081408Srandyf #endif 36091369Sdduvall 36101369Sdduvall /* 36111369Sdduvall * Step 91: disable auto-polling of PHY status 36121369Sdduvall */ 36131369Sdduvall bge_reg_put32(bgep, MI_MODE_REG, MI_MODE_DEFAULT); 36141369Sdduvall 36151369Sdduvall /* 36161369Sdduvall * Step 92: configure D0 power state (not required) 36171369Sdduvall * Step 93: initialise LED control register () 36181369Sdduvall */ 36191369Sdduvall ledctl = LED_CONTROL_DEFAULT; 36201369Sdduvall switch (bgep->chipid.device) { 36211369Sdduvall case DEVICE_ID_5700: 36221369Sdduvall case DEVICE_ID_5700x: 36231369Sdduvall case DEVICE_ID_5701: 36241369Sdduvall /* 36251369Sdduvall * Switch to 5700 (MAC) mode on these older chips 36261369Sdduvall */ 36271369Sdduvall ledctl &= ~LED_CONTROL_LED_MODE_MASK; 36281369Sdduvall ledctl |= LED_CONTROL_LED_MODE_5700; 36291369Sdduvall break; 36301369Sdduvall 36311369Sdduvall default: 36321369Sdduvall break; 36331369Sdduvall } 36341369Sdduvall bge_reg_put32(bgep, ETHERNET_MAC_LED_CONTROL_REG, ledctl); 36351369Sdduvall 36361369Sdduvall /* 36371369Sdduvall * Step 94: activate link 36381369Sdduvall */ 36391369Sdduvall bge_reg_put32(bgep, MI_STATUS_REG, MI_STATUS_LINK); 36401369Sdduvall 36411369Sdduvall /* 36421369Sdduvall * Step 95: set up physical layer (PHY/SerDes) 36431369Sdduvall * restart autoneg (if required) 36441369Sdduvall */ 36451369Sdduvall if (reset_phys) 36461865Sdilpreet if (bge_phys_update(bgep) == DDI_FAILURE) 36471865Sdilpreet retval = DDI_FAILURE; 36481369Sdduvall 36491369Sdduvall /* 36501369Sdduvall * Extra step (DSG): hand over all the Receive Buffers to the chip 36511369Sdduvall */ 36521369Sdduvall for (ring = 0; ring < BGE_BUFF_RINGS_USED; ++ring) 36531369Sdduvall bge_mbx_put(bgep, bgep->buff[ring].chip_mbx_reg, 36541369Sdduvall bgep->buff[ring].rf_next); 36551369Sdduvall 36561369Sdduvall /* 36571369Sdduvall * MSI bits:The least significant MSI 16-bit word. 36581369Sdduvall * ISR will be triggered different. 36591369Sdduvall */ 36601369Sdduvall if (bgep->intr_type == DDI_INTR_TYPE_MSI) 36611369Sdduvall bge_reg_set32(bgep, HOST_COALESCE_MODE_REG, 0x70); 36621369Sdduvall 36631369Sdduvall /* 36641369Sdduvall * Extra step (DSG): select which interrupts are enabled 36651369Sdduvall * 36661369Sdduvall * Program the Ethernet MAC engine to signal attention on 36671369Sdduvall * Link Change events, then enable interrupts on MAC, DMA, 36681369Sdduvall * and FLOW attention signals. 36691369Sdduvall */ 36701369Sdduvall bge_reg_set32(bgep, ETHERNET_MAC_EVENT_ENABLE_REG, 36711369Sdduvall ETHERNET_EVENT_LINK_INT | 36721369Sdduvall ETHERNET_STATUS_PCS_ERROR_INT); 36731408Srandyf #ifdef BGE_IPMI_ASF 36741408Srandyf if (bgep->asf_enabled) { 36751408Srandyf bge_reg_set32(bgep, MODE_CONTROL_REG, 36761408Srandyf MODE_INT_ON_FLOW_ATTN | 36771408Srandyf MODE_INT_ON_DMA_ATTN | 36781408Srandyf MODE_HOST_STACK_UP| 36791408Srandyf MODE_INT_ON_MAC_ATTN); 36801408Srandyf } else { 36811408Srandyf #endif 36821408Srandyf bge_reg_set32(bgep, MODE_CONTROL_REG, 36831408Srandyf MODE_INT_ON_FLOW_ATTN | 36841408Srandyf MODE_INT_ON_DMA_ATTN | 36851408Srandyf MODE_INT_ON_MAC_ATTN); 36861408Srandyf #ifdef BGE_IPMI_ASF 36871408Srandyf } 36881408Srandyf #endif 36891369Sdduvall 36901369Sdduvall /* 36911369Sdduvall * Step 97: enable PCI interrupts!!! 36921369Sdduvall */ 36931369Sdduvall if (bgep->intr_type == DDI_INTR_TYPE_FIXED) 36941369Sdduvall bge_cfg_clr32(bgep, PCI_CONF_BGE_MHCR, 36951369Sdduvall MHCR_MASK_PCI_INT_OUTPUT); 36961369Sdduvall 36971369Sdduvall /* 36981369Sdduvall * All done! 36991369Sdduvall */ 37001369Sdduvall bgep->bge_chip_state = BGE_CHIP_RUNNING; 37011865Sdilpreet return (retval); 37021369Sdduvall } 37031369Sdduvall 37041369Sdduvall 37051369Sdduvall /* 37061369Sdduvall * ========== Hardware interrupt handler ========== 37071369Sdduvall */ 37081369Sdduvall 37091369Sdduvall #undef BGE_DBG 37101369Sdduvall #define BGE_DBG BGE_DBG_INT /* debug flag for this code */ 37111369Sdduvall 37121369Sdduvall /* 37131369Sdduvall * Sync the status block, then atomically clear the specified bits in 37141369Sdduvall * the <flags-and-tag> field of the status block. 37151369Sdduvall * the <flags> word of the status block, returning the value of the 37161369Sdduvall * <tag> and the <flags> before the bits were cleared. 37171369Sdduvall */ 37181865Sdilpreet static int bge_status_sync(bge_t *bgep, uint64_t bits, uint64_t *flags); 37191369Sdduvall #pragma inline(bge_status_sync) 37201369Sdduvall 37211865Sdilpreet static int 37221865Sdilpreet bge_status_sync(bge_t *bgep, uint64_t bits, uint64_t *flags) 37231369Sdduvall { 37241369Sdduvall bge_status_t *bsp; 37251865Sdilpreet int retval; 37261369Sdduvall 37271369Sdduvall BGE_TRACE(("bge_status_sync($%p, 0x%llx)", 37281369Sdduvall (void *)bgep, bits)); 37291369Sdduvall 37301369Sdduvall ASSERT(bgep->bge_guard == BGE_GUARD); 37311369Sdduvall 37321369Sdduvall DMA_SYNC(bgep->status_block, DDI_DMA_SYNC_FORKERNEL); 37331865Sdilpreet retval = bge_check_dma_handle(bgep, bgep->status_block.dma_hdl); 37341865Sdilpreet if (retval != DDI_FM_OK) 37351865Sdilpreet return (retval); 37361865Sdilpreet 37371369Sdduvall bsp = DMA_VPTR(bgep->status_block); 37381865Sdilpreet *flags = bge_atomic_clr64(&bsp->flags_n_tag, bits); 37391369Sdduvall 37401369Sdduvall BGE_DEBUG(("bge_status_sync($%p, 0x%llx) returning 0x%llx", 37411865Sdilpreet (void *)bgep, bits, *flags)); 37421865Sdilpreet 37431865Sdilpreet return (retval); 37441369Sdduvall } 37451369Sdduvall 37461369Sdduvall static void bge_wake_factotum(bge_t *bgep); 37471369Sdduvall #pragma inline(bge_wake_factotum) 37481369Sdduvall 37491369Sdduvall static void 37501369Sdduvall bge_wake_factotum(bge_t *bgep) 37511369Sdduvall { 37521369Sdduvall mutex_enter(bgep->softintrlock); 37531369Sdduvall if (bgep->factotum_flag == 0) { 37541369Sdduvall bgep->factotum_flag = 1; 37551369Sdduvall ddi_trigger_softintr(bgep->factotum_id); 37561369Sdduvall } 37571369Sdduvall mutex_exit(bgep->softintrlock); 37581369Sdduvall } 37591369Sdduvall 37601369Sdduvall /* 37611369Sdduvall * bge_intr() -- handle chip interrupts 37621369Sdduvall */ 37631369Sdduvall uint_t bge_intr(caddr_t arg1, caddr_t arg2); 37641369Sdduvall #pragma no_inline(bge_intr) 37651369Sdduvall 37661369Sdduvall uint_t 37671369Sdduvall bge_intr(caddr_t arg1, caddr_t arg2) 37681369Sdduvall { 37691369Sdduvall bge_t *bgep = (bge_t *)arg1; /* private device info */ 37701369Sdduvall bge_status_t *bsp; 37711369Sdduvall uint64_t flags; 37721369Sdduvall uint32_t mlcr = 0; 37731369Sdduvall uint_t result; 37741865Sdilpreet int retval; 37751369Sdduvall 37761369Sdduvall BGE_TRACE(("bge_intr($%p) ($%p)", arg1, arg2)); 37771369Sdduvall 37781369Sdduvall /* 37791369Sdduvall * GLD v2 checks that s/w setup is complete before passing 37801369Sdduvall * interrupts to this routine, thus eliminating the old 37811369Sdduvall * (and well-known) race condition around ddi_add_intr() 37821369Sdduvall */ 37831369Sdduvall ASSERT(bgep->progress & PROGRESS_HWINT); 37841369Sdduvall 37851369Sdduvall /* 37861369Sdduvall * Check whether chip's says it's asserting #INTA; 37871369Sdduvall * if not, don't process or claim the interrupt. 37881369Sdduvall * 37891369Sdduvall * Note that the PCI signal is active low, so the 37901369Sdduvall * bit is *zero* when the interrupt is asserted. 37911369Sdduvall */ 37921369Sdduvall result = DDI_INTR_UNCLAIMED; 37931369Sdduvall mutex_enter(bgep->genlock); 37941369Sdduvall 37951369Sdduvall if (bgep->intr_type == DDI_INTR_TYPE_FIXED) 37961369Sdduvall mlcr = bge_reg_get32(bgep, MISC_LOCAL_CONTROL_REG); 37971369Sdduvall 37981369Sdduvall BGE_DEBUG(("bge_intr($%p) ($%p) mlcr 0x%08x", arg1, arg2, mlcr)); 37991369Sdduvall 38001369Sdduvall if ((mlcr & MLCR_INTA_STATE) == 0) { 38011369Sdduvall /* 38021369Sdduvall * Block further PCI interrupts ... 38031369Sdduvall */ 38041369Sdduvall result = DDI_INTR_CLAIMED; 38051369Sdduvall 38061865Sdilpreet if (bgep->intr_type == DDI_INTR_TYPE_FIXED) { 38071908Sly149593 bge_reg_set32(bgep, PCI_CONF_BGE_MHCR, 38081369Sdduvall MHCR_MASK_PCI_INT_OUTPUT); 38091865Sdilpreet if (bge_check_acc_handle(bgep, bgep->cfg_handle) != 38101865Sdilpreet DDI_FM_OK) 38111865Sdilpreet goto chip_stop; 38121865Sdilpreet } 38131369Sdduvall 38141369Sdduvall /* 38151369Sdduvall * Sync the status block and grab the flags-n-tag from it. 38161369Sdduvall * We count the number of interrupts where there doesn't 38171369Sdduvall * seem to have been a DMA update of the status block; if 38181369Sdduvall * it *has* been updated, the counter will be cleared in 38191369Sdduvall * the while() loop below ... 38201369Sdduvall */ 38211369Sdduvall bgep->missed_dmas += 1; 38221369Sdduvall bsp = DMA_VPTR(bgep->status_block); 38231865Sdilpreet for (;;) { 38241865Sdilpreet if (bgep->bge_chip_state != BGE_CHIP_RUNNING) { 38251865Sdilpreet /* 38261865Sdilpreet * bge_chip_stop() may have freed dma area etc 38271865Sdilpreet * while we were in this interrupt handler - 38281865Sdilpreet * better not call bge_status_sync() 38291865Sdilpreet */ 38301865Sdilpreet (void) bge_check_acc_handle(bgep, 38311865Sdilpreet bgep->io_handle); 38321865Sdilpreet mutex_exit(bgep->genlock); 38331865Sdilpreet return (DDI_INTR_CLAIMED); 38341865Sdilpreet } 38351865Sdilpreet retval = bge_status_sync(bgep, STATUS_FLAG_UPDATED, 38361865Sdilpreet &flags); 38371865Sdilpreet if (retval != DDI_FM_OK) { 38381865Sdilpreet bgep->bge_dma_error = B_TRUE; 38391865Sdilpreet goto chip_stop; 38401865Sdilpreet } 38411865Sdilpreet 38421865Sdilpreet if (!(flags & STATUS_FLAG_UPDATED)) 38431865Sdilpreet break; 38441865Sdilpreet 38451369Sdduvall /* 38461369Sdduvall * Tell the chip that we're processing the interrupt 38471369Sdduvall */ 38481369Sdduvall bge_mbx_put(bgep, INTERRUPT_MBOX_0_REG, 38491369Sdduvall INTERRUPT_MBOX_DISABLE(flags)); 38501865Sdilpreet if (bge_check_acc_handle(bgep, bgep->io_handle) != 38511865Sdilpreet DDI_FM_OK) 38521865Sdilpreet goto chip_stop; 38531369Sdduvall 38541369Sdduvall /* 38551369Sdduvall * Drop the mutex while we: 38561369Sdduvall * Receive any newly-arrived packets 38571369Sdduvall * Recycle any newly-finished send buffers 38581369Sdduvall */ 38591865Sdilpreet bgep->bge_intr_running = B_TRUE; 38601369Sdduvall mutex_exit(bgep->genlock); 38611369Sdduvall bge_receive(bgep, bsp); 38621369Sdduvall bge_recycle(bgep, bsp); 38631369Sdduvall mutex_enter(bgep->genlock); 38641865Sdilpreet bgep->bge_intr_running = B_FALSE; 38651369Sdduvall 38661369Sdduvall /* 38671369Sdduvall * Tell the chip we've finished processing, and 38681369Sdduvall * give it the tag that we got from the status 38691369Sdduvall * block earlier, so that it knows just how far 38701369Sdduvall * we've gone. If it's got more for us to do, 38711369Sdduvall * it will now update the status block and try 38721369Sdduvall * to assert an interrupt (but we've got the 38731369Sdduvall * #INTA blocked at present). If we see the 38741369Sdduvall * update, we'll loop around to do some more. 38751369Sdduvall * Eventually we'll get out of here ... 38761369Sdduvall */ 38771369Sdduvall bge_mbx_put(bgep, INTERRUPT_MBOX_0_REG, 38781369Sdduvall INTERRUPT_MBOX_ENABLE(flags)); 38791369Sdduvall bgep->missed_dmas = 0; 38801369Sdduvall } 38811369Sdduvall 38821369Sdduvall /* 38831369Sdduvall * Check for exceptional conditions that we need to handle 38841369Sdduvall * 38851369Sdduvall * Link status changed 38861369Sdduvall * Status block not updated 38871369Sdduvall */ 38881369Sdduvall if (flags & STATUS_FLAG_LINK_CHANGED) 38891369Sdduvall bge_wake_factotum(bgep); 38901369Sdduvall 38911369Sdduvall if (bgep->missed_dmas) { 38921369Sdduvall /* 38931369Sdduvall * Probably due to the internal status tag not 38941369Sdduvall * being reset. Force a status block update now; 38951369Sdduvall * this should ensure that we get an update and 38961369Sdduvall * a new interrupt. After that, we should be in 38971369Sdduvall * sync again ... 38981369Sdduvall */ 38991369Sdduvall BGE_REPORT((bgep, "interrupt: flags 0x%llx - " 39001369Sdduvall "not updated?", flags)); 39011369Sdduvall bge_reg_set32(bgep, HOST_COALESCE_MODE_REG, 39021369Sdduvall COALESCE_NOW); 39031369Sdduvall 39041369Sdduvall if (bgep->missed_dmas >= bge_dma_miss_limit) { 39051369Sdduvall /* 39061369Sdduvall * If this happens multiple times in a row, 39071369Sdduvall * it means DMA is just not working. Maybe 39081369Sdduvall * the chip's failed, or maybe there's a 39091369Sdduvall * problem on the PCI bus or in the host-PCI 39101369Sdduvall * bridge (Tomatillo). 39111369Sdduvall * 39121369Sdduvall * At all events, we want to stop further 39131369Sdduvall * interrupts and let the recovery code take 39141369Sdduvall * over to see whether anything can be done 39151369Sdduvall * about it ... 39161369Sdduvall */ 39171865Sdilpreet bge_fm_ereport(bgep, 39181865Sdilpreet DDI_FM_DEVICE_BADINT_LIMIT); 39191865Sdilpreet goto chip_stop; 39201369Sdduvall } 39211369Sdduvall } 39221369Sdduvall 39231369Sdduvall /* 39241369Sdduvall * Reenable assertion of #INTA, unless there's a DMA fault 39251369Sdduvall */ 39261369Sdduvall if (result == DDI_INTR_CLAIMED) { 39271865Sdilpreet if (bgep->intr_type == DDI_INTR_TYPE_FIXED) { 39281908Sly149593 bge_reg_clr32(bgep, PCI_CONF_BGE_MHCR, 39291369Sdduvall MHCR_MASK_PCI_INT_OUTPUT); 39301865Sdilpreet if (bge_check_acc_handle(bgep, 39311865Sdilpreet bgep->cfg_handle) != DDI_FM_OK) 39321865Sdilpreet goto chip_stop; 39331865Sdilpreet } 39341369Sdduvall } 39351369Sdduvall } 39361369Sdduvall 39371865Sdilpreet if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) 39381865Sdilpreet goto chip_stop; 39391865Sdilpreet 39401865Sdilpreet mutex_exit(bgep->genlock); 39411865Sdilpreet return (result); 39421865Sdilpreet 39431865Sdilpreet chip_stop: 39441865Sdilpreet #ifdef BGE_IPMI_ASF 39451865Sdilpreet if (bgep->asf_enabled && bgep->asf_status == ASF_STAT_RUN) { 39461865Sdilpreet /* 39471865Sdilpreet * We must stop ASF heart beat before 39481865Sdilpreet * bge_chip_stop(), otherwise some 39491865Sdilpreet * computers (ex. IBM HS20 blade 39501865Sdilpreet * server) may crash. 39511865Sdilpreet */ 39521865Sdilpreet bge_asf_update_status(bgep); 39531865Sdilpreet bge_asf_stop_timer(bgep); 39541865Sdilpreet bgep->asf_status = ASF_STAT_STOP; 39551865Sdilpreet 39561865Sdilpreet bge_asf_pre_reset_operations(bgep, BGE_INIT_RESET); 39571865Sdilpreet (void) bge_check_acc_handle(bgep, bgep->cfg_handle); 39581865Sdilpreet } 39591865Sdilpreet #endif 39601865Sdilpreet bge_chip_stop(bgep, B_TRUE); 39611865Sdilpreet (void) bge_check_acc_handle(bgep, bgep->io_handle); 39621369Sdduvall mutex_exit(bgep->genlock); 39631369Sdduvall return (result); 39641369Sdduvall } 39651369Sdduvall 39661369Sdduvall /* 39671369Sdduvall * ========== Factotum, implemented as a softint handler ========== 39681369Sdduvall */ 39691369Sdduvall 39701369Sdduvall #undef BGE_DBG 39711369Sdduvall #define BGE_DBG BGE_DBG_FACT /* debug flag for this code */ 39721369Sdduvall 39731369Sdduvall static void bge_factotum_error_handler(bge_t *bgep); 39741369Sdduvall #pragma no_inline(bge_factotum_error_handler) 39751369Sdduvall 39761369Sdduvall static void 39771369Sdduvall bge_factotum_error_handler(bge_t *bgep) 39781369Sdduvall { 39791369Sdduvall uint32_t flow; 39801369Sdduvall uint32_t rdma; 39811369Sdduvall uint32_t wdma; 39821369Sdduvall uint32_t tmac; 39831369Sdduvall uint32_t rmac; 39841369Sdduvall uint32_t rxrs; 39851369Sdduvall uint32_t txrs = 0; 39861369Sdduvall 39871369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 39881369Sdduvall 39891369Sdduvall /* 39901369Sdduvall * Read all the registers that show the possible 39911369Sdduvall * reasons for the ERROR bit to be asserted 39921369Sdduvall */ 39931369Sdduvall flow = bge_reg_get32(bgep, FLOW_ATTN_REG); 39941369Sdduvall rdma = bge_reg_get32(bgep, READ_DMA_STATUS_REG); 39951369Sdduvall wdma = bge_reg_get32(bgep, WRITE_DMA_STATUS_REG); 39961369Sdduvall tmac = bge_reg_get32(bgep, TRANSMIT_MAC_STATUS_REG); 39971369Sdduvall rmac = bge_reg_get32(bgep, RECEIVE_MAC_STATUS_REG); 39981369Sdduvall rxrs = bge_reg_get32(bgep, RX_RISC_STATE_REG); 39991369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) 40001369Sdduvall txrs = bge_reg_get32(bgep, TX_RISC_STATE_REG); 40011369Sdduvall 40021369Sdduvall BGE_DEBUG(("factotum($%p) flow 0x%x rdma 0x%x wdma 0x%x", 40031369Sdduvall (void *)bgep, flow, rdma, wdma)); 40041369Sdduvall BGE_DEBUG(("factotum($%p) tmac 0x%x rmac 0x%x rxrs 0x%08x txrs 0x%08x", 40051369Sdduvall (void *)bgep, tmac, rmac, rxrs, txrs)); 40061369Sdduvall 40071369Sdduvall /* 40081369Sdduvall * For now, just clear all the errors ... 40091369Sdduvall */ 40101369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) 40111369Sdduvall bge_reg_put32(bgep, TX_RISC_STATE_REG, ~0); 40121369Sdduvall bge_reg_put32(bgep, RX_RISC_STATE_REG, ~0); 40131369Sdduvall bge_reg_put32(bgep, RECEIVE_MAC_STATUS_REG, ~0); 40141369Sdduvall bge_reg_put32(bgep, WRITE_DMA_STATUS_REG, ~0); 40151369Sdduvall bge_reg_put32(bgep, READ_DMA_STATUS_REG, ~0); 40161369Sdduvall bge_reg_put32(bgep, FLOW_ATTN_REG, ~0); 40171369Sdduvall } 40181369Sdduvall 40191369Sdduvall /* 40201369Sdduvall * Handler for hardware link state change. 40211369Sdduvall * 40221369Sdduvall * When this routine is called, the hardware link state has changed 40231369Sdduvall * and the new state is reflected in the param_* variables. Here 40241369Sdduvall * we must update the softstate, reprogram the MAC to match, and 40251369Sdduvall * record the change in the log and/or on the console. 40261369Sdduvall */ 40271369Sdduvall static void bge_factotum_link_handler(bge_t *bgep); 40281369Sdduvall #pragma no_inline(bge_factotum_link_handler) 40291369Sdduvall 40301369Sdduvall static void 40311369Sdduvall bge_factotum_link_handler(bge_t *bgep) 40321369Sdduvall { 40331369Sdduvall void (*logfn)(bge_t *bgep, const char *fmt, ...); 40341369Sdduvall const char *msg; 40351369Sdduvall hrtime_t deltat; 40361369Sdduvall 40371369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 40381369Sdduvall 40391369Sdduvall /* 40401369Sdduvall * Update the s/w link_state 40411369Sdduvall */ 40421369Sdduvall if (bgep->param_link_up) 40431369Sdduvall bgep->link_state = LINK_STATE_UP; 40441369Sdduvall else 40451369Sdduvall bgep->link_state = LINK_STATE_DOWN; 40461369Sdduvall 40471369Sdduvall /* 40481369Sdduvall * Reprogram the MAC modes to match 40491369Sdduvall */ 40501369Sdduvall bge_sync_mac_modes(bgep); 40511369Sdduvall 40521369Sdduvall /* 40531369Sdduvall * Finally, we have to decide whether to write a message 40541369Sdduvall * on the console or only in the log. If the PHY has 40551369Sdduvall * been reprogrammed (at user request) "recently", then 40561369Sdduvall * the message only goes in the log. Otherwise it's an 40571369Sdduvall * "unexpected" event, and it goes on the console as well. 40581369Sdduvall */ 40591369Sdduvall deltat = bgep->phys_event_time - bgep->phys_write_time; 40601369Sdduvall if (deltat > BGE_LINK_SETTLE_TIME) 40611369Sdduvall msg = ""; 40621369Sdduvall else if (bgep->param_link_up) 40631369Sdduvall msg = bgep->link_up_msg; 40641369Sdduvall else 40651369Sdduvall msg = bgep->link_down_msg; 40661369Sdduvall 40671369Sdduvall logfn = (msg == NULL || *msg == '\0') ? bge_notice : bge_log; 40681369Sdduvall (*logfn)(bgep, "link %s%s", bgep->link_mode_msg, msg); 40691369Sdduvall } 40701369Sdduvall 40711865Sdilpreet static boolean_t bge_factotum_link_check(bge_t *bgep, int *dma_state); 40721369Sdduvall #pragma no_inline(bge_factotum_link_check) 40731369Sdduvall 40741369Sdduvall static boolean_t 40751865Sdilpreet bge_factotum_link_check(bge_t *bgep, int *dma_state) 40761369Sdduvall { 40771369Sdduvall boolean_t check; 40781369Sdduvall uint64_t flags; 40791369Sdduvall uint32_t tmac_status; 40801369Sdduvall 40811369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 40821369Sdduvall 40831369Sdduvall /* 40841369Sdduvall * Get & clear the writable status bits in the Tx status register 40851369Sdduvall * (some bits are write-1-to-clear, others are just readonly). 40861369Sdduvall */ 40871369Sdduvall tmac_status = bge_reg_get32(bgep, TRANSMIT_MAC_STATUS_REG); 40881369Sdduvall bge_reg_put32(bgep, TRANSMIT_MAC_STATUS_REG, tmac_status); 40891369Sdduvall 40901369Sdduvall /* 40911369Sdduvall * Get & clear the ERROR and LINK_CHANGED bits from the status block 40921369Sdduvall */ 40931865Sdilpreet *dma_state = bge_status_sync(bgep, STATUS_FLAG_ERROR | 40941865Sdilpreet STATUS_FLAG_LINK_CHANGED, &flags); 40951865Sdilpreet if (*dma_state != DDI_FM_OK) 40961865Sdilpreet return (B_FALSE); 40971369Sdduvall 40981369Sdduvall /* 40991369Sdduvall * Clear any errors flagged in the status block ... 41001369Sdduvall */ 41011369Sdduvall if (flags & STATUS_FLAG_ERROR) 41021369Sdduvall bge_factotum_error_handler(bgep); 41031369Sdduvall 41041369Sdduvall /* 41051369Sdduvall * We need to check the link status if: 41061369Sdduvall * the status block says there's been a link change 41071369Sdduvall * or there's any discrepancy between the various 41081369Sdduvall * flags indicating the link state (link_state, 41091369Sdduvall * param_link_up, and the LINK STATE bit in the 41101369Sdduvall * Transmit MAC status register). 41111369Sdduvall */ 41121369Sdduvall check = (flags & STATUS_FLAG_LINK_CHANGED) != 0; 41131369Sdduvall switch (bgep->link_state) { 41141369Sdduvall case LINK_STATE_UP: 41151369Sdduvall check |= (bgep->param_link_up == B_FALSE); 41161369Sdduvall check |= ((tmac_status & TRANSMIT_STATUS_LINK_UP) == 0); 41171369Sdduvall break; 41181369Sdduvall 41191369Sdduvall case LINK_STATE_DOWN: 41201369Sdduvall check |= (bgep->param_link_up != B_FALSE); 41211369Sdduvall check |= ((tmac_status & TRANSMIT_STATUS_LINK_UP) != 0); 41221369Sdduvall break; 41231369Sdduvall 41241369Sdduvall default: 41251369Sdduvall check = B_TRUE; 41261369Sdduvall break; 41271369Sdduvall } 41281369Sdduvall 41291369Sdduvall /* 41301369Sdduvall * If <check> is false, we're sure the link hasn't changed. 41311369Sdduvall * If true, however, it's not yet definitive; we have to call 41321369Sdduvall * bge_phys_check() to determine whether the link has settled 41331369Sdduvall * into a new state yet ... and if it has, then call the link 41341369Sdduvall * state change handler.But when the chip is 5700 in Dell 6650 41351369Sdduvall * ,even if check is false, the link may have changed.So we 41361369Sdduvall * have to call bge_phys_check() to determine the link state. 41371369Sdduvall */ 41381369Sdduvall if (check || bgep->chipid.device == DEVICE_ID_5700) { 41391369Sdduvall check = bge_phys_check(bgep); 41401369Sdduvall if (check) 41411369Sdduvall bge_factotum_link_handler(bgep); 41421369Sdduvall } 41431369Sdduvall 41441369Sdduvall return (check); 41451369Sdduvall } 41461369Sdduvall 41471369Sdduvall /* 41481369Sdduvall * Factotum routine to check for Tx stall, using the 'watchdog' counter 41491369Sdduvall */ 41501369Sdduvall static boolean_t bge_factotum_stall_check(bge_t *bgep); 41511369Sdduvall #pragma no_inline(bge_factotum_stall_check) 41521369Sdduvall 41531369Sdduvall static boolean_t 41541369Sdduvall bge_factotum_stall_check(bge_t *bgep) 41551369Sdduvall { 41561369Sdduvall uint32_t dogval; 41571369Sdduvall 41581369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 41591369Sdduvall 41601369Sdduvall /* 41611369Sdduvall * Specific check for Tx stall ... 41621369Sdduvall * 41631369Sdduvall * The 'watchdog' counter is incremented whenever a packet 41641369Sdduvall * is queued, reset to 1 when some (but not all) buffers 41651369Sdduvall * are reclaimed, reset to 0 (disabled) when all buffers 41661369Sdduvall * are reclaimed, and shifted left here. If it exceeds the 41671369Sdduvall * threshold value, the chip is assumed to have stalled and 41681369Sdduvall * is put into the ERROR state. The factotum will then reset 41691369Sdduvall * it on the next pass. 41701369Sdduvall * 41711369Sdduvall * All of which should ensure that we don't get into a state 41721369Sdduvall * where packets are left pending indefinitely! 41731369Sdduvall */ 41741369Sdduvall dogval = bge_atomic_shl32(&bgep->watchdog, 1); 41751369Sdduvall if (dogval < bge_watchdog_count) 41761369Sdduvall return (B_FALSE); 41771369Sdduvall 41781369Sdduvall BGE_REPORT((bgep, "Tx stall detected, watchdog code 0x%x", dogval)); 41791865Sdilpreet bge_fm_ereport(bgep, DDI_FM_DEVICE_STALL); 41801369Sdduvall return (B_TRUE); 41811369Sdduvall } 41821369Sdduvall 41831369Sdduvall /* 41841369Sdduvall * The factotum is woken up when there's something to do that we'd rather 41851369Sdduvall * not do from inside a hardware interrupt handler or high-level cyclic. 41861369Sdduvall * Its two main tasks are: 41871369Sdduvall * reset & restart the chip after an error 41881369Sdduvall * check the link status whenever necessary 41891369Sdduvall */ 41901369Sdduvall uint_t bge_chip_factotum(caddr_t arg); 41911369Sdduvall #pragma no_inline(bge_chip_factotum) 41921369Sdduvall 41931369Sdduvall uint_t 41941369Sdduvall bge_chip_factotum(caddr_t arg) 41951369Sdduvall { 41961369Sdduvall bge_t *bgep; 41971369Sdduvall uint_t result; 41981369Sdduvall boolean_t error; 41991369Sdduvall boolean_t linkchg; 42001865Sdilpreet int dma_state; 42011369Sdduvall 42021369Sdduvall bgep = (bge_t *)arg; 42031369Sdduvall 42041369Sdduvall BGE_TRACE(("bge_chip_factotum($%p)", (void *)bgep)); 42051369Sdduvall 42061369Sdduvall mutex_enter(bgep->softintrlock); 42071369Sdduvall if (bgep->factotum_flag == 0) { 42081369Sdduvall mutex_exit(bgep->softintrlock); 42091369Sdduvall return (DDI_INTR_UNCLAIMED); 42101369Sdduvall } 42111504Sly149593 bgep->factotum_flag = 0; 42121369Sdduvall mutex_exit(bgep->softintrlock); 42131369Sdduvall 42141369Sdduvall result = DDI_INTR_CLAIMED; 42151369Sdduvall error = B_FALSE; 42161369Sdduvall linkchg = B_FALSE; 42171369Sdduvall 42181369Sdduvall mutex_enter(bgep->genlock); 42191369Sdduvall switch (bgep->bge_chip_state) { 42201369Sdduvall default: 42211369Sdduvall break; 42221369Sdduvall 42231369Sdduvall case BGE_CHIP_RUNNING: 42241865Sdilpreet linkchg = bge_factotum_link_check(bgep, &dma_state); 42251369Sdduvall error = bge_factotum_stall_check(bgep); 42261865Sdilpreet if (dma_state != DDI_FM_OK) { 42271865Sdilpreet bgep->bge_dma_error = B_TRUE; 42281865Sdilpreet error = B_TRUE; 42291865Sdilpreet } 42301865Sdilpreet if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) 42311865Sdilpreet error = B_TRUE; 42321865Sdilpreet if (error) 42331865Sdilpreet bgep->bge_chip_state = BGE_CHIP_ERROR; 42341369Sdduvall break; 42351369Sdduvall 42361369Sdduvall case BGE_CHIP_ERROR: 42371369Sdduvall error = B_TRUE; 42381369Sdduvall break; 42391369Sdduvall 42401369Sdduvall case BGE_CHIP_FAULT: 42411369Sdduvall /* 42421369Sdduvall * Fault detected, time to reset ... 42431369Sdduvall */ 42441369Sdduvall if (bge_autorecover) { 42451865Sdilpreet if (!(bgep->progress & PROGRESS_BUFS)) { 42461865Sdilpreet /* 42471865Sdilpreet * if we can't allocate the ring buffers, 42481865Sdilpreet * try later 42491865Sdilpreet */ 42501865Sdilpreet if (bge_alloc_bufs(bgep) != DDI_SUCCESS) { 42511865Sdilpreet mutex_exit(bgep->genlock); 42521865Sdilpreet return (result); 42531865Sdilpreet } 42541865Sdilpreet bgep->progress |= PROGRESS_BUFS; 42551865Sdilpreet } 42561865Sdilpreet if (!(bgep->progress & PROGRESS_INTR)) { 42571865Sdilpreet bge_init_rings(bgep); 42581865Sdilpreet bge_intr_enable(bgep); 42591865Sdilpreet bgep->progress |= PROGRESS_INTR; 42601865Sdilpreet } 42611865Sdilpreet if (!(bgep->progress & PROGRESS_KSTATS)) { 42621865Sdilpreet bge_init_kstats(bgep, 42631865Sdilpreet ddi_get_instance(bgep->devinfo)); 42641865Sdilpreet bgep->progress |= PROGRESS_KSTATS; 42651865Sdilpreet } 42661865Sdilpreet 42671369Sdduvall BGE_REPORT((bgep, "automatic recovery activated")); 42681865Sdilpreet 42691865Sdilpreet if (bge_restart(bgep, B_FALSE) != DDI_SUCCESS) { 42701865Sdilpreet bgep->bge_chip_state = BGE_CHIP_ERROR; 42711865Sdilpreet error = B_TRUE; 42721865Sdilpreet } 42731865Sdilpreet if (bge_check_acc_handle(bgep, bgep->cfg_handle) != 42741865Sdilpreet DDI_FM_OK) { 42751865Sdilpreet bgep->bge_chip_state = BGE_CHIP_ERROR; 42761865Sdilpreet error = B_TRUE; 42771865Sdilpreet } 42781865Sdilpreet if (bge_check_acc_handle(bgep, bgep->io_handle) != 42791865Sdilpreet DDI_FM_OK) { 42801865Sdilpreet bgep->bge_chip_state = BGE_CHIP_ERROR; 42811865Sdilpreet error = B_TRUE; 42821865Sdilpreet } 42831865Sdilpreet if (error == B_FALSE) { 42841408Srandyf #ifdef BGE_IPMI_ASF 42851865Sdilpreet if (bgep->asf_enabled && 42861865Sdilpreet bgep->asf_status != ASF_STAT_RUN) { 42871408Srandyf bgep->asf_timeout_id = timeout( 42881865Sdilpreet bge_asf_heartbeat, (void *)bgep, 42891865Sdilpreet drv_usectohz( 42901865Sdilpreet BGE_ASF_HEARTBEAT_INTERVAL)); 42911408Srandyf bgep->asf_status = ASF_STAT_RUN; 42921408Srandyf } 42931865Sdilpreet #endif 42941865Sdilpreet ddi_fm_service_impact(bgep->devinfo, 42951865Sdilpreet DDI_SERVICE_RESTORED); 42961408Srandyf } 42971369Sdduvall } 42981369Sdduvall break; 42991369Sdduvall } 43001369Sdduvall 43011865Sdilpreet 43021369Sdduvall /* 43031369Sdduvall * If an error is detected, stop the chip now, marking it as 43041369Sdduvall * faulty, so that it will be reset next time through ... 43051865Sdilpreet * 43061865Sdilpreet * Note that if intr_running is set, then bge_intr() has dropped 43071865Sdilpreet * genlock to call bge_receive/bge_recycle. Can't stop the chip at 43081865Sdilpreet * this point so have to wait until the next time the factotum runs. 43091369Sdduvall */ 43101865Sdilpreet if (error && !bgep->bge_intr_running) { 43111408Srandyf #ifdef BGE_IPMI_ASF 43121408Srandyf if (bgep->asf_enabled && (bgep->asf_status == ASF_STAT_RUN)) { 43131408Srandyf /* 43141408Srandyf * We must stop ASF heart beat before bge_chip_stop(), 43151408Srandyf * otherwise some computers (ex. IBM HS20 blade server) 43161408Srandyf * may crash. 43171408Srandyf */ 43181408Srandyf bge_asf_update_status(bgep); 43191408Srandyf bge_asf_stop_timer(bgep); 43201408Srandyf bgep->asf_status = ASF_STAT_STOP; 43211408Srandyf 43221408Srandyf bge_asf_pre_reset_operations(bgep, BGE_INIT_RESET); 43231865Sdilpreet (void) bge_check_acc_handle(bgep, bgep->cfg_handle); 43241408Srandyf } 43251408Srandyf #endif 43261369Sdduvall bge_chip_stop(bgep, B_TRUE); 43271865Sdilpreet (void) bge_check_acc_handle(bgep, bgep->io_handle); 43281408Srandyf } 43291369Sdduvall mutex_exit(bgep->genlock); 43301369Sdduvall 43311369Sdduvall /* 43321369Sdduvall * If the link state changed, tell the world about it. 43331369Sdduvall * Note: can't do this while still holding the mutex. 43341369Sdduvall */ 43351369Sdduvall if (linkchg) 43361369Sdduvall mac_link_update(bgep->macp, bgep->link_state); 43371369Sdduvall 43381369Sdduvall return (result); 43391369Sdduvall } 43401369Sdduvall 43411369Sdduvall /* 43421369Sdduvall * High-level cyclic handler 43431369Sdduvall * 43441369Sdduvall * This routine schedules a (low-level) softint callback to the 43451369Sdduvall * factotum, and prods the chip to update the status block (which 43461369Sdduvall * will cause a hardware interrupt when complete). 43471369Sdduvall */ 43481369Sdduvall void bge_chip_cyclic(void *arg); 43491369Sdduvall #pragma no_inline(bge_chip_cyclic) 43501369Sdduvall 43511369Sdduvall void 43521369Sdduvall bge_chip_cyclic(void *arg) 43531369Sdduvall { 43541369Sdduvall bge_t *bgep; 43551369Sdduvall 43561369Sdduvall bgep = arg; 43571369Sdduvall 43581369Sdduvall switch (bgep->bge_chip_state) { 43591369Sdduvall default: 43601369Sdduvall return; 43611369Sdduvall 43621369Sdduvall case BGE_CHIP_RUNNING: 43631369Sdduvall bge_reg_set32(bgep, HOST_COALESCE_MODE_REG, COALESCE_NOW); 43641865Sdilpreet if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) 43651865Sdilpreet ddi_fm_service_impact(bgep->devinfo, 43661865Sdilpreet DDI_SERVICE_UNAFFECTED); 43671369Sdduvall break; 43681369Sdduvall 43691369Sdduvall case BGE_CHIP_FAULT: 43701369Sdduvall case BGE_CHIP_ERROR: 43711369Sdduvall break; 43721369Sdduvall } 43731369Sdduvall 43741369Sdduvall bge_wake_factotum(bgep); 43751369Sdduvall } 43761369Sdduvall 43771369Sdduvall 43781369Sdduvall /* 43791369Sdduvall * ========== Ioctl subfunctions ========== 43801369Sdduvall */ 43811369Sdduvall 43821369Sdduvall #undef BGE_DBG 43831369Sdduvall #define BGE_DBG BGE_DBG_PPIO /* debug flag for this code */ 43841369Sdduvall 43851369Sdduvall #if BGE_DEBUGGING || BGE_DO_PPIO 43861369Sdduvall 43871369Sdduvall static void bge_chip_peek_cfg(bge_t *bgep, bge_peekpoke_t *ppd); 43881369Sdduvall #pragma no_inline(bge_chip_peek_cfg) 43891369Sdduvall 43901369Sdduvall static void 43911369Sdduvall bge_chip_peek_cfg(bge_t *bgep, bge_peekpoke_t *ppd) 43921369Sdduvall { 43931369Sdduvall uint64_t regval; 43941369Sdduvall uint64_t regno; 43951369Sdduvall 43961369Sdduvall BGE_TRACE(("bge_chip_peek_cfg($%p, $%p)", 43971369Sdduvall (void *)bgep, (void *)ppd)); 43981369Sdduvall 43991369Sdduvall regno = ppd->pp_acc_offset; 44001369Sdduvall 44011369Sdduvall switch (ppd->pp_acc_size) { 44021369Sdduvall case 1: 44031369Sdduvall regval = pci_config_get8(bgep->cfg_handle, regno); 44041369Sdduvall break; 44051369Sdduvall 44061369Sdduvall case 2: 44071369Sdduvall regval = pci_config_get16(bgep->cfg_handle, regno); 44081369Sdduvall break; 44091369Sdduvall 44101369Sdduvall case 4: 44111369Sdduvall regval = pci_config_get32(bgep->cfg_handle, regno); 44121369Sdduvall break; 44131369Sdduvall 44141369Sdduvall case 8: 44151369Sdduvall regval = pci_config_get64(bgep->cfg_handle, regno); 44161369Sdduvall break; 44171369Sdduvall } 44181369Sdduvall 44191369Sdduvall ppd->pp_acc_data = regval; 44201369Sdduvall } 44211369Sdduvall 44221369Sdduvall static void bge_chip_poke_cfg(bge_t *bgep, bge_peekpoke_t *ppd); 44231369Sdduvall #pragma no_inline(bge_chip_poke_cfg) 44241369Sdduvall 44251369Sdduvall static void 44261369Sdduvall bge_chip_poke_cfg(bge_t *bgep, bge_peekpoke_t *ppd) 44271369Sdduvall { 44281369Sdduvall uint64_t regval; 44291369Sdduvall uint64_t regno; 44301369Sdduvall 44311369Sdduvall BGE_TRACE(("bge_chip_poke_cfg($%p, $%p)", 44321369Sdduvall (void *)bgep, (void *)ppd)); 44331369Sdduvall 44341369Sdduvall regno = ppd->pp_acc_offset; 44351369Sdduvall regval = ppd->pp_acc_data; 44361369Sdduvall 44371369Sdduvall switch (ppd->pp_acc_size) { 44381369Sdduvall case 1: 44391369Sdduvall pci_config_put8(bgep->cfg_handle, regno, regval); 44401369Sdduvall break; 44411369Sdduvall 44421369Sdduvall case 2: 44431369Sdduvall pci_config_put16(bgep->cfg_handle, regno, regval); 44441369Sdduvall break; 44451369Sdduvall 44461369Sdduvall case 4: 44471369Sdduvall pci_config_put32(bgep->cfg_handle, regno, regval); 44481369Sdduvall break; 44491369Sdduvall 44501369Sdduvall case 8: 44511369Sdduvall pci_config_put64(bgep->cfg_handle, regno, regval); 44521369Sdduvall break; 44531369Sdduvall } 44541369Sdduvall } 44551369Sdduvall 44561369Sdduvall static void bge_chip_peek_reg(bge_t *bgep, bge_peekpoke_t *ppd); 44571369Sdduvall #pragma no_inline(bge_chip_peek_reg) 44581369Sdduvall 44591369Sdduvall static void 44601369Sdduvall bge_chip_peek_reg(bge_t *bgep, bge_peekpoke_t *ppd) 44611369Sdduvall { 44621369Sdduvall uint64_t regval; 44631369Sdduvall void *regaddr; 44641369Sdduvall 44651369Sdduvall BGE_TRACE(("bge_chip_peek_reg($%p, $%p)", 44661369Sdduvall (void *)bgep, (void *)ppd)); 44671369Sdduvall 44681369Sdduvall regaddr = PIO_ADDR(bgep, ppd->pp_acc_offset); 44691369Sdduvall 44701369Sdduvall switch (ppd->pp_acc_size) { 44711369Sdduvall case 1: 44721369Sdduvall regval = ddi_get8(bgep->io_handle, regaddr); 44731369Sdduvall break; 44741369Sdduvall 44751369Sdduvall case 2: 44761369Sdduvall regval = ddi_get16(bgep->io_handle, regaddr); 44771369Sdduvall break; 44781369Sdduvall 44791369Sdduvall case 4: 44801369Sdduvall regval = ddi_get32(bgep->io_handle, regaddr); 44811369Sdduvall break; 44821369Sdduvall 44831369Sdduvall case 8: 44841369Sdduvall regval = ddi_get64(bgep->io_handle, regaddr); 44851369Sdduvall break; 44861369Sdduvall } 44871369Sdduvall 44881369Sdduvall ppd->pp_acc_data = regval; 44891369Sdduvall } 44901369Sdduvall 44911369Sdduvall static void bge_chip_poke_reg(bge_t *bgep, bge_peekpoke_t *ppd); 44921369Sdduvall #pragma no_inline(bge_chip_peek_reg) 44931369Sdduvall 44941369Sdduvall static void 44951369Sdduvall bge_chip_poke_reg(bge_t *bgep, bge_peekpoke_t *ppd) 44961369Sdduvall { 44971369Sdduvall uint64_t regval; 44981369Sdduvall void *regaddr; 44991369Sdduvall 45001369Sdduvall BGE_TRACE(("bge_chip_poke_reg($%p, $%p)", 45011369Sdduvall (void *)bgep, (void *)ppd)); 45021369Sdduvall 45031369Sdduvall regaddr = PIO_ADDR(bgep, ppd->pp_acc_offset); 45041369Sdduvall regval = ppd->pp_acc_data; 45051369Sdduvall 45061369Sdduvall switch (ppd->pp_acc_size) { 45071369Sdduvall case 1: 45081369Sdduvall ddi_put8(bgep->io_handle, regaddr, regval); 45091369Sdduvall break; 45101369Sdduvall 45111369Sdduvall case 2: 45121369Sdduvall ddi_put16(bgep->io_handle, regaddr, regval); 45131369Sdduvall break; 45141369Sdduvall 45151369Sdduvall case 4: 45161369Sdduvall ddi_put32(bgep->io_handle, regaddr, regval); 45171369Sdduvall break; 45181369Sdduvall 45191369Sdduvall case 8: 45201369Sdduvall ddi_put64(bgep->io_handle, regaddr, regval); 45211369Sdduvall break; 45221369Sdduvall } 45231369Sdduvall BGE_PCICHK(bgep); 45241369Sdduvall } 45251369Sdduvall 45261369Sdduvall static void bge_chip_peek_nic(bge_t *bgep, bge_peekpoke_t *ppd); 45271369Sdduvall #pragma no_inline(bge_chip_peek_nic) 45281369Sdduvall 45291369Sdduvall static void 45301369Sdduvall bge_chip_peek_nic(bge_t *bgep, bge_peekpoke_t *ppd) 45311369Sdduvall { 45321369Sdduvall uint64_t regoff; 45331369Sdduvall uint64_t regval; 45341369Sdduvall void *regaddr; 45351369Sdduvall 45361369Sdduvall BGE_TRACE(("bge_chip_peek_nic($%p, $%p)", 45371369Sdduvall (void *)bgep, (void *)ppd)); 45381369Sdduvall 45391369Sdduvall regoff = ppd->pp_acc_offset; 45401369Sdduvall bge_nic_setwin(bgep, regoff & ~MWBAR_GRANULE_MASK); 45411369Sdduvall regoff &= MWBAR_GRANULE_MASK; 45421369Sdduvall regoff += NIC_MEM_WINDOW_OFFSET; 45431369Sdduvall regaddr = PIO_ADDR(bgep, regoff); 45441369Sdduvall 45451369Sdduvall switch (ppd->pp_acc_size) { 45461369Sdduvall case 1: 45471369Sdduvall regval = ddi_get8(bgep->io_handle, regaddr); 45481369Sdduvall break; 45491369Sdduvall 45501369Sdduvall case 2: 45511369Sdduvall regval = ddi_get16(bgep->io_handle, regaddr); 45521369Sdduvall break; 45531369Sdduvall 45541369Sdduvall case 4: 45551369Sdduvall regval = ddi_get32(bgep->io_handle, regaddr); 45561369Sdduvall break; 45571369Sdduvall 45581369Sdduvall case 8: 45591369Sdduvall regval = ddi_get64(bgep->io_handle, regaddr); 45601369Sdduvall break; 45611369Sdduvall } 45621369Sdduvall 45631369Sdduvall ppd->pp_acc_data = regval; 45641369Sdduvall } 45651369Sdduvall 45661369Sdduvall static void bge_chip_poke_nic(bge_t *bgep, bge_peekpoke_t *ppd); 45671369Sdduvall #pragma no_inline(bge_chip_poke_nic) 45681369Sdduvall 45691369Sdduvall static void 45701369Sdduvall bge_chip_poke_nic(bge_t *bgep, bge_peekpoke_t *ppd) 45711369Sdduvall { 45721369Sdduvall uint64_t regoff; 45731369Sdduvall uint64_t regval; 45741369Sdduvall void *regaddr; 45751369Sdduvall 45761369Sdduvall BGE_TRACE(("bge_chip_poke_nic($%p, $%p)", 45771369Sdduvall (void *)bgep, (void *)ppd)); 45781369Sdduvall 45791369Sdduvall regoff = ppd->pp_acc_offset; 45801369Sdduvall bge_nic_setwin(bgep, regoff & ~MWBAR_GRANULE_MASK); 45811369Sdduvall regoff &= MWBAR_GRANULE_MASK; 45821369Sdduvall regoff += NIC_MEM_WINDOW_OFFSET; 45831369Sdduvall regaddr = PIO_ADDR(bgep, regoff); 45841369Sdduvall regval = ppd->pp_acc_data; 45851369Sdduvall 45861369Sdduvall switch (ppd->pp_acc_size) { 45871369Sdduvall case 1: 45881369Sdduvall ddi_put8(bgep->io_handle, regaddr, regval); 45891369Sdduvall break; 45901369Sdduvall 45911369Sdduvall case 2: 45921369Sdduvall ddi_put16(bgep->io_handle, regaddr, regval); 45931369Sdduvall break; 45941369Sdduvall 45951369Sdduvall case 4: 45961369Sdduvall ddi_put32(bgep->io_handle, regaddr, regval); 45971369Sdduvall break; 45981369Sdduvall 45991369Sdduvall case 8: 46001369Sdduvall ddi_put64(bgep->io_handle, regaddr, regval); 46011369Sdduvall break; 46021369Sdduvall } 46031369Sdduvall BGE_PCICHK(bgep); 46041369Sdduvall } 46051369Sdduvall 46061369Sdduvall static void bge_chip_peek_mii(bge_t *bgep, bge_peekpoke_t *ppd); 46071369Sdduvall #pragma no_inline(bge_chip_peek_mii) 46081369Sdduvall 46091369Sdduvall static void 46101369Sdduvall bge_chip_peek_mii(bge_t *bgep, bge_peekpoke_t *ppd) 46111369Sdduvall { 46121369Sdduvall BGE_TRACE(("bge_chip_peek_mii($%p, $%p)", 46131369Sdduvall (void *)bgep, (void *)ppd)); 46141369Sdduvall 46151369Sdduvall ppd->pp_acc_data = bge_mii_get16(bgep, ppd->pp_acc_offset/2); 46161369Sdduvall } 46171369Sdduvall 46181369Sdduvall static void bge_chip_poke_mii(bge_t *bgep, bge_peekpoke_t *ppd); 46191369Sdduvall #pragma no_inline(bge_chip_poke_mii) 46201369Sdduvall 46211369Sdduvall static void 46221369Sdduvall bge_chip_poke_mii(bge_t *bgep, bge_peekpoke_t *ppd) 46231369Sdduvall { 46241369Sdduvall BGE_TRACE(("bge_chip_poke_mii($%p, $%p)", 46251369Sdduvall (void *)bgep, (void *)ppd)); 46261369Sdduvall 46271369Sdduvall bge_mii_put16(bgep, ppd->pp_acc_offset/2, ppd->pp_acc_data); 46281369Sdduvall } 46291369Sdduvall 46301369Sdduvall #if BGE_SEE_IO32 46311369Sdduvall 46321369Sdduvall static void bge_chip_peek_seeprom(bge_t *bgep, bge_peekpoke_t *ppd); 46331369Sdduvall #pragma no_inline(bge_chip_peek_seeprom) 46341369Sdduvall 46351369Sdduvall static void 46361369Sdduvall bge_chip_peek_seeprom(bge_t *bgep, bge_peekpoke_t *ppd) 46371369Sdduvall { 46381369Sdduvall uint32_t data; 46391369Sdduvall int err; 46401369Sdduvall 46411369Sdduvall BGE_TRACE(("bge_chip_peek_seeprom($%p, $%p)", 46421369Sdduvall (void *)bgep, (void *)ppd)); 46431369Sdduvall 46441369Sdduvall err = bge_nvmem_rw32(bgep, BGE_SEE_READ, ppd->pp_acc_offset, &data); 46451369Sdduvall ppd->pp_acc_data = err ? ~0ull : data; 46461369Sdduvall } 46471369Sdduvall 46481369Sdduvall static void bge_chip_poke_seeprom(bge_t *bgep, bge_peekpoke_t *ppd); 46491369Sdduvall #pragma no_inline(bge_chip_poke_seeprom) 46501369Sdduvall 46511369Sdduvall static void 46521369Sdduvall bge_chip_poke_seeprom(bge_t *bgep, bge_peekpoke_t *ppd) 46531369Sdduvall { 46541369Sdduvall uint32_t data; 46551369Sdduvall 46561369Sdduvall BGE_TRACE(("bge_chip_poke_seeprom($%p, $%p)", 46571369Sdduvall (void *)bgep, (void *)ppd)); 46581369Sdduvall 46591369Sdduvall data = ppd->pp_acc_data; 46601369Sdduvall (void) bge_nvmem_rw32(bgep, BGE_SEE_WRITE, ppd->pp_acc_offset, &data); 46611369Sdduvall } 46621369Sdduvall #endif /* BGE_SEE_IO32 */ 46631369Sdduvall 46641369Sdduvall #if BGE_FLASH_IO32 46651369Sdduvall 46661369Sdduvall static void bge_chip_peek_flash(bge_t *bgep, bge_peekpoke_t *ppd); 46671369Sdduvall #pragma no_inline(bge_chip_peek_flash) 46681369Sdduvall 46691369Sdduvall static void 46701369Sdduvall bge_chip_peek_flash(bge_t *bgep, bge_peekpoke_t *ppd) 46711369Sdduvall { 46721369Sdduvall uint32_t data; 46731369Sdduvall int err; 46741369Sdduvall 46751369Sdduvall BGE_TRACE(("bge_chip_peek_flash($%p, $%p)", 46761369Sdduvall (void *)bgep, (void *)ppd)); 46771369Sdduvall 46781369Sdduvall err = bge_nvmem_rw32(bgep, BGE_FLASH_READ, ppd->pp_acc_offset, &data); 46791369Sdduvall ppd->pp_acc_data = err ? ~0ull : data; 46801369Sdduvall } 46811369Sdduvall 46821369Sdduvall static void bge_chip_poke_flash(bge_t *bgep, bge_peekpoke_t *ppd); 46831369Sdduvall #pragma no_inline(bge_chip_poke_flash) 46841369Sdduvall 46851369Sdduvall static void 46861369Sdduvall bge_chip_poke_flash(bge_t *bgep, bge_peekpoke_t *ppd) 46871369Sdduvall { 46881369Sdduvall uint32_t data; 46891369Sdduvall 46901369Sdduvall BGE_TRACE(("bge_chip_poke_flash($%p, $%p)", 46911369Sdduvall (void *)bgep, (void *)ppd)); 46921369Sdduvall 46931369Sdduvall data = ppd->pp_acc_data; 46941369Sdduvall (void) bge_nvmem_rw32(bgep, BGE_FLASH_WRITE, 46951369Sdduvall ppd->pp_acc_offset, &data); 46961369Sdduvall } 46971369Sdduvall #endif /* BGE_FLASH_IO32 */ 46981369Sdduvall 46991369Sdduvall static void bge_chip_peek_mem(bge_t *bgep, bge_peekpoke_t *ppd); 47001369Sdduvall #pragma no_inline(bge_chip_peek_mem) 47011369Sdduvall 47021369Sdduvall static void 47031369Sdduvall bge_chip_peek_mem(bge_t *bgep, bge_peekpoke_t *ppd) 47041369Sdduvall { 47051369Sdduvall uint64_t regval; 47061369Sdduvall void *vaddr; 47071369Sdduvall 47081369Sdduvall BGE_TRACE(("bge_chip_peek_bge($%p, $%p)", 47091369Sdduvall (void *)bgep, (void *)ppd)); 47101369Sdduvall 47111369Sdduvall vaddr = (void *)(uintptr_t)ppd->pp_acc_offset; 47121369Sdduvall 47131369Sdduvall switch (ppd->pp_acc_size) { 47141369Sdduvall case 1: 47151369Sdduvall regval = *(uint8_t *)vaddr; 47161369Sdduvall break; 47171369Sdduvall 47181369Sdduvall case 2: 47191369Sdduvall regval = *(uint16_t *)vaddr; 47201369Sdduvall break; 47211369Sdduvall 47221369Sdduvall case 4: 47231369Sdduvall regval = *(uint32_t *)vaddr; 47241369Sdduvall break; 47251369Sdduvall 47261369Sdduvall case 8: 47271369Sdduvall regval = *(uint64_t *)vaddr; 47281369Sdduvall break; 47291369Sdduvall } 47301369Sdduvall 47311369Sdduvall BGE_DEBUG(("bge_chip_peek_mem($%p, $%p) peeked 0x%llx from $%p", 47321369Sdduvall (void *)bgep, (void *)ppd, regval, vaddr)); 47331369Sdduvall 47341369Sdduvall ppd->pp_acc_data = regval; 47351369Sdduvall } 47361369Sdduvall 47371369Sdduvall static void bge_chip_poke_mem(bge_t *bgep, bge_peekpoke_t *ppd); 47381369Sdduvall #pragma no_inline(bge_chip_poke_mem) 47391369Sdduvall 47401369Sdduvall static void 47411369Sdduvall bge_chip_poke_mem(bge_t *bgep, bge_peekpoke_t *ppd) 47421369Sdduvall { 47431369Sdduvall uint64_t regval; 47441369Sdduvall void *vaddr; 47451369Sdduvall 47461369Sdduvall BGE_TRACE(("bge_chip_poke_mem($%p, $%p)", 47471369Sdduvall (void *)bgep, (void *)ppd)); 47481369Sdduvall 47491369Sdduvall vaddr = (void *)(uintptr_t)ppd->pp_acc_offset; 47501369Sdduvall regval = ppd->pp_acc_data; 47511369Sdduvall 47521369Sdduvall BGE_DEBUG(("bge_chip_poke_mem($%p, $%p) poking 0x%llx at $%p", 47531369Sdduvall (void *)bgep, (void *)ppd, regval, vaddr)); 47541369Sdduvall 47551369Sdduvall switch (ppd->pp_acc_size) { 47561369Sdduvall case 1: 47571369Sdduvall *(uint8_t *)vaddr = (uint8_t)regval; 47581369Sdduvall break; 47591369Sdduvall 47601369Sdduvall case 2: 47611369Sdduvall *(uint16_t *)vaddr = (uint16_t)regval; 47621369Sdduvall break; 47631369Sdduvall 47641369Sdduvall case 4: 47651369Sdduvall *(uint32_t *)vaddr = (uint32_t)regval; 47661369Sdduvall break; 47671369Sdduvall 47681369Sdduvall case 8: 47691369Sdduvall *(uint64_t *)vaddr = (uint64_t)regval; 47701369Sdduvall break; 47711369Sdduvall } 47721369Sdduvall } 47731369Sdduvall 47741369Sdduvall static enum ioc_reply bge_pp_ioctl(bge_t *bgep, int cmd, mblk_t *mp, 47751369Sdduvall struct iocblk *iocp); 47761369Sdduvall #pragma no_inline(bge_pp_ioctl) 47771369Sdduvall 47781369Sdduvall static enum ioc_reply 47791369Sdduvall bge_pp_ioctl(bge_t *bgep, int cmd, mblk_t *mp, struct iocblk *iocp) 47801369Sdduvall { 47811369Sdduvall void (*ppfn)(bge_t *bgep, bge_peekpoke_t *ppd); 47821369Sdduvall bge_peekpoke_t *ppd; 47831369Sdduvall dma_area_t *areap; 47841369Sdduvall uint64_t sizemask; 47851369Sdduvall uint64_t mem_va; 47861369Sdduvall uint64_t maxoff; 47871369Sdduvall boolean_t peek; 47881369Sdduvall 47891369Sdduvall switch (cmd) { 47901369Sdduvall default: 47911369Sdduvall /* NOTREACHED */ 47921369Sdduvall bge_error(bgep, "bge_pp_ioctl: invalid cmd 0x%x", cmd); 47931369Sdduvall return (IOC_INVAL); 47941369Sdduvall 47951369Sdduvall case BGE_PEEK: 47961369Sdduvall peek = B_TRUE; 47971369Sdduvall break; 47981369Sdduvall 47991369Sdduvall case BGE_POKE: 48001369Sdduvall peek = B_FALSE; 48011369Sdduvall break; 48021369Sdduvall } 48031369Sdduvall 48041369Sdduvall /* 48051369Sdduvall * Validate format of ioctl 48061369Sdduvall */ 48071369Sdduvall if (iocp->ioc_count != sizeof (bge_peekpoke_t)) 48081369Sdduvall return (IOC_INVAL); 48091369Sdduvall if (mp->b_cont == NULL) 48101369Sdduvall return (IOC_INVAL); 48111369Sdduvall ppd = (bge_peekpoke_t *)mp->b_cont->b_rptr; 48121369Sdduvall 48131369Sdduvall /* 48141369Sdduvall * Validate request parameters 48151369Sdduvall */ 48161369Sdduvall switch (ppd->pp_acc_space) { 48171369Sdduvall default: 48181369Sdduvall return (IOC_INVAL); 48191369Sdduvall 48201369Sdduvall case BGE_PP_SPACE_CFG: 48211369Sdduvall /* 48221369Sdduvall * Config space 48231369Sdduvall */ 48241369Sdduvall sizemask = 8|4|2|1; 48251369Sdduvall mem_va = 0; 48261369Sdduvall maxoff = PCI_CONF_HDR_SIZE; 48271369Sdduvall ppfn = peek ? bge_chip_peek_cfg : bge_chip_poke_cfg; 48281369Sdduvall break; 48291369Sdduvall 48301369Sdduvall case BGE_PP_SPACE_REG: 48311369Sdduvall /* 48321369Sdduvall * Memory-mapped I/O space 48331369Sdduvall */ 48341369Sdduvall sizemask = 8|4|2|1; 48351369Sdduvall mem_va = 0; 48361369Sdduvall maxoff = RIAAR_REGISTER_MAX; 48371369Sdduvall ppfn = peek ? bge_chip_peek_reg : bge_chip_poke_reg; 48381369Sdduvall break; 48391369Sdduvall 48401369Sdduvall case BGE_PP_SPACE_NIC: 48411369Sdduvall /* 48421369Sdduvall * NIC on-chip memory 48431369Sdduvall */ 48441369Sdduvall sizemask = 8|4|2|1; 48451369Sdduvall mem_va = 0; 48461369Sdduvall maxoff = MWBAR_ONCHIP_MAX; 48471369Sdduvall ppfn = peek ? bge_chip_peek_nic : bge_chip_poke_nic; 48481369Sdduvall break; 48491369Sdduvall 48501369Sdduvall case BGE_PP_SPACE_MII: 48511369Sdduvall /* 48521369Sdduvall * PHY's MII registers 48531369Sdduvall * NB: all PHY registers are two bytes, but the 48541369Sdduvall * addresses increment in ones (word addressing). 48551369Sdduvall * So we scale the address here, then undo the 48561369Sdduvall * transformation inside the peek/poke functions. 48571369Sdduvall */ 48581369Sdduvall ppd->pp_acc_offset *= 2; 48591369Sdduvall sizemask = 2; 48601369Sdduvall mem_va = 0; 48611369Sdduvall maxoff = (MII_MAXREG+1)*2; 48621369Sdduvall ppfn = peek ? bge_chip_peek_mii : bge_chip_poke_mii; 48631369Sdduvall break; 48641369Sdduvall 48651369Sdduvall #if BGE_SEE_IO32 48661369Sdduvall case BGE_PP_SPACE_SEEPROM: 48671369Sdduvall /* 48681369Sdduvall * Attached SEEPROM(s), if any. 48691369Sdduvall * NB: we use the high-order bits of the 'address' as 48701369Sdduvall * a device select to accommodate multiple SEEPROMS, 48711369Sdduvall * If each one is the maximum size (64kbytes), this 48721369Sdduvall * makes them appear contiguous. Otherwise, there may 48731369Sdduvall * be holes in the mapping. ENxS doesn't have any 48741369Sdduvall * SEEPROMs anyway ... 48751369Sdduvall */ 48761369Sdduvall sizemask = 4; 48771369Sdduvall mem_va = 0; 48781369Sdduvall maxoff = SEEPROM_DEV_AND_ADDR_MASK; 48791369Sdduvall ppfn = peek ? bge_chip_peek_seeprom : bge_chip_poke_seeprom; 48801369Sdduvall break; 48811369Sdduvall #endif /* BGE_SEE_IO32 */ 48821369Sdduvall 48831369Sdduvall #if BGE_FLASH_IO32 48841369Sdduvall case BGE_PP_SPACE_FLASH: 48851369Sdduvall /* 48861369Sdduvall * Attached Flash device (if any); a maximum of one device 48871369Sdduvall * is currently supported. But it can be up to 1MB (unlike 48881369Sdduvall * the 64k limit on SEEPROMs) so why would you need more ;-) 48891369Sdduvall */ 48901369Sdduvall sizemask = 4; 48911369Sdduvall mem_va = 0; 48921369Sdduvall maxoff = NVM_FLASH_ADDR_MASK; 48931369Sdduvall ppfn = peek ? bge_chip_peek_flash : bge_chip_poke_flash; 48941369Sdduvall break; 48951369Sdduvall #endif /* BGE_FLASH_IO32 */ 48961369Sdduvall 48971369Sdduvall case BGE_PP_SPACE_BGE: 48981369Sdduvall /* 48991369Sdduvall * BGE data structure! 49001369Sdduvall */ 49011369Sdduvall sizemask = 8|4|2|1; 49021369Sdduvall mem_va = (uintptr_t)bgep; 49031369Sdduvall maxoff = sizeof (*bgep); 49041369Sdduvall ppfn = peek ? bge_chip_peek_mem : bge_chip_poke_mem; 49051369Sdduvall break; 49061369Sdduvall 49071369Sdduvall case BGE_PP_SPACE_STATUS: 49081369Sdduvall case BGE_PP_SPACE_STATISTICS: 49091369Sdduvall case BGE_PP_SPACE_TXDESC: 49101369Sdduvall case BGE_PP_SPACE_TXBUFF: 49111369Sdduvall case BGE_PP_SPACE_RXDESC: 49121369Sdduvall case BGE_PP_SPACE_RXBUFF: 49131369Sdduvall /* 49141369Sdduvall * Various DMA_AREAs 49151369Sdduvall */ 49161369Sdduvall switch (ppd->pp_acc_space) { 49171369Sdduvall case BGE_PP_SPACE_TXDESC: 49181369Sdduvall areap = &bgep->tx_desc; 49191369Sdduvall break; 49201369Sdduvall case BGE_PP_SPACE_TXBUFF: 49211369Sdduvall areap = &bgep->tx_buff[0]; 49221369Sdduvall break; 49231369Sdduvall case BGE_PP_SPACE_RXDESC: 49241369Sdduvall areap = &bgep->rx_desc[0]; 49251369Sdduvall break; 49261369Sdduvall case BGE_PP_SPACE_RXBUFF: 49271369Sdduvall areap = &bgep->rx_buff[0]; 49281369Sdduvall break; 49291369Sdduvall case BGE_PP_SPACE_STATUS: 49301369Sdduvall areap = &bgep->status_block; 49311369Sdduvall break; 49321369Sdduvall case BGE_PP_SPACE_STATISTICS: 49331369Sdduvall if (bgep->chipid.statistic_type == BGE_STAT_BLK) 49341369Sdduvall areap = &bgep->statistics; 49351369Sdduvall break; 49361369Sdduvall } 49371369Sdduvall 49381369Sdduvall sizemask = 8|4|2|1; 49391369Sdduvall mem_va = (uintptr_t)areap->mem_va; 49401369Sdduvall maxoff = areap->alength; 49411369Sdduvall ppfn = peek ? bge_chip_peek_mem : bge_chip_poke_mem; 49421369Sdduvall break; 49431369Sdduvall } 49441369Sdduvall 49451369Sdduvall switch (ppd->pp_acc_size) { 49461369Sdduvall default: 49471369Sdduvall return (IOC_INVAL); 49481369Sdduvall 49491369Sdduvall case 8: 49501369Sdduvall case 4: 49511369Sdduvall case 2: 49521369Sdduvall case 1: 49531369Sdduvall if ((ppd->pp_acc_size & sizemask) == 0) 49541369Sdduvall return (IOC_INVAL); 49551369Sdduvall break; 49561369Sdduvall } 49571369Sdduvall 49581369Sdduvall if ((ppd->pp_acc_offset % ppd->pp_acc_size) != 0) 49591369Sdduvall return (IOC_INVAL); 49601369Sdduvall 49611369Sdduvall if (ppd->pp_acc_offset >= maxoff) 49621369Sdduvall return (IOC_INVAL); 49631369Sdduvall 49641369Sdduvall if (ppd->pp_acc_offset+ppd->pp_acc_size > maxoff) 49651369Sdduvall return (IOC_INVAL); 49661369Sdduvall 49671369Sdduvall /* 49681369Sdduvall * All OK - go do it! 49691369Sdduvall */ 49701369Sdduvall ppd->pp_acc_offset += mem_va; 49711369Sdduvall (*ppfn)(bgep, ppd); 49721369Sdduvall return (peek ? IOC_REPLY : IOC_ACK); 49731369Sdduvall } 49741369Sdduvall 49751369Sdduvall static enum ioc_reply bge_diag_ioctl(bge_t *bgep, int cmd, mblk_t *mp, 49761369Sdduvall struct iocblk *iocp); 49771369Sdduvall #pragma no_inline(bge_diag_ioctl) 49781369Sdduvall 49791369Sdduvall static enum ioc_reply 49801369Sdduvall bge_diag_ioctl(bge_t *bgep, int cmd, mblk_t *mp, struct iocblk *iocp) 49811369Sdduvall { 49821369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 49831369Sdduvall 49841369Sdduvall switch (cmd) { 49851369Sdduvall default: 49861369Sdduvall /* NOTREACHED */ 49871369Sdduvall bge_error(bgep, "bge_diag_ioctl: invalid cmd 0x%x", cmd); 49881369Sdduvall return (IOC_INVAL); 49891369Sdduvall 49901369Sdduvall case BGE_DIAG: 49911369Sdduvall /* 49921369Sdduvall * Currently a no-op 49931369Sdduvall */ 49941369Sdduvall return (IOC_ACK); 49951369Sdduvall 49961369Sdduvall case BGE_PEEK: 49971369Sdduvall case BGE_POKE: 49981369Sdduvall return (bge_pp_ioctl(bgep, cmd, mp, iocp)); 49991369Sdduvall 50001369Sdduvall case BGE_PHY_RESET: 50011369Sdduvall return (IOC_RESTART_ACK); 50021369Sdduvall 50031369Sdduvall case BGE_SOFT_RESET: 50041369Sdduvall case BGE_HARD_RESET: 50051369Sdduvall /* 50061369Sdduvall * Reset and reinitialise the 570x hardware 50071369Sdduvall */ 50081865Sdilpreet (void) bge_restart(bgep, cmd == BGE_HARD_RESET); 50091369Sdduvall return (IOC_ACK); 50101369Sdduvall } 50111369Sdduvall 50121369Sdduvall /* NOTREACHED */ 50131369Sdduvall } 50141369Sdduvall 50151369Sdduvall #endif /* BGE_DEBUGGING || BGE_DO_PPIO */ 50161369Sdduvall 50171369Sdduvall static enum ioc_reply bge_mii_ioctl(bge_t *bgep, int cmd, mblk_t *mp, 50181369Sdduvall struct iocblk *iocp); 50191369Sdduvall #pragma no_inline(bge_mii_ioctl) 50201369Sdduvall 50211369Sdduvall static enum ioc_reply 50221369Sdduvall bge_mii_ioctl(bge_t *bgep, int cmd, mblk_t *mp, struct iocblk *iocp) 50231369Sdduvall { 50241369Sdduvall struct bge_mii_rw *miirwp; 50251369Sdduvall 50261369Sdduvall /* 50271369Sdduvall * Validate format of ioctl 50281369Sdduvall */ 50291369Sdduvall if (iocp->ioc_count != sizeof (struct bge_mii_rw)) 50301369Sdduvall return (IOC_INVAL); 50311369Sdduvall if (mp->b_cont == NULL) 50321369Sdduvall return (IOC_INVAL); 50331369Sdduvall miirwp = (struct bge_mii_rw *)mp->b_cont->b_rptr; 50341369Sdduvall 50351369Sdduvall /* 50361369Sdduvall * Validate request parameters ... 50371369Sdduvall */ 50381369Sdduvall if (miirwp->mii_reg > MII_MAXREG) 50391369Sdduvall return (IOC_INVAL); 50401369Sdduvall 50411369Sdduvall switch (cmd) { 50421369Sdduvall default: 50431369Sdduvall /* NOTREACHED */ 50441369Sdduvall bge_error(bgep, "bge_mii_ioctl: invalid cmd 0x%x", cmd); 50451369Sdduvall return (IOC_INVAL); 50461369Sdduvall 50471369Sdduvall case BGE_MII_READ: 50481369Sdduvall miirwp->mii_data = bge_mii_get16(bgep, miirwp->mii_reg); 50491369Sdduvall return (IOC_REPLY); 50501369Sdduvall 50511369Sdduvall case BGE_MII_WRITE: 50521369Sdduvall bge_mii_put16(bgep, miirwp->mii_reg, miirwp->mii_data); 50531369Sdduvall return (IOC_ACK); 50541369Sdduvall } 50551369Sdduvall 50561369Sdduvall /* NOTREACHED */ 50571369Sdduvall } 50581369Sdduvall 50591369Sdduvall #if BGE_SEE_IO32 50601369Sdduvall 50611369Sdduvall static enum ioc_reply bge_see_ioctl(bge_t *bgep, int cmd, mblk_t *mp, 50621369Sdduvall struct iocblk *iocp); 50631369Sdduvall #pragma no_inline(bge_see_ioctl) 50641369Sdduvall 50651369Sdduvall static enum ioc_reply 50661369Sdduvall bge_see_ioctl(bge_t *bgep, int cmd, mblk_t *mp, struct iocblk *iocp) 50671369Sdduvall { 50681369Sdduvall struct bge_see_rw *seerwp; 50691369Sdduvall 50701369Sdduvall /* 50711369Sdduvall * Validate format of ioctl 50721369Sdduvall */ 50731369Sdduvall if (iocp->ioc_count != sizeof (struct bge_see_rw)) 50741369Sdduvall return (IOC_INVAL); 50751369Sdduvall if (mp->b_cont == NULL) 50761369Sdduvall return (IOC_INVAL); 50771369Sdduvall seerwp = (struct bge_see_rw *)mp->b_cont->b_rptr; 50781369Sdduvall 50791369Sdduvall /* 50801369Sdduvall * Validate request parameters ... 50811369Sdduvall */ 50821369Sdduvall if (seerwp->see_addr & ~SEEPROM_DEV_AND_ADDR_MASK) 50831369Sdduvall return (IOC_INVAL); 50841369Sdduvall 50851369Sdduvall switch (cmd) { 50861369Sdduvall default: 50871369Sdduvall /* NOTREACHED */ 50881369Sdduvall bge_error(bgep, "bge_see_ioctl: invalid cmd 0x%x", cmd); 50891369Sdduvall return (IOC_INVAL); 50901369Sdduvall 50911369Sdduvall case BGE_SEE_READ: 50921369Sdduvall case BGE_SEE_WRITE: 50931369Sdduvall iocp->ioc_error = bge_nvmem_rw32(bgep, cmd, 50941369Sdduvall seerwp->see_addr, &seerwp->see_data); 50951369Sdduvall return (IOC_REPLY); 50961369Sdduvall } 50971369Sdduvall 50981369Sdduvall /* NOTREACHED */ 50991369Sdduvall } 51001369Sdduvall 51011369Sdduvall #endif /* BGE_SEE_IO32 */ 51021369Sdduvall 51031369Sdduvall #if BGE_FLASH_IO32 51041369Sdduvall 51051369Sdduvall static enum ioc_reply bge_flash_ioctl(bge_t *bgep, int cmd, mblk_t *mp, 51061369Sdduvall struct iocblk *iocp); 51071369Sdduvall #pragma no_inline(bge_flash_ioctl) 51081369Sdduvall 51091369Sdduvall static enum ioc_reply 51101369Sdduvall bge_flash_ioctl(bge_t *bgep, int cmd, mblk_t *mp, struct iocblk *iocp) 51111369Sdduvall { 51121369Sdduvall struct bge_flash_rw *flashrwp; 51131369Sdduvall 51141369Sdduvall /* 51151369Sdduvall * Validate format of ioctl 51161369Sdduvall */ 51171369Sdduvall if (iocp->ioc_count != sizeof (struct bge_flash_rw)) 51181369Sdduvall return (IOC_INVAL); 51191369Sdduvall if (mp->b_cont == NULL) 51201369Sdduvall return (IOC_INVAL); 51211369Sdduvall flashrwp = (struct bge_flash_rw *)mp->b_cont->b_rptr; 51221369Sdduvall 51231369Sdduvall /* 51241369Sdduvall * Validate request parameters ... 51251369Sdduvall */ 51261369Sdduvall if (flashrwp->flash_addr & ~NVM_FLASH_ADDR_MASK) 51271369Sdduvall return (IOC_INVAL); 51281369Sdduvall 51291369Sdduvall switch (cmd) { 51301369Sdduvall default: 51311369Sdduvall /* NOTREACHED */ 51321369Sdduvall bge_error(bgep, "bge_flash_ioctl: invalid cmd 0x%x", cmd); 51331369Sdduvall return (IOC_INVAL); 51341369Sdduvall 51351369Sdduvall case BGE_FLASH_READ: 51361369Sdduvall case BGE_FLASH_WRITE: 51371369Sdduvall iocp->ioc_error = bge_nvmem_rw32(bgep, cmd, 51381369Sdduvall flashrwp->flash_addr, &flashrwp->flash_data); 51391369Sdduvall return (IOC_REPLY); 51401369Sdduvall } 51411369Sdduvall 51421369Sdduvall /* NOTREACHED */ 51431369Sdduvall } 51441369Sdduvall 51451369Sdduvall #endif /* BGE_FLASH_IO32 */ 51461369Sdduvall 51471369Sdduvall enum ioc_reply bge_chip_ioctl(bge_t *bgep, queue_t *wq, mblk_t *mp, 51481369Sdduvall struct iocblk *iocp); 51491369Sdduvall #pragma no_inline(bge_chip_ioctl) 51501369Sdduvall 51511369Sdduvall enum ioc_reply 51521369Sdduvall bge_chip_ioctl(bge_t *bgep, queue_t *wq, mblk_t *mp, struct iocblk *iocp) 51531369Sdduvall { 51541369Sdduvall int cmd; 51551369Sdduvall 51561369Sdduvall BGE_TRACE(("bge_chip_ioctl($%p, $%p, $%p, $%p)", 51571369Sdduvall (void *)bgep, (void *)wq, (void *)mp, (void *)iocp)); 51581369Sdduvall 51591369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 51601369Sdduvall 51611369Sdduvall cmd = iocp->ioc_cmd; 51621369Sdduvall switch (cmd) { 51631369Sdduvall default: 51641369Sdduvall /* NOTREACHED */ 51651369Sdduvall bge_error(bgep, "bge_chip_ioctl: invalid cmd 0x%x", cmd); 51661369Sdduvall return (IOC_INVAL); 51671369Sdduvall 51681369Sdduvall case BGE_DIAG: 51691369Sdduvall case BGE_PEEK: 51701369Sdduvall case BGE_POKE: 51711369Sdduvall case BGE_PHY_RESET: 51721369Sdduvall case BGE_SOFT_RESET: 51731369Sdduvall case BGE_HARD_RESET: 51741369Sdduvall #if BGE_DEBUGGING || BGE_DO_PPIO 51751369Sdduvall return (bge_diag_ioctl(bgep, cmd, mp, iocp)); 51761369Sdduvall #else 51771369Sdduvall return (IOC_INVAL); 51781369Sdduvall #endif /* BGE_DEBUGGING || BGE_DO_PPIO */ 51791369Sdduvall 51801369Sdduvall case BGE_MII_READ: 51811369Sdduvall case BGE_MII_WRITE: 51821369Sdduvall return (bge_mii_ioctl(bgep, cmd, mp, iocp)); 51831369Sdduvall 51841369Sdduvall #if BGE_SEE_IO32 51851369Sdduvall case BGE_SEE_READ: 51861369Sdduvall case BGE_SEE_WRITE: 51871369Sdduvall return (bge_see_ioctl(bgep, cmd, mp, iocp)); 51881369Sdduvall #endif /* BGE_SEE_IO32 */ 51891369Sdduvall 51901369Sdduvall #if BGE_FLASH_IO32 51911369Sdduvall case BGE_FLASH_READ: 51921369Sdduvall case BGE_FLASH_WRITE: 51931369Sdduvall return (bge_flash_ioctl(bgep, cmd, mp, iocp)); 51941369Sdduvall #endif /* BGE_FLASH_IO32 */ 51951369Sdduvall } 51961369Sdduvall 51971369Sdduvall /* NOTREACHED */ 51981369Sdduvall } 51991369Sdduvall 52001369Sdduvall void 52011369Sdduvall bge_chip_blank(void *arg, time_t ticks, uint_t count) 52021369Sdduvall { 52031369Sdduvall bge_t *bgep = arg; 52041369Sdduvall 52051865Sdilpreet mutex_enter(bgep->genlock); 52061369Sdduvall bge_reg_put32(bgep, RCV_COALESCE_TICKS_REG, ticks); 52071369Sdduvall bge_reg_put32(bgep, RCV_COALESCE_MAX_BD_REG, count); 52081865Sdilpreet if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) 52091865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_UNAFFECTED); 52101865Sdilpreet mutex_exit(bgep->genlock); 52111369Sdduvall } 52121408Srandyf 52131408Srandyf #ifdef BGE_IPMI_ASF 52141408Srandyf 52151408Srandyf uint32_t 52161408Srandyf bge_nic_read32(bge_t *bgep, bge_regno_t addr) 52171408Srandyf { 52181408Srandyf uint32_t data; 52191408Srandyf 52201408Srandyf if (!bgep->asf_wordswapped) { 52211408Srandyf /* a workaround word swap error */ 52221408Srandyf if (addr & 4) 52231408Srandyf addr = addr - 4; 52241408Srandyf else 52251408Srandyf addr = addr + 4; 52261408Srandyf } 52271408Srandyf 52281408Srandyf pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_MWBAR, addr); 52291408Srandyf data = pci_config_get32(bgep->cfg_handle, PCI_CONF_BGE_MWDAR); 52301408Srandyf pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_MWBAR, 0); 52311408Srandyf 52321408Srandyf return (data); 52331408Srandyf } 52341408Srandyf 52351408Srandyf 52361408Srandyf void 52371408Srandyf bge_asf_update_status(bge_t *bgep) 52381408Srandyf { 52391408Srandyf uint32_t event; 52401408Srandyf 52411408Srandyf bge_nic_put32(bgep, BGE_CMD_MAILBOX, BGE_CMD_NICDRV_ALIVE); 52421408Srandyf bge_nic_put32(bgep, BGE_CMD_LENGTH_MAILBOX, 4); 52431408Srandyf bge_nic_put32(bgep, BGE_CMD_DATA_MAILBOX, 3); 52441408Srandyf 52451408Srandyf event = bge_reg_get32(bgep, RX_RISC_EVENT_REG); 52461408Srandyf bge_reg_put32(bgep, RX_RISC_EVENT_REG, event | RRER_ASF_EVENT); 52471408Srandyf } 52481408Srandyf 52491408Srandyf 52501408Srandyf /* 52511408Srandyf * The driver is supposed to notify ASF that the OS is still running 52521408Srandyf * every three seconds, otherwise the management server may attempt 52531408Srandyf * to reboot the machine. If it hasn't actually failed, this is 5254*2135Szh199473 * not a desirable result. However, this isn't running as a real-time 52551408Srandyf * thread, and even if it were, it might not be able to generate the 52561408Srandyf * heartbeat in a timely manner due to system load. As it isn't a 52571408Srandyf * significant strain on the machine, we will set the interval to half 52581408Srandyf * of the required value. 52591408Srandyf */ 52601408Srandyf void 52611865Sdilpreet bge_asf_heartbeat(void *arg) 52621408Srandyf { 52631865Sdilpreet bge_t *bgep = (bge_t *)arg; 52641865Sdilpreet 52651865Sdilpreet mutex_enter(bgep->genlock); 52661408Srandyf bge_asf_update_status((bge_t *)bgep); 52671865Sdilpreet if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) 52681865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_DEGRADED); 52691865Sdilpreet if (bge_check_acc_handle(bgep, bgep->cfg_handle) != DDI_FM_OK) 52701865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_DEGRADED); 52711865Sdilpreet mutex_exit(bgep->genlock); 52721408Srandyf ((bge_t *)bgep)->asf_timeout_id = timeout(bge_asf_heartbeat, bgep, 52731408Srandyf drv_usectohz(BGE_ASF_HEARTBEAT_INTERVAL)); 52741408Srandyf } 52751408Srandyf 52761408Srandyf 52771408Srandyf void 52781408Srandyf bge_asf_stop_timer(bge_t *bgep) 52791408Srandyf { 52801408Srandyf timeout_id_t tmp_id = 0; 52811408Srandyf 52821408Srandyf while ((bgep->asf_timeout_id != 0) && 52831408Srandyf (tmp_id != bgep->asf_timeout_id)) { 52841408Srandyf tmp_id = bgep->asf_timeout_id; 52851408Srandyf (void) untimeout(tmp_id); 52861408Srandyf } 52871408Srandyf bgep->asf_timeout_id = 0; 52881408Srandyf } 52891408Srandyf 52901408Srandyf 52911408Srandyf 52921408Srandyf /* 5293*2135Szh199473 * This function should be placed at the earliest position of bge_attach(). 52941408Srandyf */ 52951408Srandyf void 52961408Srandyf bge_asf_get_config(bge_t *bgep) 52971408Srandyf { 52981408Srandyf uint32_t nicsig; 52991408Srandyf uint32_t niccfg; 53001408Srandyf 53011408Srandyf nicsig = bge_nic_read32(bgep, BGE_NIC_DATA_SIG_ADDR); 53021408Srandyf if (nicsig == BGE_NIC_DATA_SIG) { 53031408Srandyf niccfg = bge_nic_read32(bgep, BGE_NIC_DATA_NIC_CFG_ADDR); 53041408Srandyf if (niccfg & BGE_NIC_CFG_ENABLE_ASF) 53051408Srandyf /* 53061408Srandyf * Here, we don't consider BAXTER, because BGE haven't 53071408Srandyf * supported BAXTER (that is 5752). Also, as I know, 53081408Srandyf * BAXTER doesn't support ASF feature. 53091408Srandyf */ 53101408Srandyf bgep->asf_enabled = B_TRUE; 53111408Srandyf else 53121408Srandyf bgep->asf_enabled = B_FALSE; 53131408Srandyf } else 53141408Srandyf bgep->asf_enabled = B_FALSE; 53151408Srandyf } 53161408Srandyf 53171408Srandyf 53181408Srandyf void 53191408Srandyf bge_asf_pre_reset_operations(bge_t *bgep, uint32_t mode) 53201408Srandyf { 53211408Srandyf uint32_t tries; 53221408Srandyf uint32_t event; 53231408Srandyf 53241408Srandyf ASSERT(bgep->asf_enabled); 53251408Srandyf 53261408Srandyf /* Issues "pause firmware" command and wait for ACK */ 53271408Srandyf bge_nic_put32(bgep, BGE_CMD_MAILBOX, BGE_CMD_NICDRV_PAUSE_FW); 53281408Srandyf event = bge_reg_get32(bgep, RX_RISC_EVENT_REG); 53291408Srandyf bge_reg_put32(bgep, RX_RISC_EVENT_REG, event | RRER_ASF_EVENT); 53301408Srandyf 53311408Srandyf event = bge_reg_get32(bgep, RX_RISC_EVENT_REG); 53321408Srandyf tries = 0; 53331408Srandyf while ((event & RRER_ASF_EVENT) && (tries < 100)) { 53341408Srandyf drv_usecwait(1); 53351408Srandyf tries ++; 53361408Srandyf event = bge_reg_get32(bgep, RX_RISC_EVENT_REG); 53371408Srandyf } 53381408Srandyf 53391408Srandyf bge_nic_put32(bgep, BGE_FIRMWARE_MAILBOX, 53401408Srandyf BGE_MAGIC_NUM_FIRMWARE_INIT_DONE); 53411408Srandyf 53421408Srandyf if (bgep->asf_newhandshake) { 53431408Srandyf switch (mode) { 53441408Srandyf case BGE_INIT_RESET: 53451408Srandyf bge_nic_put32(bgep, BGE_DRV_STATE_MAILBOX, 53461408Srandyf BGE_DRV_STATE_START); 53471408Srandyf break; 53481408Srandyf case BGE_SHUTDOWN_RESET: 53491408Srandyf bge_nic_put32(bgep, BGE_DRV_STATE_MAILBOX, 53501408Srandyf BGE_DRV_STATE_UNLOAD); 53511408Srandyf break; 53521408Srandyf case BGE_SUSPEND_RESET: 53531408Srandyf bge_nic_put32(bgep, BGE_DRV_STATE_MAILBOX, 53541408Srandyf BGE_DRV_STATE_SUSPEND); 53551408Srandyf break; 53561408Srandyf default: 53571408Srandyf break; 53581408Srandyf } 53591408Srandyf } 53601408Srandyf } 53611408Srandyf 53621408Srandyf 53631408Srandyf void 53641408Srandyf bge_asf_post_reset_old_mode(bge_t *bgep, uint32_t mode) 53651408Srandyf { 53661408Srandyf switch (mode) { 53671408Srandyf case BGE_INIT_RESET: 53681408Srandyf bge_nic_put32(bgep, BGE_DRV_STATE_MAILBOX, 53691408Srandyf BGE_DRV_STATE_START); 53701408Srandyf break; 53711408Srandyf case BGE_SHUTDOWN_RESET: 53721408Srandyf bge_nic_put32(bgep, BGE_DRV_STATE_MAILBOX, 53731408Srandyf BGE_DRV_STATE_UNLOAD); 53741408Srandyf break; 53751408Srandyf case BGE_SUSPEND_RESET: 53761408Srandyf bge_nic_put32(bgep, BGE_DRV_STATE_MAILBOX, 53771408Srandyf BGE_DRV_STATE_SUSPEND); 53781408Srandyf break; 53791408Srandyf default: 53801408Srandyf break; 53811408Srandyf } 53821408Srandyf } 53831408Srandyf 53841408Srandyf 53851408Srandyf void 53861408Srandyf bge_asf_post_reset_new_mode(bge_t *bgep, uint32_t mode) 53871408Srandyf { 53881408Srandyf switch (mode) { 53891408Srandyf case BGE_INIT_RESET: 53901408Srandyf bge_nic_put32(bgep, BGE_DRV_STATE_MAILBOX, 53911408Srandyf BGE_DRV_STATE_START_DONE); 53921408Srandyf break; 53931408Srandyf case BGE_SHUTDOWN_RESET: 53941408Srandyf bge_nic_put32(bgep, BGE_DRV_STATE_MAILBOX, 53951408Srandyf BGE_DRV_STATE_UNLOAD_DONE); 53961408Srandyf break; 53971408Srandyf default: 53981408Srandyf break; 53991408Srandyf } 54001408Srandyf } 54011408Srandyf 54021408Srandyf #endif /* BGE_IPMI_ASF */ 5403