pcmcia_cis_quirks.c revision 1.29 1 1.29 christos /* $NetBSD: pcmcia_cis_quirks.c,v 1.29 2006/09/03 04:52:14 christos Exp $ */
2 1.1 marc
3 1.1 marc /*
4 1.1 marc * Copyright (c) 1998 Marc Horowitz. All rights reserved.
5 1.1 marc *
6 1.1 marc * Redistribution and use in source and binary forms, with or without
7 1.1 marc * modification, are permitted provided that the following conditions
8 1.1 marc * are met:
9 1.1 marc * 1. Redistributions of source code must retain the above copyright
10 1.1 marc * notice, this list of conditions and the following disclaimer.
11 1.1 marc * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 marc * notice, this list of conditions and the following disclaimer in the
13 1.1 marc * documentation and/or other materials provided with the distribution.
14 1.1 marc * 3. All advertising materials mentioning features or use of this software
15 1.1 marc * must display the following acknowledgement:
16 1.1 marc * This product includes software developed by Marc Horowitz.
17 1.1 marc * 4. The name of the author may not be used to endorse or promote products
18 1.1 marc * derived from this software without specific prior written permission.
19 1.1 marc *
20 1.1 marc * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 1.1 marc * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 1.1 marc * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 1.1 marc * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 1.1 marc * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 1.1 marc * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 1.1 marc * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 1.1 marc * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 1.1 marc * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 1.1 marc * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 1.1 marc */
31 1.13 lukem
32 1.13 lukem #include <sys/cdefs.h>
33 1.29 christos __KERNEL_RCSID(0, "$NetBSD: pcmcia_cis_quirks.c,v 1.29 2006/09/03 04:52:14 christos Exp $");
34 1.1 marc
35 1.1 marc #include <sys/param.h>
36 1.1 marc #include <sys/systm.h>
37 1.1 marc #include <sys/device.h>
38 1.23 enami #include <sys/kernel.h>
39 1.1 marc #include <sys/mbuf.h>
40 1.1 marc
41 1.1 marc #include <dev/pcmcia/pcmciadevs.h>
42 1.1 marc #include <dev/pcmcia/pcmciareg.h>
43 1.1 marc #include <dev/pcmcia/pcmciachip.h>
44 1.1 marc #include <dev/pcmcia/pcmciavar.h>
45 1.1 marc
46 1.1 marc /* There are cards out there whose CIS flat-out lies. This file
47 1.1 marc contains struct pcmcia_function chains for those devices. */
48 1.1 marc
49 1.1 marc /* these structures are just static templates which are then copied
50 1.1 marc into "live" allocated structures */
51 1.1 marc
52 1.8 jdolecek static const struct pcmcia_function pcmcia_3cxem556_func0 = {
53 1.29 christos .number = 0, /* function number */
54 1.29 christos .function = PCMCIA_FUNCTION_NETWORK,
55 1.29 christos .last_config_index = 0x07, /* last cfe number */
56 1.29 christos .ccr_base = 0x800, /* ccr_base */
57 1.29 christos .ccr_mask = 0x63, /* ccr_mask */
58 1.1 marc };
59 1.1 marc
60 1.8 jdolecek static const struct pcmcia_config_entry pcmcia_3cxem556_func0_cfe0 = {
61 1.29 christos .number = 0x07, /* cfe number */
62 1.29 christos .flags = PCMCIA_CFE_IO8 | PCMCIA_CFE_IO16 | PCMCIA_CFE_IRQLEVEL,
63 1.29 christos .iftype = PCMCIA_IFTYPE_IO,
64 1.29 christos .num_iospace = 1, /* num_iospace */
65 1.29 christos .iomask = 4, /* iomask */
66 1.29 christos .iospace = { { .length = 0x0010, .start = 0 } }, /* iospace */
67 1.29 christos .irqmask = 0xffff, /* irqmask */
68 1.1 marc };
69 1.1 marc
70 1.8 jdolecek static const struct pcmcia_function pcmcia_3cxem556_func1 = {
71 1.29 christos .number = 1, /* function number */
72 1.29 christos .function = PCMCIA_FUNCTION_SERIAL,
73 1.29 christos .last_config_index = 0x27, /* last cfe number */
74 1.29 christos .ccr_base = 0x900, /* ccr_base */
75 1.29 christos .ccr_mask = 0x63, /* ccr_mask */
76 1.1 marc };
77 1.1 marc
78 1.8 jdolecek static const struct pcmcia_config_entry pcmcia_3cxem556_func1_cfe0 = {
79 1.29 christos .number = 0x27, /* cfe number */
80 1.29 christos .flags = PCMCIA_CFE_IO8 | PCMCIA_CFE_IRQLEVEL,
81 1.29 christos .iftype = PCMCIA_IFTYPE_IO,
82 1.29 christos .num_iospace = 1, /* num_iospace */
83 1.29 christos .iomask = 3, /* iomask */
84 1.29 christos .iospace = { { .length = 0x0008, .start = 0 } }, /* iospace */
85 1.29 christos .irqmask = 0xffff, /* irqmask */
86 1.1 marc };
87 1.1 marc
88 1.8 jdolecek static const struct pcmcia_function pcmcia_3ccfem556bi_func0 = {
89 1.29 christos .number = 0, /* function number */
90 1.29 christos .function = PCMCIA_FUNCTION_NETWORK,
91 1.29 christos .last_config_index = 0x07, /* last cfe number */
92 1.29 christos .ccr_base = 0x1000, /* ccr_base */
93 1.29 christos .ccr_mask = 0x267, /* ccr_mask */
94 1.5 thorpej };
95 1.5 thorpej
96 1.8 jdolecek static const struct pcmcia_config_entry pcmcia_3ccfem556bi_func0_cfe0 = {
97 1.29 christos .number = 0x07, /* cfe number */
98 1.29 christos .flags = PCMCIA_CFE_IO8 | PCMCIA_CFE_IO16 | PCMCIA_CFE_IRQLEVEL,
99 1.29 christos .iftype = PCMCIA_IFTYPE_IO,
100 1.29 christos .num_iospace = 1, /* num_iospace */
101 1.29 christos .iomask = 5, /* iomask */
102 1.29 christos .iospace = { { .length = 0x0020, .start = 0 } }, /* iospace */
103 1.5 thorpej };
104 1.5 thorpej
105 1.8 jdolecek static const struct pcmcia_function pcmcia_3ccfem556bi_func1 = {
106 1.29 christos .number = 1, /* function number */
107 1.29 christos .function = PCMCIA_FUNCTION_SERIAL,
108 1.29 christos .last_config_index = 0x27, /* last cfe number */
109 1.29 christos .ccr_base = 0x1100, /* ccr_base */
110 1.29 christos .ccr_mask = 0x277, /* ccr_mask */
111 1.5 thorpej };
112 1.5 thorpej
113 1.8 jdolecek static const struct pcmcia_config_entry pcmcia_3ccfem556bi_func1_cfe0 = {
114 1.29 christos .number = 0x27, /* cfe number */
115 1.29 christos .flags = PCMCIA_CFE_IO8 | PCMCIA_CFE_IRQLEVEL,
116 1.29 christos .iftype = PCMCIA_IFTYPE_IO,
117 1.29 christos .num_iospace = 1, /* num_iospace */
118 1.29 christos .iomask = 3, /* iomask */
119 1.29 christos .iospace = { { .length = 0x0008, .start = 0 } }, /* iospace */
120 1.29 christos .irqmask = 0xffff, /* irqmask */
121 1.5 thorpej };
122 1.5 thorpej
123 1.8 jdolecek static const struct pcmcia_function pcmcia_sveclancard_func0 = {
124 1.29 christos .number = 0, /* function number */
125 1.29 christos .function = PCMCIA_FUNCTION_NETWORK,
126 1.29 christos .last_config_index = 0x1, /* last cfe number */
127 1.29 christos .ccr_base = 0x100, /* ccr_base */
128 1.29 christos .ccr_mask = 0x1, /* ccr_mask */
129 1.3 marc };
130 1.3 marc
131 1.8 jdolecek static const struct pcmcia_config_entry pcmcia_sveclancard_func0_cfe0 = {
132 1.29 christos .number = 0x1, /* cfe number */
133 1.29 christos .flags = PCMCIA_CFE_MWAIT_REQUIRED | PCMCIA_CFE_RDYBSY_ACTIVE |
134 1.29 christos PCMCIA_CFE_WP_ACTIVE | PCMCIA_CFE_BVD_ACTIVE | PCMCIA_CFE_IO16,
135 1.29 christos .iftype = PCMCIA_IFTYPE_IO,
136 1.29 christos .num_iospace = 1, /* num_iospace */
137 1.29 christos .iomask = 5, /* iomask */
138 1.29 christos .iospace = { { .length = 0x20, .start = 0x300 } }, /* iospace */
139 1.29 christos .irqmask = 0xdeb8, /* irqmask */
140 1.3 marc };
141 1.3 marc
142 1.8 jdolecek static const struct pcmcia_function pcmcia_ndc_nd5100_func0 = {
143 1.29 christos .number = 0, /* function number */
144 1.29 christos .function = PCMCIA_FUNCTION_NETWORK,
145 1.29 christos .last_config_index = 0x23, /* last cfe number */
146 1.29 christos .ccr_base = 0x3f8, /* ccr_base */
147 1.29 christos .ccr_mask = 0x3, /* ccr_mask */
148 1.6 scw };
149 1.6 scw
150 1.8 jdolecek static const struct pcmcia_config_entry pcmcia_ndc_nd5100_func0_cfe0 = {
151 1.29 christos .number = 0x20, /* cfe number */
152 1.29 christos .flags = PCMCIA_CFE_MWAIT_REQUIRED | PCMCIA_CFE_IO16 |
153 1.29 christos PCMCIA_CFE_IRQLEVEL,
154 1.29 christos .iftype = PCMCIA_IFTYPE_IO,
155 1.29 christos .num_iospace = 1, /* num_iospace */
156 1.29 christos .iomask = 5, /* iomask */
157 1.29 christos .iospace = { { .length = 0x20, .start = 0x300 } }, /* iospace */
158 1.29 christos .irqmask = 0xdeb8, /* irqmask */
159 1.6 scw };
160 1.6 scw
161 1.12 ichiro static const struct pcmcia_function pcmcia_emtac_a2424i_func0 = {
162 1.29 christos .number = 0, /* function number */
163 1.29 christos .function = PCMCIA_FUNCTION_NETWORK,
164 1.29 christos .last_config_index = 0x21, /* last cfe number */
165 1.29 christos .ccr_base = 0x3e0, /* ccr_base */
166 1.29 christos .ccr_mask = 0x1, /* ccr_mask */
167 1.12 ichiro };
168 1.12 ichiro
169 1.12 ichiro static const struct pcmcia_config_entry pcmcia_emtac_a2424i_func0_cfe0 = {
170 1.29 christos .number = 0x21, /* cfe number */
171 1.29 christos .flags = PCMCIA_CFE_IO16 | PCMCIA_CFE_IRQLEVEL | PCMCIA_CFE_IRQPULSE,
172 1.29 christos .iftype = PCMCIA_IFTYPE_IO,
173 1.29 christos .num_iospace = 1, /* num_iospace */
174 1.29 christos .iomask = 6, /* iomask */
175 1.29 christos .iospace = { { .length = 0x40, .start = 0x100 } }, /* iospace */
176 1.29 christos .irqmask = 0xffff, /* irqmask */
177 1.12 ichiro };
178 1.12 ichiro
179 1.17 ichiro static const struct pcmcia_function pcmcia_fujitsu_j181_func0 = {
180 1.29 christos .number = 0, /* function number */
181 1.29 christos .function = PCMCIA_FUNCTION_NETWORK,
182 1.29 christos .last_config_index = 0x21, /* last cfe number */
183 1.29 christos .ccr_base = 0xfe0, /* ccr_base */
184 1.29 christos .ccr_mask = 0xf, /* ccr_mask */
185 1.17 ichiro };
186 1.15 ichiro
187 1.17 ichiro static const struct pcmcia_config_entry pcmcia_fujitsu_j181_func0_cfe0 = {
188 1.29 christos .number = 0xc, /* cfe number */
189 1.29 christos .flags = PCMCIA_CFE_MWAIT_REQUIRED | PCMCIA_CFE_WP_ACTIVE |
190 1.29 christos PCMCIA_CFE_IO8 | PCMCIA_CFE_IO16 | PCMCIA_CFE_IRQLEVEL |
191 1.29 christos PCMCIA_CFE_IRQPULSE,
192 1.29 christos .iftype = PCMCIA_IFTYPE_IO,
193 1.29 christos .num_iospace = 1, /* num_iospace */
194 1.29 christos .iomask = 10, /* iomask */
195 1.29 christos .iospace = { { .length = 0x20, .start = 0x140 } }, /* iospace */
196 1.29 christos .irqmask = 0xffff, /* irqmask */
197 1.15 ichiro };
198 1.15 ichiro
199 1.8 jdolecek static const struct pcmcia_cis_quirk pcmcia_cis_quirks[] = {
200 1.25 perry { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556, PCMCIA_CIS_INVALID,
201 1.1 marc &pcmcia_3cxem556_func0, &pcmcia_3cxem556_func0_cfe0 },
202 1.3 marc { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556, PCMCIA_CIS_INVALID,
203 1.4 tron &pcmcia_3cxem556_func1, &pcmcia_3cxem556_func1_cfe0 },
204 1.25 perry { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556INT, PCMCIA_CIS_INVALID,
205 1.4 tron &pcmcia_3cxem556_func0, &pcmcia_3cxem556_func0_cfe0 },
206 1.4 tron { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556INT, PCMCIA_CIS_INVALID,
207 1.1 marc &pcmcia_3cxem556_func1, &pcmcia_3cxem556_func1_cfe0 },
208 1.5 thorpej { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CCFEM556BI,
209 1.5 thorpej PCMCIA_CIS_INVALID,
210 1.5 thorpej &pcmcia_3ccfem556bi_func0, &pcmcia_3ccfem556bi_func0_cfe0 },
211 1.5 thorpej { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CCFEM556BI,
212 1.5 thorpej PCMCIA_CIS_INVALID,
213 1.5 thorpej &pcmcia_3ccfem556bi_func1, &pcmcia_3ccfem556bi_func1_cfe0 },
214 1.3 marc { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, PCMCIA_CIS_SVEC_LANCARD,
215 1.3 marc &pcmcia_sveclancard_func0, &pcmcia_sveclancard_func0_cfe0 },
216 1.6 scw { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, PCMCIA_CIS_NDC_ND5100_E,
217 1.6 scw &pcmcia_ndc_nd5100_func0, &pcmcia_ndc_nd5100_func0_cfe0 },
218 1.12 ichiro { PCMCIA_VENDOR_EMTAC, PCMCIA_PRODUCT_EMTAC_WLAN, PCMCIA_CIS_INVALID,
219 1.12 ichiro &pcmcia_emtac_a2424i_func0, &pcmcia_emtac_a2424i_func0_cfe0 },
220 1.17 ichiro { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
221 1.17 ichiro PCMCIA_CIS_FUJITSU_FMV_J181,
222 1.17 ichiro &pcmcia_fujitsu_j181_func0, &pcmcia_fujitsu_j181_func0_cfe0 },
223 1.1 marc };
224 1.25 perry
225 1.21 mycroft static const int pcmcia_cis_nquirks =
226 1.21 mycroft sizeof(pcmcia_cis_quirks) / sizeof(pcmcia_cis_quirks[0]);
227 1.1 marc
228 1.23 enami void
229 1.23 enami pcmcia_check_cis_quirks(sc)
230 1.1 marc struct pcmcia_softc *sc;
231 1.1 marc {
232 1.1 marc int wiped = 0;
233 1.22 christos size_t i, j;
234 1.19 lukem struct pcmcia_function *pf;
235 1.8 jdolecek const struct pcmcia_function *pf_last;
236 1.19 lukem struct pcmcia_config_entry *cfe;
237 1.22 christos struct pcmcia_card *card = &sc->card;
238 1.23 enami const struct pcmcia_cis_quirk *quirk;
239 1.1 marc
240 1.2 marc pf = NULL;
241 1.1 marc pf_last = NULL;
242 1.1 marc
243 1.22 christos for (i = 0; i < pcmcia_cis_nquirks; i++) {
244 1.23 enami quirk = &pcmcia_cis_quirks[i];
245 1.22 christos
246 1.23 enami if (card->manufacturer == quirk->manufacturer &&
247 1.23 enami card->manufacturer != PCMCIA_VENDOR_INVALID &&
248 1.23 enami card->product == quirk->product &&
249 1.22 christos card->product != PCMCIA_PRODUCT_INVALID)
250 1.23 enami goto match;
251 1.22 christos
252 1.22 christos for (j = 0; j < 2; j++)
253 1.24 enami if (card->cis1_info[j] == NULL ||
254 1.24 enami quirk->cis1_info[j] == NULL ||
255 1.24 enami strcmp(card->cis1_info[j],
256 1.24 enami quirk->cis1_info[j]) != 0)
257 1.24 enami goto nomatch;
258 1.22 christos
259 1.23 enami match:
260 1.22 christos if (!wiped) {
261 1.22 christos if (pcmcia_verbose) {
262 1.22 christos printf("%s: using CIS quirks for ",
263 1.22 christos sc->dev.dv_xname);
264 1.22 christos for (j = 0; j < 4; j++) {
265 1.22 christos if (card->cis1_info[j] == NULL)
266 1.22 christos break;
267 1.22 christos if (j)
268 1.22 christos printf(", ");
269 1.22 christos printf("%s", card->cis1_info[j]);
270 1.1 marc }
271 1.22 christos printf("\n");
272 1.1 marc }
273 1.22 christos pcmcia_free_pf(&card->pf_head);
274 1.22 christos wiped = 1;
275 1.22 christos }
276 1.1 marc
277 1.23 enami if (pf_last != quirk->pf) {
278 1.23 enami /*
279 1.23 enami * XXX: a driver which still calls pcmcia_card_attach
280 1.23 enami * very early attach stage should be fixed instead.
281 1.23 enami */
282 1.23 enami pf = malloc(sizeof(*pf), M_DEVBUF,
283 1.23 enami cold ? M_NOWAIT : M_WAITOK);
284 1.23 enami if (pf == NULL)
285 1.23 enami panic("pcmcia_check_cis_quirks: malloc pf");
286 1.23 enami *pf = *quirk->pf;
287 1.22 christos SIMPLEQ_INIT(&pf->cfe_head);
288 1.23 enami SIMPLEQ_INSERT_TAIL(&card->pf_head, pf, pf_list);
289 1.23 enami pf_last = quirk->pf;
290 1.23 enami }
291 1.1 marc
292 1.23 enami /*
293 1.23 enami * XXX: see above.
294 1.23 enami */
295 1.23 enami cfe = malloc(sizeof(*cfe), M_DEVBUF,
296 1.23 enami cold ? M_NOWAIT : M_WAITOK);
297 1.23 enami if (cfe == NULL)
298 1.23 enami panic("pcmcia_check_cis_quirks: malloc cfe");
299 1.23 enami *cfe = *quirk->cfe;
300 1.27 christos KASSERT(pf != NULL);
301 1.23 enami SIMPLEQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list);
302 1.1 marc
303 1.23 enami nomatch:;
304 1.1 marc }
305 1.1 marc }
306