Home | History | Annotate | Line # | Download | only in pcmcia
pcmcia_cis_quirks.c revision 1.14
      1 /*	$NetBSD: pcmcia_cis_quirks.c,v 1.14 2001/11/15 09:48:13 lukem Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1998 Marc Horowitz.  All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. All advertising materials mentioning features or use of this software
     15  *    must display the following acknowledgement:
     16  *	This product includes software developed by Marc Horowitz.
     17  * 4. The name of the author may not be used to endorse or promote products
     18  *    derived from this software without specific prior written permission.
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include <sys/cdefs.h>
     33 __KERNEL_RCSID(0, "$NetBSD: pcmcia_cis_quirks.c,v 1.14 2001/11/15 09:48:13 lukem Exp $");
     34 
     35 #include <sys/param.h>
     36 #include <sys/systm.h>
     37 #include <sys/device.h>
     38 #include <sys/mbuf.h>
     39 
     40 #include <dev/pcmcia/pcmciadevs.h>
     41 #include <dev/pcmcia/pcmciareg.h>
     42 #include <dev/pcmcia/pcmciachip.h>
     43 #include <dev/pcmcia/pcmciavar.h>
     44 
     45 /* There are cards out there whose CIS flat-out lies.  This file
     46    contains struct pcmcia_function chains for those devices. */
     47 
     48 /* these structures are just static templates which are then copied
     49    into "live" allocated structures */
     50 
     51 static const struct pcmcia_function pcmcia_dlink_de650_func0 = {
     52 	0,
     53 	PCMCIA_FUNCTION_NETWORK,
     54 	0x23,
     55 	0x400,
     56 	0x0b,
     57 };
     58 
     59 static const struct pcmcia_config_entry pcmcia_dlink_de650_func0_cfe0 = {
     60 	0x20,
     61 	PCMCIA_CFE_IO16 | PCMCIA_CFE_IRQLEVEL,
     62 	PCMCIA_IFTYPE_IO,
     63 	1,
     64 	5,
     65 	{ { 0x20, 0x360 } },
     66 	0xbe7c,
     67 	0,
     68 	{ { 0 } },
     69 	0,
     70 };
     71 
     72 static const struct pcmcia_config_entry pcmcia_dlink_de650_func0_cfe1 = {
     73 	0x21,
     74 	PCMCIA_CFE_IO16 | PCMCIA_CFE_IRQLEVEL,
     75 	PCMCIA_IFTYPE_IO,
     76 	1,
     77 	5,
     78 	{ { 0x20, 0x340 } },
     79 	0xbe7c,
     80 	0,
     81 	{ { 0 } },
     82 	0,
     83 };
     84 
     85 static const struct pcmcia_config_entry pcmcia_dlink_de650_func0_cfe2 = {
     86 	0x22,
     87 	PCMCIA_CFE_IO16 | PCMCIA_CFE_IRQLEVEL,
     88 	PCMCIA_IFTYPE_IO,
     89 	1,
     90 	5,
     91 	{ { 0x20, 0x320 } },
     92 	0xbe7c,
     93 	0,
     94 	{ { 0 } },
     95 	0,
     96 };
     97 
     98 static const struct pcmcia_config_entry pcmcia_dlink_de650_func0_cfe3 = {
     99 	0x23,
    100 	PCMCIA_CFE_IO16 | PCMCIA_CFE_IRQLEVEL,
    101 	PCMCIA_IFTYPE_IO,
    102 	1,
    103 	5,
    104 	{ { 0x20, 0x300 } },
    105 	0xbe7c,
    106 	0,
    107 	{ { 0 } },
    108 	0,
    109 };
    110 
    111 static const struct pcmcia_function pcmcia_3cxem556_func0 = {
    112 	0,			/* function number */
    113 	PCMCIA_FUNCTION_NETWORK,
    114 	0x07,			/* last cfe number */
    115 	0x800,			/* ccr_base */
    116 	0x63,			/* ccr_mask */
    117 };
    118 
    119 static const struct pcmcia_config_entry pcmcia_3cxem556_func0_cfe0 = {
    120 	0x07,			/* cfe number */
    121 	PCMCIA_CFE_IO8 | PCMCIA_CFE_IO16 | PCMCIA_CFE_IRQLEVEL,
    122 	PCMCIA_IFTYPE_IO,
    123 	1,			/* num_iospace */
    124 	4,			/* iomask */
    125 	{ { 0x0010, 0 } },	/* iospace */
    126 	0xffff,			/* irqmask */
    127 	0,			/* num_memspace */
    128 	{ { 0 } },		/* memspace */
    129 	0,			/* maxtwins */
    130 };
    131 
    132 static const struct pcmcia_function pcmcia_3cxem556_func1 = {
    133 	1,			/* function number */
    134 	PCMCIA_FUNCTION_SERIAL,
    135 	0x27,			/* last cfe number */
    136 	0x900,			/* ccr_base */
    137 	0x63,			/* ccr_mask */
    138 };
    139 
    140 static const struct pcmcia_config_entry pcmcia_3cxem556_func1_cfe0 = {
    141 	0x27,			/* cfe number */
    142 	PCMCIA_CFE_IO8 | PCMCIA_CFE_IRQLEVEL,
    143 	PCMCIA_IFTYPE_IO,
    144 	1,			/* num_iospace */
    145 	3,			/* iomask */
    146 	{ { 0x0008, 0 } },	/* iospace */
    147 	0xffff,			/* irqmask */
    148 	0,			/* num_memspace */
    149 	{ { 0 } },		/* memspace */
    150 	0,			/* maxtwins */
    151 };
    152 
    153 static const struct pcmcia_function pcmcia_3ccfem556bi_func0 = {
    154 	0,			/* function number */
    155 	PCMCIA_FUNCTION_NETWORK,
    156 	0x07,			/* last cfe number */
    157 	0x1000,			/* ccr_base */
    158 	0x267,			/* ccr_mask */
    159 };
    160 
    161 static const struct pcmcia_config_entry pcmcia_3ccfem556bi_func0_cfe0 = {
    162 	0x07,			/* cfe number */
    163 	PCMCIA_CFE_IO8 | PCMCIA_CFE_IO16 | PCMCIA_CFE_IRQLEVEL,
    164 	PCMCIA_IFTYPE_IO,
    165 	1,			/* num_iospace */
    166 	5,			/* iomask */
    167 	{ { 0x0020, 0 } },	/* iospace */
    168 	0xffff,			/* irqmask */
    169 	0,			/* num_memspace */
    170 	{ { 0 } },		/* memspace */
    171 	0,			/* maxtwins */
    172 };
    173 
    174 static const struct pcmcia_function pcmcia_3ccfem556bi_func1 = {
    175 	1,			/* function number */
    176 	PCMCIA_FUNCTION_SERIAL,
    177 	0x27,			/* last cfe number */
    178 	0x1100,			/* ccr_base */
    179 	0x277,			/* ccr_mask */
    180 };
    181 
    182 static const struct pcmcia_config_entry pcmcia_3ccfem556bi_func1_cfe0 = {
    183 	0x27,			/* cfe number */
    184 	PCMCIA_CFE_IO8 | PCMCIA_CFE_IRQLEVEL,
    185 	PCMCIA_IFTYPE_IO,
    186 	1,			/* num_iospace */
    187 	3,			/* iomask */
    188 	{ { 0x0008, 0 } },	/* iospace */
    189 	0xffff,			/* irqmask */
    190 	0,			/* num_memspace */
    191 	{ { 0 } },		/* memspace */
    192 	0,			/* maxtwins */
    193 };
    194 
    195 static const struct pcmcia_function pcmcia_sveclancard_func0 = {
    196 	0,			/* function number */
    197 	PCMCIA_FUNCTION_NETWORK,
    198 	0x1,			/* last cfe number */
    199 	0x100,			/* ccr_base */
    200 	0x1,			/* ccr_mask */
    201 };
    202 
    203 static const struct pcmcia_config_entry pcmcia_sveclancard_func0_cfe0 = {
    204 	0x1,			/* cfe number */
    205 	PCMCIA_CFE_MWAIT_REQUIRED | PCMCIA_CFE_RDYBSY_ACTIVE |
    206 	PCMCIA_CFE_WP_ACTIVE | PCMCIA_CFE_BVD_ACTIVE | PCMCIA_CFE_IO16,
    207 	PCMCIA_IFTYPE_IO,
    208 	1,			/* num_iospace */
    209 	5,			/* iomask */
    210 	{ { 0x20, 0x300 } },	/* iospace */
    211 	0xdeb8,			/* irqmask */
    212 	0,			/* num_memspace */
    213 	{ { 0 } },		/* memspace */
    214 	0,			/* maxtwins */
    215 };
    216 
    217 static const struct pcmcia_function pcmcia_ndc_nd5100_func0 = {
    218 	0,			/* function number */
    219 	PCMCIA_FUNCTION_NETWORK,
    220 	0x23,			/* last cfe number */
    221 	0x3f8,			/* ccr_base */
    222 	0x3,			/* ccr_mask */
    223 };
    224 
    225 static const struct pcmcia_config_entry pcmcia_ndc_nd5100_func0_cfe0 = {
    226 	0x20,			/* cfe number */
    227 	PCMCIA_CFE_MWAIT_REQUIRED | PCMCIA_CFE_IO16 | PCMCIA_CFE_IRQLEVEL,
    228 	PCMCIA_IFTYPE_IO,
    229 	1,			/* num_iospace */
    230 	5,			/* iomask */
    231 	{ { 0x20, 0x300 } },	/* iospace */
    232 	0xdeb8,			/* irqmask */
    233 	0,			/* num_memspace */
    234 	{ { 0 } },		/* memspace */
    235 	0,			/* maxtwins */
    236 };
    237 
    238 static const struct pcmcia_function pcmcia_emtac_a2424i_func0 = {
    239 	0,			/* function number */
    240 	PCMCIA_FUNCTION_NETWORK,
    241 	0x21,			/* last cfe number */
    242 	0x3e0,			/* ccr_base */
    243 	0x1,			/* ccr_mask */
    244 };
    245 
    246 static const struct pcmcia_config_entry pcmcia_emtac_a2424i_func0_cfe0 = {
    247 	0x21,			/* cfe number */
    248 	PCMCIA_CFE_IO16 | PCMCIA_CFE_IRQLEVEL |
    249 	PCMCIA_CFE_IRQPULSE,
    250 	PCMCIA_IFTYPE_IO,
    251 	1,			/* num_iospace */
    252 	6,			/* iomask */
    253 	{ { 0x40, 0x100 } },	/* iospace */
    254 	0xffff,			/* irqmask */
    255 	0,			/* num_memspace */
    256 	{ { 0 } },		/* memspace */
    257 	0,			/* maxtwins */
    258 };
    259 
    260 static const struct pcmcia_cis_quirk pcmcia_cis_quirks[] = {
    261 	{ PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ECARD_1,
    262 	  PCMCIA_CIS_INVALID,
    263 	  &pcmcia_dlink_de650_func0, &pcmcia_dlink_de650_func0_cfe0 },
    264 	{ PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ECARD_1,
    265 	  PCMCIA_CIS_INVALID,
    266 	  &pcmcia_dlink_de650_func0, &pcmcia_dlink_de650_func0_cfe1 },
    267 	{ PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ECARD_1,
    268 	  PCMCIA_CIS_INVALID,
    269 	  &pcmcia_dlink_de650_func0, &pcmcia_dlink_de650_func0_cfe2 },
    270 	{ PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ECARD_1,
    271 	  PCMCIA_CIS_INVALID,
    272 	  &pcmcia_dlink_de650_func0, &pcmcia_dlink_de650_func0_cfe3 },
    273 	{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556, PCMCIA_CIS_INVALID,
    274 	  &pcmcia_3cxem556_func0, &pcmcia_3cxem556_func0_cfe0 },
    275 	{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556, PCMCIA_CIS_INVALID,
    276 	  &pcmcia_3cxem556_func1, &pcmcia_3cxem556_func1_cfe0 },
    277 	{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556INT, PCMCIA_CIS_INVALID,
    278 	  &pcmcia_3cxem556_func0, &pcmcia_3cxem556_func0_cfe0 },
    279 	{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556INT, PCMCIA_CIS_INVALID,
    280 	  &pcmcia_3cxem556_func1, &pcmcia_3cxem556_func1_cfe0 },
    281 	{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CCFEM556BI,
    282 	  PCMCIA_CIS_INVALID,
    283 	  &pcmcia_3ccfem556bi_func0, &pcmcia_3ccfem556bi_func0_cfe0 },
    284 	{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CCFEM556BI,
    285 	  PCMCIA_CIS_INVALID,
    286 	  &pcmcia_3ccfem556bi_func1, &pcmcia_3ccfem556bi_func1_cfe0 },
    287 	{ PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, PCMCIA_CIS_SVEC_LANCARD,
    288 	  &pcmcia_sveclancard_func0, &pcmcia_sveclancard_func0_cfe0 },
    289 	{ PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, PCMCIA_CIS_NDC_ND5100_E,
    290 	  &pcmcia_ndc_nd5100_func0, &pcmcia_ndc_nd5100_func0_cfe0 },
    291 	{ PCMCIA_VENDOR_EMTAC, PCMCIA_PRODUCT_EMTAC_WLAN, PCMCIA_CIS_INVALID,
    292 	  &pcmcia_emtac_a2424i_func0, &pcmcia_emtac_a2424i_func0_cfe0 },
    293 };
    294 
    295 static int n_pcmcia_cis_quirks =
    296 	sizeof(pcmcia_cis_quirks)/sizeof(pcmcia_cis_quirks[0]);
    297 
    298 void pcmcia_check_cis_quirks(sc)
    299 	struct pcmcia_softc *sc;
    300 {
    301 	int wiped = 0;
    302 	int i, j;
    303 	struct pcmcia_function *pf, *pf_next;
    304 	const struct pcmcia_function *pf_last;
    305 	struct pcmcia_config_entry *cfe, *cfe_next;
    306 
    307 	pf = NULL;
    308 	pf_last = NULL;
    309 
    310 	for (i=0; i<n_pcmcia_cis_quirks; i++) {
    311 		if ((sc->card.manufacturer == pcmcia_cis_quirks[i].manufacturer) &&
    312 			(sc->card.product == pcmcia_cis_quirks[i].product) &&
    313 			(((sc->card.manufacturer != PCMCIA_VENDOR_INVALID) &&
    314 			  (sc->card.product != PCMCIA_PRODUCT_INVALID)) ||
    315 			 ((sc->card.manufacturer == PCMCIA_VENDOR_INVALID) &&
    316 			  (sc->card.product == PCMCIA_PRODUCT_INVALID) &&
    317 			  sc->card.cis1_info[0] &&
    318 			  (strcmp(sc->card.cis1_info[0],
    319 					  pcmcia_cis_quirks[i].cis1_info[0]) == 0) &&
    320 			  sc->card.cis1_info[1] &&
    321 			  (strcmp(sc->card.cis1_info[1],
    322 					  pcmcia_cis_quirks[i].cis1_info[1]) == 0)))) {
    323 			if (!wiped) {
    324 				if (pcmcia_verbose) {
    325 					printf("%s: using CIS quirks for ", sc->dev.dv_xname);
    326 					for (j = 0; j < 4; j++) {
    327 						if (sc->card.cis1_info[j] == NULL)
    328 							break;
    329 						if (j)
    330 							printf(", ");
    331 						printf("%s", sc->card.cis1_info[j]);
    332 					}
    333 					printf("\n");
    334 				}
    335 
    336 				for (pf = SIMPLEQ_FIRST(&sc->card.pf_head); pf != NULL;
    337 				     pf = pf_next) {
    338 					for (cfe = SIMPLEQ_FIRST(&pf->cfe_head); cfe != NULL;
    339 					     cfe = cfe_next) {
    340 						cfe_next = SIMPLEQ_NEXT(cfe, cfe_list);
    341 						free(cfe, M_DEVBUF);
    342 					}
    343 					pf_next = SIMPLEQ_NEXT(pf, pf_list);
    344 					free(pf, M_DEVBUF);
    345 				}
    346 
    347 				SIMPLEQ_INIT(&sc->card.pf_head);
    348 				wiped = 1;
    349 			}
    350 
    351 			if (pf_last == pcmcia_cis_quirks[i].pf) {
    352 				cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT);
    353 				*cfe = *pcmcia_cis_quirks[i].cfe;
    354 
    355 				SIMPLEQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list);
    356 			} else {
    357 				pf = malloc(sizeof(*pf), M_DEVBUF, M_NOWAIT);
    358 				*pf = *pcmcia_cis_quirks[i].pf;
    359 				SIMPLEQ_INIT(&pf->cfe_head);
    360 
    361 				cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT);
    362 				*cfe = *pcmcia_cis_quirks[i].cfe;
    363 
    364 				SIMPLEQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list);
    365 				SIMPLEQ_INSERT_TAIL(&sc->card.pf_head, pf, pf_list);
    366 
    367 				pf_last = pcmcia_cis_quirks[i].pf;
    368 			}
    369 		}
    370 	}
    371 }
    372