Home | History | Annotate | Line # | Download | only in pci
if_gem_pci.c revision 1.3
      1 /*	$NetBSD: if_gem_pci.c,v 1.3 2001/10/18 03:48:48 thorpej Exp $ */
      2 
      3 /*
      4  *
      5  * Copyright (C) 2001 Eduardo Horvath.
      6  * All rights reserved.
      7  *
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR  ``AS IS'' AND
     19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR  BE LIABLE
     22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     28  * SUCH DAMAGE.
     29  *
     30  */
     31 
     32 /*
     33  * PCI bindings for Sun GEM ethernet controllers.
     34  */
     35 
     36 #include <sys/param.h>
     37 #include <sys/systm.h>
     38 #include <sys/malloc.h>
     39 #include <sys/kernel.h>
     40 #include <sys/socket.h>
     41 #include <sys/errno.h>
     42 #include <sys/device.h>
     43 
     44 #include <machine/endian.h>
     45 
     46 #include <uvm/uvm_extern.h>
     47 
     48 #include <net/if.h>
     49 #include <net/if_dl.h>
     50 #include <net/if_media.h>
     51 #include <net/if_ether.h>
     52 
     53 #if NBPFILTER > 0
     54 #include <net/bpf.h>
     55 #endif
     56 
     57 #include <machine/bus.h>
     58 #include <machine/intr.h>
     59 
     60 #include <dev/mii/mii.h>
     61 #include <dev/mii/miivar.h>
     62 #include <dev/mii/mii_bitbang.h>
     63 
     64 #include <dev/ic/gemreg.h>
     65 #include <dev/ic/gemvar.h>
     66 
     67 #include <dev/pci/pcivar.h>
     68 #include <dev/pci/pcireg.h>
     69 #include <dev/pci/pcidevs.h>
     70 
     71 struct gem_pci_softc {
     72 	struct	gem_softc	gsc_gem;	/* GEM device */
     73 	bus_space_tag_t		gsc_memt;
     74 	bus_space_handle_t	gsc_memh;
     75 	void			*gsc_ih;
     76 };
     77 
     78 int	gem_match_pci __P((struct device *, struct cfdata *, void *));
     79 void	gem_attach_pci __P((struct device *, struct device *, void *));
     80 
     81 struct cfattach gem_pci_ca = {
     82 	sizeof(struct gem_pci_softc), gem_match_pci, gem_attach_pci
     83 };
     84 
     85 /*
     86  * Attach routines need to be split out to different bus-specific files.
     87  */
     88 
     89 int
     90 gem_match_pci(parent, cf, aux)
     91 	struct device *parent;
     92 	struct cfdata *cf;
     93 	void *aux;
     94 {
     95 	struct pci_attach_args *pa = aux;
     96 
     97 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_SUN &&
     98 	       (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SUN_ERINETWORK ||
     99 		PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SUN_GEMNETWORK))
    100 		return (1);
    101 
    102 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_APPLE &&
    103 	       (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_GMAC ||
    104 		PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_APPLE_GMAC2))
    105 		return (1);
    106 
    107 
    108 	return (0);
    109 }
    110 
    111 void
    112 gem_attach_pci(parent, self, aux)
    113 	struct device *parent, *self;
    114 	void *aux;
    115 {
    116 	struct pci_attach_args *pa = aux;
    117 	struct gem_pci_softc *gsc = (void *)self;
    118 	struct gem_softc *sc = &gsc->gsc_gem;
    119 	pci_intr_handle_t intrhandle;
    120 	const char *intrstr;
    121 	char devinfo[256];
    122 
    123 	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
    124 	printf(": %s (rev. 0x%02x)\n", devinfo, PCI_REVISION(pa->pa_class));
    125 
    126 	sc->sc_dmatag = pa->pa_dmat;
    127 
    128 	sc->sc_pci = 1; /* XXXXX should all be done in bus_dma. */
    129 
    130 #define PCI_GEM_BASEADDR	(PCI_MAPREG_START + 0x00)
    131 
    132 	/* XXX Need to check for a 64-bit mem BAR? */
    133 	if (pci_mapreg_map(pa, PCI_GEM_BASEADDR,
    134 	    PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT, 0,
    135 	    &gsc->gsc_memt, &gsc->gsc_memh, NULL, NULL) != 0)
    136 	{
    137 		printf("%s: could not map gem registers\n",
    138 		    sc->sc_dev.dv_xname);
    139 		return;
    140 	}
    141 
    142 	sc->sc_bustag = gsc->gsc_memt;
    143 	sc->sc_h = gsc->gsc_memh;
    144 
    145 	/*
    146 	 * XXX This should be done with properties, when those are
    147 	 * XXX fleshed out.
    148 	 */
    149 #ifdef __sparc__
    150 	{
    151 		extern void myetheraddr __P((u_char *));
    152 		myetheraddr(sc->sc_enaddr);
    153 	}
    154 #endif
    155 
    156 	sc->sc_burst = 16;	/* XXX */
    157 
    158 	/*
    159 	 * call the main configure
    160 	 */
    161 	gem_config(sc);
    162 
    163 	if (pci_intr_map(pa, &intrhandle) != 0) {
    164 		printf("%s: couldn't map interrupt\n",
    165 		    sc->sc_dev.dv_xname);
    166 		return;	/* bus_unmap ? */
    167 	}
    168 	intrstr = pci_intr_string(pa->pa_pc, intrhandle);
    169 	gsc->gsc_ih = pci_intr_establish(pa->pa_pc,
    170 	    intrhandle, IPL_NET, gem_intr, sc);
    171 	if (gsc->gsc_ih != NULL) {
    172 		printf("%s: using %s for interrupt\n",
    173 		    sc->sc_dev.dv_xname,
    174 		    intrstr ? intrstr : "unknown interrupt");
    175 	} else {
    176 		printf("%s: couldn't establish interrupt",
    177 		    sc->sc_dev.dv_xname);
    178 		if (intrstr != NULL)
    179 			printf(" at %s", intrstr);
    180 		printf("\n");
    181 		return;
    182 	}
    183 }
    184