Home | History | Annotate | Line # | Download | only in pcmcia
pcmcia_cis_quirks.c revision 1.12
      1 /*	$NetBSD: pcmcia_cis_quirks.c,v 1.12 2001/06/27 16:03:01 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/types.h>
     33 #include <sys/param.h>
     34 #include <sys/systm.h>
     35 #include <sys/device.h>
     36 #include <sys/mbuf.h>
     37 
     38 #include <dev/pcmcia/pcmciadevs.h>
     39 #include <dev/pcmcia/pcmciareg.h>
     40 #include <dev/pcmcia/pcmciachip.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 static const struct pcmcia_function pcmcia_dlink_de650_func0 = {
     50 	0,
     51 	PCMCIA_FUNCTION_NETWORK,
     52 	0x23,
     53 	0x400,
     54 	0x0b,
     55 };
     56 
     57 static const struct pcmcia_config_entry pcmcia_dlink_de650_func0_cfe0 = {
     58 	0x20,
     59 	PCMCIA_CFE_IO16 | PCMCIA_CFE_IRQLEVEL,
     60 	PCMCIA_IFTYPE_IO,
     61 	1,
     62 	5,
     63 	{ { 0x20, 0x360 } },
     64 	0xbe7c,
     65 	0,
     66 	{ { 0 } },
     67 	0,
     68 };
     69 
     70 static const struct pcmcia_config_entry pcmcia_dlink_de650_func0_cfe1 = {
     71 	0x21,
     72 	PCMCIA_CFE_IO16 | PCMCIA_CFE_IRQLEVEL,
     73 	PCMCIA_IFTYPE_IO,
     74 	1,
     75 	5,
     76 	{ { 0x20, 0x340 } },
     77 	0xbe7c,
     78 	0,
     79 	{ { 0 } },
     80 	0,
     81 };
     82 
     83 static const struct pcmcia_config_entry pcmcia_dlink_de650_func0_cfe2 = {
     84 	0x22,
     85 	PCMCIA_CFE_IO16 | PCMCIA_CFE_IRQLEVEL,
     86 	PCMCIA_IFTYPE_IO,
     87 	1,
     88 	5,
     89 	{ { 0x20, 0x320 } },
     90 	0xbe7c,
     91 	0,
     92 	{ { 0 } },
     93 	0,
     94 };
     95 
     96 static const struct pcmcia_config_entry pcmcia_dlink_de650_func0_cfe3 = {
     97 	0x23,
     98 	PCMCIA_CFE_IO16 | PCMCIA_CFE_IRQLEVEL,
     99 	PCMCIA_IFTYPE_IO,
    100 	1,
    101 	5,
    102 	{ { 0x20, 0x300 } },
    103 	0xbe7c,
    104 	0,
    105 	{ { 0 } },
    106 	0,
    107 };
    108 
    109 static const struct pcmcia_function pcmcia_3cxem556_func0 = {
    110 	0,			/* function number */
    111 	PCMCIA_FUNCTION_NETWORK,
    112 	0x07,			/* last cfe number */
    113 	0x800,			/* ccr_base */
    114 	0x63,			/* ccr_mask */
    115 };
    116 
    117 static const struct pcmcia_config_entry pcmcia_3cxem556_func0_cfe0 = {
    118 	0x07,			/* cfe number */
    119 	PCMCIA_CFE_IO8 | PCMCIA_CFE_IO16 | PCMCIA_CFE_IRQLEVEL,
    120 	PCMCIA_IFTYPE_IO,
    121 	1,			/* num_iospace */
    122 	4,			/* iomask */
    123 	{ { 0x0010, 0 } },	/* iospace */
    124 	0xffff,			/* irqmask */
    125 	0,			/* num_memspace */
    126 	{ { 0 } },		/* memspace */
    127 	0,			/* maxtwins */
    128 };
    129 
    130 static const struct pcmcia_function pcmcia_3cxem556_func1 = {
    131 	1,			/* function number */
    132 	PCMCIA_FUNCTION_SERIAL,
    133 	0x27,			/* last cfe number */
    134 	0x900,			/* ccr_base */
    135 	0x63,			/* ccr_mask */
    136 };
    137 
    138 static const struct pcmcia_config_entry pcmcia_3cxem556_func1_cfe0 = {
    139 	0x27,			/* cfe number */
    140 	PCMCIA_CFE_IO8 | PCMCIA_CFE_IRQLEVEL,
    141 	PCMCIA_IFTYPE_IO,
    142 	1,			/* num_iospace */
    143 	3,			/* iomask */
    144 	{ { 0x0008, 0 } },	/* iospace */
    145 	0xffff,			/* irqmask */
    146 	0,			/* num_memspace */
    147 	{ { 0 } },		/* memspace */
    148 	0,			/* maxtwins */
    149 };
    150 
    151 static const struct pcmcia_function pcmcia_3ccfem556bi_func0 = {
    152 	0,			/* function number */
    153 	PCMCIA_FUNCTION_NETWORK,
    154 	0x07,			/* last cfe number */
    155 	0x1000,			/* ccr_base */
    156 	0x267,			/* ccr_mask */
    157 };
    158 
    159 static const struct pcmcia_config_entry pcmcia_3ccfem556bi_func0_cfe0 = {
    160 	0x07,			/* cfe number */
    161 	PCMCIA_CFE_IO8 | PCMCIA_CFE_IO16 | PCMCIA_CFE_IRQLEVEL,
    162 	PCMCIA_IFTYPE_IO,
    163 	1,			/* num_iospace */
    164 	5,			/* iomask */
    165 	{ { 0x0020, 0 } },	/* iospace */
    166 	0xffff,			/* irqmask */
    167 	0,			/* num_memspace */
    168 	{ { 0 } },		/* memspace */
    169 	0,			/* maxtwins */
    170 };
    171 
    172 static const struct pcmcia_function pcmcia_3ccfem556bi_func1 = {
    173 	1,			/* function number */
    174 	PCMCIA_FUNCTION_SERIAL,
    175 	0x27,			/* last cfe number */
    176 	0x1100,			/* ccr_base */
    177 	0x277,			/* ccr_mask */
    178 };
    179 
    180 static const struct pcmcia_config_entry pcmcia_3ccfem556bi_func1_cfe0 = {
    181 	0x27,			/* cfe number */
    182 	PCMCIA_CFE_IO8 | PCMCIA_CFE_IRQLEVEL,
    183 	PCMCIA_IFTYPE_IO,
    184 	1,			/* num_iospace */
    185 	3,			/* iomask */
    186 	{ { 0x0008, 0 } },	/* iospace */
    187 	0xffff,			/* irqmask */
    188 	0,			/* num_memspace */
    189 	{ { 0 } },		/* memspace */
    190 	0,			/* maxtwins */
    191 };
    192 
    193 static const struct pcmcia_function pcmcia_sveclancard_func0 = {
    194 	0,			/* function number */
    195 	PCMCIA_FUNCTION_NETWORK,
    196 	0x1,			/* last cfe number */
    197 	0x100,			/* ccr_base */
    198 	0x1,			/* ccr_mask */
    199 };
    200 
    201 static const struct pcmcia_config_entry pcmcia_sveclancard_func0_cfe0 = {
    202 	0x1,			/* cfe number */
    203 	PCMCIA_CFE_MWAIT_REQUIRED | PCMCIA_CFE_RDYBSY_ACTIVE |
    204 	PCMCIA_CFE_WP_ACTIVE | PCMCIA_CFE_BVD_ACTIVE | PCMCIA_CFE_IO16,
    205 	PCMCIA_IFTYPE_IO,
    206 	1,			/* num_iospace */
    207 	5,			/* iomask */
    208 	{ { 0x20, 0x300 } },	/* iospace */
    209 	0xdeb8,			/* irqmask */
    210 	0,			/* num_memspace */
    211 	{ { 0 } },		/* memspace */
    212 	0,			/* maxtwins */
    213 };
    214 
    215 static const struct pcmcia_function pcmcia_ndc_nd5100_func0 = {
    216 	0,			/* function number */
    217 	PCMCIA_FUNCTION_NETWORK,
    218 	0x23,			/* last cfe number */
    219 	0x3f8,			/* ccr_base */
    220 	0x3,			/* ccr_mask */
    221 };
    222 
    223 static const struct pcmcia_config_entry pcmcia_ndc_nd5100_func0_cfe0 = {
    224 	0x20,			/* cfe number */
    225 	PCMCIA_CFE_MWAIT_REQUIRED | PCMCIA_CFE_IO16 | PCMCIA_CFE_IRQLEVEL,
    226 	PCMCIA_IFTYPE_IO,
    227 	1,			/* num_iospace */
    228 	5,			/* iomask */
    229 	{ { 0x20, 0x300 } },	/* iospace */
    230 	0xdeb8,			/* irqmask */
    231 	0,			/* num_memspace */
    232 	{ { 0 } },		/* memspace */
    233 	0,			/* maxtwins */
    234 };
    235 
    236 static const struct pcmcia_function pcmcia_emtac_a2424i_func0 = {
    237 	0,			/* function number */
    238 	PCMCIA_FUNCTION_NETWORK,
    239 	0x21,			/* last cfe number */
    240 	0x3e0,			/* ccr_base */
    241 	0x1,			/* ccr_mask */
    242 };
    243 
    244 static const struct pcmcia_config_entry pcmcia_emtac_a2424i_func0_cfe0 = {
    245 	0x21,			/* cfe number */
    246 	PCMCIA_CFE_IO16 | PCMCIA_CFE_IRQLEVEL |
    247 	PCMCIA_CFE_IRQPULSE,
    248 	PCMCIA_IFTYPE_IO,
    249 	1,			/* num_iospace */
    250 	6,			/* iomask */
    251 	{ { 0x40, 0x100 } },	/* iospace */
    252 	0xffff,			/* irqmask */
    253 	0,			/* num_memspace */
    254 	{ { 0 } },		/* memspace */
    255 	0,			/* maxtwins */
    256 };
    257 
    258 static const struct pcmcia_cis_quirk pcmcia_cis_quirks[] = {
    259 	{ PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ECARD_1,
    260 	  PCMCIA_CIS_INVALID,
    261 	  &pcmcia_dlink_de650_func0, &pcmcia_dlink_de650_func0_cfe0 },
    262 	{ PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ECARD_1,
    263 	  PCMCIA_CIS_INVALID,
    264 	  &pcmcia_dlink_de650_func0, &pcmcia_dlink_de650_func0_cfe1 },
    265 	{ PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ECARD_1,
    266 	  PCMCIA_CIS_INVALID,
    267 	  &pcmcia_dlink_de650_func0, &pcmcia_dlink_de650_func0_cfe2 },
    268 	{ PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ECARD_1,
    269 	  PCMCIA_CIS_INVALID,
    270 	  &pcmcia_dlink_de650_func0, &pcmcia_dlink_de650_func0_cfe3 },
    271 	{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556, PCMCIA_CIS_INVALID,
    272 	  &pcmcia_3cxem556_func0, &pcmcia_3cxem556_func0_cfe0 },
    273 	{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556, PCMCIA_CIS_INVALID,
    274 	  &pcmcia_3cxem556_func1, &pcmcia_3cxem556_func1_cfe0 },
    275 	{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556INT, PCMCIA_CIS_INVALID,
    276 	  &pcmcia_3cxem556_func0, &pcmcia_3cxem556_func0_cfe0 },
    277 	{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556INT, PCMCIA_CIS_INVALID,
    278 	  &pcmcia_3cxem556_func1, &pcmcia_3cxem556_func1_cfe0 },
    279 	{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CCFEM556BI,
    280 	  PCMCIA_CIS_INVALID,
    281 	  &pcmcia_3ccfem556bi_func0, &pcmcia_3ccfem556bi_func0_cfe0 },
    282 	{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CCFEM556BI,
    283 	  PCMCIA_CIS_INVALID,
    284 	  &pcmcia_3ccfem556bi_func1, &pcmcia_3ccfem556bi_func1_cfe0 },
    285 	{ PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, PCMCIA_CIS_SVEC_LANCARD,
    286 	  &pcmcia_sveclancard_func0, &pcmcia_sveclancard_func0_cfe0 },
    287 	{ PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, PCMCIA_CIS_NDC_ND5100_E,
    288 	  &pcmcia_ndc_nd5100_func0, &pcmcia_ndc_nd5100_func0_cfe0 },
    289 	{ PCMCIA_VENDOR_EMTAC, PCMCIA_PRODUCT_EMTAC_WLAN, PCMCIA_CIS_INVALID,
    290 	  &pcmcia_emtac_a2424i_func0, &pcmcia_emtac_a2424i_func0_cfe0 },
    291 };
    292 
    293 static int n_pcmcia_cis_quirks =
    294 	sizeof(pcmcia_cis_quirks)/sizeof(pcmcia_cis_quirks[0]);
    295 
    296 void pcmcia_check_cis_quirks(sc)
    297 	struct pcmcia_softc *sc;
    298 {
    299 	int wiped = 0;
    300 	int i, j;
    301 	struct pcmcia_function *pf, *pf_next;
    302 	const struct pcmcia_function *pf_last;
    303 	struct pcmcia_config_entry *cfe, *cfe_next;
    304 
    305 	pf = NULL;
    306 	pf_last = NULL;
    307 
    308 	for (i=0; i<n_pcmcia_cis_quirks; i++) {
    309 		if ((sc->card.manufacturer == pcmcia_cis_quirks[i].manufacturer) &&
    310 			(sc->card.product == pcmcia_cis_quirks[i].product) &&
    311 			(((sc->card.manufacturer != PCMCIA_VENDOR_INVALID) &&
    312 			  (sc->card.product != PCMCIA_PRODUCT_INVALID)) ||
    313 			 ((sc->card.manufacturer == PCMCIA_VENDOR_INVALID) &&
    314 			  (sc->card.product == PCMCIA_PRODUCT_INVALID) &&
    315 			  sc->card.cis1_info[0] &&
    316 			  (strcmp(sc->card.cis1_info[0],
    317 					  pcmcia_cis_quirks[i].cis1_info[0]) == 0) &&
    318 			  sc->card.cis1_info[1] &&
    319 			  (strcmp(sc->card.cis1_info[1],
    320 					  pcmcia_cis_quirks[i].cis1_info[1]) == 0)))) {
    321 			if (!wiped) {
    322 				if (pcmcia_verbose) {
    323 					printf("%s: using CIS quirks for ", sc->dev.dv_xname);
    324 					for (j = 0; j < 4; j++) {
    325 						if (sc->card.cis1_info[j] == NULL)
    326 							break;
    327 						if (j)
    328 							printf(", ");
    329 						printf("%s", sc->card.cis1_info[j]);
    330 					}
    331 					printf("\n");
    332 				}
    333 
    334 				for (pf = SIMPLEQ_FIRST(&sc->card.pf_head); pf != NULL;
    335 				     pf = pf_next) {
    336 					for (cfe = SIMPLEQ_FIRST(&pf->cfe_head); cfe != NULL;
    337 					     cfe = cfe_next) {
    338 						cfe_next = SIMPLEQ_NEXT(cfe, cfe_list);
    339 						free(cfe, M_DEVBUF);
    340 					}
    341 					pf_next = SIMPLEQ_NEXT(pf, pf_list);
    342 					free(pf, M_DEVBUF);
    343 				}
    344 
    345 				SIMPLEQ_INIT(&sc->card.pf_head);
    346 				wiped = 1;
    347 			}
    348 
    349 			if (pf_last == pcmcia_cis_quirks[i].pf) {
    350 				cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT);
    351 				*cfe = *pcmcia_cis_quirks[i].cfe;
    352 
    353 				SIMPLEQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list);
    354 			} else {
    355 				pf = malloc(sizeof(*pf), M_DEVBUF, M_NOWAIT);
    356 				*pf = *pcmcia_cis_quirks[i].pf;
    357 				SIMPLEQ_INIT(&pf->cfe_head);
    358 
    359 				cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT);
    360 				*cfe = *pcmcia_cis_quirks[i].cfe;
    361 
    362 				SIMPLEQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list);
    363 				SIMPLEQ_INSERT_TAIL(&sc->card.pf_head, pf, pf_list);
    364 
    365 				pf_last = pcmcia_cis_quirks[i].pf;
    366 			}
    367 		}
    368 	}
    369 }
    370