if_vr.c (112821) | if_vr.c (112872) |
---|---|
1/* 2 * Copyright (c) 1997, 1998 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 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/vr/if_vr.c 112821 2003-03-29 21:39:49Z silby $ | 32 * $FreeBSD: head/sys/dev/vr/if_vr.c 112872 2003-03-31 17:29:43Z njl $ |
33 */ 34 35/* 36 * VIA Rhine fast ethernet PCI NIC driver 37 * 38 * Supports various network adapters based on the VIA Rhine 39 * and Rhine II PCI controllers, including the D-Link DFE530TX. 40 * Datasheets are available at http://www.via.com.tw. --- 55 unchanged lines hidden (view full) --- 96 97MODULE_DEPEND(vr, miibus, 1, 1, 1); 98 99/* "controller miibus0" required. See GENERIC if you get errors here. */ 100#include "miibus_if.h" 101 102#ifndef lint 103static const char rcsid[] = | 33 */ 34 35/* 36 * VIA Rhine fast ethernet PCI NIC driver 37 * 38 * Supports various network adapters based on the VIA Rhine 39 * and Rhine II PCI controllers, including the D-Link DFE530TX. 40 * Datasheets are available at http://www.via.com.tw. --- 55 unchanged lines hidden (view full) --- 96 97MODULE_DEPEND(vr, miibus, 1, 1, 1); 98 99/* "controller miibus0" required. See GENERIC if you get errors here. */ 100#include "miibus_if.h" 101 102#ifndef lint 103static const char rcsid[] = |
104 "$FreeBSD: head/sys/dev/vr/if_vr.c 112821 2003-03-29 21:39:49Z silby $"; | 104 "$FreeBSD: head/sys/dev/vr/if_vr.c 112872 2003-03-31 17:29:43Z njl $"; |
105#endif 106 107#undef VR_USESWSHIFT 108 109/* 110 * Various supported device vendors/types and their names. 111 */ 112static struct vr_type vr_devs[] = { --- 626 unchanged lines hidden (view full) --- 739 u_char eaddr[ETHER_ADDR_LEN]; 740 u_int32_t command; 741 struct vr_softc *sc; 742 struct ifnet *ifp; 743 int unit, error = 0, rid; 744 745 sc = device_get_softc(dev); 746 unit = device_get_unit(dev); | 105#endif 106 107#undef VR_USESWSHIFT 108 109/* 110 * Various supported device vendors/types and their names. 111 */ 112static struct vr_type vr_devs[] = { --- 626 unchanged lines hidden (view full) --- 739 u_char eaddr[ETHER_ADDR_LEN]; 740 u_int32_t command; 741 struct vr_softc *sc; 742 struct ifnet *ifp; 743 int unit, error = 0, rid; 744 745 sc = device_get_softc(dev); 746 unit = device_get_unit(dev); |
747 bzero(sc, sizeof(struct vr_softc *)); | |
748 749 mtx_init(&sc->vr_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK, 750 MTX_DEF | MTX_RECURSE); | 747 748 mtx_init(&sc->vr_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK, 749 MTX_DEF | MTX_RECURSE); |
751 VR_LOCK(sc); | |
752 753 /* 754 * Handle power management nonsense. 755 */ 756 if (pci_get_powerstate(dev) != PCI_POWERSTATE_D0) { 757 u_int32_t iobase, membase, irq; 758 759 /* Save important PCI config data. */ --- 20 unchanged lines hidden (view full) --- 780 pci_enable_io(dev, SYS_RES_IOPORT); 781 pci_enable_io(dev, SYS_RES_MEMORY); 782 command = pci_read_config(dev, PCIR_COMMAND, 4); 783 sc->vr_revid = pci_read_config(dev, VR_PCI_REVID, 4) & 0x000000FF; 784 785#ifdef VR_USEIOSPACE 786 if (!(command & PCIM_CMD_PORTEN)) { 787 printf("vr%d: failed to enable I/O ports!\n", unit); | 750 751 /* 752 * Handle power management nonsense. 753 */ 754 if (pci_get_powerstate(dev) != PCI_POWERSTATE_D0) { 755 u_int32_t iobase, membase, irq; 756 757 /* Save important PCI config data. */ --- 20 unchanged lines hidden (view full) --- 778 pci_enable_io(dev, SYS_RES_IOPORT); 779 pci_enable_io(dev, SYS_RES_MEMORY); 780 command = pci_read_config(dev, PCIR_COMMAND, 4); 781 sc->vr_revid = pci_read_config(dev, VR_PCI_REVID, 4) & 0x000000FF; 782 783#ifdef VR_USEIOSPACE 784 if (!(command & PCIM_CMD_PORTEN)) { 785 printf("vr%d: failed to enable I/O ports!\n", unit); |
788 free(sc, M_DEVBUF); | 786 error = ENXIO; |
789 goto fail; 790 } 791#else 792 if (!(command & PCIM_CMD_MEMEN)) { 793 printf("vr%d: failed to enable memory mapping!\n", unit); | 787 goto fail; 788 } 789#else 790 if (!(command & PCIM_CMD_MEMEN)) { 791 printf("vr%d: failed to enable memory mapping!\n", unit); |
792 error = ENXIO; |
|
794 goto fail; 795 } 796#endif 797 798 rid = VR_RID; 799 sc->vr_res = bus_alloc_resource(dev, VR_RES, &rid, 800 0, ~0, 1, RF_ACTIVE); 801 --- 8 unchanged lines hidden (view full) --- 810 811 /* Allocate interrupt */ 812 rid = 0; 813 sc->vr_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1, 814 RF_SHAREABLE | RF_ACTIVE); 815 816 if (sc->vr_irq == NULL) { 817 printf("vr%d: couldn't map interrupt\n", unit); | 793 goto fail; 794 } 795#endif 796 797 rid = VR_RID; 798 sc->vr_res = bus_alloc_resource(dev, VR_RES, &rid, 799 0, ~0, 1, RF_ACTIVE); 800 --- 8 unchanged lines hidden (view full) --- 809 810 /* Allocate interrupt */ 811 rid = 0; 812 sc->vr_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1, 813 RF_SHAREABLE | RF_ACTIVE); 814 815 if (sc->vr_irq == NULL) { 816 printf("vr%d: couldn't map interrupt\n", unit); |
818 bus_release_resource(dev, VR_RES, VR_RID, sc->vr_res); | |
819 error = ENXIO; 820 goto fail; 821 } 822 | 817 error = ENXIO; 818 goto fail; 819 } 820 |
823 error = bus_setup_intr(dev, sc->vr_irq, INTR_TYPE_NET, 824 vr_intr, sc, &sc->vr_intrhand); 825 826 if (error) { 827 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->vr_irq); 828 bus_release_resource(dev, VR_RES, VR_RID, sc->vr_res); 829 printf("vr%d: couldn't set up irq\n", unit); 830 goto fail; 831 } 832 | |
833 /* 834 * Windows may put the chip in suspend mode when it 835 * shuts down. Be sure to kick it in the head to wake it 836 * up again. 837 */ 838 VR_CLRBIT(sc, VR_STICKHW, (VR_STICKHW_DS0|VR_STICKHW_DS1)); 839 840 /* Reset the adapter. */ --- 27 unchanged lines hidden (view full) --- 868 sc->vr_unit = unit; 869 bcopy(eaddr, (char *)&sc->arpcom.ac_enaddr, ETHER_ADDR_LEN); 870 871 sc->vr_ldata = contigmalloc(sizeof(struct vr_list_data), M_DEVBUF, 872 M_NOWAIT, 0, 0xffffffff, PAGE_SIZE, 0); 873 874 if (sc->vr_ldata == NULL) { 875 printf("vr%d: no memory for list buffers!\n", unit); | 821 /* 822 * Windows may put the chip in suspend mode when it 823 * shuts down. Be sure to kick it in the head to wake it 824 * up again. 825 */ 826 VR_CLRBIT(sc, VR_STICKHW, (VR_STICKHW_DS0|VR_STICKHW_DS1)); 827 828 /* Reset the adapter. */ --- 27 unchanged lines hidden (view full) --- 856 sc->vr_unit = unit; 857 bcopy(eaddr, (char *)&sc->arpcom.ac_enaddr, ETHER_ADDR_LEN); 858 859 sc->vr_ldata = contigmalloc(sizeof(struct vr_list_data), M_DEVBUF, 860 M_NOWAIT, 0, 0xffffffff, PAGE_SIZE, 0); 861 862 if (sc->vr_ldata == NULL) { 863 printf("vr%d: no memory for list buffers!\n", unit); |
876 bus_teardown_intr(dev, sc->vr_irq, sc->vr_intrhand); 877 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->vr_irq); 878 bus_release_resource(dev, VR_RES, VR_RID, sc->vr_res); | |
879 error = ENXIO; 880 goto fail; 881 } 882 883 bzero(sc->vr_ldata, sizeof(struct vr_list_data)); 884 885 ifp = &sc->arpcom.ac_if; 886 ifp->if_softc = sc; --- 10 unchanged lines hidden (view full) --- 897 ifp->if_snd.ifq_maxlen = VR_TX_LIST_CNT - 1; 898 899 /* 900 * Do MII setup. 901 */ 902 if (mii_phy_probe(dev, &sc->vr_miibus, 903 vr_ifmedia_upd, vr_ifmedia_sts)) { 904 printf("vr%d: MII without any phy!\n", sc->vr_unit); | 864 error = ENXIO; 865 goto fail; 866 } 867 868 bzero(sc->vr_ldata, sizeof(struct vr_list_data)); 869 870 ifp = &sc->arpcom.ac_if; 871 ifp->if_softc = sc; --- 10 unchanged lines hidden (view full) --- 882 ifp->if_snd.ifq_maxlen = VR_TX_LIST_CNT - 1; 883 884 /* 885 * Do MII setup. 886 */ 887 if (mii_phy_probe(dev, &sc->vr_miibus, 888 vr_ifmedia_upd, vr_ifmedia_sts)) { 889 printf("vr%d: MII without any phy!\n", sc->vr_unit); |
905 bus_teardown_intr(dev, sc->vr_irq, sc->vr_intrhand); 906 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->vr_irq); 907 bus_release_resource(dev, VR_RES, VR_RID, sc->vr_res); 908 contigfree(sc->vr_ldata, 909 sizeof(struct vr_list_data), M_DEVBUF); | |
910 error = ENXIO; 911 goto fail; 912 } 913 914 callout_handle_init(&sc->vr_stat_ch); 915 916 /* 917 * Call MI attach routine. 918 */ 919 ether_ifattach(ifp, eaddr); | 890 error = ENXIO; 891 goto fail; 892 } 893 894 callout_handle_init(&sc->vr_stat_ch); 895 896 /* 897 * Call MI attach routine. 898 */ 899 ether_ifattach(ifp, eaddr); |
920 VR_UNLOCK(sc); 921 return(0); | |
922 | 900 |
901 error = bus_setup_intr(dev, sc->vr_irq, INTR_TYPE_NET, 902 vr_intr, sc, &sc->vr_intrhand); 903 904 if (error) { 905 printf("vr%d: couldn't set up irq\n", unit); 906 goto fail; 907 } 908 |
|
923fail: | 909fail: |
924 VR_UNLOCK(sc); 925 mtx_destroy(&sc->vr_mtx); | 910 if (error) 911 vr_detach(dev); |
926 927 return(error); 928} 929 930static int 931vr_detach(dev) 932 device_t dev; 933{ 934 struct vr_softc *sc; 935 struct ifnet *ifp; 936 937 sc = device_get_softc(dev); | 912 913 return(error); 914} 915 916static int 917vr_detach(dev) 918 device_t dev; 919{ 920 struct vr_softc *sc; 921 struct ifnet *ifp; 922 923 sc = device_get_softc(dev); |
924 KASSERT(mtx_initialized(&sc->vr_mtx), "vr mutex not initialized"); |
|
938 VR_LOCK(sc); 939 ifp = &sc->arpcom.ac_if; 940 | 925 VR_LOCK(sc); 926 ifp = &sc->arpcom.ac_if; 927 |
941 vr_stop(sc); 942 ether_ifdetach(ifp); | 928 if (device_is_alive(dev)) { 929 if (bus_child_present(dev)) 930 vr_stop(sc); 931 ether_ifdetach(ifp); 932 device_delete_child(dev, sc->vr_miibus); 933 bus_generic_detach(dev); 934 } |
943 | 935 |
944 bus_generic_detach(dev); 945 device_delete_child(dev, sc->vr_miibus); | 936 if (sc->vr_intrhand) 937 bus_teardown_intr(dev, sc->vr_irq, sc->vr_intrhand); 938 if (sc->vr_irq) 939 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->vr_irq); 940 if (sc->vr_res) 941 bus_release_resource(dev, VR_RES, VR_RID, sc->vr_res); |
946 | 942 |
947 bus_teardown_intr(dev, sc->vr_irq, sc->vr_intrhand); 948 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->vr_irq); 949 bus_release_resource(dev, VR_RES, VR_RID, sc->vr_res); | 943 if (sc->vr_ldata) 944 contigfree(sc->vr_ldata, sizeof(struct vr_list_data), M_DEVBUF); |
950 | 945 |
951 contigfree(sc->vr_ldata, sizeof(struct vr_list_data), M_DEVBUF); 952 | |
953 VR_UNLOCK(sc); 954 mtx_destroy(&sc->vr_mtx); 955 956 return(0); 957} 958 959/* 960 * Initialize the transmit descriptors. --- 863 unchanged lines hidden --- | 946 VR_UNLOCK(sc); 947 mtx_destroy(&sc->vr_mtx); 948 949 return(0); 950} 951 952/* 953 * Initialize the transmit descriptors. --- 863 unchanged lines hidden --- |