Home | History | Annotate | Line # | Download | only in pci
if_epic_pci.c revision 1.4
      1 /*	$NetBSD: if_epic_pci.c,v 1.4 1998/07/05 06:49:15 jonathan Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 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 /*
     41  * PCI bus front-end for the Standard Microsystems Corp. 83C170
     42  * Ethernet PCI Integrated Controller (EPIC/100) driver.
     43  */
     44 
     45 #include "opt_inet.h"
     46 #include "opt_ns.h"
     47 #include "bpfilter.h"
     48 
     49 #include <sys/param.h>
     50 #include <sys/systm.h>
     51 #include <sys/mbuf.h>
     52 #include <sys/malloc.h>
     53 #include <sys/kernel.h>
     54 #include <sys/socket.h>
     55 #include <sys/ioctl.h>
     56 #include <sys/errno.h>
     57 #include <sys/device.h>
     58 
     59 #include <net/if.h>
     60 #include <net/if_dl.h>
     61 #include <net/if_media.h>
     62 #include <net/if_ether.h>
     63 
     64 #if NBPFILTER > 0
     65 #include <net/bpf.h>
     66 #endif
     67 
     68 #ifdef INET
     69 #include <netinet/in.h>
     70 #include <netinet/if_inarp.h>
     71 #endif
     72 
     73 #ifdef NS
     74 #include <netns/ns.h>
     75 #include <netns/ns_if.h>
     76 #endif
     77 
     78 #include <machine/bus.h>
     79 #include <machine/intr.h>
     80 
     81 #include <dev/ic/smc83c170reg.h>
     82 #include <dev/ic/smc83c170var.h>
     83 
     84 #include <dev/pci/pcivar.h>
     85 #include <dev/pci/pcireg.h>
     86 #include <dev/pci/pcidevs.h>
     87 
     88 /*
     89  * PCI configuration space registers used by the EPIC.
     90  */
     91 #define	EPIC_PCI_IOBA		0x10	/* i/o mapped base */
     92 #define	EPIC_PCI_MMBA		0x14	/* memory mapped base */
     93 
     94 struct epic_pci_softc {
     95 	struct epic_softc sc_epic;	/* real EPIC softc */
     96 
     97 	/* PCI-specific goo. */
     98 	void	*sc_ih;			/* interrupt handle */
     99 };
    100 
    101 int	epic_pci_match __P((struct device *, struct cfdata *, void *));
    102 void	epic_pci_attach __P((struct device *, struct device *, void *));
    103 
    104 struct cfattach epic_pci_ca = {
    105 	sizeof(struct epic_pci_softc), epic_pci_match, epic_pci_attach,
    106 };
    107 
    108 int
    109 epic_pci_match(parent, match, aux)
    110 	struct device *parent;
    111 	struct cfdata *match;
    112 	void *aux;
    113 {
    114 	struct pci_attach_args *pa = aux;
    115 
    116 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_SMC &&
    117 	    PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SMC_83C170)
    118 		return (1);
    119 
    120 	return (0);
    121 }
    122 
    123 void
    124 epic_pci_attach(parent, self, aux)
    125 	struct device *parent, *self;
    126 	void *aux;
    127 {
    128 	struct epic_pci_softc *psc = (struct epic_pci_softc *)self;
    129 	struct epic_softc *sc = &psc->sc_epic;
    130 	struct pci_attach_args *pa = aux;
    131 	pci_chipset_tag_t pc = pa->pa_pc;
    132 	pci_intr_handle_t ih;
    133 	const char *intrstr = NULL;
    134 	bus_space_tag_t iot, memt;
    135 	bus_space_handle_t ioh, memh;
    136 	int ioh_valid, memh_valid;
    137 
    138 	/*
    139 	 * Map the device.
    140 	 */
    141 	ioh_valid = (pci_mapreg_map(pa, EPIC_PCI_IOBA,
    142 	    PCI_MAPREG_TYPE_IO, 0,
    143 	    &iot, &ioh, NULL, NULL) == 0);
    144 	memh_valid = (pci_mapreg_map(pa, EPIC_PCI_MMBA,
    145 	    PCI_MAPREG_TYPE_MEM|PCI_MAPREG_MEM_TYPE_32BIT, 0,
    146 	    &memt, &memh, NULL, NULL) == 0);
    147 
    148 	if (memh_valid) {
    149 		sc->sc_st = memt;
    150 		sc->sc_sh = memh;
    151 	} else if (ioh_valid) {
    152 		sc->sc_st = iot;
    153 		sc->sc_sh = ioh;
    154 	} else {
    155 		printf(": unable to map device registers\n");
    156 		return;
    157 	}
    158 
    159 	sc->sc_dmat = pa->pa_dmat;
    160 
    161 	printf(": SMC EPIC/100 Fast Ethernet\n");
    162 
    163 	/*
    164 	 * Map and establish our interrupt.
    165 	 */
    166 	if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,
    167 	    pa->pa_intrline, &ih)) {
    168 		printf("%s: unable to map interrupt\n", sc->sc_dev.dv_xname);
    169 		return;
    170 	}
    171 	intrstr = pci_intr_string(pc, ih);
    172 	psc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, epic_intr, sc);
    173 	if (psc->sc_ih == NULL) {
    174 		printf("%s: unable to establish interrupt",
    175 		    sc->sc_dev.dv_xname);
    176 		if (intrstr != NULL)
    177 			printf(" at %s", intrstr);
    178 		printf("\n");
    179 		return;
    180 	}
    181 	printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
    182 
    183 	/*
    184 	 * Finish off the attach.
    185 	 */
    186 	epic_attach(sc);
    187 }
    188