1 /* $OpenBSD: if_fxp_pci.c,v 1.21 2003/09/29 19:29:22 mickey 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/syslog.h> 48 49 #include <net/if.h> 50 #include <net/if_dl.h> 51 #include <net/if_media.h> 52 #include <net/if_types.h> 53 54 #ifdef INET 55 #include <netinet/in.h> 56 #include <netinet/in_systm.h> 57 #include <netinet/in_var.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 <uvm/uvm_extern.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 85 struct cfattach fxp_pci_ca = { 86 sizeof(struct fxp_softc), fxp_pci_match, fxp_pci_attach 87 }; 88 89 const struct pci_matchid fxp_pci_devices[] = { 90 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82557 }, 91 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82559 }, 92 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82559ER }, 93 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82562 }, 94 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82562EH_HPNA_0 }, 95 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82562EH_HPNA_1 }, 96 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82562EH_HPNA_2 }, 97 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VE_0 }, 98 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VE_1 }, 99 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VE_2 }, 100 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VE_3 }, 101 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VE_4 }, 102 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VE_5 }, 103 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_0 }, 104 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_1 }, 105 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_2 }, 106 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_3 }, 107 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_4 }, 108 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_VM_5 }, 109 { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_PRO_100_M }, 110 }; 111 112 /* 113 * Check if a device is an 82557. 114 */ 115 int 116 fxp_pci_match(parent, match, aux) 117 struct device *parent; 118 void *match; 119 void *aux; 120 { 121 return (pci_matchbyid((struct pci_attach_args *)aux, fxp_pci_devices, 122 sizeof(fxp_pci_devices)/sizeof(fxp_pci_devices[0]))); 123 } 124 125 void 126 fxp_pci_attach(parent, self, aux) 127 struct device *parent, *self; 128 void *aux; 129 { 130 struct fxp_softc *sc = (struct fxp_softc *)self; 131 struct pci_attach_args *pa = aux; 132 pci_chipset_tag_t pc = pa->pa_pc; 133 pci_intr_handle_t ih; 134 const char *intrstr = NULL; 135 u_int8_t enaddr[6]; 136 bus_size_t iosize; 137 pcireg_t rev = PCI_REVISION(pa->pa_class); 138 139 if (pci_mapreg_map(pa, FXP_PCI_IOBA, PCI_MAPREG_TYPE_IO, 0, 140 &sc->sc_st, &sc->sc_sh, NULL, &iosize, 0)) { 141 printf(": can't find i/o space\n"); 142 return; 143 } 144 145 sc->sc_dmat = pa->pa_dmat; 146 147 /* 148 * Allocate our interrupt. 149 */ 150 if (pci_intr_map(pa, &ih)) { 151 printf(": couldn't map interrupt\n"); 152 bus_space_unmap(sc->sc_st, sc->sc_sh, iosize); 153 return; 154 } 155 156 intrstr = pci_intr_string(pc, ih); 157 sc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, fxp_intr, sc, 158 self->dv_xname); 159 if (sc->sc_ih == NULL) { 160 printf(": couldn't establish interrupt"); 161 if (intrstr != NULL) 162 printf(" at %s", intrstr); 163 printf("\n"); 164 bus_space_unmap(sc->sc_st, sc->sc_sh, iosize); 165 return; 166 } 167 168 switch (PCI_PRODUCT(pa->pa_id)) { 169 case PCI_PRODUCT_INTEL_82562: 170 sc->sc_flags |= FXPF_HAS_RESUME_BUG; 171 /* FALLTHROUGH */ 172 case PCI_PRODUCT_INTEL_82559: 173 case PCI_PRODUCT_INTEL_82559ER: 174 sc->not_82557 = 1; 175 break; 176 case PCI_PRODUCT_INTEL_82557: 177 /* 178 * revisions 179 * 2 = 82557 180 * 4-6 = 82558 181 * 8 = 82559 182 */ 183 sc->not_82557 = (rev >= 4) ? 1 : 0; 184 break; 185 case PCI_PRODUCT_INTEL_PRO_100_VE_0: 186 case PCI_PRODUCT_INTEL_PRO_100_VE_1: 187 case PCI_PRODUCT_INTEL_PRO_100_VE_2: 188 case PCI_PRODUCT_INTEL_PRO_100_VE_3: 189 case PCI_PRODUCT_INTEL_PRO_100_VE_4: 190 case PCI_PRODUCT_INTEL_PRO_100_VM_0: 191 case PCI_PRODUCT_INTEL_PRO_100_VM_1: 192 case PCI_PRODUCT_INTEL_PRO_100_VM_2: 193 case PCI_PRODUCT_INTEL_PRO_100_VM_3: 194 case PCI_PRODUCT_INTEL_PRO_100_VM_4: 195 sc->sc_flags |= FXPF_HAS_RESUME_BUG; 196 sc->not_82557 = 0; 197 break; 198 default: 199 sc->not_82557 = 0; 200 break; 201 } 202 203 /* Do generic parts of attach. */ 204 if (fxp_attach_common(sc, enaddr, intrstr)) { 205 /* Failed! */ 206 pci_intr_disestablish(pc, sc->sc_ih); 207 bus_space_unmap(sc->sc_st, sc->sc_sh, iosize); 208 return; 209 } 210 } 211