40 41#define TULIP_HDR_DATA 42 43#include <sys/param.h> 44#include <sys/systm.h> 45#include <sys/endian.h> 46#include <sys/mbuf.h> 47#include <sys/socket.h> 48#include <sys/sockio.h> 49#include <sys/malloc.h> 50#include <sys/kernel.h> 51#include <sys/module.h> 52#include <sys/eventhandler.h> 53#include <machine/bus.h> 54#include <machine/resource.h> 55#include <sys/bus.h> 56#include <sys/rman.h> 57 58#include <net/if.h> 59#include <net/if_arp.h> 60#include <net/ethernet.h> 61#include <net/if_media.h> 62#include <net/if_dl.h> 63#ifdef TULIP_USE_SOFTINTR 64#include <net/netisr.h> 65#endif 66 67#include <net/bpf.h> 68 69#ifdef INET 70#include <netinet/in.h> 71#include <netinet/if_ether.h> 72#endif 73 74#include <vm/vm.h> 75 76#include <net/if_var.h> 77#include <vm/pmap.h> 78#include <dev/pci/pcivar.h> 79#include <dev/pci/pcireg.h> 80#include <pci/dc21040reg.h> 81 82/* 83 * Intel CPUs should use I/O mapped access. 84 */ 85#if defined(__i386__) 86#define TULIP_IOMAPPED 87#endif 88 89#if 0 90/* 91 * This turns on all sort of debugging stuff and make the 92 * driver much larger. 93 */ 94#define TULIP_DEBUG 95#endif 96 97#if 0 98#define TULIP_PERFSTATS 99#endif 100 101#if 0 102#define TULIP_USE_SOFTINTR 103#endif 104 105#define TULIP_HZ 10 106 107#include <pci/if_devar.h> 108 109/* 110 * This module supports 111 * the DEC 21040 PCI Ethernet Controller. 112 * the DEC 21041 PCI Ethernet Controller. 113 * the DEC 21140 PCI Fast Ethernet Controller. 114 */ 115static void tulip_addr_filter(tulip_softc_t * const sc); 116static void tulip_ifinit(void *); 117static int tulip_ifmedia_change(struct ifnet * const ifp); 118static void tulip_ifmedia_status(struct ifnet * const ifp, 119 struct ifmediareq *req); 120static void tulip_ifstart(struct ifnet *ifp); 121static void tulip_init(tulip_softc_t * const sc); 122static void tulip_intr_shared(void *arg); 123static void tulip_intr_normal(void *arg); 124static void tulip_mii_autonegotiate(tulip_softc_t * const sc, 125 const unsigned phyaddr); 126static int tulip_mii_map_abilities(tulip_softc_t * const sc, 127 unsigned abilities); 128static tulip_media_t 129 tulip_mii_phy_readspecific(tulip_softc_t * const sc); 130static unsigned tulip_mii_readreg(tulip_softc_t * const sc, unsigned devaddr, 131 unsigned regno); 132static void tulip_mii_writereg(tulip_softc_t * const sc, unsigned devaddr, 133 unsigned regno, unsigned data); 134static void tulip_reset(tulip_softc_t * const sc); 135static void tulip_rx_intr(tulip_softc_t * const sc); 136static int tulip_srom_decode(tulip_softc_t * const sc); 137static struct mbuf * 138 tulip_txput(tulip_softc_t * const sc, struct mbuf *m); 139static void tulip_txput_setup(tulip_softc_t * const sc); 140 141static void 142tulip_timeout_callback( 143 void *arg) 144{ 145 tulip_softc_t * const sc = arg; 146 int s = splimp(); 147 148 TULIP_PERFSTART(timeout) 149 150 sc->tulip_flags &= ~TULIP_TIMEOUTPENDING; 151 sc->tulip_probe_timeout -= 1000 / TULIP_HZ; 152 (sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_TIMER); 153 154 TULIP_PERFEND(timeout); 155 splx(s); 156} 157 158static void 159tulip_timeout( 160 tulip_softc_t * const sc) 161{ 162 if (sc->tulip_flags & TULIP_TIMEOUTPENDING) 163 return; 164 sc->tulip_flags |= TULIP_TIMEOUTPENDING; 165 timeout(tulip_timeout_callback, sc, (hz + TULIP_HZ / 2) / TULIP_HZ); 166} 167 168#if defined(TULIP_NEED_FASTTIMEOUT) 169static void 170tulip_fasttimeout_callback( 171 void *arg) 172{ 173 tulip_softc_t * const sc = arg; 174 int s = splimp(); 175 176 sc->tulip_flags &= ~TULIP_FASTTIMEOUTPENDING; 177 (sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_FASTTIMER); 178 splx(s); 179} 180 181static void 182tulip_fasttimeout( 183 tulip_softc_t * const sc) 184{ 185 if (sc->tulip_flags & TULIP_FASTTIMEOUTPENDING) 186 return; 187 sc->tulip_flags |= TULIP_FASTTIMEOUTPENDING; 188 timeout(tulip_fasttimeout_callback, sc, 1); 189} 190#endif 191 192static int 193tulip_txprobe( 194 tulip_softc_t * const sc) 195{ 196 struct mbuf *m; 197 /* 198 * Before we are sure this is the right media we need 199 * to send a small packet to make sure there's carrier. 200 * Strangely, BNC and AUI will "see" receive data if 201 * either is connected so the transmit is the only way 202 * to verify the connectivity. 203 */ 204 MGETHDR(m, M_DONTWAIT, MT_DATA); 205 if (m == NULL) 206 return 0; 207 /* 208 * Construct a LLC TEST message which will point to ourselves. 209 */ 210 bcopy(sc->tulip_enaddr, mtod(m, struct ether_header *)->ether_dhost, 6); 211 bcopy(sc->tulip_enaddr, mtod(m, struct ether_header *)->ether_shost, 6); 212 mtod(m, struct ether_header *)->ether_type = htons(3); 213 mtod(m, unsigned char *)[14] = 0; 214 mtod(m, unsigned char *)[15] = 0; 215 mtod(m, unsigned char *)[16] = 0xE3; /* LLC Class1 TEST (no poll) */ 216 m->m_len = m->m_pkthdr.len = sizeof(struct ether_header) + 3; 217 /* 218 * send it! 219 */ 220 sc->tulip_cmdmode |= TULIP_CMD_TXRUN; 221 sc->tulip_intrmask |= TULIP_STS_TXINTR; 222 sc->tulip_flags |= TULIP_TXPROBE_ACTIVE; 223 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode); 224 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask); 225 if ((m = tulip_txput(sc, m)) != NULL) 226 m_freem(m); 227 sc->tulip_probe.probe_txprobes++; 228 return 1; 229} 230 231#ifdef BIG_PACKET 232#define TULIP_SIAGEN_WATCHDOG (sc->tulip_if.if_mtu > ETHERMTU ? TULIP_WATCHDOG_RXDISABLE|TULIP_WATCHDOG_TXDISABLE : 0) 233#else 234#define TULIP_SIAGEN_WATCHDOG 0 235#endif 236 237static void 238tulip_media_set( 239 tulip_softc_t * const sc, 240 tulip_media_t media) 241{ 242 const tulip_media_info_t *mi = sc->tulip_mediums[media]; 243 244 if (mi == NULL) 245 return; 246 247 /* 248 * If we are switching media, make sure we don't think there's 249 * any stale RX activity 250 */ 251 sc->tulip_flags &= ~TULIP_RXACT; 252 if (mi->mi_type == TULIP_MEDIAINFO_SIA) { 253 TULIP_CSR_WRITE(sc, csr_sia_connectivity, TULIP_SIACONN_RESET); 254 TULIP_CSR_WRITE(sc, csr_sia_tx_rx, mi->mi_sia_tx_rx); 255 if (sc->tulip_features & TULIP_HAVE_SIAGP) { 256 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_gp_control|mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG); 257 DELAY(50); 258 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_gp_data|mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG); 259 } else { 260 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG); 261 } 262 TULIP_CSR_WRITE(sc, csr_sia_connectivity, mi->mi_sia_connectivity); 263 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR) { 264#define TULIP_GPR_CMDBITS (TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER|TULIP_CMD_TXTHRSHLDCTL) 265 /* 266 * If the cmdmode bits don't match the currently operating mode, 267 * set the cmdmode appropriately and reset the chip. 268 */ 269 if (((mi->mi_cmdmode ^ TULIP_CSR_READ(sc, csr_command)) & TULIP_GPR_CMDBITS) != 0) { 270 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS; 271 sc->tulip_cmdmode |= mi->mi_cmdmode; 272 tulip_reset(sc); 273 } 274 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET|sc->tulip_gpinit); 275 DELAY(10); 276 TULIP_CSR_WRITE(sc, csr_gp, (u_int8_t) mi->mi_gpdata); 277 } else if (mi->mi_type == TULIP_MEDIAINFO_SYM) { 278 /* 279 * If the cmdmode bits don't match the currently operating mode, 280 * set the cmdmode appropriately and reset the chip. 281 */ 282 if (((mi->mi_cmdmode ^ TULIP_CSR_READ(sc, csr_command)) & TULIP_GPR_CMDBITS) != 0) { 283 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS; 284 sc->tulip_cmdmode |= mi->mi_cmdmode; 285 tulip_reset(sc); 286 } 287 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_gpcontrol); 288 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_gpdata); 289 } else if (mi->mi_type == TULIP_MEDIAINFO_MII 290 && sc->tulip_probe_state != TULIP_PROBE_INACTIVE) { 291 int idx; 292 if (sc->tulip_features & TULIP_HAVE_SIAGP) { 293 const u_int8_t *dp; 294 dp = &sc->tulip_rombuf[mi->mi_reset_offset]; 295 for (idx = 0; idx < mi->mi_reset_length; idx++, dp += 2) { 296 DELAY(10); 297 TULIP_CSR_WRITE(sc, csr_sia_general, (dp[0] + 256 * dp[1]) << 16); 298 } 299 sc->tulip_phyaddr = mi->mi_phyaddr; 300 dp = &sc->tulip_rombuf[mi->mi_gpr_offset]; 301 for (idx = 0; idx < mi->mi_gpr_length; idx++, dp += 2) { 302 DELAY(10); 303 TULIP_CSR_WRITE(sc, csr_sia_general, (dp[0] + 256 * dp[1]) << 16); 304 } 305 } else { 306 for (idx = 0; idx < mi->mi_reset_length; idx++) { 307 DELAY(10); 308 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_reset_offset + idx]); 309 } 310 sc->tulip_phyaddr = mi->mi_phyaddr; 311 for (idx = 0; idx < mi->mi_gpr_length; idx++) { 312 DELAY(10); 313 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_gpr_offset + idx]); 314 } 315 } 316 if (sc->tulip_flags & TULIP_TRYNWAY) { 317 tulip_mii_autonegotiate(sc, sc->tulip_phyaddr); 318 } else if ((sc->tulip_flags & TULIP_DIDNWAY) == 0) { 319 u_int32_t data = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_CONTROL); 320 data &= ~(PHYCTL_SELECT_100MB|PHYCTL_FULL_DUPLEX|PHYCTL_AUTONEG_ENABLE); 321 sc->tulip_flags &= ~TULIP_DIDNWAY; 322 if (TULIP_IS_MEDIA_FD(media)) 323 data |= PHYCTL_FULL_DUPLEX; 324 if (TULIP_IS_MEDIA_100MB(media)) 325 data |= PHYCTL_SELECT_100MB; 326 tulip_mii_writereg(sc, sc->tulip_phyaddr, PHYREG_CONTROL, data); 327 } 328 } 329} 330 331static void 332tulip_linkup( 333 tulip_softc_t * const sc, 334 tulip_media_t media) 335{ 336 if ((sc->tulip_flags & TULIP_LINKUP) == 0) 337 sc->tulip_flags |= TULIP_PRINTLINKUP; 338 sc->tulip_flags |= TULIP_LINKUP; 339 sc->tulip_if.if_flags &= ~IFF_OACTIVE; 340#if 0 /* XXX how does with work with ifmedia? */ 341 if ((sc->tulip_flags & TULIP_DIDNWAY) == 0) { 342 if (sc->tulip_if.if_flags & IFF_FULLDUPLEX) { 343 if (TULIP_CAN_MEDIA_FD(media) 344 && sc->tulip_mediums[TULIP_FD_MEDIA_OF(media)] != NULL) 345 media = TULIP_FD_MEDIA_OF(media); 346 } else { 347 if (TULIP_IS_MEDIA_FD(media) 348 && sc->tulip_mediums[TULIP_HD_MEDIA_OF(media)] != NULL) 349 media = TULIP_HD_MEDIA_OF(media); 350 } 351 } 352#endif 353 if (sc->tulip_media != media) { 354#ifdef TULIP_DEBUG 355 sc->tulip_dbg.dbg_last_media = sc->tulip_media; 356#endif 357 sc->tulip_media = media; 358 sc->tulip_flags |= TULIP_PRINTMEDIA; 359 if (TULIP_IS_MEDIA_FD(sc->tulip_media)) { 360 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX; 361 } else if (sc->tulip_chipid != TULIP_21041 || (sc->tulip_flags & TULIP_DIDNWAY) == 0) { 362 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX; 363 } 364 } 365 /* 366 * We could set probe_timeout to 0 but setting to 3000 puts this 367 * in one central place and the only matters is tulip_link is 368 * followed by a tulip_timeout. Therefore setting it should not 369 * result in aberrant behavour. 370 */ 371 sc->tulip_probe_timeout = 3000; 372 sc->tulip_probe_state = TULIP_PROBE_INACTIVE; 373 sc->tulip_flags &= ~(TULIP_TXPROBE_ACTIVE|TULIP_TRYNWAY); 374 if (sc->tulip_flags & TULIP_INRESET) { 375 tulip_media_set(sc, sc->tulip_media); 376 } else if (sc->tulip_probe_media != sc->tulip_media) { 377 /* 378 * No reason to change media if we have the right media. 379 */ 380 tulip_reset(sc); 381 } 382 tulip_init(sc); 383} 384 385static void 386tulip_media_print( 387 tulip_softc_t * const sc) 388{ 389 if ((sc->tulip_flags & TULIP_LINKUP) == 0) 390 return; 391 if (sc->tulip_flags & TULIP_PRINTMEDIA) { 392 printf("%s: enabling %s port\n", 393 sc->tulip_xname, 394 tulip_mediums[sc->tulip_media]); 395 sc->tulip_flags &= ~(TULIP_PRINTMEDIA|TULIP_PRINTLINKUP); 396 } else if (sc->tulip_flags & TULIP_PRINTLINKUP) { 397 printf("%s: link up\n", sc->tulip_xname); 398 sc->tulip_flags &= ~TULIP_PRINTLINKUP; 399 } 400} 401 402#if defined(TULIP_DO_GPR_SENSE) 403static tulip_media_t 404tulip_21140_gpr_media_sense( 405 tulip_softc_t * const sc) 406{ 407 tulip_media_t maybe_media = TULIP_MEDIA_UNKNOWN; 408 tulip_media_t last_media = TULIP_MEDIA_UNKNOWN; 409 tulip_media_t media; 410 411 /* 412 * If one of the media blocks contained a default media flag, 413 * use that. 414 */ 415 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) { 416 const tulip_media_info_t *mi; 417 /* 418 * Media is not supported (or is full-duplex). 419 */ 420 if ((mi = sc->tulip_mediums[media]) == NULL || TULIP_IS_MEDIA_FD(media)) 421 continue; 422 if (mi->mi_type != TULIP_MEDIAINFO_GPR) 423 continue; 424 425 /* 426 * Remember the media is this is the "default" media. 427 */ 428 if (mi->mi_default && maybe_media == TULIP_MEDIA_UNKNOWN) 429 maybe_media = media; 430 431 /* 432 * No activity mask? Can't see if it is active if there's no mask. 433 */ 434 if (mi->mi_actmask == 0) 435 continue; 436 437 /* 438 * Does the activity data match? 439 */ 440 if ((TULIP_CSR_READ(sc, csr_gp) & mi->mi_actmask) != mi->mi_actdata) 441 continue; 442 443#if defined(TULIP_DEBUG) 444 printf("%s: gpr_media_sense: %s: 0x%02x & 0x%02x == 0x%02x\n", 445 sc->tulip_xname, tulip_mediums[media], 446 TULIP_CSR_READ(sc, csr_gp) & 0xFF, 447 mi->mi_actmask, mi->mi_actdata); 448#endif 449 /* 450 * It does! If this is the first media we detected, then 451 * remember this media. If isn't the first, then there were 452 * multiple matches which we equate to no match (since we don't 453 * which to select (if any). 454 */ 455 if (last_media == TULIP_MEDIA_UNKNOWN) { 456 last_media = media; 457 } else if (last_media != media) { 458 last_media = TULIP_MEDIA_UNKNOWN; 459 } 460 } 461 return (last_media != TULIP_MEDIA_UNKNOWN) ? last_media : maybe_media; 462} 463#endif /* TULIP_DO_GPR_SENSE */ 464 465static tulip_link_status_t 466tulip_media_link_monitor( 467 tulip_softc_t * const sc) 468{ 469 const tulip_media_info_t * const mi = sc->tulip_mediums[sc->tulip_media]; 470 tulip_link_status_t linkup = TULIP_LINK_DOWN; 471 472 if (mi == NULL) { 473#if defined(DIAGNOSTIC) || defined(TULIP_DEBUG) 474 panic("tulip_media_link_monitor: %s: botch at line %d\n", 475 tulip_mediums[sc->tulip_media],__LINE__); 476#else 477 return TULIP_LINK_UNKNOWN; 478#endif 479 } 480 481 482 /* 483 * Have we seen some packets? If so, the link must be good. 484 */ 485 if ((sc->tulip_flags & (TULIP_RXACT|TULIP_LINKUP)) == (TULIP_RXACT|TULIP_LINKUP)) { 486 sc->tulip_flags &= ~TULIP_RXACT; 487 sc->tulip_probe_timeout = 3000; 488 return TULIP_LINK_UP; 489 } 490 491 sc->tulip_flags &= ~TULIP_RXACT; 492 if (mi->mi_type == TULIP_MEDIAINFO_MII) { 493 u_int32_t status; 494 /* 495 * Read the PHY status register. 496 */ 497 status = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_STATUS); 498 if (status & PHYSTS_AUTONEG_DONE) { 499 /* 500 * If the PHY has completed autonegotiation, see the if the 501 * remote systems abilities have changed. If so, upgrade or 502 * downgrade as appropriate. 503 */ 504 u_int32_t abilities = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_AUTONEG_ABILITIES); 505 abilities = (abilities << 6) & status; 506 if (abilities != sc->tulip_abilities) { 507#if defined(TULIP_DEBUG) 508 loudprintf("%s(phy%d): autonegotiation changed: 0x%04x -> 0x%04x\n", 509 sc->tulip_xname, sc->tulip_phyaddr, 510 sc->tulip_abilities, abilities); 511#endif 512 if (tulip_mii_map_abilities(sc, abilities)) { 513 tulip_linkup(sc, sc->tulip_probe_media); 514 return TULIP_LINK_UP; 515 } 516 /* 517 * if we had selected media because of autonegotiation, 518 * we need to probe for the new media. 519 */ 520 sc->tulip_probe_state = TULIP_PROBE_INACTIVE; 521 if (sc->tulip_flags & TULIP_DIDNWAY) 522 return TULIP_LINK_DOWN; 523 } 524 } 525 /* 526 * The link is now up. If was down, say its back up. 527 */ 528 if ((status & (PHYSTS_LINK_UP|PHYSTS_REMOTE_FAULT)) == PHYSTS_LINK_UP) 529 linkup = TULIP_LINK_UP; 530 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR) { 531 /* 532 * No activity sensor? Assume all's well. 533 */ 534 if (mi->mi_actmask == 0) 535 return TULIP_LINK_UNKNOWN; 536 /* 537 * Does the activity data match? 538 */ 539 if ((TULIP_CSR_READ(sc, csr_gp) & mi->mi_actmask) == mi->mi_actdata) 540 linkup = TULIP_LINK_UP; 541 } else if (mi->mi_type == TULIP_MEDIAINFO_SIA) { 542 /* 543 * Assume non TP ok for now. 544 */ 545 if (!TULIP_IS_MEDIA_TP(sc->tulip_media)) 546 return TULIP_LINK_UNKNOWN; 547 if ((TULIP_CSR_READ(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL) == 0) 548 linkup = TULIP_LINK_UP; 549#if defined(TULIP_DEBUG) 550 if (sc->tulip_probe_timeout <= 0) 551 printf("%s: sia status = 0x%08x\n", sc->tulip_xname, 552 TULIP_CSR_READ(sc, csr_sia_status)); 553#endif 554 } else if (mi->mi_type == TULIP_MEDIAINFO_SYM) { 555 return TULIP_LINK_UNKNOWN; 556 } 557 /* 558 * We will wait for 3 seconds until the link goes into suspect mode. 559 */ 560 if (sc->tulip_flags & TULIP_LINKUP) { 561 if (linkup == TULIP_LINK_UP) 562 sc->tulip_probe_timeout = 3000; 563 if (sc->tulip_probe_timeout > 0) 564 return TULIP_LINK_UP; 565 566 sc->tulip_flags &= ~TULIP_LINKUP; 567 printf("%s: link down: cable problem?\n", sc->tulip_xname); 568 } 569#if defined(TULIP_DEBUG) 570 sc->tulip_dbg.dbg_link_downed++; 571#endif 572 return TULIP_LINK_DOWN; 573} 574 575static void 576tulip_media_poll( 577 tulip_softc_t * const sc, 578 tulip_mediapoll_event_t event) 579{ 580#if defined(TULIP_DEBUG) 581 sc->tulip_dbg.dbg_events[event]++; 582#endif 583 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE 584 && event == TULIP_MEDIAPOLL_TIMER) { 585 switch (tulip_media_link_monitor(sc)) { 586 case TULIP_LINK_DOWN: { 587 /* 588 * Link Monitor failed. Probe for new media. 589 */ 590 event = TULIP_MEDIAPOLL_LINKFAIL; 591 break; 592 } 593 case TULIP_LINK_UP: { 594 /* 595 * Check again soon. 596 */ 597 tulip_timeout(sc); 598 return; 599 } 600 case TULIP_LINK_UNKNOWN: { 601 /* 602 * We can't tell so don't bother. 603 */ 604 return; 605 } 606 } 607 } 608 609 if (event == TULIP_MEDIAPOLL_LINKFAIL) { 610 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE) { 611 if (TULIP_DO_AUTOSENSE(sc)) { 612#if defined(TULIP_DEBUG) 613 sc->tulip_dbg.dbg_link_failures++; 614#endif 615 sc->tulip_media = TULIP_MEDIA_UNKNOWN; 616 if (sc->tulip_if.if_flags & IFF_UP) 617 tulip_reset(sc); /* restart probe */ 618 } 619 return; 620 } 621#if defined(TULIP_DEBUG) 622 sc->tulip_dbg.dbg_link_pollintrs++; 623#endif 624 } 625 626 if (event == TULIP_MEDIAPOLL_START) { 627 sc->tulip_if.if_flags |= IFF_OACTIVE; 628 if (sc->tulip_probe_state != TULIP_PROBE_INACTIVE) 629 return; 630 sc->tulip_probe_mediamask = 0; 631 sc->tulip_probe_passes = 0; 632#if defined(TULIP_DEBUG) 633 sc->tulip_dbg.dbg_media_probes++; 634#endif 635 /* 636 * If the SROM contained an explicit media to use, use it. 637 */ 638 sc->tulip_cmdmode &= ~(TULIP_CMD_RXRUN|TULIP_CMD_FULLDUPLEX); 639 sc->tulip_flags |= TULIP_TRYNWAY|TULIP_PROBE1STPASS; 640 sc->tulip_flags &= ~(TULIP_DIDNWAY|TULIP_PRINTMEDIA|TULIP_PRINTLINKUP); 641 /* 642 * connidx is defaulted to a media_unknown type. 643 */ 644 sc->tulip_probe_media = tulip_srom_conninfo[sc->tulip_connidx].sc_media; 645 if (sc->tulip_probe_media != TULIP_MEDIA_UNKNOWN) { 646 tulip_linkup(sc, sc->tulip_probe_media); 647 tulip_timeout(sc); 648 return; 649 } 650 651 if (sc->tulip_features & TULIP_HAVE_GPR) { 652 sc->tulip_probe_state = TULIP_PROBE_GPRTEST; 653 sc->tulip_probe_timeout = 2000; 654 } else { 655 sc->tulip_probe_media = TULIP_MEDIA_MAX; 656 sc->tulip_probe_timeout = 0; 657 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST; 658 } 659 } 660 661 /* 662 * Ignore txprobe failures or spurious callbacks. 663 */ 664 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED 665 && sc->tulip_probe_state != TULIP_PROBE_MEDIATEST) { 666 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE; 667 return; 668 } 669 670 /* 671 * If we really transmitted a packet, then that's the media we'll use. 672 */ 673 if (event == TULIP_MEDIAPOLL_TXPROBE_OK || event == TULIP_MEDIAPOLL_LINKPASS) { 674 if (event == TULIP_MEDIAPOLL_LINKPASS) { 675 /* XXX Check media status just to be sure */ 676 sc->tulip_probe_media = TULIP_MEDIA_10BASET; 677#if defined(TULIP_DEBUG) 678 } else { 679 sc->tulip_dbg.dbg_txprobes_ok[sc->tulip_probe_media]++; 680#endif 681 } 682 tulip_linkup(sc, sc->tulip_probe_media); 683 tulip_timeout(sc); 684 return; 685 } 686 687 if (sc->tulip_probe_state == TULIP_PROBE_GPRTEST) { 688#if defined(TULIP_DO_GPR_SENSE) 689 /* 690 * Check for media via the general purpose register. 691 * 692 * Try to sense the media via the GPR. If the same value 693 * occurs 3 times in a row then just use that. 694 */ 695 if (sc->tulip_probe_timeout > 0) { 696 tulip_media_t new_probe_media = tulip_21140_gpr_media_sense(sc); 697#if defined(TULIP_DEBUG) 698 printf("%s: media_poll: gpr sensing = %s\n", 699 sc->tulip_xname, tulip_mediums[new_probe_media]); 700#endif 701 if (new_probe_media != TULIP_MEDIA_UNKNOWN) { 702 if (new_probe_media == sc->tulip_probe_media) { 703 if (--sc->tulip_probe_count == 0) 704 tulip_linkup(sc, sc->tulip_probe_media); 705 } else { 706 sc->tulip_probe_count = 10; 707 } 708 } 709 sc->tulip_probe_media = new_probe_media; 710 tulip_timeout(sc); 711 return; 712 } 713#endif /* TULIP_DO_GPR_SENSE */ 714 /* 715 * Brute force. We cycle through each of the media types 716 * and try to transmit a packet. 717 */ 718 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST; 719 sc->tulip_probe_media = TULIP_MEDIA_MAX; 720 sc->tulip_probe_timeout = 0; 721 tulip_timeout(sc); 722 return; 723 } 724 725 if (sc->tulip_probe_state != TULIP_PROBE_MEDIATEST 726 && (sc->tulip_features & TULIP_HAVE_MII)) { 727 tulip_media_t old_media = sc->tulip_probe_media; 728 tulip_mii_autonegotiate(sc, sc->tulip_phyaddr); 729 switch (sc->tulip_probe_state) { 730 case TULIP_PROBE_FAILED: 731 case TULIP_PROBE_MEDIATEST: { 732 /* 733 * Try the next media. 734 */ 735 sc->tulip_probe_mediamask |= sc->tulip_mediums[sc->tulip_probe_media]->mi_mediamask; 736 sc->tulip_probe_timeout = 0; 737#ifdef notyet 738 if (sc->tulip_probe_state == TULIP_PROBE_FAILED) 739 break; 740 if (sc->tulip_probe_media != tulip_mii_phy_readspecific(sc)) 741 break; 742 sc->tulip_probe_timeout = TULIP_IS_MEDIA_TP(sc->tulip_probe_media) ? 2500 : 300; 743#endif 744 break; 745 } 746 case TULIP_PROBE_PHYAUTONEG: { 747 return; 748 } 749 case TULIP_PROBE_INACTIVE: { 750 /* 751 * Only probe if we autonegotiated a media that hasn't failed. 752 */ 753 sc->tulip_probe_timeout = 0; 754 if (sc->tulip_probe_mediamask & TULIP_BIT(sc->tulip_probe_media)) { 755 sc->tulip_probe_media = old_media; 756 break; 757 } 758 tulip_linkup(sc, sc->tulip_probe_media); 759 tulip_timeout(sc); 760 return; 761 } 762 default: { 763#if defined(DIAGNOSTIC) || defined(TULIP_DEBUG) 764 panic("tulip_media_poll: botch at line %d\n", __LINE__); 765#endif 766 break; 767 } 768 } 769 } 770 771 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED) { 772#if defined(TULIP_DEBUG) 773 sc->tulip_dbg.dbg_txprobes_failed[sc->tulip_probe_media]++; 774#endif 775 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE; 776 return; 777 } 778 779 /* 780 * switch to another media if we tried this one enough. 781 */ 782 if (/* event == TULIP_MEDIAPOLL_TXPROBE_FAILED || */ sc->tulip_probe_timeout <= 0) { 783#if defined(TULIP_DEBUG) 784 if (sc->tulip_probe_media == TULIP_MEDIA_UNKNOWN) { 785 printf("%s: poll media unknown!\n", 786 sc->tulip_xname); 787 sc->tulip_probe_media = TULIP_MEDIA_MAX; 788 } 789#endif 790 /* 791 * Find the next media type to check for. Full Duplex 792 * types are not allowed. 793 */ 794 do { 795 sc->tulip_probe_media -= 1; 796 if (sc->tulip_probe_media == TULIP_MEDIA_UNKNOWN) { 797 if (++sc->tulip_probe_passes == 3) { 798 printf("%s: autosense failed: cable problem?\n", 799 sc->tulip_xname); 800 if ((sc->tulip_if.if_flags & IFF_UP) == 0) { 801 sc->tulip_if.if_flags &= ~IFF_RUNNING; 802 sc->tulip_probe_state = TULIP_PROBE_INACTIVE; 803 return; 804 } 805 } 806 sc->tulip_flags ^= TULIP_TRYNWAY; /* XXX */ 807 sc->tulip_probe_mediamask = 0; 808 sc->tulip_probe_media = TULIP_MEDIA_MAX - 1; 809 } 810 } while (sc->tulip_mediums[sc->tulip_probe_media] == NULL 811 || (sc->tulip_probe_mediamask & TULIP_BIT(sc->tulip_probe_media)) 812 || TULIP_IS_MEDIA_FD(sc->tulip_probe_media)); 813 814#if defined(TULIP_DEBUG) 815 printf("%s: %s: probing %s\n", sc->tulip_xname, 816 event == TULIP_MEDIAPOLL_TXPROBE_FAILED ? "txprobe failed" : "timeout", 817 tulip_mediums[sc->tulip_probe_media]); 818#endif 819 sc->tulip_probe_timeout = TULIP_IS_MEDIA_TP(sc->tulip_probe_media) ? 2500 : 1000; 820 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST; 821 sc->tulip_probe.probe_txprobes = 0; 822 tulip_reset(sc); 823 tulip_media_set(sc, sc->tulip_probe_media); 824 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE; 825 } 826 tulip_timeout(sc); 827 828 /* 829 * If this is hanging off a phy, we know are doing NWAY and we have 830 * forced the phy to a specific speed. Wait for link up before 831 * before sending a packet. 832 */ 833 switch (sc->tulip_mediums[sc->tulip_probe_media]->mi_type) { 834 case TULIP_MEDIAINFO_MII: { 835 if (sc->tulip_probe_media != tulip_mii_phy_readspecific(sc)) 836 return; 837 break; 838 } 839 case TULIP_MEDIAINFO_SIA: { 840 if (TULIP_IS_MEDIA_TP(sc->tulip_probe_media)) { 841 if (TULIP_CSR_READ(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL) 842 return; 843 tulip_linkup(sc, sc->tulip_probe_media); 844#ifdef notyet 845 if (sc->tulip_features & TULIP_HAVE_MII) 846 tulip_timeout(sc); 847#endif 848 return; 849 } 850 break; 851 } 852 case TULIP_MEDIAINFO_RESET: 853 case TULIP_MEDIAINFO_SYM: 854 case TULIP_MEDIAINFO_NONE: 855 case TULIP_MEDIAINFO_GPR: { 856 break; 857 } 858 } 859 /* 860 * Try to send a packet. 861 */ 862 tulip_txprobe(sc); 863} 864 865static void 866tulip_media_select( 867 tulip_softc_t * const sc) 868{ 869 if (sc->tulip_features & TULIP_HAVE_GPR) { 870 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET|sc->tulip_gpinit); 871 DELAY(10); 872 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_gpdata); 873 } 874 /* 875 * If this board has no media, just return 876 */ 877 if (sc->tulip_features & TULIP_HAVE_NOMEDIA) 878 return; 879 880 if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) { 881 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask); 882 (*sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_START); 883 } else { 884 tulip_media_set(sc, sc->tulip_media); 885 } 886} 887 888static void 889tulip_21040_mediainfo_init( 890 tulip_softc_t * const sc, 891 tulip_media_t media) 892{ 893 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_THRSHLD160 894 |TULIP_CMD_BACKOFFCTR; 895 sc->tulip_if.if_baudrate = 10000000; 896 897 if (media == TULIP_MEDIA_10BASET || media == TULIP_MEDIA_UNKNOWN) { 898 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[0], 21040, 10BASET); 899 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[1], 21040, 10BASET_FD); 900 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL; 901 } 902 903 if (media == TULIP_MEDIA_AUIBNC || media == TULIP_MEDIA_UNKNOWN) { 904 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[2], 21040, AUIBNC); 905 } 906 907 if (media == TULIP_MEDIA_UNKNOWN) { 908 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[3], 21040, EXTSIA); 909 } 910} 911 912static void 913tulip_21040_media_probe( 914 tulip_softc_t * const sc) 915{ 916 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_UNKNOWN); 917 return; 918} 919 920static void 921tulip_21040_10baset_only_media_probe( 922 tulip_softc_t * const sc) 923{ 924 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_10BASET); 925 tulip_media_set(sc, TULIP_MEDIA_10BASET); 926 sc->tulip_media = TULIP_MEDIA_10BASET; 927} 928 929static void 930tulip_21040_10baset_only_media_select( 931 tulip_softc_t * const sc) 932{ 933 sc->tulip_flags |= TULIP_LINKUP; 934 if (sc->tulip_media == TULIP_MEDIA_10BASET_FD) { 935 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX; 936 sc->tulip_flags &= ~TULIP_SQETEST; 937 } else { 938 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX; 939 sc->tulip_flags |= TULIP_SQETEST; 940 } 941 tulip_media_set(sc, sc->tulip_media); 942} 943 944static void 945tulip_21040_auibnc_only_media_probe( 946 tulip_softc_t * const sc) 947{ 948 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_AUIBNC); 949 sc->tulip_flags |= TULIP_SQETEST|TULIP_LINKUP; 950 tulip_media_set(sc, TULIP_MEDIA_AUIBNC); 951 sc->tulip_media = TULIP_MEDIA_AUIBNC; 952} 953 954static void 955tulip_21040_auibnc_only_media_select( 956 tulip_softc_t * const sc) 957{ 958 tulip_media_set(sc, TULIP_MEDIA_AUIBNC); 959 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX; 960} 961 962static const tulip_boardsw_t tulip_21040_boardsw = { 963 TULIP_21040_GENERIC, 964 tulip_21040_media_probe, 965 tulip_media_select, 966 tulip_media_poll, 967}; 968 969static const tulip_boardsw_t tulip_21040_10baset_only_boardsw = { 970 TULIP_21040_GENERIC, 971 tulip_21040_10baset_only_media_probe, 972 tulip_21040_10baset_only_media_select, 973 NULL, 974}; 975 976static const tulip_boardsw_t tulip_21040_auibnc_only_boardsw = { 977 TULIP_21040_GENERIC, 978 tulip_21040_auibnc_only_media_probe, 979 tulip_21040_auibnc_only_media_select, 980 NULL, 981}; 982 983static void 984tulip_21041_mediainfo_init( 985 tulip_softc_t * const sc) 986{ 987 tulip_media_info_t * const mi = sc->tulip_mediainfo; 988 989#ifdef notyet 990 if (sc->tulip_revinfo >= 0x20) { 991 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041P2, 10BASET); 992 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041P2, 10BASET_FD); 993 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041P2, AUI); 994 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041P2, BNC); 995 return; 996 } 997#endif 998 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041, 10BASET); 999 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041, 10BASET_FD); 1000 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[2], 21041, AUI); 1001 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[3], 21041, BNC); 1002} 1003 1004static void 1005tulip_21041_media_probe( 1006 tulip_softc_t * const sc) 1007{ 1008 sc->tulip_if.if_baudrate = 10000000; 1009 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_ENHCAPTEFFCT 1010 |TULIP_CMD_THRSHLD160|TULIP_CMD_BACKOFFCTR; 1011 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL; 1012 tulip_21041_mediainfo_init(sc); 1013} 1014 1015static void 1016tulip_21041_media_poll( 1017 tulip_softc_t * const sc, 1018 const tulip_mediapoll_event_t event) 1019{ 1020 u_int32_t sia_status; 1021 1022#if defined(TULIP_DEBUG) 1023 sc->tulip_dbg.dbg_events[event]++; 1024#endif 1025 1026 if (event == TULIP_MEDIAPOLL_LINKFAIL) { 1027 if (sc->tulip_probe_state != TULIP_PROBE_INACTIVE 1028 || !TULIP_DO_AUTOSENSE(sc)) 1029 return; 1030 sc->tulip_media = TULIP_MEDIA_UNKNOWN; 1031 tulip_reset(sc); /* start probe */ 1032 return; 1033 } 1034 1035 /* 1036 * If we've been been asked to start a poll or link change interrupt 1037 * restart the probe (and reset the tulip to a known state). 1038 */ 1039 if (event == TULIP_MEDIAPOLL_START) { 1040 sc->tulip_if.if_flags |= IFF_OACTIVE; 1041 sc->tulip_cmdmode &= ~(TULIP_CMD_FULLDUPLEX|TULIP_CMD_RXRUN); 1042#ifdef notyet 1043 if (sc->tulip_revinfo >= 0x20) { 1044 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX; 1045 sc->tulip_flags |= TULIP_DIDNWAY; 1046 } 1047#endif 1048 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode); 1049 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST; 1050 sc->tulip_probe_media = TULIP_MEDIA_10BASET; 1051 sc->tulip_probe_timeout = TULIP_21041_PROBE_10BASET_TIMEOUT; 1052 tulip_media_set(sc, TULIP_MEDIA_10BASET); 1053 tulip_timeout(sc); 1054 return; 1055 } 1056 1057 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE) 1058 return; 1059 1060 if (event == TULIP_MEDIAPOLL_TXPROBE_OK) { 1061#if defined(TULIP_DEBUG) 1062 sc->tulip_dbg.dbg_txprobes_ok[sc->tulip_probe_media]++; 1063#endif 1064 tulip_linkup(sc, sc->tulip_probe_media); 1065 return; 1066 } 1067 1068 sia_status = TULIP_CSR_READ(sc, csr_sia_status); 1069 TULIP_CSR_WRITE(sc, csr_sia_status, sia_status); 1070 if ((sia_status & TULIP_SIASTS_LINKFAIL) == 0) { 1071 if (sc->tulip_revinfo >= 0x20) { 1072 if (sia_status & (PHYSTS_10BASET_FD << (16 - 6))) 1073 sc->tulip_probe_media = TULIP_MEDIA_10BASET_FD; 1074 } 1075 /* 1076 * If the link has passed LinkPass, 10baseT is the 1077 * proper media to use. 1078 */ 1079 tulip_linkup(sc, sc->tulip_probe_media); 1080 return; 1081 } 1082 1083 /* 1084 * wait for up to 2.4 seconds for the link to reach pass state. 1085 * Only then start scanning the other media for activity. 1086 * choose media with receive activity over those without. 1087 */ 1088 if (sc->tulip_probe_media == TULIP_MEDIA_10BASET) { 1089 if (event != TULIP_MEDIAPOLL_TIMER) 1090 return; 1091 if (sc->tulip_probe_timeout > 0 1092 && (sia_status & TULIP_SIASTS_OTHERRXACTIVITY) == 0) { 1093 tulip_timeout(sc); 1094 return; 1095 } 1096 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT; 1097 sc->tulip_flags |= TULIP_WANTRXACT; 1098 if (sia_status & TULIP_SIASTS_OTHERRXACTIVITY) { 1099 sc->tulip_probe_media = TULIP_MEDIA_BNC; 1100 } else { 1101 sc->tulip_probe_media = TULIP_MEDIA_AUI; 1102 } 1103 tulip_media_set(sc, sc->tulip_probe_media); 1104 tulip_timeout(sc); 1105 return; 1106 } 1107 1108 /* 1109 * If we failed, clear the txprobe active flag. 1110 */ 1111 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED) 1112 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE; 1113 1114 1115 if (event == TULIP_MEDIAPOLL_TIMER) { 1116 /* 1117 * If we've received something, then that's our link! 1118 */ 1119 if (sc->tulip_flags & TULIP_RXACT) { 1120 tulip_linkup(sc, sc->tulip_probe_media); 1121 return; 1122 } 1123 /* 1124 * if no txprobe active 1125 */ 1126 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0 1127 && ((sc->tulip_flags & TULIP_WANTRXACT) == 0 1128 || (sia_status & TULIP_SIASTS_RXACTIVITY))) { 1129 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT; 1130 tulip_txprobe(sc); 1131 tulip_timeout(sc); 1132 return; 1133 } 1134 /* 1135 * Take 2 passes through before deciding to not 1136 * wait for receive activity. Then take another 1137 * two passes before spitting out a warning. 1138 */ 1139 if (sc->tulip_probe_timeout <= 0) { 1140 if (sc->tulip_flags & TULIP_WANTRXACT) { 1141 sc->tulip_flags &= ~TULIP_WANTRXACT; 1142 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT; 1143 } else { 1144 printf("%s: autosense failed: cable problem?\n", 1145 sc->tulip_xname); 1146 if ((sc->tulip_if.if_flags & IFF_UP) == 0) { 1147 sc->tulip_if.if_flags &= ~IFF_RUNNING; 1148 sc->tulip_probe_state = TULIP_PROBE_INACTIVE; 1149 return; 1150 } 1151 } 1152 } 1153 } 1154 1155 /* 1156 * Since this media failed to probe, try the other one. 1157 */ 1158 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT; 1159 if (sc->tulip_probe_media == TULIP_MEDIA_AUI) { 1160 sc->tulip_probe_media = TULIP_MEDIA_BNC; 1161 } else { 1162 sc->tulip_probe_media = TULIP_MEDIA_AUI; 1163 } 1164 tulip_media_set(sc, sc->tulip_probe_media); 1165 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE; 1166 tulip_timeout(sc); 1167} 1168 1169static const tulip_boardsw_t tulip_21041_boardsw = { 1170 TULIP_21041_GENERIC, 1171 tulip_21041_media_probe, 1172 tulip_media_select, 1173 tulip_21041_media_poll 1174}; 1175 1176static const tulip_phy_attr_t tulip_mii_phy_attrlist[] = { 1177 { 0x20005c00, 0, /* 08-00-17 */ 1178 { 1179 { 0x19, 0x0040, 0x0040 }, /* 10TX */ 1180 { 0x19, 0x0040, 0x0000 }, /* 100TX */ 1181 }, 1182#if defined(TULIP_DEBUG) 1183 "NS DP83840", 1184#endif 1185 }, 1186 { 0x0281F400, 0, /* 00-A0-7D */ 1187 { 1188 { 0x12, 0x0010, 0x0000 }, /* 10T */ 1189 { }, /* 100TX */ 1190 { 0x12, 0x0010, 0x0010 }, /* 100T4 */ 1191 { 0x12, 0x0008, 0x0008 }, /* FULL_DUPLEX */ 1192 }, 1193#if defined(TULIP_DEBUG) 1194 "Seeq 80C240" 1195#endif 1196 }, 1197#if 0 1198 { 0x0015F420, 0, /* 00-A0-7D */ 1199 { 1200 { 0x12, 0x0010, 0x0000 }, /* 10T */ 1201 { }, /* 100TX */ 1202 { 0x12, 0x0010, 0x0010 }, /* 100T4 */ 1203 { 0x12, 0x0008, 0x0008 }, /* FULL_DUPLEX */ 1204 }, 1205#if defined(TULIP_DEBUG) 1206 "Broadcom BCM5000" 1207#endif 1208 }, 1209#endif 1210 { 0x0281F400, 0, /* 00-A0-BE */ 1211 { 1212 { 0x11, 0x8000, 0x0000 }, /* 10T */ 1213 { 0x11, 0x8000, 0x8000 }, /* 100TX */ 1214 { }, /* 100T4 */ 1215 { 0x11, 0x4000, 0x4000 }, /* FULL_DUPLEX */ 1216 }, 1217#if defined(TULIP_DEBUG) 1218 "ICS 1890" 1219#endif 1220 }, 1221 { 0 } 1222}; 1223 1224static tulip_media_t 1225tulip_mii_phy_readspecific( 1226 tulip_softc_t * const sc) 1227{ 1228 const tulip_phy_attr_t *attr; 1229 u_int16_t data; 1230 u_int32_t id; 1231 unsigned idx = 0; 1232 static const tulip_media_t table[] = { 1233 TULIP_MEDIA_UNKNOWN, 1234 TULIP_MEDIA_10BASET, 1235 TULIP_MEDIA_100BASETX, 1236 TULIP_MEDIA_100BASET4, 1237 TULIP_MEDIA_UNKNOWN, 1238 TULIP_MEDIA_10BASET_FD, 1239 TULIP_MEDIA_100BASETX_FD, 1240 TULIP_MEDIA_UNKNOWN 1241 }; 1242 1243 /* 1244 * Don't read phy specific registers if link is not up. 1245 */ 1246 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_STATUS); 1247 if ((data & (PHYSTS_LINK_UP|PHYSTS_EXTENDED_REGS)) != (PHYSTS_LINK_UP|PHYSTS_EXTENDED_REGS)) 1248 return TULIP_MEDIA_UNKNOWN; 1249 1250 id = (tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_IDLOW) << 16) | 1251 tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_IDHIGH); 1252 for (attr = tulip_mii_phy_attrlist;; attr++) { 1253 if (attr->attr_id == 0) 1254 return TULIP_MEDIA_UNKNOWN; 1255 if ((id & ~0x0F) == attr->attr_id) 1256 break; 1257 } 1258 1259 if (attr->attr_modes[PHY_MODE_100TX].pm_regno) { 1260 const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_100TX]; 1261 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno); 1262 if ((data & pm->pm_mask) == pm->pm_value) 1263 idx = 2; 1264 } 1265 if (idx == 0 && attr->attr_modes[PHY_MODE_100T4].pm_regno) { 1266 const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_100T4]; 1267 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno); 1268 if ((data & pm->pm_mask) == pm->pm_value) 1269 idx = 3; 1270 } 1271 if (idx == 0 && attr->attr_modes[PHY_MODE_10T].pm_regno) { 1272 const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_10T]; 1273 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno); 1274 if ((data & pm->pm_mask) == pm->pm_value) 1275 idx = 1; 1276 } 1277 if (idx != 0 && attr->attr_modes[PHY_MODE_FULLDUPLEX].pm_regno) { 1278 const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_FULLDUPLEX]; 1279 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno); 1280 idx += ((data & pm->pm_mask) == pm->pm_value ? 4 : 0); 1281 } 1282 return table[idx]; 1283} 1284 1285static unsigned 1286tulip_mii_get_phyaddr( 1287 tulip_softc_t * const sc, 1288 unsigned offset) 1289{ 1290 unsigned phyaddr; 1291 1292 for (phyaddr = 1; phyaddr < 32; phyaddr++) { 1293 unsigned status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS); 1294 if (status == 0 || status == 0xFFFF || status < PHYSTS_10BASET) 1295 continue; 1296 if (offset == 0) 1297 return phyaddr; 1298 offset--; 1299 } 1300 if (offset == 0) { 1301 unsigned status = tulip_mii_readreg(sc, 0, PHYREG_STATUS); 1302 if (status == 0 || status == 0xFFFF || status < PHYSTS_10BASET) 1303 return TULIP_MII_NOPHY; 1304 return 0; 1305 } 1306 return TULIP_MII_NOPHY; 1307} 1308 1309static int 1310tulip_mii_map_abilities( 1311 tulip_softc_t * const sc, 1312 unsigned abilities) 1313{ 1314 sc->tulip_abilities = abilities; 1315 if (abilities & PHYSTS_100BASETX_FD) { 1316 sc->tulip_probe_media = TULIP_MEDIA_100BASETX_FD; 1317 } else if (abilities & PHYSTS_100BASET4) { 1318 sc->tulip_probe_media = TULIP_MEDIA_100BASET4; 1319 } else if (abilities & PHYSTS_100BASETX) { 1320 sc->tulip_probe_media = TULIP_MEDIA_100BASETX; 1321 } else if (abilities & PHYSTS_10BASET_FD) { 1322 sc->tulip_probe_media = TULIP_MEDIA_10BASET_FD; 1323 } else if (abilities & PHYSTS_10BASET) { 1324 sc->tulip_probe_media = TULIP_MEDIA_10BASET; 1325 } else { 1326 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST; 1327 return 0; 1328 } 1329 sc->tulip_probe_state = TULIP_PROBE_INACTIVE; 1330 return 1; 1331} 1332 1333static void 1334tulip_mii_autonegotiate( 1335 tulip_softc_t * const sc, 1336 const unsigned phyaddr) 1337{ 1338 switch (sc->tulip_probe_state) { 1339 case TULIP_PROBE_MEDIATEST: 1340 case TULIP_PROBE_INACTIVE: { 1341 sc->tulip_flags |= TULIP_DIDNWAY; 1342 tulip_mii_writereg(sc, phyaddr, PHYREG_CONTROL, PHYCTL_RESET); 1343 sc->tulip_probe_timeout = 3000; 1344 sc->tulip_intrmask |= TULIP_STS_ABNRMLINTR|TULIP_STS_NORMALINTR; 1345 sc->tulip_probe_state = TULIP_PROBE_PHYRESET; 1346 } 1347 /* FALLTHROUGH */ 1348 case TULIP_PROBE_PHYRESET: { 1349 u_int32_t status; 1350 u_int32_t data = tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL); 1351 if (data & PHYCTL_RESET) { 1352 if (sc->tulip_probe_timeout > 0) { 1353 tulip_timeout(sc); 1354 return; 1355 } 1356 printf("%s(phy%d): error: reset of PHY never completed!\n", 1357 sc->tulip_xname, phyaddr); 1358 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE; 1359 sc->tulip_probe_state = TULIP_PROBE_FAILED; 1360 sc->tulip_if.if_flags &= ~(IFF_UP|IFF_RUNNING); 1361 return; 1362 } 1363 status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS); 1364 if ((status & PHYSTS_CAN_AUTONEG) == 0) { 1365#if defined(TULIP_DEBUG) 1366 loudprintf("%s(phy%d): autonegotiation disabled\n", 1367 sc->tulip_xname, phyaddr); 1368#endif 1369 sc->tulip_flags &= ~TULIP_DIDNWAY; 1370 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST; 1371 return; 1372 } 1373 if (tulip_mii_readreg(sc, phyaddr, PHYREG_AUTONEG_ADVERTISEMENT) != ((status >> 6) | 0x01)) 1374 tulip_mii_writereg(sc, phyaddr, PHYREG_AUTONEG_ADVERTISEMENT, (status >> 6) | 0x01); 1375 tulip_mii_writereg(sc, phyaddr, PHYREG_CONTROL, data|PHYCTL_AUTONEG_RESTART|PHYCTL_AUTONEG_ENABLE); 1376 data = tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL); 1377#if defined(TULIP_DEBUG) 1378 if ((data & PHYCTL_AUTONEG_ENABLE) == 0) 1379 loudprintf("%s(phy%d): oops: enable autonegotiation failed: 0x%04x\n", 1380 sc->tulip_xname, phyaddr, data); 1381 else 1382 loudprintf("%s(phy%d): autonegotiation restarted: 0x%04x\n", 1383 sc->tulip_xname, phyaddr, data); 1384 sc->tulip_dbg.dbg_nway_starts++; 1385#endif 1386 sc->tulip_probe_state = TULIP_PROBE_PHYAUTONEG; 1387 sc->tulip_probe_timeout = 3000; 1388 } 1389 /* FALLTHROUGH */ 1390 case TULIP_PROBE_PHYAUTONEG: { 1391 u_int32_t status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS); 1392 u_int32_t data; 1393 if ((status & PHYSTS_AUTONEG_DONE) == 0) { 1394 if (sc->tulip_probe_timeout > 0) { 1395 tulip_timeout(sc); 1396 return; 1397 } 1398#if defined(TULIP_DEBUG) 1399 loudprintf("%s(phy%d): autonegotiation timeout: sts=0x%04x, ctl=0x%04x\n", 1400 sc->tulip_xname, phyaddr, status, 1401 tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL)); 1402#endif 1403 sc->tulip_flags &= ~TULIP_DIDNWAY; 1404 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST; 1405 return; 1406 } 1407 data = tulip_mii_readreg(sc, phyaddr, PHYREG_AUTONEG_ABILITIES); 1408#if defined(TULIP_DEBUG) 1409 loudprintf("%s(phy%d): autonegotiation complete: 0x%04x\n", 1410 sc->tulip_xname, phyaddr, data); 1411#endif 1412 data = (data << 6) & status; 1413 if (!tulip_mii_map_abilities(sc, data)) 1414 sc->tulip_flags &= ~TULIP_DIDNWAY; 1415 return; 1416 } 1417 default: { 1418#if defined(DIAGNOSTIC) 1419 panic("tulip_media_poll: botch at line %d\n", __LINE__); 1420#endif 1421 break; 1422 } 1423 } 1424#if defined(TULIP_DEBUG) 1425 loudprintf("%s(phy%d): autonegotiation failure: state = %d\n", 1426 sc->tulip_xname, phyaddr, sc->tulip_probe_state); 1427 sc->tulip_dbg.dbg_nway_failures++; 1428#endif 1429} 1430 1431static void 1432tulip_2114x_media_preset( 1433 tulip_softc_t * const sc) 1434{ 1435 const tulip_media_info_t *mi = NULL; 1436 tulip_media_t media = sc->tulip_media; 1437 1438 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE) 1439 media = sc->tulip_media; 1440 else 1441 media = sc->tulip_probe_media; 1442 1443 sc->tulip_cmdmode &= ~TULIP_CMD_PORTSELECT; 1444 sc->tulip_flags &= ~TULIP_SQETEST; 1445 if (media != TULIP_MEDIA_UNKNOWN && media != TULIP_MEDIA_MAX) { 1446#if defined(TULIP_DEBUG) 1447 if (media < TULIP_MEDIA_MAX && sc->tulip_mediums[media] != NULL) { 1448#endif 1449 mi = sc->tulip_mediums[media]; 1450 if (mi->mi_type == TULIP_MEDIAINFO_MII) { 1451 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT; 1452 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR 1453 || mi->mi_type == TULIP_MEDIAINFO_SYM) { 1454 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS; 1455 sc->tulip_cmdmode |= mi->mi_cmdmode; 1456 } else if (mi->mi_type == TULIP_MEDIAINFO_SIA) { 1457 TULIP_CSR_WRITE(sc, csr_sia_connectivity, TULIP_SIACONN_RESET); 1458 } 1459#if defined(TULIP_DEBUG) 1460 } else { 1461 printf("%s: preset: bad media %d!\n", 1462 sc->tulip_xname, media); 1463 } 1464#endif 1465 } 1466 switch (media) { 1467 case TULIP_MEDIA_BNC: 1468 case TULIP_MEDIA_AUI: 1469 case TULIP_MEDIA_10BASET: { 1470 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX; 1471 sc->tulip_cmdmode |= TULIP_CMD_TXTHRSHLDCTL; 1472 sc->tulip_if.if_baudrate = 10000000; 1473 sc->tulip_flags |= TULIP_SQETEST; 1474 break; 1475 } 1476 case TULIP_MEDIA_10BASET_FD: { 1477 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX|TULIP_CMD_TXTHRSHLDCTL; 1478 sc->tulip_if.if_baudrate = 10000000; 1479 break; 1480 } 1481 case TULIP_MEDIA_100BASEFX: 1482 case TULIP_MEDIA_100BASET4: 1483 case TULIP_MEDIA_100BASETX: { 1484 sc->tulip_cmdmode &= ~(TULIP_CMD_FULLDUPLEX|TULIP_CMD_TXTHRSHLDCTL); 1485 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT; 1486 sc->tulip_if.if_baudrate = 100000000; 1487 break; 1488 } 1489 case TULIP_MEDIA_100BASEFX_FD: 1490 case TULIP_MEDIA_100BASETX_FD: { 1491 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX|TULIP_CMD_PORTSELECT; 1492 sc->tulip_cmdmode &= ~TULIP_CMD_TXTHRSHLDCTL; 1493 sc->tulip_if.if_baudrate = 100000000; 1494 break; 1495 } 1496 default: { 1497 break; 1498 } 1499 } 1500 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode); 1501} 1502 1503/* 1504 ******************************************************************** 1505 * Start of 21140/21140A support which does not use the MII interface 1506 */ 1507 1508static void 1509tulip_null_media_poll( 1510 tulip_softc_t * const sc, 1511 tulip_mediapoll_event_t event) 1512{ 1513#if defined(TULIP_DEBUG) 1514 sc->tulip_dbg.dbg_events[event]++; 1515#endif 1516#if defined(DIAGNOSTIC) 1517 printf("%s: botch(media_poll) at line %d\n", 1518 sc->tulip_xname, __LINE__); 1519#endif 1520} 1521 1522__inline static void 1523tulip_21140_mediainit( 1524 tulip_softc_t * const sc, 1525 tulip_media_info_t * const mip, 1526 tulip_media_t const media, 1527 unsigned gpdata, 1528 unsigned cmdmode) 1529{ 1530 sc->tulip_mediums[media] = mip; 1531 mip->mi_type = TULIP_MEDIAINFO_GPR; 1532 mip->mi_cmdmode = cmdmode; 1533 mip->mi_gpdata = gpdata; 1534} 1535 1536static void 1537tulip_21140_evalboard_media_probe( 1538 tulip_softc_t * const sc) 1539{ 1540 tulip_media_info_t *mip = sc->tulip_mediainfo; 1541 1542 sc->tulip_gpinit = TULIP_GP_EB_PINS; 1543 sc->tulip_gpdata = TULIP_GP_EB_INIT; 1544 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_PINS); 1545 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_INIT); 1546 TULIP_CSR_WRITE(sc, csr_command, 1547 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT | 1548 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE); 1549 TULIP_CSR_WRITE(sc, csr_command, 1550 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL); 1551 DELAY(1000000); 1552 if ((TULIP_CSR_READ(sc, csr_gp) & TULIP_GP_EB_OK100) != 0) { 1553 sc->tulip_media = TULIP_MEDIA_10BASET; 1554 } else { 1555 sc->tulip_media = TULIP_MEDIA_100BASETX; 1556 } 1557 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET, 1558 TULIP_GP_EB_INIT, 1559 TULIP_CMD_TXTHRSHLDCTL); 1560 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD, 1561 TULIP_GP_EB_INIT, 1562 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX); 1563 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX, 1564 TULIP_GP_EB_INIT, 1565 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION 1566 |TULIP_CMD_SCRAMBLER); 1567 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD, 1568 TULIP_GP_EB_INIT, 1569 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION 1570 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX); 1571} 1572 1573static const tulip_boardsw_t tulip_21140_eb_boardsw = { 1574 TULIP_21140_DEC_EB, 1575 tulip_21140_evalboard_media_probe, 1576 tulip_media_select, 1577 tulip_null_media_poll, 1578 tulip_2114x_media_preset, 1579}; 1580 1581static void 1582tulip_21140_accton_media_probe( 1583 tulip_softc_t * const sc) 1584{ 1585 tulip_media_info_t *mip = sc->tulip_mediainfo; 1586 unsigned gpdata; 1587 1588 sc->tulip_gpinit = TULIP_GP_EB_PINS; 1589 sc->tulip_gpdata = TULIP_GP_EB_INIT; 1590 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_PINS); 1591 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_INIT); 1592 TULIP_CSR_WRITE(sc, csr_command, 1593 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT | 1594 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE); 1595 TULIP_CSR_WRITE(sc, csr_command, 1596 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL); 1597 DELAY(1000000); 1598 gpdata = TULIP_CSR_READ(sc, csr_gp); 1599 if ((gpdata & TULIP_GP_EN1207_UTP_INIT) == 0) { 1600 sc->tulip_media = TULIP_MEDIA_10BASET; 1601 } else { 1602 if ((gpdata & TULIP_GP_EN1207_BNC_INIT) == 0) { 1603 sc->tulip_media = TULIP_MEDIA_BNC; 1604 } else { 1605 sc->tulip_media = TULIP_MEDIA_100BASETX; 1606 } 1607 } 1608 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_BNC, 1609 TULIP_GP_EN1207_BNC_INIT, 1610 TULIP_CMD_TXTHRSHLDCTL); 1611 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET, 1612 TULIP_GP_EN1207_UTP_INIT, 1613 TULIP_CMD_TXTHRSHLDCTL); 1614 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD, 1615 TULIP_GP_EN1207_UTP_INIT, 1616 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX); 1617 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX, 1618 TULIP_GP_EN1207_100_INIT, 1619 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION 1620 |TULIP_CMD_SCRAMBLER); 1621 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD, 1622 TULIP_GP_EN1207_100_INIT, 1623 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION 1624 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX); 1625} 1626 1627static const tulip_boardsw_t tulip_21140_accton_boardsw = { 1628 TULIP_21140_EN1207, 1629 tulip_21140_accton_media_probe, 1630 tulip_media_select, 1631 tulip_null_media_poll, 1632 tulip_2114x_media_preset, 1633}; 1634 1635static void 1636tulip_21140_smc9332_media_probe( 1637 tulip_softc_t * const sc) 1638{ 1639 tulip_media_info_t *mip = sc->tulip_mediainfo; 1640 int idx, cnt = 0; 1641 1642 TULIP_CSR_WRITE(sc, csr_command, TULIP_CMD_PORTSELECT|TULIP_CMD_MUSTBEONE); 1643 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET); 1644 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at 1645 33MHz that comes to two microseconds but wait a 1646 bit longer anyways) */ 1647 TULIP_CSR_WRITE(sc, csr_command, TULIP_CMD_PORTSELECT | 1648 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE); 1649 sc->tulip_gpinit = TULIP_GP_SMC_9332_PINS; 1650 sc->tulip_gpdata = TULIP_GP_SMC_9332_INIT; 1651 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_SMC_9332_PINS|TULIP_GP_PINSET); 1652 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_SMC_9332_INIT); 1653 DELAY(200000); 1654 for (idx = 1000; idx > 0; idx--) { 1655 u_int32_t csr = TULIP_CSR_READ(sc, csr_gp); 1656 if ((csr & (TULIP_GP_SMC_9332_OK10|TULIP_GP_SMC_9332_OK100)) == (TULIP_GP_SMC_9332_OK10|TULIP_GP_SMC_9332_OK100)) { 1657 if (++cnt > 100) 1658 break; 1659 } else if ((csr & TULIP_GP_SMC_9332_OK10) == 0) { 1660 break; 1661 } else { 1662 cnt = 0; 1663 } 1664 DELAY(1000); 1665 } 1666 sc->tulip_media = cnt > 100 ? TULIP_MEDIA_100BASETX : TULIP_MEDIA_10BASET; 1667 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX, 1668 TULIP_GP_SMC_9332_INIT, 1669 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION 1670 |TULIP_CMD_SCRAMBLER); 1671 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD, 1672 TULIP_GP_SMC_9332_INIT, 1673 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION 1674 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX); 1675 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET, 1676 TULIP_GP_SMC_9332_INIT, 1677 TULIP_CMD_TXTHRSHLDCTL); 1678 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD, 1679 TULIP_GP_SMC_9332_INIT, 1680 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX); 1681} 1682 1683static const tulip_boardsw_t tulip_21140_smc9332_boardsw = { 1684 TULIP_21140_SMC_9332, 1685 tulip_21140_smc9332_media_probe, 1686 tulip_media_select, 1687 tulip_null_media_poll, 1688 tulip_2114x_media_preset, 1689}; 1690 1691static void 1692tulip_21140_cogent_em100_media_probe( 1693 tulip_softc_t * const sc) 1694{ 1695 tulip_media_info_t *mip = sc->tulip_mediainfo; 1696 u_int32_t cmdmode = TULIP_CSR_READ(sc, csr_command); 1697 1698 sc->tulip_gpinit = TULIP_GP_EM100_PINS; 1699 sc->tulip_gpdata = TULIP_GP_EM100_INIT; 1700 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EM100_PINS); 1701 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EM100_INIT); 1702 1703 cmdmode = TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION|TULIP_CMD_MUSTBEONE; 1704 cmdmode &= ~(TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_SCRAMBLER); 1705 if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100FX_ID) { 1706 TULIP_CSR_WRITE(sc, csr_command, cmdmode); 1707 sc->tulip_media = TULIP_MEDIA_100BASEFX; 1708 1709 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASEFX, 1710 TULIP_GP_EM100_INIT, 1711 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION); 1712 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASEFX_FD, 1713 TULIP_GP_EM100_INIT, 1714 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION 1715 |TULIP_CMD_FULLDUPLEX); 1716 } else { 1717 TULIP_CSR_WRITE(sc, csr_command, cmdmode|TULIP_CMD_SCRAMBLER); 1718 sc->tulip_media = TULIP_MEDIA_100BASETX; 1719 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX, 1720 TULIP_GP_EM100_INIT, 1721 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION 1722 |TULIP_CMD_SCRAMBLER); 1723 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD, 1724 TULIP_GP_EM100_INIT, 1725 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION 1726 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX); 1727 } 1728} 1729 1730static const tulip_boardsw_t tulip_21140_cogent_em100_boardsw = { 1731 TULIP_21140_COGENT_EM100, 1732 tulip_21140_cogent_em100_media_probe, 1733 tulip_media_select, 1734 tulip_null_media_poll, 1735 tulip_2114x_media_preset 1736}; 1737 1738static void 1739tulip_21140_znyx_zx34x_media_probe( 1740 tulip_softc_t * const sc) 1741{ 1742 tulip_media_info_t *mip = sc->tulip_mediainfo; 1743 int cnt10 = 0, cnt100 = 0, idx; 1744 1745 sc->tulip_gpinit = TULIP_GP_ZX34X_PINS; 1746 sc->tulip_gpdata = TULIP_GP_ZX34X_INIT; 1747 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ZX34X_PINS); 1748 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ZX34X_INIT); 1749 TULIP_CSR_WRITE(sc, csr_command, 1750 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT | 1751 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE); 1752 TULIP_CSR_WRITE(sc, csr_command, 1753 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL); 1754 1755 DELAY(200000); 1756 for (idx = 1000; idx > 0; idx--) { 1757 u_int32_t csr = TULIP_CSR_READ(sc, csr_gp); 1758 if ((csr & (TULIP_GP_ZX34X_LNKFAIL|TULIP_GP_ZX34X_SYMDET|TULIP_GP_ZX34X_SIGDET)) == (TULIP_GP_ZX34X_LNKFAIL|TULIP_GP_ZX34X_SYMDET|TULIP_GP_ZX34X_SIGDET)) { 1759 if (++cnt100 > 100) 1760 break; 1761 } else if ((csr & TULIP_GP_ZX34X_LNKFAIL) == 0) { 1762 if (++cnt10 > 100) 1763 break; 1764 } else { 1765 cnt10 = 0; 1766 cnt100 = 0; 1767 } 1768 DELAY(1000); 1769 } 1770 sc->tulip_media = cnt100 > 100 ? TULIP_MEDIA_100BASETX : TULIP_MEDIA_10BASET; 1771 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET, 1772 TULIP_GP_ZX34X_INIT, 1773 TULIP_CMD_TXTHRSHLDCTL); 1774 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD, 1775 TULIP_GP_ZX34X_INIT, 1776 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX); 1777 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX, 1778 TULIP_GP_ZX34X_INIT, 1779 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION 1780 |TULIP_CMD_SCRAMBLER); 1781 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD, 1782 TULIP_GP_ZX34X_INIT, 1783 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION 1784 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX); 1785} 1786 1787static const tulip_boardsw_t tulip_21140_znyx_zx34x_boardsw = { 1788 TULIP_21140_ZNYX_ZX34X, 1789 tulip_21140_znyx_zx34x_media_probe, 1790 tulip_media_select, 1791 tulip_null_media_poll, 1792 tulip_2114x_media_preset, 1793}; 1794 1795static void 1796tulip_2114x_media_probe( 1797 tulip_softc_t * const sc) 1798{ 1799 sc->tulip_cmdmode |= TULIP_CMD_MUSTBEONE 1800 |TULIP_CMD_BACKOFFCTR|TULIP_CMD_THRSHLD72; 1801} 1802 1803static const tulip_boardsw_t tulip_2114x_isv_boardsw = { 1804 TULIP_21140_ISV, 1805 tulip_2114x_media_probe, 1806 tulip_media_select, 1807 tulip_media_poll, 1808 tulip_2114x_media_preset, 1809}; 1810 1811/* 1812 * ******** END of chip-specific handlers. *********** 1813 */ 1814 1815/* 1816 * Code the read the SROM and MII bit streams (I2C) 1817 */ 1818#define EMIT do { TULIP_CSR_WRITE(sc, csr_srom_mii, csr); DELAY(1); } while (0) 1819 1820static void 1821tulip_srom_idle( 1822 tulip_softc_t * const sc) 1823{ 1824 unsigned bit, csr; 1825 1826 csr = SROMSEL ; EMIT; 1827 csr = SROMSEL | SROMRD; EMIT; 1828 csr ^= SROMCS; EMIT; 1829 csr ^= SROMCLKON; EMIT; 1830 1831 /* 1832 * Write 25 cycles of 0 which will force the SROM to be idle. 1833 */ 1834 for (bit = 3 + SROM_BITWIDTH + 16; bit > 0; bit--) { 1835 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */ 1836 csr ^= SROMCLKON; EMIT; /* clock high; data valid */ 1837 } 1838 csr ^= SROMCLKOFF; EMIT; 1839 csr ^= SROMCS; EMIT; 1840 csr = 0; EMIT; 1841} 1842 1843 1844static void 1845tulip_srom_read( 1846 tulip_softc_t * const sc) 1847{ 1848 unsigned idx; 1849 const unsigned bitwidth = SROM_BITWIDTH; 1850 const unsigned cmdmask = (SROMCMD_RD << bitwidth); 1851 const unsigned msb = 1 << (bitwidth + 3 - 1); 1852 unsigned lastidx = (1 << bitwidth) - 1; 1853 1854 tulip_srom_idle(sc); 1855 1856 for (idx = 0; idx <= lastidx; idx++) { 1857 unsigned lastbit, data, bits, bit, csr; 1858 csr = SROMSEL ; EMIT; 1859 csr = SROMSEL | SROMRD; EMIT; 1860 csr ^= SROMCSON; EMIT; 1861 csr ^= SROMCLKON; EMIT; 1862 1863 lastbit = 0; 1864 for (bits = idx|cmdmask, bit = bitwidth + 3; bit > 0; bit--, bits <<= 1) { 1865 const unsigned thisbit = bits & msb; 1866 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */ 1867 if (thisbit != lastbit) { 1868 csr ^= SROMDOUT; EMIT; /* clock low; invert data */ 1869 } else { 1870 EMIT; 1871 } 1872 csr ^= SROMCLKON; EMIT; /* clock high; data valid */ 1873 lastbit = thisbit; 1874 } 1875 csr ^= SROMCLKOFF; EMIT; 1876 1877 for (data = 0, bits = 0; bits < 16; bits++) { 1878 data <<= 1; 1879 csr ^= SROMCLKON; EMIT; /* clock high; data valid */ 1880 data |= TULIP_CSR_READ(sc, csr_srom_mii) & SROMDIN ? 1 : 0; 1881 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */ 1882 } 1883 sc->tulip_rombuf[idx*2] = data & 0xFF; 1884 sc->tulip_rombuf[idx*2+1] = data >> 8; 1885 csr = SROMSEL | SROMRD; EMIT; 1886 csr = 0; EMIT; 1887 } 1888 tulip_srom_idle(sc); 1889} 1890 1891#define MII_EMIT do { TULIP_CSR_WRITE(sc, csr_srom_mii, csr); DELAY(1); } while (0) 1892 1893static void 1894tulip_mii_writebits( 1895 tulip_softc_t * const sc, 1896 unsigned data, 1897 unsigned bits) 1898{ 1899 unsigned msb = 1 << (bits - 1); 1900 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK); 1901 unsigned lastbit = (csr & MII_DOUT) ? msb : 0; 1902 1903 csr |= MII_WR; MII_EMIT; /* clock low; assert write */ 1904 1905 for (; bits > 0; bits--, data <<= 1) { 1906 const unsigned thisbit = data & msb; 1907 if (thisbit != lastbit) { 1908 csr ^= MII_DOUT; MII_EMIT; /* clock low; invert data */ 1909 } 1910 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */ 1911 lastbit = thisbit; 1912 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */ 1913 } 1914} 1915 1916static void 1917tulip_mii_turnaround( 1918 tulip_softc_t * const sc, 1919 unsigned cmd) 1920{ 1921 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK); 1922 1923 if (cmd == MII_WRCMD) { 1924 csr |= MII_DOUT; MII_EMIT; /* clock low; change data */ 1925 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */ 1926 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */ 1927 csr ^= MII_DOUT; MII_EMIT; /* clock low; change data */ 1928 } else { 1929 csr |= MII_RD; MII_EMIT; /* clock low; switch to read */ 1930 } 1931 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */ 1932 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */ 1933} 1934 1935static unsigned 1936tulip_mii_readbits( 1937 tulip_softc_t * const sc) 1938{ 1939 unsigned data; 1940 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK); 1941 int idx; 1942 1943 for (idx = 0, data = 0; idx < 16; idx++) { 1944 data <<= 1; /* this is NOOP on the first pass through */ 1945 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */ 1946 if (TULIP_CSR_READ(sc, csr_srom_mii) & MII_DIN) 1947 data |= 1; 1948 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */ 1949 } 1950 csr ^= MII_RD; MII_EMIT; /* clock low; turn off read */ 1951 1952 return data; 1953} 1954 1955static unsigned 1956tulip_mii_readreg( 1957 tulip_softc_t * const sc, 1958 unsigned devaddr, 1959 unsigned regno) 1960{ 1961 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK); 1962 unsigned data; 1963 1964 csr &= ~(MII_RD|MII_CLK); MII_EMIT; 1965 tulip_mii_writebits(sc, MII_PREAMBLE, 32); 1966 tulip_mii_writebits(sc, MII_RDCMD, 8); 1967 tulip_mii_writebits(sc, devaddr, 5); 1968 tulip_mii_writebits(sc, regno, 5); 1969 tulip_mii_turnaround(sc, MII_RDCMD); 1970 1971 data = tulip_mii_readbits(sc); 1972#if defined(TULIP_DEBUG) 1973 sc->tulip_dbg.dbg_phyregs[regno][0] = data; 1974 sc->tulip_dbg.dbg_phyregs[regno][1]++; 1975#endif 1976 return data; 1977} 1978 1979static void 1980tulip_mii_writereg( 1981 tulip_softc_t * const sc, 1982 unsigned devaddr, 1983 unsigned regno, 1984 unsigned data) 1985{ 1986 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK); 1987 csr &= ~(MII_RD|MII_CLK); MII_EMIT; 1988 tulip_mii_writebits(sc, MII_PREAMBLE, 32); 1989 tulip_mii_writebits(sc, MII_WRCMD, 8); 1990 tulip_mii_writebits(sc, devaddr, 5); 1991 tulip_mii_writebits(sc, regno, 5); 1992 tulip_mii_turnaround(sc, MII_WRCMD); 1993 tulip_mii_writebits(sc, data, 16); 1994#if defined(TULIP_DEBUG) 1995 sc->tulip_dbg.dbg_phyregs[regno][2] = data; 1996 sc->tulip_dbg.dbg_phyregs[regno][3]++; 1997#endif 1998} 1999 2000#define tulip_mchash(mca) (ether_crc32_le(mca, 6) & 0x1FF) 2001#define tulip_srom_crcok(databuf) ( \ 2002 ((ether_crc32_le(databuf, 126) & 0xFFFFU) ^ 0xFFFFU) == \ 2003 ((databuf)[126] | ((databuf)[127] << 8))) 2004 2005static void 2006tulip_identify_dec_nic( 2007 tulip_softc_t * const sc) 2008{ 2009 strcpy(sc->tulip_boardid, "DEC "); 2010#define D0 4 2011 if (sc->tulip_chipid <= TULIP_21040) 2012 return; 2013 if (bcmp(sc->tulip_rombuf + 29, "DE500", 5) == 0 2014 || bcmp(sc->tulip_rombuf + 29, "DE450", 5) == 0) { 2015 bcopy(sc->tulip_rombuf + 29, &sc->tulip_boardid[D0], 8); 2016 sc->tulip_boardid[D0+8] = ' '; 2017 } 2018#undef D0 2019} 2020 2021static void 2022tulip_identify_znyx_nic( 2023 tulip_softc_t * const sc) 2024{ 2025 unsigned id = 0; 2026 strcpy(sc->tulip_boardid, "ZNYX ZX3XX "); 2027 if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) { 2028 unsigned znyx_ptr; 2029 sc->tulip_boardid[8] = '4'; 2030 znyx_ptr = sc->tulip_rombuf[124] + 256 * sc->tulip_rombuf[125]; 2031 if (znyx_ptr < 26 || znyx_ptr > 116) { 2032 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw; 2033 return; 2034 } 2035 /* ZX344 = 0010 .. 0013FF 2036 */ 2037 if (sc->tulip_rombuf[znyx_ptr] == 0x4A 2038 && sc->tulip_rombuf[znyx_ptr + 1] == 0x52 2039 && sc->tulip_rombuf[znyx_ptr + 2] == 0x01) { 2040 id = sc->tulip_rombuf[znyx_ptr + 5] + 256 * sc->tulip_rombuf[znyx_ptr + 4]; 2041 if ((id >> 8) == (TULIP_ZNYX_ID_ZX342 >> 8)) { 2042 sc->tulip_boardid[9] = '2'; 2043 if (id == TULIP_ZNYX_ID_ZX342B) { 2044 sc->tulip_boardid[10] = 'B'; 2045 sc->tulip_boardid[11] = ' '; 2046 } 2047 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw; 2048 } else if (id == TULIP_ZNYX_ID_ZX344) { 2049 sc->tulip_boardid[10] = '4'; 2050 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw; 2051 } else if (id == TULIP_ZNYX_ID_ZX345) { 2052 sc->tulip_boardid[9] = (sc->tulip_rombuf[19] > 1) ? '8' : '5'; 2053 } else if (id == TULIP_ZNYX_ID_ZX346) { 2054 sc->tulip_boardid[9] = '6'; 2055 } else if (id == TULIP_ZNYX_ID_ZX351) { 2056 sc->tulip_boardid[8] = '5'; 2057 sc->tulip_boardid[9] = '1'; 2058 } 2059 } 2060 if (id == 0) { 2061 /* 2062 * Assume it's a ZX342... 2063 */ 2064 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw; 2065 } 2066 return; 2067 } 2068 sc->tulip_boardid[8] = '1'; 2069 if (sc->tulip_chipid == TULIP_21041) { 2070 sc->tulip_boardid[10] = '1'; 2071 return; 2072 } 2073 if (sc->tulip_rombuf[32] == 0x4A && sc->tulip_rombuf[33] == 0x52) { 2074 id = sc->tulip_rombuf[37] + 256 * sc->tulip_rombuf[36]; 2075 if (id == TULIP_ZNYX_ID_ZX312T) { 2076 sc->tulip_boardid[9] = '2'; 2077 sc->tulip_boardid[10] = 'T'; 2078 sc->tulip_boardid[11] = ' '; 2079 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw; 2080 } else if (id == TULIP_ZNYX_ID_ZX314_INTA) { 2081 sc->tulip_boardid[9] = '4'; 2082 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw; 2083 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM; 2084 } else if (id == TULIP_ZNYX_ID_ZX314) { 2085 sc->tulip_boardid[9] = '4'; 2086 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw; 2087 sc->tulip_features |= TULIP_HAVE_BASEROM; 2088 } else if (id == TULIP_ZNYX_ID_ZX315_INTA) { 2089 sc->tulip_boardid[9] = '5'; 2090 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM; 2091 } else if (id == TULIP_ZNYX_ID_ZX315) { 2092 sc->tulip_boardid[9] = '5'; 2093 sc->tulip_features |= TULIP_HAVE_BASEROM; 2094 } else { 2095 id = 0; 2096 } 2097 } 2098 if (id == 0) { 2099 if ((sc->tulip_enaddr[3] & ~3) == 0xF0 && (sc->tulip_enaddr[5] & 2) == 0) { 2100 sc->tulip_boardid[9] = '4'; 2101 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw; 2102 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM; 2103 } else if ((sc->tulip_enaddr[3] & ~3) == 0xF4 && (sc->tulip_enaddr[5] & 1) == 0) { 2104 sc->tulip_boardid[9] = '5'; 2105 sc->tulip_boardsw = &tulip_21040_boardsw; 2106 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM; 2107 } else if ((sc->tulip_enaddr[3] & ~3) == 0xEC) { 2108 sc->tulip_boardid[9] = '2'; 2109 sc->tulip_boardsw = &tulip_21040_boardsw; 2110 } 2111 } 2112} 2113 2114static void 2115tulip_identify_smc_nic( 2116 tulip_softc_t * const sc) 2117{ 2118 u_int32_t id1, id2, ei; 2119 int auibnc = 0, utp = 0; 2120 char *cp; 2121 2122 strcpy(sc->tulip_boardid, "SMC "); 2123 if (sc->tulip_chipid == TULIP_21041) 2124 return; 2125 if (sc->tulip_chipid != TULIP_21040) { 2126 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw) { 2127 strcpy(&sc->tulip_boardid[4], "9332DST "); 2128 sc->tulip_boardsw = &tulip_21140_smc9332_boardsw; 2129 } else if (sc->tulip_features & (TULIP_HAVE_BASEROM|TULIP_HAVE_SLAVEDROM)) { 2130 strcpy(&sc->tulip_boardid[4], "9334BDT "); 2131 } else { 2132 strcpy(&sc->tulip_boardid[4], "9332BDT "); 2133 } 2134 return; 2135 } 2136 id1 = sc->tulip_rombuf[0x60] | (sc->tulip_rombuf[0x61] << 8); 2137 id2 = sc->tulip_rombuf[0x62] | (sc->tulip_rombuf[0x63] << 8); 2138 ei = sc->tulip_rombuf[0x66] | (sc->tulip_rombuf[0x67] << 8); 2139 2140 strcpy(&sc->tulip_boardid[4], "8432"); 2141 cp = &sc->tulip_boardid[8]; 2142 if ((id1 & 1) == 0) 2143 *cp++ = 'B', auibnc = 1; 2144 if ((id1 & 0xFF) > 0x32) 2145 *cp++ = 'T', utp = 1; 2146 if ((id1 & 0x4000) == 0) 2147 *cp++ = 'A', auibnc = 1; 2148 if (id2 == 0x15) { 2149 sc->tulip_boardid[7] = '4'; 2150 *cp++ = '-'; 2151 *cp++ = 'C'; 2152 *cp++ = 'H'; 2153 *cp++ = (ei ? '2' : '1'); 2154 } 2155 *cp++ = ' '; 2156 *cp = '\0'; 2157 if (utp && !auibnc) 2158 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw; 2159 else if (!utp && auibnc) 2160 sc->tulip_boardsw = &tulip_21040_auibnc_only_boardsw; 2161} 2162 2163static void 2164tulip_identify_cogent_nic( 2165 tulip_softc_t * const sc) 2166{ 2167 strcpy(sc->tulip_boardid, "Cogent "); 2168 if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) { 2169 if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100TX_ID) { 2170 strcat(sc->tulip_boardid, "EM100TX "); 2171 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw; 2172#if defined(TULIP_COGENT_EM110TX_ID) 2173 } else if (sc->tulip_rombuf[32] == TULIP_COGENT_EM110TX_ID) { 2174 strcat(sc->tulip_boardid, "EM110TX "); 2175 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw; 2176#endif 2177 } else if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100FX_ID) { 2178 strcat(sc->tulip_boardid, "EM100FX "); 2179 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw; 2180 } 2181 /* 2182 * Magic number (0x24001109U) is the SubVendor (0x2400) and 2183 * SubDevId (0x1109) for the ANA6944TX (EM440TX). 2184 */ 2185 if (*(u_int32_t *) sc->tulip_rombuf == 0x24001109U 2186 && (sc->tulip_features & TULIP_HAVE_BASEROM)) { 2187 /* 2188 * Cogent (Adaptec) is still mapping all INTs to INTA of 2189 * first 21140. Dumb! Dumb! 2190 */ 2191 strcat(sc->tulip_boardid, "EM440TX "); 2192 sc->tulip_features |= TULIP_HAVE_SHAREDINTR; 2193 } 2194 } else if (sc->tulip_chipid == TULIP_21040) { 2195 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM; 2196 } 2197} 2198 2199static void 2200tulip_identify_accton_nic( 2201 tulip_softc_t * const sc) 2202{ 2203 strcpy(sc->tulip_boardid, "ACCTON "); 2204 switch (sc->tulip_chipid) { 2205 case TULIP_21140A: 2206 strcat(sc->tulip_boardid, "EN1207 "); 2207 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw) 2208 sc->tulip_boardsw = &tulip_21140_accton_boardsw; 2209 break; 2210 case TULIP_21140: 2211 strcat(sc->tulip_boardid, "EN1207TX "); 2212 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw) 2213 sc->tulip_boardsw = &tulip_21140_eb_boardsw; 2214 break; 2215 case TULIP_21040: 2216 strcat(sc->tulip_boardid, "EN1203 "); 2217 sc->tulip_boardsw = &tulip_21040_boardsw; 2218 break; 2219 case TULIP_21041: 2220 strcat(sc->tulip_boardid, "EN1203 "); 2221 sc->tulip_boardsw = &tulip_21041_boardsw; 2222 break; 2223 default: 2224 sc->tulip_boardsw = &tulip_2114x_isv_boardsw; 2225 break; 2226 } 2227} 2228 2229static void 2230tulip_identify_asante_nic( 2231 tulip_softc_t * const sc) 2232{ 2233 strcpy(sc->tulip_boardid, "Asante "); 2234 if ((sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) 2235 && sc->tulip_boardsw != &tulip_2114x_isv_boardsw) { 2236 tulip_media_info_t *mi = sc->tulip_mediainfo; 2237 int idx; 2238 /* 2239 * The Asante Fast Ethernet doesn't always ship with a valid 2240 * new format SROM. So if isn't in the new format, we cheat 2241 * set it up as if we had. 2242 */ 2243 2244 sc->tulip_gpinit = TULIP_GP_ASANTE_PINS; 2245 sc->tulip_gpdata = 0; 2246 2247 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ASANTE_PINS|TULIP_GP_PINSET); 2248 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ASANTE_PHYRESET); 2249 DELAY(100); 2250 TULIP_CSR_WRITE(sc, csr_gp, 0); 2251 2252 mi->mi_type = TULIP_MEDIAINFO_MII; 2253 mi->mi_gpr_length = 0; 2254 mi->mi_gpr_offset = 0; 2255 mi->mi_reset_length = 0; 2256 mi->mi_reset_offset = 0;; 2257 2258 mi->mi_phyaddr = TULIP_MII_NOPHY; 2259 for (idx = 20; idx > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx--) { 2260 DELAY(10000); 2261 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, 0); 2262 } 2263 if (mi->mi_phyaddr == TULIP_MII_NOPHY) { 2264 printf("%s: can't find phy 0\n", sc->tulip_xname); 2265 return; 2266 } 2267 2268 sc->tulip_features |= TULIP_HAVE_MII; 2269 mi->mi_capabilities = PHYSTS_10BASET|PHYSTS_10BASET_FD|PHYSTS_100BASETX|PHYSTS_100BASETX_FD; 2270 mi->mi_advertisement = PHYSTS_10BASET|PHYSTS_10BASET_FD|PHYSTS_100BASETX|PHYSTS_100BASETX_FD; 2271 mi->mi_full_duplex = PHYSTS_10BASET_FD|PHYSTS_100BASETX_FD; 2272 mi->mi_tx_threshold = PHYSTS_10BASET|PHYSTS_10BASET_FD; 2273 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD); 2274 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX); 2275 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4); 2276 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD); 2277 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET); 2278 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) | 2279 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH); 2280 2281 sc->tulip_boardsw = &tulip_2114x_isv_boardsw; 2282 } 2283} 2284 2285static void 2286tulip_identify_compex_nic( 2287 tulip_softc_t * const sc) 2288{ 2289 strcpy(sc->tulip_boardid, "COMPEX "); 2290 if (sc->tulip_chipid == TULIP_21140A) { 2291 int root_unit; 2292 tulip_softc_t *root_sc = NULL; 2293 2294 strcat(sc->tulip_boardid, "400TX/PCI "); 2295 /* 2296 * All 4 chips on these boards share an interrupt. This code 2297 * copied from tulip_read_macaddr. 2298 */ 2299 sc->tulip_features |= TULIP_HAVE_SHAREDINTR; 2300 for (root_unit = sc->tulip_unit - 1; root_unit >= 0; root_unit--) { 2301 root_sc = tulips[root_unit]; 2302 if (root_sc == NULL 2303 || !(root_sc->tulip_features & TULIP_HAVE_SLAVEDINTR)) 2304 break; 2305 root_sc = NULL; 2306 } 2307 if (root_sc != NULL 2308 && root_sc->tulip_chipid == sc->tulip_chipid 2309 && root_sc->tulip_pci_busno == sc->tulip_pci_busno) { 2310 sc->tulip_features |= TULIP_HAVE_SLAVEDINTR; 2311 sc->tulip_slaves = root_sc->tulip_slaves; 2312 root_sc->tulip_slaves = sc; 2313 } else if(sc->tulip_features & TULIP_HAVE_SLAVEDINTR) { 2314 printf("\nCannot find master device for %s interrupts", 2315 sc->tulip_xname); 2316 } 2317 } else { 2318 strcat(sc->tulip_boardid, "unknown "); 2319 } 2320 /* sc->tulip_boardsw = &tulip_21140_eb_boardsw; */ 2321 return; 2322} 2323 2324static int 2325tulip_srom_decode( 2326 tulip_softc_t * const sc) 2327{ 2328 unsigned idx1, idx2, idx3; 2329 2330 const tulip_srom_header_t *shp = (const tulip_srom_header_t *) &sc->tulip_rombuf[0]; 2331 const tulip_srom_adapter_info_t *saip = (const tulip_srom_adapter_info_t *) (shp + 1); 2332 tulip_srom_media_t srom_media; 2333 tulip_media_info_t *mi = sc->tulip_mediainfo; 2334 const u_int8_t *dp; 2335 u_int32_t leaf_offset, blocks, data; 2336 2337 for (idx1 = 0; idx1 < shp->sh_adapter_count; idx1++, saip++) { 2338 if (shp->sh_adapter_count == 1) 2339 break; 2340 if (saip->sai_device == sc->tulip_pci_devno) 2341 break; 2342 } 2343 /* 2344 * Didn't find the right media block for this card. 2345 */ 2346 if (idx1 == shp->sh_adapter_count) 2347 return 0; 2348 2349 /* 2350 * Save the hardware address. 2351 */ 2352 bcopy(shp->sh_ieee802_address, sc->tulip_enaddr, 6); 2353 /* 2354 * If this is a multiple port card, add the adapter index to the last 2355 * byte of the hardware address. (if it isn't multiport, adding 0 2356 * won't hurt. 2357 */ 2358 sc->tulip_enaddr[5] += idx1; 2359 2360 leaf_offset = saip->sai_leaf_offset_lowbyte 2361 + saip->sai_leaf_offset_highbyte * 256; 2362 dp = sc->tulip_rombuf + leaf_offset; 2363 2364 sc->tulip_conntype = (tulip_srom_connection_t) (dp[0] + dp[1] * 256); dp += 2; 2365 2366 for (idx2 = 0;; idx2++) { 2367 if (tulip_srom_conninfo[idx2].sc_type == sc->tulip_conntype 2368 || tulip_srom_conninfo[idx2].sc_type == TULIP_SROM_CONNTYPE_NOT_USED) 2369 break; 2370 } 2371 sc->tulip_connidx = idx2; 2372 2373 if (sc->tulip_chipid == TULIP_21041) { 2374 blocks = *dp++; 2375 for (idx2 = 0; idx2 < blocks; idx2++) { 2376 tulip_media_t media; 2377 data = *dp++; 2378 srom_media = (tulip_srom_media_t) (data & 0x3F); 2379 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) { 2380 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media) 2381 break; 2382 } 2383 media = tulip_srom_mediums[idx3].sm_type; 2384 if (media != TULIP_MEDIA_UNKNOWN) { 2385 if (data & TULIP_SROM_21041_EXTENDED) { 2386 mi->mi_type = TULIP_MEDIAINFO_SIA; 2387 sc->tulip_mediums[media] = mi; 2388 mi->mi_sia_connectivity = dp[0] + dp[1] * 256; 2389 mi->mi_sia_tx_rx = dp[2] + dp[3] * 256; 2390 mi->mi_sia_general = dp[4] + dp[5] * 256; 2391 mi++; 2392 } else { 2393 switch (media) { 2394 case TULIP_MEDIA_BNC: { 2395 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, BNC); 2396 mi++; 2397 break; 2398 } 2399 case TULIP_MEDIA_AUI: { 2400 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, AUI); 2401 mi++; 2402 break; 2403 } 2404 case TULIP_MEDIA_10BASET: { 2405 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET); 2406 mi++; 2407 break; 2408 } 2409 case TULIP_MEDIA_10BASET_FD: { 2410 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET_FD); 2411 mi++; 2412 break; 2413 } 2414 default: { 2415 break; 2416 } 2417 } 2418 } 2419 } 2420 if (data & TULIP_SROM_21041_EXTENDED) 2421 dp += 6; 2422 } 2423#ifdef notdef 2424 if (blocks == 0) { 2425 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, BNC); mi++; 2426 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, AUI); mi++; 2427 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET); mi++; 2428 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET_FD); mi++; 2429 } 2430#endif 2431 } else { 2432 unsigned length, type; 2433 tulip_media_t gp_media = TULIP_MEDIA_UNKNOWN; 2434 if (sc->tulip_features & TULIP_HAVE_GPR) 2435 sc->tulip_gpinit = *dp++; 2436 blocks = *dp++; 2437 for (idx2 = 0; idx2 < blocks; idx2++) { 2438 const u_int8_t *ep; 2439 if ((*dp & 0x80) == 0) { 2440 length = 4; 2441 type = 0; 2442 } else { 2443 length = (*dp++ & 0x7f) - 1; 2444 type = *dp++ & 0x3f; 2445 } 2446 ep = dp + length; 2447 switch (type & 0x3f) { 2448 case 0: { /* 21140[A] GPR block */ 2449 tulip_media_t media; 2450 srom_media = (tulip_srom_media_t)(dp[0] & 0x3f); 2451 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) { 2452 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media) 2453 break; 2454 } 2455 media = tulip_srom_mediums[idx3].sm_type; 2456 if (media == TULIP_MEDIA_UNKNOWN) 2457 break; 2458 mi->mi_type = TULIP_MEDIAINFO_GPR; 2459 sc->tulip_mediums[media] = mi; 2460 mi->mi_gpdata = dp[1]; 2461 if (media > gp_media && !TULIP_IS_MEDIA_FD(media)) { 2462 sc->tulip_gpdata = mi->mi_gpdata; 2463 gp_media = media; 2464 } 2465 data = dp[2] + dp[3] * 256; 2466 mi->mi_cmdmode = TULIP_SROM_2114X_CMDBITS(data); 2467 if (data & TULIP_SROM_2114X_NOINDICATOR) { 2468 mi->mi_actmask = 0; 2469 } else { 2470#if 0 2471 mi->mi_default = (data & TULIP_SROM_2114X_DEFAULT) != 0; 2472#endif 2473 mi->mi_actmask = TULIP_SROM_2114X_BITPOS(data); 2474 mi->mi_actdata = (data & TULIP_SROM_2114X_POLARITY) ? 0 : mi->mi_actmask; 2475 } 2476 mi++; 2477 break; 2478 } 2479 case 1: { /* 21140[A] MII block */ 2480 const unsigned phyno = *dp++; 2481 mi->mi_type = TULIP_MEDIAINFO_MII; 2482 mi->mi_gpr_length = *dp++; 2483 mi->mi_gpr_offset = dp - sc->tulip_rombuf; 2484 dp += mi->mi_gpr_length; 2485 mi->mi_reset_length = *dp++; 2486 mi->mi_reset_offset = dp - sc->tulip_rombuf; 2487 dp += mi->mi_reset_length; 2488 2489 /* 2490 * Before we probe for a PHY, use the GPR information 2491 * to select it. If we don't, it may be inaccessible. 2492 */ 2493 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_gpinit|TULIP_GP_PINSET); 2494 for (idx3 = 0; idx3 < mi->mi_reset_length; idx3++) { 2495 DELAY(10); 2496 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_reset_offset + idx3]); 2497 } 2498 sc->tulip_phyaddr = mi->mi_phyaddr; 2499 for (idx3 = 0; idx3 < mi->mi_gpr_length; idx3++) { 2500 DELAY(10); 2501 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_gpr_offset + idx3]); 2502 } 2503 2504 /* 2505 * At least write something! 2506 */ 2507 if (mi->mi_reset_length == 0 && mi->mi_gpr_length == 0) 2508 TULIP_CSR_WRITE(sc, csr_gp, 0); 2509 2510 mi->mi_phyaddr = TULIP_MII_NOPHY; 2511 for (idx3 = 20; idx3 > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx3--) { 2512 DELAY(10000); 2513 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, phyno); 2514 } 2515 if (mi->mi_phyaddr == TULIP_MII_NOPHY) { 2516#if defined(TULIP_DEBUG) 2517 printf("%s: can't find phy %d\n", 2518 sc->tulip_xname, phyno); 2519#endif 2520 break; 2521 } 2522 sc->tulip_features |= TULIP_HAVE_MII; 2523 mi->mi_capabilities = dp[0] + dp[1] * 256; dp += 2; 2524 mi->mi_advertisement = dp[0] + dp[1] * 256; dp += 2; 2525 mi->mi_full_duplex = dp[0] + dp[1] * 256; dp += 2; 2526 mi->mi_tx_threshold = dp[0] + dp[1] * 256; dp += 2; 2527 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD); 2528 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX); 2529 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4); 2530 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD); 2531 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET); 2532 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) | 2533 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH); 2534 mi++; 2535 break; 2536 } 2537 case 2: { /* 2114[23] SIA block */ 2538 tulip_media_t media; 2539 srom_media = (tulip_srom_media_t)(dp[0] & 0x3f); 2540 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) { 2541 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media) 2542 break; 2543 } 2544 media = tulip_srom_mediums[idx3].sm_type; 2545 if (media == TULIP_MEDIA_UNKNOWN) 2546 break; 2547 mi->mi_type = TULIP_MEDIAINFO_SIA; 2548 sc->tulip_mediums[media] = mi; 2549 if (dp[0] & 0x40) { 2550 mi->mi_sia_connectivity = dp[1] + dp[2] * 256; 2551 mi->mi_sia_tx_rx = dp[3] + dp[4] * 256; 2552 mi->mi_sia_general = dp[5] + dp[6] * 256; 2553 dp += 6; 2554 } else { 2555 switch (media) { 2556 case TULIP_MEDIA_BNC: { 2557 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, BNC); 2558 break; 2559 } 2560 case TULIP_MEDIA_AUI: { 2561 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, AUI); 2562 break; 2563 } 2564 case TULIP_MEDIA_10BASET: { 2565 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, 10BASET); 2566 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL; 2567 break; 2568 } 2569 case TULIP_MEDIA_10BASET_FD: { 2570 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, 10BASET_FD); 2571 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL; 2572 break; 2573 } 2574 default: { 2575 goto bad_media; 2576 } 2577 } 2578 } 2579 mi->mi_sia_gp_control = (dp[1] + dp[2] * 256) << 16; 2580 mi->mi_sia_gp_data = (dp[3] + dp[4] * 256) << 16; 2581 mi++; 2582 bad_media: 2583 break; 2584 } 2585 case 3: { /* 2114[23] MII PHY block */ 2586 const unsigned phyno = *dp++; 2587 const u_int8_t *dp0; 2588 mi->mi_type = TULIP_MEDIAINFO_MII; 2589 mi->mi_gpr_length = *dp++; 2590 mi->mi_gpr_offset = dp - sc->tulip_rombuf; 2591 dp += 2 * mi->mi_gpr_length; 2592 mi->mi_reset_length = *dp++; 2593 mi->mi_reset_offset = dp - sc->tulip_rombuf; 2594 dp += 2 * mi->mi_reset_length; 2595 2596 dp0 = &sc->tulip_rombuf[mi->mi_reset_offset]; 2597 for (idx3 = 0; idx3 < mi->mi_reset_length; idx3++, dp0 += 2) { 2598 DELAY(10); 2599 TULIP_CSR_WRITE(sc, csr_sia_general, (dp0[0] + 256 * dp0[1]) << 16); 2600 } 2601 sc->tulip_phyaddr = mi->mi_phyaddr; 2602 dp0 = &sc->tulip_rombuf[mi->mi_gpr_offset]; 2603 for (idx3 = 0; idx3 < mi->mi_gpr_length; idx3++, dp0 += 2) { 2604 DELAY(10); 2605 TULIP_CSR_WRITE(sc, csr_sia_general, (dp0[0] + 256 * dp0[1]) << 16); 2606 } 2607 2608 if (mi->mi_reset_length == 0 && mi->mi_gpr_length == 0) 2609 TULIP_CSR_WRITE(sc, csr_sia_general, 0); 2610 2611 mi->mi_phyaddr = TULIP_MII_NOPHY; 2612 for (idx3 = 20; idx3 > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx3--) { 2613 DELAY(10000); 2614 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, phyno); 2615 } 2616 if (mi->mi_phyaddr == TULIP_MII_NOPHY) { 2617#if defined(TULIP_DEBUG) 2618 printf("%s: can't find phy %d\n", 2619 sc->tulip_xname, phyno); 2620#endif 2621 break; 2622 } 2623 sc->tulip_features |= TULIP_HAVE_MII; 2624 mi->mi_capabilities = dp[0] + dp[1] * 256; dp += 2; 2625 mi->mi_advertisement = dp[0] + dp[1] * 256; dp += 2; 2626 mi->mi_full_duplex = dp[0] + dp[1] * 256; dp += 2; 2627 mi->mi_tx_threshold = dp[0] + dp[1] * 256; dp += 2; 2628 mi->mi_mii_interrupt = dp[0] + dp[1] * 256; dp += 2; 2629 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD); 2630 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX); 2631 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4); 2632 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD); 2633 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET); 2634 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) | 2635 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH); 2636 mi++; 2637 break; 2638 } 2639 case 4: { /* 21143 SYM block */ 2640 tulip_media_t media; 2641 srom_media = (tulip_srom_media_t) dp[0]; 2642 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) { 2643 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media) 2644 break; 2645 } 2646 media = tulip_srom_mediums[idx3].sm_type; 2647 if (media == TULIP_MEDIA_UNKNOWN) 2648 break; 2649 mi->mi_type = TULIP_MEDIAINFO_SYM; 2650 sc->tulip_mediums[media] = mi; 2651 mi->mi_gpcontrol = (dp[1] + dp[2] * 256) << 16; 2652 mi->mi_gpdata = (dp[3] + dp[4] * 256) << 16; 2653 data = dp[5] + dp[6] * 256; 2654 mi->mi_cmdmode = TULIP_SROM_2114X_CMDBITS(data); 2655 if (data & TULIP_SROM_2114X_NOINDICATOR) { 2656 mi->mi_actmask = 0; 2657 } else { 2658 mi->mi_default = (data & TULIP_SROM_2114X_DEFAULT) != 0; 2659 mi->mi_actmask = TULIP_SROM_2114X_BITPOS(data); 2660 mi->mi_actdata = (data & TULIP_SROM_2114X_POLARITY) ? 0 : mi->mi_actmask; 2661 } 2662 if (TULIP_IS_MEDIA_TP(media)) 2663 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL; 2664 mi++; 2665 break; 2666 } 2667#if 0 2668 case 5: { /* 21143 Reset block */ 2669 mi->mi_type = TULIP_MEDIAINFO_RESET; 2670 mi->mi_reset_length = *dp++; 2671 mi->mi_reset_offset = dp - sc->tulip_rombuf; 2672 dp += 2 * mi->mi_reset_length; 2673 mi++; 2674 break; 2675 } 2676#endif 2677 default: { 2678 } 2679 } 2680 dp = ep; 2681 } 2682 } 2683 return mi - sc->tulip_mediainfo; 2684} 2685 2686static const struct { 2687 void (*vendor_identify_nic)(tulip_softc_t * const sc); 2688 unsigned char vendor_oui[3]; 2689} tulip_vendors[] = { 2690 { tulip_identify_dec_nic, { 0x08, 0x00, 0x2B } }, 2691 { tulip_identify_dec_nic, { 0x00, 0x00, 0xF8 } }, 2692 { tulip_identify_smc_nic, { 0x00, 0x00, 0xC0 } }, 2693 { tulip_identify_smc_nic, { 0x00, 0xE0, 0x29 } }, 2694 { tulip_identify_znyx_nic, { 0x00, 0xC0, 0x95 } }, 2695 { tulip_identify_cogent_nic, { 0x00, 0x00, 0x92 } }, 2696 { tulip_identify_asante_nic, { 0x00, 0x00, 0x94 } }, 2697 { tulip_identify_cogent_nic, { 0x00, 0x00, 0xD1 } }, 2698 { tulip_identify_accton_nic, { 0x00, 0x00, 0xE8 } }, 2699 { tulip_identify_compex_nic, { 0x00, 0x80, 0x48 } }, 2700 { NULL } 2701}; 2702 2703/* 2704 * This deals with the vagaries of the address roms and the 2705 * brain-deadness that various vendors commit in using them. 2706 */ 2707static int 2708tulip_read_macaddr( 2709 tulip_softc_t * const sc) 2710{ 2711 unsigned cksum, rom_cksum, idx; 2712 u_int32_t csr; 2713 unsigned char tmpbuf[8]; 2714 static const u_char testpat[] = { 0xFF, 0, 0x55, 0xAA, 0xFF, 0, 0x55, 0xAA }; 2715 2716 sc->tulip_connidx = TULIP_SROM_LASTCONNIDX; 2717 2718 if (sc->tulip_chipid == TULIP_21040) { 2719 TULIP_CSR_WRITE(sc, csr_enetrom, 1); 2720 for (idx = 0; idx < sizeof(sc->tulip_rombuf); idx++) { 2721 int cnt = 0; 2722 while (((csr = TULIP_CSR_READ(sc, csr_enetrom)) & 0x80000000L) && cnt < 10000) 2723 cnt++; 2724 sc->tulip_rombuf[idx] = csr & 0xFF; 2725 } 2726 sc->tulip_boardsw = &tulip_21040_boardsw; 2727 } else { 2728 if (sc->tulip_chipid == TULIP_21041) { 2729 /* 2730 * Thankfully all 21041's act the same. 2731 */ 2732 sc->tulip_boardsw = &tulip_21041_boardsw; 2733 } else { 2734 /* 2735 * Assume all 21140 board are compatible with the 2736 * DEC 10/100 evaluation board. Not really valid but 2737 * it's the best we can do until every one switches to 2738 * the new SROM format. 2739 */ 2740 2741 sc->tulip_boardsw = &tulip_21140_eb_boardsw; 2742 } 2743 tulip_srom_read(sc); 2744 if (tulip_srom_crcok(sc->tulip_rombuf)) { 2745 /* 2746 * SROM CRC is valid therefore it must be in the 2747 * new format. 2748 */ 2749 sc->tulip_features |= TULIP_HAVE_ISVSROM|TULIP_HAVE_OKSROM; 2750 } else if (sc->tulip_rombuf[126] == 0xff && sc->tulip_rombuf[127] == 0xFF) { 2751 /* 2752 * No checksum is present. See if the SROM id checks out; 2753 * the first 18 bytes should be 0 followed by a 1 followed 2754 * by the number of adapters (which we don't deal with yet). 2755 */ 2756 for (idx = 0; idx < 18; idx++) { 2757 if (sc->tulip_rombuf[idx] != 0) 2758 break; 2759 } 2760 if (idx == 18 && sc->tulip_rombuf[18] == 1 && sc->tulip_rombuf[19] != 0) 2761 sc->tulip_features |= TULIP_HAVE_ISVSROM; 2762 } else if (sc->tulip_chipid >= TULIP_21142) { 2763 sc->tulip_features |= TULIP_HAVE_ISVSROM; 2764 sc->tulip_boardsw = &tulip_2114x_isv_boardsw; 2765 } 2766 if ((sc->tulip_features & TULIP_HAVE_ISVSROM) && tulip_srom_decode(sc)) { 2767 if (sc->tulip_chipid != TULIP_21041) 2768 sc->tulip_boardsw = &tulip_2114x_isv_boardsw; 2769 2770 /* 2771 * If the SROM specifies more than one adapter, tag this as a 2772 * BASE rom. 2773 */ 2774 if (sc->tulip_rombuf[19] > 1) 2775 sc->tulip_features |= TULIP_HAVE_BASEROM; 2776 if (sc->tulip_boardsw == NULL) 2777 return -6; 2778 goto check_oui; 2779 } 2780 } 2781 2782 2783 if (bcmp(&sc->tulip_rombuf[0], &sc->tulip_rombuf[16], 8) != 0) { 2784 /* 2785 * Some folks don't use the standard ethernet rom format 2786 * but instead just put the address in the first 6 bytes 2787 * of the rom and let the rest be all 0xffs. (Can we say 2788 * ZNYX?) (well sometimes they put in a checksum so we'll 2789 * start at 8). 2790 */ 2791 for (idx = 8; idx < 32; idx++) { 2792 if (sc->tulip_rombuf[idx] != 0xFF) 2793 return -4; 2794 } 2795 /* 2796 * Make sure the address is not multicast or locally assigned 2797 * that the OUI is not 00-00-00. 2798 */ 2799 if ((sc->tulip_rombuf[0] & 3) != 0) 2800 return -4; 2801 if (sc->tulip_rombuf[0] == 0 && sc->tulip_rombuf[1] == 0 2802 && sc->tulip_rombuf[2] == 0) 2803 return -4; 2804 bcopy(sc->tulip_rombuf, sc->tulip_enaddr, 6); 2805 sc->tulip_features |= TULIP_HAVE_OKROM; 2806 goto check_oui; 2807 } else { 2808 /* 2809 * A number of makers of multiport boards (ZNYX and Cogent) 2810 * only put on one address ROM on their 21040 boards. So 2811 * if the ROM is all zeros (or all 0xFFs), look at the 2812 * previous configured boards (as long as they are on the same 2813 * PCI bus and the bus number is non-zero) until we find the 2814 * master board with address ROM. We then use its address ROM 2815 * as the base for this board. (we add our relative board 2816 * to the last byte of its address). 2817 */ 2818 for (idx = 0; idx < sizeof(sc->tulip_rombuf); idx++) { 2819 if (sc->tulip_rombuf[idx] != 0 && sc->tulip_rombuf[idx] != 0xFF) 2820 break; 2821 } 2822 if (idx == sizeof(sc->tulip_rombuf)) { 2823 int root_unit; 2824 tulip_softc_t *root_sc = NULL; 2825 for (root_unit = sc->tulip_unit - 1; root_unit >= 0; root_unit--) { 2826 root_sc = tulips[root_unit]; 2827 if (root_sc == NULL || (root_sc->tulip_features & (TULIP_HAVE_OKROM|TULIP_HAVE_SLAVEDROM)) == TULIP_HAVE_OKROM) 2828 break; 2829 root_sc = NULL; 2830 } 2831 if (root_sc != NULL && (root_sc->tulip_features & TULIP_HAVE_BASEROM) 2832 && root_sc->tulip_chipid == sc->tulip_chipid 2833 && root_sc->tulip_pci_busno == sc->tulip_pci_busno) { 2834 sc->tulip_features |= TULIP_HAVE_SLAVEDROM; 2835 sc->tulip_boardsw = root_sc->tulip_boardsw; 2836 strcpy(sc->tulip_boardid, root_sc->tulip_boardid); 2837 if (sc->tulip_boardsw->bd_type == TULIP_21140_ISV) { 2838 bcopy(root_sc->tulip_rombuf, sc->tulip_rombuf, 2839 sizeof(sc->tulip_rombuf)); 2840 if (!tulip_srom_decode(sc)) 2841 return -5; 2842 } else { 2843 bcopy(root_sc->tulip_enaddr, sc->tulip_enaddr, 6); 2844 sc->tulip_enaddr[5] += sc->tulip_unit - root_sc->tulip_unit; 2845 } 2846 /* 2847 * Now for a truly disgusting kludge: all 4 21040s on 2848 * the ZX314 share the same INTA line so the mapping 2849 * setup by the BIOS on the PCI bridge is worthless. 2850 * Rather than reprogramming the value in the config 2851 * register, we will handle this internally. 2852 */ 2853 if (root_sc->tulip_features & TULIP_HAVE_SHAREDINTR) { 2854 sc->tulip_slaves = root_sc->tulip_slaves; 2855 root_sc->tulip_slaves = sc; 2856 sc->tulip_features |= TULIP_HAVE_SLAVEDINTR; 2857 } 2858 return 0; 2859 } 2860 } 2861 } 2862 2863 /* 2864 * This is the standard DEC address ROM test. 2865 */ 2866 2867 if (bcmp(&sc->tulip_rombuf[24], testpat, 8) != 0) 2868 return -3; 2869 2870 tmpbuf[0] = sc->tulip_rombuf[15]; tmpbuf[1] = sc->tulip_rombuf[14]; 2871 tmpbuf[2] = sc->tulip_rombuf[13]; tmpbuf[3] = sc->tulip_rombuf[12]; 2872 tmpbuf[4] = sc->tulip_rombuf[11]; tmpbuf[5] = sc->tulip_rombuf[10]; 2873 tmpbuf[6] = sc->tulip_rombuf[9]; tmpbuf[7] = sc->tulip_rombuf[8]; 2874 if (bcmp(&sc->tulip_rombuf[0], tmpbuf, 8) != 0) 2875 return -2; 2876 2877 bcopy(sc->tulip_rombuf, sc->tulip_enaddr, 6); 2878 2879 cksum = *(u_int16_t *) &sc->tulip_enaddr[0]; 2880 cksum *= 2; 2881 if (cksum > 65535) cksum -= 65535; 2882 cksum += *(u_int16_t *) &sc->tulip_enaddr[2]; 2883 if (cksum > 65535) cksum -= 65535; 2884 cksum *= 2; 2885 if (cksum > 65535) cksum -= 65535; 2886 cksum += *(u_int16_t *) &sc->tulip_enaddr[4]; 2887 if (cksum >= 65535) cksum -= 65535; 2888 2889 rom_cksum = *(u_int16_t *) &sc->tulip_rombuf[6]; 2890 2891 if (cksum != rom_cksum) 2892 return -1; 2893 2894 check_oui: 2895 /* 2896 * Check for various boards based on OUI. Did I say braindead? 2897 */ 2898 for (idx = 0; tulip_vendors[idx].vendor_identify_nic != NULL; idx++) { 2899 if (bcmp(sc->tulip_enaddr, tulip_vendors[idx].vendor_oui, 3) == 0) { 2900 (*tulip_vendors[idx].vendor_identify_nic)(sc); 2901 break; 2902 } 2903 } 2904 2905 sc->tulip_features |= TULIP_HAVE_OKROM; 2906 return 0; 2907} 2908 2909static void 2910tulip_ifmedia_add( 2911 tulip_softc_t * const sc) 2912{ 2913 tulip_media_t media; 2914 int medias = 0; 2915 2916 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) { 2917 if (sc->tulip_mediums[media] != NULL) { 2918 ifmedia_add(&sc->tulip_ifmedia, tulip_media_to_ifmedia[media], 2919 0, 0); 2920 medias++; 2921 } 2922 } 2923 if (medias == 0) { 2924 sc->tulip_features |= TULIP_HAVE_NOMEDIA; 2925 ifmedia_add(&sc->tulip_ifmedia, IFM_ETHER | IFM_NONE, 0, 0); 2926 ifmedia_set(&sc->tulip_ifmedia, IFM_ETHER | IFM_NONE); 2927 } else if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) { 2928 ifmedia_add(&sc->tulip_ifmedia, IFM_ETHER | IFM_AUTO, 0, 0); 2929 ifmedia_set(&sc->tulip_ifmedia, IFM_ETHER | IFM_AUTO); 2930 } else { 2931 ifmedia_set(&sc->tulip_ifmedia, tulip_media_to_ifmedia[sc->tulip_media]); 2932 sc->tulip_flags |= TULIP_PRINTMEDIA; 2933 tulip_linkup(sc, sc->tulip_media); 2934 } 2935} 2936 2937static int 2938tulip_ifmedia_change( 2939 struct ifnet * const ifp) 2940{ 2941 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc; 2942 2943 sc->tulip_flags |= TULIP_NEEDRESET; 2944 sc->tulip_probe_state = TULIP_PROBE_INACTIVE; 2945 sc->tulip_media = TULIP_MEDIA_UNKNOWN; 2946 if (IFM_SUBTYPE(sc->tulip_ifmedia.ifm_media) != IFM_AUTO) { 2947 tulip_media_t media; 2948 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) { 2949 if (sc->tulip_mediums[media] != NULL 2950 && sc->tulip_ifmedia.ifm_media == tulip_media_to_ifmedia[media]) { 2951 sc->tulip_flags |= TULIP_PRINTMEDIA; 2952 sc->tulip_flags &= ~TULIP_DIDNWAY; 2953 tulip_linkup(sc, media); 2954 return 0; 2955 } 2956 } 2957 } 2958 sc->tulip_flags &= ~(TULIP_TXPROBE_ACTIVE|TULIP_WANTRXACT); 2959 tulip_reset(sc); 2960 tulip_init(sc); 2961 return 0; 2962} 2963 2964/* 2965 * Media status callback 2966 */ 2967static void 2968tulip_ifmedia_status( 2969 struct ifnet * const ifp, 2970 struct ifmediareq *req) 2971{ 2972 tulip_softc_t *sc = (tulip_softc_t *)ifp->if_softc; 2973 2974 if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) 2975 return; 2976 2977 req->ifm_status = IFM_AVALID; 2978 if (sc->tulip_flags & TULIP_LINKUP) 2979 req->ifm_status |= IFM_ACTIVE; 2980 2981 req->ifm_active = tulip_media_to_ifmedia[sc->tulip_media]; 2982} 2983 2984static void 2985tulip_addr_filter( 2986 tulip_softc_t * const sc) 2987{ 2988 struct ifmultiaddr *ifma; 2989 u_char *addrp; 2990 int multicnt; 2991 2992 sc->tulip_flags &= ~(TULIP_WANTHASHPERFECT|TULIP_WANTHASHONLY|TULIP_ALLMULTI); 2993 sc->tulip_flags |= TULIP_WANTSETUP|TULIP_WANTTXSTART; 2994 sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN; 2995 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED; 2996#if defined(IFF_ALLMULTI) 2997 if (sc->tulip_if.if_flags & IFF_ALLMULTI) 2998 sc->tulip_flags |= TULIP_ALLMULTI ; 2999#endif 3000 3001 multicnt = 0; 3002 TAILQ_FOREACH(ifma, &sc->tulip_if.if_multiaddrs, ifma_link) { 3003 3004 if (ifma->ifma_addr->sa_family == AF_LINK) 3005 multicnt++; 3006 } 3007 3008 sc->tulip_if.if_start = tulip_ifstart; /* so the setup packet gets queued */ 3009 if (multicnt > 14) { 3010 u_int32_t *sp = sc->tulip_setupdata; 3011 unsigned hash; 3012 /* 3013 * Some early passes of the 21140 have broken implementations of 3014 * hash-perfect mode. When we get too many multicasts for perfect 3015 * filtering with these chips, we need to switch into hash-only 3016 * mode (this is better than all-multicast on network with lots 3017 * of multicast traffic). 3018 */ 3019 if (sc->tulip_features & TULIP_HAVE_BROKEN_HASH) 3020 sc->tulip_flags |= TULIP_WANTHASHONLY; 3021 else 3022 sc->tulip_flags |= TULIP_WANTHASHPERFECT; 3023 /* 3024 * If we have more than 14 multicasts, we have 3025 * go into hash perfect mode (512 bit multicast 3026 * hash and one perfect hardware). 3027 */ 3028 bzero(sc->tulip_setupdata, sizeof(sc->tulip_setupdata)); 3029 3030 TAILQ_FOREACH(ifma, &sc->tulip_if.if_multiaddrs, ifma_link) { 3031 3032 if (ifma->ifma_addr->sa_family != AF_LINK) 3033 continue; 3034 3035 hash = tulip_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr)); 3036#if BYTE_ORDER == BIG_ENDIAN 3037 sp[hash >> 4] |= bswap32(1 << (hash & 0xF)); 3038#else 3039 sp[hash >> 4] |= 1 << (hash & 0xF); 3040#endif 3041 } 3042 /* 3043 * No reason to use a hash if we are going to be 3044 * receiving every multicast. 3045 */ 3046 if ((sc->tulip_flags & TULIP_ALLMULTI) == 0) { 3047 hash = tulip_mchash(sc->tulip_if.if_broadcastaddr); 3048#if BYTE_ORDER == BIG_ENDIAN 3049 sp[hash >> 4] |= bswap32(1 << (hash & 0xF)); 3050#else 3051 sp[hash >> 4] |= 1 << (hash & 0xF); 3052#endif 3053 if (sc->tulip_flags & TULIP_WANTHASHONLY) { 3054 hash = tulip_mchash(sc->tulip_enaddr); 3055#if BYTE_ORDER == BIG_ENDIAN 3056 sp[hash >> 4] |= bswap32(1 << (hash & 0xF)); 3057#else 3058 sp[hash >> 4] |= 1 << (hash & 0xF); 3059#endif 3060 } else { 3061#if BYTE_ORDER == BIG_ENDIAN 3062 sp[39] = ((u_int16_t *) sc->tulip_enaddr)[0] << 16; 3063 sp[40] = ((u_int16_t *) sc->tulip_enaddr)[1] << 16; 3064 sp[41] = ((u_int16_t *) sc->tulip_enaddr)[2] << 16; 3065#else 3066 sp[39] = ((u_int16_t *) sc->tulip_enaddr)[0]; 3067 sp[40] = ((u_int16_t *) sc->tulip_enaddr)[1]; 3068 sp[41] = ((u_int16_t *) sc->tulip_enaddr)[2]; 3069#endif 3070 } 3071 } 3072 } 3073 if ((sc->tulip_flags & (TULIP_WANTHASHPERFECT|TULIP_WANTHASHONLY)) == 0) { 3074 u_int32_t *sp = sc->tulip_setupdata; 3075 int idx = 0; 3076 if ((sc->tulip_flags & TULIP_ALLMULTI) == 0) { 3077 /* 3078 * Else can get perfect filtering for 16 addresses. 3079 */ 3080 TAILQ_FOREACH(ifma, &sc->tulip_if.if_multiaddrs, ifma_link) { 3081 if (ifma->ifma_addr->sa_family != AF_LINK) 3082 continue; 3083 addrp = LLADDR((struct sockaddr_dl *)ifma->ifma_addr); 3084#if BYTE_ORDER == BIG_ENDIAN 3085 *sp++ = ((u_int16_t *) addrp)[0] << 16; 3086 *sp++ = ((u_int16_t *) addrp)[1] << 16; 3087 *sp++ = ((u_int16_t *) addrp)[2] << 16; 3088#else 3089 *sp++ = ((u_int16_t *) addrp)[0]; 3090 *sp++ = ((u_int16_t *) addrp)[1]; 3091 *sp++ = ((u_int16_t *) addrp)[2]; 3092#endif 3093 idx++; 3094 } 3095 /* 3096 * Add the broadcast address. 3097 */ 3098 idx++; 3099#if BYTE_ORDER == BIG_ENDIAN 3100 *sp++ = 0xFFFF << 16; 3101 *sp++ = 0xFFFF << 16; 3102 *sp++ = 0xFFFF << 16; 3103#else 3104 *sp++ = 0xFFFF; 3105 *sp++ = 0xFFFF; 3106 *sp++ = 0xFFFF; 3107#endif 3108 } 3109 /* 3110 * Pad the rest with our hardware address 3111 */ 3112 for (; idx < 16; idx++) { 3113#if BYTE_ORDER == BIG_ENDIAN 3114 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[0] << 16; 3115 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[1] << 16; 3116 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[2] << 16; 3117#else 3118 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[0]; 3119 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[1]; 3120 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[2]; 3121#endif 3122 } 3123 } 3124#if defined(IFF_ALLMULTI) 3125 if (sc->tulip_flags & TULIP_ALLMULTI) 3126 sc->tulip_if.if_flags |= IFF_ALLMULTI; 3127#endif 3128} 3129 3130static void 3131tulip_reset( 3132 tulip_softc_t * const sc) 3133{ 3134 tulip_ringinfo_t *ri; 3135 tulip_desc_t *di; 3136 u_int32_t inreset = (sc->tulip_flags & TULIP_INRESET); 3137 3138 /* 3139 * Brilliant. Simply brilliant. When switching modes/speeds 3140 * on a 2114*, you need to set the appriopriate MII/PCS/SCL/PS 3141 * bits in CSR6 and then do a software reset to get the 21140 3142 * to properly reset its internal pathways to the right places. 3143 * Grrrr. 3144 */ 3145 if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0 3146 && sc->tulip_boardsw->bd_media_preset != NULL) 3147 (*sc->tulip_boardsw->bd_media_preset)(sc); 3148 3149 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET); 3150 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at 3151 33MHz that comes to two microseconds but wait a 3152 bit longer anyways) */ 3153 3154 if (!inreset) { 3155 sc->tulip_flags |= TULIP_INRESET; 3156 sc->tulip_flags &= ~(TULIP_NEEDRESET|TULIP_RXBUFSLOW); 3157 sc->tulip_if.if_flags &= ~IFF_OACTIVE; 3158 sc->tulip_if.if_start = tulip_ifstart; 3159 } 3160 3161#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX) 3162 TULIP_CSR_WRITE(sc, csr_txlist, sc->tulip_txdescmap->dm_segs[0].ds_addr); 3163#else 3164 TULIP_CSR_WRITE(sc, csr_txlist, TULIP_KVATOPHYS(sc, &sc->tulip_txinfo.ri_first[0])); 3165#endif 3166#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX) 3167 TULIP_CSR_WRITE(sc, csr_rxlist, sc->tulip_rxdescmap->dm_segs[0].ds_addr); 3168#else 3169 TULIP_CSR_WRITE(sc, csr_rxlist, TULIP_KVATOPHYS(sc, &sc->tulip_rxinfo.ri_first[0])); 3170#endif 3171 TULIP_CSR_WRITE(sc, csr_busmode, 3172 (1 << (3 /*pci_max_burst_len*/ + 8)) 3173 |TULIP_BUSMODE_CACHE_ALIGN8 3174 |TULIP_BUSMODE_READMULTIPLE 3175 |(BYTE_ORDER != LITTLE_ENDIAN ? 3176 TULIP_BUSMODE_DESC_BIGENDIAN : 0)); 3177 3178 sc->tulip_txtimer = 0; 3179 sc->tulip_txq.ifq_maxlen = TULIP_TXDESCS; 3180 /* 3181 * Free all the mbufs that were on the transmit ring. 3182 */ 3183 for (;;) { 3184#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX) 3185 bus_dmamap_t map; 3186#endif 3187 struct mbuf *m; 3188 _IF_DEQUEUE(&sc->tulip_txq, m); 3189 if (m == NULL) 3190 break; 3191#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX) 3192 map = M_GETCTX(m, bus_dmamap_t); 3193 bus_dmamap_unload(sc->tulip_dmatag, map); 3194 sc->tulip_txmaps[sc->tulip_txmaps_free++] = map; 3195#endif 3196 m_freem(m); 3197 } 3198 3199 ri = &sc->tulip_txinfo; 3200 ri->ri_nextin = ri->ri_nextout = ri->ri_first; 3201 ri->ri_free = ri->ri_max; 3202 for (di = ri->ri_first; di < ri->ri_last; di++) 3203 di->d_status = 0; 3204#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX) 3205 bus_dmamap_sync(sc->tulip_dmatag, sc->tulip_txdescmap, 3206 0, sc->tulip_txdescmap->dm_mapsize, 3207 BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE); 3208#endif 3209 3210 /* 3211 * We need to collect all the mbufs were on the 3212 * receive ring before we reinit it either to put 3213 * them back on or to know if we have to allocate 3214 * more. 3215 */ 3216 ri = &sc->tulip_rxinfo; 3217 ri->ri_nextin = ri->ri_nextout = ri->ri_first; 3218 ri->ri_free = ri->ri_max; 3219 for (di = ri->ri_first; di < ri->ri_last; di++) { 3220 di->d_status = 0; 3221 di->d_length1 = 0; di->d_addr1 = 0; 3222 di->d_length2 = 0; di->d_addr2 = 0; 3223 } 3224#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX) 3225 bus_dmamap_sync(sc->tulip_dmatag, sc->tulip_rxdescmap, 3226 0, sc->tulip_rxdescmap->dm_mapsize, 3227 BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE); 3228#endif 3229 for (;;) { 3230#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX) 3231 bus_dmamap_t map; 3232#endif 3233 struct mbuf *m; 3234 _IF_DEQUEUE(&sc->tulip_rxq, m); 3235 if (m == NULL) 3236 break; 3237#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX) 3238 map = M_GETCTX(m, bus_dmamap_t); 3239 bus_dmamap_unload(sc->tulip_dmatag, map); 3240 sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map; 3241#endif 3242 m_freem(m); 3243 } 3244 3245 /* 3246 * If tulip_reset is being called recurisvely, exit quickly knowing 3247 * that when the outer tulip_reset returns all the right stuff will 3248 * have happened. 3249 */ 3250 if (inreset) 3251 return; 3252 3253 sc->tulip_intrmask |= TULIP_STS_NORMALINTR|TULIP_STS_RXINTR|TULIP_STS_TXINTR 3254 |TULIP_STS_ABNRMLINTR|TULIP_STS_SYSERROR|TULIP_STS_TXSTOPPED 3255 |TULIP_STS_TXUNDERFLOW|TULIP_STS_TXBABBLE 3256 |TULIP_STS_RXSTOPPED; 3257 3258 if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0) 3259 (*sc->tulip_boardsw->bd_media_select)(sc); 3260#if defined(TULIP_DEBUG) 3261 if ((sc->tulip_flags & TULIP_NEEDRESET) == TULIP_NEEDRESET) 3262 printf("%s: tulip_reset: additional reset needed?!?\n", 3263 sc->tulip_xname); 3264#endif 3265 if (bootverbose) 3266 tulip_media_print(sc); 3267 if (sc->tulip_features & TULIP_HAVE_DUALSENSE) 3268 TULIP_CSR_WRITE(sc, csr_sia_status, TULIP_CSR_READ(sc, csr_sia_status)); 3269 3270 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_WANTSETUP|TULIP_INRESET 3271 |TULIP_RXACT); 3272 tulip_addr_filter(sc); 3273} 3274 3275 3276static void 3277tulip_ifinit( 3278 void * sc) 3279{ 3280 tulip_init((tulip_softc_t *)sc); 3281} 3282 3283static void 3284tulip_init( 3285 tulip_softc_t * const sc) 3286{ 3287 if (sc->tulip_if.if_flags & IFF_UP) { 3288 if ((sc->tulip_if.if_flags & IFF_RUNNING) == 0) { 3289 /* initialize the media */ 3290 tulip_reset(sc); 3291 } 3292 sc->tulip_if.if_flags |= IFF_RUNNING; 3293 if (sc->tulip_if.if_flags & IFF_PROMISC) { 3294 sc->tulip_flags |= TULIP_PROMISC; 3295 sc->tulip_cmdmode |= TULIP_CMD_PROMISCUOUS; 3296 sc->tulip_intrmask |= TULIP_STS_TXINTR; 3297 } else { 3298 sc->tulip_flags &= ~TULIP_PROMISC; 3299 sc->tulip_cmdmode &= ~TULIP_CMD_PROMISCUOUS; 3300 if (sc->tulip_flags & TULIP_ALLMULTI) { 3301 sc->tulip_cmdmode |= TULIP_CMD_ALLMULTI; 3302 } else { 3303 sc->tulip_cmdmode &= ~TULIP_CMD_ALLMULTI; 3304 } 3305 } 3306 sc->tulip_cmdmode |= TULIP_CMD_TXRUN; 3307 if ((sc->tulip_flags & (TULIP_TXPROBE_ACTIVE|TULIP_WANTSETUP)) == 0) { 3308 tulip_rx_intr(sc); 3309 sc->tulip_cmdmode |= TULIP_CMD_RXRUN; 3310 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED; 3311 } else { 3312 sc->tulip_if.if_flags |= IFF_OACTIVE; 3313 sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN; 3314 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED; 3315 } 3316 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask); 3317 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode); 3318 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP) 3319 tulip_txput_setup(sc); 3320 } else { 3321 sc->tulip_if.if_flags &= ~IFF_RUNNING; 3322 tulip_reset(sc); 3323 } 3324} 3325 3326static void 3327tulip_rx_intr( 3328 tulip_softc_t * const sc) 3329{ 3330 TULIP_PERFSTART(rxintr) 3331 tulip_ringinfo_t * const ri = &sc->tulip_rxinfo; 3332 struct ifnet * const ifp = &sc->tulip_if; 3333 int fillok = 1; 3334#if defined(TULIP_DEBUG) 3335 int cnt = 0; 3336#endif 3337 3338 for (;;) { 3339 TULIP_PERFSTART(rxget) 3340 tulip_desc_t *eop = ri->ri_nextin; 3341 int total_len = 0, last_offset = 0; 3342 struct mbuf *ms = NULL, *me = NULL; 3343 int accept = 0; 3344#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX) 3345 bus_dmamap_t map; 3346 int error; 3347#endif 3348 3349 if (fillok && sc->tulip_rxq.ifq_len < TULIP_RXQ_TARGET) 3350 goto queue_mbuf; 3351 3352#if defined(TULIP_DEBUG) 3353 if (cnt == ri->ri_max) 3354 break; 3355#endif 3356 /* 3357 * If the TULIP has no descriptors, there can't be any receive 3358 * descriptors to process. 3359 */ 3360 if (eop == ri->ri_nextout) 3361 break; 3362 3363 /* 3364 * 90% of the packets will fit in one descriptor. So we optimize 3365 * for that case. 3366 */ 3367 TULIP_RXDESC_POSTSYNC(sc, eop, sizeof(*eop)); 3368 if ((((volatile tulip_desc_t *) eop)->d_status & (TULIP_DSTS_OWNER|TULIP_DSTS_RxFIRSTDESC|TULIP_DSTS_RxLASTDESC)) == (TULIP_DSTS_RxFIRSTDESC|TULIP_DSTS_RxLASTDESC)) { 3369 _IF_DEQUEUE(&sc->tulip_rxq, ms); 3370 me = ms; 3371 } else { 3372 /* 3373 * If still owned by the TULIP, don't touch it. 3374 */ 3375 if (((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER) 3376 break; 3377 3378 /* 3379 * It is possible (though improbable unless the BIG_PACKET support 3380 * is enabled or MCLBYTES < 1518) for a received packet to cross 3381 * more than one receive descriptor. 3382 */ 3383 while ((((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_RxLASTDESC) == 0) { 3384 if (++eop == ri->ri_last) 3385 eop = ri->ri_first; 3386 TULIP_RXDESC_POSTSYNC(sc, eop, sizeof(*eop)); 3387 if (eop == ri->ri_nextout || ((((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER))) { 3388#if defined(TULIP_DEBUG) 3389 sc->tulip_dbg.dbg_rxintrs++; 3390 sc->tulip_dbg.dbg_rxpktsperintr[cnt]++; 3391#endif 3392 TULIP_PERFEND(rxget); 3393 TULIP_PERFEND(rxintr); 3394 return; 3395 } 3396 total_len++; 3397 } 3398 3399 /* 3400 * Dequeue the first buffer for the start of the packet. Hopefully 3401 * this will be the only one we need to dequeue. However, if the 3402 * packet consumed multiple descriptors, then we need to dequeue 3403 * those buffers and chain to the starting mbuf. All buffers but 3404 * the last buffer have the same length so we can set that now. 3405 * (we add to last_offset instead of multiplying since we normally 3406 * won't go into the loop and thereby saving ourselves from 3407 * doing a multiplication by 0 in the normal case). 3408 */ 3409 _IF_DEQUEUE(&sc->tulip_rxq, ms); 3410 for (me = ms; total_len > 0; total_len--) { 3411#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX) 3412 map = M_GETCTX(me, bus_dmamap_t); 3413 TULIP_RXMAP_POSTSYNC(sc, map); 3414 bus_dmamap_unload(sc->tulip_dmatag, map); 3415 sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map; 3416#if defined(DIAGNOSTIC) 3417 M_SETCTX(me, NULL); 3418#endif 3419#endif /* TULIP_BUS_DMA */ 3420 me->m_len = TULIP_RX_BUFLEN; 3421 last_offset += TULIP_RX_BUFLEN; 3422 _IF_DEQUEUE(&sc->tulip_rxq, me->m_next); 3423 me = me->m_next; 3424 } 3425 } 3426 3427 /* 3428 * Now get the size of received packet (minus the CRC). 3429 */ 3430 total_len = ((eop->d_status >> 16) & 0x7FFF) - 4; 3431 if ((sc->tulip_flags & TULIP_RXIGNORE) == 0 3432 && ((eop->d_status & TULIP_DSTS_ERRSUM) == 0 3433#ifdef BIG_PACKET 3434 || (total_len <= sc->tulip_if.if_mtu + sizeof(struct ether_header) && 3435 (eop->d_status & (TULIP_DSTS_RxBADLENGTH|TULIP_DSTS_RxRUNT| 3436 TULIP_DSTS_RxCOLLSEEN|TULIP_DSTS_RxBADCRC| 3437 TULIP_DSTS_RxOVERFLOW)) == 0) 3438#endif 3439 )) { 3440 me->m_len = total_len - last_offset; 3441 3442#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX) 3443 map = M_GETCTX(me, bus_dmamap_t); 3444 bus_dmamap_sync(sc->tulip_dmatag, map, 0, me->m_len, 3445 BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE); 3446 bus_dmamap_unload(sc->tulip_dmatag, map); 3447 sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map; 3448#if defined(DIAGNOSTIC) 3449 M_SETCTX(me, NULL); 3450#endif 3451#endif /* TULIP_BUS_DMA */ 3452 3453#ifndef __FreeBSD__ 3454 if (sc->tulip_if.if_bpf != NULL) { 3455 if (me == ms) 3456 bpf_tap(&sc->tulip_if, mtod(ms, caddr_t), total_len); 3457 else 3458 bpf_mtap(&sc->tulip_if, ms); 3459 } 3460#endif 3461 sc->tulip_flags |= TULIP_RXACT; 3462 accept = 1; 3463 } else { 3464 ifp->if_ierrors++; 3465 if (eop->d_status & (TULIP_DSTS_RxBADLENGTH|TULIP_DSTS_RxOVERFLOW|TULIP_DSTS_RxWATCHDOG)) { 3466 sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++; 3467 } else { 3468#if defined(TULIP_VERBOSE) 3469 const char *error = NULL; 3470#endif 3471 if (eop->d_status & TULIP_DSTS_RxTOOLONG) { 3472 sc->tulip_dot3stats.dot3StatsFrameTooLongs++; 3473#if defined(TULIP_VERBOSE) 3474 error = "frame too long"; 3475#endif 3476 } 3477 if (eop->d_status & TULIP_DSTS_RxBADCRC) { 3478 if (eop->d_status & TULIP_DSTS_RxDRBBLBIT) { 3479 sc->tulip_dot3stats.dot3StatsAlignmentErrors++; 3480#if defined(TULIP_VERBOSE) 3481 error = "alignment error"; 3482#endif 3483 } else { 3484 sc->tulip_dot3stats.dot3StatsFCSErrors++; 3485#if defined(TULIP_VERBOSE) 3486 error = "bad crc"; 3487#endif 3488 } 3489 } 3490#if defined(TULIP_VERBOSE) 3491 if (error != NULL && (sc->tulip_flags & TULIP_NOMESSAGES) == 0) { 3492 printf("%s: receive: %6D: %s\n", 3493 sc->tulip_xname, 3494 mtod(ms, u_char *) + 6, ":", 3495 error); 3496 sc->tulip_flags |= TULIP_NOMESSAGES; 3497 } 3498#endif 3499 } 3500 3501#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX) 3502 map = M_GETCTX(me, bus_dmamap_t); 3503 bus_dmamap_unload(sc->tulip_dmatag, map); 3504 sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map; 3505#if defined(DIAGNOSTIC) 3506 M_SETCTX(me, NULL); 3507#endif 3508#endif /* TULIP_BUS_DMA */ 3509 } 3510#if defined(TULIP_DEBUG) 3511 cnt++; 3512#endif 3513 ifp->if_ipackets++; 3514 if (++eop == ri->ri_last) 3515 eop = ri->ri_first; 3516 ri->ri_nextin = eop; 3517 queue_mbuf: 3518 /* 3519 * Either we are priming the TULIP with mbufs (m == NULL) 3520 * or we are about to accept an mbuf for the upper layers 3521 * so we need to allocate an mbuf to replace it. If we 3522 * can't replace it, send up it anyways. This may cause 3523 * us to drop packets in the future but that's better than 3524 * being caught in livelock. 3525 * 3526 * Note that if this packet crossed multiple descriptors 3527 * we don't even try to reallocate all the mbufs here. 3528 * Instead we rely on the test of the beginning of 3529 * the loop to refill for the extra consumed mbufs. 3530 */ 3531 if (accept || ms == NULL) { 3532 struct mbuf *m0; 3533 MGETHDR(m0, M_DONTWAIT, MT_DATA); 3534 if (m0 != NULL) { 3535#if defined(TULIP_COPY_RXDATA) 3536 if (!accept || total_len >= (MHLEN - 2)) { 3537#endif 3538 MCLGET(m0, M_DONTWAIT); 3539 if ((m0->m_flags & M_EXT) == 0) { 3540 m_freem(m0); 3541 m0 = NULL; 3542 } 3543#if defined(TULIP_COPY_RXDATA) 3544 } 3545#endif 3546 } 3547 if (accept 3548#if defined(TULIP_COPY_RXDATA) 3549 && m0 != NULL 3550#endif 3551 ) { 3552#if !defined(TULIP_COPY_RXDATA) 3553 ms->m_pkthdr.len = total_len; 3554 ms->m_pkthdr.rcvif = ifp; 3555 (*ifp->if_input)(ifp, ms); 3556#else 3557#ifdef BIG_PACKET 3558#error BIG_PACKET is incompatible with TULIP_COPY_RXDATA 3559#endif 3560 m0->m_data += 2; /* align data after header */ 3561 m_copydata(ms, 0, total_len, mtod(m0, caddr_t)); 3562 m0->m_len = m0->m_pkthdr.len = total_len; 3563 m0->m_pkthdr.rcvif = ifp; 3564 (*ifp->if_input)(ifp, m0); 3565 m0 = ms; 3566#endif /* ! TULIP_COPY_RXDATA */ 3567 } 3568 ms = m0; 3569 } 3570 if (ms == NULL) { 3571 /* 3572 * Couldn't allocate a new buffer. Don't bother 3573 * trying to replenish the receive queue. 3574 */ 3575 fillok = 0; 3576 sc->tulip_flags |= TULIP_RXBUFSLOW; 3577#if defined(TULIP_DEBUG) 3578 sc->tulip_dbg.dbg_rxlowbufs++; 3579#endif 3580 TULIP_PERFEND(rxget); 3581 continue; 3582 } 3583 /* 3584 * Now give the buffer(s) to the TULIP and save in our 3585 * receive queue. 3586 */ 3587 do { 3588 tulip_desc_t * const nextout = ri->ri_nextout; 3589#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX) 3590 if (sc->tulip_rxmaps_free > 0) { 3591 map = sc->tulip_rxmaps[--sc->tulip_rxmaps_free]; 3592 } else { 3593 m_freem(ms); 3594 sc->tulip_flags |= TULIP_RXBUFSLOW; 3595#if defined(TULIP_DEBUG) 3596 sc->tulip_dbg.dbg_rxlowbufs++; 3597#endif 3598 break; 3599 } 3600 M_SETCTX(ms, map); 3601 error = bus_dmamap_load(sc->tulip_dmatag, map, mtod(ms, void *), 3602 TULIP_RX_BUFLEN, NULL, BUS_DMA_NOWAIT); 3603 if (error) { 3604 printf("%s: unable to load rx map, " 3605 "error = %d\n", sc->tulip_xname, error); 3606 panic("tulip_rx_intr"); /* XXX */ 3607 } 3608 nextout->d_addr1 = map->dm_segs[0].ds_addr; 3609 nextout->d_length1 = map->dm_segs[0].ds_len; 3610 if (map->dm_nsegs == 2) { 3611 nextout->d_addr2 = map->dm_segs[1].ds_addr; 3612 nextout->d_length2 = map->dm_segs[1].ds_len; 3613 } else { 3614 nextout->d_addr2 = 0; 3615 nextout->d_length2 = 0; 3616 } 3617 TULIP_RXDESC_POSTSYNC(sc, nextout, sizeof(*nextout)); 3618#else /* TULIP_BUS_DMA */ 3619 nextout->d_addr1 = TULIP_KVATOPHYS(sc, mtod(ms, caddr_t)); 3620 nextout->d_length1 = TULIP_RX_BUFLEN; 3621#endif /* TULIP_BUS_DMA */ 3622 nextout->d_status = TULIP_DSTS_OWNER; 3623 TULIP_RXDESC_POSTSYNC(sc, nextout, sizeof(u_int32_t)); 3624 if (++ri->ri_nextout == ri->ri_last) 3625 ri->ri_nextout = ri->ri_first; 3626 me = ms->m_next; 3627 ms->m_next = NULL; 3628 _IF_ENQUEUE(&sc->tulip_rxq, ms); 3629 } while ((ms = me) != NULL); 3630 3631 if (sc->tulip_rxq.ifq_len >= TULIP_RXQ_TARGET) 3632 sc->tulip_flags &= ~TULIP_RXBUFSLOW; 3633 TULIP_PERFEND(rxget); 3634 } 3635 3636#if defined(TULIP_DEBUG) 3637 sc->tulip_dbg.dbg_rxintrs++; 3638 sc->tulip_dbg.dbg_rxpktsperintr[cnt]++; 3639#endif 3640 TULIP_PERFEND(rxintr); 3641} 3642 3643static int 3644tulip_tx_intr( 3645 tulip_softc_t * const sc) 3646{ 3647 TULIP_PERFSTART(txintr) 3648 tulip_ringinfo_t * const ri = &sc->tulip_txinfo; 3649 struct mbuf *m; 3650 int xmits = 0; 3651 int descs = 0; 3652 3653 while (ri->ri_free < ri->ri_max) { 3654 u_int32_t d_flag; 3655 3656 TULIP_TXDESC_POSTSYNC(sc, ri->ri_nextin, sizeof(*ri->ri_nextin)); 3657 if (((volatile tulip_desc_t *) ri->ri_nextin)->d_status & TULIP_DSTS_OWNER) 3658 break; 3659 3660 ri->ri_free++; 3661 descs++; 3662 d_flag = ri->ri_nextin->d_flag; 3663 if (d_flag & TULIP_DFLAG_TxLASTSEG) { 3664 if (d_flag & TULIP_DFLAG_TxSETUPPKT) { 3665 /* 3666 * We've just finished processing a setup packet. 3667 * Mark that we finished it. If there's not 3668 * another pending, startup the TULIP receiver. 3669 * Make sure we ack the RXSTOPPED so we won't get 3670 * an abormal interrupt indication. 3671 */ 3672 TULIP_TXMAP_POSTSYNC(sc, sc->tulip_setupmap); 3673 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_HASHONLY); 3674 if (ri->ri_nextin->d_flag & TULIP_DFLAG_TxINVRSFILT) 3675 sc->tulip_flags |= TULIP_HASHONLY; 3676 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == 0) { 3677 tulip_rx_intr(sc); 3678 sc->tulip_cmdmode |= TULIP_CMD_RXRUN; 3679 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED; 3680 TULIP_CSR_WRITE(sc, csr_status, TULIP_STS_RXSTOPPED); 3681 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask); 3682 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode); 3683 } 3684 } else { 3685 const u_int32_t d_status = ri->ri_nextin->d_status; 3686 _IF_DEQUEUE(&sc->tulip_txq, m); 3687 if (m != NULL) { 3688#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX) 3689 bus_dmamap_t map = M_GETCTX(m, bus_dmamap_t); 3690 TULIP_TXMAP_POSTSYNC(sc, map); 3691 sc->tulip_txmaps[sc->tulip_txmaps_free++] = map; 3692#endif /* TULIP_BUS_DMA */ 3693 m_freem(m); 3694#if defined(TULIP_DEBUG) 3695 } else { 3696 printf("%s: tx_intr: failed to dequeue mbuf?!?\n", 3697 sc->tulip_xname); 3698#endif 3699 } 3700 if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) { 3701 tulip_mediapoll_event_t event = TULIP_MEDIAPOLL_TXPROBE_OK; 3702 if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxEXCCOLL)) { 3703#if defined(TULIP_DEBUG) 3704 if (d_status & TULIP_DSTS_TxNOCARR) 3705 sc->tulip_dbg.dbg_txprobe_nocarr++; 3706 if (d_status & TULIP_DSTS_TxEXCCOLL) 3707 sc->tulip_dbg.dbg_txprobe_exccoll++; 3708#endif 3709 event = TULIP_MEDIAPOLL_TXPROBE_FAILED; 3710 } 3711 (*sc->tulip_boardsw->bd_media_poll)(sc, event); 3712 /* 3713 * Escape from the loop before media poll has reset the TULIP! 3714 */ 3715 break; 3716 } else { 3717 xmits++; 3718 if (d_status & TULIP_DSTS_ERRSUM) { 3719 sc->tulip_if.if_oerrors++; 3720 if (d_status & TULIP_DSTS_TxEXCCOLL) 3721 sc->tulip_dot3stats.dot3StatsExcessiveCollisions++; 3722 if (d_status & TULIP_DSTS_TxLATECOLL) 3723 sc->tulip_dot3stats.dot3StatsLateCollisions++; 3724 if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxCARRLOSS)) 3725 sc->tulip_dot3stats.dot3StatsCarrierSenseErrors++; 3726 if (d_status & (TULIP_DSTS_TxUNDERFLOW|TULIP_DSTS_TxBABBLE)) 3727 sc->tulip_dot3stats.dot3StatsInternalMacTransmitErrors++; 3728 if (d_status & TULIP_DSTS_TxUNDERFLOW) 3729 sc->tulip_dot3stats.dot3StatsInternalTransmitUnderflows++; 3730 if (d_status & TULIP_DSTS_TxBABBLE) 3731 sc->tulip_dot3stats.dot3StatsInternalTransmitBabbles++; 3732 } else { 3733 u_int32_t collisions = 3734 (d_status & TULIP_DSTS_TxCOLLMASK) 3735 >> TULIP_DSTS_V_TxCOLLCNT; 3736 sc->tulip_if.if_collisions += collisions; 3737 if (collisions == 1) 3738 sc->tulip_dot3stats.dot3StatsSingleCollisionFrames++; 3739 else if (collisions > 1) 3740 sc->tulip_dot3stats.dot3StatsMultipleCollisionFrames++; 3741 else if (d_status & TULIP_DSTS_TxDEFERRED) 3742 sc->tulip_dot3stats.dot3StatsDeferredTransmissions++; 3743 /* 3744 * SQE is only valid for 10baseT/BNC/AUI when not 3745 * running in full-duplex. In order to speed up the 3746 * test, the corresponding bit in tulip_flags needs to 3747 * set as well to get us to count SQE Test Errors. 3748 */ 3749 if (d_status & TULIP_DSTS_TxNOHRTBT & sc->tulip_flags) 3750 sc->tulip_dot3stats.dot3StatsSQETestErrors++; 3751 } 3752 } 3753 } 3754 } 3755 3756 if (++ri->ri_nextin == ri->ri_last) 3757 ri->ri_nextin = ri->ri_first; 3758 3759 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0) 3760 sc->tulip_if.if_flags &= ~IFF_OACTIVE; 3761 } 3762 /* 3763 * If nothing left to transmit, disable the timer. 3764 * Else if progress, reset the timer back to 2 ticks. 3765 */ 3766 if (ri->ri_free == ri->ri_max || (sc->tulip_flags & TULIP_TXPROBE_ACTIVE)) 3767 sc->tulip_txtimer = 0; 3768 else if (xmits > 0) 3769 sc->tulip_txtimer = TULIP_TXTIMER; 3770 sc->tulip_if.if_opackets += xmits; 3771 TULIP_PERFEND(txintr); 3772 return descs; 3773} 3774 3775static void 3776tulip_print_abnormal_interrupt( 3777 tulip_softc_t * const sc, 3778 u_int32_t csr) 3779{ 3780 const char * const *msgp = tulip_status_bits; 3781 const char *sep; 3782 u_int32_t mask; 3783 const char thrsh[] = "72|128\0\0\0" "96|256\0\0\0" "128|512\0\0" "160|1024"; 3784 3785 csr &= (1 << (sizeof(tulip_status_bits)/sizeof(tulip_status_bits[0]))) - 1; 3786 printf("%s: abnormal interrupt:", sc->tulip_xname); 3787 for (sep = " ", mask = 1; mask <= csr; mask <<= 1, msgp++) { 3788 if ((csr & mask) && *msgp != NULL) { 3789 printf("%s%s", sep, *msgp); 3790 if (mask == TULIP_STS_TXUNDERFLOW && (sc->tulip_flags & TULIP_NEWTXTHRESH)) { 3791 sc->tulip_flags &= ~TULIP_NEWTXTHRESH; 3792 if (sc->tulip_cmdmode & TULIP_CMD_STOREFWD) { 3793 printf(" (switching to store-and-forward mode)"); 3794 } else { 3795 printf(" (raising TX threshold to %s)", 3796 &thrsh[9 * ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) >> 14)]); 3797 } 3798 } 3799 sep = ", "; 3800 } 3801 } 3802 printf("\n"); 3803} 3804 3805static void 3806tulip_intr_handler( 3807 tulip_softc_t * const sc, 3808 int *progress_p) 3809{ 3810 TULIP_PERFSTART(intr) 3811 u_int32_t csr; 3812 3813 while ((csr = TULIP_CSR_READ(sc, csr_status)) & sc->tulip_intrmask) { 3814 *progress_p = 1; 3815 TULIP_CSR_WRITE(sc, csr_status, csr); 3816 3817 if (csr & TULIP_STS_SYSERROR) { 3818 sc->tulip_last_system_error = (csr & TULIP_STS_ERRORMASK) >> TULIP_STS_ERR_SHIFT; 3819 if (sc->tulip_flags & TULIP_NOMESSAGES) { 3820 sc->tulip_flags |= TULIP_SYSTEMERROR; 3821 } else { 3822 printf("%s: system error: %s\n", 3823 sc->tulip_xname, 3824 tulip_system_errors[sc->tulip_last_system_error]); 3825 } 3826 sc->tulip_flags |= TULIP_NEEDRESET; 3827 sc->tulip_system_errors++; 3828 break; 3829 } 3830 if (csr & (TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL) & sc->tulip_intrmask) { 3831#if defined(TULIP_DEBUG) 3832 sc->tulip_dbg.dbg_link_intrs++; 3833#endif 3834 if (sc->tulip_boardsw->bd_media_poll != NULL) { 3835 (*sc->tulip_boardsw->bd_media_poll)(sc, csr & TULIP_STS_LINKFAIL 3836 ? TULIP_MEDIAPOLL_LINKFAIL 3837 : TULIP_MEDIAPOLL_LINKPASS); 3838 csr &= ~TULIP_STS_ABNRMLINTR; 3839 } 3840 tulip_media_print(sc); 3841 } 3842 if (csr & (TULIP_STS_RXINTR|TULIP_STS_RXNOBUF)) { 3843 u_int32_t misses = TULIP_CSR_READ(sc, csr_missed_frames); 3844 if (csr & TULIP_STS_RXNOBUF) 3845 sc->tulip_dot3stats.dot3StatsMissedFrames += misses & 0xFFFF; 3846 /* 3847 * Pass 2.[012] of the 21140A-A[CDE] may hang and/or corrupt data 3848 * on receive overflows. 3849 */ 3850 if ((misses & 0x0FFE0000) && (sc->tulip_features & TULIP_HAVE_RXBADOVRFLW)) { 3851 sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++; 3852 /* 3853 * Stop the receiver process and spin until it's stopped. 3854 * Tell rx_intr to drop the packets it dequeues. 3855 */ 3856 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode & ~TULIP_CMD_RXRUN); 3857 while ((TULIP_CSR_READ(sc, csr_status) & TULIP_STS_RXSTOPPED) == 0) 3858 ; 3859 TULIP_CSR_WRITE(sc, csr_status, TULIP_STS_RXSTOPPED); 3860 sc->tulip_flags |= TULIP_RXIGNORE; 3861 } 3862 tulip_rx_intr(sc); 3863 if (sc->tulip_flags & TULIP_RXIGNORE) { 3864 /* 3865 * Restart the receiver. 3866 */ 3867 sc->tulip_flags &= ~TULIP_RXIGNORE; 3868 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode); 3869 } 3870 } 3871 if (csr & TULIP_STS_ABNRMLINTR) { 3872 u_int32_t tmp = csr & sc->tulip_intrmask 3873 & ~(TULIP_STS_NORMALINTR|TULIP_STS_ABNRMLINTR); 3874 if (csr & TULIP_STS_TXUNDERFLOW) { 3875 if ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) != TULIP_CMD_THRSHLD160) { 3876 sc->tulip_cmdmode += TULIP_CMD_THRSHLD96; 3877 sc->tulip_flags |= TULIP_NEWTXTHRESH; 3878 } else if (sc->tulip_features & TULIP_HAVE_STOREFWD) { 3879 sc->tulip_cmdmode |= TULIP_CMD_STOREFWD; 3880 sc->tulip_flags |= TULIP_NEWTXTHRESH; 3881 } 3882 } 3883 if (sc->tulip_flags & TULIP_NOMESSAGES) { 3884 sc->tulip_statusbits |= tmp; 3885 } else { 3886 tulip_print_abnormal_interrupt(sc, tmp); 3887 sc->tulip_flags |= TULIP_NOMESSAGES; 3888 } 3889 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode); 3890 } 3891 if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_TXPROBE_ACTIVE|TULIP_DOINGSETUP|TULIP_PROMISC)) { 3892 tulip_tx_intr(sc); 3893 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0) 3894 tulip_ifstart(&sc->tulip_if); 3895 } 3896 } 3897 if (sc->tulip_flags & TULIP_NEEDRESET) { 3898 tulip_reset(sc); 3899 tulip_init(sc); 3900 } 3901 TULIP_PERFEND(intr); 3902} 3903 3904#if defined(TULIP_USE_SOFTINTR) 3905/* 3906 * This is an experimental idea to alleviate problems due to interrupt 3907 * livelock. What is interrupt livelock? It's when you spend all your 3908 * time servicing device interrupts and never drop below device ipl 3909 * to do "useful" work. 3910 * 3911 * So what we do here is see if the device needs service and if so, 3912 * disable interrupts (dismiss the interrupt), place it in a list of devices 3913 * needing service, and issue a network software interrupt. 3914 * 3915 * When our network software interrupt routine gets called, we simply 3916 * walk done the list of devices that we have created and deal with them 3917 * at splnet/splsoftnet. 3918 * 3919 */ 3920static void 3921tulip_hardintr_handler( 3922 tulip_softc_t * const sc, 3923 int *progress_p) 3924{ 3925 if (TULIP_CSR_READ(sc, csr_status) & (TULIP_STS_NORMALINTR|TULIP_STS_ABNRMLINTR) == 0) 3926 return; 3927 *progress_p = 1; 3928 /* 3929 * disable interrupts 3930 */ 3931 TULIP_CSR_WRITE(sc, csr_intr, 0); 3932 /* 3933 * mark it as needing a software interrupt 3934 */ 3935 tulip_softintr_mask |= (1U << sc->tulip_unit); 3936} 3937 3938static void 3939tulip_softintr( 3940 void) 3941{ 3942 u_int32_t softintr_mask, mask; 3943 int progress = 0; 3944 int unit; 3945 int s; 3946 3947 /* 3948 * Copy mask to local copy and reset global one to 0. 3949 */ 3950 s = splimp(); 3951 softintr_mask = tulip_softintr_mask; 3952 tulip_softintr_mask = 0; 3953 splx(s); 3954 3955 /* 3956 * Optimize for the single unit case. 3957 */ 3958 if (tulip_softintr_max_unit == 0) { 3959 if (softintr_mask & 1) { 3960 tulip_softc_t * const sc = tulips[0]; 3961 /* 3962 * Handle the "interrupt" and then reenable interrupts 3963 */ 3964 softintr_mask = 0; 3965 tulip_intr_handler(sc, &progress); 3966 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask); 3967 } 3968 return; 3969 } 3970 3971 /* 3972 * Handle all "queued" interrupts in a round robin fashion. 3973 * This is done so as not to favor a particular interface. 3974 */ 3975 unit = tulip_softintr_last_unit; 3976 mask = (1U << unit); 3977 while (softintr_mask != 0) { 3978 if (tulip_softintr_max_unit == unit) { 3979 unit = 0; mask = 1; 3980 } else { 3981 unit += 1; mask <<= 1; 3982 } 3983 if (softintr_mask & mask) { 3984 tulip_softc_t * const sc = tulips[unit]; 3985 /* 3986 * Handle the "interrupt" and then reenable interrupts 3987 */ 3988 softintr_mask ^= mask; 3989 tulip_intr_handler(sc, &progress); 3990 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask); 3991 } 3992 } 3993 3994 /* 3995 * Save where we ending up. 3996 */ 3997 tulip_softintr_last_unit = unit; 3998} 3999#endif /* TULIP_USE_SOFTINTR */ 4000 4001static void 4002tulip_intr_shared( 4003 void *arg) 4004{ 4005 tulip_softc_t * sc = arg; 4006 int progress = 0; 4007 4008 for (; sc != NULL; sc = sc->tulip_slaves) { 4009#if defined(TULIP_DEBUG) 4010 sc->tulip_dbg.dbg_intrs++; 4011#endif 4012#if defined(TULIP_USE_SOFTINTR) 4013 tulip_hardintr_handler(sc, &progress); 4014#else 4015 tulip_intr_handler(sc, &progress); 4016#endif 4017 } 4018#if defined(TULIP_USE_SOFTINTR) 4019 if (progress) 4020 schednetisr(NETISR_DE); 4021#endif 4022} 4023 4024static void 4025tulip_intr_normal( 4026 void *arg) 4027{ 4028 tulip_softc_t * sc = (tulip_softc_t *) arg; 4029 int progress = 0; 4030 4031#if defined(TULIP_DEBUG) 4032 sc->tulip_dbg.dbg_intrs++; 4033#endif 4034#if defined(TULIP_USE_SOFTINTR) 4035 tulip_hardintr_handler(sc, &progress); 4036 if (progress) 4037 schednetisr(NETISR_DE); 4038#else 4039 tulip_intr_handler(sc, &progress); 4040#endif 4041} 4042 4043static struct mbuf * 4044tulip_mbuf_compress( 4045 struct mbuf *m) 4046{ 4047 struct mbuf *m0; 4048#if MCLBYTES >= ETHERMTU + 18 && !defined(BIG_PACKET) 4049 MGETHDR(m0, M_DONTWAIT, MT_DATA); 4050 if (m0 != NULL) { 4051 if (m->m_pkthdr.len > MHLEN) { 4052 MCLGET(m0, M_DONTWAIT); 4053 if ((m0->m_flags & M_EXT) == 0) { 4054 m_freem(m); 4055 m_freem(m0); 4056 return NULL; 4057 } 4058 } 4059 m_copydata(m, 0, m->m_pkthdr.len, mtod(m0, caddr_t)); 4060 m0->m_pkthdr.len = m0->m_len = m->m_pkthdr.len; 4061 } 4062#else 4063 int mlen = MHLEN; 4064 int len = m->m_pkthdr.len; 4065 struct mbuf **mp = &m0; 4066 4067 while (len > 0) { 4068 if (mlen == MHLEN) { 4069 MGETHDR(*mp, M_DONTWAIT, MT_DATA); 4070 } else { 4071 MGET(*mp, M_DONTWAIT, MT_DATA); 4072 } 4073 if (*mp == NULL) { 4074 m_freem(m0); 4075 m0 = NULL; 4076 break; 4077 } 4078 if (len > MLEN) { 4079 MCLGET(*mp, M_DONTWAIT); 4080 if (((*mp)->m_flags & M_EXT) == 0) { 4081 m_freem(m0); 4082 m0 = NULL; 4083 break; 4084 } 4085 (*mp)->m_len = len <= MCLBYTES ? len : MCLBYTES; 4086 } else { 4087 (*mp)->m_len = len <= mlen ? len : mlen; 4088 } 4089 m_copydata(m, m->m_pkthdr.len - len, 4090 (*mp)->m_len, mtod((*mp), caddr_t)); 4091 len -= (*mp)->m_len; 4092 mp = &(*mp)->m_next; 4093 mlen = MLEN; 4094 } 4095#endif 4096 m_freem(m); 4097 return m0; 4098} 4099 4100static struct mbuf * 4101tulip_txput( 4102 tulip_softc_t * const sc, 4103 struct mbuf *m) 4104{ 4105 TULIP_PERFSTART(txput) 4106 tulip_ringinfo_t * const ri = &sc->tulip_txinfo; 4107 tulip_desc_t *eop, *nextout; 4108 int segcnt, free; 4109 u_int32_t d_status; 4110#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX) 4111 bus_dmamap_t map; 4112 int error; 4113#else 4114 struct mbuf *m0; 4115#endif 4116 4117#if defined(TULIP_DEBUG) 4118 if ((sc->tulip_cmdmode & TULIP_CMD_TXRUN) == 0) { 4119 printf("%s: txput%s: tx not running\n", 4120 sc->tulip_xname, 4121 (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) ? "(probe)" : ""); 4122 sc->tulip_flags |= TULIP_WANTTXSTART; 4123 sc->tulip_dbg.dbg_txput_finishes[0]++; 4124 goto finish; 4125 } 4126#endif 4127 4128 /* 4129 * Now we try to fill in our transmit descriptors. This is 4130 * a bit reminiscent of going on the Ark two by two 4131 * since each descriptor for the TULIP can describe 4132 * two buffers. So we advance through packet filling 4133 * each of the two entries at a time to to fill each 4134 * descriptor. Clear the first and last segment bits 4135 * in each descriptor (actually just clear everything 4136 * but the end-of-ring or chain bits) to make sure 4137 * we don't get messed up by previously sent packets. 4138 * 4139 * We may fail to put the entire packet on the ring if 4140 * there is either not enough ring entries free or if the 4141 * packet has more than MAX_TXSEG segments. In the former 4142 * case we will just wait for the ring to empty. In the 4143 * latter case we have to recopy. 4144 */ 4145#if !defined(TULIP_BUS_DMA) || defined(TULIP_BUS_DMA_NOTX) 4146 again: 4147 m0 = m; 4148#endif 4149 d_status = 0; 4150 eop = nextout = ri->ri_nextout; 4151 segcnt = 0; 4152 free = ri->ri_free; 4153 4154#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX) 4155 /* 4156 * Reclaim some dma maps from if we are out. 4157 */ 4158 if (sc->tulip_txmaps_free == 0) { 4159#if defined(TULIP_DEBUG) 4160 sc->tulip_dbg.dbg_no_txmaps++; 4161#endif 4162 free += tulip_tx_intr(sc); 4163 } 4164 if (sc->tulip_txmaps_free > 0) { 4165 map = sc->tulip_txmaps[sc->tulip_txmaps_free-1]; 4166 } else { 4167 sc->tulip_flags |= TULIP_WANTTXSTART; 4168#if defined(TULIP_DEBUG) 4169 sc->tulip_dbg.dbg_txput_finishes[1]++; 4170#endif 4171 goto finish; 4172 } 4173 error = bus_dmamap_load_mbuf(sc->tulip_dmatag, map, m, BUS_DMA_NOWAIT); 4174 if (error != 0) { 4175 if (error == EFBIG) { 4176 /* 4177 * The packet exceeds the number of transmit buffer 4178 * entries that we can use for one packet, so we have 4179 * to recopy it into one mbuf and then try again. 4180 */ 4181 m = tulip_mbuf_compress(m); 4182 if (m == NULL) { 4183#if defined(TULIP_DEBUG) 4184 sc->tulip_dbg.dbg_txput_finishes[2]++; 4185#endif 4186 goto finish; 4187 } 4188 error = bus_dmamap_load_mbuf(sc->tulip_dmatag, map, m, BUS_DMA_NOWAIT); 4189 } 4190 if (error != 0) { 4191 printf("%s: unable to load tx map, " 4192 "error = %d\n", sc->tulip_xname, error); 4193#if defined(TULIP_DEBUG) 4194 sc->tulip_dbg.dbg_txput_finishes[3]++; 4195#endif 4196 goto finish; 4197 } 4198 } 4199 if ((free -= (map->dm_nsegs + 1) / 2) <= 0 4200 /* 4201 * See if there's any unclaimed space in the transmit ring. 4202 */ 4203 && (free += tulip_tx_intr(sc)) <= 0) { 4204 /* 4205 * There's no more room but since nothing 4206 * has been committed at this point, just 4207 * show output is active, put back the 4208 * mbuf and return. 4209 */ 4210 sc->tulip_flags |= TULIP_WANTTXSTART; 4211#if defined(TULIP_DEBUG) 4212 sc->tulip_dbg.dbg_txput_finishes[4]++; 4213#endif 4214 bus_dmamap_unload(sc->tulip_dmatag, map); 4215 goto finish; 4216 } 4217 for (; map->dm_nsegs - segcnt > 1; segcnt += 2) { 4218 eop = nextout; 4219 eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN; 4220 eop->d_status = d_status; 4221 eop->d_addr1 = map->dm_segs[segcnt].ds_addr; 4222 eop->d_length1 = map->dm_segs[segcnt].ds_len; 4223 eop->d_addr2 = map->dm_segs[segcnt+1].ds_addr; 4224 eop->d_length2 = map->dm_segs[segcnt+1].ds_len; 4225 d_status = TULIP_DSTS_OWNER; 4226 if (++nextout == ri->ri_last) 4227 nextout = ri->ri_first; 4228 } 4229 if (segcnt < map->dm_nsegs) { 4230 eop = nextout; 4231 eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN; 4232 eop->d_status = d_status; 4233 eop->d_addr1 = map->dm_segs[segcnt].ds_addr; 4234 eop->d_length1 = map->dm_segs[segcnt].ds_len; 4235 eop->d_addr2 = 0; 4236 eop->d_length2 = 0; 4237 if (++nextout == ri->ri_last) 4238 nextout = ri->ri_first; 4239 } 4240 TULIP_TXMAP_PRESYNC(sc, map); 4241 M_SETCTX(m, map); 4242 map = NULL; 4243 --sc->tulip_txmaps_free; /* commit to using the dmamap */ 4244 4245#else /* !TULIP_BUS_DMA */ 4246 4247 do { 4248 int len = m0->m_len; 4249 caddr_t addr = mtod(m0, caddr_t); 4250 unsigned clsize = PAGE_SIZE - (((uintptr_t) addr) & (PAGE_SIZE-1)); 4251 4252 while (len > 0) { 4253 unsigned slen = min(len, clsize); 4254#ifdef BIG_PACKET 4255 int partial = 0; 4256 if (slen >= 2048) 4257 slen = 2040, partial = 1; 4258#endif 4259 segcnt++; 4260 if (segcnt > TULIP_MAX_TXSEG) { 4261 /* 4262 * The packet exceeds the number of transmit buffer 4263 * entries that we can use for one packet, so we have 4264 * recopy it into one mbuf and then try again. 4265 */ 4266 m = tulip_mbuf_compress(m); 4267 if (m == NULL) 4268 goto finish; 4269 goto again; 4270 } 4271 if (segcnt & 1) { 4272 if (--free == 0) { 4273 /* 4274 * See if there's any unclaimed space in the 4275 * transmit ring. 4276 */ 4277 if ((free += tulip_tx_intr(sc)) == 0) { 4278 /* 4279 * There's no more room but since nothing 4280 * has been committed at this point, just 4281 * show output is active, put back the 4282 * mbuf and return. 4283 */ 4284 sc->tulip_flags |= TULIP_WANTTXSTART; 4285#if defined(TULIP_DEBUG) 4286 sc->tulip_dbg.dbg_txput_finishes[1]++; 4287#endif 4288 goto finish; 4289 } 4290 } 4291 eop = nextout; 4292 if (++nextout == ri->ri_last) 4293 nextout = ri->ri_first; 4294 eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN; 4295 eop->d_status = d_status; 4296 eop->d_addr1 = TULIP_KVATOPHYS(sc, addr); 4297 eop->d_length1 = slen; 4298 } else { 4299 /* 4300 * Fill in second half of descriptor 4301 */ 4302 eop->d_addr2 = TULIP_KVATOPHYS(sc, addr); 4303 eop->d_length2 = slen; 4304 } 4305 d_status = TULIP_DSTS_OWNER; 4306 len -= slen; 4307 addr += slen; 4308#ifdef BIG_PACKET 4309 if (partial) 4310 continue; 4311#endif 4312 clsize = PAGE_SIZE; 4313 } 4314 } while ((m0 = m0->m_next) != NULL); 4315#endif /* TULIP_BUS_DMA */ 4316 4317 /* 4318 * bounce a copy to the bpf listener, if any. 4319 */ 4320 BPF_MTAP(&sc->tulip_if, m); 4321 4322 /* 4323 * The descriptors have been filled in. Now get ready 4324 * to transmit. 4325 */ 4326 _IF_ENQUEUE(&sc->tulip_txq, m); 4327 m = NULL; 4328 4329 /* 4330 * Make sure the next descriptor after this packet is owned 4331 * by us since it may have been set up above if we ran out 4332 * of room in the ring. 4333 */ 4334 nextout->d_status = 0; 4335 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(u_int32_t)); 4336 4337#if !defined(TULIP_BUS_DMA) || defined(TULIP_BUS_DMA_NOTX) 4338 /* 4339 * If we only used the first segment of the last descriptor, 4340 * make sure the second segment will not be used. 4341 */ 4342 if (segcnt & 1) { 4343 eop->d_addr2 = 0; 4344 eop->d_length2 = 0; 4345 } 4346#endif /* TULIP_BUS_DMA */ 4347 4348 /* 4349 * Mark the last and first segments, indicate we want a transmit 4350 * complete interrupt, and tell it to transmit! 4351 */ 4352 eop->d_flag |= TULIP_DFLAG_TxLASTSEG|TULIP_DFLAG_TxWANTINTR; 4353 4354 /* 4355 * Note that ri->ri_nextout is still the start of the packet 4356 * and until we set the OWNER bit, we can still back out of 4357 * everything we have done. 4358 */ 4359 ri->ri_nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG; 4360#if defined(TULIP_BUS_MAP) && !defined(TULIP_BUS_DMA_NOTX) 4361 if (eop < ri->ri_nextout) { 4362 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, 4363 (caddr_t) ri->ri_last - (caddr_t) ri->ri_nextout); 4364 TULIP_TXDESC_PRESYNC(sc, ri->ri_first, 4365 (caddr_t) (eop + 1) - (caddr_t) ri->ri_first); 4366 } else { 4367 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, 4368 (caddr_t) (eop + 1) - (caddr_t) ri->ri_nextout); 4369 } 4370#endif 4371 ri->ri_nextout->d_status = TULIP_DSTS_OWNER; 4372 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, sizeof(u_int32_t)); 4373 4374 /* 4375 * This advances the ring for us. 4376 */ 4377 ri->ri_nextout = nextout; 4378 ri->ri_free = free; 4379 4380 TULIP_PERFEND(txput); 4381 4382 if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) { 4383 TULIP_CSR_WRITE(sc, csr_txpoll, 1); 4384 sc->tulip_if.if_flags |= IFF_OACTIVE; 4385 sc->tulip_if.if_start = tulip_ifstart; 4386 TULIP_PERFEND(txput); 4387 return NULL; 4388 } 4389 4390 /* 4391 * switch back to the single queueing ifstart. 4392 */ 4393 sc->tulip_flags &= ~TULIP_WANTTXSTART; 4394 if (sc->tulip_txtimer == 0) 4395 sc->tulip_txtimer = TULIP_TXTIMER; 4396#if defined(TULIP_DEBUG) 4397 sc->tulip_dbg.dbg_txput_finishes[5]++; 4398#endif 4399 4400 /* 4401 * If we want a txstart, there must be not enough space in the 4402 * transmit ring. So we want to enable transmit done interrupts 4403 * so we can immediately reclaim some space. When the transmit 4404 * interrupt is posted, the interrupt handler will call tx_intr 4405 * to reclaim space and then txstart (since WANTTXSTART is set). 4406 * txstart will move the packet into the transmit ring and clear 4407 * WANTTXSTART thereby causing TXINTR to be cleared. 4408 */ 4409 finish: 4410#if defined(TULIP_DEBUG) 4411 sc->tulip_dbg.dbg_txput_finishes[6]++; 4412#endif 4413 if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_DOINGSETUP)) { 4414 sc->tulip_if.if_flags |= IFF_OACTIVE; 4415 sc->tulip_if.if_start = tulip_ifstart; 4416 if ((sc->tulip_intrmask & TULIP_STS_TXINTR) == 0) { 4417 sc->tulip_intrmask |= TULIP_STS_TXINTR; 4418 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask); 4419 } 4420 } else if ((sc->tulip_flags & TULIP_PROMISC) == 0) { 4421 if (sc->tulip_intrmask & TULIP_STS_TXINTR) { 4422 sc->tulip_intrmask &= ~TULIP_STS_TXINTR; 4423 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask); 4424 } 4425 } 4426 TULIP_CSR_WRITE(sc, csr_txpoll, 1); 4427 TULIP_PERFEND(txput); 4428 return m; 4429} 4430 4431static void 4432tulip_txput_setup( 4433 tulip_softc_t * const sc) 4434{ 4435 tulip_ringinfo_t * const ri = &sc->tulip_txinfo; 4436 tulip_desc_t *nextout; 4437 4438 /* 4439 * We will transmit, at most, one setup packet per call to ifstart. 4440 */ 4441 4442#if defined(TULIP_DEBUG) 4443 if ((sc->tulip_cmdmode & TULIP_CMD_TXRUN) == 0) { 4444 printf("%s: txput_setup: tx not running\n", 4445 sc->tulip_xname); 4446 sc->tulip_flags |= TULIP_WANTTXSTART; 4447 sc->tulip_if.if_start = tulip_ifstart; 4448 return; 4449 } 4450#endif 4451 /* 4452 * Try to reclaim some free descriptors.. 4453 */ 4454 if (ri->ri_free < 2) 4455 tulip_tx_intr(sc); 4456 if ((sc->tulip_flags & TULIP_DOINGSETUP) || ri->ri_free == 1) { 4457 sc->tulip_flags |= TULIP_WANTTXSTART; 4458 sc->tulip_if.if_start = tulip_ifstart; 4459 return; 4460 } 4461 bcopy(sc->tulip_setupdata, sc->tulip_setupbuf, 4462 sizeof(sc->tulip_setupbuf)); 4463 /* 4464 * Clear WANTSETUP and set DOINGSETUP. Set know that WANTSETUP is 4465 * set and DOINGSETUP is clear doing an XOR of the two will DTRT. 4466 */ 4467 sc->tulip_flags ^= TULIP_WANTSETUP|TULIP_DOINGSETUP; 4468 ri->ri_free--; 4469 nextout = ri->ri_nextout; 4470 nextout->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN; 4471 nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG|TULIP_DFLAG_TxLASTSEG 4472 |TULIP_DFLAG_TxSETUPPKT|TULIP_DFLAG_TxWANTINTR; 4473 if (sc->tulip_flags & TULIP_WANTHASHPERFECT) 4474 nextout->d_flag |= TULIP_DFLAG_TxHASHFILT; 4475 else if (sc->tulip_flags & TULIP_WANTHASHONLY) 4476 nextout->d_flag |= TULIP_DFLAG_TxHASHFILT|TULIP_DFLAG_TxINVRSFILT; 4477 4478 nextout->d_length2 = 0; 4479 nextout->d_addr2 = 0; 4480#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX) 4481 nextout->d_length1 = sc->tulip_setupmap->dm_segs[0].ds_len; 4482 nextout->d_addr1 = sc->tulip_setupmap->dm_segs[0].ds_addr; 4483 if (sc->tulip_setupmap->dm_nsegs == 2) { 4484 nextout->d_length2 = sc->tulip_setupmap->dm_segs[1].ds_len; 4485 nextout->d_addr2 = sc->tulip_setupmap->dm_segs[1].ds_addr; 4486 } 4487 TULIP_TXMAP_PRESYNC(sc, sc->tulip_setupmap); 4488 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(*nextout)); 4489#else 4490 nextout->d_length1 = sizeof(sc->tulip_setupbuf); 4491 nextout->d_addr1 = TULIP_KVATOPHYS(sc, sc->tulip_setupbuf); 4492#endif 4493 4494 /* 4495 * Advance the ring for the next transmit packet. 4496 */ 4497 if (++ri->ri_nextout == ri->ri_last) 4498 ri->ri_nextout = ri->ri_first; 4499 4500 /* 4501 * Make sure the next descriptor is owned by us since it 4502 * may have been set up above if we ran out of room in the 4503 * ring. 4504 */ 4505 ri->ri_nextout->d_status = 0; 4506 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, sizeof(u_int32_t)); 4507 nextout->d_status = TULIP_DSTS_OWNER; 4508 /* 4509 * Flush the ownwership of the current descriptor 4510 */ 4511 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(u_int32_t)); 4512 TULIP_CSR_WRITE(sc, csr_txpoll, 1); 4513 if ((sc->tulip_intrmask & TULIP_STS_TXINTR) == 0) { 4514 sc->tulip_intrmask |= TULIP_STS_TXINTR; 4515 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask); 4516 } 4517} 4518 4519 4520/* 4521 * This routine is entered at splnet() (splsoftnet() on NetBSD) 4522 * and thereby imposes no problems when TULIP_USE_SOFTINTR is 4523 * defined or not. 4524 */ 4525static int 4526tulip_ifioctl( 4527 struct ifnet * ifp, 4528 u_long cmd, 4529 caddr_t data) 4530{ 4531 TULIP_PERFSTART(ifioctl) 4532 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc; 4533 struct ifreq *ifr = (struct ifreq *) data; 4534 int s; 4535 int error = 0; 4536 4537#if defined(TULIP_USE_SOFTINTR) 4538 s = splnet(); 4539#else 4540 s = splimp(); 4541#endif 4542 switch (cmd) { 4543 case SIOCSIFFLAGS: { 4544 tulip_addr_filter(sc); /* reinit multicast filter */ 4545 tulip_init(sc); 4546 break; 4547 } 4548 4549 case SIOCSIFMEDIA: 4550 case SIOCGIFMEDIA: { 4551 error = ifmedia_ioctl(ifp, ifr, &sc->tulip_ifmedia, cmd); 4552 break; 4553 } 4554 4555 case SIOCADDMULTI: 4556 case SIOCDELMULTI: { 4557 /* 4558 * Update multicast listeners 4559 */ 4560 tulip_addr_filter(sc); /* reset multicast filtering */ 4561 tulip_init(sc); 4562 error = 0; 4563 break; 4564 } 4565 4566 case SIOCSIFMTU: 4567 /* 4568 * Set the interface MTU. 4569 */ 4570 if (ifr->ifr_mtu > ETHERMTU 4571#ifdef BIG_PACKET 4572 && sc->tulip_chipid != TULIP_21140 4573 && sc->tulip_chipid != TULIP_21140A 4574 && sc->tulip_chipid != TULIP_21041 4575#endif 4576 ) { 4577 error = EINVAL; 4578 break; 4579 } 4580 ifp->if_mtu = ifr->ifr_mtu; 4581#ifdef BIG_PACKET 4582 tulip_reset(sc); 4583 tulip_init(sc); 4584#endif 4585 break; 4586 4587#ifdef SIOCGADDRROM 4588 case SIOCGADDRROM: { 4589 error = copyout(sc->tulip_rombuf, ifr->ifr_data, sizeof(sc->tulip_rombuf)); 4590 break; 4591 } 4592#endif 4593#ifdef SIOCGCHIPID 4594 case SIOCGCHIPID: { 4595 ifr->ifr_metric = (int) sc->tulip_chipid; 4596 break; 4597 } 4598#endif 4599 default: { 4600 error = ether_ioctl(ifp, cmd, data); 4601 break; 4602 } 4603 } 4604 4605 splx(s); 4606 TULIP_PERFEND(ifioctl); 4607 return error; 4608} 4609 4610/* 4611 * These routines gets called at device spl (from ether_output). This might 4612 * pose a problem for TULIP_USE_SOFTINTR if ether_output is called at 4613 * device spl from another driver. 4614 */ 4615 4616static void 4617tulip_ifstart( 4618 struct ifnet * const ifp) 4619{ 4620 TULIP_PERFSTART(ifstart) 4621 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc; 4622 4623 if (sc->tulip_if.if_flags & IFF_RUNNING) { 4624 4625 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP) 4626 tulip_txput_setup(sc); 4627 4628 while (!IFQ_DRV_IS_EMPTY(&sc->tulip_if.if_snd)) { 4629 struct mbuf *m; 4630 IFQ_DRV_DEQUEUE(&sc->tulip_if.if_snd, m); 4631 if(m == NULL) 4632 break; 4633 if ((m = tulip_txput(sc, m)) != NULL) { 4634 IFQ_DRV_PREPEND(&sc->tulip_if.if_snd, m); 4635 break; 4636 } 4637 } 4638 } 4639 4640 TULIP_PERFEND(ifstart); 4641} 4642 4643/* 4644 * Even though this routine runs at device spl, it does not break 4645 * our use of splnet (splsoftnet under NetBSD) for the majority 4646 * of this driver (if TULIP_USE_SOFTINTR defined) since 4647 * if_watcbog is called from if_watchdog which is called from 4648 * splsoftclock which is below spl[soft]net. 4649 */ 4650static void 4651tulip_ifwatchdog( 4652 struct ifnet *ifp) 4653{ 4654 TULIP_PERFSTART(ifwatchdog) 4655 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc; 4656 4657#if defined(TULIP_DEBUG) 4658 u_int32_t rxintrs = sc->tulip_dbg.dbg_rxintrs - sc->tulip_dbg.dbg_last_rxintrs; 4659 if (rxintrs > sc->tulip_dbg.dbg_high_rxintrs_hz) 4660 sc->tulip_dbg.dbg_high_rxintrs_hz = rxintrs; 4661 sc->tulip_dbg.dbg_last_rxintrs = sc->tulip_dbg.dbg_rxintrs; 4662#endif /* TULIP_DEBUG */ 4663 4664 sc->tulip_if.if_timer = 1; 4665 /* 4666 * These should be rare so do a bulk test up front so we can just skip 4667 * them if needed. 4668 */ 4669 if (sc->tulip_flags & (TULIP_SYSTEMERROR|TULIP_RXBUFSLOW|TULIP_NOMESSAGES)) { 4670 /* 4671 * If the number of receive buffer is low, try to refill 4672 */ 4673 if (sc->tulip_flags & TULIP_RXBUFSLOW) 4674 tulip_rx_intr(sc); 4675 4676 if (sc->tulip_flags & TULIP_SYSTEMERROR) { 4677 printf("%s: %d system errors: last was %s\n", 4678 sc->tulip_xname, sc->tulip_system_errors, 4679 tulip_system_errors[sc->tulip_last_system_error]); 4680 } 4681 if (sc->tulip_statusbits) { 4682 tulip_print_abnormal_interrupt(sc, sc->tulip_statusbits); 4683 sc->tulip_statusbits = 0; 4684 } 4685 4686 sc->tulip_flags &= ~(TULIP_NOMESSAGES|TULIP_SYSTEMERROR); 4687 } 4688 4689 if (sc->tulip_txtimer) 4690 tulip_tx_intr(sc); 4691 if (sc->tulip_txtimer && --sc->tulip_txtimer == 0) { 4692 printf("%s: transmission timeout\n", sc->tulip_xname); 4693 if (TULIP_DO_AUTOSENSE(sc)) { 4694 sc->tulip_media = TULIP_MEDIA_UNKNOWN; 4695 sc->tulip_probe_state = TULIP_PROBE_INACTIVE; 4696 sc->tulip_flags &= ~(TULIP_WANTRXACT|TULIP_LINKUP); 4697 } 4698 tulip_reset(sc); 4699 tulip_init(sc); 4700 } 4701 4702 TULIP_PERFEND(ifwatchdog); 4703 TULIP_PERFMERGE(sc, perf_intr_cycles); 4704 TULIP_PERFMERGE(sc, perf_ifstart_cycles); 4705 TULIP_PERFMERGE(sc, perf_ifioctl_cycles); 4706 TULIP_PERFMERGE(sc, perf_ifwatchdog_cycles); 4707 TULIP_PERFMERGE(sc, perf_timeout_cycles); 4708 TULIP_PERFMERGE(sc, perf_ifstart_one_cycles); 4709 TULIP_PERFMERGE(sc, perf_txput_cycles); 4710 TULIP_PERFMERGE(sc, perf_txintr_cycles); 4711 TULIP_PERFMERGE(sc, perf_rxintr_cycles); 4712 TULIP_PERFMERGE(sc, perf_rxget_cycles); 4713 TULIP_PERFMERGE(sc, perf_intr); 4714 TULIP_PERFMERGE(sc, perf_ifstart); 4715 TULIP_PERFMERGE(sc, perf_ifioctl); 4716 TULIP_PERFMERGE(sc, perf_ifwatchdog); 4717 TULIP_PERFMERGE(sc, perf_timeout); 4718 TULIP_PERFMERGE(sc, perf_ifstart_one); 4719 TULIP_PERFMERGE(sc, perf_txput); 4720 TULIP_PERFMERGE(sc, perf_txintr); 4721 TULIP_PERFMERGE(sc, perf_rxintr); 4722 TULIP_PERFMERGE(sc, perf_rxget); 4723} 4724 4725/* 4726 * All printf's are real as of now! 4727 */ 4728#ifdef printf 4729#undef printf 4730#endif 4731 4732static void 4733tulip_attach( 4734 tulip_softc_t * const sc) 4735{ 4736 struct ifnet * const ifp = &sc->tulip_if; 4737 4738 /* XXX: driver name/unit should be set some other way */ 4739 ifp->if_dname = "de"; 4740 ifp->if_dunit = sc->tulip_unit; 4741 ifp->if_flags = IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST|IFF_NEEDSGIANT; 4742 ifp->if_ioctl = tulip_ifioctl; 4743 ifp->if_start = tulip_ifstart; 4744 ifp->if_watchdog = tulip_ifwatchdog; 4745 ifp->if_timer = 1; 4746 ifp->if_init = tulip_ifinit; 4747 4748 printf("%s: %s%s pass %d.%d%s\n", 4749 sc->tulip_xname, 4750 sc->tulip_boardid, 4751 tulip_chipdescs[sc->tulip_chipid], 4752 (sc->tulip_revinfo & 0xF0) >> 4, 4753 sc->tulip_revinfo & 0x0F, 4754 (sc->tulip_features & (TULIP_HAVE_ISVSROM|TULIP_HAVE_OKSROM)) 4755 == TULIP_HAVE_ISVSROM ? " (invalid EESPROM checksum)" : ""); 4756#ifndef __FreeBSD__ 4757 printf("%s: address %6D\n", 4758 sc->tulip_xname, sc->tulip_enaddr, ":"); 4759#endif 4760 4761#if defined(__alpha__) 4762 /* 4763 * In case the SRM console told us about a bogus media, 4764 * we need to check to be safe. 4765 */ 4766 if (sc->tulip_mediums[sc->tulip_media] == NULL) 4767 sc->tulip_media = TULIP_MEDIA_UNKNOWN; 4768#endif 4769 4770 (*sc->tulip_boardsw->bd_media_probe)(sc); 4771 ifmedia_init(&sc->tulip_ifmedia, 0, 4772 tulip_ifmedia_change, 4773 tulip_ifmedia_status); 4774 sc->tulip_flags &= ~TULIP_DEVICEPROBE; 4775 tulip_ifmedia_add(sc); 4776 4777 tulip_reset(sc); 4778 4779 ether_ifattach(&(sc)->tulip_if, sc->tulip_enaddr); 4780 IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen); 4781 ifp->if_snd.ifq_drv_maxlen = ifqmaxlen; 4782 IFQ_SET_READY(&ifp->if_snd); 4783} 4784 4785#if defined(TULIP_BUS_DMA) 4786#if !defined(TULIP_BUS_DMA_NOTX) || !defined(TULIP_BUS_DMA_NORX) 4787static int 4788tulip_busdma_allocmem( 4789 tulip_softc_t * const sc, 4790 size_t size, 4791 bus_dmamap_t *map_p, 4792 tulip_desc_t **desc_p) 4793{ 4794 bus_dma_segment_t segs[1]; 4795 int nsegs, error; 4796 error = bus_dmamem_alloc(sc->tulip_dmatag, size, 1, PAGE_SIZE, 4797 segs, sizeof(segs)/sizeof(segs[0]), 4798 &nsegs, BUS_DMA_NOWAIT); 4799 if (error == 0) { 4800 void *desc; 4801 error = bus_dmamem_map(sc->tulip_dmatag, segs, nsegs, size, 4802 (void *) &desc, BUS_DMA_NOWAIT|BUS_DMA_COHERENT); 4803 if (error == 0) { 4804 bus_dmamap_t map; 4805 error = bus_dmamap_create(sc->tulip_dmatag, size, 1, size, 0, 4806 BUS_DMA_NOWAIT, &map); 4807 if (error == 0) { 4808 error = bus_dmamap_load(sc->tulip_dmatag, map, desc, 4809 size, NULL, BUS_DMA_NOWAIT); 4810 if (error) 4811 bus_dmamap_destroy(sc->tulip_dmatag, map); 4812 else 4813 *map_p = map; 4814 } 4815 if (error) 4816 bus_dmamem_unmap(sc->tulip_dmatag, desc, size); 4817 } 4818 if (error) 4819 bus_dmamem_free(sc->tulip_dmatag, segs, nsegs); 4820 else 4821 *desc_p = desc; 4822 } 4823 return error; 4824} 4825#endif 4826 4827static int 4828tulip_busdma_init( 4829 tulip_softc_t * const sc) 4830{ 4831 int error = 0; 4832 4833#if !defined(TULIP_BUS_DMA_NOTX) 4834 /* 4835 * Allocate dmamap for setup descriptor 4836 */ 4837 error = bus_dmamap_create(sc->tulip_dmatag, sizeof(sc->tulip_setupbuf), 2, 4838 sizeof(sc->tulip_setupbuf), 0, BUS_DMA_NOWAIT, 4839 &sc->tulip_setupmap); 4840 if (error == 0) { 4841 error = bus_dmamap_load(sc->tulip_dmatag, sc->tulip_setupmap, 4842 sc->tulip_setupbuf, sizeof(sc->tulip_setupbuf), 4843 NULL, BUS_DMA_NOWAIT); 4844 if (error) 4845 bus_dmamap_destroy(sc->tulip_dmatag, sc->tulip_setupmap); 4846 } 4847 /* 4848 * Allocate space and dmamap for transmit ring 4849 */ 4850 if (error == 0) { 4851 error = tulip_busdma_allocmem(sc, sizeof(tulip_desc_t) * TULIP_TXDESCS, 4852 &sc->tulip_txdescmap, 4853 &sc->tulip_txdescs); 4854 } 4855 4856 /* 4857 * Allocate dmamaps for each transmit descriptors 4858 */ 4859 if (error == 0) { 4860 while (error == 0 && sc->tulip_txmaps_free < TULIP_TXDESCS) { 4861 bus_dmamap_t map; 4862 if ((error = TULIP_TXMAP_CREATE(sc, &map)) == 0) 4863 sc->tulip_txmaps[sc->tulip_txmaps_free++] = map; 4864 } 4865 if (error) { 4866 while (sc->tulip_txmaps_free > 0) 4867 bus_dmamap_destroy(sc->tulip_dmatag, 4868 sc->tulip_txmaps[--sc->tulip_txmaps_free]); 4869 } 4870 } 4871#else 4872 if (error == 0) { 4873 sc->tulip_txdescs = (tulip_desc_t *) malloc(TULIP_TXDESCS * sizeof(tulip_desc_t), M_DEVBUF, M_NOWAIT); 4874 if (sc->tulip_txdescs == NULL) 4875 error = ENOMEM; 4876 } 4877#endif 4878#if !defined(TULIP_BUS_DMA_NORX) 4879 /* 4880 * Allocate space and dmamap for receive ring 4881 */ 4882 if (error == 0) { 4883 error = tulip_busdma_allocmem(sc, sizeof(tulip_desc_t) * TULIP_RXDESCS, 4884 &sc->tulip_rxdescmap, 4885 &sc->tulip_rxdescs); 4886 } 4887 4888 /* 4889 * Allocate dmamaps for each receive descriptors 4890 */ 4891 if (error == 0) { 4892 while (error == 0 && sc->tulip_rxmaps_free < TULIP_RXDESCS) { 4893 bus_dmamap_t map; 4894 if ((error = TULIP_RXMAP_CREATE(sc, &map)) == 0) 4895 sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map; 4896 } 4897 if (error) { 4898 while (sc->tulip_rxmaps_free > 0) 4899 bus_dmamap_destroy(sc->tulip_dmatag, 4900 sc->tulip_rxmaps[--sc->tulip_rxmaps_free]); 4901 } 4902 } 4903#else 4904 if (error == 0) { 4905 sc->tulip_rxdescs = (tulip_desc_t *) malloc(TULIP_RXDESCS * sizeof(tulip_desc_t), M_DEVBUF, M_NOWAIT); 4906 if (sc->tulip_rxdescs == NULL) 4907 error = ENOMEM; 4908 } 4909#endif 4910 return error; 4911} 4912#endif /* TULIP_BUS_DMA */ 4913 4914static void 4915tulip_initcsrs( 4916 tulip_softc_t * const sc, 4917 tulip_csrptr_t csr_base, 4918 size_t csr_size) 4919{ 4920 sc->tulip_csrs.csr_busmode = csr_base + 0 * csr_size; 4921 sc->tulip_csrs.csr_txpoll = csr_base + 1 * csr_size; 4922 sc->tulip_csrs.csr_rxpoll = csr_base + 2 * csr_size; 4923 sc->tulip_csrs.csr_rxlist = csr_base + 3 * csr_size; 4924 sc->tulip_csrs.csr_txlist = csr_base + 4 * csr_size; 4925 sc->tulip_csrs.csr_status = csr_base + 5 * csr_size; 4926 sc->tulip_csrs.csr_command = csr_base + 6 * csr_size; 4927 sc->tulip_csrs.csr_intr = csr_base + 7 * csr_size; 4928 sc->tulip_csrs.csr_missed_frames = csr_base + 8 * csr_size; 4929 sc->tulip_csrs.csr_9 = csr_base + 9 * csr_size; 4930 sc->tulip_csrs.csr_10 = csr_base + 10 * csr_size; 4931 sc->tulip_csrs.csr_11 = csr_base + 11 * csr_size; 4932 sc->tulip_csrs.csr_12 = csr_base + 12 * csr_size; 4933 sc->tulip_csrs.csr_13 = csr_base + 13 * csr_size; 4934 sc->tulip_csrs.csr_14 = csr_base + 14 * csr_size; 4935 sc->tulip_csrs.csr_15 = csr_base + 15 * csr_size; 4936} 4937 4938static void 4939tulip_initring( 4940 tulip_softc_t * const sc, 4941 tulip_ringinfo_t * const ri, 4942 tulip_desc_t *descs, 4943 int ndescs) 4944{ 4945 ri->ri_max = ndescs; 4946 ri->ri_first = descs; 4947 ri->ri_last = ri->ri_first + ri->ri_max; 4948 bzero((caddr_t) ri->ri_first, sizeof(ri->ri_first[0]) * ri->ri_max); 4949 ri->ri_last[-1].d_flag = TULIP_DFLAG_ENDRING; 4950} 4951 4952/* 4953 * This is the PCI configuration support. 4954 */ 4955 4956#define PCI_CBIO 0x10 /* Configuration Base IO Address */ 4957#define PCI_CBMA 0x14 /* Configuration Base Memory Address */ 4958#define PCI_CFDA 0x40 /* Configuration Driver Area */ 4959 4960static int 4961tulip_pci_probe(device_t dev) 4962{ 4963 const char *name = NULL; 4964 4965 if (pci_get_vendor(dev) != DEC_VENDORID) 4966 return ENXIO; 4967 4968 /* 4969 * Some LanMedia WAN cards use the Tulip chip, but they have 4970 * their own driver, and we should not recognize them 4971 */ 4972 if (pci_get_subvendor(dev) == 0x1376) 4973 return ENXIO; 4974 4975 switch (pci_get_device(dev)) { 4976 case CHIPID_21040: 4977 name = "Digital 21040 Ethernet"; 4978 break; 4979 case CHIPID_21041: 4980 name = "Digital 21041 Ethernet"; 4981 break; 4982 case CHIPID_21140: 4983 if (pci_get_revid(dev) >= 0x20) 4984 name = "Digital 21140A Fast Ethernet"; 4985 else 4986 name = "Digital 21140 Fast Ethernet"; 4987 break; 4988 case CHIPID_21142: 4989 if (pci_get_revid(dev) >= 0x20) 4990 name = "Digital 21143 Fast Ethernet"; 4991 else 4992 name = "Digital 21142 Fast Ethernet"; 4993 break; 4994 } 4995 if (name) { 4996 device_set_desc(dev, name);
| 40 41#define TULIP_HDR_DATA 42 43#include <sys/param.h> 44#include <sys/systm.h> 45#include <sys/endian.h> 46#include <sys/mbuf.h> 47#include <sys/socket.h> 48#include <sys/sockio.h> 49#include <sys/malloc.h> 50#include <sys/kernel.h> 51#include <sys/module.h> 52#include <sys/eventhandler.h> 53#include <machine/bus.h> 54#include <machine/resource.h> 55#include <sys/bus.h> 56#include <sys/rman.h> 57 58#include <net/if.h> 59#include <net/if_arp.h> 60#include <net/ethernet.h> 61#include <net/if_media.h> 62#include <net/if_dl.h> 63#ifdef TULIP_USE_SOFTINTR 64#include <net/netisr.h> 65#endif 66 67#include <net/bpf.h> 68 69#ifdef INET 70#include <netinet/in.h> 71#include <netinet/if_ether.h> 72#endif 73 74#include <vm/vm.h> 75 76#include <net/if_var.h> 77#include <vm/pmap.h> 78#include <dev/pci/pcivar.h> 79#include <dev/pci/pcireg.h> 80#include <pci/dc21040reg.h> 81 82/* 83 * Intel CPUs should use I/O mapped access. 84 */ 85#if defined(__i386__) 86#define TULIP_IOMAPPED 87#endif 88 89#if 0 90/* 91 * This turns on all sort of debugging stuff and make the 92 * driver much larger. 93 */ 94#define TULIP_DEBUG 95#endif 96 97#if 0 98#define TULIP_PERFSTATS 99#endif 100 101#if 0 102#define TULIP_USE_SOFTINTR 103#endif 104 105#define TULIP_HZ 10 106 107#include <pci/if_devar.h> 108 109/* 110 * This module supports 111 * the DEC 21040 PCI Ethernet Controller. 112 * the DEC 21041 PCI Ethernet Controller. 113 * the DEC 21140 PCI Fast Ethernet Controller. 114 */ 115static void tulip_addr_filter(tulip_softc_t * const sc); 116static void tulip_ifinit(void *); 117static int tulip_ifmedia_change(struct ifnet * const ifp); 118static void tulip_ifmedia_status(struct ifnet * const ifp, 119 struct ifmediareq *req); 120static void tulip_ifstart(struct ifnet *ifp); 121static void tulip_init(tulip_softc_t * const sc); 122static void tulip_intr_shared(void *arg); 123static void tulip_intr_normal(void *arg); 124static void tulip_mii_autonegotiate(tulip_softc_t * const sc, 125 const unsigned phyaddr); 126static int tulip_mii_map_abilities(tulip_softc_t * const sc, 127 unsigned abilities); 128static tulip_media_t 129 tulip_mii_phy_readspecific(tulip_softc_t * const sc); 130static unsigned tulip_mii_readreg(tulip_softc_t * const sc, unsigned devaddr, 131 unsigned regno); 132static void tulip_mii_writereg(tulip_softc_t * const sc, unsigned devaddr, 133 unsigned regno, unsigned data); 134static void tulip_reset(tulip_softc_t * const sc); 135static void tulip_rx_intr(tulip_softc_t * const sc); 136static int tulip_srom_decode(tulip_softc_t * const sc); 137static struct mbuf * 138 tulip_txput(tulip_softc_t * const sc, struct mbuf *m); 139static void tulip_txput_setup(tulip_softc_t * const sc); 140 141static void 142tulip_timeout_callback( 143 void *arg) 144{ 145 tulip_softc_t * const sc = arg; 146 int s = splimp(); 147 148 TULIP_PERFSTART(timeout) 149 150 sc->tulip_flags &= ~TULIP_TIMEOUTPENDING; 151 sc->tulip_probe_timeout -= 1000 / TULIP_HZ; 152 (sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_TIMER); 153 154 TULIP_PERFEND(timeout); 155 splx(s); 156} 157 158static void 159tulip_timeout( 160 tulip_softc_t * const sc) 161{ 162 if (sc->tulip_flags & TULIP_TIMEOUTPENDING) 163 return; 164 sc->tulip_flags |= TULIP_TIMEOUTPENDING; 165 timeout(tulip_timeout_callback, sc, (hz + TULIP_HZ / 2) / TULIP_HZ); 166} 167 168#if defined(TULIP_NEED_FASTTIMEOUT) 169static void 170tulip_fasttimeout_callback( 171 void *arg) 172{ 173 tulip_softc_t * const sc = arg; 174 int s = splimp(); 175 176 sc->tulip_flags &= ~TULIP_FASTTIMEOUTPENDING; 177 (sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_FASTTIMER); 178 splx(s); 179} 180 181static void 182tulip_fasttimeout( 183 tulip_softc_t * const sc) 184{ 185 if (sc->tulip_flags & TULIP_FASTTIMEOUTPENDING) 186 return; 187 sc->tulip_flags |= TULIP_FASTTIMEOUTPENDING; 188 timeout(tulip_fasttimeout_callback, sc, 1); 189} 190#endif 191 192static int 193tulip_txprobe( 194 tulip_softc_t * const sc) 195{ 196 struct mbuf *m; 197 /* 198 * Before we are sure this is the right media we need 199 * to send a small packet to make sure there's carrier. 200 * Strangely, BNC and AUI will "see" receive data if 201 * either is connected so the transmit is the only way 202 * to verify the connectivity. 203 */ 204 MGETHDR(m, M_DONTWAIT, MT_DATA); 205 if (m == NULL) 206 return 0; 207 /* 208 * Construct a LLC TEST message which will point to ourselves. 209 */ 210 bcopy(sc->tulip_enaddr, mtod(m, struct ether_header *)->ether_dhost, 6); 211 bcopy(sc->tulip_enaddr, mtod(m, struct ether_header *)->ether_shost, 6); 212 mtod(m, struct ether_header *)->ether_type = htons(3); 213 mtod(m, unsigned char *)[14] = 0; 214 mtod(m, unsigned char *)[15] = 0; 215 mtod(m, unsigned char *)[16] = 0xE3; /* LLC Class1 TEST (no poll) */ 216 m->m_len = m->m_pkthdr.len = sizeof(struct ether_header) + 3; 217 /* 218 * send it! 219 */ 220 sc->tulip_cmdmode |= TULIP_CMD_TXRUN; 221 sc->tulip_intrmask |= TULIP_STS_TXINTR; 222 sc->tulip_flags |= TULIP_TXPROBE_ACTIVE; 223 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode); 224 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask); 225 if ((m = tulip_txput(sc, m)) != NULL) 226 m_freem(m); 227 sc->tulip_probe.probe_txprobes++; 228 return 1; 229} 230 231#ifdef BIG_PACKET 232#define TULIP_SIAGEN_WATCHDOG (sc->tulip_if.if_mtu > ETHERMTU ? TULIP_WATCHDOG_RXDISABLE|TULIP_WATCHDOG_TXDISABLE : 0) 233#else 234#define TULIP_SIAGEN_WATCHDOG 0 235#endif 236 237static void 238tulip_media_set( 239 tulip_softc_t * const sc, 240 tulip_media_t media) 241{ 242 const tulip_media_info_t *mi = sc->tulip_mediums[media]; 243 244 if (mi == NULL) 245 return; 246 247 /* 248 * If we are switching media, make sure we don't think there's 249 * any stale RX activity 250 */ 251 sc->tulip_flags &= ~TULIP_RXACT; 252 if (mi->mi_type == TULIP_MEDIAINFO_SIA) { 253 TULIP_CSR_WRITE(sc, csr_sia_connectivity, TULIP_SIACONN_RESET); 254 TULIP_CSR_WRITE(sc, csr_sia_tx_rx, mi->mi_sia_tx_rx); 255 if (sc->tulip_features & TULIP_HAVE_SIAGP) { 256 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_gp_control|mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG); 257 DELAY(50); 258 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_gp_data|mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG); 259 } else { 260 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG); 261 } 262 TULIP_CSR_WRITE(sc, csr_sia_connectivity, mi->mi_sia_connectivity); 263 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR) { 264#define TULIP_GPR_CMDBITS (TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER|TULIP_CMD_TXTHRSHLDCTL) 265 /* 266 * If the cmdmode bits don't match the currently operating mode, 267 * set the cmdmode appropriately and reset the chip. 268 */ 269 if (((mi->mi_cmdmode ^ TULIP_CSR_READ(sc, csr_command)) & TULIP_GPR_CMDBITS) != 0) { 270 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS; 271 sc->tulip_cmdmode |= mi->mi_cmdmode; 272 tulip_reset(sc); 273 } 274 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET|sc->tulip_gpinit); 275 DELAY(10); 276 TULIP_CSR_WRITE(sc, csr_gp, (u_int8_t) mi->mi_gpdata); 277 } else if (mi->mi_type == TULIP_MEDIAINFO_SYM) { 278 /* 279 * If the cmdmode bits don't match the currently operating mode, 280 * set the cmdmode appropriately and reset the chip. 281 */ 282 if (((mi->mi_cmdmode ^ TULIP_CSR_READ(sc, csr_command)) & TULIP_GPR_CMDBITS) != 0) { 283 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS; 284 sc->tulip_cmdmode |= mi->mi_cmdmode; 285 tulip_reset(sc); 286 } 287 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_gpcontrol); 288 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_gpdata); 289 } else if (mi->mi_type == TULIP_MEDIAINFO_MII 290 && sc->tulip_probe_state != TULIP_PROBE_INACTIVE) { 291 int idx; 292 if (sc->tulip_features & TULIP_HAVE_SIAGP) { 293 const u_int8_t *dp; 294 dp = &sc->tulip_rombuf[mi->mi_reset_offset]; 295 for (idx = 0; idx < mi->mi_reset_length; idx++, dp += 2) { 296 DELAY(10); 297 TULIP_CSR_WRITE(sc, csr_sia_general, (dp[0] + 256 * dp[1]) << 16); 298 } 299 sc->tulip_phyaddr = mi->mi_phyaddr; 300 dp = &sc->tulip_rombuf[mi->mi_gpr_offset]; 301 for (idx = 0; idx < mi->mi_gpr_length; idx++, dp += 2) { 302 DELAY(10); 303 TULIP_CSR_WRITE(sc, csr_sia_general, (dp[0] + 256 * dp[1]) << 16); 304 } 305 } else { 306 for (idx = 0; idx < mi->mi_reset_length; idx++) { 307 DELAY(10); 308 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_reset_offset + idx]); 309 } 310 sc->tulip_phyaddr = mi->mi_phyaddr; 311 for (idx = 0; idx < mi->mi_gpr_length; idx++) { 312 DELAY(10); 313 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_gpr_offset + idx]); 314 } 315 } 316 if (sc->tulip_flags & TULIP_TRYNWAY) { 317 tulip_mii_autonegotiate(sc, sc->tulip_phyaddr); 318 } else if ((sc->tulip_flags & TULIP_DIDNWAY) == 0) { 319 u_int32_t data = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_CONTROL); 320 data &= ~(PHYCTL_SELECT_100MB|PHYCTL_FULL_DUPLEX|PHYCTL_AUTONEG_ENABLE); 321 sc->tulip_flags &= ~TULIP_DIDNWAY; 322 if (TULIP_IS_MEDIA_FD(media)) 323 data |= PHYCTL_FULL_DUPLEX; 324 if (TULIP_IS_MEDIA_100MB(media)) 325 data |= PHYCTL_SELECT_100MB; 326 tulip_mii_writereg(sc, sc->tulip_phyaddr, PHYREG_CONTROL, data); 327 } 328 } 329} 330 331static void 332tulip_linkup( 333 tulip_softc_t * const sc, 334 tulip_media_t media) 335{ 336 if ((sc->tulip_flags & TULIP_LINKUP) == 0) 337 sc->tulip_flags |= TULIP_PRINTLINKUP; 338 sc->tulip_flags |= TULIP_LINKUP; 339 sc->tulip_if.if_flags &= ~IFF_OACTIVE; 340#if 0 /* XXX how does with work with ifmedia? */ 341 if ((sc->tulip_flags & TULIP_DIDNWAY) == 0) { 342 if (sc->tulip_if.if_flags & IFF_FULLDUPLEX) { 343 if (TULIP_CAN_MEDIA_FD(media) 344 && sc->tulip_mediums[TULIP_FD_MEDIA_OF(media)] != NULL) 345 media = TULIP_FD_MEDIA_OF(media); 346 } else { 347 if (TULIP_IS_MEDIA_FD(media) 348 && sc->tulip_mediums[TULIP_HD_MEDIA_OF(media)] != NULL) 349 media = TULIP_HD_MEDIA_OF(media); 350 } 351 } 352#endif 353 if (sc->tulip_media != media) { 354#ifdef TULIP_DEBUG 355 sc->tulip_dbg.dbg_last_media = sc->tulip_media; 356#endif 357 sc->tulip_media = media; 358 sc->tulip_flags |= TULIP_PRINTMEDIA; 359 if (TULIP_IS_MEDIA_FD(sc->tulip_media)) { 360 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX; 361 } else if (sc->tulip_chipid != TULIP_21041 || (sc->tulip_flags & TULIP_DIDNWAY) == 0) { 362 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX; 363 } 364 } 365 /* 366 * We could set probe_timeout to 0 but setting to 3000 puts this 367 * in one central place and the only matters is tulip_link is 368 * followed by a tulip_timeout. Therefore setting it should not 369 * result in aberrant behavour. 370 */ 371 sc->tulip_probe_timeout = 3000; 372 sc->tulip_probe_state = TULIP_PROBE_INACTIVE; 373 sc->tulip_flags &= ~(TULIP_TXPROBE_ACTIVE|TULIP_TRYNWAY); 374 if (sc->tulip_flags & TULIP_INRESET) { 375 tulip_media_set(sc, sc->tulip_media); 376 } else if (sc->tulip_probe_media != sc->tulip_media) { 377 /* 378 * No reason to change media if we have the right media. 379 */ 380 tulip_reset(sc); 381 } 382 tulip_init(sc); 383} 384 385static void 386tulip_media_print( 387 tulip_softc_t * const sc) 388{ 389 if ((sc->tulip_flags & TULIP_LINKUP) == 0) 390 return; 391 if (sc->tulip_flags & TULIP_PRINTMEDIA) { 392 printf("%s: enabling %s port\n", 393 sc->tulip_xname, 394 tulip_mediums[sc->tulip_media]); 395 sc->tulip_flags &= ~(TULIP_PRINTMEDIA|TULIP_PRINTLINKUP); 396 } else if (sc->tulip_flags & TULIP_PRINTLINKUP) { 397 printf("%s: link up\n", sc->tulip_xname); 398 sc->tulip_flags &= ~TULIP_PRINTLINKUP; 399 } 400} 401 402#if defined(TULIP_DO_GPR_SENSE) 403static tulip_media_t 404tulip_21140_gpr_media_sense( 405 tulip_softc_t * const sc) 406{ 407 tulip_media_t maybe_media = TULIP_MEDIA_UNKNOWN; 408 tulip_media_t last_media = TULIP_MEDIA_UNKNOWN; 409 tulip_media_t media; 410 411 /* 412 * If one of the media blocks contained a default media flag, 413 * use that. 414 */ 415 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) { 416 const tulip_media_info_t *mi; 417 /* 418 * Media is not supported (or is full-duplex). 419 */ 420 if ((mi = sc->tulip_mediums[media]) == NULL || TULIP_IS_MEDIA_FD(media)) 421 continue; 422 if (mi->mi_type != TULIP_MEDIAINFO_GPR) 423 continue; 424 425 /* 426 * Remember the media is this is the "default" media. 427 */ 428 if (mi->mi_default && maybe_media == TULIP_MEDIA_UNKNOWN) 429 maybe_media = media; 430 431 /* 432 * No activity mask? Can't see if it is active if there's no mask. 433 */ 434 if (mi->mi_actmask == 0) 435 continue; 436 437 /* 438 * Does the activity data match? 439 */ 440 if ((TULIP_CSR_READ(sc, csr_gp) & mi->mi_actmask) != mi->mi_actdata) 441 continue; 442 443#if defined(TULIP_DEBUG) 444 printf("%s: gpr_media_sense: %s: 0x%02x & 0x%02x == 0x%02x\n", 445 sc->tulip_xname, tulip_mediums[media], 446 TULIP_CSR_READ(sc, csr_gp) & 0xFF, 447 mi->mi_actmask, mi->mi_actdata); 448#endif 449 /* 450 * It does! If this is the first media we detected, then 451 * remember this media. If isn't the first, then there were 452 * multiple matches which we equate to no match (since we don't 453 * which to select (if any). 454 */ 455 if (last_media == TULIP_MEDIA_UNKNOWN) { 456 last_media = media; 457 } else if (last_media != media) { 458 last_media = TULIP_MEDIA_UNKNOWN; 459 } 460 } 461 return (last_media != TULIP_MEDIA_UNKNOWN) ? last_media : maybe_media; 462} 463#endif /* TULIP_DO_GPR_SENSE */ 464 465static tulip_link_status_t 466tulip_media_link_monitor( 467 tulip_softc_t * const sc) 468{ 469 const tulip_media_info_t * const mi = sc->tulip_mediums[sc->tulip_media]; 470 tulip_link_status_t linkup = TULIP_LINK_DOWN; 471 472 if (mi == NULL) { 473#if defined(DIAGNOSTIC) || defined(TULIP_DEBUG) 474 panic("tulip_media_link_monitor: %s: botch at line %d\n", 475 tulip_mediums[sc->tulip_media],__LINE__); 476#else 477 return TULIP_LINK_UNKNOWN; 478#endif 479 } 480 481 482 /* 483 * Have we seen some packets? If so, the link must be good. 484 */ 485 if ((sc->tulip_flags & (TULIP_RXACT|TULIP_LINKUP)) == (TULIP_RXACT|TULIP_LINKUP)) { 486 sc->tulip_flags &= ~TULIP_RXACT; 487 sc->tulip_probe_timeout = 3000; 488 return TULIP_LINK_UP; 489 } 490 491 sc->tulip_flags &= ~TULIP_RXACT; 492 if (mi->mi_type == TULIP_MEDIAINFO_MII) { 493 u_int32_t status; 494 /* 495 * Read the PHY status register. 496 */ 497 status = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_STATUS); 498 if (status & PHYSTS_AUTONEG_DONE) { 499 /* 500 * If the PHY has completed autonegotiation, see the if the 501 * remote systems abilities have changed. If so, upgrade or 502 * downgrade as appropriate. 503 */ 504 u_int32_t abilities = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_AUTONEG_ABILITIES); 505 abilities = (abilities << 6) & status; 506 if (abilities != sc->tulip_abilities) { 507#if defined(TULIP_DEBUG) 508 loudprintf("%s(phy%d): autonegotiation changed: 0x%04x -> 0x%04x\n", 509 sc->tulip_xname, sc->tulip_phyaddr, 510 sc->tulip_abilities, abilities); 511#endif 512 if (tulip_mii_map_abilities(sc, abilities)) { 513 tulip_linkup(sc, sc->tulip_probe_media); 514 return TULIP_LINK_UP; 515 } 516 /* 517 * if we had selected media because of autonegotiation, 518 * we need to probe for the new media. 519 */ 520 sc->tulip_probe_state = TULIP_PROBE_INACTIVE; 521 if (sc->tulip_flags & TULIP_DIDNWAY) 522 return TULIP_LINK_DOWN; 523 } 524 } 525 /* 526 * The link is now up. If was down, say its back up. 527 */ 528 if ((status & (PHYSTS_LINK_UP|PHYSTS_REMOTE_FAULT)) == PHYSTS_LINK_UP) 529 linkup = TULIP_LINK_UP; 530 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR) { 531 /* 532 * No activity sensor? Assume all's well. 533 */ 534 if (mi->mi_actmask == 0) 535 return TULIP_LINK_UNKNOWN; 536 /* 537 * Does the activity data match? 538 */ 539 if ((TULIP_CSR_READ(sc, csr_gp) & mi->mi_actmask) == mi->mi_actdata) 540 linkup = TULIP_LINK_UP; 541 } else if (mi->mi_type == TULIP_MEDIAINFO_SIA) { 542 /* 543 * Assume non TP ok for now. 544 */ 545 if (!TULIP_IS_MEDIA_TP(sc->tulip_media)) 546 return TULIP_LINK_UNKNOWN; 547 if ((TULIP_CSR_READ(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL) == 0) 548 linkup = TULIP_LINK_UP; 549#if defined(TULIP_DEBUG) 550 if (sc->tulip_probe_timeout <= 0) 551 printf("%s: sia status = 0x%08x\n", sc->tulip_xname, 552 TULIP_CSR_READ(sc, csr_sia_status)); 553#endif 554 } else if (mi->mi_type == TULIP_MEDIAINFO_SYM) { 555 return TULIP_LINK_UNKNOWN; 556 } 557 /* 558 * We will wait for 3 seconds until the link goes into suspect mode. 559 */ 560 if (sc->tulip_flags & TULIP_LINKUP) { 561 if (linkup == TULIP_LINK_UP) 562 sc->tulip_probe_timeout = 3000; 563 if (sc->tulip_probe_timeout > 0) 564 return TULIP_LINK_UP; 565 566 sc->tulip_flags &= ~TULIP_LINKUP; 567 printf("%s: link down: cable problem?\n", sc->tulip_xname); 568 } 569#if defined(TULIP_DEBUG) 570 sc->tulip_dbg.dbg_link_downed++; 571#endif 572 return TULIP_LINK_DOWN; 573} 574 575static void 576tulip_media_poll( 577 tulip_softc_t * const sc, 578 tulip_mediapoll_event_t event) 579{ 580#if defined(TULIP_DEBUG) 581 sc->tulip_dbg.dbg_events[event]++; 582#endif 583 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE 584 && event == TULIP_MEDIAPOLL_TIMER) { 585 switch (tulip_media_link_monitor(sc)) { 586 case TULIP_LINK_DOWN: { 587 /* 588 * Link Monitor failed. Probe for new media. 589 */ 590 event = TULIP_MEDIAPOLL_LINKFAIL; 591 break; 592 } 593 case TULIP_LINK_UP: { 594 /* 595 * Check again soon. 596 */ 597 tulip_timeout(sc); 598 return; 599 } 600 case TULIP_LINK_UNKNOWN: { 601 /* 602 * We can't tell so don't bother. 603 */ 604 return; 605 } 606 } 607 } 608 609 if (event == TULIP_MEDIAPOLL_LINKFAIL) { 610 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE) { 611 if (TULIP_DO_AUTOSENSE(sc)) { 612#if defined(TULIP_DEBUG) 613 sc->tulip_dbg.dbg_link_failures++; 614#endif 615 sc->tulip_media = TULIP_MEDIA_UNKNOWN; 616 if (sc->tulip_if.if_flags & IFF_UP) 617 tulip_reset(sc); /* restart probe */ 618 } 619 return; 620 } 621#if defined(TULIP_DEBUG) 622 sc->tulip_dbg.dbg_link_pollintrs++; 623#endif 624 } 625 626 if (event == TULIP_MEDIAPOLL_START) { 627 sc->tulip_if.if_flags |= IFF_OACTIVE; 628 if (sc->tulip_probe_state != TULIP_PROBE_INACTIVE) 629 return; 630 sc->tulip_probe_mediamask = 0; 631 sc->tulip_probe_passes = 0; 632#if defined(TULIP_DEBUG) 633 sc->tulip_dbg.dbg_media_probes++; 634#endif 635 /* 636 * If the SROM contained an explicit media to use, use it. 637 */ 638 sc->tulip_cmdmode &= ~(TULIP_CMD_RXRUN|TULIP_CMD_FULLDUPLEX); 639 sc->tulip_flags |= TULIP_TRYNWAY|TULIP_PROBE1STPASS; 640 sc->tulip_flags &= ~(TULIP_DIDNWAY|TULIP_PRINTMEDIA|TULIP_PRINTLINKUP); 641 /* 642 * connidx is defaulted to a media_unknown type. 643 */ 644 sc->tulip_probe_media = tulip_srom_conninfo[sc->tulip_connidx].sc_media; 645 if (sc->tulip_probe_media != TULIP_MEDIA_UNKNOWN) { 646 tulip_linkup(sc, sc->tulip_probe_media); 647 tulip_timeout(sc); 648 return; 649 } 650 651 if (sc->tulip_features & TULIP_HAVE_GPR) { 652 sc->tulip_probe_state = TULIP_PROBE_GPRTEST; 653 sc->tulip_probe_timeout = 2000; 654 } else { 655 sc->tulip_probe_media = TULIP_MEDIA_MAX; 656 sc->tulip_probe_timeout = 0; 657 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST; 658 } 659 } 660 661 /* 662 * Ignore txprobe failures or spurious callbacks. 663 */ 664 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED 665 && sc->tulip_probe_state != TULIP_PROBE_MEDIATEST) { 666 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE; 667 return; 668 } 669 670 /* 671 * If we really transmitted a packet, then that's the media we'll use. 672 */ 673 if (event == TULIP_MEDIAPOLL_TXPROBE_OK || event == TULIP_MEDIAPOLL_LINKPASS) { 674 if (event == TULIP_MEDIAPOLL_LINKPASS) { 675 /* XXX Check media status just to be sure */ 676 sc->tulip_probe_media = TULIP_MEDIA_10BASET; 677#if defined(TULIP_DEBUG) 678 } else { 679 sc->tulip_dbg.dbg_txprobes_ok[sc->tulip_probe_media]++; 680#endif 681 } 682 tulip_linkup(sc, sc->tulip_probe_media); 683 tulip_timeout(sc); 684 return; 685 } 686 687 if (sc->tulip_probe_state == TULIP_PROBE_GPRTEST) { 688#if defined(TULIP_DO_GPR_SENSE) 689 /* 690 * Check for media via the general purpose register. 691 * 692 * Try to sense the media via the GPR. If the same value 693 * occurs 3 times in a row then just use that. 694 */ 695 if (sc->tulip_probe_timeout > 0) { 696 tulip_media_t new_probe_media = tulip_21140_gpr_media_sense(sc); 697#if defined(TULIP_DEBUG) 698 printf("%s: media_poll: gpr sensing = %s\n", 699 sc->tulip_xname, tulip_mediums[new_probe_media]); 700#endif 701 if (new_probe_media != TULIP_MEDIA_UNKNOWN) { 702 if (new_probe_media == sc->tulip_probe_media) { 703 if (--sc->tulip_probe_count == 0) 704 tulip_linkup(sc, sc->tulip_probe_media); 705 } else { 706 sc->tulip_probe_count = 10; 707 } 708 } 709 sc->tulip_probe_media = new_probe_media; 710 tulip_timeout(sc); 711 return; 712 } 713#endif /* TULIP_DO_GPR_SENSE */ 714 /* 715 * Brute force. We cycle through each of the media types 716 * and try to transmit a packet. 717 */ 718 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST; 719 sc->tulip_probe_media = TULIP_MEDIA_MAX; 720 sc->tulip_probe_timeout = 0; 721 tulip_timeout(sc); 722 return; 723 } 724 725 if (sc->tulip_probe_state != TULIP_PROBE_MEDIATEST 726 && (sc->tulip_features & TULIP_HAVE_MII)) { 727 tulip_media_t old_media = sc->tulip_probe_media; 728 tulip_mii_autonegotiate(sc, sc->tulip_phyaddr); 729 switch (sc->tulip_probe_state) { 730 case TULIP_PROBE_FAILED: 731 case TULIP_PROBE_MEDIATEST: { 732 /* 733 * Try the next media. 734 */ 735 sc->tulip_probe_mediamask |= sc->tulip_mediums[sc->tulip_probe_media]->mi_mediamask; 736 sc->tulip_probe_timeout = 0; 737#ifdef notyet 738 if (sc->tulip_probe_state == TULIP_PROBE_FAILED) 739 break; 740 if (sc->tulip_probe_media != tulip_mii_phy_readspecific(sc)) 741 break; 742 sc->tulip_probe_timeout = TULIP_IS_MEDIA_TP(sc->tulip_probe_media) ? 2500 : 300; 743#endif 744 break; 745 } 746 case TULIP_PROBE_PHYAUTONEG: { 747 return; 748 } 749 case TULIP_PROBE_INACTIVE: { 750 /* 751 * Only probe if we autonegotiated a media that hasn't failed. 752 */ 753 sc->tulip_probe_timeout = 0; 754 if (sc->tulip_probe_mediamask & TULIP_BIT(sc->tulip_probe_media)) { 755 sc->tulip_probe_media = old_media; 756 break; 757 } 758 tulip_linkup(sc, sc->tulip_probe_media); 759 tulip_timeout(sc); 760 return; 761 } 762 default: { 763#if defined(DIAGNOSTIC) || defined(TULIP_DEBUG) 764 panic("tulip_media_poll: botch at line %d\n", __LINE__); 765#endif 766 break; 767 } 768 } 769 } 770 771 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED) { 772#if defined(TULIP_DEBUG) 773 sc->tulip_dbg.dbg_txprobes_failed[sc->tulip_probe_media]++; 774#endif 775 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE; 776 return; 777 } 778 779 /* 780 * switch to another media if we tried this one enough. 781 */ 782 if (/* event == TULIP_MEDIAPOLL_TXPROBE_FAILED || */ sc->tulip_probe_timeout <= 0) { 783#if defined(TULIP_DEBUG) 784 if (sc->tulip_probe_media == TULIP_MEDIA_UNKNOWN) { 785 printf("%s: poll media unknown!\n", 786 sc->tulip_xname); 787 sc->tulip_probe_media = TULIP_MEDIA_MAX; 788 } 789#endif 790 /* 791 * Find the next media type to check for. Full Duplex 792 * types are not allowed. 793 */ 794 do { 795 sc->tulip_probe_media -= 1; 796 if (sc->tulip_probe_media == TULIP_MEDIA_UNKNOWN) { 797 if (++sc->tulip_probe_passes == 3) { 798 printf("%s: autosense failed: cable problem?\n", 799 sc->tulip_xname); 800 if ((sc->tulip_if.if_flags & IFF_UP) == 0) { 801 sc->tulip_if.if_flags &= ~IFF_RUNNING; 802 sc->tulip_probe_state = TULIP_PROBE_INACTIVE; 803 return; 804 } 805 } 806 sc->tulip_flags ^= TULIP_TRYNWAY; /* XXX */ 807 sc->tulip_probe_mediamask = 0; 808 sc->tulip_probe_media = TULIP_MEDIA_MAX - 1; 809 } 810 } while (sc->tulip_mediums[sc->tulip_probe_media] == NULL 811 || (sc->tulip_probe_mediamask & TULIP_BIT(sc->tulip_probe_media)) 812 || TULIP_IS_MEDIA_FD(sc->tulip_probe_media)); 813 814#if defined(TULIP_DEBUG) 815 printf("%s: %s: probing %s\n", sc->tulip_xname, 816 event == TULIP_MEDIAPOLL_TXPROBE_FAILED ? "txprobe failed" : "timeout", 817 tulip_mediums[sc->tulip_probe_media]); 818#endif 819 sc->tulip_probe_timeout = TULIP_IS_MEDIA_TP(sc->tulip_probe_media) ? 2500 : 1000; 820 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST; 821 sc->tulip_probe.probe_txprobes = 0; 822 tulip_reset(sc); 823 tulip_media_set(sc, sc->tulip_probe_media); 824 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE; 825 } 826 tulip_timeout(sc); 827 828 /* 829 * If this is hanging off a phy, we know are doing NWAY and we have 830 * forced the phy to a specific speed. Wait for link up before 831 * before sending a packet. 832 */ 833 switch (sc->tulip_mediums[sc->tulip_probe_media]->mi_type) { 834 case TULIP_MEDIAINFO_MII: { 835 if (sc->tulip_probe_media != tulip_mii_phy_readspecific(sc)) 836 return; 837 break; 838 } 839 case TULIP_MEDIAINFO_SIA: { 840 if (TULIP_IS_MEDIA_TP(sc->tulip_probe_media)) { 841 if (TULIP_CSR_READ(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL) 842 return; 843 tulip_linkup(sc, sc->tulip_probe_media); 844#ifdef notyet 845 if (sc->tulip_features & TULIP_HAVE_MII) 846 tulip_timeout(sc); 847#endif 848 return; 849 } 850 break; 851 } 852 case TULIP_MEDIAINFO_RESET: 853 case TULIP_MEDIAINFO_SYM: 854 case TULIP_MEDIAINFO_NONE: 855 case TULIP_MEDIAINFO_GPR: { 856 break; 857 } 858 } 859 /* 860 * Try to send a packet. 861 */ 862 tulip_txprobe(sc); 863} 864 865static void 866tulip_media_select( 867 tulip_softc_t * const sc) 868{ 869 if (sc->tulip_features & TULIP_HAVE_GPR) { 870 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET|sc->tulip_gpinit); 871 DELAY(10); 872 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_gpdata); 873 } 874 /* 875 * If this board has no media, just return 876 */ 877 if (sc->tulip_features & TULIP_HAVE_NOMEDIA) 878 return; 879 880 if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) { 881 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask); 882 (*sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_START); 883 } else { 884 tulip_media_set(sc, sc->tulip_media); 885 } 886} 887 888static void 889tulip_21040_mediainfo_init( 890 tulip_softc_t * const sc, 891 tulip_media_t media) 892{ 893 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_THRSHLD160 894 |TULIP_CMD_BACKOFFCTR; 895 sc->tulip_if.if_baudrate = 10000000; 896 897 if (media == TULIP_MEDIA_10BASET || media == TULIP_MEDIA_UNKNOWN) { 898 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[0], 21040, 10BASET); 899 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[1], 21040, 10BASET_FD); 900 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL; 901 } 902 903 if (media == TULIP_MEDIA_AUIBNC || media == TULIP_MEDIA_UNKNOWN) { 904 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[2], 21040, AUIBNC); 905 } 906 907 if (media == TULIP_MEDIA_UNKNOWN) { 908 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[3], 21040, EXTSIA); 909 } 910} 911 912static void 913tulip_21040_media_probe( 914 tulip_softc_t * const sc) 915{ 916 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_UNKNOWN); 917 return; 918} 919 920static void 921tulip_21040_10baset_only_media_probe( 922 tulip_softc_t * const sc) 923{ 924 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_10BASET); 925 tulip_media_set(sc, TULIP_MEDIA_10BASET); 926 sc->tulip_media = TULIP_MEDIA_10BASET; 927} 928 929static void 930tulip_21040_10baset_only_media_select( 931 tulip_softc_t * const sc) 932{ 933 sc->tulip_flags |= TULIP_LINKUP; 934 if (sc->tulip_media == TULIP_MEDIA_10BASET_FD) { 935 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX; 936 sc->tulip_flags &= ~TULIP_SQETEST; 937 } else { 938 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX; 939 sc->tulip_flags |= TULIP_SQETEST; 940 } 941 tulip_media_set(sc, sc->tulip_media); 942} 943 944static void 945tulip_21040_auibnc_only_media_probe( 946 tulip_softc_t * const sc) 947{ 948 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_AUIBNC); 949 sc->tulip_flags |= TULIP_SQETEST|TULIP_LINKUP; 950 tulip_media_set(sc, TULIP_MEDIA_AUIBNC); 951 sc->tulip_media = TULIP_MEDIA_AUIBNC; 952} 953 954static void 955tulip_21040_auibnc_only_media_select( 956 tulip_softc_t * const sc) 957{ 958 tulip_media_set(sc, TULIP_MEDIA_AUIBNC); 959 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX; 960} 961 962static const tulip_boardsw_t tulip_21040_boardsw = { 963 TULIP_21040_GENERIC, 964 tulip_21040_media_probe, 965 tulip_media_select, 966 tulip_media_poll, 967}; 968 969static const tulip_boardsw_t tulip_21040_10baset_only_boardsw = { 970 TULIP_21040_GENERIC, 971 tulip_21040_10baset_only_media_probe, 972 tulip_21040_10baset_only_media_select, 973 NULL, 974}; 975 976static const tulip_boardsw_t tulip_21040_auibnc_only_boardsw = { 977 TULIP_21040_GENERIC, 978 tulip_21040_auibnc_only_media_probe, 979 tulip_21040_auibnc_only_media_select, 980 NULL, 981}; 982 983static void 984tulip_21041_mediainfo_init( 985 tulip_softc_t * const sc) 986{ 987 tulip_media_info_t * const mi = sc->tulip_mediainfo; 988 989#ifdef notyet 990 if (sc->tulip_revinfo >= 0x20) { 991 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041P2, 10BASET); 992 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041P2, 10BASET_FD); 993 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041P2, AUI); 994 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041P2, BNC); 995 return; 996 } 997#endif 998 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041, 10BASET); 999 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041, 10BASET_FD); 1000 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[2], 21041, AUI); 1001 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[3], 21041, BNC); 1002} 1003 1004static void 1005tulip_21041_media_probe( 1006 tulip_softc_t * const sc) 1007{ 1008 sc->tulip_if.if_baudrate = 10000000; 1009 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_ENHCAPTEFFCT 1010 |TULIP_CMD_THRSHLD160|TULIP_CMD_BACKOFFCTR; 1011 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL; 1012 tulip_21041_mediainfo_init(sc); 1013} 1014 1015static void 1016tulip_21041_media_poll( 1017 tulip_softc_t * const sc, 1018 const tulip_mediapoll_event_t event) 1019{ 1020 u_int32_t sia_status; 1021 1022#if defined(TULIP_DEBUG) 1023 sc->tulip_dbg.dbg_events[event]++; 1024#endif 1025 1026 if (event == TULIP_MEDIAPOLL_LINKFAIL) { 1027 if (sc->tulip_probe_state != TULIP_PROBE_INACTIVE 1028 || !TULIP_DO_AUTOSENSE(sc)) 1029 return; 1030 sc->tulip_media = TULIP_MEDIA_UNKNOWN; 1031 tulip_reset(sc); /* start probe */ 1032 return; 1033 } 1034 1035 /* 1036 * If we've been been asked to start a poll or link change interrupt 1037 * restart the probe (and reset the tulip to a known state). 1038 */ 1039 if (event == TULIP_MEDIAPOLL_START) { 1040 sc->tulip_if.if_flags |= IFF_OACTIVE; 1041 sc->tulip_cmdmode &= ~(TULIP_CMD_FULLDUPLEX|TULIP_CMD_RXRUN); 1042#ifdef notyet 1043 if (sc->tulip_revinfo >= 0x20) { 1044 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX; 1045 sc->tulip_flags |= TULIP_DIDNWAY; 1046 } 1047#endif 1048 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode); 1049 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST; 1050 sc->tulip_probe_media = TULIP_MEDIA_10BASET; 1051 sc->tulip_probe_timeout = TULIP_21041_PROBE_10BASET_TIMEOUT; 1052 tulip_media_set(sc, TULIP_MEDIA_10BASET); 1053 tulip_timeout(sc); 1054 return; 1055 } 1056 1057 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE) 1058 return; 1059 1060 if (event == TULIP_MEDIAPOLL_TXPROBE_OK) { 1061#if defined(TULIP_DEBUG) 1062 sc->tulip_dbg.dbg_txprobes_ok[sc->tulip_probe_media]++; 1063#endif 1064 tulip_linkup(sc, sc->tulip_probe_media); 1065 return; 1066 } 1067 1068 sia_status = TULIP_CSR_READ(sc, csr_sia_status); 1069 TULIP_CSR_WRITE(sc, csr_sia_status, sia_status); 1070 if ((sia_status & TULIP_SIASTS_LINKFAIL) == 0) { 1071 if (sc->tulip_revinfo >= 0x20) { 1072 if (sia_status & (PHYSTS_10BASET_FD << (16 - 6))) 1073 sc->tulip_probe_media = TULIP_MEDIA_10BASET_FD; 1074 } 1075 /* 1076 * If the link has passed LinkPass, 10baseT is the 1077 * proper media to use. 1078 */ 1079 tulip_linkup(sc, sc->tulip_probe_media); 1080 return; 1081 } 1082 1083 /* 1084 * wait for up to 2.4 seconds for the link to reach pass state. 1085 * Only then start scanning the other media for activity. 1086 * choose media with receive activity over those without. 1087 */ 1088 if (sc->tulip_probe_media == TULIP_MEDIA_10BASET) { 1089 if (event != TULIP_MEDIAPOLL_TIMER) 1090 return; 1091 if (sc->tulip_probe_timeout > 0 1092 && (sia_status & TULIP_SIASTS_OTHERRXACTIVITY) == 0) { 1093 tulip_timeout(sc); 1094 return; 1095 } 1096 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT; 1097 sc->tulip_flags |= TULIP_WANTRXACT; 1098 if (sia_status & TULIP_SIASTS_OTHERRXACTIVITY) { 1099 sc->tulip_probe_media = TULIP_MEDIA_BNC; 1100 } else { 1101 sc->tulip_probe_media = TULIP_MEDIA_AUI; 1102 } 1103 tulip_media_set(sc, sc->tulip_probe_media); 1104 tulip_timeout(sc); 1105 return; 1106 } 1107 1108 /* 1109 * If we failed, clear the txprobe active flag. 1110 */ 1111 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED) 1112 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE; 1113 1114 1115 if (event == TULIP_MEDIAPOLL_TIMER) { 1116 /* 1117 * If we've received something, then that's our link! 1118 */ 1119 if (sc->tulip_flags & TULIP_RXACT) { 1120 tulip_linkup(sc, sc->tulip_probe_media); 1121 return; 1122 } 1123 /* 1124 * if no txprobe active 1125 */ 1126 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0 1127 && ((sc->tulip_flags & TULIP_WANTRXACT) == 0 1128 || (sia_status & TULIP_SIASTS_RXACTIVITY))) { 1129 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT; 1130 tulip_txprobe(sc); 1131 tulip_timeout(sc); 1132 return; 1133 } 1134 /* 1135 * Take 2 passes through before deciding to not 1136 * wait for receive activity. Then take another 1137 * two passes before spitting out a warning. 1138 */ 1139 if (sc->tulip_probe_timeout <= 0) { 1140 if (sc->tulip_flags & TULIP_WANTRXACT) { 1141 sc->tulip_flags &= ~TULIP_WANTRXACT; 1142 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT; 1143 } else { 1144 printf("%s: autosense failed: cable problem?\n", 1145 sc->tulip_xname); 1146 if ((sc->tulip_if.if_flags & IFF_UP) == 0) { 1147 sc->tulip_if.if_flags &= ~IFF_RUNNING; 1148 sc->tulip_probe_state = TULIP_PROBE_INACTIVE; 1149 return; 1150 } 1151 } 1152 } 1153 } 1154 1155 /* 1156 * Since this media failed to probe, try the other one. 1157 */ 1158 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT; 1159 if (sc->tulip_probe_media == TULIP_MEDIA_AUI) { 1160 sc->tulip_probe_media = TULIP_MEDIA_BNC; 1161 } else { 1162 sc->tulip_probe_media = TULIP_MEDIA_AUI; 1163 } 1164 tulip_media_set(sc, sc->tulip_probe_media); 1165 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE; 1166 tulip_timeout(sc); 1167} 1168 1169static const tulip_boardsw_t tulip_21041_boardsw = { 1170 TULIP_21041_GENERIC, 1171 tulip_21041_media_probe, 1172 tulip_media_select, 1173 tulip_21041_media_poll 1174}; 1175 1176static const tulip_phy_attr_t tulip_mii_phy_attrlist[] = { 1177 { 0x20005c00, 0, /* 08-00-17 */ 1178 { 1179 { 0x19, 0x0040, 0x0040 }, /* 10TX */ 1180 { 0x19, 0x0040, 0x0000 }, /* 100TX */ 1181 }, 1182#if defined(TULIP_DEBUG) 1183 "NS DP83840", 1184#endif 1185 }, 1186 { 0x0281F400, 0, /* 00-A0-7D */ 1187 { 1188 { 0x12, 0x0010, 0x0000 }, /* 10T */ 1189 { }, /* 100TX */ 1190 { 0x12, 0x0010, 0x0010 }, /* 100T4 */ 1191 { 0x12, 0x0008, 0x0008 }, /* FULL_DUPLEX */ 1192 }, 1193#if defined(TULIP_DEBUG) 1194 "Seeq 80C240" 1195#endif 1196 }, 1197#if 0 1198 { 0x0015F420, 0, /* 00-A0-7D */ 1199 { 1200 { 0x12, 0x0010, 0x0000 }, /* 10T */ 1201 { }, /* 100TX */ 1202 { 0x12, 0x0010, 0x0010 }, /* 100T4 */ 1203 { 0x12, 0x0008, 0x0008 }, /* FULL_DUPLEX */ 1204 }, 1205#if defined(TULIP_DEBUG) 1206 "Broadcom BCM5000" 1207#endif 1208 }, 1209#endif 1210 { 0x0281F400, 0, /* 00-A0-BE */ 1211 { 1212 { 0x11, 0x8000, 0x0000 }, /* 10T */ 1213 { 0x11, 0x8000, 0x8000 }, /* 100TX */ 1214 { }, /* 100T4 */ 1215 { 0x11, 0x4000, 0x4000 }, /* FULL_DUPLEX */ 1216 }, 1217#if defined(TULIP_DEBUG) 1218 "ICS 1890" 1219#endif 1220 }, 1221 { 0 } 1222}; 1223 1224static tulip_media_t 1225tulip_mii_phy_readspecific( 1226 tulip_softc_t * const sc) 1227{ 1228 const tulip_phy_attr_t *attr; 1229 u_int16_t data; 1230 u_int32_t id; 1231 unsigned idx = 0; 1232 static const tulip_media_t table[] = { 1233 TULIP_MEDIA_UNKNOWN, 1234 TULIP_MEDIA_10BASET, 1235 TULIP_MEDIA_100BASETX, 1236 TULIP_MEDIA_100BASET4, 1237 TULIP_MEDIA_UNKNOWN, 1238 TULIP_MEDIA_10BASET_FD, 1239 TULIP_MEDIA_100BASETX_FD, 1240 TULIP_MEDIA_UNKNOWN 1241 }; 1242 1243 /* 1244 * Don't read phy specific registers if link is not up. 1245 */ 1246 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_STATUS); 1247 if ((data & (PHYSTS_LINK_UP|PHYSTS_EXTENDED_REGS)) != (PHYSTS_LINK_UP|PHYSTS_EXTENDED_REGS)) 1248 return TULIP_MEDIA_UNKNOWN; 1249 1250 id = (tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_IDLOW) << 16) | 1251 tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_IDHIGH); 1252 for (attr = tulip_mii_phy_attrlist;; attr++) { 1253 if (attr->attr_id == 0) 1254 return TULIP_MEDIA_UNKNOWN; 1255 if ((id & ~0x0F) == attr->attr_id) 1256 break; 1257 } 1258 1259 if (attr->attr_modes[PHY_MODE_100TX].pm_regno) { 1260 const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_100TX]; 1261 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno); 1262 if ((data & pm->pm_mask) == pm->pm_value) 1263 idx = 2; 1264 } 1265 if (idx == 0 && attr->attr_modes[PHY_MODE_100T4].pm_regno) { 1266 const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_100T4]; 1267 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno); 1268 if ((data & pm->pm_mask) == pm->pm_value) 1269 idx = 3; 1270 } 1271 if (idx == 0 && attr->attr_modes[PHY_MODE_10T].pm_regno) { 1272 const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_10T]; 1273 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno); 1274 if ((data & pm->pm_mask) == pm->pm_value) 1275 idx = 1; 1276 } 1277 if (idx != 0 && attr->attr_modes[PHY_MODE_FULLDUPLEX].pm_regno) { 1278 const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_FULLDUPLEX]; 1279 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno); 1280 idx += ((data & pm->pm_mask) == pm->pm_value ? 4 : 0); 1281 } 1282 return table[idx]; 1283} 1284 1285static unsigned 1286tulip_mii_get_phyaddr( 1287 tulip_softc_t * const sc, 1288 unsigned offset) 1289{ 1290 unsigned phyaddr; 1291 1292 for (phyaddr = 1; phyaddr < 32; phyaddr++) { 1293 unsigned status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS); 1294 if (status == 0 || status == 0xFFFF || status < PHYSTS_10BASET) 1295 continue; 1296 if (offset == 0) 1297 return phyaddr; 1298 offset--; 1299 } 1300 if (offset == 0) { 1301 unsigned status = tulip_mii_readreg(sc, 0, PHYREG_STATUS); 1302 if (status == 0 || status == 0xFFFF || status < PHYSTS_10BASET) 1303 return TULIP_MII_NOPHY; 1304 return 0; 1305 } 1306 return TULIP_MII_NOPHY; 1307} 1308 1309static int 1310tulip_mii_map_abilities( 1311 tulip_softc_t * const sc, 1312 unsigned abilities) 1313{ 1314 sc->tulip_abilities = abilities; 1315 if (abilities & PHYSTS_100BASETX_FD) { 1316 sc->tulip_probe_media = TULIP_MEDIA_100BASETX_FD; 1317 } else if (abilities & PHYSTS_100BASET4) { 1318 sc->tulip_probe_media = TULIP_MEDIA_100BASET4; 1319 } else if (abilities & PHYSTS_100BASETX) { 1320 sc->tulip_probe_media = TULIP_MEDIA_100BASETX; 1321 } else if (abilities & PHYSTS_10BASET_FD) { 1322 sc->tulip_probe_media = TULIP_MEDIA_10BASET_FD; 1323 } else if (abilities & PHYSTS_10BASET) { 1324 sc->tulip_probe_media = TULIP_MEDIA_10BASET; 1325 } else { 1326 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST; 1327 return 0; 1328 } 1329 sc->tulip_probe_state = TULIP_PROBE_INACTIVE; 1330 return 1; 1331} 1332 1333static void 1334tulip_mii_autonegotiate( 1335 tulip_softc_t * const sc, 1336 const unsigned phyaddr) 1337{ 1338 switch (sc->tulip_probe_state) { 1339 case TULIP_PROBE_MEDIATEST: 1340 case TULIP_PROBE_INACTIVE: { 1341 sc->tulip_flags |= TULIP_DIDNWAY; 1342 tulip_mii_writereg(sc, phyaddr, PHYREG_CONTROL, PHYCTL_RESET); 1343 sc->tulip_probe_timeout = 3000; 1344 sc->tulip_intrmask |= TULIP_STS_ABNRMLINTR|TULIP_STS_NORMALINTR; 1345 sc->tulip_probe_state = TULIP_PROBE_PHYRESET; 1346 } 1347 /* FALLTHROUGH */ 1348 case TULIP_PROBE_PHYRESET: { 1349 u_int32_t status; 1350 u_int32_t data = tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL); 1351 if (data & PHYCTL_RESET) { 1352 if (sc->tulip_probe_timeout > 0) { 1353 tulip_timeout(sc); 1354 return; 1355 } 1356 printf("%s(phy%d): error: reset of PHY never completed!\n", 1357 sc->tulip_xname, phyaddr); 1358 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE; 1359 sc->tulip_probe_state = TULIP_PROBE_FAILED; 1360 sc->tulip_if.if_flags &= ~(IFF_UP|IFF_RUNNING); 1361 return; 1362 } 1363 status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS); 1364 if ((status & PHYSTS_CAN_AUTONEG) == 0) { 1365#if defined(TULIP_DEBUG) 1366 loudprintf("%s(phy%d): autonegotiation disabled\n", 1367 sc->tulip_xname, phyaddr); 1368#endif 1369 sc->tulip_flags &= ~TULIP_DIDNWAY; 1370 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST; 1371 return; 1372 } 1373 if (tulip_mii_readreg(sc, phyaddr, PHYREG_AUTONEG_ADVERTISEMENT) != ((status >> 6) | 0x01)) 1374 tulip_mii_writereg(sc, phyaddr, PHYREG_AUTONEG_ADVERTISEMENT, (status >> 6) | 0x01); 1375 tulip_mii_writereg(sc, phyaddr, PHYREG_CONTROL, data|PHYCTL_AUTONEG_RESTART|PHYCTL_AUTONEG_ENABLE); 1376 data = tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL); 1377#if defined(TULIP_DEBUG) 1378 if ((data & PHYCTL_AUTONEG_ENABLE) == 0) 1379 loudprintf("%s(phy%d): oops: enable autonegotiation failed: 0x%04x\n", 1380 sc->tulip_xname, phyaddr, data); 1381 else 1382 loudprintf("%s(phy%d): autonegotiation restarted: 0x%04x\n", 1383 sc->tulip_xname, phyaddr, data); 1384 sc->tulip_dbg.dbg_nway_starts++; 1385#endif 1386 sc->tulip_probe_state = TULIP_PROBE_PHYAUTONEG; 1387 sc->tulip_probe_timeout = 3000; 1388 } 1389 /* FALLTHROUGH */ 1390 case TULIP_PROBE_PHYAUTONEG: { 1391 u_int32_t status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS); 1392 u_int32_t data; 1393 if ((status & PHYSTS_AUTONEG_DONE) == 0) { 1394 if (sc->tulip_probe_timeout > 0) { 1395 tulip_timeout(sc); 1396 return; 1397 } 1398#if defined(TULIP_DEBUG) 1399 loudprintf("%s(phy%d): autonegotiation timeout: sts=0x%04x, ctl=0x%04x\n", 1400 sc->tulip_xname, phyaddr, status, 1401 tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL)); 1402#endif 1403 sc->tulip_flags &= ~TULIP_DIDNWAY; 1404 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST; 1405 return; 1406 } 1407 data = tulip_mii_readreg(sc, phyaddr, PHYREG_AUTONEG_ABILITIES); 1408#if defined(TULIP_DEBUG) 1409 loudprintf("%s(phy%d): autonegotiation complete: 0x%04x\n", 1410 sc->tulip_xname, phyaddr, data); 1411#endif 1412 data = (data << 6) & status; 1413 if (!tulip_mii_map_abilities(sc, data)) 1414 sc->tulip_flags &= ~TULIP_DIDNWAY; 1415 return; 1416 } 1417 default: { 1418#if defined(DIAGNOSTIC) 1419 panic("tulip_media_poll: botch at line %d\n", __LINE__); 1420#endif 1421 break; 1422 } 1423 } 1424#if defined(TULIP_DEBUG) 1425 loudprintf("%s(phy%d): autonegotiation failure: state = %d\n", 1426 sc->tulip_xname, phyaddr, sc->tulip_probe_state); 1427 sc->tulip_dbg.dbg_nway_failures++; 1428#endif 1429} 1430 1431static void 1432tulip_2114x_media_preset( 1433 tulip_softc_t * const sc) 1434{ 1435 const tulip_media_info_t *mi = NULL; 1436 tulip_media_t media = sc->tulip_media; 1437 1438 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE) 1439 media = sc->tulip_media; 1440 else 1441 media = sc->tulip_probe_media; 1442 1443 sc->tulip_cmdmode &= ~TULIP_CMD_PORTSELECT; 1444 sc->tulip_flags &= ~TULIP_SQETEST; 1445 if (media != TULIP_MEDIA_UNKNOWN && media != TULIP_MEDIA_MAX) { 1446#if defined(TULIP_DEBUG) 1447 if (media < TULIP_MEDIA_MAX && sc->tulip_mediums[media] != NULL) { 1448#endif 1449 mi = sc->tulip_mediums[media]; 1450 if (mi->mi_type == TULIP_MEDIAINFO_MII) { 1451 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT; 1452 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR 1453 || mi->mi_type == TULIP_MEDIAINFO_SYM) { 1454 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS; 1455 sc->tulip_cmdmode |= mi->mi_cmdmode; 1456 } else if (mi->mi_type == TULIP_MEDIAINFO_SIA) { 1457 TULIP_CSR_WRITE(sc, csr_sia_connectivity, TULIP_SIACONN_RESET); 1458 } 1459#if defined(TULIP_DEBUG) 1460 } else { 1461 printf("%s: preset: bad media %d!\n", 1462 sc->tulip_xname, media); 1463 } 1464#endif 1465 } 1466 switch (media) { 1467 case TULIP_MEDIA_BNC: 1468 case TULIP_MEDIA_AUI: 1469 case TULIP_MEDIA_10BASET: { 1470 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX; 1471 sc->tulip_cmdmode |= TULIP_CMD_TXTHRSHLDCTL; 1472 sc->tulip_if.if_baudrate = 10000000; 1473 sc->tulip_flags |= TULIP_SQETEST; 1474 break; 1475 } 1476 case TULIP_MEDIA_10BASET_FD: { 1477 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX|TULIP_CMD_TXTHRSHLDCTL; 1478 sc->tulip_if.if_baudrate = 10000000; 1479 break; 1480 } 1481 case TULIP_MEDIA_100BASEFX: 1482 case TULIP_MEDIA_100BASET4: 1483 case TULIP_MEDIA_100BASETX: { 1484 sc->tulip_cmdmode &= ~(TULIP_CMD_FULLDUPLEX|TULIP_CMD_TXTHRSHLDCTL); 1485 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT; 1486 sc->tulip_if.if_baudrate = 100000000; 1487 break; 1488 } 1489 case TULIP_MEDIA_100BASEFX_FD: 1490 case TULIP_MEDIA_100BASETX_FD: { 1491 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX|TULIP_CMD_PORTSELECT; 1492 sc->tulip_cmdmode &= ~TULIP_CMD_TXTHRSHLDCTL; 1493 sc->tulip_if.if_baudrate = 100000000; 1494 break; 1495 } 1496 default: { 1497 break; 1498 } 1499 } 1500 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode); 1501} 1502 1503/* 1504 ******************************************************************** 1505 * Start of 21140/21140A support which does not use the MII interface 1506 */ 1507 1508static void 1509tulip_null_media_poll( 1510 tulip_softc_t * const sc, 1511 tulip_mediapoll_event_t event) 1512{ 1513#if defined(TULIP_DEBUG) 1514 sc->tulip_dbg.dbg_events[event]++; 1515#endif 1516#if defined(DIAGNOSTIC) 1517 printf("%s: botch(media_poll) at line %d\n", 1518 sc->tulip_xname, __LINE__); 1519#endif 1520} 1521 1522__inline static void 1523tulip_21140_mediainit( 1524 tulip_softc_t * const sc, 1525 tulip_media_info_t * const mip, 1526 tulip_media_t const media, 1527 unsigned gpdata, 1528 unsigned cmdmode) 1529{ 1530 sc->tulip_mediums[media] = mip; 1531 mip->mi_type = TULIP_MEDIAINFO_GPR; 1532 mip->mi_cmdmode = cmdmode; 1533 mip->mi_gpdata = gpdata; 1534} 1535 1536static void 1537tulip_21140_evalboard_media_probe( 1538 tulip_softc_t * const sc) 1539{ 1540 tulip_media_info_t *mip = sc->tulip_mediainfo; 1541 1542 sc->tulip_gpinit = TULIP_GP_EB_PINS; 1543 sc->tulip_gpdata = TULIP_GP_EB_INIT; 1544 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_PINS); 1545 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_INIT); 1546 TULIP_CSR_WRITE(sc, csr_command, 1547 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT | 1548 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE); 1549 TULIP_CSR_WRITE(sc, csr_command, 1550 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL); 1551 DELAY(1000000); 1552 if ((TULIP_CSR_READ(sc, csr_gp) & TULIP_GP_EB_OK100) != 0) { 1553 sc->tulip_media = TULIP_MEDIA_10BASET; 1554 } else { 1555 sc->tulip_media = TULIP_MEDIA_100BASETX; 1556 } 1557 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET, 1558 TULIP_GP_EB_INIT, 1559 TULIP_CMD_TXTHRSHLDCTL); 1560 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD, 1561 TULIP_GP_EB_INIT, 1562 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX); 1563 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX, 1564 TULIP_GP_EB_INIT, 1565 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION 1566 |TULIP_CMD_SCRAMBLER); 1567 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD, 1568 TULIP_GP_EB_INIT, 1569 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION 1570 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX); 1571} 1572 1573static const tulip_boardsw_t tulip_21140_eb_boardsw = { 1574 TULIP_21140_DEC_EB, 1575 tulip_21140_evalboard_media_probe, 1576 tulip_media_select, 1577 tulip_null_media_poll, 1578 tulip_2114x_media_preset, 1579}; 1580 1581static void 1582tulip_21140_accton_media_probe( 1583 tulip_softc_t * const sc) 1584{ 1585 tulip_media_info_t *mip = sc->tulip_mediainfo; 1586 unsigned gpdata; 1587 1588 sc->tulip_gpinit = TULIP_GP_EB_PINS; 1589 sc->tulip_gpdata = TULIP_GP_EB_INIT; 1590 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_PINS); 1591 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_INIT); 1592 TULIP_CSR_WRITE(sc, csr_command, 1593 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT | 1594 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE); 1595 TULIP_CSR_WRITE(sc, csr_command, 1596 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL); 1597 DELAY(1000000); 1598 gpdata = TULIP_CSR_READ(sc, csr_gp); 1599 if ((gpdata & TULIP_GP_EN1207_UTP_INIT) == 0) { 1600 sc->tulip_media = TULIP_MEDIA_10BASET; 1601 } else { 1602 if ((gpdata & TULIP_GP_EN1207_BNC_INIT) == 0) { 1603 sc->tulip_media = TULIP_MEDIA_BNC; 1604 } else { 1605 sc->tulip_media = TULIP_MEDIA_100BASETX; 1606 } 1607 } 1608 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_BNC, 1609 TULIP_GP_EN1207_BNC_INIT, 1610 TULIP_CMD_TXTHRSHLDCTL); 1611 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET, 1612 TULIP_GP_EN1207_UTP_INIT, 1613 TULIP_CMD_TXTHRSHLDCTL); 1614 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD, 1615 TULIP_GP_EN1207_UTP_INIT, 1616 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX); 1617 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX, 1618 TULIP_GP_EN1207_100_INIT, 1619 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION 1620 |TULIP_CMD_SCRAMBLER); 1621 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD, 1622 TULIP_GP_EN1207_100_INIT, 1623 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION 1624 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX); 1625} 1626 1627static const tulip_boardsw_t tulip_21140_accton_boardsw = { 1628 TULIP_21140_EN1207, 1629 tulip_21140_accton_media_probe, 1630 tulip_media_select, 1631 tulip_null_media_poll, 1632 tulip_2114x_media_preset, 1633}; 1634 1635static void 1636tulip_21140_smc9332_media_probe( 1637 tulip_softc_t * const sc) 1638{ 1639 tulip_media_info_t *mip = sc->tulip_mediainfo; 1640 int idx, cnt = 0; 1641 1642 TULIP_CSR_WRITE(sc, csr_command, TULIP_CMD_PORTSELECT|TULIP_CMD_MUSTBEONE); 1643 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET); 1644 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at 1645 33MHz that comes to two microseconds but wait a 1646 bit longer anyways) */ 1647 TULIP_CSR_WRITE(sc, csr_command, TULIP_CMD_PORTSELECT | 1648 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE); 1649 sc->tulip_gpinit = TULIP_GP_SMC_9332_PINS; 1650 sc->tulip_gpdata = TULIP_GP_SMC_9332_INIT; 1651 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_SMC_9332_PINS|TULIP_GP_PINSET); 1652 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_SMC_9332_INIT); 1653 DELAY(200000); 1654 for (idx = 1000; idx > 0; idx--) { 1655 u_int32_t csr = TULIP_CSR_READ(sc, csr_gp); 1656 if ((csr & (TULIP_GP_SMC_9332_OK10|TULIP_GP_SMC_9332_OK100)) == (TULIP_GP_SMC_9332_OK10|TULIP_GP_SMC_9332_OK100)) { 1657 if (++cnt > 100) 1658 break; 1659 } else if ((csr & TULIP_GP_SMC_9332_OK10) == 0) { 1660 break; 1661 } else { 1662 cnt = 0; 1663 } 1664 DELAY(1000); 1665 } 1666 sc->tulip_media = cnt > 100 ? TULIP_MEDIA_100BASETX : TULIP_MEDIA_10BASET; 1667 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX, 1668 TULIP_GP_SMC_9332_INIT, 1669 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION 1670 |TULIP_CMD_SCRAMBLER); 1671 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD, 1672 TULIP_GP_SMC_9332_INIT, 1673 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION 1674 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX); 1675 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET, 1676 TULIP_GP_SMC_9332_INIT, 1677 TULIP_CMD_TXTHRSHLDCTL); 1678 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD, 1679 TULIP_GP_SMC_9332_INIT, 1680 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX); 1681} 1682 1683static const tulip_boardsw_t tulip_21140_smc9332_boardsw = { 1684 TULIP_21140_SMC_9332, 1685 tulip_21140_smc9332_media_probe, 1686 tulip_media_select, 1687 tulip_null_media_poll, 1688 tulip_2114x_media_preset, 1689}; 1690 1691static void 1692tulip_21140_cogent_em100_media_probe( 1693 tulip_softc_t * const sc) 1694{ 1695 tulip_media_info_t *mip = sc->tulip_mediainfo; 1696 u_int32_t cmdmode = TULIP_CSR_READ(sc, csr_command); 1697 1698 sc->tulip_gpinit = TULIP_GP_EM100_PINS; 1699 sc->tulip_gpdata = TULIP_GP_EM100_INIT; 1700 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EM100_PINS); 1701 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EM100_INIT); 1702 1703 cmdmode = TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION|TULIP_CMD_MUSTBEONE; 1704 cmdmode &= ~(TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_SCRAMBLER); 1705 if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100FX_ID) { 1706 TULIP_CSR_WRITE(sc, csr_command, cmdmode); 1707 sc->tulip_media = TULIP_MEDIA_100BASEFX; 1708 1709 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASEFX, 1710 TULIP_GP_EM100_INIT, 1711 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION); 1712 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASEFX_FD, 1713 TULIP_GP_EM100_INIT, 1714 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION 1715 |TULIP_CMD_FULLDUPLEX); 1716 } else { 1717 TULIP_CSR_WRITE(sc, csr_command, cmdmode|TULIP_CMD_SCRAMBLER); 1718 sc->tulip_media = TULIP_MEDIA_100BASETX; 1719 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX, 1720 TULIP_GP_EM100_INIT, 1721 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION 1722 |TULIP_CMD_SCRAMBLER); 1723 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD, 1724 TULIP_GP_EM100_INIT, 1725 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION 1726 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX); 1727 } 1728} 1729 1730static const tulip_boardsw_t tulip_21140_cogent_em100_boardsw = { 1731 TULIP_21140_COGENT_EM100, 1732 tulip_21140_cogent_em100_media_probe, 1733 tulip_media_select, 1734 tulip_null_media_poll, 1735 tulip_2114x_media_preset 1736}; 1737 1738static void 1739tulip_21140_znyx_zx34x_media_probe( 1740 tulip_softc_t * const sc) 1741{ 1742 tulip_media_info_t *mip = sc->tulip_mediainfo; 1743 int cnt10 = 0, cnt100 = 0, idx; 1744 1745 sc->tulip_gpinit = TULIP_GP_ZX34X_PINS; 1746 sc->tulip_gpdata = TULIP_GP_ZX34X_INIT; 1747 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ZX34X_PINS); 1748 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ZX34X_INIT); 1749 TULIP_CSR_WRITE(sc, csr_command, 1750 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT | 1751 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE); 1752 TULIP_CSR_WRITE(sc, csr_command, 1753 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL); 1754 1755 DELAY(200000); 1756 for (idx = 1000; idx > 0; idx--) { 1757 u_int32_t csr = TULIP_CSR_READ(sc, csr_gp); 1758 if ((csr & (TULIP_GP_ZX34X_LNKFAIL|TULIP_GP_ZX34X_SYMDET|TULIP_GP_ZX34X_SIGDET)) == (TULIP_GP_ZX34X_LNKFAIL|TULIP_GP_ZX34X_SYMDET|TULIP_GP_ZX34X_SIGDET)) { 1759 if (++cnt100 > 100) 1760 break; 1761 } else if ((csr & TULIP_GP_ZX34X_LNKFAIL) == 0) { 1762 if (++cnt10 > 100) 1763 break; 1764 } else { 1765 cnt10 = 0; 1766 cnt100 = 0; 1767 } 1768 DELAY(1000); 1769 } 1770 sc->tulip_media = cnt100 > 100 ? TULIP_MEDIA_100BASETX : TULIP_MEDIA_10BASET; 1771 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET, 1772 TULIP_GP_ZX34X_INIT, 1773 TULIP_CMD_TXTHRSHLDCTL); 1774 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD, 1775 TULIP_GP_ZX34X_INIT, 1776 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX); 1777 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX, 1778 TULIP_GP_ZX34X_INIT, 1779 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION 1780 |TULIP_CMD_SCRAMBLER); 1781 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD, 1782 TULIP_GP_ZX34X_INIT, 1783 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION 1784 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX); 1785} 1786 1787static const tulip_boardsw_t tulip_21140_znyx_zx34x_boardsw = { 1788 TULIP_21140_ZNYX_ZX34X, 1789 tulip_21140_znyx_zx34x_media_probe, 1790 tulip_media_select, 1791 tulip_null_media_poll, 1792 tulip_2114x_media_preset, 1793}; 1794 1795static void 1796tulip_2114x_media_probe( 1797 tulip_softc_t * const sc) 1798{ 1799 sc->tulip_cmdmode |= TULIP_CMD_MUSTBEONE 1800 |TULIP_CMD_BACKOFFCTR|TULIP_CMD_THRSHLD72; 1801} 1802 1803static const tulip_boardsw_t tulip_2114x_isv_boardsw = { 1804 TULIP_21140_ISV, 1805 tulip_2114x_media_probe, 1806 tulip_media_select, 1807 tulip_media_poll, 1808 tulip_2114x_media_preset, 1809}; 1810 1811/* 1812 * ******** END of chip-specific handlers. *********** 1813 */ 1814 1815/* 1816 * Code the read the SROM and MII bit streams (I2C) 1817 */ 1818#define EMIT do { TULIP_CSR_WRITE(sc, csr_srom_mii, csr); DELAY(1); } while (0) 1819 1820static void 1821tulip_srom_idle( 1822 tulip_softc_t * const sc) 1823{ 1824 unsigned bit, csr; 1825 1826 csr = SROMSEL ; EMIT; 1827 csr = SROMSEL | SROMRD; EMIT; 1828 csr ^= SROMCS; EMIT; 1829 csr ^= SROMCLKON; EMIT; 1830 1831 /* 1832 * Write 25 cycles of 0 which will force the SROM to be idle. 1833 */ 1834 for (bit = 3 + SROM_BITWIDTH + 16; bit > 0; bit--) { 1835 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */ 1836 csr ^= SROMCLKON; EMIT; /* clock high; data valid */ 1837 } 1838 csr ^= SROMCLKOFF; EMIT; 1839 csr ^= SROMCS; EMIT; 1840 csr = 0; EMIT; 1841} 1842 1843 1844static void 1845tulip_srom_read( 1846 tulip_softc_t * const sc) 1847{ 1848 unsigned idx; 1849 const unsigned bitwidth = SROM_BITWIDTH; 1850 const unsigned cmdmask = (SROMCMD_RD << bitwidth); 1851 const unsigned msb = 1 << (bitwidth + 3 - 1); 1852 unsigned lastidx = (1 << bitwidth) - 1; 1853 1854 tulip_srom_idle(sc); 1855 1856 for (idx = 0; idx <= lastidx; idx++) { 1857 unsigned lastbit, data, bits, bit, csr; 1858 csr = SROMSEL ; EMIT; 1859 csr = SROMSEL | SROMRD; EMIT; 1860 csr ^= SROMCSON; EMIT; 1861 csr ^= SROMCLKON; EMIT; 1862 1863 lastbit = 0; 1864 for (bits = idx|cmdmask, bit = bitwidth + 3; bit > 0; bit--, bits <<= 1) { 1865 const unsigned thisbit = bits & msb; 1866 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */ 1867 if (thisbit != lastbit) { 1868 csr ^= SROMDOUT; EMIT; /* clock low; invert data */ 1869 } else { 1870 EMIT; 1871 } 1872 csr ^= SROMCLKON; EMIT; /* clock high; data valid */ 1873 lastbit = thisbit; 1874 } 1875 csr ^= SROMCLKOFF; EMIT; 1876 1877 for (data = 0, bits = 0; bits < 16; bits++) { 1878 data <<= 1; 1879 csr ^= SROMCLKON; EMIT; /* clock high; data valid */ 1880 data |= TULIP_CSR_READ(sc, csr_srom_mii) & SROMDIN ? 1 : 0; 1881 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */ 1882 } 1883 sc->tulip_rombuf[idx*2] = data & 0xFF; 1884 sc->tulip_rombuf[idx*2+1] = data >> 8; 1885 csr = SROMSEL | SROMRD; EMIT; 1886 csr = 0; EMIT; 1887 } 1888 tulip_srom_idle(sc); 1889} 1890 1891#define MII_EMIT do { TULIP_CSR_WRITE(sc, csr_srom_mii, csr); DELAY(1); } while (0) 1892 1893static void 1894tulip_mii_writebits( 1895 tulip_softc_t * const sc, 1896 unsigned data, 1897 unsigned bits) 1898{ 1899 unsigned msb = 1 << (bits - 1); 1900 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK); 1901 unsigned lastbit = (csr & MII_DOUT) ? msb : 0; 1902 1903 csr |= MII_WR; MII_EMIT; /* clock low; assert write */ 1904 1905 for (; bits > 0; bits--, data <<= 1) { 1906 const unsigned thisbit = data & msb; 1907 if (thisbit != lastbit) { 1908 csr ^= MII_DOUT; MII_EMIT; /* clock low; invert data */ 1909 } 1910 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */ 1911 lastbit = thisbit; 1912 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */ 1913 } 1914} 1915 1916static void 1917tulip_mii_turnaround( 1918 tulip_softc_t * const sc, 1919 unsigned cmd) 1920{ 1921 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK); 1922 1923 if (cmd == MII_WRCMD) { 1924 csr |= MII_DOUT; MII_EMIT; /* clock low; change data */ 1925 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */ 1926 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */ 1927 csr ^= MII_DOUT; MII_EMIT; /* clock low; change data */ 1928 } else { 1929 csr |= MII_RD; MII_EMIT; /* clock low; switch to read */ 1930 } 1931 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */ 1932 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */ 1933} 1934 1935static unsigned 1936tulip_mii_readbits( 1937 tulip_softc_t * const sc) 1938{ 1939 unsigned data; 1940 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK); 1941 int idx; 1942 1943 for (idx = 0, data = 0; idx < 16; idx++) { 1944 data <<= 1; /* this is NOOP on the first pass through */ 1945 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */ 1946 if (TULIP_CSR_READ(sc, csr_srom_mii) & MII_DIN) 1947 data |= 1; 1948 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */ 1949 } 1950 csr ^= MII_RD; MII_EMIT; /* clock low; turn off read */ 1951 1952 return data; 1953} 1954 1955static unsigned 1956tulip_mii_readreg( 1957 tulip_softc_t * const sc, 1958 unsigned devaddr, 1959 unsigned regno) 1960{ 1961 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK); 1962 unsigned data; 1963 1964 csr &= ~(MII_RD|MII_CLK); MII_EMIT; 1965 tulip_mii_writebits(sc, MII_PREAMBLE, 32); 1966 tulip_mii_writebits(sc, MII_RDCMD, 8); 1967 tulip_mii_writebits(sc, devaddr, 5); 1968 tulip_mii_writebits(sc, regno, 5); 1969 tulip_mii_turnaround(sc, MII_RDCMD); 1970 1971 data = tulip_mii_readbits(sc); 1972#if defined(TULIP_DEBUG) 1973 sc->tulip_dbg.dbg_phyregs[regno][0] = data; 1974 sc->tulip_dbg.dbg_phyregs[regno][1]++; 1975#endif 1976 return data; 1977} 1978 1979static void 1980tulip_mii_writereg( 1981 tulip_softc_t * const sc, 1982 unsigned devaddr, 1983 unsigned regno, 1984 unsigned data) 1985{ 1986 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK); 1987 csr &= ~(MII_RD|MII_CLK); MII_EMIT; 1988 tulip_mii_writebits(sc, MII_PREAMBLE, 32); 1989 tulip_mii_writebits(sc, MII_WRCMD, 8); 1990 tulip_mii_writebits(sc, devaddr, 5); 1991 tulip_mii_writebits(sc, regno, 5); 1992 tulip_mii_turnaround(sc, MII_WRCMD); 1993 tulip_mii_writebits(sc, data, 16); 1994#if defined(TULIP_DEBUG) 1995 sc->tulip_dbg.dbg_phyregs[regno][2] = data; 1996 sc->tulip_dbg.dbg_phyregs[regno][3]++; 1997#endif 1998} 1999 2000#define tulip_mchash(mca) (ether_crc32_le(mca, 6) & 0x1FF) 2001#define tulip_srom_crcok(databuf) ( \ 2002 ((ether_crc32_le(databuf, 126) & 0xFFFFU) ^ 0xFFFFU) == \ 2003 ((databuf)[126] | ((databuf)[127] << 8))) 2004 2005static void 2006tulip_identify_dec_nic( 2007 tulip_softc_t * const sc) 2008{ 2009 strcpy(sc->tulip_boardid, "DEC "); 2010#define D0 4 2011 if (sc->tulip_chipid <= TULIP_21040) 2012 return; 2013 if (bcmp(sc->tulip_rombuf + 29, "DE500", 5) == 0 2014 || bcmp(sc->tulip_rombuf + 29, "DE450", 5) == 0) { 2015 bcopy(sc->tulip_rombuf + 29, &sc->tulip_boardid[D0], 8); 2016 sc->tulip_boardid[D0+8] = ' '; 2017 } 2018#undef D0 2019} 2020 2021static void 2022tulip_identify_znyx_nic( 2023 tulip_softc_t * const sc) 2024{ 2025 unsigned id = 0; 2026 strcpy(sc->tulip_boardid, "ZNYX ZX3XX "); 2027 if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) { 2028 unsigned znyx_ptr; 2029 sc->tulip_boardid[8] = '4'; 2030 znyx_ptr = sc->tulip_rombuf[124] + 256 * sc->tulip_rombuf[125]; 2031 if (znyx_ptr < 26 || znyx_ptr > 116) { 2032 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw; 2033 return; 2034 } 2035 /* ZX344 = 0010 .. 0013FF 2036 */ 2037 if (sc->tulip_rombuf[znyx_ptr] == 0x4A 2038 && sc->tulip_rombuf[znyx_ptr + 1] == 0x52 2039 && sc->tulip_rombuf[znyx_ptr + 2] == 0x01) { 2040 id = sc->tulip_rombuf[znyx_ptr + 5] + 256 * sc->tulip_rombuf[znyx_ptr + 4]; 2041 if ((id >> 8) == (TULIP_ZNYX_ID_ZX342 >> 8)) { 2042 sc->tulip_boardid[9] = '2'; 2043 if (id == TULIP_ZNYX_ID_ZX342B) { 2044 sc->tulip_boardid[10] = 'B'; 2045 sc->tulip_boardid[11] = ' '; 2046 } 2047 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw; 2048 } else if (id == TULIP_ZNYX_ID_ZX344) { 2049 sc->tulip_boardid[10] = '4'; 2050 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw; 2051 } else if (id == TULIP_ZNYX_ID_ZX345) { 2052 sc->tulip_boardid[9] = (sc->tulip_rombuf[19] > 1) ? '8' : '5'; 2053 } else if (id == TULIP_ZNYX_ID_ZX346) { 2054 sc->tulip_boardid[9] = '6'; 2055 } else if (id == TULIP_ZNYX_ID_ZX351) { 2056 sc->tulip_boardid[8] = '5'; 2057 sc->tulip_boardid[9] = '1'; 2058 } 2059 } 2060 if (id == 0) { 2061 /* 2062 * Assume it's a ZX342... 2063 */ 2064 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw; 2065 } 2066 return; 2067 } 2068 sc->tulip_boardid[8] = '1'; 2069 if (sc->tulip_chipid == TULIP_21041) { 2070 sc->tulip_boardid[10] = '1'; 2071 return; 2072 } 2073 if (sc->tulip_rombuf[32] == 0x4A && sc->tulip_rombuf[33] == 0x52) { 2074 id = sc->tulip_rombuf[37] + 256 * sc->tulip_rombuf[36]; 2075 if (id == TULIP_ZNYX_ID_ZX312T) { 2076 sc->tulip_boardid[9] = '2'; 2077 sc->tulip_boardid[10] = 'T'; 2078 sc->tulip_boardid[11] = ' '; 2079 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw; 2080 } else if (id == TULIP_ZNYX_ID_ZX314_INTA) { 2081 sc->tulip_boardid[9] = '4'; 2082 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw; 2083 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM; 2084 } else if (id == TULIP_ZNYX_ID_ZX314) { 2085 sc->tulip_boardid[9] = '4'; 2086 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw; 2087 sc->tulip_features |= TULIP_HAVE_BASEROM; 2088 } else if (id == TULIP_ZNYX_ID_ZX315_INTA) { 2089 sc->tulip_boardid[9] = '5'; 2090 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM; 2091 } else if (id == TULIP_ZNYX_ID_ZX315) { 2092 sc->tulip_boardid[9] = '5'; 2093 sc->tulip_features |= TULIP_HAVE_BASEROM; 2094 } else { 2095 id = 0; 2096 } 2097 } 2098 if (id == 0) { 2099 if ((sc->tulip_enaddr[3] & ~3) == 0xF0 && (sc->tulip_enaddr[5] & 2) == 0) { 2100 sc->tulip_boardid[9] = '4'; 2101 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw; 2102 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM; 2103 } else if ((sc->tulip_enaddr[3] & ~3) == 0xF4 && (sc->tulip_enaddr[5] & 1) == 0) { 2104 sc->tulip_boardid[9] = '5'; 2105 sc->tulip_boardsw = &tulip_21040_boardsw; 2106 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM; 2107 } else if ((sc->tulip_enaddr[3] & ~3) == 0xEC) { 2108 sc->tulip_boardid[9] = '2'; 2109 sc->tulip_boardsw = &tulip_21040_boardsw; 2110 } 2111 } 2112} 2113 2114static void 2115tulip_identify_smc_nic( 2116 tulip_softc_t * const sc) 2117{ 2118 u_int32_t id1, id2, ei; 2119 int auibnc = 0, utp = 0; 2120 char *cp; 2121 2122 strcpy(sc->tulip_boardid, "SMC "); 2123 if (sc->tulip_chipid == TULIP_21041) 2124 return; 2125 if (sc->tulip_chipid != TULIP_21040) { 2126 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw) { 2127 strcpy(&sc->tulip_boardid[4], "9332DST "); 2128 sc->tulip_boardsw = &tulip_21140_smc9332_boardsw; 2129 } else if (sc->tulip_features & (TULIP_HAVE_BASEROM|TULIP_HAVE_SLAVEDROM)) { 2130 strcpy(&sc->tulip_boardid[4], "9334BDT "); 2131 } else { 2132 strcpy(&sc->tulip_boardid[4], "9332BDT "); 2133 } 2134 return; 2135 } 2136 id1 = sc->tulip_rombuf[0x60] | (sc->tulip_rombuf[0x61] << 8); 2137 id2 = sc->tulip_rombuf[0x62] | (sc->tulip_rombuf[0x63] << 8); 2138 ei = sc->tulip_rombuf[0x66] | (sc->tulip_rombuf[0x67] << 8); 2139 2140 strcpy(&sc->tulip_boardid[4], "8432"); 2141 cp = &sc->tulip_boardid[8]; 2142 if ((id1 & 1) == 0) 2143 *cp++ = 'B', auibnc = 1; 2144 if ((id1 & 0xFF) > 0x32) 2145 *cp++ = 'T', utp = 1; 2146 if ((id1 & 0x4000) == 0) 2147 *cp++ = 'A', auibnc = 1; 2148 if (id2 == 0x15) { 2149 sc->tulip_boardid[7] = '4'; 2150 *cp++ = '-'; 2151 *cp++ = 'C'; 2152 *cp++ = 'H'; 2153 *cp++ = (ei ? '2' : '1'); 2154 } 2155 *cp++ = ' '; 2156 *cp = '\0'; 2157 if (utp && !auibnc) 2158 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw; 2159 else if (!utp && auibnc) 2160 sc->tulip_boardsw = &tulip_21040_auibnc_only_boardsw; 2161} 2162 2163static void 2164tulip_identify_cogent_nic( 2165 tulip_softc_t * const sc) 2166{ 2167 strcpy(sc->tulip_boardid, "Cogent "); 2168 if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) { 2169 if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100TX_ID) { 2170 strcat(sc->tulip_boardid, "EM100TX "); 2171 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw; 2172#if defined(TULIP_COGENT_EM110TX_ID) 2173 } else if (sc->tulip_rombuf[32] == TULIP_COGENT_EM110TX_ID) { 2174 strcat(sc->tulip_boardid, "EM110TX "); 2175 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw; 2176#endif 2177 } else if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100FX_ID) { 2178 strcat(sc->tulip_boardid, "EM100FX "); 2179 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw; 2180 } 2181 /* 2182 * Magic number (0x24001109U) is the SubVendor (0x2400) and 2183 * SubDevId (0x1109) for the ANA6944TX (EM440TX). 2184 */ 2185 if (*(u_int32_t *) sc->tulip_rombuf == 0x24001109U 2186 && (sc->tulip_features & TULIP_HAVE_BASEROM)) { 2187 /* 2188 * Cogent (Adaptec) is still mapping all INTs to INTA of 2189 * first 21140. Dumb! Dumb! 2190 */ 2191 strcat(sc->tulip_boardid, "EM440TX "); 2192 sc->tulip_features |= TULIP_HAVE_SHAREDINTR; 2193 } 2194 } else if (sc->tulip_chipid == TULIP_21040) { 2195 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM; 2196 } 2197} 2198 2199static void 2200tulip_identify_accton_nic( 2201 tulip_softc_t * const sc) 2202{ 2203 strcpy(sc->tulip_boardid, "ACCTON "); 2204 switch (sc->tulip_chipid) { 2205 case TULIP_21140A: 2206 strcat(sc->tulip_boardid, "EN1207 "); 2207 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw) 2208 sc->tulip_boardsw = &tulip_21140_accton_boardsw; 2209 break; 2210 case TULIP_21140: 2211 strcat(sc->tulip_boardid, "EN1207TX "); 2212 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw) 2213 sc->tulip_boardsw = &tulip_21140_eb_boardsw; 2214 break; 2215 case TULIP_21040: 2216 strcat(sc->tulip_boardid, "EN1203 "); 2217 sc->tulip_boardsw = &tulip_21040_boardsw; 2218 break; 2219 case TULIP_21041: 2220 strcat(sc->tulip_boardid, "EN1203 "); 2221 sc->tulip_boardsw = &tulip_21041_boardsw; 2222 break; 2223 default: 2224 sc->tulip_boardsw = &tulip_2114x_isv_boardsw; 2225 break; 2226 } 2227} 2228 2229static void 2230tulip_identify_asante_nic( 2231 tulip_softc_t * const sc) 2232{ 2233 strcpy(sc->tulip_boardid, "Asante "); 2234 if ((sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) 2235 && sc->tulip_boardsw != &tulip_2114x_isv_boardsw) { 2236 tulip_media_info_t *mi = sc->tulip_mediainfo; 2237 int idx; 2238 /* 2239 * The Asante Fast Ethernet doesn't always ship with a valid 2240 * new format SROM. So if isn't in the new format, we cheat 2241 * set it up as if we had. 2242 */ 2243 2244 sc->tulip_gpinit = TULIP_GP_ASANTE_PINS; 2245 sc->tulip_gpdata = 0; 2246 2247 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ASANTE_PINS|TULIP_GP_PINSET); 2248 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ASANTE_PHYRESET); 2249 DELAY(100); 2250 TULIP_CSR_WRITE(sc, csr_gp, 0); 2251 2252 mi->mi_type = TULIP_MEDIAINFO_MII; 2253 mi->mi_gpr_length = 0; 2254 mi->mi_gpr_offset = 0; 2255 mi->mi_reset_length = 0; 2256 mi->mi_reset_offset = 0;; 2257 2258 mi->mi_phyaddr = TULIP_MII_NOPHY; 2259 for (idx = 20; idx > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx--) { 2260 DELAY(10000); 2261 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, 0); 2262 } 2263 if (mi->mi_phyaddr == TULIP_MII_NOPHY) { 2264 printf("%s: can't find phy 0\n", sc->tulip_xname); 2265 return; 2266 } 2267 2268 sc->tulip_features |= TULIP_HAVE_MII; 2269 mi->mi_capabilities = PHYSTS_10BASET|PHYSTS_10BASET_FD|PHYSTS_100BASETX|PHYSTS_100BASETX_FD; 2270 mi->mi_advertisement = PHYSTS_10BASET|PHYSTS_10BASET_FD|PHYSTS_100BASETX|PHYSTS_100BASETX_FD; 2271 mi->mi_full_duplex = PHYSTS_10BASET_FD|PHYSTS_100BASETX_FD; 2272 mi->mi_tx_threshold = PHYSTS_10BASET|PHYSTS_10BASET_FD; 2273 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD); 2274 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX); 2275 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4); 2276 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD); 2277 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET); 2278 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) | 2279 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH); 2280 2281 sc->tulip_boardsw = &tulip_2114x_isv_boardsw; 2282 } 2283} 2284 2285static void 2286tulip_identify_compex_nic( 2287 tulip_softc_t * const sc) 2288{ 2289 strcpy(sc->tulip_boardid, "COMPEX "); 2290 if (sc->tulip_chipid == TULIP_21140A) { 2291 int root_unit; 2292 tulip_softc_t *root_sc = NULL; 2293 2294 strcat(sc->tulip_boardid, "400TX/PCI "); 2295 /* 2296 * All 4 chips on these boards share an interrupt. This code 2297 * copied from tulip_read_macaddr. 2298 */ 2299 sc->tulip_features |= TULIP_HAVE_SHAREDINTR; 2300 for (root_unit = sc->tulip_unit - 1; root_unit >= 0; root_unit--) { 2301 root_sc = tulips[root_unit]; 2302 if (root_sc == NULL 2303 || !(root_sc->tulip_features & TULIP_HAVE_SLAVEDINTR)) 2304 break; 2305 root_sc = NULL; 2306 } 2307 if (root_sc != NULL 2308 && root_sc->tulip_chipid == sc->tulip_chipid 2309 && root_sc->tulip_pci_busno == sc->tulip_pci_busno) { 2310 sc->tulip_features |= TULIP_HAVE_SLAVEDINTR; 2311 sc->tulip_slaves = root_sc->tulip_slaves; 2312 root_sc->tulip_slaves = sc; 2313 } else if(sc->tulip_features & TULIP_HAVE_SLAVEDINTR) { 2314 printf("\nCannot find master device for %s interrupts", 2315 sc->tulip_xname); 2316 } 2317 } else { 2318 strcat(sc->tulip_boardid, "unknown "); 2319 } 2320 /* sc->tulip_boardsw = &tulip_21140_eb_boardsw; */ 2321 return; 2322} 2323 2324static int 2325tulip_srom_decode( 2326 tulip_softc_t * const sc) 2327{ 2328 unsigned idx1, idx2, idx3; 2329 2330 const tulip_srom_header_t *shp = (const tulip_srom_header_t *) &sc->tulip_rombuf[0]; 2331 const tulip_srom_adapter_info_t *saip = (const tulip_srom_adapter_info_t *) (shp + 1); 2332 tulip_srom_media_t srom_media; 2333 tulip_media_info_t *mi = sc->tulip_mediainfo; 2334 const u_int8_t *dp; 2335 u_int32_t leaf_offset, blocks, data; 2336 2337 for (idx1 = 0; idx1 < shp->sh_adapter_count; idx1++, saip++) { 2338 if (shp->sh_adapter_count == 1) 2339 break; 2340 if (saip->sai_device == sc->tulip_pci_devno) 2341 break; 2342 } 2343 /* 2344 * Didn't find the right media block for this card. 2345 */ 2346 if (idx1 == shp->sh_adapter_count) 2347 return 0; 2348 2349 /* 2350 * Save the hardware address. 2351 */ 2352 bcopy(shp->sh_ieee802_address, sc->tulip_enaddr, 6); 2353 /* 2354 * If this is a multiple port card, add the adapter index to the last 2355 * byte of the hardware address. (if it isn't multiport, adding 0 2356 * won't hurt. 2357 */ 2358 sc->tulip_enaddr[5] += idx1; 2359 2360 leaf_offset = saip->sai_leaf_offset_lowbyte 2361 + saip->sai_leaf_offset_highbyte * 256; 2362 dp = sc->tulip_rombuf + leaf_offset; 2363 2364 sc->tulip_conntype = (tulip_srom_connection_t) (dp[0] + dp[1] * 256); dp += 2; 2365 2366 for (idx2 = 0;; idx2++) { 2367 if (tulip_srom_conninfo[idx2].sc_type == sc->tulip_conntype 2368 || tulip_srom_conninfo[idx2].sc_type == TULIP_SROM_CONNTYPE_NOT_USED) 2369 break; 2370 } 2371 sc->tulip_connidx = idx2; 2372 2373 if (sc->tulip_chipid == TULIP_21041) { 2374 blocks = *dp++; 2375 for (idx2 = 0; idx2 < blocks; idx2++) { 2376 tulip_media_t media; 2377 data = *dp++; 2378 srom_media = (tulip_srom_media_t) (data & 0x3F); 2379 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) { 2380 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media) 2381 break; 2382 } 2383 media = tulip_srom_mediums[idx3].sm_type; 2384 if (media != TULIP_MEDIA_UNKNOWN) { 2385 if (data & TULIP_SROM_21041_EXTENDED) { 2386 mi->mi_type = TULIP_MEDIAINFO_SIA; 2387 sc->tulip_mediums[media] = mi; 2388 mi->mi_sia_connectivity = dp[0] + dp[1] * 256; 2389 mi->mi_sia_tx_rx = dp[2] + dp[3] * 256; 2390 mi->mi_sia_general = dp[4] + dp[5] * 256; 2391 mi++; 2392 } else { 2393 switch (media) { 2394 case TULIP_MEDIA_BNC: { 2395 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, BNC); 2396 mi++; 2397 break; 2398 } 2399 case TULIP_MEDIA_AUI: { 2400 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, AUI); 2401 mi++; 2402 break; 2403 } 2404 case TULIP_MEDIA_10BASET: { 2405 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET); 2406 mi++; 2407 break; 2408 } 2409 case TULIP_MEDIA_10BASET_FD: { 2410 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET_FD); 2411 mi++; 2412 break; 2413 } 2414 default: { 2415 break; 2416 } 2417 } 2418 } 2419 } 2420 if (data & TULIP_SROM_21041_EXTENDED) 2421 dp += 6; 2422 } 2423#ifdef notdef 2424 if (blocks == 0) { 2425 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, BNC); mi++; 2426 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, AUI); mi++; 2427 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET); mi++; 2428 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET_FD); mi++; 2429 } 2430#endif 2431 } else { 2432 unsigned length, type; 2433 tulip_media_t gp_media = TULIP_MEDIA_UNKNOWN; 2434 if (sc->tulip_features & TULIP_HAVE_GPR) 2435 sc->tulip_gpinit = *dp++; 2436 blocks = *dp++; 2437 for (idx2 = 0; idx2 < blocks; idx2++) { 2438 const u_int8_t *ep; 2439 if ((*dp & 0x80) == 0) { 2440 length = 4; 2441 type = 0; 2442 } else { 2443 length = (*dp++ & 0x7f) - 1; 2444 type = *dp++ & 0x3f; 2445 } 2446 ep = dp + length; 2447 switch (type & 0x3f) { 2448 case 0: { /* 21140[A] GPR block */ 2449 tulip_media_t media; 2450 srom_media = (tulip_srom_media_t)(dp[0] & 0x3f); 2451 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) { 2452 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media) 2453 break; 2454 } 2455 media = tulip_srom_mediums[idx3].sm_type; 2456 if (media == TULIP_MEDIA_UNKNOWN) 2457 break; 2458 mi->mi_type = TULIP_MEDIAINFO_GPR; 2459 sc->tulip_mediums[media] = mi; 2460 mi->mi_gpdata = dp[1]; 2461 if (media > gp_media && !TULIP_IS_MEDIA_FD(media)) { 2462 sc->tulip_gpdata = mi->mi_gpdata; 2463 gp_media = media; 2464 } 2465 data = dp[2] + dp[3] * 256; 2466 mi->mi_cmdmode = TULIP_SROM_2114X_CMDBITS(data); 2467 if (data & TULIP_SROM_2114X_NOINDICATOR) { 2468 mi->mi_actmask = 0; 2469 } else { 2470#if 0 2471 mi->mi_default = (data & TULIP_SROM_2114X_DEFAULT) != 0; 2472#endif 2473 mi->mi_actmask = TULIP_SROM_2114X_BITPOS(data); 2474 mi->mi_actdata = (data & TULIP_SROM_2114X_POLARITY) ? 0 : mi->mi_actmask; 2475 } 2476 mi++; 2477 break; 2478 } 2479 case 1: { /* 21140[A] MII block */ 2480 const unsigned phyno = *dp++; 2481 mi->mi_type = TULIP_MEDIAINFO_MII; 2482 mi->mi_gpr_length = *dp++; 2483 mi->mi_gpr_offset = dp - sc->tulip_rombuf; 2484 dp += mi->mi_gpr_length; 2485 mi->mi_reset_length = *dp++; 2486 mi->mi_reset_offset = dp - sc->tulip_rombuf; 2487 dp += mi->mi_reset_length; 2488 2489 /* 2490 * Before we probe for a PHY, use the GPR information 2491 * to select it. If we don't, it may be inaccessible. 2492 */ 2493 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_gpinit|TULIP_GP_PINSET); 2494 for (idx3 = 0; idx3 < mi->mi_reset_length; idx3++) { 2495 DELAY(10); 2496 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_reset_offset + idx3]); 2497 } 2498 sc->tulip_phyaddr = mi->mi_phyaddr; 2499 for (idx3 = 0; idx3 < mi->mi_gpr_length; idx3++) { 2500 DELAY(10); 2501 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_gpr_offset + idx3]); 2502 } 2503 2504 /* 2505 * At least write something! 2506 */ 2507 if (mi->mi_reset_length == 0 && mi->mi_gpr_length == 0) 2508 TULIP_CSR_WRITE(sc, csr_gp, 0); 2509 2510 mi->mi_phyaddr = TULIP_MII_NOPHY; 2511 for (idx3 = 20; idx3 > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx3--) { 2512 DELAY(10000); 2513 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, phyno); 2514 } 2515 if (mi->mi_phyaddr == TULIP_MII_NOPHY) { 2516#if defined(TULIP_DEBUG) 2517 printf("%s: can't find phy %d\n", 2518 sc->tulip_xname, phyno); 2519#endif 2520 break; 2521 } 2522 sc->tulip_features |= TULIP_HAVE_MII; 2523 mi->mi_capabilities = dp[0] + dp[1] * 256; dp += 2; 2524 mi->mi_advertisement = dp[0] + dp[1] * 256; dp += 2; 2525 mi->mi_full_duplex = dp[0] + dp[1] * 256; dp += 2; 2526 mi->mi_tx_threshold = dp[0] + dp[1] * 256; dp += 2; 2527 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD); 2528 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX); 2529 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4); 2530 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD); 2531 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET); 2532 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) | 2533 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH); 2534 mi++; 2535 break; 2536 } 2537 case 2: { /* 2114[23] SIA block */ 2538 tulip_media_t media; 2539 srom_media = (tulip_srom_media_t)(dp[0] & 0x3f); 2540 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) { 2541 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media) 2542 break; 2543 } 2544 media = tulip_srom_mediums[idx3].sm_type; 2545 if (media == TULIP_MEDIA_UNKNOWN) 2546 break; 2547 mi->mi_type = TULIP_MEDIAINFO_SIA; 2548 sc->tulip_mediums[media] = mi; 2549 if (dp[0] & 0x40) { 2550 mi->mi_sia_connectivity = dp[1] + dp[2] * 256; 2551 mi->mi_sia_tx_rx = dp[3] + dp[4] * 256; 2552 mi->mi_sia_general = dp[5] + dp[6] * 256; 2553 dp += 6; 2554 } else { 2555 switch (media) { 2556 case TULIP_MEDIA_BNC: { 2557 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, BNC); 2558 break; 2559 } 2560 case TULIP_MEDIA_AUI: { 2561 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, AUI); 2562 break; 2563 } 2564 case TULIP_MEDIA_10BASET: { 2565 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, 10BASET); 2566 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL; 2567 break; 2568 } 2569 case TULIP_MEDIA_10BASET_FD: { 2570 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, 10BASET_FD); 2571 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL; 2572 break; 2573 } 2574 default: { 2575 goto bad_media; 2576 } 2577 } 2578 } 2579 mi->mi_sia_gp_control = (dp[1] + dp[2] * 256) << 16; 2580 mi->mi_sia_gp_data = (dp[3] + dp[4] * 256) << 16; 2581 mi++; 2582 bad_media: 2583 break; 2584 } 2585 case 3: { /* 2114[23] MII PHY block */ 2586 const unsigned phyno = *dp++; 2587 const u_int8_t *dp0; 2588 mi->mi_type = TULIP_MEDIAINFO_MII; 2589 mi->mi_gpr_length = *dp++; 2590 mi->mi_gpr_offset = dp - sc->tulip_rombuf; 2591 dp += 2 * mi->mi_gpr_length; 2592 mi->mi_reset_length = *dp++; 2593 mi->mi_reset_offset = dp - sc->tulip_rombuf; 2594 dp += 2 * mi->mi_reset_length; 2595 2596 dp0 = &sc->tulip_rombuf[mi->mi_reset_offset]; 2597 for (idx3 = 0; idx3 < mi->mi_reset_length; idx3++, dp0 += 2) { 2598 DELAY(10); 2599 TULIP_CSR_WRITE(sc, csr_sia_general, (dp0[0] + 256 * dp0[1]) << 16); 2600 } 2601 sc->tulip_phyaddr = mi->mi_phyaddr; 2602 dp0 = &sc->tulip_rombuf[mi->mi_gpr_offset]; 2603 for (idx3 = 0; idx3 < mi->mi_gpr_length; idx3++, dp0 += 2) { 2604 DELAY(10); 2605 TULIP_CSR_WRITE(sc, csr_sia_general, (dp0[0] + 256 * dp0[1]) << 16); 2606 } 2607 2608 if (mi->mi_reset_length == 0 && mi->mi_gpr_length == 0) 2609 TULIP_CSR_WRITE(sc, csr_sia_general, 0); 2610 2611 mi->mi_phyaddr = TULIP_MII_NOPHY; 2612 for (idx3 = 20; idx3 > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx3--) { 2613 DELAY(10000); 2614 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, phyno); 2615 } 2616 if (mi->mi_phyaddr == TULIP_MII_NOPHY) { 2617#if defined(TULIP_DEBUG) 2618 printf("%s: can't find phy %d\n", 2619 sc->tulip_xname, phyno); 2620#endif 2621 break; 2622 } 2623 sc->tulip_features |= TULIP_HAVE_MII; 2624 mi->mi_capabilities = dp[0] + dp[1] * 256; dp += 2; 2625 mi->mi_advertisement = dp[0] + dp[1] * 256; dp += 2; 2626 mi->mi_full_duplex = dp[0] + dp[1] * 256; dp += 2; 2627 mi->mi_tx_threshold = dp[0] + dp[1] * 256; dp += 2; 2628 mi->mi_mii_interrupt = dp[0] + dp[1] * 256; dp += 2; 2629 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD); 2630 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX); 2631 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4); 2632 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD); 2633 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET); 2634 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) | 2635 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH); 2636 mi++; 2637 break; 2638 } 2639 case 4: { /* 21143 SYM block */ 2640 tulip_media_t media; 2641 srom_media = (tulip_srom_media_t) dp[0]; 2642 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) { 2643 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media) 2644 break; 2645 } 2646 media = tulip_srom_mediums[idx3].sm_type; 2647 if (media == TULIP_MEDIA_UNKNOWN) 2648 break; 2649 mi->mi_type = TULIP_MEDIAINFO_SYM; 2650 sc->tulip_mediums[media] = mi; 2651 mi->mi_gpcontrol = (dp[1] + dp[2] * 256) << 16; 2652 mi->mi_gpdata = (dp[3] + dp[4] * 256) << 16; 2653 data = dp[5] + dp[6] * 256; 2654 mi->mi_cmdmode = TULIP_SROM_2114X_CMDBITS(data); 2655 if (data & TULIP_SROM_2114X_NOINDICATOR) { 2656 mi->mi_actmask = 0; 2657 } else { 2658 mi->mi_default = (data & TULIP_SROM_2114X_DEFAULT) != 0; 2659 mi->mi_actmask = TULIP_SROM_2114X_BITPOS(data); 2660 mi->mi_actdata = (data & TULIP_SROM_2114X_POLARITY) ? 0 : mi->mi_actmask; 2661 } 2662 if (TULIP_IS_MEDIA_TP(media)) 2663 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL; 2664 mi++; 2665 break; 2666 } 2667#if 0 2668 case 5: { /* 21143 Reset block */ 2669 mi->mi_type = TULIP_MEDIAINFO_RESET; 2670 mi->mi_reset_length = *dp++; 2671 mi->mi_reset_offset = dp - sc->tulip_rombuf; 2672 dp += 2 * mi->mi_reset_length; 2673 mi++; 2674 break; 2675 } 2676#endif 2677 default: { 2678 } 2679 } 2680 dp = ep; 2681 } 2682 } 2683 return mi - sc->tulip_mediainfo; 2684} 2685 2686static const struct { 2687 void (*vendor_identify_nic)(tulip_softc_t * const sc); 2688 unsigned char vendor_oui[3]; 2689} tulip_vendors[] = { 2690 { tulip_identify_dec_nic, { 0x08, 0x00, 0x2B } }, 2691 { tulip_identify_dec_nic, { 0x00, 0x00, 0xF8 } }, 2692 { tulip_identify_smc_nic, { 0x00, 0x00, 0xC0 } }, 2693 { tulip_identify_smc_nic, { 0x00, 0xE0, 0x29 } }, 2694 { tulip_identify_znyx_nic, { 0x00, 0xC0, 0x95 } }, 2695 { tulip_identify_cogent_nic, { 0x00, 0x00, 0x92 } }, 2696 { tulip_identify_asante_nic, { 0x00, 0x00, 0x94 } }, 2697 { tulip_identify_cogent_nic, { 0x00, 0x00, 0xD1 } }, 2698 { tulip_identify_accton_nic, { 0x00, 0x00, 0xE8 } }, 2699 { tulip_identify_compex_nic, { 0x00, 0x80, 0x48 } }, 2700 { NULL } 2701}; 2702 2703/* 2704 * This deals with the vagaries of the address roms and the 2705 * brain-deadness that various vendors commit in using them. 2706 */ 2707static int 2708tulip_read_macaddr( 2709 tulip_softc_t * const sc) 2710{ 2711 unsigned cksum, rom_cksum, idx; 2712 u_int32_t csr; 2713 unsigned char tmpbuf[8]; 2714 static const u_char testpat[] = { 0xFF, 0, 0x55, 0xAA, 0xFF, 0, 0x55, 0xAA }; 2715 2716 sc->tulip_connidx = TULIP_SROM_LASTCONNIDX; 2717 2718 if (sc->tulip_chipid == TULIP_21040) { 2719 TULIP_CSR_WRITE(sc, csr_enetrom, 1); 2720 for (idx = 0; idx < sizeof(sc->tulip_rombuf); idx++) { 2721 int cnt = 0; 2722 while (((csr = TULIP_CSR_READ(sc, csr_enetrom)) & 0x80000000L) && cnt < 10000) 2723 cnt++; 2724 sc->tulip_rombuf[idx] = csr & 0xFF; 2725 } 2726 sc->tulip_boardsw = &tulip_21040_boardsw; 2727 } else { 2728 if (sc->tulip_chipid == TULIP_21041) { 2729 /* 2730 * Thankfully all 21041's act the same. 2731 */ 2732 sc->tulip_boardsw = &tulip_21041_boardsw; 2733 } else { 2734 /* 2735 * Assume all 21140 board are compatible with the 2736 * DEC 10/100 evaluation board. Not really valid but 2737 * it's the best we can do until every one switches to 2738 * the new SROM format. 2739 */ 2740 2741 sc->tulip_boardsw = &tulip_21140_eb_boardsw; 2742 } 2743 tulip_srom_read(sc); 2744 if (tulip_srom_crcok(sc->tulip_rombuf)) { 2745 /* 2746 * SROM CRC is valid therefore it must be in the 2747 * new format. 2748 */ 2749 sc->tulip_features |= TULIP_HAVE_ISVSROM|TULIP_HAVE_OKSROM; 2750 } else if (sc->tulip_rombuf[126] == 0xff && sc->tulip_rombuf[127] == 0xFF) { 2751 /* 2752 * No checksum is present. See if the SROM id checks out; 2753 * the first 18 bytes should be 0 followed by a 1 followed 2754 * by the number of adapters (which we don't deal with yet). 2755 */ 2756 for (idx = 0; idx < 18; idx++) { 2757 if (sc->tulip_rombuf[idx] != 0) 2758 break; 2759 } 2760 if (idx == 18 && sc->tulip_rombuf[18] == 1 && sc->tulip_rombuf[19] != 0) 2761 sc->tulip_features |= TULIP_HAVE_ISVSROM; 2762 } else if (sc->tulip_chipid >= TULIP_21142) { 2763 sc->tulip_features |= TULIP_HAVE_ISVSROM; 2764 sc->tulip_boardsw = &tulip_2114x_isv_boardsw; 2765 } 2766 if ((sc->tulip_features & TULIP_HAVE_ISVSROM) && tulip_srom_decode(sc)) { 2767 if (sc->tulip_chipid != TULIP_21041) 2768 sc->tulip_boardsw = &tulip_2114x_isv_boardsw; 2769 2770 /* 2771 * If the SROM specifies more than one adapter, tag this as a 2772 * BASE rom. 2773 */ 2774 if (sc->tulip_rombuf[19] > 1) 2775 sc->tulip_features |= TULIP_HAVE_BASEROM; 2776 if (sc->tulip_boardsw == NULL) 2777 return -6; 2778 goto check_oui; 2779 } 2780 } 2781 2782 2783 if (bcmp(&sc->tulip_rombuf[0], &sc->tulip_rombuf[16], 8) != 0) { 2784 /* 2785 * Some folks don't use the standard ethernet rom format 2786 * but instead just put the address in the first 6 bytes 2787 * of the rom and let the rest be all 0xffs. (Can we say 2788 * ZNYX?) (well sometimes they put in a checksum so we'll 2789 * start at 8). 2790 */ 2791 for (idx = 8; idx < 32; idx++) { 2792 if (sc->tulip_rombuf[idx] != 0xFF) 2793 return -4; 2794 } 2795 /* 2796 * Make sure the address is not multicast or locally assigned 2797 * that the OUI is not 00-00-00. 2798 */ 2799 if ((sc->tulip_rombuf[0] & 3) != 0) 2800 return -4; 2801 if (sc->tulip_rombuf[0] == 0 && sc->tulip_rombuf[1] == 0 2802 && sc->tulip_rombuf[2] == 0) 2803 return -4; 2804 bcopy(sc->tulip_rombuf, sc->tulip_enaddr, 6); 2805 sc->tulip_features |= TULIP_HAVE_OKROM; 2806 goto check_oui; 2807 } else { 2808 /* 2809 * A number of makers of multiport boards (ZNYX and Cogent) 2810 * only put on one address ROM on their 21040 boards. So 2811 * if the ROM is all zeros (or all 0xFFs), look at the 2812 * previous configured boards (as long as they are on the same 2813 * PCI bus and the bus number is non-zero) until we find the 2814 * master board with address ROM. We then use its address ROM 2815 * as the base for this board. (we add our relative board 2816 * to the last byte of its address). 2817 */ 2818 for (idx = 0; idx < sizeof(sc->tulip_rombuf); idx++) { 2819 if (sc->tulip_rombuf[idx] != 0 && sc->tulip_rombuf[idx] != 0xFF) 2820 break; 2821 } 2822 if (idx == sizeof(sc->tulip_rombuf)) { 2823 int root_unit; 2824 tulip_softc_t *root_sc = NULL; 2825 for (root_unit = sc->tulip_unit - 1; root_unit >= 0; root_unit--) { 2826 root_sc = tulips[root_unit]; 2827 if (root_sc == NULL || (root_sc->tulip_features & (TULIP_HAVE_OKROM|TULIP_HAVE_SLAVEDROM)) == TULIP_HAVE_OKROM) 2828 break; 2829 root_sc = NULL; 2830 } 2831 if (root_sc != NULL && (root_sc->tulip_features & TULIP_HAVE_BASEROM) 2832 && root_sc->tulip_chipid == sc->tulip_chipid 2833 && root_sc->tulip_pci_busno == sc->tulip_pci_busno) { 2834 sc->tulip_features |= TULIP_HAVE_SLAVEDROM; 2835 sc->tulip_boardsw = root_sc->tulip_boardsw; 2836 strcpy(sc->tulip_boardid, root_sc->tulip_boardid); 2837 if (sc->tulip_boardsw->bd_type == TULIP_21140_ISV) { 2838 bcopy(root_sc->tulip_rombuf, sc->tulip_rombuf, 2839 sizeof(sc->tulip_rombuf)); 2840 if (!tulip_srom_decode(sc)) 2841 return -5; 2842 } else { 2843 bcopy(root_sc->tulip_enaddr, sc->tulip_enaddr, 6); 2844 sc->tulip_enaddr[5] += sc->tulip_unit - root_sc->tulip_unit; 2845 } 2846 /* 2847 * Now for a truly disgusting kludge: all 4 21040s on 2848 * the ZX314 share the same INTA line so the mapping 2849 * setup by the BIOS on the PCI bridge is worthless. 2850 * Rather than reprogramming the value in the config 2851 * register, we will handle this internally. 2852 */ 2853 if (root_sc->tulip_features & TULIP_HAVE_SHAREDINTR) { 2854 sc->tulip_slaves = root_sc->tulip_slaves; 2855 root_sc->tulip_slaves = sc; 2856 sc->tulip_features |= TULIP_HAVE_SLAVEDINTR; 2857 } 2858 return 0; 2859 } 2860 } 2861 } 2862 2863 /* 2864 * This is the standard DEC address ROM test. 2865 */ 2866 2867 if (bcmp(&sc->tulip_rombuf[24], testpat, 8) != 0) 2868 return -3; 2869 2870 tmpbuf[0] = sc->tulip_rombuf[15]; tmpbuf[1] = sc->tulip_rombuf[14]; 2871 tmpbuf[2] = sc->tulip_rombuf[13]; tmpbuf[3] = sc->tulip_rombuf[12]; 2872 tmpbuf[4] = sc->tulip_rombuf[11]; tmpbuf[5] = sc->tulip_rombuf[10]; 2873 tmpbuf[6] = sc->tulip_rombuf[9]; tmpbuf[7] = sc->tulip_rombuf[8]; 2874 if (bcmp(&sc->tulip_rombuf[0], tmpbuf, 8) != 0) 2875 return -2; 2876 2877 bcopy(sc->tulip_rombuf, sc->tulip_enaddr, 6); 2878 2879 cksum = *(u_int16_t *) &sc->tulip_enaddr[0]; 2880 cksum *= 2; 2881 if (cksum > 65535) cksum -= 65535; 2882 cksum += *(u_int16_t *) &sc->tulip_enaddr[2]; 2883 if (cksum > 65535) cksum -= 65535; 2884 cksum *= 2; 2885 if (cksum > 65535) cksum -= 65535; 2886 cksum += *(u_int16_t *) &sc->tulip_enaddr[4]; 2887 if (cksum >= 65535) cksum -= 65535; 2888 2889 rom_cksum = *(u_int16_t *) &sc->tulip_rombuf[6]; 2890 2891 if (cksum != rom_cksum) 2892 return -1; 2893 2894 check_oui: 2895 /* 2896 * Check for various boards based on OUI. Did I say braindead? 2897 */ 2898 for (idx = 0; tulip_vendors[idx].vendor_identify_nic != NULL; idx++) { 2899 if (bcmp(sc->tulip_enaddr, tulip_vendors[idx].vendor_oui, 3) == 0) { 2900 (*tulip_vendors[idx].vendor_identify_nic)(sc); 2901 break; 2902 } 2903 } 2904 2905 sc->tulip_features |= TULIP_HAVE_OKROM; 2906 return 0; 2907} 2908 2909static void 2910tulip_ifmedia_add( 2911 tulip_softc_t * const sc) 2912{ 2913 tulip_media_t media; 2914 int medias = 0; 2915 2916 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) { 2917 if (sc->tulip_mediums[media] != NULL) { 2918 ifmedia_add(&sc->tulip_ifmedia, tulip_media_to_ifmedia[media], 2919 0, 0); 2920 medias++; 2921 } 2922 } 2923 if (medias == 0) { 2924 sc->tulip_features |= TULIP_HAVE_NOMEDIA; 2925 ifmedia_add(&sc->tulip_ifmedia, IFM_ETHER | IFM_NONE, 0, 0); 2926 ifmedia_set(&sc->tulip_ifmedia, IFM_ETHER | IFM_NONE); 2927 } else if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) { 2928 ifmedia_add(&sc->tulip_ifmedia, IFM_ETHER | IFM_AUTO, 0, 0); 2929 ifmedia_set(&sc->tulip_ifmedia, IFM_ETHER | IFM_AUTO); 2930 } else { 2931 ifmedia_set(&sc->tulip_ifmedia, tulip_media_to_ifmedia[sc->tulip_media]); 2932 sc->tulip_flags |= TULIP_PRINTMEDIA; 2933 tulip_linkup(sc, sc->tulip_media); 2934 } 2935} 2936 2937static int 2938tulip_ifmedia_change( 2939 struct ifnet * const ifp) 2940{ 2941 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc; 2942 2943 sc->tulip_flags |= TULIP_NEEDRESET; 2944 sc->tulip_probe_state = TULIP_PROBE_INACTIVE; 2945 sc->tulip_media = TULIP_MEDIA_UNKNOWN; 2946 if (IFM_SUBTYPE(sc->tulip_ifmedia.ifm_media) != IFM_AUTO) { 2947 tulip_media_t media; 2948 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) { 2949 if (sc->tulip_mediums[media] != NULL 2950 && sc->tulip_ifmedia.ifm_media == tulip_media_to_ifmedia[media]) { 2951 sc->tulip_flags |= TULIP_PRINTMEDIA; 2952 sc->tulip_flags &= ~TULIP_DIDNWAY; 2953 tulip_linkup(sc, media); 2954 return 0; 2955 } 2956 } 2957 } 2958 sc->tulip_flags &= ~(TULIP_TXPROBE_ACTIVE|TULIP_WANTRXACT); 2959 tulip_reset(sc); 2960 tulip_init(sc); 2961 return 0; 2962} 2963 2964/* 2965 * Media status callback 2966 */ 2967static void 2968tulip_ifmedia_status( 2969 struct ifnet * const ifp, 2970 struct ifmediareq *req) 2971{ 2972 tulip_softc_t *sc = (tulip_softc_t *)ifp->if_softc; 2973 2974 if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) 2975 return; 2976 2977 req->ifm_status = IFM_AVALID; 2978 if (sc->tulip_flags & TULIP_LINKUP) 2979 req->ifm_status |= IFM_ACTIVE; 2980 2981 req->ifm_active = tulip_media_to_ifmedia[sc->tulip_media]; 2982} 2983 2984static void 2985tulip_addr_filter( 2986 tulip_softc_t * const sc) 2987{ 2988 struct ifmultiaddr *ifma; 2989 u_char *addrp; 2990 int multicnt; 2991 2992 sc->tulip_flags &= ~(TULIP_WANTHASHPERFECT|TULIP_WANTHASHONLY|TULIP_ALLMULTI); 2993 sc->tulip_flags |= TULIP_WANTSETUP|TULIP_WANTTXSTART; 2994 sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN; 2995 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED; 2996#if defined(IFF_ALLMULTI) 2997 if (sc->tulip_if.if_flags & IFF_ALLMULTI) 2998 sc->tulip_flags |= TULIP_ALLMULTI ; 2999#endif 3000 3001 multicnt = 0; 3002 TAILQ_FOREACH(ifma, &sc->tulip_if.if_multiaddrs, ifma_link) { 3003 3004 if (ifma->ifma_addr->sa_family == AF_LINK) 3005 multicnt++; 3006 } 3007 3008 sc->tulip_if.if_start = tulip_ifstart; /* so the setup packet gets queued */ 3009 if (multicnt > 14) { 3010 u_int32_t *sp = sc->tulip_setupdata; 3011 unsigned hash; 3012 /* 3013 * Some early passes of the 21140 have broken implementations of 3014 * hash-perfect mode. When we get too many multicasts for perfect 3015 * filtering with these chips, we need to switch into hash-only 3016 * mode (this is better than all-multicast on network with lots 3017 * of multicast traffic). 3018 */ 3019 if (sc->tulip_features & TULIP_HAVE_BROKEN_HASH) 3020 sc->tulip_flags |= TULIP_WANTHASHONLY; 3021 else 3022 sc->tulip_flags |= TULIP_WANTHASHPERFECT; 3023 /* 3024 * If we have more than 14 multicasts, we have 3025 * go into hash perfect mode (512 bit multicast 3026 * hash and one perfect hardware). 3027 */ 3028 bzero(sc->tulip_setupdata, sizeof(sc->tulip_setupdata)); 3029 3030 TAILQ_FOREACH(ifma, &sc->tulip_if.if_multiaddrs, ifma_link) { 3031 3032 if (ifma->ifma_addr->sa_family != AF_LINK) 3033 continue; 3034 3035 hash = tulip_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr)); 3036#if BYTE_ORDER == BIG_ENDIAN 3037 sp[hash >> 4] |= bswap32(1 << (hash & 0xF)); 3038#else 3039 sp[hash >> 4] |= 1 << (hash & 0xF); 3040#endif 3041 } 3042 /* 3043 * No reason to use a hash if we are going to be 3044 * receiving every multicast. 3045 */ 3046 if ((sc->tulip_flags & TULIP_ALLMULTI) == 0) { 3047 hash = tulip_mchash(sc->tulip_if.if_broadcastaddr); 3048#if BYTE_ORDER == BIG_ENDIAN 3049 sp[hash >> 4] |= bswap32(1 << (hash & 0xF)); 3050#else 3051 sp[hash >> 4] |= 1 << (hash & 0xF); 3052#endif 3053 if (sc->tulip_flags & TULIP_WANTHASHONLY) { 3054 hash = tulip_mchash(sc->tulip_enaddr); 3055#if BYTE_ORDER == BIG_ENDIAN 3056 sp[hash >> 4] |= bswap32(1 << (hash & 0xF)); 3057#else 3058 sp[hash >> 4] |= 1 << (hash & 0xF); 3059#endif 3060 } else { 3061#if BYTE_ORDER == BIG_ENDIAN 3062 sp[39] = ((u_int16_t *) sc->tulip_enaddr)[0] << 16; 3063 sp[40] = ((u_int16_t *) sc->tulip_enaddr)[1] << 16; 3064 sp[41] = ((u_int16_t *) sc->tulip_enaddr)[2] << 16; 3065#else 3066 sp[39] = ((u_int16_t *) sc->tulip_enaddr)[0]; 3067 sp[40] = ((u_int16_t *) sc->tulip_enaddr)[1]; 3068 sp[41] = ((u_int16_t *) sc->tulip_enaddr)[2]; 3069#endif 3070 } 3071 } 3072 } 3073 if ((sc->tulip_flags & (TULIP_WANTHASHPERFECT|TULIP_WANTHASHONLY)) == 0) { 3074 u_int32_t *sp = sc->tulip_setupdata; 3075 int idx = 0; 3076 if ((sc->tulip_flags & TULIP_ALLMULTI) == 0) { 3077 /* 3078 * Else can get perfect filtering for 16 addresses. 3079 */ 3080 TAILQ_FOREACH(ifma, &sc->tulip_if.if_multiaddrs, ifma_link) { 3081 if (ifma->ifma_addr->sa_family != AF_LINK) 3082 continue; 3083 addrp = LLADDR((struct sockaddr_dl *)ifma->ifma_addr); 3084#if BYTE_ORDER == BIG_ENDIAN 3085 *sp++ = ((u_int16_t *) addrp)[0] << 16; 3086 *sp++ = ((u_int16_t *) addrp)[1] << 16; 3087 *sp++ = ((u_int16_t *) addrp)[2] << 16; 3088#else 3089 *sp++ = ((u_int16_t *) addrp)[0]; 3090 *sp++ = ((u_int16_t *) addrp)[1]; 3091 *sp++ = ((u_int16_t *) addrp)[2]; 3092#endif 3093 idx++; 3094 } 3095 /* 3096 * Add the broadcast address. 3097 */ 3098 idx++; 3099#if BYTE_ORDER == BIG_ENDIAN 3100 *sp++ = 0xFFFF << 16; 3101 *sp++ = 0xFFFF << 16; 3102 *sp++ = 0xFFFF << 16; 3103#else 3104 *sp++ = 0xFFFF; 3105 *sp++ = 0xFFFF; 3106 *sp++ = 0xFFFF; 3107#endif 3108 } 3109 /* 3110 * Pad the rest with our hardware address 3111 */ 3112 for (; idx < 16; idx++) { 3113#if BYTE_ORDER == BIG_ENDIAN 3114 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[0] << 16; 3115 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[1] << 16; 3116 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[2] << 16; 3117#else 3118 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[0]; 3119 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[1]; 3120 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[2]; 3121#endif 3122 } 3123 } 3124#if defined(IFF_ALLMULTI) 3125 if (sc->tulip_flags & TULIP_ALLMULTI) 3126 sc->tulip_if.if_flags |= IFF_ALLMULTI; 3127#endif 3128} 3129 3130static void 3131tulip_reset( 3132 tulip_softc_t * const sc) 3133{ 3134 tulip_ringinfo_t *ri; 3135 tulip_desc_t *di; 3136 u_int32_t inreset = (sc->tulip_flags & TULIP_INRESET); 3137 3138 /* 3139 * Brilliant. Simply brilliant. When switching modes/speeds 3140 * on a 2114*, you need to set the appriopriate MII/PCS/SCL/PS 3141 * bits in CSR6 and then do a software reset to get the 21140 3142 * to properly reset its internal pathways to the right places. 3143 * Grrrr. 3144 */ 3145 if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0 3146 && sc->tulip_boardsw->bd_media_preset != NULL) 3147 (*sc->tulip_boardsw->bd_media_preset)(sc); 3148 3149 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET); 3150 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at 3151 33MHz that comes to two microseconds but wait a 3152 bit longer anyways) */ 3153 3154 if (!inreset) { 3155 sc->tulip_flags |= TULIP_INRESET; 3156 sc->tulip_flags &= ~(TULIP_NEEDRESET|TULIP_RXBUFSLOW); 3157 sc->tulip_if.if_flags &= ~IFF_OACTIVE; 3158 sc->tulip_if.if_start = tulip_ifstart; 3159 } 3160 3161#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX) 3162 TULIP_CSR_WRITE(sc, csr_txlist, sc->tulip_txdescmap->dm_segs[0].ds_addr); 3163#else 3164 TULIP_CSR_WRITE(sc, csr_txlist, TULIP_KVATOPHYS(sc, &sc->tulip_txinfo.ri_first[0])); 3165#endif 3166#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX) 3167 TULIP_CSR_WRITE(sc, csr_rxlist, sc->tulip_rxdescmap->dm_segs[0].ds_addr); 3168#else 3169 TULIP_CSR_WRITE(sc, csr_rxlist, TULIP_KVATOPHYS(sc, &sc->tulip_rxinfo.ri_first[0])); 3170#endif 3171 TULIP_CSR_WRITE(sc, csr_busmode, 3172 (1 << (3 /*pci_max_burst_len*/ + 8)) 3173 |TULIP_BUSMODE_CACHE_ALIGN8 3174 |TULIP_BUSMODE_READMULTIPLE 3175 |(BYTE_ORDER != LITTLE_ENDIAN ? 3176 TULIP_BUSMODE_DESC_BIGENDIAN : 0)); 3177 3178 sc->tulip_txtimer = 0; 3179 sc->tulip_txq.ifq_maxlen = TULIP_TXDESCS; 3180 /* 3181 * Free all the mbufs that were on the transmit ring. 3182 */ 3183 for (;;) { 3184#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX) 3185 bus_dmamap_t map; 3186#endif 3187 struct mbuf *m; 3188 _IF_DEQUEUE(&sc->tulip_txq, m); 3189 if (m == NULL) 3190 break; 3191#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX) 3192 map = M_GETCTX(m, bus_dmamap_t); 3193 bus_dmamap_unload(sc->tulip_dmatag, map); 3194 sc->tulip_txmaps[sc->tulip_txmaps_free++] = map; 3195#endif 3196 m_freem(m); 3197 } 3198 3199 ri = &sc->tulip_txinfo; 3200 ri->ri_nextin = ri->ri_nextout = ri->ri_first; 3201 ri->ri_free = ri->ri_max; 3202 for (di = ri->ri_first; di < ri->ri_last; di++) 3203 di->d_status = 0; 3204#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX) 3205 bus_dmamap_sync(sc->tulip_dmatag, sc->tulip_txdescmap, 3206 0, sc->tulip_txdescmap->dm_mapsize, 3207 BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE); 3208#endif 3209 3210 /* 3211 * We need to collect all the mbufs were on the 3212 * receive ring before we reinit it either to put 3213 * them back on or to know if we have to allocate 3214 * more. 3215 */ 3216 ri = &sc->tulip_rxinfo; 3217 ri->ri_nextin = ri->ri_nextout = ri->ri_first; 3218 ri->ri_free = ri->ri_max; 3219 for (di = ri->ri_first; di < ri->ri_last; di++) { 3220 di->d_status = 0; 3221 di->d_length1 = 0; di->d_addr1 = 0; 3222 di->d_length2 = 0; di->d_addr2 = 0; 3223 } 3224#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX) 3225 bus_dmamap_sync(sc->tulip_dmatag, sc->tulip_rxdescmap, 3226 0, sc->tulip_rxdescmap->dm_mapsize, 3227 BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE); 3228#endif 3229 for (;;) { 3230#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX) 3231 bus_dmamap_t map; 3232#endif 3233 struct mbuf *m; 3234 _IF_DEQUEUE(&sc->tulip_rxq, m); 3235 if (m == NULL) 3236 break; 3237#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX) 3238 map = M_GETCTX(m, bus_dmamap_t); 3239 bus_dmamap_unload(sc->tulip_dmatag, map); 3240 sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map; 3241#endif 3242 m_freem(m); 3243 } 3244 3245 /* 3246 * If tulip_reset is being called recurisvely, exit quickly knowing 3247 * that when the outer tulip_reset returns all the right stuff will 3248 * have happened. 3249 */ 3250 if (inreset) 3251 return; 3252 3253 sc->tulip_intrmask |= TULIP_STS_NORMALINTR|TULIP_STS_RXINTR|TULIP_STS_TXINTR 3254 |TULIP_STS_ABNRMLINTR|TULIP_STS_SYSERROR|TULIP_STS_TXSTOPPED 3255 |TULIP_STS_TXUNDERFLOW|TULIP_STS_TXBABBLE 3256 |TULIP_STS_RXSTOPPED; 3257 3258 if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0) 3259 (*sc->tulip_boardsw->bd_media_select)(sc); 3260#if defined(TULIP_DEBUG) 3261 if ((sc->tulip_flags & TULIP_NEEDRESET) == TULIP_NEEDRESET) 3262 printf("%s: tulip_reset: additional reset needed?!?\n", 3263 sc->tulip_xname); 3264#endif 3265 if (bootverbose) 3266 tulip_media_print(sc); 3267 if (sc->tulip_features & TULIP_HAVE_DUALSENSE) 3268 TULIP_CSR_WRITE(sc, csr_sia_status, TULIP_CSR_READ(sc, csr_sia_status)); 3269 3270 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_WANTSETUP|TULIP_INRESET 3271 |TULIP_RXACT); 3272 tulip_addr_filter(sc); 3273} 3274 3275 3276static void 3277tulip_ifinit( 3278 void * sc) 3279{ 3280 tulip_init((tulip_softc_t *)sc); 3281} 3282 3283static void 3284tulip_init( 3285 tulip_softc_t * const sc) 3286{ 3287 if (sc->tulip_if.if_flags & IFF_UP) { 3288 if ((sc->tulip_if.if_flags & IFF_RUNNING) == 0) { 3289 /* initialize the media */ 3290 tulip_reset(sc); 3291 } 3292 sc->tulip_if.if_flags |= IFF_RUNNING; 3293 if (sc->tulip_if.if_flags & IFF_PROMISC) { 3294 sc->tulip_flags |= TULIP_PROMISC; 3295 sc->tulip_cmdmode |= TULIP_CMD_PROMISCUOUS; 3296 sc->tulip_intrmask |= TULIP_STS_TXINTR; 3297 } else { 3298 sc->tulip_flags &= ~TULIP_PROMISC; 3299 sc->tulip_cmdmode &= ~TULIP_CMD_PROMISCUOUS; 3300 if (sc->tulip_flags & TULIP_ALLMULTI) { 3301 sc->tulip_cmdmode |= TULIP_CMD_ALLMULTI; 3302 } else { 3303 sc->tulip_cmdmode &= ~TULIP_CMD_ALLMULTI; 3304 } 3305 } 3306 sc->tulip_cmdmode |= TULIP_CMD_TXRUN; 3307 if ((sc->tulip_flags & (TULIP_TXPROBE_ACTIVE|TULIP_WANTSETUP)) == 0) { 3308 tulip_rx_intr(sc); 3309 sc->tulip_cmdmode |= TULIP_CMD_RXRUN; 3310 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED; 3311 } else { 3312 sc->tulip_if.if_flags |= IFF_OACTIVE; 3313 sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN; 3314 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED; 3315 } 3316 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask); 3317 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode); 3318 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP) 3319 tulip_txput_setup(sc); 3320 } else { 3321 sc->tulip_if.if_flags &= ~IFF_RUNNING; 3322 tulip_reset(sc); 3323 } 3324} 3325 3326static void 3327tulip_rx_intr( 3328 tulip_softc_t * const sc) 3329{ 3330 TULIP_PERFSTART(rxintr) 3331 tulip_ringinfo_t * const ri = &sc->tulip_rxinfo; 3332 struct ifnet * const ifp = &sc->tulip_if; 3333 int fillok = 1; 3334#if defined(TULIP_DEBUG) 3335 int cnt = 0; 3336#endif 3337 3338 for (;;) { 3339 TULIP_PERFSTART(rxget) 3340 tulip_desc_t *eop = ri->ri_nextin; 3341 int total_len = 0, last_offset = 0; 3342 struct mbuf *ms = NULL, *me = NULL; 3343 int accept = 0; 3344#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX) 3345 bus_dmamap_t map; 3346 int error; 3347#endif 3348 3349 if (fillok && sc->tulip_rxq.ifq_len < TULIP_RXQ_TARGET) 3350 goto queue_mbuf; 3351 3352#if defined(TULIP_DEBUG) 3353 if (cnt == ri->ri_max) 3354 break; 3355#endif 3356 /* 3357 * If the TULIP has no descriptors, there can't be any receive 3358 * descriptors to process. 3359 */ 3360 if (eop == ri->ri_nextout) 3361 break; 3362 3363 /* 3364 * 90% of the packets will fit in one descriptor. So we optimize 3365 * for that case. 3366 */ 3367 TULIP_RXDESC_POSTSYNC(sc, eop, sizeof(*eop)); 3368 if ((((volatile tulip_desc_t *) eop)->d_status & (TULIP_DSTS_OWNER|TULIP_DSTS_RxFIRSTDESC|TULIP_DSTS_RxLASTDESC)) == (TULIP_DSTS_RxFIRSTDESC|TULIP_DSTS_RxLASTDESC)) { 3369 _IF_DEQUEUE(&sc->tulip_rxq, ms); 3370 me = ms; 3371 } else { 3372 /* 3373 * If still owned by the TULIP, don't touch it. 3374 */ 3375 if (((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER) 3376 break; 3377 3378 /* 3379 * It is possible (though improbable unless the BIG_PACKET support 3380 * is enabled or MCLBYTES < 1518) for a received packet to cross 3381 * more than one receive descriptor. 3382 */ 3383 while ((((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_RxLASTDESC) == 0) { 3384 if (++eop == ri->ri_last) 3385 eop = ri->ri_first; 3386 TULIP_RXDESC_POSTSYNC(sc, eop, sizeof(*eop)); 3387 if (eop == ri->ri_nextout || ((((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER))) { 3388#if defined(TULIP_DEBUG) 3389 sc->tulip_dbg.dbg_rxintrs++; 3390 sc->tulip_dbg.dbg_rxpktsperintr[cnt]++; 3391#endif 3392 TULIP_PERFEND(rxget); 3393 TULIP_PERFEND(rxintr); 3394 return; 3395 } 3396 total_len++; 3397 } 3398 3399 /* 3400 * Dequeue the first buffer for the start of the packet. Hopefully 3401 * this will be the only one we need to dequeue. However, if the 3402 * packet consumed multiple descriptors, then we need to dequeue 3403 * those buffers and chain to the starting mbuf. All buffers but 3404 * the last buffer have the same length so we can set that now. 3405 * (we add to last_offset instead of multiplying since we normally 3406 * won't go into the loop and thereby saving ourselves from 3407 * doing a multiplication by 0 in the normal case). 3408 */ 3409 _IF_DEQUEUE(&sc->tulip_rxq, ms); 3410 for (me = ms; total_len > 0; total_len--) { 3411#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX) 3412 map = M_GETCTX(me, bus_dmamap_t); 3413 TULIP_RXMAP_POSTSYNC(sc, map); 3414 bus_dmamap_unload(sc->tulip_dmatag, map); 3415 sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map; 3416#if defined(DIAGNOSTIC) 3417 M_SETCTX(me, NULL); 3418#endif 3419#endif /* TULIP_BUS_DMA */ 3420 me->m_len = TULIP_RX_BUFLEN; 3421 last_offset += TULIP_RX_BUFLEN; 3422 _IF_DEQUEUE(&sc->tulip_rxq, me->m_next); 3423 me = me->m_next; 3424 } 3425 } 3426 3427 /* 3428 * Now get the size of received packet (minus the CRC). 3429 */ 3430 total_len = ((eop->d_status >> 16) & 0x7FFF) - 4; 3431 if ((sc->tulip_flags & TULIP_RXIGNORE) == 0 3432 && ((eop->d_status & TULIP_DSTS_ERRSUM) == 0 3433#ifdef BIG_PACKET 3434 || (total_len <= sc->tulip_if.if_mtu + sizeof(struct ether_header) && 3435 (eop->d_status & (TULIP_DSTS_RxBADLENGTH|TULIP_DSTS_RxRUNT| 3436 TULIP_DSTS_RxCOLLSEEN|TULIP_DSTS_RxBADCRC| 3437 TULIP_DSTS_RxOVERFLOW)) == 0) 3438#endif 3439 )) { 3440 me->m_len = total_len - last_offset; 3441 3442#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX) 3443 map = M_GETCTX(me, bus_dmamap_t); 3444 bus_dmamap_sync(sc->tulip_dmatag, map, 0, me->m_len, 3445 BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE); 3446 bus_dmamap_unload(sc->tulip_dmatag, map); 3447 sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map; 3448#if defined(DIAGNOSTIC) 3449 M_SETCTX(me, NULL); 3450#endif 3451#endif /* TULIP_BUS_DMA */ 3452 3453#ifndef __FreeBSD__ 3454 if (sc->tulip_if.if_bpf != NULL) { 3455 if (me == ms) 3456 bpf_tap(&sc->tulip_if, mtod(ms, caddr_t), total_len); 3457 else 3458 bpf_mtap(&sc->tulip_if, ms); 3459 } 3460#endif 3461 sc->tulip_flags |= TULIP_RXACT; 3462 accept = 1; 3463 } else { 3464 ifp->if_ierrors++; 3465 if (eop->d_status & (TULIP_DSTS_RxBADLENGTH|TULIP_DSTS_RxOVERFLOW|TULIP_DSTS_RxWATCHDOG)) { 3466 sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++; 3467 } else { 3468#if defined(TULIP_VERBOSE) 3469 const char *error = NULL; 3470#endif 3471 if (eop->d_status & TULIP_DSTS_RxTOOLONG) { 3472 sc->tulip_dot3stats.dot3StatsFrameTooLongs++; 3473#if defined(TULIP_VERBOSE) 3474 error = "frame too long"; 3475#endif 3476 } 3477 if (eop->d_status & TULIP_DSTS_RxBADCRC) { 3478 if (eop->d_status & TULIP_DSTS_RxDRBBLBIT) { 3479 sc->tulip_dot3stats.dot3StatsAlignmentErrors++; 3480#if defined(TULIP_VERBOSE) 3481 error = "alignment error"; 3482#endif 3483 } else { 3484 sc->tulip_dot3stats.dot3StatsFCSErrors++; 3485#if defined(TULIP_VERBOSE) 3486 error = "bad crc"; 3487#endif 3488 } 3489 } 3490#if defined(TULIP_VERBOSE) 3491 if (error != NULL && (sc->tulip_flags & TULIP_NOMESSAGES) == 0) { 3492 printf("%s: receive: %6D: %s\n", 3493 sc->tulip_xname, 3494 mtod(ms, u_char *) + 6, ":", 3495 error); 3496 sc->tulip_flags |= TULIP_NOMESSAGES; 3497 } 3498#endif 3499 } 3500 3501#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX) 3502 map = M_GETCTX(me, bus_dmamap_t); 3503 bus_dmamap_unload(sc->tulip_dmatag, map); 3504 sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map; 3505#if defined(DIAGNOSTIC) 3506 M_SETCTX(me, NULL); 3507#endif 3508#endif /* TULIP_BUS_DMA */ 3509 } 3510#if defined(TULIP_DEBUG) 3511 cnt++; 3512#endif 3513 ifp->if_ipackets++; 3514 if (++eop == ri->ri_last) 3515 eop = ri->ri_first; 3516 ri->ri_nextin = eop; 3517 queue_mbuf: 3518 /* 3519 * Either we are priming the TULIP with mbufs (m == NULL) 3520 * or we are about to accept an mbuf for the upper layers 3521 * so we need to allocate an mbuf to replace it. If we 3522 * can't replace it, send up it anyways. This may cause 3523 * us to drop packets in the future but that's better than 3524 * being caught in livelock. 3525 * 3526 * Note that if this packet crossed multiple descriptors 3527 * we don't even try to reallocate all the mbufs here. 3528 * Instead we rely on the test of the beginning of 3529 * the loop to refill for the extra consumed mbufs. 3530 */ 3531 if (accept || ms == NULL) { 3532 struct mbuf *m0; 3533 MGETHDR(m0, M_DONTWAIT, MT_DATA); 3534 if (m0 != NULL) { 3535#if defined(TULIP_COPY_RXDATA) 3536 if (!accept || total_len >= (MHLEN - 2)) { 3537#endif 3538 MCLGET(m0, M_DONTWAIT); 3539 if ((m0->m_flags & M_EXT) == 0) { 3540 m_freem(m0); 3541 m0 = NULL; 3542 } 3543#if defined(TULIP_COPY_RXDATA) 3544 } 3545#endif 3546 } 3547 if (accept 3548#if defined(TULIP_COPY_RXDATA) 3549 && m0 != NULL 3550#endif 3551 ) { 3552#if !defined(TULIP_COPY_RXDATA) 3553 ms->m_pkthdr.len = total_len; 3554 ms->m_pkthdr.rcvif = ifp; 3555 (*ifp->if_input)(ifp, ms); 3556#else 3557#ifdef BIG_PACKET 3558#error BIG_PACKET is incompatible with TULIP_COPY_RXDATA 3559#endif 3560 m0->m_data += 2; /* align data after header */ 3561 m_copydata(ms, 0, total_len, mtod(m0, caddr_t)); 3562 m0->m_len = m0->m_pkthdr.len = total_len; 3563 m0->m_pkthdr.rcvif = ifp; 3564 (*ifp->if_input)(ifp, m0); 3565 m0 = ms; 3566#endif /* ! TULIP_COPY_RXDATA */ 3567 } 3568 ms = m0; 3569 } 3570 if (ms == NULL) { 3571 /* 3572 * Couldn't allocate a new buffer. Don't bother 3573 * trying to replenish the receive queue. 3574 */ 3575 fillok = 0; 3576 sc->tulip_flags |= TULIP_RXBUFSLOW; 3577#if defined(TULIP_DEBUG) 3578 sc->tulip_dbg.dbg_rxlowbufs++; 3579#endif 3580 TULIP_PERFEND(rxget); 3581 continue; 3582 } 3583 /* 3584 * Now give the buffer(s) to the TULIP and save in our 3585 * receive queue. 3586 */ 3587 do { 3588 tulip_desc_t * const nextout = ri->ri_nextout; 3589#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX) 3590 if (sc->tulip_rxmaps_free > 0) { 3591 map = sc->tulip_rxmaps[--sc->tulip_rxmaps_free]; 3592 } else { 3593 m_freem(ms); 3594 sc->tulip_flags |= TULIP_RXBUFSLOW; 3595#if defined(TULIP_DEBUG) 3596 sc->tulip_dbg.dbg_rxlowbufs++; 3597#endif 3598 break; 3599 } 3600 M_SETCTX(ms, map); 3601 error = bus_dmamap_load(sc->tulip_dmatag, map, mtod(ms, void *), 3602 TULIP_RX_BUFLEN, NULL, BUS_DMA_NOWAIT); 3603 if (error) { 3604 printf("%s: unable to load rx map, " 3605 "error = %d\n", sc->tulip_xname, error); 3606 panic("tulip_rx_intr"); /* XXX */ 3607 } 3608 nextout->d_addr1 = map->dm_segs[0].ds_addr; 3609 nextout->d_length1 = map->dm_segs[0].ds_len; 3610 if (map->dm_nsegs == 2) { 3611 nextout->d_addr2 = map->dm_segs[1].ds_addr; 3612 nextout->d_length2 = map->dm_segs[1].ds_len; 3613 } else { 3614 nextout->d_addr2 = 0; 3615 nextout->d_length2 = 0; 3616 } 3617 TULIP_RXDESC_POSTSYNC(sc, nextout, sizeof(*nextout)); 3618#else /* TULIP_BUS_DMA */ 3619 nextout->d_addr1 = TULIP_KVATOPHYS(sc, mtod(ms, caddr_t)); 3620 nextout->d_length1 = TULIP_RX_BUFLEN; 3621#endif /* TULIP_BUS_DMA */ 3622 nextout->d_status = TULIP_DSTS_OWNER; 3623 TULIP_RXDESC_POSTSYNC(sc, nextout, sizeof(u_int32_t)); 3624 if (++ri->ri_nextout == ri->ri_last) 3625 ri->ri_nextout = ri->ri_first; 3626 me = ms->m_next; 3627 ms->m_next = NULL; 3628 _IF_ENQUEUE(&sc->tulip_rxq, ms); 3629 } while ((ms = me) != NULL); 3630 3631 if (sc->tulip_rxq.ifq_len >= TULIP_RXQ_TARGET) 3632 sc->tulip_flags &= ~TULIP_RXBUFSLOW; 3633 TULIP_PERFEND(rxget); 3634 } 3635 3636#if defined(TULIP_DEBUG) 3637 sc->tulip_dbg.dbg_rxintrs++; 3638 sc->tulip_dbg.dbg_rxpktsperintr[cnt]++; 3639#endif 3640 TULIP_PERFEND(rxintr); 3641} 3642 3643static int 3644tulip_tx_intr( 3645 tulip_softc_t * const sc) 3646{ 3647 TULIP_PERFSTART(txintr) 3648 tulip_ringinfo_t * const ri = &sc->tulip_txinfo; 3649 struct mbuf *m; 3650 int xmits = 0; 3651 int descs = 0; 3652 3653 while (ri->ri_free < ri->ri_max) { 3654 u_int32_t d_flag; 3655 3656 TULIP_TXDESC_POSTSYNC(sc, ri->ri_nextin, sizeof(*ri->ri_nextin)); 3657 if (((volatile tulip_desc_t *) ri->ri_nextin)->d_status & TULIP_DSTS_OWNER) 3658 break; 3659 3660 ri->ri_free++; 3661 descs++; 3662 d_flag = ri->ri_nextin->d_flag; 3663 if (d_flag & TULIP_DFLAG_TxLASTSEG) { 3664 if (d_flag & TULIP_DFLAG_TxSETUPPKT) { 3665 /* 3666 * We've just finished processing a setup packet. 3667 * Mark that we finished it. If there's not 3668 * another pending, startup the TULIP receiver. 3669 * Make sure we ack the RXSTOPPED so we won't get 3670 * an abormal interrupt indication. 3671 */ 3672 TULIP_TXMAP_POSTSYNC(sc, sc->tulip_setupmap); 3673 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_HASHONLY); 3674 if (ri->ri_nextin->d_flag & TULIP_DFLAG_TxINVRSFILT) 3675 sc->tulip_flags |= TULIP_HASHONLY; 3676 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == 0) { 3677 tulip_rx_intr(sc); 3678 sc->tulip_cmdmode |= TULIP_CMD_RXRUN; 3679 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED; 3680 TULIP_CSR_WRITE(sc, csr_status, TULIP_STS_RXSTOPPED); 3681 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask); 3682 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode); 3683 } 3684 } else { 3685 const u_int32_t d_status = ri->ri_nextin->d_status; 3686 _IF_DEQUEUE(&sc->tulip_txq, m); 3687 if (m != NULL) { 3688#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX) 3689 bus_dmamap_t map = M_GETCTX(m, bus_dmamap_t); 3690 TULIP_TXMAP_POSTSYNC(sc, map); 3691 sc->tulip_txmaps[sc->tulip_txmaps_free++] = map; 3692#endif /* TULIP_BUS_DMA */ 3693 m_freem(m); 3694#if defined(TULIP_DEBUG) 3695 } else { 3696 printf("%s: tx_intr: failed to dequeue mbuf?!?\n", 3697 sc->tulip_xname); 3698#endif 3699 } 3700 if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) { 3701 tulip_mediapoll_event_t event = TULIP_MEDIAPOLL_TXPROBE_OK; 3702 if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxEXCCOLL)) { 3703#if defined(TULIP_DEBUG) 3704 if (d_status & TULIP_DSTS_TxNOCARR) 3705 sc->tulip_dbg.dbg_txprobe_nocarr++; 3706 if (d_status & TULIP_DSTS_TxEXCCOLL) 3707 sc->tulip_dbg.dbg_txprobe_exccoll++; 3708#endif 3709 event = TULIP_MEDIAPOLL_TXPROBE_FAILED; 3710 } 3711 (*sc->tulip_boardsw->bd_media_poll)(sc, event); 3712 /* 3713 * Escape from the loop before media poll has reset the TULIP! 3714 */ 3715 break; 3716 } else { 3717 xmits++; 3718 if (d_status & TULIP_DSTS_ERRSUM) { 3719 sc->tulip_if.if_oerrors++; 3720 if (d_status & TULIP_DSTS_TxEXCCOLL) 3721 sc->tulip_dot3stats.dot3StatsExcessiveCollisions++; 3722 if (d_status & TULIP_DSTS_TxLATECOLL) 3723 sc->tulip_dot3stats.dot3StatsLateCollisions++; 3724 if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxCARRLOSS)) 3725 sc->tulip_dot3stats.dot3StatsCarrierSenseErrors++; 3726 if (d_status & (TULIP_DSTS_TxUNDERFLOW|TULIP_DSTS_TxBABBLE)) 3727 sc->tulip_dot3stats.dot3StatsInternalMacTransmitErrors++; 3728 if (d_status & TULIP_DSTS_TxUNDERFLOW) 3729 sc->tulip_dot3stats.dot3StatsInternalTransmitUnderflows++; 3730 if (d_status & TULIP_DSTS_TxBABBLE) 3731 sc->tulip_dot3stats.dot3StatsInternalTransmitBabbles++; 3732 } else { 3733 u_int32_t collisions = 3734 (d_status & TULIP_DSTS_TxCOLLMASK) 3735 >> TULIP_DSTS_V_TxCOLLCNT; 3736 sc->tulip_if.if_collisions += collisions; 3737 if (collisions == 1) 3738 sc->tulip_dot3stats.dot3StatsSingleCollisionFrames++; 3739 else if (collisions > 1) 3740 sc->tulip_dot3stats.dot3StatsMultipleCollisionFrames++; 3741 else if (d_status & TULIP_DSTS_TxDEFERRED) 3742 sc->tulip_dot3stats.dot3StatsDeferredTransmissions++; 3743 /* 3744 * SQE is only valid for 10baseT/BNC/AUI when not 3745 * running in full-duplex. In order to speed up the 3746 * test, the corresponding bit in tulip_flags needs to 3747 * set as well to get us to count SQE Test Errors. 3748 */ 3749 if (d_status & TULIP_DSTS_TxNOHRTBT & sc->tulip_flags) 3750 sc->tulip_dot3stats.dot3StatsSQETestErrors++; 3751 } 3752 } 3753 } 3754 } 3755 3756 if (++ri->ri_nextin == ri->ri_last) 3757 ri->ri_nextin = ri->ri_first; 3758 3759 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0) 3760 sc->tulip_if.if_flags &= ~IFF_OACTIVE; 3761 } 3762 /* 3763 * If nothing left to transmit, disable the timer. 3764 * Else if progress, reset the timer back to 2 ticks. 3765 */ 3766 if (ri->ri_free == ri->ri_max || (sc->tulip_flags & TULIP_TXPROBE_ACTIVE)) 3767 sc->tulip_txtimer = 0; 3768 else if (xmits > 0) 3769 sc->tulip_txtimer = TULIP_TXTIMER; 3770 sc->tulip_if.if_opackets += xmits; 3771 TULIP_PERFEND(txintr); 3772 return descs; 3773} 3774 3775static void 3776tulip_print_abnormal_interrupt( 3777 tulip_softc_t * const sc, 3778 u_int32_t csr) 3779{ 3780 const char * const *msgp = tulip_status_bits; 3781 const char *sep; 3782 u_int32_t mask; 3783 const char thrsh[] = "72|128\0\0\0" "96|256\0\0\0" "128|512\0\0" "160|1024"; 3784 3785 csr &= (1 << (sizeof(tulip_status_bits)/sizeof(tulip_status_bits[0]))) - 1; 3786 printf("%s: abnormal interrupt:", sc->tulip_xname); 3787 for (sep = " ", mask = 1; mask <= csr; mask <<= 1, msgp++) { 3788 if ((csr & mask) && *msgp != NULL) { 3789 printf("%s%s", sep, *msgp); 3790 if (mask == TULIP_STS_TXUNDERFLOW && (sc->tulip_flags & TULIP_NEWTXTHRESH)) { 3791 sc->tulip_flags &= ~TULIP_NEWTXTHRESH; 3792 if (sc->tulip_cmdmode & TULIP_CMD_STOREFWD) { 3793 printf(" (switching to store-and-forward mode)"); 3794 } else { 3795 printf(" (raising TX threshold to %s)", 3796 &thrsh[9 * ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) >> 14)]); 3797 } 3798 } 3799 sep = ", "; 3800 } 3801 } 3802 printf("\n"); 3803} 3804 3805static void 3806tulip_intr_handler( 3807 tulip_softc_t * const sc, 3808 int *progress_p) 3809{ 3810 TULIP_PERFSTART(intr) 3811 u_int32_t csr; 3812 3813 while ((csr = TULIP_CSR_READ(sc, csr_status)) & sc->tulip_intrmask) { 3814 *progress_p = 1; 3815 TULIP_CSR_WRITE(sc, csr_status, csr); 3816 3817 if (csr & TULIP_STS_SYSERROR) { 3818 sc->tulip_last_system_error = (csr & TULIP_STS_ERRORMASK) >> TULIP_STS_ERR_SHIFT; 3819 if (sc->tulip_flags & TULIP_NOMESSAGES) { 3820 sc->tulip_flags |= TULIP_SYSTEMERROR; 3821 } else { 3822 printf("%s: system error: %s\n", 3823 sc->tulip_xname, 3824 tulip_system_errors[sc->tulip_last_system_error]); 3825 } 3826 sc->tulip_flags |= TULIP_NEEDRESET; 3827 sc->tulip_system_errors++; 3828 break; 3829 } 3830 if (csr & (TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL) & sc->tulip_intrmask) { 3831#if defined(TULIP_DEBUG) 3832 sc->tulip_dbg.dbg_link_intrs++; 3833#endif 3834 if (sc->tulip_boardsw->bd_media_poll != NULL) { 3835 (*sc->tulip_boardsw->bd_media_poll)(sc, csr & TULIP_STS_LINKFAIL 3836 ? TULIP_MEDIAPOLL_LINKFAIL 3837 : TULIP_MEDIAPOLL_LINKPASS); 3838 csr &= ~TULIP_STS_ABNRMLINTR; 3839 } 3840 tulip_media_print(sc); 3841 } 3842 if (csr & (TULIP_STS_RXINTR|TULIP_STS_RXNOBUF)) { 3843 u_int32_t misses = TULIP_CSR_READ(sc, csr_missed_frames); 3844 if (csr & TULIP_STS_RXNOBUF) 3845 sc->tulip_dot3stats.dot3StatsMissedFrames += misses & 0xFFFF; 3846 /* 3847 * Pass 2.[012] of the 21140A-A[CDE] may hang and/or corrupt data 3848 * on receive overflows. 3849 */ 3850 if ((misses & 0x0FFE0000) && (sc->tulip_features & TULIP_HAVE_RXBADOVRFLW)) { 3851 sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++; 3852 /* 3853 * Stop the receiver process and spin until it's stopped. 3854 * Tell rx_intr to drop the packets it dequeues. 3855 */ 3856 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode & ~TULIP_CMD_RXRUN); 3857 while ((TULIP_CSR_READ(sc, csr_status) & TULIP_STS_RXSTOPPED) == 0) 3858 ; 3859 TULIP_CSR_WRITE(sc, csr_status, TULIP_STS_RXSTOPPED); 3860 sc->tulip_flags |= TULIP_RXIGNORE; 3861 } 3862 tulip_rx_intr(sc); 3863 if (sc->tulip_flags & TULIP_RXIGNORE) { 3864 /* 3865 * Restart the receiver. 3866 */ 3867 sc->tulip_flags &= ~TULIP_RXIGNORE; 3868 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode); 3869 } 3870 } 3871 if (csr & TULIP_STS_ABNRMLINTR) { 3872 u_int32_t tmp = csr & sc->tulip_intrmask 3873 & ~(TULIP_STS_NORMALINTR|TULIP_STS_ABNRMLINTR); 3874 if (csr & TULIP_STS_TXUNDERFLOW) { 3875 if ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) != TULIP_CMD_THRSHLD160) { 3876 sc->tulip_cmdmode += TULIP_CMD_THRSHLD96; 3877 sc->tulip_flags |= TULIP_NEWTXTHRESH; 3878 } else if (sc->tulip_features & TULIP_HAVE_STOREFWD) { 3879 sc->tulip_cmdmode |= TULIP_CMD_STOREFWD; 3880 sc->tulip_flags |= TULIP_NEWTXTHRESH; 3881 } 3882 } 3883 if (sc->tulip_flags & TULIP_NOMESSAGES) { 3884 sc->tulip_statusbits |= tmp; 3885 } else { 3886 tulip_print_abnormal_interrupt(sc, tmp); 3887 sc->tulip_flags |= TULIP_NOMESSAGES; 3888 } 3889 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode); 3890 } 3891 if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_TXPROBE_ACTIVE|TULIP_DOINGSETUP|TULIP_PROMISC)) { 3892 tulip_tx_intr(sc); 3893 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0) 3894 tulip_ifstart(&sc->tulip_if); 3895 } 3896 } 3897 if (sc->tulip_flags & TULIP_NEEDRESET) { 3898 tulip_reset(sc); 3899 tulip_init(sc); 3900 } 3901 TULIP_PERFEND(intr); 3902} 3903 3904#if defined(TULIP_USE_SOFTINTR) 3905/* 3906 * This is an experimental idea to alleviate problems due to interrupt 3907 * livelock. What is interrupt livelock? It's when you spend all your 3908 * time servicing device interrupts and never drop below device ipl 3909 * to do "useful" work. 3910 * 3911 * So what we do here is see if the device needs service and if so, 3912 * disable interrupts (dismiss the interrupt), place it in a list of devices 3913 * needing service, and issue a network software interrupt. 3914 * 3915 * When our network software interrupt routine gets called, we simply 3916 * walk done the list of devices that we have created and deal with them 3917 * at splnet/splsoftnet. 3918 * 3919 */ 3920static void 3921tulip_hardintr_handler( 3922 tulip_softc_t * const sc, 3923 int *progress_p) 3924{ 3925 if (TULIP_CSR_READ(sc, csr_status) & (TULIP_STS_NORMALINTR|TULIP_STS_ABNRMLINTR) == 0) 3926 return; 3927 *progress_p = 1; 3928 /* 3929 * disable interrupts 3930 */ 3931 TULIP_CSR_WRITE(sc, csr_intr, 0); 3932 /* 3933 * mark it as needing a software interrupt 3934 */ 3935 tulip_softintr_mask |= (1U << sc->tulip_unit); 3936} 3937 3938static void 3939tulip_softintr( 3940 void) 3941{ 3942 u_int32_t softintr_mask, mask; 3943 int progress = 0; 3944 int unit; 3945 int s; 3946 3947 /* 3948 * Copy mask to local copy and reset global one to 0. 3949 */ 3950 s = splimp(); 3951 softintr_mask = tulip_softintr_mask; 3952 tulip_softintr_mask = 0; 3953 splx(s); 3954 3955 /* 3956 * Optimize for the single unit case. 3957 */ 3958 if (tulip_softintr_max_unit == 0) { 3959 if (softintr_mask & 1) { 3960 tulip_softc_t * const sc = tulips[0]; 3961 /* 3962 * Handle the "interrupt" and then reenable interrupts 3963 */ 3964 softintr_mask = 0; 3965 tulip_intr_handler(sc, &progress); 3966 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask); 3967 } 3968 return; 3969 } 3970 3971 /* 3972 * Handle all "queued" interrupts in a round robin fashion. 3973 * This is done so as not to favor a particular interface. 3974 */ 3975 unit = tulip_softintr_last_unit; 3976 mask = (1U << unit); 3977 while (softintr_mask != 0) { 3978 if (tulip_softintr_max_unit == unit) { 3979 unit = 0; mask = 1; 3980 } else { 3981 unit += 1; mask <<= 1; 3982 } 3983 if (softintr_mask & mask) { 3984 tulip_softc_t * const sc = tulips[unit]; 3985 /* 3986 * Handle the "interrupt" and then reenable interrupts 3987 */ 3988 softintr_mask ^= mask; 3989 tulip_intr_handler(sc, &progress); 3990 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask); 3991 } 3992 } 3993 3994 /* 3995 * Save where we ending up. 3996 */ 3997 tulip_softintr_last_unit = unit; 3998} 3999#endif /* TULIP_USE_SOFTINTR */ 4000 4001static void 4002tulip_intr_shared( 4003 void *arg) 4004{ 4005 tulip_softc_t * sc = arg; 4006 int progress = 0; 4007 4008 for (; sc != NULL; sc = sc->tulip_slaves) { 4009#if defined(TULIP_DEBUG) 4010 sc->tulip_dbg.dbg_intrs++; 4011#endif 4012#if defined(TULIP_USE_SOFTINTR) 4013 tulip_hardintr_handler(sc, &progress); 4014#else 4015 tulip_intr_handler(sc, &progress); 4016#endif 4017 } 4018#if defined(TULIP_USE_SOFTINTR) 4019 if (progress) 4020 schednetisr(NETISR_DE); 4021#endif 4022} 4023 4024static void 4025tulip_intr_normal( 4026 void *arg) 4027{ 4028 tulip_softc_t * sc = (tulip_softc_t *) arg; 4029 int progress = 0; 4030 4031#if defined(TULIP_DEBUG) 4032 sc->tulip_dbg.dbg_intrs++; 4033#endif 4034#if defined(TULIP_USE_SOFTINTR) 4035 tulip_hardintr_handler(sc, &progress); 4036 if (progress) 4037 schednetisr(NETISR_DE); 4038#else 4039 tulip_intr_handler(sc, &progress); 4040#endif 4041} 4042 4043static struct mbuf * 4044tulip_mbuf_compress( 4045 struct mbuf *m) 4046{ 4047 struct mbuf *m0; 4048#if MCLBYTES >= ETHERMTU + 18 && !defined(BIG_PACKET) 4049 MGETHDR(m0, M_DONTWAIT, MT_DATA); 4050 if (m0 != NULL) { 4051 if (m->m_pkthdr.len > MHLEN) { 4052 MCLGET(m0, M_DONTWAIT); 4053 if ((m0->m_flags & M_EXT) == 0) { 4054 m_freem(m); 4055 m_freem(m0); 4056 return NULL; 4057 } 4058 } 4059 m_copydata(m, 0, m->m_pkthdr.len, mtod(m0, caddr_t)); 4060 m0->m_pkthdr.len = m0->m_len = m->m_pkthdr.len; 4061 } 4062#else 4063 int mlen = MHLEN; 4064 int len = m->m_pkthdr.len; 4065 struct mbuf **mp = &m0; 4066 4067 while (len > 0) { 4068 if (mlen == MHLEN) { 4069 MGETHDR(*mp, M_DONTWAIT, MT_DATA); 4070 } else { 4071 MGET(*mp, M_DONTWAIT, MT_DATA); 4072 } 4073 if (*mp == NULL) { 4074 m_freem(m0); 4075 m0 = NULL; 4076 break; 4077 } 4078 if (len > MLEN) { 4079 MCLGET(*mp, M_DONTWAIT); 4080 if (((*mp)->m_flags & M_EXT) == 0) { 4081 m_freem(m0); 4082 m0 = NULL; 4083 break; 4084 } 4085 (*mp)->m_len = len <= MCLBYTES ? len : MCLBYTES; 4086 } else { 4087 (*mp)->m_len = len <= mlen ? len : mlen; 4088 } 4089 m_copydata(m, m->m_pkthdr.len - len, 4090 (*mp)->m_len, mtod((*mp), caddr_t)); 4091 len -= (*mp)->m_len; 4092 mp = &(*mp)->m_next; 4093 mlen = MLEN; 4094 } 4095#endif 4096 m_freem(m); 4097 return m0; 4098} 4099 4100static struct mbuf * 4101tulip_txput( 4102 tulip_softc_t * const sc, 4103 struct mbuf *m) 4104{ 4105 TULIP_PERFSTART(txput) 4106 tulip_ringinfo_t * const ri = &sc->tulip_txinfo; 4107 tulip_desc_t *eop, *nextout; 4108 int segcnt, free; 4109 u_int32_t d_status; 4110#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX) 4111 bus_dmamap_t map; 4112 int error; 4113#else 4114 struct mbuf *m0; 4115#endif 4116 4117#if defined(TULIP_DEBUG) 4118 if ((sc->tulip_cmdmode & TULIP_CMD_TXRUN) == 0) { 4119 printf("%s: txput%s: tx not running\n", 4120 sc->tulip_xname, 4121 (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) ? "(probe)" : ""); 4122 sc->tulip_flags |= TULIP_WANTTXSTART; 4123 sc->tulip_dbg.dbg_txput_finishes[0]++; 4124 goto finish; 4125 } 4126#endif 4127 4128 /* 4129 * Now we try to fill in our transmit descriptors. This is 4130 * a bit reminiscent of going on the Ark two by two 4131 * since each descriptor for the TULIP can describe 4132 * two buffers. So we advance through packet filling 4133 * each of the two entries at a time to to fill each 4134 * descriptor. Clear the first and last segment bits 4135 * in each descriptor (actually just clear everything 4136 * but the end-of-ring or chain bits) to make sure 4137 * we don't get messed up by previously sent packets. 4138 * 4139 * We may fail to put the entire packet on the ring if 4140 * there is either not enough ring entries free or if the 4141 * packet has more than MAX_TXSEG segments. In the former 4142 * case we will just wait for the ring to empty. In the 4143 * latter case we have to recopy. 4144 */ 4145#if !defined(TULIP_BUS_DMA) || defined(TULIP_BUS_DMA_NOTX) 4146 again: 4147 m0 = m; 4148#endif 4149 d_status = 0; 4150 eop = nextout = ri->ri_nextout; 4151 segcnt = 0; 4152 free = ri->ri_free; 4153 4154#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX) 4155 /* 4156 * Reclaim some dma maps from if we are out. 4157 */ 4158 if (sc->tulip_txmaps_free == 0) { 4159#if defined(TULIP_DEBUG) 4160 sc->tulip_dbg.dbg_no_txmaps++; 4161#endif 4162 free += tulip_tx_intr(sc); 4163 } 4164 if (sc->tulip_txmaps_free > 0) { 4165 map = sc->tulip_txmaps[sc->tulip_txmaps_free-1]; 4166 } else { 4167 sc->tulip_flags |= TULIP_WANTTXSTART; 4168#if defined(TULIP_DEBUG) 4169 sc->tulip_dbg.dbg_txput_finishes[1]++; 4170#endif 4171 goto finish; 4172 } 4173 error = bus_dmamap_load_mbuf(sc->tulip_dmatag, map, m, BUS_DMA_NOWAIT); 4174 if (error != 0) { 4175 if (error == EFBIG) { 4176 /* 4177 * The packet exceeds the number of transmit buffer 4178 * entries that we can use for one packet, so we have 4179 * to recopy it into one mbuf and then try again. 4180 */ 4181 m = tulip_mbuf_compress(m); 4182 if (m == NULL) { 4183#if defined(TULIP_DEBUG) 4184 sc->tulip_dbg.dbg_txput_finishes[2]++; 4185#endif 4186 goto finish; 4187 } 4188 error = bus_dmamap_load_mbuf(sc->tulip_dmatag, map, m, BUS_DMA_NOWAIT); 4189 } 4190 if (error != 0) { 4191 printf("%s: unable to load tx map, " 4192 "error = %d\n", sc->tulip_xname, error); 4193#if defined(TULIP_DEBUG) 4194 sc->tulip_dbg.dbg_txput_finishes[3]++; 4195#endif 4196 goto finish; 4197 } 4198 } 4199 if ((free -= (map->dm_nsegs + 1) / 2) <= 0 4200 /* 4201 * See if there's any unclaimed space in the transmit ring. 4202 */ 4203 && (free += tulip_tx_intr(sc)) <= 0) { 4204 /* 4205 * There's no more room but since nothing 4206 * has been committed at this point, just 4207 * show output is active, put back the 4208 * mbuf and return. 4209 */ 4210 sc->tulip_flags |= TULIP_WANTTXSTART; 4211#if defined(TULIP_DEBUG) 4212 sc->tulip_dbg.dbg_txput_finishes[4]++; 4213#endif 4214 bus_dmamap_unload(sc->tulip_dmatag, map); 4215 goto finish; 4216 } 4217 for (; map->dm_nsegs - segcnt > 1; segcnt += 2) { 4218 eop = nextout; 4219 eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN; 4220 eop->d_status = d_status; 4221 eop->d_addr1 = map->dm_segs[segcnt].ds_addr; 4222 eop->d_length1 = map->dm_segs[segcnt].ds_len; 4223 eop->d_addr2 = map->dm_segs[segcnt+1].ds_addr; 4224 eop->d_length2 = map->dm_segs[segcnt+1].ds_len; 4225 d_status = TULIP_DSTS_OWNER; 4226 if (++nextout == ri->ri_last) 4227 nextout = ri->ri_first; 4228 } 4229 if (segcnt < map->dm_nsegs) { 4230 eop = nextout; 4231 eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN; 4232 eop->d_status = d_status; 4233 eop->d_addr1 = map->dm_segs[segcnt].ds_addr; 4234 eop->d_length1 = map->dm_segs[segcnt].ds_len; 4235 eop->d_addr2 = 0; 4236 eop->d_length2 = 0; 4237 if (++nextout == ri->ri_last) 4238 nextout = ri->ri_first; 4239 } 4240 TULIP_TXMAP_PRESYNC(sc, map); 4241 M_SETCTX(m, map); 4242 map = NULL; 4243 --sc->tulip_txmaps_free; /* commit to using the dmamap */ 4244 4245#else /* !TULIP_BUS_DMA */ 4246 4247 do { 4248 int len = m0->m_len; 4249 caddr_t addr = mtod(m0, caddr_t); 4250 unsigned clsize = PAGE_SIZE - (((uintptr_t) addr) & (PAGE_SIZE-1)); 4251 4252 while (len > 0) { 4253 unsigned slen = min(len, clsize); 4254#ifdef BIG_PACKET 4255 int partial = 0; 4256 if (slen >= 2048) 4257 slen = 2040, partial = 1; 4258#endif 4259 segcnt++; 4260 if (segcnt > TULIP_MAX_TXSEG) { 4261 /* 4262 * The packet exceeds the number of transmit buffer 4263 * entries that we can use for one packet, so we have 4264 * recopy it into one mbuf and then try again. 4265 */ 4266 m = tulip_mbuf_compress(m); 4267 if (m == NULL) 4268 goto finish; 4269 goto again; 4270 } 4271 if (segcnt & 1) { 4272 if (--free == 0) { 4273 /* 4274 * See if there's any unclaimed space in the 4275 * transmit ring. 4276 */ 4277 if ((free += tulip_tx_intr(sc)) == 0) { 4278 /* 4279 * There's no more room but since nothing 4280 * has been committed at this point, just 4281 * show output is active, put back the 4282 * mbuf and return. 4283 */ 4284 sc->tulip_flags |= TULIP_WANTTXSTART; 4285#if defined(TULIP_DEBUG) 4286 sc->tulip_dbg.dbg_txput_finishes[1]++; 4287#endif 4288 goto finish; 4289 } 4290 } 4291 eop = nextout; 4292 if (++nextout == ri->ri_last) 4293 nextout = ri->ri_first; 4294 eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN; 4295 eop->d_status = d_status; 4296 eop->d_addr1 = TULIP_KVATOPHYS(sc, addr); 4297 eop->d_length1 = slen; 4298 } else { 4299 /* 4300 * Fill in second half of descriptor 4301 */ 4302 eop->d_addr2 = TULIP_KVATOPHYS(sc, addr); 4303 eop->d_length2 = slen; 4304 } 4305 d_status = TULIP_DSTS_OWNER; 4306 len -= slen; 4307 addr += slen; 4308#ifdef BIG_PACKET 4309 if (partial) 4310 continue; 4311#endif 4312 clsize = PAGE_SIZE; 4313 } 4314 } while ((m0 = m0->m_next) != NULL); 4315#endif /* TULIP_BUS_DMA */ 4316 4317 /* 4318 * bounce a copy to the bpf listener, if any. 4319 */ 4320 BPF_MTAP(&sc->tulip_if, m); 4321 4322 /* 4323 * The descriptors have been filled in. Now get ready 4324 * to transmit. 4325 */ 4326 _IF_ENQUEUE(&sc->tulip_txq, m); 4327 m = NULL; 4328 4329 /* 4330 * Make sure the next descriptor after this packet is owned 4331 * by us since it may have been set up above if we ran out 4332 * of room in the ring. 4333 */ 4334 nextout->d_status = 0; 4335 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(u_int32_t)); 4336 4337#if !defined(TULIP_BUS_DMA) || defined(TULIP_BUS_DMA_NOTX) 4338 /* 4339 * If we only used the first segment of the last descriptor, 4340 * make sure the second segment will not be used. 4341 */ 4342 if (segcnt & 1) { 4343 eop->d_addr2 = 0; 4344 eop->d_length2 = 0; 4345 } 4346#endif /* TULIP_BUS_DMA */ 4347 4348 /* 4349 * Mark the last and first segments, indicate we want a transmit 4350 * complete interrupt, and tell it to transmit! 4351 */ 4352 eop->d_flag |= TULIP_DFLAG_TxLASTSEG|TULIP_DFLAG_TxWANTINTR; 4353 4354 /* 4355 * Note that ri->ri_nextout is still the start of the packet 4356 * and until we set the OWNER bit, we can still back out of 4357 * everything we have done. 4358 */ 4359 ri->ri_nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG; 4360#if defined(TULIP_BUS_MAP) && !defined(TULIP_BUS_DMA_NOTX) 4361 if (eop < ri->ri_nextout) { 4362 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, 4363 (caddr_t) ri->ri_last - (caddr_t) ri->ri_nextout); 4364 TULIP_TXDESC_PRESYNC(sc, ri->ri_first, 4365 (caddr_t) (eop + 1) - (caddr_t) ri->ri_first); 4366 } else { 4367 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, 4368 (caddr_t) (eop + 1) - (caddr_t) ri->ri_nextout); 4369 } 4370#endif 4371 ri->ri_nextout->d_status = TULIP_DSTS_OWNER; 4372 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, sizeof(u_int32_t)); 4373 4374 /* 4375 * This advances the ring for us. 4376 */ 4377 ri->ri_nextout = nextout; 4378 ri->ri_free = free; 4379 4380 TULIP_PERFEND(txput); 4381 4382 if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) { 4383 TULIP_CSR_WRITE(sc, csr_txpoll, 1); 4384 sc->tulip_if.if_flags |= IFF_OACTIVE; 4385 sc->tulip_if.if_start = tulip_ifstart; 4386 TULIP_PERFEND(txput); 4387 return NULL; 4388 } 4389 4390 /* 4391 * switch back to the single queueing ifstart. 4392 */ 4393 sc->tulip_flags &= ~TULIP_WANTTXSTART; 4394 if (sc->tulip_txtimer == 0) 4395 sc->tulip_txtimer = TULIP_TXTIMER; 4396#if defined(TULIP_DEBUG) 4397 sc->tulip_dbg.dbg_txput_finishes[5]++; 4398#endif 4399 4400 /* 4401 * If we want a txstart, there must be not enough space in the 4402 * transmit ring. So we want to enable transmit done interrupts 4403 * so we can immediately reclaim some space. When the transmit 4404 * interrupt is posted, the interrupt handler will call tx_intr 4405 * to reclaim space and then txstart (since WANTTXSTART is set). 4406 * txstart will move the packet into the transmit ring and clear 4407 * WANTTXSTART thereby causing TXINTR to be cleared. 4408 */ 4409 finish: 4410#if defined(TULIP_DEBUG) 4411 sc->tulip_dbg.dbg_txput_finishes[6]++; 4412#endif 4413 if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_DOINGSETUP)) { 4414 sc->tulip_if.if_flags |= IFF_OACTIVE; 4415 sc->tulip_if.if_start = tulip_ifstart; 4416 if ((sc->tulip_intrmask & TULIP_STS_TXINTR) == 0) { 4417 sc->tulip_intrmask |= TULIP_STS_TXINTR; 4418 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask); 4419 } 4420 } else if ((sc->tulip_flags & TULIP_PROMISC) == 0) { 4421 if (sc->tulip_intrmask & TULIP_STS_TXINTR) { 4422 sc->tulip_intrmask &= ~TULIP_STS_TXINTR; 4423 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask); 4424 } 4425 } 4426 TULIP_CSR_WRITE(sc, csr_txpoll, 1); 4427 TULIP_PERFEND(txput); 4428 return m; 4429} 4430 4431static void 4432tulip_txput_setup( 4433 tulip_softc_t * const sc) 4434{ 4435 tulip_ringinfo_t * const ri = &sc->tulip_txinfo; 4436 tulip_desc_t *nextout; 4437 4438 /* 4439 * We will transmit, at most, one setup packet per call to ifstart. 4440 */ 4441 4442#if defined(TULIP_DEBUG) 4443 if ((sc->tulip_cmdmode & TULIP_CMD_TXRUN) == 0) { 4444 printf("%s: txput_setup: tx not running\n", 4445 sc->tulip_xname); 4446 sc->tulip_flags |= TULIP_WANTTXSTART; 4447 sc->tulip_if.if_start = tulip_ifstart; 4448 return; 4449 } 4450#endif 4451 /* 4452 * Try to reclaim some free descriptors.. 4453 */ 4454 if (ri->ri_free < 2) 4455 tulip_tx_intr(sc); 4456 if ((sc->tulip_flags & TULIP_DOINGSETUP) || ri->ri_free == 1) { 4457 sc->tulip_flags |= TULIP_WANTTXSTART; 4458 sc->tulip_if.if_start = tulip_ifstart; 4459 return; 4460 } 4461 bcopy(sc->tulip_setupdata, sc->tulip_setupbuf, 4462 sizeof(sc->tulip_setupbuf)); 4463 /* 4464 * Clear WANTSETUP and set DOINGSETUP. Set know that WANTSETUP is 4465 * set and DOINGSETUP is clear doing an XOR of the two will DTRT. 4466 */ 4467 sc->tulip_flags ^= TULIP_WANTSETUP|TULIP_DOINGSETUP; 4468 ri->ri_free--; 4469 nextout = ri->ri_nextout; 4470 nextout->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN; 4471 nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG|TULIP_DFLAG_TxLASTSEG 4472 |TULIP_DFLAG_TxSETUPPKT|TULIP_DFLAG_TxWANTINTR; 4473 if (sc->tulip_flags & TULIP_WANTHASHPERFECT) 4474 nextout->d_flag |= TULIP_DFLAG_TxHASHFILT; 4475 else if (sc->tulip_flags & TULIP_WANTHASHONLY) 4476 nextout->d_flag |= TULIP_DFLAG_TxHASHFILT|TULIP_DFLAG_TxINVRSFILT; 4477 4478 nextout->d_length2 = 0; 4479 nextout->d_addr2 = 0; 4480#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX) 4481 nextout->d_length1 = sc->tulip_setupmap->dm_segs[0].ds_len; 4482 nextout->d_addr1 = sc->tulip_setupmap->dm_segs[0].ds_addr; 4483 if (sc->tulip_setupmap->dm_nsegs == 2) { 4484 nextout->d_length2 = sc->tulip_setupmap->dm_segs[1].ds_len; 4485 nextout->d_addr2 = sc->tulip_setupmap->dm_segs[1].ds_addr; 4486 } 4487 TULIP_TXMAP_PRESYNC(sc, sc->tulip_setupmap); 4488 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(*nextout)); 4489#else 4490 nextout->d_length1 = sizeof(sc->tulip_setupbuf); 4491 nextout->d_addr1 = TULIP_KVATOPHYS(sc, sc->tulip_setupbuf); 4492#endif 4493 4494 /* 4495 * Advance the ring for the next transmit packet. 4496 */ 4497 if (++ri->ri_nextout == ri->ri_last) 4498 ri->ri_nextout = ri->ri_first; 4499 4500 /* 4501 * Make sure the next descriptor is owned by us since it 4502 * may have been set up above if we ran out of room in the 4503 * ring. 4504 */ 4505 ri->ri_nextout->d_status = 0; 4506 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, sizeof(u_int32_t)); 4507 nextout->d_status = TULIP_DSTS_OWNER; 4508 /* 4509 * Flush the ownwership of the current descriptor 4510 */ 4511 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(u_int32_t)); 4512 TULIP_CSR_WRITE(sc, csr_txpoll, 1); 4513 if ((sc->tulip_intrmask & TULIP_STS_TXINTR) == 0) { 4514 sc->tulip_intrmask |= TULIP_STS_TXINTR; 4515 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask); 4516 } 4517} 4518 4519 4520/* 4521 * This routine is entered at splnet() (splsoftnet() on NetBSD) 4522 * and thereby imposes no problems when TULIP_USE_SOFTINTR is 4523 * defined or not. 4524 */ 4525static int 4526tulip_ifioctl( 4527 struct ifnet * ifp, 4528 u_long cmd, 4529 caddr_t data) 4530{ 4531 TULIP_PERFSTART(ifioctl) 4532 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc; 4533 struct ifreq *ifr = (struct ifreq *) data; 4534 int s; 4535 int error = 0; 4536 4537#if defined(TULIP_USE_SOFTINTR) 4538 s = splnet(); 4539#else 4540 s = splimp(); 4541#endif 4542 switch (cmd) { 4543 case SIOCSIFFLAGS: { 4544 tulip_addr_filter(sc); /* reinit multicast filter */ 4545 tulip_init(sc); 4546 break; 4547 } 4548 4549 case SIOCSIFMEDIA: 4550 case SIOCGIFMEDIA: { 4551 error = ifmedia_ioctl(ifp, ifr, &sc->tulip_ifmedia, cmd); 4552 break; 4553 } 4554 4555 case SIOCADDMULTI: 4556 case SIOCDELMULTI: { 4557 /* 4558 * Update multicast listeners 4559 */ 4560 tulip_addr_filter(sc); /* reset multicast filtering */ 4561 tulip_init(sc); 4562 error = 0; 4563 break; 4564 } 4565 4566 case SIOCSIFMTU: 4567 /* 4568 * Set the interface MTU. 4569 */ 4570 if (ifr->ifr_mtu > ETHERMTU 4571#ifdef BIG_PACKET 4572 && sc->tulip_chipid != TULIP_21140 4573 && sc->tulip_chipid != TULIP_21140A 4574 && sc->tulip_chipid != TULIP_21041 4575#endif 4576 ) { 4577 error = EINVAL; 4578 break; 4579 } 4580 ifp->if_mtu = ifr->ifr_mtu; 4581#ifdef BIG_PACKET 4582 tulip_reset(sc); 4583 tulip_init(sc); 4584#endif 4585 break; 4586 4587#ifdef SIOCGADDRROM 4588 case SIOCGADDRROM: { 4589 error = copyout(sc->tulip_rombuf, ifr->ifr_data, sizeof(sc->tulip_rombuf)); 4590 break; 4591 } 4592#endif 4593#ifdef SIOCGCHIPID 4594 case SIOCGCHIPID: { 4595 ifr->ifr_metric = (int) sc->tulip_chipid; 4596 break; 4597 } 4598#endif 4599 default: { 4600 error = ether_ioctl(ifp, cmd, data); 4601 break; 4602 } 4603 } 4604 4605 splx(s); 4606 TULIP_PERFEND(ifioctl); 4607 return error; 4608} 4609 4610/* 4611 * These routines gets called at device spl (from ether_output). This might 4612 * pose a problem for TULIP_USE_SOFTINTR if ether_output is called at 4613 * device spl from another driver. 4614 */ 4615 4616static void 4617tulip_ifstart( 4618 struct ifnet * const ifp) 4619{ 4620 TULIP_PERFSTART(ifstart) 4621 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc; 4622 4623 if (sc->tulip_if.if_flags & IFF_RUNNING) { 4624 4625 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP) 4626 tulip_txput_setup(sc); 4627 4628 while (!IFQ_DRV_IS_EMPTY(&sc->tulip_if.if_snd)) { 4629 struct mbuf *m; 4630 IFQ_DRV_DEQUEUE(&sc->tulip_if.if_snd, m); 4631 if(m == NULL) 4632 break; 4633 if ((m = tulip_txput(sc, m)) != NULL) { 4634 IFQ_DRV_PREPEND(&sc->tulip_if.if_snd, m); 4635 break; 4636 } 4637 } 4638 } 4639 4640 TULIP_PERFEND(ifstart); 4641} 4642 4643/* 4644 * Even though this routine runs at device spl, it does not break 4645 * our use of splnet (splsoftnet under NetBSD) for the majority 4646 * of this driver (if TULIP_USE_SOFTINTR defined) since 4647 * if_watcbog is called from if_watchdog which is called from 4648 * splsoftclock which is below spl[soft]net. 4649 */ 4650static void 4651tulip_ifwatchdog( 4652 struct ifnet *ifp) 4653{ 4654 TULIP_PERFSTART(ifwatchdog) 4655 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc; 4656 4657#if defined(TULIP_DEBUG) 4658 u_int32_t rxintrs = sc->tulip_dbg.dbg_rxintrs - sc->tulip_dbg.dbg_last_rxintrs; 4659 if (rxintrs > sc->tulip_dbg.dbg_high_rxintrs_hz) 4660 sc->tulip_dbg.dbg_high_rxintrs_hz = rxintrs; 4661 sc->tulip_dbg.dbg_last_rxintrs = sc->tulip_dbg.dbg_rxintrs; 4662#endif /* TULIP_DEBUG */ 4663 4664 sc->tulip_if.if_timer = 1; 4665 /* 4666 * These should be rare so do a bulk test up front so we can just skip 4667 * them if needed. 4668 */ 4669 if (sc->tulip_flags & (TULIP_SYSTEMERROR|TULIP_RXBUFSLOW|TULIP_NOMESSAGES)) { 4670 /* 4671 * If the number of receive buffer is low, try to refill 4672 */ 4673 if (sc->tulip_flags & TULIP_RXBUFSLOW) 4674 tulip_rx_intr(sc); 4675 4676 if (sc->tulip_flags & TULIP_SYSTEMERROR) { 4677 printf("%s: %d system errors: last was %s\n", 4678 sc->tulip_xname, sc->tulip_system_errors, 4679 tulip_system_errors[sc->tulip_last_system_error]); 4680 } 4681 if (sc->tulip_statusbits) { 4682 tulip_print_abnormal_interrupt(sc, sc->tulip_statusbits); 4683 sc->tulip_statusbits = 0; 4684 } 4685 4686 sc->tulip_flags &= ~(TULIP_NOMESSAGES|TULIP_SYSTEMERROR); 4687 } 4688 4689 if (sc->tulip_txtimer) 4690 tulip_tx_intr(sc); 4691 if (sc->tulip_txtimer && --sc->tulip_txtimer == 0) { 4692 printf("%s: transmission timeout\n", sc->tulip_xname); 4693 if (TULIP_DO_AUTOSENSE(sc)) { 4694 sc->tulip_media = TULIP_MEDIA_UNKNOWN; 4695 sc->tulip_probe_state = TULIP_PROBE_INACTIVE; 4696 sc->tulip_flags &= ~(TULIP_WANTRXACT|TULIP_LINKUP); 4697 } 4698 tulip_reset(sc); 4699 tulip_init(sc); 4700 } 4701 4702 TULIP_PERFEND(ifwatchdog); 4703 TULIP_PERFMERGE(sc, perf_intr_cycles); 4704 TULIP_PERFMERGE(sc, perf_ifstart_cycles); 4705 TULIP_PERFMERGE(sc, perf_ifioctl_cycles); 4706 TULIP_PERFMERGE(sc, perf_ifwatchdog_cycles); 4707 TULIP_PERFMERGE(sc, perf_timeout_cycles); 4708 TULIP_PERFMERGE(sc, perf_ifstart_one_cycles); 4709 TULIP_PERFMERGE(sc, perf_txput_cycles); 4710 TULIP_PERFMERGE(sc, perf_txintr_cycles); 4711 TULIP_PERFMERGE(sc, perf_rxintr_cycles); 4712 TULIP_PERFMERGE(sc, perf_rxget_cycles); 4713 TULIP_PERFMERGE(sc, perf_intr); 4714 TULIP_PERFMERGE(sc, perf_ifstart); 4715 TULIP_PERFMERGE(sc, perf_ifioctl); 4716 TULIP_PERFMERGE(sc, perf_ifwatchdog); 4717 TULIP_PERFMERGE(sc, perf_timeout); 4718 TULIP_PERFMERGE(sc, perf_ifstart_one); 4719 TULIP_PERFMERGE(sc, perf_txput); 4720 TULIP_PERFMERGE(sc, perf_txintr); 4721 TULIP_PERFMERGE(sc, perf_rxintr); 4722 TULIP_PERFMERGE(sc, perf_rxget); 4723} 4724 4725/* 4726 * All printf's are real as of now! 4727 */ 4728#ifdef printf 4729#undef printf 4730#endif 4731 4732static void 4733tulip_attach( 4734 tulip_softc_t * const sc) 4735{ 4736 struct ifnet * const ifp = &sc->tulip_if; 4737 4738 /* XXX: driver name/unit should be set some other way */ 4739 ifp->if_dname = "de"; 4740 ifp->if_dunit = sc->tulip_unit; 4741 ifp->if_flags = IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST|IFF_NEEDSGIANT; 4742 ifp->if_ioctl = tulip_ifioctl; 4743 ifp->if_start = tulip_ifstart; 4744 ifp->if_watchdog = tulip_ifwatchdog; 4745 ifp->if_timer = 1; 4746 ifp->if_init = tulip_ifinit; 4747 4748 printf("%s: %s%s pass %d.%d%s\n", 4749 sc->tulip_xname, 4750 sc->tulip_boardid, 4751 tulip_chipdescs[sc->tulip_chipid], 4752 (sc->tulip_revinfo & 0xF0) >> 4, 4753 sc->tulip_revinfo & 0x0F, 4754 (sc->tulip_features & (TULIP_HAVE_ISVSROM|TULIP_HAVE_OKSROM)) 4755 == TULIP_HAVE_ISVSROM ? " (invalid EESPROM checksum)" : ""); 4756#ifndef __FreeBSD__ 4757 printf("%s: address %6D\n", 4758 sc->tulip_xname, sc->tulip_enaddr, ":"); 4759#endif 4760 4761#if defined(__alpha__) 4762 /* 4763 * In case the SRM console told us about a bogus media, 4764 * we need to check to be safe. 4765 */ 4766 if (sc->tulip_mediums[sc->tulip_media] == NULL) 4767 sc->tulip_media = TULIP_MEDIA_UNKNOWN; 4768#endif 4769 4770 (*sc->tulip_boardsw->bd_media_probe)(sc); 4771 ifmedia_init(&sc->tulip_ifmedia, 0, 4772 tulip_ifmedia_change, 4773 tulip_ifmedia_status); 4774 sc->tulip_flags &= ~TULIP_DEVICEPROBE; 4775 tulip_ifmedia_add(sc); 4776 4777 tulip_reset(sc); 4778 4779 ether_ifattach(&(sc)->tulip_if, sc->tulip_enaddr); 4780 IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen); 4781 ifp->if_snd.ifq_drv_maxlen = ifqmaxlen; 4782 IFQ_SET_READY(&ifp->if_snd); 4783} 4784 4785#if defined(TULIP_BUS_DMA) 4786#if !defined(TULIP_BUS_DMA_NOTX) || !defined(TULIP_BUS_DMA_NORX) 4787static int 4788tulip_busdma_allocmem( 4789 tulip_softc_t * const sc, 4790 size_t size, 4791 bus_dmamap_t *map_p, 4792 tulip_desc_t **desc_p) 4793{ 4794 bus_dma_segment_t segs[1]; 4795 int nsegs, error; 4796 error = bus_dmamem_alloc(sc->tulip_dmatag, size, 1, PAGE_SIZE, 4797 segs, sizeof(segs)/sizeof(segs[0]), 4798 &nsegs, BUS_DMA_NOWAIT); 4799 if (error == 0) { 4800 void *desc; 4801 error = bus_dmamem_map(sc->tulip_dmatag, segs, nsegs, size, 4802 (void *) &desc, BUS_DMA_NOWAIT|BUS_DMA_COHERENT); 4803 if (error == 0) { 4804 bus_dmamap_t map; 4805 error = bus_dmamap_create(sc->tulip_dmatag, size, 1, size, 0, 4806 BUS_DMA_NOWAIT, &map); 4807 if (error == 0) { 4808 error = bus_dmamap_load(sc->tulip_dmatag, map, desc, 4809 size, NULL, BUS_DMA_NOWAIT); 4810 if (error) 4811 bus_dmamap_destroy(sc->tulip_dmatag, map); 4812 else 4813 *map_p = map; 4814 } 4815 if (error) 4816 bus_dmamem_unmap(sc->tulip_dmatag, desc, size); 4817 } 4818 if (error) 4819 bus_dmamem_free(sc->tulip_dmatag, segs, nsegs); 4820 else 4821 *desc_p = desc; 4822 } 4823 return error; 4824} 4825#endif 4826 4827static int 4828tulip_busdma_init( 4829 tulip_softc_t * const sc) 4830{ 4831 int error = 0; 4832 4833#if !defined(TULIP_BUS_DMA_NOTX) 4834 /* 4835 * Allocate dmamap for setup descriptor 4836 */ 4837 error = bus_dmamap_create(sc->tulip_dmatag, sizeof(sc->tulip_setupbuf), 2, 4838 sizeof(sc->tulip_setupbuf), 0, BUS_DMA_NOWAIT, 4839 &sc->tulip_setupmap); 4840 if (error == 0) { 4841 error = bus_dmamap_load(sc->tulip_dmatag, sc->tulip_setupmap, 4842 sc->tulip_setupbuf, sizeof(sc->tulip_setupbuf), 4843 NULL, BUS_DMA_NOWAIT); 4844 if (error) 4845 bus_dmamap_destroy(sc->tulip_dmatag, sc->tulip_setupmap); 4846 } 4847 /* 4848 * Allocate space and dmamap for transmit ring 4849 */ 4850 if (error == 0) { 4851 error = tulip_busdma_allocmem(sc, sizeof(tulip_desc_t) * TULIP_TXDESCS, 4852 &sc->tulip_txdescmap, 4853 &sc->tulip_txdescs); 4854 } 4855 4856 /* 4857 * Allocate dmamaps for each transmit descriptors 4858 */ 4859 if (error == 0) { 4860 while (error == 0 && sc->tulip_txmaps_free < TULIP_TXDESCS) { 4861 bus_dmamap_t map; 4862 if ((error = TULIP_TXMAP_CREATE(sc, &map)) == 0) 4863 sc->tulip_txmaps[sc->tulip_txmaps_free++] = map; 4864 } 4865 if (error) { 4866 while (sc->tulip_txmaps_free > 0) 4867 bus_dmamap_destroy(sc->tulip_dmatag, 4868 sc->tulip_txmaps[--sc->tulip_txmaps_free]); 4869 } 4870 } 4871#else 4872 if (error == 0) { 4873 sc->tulip_txdescs = (tulip_desc_t *) malloc(TULIP_TXDESCS * sizeof(tulip_desc_t), M_DEVBUF, M_NOWAIT); 4874 if (sc->tulip_txdescs == NULL) 4875 error = ENOMEM; 4876 } 4877#endif 4878#if !defined(TULIP_BUS_DMA_NORX) 4879 /* 4880 * Allocate space and dmamap for receive ring 4881 */ 4882 if (error == 0) { 4883 error = tulip_busdma_allocmem(sc, sizeof(tulip_desc_t) * TULIP_RXDESCS, 4884 &sc->tulip_rxdescmap, 4885 &sc->tulip_rxdescs); 4886 } 4887 4888 /* 4889 * Allocate dmamaps for each receive descriptors 4890 */ 4891 if (error == 0) { 4892 while (error == 0 && sc->tulip_rxmaps_free < TULIP_RXDESCS) { 4893 bus_dmamap_t map; 4894 if ((error = TULIP_RXMAP_CREATE(sc, &map)) == 0) 4895 sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map; 4896 } 4897 if (error) { 4898 while (sc->tulip_rxmaps_free > 0) 4899 bus_dmamap_destroy(sc->tulip_dmatag, 4900 sc->tulip_rxmaps[--sc->tulip_rxmaps_free]); 4901 } 4902 } 4903#else 4904 if (error == 0) { 4905 sc->tulip_rxdescs = (tulip_desc_t *) malloc(TULIP_RXDESCS * sizeof(tulip_desc_t), M_DEVBUF, M_NOWAIT); 4906 if (sc->tulip_rxdescs == NULL) 4907 error = ENOMEM; 4908 } 4909#endif 4910 return error; 4911} 4912#endif /* TULIP_BUS_DMA */ 4913 4914static void 4915tulip_initcsrs( 4916 tulip_softc_t * const sc, 4917 tulip_csrptr_t csr_base, 4918 size_t csr_size) 4919{ 4920 sc->tulip_csrs.csr_busmode = csr_base + 0 * csr_size; 4921 sc->tulip_csrs.csr_txpoll = csr_base + 1 * csr_size; 4922 sc->tulip_csrs.csr_rxpoll = csr_base + 2 * csr_size; 4923 sc->tulip_csrs.csr_rxlist = csr_base + 3 * csr_size; 4924 sc->tulip_csrs.csr_txlist = csr_base + 4 * csr_size; 4925 sc->tulip_csrs.csr_status = csr_base + 5 * csr_size; 4926 sc->tulip_csrs.csr_command = csr_base + 6 * csr_size; 4927 sc->tulip_csrs.csr_intr = csr_base + 7 * csr_size; 4928 sc->tulip_csrs.csr_missed_frames = csr_base + 8 * csr_size; 4929 sc->tulip_csrs.csr_9 = csr_base + 9 * csr_size; 4930 sc->tulip_csrs.csr_10 = csr_base + 10 * csr_size; 4931 sc->tulip_csrs.csr_11 = csr_base + 11 * csr_size; 4932 sc->tulip_csrs.csr_12 = csr_base + 12 * csr_size; 4933 sc->tulip_csrs.csr_13 = csr_base + 13 * csr_size; 4934 sc->tulip_csrs.csr_14 = csr_base + 14 * csr_size; 4935 sc->tulip_csrs.csr_15 = csr_base + 15 * csr_size; 4936} 4937 4938static void 4939tulip_initring( 4940 tulip_softc_t * const sc, 4941 tulip_ringinfo_t * const ri, 4942 tulip_desc_t *descs, 4943 int ndescs) 4944{ 4945 ri->ri_max = ndescs; 4946 ri->ri_first = descs; 4947 ri->ri_last = ri->ri_first + ri->ri_max; 4948 bzero((caddr_t) ri->ri_first, sizeof(ri->ri_first[0]) * ri->ri_max); 4949 ri->ri_last[-1].d_flag = TULIP_DFLAG_ENDRING; 4950} 4951 4952/* 4953 * This is the PCI configuration support. 4954 */ 4955 4956#define PCI_CBIO 0x10 /* Configuration Base IO Address */ 4957#define PCI_CBMA 0x14 /* Configuration Base Memory Address */ 4958#define PCI_CFDA 0x40 /* Configuration Driver Area */ 4959 4960static int 4961tulip_pci_probe(device_t dev) 4962{ 4963 const char *name = NULL; 4964 4965 if (pci_get_vendor(dev) != DEC_VENDORID) 4966 return ENXIO; 4967 4968 /* 4969 * Some LanMedia WAN cards use the Tulip chip, but they have 4970 * their own driver, and we should not recognize them 4971 */ 4972 if (pci_get_subvendor(dev) == 0x1376) 4973 return ENXIO; 4974 4975 switch (pci_get_device(dev)) { 4976 case CHIPID_21040: 4977 name = "Digital 21040 Ethernet"; 4978 break; 4979 case CHIPID_21041: 4980 name = "Digital 21041 Ethernet"; 4981 break; 4982 case CHIPID_21140: 4983 if (pci_get_revid(dev) >= 0x20) 4984 name = "Digital 21140A Fast Ethernet"; 4985 else 4986 name = "Digital 21140 Fast Ethernet"; 4987 break; 4988 case CHIPID_21142: 4989 if (pci_get_revid(dev) >= 0x20) 4990 name = "Digital 21143 Fast Ethernet"; 4991 else 4992 name = "Digital 21142 Fast Ethernet"; 4993 break; 4994 } 4995 if (name) { 4996 device_set_desc(dev, name);
|