pccard_cis_quirks.c revision 120849
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 120849 2003-10-06 07:17:20Z imp $"); 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 211static int 212pccard_cis_quirk_match(struct pccard_softc *sc, struct pccard_cis_quirk *q) 213{ 214 if ((sc->card.manufacturer == q->manufacturer) && 215 (sc->card.product == q->product) && 216 (((sc->card.manufacturer != PCMCIA_VENDOR_INVALID) && 217 (sc->card.product != PCMCIA_PRODUCT_INVALID)) || 218 ((sc->card.manufacturer == PCMCIA_VENDOR_INVALID) && 219 (sc->card.product == PCMCIA_PRODUCT_INVALID) && 220 sc->card.cis1_info[0] && 221 (strcmp(sc->card.cis1_info[0], q->cis1_info[0]) == 0) && 222 sc->card.cis1_info[1] && 223 (strcmp(sc->card.cis1_info[1], q->cis1_info[1]) == 0)))) 224 return (1); 225 return (0); 226} 227 228void pccard_check_cis_quirks(device_t dev) 229{ 230 struct pccard_softc *sc = PCCARD_SOFTC(dev); 231 int wiped = 0; 232 int i, j; 233 struct pccard_function *pf, *pf_next, *pf_last; 234 struct pccard_config_entry *cfe, *cfe_next; 235 struct pccard_cis_quirk *q; 236 237 pf = NULL; 238 pf_last = NULL; 239 240 for (i=0; i<n_pccard_cis_quirks; i++) { 241 q = &pccard_cis_quirks[i]; 242 if (!pccard_cis_quirk_match(sc, q)) 243 continue; 244 if (!wiped) { 245 if (bootverbose) { 246 device_printf(dev, "using CIS quirks for "); 247 for (j = 0; j < 4; j++) { 248 if (sc->card.cis1_info[j] == NULL) 249 break; 250 if (j) 251 printf(", "); 252 printf("%s", sc->card.cis1_info[j]); 253 } 254 printf("\n"); 255 } 256 257 for (pf = STAILQ_FIRST(&sc->card.pf_head); pf != NULL; 258 pf = pf_next) { 259 for (cfe = STAILQ_FIRST(&pf->cfe_head); cfe != NULL; 260 cfe = cfe_next) { 261 cfe_next = STAILQ_NEXT(cfe, cfe_list); 262 free(cfe, M_DEVBUF); 263 } 264 pf_next = STAILQ_NEXT(pf, pf_list); 265 free(pf, M_DEVBUF); 266 } 267 268 STAILQ_INIT(&sc->card.pf_head); 269 wiped = 1; 270 } 271 272 if (pf_last == q->pf) { 273 cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT); 274 *cfe = *q->cfe; 275 STAILQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list); 276 } else { 277 pf = malloc(sizeof(*pf), M_DEVBUF, M_NOWAIT); 278 *pf = *q->pf; 279 STAILQ_INIT(&pf->cfe_head); 280 cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT); 281 *cfe = *q->cfe; 282 STAILQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list); 283 STAILQ_INSERT_TAIL(&sc->card.pf_head, pf, pf_list); 284 pf_last = q->pf; 285 } 286 } 287} 288