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