pccard_cis_quirks.c revision 172572
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 172572 2007-10-12 08:26:15Z remko $"); 5119418Sobrien 652506Simp#define PCCARDDEBUG 752506Simp 8139749Simp/*- 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> 38129762Simp#include <sys/bus.h> 39129781Simp#include <sys/malloc.h> 4052506Simp#include <sys/systm.h> 4152506Simp 4252506Simp#include <machine/bus.h> 4352506Simp 44129762Simp#include <dev/pccard/pccard_cis.h> 45129762Simp#include <dev/pccard/pccardvar.h> 46150371Sglebius#include <dev/pccard/pccardvarp.h> 47129781Simp 48129740Simp#include "pccarddevs.h" 4952506Simp 5052506Simp/* There are cards out there whose CIS flat-out lies. This file 5152506Simp contains struct pccard_function chains for those devices. */ 5252506Simp 5352506Simp/* these structures are just static templates which are then copied 5452506Simp into "live" allocated structures */ 5552506Simp 5652506Simpstruct pccard_function pccard_3cxem556_func0 = { 5752506Simp 0, /* function number */ 5852506Simp PCCARD_FUNCTION_NETWORK, 5952506Simp 0x07, /* last cfe number */ 6052506Simp 0x800, /* ccr_base */ 6152506Simp 0x63, /* ccr_mask */ 6252506Simp}; 6352506Simp 6452506Simpstruct pccard_config_entry pccard_3cxem556_func0_cfe0 = { 6552506Simp 0x07, /* cfe number */ 6652506Simp PCCARD_CFE_IO8 | PCCARD_CFE_IO16 | PCCARD_CFE_IRQLEVEL, 6752506Simp PCCARD_IFTYPE_IO, 6852506Simp 1, /* num_iospace */ 6952506Simp 4, /* iomask */ 7052506Simp { { 0x0010, 0 } }, /* iospace */ 7152506Simp 0xffff, /* irqmask */ 7252506Simp 0, /* num_memspace */ 7352506Simp { }, /* memspace */ 7452506Simp 0, /* maxtwins */ 7552506Simp}; 7652506Simp 7752506Simpstatic struct pccard_function pccard_3cxem556_func1 = { 7852506Simp 1, /* function number */ 7952506Simp PCCARD_FUNCTION_SERIAL, 8052506Simp 0x27, /* last cfe number */ 8152506Simp 0x900, /* ccr_base */ 8252506Simp 0x63, /* ccr_mask */ 8352506Simp}; 8452506Simp 8552506Simpstatic struct pccard_config_entry pccard_3cxem556_func1_cfe0 = { 8652506Simp 0x27, /* cfe number */ 8752506Simp PCCARD_CFE_IO8 | PCCARD_CFE_IRQLEVEL, 8852506Simp PCCARD_IFTYPE_IO, 8952506Simp 1, /* num_iospace */ 9052506Simp 3, /* iomask */ 9152506Simp { { 0x0008, 0 } }, /* iospace */ 9252506Simp 0xffff, /* irqmask */ 9352506Simp 0, /* num_memspace */ 9452506Simp { }, /* memspace */ 9552506Simp 0, /* maxtwins */ 9652506Simp}; 9752506Simp 9853813Simpstatic struct pccard_function pccard_3ccfem556bi_func0 = { 9953813Simp 0, /* function number */ 10053813Simp PCCARD_FUNCTION_NETWORK, 10153813Simp 0x07, /* last cfe number */ 10253813Simp 0x1000, /* ccr_base */ 10353813Simp 0x267, /* ccr_mask */ 10453813Simp}; 10553813Simp 10653813Simpstatic struct pccard_config_entry pccard_3ccfem556bi_func0_cfe0 = { 10753813Simp 0x07, /* cfe number */ 10853813Simp PCCARD_CFE_IO8 | PCCARD_CFE_IO16 | PCCARD_CFE_IRQLEVEL, 10953813Simp PCCARD_IFTYPE_IO, 11053813Simp 1, /* num_iospace */ 11153813Simp 5, /* iomask */ 11253813Simp { { 0x0020, 0 } }, /* iospace */ 11353813Simp 0xffff, /* irqmask */ 11453813Simp 0, /* num_memspace */ 11553813Simp { }, /* memspace */ 11653813Simp 0, /* maxtwins */ 11753813Simp}; 11853813Simp 11953813Simpstatic struct pccard_function pccard_3ccfem556bi_func1 = { 12053813Simp 1, /* function number */ 12153813Simp PCCARD_FUNCTION_SERIAL, 12253813Simp 0x27, /* last cfe number */ 12353813Simp 0x1100, /* ccr_base */ 12453813Simp 0x277, /* ccr_mask */ 12553813Simp}; 12653813Simp 12753813Simpstatic struct pccard_config_entry pccard_3ccfem556bi_func1_cfe0 = { 12853813Simp 0x27, /* cfe number */ 12953813Simp PCCARD_CFE_IO8 | PCCARD_CFE_IRQLEVEL, 13053813Simp PCCARD_IFTYPE_IO, 13153813Simp 1, /* num_iospace */ 13253813Simp 3, /* iomask */ 13353813Simp { { 0x0008, 0 } }, /* iospace */ 13453813Simp 0xffff, /* irqmask */ 13553813Simp 0, /* num_memspace */ 13653813Simp { }, /* memspace */ 13753813Simp 0, /* maxtwins */ 13853813Simp}; 13953813Simp 14052506Simpstatic struct pccard_function pccard_sveclancard_func0 = { 14152506Simp 0, /* function number */ 14252506Simp PCCARD_FUNCTION_NETWORK, 14352506Simp 0x1, /* last cfe number */ 14452506Simp 0x100, /* ccr_base */ 14552506Simp 0x1, /* ccr_mask */ 14652506Simp}; 14752506Simp 14852506Simpstatic struct pccard_config_entry pccard_sveclancard_func0_cfe0 = { 14952506Simp 0x1, /* cfe number */ 15052506Simp PCCARD_CFE_MWAIT_REQUIRED | PCCARD_CFE_RDYBSY_ACTIVE | 15152506Simp PCCARD_CFE_WP_ACTIVE | PCCARD_CFE_BVD_ACTIVE | PCCARD_CFE_IO16, 15252506Simp PCCARD_IFTYPE_IO, 15352506Simp 1, /* num_iospace */ 15452506Simp 5, /* iomask */ 15552506Simp { { 0x20, 0x300 } }, /* iospace */ 15652506Simp 0xdeb8, /* irqmask */ 15752506Simp 0, /* num_memspace */ 15852506Simp { }, /* memspace */ 15952506Simp 0, /* maxtwins */ 16052506Simp}; 16152506Simp 16265483Simpstatic struct pccard_function pccard_ndc_nd5100_func0 = { 16365483Simp 0, /* function number */ 16465483Simp PCCARD_FUNCTION_NETWORK, 16565483Simp 0x23, /* last cfe number */ 16665483Simp 0x3f8, /* ccr_base */ 16765483Simp 0x3, /* ccr_mask */ 16865483Simp}; 16965483Simp 17065483Simpstatic struct pccard_config_entry pccard_ndc_nd5100_func0_cfe0 = { 17165483Simp 0x20, /* cfe number */ 17265483Simp PCCARD_CFE_MWAIT_REQUIRED | PCCARD_CFE_IO16 | PCCARD_CFE_IRQLEVEL, 17365483Simp PCCARD_IFTYPE_IO, 17465483Simp 1, /* num_iospace */ 17565483Simp 5, /* iomask */ 17665483Simp { { 0x20, 0x300 } }, /* iospace */ 17765483Simp 0xdeb8, /* irqmask */ 17865483Simp 0, /* num_memspace */ 17965483Simp { }, /* memspace */ 18065483Simp 0, /* maxtwins */ 18165483Simp}; 18265483Simp 183172572Sremkostatic struct pccard_function pccard_sierra_a555_func1 = { 184172572Sremko 1, /* function number */ 185172572Sremko PCCARD_FUNCTION_SERIAL, 186172572Sremko 0x24, /* last cfe number */ 187172572Sremko 0x700, /* ccr_base */ 188172572Sremko 0x73, /* ccr_mask */ 189172572Sremko}; 190172572Sremko 191172572Sremkostatic struct pccard_config_entry pccard_sierra_a555_func1_cfe0 = { 192172572Sremko 0x22, /* cfe number */ 193172572Sremko PCCARD_CFE_IO8 | PCCARD_CFE_IRQLEVEL, 194172572Sremko PCCARD_IFTYPE_IO, 195172572Sremko 1, /* num_iospace */ 196172572Sremko 0, /* iomask */ 197172572Sremko { { 0x0008, 0x3e8 } }, /* iospace */ 198172572Sremko 0x3fbc, /* irqmask */ 199172572Sremko 0, /* num_memspace */ 200172572Sremko { }, /* memspace */ 201172572Sremko 0, /* maxtwins */ 202172572Sremko}; 203172572Sremko 20452506Simpstatic struct pccard_cis_quirk pccard_cis_quirks[] = { 20586272Simp { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556, PCMCIA_CIS_INVALID, 20652506Simp &pccard_3cxem556_func0, &pccard_3cxem556_func0_cfe0 }, 20786272Simp { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556, PCMCIA_CIS_INVALID, 20852506Simp &pccard_3cxem556_func1, &pccard_3cxem556_func1_cfe0 }, 20986272Simp { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556INT, PCMCIA_CIS_INVALID, 21053813Simp &pccard_3cxem556_func0, &pccard_3cxem556_func0_cfe0 }, 21186272Simp { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556INT, PCMCIA_CIS_INVALID, 21253813Simp &pccard_3cxem556_func1, &pccard_3cxem556_func1_cfe0 }, 21386272Simp { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CCFEM556BI, 21486272Simp PCMCIA_CIS_INVALID, 21553813Simp &pccard_3ccfem556bi_func0, &pccard_3ccfem556bi_func0_cfe0 }, 21686272Simp { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CCFEM556BI, 21786272Simp PCMCIA_CIS_INVALID, 21853813Simp &pccard_3ccfem556bi_func1, &pccard_3ccfem556bi_func1_cfe0 }, 219172572Sremko { PCMCIA_VENDOR_SIERRA, PCMCIA_PRODUCT_SIERRA_A550, 220172572Sremko PCMCIA_CIS_INVALID, 221172572Sremko &pccard_sierra_a555_func1, &pccard_sierra_a555_func1_cfe0 }, 222172572Sremko { PCMCIA_VENDOR_SIERRA, PCMCIA_PRODUCT_SIERRA_A555, 223172572Sremko PCMCIA_CIS_INVALID, 224172572Sremko &pccard_sierra_a555_func1, &pccard_sierra_a555_func1_cfe0 }, 225172572Sremko { PCMCIA_VENDOR_SIERRA, PCMCIA_PRODUCT_SIERRA_A710, 226172572Sremko PCMCIA_CIS_INVALID, 227172572Sremko &pccard_sierra_a555_func1, &pccard_sierra_a555_func1_cfe0 }, 228172572Sremko { PCMCIA_VENDOR_SIERRA, PCMCIA_PRODUCT_SIERRA_AC710, 229172572Sremko PCMCIA_CIS_INVALID, 230172572Sremko &pccard_sierra_a555_func1, &pccard_sierra_a555_func1_cfe0 }, 23186272Simp { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, PCMCIA_CIS_SVEC_LANCARD, 23252506Simp &pccard_sveclancard_func0, &pccard_sveclancard_func0_cfe0 }, 23386272Simp { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, PCMCIA_CIS_NDC_ND5100_E, 23465483Simp &pccard_ndc_nd5100_func0, &pccard_ndc_nd5100_func0_cfe0 }, 23552506Simp}; 23652506Simp 23752506Simpstatic int n_pccard_cis_quirks = 23852506Simp sizeof(pccard_cis_quirks)/sizeof(pccard_cis_quirks[0]); 23952506Simp 240120849Simpstatic int 241120849Simppccard_cis_quirk_match(struct pccard_softc *sc, struct pccard_cis_quirk *q) 242120849Simp{ 243120849Simp if ((sc->card.manufacturer == q->manufacturer) && 244120849Simp (sc->card.product == q->product) && 245120849Simp (((sc->card.manufacturer != PCMCIA_VENDOR_INVALID) && 246120849Simp (sc->card.product != PCMCIA_PRODUCT_INVALID)) || 247120849Simp ((sc->card.manufacturer == PCMCIA_VENDOR_INVALID) && 248120849Simp (sc->card.product == PCMCIA_PRODUCT_INVALID) && 249120849Simp sc->card.cis1_info[0] && 250120849Simp (strcmp(sc->card.cis1_info[0], q->cis1_info[0]) == 0) && 251120849Simp sc->card.cis1_info[1] && 252120849Simp (strcmp(sc->card.cis1_info[1], q->cis1_info[1]) == 0)))) 253120849Simp return (1); 254120849Simp return (0); 255120849Simp} 256120849Simp 25752506Simpvoid pccard_check_cis_quirks(device_t dev) 25852506Simp{ 25964850Simp struct pccard_softc *sc = PCCARD_SOFTC(dev); 26052506Simp int wiped = 0; 26152506Simp int i, j; 26252506Simp struct pccard_function *pf, *pf_next, *pf_last; 26352506Simp struct pccard_config_entry *cfe, *cfe_next; 264120849Simp struct pccard_cis_quirk *q; 26552506Simp 26652506Simp pf = NULL; 26752506Simp pf_last = NULL; 26852506Simp 26952506Simp for (i=0; i<n_pccard_cis_quirks; i++) { 270120849Simp q = &pccard_cis_quirks[i]; 271120849Simp if (!pccard_cis_quirk_match(sc, q)) 272120849Simp continue; 273120849Simp if (!wiped) { 274120849Simp if (bootverbose) { 275120849Simp device_printf(dev, "using CIS quirks for "); 276120849Simp for (j = 0; j < 4; j++) { 277120849Simp if (sc->card.cis1_info[j] == NULL) 278120849Simp break; 279120849Simp if (j) 280120849Simp printf(", "); 281120849Simp printf("%s", sc->card.cis1_info[j]); 28252506Simp } 283120849Simp printf("\n"); 284120849Simp } 28552506Simp 286120849Simp for (pf = STAILQ_FIRST(&sc->card.pf_head); pf != NULL; 287120849Simp pf = pf_next) { 288120849Simp for (cfe = STAILQ_FIRST(&pf->cfe_head); cfe != NULL; 289120849Simp cfe = cfe_next) { 290120849Simp cfe_next = STAILQ_NEXT(cfe, cfe_list); 291120849Simp free(cfe, M_DEVBUF); 29252506Simp } 293120849Simp pf_next = STAILQ_NEXT(pf, pf_list); 294120849Simp free(pf, M_DEVBUF); 29552506Simp } 29652506Simp 297120849Simp STAILQ_INIT(&sc->card.pf_head); 298120849Simp wiped = 1; 299120849Simp } 30052506Simp 301120849Simp if (pf_last == q->pf) { 302120849Simp cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT); 303144158Ssam if (cfe == NULL) { 304144158Ssam device_printf(dev, "no memory for quirk (1)\n"); 305144158Ssam continue; 306144158Ssam } 307120849Simp *cfe = *q->cfe; 308120849Simp STAILQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list); 309120849Simp } else { 310120849Simp pf = malloc(sizeof(*pf), M_DEVBUF, M_NOWAIT); 311144158Ssam if (pf == NULL) { 312144158Ssam device_printf(dev, 313144158Ssam "no memory for pccard function\n"); 314144158Ssam continue; 315144158Ssam } 316120849Simp *pf = *q->pf; 317120849Simp STAILQ_INIT(&pf->cfe_head); 318120849Simp cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT); 319144158Ssam if (cfe == NULL) { 320144158Ssam free(pf, M_DEVBUF); 321144158Ssam device_printf(dev, "no memory for quirk (2)\n"); 322144158Ssam continue; 323144158Ssam } 324120849Simp *cfe = *q->cfe; 325120849Simp STAILQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list); 326120849Simp STAILQ_INSERT_TAIL(&sc->card.pf_head, pf, pf_list); 327120849Simp pf_last = q->pf; 32852506Simp } 32952506Simp } 33052506Simp} 331