#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: pcmcia_cis_quirks.c,v 1.36 2019/11/10 21:16:36 chs Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/kernel.h>
#include <sys/mbuf.h>
#include <dev/pcmcia/pcmciadevs.h>
#include <dev/pcmcia/pcmciareg.h>
#include <dev/pcmcia/pcmciachip.h>
#include <dev/pcmcia/pcmciavar.h>
static const struct pcmcia_function pcmcia_3cxem556_func0 = {
.number = 0,
.function = PCMCIA_FUNCTION_NETWORK,
.last_config_index = 0x07,
.ccr_base = 0x800,
.ccr_mask = 0x63,
};
static const struct pcmcia_config_entry pcmcia_3cxem556_func0_cfe0 = {
.number = 0x07,
.flags = PCMCIA_CFE_IO8 | PCMCIA_CFE_IO16 | PCMCIA_CFE_IRQLEVEL,
.iftype = PCMCIA_IFTYPE_IO,
.num_iospace = 1,
.iomask = 4,
.iospace = { { .length = 0x0010, .start = 0 } },
.irqmask = 0xffff,
};
static const struct pcmcia_function pcmcia_3cxem556_func1 = {
.number = 1,
.function = PCMCIA_FUNCTION_SERIAL,
.last_config_index = 0x27,
.ccr_base = 0x900,
.ccr_mask = 0x63,
};
static const struct pcmcia_config_entry pcmcia_3cxem556_func1_cfe0 = {
.number = 0x27,
.flags = PCMCIA_CFE_IO8 | PCMCIA_CFE_IRQLEVEL,
.iftype = PCMCIA_IFTYPE_IO,
.num_iospace = 1,
.iomask = 3,
.iospace = { { .length = 0x0008, .start = 0 } },
.irqmask = 0xffff,
};
static const struct pcmcia_function pcmcia_3ccfem556bi_func0 = {
.number = 0,
.function = PCMCIA_FUNCTION_NETWORK,
.last_config_index = 0x07,
.ccr_base = 0x1000,
.ccr_mask = 0x267,
};
static const struct pcmcia_config_entry pcmcia_3ccfem556bi_func0_cfe0 = {
.number = 0x07,
.flags = PCMCIA_CFE_IO8 | PCMCIA_CFE_IO16 | PCMCIA_CFE_IRQLEVEL,
.iftype = PCMCIA_IFTYPE_IO,
.num_iospace = 1,
.iomask = 5,
.iospace = { { .length = 0x0020, .start = 0 } },
};
static const struct pcmcia_function pcmcia_3ccfem556bi_func1 = {
.number = 1,
.function = PCMCIA_FUNCTION_SERIAL,
.last_config_index = 0x27,
.ccr_base = 0x1100,
.ccr_mask = 0x277,
};
static const struct pcmcia_config_entry pcmcia_3ccfem556bi_func1_cfe0 = {
.number = 0x27,
.flags = PCMCIA_CFE_IO8 | PCMCIA_CFE_IRQLEVEL,
.iftype = PCMCIA_IFTYPE_IO,
.num_iospace = 1,
.iomask = 3,
.iospace = { { .length = 0x0008, .start = 0 } },
.irqmask = 0xffff,
};
static const struct pcmcia_function pcmcia_sveclancard_func0 = {
.number = 0,
.function = PCMCIA_FUNCTION_NETWORK,
.last_config_index = 0x1,
.ccr_base = 0x100,
.ccr_mask = 0x1,
};
static const struct pcmcia_config_entry pcmcia_sveclancard_func0_cfe0 = {
.number = 0x1,
.flags = PCMCIA_CFE_MWAIT_REQUIRED | PCMCIA_CFE_RDYBSY_ACTIVE |
PCMCIA_CFE_WP_ACTIVE | PCMCIA_CFE_BVD_ACTIVE | PCMCIA_CFE_IO16,
.iftype = PCMCIA_IFTYPE_IO,
.num_iospace = 1,
.iomask = 5,
.iospace = { { .length = 0x20, .start = 0x300 } },
.irqmask = 0xdeb8,
};
static const struct pcmcia_function pcmcia_ndc_nd5100_func0 = {
.number = 0,
.function = PCMCIA_FUNCTION_NETWORK,
.last_config_index = 0x23,
.ccr_base = 0x3f8,
.ccr_mask = 0x3,
};
static const struct pcmcia_config_entry pcmcia_ndc_nd5100_func0_cfe0 = {
.number = 0x20,
.flags = PCMCIA_CFE_MWAIT_REQUIRED | PCMCIA_CFE_IO16 |
PCMCIA_CFE_IRQLEVEL,
.iftype = PCMCIA_IFTYPE_IO,
.num_iospace = 1,
.iomask = 5,
.iospace = { { .length = 0x20, .start = 0x300 } },
.irqmask = 0xdeb8,
};
static const struct pcmcia_function pcmcia_emtac_a2424i_func0 = {
.number = 0,
.function = PCMCIA_FUNCTION_NETWORK,
.last_config_index = 0x21,
.ccr_base = 0x3e0,
.ccr_mask = 0x1,
};
static const struct pcmcia_config_entry pcmcia_emtac_a2424i_func0_cfe0 = {
.number = 0x21,
.flags = PCMCIA_CFE_IO16 | PCMCIA_CFE_IRQLEVEL | PCMCIA_CFE_IRQPULSE,
.iftype = PCMCIA_IFTYPE_IO,
.num_iospace = 1,
.iomask = 6,
.iospace = { { .length = 0x40, .start = 0x100 } },
.irqmask = 0xffff,
};
static const struct pcmcia_function pcmcia_fujitsu_j181_func0 = {
.number = 0,
.function = PCMCIA_FUNCTION_NETWORK,
.last_config_index = 0x21,
.ccr_base = 0xfe0,
.ccr_mask = 0xf,
};
static const struct pcmcia_config_entry pcmcia_fujitsu_j181_func0_cfe0 = {
.number = 0xc,
.flags = PCMCIA_CFE_MWAIT_REQUIRED | PCMCIA_CFE_WP_ACTIVE |
PCMCIA_CFE_IO8 | PCMCIA_CFE_IO16 | PCMCIA_CFE_IRQLEVEL |
PCMCIA_CFE_IRQPULSE,
.iftype = PCMCIA_IFTYPE_IO,
.num_iospace = 1,
.iomask = 10,
.iospace = { { .length = 0x20, .start = 0x140 } },
.irqmask = 0xffff,
};
static const struct pcmcia_function pcmcia_necinfrontia_ax420n_func0 = {
.number = 0,
.function = PCMCIA_FUNCTION_SERIAL,
.last_config_index = 0x38,
.ccr_base = 0x200,
.ccr_mask = 0x1f,
};
static const struct pcmcia_config_entry pcmcia_necinfrontia_ax420n_func0_cfe0 = {
.number = 0x25,
.flags = PCMCIA_CFE_RDYBSY_ACTIVE | PCMCIA_CFE_IO8 |
PCMCIA_CFE_IRQLEVEL | PCMCIA_CFE_POWERDOWN |
PCMCIA_CFE_AUDIO,
.iftype = PCMCIA_IFTYPE_IO,
.num_iospace = 1,
.iomask = 10,
.iospace = { { .length = 0x8, .start = 0x3f8 } },
.irqmask = 0x86bc,
};
static const struct pcmcia_cis_quirk pcmcia_cis_quirks[] = {
{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556,
PCMCIA_CIS_INVALID,
&pcmcia_3cxem556_func0, &pcmcia_3cxem556_func0_cfe0 },
{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556,
PCMCIA_CIS_INVALID,
&pcmcia_3cxem556_func1, &pcmcia_3cxem556_func1_cfe0 },
{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556INT,
PCMCIA_CIS_INVALID,
&pcmcia_3cxem556_func0, &pcmcia_3cxem556_func0_cfe0 },
{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556INT,
PCMCIA_CIS_INVALID,
&pcmcia_3cxem556_func1, &pcmcia_3cxem556_func1_cfe0 },
{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CCFEM556BI,
PCMCIA_CIS_INVALID,
&pcmcia_3ccfem556bi_func0, &pcmcia_3ccfem556bi_func0_cfe0 },
{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CCFEM556BI,
PCMCIA_CIS_INVALID,
&pcmcia_3ccfem556bi_func1, &pcmcia_3ccfem556bi_func1_cfe0 },
{ PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
PCMCIA_CIS_SVEC_LANCARD,
&pcmcia_sveclancard_func0, &pcmcia_sveclancard_func0_cfe0 },
{ PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
PCMCIA_CIS_NDC_ND5100_E,
&pcmcia_ndc_nd5100_func0, &pcmcia_ndc_nd5100_func0_cfe0 },
{ PCMCIA_VENDOR_EMTAC, PCMCIA_PRODUCT_EMTAC_WLAN,
PCMCIA_CIS_INVALID,
&pcmcia_emtac_a2424i_func0, &pcmcia_emtac_a2424i_func0_cfe0 },
{ PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
PCMCIA_CIS_FUJITSU_FMV_J181,
&pcmcia_fujitsu_j181_func0, &pcmcia_fujitsu_j181_func0_cfe0 },
{ PCMCIA_VENDOR_NECINFRONTIA, PCMCIA_PRODUCT_NECINFRONTIA_AX420N,
PCMCIA_CIS_INVALID,
&pcmcia_necinfrontia_ax420n_func0,
&pcmcia_necinfrontia_ax420n_func0_cfe0 },
};
static const int pcmcia_cis_nquirks =
sizeof(pcmcia_cis_quirks) / sizeof(pcmcia_cis_quirks[0]);
void
pcmcia_check_cis_quirks(struct pcmcia_softc *sc)
{
int wiped = 0;
size_t i, j;
struct pcmcia_function *pf;
const struct pcmcia_function *pf_last;
struct pcmcia_config_entry *cfe;
struct pcmcia_card *card = &sc->card;
const struct pcmcia_cis_quirk *quirk;
pf = NULL;
pf_last = NULL;
for (i = 0; i < pcmcia_cis_nquirks; i++) {
quirk = &pcmcia_cis_quirks[i];
if (card->manufacturer == quirk->manufacturer &&
card->manufacturer != PCMCIA_VENDOR_INVALID &&
card->product == quirk->product &&
card->product != PCMCIA_PRODUCT_INVALID)
goto match;
for (j = 0; j < 2; j++)
if (card->cis1_info[j] == NULL ||
quirk->cis1_info[j] == NULL ||
strcmp(card->cis1_info[j],
quirk->cis1_info[j]) != 0)
goto nomatch;
match:
if (!wiped) {
if (pcmcia_verbose) {
printf("%s: using CIS quirks for ",
device_xname(sc->dev));
for (j = 0; j < 4; j++) {
if (card->cis1_info[j] == NULL)
break;
if (j)
printf(", ");
printf("%s", card->cis1_info[j]);
}
printf("\n");
}
pcmcia_free_pf(&card->pf_head);
wiped = 1;
}
if (pf_last != quirk->pf) {
pf = malloc(sizeof(*pf), M_DEVBUF, M_WAITOK);
*pf = *quirk->pf;
SIMPLEQ_INIT(&pf->cfe_head);
SIMPLEQ_INSERT_TAIL(&card->pf_head, pf, pf_list);
pf_last = quirk->pf;
}
cfe = malloc(sizeof(*cfe), M_DEVBUF, M_WAITOK);
*cfe = *quirk->cfe;
KASSERT(pf != NULL);
SIMPLEQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list);
nomatch:;
}
}