pccard_cis_quirks.c revision 129740
165483Simp/* $NetBSD: pcmcia_cis_quirks.c,v 1.6 2000/04/12 21:07:55 scw Exp $ */ 252506Simp 3119418Sobrien#include <sys/cdefs.h> 4119418Sobrien__FBSDID("$FreeBSD: head/sys/dev/pccard/pccard_cis_quirks.c 129740 2004-05-26 00:53:10Z imp $"); 5119418Sobrien 652506Simp#define PCCARDDEBUG 752506Simp 852506Simp/* 952506Simp * Copyright (c) 1998 Marc Horowitz. All rights reserved. 1052506Simp * 1152506Simp * Redistribution and use in source and binary forms, with or without 1252506Simp * modification, are permitted provided that the following conditions 1352506Simp * are met: 1452506Simp * 1. Redistributions of source code must retain the above copyright 1552506Simp * notice, this list of conditions and the following disclaimer. 1652506Simp * 2. Redistributions in binary form must reproduce the above copyright 1752506Simp * notice, this list of conditions and the following disclaimer in the 1852506Simp * documentation and/or other materials provided with the distribution. 1952506Simp * 3. All advertising materials mentioning features or use of this software 2052506Simp * must display the following acknowledgement: 2152506Simp * This product includes software developed by Marc Horowitz. 2252506Simp * 4. The name of the author may not be used to endorse or promote products 2352506Simp * derived from this software without specific prior written permission. 2452506Simp * 2552506Simp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 2652506Simp * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 2752506Simp * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2852506Simp * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2952506Simp * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 3052506Simp * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 3152506Simp * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3252506Simp * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3352506Simp * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 3452506Simp * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3552506Simp */ 3652506Simp 3752506Simp#include <sys/param.h> 3852506Simp#include <sys/systm.h> 3952506Simp#include <sys/malloc.h> 4052506Simp#include <sys/module.h> 4152506Simp#include <sys/kernel.h> 4252506Simp#include <sys/queue.h> 4352506Simp#include <sys/types.h> 4452506Simp 4552506Simp#include <sys/bus.h> 4652506Simp#include <machine/bus.h> 4752506Simp#include <sys/rman.h> 4852506Simp#include <machine/resource.h> 4952506Simp 50129740Simp#include "pccarddevs.h" 5152506Simp#include <dev/pccard/pccardreg.h> 5252506Simp#include <dev/pccard/pccardvar.h> 53120868Simp#include <dev/pccard/pccard_cis.h> 5452506Simp 5552506Simp/* There are cards out there whose CIS flat-out lies. This file 5652506Simp contains struct pccard_function chains for those devices. */ 5752506Simp 5852506Simp/* these structures are just static templates which are then copied 5952506Simp into "live" allocated structures */ 6052506Simp 6152506Simpstruct pccard_function pccard_3cxem556_func0 = { 6252506Simp 0, /* function number */ 6352506Simp PCCARD_FUNCTION_NETWORK, 6452506Simp 0x07, /* last cfe number */ 6552506Simp 0x800, /* ccr_base */ 6652506Simp 0x63, /* ccr_mask */ 6752506Simp}; 6852506Simp 6952506Simpstruct pccard_config_entry pccard_3cxem556_func0_cfe0 = { 7052506Simp 0x07, /* cfe number */ 7152506Simp PCCARD_CFE_IO8 | PCCARD_CFE_IO16 | PCCARD_CFE_IRQLEVEL, 7252506Simp PCCARD_IFTYPE_IO, 7352506Simp 1, /* num_iospace */ 7452506Simp 4, /* iomask */ 7552506Simp { { 0x0010, 0 } }, /* iospace */ 7652506Simp 0xffff, /* irqmask */ 7752506Simp 0, /* num_memspace */ 7852506Simp { }, /* memspace */ 7952506Simp 0, /* maxtwins */ 8052506Simp}; 8152506Simp 8252506Simpstatic struct pccard_function pccard_3cxem556_func1 = { 8352506Simp 1, /* function number */ 8452506Simp PCCARD_FUNCTION_SERIAL, 8552506Simp 0x27, /* last cfe number */ 8652506Simp 0x900, /* ccr_base */ 8752506Simp 0x63, /* ccr_mask */ 8852506Simp}; 8952506Simp 9052506Simpstatic struct pccard_config_entry pccard_3cxem556_func1_cfe0 = { 9152506Simp 0x27, /* cfe number */ 9252506Simp PCCARD_CFE_IO8 | PCCARD_CFE_IRQLEVEL, 9352506Simp PCCARD_IFTYPE_IO, 9452506Simp 1, /* num_iospace */ 9552506Simp 3, /* iomask */ 9652506Simp { { 0x0008, 0 } }, /* iospace */ 9752506Simp 0xffff, /* irqmask */ 9852506Simp 0, /* num_memspace */ 9952506Simp { }, /* memspace */ 10052506Simp 0, /* maxtwins */ 10152506Simp}; 10252506Simp 10353813Simpstatic struct pccard_function pccard_3ccfem556bi_func0 = { 10453813Simp 0, /* function number */ 10553813Simp PCCARD_FUNCTION_NETWORK, 10653813Simp 0x07, /* last cfe number */ 10753813Simp 0x1000, /* ccr_base */ 10853813Simp 0x267, /* ccr_mask */ 10953813Simp}; 11053813Simp 11153813Simpstatic struct pccard_config_entry pccard_3ccfem556bi_func0_cfe0 = { 11253813Simp 0x07, /* cfe number */ 11353813Simp PCCARD_CFE_IO8 | PCCARD_CFE_IO16 | PCCARD_CFE_IRQLEVEL, 11453813Simp PCCARD_IFTYPE_IO, 11553813Simp 1, /* num_iospace */ 11653813Simp 5, /* iomask */ 11753813Simp { { 0x0020, 0 } }, /* iospace */ 11853813Simp 0xffff, /* irqmask */ 11953813Simp 0, /* num_memspace */ 12053813Simp { }, /* memspace */ 12153813Simp 0, /* maxtwins */ 12253813Simp}; 12353813Simp 12453813Simpstatic struct pccard_function pccard_3ccfem556bi_func1 = { 12553813Simp 1, /* function number */ 12653813Simp PCCARD_FUNCTION_SERIAL, 12753813Simp 0x27, /* last cfe number */ 12853813Simp 0x1100, /* ccr_base */ 12953813Simp 0x277, /* ccr_mask */ 13053813Simp}; 13153813Simp 13253813Simpstatic struct pccard_config_entry pccard_3ccfem556bi_func1_cfe0 = { 13353813Simp 0x27, /* cfe number */ 13453813Simp PCCARD_CFE_IO8 | PCCARD_CFE_IRQLEVEL, 13553813Simp PCCARD_IFTYPE_IO, 13653813Simp 1, /* num_iospace */ 13753813Simp 3, /* iomask */ 13853813Simp { { 0x0008, 0 } }, /* iospace */ 13953813Simp 0xffff, /* irqmask */ 14053813Simp 0, /* num_memspace */ 14153813Simp { }, /* memspace */ 14253813Simp 0, /* maxtwins */ 14353813Simp}; 14453813Simp 14552506Simpstatic struct pccard_function pccard_sveclancard_func0 = { 14652506Simp 0, /* function number */ 14752506Simp PCCARD_FUNCTION_NETWORK, 14852506Simp 0x1, /* last cfe number */ 14952506Simp 0x100, /* ccr_base */ 15052506Simp 0x1, /* ccr_mask */ 15152506Simp}; 15252506Simp 15352506Simpstatic struct pccard_config_entry pccard_sveclancard_func0_cfe0 = { 15452506Simp 0x1, /* cfe number */ 15552506Simp PCCARD_CFE_MWAIT_REQUIRED | PCCARD_CFE_RDYBSY_ACTIVE | 15652506Simp PCCARD_CFE_WP_ACTIVE | PCCARD_CFE_BVD_ACTIVE | PCCARD_CFE_IO16, 15752506Simp PCCARD_IFTYPE_IO, 15852506Simp 1, /* num_iospace */ 15952506Simp 5, /* iomask */ 16052506Simp { { 0x20, 0x300 } }, /* iospace */ 16152506Simp 0xdeb8, /* irqmask */ 16252506Simp 0, /* num_memspace */ 16352506Simp { }, /* memspace */ 16452506Simp 0, /* maxtwins */ 16552506Simp}; 16652506Simp 16765483Simpstatic struct pccard_function pccard_ndc_nd5100_func0 = { 16865483Simp 0, /* function number */ 16965483Simp PCCARD_FUNCTION_NETWORK, 17065483Simp 0x23, /* last cfe number */ 17165483Simp 0x3f8, /* ccr_base */ 17265483Simp 0x3, /* ccr_mask */ 17365483Simp}; 17465483Simp 17565483Simpstatic struct pccard_config_entry pccard_ndc_nd5100_func0_cfe0 = { 17665483Simp 0x20, /* cfe number */ 17765483Simp PCCARD_CFE_MWAIT_REQUIRED | PCCARD_CFE_IO16 | PCCARD_CFE_IRQLEVEL, 17865483Simp PCCARD_IFTYPE_IO, 17965483Simp 1, /* num_iospace */ 18065483Simp 5, /* iomask */ 18165483Simp { { 0x20, 0x300 } }, /* iospace */ 18265483Simp 0xdeb8, /* irqmask */ 18365483Simp 0, /* num_memspace */ 18465483Simp { }, /* memspace */ 18565483Simp 0, /* maxtwins */ 18665483Simp}; 18765483Simp 18852506Simpstatic struct pccard_cis_quirk pccard_cis_quirks[] = { 18986272Simp { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556, PCMCIA_CIS_INVALID, 19052506Simp &pccard_3cxem556_func0, &pccard_3cxem556_func0_cfe0 }, 19186272Simp { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556, PCMCIA_CIS_INVALID, 19252506Simp &pccard_3cxem556_func1, &pccard_3cxem556_func1_cfe0 }, 19386272Simp { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556INT, PCMCIA_CIS_INVALID, 19453813Simp &pccard_3cxem556_func0, &pccard_3cxem556_func0_cfe0 }, 19586272Simp { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556INT, PCMCIA_CIS_INVALID, 19653813Simp &pccard_3cxem556_func1, &pccard_3cxem556_func1_cfe0 }, 19786272Simp { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CCFEM556BI, 19886272Simp PCMCIA_CIS_INVALID, 19953813Simp &pccard_3ccfem556bi_func0, &pccard_3ccfem556bi_func0_cfe0 }, 20086272Simp { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CCFEM556BI, 20186272Simp PCMCIA_CIS_INVALID, 20253813Simp &pccard_3ccfem556bi_func1, &pccard_3ccfem556bi_func1_cfe0 }, 20386272Simp { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, PCMCIA_CIS_SVEC_LANCARD, 20452506Simp &pccard_sveclancard_func0, &pccard_sveclancard_func0_cfe0 }, 20586272Simp { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, PCMCIA_CIS_NDC_ND5100_E, 20665483Simp &pccard_ndc_nd5100_func0, &pccard_ndc_nd5100_func0_cfe0 }, 20752506Simp}; 20852506Simp 20952506Simpstatic int n_pccard_cis_quirks = 21052506Simp sizeof(pccard_cis_quirks)/sizeof(pccard_cis_quirks[0]); 21152506Simp 212120849Simpstatic int 213120849Simppccard_cis_quirk_match(struct pccard_softc *sc, struct pccard_cis_quirk *q) 214120849Simp{ 215120849Simp if ((sc->card.manufacturer == q->manufacturer) && 216120849Simp (sc->card.product == q->product) && 217120849Simp (((sc->card.manufacturer != PCMCIA_VENDOR_INVALID) && 218120849Simp (sc->card.product != PCMCIA_PRODUCT_INVALID)) || 219120849Simp ((sc->card.manufacturer == PCMCIA_VENDOR_INVALID) && 220120849Simp (sc->card.product == PCMCIA_PRODUCT_INVALID) && 221120849Simp sc->card.cis1_info[0] && 222120849Simp (strcmp(sc->card.cis1_info[0], q->cis1_info[0]) == 0) && 223120849Simp sc->card.cis1_info[1] && 224120849Simp (strcmp(sc->card.cis1_info[1], q->cis1_info[1]) == 0)))) 225120849Simp return (1); 226120849Simp return (0); 227120849Simp} 228120849Simp 22952506Simpvoid pccard_check_cis_quirks(device_t dev) 23052506Simp{ 23164850Simp struct pccard_softc *sc = PCCARD_SOFTC(dev); 23252506Simp int wiped = 0; 23352506Simp int i, j; 23452506Simp struct pccard_function *pf, *pf_next, *pf_last; 23552506Simp struct pccard_config_entry *cfe, *cfe_next; 236120849Simp struct pccard_cis_quirk *q; 23752506Simp 23852506Simp pf = NULL; 23952506Simp pf_last = NULL; 24052506Simp 24152506Simp for (i=0; i<n_pccard_cis_quirks; i++) { 242120849Simp q = &pccard_cis_quirks[i]; 243120849Simp if (!pccard_cis_quirk_match(sc, q)) 244120849Simp continue; 245120849Simp if (!wiped) { 246120849Simp if (bootverbose) { 247120849Simp device_printf(dev, "using CIS quirks for "); 248120849Simp for (j = 0; j < 4; j++) { 249120849Simp if (sc->card.cis1_info[j] == NULL) 250120849Simp break; 251120849Simp if (j) 252120849Simp printf(", "); 253120849Simp printf("%s", sc->card.cis1_info[j]); 25452506Simp } 255120849Simp printf("\n"); 256120849Simp } 25752506Simp 258120849Simp for (pf = STAILQ_FIRST(&sc->card.pf_head); pf != NULL; 259120849Simp pf = pf_next) { 260120849Simp for (cfe = STAILQ_FIRST(&pf->cfe_head); cfe != NULL; 261120849Simp cfe = cfe_next) { 262120849Simp cfe_next = STAILQ_NEXT(cfe, cfe_list); 263120849Simp free(cfe, M_DEVBUF); 26452506Simp } 265120849Simp pf_next = STAILQ_NEXT(pf, pf_list); 266120849Simp free(pf, M_DEVBUF); 26752506Simp } 26852506Simp 269120849Simp STAILQ_INIT(&sc->card.pf_head); 270120849Simp wiped = 1; 271120849Simp } 27252506Simp 273120849Simp if (pf_last == q->pf) { 274120849Simp cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT); 275120849Simp *cfe = *q->cfe; 276120849Simp STAILQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list); 277120849Simp } else { 278120849Simp pf = malloc(sizeof(*pf), M_DEVBUF, M_NOWAIT); 279120849Simp *pf = *q->pf; 280120849Simp STAILQ_INIT(&pf->cfe_head); 281120849Simp cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT); 282120849Simp *cfe = *q->cfe; 283120849Simp STAILQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list); 284120849Simp STAILQ_INSERT_TAIL(&sc->card.pf_head, pf, pf_list); 285120849Simp pf_last = q->pf; 28652506Simp } 28752506Simp } 28852506Simp} 289