#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_ne_neptune.c,v 1.21 2015/05/20 09:17:18 ozaki-r Exp $");
#include "opt_inet.h"
#include "opt_ns.h"
#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>
#ifdef INET
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/in_var.h>
#include <netinet/ip.h>
#include <netinet/if_inarp.h>
#endif
#include <machine/bus.h>
#include <dev/ic/dp8390reg.h>
#include <dev/ic/dp8390var.h>
#include <dev/ic/ne2000reg.h>
#include <dev/ic/ne2000var.h>
#include <arch/x68k/dev/neptunevar.h>
static int ne_neptune_match(device_t, cfdata_t, void *);
static void ne_neptune_attach(device_t, device_t, void *);
#define ne_neptune_softc ne2000_softc
CFATTACH_DECL_NEW(ne_neptune, sizeof(struct ne_neptune_softc),
ne_neptune_match, ne_neptune_attach, NULL, NULL);
int
ne_neptune_match(device_t parent, cfdata_t match, void *aux)
{
struct neptune_attach_args *na = aux;
bus_space_tag_t nict = na->na_bst;
bus_space_handle_t nich;
bus_space_tag_t asict;
bus_space_handle_t asich;
int rv = 0;
if (na->na_addr == NEPTUNECF_ADDR_DEFAULT)
na->na_addr = 0x300;
if ((na->na_addr & 0x1f) != 0)
return (0);
if (bus_space_map(nict, na->na_addr, NE2000_NPORTS*2, 0, &nich))
return (0);
asict = nict;
if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET,
NE2000_ASIC_NPORTS*2, &asich))
goto out;
rv = ne2000_detect(nict, nich, asict, asich);
out:
bus_space_unmap(nict, nich, NE2000_NPORTS);
return (rv != 0) ? 1 : 0;
}
void
ne_neptune_attach(device_t parent, device_t self, void *aux)
{
struct ne_neptune_softc *nsc = device_private(self);
struct dp8390_softc *dsc = &nsc->sc_dp8390;
struct neptune_attach_args *na = aux;
bus_space_tag_t nict = na->na_bst;
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_normal("\n");
if (bus_space_map(nict, na->na_addr, NE2000_NPORTS*2, 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*2, &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);
if (neptune_intr_establish(na->na_intr, "ne", dp8390_intr, dsc))
aprint_error_dev(self,
"couldn't establish interrupt handler\n");
}