Home | History | Annotate | Line # | Download | only in sbus
      1  1.34  thorpej /*	$NetBSD: if_hme_sbus.c,v 1.34 2022/09/25 18:03:04 thorpej 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.34  thorpej __KERNEL_RCSID(0, "$NetBSD: if_hme_sbus.c,v 1.34 2022/09/25 18:03:04 thorpej 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/socket.h>
     44   1.1       pk 
     45   1.1       pk #include <net/if.h>
     46   1.1       pk #include <net/if_dl.h>
     47   1.1       pk #include <net/if_ether.h>
     48   1.1       pk #include <net/if_media.h>
     49   1.1       pk 
     50   1.1       pk #include <dev/mii/mii.h>
     51   1.1       pk #include <dev/mii/miivar.h>
     52   1.1       pk 
     53  1.22       ad #include <sys/bus.h>
     54  1.22       ad #include <sys/intr.h>
     55   1.1       pk #include <machine/autoconf.h>
     56   1.1       pk 
     57   1.1       pk #include <dev/sbus/sbusvar.h>
     58   1.1       pk #include <dev/ic/hmevar.h>
     59   1.1       pk 
     60   1.1       pk struct hmesbus_softc {
     61   1.1       pk 	struct	hme_softc	hsc_hme;	/* HME device */
     62  1.33  tsutsui 	/* sbus specific stuff here */
     63   1.1       pk };
     64   1.1       pk 
     65  1.28   cegger int	hmematch_sbus(device_t, cfdata_t, void *);
     66  1.28   cegger void	hmeattach_sbus(device_t, device_t, void *);
     67   1.1       pk 
     68  1.30  tsutsui CFATTACH_DECL_NEW(hme_sbus, sizeof(struct hmesbus_softc),
     69  1.16  thorpej     hmematch_sbus, hmeattach_sbus, NULL, NULL);
     70   1.1       pk 
     71   1.1       pk int
     72  1.28   cegger hmematch_sbus(device_t parent, cfdata_t cf, void *aux)
     73   1.1       pk {
     74   1.1       pk 	struct sbus_attach_args *sa = aux;
     75   1.1       pk 
     76  1.13  thorpej 	return (strcmp(cf->cf_name, sa->sa_name) == 0 ||
     77   1.6      mrg 	    strcmp("SUNW,qfe", sa->sa_name) == 0 ||
     78   1.2      mrg 	    strcmp("SUNW,hme", sa->sa_name) == 0);
     79   1.1       pk }
     80   1.1       pk 
     81   1.1       pk void
     82  1.28   cegger hmeattach_sbus(device_t parent, device_t self, void *aux)
     83   1.1       pk {
     84   1.1       pk 	struct sbus_attach_args *sa = aux;
     85  1.30  tsutsui 	struct hmesbus_softc *hsc = device_private(self);
     86   1.1       pk 	struct hme_softc *sc = &hsc->hsc_hme;
     87  1.29  tsutsui 	struct sbus_softc *sbsc = device_private(parent);
     88  1.31  tsutsui 	uint32_t burst, sbusburst;
     89   1.1       pk 	int node;
     90   1.8  thorpej 
     91  1.30  tsutsui 	sc->sc_dev = self;
     92   1.1       pk 	node = sa->sa_node;
     93   1.1       pk 
     94   1.1       pk 	/* Pass on the bus tags */
     95   1.1       pk 	sc->sc_bustag = sa->sa_bustag;
     96   1.1       pk 	sc->sc_dmatag = sa->sa_dmatag;
     97   1.1       pk 
     98  1.30  tsutsui 	aprint_normal(": Sun Happy Meal Ethernet (%s)\n",
     99   1.8  thorpej 	    sa->sa_name);
    100   1.8  thorpej 
    101   1.1       pk 	if (sa->sa_nreg < 5) {
    102  1.30  tsutsui 		aprint_error_dev(self, "only %d register sets\n",
    103  1.30  tsutsui 		    sa->sa_nreg);
    104   1.1       pk 		return;
    105   1.1       pk 	}
    106   1.1       pk 
    107   1.1       pk 	/*
    108   1.1       pk 	 * Map five register banks:
    109   1.1       pk 	 *
    110   1.1       pk 	 *	bank 0: HME SEB registers
    111   1.1       pk 	 *	bank 1: HME ETX registers
    112   1.1       pk 	 *	bank 2: HME ERX registers
    113   1.1       pk 	 *	bank 3: HME MAC registers
    114   1.1       pk 	 *	bank 4: HME MIF registers
    115   1.1       pk 	 *
    116   1.1       pk 	 */
    117   1.1       pk 	if (sbus_bus_map(sa->sa_bustag,
    118  1.12  thorpej 			 sa->sa_reg[0].oa_space,
    119  1.12  thorpej 			 sa->sa_reg[0].oa_base,
    120  1.12  thorpej 			 (bus_size_t)sa->sa_reg[0].oa_size,
    121  1.11      eeh 			 0, &sc->sc_seb) != 0) {
    122  1.23   cegger 		aprint_error_dev(self, "cannot map SEB registers\n");
    123   1.1       pk 		return;
    124   1.1       pk 	}
    125   1.1       pk 	if (sbus_bus_map(sa->sa_bustag,
    126  1.12  thorpej 			 sa->sa_reg[1].oa_space,
    127  1.12  thorpej 			 sa->sa_reg[1].oa_base,
    128  1.12  thorpej 			 (bus_size_t)sa->sa_reg[1].oa_size,
    129  1.11      eeh 			 0, &sc->sc_etx) != 0) {
    130  1.23   cegger 		aprint_error_dev(self, "cannot map ETX registers\n");
    131   1.1       pk 		return;
    132   1.1       pk 	}
    133   1.1       pk 	if (sbus_bus_map(sa->sa_bustag,
    134  1.12  thorpej 			 sa->sa_reg[2].oa_space,
    135  1.12  thorpej 			 sa->sa_reg[2].oa_base,
    136  1.12  thorpej 			 (bus_size_t)sa->sa_reg[2].oa_size,
    137  1.11      eeh 			 0, &sc->sc_erx) != 0) {
    138  1.23   cegger 		aprint_error_dev(self, "cannot map ERX registers\n");
    139   1.1       pk 		return;
    140   1.1       pk 	}
    141   1.1       pk 	if (sbus_bus_map(sa->sa_bustag,
    142  1.12  thorpej 			 sa->sa_reg[3].oa_space,
    143  1.12  thorpej 			 sa->sa_reg[3].oa_base,
    144  1.12  thorpej 			 (bus_size_t)sa->sa_reg[3].oa_size,
    145  1.11      eeh 			 0, &sc->sc_mac) != 0) {
    146  1.23   cegger 		aprint_error_dev(self, "cannot map MAC registers\n");
    147   1.1       pk 		return;
    148   1.1       pk 	}
    149   1.1       pk 	if (sbus_bus_map(sa->sa_bustag,
    150  1.12  thorpej 			 sa->sa_reg[4].oa_space,
    151  1.12  thorpej 			 sa->sa_reg[4].oa_base,
    152  1.12  thorpej 			 (bus_size_t)sa->sa_reg[4].oa_size,
    153  1.11      eeh 			 0, &sc->sc_mif) != 0) {
    154  1.23   cegger 		aprint_error_dev(self, "cannot map MIF registers\n");
    155   1.1       pk 		return;
    156   1.1       pk 	}
    157   1.1       pk 
    158  1.18       pk 	prom_getether(node, sc->sc_enaddr);
    159   1.1       pk 
    160   1.1       pk 	/*
    161   1.1       pk 	 * Get transfer burst size from PROM and pass it on
    162   1.1       pk 	 * to the back-end driver.
    163   1.1       pk 	 */
    164  1.29  tsutsui 	sbusburst = sbsc->sc_burst;
    165   1.1       pk 	if (sbusburst == 0)
    166   1.1       pk 		sbusburst = SBUS_BURST_32 - 1; /* 1->16 */
    167   1.1       pk 
    168  1.19       pk 	burst = prom_getpropint(node, "burst-sizes", -1);
    169   1.1       pk 	if (burst == -1)
    170   1.1       pk 		/* take SBus burst sizes */
    171   1.1       pk 		burst = sbusburst;
    172   1.1       pk 
    173   1.1       pk 	/* Clamp at parent's burst sizes */
    174   1.1       pk 	burst &= sbusburst;
    175   1.1       pk 
    176   1.1       pk 	/* Translate into plain numerical format */
    177   1.1       pk 	sc->sc_burst =  (burst & SBUS_BURST_32) ? 32 :
    178   1.1       pk 			(burst & SBUS_BURST_16) ? 16 : 0;
    179   1.1       pk 
    180   1.4      eeh 	sc->sc_pci = 0; /* XXXXX should all be done in bus_dma. */
    181   1.1       pk 	hme_config(sc);
    182   1.1       pk 
    183   1.3       pk 	/* Establish interrupt handler */
    184   1.3       pk 	if (sa->sa_nintr != 0)
    185  1.17       pk 		(void)bus_intr_establish(sa->sa_bustag, sa->sa_pri, IPL_NET,
    186   1.3       pk 					 hme_intr, sc);
    187   1.1       pk }
    188