#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_ne_mainbus.c,v 1.3 2012/12/01 03:16:46 tsutsui Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/mbuf.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/errno.h>
#include <sys/syslog.h>
#include <sys/select.h>
#include <sys/device.h>
#include <sys/bus.h>
#include <net/if.h>
#include <net/if_dl.h>
#include <net/if_ether.h>
#include <net/if_media.h>
#include <sys/intr.h>
#include <dev/ic/dp8390reg.h>
#include <dev/ic/dp8390var.h>
#include <dev/ic/ne2000reg.h>
#include <dev/ic/ne2000var.h>
#include <machine/autoconf.h>
#include <sh3/exception.h>
static int ne_mainbus_match(device_t, cfdata_t, void *);
static void ne_mainbus_attach(device_t, device_t, void *);
struct ne_mainbus_softc {
struct ne2000_softc sc_ne2000;
void *sc_ih;
};
CFATTACH_DECL_NEW(ne_mainbus, sizeof(struct ne_mainbus_softc),
ne_mainbus_match, ne_mainbus_attach, NULL, NULL);
extern struct _bus_space t_sh7706lan_bus_io;
static int
ne_mainbus_match(device_t parent, cfdata_t cf, void *aux)
{
struct mainbus_attach_args *maa = (struct mainbus_attach_args *)aux;
bus_space_tag_t nict = &t_sh7706lan_bus_io;
bus_space_handle_t nich;
bus_space_tag_t asict;
bus_space_handle_t asich;
int rv = 0;
if (strcmp(maa->ma_name, "ne") != 0)
return 0;
if (bus_space_map(nict, 0x10000300, NE2000_NPORTS, 0, &nich))
return 0;
asict = nict;
if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET,
NE2000_ASIC_NPORTS, &asich))
goto out;
rv = ne2000_detect(nict, nich, asict, asich);
out:
bus_space_unmap(nict, nich, NE2000_NPORTS);
return rv;
}
static void
ne_mainbus_attach(device_t parent, device_t self, void *aux)
{
struct ne_mainbus_softc *msc = device_private(self);
struct ne2000_softc *nsc = &msc->sc_ne2000;
struct dp8390_softc *dsc = &nsc->sc_dp8390;
bus_space_tag_t nict = &t_sh7706lan_bus_io;
bus_space_handle_t nich;
bus_space_tag_t asict = nict;
bus_space_handle_t asich;
const char *typestr;
int netype;
dsc->sc_dev = self;
aprint_naive("\n");
aprint_normal("\n");
if (bus_space_map(nict, 0x10000300, NE2000_NPORTS, 0, &nich)){
aprint_error_dev(self, "can't map i/o space\n");
return;
}
if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET,
NE2000_ASIC_NPORTS, &asich)) {
aprint_error_dev(self, "can't subregion i/o space\n");
bus_space_unmap(nict, nich, NE2000_NPORTS);
return;
}
dsc->sc_regt = nict;
dsc->sc_regh = nich;
nsc->sc_asict = asict;
nsc->sc_asich = asich;
netype = ne2000_detect(nict, nich, asict, asich);
switch (netype) {
case NE2000_TYPE_NE1000:
typestr = "NE1000";
break;
case NE2000_TYPE_NE2000:
typestr = "NE2000";
break;
case NE2000_TYPE_RTL8019:
typestr = "NE2000 (RTL8019)";
break;
default:
aprint_error_dev(self, "where did the card go?!\n");
bus_space_unmap(nict, nich, NE2000_NPORTS);
return;
}
aprint_normal_dev(self, "%s Ethernet\n", typestr);
dsc->sc_enabled = 1;
nsc->sc_quirk |= NE2000_QUIRK_8BIT;
ne2000_attach(nsc, NULL);
msc->sc_ih = intc_intr_establish(SH7709_INTEVT2_IRQ2, IST_LEVEL,
IPL_NET, dp8390_intr, dsc);
if (msc->sc_ih == NULL)
aprint_error_dev(self,
"couldn't establish interrupt handler\n");
}