Home | History | Annotate | Line # | Download | only in sbus
if_hme_sbus.c revision 1.23.4.1
      1  1.23.4.1     yamt /*	$NetBSD: if_hme_sbus.c,v 1.23.4.1 2008/05/16 02:25:02 yamt 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  *
     19       1.1       pk  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20       1.1       pk  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21       1.1       pk  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22       1.1       pk  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23       1.1       pk  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24       1.1       pk  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25       1.1       pk  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26       1.1       pk  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27       1.1       pk  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28       1.1       pk  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29       1.1       pk  * POSSIBILITY OF SUCH DAMAGE.
     30       1.1       pk  */
     31       1.1       pk 
     32       1.1       pk /*
     33       1.1       pk  * SBus front-end device driver for the HME ethernet device.
     34       1.1       pk  */
     35       1.9    lukem 
     36       1.9    lukem #include <sys/cdefs.h>
     37  1.23.4.1     yamt __KERNEL_RCSID(0, "$NetBSD: if_hme_sbus.c,v 1.23.4.1 2008/05/16 02:25:02 yamt Exp $");
     38       1.1       pk 
     39       1.1       pk #include <sys/param.h>
     40       1.1       pk #include <sys/systm.h>
     41       1.1       pk #include <sys/syslog.h>
     42       1.1       pk #include <sys/device.h>
     43       1.1       pk #include <sys/malloc.h>
     44       1.1       pk #include <sys/socket.h>
     45       1.1       pk 
     46       1.1       pk #include <net/if.h>
     47       1.1       pk #include <net/if_dl.h>
     48       1.1       pk #include <net/if_ether.h>
     49       1.1       pk #include <net/if_media.h>
     50       1.1       pk 
     51       1.1       pk #include <dev/mii/mii.h>
     52       1.1       pk #include <dev/mii/miivar.h>
     53       1.1       pk 
     54      1.22       ad #include <sys/bus.h>
     55      1.22       ad #include <sys/intr.h>
     56       1.1       pk #include <machine/autoconf.h>
     57       1.1       pk 
     58       1.1       pk #include <dev/sbus/sbusvar.h>
     59       1.1       pk #include <dev/ic/hmevar.h>
     60       1.1       pk 
     61       1.1       pk struct hmesbus_softc {
     62       1.1       pk 	struct	hme_softc	hsc_hme;	/* HME device */
     63       1.1       pk 	struct	sbusdev		hsc_sbus;	/* SBus device */
     64       1.1       pk };
     65       1.1       pk 
     66      1.20    perry int	hmematch_sbus(struct device *, struct cfdata *, void *);
     67      1.20    perry void	hmeattach_sbus(struct device *, struct device *, void *);
     68       1.1       pk 
     69      1.15  thorpej CFATTACH_DECL(hme_sbus, sizeof(struct hmesbus_softc),
     70      1.16  thorpej     hmematch_sbus, hmeattach_sbus, NULL, NULL);
     71       1.1       pk 
     72       1.1       pk int
     73       1.1       pk hmematch_sbus(parent, cf, aux)
     74       1.1       pk 	struct device *parent;
     75       1.1       pk 	struct cfdata *cf;
     76       1.1       pk 	void *aux;
     77       1.1       pk {
     78       1.1       pk 	struct sbus_attach_args *sa = aux;
     79       1.1       pk 
     80      1.13  thorpej 	return (strcmp(cf->cf_name, sa->sa_name) == 0 ||
     81       1.6      mrg 	    strcmp("SUNW,qfe", sa->sa_name) == 0 ||
     82       1.2      mrg 	    strcmp("SUNW,hme", sa->sa_name) == 0);
     83       1.1       pk }
     84       1.1       pk 
     85       1.1       pk void
     86       1.1       pk hmeattach_sbus(parent, self, aux)
     87       1.1       pk 	struct device *parent, *self;
     88       1.1       pk 	void *aux;
     89       1.1       pk {
     90       1.1       pk 	struct sbus_attach_args *sa = aux;
     91       1.1       pk 	struct hmesbus_softc *hsc = (void *)self;
     92       1.1       pk 	struct hme_softc *sc = &hsc->hsc_hme;
     93       1.1       pk 	struct sbusdev *sd = &hsc->hsc_sbus;
     94       1.1       pk 	u_int32_t burst, sbusburst;
     95       1.1       pk 	int node;
     96       1.8  thorpej 
     97       1.1       pk 	node = sa->sa_node;
     98       1.1       pk 
     99       1.1       pk 	/* Pass on the bus tags */
    100       1.1       pk 	sc->sc_bustag = sa->sa_bustag;
    101       1.1       pk 	sc->sc_dmatag = sa->sa_dmatag;
    102       1.1       pk 
    103       1.8  thorpej 	printf(": Sun Happy Meal Ethernet (%s)\n",
    104       1.8  thorpej 	    sa->sa_name);
    105       1.8  thorpej 
    106       1.1       pk 	if (sa->sa_nreg < 5) {
    107       1.1       pk 		printf("%s: only %d register sets\n",
    108      1.23   cegger 			device_xname(self), sa->sa_nreg);
    109       1.1       pk 		return;
    110       1.1       pk 	}
    111       1.1       pk 
    112       1.1       pk 	/*
    113       1.1       pk 	 * Map five register banks:
    114       1.1       pk 	 *
    115       1.1       pk 	 *	bank 0: HME SEB registers
    116       1.1       pk 	 *	bank 1: HME ETX registers
    117       1.1       pk 	 *	bank 2: HME ERX registers
    118       1.1       pk 	 *	bank 3: HME MAC registers
    119       1.1       pk 	 *	bank 4: HME MIF registers
    120       1.1       pk 	 *
    121       1.1       pk 	 */
    122       1.1       pk 	if (sbus_bus_map(sa->sa_bustag,
    123      1.12  thorpej 			 sa->sa_reg[0].oa_space,
    124      1.12  thorpej 			 sa->sa_reg[0].oa_base,
    125      1.12  thorpej 			 (bus_size_t)sa->sa_reg[0].oa_size,
    126      1.11      eeh 			 0, &sc->sc_seb) != 0) {
    127      1.23   cegger 		aprint_error_dev(self, "cannot map SEB registers\n");
    128       1.1       pk 		return;
    129       1.1       pk 	}
    130       1.1       pk 	if (sbus_bus_map(sa->sa_bustag,
    131      1.12  thorpej 			 sa->sa_reg[1].oa_space,
    132      1.12  thorpej 			 sa->sa_reg[1].oa_base,
    133      1.12  thorpej 			 (bus_size_t)sa->sa_reg[1].oa_size,
    134      1.11      eeh 			 0, &sc->sc_etx) != 0) {
    135      1.23   cegger 		aprint_error_dev(self, "cannot map ETX registers\n");
    136       1.1       pk 		return;
    137       1.1       pk 	}
    138       1.1       pk 	if (sbus_bus_map(sa->sa_bustag,
    139      1.12  thorpej 			 sa->sa_reg[2].oa_space,
    140      1.12  thorpej 			 sa->sa_reg[2].oa_base,
    141      1.12  thorpej 			 (bus_size_t)sa->sa_reg[2].oa_size,
    142      1.11      eeh 			 0, &sc->sc_erx) != 0) {
    143      1.23   cegger 		aprint_error_dev(self, "cannot map ERX registers\n");
    144       1.1       pk 		return;
    145       1.1       pk 	}
    146       1.1       pk 	if (sbus_bus_map(sa->sa_bustag,
    147      1.12  thorpej 			 sa->sa_reg[3].oa_space,
    148      1.12  thorpej 			 sa->sa_reg[3].oa_base,
    149      1.12  thorpej 			 (bus_size_t)sa->sa_reg[3].oa_size,
    150      1.11      eeh 			 0, &sc->sc_mac) != 0) {
    151      1.23   cegger 		aprint_error_dev(self, "cannot map MAC registers\n");
    152       1.1       pk 		return;
    153       1.1       pk 	}
    154       1.1       pk 	if (sbus_bus_map(sa->sa_bustag,
    155      1.12  thorpej 			 sa->sa_reg[4].oa_space,
    156      1.12  thorpej 			 sa->sa_reg[4].oa_base,
    157      1.12  thorpej 			 (bus_size_t)sa->sa_reg[4].oa_size,
    158      1.11      eeh 			 0, &sc->sc_mif) != 0) {
    159      1.23   cegger 		aprint_error_dev(self, "cannot map MIF registers\n");
    160       1.1       pk 		return;
    161       1.1       pk 	}
    162       1.1       pk 
    163       1.1       pk 	sd->sd_reset = (void *)hme_reset;
    164       1.1       pk 	sbus_establish(sd, self);
    165       1.1       pk 
    166      1.18       pk 	prom_getether(node, sc->sc_enaddr);
    167       1.1       pk 
    168       1.1       pk 	/*
    169       1.1       pk 	 * Get transfer burst size from PROM and pass it on
    170       1.1       pk 	 * to the back-end driver.
    171       1.1       pk 	 */
    172       1.1       pk 	sbusburst = ((struct sbus_softc *)parent)->sc_burst;
    173       1.1       pk 	if (sbusburst == 0)
    174       1.1       pk 		sbusburst = SBUS_BURST_32 - 1; /* 1->16 */
    175       1.1       pk 
    176      1.19       pk 	burst = prom_getpropint(node, "burst-sizes", -1);
    177       1.1       pk 	if (burst == -1)
    178       1.1       pk 		/* take SBus burst sizes */
    179       1.1       pk 		burst = sbusburst;
    180       1.1       pk 
    181       1.1       pk 	/* Clamp at parent's burst sizes */
    182       1.1       pk 	burst &= sbusburst;
    183       1.1       pk 
    184       1.1       pk 	/* Translate into plain numerical format */
    185       1.1       pk 	sc->sc_burst =  (burst & SBUS_BURST_32) ? 32 :
    186       1.1       pk 			(burst & SBUS_BURST_16) ? 16 : 0;
    187       1.1       pk 
    188       1.4      eeh 	sc->sc_pci = 0; /* XXXXX should all be done in bus_dma. */
    189       1.1       pk 	hme_config(sc);
    190       1.1       pk 
    191       1.3       pk 	/* Establish interrupt handler */
    192       1.3       pk 	if (sa->sa_nintr != 0)
    193      1.17       pk 		(void)bus_intr_establish(sa->sa_bustag, sa->sa_pri, IPL_NET,
    194       1.3       pk 					 hme_intr, sc);
    195       1.1       pk }
    196