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 29*2675Szh199473 #include "bge_impl.h" 301369Sdduvall 311369Sdduvall #define PIO_ADDR(bgep, offset) ((void *)((caddr_t)(bgep)->io_regs+(offset))) 321369Sdduvall 331369Sdduvall /* 341369Sdduvall * Future features ... ? 351369Sdduvall */ 362135Szh199473 #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 * 3892135Szh199473 * 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 * 4162135Szh199473 * 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 4582135Szh199473 * 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 5482135Szh199473 * 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 } 5902135Szh199473 /* 5912135Szh199473 * Step 8: Disable PCI-X/PCI-E Relaxed Ordering 5922135Szh199473 */ 5932135Szh199473 bge_cfg_clr16(bgep, PCIX_CONF_COMM, PCIX_COMM_RELAXED); 5942135Szh199473 5952135Szh199473 if (cidp->pci_type == BGE_PCI_E) 5962135Szh199473 bge_cfg_clr16(bgep, PCI_CONF_DEV_CTRL, 5972135Szh199473 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 * 13132135Szh199473 * 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 * 14112135Szh199473 * 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 15352135Szh199473 * 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 16012135Szh199473 * 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: 18302135Szh199473 case DEVICE_ID_5789: 18311369Sdduvall case DEVICE_ID_5751: 18321369Sdduvall case DEVICE_ID_5751M: 1833*2675Szh199473 case DEVICE_ID_5752: 1834*2675Szh199473 case DEVICE_ID_5752M: 18351369Sdduvall case DEVICE_ID_5721: 18361369Sdduvall case DEVICE_ID_5714C: 18371369Sdduvall case DEVICE_ID_5714S: 18381369Sdduvall case DEVICE_ID_5715C: 18391369Sdduvall config1 = bge_reg_get32(bgep, NVM_CONFIG1_REG); 18401369Sdduvall if (config1 & NVM_CFG1_FLASH_MODE) 18411369Sdduvall if (config1 & NVM_CFG1_BUFFERED_MODE) 18421369Sdduvall nvtype = BGE_NVTYPE_BUFFERED_FLASH; 18431369Sdduvall else 18441369Sdduvall nvtype = BGE_NVTYPE_UNBUFFERED_FLASH; 18451369Sdduvall else 18461369Sdduvall nvtype = BGE_NVTYPE_LEGACY_SEEPROM; 18471369Sdduvall break; 18481369Sdduvall } 18491369Sdduvall 18501369Sdduvall return (nvtype); 18511369Sdduvall } 18521369Sdduvall 18531369Sdduvall #undef BGE_DBG 18541369Sdduvall #define BGE_DBG BGE_DBG_CHIP /* debug flag for this code */ 18551369Sdduvall 18561369Sdduvall static void 18571369Sdduvall bge_init_recv_rule(bge_t *bgep) 18581369Sdduvall { 18591369Sdduvall bge_recv_rule_t *rulep; 18601369Sdduvall uint32_t i; 18611369Sdduvall 18621369Sdduvall /* 18631369Sdduvall * receive rule: direct all TCP traffic to ring RULE_MATCH_TO_RING 18641369Sdduvall * 1. to direct UDP traffic, set: 18651369Sdduvall * rulep->control = RULE_PROTO_CONTROL; 18661369Sdduvall * rulep->mask_value = RULE_UDP_MASK_VALUE; 18671369Sdduvall * 2. to direct ICMP traffic, set: 18681369Sdduvall * rulep->control = RULE_PROTO_CONTROL; 18691369Sdduvall * rulep->mask_value = RULE_ICMP_MASK_VALUE; 18701369Sdduvall * 3. to direct traffic by source ip, set: 18711369Sdduvall * rulep->control = RULE_SIP_CONTROL; 18721369Sdduvall * rulep->mask_value = RULE_SIP_MASK_VALUE; 18731369Sdduvall */ 18741369Sdduvall rulep = bgep->recv_rules; 18751369Sdduvall rulep->control = RULE_PROTO_CONTROL; 18761369Sdduvall rulep->mask_value = RULE_TCP_MASK_VALUE; 18771369Sdduvall 18781369Sdduvall /* 18791369Sdduvall * set receive rule registers 18801369Sdduvall */ 18811369Sdduvall rulep = bgep->recv_rules; 18821369Sdduvall for (i = 0; i < RECV_RULES_NUM_MAX; i++, rulep++) { 18831369Sdduvall bge_reg_put32(bgep, RECV_RULE_MASK_REG(i), rulep->mask_value); 18841369Sdduvall bge_reg_put32(bgep, RECV_RULE_CONTROL_REG(i), rulep->control); 18851369Sdduvall } 18861369Sdduvall } 18871369Sdduvall 18881369Sdduvall /* 18891369Sdduvall * Using the values captured by bge_chip_cfg_init(), and additional probes 18901369Sdduvall * as required, characterise the chip fully: determine the label by which 18911369Sdduvall * to refer to this chip, the correct settings for various registers, and 18921369Sdduvall * of course whether the device and/or subsystem are supported! 18931369Sdduvall */ 18941865Sdilpreet int bge_chip_id_init(bge_t *bgep); 18951369Sdduvall #pragma no_inline(bge_chip_id_init) 18961369Sdduvall 18971865Sdilpreet int 18981369Sdduvall bge_chip_id_init(bge_t *bgep) 18991369Sdduvall { 19001369Sdduvall char buf[MAXPATHLEN]; /* any risk of stack overflow? */ 19011369Sdduvall boolean_t sys_ok; 19021369Sdduvall boolean_t dev_ok; 19031369Sdduvall chip_id_t *cidp; 19041369Sdduvall uint32_t subid; 19051369Sdduvall char *devname; 19061369Sdduvall char *sysname; 19071369Sdduvall int *ids; 19081369Sdduvall int err; 19091369Sdduvall uint_t i; 19101369Sdduvall 19111369Sdduvall ASSERT(bgep->bge_chip_state == BGE_CHIP_INITIAL); 19121369Sdduvall 19131369Sdduvall sys_ok = dev_ok = B_FALSE; 19141369Sdduvall cidp = &bgep->chipid; 19151369Sdduvall 19161369Sdduvall /* 19171369Sdduvall * Check the PCI device ID to determine the generic chip type and 19181369Sdduvall * select parameters that depend on this. 19191369Sdduvall * 19201369Sdduvall * Note: because the SPARC platforms in general don't fit the 19211369Sdduvall * SEEPROM 'behind' the chip, the PCI revision ID register reads 19221369Sdduvall * as zero - which is why we use <asic_rev> rather than <revision> 19231369Sdduvall * below ... 19241369Sdduvall * 19251369Sdduvall * Note: in general we can't distinguish between the Copper/SerDes 19261369Sdduvall * versions by ID alone, as some Copper devices (e.g. some but not 19271369Sdduvall * all 5703Cs) have the same ID as the SerDes equivalents. So we 19281369Sdduvall * treat them the same here, and the MII code works out the media 19291369Sdduvall * type later on ... 19301369Sdduvall */ 19311369Sdduvall cidp->mbuf_base = bge_mbuf_pool_base; 19321369Sdduvall cidp->mbuf_length = bge_mbuf_pool_len; 19331369Sdduvall cidp->recv_slots = BGE_RECV_SLOTS_USED; 19341369Sdduvall cidp->bge_dma_rwctrl = bge_dma_rwctrl; 19351369Sdduvall cidp->pci_type = BGE_PCI_X; 19361369Sdduvall cidp->statistic_type = BGE_STAT_BLK; 19371908Sly149593 cidp->mbuf_lo_water_rdma = bge_mbuf_lo_water_rdma; 19381908Sly149593 cidp->mbuf_lo_water_rmac = bge_mbuf_lo_water_rmac; 19391908Sly149593 cidp->mbuf_hi_water = bge_mbuf_hi_water; 19401369Sdduvall 19411369Sdduvall if (cidp->rx_rings == 0 || cidp->rx_rings > BGE_RECV_RINGS_MAX) 19421369Sdduvall cidp->rx_rings = BGE_RECV_RINGS_DEFAULT; 19431369Sdduvall if (cidp->tx_rings == 0 || cidp->tx_rings > BGE_SEND_RINGS_MAX) 19441369Sdduvall cidp->tx_rings = BGE_SEND_RINGS_DEFAULT; 19451369Sdduvall 19461369Sdduvall cidp->msi_enabled = B_FALSE; 19471369Sdduvall 19481369Sdduvall switch (cidp->device) { 19491369Sdduvall case DEVICE_ID_5700: 19501369Sdduvall case DEVICE_ID_5700x: 19511369Sdduvall cidp->chip_label = 5700; 19522135Szh199473 cidp->flags |= CHIP_FLAG_PARTIAL_CSUM; 19531369Sdduvall break; 19541369Sdduvall 19551369Sdduvall case DEVICE_ID_5701: 19561369Sdduvall cidp->chip_label = 5701; 19571369Sdduvall dev_ok = B_TRUE; 19582135Szh199473 cidp->flags |= CHIP_FLAG_PARTIAL_CSUM; 19591369Sdduvall break; 19601369Sdduvall 19611369Sdduvall case DEVICE_ID_5702: 19621369Sdduvall case DEVICE_ID_5702fe: 19631369Sdduvall cidp->chip_label = 5702; 19641369Sdduvall dev_ok = B_TRUE; 19652135Szh199473 cidp->flags |= CHIP_FLAG_PARTIAL_CSUM; 19662135Szh199473 cidp->pci_type = BGE_PCI; 19671369Sdduvall break; 19681369Sdduvall 19691369Sdduvall case DEVICE_ID_5703C: 19701369Sdduvall case DEVICE_ID_5703S: 19711369Sdduvall case DEVICE_ID_5703: 19721369Sdduvall /* 19731369Sdduvall * Revision A0 of the 5703/5793 had various errata 19741369Sdduvall * that we can't or don't work around, so it's not 19751369Sdduvall * supported, but all later versions are 19761369Sdduvall */ 19771369Sdduvall cidp->chip_label = cidp->subven == VENDOR_ID_SUN ? 5793 : 5703; 19781369Sdduvall if (bgep->chipid.asic_rev != MHCR_CHIP_REV_5703_A0) 19791369Sdduvall dev_ok = B_TRUE; 19802135Szh199473 cidp->flags |= CHIP_FLAG_PARTIAL_CSUM; 19811369Sdduvall break; 19821369Sdduvall 19831369Sdduvall case DEVICE_ID_5704C: 19841369Sdduvall case DEVICE_ID_5704S: 19851369Sdduvall case DEVICE_ID_5704: 19861369Sdduvall /* 19871369Sdduvall * Revision A0 of the 5704/5794 had various errata 19881369Sdduvall * but we have workarounds, so it *is* supported. 19891369Sdduvall */ 19901369Sdduvall cidp->chip_label = cidp->subven == VENDOR_ID_SUN ? 5794 : 5704; 19911369Sdduvall cidp->mbuf_base = bge_mbuf_pool_base_5704; 19921369Sdduvall cidp->mbuf_length = bge_mbuf_pool_len_5704; 19931369Sdduvall dev_ok = B_TRUE; 19942135Szh199473 if (cidp->asic_rev < MHCR_CHIP_REV_5704_B0) 19952135Szh199473 cidp->flags |= CHIP_FLAG_PARTIAL_CSUM; 19961369Sdduvall break; 19971369Sdduvall 19981369Sdduvall case DEVICE_ID_5705C: 19991369Sdduvall case DEVICE_ID_5705M: 20001369Sdduvall case DEVICE_ID_5705MA3: 20011369Sdduvall case DEVICE_ID_5705F: 20021369Sdduvall cidp->chip_label = 5705; 20031908Sly149593 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 20041908Sly149593 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 20051908Sly149593 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 20061369Sdduvall cidp->mbuf_base = bge_mbuf_pool_base_5705; 20071369Sdduvall cidp->mbuf_length = bge_mbuf_pool_len_5705; 20081369Sdduvall cidp->recv_slots = BGE_RECV_SLOTS_5705; 20091369Sdduvall cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 20101908Sly149593 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 20111369Sdduvall cidp->flags |= CHIP_FLAG_NO_JUMBO; 20122135Szh199473 cidp->flags |= CHIP_FLAG_PARTIAL_CSUM; 20132135Szh199473 cidp->pci_type = BGE_PCI; 20141369Sdduvall cidp->statistic_type = BGE_STAT_REG; 20151369Sdduvall dev_ok = B_TRUE; 20161369Sdduvall break; 20171369Sdduvall 20181369Sdduvall case DEVICE_ID_5706: 20191369Sdduvall cidp->chip_label = 5706; 20201369Sdduvall cidp->flags |= CHIP_FLAG_NO_JUMBO; 20211369Sdduvall break; 20221369Sdduvall 20231369Sdduvall case DEVICE_ID_5782: 20241369Sdduvall /* 20251369Sdduvall * Apart from the label, we treat this as a 5705(?) 20261369Sdduvall */ 20271369Sdduvall cidp->chip_label = 5782; 20281908Sly149593 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 20291908Sly149593 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 20301908Sly149593 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 20311369Sdduvall cidp->mbuf_base = bge_mbuf_pool_base_5705; 20321369Sdduvall cidp->mbuf_length = bge_mbuf_pool_len_5705; 20331369Sdduvall cidp->recv_slots = BGE_RECV_SLOTS_5705; 20341369Sdduvall cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 20351908Sly149593 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 20361369Sdduvall cidp->flags |= CHIP_FLAG_NO_JUMBO; 20372135Szh199473 cidp->flags |= CHIP_FLAG_PARTIAL_CSUM; 20381369Sdduvall cidp->statistic_type = BGE_STAT_REG; 20391369Sdduvall dev_ok = B_TRUE; 20401369Sdduvall break; 20411369Sdduvall 20421369Sdduvall case DEVICE_ID_5788: 20431369Sdduvall /* 20441369Sdduvall * Apart from the label, we treat this as a 5705(?) 20451369Sdduvall */ 20461369Sdduvall cidp->chip_label = 5788; 20471908Sly149593 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 20481908Sly149593 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 20491908Sly149593 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 20501369Sdduvall cidp->mbuf_base = bge_mbuf_pool_base_5705; 20511369Sdduvall cidp->mbuf_length = bge_mbuf_pool_len_5705; 20521369Sdduvall cidp->recv_slots = BGE_RECV_SLOTS_5705; 20531369Sdduvall cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 20541908Sly149593 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 20551369Sdduvall cidp->statistic_type = BGE_STAT_REG; 20561369Sdduvall cidp->flags |= CHIP_FLAG_NO_JUMBO; 20571369Sdduvall dev_ok = B_TRUE; 20581369Sdduvall break; 20591369Sdduvall 20601369Sdduvall case DEVICE_ID_5714C: 20611369Sdduvall if (cidp->revision >= REVISION_ID_5714_A2) 20621369Sdduvall cidp->msi_enabled = bge_enable_msi; 20631369Sdduvall /* FALLTHRU */ 20641369Sdduvall case DEVICE_ID_5714S: 20651369Sdduvall cidp->chip_label = 5714; 20661908Sly149593 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 20671908Sly149593 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 20681908Sly149593 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 20691369Sdduvall cidp->mbuf_base = bge_mbuf_pool_base_5721; 20701369Sdduvall cidp->mbuf_length = bge_mbuf_pool_len_5721; 20711369Sdduvall cidp->recv_slots = BGE_RECV_SLOTS_5721; 20721369Sdduvall cidp->bge_dma_rwctrl = bge_dma_rwctrl_5714; 20731369Sdduvall cidp->bge_mlcr_default = bge_mlcr_default_5714; 20741369Sdduvall cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 20751908Sly149593 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 20761369Sdduvall cidp->pci_type = BGE_PCI_E; 20771369Sdduvall cidp->statistic_type = BGE_STAT_REG; 20781369Sdduvall dev_ok = B_TRUE; 20791369Sdduvall break; 20801369Sdduvall 20811369Sdduvall case DEVICE_ID_5715C: 20821369Sdduvall cidp->chip_label = 5715; 20831908Sly149593 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 20841908Sly149593 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 20851908Sly149593 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 20861369Sdduvall cidp->mbuf_base = bge_mbuf_pool_base_5721; 20871369Sdduvall cidp->mbuf_length = bge_mbuf_pool_len_5721; 20881369Sdduvall cidp->recv_slots = BGE_RECV_SLOTS_5721; 20891369Sdduvall cidp->bge_dma_rwctrl = bge_dma_rwctrl_5715; 20901369Sdduvall cidp->bge_mlcr_default = bge_mlcr_default_5714; 20911369Sdduvall cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 20921908Sly149593 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 20931369Sdduvall cidp->pci_type = BGE_PCI_E; 20941369Sdduvall cidp->statistic_type = BGE_STAT_REG; 20951908Sly149593 if (cidp->revision >= REVISION_ID_5715_A2) 20961908Sly149593 cidp->msi_enabled = bge_enable_msi; 20971369Sdduvall dev_ok = B_TRUE; 20981369Sdduvall break; 20991369Sdduvall 21001369Sdduvall case DEVICE_ID_5721: 21011369Sdduvall cidp->chip_label = 5721; 21021908Sly149593 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 21031908Sly149593 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 21041908Sly149593 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 21051369Sdduvall cidp->mbuf_base = bge_mbuf_pool_base_5721; 21061369Sdduvall cidp->mbuf_length = bge_mbuf_pool_len_5721; 21071369Sdduvall cidp->recv_slots = BGE_RECV_SLOTS_5721; 21081369Sdduvall cidp->bge_dma_rwctrl = bge_dma_rwctrl_5721; 21091369Sdduvall cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 21101908Sly149593 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 21111369Sdduvall cidp->pci_type = BGE_PCI_E; 21121369Sdduvall cidp->statistic_type = BGE_STAT_REG; 21131369Sdduvall cidp->flags |= CHIP_FLAG_NO_JUMBO; 21141369Sdduvall dev_ok = B_TRUE; 21151369Sdduvall break; 21161369Sdduvall 21171369Sdduvall case DEVICE_ID_5751: 21181369Sdduvall case DEVICE_ID_5751M: 21191369Sdduvall cidp->chip_label = 5751; 21201908Sly149593 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 21211908Sly149593 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 21221908Sly149593 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 21231369Sdduvall cidp->mbuf_base = bge_mbuf_pool_base_5721; 21241369Sdduvall cidp->mbuf_length = bge_mbuf_pool_len_5721; 21251369Sdduvall cidp->recv_slots = BGE_RECV_SLOTS_5721; 21261369Sdduvall cidp->bge_dma_rwctrl = bge_dma_rwctrl_5721; 21271369Sdduvall cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 21281908Sly149593 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 21291369Sdduvall cidp->pci_type = BGE_PCI_E; 21301369Sdduvall cidp->statistic_type = BGE_STAT_REG; 21311369Sdduvall cidp->flags |= CHIP_FLAG_NO_JUMBO; 21321369Sdduvall dev_ok = B_TRUE; 21331369Sdduvall break; 21341369Sdduvall 2135*2675Szh199473 case DEVICE_ID_5752: 2136*2675Szh199473 case DEVICE_ID_5752M: 2137*2675Szh199473 cidp->chip_label = 5752; 2138*2675Szh199473 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 2139*2675Szh199473 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 2140*2675Szh199473 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 2141*2675Szh199473 cidp->mbuf_base = bge_mbuf_pool_base_5721; 2142*2675Szh199473 cidp->mbuf_length = bge_mbuf_pool_len_5721; 2143*2675Szh199473 cidp->recv_slots = BGE_RECV_SLOTS_5721; 2144*2675Szh199473 cidp->bge_dma_rwctrl = bge_dma_rwctrl_5721; 2145*2675Szh199473 cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 2146*2675Szh199473 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 2147*2675Szh199473 cidp->pci_type = BGE_PCI_E; 2148*2675Szh199473 cidp->statistic_type = BGE_STAT_REG; 2149*2675Szh199473 cidp->flags |= CHIP_FLAG_NO_JUMBO; 2150*2675Szh199473 dev_ok = B_TRUE; 2151*2675Szh199473 break; 2152*2675Szh199473 21532135Szh199473 case DEVICE_ID_5789: 21542135Szh199473 cidp->chip_label = 5789; 21552135Szh199473 cidp->mbuf_base = bge_mbuf_pool_base_5721; 21562135Szh199473 cidp->mbuf_length = bge_mbuf_pool_len_5721; 21572135Szh199473 cidp->recv_slots = BGE_RECV_SLOTS_5721; 21582135Szh199473 cidp->bge_dma_rwctrl = bge_dma_rwctrl_5721; 21592135Szh199473 cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 21602135Szh199473 cidp->tx_rings = BGE_RECV_RINGS_MAX_5705; 21612135Szh199473 cidp->pci_type = BGE_PCI_E; 21622135Szh199473 cidp->statistic_type = BGE_STAT_REG; 21632135Szh199473 cidp->flags |= CHIP_FLAG_PARTIAL_CSUM; 21642135Szh199473 cidp->flags |= CHIP_FLAG_NO_JUMBO; 21652135Szh199473 cidp->msi_enabled = B_TRUE; 21662135Szh199473 dev_ok = B_TRUE; 21672135Szh199473 break; 21682135Szh199473 21691369Sdduvall } 21701369Sdduvall 21711369Sdduvall /* 21721369Sdduvall * Setup the default jumbo parameter. 21731369Sdduvall */ 21741369Sdduvall cidp->ethmax_size = ETHERMAX; 21751369Sdduvall cidp->snd_buff_size = BGE_SEND_BUFF_SIZE_DEFAULT; 21761908Sly149593 cidp->std_buf_size = BGE_STD_BUFF_SIZE; 21771369Sdduvall 21781369Sdduvall /* 21791369Sdduvall * If jumbo is enabled and this kind of chipset supports jumbo feature, 21801369Sdduvall * setup below jumbo specific parameters. 21811908Sly149593 * 21821908Sly149593 * For BCM5714/5715, there is only one standard receive ring. So the 21831908Sly149593 * std buffer size should be set to BGE_JUMBO_BUFF_SIZE when jumbo 21841908Sly149593 * feature is enabled. 21851369Sdduvall */ 21861369Sdduvall if (bge_jumbo_enable && 21871369Sdduvall !(cidp->flags & CHIP_FLAG_NO_JUMBO) && 21881369Sdduvall (cidp->default_mtu > BGE_DEFAULT_MTU) && 21891369Sdduvall (cidp->default_mtu <= BGE_MAXIMUM_MTU)) { 21901908Sly149593 if (DEVICE_5714_SERIES_CHIPSETS(bgep)) { 21911908Sly149593 cidp->mbuf_lo_water_rdma = 21921908Sly149593 RDMA_MBUF_LOWAT_5714_JUMBO; 21931908Sly149593 cidp->mbuf_lo_water_rmac = 21941908Sly149593 MAC_RX_MBUF_LOWAT_5714_JUMBO; 21951908Sly149593 cidp->mbuf_hi_water = MBUF_HIWAT_5714_JUMBO; 21961908Sly149593 cidp->jumbo_slots = 0; 21971908Sly149593 cidp->std_buf_size = BGE_JUMBO_BUFF_SIZE; 21981908Sly149593 } else { 21991908Sly149593 cidp->mbuf_lo_water_rdma = 22001908Sly149593 RDMA_MBUF_LOWAT_JUMBO; 22011908Sly149593 cidp->mbuf_lo_water_rmac = 22021908Sly149593 MAC_RX_MBUF_LOWAT_JUMBO; 22031908Sly149593 cidp->mbuf_hi_water = MBUF_HIWAT_JUMBO; 22041908Sly149593 cidp->jumbo_slots = BGE_JUMBO_SLOTS_USED; 22051908Sly149593 } 22061369Sdduvall cidp->recv_jumbo_size = BGE_JUMBO_BUFF_SIZE; 22071369Sdduvall cidp->snd_buff_size = BGE_SEND_BUFF_SIZE_JUMBO; 22081369Sdduvall cidp->ethmax_size = cidp->default_mtu + 22091369Sdduvall sizeof (struct ether_header); 22101369Sdduvall } 22111369Sdduvall 22121369Sdduvall /* 22131369Sdduvall * Identify the NV memory type: SEEPROM or Flash? 22141369Sdduvall */ 22151369Sdduvall cidp->nvtype = bge_nvmem_id(bgep); 22161369Sdduvall 22171369Sdduvall /* 22181369Sdduvall * Now, we want to check whether this device is part of a 22191369Sdduvall * supported subsystem (e.g., on the motherboard of a Sun 22201369Sdduvall * branded platform). 22211369Sdduvall * 22221369Sdduvall * Rule 1: If the Subsystem Vendor ID is "Sun", then it's OK ;-) 22231369Sdduvall */ 22241369Sdduvall if (cidp->subven == VENDOR_ID_SUN) 22251369Sdduvall sys_ok = B_TRUE; 22261369Sdduvall 22271369Sdduvall /* 22281369Sdduvall * Rule 2: If it's on the list on known subsystems, then it's OK. 22291369Sdduvall * Note: 0x14e41647 should *not* appear in the list, but the code 22301369Sdduvall * doesn't enforce that. 22311369Sdduvall */ 22321369Sdduvall err = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, bgep->devinfo, 22331369Sdduvall DDI_PROP_DONTPASS, knownids_propname, &ids, &i); 22341369Sdduvall if (err == DDI_PROP_SUCCESS) { 22351369Sdduvall /* 22361369Sdduvall * Got the list; scan for a matching subsystem vendor/device 22371369Sdduvall */ 22381369Sdduvall subid = (cidp->subven << 16) | cidp->subdev; 22391369Sdduvall while (i--) 22401369Sdduvall if (ids[i] == subid) 22411369Sdduvall sys_ok = B_TRUE; 22421369Sdduvall ddi_prop_free(ids); 22431369Sdduvall } 22441369Sdduvall 22451369Sdduvall /* 22461369Sdduvall * Rule 3: If it's a Taco/ENWS motherboard device, then it's OK 22471369Sdduvall * 22481369Sdduvall * Unfortunately, early SunBlade 1500s and 2500s didn't reprogram 22491369Sdduvall * the Subsystem Vendor ID, so it defaults to Broadcom. Therefore, 22501369Sdduvall * we have to check specially for the exact device paths to the 22511369Sdduvall * motherboard devices on those platforms ;-( 22521369Sdduvall * 22531369Sdduvall * Note: we can't just use the "supported-subsystems" mechanism 22541369Sdduvall * above, because the entry would have to be 0x14e41647 -- which 22551369Sdduvall * would then accept *any* plugin card that *didn't* contain a 22561369Sdduvall * (valid) SEEPROM ;-( 22571369Sdduvall */ 22581369Sdduvall sysname = ddi_node_name(ddi_root_node()); 22591369Sdduvall devname = ddi_pathname(bgep->devinfo, buf); 22601369Sdduvall ASSERT(strlen(devname) > 0); 22611369Sdduvall if (strcmp(sysname, "SUNW,Sun-Blade-1500") == 0) /* Taco */ 22621369Sdduvall if (strcmp(devname, "/pci@1f,700000/network@2") == 0) 22631369Sdduvall sys_ok = B_TRUE; 22641369Sdduvall if (strcmp(sysname, "SUNW,Sun-Blade-2500") == 0) /* ENWS */ 22651369Sdduvall if (strcmp(devname, "/pci@1c,600000/network@3") == 0) 22661369Sdduvall sys_ok = B_TRUE; 22671369Sdduvall 22681369Sdduvall /* 22691369Sdduvall * Now check what we've discovered: is this truly a supported 22701369Sdduvall * chip on (the motherboard of) a supported platform? 22711369Sdduvall * 22721369Sdduvall * Possible problems here: 22731369Sdduvall * 1) it's a completely unheard-of chip (e.g. 5761) 22741369Sdduvall * 2) it's a recognised but unsupported chip (e.g. 5701, 5703C-A0) 22751369Sdduvall * 3) it's a chip we would support if it were on the motherboard 22761369Sdduvall * of a Sun platform, but this one isn't ;-( 22771369Sdduvall */ 22781369Sdduvall if (cidp->chip_label == 0) 22791369Sdduvall bge_problem(bgep, 22801369Sdduvall "Device 'pci%04x,%04x' not recognized (%d?)", 22811369Sdduvall cidp->vendor, cidp->device, cidp->device); 22821369Sdduvall else if (!dev_ok) 22831369Sdduvall bge_problem(bgep, 22841369Sdduvall "Device 'pci%04x,%04x' (%d) revision %d not supported", 22851369Sdduvall cidp->vendor, cidp->device, cidp->chip_label, 22861369Sdduvall cidp->revision); 22871369Sdduvall #if BGE_DEBUGGING 22881369Sdduvall else if (!sys_ok) 22891369Sdduvall bge_problem(bgep, 22901369Sdduvall "%d-based subsystem 'pci%04x,%04x' not validated", 22911369Sdduvall cidp->chip_label, cidp->subven, cidp->subdev); 22921369Sdduvall #endif 22931369Sdduvall else 22941369Sdduvall cidp->flags |= CHIP_FLAG_SUPPORTED; 22951865Sdilpreet if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) 22961865Sdilpreet return (EIO); 22971865Sdilpreet return (0); 22981369Sdduvall } 22991369Sdduvall 23001369Sdduvall void 23011369Sdduvall bge_chip_msi_trig(bge_t *bgep) 23021369Sdduvall { 23031369Sdduvall uint32_t regval; 23041369Sdduvall 23051369Sdduvall regval = bgep->param_msi_cnt<<4; 23061369Sdduvall bge_reg_set32(bgep, HOST_COALESCE_MODE_REG, regval); 23071369Sdduvall BGE_DEBUG(("bge_chip_msi_trig:data = %d", regval)); 23081369Sdduvall } 23091369Sdduvall 23101369Sdduvall /* 23111369Sdduvall * Various registers that control the chip's internal engines (state 23121369Sdduvall * machines) have a <reset> and <enable> bits (fortunately, in the 23131369Sdduvall * same place in each such register :-). 23141369Sdduvall * 23151369Sdduvall * To reset the state machine, the <reset> bit must be written with 1; 23161369Sdduvall * it will then read back as 1 while the reset is in progress, but 23171369Sdduvall * self-clear to 0 when the reset completes. 23181369Sdduvall * 23191369Sdduvall * To enable a state machine, one must set the <enable> bit, which 23201369Sdduvall * will continue to read back as 0 until the state machine is running. 23211369Sdduvall * 23221369Sdduvall * To disable a state machine, the <enable> bit must be cleared, but 23231369Sdduvall * it will continue to read back as 1 until the state machine actually 23241369Sdduvall * stops. 23251369Sdduvall * 23261369Sdduvall * This routine implements polling for completion of a reset, enable 23271369Sdduvall * or disable operation, returning B_TRUE on success (bit reached the 23281369Sdduvall * required state) or B_FALSE on timeout (200*100us == 20ms). 23291369Sdduvall */ 23301369Sdduvall static boolean_t bge_chip_poll_engine(bge_t *bgep, bge_regno_t regno, 23311369Sdduvall uint32_t mask, uint32_t val); 23321369Sdduvall #pragma no_inline(bge_chip_poll_engine) 23331369Sdduvall 23341369Sdduvall static boolean_t 23351369Sdduvall bge_chip_poll_engine(bge_t *bgep, bge_regno_t regno, 23361369Sdduvall uint32_t mask, uint32_t val) 23371369Sdduvall { 23381369Sdduvall uint32_t regval; 23391369Sdduvall uint32_t n; 23401369Sdduvall 23411369Sdduvall BGE_TRACE(("bge_chip_poll_engine($%p, 0x%lx, 0x%x, 0x%x)", 23421369Sdduvall (void *)bgep, regno, mask, val)); 23431369Sdduvall 23441369Sdduvall for (n = 200; n; --n) { 23451369Sdduvall regval = bge_reg_get32(bgep, regno); 23461369Sdduvall if ((regval & mask) == val) 23471369Sdduvall return (B_TRUE); 23481369Sdduvall drv_usecwait(100); 23491369Sdduvall } 23501369Sdduvall 23511865Sdilpreet bge_fm_ereport(bgep, DDI_FM_DEVICE_NO_RESPONSE); 23521369Sdduvall return (B_FALSE); 23531369Sdduvall } 23541369Sdduvall 23551369Sdduvall /* 23561369Sdduvall * Various registers that control the chip's internal engines (state 23571369Sdduvall * machines) have a <reset> bit (fortunately, in the same place in 23581369Sdduvall * each such register :-). To reset the state machine, this bit must 23591369Sdduvall * be written with 1; it will then read back as 1 while the reset is 23601369Sdduvall * in progress, but self-clear to 0 when the reset completes. 23611369Sdduvall * 23621369Sdduvall * This code sets the bit, then polls for it to read back as zero. 23631369Sdduvall * The return value is B_TRUE on success (reset bit cleared itself), 23641369Sdduvall * or B_FALSE if the state machine didn't recover :( 23651369Sdduvall * 23661369Sdduvall * NOTE: the Core reset is similar to other resets, except that we 23671369Sdduvall * can't poll for completion, since the Core reset disables memory 23681369Sdduvall * access! So we just have to assume that it will all complete in 23691369Sdduvall * 100us. See Broadcom document 570X-PG102-R, p102, steps 4-5. 23701369Sdduvall */ 23711369Sdduvall static boolean_t bge_chip_reset_engine(bge_t *bgep, bge_regno_t regno); 23721369Sdduvall #pragma no_inline(bge_chip_reset_engine) 23731369Sdduvall 23741369Sdduvall static boolean_t 23751369Sdduvall bge_chip_reset_engine(bge_t *bgep, bge_regno_t regno) 23761369Sdduvall { 23771369Sdduvall uint32_t regval; 23781369Sdduvall uint32_t val32; 23791369Sdduvall 23801369Sdduvall regval = bge_reg_get32(bgep, regno); 23811369Sdduvall 23821369Sdduvall BGE_TRACE(("bge_chip_reset_engine($%p, 0x%lx)", 23831369Sdduvall (void *)bgep, regno)); 23841369Sdduvall BGE_DEBUG(("bge_chip_reset_engine: 0x%lx before reset = 0x%08x", 23851369Sdduvall regno, regval)); 23861369Sdduvall 23871369Sdduvall regval |= STATE_MACHINE_RESET_BIT; 23881369Sdduvall 23891369Sdduvall switch (regno) { 23901369Sdduvall case MISC_CONFIG_REG: 23911369Sdduvall /* 23921369Sdduvall * BCM5714/5721/5751 pcie chip special case. In order to avoid 23931369Sdduvall * resetting PCIE block and bringing PCIE link down, bit 29 23941369Sdduvall * in the register needs to be set first, and then set it again 23951369Sdduvall * while the reset bit is written. 23961369Sdduvall * See:P500 of 57xx-PG102-RDS.pdf. 23971369Sdduvall */ 23981369Sdduvall if (DEVICE_5705_SERIES_CHIPSETS(bgep)|| 23991369Sdduvall DEVICE_5721_SERIES_CHIPSETS(bgep)|| 24001369Sdduvall DEVICE_5714_SERIES_CHIPSETS(bgep)) { 24011369Sdduvall regval |= MISC_CONFIG_GPHY_POWERDOWN_OVERRIDE; 24021369Sdduvall if (bgep->chipid.pci_type == BGE_PCI_E) { 24031369Sdduvall if (bgep->chipid.asic_rev == 24041369Sdduvall MHCR_CHIP_REV_5751_A0 || 24051369Sdduvall bgep->chipid.asic_rev == 24061369Sdduvall MHCR_CHIP_REV_5721_A0) { 24071369Sdduvall val32 = bge_reg_get32(bgep, 24081369Sdduvall PHY_TEST_CTRL_REG); 24091369Sdduvall if (val32 == (PHY_PCIE_SCRAM_MODE | 24101369Sdduvall PHY_PCIE_LTASS_MODE)) 24111369Sdduvall bge_reg_put32(bgep, 24121369Sdduvall PHY_TEST_CTRL_REG, 24131369Sdduvall PHY_PCIE_SCRAM_MODE); 24141369Sdduvall val32 = pci_config_get32 24151369Sdduvall (bgep->cfg_handle, 24161369Sdduvall PCI_CONF_BGE_CLKCTL); 24171369Sdduvall val32 |= CLKCTL_PCIE_A0_FIX; 24181369Sdduvall pci_config_put32(bgep->cfg_handle, 24191369Sdduvall PCI_CONF_BGE_CLKCTL, val32); 24201369Sdduvall } 24211369Sdduvall bge_reg_set32(bgep, regno, 24221369Sdduvall MISC_CONFIG_GRC_RESET_DISABLE); 24231369Sdduvall regval |= MISC_CONFIG_GRC_RESET_DISABLE; 24241369Sdduvall } 24251369Sdduvall } 24261369Sdduvall 24271369Sdduvall /* 24281369Sdduvall * Special case - causes Core reset 24291369Sdduvall * 24301369Sdduvall * On SPARC v9 we want to ensure that we don't start 24311369Sdduvall * timing until the I/O access has actually reached 24321369Sdduvall * the chip, otherwise we might make the next access 24331369Sdduvall * too early. And we can't just force the write out 24341369Sdduvall * by following it with a read (even to config space) 24351369Sdduvall * because that would cause the fault we're trying 24361369Sdduvall * to avoid. Hence the need for membar_sync() here. 24371369Sdduvall */ 24381369Sdduvall ddi_put32(bgep->io_handle, PIO_ADDR(bgep, regno), regval); 24391369Sdduvall #ifdef __sparcv9 24401369Sdduvall membar_sync(); 24411369Sdduvall #endif /* __sparcv9 */ 24421369Sdduvall /* 24431369Sdduvall * On some platforms,system need about 300us for 24441369Sdduvall * link setup. 24451369Sdduvall */ 24461369Sdduvall drv_usecwait(300); 24471369Sdduvall 24481369Sdduvall if (bgep->chipid.pci_type == BGE_PCI_E) { 24491369Sdduvall /* PCI-E device need more reset time */ 24501369Sdduvall drv_usecwait(120000); 24511369Sdduvall 24521369Sdduvall /* Set PCIE max payload size and clear error status. */ 24532135Szh199473 if ((bgep->chipid.chip_label == 5721) || 24542135Szh199473 (bgep->chipid.chip_label == 5751) || 2455*2675Szh199473 (bgep->chipid.chip_label == 5752) || 24562135Szh199473 (bgep->chipid.chip_label == 5789)) { 24571369Sdduvall pci_config_put16(bgep->cfg_handle, 24581369Sdduvall PCI_CONF_DEV_CTRL, READ_REQ_SIZE_MAX); 24591369Sdduvall pci_config_put16(bgep->cfg_handle, 24601369Sdduvall PCI_CONF_DEV_STUS, DEVICE_ERROR_STUS); 24611369Sdduvall } 24621369Sdduvall } 24631369Sdduvall 24641369Sdduvall BGE_PCICHK(bgep); 24651369Sdduvall return (B_TRUE); 24661369Sdduvall 24671369Sdduvall default: 24681369Sdduvall bge_reg_put32(bgep, regno, regval); 24691369Sdduvall return (bge_chip_poll_engine(bgep, regno, 24701865Sdilpreet STATE_MACHINE_RESET_BIT, 0)); 24711369Sdduvall } 24721369Sdduvall } 24731369Sdduvall 24741369Sdduvall /* 24751369Sdduvall * Various registers that control the chip's internal engines (state 24761369Sdduvall * machines) have an <enable> bit (fortunately, in the same place in 24771369Sdduvall * each such register :-). To stop the state machine, this bit must 24781369Sdduvall * be written with 0, then polled to see when the state machine has 24791369Sdduvall * actually stopped. 24801369Sdduvall * 24811369Sdduvall * The return value is B_TRUE on success (enable bit cleared), or 24821369Sdduvall * B_FALSE if the state machine didn't stop :( 24831369Sdduvall */ 24841369Sdduvall static boolean_t bge_chip_disable_engine(bge_t *bgep, bge_regno_t regno, 24851369Sdduvall uint32_t morebits); 24861369Sdduvall #pragma no_inline(bge_chip_disable_engine) 24871369Sdduvall 24881369Sdduvall static boolean_t 24891369Sdduvall bge_chip_disable_engine(bge_t *bgep, bge_regno_t regno, uint32_t morebits) 24901369Sdduvall { 24911369Sdduvall uint32_t regval; 24921369Sdduvall 24931369Sdduvall BGE_TRACE(("bge_chip_disable_engine($%p, 0x%lx, 0x%x)", 24941369Sdduvall (void *)bgep, regno, morebits)); 24951369Sdduvall 24961369Sdduvall switch (regno) { 24971369Sdduvall case FTQ_RESET_REG: 24981369Sdduvall /* 24991369Sdduvall * Not quite like the others; it doesn't 25001369Sdduvall * have an <enable> bit, but instead we 25011369Sdduvall * have to set and then clear all the bits 25021369Sdduvall */ 25031369Sdduvall bge_reg_put32(bgep, regno, ~(uint32_t)0); 25041369Sdduvall drv_usecwait(100); 25051369Sdduvall bge_reg_put32(bgep, regno, 0); 25061369Sdduvall return (B_TRUE); 25071369Sdduvall 25081369Sdduvall default: 25091369Sdduvall regval = bge_reg_get32(bgep, regno); 25101369Sdduvall regval &= ~STATE_MACHINE_ENABLE_BIT; 25111369Sdduvall regval &= ~morebits; 25121369Sdduvall bge_reg_put32(bgep, regno, regval); 25131369Sdduvall return (bge_chip_poll_engine(bgep, regno, 25141865Sdilpreet STATE_MACHINE_ENABLE_BIT, 0)); 25151369Sdduvall } 25161369Sdduvall } 25171369Sdduvall 25181369Sdduvall /* 25191369Sdduvall * Various registers that control the chip's internal engines (state 25201369Sdduvall * machines) have an <enable> bit (fortunately, in the same place in 25211369Sdduvall * each such register :-). To start the state machine, this bit must 25221369Sdduvall * be written with 1, then polled to see when the state machine has 25231369Sdduvall * actually started. 25241369Sdduvall * 25251369Sdduvall * The return value is B_TRUE on success (enable bit set), or 25261369Sdduvall * B_FALSE if the state machine didn't start :( 25271369Sdduvall */ 25281369Sdduvall static boolean_t bge_chip_enable_engine(bge_t *bgep, bge_regno_t regno, 25291369Sdduvall uint32_t morebits); 25301369Sdduvall #pragma no_inline(bge_chip_enable_engine) 25311369Sdduvall 25321369Sdduvall static boolean_t 25331369Sdduvall bge_chip_enable_engine(bge_t *bgep, bge_regno_t regno, uint32_t morebits) 25341369Sdduvall { 25351369Sdduvall uint32_t regval; 25361369Sdduvall 25371369Sdduvall BGE_TRACE(("bge_chip_enable_engine($%p, 0x%lx, 0x%x)", 25381369Sdduvall (void *)bgep, regno, morebits)); 25391369Sdduvall 25401369Sdduvall switch (regno) { 25411369Sdduvall case FTQ_RESET_REG: 25421369Sdduvall /* 25431369Sdduvall * Not quite like the others; it doesn't 25441369Sdduvall * have an <enable> bit, but instead we 25451369Sdduvall * have to set and then clear all the bits 25461369Sdduvall */ 25471369Sdduvall bge_reg_put32(bgep, regno, ~(uint32_t)0); 25481369Sdduvall drv_usecwait(100); 25491369Sdduvall bge_reg_put32(bgep, regno, 0); 25501369Sdduvall return (B_TRUE); 25511369Sdduvall 25521369Sdduvall default: 25531369Sdduvall regval = bge_reg_get32(bgep, regno); 25541369Sdduvall regval |= STATE_MACHINE_ENABLE_BIT; 25551369Sdduvall regval |= morebits; 25561369Sdduvall bge_reg_put32(bgep, regno, regval); 25571369Sdduvall return (bge_chip_poll_engine(bgep, regno, 25581865Sdilpreet STATE_MACHINE_ENABLE_BIT, STATE_MACHINE_ENABLE_BIT)); 25591369Sdduvall } 25601369Sdduvall } 25611369Sdduvall 25621369Sdduvall /* 25631369Sdduvall * Reprogram the Ethernet, Transmit, and Receive MAC 25641369Sdduvall * modes to match the param_* variables 25651369Sdduvall */ 25661369Sdduvall static void bge_sync_mac_modes(bge_t *bgep); 25671369Sdduvall #pragma no_inline(bge_sync_mac_modes) 25681369Sdduvall 25691369Sdduvall static void 25701369Sdduvall bge_sync_mac_modes(bge_t *bgep) 25711369Sdduvall { 25721369Sdduvall uint32_t macmode; 25731369Sdduvall uint32_t regval; 25741369Sdduvall 25751369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 25761369Sdduvall 25771369Sdduvall /* 25781369Sdduvall * Reprogram the Ethernet MAC mode ... 25791369Sdduvall */ 25801369Sdduvall macmode = regval = bge_reg_get32(bgep, ETHERNET_MAC_MODE_REG); 25811369Sdduvall if ((bgep->chipid.flags & CHIP_FLAG_SERDES) && 25821369Sdduvall (bgep->param_loop_mode != BGE_LOOP_INTERNAL_MAC)) 25831369Sdduvall macmode &= ~ETHERNET_MODE_LINK_POLARITY; 25841369Sdduvall else 25851369Sdduvall macmode |= ETHERNET_MODE_LINK_POLARITY; 25861369Sdduvall macmode &= ~ETHERNET_MODE_PORTMODE_MASK; 25871369Sdduvall if ((bgep->chipid.flags & CHIP_FLAG_SERDES) && 25881369Sdduvall (bgep->param_loop_mode != BGE_LOOP_INTERNAL_MAC)) 25891369Sdduvall macmode |= ETHERNET_MODE_PORTMODE_TBI; 25901369Sdduvall else if (bgep->param_link_speed == 10 || bgep->param_link_speed == 100) 25911369Sdduvall macmode |= ETHERNET_MODE_PORTMODE_MII; 25921369Sdduvall else 25931369Sdduvall macmode |= ETHERNET_MODE_PORTMODE_GMII; 25941369Sdduvall if (bgep->param_link_duplex == LINK_DUPLEX_HALF) 25951369Sdduvall macmode |= ETHERNET_MODE_HALF_DUPLEX; 25961369Sdduvall else 25971369Sdduvall macmode &= ~ETHERNET_MODE_HALF_DUPLEX; 25981369Sdduvall if (bgep->param_loop_mode == BGE_LOOP_INTERNAL_MAC) 25991369Sdduvall macmode |= ETHERNET_MODE_MAC_LOOPBACK; 26001369Sdduvall else 26011369Sdduvall macmode &= ~ETHERNET_MODE_MAC_LOOPBACK; 26021369Sdduvall bge_reg_put32(bgep, ETHERNET_MAC_MODE_REG, macmode); 26031369Sdduvall BGE_DEBUG(("bge_sync_mac_modes($%p) Ethernet MAC mode 0x%x => 0x%x", 26041369Sdduvall (void *)bgep, regval, macmode)); 26051369Sdduvall 26061369Sdduvall /* 26071369Sdduvall * ... the Transmit MAC mode ... 26081369Sdduvall */ 26091369Sdduvall macmode = regval = bge_reg_get32(bgep, TRANSMIT_MAC_MODE_REG); 26101369Sdduvall if (bgep->param_link_tx_pause) 26111369Sdduvall macmode |= TRANSMIT_MODE_FLOW_CONTROL; 26121369Sdduvall else 26131369Sdduvall macmode &= ~TRANSMIT_MODE_FLOW_CONTROL; 26141369Sdduvall bge_reg_put32(bgep, TRANSMIT_MAC_MODE_REG, macmode); 26151369Sdduvall BGE_DEBUG(("bge_sync_mac_modes($%p) Transmit MAC mode 0x%x => 0x%x", 26161369Sdduvall (void *)bgep, regval, macmode)); 26171369Sdduvall 26181369Sdduvall /* 26191369Sdduvall * ... and the Receive MAC mode 26201369Sdduvall */ 26211369Sdduvall macmode = regval = bge_reg_get32(bgep, RECEIVE_MAC_MODE_REG); 26221369Sdduvall if (bgep->param_link_rx_pause) 26231369Sdduvall macmode |= RECEIVE_MODE_FLOW_CONTROL; 26241369Sdduvall else 26251369Sdduvall macmode &= ~RECEIVE_MODE_FLOW_CONTROL; 26261369Sdduvall bge_reg_put32(bgep, RECEIVE_MAC_MODE_REG, macmode); 26271369Sdduvall BGE_DEBUG(("bge_sync_mac_modes($%p) Receive MAC mode 0x%x => 0x%x", 26281369Sdduvall (void *)bgep, regval, macmode)); 26291369Sdduvall } 26301369Sdduvall 26311369Sdduvall /* 26321369Sdduvall * bge_chip_sync() -- program the chip with the unicast MAC address, 26331369Sdduvall * the multicast hash table, the required level of promiscuity, and 26341369Sdduvall * the current loopback mode ... 26351369Sdduvall */ 26361408Srandyf #ifdef BGE_IPMI_ASF 26371865Sdilpreet int bge_chip_sync(bge_t *bgep, boolean_t asf_keeplive); 26381408Srandyf #else 26391865Sdilpreet int bge_chip_sync(bge_t *bgep); 26401408Srandyf #endif 26411369Sdduvall #pragma no_inline(bge_chip_sync) 26421369Sdduvall 26431865Sdilpreet int 26441408Srandyf #ifdef BGE_IPMI_ASF 26451408Srandyf bge_chip_sync(bge_t *bgep, boolean_t asf_keeplive) 26461408Srandyf #else 26471369Sdduvall bge_chip_sync(bge_t *bgep) 26481408Srandyf #endif 26491369Sdduvall { 26501369Sdduvall void (*opfn)(bge_t *bgep, bge_regno_t reg, uint32_t bits); 26511369Sdduvall boolean_t promisc; 26521369Sdduvall uint64_t macaddr; 26531369Sdduvall uint32_t fill; 26542331Skrgopi int i, j; 26551865Sdilpreet int retval = DDI_SUCCESS; 26561369Sdduvall 26571369Sdduvall BGE_TRACE(("bge_chip_sync($%p)", 26581369Sdduvall (void *)bgep)); 26591369Sdduvall 26601369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 26611369Sdduvall 26621369Sdduvall promisc = B_FALSE; 26631369Sdduvall fill = ~(uint32_t)0; 26641369Sdduvall 26651369Sdduvall if (bgep->promisc) 26661369Sdduvall promisc = B_TRUE; 26671369Sdduvall else 26681369Sdduvall fill = (uint32_t)0; 26691369Sdduvall 26701369Sdduvall /* 26711369Sdduvall * If the TX/RX MAC engines are already running, we should stop 26721369Sdduvall * them (and reset the RX engine) before changing the parameters. 26731369Sdduvall * If they're not running, this will have no effect ... 26741369Sdduvall * 26751369Sdduvall * NOTE: this is currently disabled by default because stopping 26761369Sdduvall * and restarting the Tx engine may cause an outgoing packet in 26771369Sdduvall * transit to be truncated. Also, stopping and restarting the 26781369Sdduvall * Rx engine seems to not work correctly on the 5705. Testing 26791369Sdduvall * has not (yet!) revealed any problems with NOT stopping and 26801369Sdduvall * restarting these engines (and Broadcom say their drivers don't 26811369Sdduvall * do this), but if it is found to cause problems, this variable 26821369Sdduvall * can be patched to re-enable the old behaviour ... 26831369Sdduvall */ 26841369Sdduvall if (bge_stop_start_on_sync) { 26851408Srandyf #ifdef BGE_IPMI_ASF 26861865Sdilpreet if (!bgep->asf_enabled) { 26871865Sdilpreet if (!bge_chip_disable_engine(bgep, 26881865Sdilpreet RECEIVE_MAC_MODE_REG, RECEIVE_MODE_KEEP_VLAN_TAG)) 26891865Sdilpreet retval = DDI_FAILURE; 26901408Srandyf } else { 26911865Sdilpreet if (!bge_chip_disable_engine(bgep, 26921865Sdilpreet RECEIVE_MAC_MODE_REG, 0)) 26931865Sdilpreet retval = DDI_FAILURE; 26941408Srandyf } 26951408Srandyf #else 26961865Sdilpreet if (!bge_chip_disable_engine(bgep, RECEIVE_MAC_MODE_REG, 26971865Sdilpreet RECEIVE_MODE_KEEP_VLAN_TAG)) 26981865Sdilpreet retval = DDI_FAILURE; 26991408Srandyf #endif 27001865Sdilpreet if (!bge_chip_disable_engine(bgep, TRANSMIT_MAC_MODE_REG, 0)) 27011865Sdilpreet retval = DDI_FAILURE; 27021865Sdilpreet if (!bge_chip_reset_engine(bgep, RECEIVE_MAC_MODE_REG)) 27031865Sdilpreet retval = DDI_FAILURE; 27041369Sdduvall } 27051369Sdduvall 27061369Sdduvall /* 27071369Sdduvall * Reprogram the hashed multicast address table ... 27081369Sdduvall */ 27091369Sdduvall for (i = 0; i < BGE_HASH_TABLE_SIZE/32; ++i) 27101369Sdduvall bge_reg_put32(bgep, MAC_HASH_REG(i), 27111369Sdduvall bgep->mcast_hash[i] | fill); 27121369Sdduvall 27131408Srandyf #ifdef BGE_IPMI_ASF 27141408Srandyf if (!bgep->asf_enabled || !asf_keeplive) { 27151408Srandyf #endif 27161408Srandyf /* 27172331Skrgopi * Transform the MAC address(es) from host to chip format, then 27181408Srandyf * reprogram the transmit random backoff seed and the unicast 27191408Srandyf * MAC address(es) ... 27201408Srandyf */ 27212331Skrgopi for (j = 0; j < MAC_ADDRESS_REGS_MAX; j++) { 27222331Skrgopi for (i = 0, fill = 0, macaddr = 0ull; 27232331Skrgopi i < ETHERADDRL; ++i) { 27242331Skrgopi macaddr <<= 8; 27252331Skrgopi macaddr |= bgep->curr_addr[j].addr[i]; 27262331Skrgopi fill += bgep->curr_addr[j].addr[i]; 27272331Skrgopi } 27282331Skrgopi bge_reg_put32(bgep, MAC_TX_RANDOM_BACKOFF_REG, fill); 27292331Skrgopi bge_reg_put64(bgep, MAC_ADDRESS_REG(j), macaddr); 27301408Srandyf } 27311408Srandyf 27321408Srandyf BGE_DEBUG(("bge_chip_sync($%p) setting MAC address %012llx", 27331408Srandyf (void *)bgep, macaddr)); 27341408Srandyf #ifdef BGE_IPMI_ASF 27351369Sdduvall } 27361408Srandyf #endif 27371369Sdduvall 27381369Sdduvall /* 27391369Sdduvall * Set or clear the PROMISCUOUS mode bit 27401369Sdduvall */ 27411369Sdduvall opfn = promisc ? bge_reg_set32 : bge_reg_clr32; 27421369Sdduvall (*opfn)(bgep, RECEIVE_MAC_MODE_REG, RECEIVE_MODE_PROMISCUOUS); 27431369Sdduvall 27441369Sdduvall /* 27451369Sdduvall * Sync the rest of the MAC modes too ... 27461369Sdduvall */ 27471369Sdduvall bge_sync_mac_modes(bgep); 27481369Sdduvall 27491369Sdduvall /* 27501369Sdduvall * Restart RX/TX MAC engines if required ... 27511369Sdduvall */ 27521369Sdduvall if (bgep->bge_chip_state == BGE_CHIP_RUNNING) { 27531865Sdilpreet if (!bge_chip_enable_engine(bgep, TRANSMIT_MAC_MODE_REG, 0)) 27541865Sdilpreet retval = DDI_FAILURE; 27551408Srandyf #ifdef BGE_IPMI_ASF 27561865Sdilpreet if (!bgep->asf_enabled) { 27571865Sdilpreet if (!bge_chip_enable_engine(bgep, 27581865Sdilpreet RECEIVE_MAC_MODE_REG, RECEIVE_MODE_KEEP_VLAN_TAG)) 27591865Sdilpreet retval = DDI_FAILURE; 27601408Srandyf } else { 27611865Sdilpreet if (!bge_chip_enable_engine(bgep, 27621865Sdilpreet RECEIVE_MAC_MODE_REG, 0)) 27631865Sdilpreet retval = DDI_FAILURE; 27641408Srandyf } 27651408Srandyf #else 27661865Sdilpreet if (!bge_chip_enable_engine(bgep, RECEIVE_MAC_MODE_REG, 27671865Sdilpreet RECEIVE_MODE_KEEP_VLAN_TAG)) 27681865Sdilpreet retval = DDI_FAILURE; 27691408Srandyf #endif 27701369Sdduvall } 27711865Sdilpreet return (retval); 27721369Sdduvall } 27731369Sdduvall 27741369Sdduvall /* 27751369Sdduvall * This array defines the sequence of state machine control registers 27761369Sdduvall * in which the <enable> bit must be cleared to bring the chip to a 27771369Sdduvall * clean stop. Taken from Broadcom document 570X-PG102-R, p116. 27781369Sdduvall */ 27791369Sdduvall static bge_regno_t shutdown_engine_regs[] = { 27801369Sdduvall RECEIVE_MAC_MODE_REG, 27811369Sdduvall RCV_BD_INITIATOR_MODE_REG, 27821369Sdduvall RCV_LIST_PLACEMENT_MODE_REG, 27831369Sdduvall RCV_LIST_SELECTOR_MODE_REG, /* BCM5704 series only */ 27841369Sdduvall RCV_DATA_BD_INITIATOR_MODE_REG, 27851369Sdduvall RCV_DATA_COMPLETION_MODE_REG, 27861369Sdduvall RCV_BD_COMPLETION_MODE_REG, 27871369Sdduvall 27881369Sdduvall SEND_BD_SELECTOR_MODE_REG, 27891369Sdduvall SEND_BD_INITIATOR_MODE_REG, 27901369Sdduvall SEND_DATA_INITIATOR_MODE_REG, 27911369Sdduvall READ_DMA_MODE_REG, 27921369Sdduvall SEND_DATA_COMPLETION_MODE_REG, 27931369Sdduvall DMA_COMPLETION_MODE_REG, /* BCM5704 series only */ 27941369Sdduvall SEND_BD_COMPLETION_MODE_REG, 27951369Sdduvall TRANSMIT_MAC_MODE_REG, 27961369Sdduvall 27971369Sdduvall HOST_COALESCE_MODE_REG, 27981369Sdduvall WRITE_DMA_MODE_REG, 27991369Sdduvall MBUF_CLUSTER_FREE_MODE_REG, /* BCM5704 series only */ 28001369Sdduvall FTQ_RESET_REG, /* special - see code */ 28011369Sdduvall BUFFER_MANAGER_MODE_REG, /* BCM5704 series only */ 28021369Sdduvall MEMORY_ARBITER_MODE_REG, /* BCM5704 series only */ 28031369Sdduvall BGE_REGNO_NONE /* terminator */ 28041369Sdduvall }; 28051369Sdduvall 28061369Sdduvall /* 28071369Sdduvall * bge_chip_stop() -- stop all chip processing 28081369Sdduvall * 28091369Sdduvall * If the <fault> parameter is B_TRUE, we're stopping the chip because 28101369Sdduvall * we've detected a problem internally; otherwise, this is a normal 28111369Sdduvall * (clean) stop (at user request i.e. the last STREAM has been closed). 28121369Sdduvall */ 28131369Sdduvall void bge_chip_stop(bge_t *bgep, boolean_t fault); 28141369Sdduvall #pragma no_inline(bge_chip_stop) 28151369Sdduvall 28161369Sdduvall void 28171369Sdduvall bge_chip_stop(bge_t *bgep, boolean_t fault) 28181369Sdduvall { 28191369Sdduvall bge_regno_t regno; 28201369Sdduvall bge_regno_t *rbp; 28211369Sdduvall boolean_t ok; 28221369Sdduvall 28231369Sdduvall BGE_TRACE(("bge_chip_stop($%p)", 28241369Sdduvall (void *)bgep)); 28251369Sdduvall 28261369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 28271369Sdduvall 28281369Sdduvall rbp = shutdown_engine_regs; 28291369Sdduvall /* 28301369Sdduvall * When driver try to shutdown the BCM5705/5788/5721/5751/ 28311369Sdduvall * 5752/5714 and 5715 chipsets,the buffer manager and the mem 28321369Sdduvall * -ory arbiter should not be disabled. 28331369Sdduvall */ 28341369Sdduvall for (ok = B_TRUE; (regno = *rbp) != BGE_REGNO_NONE; ++rbp) { 28351369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) 28361369Sdduvall ok &= bge_chip_disable_engine(bgep, regno, 0); 28371369Sdduvall else if ((regno != RCV_LIST_SELECTOR_MODE_REG) && 28381369Sdduvall (regno != DMA_COMPLETION_MODE_REG) && 28391369Sdduvall (regno != MBUF_CLUSTER_FREE_MODE_REG)&& 28401369Sdduvall (regno != BUFFER_MANAGER_MODE_REG) && 28411369Sdduvall (regno != MEMORY_ARBITER_MODE_REG)) 28421369Sdduvall ok &= bge_chip_disable_engine(bgep, 28431369Sdduvall regno, 0); 28441369Sdduvall } 28451369Sdduvall 28461865Sdilpreet if (!ok && !fault) 28471865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_UNAFFECTED); 28481865Sdilpreet 28491369Sdduvall /* 28501369Sdduvall * Finally, disable (all) MAC events & clear the MAC status 28511369Sdduvall */ 28521369Sdduvall bge_reg_put32(bgep, ETHERNET_MAC_EVENT_ENABLE_REG, 0); 28531369Sdduvall bge_reg_put32(bgep, ETHERNET_MAC_STATUS_REG, ~0); 28541369Sdduvall 28551369Sdduvall /* 28561865Sdilpreet * if we're stopping the chip because of a detected fault then do 28571865Sdilpreet * appropriate actions 28581369Sdduvall */ 28591865Sdilpreet if (fault) { 28601865Sdilpreet if (bgep->bge_chip_state != BGE_CHIP_FAULT) { 28611865Sdilpreet bgep->bge_chip_state = BGE_CHIP_FAULT; 28621865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_LOST); 28631865Sdilpreet if (bgep->bge_dma_error) { 28641865Sdilpreet /* 28651865Sdilpreet * need to free buffers in case the fault was 28661865Sdilpreet * due to a memory error in a buffer - got to 28671865Sdilpreet * do a fair bit of tidying first 28681865Sdilpreet */ 28691865Sdilpreet if (bgep->progress & PROGRESS_KSTATS) { 28701865Sdilpreet bge_fini_kstats(bgep); 28711865Sdilpreet bgep->progress &= ~PROGRESS_KSTATS; 28721865Sdilpreet } 28731865Sdilpreet if (bgep->progress & PROGRESS_INTR) { 28741865Sdilpreet bge_intr_disable(bgep); 28751865Sdilpreet rw_enter(bgep->errlock, RW_WRITER); 28761865Sdilpreet bge_fini_rings(bgep); 28771865Sdilpreet rw_exit(bgep->errlock); 28781865Sdilpreet bgep->progress &= ~PROGRESS_INTR; 28791865Sdilpreet } 28801865Sdilpreet if (bgep->progress & PROGRESS_BUFS) { 28811865Sdilpreet bge_free_bufs(bgep); 28821865Sdilpreet bgep->progress &= ~PROGRESS_BUFS; 28831865Sdilpreet } 28841865Sdilpreet bgep->bge_dma_error = B_FALSE; 28851865Sdilpreet } 28861865Sdilpreet } 28871865Sdilpreet } else 28881369Sdduvall bgep->bge_chip_state = BGE_CHIP_STOPPED; 28891369Sdduvall } 28901369Sdduvall 28911369Sdduvall /* 28921369Sdduvall * Poll for completion of chip's ROM firmware; also, at least on the 28931369Sdduvall * first time through, find and return the hardware MAC address, if any. 28941369Sdduvall */ 28951369Sdduvall static uint64_t bge_poll_firmware(bge_t *bgep); 28961369Sdduvall #pragma no_inline(bge_poll_firmware) 28971369Sdduvall 28981369Sdduvall static uint64_t 28991369Sdduvall bge_poll_firmware(bge_t *bgep) 29001369Sdduvall { 29011369Sdduvall uint64_t magic; 29021369Sdduvall uint64_t mac; 29031369Sdduvall uint32_t gen; 29041369Sdduvall uint32_t i; 29051369Sdduvall 29061369Sdduvall /* 29071369Sdduvall * Step 19: poll for firmware completion (GENCOMM port set 29081369Sdduvall * to the ones complement of T3_MAGIC_NUMBER). 29091369Sdduvall * 29101369Sdduvall * While we're at it, we also read the MAC address register; 29112135Szh199473 * at some stage the firmware will load this with the 29121369Sdduvall * factory-set value. 29131369Sdduvall * 29141369Sdduvall * When both the magic number and the MAC address are set, 29151369Sdduvall * we're done; but we impose a time limit of one second 29161369Sdduvall * (1000*1000us) in case the firmware fails in some fashion 29171369Sdduvall * or the SEEPROM that provides that MAC address isn't fitted. 29181369Sdduvall * 29191369Sdduvall * After the first time through (chip state != INITIAL), we 29201369Sdduvall * don't need the MAC address to be set (we've already got it 29211369Sdduvall * or not, from the first time), so we don't wait for it, but 29221369Sdduvall * we still have to wait for the T3_MAGIC_NUMBER. 29231369Sdduvall * 29241369Sdduvall * Note: the magic number is only a 32-bit quantity, but the NIC 29251369Sdduvall * memory is 64-bit (and big-endian) internally. Addressing the 29261369Sdduvall * GENCOMM word as "the upper half of a 64-bit quantity" makes 29271369Sdduvall * it work correctly on both big- and little-endian hosts. 29281369Sdduvall */ 29291369Sdduvall for (i = 0; i < 1000; ++i) { 29301369Sdduvall drv_usecwait(1000); 29311369Sdduvall gen = bge_nic_get64(bgep, NIC_MEM_GENCOMM) >> 32; 29321369Sdduvall mac = bge_reg_get64(bgep, MAC_ADDRESS_REG(0)); 29331408Srandyf #ifdef BGE_IPMI_ASF 29341408Srandyf if (!bgep->asf_enabled) { 29351408Srandyf #endif 29361408Srandyf if (gen != ~T3_MAGIC_NUMBER) 29371408Srandyf continue; 29381408Srandyf #ifdef BGE_IPMI_ASF 29391408Srandyf } 29401408Srandyf #endif 29411369Sdduvall if (mac != 0ULL) 29421369Sdduvall break; 29431369Sdduvall if (bgep->bge_chip_state != BGE_CHIP_INITIAL) 29441369Sdduvall break; 29451369Sdduvall } 29461369Sdduvall 29471369Sdduvall magic = bge_nic_get64(bgep, NIC_MEM_GENCOMM); 29481369Sdduvall BGE_DEBUG(("bge_poll_firmware($%p): PXE magic 0x%x after %d loops", 29491369Sdduvall (void *)bgep, gen, i)); 29501369Sdduvall BGE_DEBUG(("bge_poll_firmware: MAC %016llx, GENCOMM %016llx", 29511369Sdduvall mac, magic)); 29521369Sdduvall 29531369Sdduvall return (mac); 29541369Sdduvall } 29551369Sdduvall 29561408Srandyf #ifdef BGE_IPMI_ASF 29571865Sdilpreet int bge_chip_reset(bge_t *bgep, boolean_t enable_dma, uint_t asf_mode); 29581408Srandyf #else 29591865Sdilpreet int bge_chip_reset(bge_t *bgep, boolean_t enable_dma); 29601408Srandyf #endif 29611369Sdduvall #pragma no_inline(bge_chip_reset) 29621369Sdduvall 29631865Sdilpreet int 29641408Srandyf #ifdef BGE_IPMI_ASF 29651408Srandyf bge_chip_reset(bge_t *bgep, boolean_t enable_dma, uint_t asf_mode) 29661408Srandyf #else 29671369Sdduvall bge_chip_reset(bge_t *bgep, boolean_t enable_dma) 29681408Srandyf #endif 29691369Sdduvall { 29701369Sdduvall chip_id_t chipid; 29711369Sdduvall uint64_t mac; 29721908Sly149593 uint64_t magic; 29731369Sdduvall uint32_t modeflags; 29741369Sdduvall uint32_t mhcr; 29751369Sdduvall uint32_t sx0; 29761369Sdduvall uint32_t i; 29771408Srandyf #ifdef BGE_IPMI_ASF 29781408Srandyf uint32_t mailbox; 29791408Srandyf #endif 29801865Sdilpreet int retval = DDI_SUCCESS; 29811369Sdduvall 29821369Sdduvall BGE_TRACE(("bge_chip_reset($%p, %d)", 29831369Sdduvall (void *)bgep, enable_dma)); 29841369Sdduvall 29851369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 29861369Sdduvall 29871369Sdduvall BGE_DEBUG(("bge_chip_reset($%p, %d): current state is %d", 29881369Sdduvall (void *)bgep, enable_dma, bgep->bge_chip_state)); 29891369Sdduvall 29901369Sdduvall /* 29911369Sdduvall * Do we need to stop the chip cleanly before resetting? 29921369Sdduvall */ 29931369Sdduvall switch (bgep->bge_chip_state) { 29941369Sdduvall default: 29951369Sdduvall _NOTE(NOTREACHED) 29961865Sdilpreet return (DDI_FAILURE); 29971369Sdduvall 29981369Sdduvall case BGE_CHIP_INITIAL: 29991369Sdduvall case BGE_CHIP_STOPPED: 30001369Sdduvall case BGE_CHIP_RESET: 30011369Sdduvall break; 30021369Sdduvall 30031369Sdduvall case BGE_CHIP_RUNNING: 30041369Sdduvall case BGE_CHIP_ERROR: 30051369Sdduvall case BGE_CHIP_FAULT: 30061369Sdduvall bge_chip_stop(bgep, B_FALSE); 30071369Sdduvall break; 30081369Sdduvall } 30091369Sdduvall 30101408Srandyf #ifdef BGE_IPMI_ASF 30111408Srandyf if (bgep->asf_enabled) { 30121408Srandyf if (asf_mode == ASF_MODE_INIT) { 30131408Srandyf bge_asf_pre_reset_operations(bgep, BGE_INIT_RESET); 30141408Srandyf } else if (asf_mode == ASF_MODE_SHUTDOWN) { 30151408Srandyf bge_asf_pre_reset_operations(bgep, BGE_SHUTDOWN_RESET); 30161408Srandyf } 30171408Srandyf } 30181408Srandyf #endif 30191369Sdduvall /* 30201369Sdduvall * Adapted from Broadcom document 570X-PG102-R, pp 102-116. 30211369Sdduvall * Updated to reflect Broadcom document 570X-PG104-R, pp 146-159. 30221369Sdduvall * 30231369Sdduvall * Before reset Core clock,it is 30241369Sdduvall * also required to initialize the Memory Arbiter as specified in step9 30251369Sdduvall * and Misc Host Control Register as specified in step-13 30261369Sdduvall * Step 4-5: reset Core clock & wait for completion 30271369Sdduvall * Steps 6-8: are done by bge_chip_cfg_init() 30281908Sly149593 * put the T3_MAGIC_NUMBER into the GENCOMM port before reset 30291369Sdduvall */ 30301865Sdilpreet if (!bge_chip_enable_engine(bgep, MEMORY_ARBITER_MODE_REG, 0)) 30311865Sdilpreet retval = DDI_FAILURE; 30321369Sdduvall 30331369Sdduvall mhcr = MHCR_ENABLE_INDIRECT_ACCESS | 30341369Sdduvall MHCR_ENABLE_TAGGED_STATUS_MODE | 30351369Sdduvall MHCR_MASK_INTERRUPT_MODE | 30361369Sdduvall MHCR_MASK_PCI_INT_OUTPUT | 30371369Sdduvall MHCR_CLEAR_INTERRUPT_INTA; 30381369Sdduvall #ifdef _BIG_ENDIAN 30391369Sdduvall mhcr |= MHCR_ENABLE_ENDIAN_WORD_SWAP | MHCR_ENABLE_ENDIAN_BYTE_SWAP; 30401369Sdduvall #endif /* _BIG_ENDIAN */ 30411369Sdduvall pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_MHCR, mhcr); 30421408Srandyf #ifdef BGE_IPMI_ASF 30431408Srandyf if (bgep->asf_enabled) 30441408Srandyf bgep->asf_wordswapped = B_FALSE; 30451408Srandyf #endif 3046*2675Szh199473 /* 3047*2675Szh199473 * NVRAM Corruption Workaround 3048*2675Szh199473 */ 3049*2675Szh199473 for (i = 0; i < 600; i++) 3050*2675Szh199473 if (bge_nvmem_acquire(bgep) == 0) 3051*2675Szh199473 break; 3052*2675Szh199473 if (i >= 600) 3053*2675Szh199473 BGE_DEBUG(("%s: fail to acquire nvram lock", 3054*2675Szh199473 bgep->ifname)); 3055*2675Szh199473 30561908Sly149593 #ifdef BGE_IPMI_ASF 30571908Sly149593 if (!bgep->asf_enabled) { 30581908Sly149593 #endif 30591908Sly149593 magic = (uint64_t)T3_MAGIC_NUMBER << 32; 30601908Sly149593 bge_nic_put64(bgep, NIC_MEM_GENCOMM, magic); 30611908Sly149593 #ifdef BGE_IPMI_ASF 30621908Sly149593 } 30631908Sly149593 #endif 30641908Sly149593 30651865Sdilpreet if (!bge_chip_reset_engine(bgep, MISC_CONFIG_REG)) 30661865Sdilpreet retval = DDI_FAILURE; 30671369Sdduvall bge_chip_cfg_init(bgep, &chipid, enable_dma); 30681369Sdduvall 30691369Sdduvall /* 30701369Sdduvall * Step 8a: This may belong elsewhere, but BCM5721 needs 30711369Sdduvall * a bit set to avoid a fifo overflow/underflow bug. 30721369Sdduvall */ 30732135Szh199473 if ((bgep->chipid.chip_label == 5721) || 30742135Szh199473 (bgep->chipid.chip_label == 5751) || 3075*2675Szh199473 (bgep->chipid.chip_label == 5752) || 30762135Szh199473 (bgep->chipid.chip_label == 5789)) 30771369Sdduvall bge_reg_set32(bgep, TLP_CONTROL_REG, TLP_DATA_FIFO_PROTECT); 30781369Sdduvall 30791369Sdduvall 30801369Sdduvall /* 30811369Sdduvall * Step 9: enable MAC memory arbiter,bit30 and bit31 of 5714/5715 should 30821369Sdduvall * not be changed. 30831369Sdduvall */ 30841865Sdilpreet if (!bge_chip_enable_engine(bgep, MEMORY_ARBITER_MODE_REG, 0)) 30851865Sdilpreet retval = DDI_FAILURE; 30861369Sdduvall 30871369Sdduvall /* 30881369Sdduvall * Steps 10-11: configure PIO endianness options and 30891369Sdduvall * enable indirect register access -- already done 30901369Sdduvall * Steps 12-13: enable writing to the PCI state & clock 30911369Sdduvall * control registers -- not required; we aren't going to 30921369Sdduvall * use those features. 30931369Sdduvall * Steps 14-15: Configure DMA endianness options. See 30941369Sdduvall * the comments on the setting of the MHCR above. 30951369Sdduvall */ 30961369Sdduvall #ifdef _BIG_ENDIAN 30971369Sdduvall modeflags = MODE_WORD_SWAP_FRAME | MODE_BYTE_SWAP_FRAME | 30981369Sdduvall MODE_WORD_SWAP_NONFRAME | MODE_BYTE_SWAP_NONFRAME; 30991369Sdduvall #else 31001369Sdduvall modeflags = MODE_WORD_SWAP_FRAME | MODE_BYTE_SWAP_FRAME; 31011369Sdduvall #endif /* _BIG_ENDIAN */ 31021408Srandyf #ifdef BGE_IPMI_ASF 31031408Srandyf if (bgep->asf_enabled) 31041408Srandyf modeflags |= MODE_HOST_STACK_UP; 31051408Srandyf #endif 31061369Sdduvall bge_reg_put32(bgep, MODE_CONTROL_REG, modeflags); 31071369Sdduvall 31081408Srandyf #ifdef BGE_IPMI_ASF 31091408Srandyf if (bgep->asf_enabled) { 31101408Srandyf if (asf_mode != ASF_MODE_NONE) { 31111408Srandyf /* Wait for NVRAM init */ 31121408Srandyf i = 0; 31131408Srandyf drv_usecwait(5000); 31141408Srandyf mailbox = bge_nic_get32(bgep, BGE_FIRMWARE_MAILBOX); 31151408Srandyf while ((mailbox != (uint32_t) 31161408Srandyf ~BGE_MAGIC_NUM_FIRMWARE_INIT_DONE) && 31171408Srandyf (i < 10000)) { 31181408Srandyf drv_usecwait(100); 31191408Srandyf mailbox = bge_nic_get32(bgep, 31201408Srandyf BGE_FIRMWARE_MAILBOX); 31211408Srandyf i++; 31221408Srandyf } 31231408Srandyf if (!bgep->asf_newhandshake) { 31241408Srandyf if ((asf_mode == ASF_MODE_INIT) || 31251408Srandyf (asf_mode == ASF_MODE_POST_INIT)) { 31261408Srandyf 31271408Srandyf bge_asf_post_reset_old_mode(bgep, 31281408Srandyf BGE_INIT_RESET); 31291408Srandyf } else { 31301408Srandyf bge_asf_post_reset_old_mode(bgep, 31311408Srandyf BGE_SHUTDOWN_RESET); 31321408Srandyf } 31331408Srandyf } 31341408Srandyf } 31351408Srandyf } 31361408Srandyf #endif 31371369Sdduvall /* 31381369Sdduvall * Steps 16-17: poll for firmware completion 31391369Sdduvall */ 31401369Sdduvall mac = bge_poll_firmware(bgep); 31411369Sdduvall 31421369Sdduvall /* 31431369Sdduvall * Step 18: enable external memory -- doesn't apply. 31441369Sdduvall * 31451369Sdduvall * However we take the opportunity to set the MLCR anyway, as 31461369Sdduvall * this register also controls the SEEPROM auto-access method 31471369Sdduvall * which we may want to use later ... 31481369Sdduvall * 31491369Sdduvall * The proper value here depends on the way the chip is wired 31501369Sdduvall * into the circuit board, as this register *also* controls which 31511369Sdduvall * of the "Miscellaneous I/O" pins are driven as outputs and the 31521369Sdduvall * values driven onto those pins! 31531369Sdduvall * 31541369Sdduvall * See also step 74 in the PRM ... 31551369Sdduvall */ 31561369Sdduvall bge_reg_put32(bgep, MISC_LOCAL_CONTROL_REG, 31571369Sdduvall bgep->chipid.bge_mlcr_default); 31581369Sdduvall bge_reg_set32(bgep, SERIAL_EEPROM_ADDRESS_REG, SEEPROM_ACCESS_INIT); 31591369Sdduvall 31601369Sdduvall /* 31611369Sdduvall * Step 20: clear the Ethernet MAC mode register 31621369Sdduvall */ 31631369Sdduvall bge_reg_put32(bgep, ETHERNET_MAC_MODE_REG, 0); 31641369Sdduvall 31651369Sdduvall /* 31661369Sdduvall * Step 21: restore cache-line-size, latency timer, and 31671369Sdduvall * subsystem ID registers to their original values (not 31681369Sdduvall * those read into the local structure <chipid>, 'cos 31691369Sdduvall * that was after they were cleared by the RESET). 31701369Sdduvall * 31711369Sdduvall * Note: the Subsystem Vendor/Device ID registers are not 31721369Sdduvall * directly writable in config space, so we use the shadow 31731369Sdduvall * copy in "Page Zero" of register space to restore them 31741369Sdduvall * both in one go ... 31751369Sdduvall */ 31761369Sdduvall pci_config_put8(bgep->cfg_handle, PCI_CONF_CACHE_LINESZ, 31771369Sdduvall bgep->chipid.clsize); 31781369Sdduvall pci_config_put8(bgep->cfg_handle, PCI_CONF_LATENCY_TIMER, 31791369Sdduvall bgep->chipid.latency); 31801369Sdduvall bge_reg_put32(bgep, PCI_CONF_SUBVENID, 31811369Sdduvall (bgep->chipid.subdev << 16) | bgep->chipid.subven); 31821369Sdduvall 31831369Sdduvall /* 31841369Sdduvall * The SEND INDEX registers should be reset to zero by the 31851369Sdduvall * global chip reset; if they're not, there'll be trouble 31861865Sdilpreet * later on. 31871369Sdduvall */ 31881369Sdduvall sx0 = bge_reg_get32(bgep, NIC_DIAG_SEND_INDEX_REG(0)); 31891865Sdilpreet if (sx0 != 0) { 31901865Sdilpreet BGE_REPORT((bgep, "SEND INDEX - device didn't RESET")); 31911865Sdilpreet bge_fm_ereport(bgep, DDI_FM_DEVICE_INVAL_STATE); 31921865Sdilpreet return (DDI_FAILURE); 31931865Sdilpreet } 31941369Sdduvall 31951369Sdduvall /* Enable MSI code */ 31961369Sdduvall if (bgep->intr_type == DDI_INTR_TYPE_MSI) 31971369Sdduvall bge_reg_set32(bgep, MSI_MODE_REG, 31981369Sdduvall MSI_PRI_HIGHEST|MSI_MSI_ENABLE); 31991369Sdduvall 32001369Sdduvall /* 32011369Sdduvall * On the first time through, save the factory-set MAC address 32021369Sdduvall * (if any). If bge_poll_firmware() above didn't return one 32031369Sdduvall * (from a chip register) consider looking in the attached NV 32041369Sdduvall * memory device, if any. Once we have it, we save it in both 32051369Sdduvall * register-image (64-bit) and byte-array forms. All-zero and 32061369Sdduvall * all-one addresses are not valid, and we refuse to stash those. 32071369Sdduvall */ 32081369Sdduvall if (bgep->bge_chip_state == BGE_CHIP_INITIAL) { 32091369Sdduvall if (mac == 0ULL) 32101369Sdduvall mac = bge_get_nvmac(bgep); 32111369Sdduvall if (mac != 0ULL && mac != ~0ULL) { 32121369Sdduvall bgep->chipid.hw_mac_addr = mac; 32131369Sdduvall for (i = ETHERADDRL; i-- != 0; ) { 32141369Sdduvall bgep->chipid.vendor_addr.addr[i] = (uchar_t)mac; 32151369Sdduvall mac >>= 8; 32161369Sdduvall } 32172331Skrgopi bgep->chipid.vendor_addr.set = B_TRUE; 32181369Sdduvall } 32191369Sdduvall } 32201369Sdduvall 32211408Srandyf #ifdef BGE_IPMI_ASF 32221408Srandyf if (bgep->asf_enabled && bgep->asf_newhandshake) { 32231408Srandyf if (asf_mode != ASF_MODE_NONE) { 32241408Srandyf if ((asf_mode == ASF_MODE_INIT) || 32251408Srandyf (asf_mode == ASF_MODE_POST_INIT)) { 32261408Srandyf 32271408Srandyf bge_asf_post_reset_new_mode(bgep, 32281408Srandyf BGE_INIT_RESET); 32291408Srandyf } else { 32301408Srandyf bge_asf_post_reset_new_mode(bgep, 32311408Srandyf BGE_SHUTDOWN_RESET); 32321408Srandyf } 32331408Srandyf } 32341408Srandyf } 32351408Srandyf #endif 32361408Srandyf 32371369Sdduvall /* 32381369Sdduvall * Record the new state 32391369Sdduvall */ 32401369Sdduvall bgep->chip_resets += 1; 32411369Sdduvall bgep->bge_chip_state = BGE_CHIP_RESET; 32421865Sdilpreet return (retval); 32431369Sdduvall } 32441369Sdduvall 32451369Sdduvall /* 32461369Sdduvall * bge_chip_start() -- start the chip transmitting and/or receiving, 32471369Sdduvall * including enabling interrupts 32481369Sdduvall */ 32491865Sdilpreet int bge_chip_start(bge_t *bgep, boolean_t reset_phys); 32501369Sdduvall #pragma no_inline(bge_chip_start) 32511369Sdduvall 32521865Sdilpreet int 32531369Sdduvall bge_chip_start(bge_t *bgep, boolean_t reset_phys) 32541369Sdduvall { 32551369Sdduvall uint32_t coalmode; 32561369Sdduvall uint32_t ledctl; 32571369Sdduvall uint32_t mtu; 32581369Sdduvall uint32_t maxring; 32591369Sdduvall uint64_t ring; 32601865Sdilpreet int retval = DDI_SUCCESS; 32611369Sdduvall 32621369Sdduvall BGE_TRACE(("bge_chip_start($%p)", 32631369Sdduvall (void *)bgep)); 32641369Sdduvall 32651369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 32661369Sdduvall ASSERT(bgep->bge_chip_state == BGE_CHIP_RESET); 32671369Sdduvall 32681369Sdduvall /* 32691369Sdduvall * Taken from Broadcom document 570X-PG102-R, pp 102-116. 32701369Sdduvall * The document specifies 95 separate steps to fully 32711369Sdduvall * initialise the chip!!!! 32721369Sdduvall * 32731369Sdduvall * The reset code above has already got us as far as step 32741369Sdduvall * 21, so we continue with ... 32751369Sdduvall * 32761369Sdduvall * Step 22: clear the MAC statistics block 32771369Sdduvall * (0x0300-0x0aff in NIC-local memory) 32781369Sdduvall */ 32791369Sdduvall if (bgep->chipid.statistic_type == BGE_STAT_BLK) 32801369Sdduvall bge_nic_zero(bgep, NIC_MEM_STATISTICS, 32811369Sdduvall NIC_MEM_STATISTICS_SIZE); 32821369Sdduvall 32831369Sdduvall /* 32841369Sdduvall * Step 23: clear the status block (in host memory) 32851369Sdduvall */ 32861369Sdduvall DMA_ZERO(bgep->status_block); 32871369Sdduvall 32881369Sdduvall /* 32891369Sdduvall * Step 24: set DMA read/write control register 32901369Sdduvall */ 32911369Sdduvall pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_PDRWCR, 32921369Sdduvall bgep->chipid.bge_dma_rwctrl); 32931369Sdduvall 32941369Sdduvall /* 32951369Sdduvall * Step 25: Configure DMA endianness -- already done (16/17) 32961369Sdduvall * Step 26: Configure Host-Based Send Rings 32971369Sdduvall * Step 27: Indicate Host Stack Up 32981369Sdduvall */ 32991369Sdduvall bge_reg_set32(bgep, MODE_CONTROL_REG, 33001369Sdduvall MODE_HOST_SEND_BDS | 33011369Sdduvall MODE_HOST_STACK_UP); 33021369Sdduvall 33031369Sdduvall /* 33041369Sdduvall * Step 28: Configure checksum options: 33051611Szh199473 * Solaris supports the hardware default checksum options. 33061611Szh199473 * 33071611Szh199473 * Workaround for Incorrect pseudo-header checksum calculation. 33081369Sdduvall */ 33092135Szh199473 if (bgep->chipid.flags & CHIP_FLAG_PARTIAL_CSUM) 33101611Szh199473 bge_reg_set32(bgep, MODE_CONTROL_REG, 33112311Sseb MODE_SEND_NO_PSEUDO_HDR_CSUM); 33121369Sdduvall 33131369Sdduvall /* 33141369Sdduvall * Step 29: configure Timer Prescaler. The value is always the 33151369Sdduvall * same: the Core Clock frequency in MHz (66), minus 1, shifted 33161369Sdduvall * into bits 7-1. Don't set bit 0, 'cos that's the RESET bit 33171369Sdduvall * for the whole chip! 33181369Sdduvall */ 33191369Sdduvall bge_reg_put32(bgep, MISC_CONFIG_REG, MISC_CONFIG_DEFAULT); 33201369Sdduvall 33211369Sdduvall /* 33221369Sdduvall * Steps 30-31: Configure MAC local memory pool & DMA pool registers 33231369Sdduvall * 33241369Sdduvall * If the mbuf_length is specified as 0, we just leave these at 33251369Sdduvall * their hardware defaults, rather than explicitly setting them. 33261369Sdduvall * As the Broadcom HRM,driver better not change the parameters 33271369Sdduvall * when the chipsets is 5705/5788/5721/5751/5714 and 5715. 33281369Sdduvall */ 33291369Sdduvall if ((bgep->chipid.mbuf_length != 0) && 33301369Sdduvall (DEVICE_5704_SERIES_CHIPSETS(bgep))) { 33311369Sdduvall bge_reg_put32(bgep, MBUF_POOL_BASE_REG, 33321369Sdduvall bgep->chipid.mbuf_base); 33331369Sdduvall bge_reg_put32(bgep, MBUF_POOL_LENGTH_REG, 33341369Sdduvall bgep->chipid.mbuf_length); 33351369Sdduvall bge_reg_put32(bgep, DMAD_POOL_BASE_REG, 33361369Sdduvall DMAD_POOL_BASE_DEFAULT); 33371369Sdduvall bge_reg_put32(bgep, DMAD_POOL_LENGTH_REG, 33381369Sdduvall DMAD_POOL_LENGTH_DEFAULT); 33391369Sdduvall } 33401369Sdduvall 33411369Sdduvall /* 33421369Sdduvall * Step 32: configure MAC memory pool watermarks 33431369Sdduvall */ 33441369Sdduvall bge_reg_put32(bgep, RDMA_MBUF_LOWAT_REG, 33451369Sdduvall bgep->chipid.mbuf_lo_water_rdma); 33461369Sdduvall bge_reg_put32(bgep, MAC_RX_MBUF_LOWAT_REG, 33471369Sdduvall bgep->chipid.mbuf_lo_water_rmac); 33481369Sdduvall bge_reg_put32(bgep, MBUF_HIWAT_REG, 33491369Sdduvall bgep->chipid.mbuf_hi_water); 33501369Sdduvall 33511369Sdduvall /* 33521369Sdduvall * Step 33: configure DMA resource watermarks 33531369Sdduvall */ 33541369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) { 33551369Sdduvall bge_reg_put32(bgep, DMAD_POOL_LOWAT_REG, 33561369Sdduvall bge_dmad_lo_water); 33571369Sdduvall bge_reg_put32(bgep, DMAD_POOL_HIWAT_REG, 33581369Sdduvall bge_dmad_hi_water); 33591369Sdduvall } 33601369Sdduvall bge_reg_put32(bgep, LOWAT_MAX_RECV_FRAMES_REG, bge_lowat_recv_frames); 33611369Sdduvall 33621369Sdduvall /* 33631369Sdduvall * Steps 34-36: enable buffer manager & internal h/w queues 33641369Sdduvall */ 33651865Sdilpreet if (!bge_chip_enable_engine(bgep, BUFFER_MANAGER_MODE_REG, 33661865Sdilpreet STATE_MACHINE_ATTN_ENABLE_BIT)) 33671865Sdilpreet retval = DDI_FAILURE; 33681865Sdilpreet if (!bge_chip_enable_engine(bgep, FTQ_RESET_REG, 0)) 33691865Sdilpreet retval = DDI_FAILURE; 33701369Sdduvall 33711369Sdduvall /* 33721369Sdduvall * Steps 37-39: initialise Receive Buffer (Producer) RCBs 33731369Sdduvall */ 33741369Sdduvall bge_reg_putrcb(bgep, STD_RCV_BD_RING_RCB_REG, 33751369Sdduvall &bgep->buff[BGE_STD_BUFF_RING].hw_rcb); 33761369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) { 33771369Sdduvall bge_reg_putrcb(bgep, JUMBO_RCV_BD_RING_RCB_REG, 33781369Sdduvall &bgep->buff[BGE_JUMBO_BUFF_RING].hw_rcb); 33791369Sdduvall bge_reg_putrcb(bgep, MINI_RCV_BD_RING_RCB_REG, 33801369Sdduvall &bgep->buff[BGE_MINI_BUFF_RING].hw_rcb); 33811369Sdduvall } 33821369Sdduvall 33831369Sdduvall /* 33841369Sdduvall * Step 40: set Receive Buffer Descriptor Ring replenish thresholds 33851369Sdduvall */ 33861369Sdduvall bge_reg_put32(bgep, STD_RCV_BD_REPLENISH_REG, bge_replenish_std); 33871369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) { 33881369Sdduvall bge_reg_put32(bgep, JUMBO_RCV_BD_REPLENISH_REG, 33891369Sdduvall bge_replenish_jumbo); 33901369Sdduvall bge_reg_put32(bgep, MINI_RCV_BD_REPLENISH_REG, 33911369Sdduvall bge_replenish_mini); 33921369Sdduvall } 33931369Sdduvall 33941369Sdduvall /* 33951369Sdduvall * Steps 41-43: clear Send Ring Producer Indices and initialise 33961369Sdduvall * Send Producer Rings (0x0100-0x01ff in NIC-local memory) 33971369Sdduvall */ 33981369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) 33991369Sdduvall maxring = BGE_SEND_RINGS_MAX; 34001369Sdduvall else 34011369Sdduvall maxring = BGE_SEND_RINGS_MAX_5705; 34021369Sdduvall for (ring = 0; ring < maxring; ++ring) { 34031369Sdduvall bge_mbx_put(bgep, SEND_RING_HOST_INDEX_REG(ring), 0); 34041369Sdduvall bge_mbx_put(bgep, SEND_RING_NIC_INDEX_REG(ring), 0); 34051369Sdduvall bge_nic_putrcb(bgep, NIC_MEM_SEND_RING(ring), 34061369Sdduvall &bgep->send[ring].hw_rcb); 34071369Sdduvall } 34081369Sdduvall 34091369Sdduvall /* 34101369Sdduvall * Steps 44-45: initialise Receive Return Rings 34111369Sdduvall * (0x0200-0x02ff in NIC-local memory) 34121369Sdduvall */ 34131369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) 34141369Sdduvall maxring = BGE_RECV_RINGS_MAX; 34151369Sdduvall else 34161369Sdduvall maxring = BGE_RECV_RINGS_MAX_5705; 34171369Sdduvall for (ring = 0; ring < maxring; ++ring) 34181369Sdduvall bge_nic_putrcb(bgep, NIC_MEM_RECV_RING(ring), 34191369Sdduvall &bgep->recv[ring].hw_rcb); 34201369Sdduvall 34211369Sdduvall /* 34221369Sdduvall * Step 46: initialise Receive Buffer (Producer) Ring indexes 34231369Sdduvall */ 34241369Sdduvall bge_mbx_put(bgep, RECV_STD_PROD_INDEX_REG, 0); 34251369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) { 34261369Sdduvall bge_mbx_put(bgep, RECV_JUMBO_PROD_INDEX_REG, 0); 34271369Sdduvall bge_mbx_put(bgep, RECV_MINI_PROD_INDEX_REG, 0); 34281369Sdduvall } 34291369Sdduvall /* 34301369Sdduvall * Step 47: configure the MAC unicast address 34311369Sdduvall * Step 48: configure the random backoff seed 34321369Sdduvall * Step 96: set up multicast filters 34331369Sdduvall */ 34341408Srandyf #ifdef BGE_IPMI_ASF 34351865Sdilpreet if (bge_chip_sync(bgep, B_FALSE) == DDI_FAILURE) 34361408Srandyf #else 34371865Sdilpreet if (bge_chip_sync(bgep) == DDI_FAILURE) 34381408Srandyf #endif 34391865Sdilpreet retval = DDI_FAILURE; 34401369Sdduvall 34411369Sdduvall /* 34421369Sdduvall * Step 49: configure the MTU 34431369Sdduvall */ 34441369Sdduvall mtu = bgep->chipid.ethmax_size+ETHERFCSL+VLAN_TAGSZ; 34451369Sdduvall bge_reg_put32(bgep, MAC_RX_MTU_SIZE_REG, mtu); 34461369Sdduvall 34471369Sdduvall /* 34481369Sdduvall * Step 50: configure the IPG et al 34491369Sdduvall */ 34501369Sdduvall bge_reg_put32(bgep, MAC_TX_LENGTHS_REG, MAC_TX_LENGTHS_DEFAULT); 34511369Sdduvall 34521369Sdduvall /* 34531369Sdduvall * Step 51: configure the default Rx Return Ring 34541369Sdduvall */ 34551369Sdduvall bge_reg_put32(bgep, RCV_RULES_CONFIG_REG, RCV_RULES_CONFIG_DEFAULT); 34561369Sdduvall 34571369Sdduvall /* 34581369Sdduvall * Steps 52-54: configure Receive List Placement, 34591369Sdduvall * and enable Receive List Placement Statistics 34601369Sdduvall */ 34611369Sdduvall bge_reg_put32(bgep, RCV_LP_CONFIG_REG, 34621369Sdduvall RCV_LP_CONFIG(bgep->chipid.rx_rings)); 34631369Sdduvall bge_reg_put32(bgep, RCV_LP_STATS_ENABLE_MASK_REG, ~0); 34641369Sdduvall bge_reg_set32(bgep, RCV_LP_STATS_CONTROL_REG, RCV_LP_STATS_ENABLE); 34651369Sdduvall 34661369Sdduvall if (bgep->chipid.rx_rings > 1) 34671369Sdduvall bge_init_recv_rule(bgep); 34681369Sdduvall 34691369Sdduvall /* 34701369Sdduvall * Steps 55-56: enable Send Data Initiator Statistics 34711369Sdduvall */ 34721369Sdduvall bge_reg_put32(bgep, SEND_INIT_STATS_ENABLE_MASK_REG, ~0); 34731369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) { 34741369Sdduvall bge_reg_put32(bgep, SEND_INIT_STATS_CONTROL_REG, 34751369Sdduvall SEND_INIT_STATS_ENABLE | SEND_INIT_STATS_FASTER); 34761369Sdduvall } else { 34771369Sdduvall bge_reg_put32(bgep, SEND_INIT_STATS_CONTROL_REG, 34781369Sdduvall SEND_INIT_STATS_ENABLE); 34791369Sdduvall } 34801369Sdduvall /* 34811369Sdduvall * Steps 57-58: stop (?) the Host Coalescing Engine 34821369Sdduvall */ 34831865Sdilpreet if (!bge_chip_disable_engine(bgep, HOST_COALESCE_MODE_REG, ~0)) 34841865Sdilpreet retval = DDI_FAILURE; 34851369Sdduvall 34861369Sdduvall /* 34871369Sdduvall * Steps 59-62: initialise Host Coalescing parameters 34881369Sdduvall */ 34891369Sdduvall bge_reg_put32(bgep, SEND_COALESCE_MAX_BD_REG, bge_tx_count_norm); 34901369Sdduvall bge_reg_put32(bgep, SEND_COALESCE_TICKS_REG, bge_tx_ticks_norm); 34911369Sdduvall bge_reg_put32(bgep, RCV_COALESCE_MAX_BD_REG, bge_rx_count_norm); 34921369Sdduvall bge_reg_put32(bgep, RCV_COALESCE_TICKS_REG, bge_rx_ticks_norm); 34931369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) { 34941369Sdduvall bge_reg_put32(bgep, SEND_COALESCE_INT_BD_REG, 34951369Sdduvall bge_tx_count_intr); 34961369Sdduvall bge_reg_put32(bgep, SEND_COALESCE_INT_TICKS_REG, 34971369Sdduvall bge_tx_ticks_intr); 34981369Sdduvall bge_reg_put32(bgep, RCV_COALESCE_INT_BD_REG, 34991369Sdduvall bge_rx_count_intr); 35001369Sdduvall bge_reg_put32(bgep, RCV_COALESCE_INT_TICKS_REG, 35011369Sdduvall bge_rx_ticks_intr); 35021369Sdduvall } 35031369Sdduvall 35041369Sdduvall /* 35051369Sdduvall * Steps 63-64: initialise status block & statistics 35061369Sdduvall * host memory addresses 35071369Sdduvall * The statistic block does not exist in some chipsets 35081369Sdduvall * Step 65: initialise Statistics Coalescing Tick Counter 35091369Sdduvall */ 35101369Sdduvall bge_reg_put64(bgep, STATUS_BLOCK_HOST_ADDR_REG, 35111369Sdduvall bgep->status_block.cookie.dmac_laddress); 35121369Sdduvall 35131369Sdduvall /* 35141369Sdduvall * Steps 66-67: initialise status block & statistics 35151369Sdduvall * NIC-local memory addresses 35161369Sdduvall */ 35171369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) { 35181369Sdduvall bge_reg_put64(bgep, STATISTICS_HOST_ADDR_REG, 35191369Sdduvall bgep->statistics.cookie.dmac_laddress); 35201369Sdduvall bge_reg_put32(bgep, STATISTICS_TICKS_REG, 35211369Sdduvall STATISTICS_TICKS_DEFAULT); 35221369Sdduvall bge_reg_put32(bgep, STATUS_BLOCK_BASE_ADDR_REG, 35231369Sdduvall NIC_MEM_STATUS_BLOCK); 35241369Sdduvall bge_reg_put32(bgep, STATISTICS_BASE_ADDR_REG, 35251369Sdduvall NIC_MEM_STATISTICS); 35261369Sdduvall } 35271369Sdduvall 35281369Sdduvall /* 35291369Sdduvall * Steps 68-71: start the Host Coalescing Engine, the Receive BD 35301369Sdduvall * Completion Engine, the Receive List Placement Engine, and the 35311369Sdduvall * Receive List selector.Pay attention:0x3400 is not exist in BCM5714 35321369Sdduvall * and BCM5715. 35331369Sdduvall */ 35341369Sdduvall if (bgep->chipid.tx_rings <= COALESCE_64_BYTE_RINGS && 35351369Sdduvall bgep->chipid.rx_rings <= COALESCE_64_BYTE_RINGS) 35361369Sdduvall coalmode = COALESCE_64_BYTE_STATUS; 35371369Sdduvall else 35381369Sdduvall coalmode = 0; 35391865Sdilpreet if (!bge_chip_enable_engine(bgep, HOST_COALESCE_MODE_REG, coalmode)) 35401865Sdilpreet retval = DDI_FAILURE; 35411865Sdilpreet if (!bge_chip_enable_engine(bgep, RCV_BD_COMPLETION_MODE_REG, 35421865Sdilpreet STATE_MACHINE_ATTN_ENABLE_BIT)) 35431865Sdilpreet retval = DDI_FAILURE; 35441865Sdilpreet if (!bge_chip_enable_engine(bgep, RCV_LIST_PLACEMENT_MODE_REG, 0)) 35451865Sdilpreet retval = DDI_FAILURE; 35461369Sdduvall 35471369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) 35481865Sdilpreet if (!bge_chip_enable_engine(bgep, RCV_LIST_SELECTOR_MODE_REG, 35491865Sdilpreet STATE_MACHINE_ATTN_ENABLE_BIT)) 35501865Sdilpreet retval = DDI_FAILURE; 35511369Sdduvall 35521369Sdduvall /* 35531369Sdduvall * Step 72: Enable MAC DMA engines 35541369Sdduvall * Step 73: Clear & enable MAC statistics 35551369Sdduvall */ 35561369Sdduvall bge_reg_set32(bgep, ETHERNET_MAC_MODE_REG, 35571369Sdduvall ETHERNET_MODE_ENABLE_FHDE | 35581369Sdduvall ETHERNET_MODE_ENABLE_RDE | 35591369Sdduvall ETHERNET_MODE_ENABLE_TDE); 35601369Sdduvall bge_reg_set32(bgep, ETHERNET_MAC_MODE_REG, 35611369Sdduvall ETHERNET_MODE_ENABLE_TX_STATS | 35621369Sdduvall ETHERNET_MODE_ENABLE_RX_STATS | 35631369Sdduvall ETHERNET_MODE_CLEAR_TX_STATS | 35641369Sdduvall ETHERNET_MODE_CLEAR_RX_STATS); 35651369Sdduvall 35661369Sdduvall /* 35671369Sdduvall * Step 74: configure the MLCR (Miscellaneous Local Control 35681369Sdduvall * Register); not required, as we set up the MLCR in step 10 35691369Sdduvall * (part of the reset code) above. 35701369Sdduvall * 35711369Sdduvall * Step 75: clear Interrupt Mailbox 0 35721369Sdduvall */ 35731369Sdduvall bge_mbx_put(bgep, INTERRUPT_MBOX_0_REG, 0); 35741369Sdduvall 35751369Sdduvall /* 35761369Sdduvall * Steps 76-87: Gentlemen, start your engines ... 35771369Sdduvall * 35781369Sdduvall * Enable the DMA Completion Engine, the Write DMA Engine, 35791369Sdduvall * the Read DMA Engine, Receive Data Completion Engine, 35801369Sdduvall * the MBuf Cluster Free Engine, the Send Data Completion Engine, 35811369Sdduvall * the Send BD Completion Engine, the Receive BD Initiator Engine, 35821369Sdduvall * the Receive Data Initiator Engine, the Send Data Initiator Engine, 35831369Sdduvall * the Send BD Initiator Engine, and the Send BD Selector Engine. 35841369Sdduvall * 35851369Sdduvall * Beware exhaust fumes? 35861369Sdduvall */ 35871369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) 35881865Sdilpreet if (!bge_chip_enable_engine(bgep, DMA_COMPLETION_MODE_REG, 0)) 35891865Sdilpreet retval = DDI_FAILURE; 35901865Sdilpreet if (!bge_chip_enable_engine(bgep, WRITE_DMA_MODE_REG, 35911865Sdilpreet (bge_dma_wrprio << DMA_PRIORITY_SHIFT) | ALL_DMA_ATTN_BITS)) 35921865Sdilpreet retval = DDI_FAILURE; 35931865Sdilpreet if (!bge_chip_enable_engine(bgep, READ_DMA_MODE_REG, 35941865Sdilpreet (bge_dma_rdprio << DMA_PRIORITY_SHIFT) | ALL_DMA_ATTN_BITS)) 35951865Sdilpreet retval = DDI_FAILURE; 35961865Sdilpreet if (!bge_chip_enable_engine(bgep, RCV_DATA_COMPLETION_MODE_REG, 35971865Sdilpreet STATE_MACHINE_ATTN_ENABLE_BIT)) 35981865Sdilpreet retval = DDI_FAILURE; 35991369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) 36001865Sdilpreet if (!bge_chip_enable_engine(bgep, 36011865Sdilpreet MBUF_CLUSTER_FREE_MODE_REG, 0)) 36021865Sdilpreet retval = DDI_FAILURE; 36031865Sdilpreet if (!bge_chip_enable_engine(bgep, SEND_DATA_COMPLETION_MODE_REG, 0)) 36041865Sdilpreet retval = DDI_FAILURE; 36051865Sdilpreet if (!bge_chip_enable_engine(bgep, SEND_BD_COMPLETION_MODE_REG, 36061865Sdilpreet STATE_MACHINE_ATTN_ENABLE_BIT)) 36071865Sdilpreet retval = DDI_FAILURE; 36081865Sdilpreet if (!bge_chip_enable_engine(bgep, RCV_BD_INITIATOR_MODE_REG, 36091865Sdilpreet RCV_BD_DISABLED_RING_ATTN)) 36101865Sdilpreet retval = DDI_FAILURE; 36111865Sdilpreet if (!bge_chip_enable_engine(bgep, RCV_DATA_BD_INITIATOR_MODE_REG, 36121865Sdilpreet RCV_DATA_BD_ILL_RING_ATTN)) 36131865Sdilpreet retval = DDI_FAILURE; 36141865Sdilpreet if (!bge_chip_enable_engine(bgep, SEND_DATA_INITIATOR_MODE_REG, 0)) 36151865Sdilpreet retval = DDI_FAILURE; 36161865Sdilpreet if (!bge_chip_enable_engine(bgep, SEND_BD_INITIATOR_MODE_REG, 36171865Sdilpreet STATE_MACHINE_ATTN_ENABLE_BIT)) 36181865Sdilpreet retval = DDI_FAILURE; 36191865Sdilpreet if (!bge_chip_enable_engine(bgep, SEND_BD_SELECTOR_MODE_REG, 36201865Sdilpreet STATE_MACHINE_ATTN_ENABLE_BIT)) 36211865Sdilpreet retval = DDI_FAILURE; 36221369Sdduvall 36231369Sdduvall /* 36241369Sdduvall * Step 88: download firmware -- doesn't apply 36251369Sdduvall * Steps 89-90: enable Transmit & Receive MAC Engines 36261369Sdduvall */ 36271865Sdilpreet if (!bge_chip_enable_engine(bgep, TRANSMIT_MAC_MODE_REG, 0)) 36281865Sdilpreet retval = DDI_FAILURE; 36291408Srandyf #ifdef BGE_IPMI_ASF 36301865Sdilpreet if (!bgep->asf_enabled) { 36311865Sdilpreet if (!bge_chip_enable_engine(bgep, RECEIVE_MAC_MODE_REG, 36321865Sdilpreet RECEIVE_MODE_KEEP_VLAN_TAG)) 36331865Sdilpreet retval = DDI_FAILURE; 36341408Srandyf } else { 36351865Sdilpreet if (!bge_chip_enable_engine(bgep, RECEIVE_MAC_MODE_REG, 0)) 36361865Sdilpreet retval = DDI_FAILURE; 36371408Srandyf } 36381408Srandyf #else 36391865Sdilpreet if (!bge_chip_enable_engine(bgep, RECEIVE_MAC_MODE_REG, 36401865Sdilpreet RECEIVE_MODE_KEEP_VLAN_TAG)) 36411865Sdilpreet retval = DDI_FAILURE; 36421408Srandyf #endif 36431369Sdduvall 36441369Sdduvall /* 36451369Sdduvall * Step 91: disable auto-polling of PHY status 36461369Sdduvall */ 36471369Sdduvall bge_reg_put32(bgep, MI_MODE_REG, MI_MODE_DEFAULT); 36481369Sdduvall 36491369Sdduvall /* 36501369Sdduvall * Step 92: configure D0 power state (not required) 36511369Sdduvall * Step 93: initialise LED control register () 36521369Sdduvall */ 36531369Sdduvall ledctl = LED_CONTROL_DEFAULT; 36541369Sdduvall switch (bgep->chipid.device) { 36551369Sdduvall case DEVICE_ID_5700: 36561369Sdduvall case DEVICE_ID_5700x: 36571369Sdduvall case DEVICE_ID_5701: 36581369Sdduvall /* 36591369Sdduvall * Switch to 5700 (MAC) mode on these older chips 36601369Sdduvall */ 36611369Sdduvall ledctl &= ~LED_CONTROL_LED_MODE_MASK; 36621369Sdduvall ledctl |= LED_CONTROL_LED_MODE_5700; 36631369Sdduvall break; 36641369Sdduvall 36651369Sdduvall default: 36661369Sdduvall break; 36671369Sdduvall } 36681369Sdduvall bge_reg_put32(bgep, ETHERNET_MAC_LED_CONTROL_REG, ledctl); 36691369Sdduvall 36701369Sdduvall /* 36711369Sdduvall * Step 94: activate link 36721369Sdduvall */ 36731369Sdduvall bge_reg_put32(bgep, MI_STATUS_REG, MI_STATUS_LINK); 36741369Sdduvall 36751369Sdduvall /* 36761369Sdduvall * Step 95: set up physical layer (PHY/SerDes) 36771369Sdduvall * restart autoneg (if required) 36781369Sdduvall */ 36791369Sdduvall if (reset_phys) 36801865Sdilpreet if (bge_phys_update(bgep) == DDI_FAILURE) 36811865Sdilpreet retval = DDI_FAILURE; 36821369Sdduvall 36831369Sdduvall /* 36841369Sdduvall * Extra step (DSG): hand over all the Receive Buffers to the chip 36851369Sdduvall */ 36861369Sdduvall for (ring = 0; ring < BGE_BUFF_RINGS_USED; ++ring) 36871369Sdduvall bge_mbx_put(bgep, bgep->buff[ring].chip_mbx_reg, 36881369Sdduvall bgep->buff[ring].rf_next); 36891369Sdduvall 36901369Sdduvall /* 36911369Sdduvall * MSI bits:The least significant MSI 16-bit word. 36921369Sdduvall * ISR will be triggered different. 36931369Sdduvall */ 36941369Sdduvall if (bgep->intr_type == DDI_INTR_TYPE_MSI) 36951369Sdduvall bge_reg_set32(bgep, HOST_COALESCE_MODE_REG, 0x70); 36961369Sdduvall 36971369Sdduvall /* 36981369Sdduvall * Extra step (DSG): select which interrupts are enabled 36991369Sdduvall * 37001369Sdduvall * Program the Ethernet MAC engine to signal attention on 37011369Sdduvall * Link Change events, then enable interrupts on MAC, DMA, 37021369Sdduvall * and FLOW attention signals. 37031369Sdduvall */ 37041369Sdduvall bge_reg_set32(bgep, ETHERNET_MAC_EVENT_ENABLE_REG, 37051369Sdduvall ETHERNET_EVENT_LINK_INT | 37061369Sdduvall ETHERNET_STATUS_PCS_ERROR_INT); 37071408Srandyf #ifdef BGE_IPMI_ASF 37081408Srandyf if (bgep->asf_enabled) { 37091408Srandyf bge_reg_set32(bgep, MODE_CONTROL_REG, 37101408Srandyf MODE_INT_ON_FLOW_ATTN | 37111408Srandyf MODE_INT_ON_DMA_ATTN | 37121408Srandyf MODE_HOST_STACK_UP| 37131408Srandyf MODE_INT_ON_MAC_ATTN); 37141408Srandyf } else { 37151408Srandyf #endif 37161408Srandyf bge_reg_set32(bgep, MODE_CONTROL_REG, 37171408Srandyf MODE_INT_ON_FLOW_ATTN | 37181408Srandyf MODE_INT_ON_DMA_ATTN | 37191408Srandyf MODE_INT_ON_MAC_ATTN); 37201408Srandyf #ifdef BGE_IPMI_ASF 37211408Srandyf } 37221408Srandyf #endif 37231369Sdduvall 37241369Sdduvall /* 37251369Sdduvall * Step 97: enable PCI interrupts!!! 37261369Sdduvall */ 37271369Sdduvall if (bgep->intr_type == DDI_INTR_TYPE_FIXED) 37281369Sdduvall bge_cfg_clr32(bgep, PCI_CONF_BGE_MHCR, 37291369Sdduvall MHCR_MASK_PCI_INT_OUTPUT); 37301369Sdduvall 37311369Sdduvall /* 37321369Sdduvall * All done! 37331369Sdduvall */ 37341369Sdduvall bgep->bge_chip_state = BGE_CHIP_RUNNING; 37351865Sdilpreet return (retval); 37361369Sdduvall } 37371369Sdduvall 37381369Sdduvall 37391369Sdduvall /* 37401369Sdduvall * ========== Hardware interrupt handler ========== 37411369Sdduvall */ 37421369Sdduvall 37431369Sdduvall #undef BGE_DBG 37441369Sdduvall #define BGE_DBG BGE_DBG_INT /* debug flag for this code */ 37451369Sdduvall 37461369Sdduvall /* 37471369Sdduvall * Sync the status block, then atomically clear the specified bits in 37481369Sdduvall * the <flags-and-tag> field of the status block. 37491369Sdduvall * the <flags> word of the status block, returning the value of the 37501369Sdduvall * <tag> and the <flags> before the bits were cleared. 37511369Sdduvall */ 37521865Sdilpreet static int bge_status_sync(bge_t *bgep, uint64_t bits, uint64_t *flags); 37531369Sdduvall #pragma inline(bge_status_sync) 37541369Sdduvall 37551865Sdilpreet static int 37561865Sdilpreet bge_status_sync(bge_t *bgep, uint64_t bits, uint64_t *flags) 37571369Sdduvall { 37581369Sdduvall bge_status_t *bsp; 37591865Sdilpreet int retval; 37601369Sdduvall 37611369Sdduvall BGE_TRACE(("bge_status_sync($%p, 0x%llx)", 37621369Sdduvall (void *)bgep, bits)); 37631369Sdduvall 37641369Sdduvall ASSERT(bgep->bge_guard == BGE_GUARD); 37651369Sdduvall 37661369Sdduvall DMA_SYNC(bgep->status_block, DDI_DMA_SYNC_FORKERNEL); 37671865Sdilpreet retval = bge_check_dma_handle(bgep, bgep->status_block.dma_hdl); 37681865Sdilpreet if (retval != DDI_FM_OK) 37691865Sdilpreet return (retval); 37701865Sdilpreet 37711369Sdduvall bsp = DMA_VPTR(bgep->status_block); 37721865Sdilpreet *flags = bge_atomic_clr64(&bsp->flags_n_tag, bits); 37731369Sdduvall 37741369Sdduvall BGE_DEBUG(("bge_status_sync($%p, 0x%llx) returning 0x%llx", 37751865Sdilpreet (void *)bgep, bits, *flags)); 37761865Sdilpreet 37771865Sdilpreet return (retval); 37781369Sdduvall } 37791369Sdduvall 37801369Sdduvall static void bge_wake_factotum(bge_t *bgep); 37811369Sdduvall #pragma inline(bge_wake_factotum) 37821369Sdduvall 37831369Sdduvall static void 37841369Sdduvall bge_wake_factotum(bge_t *bgep) 37851369Sdduvall { 37861369Sdduvall mutex_enter(bgep->softintrlock); 37871369Sdduvall if (bgep->factotum_flag == 0) { 37881369Sdduvall bgep->factotum_flag = 1; 37891369Sdduvall ddi_trigger_softintr(bgep->factotum_id); 37901369Sdduvall } 37911369Sdduvall mutex_exit(bgep->softintrlock); 37921369Sdduvall } 37931369Sdduvall 37941369Sdduvall /* 37951369Sdduvall * bge_intr() -- handle chip interrupts 37961369Sdduvall */ 37971369Sdduvall uint_t bge_intr(caddr_t arg1, caddr_t arg2); 37981369Sdduvall #pragma no_inline(bge_intr) 37991369Sdduvall 38001369Sdduvall uint_t 38011369Sdduvall bge_intr(caddr_t arg1, caddr_t arg2) 38021369Sdduvall { 38031369Sdduvall bge_t *bgep = (bge_t *)arg1; /* private device info */ 38041369Sdduvall bge_status_t *bsp; 38051369Sdduvall uint64_t flags; 38061369Sdduvall uint32_t mlcr = 0; 38071369Sdduvall uint_t result; 38081865Sdilpreet int retval; 38091369Sdduvall 38101369Sdduvall BGE_TRACE(("bge_intr($%p) ($%p)", arg1, arg2)); 38111369Sdduvall 38121369Sdduvall /* 38131369Sdduvall * GLD v2 checks that s/w setup is complete before passing 38141369Sdduvall * interrupts to this routine, thus eliminating the old 38151369Sdduvall * (and well-known) race condition around ddi_add_intr() 38161369Sdduvall */ 38171369Sdduvall ASSERT(bgep->progress & PROGRESS_HWINT); 38181369Sdduvall 38191369Sdduvall /* 38201369Sdduvall * Check whether chip's says it's asserting #INTA; 38211369Sdduvall * if not, don't process or claim the interrupt. 38221369Sdduvall * 38231369Sdduvall * Note that the PCI signal is active low, so the 38241369Sdduvall * bit is *zero* when the interrupt is asserted. 38251369Sdduvall */ 38261369Sdduvall result = DDI_INTR_UNCLAIMED; 38271369Sdduvall mutex_enter(bgep->genlock); 38281369Sdduvall 38291369Sdduvall if (bgep->intr_type == DDI_INTR_TYPE_FIXED) 38301369Sdduvall mlcr = bge_reg_get32(bgep, MISC_LOCAL_CONTROL_REG); 38311369Sdduvall 38321369Sdduvall BGE_DEBUG(("bge_intr($%p) ($%p) mlcr 0x%08x", arg1, arg2, mlcr)); 38331369Sdduvall 38341369Sdduvall if ((mlcr & MLCR_INTA_STATE) == 0) { 38351369Sdduvall /* 38361369Sdduvall * Block further PCI interrupts ... 38371369Sdduvall */ 38381369Sdduvall result = DDI_INTR_CLAIMED; 38391369Sdduvall 38401865Sdilpreet if (bgep->intr_type == DDI_INTR_TYPE_FIXED) { 38411908Sly149593 bge_reg_set32(bgep, PCI_CONF_BGE_MHCR, 38421369Sdduvall MHCR_MASK_PCI_INT_OUTPUT); 38431865Sdilpreet if (bge_check_acc_handle(bgep, bgep->cfg_handle) != 38441865Sdilpreet DDI_FM_OK) 38451865Sdilpreet goto chip_stop; 38461865Sdilpreet } 38471369Sdduvall 38481369Sdduvall /* 38491369Sdduvall * Sync the status block and grab the flags-n-tag from it. 38501369Sdduvall * We count the number of interrupts where there doesn't 38511369Sdduvall * seem to have been a DMA update of the status block; if 38521369Sdduvall * it *has* been updated, the counter will be cleared in 38531369Sdduvall * the while() loop below ... 38541369Sdduvall */ 38551369Sdduvall bgep->missed_dmas += 1; 38561369Sdduvall bsp = DMA_VPTR(bgep->status_block); 38571865Sdilpreet for (;;) { 38581865Sdilpreet if (bgep->bge_chip_state != BGE_CHIP_RUNNING) { 38591865Sdilpreet /* 38601865Sdilpreet * bge_chip_stop() may have freed dma area etc 38611865Sdilpreet * while we were in this interrupt handler - 38621865Sdilpreet * better not call bge_status_sync() 38631865Sdilpreet */ 38641865Sdilpreet (void) bge_check_acc_handle(bgep, 38651865Sdilpreet bgep->io_handle); 38661865Sdilpreet mutex_exit(bgep->genlock); 38671865Sdilpreet return (DDI_INTR_CLAIMED); 38681865Sdilpreet } 38691865Sdilpreet retval = bge_status_sync(bgep, STATUS_FLAG_UPDATED, 38701865Sdilpreet &flags); 38711865Sdilpreet if (retval != DDI_FM_OK) { 38721865Sdilpreet bgep->bge_dma_error = B_TRUE; 38731865Sdilpreet goto chip_stop; 38741865Sdilpreet } 38751865Sdilpreet 38761865Sdilpreet if (!(flags & STATUS_FLAG_UPDATED)) 38771865Sdilpreet break; 38781865Sdilpreet 38791369Sdduvall /* 38801369Sdduvall * Tell the chip that we're processing the interrupt 38811369Sdduvall */ 38821369Sdduvall bge_mbx_put(bgep, INTERRUPT_MBOX_0_REG, 38831369Sdduvall INTERRUPT_MBOX_DISABLE(flags)); 38841865Sdilpreet if (bge_check_acc_handle(bgep, bgep->io_handle) != 38851865Sdilpreet DDI_FM_OK) 38861865Sdilpreet goto chip_stop; 38871369Sdduvall 38881369Sdduvall /* 38891369Sdduvall * Drop the mutex while we: 38901369Sdduvall * Receive any newly-arrived packets 38911369Sdduvall * Recycle any newly-finished send buffers 38921369Sdduvall */ 38931865Sdilpreet bgep->bge_intr_running = B_TRUE; 38941369Sdduvall mutex_exit(bgep->genlock); 38951369Sdduvall bge_receive(bgep, bsp); 38961369Sdduvall bge_recycle(bgep, bsp); 38971369Sdduvall mutex_enter(bgep->genlock); 38981865Sdilpreet bgep->bge_intr_running = B_FALSE; 38991369Sdduvall 39001369Sdduvall /* 39011369Sdduvall * Tell the chip we've finished processing, and 39021369Sdduvall * give it the tag that we got from the status 39031369Sdduvall * block earlier, so that it knows just how far 39041369Sdduvall * we've gone. If it's got more for us to do, 39051369Sdduvall * it will now update the status block and try 39061369Sdduvall * to assert an interrupt (but we've got the 39071369Sdduvall * #INTA blocked at present). If we see the 39081369Sdduvall * update, we'll loop around to do some more. 39091369Sdduvall * Eventually we'll get out of here ... 39101369Sdduvall */ 39111369Sdduvall bge_mbx_put(bgep, INTERRUPT_MBOX_0_REG, 39121369Sdduvall INTERRUPT_MBOX_ENABLE(flags)); 39131369Sdduvall bgep->missed_dmas = 0; 39141369Sdduvall } 39151369Sdduvall 39161369Sdduvall /* 39171369Sdduvall * Check for exceptional conditions that we need to handle 39181369Sdduvall * 39191369Sdduvall * Link status changed 39201369Sdduvall * Status block not updated 39211369Sdduvall */ 39221369Sdduvall if (flags & STATUS_FLAG_LINK_CHANGED) 39231369Sdduvall bge_wake_factotum(bgep); 39241369Sdduvall 39251369Sdduvall if (bgep->missed_dmas) { 39261369Sdduvall /* 39271369Sdduvall * Probably due to the internal status tag not 39281369Sdduvall * being reset. Force a status block update now; 39291369Sdduvall * this should ensure that we get an update and 39301369Sdduvall * a new interrupt. After that, we should be in 39311369Sdduvall * sync again ... 39321369Sdduvall */ 39331369Sdduvall BGE_REPORT((bgep, "interrupt: flags 0x%llx - " 39341369Sdduvall "not updated?", flags)); 39351369Sdduvall bge_reg_set32(bgep, HOST_COALESCE_MODE_REG, 39361369Sdduvall COALESCE_NOW); 39371369Sdduvall 39381369Sdduvall if (bgep->missed_dmas >= bge_dma_miss_limit) { 39391369Sdduvall /* 39401369Sdduvall * If this happens multiple times in a row, 39411369Sdduvall * it means DMA is just not working. Maybe 39421369Sdduvall * the chip's failed, or maybe there's a 39431369Sdduvall * problem on the PCI bus or in the host-PCI 39441369Sdduvall * bridge (Tomatillo). 39451369Sdduvall * 39461369Sdduvall * At all events, we want to stop further 39471369Sdduvall * interrupts and let the recovery code take 39481369Sdduvall * over to see whether anything can be done 39491369Sdduvall * about it ... 39501369Sdduvall */ 39511865Sdilpreet bge_fm_ereport(bgep, 39521865Sdilpreet DDI_FM_DEVICE_BADINT_LIMIT); 39531865Sdilpreet goto chip_stop; 39541369Sdduvall } 39551369Sdduvall } 39561369Sdduvall 39571369Sdduvall /* 39581369Sdduvall * Reenable assertion of #INTA, unless there's a DMA fault 39591369Sdduvall */ 39601369Sdduvall if (result == DDI_INTR_CLAIMED) { 39611865Sdilpreet if (bgep->intr_type == DDI_INTR_TYPE_FIXED) { 39621908Sly149593 bge_reg_clr32(bgep, PCI_CONF_BGE_MHCR, 39631369Sdduvall MHCR_MASK_PCI_INT_OUTPUT); 39641865Sdilpreet if (bge_check_acc_handle(bgep, 39651865Sdilpreet bgep->cfg_handle) != DDI_FM_OK) 39661865Sdilpreet goto chip_stop; 39671865Sdilpreet } 39681369Sdduvall } 39691369Sdduvall } 39701369Sdduvall 39711865Sdilpreet if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) 39721865Sdilpreet goto chip_stop; 39731865Sdilpreet 39741865Sdilpreet mutex_exit(bgep->genlock); 39751865Sdilpreet return (result); 39761865Sdilpreet 39771865Sdilpreet chip_stop: 39781865Sdilpreet #ifdef BGE_IPMI_ASF 39791865Sdilpreet if (bgep->asf_enabled && bgep->asf_status == ASF_STAT_RUN) { 39801865Sdilpreet /* 39811865Sdilpreet * We must stop ASF heart beat before 39821865Sdilpreet * bge_chip_stop(), otherwise some 39831865Sdilpreet * computers (ex. IBM HS20 blade 39841865Sdilpreet * server) may crash. 39851865Sdilpreet */ 39861865Sdilpreet bge_asf_update_status(bgep); 39871865Sdilpreet bge_asf_stop_timer(bgep); 39881865Sdilpreet bgep->asf_status = ASF_STAT_STOP; 39891865Sdilpreet 39901865Sdilpreet bge_asf_pre_reset_operations(bgep, BGE_INIT_RESET); 39911865Sdilpreet (void) bge_check_acc_handle(bgep, bgep->cfg_handle); 39921865Sdilpreet } 39931865Sdilpreet #endif 39941865Sdilpreet bge_chip_stop(bgep, B_TRUE); 39951865Sdilpreet (void) bge_check_acc_handle(bgep, bgep->io_handle); 39961369Sdduvall mutex_exit(bgep->genlock); 39971369Sdduvall return (result); 39981369Sdduvall } 39991369Sdduvall 40001369Sdduvall /* 40011369Sdduvall * ========== Factotum, implemented as a softint handler ========== 40021369Sdduvall */ 40031369Sdduvall 40041369Sdduvall #undef BGE_DBG 40051369Sdduvall #define BGE_DBG BGE_DBG_FACT /* debug flag for this code */ 40061369Sdduvall 40071369Sdduvall static void bge_factotum_error_handler(bge_t *bgep); 40081369Sdduvall #pragma no_inline(bge_factotum_error_handler) 40091369Sdduvall 40101369Sdduvall static void 40111369Sdduvall bge_factotum_error_handler(bge_t *bgep) 40121369Sdduvall { 40131369Sdduvall uint32_t flow; 40141369Sdduvall uint32_t rdma; 40151369Sdduvall uint32_t wdma; 40161369Sdduvall uint32_t tmac; 40171369Sdduvall uint32_t rmac; 40181369Sdduvall uint32_t rxrs; 40191369Sdduvall uint32_t txrs = 0; 40201369Sdduvall 40211369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 40221369Sdduvall 40231369Sdduvall /* 40241369Sdduvall * Read all the registers that show the possible 40251369Sdduvall * reasons for the ERROR bit to be asserted 40261369Sdduvall */ 40271369Sdduvall flow = bge_reg_get32(bgep, FLOW_ATTN_REG); 40281369Sdduvall rdma = bge_reg_get32(bgep, READ_DMA_STATUS_REG); 40291369Sdduvall wdma = bge_reg_get32(bgep, WRITE_DMA_STATUS_REG); 40301369Sdduvall tmac = bge_reg_get32(bgep, TRANSMIT_MAC_STATUS_REG); 40311369Sdduvall rmac = bge_reg_get32(bgep, RECEIVE_MAC_STATUS_REG); 40321369Sdduvall rxrs = bge_reg_get32(bgep, RX_RISC_STATE_REG); 40331369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) 40341369Sdduvall txrs = bge_reg_get32(bgep, TX_RISC_STATE_REG); 40351369Sdduvall 40361369Sdduvall BGE_DEBUG(("factotum($%p) flow 0x%x rdma 0x%x wdma 0x%x", 40371369Sdduvall (void *)bgep, flow, rdma, wdma)); 40381369Sdduvall BGE_DEBUG(("factotum($%p) tmac 0x%x rmac 0x%x rxrs 0x%08x txrs 0x%08x", 40391369Sdduvall (void *)bgep, tmac, rmac, rxrs, txrs)); 40401369Sdduvall 40411369Sdduvall /* 40421369Sdduvall * For now, just clear all the errors ... 40431369Sdduvall */ 40441369Sdduvall if (DEVICE_5704_SERIES_CHIPSETS(bgep)) 40451369Sdduvall bge_reg_put32(bgep, TX_RISC_STATE_REG, ~0); 40461369Sdduvall bge_reg_put32(bgep, RX_RISC_STATE_REG, ~0); 40471369Sdduvall bge_reg_put32(bgep, RECEIVE_MAC_STATUS_REG, ~0); 40481369Sdduvall bge_reg_put32(bgep, WRITE_DMA_STATUS_REG, ~0); 40491369Sdduvall bge_reg_put32(bgep, READ_DMA_STATUS_REG, ~0); 40501369Sdduvall bge_reg_put32(bgep, FLOW_ATTN_REG, ~0); 40511369Sdduvall } 40521369Sdduvall 40531369Sdduvall /* 40541369Sdduvall * Handler for hardware link state change. 40551369Sdduvall * 40561369Sdduvall * When this routine is called, the hardware link state has changed 40571369Sdduvall * and the new state is reflected in the param_* variables. Here 40581369Sdduvall * we must update the softstate, reprogram the MAC to match, and 40591369Sdduvall * record the change in the log and/or on the console. 40601369Sdduvall */ 40611369Sdduvall static void bge_factotum_link_handler(bge_t *bgep); 40621369Sdduvall #pragma no_inline(bge_factotum_link_handler) 40631369Sdduvall 40641369Sdduvall static void 40651369Sdduvall bge_factotum_link_handler(bge_t *bgep) 40661369Sdduvall { 40671369Sdduvall void (*logfn)(bge_t *bgep, const char *fmt, ...); 40681369Sdduvall const char *msg; 40691369Sdduvall hrtime_t deltat; 40701369Sdduvall 40711369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 40721369Sdduvall 40731369Sdduvall /* 40741369Sdduvall * Update the s/w link_state 40751369Sdduvall */ 40761369Sdduvall if (bgep->param_link_up) 40771369Sdduvall bgep->link_state = LINK_STATE_UP; 40781369Sdduvall else 40791369Sdduvall bgep->link_state = LINK_STATE_DOWN; 40801369Sdduvall 40811369Sdduvall /* 40821369Sdduvall * Reprogram the MAC modes to match 40831369Sdduvall */ 40841369Sdduvall bge_sync_mac_modes(bgep); 40851369Sdduvall 40861369Sdduvall /* 40871369Sdduvall * Finally, we have to decide whether to write a message 40881369Sdduvall * on the console or only in the log. If the PHY has 40891369Sdduvall * been reprogrammed (at user request) "recently", then 40901369Sdduvall * the message only goes in the log. Otherwise it's an 40911369Sdduvall * "unexpected" event, and it goes on the console as well. 40921369Sdduvall */ 40931369Sdduvall deltat = bgep->phys_event_time - bgep->phys_write_time; 40941369Sdduvall if (deltat > BGE_LINK_SETTLE_TIME) 40951369Sdduvall msg = ""; 40961369Sdduvall else if (bgep->param_link_up) 40971369Sdduvall msg = bgep->link_up_msg; 40981369Sdduvall else 40991369Sdduvall msg = bgep->link_down_msg; 41001369Sdduvall 41011369Sdduvall logfn = (msg == NULL || *msg == '\0') ? bge_notice : bge_log; 41021369Sdduvall (*logfn)(bgep, "link %s%s", bgep->link_mode_msg, msg); 41031369Sdduvall } 41041369Sdduvall 41051865Sdilpreet static boolean_t bge_factotum_link_check(bge_t *bgep, int *dma_state); 41061369Sdduvall #pragma no_inline(bge_factotum_link_check) 41071369Sdduvall 41081369Sdduvall static boolean_t 41091865Sdilpreet bge_factotum_link_check(bge_t *bgep, int *dma_state) 41101369Sdduvall { 41111369Sdduvall boolean_t check; 41121369Sdduvall uint64_t flags; 41131369Sdduvall uint32_t tmac_status; 41141369Sdduvall 41151369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 41161369Sdduvall 41171369Sdduvall /* 41181369Sdduvall * Get & clear the writable status bits in the Tx status register 41191369Sdduvall * (some bits are write-1-to-clear, others are just readonly). 41201369Sdduvall */ 41211369Sdduvall tmac_status = bge_reg_get32(bgep, TRANSMIT_MAC_STATUS_REG); 41221369Sdduvall bge_reg_put32(bgep, TRANSMIT_MAC_STATUS_REG, tmac_status); 41231369Sdduvall 41241369Sdduvall /* 41251369Sdduvall * Get & clear the ERROR and LINK_CHANGED bits from the status block 41261369Sdduvall */ 41271865Sdilpreet *dma_state = bge_status_sync(bgep, STATUS_FLAG_ERROR | 41281865Sdilpreet STATUS_FLAG_LINK_CHANGED, &flags); 41291865Sdilpreet if (*dma_state != DDI_FM_OK) 41301865Sdilpreet return (B_FALSE); 41311369Sdduvall 41321369Sdduvall /* 41331369Sdduvall * Clear any errors flagged in the status block ... 41341369Sdduvall */ 41351369Sdduvall if (flags & STATUS_FLAG_ERROR) 41361369Sdduvall bge_factotum_error_handler(bgep); 41371369Sdduvall 41381369Sdduvall /* 41391369Sdduvall * We need to check the link status if: 41401369Sdduvall * the status block says there's been a link change 41411369Sdduvall * or there's any discrepancy between the various 41421369Sdduvall * flags indicating the link state (link_state, 41431369Sdduvall * param_link_up, and the LINK STATE bit in the 41441369Sdduvall * Transmit MAC status register). 41451369Sdduvall */ 41461369Sdduvall check = (flags & STATUS_FLAG_LINK_CHANGED) != 0; 41471369Sdduvall switch (bgep->link_state) { 41481369Sdduvall case LINK_STATE_UP: 41491369Sdduvall check |= (bgep->param_link_up == B_FALSE); 41501369Sdduvall check |= ((tmac_status & TRANSMIT_STATUS_LINK_UP) == 0); 41511369Sdduvall break; 41521369Sdduvall 41531369Sdduvall case LINK_STATE_DOWN: 41541369Sdduvall check |= (bgep->param_link_up != B_FALSE); 41551369Sdduvall check |= ((tmac_status & TRANSMIT_STATUS_LINK_UP) != 0); 41561369Sdduvall break; 41571369Sdduvall 41581369Sdduvall default: 41591369Sdduvall check = B_TRUE; 41601369Sdduvall break; 41611369Sdduvall } 41621369Sdduvall 41631369Sdduvall /* 41641369Sdduvall * If <check> is false, we're sure the link hasn't changed. 41651369Sdduvall * If true, however, it's not yet definitive; we have to call 41661369Sdduvall * bge_phys_check() to determine whether the link has settled 41671369Sdduvall * into a new state yet ... and if it has, then call the link 41681369Sdduvall * state change handler.But when the chip is 5700 in Dell 6650 41691369Sdduvall * ,even if check is false, the link may have changed.So we 41701369Sdduvall * have to call bge_phys_check() to determine the link state. 41711369Sdduvall */ 41721369Sdduvall if (check || bgep->chipid.device == DEVICE_ID_5700) { 41731369Sdduvall check = bge_phys_check(bgep); 41741369Sdduvall if (check) 41751369Sdduvall bge_factotum_link_handler(bgep); 41761369Sdduvall } 41771369Sdduvall 41781369Sdduvall return (check); 41791369Sdduvall } 41801369Sdduvall 41811369Sdduvall /* 41821369Sdduvall * Factotum routine to check for Tx stall, using the 'watchdog' counter 41831369Sdduvall */ 41841369Sdduvall static boolean_t bge_factotum_stall_check(bge_t *bgep); 41851369Sdduvall #pragma no_inline(bge_factotum_stall_check) 41861369Sdduvall 41871369Sdduvall static boolean_t 41881369Sdduvall bge_factotum_stall_check(bge_t *bgep) 41891369Sdduvall { 41901369Sdduvall uint32_t dogval; 41911369Sdduvall 41921369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 41931369Sdduvall 41941369Sdduvall /* 41951369Sdduvall * Specific check for Tx stall ... 41961369Sdduvall * 41971369Sdduvall * The 'watchdog' counter is incremented whenever a packet 41981369Sdduvall * is queued, reset to 1 when some (but not all) buffers 41991369Sdduvall * are reclaimed, reset to 0 (disabled) when all buffers 42001369Sdduvall * are reclaimed, and shifted left here. If it exceeds the 42011369Sdduvall * threshold value, the chip is assumed to have stalled and 42021369Sdduvall * is put into the ERROR state. The factotum will then reset 42031369Sdduvall * it on the next pass. 42041369Sdduvall * 42051369Sdduvall * All of which should ensure that we don't get into a state 42061369Sdduvall * where packets are left pending indefinitely! 42071369Sdduvall */ 42081369Sdduvall dogval = bge_atomic_shl32(&bgep->watchdog, 1); 42091369Sdduvall if (dogval < bge_watchdog_count) 42101369Sdduvall return (B_FALSE); 42111369Sdduvall 42121369Sdduvall BGE_REPORT((bgep, "Tx stall detected, watchdog code 0x%x", dogval)); 42131865Sdilpreet bge_fm_ereport(bgep, DDI_FM_DEVICE_STALL); 42141369Sdduvall return (B_TRUE); 42151369Sdduvall } 42161369Sdduvall 42171369Sdduvall /* 42181369Sdduvall * The factotum is woken up when there's something to do that we'd rather 42191369Sdduvall * not do from inside a hardware interrupt handler or high-level cyclic. 42201369Sdduvall * Its two main tasks are: 42211369Sdduvall * reset & restart the chip after an error 42221369Sdduvall * check the link status whenever necessary 42231369Sdduvall */ 42241369Sdduvall uint_t bge_chip_factotum(caddr_t arg); 42251369Sdduvall #pragma no_inline(bge_chip_factotum) 42261369Sdduvall 42271369Sdduvall uint_t 42281369Sdduvall bge_chip_factotum(caddr_t arg) 42291369Sdduvall { 42301369Sdduvall bge_t *bgep; 42311369Sdduvall uint_t result; 42321369Sdduvall boolean_t error; 42331369Sdduvall boolean_t linkchg; 42341865Sdilpreet int dma_state; 42351369Sdduvall 42361369Sdduvall bgep = (bge_t *)arg; 42371369Sdduvall 42381369Sdduvall BGE_TRACE(("bge_chip_factotum($%p)", (void *)bgep)); 42391369Sdduvall 42401369Sdduvall mutex_enter(bgep->softintrlock); 42411369Sdduvall if (bgep->factotum_flag == 0) { 42421369Sdduvall mutex_exit(bgep->softintrlock); 42431369Sdduvall return (DDI_INTR_UNCLAIMED); 42441369Sdduvall } 42451504Sly149593 bgep->factotum_flag = 0; 42461369Sdduvall mutex_exit(bgep->softintrlock); 42471369Sdduvall 42481369Sdduvall result = DDI_INTR_CLAIMED; 42491369Sdduvall error = B_FALSE; 42501369Sdduvall linkchg = B_FALSE; 42511369Sdduvall 42521369Sdduvall mutex_enter(bgep->genlock); 42531369Sdduvall switch (bgep->bge_chip_state) { 42541369Sdduvall default: 42551369Sdduvall break; 42561369Sdduvall 42571369Sdduvall case BGE_CHIP_RUNNING: 42581865Sdilpreet linkchg = bge_factotum_link_check(bgep, &dma_state); 42591369Sdduvall error = bge_factotum_stall_check(bgep); 42601865Sdilpreet if (dma_state != DDI_FM_OK) { 42611865Sdilpreet bgep->bge_dma_error = B_TRUE; 42621865Sdilpreet error = B_TRUE; 42631865Sdilpreet } 42641865Sdilpreet if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) 42651865Sdilpreet error = B_TRUE; 42661865Sdilpreet if (error) 42671865Sdilpreet bgep->bge_chip_state = BGE_CHIP_ERROR; 42681369Sdduvall break; 42691369Sdduvall 42701369Sdduvall case BGE_CHIP_ERROR: 42711369Sdduvall error = B_TRUE; 42721369Sdduvall break; 42731369Sdduvall 42741369Sdduvall case BGE_CHIP_FAULT: 42751369Sdduvall /* 42761369Sdduvall * Fault detected, time to reset ... 42771369Sdduvall */ 42781369Sdduvall if (bge_autorecover) { 42791865Sdilpreet if (!(bgep->progress & PROGRESS_BUFS)) { 42801865Sdilpreet /* 42811865Sdilpreet * if we can't allocate the ring buffers, 42821865Sdilpreet * try later 42831865Sdilpreet */ 42841865Sdilpreet if (bge_alloc_bufs(bgep) != DDI_SUCCESS) { 42851865Sdilpreet mutex_exit(bgep->genlock); 42861865Sdilpreet return (result); 42871865Sdilpreet } 42881865Sdilpreet bgep->progress |= PROGRESS_BUFS; 42891865Sdilpreet } 42901865Sdilpreet if (!(bgep->progress & PROGRESS_INTR)) { 42911865Sdilpreet bge_init_rings(bgep); 42921865Sdilpreet bge_intr_enable(bgep); 42931865Sdilpreet bgep->progress |= PROGRESS_INTR; 42941865Sdilpreet } 42951865Sdilpreet if (!(bgep->progress & PROGRESS_KSTATS)) { 42961865Sdilpreet bge_init_kstats(bgep, 42971865Sdilpreet ddi_get_instance(bgep->devinfo)); 42981865Sdilpreet bgep->progress |= PROGRESS_KSTATS; 42991865Sdilpreet } 43001865Sdilpreet 43011369Sdduvall BGE_REPORT((bgep, "automatic recovery activated")); 43021865Sdilpreet 43031865Sdilpreet if (bge_restart(bgep, B_FALSE) != DDI_SUCCESS) { 43041865Sdilpreet bgep->bge_chip_state = BGE_CHIP_ERROR; 43051865Sdilpreet error = B_TRUE; 43061865Sdilpreet } 43071865Sdilpreet if (bge_check_acc_handle(bgep, bgep->cfg_handle) != 43081865Sdilpreet DDI_FM_OK) { 43091865Sdilpreet bgep->bge_chip_state = BGE_CHIP_ERROR; 43101865Sdilpreet error = B_TRUE; 43111865Sdilpreet } 43121865Sdilpreet if (bge_check_acc_handle(bgep, bgep->io_handle) != 43131865Sdilpreet DDI_FM_OK) { 43141865Sdilpreet bgep->bge_chip_state = BGE_CHIP_ERROR; 43151865Sdilpreet error = B_TRUE; 43161865Sdilpreet } 43171865Sdilpreet if (error == B_FALSE) { 43181408Srandyf #ifdef BGE_IPMI_ASF 43191865Sdilpreet if (bgep->asf_enabled && 43201865Sdilpreet bgep->asf_status != ASF_STAT_RUN) { 43211408Srandyf bgep->asf_timeout_id = timeout( 43221865Sdilpreet bge_asf_heartbeat, (void *)bgep, 43231865Sdilpreet drv_usectohz( 43241865Sdilpreet BGE_ASF_HEARTBEAT_INTERVAL)); 43251408Srandyf bgep->asf_status = ASF_STAT_RUN; 43261408Srandyf } 43271865Sdilpreet #endif 43281865Sdilpreet ddi_fm_service_impact(bgep->devinfo, 43291865Sdilpreet DDI_SERVICE_RESTORED); 43301408Srandyf } 43311369Sdduvall } 43321369Sdduvall break; 43331369Sdduvall } 43341369Sdduvall 43351865Sdilpreet 43361369Sdduvall /* 43371369Sdduvall * If an error is detected, stop the chip now, marking it as 43381369Sdduvall * faulty, so that it will be reset next time through ... 43391865Sdilpreet * 43401865Sdilpreet * Note that if intr_running is set, then bge_intr() has dropped 43411865Sdilpreet * genlock to call bge_receive/bge_recycle. Can't stop the chip at 43421865Sdilpreet * this point so have to wait until the next time the factotum runs. 43431369Sdduvall */ 43441865Sdilpreet if (error && !bgep->bge_intr_running) { 43451408Srandyf #ifdef BGE_IPMI_ASF 43461408Srandyf if (bgep->asf_enabled && (bgep->asf_status == ASF_STAT_RUN)) { 43471408Srandyf /* 43481408Srandyf * We must stop ASF heart beat before bge_chip_stop(), 43491408Srandyf * otherwise some computers (ex. IBM HS20 blade server) 43501408Srandyf * may crash. 43511408Srandyf */ 43521408Srandyf bge_asf_update_status(bgep); 43531408Srandyf bge_asf_stop_timer(bgep); 43541408Srandyf bgep->asf_status = ASF_STAT_STOP; 43551408Srandyf 43561408Srandyf bge_asf_pre_reset_operations(bgep, BGE_INIT_RESET); 43571865Sdilpreet (void) bge_check_acc_handle(bgep, bgep->cfg_handle); 43581408Srandyf } 43591408Srandyf #endif 43601369Sdduvall bge_chip_stop(bgep, B_TRUE); 43611865Sdilpreet (void) bge_check_acc_handle(bgep, bgep->io_handle); 43621408Srandyf } 43631369Sdduvall mutex_exit(bgep->genlock); 43641369Sdduvall 43651369Sdduvall /* 43661369Sdduvall * If the link state changed, tell the world about it. 43671369Sdduvall * Note: can't do this while still holding the mutex. 43681369Sdduvall */ 43691369Sdduvall if (linkchg) 43702311Sseb mac_link_update(bgep->mh, bgep->link_state); 43711369Sdduvall 43721369Sdduvall return (result); 43731369Sdduvall } 43741369Sdduvall 43751369Sdduvall /* 43761369Sdduvall * High-level cyclic handler 43771369Sdduvall * 43781369Sdduvall * This routine schedules a (low-level) softint callback to the 43791369Sdduvall * factotum, and prods the chip to update the status block (which 43801369Sdduvall * will cause a hardware interrupt when complete). 43811369Sdduvall */ 43821369Sdduvall void bge_chip_cyclic(void *arg); 43831369Sdduvall #pragma no_inline(bge_chip_cyclic) 43841369Sdduvall 43851369Sdduvall void 43861369Sdduvall bge_chip_cyclic(void *arg) 43871369Sdduvall { 43881369Sdduvall bge_t *bgep; 43891369Sdduvall 43901369Sdduvall bgep = arg; 43911369Sdduvall 43921369Sdduvall switch (bgep->bge_chip_state) { 43931369Sdduvall default: 43941369Sdduvall return; 43951369Sdduvall 43961369Sdduvall case BGE_CHIP_RUNNING: 43971369Sdduvall bge_reg_set32(bgep, HOST_COALESCE_MODE_REG, COALESCE_NOW); 43981865Sdilpreet if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) 43991865Sdilpreet ddi_fm_service_impact(bgep->devinfo, 44001865Sdilpreet DDI_SERVICE_UNAFFECTED); 44011369Sdduvall break; 44021369Sdduvall 44031369Sdduvall case BGE_CHIP_FAULT: 44041369Sdduvall case BGE_CHIP_ERROR: 44051369Sdduvall break; 44061369Sdduvall } 44071369Sdduvall 44081369Sdduvall bge_wake_factotum(bgep); 44091369Sdduvall } 44101369Sdduvall 44111369Sdduvall 44121369Sdduvall /* 44131369Sdduvall * ========== Ioctl subfunctions ========== 44141369Sdduvall */ 44151369Sdduvall 44161369Sdduvall #undef BGE_DBG 44171369Sdduvall #define BGE_DBG BGE_DBG_PPIO /* debug flag for this code */ 44181369Sdduvall 44191369Sdduvall #if BGE_DEBUGGING || BGE_DO_PPIO 44201369Sdduvall 44211369Sdduvall static void bge_chip_peek_cfg(bge_t *bgep, bge_peekpoke_t *ppd); 44221369Sdduvall #pragma no_inline(bge_chip_peek_cfg) 44231369Sdduvall 44241369Sdduvall static void 44251369Sdduvall bge_chip_peek_cfg(bge_t *bgep, bge_peekpoke_t *ppd) 44261369Sdduvall { 44271369Sdduvall uint64_t regval; 44281369Sdduvall uint64_t regno; 44291369Sdduvall 44301369Sdduvall BGE_TRACE(("bge_chip_peek_cfg($%p, $%p)", 44311369Sdduvall (void *)bgep, (void *)ppd)); 44321369Sdduvall 44331369Sdduvall regno = ppd->pp_acc_offset; 44341369Sdduvall 44351369Sdduvall switch (ppd->pp_acc_size) { 44361369Sdduvall case 1: 44371369Sdduvall regval = pci_config_get8(bgep->cfg_handle, regno); 44381369Sdduvall break; 44391369Sdduvall 44401369Sdduvall case 2: 44411369Sdduvall regval = pci_config_get16(bgep->cfg_handle, regno); 44421369Sdduvall break; 44431369Sdduvall 44441369Sdduvall case 4: 44451369Sdduvall regval = pci_config_get32(bgep->cfg_handle, regno); 44461369Sdduvall break; 44471369Sdduvall 44481369Sdduvall case 8: 44491369Sdduvall regval = pci_config_get64(bgep->cfg_handle, regno); 44501369Sdduvall break; 44511369Sdduvall } 44521369Sdduvall 44531369Sdduvall ppd->pp_acc_data = regval; 44541369Sdduvall } 44551369Sdduvall 44561369Sdduvall static void bge_chip_poke_cfg(bge_t *bgep, bge_peekpoke_t *ppd); 44571369Sdduvall #pragma no_inline(bge_chip_poke_cfg) 44581369Sdduvall 44591369Sdduvall static void 44601369Sdduvall bge_chip_poke_cfg(bge_t *bgep, bge_peekpoke_t *ppd) 44611369Sdduvall { 44621369Sdduvall uint64_t regval; 44631369Sdduvall uint64_t regno; 44641369Sdduvall 44651369Sdduvall BGE_TRACE(("bge_chip_poke_cfg($%p, $%p)", 44661369Sdduvall (void *)bgep, (void *)ppd)); 44671369Sdduvall 44681369Sdduvall regno = ppd->pp_acc_offset; 44691369Sdduvall regval = ppd->pp_acc_data; 44701369Sdduvall 44711369Sdduvall switch (ppd->pp_acc_size) { 44721369Sdduvall case 1: 44731369Sdduvall pci_config_put8(bgep->cfg_handle, regno, regval); 44741369Sdduvall break; 44751369Sdduvall 44761369Sdduvall case 2: 44771369Sdduvall pci_config_put16(bgep->cfg_handle, regno, regval); 44781369Sdduvall break; 44791369Sdduvall 44801369Sdduvall case 4: 44811369Sdduvall pci_config_put32(bgep->cfg_handle, regno, regval); 44821369Sdduvall break; 44831369Sdduvall 44841369Sdduvall case 8: 44851369Sdduvall pci_config_put64(bgep->cfg_handle, regno, regval); 44861369Sdduvall break; 44871369Sdduvall } 44881369Sdduvall } 44891369Sdduvall 44901369Sdduvall static void bge_chip_peek_reg(bge_t *bgep, bge_peekpoke_t *ppd); 44911369Sdduvall #pragma no_inline(bge_chip_peek_reg) 44921369Sdduvall 44931369Sdduvall static void 44941369Sdduvall bge_chip_peek_reg(bge_t *bgep, bge_peekpoke_t *ppd) 44951369Sdduvall { 44961369Sdduvall uint64_t regval; 44971369Sdduvall void *regaddr; 44981369Sdduvall 44991369Sdduvall BGE_TRACE(("bge_chip_peek_reg($%p, $%p)", 45001369Sdduvall (void *)bgep, (void *)ppd)); 45011369Sdduvall 45021369Sdduvall regaddr = PIO_ADDR(bgep, ppd->pp_acc_offset); 45031369Sdduvall 45041369Sdduvall switch (ppd->pp_acc_size) { 45051369Sdduvall case 1: 45061369Sdduvall regval = ddi_get8(bgep->io_handle, regaddr); 45071369Sdduvall break; 45081369Sdduvall 45091369Sdduvall case 2: 45101369Sdduvall regval = ddi_get16(bgep->io_handle, regaddr); 45111369Sdduvall break; 45121369Sdduvall 45131369Sdduvall case 4: 45141369Sdduvall regval = ddi_get32(bgep->io_handle, regaddr); 45151369Sdduvall break; 45161369Sdduvall 45171369Sdduvall case 8: 45181369Sdduvall regval = ddi_get64(bgep->io_handle, regaddr); 45191369Sdduvall break; 45201369Sdduvall } 45211369Sdduvall 45221369Sdduvall ppd->pp_acc_data = regval; 45231369Sdduvall } 45241369Sdduvall 45251369Sdduvall static void bge_chip_poke_reg(bge_t *bgep, bge_peekpoke_t *ppd); 45261369Sdduvall #pragma no_inline(bge_chip_peek_reg) 45271369Sdduvall 45281369Sdduvall static void 45291369Sdduvall bge_chip_poke_reg(bge_t *bgep, bge_peekpoke_t *ppd) 45301369Sdduvall { 45311369Sdduvall uint64_t regval; 45321369Sdduvall void *regaddr; 45331369Sdduvall 45341369Sdduvall BGE_TRACE(("bge_chip_poke_reg($%p, $%p)", 45351369Sdduvall (void *)bgep, (void *)ppd)); 45361369Sdduvall 45371369Sdduvall regaddr = PIO_ADDR(bgep, ppd->pp_acc_offset); 45381369Sdduvall regval = ppd->pp_acc_data; 45391369Sdduvall 45401369Sdduvall switch (ppd->pp_acc_size) { 45411369Sdduvall case 1: 45421369Sdduvall ddi_put8(bgep->io_handle, regaddr, regval); 45431369Sdduvall break; 45441369Sdduvall 45451369Sdduvall case 2: 45461369Sdduvall ddi_put16(bgep->io_handle, regaddr, regval); 45471369Sdduvall break; 45481369Sdduvall 45491369Sdduvall case 4: 45501369Sdduvall ddi_put32(bgep->io_handle, regaddr, regval); 45511369Sdduvall break; 45521369Sdduvall 45531369Sdduvall case 8: 45541369Sdduvall ddi_put64(bgep->io_handle, regaddr, regval); 45551369Sdduvall break; 45561369Sdduvall } 45571369Sdduvall BGE_PCICHK(bgep); 45581369Sdduvall } 45591369Sdduvall 45601369Sdduvall static void bge_chip_peek_nic(bge_t *bgep, bge_peekpoke_t *ppd); 45611369Sdduvall #pragma no_inline(bge_chip_peek_nic) 45621369Sdduvall 45631369Sdduvall static void 45641369Sdduvall bge_chip_peek_nic(bge_t *bgep, bge_peekpoke_t *ppd) 45651369Sdduvall { 45661369Sdduvall uint64_t regoff; 45671369Sdduvall uint64_t regval; 45681369Sdduvall void *regaddr; 45691369Sdduvall 45701369Sdduvall BGE_TRACE(("bge_chip_peek_nic($%p, $%p)", 45711369Sdduvall (void *)bgep, (void *)ppd)); 45721369Sdduvall 45731369Sdduvall regoff = ppd->pp_acc_offset; 45741369Sdduvall bge_nic_setwin(bgep, regoff & ~MWBAR_GRANULE_MASK); 45751369Sdduvall regoff &= MWBAR_GRANULE_MASK; 45761369Sdduvall regoff += NIC_MEM_WINDOW_OFFSET; 45771369Sdduvall regaddr = PIO_ADDR(bgep, regoff); 45781369Sdduvall 45791369Sdduvall switch (ppd->pp_acc_size) { 45801369Sdduvall case 1: 45811369Sdduvall regval = ddi_get8(bgep->io_handle, regaddr); 45821369Sdduvall break; 45831369Sdduvall 45841369Sdduvall case 2: 45851369Sdduvall regval = ddi_get16(bgep->io_handle, regaddr); 45861369Sdduvall break; 45871369Sdduvall 45881369Sdduvall case 4: 45891369Sdduvall regval = ddi_get32(bgep->io_handle, regaddr); 45901369Sdduvall break; 45911369Sdduvall 45921369Sdduvall case 8: 45931369Sdduvall regval = ddi_get64(bgep->io_handle, regaddr); 45941369Sdduvall break; 45951369Sdduvall } 45961369Sdduvall 45971369Sdduvall ppd->pp_acc_data = regval; 45981369Sdduvall } 45991369Sdduvall 46001369Sdduvall static void bge_chip_poke_nic(bge_t *bgep, bge_peekpoke_t *ppd); 46011369Sdduvall #pragma no_inline(bge_chip_poke_nic) 46021369Sdduvall 46031369Sdduvall static void 46041369Sdduvall bge_chip_poke_nic(bge_t *bgep, bge_peekpoke_t *ppd) 46051369Sdduvall { 46061369Sdduvall uint64_t regoff; 46071369Sdduvall uint64_t regval; 46081369Sdduvall void *regaddr; 46091369Sdduvall 46101369Sdduvall BGE_TRACE(("bge_chip_poke_nic($%p, $%p)", 46111369Sdduvall (void *)bgep, (void *)ppd)); 46121369Sdduvall 46131369Sdduvall regoff = ppd->pp_acc_offset; 46141369Sdduvall bge_nic_setwin(bgep, regoff & ~MWBAR_GRANULE_MASK); 46151369Sdduvall regoff &= MWBAR_GRANULE_MASK; 46161369Sdduvall regoff += NIC_MEM_WINDOW_OFFSET; 46171369Sdduvall regaddr = PIO_ADDR(bgep, regoff); 46181369Sdduvall regval = ppd->pp_acc_data; 46191369Sdduvall 46201369Sdduvall switch (ppd->pp_acc_size) { 46211369Sdduvall case 1: 46221369Sdduvall ddi_put8(bgep->io_handle, regaddr, regval); 46231369Sdduvall break; 46241369Sdduvall 46251369Sdduvall case 2: 46261369Sdduvall ddi_put16(bgep->io_handle, regaddr, regval); 46271369Sdduvall break; 46281369Sdduvall 46291369Sdduvall case 4: 46301369Sdduvall ddi_put32(bgep->io_handle, regaddr, regval); 46311369Sdduvall break; 46321369Sdduvall 46331369Sdduvall case 8: 46341369Sdduvall ddi_put64(bgep->io_handle, regaddr, regval); 46351369Sdduvall break; 46361369Sdduvall } 46371369Sdduvall BGE_PCICHK(bgep); 46381369Sdduvall } 46391369Sdduvall 46401369Sdduvall static void bge_chip_peek_mii(bge_t *bgep, bge_peekpoke_t *ppd); 46411369Sdduvall #pragma no_inline(bge_chip_peek_mii) 46421369Sdduvall 46431369Sdduvall static void 46441369Sdduvall bge_chip_peek_mii(bge_t *bgep, bge_peekpoke_t *ppd) 46451369Sdduvall { 46461369Sdduvall BGE_TRACE(("bge_chip_peek_mii($%p, $%p)", 46471369Sdduvall (void *)bgep, (void *)ppd)); 46481369Sdduvall 46491369Sdduvall ppd->pp_acc_data = bge_mii_get16(bgep, ppd->pp_acc_offset/2); 46501369Sdduvall } 46511369Sdduvall 46521369Sdduvall static void bge_chip_poke_mii(bge_t *bgep, bge_peekpoke_t *ppd); 46531369Sdduvall #pragma no_inline(bge_chip_poke_mii) 46541369Sdduvall 46551369Sdduvall static void 46561369Sdduvall bge_chip_poke_mii(bge_t *bgep, bge_peekpoke_t *ppd) 46571369Sdduvall { 46581369Sdduvall BGE_TRACE(("bge_chip_poke_mii($%p, $%p)", 46591369Sdduvall (void *)bgep, (void *)ppd)); 46601369Sdduvall 46611369Sdduvall bge_mii_put16(bgep, ppd->pp_acc_offset/2, ppd->pp_acc_data); 46621369Sdduvall } 46631369Sdduvall 46641369Sdduvall #if BGE_SEE_IO32 46651369Sdduvall 46661369Sdduvall static void bge_chip_peek_seeprom(bge_t *bgep, bge_peekpoke_t *ppd); 46671369Sdduvall #pragma no_inline(bge_chip_peek_seeprom) 46681369Sdduvall 46691369Sdduvall static void 46701369Sdduvall bge_chip_peek_seeprom(bge_t *bgep, bge_peekpoke_t *ppd) 46711369Sdduvall { 46721369Sdduvall uint32_t data; 46731369Sdduvall int err; 46741369Sdduvall 46751369Sdduvall BGE_TRACE(("bge_chip_peek_seeprom($%p, $%p)", 46761369Sdduvall (void *)bgep, (void *)ppd)); 46771369Sdduvall 46781369Sdduvall err = bge_nvmem_rw32(bgep, BGE_SEE_READ, ppd->pp_acc_offset, &data); 46791369Sdduvall ppd->pp_acc_data = err ? ~0ull : data; 46801369Sdduvall } 46811369Sdduvall 46821369Sdduvall static void bge_chip_poke_seeprom(bge_t *bgep, bge_peekpoke_t *ppd); 46831369Sdduvall #pragma no_inline(bge_chip_poke_seeprom) 46841369Sdduvall 46851369Sdduvall static void 46861369Sdduvall bge_chip_poke_seeprom(bge_t *bgep, bge_peekpoke_t *ppd) 46871369Sdduvall { 46881369Sdduvall uint32_t data; 46891369Sdduvall 46901369Sdduvall BGE_TRACE(("bge_chip_poke_seeprom($%p, $%p)", 46911369Sdduvall (void *)bgep, (void *)ppd)); 46921369Sdduvall 46931369Sdduvall data = ppd->pp_acc_data; 46941369Sdduvall (void) bge_nvmem_rw32(bgep, BGE_SEE_WRITE, ppd->pp_acc_offset, &data); 46951369Sdduvall } 46961369Sdduvall #endif /* BGE_SEE_IO32 */ 46971369Sdduvall 46981369Sdduvall #if BGE_FLASH_IO32 46991369Sdduvall 47001369Sdduvall static void bge_chip_peek_flash(bge_t *bgep, bge_peekpoke_t *ppd); 47011369Sdduvall #pragma no_inline(bge_chip_peek_flash) 47021369Sdduvall 47031369Sdduvall static void 47041369Sdduvall bge_chip_peek_flash(bge_t *bgep, bge_peekpoke_t *ppd) 47051369Sdduvall { 47061369Sdduvall uint32_t data; 47071369Sdduvall int err; 47081369Sdduvall 47091369Sdduvall BGE_TRACE(("bge_chip_peek_flash($%p, $%p)", 47101369Sdduvall (void *)bgep, (void *)ppd)); 47111369Sdduvall 47121369Sdduvall err = bge_nvmem_rw32(bgep, BGE_FLASH_READ, ppd->pp_acc_offset, &data); 47131369Sdduvall ppd->pp_acc_data = err ? ~0ull : data; 47141369Sdduvall } 47151369Sdduvall 47161369Sdduvall static void bge_chip_poke_flash(bge_t *bgep, bge_peekpoke_t *ppd); 47171369Sdduvall #pragma no_inline(bge_chip_poke_flash) 47181369Sdduvall 47191369Sdduvall static void 47201369Sdduvall bge_chip_poke_flash(bge_t *bgep, bge_peekpoke_t *ppd) 47211369Sdduvall { 47221369Sdduvall uint32_t data; 47231369Sdduvall 47241369Sdduvall BGE_TRACE(("bge_chip_poke_flash($%p, $%p)", 47251369Sdduvall (void *)bgep, (void *)ppd)); 47261369Sdduvall 47271369Sdduvall data = ppd->pp_acc_data; 47281369Sdduvall (void) bge_nvmem_rw32(bgep, BGE_FLASH_WRITE, 47291369Sdduvall ppd->pp_acc_offset, &data); 47301369Sdduvall } 47311369Sdduvall #endif /* BGE_FLASH_IO32 */ 47321369Sdduvall 47331369Sdduvall static void bge_chip_peek_mem(bge_t *bgep, bge_peekpoke_t *ppd); 47341369Sdduvall #pragma no_inline(bge_chip_peek_mem) 47351369Sdduvall 47361369Sdduvall static void 47371369Sdduvall bge_chip_peek_mem(bge_t *bgep, bge_peekpoke_t *ppd) 47381369Sdduvall { 47391369Sdduvall uint64_t regval; 47401369Sdduvall void *vaddr; 47411369Sdduvall 47421369Sdduvall BGE_TRACE(("bge_chip_peek_bge($%p, $%p)", 47431369Sdduvall (void *)bgep, (void *)ppd)); 47441369Sdduvall 47451369Sdduvall vaddr = (void *)(uintptr_t)ppd->pp_acc_offset; 47461369Sdduvall 47471369Sdduvall switch (ppd->pp_acc_size) { 47481369Sdduvall case 1: 47491369Sdduvall regval = *(uint8_t *)vaddr; 47501369Sdduvall break; 47511369Sdduvall 47521369Sdduvall case 2: 47531369Sdduvall regval = *(uint16_t *)vaddr; 47541369Sdduvall break; 47551369Sdduvall 47561369Sdduvall case 4: 47571369Sdduvall regval = *(uint32_t *)vaddr; 47581369Sdduvall break; 47591369Sdduvall 47601369Sdduvall case 8: 47611369Sdduvall regval = *(uint64_t *)vaddr; 47621369Sdduvall break; 47631369Sdduvall } 47641369Sdduvall 47651369Sdduvall BGE_DEBUG(("bge_chip_peek_mem($%p, $%p) peeked 0x%llx from $%p", 47661369Sdduvall (void *)bgep, (void *)ppd, regval, vaddr)); 47671369Sdduvall 47681369Sdduvall ppd->pp_acc_data = regval; 47691369Sdduvall } 47701369Sdduvall 47711369Sdduvall static void bge_chip_poke_mem(bge_t *bgep, bge_peekpoke_t *ppd); 47721369Sdduvall #pragma no_inline(bge_chip_poke_mem) 47731369Sdduvall 47741369Sdduvall static void 47751369Sdduvall bge_chip_poke_mem(bge_t *bgep, bge_peekpoke_t *ppd) 47761369Sdduvall { 47771369Sdduvall uint64_t regval; 47781369Sdduvall void *vaddr; 47791369Sdduvall 47801369Sdduvall BGE_TRACE(("bge_chip_poke_mem($%p, $%p)", 47811369Sdduvall (void *)bgep, (void *)ppd)); 47821369Sdduvall 47831369Sdduvall vaddr = (void *)(uintptr_t)ppd->pp_acc_offset; 47841369Sdduvall regval = ppd->pp_acc_data; 47851369Sdduvall 47861369Sdduvall BGE_DEBUG(("bge_chip_poke_mem($%p, $%p) poking 0x%llx at $%p", 47871369Sdduvall (void *)bgep, (void *)ppd, regval, vaddr)); 47881369Sdduvall 47891369Sdduvall switch (ppd->pp_acc_size) { 47901369Sdduvall case 1: 47911369Sdduvall *(uint8_t *)vaddr = (uint8_t)regval; 47921369Sdduvall break; 47931369Sdduvall 47941369Sdduvall case 2: 47951369Sdduvall *(uint16_t *)vaddr = (uint16_t)regval; 47961369Sdduvall break; 47971369Sdduvall 47981369Sdduvall case 4: 47991369Sdduvall *(uint32_t *)vaddr = (uint32_t)regval; 48001369Sdduvall break; 48011369Sdduvall 48021369Sdduvall case 8: 48031369Sdduvall *(uint64_t *)vaddr = (uint64_t)regval; 48041369Sdduvall break; 48051369Sdduvall } 48061369Sdduvall } 48071369Sdduvall 48081369Sdduvall static enum ioc_reply bge_pp_ioctl(bge_t *bgep, int cmd, mblk_t *mp, 48091369Sdduvall struct iocblk *iocp); 48101369Sdduvall #pragma no_inline(bge_pp_ioctl) 48111369Sdduvall 48121369Sdduvall static enum ioc_reply 48131369Sdduvall bge_pp_ioctl(bge_t *bgep, int cmd, mblk_t *mp, struct iocblk *iocp) 48141369Sdduvall { 48151369Sdduvall void (*ppfn)(bge_t *bgep, bge_peekpoke_t *ppd); 48161369Sdduvall bge_peekpoke_t *ppd; 48171369Sdduvall dma_area_t *areap; 48181369Sdduvall uint64_t sizemask; 48191369Sdduvall uint64_t mem_va; 48201369Sdduvall uint64_t maxoff; 48211369Sdduvall boolean_t peek; 48221369Sdduvall 48231369Sdduvall switch (cmd) { 48241369Sdduvall default: 48251369Sdduvall /* NOTREACHED */ 48261369Sdduvall bge_error(bgep, "bge_pp_ioctl: invalid cmd 0x%x", cmd); 48271369Sdduvall return (IOC_INVAL); 48281369Sdduvall 48291369Sdduvall case BGE_PEEK: 48301369Sdduvall peek = B_TRUE; 48311369Sdduvall break; 48321369Sdduvall 48331369Sdduvall case BGE_POKE: 48341369Sdduvall peek = B_FALSE; 48351369Sdduvall break; 48361369Sdduvall } 48371369Sdduvall 48381369Sdduvall /* 48391369Sdduvall * Validate format of ioctl 48401369Sdduvall */ 48411369Sdduvall if (iocp->ioc_count != sizeof (bge_peekpoke_t)) 48421369Sdduvall return (IOC_INVAL); 48431369Sdduvall if (mp->b_cont == NULL) 48441369Sdduvall return (IOC_INVAL); 48451369Sdduvall ppd = (bge_peekpoke_t *)mp->b_cont->b_rptr; 48461369Sdduvall 48471369Sdduvall /* 48481369Sdduvall * Validate request parameters 48491369Sdduvall */ 48501369Sdduvall switch (ppd->pp_acc_space) { 48511369Sdduvall default: 48521369Sdduvall return (IOC_INVAL); 48531369Sdduvall 48541369Sdduvall case BGE_PP_SPACE_CFG: 48551369Sdduvall /* 48561369Sdduvall * Config space 48571369Sdduvall */ 48581369Sdduvall sizemask = 8|4|2|1; 48591369Sdduvall mem_va = 0; 48601369Sdduvall maxoff = PCI_CONF_HDR_SIZE; 48611369Sdduvall ppfn = peek ? bge_chip_peek_cfg : bge_chip_poke_cfg; 48621369Sdduvall break; 48631369Sdduvall 48641369Sdduvall case BGE_PP_SPACE_REG: 48651369Sdduvall /* 48661369Sdduvall * Memory-mapped I/O space 48671369Sdduvall */ 48681369Sdduvall sizemask = 8|4|2|1; 48691369Sdduvall mem_va = 0; 48701369Sdduvall maxoff = RIAAR_REGISTER_MAX; 48711369Sdduvall ppfn = peek ? bge_chip_peek_reg : bge_chip_poke_reg; 48721369Sdduvall break; 48731369Sdduvall 48741369Sdduvall case BGE_PP_SPACE_NIC: 48751369Sdduvall /* 48761369Sdduvall * NIC on-chip memory 48771369Sdduvall */ 48781369Sdduvall sizemask = 8|4|2|1; 48791369Sdduvall mem_va = 0; 48801369Sdduvall maxoff = MWBAR_ONCHIP_MAX; 48811369Sdduvall ppfn = peek ? bge_chip_peek_nic : bge_chip_poke_nic; 48821369Sdduvall break; 48831369Sdduvall 48841369Sdduvall case BGE_PP_SPACE_MII: 48851369Sdduvall /* 48861369Sdduvall * PHY's MII registers 48871369Sdduvall * NB: all PHY registers are two bytes, but the 48881369Sdduvall * addresses increment in ones (word addressing). 48891369Sdduvall * So we scale the address here, then undo the 48901369Sdduvall * transformation inside the peek/poke functions. 48911369Sdduvall */ 48921369Sdduvall ppd->pp_acc_offset *= 2; 48931369Sdduvall sizemask = 2; 48941369Sdduvall mem_va = 0; 48951369Sdduvall maxoff = (MII_MAXREG+1)*2; 48961369Sdduvall ppfn = peek ? bge_chip_peek_mii : bge_chip_poke_mii; 48971369Sdduvall break; 48981369Sdduvall 48991369Sdduvall #if BGE_SEE_IO32 49001369Sdduvall case BGE_PP_SPACE_SEEPROM: 49011369Sdduvall /* 49021369Sdduvall * Attached SEEPROM(s), if any. 49031369Sdduvall * NB: we use the high-order bits of the 'address' as 49041369Sdduvall * a device select to accommodate multiple SEEPROMS, 49051369Sdduvall * If each one is the maximum size (64kbytes), this 49061369Sdduvall * makes them appear contiguous. Otherwise, there may 49071369Sdduvall * be holes in the mapping. ENxS doesn't have any 49081369Sdduvall * SEEPROMs anyway ... 49091369Sdduvall */ 49101369Sdduvall sizemask = 4; 49111369Sdduvall mem_va = 0; 49121369Sdduvall maxoff = SEEPROM_DEV_AND_ADDR_MASK; 49131369Sdduvall ppfn = peek ? bge_chip_peek_seeprom : bge_chip_poke_seeprom; 49141369Sdduvall break; 49151369Sdduvall #endif /* BGE_SEE_IO32 */ 49161369Sdduvall 49171369Sdduvall #if BGE_FLASH_IO32 49181369Sdduvall case BGE_PP_SPACE_FLASH: 49191369Sdduvall /* 49201369Sdduvall * Attached Flash device (if any); a maximum of one device 49211369Sdduvall * is currently supported. But it can be up to 1MB (unlike 49221369Sdduvall * the 64k limit on SEEPROMs) so why would you need more ;-) 49231369Sdduvall */ 49241369Sdduvall sizemask = 4; 49251369Sdduvall mem_va = 0; 49261369Sdduvall maxoff = NVM_FLASH_ADDR_MASK; 49271369Sdduvall ppfn = peek ? bge_chip_peek_flash : bge_chip_poke_flash; 49281369Sdduvall break; 49291369Sdduvall #endif /* BGE_FLASH_IO32 */ 49301369Sdduvall 49311369Sdduvall case BGE_PP_SPACE_BGE: 49321369Sdduvall /* 49331369Sdduvall * BGE data structure! 49341369Sdduvall */ 49351369Sdduvall sizemask = 8|4|2|1; 49361369Sdduvall mem_va = (uintptr_t)bgep; 49371369Sdduvall maxoff = sizeof (*bgep); 49381369Sdduvall ppfn = peek ? bge_chip_peek_mem : bge_chip_poke_mem; 49391369Sdduvall break; 49401369Sdduvall 49411369Sdduvall case BGE_PP_SPACE_STATUS: 49421369Sdduvall case BGE_PP_SPACE_STATISTICS: 49431369Sdduvall case BGE_PP_SPACE_TXDESC: 49441369Sdduvall case BGE_PP_SPACE_TXBUFF: 49451369Sdduvall case BGE_PP_SPACE_RXDESC: 49461369Sdduvall case BGE_PP_SPACE_RXBUFF: 49471369Sdduvall /* 49481369Sdduvall * Various DMA_AREAs 49491369Sdduvall */ 49501369Sdduvall switch (ppd->pp_acc_space) { 49511369Sdduvall case BGE_PP_SPACE_TXDESC: 49521369Sdduvall areap = &bgep->tx_desc; 49531369Sdduvall break; 49541369Sdduvall case BGE_PP_SPACE_TXBUFF: 49551369Sdduvall areap = &bgep->tx_buff[0]; 49561369Sdduvall break; 49571369Sdduvall case BGE_PP_SPACE_RXDESC: 49581369Sdduvall areap = &bgep->rx_desc[0]; 49591369Sdduvall break; 49601369Sdduvall case BGE_PP_SPACE_RXBUFF: 49611369Sdduvall areap = &bgep->rx_buff[0]; 49621369Sdduvall break; 49631369Sdduvall case BGE_PP_SPACE_STATUS: 49641369Sdduvall areap = &bgep->status_block; 49651369Sdduvall break; 49661369Sdduvall case BGE_PP_SPACE_STATISTICS: 49671369Sdduvall if (bgep->chipid.statistic_type == BGE_STAT_BLK) 49681369Sdduvall areap = &bgep->statistics; 49691369Sdduvall break; 49701369Sdduvall } 49711369Sdduvall 49721369Sdduvall sizemask = 8|4|2|1; 49731369Sdduvall mem_va = (uintptr_t)areap->mem_va; 49741369Sdduvall maxoff = areap->alength; 49751369Sdduvall ppfn = peek ? bge_chip_peek_mem : bge_chip_poke_mem; 49761369Sdduvall break; 49771369Sdduvall } 49781369Sdduvall 49791369Sdduvall switch (ppd->pp_acc_size) { 49801369Sdduvall default: 49811369Sdduvall return (IOC_INVAL); 49821369Sdduvall 49831369Sdduvall case 8: 49841369Sdduvall case 4: 49851369Sdduvall case 2: 49861369Sdduvall case 1: 49871369Sdduvall if ((ppd->pp_acc_size & sizemask) == 0) 49881369Sdduvall return (IOC_INVAL); 49891369Sdduvall break; 49901369Sdduvall } 49911369Sdduvall 49921369Sdduvall if ((ppd->pp_acc_offset % ppd->pp_acc_size) != 0) 49931369Sdduvall return (IOC_INVAL); 49941369Sdduvall 49951369Sdduvall if (ppd->pp_acc_offset >= maxoff) 49961369Sdduvall return (IOC_INVAL); 49971369Sdduvall 49981369Sdduvall if (ppd->pp_acc_offset+ppd->pp_acc_size > maxoff) 49991369Sdduvall return (IOC_INVAL); 50001369Sdduvall 50011369Sdduvall /* 50021369Sdduvall * All OK - go do it! 50031369Sdduvall */ 50041369Sdduvall ppd->pp_acc_offset += mem_va; 50051369Sdduvall (*ppfn)(bgep, ppd); 50061369Sdduvall return (peek ? IOC_REPLY : IOC_ACK); 50071369Sdduvall } 50081369Sdduvall 50091369Sdduvall static enum ioc_reply bge_diag_ioctl(bge_t *bgep, int cmd, mblk_t *mp, 50101369Sdduvall struct iocblk *iocp); 50111369Sdduvall #pragma no_inline(bge_diag_ioctl) 50121369Sdduvall 50131369Sdduvall static enum ioc_reply 50141369Sdduvall bge_diag_ioctl(bge_t *bgep, int cmd, mblk_t *mp, struct iocblk *iocp) 50151369Sdduvall { 50161369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 50171369Sdduvall 50181369Sdduvall switch (cmd) { 50191369Sdduvall default: 50201369Sdduvall /* NOTREACHED */ 50211369Sdduvall bge_error(bgep, "bge_diag_ioctl: invalid cmd 0x%x", cmd); 50221369Sdduvall return (IOC_INVAL); 50231369Sdduvall 50241369Sdduvall case BGE_DIAG: 50251369Sdduvall /* 50261369Sdduvall * Currently a no-op 50271369Sdduvall */ 50281369Sdduvall return (IOC_ACK); 50291369Sdduvall 50301369Sdduvall case BGE_PEEK: 50311369Sdduvall case BGE_POKE: 50321369Sdduvall return (bge_pp_ioctl(bgep, cmd, mp, iocp)); 50331369Sdduvall 50341369Sdduvall case BGE_PHY_RESET: 50351369Sdduvall return (IOC_RESTART_ACK); 50361369Sdduvall 50371369Sdduvall case BGE_SOFT_RESET: 50381369Sdduvall case BGE_HARD_RESET: 50391369Sdduvall /* 50401369Sdduvall * Reset and reinitialise the 570x hardware 50411369Sdduvall */ 50421865Sdilpreet (void) bge_restart(bgep, cmd == BGE_HARD_RESET); 50431369Sdduvall return (IOC_ACK); 50441369Sdduvall } 50451369Sdduvall 50461369Sdduvall /* NOTREACHED */ 50471369Sdduvall } 50481369Sdduvall 50491369Sdduvall #endif /* BGE_DEBUGGING || BGE_DO_PPIO */ 50501369Sdduvall 50511369Sdduvall static enum ioc_reply bge_mii_ioctl(bge_t *bgep, int cmd, mblk_t *mp, 50521369Sdduvall struct iocblk *iocp); 50531369Sdduvall #pragma no_inline(bge_mii_ioctl) 50541369Sdduvall 50551369Sdduvall static enum ioc_reply 50561369Sdduvall bge_mii_ioctl(bge_t *bgep, int cmd, mblk_t *mp, struct iocblk *iocp) 50571369Sdduvall { 50581369Sdduvall struct bge_mii_rw *miirwp; 50591369Sdduvall 50601369Sdduvall /* 50611369Sdduvall * Validate format of ioctl 50621369Sdduvall */ 50631369Sdduvall if (iocp->ioc_count != sizeof (struct bge_mii_rw)) 50641369Sdduvall return (IOC_INVAL); 50651369Sdduvall if (mp->b_cont == NULL) 50661369Sdduvall return (IOC_INVAL); 50671369Sdduvall miirwp = (struct bge_mii_rw *)mp->b_cont->b_rptr; 50681369Sdduvall 50691369Sdduvall /* 50701369Sdduvall * Validate request parameters ... 50711369Sdduvall */ 50721369Sdduvall if (miirwp->mii_reg > MII_MAXREG) 50731369Sdduvall return (IOC_INVAL); 50741369Sdduvall 50751369Sdduvall switch (cmd) { 50761369Sdduvall default: 50771369Sdduvall /* NOTREACHED */ 50781369Sdduvall bge_error(bgep, "bge_mii_ioctl: invalid cmd 0x%x", cmd); 50791369Sdduvall return (IOC_INVAL); 50801369Sdduvall 50811369Sdduvall case BGE_MII_READ: 50821369Sdduvall miirwp->mii_data = bge_mii_get16(bgep, miirwp->mii_reg); 50831369Sdduvall return (IOC_REPLY); 50841369Sdduvall 50851369Sdduvall case BGE_MII_WRITE: 50861369Sdduvall bge_mii_put16(bgep, miirwp->mii_reg, miirwp->mii_data); 50871369Sdduvall return (IOC_ACK); 50881369Sdduvall } 50891369Sdduvall 50901369Sdduvall /* NOTREACHED */ 50911369Sdduvall } 50921369Sdduvall 50931369Sdduvall #if BGE_SEE_IO32 50941369Sdduvall 50951369Sdduvall static enum ioc_reply bge_see_ioctl(bge_t *bgep, int cmd, mblk_t *mp, 50961369Sdduvall struct iocblk *iocp); 50971369Sdduvall #pragma no_inline(bge_see_ioctl) 50981369Sdduvall 50991369Sdduvall static enum ioc_reply 51001369Sdduvall bge_see_ioctl(bge_t *bgep, int cmd, mblk_t *mp, struct iocblk *iocp) 51011369Sdduvall { 51021369Sdduvall struct bge_see_rw *seerwp; 51031369Sdduvall 51041369Sdduvall /* 51051369Sdduvall * Validate format of ioctl 51061369Sdduvall */ 51071369Sdduvall if (iocp->ioc_count != sizeof (struct bge_see_rw)) 51081369Sdduvall return (IOC_INVAL); 51091369Sdduvall if (mp->b_cont == NULL) 51101369Sdduvall return (IOC_INVAL); 51111369Sdduvall seerwp = (struct bge_see_rw *)mp->b_cont->b_rptr; 51121369Sdduvall 51131369Sdduvall /* 51141369Sdduvall * Validate request parameters ... 51151369Sdduvall */ 51161369Sdduvall if (seerwp->see_addr & ~SEEPROM_DEV_AND_ADDR_MASK) 51171369Sdduvall return (IOC_INVAL); 51181369Sdduvall 51191369Sdduvall switch (cmd) { 51201369Sdduvall default: 51211369Sdduvall /* NOTREACHED */ 51221369Sdduvall bge_error(bgep, "bge_see_ioctl: invalid cmd 0x%x", cmd); 51231369Sdduvall return (IOC_INVAL); 51241369Sdduvall 51251369Sdduvall case BGE_SEE_READ: 51261369Sdduvall case BGE_SEE_WRITE: 51271369Sdduvall iocp->ioc_error = bge_nvmem_rw32(bgep, cmd, 51281369Sdduvall seerwp->see_addr, &seerwp->see_data); 51291369Sdduvall return (IOC_REPLY); 51301369Sdduvall } 51311369Sdduvall 51321369Sdduvall /* NOTREACHED */ 51331369Sdduvall } 51341369Sdduvall 51351369Sdduvall #endif /* BGE_SEE_IO32 */ 51361369Sdduvall 51371369Sdduvall #if BGE_FLASH_IO32 51381369Sdduvall 51391369Sdduvall static enum ioc_reply bge_flash_ioctl(bge_t *bgep, int cmd, mblk_t *mp, 51401369Sdduvall struct iocblk *iocp); 51411369Sdduvall #pragma no_inline(bge_flash_ioctl) 51421369Sdduvall 51431369Sdduvall static enum ioc_reply 51441369Sdduvall bge_flash_ioctl(bge_t *bgep, int cmd, mblk_t *mp, struct iocblk *iocp) 51451369Sdduvall { 51461369Sdduvall struct bge_flash_rw *flashrwp; 51471369Sdduvall 51481369Sdduvall /* 51491369Sdduvall * Validate format of ioctl 51501369Sdduvall */ 51511369Sdduvall if (iocp->ioc_count != sizeof (struct bge_flash_rw)) 51521369Sdduvall return (IOC_INVAL); 51531369Sdduvall if (mp->b_cont == NULL) 51541369Sdduvall return (IOC_INVAL); 51551369Sdduvall flashrwp = (struct bge_flash_rw *)mp->b_cont->b_rptr; 51561369Sdduvall 51571369Sdduvall /* 51581369Sdduvall * Validate request parameters ... 51591369Sdduvall */ 51601369Sdduvall if (flashrwp->flash_addr & ~NVM_FLASH_ADDR_MASK) 51611369Sdduvall return (IOC_INVAL); 51621369Sdduvall 51631369Sdduvall switch (cmd) { 51641369Sdduvall default: 51651369Sdduvall /* NOTREACHED */ 51661369Sdduvall bge_error(bgep, "bge_flash_ioctl: invalid cmd 0x%x", cmd); 51671369Sdduvall return (IOC_INVAL); 51681369Sdduvall 51691369Sdduvall case BGE_FLASH_READ: 51701369Sdduvall case BGE_FLASH_WRITE: 51711369Sdduvall iocp->ioc_error = bge_nvmem_rw32(bgep, cmd, 51721369Sdduvall flashrwp->flash_addr, &flashrwp->flash_data); 51731369Sdduvall return (IOC_REPLY); 51741369Sdduvall } 51751369Sdduvall 51761369Sdduvall /* NOTREACHED */ 51771369Sdduvall } 51781369Sdduvall 51791369Sdduvall #endif /* BGE_FLASH_IO32 */ 51801369Sdduvall 51811369Sdduvall enum ioc_reply bge_chip_ioctl(bge_t *bgep, queue_t *wq, mblk_t *mp, 51821369Sdduvall struct iocblk *iocp); 51831369Sdduvall #pragma no_inline(bge_chip_ioctl) 51841369Sdduvall 51851369Sdduvall enum ioc_reply 51861369Sdduvall bge_chip_ioctl(bge_t *bgep, queue_t *wq, mblk_t *mp, struct iocblk *iocp) 51871369Sdduvall { 51881369Sdduvall int cmd; 51891369Sdduvall 51901369Sdduvall BGE_TRACE(("bge_chip_ioctl($%p, $%p, $%p, $%p)", 51911369Sdduvall (void *)bgep, (void *)wq, (void *)mp, (void *)iocp)); 51921369Sdduvall 51931369Sdduvall ASSERT(mutex_owned(bgep->genlock)); 51941369Sdduvall 51951369Sdduvall cmd = iocp->ioc_cmd; 51961369Sdduvall switch (cmd) { 51971369Sdduvall default: 51981369Sdduvall /* NOTREACHED */ 51991369Sdduvall bge_error(bgep, "bge_chip_ioctl: invalid cmd 0x%x", cmd); 52001369Sdduvall return (IOC_INVAL); 52011369Sdduvall 52021369Sdduvall case BGE_DIAG: 52031369Sdduvall case BGE_PEEK: 52041369Sdduvall case BGE_POKE: 52051369Sdduvall case BGE_PHY_RESET: 52061369Sdduvall case BGE_SOFT_RESET: 52071369Sdduvall case BGE_HARD_RESET: 52081369Sdduvall #if BGE_DEBUGGING || BGE_DO_PPIO 52091369Sdduvall return (bge_diag_ioctl(bgep, cmd, mp, iocp)); 52101369Sdduvall #else 52111369Sdduvall return (IOC_INVAL); 52121369Sdduvall #endif /* BGE_DEBUGGING || BGE_DO_PPIO */ 52131369Sdduvall 52141369Sdduvall case BGE_MII_READ: 52151369Sdduvall case BGE_MII_WRITE: 52161369Sdduvall return (bge_mii_ioctl(bgep, cmd, mp, iocp)); 52171369Sdduvall 52181369Sdduvall #if BGE_SEE_IO32 52191369Sdduvall case BGE_SEE_READ: 52201369Sdduvall case BGE_SEE_WRITE: 52211369Sdduvall return (bge_see_ioctl(bgep, cmd, mp, iocp)); 52221369Sdduvall #endif /* BGE_SEE_IO32 */ 52231369Sdduvall 52241369Sdduvall #if BGE_FLASH_IO32 52251369Sdduvall case BGE_FLASH_READ: 52261369Sdduvall case BGE_FLASH_WRITE: 52271369Sdduvall return (bge_flash_ioctl(bgep, cmd, mp, iocp)); 52281369Sdduvall #endif /* BGE_FLASH_IO32 */ 52291369Sdduvall } 52301369Sdduvall 52311369Sdduvall /* NOTREACHED */ 52321369Sdduvall } 52331369Sdduvall 52341369Sdduvall void 52351369Sdduvall bge_chip_blank(void *arg, time_t ticks, uint_t count) 52361369Sdduvall { 52371369Sdduvall bge_t *bgep = arg; 52381369Sdduvall 52391865Sdilpreet mutex_enter(bgep->genlock); 52401369Sdduvall bge_reg_put32(bgep, RCV_COALESCE_TICKS_REG, ticks); 52411369Sdduvall bge_reg_put32(bgep, RCV_COALESCE_MAX_BD_REG, count); 52421865Sdilpreet if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) 52431865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_UNAFFECTED); 52441865Sdilpreet mutex_exit(bgep->genlock); 52451369Sdduvall } 52461408Srandyf 52471408Srandyf #ifdef BGE_IPMI_ASF 52481408Srandyf 52491408Srandyf uint32_t 52501408Srandyf bge_nic_read32(bge_t *bgep, bge_regno_t addr) 52511408Srandyf { 52521408Srandyf uint32_t data; 52531408Srandyf 52541408Srandyf if (!bgep->asf_wordswapped) { 52551408Srandyf /* a workaround word swap error */ 52561408Srandyf if (addr & 4) 52571408Srandyf addr = addr - 4; 52581408Srandyf else 52591408Srandyf addr = addr + 4; 52601408Srandyf } 52611408Srandyf 52621408Srandyf pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_MWBAR, addr); 52631408Srandyf data = pci_config_get32(bgep->cfg_handle, PCI_CONF_BGE_MWDAR); 52641408Srandyf pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_MWBAR, 0); 52651408Srandyf 52661408Srandyf return (data); 52671408Srandyf } 52681408Srandyf 52691408Srandyf 52701408Srandyf void 52711408Srandyf bge_asf_update_status(bge_t *bgep) 52721408Srandyf { 52731408Srandyf uint32_t event; 52741408Srandyf 52751408Srandyf bge_nic_put32(bgep, BGE_CMD_MAILBOX, BGE_CMD_NICDRV_ALIVE); 52761408Srandyf bge_nic_put32(bgep, BGE_CMD_LENGTH_MAILBOX, 4); 52771408Srandyf bge_nic_put32(bgep, BGE_CMD_DATA_MAILBOX, 3); 52781408Srandyf 52791408Srandyf event = bge_reg_get32(bgep, RX_RISC_EVENT_REG); 52801408Srandyf bge_reg_put32(bgep, RX_RISC_EVENT_REG, event | RRER_ASF_EVENT); 52811408Srandyf } 52821408Srandyf 52831408Srandyf 52841408Srandyf /* 52851408Srandyf * The driver is supposed to notify ASF that the OS is still running 52861408Srandyf * every three seconds, otherwise the management server may attempt 52871408Srandyf * to reboot the machine. If it hasn't actually failed, this is 52882135Szh199473 * not a desirable result. However, this isn't running as a real-time 52891408Srandyf * thread, and even if it were, it might not be able to generate the 52901408Srandyf * heartbeat in a timely manner due to system load. As it isn't a 52911408Srandyf * significant strain on the machine, we will set the interval to half 52921408Srandyf * of the required value. 52931408Srandyf */ 52941408Srandyf void 52951865Sdilpreet bge_asf_heartbeat(void *arg) 52961408Srandyf { 52971865Sdilpreet bge_t *bgep = (bge_t *)arg; 52981865Sdilpreet 52991865Sdilpreet mutex_enter(bgep->genlock); 53001408Srandyf bge_asf_update_status((bge_t *)bgep); 53011865Sdilpreet if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) 53021865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_DEGRADED); 53031865Sdilpreet if (bge_check_acc_handle(bgep, bgep->cfg_handle) != DDI_FM_OK) 53041865Sdilpreet ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_DEGRADED); 53051865Sdilpreet mutex_exit(bgep->genlock); 53061408Srandyf ((bge_t *)bgep)->asf_timeout_id = timeout(bge_asf_heartbeat, bgep, 53071408Srandyf drv_usectohz(BGE_ASF_HEARTBEAT_INTERVAL)); 53081408Srandyf } 53091408Srandyf 53101408Srandyf 53111408Srandyf void 53121408Srandyf bge_asf_stop_timer(bge_t *bgep) 53131408Srandyf { 53141408Srandyf timeout_id_t tmp_id = 0; 53151408Srandyf 53161408Srandyf while ((bgep->asf_timeout_id != 0) && 53171408Srandyf (tmp_id != bgep->asf_timeout_id)) { 53181408Srandyf tmp_id = bgep->asf_timeout_id; 53191408Srandyf (void) untimeout(tmp_id); 53201408Srandyf } 53211408Srandyf bgep->asf_timeout_id = 0; 53221408Srandyf } 53231408Srandyf 53241408Srandyf 53251408Srandyf 53261408Srandyf /* 53272135Szh199473 * This function should be placed at the earliest position of bge_attach(). 53281408Srandyf */ 53291408Srandyf void 53301408Srandyf bge_asf_get_config(bge_t *bgep) 53311408Srandyf { 53321408Srandyf uint32_t nicsig; 53331408Srandyf uint32_t niccfg; 53341408Srandyf 53351408Srandyf nicsig = bge_nic_read32(bgep, BGE_NIC_DATA_SIG_ADDR); 53361408Srandyf if (nicsig == BGE_NIC_DATA_SIG) { 53371408Srandyf niccfg = bge_nic_read32(bgep, BGE_NIC_DATA_NIC_CFG_ADDR); 53381408Srandyf if (niccfg & BGE_NIC_CFG_ENABLE_ASF) 53391408Srandyf /* 53401408Srandyf * Here, we don't consider BAXTER, because BGE haven't 53411408Srandyf * supported BAXTER (that is 5752). Also, as I know, 53421408Srandyf * BAXTER doesn't support ASF feature. 53431408Srandyf */ 53441408Srandyf bgep->asf_enabled = B_TRUE; 53451408Srandyf else 53461408Srandyf bgep->asf_enabled = B_FALSE; 53471408Srandyf } else 53481408Srandyf bgep->asf_enabled = B_FALSE; 53491408Srandyf } 53501408Srandyf 53511408Srandyf 53521408Srandyf void 53531408Srandyf bge_asf_pre_reset_operations(bge_t *bgep, uint32_t mode) 53541408Srandyf { 53551408Srandyf uint32_t tries; 53561408Srandyf uint32_t event; 53571408Srandyf 53581408Srandyf ASSERT(bgep->asf_enabled); 53591408Srandyf 53601408Srandyf /* Issues "pause firmware" command and wait for ACK */ 53611408Srandyf bge_nic_put32(bgep, BGE_CMD_MAILBOX, BGE_CMD_NICDRV_PAUSE_FW); 53621408Srandyf event = bge_reg_get32(bgep, RX_RISC_EVENT_REG); 53631408Srandyf bge_reg_put32(bgep, RX_RISC_EVENT_REG, event | RRER_ASF_EVENT); 53641408Srandyf 53651408Srandyf event = bge_reg_get32(bgep, RX_RISC_EVENT_REG); 53661408Srandyf tries = 0; 53671408Srandyf while ((event & RRER_ASF_EVENT) && (tries < 100)) { 53681408Srandyf drv_usecwait(1); 53691408Srandyf tries ++; 53701408Srandyf event = bge_reg_get32(bgep, RX_RISC_EVENT_REG); 53711408Srandyf } 53721408Srandyf 53731408Srandyf bge_nic_put32(bgep, BGE_FIRMWARE_MAILBOX, 53741408Srandyf BGE_MAGIC_NUM_FIRMWARE_INIT_DONE); 53751408Srandyf 53761408Srandyf if (bgep->asf_newhandshake) { 53771408Srandyf switch (mode) { 53781408Srandyf case BGE_INIT_RESET: 53791408Srandyf bge_nic_put32(bgep, BGE_DRV_STATE_MAILBOX, 53801408Srandyf BGE_DRV_STATE_START); 53811408Srandyf break; 53821408Srandyf case BGE_SHUTDOWN_RESET: 53831408Srandyf bge_nic_put32(bgep, BGE_DRV_STATE_MAILBOX, 53841408Srandyf BGE_DRV_STATE_UNLOAD); 53851408Srandyf break; 53861408Srandyf case BGE_SUSPEND_RESET: 53871408Srandyf bge_nic_put32(bgep, BGE_DRV_STATE_MAILBOX, 53881408Srandyf BGE_DRV_STATE_SUSPEND); 53891408Srandyf break; 53901408Srandyf default: 53911408Srandyf break; 53921408Srandyf } 53931408Srandyf } 53941408Srandyf } 53951408Srandyf 53961408Srandyf 53971408Srandyf void 53981408Srandyf bge_asf_post_reset_old_mode(bge_t *bgep, uint32_t mode) 53991408Srandyf { 54001408Srandyf switch (mode) { 54011408Srandyf case BGE_INIT_RESET: 54021408Srandyf bge_nic_put32(bgep, BGE_DRV_STATE_MAILBOX, 54031408Srandyf BGE_DRV_STATE_START); 54041408Srandyf break; 54051408Srandyf case BGE_SHUTDOWN_RESET: 54061408Srandyf bge_nic_put32(bgep, BGE_DRV_STATE_MAILBOX, 54071408Srandyf BGE_DRV_STATE_UNLOAD); 54081408Srandyf break; 54091408Srandyf case BGE_SUSPEND_RESET: 54101408Srandyf bge_nic_put32(bgep, BGE_DRV_STATE_MAILBOX, 54111408Srandyf BGE_DRV_STATE_SUSPEND); 54121408Srandyf break; 54131408Srandyf default: 54141408Srandyf break; 54151408Srandyf } 54161408Srandyf } 54171408Srandyf 54181408Srandyf 54191408Srandyf void 54201408Srandyf bge_asf_post_reset_new_mode(bge_t *bgep, uint32_t mode) 54211408Srandyf { 54221408Srandyf switch (mode) { 54231408Srandyf case BGE_INIT_RESET: 54241408Srandyf bge_nic_put32(bgep, BGE_DRV_STATE_MAILBOX, 54251408Srandyf BGE_DRV_STATE_START_DONE); 54261408Srandyf break; 54271408Srandyf case BGE_SHUTDOWN_RESET: 54281408Srandyf bge_nic_put32(bgep, BGE_DRV_STATE_MAILBOX, 54291408Srandyf BGE_DRV_STATE_UNLOAD_DONE); 54301408Srandyf break; 54311408Srandyf default: 54321408Srandyf break; 54331408Srandyf } 54341408Srandyf } 54351408Srandyf 54361408Srandyf #endif /* BGE_IPMI_ASF */ 5437