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