1 /* $OpenBSD: pcmcia_cis_quirks.c,v 1.12 2015/03/14 03:38:49 jsg Exp $ */ 2 /* $NetBSD: pcmcia_cis_quirks.c,v 1.3 1998/12/29 09:00:28 marc Exp $ */ 3 4 /* 5 * Copyright (c) 1998 Marc Horowitz. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by Marc Horowitz. 18 * 4. The name of the author may not be used to endorse or promote products 19 * derived from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 #include <sys/types.h> 34 #include <sys/param.h> 35 #include <sys/systm.h> 36 #include <sys/malloc.h> 37 #include <sys/device.h> 38 39 #include <dev/pcmcia/pcmciadevs.h> 40 #include <dev/pcmcia/pcmciareg.h> 41 #include <dev/pcmcia/pcmciavar.h> 42 43 /* There are cards out there whose CIS flat-out lies. This file 44 contains struct pcmcia_function chains for those devices. */ 45 46 /* these structures are just static templates which are then copied 47 into "live" allocated structures */ 48 49 struct pcmcia_function pcmcia_3cxem556_func0 = { 50 0, /* function number */ 51 PCMCIA_FUNCTION_NETWORK, 52 0x07, /* last cfe number */ 53 0x800, /* ccr_base */ 54 0x63, /* ccr_mask */ 55 }; 56 57 struct pcmcia_config_entry pcmcia_3cxem556_func0_cfe0 = { 58 0x07, /* cfe number */ 59 PCMCIA_CFE_IO8 | PCMCIA_CFE_IO16 | PCMCIA_CFE_IRQLEVEL, 60 PCMCIA_IFTYPE_IO, 61 1, /* num_iospace */ 62 4, /* iomask */ 63 { { 0x0010, 0 } }, /* iospace */ 64 0xffff, /* irqmask */ 65 0, /* num_memspace */ 66 { }, /* memspace */ 67 0, /* maxtwins */ 68 }; 69 70 static struct pcmcia_function pcmcia_3cxem556_func1 = { 71 1, /* function number */ 72 PCMCIA_FUNCTION_SERIAL, 73 0x27, /* last cfe number */ 74 0x900, /* ccr_base */ 75 0x63, /* ccr_mask */ 76 }; 77 78 static struct pcmcia_config_entry pcmcia_3cxem556_func1_cfe0 = { 79 0x27, /* cfe number */ 80 PCMCIA_CFE_IO8 | PCMCIA_CFE_IRQLEVEL, 81 PCMCIA_IFTYPE_IO, 82 1, /* num_iospace */ 83 3, /* iomask */ 84 { { 0x0008, 0 } }, /* iospace */ 85 0xffff, /* irqmask */ 86 0, /* num_memspace */ 87 { }, /* memspace */ 88 0, /* maxtwins */ 89 }; 90 91 struct pcmcia_function pcmcia_megahertz_xjem1144_func0 = { 92 0, /* function number */ 93 PCMCIA_FUNCTION_NETWORK, 94 0x07, /* last cfe number */ 95 0x200, /* ccr_base */ 96 0x63, /* ccr_mask */ 97 }; 98 99 struct pcmcia_config_entry pcmcia_megahertz_xjem1144_func0_cfe0 = { 100 0x07, /* cfe number */ 101 PCMCIA_CFE_IO8 | PCMCIA_CFE_IO16 | PCMCIA_CFE_IRQLEVEL, 102 PCMCIA_IFTYPE_IO, 103 1, /* num_iospace */ 104 4, /* iomask */ 105 { { 0x0010, 0 } }, /* iospace */ 106 0xffff, /* irqmask */ 107 0, /* num_memspace */ 108 { }, /* memspace */ 109 0, /* maxtwins */ 110 }; 111 112 static struct pcmcia_function pcmcia_megahertz_xjem1144_func1 = { 113 1, /* function number */ 114 PCMCIA_FUNCTION_SERIAL, 115 0x35, /* last cfe number */ 116 0x300, /* ccr_base */ 117 0x3, /* ccr_mask */ 118 }; 119 120 static struct pcmcia_config_entry pcmcia_megahertz_xjem1144_func1_cfe0 = { 121 0x35, /* cfe number */ 122 PCMCIA_CFE_IO8 | PCMCIA_CFE_IRQLEVEL, PCMCIA_IFTYPE_IO, 123 1, /* num_iospace */ 124 0, /* iomask */ 125 { { 0x0008, 0x2f8 } }, /* iospace */ 126 0xffff, /* irqmask */ 127 0, /* num_memspace */ 128 { }, /* memspace */ 129 0, /* maxtwins */ 130 }; 131 132 static struct pcmcia_function pcmcia_sierra_a555_func1 = { 133 1, /* function number */ 134 PCMCIA_FUNCTION_SERIAL, 135 0x24, /* last cfe number */ 136 0x700, /* ccr_base */ 137 0x73, /* ccr_mask */ 138 }; 139 140 static struct pcmcia_config_entry pcmcia_sierra_a555_func1_cfe0 = { 141 0x20, /* cfe number */ 142 PCMCIA_CFE_IO8 | PCMCIA_CFE_IRQLEVEL, PCMCIA_IFTYPE_IO, 143 1, /* num_iospace */ 144 0, /* iomask */ 145 { { 0x0008, 0x3f8 } }, /* iospace */ 146 0x3fbc, /* irqmask */ 147 0, /* num_memspace */ 148 { }, /* memspace */ 149 0, /* maxtwins */ 150 }; 151 152 static struct pcmcia_function pcmcia_sveclancard_func0 = { 153 0, /* function number */ 154 PCMCIA_FUNCTION_NETWORK, 155 0x1, /* last cfe number */ 156 0x100, /* ccr_base */ 157 0x1, /* ccr_mask */ 158 }; 159 160 static struct pcmcia_config_entry pcmcia_sveclancard_func0_cfe0 = { 161 0x1, /* cfe number */ 162 PCMCIA_CFE_MWAIT_REQUIRED | PCMCIA_CFE_RDYBSY_ACTIVE | 163 PCMCIA_CFE_WP_ACTIVE | PCMCIA_CFE_BVD_ACTIVE | PCMCIA_CFE_IO16, 164 PCMCIA_IFTYPE_IO, 165 1, /* num_iospace */ 166 5, /* iomask */ 167 { { 0x20, 0x300 } }, /* iospace */ 168 0xdeb8, /* irqmask */ 169 0, /* num_memspace */ 170 { }, /* memspace */ 171 0, /* maxtwins */ 172 }; 173 174 static struct pcmcia_cis_quirk pcmcia_cis_quirks[] = { 175 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556, PCMCIA_CIS_INVALID, 176 &pcmcia_3cxem556_func0, &pcmcia_3cxem556_func0_cfe0 }, 177 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556, PCMCIA_CIS_INVALID, 178 &pcmcia_3cxem556_func1, &pcmcia_3cxem556_func1_cfe0 }, 179 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556B, 180 PCMCIA_CIS_INVALID, 181 &pcmcia_3cxem556_func0, &pcmcia_3cxem556_func0_cfe0 }, 182 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556B, 183 PCMCIA_CIS_INVALID, 184 &pcmcia_3cxem556_func1, &pcmcia_3cxem556_func1_cfe0 }, 185 { PCMCIA_VENDOR_MEGAHERTZ2, PCMCIA_PRODUCT_MEGAHERTZ2_XJEM1144, 186 PCMCIA_CIS_INVALID, 187 &pcmcia_megahertz_xjem1144_func0, 188 &pcmcia_megahertz_xjem1144_func0_cfe0 }, 189 { PCMCIA_VENDOR_MEGAHERTZ2, PCMCIA_PRODUCT_MEGAHERTZ2_XJEM1144, 190 PCMCIA_CIS_INVALID, 191 &pcmcia_megahertz_xjem1144_func1, 192 &pcmcia_megahertz_xjem1144_func1_cfe0 }, 193 { PCMCIA_VENDOR_SIERRA, PCMCIA_PRODUCT_SIERRA_A550, 194 PCMCIA_CIS_INVALID, 195 &pcmcia_sierra_a555_func1, &pcmcia_sierra_a555_func1_cfe0 }, 196 { PCMCIA_VENDOR_SIERRA, PCMCIA_PRODUCT_SIERRA_A555, 197 PCMCIA_CIS_INVALID, 198 &pcmcia_sierra_a555_func1, &pcmcia_sierra_a555_func1_cfe0 }, 199 { PCMCIA_VENDOR_SIERRA, PCMCIA_PRODUCT_SIERRA_A710, 200 PCMCIA_CIS_INVALID, 201 &pcmcia_sierra_a555_func1, &pcmcia_sierra_a555_func1_cfe0 }, 202 { PCMCIA_VENDOR_SIERRA, PCMCIA_PRODUCT_SIERRA_AC710, 203 PCMCIA_CIS_INVALID, 204 &pcmcia_sierra_a555_func1, &pcmcia_sierra_a555_func1_cfe0 }, 205 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, 206 PCMCIA_CIS_SVEC_LANCARD, 207 &pcmcia_sveclancard_func0, &pcmcia_sveclancard_func0_cfe0 }, 208 }; 209 210 void pcmcia_check_cis_quirks(sc) 211 struct pcmcia_softc *sc; 212 { 213 int wiped = 0; 214 int i, j; 215 struct pcmcia_function *pf, *pf_next, *pf_last; 216 struct pcmcia_config_entry *cfe, *cfe_next; 217 218 pf = NULL; 219 pf_last = NULL; 220 221 222 for (i = 0; i < nitems(pcmcia_cis_quirks); 223 i++) { 224 if ((sc->card.manufacturer == pcmcia_cis_quirks[i].manufacturer) && 225 (sc->card.product == pcmcia_cis_quirks[i].product) && 226 (((sc->card.manufacturer != PCMCIA_VENDOR_INVALID) && 227 (sc->card.product != PCMCIA_PRODUCT_INVALID)) || 228 ((sc->card.manufacturer == PCMCIA_VENDOR_INVALID) && 229 (sc->card.product == PCMCIA_PRODUCT_INVALID) && 230 sc->card.cis1_info[0] && 231 (strcmp(sc->card.cis1_info[0], 232 pcmcia_cis_quirks[i].cis1_info[0]) == 0) && 233 sc->card.cis1_info[1] && 234 (strcmp(sc->card.cis1_info[1], 235 pcmcia_cis_quirks[i].cis1_info[1]) == 0)))) { 236 if (!wiped) { 237 if (pcmcia_verbose) { 238 printf("%s: using CIS quirks for ", sc->dev.dv_xname); 239 for (j = 0; j < 4; j++) { 240 if (sc->card.cis1_info[j] == NULL) 241 break; 242 if (j) 243 printf(", "); 244 printf("%s", sc->card.cis1_info[j]); 245 } 246 printf("\n"); 247 } 248 249 for (pf = SIMPLEQ_FIRST(&sc->card.pf_head); pf != NULL; 250 pf = pf_next) { 251 for (cfe = SIMPLEQ_FIRST(&pf->cfe_head); cfe != NULL; 252 cfe = cfe_next) { 253 cfe_next = SIMPLEQ_NEXT(cfe, cfe_list); 254 free(cfe, M_DEVBUF, 0); 255 } 256 pf_next = SIMPLEQ_NEXT(pf, pf_list); 257 free(pf, M_DEVBUF, 0); 258 } 259 260 SIMPLEQ_INIT(&sc->card.pf_head); 261 wiped = 1; 262 } 263 264 if (pf_last == pcmcia_cis_quirks[i].pf) { 265 cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT); 266 if (cfe == NULL) 267 return; 268 *cfe = *pcmcia_cis_quirks[i].cfe; 269 270 SIMPLEQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list); 271 } else { 272 pf = malloc(sizeof(*pf), M_DEVBUF, M_NOWAIT); 273 if (pf == NULL) 274 return; 275 *pf = *pcmcia_cis_quirks[i].pf; 276 SIMPLEQ_INIT(&pf->cfe_head); 277 278 cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT); 279 if (cfe == NULL) 280 return; 281 *cfe = *pcmcia_cis_quirks[i].cfe; 282 283 SIMPLEQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list); 284 SIMPLEQ_INSERT_TAIL(&sc->card.pf_head, pf, pf_list); 285 286 pf_last = pcmcia_cis_quirks[i].pf; 287 } 288 } 289 } 290 } 291