#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_ne_isapnp.c,v 1.27 2010/03/03 13:39:57 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 <net/if.h>
#include <net/if_dl.h>
#include <net/if_ether.h>
#include <net/if_media.h>
#include <sys/intr.h>
#include <sys/bus.h>
#include <dev/ic/dp8390reg.h>
#include <dev/ic/dp8390var.h>
#include <dev/ic/ne2000reg.h>
#include <dev/ic/ne2000var.h>
#include <dev/isa/isavar.h>
#include <dev/isapnp/isapnpreg.h>
#include <dev/isapnp/isapnpvar.h>
#include <dev/isapnp/isapnpdevs.h>
static int ne_isapnp_match(device_t, cfdata_t , void *);
static void ne_isapnp_attach(device_t, device_t, void *);
struct ne_isapnp_softc {
struct ne2000_softc sc_ne2000;
void *sc_ih;
};
CFATTACH_DECL_NEW(ne_isapnp, sizeof(struct ne_isapnp_softc),
ne_isapnp_match, ne_isapnp_attach, NULL, NULL);
static int
ne_isapnp_match(device_t parent, cfdata_t match, void *aux)
{
int pri, variant;
pri = isapnp_devmatch(aux, &isapnp_ne_devinfo, &variant);
if (pri && variant > 0)
pri = 0;
return (pri);
}
static void
ne_isapnp_attach(device_t parent, device_t self, void *aux)
{
struct ne_isapnp_softc * const isc = device_private(self);
struct ne2000_softc * const nsc = &isc->sc_ne2000;
struct dp8390_softc * const dsc = &nsc->sc_dp8390;
struct isapnp_attach_args * const ipa = aux;
bus_space_tag_t nict;
bus_space_handle_t nich;
bus_space_tag_t asict;
bus_space_handle_t asich;
const char *typestr;
int netype;
aprint_normal("\n");
dsc->sc_dev = self;
if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
aprint_error_dev(self, "can't configure isapnp resources\n");
return;
}
nict = ipa->ipa_iot;
nich = ipa->ipa_io[0].h;
asict = nict;
if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET,
NE2000_ASIC_NPORTS, &asich)) {
aprint_error_dev(self, "can't subregion i/o space\n");
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");
return;
}
aprint_normal_dev(self, "%s Ethernet\n", typestr);
dsc->sc_enabled = 1;
ne2000_attach(nsc, NULL);
isc->sc_ih = isa_intr_establish(ipa->ipa_ic, ipa->ipa_irq[0].num,
ipa->ipa_irq[0].type, IPL_NET, dp8390_intr, dsc);
if (isc->sc_ih == NULL)
aprint_error_dev(self,
"couldn't establish interrupt handler\n");
}