1 /* $NetBSD: pcmcia_cis_quirks.c,v 1.6 2000/04/12 21:07:55 scw Exp $ */
2
3 #include <sys/cdefs.h>
4 __FBSDID("$FreeBSD: releng/6.0/sys/dev/pccard/pccard_cis_quirks.c 150641 2005-09-27 18:42:20Z imp $");
5
6 #define PCCARDDEBUG
7
8 /*-
9 * Copyright (c) 1998 Marc Horowitz. All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by Marc Horowitz.
22 * 4. The name of the author may not be used to endorse or promote products
23 * derived from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
26 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
29 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 */
36
37 #include <sys/param.h>
38 #include <sys/bus.h>
39 #include <sys/malloc.h>
40 #include <sys/systm.h>
41
42 #include <machine/bus.h>
43
44 #include <dev/pccard/pccard_cis.h>
45 #include <dev/pccard/pccardvar.h>
46 #include <dev/pccard/pccardvarp.h>
47
48 #include "pccarddevs.h"
49
50 /* There are cards out there whose CIS flat-out lies. This file
51 contains struct pccard_function chains for those devices. */
52
53 /* these structures are just static templates which are then copied
54 into "live" allocated structures */
55
56 struct pccard_function pccard_3cxem556_func0 = {
57 0, /* function number */
58 PCCARD_FUNCTION_NETWORK,
59 0x07, /* last cfe number */
60 0x800, /* ccr_base */
61 0x63, /* ccr_mask */
62 };
63
64 struct pccard_config_entry pccard_3cxem556_func0_cfe0 = {
65 0x07, /* cfe number */
66 PCCARD_CFE_IO8 | PCCARD_CFE_IO16 | PCCARD_CFE_IRQLEVEL,
67 PCCARD_IFTYPE_IO,
68 1, /* num_iospace */
69 4, /* iomask */
70 { { 0x0010, 0 } }, /* iospace */
71 0xffff, /* irqmask */
72 0, /* num_memspace */
73 { }, /* memspace */
74 0, /* maxtwins */
75 };
76
77 static struct pccard_function pccard_3cxem556_func1 = {
78 1, /* function number */
79 PCCARD_FUNCTION_SERIAL,
80 0x27, /* last cfe number */
81 0x900, /* ccr_base */
82 0x63, /* ccr_mask */
83 };
84
85 static struct pccard_config_entry pccard_3cxem556_func1_cfe0 = {
86 0x27, /* cfe number */
87 PCCARD_CFE_IO8 | PCCARD_CFE_IRQLEVEL,
88 PCCARD_IFTYPE_IO,
89 1, /* num_iospace */
90 3, /* iomask */
91 { { 0x0008, 0 } }, /* iospace */
92 0xffff, /* irqmask */
93 0, /* num_memspace */
94 { }, /* memspace */
95 0, /* maxtwins */
96 };
97
98 static struct pccard_function pccard_3ccfem556bi_func0 = {
99 0, /* function number */
100 PCCARD_FUNCTION_NETWORK,
101 0x07, /* last cfe number */
102 0x1000, /* ccr_base */
103 0x267, /* ccr_mask */
104 };
105
106 static struct pccard_config_entry pccard_3ccfem556bi_func0_cfe0 = {
107 0x07, /* cfe number */
108 PCCARD_CFE_IO8 | PCCARD_CFE_IO16 | PCCARD_CFE_IRQLEVEL,
109 PCCARD_IFTYPE_IO,
110 1, /* num_iospace */
111 5, /* iomask */
112 { { 0x0020, 0 } }, /* iospace */
113 0xffff, /* irqmask */
114 0, /* num_memspace */
115 { }, /* memspace */
116 0, /* maxtwins */
117 };
118
119 static struct pccard_function pccard_3ccfem556bi_func1 = {
120 1, /* function number */
121 PCCARD_FUNCTION_SERIAL,
122 0x27, /* last cfe number */
123 0x1100, /* ccr_base */
124 0x277, /* ccr_mask */
125 };
126
127 static struct pccard_config_entry pccard_3ccfem556bi_func1_cfe0 = {
128 0x27, /* cfe number */
129 PCCARD_CFE_IO8 | PCCARD_CFE_IRQLEVEL,
130 PCCARD_IFTYPE_IO,
131 1, /* num_iospace */
132 3, /* iomask */
133 { { 0x0008, 0 } }, /* iospace */
134 0xffff, /* irqmask */
135 0, /* num_memspace */
136 { }, /* memspace */
137 0, /* maxtwins */
138 };
139
140 static struct pccard_function pccard_sveclancard_func0 = {
141 0, /* function number */
142 PCCARD_FUNCTION_NETWORK,
143 0x1, /* last cfe number */
144 0x100, /* ccr_base */
145 0x1, /* ccr_mask */
146 };
147
148 static struct pccard_config_entry pccard_sveclancard_func0_cfe0 = {
149 0x1, /* cfe number */
150 PCCARD_CFE_MWAIT_REQUIRED | PCCARD_CFE_RDYBSY_ACTIVE |
151 PCCARD_CFE_WP_ACTIVE | PCCARD_CFE_BVD_ACTIVE | PCCARD_CFE_IO16,
152 PCCARD_IFTYPE_IO,
153 1, /* num_iospace */
154 5, /* iomask */
155 { { 0x20, 0x300 } }, /* iospace */
156 0xdeb8, /* irqmask */
157 0, /* num_memspace */
158 { }, /* memspace */
159 0, /* maxtwins */
160 };
161
162 static struct pccard_function pccard_ndc_nd5100_func0 = {
163 0, /* function number */
164 PCCARD_FUNCTION_NETWORK,
165 0x23, /* last cfe number */
166 0x3f8, /* ccr_base */
167 0x3, /* ccr_mask */
168 };
169
170 static struct pccard_config_entry pccard_ndc_nd5100_func0_cfe0 = {
171 0x20, /* cfe number */
172 PCCARD_CFE_MWAIT_REQUIRED | PCCARD_CFE_IO16 | PCCARD_CFE_IRQLEVEL,
173 PCCARD_IFTYPE_IO,
174 1, /* num_iospace */
175 5, /* iomask */
176 { { 0x20, 0x300 } }, /* iospace */
177 0xdeb8, /* irqmask */
178 0, /* num_memspace */
179 { }, /* memspace */
180 0, /* maxtwins */
181 };
182
183 static struct pccard_cis_quirk pccard_cis_quirks[] = {
184 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556, PCMCIA_CIS_INVALID,
185 &pccard_3cxem556_func0, &pccard_3cxem556_func0_cfe0 },
186 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556, PCMCIA_CIS_INVALID,
187 &pccard_3cxem556_func1, &pccard_3cxem556_func1_cfe0 },
188 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556INT, PCMCIA_CIS_INVALID,
189 &pccard_3cxem556_func0, &pccard_3cxem556_func0_cfe0 },
190 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556INT, PCMCIA_CIS_INVALID,
191 &pccard_3cxem556_func1, &pccard_3cxem556_func1_cfe0 },
192 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CCFEM556BI,
193 PCMCIA_CIS_INVALID,
194 &pccard_3ccfem556bi_func0, &pccard_3ccfem556bi_func0_cfe0 },
195 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CCFEM556BI,
196 PCMCIA_CIS_INVALID,
197 &pccard_3ccfem556bi_func1, &pccard_3ccfem556bi_func1_cfe0 },
198 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, PCMCIA_CIS_SVEC_LANCARD,
199 &pccard_sveclancard_func0, &pccard_sveclancard_func0_cfe0 },
200 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, PCMCIA_CIS_NDC_ND5100_E,
201 &pccard_ndc_nd5100_func0, &pccard_ndc_nd5100_func0_cfe0 },
202 };
203
204 static int n_pccard_cis_quirks =
205 sizeof(pccard_cis_quirks)/sizeof(pccard_cis_quirks[0]);
206
207 static int
208 pccard_cis_quirk_match(struct pccard_softc *sc, struct pccard_cis_quirk *q)
209 {
210 if ((sc->card.manufacturer == q->manufacturer) &&
211 (sc->card.product == q->product) &&
212 (((sc->card.manufacturer != PCMCIA_VENDOR_INVALID) &&
213 (sc->card.product != PCMCIA_PRODUCT_INVALID)) ||
214 ((sc->card.manufacturer == PCMCIA_VENDOR_INVALID) &&
215 (sc->card.product == PCMCIA_PRODUCT_INVALID) &&
216 sc->card.cis1_info[0] &&
217 (strcmp(sc->card.cis1_info[0], q->cis1_info[0]) == 0) &&
218 sc->card.cis1_info[1] &&
219 (strcmp(sc->card.cis1_info[1], q->cis1_info[1]) == 0))))
220 return (1);
221 return (0);
222 }
223
224 void pccard_check_cis_quirks(device_t dev)
225 {
226 struct pccard_softc *sc = PCCARD_SOFTC(dev);
227 int wiped = 0;
228 int i, j;
229 struct pccard_function *pf, *pf_next, *pf_last;
230 struct pccard_config_entry *cfe, *cfe_next;
231 struct pccard_cis_quirk *q;
232
233 pf = NULL;
234 pf_last = NULL;
235
236 for (i=0; i<n_pccard_cis_quirks; i++) {
237 q = &pccard_cis_quirks[i];
238 if (!pccard_cis_quirk_match(sc, q))
239 continue;
240 if (!wiped) {
241 if (bootverbose) {
242 device_printf(dev, "using CIS quirks for ");
243 for (j = 0; j < 4; j++) {
244 if (sc->card.cis1_info[j] == NULL)
245 break;
246 if (j)
247 printf(", ");
248 printf("%s", sc->card.cis1_info[j]);
249 }
250 printf("\n");
251 }
252
253 for (pf = STAILQ_FIRST(&sc->card.pf_head); pf != NULL;
254 pf = pf_next) {
255 for (cfe = STAILQ_FIRST(&pf->cfe_head); cfe != NULL;
256 cfe = cfe_next) {
257 cfe_next = STAILQ_NEXT(cfe, cfe_list);
258 free(cfe, M_DEVBUF);
259 }
260 pf_next = STAILQ_NEXT(pf, pf_list);
261 free(pf, M_DEVBUF);
262 }
263
264 STAILQ_INIT(&sc->card.pf_head);
265 wiped = 1;
266 }
267
268 if (pf_last == q->pf) {
269 cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT);
270 if (cfe == NULL) {
271 device_printf(dev, "no memory for quirk (1)\n");
272 continue;
273 }
274 *cfe = *q->cfe;
275 STAILQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list);
276 } else {
277 pf = malloc(sizeof(*pf), M_DEVBUF, M_NOWAIT);
278 if (pf == NULL) {
279 device_printf(dev,
280 "no memory for pccard function\n");
281 continue;
282 }
283 *pf = *q->pf;
284 STAILQ_INIT(&pf->cfe_head);
285 cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT);
286 if (cfe == NULL) {
287 free(pf, M_DEVBUF);
288 device_printf(dev, "no memory for quirk (2)\n");
289 continue;
290 }
291 *cfe = *q->cfe;
292 STAILQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list);
293 STAILQ_INSERT_TAIL(&sc->card.pf_head, pf, pf_list);
294 pf_last = q->pf;
295 }
296 }
297 }
Cache object: 5f5c2b29324582dff677e7f1c4c8bdef
|