pccard_cis_quirks.c revision 119418
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 119418 2003-08-24 17:55:58Z obrien $"); 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/systm.h> 39#include <sys/malloc.h> 40#include <sys/module.h> 41#include <sys/kernel.h> 42#include <sys/queue.h> 43#include <sys/types.h> 44 45#include <sys/bus.h> 46#include <machine/bus.h> 47#include <sys/rman.h> 48#include <machine/resource.h> 49 50#include <dev/pccard/pccarddevs.h> 51#include <dev/pccard/pccardreg.h> 52#include <dev/pccard/pccardvar.h> 53 54/* There are cards out there whose CIS flat-out lies. This file 55 contains struct pccard_function chains for those devices. */ 56 57/* these structures are just static templates which are then copied 58 into "live" allocated structures */ 59 60struct pccard_function pccard_3cxem556_func0 = { 61 0, /* function number */ 62 PCCARD_FUNCTION_NETWORK, 63 0x07, /* last cfe number */ 64 0x800, /* ccr_base */ 65 0x63, /* ccr_mask */ 66}; 67 68struct pccard_config_entry pccard_3cxem556_func0_cfe0 = { 69 0x07, /* cfe number */ 70 PCCARD_CFE_IO8 | PCCARD_CFE_IO16 | PCCARD_CFE_IRQLEVEL, 71 PCCARD_IFTYPE_IO, 72 1, /* num_iospace */ 73 4, /* iomask */ 74 { { 0x0010, 0 } }, /* iospace */ 75 0xffff, /* irqmask */ 76 0, /* num_memspace */ 77 { }, /* memspace */ 78 0, /* maxtwins */ 79}; 80 81static struct pccard_function pccard_3cxem556_func1 = { 82 1, /* function number */ 83 PCCARD_FUNCTION_SERIAL, 84 0x27, /* last cfe number */ 85 0x900, /* ccr_base */ 86 0x63, /* ccr_mask */ 87}; 88 89static struct pccard_config_entry pccard_3cxem556_func1_cfe0 = { 90 0x27, /* cfe number */ 91 PCCARD_CFE_IO8 | PCCARD_CFE_IRQLEVEL, 92 PCCARD_IFTYPE_IO, 93 1, /* num_iospace */ 94 3, /* iomask */ 95 { { 0x0008, 0 } }, /* iospace */ 96 0xffff, /* irqmask */ 97 0, /* num_memspace */ 98 { }, /* memspace */ 99 0, /* maxtwins */ 100}; 101 102static struct pccard_function pccard_3ccfem556bi_func0 = { 103 0, /* function number */ 104 PCCARD_FUNCTION_NETWORK, 105 0x07, /* last cfe number */ 106 0x1000, /* ccr_base */ 107 0x267, /* ccr_mask */ 108}; 109 110static struct pccard_config_entry pccard_3ccfem556bi_func0_cfe0 = { 111 0x07, /* cfe number */ 112 PCCARD_CFE_IO8 | PCCARD_CFE_IO16 | PCCARD_CFE_IRQLEVEL, 113 PCCARD_IFTYPE_IO, 114 1, /* num_iospace */ 115 5, /* iomask */ 116 { { 0x0020, 0 } }, /* iospace */ 117 0xffff, /* irqmask */ 118 0, /* num_memspace */ 119 { }, /* memspace */ 120 0, /* maxtwins */ 121}; 122 123static struct pccard_function pccard_3ccfem556bi_func1 = { 124 1, /* function number */ 125 PCCARD_FUNCTION_SERIAL, 126 0x27, /* last cfe number */ 127 0x1100, /* ccr_base */ 128 0x277, /* ccr_mask */ 129}; 130 131static struct pccard_config_entry pccard_3ccfem556bi_func1_cfe0 = { 132 0x27, /* cfe number */ 133 PCCARD_CFE_IO8 | PCCARD_CFE_IRQLEVEL, 134 PCCARD_IFTYPE_IO, 135 1, /* num_iospace */ 136 3, /* iomask */ 137 { { 0x0008, 0 } }, /* iospace */ 138 0xffff, /* irqmask */ 139 0, /* num_memspace */ 140 { }, /* memspace */ 141 0, /* maxtwins */ 142}; 143 144static struct pccard_function pccard_sveclancard_func0 = { 145 0, /* function number */ 146 PCCARD_FUNCTION_NETWORK, 147 0x1, /* last cfe number */ 148 0x100, /* ccr_base */ 149 0x1, /* ccr_mask */ 150}; 151 152static struct pccard_config_entry pccard_sveclancard_func0_cfe0 = { 153 0x1, /* cfe number */ 154 PCCARD_CFE_MWAIT_REQUIRED | PCCARD_CFE_RDYBSY_ACTIVE | 155 PCCARD_CFE_WP_ACTIVE | PCCARD_CFE_BVD_ACTIVE | PCCARD_CFE_IO16, 156 PCCARD_IFTYPE_IO, 157 1, /* num_iospace */ 158 5, /* iomask */ 159 { { 0x20, 0x300 } }, /* iospace */ 160 0xdeb8, /* irqmask */ 161 0, /* num_memspace */ 162 { }, /* memspace */ 163 0, /* maxtwins */ 164}; 165 166static struct pccard_function pccard_ndc_nd5100_func0 = { 167 0, /* function number */ 168 PCCARD_FUNCTION_NETWORK, 169 0x23, /* last cfe number */ 170 0x3f8, /* ccr_base */ 171 0x3, /* ccr_mask */ 172}; 173 174static struct pccard_config_entry pccard_ndc_nd5100_func0_cfe0 = { 175 0x20, /* cfe number */ 176 PCCARD_CFE_MWAIT_REQUIRED | PCCARD_CFE_IO16 | PCCARD_CFE_IRQLEVEL, 177 PCCARD_IFTYPE_IO, 178 1, /* num_iospace */ 179 5, /* iomask */ 180 { { 0x20, 0x300 } }, /* iospace */ 181 0xdeb8, /* irqmask */ 182 0, /* num_memspace */ 183 { }, /* memspace */ 184 0, /* maxtwins */ 185}; 186 187static struct pccard_cis_quirk pccard_cis_quirks[] = { 188 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556, PCMCIA_CIS_INVALID, 189 &pccard_3cxem556_func0, &pccard_3cxem556_func0_cfe0 }, 190 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556, PCMCIA_CIS_INVALID, 191 &pccard_3cxem556_func1, &pccard_3cxem556_func1_cfe0 }, 192 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556INT, PCMCIA_CIS_INVALID, 193 &pccard_3cxem556_func0, &pccard_3cxem556_func0_cfe0 }, 194 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556INT, PCMCIA_CIS_INVALID, 195 &pccard_3cxem556_func1, &pccard_3cxem556_func1_cfe0 }, 196 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CCFEM556BI, 197 PCMCIA_CIS_INVALID, 198 &pccard_3ccfem556bi_func0, &pccard_3ccfem556bi_func0_cfe0 }, 199 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CCFEM556BI, 200 PCMCIA_CIS_INVALID, 201 &pccard_3ccfem556bi_func1, &pccard_3ccfem556bi_func1_cfe0 }, 202 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, PCMCIA_CIS_SVEC_LANCARD, 203 &pccard_sveclancard_func0, &pccard_sveclancard_func0_cfe0 }, 204 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, PCMCIA_CIS_NDC_ND5100_E, 205 &pccard_ndc_nd5100_func0, &pccard_ndc_nd5100_func0_cfe0 }, 206}; 207 208static int n_pccard_cis_quirks = 209 sizeof(pccard_cis_quirks)/sizeof(pccard_cis_quirks[0]); 210 211void pccard_check_cis_quirks(device_t dev) 212{ 213 struct pccard_softc *sc = PCCARD_SOFTC(dev); 214 int wiped = 0; 215 int i, j; 216 struct pccard_function *pf, *pf_next, *pf_last; 217 struct pccard_config_entry *cfe, *cfe_next; 218 219 pf = NULL; 220 pf_last = NULL; 221 222 for (i=0; i<n_pccard_cis_quirks; i++) { 223 if ((sc->card.manufacturer == pccard_cis_quirks[i].manufacturer) && 224 (sc->card.product == pccard_cis_quirks[i].product) && 225 (((sc->card.manufacturer != PCMCIA_VENDOR_INVALID) && 226 (sc->card.product != PCMCIA_PRODUCT_INVALID)) || 227 ((sc->card.manufacturer == PCMCIA_VENDOR_INVALID) && 228 (sc->card.product == PCMCIA_PRODUCT_INVALID) && 229 sc->card.cis1_info[0] && 230 (strcmp(sc->card.cis1_info[0], 231 pccard_cis_quirks[i].cis1_info[0]) == 0) && 232 sc->card.cis1_info[1] && 233 (strcmp(sc->card.cis1_info[1], 234 pccard_cis_quirks[i].cis1_info[1]) == 0)))) { 235 if (!wiped) { 236 if (bootverbose) { 237 device_printf(dev, "using CIS quirks for "); 238 for (j = 0; j < 4; j++) { 239 if (sc->card.cis1_info[j] == NULL) 240 break; 241 if (j) 242 printf(", "); 243 printf("%s", sc->card.cis1_info[j]); 244 } 245 printf("\n"); 246 } 247 248 for (pf = STAILQ_FIRST(&sc->card.pf_head); pf != NULL; 249 pf = pf_next) { 250 for (cfe = STAILQ_FIRST(&pf->cfe_head); cfe != NULL; 251 cfe = cfe_next) { 252 cfe_next = STAILQ_NEXT(cfe, cfe_list); 253 free(cfe, M_DEVBUF); 254 } 255 pf_next = STAILQ_NEXT(pf, pf_list); 256 free(pf, M_DEVBUF); 257 } 258 259 STAILQ_INIT(&sc->card.pf_head); 260 wiped = 1; 261 } 262 263 if (pf_last == pccard_cis_quirks[i].pf) { 264 cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT); 265 *cfe = *pccard_cis_quirks[i].cfe; 266 267 STAILQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list); 268 } else { 269 pf = malloc(sizeof(*pf), M_DEVBUF, M_NOWAIT); 270 *pf = *pccard_cis_quirks[i].pf; 271 STAILQ_INIT(&pf->cfe_head); 272 273 cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT); 274 *cfe = *pccard_cis_quirks[i].cfe; 275 276 STAILQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list); 277 STAILQ_INSERT_TAIL(&sc->card.pf_head, pf, pf_list); 278 279 pf_last = pccard_cis_quirks[i].pf; 280 } 281 } 282 } 283} 284