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