Home | History | Annotate | Line # | Download | only in sbus
if_hme_sbus.c revision 1.6.2.5
      1  1.6.2.3  nathanw /*	$NetBSD: if_hme_sbus.c,v 1.6.2.5 2002/08/27 23:47:01 nathanw Exp $	*/
      2      1.1       pk 
      3      1.1       pk /*-
      4      1.1       pk  * Copyright (c) 1999 The NetBSD Foundation, Inc.
      5      1.1       pk  * All rights reserved.
      6      1.1       pk  *
      7      1.1       pk  * This code is derived from software contributed to The NetBSD Foundation
      8      1.1       pk  * by Paul Kranenburg.
      9      1.1       pk  *
     10      1.1       pk  * Redistribution and use in source and binary forms, with or without
     11      1.1       pk  * modification, are permitted provided that the following conditions
     12      1.1       pk  * are met:
     13      1.1       pk  * 1. Redistributions of source code must retain the above copyright
     14      1.1       pk  *    notice, this list of conditions and the following disclaimer.
     15      1.1       pk  * 2. Redistributions in binary form must reproduce the above copyright
     16      1.1       pk  *    notice, this list of conditions and the following disclaimer in the
     17      1.1       pk  *    documentation and/or other materials provided with the distribution.
     18      1.1       pk  * 3. All advertising materials mentioning features or use of this software
     19      1.1       pk  *    must display the following acknowledgement:
     20      1.1       pk  *        This product includes software developed by the NetBSD
     21      1.1       pk  *        Foundation, Inc. and its contributors.
     22      1.1       pk  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23      1.1       pk  *    contributors may be used to endorse or promote products derived
     24      1.1       pk  *    from this software without specific prior written permission.
     25      1.1       pk  *
     26      1.1       pk  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27      1.1       pk  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28      1.1       pk  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29      1.1       pk  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30      1.1       pk  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31      1.1       pk  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32      1.1       pk  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33      1.1       pk  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34      1.1       pk  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35      1.1       pk  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36      1.1       pk  * POSSIBILITY OF SUCH DAMAGE.
     37      1.1       pk  */
     38      1.1       pk 
     39      1.1       pk /*
     40      1.1       pk  * SBus front-end device driver for the HME ethernet device.
     41      1.1       pk  */
     42  1.6.2.3  nathanw 
     43  1.6.2.3  nathanw #include <sys/cdefs.h>
     44  1.6.2.3  nathanw __KERNEL_RCSID(0, "$NetBSD: if_hme_sbus.c,v 1.6.2.5 2002/08/27 23:47:01 nathanw Exp $");
     45      1.1       pk 
     46      1.1       pk #include <sys/param.h>
     47      1.1       pk #include <sys/systm.h>
     48      1.1       pk #include <sys/syslog.h>
     49      1.1       pk #include <sys/device.h>
     50      1.1       pk #include <sys/malloc.h>
     51      1.1       pk #include <sys/socket.h>
     52      1.1       pk 
     53      1.1       pk #include <net/if.h>
     54      1.1       pk #include <net/if_dl.h>
     55      1.1       pk #include <net/if_ether.h>
     56      1.1       pk #include <net/if_media.h>
     57      1.1       pk 
     58      1.1       pk #include <dev/mii/mii.h>
     59      1.1       pk #include <dev/mii/miivar.h>
     60      1.1       pk 
     61      1.5       pk #include <machine/bus.h>
     62      1.5       pk #include <machine/intr.h>
     63      1.1       pk #include <machine/autoconf.h>
     64      1.1       pk 
     65      1.1       pk #include <dev/sbus/sbusvar.h>
     66      1.1       pk #include <dev/ic/hmevar.h>
     67      1.1       pk 
     68      1.1       pk struct hmesbus_softc {
     69      1.1       pk 	struct	hme_softc	hsc_hme;	/* HME device */
     70      1.1       pk 	struct	sbusdev		hsc_sbus;	/* SBus device */
     71      1.1       pk };
     72      1.1       pk 
     73      1.1       pk int	hmematch_sbus __P((struct device *, struct cfdata *, void *));
     74      1.1       pk void	hmeattach_sbus __P((struct device *, struct device *, void *));
     75      1.1       pk 
     76      1.1       pk struct cfattach hme_sbus_ca = {
     77      1.1       pk 	sizeof(struct hmesbus_softc), hmematch_sbus, hmeattach_sbus
     78      1.1       pk };
     79      1.1       pk 
     80      1.1       pk int
     81      1.1       pk hmematch_sbus(parent, cf, aux)
     82      1.1       pk 	struct device *parent;
     83      1.1       pk 	struct cfdata *cf;
     84      1.1       pk 	void *aux;
     85      1.1       pk {
     86      1.1       pk 	struct sbus_attach_args *sa = aux;
     87      1.1       pk 
     88      1.2      mrg 	return (strcmp(cf->cf_driver->cd_name, sa->sa_name) == 0 ||
     89      1.6      mrg 	    strcmp("SUNW,qfe", sa->sa_name) == 0 ||
     90      1.2      mrg 	    strcmp("SUNW,hme", sa->sa_name) == 0);
     91      1.1       pk }
     92      1.1       pk 
     93      1.1       pk void
     94      1.1       pk hmeattach_sbus(parent, self, aux)
     95      1.1       pk 	struct device *parent, *self;
     96      1.1       pk 	void *aux;
     97      1.1       pk {
     98      1.1       pk 	struct sbus_attach_args *sa = aux;
     99      1.1       pk 	struct hmesbus_softc *hsc = (void *)self;
    100      1.1       pk 	struct hme_softc *sc = &hsc->hsc_hme;
    101      1.1       pk 	struct sbusdev *sd = &hsc->hsc_sbus;
    102      1.1       pk 	u_int32_t burst, sbusburst;
    103      1.1       pk 	int node;
    104  1.6.2.2  nathanw 
    105      1.1       pk 	/* XXX the following declarations should be elsewhere */
    106      1.1       pk 	extern void myetheraddr __P((u_char *));
    107      1.1       pk 
    108      1.1       pk 	node = sa->sa_node;
    109      1.1       pk 
    110      1.1       pk 	/* Pass on the bus tags */
    111      1.1       pk 	sc->sc_bustag = sa->sa_bustag;
    112      1.1       pk 	sc->sc_dmatag = sa->sa_dmatag;
    113      1.1       pk 
    114  1.6.2.2  nathanw 	printf(": Sun Happy Meal Ethernet (%s)\n",
    115  1.6.2.2  nathanw 	    sa->sa_name);
    116  1.6.2.2  nathanw 
    117      1.1       pk 	if (sa->sa_nreg < 5) {
    118      1.1       pk 		printf("%s: only %d register sets\n",
    119      1.1       pk 			self->dv_xname, sa->sa_nreg);
    120      1.1       pk 		return;
    121      1.1       pk 	}
    122      1.1       pk 
    123      1.1       pk 	/*
    124      1.1       pk 	 * Map five register banks:
    125      1.1       pk 	 *
    126      1.1       pk 	 *	bank 0: HME SEB registers
    127      1.1       pk 	 *	bank 1: HME ETX registers
    128      1.1       pk 	 *	bank 2: HME ERX registers
    129      1.1       pk 	 *	bank 3: HME MAC registers
    130      1.1       pk 	 *	bank 4: HME MIF registers
    131      1.1       pk 	 *
    132      1.1       pk 	 */
    133      1.1       pk 	if (sbus_bus_map(sa->sa_bustag,
    134  1.6.2.5  nathanw 			 sa->sa_reg[0].oa_space,
    135  1.6.2.5  nathanw 			 sa->sa_reg[0].oa_base,
    136  1.6.2.5  nathanw 			 (bus_size_t)sa->sa_reg[0].oa_size,
    137  1.6.2.4  nathanw 			 0, &sc->sc_seb) != 0) {
    138  1.6.2.2  nathanw 		printf("%s: cannot map SEB registers\n", self->dv_xname);
    139      1.1       pk 		return;
    140      1.1       pk 	}
    141      1.1       pk 	if (sbus_bus_map(sa->sa_bustag,
    142  1.6.2.5  nathanw 			 sa->sa_reg[1].oa_space,
    143  1.6.2.5  nathanw 			 sa->sa_reg[1].oa_base,
    144  1.6.2.5  nathanw 			 (bus_size_t)sa->sa_reg[1].oa_size,
    145  1.6.2.4  nathanw 			 0, &sc->sc_etx) != 0) {
    146  1.6.2.2  nathanw 		printf("%s: cannot map ETX registers\n", self->dv_xname);
    147      1.1       pk 		return;
    148      1.1       pk 	}
    149      1.1       pk 	if (sbus_bus_map(sa->sa_bustag,
    150  1.6.2.5  nathanw 			 sa->sa_reg[2].oa_space,
    151  1.6.2.5  nathanw 			 sa->sa_reg[2].oa_base,
    152  1.6.2.5  nathanw 			 (bus_size_t)sa->sa_reg[2].oa_size,
    153  1.6.2.4  nathanw 			 0, &sc->sc_erx) != 0) {
    154  1.6.2.2  nathanw 		printf("%s: cannot map ERX registers\n", self->dv_xname);
    155      1.1       pk 		return;
    156      1.1       pk 	}
    157      1.1       pk 	if (sbus_bus_map(sa->sa_bustag,
    158  1.6.2.5  nathanw 			 sa->sa_reg[3].oa_space,
    159  1.6.2.5  nathanw 			 sa->sa_reg[3].oa_base,
    160  1.6.2.5  nathanw 			 (bus_size_t)sa->sa_reg[3].oa_size,
    161  1.6.2.4  nathanw 			 0, &sc->sc_mac) != 0) {
    162  1.6.2.2  nathanw 		printf("%s: cannot map MAC registers\n", self->dv_xname);
    163      1.1       pk 		return;
    164      1.1       pk 	}
    165      1.1       pk 	if (sbus_bus_map(sa->sa_bustag,
    166  1.6.2.5  nathanw 			 sa->sa_reg[4].oa_space,
    167  1.6.2.5  nathanw 			 sa->sa_reg[4].oa_base,
    168  1.6.2.5  nathanw 			 (bus_size_t)sa->sa_reg[4].oa_size,
    169  1.6.2.4  nathanw 			 0, &sc->sc_mif) != 0) {
    170  1.6.2.2  nathanw 		printf("%s: cannot map MIF registers\n", self->dv_xname);
    171      1.1       pk 		return;
    172      1.1       pk 	}
    173      1.1       pk 
    174      1.1       pk 	sd->sd_reset = (void *)hme_reset;
    175      1.1       pk 	sbus_establish(sd, self);
    176      1.1       pk 
    177      1.1       pk 	myetheraddr(sc->sc_enaddr);
    178      1.1       pk 
    179      1.1       pk 	/*
    180      1.1       pk 	 * Get transfer burst size from PROM and pass it on
    181      1.1       pk 	 * to the back-end driver.
    182      1.1       pk 	 */
    183      1.1       pk 	sbusburst = ((struct sbus_softc *)parent)->sc_burst;
    184      1.1       pk 	if (sbusburst == 0)
    185      1.1       pk 		sbusburst = SBUS_BURST_32 - 1; /* 1->16 */
    186      1.1       pk 
    187  1.6.2.1  nathanw 	burst = PROM_getpropint(node, "burst-sizes", -1);
    188      1.1       pk 	if (burst == -1)
    189      1.1       pk 		/* take SBus burst sizes */
    190      1.1       pk 		burst = sbusburst;
    191      1.1       pk 
    192      1.1       pk 	/* Clamp at parent's burst sizes */
    193      1.1       pk 	burst &= sbusburst;
    194      1.1       pk 
    195      1.1       pk 	/* Translate into plain numerical format */
    196      1.1       pk 	sc->sc_burst =  (burst & SBUS_BURST_32) ? 32 :
    197      1.1       pk 			(burst & SBUS_BURST_16) ? 16 : 0;
    198      1.1       pk 
    199      1.4      eeh 	sc->sc_pci = 0; /* XXXXX should all be done in bus_dma. */
    200      1.1       pk 	hme_config(sc);
    201      1.1       pk 
    202      1.3       pk 	/* Establish interrupt handler */
    203      1.3       pk 	if (sa->sa_nintr != 0)
    204      1.5       pk 		(void)bus_intr_establish(sa->sa_bustag, sa->sa_pri, IPL_NET, 0,
    205      1.3       pk 					 hme_intr, sc);
    206      1.1       pk }
    207