Deleted Added
full compact
if_ste.c (111119) if_ste.c (112872)
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/pci/if_ste.c 111119 2003-02-19 05:47:46Z imp $
32 * $FreeBSD: head/sys/pci/if_ste.c 112872 2003-03-31 17:29:43Z njl $
33 */
34
35#include <sys/param.h>
36#include <sys/systm.h>
37#include <sys/sockio.h>
38#include <sys/mbuf.h>
39#include <sys/malloc.h>
40#include <sys/kernel.h>

--- 29 unchanged lines hidden (view full) ---

70#define STE_USEIOSPACE
71
72#include <pci/if_stereg.h>
73
74MODULE_DEPEND(ste, miibus, 1, 1, 1);
75
76#if !defined(lint)
77static const char rcsid[] =
33 */
34
35#include <sys/param.h>
36#include <sys/systm.h>
37#include <sys/sockio.h>
38#include <sys/mbuf.h>
39#include <sys/malloc.h>
40#include <sys/kernel.h>

--- 29 unchanged lines hidden (view full) ---

70#define STE_USEIOSPACE
71
72#include <pci/if_stereg.h>
73
74MODULE_DEPEND(ste, miibus, 1, 1, 1);
75
76#if !defined(lint)
77static const char rcsid[] =
78 "$FreeBSD: head/sys/pci/if_ste.c 111119 2003-02-19 05:47:46Z imp $";
78 "$FreeBSD: head/sys/pci/if_ste.c 112872 2003-03-31 17:29:43Z njl $";
79#endif
80
81/*
82 * Various supported device vendors/types and their names.
83 */
84static struct ste_type ste_devs[] = {
85 { ST_VENDORID, ST_DEVICEID_ST201, "Sundance ST201 10/100BaseTX" },
86 { DL_VENDORID, DL_DEVICEID_DL10050, "D-Link DL10050 10/100BaseTX" },

--- 826 unchanged lines hidden (view full) ---

913{
914 u_int32_t command;
915 struct ste_softc *sc;
916 struct ifnet *ifp;
917 int unit, error = 0, rid;
918
919 sc = device_get_softc(dev);
920 unit = device_get_unit(dev);
79#endif
80
81/*
82 * Various supported device vendors/types and their names.
83 */
84static struct ste_type ste_devs[] = {
85 { ST_VENDORID, ST_DEVICEID_ST201, "Sundance ST201 10/100BaseTX" },
86 { DL_VENDORID, DL_DEVICEID_DL10050, "D-Link DL10050 10/100BaseTX" },

--- 826 unchanged lines hidden (view full) ---

913{
914 u_int32_t command;
915 struct ste_softc *sc;
916 struct ifnet *ifp;
917 int unit, error = 0, rid;
918
919 sc = device_get_softc(dev);
920 unit = device_get_unit(dev);
921 bzero(sc, sizeof(struct ste_softc));
922 sc->ste_dev = dev;
923
924 /*
925 * Only use one PHY since this chip reports multiple
926 * Note on the DFE-550 the PHY is at 1 on the DFE-580
927 * it is at 0 & 1. It is rev 0x12.
928 */
929 if (pci_get_vendor(dev) == DL_VENDORID &&
930 pci_get_device(dev) == DL_DEVICEID_DL10050 &&
931 pci_get_revid(dev) == 0x12 )
932 sc->ste_one_phy = 1;
933
934 mtx_init(&sc->ste_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
935 MTX_DEF | MTX_RECURSE);
921 sc->ste_dev = dev;
922
923 /*
924 * Only use one PHY since this chip reports multiple
925 * Note on the DFE-550 the PHY is at 1 on the DFE-580
926 * it is at 0 & 1. It is rev 0x12.
927 */
928 if (pci_get_vendor(dev) == DL_VENDORID &&
929 pci_get_device(dev) == DL_DEVICEID_DL10050 &&
930 pci_get_revid(dev) == 0x12 )
931 sc->ste_one_phy = 1;
932
933 mtx_init(&sc->ste_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
934 MTX_DEF | MTX_RECURSE);
936 STE_LOCK(sc);
937
938 /*
939 * Handle power management nonsense.
940 */
941 if (pci_get_powerstate(dev) != PCI_POWERSTATE_D0) {
942 u_int32_t iobase, membase, irq;
943
944 /* Save important PCI config data. */

--- 43 unchanged lines hidden (view full) ---

988 printf ("ste%d: couldn't map ports/memory\n", unit);
989 error = ENXIO;
990 goto fail;
991 }
992
993 sc->ste_btag = rman_get_bustag(sc->ste_res);
994 sc->ste_bhandle = rman_get_bushandle(sc->ste_res);
995
935
936 /*
937 * Handle power management nonsense.
938 */
939 if (pci_get_powerstate(dev) != PCI_POWERSTATE_D0) {
940 u_int32_t iobase, membase, irq;
941
942 /* Save important PCI config data. */

--- 43 unchanged lines hidden (view full) ---

986 printf ("ste%d: couldn't map ports/memory\n", unit);
987 error = ENXIO;
988 goto fail;
989 }
990
991 sc->ste_btag = rman_get_bustag(sc->ste_res);
992 sc->ste_bhandle = rman_get_bushandle(sc->ste_res);
993
994 /* Allocate interrupt */
996 rid = 0;
997 sc->ste_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
998 RF_SHAREABLE | RF_ACTIVE);
999
1000 if (sc->ste_irq == NULL) {
1001 printf("ste%d: couldn't map interrupt\n", unit);
995 rid = 0;
996 sc->ste_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
997 RF_SHAREABLE | RF_ACTIVE);
998
999 if (sc->ste_irq == NULL) {
1000 printf("ste%d: couldn't map interrupt\n", unit);
1002 bus_release_resource(dev, STE_RES, STE_RID, sc->ste_res);
1003 error = ENXIO;
1004 goto fail;
1005 }
1006
1001 error = ENXIO;
1002 goto fail;
1003 }
1004
1007 error = bus_setup_intr(dev, sc->ste_irq, INTR_TYPE_NET,
1008 ste_intr, sc, &sc->ste_intrhand);
1009
1010 if (error) {
1011 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->ste_irq);
1012 bus_release_resource(dev, STE_RES, STE_RID, sc->ste_res);
1013 printf("ste%d: couldn't set up irq\n", unit);
1014 goto fail;
1015 }
1016
1017 callout_handle_init(&sc->ste_stat_ch);
1018
1019 /* Reset the adapter. */
1020 ste_reset(sc);
1021
1022 /*
1023 * Get station address from the EEPROM.
1024 */
1025 if (ste_read_eeprom(sc, (caddr_t)&sc->arpcom.ac_enaddr,
1026 STE_EEADDR_NODE0, 3, 0)) {
1027 printf("ste%d: failed to read station address\n", unit);
1005 callout_handle_init(&sc->ste_stat_ch);
1006
1007 /* Reset the adapter. */
1008 ste_reset(sc);
1009
1010 /*
1011 * Get station address from the EEPROM.
1012 */
1013 if (ste_read_eeprom(sc, (caddr_t)&sc->arpcom.ac_enaddr,
1014 STE_EEADDR_NODE0, 3, 0)) {
1015 printf("ste%d: failed to read station address\n", unit);
1028 bus_teardown_intr(dev, sc->ste_irq, sc->ste_intrhand);
1029 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->ste_irq);
1030 bus_release_resource(dev, STE_RES, STE_RID, sc->ste_res);
1031 error = ENXIO;;
1032 goto fail;
1033 }
1034
1035 /*
1036 * A Sundance chip was detected. Inform the world.
1037 */
1038 printf("ste%d: Ethernet address: %6D\n", unit,
1039 sc->arpcom.ac_enaddr, ":");
1040
1041 sc->ste_unit = unit;
1042
1043 /* Allocate the descriptor queues. */
1044 sc->ste_ldata = contigmalloc(sizeof(struct ste_list_data), M_DEVBUF,
1045 M_NOWAIT, 0, 0xffffffff, PAGE_SIZE, 0);
1046
1047 if (sc->ste_ldata == NULL) {
1048 printf("ste%d: no memory for list buffers!\n", unit);
1016 error = ENXIO;;
1017 goto fail;
1018 }
1019
1020 /*
1021 * A Sundance chip was detected. Inform the world.
1022 */
1023 printf("ste%d: Ethernet address: %6D\n", unit,
1024 sc->arpcom.ac_enaddr, ":");
1025
1026 sc->ste_unit = unit;
1027
1028 /* Allocate the descriptor queues. */
1029 sc->ste_ldata = contigmalloc(sizeof(struct ste_list_data), M_DEVBUF,
1030 M_NOWAIT, 0, 0xffffffff, PAGE_SIZE, 0);
1031
1032 if (sc->ste_ldata == NULL) {
1033 printf("ste%d: no memory for list buffers!\n", unit);
1049 bus_teardown_intr(dev, sc->ste_irq, sc->ste_intrhand);
1050 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->ste_irq);
1051 bus_release_resource(dev, STE_RES, STE_RID, sc->ste_res);
1052 error = ENXIO;
1053 goto fail;
1054 }
1055
1056 bzero(sc->ste_ldata, sizeof(struct ste_list_data));
1057
1058 /* Do MII setup. */
1059 if (mii_phy_probe(dev, &sc->ste_miibus,
1034 error = ENXIO;
1035 goto fail;
1036 }
1037
1038 bzero(sc->ste_ldata, sizeof(struct ste_list_data));
1039
1040 /* Do MII setup. */
1041 if (mii_phy_probe(dev, &sc->ste_miibus,
1060 ste_ifmedia_upd, ste_ifmedia_sts)) {
1042 ste_ifmedia_upd, ste_ifmedia_sts)) {
1061 printf("ste%d: MII without any phy!\n", sc->ste_unit);
1043 printf("ste%d: MII without any phy!\n", sc->ste_unit);
1062 bus_teardown_intr(dev, sc->ste_irq, sc->ste_intrhand);
1063 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->ste_irq);
1064 bus_release_resource(dev, STE_RES, STE_RID, sc->ste_res);
1065 contigfree(sc->ste_ldata,
1066 sizeof(struct ste_list_data), M_DEVBUF);
1067 error = ENXIO;
1068 goto fail;
1069 }
1070
1071 ifp = &sc->arpcom.ac_if;
1072 ifp->if_softc = sc;
1073 ifp->if_unit = unit;
1074 ifp->if_name = "ste";

--- 15 unchanged lines hidden (view full) ---

1090 ether_ifattach(ifp, sc->arpcom.ac_enaddr);
1091
1092 /*
1093 * Tell the upper layer(s) we support long frames.
1094 */
1095 ifp->if_data.ifi_hdrlen = sizeof(struct ether_vlan_header);
1096 ifp->if_capabilities |= IFCAP_VLAN_MTU;
1097
1044 error = ENXIO;
1045 goto fail;
1046 }
1047
1048 ifp = &sc->arpcom.ac_if;
1049 ifp->if_softc = sc;
1050 ifp->if_unit = unit;
1051 ifp->if_name = "ste";

--- 15 unchanged lines hidden (view full) ---

1067 ether_ifattach(ifp, sc->arpcom.ac_enaddr);
1068
1069 /*
1070 * Tell the upper layer(s) we support long frames.
1071 */
1072 ifp->if_data.ifi_hdrlen = sizeof(struct ether_vlan_header);
1073 ifp->if_capabilities |= IFCAP_VLAN_MTU;
1074
1098 STE_UNLOCK(sc);
1099 return(0);
1075 error = bus_setup_intr(dev, sc->ste_irq, INTR_TYPE_NET,
1076 ste_intr, sc, &sc->ste_intrhand);
1100
1077
1078 if (error) {
1079 printf("ste%d: couldn't set up irq\n", unit);
1080 goto fail;
1081 }
1082
1101fail:
1083fail:
1102 STE_UNLOCK(sc);
1103 mtx_destroy(&sc->ste_mtx);
1084 if (error)
1085 ste_detach(dev);
1086
1104 return(error);
1105}
1106
1107static int
1108ste_detach(dev)
1109 device_t dev;
1110{
1111 struct ste_softc *sc;
1112 struct ifnet *ifp;
1113
1114 sc = device_get_softc(dev);
1087 return(error);
1088}
1089
1090static int
1091ste_detach(dev)
1092 device_t dev;
1093{
1094 struct ste_softc *sc;
1095 struct ifnet *ifp;
1096
1097 sc = device_get_softc(dev);
1098 KASSERT(mtx_initialized(&sc->ste_mtx), "ste mutex not initialized");
1115 STE_LOCK(sc);
1116 ifp = &sc->arpcom.ac_if;
1117
1099 STE_LOCK(sc);
1100 ifp = &sc->arpcom.ac_if;
1101
1118 ste_stop(sc);
1119 ether_ifdetach(ifp);
1102 if (device_is_alive(dev)) {
1103 if (bus_child_present(dev))
1104 ste_stop(sc);
1105 ether_ifdetach(ifp);
1106 device_delete_child(dev, sc->ste_miibus);
1107 bus_generic_detach(dev);
1108 }
1120
1109
1121 bus_generic_detach(dev);
1122 device_delete_child(dev, sc->ste_miibus);
1110 if (sc->ste_intrhand)
1111 bus_teardown_intr(dev, sc->ste_irq, sc->ste_intrhand);
1112 if (sc->ste_irq)
1113 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->ste_irq);
1114 if (sc->ste_res)
1115 bus_release_resource(dev, STE_RES, STE_RID, sc->ste_res);
1123
1116
1124 bus_teardown_intr(dev, sc->ste_irq, sc->ste_intrhand);
1125 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->ste_irq);
1126 bus_release_resource(dev, STE_RES, STE_RID, sc->ste_res);
1117 if (sc->ste_ldata) {
1118 contigfree(sc->ste_ldata, sizeof(struct ste_list_data),
1119 M_DEVBUF);
1120 }
1127
1121
1128 contigfree(sc->ste_ldata, sizeof(struct ste_list_data), M_DEVBUF);
1129
1130 STE_UNLOCK(sc);
1131 mtx_destroy(&sc->ste_mtx);
1132
1133 return(0);
1134}
1135
1136static int
1137ste_newbuf(sc, c, m)

--- 531 unchanged lines hidden ---
1122 STE_UNLOCK(sc);
1123 mtx_destroy(&sc->ste_mtx);
1124
1125 return(0);
1126}
1127
1128static int
1129ste_newbuf(sc, c, m)

--- 531 unchanged lines hidden ---