Home | History | Annotate | Line # | Download | only in pcmcia
pcmcia_cis_quirks.c revision 1.17
      1 /*	$NetBSD: pcmcia_cis_quirks.c,v 1.17 2001/12/23 09:25:19 ichiro 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.17 2001/12/23 09:25:19 ichiro 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 | PCMCIA_CFE_IRQPULSE,
    249 	PCMCIA_IFTYPE_IO,
    250 	1,			/* num_iospace */
    251 	6,			/* iomask */
    252 	{ { 0x40, 0x100 } },	/* iospace */
    253 	0xffff,			/* irqmask */
    254 	0,			/* num_memspace */
    255 	{ { 0 } },		/* memspace */
    256 	0,			/* maxtwins */
    257 };
    258 
    259 static const struct pcmcia_function pcmcia_fujitsu_j181_func0 = {
    260 	0,			/* function number */
    261 	PCMCIA_FUNCTION_NETWORK,
    262 	0x21,			/* last cfe number */
    263 	0xfe0,			/* ccr_base */
    264 	0xf,			/* ccr_mask */
    265 };
    266 
    267 static const struct pcmcia_config_entry pcmcia_fujitsu_j181_func0_cfe0 = {
    268 	0xc,			/* cfe number */
    269 	PCMCIA_CFE_MWAIT_REQUIRED | PCMCIA_CFE_WP_ACTIVE | PCMCIA_CFE_IO8 |
    270 	PCMCIA_CFE_IO16 | PCMCIA_CFE_IRQLEVEL | PCMCIA_CFE_IRQPULSE,
    271 	PCMCIA_IFTYPE_IO,
    272 	1,			/* num_iospace */
    273 	10,			/* iomask */
    274 	{ { 0x20, 0x140 } },	/* iospace */
    275 	0xffff,			/* irqmask */
    276 	0,			/* num_memspace */
    277 	{ { 0 } },		/* memspace */
    278 	0,			/* maxtwins */
    279 };
    280 
    281 static const struct pcmcia_cis_quirk pcmcia_cis_quirks[] = {
    282 	{ PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ECARD_1,
    283 	  PCMCIA_CIS_INVALID,
    284 	  &pcmcia_dlink_de650_func0, &pcmcia_dlink_de650_func0_cfe0 },
    285 	{ PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ECARD_1,
    286 	  PCMCIA_CIS_INVALID,
    287 	  &pcmcia_dlink_de650_func0, &pcmcia_dlink_de650_func0_cfe1 },
    288 	{ PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ECARD_1,
    289 	  PCMCIA_CIS_INVALID,
    290 	  &pcmcia_dlink_de650_func0, &pcmcia_dlink_de650_func0_cfe2 },
    291 	{ PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ECARD_1,
    292 	  PCMCIA_CIS_INVALID,
    293 	  &pcmcia_dlink_de650_func0, &pcmcia_dlink_de650_func0_cfe3 },
    294 	{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556, PCMCIA_CIS_INVALID,
    295 	  &pcmcia_3cxem556_func0, &pcmcia_3cxem556_func0_cfe0 },
    296 	{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556, PCMCIA_CIS_INVALID,
    297 	  &pcmcia_3cxem556_func1, &pcmcia_3cxem556_func1_cfe0 },
    298 	{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556INT, PCMCIA_CIS_INVALID,
    299 	  &pcmcia_3cxem556_func0, &pcmcia_3cxem556_func0_cfe0 },
    300 	{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556INT, PCMCIA_CIS_INVALID,
    301 	  &pcmcia_3cxem556_func1, &pcmcia_3cxem556_func1_cfe0 },
    302 	{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CCFEM556BI,
    303 	  PCMCIA_CIS_INVALID,
    304 	  &pcmcia_3ccfem556bi_func0, &pcmcia_3ccfem556bi_func0_cfe0 },
    305 	{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CCFEM556BI,
    306 	  PCMCIA_CIS_INVALID,
    307 	  &pcmcia_3ccfem556bi_func1, &pcmcia_3ccfem556bi_func1_cfe0 },
    308 	{ PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, PCMCIA_CIS_SVEC_LANCARD,
    309 	  &pcmcia_sveclancard_func0, &pcmcia_sveclancard_func0_cfe0 },
    310 	{ PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, PCMCIA_CIS_NDC_ND5100_E,
    311 	  &pcmcia_ndc_nd5100_func0, &pcmcia_ndc_nd5100_func0_cfe0 },
    312 	{ PCMCIA_VENDOR_EMTAC, PCMCIA_PRODUCT_EMTAC_WLAN, PCMCIA_CIS_INVALID,
    313 	  &pcmcia_emtac_a2424i_func0, &pcmcia_emtac_a2424i_func0_cfe0 },
    314 	{ PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
    315 	  PCMCIA_CIS_FUJITSU_FMV_J181,
    316 	  &pcmcia_fujitsu_j181_func0, &pcmcia_fujitsu_j181_func0_cfe0 },
    317 };
    318 
    319 static int n_pcmcia_cis_quirks =
    320 	sizeof(pcmcia_cis_quirks)/sizeof(pcmcia_cis_quirks[0]);
    321 
    322 void pcmcia_check_cis_quirks(sc)
    323 	struct pcmcia_softc *sc;
    324 {
    325 	int wiped = 0;
    326 	int i, j;
    327 	struct pcmcia_function *pf, *pf_next;
    328 	const struct pcmcia_function *pf_last;
    329 	struct pcmcia_config_entry *cfe, *cfe_next;
    330 
    331 	pf = NULL;
    332 	pf_last = NULL;
    333 
    334 	for (i=0; i<n_pcmcia_cis_quirks; i++) {
    335 		if ((sc->card.manufacturer == pcmcia_cis_quirks[i].manufacturer) &&
    336 			(sc->card.product == pcmcia_cis_quirks[i].product) &&
    337 			(((sc->card.manufacturer != PCMCIA_VENDOR_INVALID) &&
    338 			  (sc->card.product != PCMCIA_PRODUCT_INVALID)) ||
    339 			 ((sc->card.manufacturer == PCMCIA_VENDOR_INVALID) &&
    340 			  (sc->card.product == PCMCIA_PRODUCT_INVALID) &&
    341 			  sc->card.cis1_info[0] &&
    342 			  (strcmp(sc->card.cis1_info[0],
    343 					  pcmcia_cis_quirks[i].cis1_info[0]) == 0) &&
    344 			  sc->card.cis1_info[1] &&
    345 			  (strcmp(sc->card.cis1_info[1],
    346 					  pcmcia_cis_quirks[i].cis1_info[1]) == 0)))) {
    347 			if (!wiped) {
    348 				if (pcmcia_verbose) {
    349 					printf("%s: using CIS quirks for ", sc->dev.dv_xname);
    350 					for (j = 0; j < 4; j++) {
    351 						if (sc->card.cis1_info[j] == NULL)
    352 							break;
    353 						if (j)
    354 							printf(", ");
    355 						printf("%s", sc->card.cis1_info[j]);
    356 					}
    357 					printf("\n");
    358 				}
    359 
    360 				for (pf = SIMPLEQ_FIRST(&sc->card.pf_head); pf != NULL;
    361 				     pf = pf_next) {
    362 					for (cfe = SIMPLEQ_FIRST(&pf->cfe_head); cfe != NULL;
    363 					     cfe = cfe_next) {
    364 						cfe_next = SIMPLEQ_NEXT(cfe, cfe_list);
    365 						free(cfe, M_DEVBUF);
    366 					}
    367 					pf_next = SIMPLEQ_NEXT(pf, pf_list);
    368 					free(pf, M_DEVBUF);
    369 				}
    370 
    371 				SIMPLEQ_INIT(&sc->card.pf_head);
    372 				wiped = 1;
    373 			}
    374 
    375 			if (pf_last == pcmcia_cis_quirks[i].pf) {
    376 				cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT);
    377 				*cfe = *pcmcia_cis_quirks[i].cfe;
    378 
    379 				SIMPLEQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list);
    380 			} else {
    381 				pf = malloc(sizeof(*pf), M_DEVBUF, M_NOWAIT);
    382 				*pf = *pcmcia_cis_quirks[i].pf;
    383 				SIMPLEQ_INIT(&pf->cfe_head);
    384 
    385 				cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT);
    386 				*cfe = *pcmcia_cis_quirks[i].cfe;
    387 
    388 				SIMPLEQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list);
    389 				SIMPLEQ_INSERT_TAIL(&sc->card.pf_head, pf, pf_list);
    390 
    391 				pf_last = pcmcia_cis_quirks[i].pf;
    392 			}
    393 		}
    394 	}
    395 }
    396