Home | History | Annotate | Line # | Download | only in pci
if_hme_pci.c revision 1.5.2.2
      1 /*	$NetBSD: if_hme_pci.c,v 1.5.2.2 2001/10/11 00:02:10 fvdl Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2000 Matthew R. Green
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. The name of the author may not be used to endorse or promote products
     16  *    derived from this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     23  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     25  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     26  * 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  * PCI front-end device driver for the HME ethernet device.
     33  */
     34 
     35 #include <sys/param.h>
     36 #include <sys/systm.h>
     37 #include <sys/syslog.h>
     38 #include <sys/device.h>
     39 #include <sys/malloc.h>
     40 #include <sys/socket.h>
     41 
     42 #include <net/if.h>
     43 #include <net/if_dl.h>
     44 #include <net/if_ether.h>
     45 #include <net/if_media.h>
     46 
     47 #include <dev/mii/mii.h>
     48 #include <dev/mii/miivar.h>
     49 
     50 #include <machine/intr.h>
     51 
     52 #include <dev/pci/pcivar.h>
     53 #include <dev/pci/pcireg.h>
     54 #include <dev/pci/pcidevs.h>
     55 
     56 #include <dev/ic/hmevar.h>
     57 
     58 struct hme_pci_softc {
     59 	struct	hme_softc	hsc_hme;	/* HME device */
     60 	bus_space_tag_t		hsc_memt;
     61 	bus_space_handle_t	hsc_memh;
     62 	void			*hsc_ih;
     63 };
     64 
     65 int	hmematch_pci __P((struct device *, struct cfdata *, void *));
     66 void	hmeattach_pci __P((struct device *, struct device *, void *));
     67 
     68 struct cfattach hme_pci_ca = {
     69 	sizeof(struct hme_pci_softc), hmematch_pci, hmeattach_pci
     70 };
     71 
     72 int
     73 hmematch_pci(parent, cf, aux)
     74 	struct device *parent;
     75 	struct cfdata *cf;
     76 	void *aux;
     77 {
     78 	struct pci_attach_args *pa = aux;
     79 
     80 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_SUN &&
     81 	    PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SUN_HMENETWORK)
     82 		return (1);
     83 
     84 	return (0);
     85 }
     86 
     87 void
     88 hmeattach_pci(parent, self, aux)
     89 	struct device *parent, *self;
     90 	void *aux;
     91 {
     92 	struct pci_attach_args *pa = aux;
     93 	struct hme_pci_softc *hsc = (void *)self;
     94 	struct hme_softc *sc = &hsc->hsc_hme;
     95 	pci_intr_handle_t ih;
     96 	pcireg_t csr;
     97 	const char *intrstr;
     98 	int type;
     99 
    100 	/* XXX the following declarations should be elsewhere */
    101 	extern void myetheraddr __P((u_char *));
    102 
    103 	printf(": Sun Happy Meal Ethernet, rev. %d\n",
    104 	    PCI_REVISION(pa->pa_class));
    105 
    106 	/*
    107 	 * enable io/memory-space accesses.  this is kinda of gross; but
    108 	 # the hme comes up with neither IO space enabled, or memory space.
    109 	 */
    110 	if (pa->pa_memt)
    111 		pa->pa_flags |= PCI_FLAGS_MEM_ENABLED;
    112 	if (pa->pa_iot)
    113 		pa->pa_flags |= PCI_FLAGS_IO_ENABLED;
    114 	csr = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
    115 	if (pa->pa_memt) {
    116 		type = PCI_MAPREG_TYPE_MEM;
    117 		csr |= PCI_COMMAND_MEM_ENABLE;
    118 		sc->sc_bustag = pa->pa_memt;
    119 	} else {
    120 		type = PCI_MAPREG_TYPE_IO;
    121 		csr |= PCI_COMMAND_IO_ENABLE;
    122 		sc->sc_bustag = pa->pa_iot;
    123 	}
    124 	pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
    125 	    csr | PCI_COMMAND_MEM_ENABLE);
    126 
    127 	sc->sc_dmatag = pa->pa_dmat;
    128 
    129 	sc->sc_pci = 1; /* XXXXX should all be done in bus_dma. */
    130 	/*
    131 	 * Map five register banks:
    132 	 *
    133 	 *	bank 0: HME SEB registers:	+0x0000
    134 	 *	bank 1: HME ETX registers:	+0x2000
    135 	 *	bank 2: HME ERX registers:	+0x4000
    136 	 *	bank 3: HME MAC registers:	+0x6000
    137 	 *	bank 4: HME MIF registers:	+0x7000
    138 	 *
    139 	 */
    140 
    141 #define PCI_HME_BASEADDR	0x10
    142 	if (pci_mapreg_map(pa, PCI_HME_BASEADDR, type, 0,
    143 	    &hsc->hsc_memt, &hsc->hsc_memh, NULL, NULL) != 0)
    144 	{
    145 		printf("%s: unable to map device registers\n",
    146 		    sc->sc_dev.dv_xname);
    147 		return;
    148 	}
    149 	sc->sc_seb = hsc->hsc_memh;
    150 	if (bus_space_subregion(hsc->hsc_memt, hsc->hsc_memh, 0x2000,
    151 	    0x1000, &sc->sc_etx)) {
    152 		printf("%s: unable to subregion ETX registers\n",
    153 		    sc->sc_dev.dv_xname);
    154 		return;
    155 	}
    156 	if (bus_space_subregion(hsc->hsc_memt, hsc->hsc_memh, 0x4000,
    157 	    0x1000, &sc->sc_erx)) {
    158 		printf("%s: unable to subregion ERX registers\n",
    159 		    sc->sc_dev.dv_xname);
    160 		return;
    161 	}
    162 	if (bus_space_subregion(hsc->hsc_memt, hsc->hsc_memh, 0x6000,
    163 	    0x1000, &sc->sc_mac)) {
    164 		printf("%s: unable to subregion MAC registers\n",
    165 		    sc->sc_dev.dv_xname);
    166 		return;
    167 	}
    168 	if (bus_space_subregion(hsc->hsc_memt, hsc->hsc_memh, 0x7000,
    169 	    0x1000, &sc->sc_mif)) {
    170 		printf("%s: unable to subregion MIF registers\n",
    171 		    sc->sc_dev.dv_xname);
    172 		return;
    173 	}
    174 
    175 	myetheraddr(sc->sc_enaddr);
    176 
    177 	/*
    178 	 * Map and establish our interrupt.
    179 	 */
    180 	if (pci_intr_map(pa, &ih) != 0) {
    181 		printf("%s: unable to map interrupt\n", sc->sc_dev.dv_xname);
    182 		return;
    183 	}
    184 	intrstr = pci_intr_string(pa->pa_pc, ih);
    185 	hsc->hsc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_NET, hme_intr, sc);
    186 	if (hsc->hsc_ih == NULL) {
    187 		printf("%s: unable to establish interrupt",
    188 		    sc->sc_dev.dv_xname);
    189 		if (intrstr != NULL)
    190 			printf(" at %s", intrstr);
    191 		printf("\n");
    192 	}
    193 	printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
    194 
    195 #if 0
    196 	/*
    197 	 * Get transfer burst size from PROM and pass it on
    198 	 * to the back-end driver.
    199 	 */
    200 	sbusburst = ((struct sbus_softc *)parent)->sc_burst;
    201 	if (sbusburst == 0)
    202 		sbusburst = SBUS_BURST_32 - 1; /* 1->16 */
    203 
    204 	burst = PROM_getpropint(node, "burst-sizes", -1);
    205 	if (burst == -1)
    206 		/* take SBus burst sizes */
    207 		burst = sbusburst;
    208 
    209 	/* Clamp at parent's burst sizes */
    210 	burst &= sbusburst;
    211 
    212 	/* Translate into plain numerical format */
    213 	sc->sc_burst =  (burst & SBUS_BURST_32) ? 32 :
    214 			(burst & SBUS_BURST_16) ? 16 : 0;
    215 #endif
    216 
    217 	sc->sc_burst = 16;	/* XXX */
    218 
    219 	/* Finish off the attach. */
    220 	hme_config(sc);
    221 }
    222