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