if_wb.c (48745) | if_wb.c (49611) |
---|---|
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 * $Id: if_wb.c,v 1.6.2.2 1999/05/13 21:19:31 wpaul Exp $ | 32 * $Id: if_wb.c,v 1.13 1999/07/11 00:56:07 wpaul Exp $ |
33 */ 34 35/* 36 * Winbond fast ethernet PCI NIC driver 37 * 38 * Supports various cheap network adapters based on the Winbond W89C840F 39 * fast ethernet controller chip. This includes adapters manufactured by 40 * Winbond itself and some made by Linksys. --- 68 unchanged lines hidden (view full) --- 109#endif 110 111#include <vm/vm.h> /* for vtophys */ 112#include <vm/pmap.h> /* for vtophys */ 113#include <machine/clock.h> /* for DELAY */ 114#include <machine/bus_memio.h> 115#include <machine/bus_pio.h> 116#include <machine/bus.h> | 33 */ 34 35/* 36 * Winbond fast ethernet PCI NIC driver 37 * 38 * Supports various cheap network adapters based on the Winbond W89C840F 39 * fast ethernet controller chip. This includes adapters manufactured by 40 * Winbond itself and some made by Linksys. --- 68 unchanged lines hidden (view full) --- 109#endif 110 111#include <vm/vm.h> /* for vtophys */ 112#include <vm/pmap.h> /* for vtophys */ 113#include <machine/clock.h> /* for DELAY */ 114#include <machine/bus_memio.h> 115#include <machine/bus_pio.h> 116#include <machine/bus.h> |
117#include <machine/resource.h> 118#include <sys/bus.h> 119#include <sys/rman.h> |
|
117 118#include <pci/pcireg.h> 119#include <pci/pcivar.h> 120 121#define WB_USEIOSPACE 122 123/* #define WB_BACKGROUND_AUTONEG */ 124 125#include <pci/if_wbreg.h> 126 127#ifndef lint 128static const char rcsid[] = | 120 121#include <pci/pcireg.h> 122#include <pci/pcivar.h> 123 124#define WB_USEIOSPACE 125 126/* #define WB_BACKGROUND_AUTONEG */ 127 128#include <pci/if_wbreg.h> 129 130#ifndef lint 131static const char rcsid[] = |
129 "$Id: if_wb.c,v 1.6.2.2 1999/05/13 21:19:31 wpaul Exp $"; | 132 "$Id: if_wb.c,v 1.13 1999/07/11 00:56:07 wpaul Exp $"; |
130#endif 131 132/* 133 * Various supported device vendors/types and their names. 134 */ 135static struct wb_type wb_devs[] = { 136 { WB_VENDORID, WB_DEVICEID_840F, 137 "Winbond W89C840F 10/100BaseTX" }, --- 13 unchanged lines hidden (view full) --- 151 { TI_PHY_VENDORID, TI_PHY_100VGPMI, "<TI TNETE211 100VG Any-LAN>" }, 152 { NS_PHY_VENDORID, NS_PHY_83840A, "<National Semiconductor DP83840A>"}, 153 { LEVEL1_PHY_VENDORID, LEVEL1_PHY_LXT970, "<Level 1 LXT970>" }, 154 { INTEL_PHY_VENDORID, INTEL_PHY_82555, "<Intel 82555>" }, 155 { SEEQ_PHY_VENDORID, SEEQ_PHY_80220, "<SEEQ 80220>" }, 156 { 0, 0, "<MII-compliant physical interface>" } 157}; 158 | 133#endif 134 135/* 136 * Various supported device vendors/types and their names. 137 */ 138static struct wb_type wb_devs[] = { 139 { WB_VENDORID, WB_DEVICEID_840F, 140 "Winbond W89C840F 10/100BaseTX" }, --- 13 unchanged lines hidden (view full) --- 154 { TI_PHY_VENDORID, TI_PHY_100VGPMI, "<TI TNETE211 100VG Any-LAN>" }, 155 { NS_PHY_VENDORID, NS_PHY_83840A, "<National Semiconductor DP83840A>"}, 156 { LEVEL1_PHY_VENDORID, LEVEL1_PHY_LXT970, "<Level 1 LXT970>" }, 157 { INTEL_PHY_VENDORID, INTEL_PHY_82555, "<Intel 82555>" }, 158 { SEEQ_PHY_VENDORID, SEEQ_PHY_80220, "<SEEQ 80220>" }, 159 { 0, 0, "<MII-compliant physical interface>" } 160}; 161 |
159static unsigned long wb_count = 0; 160static const char *wb_probe __P((pcici_t, pcidi_t)); 161static void wb_attach __P((pcici_t, int)); | 162static int wb_probe __P((device_t)); 163static int wb_attach __P((device_t)); 164static int wb_detach __P((device_t)); |
162 163static int wb_newbuf __P((struct wb_softc *, 164 struct wb_chain_onefrag *, 165 struct mbuf *)); 166static int wb_encap __P((struct wb_softc *, struct wb_chain *, 167 struct mbuf *)); 168 169static void wb_rxeof __P((struct wb_softc *)); 170static void wb_rxeoc __P((struct wb_softc *)); 171static void wb_txeof __P((struct wb_softc *)); 172static void wb_txeoc __P((struct wb_softc *)); 173static void wb_intr __P((void *)); 174static void wb_start __P((struct ifnet *)); 175static int wb_ioctl __P((struct ifnet *, u_long, caddr_t)); 176static void wb_init __P((void *)); 177static void wb_stop __P((struct wb_softc *)); 178static void wb_watchdog __P((struct ifnet *)); | 165 166static int wb_newbuf __P((struct wb_softc *, 167 struct wb_chain_onefrag *, 168 struct mbuf *)); 169static int wb_encap __P((struct wb_softc *, struct wb_chain *, 170 struct mbuf *)); 171 172static void wb_rxeof __P((struct wb_softc *)); 173static void wb_rxeoc __P((struct wb_softc *)); 174static void wb_txeof __P((struct wb_softc *)); 175static void wb_txeoc __P((struct wb_softc *)); 176static void wb_intr __P((void *)); 177static void wb_start __P((struct ifnet *)); 178static int wb_ioctl __P((struct ifnet *, u_long, caddr_t)); 179static void wb_init __P((void *)); 180static void wb_stop __P((struct wb_softc *)); 181static void wb_watchdog __P((struct ifnet *)); |
179static void wb_shutdown __P((int, void *)); | 182static void wb_shutdown __P((device_t)); |
180static int wb_ifmedia_upd __P((struct ifnet *)); 181static void wb_ifmedia_sts __P((struct ifnet *, struct ifmediareq *)); 182 183static void wb_eeprom_putbyte __P((struct wb_softc *, int)); 184static void wb_eeprom_getword __P((struct wb_softc *, int, u_int16_t *)); 185static void wb_read_eeprom __P((struct wb_softc *, caddr_t, int, 186 int, int)); 187static void wb_mii_sync __P((struct wb_softc *)); --- 9 unchanged lines hidden (view full) --- 197static void wb_getmode_mii __P((struct wb_softc *)); 198static void wb_setcfg __P((struct wb_softc *, int)); 199static u_int8_t wb_calchash __P((caddr_t)); 200static void wb_setmulti __P((struct wb_softc *)); 201static void wb_reset __P((struct wb_softc *)); 202static int wb_list_rx_init __P((struct wb_softc *)); 203static int wb_list_tx_init __P((struct wb_softc *)); 204 | 183static int wb_ifmedia_upd __P((struct ifnet *)); 184static void wb_ifmedia_sts __P((struct ifnet *, struct ifmediareq *)); 185 186static void wb_eeprom_putbyte __P((struct wb_softc *, int)); 187static void wb_eeprom_getword __P((struct wb_softc *, int, u_int16_t *)); 188static void wb_read_eeprom __P((struct wb_softc *, caddr_t, int, 189 int, int)); 190static void wb_mii_sync __P((struct wb_softc *)); --- 9 unchanged lines hidden (view full) --- 200static void wb_getmode_mii __P((struct wb_softc *)); 201static void wb_setcfg __P((struct wb_softc *, int)); 202static u_int8_t wb_calchash __P((caddr_t)); 203static void wb_setmulti __P((struct wb_softc *)); 204static void wb_reset __P((struct wb_softc *)); 205static int wb_list_rx_init __P((struct wb_softc *)); 206static int wb_list_tx_init __P((struct wb_softc *)); 207 |
208#ifdef WB_USEIOSPACE 209#define WB_RES SYS_RES_IOPORT 210#define WB_RID WB_PCI_LOIO 211#else 212#define WB_RES SYS_RES_MEMORY 213#define WB_RID WB_PCI_LOMEM 214#endif 215 216static device_method_t wb_methods[] = { 217 /* Device interface */ 218 DEVMETHOD(device_probe, wb_probe), 219 DEVMETHOD(device_attach, wb_attach), 220 DEVMETHOD(device_detach, wb_detach), 221 DEVMETHOD(device_shutdown, wb_shutdown), 222 { 0, 0 } 223}; 224 225static driver_t wb_driver = { 226 "wb", 227 wb_methods, 228 sizeof(struct wb_softc) 229}; 230 231static devclass_t wb_devclass; 232 233DRIVER_MODULE(wb, pci, wb_driver, wb_devclass, 0, 0); 234 |
|
205#define WB_SETBIT(sc, reg, x) \ 206 CSR_WRITE_4(sc, reg, \ 207 CSR_READ_4(sc, reg) | x) 208 209#define WB_CLRBIT(sc, reg, x) \ 210 CSR_WRITE_4(sc, reg, \ 211 CSR_READ_4(sc, reg) & ~x) 212 --- 783 unchanged lines hidden (view full) --- 996 997 return; 998} 999 1000/* 1001 * Probe for a Winbond chip. Check the PCI vendor and device 1002 * IDs against our list and return a device name if we find a match. 1003 */ | 235#define WB_SETBIT(sc, reg, x) \ 236 CSR_WRITE_4(sc, reg, \ 237 CSR_READ_4(sc, reg) | x) 238 239#define WB_CLRBIT(sc, reg, x) \ 240 CSR_WRITE_4(sc, reg, \ 241 CSR_READ_4(sc, reg) & ~x) 242 --- 783 unchanged lines hidden (view full) --- 1026 1027 return; 1028} 1029 1030/* 1031 * Probe for a Winbond chip. Check the PCI vendor and device 1032 * IDs against our list and return a device name if we find a match. 1033 */ |
1004static const char * 1005wb_probe(config_id, device_id) 1006 pcici_t config_id; 1007 pcidi_t device_id; | 1034static int wb_probe(dev) 1035 device_t dev; |
1008{ 1009 struct wb_type *t; 1010 1011 t = wb_devs; 1012 1013 while(t->wb_name != NULL) { | 1036{ 1037 struct wb_type *t; 1038 1039 t = wb_devs; 1040 1041 while(t->wb_name != NULL) { |
1014 if ((device_id & 0xFFFF) == t->wb_vid && 1015 ((device_id >> 16) & 0xFFFF) == t->wb_did) { 1016 return(t->wb_name); | 1042 if ((pci_get_vendor(dev) == t->wb_vid) && 1043 (pci_get_device(dev) == t->wb_did)) { 1044 device_set_desc(dev, t->wb_name); 1045 return(0); |
1017 } 1018 t++; 1019 } 1020 | 1046 } 1047 t++; 1048 } 1049 |
1021 return(NULL); | 1050 return(ENXIO); |
1022} 1023 1024/* 1025 * Attach the interface. Allocate softc structures, do ifmedia 1026 * setup and ethernet/BPF attach. 1027 */ | 1051} 1052 1053/* 1054 * Attach the interface. Allocate softc structures, do ifmedia 1055 * setup and ethernet/BPF attach. 1056 */ |
1028static void 1029wb_attach(config_id, unit) 1030 pcici_t config_id; 1031 int unit; | 1057static int wb_attach(dev) 1058 device_t dev; |
1032{ 1033 int s, i; | 1059{ 1060 int s, i; |
1034#ifndef WB_USEIOSPACE 1035 vm_offset_t pbase, vbase; 1036#endif | |
1037 u_char eaddr[ETHER_ADDR_LEN]; 1038 u_int32_t command; 1039 struct wb_softc *sc; 1040 struct ifnet *ifp; 1041 int media = IFM_ETHER|IFM_100_TX|IFM_FDX; 1042 unsigned int round; 1043 caddr_t roundptr; 1044 struct wb_type *p; 1045 u_int16_t phy_vid, phy_did, phy_sts; | 1061 u_char eaddr[ETHER_ADDR_LEN]; 1062 u_int32_t command; 1063 struct wb_softc *sc; 1064 struct ifnet *ifp; 1065 int media = IFM_ETHER|IFM_100_TX|IFM_FDX; 1066 unsigned int round; 1067 caddr_t roundptr; 1068 struct wb_type *p; 1069 u_int16_t phy_vid, phy_did, phy_sts; |
1070 int unit, error = 0, rid; |
|
1046 1047 s = splimp(); 1048 | 1071 1072 s = splimp(); 1073 |
1049 sc = malloc(sizeof(struct wb_softc), M_DEVBUF, M_NOWAIT); 1050 if (sc == NULL) { 1051 printf("wb%d: no memory for softc struct!\n", unit); 1052 return; 1053 } | 1074 sc = device_get_softc(dev); 1075 unit = device_get_unit(dev); |
1054 bzero(sc, sizeof(struct wb_softc)); 1055 1056 /* 1057 * Handle power management nonsense. 1058 */ 1059 | 1076 bzero(sc, sizeof(struct wb_softc)); 1077 1078 /* 1079 * Handle power management nonsense. 1080 */ 1081 |
1060 command = pci_conf_read(config_id, WB_PCI_CAPID) & 0x000000FF; | 1082 command = pci_read_config(dev, WB_PCI_CAPID, 4) & 0x000000FF; |
1061 if (command == 0x01) { 1062 | 1083 if (command == 0x01) { 1084 |
1063 command = pci_conf_read(config_id, WB_PCI_PWRMGMTCTRL); | 1085 command = pci_read_config(dev, WB_PCI_PWRMGMTCTRL, 4); |
1064 if (command & WB_PSTATE_MASK) { 1065 u_int32_t iobase, membase, irq; 1066 1067 /* Save important PCI config data. */ | 1086 if (command & WB_PSTATE_MASK) { 1087 u_int32_t iobase, membase, irq; 1088 1089 /* Save important PCI config data. */ |
1068 iobase = pci_conf_read(config_id, WB_PCI_LOIO); 1069 membase = pci_conf_read(config_id, WB_PCI_LOMEM); 1070 irq = pci_conf_read(config_id, WB_PCI_INTLINE); | 1090 iobase = pci_read_config(dev, WB_PCI_LOIO, 4); 1091 membase = pci_read_config(dev, WB_PCI_LOMEM, 4); 1092 irq = pci_read_config(dev, WB_PCI_INTLINE, 4); |
1071 1072 /* Reset the power state. */ 1073 printf("wb%d: chip is in D%d power mode " 1074 "-- setting to D0\n", unit, command & WB_PSTATE_MASK); 1075 command &= 0xFFFFFFFC; | 1093 1094 /* Reset the power state. */ 1095 printf("wb%d: chip is in D%d power mode " 1096 "-- setting to D0\n", unit, command & WB_PSTATE_MASK); 1097 command &= 0xFFFFFFFC; |
1076 pci_conf_write(config_id, WB_PCI_PWRMGMTCTRL, command); | 1098 pci_write_config(dev, WB_PCI_PWRMGMTCTRL, command, 4); |
1077 1078 /* Restore PCI config data. */ | 1099 1100 /* Restore PCI config data. */ |
1079 pci_conf_write(config_id, WB_PCI_LOIO, iobase); 1080 pci_conf_write(config_id, WB_PCI_LOMEM, membase); 1081 pci_conf_write(config_id, WB_PCI_INTLINE, irq); | 1101 pci_write_config(dev, WB_PCI_LOIO, iobase, 4); 1102 pci_write_config(dev, WB_PCI_LOMEM, membase, 4); 1103 pci_write_config(dev, WB_PCI_INTLINE, irq, 4); |
1082 } 1083 } 1084 1085 /* 1086 * Map control/status registers. 1087 */ | 1104 } 1105 } 1106 1107 /* 1108 * Map control/status registers. 1109 */ |
1088 command = pci_conf_read(config_id, PCI_COMMAND_STATUS_REG); | 1110 command = pci_read_config(dev, PCI_COMMAND_STATUS_REG, 4); |
1089 command |= (PCIM_CMD_PORTEN|PCIM_CMD_MEMEN|PCIM_CMD_BUSMASTEREN); | 1111 command |= (PCIM_CMD_PORTEN|PCIM_CMD_MEMEN|PCIM_CMD_BUSMASTEREN); |
1090 pci_conf_write(config_id, PCI_COMMAND_STATUS_REG, command); 1091 command = pci_conf_read(config_id, PCI_COMMAND_STATUS_REG); | 1112 pci_write_config(dev, PCI_COMMAND_STATUS_REG, command, 4); 1113 command = pci_read_config(dev, PCI_COMMAND_STATUS_REG, 4); |
1092 1093#ifdef WB_USEIOSPACE 1094 if (!(command & PCIM_CMD_PORTEN)) { 1095 printf("wb%d: failed to enable I/O ports!\n", unit); | 1114 1115#ifdef WB_USEIOSPACE 1116 if (!(command & PCIM_CMD_PORTEN)) { 1117 printf("wb%d: failed to enable I/O ports!\n", unit); |
1096 free(sc, M_DEVBUF); | 1118 error = ENXIO; |
1097 goto fail; 1098 } | 1119 goto fail; 1120 } |
1099 1100 if (!pci_map_port(config_id, WB_PCI_LOIO, 1101 (pci_port_t *)&(sc->wb_bhandle))) { 1102 printf ("wb%d: couldn't map ports\n", unit); 1103 goto fail; 1104 } 1105#ifdef __i386__ 1106 sc->wb_btag = I386_BUS_SPACE_IO; 1107#endif 1108#ifdef __alpha__ 1109 sc->wb_btag = ALPHA_BUS_SPACE_IO; 1110#endif | |
1111#else 1112 if (!(command & PCIM_CMD_MEMEN)) { 1113 printf("wb%d: failed to enable memory mapping!\n", unit); | 1121#else 1122 if (!(command & PCIM_CMD_MEMEN)) { 1123 printf("wb%d: failed to enable memory mapping!\n", unit); |
1124 error = ENXIO; |
|
1114 goto fail; 1115 } | 1125 goto fail; 1126 } |
1127#endif |
|
1116 | 1128 |
1117 if (!pci_map_mem(config_id, WB_PCI_LOMEM, &vbase, &pbase)) { 1118 printf ("wb%d: couldn't map memory\n", unit); | 1129 rid = WB_RID; 1130 sc->wb_res = bus_alloc_resource(dev, WB_RES, &rid, 1131 0, ~0, 1, RF_ACTIVE); 1132 1133 if (sc->wb_res == NULL) { 1134 printf("wb%d: couldn't map ports/memory\n", unit); 1135 error = ENXIO; |
1119 goto fail; 1120 } | 1136 goto fail; 1137 } |
1121#ifdef __i386__ 1122 sc->wb_btag = I386_BUS_SPACE_MEM; 1123#endif 1124#ifdef __alpha__ 1125 sc->wb_btag = I386_BUS_SPACE_MEM; 1126#endif 1127 sc->wb_bhandle = vbase; 1128#endif | |
1129 | 1138 |
1139 sc->wb_btag = rman_get_bustag(sc->wb_res); 1140 sc->wb_bhandle = rman_get_bushandle(sc->wb_res); 1141 |
|
1130 /* Allocate interrupt */ | 1142 /* Allocate interrupt */ |
1131 if (!pci_map_int(config_id, wb_intr, sc, &net_imask)) { | 1143 rid = 0; 1144 sc->wb_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1, 1145 RF_SHAREABLE | RF_ACTIVE); 1146 1147 if (sc->wb_irq == NULL) { |
1132 printf("wb%d: couldn't map interrupt\n", unit); | 1148 printf("wb%d: couldn't map interrupt\n", unit); |
1149 bus_release_resource(dev, WB_RES, WB_RID, sc->wb_res); 1150 error = ENXIO; |
|
1133 goto fail; 1134 } 1135 | 1151 goto fail; 1152 } 1153 |
1154 error = bus_setup_intr(dev, sc->wb_irq, INTR_TYPE_NET, 1155 wb_intr, sc, &sc->wb_intrhand); 1156 1157 if (error) { 1158 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->wb_irq); 1159 bus_release_resource(dev, WB_RES, WB_RID, sc->wb_res); 1160 printf("wb%d: couldn't set up irq\n", unit); 1161 goto fail; 1162 } 1163 |
|
1136 /* Reset the adapter. */ 1137 wb_reset(sc); 1138 1139 /* 1140 * Get station address from the EEPROM. 1141 */ 1142 wb_read_eeprom(sc, (caddr_t)&eaddr, 0, 3, 0); 1143 1144 /* 1145 * A Winbond chip was detected. Inform the world. 1146 */ 1147 printf("wb%d: Ethernet address: %6D\n", unit, eaddr, ":"); 1148 1149 sc->wb_unit = unit; 1150 bcopy(eaddr, (char *)&sc->arpcom.ac_enaddr, ETHER_ADDR_LEN); 1151 1152 sc->wb_ldata_ptr = malloc(sizeof(struct wb_list_data) + 8, 1153 M_DEVBUF, M_NOWAIT); 1154 if (sc->wb_ldata_ptr == NULL) { | 1164 /* Reset the adapter. */ 1165 wb_reset(sc); 1166 1167 /* 1168 * Get station address from the EEPROM. 1169 */ 1170 wb_read_eeprom(sc, (caddr_t)&eaddr, 0, 3, 0); 1171 1172 /* 1173 * A Winbond chip was detected. Inform the world. 1174 */ 1175 printf("wb%d: Ethernet address: %6D\n", unit, eaddr, ":"); 1176 1177 sc->wb_unit = unit; 1178 bcopy(eaddr, (char *)&sc->arpcom.ac_enaddr, ETHER_ADDR_LEN); 1179 1180 sc->wb_ldata_ptr = malloc(sizeof(struct wb_list_data) + 8, 1181 M_DEVBUF, M_NOWAIT); 1182 if (sc->wb_ldata_ptr == NULL) { |
1155 free(sc, M_DEVBUF); | |
1156 printf("wb%d: no memory for list buffers!\n", unit); | 1183 printf("wb%d: no memory for list buffers!\n", unit); |
1157 return; | 1184 bus_teardown_intr(dev, sc->wb_irq, sc->wb_intrhand); 1185 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->wb_irq); 1186 bus_release_resource(dev, WB_RES, WB_RID, sc->wb_res); 1187 error = ENXIO; 1188 goto fail; |
1158 } 1159 1160 sc->wb_ldata = (struct wb_list_data *)sc->wb_ldata_ptr; 1161 round = (uintptr_t)sc->wb_ldata_ptr & 0xF; 1162 roundptr = sc->wb_ldata_ptr; 1163 for (i = 0; i < 8; i++) { 1164 if (round % 8) { 1165 round++; --- 52 unchanged lines hidden (view full) --- 1218 } 1219 if (sc->wb_pinfo == NULL) 1220 sc->wb_pinfo = &wb_phys[PHY_UNKNOWN]; 1221 if (bootverbose) 1222 printf("wb%d: PHY type: %s\n", 1223 sc->wb_unit, sc->wb_pinfo->wb_name); 1224 } else { 1225 printf("wb%d: MII without any phy!\n", sc->wb_unit); | 1189 } 1190 1191 sc->wb_ldata = (struct wb_list_data *)sc->wb_ldata_ptr; 1192 round = (uintptr_t)sc->wb_ldata_ptr & 0xF; 1193 roundptr = sc->wb_ldata_ptr; 1194 for (i = 0; i < 8; i++) { 1195 if (round % 8) { 1196 round++; --- 52 unchanged lines hidden (view full) --- 1249 } 1250 if (sc->wb_pinfo == NULL) 1251 sc->wb_pinfo = &wb_phys[PHY_UNKNOWN]; 1252 if (bootverbose) 1253 printf("wb%d: PHY type: %s\n", 1254 sc->wb_unit, sc->wb_pinfo->wb_name); 1255 } else { 1256 printf("wb%d: MII without any phy!\n", sc->wb_unit); |
1257 bus_teardown_intr(dev, sc->wb_irq, sc->wb_intrhand); 1258 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->wb_irq); 1259 bus_release_resource(dev, WB_RES, WB_RID, sc->wb_res); 1260 free(sc->wb_ldata_ptr, M_DEVBUF); 1261 error = ENXIO; |
|
1226 goto fail; 1227 } 1228 1229 /* 1230 * Do ifmedia setup. 1231 */ 1232 ifmedia_init(&sc->ifmedia, 0, wb_ifmedia_upd, wb_ifmedia_sts); 1233 1234 wb_getmode_mii(sc); | 1262 goto fail; 1263 } 1264 1265 /* 1266 * Do ifmedia setup. 1267 */ 1268 ifmedia_init(&sc->ifmedia, 0, wb_ifmedia_upd, wb_ifmedia_sts); 1269 1270 wb_getmode_mii(sc); |
1235 wb_autoneg_mii(sc, WB_FLAG_FORCEDELAY, 1); | 1271 if (cold) { 1272 wb_autoneg_mii(sc, WB_FLAG_FORCEDELAY, 1); 1273 wb_stop(sc); 1274 } else { 1275 wb_init(sc); 1276 wb_autoneg_mii(sc, WB_FLAG_SCHEDDELAY, 1); 1277 } |
1236 media = sc->ifmedia.ifm_media; | 1278 media = sc->ifmedia.ifm_media; |
1237 wb_stop(sc); | |
1238 1239 ifmedia_set(&sc->ifmedia, media); 1240 1241 /* 1242 * Call MI attach routines. 1243 */ 1244 if_attach(ifp); 1245 ether_ifattach(ifp); 1246 1247#if NBPF > 0 1248 bpfattach(ifp, DLT_EN10MB, sizeof(struct ether_header)); 1249#endif | 1279 1280 ifmedia_set(&sc->ifmedia, media); 1281 1282 /* 1283 * Call MI attach routines. 1284 */ 1285 if_attach(ifp); 1286 ether_ifattach(ifp); 1287 1288#if NBPF > 0 1289 bpfattach(ifp, DLT_EN10MB, sizeof(struct ether_header)); 1290#endif |
1250 at_shutdown(wb_shutdown, sc, SHUTDOWN_POST_SYNC); | |
1251 1252fail: 1253 splx(s); | 1291 1292fail: 1293 splx(s); |
1254 return; | 1294 return(error); |
1255} 1256 | 1295} 1296 |
1297static int wb_detach(dev) 1298 device_t dev; 1299{ 1300 struct wb_softc *sc; 1301 struct ifnet *ifp; 1302 int s; 1303 1304 s = splimp(); 1305 1306 sc = device_get_softc(dev); 1307 ifp = &sc->arpcom.ac_if; 1308 1309 wb_stop(sc); 1310 if_detach(ifp); 1311 1312 bus_teardown_intr(dev, sc->wb_irq, sc->wb_intrhand); 1313 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->wb_irq); 1314 bus_release_resource(dev, WB_RES, WB_RID, sc->wb_res); 1315 1316 free(sc->wb_ldata_ptr, M_DEVBUF); 1317 ifmedia_removeall(&sc->ifmedia); 1318 1319 splx(s); 1320 1321 return(0); 1322} 1323 |
|
1257/* 1258 * Initialize the transmit descriptors. 1259 */ 1260static int wb_list_tx_init(sc) 1261 struct wb_softc *sc; 1262{ 1263 struct wb_chain_data *cd; 1264 struct wb_list_data *ld; --- 809 unchanged lines hidden (view full) --- 2074 struct ifnet *ifp; 2075{ 2076 struct wb_softc *sc; 2077 2078 sc = ifp->if_softc; 2079 2080 if (sc->wb_autoneg) { 2081 wb_autoneg_mii(sc, WB_FLAG_DELAYTIMEO, 1); | 1324/* 1325 * Initialize the transmit descriptors. 1326 */ 1327static int wb_list_tx_init(sc) 1328 struct wb_softc *sc; 1329{ 1330 struct wb_chain_data *cd; 1331 struct wb_list_data *ld; --- 809 unchanged lines hidden (view full) --- 2141 struct ifnet *ifp; 2142{ 2143 struct wb_softc *sc; 2144 2145 sc = ifp->if_softc; 2146 2147 if (sc->wb_autoneg) { 2148 wb_autoneg_mii(sc, WB_FLAG_DELAYTIMEO, 1); |
2149 if (!(ifp->if_flags & IFF_UP)) 2150 wb_stop(sc); |
|
2082 return; 2083 } 2084 2085 ifp->if_oerrors++; 2086 printf("wb%d: watchdog timeout\n", sc->wb_unit); 2087 2088 if (!(wb_phy_readreg(sc, PHY_BMSR) & PHY_BMSR_LINKSTAT)) 2089 printf("wb%d: no carrier - transceiver cable problem?\n", --- 56 unchanged lines hidden (view full) --- 2146 2147 return; 2148} 2149 2150/* 2151 * Stop all chip I/O so that the kernel's probe routines don't 2152 * get confused by errant DMAs when rebooting. 2153 */ | 2151 return; 2152 } 2153 2154 ifp->if_oerrors++; 2155 printf("wb%d: watchdog timeout\n", sc->wb_unit); 2156 2157 if (!(wb_phy_readreg(sc, PHY_BMSR) & PHY_BMSR_LINKSTAT)) 2158 printf("wb%d: no carrier - transceiver cable problem?\n", --- 56 unchanged lines hidden (view full) --- 2215 2216 return; 2217} 2218 2219/* 2220 * Stop all chip I/O so that the kernel's probe routines don't 2221 * get confused by errant DMAs when rebooting. 2222 */ |
2154static void wb_shutdown(howto, arg) 2155 int howto; 2156 void *arg; | 2223static void wb_shutdown(dev) 2224 device_t dev; |
2157{ | 2225{ |
2158 struct wb_softc *sc = (struct wb_softc *)arg; | 2226 struct wb_softc *sc; |
2159 | 2227 |
2228 sc = device_get_softc(dev); |
|
2160 wb_stop(sc); 2161 2162 return; 2163} | 2229 wb_stop(sc); 2230 2231 return; 2232} |
2164 2165static struct pci_device wb_device = { 2166 "wb", 2167 wb_probe, 2168 wb_attach, 2169 &wb_count, 2170 NULL 2171}; 2172COMPAT_PCI_DRIVER(wb, wb_device); | |