Home | History | Annotate | Line # | Download | only in pci
if_hme_pci.c revision 1.1
      1 /*	$NetBSD: if_hme_pci.c,v 1.1 2000/04/05 02:31:19 mrg 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/autoconf.h>
     51 #include <machine/cpu.h>
     52 
     53 #include <dev/pci/pcivar.h>
     54 #include <dev/pci/pcireg.h>
     55 #include <dev/pci/pcidevs.h>
     56 
     57 #include <dev/ic/hmevar.h>
     58 
     59 struct hme_pci_softc {
     60 	struct	hme_softc	hsc_hme;	/* HME device */
     61 	bus_space_tag_t		hsc_memt;
     62 	bus_space_handle_t	hsc_memh;
     63 	void			*hsc_ih;
     64 };
     65 
     66 int	hmematch_pci __P((struct device *, struct cfdata *, void *));
     67 void	hmeattach_pci __P((struct device *, struct device *, void *));
     68 
     69 struct cfattach hme_pci_ca = {
     70 	sizeof(struct hme_pci_softc), hmematch_pci, hmeattach_pci
     71 };
     72 
     73 int
     74 hmematch_pci(parent, cf, aux)
     75 	struct device *parent;
     76 	struct cfdata *cf;
     77 	void *aux;
     78 {
     79 	struct pci_attach_args *pa = aux;
     80 
     81 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_SUN &&
     82 	    PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SUN_HMENETWORK)
     83 		return (1);
     84 
     85 	return (0);
     86 }
     87 
     88 void
     89 hmeattach_pci(parent, self, aux)
     90 	struct device *parent, *self;
     91 	void *aux;
     92 {
     93 	struct pci_attach_args *pa = aux;
     94 	struct hme_pci_softc *hsc = (void *)self;
     95 	struct hme_softc *sc = &hsc->hsc_hme;
     96 	pci_intr_handle_t intrhandle;
     97 	/* XXX the following declarations should be elsewhere */
     98 	extern void myetheraddr __P((u_char *));
     99 	pcireg_t csr;
    100 	const char *intrstr;
    101 	int type;
    102 
    103 	/*
    104 	 * enable io/memory-space accesses.  this is kinda of gross; but
    105 	 # the hme comes up with neither IO space enabled, or memory space.
    106 	 */
    107 	if (pa->pa_memt)
    108 		pa->pa_flags |= PCI_FLAGS_MEM_ENABLED;
    109 	if (pa->pa_iot)
    110 		pa->pa_flags |= PCI_FLAGS_IO_ENABLED;
    111 	csr = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
    112 	if (pa->pa_memt) {
    113 		type = PCI_MAPREG_TYPE_MEM;
    114 		csr |= PCI_COMMAND_MEM_ENABLE;
    115 		sc->sc_bustag = pa->pa_memt;
    116 	} else {
    117 		type = PCI_MAPREG_TYPE_IO;
    118 		csr |= PCI_COMMAND_IO_ENABLE;
    119 		sc->sc_bustag = pa->pa_iot;
    120 	}
    121 	pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
    122 	    csr | PCI_COMMAND_MEM_ENABLE);
    123 
    124 	sc->sc_dmatag = pa->pa_dmat;
    125 
    126 	/*
    127 	 * Map five register banks:
    128 	 *
    129 	 *	bank 0: HME SEB registers:	+0x0000
    130 	 *	bank 1: HME ETX registers:	+0x2000
    131 	 *	bank 2: HME ERX registers:	+0x4000
    132 	 *	bank 3: HME MAC registers:	+0x6000
    133 	 *	bank 4: HME MIF registers:	+0x7000
    134 	 *
    135 	 */
    136 
    137 #define PCI_HME_BASEADDR	0x10
    138 	if (pci_mapreg_map(pa, PCI_HME_BASEADDR, type, 0,
    139 	    &hsc->hsc_memt, &hsc->hsc_memh, NULL, NULL) != 0)
    140 	{
    141 		printf(": could not map hme registers\n");
    142 		return;
    143 	}
    144 	sc->sc_seb = hsc->hsc_memh;
    145 	sc->sc_etx = hsc->hsc_memh + 0x2000;
    146 	sc->sc_erx = hsc->hsc_memh + 0x4000;
    147 	sc->sc_mac = hsc->hsc_memh + 0x6000;
    148 	sc->sc_mif = hsc->hsc_memh + 0x7000;
    149 
    150 	myetheraddr(sc->sc_enaddr);
    151 
    152 #if 0
    153 	/*
    154 	 * Get transfer burst size from PROM and pass it on
    155 	 * to the back-end driver.
    156 	 */
    157 	sbusburst = ((struct sbus_softc *)parent)->sc_burst;
    158 	if (sbusburst == 0)
    159 		sbusburst = SBUS_BURST_32 - 1; /* 1->16 */
    160 
    161 	burst = getpropint(node, "burst-sizes", -1);
    162 	if (burst == -1)
    163 		/* take SBus burst sizes */
    164 		burst = sbusburst;
    165 
    166 	/* Clamp at parent's burst sizes */
    167 	burst &= sbusburst;
    168 
    169 	/* Translate into plain numerical format */
    170 	sc->sc_burst =  (burst & SBUS_BURST_32) ? 32 :
    171 			(burst & SBUS_BURST_16) ? 16 : 0;
    172 #endif
    173 
    174 	sc->sc_burst = 16;	/* XXX */
    175 
    176 	/*
    177 	 * call the main configure
    178 	 */
    179 	hme_config(sc);
    180 
    181 #if 0
    182 printf("%s: ", sc->sc_dev.dv_xname);
    183 pci_conf_print(pa->pa_pc, pa->pa_tag, 0);
    184 #endif
    185 
    186 	if (pci_intr_map(pa->pa_pc, pa->pa_intrtag, pa->pa_intrpin,
    187 	    pa->pa_intrline, &intrhandle) != 0) {
    188 		printf("%s: couldn't map interrupt\n",
    189 		    sc->sc_dev.dv_xname);
    190 		return;	/* bus_unmap ? */
    191 	}
    192 	intrstr = pci_intr_string(pa->pa_pc, intrhandle);
    193 	hsc->hsc_ih = pci_intr_establish(pa->pa_pc,
    194 	    intrhandle, IPL_NET, hme_intr, sc);
    195 	if (hsc->hsc_ih != NULL) {
    196 		printf("%s: using %s for interrupt\n",
    197 		    sc->sc_dev.dv_xname,
    198 		    intrstr ? intrstr : "unknown interrupt");
    199 	} else {
    200 		printf("%s: couldn't establish interrupt",
    201 		    sc->sc_dev.dv_xname);
    202 		if (intrstr != NULL)
    203 			printf(" at %s", intrstr);
    204 		printf("\n");
    205 		return;	/* bus_unmap ? */
    206 	}
    207 }
    208