Home | History | Annotate | Line # | Download | only in pcmcia
pcmcia_cis_quirks.c revision 1.11
      1 /*	$NetBSD: pcmcia_cis_quirks.c,v 1.11 2001/05/16 06:29:01 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/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_cis_quirk pcmcia_cis_quirks[] = {
    237 	{ PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ECARD_1,
    238 	  PCMCIA_CIS_INVALID,
    239 	  &pcmcia_dlink_de650_func0, &pcmcia_dlink_de650_func0_cfe0 },
    240 	{ PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ECARD_1,
    241 	  PCMCIA_CIS_INVALID,
    242 	  &pcmcia_dlink_de650_func0, &pcmcia_dlink_de650_func0_cfe1 },
    243 	{ PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ECARD_1,
    244 	  PCMCIA_CIS_INVALID,
    245 	  &pcmcia_dlink_de650_func0, &pcmcia_dlink_de650_func0_cfe2 },
    246 	{ PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ECARD_1,
    247 	  PCMCIA_CIS_INVALID,
    248 	  &pcmcia_dlink_de650_func0, &pcmcia_dlink_de650_func0_cfe3 },
    249 	{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556, PCMCIA_CIS_INVALID,
    250 	  &pcmcia_3cxem556_func0, &pcmcia_3cxem556_func0_cfe0 },
    251 	{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556, PCMCIA_CIS_INVALID,
    252 	  &pcmcia_3cxem556_func1, &pcmcia_3cxem556_func1_cfe0 },
    253 	{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556INT, PCMCIA_CIS_INVALID,
    254 	  &pcmcia_3cxem556_func0, &pcmcia_3cxem556_func0_cfe0 },
    255 	{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556INT, PCMCIA_CIS_INVALID,
    256 	  &pcmcia_3cxem556_func1, &pcmcia_3cxem556_func1_cfe0 },
    257 	{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CCFEM556BI,
    258 	  PCMCIA_CIS_INVALID,
    259 	  &pcmcia_3ccfem556bi_func0, &pcmcia_3ccfem556bi_func0_cfe0 },
    260 	{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CCFEM556BI,
    261 	  PCMCIA_CIS_INVALID,
    262 	  &pcmcia_3ccfem556bi_func1, &pcmcia_3ccfem556bi_func1_cfe0 },
    263 	{ PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, PCMCIA_CIS_SVEC_LANCARD,
    264 	  &pcmcia_sveclancard_func0, &pcmcia_sveclancard_func0_cfe0 },
    265 	{ PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, PCMCIA_CIS_NDC_ND5100_E,
    266 	  &pcmcia_ndc_nd5100_func0, &pcmcia_ndc_nd5100_func0_cfe0 },
    267 };
    268 
    269 static int n_pcmcia_cis_quirks =
    270 	sizeof(pcmcia_cis_quirks)/sizeof(pcmcia_cis_quirks[0]);
    271 
    272 void pcmcia_check_cis_quirks(sc)
    273 	struct pcmcia_softc *sc;
    274 {
    275 	int wiped = 0;
    276 	int i, j;
    277 	struct pcmcia_function *pf, *pf_next;
    278 	const struct pcmcia_function *pf_last;
    279 	struct pcmcia_config_entry *cfe, *cfe_next;
    280 
    281 	pf = NULL;
    282 	pf_last = NULL;
    283 
    284 	for (i=0; i<n_pcmcia_cis_quirks; i++) {
    285 		if ((sc->card.manufacturer == pcmcia_cis_quirks[i].manufacturer) &&
    286 			(sc->card.product == pcmcia_cis_quirks[i].product) &&
    287 			(((sc->card.manufacturer != PCMCIA_VENDOR_INVALID) &&
    288 			  (sc->card.product != PCMCIA_PRODUCT_INVALID)) ||
    289 			 ((sc->card.manufacturer == PCMCIA_VENDOR_INVALID) &&
    290 			  (sc->card.product == PCMCIA_PRODUCT_INVALID) &&
    291 			  sc->card.cis1_info[0] &&
    292 			  (strcmp(sc->card.cis1_info[0],
    293 					  pcmcia_cis_quirks[i].cis1_info[0]) == 0) &&
    294 			  sc->card.cis1_info[1] &&
    295 			  (strcmp(sc->card.cis1_info[1],
    296 					  pcmcia_cis_quirks[i].cis1_info[1]) == 0)))) {
    297 			if (!wiped) {
    298 				if (pcmcia_verbose) {
    299 					printf("%s: using CIS quirks for ", sc->dev.dv_xname);
    300 					for (j = 0; j < 4; j++) {
    301 						if (sc->card.cis1_info[j] == NULL)
    302 							break;
    303 						if (j)
    304 							printf(", ");
    305 						printf("%s", sc->card.cis1_info[j]);
    306 					}
    307 					printf("\n");
    308 				}
    309 
    310 				for (pf = SIMPLEQ_FIRST(&sc->card.pf_head); pf != NULL;
    311 				     pf = pf_next) {
    312 					for (cfe = SIMPLEQ_FIRST(&pf->cfe_head); cfe != NULL;
    313 					     cfe = cfe_next) {
    314 						cfe_next = SIMPLEQ_NEXT(cfe, cfe_list);
    315 						free(cfe, M_DEVBUF);
    316 					}
    317 					pf_next = SIMPLEQ_NEXT(pf, pf_list);
    318 					free(pf, M_DEVBUF);
    319 				}
    320 
    321 				SIMPLEQ_INIT(&sc->card.pf_head);
    322 				wiped = 1;
    323 			}
    324 
    325 			if (pf_last == pcmcia_cis_quirks[i].pf) {
    326 				cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT);
    327 				*cfe = *pcmcia_cis_quirks[i].cfe;
    328 
    329 				SIMPLEQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list);
    330 			} else {
    331 				pf = malloc(sizeof(*pf), M_DEVBUF, M_NOWAIT);
    332 				*pf = *pcmcia_cis_quirks[i].pf;
    333 				SIMPLEQ_INIT(&pf->cfe_head);
    334 
    335 				cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT);
    336 				*cfe = *pcmcia_cis_quirks[i].cfe;
    337 
    338 				SIMPLEQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list);
    339 				SIMPLEQ_INSERT_TAIL(&sc->card.pf_head, pf, pf_list);
    340 
    341 				pf_last = pcmcia_cis_quirks[i].pf;
    342 			}
    343 		}
    344 	}
    345 }
    346