Home | History | Annotate | Line # | Download | only in sbus
if_gem_sbus.c revision 1.8
      1  1.8     jdc /*	$NetBSD: if_gem_sbus.c,v 1.8 2008/11/20 20:56:56 jdc Exp $	*/
      2  1.1  martin 
      3  1.1  martin /*-
      4  1.1  martin  * Copyright (c) 2006 The NetBSD Foundation, Inc.
      5  1.1  martin  * All rights reserved.
      6  1.1  martin  *
      7  1.1  martin  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  martin  * by Martin Husemann.
      9  1.1  martin  *
     10  1.1  martin  * Redistribution and use in source and binary forms, with or without
     11  1.1  martin  * modification, are permitted provided that the following conditions
     12  1.1  martin  * are met:
     13  1.1  martin  * 1. Redistributions of source code must retain the above copyright
     14  1.1  martin  *    notice, this list of conditions and the following disclaimer.
     15  1.1  martin  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  martin  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  martin  *    documentation and/or other materials provided with the distribution.
     18  1.1  martin  *
     19  1.1  martin  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.1  martin  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.1  martin  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.1  martin  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.1  martin  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.1  martin  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.1  martin  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.1  martin  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.1  martin  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.1  martin  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.1  martin  * POSSIBILITY OF SUCH DAMAGE.
     30  1.1  martin  */
     31  1.1  martin 
     32  1.1  martin /*
     33  1.1  martin  * SBus front-end for the GEM network driver
     34  1.1  martin  */
     35  1.1  martin 
     36  1.1  martin #include <sys/cdefs.h>
     37  1.8     jdc __KERNEL_RCSID(0, "$NetBSD: if_gem_sbus.c,v 1.8 2008/11/20 20:56:56 jdc Exp $");
     38  1.1  martin 
     39  1.1  martin #include <sys/param.h>
     40  1.1  martin #include <sys/systm.h>
     41  1.1  martin #include <sys/syslog.h>
     42  1.1  martin #include <sys/device.h>
     43  1.1  martin #include <sys/malloc.h>
     44  1.1  martin #include <sys/socket.h>
     45  1.1  martin 
     46  1.1  martin #include <net/if.h>
     47  1.1  martin #include <net/if_dl.h>
     48  1.1  martin #include <net/if_ether.h>
     49  1.1  martin #include <net/if_media.h>
     50  1.1  martin 
     51  1.1  martin #include <dev/mii/mii.h>
     52  1.1  martin #include <dev/mii/miivar.h>
     53  1.1  martin 
     54  1.2      ad #include <sys/bus.h>
     55  1.2      ad #include <sys/intr.h>
     56  1.1  martin #include <machine/autoconf.h>
     57  1.1  martin 
     58  1.1  martin #include <dev/sbus/sbusvar.h>
     59  1.1  martin 
     60  1.1  martin #include <dev/ic/gemreg.h>
     61  1.1  martin #include <dev/ic/gemvar.h>
     62  1.1  martin 
     63  1.1  martin struct gem_sbus_softc {
     64  1.1  martin 	struct	gem_softc	gsc_gem;	/* GEM device */
     65  1.1  martin 	struct sbusdev		gsc_sd;
     66  1.1  martin 	void			*gsc_ih;
     67  1.1  martin 	bus_space_handle_t	gsc_sbus_regs_h;
     68  1.1  martin };
     69  1.1  martin 
     70  1.1  martin int	gemmatch_sbus(struct device *, struct cfdata *, void *);
     71  1.1  martin void	gemattach_sbus(struct device *, struct device *, void *);
     72  1.1  martin 
     73  1.1  martin CFATTACH_DECL(gem_sbus, sizeof(struct gem_sbus_softc),
     74  1.1  martin     gemmatch_sbus, gemattach_sbus, NULL, NULL);
     75  1.1  martin 
     76  1.1  martin int
     77  1.1  martin gemmatch_sbus(struct device *parent, struct cfdata *cf, void *aux)
     78  1.1  martin {
     79  1.1  martin 	struct sbus_attach_args *sa = aux;
     80  1.1  martin 
     81  1.1  martin 	return (strcmp("network", sa->sa_name) == 0);
     82  1.1  martin }
     83  1.1  martin 
     84  1.1  martin void
     85  1.1  martin gemattach_sbus(struct device *parent, struct device *self, void *aux)
     86  1.1  martin {
     87  1.1  martin 	struct sbus_attach_args *sa = aux;
     88  1.1  martin 	struct gem_sbus_softc *gsc = (void *)self;
     89  1.1  martin 	struct gem_softc *sc = &gsc->gsc_gem;
     90  1.1  martin 	uint8_t enaddr[ETHER_ADDR_LEN];
     91  1.1  martin 
     92  1.1  martin 	/* Pass on the bus tags */
     93  1.1  martin 	sc->sc_bustag = sa->sa_bustag;
     94  1.1  martin 	sc->sc_dmatag = sa->sa_dmatag;
     95  1.1  martin 
     96  1.1  martin 	if (sa->sa_nreg < 2) {
     97  1.1  martin 		printf("%s: only %d register sets\n",
     98  1.4  cegger 			device_xname(self), sa->sa_nreg);
     99  1.1  martin 		return;
    100  1.1  martin 	}
    101  1.1  martin 
    102  1.1  martin 	/*
    103  1.1  martin 	 * Map two register banks:
    104  1.1  martin 	 *
    105  1.1  martin 	 *	bank 0: status, config, reset
    106  1.1  martin 	 *	bank 1: various gem parts
    107  1.1  martin 	 *
    108  1.1  martin 	 */
    109  1.1  martin 	if (sbus_bus_map(sa->sa_bustag,
    110  1.1  martin 			 sa->sa_reg[0].oa_space,
    111  1.1  martin 			 sa->sa_reg[0].oa_base,
    112  1.1  martin 			 (bus_size_t)sa->sa_reg[0].oa_size,
    113  1.1  martin 			 0, &sc->sc_h2) != 0) {
    114  1.4  cegger 		aprint_error_dev(self, "cannot map registers\n");
    115  1.1  martin 		return;
    116  1.1  martin 	}
    117  1.1  martin 	if (sbus_bus_map(sa->sa_bustag,
    118  1.1  martin 			 sa->sa_reg[1].oa_space,
    119  1.1  martin 			 sa->sa_reg[1].oa_base,
    120  1.1  martin 			 (bus_size_t)sa->sa_reg[1].oa_size,
    121  1.1  martin 			 0, &sc->sc_h1) != 0) {
    122  1.4  cegger 		aprint_error_dev(self, "cannot map registers\n");
    123  1.1  martin 		return;
    124  1.1  martin 	}
    125  1.1  martin 	sbus_establish(&gsc->gsc_sd, self);
    126  1.1  martin 	prom_getether(sa->sa_node, enaddr);
    127  1.1  martin 
    128  1.3     jdc 	if (!strcmp("serdes", prom_getpropstring(sa->sa_node, "shared-pins")))
    129  1.3     jdc 		sc->sc_flags |= GEM_SERDES;
    130  1.5     jdc 	sc->sc_variant = GEM_SUN_GEM;
    131  1.8     jdc 	sc->sc_flags &= ~GEM_PCI;
    132  1.3     jdc 
    133  1.1  martin 	/*
    134  1.1  martin 	 * SBUS config
    135  1.1  martin 	 */
    136  1.7     jdc 	(void) bus_space_read_4(sa->sa_bustag, sc->sc_h2, GEM_SBUS_RESET);
    137  1.7     jdc 	delay(100);
    138  1.1  martin 	bus_space_write_4(sa->sa_bustag, sc->sc_h2, GEM_SBUS_CONFIG,
    139  1.7     jdc 	    GEM_SBUS_CFG_BSIZE128|GEM_SBUS_CFG_PARITY|GEM_SBUS_CFG_BMODE64);
    140  1.8     jdc 	sc->sc_chiprev = bus_space_read_4(sa->sa_bustag, sc->sc_h2,
    141  1.8     jdc 	    GEM_SBUS_REVISION);
    142  1.8     jdc 
    143  1.8     jdc 	printf(": GEM Ethernet controller (%s), version %s (rev 0x%02x)\n",
    144  1.8     jdc 	    sa->sa_name, prom_getpropstring(sa->sa_node, "version"),
    145  1.8     jdc 	    sc->sc_chiprev);
    146  1.1  martin 
    147  1.1  martin 	gem_attach(sc, enaddr);
    148  1.1  martin 
    149  1.1  martin 	/* Establish interrupt handler */
    150  1.1  martin 	if (sa->sa_nintr != 0)
    151  1.1  martin 		gsc->gsc_ih = bus_intr_establish(sa->sa_bustag, sa->sa_pri, IPL_NET,
    152  1.1  martin 					gem_intr, sc);
    153  1.1  martin }
    154