Home | History | Annotate | Line # | Download | only in sbus
if_gem_sbus.c revision 1.1.30.1
      1  1.1.30.1    matt /*	$NetBSD: if_gem_sbus.c,v 1.1.30.1 2007/11/06 23:30:09 matt 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  * 3. All advertising materials mentioning features or use of this software
     19       1.1  martin  *    must display the following acknowledgement:
     20       1.1  martin  *        This product includes software developed by the NetBSD
     21       1.1  martin  *        Foundation, Inc. and its contributors.
     22       1.1  martin  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23       1.1  martin  *    contributors may be used to endorse or promote products derived
     24       1.1  martin  *    from this software without specific prior written permission.
     25       1.1  martin  *
     26       1.1  martin  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27       1.1  martin  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28       1.1  martin  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29       1.1  martin  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30       1.1  martin  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31       1.1  martin  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32       1.1  martin  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33       1.1  martin  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34       1.1  martin  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35       1.1  martin  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36       1.1  martin  * POSSIBILITY OF SUCH DAMAGE.
     37       1.1  martin  */
     38       1.1  martin 
     39       1.1  martin /*
     40       1.1  martin  * SBus front-end for the GEM network driver
     41       1.1  martin  */
     42       1.1  martin 
     43       1.1  martin #include <sys/cdefs.h>
     44  1.1.30.1    matt __KERNEL_RCSID(0, "$NetBSD: if_gem_sbus.c,v 1.1.30.1 2007/11/06 23:30:09 matt Exp $");
     45       1.1  martin 
     46       1.1  martin #include <sys/param.h>
     47       1.1  martin #include <sys/systm.h>
     48       1.1  martin #include <sys/syslog.h>
     49       1.1  martin #include <sys/device.h>
     50       1.1  martin #include <sys/malloc.h>
     51       1.1  martin #include <sys/socket.h>
     52       1.1  martin 
     53       1.1  martin #include <net/if.h>
     54       1.1  martin #include <net/if_dl.h>
     55       1.1  martin #include <net/if_ether.h>
     56       1.1  martin #include <net/if_media.h>
     57       1.1  martin 
     58       1.1  martin #include <dev/mii/mii.h>
     59       1.1  martin #include <dev/mii/miivar.h>
     60       1.1  martin 
     61  1.1.30.1    matt #include <sys/bus.h>
     62  1.1.30.1    matt #include <sys/intr.h>
     63       1.1  martin #include <machine/autoconf.h>
     64       1.1  martin 
     65       1.1  martin #include <dev/sbus/sbusvar.h>
     66       1.1  martin 
     67       1.1  martin #include <dev/ic/gemreg.h>
     68       1.1  martin #include <dev/ic/gemvar.h>
     69       1.1  martin 
     70       1.1  martin struct gem_sbus_softc {
     71       1.1  martin 	struct	gem_softc	gsc_gem;	/* GEM device */
     72       1.1  martin 	struct sbusdev		gsc_sd;
     73       1.1  martin 	void			*gsc_ih;
     74       1.1  martin 	bus_space_handle_t	gsc_sbus_regs_h;
     75       1.1  martin };
     76       1.1  martin 
     77       1.1  martin int	gemmatch_sbus(struct device *, struct cfdata *, void *);
     78       1.1  martin void	gemattach_sbus(struct device *, struct device *, void *);
     79       1.1  martin 
     80       1.1  martin CFATTACH_DECL(gem_sbus, sizeof(struct gem_sbus_softc),
     81       1.1  martin     gemmatch_sbus, gemattach_sbus, NULL, NULL);
     82       1.1  martin 
     83       1.1  martin int
     84       1.1  martin gemmatch_sbus(struct device *parent, struct cfdata *cf, void *aux)
     85       1.1  martin {
     86       1.1  martin 	struct sbus_attach_args *sa = aux;
     87       1.1  martin 
     88       1.1  martin 	return (strcmp("network", sa->sa_name) == 0);
     89       1.1  martin }
     90       1.1  martin 
     91       1.1  martin void
     92       1.1  martin gemattach_sbus(struct device *parent, struct device *self, void *aux)
     93       1.1  martin {
     94       1.1  martin 	struct sbus_attach_args *sa = aux;
     95       1.1  martin 	struct gem_sbus_softc *gsc = (void *)self;
     96       1.1  martin 	struct gem_softc *sc = &gsc->gsc_gem;
     97       1.1  martin 	uint8_t enaddr[ETHER_ADDR_LEN];
     98       1.1  martin 
     99       1.1  martin 	/* Pass on the bus tags */
    100       1.1  martin 	sc->sc_bustag = sa->sa_bustag;
    101       1.1  martin 	sc->sc_dmatag = sa->sa_dmatag;
    102       1.1  martin 
    103       1.1  martin 	printf(": GEM Ethernet controller (%s), version %s\n",
    104       1.1  martin 	    sa->sa_name, prom_getpropstring(sa->sa_node, "version"));
    105       1.1  martin 
    106       1.1  martin 	if (sa->sa_nreg < 2) {
    107       1.1  martin 		printf("%s: only %d register sets\n",
    108       1.1  martin 			self->dv_xname, sa->sa_nreg);
    109       1.1  martin 		return;
    110       1.1  martin 	}
    111       1.1  martin 
    112       1.1  martin 	/*
    113       1.1  martin 	 * Map two register banks:
    114       1.1  martin 	 *
    115       1.1  martin 	 *	bank 0: status, config, reset
    116       1.1  martin 	 *	bank 1: various gem parts
    117       1.1  martin 	 *
    118       1.1  martin 	 */
    119       1.1  martin 	if (sbus_bus_map(sa->sa_bustag,
    120       1.1  martin 			 sa->sa_reg[0].oa_space,
    121       1.1  martin 			 sa->sa_reg[0].oa_base,
    122       1.1  martin 			 (bus_size_t)sa->sa_reg[0].oa_size,
    123       1.1  martin 			 0, &sc->sc_h2) != 0) {
    124       1.1  martin 		printf("%s: cannot map registers\n", self->dv_xname);
    125       1.1  martin 		return;
    126       1.1  martin 	}
    127       1.1  martin 	if (sbus_bus_map(sa->sa_bustag,
    128       1.1  martin 			 sa->sa_reg[1].oa_space,
    129       1.1  martin 			 sa->sa_reg[1].oa_base,
    130       1.1  martin 			 (bus_size_t)sa->sa_reg[1].oa_size,
    131       1.1  martin 			 0, &sc->sc_h1) != 0) {
    132       1.1  martin 		printf("%s: cannot map registers\n", self->dv_xname);
    133       1.1  martin 		return;
    134       1.1  martin 	}
    135       1.1  martin 	sbus_establish(&gsc->gsc_sd, self);
    136       1.1  martin 	prom_getether(sa->sa_node, enaddr);
    137       1.1  martin 
    138       1.1  martin 	/*
    139       1.1  martin 	 * SBUS config
    140       1.1  martin 	 */
    141       1.1  martin 	bus_space_write_4(sa->sa_bustag, sc->sc_h2, GEM_SBUS_CONFIG,
    142       1.1  martin 	    GEM_SBUS_CFG_PARITY|GEM_SBUS_CFG_BMODE64);
    143       1.1  martin 
    144       1.1  martin 	gem_attach(sc, enaddr);
    145       1.1  martin 
    146       1.1  martin 	/* Establish interrupt handler */
    147       1.1  martin 	if (sa->sa_nintr != 0)
    148       1.1  martin 		gsc->gsc_ih = bus_intr_establish(sa->sa_bustag, sa->sa_pri, IPL_NET,
    149       1.1  martin 					gem_intr, sc);
    150       1.1  martin }
    151