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