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