if_sf.c (50548) | if_sf.c (50675) |
---|---|
1/* 2 * Copyright (c) 1997, 1998, 1999 3 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 15 unchanged lines hidden (view full) --- 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 30 * THE POSSIBILITY OF SUCH DAMAGE. 31 * | 1/* 2 * Copyright (c) 1997, 1998, 1999 3 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 15 unchanged lines hidden (view full) --- 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 30 * THE POSSIBILITY OF SUCH DAMAGE. 31 * |
32 * $FreeBSD: head/sys/dev/sf/if_sf.c 50548 1999-08-29 09:03:58Z bde $ | 32 * $FreeBSD: head/sys/dev/sf/if_sf.c 50675 1999-08-30 23:08:32Z wpaul $ |
33 */ 34 35/* 36 * Adaptec AIC-6915 "Starfire" PCI fast ethernet driver for FreeBSD. 37 * Programming manual is available from www.adaptec.com. 38 * 39 * Written by Bill Paul <wpaul@ctr.columbia.edu> 40 * Department of Electical Engineering --- 62 unchanged lines hidden (view full) --- 103#include <machine/clock.h> /* for DELAY */ 104#include <machine/bus_pio.h> 105#include <machine/bus_memio.h> 106#include <machine/bus.h> 107#include <machine/resource.h> 108#include <sys/bus.h> 109#include <sys/rman.h> 110 | 33 */ 34 35/* 36 * Adaptec AIC-6915 "Starfire" PCI fast ethernet driver for FreeBSD. 37 * Programming manual is available from www.adaptec.com. 38 * 39 * Written by Bill Paul <wpaul@ctr.columbia.edu> 40 * Department of Electical Engineering --- 62 unchanged lines hidden (view full) --- 103#include <machine/clock.h> /* for DELAY */ 104#include <machine/bus_pio.h> 105#include <machine/bus_memio.h> 106#include <machine/bus.h> 107#include <machine/resource.h> 108#include <sys/bus.h> 109#include <sys/rman.h> 110 |
111#include <dev/mii/mii.h> 112#include <dev/mii/miivar.h> 113 114#include "miibus_if.h" 115 |
|
111#include <pci/pcireg.h> 112#include <pci/pcivar.h> 113 114#define SF_USEIOSPACE 115 | 116#include <pci/pcireg.h> 117#include <pci/pcivar.h> 118 119#define SF_USEIOSPACE 120 |
116/* #define SF_BACKGROUND_AUTONEG */ 117 | |
118#include <pci/if_sfreg.h> 119 120#ifndef lint 121static const char rcsid[] = | 121#include <pci/if_sfreg.h> 122 123#ifndef lint 124static const char rcsid[] = |
122 "$FreeBSD: head/sys/dev/sf/if_sf.c 50548 1999-08-29 09:03:58Z bde $"; | 125 "$FreeBSD: head/sys/dev/sf/if_sf.c 50675 1999-08-30 23:08:32Z wpaul $"; |
123#endif 124 125static struct sf_type sf_devs[] = { 126 { AD_VENDORID, AD_DEVICEID_STARFIRE, 127 "Adaptec AIC-6915 10/100BaseTX" }, 128 { 0, 0, NULL } 129}; 130 | 126#endif 127 128static struct sf_type sf_devs[] = { 129 { AD_VENDORID, AD_DEVICEID_STARFIRE, 130 "Adaptec AIC-6915 10/100BaseTX" }, 131 { 0, 0, NULL } 132}; 133 |
131static struct sf_type sf_phys[] = { 132 { 0, 0, "<MII-compliant physical interface>" } 133}; 134 | |
135static int sf_probe __P((device_t)); 136static int sf_attach __P((device_t)); 137static int sf_detach __P((device_t)); 138static void sf_intr __P((void *)); 139static void sf_stats_update __P((void *)); 140static void sf_rxeof __P((struct sf_softc *)); 141static void sf_txeof __P((struct sf_softc *)); 142static int sf_encap __P((struct sf_softc *, --- 18 unchanged lines hidden (view full) --- 161static int sf_sethash __P((struct sf_softc *, caddr_t, int)); 162#ifdef notdef 163static int sf_setvlan __P((struct sf_softc *, int, u_int32_t)); 164#endif 165 166static u_int8_t sf_read_eeprom __P((struct sf_softc *, int)); 167static u_int32_t sf_calchash __P((caddr_t)); 168 | 134static int sf_probe __P((device_t)); 135static int sf_attach __P((device_t)); 136static int sf_detach __P((device_t)); 137static void sf_intr __P((void *)); 138static void sf_stats_update __P((void *)); 139static void sf_rxeof __P((struct sf_softc *)); 140static void sf_txeof __P((struct sf_softc *)); 141static int sf_encap __P((struct sf_softc *, --- 18 unchanged lines hidden (view full) --- 160static int sf_sethash __P((struct sf_softc *, caddr_t, int)); 161#ifdef notdef 162static int sf_setvlan __P((struct sf_softc *, int, u_int32_t)); 163#endif 164 165static u_int8_t sf_read_eeprom __P((struct sf_softc *, int)); 166static u_int32_t sf_calchash __P((caddr_t)); 167 |
169static int sf_phy_readreg __P((struct sf_softc *, int)); 170static void sf_phy_writereg __P((struct sf_softc *, int, int)); 171static void sf_autoneg_xmit __P((struct sf_softc *)); 172static void sf_autoneg_mii __P((struct sf_softc *, int, int)); 173static void sf_getmode_mii __P((struct sf_softc *)); 174static void sf_setmode_mii __P((struct sf_softc *, int)); | 168static int sf_miibus_readreg __P((device_t, int, int)); 169static int sf_miibus_writereg __P((device_t, int, int, int)); 170static void sf_miibus_statchg __P((device_t)); |
175 176static u_int32_t csr_read_4 __P((struct sf_softc *, int)); 177static void csr_write_4 __P((struct sf_softc *, int, u_int32_t)); 178 179#ifdef SF_USEIOSPACE 180#define SF_RES SYS_RES_IOPORT 181#define SF_RID SF_PCI_LOIO 182#else 183#define SF_RES SYS_RES_MEMORY 184#define SF_RID SF_PCI_LOMEM 185#endif 186 187static device_method_t sf_methods[] = { 188 /* Device interface */ 189 DEVMETHOD(device_probe, sf_probe), 190 DEVMETHOD(device_attach, sf_attach), 191 DEVMETHOD(device_detach, sf_detach), 192 DEVMETHOD(device_shutdown, sf_shutdown), | 171 172static u_int32_t csr_read_4 __P((struct sf_softc *, int)); 173static void csr_write_4 __P((struct sf_softc *, int, u_int32_t)); 174 175#ifdef SF_USEIOSPACE 176#define SF_RES SYS_RES_IOPORT 177#define SF_RID SF_PCI_LOIO 178#else 179#define SF_RES SYS_RES_MEMORY 180#define SF_RID SF_PCI_LOMEM 181#endif 182 183static device_method_t sf_methods[] = { 184 /* Device interface */ 185 DEVMETHOD(device_probe, sf_probe), 186 DEVMETHOD(device_attach, sf_attach), 187 DEVMETHOD(device_detach, sf_detach), 188 DEVMETHOD(device_shutdown, sf_shutdown), |
189 190 /* bus interface */ 191 DEVMETHOD(bus_print_child, bus_generic_print_child), 192 DEVMETHOD(bus_driver_added, bus_generic_driver_added), 193 194 /* MII interface */ 195 DEVMETHOD(miibus_readreg, sf_miibus_readreg), 196 DEVMETHOD(miibus_writereg, sf_miibus_writereg), 197 DEVMETHOD(miibus_statchg, sf_miibus_statchg), 198 |
|
193 { 0, 0 } 194}; 195 196static driver_t sf_driver = { 197 "sf", 198 sf_methods, 199 sizeof(struct sf_softc), 200}; 201 202static devclass_t sf_devclass; 203 204DRIVER_MODULE(sf, pci, sf_driver, sf_devclass, 0, 0); | 199 { 0, 0 } 200}; 201 202static driver_t sf_driver = { 203 "sf", 204 sf_methods, 205 sizeof(struct sf_softc), 206}; 207 208static devclass_t sf_devclass; 209 210DRIVER_MODULE(sf, pci, sf_driver, sf_devclass, 0, 0); |
211DRIVER_MODULE(miibus, sf, miibus_driver, miibus_devclass, 0, 0); |
|
205 206#define SF_SETBIT(sc, reg, x) \ 207 csr_write_4(sc, reg, csr_read_4(sc, reg) | x) 208 209#define SF_CLRBIT(sc, reg, x) \ 210 csr_write_4(sc, reg, csr_read_4(sc, reg) & ~x) 211 212static u_int32_t csr_read_4(sc, reg) --- 135 unchanged lines hidden (view full) --- 348 349 csr_write_4(sc, SF_RXFILT_HASH_BASE + 350 (idx * SF_RXFILT_HASH_SKIP) + SF_RXFILT_HASH_VLANOFF, vlan); 351 352 return(0); 353} 354#endif 355 | 212 213#define SF_SETBIT(sc, reg, x) \ 214 csr_write_4(sc, reg, csr_read_4(sc, reg) | x) 215 216#define SF_CLRBIT(sc, reg, x) \ 217 csr_write_4(sc, reg, csr_read_4(sc, reg) & ~x) 218 219static u_int32_t csr_read_4(sc, reg) --- 135 unchanged lines hidden (view full) --- 355 356 csr_write_4(sc, SF_RXFILT_HASH_BASE + 357 (idx * SF_RXFILT_HASH_SKIP) + SF_RXFILT_HASH_VLANOFF, vlan); 358 359 return(0); 360} 361#endif 362 |
356static int sf_phy_readreg(sc, reg) 357 struct sf_softc *sc; 358 int reg; | 363static int sf_miibus_readreg(dev, phy, reg) 364 device_t dev; 365 int phy, reg; |
359{ | 366{ |
367 struct sf_softc *sc; |
|
360 int i; 361 u_int32_t val = 0; 362 | 368 int i; 369 u_int32_t val = 0; 370 |
371 sc = device_get_softc(dev); 372 |
|
363 for (i = 0; i < SF_TIMEOUT; i++) { | 373 for (i = 0; i < SF_TIMEOUT; i++) { |
364 val = csr_read_4(sc, SF_PHY_REG(sc->sf_phy_addr, reg)); | 374 val = csr_read_4(sc, SF_PHY_REG(phy, reg)); |
365 if (val & SF_MII_DATAVALID) 366 break; 367 } 368 369 if (i == SF_TIMEOUT) 370 return(0); 371 372 if ((val & 0x0000FFFF) == 0xFFFF) 373 return(0); 374 375 return(val & 0x0000FFFF); 376} 377 | 375 if (val & SF_MII_DATAVALID) 376 break; 377 } 378 379 if (i == SF_TIMEOUT) 380 return(0); 381 382 if ((val & 0x0000FFFF) == 0xFFFF) 383 return(0); 384 385 return(val & 0x0000FFFF); 386} 387 |
378static void sf_phy_writereg(sc, reg, val) 379 struct sf_softc *sc; 380 int reg, val; | 388static int sf_miibus_writereg(dev, phy, reg, val) 389 device_t dev; 390 int phy, reg, val; |
381{ | 391{ |
392 struct sf_softc *sc; |
|
382 int i; 383 int busy; 384 | 393 int i; 394 int busy; 395 |
385 csr_write_4(sc, SF_PHY_REG(sc->sf_phy_addr, reg), val); | 396 sc = device_get_softc(dev); |
386 | 397 |
398 csr_write_4(sc, SF_PHY_REG(phy, reg), val); 399 |
|
387 for (i = 0; i < SF_TIMEOUT; i++) { | 400 for (i = 0; i < SF_TIMEOUT; i++) { |
388 busy = csr_read_4(sc, SF_PHY_REG(sc->sf_phy_addr, reg)); | 401 busy = csr_read_4(sc, SF_PHY_REG(phy, reg)); |
389 if (!(busy & SF_MII_BUSY)) 390 break; 391 } 392 | 402 if (!(busy & SF_MII_BUSY)) 403 break; 404 } 405 |
406 return(0); 407} 408 409static void sf_miibus_statchg(dev) 410 device_t dev; 411{ 412 struct sf_softc *sc; 413 struct mii_data *mii; 414 415 sc = device_get_softc(dev); 416 mii = device_get_softc(sc->sf_miibus); 417 418 if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX) { 419 SF_SETBIT(sc, SF_MACCFG_1, SF_MACCFG1_FULLDUPLEX); 420 } else { 421 SF_CLRBIT(sc, SF_MACCFG_1, SF_MACCFG1_FULLDUPLEX); 422 } 423 |
|
393 return; 394} 395 396static void sf_setmulti(sc) 397 struct sf_softc *sc; 398{ 399 struct ifnet *ifp; 400 int i; --- 42 unchanged lines hidden (view full) --- 443 LLADDR((struct sockaddr_dl *)ifma->ifma_addr), 0); 444 } 445 } 446 447 return; 448} 449 450/* | 424 return; 425} 426 427static void sf_setmulti(sc) 428 struct sf_softc *sc; 429{ 430 struct ifnet *ifp; 431 int i; --- 42 unchanged lines hidden (view full) --- 474 LLADDR((struct sockaddr_dl *)ifma->ifma_addr), 0); 475 } 476 } 477 478 return; 479} 480 481/* |
451 * Initiate an autonegotiation session. 452 */ 453static void sf_autoneg_xmit(sc) 454 struct sf_softc *sc; 455{ 456 u_int16_t phy_sts; 457 458 sf_phy_writereg(sc, PHY_BMCR, PHY_BMCR_RESET); 459 DELAY(500); 460 while(sf_phy_readreg(sc, PHY_BMCR) 461 & PHY_BMCR_RESET); 462 463 phy_sts = sf_phy_readreg(sc, PHY_BMCR); 464 phy_sts |= PHY_BMCR_AUTONEGENBL|PHY_BMCR_AUTONEGRSTR; 465 sf_phy_writereg(sc, PHY_BMCR, phy_sts); 466 467 return; 468} 469 470/* 471 * Invoke autonegotiation on a PHY. 472 */ 473static void sf_autoneg_mii(sc, flag, verbose) 474 struct sf_softc *sc; 475 int flag; 476 int verbose; 477{ 478 u_int16_t phy_sts = 0, media, advert, ability; 479 struct ifnet *ifp; 480 struct ifmedia *ifm; 481 482 ifm = &sc->ifmedia; 483 ifp = &sc->arpcom.ac_if; 484 485 ifm->ifm_media = IFM_ETHER | IFM_AUTO; 486 487#ifndef FORCE_AUTONEG_TFOUR 488 /* 489 * First, see if autoneg is supported. If not, there's 490 * no point in continuing. 491 */ 492 phy_sts = sf_phy_readreg(sc, PHY_BMSR); 493 if (!(phy_sts & PHY_BMSR_CANAUTONEG)) { 494 if (verbose) 495 printf("sf%d: autonegotiation not supported\n", 496 sc->sf_unit); 497 ifm->ifm_media = IFM_ETHER|IFM_10_T|IFM_HDX; 498 return; 499 } 500#endif 501 502 switch (flag) { 503 case SF_FLAG_FORCEDELAY: 504 /* 505 * XXX Never use this option anywhere but in the probe 506 * routine: making the kernel stop dead in its tracks 507 * for three whole seconds after we've gone multi-user 508 * is really bad manners. 509 */ 510 sf_autoneg_xmit(sc); 511 DELAY(5000000); 512 break; 513 case SF_FLAG_SCHEDDELAY: 514 /* 515 * Wait for the transmitter to go idle before starting 516 * an autoneg session, otherwise sf_start() may clobber 517 * our timeout, and we don't want to allow transmission 518 * during an autoneg session since that can screw it up. 519 */ 520 if (sc->sf_tx_cnt) { 521 sc->sf_want_auto = 1; 522 return; 523 } 524 sf_autoneg_xmit(sc); 525 ifp->if_timer = 5; 526 sc->sf_autoneg = 1; 527 sc->sf_want_auto = 0; 528 return; 529 break; 530 case SF_FLAG_DELAYTIMEO: 531 ifp->if_timer = 0; 532 sc->sf_autoneg = 0; 533 break; 534 default: 535 printf("sf%d: invalid autoneg flag: %d\n", sc->sf_unit, flag); 536 return; 537 } 538 539 if (sf_phy_readreg(sc, PHY_BMSR) & PHY_BMSR_AUTONEGCOMP) { 540 if (verbose) 541 printf("sf%d: autoneg complete, ", sc->sf_unit); 542 phy_sts = sf_phy_readreg(sc, PHY_BMSR); 543 } else { 544 if (verbose) 545 printf("sf%d: autoneg not complete, ", sc->sf_unit); 546 } 547 548 media = sf_phy_readreg(sc, PHY_BMCR); 549 550 /* Link is good. Report modes and set duplex mode. */ 551 if (sf_phy_readreg(sc, PHY_BMSR) & PHY_BMSR_LINKSTAT) { 552 if (verbose) 553 printf("link status good "); 554 advert = sf_phy_readreg(sc, PHY_ANAR); 555 ability = sf_phy_readreg(sc, PHY_LPAR); 556 557 if (advert & PHY_ANAR_100BT4 && ability & PHY_ANAR_100BT4) { 558 ifm->ifm_media = IFM_ETHER|IFM_100_T4; 559 media |= PHY_BMCR_SPEEDSEL; 560 media &= ~PHY_BMCR_DUPLEX; 561 printf("(100baseT4)\n"); 562 } else if (advert & PHY_ANAR_100BTXFULL && 563 ability & PHY_ANAR_100BTXFULL) { 564 ifm->ifm_media = IFM_ETHER|IFM_100_TX|IFM_FDX; 565 media |= PHY_BMCR_SPEEDSEL; 566 media |= PHY_BMCR_DUPLEX; 567 printf("(full-duplex, 100Mbps)\n"); 568 } else if (advert & PHY_ANAR_100BTXHALF && 569 ability & PHY_ANAR_100BTXHALF) { 570 ifm->ifm_media = IFM_ETHER|IFM_100_TX|IFM_HDX; 571 media |= PHY_BMCR_SPEEDSEL; 572 media &= ~PHY_BMCR_DUPLEX; 573 printf("(half-duplex, 100Mbps)\n"); 574 } else if (advert & PHY_ANAR_10BTFULL && 575 ability & PHY_ANAR_10BTFULL) { 576 ifm->ifm_media = IFM_ETHER|IFM_10_T|IFM_FDX; 577 media &= ~PHY_BMCR_SPEEDSEL; 578 media |= PHY_BMCR_DUPLEX; 579 printf("(full-duplex, 10Mbps)\n"); 580 } else if (advert & PHY_ANAR_10BTHALF && 581 ability & PHY_ANAR_10BTHALF) { 582 ifm->ifm_media = IFM_ETHER|IFM_10_T|IFM_HDX; 583 media &= ~PHY_BMCR_SPEEDSEL; 584 media &= ~PHY_BMCR_DUPLEX; 585 printf("(half-duplex, 10Mbps)\n"); 586 } 587 588 media &= ~PHY_BMCR_AUTONEGENBL; 589 590 /* Set ASIC's duplex mode to match the PHY. */ 591 sf_phy_writereg(sc, PHY_BMCR, media); 592 if ((media & IFM_GMASK) == IFM_FDX) { 593 SF_SETBIT(sc, SF_MACCFG_1, SF_MACCFG1_FULLDUPLEX); 594 } else { 595 SF_CLRBIT(sc, SF_MACCFG_1, SF_MACCFG1_FULLDUPLEX); 596 } 597 } else { 598 if (verbose) 599 printf("no carrier\n"); 600 } 601 602 sf_init(sc); 603 604 if (sc->sf_tx_pend) { 605 sc->sf_autoneg = 0; 606 sc->sf_tx_pend = 0; 607 sf_start(ifp); 608 } 609 610 return; 611} 612 613static void sf_getmode_mii(sc) 614 struct sf_softc *sc; 615{ 616 u_int16_t bmsr; 617 struct ifnet *ifp; 618 619 ifp = &sc->arpcom.ac_if; 620 621 bmsr = sf_phy_readreg(sc, PHY_BMSR); 622 if (bootverbose) 623 printf("sf%d: PHY status word: %x\n", sc->sf_unit, bmsr); 624 625 /* fallback */ 626 sc->ifmedia.ifm_media = IFM_ETHER|IFM_10_T|IFM_HDX; 627 628 if (bmsr & PHY_BMSR_10BTHALF) { 629 if (bootverbose) 630 printf("sf%d: 10Mbps half-duplex mode supported\n", 631 sc->sf_unit); 632 ifmedia_add(&sc->ifmedia, 633 IFM_ETHER|IFM_10_T|IFM_HDX, 0, NULL); 634 ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_10_T, 0, NULL); 635 } 636 637 if (bmsr & PHY_BMSR_10BTFULL) { 638 if (bootverbose) 639 printf("sf%d: 10Mbps full-duplex mode supported\n", 640 sc->sf_unit); 641 ifmedia_add(&sc->ifmedia, 642 IFM_ETHER|IFM_10_T|IFM_FDX, 0, NULL); 643 sc->ifmedia.ifm_media = IFM_ETHER|IFM_10_T|IFM_FDX; 644 } 645 646 if (bmsr & PHY_BMSR_100BTXHALF) { 647 if (bootverbose) 648 printf("sf%d: 100Mbps half-duplex mode supported\n", 649 sc->sf_unit); 650 ifp->if_baudrate = 100000000; 651 ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_100_TX, 0, NULL); 652 ifmedia_add(&sc->ifmedia, 653 IFM_ETHER|IFM_100_TX|IFM_HDX, 0, NULL); 654 sc->ifmedia.ifm_media = IFM_ETHER|IFM_100_TX|IFM_HDX; 655 } 656 657 if (bmsr & PHY_BMSR_100BTXFULL) { 658 if (bootverbose) 659 printf("sf%d: 100Mbps full-duplex mode supported\n", 660 sc->sf_unit); 661 ifp->if_baudrate = 100000000; 662 ifmedia_add(&sc->ifmedia, 663 IFM_ETHER|IFM_100_TX|IFM_FDX, 0, NULL); 664 sc->ifmedia.ifm_media = IFM_ETHER|IFM_100_TX|IFM_FDX; 665 } 666 667 /* Some also support 100BaseT4. */ 668 if (bmsr & PHY_BMSR_100BT4) { 669 if (bootverbose) 670 printf("sf%d: 100baseT4 mode supported\n", sc->sf_unit); 671 ifp->if_baudrate = 100000000; 672 ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_100_T4, 0, NULL); 673 sc->ifmedia.ifm_media = IFM_ETHER|IFM_100_T4; 674#ifdef FORCE_AUTONEG_TFOUR 675 if (bootverbose) 676 printf("sf%d: forcing on autoneg support for BT4\n", 677 sc->sf_unit); 678 ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_AUTO, 0 NULL): 679 sc->ifmedia.ifm_media = IFM_ETHER|IFM_AUTO; 680#endif 681 } 682 683 if (bmsr & PHY_BMSR_CANAUTONEG) { 684 if (bootverbose) 685 printf("sf%d: autoneg supported\n", sc->sf_unit); 686 ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_AUTO, 0, NULL); 687 sc->ifmedia.ifm_media = IFM_ETHER|IFM_AUTO; 688 } 689 690 return; 691} 692 693/* 694 * Set speed and duplex mode. 695 */ 696static void sf_setmode_mii(sc, media) 697 struct sf_softc *sc; 698 int media; 699{ 700 u_int16_t bmcr; 701 struct ifnet *ifp; 702 703 ifp = &sc->arpcom.ac_if; 704 705 /* 706 * If an autoneg session is in progress, stop it. 707 */ 708 if (sc->sf_autoneg) { 709 printf("sf%d: canceling autoneg session\n", sc->sf_unit); 710 ifp->if_timer = sc->sf_autoneg = sc->sf_want_auto = 0; 711 bmcr = sf_phy_readreg(sc, PHY_BMCR); 712 bmcr &= ~PHY_BMCR_AUTONEGENBL; 713 sf_phy_writereg(sc, PHY_BMCR, bmcr); 714 } 715 716 printf("sf%d: selecting MII, ", sc->sf_unit); 717 718 bmcr = sf_phy_readreg(sc, PHY_BMCR); 719 720 bmcr &= ~(PHY_BMCR_AUTONEGENBL|PHY_BMCR_SPEEDSEL| 721 PHY_BMCR_DUPLEX|PHY_BMCR_LOOPBK); 722 723 if (IFM_SUBTYPE(media) == IFM_100_T4) { 724 printf("100Mbps/T4, half-duplex\n"); 725 bmcr |= PHY_BMCR_SPEEDSEL; 726 bmcr &= ~PHY_BMCR_DUPLEX; 727 } 728 729 if (IFM_SUBTYPE(media) == IFM_100_TX) { 730 printf("100Mbps, "); 731 bmcr |= PHY_BMCR_SPEEDSEL; 732 } 733 734 if (IFM_SUBTYPE(media) == IFM_10_T) { 735 printf("10Mbps, "); 736 bmcr &= ~PHY_BMCR_SPEEDSEL; 737 } 738 739 if ((media & IFM_GMASK) == IFM_FDX) { 740 printf("full duplex\n"); 741 bmcr |= PHY_BMCR_DUPLEX; 742 SF_SETBIT(sc, SF_MACCFG_1, SF_MACCFG1_FULLDUPLEX); 743 } else { 744 printf("half duplex\n"); 745 bmcr &= ~PHY_BMCR_DUPLEX; 746 SF_CLRBIT(sc, SF_MACCFG_1, SF_MACCFG1_FULLDUPLEX); 747 } 748 749 sf_phy_writereg(sc, PHY_BMCR, bmcr); 750 751 return; 752} 753 754/* | |
755 * Set media options. 756 */ 757static int sf_ifmedia_upd(ifp) 758 struct ifnet *ifp; 759{ 760 struct sf_softc *sc; | 482 * Set media options. 483 */ 484static int sf_ifmedia_upd(ifp) 485 struct ifnet *ifp; 486{ 487 struct sf_softc *sc; |
761 struct ifmedia *ifm; | 488 struct mii_data *mii; |
762 763 sc = ifp->if_softc; | 489 490 sc = ifp->if_softc; |
764 ifm = &sc->ifmedia; | 491 mii = device_get_softc(sc->sf_miibus); 492 mii_mediachg(mii); |
765 | 493 |
766 if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER) 767 return(EINVAL); 768 769 if (IFM_SUBTYPE(ifm->ifm_media) == IFM_AUTO) 770 sf_autoneg_mii(sc, SF_FLAG_SCHEDDELAY, 1); 771 else { 772 sf_setmode_mii(sc, ifm->ifm_media); 773 } 774 | |
775 return(0); 776} 777 778/* 779 * Report current media status. 780 */ 781static void sf_ifmedia_sts(ifp, ifmr) 782 struct ifnet *ifp; 783 struct ifmediareq *ifmr; 784{ 785 struct sf_softc *sc; | 494 return(0); 495} 496 497/* 498 * Report current media status. 499 */ 500static void sf_ifmedia_sts(ifp, ifmr) 501 struct ifnet *ifp; 502 struct ifmediareq *ifmr; 503{ 504 struct sf_softc *sc; |
786 u_int16_t advert = 0, ability = 0; | 505 struct mii_data *mii; |
787 788 sc = ifp->if_softc; | 506 507 sc = ifp->if_softc; |
508 mii = device_get_softc(sc->sf_miibus); |
|
789 | 509 |
790 ifmr->ifm_active = IFM_ETHER; | 510 mii_pollstat(mii); 511 ifmr->ifm_active = mii->mii_media_active; 512 ifmr->ifm_status = mii->mii_media_status; |
791 | 513 |
792 if (!(sf_phy_readreg(sc, PHY_BMCR) & PHY_BMCR_AUTONEGENBL)) { 793 if (sf_phy_readreg(sc, PHY_BMCR) & PHY_BMCR_SPEEDSEL) 794 ifmr->ifm_active = IFM_ETHER|IFM_100_TX; 795 else 796 ifmr->ifm_active = IFM_ETHER|IFM_10_T; 797 if (sf_phy_readreg(sc, PHY_BMCR) & PHY_BMCR_DUPLEX) 798 ifmr->ifm_active |= IFM_FDX; 799 else 800 ifmr->ifm_active |= IFM_HDX; 801 return; 802 } 803 804 ability = sf_phy_readreg(sc, PHY_LPAR); 805 advert = sf_phy_readreg(sc, PHY_ANAR); 806 if (advert & PHY_ANAR_100BT4 && 807 ability & PHY_ANAR_100BT4) { 808 ifmr->ifm_active = IFM_ETHER|IFM_100_T4; 809 } else if (advert & PHY_ANAR_100BTXFULL && 810 ability & PHY_ANAR_100BTXFULL) { 811 ifmr->ifm_active = IFM_ETHER|IFM_100_TX|IFM_FDX; 812 } else if (advert & PHY_ANAR_100BTXHALF && 813 ability & PHY_ANAR_100BTXHALF) { 814 ifmr->ifm_active = IFM_ETHER|IFM_100_TX|IFM_HDX; 815 } else if (advert & PHY_ANAR_10BTFULL && 816 ability & PHY_ANAR_10BTFULL) { 817 ifmr->ifm_active = IFM_ETHER|IFM_10_T|IFM_FDX; 818 } else if (advert & PHY_ANAR_10BTHALF && 819 ability & PHY_ANAR_10BTHALF) { 820 ifmr->ifm_active = IFM_ETHER|IFM_10_T|IFM_HDX; 821 } 822 | |
823 return; 824} 825 826static int sf_ioctl(ifp, command, data) 827 struct ifnet *ifp; 828 u_long command; 829 caddr_t data; 830{ 831 struct sf_softc *sc = ifp->if_softc; 832 struct ifreq *ifr = (struct ifreq *) data; | 514 return; 515} 516 517static int sf_ioctl(ifp, command, data) 518 struct ifnet *ifp; 519 u_long command; 520 caddr_t data; 521{ 522 struct sf_softc *sc = ifp->if_softc; 523 struct ifreq *ifr = (struct ifreq *) data; |
524 struct mii_data *mii; |
|
833 int s, error = 0; 834 835 s = splimp(); 836 837 switch(command) { 838 case SIOCSIFADDR: 839 case SIOCGIFADDR: 840 case SIOCSIFMTU: --- 10 unchanged lines hidden (view full) --- 851 break; 852 case SIOCADDMULTI: 853 case SIOCDELMULTI: 854 sf_setmulti(sc); 855 error = 0; 856 break; 857 case SIOCGIFMEDIA: 858 case SIOCSIFMEDIA: | 525 int s, error = 0; 526 527 s = splimp(); 528 529 switch(command) { 530 case SIOCSIFADDR: 531 case SIOCGIFADDR: 532 case SIOCSIFMTU: --- 10 unchanged lines hidden (view full) --- 543 break; 544 case SIOCADDMULTI: 545 case SIOCDELMULTI: 546 sf_setmulti(sc); 547 error = 0; 548 break; 549 case SIOCGIFMEDIA: 550 case SIOCSIFMEDIA: |
859 error = ifmedia_ioctl(ifp, ifr, &sc->ifmedia, command); | 551 mii = device_get_softc(sc->sf_miibus); 552 error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command); |
860 break; 861 default: 862 error = EINVAL; 863 break; 864 } 865 866 (void)splx(s); 867 --- 88 unchanged lines hidden (view full) --- 956 */ 957static int sf_attach(dev) 958 device_t dev; 959{ 960 int s, i; 961 u_int32_t command; 962 struct sf_softc *sc; 963 struct ifnet *ifp; | 553 break; 554 default: 555 error = EINVAL; 556 break; 557 } 558 559 (void)splx(s); 560 --- 88 unchanged lines hidden (view full) --- 649 */ 650static int sf_attach(dev) 651 device_t dev; 652{ 653 int s, i; 654 u_int32_t command; 655 struct sf_softc *sc; 656 struct ifnet *ifp; |
964 int media = IFM_ETHER|IFM_100_TX|IFM_FDX; 965 struct sf_type *p; 966 u_int16_t phy_vid, phy_did, phy_sts; | |
967 int unit, rid, error = 0; 968 969 s = splimp(); 970 971 sc = device_get_softc(dev); 972 unit = device_get_unit(dev); 973 bzero(sc, sizeof(struct sf_softc)); 974 --- 99 unchanged lines hidden (view full) --- 1074 */ 1075 printf("sf%d: Ethernet address: %6D\n", unit, 1076 sc->arpcom.ac_enaddr, ":"); 1077 1078 sc->sf_unit = unit; 1079 1080 /* Allocate the descriptor queues. */ 1081 sc->sf_ldata = contigmalloc(sizeof(struct sf_list_data), M_DEVBUF, | 657 int unit, rid, error = 0; 658 659 s = splimp(); 660 661 sc = device_get_softc(dev); 662 unit = device_get_unit(dev); 663 bzero(sc, sizeof(struct sf_softc)); 664 --- 99 unchanged lines hidden (view full) --- 764 */ 765 printf("sf%d: Ethernet address: %6D\n", unit, 766 sc->arpcom.ac_enaddr, ":"); 767 768 sc->sf_unit = unit; 769 770 /* Allocate the descriptor queues. */ 771 sc->sf_ldata = contigmalloc(sizeof(struct sf_list_data), M_DEVBUF, |
1082 M_NOWAIT, 0, 0xffffffff, PAGE_SIZE, 0); | 772 M_NOWAIT, 0x100000, 0xffffffff, PAGE_SIZE, 0); |
1083 1084 if (sc->sf_ldata == NULL) { 1085 printf("sf%d: no memory for list buffers!\n", unit); 1086 bus_teardown_intr(dev, sc->sf_irq, sc->sf_intrhand); 1087 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sf_irq); 1088 bus_release_resource(dev, SF_RES, SF_RID, sc->sf_res); 1089 error = ENXIO; 1090 goto fail; 1091 } 1092 1093 bzero(sc->sf_ldata, sizeof(struct sf_list_data)); 1094 | 773 774 if (sc->sf_ldata == NULL) { 775 printf("sf%d: no memory for list buffers!\n", unit); 776 bus_teardown_intr(dev, sc->sf_irq, sc->sf_intrhand); 777 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sf_irq); 778 bus_release_resource(dev, SF_RES, SF_RID, sc->sf_res); 779 error = ENXIO; 780 goto fail; 781 } 782 783 bzero(sc->sf_ldata, sizeof(struct sf_list_data)); 784 |
1095 if (bootverbose) 1096 printf("sf%d: probing for a PHY\n", sc->sf_unit); 1097 for (i = SF_PHYADDR_MIN; i < SF_PHYADDR_MAX + 1; i++) { 1098 if (bootverbose) 1099 printf("sf%d: checking address: %d\n", 1100 sc->sf_unit, i); 1101 sc->sf_phy_addr = i; 1102 sf_phy_writereg(sc, PHY_BMCR, PHY_BMCR_RESET); 1103 DELAY(500); 1104 while(sf_phy_readreg(sc, PHY_BMCR) 1105 & PHY_BMCR_RESET); 1106 if ((phy_sts = sf_phy_readreg(sc, PHY_BMSR))) 1107 break; 1108 } 1109 if (phy_sts) { 1110 phy_vid = sf_phy_readreg(sc, PHY_VENID); 1111 phy_did = sf_phy_readreg(sc, PHY_DEVID); 1112 if (bootverbose) 1113 printf("sf%d: found PHY at address %d, ", 1114 sc->sf_unit, sc->sf_phy_addr); 1115 if (bootverbose) 1116 printf("vendor id: %x device id: %x\n", 1117 phy_vid, phy_did); 1118 p = sf_phys; 1119 while(p->sf_vid) { 1120 if (phy_vid == p->sf_vid && 1121 (phy_did | 0x000F) == p->sf_did) { 1122 sc->sf_pinfo = p; 1123 break; 1124 } 1125 p++; 1126 } 1127 if (sc->sf_pinfo == NULL) 1128 sc->sf_pinfo = &sf_phys[PHY_UNKNOWN]; 1129 if (bootverbose) 1130 printf("sf%d: PHY type: %s\n", 1131 sc->sf_unit, sc->sf_pinfo->sf_name); 1132 } else { | 785 /* Do MII setup. */ 786 if (mii_phy_probe(dev, &sc->sf_miibus, 787 sf_ifmedia_upd, sf_ifmedia_sts)) { |
1133 printf("sf%d: MII without any phy!\n", sc->sf_unit); 1134 free(sc->sf_ldata, M_DEVBUF); 1135 bus_teardown_intr(dev, sc->sf_irq, sc->sf_intrhand); 1136 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sf_irq); 1137 bus_release_resource(dev, SF_RES, SF_RID, sc->sf_res); 1138 error = ENXIO; 1139 goto fail; 1140 } --- 8 unchanged lines hidden (view full) --- 1149 ifp->if_output = ether_output; 1150 ifp->if_start = sf_start; 1151 ifp->if_watchdog = sf_watchdog; 1152 ifp->if_init = sf_init; 1153 ifp->if_baudrate = 10000000; 1154 ifp->if_snd.ifq_maxlen = SF_TX_DLIST_CNT - 1; 1155 1156 /* | 788 printf("sf%d: MII without any phy!\n", sc->sf_unit); 789 free(sc->sf_ldata, M_DEVBUF); 790 bus_teardown_intr(dev, sc->sf_irq, sc->sf_intrhand); 791 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sf_irq); 792 bus_release_resource(dev, SF_RES, SF_RID, sc->sf_res); 793 error = ENXIO; 794 goto fail; 795 } --- 8 unchanged lines hidden (view full) --- 804 ifp->if_output = ether_output; 805 ifp->if_start = sf_start; 806 ifp->if_watchdog = sf_watchdog; 807 ifp->if_init = sf_init; 808 ifp->if_baudrate = 10000000; 809 ifp->if_snd.ifq_maxlen = SF_TX_DLIST_CNT - 1; 810 811 /* |
1157 * Do ifmedia setup. 1158 */ 1159 ifmedia_init(&sc->ifmedia, 0, sf_ifmedia_upd, sf_ifmedia_sts); 1160 1161 sf_getmode_mii(sc); 1162 if (cold) { 1163 sf_autoneg_mii(sc, SF_FLAG_FORCEDELAY, 1); 1164 sf_stop(sc); 1165 } else { 1166 sf_init(sc); 1167 sf_autoneg_mii(sc, SF_FLAG_SCHEDDELAY, 1); 1168 } 1169 1170 media = sc->ifmedia.ifm_media; 1171 ifmedia_set(&sc->ifmedia, media); 1172 1173 /* | |
1174 * Call MI attach routines. 1175 */ 1176 if_attach(ifp); 1177 ether_ifattach(ifp); 1178 1179#if NBPF > 0 1180 bpfattach(ifp, DLT_EN10MB, sizeof(struct ether_header)); 1181#endif --- 13 unchanged lines hidden (view full) --- 1195 s = splimp(); 1196 1197 sc = device_get_softc(dev); 1198 ifp = &sc->arpcom.ac_if; 1199 1200 if_detach(ifp); 1201 sf_stop(sc); 1202 | 812 * Call MI attach routines. 813 */ 814 if_attach(ifp); 815 ether_ifattach(ifp); 816 817#if NBPF > 0 818 bpfattach(ifp, DLT_EN10MB, sizeof(struct ether_header)); 819#endif --- 13 unchanged lines hidden (view full) --- 833 s = splimp(); 834 835 sc = device_get_softc(dev); 836 ifp = &sc->arpcom.ac_if; 837 838 if_detach(ifp); 839 sf_stop(sc); 840 |
841 bus_generic_detach(dev); 842 device_delete_child(dev, sc->sf_miibus); 843 |
|
1203 bus_teardown_intr(dev, sc->sf_irq, sc->sf_intrhand); 1204 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sf_irq); 1205 bus_release_resource(dev, SF_RES, SF_RID, sc->sf_res); 1206 1207 free(sc->sf_ldata, M_DEVBUF); | 844 bus_teardown_intr(dev, sc->sf_irq, sc->sf_intrhand); 845 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sf_irq); 846 bus_release_resource(dev, SF_RES, SF_RID, sc->sf_res); 847 848 free(sc->sf_ldata, M_DEVBUF); |
1208 ifmedia_removeall(&sc->ifmedia); | |
1209 1210 splx(s); 1211 1212 return(0); 1213} 1214 1215static int sf_init_rx_ring(sc) 1216 struct sf_softc *sc; --- 268 unchanged lines hidden (view full) --- 1485 return; 1486} 1487 1488static void sf_init(xsc) 1489 void *xsc; 1490{ 1491 struct sf_softc *sc; 1492 struct ifnet *ifp; | 849 850 splx(s); 851 852 return(0); 853} 854 855static int sf_init_rx_ring(sc) 856 struct sf_softc *sc; --- 268 unchanged lines hidden (view full) --- 1125 return; 1126} 1127 1128static void sf_init(xsc) 1129 void *xsc; 1130{ 1131 struct sf_softc *sc; 1132 struct ifnet *ifp; |
1133 struct mii_data *mii; |
|
1493 int i, s; 1494 1495 s = splimp(); 1496 1497 sc = xsc; 1498 ifp = &sc->arpcom.ac_if; | 1134 int i, s; 1135 1136 s = splimp(); 1137 1138 sc = xsc; 1139 ifp = &sc->arpcom.ac_if; |
1140 mii = device_get_softc(sc->sf_miibus); |
|
1499 1500 sf_stop(sc); 1501 sf_reset(sc); 1502 1503 /* Init all the receive filter registers */ 1504 for (i = SF_RXFILT_PERFECT_BASE; 1505 i < (SF_RXFILT_HASH_MAX + 1); i += 4) 1506 csr_write_4(sc, i, 0); --- 61 unchanged lines hidden (view full) --- 1568 csr_write_4(sc, SF_TXDQ_CTL, 1569 SF_TXBUFDESC_TYPE0|SF_TXMINSPACE_128BYTES|SF_TXSKIPLEN_8BYTES); 1570 SF_SETBIT(sc, SF_TXDQ_CTL, SF_TXDQCTL_NODMACMP); 1571 1572 /* Enable autopadding of short TX frames. */ 1573 SF_SETBIT(sc, SF_MACCFG_1, SF_MACCFG1_AUTOPAD); 1574 1575 /* Make sure the duplex mode is set correctly. */ | 1141 1142 sf_stop(sc); 1143 sf_reset(sc); 1144 1145 /* Init all the receive filter registers */ 1146 for (i = SF_RXFILT_PERFECT_BASE; 1147 i < (SF_RXFILT_HASH_MAX + 1); i += 4) 1148 csr_write_4(sc, i, 0); --- 61 unchanged lines hidden (view full) --- 1210 csr_write_4(sc, SF_TXDQ_CTL, 1211 SF_TXBUFDESC_TYPE0|SF_TXMINSPACE_128BYTES|SF_TXSKIPLEN_8BYTES); 1212 SF_SETBIT(sc, SF_TXDQ_CTL, SF_TXDQCTL_NODMACMP); 1213 1214 /* Enable autopadding of short TX frames. */ 1215 SF_SETBIT(sc, SF_MACCFG_1, SF_MACCFG1_AUTOPAD); 1216 1217 /* Make sure the duplex mode is set correctly. */ |
1576 if ((sc->ifmedia.ifm_media & IFM_GMASK) == IFM_FDX) { | 1218 if ((mii->mii_media.ifm_media & IFM_GMASK) == IFM_FDX) { |
1577 SF_SETBIT(sc, SF_MACCFG_1, SF_MACCFG1_FULLDUPLEX); 1578 } else { 1579 SF_CLRBIT(sc, SF_MACCFG_1, SF_MACCFG1_FULLDUPLEX); 1580 } 1581 1582 /* Enable interrupts. */ 1583 csr_write_4(sc, SF_IMR, SF_INTRS); 1584 SF_SETBIT(sc, SF_PCI_DEVCFG, SF_PCIDEVCFG_INTR_ENB); 1585 1586 /* Enable the RX and TX engines. */ 1587 SF_SETBIT(sc, SF_GEN_ETH_CTL, SF_ETHCTL_RX_ENB|SF_ETHCTL_RXDMA_ENB); 1588 SF_SETBIT(sc, SF_GEN_ETH_CTL, SF_ETHCTL_TX_ENB|SF_ETHCTL_TXDMA_ENB); 1589 | 1219 SF_SETBIT(sc, SF_MACCFG_1, SF_MACCFG1_FULLDUPLEX); 1220 } else { 1221 SF_CLRBIT(sc, SF_MACCFG_1, SF_MACCFG1_FULLDUPLEX); 1222 } 1223 1224 /* Enable interrupts. */ 1225 csr_write_4(sc, SF_IMR, SF_INTRS); 1226 SF_SETBIT(sc, SF_PCI_DEVCFG, SF_PCIDEVCFG_INTR_ENB); 1227 1228 /* Enable the RX and TX engines. */ 1229 SF_SETBIT(sc, SF_GEN_ETH_CTL, SF_ETHCTL_RX_ENB|SF_ETHCTL_RXDMA_ENB); 1230 SF_SETBIT(sc, SF_GEN_ETH_CTL, SF_ETHCTL_TX_ENB|SF_ETHCTL_TXDMA_ENB); 1231 |
1232 mii_mediachg(mii); 1233 |
|
1590 ifp->if_flags |= IFF_RUNNING; 1591 ifp->if_flags &= ~IFF_OACTIVE; 1592 1593 sc->sf_stat_ch = timeout(sf_stats_update, sc, hz); 1594 1595 splx(s); 1596 1597 return; --- 70 unchanged lines hidden (view full) --- 1668 struct mbuf *m_head = NULL; 1669 int i, txprod; 1670 1671 sc = ifp->if_softc; 1672 1673 if (ifp->if_flags & IFF_OACTIVE) 1674 return; 1675 | 1234 ifp->if_flags |= IFF_RUNNING; 1235 ifp->if_flags &= ~IFF_OACTIVE; 1236 1237 sc->sf_stat_ch = timeout(sf_stats_update, sc, hz); 1238 1239 splx(s); 1240 1241 return; --- 70 unchanged lines hidden (view full) --- 1312 struct mbuf *m_head = NULL; 1313 int i, txprod; 1314 1315 sc = ifp->if_softc; 1316 1317 if (ifp->if_flags & IFF_OACTIVE) 1318 return; 1319 |
1676 if (sc->sf_autoneg) { 1677 sc->sf_tx_pend = 1; 1678 return; 1679 } 1680 | |
1681 txprod = csr_read_4(sc, SF_TXDQ_PRODIDX); 1682 i = SF_IDX_HI(txprod) >> 4; 1683 1684 while(sc->sf_ldata->sf_tx_dlist[i].sf_mbuf == NULL) { 1685 IF_DEQUEUE(&ifp->if_snd, m_head); 1686 if (m_head == NULL) 1687 break; 1688 --- 74 unchanged lines hidden (view full) --- 1763 * indirect data register, the contents of the address register could 1764 * be changed out from under us. 1765 */ 1766static void sf_stats_update(xsc) 1767 void *xsc; 1768{ 1769 struct sf_softc *sc; 1770 struct ifnet *ifp; | 1320 txprod = csr_read_4(sc, SF_TXDQ_PRODIDX); 1321 i = SF_IDX_HI(txprod) >> 4; 1322 1323 while(sc->sf_ldata->sf_tx_dlist[i].sf_mbuf == NULL) { 1324 IF_DEQUEUE(&ifp->if_snd, m_head); 1325 if (m_head == NULL) 1326 break; 1327 --- 74 unchanged lines hidden (view full) --- 1402 * indirect data register, the contents of the address register could 1403 * be changed out from under us. 1404 */ 1405static void sf_stats_update(xsc) 1406 void *xsc; 1407{ 1408 struct sf_softc *sc; 1409 struct ifnet *ifp; |
1410 struct mii_data *mii; |
|
1771 struct sf_stats stats; 1772 u_int32_t *ptr; 1773 int i, s; 1774 1775 s = splimp(); 1776 1777 sc = xsc; 1778 ifp = &sc->arpcom.ac_if; | 1411 struct sf_stats stats; 1412 u_int32_t *ptr; 1413 int i, s; 1414 1415 s = splimp(); 1416 1417 sc = xsc; 1418 ifp = &sc->arpcom.ac_if; |
1419 mii = device_get_softc(sc->sf_miibus); |
|
1779 1780 ptr = (u_int32_t *)&stats; 1781 for (i = 0; i < sizeof(stats)/sizeof(u_int32_t); i++) 1782 ptr[i] = csr_read_4(sc, SF_STATS_BASE + 1783 (i + sizeof(u_int32_t))); 1784 1785 for (i = 0; i < sizeof(stats)/sizeof(u_int32_t); i++) 1786 csr_write_4(sc, SF_STATS_BASE + 1787 (i + sizeof(u_int32_t)), 0); 1788 1789 ifp->if_collisions += stats.sf_tx_single_colls + 1790 stats.sf_tx_multi_colls + stats.sf_tx_excess_colls; 1791 | 1420 1421 ptr = (u_int32_t *)&stats; 1422 for (i = 0; i < sizeof(stats)/sizeof(u_int32_t); i++) 1423 ptr[i] = csr_read_4(sc, SF_STATS_BASE + 1424 (i + sizeof(u_int32_t))); 1425 1426 for (i = 0; i < sizeof(stats)/sizeof(u_int32_t); i++) 1427 csr_write_4(sc, SF_STATS_BASE + 1428 (i + sizeof(u_int32_t)), 0); 1429 1430 ifp->if_collisions += stats.sf_tx_single_colls + 1431 stats.sf_tx_multi_colls + stats.sf_tx_excess_colls; 1432 |
1433 mii_tick(mii); 1434 |
|
1792 sc->sf_stat_ch = timeout(sf_stats_update, sc, hz); 1793 1794 splx(s); 1795 1796 return; 1797} 1798 1799static void sf_watchdog(ifp) 1800 struct ifnet *ifp; 1801{ 1802 struct sf_softc *sc; 1803 1804 sc = ifp->if_softc; 1805 | 1435 sc->sf_stat_ch = timeout(sf_stats_update, sc, hz); 1436 1437 splx(s); 1438 1439 return; 1440} 1441 1442static void sf_watchdog(ifp) 1443 struct ifnet *ifp; 1444{ 1445 struct sf_softc *sc; 1446 1447 sc = ifp->if_softc; 1448 |
1806 if (sc->sf_autoneg) { 1807 sf_autoneg_mii(sc, SF_FLAG_DELAYTIMEO, 1); 1808 if (!(ifp->if_flags & IFF_UP)) 1809 sf_stop(sc); 1810 return; 1811 } 1812 | |
1813 ifp->if_oerrors++; 1814 printf("sf%d: watchdog timeout\n", sc->sf_unit); 1815 | 1449 ifp->if_oerrors++; 1450 printf("sf%d: watchdog timeout\n", sc->sf_unit); 1451 |
1816 if (sc->sf_pinfo != NULL) { 1817 if (!(sf_phy_readreg(sc, PHY_BMSR) & PHY_BMSR_LINKSTAT)) 1818 printf("sf%d: no carrier - transceiver " 1819 "cable problem?\n", sc->sf_unit); 1820 } 1821 | |
1822 sf_stop(sc); 1823 sf_reset(sc); 1824 sf_init(sc); 1825 1826 if (ifp->if_snd.ifq_head != NULL) 1827 sf_start(ifp); 1828 1829 return; --- 13 unchanged lines hidden --- | 1452 sf_stop(sc); 1453 sf_reset(sc); 1454 sf_init(sc); 1455 1456 if (ifp->if_snd.ifq_head != NULL) 1457 sf_start(ifp); 1458 1459 return; --- 13 unchanged lines hidden --- |