Home | History | Annotate | Line # | Download | only in pci
if_ne_pci.c revision 1.3
      1 /*	$NetBSD: if_ne_pci.c,v 1.3 1997/10/27 23:31:41 thorpej Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1997 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 "bpfilter.h"
     41 
     42 #include <sys/param.h>
     43 #include <sys/systm.h>
     44 #include <sys/mbuf.h>
     45 #include <sys/syslog.h>
     46 #include <sys/socket.h>
     47 #include <sys/device.h>
     48 
     49 #include <net/if.h>
     50 #include <net/if_ether.h>
     51 #include <net/if_media.h>
     52 
     53 #ifdef INET
     54 #include <netinet/in.h>
     55 #include <netinet/if_inarp.h>
     56 #endif
     57 
     58 #include <machine/bus.h>
     59 #include <machine/intr.h>
     60 
     61 #include <dev/pci/pcireg.h>
     62 #include <dev/pci/pcivar.h>
     63 #include <dev/pci/pcidevs.h>
     64 
     65 #include <dev/ic/dp8390reg.h>
     66 #include <dev/ic/dp8390var.h>
     67 
     68 #include <dev/ic/ne2000reg.h>
     69 #include <dev/ic/ne2000var.h>
     70 
     71 struct ne_pci_softc {
     72 	struct ne2000_softc sc_ne2000;		/* real "ne2000" softc */
     73 
     74 	/* PCI-specific goo */
     75 	void *sc_ih;				/* interrupt handle */
     76 };
     77 
     78 #ifdef __BROKEN_INDIRECT_CONFIG
     79 int ne_pci_match __P((struct device *, void *, void *));
     80 #else
     81 int ne_pci_match __P((struct device *, struct cfdata *, void *));
     82 #endif
     83 void ne_pci_attach __P((struct device *, struct device *, void *));
     84 
     85 struct cfattach ne_pci_ca = {
     86 	sizeof(struct ne_pci_softc), ne_pci_match, ne_pci_attach
     87 };
     88 
     89 /*
     90  * PCI constants.
     91  * XXX These should be in a common file!
     92  */
     93 #define PCI_CBIO	0x10		/* Configuration Base IO Address */
     94 
     95 int
     96 ne_pci_match(parent, match, aux)
     97 	struct device *parent;
     98 #ifdef __BROKEN_INDIRECT_CONFIG
     99 	void *match;
    100 #else
    101 	struct cfdata *match;
    102 #endif
    103 	void *aux;
    104 {
    105 	struct pci_attach_args *pa = aux;
    106 
    107 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_REALTEK) {
    108 		switch (PCI_PRODUCT(pa->pa_id)) {
    109 		case PCI_PRODUCT_REALTEK_RT8029:
    110 			return (1);
    111 		}
    112 	}
    113 
    114 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_WINBOND) {
    115 		switch (PCI_PRODUCT(pa->pa_id)) {
    116 		case PCI_PRODUCT_WINBOND_W89C940F:
    117 			return (1);
    118 		}
    119 	}
    120 
    121 	return (0);
    122 }
    123 
    124 void
    125 ne_pci_attach(parent, self, aux)
    126 	struct device *parent, *self;
    127 	void *aux;
    128 {
    129 	struct ne_pci_softc *psc = (struct ne_pci_softc *)self;
    130 	struct ne2000_softc *nsc = &psc->sc_ne2000;
    131 	struct dp8390_softc *dsc = &nsc->sc_dp8390;
    132 	struct pci_attach_args *pa = aux;
    133 	pci_chipset_tag_t pc = pa->pa_pc;
    134 	bus_space_tag_t nict;
    135 	bus_space_handle_t nich;
    136 	bus_space_tag_t asict;
    137 	bus_space_handle_t asich;
    138 	const char *typestr = NULL, *intrstr;
    139 	pci_intr_handle_t ih;
    140 	pcireg_t csr;
    141 
    142 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_REALTEK) {
    143 		switch (PCI_PRODUCT(pa->pa_id)) {
    144 		case PCI_PRODUCT_REALTEK_RT8029:
    145 			typestr = "Realtek 8029";
    146 			break;
    147 		}
    148 	}
    149 
    150 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_WINBOND) {
    151 		switch (PCI_PRODUCT(pa->pa_id)) {
    152 		case PCI_PRODUCT_WINBOND_NEXXX:
    153 			typestr = "Winbond";
    154 			break;
    155 		}
    156 	}
    157 
    158 	if (typestr == NULL) {
    159 		printf(": unknown model?!\n");
    160 		return;
    161 	}
    162 
    163 	printf(": %s Ethernet\n", typestr);
    164 
    165 	if (pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0,
    166 	    &nict, &nich, NULL, NULL)) {
    167 		printf("%s: can't map i/o space\n", dsc->sc_dev.dv_xname);
    168 		return;
    169 	}
    170 
    171 	asict = nict;
    172 	if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET,
    173 	    NE2000_ASIC_NPORTS, &asich)) {
    174 		printf("%s: can't subregion i/o space\n", dsc->sc_dev.dv_xname);
    175 		return;
    176 	}
    177 
    178 	dsc->sc_regt = nict;
    179 	dsc->sc_regh = nich;
    180 
    181 	nsc->sc_asict = asict;
    182 	nsc->sc_asich = asich;
    183 
    184 	/* Enable the card. */
    185 	csr = pci_conf_read(pc, pa->pa_tag,
    186 	    PCI_COMMAND_STATUS_REG);
    187 	pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
    188 	    csr | PCI_COMMAND_MASTER_ENABLE);
    189 
    190 	/* This interface is always enabled. */
    191 	dsc->sc_enabled = 1;
    192 
    193 	/*
    194 	 * Do generic NE2000 attach.  This will read the station address
    195 	 * from the EEPROM.
    196 	 */
    197 	ne2000_attach(nsc, NULL);
    198 
    199 	/* Map and establish the interrupt. */
    200 	if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,
    201 	    pa->pa_intrline, &ih)) {
    202 		printf("%s: couldn't map interrupt\n", dsc->sc_dev.dv_xname);
    203 		return;
    204 	}
    205 	intrstr = pci_intr_string(pc, ih);
    206 	psc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, dp8390_intr, dsc);
    207 	if (psc->sc_ih == NULL) {
    208 		printf("%s: couldn't establish interrupt",
    209 		    dsc->sc_dev.dv_xname);
    210 		if (intrstr != NULL)
    211 			printf(" at %s", intrstr);
    212 		printf("\n");
    213 		return;
    214 	}
    215 	printf("%s: interrupting at %s\n", dsc->sc_dev.dv_xname, intrstr);
    216 }
    217