#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_we_mca.c,v 1.22 2021/04/08 17:36:33 jdolecek Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/socket.h>
#include <sys/mbuf.h>
#include <net/if.h>
#include <net/if_types.h>
#include <net/if_media.h>
#include <net/if_ether.h>
#include <sys/bus.h>
#include <dev/mca/mcareg.h>
#include <dev/mca/mcavar.h>
#include <dev/mca/mcadevs.h>
#include <dev/ic/dp8390reg.h>
#include <dev/ic/dp8390var.h>
#include <dev/ic/wereg.h>
#include <dev/ic/wevar.h>
#define WD_8003 0x01
#define WD_ELITE 0x02
int we_mca_probe(device_t, cfdata_t , void *);
void we_mca_attach(device_t, device_t, void *);
void we_mca_init_hook(struct we_softc *);
CFATTACH_DECL_NEW(we_mca, sizeof(struct we_softc),
we_mca_probe, we_mca_attach, NULL, NULL);
static const struct we_mca_product {
u_int32_t we_id;
const char *we_name;
int we_flag;
int we_type;
const char *we_typestr;
} we_mca_products[] = {
{ MCA_PRODUCT_WD_8013EP, "EtherCard PLUS Elite/A (8013EP/A)",
WD_ELITE, WE_TYPE_WD8013EP, "WD8013EP/A" },
{ MCA_PRODUCT_WD_8013WP, "EtherCard PLUS Elite 10T/A (8013WP/A)",
WD_ELITE, WE_TYPE_WD8013EP, "WD8013WP/A" },
{ MCA_PRODUCT_IBM_WD_2,"IBM PS/2 Adapter/A for Ethernet Networks (UTP)",
WD_ELITE, WE_TYPE_WD8013EP, "WD8013WP/A"},
{ MCA_PRODUCT_IBM_WD_T,"IBM PS/2 Adapter/A for Ethernet Networks (BNC)",
WD_ELITE, WE_TYPE_WD8013EP, "WD8013WP/A"},
{ MCA_PRODUCT_WD_8003E, "WD EtherCard PLUS/A (WD8003E/A or WD8003ET/A)",
WD_8003, WE_TYPE_WD8003E, "WD8003E/A or WD8003ET/A" },
{ MCA_PRODUCT_WD_8003ST,"WD StarCard PLUS/A (WD8003ST/A)",
WD_8003, WE_TYPE_WD8003W, "WD8003ST/A" },
{ MCA_PRODUCT_WD_8003W, "WD EtherCard PLUS 10T/A (WD8003W/A)",
WD_8003, WE_TYPE_WD8003W, "WD8003W/A" },
{ MCA_PRODUCT_IBM_WD_O, "IBM PS/2 Adapter/A for Ethernet Networks",
WD_8003, WE_TYPE_WD8003W, "IBM PS/2 Adapter/A" },
{ 0x0000, NULL,
0, 0, NULL },
};
static const int we_mca_irq[] = {
3, 4, 10, 15,
};
static const struct we_mca_product *we_mca_lookup(int);
static const struct we_mca_product *
we_mca_lookup(int id)
{
const struct we_mca_product *wep;
for(wep = we_mca_products; wep->we_name; wep++)
if (wep->we_id == id)
return (wep);
return (NULL);
}
int
we_mca_probe(device_t parent, cfdata_t cf, void *aux)
{
struct mca_attach_args *ma = aux;
return (we_mca_lookup(ma->ma_id) != NULL);
}
void
we_mca_attach(device_t parent, device_t self, void *aux)
{
struct we_softc *wsc = device_private(self);
struct dp8390_softc *sc = &wsc->sc_dp8390;
struct mca_attach_args *ma = aux;
const struct we_mca_product *wep;
bus_space_tag_t nict, asict, memt;
bus_space_handle_t nich, asich, memh;
const char *typestr;
int irq, iobase, maddr;
int pos2, pos3, pos5;
sc->sc_dev = self;
pos2 = mca_conf_read(ma->ma_mc, ma->ma_slot, 2);
pos3 = mca_conf_read(ma->ma_mc, ma->ma_slot, 3);
pos5 = mca_conf_read(ma->ma_mc, ma->ma_slot, 5);
wep = we_mca_lookup(ma->ma_id);
#ifdef DIAGNOSTIC
if (wep == NULL) {
aprint_error("\n%s: where did the card go?\n",
device_xname(self));
return;
}
#endif
if (wep->we_flag & WD_8003) {
iobase = 0x200 + (((pos2 & 0x0e) >> 1) * 0x020);
maddr = 0xC0000 + (((pos3 & 0x1c) >> 2) * 0x04000);
irq = we_mca_irq[(pos5 & 0x03)];
sc->mem_size = 16384;
} else {
iobase = 0x800 + (((pos2 & 0xf0) >> 4) * 0x1000);
maddr = 0xC0000 + ((pos3 & 0x0f) * 0x2000)
+ ((pos3 & 0x80) ? 0xF00000 : 0);
irq = we_mca_irq[(pos5 & 0x0c) >> 2];
sc->mem_size = (pos3 & 0x10) ? 16384 : 8192;
}
nict = asict = ma->ma_iot;
memt = ma->ma_memt;
aprint_normal(" slot %d port %#x-%#x mem %#x-%#x irq %d: %s\n",
ma->ma_slot + 1,
iobase, iobase + WE_NPORTS - 1,
maddr, maddr + sc->mem_size - 1,
irq, wep->we_name);
if (bus_space_map(asict, iobase, WE_NPORTS, 0, &asich)) {
aprint_error_dev(self, "can't map nic i/o space\n");
return;
}
if (bus_space_subregion(asict, asich, WE_NIC_OFFSET, WE_NIC_NPORTS,
&nich)) {
aprint_error_dev(self, "can't subregion i/o space\n");
return;
}
wsc->sc_type = wep->we_type;
wsc->sc_flags = WE_16BIT_ENABLE|WE_16BIT_NOTOGGLE;
sc->is790 = 0;
typestr = wep->we_typestr;
if (bus_space_map(memt, maddr, sc->mem_size, 0, &memh)) {
aprint_error_dev(self, "can't map shared memory %#x-%#x\n",
maddr, maddr + sc->mem_size - 1);
return;
}
wsc->sc_asict = asict;
wsc->sc_asich = asich;
sc->sc_regt = nict;
sc->sc_regh = nich;
sc->sc_buft = memt;
sc->sc_bufh = memh;
wsc->sc_maddr = maddr;
sc->sc_enabled = 1;
wsc->sc_init_hook = we_mca_init_hook;
if (we_config(self, wsc, typestr))
return;
wsc->sc_ih = mca_intr_establish(ma->ma_mc, irq,
IPL_NET, dp8390_intr, sc);
if (wsc->sc_ih == NULL) {
aprint_error_dev(self, "can't establish interrupt\n");
return;
}
}
void
we_mca_init_hook(struct we_softc *wsc)
{
bus_space_write_1(wsc->sc_asict, wsc->sc_asich, WE_LAAR, 0x04);
wsc->sc_laar_proto |= 0x04;
}