#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_sm_nubus.c,v 1.10 2012/10/27 17:17:59 chs Exp $");
#include "opt_inet.h"
#include <sys/param.h>
#include <sys/device.h>
#include <sys/errno.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/syslog.h>
#include <sys/systm.h>
#include <net/if.h>
#include <net/if_ether.h>
#include <net/if_media.h>
#include <machine/bus.h>
#include <machine/viareg.h>
#include <dev/mii/mii.h>
#include <dev/mii/miivar.h>
#include <dev/ic/smc91cxxreg.h>
#include <dev/ic/smc91cxxvar.h>
#include <mac68k/nubus/nubus.h>
static int sm_nubus_match(device_t, cfdata_t, void *);
static void sm_nubus_attach(device_t, device_t, void *);
CFATTACH_DECL_NEW(sm_nubus, sizeof(struct smc91cxx_softc),
sm_nubus_match, sm_nubus_attach, NULL, NULL);
static int
sm_nubus_match(device_t parent, cfdata_t cf, void *aux)
{
struct nubus_attach_args *na = (struct nubus_attach_args *) aux;
bus_space_handle_t bsh;
int rv;
if (bus_space_map(na->na_tag,
NUBUS_SLOT2PA(na->slot), NBMEMSIZE, 0, &bsh))
return (0);
rv = 0;
if (na->category == NUBUS_CATEGORY_NETWORK &&
na->type == NUBUS_TYPE_ETHERNET) {
switch (na->drsw) {
case NUBUS_DRSW_FOCUS:
case NUBUS_DRSW_ASANTEF:
rv = 1;
break;
default:
rv = 0;
break;
}
}
bus_space_unmap(na->na_tag, bsh, NBMEMSIZE);
return rv;
}
static void
sm_nubus_attach(device_t parent, device_t self, void *aux)
{
struct smc91cxx_softc *smc = device_private(self);
struct nubus_attach_args *na = (struct nubus_attach_args *)aux;
bus_space_tag_t bst = na->na_tag;
bus_space_handle_t bsh, prom_bsh;
u_int8_t myaddr[ETHER_ADDR_LEN];
int i, success;
const char *cardtype;
bst = na->na_tag;
if (bus_space_map(bst, NUBUS_SLOT2PA(na->slot), NBMEMSIZE, 0, &bsh)) {
printf(": failed to map memory space.\n");
return;
}
mac68k_bus_space_handle_swapped(bst, &bsh);
smc->sc_dev = self;
smc->sc_bst = bst;
smc->sc_bsh = bsh;
cardtype = nubus_get_card_name(bst, bsh, na->fmt);
success = 0;
switch (na->drsw) {
case NUBUS_DRSW_FOCUS:
if (bus_space_subregion(bst, bsh, 0xFF8000, 0x20, &prom_bsh)) {
printf(": failed to map EEPROM space.\n");
break;
}
success = 1;
break;
case NUBUS_DRSW_ASANTEF:
if (bus_space_subregion(bst, bsh, 0xFE0000, 0x20, &prom_bsh)) {
printf(": failed to map EEPROM space.\n");
break;
}
success = 1;
break;
}
if (!success) {
bus_space_unmap(bst, bsh, NBMEMSIZE);
return;
}
for (i=0 ; i<6 ; i++) {
myaddr[i] = bus_space_read_1(bst, prom_bsh, i*4);
}
smc->sc_flags |= SMC_FLAGS_ENABLED;
printf(": %s\n", cardtype);
smc91cxx_attach(smc, myaddr);
add_nubus_intr(na->slot, (void (*)(void *))smc91cxx_intr, smc);
}