1 /* $NetBSD: if_tlp_pci.c,v 1.20 1999/09/30 17:48:25 thorpej Exp $ */ 2 3 /*- 4 * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 9 * NASA Ames Research Center. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. All advertising materials mentioning features or use of this software 20 * must display the following acknowledgement: 21 * This product includes software developed by the NetBSD 22 * Foundation, Inc. and its contributors. 23 * 4. Neither the name of The NetBSD Foundation nor the names of its 24 * contributors may be used to endorse or promote products derived 25 * from this software without specific prior written permission. 26 * 27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37 * POSSIBILITY OF SUCH DAMAGE. 38 */ 39 40 /* 41 * PCI bus front-end for the Digital Semiconductor ``Tulip'' (21x4x) 42 * Ethernet controller family driver. 43 */ 44 45 #include "opt_inet.h" 46 #include "opt_ns.h" 47 #include "bpfilter.h" 48 49 #include <sys/param.h> 50 #include <sys/systm.h> 51 #include <sys/mbuf.h> 52 #include <sys/malloc.h> 53 #include <sys/kernel.h> 54 #include <sys/socket.h> 55 #include <sys/ioctl.h> 56 #include <sys/errno.h> 57 #include <sys/device.h> 58 59 #include <net/if.h> 60 #include <net/if_dl.h> 61 #include <net/if_media.h> 62 #include <net/if_ether.h> 63 64 #if NBPFILTER > 0 65 #include <net/bpf.h> 66 #endif 67 68 #ifdef INET 69 #include <netinet/in.h> 70 #include <netinet/if_inarp.h> 71 #endif 72 73 #ifdef NS 74 #include <netns/ns.h> 75 #include <netns/ns_if.h> 76 #endif 77 78 #include <machine/bus.h> 79 #include <machine/intr.h> 80 81 #include <dev/mii/miivar.h> 82 83 #include <dev/ic/tulipreg.h> 84 #include <dev/ic/tulipvar.h> 85 86 #include <dev/pci/pcivar.h> 87 #include <dev/pci/pcireg.h> 88 #include <dev/pci/pcidevs.h> 89 90 /* 91 * PCI configuration space registers used by the Tulip. 92 */ 93 #define TULIP_PCI_IOBA 0x10 /* i/o mapped base */ 94 #define TULIP_PCI_MMBA 0x14 /* memory mapped base */ 95 #define TULIP_PCI_CFDA 0x40 /* configuration driver area */ 96 97 #define CFDA_SLEEP 0x80000000 /* sleep mode */ 98 99 struct tulip_pci_softc { 100 struct tulip_softc sc_tulip; /* real Tulip softc */ 101 102 /* PCI-specific goo. */ 103 void *sc_ih; /* interrupt handle */ 104 105 pci_chipset_tag_t sc_pc; /* our PCI chipset */ 106 pcitag_t sc_pcitag; /* our PCI tag */ 107 108 int sc_flags; /* flags; see below */ 109 110 LIST_HEAD(, tulip_pci_softc) sc_intrslaves; 111 LIST_ENTRY(tulip_pci_softc) sc_intrq; 112 113 /* Our {ROM,interrupt} master. */ 114 struct tulip_pci_softc *sc_master; 115 }; 116 117 /* sc_flags */ 118 #define TULIP_PCI_SHAREDINTR 0x01 /* interrupt is shared */ 119 #define TULIP_PCI_SLAVEINTR 0x02 /* interrupt is slave */ 120 #define TULIP_PCI_SHAREDROM 0x04 /* ROM is shared */ 121 #define TULIP_PCI_SLAVEROM 0x08 /* slave of shared ROM */ 122 123 int tlp_pci_match __P((struct device *, struct cfdata *, void *)); 124 void tlp_pci_attach __P((struct device *, struct device *, void *)); 125 126 struct cfattach tlp_pci_ca = { 127 sizeof(struct tulip_pci_softc), tlp_pci_match, tlp_pci_attach, 128 }; 129 130 const struct tulip_pci_product { 131 u_int32_t tpp_vendor; /* PCI vendor ID */ 132 u_int32_t tpp_product; /* PCI product ID */ 133 tulip_chip_t tpp_chip; /* base Tulip chip type */ 134 int tpp_pmreg; /* power management register offset */ 135 } tlp_pci_products[] = { 136 #ifdef TLP_MATCH_21040 137 { PCI_VENDOR_DEC, PCI_PRODUCT_DEC_21040, 138 TULIP_CHIP_21040, 0 }, 139 #endif 140 #ifdef TLP_MATCH_21041 141 { PCI_VENDOR_DEC, PCI_PRODUCT_DEC_21041, 142 TULIP_CHIP_21041, 0 }, 143 #endif 144 #ifdef TLP_MATCH_21140 145 { PCI_VENDOR_DEC, PCI_PRODUCT_DEC_21140, 146 TULIP_CHIP_21140, 0 }, 147 #endif 148 #ifdef TLP_MATCH_21142 149 { PCI_VENDOR_DEC, PCI_PRODUCT_DEC_21142, 150 TULIP_CHIP_21142, 0 }, 151 #endif 152 153 { PCI_VENDOR_LITEON, PCI_PRODUCT_LITEON_82C168, 154 TULIP_CHIP_82C168, 0 }, 155 156 /* 157 * Note: This is like a MX98725 with Wake-On-LAN and a 158 * 128-bit multicast hash table. 159 */ 160 { PCI_VENDOR_LITEON, PCI_PRODUCT_LITEON_82C115, 161 TULIP_CHIP_82C115, 0x48 }, 162 163 { PCI_VENDOR_MACRONIX, PCI_PRODUCT_MACRONIX_MX98713, 164 TULIP_CHIP_MX98713, 0 }, 165 { PCI_VENDOR_MACRONIX, PCI_PRODUCT_MACRONIX_MX987x5, 166 TULIP_CHIP_MX98715, 0x48 }, 167 168 { PCI_VENDOR_COMPEX, PCI_PRODUCT_COMPEX_RL100TX, 169 TULIP_CHIP_MX98713, 0 }, 170 171 { PCI_VENDOR_WINBOND, PCI_PRODUCT_WINBOND_W89C840F, 172 TULIP_CHIP_WB89C840F, 0 }, 173 { PCI_VENDOR_COMPEX, PCI_PRODUCT_COMPEX_RL100ATX, 174 TULIP_CHIP_WB89C840F, 0 }, 175 176 #if 0 177 { PCI_VENDOR_DAVICOM, PCI_PRODUCT_DAVICOM_DM9102, 178 TULIP_CHIP_DM9102, 0 }, 179 #endif 180 181 { PCI_VENDOR_ADMTEK, PCI_PRODUCT_ADMTEK_AL981, 182 TULIP_CHIP_AL981, 0xc4 }, 183 184 #if 0 185 { PCI_VENDOR_ASIX, PCI_PRODUCT_ASIX_AX88140A, 186 TULIP_CHIP_AX88140, 0 }, 187 #endif 188 189 { 0, 0, 190 TULIP_CHIP_INVALID, 0 }, 191 }; 192 193 struct tlp_pci_quirks { 194 void (*tpq_func) __P((struct tulip_pci_softc *, 195 const u_int8_t *)); 196 u_int8_t tpq_oui[3]; 197 }; 198 199 void tlp_pci_dec_quirks __P((struct tulip_pci_softc *, 200 const u_int8_t *)); 201 202 void tlp_pci_znyx_21040_quirks __P((struct tulip_pci_softc *, 203 const u_int8_t *)); 204 void tlp_pci_smc_21040_quirks __P((struct tulip_pci_softc *, 205 const u_int8_t *)); 206 void tlp_pci_cogent_21040_quirks __P((struct tulip_pci_softc *, 207 const u_int8_t *)); 208 void tlp_pci_accton_21040_quirks __P((struct tulip_pci_softc *, 209 const u_int8_t *)); 210 211 const struct tlp_pci_quirks tlp_pci_21040_quirks[] = { 212 { tlp_pci_znyx_21040_quirks, { 0x00, 0xc0, 0x95 } }, 213 { tlp_pci_smc_21040_quirks, { 0x00, 0x00, 0xc0 } }, 214 { tlp_pci_cogent_21040_quirks, { 0x00, 0x00, 0x92 } }, 215 { tlp_pci_accton_21040_quirks, { 0x00, 0x00, 0xe8 } }, 216 { NULL, { 0, 0, 0 } } 217 }; 218 219 const struct tlp_pci_quirks tlp_pci_21041_quirks[] = { 220 { tlp_pci_dec_quirks, { 0x08, 0x00, 0x2b } }, 221 { tlp_pci_dec_quirks, { 0x00, 0x00, 0xf8 } }, 222 { NULL, { 0, 0, 0 } } 223 }; 224 225 void tlp_pci_asante_21140_quirks __P((struct tulip_pci_softc *, 226 const u_int8_t *)); 227 228 const struct tlp_pci_quirks tlp_pci_21140_quirks[] = { 229 { tlp_pci_dec_quirks, { 0x08, 0x00, 0x2b } }, 230 { tlp_pci_dec_quirks, { 0x00, 0x00, 0xf8 } }, 231 { tlp_pci_asante_21140_quirks, { 0x00, 0x00, 0x94 } }, 232 { NULL, { 0, 0, 0 } } 233 }; 234 235 const char *tlp_pci_chip_names[] = TULIP_CHIP_NAMES; 236 237 int tlp_pci_shared_intr __P((void *)); 238 239 const struct tulip_pci_product *tlp_pci_lookup 240 __P((const struct pci_attach_args *)); 241 void tlp_pci_get_quirks __P((struct tulip_pci_softc *, const u_int8_t *, 242 const struct tlp_pci_quirks *)); 243 void tlp_pci_check_slaved __P((struct tulip_pci_softc *, int, int)); 244 245 const struct tulip_pci_product * 246 tlp_pci_lookup(pa) 247 const struct pci_attach_args *pa; 248 { 249 const struct tulip_pci_product *tpp; 250 251 for (tpp = tlp_pci_products; 252 tlp_pci_chip_names[tpp->tpp_chip] != NULL; 253 tpp++) { 254 if (PCI_VENDOR(pa->pa_id) == tpp->tpp_vendor && 255 PCI_PRODUCT(pa->pa_id) == tpp->tpp_product) 256 return (tpp); 257 } 258 return (NULL); 259 } 260 261 void 262 tlp_pci_get_quirks(psc, enaddr, tpq) 263 struct tulip_pci_softc *psc; 264 const u_int8_t *enaddr; 265 const struct tlp_pci_quirks *tpq; 266 { 267 268 for (; tpq->tpq_func != NULL; tpq++) { 269 if (tpq->tpq_oui[0] == enaddr[0] && 270 tpq->tpq_oui[1] == enaddr[1] && 271 tpq->tpq_oui[2] == enaddr[2]) { 272 (*tpq->tpq_func)(psc, enaddr); 273 return; 274 } 275 } 276 } 277 278 void 279 tlp_pci_check_slaved(psc, shared, slaved) 280 struct tulip_pci_softc *psc; 281 int shared, slaved; 282 { 283 extern struct cfdriver tlp_cd; 284 struct tulip_pci_softc *cur, *best = NULL; 285 struct tulip_softc *sc = &psc->sc_tulip; 286 int i; 287 288 /* 289 * First of all, find the lowest pcidev numbered device on our 290 * bus marked as shared. That should be our master. 291 */ 292 for (i = 0; i < tlp_cd.cd_ndevs; i++) { 293 if ((cur = tlp_cd.cd_devs[i]) == NULL) 294 continue; 295 if (cur->sc_tulip.sc_dev.dv_parent != sc->sc_dev.dv_parent) 296 continue; 297 if ((cur->sc_flags & shared) == 0) 298 continue; 299 if (cur == psc) 300 continue; 301 if (best == NULL || 302 best->sc_tulip.sc_devno > cur->sc_tulip.sc_devno) 303 best = cur; 304 } 305 306 if (best != NULL) { 307 psc->sc_master = best; 308 psc->sc_flags |= (shared | slaved); 309 } 310 } 311 312 int 313 tlp_pci_match(parent, match, aux) 314 struct device *parent; 315 struct cfdata *match; 316 void *aux; 317 { 318 struct pci_attach_args *pa = aux; 319 320 if (tlp_pci_lookup(pa) != NULL) 321 return (10); /* beat if_de.c */ 322 323 return (0); 324 } 325 326 void 327 tlp_pci_attach(parent, self, aux) 328 struct device *parent, *self; 329 void *aux; 330 { 331 struct tulip_pci_softc *psc = (void *) self; 332 struct tulip_softc *sc = &psc->sc_tulip; 333 struct pci_attach_args *pa = aux; 334 pci_chipset_tag_t pc = pa->pa_pc; 335 pci_intr_handle_t ih; 336 const char *intrstr = NULL; 337 bus_space_tag_t iot, memt; 338 bus_space_handle_t ioh, memh; 339 int ioh_valid, memh_valid, i, j; 340 const struct tulip_pci_product *tpp; 341 u_int8_t enaddr[ETHER_ADDR_LEN]; 342 u_int32_t val; 343 pcireg_t reg; 344 345 sc->sc_devno = pa->pa_device; 346 psc->sc_pc = pa->pa_pc; 347 psc->sc_pcitag = pa->pa_tag; 348 349 LIST_INIT(&psc->sc_intrslaves); 350 351 tpp = tlp_pci_lookup(pa); 352 if (tpp == NULL) { 353 printf("\n"); 354 panic("tlp_pci_attach: impossible"); 355 } 356 sc->sc_chip = tpp->tpp_chip; 357 358 /* 359 * By default, Tulip registers are 8 bytes long (4 bytes 360 * followed by a 4 byte pad). 361 */ 362 sc->sc_regshift = 3; 363 364 /* 365 * Get revision info, and set some chip-specific variables. 366 */ 367 sc->sc_rev = PCI_REVISION(pa->pa_class); 368 switch (sc->sc_chip) { 369 case TULIP_CHIP_21140: 370 if (sc->sc_rev >= 0x20) 371 sc->sc_chip = TULIP_CHIP_21140A; 372 break; 373 374 case TULIP_CHIP_21142: 375 if (sc->sc_rev >= 0x20) 376 sc->sc_chip = TULIP_CHIP_21143; 377 break; 378 379 case TULIP_CHIP_82C168: 380 if (sc->sc_rev >= 0x20) 381 sc->sc_chip = TULIP_CHIP_82C169; 382 break; 383 384 case TULIP_CHIP_MX98713: 385 if (sc->sc_rev >= 0x10) 386 sc->sc_chip = TULIP_CHIP_MX98713A; 387 break; 388 389 case TULIP_CHIP_MX98715: 390 if (sc->sc_rev >= 0x20) 391 sc->sc_chip = TULIP_CHIP_MX98715A; 392 if (sc->sc_rev >= 0x30) 393 sc->sc_chip = TULIP_CHIP_MX98725; 394 break; 395 396 case TULIP_CHIP_WB89C840F: 397 sc->sc_regshift = 2; 398 break; 399 400 case TULIP_CHIP_AX88140: 401 if (sc->sc_rev >= 0x10) 402 sc->sc_chip = TULIP_CHIP_AX88141; 403 break; 404 405 default: 406 /* Nothing. */ 407 } 408 409 printf(": %s Ethernet, pass %d.%d\n", 410 tlp_pci_chip_names[sc->sc_chip], 411 (sc->sc_rev >> 4) & 0xf, sc->sc_rev & 0xf); 412 413 switch (sc->sc_chip) { 414 case TULIP_CHIP_21040: 415 if (sc->sc_rev < 0x20) { 416 printf("%s: 21040 must be at least pass 2.0\n", 417 sc->sc_dev.dv_xname); 418 return; 419 } 420 break; 421 422 case TULIP_CHIP_21140: 423 if (sc->sc_rev < 0x11) { 424 printf("%s: 21140 must be at least pass 1.1\n", 425 sc->sc_dev.dv_xname); 426 return; 427 } 428 break; 429 430 default: 431 /* Nothing. */ 432 } 433 434 /* 435 * Check to see if the device is in power-save mode, and 436 * being it out if necessary. 437 */ 438 switch (sc->sc_chip) { 439 case TULIP_CHIP_21140: 440 case TULIP_CHIP_21140A: 441 case TULIP_CHIP_MX98713A: 442 case TULIP_CHIP_MX98715: 443 case TULIP_CHIP_MX98715A: 444 case TULIP_CHIP_MX98725: 445 /* 446 * Clear the "sleep mode" bit in the CFDA register. 447 */ 448 reg = pci_conf_read(pc, pa->pa_tag, TULIP_PCI_CFDA); 449 if (reg & CFDA_SLEEP) 450 pci_conf_write(pc, pa->pa_tag, TULIP_PCI_CFDA, 451 reg & ~CFDA_SLEEP); 452 break; 453 454 default: 455 /* Nothing. */ 456 } 457 458 if (pci_get_capability(pc, pa->pa_tag, PCI_CAP_PWRMGMT, 0, 0)) { 459 if (tpp->tpp_pmreg == 0) { 460 printf("%s: don't know location of PMCSR for this " 461 "chip\n", sc->sc_dev.dv_xname); 462 return; 463 } 464 reg = pci_conf_read(pc, pa->pa_tag, tpp->tpp_pmreg) & 0x3; 465 if (reg == 3) { 466 /* 467 * The card has lost all configuration data in 468 * this state, so punt. 469 */ 470 printf("%s: unable to wake up from power state D3\n", 471 sc->sc_dev.dv_xname); 472 return; 473 } 474 if (reg != 0) { 475 printf("%s: waking up from power state D%d\n", 476 sc->sc_dev.dv_xname, reg); 477 pci_conf_write(pc, pa->pa_tag, tpp->tpp_pmreg, 0); 478 } 479 } 480 481 /* 482 * Map the device. 483 */ 484 ioh_valid = (pci_mapreg_map(pa, TULIP_PCI_IOBA, 485 PCI_MAPREG_TYPE_IO, 0, 486 &iot, &ioh, NULL, NULL) == 0); 487 memh_valid = (pci_mapreg_map(pa, TULIP_PCI_MMBA, 488 PCI_MAPREG_TYPE_MEM|PCI_MAPREG_MEM_TYPE_32BIT, 0, 489 &memt, &memh, NULL, NULL) == 0); 490 491 if (memh_valid) { 492 sc->sc_st = memt; 493 sc->sc_sh = memh; 494 } else if (ioh_valid) { 495 sc->sc_st = iot; 496 sc->sc_sh = ioh; 497 } else { 498 printf(": unable to map device registers\n"); 499 return; 500 } 501 502 sc->sc_dmat = pa->pa_dmat; 503 504 /* 505 * Make sure bus mastering is enabled. 506 */ 507 pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, 508 pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) | 509 PCI_COMMAND_MASTER_ENABLE); 510 511 /* 512 * Get the cacheline size. 513 */ 514 sc->sc_cacheline = PCI_CACHELINE(pci_conf_read(pc, pa->pa_tag, 515 PCI_BHLC_REG)); 516 517 /* 518 * Read the contents of the Ethernet Address ROM/SROM. 519 */ 520 memset(sc->sc_srom, 0, sizeof(sc->sc_srom)); 521 switch (sc->sc_chip) { 522 case TULIP_CHIP_21040: 523 TULIP_WRITE(sc, CSR_MIIROM, MIIROM_SROMCS); 524 for (i = 0; i < sizeof(sc->sc_srom); i++) { 525 for (j = 0; j < 10000; j++) { 526 val = TULIP_READ(sc, CSR_MIIROM); 527 if ((val & MIIROM_DN) == 0) 528 break; 529 } 530 sc->sc_srom[i] = val & MIIROM_DATA; 531 } 532 break; 533 534 case TULIP_CHIP_82C168: 535 case TULIP_CHIP_82C169: 536 { 537 u_int16_t *rombuf = (u_int16_t *)sc->sc_srom; 538 539 /* 540 * The Lite-On PNIC stores the Ethernet address in 541 * the first 3 words of the EEPROM. EEPROM access 542 * is not like the other Tulip chips. 543 */ 544 for (i = 0; i < 3; i++) { 545 TULIP_WRITE(sc, CSR_PNIC_SROMCTL, 546 PNIC_SROMCTL_READ | i); 547 for (j = 0; j < 500; j++) { 548 delay(2); 549 val = TULIP_READ(sc, CSR_MIIROM); 550 if ((val & PNIC_MIIROM_BUSY) == 0) 551 break; 552 } 553 if (val & PNIC_MIIROM_BUSY) { 554 printf("%s: EEPROM timed out\n", 555 sc->sc_dev.dv_xname); 556 return; 557 } 558 rombuf[i] = bswap16(val & PNIC_MIIROM_DATA); 559 } 560 break; 561 } 562 563 default: 564 tlp_read_srom(sc, 0, sizeof(sc->sc_srom) >> 1, sc->sc_srom); 565 #if 0 566 printf("SROM CONTENTS:"); 567 for (i = 0; i < sizeof(sc->sc_srom); i++) { 568 if ((i % 8) == 0) 569 printf("\n\t"); 570 printf("0x%02x ", sc->sc_srom[i]); 571 } 572 printf("\n"); 573 #endif 574 } 575 576 /* 577 * Deal with chip/board quirks. This includes setting up 578 * the mediasw, and extracting the Ethernet address from 579 * the rombuf. 580 */ 581 switch (sc->sc_chip) { 582 case TULIP_CHIP_21040: 583 /* Check for a slaved ROM on a multi-port board. */ 584 tlp_pci_check_slaved(psc, TULIP_PCI_SHAREDROM, 585 TULIP_PCI_SLAVEROM); 586 if (psc->sc_flags & TULIP_PCI_SLAVEROM) 587 memcpy(sc->sc_srom, psc->sc_master->sc_tulip.sc_srom, 588 sizeof(sc->sc_srom)); 589 590 /* 591 * Parse the Ethernet Address ROM. 592 */ 593 if (tlp_parse_old_srom(sc, enaddr) == 0) { 594 printf("%s: unable to decode Ethernet Address ROM\n", 595 sc->sc_dev.dv_xname); 596 return; 597 } 598 599 /* 600 * If we have a slaved ROM, adjust the Ethernet address. 601 */ 602 if (psc->sc_flags & TULIP_PCI_SLAVEROM) 603 enaddr[5] += 604 sc->sc_devno - psc->sc_master->sc_tulip.sc_devno; 605 606 /* 607 * All 21040 boards start out with the same 608 * media switch. 609 */ 610 sc->sc_mediasw = &tlp_21040_mediasw; 611 612 /* 613 * Deal with any quirks this board might have. 614 */ 615 tlp_pci_get_quirks(psc, enaddr, tlp_pci_21040_quirks); 616 break; 617 618 case TULIP_CHIP_21041: 619 /* Check for a slaved ROM on a multi-port board. */ 620 tlp_pci_check_slaved(psc, TULIP_PCI_SHAREDROM, 621 TULIP_PCI_SLAVEROM); 622 if (psc->sc_flags & TULIP_PCI_SLAVEROM) 623 memcpy(sc->sc_srom, psc->sc_master->sc_tulip.sc_srom, 624 sizeof(sc->sc_srom)); 625 626 /* Check for new format SROM. */ 627 if (tlp_isv_srom_enaddr(sc, enaddr) == 0) { 628 /* 629 * Not an ISV SROM; try the old DEC Ethernet Address 630 * ROM format. 631 */ 632 if (tlp_parse_old_srom(sc, enaddr) == 0) { 633 printf("%s: unable to decode Ethernet " 634 "Address ROM\n", sc->sc_dev.dv_xname); 635 return; 636 } 637 } 638 639 /* 640 * All 21041 boards use the same media switch; they all 641 * work basically the same! Yippee! 642 */ 643 sc->sc_mediasw = &tlp_21041_mediasw; 644 645 /* 646 * Deal with any quirks this board might have. 647 */ 648 tlp_pci_get_quirks(psc, enaddr, tlp_pci_21041_quirks); 649 break; 650 651 case TULIP_CHIP_21140: 652 case TULIP_CHIP_21140A: 653 /* Check for new format SROM. */ 654 if (tlp_isv_srom_enaddr(sc, enaddr) == 0) { 655 /* 656 * Not an ISV SROM; try the old DEC Ethernet Address 657 * ROM format. 658 */ 659 if (tlp_parse_old_srom(sc, enaddr) == 0) { 660 printf("%s: unable to decode Ethernet " 661 "Address ROM\n", sc->sc_dev.dv_xname); 662 return; 663 } 664 } else { 665 /* 666 * We start out with the 2114x ISV media switch. 667 * When we search for quirks, we may change to 668 * a different switch. 669 */ 670 sc->sc_mediasw = &tlp_2114x_isv_mediasw; 671 } 672 673 /* 674 * Deal with any quirks this board might have. 675 */ 676 tlp_pci_get_quirks(psc, enaddr, tlp_pci_21140_quirks); 677 678 /* 679 * Bail out now if we can't deal with this board. 680 */ 681 if (sc->sc_mediasw == NULL) 682 goto cant_cope; 683 break; 684 685 case TULIP_CHIP_82C168: 686 case TULIP_CHIP_82C169: 687 /* 688 * Lite-On PNIC's Ethernet address is the first 6 689 * bytes of its EEPROM. 690 */ 691 memcpy(enaddr, sc->sc_srom, ETHER_ADDR_LEN); 692 693 /* 694 * Lite-On PNICs always use the same mediasw; we 695 * select MII vs. internal NWAY automatically. 696 */ 697 sc->sc_mediasw = &tlp_pnic_mediasw; 698 break; 699 700 case TULIP_CHIP_MX98713: 701 /* 702 * The Macronix MX98713 has an MII and GPIO, but no 703 * internal Nway block. This chip is basically a 704 * perfect 21140A clone, with the exception of the 705 * a magic register frobbing in order to make the 706 * interface function. 707 */ 708 if (tlp_isv_srom_enaddr(sc, enaddr)) { 709 sc->sc_mediasw = &tlp_2114x_isv_mediasw; 710 break; 711 } 712 /* FALLTHROUGH */ 713 714 case TULIP_CHIP_82C115: 715 /* 716 * Yippee! The Lite-On 82C115 is a clone of 717 * the MX98725 (the data sheet even says `MXIC' 718 * on it)! Imagine that, a clone of a clone. 719 * 720 * The differences are really minimal: 721 * 722 * - Wake-On-LAN support 723 * - 128-bit multicast hash table, rather than 724 * the standard 512-bit hash table 725 */ 726 /* FALLTHROUGH */ 727 728 case TULIP_CHIP_MX98713A: 729 case TULIP_CHIP_MX98715A: 730 case TULIP_CHIP_MX98725: 731 /* 732 * The MX98713A has an MII as well as an internal Nway block, 733 * but no GPIO. The MX98715 and MX98725 have an internal 734 * Nway block only. 735 * 736 * The internal Nway block, unlike the Lite-On PNIC's, does 737 * just that - performs Nway. Once autonegotiation completes, 738 * we must program the GPR media information into the chip. 739 * 740 * The byte offset of the Ethernet address is stored at 741 * offset 0x70. 742 */ 743 memcpy(enaddr, &sc->sc_srom[sc->sc_srom[0x70]], ETHER_ADDR_LEN); 744 sc->sc_mediasw = &tlp_pmac_mediasw; 745 break; 746 747 case TULIP_CHIP_WB89C840F: 748 /* 749 * Winbond 89C840F's Ethernet address is the first 750 * 6 bytes of its EEPROM. 751 */ 752 memcpy(enaddr, sc->sc_srom, ETHER_ADDR_LEN); 753 754 /* 755 * Winbond 89C840F has an MII attached to the SIO. 756 */ 757 sc->sc_mediasw = &tlp_sio_mii_mediasw; 758 break; 759 760 case TULIP_CHIP_AL981: 761 /* 762 * The ADMtek AL981's Ethernet address is located 763 * at offset 8 of its EEPROM. 764 */ 765 memcpy(enaddr, &sc->sc_srom[8], ETHER_ADDR_LEN); 766 767 /* 768 * ADMtek AL981 has a built-in PHY accessed through 769 * special registers. 770 */ 771 sc->sc_mediasw = &tlp_al981_mediasw; 772 break; 773 774 default: 775 cant_cope: 776 printf("%s: sorry, unable to handle your board\n", 777 sc->sc_dev.dv_xname); 778 return; 779 } 780 781 /* 782 * Handle shared interrupts. 783 */ 784 if (psc->sc_flags & TULIP_PCI_SHAREDINTR) { 785 if (psc->sc_master) 786 psc->sc_flags |= TULIP_PCI_SLAVEINTR; 787 else { 788 tlp_pci_check_slaved(psc, TULIP_PCI_SHAREDINTR, 789 TULIP_PCI_SLAVEINTR); 790 if (psc->sc_master == NULL) 791 psc->sc_master = psc; 792 } 793 LIST_INSERT_HEAD(&psc->sc_master->sc_intrslaves, 794 psc, sc_intrq); 795 } 796 797 if (psc->sc_flags & TULIP_PCI_SLAVEINTR) { 798 printf("%s: sharing interrupt with %s\n", 799 sc->sc_dev.dv_xname, 800 psc->sc_master->sc_tulip.sc_dev.dv_xname); 801 } else { 802 /* 803 * Map and establish our interrupt. 804 */ 805 if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin, 806 pa->pa_intrline, &ih)) { 807 printf("%s: unable to map interrupt\n", 808 sc->sc_dev.dv_xname); 809 return; 810 } 811 intrstr = pci_intr_string(pc, ih); 812 psc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, 813 (psc->sc_flags & TULIP_PCI_SHAREDINTR) ? 814 tlp_pci_shared_intr : tlp_intr, sc); 815 if (psc->sc_ih == NULL) { 816 printf("%s: unable to establish interrupt", 817 sc->sc_dev.dv_xname); 818 if (intrstr != NULL) 819 printf(" at %s", intrstr); 820 printf("\n"); 821 return; 822 } 823 printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, 824 intrstr); 825 } 826 827 /* 828 * Finish off the attach. 829 */ 830 tlp_attach(sc, enaddr); 831 } 832 833 int 834 tlp_pci_shared_intr(arg) 835 void *arg; 836 { 837 struct tulip_pci_softc *master = arg, *slave; 838 int rv = 0; 839 840 for (slave = LIST_FIRST(&master->sc_intrslaves); 841 slave != NULL; 842 slave = LIST_NEXT(slave, sc_intrq)) 843 rv |= tlp_intr(&slave->sc_tulip); 844 845 return (rv); 846 } 847 848 void 849 tlp_pci_dec_quirks(psc, enaddr) 850 struct tulip_pci_softc *psc; 851 const u_int8_t *enaddr; 852 { 853 struct tulip_softc *sc = &psc->sc_tulip; 854 855 /* 856 * This isn't really a quirk-gathering device, really. We 857 * just want to get the spiffy DEC board name from the SROM. 858 */ 859 strcpy(sc->sc_name, "DEC "); 860 861 if (memcmp(&sc->sc_srom[29], "DE500", 5) == 0 || 862 memcmp(&sc->sc_srom[29], "DE450", 5) == 0) 863 memcpy(&sc->sc_name[4], &sc->sc_srom[29], 8); 864 } 865 866 void 867 tlp_pci_znyx_21040_quirks(psc, enaddr) 868 struct tulip_pci_softc *psc; 869 const u_int8_t *enaddr; 870 { 871 struct tulip_softc *sc = &psc->sc_tulip; 872 u_int16_t id = 0; 873 874 /* 875 * If we have a slaved ROM, just copy the bits from the master. 876 * This is in case we fail the ROM ID check (older boards) and 877 * need to fall back on Ethernet address model checking; that 878 * will fail for slave chips. 879 */ 880 if (psc->sc_flags & TULIP_PCI_SLAVEROM) { 881 strcpy(sc->sc_name, psc->sc_master->sc_tulip.sc_name); 882 sc->sc_mediasw = psc->sc_master->sc_tulip.sc_mediasw; 883 psc->sc_flags |= 884 psc->sc_master->sc_flags & TULIP_PCI_SHAREDINTR; 885 return; 886 } 887 888 if (sc->sc_srom[32] == 0x4a && sc->sc_srom[33] == 0x52) { 889 id = sc->sc_srom[37] | (sc->sc_srom[36] << 8); 890 switch (id) { 891 zx312: 892 case 0x0602: /* ZX312 */ 893 strcpy(sc->sc_name, "ZNYX ZX312"); 894 return; 895 896 case 0x0622: /* ZX312T */ 897 strcpy(sc->sc_name, "ZNYX ZX312T"); 898 sc->sc_mediasw = &tlp_21040_tp_mediasw; 899 return; 900 901 zx314_inta: 902 case 0x0701: /* ZX314 INTA */ 903 psc->sc_flags |= TULIP_PCI_SHAREDINTR; 904 /* FALLTHROUGH */ 905 case 0x0711: /* ZX314 */ 906 strcpy(sc->sc_name, "ZNYX ZX314"); 907 psc->sc_flags |= TULIP_PCI_SHAREDROM; 908 sc->sc_mediasw = &tlp_21040_tp_mediasw; 909 return; 910 911 zx315_inta: 912 case 0x0801: /* ZX315 INTA */ 913 psc->sc_flags |= TULIP_PCI_SHAREDINTR; 914 /* FALLTHROUGH */ 915 case 0x0811: /* ZX315 */ 916 strcpy(sc->sc_name, "ZNYX ZX315"); 917 psc->sc_flags |= TULIP_PCI_SHAREDROM; 918 return; 919 920 default: 921 id = 0; 922 } 923 } 924 925 /* 926 * Deal with boards that have broken ROMs. 927 */ 928 if (id == 0) { 929 if ((enaddr[3] & ~3) == 0xf0 && (enaddr[5] & 3) == 0x00) 930 goto zx314_inta; 931 if ((enaddr[3] & ~3) == 0xf4 && (enaddr[5] & 1) == 0x00) 932 goto zx315_inta; 933 if ((enaddr[3] & ~3) == 0xec) 934 goto zx312; 935 } 936 937 strcpy(sc->sc_name, "ZNYX ZX31x"); 938 } 939 940 void 941 tlp_pci_smc_21040_quirks(psc, enaddr) 942 struct tulip_pci_softc *psc; 943 const u_int8_t *enaddr; 944 { 945 struct tulip_softc *sc = &psc->sc_tulip; 946 u_int16_t id1, id2, ei; 947 int auibnc = 0, utp = 0; 948 char *cp; 949 950 id1 = sc->sc_srom[0x60] | (sc->sc_srom[0x61] << 8); 951 id2 = sc->sc_srom[0x62] | (sc->sc_srom[0x63] << 8); 952 ei = sc->sc_srom[0x66] | (sc->sc_srom[0x67] << 8); 953 954 strcpy(sc->sc_name, "SMC 8432"); 955 cp = &sc->sc_name[8]; 956 957 if ((id1 & 1) == 0) { 958 *cp++ = 'B'; 959 auibnc = 1; 960 } 961 if ((id1 & 0xff) > 0x32) { 962 *cp++ = 'T'; 963 utp = 1; 964 } 965 if ((id1 & 0x4000) == 0) { 966 *cp++ = 'A'; 967 auibnc = 1; 968 } 969 if (id2 == 0x15) { 970 sc->sc_name[7] = '4'; 971 *cp++ = '-'; 972 *cp++ = 'C'; 973 *cp++ = 'H'; 974 *cp++ = ei ? '2' : '1'; 975 } 976 *cp = '\0'; 977 978 if (utp != 0 && auibnc == 0) 979 sc->sc_mediasw = &tlp_21040_tp_mediasw; 980 else if (utp == 0 && auibnc != 0) 981 sc->sc_mediasw = &tlp_21040_auibnc_mediasw; 982 } 983 984 void 985 tlp_pci_cogent_21040_quirks(psc, enaddr) 986 struct tulip_pci_softc *psc; 987 const u_int8_t *enaddr; 988 { 989 990 strcpy(psc->sc_tulip.sc_name, "Cogent multi-port"); 991 psc->sc_flags |= TULIP_PCI_SHAREDINTR|TULIP_PCI_SHAREDROM; 992 } 993 994 void 995 tlp_pci_accton_21040_quirks(psc, enaddr) 996 struct tulip_pci_softc *psc; 997 const u_int8_t *enaddr; 998 { 999 1000 strcpy(psc->sc_tulip.sc_name, "ACCTON EN1203"); 1001 } 1002 1003 void tlp_pci_asante_21140_reset __P((struct tulip_softc *)); 1004 1005 void 1006 tlp_pci_asante_21140_quirks(psc, enaddr) 1007 struct tulip_pci_softc *psc; 1008 const u_int8_t *enaddr; 1009 { 1010 struct tulip_softc *sc = &psc->sc_tulip; 1011 1012 /* 1013 * Some Asante boards don't use the ISV SROM format. For 1014 * those that don't, we initialize the GPIO direction bits, 1015 * and provide our own reset hook, which resets the MII. 1016 * 1017 * All of these boards use SIO-attached-MII media. 1018 */ 1019 if (sc->sc_mediasw == &tlp_2114x_isv_mediasw) 1020 return; 1021 1022 strcpy(sc->sc_name, "Asante"); 1023 1024 sc->sc_gp_dir = 0xbf; 1025 sc->sc_reset = tlp_pci_asante_21140_reset; 1026 sc->sc_mediasw = &tlp_sio_mii_mediasw; 1027 } 1028 1029 void 1030 tlp_pci_asante_21140_reset(sc) 1031 struct tulip_softc *sc; 1032 { 1033 1034 TULIP_WRITE(sc, CSR_GPP, GPP_GPC | sc->sc_gp_dir); 1035 TULIP_WRITE(sc, CSR_GPP, 0x8); 1036 delay(100); 1037 TULIP_WRITE(sc, CSR_GPP, 0); 1038 } 1039