1 /* $OpenBSD: if_fxp_pci.c,v 1.60 2013/12/06 21:03:04 deraadt 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 50 #include <net/if.h> 51 #include <net/if_dl.h> 52 #include <net/if_media.h> 53 #include <net/if_types.h> 54 55 #ifdef INET 56 #include <netinet/in.h> 57 #include <netinet/in_systm.h> 58 #include <netinet/ip.h> 59 #endif 60 61 #include <sys/ioctl.h> 62 #include <sys/errno.h> 63 #include <sys/device.h> 64 65 #include <netinet/if_ether.h> 66 67 #include <machine/cpu.h> 68 #include <machine/bus.h> 69 #include <machine/intr.h> 70 71 #include <dev/mii/miivar.h> 72 73 #include <dev/ic/fxpreg.h> 74 #include <dev/ic/fxpvar.h> 75 76 #include <dev/pci/pcivar.h> 77 #include <dev/pci/pcireg.h> 78 #include <dev/pci/pcidevs.h> 79 80 int fxp_pci_match(struct device *, void *, void *); 81 void fxp_pci_attach(struct device *, struct device *, void *); 82 int fxp_pci_detach(struct device *, int); 83 84 struct fxp_pci_softc { 85 struct fxp_softc psc_softc; 86 pci_chipset_tag_t psc_pc; 87 bus_size_t psc_mapsize; 88 }; 89 90 struct cfattach fxp_pci_ca = { 91 sizeof(struct fxp_pci_softc), fxp_pci_match, fxp_pci_attach, 92 fxp_pci_detach, fxp_activate 93 }; 94 95 const struct pci_matchid fxp_pci_devices[] = { 96 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_8255x }, 97 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82552 }, 98 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82559 }, 99 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82559ER }, 100 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82562 }, 101 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82562EH_HPNA_0 }, 102 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82562EH_HPNA_1 }, 103 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82562EH_HPNA_2 }, 104 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VE_0 }, 105 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VE_1 }, 106 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VE_2 }, 107 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VE_3 }, 108 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VE_4 }, 109 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VE_5 }, 110 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VE_6 }, 111 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VE_7 }, 112 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VE_8 }, 113 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_0 }, 114 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_1 }, 115 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_2 }, 116 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_3 }, 117 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_4 }, 118 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_5 }, 119 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_6 }, 120 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_7 }, 121 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_8 }, 122 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_9 }, 123 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_10 }, 124 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_11 }, 125 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_12 }, 126 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_13 }, 127 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_14 }, 128 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_15 }, 129 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_16 }, 130 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_17 }, 131 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_18 }, 132 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_19 }, 133 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_M }, 134 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100 }, 135 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801DB_LAN }, 136 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801E_LAN_1 }, 137 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801E_LAN_2 }, 138 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801FB_LAN }, 139 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801FB_LAN_2 }, 140 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801FBM_LAN }, 141 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801GB_LAN }, 142 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801GB_LAN_2 }, 143 }; 144 145 int 146 fxp_pci_match(struct device *parent, void *match, void *aux) 147 { 148 return (pci_matchbyid((struct pci_attach_args *)aux, fxp_pci_devices, 149 nitems(fxp_pci_devices))); 150 } 151 152 void 153 fxp_pci_attach(struct device *parent, struct device *self, void *aux) 154 { 155 struct fxp_pci_softc *psc = (void *)self; 156 struct fxp_softc *sc = &psc->psc_softc; 157 struct pci_attach_args *pa = aux; 158 pci_chipset_tag_t pc = pa->pa_pc; 159 pci_intr_handle_t ih; 160 const char *chipname = NULL; 161 const char *intrstr = NULL; 162 163 if (pci_mapreg_map(pa, FXP_PCI_IOBA, PCI_MAPREG_TYPE_IO, 0, 164 &sc->sc_st, &sc->sc_sh, NULL, &psc->psc_mapsize, 0)) { 165 printf(": can't map i/o space\n"); 166 return; 167 } 168 psc->psc_pc = pa->pa_pc; 169 sc->sc_dmat = pa->pa_dmat; 170 171 sc->sc_revision = PCI_REVISION(pa->pa_class); 172 173 /* 174 * Allocate our interrupt. 175 */ 176 if (pci_intr_map(pa, &ih)) { 177 printf(": couldn't map interrupt\n"); 178 bus_space_unmap(sc->sc_st, sc->sc_sh, psc->psc_mapsize); 179 return; 180 } 181 182 intrstr = pci_intr_string(pc, ih); 183 sc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, fxp_intr, sc, 184 self->dv_xname); 185 if (sc->sc_ih == NULL) { 186 printf(": couldn't establish interrupt"); 187 if (intrstr != NULL) 188 printf(" at %s", intrstr); 189 printf("\n"); 190 bus_space_unmap(sc->sc_st, sc->sc_sh, psc->psc_mapsize); 191 return; 192 } 193 194 switch (PCI_PRODUCT(pa->pa_id)) { 195 case PCI_PRODUCT_INTEL_8255x: 196 case PCI_PRODUCT_INTEL_82559: 197 case PCI_PRODUCT_INTEL_82559ER: 198 { 199 chipname = "i82557"; 200 if (sc->sc_revision >= FXP_REV_82558_A4) 201 chipname = "i82558"; 202 if (sc->sc_revision >= FXP_REV_82559_A0) 203 chipname = "i82559"; 204 if (sc->sc_revision >= FXP_REV_82559S_A) 205 chipname = "i82559S"; 206 if (sc->sc_revision >= FXP_REV_82550) 207 chipname = "i82550"; 208 if (sc->sc_revision >= FXP_REV_82551_E) 209 chipname = "i82551"; 210 break; 211 } 212 break; 213 case PCI_PRODUCT_INTEL_82552: 214 chipname = "i82552"; 215 break; 216 default: 217 chipname = "i82562"; 218 break; 219 } 220 221 if (chipname != NULL) 222 printf(", %s", chipname); 223 224 /* 225 * Cards for which we should WRITE TO THE EEPROM 226 * to turn off dynamic standby mode to avoid 227 * a problem where the card will fail to resume when 228 * entering the IDLE state. We use this nasty if statement 229 * and corresponding pci dev numbers directly so that people 230 * know not to add new cards to this unless you are really 231 * certain what you are doing and are not going to end up 232 * killing people's eeproms. 233 */ 234 if ((PCI_VENDOR(pa->pa_id) == PCI_VENDOR_INTEL) && 235 (PCI_PRODUCT(pa->pa_id) == 0x2449 || 236 (PCI_PRODUCT(pa->pa_id) > 0x1030 && 237 PCI_PRODUCT(pa->pa_id) < 0x1039) || 238 (PCI_PRODUCT(pa->pa_id) == 0x1229 && 239 (sc->sc_revision >= 8 && sc->sc_revision <= 16)))) 240 sc->sc_flags |= FXPF_DISABLE_STANDBY; 241 242 /* 243 * enable PCI Memory Write and Invalidate command 244 */ 245 if (sc->sc_revision >= FXP_REV_82558_A4) 246 if (PCI_CACHELINE(pci_conf_read(pa->pa_pc, pa->pa_tag, 247 PCI_BHLC_REG))) { 248 pci_conf_write(pa->pa_pc, pa->pa_tag, 249 PCI_COMMAND_STATUS_REG, 250 PCI_COMMAND_INVALIDATE_ENABLE | 251 pci_conf_read(pa->pa_pc, pa->pa_tag, 252 PCI_COMMAND_STATUS_REG)); 253 sc->sc_flags |= FXPF_MWI_ENABLE; 254 } 255 256 /* Do generic parts of attach. */ 257 if (fxp_attach(sc, intrstr)) { 258 /* Failed! */ 259 pci_intr_disestablish(pc, sc->sc_ih); 260 bus_space_unmap(sc->sc_st, sc->sc_sh, psc->psc_mapsize); 261 return; 262 } 263 } 264 265 int 266 fxp_pci_detach(struct device *self, int flags) 267 { 268 struct fxp_pci_softc *psc = (void *)self; 269 struct fxp_softc *sc = &psc->psc_softc; 270 271 if (sc->sc_ih != NULL) 272 pci_intr_disestablish(psc->psc_pc, sc->sc_ih); 273 fxp_detach(sc); 274 bus_space_unmap(sc->sc_st, sc->sc_sh, psc->psc_mapsize); 275 276 return (0); 277 } 278