pcmcia_cis_quirks.c revision 1.8 1 /* $NetBSD: pcmcia_cis_quirks.c,v 1.8 2001/01/18 20:28:26 jdolecek Exp $ */
2
3 #define PCMCIADEBUG
4
5 /*
6 * Copyright (c) 1998 Marc Horowitz. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Marc Horowitz.
19 * 4. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #include <sys/types.h>
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 { },
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 { },
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 { },
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 { },
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 { }, /* 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 { }, /* 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 { }, /* 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 { }, /* 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 { }, /* 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 { }, /* memspace */
235 0, /* maxtwins */
236 };
237
238 static const struct pcmcia_cis_quirk pcmcia_cis_quirks[] = {
239 { PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ECARD_1,
240 PCMCIA_CIS_INVALID,
241 &pcmcia_dlink_de650_func0, &pcmcia_dlink_de650_func0_cfe0 },
242 { PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ECARD_1,
243 PCMCIA_CIS_INVALID,
244 &pcmcia_dlink_de650_func0, &pcmcia_dlink_de650_func0_cfe1 },
245 { PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ECARD_1,
246 PCMCIA_CIS_INVALID,
247 &pcmcia_dlink_de650_func0, &pcmcia_dlink_de650_func0_cfe2 },
248 { PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ECARD_1,
249 PCMCIA_CIS_INVALID,
250 &pcmcia_dlink_de650_func0, &pcmcia_dlink_de650_func0_cfe3 },
251 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556, PCMCIA_CIS_INVALID,
252 &pcmcia_3cxem556_func0, &pcmcia_3cxem556_func0_cfe0 },
253 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556, PCMCIA_CIS_INVALID,
254 &pcmcia_3cxem556_func1, &pcmcia_3cxem556_func1_cfe0 },
255 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556INT, PCMCIA_CIS_INVALID,
256 &pcmcia_3cxem556_func0, &pcmcia_3cxem556_func0_cfe0 },
257 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556INT, PCMCIA_CIS_INVALID,
258 &pcmcia_3cxem556_func1, &pcmcia_3cxem556_func1_cfe0 },
259 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CCFEM556BI,
260 PCMCIA_CIS_INVALID,
261 &pcmcia_3ccfem556bi_func0, &pcmcia_3ccfem556bi_func0_cfe0 },
262 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CCFEM556BI,
263 PCMCIA_CIS_INVALID,
264 &pcmcia_3ccfem556bi_func1, &pcmcia_3ccfem556bi_func1_cfe0 },
265 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, PCMCIA_CIS_SVEC_LANCARD,
266 &pcmcia_sveclancard_func0, &pcmcia_sveclancard_func0_cfe0 },
267 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, PCMCIA_CIS_NDC_ND5100_E,
268 &pcmcia_ndc_nd5100_func0, &pcmcia_ndc_nd5100_func0_cfe0 },
269 };
270
271 static int n_pcmcia_cis_quirks =
272 sizeof(pcmcia_cis_quirks)/sizeof(pcmcia_cis_quirks[0]);
273
274 void pcmcia_check_cis_quirks(sc)
275 struct pcmcia_softc *sc;
276 {
277 int wiped = 0;
278 int i, j;
279 struct pcmcia_function *pf, *pf_next;
280 const struct pcmcia_function *pf_last;
281 struct pcmcia_config_entry *cfe, *cfe_next;
282
283 pf = NULL;
284 pf_last = NULL;
285
286 for (i=0; i<n_pcmcia_cis_quirks; i++) {
287 if ((sc->card.manufacturer == pcmcia_cis_quirks[i].manufacturer) &&
288 (sc->card.product == pcmcia_cis_quirks[i].product) &&
289 (((sc->card.manufacturer != PCMCIA_VENDOR_INVALID) &&
290 (sc->card.product != PCMCIA_PRODUCT_INVALID)) ||
291 ((sc->card.manufacturer == PCMCIA_VENDOR_INVALID) &&
292 (sc->card.product == PCMCIA_PRODUCT_INVALID) &&
293 sc->card.cis1_info[0] &&
294 (strcmp(sc->card.cis1_info[0],
295 pcmcia_cis_quirks[i].cis1_info[0]) == 0) &&
296 sc->card.cis1_info[1] &&
297 (strcmp(sc->card.cis1_info[1],
298 pcmcia_cis_quirks[i].cis1_info[1]) == 0)))) {
299 if (!wiped) {
300 if (pcmcia_verbose) {
301 printf("%s: using CIS quirks for ", sc->dev.dv_xname);
302 for (j = 0; j < 4; j++) {
303 if (sc->card.cis1_info[j] == NULL)
304 break;
305 if (j)
306 printf(", ");
307 printf("%s", sc->card.cis1_info[j]);
308 }
309 printf("\n");
310 }
311
312 for (pf = SIMPLEQ_FIRST(&sc->card.pf_head); pf != NULL;
313 pf = pf_next) {
314 for (cfe = SIMPLEQ_FIRST(&pf->cfe_head); cfe != NULL;
315 cfe = cfe_next) {
316 cfe_next = SIMPLEQ_NEXT(cfe, cfe_list);
317 free(cfe, M_DEVBUF);
318 }
319 pf_next = SIMPLEQ_NEXT(pf, pf_list);
320 free(pf, M_DEVBUF);
321 }
322
323 SIMPLEQ_INIT(&sc->card.pf_head);
324 wiped = 1;
325 }
326
327 if (pf_last == pcmcia_cis_quirks[i].pf) {
328 cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT);
329 *cfe = *pcmcia_cis_quirks[i].cfe;
330
331 SIMPLEQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list);
332 } else {
333 pf = malloc(sizeof(*pf), M_DEVBUF, M_NOWAIT);
334 *pf = *pcmcia_cis_quirks[i].pf;
335 SIMPLEQ_INIT(&pf->cfe_head);
336
337 cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT);
338 *cfe = *pcmcia_cis_quirks[i].cfe;
339
340 SIMPLEQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list);
341 SIMPLEQ_INSERT_TAIL(&sc->card.pf_head, pf, pf_list);
342
343 pf_last = pcmcia_cis_quirks[i].pf;
344 }
345 }
346 }
347 }
348