2009-09-17 20:28:12 +04:00
|
|
|
/* $NetBSD: if_hme_sbus.c,v 1.33 2009/09/17 16:28:12 tsutsui Exp $ */
|
1999-06-27 16:47:52 +04:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1999 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Paul Kranenburg.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SBus front-end device driver for the HME ethernet device.
|
|
|
|
*/
|
|
|
|
|
2001-11-13 09:54:32 +03:00
|
|
|
#include <sys/cdefs.h>
|
2009-09-17 20:28:12 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: if_hme_sbus.c,v 1.33 2009/09/17 16:28:12 tsutsui Exp $");
|
2001-11-13 09:54:32 +03:00
|
|
|
|
1999-06-27 16:47:52 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/if_ether.h>
|
|
|
|
#include <net/if_media.h>
|
|
|
|
|
|
|
|
#include <dev/mii/mii.h>
|
|
|
|
#include <dev/mii/miivar.h>
|
|
|
|
|
2007-10-19 15:59:34 +04:00
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/intr.h>
|
1999-06-27 16:47:52 +04:00
|
|
|
#include <machine/autoconf.h>
|
|
|
|
|
|
|
|
#include <dev/sbus/sbusvar.h>
|
|
|
|
#include <dev/ic/hmevar.h>
|
|
|
|
|
|
|
|
struct hmesbus_softc {
|
|
|
|
struct hme_softc hsc_hme; /* HME device */
|
2009-09-17 20:28:12 +04:00
|
|
|
/* sbus specific stuff here */
|
1999-06-27 16:47:52 +04:00
|
|
|
};
|
|
|
|
|
2009-05-12 18:38:26 +04:00
|
|
|
int hmematch_sbus(device_t, cfdata_t, void *);
|
|
|
|
void hmeattach_sbus(device_t, device_t, void *);
|
1999-06-27 16:47:52 +04:00
|
|
|
|
2009-05-17 04:40:43 +04:00
|
|
|
CFATTACH_DECL_NEW(hme_sbus, sizeof(struct hmesbus_softc),
|
2002-10-02 20:51:16 +04:00
|
|
|
hmematch_sbus, hmeattach_sbus, NULL, NULL);
|
1999-06-27 16:47:52 +04:00
|
|
|
|
|
|
|
int
|
2009-05-12 18:38:26 +04:00
|
|
|
hmematch_sbus(device_t parent, cfdata_t cf, void *aux)
|
1999-06-27 16:47:52 +04:00
|
|
|
{
|
|
|
|
struct sbus_attach_args *sa = aux;
|
|
|
|
|
2002-09-27 06:24:06 +04:00
|
|
|
return (strcmp(cf->cf_name, sa->sa_name) == 0 ||
|
2001-02-28 17:52:48 +03:00
|
|
|
strcmp("SUNW,qfe", sa->sa_name) == 0 ||
|
1999-11-04 08:31:38 +03:00
|
|
|
strcmp("SUNW,hme", sa->sa_name) == 0);
|
1999-06-27 16:47:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-05-12 18:38:26 +04:00
|
|
|
hmeattach_sbus(device_t parent, device_t self, void *aux)
|
1999-06-27 16:47:52 +04:00
|
|
|
{
|
|
|
|
struct sbus_attach_args *sa = aux;
|
2009-05-17 04:40:43 +04:00
|
|
|
struct hmesbus_softc *hsc = device_private(self);
|
1999-06-27 16:47:52 +04:00
|
|
|
struct hme_softc *sc = &hsc->hsc_hme;
|
2009-05-17 04:28:35 +04:00
|
|
|
struct sbus_softc *sbsc = device_private(parent);
|
2009-05-17 05:33:24 +04:00
|
|
|
uint32_t burst, sbusburst;
|
1999-06-27 16:47:52 +04:00
|
|
|
int node;
|
2001-10-05 21:49:43 +04:00
|
|
|
|
2009-05-17 04:40:43 +04:00
|
|
|
sc->sc_dev = self;
|
1999-06-27 16:47:52 +04:00
|
|
|
node = sa->sa_node;
|
|
|
|
|
|
|
|
/* Pass on the bus tags */
|
|
|
|
sc->sc_bustag = sa->sa_bustag;
|
|
|
|
sc->sc_dmatag = sa->sa_dmatag;
|
|
|
|
|
2009-05-17 04:40:43 +04:00
|
|
|
aprint_normal(": Sun Happy Meal Ethernet (%s)\n",
|
2001-10-05 21:49:43 +04:00
|
|
|
sa->sa_name);
|
|
|
|
|
1999-06-27 16:47:52 +04:00
|
|
|
if (sa->sa_nreg < 5) {
|
2009-05-17 04:40:43 +04:00
|
|
|
aprint_error_dev(self, "only %d register sets\n",
|
|
|
|
sa->sa_nreg);
|
1999-06-27 16:47:52 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Map five register banks:
|
|
|
|
*
|
|
|
|
* bank 0: HME SEB registers
|
|
|
|
* bank 1: HME ETX registers
|
|
|
|
* bank 2: HME ERX registers
|
|
|
|
* bank 3: HME MAC registers
|
|
|
|
* bank 4: HME MIF registers
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
if (sbus_bus_map(sa->sa_bustag,
|
2002-08-23 06:53:10 +04:00
|
|
|
sa->sa_reg[0].oa_space,
|
|
|
|
sa->sa_reg[0].oa_base,
|
|
|
|
(bus_size_t)sa->sa_reg[0].oa_size,
|
2002-03-20 23:39:15 +03:00
|
|
|
0, &sc->sc_seb) != 0) {
|
2008-04-05 22:35:31 +04:00
|
|
|
aprint_error_dev(self, "cannot map SEB registers\n");
|
1999-06-27 16:47:52 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (sbus_bus_map(sa->sa_bustag,
|
2002-08-23 06:53:10 +04:00
|
|
|
sa->sa_reg[1].oa_space,
|
|
|
|
sa->sa_reg[1].oa_base,
|
|
|
|
(bus_size_t)sa->sa_reg[1].oa_size,
|
2002-03-20 23:39:15 +03:00
|
|
|
0, &sc->sc_etx) != 0) {
|
2008-04-05 22:35:31 +04:00
|
|
|
aprint_error_dev(self, "cannot map ETX registers\n");
|
1999-06-27 16:47:52 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (sbus_bus_map(sa->sa_bustag,
|
2002-08-23 06:53:10 +04:00
|
|
|
sa->sa_reg[2].oa_space,
|
|
|
|
sa->sa_reg[2].oa_base,
|
|
|
|
(bus_size_t)sa->sa_reg[2].oa_size,
|
2002-03-20 23:39:15 +03:00
|
|
|
0, &sc->sc_erx) != 0) {
|
2008-04-05 22:35:31 +04:00
|
|
|
aprint_error_dev(self, "cannot map ERX registers\n");
|
1999-06-27 16:47:52 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (sbus_bus_map(sa->sa_bustag,
|
2002-08-23 06:53:10 +04:00
|
|
|
sa->sa_reg[3].oa_space,
|
|
|
|
sa->sa_reg[3].oa_base,
|
|
|
|
(bus_size_t)sa->sa_reg[3].oa_size,
|
2002-03-20 23:39:15 +03:00
|
|
|
0, &sc->sc_mac) != 0) {
|
2008-04-05 22:35:31 +04:00
|
|
|
aprint_error_dev(self, "cannot map MAC registers\n");
|
1999-06-27 16:47:52 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (sbus_bus_map(sa->sa_bustag,
|
2002-08-23 06:53:10 +04:00
|
|
|
sa->sa_reg[4].oa_space,
|
|
|
|
sa->sa_reg[4].oa_base,
|
|
|
|
(bus_size_t)sa->sa_reg[4].oa_size,
|
2002-03-20 23:39:15 +03:00
|
|
|
0, &sc->sc_mif) != 0) {
|
2008-04-05 22:35:31 +04:00
|
|
|
aprint_error_dev(self, "cannot map MIF registers\n");
|
1999-06-27 16:47:52 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-03-16 02:51:11 +03:00
|
|
|
prom_getether(node, sc->sc_enaddr);
|
1999-06-27 16:47:52 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get transfer burst size from PROM and pass it on
|
|
|
|
* to the back-end driver.
|
|
|
|
*/
|
2009-05-17 04:28:35 +04:00
|
|
|
sbusburst = sbsc->sc_burst;
|
1999-06-27 16:47:52 +04:00
|
|
|
if (sbusburst == 0)
|
|
|
|
sbusburst = SBUS_BURST_32 - 1; /* 1->16 */
|
|
|
|
|
2004-03-17 20:04:58 +03:00
|
|
|
burst = prom_getpropint(node, "burst-sizes", -1);
|
1999-06-27 16:47:52 +04:00
|
|
|
if (burst == -1)
|
|
|
|
/* take SBus burst sizes */
|
|
|
|
burst = sbusburst;
|
|
|
|
|
|
|
|
/* Clamp at parent's burst sizes */
|
|
|
|
burst &= sbusburst;
|
|
|
|
|
|
|
|
/* Translate into plain numerical format */
|
|
|
|
sc->sc_burst = (burst & SBUS_BURST_32) ? 32 :
|
|
|
|
(burst & SBUS_BURST_16) ? 16 : 0;
|
|
|
|
|
2000-06-25 05:05:16 +04:00
|
|
|
sc->sc_pci = 0; /* XXXXX should all be done in bus_dma. */
|
1999-06-27 16:47:52 +04:00
|
|
|
hme_config(sc);
|
|
|
|
|
1999-11-21 18:01:50 +03:00
|
|
|
/* Establish interrupt handler */
|
|
|
|
if (sa->sa_nintr != 0)
|
2002-12-10 16:44:47 +03:00
|
|
|
(void)bus_intr_establish(sa->sa_bustag, sa->sa_pri, IPL_NET,
|
1999-11-21 18:01:50 +03:00
|
|
|
hme_intr, sc);
|
1999-06-27 16:47:52 +04:00
|
|
|
}
|