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