if_pcn.c (111119) | if_pcn.c (112872) |
---|---|
1/* 2 * Copyright (c) 2000 Berkeley Software Design, Inc. 3 * Copyright (c) 1997, 1998, 1999, 2000 4 * Bill Paul <wpaul@osd.bsdi.com>. 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: --- 16 unchanged lines hidden (view full) --- 25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 * THE POSSIBILITY OF SUCH DAMAGE. 32 * | 1/* 2 * Copyright (c) 2000 Berkeley Software Design, Inc. 3 * Copyright (c) 1997, 1998, 1999, 2000 4 * Bill Paul <wpaul@osd.bsdi.com>. 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: --- 16 unchanged lines hidden (view full) --- 25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 * THE POSSIBILITY OF SUCH DAMAGE. 32 * |
33 * $FreeBSD: head/sys/pci/if_pcn.c 111119 2003-02-19 05:47:46Z imp $ | 33 * $FreeBSD: head/sys/pci/if_pcn.c 112872 2003-03-31 17:29:43Z njl $ |
34 */ 35 36/* 37 * AMD Am79c972 fast ethernet PCI NIC driver. Datatheets are available 38 * from http://www.amd.com. 39 * 40 * Written by Bill Paul <wpaul@osd.bsdi.com> 41 */ --- 50 unchanged lines hidden (view full) --- 92 93MODULE_DEPEND(pcn, miibus, 1, 1, 1); 94 95/* "controller miibus0" required. See GENERIC if you get errors here. */ 96#include "miibus_if.h" 97 98#ifndef lint 99static const char rcsid[] = | 34 */ 35 36/* 37 * AMD Am79c972 fast ethernet PCI NIC driver. Datatheets are available 38 * from http://www.amd.com. 39 * 40 * Written by Bill Paul <wpaul@osd.bsdi.com> 41 */ --- 50 unchanged lines hidden (view full) --- 92 93MODULE_DEPEND(pcn, miibus, 1, 1, 1); 94 95/* "controller miibus0" required. See GENERIC if you get errors here. */ 96#include "miibus_if.h" 97 98#ifndef lint 99static const char rcsid[] = |
100 "$FreeBSD: head/sys/pci/if_pcn.c 111119 2003-02-19 05:47:46Z imp $"; | 100 "$FreeBSD: head/sys/pci/if_pcn.c 112872 2003-03-31 17:29:43Z njl $"; |
101#endif 102 103/* 104 * Various supported device vendors/types and their names. 105 */ 106static struct pcn_type pcn_devs[] = { 107 { PCN_VENDORID, PCN_DEVICEID_PCNET, "AMD PCnet/PCI 10/100BaseTX" }, 108 { PCN_VENDORID, PCN_DEVICEID_HOME, "AMD PCnet/Home HomePNA" }, --- 407 unchanged lines hidden (view full) --- 516 int unit, error = 0, rid; 517 518 sc = device_get_softc(dev); 519 unit = device_get_unit(dev); 520 521 /* Initialize our mutex. */ 522 mtx_init(&sc->pcn_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK, 523 MTX_DEF | MTX_RECURSE); | 101#endif 102 103/* 104 * Various supported device vendors/types and their names. 105 */ 106static struct pcn_type pcn_devs[] = { 107 { PCN_VENDORID, PCN_DEVICEID_PCNET, "AMD PCnet/PCI 10/100BaseTX" }, 108 { PCN_VENDORID, PCN_DEVICEID_HOME, "AMD PCnet/Home HomePNA" }, --- 407 unchanged lines hidden (view full) --- 516 int unit, error = 0, rid; 517 518 sc = device_get_softc(dev); 519 unit = device_get_unit(dev); 520 521 /* Initialize our mutex. */ 522 mtx_init(&sc->pcn_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK, 523 MTX_DEF | MTX_RECURSE); |
524 PCN_LOCK(sc); | |
525 526 /* 527 * Handle power management nonsense. 528 */ 529 if (pci_get_powerstate(dev) != PCI_POWERSTATE_D0) { 530 u_int32_t iobase, membase, irq; 531 532 /* Save important PCI config data. */ --- 19 unchanged lines hidden (view full) --- 552 pci_enable_busmaster(dev); 553 pci_enable_io(dev, SYS_RES_IOPORT); 554 pci_enable_io(dev, SYS_RES_MEMORY); 555 command = pci_read_config(dev, PCIR_COMMAND, 4); 556 557#ifdef PCN_USEIOSPACE 558 if (!(command & PCIM_CMD_PORTEN)) { 559 printf("pcn%d: failed to enable I/O ports!\n", unit); | 524 525 /* 526 * Handle power management nonsense. 527 */ 528 if (pci_get_powerstate(dev) != PCI_POWERSTATE_D0) { 529 u_int32_t iobase, membase, irq; 530 531 /* Save important PCI config data. */ --- 19 unchanged lines hidden (view full) --- 551 pci_enable_busmaster(dev); 552 pci_enable_io(dev, SYS_RES_IOPORT); 553 pci_enable_io(dev, SYS_RES_MEMORY); 554 command = pci_read_config(dev, PCIR_COMMAND, 4); 555 556#ifdef PCN_USEIOSPACE 557 if (!(command & PCIM_CMD_PORTEN)) { 558 printf("pcn%d: failed to enable I/O ports!\n", unit); |
560 error = ENXIO;; | 559 error = ENXIO; |
561 goto fail; 562 } 563#else 564 if (!(command & PCIM_CMD_MEMEN)) { 565 printf("pcn%d: failed to enable memory mapping!\n", unit); | 560 goto fail; 561 } 562#else 563 if (!(command & PCIM_CMD_MEMEN)) { 564 printf("pcn%d: failed to enable memory mapping!\n", unit); |
566 error = ENXIO;; | 565 error = ENXIO; |
567 goto fail; 568 } 569#endif 570 571 rid = PCN_RID; 572 sc->pcn_res = bus_alloc_resource(dev, PCN_RES, &rid, 573 0, ~0, 1, RF_ACTIVE); 574 --- 12 unchanged lines hidden (view full) --- 587 RF_SHAREABLE | RF_ACTIVE); 588 589 if (sc->pcn_irq == NULL) { 590 printf("pcn%d: couldn't map interrupt\n", unit); 591 error = ENXIO; 592 goto fail; 593 } 594 | 566 goto fail; 567 } 568#endif 569 570 rid = PCN_RID; 571 sc->pcn_res = bus_alloc_resource(dev, PCN_RES, &rid, 572 0, ~0, 1, RF_ACTIVE); 573 --- 12 unchanged lines hidden (view full) --- 586 RF_SHAREABLE | RF_ACTIVE); 587 588 if (sc->pcn_irq == NULL) { 589 printf("pcn%d: couldn't map interrupt\n", unit); 590 error = ENXIO; 591 goto fail; 592 } 593 |
595 error = bus_setup_intr(dev, sc->pcn_irq, INTR_TYPE_NET, 596 pcn_intr, sc, &sc->pcn_intrhand); 597 598 if (error) { 599 printf("pcn%d: couldn't set up irq\n", unit); 600 goto fail; 601 } 602 | |
603 /* Reset the adapter. */ 604 pcn_reset(sc); 605 606 /* 607 * Get station address from the EEPROM. 608 */ 609 eaddr[0] = CSR_READ_4(sc, PCN_IO32_APROM00); 610 eaddr[1] = CSR_READ_4(sc, PCN_IO32_APROM01); --- 41 unchanged lines hidden (view full) --- 652 error = ENXIO; 653 goto fail; 654 } 655 656 /* 657 * Call MI attach routine. 658 */ 659 ether_ifattach(ifp, (u_int8_t *) eaddr); | 594 /* Reset the adapter. */ 595 pcn_reset(sc); 596 597 /* 598 * Get station address from the EEPROM. 599 */ 600 eaddr[0] = CSR_READ_4(sc, PCN_IO32_APROM00); 601 eaddr[1] = CSR_READ_4(sc, PCN_IO32_APROM01); --- 41 unchanged lines hidden (view full) --- 643 error = ENXIO; 644 goto fail; 645 } 646 647 /* 648 * Call MI attach routine. 649 */ 650 ether_ifattach(ifp, (u_int8_t *) eaddr); |
660 PCN_UNLOCK(sc); 661 return(0); | |
662 | 651 |
663fail: 664 PCN_UNLOCK(sc); | 652 error = bus_setup_intr(dev, sc->pcn_irq, INTR_TYPE_NET, 653 pcn_intr, sc, &sc->pcn_intrhand); |
665 | 654 |
666 if (sc->pcn_intrhand) 667 bus_teardown_intr(dev, sc->pcn_irq, sc->pcn_intrhand); 668 if (sc->pcn_irq) 669 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->pcn_irq); 670 if (sc->pcn_res) 671 bus_release_resource(dev, PCN_RES, PCN_RID, sc->pcn_res); | 655 if (error) { 656 printf("pcn%d: couldn't set up irq\n", unit); 657 goto fail; 658 } |
672 | 659 |
673 if (mtx_initialized(&sc->pcn_mtx) != 0) 674 mtx_destroy(&sc->pcn_mtx); | 660fail: 661 if (error) 662 pcn_detach(dev); |
675 676 return(error); 677} 678 679static int 680pcn_detach(dev) 681 device_t dev; 682{ 683 struct pcn_softc *sc; 684 struct ifnet *ifp; 685 686 sc = device_get_softc(dev); 687 ifp = &sc->arpcom.ac_if; 688 | 663 664 return(error); 665} 666 667static int 668pcn_detach(dev) 669 device_t dev; 670{ 671 struct pcn_softc *sc; 672 struct ifnet *ifp; 673 674 sc = device_get_softc(dev); 675 ifp = &sc->arpcom.ac_if; 676 |
677 KASSERT(mtx_initialized(&sc->pcn_mtx), "pcn mutex not initialized"); |
|
689 PCN_LOCK(sc); 690 | 678 PCN_LOCK(sc); 679 |
691 pcn_reset(sc); 692 pcn_stop(sc); 693 ether_ifdetach(ifp); 694 695 if (sc->pcn_miibus != NULL) { 696 bus_generic_detach(dev); | 680 if (device_is_alive(dev)) { 681 if (bus_child_present(dev)) { 682 pcn_reset(sc); 683 pcn_stop(sc); 684 } 685 ether_ifdetach(ifp); |
697 device_delete_child(dev, sc->pcn_miibus); | 686 device_delete_child(dev, sc->pcn_miibus); |
687 bus_generic_detach(dev); |
|
698 } 699 | 688 } 689 |
700 bus_teardown_intr(dev, sc->pcn_irq, sc->pcn_intrhand); 701 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->pcn_irq); 702 bus_release_resource(dev, PCN_RES, PCN_RID, sc->pcn_res); | 690 if (sc->pcn_intrhand) 691 bus_teardown_intr(dev, sc->pcn_irq, sc->pcn_intrhand); 692 if (sc->pcn_irq) 693 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->pcn_irq); 694 if (sc->pcn_res) 695 bus_release_resource(dev, PCN_RES, PCN_RID, sc->pcn_res); |
703 | 696 |
704 contigfree(sc->pcn_ldata, sizeof(struct pcn_list_data), M_DEVBUF); | 697 if (sc->pcn_ldata) { 698 contigfree(sc->pcn_ldata, sizeof(struct pcn_list_data), 699 M_DEVBUF); 700 } |
705 PCN_UNLOCK(sc); 706 707 mtx_destroy(&sc->pcn_mtx); 708 709 return(0); 710} 711 712/* --- 750 unchanged lines hidden --- | 701 PCN_UNLOCK(sc); 702 703 mtx_destroy(&sc->pcn_mtx); 704 705 return(0); 706} 707 708/* --- 750 unchanged lines hidden --- |