1 /* $OpenBSD: if_ne_pci.c,v 1.18 2011/04/03 15:36:02 jasper Exp $ */ 2 /* $NetBSD: if_ne_pci.c,v 1.8 1998/07/05 00:51:24 jonathan Exp $ */ 3 4 /*- 5 * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to The NetBSD Foundation 9 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 10 * NASA Ames Research Center. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer. 17 * 2. Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in the 19 * documentation and/or other materials provided with the distribution. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 * POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 #include "bpfilter.h" 35 36 #include <sys/param.h> 37 #include <sys/systm.h> 38 #include <sys/mbuf.h> 39 #include <sys/syslog.h> 40 #include <sys/socket.h> 41 #include <sys/device.h> 42 43 #include <net/if.h> 44 #include <net/if_media.h> 45 46 #ifdef INET 47 #include <netinet/in.h> 48 #include <netinet/if_ether.h> 49 #endif 50 51 #include <machine/bus.h> 52 #include <machine/intr.h> 53 54 #include <dev/pci/pcireg.h> 55 #include <dev/pci/pcivar.h> 56 #include <dev/pci/pcidevs.h> 57 58 #include <dev/mii/miivar.h> 59 60 #include <dev/ic/dp8390reg.h> 61 #include <dev/ic/dp8390var.h> 62 63 #include <dev/ic/ne2000reg.h> 64 #include <dev/ic/ne2000var.h> 65 66 #include <dev/ic/rtl80x9reg.h> 67 #include <dev/ic/rtl80x9var.h> 68 69 struct ne_pci_softc { 70 struct ne2000_softc sc_ne2000; /* real "ne2000" softc */ 71 72 /* PCI-specific goo */ 73 void *sc_ih; /* interrupt handle */ 74 }; 75 76 int ne_pci_match(struct device *, void *, void *); 77 void ne_pci_attach(struct device *, struct device *, void *); 78 79 struct cfattach ne_pci_ca = { 80 sizeof(struct ne_pci_softc), ne_pci_match, ne_pci_attach 81 }; 82 83 const struct ne_pci_product { 84 pci_vendor_id_t npp_vendor; 85 pci_product_id_t npp_product; 86 int (*npp_mediachange)(struct dp8390_softc *); 87 void (*npp_mediastatus)(struct dp8390_softc *, 88 struct ifmediareq *); 89 void (*npp_init_card)(struct dp8390_softc *); 90 void (*npp_media_init)(struct dp8390_softc *); 91 } ne_pci_prod[] = { 92 { PCI_VENDOR_REALTEK, PCI_PRODUCT_REALTEK_RT8029, 93 rtl80x9_mediachange, rtl80x9_mediastatus, 94 rtl80x9_init_card, rtl80x9_media_init, 95 /* RealTek 8029 */ }, 96 97 { PCI_VENDOR_WINBOND, PCI_PRODUCT_WINBOND_W89C940F, 98 NULL, NULL, 99 NULL, NULL, 100 /* Winbond 89C940F */ }, 101 102 { PCI_VENDOR_VIATECH, PCI_PRODUCT_VIATECH_VT86C926, 103 NULL, NULL, 104 NULL, NULL, 105 /* VIA Technologies VT86C926 */ }, 106 107 { PCI_VENDOR_SURECOM, PCI_PRODUCT_SURECOM_NE34, 108 NULL, NULL, 109 NULL, NULL, 110 /* Surecom NE-34 */ }, 111 112 { PCI_VENDOR_NETVIN, PCI_PRODUCT_NETVIN_NV5000, 113 NULL, NULL, 114 NULL, NULL, 115 /* NetVin 5000 */ }, 116 117 /* XXX The following entries need sanity checking in pcidevs */ 118 { PCI_VENDOR_COMPEX, PCI_PRODUCT_COMPEX_COMPEXE, 119 NULL, NULL, 120 NULL, NULL, 121 /* Compex */ }, 122 123 { PCI_VENDOR_WINBOND2, PCI_PRODUCT_WINBOND2_W89C940, 124 NULL, NULL, 125 NULL, NULL, 126 /* ProLAN */ }, 127 128 { PCI_VENDOR_KTI, PCI_PRODUCT_KTI_KTIE, 129 NULL, NULL, 130 NULL, NULL, 131 /* KTI */ }, 132 }; 133 134 const struct ne_pci_product *ne_pci_lookup(struct pci_attach_args *); 135 136 const struct ne_pci_product * 137 ne_pci_lookup(struct pci_attach_args *pa) 138 { 139 const struct ne_pci_product *npp; 140 141 for (npp = ne_pci_prod; 142 npp < &ne_pci_prod[nitems(ne_pci_prod)]; 143 npp++) { 144 if (PCI_VENDOR(pa->pa_id) == npp->npp_vendor && 145 PCI_PRODUCT(pa->pa_id) == npp->npp_product) 146 return (npp); 147 } 148 return (NULL); 149 } 150 151 /* 152 * PCI constants. 153 * XXX These should be in a common file! 154 */ 155 #define PCI_CBIO 0x10 /* Configuration Base IO Address */ 156 157 int 158 ne_pci_match(struct device *parent, void *match, void *aux) 159 { 160 struct pci_attach_args *pa = aux; 161 162 if (ne_pci_lookup(pa) != NULL) 163 return (1); 164 165 return (0); 166 } 167 168 void 169 ne_pci_attach(struct device *parent, struct device *self, void *aux) 170 { 171 struct ne_pci_softc *psc = (struct ne_pci_softc *)self; 172 struct ne2000_softc *nsc = &psc->sc_ne2000; 173 struct dp8390_softc *dsc = &nsc->sc_dp8390; 174 struct pci_attach_args *pa = aux; 175 pci_chipset_tag_t pc = pa->pa_pc; 176 bus_size_t iosize; 177 bus_space_tag_t nict; 178 bus_space_handle_t nich; 179 bus_space_tag_t asict; 180 bus_space_handle_t asich; 181 const char *intrstr; 182 const struct ne_pci_product *npp; 183 pci_intr_handle_t ih; 184 185 npp = ne_pci_lookup(pa); 186 if (npp == NULL) { 187 printf("\n"); 188 panic("ne_pci_attach: impossible"); 189 } 190 191 if (pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0, 192 &nict, &nich, NULL, &iosize, 0)) { 193 printf(": can't map i/o space\n"); 194 return; 195 } 196 197 asict = nict; 198 if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET, 199 NE2000_ASIC_NPORTS, &asich)) { 200 printf(": can't subregion i/o space\n"); 201 bus_space_unmap(nict, nich, iosize); 202 return; 203 } 204 205 dsc->sc_regt = nict; 206 dsc->sc_regh = nich; 207 208 nsc->sc_asict = asict; 209 nsc->sc_asich = asich; 210 211 /* This interface is always enabled. */ 212 dsc->sc_enabled = 1; 213 214 dsc->sc_mediachange = npp->npp_mediachange; 215 dsc->sc_mediastatus = npp->npp_mediastatus; 216 dsc->sc_media_init = npp->npp_media_init; 217 dsc->init_card = npp->npp_init_card; 218 219 /* Map and establish the interrupt. */ 220 if (pci_intr_map(pa, &ih)) { 221 printf(": couldn't map interrupt\n"); 222 bus_space_unmap(nict, nich, iosize); 223 return; 224 } 225 intrstr = pci_intr_string(pc, ih); 226 psc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, dp8390_intr, dsc, 227 dsc->sc_dev.dv_xname); 228 if (psc->sc_ih == NULL) { 229 printf(": couldn't establish interrupt"); 230 if (intrstr != NULL) 231 printf(" at %s", intrstr); 232 printf("\n"); 233 bus_space_unmap(nict, nich, iosize); 234 return; 235 } 236 printf(": %s", intrstr); 237 238 /* 239 * Do generic NE2000 attach. This will read the station address 240 * from the EEPROM. 241 */ 242 ne2000_attach(nsc, NULL); 243 } 244