1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #pragma ident "%Z%%M% %I% %E% SMI" 28 29 #include "bge_impl.h" 30 31 #define PIO_ADDR(bgep, offset) ((void *)((caddr_t)(bgep)->io_regs+(offset))) 32 33 /* 34 * Future features ... ? 35 */ 36 #define BGE_CFG_IO8 1 /* 8/16-bit cfg space BIS/BIC */ 37 #define BGE_IND_IO32 1 /* indirect access code */ 38 #define BGE_SEE_IO32 1 /* SEEPROM access code */ 39 #define BGE_FLASH_IO32 1 /* FLASH access code */ 40 41 /* 42 * BGE MSI tunable: 43 * 44 * By default MSI is enabled on all supported platforms but it is disabled 45 * for some Broadcom chips due to known MSI hardware issues. Currently MSI 46 * is enabled only for 5714C A2 and 5715C A2 broadcom chips. 47 */ 48 #if defined(__sparc) 49 boolean_t bge_enable_msi = B_TRUE; 50 #else 51 boolean_t bge_enable_msi = B_FALSE; 52 #endif 53 54 /* 55 * PCI-X/PCI-E relaxed ordering tunable for OS/Nexus driver 56 */ 57 boolean_t bge_relaxed_ordering = B_TRUE; 58 59 /* 60 * Property names 61 */ 62 static char knownids_propname[] = "bge-known-subsystems"; 63 64 /* 65 * Patchable globals: 66 * 67 * bge_autorecover 68 * Enables/disables automatic recovery after fault detection 69 * 70 * bge_mlcr_default 71 * Value to program into the MLCR; controls the chip's GPIO pins 72 * 73 * bge_dma_{rd,wr}prio 74 * Relative priorities of DMA reads & DMA writes respectively. 75 * These may each be patched to any value 0-3. Equal values 76 * will give "fair" (round-robin) arbitration for PCI access. 77 * Unequal values will give one or the other function priority. 78 * 79 * bge_dma_rwctrl 80 * Value to put in the Read/Write DMA control register. See 81 * the Broadcom PRM for things you can fiddle with in this 82 * register ... 83 * 84 * bge_{tx,rx}_{count,ticks}_{norm,intr} 85 * Send/receive interrupt coalescing parameters. Counts are 86 * #s of descriptors, ticks are in microseconds. *norm* values 87 * apply between status updates/interrupts; the *intr* values 88 * refer to the 'during-interrupt' versions - see the PRM. 89 * 90 * NOTE: these values have been determined by measurement. They 91 * differ significantly from the values recommended in the PRM. 92 */ 93 static uint32_t bge_autorecover = 1; 94 static uint32_t bge_mlcr_default_5714 = MLCR_DEFAULT_5714; 95 96 static uint32_t bge_dma_rdprio = 1; 97 static uint32_t bge_dma_wrprio = 0; 98 static uint32_t bge_dma_rwctrl = PDRWCR_VAR_DEFAULT; 99 static uint32_t bge_dma_rwctrl_5721 = PDRWCR_VAR_5721; 100 static uint32_t bge_dma_rwctrl_5714 = PDRWCR_VAR_5714; 101 static uint32_t bge_dma_rwctrl_5715 = PDRWCR_VAR_5715; 102 103 uint32_t bge_rx_ticks_norm = 128; 104 uint32_t bge_tx_ticks_norm = 2048; /* 8 for FJ2+ !?!? */ 105 uint32_t bge_rx_count_norm = 8; 106 uint32_t bge_tx_count_norm = 128; 107 108 static uint32_t bge_rx_ticks_intr = 128; 109 static uint32_t bge_tx_ticks_intr = 0; /* 8 for FJ2+ !?!? */ 110 static uint32_t bge_rx_count_intr = 2; 111 static uint32_t bge_tx_count_intr = 0; 112 113 /* 114 * Memory pool configuration parameters. 115 * 116 * These are generally specific to each member of the chip family, since 117 * each one may have a different memory size/configuration. 118 * 119 * Setting the mbuf pool length for a specific type of chip to 0 inhibits 120 * the driver from programming the various registers; instead they are left 121 * at their hardware defaults. This is the preferred option for later chips 122 * (5705+), whereas the older chips *required* these registers to be set, 123 * since the h/w default was 0 ;-( 124 */ 125 static uint32_t bge_mbuf_pool_base = MBUF_POOL_BASE_DEFAULT; 126 static uint32_t bge_mbuf_pool_base_5704 = MBUF_POOL_BASE_5704; 127 static uint32_t bge_mbuf_pool_base_5705 = MBUF_POOL_BASE_5705; 128 static uint32_t bge_mbuf_pool_base_5721 = MBUF_POOL_BASE_5721; 129 static uint32_t bge_mbuf_pool_len = MBUF_POOL_LENGTH_DEFAULT; 130 static uint32_t bge_mbuf_pool_len_5704 = MBUF_POOL_LENGTH_5704; 131 static uint32_t bge_mbuf_pool_len_5705 = 0; /* use h/w default */ 132 static uint32_t bge_mbuf_pool_len_5721 = 0; 133 134 /* 135 * Various high and low water marks, thresholds, etc ... 136 * 137 * Note: these are taken from revision 7 of the PRM, and some are different 138 * from both the values in earlier PRMs *and* those determined experimentally 139 * and used in earlier versions of this driver ... 140 */ 141 static uint32_t bge_mbuf_hi_water = MBUF_HIWAT_DEFAULT; 142 static uint32_t bge_mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_DEFAULT; 143 static uint32_t bge_mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_DEFAULT; 144 145 static uint32_t bge_dmad_lo_water = DMAD_POOL_LOWAT_DEFAULT; 146 static uint32_t bge_dmad_hi_water = DMAD_POOL_HIWAT_DEFAULT; 147 static uint32_t bge_lowat_recv_frames = LOWAT_MAX_RECV_FRAMES_DEFAULT; 148 149 static uint32_t bge_replenish_std = STD_RCV_BD_REPLENISH_DEFAULT; 150 static uint32_t bge_replenish_mini = MINI_RCV_BD_REPLENISH_DEFAULT; 151 static uint32_t bge_replenish_jumbo = JUMBO_RCV_BD_REPLENISH_DEFAULT; 152 153 static uint32_t bge_watchdog_count = 1 << 16; 154 static uint16_t bge_dma_miss_limit = 20; 155 156 static uint32_t bge_stop_start_on_sync = 0; 157 158 boolean_t bge_jumbo_enable = B_TRUE; 159 160 /* 161 * bge_intr_max_loop controls the maximum loop number within bge_intr. 162 * When loading NIC with heavy network traffic, it is useful. 163 * Increasing this value could have positive effect to throughput, 164 * but it might also increase ticks of a bge ISR stick on CPU, which might 165 * lead to bad UI interactive experience. So tune this with caution. 166 */ 167 static int bge_intr_max_loop = 1; 168 169 /* 170 * ========== Low-level chip & ring buffer manipulation ========== 171 */ 172 173 #define BGE_DBG BGE_DBG_REGS /* debug flag for this code */ 174 175 176 /* 177 * Config space read-modify-write routines 178 */ 179 180 #if BGE_CFG_IO8 181 182 static void bge_cfg_clr16(bge_t *bgep, bge_regno_t regno, uint16_t bits); 183 #pragma inline(bge_cfg_clr16) 184 185 static void 186 bge_cfg_clr16(bge_t *bgep, bge_regno_t regno, uint16_t bits) 187 { 188 uint16_t regval; 189 190 BGE_TRACE(("bge_cfg_clr16($%p, 0x%lx, 0x%x)", 191 (void *)bgep, regno, bits)); 192 193 regval = pci_config_get16(bgep->cfg_handle, regno); 194 195 BGE_DEBUG(("bge_cfg_clr16($%p, 0x%lx, 0x%x): 0x%x => 0x%x", 196 (void *)bgep, regno, bits, regval, regval & ~bits)); 197 198 regval &= ~bits; 199 pci_config_put16(bgep->cfg_handle, regno, regval); 200 } 201 202 #endif /* BGE_CFG_IO8 */ 203 204 static void bge_cfg_clr32(bge_t *bgep, bge_regno_t regno, uint32_t bits); 205 #pragma inline(bge_cfg_clr32) 206 207 static void 208 bge_cfg_clr32(bge_t *bgep, bge_regno_t regno, uint32_t bits) 209 { 210 uint32_t regval; 211 212 BGE_TRACE(("bge_cfg_clr32($%p, 0x%lx, 0x%x)", 213 (void *)bgep, regno, bits)); 214 215 regval = pci_config_get32(bgep->cfg_handle, regno); 216 217 BGE_DEBUG(("bge_cfg_clr32($%p, 0x%lx, 0x%x): 0x%x => 0x%x", 218 (void *)bgep, regno, bits, regval, regval & ~bits)); 219 220 regval &= ~bits; 221 pci_config_put32(bgep->cfg_handle, regno, regval); 222 } 223 224 #if BGE_IND_IO32 225 226 /* 227 * Indirect access to registers & RISC scratchpads, using config space 228 * accesses only. 229 * 230 * This isn't currently used, but someday we might want to use it for 231 * restoring the Subsystem Device/Vendor registers (which aren't directly 232 * writable in Config Space), or for downloading firmware into the RISCs 233 * 234 * In any case there are endian issues to be resolved before this code is 235 * enabled; the bizarre way that bytes get twisted by this chip AND by 236 * the PCI bridge in SPARC systems mean that we shouldn't enable it until 237 * it's been thoroughly tested for all access sizes on all supported 238 * architectures (SPARC *and* x86!). 239 */ 240 uint32_t bge_ind_get32(bge_t *bgep, bge_regno_t regno); 241 #pragma inline(bge_ind_get32) 242 243 uint32_t 244 bge_ind_get32(bge_t *bgep, bge_regno_t regno) 245 { 246 uint32_t val; 247 248 BGE_TRACE(("bge_ind_get32($%p, 0x%lx)", (void *)bgep, regno)); 249 250 pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_RIAAR, regno); 251 val = pci_config_get32(bgep->cfg_handle, PCI_CONF_BGE_RIADR); 252 253 BGE_DEBUG(("bge_ind_get32($%p, 0x%lx) => 0x%x", 254 (void *)bgep, regno, val)); 255 256 val = LE_32(val); 257 258 return (val); 259 } 260 261 void bge_ind_put32(bge_t *bgep, bge_regno_t regno, uint32_t val); 262 #pragma inline(bge_ind_put32) 263 264 void 265 bge_ind_put32(bge_t *bgep, bge_regno_t regno, uint32_t val) 266 { 267 BGE_TRACE(("bge_ind_put32($%p, 0x%lx, 0x%x)", 268 (void *)bgep, regno, val)); 269 270 val = LE_32(val); 271 pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_RIAAR, regno); 272 pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_RIADR, val); 273 } 274 275 #endif /* BGE_IND_IO32 */ 276 277 #if BGE_DEBUGGING 278 279 static void bge_pci_check(bge_t *bgep); 280 #pragma no_inline(bge_pci_check) 281 282 static void 283 bge_pci_check(bge_t *bgep) 284 { 285 uint16_t pcistatus; 286 287 pcistatus = pci_config_get16(bgep->cfg_handle, PCI_CONF_STAT); 288 if ((pcistatus & (PCI_STAT_R_MAST_AB | PCI_STAT_R_TARG_AB)) != 0) 289 BGE_DEBUG(("bge_pci_check($%p): PCI status 0x%x", 290 (void *)bgep, pcistatus)); 291 } 292 293 #endif /* BGE_DEBUGGING */ 294 295 /* 296 * Perform first-stage chip (re-)initialisation, using only config-space 297 * accesses: 298 * 299 * + Read the vendor/device/revision/subsystem/cache-line-size registers, 300 * returning the data in the structure pointed to by <idp>. 301 * + Configure the target-mode endianness (swap) options. 302 * + Disable interrupts and enable Memory Space accesses. 303 * + Enable or disable Bus Mastering according to the <enable_dma> flag. 304 * 305 * This sequence is adapted from Broadcom document 570X-PG102-R, 306 * page 102, steps 1-3, 6-8 and 11-13. The omitted parts of the sequence 307 * are 4 and 5 (Reset Core and wait) which are handled elsewhere. 308 * 309 * This function MUST be called before any non-config-space accesses 310 * are made; on this first call <enable_dma> is B_FALSE, and it 311 * effectively performs steps 3-1(!) of the initialisation sequence 312 * (the rest are not required but should be harmless). 313 * 314 * It MUST also be called after a chip reset, as this disables 315 * Memory Space cycles! In this case, <enable_dma> is B_TRUE, and 316 * it is effectively performing steps 6-8. 317 */ 318 void bge_chip_cfg_init(bge_t *bgep, chip_id_t *cidp, boolean_t enable_dma); 319 #pragma no_inline(bge_chip_cfg_init) 320 321 void 322 bge_chip_cfg_init(bge_t *bgep, chip_id_t *cidp, boolean_t enable_dma) 323 { 324 ddi_acc_handle_t handle; 325 uint16_t command; 326 uint32_t mhcr; 327 uint16_t value16; 328 int i; 329 330 BGE_TRACE(("bge_chip_cfg_init($%p, $%p, %d)", 331 (void *)bgep, (void *)cidp, enable_dma)); 332 333 /* 334 * Step 3: save PCI cache line size and subsystem vendor ID 335 * 336 * Read all the config-space registers that characterise the 337 * chip, specifically vendor/device/revision/subsystem vendor 338 * and subsystem device id. We expect (but don't check) that 339 * (vendor == VENDOR_ID_BROADCOM) && (device == DEVICE_ID_5704) 340 * 341 * Also save all bus-transaction related registers (cache-line 342 * size, bus-grant/latency parameters, etc). Some of these are 343 * cleared by reset, so we'll have to restore them later. This 344 * comes from the Broadcom document 570X-PG102-R ... 345 * 346 * Note: Broadcom document 570X-PG102-R seems to be in error 347 * here w.r.t. the offsets of the Subsystem Vendor ID and 348 * Subsystem (Device) ID registers, which are the opposite way 349 * round according to the PCI standard. For good measure, we 350 * save/restore both anyway. 351 */ 352 handle = bgep->cfg_handle; 353 354 mhcr = pci_config_get32(handle, PCI_CONF_BGE_MHCR); 355 cidp->asic_rev = mhcr & MHCR_CHIP_REV_MASK; 356 cidp->businfo = pci_config_get32(handle, PCI_CONF_BGE_PCISTATE); 357 cidp->command = pci_config_get16(handle, PCI_CONF_COMM); 358 359 cidp->vendor = pci_config_get16(handle, PCI_CONF_VENID); 360 cidp->device = pci_config_get16(handle, PCI_CONF_DEVID); 361 cidp->subven = pci_config_get16(handle, PCI_CONF_SUBVENID); 362 cidp->subdev = pci_config_get16(handle, PCI_CONF_SUBSYSID); 363 cidp->revision = pci_config_get8(handle, PCI_CONF_REVID); 364 cidp->clsize = pci_config_get8(handle, PCI_CONF_CACHE_LINESZ); 365 cidp->latency = pci_config_get8(handle, PCI_CONF_LATENCY_TIMER); 366 367 BGE_DEBUG(("bge_chip_cfg_init: %s bus is %s and %s; #INTA is %s", 368 cidp->businfo & PCISTATE_BUS_IS_PCI ? "PCI" : "PCI-X", 369 cidp->businfo & PCISTATE_BUS_IS_FAST ? "fast" : "slow", 370 cidp->businfo & PCISTATE_BUS_IS_32_BIT ? "narrow" : "wide", 371 cidp->businfo & PCISTATE_INTA_STATE ? "high" : "low")); 372 BGE_DEBUG(("bge_chip_cfg_init: vendor 0x%x device 0x%x revision 0x%x", 373 cidp->vendor, cidp->device, cidp->revision)); 374 BGE_DEBUG(("bge_chip_cfg_init: subven 0x%x subdev 0x%x asic_rev 0x%x", 375 cidp->subven, cidp->subdev, cidp->asic_rev)); 376 BGE_DEBUG(("bge_chip_cfg_init: clsize %d latency %d command 0x%x", 377 cidp->clsize, cidp->latency, cidp->command)); 378 379 /* 380 * Step 2 (also step 6): disable and clear interrupts. 381 * Steps 11-13: configure PIO endianness options, and enable 382 * indirect register access. We'll also select any other 383 * options controlled by the MHCR (e.g. tagged status, mask 384 * interrupt mode) at this stage ... 385 * 386 * Note: internally, the chip is 64-bit and BIG-endian, but 387 * since it talks to the host over a (LITTLE-endian) PCI bus, 388 * it normally swaps bytes around at the PCI interface. 389 * However, the PCI host bridge on SPARC systems normally 390 * swaps the byte lanes around too, since SPARCs are also 391 * BIG-endian. So it turns out that on SPARC, the right 392 * option is to tell the chip to swap (and the host bridge 393 * will swap back again), whereas on x86 we ask the chip 394 * NOT to swap, so the natural little-endianness of the 395 * PCI bus is assumed. Then the only thing that doesn't 396 * automatically work right is access to an 8-byte register 397 * by a little-endian host; but we don't want to set the 398 * MHCR_ENABLE_REGISTER_WORD_SWAP bit because then 4-byte 399 * accesses don't go where expected ;-( So we live with 400 * that, and perform word-swaps in software in the few cases 401 * where a chip register is defined as an 8-byte value -- 402 * see the code below for details ... 403 * 404 * Note: the meaning of the 'MASK_INTERRUPT_MODE' bit isn't 405 * very clear in the register description in the PRM, but 406 * Broadcom document 570X-PG104-R page 248 explains a little 407 * more (under "Broadcom Mask Mode"). The bit changes the way 408 * the MASK_PCI_INT_OUTPUT bit works: with MASK_INTERRUPT_MODE 409 * clear, the chip interprets MASK_PCI_INT_OUTPUT in the same 410 * way as the 5700 did, which isn't very convenient. Setting 411 * the MASK_INTERRUPT_MODE bit makes the MASK_PCI_INT_OUTPUT 412 * bit do just what its name says -- MASK the PCI #INTA output 413 * (i.e. deassert the signal at the pin) leaving all internal 414 * state unchanged. This is much more convenient for our 415 * interrupt handler, so we set MASK_INTERRUPT_MODE here. 416 * 417 * Note: the inconvenient semantics of the interrupt mailbox 418 * (nonzero disables and acknowledges/clears the interrupt, 419 * zero enables AND CLEARS it) would make race conditions 420 * likely in the interrupt handler: 421 * 422 * (1) acknowledge & disable interrupts 423 * (2) while (more to do) 424 * process packets 425 * (3) enable interrupts -- also clears pending 426 * 427 * If the chip received more packets and internally generated 428 * an interrupt between the check at (2) and the mbox write 429 * at (3), this interrupt would be lost :-( 430 * 431 * The best way to avoid this is to use TAGGED STATUS mode, 432 * where the chip includes a unique tag in each status block 433 * update, and the host, when re-enabling interrupts, passes 434 * the last tag it saw back to the chip; then the chip can 435 * see whether the host is truly up to date, and regenerate 436 * its interrupt if not. 437 */ 438 mhcr = MHCR_ENABLE_INDIRECT_ACCESS | 439 MHCR_ENABLE_TAGGED_STATUS_MODE | 440 MHCR_MASK_INTERRUPT_MODE | 441 MHCR_CLEAR_INTERRUPT_INTA; 442 443 if (bgep->intr_type == DDI_INTR_TYPE_FIXED) 444 mhcr |= MHCR_MASK_PCI_INT_OUTPUT; 445 446 #ifdef _BIG_ENDIAN 447 mhcr |= MHCR_ENABLE_ENDIAN_WORD_SWAP | MHCR_ENABLE_ENDIAN_BYTE_SWAP; 448 #endif /* _BIG_ENDIAN */ 449 450 pci_config_put32(handle, PCI_CONF_BGE_MHCR, mhcr); 451 452 #ifdef BGE_IPMI_ASF 453 bgep->asf_wordswapped = B_FALSE; 454 #endif 455 /* 456 * Step 1 (also step 7): Enable PCI Memory Space accesses 457 * Disable Memory Write/Invalidate 458 * Enable or disable Bus Mastering 459 * 460 * Note that all other bits are taken from the original value saved 461 * the first time through here, rather than from the current register 462 * value, 'cos that will have been cleared by a soft RESET since. 463 * In this way we preserve the OBP/nexus-parent's preferred settings 464 * of the parity-error and system-error enable bits across multiple 465 * chip RESETs. 466 */ 467 command = bgep->chipid.command | PCI_COMM_MAE; 468 command &= ~(PCI_COMM_ME|PCI_COMM_MEMWR_INVAL); 469 if (enable_dma) 470 command |= PCI_COMM_ME; 471 /* 472 * on BCM5714 revision A0, false parity error gets generated 473 * due to a logic bug. Provide a workaround by disabling parity 474 * error. 475 */ 476 if (((cidp->device == DEVICE_ID_5714C) || 477 (cidp->device == DEVICE_ID_5714S)) && 478 (cidp->revision == REVISION_ID_5714_A0)) { 479 command &= ~PCI_COMM_PARITY_DETECT; 480 } 481 pci_config_put16(handle, PCI_CONF_COMM, command); 482 483 /* 484 * On some PCI-E device, there were instances when 485 * the device was still link training. 486 */ 487 if (bgep->chipid.pci_type == BGE_PCI_E) { 488 i = 0; 489 value16 = pci_config_get16(handle, PCI_CONF_COMM); 490 while ((value16 != command) && (i < 100)) { 491 drv_usecwait(200); 492 value16 = pci_config_get16(handle, PCI_CONF_COMM); 493 ++i; 494 } 495 } 496 497 /* 498 * Clear any remaining error status bits 499 */ 500 pci_config_put16(handle, PCI_CONF_STAT, ~0); 501 502 /* 503 * Do following if and only if the device is NOT BCM5714C OR 504 * BCM5715C 505 */ 506 if (!((cidp->device == DEVICE_ID_5714C) || 507 (cidp->device == DEVICE_ID_5715C))) { 508 /* 509 * Make sure these indirect-access registers are sane 510 * rather than random after power-up or reset 511 */ 512 pci_config_put32(handle, PCI_CONF_BGE_RIAAR, 0); 513 pci_config_put32(handle, PCI_CONF_BGE_MWBAR, 0); 514 } 515 /* 516 * Step 8: Disable PCI-X/PCI-E Relaxed Ordering 517 */ 518 bge_cfg_clr16(bgep, PCIX_CONF_COMM, PCIX_COMM_RELAXED); 519 520 if (cidp->pci_type == BGE_PCI_E) 521 bge_cfg_clr16(bgep, PCI_CONF_DEV_CTRL, 522 DEV_CTRL_NO_SNOOP | DEV_CTRL_RELAXED); 523 } 524 525 #ifdef __amd64 526 /* 527 * Distinguish CPU types 528 * 529 * These use to distinguish AMD64 or Intel EM64T of CPU running mode. 530 * If CPU runs on Intel EM64T mode,the 64bit operation cannot works fine 531 * for PCI-Express based network interface card. This is the work-around 532 * for those nics. 533 */ 534 static boolean_t bge_get_em64t_type(void); 535 #pragma inline(bge_get_em64t_type) 536 537 static boolean_t 538 bge_get_em64t_type(void) 539 { 540 541 return (x86_vendor == X86_VENDOR_Intel); 542 } 543 #endif 544 545 /* 546 * Operating register get/set access routines 547 */ 548 549 uint32_t bge_reg_get32(bge_t *bgep, bge_regno_t regno); 550 #pragma inline(bge_reg_get32) 551 552 uint32_t 553 bge_reg_get32(bge_t *bgep, bge_regno_t regno) 554 { 555 BGE_TRACE(("bge_reg_get32($%p, 0x%lx)", 556 (void *)bgep, regno)); 557 558 return (ddi_get32(bgep->io_handle, PIO_ADDR(bgep, regno))); 559 } 560 561 void bge_reg_put32(bge_t *bgep, bge_regno_t regno, uint32_t data); 562 #pragma inline(bge_reg_put32) 563 564 void 565 bge_reg_put32(bge_t *bgep, bge_regno_t regno, uint32_t data) 566 { 567 BGE_TRACE(("bge_reg_put32($%p, 0x%lx, 0x%x)", 568 (void *)bgep, regno, data)); 569 570 ddi_put32(bgep->io_handle, PIO_ADDR(bgep, regno), data); 571 BGE_PCICHK(bgep); 572 } 573 574 void bge_reg_set32(bge_t *bgep, bge_regno_t regno, uint32_t bits); 575 #pragma inline(bge_reg_set32) 576 577 void 578 bge_reg_set32(bge_t *bgep, bge_regno_t regno, uint32_t bits) 579 { 580 uint32_t regval; 581 582 BGE_TRACE(("bge_reg_set32($%p, 0x%lx, 0x%x)", 583 (void *)bgep, regno, bits)); 584 585 regval = bge_reg_get32(bgep, regno); 586 regval |= bits; 587 bge_reg_put32(bgep, regno, regval); 588 } 589 590 void bge_reg_clr32(bge_t *bgep, bge_regno_t regno, uint32_t bits); 591 #pragma inline(bge_reg_clr32) 592 593 void 594 bge_reg_clr32(bge_t *bgep, bge_regno_t regno, uint32_t bits) 595 { 596 uint32_t regval; 597 598 BGE_TRACE(("bge_reg_clr32($%p, 0x%lx, 0x%x)", 599 (void *)bgep, regno, bits)); 600 601 regval = bge_reg_get32(bgep, regno); 602 regval &= ~bits; 603 bge_reg_put32(bgep, regno, regval); 604 } 605 606 static uint64_t bge_reg_get64(bge_t *bgep, bge_regno_t regno); 607 #pragma inline(bge_reg_get64) 608 609 static uint64_t 610 bge_reg_get64(bge_t *bgep, bge_regno_t regno) 611 { 612 uint64_t regval; 613 614 #ifdef __amd64 615 if (bge_get_em64t_type()) { 616 regval = ddi_get32(bgep->io_handle, PIO_ADDR(bgep, regno + 4)); 617 regval <<= 32; 618 regval |= ddi_get32(bgep->io_handle, PIO_ADDR(bgep, regno)); 619 } else { 620 regval = ddi_get64(bgep->io_handle, PIO_ADDR(bgep, regno)); 621 } 622 #else 623 regval = ddi_get64(bgep->io_handle, PIO_ADDR(bgep, regno)); 624 #endif 625 626 #ifdef _LITTLE_ENDIAN 627 regval = (regval >> 32) | (regval << 32); 628 #endif /* _LITTLE_ENDIAN */ 629 630 BGE_TRACE(("bge_reg_get64($%p, 0x%lx) = 0x%016llx", 631 (void *)bgep, regno, regval)); 632 633 return (regval); 634 } 635 636 static void bge_reg_put64(bge_t *bgep, bge_regno_t regno, uint64_t data); 637 #pragma inline(bge_reg_put64) 638 639 static void 640 bge_reg_put64(bge_t *bgep, bge_regno_t regno, uint64_t data) 641 { 642 BGE_TRACE(("bge_reg_put64($%p, 0x%lx, 0x%016llx)", 643 (void *)bgep, regno, data)); 644 645 #ifdef _LITTLE_ENDIAN 646 data = ((data >> 32) | (data << 32)); 647 #endif /* _LITTLE_ENDIAN */ 648 649 #ifdef __amd64 650 if (bge_get_em64t_type()) { 651 ddi_put32(bgep->io_handle, 652 PIO_ADDR(bgep, regno), (uint32_t)data); 653 BGE_PCICHK(bgep); 654 ddi_put32(bgep->io_handle, 655 PIO_ADDR(bgep, regno + 4), (uint32_t)(data >> 32)); 656 657 } else { 658 ddi_put64(bgep->io_handle, PIO_ADDR(bgep, regno), data); 659 } 660 #else 661 ddi_put64(bgep->io_handle, PIO_ADDR(bgep, regno), data); 662 #endif 663 664 BGE_PCICHK(bgep); 665 } 666 667 /* 668 * The DDI doesn't provide get/put functions for 128 bit data 669 * so we put RCBs out as two 64-bit chunks instead. 670 */ 671 static void bge_reg_putrcb(bge_t *bgep, bge_regno_t addr, bge_rcb_t *rcbp); 672 #pragma inline(bge_reg_putrcb) 673 674 static void 675 bge_reg_putrcb(bge_t *bgep, bge_regno_t addr, bge_rcb_t *rcbp) 676 { 677 uint64_t *p; 678 679 BGE_TRACE(("bge_reg_putrcb($%p, 0x%lx, 0x%016llx:%04x:%04x:%08x)", 680 (void *)bgep, addr, rcbp->host_ring_addr, 681 rcbp->max_len, rcbp->flags, rcbp->nic_ring_addr)); 682 683 ASSERT((addr % sizeof (*rcbp)) == 0); 684 685 p = (void *)rcbp; 686 bge_reg_put64(bgep, addr, *p++); 687 bge_reg_put64(bgep, addr+8, *p); 688 } 689 690 void bge_mbx_put(bge_t *bgep, bge_regno_t regno, uint64_t data); 691 #pragma inline(bge_mbx_put) 692 693 void 694 bge_mbx_put(bge_t *bgep, bge_regno_t regno, uint64_t data) 695 { 696 BGE_TRACE(("bge_mbx_put($%p, 0x%lx, 0x%016llx)", 697 (void *)bgep, regno, data)); 698 699 /* 700 * Mailbox registers are nominally 64 bits on the 5701, but 701 * the MSW isn't used. On the 5703, they're only 32 bits 702 * anyway. So here we just write the lower(!) 32 bits - 703 * remembering that the chip is big-endian, even though the 704 * PCI bus is little-endian ... 705 */ 706 #ifdef _BIG_ENDIAN 707 ddi_put32(bgep->io_handle, PIO_ADDR(bgep, regno+4), (uint32_t)data); 708 #else 709 ddi_put32(bgep->io_handle, PIO_ADDR(bgep, regno), (uint32_t)data); 710 #endif /* _BIG_ENDIAN */ 711 BGE_PCICHK(bgep); 712 } 713 714 uint32_t bge_mbx_get(bge_t *bgep, bge_regno_t regno); 715 #pragma inline(bge_mbx_get) 716 717 uint32_t 718 bge_mbx_get(bge_t *bgep, bge_regno_t regno) 719 { 720 uint32_t val32; 721 722 BGE_TRACE(("bge_mbx_get($%p, 0x%lx)", 723 (void *)bgep, regno)); 724 725 #ifdef _BIG_ENDIAN 726 val32 = ddi_get32(bgep->io_handle, PIO_ADDR(bgep, regno+4)); 727 #else 728 val32 = ddi_get32(bgep->io_handle, PIO_ADDR(bgep, regno)); 729 #endif /* _BIG_ENDIAN */ 730 BGE_PCICHK(bgep); 731 732 return (val32); 733 } 734 735 736 #if BGE_DEBUGGING 737 738 void bge_led_mark(bge_t *bgep); 739 #pragma no_inline(bge_led_mark) 740 741 void 742 bge_led_mark(bge_t *bgep) 743 { 744 uint32_t led_ctrl = LED_CONTROL_OVERRIDE_LINK | 745 LED_CONTROL_1000MBPS_LED | 746 LED_CONTROL_100MBPS_LED | 747 LED_CONTROL_10MBPS_LED; 748 749 /* 750 * Blink all three LINK LEDs on simultaneously, then all off, 751 * then restore to automatic hardware control. This is used 752 * in laboratory testing to trigger a logic analyser or scope. 753 */ 754 bge_reg_set32(bgep, ETHERNET_MAC_LED_CONTROL_REG, led_ctrl); 755 led_ctrl ^= LED_CONTROL_OVERRIDE_LINK; 756 bge_reg_clr32(bgep, ETHERNET_MAC_LED_CONTROL_REG, led_ctrl); 757 led_ctrl = LED_CONTROL_OVERRIDE_LINK; 758 bge_reg_clr32(bgep, ETHERNET_MAC_LED_CONTROL_REG, led_ctrl); 759 } 760 761 #endif /* BGE_DEBUGGING */ 762 763 /* 764 * NIC on-chip memory access routines 765 * 766 * Only 32K of NIC memory is visible at a time, controlled by the 767 * Memory Window Base Address Register (in PCI config space). Once 768 * this is set, the 32K region of NIC-local memory that it refers 769 * to can be directly addressed in the upper 32K of the 64K of PCI 770 * memory space used for the device. 771 */ 772 773 static void bge_nic_setwin(bge_t *bgep, bge_regno_t base); 774 #pragma inline(bge_nic_setwin) 775 776 static void 777 bge_nic_setwin(bge_t *bgep, bge_regno_t base) 778 { 779 chip_id_t *cidp; 780 781 BGE_TRACE(("bge_nic_setwin($%p, 0x%lx)", 782 (void *)bgep, base)); 783 784 ASSERT((base & MWBAR_GRANULE_MASK) == 0); 785 786 /* 787 * Don't do repeated zero data writes, 788 * if the device is BCM5714C/15C. 789 */ 790 cidp = &bgep->chipid; 791 if ((cidp->device == DEVICE_ID_5714C) || 792 (cidp->device == DEVICE_ID_5715C)) { 793 if (bgep->lastWriteZeroData && (base == (bge_regno_t)0)) 794 return; 795 /* Adjust lastWriteZeroData */ 796 bgep->lastWriteZeroData = ((base == (bge_regno_t)0) ? 797 B_TRUE : B_FALSE); 798 } 799 pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_MWBAR, base); 800 } 801 802 static uint32_t bge_nic_get32(bge_t *bgep, bge_regno_t addr); 803 #pragma inline(bge_nic_get32) 804 805 static uint32_t 806 bge_nic_get32(bge_t *bgep, bge_regno_t addr) 807 { 808 uint32_t data; 809 810 #if defined(BGE_IPMI_ASF) && !defined(__sparc) 811 if (bgep->asf_enabled && !bgep->asf_wordswapped) { 812 /* workaround for word swap error */ 813 if (addr & 4) 814 addr = addr - 4; 815 else 816 addr = addr + 4; 817 } 818 #endif 819 820 #ifdef __sparc 821 data = bge_nic_read32(bgep, addr); 822 #else 823 bge_nic_setwin(bgep, addr & ~MWBAR_GRANULE_MASK); 824 addr &= MWBAR_GRANULE_MASK; 825 addr += NIC_MEM_WINDOW_OFFSET; 826 827 data = ddi_get32(bgep->io_handle, PIO_ADDR(bgep, addr)); 828 #endif 829 830 BGE_TRACE(("bge_nic_get32($%p, 0x%lx) = 0x%08x", 831 (void *)bgep, addr, data)); 832 833 return (data); 834 } 835 836 void bge_nic_put32(bge_t *bgep, bge_regno_t addr, uint32_t data); 837 #pragma inline(bge_nic_put32) 838 839 void 840 bge_nic_put32(bge_t *bgep, bge_regno_t addr, uint32_t data) 841 { 842 BGE_TRACE(("bge_nic_put32($%p, 0x%lx, 0x%08x)", 843 (void *)bgep, addr, data)); 844 845 #if defined(BGE_IPMI_ASF) && !defined(__sparc) 846 if (bgep->asf_enabled && !bgep->asf_wordswapped) { 847 /* workaround for word swap error */ 848 if (addr & 4) 849 addr = addr - 4; 850 else 851 addr = addr + 4; 852 } 853 #endif 854 855 #ifdef __sparc 856 pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_MWBAR, addr); 857 data = LE_32(data); 858 pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_MWDAR, data); 859 pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_MWBAR, 0); 860 #else 861 bge_nic_setwin(bgep, addr & ~MWBAR_GRANULE_MASK); 862 addr &= MWBAR_GRANULE_MASK; 863 addr += NIC_MEM_WINDOW_OFFSET; 864 ddi_put32(bgep->io_handle, PIO_ADDR(bgep, addr), data); 865 BGE_PCICHK(bgep); 866 #endif 867 } 868 869 static uint64_t bge_nic_get64(bge_t *bgep, bge_regno_t addr); 870 #pragma inline(bge_nic_get64) 871 872 static uint64_t 873 bge_nic_get64(bge_t *bgep, bge_regno_t addr) 874 { 875 uint64_t data; 876 877 bge_nic_setwin(bgep, addr & ~MWBAR_GRANULE_MASK); 878 addr &= MWBAR_GRANULE_MASK; 879 addr += NIC_MEM_WINDOW_OFFSET; 880 881 #ifdef __amd64 882 if (bge_get_em64t_type()) { 883 data = ddi_get32(bgep->io_handle, PIO_ADDR(bgep, addr)); 884 data <<= 32; 885 data |= ddi_get32(bgep->io_handle, 886 PIO_ADDR(bgep, addr + 4)); 887 } else { 888 data = ddi_get64(bgep->io_handle, PIO_ADDR(bgep, addr)); 889 } 890 #else 891 data = ddi_get64(bgep->io_handle, PIO_ADDR(bgep, addr)); 892 #endif 893 894 BGE_TRACE(("bge_nic_get64($%p, 0x%lx) = 0x%016llx", 895 (void *)bgep, addr, data)); 896 897 return (data); 898 } 899 900 static void bge_nic_put64(bge_t *bgep, bge_regno_t addr, uint64_t data); 901 #pragma inline(bge_nic_put64) 902 903 static void 904 bge_nic_put64(bge_t *bgep, bge_regno_t addr, uint64_t data) 905 { 906 BGE_TRACE(("bge_nic_put64($%p, 0x%lx, 0x%016llx)", 907 (void *)bgep, addr, data)); 908 909 bge_nic_setwin(bgep, addr & ~MWBAR_GRANULE_MASK); 910 addr &= MWBAR_GRANULE_MASK; 911 addr += NIC_MEM_WINDOW_OFFSET; 912 913 #ifdef __amd64 914 if (bge_get_em64t_type()) { 915 ddi_put32(bgep->io_handle, 916 PIO_ADDR(bgep, addr), (uint32_t)data); 917 BGE_PCICHK(bgep); 918 ddi_put32(bgep->io_handle, 919 PIO_ADDR(bgep, addr + 4), (uint32_t)(data >> 32)); 920 } else { 921 ddi_put64(bgep->io_handle, PIO_ADDR(bgep, addr), data); 922 } 923 #else 924 ddi_put64(bgep->io_handle, PIO_ADDR(bgep, addr), data); 925 #endif 926 927 BGE_PCICHK(bgep); 928 } 929 930 /* 931 * The DDI doesn't provide get/put functions for 128 bit data 932 * so we put RCBs out as two 64-bit chunks instead. 933 */ 934 static void bge_nic_putrcb(bge_t *bgep, bge_regno_t addr, bge_rcb_t *rcbp); 935 #pragma inline(bge_nic_putrcb) 936 937 static void 938 bge_nic_putrcb(bge_t *bgep, bge_regno_t addr, bge_rcb_t *rcbp) 939 { 940 uint64_t *p; 941 942 BGE_TRACE(("bge_nic_putrcb($%p, 0x%lx, 0x%016llx:%04x:%04x:%08x)", 943 (void *)bgep, addr, rcbp->host_ring_addr, 944 rcbp->max_len, rcbp->flags, rcbp->nic_ring_addr)); 945 946 ASSERT((addr % sizeof (*rcbp)) == 0); 947 948 bge_nic_setwin(bgep, addr & ~MWBAR_GRANULE_MASK); 949 addr &= MWBAR_GRANULE_MASK; 950 addr += NIC_MEM_WINDOW_OFFSET; 951 952 p = (void *)rcbp; 953 #ifdef __amd64 954 if (bge_get_em64t_type()) { 955 ddi_put32(bgep->io_handle, PIO_ADDR(bgep, addr), 956 (uint32_t)(*p)); 957 ddi_put32(bgep->io_handle, PIO_ADDR(bgep, addr + 4), 958 (uint32_t)(*p >> 32)); 959 ddi_put32(bgep->io_handle, PIO_ADDR(bgep, addr + 8), 960 (uint32_t)(*(p + 1))); 961 ddi_put32(bgep->io_handle, PIO_ADDR(bgep, addr + 12), 962 (uint32_t)(*p >> 32)); 963 964 } else { 965 ddi_put64(bgep->io_handle, PIO_ADDR(bgep, addr), *p++); 966 ddi_put64(bgep->io_handle, PIO_ADDR(bgep, addr+8), *p); 967 } 968 #else 969 ddi_put64(bgep->io_handle, PIO_ADDR(bgep, addr), *p++); 970 ddi_put64(bgep->io_handle, PIO_ADDR(bgep, addr + 8), *p); 971 #endif 972 973 BGE_PCICHK(bgep); 974 } 975 976 static void bge_nic_zero(bge_t *bgep, bge_regno_t addr, uint32_t nbytes); 977 #pragma inline(bge_nic_zero) 978 979 static void 980 bge_nic_zero(bge_t *bgep, bge_regno_t addr, uint32_t nbytes) 981 { 982 BGE_TRACE(("bge_nic_zero($%p, 0x%lx, 0x%x)", 983 (void *)bgep, addr, nbytes)); 984 985 ASSERT((addr & ~MWBAR_GRANULE_MASK) == 986 ((addr+nbytes) & ~MWBAR_GRANULE_MASK)); 987 988 bge_nic_setwin(bgep, addr & ~MWBAR_GRANULE_MASK); 989 addr &= MWBAR_GRANULE_MASK; 990 addr += NIC_MEM_WINDOW_OFFSET; 991 992 (void) ddi_device_zero(bgep->io_handle, PIO_ADDR(bgep, addr), 993 nbytes, 1, DDI_DATA_SZ08_ACC); 994 BGE_PCICHK(bgep); 995 } 996 997 /* 998 * MII (PHY) register get/set access routines 999 * 1000 * These use the chip's MII auto-access method, controlled by the 1001 * MII Communication register at 0x044c, so the CPU doesn't have 1002 * to fiddle with the individual bits. 1003 */ 1004 1005 #undef BGE_DBG 1006 #define BGE_DBG BGE_DBG_MII /* debug flag for this code */ 1007 1008 static uint16_t bge_mii_access(bge_t *bgep, bge_regno_t regno, 1009 uint16_t data, uint32_t cmd); 1010 #pragma no_inline(bge_mii_access) 1011 1012 static uint16_t 1013 bge_mii_access(bge_t *bgep, bge_regno_t regno, uint16_t data, uint32_t cmd) 1014 { 1015 uint32_t timeout; 1016 uint32_t regval1; 1017 uint32_t regval2; 1018 1019 BGE_TRACE(("bge_mii_access($%p, 0x%lx, 0x%x, 0x%x)", 1020 (void *)bgep, regno, data, cmd)); 1021 1022 ASSERT(mutex_owned(bgep->genlock)); 1023 1024 /* 1025 * Assemble the command ... 1026 */ 1027 cmd |= data << MI_COMMS_DATA_SHIFT; 1028 cmd |= regno << MI_COMMS_REGISTER_SHIFT; 1029 cmd |= bgep->phy_mii_addr << MI_COMMS_ADDRESS_SHIFT; 1030 cmd |= MI_COMMS_START; 1031 1032 /* 1033 * Wait for any command already in progress ... 1034 * 1035 * Note: this *shouldn't* ever find that there is a command 1036 * in progress, because we already hold the <genlock> mutex. 1037 * Nonetheless, we have sometimes seen the MI_COMMS_START 1038 * bit set here -- it seems that the chip can initiate MII 1039 * accesses internally, even with polling OFF. 1040 */ 1041 regval1 = regval2 = bge_reg_get32(bgep, MI_COMMS_REG); 1042 for (timeout = 100; ; ) { 1043 if ((regval2 & MI_COMMS_START) == 0) { 1044 bge_reg_put32(bgep, MI_COMMS_REG, cmd); 1045 break; 1046 } 1047 if (--timeout == 0) 1048 break; 1049 drv_usecwait(10); 1050 regval2 = bge_reg_get32(bgep, MI_COMMS_REG); 1051 } 1052 1053 if (timeout == 0) 1054 return ((uint16_t)~0u); 1055 1056 if (timeout != 100) 1057 BGE_REPORT((bgep, "bge_mii_access: cmd 0x%x -- " 1058 "MI_COMMS_START set for %d us; 0x%x->0x%x", 1059 cmd, 10*(100-timeout), regval1, regval2)); 1060 1061 regval1 = bge_reg_get32(bgep, MI_COMMS_REG); 1062 for (timeout = 1000; ; ) { 1063 if ((regval1 & MI_COMMS_START) == 0) 1064 break; 1065 if (--timeout == 0) 1066 break; 1067 drv_usecwait(10); 1068 regval1 = bge_reg_get32(bgep, MI_COMMS_REG); 1069 } 1070 1071 /* 1072 * Drop out early if the READ FAILED bit is set -- this chip 1073 * could be a 5703/4S, with a SerDes instead of a PHY! 1074 */ 1075 if (regval2 & MI_COMMS_READ_FAILED) 1076 return ((uint16_t)~0u); 1077 1078 if (timeout == 0) 1079 return ((uint16_t)~0u); 1080 1081 /* 1082 * The PRM says to wait 5us after seeing the START bit clear 1083 * and then re-read the register to get the final value of the 1084 * data field, in order to avoid a race condition where the 1085 * START bit is clear but the data field isn't yet valid. 1086 * 1087 * Note: we don't actually seem to be encounter this race; 1088 * except when the START bit is seen set again (see below), 1089 * the data field doesn't change during this 5us interval. 1090 */ 1091 drv_usecwait(5); 1092 regval2 = bge_reg_get32(bgep, MI_COMMS_REG); 1093 1094 /* 1095 * Unfortunately, when following the PRMs instructions above, 1096 * we have occasionally seen the START bit set again(!) in the 1097 * value read after the 5us delay. This seems to be due to the 1098 * chip autonomously starting another MII access internally. 1099 * In such cases, the command/data/etc fields relate to the 1100 * internal command, rather than the one that we thought had 1101 * just finished. So in this case, we fall back to returning 1102 * the data from the original read that showed START clear. 1103 */ 1104 if (regval2 & MI_COMMS_START) { 1105 BGE_REPORT((bgep, "bge_mii_access: cmd 0x%x -- " 1106 "MI_COMMS_START set after transaction; 0x%x->0x%x", 1107 cmd, regval1, regval2)); 1108 regval2 = regval1; 1109 } 1110 1111 if (regval2 & MI_COMMS_START) 1112 return ((uint16_t)~0u); 1113 1114 if (regval2 & MI_COMMS_READ_FAILED) 1115 return ((uint16_t)~0u); 1116 1117 return ((regval2 & MI_COMMS_DATA_MASK) >> MI_COMMS_DATA_SHIFT); 1118 } 1119 1120 uint16_t bge_mii_get16(bge_t *bgep, bge_regno_t regno); 1121 #pragma no_inline(bge_mii_get16) 1122 1123 uint16_t 1124 bge_mii_get16(bge_t *bgep, bge_regno_t regno) 1125 { 1126 BGE_TRACE(("bge_mii_get16($%p, 0x%lx)", 1127 (void *)bgep, regno)); 1128 1129 ASSERT(mutex_owned(bgep->genlock)); 1130 1131 return (bge_mii_access(bgep, regno, 0, MI_COMMS_COMMAND_READ)); 1132 } 1133 1134 void bge_mii_put16(bge_t *bgep, bge_regno_t regno, uint16_t data); 1135 #pragma no_inline(bge_mii_put16) 1136 1137 void 1138 bge_mii_put16(bge_t *bgep, bge_regno_t regno, uint16_t data) 1139 { 1140 BGE_TRACE(("bge_mii_put16($%p, 0x%lx, 0x%x)", 1141 (void *)bgep, regno, data)); 1142 1143 ASSERT(mutex_owned(bgep->genlock)); 1144 1145 (void) bge_mii_access(bgep, regno, data, MI_COMMS_COMMAND_WRITE); 1146 } 1147 1148 #undef BGE_DBG 1149 #define BGE_DBG BGE_DBG_SEEPROM /* debug flag for this code */ 1150 1151 #if BGE_SEE_IO32 || BGE_FLASH_IO32 1152 1153 /* 1154 * Basic SEEPROM get/set access routine 1155 * 1156 * This uses the chip's SEEPROM auto-access method, controlled by the 1157 * Serial EEPROM Address/Data Registers at 0x6838/683c, so the CPU 1158 * doesn't have to fiddle with the individual bits. 1159 * 1160 * The caller should hold <genlock> and *also* have already acquired 1161 * the right to access the SEEPROM, via bge_nvmem_acquire() above. 1162 * 1163 * Return value: 1164 * 0 on success, 1165 * ENODATA on access timeout (maybe retryable: device may just be busy) 1166 * EPROTO on other h/w or s/w errors. 1167 * 1168 * <*dp> is an input to a SEEPROM_ACCESS_WRITE operation, or an output 1169 * from a (successful) SEEPROM_ACCESS_READ. 1170 */ 1171 static int bge_seeprom_access(bge_t *bgep, uint32_t cmd, bge_regno_t addr, 1172 uint32_t *dp); 1173 #pragma no_inline(bge_seeprom_access) 1174 1175 static int 1176 bge_seeprom_access(bge_t *bgep, uint32_t cmd, bge_regno_t addr, uint32_t *dp) 1177 { 1178 uint32_t tries; 1179 uint32_t regval; 1180 1181 ASSERT(mutex_owned(bgep->genlock)); 1182 1183 /* 1184 * On the newer chips that support both SEEPROM & Flash, we need 1185 * to specifically enable SEEPROM access (Flash is the default). 1186 * On older chips, we don't; SEEPROM is the only NVtype supported, 1187 * and the NVM control registers don't exist ... 1188 */ 1189 switch (bgep->chipid.nvtype) { 1190 case BGE_NVTYPE_NONE: 1191 case BGE_NVTYPE_UNKNOWN: 1192 _NOTE(NOTREACHED) 1193 case BGE_NVTYPE_SEEPROM: 1194 break; 1195 1196 case BGE_NVTYPE_LEGACY_SEEPROM: 1197 case BGE_NVTYPE_UNBUFFERED_FLASH: 1198 case BGE_NVTYPE_BUFFERED_FLASH: 1199 default: 1200 bge_reg_set32(bgep, NVM_CONFIG1_REG, 1201 NVM_CFG1_LEGACY_SEEPROM_MODE); 1202 break; 1203 } 1204 1205 /* 1206 * Check there's no command in progress. 1207 * 1208 * Note: this *shouldn't* ever find that there is a command 1209 * in progress, because we already hold the <genlock> mutex. 1210 * Also, to ensure we don't have a conflict with the chip's 1211 * internal firmware or a process accessing the same (shared) 1212 * SEEPROM through the other port of a 5704, we've already 1213 * been through the "software arbitration" protocol. 1214 * So this is just a final consistency check: we shouldn't 1215 * see EITHER the START bit (command started but not complete) 1216 * OR the COMPLETE bit (command completed but not cleared). 1217 */ 1218 regval = bge_reg_get32(bgep, SERIAL_EEPROM_ADDRESS_REG); 1219 if (regval & SEEPROM_ACCESS_START) 1220 return (EPROTO); 1221 if (regval & SEEPROM_ACCESS_COMPLETE) 1222 return (EPROTO); 1223 1224 /* 1225 * Assemble the command ... 1226 */ 1227 cmd |= addr & SEEPROM_ACCESS_ADDRESS_MASK; 1228 addr >>= SEEPROM_ACCESS_ADDRESS_SIZE; 1229 addr <<= SEEPROM_ACCESS_DEVID_SHIFT; 1230 cmd |= addr & SEEPROM_ACCESS_DEVID_MASK; 1231 cmd |= SEEPROM_ACCESS_START; 1232 cmd |= SEEPROM_ACCESS_COMPLETE; 1233 cmd |= regval & SEEPROM_ACCESS_HALFCLOCK_MASK; 1234 1235 bge_reg_put32(bgep, SERIAL_EEPROM_DATA_REG, *dp); 1236 bge_reg_put32(bgep, SERIAL_EEPROM_ADDRESS_REG, cmd); 1237 1238 /* 1239 * By observation, a successful access takes ~20us on a 5703/4, 1240 * but apparently much longer (up to 1000us) on the obsolescent 1241 * BCM5700/BCM5701. We want to be sure we don't get any false 1242 * timeouts here; but OTOH, we don't want a bogus access to lock 1243 * out interrupts for longer than necessary. So we'll allow up 1244 * to 1000us ... 1245 */ 1246 for (tries = 0; tries < 1000; ++tries) { 1247 regval = bge_reg_get32(bgep, SERIAL_EEPROM_ADDRESS_REG); 1248 if (regval & SEEPROM_ACCESS_COMPLETE) 1249 break; 1250 drv_usecwait(1); 1251 } 1252 1253 if (regval & SEEPROM_ACCESS_COMPLETE) { 1254 /* 1255 * All OK; read the SEEPROM data register, then write back 1256 * the value read from the address register in order to 1257 * clear the <complete> bit and leave the SEEPROM access 1258 * state machine idle, ready for the next access ... 1259 */ 1260 BGE_DEBUG(("bge_seeprom_access: complete after %d us", tries)); 1261 *dp = bge_reg_get32(bgep, SERIAL_EEPROM_DATA_REG); 1262 bge_reg_put32(bgep, SERIAL_EEPROM_ADDRESS_REG, regval); 1263 return (0); 1264 } 1265 1266 /* 1267 * Hmm ... what happened here? 1268 * 1269 * Most likely, the user addressed a non-existent SEEPROM. Or 1270 * maybe the SEEPROM was busy internally (e.g. processing a write) 1271 * and didn't respond to being addressed. Either way, it's left 1272 * the SEEPROM access state machine wedged. So we'll reset it 1273 * before we leave, so it's ready for next time ... 1274 */ 1275 BGE_DEBUG(("bge_seeprom_access: timed out after %d us", tries)); 1276 bge_reg_set32(bgep, SERIAL_EEPROM_ADDRESS_REG, SEEPROM_ACCESS_INIT); 1277 return (ENODATA); 1278 } 1279 1280 /* 1281 * Basic Flash get/set access routine 1282 * 1283 * These use the chip's Flash auto-access method, controlled by the 1284 * Flash Access Registers at 0x7000-701c, so the CPU doesn't have to 1285 * fiddle with the individual bits. 1286 * 1287 * The caller should hold <genlock> and *also* have already acquired 1288 * the right to access the Flash, via bge_nvmem_acquire() above. 1289 * 1290 * Return value: 1291 * 0 on success, 1292 * ENODATA on access timeout (maybe retryable: device may just be busy) 1293 * ENODEV if the NVmem device is missing or otherwise unusable 1294 * 1295 * <*dp> is an input to a NVM_FLASH_CMD_WR operation, or an output 1296 * from a (successful) NVM_FLASH_CMD_RD. 1297 */ 1298 static int bge_flash_access(bge_t *bgep, uint32_t cmd, bge_regno_t addr, 1299 uint32_t *dp); 1300 #pragma no_inline(bge_flash_access) 1301 1302 static int 1303 bge_flash_access(bge_t *bgep, uint32_t cmd, bge_regno_t addr, uint32_t *dp) 1304 { 1305 uint32_t tries; 1306 uint32_t regval; 1307 1308 ASSERT(mutex_owned(bgep->genlock)); 1309 1310 /* 1311 * On the newer chips that support both SEEPROM & Flash, we need 1312 * to specifically disable SEEPROM access while accessing Flash. 1313 * The older chips don't support Flash, and the NVM registers don't 1314 * exist, so we shouldn't be here at all! 1315 */ 1316 switch (bgep->chipid.nvtype) { 1317 case BGE_NVTYPE_NONE: 1318 case BGE_NVTYPE_UNKNOWN: 1319 _NOTE(NOTREACHED) 1320 case BGE_NVTYPE_SEEPROM: 1321 return (ENODEV); 1322 1323 case BGE_NVTYPE_LEGACY_SEEPROM: 1324 case BGE_NVTYPE_UNBUFFERED_FLASH: 1325 case BGE_NVTYPE_BUFFERED_FLASH: 1326 default: 1327 bge_reg_clr32(bgep, NVM_CONFIG1_REG, 1328 NVM_CFG1_LEGACY_SEEPROM_MODE); 1329 break; 1330 } 1331 1332 /* 1333 * Assemble the command ... 1334 */ 1335 addr &= NVM_FLASH_ADDR_MASK; 1336 cmd |= NVM_FLASH_CMD_DOIT; 1337 cmd |= NVM_FLASH_CMD_FIRST; 1338 cmd |= NVM_FLASH_CMD_LAST; 1339 cmd |= NVM_FLASH_CMD_DONE; 1340 1341 bge_reg_put32(bgep, NVM_FLASH_WRITE_REG, *dp); 1342 bge_reg_put32(bgep, NVM_FLASH_ADDR_REG, addr); 1343 bge_reg_put32(bgep, NVM_FLASH_CMD_REG, cmd); 1344 1345 /* 1346 * Allow up to 1000ms ... 1347 */ 1348 for (tries = 0; tries < 1000; ++tries) { 1349 regval = bge_reg_get32(bgep, NVM_FLASH_CMD_REG); 1350 if (regval & NVM_FLASH_CMD_DONE) 1351 break; 1352 drv_usecwait(1); 1353 } 1354 1355 if (regval & NVM_FLASH_CMD_DONE) { 1356 /* 1357 * All OK; read the data from the Flash read register 1358 */ 1359 BGE_DEBUG(("bge_flash_access: complete after %d us", tries)); 1360 *dp = bge_reg_get32(bgep, NVM_FLASH_READ_REG); 1361 return (0); 1362 } 1363 1364 /* 1365 * Hmm ... what happened here? 1366 * 1367 * Most likely, the user addressed a non-existent Flash. Or 1368 * maybe the Flash was busy internally (e.g. processing a write) 1369 * and didn't respond to being addressed. Either way, there's 1370 * nothing we can here ... 1371 */ 1372 BGE_DEBUG(("bge_flash_access: timed out after %d us", tries)); 1373 return (ENODATA); 1374 } 1375 1376 /* 1377 * The next two functions regulate access to the NVram (if fitted). 1378 * 1379 * On a 5704 (dual core) chip, there's only one SEEPROM and one Flash 1380 * (SPI) interface, but they can be accessed through either port. These 1381 * are managed by different instance of this driver and have no software 1382 * state in common. 1383 * 1384 * In addition (and even on a single core chip) the chip's internal 1385 * firmware can access the SEEPROM/Flash, most notably after a RESET 1386 * when it may download code to run internally. 1387 * 1388 * So we need to arbitrate between these various software agents. For 1389 * this purpose, the chip provides the Software Arbitration Register, 1390 * which implements hardware(!) arbitration. 1391 * 1392 * This functionality didn't exist on older (5700/5701) chips, so there's 1393 * nothing we can do by way of arbitration on those; also, if there's no 1394 * SEEPROM/Flash fitted (or we couldn't determine what type), there's also 1395 * nothing to do. 1396 * 1397 * The internal firmware appears to use Request 0, which is the highest 1398 * priority. So we'd like to use Request 2, leaving one higher and one 1399 * lower for any future developments ... but apparently this doesn't 1400 * always work. So for now, the code uses Request 1 ;-( 1401 */ 1402 1403 #define NVM_READ_REQ NVM_READ_REQ1 1404 #define NVM_RESET_REQ NVM_RESET_REQ1 1405 #define NVM_SET_REQ NVM_SET_REQ1 1406 1407 static void bge_nvmem_relinquish(bge_t *bgep); 1408 #pragma no_inline(bge_nvmem_relinquish) 1409 1410 static void 1411 bge_nvmem_relinquish(bge_t *bgep) 1412 { 1413 ASSERT(mutex_owned(bgep->genlock)); 1414 1415 switch (bgep->chipid.nvtype) { 1416 case BGE_NVTYPE_NONE: 1417 case BGE_NVTYPE_UNKNOWN: 1418 _NOTE(NOTREACHED) 1419 return; 1420 1421 case BGE_NVTYPE_SEEPROM: 1422 /* 1423 * No arbitration performed, no release needed 1424 */ 1425 return; 1426 1427 case BGE_NVTYPE_LEGACY_SEEPROM: 1428 case BGE_NVTYPE_UNBUFFERED_FLASH: 1429 case BGE_NVTYPE_BUFFERED_FLASH: 1430 default: 1431 break; 1432 } 1433 1434 /* 1435 * Our own request should be present (whether or not granted) ... 1436 */ 1437 (void) bge_reg_get32(bgep, NVM_SW_ARBITRATION_REG); 1438 1439 /* 1440 * ... this will make it go away. 1441 */ 1442 bge_reg_put32(bgep, NVM_SW_ARBITRATION_REG, NVM_RESET_REQ); 1443 (void) bge_reg_get32(bgep, NVM_SW_ARBITRATION_REG); 1444 } 1445 1446 /* 1447 * Arbitrate for access to the NVmem, if necessary 1448 * 1449 * Return value: 1450 * 0 on success 1451 * EAGAIN if the device is in use (retryable) 1452 * ENODEV if the NVmem device is missing or otherwise unusable 1453 */ 1454 static int bge_nvmem_acquire(bge_t *bgep); 1455 #pragma no_inline(bge_nvmem_acquire) 1456 1457 static int 1458 bge_nvmem_acquire(bge_t *bgep) 1459 { 1460 uint32_t regval; 1461 uint32_t tries; 1462 1463 ASSERT(mutex_owned(bgep->genlock)); 1464 1465 switch (bgep->chipid.nvtype) { 1466 case BGE_NVTYPE_NONE: 1467 case BGE_NVTYPE_UNKNOWN: 1468 /* 1469 * Access denied: no (recognisable) device fitted 1470 */ 1471 return (ENODEV); 1472 1473 case BGE_NVTYPE_SEEPROM: 1474 /* 1475 * Access granted: no arbitration needed (or possible) 1476 */ 1477 return (0); 1478 1479 case BGE_NVTYPE_LEGACY_SEEPROM: 1480 case BGE_NVTYPE_UNBUFFERED_FLASH: 1481 case BGE_NVTYPE_BUFFERED_FLASH: 1482 default: 1483 /* 1484 * Access conditional: conduct arbitration protocol 1485 */ 1486 break; 1487 } 1488 1489 /* 1490 * We're holding the per-port mutex <genlock>, so no-one other 1491 * thread can be attempting to access the NVmem through *this* 1492 * port. But it could be in use by the *other* port (of a 5704), 1493 * or by the chip's internal firmware, so we have to go through 1494 * the full (hardware) arbitration protocol ... 1495 * 1496 * Note that *because* we're holding <genlock>, the interrupt handler 1497 * won't be able to progress. So we're only willing to spin for a 1498 * fairly short time. Specifically: 1499 * 1500 * We *must* wait long enough for the hardware to resolve all 1501 * requests and determine the winner. Fortunately, this is 1502 * "almost instantaneous", even as observed by GHz CPUs. 1503 * 1504 * A successful access by another Solaris thread (via either 1505 * port) typically takes ~20us. So waiting a bit longer than 1506 * that will give a good chance of success, if the other user 1507 * *is* another thread on the other port. 1508 * 1509 * However, the internal firmware can hold on to the NVmem 1510 * for *much* longer: at least 10 milliseconds just after a 1511 * RESET, and maybe even longer if the NVmem actually contains 1512 * code to download and run on the internal CPUs. 1513 * 1514 * So, we'll allow 50us; if that's not enough then it's up to the 1515 * caller to retry later (hence the choice of return code EAGAIN). 1516 */ 1517 regval = bge_reg_get32(bgep, NVM_SW_ARBITRATION_REG); 1518 bge_reg_put32(bgep, NVM_SW_ARBITRATION_REG, NVM_SET_REQ); 1519 1520 for (tries = 0; tries < 50; ++tries) { 1521 regval = bge_reg_get32(bgep, NVM_SW_ARBITRATION_REG); 1522 if (regval & NVM_WON_REQ1) 1523 break; 1524 drv_usecwait(1); 1525 } 1526 1527 if (regval & NVM_WON_REQ1) { 1528 BGE_DEBUG(("bge_nvmem_acquire: won after %d us", tries)); 1529 return (0); 1530 } 1531 1532 /* 1533 * Somebody else must be accessing the NVmem, so abandon our 1534 * attempt take control of it. The caller can try again later ... 1535 */ 1536 BGE_DEBUG(("bge_nvmem_acquire: lost after %d us", tries)); 1537 bge_nvmem_relinquish(bgep); 1538 return (EAGAIN); 1539 } 1540 1541 /* 1542 * This code assumes that the GPIO1 bit has been wired up to the NVmem 1543 * write protect line in such a way that the NVmem is protected when 1544 * GPIO1 is an input, or is an output but driven high. Thus, to make the 1545 * NVmem writable we have to change GPIO1 to an output AND drive it low. 1546 * 1547 * Note: there's only one set of GPIO pins on a 5704, even though they 1548 * can be accessed through either port. So the chip has to resolve what 1549 * happens if the two ports program a single pin differently ... the rule 1550 * it uses is that if the ports disagree about the *direction* of a pin, 1551 * "output" wins over "input", but if they disagree about its *value* as 1552 * an output, then the pin is TRISTATED instead! In such a case, no-one 1553 * wins, and the external signal does whatever the external circuitry 1554 * defines as the default -- which we've assumed is the PROTECTED state. 1555 * So, we always change GPIO1 back to being an *input* whenever we're not 1556 * specifically using it to unprotect the NVmem. This allows either port 1557 * to update the NVmem, although obviously only one at a time! 1558 * 1559 * The caller should hold <genlock> and *also* have already acquired the 1560 * right to access the NVmem, via bge_nvmem_acquire() above. 1561 */ 1562 static void bge_nvmem_protect(bge_t *bgep, boolean_t protect); 1563 #pragma inline(bge_nvmem_protect) 1564 1565 static void 1566 bge_nvmem_protect(bge_t *bgep, boolean_t protect) 1567 { 1568 uint32_t regval; 1569 1570 ASSERT(mutex_owned(bgep->genlock)); 1571 1572 regval = bge_reg_get32(bgep, MISC_LOCAL_CONTROL_REG); 1573 if (protect) { 1574 regval |= MLCR_MISC_PINS_OUTPUT_1; 1575 regval &= ~MLCR_MISC_PINS_OUTPUT_ENABLE_1; 1576 } else { 1577 regval &= ~MLCR_MISC_PINS_OUTPUT_1; 1578 regval |= MLCR_MISC_PINS_OUTPUT_ENABLE_1; 1579 } 1580 bge_reg_put32(bgep, MISC_LOCAL_CONTROL_REG, regval); 1581 } 1582 1583 /* 1584 * Now put it all together ... 1585 * 1586 * Try to acquire control of the NVmem; if successful, then: 1587 * unprotect it (if we want to write to it) 1588 * perform the requested access 1589 * reprotect it (after a write) 1590 * relinquish control 1591 * 1592 * Return value: 1593 * 0 on success, 1594 * EAGAIN if the device is in use (retryable) 1595 * ENODATA on access timeout (maybe retryable: device may just be busy) 1596 * ENODEV if the NVmem device is missing or otherwise unusable 1597 * EPROTO on other h/w or s/w errors. 1598 */ 1599 static int 1600 bge_nvmem_rw32(bge_t *bgep, uint32_t cmd, bge_regno_t addr, uint32_t *dp) 1601 { 1602 int err; 1603 1604 if ((err = bge_nvmem_acquire(bgep)) == 0) { 1605 switch (cmd) { 1606 case BGE_SEE_READ: 1607 err = bge_seeprom_access(bgep, 1608 SEEPROM_ACCESS_READ, addr, dp); 1609 break; 1610 1611 case BGE_SEE_WRITE: 1612 bge_nvmem_protect(bgep, B_FALSE); 1613 err = bge_seeprom_access(bgep, 1614 SEEPROM_ACCESS_WRITE, addr, dp); 1615 bge_nvmem_protect(bgep, B_TRUE); 1616 break; 1617 1618 case BGE_FLASH_READ: 1619 if (DEVICE_5721_SERIES_CHIPSETS(bgep) || 1620 DEVICE_5714_SERIES_CHIPSETS(bgep)) { 1621 bge_reg_set32(bgep, NVM_ACCESS_REG, 1622 NVM_ACCESS_ENABLE); 1623 } 1624 err = bge_flash_access(bgep, 1625 NVM_FLASH_CMD_RD, addr, dp); 1626 if (DEVICE_5721_SERIES_CHIPSETS(bgep) || 1627 DEVICE_5714_SERIES_CHIPSETS(bgep)) { 1628 bge_reg_clr32(bgep, NVM_ACCESS_REG, 1629 NVM_ACCESS_ENABLE); 1630 } 1631 break; 1632 1633 case BGE_FLASH_WRITE: 1634 if (DEVICE_5721_SERIES_CHIPSETS(bgep) || 1635 DEVICE_5714_SERIES_CHIPSETS(bgep)) { 1636 bge_reg_set32(bgep, NVM_ACCESS_REG, 1637 NVM_WRITE_ENABLE|NVM_ACCESS_ENABLE); 1638 } 1639 bge_nvmem_protect(bgep, B_FALSE); 1640 err = bge_flash_access(bgep, 1641 NVM_FLASH_CMD_WR, addr, dp); 1642 bge_nvmem_protect(bgep, B_TRUE); 1643 if (DEVICE_5721_SERIES_CHIPSETS(bgep) || 1644 DEVICE_5714_SERIES_CHIPSETS(bgep)) { 1645 bge_reg_clr32(bgep, NVM_ACCESS_REG, 1646 NVM_WRITE_ENABLE|NVM_ACCESS_ENABLE); 1647 } 1648 1649 break; 1650 1651 default: 1652 _NOTE(NOTREACHED) 1653 break; 1654 } 1655 bge_nvmem_relinquish(bgep); 1656 } 1657 1658 BGE_DEBUG(("bge_nvmem_rw32: err %d", err)); 1659 return (err); 1660 } 1661 1662 /* 1663 * Attempt to get a MAC address from the SEEPROM or Flash, if any 1664 */ 1665 static uint64_t bge_get_nvmac(bge_t *bgep); 1666 #pragma no_inline(bge_get_nvmac) 1667 1668 static uint64_t 1669 bge_get_nvmac(bge_t *bgep) 1670 { 1671 uint32_t mac_high; 1672 uint32_t mac_low; 1673 uint32_t addr; 1674 uint32_t cmd; 1675 uint64_t mac; 1676 1677 BGE_TRACE(("bge_get_nvmac($%p)", 1678 (void *)bgep)); 1679 1680 switch (bgep->chipid.nvtype) { 1681 case BGE_NVTYPE_NONE: 1682 case BGE_NVTYPE_UNKNOWN: 1683 default: 1684 return (0ULL); 1685 1686 case BGE_NVTYPE_SEEPROM: 1687 case BGE_NVTYPE_LEGACY_SEEPROM: 1688 cmd = BGE_SEE_READ; 1689 break; 1690 1691 case BGE_NVTYPE_UNBUFFERED_FLASH: 1692 case BGE_NVTYPE_BUFFERED_FLASH: 1693 cmd = BGE_FLASH_READ; 1694 break; 1695 } 1696 1697 addr = NVMEM_DATA_MAC_ADDRESS; 1698 if (bge_nvmem_rw32(bgep, cmd, addr, &mac_high)) 1699 return (0ULL); 1700 addr += 4; 1701 if (bge_nvmem_rw32(bgep, cmd, addr, &mac_low)) 1702 return (0ULL); 1703 1704 /* 1705 * The Broadcom chip is natively BIG-endian, so that's how the 1706 * MAC address is represented in NVmem. We may need to swap it 1707 * around on a little-endian host ... 1708 */ 1709 #ifdef _BIG_ENDIAN 1710 mac = mac_high; 1711 mac = mac << 32; 1712 mac |= mac_low; 1713 #else 1714 mac = BGE_BSWAP_32(mac_high); 1715 mac = mac << 32; 1716 mac |= BGE_BSWAP_32(mac_low); 1717 #endif /* _BIG_ENDIAN */ 1718 1719 return (mac); 1720 } 1721 1722 #else /* BGE_SEE_IO32 || BGE_FLASH_IO32 */ 1723 1724 /* 1725 * Dummy version for when we're not supporting NVmem access 1726 */ 1727 static uint64_t bge_get_nvmac(bge_t *bgep); 1728 #pragma inline(bge_get_nvmac) 1729 1730 static uint64_t 1731 bge_get_nvmac(bge_t *bgep) 1732 { 1733 _NOTE(ARGUNUSED(bgep)) 1734 return (0ULL); 1735 } 1736 1737 #endif /* BGE_SEE_IO32 || BGE_FLASH_IO32 */ 1738 1739 /* 1740 * Determine the type of NVmem that is (or may be) attached to this chip, 1741 */ 1742 static enum bge_nvmem_type bge_nvmem_id(bge_t *bgep); 1743 #pragma no_inline(bge_nvmem_id) 1744 1745 static enum bge_nvmem_type 1746 bge_nvmem_id(bge_t *bgep) 1747 { 1748 enum bge_nvmem_type nvtype; 1749 uint32_t config1; 1750 1751 BGE_TRACE(("bge_nvmem_id($%p)", 1752 (void *)bgep)); 1753 1754 switch (bgep->chipid.device) { 1755 default: 1756 /* 1757 * We shouldn't get here; it means we don't recognise 1758 * the chip, which means we don't know how to determine 1759 * what sort of NVmem (if any) it has. So we'll say 1760 * NONE, to disable the NVmem access code ... 1761 */ 1762 nvtype = BGE_NVTYPE_NONE; 1763 break; 1764 1765 case DEVICE_ID_5700: 1766 case DEVICE_ID_5700x: 1767 case DEVICE_ID_5701: 1768 /* 1769 * These devices support *only* SEEPROMs 1770 */ 1771 nvtype = BGE_NVTYPE_SEEPROM; 1772 break; 1773 1774 case DEVICE_ID_5702: 1775 case DEVICE_ID_5702fe: 1776 case DEVICE_ID_5703C: 1777 case DEVICE_ID_5703S: 1778 case DEVICE_ID_5704C: 1779 case DEVICE_ID_5704S: 1780 case DEVICE_ID_5704: 1781 case DEVICE_ID_5705M: 1782 case DEVICE_ID_5705C: 1783 case DEVICE_ID_5705_2: 1784 case DEVICE_ID_5706: 1785 case DEVICE_ID_5782: 1786 case DEVICE_ID_5787: 1787 case DEVICE_ID_5787M: 1788 case DEVICE_ID_5788: 1789 case DEVICE_ID_5789: 1790 case DEVICE_ID_5751: 1791 case DEVICE_ID_5751M: 1792 case DEVICE_ID_5752: 1793 case DEVICE_ID_5752M: 1794 case DEVICE_ID_5754: 1795 case DEVICE_ID_5755: 1796 case DEVICE_ID_5755M: 1797 case DEVICE_ID_5721: 1798 case DEVICE_ID_5714C: 1799 case DEVICE_ID_5714S: 1800 case DEVICE_ID_5715C: 1801 case DEVICE_ID_5715S: 1802 config1 = bge_reg_get32(bgep, NVM_CONFIG1_REG); 1803 if (config1 & NVM_CFG1_FLASH_MODE) 1804 if (config1 & NVM_CFG1_BUFFERED_MODE) 1805 nvtype = BGE_NVTYPE_BUFFERED_FLASH; 1806 else 1807 nvtype = BGE_NVTYPE_UNBUFFERED_FLASH; 1808 else 1809 nvtype = BGE_NVTYPE_LEGACY_SEEPROM; 1810 break; 1811 } 1812 1813 return (nvtype); 1814 } 1815 1816 #undef BGE_DBG 1817 #define BGE_DBG BGE_DBG_CHIP /* debug flag for this code */ 1818 1819 static void 1820 bge_init_recv_rule(bge_t *bgep) 1821 { 1822 bge_recv_rule_t *rulep; 1823 uint32_t i; 1824 1825 /* 1826 * receive rule: direct all TCP traffic to ring RULE_MATCH_TO_RING 1827 * 1. to direct UDP traffic, set: 1828 * rulep->control = RULE_PROTO_CONTROL; 1829 * rulep->mask_value = RULE_UDP_MASK_VALUE; 1830 * 2. to direct ICMP traffic, set: 1831 * rulep->control = RULE_PROTO_CONTROL; 1832 * rulep->mask_value = RULE_ICMP_MASK_VALUE; 1833 * 3. to direct traffic by source ip, set: 1834 * rulep->control = RULE_SIP_CONTROL; 1835 * rulep->mask_value = RULE_SIP_MASK_VALUE; 1836 */ 1837 rulep = bgep->recv_rules; 1838 rulep->control = RULE_PROTO_CONTROL; 1839 rulep->mask_value = RULE_TCP_MASK_VALUE; 1840 1841 /* 1842 * set receive rule registers 1843 */ 1844 rulep = bgep->recv_rules; 1845 for (i = 0; i < RECV_RULES_NUM_MAX; i++, rulep++) { 1846 bge_reg_put32(bgep, RECV_RULE_MASK_REG(i), rulep->mask_value); 1847 bge_reg_put32(bgep, RECV_RULE_CONTROL_REG(i), rulep->control); 1848 } 1849 } 1850 1851 /* 1852 * Using the values captured by bge_chip_cfg_init(), and additional probes 1853 * as required, characterise the chip fully: determine the label by which 1854 * to refer to this chip, the correct settings for various registers, and 1855 * of course whether the device and/or subsystem are supported! 1856 */ 1857 int bge_chip_id_init(bge_t *bgep); 1858 #pragma no_inline(bge_chip_id_init) 1859 1860 int 1861 bge_chip_id_init(bge_t *bgep) 1862 { 1863 char buf[MAXPATHLEN]; /* any risk of stack overflow? */ 1864 boolean_t sys_ok; 1865 boolean_t dev_ok; 1866 chip_id_t *cidp; 1867 uint32_t subid; 1868 char *devname; 1869 char *sysname; 1870 int *ids; 1871 int err; 1872 uint_t i; 1873 1874 sys_ok = dev_ok = B_FALSE; 1875 cidp = &bgep->chipid; 1876 1877 /* 1878 * Check the PCI device ID to determine the generic chip type and 1879 * select parameters that depend on this. 1880 * 1881 * Note: because the SPARC platforms in general don't fit the 1882 * SEEPROM 'behind' the chip, the PCI revision ID register reads 1883 * as zero - which is why we use <asic_rev> rather than <revision> 1884 * below ... 1885 * 1886 * Note: in general we can't distinguish between the Copper/SerDes 1887 * versions by ID alone, as some Copper devices (e.g. some but not 1888 * all 5703Cs) have the same ID as the SerDes equivalents. So we 1889 * treat them the same here, and the MII code works out the media 1890 * type later on ... 1891 */ 1892 cidp->mbuf_base = bge_mbuf_pool_base; 1893 cidp->mbuf_length = bge_mbuf_pool_len; 1894 cidp->recv_slots = BGE_RECV_SLOTS_USED; 1895 cidp->bge_dma_rwctrl = bge_dma_rwctrl; 1896 cidp->pci_type = BGE_PCI_X; 1897 cidp->statistic_type = BGE_STAT_BLK; 1898 cidp->mbuf_lo_water_rdma = bge_mbuf_lo_water_rdma; 1899 cidp->mbuf_lo_water_rmac = bge_mbuf_lo_water_rmac; 1900 cidp->mbuf_hi_water = bge_mbuf_hi_water; 1901 cidp->rx_ticks_norm = bge_rx_ticks_norm; 1902 cidp->rx_count_norm = bge_rx_count_norm; 1903 1904 if (cidp->rx_rings == 0 || cidp->rx_rings > BGE_RECV_RINGS_MAX) 1905 cidp->rx_rings = BGE_RECV_RINGS_DEFAULT; 1906 if (cidp->tx_rings == 0 || cidp->tx_rings > BGE_SEND_RINGS_MAX) 1907 cidp->tx_rings = BGE_SEND_RINGS_DEFAULT; 1908 1909 cidp->msi_enabled = B_FALSE; 1910 1911 switch (cidp->device) { 1912 case DEVICE_ID_5700: 1913 case DEVICE_ID_5700x: 1914 cidp->chip_label = 5700; 1915 cidp->flags |= CHIP_FLAG_PARTIAL_CSUM; 1916 break; 1917 1918 case DEVICE_ID_5701: 1919 cidp->chip_label = 5701; 1920 dev_ok = B_TRUE; 1921 cidp->flags |= CHIP_FLAG_PARTIAL_CSUM; 1922 break; 1923 1924 case DEVICE_ID_5702: 1925 case DEVICE_ID_5702fe: 1926 cidp->chip_label = 5702; 1927 dev_ok = B_TRUE; 1928 cidp->flags |= CHIP_FLAG_PARTIAL_CSUM; 1929 cidp->pci_type = BGE_PCI; 1930 break; 1931 1932 case DEVICE_ID_5703C: 1933 case DEVICE_ID_5703S: 1934 case DEVICE_ID_5703: 1935 /* 1936 * Revision A0 of the 5703/5793 had various errata 1937 * that we can't or don't work around, so it's not 1938 * supported, but all later versions are 1939 */ 1940 cidp->chip_label = cidp->subven == VENDOR_ID_SUN ? 5793 : 5703; 1941 if (bgep->chipid.asic_rev != MHCR_CHIP_REV_5703_A0) 1942 dev_ok = B_TRUE; 1943 cidp->flags |= CHIP_FLAG_PARTIAL_CSUM; 1944 break; 1945 1946 case DEVICE_ID_5704C: 1947 case DEVICE_ID_5704S: 1948 case DEVICE_ID_5704: 1949 cidp->chip_label = cidp->subven == VENDOR_ID_SUN ? 5794 : 5704; 1950 cidp->mbuf_base = bge_mbuf_pool_base_5704; 1951 cidp->mbuf_length = bge_mbuf_pool_len_5704; 1952 dev_ok = B_TRUE; 1953 cidp->flags |= CHIP_FLAG_PARTIAL_CSUM; 1954 break; 1955 1956 case DEVICE_ID_5705C: 1957 case DEVICE_ID_5705M: 1958 case DEVICE_ID_5705MA3: 1959 case DEVICE_ID_5705F: 1960 case DEVICE_ID_5705_2: 1961 case DEVICE_ID_5754: 1962 if (cidp->device == DEVICE_ID_5754) { 1963 cidp->chip_label = 5754; 1964 cidp->pci_type = BGE_PCI_E; 1965 } else { 1966 cidp->chip_label = 5705; 1967 cidp->pci_type = BGE_PCI; 1968 } 1969 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 1970 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 1971 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 1972 cidp->mbuf_base = bge_mbuf_pool_base_5705; 1973 cidp->mbuf_length = bge_mbuf_pool_len_5705; 1974 cidp->recv_slots = BGE_RECV_SLOTS_5705; 1975 cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 1976 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 1977 cidp->flags |= CHIP_FLAG_NO_JUMBO; 1978 cidp->flags |= CHIP_FLAG_PARTIAL_CSUM; 1979 cidp->statistic_type = BGE_STAT_REG; 1980 dev_ok = B_TRUE; 1981 break; 1982 1983 case DEVICE_ID_5753: 1984 cidp->chip_label = 5753; 1985 cidp->pci_type = BGE_PCI_E; 1986 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 1987 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 1988 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 1989 cidp->mbuf_base = bge_mbuf_pool_base_5705; 1990 cidp->mbuf_length = bge_mbuf_pool_len_5705; 1991 cidp->recv_slots = BGE_RECV_SLOTS_5705; 1992 cidp->bge_mlcr_default |= MLCR_MISC_PINS_OUTPUT_ENABLE_1; 1993 cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 1994 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 1995 cidp->flags |= CHIP_FLAG_NO_JUMBO; 1996 cidp->statistic_type = BGE_STAT_REG; 1997 dev_ok = B_TRUE; 1998 break; 1999 2000 case DEVICE_ID_5755: 2001 case DEVICE_ID_5755M: 2002 cidp->chip_label = 5755; 2003 cidp->pci_type = BGE_PCI_E; 2004 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 2005 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 2006 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 2007 cidp->mbuf_base = bge_mbuf_pool_base_5705; 2008 cidp->mbuf_length = bge_mbuf_pool_len_5705; 2009 cidp->recv_slots = BGE_RECV_SLOTS_5705; 2010 cidp->bge_mlcr_default |= MLCR_MISC_PINS_OUTPUT_ENABLE_1; 2011 cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 2012 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 2013 cidp->flags |= CHIP_FLAG_NO_JUMBO; 2014 cidp->flags |= CHIP_FLAG_PARTIAL_CSUM; 2015 cidp->statistic_type = BGE_STAT_REG; 2016 dev_ok = B_TRUE; 2017 break; 2018 2019 case DEVICE_ID_5787: 2020 case DEVICE_ID_5787M: 2021 cidp->chip_label = 5787; 2022 cidp->pci_type = BGE_PCI_E; 2023 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 2024 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 2025 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 2026 cidp->mbuf_base = bge_mbuf_pool_base_5705; 2027 cidp->mbuf_length = bge_mbuf_pool_len_5705; 2028 cidp->recv_slots = BGE_RECV_SLOTS_5705; 2029 cidp->bge_mlcr_default |= MLCR_MISC_PINS_OUTPUT_ENABLE_1; 2030 cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 2031 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 2032 cidp->flags |= CHIP_FLAG_NO_JUMBO; 2033 cidp->statistic_type = BGE_STAT_REG; 2034 dev_ok = B_TRUE; 2035 break; 2036 2037 case DEVICE_ID_5706: 2038 cidp->chip_label = 5706; 2039 cidp->flags |= CHIP_FLAG_NO_JUMBO; 2040 break; 2041 2042 case DEVICE_ID_5782: 2043 /* 2044 * Apart from the label, we treat this as a 5705(?) 2045 */ 2046 cidp->chip_label = 5782; 2047 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 2048 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 2049 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 2050 cidp->mbuf_base = bge_mbuf_pool_base_5705; 2051 cidp->mbuf_length = bge_mbuf_pool_len_5705; 2052 cidp->recv_slots = BGE_RECV_SLOTS_5705; 2053 cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 2054 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 2055 cidp->flags |= CHIP_FLAG_NO_JUMBO; 2056 cidp->flags |= CHIP_FLAG_PARTIAL_CSUM; 2057 cidp->statistic_type = BGE_STAT_REG; 2058 dev_ok = B_TRUE; 2059 break; 2060 2061 case DEVICE_ID_5788: 2062 /* 2063 * Apart from the label, we treat this as a 5705(?) 2064 */ 2065 cidp->chip_label = 5788; 2066 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 2067 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 2068 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 2069 cidp->mbuf_base = bge_mbuf_pool_base_5705; 2070 cidp->mbuf_length = bge_mbuf_pool_len_5705; 2071 cidp->recv_slots = BGE_RECV_SLOTS_5705; 2072 cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 2073 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 2074 cidp->statistic_type = BGE_STAT_REG; 2075 cidp->flags |= CHIP_FLAG_NO_JUMBO; 2076 dev_ok = B_TRUE; 2077 break; 2078 2079 case DEVICE_ID_5714C: 2080 if (cidp->revision >= REVISION_ID_5714_A2) 2081 cidp->msi_enabled = bge_enable_msi; 2082 /* FALLTHRU */ 2083 case DEVICE_ID_5714S: 2084 cidp->chip_label = 5714; 2085 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 2086 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 2087 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 2088 cidp->mbuf_base = bge_mbuf_pool_base_5721; 2089 cidp->mbuf_length = bge_mbuf_pool_len_5721; 2090 cidp->recv_slots = BGE_RECV_SLOTS_5721; 2091 cidp->bge_dma_rwctrl = bge_dma_rwctrl_5714; 2092 cidp->bge_mlcr_default = bge_mlcr_default_5714; 2093 cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 2094 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 2095 cidp->pci_type = BGE_PCI_E; 2096 cidp->statistic_type = BGE_STAT_REG; 2097 dev_ok = B_TRUE; 2098 break; 2099 2100 case DEVICE_ID_5715C: 2101 case DEVICE_ID_5715S: 2102 cidp->chip_label = 5715; 2103 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 2104 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 2105 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 2106 cidp->mbuf_base = bge_mbuf_pool_base_5721; 2107 cidp->mbuf_length = bge_mbuf_pool_len_5721; 2108 cidp->recv_slots = BGE_RECV_SLOTS_5721; 2109 cidp->bge_dma_rwctrl = bge_dma_rwctrl_5715; 2110 cidp->bge_mlcr_default = bge_mlcr_default_5714; 2111 cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 2112 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 2113 cidp->pci_type = BGE_PCI_E; 2114 cidp->statistic_type = BGE_STAT_REG; 2115 if (cidp->revision >= REVISION_ID_5715_A2) 2116 cidp->msi_enabled = bge_enable_msi; 2117 dev_ok = B_TRUE; 2118 break; 2119 2120 case DEVICE_ID_5721: 2121 cidp->chip_label = 5721; 2122 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 2123 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 2124 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 2125 cidp->mbuf_base = bge_mbuf_pool_base_5721; 2126 cidp->mbuf_length = bge_mbuf_pool_len_5721; 2127 cidp->recv_slots = BGE_RECV_SLOTS_5721; 2128 cidp->bge_dma_rwctrl = bge_dma_rwctrl_5721; 2129 cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 2130 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 2131 cidp->pci_type = BGE_PCI_E; 2132 cidp->statistic_type = BGE_STAT_REG; 2133 cidp->flags |= CHIP_FLAG_NO_JUMBO; 2134 dev_ok = B_TRUE; 2135 break; 2136 2137 case DEVICE_ID_5751: 2138 case DEVICE_ID_5751M: 2139 cidp->chip_label = 5751; 2140 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 2141 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 2142 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 2143 cidp->mbuf_base = bge_mbuf_pool_base_5721; 2144 cidp->mbuf_length = bge_mbuf_pool_len_5721; 2145 cidp->recv_slots = BGE_RECV_SLOTS_5721; 2146 cidp->bge_dma_rwctrl = bge_dma_rwctrl_5721; 2147 cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 2148 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 2149 cidp->pci_type = BGE_PCI_E; 2150 cidp->statistic_type = BGE_STAT_REG; 2151 cidp->flags |= CHIP_FLAG_NO_JUMBO; 2152 dev_ok = B_TRUE; 2153 break; 2154 2155 case DEVICE_ID_5752: 2156 case DEVICE_ID_5752M: 2157 cidp->chip_label = 5752; 2158 cidp->mbuf_lo_water_rdma = RDMA_MBUF_LOWAT_5705; 2159 cidp->mbuf_lo_water_rmac = MAC_RX_MBUF_LOWAT_5705; 2160 cidp->mbuf_hi_water = MBUF_HIWAT_5705; 2161 cidp->mbuf_base = bge_mbuf_pool_base_5721; 2162 cidp->mbuf_length = bge_mbuf_pool_len_5721; 2163 cidp->recv_slots = BGE_RECV_SLOTS_5721; 2164 cidp->bge_dma_rwctrl = bge_dma_rwctrl_5721; 2165 cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 2166 cidp->tx_rings = BGE_SEND_RINGS_MAX_5705; 2167 cidp->pci_type = BGE_PCI_E; 2168 cidp->statistic_type = BGE_STAT_REG; 2169 cidp->flags |= CHIP_FLAG_NO_JUMBO; 2170 dev_ok = B_TRUE; 2171 break; 2172 2173 case DEVICE_ID_5789: 2174 cidp->chip_label = 5789; 2175 cidp->mbuf_base = bge_mbuf_pool_base_5721; 2176 cidp->mbuf_length = bge_mbuf_pool_len_5721; 2177 cidp->recv_slots = BGE_RECV_SLOTS_5721; 2178 cidp->bge_dma_rwctrl = bge_dma_rwctrl_5721; 2179 cidp->rx_rings = BGE_RECV_RINGS_MAX_5705; 2180 cidp->tx_rings = BGE_RECV_RINGS_MAX_5705; 2181 cidp->pci_type = BGE_PCI_E; 2182 cidp->statistic_type = BGE_STAT_REG; 2183 cidp->flags |= CHIP_FLAG_PARTIAL_CSUM; 2184 cidp->flags |= CHIP_FLAG_NO_JUMBO; 2185 cidp->msi_enabled = B_TRUE; 2186 dev_ok = B_TRUE; 2187 break; 2188 2189 } 2190 2191 /* 2192 * Setup the default jumbo parameter. 2193 */ 2194 cidp->ethmax_size = ETHERMAX; 2195 cidp->snd_buff_size = BGE_SEND_BUFF_SIZE_DEFAULT; 2196 cidp->std_buf_size = BGE_STD_BUFF_SIZE; 2197 2198 /* 2199 * If jumbo is enabled and this kind of chipset supports jumbo feature, 2200 * setup below jumbo specific parameters. 2201 * 2202 * For BCM5714/5715, there is only one standard receive ring. So the 2203 * std buffer size should be set to BGE_JUMBO_BUFF_SIZE when jumbo 2204 * feature is enabled. 2205 */ 2206 if (bge_jumbo_enable && 2207 !(cidp->flags & CHIP_FLAG_NO_JUMBO) && 2208 (cidp->default_mtu > BGE_DEFAULT_MTU) && 2209 (cidp->default_mtu <= BGE_MAXIMUM_MTU)) { 2210 if (DEVICE_5714_SERIES_CHIPSETS(bgep)) { 2211 cidp->mbuf_lo_water_rdma = 2212 RDMA_MBUF_LOWAT_5714_JUMBO; 2213 cidp->mbuf_lo_water_rmac = 2214 MAC_RX_MBUF_LOWAT_5714_JUMBO; 2215 cidp->mbuf_hi_water = MBUF_HIWAT_5714_JUMBO; 2216 cidp->jumbo_slots = 0; 2217 cidp->std_buf_size = BGE_JUMBO_BUFF_SIZE; 2218 } else { 2219 cidp->mbuf_lo_water_rdma = 2220 RDMA_MBUF_LOWAT_JUMBO; 2221 cidp->mbuf_lo_water_rmac = 2222 MAC_RX_MBUF_LOWAT_JUMBO; 2223 cidp->mbuf_hi_water = MBUF_HIWAT_JUMBO; 2224 cidp->jumbo_slots = BGE_JUMBO_SLOTS_USED; 2225 } 2226 cidp->recv_jumbo_size = BGE_JUMBO_BUFF_SIZE; 2227 cidp->snd_buff_size = BGE_SEND_BUFF_SIZE_JUMBO; 2228 cidp->ethmax_size = cidp->default_mtu + 2229 sizeof (struct ether_header); 2230 } 2231 2232 /* 2233 * Identify the NV memory type: SEEPROM or Flash? 2234 */ 2235 cidp->nvtype = bge_nvmem_id(bgep); 2236 2237 /* 2238 * Now, we want to check whether this device is part of a 2239 * supported subsystem (e.g., on the motherboard of a Sun 2240 * branded platform). 2241 * 2242 * Rule 1: If the Subsystem Vendor ID is "Sun", then it's OK ;-) 2243 */ 2244 if (cidp->subven == VENDOR_ID_SUN) 2245 sys_ok = B_TRUE; 2246 2247 /* 2248 * Rule 2: If it's on the list on known subsystems, then it's OK. 2249 * Note: 0x14e41647 should *not* appear in the list, but the code 2250 * doesn't enforce that. 2251 */ 2252 err = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, bgep->devinfo, 2253 DDI_PROP_DONTPASS, knownids_propname, &ids, &i); 2254 if (err == DDI_PROP_SUCCESS) { 2255 /* 2256 * Got the list; scan for a matching subsystem vendor/device 2257 */ 2258 subid = (cidp->subven << 16) | cidp->subdev; 2259 while (i--) 2260 if (ids[i] == subid) 2261 sys_ok = B_TRUE; 2262 ddi_prop_free(ids); 2263 } 2264 2265 /* 2266 * Rule 3: If it's a Taco/ENWS motherboard device, then it's OK 2267 * 2268 * Unfortunately, early SunBlade 1500s and 2500s didn't reprogram 2269 * the Subsystem Vendor ID, so it defaults to Broadcom. Therefore, 2270 * we have to check specially for the exact device paths to the 2271 * motherboard devices on those platforms ;-( 2272 * 2273 * Note: we can't just use the "supported-subsystems" mechanism 2274 * above, because the entry would have to be 0x14e41647 -- which 2275 * would then accept *any* plugin card that *didn't* contain a 2276 * (valid) SEEPROM ;-( 2277 */ 2278 sysname = ddi_node_name(ddi_root_node()); 2279 devname = ddi_pathname(bgep->devinfo, buf); 2280 ASSERT(strlen(devname) > 0); 2281 if (strcmp(sysname, "SUNW,Sun-Blade-1500") == 0) /* Taco */ 2282 if (strcmp(devname, "/pci@1f,700000/network@2") == 0) 2283 sys_ok = B_TRUE; 2284 if (strcmp(sysname, "SUNW,Sun-Blade-2500") == 0) /* ENWS */ 2285 if (strcmp(devname, "/pci@1c,600000/network@3") == 0) 2286 sys_ok = B_TRUE; 2287 2288 /* 2289 * Now check what we've discovered: is this truly a supported 2290 * chip on (the motherboard of) a supported platform? 2291 * 2292 * Possible problems here: 2293 * 1) it's a completely unheard-of chip (e.g. 5761) 2294 * 2) it's a recognised but unsupported chip (e.g. 5701, 5703C-A0) 2295 * 3) it's a chip we would support if it were on the motherboard 2296 * of a Sun platform, but this one isn't ;-( 2297 */ 2298 if (cidp->chip_label == 0) 2299 bge_problem(bgep, 2300 "Device 'pci%04x,%04x' not recognized (%d?)", 2301 cidp->vendor, cidp->device, cidp->device); 2302 else if (!dev_ok) 2303 bge_problem(bgep, 2304 "Device 'pci%04x,%04x' (%d) revision %d not supported", 2305 cidp->vendor, cidp->device, cidp->chip_label, 2306 cidp->revision); 2307 #if BGE_DEBUGGING 2308 else if (!sys_ok) 2309 bge_problem(bgep, 2310 "%d-based subsystem 'pci%04x,%04x' not validated", 2311 cidp->chip_label, cidp->subven, cidp->subdev); 2312 #endif 2313 else 2314 cidp->flags |= CHIP_FLAG_SUPPORTED; 2315 if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) 2316 return (EIO); 2317 return (0); 2318 } 2319 2320 void 2321 bge_chip_msi_trig(bge_t *bgep) 2322 { 2323 uint32_t regval; 2324 2325 regval = bgep->param_msi_cnt<<4; 2326 bge_reg_set32(bgep, HOST_COALESCE_MODE_REG, regval); 2327 BGE_DEBUG(("bge_chip_msi_trig:data = %d", regval)); 2328 } 2329 2330 /* 2331 * Various registers that control the chip's internal engines (state 2332 * machines) have a <reset> and <enable> bits (fortunately, in the 2333 * same place in each such register :-). 2334 * 2335 * To reset the state machine, the <reset> bit must be written with 1; 2336 * it will then read back as 1 while the reset is in progress, but 2337 * self-clear to 0 when the reset completes. 2338 * 2339 * To enable a state machine, one must set the <enable> bit, which 2340 * will continue to read back as 0 until the state machine is running. 2341 * 2342 * To disable a state machine, the <enable> bit must be cleared, but 2343 * it will continue to read back as 1 until the state machine actually 2344 * stops. 2345 * 2346 * This routine implements polling for completion of a reset, enable 2347 * or disable operation, returning B_TRUE on success (bit reached the 2348 * required state) or B_FALSE on timeout (200*100us == 20ms). 2349 */ 2350 static boolean_t bge_chip_poll_engine(bge_t *bgep, bge_regno_t regno, 2351 uint32_t mask, uint32_t val); 2352 #pragma no_inline(bge_chip_poll_engine) 2353 2354 static boolean_t 2355 bge_chip_poll_engine(bge_t *bgep, bge_regno_t regno, 2356 uint32_t mask, uint32_t val) 2357 { 2358 uint32_t regval; 2359 uint32_t n; 2360 2361 BGE_TRACE(("bge_chip_poll_engine($%p, 0x%lx, 0x%x, 0x%x)", 2362 (void *)bgep, regno, mask, val)); 2363 2364 for (n = 200; n; --n) { 2365 regval = bge_reg_get32(bgep, regno); 2366 if ((regval & mask) == val) 2367 return (B_TRUE); 2368 drv_usecwait(100); 2369 } 2370 2371 bge_fm_ereport(bgep, DDI_FM_DEVICE_NO_RESPONSE); 2372 return (B_FALSE); 2373 } 2374 2375 /* 2376 * Various registers that control the chip's internal engines (state 2377 * machines) have a <reset> bit (fortunately, in the same place in 2378 * each such register :-). To reset the state machine, this bit must 2379 * be written with 1; it will then read back as 1 while the reset is 2380 * in progress, but self-clear to 0 when the reset completes. 2381 * 2382 * This code sets the bit, then polls for it to read back as zero. 2383 * The return value is B_TRUE on success (reset bit cleared itself), 2384 * or B_FALSE if the state machine didn't recover :( 2385 * 2386 * NOTE: the Core reset is similar to other resets, except that we 2387 * can't poll for completion, since the Core reset disables memory 2388 * access! So we just have to assume that it will all complete in 2389 * 100us. See Broadcom document 570X-PG102-R, p102, steps 4-5. 2390 */ 2391 static boolean_t bge_chip_reset_engine(bge_t *bgep, bge_regno_t regno); 2392 #pragma no_inline(bge_chip_reset_engine) 2393 2394 static boolean_t 2395 bge_chip_reset_engine(bge_t *bgep, bge_regno_t regno) 2396 { 2397 uint32_t regval; 2398 uint32_t val32; 2399 2400 regval = bge_reg_get32(bgep, regno); 2401 2402 BGE_TRACE(("bge_chip_reset_engine($%p, 0x%lx)", 2403 (void *)bgep, regno)); 2404 BGE_DEBUG(("bge_chip_reset_engine: 0x%lx before reset = 0x%08x", 2405 regno, regval)); 2406 2407 regval |= STATE_MACHINE_RESET_BIT; 2408 2409 switch (regno) { 2410 case MISC_CONFIG_REG: 2411 /* 2412 * BCM5714/5721/5751 pcie chip special case. In order to avoid 2413 * resetting PCIE block and bringing PCIE link down, bit 29 2414 * in the register needs to be set first, and then set it again 2415 * while the reset bit is written. 2416 * See:P500 of 57xx-PG102-RDS.pdf. 2417 */ 2418 if (DEVICE_5705_SERIES_CHIPSETS(bgep)|| 2419 DEVICE_5721_SERIES_CHIPSETS(bgep)|| 2420 DEVICE_5714_SERIES_CHIPSETS(bgep)) { 2421 regval |= MISC_CONFIG_GPHY_POWERDOWN_OVERRIDE; 2422 if (bgep->chipid.pci_type == BGE_PCI_E) { 2423 if (bgep->chipid.asic_rev == 2424 MHCR_CHIP_REV_5751_A0 || 2425 bgep->chipid.asic_rev == 2426 MHCR_CHIP_REV_5721_A0 || 2427 bgep->chipid.asic_rev == 2428 MHCR_CHIP_REV_5755_A0) { 2429 val32 = bge_reg_get32(bgep, 2430 PHY_TEST_CTRL_REG); 2431 if (val32 == (PHY_PCIE_SCRAM_MODE | 2432 PHY_PCIE_LTASS_MODE)) 2433 bge_reg_put32(bgep, 2434 PHY_TEST_CTRL_REG, 2435 PHY_PCIE_SCRAM_MODE); 2436 val32 = pci_config_get32 2437 (bgep->cfg_handle, 2438 PCI_CONF_BGE_CLKCTL); 2439 val32 |= CLKCTL_PCIE_A0_FIX; 2440 pci_config_put32(bgep->cfg_handle, 2441 PCI_CONF_BGE_CLKCTL, val32); 2442 } 2443 bge_reg_set32(bgep, regno, 2444 MISC_CONFIG_GRC_RESET_DISABLE); 2445 regval |= MISC_CONFIG_GRC_RESET_DISABLE; 2446 } 2447 } 2448 2449 /* 2450 * Special case - causes Core reset 2451 * 2452 * On SPARC v9 we want to ensure that we don't start 2453 * timing until the I/O access has actually reached 2454 * the chip, otherwise we might make the next access 2455 * too early. And we can't just force the write out 2456 * by following it with a read (even to config space) 2457 * because that would cause the fault we're trying 2458 * to avoid. Hence the need for membar_sync() here. 2459 */ 2460 ddi_put32(bgep->io_handle, PIO_ADDR(bgep, regno), regval); 2461 #ifdef __sparcv9 2462 membar_sync(); 2463 #endif /* __sparcv9 */ 2464 /* 2465 * On some platforms,system need about 300us for 2466 * link setup. 2467 */ 2468 drv_usecwait(300); 2469 2470 if (bgep->chipid.pci_type == BGE_PCI_E) { 2471 /* PCI-E device need more reset time */ 2472 drv_usecwait(120000); 2473 2474 /* Set PCIE max payload size and clear error status. */ 2475 if ((bgep->chipid.chip_label == 5721) || 2476 (bgep->chipid.chip_label == 5751) || 2477 (bgep->chipid.chip_label == 5752) || 2478 (bgep->chipid.chip_label == 5789)) { 2479 pci_config_put16(bgep->cfg_handle, 2480 PCI_CONF_DEV_CTRL, READ_REQ_SIZE_MAX); 2481 pci_config_put16(bgep->cfg_handle, 2482 PCI_CONF_DEV_STUS, DEVICE_ERROR_STUS); 2483 } 2484 } 2485 2486 BGE_PCICHK(bgep); 2487 return (B_TRUE); 2488 2489 default: 2490 bge_reg_put32(bgep, regno, regval); 2491 return (bge_chip_poll_engine(bgep, regno, 2492 STATE_MACHINE_RESET_BIT, 0)); 2493 } 2494 } 2495 2496 /* 2497 * Various registers that control the chip's internal engines (state 2498 * machines) have an <enable> bit (fortunately, in the same place in 2499 * each such register :-). To stop the state machine, this bit must 2500 * be written with 0, then polled to see when the state machine has 2501 * actually stopped. 2502 * 2503 * The return value is B_TRUE on success (enable bit cleared), or 2504 * B_FALSE if the state machine didn't stop :( 2505 */ 2506 static boolean_t bge_chip_disable_engine(bge_t *bgep, bge_regno_t regno, 2507 uint32_t morebits); 2508 #pragma no_inline(bge_chip_disable_engine) 2509 2510 static boolean_t 2511 bge_chip_disable_engine(bge_t *bgep, bge_regno_t regno, uint32_t morebits) 2512 { 2513 uint32_t regval; 2514 2515 BGE_TRACE(("bge_chip_disable_engine($%p, 0x%lx, 0x%x)", 2516 (void *)bgep, regno, morebits)); 2517 2518 switch (regno) { 2519 case FTQ_RESET_REG: 2520 /* 2521 * For Schumacher's bugfix CR6490108 2522 */ 2523 #ifdef BGE_IPMI_ASF 2524 #ifdef BGE_NETCONSOLE 2525 if (bgep->asf_enabled) 2526 return (B_TRUE); 2527 #endif 2528 #endif 2529 /* 2530 * Not quite like the others; it doesn't 2531 * have an <enable> bit, but instead we 2532 * have to set and then clear all the bits 2533 */ 2534 bge_reg_put32(bgep, regno, ~(uint32_t)0); 2535 drv_usecwait(100); 2536 bge_reg_put32(bgep, regno, 0); 2537 return (B_TRUE); 2538 2539 default: 2540 regval = bge_reg_get32(bgep, regno); 2541 regval &= ~STATE_MACHINE_ENABLE_BIT; 2542 regval &= ~morebits; 2543 bge_reg_put32(bgep, regno, regval); 2544 return (bge_chip_poll_engine(bgep, regno, 2545 STATE_MACHINE_ENABLE_BIT, 0)); 2546 } 2547 } 2548 2549 /* 2550 * Various registers that control the chip's internal engines (state 2551 * machines) have an <enable> bit (fortunately, in the same place in 2552 * each such register :-). To start the state machine, this bit must 2553 * be written with 1, then polled to see when the state machine has 2554 * actually started. 2555 * 2556 * The return value is B_TRUE on success (enable bit set), or 2557 * B_FALSE if the state machine didn't start :( 2558 */ 2559 static boolean_t bge_chip_enable_engine(bge_t *bgep, bge_regno_t regno, 2560 uint32_t morebits); 2561 #pragma no_inline(bge_chip_enable_engine) 2562 2563 static boolean_t 2564 bge_chip_enable_engine(bge_t *bgep, bge_regno_t regno, uint32_t morebits) 2565 { 2566 uint32_t regval; 2567 2568 BGE_TRACE(("bge_chip_enable_engine($%p, 0x%lx, 0x%x)", 2569 (void *)bgep, regno, morebits)); 2570 2571 switch (regno) { 2572 case FTQ_RESET_REG: 2573 #ifdef BGE_IPMI_ASF 2574 #ifdef BGE_NETCONSOLE 2575 if (bgep->asf_enabled) 2576 return (B_TRUE); 2577 #endif 2578 #endif 2579 /* 2580 * Not quite like the others; it doesn't 2581 * have an <enable> bit, but instead we 2582 * have to set and then clear all the bits 2583 */ 2584 bge_reg_put32(bgep, regno, ~(uint32_t)0); 2585 drv_usecwait(100); 2586 bge_reg_put32(bgep, regno, 0); 2587 return (B_TRUE); 2588 2589 default: 2590 regval = bge_reg_get32(bgep, regno); 2591 regval |= STATE_MACHINE_ENABLE_BIT; 2592 regval |= morebits; 2593 bge_reg_put32(bgep, regno, regval); 2594 return (bge_chip_poll_engine(bgep, regno, 2595 STATE_MACHINE_ENABLE_BIT, STATE_MACHINE_ENABLE_BIT)); 2596 } 2597 } 2598 2599 /* 2600 * Reprogram the Ethernet, Transmit, and Receive MAC 2601 * modes to match the param_* variables 2602 */ 2603 void bge_sync_mac_modes(bge_t *bgep); 2604 #pragma no_inline(bge_sync_mac_modes) 2605 2606 void 2607 bge_sync_mac_modes(bge_t *bgep) 2608 { 2609 uint32_t macmode; 2610 uint32_t regval; 2611 2612 ASSERT(mutex_owned(bgep->genlock)); 2613 2614 /* 2615 * Reprogram the Ethernet MAC mode ... 2616 */ 2617 macmode = regval = bge_reg_get32(bgep, ETHERNET_MAC_MODE_REG); 2618 if ((bgep->chipid.flags & CHIP_FLAG_SERDES) && 2619 (bgep->param_loop_mode != BGE_LOOP_INTERNAL_MAC)) 2620 macmode &= ~ETHERNET_MODE_LINK_POLARITY; 2621 else 2622 macmode |= ETHERNET_MODE_LINK_POLARITY; 2623 macmode &= ~ETHERNET_MODE_PORTMODE_MASK; 2624 if ((bgep->chipid.flags & CHIP_FLAG_SERDES) && 2625 (bgep->param_loop_mode != BGE_LOOP_INTERNAL_MAC)) 2626 macmode |= ETHERNET_MODE_PORTMODE_TBI; 2627 else if (bgep->param_link_speed == 10 || bgep->param_link_speed == 100) 2628 macmode |= ETHERNET_MODE_PORTMODE_MII; 2629 else 2630 macmode |= ETHERNET_MODE_PORTMODE_GMII; 2631 if (bgep->param_link_duplex == LINK_DUPLEX_HALF) 2632 macmode |= ETHERNET_MODE_HALF_DUPLEX; 2633 else 2634 macmode &= ~ETHERNET_MODE_HALF_DUPLEX; 2635 if (bgep->param_loop_mode == BGE_LOOP_INTERNAL_MAC) 2636 macmode |= ETHERNET_MODE_MAC_LOOPBACK; 2637 else 2638 macmode &= ~ETHERNET_MODE_MAC_LOOPBACK; 2639 bge_reg_put32(bgep, ETHERNET_MAC_MODE_REG, macmode); 2640 BGE_DEBUG(("bge_sync_mac_modes($%p) Ethernet MAC mode 0x%x => 0x%x", 2641 (void *)bgep, regval, macmode)); 2642 2643 /* 2644 * ... the Transmit MAC mode ... 2645 */ 2646 macmode = regval = bge_reg_get32(bgep, TRANSMIT_MAC_MODE_REG); 2647 if (bgep->param_link_tx_pause) 2648 macmode |= TRANSMIT_MODE_FLOW_CONTROL; 2649 else 2650 macmode &= ~TRANSMIT_MODE_FLOW_CONTROL; 2651 bge_reg_put32(bgep, TRANSMIT_MAC_MODE_REG, macmode); 2652 BGE_DEBUG(("bge_sync_mac_modes($%p) Transmit MAC mode 0x%x => 0x%x", 2653 (void *)bgep, regval, macmode)); 2654 2655 /* 2656 * ... and the Receive MAC mode 2657 */ 2658 macmode = regval = bge_reg_get32(bgep, RECEIVE_MAC_MODE_REG); 2659 if (bgep->param_link_rx_pause) 2660 macmode |= RECEIVE_MODE_FLOW_CONTROL; 2661 else 2662 macmode &= ~RECEIVE_MODE_FLOW_CONTROL; 2663 bge_reg_put32(bgep, RECEIVE_MAC_MODE_REG, macmode); 2664 BGE_DEBUG(("bge_sync_mac_modes($%p) Receive MAC mode 0x%x => 0x%x", 2665 (void *)bgep, regval, macmode)); 2666 } 2667 2668 /* 2669 * bge_chip_sync() -- program the chip with the unicast MAC address, 2670 * the multicast hash table, the required level of promiscuity, and 2671 * the current loopback mode ... 2672 */ 2673 #ifdef BGE_IPMI_ASF 2674 int bge_chip_sync(bge_t *bgep, boolean_t asf_keeplive); 2675 #else 2676 int bge_chip_sync(bge_t *bgep); 2677 #endif 2678 #pragma no_inline(bge_chip_sync) 2679 2680 int 2681 #ifdef BGE_IPMI_ASF 2682 bge_chip_sync(bge_t *bgep, boolean_t asf_keeplive) 2683 #else 2684 bge_chip_sync(bge_t *bgep) 2685 #endif 2686 { 2687 void (*opfn)(bge_t *bgep, bge_regno_t reg, uint32_t bits); 2688 boolean_t promisc; 2689 uint64_t macaddr; 2690 uint32_t fill; 2691 int i, j; 2692 int retval = DDI_SUCCESS; 2693 2694 BGE_TRACE(("bge_chip_sync($%p)", 2695 (void *)bgep)); 2696 2697 ASSERT(mutex_owned(bgep->genlock)); 2698 2699 promisc = B_FALSE; 2700 fill = ~(uint32_t)0; 2701 2702 if (bgep->promisc) 2703 promisc = B_TRUE; 2704 else 2705 fill = (uint32_t)0; 2706 2707 /* 2708 * If the TX/RX MAC engines are already running, we should stop 2709 * them (and reset the RX engine) before changing the parameters. 2710 * If they're not running, this will have no effect ... 2711 * 2712 * NOTE: this is currently disabled by default because stopping 2713 * and restarting the Tx engine may cause an outgoing packet in 2714 * transit to be truncated. Also, stopping and restarting the 2715 * Rx engine seems to not work correctly on the 5705. Testing 2716 * has not (yet!) revealed any problems with NOT stopping and 2717 * restarting these engines (and Broadcom say their drivers don't 2718 * do this), but if it is found to cause problems, this variable 2719 * can be patched to re-enable the old behaviour ... 2720 */ 2721 if (bge_stop_start_on_sync) { 2722 #ifdef BGE_IPMI_ASF 2723 if (!bgep->asf_enabled) { 2724 if (!bge_chip_disable_engine(bgep, 2725 RECEIVE_MAC_MODE_REG, RECEIVE_MODE_KEEP_VLAN_TAG)) 2726 retval = DDI_FAILURE; 2727 } else { 2728 if (!bge_chip_disable_engine(bgep, 2729 RECEIVE_MAC_MODE_REG, 0)) 2730 retval = DDI_FAILURE; 2731 } 2732 #else 2733 if (!bge_chip_disable_engine(bgep, RECEIVE_MAC_MODE_REG, 2734 RECEIVE_MODE_KEEP_VLAN_TAG)) 2735 retval = DDI_FAILURE; 2736 #endif 2737 if (!bge_chip_disable_engine(bgep, TRANSMIT_MAC_MODE_REG, 0)) 2738 retval = DDI_FAILURE; 2739 if (!bge_chip_reset_engine(bgep, RECEIVE_MAC_MODE_REG)) 2740 retval = DDI_FAILURE; 2741 } 2742 2743 /* 2744 * Reprogram the hashed multicast address table ... 2745 */ 2746 for (i = 0; i < BGE_HASH_TABLE_SIZE/32; ++i) 2747 bge_reg_put32(bgep, MAC_HASH_REG(i), 0); 2748 2749 for (i = 0; i < BGE_HASH_TABLE_SIZE/32; ++i) 2750 bge_reg_put32(bgep, MAC_HASH_REG(i), 2751 bgep->mcast_hash[i] | fill); 2752 2753 #ifdef BGE_IPMI_ASF 2754 if (!bgep->asf_enabled || !asf_keeplive) { 2755 #endif 2756 /* 2757 * Transform the MAC address(es) from host to chip format, then 2758 * reprogram the transmit random backoff seed and the unicast 2759 * MAC address(es) ... 2760 */ 2761 for (j = 0; j < MAC_ADDRESS_REGS_MAX; j++) { 2762 for (i = 0, fill = 0, macaddr = 0ull; 2763 i < ETHERADDRL; ++i) { 2764 macaddr <<= 8; 2765 macaddr |= bgep->curr_addr[j].addr[i]; 2766 fill += bgep->curr_addr[j].addr[i]; 2767 } 2768 bge_reg_put32(bgep, MAC_TX_RANDOM_BACKOFF_REG, fill); 2769 bge_reg_put64(bgep, MAC_ADDRESS_REG(j), macaddr); 2770 } 2771 2772 BGE_DEBUG(("bge_chip_sync($%p) setting MAC address %012llx", 2773 (void *)bgep, macaddr)); 2774 #ifdef BGE_IPMI_ASF 2775 } 2776 #endif 2777 2778 /* 2779 * Set or clear the PROMISCUOUS mode bit 2780 */ 2781 opfn = promisc ? bge_reg_set32 : bge_reg_clr32; 2782 (*opfn)(bgep, RECEIVE_MAC_MODE_REG, RECEIVE_MODE_PROMISCUOUS); 2783 2784 /* 2785 * Sync the rest of the MAC modes too ... 2786 */ 2787 bge_sync_mac_modes(bgep); 2788 2789 /* 2790 * Restart RX/TX MAC engines if required ... 2791 */ 2792 if (bgep->bge_chip_state == BGE_CHIP_RUNNING) { 2793 if (!bge_chip_enable_engine(bgep, TRANSMIT_MAC_MODE_REG, 0)) 2794 retval = DDI_FAILURE; 2795 #ifdef BGE_IPMI_ASF 2796 if (!bgep->asf_enabled) { 2797 if (!bge_chip_enable_engine(bgep, 2798 RECEIVE_MAC_MODE_REG, RECEIVE_MODE_KEEP_VLAN_TAG)) 2799 retval = DDI_FAILURE; 2800 } else { 2801 if (!bge_chip_enable_engine(bgep, 2802 RECEIVE_MAC_MODE_REG, 0)) 2803 retval = DDI_FAILURE; 2804 } 2805 #else 2806 if (!bge_chip_enable_engine(bgep, RECEIVE_MAC_MODE_REG, 2807 RECEIVE_MODE_KEEP_VLAN_TAG)) 2808 retval = DDI_FAILURE; 2809 #endif 2810 } 2811 return (retval); 2812 } 2813 2814 /* 2815 * This array defines the sequence of state machine control registers 2816 * in which the <enable> bit must be cleared to bring the chip to a 2817 * clean stop. Taken from Broadcom document 570X-PG102-R, p116. 2818 */ 2819 static bge_regno_t shutdown_engine_regs[] = { 2820 RECEIVE_MAC_MODE_REG, 2821 RCV_BD_INITIATOR_MODE_REG, 2822 RCV_LIST_PLACEMENT_MODE_REG, 2823 RCV_LIST_SELECTOR_MODE_REG, /* BCM5704 series only */ 2824 RCV_DATA_BD_INITIATOR_MODE_REG, 2825 RCV_DATA_COMPLETION_MODE_REG, 2826 RCV_BD_COMPLETION_MODE_REG, 2827 2828 SEND_BD_SELECTOR_MODE_REG, 2829 SEND_BD_INITIATOR_MODE_REG, 2830 SEND_DATA_INITIATOR_MODE_REG, 2831 READ_DMA_MODE_REG, 2832 SEND_DATA_COMPLETION_MODE_REG, 2833 DMA_COMPLETION_MODE_REG, /* BCM5704 series only */ 2834 SEND_BD_COMPLETION_MODE_REG, 2835 TRANSMIT_MAC_MODE_REG, 2836 2837 HOST_COALESCE_MODE_REG, 2838 WRITE_DMA_MODE_REG, 2839 MBUF_CLUSTER_FREE_MODE_REG, /* BCM5704 series only */ 2840 FTQ_RESET_REG, /* special - see code */ 2841 BUFFER_MANAGER_MODE_REG, /* BCM5704 series only */ 2842 MEMORY_ARBITER_MODE_REG, /* BCM5704 series only */ 2843 BGE_REGNO_NONE /* terminator */ 2844 }; 2845 2846 /* 2847 * bge_chip_stop() -- stop all chip processing 2848 * 2849 * If the <fault> parameter is B_TRUE, we're stopping the chip because 2850 * we've detected a problem internally; otherwise, this is a normal 2851 * (clean) stop (at user request i.e. the last STREAM has been closed). 2852 */ 2853 void bge_chip_stop(bge_t *bgep, boolean_t fault); 2854 #pragma no_inline(bge_chip_stop) 2855 2856 void 2857 bge_chip_stop(bge_t *bgep, boolean_t fault) 2858 { 2859 bge_regno_t regno; 2860 bge_regno_t *rbp; 2861 boolean_t ok; 2862 2863 BGE_TRACE(("bge_chip_stop($%p)", 2864 (void *)bgep)); 2865 2866 ASSERT(mutex_owned(bgep->genlock)); 2867 2868 rbp = shutdown_engine_regs; 2869 /* 2870 * When driver try to shutdown the BCM5705/5788/5721/5751/ 2871 * 5752/5714 and 5715 chipsets,the buffer manager and the mem 2872 * -ory arbiter should not be disabled. 2873 */ 2874 for (ok = B_TRUE; (regno = *rbp) != BGE_REGNO_NONE; ++rbp) { 2875 if (DEVICE_5704_SERIES_CHIPSETS(bgep)) 2876 ok &= bge_chip_disable_engine(bgep, regno, 0); 2877 else if ((regno != RCV_LIST_SELECTOR_MODE_REG) && 2878 (regno != DMA_COMPLETION_MODE_REG) && 2879 (regno != MBUF_CLUSTER_FREE_MODE_REG)&& 2880 (regno != BUFFER_MANAGER_MODE_REG) && 2881 (regno != MEMORY_ARBITER_MODE_REG)) 2882 ok &= bge_chip_disable_engine(bgep, 2883 regno, 0); 2884 } 2885 2886 if (!ok && !fault) 2887 ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_UNAFFECTED); 2888 2889 /* 2890 * Finally, disable (all) MAC events & clear the MAC status 2891 */ 2892 bge_reg_put32(bgep, ETHERNET_MAC_EVENT_ENABLE_REG, 0); 2893 bge_reg_put32(bgep, ETHERNET_MAC_STATUS_REG, ~0); 2894 2895 /* 2896 * if we're stopping the chip because of a detected fault then do 2897 * appropriate actions 2898 */ 2899 if (fault) { 2900 if (bgep->bge_chip_state != BGE_CHIP_FAULT) { 2901 bgep->bge_chip_state = BGE_CHIP_FAULT; 2902 if (!bgep->manual_reset) 2903 ddi_fm_service_impact(bgep->devinfo, 2904 DDI_SERVICE_LOST); 2905 if (bgep->bge_dma_error) { 2906 /* 2907 * need to free buffers in case the fault was 2908 * due to a memory error in a buffer - got to 2909 * do a fair bit of tidying first 2910 */ 2911 if (bgep->progress & PROGRESS_KSTATS) { 2912 bge_fini_kstats(bgep); 2913 bgep->progress &= ~PROGRESS_KSTATS; 2914 } 2915 if (bgep->progress & PROGRESS_INTR) { 2916 bge_intr_disable(bgep); 2917 rw_enter(bgep->errlock, RW_WRITER); 2918 bge_fini_rings(bgep); 2919 rw_exit(bgep->errlock); 2920 bgep->progress &= ~PROGRESS_INTR; 2921 } 2922 if (bgep->progress & PROGRESS_BUFS) { 2923 bge_free_bufs(bgep); 2924 bgep->progress &= ~PROGRESS_BUFS; 2925 } 2926 bgep->bge_dma_error = B_FALSE; 2927 } 2928 } 2929 } else 2930 bgep->bge_chip_state = BGE_CHIP_STOPPED; 2931 } 2932 2933 /* 2934 * Poll for completion of chip's ROM firmware; also, at least on the 2935 * first time through, find and return the hardware MAC address, if any. 2936 */ 2937 static uint64_t bge_poll_firmware(bge_t *bgep); 2938 #pragma no_inline(bge_poll_firmware) 2939 2940 static uint64_t 2941 bge_poll_firmware(bge_t *bgep) 2942 { 2943 uint64_t magic; 2944 uint64_t mac; 2945 uint32_t gen; 2946 uint32_t i; 2947 2948 /* 2949 * Step 19: poll for firmware completion (GENCOMM port set 2950 * to the ones complement of T3_MAGIC_NUMBER). 2951 * 2952 * While we're at it, we also read the MAC address register; 2953 * at some stage the firmware will load this with the 2954 * factory-set value. 2955 * 2956 * When both the magic number and the MAC address are set, 2957 * we're done; but we impose a time limit of one second 2958 * (1000*1000us) in case the firmware fails in some fashion 2959 * or the SEEPROM that provides that MAC address isn't fitted. 2960 * 2961 * After the first time through (chip state != INITIAL), we 2962 * don't need the MAC address to be set (we've already got it 2963 * or not, from the first time), so we don't wait for it, but 2964 * we still have to wait for the T3_MAGIC_NUMBER. 2965 * 2966 * Note: the magic number is only a 32-bit quantity, but the NIC 2967 * memory is 64-bit (and big-endian) internally. Addressing the 2968 * GENCOMM word as "the upper half of a 64-bit quantity" makes 2969 * it work correctly on both big- and little-endian hosts. 2970 */ 2971 for (i = 0; i < 1000; ++i) { 2972 drv_usecwait(1000); 2973 gen = bge_nic_get64(bgep, NIC_MEM_GENCOMM) >> 32; 2974 mac = bge_reg_get64(bgep, MAC_ADDRESS_REG(0)); 2975 #ifdef BGE_IPMI_ASF 2976 if (!bgep->asf_enabled) { 2977 #endif 2978 if (gen != ~T3_MAGIC_NUMBER) 2979 continue; 2980 #ifdef BGE_IPMI_ASF 2981 } 2982 #endif 2983 if (mac != 0ULL) 2984 break; 2985 if (bgep->bge_chip_state != BGE_CHIP_INITIAL) 2986 break; 2987 } 2988 2989 magic = bge_nic_get64(bgep, NIC_MEM_GENCOMM); 2990 BGE_DEBUG(("bge_poll_firmware($%p): PXE magic 0x%x after %d loops", 2991 (void *)bgep, gen, i)); 2992 BGE_DEBUG(("bge_poll_firmware: MAC %016llx, GENCOMM %016llx", 2993 mac, magic)); 2994 2995 return (mac); 2996 } 2997 2998 /* 2999 * Maximum times of trying to get the NVRAM access lock 3000 * by calling bge_nvmem_acquire() 3001 */ 3002 #define MAX_TRY_NVMEM_ACQUIRE 10000 3003 3004 #ifdef BGE_IPMI_ASF 3005 int bge_chip_reset(bge_t *bgep, boolean_t enable_dma, uint_t asf_mode); 3006 #else 3007 int bge_chip_reset(bge_t *bgep, boolean_t enable_dma); 3008 #endif 3009 #pragma no_inline(bge_chip_reset) 3010 3011 int 3012 #ifdef BGE_IPMI_ASF 3013 bge_chip_reset(bge_t *bgep, boolean_t enable_dma, uint_t asf_mode) 3014 #else 3015 bge_chip_reset(bge_t *bgep, boolean_t enable_dma) 3016 #endif 3017 { 3018 chip_id_t chipid; 3019 uint64_t mac; 3020 uint64_t magic; 3021 uint32_t modeflags; 3022 uint32_t mhcr; 3023 uint32_t sx0; 3024 uint32_t i, tries; 3025 #ifdef BGE_IPMI_ASF 3026 uint32_t mailbox; 3027 #endif 3028 int retval = DDI_SUCCESS; 3029 3030 BGE_TRACE(("bge_chip_reset($%p, %d)", 3031 (void *)bgep, enable_dma)); 3032 3033 ASSERT(mutex_owned(bgep->genlock)); 3034 3035 BGE_DEBUG(("bge_chip_reset($%p, %d): current state is %d", 3036 (void *)bgep, enable_dma, bgep->bge_chip_state)); 3037 3038 /* 3039 * Do we need to stop the chip cleanly before resetting? 3040 */ 3041 switch (bgep->bge_chip_state) { 3042 default: 3043 _NOTE(NOTREACHED) 3044 return (DDI_FAILURE); 3045 3046 case BGE_CHIP_INITIAL: 3047 case BGE_CHIP_STOPPED: 3048 case BGE_CHIP_RESET: 3049 break; 3050 3051 case BGE_CHIP_RUNNING: 3052 case BGE_CHIP_ERROR: 3053 case BGE_CHIP_FAULT: 3054 bge_chip_stop(bgep, B_FALSE); 3055 break; 3056 } 3057 3058 #ifdef BGE_IPMI_ASF 3059 if (bgep->asf_enabled) { 3060 #ifdef __sparc 3061 mhcr = MHCR_ENABLE_INDIRECT_ACCESS | 3062 MHCR_ENABLE_TAGGED_STATUS_MODE | 3063 MHCR_MASK_INTERRUPT_MODE | 3064 MHCR_MASK_PCI_INT_OUTPUT | 3065 MHCR_CLEAR_INTERRUPT_INTA | 3066 MHCR_ENABLE_ENDIAN_WORD_SWAP | 3067 MHCR_ENABLE_ENDIAN_BYTE_SWAP; 3068 pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_MHCR, mhcr); 3069 bge_reg_put32(bgep, MEMORY_ARBITER_MODE_REG, 3070 bge_reg_get32(bgep, MEMORY_ARBITER_MODE_REG) | 3071 MEMORY_ARBITER_ENABLE); 3072 #endif 3073 if (asf_mode == ASF_MODE_INIT) { 3074 bge_asf_pre_reset_operations(bgep, BGE_INIT_RESET); 3075 } else if (asf_mode == ASF_MODE_SHUTDOWN) { 3076 bge_asf_pre_reset_operations(bgep, BGE_SHUTDOWN_RESET); 3077 } 3078 } 3079 #endif 3080 /* 3081 * Adapted from Broadcom document 570X-PG102-R, pp 102-116. 3082 * Updated to reflect Broadcom document 570X-PG104-R, pp 146-159. 3083 * 3084 * Before reset Core clock,it is 3085 * also required to initialize the Memory Arbiter as specified in step9 3086 * and Misc Host Control Register as specified in step-13 3087 * Step 4-5: reset Core clock & wait for completion 3088 * Steps 6-8: are done by bge_chip_cfg_init() 3089 * put the T3_MAGIC_NUMBER into the GENCOMM port before reset 3090 */ 3091 if (!bge_chip_enable_engine(bgep, MEMORY_ARBITER_MODE_REG, 0)) 3092 retval = DDI_FAILURE; 3093 3094 mhcr = MHCR_ENABLE_INDIRECT_ACCESS | 3095 MHCR_ENABLE_TAGGED_STATUS_MODE | 3096 MHCR_MASK_INTERRUPT_MODE | 3097 MHCR_MASK_PCI_INT_OUTPUT | 3098 MHCR_CLEAR_INTERRUPT_INTA; 3099 #ifdef _BIG_ENDIAN 3100 mhcr |= MHCR_ENABLE_ENDIAN_WORD_SWAP | MHCR_ENABLE_ENDIAN_BYTE_SWAP; 3101 #endif /* _BIG_ENDIAN */ 3102 pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_MHCR, mhcr); 3103 #ifdef BGE_IPMI_ASF 3104 if (bgep->asf_enabled) 3105 bgep->asf_wordswapped = B_FALSE; 3106 #endif 3107 /* 3108 * NVRAM Corruption Workaround 3109 */ 3110 for (tries = 0; tries < MAX_TRY_NVMEM_ACQUIRE; tries++) 3111 if (bge_nvmem_acquire(bgep) != EAGAIN) 3112 break; 3113 if (tries >= MAX_TRY_NVMEM_ACQUIRE) 3114 BGE_DEBUG(("%s: fail to acquire nvram lock", 3115 bgep->ifname)); 3116 3117 #ifdef BGE_IPMI_ASF 3118 if (!bgep->asf_enabled) { 3119 #endif 3120 magic = (uint64_t)T3_MAGIC_NUMBER << 32; 3121 bge_nic_put64(bgep, NIC_MEM_GENCOMM, magic); 3122 #ifdef BGE_IPMI_ASF 3123 } 3124 #endif 3125 3126 if (!bge_chip_reset_engine(bgep, MISC_CONFIG_REG)) 3127 retval = DDI_FAILURE; 3128 bge_chip_cfg_init(bgep, &chipid, enable_dma); 3129 3130 /* 3131 * Step 8a: This may belong elsewhere, but BCM5721 needs 3132 * a bit set to avoid a fifo overflow/underflow bug. 3133 */ 3134 if ((bgep->chipid.chip_label == 5721) || 3135 (bgep->chipid.chip_label == 5751) || 3136 (bgep->chipid.chip_label == 5752) || 3137 (bgep->chipid.chip_label == 5755) || 3138 (bgep->chipid.chip_label == 5789)) 3139 bge_reg_set32(bgep, TLP_CONTROL_REG, TLP_DATA_FIFO_PROTECT); 3140 3141 3142 /* 3143 * Step 9: enable MAC memory arbiter,bit30 and bit31 of 5714/5715 should 3144 * not be changed. 3145 */ 3146 if (!bge_chip_enable_engine(bgep, MEMORY_ARBITER_MODE_REG, 0)) 3147 retval = DDI_FAILURE; 3148 3149 /* 3150 * Steps 10-11: configure PIO endianness options and 3151 * enable indirect register access -- already done 3152 * Steps 12-13: enable writing to the PCI state & clock 3153 * control registers -- not required; we aren't going to 3154 * use those features. 3155 * Steps 14-15: Configure DMA endianness options. See 3156 * the comments on the setting of the MHCR above. 3157 */ 3158 #ifdef _BIG_ENDIAN 3159 modeflags = MODE_WORD_SWAP_FRAME | MODE_BYTE_SWAP_FRAME | 3160 MODE_WORD_SWAP_NONFRAME | MODE_BYTE_SWAP_NONFRAME; 3161 #else 3162 modeflags = MODE_WORD_SWAP_FRAME | MODE_BYTE_SWAP_FRAME; 3163 #endif /* _BIG_ENDIAN */ 3164 #ifdef BGE_IPMI_ASF 3165 if (bgep->asf_enabled) 3166 modeflags |= MODE_HOST_STACK_UP; 3167 #endif 3168 bge_reg_put32(bgep, MODE_CONTROL_REG, modeflags); 3169 3170 #ifdef BGE_IPMI_ASF 3171 if (bgep->asf_enabled) { 3172 #ifdef __sparc 3173 bge_reg_put32(bgep, MEMORY_ARBITER_MODE_REG, 3174 MEMORY_ARBITER_ENABLE | 3175 bge_reg_get32(bgep, MEMORY_ARBITER_MODE_REG)); 3176 #endif 3177 3178 #ifdef BGE_NETCONSOLE 3179 if (!bgep->asf_newhandshake) { 3180 if ((asf_mode == ASF_MODE_INIT) || 3181 (asf_mode == ASF_MODE_POST_INIT)) { 3182 bge_asf_post_reset_old_mode(bgep, 3183 BGE_INIT_RESET); 3184 } else { 3185 bge_asf_post_reset_old_mode(bgep, 3186 BGE_SHUTDOWN_RESET); 3187 } 3188 } 3189 #endif 3190 3191 /* Wait for NVRAM init */ 3192 i = 0; 3193 drv_usecwait(5000); 3194 mailbox = bge_nic_get32(bgep, BGE_FIRMWARE_MAILBOX); 3195 3196 while ((mailbox != (uint32_t) 3197 ~BGE_MAGIC_NUM_FIRMWARE_INIT_DONE) && 3198 (i < 10000)) { 3199 drv_usecwait(100); 3200 mailbox = bge_nic_get32(bgep, 3201 BGE_FIRMWARE_MAILBOX); 3202 i++; 3203 } 3204 3205 #ifndef BGE_NETCONSOLE 3206 if (!bgep->asf_newhandshake) { 3207 if ((asf_mode == ASF_MODE_INIT) || 3208 (asf_mode == ASF_MODE_POST_INIT)) { 3209 3210 bge_asf_post_reset_old_mode(bgep, 3211 BGE_INIT_RESET); 3212 } else { 3213 bge_asf_post_reset_old_mode(bgep, 3214 BGE_SHUTDOWN_RESET); 3215 } 3216 } 3217 #endif 3218 } 3219 #endif 3220 /* 3221 * Steps 16-17: poll for firmware completion 3222 */ 3223 mac = bge_poll_firmware(bgep); 3224 3225 /* 3226 * Step 18: enable external memory -- doesn't apply. 3227 * 3228 * However we take the opportunity to set the MLCR anyway, as 3229 * this register also controls the SEEPROM auto-access method 3230 * which we may want to use later ... 3231 * 3232 * The proper value here depends on the way the chip is wired 3233 * into the circuit board, as this register *also* controls which 3234 * of the "Miscellaneous I/O" pins are driven as outputs and the 3235 * values driven onto those pins! 3236 * 3237 * See also step 74 in the PRM ... 3238 */ 3239 bge_reg_put32(bgep, MISC_LOCAL_CONTROL_REG, 3240 bgep->chipid.bge_mlcr_default); 3241 bge_reg_set32(bgep, SERIAL_EEPROM_ADDRESS_REG, SEEPROM_ACCESS_INIT); 3242 3243 /* 3244 * Step 20: clear the Ethernet MAC mode register 3245 */ 3246 bge_reg_put32(bgep, ETHERNET_MAC_MODE_REG, 0); 3247 3248 /* 3249 * Step 21: restore cache-line-size, latency timer, and 3250 * subsystem ID registers to their original values (not 3251 * those read into the local structure <chipid>, 'cos 3252 * that was after they were cleared by the RESET). 3253 * 3254 * Note: the Subsystem Vendor/Device ID registers are not 3255 * directly writable in config space, so we use the shadow 3256 * copy in "Page Zero" of register space to restore them 3257 * both in one go ... 3258 */ 3259 pci_config_put8(bgep->cfg_handle, PCI_CONF_CACHE_LINESZ, 3260 bgep->chipid.clsize); 3261 pci_config_put8(bgep->cfg_handle, PCI_CONF_LATENCY_TIMER, 3262 bgep->chipid.latency); 3263 bge_reg_put32(bgep, PCI_CONF_SUBVENID, 3264 (bgep->chipid.subdev << 16) | bgep->chipid.subven); 3265 3266 /* 3267 * The SEND INDEX registers should be reset to zero by the 3268 * global chip reset; if they're not, there'll be trouble 3269 * later on. 3270 */ 3271 sx0 = bge_reg_get32(bgep, NIC_DIAG_SEND_INDEX_REG(0)); 3272 if (sx0 != 0) { 3273 BGE_REPORT((bgep, "SEND INDEX - device didn't RESET")); 3274 bge_fm_ereport(bgep, DDI_FM_DEVICE_INVAL_STATE); 3275 retval = DDI_FAILURE; 3276 } 3277 3278 /* Enable MSI code */ 3279 if (bgep->intr_type == DDI_INTR_TYPE_MSI) 3280 bge_reg_set32(bgep, MSI_MODE_REG, 3281 MSI_PRI_HIGHEST|MSI_MSI_ENABLE|MSI_ERROR_ATTENTION); 3282 3283 /* 3284 * On the first time through, save the factory-set MAC address 3285 * (if any). If bge_poll_firmware() above didn't return one 3286 * (from a chip register) consider looking in the attached NV 3287 * memory device, if any. Once we have it, we save it in both 3288 * register-image (64-bit) and byte-array forms. All-zero and 3289 * all-one addresses are not valid, and we refuse to stash those. 3290 */ 3291 if (bgep->bge_chip_state == BGE_CHIP_INITIAL) { 3292 if (mac == 0ULL) 3293 mac = bge_get_nvmac(bgep); 3294 if (mac != 0ULL && mac != ~0ULL) { 3295 bgep->chipid.hw_mac_addr = mac; 3296 for (i = ETHERADDRL; i-- != 0; ) { 3297 bgep->chipid.vendor_addr.addr[i] = (uchar_t)mac; 3298 mac >>= 8; 3299 } 3300 bgep->chipid.vendor_addr.set = B_TRUE; 3301 } 3302 } 3303 3304 #ifdef BGE_IPMI_ASF 3305 if (bgep->asf_enabled && bgep->asf_newhandshake) { 3306 if (asf_mode != ASF_MODE_NONE) { 3307 if ((asf_mode == ASF_MODE_INIT) || 3308 (asf_mode == ASF_MODE_POST_INIT)) { 3309 3310 bge_asf_post_reset_new_mode(bgep, 3311 BGE_INIT_RESET); 3312 } else { 3313 bge_asf_post_reset_new_mode(bgep, 3314 BGE_SHUTDOWN_RESET); 3315 } 3316 } 3317 } 3318 #endif 3319 3320 /* 3321 * Record the new state 3322 */ 3323 bgep->chip_resets += 1; 3324 bgep->bge_chip_state = BGE_CHIP_RESET; 3325 return (retval); 3326 } 3327 3328 /* 3329 * bge_chip_start() -- start the chip transmitting and/or receiving, 3330 * including enabling interrupts 3331 */ 3332 int bge_chip_start(bge_t *bgep, boolean_t reset_phys); 3333 #pragma no_inline(bge_chip_start) 3334 3335 int 3336 bge_chip_start(bge_t *bgep, boolean_t reset_phys) 3337 { 3338 uint32_t coalmode; 3339 uint32_t ledctl; 3340 uint32_t mtu; 3341 uint32_t maxring; 3342 uint32_t stats_mask; 3343 uint32_t dma_wrprio; 3344 uint64_t ring; 3345 int retval = DDI_SUCCESS; 3346 3347 BGE_TRACE(("bge_chip_start($%p)", 3348 (void *)bgep)); 3349 3350 ASSERT(mutex_owned(bgep->genlock)); 3351 ASSERT(bgep->bge_chip_state == BGE_CHIP_RESET); 3352 3353 /* 3354 * Taken from Broadcom document 570X-PG102-R, pp 102-116. 3355 * The document specifies 95 separate steps to fully 3356 * initialise the chip!!!! 3357 * 3358 * The reset code above has already got us as far as step 3359 * 21, so we continue with ... 3360 * 3361 * Step 22: clear the MAC statistics block 3362 * (0x0300-0x0aff in NIC-local memory) 3363 */ 3364 if (bgep->chipid.statistic_type == BGE_STAT_BLK) 3365 bge_nic_zero(bgep, NIC_MEM_STATISTICS, 3366 NIC_MEM_STATISTICS_SIZE); 3367 3368 /* 3369 * Step 23: clear the status block (in host memory) 3370 */ 3371 DMA_ZERO(bgep->status_block); 3372 3373 /* 3374 * Step 24: set DMA read/write control register 3375 */ 3376 pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_PDRWCR, 3377 bgep->chipid.bge_dma_rwctrl); 3378 3379 /* 3380 * Step 25: Configure DMA endianness -- already done (16/17) 3381 * Step 26: Configure Host-Based Send Rings 3382 * Step 27: Indicate Host Stack Up 3383 */ 3384 bge_reg_set32(bgep, MODE_CONTROL_REG, 3385 MODE_HOST_SEND_BDS | 3386 MODE_HOST_STACK_UP); 3387 3388 /* 3389 * Step 28: Configure checksum options: 3390 * Solaris supports the hardware default checksum options. 3391 * 3392 * Workaround for Incorrect pseudo-header checksum calculation. 3393 */ 3394 if (bgep->chipid.flags & CHIP_FLAG_PARTIAL_CSUM) 3395 bge_reg_set32(bgep, MODE_CONTROL_REG, 3396 MODE_SEND_NO_PSEUDO_HDR_CSUM); 3397 3398 /* 3399 * Step 29: configure Timer Prescaler. The value is always the 3400 * same: the Core Clock frequency in MHz (66), minus 1, shifted 3401 * into bits 7-1. Don't set bit 0, 'cos that's the RESET bit 3402 * for the whole chip! 3403 */ 3404 bge_reg_put32(bgep, MISC_CONFIG_REG, MISC_CONFIG_DEFAULT); 3405 3406 /* 3407 * Steps 30-31: Configure MAC local memory pool & DMA pool registers 3408 * 3409 * If the mbuf_length is specified as 0, we just leave these at 3410 * their hardware defaults, rather than explicitly setting them. 3411 * As the Broadcom HRM,driver better not change the parameters 3412 * when the chipsets is 5705/5788/5721/5751/5714 and 5715. 3413 */ 3414 if ((bgep->chipid.mbuf_length != 0) && 3415 (DEVICE_5704_SERIES_CHIPSETS(bgep))) { 3416 bge_reg_put32(bgep, MBUF_POOL_BASE_REG, 3417 bgep->chipid.mbuf_base); 3418 bge_reg_put32(bgep, MBUF_POOL_LENGTH_REG, 3419 bgep->chipid.mbuf_length); 3420 bge_reg_put32(bgep, DMAD_POOL_BASE_REG, 3421 DMAD_POOL_BASE_DEFAULT); 3422 bge_reg_put32(bgep, DMAD_POOL_LENGTH_REG, 3423 DMAD_POOL_LENGTH_DEFAULT); 3424 } 3425 3426 /* 3427 * Step 32: configure MAC memory pool watermarks 3428 */ 3429 bge_reg_put32(bgep, RDMA_MBUF_LOWAT_REG, 3430 bgep->chipid.mbuf_lo_water_rdma); 3431 bge_reg_put32(bgep, MAC_RX_MBUF_LOWAT_REG, 3432 bgep->chipid.mbuf_lo_water_rmac); 3433 bge_reg_put32(bgep, MBUF_HIWAT_REG, 3434 bgep->chipid.mbuf_hi_water); 3435 3436 /* 3437 * Step 33: configure DMA resource watermarks 3438 */ 3439 if (DEVICE_5704_SERIES_CHIPSETS(bgep)) { 3440 bge_reg_put32(bgep, DMAD_POOL_LOWAT_REG, 3441 bge_dmad_lo_water); 3442 bge_reg_put32(bgep, DMAD_POOL_HIWAT_REG, 3443 bge_dmad_hi_water); 3444 } 3445 bge_reg_put32(bgep, LOWAT_MAX_RECV_FRAMES_REG, bge_lowat_recv_frames); 3446 3447 /* 3448 * Steps 34-36: enable buffer manager & internal h/w queues 3449 */ 3450 if (!bge_chip_enable_engine(bgep, BUFFER_MANAGER_MODE_REG, 3451 STATE_MACHINE_ATTN_ENABLE_BIT)) 3452 retval = DDI_FAILURE; 3453 if (!bge_chip_enable_engine(bgep, FTQ_RESET_REG, 0)) 3454 retval = DDI_FAILURE; 3455 3456 /* 3457 * Steps 37-39: initialise Receive Buffer (Producer) RCBs 3458 */ 3459 bge_reg_putrcb(bgep, STD_RCV_BD_RING_RCB_REG, 3460 &bgep->buff[BGE_STD_BUFF_RING].hw_rcb); 3461 if (DEVICE_5704_SERIES_CHIPSETS(bgep)) { 3462 bge_reg_putrcb(bgep, JUMBO_RCV_BD_RING_RCB_REG, 3463 &bgep->buff[BGE_JUMBO_BUFF_RING].hw_rcb); 3464 bge_reg_putrcb(bgep, MINI_RCV_BD_RING_RCB_REG, 3465 &bgep->buff[BGE_MINI_BUFF_RING].hw_rcb); 3466 } 3467 3468 /* 3469 * Step 40: set Receive Buffer Descriptor Ring replenish thresholds 3470 */ 3471 bge_reg_put32(bgep, STD_RCV_BD_REPLENISH_REG, bge_replenish_std); 3472 if (DEVICE_5704_SERIES_CHIPSETS(bgep)) { 3473 bge_reg_put32(bgep, JUMBO_RCV_BD_REPLENISH_REG, 3474 bge_replenish_jumbo); 3475 bge_reg_put32(bgep, MINI_RCV_BD_REPLENISH_REG, 3476 bge_replenish_mini); 3477 } 3478 3479 /* 3480 * Steps 41-43: clear Send Ring Producer Indices and initialise 3481 * Send Producer Rings (0x0100-0x01ff in NIC-local memory) 3482 */ 3483 if (DEVICE_5704_SERIES_CHIPSETS(bgep)) 3484 maxring = BGE_SEND_RINGS_MAX; 3485 else 3486 maxring = BGE_SEND_RINGS_MAX_5705; 3487 for (ring = 0; ring < maxring; ++ring) { 3488 bge_mbx_put(bgep, SEND_RING_HOST_INDEX_REG(ring), 0); 3489 bge_mbx_put(bgep, SEND_RING_NIC_INDEX_REG(ring), 0); 3490 bge_nic_putrcb(bgep, NIC_MEM_SEND_RING(ring), 3491 &bgep->send[ring].hw_rcb); 3492 } 3493 3494 /* 3495 * Steps 44-45: initialise Receive Return Rings 3496 * (0x0200-0x02ff in NIC-local memory) 3497 */ 3498 if (DEVICE_5704_SERIES_CHIPSETS(bgep)) 3499 maxring = BGE_RECV_RINGS_MAX; 3500 else 3501 maxring = BGE_RECV_RINGS_MAX_5705; 3502 for (ring = 0; ring < maxring; ++ring) 3503 bge_nic_putrcb(bgep, NIC_MEM_RECV_RING(ring), 3504 &bgep->recv[ring].hw_rcb); 3505 3506 /* 3507 * Step 46: initialise Receive Buffer (Producer) Ring indexes 3508 */ 3509 bge_mbx_put(bgep, RECV_STD_PROD_INDEX_REG, 0); 3510 if (DEVICE_5704_SERIES_CHIPSETS(bgep)) { 3511 bge_mbx_put(bgep, RECV_JUMBO_PROD_INDEX_REG, 0); 3512 bge_mbx_put(bgep, RECV_MINI_PROD_INDEX_REG, 0); 3513 } 3514 /* 3515 * Step 47: configure the MAC unicast address 3516 * Step 48: configure the random backoff seed 3517 * Step 96: set up multicast filters 3518 */ 3519 #ifdef BGE_IPMI_ASF 3520 if (bge_chip_sync(bgep, B_FALSE) == DDI_FAILURE) 3521 #else 3522 if (bge_chip_sync(bgep) == DDI_FAILURE) 3523 #endif 3524 retval = DDI_FAILURE; 3525 3526 /* 3527 * Step 49: configure the MTU 3528 */ 3529 mtu = bgep->chipid.ethmax_size+ETHERFCSL+VLAN_TAGSZ; 3530 bge_reg_put32(bgep, MAC_RX_MTU_SIZE_REG, mtu); 3531 3532 /* 3533 * Step 50: configure the IPG et al 3534 */ 3535 bge_reg_put32(bgep, MAC_TX_LENGTHS_REG, MAC_TX_LENGTHS_DEFAULT); 3536 3537 /* 3538 * Step 51: configure the default Rx Return Ring 3539 */ 3540 bge_reg_put32(bgep, RCV_RULES_CONFIG_REG, RCV_RULES_CONFIG_DEFAULT); 3541 3542 /* 3543 * Steps 52-54: configure Receive List Placement, 3544 * and enable Receive List Placement Statistics 3545 */ 3546 bge_reg_put32(bgep, RCV_LP_CONFIG_REG, 3547 RCV_LP_CONFIG(bgep->chipid.rx_rings)); 3548 switch (MHCR_CHIP_ASIC_REV(bgep->chipid.asic_rev)) { 3549 case MHCR_CHIP_ASIC_REV_5700: 3550 case MHCR_CHIP_ASIC_REV_5701: 3551 case MHCR_CHIP_ASIC_REV_5703: 3552 case MHCR_CHIP_ASIC_REV_5704: 3553 bge_reg_put32(bgep, RCV_LP_STATS_ENABLE_MASK_REG, ~0); 3554 break; 3555 case MHCR_CHIP_ASIC_REV_5705: 3556 break; 3557 default: 3558 stats_mask = bge_reg_get32(bgep, RCV_LP_STATS_ENABLE_MASK_REG); 3559 stats_mask &= ~RCV_LP_STATS_DISABLE_MACTQ; 3560 bge_reg_put32(bgep, RCV_LP_STATS_ENABLE_MASK_REG, stats_mask); 3561 break; 3562 } 3563 bge_reg_set32(bgep, RCV_LP_STATS_CONTROL_REG, RCV_LP_STATS_ENABLE); 3564 3565 if (bgep->chipid.rx_rings > 1) 3566 bge_init_recv_rule(bgep); 3567 3568 /* 3569 * Steps 55-56: enable Send Data Initiator Statistics 3570 */ 3571 bge_reg_put32(bgep, SEND_INIT_STATS_ENABLE_MASK_REG, ~0); 3572 if (DEVICE_5704_SERIES_CHIPSETS(bgep)) { 3573 bge_reg_put32(bgep, SEND_INIT_STATS_CONTROL_REG, 3574 SEND_INIT_STATS_ENABLE | SEND_INIT_STATS_FASTER); 3575 } else { 3576 bge_reg_put32(bgep, SEND_INIT_STATS_CONTROL_REG, 3577 SEND_INIT_STATS_ENABLE); 3578 } 3579 /* 3580 * Steps 57-58: stop (?) the Host Coalescing Engine 3581 */ 3582 if (!bge_chip_disable_engine(bgep, HOST_COALESCE_MODE_REG, ~0)) 3583 retval = DDI_FAILURE; 3584 3585 /* 3586 * Steps 59-62: initialise Host Coalescing parameters 3587 */ 3588 bge_reg_put32(bgep, SEND_COALESCE_MAX_BD_REG, bge_tx_count_norm); 3589 bge_reg_put32(bgep, SEND_COALESCE_TICKS_REG, bge_tx_ticks_norm); 3590 bge_reg_put32(bgep, RCV_COALESCE_MAX_BD_REG, bge_rx_count_norm); 3591 bge_reg_put32(bgep, RCV_COALESCE_TICKS_REG, bge_rx_ticks_norm); 3592 if (DEVICE_5704_SERIES_CHIPSETS(bgep)) { 3593 bge_reg_put32(bgep, SEND_COALESCE_INT_BD_REG, 3594 bge_tx_count_intr); 3595 bge_reg_put32(bgep, SEND_COALESCE_INT_TICKS_REG, 3596 bge_tx_ticks_intr); 3597 bge_reg_put32(bgep, RCV_COALESCE_INT_BD_REG, 3598 bge_rx_count_intr); 3599 bge_reg_put32(bgep, RCV_COALESCE_INT_TICKS_REG, 3600 bge_rx_ticks_intr); 3601 } 3602 3603 /* 3604 * Steps 63-64: initialise status block & statistics 3605 * host memory addresses 3606 * The statistic block does not exist in some chipsets 3607 * Step 65: initialise Statistics Coalescing Tick Counter 3608 */ 3609 bge_reg_put64(bgep, STATUS_BLOCK_HOST_ADDR_REG, 3610 bgep->status_block.cookie.dmac_laddress); 3611 3612 /* 3613 * Steps 66-67: initialise status block & statistics 3614 * NIC-local memory addresses 3615 */ 3616 if (DEVICE_5704_SERIES_CHIPSETS(bgep)) { 3617 bge_reg_put64(bgep, STATISTICS_HOST_ADDR_REG, 3618 bgep->statistics.cookie.dmac_laddress); 3619 bge_reg_put32(bgep, STATISTICS_TICKS_REG, 3620 STATISTICS_TICKS_DEFAULT); 3621 bge_reg_put32(bgep, STATUS_BLOCK_BASE_ADDR_REG, 3622 NIC_MEM_STATUS_BLOCK); 3623 bge_reg_put32(bgep, STATISTICS_BASE_ADDR_REG, 3624 NIC_MEM_STATISTICS); 3625 } 3626 3627 /* 3628 * Steps 68-71: start the Host Coalescing Engine, the Receive BD 3629 * Completion Engine, the Receive List Placement Engine, and the 3630 * Receive List selector.Pay attention:0x3400 is not exist in BCM5714 3631 * and BCM5715. 3632 */ 3633 if (bgep->chipid.tx_rings <= COALESCE_64_BYTE_RINGS && 3634 bgep->chipid.rx_rings <= COALESCE_64_BYTE_RINGS) 3635 coalmode = COALESCE_64_BYTE_STATUS; 3636 else 3637 coalmode = 0; 3638 if (!bge_chip_enable_engine(bgep, HOST_COALESCE_MODE_REG, coalmode)) 3639 retval = DDI_FAILURE; 3640 if (!bge_chip_enable_engine(bgep, RCV_BD_COMPLETION_MODE_REG, 3641 STATE_MACHINE_ATTN_ENABLE_BIT)) 3642 retval = DDI_FAILURE; 3643 if (!bge_chip_enable_engine(bgep, RCV_LIST_PLACEMENT_MODE_REG, 0)) 3644 retval = DDI_FAILURE; 3645 3646 if (DEVICE_5704_SERIES_CHIPSETS(bgep)) 3647 if (!bge_chip_enable_engine(bgep, RCV_LIST_SELECTOR_MODE_REG, 3648 STATE_MACHINE_ATTN_ENABLE_BIT)) 3649 retval = DDI_FAILURE; 3650 3651 /* 3652 * Step 72: Enable MAC DMA engines 3653 * Step 73: Clear & enable MAC statistics 3654 */ 3655 bge_reg_set32(bgep, ETHERNET_MAC_MODE_REG, 3656 ETHERNET_MODE_ENABLE_FHDE | 3657 ETHERNET_MODE_ENABLE_RDE | 3658 ETHERNET_MODE_ENABLE_TDE); 3659 bge_reg_set32(bgep, ETHERNET_MAC_MODE_REG, 3660 ETHERNET_MODE_ENABLE_TX_STATS | 3661 ETHERNET_MODE_ENABLE_RX_STATS | 3662 ETHERNET_MODE_CLEAR_TX_STATS | 3663 ETHERNET_MODE_CLEAR_RX_STATS); 3664 3665 /* 3666 * Step 74: configure the MLCR (Miscellaneous Local Control 3667 * Register); not required, as we set up the MLCR in step 10 3668 * (part of the reset code) above. 3669 * 3670 * Step 75: clear Interrupt Mailbox 0 3671 */ 3672 bge_mbx_put(bgep, INTERRUPT_MBOX_0_REG, 0); 3673 3674 /* 3675 * Steps 76-87: Gentlemen, start your engines ... 3676 * 3677 * Enable the DMA Completion Engine, the Write DMA Engine, 3678 * the Read DMA Engine, Receive Data Completion Engine, 3679 * the MBuf Cluster Free Engine, the Send Data Completion Engine, 3680 * the Send BD Completion Engine, the Receive BD Initiator Engine, 3681 * the Receive Data Initiator Engine, the Send Data Initiator Engine, 3682 * the Send BD Initiator Engine, and the Send BD Selector Engine. 3683 * 3684 * Beware exhaust fumes? 3685 */ 3686 if (DEVICE_5704_SERIES_CHIPSETS(bgep)) 3687 if (!bge_chip_enable_engine(bgep, DMA_COMPLETION_MODE_REG, 0)) 3688 retval = DDI_FAILURE; 3689 dma_wrprio = (bge_dma_wrprio << DMA_PRIORITY_SHIFT) | 3690 ALL_DMA_ATTN_BITS; 3691 if (MHCR_CHIP_ASIC_REV(bgep->chipid.asic_rev) == 3692 MHCR_CHIP_ASIC_REV_5755) { 3693 dma_wrprio |= DMA_STATUS_TAG_FIX_CQ12384; 3694 } 3695 if (!bge_chip_enable_engine(bgep, WRITE_DMA_MODE_REG, 3696 dma_wrprio)) 3697 retval = DDI_FAILURE; 3698 if (!bge_chip_enable_engine(bgep, READ_DMA_MODE_REG, 3699 (bge_dma_rdprio << DMA_PRIORITY_SHIFT) | ALL_DMA_ATTN_BITS)) 3700 retval = DDI_FAILURE; 3701 if (!bge_chip_enable_engine(bgep, RCV_DATA_COMPLETION_MODE_REG, 3702 STATE_MACHINE_ATTN_ENABLE_BIT)) 3703 retval = DDI_FAILURE; 3704 if (DEVICE_5704_SERIES_CHIPSETS(bgep)) 3705 if (!bge_chip_enable_engine(bgep, 3706 MBUF_CLUSTER_FREE_MODE_REG, 0)) 3707 retval = DDI_FAILURE; 3708 if (!bge_chip_enable_engine(bgep, SEND_DATA_COMPLETION_MODE_REG, 0)) 3709 retval = DDI_FAILURE; 3710 if (!bge_chip_enable_engine(bgep, SEND_BD_COMPLETION_MODE_REG, 3711 STATE_MACHINE_ATTN_ENABLE_BIT)) 3712 retval = DDI_FAILURE; 3713 if (!bge_chip_enable_engine(bgep, RCV_BD_INITIATOR_MODE_REG, 3714 RCV_BD_DISABLED_RING_ATTN)) 3715 retval = DDI_FAILURE; 3716 if (!bge_chip_enable_engine(bgep, RCV_DATA_BD_INITIATOR_MODE_REG, 3717 RCV_DATA_BD_ILL_RING_ATTN)) 3718 retval = DDI_FAILURE; 3719 if (!bge_chip_enable_engine(bgep, SEND_DATA_INITIATOR_MODE_REG, 0)) 3720 retval = DDI_FAILURE; 3721 if (!bge_chip_enable_engine(bgep, SEND_BD_INITIATOR_MODE_REG, 3722 STATE_MACHINE_ATTN_ENABLE_BIT)) 3723 retval = DDI_FAILURE; 3724 if (!bge_chip_enable_engine(bgep, SEND_BD_SELECTOR_MODE_REG, 3725 STATE_MACHINE_ATTN_ENABLE_BIT)) 3726 retval = DDI_FAILURE; 3727 3728 /* 3729 * Step 88: download firmware -- doesn't apply 3730 * Steps 89-90: enable Transmit & Receive MAC Engines 3731 */ 3732 if (!bge_chip_enable_engine(bgep, TRANSMIT_MAC_MODE_REG, 0)) 3733 retval = DDI_FAILURE; 3734 #ifdef BGE_IPMI_ASF 3735 if (!bgep->asf_enabled) { 3736 if (!bge_chip_enable_engine(bgep, RECEIVE_MAC_MODE_REG, 3737 RECEIVE_MODE_KEEP_VLAN_TAG)) 3738 retval = DDI_FAILURE; 3739 } else { 3740 if (!bge_chip_enable_engine(bgep, RECEIVE_MAC_MODE_REG, 0)) 3741 retval = DDI_FAILURE; 3742 } 3743 #else 3744 if (!bge_chip_enable_engine(bgep, RECEIVE_MAC_MODE_REG, 3745 RECEIVE_MODE_KEEP_VLAN_TAG)) 3746 retval = DDI_FAILURE; 3747 #endif 3748 3749 /* 3750 * Step 91: disable auto-polling of PHY status 3751 */ 3752 bge_reg_put32(bgep, MI_MODE_REG, MI_MODE_DEFAULT); 3753 3754 /* 3755 * Step 92: configure D0 power state (not required) 3756 * Step 93: initialise LED control register () 3757 */ 3758 ledctl = LED_CONTROL_DEFAULT; 3759 switch (bgep->chipid.device) { 3760 case DEVICE_ID_5700: 3761 case DEVICE_ID_5700x: 3762 case DEVICE_ID_5701: 3763 /* 3764 * Switch to 5700 (MAC) mode on these older chips 3765 */ 3766 ledctl &= ~LED_CONTROL_LED_MODE_MASK; 3767 ledctl |= LED_CONTROL_LED_MODE_5700; 3768 break; 3769 3770 default: 3771 break; 3772 } 3773 bge_reg_put32(bgep, ETHERNET_MAC_LED_CONTROL_REG, ledctl); 3774 3775 /* 3776 * Step 94: activate link 3777 */ 3778 bge_reg_put32(bgep, MI_STATUS_REG, MI_STATUS_LINK); 3779 3780 /* 3781 * Step 95: set up physical layer (PHY/SerDes) 3782 * restart autoneg (if required) 3783 */ 3784 if (reset_phys) 3785 if (bge_phys_update(bgep) == DDI_FAILURE) 3786 retval = DDI_FAILURE; 3787 3788 /* 3789 * Extra step (DSG): hand over all the Receive Buffers to the chip 3790 */ 3791 for (ring = 0; ring < BGE_BUFF_RINGS_USED; ++ring) 3792 bge_mbx_put(bgep, bgep->buff[ring].chip_mbx_reg, 3793 bgep->buff[ring].rf_next); 3794 3795 /* 3796 * MSI bits:The least significant MSI 16-bit word. 3797 * ISR will be triggered different. 3798 */ 3799 if (bgep->intr_type == DDI_INTR_TYPE_MSI) 3800 bge_reg_set32(bgep, HOST_COALESCE_MODE_REG, 0x70); 3801 3802 /* 3803 * Extra step (DSG): select which interrupts are enabled 3804 * 3805 * Program the Ethernet MAC engine to signal attention on 3806 * Link Change events, then enable interrupts on MAC, DMA, 3807 * and FLOW attention signals. 3808 */ 3809 bge_reg_set32(bgep, ETHERNET_MAC_EVENT_ENABLE_REG, 3810 ETHERNET_EVENT_LINK_INT | 3811 ETHERNET_STATUS_PCS_ERROR_INT); 3812 #ifdef BGE_IPMI_ASF 3813 if (bgep->asf_enabled) { 3814 bge_reg_set32(bgep, MODE_CONTROL_REG, 3815 MODE_INT_ON_FLOW_ATTN | 3816 MODE_INT_ON_DMA_ATTN | 3817 MODE_HOST_STACK_UP| 3818 MODE_INT_ON_MAC_ATTN); 3819 } else { 3820 #endif 3821 bge_reg_set32(bgep, MODE_CONTROL_REG, 3822 MODE_INT_ON_FLOW_ATTN | 3823 MODE_INT_ON_DMA_ATTN | 3824 MODE_INT_ON_MAC_ATTN); 3825 #ifdef BGE_IPMI_ASF 3826 } 3827 #endif 3828 3829 /* 3830 * Step 97: enable PCI interrupts!!! 3831 */ 3832 if (bgep->intr_type == DDI_INTR_TYPE_FIXED) 3833 bge_cfg_clr32(bgep, PCI_CONF_BGE_MHCR, 3834 MHCR_MASK_PCI_INT_OUTPUT); 3835 3836 /* 3837 * All done! 3838 */ 3839 bgep->bge_chip_state = BGE_CHIP_RUNNING; 3840 return (retval); 3841 } 3842 3843 3844 /* 3845 * ========== Hardware interrupt handler ========== 3846 */ 3847 3848 #undef BGE_DBG 3849 #define BGE_DBG BGE_DBG_INT /* debug flag for this code */ 3850 3851 /* 3852 * Sync the status block, then atomically clear the specified bits in 3853 * the <flags-and-tag> field of the status block. 3854 * the <flags> word of the status block, returning the value of the 3855 * <tag> and the <flags> before the bits were cleared. 3856 */ 3857 static int bge_status_sync(bge_t *bgep, uint64_t bits, uint64_t *flags); 3858 #pragma inline(bge_status_sync) 3859 3860 static int 3861 bge_status_sync(bge_t *bgep, uint64_t bits, uint64_t *flags) 3862 { 3863 bge_status_t *bsp; 3864 int retval; 3865 3866 BGE_TRACE(("bge_status_sync($%p, 0x%llx)", 3867 (void *)bgep, bits)); 3868 3869 ASSERT(bgep->bge_guard == BGE_GUARD); 3870 3871 DMA_SYNC(bgep->status_block, DDI_DMA_SYNC_FORKERNEL); 3872 retval = bge_check_dma_handle(bgep, bgep->status_block.dma_hdl); 3873 if (retval != DDI_FM_OK) 3874 return (retval); 3875 3876 bsp = DMA_VPTR(bgep->status_block); 3877 *flags = bge_atomic_clr64(&bsp->flags_n_tag, bits); 3878 3879 BGE_DEBUG(("bge_status_sync($%p, 0x%llx) returning 0x%llx", 3880 (void *)bgep, bits, *flags)); 3881 3882 return (retval); 3883 } 3884 3885 void bge_wake_factotum(bge_t *bgep); 3886 #pragma inline(bge_wake_factotum) 3887 3888 void 3889 bge_wake_factotum(bge_t *bgep) 3890 { 3891 mutex_enter(bgep->softintrlock); 3892 if (bgep->factotum_flag == 0) { 3893 bgep->factotum_flag = 1; 3894 ddi_trigger_softintr(bgep->factotum_id); 3895 } 3896 mutex_exit(bgep->softintrlock); 3897 } 3898 3899 /* 3900 * bge_intr() -- handle chip interrupts 3901 */ 3902 uint_t bge_intr(caddr_t arg1, caddr_t arg2); 3903 #pragma no_inline(bge_intr) 3904 3905 uint_t 3906 bge_intr(caddr_t arg1, caddr_t arg2) 3907 { 3908 bge_t *bgep = (void *)arg1; /* private device info */ 3909 bge_status_t *bsp; 3910 uint64_t flags; 3911 uint32_t regval; 3912 uint_t result; 3913 int retval, loop_cnt = 0; 3914 3915 BGE_TRACE(("bge_intr($%p) ($%p)", arg1, arg2)); 3916 3917 /* 3918 * GLD v2 checks that s/w setup is complete before passing 3919 * interrupts to this routine, thus eliminating the old 3920 * (and well-known) race condition around ddi_add_intr() 3921 */ 3922 ASSERT(bgep->progress & PROGRESS_HWINT); 3923 3924 result = DDI_INTR_UNCLAIMED; 3925 mutex_enter(bgep->genlock); 3926 3927 if (bgep->intr_type == DDI_INTR_TYPE_FIXED) { 3928 /* 3929 * Check whether chip's says it's asserting #INTA; 3930 * if not, don't process or claim the interrupt. 3931 * 3932 * Note that the PCI signal is active low, so the 3933 * bit is *zero* when the interrupt is asserted. 3934 */ 3935 regval = bge_reg_get32(bgep, MISC_LOCAL_CONTROL_REG); 3936 if (regval & MLCR_INTA_STATE) { 3937 if (bge_check_acc_handle(bgep, bgep->io_handle) 3938 != DDI_FM_OK) 3939 goto chip_stop; 3940 mutex_exit(bgep->genlock); 3941 return (result); 3942 } 3943 3944 /* 3945 * Block further PCI interrupts ... 3946 */ 3947 bge_reg_set32(bgep, PCI_CONF_BGE_MHCR, 3948 MHCR_MASK_PCI_INT_OUTPUT); 3949 3950 } else { 3951 /* 3952 * Check MSI status 3953 */ 3954 regval = bge_reg_get32(bgep, MSI_STATUS_REG); 3955 if (regval & MSI_ERROR_ATTENTION) { 3956 BGE_REPORT((bgep, "msi error attention," 3957 " status=0x%x", regval)); 3958 bge_reg_put32(bgep, MSI_STATUS_REG, regval); 3959 } 3960 } 3961 3962 result = DDI_INTR_CLAIMED; 3963 3964 BGE_DEBUG(("bge_intr($%p) ($%p) regval 0x%08x", arg1, arg2, regval)); 3965 3966 /* 3967 * Sync the status block and grab the flags-n-tag from it. 3968 * We count the number of interrupts where there doesn't 3969 * seem to have been a DMA update of the status block; if 3970 * it *has* been updated, the counter will be cleared in 3971 * the while() loop below ... 3972 */ 3973 bgep->missed_dmas += 1; 3974 bsp = DMA_VPTR(bgep->status_block); 3975 for (loop_cnt = 0; loop_cnt < bge_intr_max_loop; loop_cnt++) { 3976 if (bgep->bge_chip_state != BGE_CHIP_RUNNING) { 3977 /* 3978 * bge_chip_stop() may have freed dma area etc 3979 * while we were in this interrupt handler - 3980 * better not call bge_status_sync() 3981 */ 3982 (void) bge_check_acc_handle(bgep, 3983 bgep->io_handle); 3984 mutex_exit(bgep->genlock); 3985 return (DDI_INTR_CLAIMED); 3986 } 3987 retval = bge_status_sync(bgep, STATUS_FLAG_UPDATED, 3988 &flags); 3989 if (retval != DDI_FM_OK) { 3990 bgep->bge_dma_error = B_TRUE; 3991 goto chip_stop; 3992 } 3993 3994 if (!(flags & STATUS_FLAG_UPDATED)) 3995 break; 3996 3997 /* 3998 * Tell the chip that we're processing the interrupt 3999 */ 4000 bge_mbx_put(bgep, INTERRUPT_MBOX_0_REG, 4001 INTERRUPT_MBOX_DISABLE(flags)); 4002 if (bge_check_acc_handle(bgep, bgep->io_handle) != 4003 DDI_FM_OK) 4004 goto chip_stop; 4005 4006 /* 4007 * Drop the mutex while we: 4008 * Receive any newly-arrived packets 4009 * Recycle any newly-finished send buffers 4010 */ 4011 bgep->bge_intr_running = B_TRUE; 4012 mutex_exit(bgep->genlock); 4013 bge_receive(bgep, bsp); 4014 bge_recycle(bgep, bsp); 4015 mutex_enter(bgep->genlock); 4016 bgep->bge_intr_running = B_FALSE; 4017 4018 /* 4019 * Tell the chip we've finished processing, and 4020 * give it the tag that we got from the status 4021 * block earlier, so that it knows just how far 4022 * we've gone. If it's got more for us to do, 4023 * it will now update the status block and try 4024 * to assert an interrupt (but we've got the 4025 * #INTA blocked at present). If we see the 4026 * update, we'll loop around to do some more. 4027 * Eventually we'll get out of here ... 4028 */ 4029 bge_mbx_put(bgep, INTERRUPT_MBOX_0_REG, 4030 INTERRUPT_MBOX_ENABLE(flags)); 4031 if (bgep->chipid.pci_type == BGE_PCI_E) 4032 (void) bge_mbx_get(bgep, INTERRUPT_MBOX_0_REG); 4033 bgep->missed_dmas = 0; 4034 } 4035 4036 /* 4037 * Check for exceptional conditions that we need to handle 4038 * 4039 * Link status changed 4040 * Status block not updated 4041 */ 4042 if (flags & STATUS_FLAG_LINK_CHANGED) 4043 bge_wake_factotum(bgep); 4044 4045 if (bgep->missed_dmas) { 4046 /* 4047 * Probably due to the internal status tag not 4048 * being reset. Force a status block update now; 4049 * this should ensure that we get an update and 4050 * a new interrupt. After that, we should be in 4051 * sync again ... 4052 */ 4053 BGE_REPORT((bgep, "interrupt: flags 0x%llx - " 4054 "not updated?", flags)); 4055 bgep->missed_updates++; 4056 bge_reg_set32(bgep, HOST_COALESCE_MODE_REG, 4057 COALESCE_NOW); 4058 4059 if (bgep->missed_dmas >= bge_dma_miss_limit) { 4060 /* 4061 * If this happens multiple times in a row, 4062 * it means DMA is just not working. Maybe 4063 * the chip's failed, or maybe there's a 4064 * problem on the PCI bus or in the host-PCI 4065 * bridge (Tomatillo). 4066 * 4067 * At all events, we want to stop further 4068 * interrupts and let the recovery code take 4069 * over to see whether anything can be done 4070 * about it ... 4071 */ 4072 bge_fm_ereport(bgep, 4073 DDI_FM_DEVICE_BADINT_LIMIT); 4074 goto chip_stop; 4075 } 4076 } 4077 4078 /* 4079 * Reenable assertion of #INTA, unless there's a DMA fault 4080 */ 4081 if (bgep->intr_type == DDI_INTR_TYPE_FIXED) { 4082 bge_reg_clr32(bgep, PCI_CONF_BGE_MHCR, 4083 MHCR_MASK_PCI_INT_OUTPUT); 4084 if (bge_check_acc_handle(bgep, bgep->cfg_handle) != 4085 DDI_FM_OK) 4086 goto chip_stop; 4087 } 4088 4089 if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) 4090 goto chip_stop; 4091 4092 mutex_exit(bgep->genlock); 4093 return (result); 4094 4095 chip_stop: 4096 #ifdef BGE_IPMI_ASF 4097 if (bgep->asf_enabled && bgep->asf_status == ASF_STAT_RUN) { 4098 /* 4099 * We must stop ASF heart beat before 4100 * bge_chip_stop(), otherwise some 4101 * computers (ex. IBM HS20 blade 4102 * server) may crash. 4103 */ 4104 bge_asf_update_status(bgep); 4105 bge_asf_stop_timer(bgep); 4106 bgep->asf_status = ASF_STAT_STOP; 4107 4108 bge_asf_pre_reset_operations(bgep, BGE_INIT_RESET); 4109 (void) bge_check_acc_handle(bgep, bgep->cfg_handle); 4110 } 4111 #endif 4112 bge_chip_stop(bgep, B_TRUE); 4113 (void) bge_check_acc_handle(bgep, bgep->io_handle); 4114 mutex_exit(bgep->genlock); 4115 return (result); 4116 } 4117 4118 /* 4119 * ========== Factotum, implemented as a softint handler ========== 4120 */ 4121 4122 #undef BGE_DBG 4123 #define BGE_DBG BGE_DBG_FACT /* debug flag for this code */ 4124 4125 static void bge_factotum_error_handler(bge_t *bgep); 4126 #pragma no_inline(bge_factotum_error_handler) 4127 4128 static void 4129 bge_factotum_error_handler(bge_t *bgep) 4130 { 4131 uint32_t flow; 4132 uint32_t rdma; 4133 uint32_t wdma; 4134 uint32_t tmac; 4135 uint32_t rmac; 4136 uint32_t rxrs; 4137 uint32_t txrs = 0; 4138 4139 ASSERT(mutex_owned(bgep->genlock)); 4140 4141 /* 4142 * Read all the registers that show the possible 4143 * reasons for the ERROR bit to be asserted 4144 */ 4145 flow = bge_reg_get32(bgep, FLOW_ATTN_REG); 4146 rdma = bge_reg_get32(bgep, READ_DMA_STATUS_REG); 4147 wdma = bge_reg_get32(bgep, WRITE_DMA_STATUS_REG); 4148 tmac = bge_reg_get32(bgep, TRANSMIT_MAC_STATUS_REG); 4149 rmac = bge_reg_get32(bgep, RECEIVE_MAC_STATUS_REG); 4150 rxrs = bge_reg_get32(bgep, RX_RISC_STATE_REG); 4151 if (DEVICE_5704_SERIES_CHIPSETS(bgep)) 4152 txrs = bge_reg_get32(bgep, TX_RISC_STATE_REG); 4153 4154 BGE_DEBUG(("factotum($%p) flow 0x%x rdma 0x%x wdma 0x%x", 4155 (void *)bgep, flow, rdma, wdma)); 4156 BGE_DEBUG(("factotum($%p) tmac 0x%x rmac 0x%x rxrs 0x%08x txrs 0x%08x", 4157 (void *)bgep, tmac, rmac, rxrs, txrs)); 4158 4159 /* 4160 * For now, just clear all the errors ... 4161 */ 4162 if (DEVICE_5704_SERIES_CHIPSETS(bgep)) 4163 bge_reg_put32(bgep, TX_RISC_STATE_REG, ~0); 4164 bge_reg_put32(bgep, RX_RISC_STATE_REG, ~0); 4165 bge_reg_put32(bgep, RECEIVE_MAC_STATUS_REG, ~0); 4166 bge_reg_put32(bgep, WRITE_DMA_STATUS_REG, ~0); 4167 bge_reg_put32(bgep, READ_DMA_STATUS_REG, ~0); 4168 bge_reg_put32(bgep, FLOW_ATTN_REG, ~0); 4169 } 4170 4171 /* 4172 * Handler for hardware link state change. 4173 * 4174 * When this routine is called, the hardware link state has changed 4175 * and the new state is reflected in the param_* variables. Here 4176 * we must update the softstate and reprogram the MAC to match. 4177 */ 4178 static void bge_factotum_link_handler(bge_t *bgep); 4179 #pragma no_inline(bge_factotum_link_handler) 4180 4181 static void 4182 bge_factotum_link_handler(bge_t *bgep) 4183 { 4184 ASSERT(mutex_owned(bgep->genlock)); 4185 4186 /* 4187 * Update the s/w link_state 4188 */ 4189 if (bgep->param_link_up) 4190 bgep->link_state = LINK_STATE_UP; 4191 else 4192 bgep->link_state = LINK_STATE_DOWN; 4193 4194 /* 4195 * Reprogram the MAC modes to match 4196 */ 4197 bge_sync_mac_modes(bgep); 4198 } 4199 4200 static boolean_t bge_factotum_link_check(bge_t *bgep, int *dma_state); 4201 #pragma no_inline(bge_factotum_link_check) 4202 4203 static boolean_t 4204 bge_factotum_link_check(bge_t *bgep, int *dma_state) 4205 { 4206 boolean_t check; 4207 uint64_t flags; 4208 uint32_t tmac_status; 4209 4210 ASSERT(mutex_owned(bgep->genlock)); 4211 4212 /* 4213 * Get & clear the writable status bits in the Tx status register 4214 * (some bits are write-1-to-clear, others are just readonly). 4215 */ 4216 tmac_status = bge_reg_get32(bgep, TRANSMIT_MAC_STATUS_REG); 4217 bge_reg_put32(bgep, TRANSMIT_MAC_STATUS_REG, tmac_status); 4218 4219 /* 4220 * Get & clear the ERROR and LINK_CHANGED bits from the status block 4221 */ 4222 *dma_state = bge_status_sync(bgep, STATUS_FLAG_ERROR | 4223 STATUS_FLAG_LINK_CHANGED, &flags); 4224 if (*dma_state != DDI_FM_OK) 4225 return (B_FALSE); 4226 4227 /* 4228 * Clear any errors flagged in the status block ... 4229 */ 4230 if (flags & STATUS_FLAG_ERROR) 4231 bge_factotum_error_handler(bgep); 4232 4233 /* 4234 * We need to check the link status if: 4235 * the status block says there's been a link change 4236 * or there's any discrepancy between the various 4237 * flags indicating the link state (link_state, 4238 * param_link_up, and the LINK STATE bit in the 4239 * Transmit MAC status register). 4240 */ 4241 check = (flags & STATUS_FLAG_LINK_CHANGED) != 0; 4242 switch (bgep->link_state) { 4243 case LINK_STATE_UP: 4244 check |= (bgep->param_link_up == B_FALSE); 4245 check |= ((tmac_status & TRANSMIT_STATUS_LINK_UP) == 0); 4246 break; 4247 4248 case LINK_STATE_DOWN: 4249 check |= (bgep->param_link_up != B_FALSE); 4250 check |= ((tmac_status & TRANSMIT_STATUS_LINK_UP) != 0); 4251 break; 4252 4253 default: 4254 check = B_TRUE; 4255 break; 4256 } 4257 4258 /* 4259 * If <check> is false, we're sure the link hasn't changed. 4260 * If true, however, it's not yet definitive; we have to call 4261 * bge_phys_check() to determine whether the link has settled 4262 * into a new state yet ... and if it has, then call the link 4263 * state change handler.But when the chip is 5700 in Dell 6650 4264 * ,even if check is false, the link may have changed.So we 4265 * have to call bge_phys_check() to determine the link state. 4266 */ 4267 if (check || bgep->chipid.device == DEVICE_ID_5700) { 4268 check = bge_phys_check(bgep); 4269 if (check) 4270 bge_factotum_link_handler(bgep); 4271 } 4272 4273 return (check); 4274 } 4275 4276 /* 4277 * Factotum routine to check for Tx stall, using the 'watchdog' counter 4278 */ 4279 static boolean_t bge_factotum_stall_check(bge_t *bgep); 4280 #pragma no_inline(bge_factotum_stall_check) 4281 4282 static boolean_t 4283 bge_factotum_stall_check(bge_t *bgep) 4284 { 4285 uint32_t dogval; 4286 4287 ASSERT(mutex_owned(bgep->genlock)); 4288 4289 /* 4290 * Specific check for Tx stall ... 4291 * 4292 * The 'watchdog' counter is incremented whenever a packet 4293 * is queued, reset to 1 when some (but not all) buffers 4294 * are reclaimed, reset to 0 (disabled) when all buffers 4295 * are reclaimed, and shifted left here. If it exceeds the 4296 * threshold value, the chip is assumed to have stalled and 4297 * is put into the ERROR state. The factotum will then reset 4298 * it on the next pass. 4299 * 4300 * All of which should ensure that we don't get into a state 4301 * where packets are left pending indefinitely! 4302 */ 4303 dogval = bge_atomic_shl32(&bgep->watchdog, 1); 4304 if (dogval < bge_watchdog_count) 4305 return (B_FALSE); 4306 4307 #if !defined(BGE_NETCONSOLE) 4308 BGE_REPORT((bgep, "Tx stall detected, watchdog code 0x%x", dogval)); 4309 #endif 4310 bge_fm_ereport(bgep, DDI_FM_DEVICE_STALL); 4311 return (B_TRUE); 4312 } 4313 4314 /* 4315 * The factotum is woken up when there's something to do that we'd rather 4316 * not do from inside a hardware interrupt handler or high-level cyclic. 4317 * Its two main tasks are: 4318 * reset & restart the chip after an error 4319 * check the link status whenever necessary 4320 */ 4321 uint_t bge_chip_factotum(caddr_t arg); 4322 #pragma no_inline(bge_chip_factotum) 4323 4324 uint_t 4325 bge_chip_factotum(caddr_t arg) 4326 { 4327 bge_t *bgep; 4328 uint_t result; 4329 boolean_t error; 4330 boolean_t linkchg; 4331 int dma_state; 4332 4333 bgep = (void *)arg; 4334 4335 BGE_TRACE(("bge_chip_factotum($%p)", (void *)bgep)); 4336 4337 mutex_enter(bgep->softintrlock); 4338 if (bgep->factotum_flag == 0) { 4339 mutex_exit(bgep->softintrlock); 4340 return (DDI_INTR_UNCLAIMED); 4341 } 4342 bgep->factotum_flag = 0; 4343 mutex_exit(bgep->softintrlock); 4344 4345 result = DDI_INTR_CLAIMED; 4346 error = B_FALSE; 4347 linkchg = B_FALSE; 4348 4349 mutex_enter(bgep->genlock); 4350 switch (bgep->bge_chip_state) { 4351 default: 4352 break; 4353 4354 case BGE_CHIP_RUNNING: 4355 linkchg = bge_factotum_link_check(bgep, &dma_state); 4356 error = bge_factotum_stall_check(bgep); 4357 if (dma_state != DDI_FM_OK) { 4358 bgep->bge_dma_error = B_TRUE; 4359 error = B_TRUE; 4360 } 4361 if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) 4362 error = B_TRUE; 4363 if (error) 4364 bgep->bge_chip_state = BGE_CHIP_ERROR; 4365 break; 4366 4367 case BGE_CHIP_ERROR: 4368 error = B_TRUE; 4369 break; 4370 4371 case BGE_CHIP_FAULT: 4372 /* 4373 * Fault detected, time to reset ... 4374 */ 4375 if (bge_autorecover) { 4376 if (!(bgep->progress & PROGRESS_BUFS)) { 4377 /* 4378 * if we can't allocate the ring buffers, 4379 * try later 4380 */ 4381 if (bge_alloc_bufs(bgep) != DDI_SUCCESS) { 4382 mutex_exit(bgep->genlock); 4383 return (result); 4384 } 4385 bgep->progress |= PROGRESS_BUFS; 4386 } 4387 if (!(bgep->progress & PROGRESS_INTR)) { 4388 bge_init_rings(bgep); 4389 bge_intr_enable(bgep); 4390 bgep->progress |= PROGRESS_INTR; 4391 } 4392 if (!(bgep->progress & PROGRESS_KSTATS)) { 4393 bge_init_kstats(bgep, 4394 ddi_get_instance(bgep->devinfo)); 4395 bgep->progress |= PROGRESS_KSTATS; 4396 } 4397 4398 BGE_REPORT((bgep, "automatic recovery activated")); 4399 4400 if (bge_restart(bgep, B_FALSE) != DDI_SUCCESS) { 4401 bgep->bge_chip_state = BGE_CHIP_ERROR; 4402 error = B_TRUE; 4403 } 4404 if (bge_check_acc_handle(bgep, bgep->cfg_handle) != 4405 DDI_FM_OK) { 4406 bgep->bge_chip_state = BGE_CHIP_ERROR; 4407 error = B_TRUE; 4408 } 4409 if (bge_check_acc_handle(bgep, bgep->io_handle) != 4410 DDI_FM_OK) { 4411 bgep->bge_chip_state = BGE_CHIP_ERROR; 4412 error = B_TRUE; 4413 } 4414 if (error == B_FALSE) { 4415 #ifdef BGE_IPMI_ASF 4416 if (bgep->asf_enabled && 4417 bgep->asf_status != ASF_STAT_RUN) { 4418 bgep->asf_timeout_id = timeout( 4419 bge_asf_heartbeat, (void *)bgep, 4420 drv_usectohz( 4421 BGE_ASF_HEARTBEAT_INTERVAL)); 4422 bgep->asf_status = ASF_STAT_RUN; 4423 } 4424 #endif 4425 if (!bgep->manual_reset) { 4426 ddi_fm_service_impact(bgep->devinfo, 4427 DDI_SERVICE_RESTORED); 4428 } 4429 } 4430 } 4431 break; 4432 } 4433 4434 4435 /* 4436 * If an error is detected, stop the chip now, marking it as 4437 * faulty, so that it will be reset next time through ... 4438 * 4439 * Note that if intr_running is set, then bge_intr() has dropped 4440 * genlock to call bge_receive/bge_recycle. Can't stop the chip at 4441 * this point so have to wait until the next time the factotum runs. 4442 */ 4443 if (error && !bgep->bge_intr_running) { 4444 #ifdef BGE_IPMI_ASF 4445 if (bgep->asf_enabled && (bgep->asf_status == ASF_STAT_RUN)) { 4446 /* 4447 * We must stop ASF heart beat before bge_chip_stop(), 4448 * otherwise some computers (ex. IBM HS20 blade server) 4449 * may crash. 4450 */ 4451 bge_asf_update_status(bgep); 4452 bge_asf_stop_timer(bgep); 4453 bgep->asf_status = ASF_STAT_STOP; 4454 4455 bge_asf_pre_reset_operations(bgep, BGE_INIT_RESET); 4456 (void) bge_check_acc_handle(bgep, bgep->cfg_handle); 4457 } 4458 #endif 4459 bge_chip_stop(bgep, B_TRUE); 4460 (void) bge_check_acc_handle(bgep, bgep->io_handle); 4461 } 4462 mutex_exit(bgep->genlock); 4463 4464 /* 4465 * If the link state changed, tell the world about it. 4466 * Note: can't do this while still holding the mutex. 4467 */ 4468 if (bgep->link_update_timer == BGE_LINK_UPDATE_TIMEOUT && 4469 bgep->link_state != LINK_STATE_UNKNOWN) 4470 linkchg = B_TRUE; 4471 else if (bgep->link_update_timer < BGE_LINK_UPDATE_TIMEOUT && 4472 bgep->link_state == LINK_STATE_DOWN) 4473 linkchg = B_FALSE; 4474 4475 if (linkchg) { 4476 mac_link_update(bgep->mh, bgep->link_state); 4477 bgep->link_update_timer = BGE_LINK_UPDATE_DONE; 4478 } 4479 if (bgep->manual_reset) { 4480 bgep->manual_reset = B_FALSE; 4481 } 4482 4483 return (result); 4484 } 4485 4486 /* 4487 * High-level cyclic handler 4488 * 4489 * This routine schedules a (low-level) softint callback to the 4490 * factotum, and prods the chip to update the status block (which 4491 * will cause a hardware interrupt when complete). 4492 */ 4493 void bge_chip_cyclic(void *arg); 4494 #pragma no_inline(bge_chip_cyclic) 4495 4496 void 4497 bge_chip_cyclic(void *arg) 4498 { 4499 bge_t *bgep; 4500 4501 bgep = arg; 4502 4503 switch (bgep->bge_chip_state) { 4504 default: 4505 return; 4506 4507 case BGE_CHIP_RUNNING: 4508 bge_reg_set32(bgep, HOST_COALESCE_MODE_REG, COALESCE_NOW); 4509 if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) 4510 ddi_fm_service_impact(bgep->devinfo, 4511 DDI_SERVICE_UNAFFECTED); 4512 4513 if (bgep->link_update_timer < BGE_LINK_UPDATE_TIMEOUT) 4514 bgep->link_update_timer++; 4515 4516 break; 4517 4518 case BGE_CHIP_FAULT: 4519 case BGE_CHIP_ERROR: 4520 break; 4521 } 4522 4523 bge_wake_factotum(bgep); 4524 } 4525 4526 4527 /* 4528 * ========== Ioctl subfunctions ========== 4529 */ 4530 4531 #undef BGE_DBG 4532 #define BGE_DBG BGE_DBG_PPIO /* debug flag for this code */ 4533 4534 #if BGE_DEBUGGING || BGE_DO_PPIO 4535 4536 static void bge_chip_peek_cfg(bge_t *bgep, bge_peekpoke_t *ppd); 4537 #pragma no_inline(bge_chip_peek_cfg) 4538 4539 static void 4540 bge_chip_peek_cfg(bge_t *bgep, bge_peekpoke_t *ppd) 4541 { 4542 uint64_t regval; 4543 uint64_t regno; 4544 4545 BGE_TRACE(("bge_chip_peek_cfg($%p, $%p)", 4546 (void *)bgep, (void *)ppd)); 4547 4548 regno = ppd->pp_acc_offset; 4549 4550 switch (ppd->pp_acc_size) { 4551 case 1: 4552 regval = pci_config_get8(bgep->cfg_handle, regno); 4553 break; 4554 4555 case 2: 4556 regval = pci_config_get16(bgep->cfg_handle, regno); 4557 break; 4558 4559 case 4: 4560 regval = pci_config_get32(bgep->cfg_handle, regno); 4561 break; 4562 4563 case 8: 4564 regval = pci_config_get64(bgep->cfg_handle, regno); 4565 break; 4566 } 4567 4568 ppd->pp_acc_data = regval; 4569 } 4570 4571 static void bge_chip_poke_cfg(bge_t *bgep, bge_peekpoke_t *ppd); 4572 #pragma no_inline(bge_chip_poke_cfg) 4573 4574 static void 4575 bge_chip_poke_cfg(bge_t *bgep, bge_peekpoke_t *ppd) 4576 { 4577 uint64_t regval; 4578 uint64_t regno; 4579 4580 BGE_TRACE(("bge_chip_poke_cfg($%p, $%p)", 4581 (void *)bgep, (void *)ppd)); 4582 4583 regno = ppd->pp_acc_offset; 4584 regval = ppd->pp_acc_data; 4585 4586 switch (ppd->pp_acc_size) { 4587 case 1: 4588 pci_config_put8(bgep->cfg_handle, regno, regval); 4589 break; 4590 4591 case 2: 4592 pci_config_put16(bgep->cfg_handle, regno, regval); 4593 break; 4594 4595 case 4: 4596 pci_config_put32(bgep->cfg_handle, regno, regval); 4597 break; 4598 4599 case 8: 4600 pci_config_put64(bgep->cfg_handle, regno, regval); 4601 break; 4602 } 4603 } 4604 4605 static void bge_chip_peek_reg(bge_t *bgep, bge_peekpoke_t *ppd); 4606 #pragma no_inline(bge_chip_peek_reg) 4607 4608 static void 4609 bge_chip_peek_reg(bge_t *bgep, bge_peekpoke_t *ppd) 4610 { 4611 uint64_t regval; 4612 void *regaddr; 4613 4614 BGE_TRACE(("bge_chip_peek_reg($%p, $%p)", 4615 (void *)bgep, (void *)ppd)); 4616 4617 regaddr = PIO_ADDR(bgep, ppd->pp_acc_offset); 4618 4619 switch (ppd->pp_acc_size) { 4620 case 1: 4621 regval = ddi_get8(bgep->io_handle, regaddr); 4622 break; 4623 4624 case 2: 4625 regval = ddi_get16(bgep->io_handle, regaddr); 4626 break; 4627 4628 case 4: 4629 regval = ddi_get32(bgep->io_handle, regaddr); 4630 break; 4631 4632 case 8: 4633 regval = ddi_get64(bgep->io_handle, regaddr); 4634 break; 4635 } 4636 4637 ppd->pp_acc_data = regval; 4638 } 4639 4640 static void bge_chip_poke_reg(bge_t *bgep, bge_peekpoke_t *ppd); 4641 #pragma no_inline(bge_chip_peek_reg) 4642 4643 static void 4644 bge_chip_poke_reg(bge_t *bgep, bge_peekpoke_t *ppd) 4645 { 4646 uint64_t regval; 4647 void *regaddr; 4648 4649 BGE_TRACE(("bge_chip_poke_reg($%p, $%p)", 4650 (void *)bgep, (void *)ppd)); 4651 4652 regaddr = PIO_ADDR(bgep, ppd->pp_acc_offset); 4653 regval = ppd->pp_acc_data; 4654 4655 switch (ppd->pp_acc_size) { 4656 case 1: 4657 ddi_put8(bgep->io_handle, regaddr, regval); 4658 break; 4659 4660 case 2: 4661 ddi_put16(bgep->io_handle, regaddr, regval); 4662 break; 4663 4664 case 4: 4665 ddi_put32(bgep->io_handle, regaddr, regval); 4666 break; 4667 4668 case 8: 4669 ddi_put64(bgep->io_handle, regaddr, regval); 4670 break; 4671 } 4672 BGE_PCICHK(bgep); 4673 } 4674 4675 static void bge_chip_peek_nic(bge_t *bgep, bge_peekpoke_t *ppd); 4676 #pragma no_inline(bge_chip_peek_nic) 4677 4678 static void 4679 bge_chip_peek_nic(bge_t *bgep, bge_peekpoke_t *ppd) 4680 { 4681 uint64_t regoff; 4682 uint64_t regval; 4683 void *regaddr; 4684 4685 BGE_TRACE(("bge_chip_peek_nic($%p, $%p)", 4686 (void *)bgep, (void *)ppd)); 4687 4688 regoff = ppd->pp_acc_offset; 4689 bge_nic_setwin(bgep, regoff & ~MWBAR_GRANULE_MASK); 4690 regoff &= MWBAR_GRANULE_MASK; 4691 regoff += NIC_MEM_WINDOW_OFFSET; 4692 regaddr = PIO_ADDR(bgep, regoff); 4693 4694 switch (ppd->pp_acc_size) { 4695 case 1: 4696 regval = ddi_get8(bgep->io_handle, regaddr); 4697 break; 4698 4699 case 2: 4700 regval = ddi_get16(bgep->io_handle, regaddr); 4701 break; 4702 4703 case 4: 4704 regval = ddi_get32(bgep->io_handle, regaddr); 4705 break; 4706 4707 case 8: 4708 regval = ddi_get64(bgep->io_handle, regaddr); 4709 break; 4710 } 4711 4712 ppd->pp_acc_data = regval; 4713 } 4714 4715 static void bge_chip_poke_nic(bge_t *bgep, bge_peekpoke_t *ppd); 4716 #pragma no_inline(bge_chip_poke_nic) 4717 4718 static void 4719 bge_chip_poke_nic(bge_t *bgep, bge_peekpoke_t *ppd) 4720 { 4721 uint64_t regoff; 4722 uint64_t regval; 4723 void *regaddr; 4724 4725 BGE_TRACE(("bge_chip_poke_nic($%p, $%p)", 4726 (void *)bgep, (void *)ppd)); 4727 4728 regoff = ppd->pp_acc_offset; 4729 bge_nic_setwin(bgep, regoff & ~MWBAR_GRANULE_MASK); 4730 regoff &= MWBAR_GRANULE_MASK; 4731 regoff += NIC_MEM_WINDOW_OFFSET; 4732 regaddr = PIO_ADDR(bgep, regoff); 4733 regval = ppd->pp_acc_data; 4734 4735 switch (ppd->pp_acc_size) { 4736 case 1: 4737 ddi_put8(bgep->io_handle, regaddr, regval); 4738 break; 4739 4740 case 2: 4741 ddi_put16(bgep->io_handle, regaddr, regval); 4742 break; 4743 4744 case 4: 4745 ddi_put32(bgep->io_handle, regaddr, regval); 4746 break; 4747 4748 case 8: 4749 ddi_put64(bgep->io_handle, regaddr, regval); 4750 break; 4751 } 4752 BGE_PCICHK(bgep); 4753 } 4754 4755 static void bge_chip_peek_mii(bge_t *bgep, bge_peekpoke_t *ppd); 4756 #pragma no_inline(bge_chip_peek_mii) 4757 4758 static void 4759 bge_chip_peek_mii(bge_t *bgep, bge_peekpoke_t *ppd) 4760 { 4761 BGE_TRACE(("bge_chip_peek_mii($%p, $%p)", 4762 (void *)bgep, (void *)ppd)); 4763 4764 ppd->pp_acc_data = bge_mii_get16(bgep, ppd->pp_acc_offset/2); 4765 } 4766 4767 static void bge_chip_poke_mii(bge_t *bgep, bge_peekpoke_t *ppd); 4768 #pragma no_inline(bge_chip_poke_mii) 4769 4770 static void 4771 bge_chip_poke_mii(bge_t *bgep, bge_peekpoke_t *ppd) 4772 { 4773 BGE_TRACE(("bge_chip_poke_mii($%p, $%p)", 4774 (void *)bgep, (void *)ppd)); 4775 4776 bge_mii_put16(bgep, ppd->pp_acc_offset/2, ppd->pp_acc_data); 4777 } 4778 4779 #if BGE_SEE_IO32 4780 4781 static void bge_chip_peek_seeprom(bge_t *bgep, bge_peekpoke_t *ppd); 4782 #pragma no_inline(bge_chip_peek_seeprom) 4783 4784 static void 4785 bge_chip_peek_seeprom(bge_t *bgep, bge_peekpoke_t *ppd) 4786 { 4787 uint32_t data; 4788 int err; 4789 4790 BGE_TRACE(("bge_chip_peek_seeprom($%p, $%p)", 4791 (void *)bgep, (void *)ppd)); 4792 4793 err = bge_nvmem_rw32(bgep, BGE_SEE_READ, ppd->pp_acc_offset, &data); 4794 ppd->pp_acc_data = err ? ~0ull : data; 4795 } 4796 4797 static void bge_chip_poke_seeprom(bge_t *bgep, bge_peekpoke_t *ppd); 4798 #pragma no_inline(bge_chip_poke_seeprom) 4799 4800 static void 4801 bge_chip_poke_seeprom(bge_t *bgep, bge_peekpoke_t *ppd) 4802 { 4803 uint32_t data; 4804 4805 BGE_TRACE(("bge_chip_poke_seeprom($%p, $%p)", 4806 (void *)bgep, (void *)ppd)); 4807 4808 data = ppd->pp_acc_data; 4809 (void) bge_nvmem_rw32(bgep, BGE_SEE_WRITE, ppd->pp_acc_offset, &data); 4810 } 4811 #endif /* BGE_SEE_IO32 */ 4812 4813 #if BGE_FLASH_IO32 4814 4815 static void bge_chip_peek_flash(bge_t *bgep, bge_peekpoke_t *ppd); 4816 #pragma no_inline(bge_chip_peek_flash) 4817 4818 static void 4819 bge_chip_peek_flash(bge_t *bgep, bge_peekpoke_t *ppd) 4820 { 4821 uint32_t data; 4822 int err; 4823 4824 BGE_TRACE(("bge_chip_peek_flash($%p, $%p)", 4825 (void *)bgep, (void *)ppd)); 4826 4827 err = bge_nvmem_rw32(bgep, BGE_FLASH_READ, ppd->pp_acc_offset, &data); 4828 ppd->pp_acc_data = err ? ~0ull : data; 4829 } 4830 4831 static void bge_chip_poke_flash(bge_t *bgep, bge_peekpoke_t *ppd); 4832 #pragma no_inline(bge_chip_poke_flash) 4833 4834 static void 4835 bge_chip_poke_flash(bge_t *bgep, bge_peekpoke_t *ppd) 4836 { 4837 uint32_t data; 4838 4839 BGE_TRACE(("bge_chip_poke_flash($%p, $%p)", 4840 (void *)bgep, (void *)ppd)); 4841 4842 data = ppd->pp_acc_data; 4843 (void) bge_nvmem_rw32(bgep, BGE_FLASH_WRITE, 4844 ppd->pp_acc_offset, &data); 4845 } 4846 #endif /* BGE_FLASH_IO32 */ 4847 4848 static void bge_chip_peek_mem(bge_t *bgep, bge_peekpoke_t *ppd); 4849 #pragma no_inline(bge_chip_peek_mem) 4850 4851 static void 4852 bge_chip_peek_mem(bge_t *bgep, bge_peekpoke_t *ppd) 4853 { 4854 uint64_t regval; 4855 void *vaddr; 4856 4857 BGE_TRACE(("bge_chip_peek_bge($%p, $%p)", 4858 (void *)bgep, (void *)ppd)); 4859 4860 vaddr = (void *)(uintptr_t)ppd->pp_acc_offset; 4861 4862 switch (ppd->pp_acc_size) { 4863 case 1: 4864 regval = *(uint8_t *)vaddr; 4865 break; 4866 4867 case 2: 4868 regval = *(uint16_t *)vaddr; 4869 break; 4870 4871 case 4: 4872 regval = *(uint32_t *)vaddr; 4873 break; 4874 4875 case 8: 4876 regval = *(uint64_t *)vaddr; 4877 break; 4878 } 4879 4880 BGE_DEBUG(("bge_chip_peek_mem($%p, $%p) peeked 0x%llx from $%p", 4881 (void *)bgep, (void *)ppd, regval, vaddr)); 4882 4883 ppd->pp_acc_data = regval; 4884 } 4885 4886 static void bge_chip_poke_mem(bge_t *bgep, bge_peekpoke_t *ppd); 4887 #pragma no_inline(bge_chip_poke_mem) 4888 4889 static void 4890 bge_chip_poke_mem(bge_t *bgep, bge_peekpoke_t *ppd) 4891 { 4892 uint64_t regval; 4893 void *vaddr; 4894 4895 BGE_TRACE(("bge_chip_poke_mem($%p, $%p)", 4896 (void *)bgep, (void *)ppd)); 4897 4898 vaddr = (void *)(uintptr_t)ppd->pp_acc_offset; 4899 regval = ppd->pp_acc_data; 4900 4901 BGE_DEBUG(("bge_chip_poke_mem($%p, $%p) poking 0x%llx at $%p", 4902 (void *)bgep, (void *)ppd, regval, vaddr)); 4903 4904 switch (ppd->pp_acc_size) { 4905 case 1: 4906 *(uint8_t *)vaddr = (uint8_t)regval; 4907 break; 4908 4909 case 2: 4910 *(uint16_t *)vaddr = (uint16_t)regval; 4911 break; 4912 4913 case 4: 4914 *(uint32_t *)vaddr = (uint32_t)regval; 4915 break; 4916 4917 case 8: 4918 *(uint64_t *)vaddr = (uint64_t)regval; 4919 break; 4920 } 4921 } 4922 4923 static enum ioc_reply bge_pp_ioctl(bge_t *bgep, int cmd, mblk_t *mp, 4924 struct iocblk *iocp); 4925 #pragma no_inline(bge_pp_ioctl) 4926 4927 static enum ioc_reply 4928 bge_pp_ioctl(bge_t *bgep, int cmd, mblk_t *mp, struct iocblk *iocp) 4929 { 4930 void (*ppfn)(bge_t *bgep, bge_peekpoke_t *ppd); 4931 bge_peekpoke_t *ppd; 4932 dma_area_t *areap; 4933 uint64_t sizemask; 4934 uint64_t mem_va; 4935 uint64_t maxoff; 4936 boolean_t peek; 4937 4938 switch (cmd) { 4939 default: 4940 /* NOTREACHED */ 4941 bge_error(bgep, "bge_pp_ioctl: invalid cmd 0x%x", cmd); 4942 return (IOC_INVAL); 4943 4944 case BGE_PEEK: 4945 peek = B_TRUE; 4946 break; 4947 4948 case BGE_POKE: 4949 peek = B_FALSE; 4950 break; 4951 } 4952 4953 /* 4954 * Validate format of ioctl 4955 */ 4956 if (iocp->ioc_count != sizeof (bge_peekpoke_t)) 4957 return (IOC_INVAL); 4958 if (mp->b_cont == NULL) 4959 return (IOC_INVAL); 4960 ppd = (void *)mp->b_cont->b_rptr; 4961 4962 /* 4963 * Validate request parameters 4964 */ 4965 switch (ppd->pp_acc_space) { 4966 default: 4967 return (IOC_INVAL); 4968 4969 case BGE_PP_SPACE_CFG: 4970 /* 4971 * Config space 4972 */ 4973 sizemask = 8|4|2|1; 4974 mem_va = 0; 4975 maxoff = PCI_CONF_HDR_SIZE; 4976 ppfn = peek ? bge_chip_peek_cfg : bge_chip_poke_cfg; 4977 break; 4978 4979 case BGE_PP_SPACE_REG: 4980 /* 4981 * Memory-mapped I/O space 4982 */ 4983 sizemask = 8|4|2|1; 4984 mem_va = 0; 4985 maxoff = RIAAR_REGISTER_MAX; 4986 ppfn = peek ? bge_chip_peek_reg : bge_chip_poke_reg; 4987 break; 4988 4989 case BGE_PP_SPACE_NIC: 4990 /* 4991 * NIC on-chip memory 4992 */ 4993 sizemask = 8|4|2|1; 4994 mem_va = 0; 4995 maxoff = MWBAR_ONCHIP_MAX; 4996 ppfn = peek ? bge_chip_peek_nic : bge_chip_poke_nic; 4997 break; 4998 4999 case BGE_PP_SPACE_MII: 5000 /* 5001 * PHY's MII registers 5002 * NB: all PHY registers are two bytes, but the 5003 * addresses increment in ones (word addressing). 5004 * So we scale the address here, then undo the 5005 * transformation inside the peek/poke functions. 5006 */ 5007 ppd->pp_acc_offset *= 2; 5008 sizemask = 2; 5009 mem_va = 0; 5010 maxoff = (MII_MAXREG+1)*2; 5011 ppfn = peek ? bge_chip_peek_mii : bge_chip_poke_mii; 5012 break; 5013 5014 #if BGE_SEE_IO32 5015 case BGE_PP_SPACE_SEEPROM: 5016 /* 5017 * Attached SEEPROM(s), if any. 5018 * NB: we use the high-order bits of the 'address' as 5019 * a device select to accommodate multiple SEEPROMS, 5020 * If each one is the maximum size (64kbytes), this 5021 * makes them appear contiguous. Otherwise, there may 5022 * be holes in the mapping. ENxS doesn't have any 5023 * SEEPROMs anyway ... 5024 */ 5025 sizemask = 4; 5026 mem_va = 0; 5027 maxoff = SEEPROM_DEV_AND_ADDR_MASK; 5028 ppfn = peek ? bge_chip_peek_seeprom : bge_chip_poke_seeprom; 5029 break; 5030 #endif /* BGE_SEE_IO32 */ 5031 5032 #if BGE_FLASH_IO32 5033 case BGE_PP_SPACE_FLASH: 5034 /* 5035 * Attached Flash device (if any); a maximum of one device 5036 * is currently supported. But it can be up to 1MB (unlike 5037 * the 64k limit on SEEPROMs) so why would you need more ;-) 5038 */ 5039 sizemask = 4; 5040 mem_va = 0; 5041 maxoff = NVM_FLASH_ADDR_MASK; 5042 ppfn = peek ? bge_chip_peek_flash : bge_chip_poke_flash; 5043 break; 5044 #endif /* BGE_FLASH_IO32 */ 5045 5046 case BGE_PP_SPACE_BGE: 5047 /* 5048 * BGE data structure! 5049 */ 5050 sizemask = 8|4|2|1; 5051 mem_va = (uintptr_t)bgep; 5052 maxoff = sizeof (*bgep); 5053 ppfn = peek ? bge_chip_peek_mem : bge_chip_poke_mem; 5054 break; 5055 5056 case BGE_PP_SPACE_STATUS: 5057 case BGE_PP_SPACE_STATISTICS: 5058 case BGE_PP_SPACE_TXDESC: 5059 case BGE_PP_SPACE_TXBUFF: 5060 case BGE_PP_SPACE_RXDESC: 5061 case BGE_PP_SPACE_RXBUFF: 5062 /* 5063 * Various DMA_AREAs 5064 */ 5065 switch (ppd->pp_acc_space) { 5066 case BGE_PP_SPACE_TXDESC: 5067 areap = &bgep->tx_desc; 5068 break; 5069 case BGE_PP_SPACE_TXBUFF: 5070 areap = &bgep->tx_buff[0]; 5071 break; 5072 case BGE_PP_SPACE_RXDESC: 5073 areap = &bgep->rx_desc[0]; 5074 break; 5075 case BGE_PP_SPACE_RXBUFF: 5076 areap = &bgep->rx_buff[0]; 5077 break; 5078 case BGE_PP_SPACE_STATUS: 5079 areap = &bgep->status_block; 5080 break; 5081 case BGE_PP_SPACE_STATISTICS: 5082 if (bgep->chipid.statistic_type == BGE_STAT_BLK) 5083 areap = &bgep->statistics; 5084 break; 5085 } 5086 5087 sizemask = 8|4|2|1; 5088 mem_va = (uintptr_t)areap->mem_va; 5089 maxoff = areap->alength; 5090 ppfn = peek ? bge_chip_peek_mem : bge_chip_poke_mem; 5091 break; 5092 } 5093 5094 switch (ppd->pp_acc_size) { 5095 default: 5096 return (IOC_INVAL); 5097 5098 case 8: 5099 case 4: 5100 case 2: 5101 case 1: 5102 if ((ppd->pp_acc_size & sizemask) == 0) 5103 return (IOC_INVAL); 5104 break; 5105 } 5106 5107 if ((ppd->pp_acc_offset % ppd->pp_acc_size) != 0) 5108 return (IOC_INVAL); 5109 5110 if (ppd->pp_acc_offset >= maxoff) 5111 return (IOC_INVAL); 5112 5113 if (ppd->pp_acc_offset+ppd->pp_acc_size > maxoff) 5114 return (IOC_INVAL); 5115 5116 /* 5117 * All OK - go do it! 5118 */ 5119 ppd->pp_acc_offset += mem_va; 5120 (*ppfn)(bgep, ppd); 5121 return (peek ? IOC_REPLY : IOC_ACK); 5122 } 5123 5124 static enum ioc_reply bge_diag_ioctl(bge_t *bgep, int cmd, mblk_t *mp, 5125 struct iocblk *iocp); 5126 #pragma no_inline(bge_diag_ioctl) 5127 5128 static enum ioc_reply 5129 bge_diag_ioctl(bge_t *bgep, int cmd, mblk_t *mp, struct iocblk *iocp) 5130 { 5131 ASSERT(mutex_owned(bgep->genlock)); 5132 5133 switch (cmd) { 5134 default: 5135 /* NOTREACHED */ 5136 bge_error(bgep, "bge_diag_ioctl: invalid cmd 0x%x", cmd); 5137 return (IOC_INVAL); 5138 5139 case BGE_DIAG: 5140 /* 5141 * Currently a no-op 5142 */ 5143 return (IOC_ACK); 5144 5145 case BGE_PEEK: 5146 case BGE_POKE: 5147 return (bge_pp_ioctl(bgep, cmd, mp, iocp)); 5148 5149 case BGE_PHY_RESET: 5150 return (IOC_RESTART_ACK); 5151 5152 case BGE_SOFT_RESET: 5153 case BGE_HARD_RESET: 5154 /* 5155 * Reset and reinitialise the 570x hardware 5156 */ 5157 bgep->bge_chip_state = BGE_CHIP_FAULT; 5158 ddi_trigger_softintr(bgep->factotum_id); 5159 (void) bge_restart(bgep, cmd == BGE_HARD_RESET); 5160 return (IOC_ACK); 5161 } 5162 5163 /* NOTREACHED */ 5164 } 5165 5166 #endif /* BGE_DEBUGGING || BGE_DO_PPIO */ 5167 5168 static enum ioc_reply bge_mii_ioctl(bge_t *bgep, int cmd, mblk_t *mp, 5169 struct iocblk *iocp); 5170 #pragma no_inline(bge_mii_ioctl) 5171 5172 static enum ioc_reply 5173 bge_mii_ioctl(bge_t *bgep, int cmd, mblk_t *mp, struct iocblk *iocp) 5174 { 5175 struct bge_mii_rw *miirwp; 5176 5177 /* 5178 * Validate format of ioctl 5179 */ 5180 if (iocp->ioc_count != sizeof (struct bge_mii_rw)) 5181 return (IOC_INVAL); 5182 if (mp->b_cont == NULL) 5183 return (IOC_INVAL); 5184 miirwp = (void *)mp->b_cont->b_rptr; 5185 5186 /* 5187 * Validate request parameters ... 5188 */ 5189 if (miirwp->mii_reg > MII_MAXREG) 5190 return (IOC_INVAL); 5191 5192 switch (cmd) { 5193 default: 5194 /* NOTREACHED */ 5195 bge_error(bgep, "bge_mii_ioctl: invalid cmd 0x%x", cmd); 5196 return (IOC_INVAL); 5197 5198 case BGE_MII_READ: 5199 miirwp->mii_data = bge_mii_get16(bgep, miirwp->mii_reg); 5200 return (IOC_REPLY); 5201 5202 case BGE_MII_WRITE: 5203 bge_mii_put16(bgep, miirwp->mii_reg, miirwp->mii_data); 5204 return (IOC_ACK); 5205 } 5206 5207 /* NOTREACHED */ 5208 } 5209 5210 #if BGE_SEE_IO32 5211 5212 static enum ioc_reply bge_see_ioctl(bge_t *bgep, int cmd, mblk_t *mp, 5213 struct iocblk *iocp); 5214 #pragma no_inline(bge_see_ioctl) 5215 5216 static enum ioc_reply 5217 bge_see_ioctl(bge_t *bgep, int cmd, mblk_t *mp, struct iocblk *iocp) 5218 { 5219 struct bge_see_rw *seerwp; 5220 5221 /* 5222 * Validate format of ioctl 5223 */ 5224 if (iocp->ioc_count != sizeof (struct bge_see_rw)) 5225 return (IOC_INVAL); 5226 if (mp->b_cont == NULL) 5227 return (IOC_INVAL); 5228 seerwp = (void *)mp->b_cont->b_rptr; 5229 5230 /* 5231 * Validate request parameters ... 5232 */ 5233 if (seerwp->see_addr & ~SEEPROM_DEV_AND_ADDR_MASK) 5234 return (IOC_INVAL); 5235 5236 switch (cmd) { 5237 default: 5238 /* NOTREACHED */ 5239 bge_error(bgep, "bge_see_ioctl: invalid cmd 0x%x", cmd); 5240 return (IOC_INVAL); 5241 5242 case BGE_SEE_READ: 5243 case BGE_SEE_WRITE: 5244 iocp->ioc_error = bge_nvmem_rw32(bgep, cmd, 5245 seerwp->see_addr, &seerwp->see_data); 5246 return (IOC_REPLY); 5247 } 5248 5249 /* NOTREACHED */ 5250 } 5251 5252 #endif /* BGE_SEE_IO32 */ 5253 5254 #if BGE_FLASH_IO32 5255 5256 static enum ioc_reply bge_flash_ioctl(bge_t *bgep, int cmd, mblk_t *mp, 5257 struct iocblk *iocp); 5258 #pragma no_inline(bge_flash_ioctl) 5259 5260 static enum ioc_reply 5261 bge_flash_ioctl(bge_t *bgep, int cmd, mblk_t *mp, struct iocblk *iocp) 5262 { 5263 struct bge_flash_rw *flashrwp; 5264 5265 /* 5266 * Validate format of ioctl 5267 */ 5268 if (iocp->ioc_count != sizeof (struct bge_flash_rw)) 5269 return (IOC_INVAL); 5270 if (mp->b_cont == NULL) 5271 return (IOC_INVAL); 5272 flashrwp = (void *)mp->b_cont->b_rptr; 5273 5274 /* 5275 * Validate request parameters ... 5276 */ 5277 if (flashrwp->flash_addr & ~NVM_FLASH_ADDR_MASK) 5278 return (IOC_INVAL); 5279 5280 switch (cmd) { 5281 default: 5282 /* NOTREACHED */ 5283 bge_error(bgep, "bge_flash_ioctl: invalid cmd 0x%x", cmd); 5284 return (IOC_INVAL); 5285 5286 case BGE_FLASH_READ: 5287 case BGE_FLASH_WRITE: 5288 iocp->ioc_error = bge_nvmem_rw32(bgep, cmd, 5289 flashrwp->flash_addr, &flashrwp->flash_data); 5290 return (IOC_REPLY); 5291 } 5292 5293 /* NOTREACHED */ 5294 } 5295 5296 #endif /* BGE_FLASH_IO32 */ 5297 5298 enum ioc_reply bge_chip_ioctl(bge_t *bgep, queue_t *wq, mblk_t *mp, 5299 struct iocblk *iocp); 5300 #pragma no_inline(bge_chip_ioctl) 5301 5302 enum ioc_reply 5303 bge_chip_ioctl(bge_t *bgep, queue_t *wq, mblk_t *mp, struct iocblk *iocp) 5304 { 5305 int cmd; 5306 5307 BGE_TRACE(("bge_chip_ioctl($%p, $%p, $%p, $%p)", 5308 (void *)bgep, (void *)wq, (void *)mp, (void *)iocp)); 5309 5310 ASSERT(mutex_owned(bgep->genlock)); 5311 5312 cmd = iocp->ioc_cmd; 5313 switch (cmd) { 5314 default: 5315 /* NOTREACHED */ 5316 bge_error(bgep, "bge_chip_ioctl: invalid cmd 0x%x", cmd); 5317 return (IOC_INVAL); 5318 5319 case BGE_DIAG: 5320 case BGE_PEEK: 5321 case BGE_POKE: 5322 case BGE_PHY_RESET: 5323 case BGE_SOFT_RESET: 5324 case BGE_HARD_RESET: 5325 #if BGE_DEBUGGING || BGE_DO_PPIO 5326 return (bge_diag_ioctl(bgep, cmd, mp, iocp)); 5327 #else 5328 return (IOC_INVAL); 5329 #endif /* BGE_DEBUGGING || BGE_DO_PPIO */ 5330 5331 case BGE_MII_READ: 5332 case BGE_MII_WRITE: 5333 return (bge_mii_ioctl(bgep, cmd, mp, iocp)); 5334 5335 #if BGE_SEE_IO32 5336 case BGE_SEE_READ: 5337 case BGE_SEE_WRITE: 5338 return (bge_see_ioctl(bgep, cmd, mp, iocp)); 5339 #endif /* BGE_SEE_IO32 */ 5340 5341 #if BGE_FLASH_IO32 5342 case BGE_FLASH_READ: 5343 case BGE_FLASH_WRITE: 5344 return (bge_flash_ioctl(bgep, cmd, mp, iocp)); 5345 #endif /* BGE_FLASH_IO32 */ 5346 } 5347 5348 /* NOTREACHED */ 5349 } 5350 5351 void 5352 bge_chip_blank(void *arg, time_t ticks, uint_t count) 5353 { 5354 bge_t *bgep = arg; 5355 5356 mutex_enter(bgep->genlock); 5357 bge_reg_put32(bgep, RCV_COALESCE_TICKS_REG, ticks); 5358 bge_reg_put32(bgep, RCV_COALESCE_MAX_BD_REG, count); 5359 if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) 5360 ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_UNAFFECTED); 5361 mutex_exit(bgep->genlock); 5362 } 5363 5364 #ifdef BGE_IPMI_ASF 5365 5366 uint32_t 5367 bge_nic_read32(bge_t *bgep, bge_regno_t addr) 5368 { 5369 uint32_t data; 5370 5371 #ifndef __sparc 5372 if (!bgep->asf_wordswapped) { 5373 /* a workaround word swap error */ 5374 if (addr & 4) 5375 addr = addr - 4; 5376 else 5377 addr = addr + 4; 5378 } 5379 #endif 5380 5381 pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_MWBAR, addr); 5382 data = pci_config_get32(bgep->cfg_handle, PCI_CONF_BGE_MWDAR); 5383 pci_config_put32(bgep->cfg_handle, PCI_CONF_BGE_MWBAR, 0); 5384 5385 data = LE_32(data); 5386 return (data); 5387 } 5388 5389 void 5390 bge_asf_update_status(bge_t *bgep) 5391 { 5392 uint32_t event; 5393 5394 bge_nic_put32(bgep, BGE_CMD_MAILBOX, BGE_CMD_NICDRV_ALIVE); 5395 bge_nic_put32(bgep, BGE_CMD_LENGTH_MAILBOX, 4); 5396 bge_nic_put32(bgep, BGE_CMD_DATA_MAILBOX, 3); 5397 5398 event = bge_reg_get32(bgep, RX_RISC_EVENT_REG); 5399 bge_reg_put32(bgep, RX_RISC_EVENT_REG, event | RRER_ASF_EVENT); 5400 } 5401 5402 5403 /* 5404 * The driver is supposed to notify ASF that the OS is still running 5405 * every three seconds, otherwise the management server may attempt 5406 * to reboot the machine. If it hasn't actually failed, this is 5407 * not a desirable result. However, this isn't running as a real-time 5408 * thread, and even if it were, it might not be able to generate the 5409 * heartbeat in a timely manner due to system load. As it isn't a 5410 * significant strain on the machine, we will set the interval to half 5411 * of the required value. 5412 */ 5413 void 5414 bge_asf_heartbeat(void *arg) 5415 { 5416 bge_t *bgep = (bge_t *)arg; 5417 5418 mutex_enter(bgep->genlock); 5419 bge_asf_update_status((bge_t *)bgep); 5420 if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) 5421 ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_DEGRADED); 5422 if (bge_check_acc_handle(bgep, bgep->cfg_handle) != DDI_FM_OK) 5423 ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_DEGRADED); 5424 mutex_exit(bgep->genlock); 5425 ((bge_t *)bgep)->asf_timeout_id = timeout(bge_asf_heartbeat, bgep, 5426 drv_usectohz(BGE_ASF_HEARTBEAT_INTERVAL)); 5427 } 5428 5429 5430 void 5431 bge_asf_stop_timer(bge_t *bgep) 5432 { 5433 timeout_id_t tmp_id = 0; 5434 5435 while ((bgep->asf_timeout_id != 0) && 5436 (tmp_id != bgep->asf_timeout_id)) { 5437 tmp_id = bgep->asf_timeout_id; 5438 (void) untimeout(tmp_id); 5439 } 5440 bgep->asf_timeout_id = 0; 5441 } 5442 5443 5444 5445 /* 5446 * This function should be placed at the earliest position of bge_attach(). 5447 */ 5448 void 5449 bge_asf_get_config(bge_t *bgep) 5450 { 5451 uint32_t nicsig; 5452 uint32_t niccfg; 5453 5454 bgep->asf_enabled = B_FALSE; 5455 nicsig = bge_nic_read32(bgep, BGE_NIC_DATA_SIG_ADDR); 5456 if (nicsig == BGE_NIC_DATA_SIG) { 5457 niccfg = bge_nic_read32(bgep, BGE_NIC_DATA_NIC_CFG_ADDR); 5458 if (niccfg & BGE_NIC_CFG_ENABLE_ASF) 5459 /* 5460 * Here, we don't consider BAXTER, because BGE haven't 5461 * supported BAXTER (that is 5752). Also, as I know, 5462 * BAXTER doesn't support ASF feature. 5463 */ 5464 bgep->asf_enabled = B_TRUE; 5465 else 5466 bgep->asf_enabled = B_FALSE; 5467 } else 5468 bgep->asf_enabled = B_FALSE; 5469 } 5470 5471 5472 void 5473 bge_asf_pre_reset_operations(bge_t *bgep, uint32_t mode) 5474 { 5475 uint32_t tries; 5476 uint32_t event; 5477 5478 ASSERT(bgep->asf_enabled); 5479 5480 /* Issues "pause firmware" command and wait for ACK */ 5481 bge_nic_put32(bgep, BGE_CMD_MAILBOX, BGE_CMD_NICDRV_PAUSE_FW); 5482 event = bge_reg_get32(bgep, RX_RISC_EVENT_REG); 5483 bge_reg_put32(bgep, RX_RISC_EVENT_REG, event | RRER_ASF_EVENT); 5484 5485 event = bge_reg_get32(bgep, RX_RISC_EVENT_REG); 5486 tries = 0; 5487 while ((event & RRER_ASF_EVENT) && (tries < 100)) { 5488 drv_usecwait(1); 5489 tries ++; 5490 event = bge_reg_get32(bgep, RX_RISC_EVENT_REG); 5491 } 5492 5493 bge_nic_put32(bgep, BGE_FIRMWARE_MAILBOX, 5494 BGE_MAGIC_NUM_FIRMWARE_INIT_DONE); 5495 5496 if (bgep->asf_newhandshake) { 5497 switch (mode) { 5498 case BGE_INIT_RESET: 5499 bge_nic_put32(bgep, BGE_DRV_STATE_MAILBOX, 5500 BGE_DRV_STATE_START); 5501 break; 5502 case BGE_SHUTDOWN_RESET: 5503 bge_nic_put32(bgep, BGE_DRV_STATE_MAILBOX, 5504 BGE_DRV_STATE_UNLOAD); 5505 break; 5506 case BGE_SUSPEND_RESET: 5507 bge_nic_put32(bgep, BGE_DRV_STATE_MAILBOX, 5508 BGE_DRV_STATE_SUSPEND); 5509 break; 5510 default: 5511 break; 5512 } 5513 } 5514 } 5515 5516 5517 void 5518 bge_asf_post_reset_old_mode(bge_t *bgep, uint32_t mode) 5519 { 5520 switch (mode) { 5521 case BGE_INIT_RESET: 5522 bge_nic_put32(bgep, BGE_DRV_STATE_MAILBOX, 5523 BGE_DRV_STATE_START); 5524 break; 5525 case BGE_SHUTDOWN_RESET: 5526 bge_nic_put32(bgep, BGE_DRV_STATE_MAILBOX, 5527 BGE_DRV_STATE_UNLOAD); 5528 break; 5529 case BGE_SUSPEND_RESET: 5530 bge_nic_put32(bgep, BGE_DRV_STATE_MAILBOX, 5531 BGE_DRV_STATE_SUSPEND); 5532 break; 5533 default: 5534 break; 5535 } 5536 } 5537 5538 5539 void 5540 bge_asf_post_reset_new_mode(bge_t *bgep, uint32_t mode) 5541 { 5542 switch (mode) { 5543 case BGE_INIT_RESET: 5544 bge_nic_put32(bgep, BGE_DRV_STATE_MAILBOX, 5545 BGE_DRV_STATE_START_DONE); 5546 break; 5547 case BGE_SHUTDOWN_RESET: 5548 bge_nic_put32(bgep, BGE_DRV_STATE_MAILBOX, 5549 BGE_DRV_STATE_UNLOAD_DONE); 5550 break; 5551 default: 5552 break; 5553 } 5554 } 5555 5556 #endif /* BGE_IPMI_ASF */ 5557