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