pccard_cis_quirks.c revision 172572
1/* $NetBSD: pcmcia_cis_quirks.c,v 1.6 2000/04/12 21:07:55 scw Exp $ */ 2 3#include <sys/cdefs.h> 4__FBSDID("$FreeBSD: head/sys/dev/pccard/pccard_cis_quirks.c 172572 2007-10-12 08:26:15Z remko $"); 5 6#define PCCARDDEBUG 7 8/*- 9 * Copyright (c) 1998 Marc Horowitz. All rights reserved. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. All advertising materials mentioning features or use of this software 20 * must display the following acknowledgement: 21 * This product includes software developed by Marc Horowitz. 22 * 4. The name of the author may not be used to endorse or promote products 23 * derived from this software without specific prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 26 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 27 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 28 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 29 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 34 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 */ 36 37#include <sys/param.h> 38#include <sys/bus.h> 39#include <sys/malloc.h> 40#include <sys/systm.h> 41 42#include <machine/bus.h> 43 44#include <dev/pccard/pccard_cis.h> 45#include <dev/pccard/pccardvar.h> 46#include <dev/pccard/pccardvarp.h> 47 48#include "pccarddevs.h" 49 50/* There are cards out there whose CIS flat-out lies. This file 51 contains struct pccard_function chains for those devices. */ 52 53/* these structures are just static templates which are then copied 54 into "live" allocated structures */ 55 56struct pccard_function pccard_3cxem556_func0 = { 57 0, /* function number */ 58 PCCARD_FUNCTION_NETWORK, 59 0x07, /* last cfe number */ 60 0x800, /* ccr_base */ 61 0x63, /* ccr_mask */ 62}; 63 64struct pccard_config_entry pccard_3cxem556_func0_cfe0 = { 65 0x07, /* cfe number */ 66 PCCARD_CFE_IO8 | PCCARD_CFE_IO16 | PCCARD_CFE_IRQLEVEL, 67 PCCARD_IFTYPE_IO, 68 1, /* num_iospace */ 69 4, /* iomask */ 70 { { 0x0010, 0 } }, /* iospace */ 71 0xffff, /* irqmask */ 72 0, /* num_memspace */ 73 { }, /* memspace */ 74 0, /* maxtwins */ 75}; 76 77static struct pccard_function pccard_3cxem556_func1 = { 78 1, /* function number */ 79 PCCARD_FUNCTION_SERIAL, 80 0x27, /* last cfe number */ 81 0x900, /* ccr_base */ 82 0x63, /* ccr_mask */ 83}; 84 85static struct pccard_config_entry pccard_3cxem556_func1_cfe0 = { 86 0x27, /* cfe number */ 87 PCCARD_CFE_IO8 | PCCARD_CFE_IRQLEVEL, 88 PCCARD_IFTYPE_IO, 89 1, /* num_iospace */ 90 3, /* iomask */ 91 { { 0x0008, 0 } }, /* iospace */ 92 0xffff, /* irqmask */ 93 0, /* num_memspace */ 94 { }, /* memspace */ 95 0, /* maxtwins */ 96}; 97 98static struct pccard_function pccard_3ccfem556bi_func0 = { 99 0, /* function number */ 100 PCCARD_FUNCTION_NETWORK, 101 0x07, /* last cfe number */ 102 0x1000, /* ccr_base */ 103 0x267, /* ccr_mask */ 104}; 105 106static struct pccard_config_entry pccard_3ccfem556bi_func0_cfe0 = { 107 0x07, /* cfe number */ 108 PCCARD_CFE_IO8 | PCCARD_CFE_IO16 | PCCARD_CFE_IRQLEVEL, 109 PCCARD_IFTYPE_IO, 110 1, /* num_iospace */ 111 5, /* iomask */ 112 { { 0x0020, 0 } }, /* iospace */ 113 0xffff, /* irqmask */ 114 0, /* num_memspace */ 115 { }, /* memspace */ 116 0, /* maxtwins */ 117}; 118 119static struct pccard_function pccard_3ccfem556bi_func1 = { 120 1, /* function number */ 121 PCCARD_FUNCTION_SERIAL, 122 0x27, /* last cfe number */ 123 0x1100, /* ccr_base */ 124 0x277, /* ccr_mask */ 125}; 126 127static struct pccard_config_entry pccard_3ccfem556bi_func1_cfe0 = { 128 0x27, /* cfe number */ 129 PCCARD_CFE_IO8 | PCCARD_CFE_IRQLEVEL, 130 PCCARD_IFTYPE_IO, 131 1, /* num_iospace */ 132 3, /* iomask */ 133 { { 0x0008, 0 } }, /* iospace */ 134 0xffff, /* irqmask */ 135 0, /* num_memspace */ 136 { }, /* memspace */ 137 0, /* maxtwins */ 138}; 139 140static struct pccard_function pccard_sveclancard_func0 = { 141 0, /* function number */ 142 PCCARD_FUNCTION_NETWORK, 143 0x1, /* last cfe number */ 144 0x100, /* ccr_base */ 145 0x1, /* ccr_mask */ 146}; 147 148static struct pccard_config_entry pccard_sveclancard_func0_cfe0 = { 149 0x1, /* cfe number */ 150 PCCARD_CFE_MWAIT_REQUIRED | PCCARD_CFE_RDYBSY_ACTIVE | 151 PCCARD_CFE_WP_ACTIVE | PCCARD_CFE_BVD_ACTIVE | PCCARD_CFE_IO16, 152 PCCARD_IFTYPE_IO, 153 1, /* num_iospace */ 154 5, /* iomask */ 155 { { 0x20, 0x300 } }, /* iospace */ 156 0xdeb8, /* irqmask */ 157 0, /* num_memspace */ 158 { }, /* memspace */ 159 0, /* maxtwins */ 160}; 161 162static struct pccard_function pccard_ndc_nd5100_func0 = { 163 0, /* function number */ 164 PCCARD_FUNCTION_NETWORK, 165 0x23, /* last cfe number */ 166 0x3f8, /* ccr_base */ 167 0x3, /* ccr_mask */ 168}; 169 170static struct pccard_config_entry pccard_ndc_nd5100_func0_cfe0 = { 171 0x20, /* cfe number */ 172 PCCARD_CFE_MWAIT_REQUIRED | PCCARD_CFE_IO16 | PCCARD_CFE_IRQLEVEL, 173 PCCARD_IFTYPE_IO, 174 1, /* num_iospace */ 175 5, /* iomask */ 176 { { 0x20, 0x300 } }, /* iospace */ 177 0xdeb8, /* irqmask */ 178 0, /* num_memspace */ 179 { }, /* memspace */ 180 0, /* maxtwins */ 181}; 182 183static struct pccard_function pccard_sierra_a555_func1 = { 184 1, /* function number */ 185 PCCARD_FUNCTION_SERIAL, 186 0x24, /* last cfe number */ 187 0x700, /* ccr_base */ 188 0x73, /* ccr_mask */ 189}; 190 191static struct pccard_config_entry pccard_sierra_a555_func1_cfe0 = { 192 0x22, /* cfe number */ 193 PCCARD_CFE_IO8 | PCCARD_CFE_IRQLEVEL, 194 PCCARD_IFTYPE_IO, 195 1, /* num_iospace */ 196 0, /* iomask */ 197 { { 0x0008, 0x3e8 } }, /* iospace */ 198 0x3fbc, /* irqmask */ 199 0, /* num_memspace */ 200 { }, /* memspace */ 201 0, /* maxtwins */ 202}; 203 204static struct pccard_cis_quirk pccard_cis_quirks[] = { 205 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556, PCMCIA_CIS_INVALID, 206 &pccard_3cxem556_func0, &pccard_3cxem556_func0_cfe0 }, 207 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556, PCMCIA_CIS_INVALID, 208 &pccard_3cxem556_func1, &pccard_3cxem556_func1_cfe0 }, 209 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556INT, PCMCIA_CIS_INVALID, 210 &pccard_3cxem556_func0, &pccard_3cxem556_func0_cfe0 }, 211 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556INT, PCMCIA_CIS_INVALID, 212 &pccard_3cxem556_func1, &pccard_3cxem556_func1_cfe0 }, 213 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CCFEM556BI, 214 PCMCIA_CIS_INVALID, 215 &pccard_3ccfem556bi_func0, &pccard_3ccfem556bi_func0_cfe0 }, 216 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CCFEM556BI, 217 PCMCIA_CIS_INVALID, 218 &pccard_3ccfem556bi_func1, &pccard_3ccfem556bi_func1_cfe0 }, 219 { PCMCIA_VENDOR_SIERRA, PCMCIA_PRODUCT_SIERRA_A550, 220 PCMCIA_CIS_INVALID, 221 &pccard_sierra_a555_func1, &pccard_sierra_a555_func1_cfe0 }, 222 { PCMCIA_VENDOR_SIERRA, PCMCIA_PRODUCT_SIERRA_A555, 223 PCMCIA_CIS_INVALID, 224 &pccard_sierra_a555_func1, &pccard_sierra_a555_func1_cfe0 }, 225 { PCMCIA_VENDOR_SIERRA, PCMCIA_PRODUCT_SIERRA_A710, 226 PCMCIA_CIS_INVALID, 227 &pccard_sierra_a555_func1, &pccard_sierra_a555_func1_cfe0 }, 228 { PCMCIA_VENDOR_SIERRA, PCMCIA_PRODUCT_SIERRA_AC710, 229 PCMCIA_CIS_INVALID, 230 &pccard_sierra_a555_func1, &pccard_sierra_a555_func1_cfe0 }, 231 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, PCMCIA_CIS_SVEC_LANCARD, 232 &pccard_sveclancard_func0, &pccard_sveclancard_func0_cfe0 }, 233 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, PCMCIA_CIS_NDC_ND5100_E, 234 &pccard_ndc_nd5100_func0, &pccard_ndc_nd5100_func0_cfe0 }, 235}; 236 237static int n_pccard_cis_quirks = 238 sizeof(pccard_cis_quirks)/sizeof(pccard_cis_quirks[0]); 239 240static int 241pccard_cis_quirk_match(struct pccard_softc *sc, struct pccard_cis_quirk *q) 242{ 243 if ((sc->card.manufacturer == q->manufacturer) && 244 (sc->card.product == q->product) && 245 (((sc->card.manufacturer != PCMCIA_VENDOR_INVALID) && 246 (sc->card.product != PCMCIA_PRODUCT_INVALID)) || 247 ((sc->card.manufacturer == PCMCIA_VENDOR_INVALID) && 248 (sc->card.product == PCMCIA_PRODUCT_INVALID) && 249 sc->card.cis1_info[0] && 250 (strcmp(sc->card.cis1_info[0], q->cis1_info[0]) == 0) && 251 sc->card.cis1_info[1] && 252 (strcmp(sc->card.cis1_info[1], q->cis1_info[1]) == 0)))) 253 return (1); 254 return (0); 255} 256 257void pccard_check_cis_quirks(device_t dev) 258{ 259 struct pccard_softc *sc = PCCARD_SOFTC(dev); 260 int wiped = 0; 261 int i, j; 262 struct pccard_function *pf, *pf_next, *pf_last; 263 struct pccard_config_entry *cfe, *cfe_next; 264 struct pccard_cis_quirk *q; 265 266 pf = NULL; 267 pf_last = NULL; 268 269 for (i=0; i<n_pccard_cis_quirks; i++) { 270 q = &pccard_cis_quirks[i]; 271 if (!pccard_cis_quirk_match(sc, q)) 272 continue; 273 if (!wiped) { 274 if (bootverbose) { 275 device_printf(dev, "using CIS quirks for "); 276 for (j = 0; j < 4; j++) { 277 if (sc->card.cis1_info[j] == NULL) 278 break; 279 if (j) 280 printf(", "); 281 printf("%s", sc->card.cis1_info[j]); 282 } 283 printf("\n"); 284 } 285 286 for (pf = STAILQ_FIRST(&sc->card.pf_head); pf != NULL; 287 pf = pf_next) { 288 for (cfe = STAILQ_FIRST(&pf->cfe_head); cfe != NULL; 289 cfe = cfe_next) { 290 cfe_next = STAILQ_NEXT(cfe, cfe_list); 291 free(cfe, M_DEVBUF); 292 } 293 pf_next = STAILQ_NEXT(pf, pf_list); 294 free(pf, M_DEVBUF); 295 } 296 297 STAILQ_INIT(&sc->card.pf_head); 298 wiped = 1; 299 } 300 301 if (pf_last == q->pf) { 302 cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT); 303 if (cfe == NULL) { 304 device_printf(dev, "no memory for quirk (1)\n"); 305 continue; 306 } 307 *cfe = *q->cfe; 308 STAILQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list); 309 } else { 310 pf = malloc(sizeof(*pf), M_DEVBUF, M_NOWAIT); 311 if (pf == NULL) { 312 device_printf(dev, 313 "no memory for pccard function\n"); 314 continue; 315 } 316 *pf = *q->pf; 317 STAILQ_INIT(&pf->cfe_head); 318 cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT); 319 if (cfe == NULL) { 320 free(pf, M_DEVBUF); 321 device_printf(dev, "no memory for quirk (2)\n"); 322 continue; 323 } 324 *cfe = *q->cfe; 325 STAILQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list); 326 STAILQ_INSERT_TAIL(&sc->card.pf_head, pf, pf_list); 327 pf_last = q->pf; 328 } 329 } 330} 331