if_my.c (148887) | if_my.c (148945) |
---|---|
1/*- 2 * Written by: yen_cw@myson.com.tw 3 * Copyright (c) 2002 Myson Technology Inc. 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 14 unchanged lines hidden (view full) --- 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * 27 * Myson fast ethernet PCI NIC driver, available at: http://www.myson.com.tw/ 28 */ 29 30#include <sys/cdefs.h> | 1/*- 2 * Written by: yen_cw@myson.com.tw 3 * Copyright (c) 2002 Myson Technology Inc. 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 14 unchanged lines hidden (view full) --- 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * 27 * Myson fast ethernet PCI NIC driver, available at: http://www.myson.com.tw/ 28 */ 29 30#include <sys/cdefs.h> |
31__FBSDID("$FreeBSD: head/sys/dev/my/if_my.c 148887 2005-08-09 10:20:02Z rwatson $"); | 31__FBSDID("$FreeBSD: head/sys/dev/my/if_my.c 148945 2005-08-10 20:15:56Z jhb $"); |
32 33#include <sys/param.h> 34#include <sys/systm.h> 35#include <sys/sockio.h> 36#include <sys/mbuf.h> 37#include <sys/malloc.h> 38#include <sys/kernel.h> 39#include <sys/socket.h> --- 181 unchanged lines hidden (view full) --- 221 miir &= ~MY_MASK_MIIR_MII_WRITE; 222 } 223 224 MY_UNLOCK(sc); 225 return miir; 226} 227 228 | 32 33#include <sys/param.h> 34#include <sys/systm.h> 35#include <sys/sockio.h> 36#include <sys/mbuf.h> 37#include <sys/malloc.h> 38#include <sys/kernel.h> 39#include <sys/socket.h> --- 181 unchanged lines hidden (view full) --- 221 miir &= ~MY_MASK_MIIR_MII_WRITE; 222 } 223 224 MY_UNLOCK(sc); 225 return miir; 226} 227 228 |
229static u_int16_t | 229static u_int16_t |
230my_phy_readreg(struct my_softc * sc, int reg) 231{ 232 long miir; 233 int mask, data; 234 235 MY_LOCK(sc); 236 237 if (sc->my_info->my_did == MTD803ID) --- 177 unchanged lines hidden (view full) --- 415#ifndef FORCE_AUTONEG_TFOUR 416 /* 417 * First, see if autoneg is supported. If not, there's no point in 418 * continuing. 419 */ 420 phy_sts = my_phy_readreg(sc, PHY_BMSR); 421 if (!(phy_sts & PHY_BMSR_CANAUTONEG)) { 422 if (verbose) | 230my_phy_readreg(struct my_softc * sc, int reg) 231{ 232 long miir; 233 int mask, data; 234 235 MY_LOCK(sc); 236 237 if (sc->my_info->my_did == MTD803ID) --- 177 unchanged lines hidden (view full) --- 415#ifndef FORCE_AUTONEG_TFOUR 416 /* 417 * First, see if autoneg is supported. If not, there's no point in 418 * continuing. 419 */ 420 phy_sts = my_phy_readreg(sc, PHY_BMSR); 421 if (!(phy_sts & PHY_BMSR_CANAUTONEG)) { 422 if (verbose) |
423 printf("my%d: autonegotiation not supported\n", 424 sc->my_unit); | 423 if_printf(ifp, "autonegotiation not supported\n"); |
425 ifm->ifm_media = IFM_ETHER | IFM_10_T | IFM_HDX; 426 MY_UNLOCK(sc); 427 return; 428 } 429#endif 430 switch (flag) { 431 case MY_FLAG_FORCEDELAY: 432 /* --- 23 unchanged lines hidden (view full) --- 456 sc->my_want_auto = 0; 457 MY_UNLOCK(sc); 458 return; 459 case MY_FLAG_DELAYTIMEO: 460 ifp->if_timer = 0; 461 sc->my_autoneg = 0; 462 break; 463 default: | 424 ifm->ifm_media = IFM_ETHER | IFM_10_T | IFM_HDX; 425 MY_UNLOCK(sc); 426 return; 427 } 428#endif 429 switch (flag) { 430 case MY_FLAG_FORCEDELAY: 431 /* --- 23 unchanged lines hidden (view full) --- 455 sc->my_want_auto = 0; 456 MY_UNLOCK(sc); 457 return; 458 case MY_FLAG_DELAYTIMEO: 459 ifp->if_timer = 0; 460 sc->my_autoneg = 0; 461 break; 462 default: |
464 printf("my%d: invalid autoneg flag: %d\n", sc->my_unit, flag); 465 MY_UNLOCK(sc); | 463 if_printf(ifp, "invalid autoneg flag: %d\n", flag); |
466 return; 467 } 468 469 if (my_phy_readreg(sc, PHY_BMSR) & PHY_BMSR_AUTONEGCOMP) { 470 if (verbose) | 464 return; 465 } 466 467 if (my_phy_readreg(sc, PHY_BMSR) & PHY_BMSR_AUTONEGCOMP) { 468 if (verbose) |
471 printf("my%d: autoneg complete, ", sc->my_unit); | 469 if_printf(ifp, "autoneg complete, "); |
472 phy_sts = my_phy_readreg(sc, PHY_BMSR); 473 } else { 474 if (verbose) | 470 phy_sts = my_phy_readreg(sc, PHY_BMSR); 471 } else { 472 if (verbose) |
475 printf("my%d: autoneg not complete, ", sc->my_unit); | 473 if_printf(ifp, "autoneg not complete, "); |
476 } 477 478 media = my_phy_readreg(sc, PHY_BMCR); 479 480 /* Link is good. Report modes and set duplex mode. */ 481 if (my_phy_readreg(sc, PHY_BMSR) & PHY_BMSR_LINKSTAT) { 482 if (verbose) | 474 } 475 476 media = my_phy_readreg(sc, PHY_BMCR); 477 478 /* Link is good. Report modes and set duplex mode. */ 479 if (my_phy_readreg(sc, PHY_BMSR) & PHY_BMSR_LINKSTAT) { 480 if (verbose) |
483 printf("my%d: link status good. ", sc->my_unit); | 481 if_printf(ifp, "link status good. "); |
484 advert = my_phy_readreg(sc, PHY_ANAR); 485 ability = my_phy_readreg(sc, PHY_LPAR); 486 if ((sc->my_pinfo->my_vid == MarvellPHYID0) || 487 (sc->my_pinfo->my_vid == LevelOnePHYID0)) { 488 ability2 = my_phy_readreg(sc, PHY_1000SR); 489 if (ability2 & PHY_1000SR_1000BTXFULL) { 490 advert = 0; 491 ability = 0; --- 53 unchanged lines hidden (view full) --- 545 } 546 media &= ~PHY_BMCR_AUTONEGENBL; 547 548 /* Set ASIC's duplex mode to match the PHY. */ 549 my_phy_writereg(sc, PHY_BMCR, media); 550 my_setcfg(sc, media); 551 } else { 552 if (verbose) | 482 advert = my_phy_readreg(sc, PHY_ANAR); 483 ability = my_phy_readreg(sc, PHY_LPAR); 484 if ((sc->my_pinfo->my_vid == MarvellPHYID0) || 485 (sc->my_pinfo->my_vid == LevelOnePHYID0)) { 486 ability2 = my_phy_readreg(sc, PHY_1000SR); 487 if (ability2 & PHY_1000SR_1000BTXFULL) { 488 advert = 0; 489 ability = 0; --- 53 unchanged lines hidden (view full) --- 543 } 544 media &= ~PHY_BMCR_AUTONEGENBL; 545 546 /* Set ASIC's duplex mode to match the PHY. */ 547 my_phy_writereg(sc, PHY_BMCR, media); 548 my_setcfg(sc, media); 549 } else { 550 if (verbose) |
553 printf("my%d: no carrier\n", sc->my_unit); | 551 if_printf(ifp, "no carrier\n"); |
554 } 555 556 my_init(sc); 557 if (sc->my_tx_pend) { 558 sc->my_autoneg = 0; 559 sc->my_tx_pend = 0; 560 my_start(ifp); 561 } --- 9 unchanged lines hidden (view full) --- 571{ 572 u_int16_t bmsr; 573 struct ifnet *ifp; 574 575 MY_LOCK(sc); 576 ifp = sc->my_ifp; 577 bmsr = my_phy_readreg(sc, PHY_BMSR); 578 if (bootverbose) | 552 } 553 554 my_init(sc); 555 if (sc->my_tx_pend) { 556 sc->my_autoneg = 0; 557 sc->my_tx_pend = 0; 558 my_start(ifp); 559 } --- 9 unchanged lines hidden (view full) --- 569{ 570 u_int16_t bmsr; 571 struct ifnet *ifp; 572 573 MY_LOCK(sc); 574 ifp = sc->my_ifp; 575 bmsr = my_phy_readreg(sc, PHY_BMSR); 576 if (bootverbose) |
579 printf("my%d: PHY status word: %x\n", sc->my_unit, bmsr); | 577 if_printf(ifp, "PHY status word: %x\n", bmsr); |
580 581 /* fallback */ 582 sc->ifmedia.ifm_media = IFM_ETHER | IFM_10_T | IFM_HDX; 583 584 if (bmsr & PHY_BMSR_10BTHALF) { 585 if (bootverbose) | 578 579 /* fallback */ 580 sc->ifmedia.ifm_media = IFM_ETHER | IFM_10_T | IFM_HDX; 581 582 if (bmsr & PHY_BMSR_10BTHALF) { 583 if (bootverbose) |
586 printf("my%d: 10Mbps half-duplex mode supported\n", 587 sc->my_unit); | 584 if_printf(ifp, "10Mbps half-duplex mode supported\n"); |
588 ifmedia_add(&sc->ifmedia, IFM_ETHER | IFM_10_T | IFM_HDX, 589 0, NULL); 590 ifmedia_add(&sc->ifmedia, IFM_ETHER | IFM_10_T, 0, NULL); 591 } 592 if (bmsr & PHY_BMSR_10BTFULL) { 593 if (bootverbose) | 585 ifmedia_add(&sc->ifmedia, IFM_ETHER | IFM_10_T | IFM_HDX, 586 0, NULL); 587 ifmedia_add(&sc->ifmedia, IFM_ETHER | IFM_10_T, 0, NULL); 588 } 589 if (bmsr & PHY_BMSR_10BTFULL) { 590 if (bootverbose) |
594 printf("my%d: 10Mbps full-duplex mode supported\n", 595 sc->my_unit); | 591 if_printf(ifp, "10Mbps full-duplex mode supported\n"); |
596 597 ifmedia_add(&sc->ifmedia, IFM_ETHER | IFM_10_T | IFM_FDX, 598 0, NULL); 599 sc->ifmedia.ifm_media = IFM_ETHER | IFM_10_T | IFM_FDX; 600 } 601 if (bmsr & PHY_BMSR_100BTXHALF) { 602 if (bootverbose) | 592 593 ifmedia_add(&sc->ifmedia, IFM_ETHER | IFM_10_T | IFM_FDX, 594 0, NULL); 595 sc->ifmedia.ifm_media = IFM_ETHER | IFM_10_T | IFM_FDX; 596 } 597 if (bmsr & PHY_BMSR_100BTXHALF) { 598 if (bootverbose) |
603 printf("my%d: 100Mbps half-duplex mode supported\n", 604 sc->my_unit); | 599 if_printf(ifp, "100Mbps half-duplex mode supported\n"); |
605 ifp->if_baudrate = 100000000; 606 ifmedia_add(&sc->ifmedia, IFM_ETHER | IFM_100_TX, 0, NULL); 607 ifmedia_add(&sc->ifmedia, IFM_ETHER | IFM_100_TX | IFM_HDX, 608 0, NULL); 609 sc->ifmedia.ifm_media = IFM_ETHER | IFM_100_TX | IFM_HDX; 610 } 611 if (bmsr & PHY_BMSR_100BTXFULL) { 612 if (bootverbose) | 600 ifp->if_baudrate = 100000000; 601 ifmedia_add(&sc->ifmedia, IFM_ETHER | IFM_100_TX, 0, NULL); 602 ifmedia_add(&sc->ifmedia, IFM_ETHER | IFM_100_TX | IFM_HDX, 603 0, NULL); 604 sc->ifmedia.ifm_media = IFM_ETHER | IFM_100_TX | IFM_HDX; 605 } 606 if (bmsr & PHY_BMSR_100BTXFULL) { 607 if (bootverbose) |
613 printf("my%d: 100Mbps full-duplex mode supported\n", 614 sc->my_unit); | 608 if_printf(ifp, "100Mbps full-duplex mode supported\n"); |
615 ifp->if_baudrate = 100000000; 616 ifmedia_add(&sc->ifmedia, IFM_ETHER | IFM_100_TX | IFM_FDX, 617 0, NULL); 618 sc->ifmedia.ifm_media = IFM_ETHER | IFM_100_TX | IFM_FDX; 619 } 620 /* Some also support 100BaseT4. */ 621 if (bmsr & PHY_BMSR_100BT4) { 622 if (bootverbose) | 609 ifp->if_baudrate = 100000000; 610 ifmedia_add(&sc->ifmedia, IFM_ETHER | IFM_100_TX | IFM_FDX, 611 0, NULL); 612 sc->ifmedia.ifm_media = IFM_ETHER | IFM_100_TX | IFM_FDX; 613 } 614 /* Some also support 100BaseT4. */ 615 if (bmsr & PHY_BMSR_100BT4) { 616 if (bootverbose) |
623 printf("my%d: 100baseT4 mode supported\n", sc->my_unit); | 617 if_printf(ifp, "100baseT4 mode supported\n"); |
624 ifp->if_baudrate = 100000000; 625 ifmedia_add(&sc->ifmedia, IFM_ETHER | IFM_100_T4, 0, NULL); 626 sc->ifmedia.ifm_media = IFM_ETHER | IFM_100_T4; 627#ifdef FORCE_AUTONEG_TFOUR 628 if (bootverbose) | 618 ifp->if_baudrate = 100000000; 619 ifmedia_add(&sc->ifmedia, IFM_ETHER | IFM_100_T4, 0, NULL); 620 sc->ifmedia.ifm_media = IFM_ETHER | IFM_100_T4; 621#ifdef FORCE_AUTONEG_TFOUR 622 if (bootverbose) |
629 printf("my%d: forcing on autoneg support for BT4\n", 630 sc->my_unit); | 623 if_printf(ifp, "forcing on autoneg support for BT4\n"); |
631 ifmedia_add(&sc->ifmedia, IFM_ETHER | IFM_AUTO, 0 NULL): 632 sc->ifmedia.ifm_media = IFM_ETHER | IFM_AUTO; 633#endif 634 } 635#if 0 /* this version did not support 1000M, */ 636 if (sc->my_pinfo->my_vid == MarvellPHYID0) { 637 if (bootverbose) | 624 ifmedia_add(&sc->ifmedia, IFM_ETHER | IFM_AUTO, 0 NULL): 625 sc->ifmedia.ifm_media = IFM_ETHER | IFM_AUTO; 626#endif 627 } 628#if 0 /* this version did not support 1000M, */ 629 if (sc->my_pinfo->my_vid == MarvellPHYID0) { 630 if (bootverbose) |
638 printf("my%d: 1000Mbps half-duplex mode supported\n", 639 sc->my_unit); | 631 if_printf(ifp, "1000Mbps half-duplex mode supported\n"); |
640 641 ifp->if_baudrate = 1000000000; 642 ifmedia_add(&sc->ifmedia, IFM_ETHER | IFM_1000_T, 0, NULL); 643 ifmedia_add(&sc->ifmedia, IFM_ETHER | IFM_1000_T | IFM_HDX, 644 0, NULL); 645 if (bootverbose) | 632 633 ifp->if_baudrate = 1000000000; 634 ifmedia_add(&sc->ifmedia, IFM_ETHER | IFM_1000_T, 0, NULL); 635 ifmedia_add(&sc->ifmedia, IFM_ETHER | IFM_1000_T | IFM_HDX, 636 0, NULL); 637 if (bootverbose) |
646 printf("my%d: 1000Mbps full-duplex mode supported\n", 647 sc->my_unit); | 638 if_printf(ifp, "1000Mbps full-duplex mode supported\n"); |
648 ifp->if_baudrate = 1000000000; 649 ifmedia_add(&sc->ifmedia, IFM_ETHER | IFM_1000_T | IFM_FDX, 650 0, NULL); 651 sc->ifmedia.ifm_media = IFM_ETHER | IFM_1000_T | IFM_FDX; 652 } 653#endif 654 if (bmsr & PHY_BMSR_CANAUTONEG) { 655 if (bootverbose) | 639 ifp->if_baudrate = 1000000000; 640 ifmedia_add(&sc->ifmedia, IFM_ETHER | IFM_1000_T | IFM_FDX, 641 0, NULL); 642 sc->ifmedia.ifm_media = IFM_ETHER | IFM_1000_T | IFM_FDX; 643 } 644#endif 645 if (bmsr & PHY_BMSR_CANAUTONEG) { 646 if (bootverbose) |
656 printf("my%d: autoneg supported\n", sc->my_unit); | 647 if_printf(ifp, "autoneg supported\n"); |
657 ifmedia_add(&sc->ifmedia, IFM_ETHER | IFM_AUTO, 0, NULL); 658 sc->ifmedia.ifm_media = IFM_ETHER | IFM_AUTO; 659 } 660 MY_UNLOCK(sc); 661 return; 662} 663 664/* --- 6 unchanged lines hidden (view full) --- 671 struct ifnet *ifp; 672 673 MY_LOCK(sc); 674 ifp = sc->my_ifp; 675 /* 676 * If an autoneg session is in progress, stop it. 677 */ 678 if (sc->my_autoneg) { | 648 ifmedia_add(&sc->ifmedia, IFM_ETHER | IFM_AUTO, 0, NULL); 649 sc->ifmedia.ifm_media = IFM_ETHER | IFM_AUTO; 650 } 651 MY_UNLOCK(sc); 652 return; 653} 654 655/* --- 6 unchanged lines hidden (view full) --- 662 struct ifnet *ifp; 663 664 MY_LOCK(sc); 665 ifp = sc->my_ifp; 666 /* 667 * If an autoneg session is in progress, stop it. 668 */ 669 if (sc->my_autoneg) { |
679 printf("my%d: canceling autoneg session\n", sc->my_unit); | 670 if_printf(ifp, "canceling autoneg session\n"); |
680 ifp->if_timer = sc->my_autoneg = sc->my_want_auto = 0; 681 bmcr = my_phy_readreg(sc, PHY_BMCR); 682 bmcr &= ~PHY_BMCR_AUTONEGENBL; 683 my_phy_writereg(sc, PHY_BMCR, bmcr); 684 } | 671 ifp->if_timer = sc->my_autoneg = sc->my_want_auto = 0; 672 bmcr = my_phy_readreg(sc, PHY_BMCR); 673 bmcr &= ~PHY_BMCR_AUTONEGENBL; 674 my_phy_writereg(sc, PHY_BMCR, bmcr); 675 } |
685 printf("my%d: selecting MII, ", sc->my_unit); | 676 if_printf(ifp, "selecting MII, "); |
686 bmcr = my_phy_readreg(sc, PHY_BMCR); 687 bmcr &= ~(PHY_BMCR_AUTONEGENBL | PHY_BMCR_SPEEDSEL | PHY_BMCR_1000 | 688 PHY_BMCR_DUPLEX | PHY_BMCR_LOOPBK); 689 690#if 0 /* this version did not support 1000M, */ 691 if (IFM_SUBTYPE(media) == IFM_1000_T) { 692 printf("1000Mbps/T4, half-duplex\n"); 693 bmcr &= ~PHY_BMCR_SPEEDSEL; --- 43 unchanged lines hidden (view full) --- 737 MY_CLRBIT(sc, MY_TCRRCR, (MY_TE | MY_RE)); 738 for (i = 0; i < MY_TIMEOUT; i++) { 739 DELAY(10); 740 if (!(CSR_READ_4(sc, MY_TCRRCR) & 741 (MY_TXRUN | MY_RXRUN))) 742 break; 743 } 744 if (i == MY_TIMEOUT) | 677 bmcr = my_phy_readreg(sc, PHY_BMCR); 678 bmcr &= ~(PHY_BMCR_AUTONEGENBL | PHY_BMCR_SPEEDSEL | PHY_BMCR_1000 | 679 PHY_BMCR_DUPLEX | PHY_BMCR_LOOPBK); 680 681#if 0 /* this version did not support 1000M, */ 682 if (IFM_SUBTYPE(media) == IFM_1000_T) { 683 printf("1000Mbps/T4, half-duplex\n"); 684 bmcr &= ~PHY_BMCR_SPEEDSEL; --- 43 unchanged lines hidden (view full) --- 728 MY_CLRBIT(sc, MY_TCRRCR, (MY_TE | MY_RE)); 729 for (i = 0; i < MY_TIMEOUT; i++) { 730 DELAY(10); 731 if (!(CSR_READ_4(sc, MY_TCRRCR) & 732 (MY_TXRUN | MY_RXRUN))) 733 break; 734 } 735 if (i == MY_TIMEOUT) |
745 printf("my%d: failed to force tx and rx to idle \n", 746 sc->my_unit); | 736 if_printf(sc->my_ifp, 737 "failed to force tx and rx to idle \n"); |
747 } 748 MY_CLRBIT(sc, MY_TCRRCR, MY_PS1000); 749 MY_CLRBIT(sc, MY_TCRRCR, MY_PS10); 750 if (bmcr & PHY_BMCR_1000) 751 MY_SETBIT(sc, MY_TCRRCR, MY_PS1000); 752 else if (!(bmcr & PHY_BMCR_SPEEDSEL)) 753 MY_SETBIT(sc, MY_TCRRCR, MY_PS10); 754 if (bmcr & PHY_BMCR_DUPLEX) --- 14 unchanged lines hidden (view full) --- 769 MY_LOCK(sc); 770 MY_SETBIT(sc, MY_BCR, MY_SWR); 771 for (i = 0; i < MY_TIMEOUT; i++) { 772 DELAY(10); 773 if (!(CSR_READ_4(sc, MY_BCR) & MY_SWR)) 774 break; 775 } 776 if (i == MY_TIMEOUT) | 738 } 739 MY_CLRBIT(sc, MY_TCRRCR, MY_PS1000); 740 MY_CLRBIT(sc, MY_TCRRCR, MY_PS10); 741 if (bmcr & PHY_BMCR_1000) 742 MY_SETBIT(sc, MY_TCRRCR, MY_PS1000); 743 else if (!(bmcr & PHY_BMCR_SPEEDSEL)) 744 MY_SETBIT(sc, MY_TCRRCR, MY_PS10); 745 if (bmcr & PHY_BMCR_DUPLEX) --- 14 unchanged lines hidden (view full) --- 760 MY_LOCK(sc); 761 MY_SETBIT(sc, MY_BCR, MY_SWR); 762 for (i = 0; i < MY_TIMEOUT; i++) { 763 DELAY(10); 764 if (!(CSR_READ_4(sc, MY_BCR) & MY_SWR)) 765 break; 766 } 767 if (i == MY_TIMEOUT) |
777 printf("m0x%d: reset never completed!\n", sc->my_unit); | 768 if_printf(sc->my_ifp, "reset never completed!\n"); |
778 779 /* Wait a little while for the chip to get its brains in order. */ 780 DELAY(1000); 781 MY_UNLOCK(sc); 782 return; 783} 784 785/* --- 30 unchanged lines hidden (view full) --- 816 u_int32_t command, iobase; 817 struct my_softc *sc; 818 struct ifnet *ifp; 819 int media = IFM_ETHER | IFM_100_TX | IFM_FDX; 820 unsigned int round; 821 caddr_t roundptr; 822 struct my_type *p; 823 u_int16_t phy_vid, phy_did, phy_sts = 0; | 769 770 /* Wait a little while for the chip to get its brains in order. */ 771 DELAY(1000); 772 MY_UNLOCK(sc); 773 return; 774} 775 776/* --- 30 unchanged lines hidden (view full) --- 807 u_int32_t command, iobase; 808 struct my_softc *sc; 809 struct ifnet *ifp; 810 int media = IFM_ETHER | IFM_100_TX | IFM_FDX; 811 unsigned int round; 812 caddr_t roundptr; 813 struct my_type *p; 814 u_int16_t phy_vid, phy_did, phy_sts = 0; |
824 int rid, unit, error = 0; | 815 int rid, error = 0; |
825 826 s = splimp(); 827 sc = device_get_softc(dev); | 816 817 s = splimp(); 818 sc = device_get_softc(dev); |
828 unit = device_get_unit(dev); 829 bzero(sc, sizeof(struct my_softc)); | |
830 mtx_init(&sc->my_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK, 831 MTX_DEF | MTX_RECURSE); 832 MY_LOCK(sc); 833 834 /* 835 * Map control/status registers. 836 */ 837#if 0 --- 9 unchanged lines hidden (view full) --- 847 848 if (my_info_tmp->my_did == MTD800ID) { 849 iobase = pci_read_config(dev, MY_PCI_LOIO, 4); 850 if (iobase & 0x300) 851 MY_USEIOSPACE = 0; 852 } 853 if (MY_USEIOSPACE) { 854 if (!(command & PCIM_CMD_PORTEN)) { | 819 mtx_init(&sc->my_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK, 820 MTX_DEF | MTX_RECURSE); 821 MY_LOCK(sc); 822 823 /* 824 * Map control/status registers. 825 */ 826#if 0 --- 9 unchanged lines hidden (view full) --- 836 837 if (my_info_tmp->my_did == MTD800ID) { 838 iobase = pci_read_config(dev, MY_PCI_LOIO, 4); 839 if (iobase & 0x300) 840 MY_USEIOSPACE = 0; 841 } 842 if (MY_USEIOSPACE) { 843 if (!(command & PCIM_CMD_PORTEN)) { |
855 printf("my%d: failed to enable I/O ports!\n", unit); 856 free(sc, M_DEVBUF); | 844 device_printf(dev, "failed to enable I/O ports!\n"); |
857 error = ENXIO; 858 goto fail; 859 } 860#if 0 861 if (!pci_map_port(config_id, MY_PCI_LOIO, (u_int16_t *) & (sc->my_bhandle))) { | 845 error = ENXIO; 846 goto fail; 847 } 848#if 0 849 if (!pci_map_port(config_id, MY_PCI_LOIO, (u_int16_t *) & (sc->my_bhandle))) { |
862 printf("my%d: couldn't map ports\n", unit); | 850 device_printf(dev, "couldn't map ports\n"); |
863 error = ENXIO; 864 goto fail; 865 } 866 867 sc->my_btag = I386_BUS_SPACE_IO; 868#endif 869 } else { 870 if (!(command & PCIM_CMD_MEMEN)) { | 851 error = ENXIO; 852 goto fail; 853 } 854 855 sc->my_btag = I386_BUS_SPACE_IO; 856#endif 857 } else { 858 if (!(command & PCIM_CMD_MEMEN)) { |
871 printf("my%d: failed to enable memory mapping!\n", 872 unit); | 859 device_printf(dev, "failed to enable memory mapping!\n"); |
873 error = ENXIO; 874 goto fail; 875 } 876#if 0 877 if (!pci_map_mem(config_id, MY_PCI_LOMEM, &vbase, &pbase)) { | 860 error = ENXIO; 861 goto fail; 862 } 863#if 0 864 if (!pci_map_mem(config_id, MY_PCI_LOMEM, &vbase, &pbase)) { |
878 printf ("my%d: couldn't map memory\n", unit); | 865 device_printf(dev, "couldn't map memory\n"); |
879 error = ENXIO; 880 goto fail; 881 } 882 sc->my_btag = I386_BUS_SPACE_MEM; 883 sc->my_bhandle = vbase; 884#endif 885 } 886 887 rid = MY_RID; 888 sc->my_res = bus_alloc_resource_any(dev, MY_RES, &rid, RF_ACTIVE); 889 890 if (sc->my_res == NULL) { | 866 error = ENXIO; 867 goto fail; 868 } 869 sc->my_btag = I386_BUS_SPACE_MEM; 870 sc->my_bhandle = vbase; 871#endif 872 } 873 874 rid = MY_RID; 875 sc->my_res = bus_alloc_resource_any(dev, MY_RES, &rid, RF_ACTIVE); 876 877 if (sc->my_res == NULL) { |
891 printf("my%d: couldn't map ports/memory\n", unit); | 878 device_printf(dev, "couldn't map ports/memory\n"); |
892 error = ENXIO; 893 goto fail; 894 } 895 sc->my_btag = rman_get_bustag(sc->my_res); 896 sc->my_bhandle = rman_get_bushandle(sc->my_res); 897 898 rid = 0; 899 sc->my_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, 900 RF_SHAREABLE | RF_ACTIVE); 901 902 if (sc->my_irq == NULL) { | 879 error = ENXIO; 880 goto fail; 881 } 882 sc->my_btag = rman_get_bustag(sc->my_res); 883 sc->my_bhandle = rman_get_bushandle(sc->my_res); 884 885 rid = 0; 886 sc->my_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, 887 RF_SHAREABLE | RF_ACTIVE); 888 889 if (sc->my_irq == NULL) { |
903 printf("my%d: couldn't map interrupt\n", unit); | 890 device_printf(dev, "couldn't map interrupt\n"); |
904 bus_release_resource(dev, MY_RES, MY_RID, sc->my_res); 905 error = ENXIO; 906 goto fail; 907 } 908 error = bus_setup_intr(dev, sc->my_irq, INTR_TYPE_NET, 909 my_intr, sc, &sc->my_intrhand); 910 911 if (error) { 912 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->my_irq); 913 bus_release_resource(dev, MY_RES, MY_RID, sc->my_res); | 891 bus_release_resource(dev, MY_RES, MY_RID, sc->my_res); 892 error = ENXIO; 893 goto fail; 894 } 895 error = bus_setup_intr(dev, sc->my_irq, INTR_TYPE_NET, 896 my_intr, sc, &sc->my_intrhand); 897 898 if (error) { 899 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->my_irq); 900 bus_release_resource(dev, MY_RES, MY_RID, sc->my_res); |
914 printf("my%d: couldn't set up irq\n", unit); | 901 device_printf(dev, "couldn't set up irq\n"); |
915 goto fail; 916 } 917 callout_handle_init(&sc->my_stat_ch); 918 919 sc->my_info = my_info_tmp; 920 921 /* Reset the adapter. */ 922 my_reset(sc); 923 924 /* 925 * Get station address 926 */ 927 for (i = 0; i < ETHER_ADDR_LEN; ++i) 928 eaddr[i] = CSR_READ_1(sc, MY_PAR0 + i); 929 | 902 goto fail; 903 } 904 callout_handle_init(&sc->my_stat_ch); 905 906 sc->my_info = my_info_tmp; 907 908 /* Reset the adapter. */ 909 my_reset(sc); 910 911 /* 912 * Get station address 913 */ 914 for (i = 0; i < ETHER_ADDR_LEN; ++i) 915 eaddr[i] = CSR_READ_1(sc, MY_PAR0 + i); 916 |
930 sc->my_unit = unit; 931 | |
932 sc->my_ldata_ptr = malloc(sizeof(struct my_list_data) + 8, 933 M_DEVBUF, M_NOWAIT); 934 if (sc->my_ldata_ptr == NULL) { | 917 sc->my_ldata_ptr = malloc(sizeof(struct my_list_data) + 8, 918 M_DEVBUF, M_NOWAIT); 919 if (sc->my_ldata_ptr == NULL) { |
935 free(sc, M_DEVBUF); 936 printf("my%d: no memory for list buffers!\n", unit); | 920 device_printf(dev, "no memory for list buffers!\n"); |
937 error = ENXIO; 938 goto fail; 939 } 940 sc->my_ldata = (struct my_list_data *) sc->my_ldata_ptr; 941 round = (uintptr_t)sc->my_ldata_ptr & 0xF; 942 roundptr = sc->my_ldata_ptr; 943 for (i = 0; i < 8; i++) { 944 if (round % 8) { --- 21 unchanged lines hidden (view full) --- 966 ifp->if_init = my_init; 967 ifp->if_baudrate = 10000000; 968 ifp->if_snd.ifq_maxlen = IFQ_MAXLEN; 969 970 if (sc->my_info->my_did == MTD803ID) 971 sc->my_pinfo = my_phys; 972 else { 973 if (bootverbose) | 921 error = ENXIO; 922 goto fail; 923 } 924 sc->my_ldata = (struct my_list_data *) sc->my_ldata_ptr; 925 round = (uintptr_t)sc->my_ldata_ptr & 0xF; 926 roundptr = sc->my_ldata_ptr; 927 for (i = 0; i < 8; i++) { 928 if (round % 8) { --- 21 unchanged lines hidden (view full) --- 950 ifp->if_init = my_init; 951 ifp->if_baudrate = 10000000; 952 ifp->if_snd.ifq_maxlen = IFQ_MAXLEN; 953 954 if (sc->my_info->my_did == MTD803ID) 955 sc->my_pinfo = my_phys; 956 else { 957 if (bootverbose) |
974 printf("my%d: probing for a PHY\n", sc->my_unit); | 958 device_printf(dev, "probing for a PHY\n"); |
975 for (i = MY_PHYADDR_MIN; i < MY_PHYADDR_MAX + 1; i++) { 976 if (bootverbose) | 959 for (i = MY_PHYADDR_MIN; i < MY_PHYADDR_MAX + 1; i++) { 960 if (bootverbose) |
977 printf("my%d: checking address: %d\n", 978 sc->my_unit, i); | 961 device_printf(dev, "checking address: %d\n", i); |
979 sc->my_phy_addr = i; 980 phy_sts = my_phy_readreg(sc, PHY_BMSR); 981 if ((phy_sts != 0) && (phy_sts != 0xffff)) 982 break; 983 else 984 phy_sts = 0; 985 } 986 if (phy_sts) { 987 phy_vid = my_phy_readreg(sc, PHY_VENID); 988 phy_did = my_phy_readreg(sc, PHY_DEVID); 989 if (bootverbose) { | 962 sc->my_phy_addr = i; 963 phy_sts = my_phy_readreg(sc, PHY_BMSR); 964 if ((phy_sts != 0) && (phy_sts != 0xffff)) 965 break; 966 else 967 phy_sts = 0; 968 } 969 if (phy_sts) { 970 phy_vid = my_phy_readreg(sc, PHY_VENID); 971 phy_did = my_phy_readreg(sc, PHY_DEVID); 972 if (bootverbose) { |
990 printf("my%d: found PHY at address %d, ", 991 sc->my_unit, sc->my_phy_addr); | 973 device_printf(dev, "found PHY at address %d, ", 974 sc->my_phy_addr); |
992 printf("vendor id: %x device id: %x\n", 993 phy_vid, phy_did); 994 } 995 p = my_phys; 996 while (p->my_vid) { 997 if (phy_vid == p->my_vid) { 998 sc->my_pinfo = p; 999 break; 1000 } 1001 p++; 1002 } 1003 if (sc->my_pinfo == NULL) 1004 sc->my_pinfo = &my_phys[PHY_UNKNOWN]; 1005 if (bootverbose) | 975 printf("vendor id: %x device id: %x\n", 976 phy_vid, phy_did); 977 } 978 p = my_phys; 979 while (p->my_vid) { 980 if (phy_vid == p->my_vid) { 981 sc->my_pinfo = p; 982 break; 983 } 984 p++; 985 } 986 if (sc->my_pinfo == NULL) 987 sc->my_pinfo = &my_phys[PHY_UNKNOWN]; 988 if (bootverbose) |
1006 printf("my%d: PHY type: %s\n", 1007 sc->my_unit, sc->my_pinfo->my_name); | 989 device_printf(dev, "PHY type: %s\n", 990 sc->my_pinfo->my_name); |
1008 } else { | 991 } else { |
1009 printf("my%d: MII without any phy!\n", sc->my_unit); | 992 device_printf(dev, "MII without any phy!\n"); |
1010 error = ENXIO; 1011 goto fail; 1012 } 1013 } 1014 1015 /* Do ifmedia setup. */ 1016 ifmedia_init(&sc->ifmedia, 0, my_ifmedia_upd, my_ifmedia_sts); 1017 my_getmode_mii(sc); --- 42 unchanged lines hidden (view full) --- 1060#endif 1061 1062 bus_teardown_intr(dev, sc->my_irq, sc->my_intrhand); 1063 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->my_irq); 1064 bus_release_resource(dev, MY_RES, MY_RID, sc->my_res); 1065#if 0 1066 contigfree(sc->my_cdata.my_rx_buf, MY_RXBUFLEN + 32, M_DEVBUF); 1067#endif | 993 error = ENXIO; 994 goto fail; 995 } 996 } 997 998 /* Do ifmedia setup. */ 999 ifmedia_init(&sc->ifmedia, 0, my_ifmedia_upd, my_ifmedia_sts); 1000 my_getmode_mii(sc); --- 42 unchanged lines hidden (view full) --- 1043#endif 1044 1045 bus_teardown_intr(dev, sc->my_irq, sc->my_intrhand); 1046 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->my_irq); 1047 bus_release_resource(dev, MY_RES, MY_RID, sc->my_res); 1048#if 0 1049 contigfree(sc->my_cdata.my_rx_buf, MY_RXBUFLEN + 32, M_DEVBUF); 1050#endif |
1068 free(sc, M_DEVBUF); | |
1069 MY_UNLOCK(sc); 1070 splx(s); 1071 mtx_destroy(&sc->my_mtx); 1072 return (0); 1073} 1074 1075 1076/* --- 66 unchanged lines hidden (view full) --- 1143static int 1144my_newbuf(struct my_softc * sc, struct my_chain_onefrag * c) 1145{ 1146 struct mbuf *m_new = NULL; 1147 1148 MY_LOCK(sc); 1149 MGETHDR(m_new, M_DONTWAIT, MT_DATA); 1150 if (m_new == NULL) { | 1051 MY_UNLOCK(sc); 1052 splx(s); 1053 mtx_destroy(&sc->my_mtx); 1054 return (0); 1055} 1056 1057 1058/* --- 66 unchanged lines hidden (view full) --- 1125static int 1126my_newbuf(struct my_softc * sc, struct my_chain_onefrag * c) 1127{ 1128 struct mbuf *m_new = NULL; 1129 1130 MY_LOCK(sc); 1131 MGETHDR(m_new, M_DONTWAIT, MT_DATA); 1132 if (m_new == NULL) { |
1151 printf("my%d: no memory for rx list -- packet dropped!\n", 1152 sc->my_unit); | 1133 if_printf(sc->my_ifp, 1134 "no memory for rx list -- packet dropped!\n"); |
1153 MY_UNLOCK(sc); 1154 return (ENOBUFS); 1155 } 1156 MCLGET(m_new, M_DONTWAIT); 1157 if (!(m_new->m_flags & M_EXT)) { | 1135 MY_UNLOCK(sc); 1136 return (ENOBUFS); 1137 } 1138 MCLGET(m_new, M_DONTWAIT); 1139 if (!(m_new->m_flags & M_EXT)) { |
1158 printf("my%d: no memory for rx list -- packet dropped!\n", 1159 sc->my_unit); | 1140 if_printf(sc->my_ifp, 1141 "no memory for rx list -- packet dropped!\n"); |
1160 m_freem(m_new); 1161 MY_UNLOCK(sc); 1162 return (ENOBUFS); 1163 } 1164 c->my_mbuf = m_new; 1165 c->my_ptr->my_data = vtophys(mtod(m_new, caddr_t)); 1166 c->my_ptr->my_ctl = (MCLBYTES - 1) << MY_RBSShift; 1167 c->my_ptr->my_status = MY_OWNByNIC; --- 249 unchanged lines hidden (view full) --- 1417 /* 1418 * Start packing the mbufs in this chain into the fragment pointers. 1419 * Stop when we run out of fragments or hit the end of the mbuf 1420 * chain. 1421 */ 1422 m = m_head; 1423 MGETHDR(m_new, M_DONTWAIT, MT_DATA); 1424 if (m_new == NULL) { | 1142 m_freem(m_new); 1143 MY_UNLOCK(sc); 1144 return (ENOBUFS); 1145 } 1146 c->my_mbuf = m_new; 1147 c->my_ptr->my_data = vtophys(mtod(m_new, caddr_t)); 1148 c->my_ptr->my_ctl = (MCLBYTES - 1) << MY_RBSShift; 1149 c->my_ptr->my_status = MY_OWNByNIC; --- 249 unchanged lines hidden (view full) --- 1399 /* 1400 * Start packing the mbufs in this chain into the fragment pointers. 1401 * Stop when we run out of fragments or hit the end of the mbuf 1402 * chain. 1403 */ 1404 m = m_head; 1405 MGETHDR(m_new, M_DONTWAIT, MT_DATA); 1406 if (m_new == NULL) { |
1425 printf("my%d: no memory for tx list", sc->my_unit); | 1407 if_printf(sc->my_ifp, "no memory for tx list"); |
1426 MY_UNLOCK(sc); 1427 return (1); 1428 } 1429 if (m_head->m_pkthdr.len > MHLEN) { 1430 MCLGET(m_new, M_DONTWAIT); 1431 if (!(m_new->m_flags & M_EXT)) { 1432 m_freem(m_new); | 1408 MY_UNLOCK(sc); 1409 return (1); 1410 } 1411 if (m_head->m_pkthdr.len > MHLEN) { 1412 MCLGET(m_new, M_DONTWAIT); 1413 if (!(m_new->m_flags & M_EXT)) { 1414 m_freem(m_new); |
1433 printf("my%d: no memory for tx list", sc->my_unit); | 1415 if_printf(sc->my_ifp, "no memory for tx list"); |
1434 MY_UNLOCK(sc); 1435 return (1); 1436 } 1437 } 1438 m_copydata(m_head, 0, m_head->m_pkthdr.len, mtod(m_new, caddr_t)); 1439 m_new->m_pkthdr.len = m_new->m_len = m_head->m_pkthdr.len; 1440 m_freem(m_head); 1441 m_head = m_new; --- 130 unchanged lines hidden (view full) --- 1572 */ 1573 if (sc->my_info->my_did == MTD891ID) { 1574 MY_SETBIT(sc, MY_BCR, MY_PROG); 1575 MY_SETBIT(sc, MY_TCRRCR, MY_Enhanced); 1576 } 1577 my_setcfg(sc, phy_bmcr); 1578 /* Init circular RX list. */ 1579 if (my_list_rx_init(sc) == ENOBUFS) { | 1416 MY_UNLOCK(sc); 1417 return (1); 1418 } 1419 } 1420 m_copydata(m_head, 0, m_head->m_pkthdr.len, mtod(m_new, caddr_t)); 1421 m_new->m_pkthdr.len = m_new->m_len = m_head->m_pkthdr.len; 1422 m_freem(m_head); 1423 m_head = m_new; --- 130 unchanged lines hidden (view full) --- 1554 */ 1555 if (sc->my_info->my_did == MTD891ID) { 1556 MY_SETBIT(sc, MY_BCR, MY_PROG); 1557 MY_SETBIT(sc, MY_TCRRCR, MY_Enhanced); 1558 } 1559 my_setcfg(sc, phy_bmcr); 1560 /* Init circular RX list. */ 1561 if (my_list_rx_init(sc) == ENOBUFS) { |
1580 printf("my%d: init failed: no memory for rx buffers\n", 1581 sc->my_unit); | 1562 if_printf(ifp, "init failed: no memory for rx buffers\n"); |
1582 my_stop(sc); 1583 (void)splx(s); 1584 MY_UNLOCK(sc); 1585 return; 1586 } 1587 /* Init TX descriptors. */ 1588 my_list_tx_init(sc); 1589 --- 173 unchanged lines hidden (view full) --- 1763 sc = ifp->if_softc; 1764 MY_LOCK(sc); 1765 if (sc->my_autoneg) { 1766 my_autoneg_mii(sc, MY_FLAG_DELAYTIMEO, 1); 1767 MY_UNLOCK(sc); 1768 return; 1769 } 1770 ifp->if_oerrors++; | 1563 my_stop(sc); 1564 (void)splx(s); 1565 MY_UNLOCK(sc); 1566 return; 1567 } 1568 /* Init TX descriptors. */ 1569 my_list_tx_init(sc); 1570 --- 173 unchanged lines hidden (view full) --- 1744 sc = ifp->if_softc; 1745 MY_LOCK(sc); 1746 if (sc->my_autoneg) { 1747 my_autoneg_mii(sc, MY_FLAG_DELAYTIMEO, 1); 1748 MY_UNLOCK(sc); 1749 return; 1750 } 1751 ifp->if_oerrors++; |
1771 printf("my%d: watchdog timeout\n", sc->my_unit); | 1752 if_printf(ifp, "watchdog timeout\n"); |
1772 if (!(my_phy_readreg(sc, PHY_BMSR) & PHY_BMSR_LINKSTAT)) | 1753 if (!(my_phy_readreg(sc, PHY_BMSR) & PHY_BMSR_LINKSTAT)) |
1773 printf("my%d: no carrier - transceiver cable problem?\n", 1774 sc->my_unit); | 1754 if_printf(ifp, "no carrier - transceiver cable problem?\n"); |
1775 my_stop(sc); 1776 my_reset(sc); 1777 my_init(sc); 1778 if (ifp->if_snd.ifq_head != NULL) 1779 my_start(ifp); 1780 MY_LOCK(sc); 1781 return; 1782} --- 60 unchanged lines hidden --- | 1755 my_stop(sc); 1756 my_reset(sc); 1757 my_init(sc); 1758 if (ifp->if_snd.ifq_head != NULL) 1759 my_start(ifp); 1760 MY_LOCK(sc); 1761 return; 1762} --- 60 unchanged lines hidden --- |