1 /* $OpenBSD: if_fxp_pci.c,v 1.57 2011/04/03 15:36:02 jasper Exp $ */ 2 3 /* 4 * Copyright (c) 1995, David Greenman 5 * All rights reserved. 6 * 7 * Modifications to support NetBSD: 8 * Copyright (c) 1997 Jason R. Thorpe. All rights reserved. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice unmodified, this list of conditions, and the following 15 * disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * 32 * Id: if_fxp.c,v 1.55 1998/08/04 08:53:12 dg Exp 33 */ 34 35 /* 36 * Intel EtherExpress Pro/100B PCI Fast Ethernet driver 37 */ 38 39 #include "bpfilter.h" 40 41 #include <sys/param.h> 42 #include <sys/systm.h> 43 #include <sys/mbuf.h> 44 #include <sys/malloc.h> 45 #include <sys/kernel.h> 46 #include <sys/socket.h> 47 #include <sys/timeout.h> 48 #include <sys/syslog.h> 49 #include <sys/workq.h> 50 51 #include <net/if.h> 52 #include <net/if_dl.h> 53 #include <net/if_media.h> 54 #include <net/if_types.h> 55 56 #ifdef INET 57 #include <netinet/in.h> 58 #include <netinet/in_systm.h> 59 #include <netinet/in_var.h> 60 #include <netinet/ip.h> 61 #endif 62 63 #include <sys/ioctl.h> 64 #include <sys/errno.h> 65 #include <sys/device.h> 66 67 #include <netinet/if_ether.h> 68 69 #include <machine/cpu.h> 70 #include <machine/bus.h> 71 #include <machine/intr.h> 72 73 #include <dev/mii/miivar.h> 74 75 #include <dev/ic/fxpreg.h> 76 #include <dev/ic/fxpvar.h> 77 78 #include <dev/pci/pcivar.h> 79 #include <dev/pci/pcireg.h> 80 #include <dev/pci/pcidevs.h> 81 82 int fxp_pci_match(struct device *, void *, void *); 83 void fxp_pci_attach(struct device *, struct device *, void *); 84 int fxp_pci_detach(struct device *, int); 85 86 struct fxp_pci_softc { 87 struct fxp_softc psc_softc; 88 pci_chipset_tag_t psc_pc; 89 bus_size_t psc_mapsize; 90 }; 91 92 struct cfattach fxp_pci_ca = { 93 sizeof(struct fxp_pci_softc), fxp_pci_match, fxp_pci_attach, 94 fxp_pci_detach, fxp_activate 95 }; 96 97 const struct pci_matchid fxp_pci_devices[] = { 98 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_8255x }, 99 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82552 }, 100 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82559 }, 101 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82559ER }, 102 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82562 }, 103 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82562EH_HPNA_0 }, 104 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82562EH_HPNA_1 }, 105 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82562EH_HPNA_2 }, 106 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VE_0 }, 107 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VE_1 }, 108 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VE_2 }, 109 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VE_3 }, 110 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VE_4 }, 111 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VE_5 }, 112 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VE_6 }, 113 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VE_7 }, 114 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VE_8 }, 115 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_0 }, 116 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_1 }, 117 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_2 }, 118 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_3 }, 119 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_4 }, 120 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_5 }, 121 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_6 }, 122 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_7 }, 123 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_8 }, 124 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_9 }, 125 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_10 }, 126 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_11 }, 127 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_12 }, 128 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_13 }, 129 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_14 }, 130 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_15 }, 131 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_16 }, 132 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_17 }, 133 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_18 }, 134 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_19 }, 135 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_M }, 136 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100 }, 137 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801DB_LAN }, 138 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801E_LAN_1 }, 139 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801E_LAN_2 }, 140 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801FB_LAN }, 141 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801FB_LAN_2 }, 142 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801FBM_LAN }, 143 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801GB_LAN }, 144 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801GB_LAN_2 }, 145 }; 146 147 int 148 fxp_pci_match(struct device *parent, void *match, void *aux) 149 { 150 return (pci_matchbyid((struct pci_attach_args *)aux, fxp_pci_devices, 151 nitems(fxp_pci_devices))); 152 } 153 154 void 155 fxp_pci_attach(struct device *parent, struct device *self, void *aux) 156 { 157 struct fxp_pci_softc *psc = (void *)self; 158 struct fxp_softc *sc = &psc->psc_softc; 159 struct pci_attach_args *pa = aux; 160 pci_chipset_tag_t pc = pa->pa_pc; 161 pci_intr_handle_t ih; 162 const char *chipname = NULL; 163 const char *intrstr = NULL; 164 165 if (pci_mapreg_map(pa, FXP_PCI_IOBA, PCI_MAPREG_TYPE_IO, 0, 166 &sc->sc_st, &sc->sc_sh, NULL, &psc->psc_mapsize, 0)) { 167 printf(": can't map i/o space\n"); 168 return; 169 } 170 psc->psc_pc = pa->pa_pc; 171 sc->sc_dmat = pa->pa_dmat; 172 173 sc->sc_revision = PCI_REVISION(pa->pa_class); 174 175 /* 176 * Allocate our interrupt. 177 */ 178 if (pci_intr_map(pa, &ih)) { 179 printf(": couldn't map interrupt\n"); 180 bus_space_unmap(sc->sc_st, sc->sc_sh, psc->psc_mapsize); 181 return; 182 } 183 184 intrstr = pci_intr_string(pc, ih); 185 sc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, fxp_intr, sc, 186 self->dv_xname); 187 if (sc->sc_ih == NULL) { 188 printf(": couldn't establish interrupt"); 189 if (intrstr != NULL) 190 printf(" at %s", intrstr); 191 printf("\n"); 192 bus_space_unmap(sc->sc_st, sc->sc_sh, psc->psc_mapsize); 193 return; 194 } 195 196 switch (PCI_PRODUCT(pa->pa_id)) { 197 case PCI_PRODUCT_INTEL_8255x: 198 case PCI_PRODUCT_INTEL_82559: 199 case PCI_PRODUCT_INTEL_82559ER: 200 { 201 chipname = "i82557"; 202 if (sc->sc_revision >= FXP_REV_82558_A4) 203 chipname = "i82558"; 204 if (sc->sc_revision >= FXP_REV_82559_A0) 205 chipname = "i82559"; 206 if (sc->sc_revision >= FXP_REV_82559S_A) 207 chipname = "i82559S"; 208 if (sc->sc_revision >= FXP_REV_82550) 209 chipname = "i82550"; 210 if (sc->sc_revision >= FXP_REV_82551_E) 211 chipname = "i82551"; 212 break; 213 } 214 break; 215 case PCI_PRODUCT_INTEL_82552: 216 chipname = "i82552"; 217 break; 218 default: 219 chipname = "i82562"; 220 break; 221 } 222 223 if (chipname != NULL) 224 printf(", %s", chipname); 225 226 /* 227 * Cards for which we should WRITE TO THE EEPROM 228 * to turn off dynamic standby mode to avoid 229 * a problem where the card will fail to resume when 230 * entering the IDLE state. We use this nasty if statement 231 * and corresponding pci dev numbers directly so that people 232 * know not to add new cards to this unless you are really 233 * certain what you are doing and are not going to end up 234 * killing people's eeproms. 235 */ 236 if ((PCI_VENDOR(pa->pa_id) == PCI_VENDOR_INTEL) && 237 (PCI_PRODUCT(pa->pa_id) == 0x2449 || 238 (PCI_PRODUCT(pa->pa_id) > 0x1030 && 239 PCI_PRODUCT(pa->pa_id) < 0x1039) || 240 (PCI_PRODUCT(pa->pa_id) == 0x1229 && 241 (sc->sc_revision >= 8 && sc->sc_revision <= 16)))) 242 sc->sc_flags |= FXPF_DISABLE_STANDBY; 243 244 /* 245 * enable PCI Memory Write and Invalidate command 246 */ 247 if (sc->sc_revision >= FXP_REV_82558_A4) 248 if (PCI_CACHELINE(pci_conf_read(pa->pa_pc, pa->pa_tag, 249 PCI_BHLC_REG))) { 250 pci_conf_write(pa->pa_pc, pa->pa_tag, 251 PCI_COMMAND_STATUS_REG, 252 PCI_COMMAND_INVALIDATE_ENABLE | 253 pci_conf_read(pa->pa_pc, pa->pa_tag, 254 PCI_COMMAND_STATUS_REG)); 255 sc->sc_flags |= FXPF_MWI_ENABLE; 256 } 257 258 /* Do generic parts of attach. */ 259 if (fxp_attach(sc, intrstr)) { 260 /* Failed! */ 261 pci_intr_disestablish(pc, sc->sc_ih); 262 bus_space_unmap(sc->sc_st, sc->sc_sh, psc->psc_mapsize); 263 return; 264 } 265 } 266 267 int 268 fxp_pci_detach(struct device *self, int flags) 269 { 270 struct fxp_pci_softc *psc = (void *)self; 271 struct fxp_softc *sc = &psc->psc_softc; 272 273 if (sc->sc_ih != NULL) 274 pci_intr_disestablish(psc->psc_pc, sc->sc_ih); 275 fxp_detach(sc); 276 bus_space_unmap(sc->sc_st, sc->sc_sh, psc->psc_mapsize); 277 278 return (0); 279 } 280