1 /* $NetBSD: pcmcia_cis_quirks.c,v 1.6 2000/04/12 21:07:55 scw Exp $ */
9 * Copyright (c) 1998 Marc Horowitz. All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
37 #include <sys/param.h>
39 #include <sys/malloc.h>
40 #include <sys/systm.h>
42 #include <machine/bus.h>
44 #include <dev/pccard/pccard_cis.h>
45 #include <dev/pccard/pccardvar.h>
46 #include <dev/pccard/pccardvarp.h>
48 #include "pccarddevs.h"
50 /* There are cards out there whose CIS flat-out lies. This file
51 contains struct pccard_function chains for those devices. */
53 /* these structures are just static templates which are then copied
54 into "live" allocated structures */
56 struct pccard_function pccard_3cxem556_func0 = {
57 0, /* function number */
58 PCCARD_FUNCTION_NETWORK,
59 0x07, /* last cfe number */
64 struct pccard_config_entry pccard_3cxem556_func0_cfe0 = {
65 0x07, /* cfe number */
66 PCCARD_CFE_IO8 | PCCARD_CFE_IO16 | PCCARD_CFE_IRQLEVEL,
70 { { 0x0010, 0 } }, /* iospace */
77 static struct pccard_function pccard_3cxem556_func1 = {
78 1, /* function number */
79 PCCARD_FUNCTION_SERIAL,
80 0x27, /* last cfe number */
85 static struct pccard_config_entry pccard_3cxem556_func1_cfe0 = {
86 0x27, /* cfe number */
87 PCCARD_CFE_IO8 | PCCARD_CFE_IRQLEVEL,
91 { { 0x0008, 0 } }, /* iospace */
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 */
106 static struct pccard_config_entry pccard_3ccfem556bi_func0_cfe0 = {
107 0x07, /* cfe number */
108 PCCARD_CFE_IO8 | PCCARD_CFE_IO16 | PCCARD_CFE_IRQLEVEL,
112 { { 0x0020, 0 } }, /* iospace */
113 0xffff, /* irqmask */
114 0, /* num_memspace */
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 */
127 static struct pccard_config_entry pccard_3ccfem556bi_func1_cfe0 = {
128 0x27, /* cfe number */
129 PCCARD_CFE_IO8 | PCCARD_CFE_IRQLEVEL,
133 { { 0x0008, 0 } }, /* iospace */
134 0xffff, /* irqmask */
135 0, /* num_memspace */
140 static struct pccard_function pccard_3c1_func0 = {
141 0, /* function number */
142 PCCARD_FUNCTION_NETWORK,
143 0x05, /* last cfe number */
144 0x400, /* ccr_base */
145 0x267, /* ccr_mask */
148 static struct pccard_config_entry pccard_3c1_func0_cfe0 = {
149 0x05, /* cfe number */
150 PCCARD_CFE_IO8 | PCCARD_CFE_IO16 | PCCARD_CFE_IRQLEVEL,
154 { { 0x0010, 0 } }, /* iospace */
155 0xffff, /* irqmask */
156 0, /* num_memspace */
161 static struct pccard_function pccard_sveclancard_func0 = {
162 0, /* function number */
163 PCCARD_FUNCTION_NETWORK,
164 0x1, /* last cfe number */
165 0x100, /* ccr_base */
169 static struct pccard_config_entry pccard_sveclancard_func0_cfe0 = {
170 0x1, /* cfe number */
171 PCCARD_CFE_MWAIT_REQUIRED | PCCARD_CFE_RDYBSY_ACTIVE |
172 PCCARD_CFE_WP_ACTIVE | PCCARD_CFE_BVD_ACTIVE | PCCARD_CFE_IO16,
176 { { 0x20, 0x300 } }, /* iospace */
177 0xdeb8, /* irqmask */
178 0, /* num_memspace */
183 static struct pccard_function pccard_ndc_nd5100_func0 = {
184 0, /* function number */
185 PCCARD_FUNCTION_NETWORK,
186 0x23, /* last cfe number */
187 0x3f8, /* ccr_base */
191 static struct pccard_config_entry pccard_ndc_nd5100_func0_cfe0 = {
192 0x20, /* cfe number */
193 PCCARD_CFE_MWAIT_REQUIRED | PCCARD_CFE_IO16 | PCCARD_CFE_IRQLEVEL,
197 { { 0x20, 0x300 } }, /* iospace */
198 0xdeb8, /* irqmask */
199 0, /* num_memspace */
204 static struct pccard_function pccard_sierra_a555_func1 = {
205 1, /* function number */
206 PCCARD_FUNCTION_SERIAL,
207 0x24, /* last cfe number */
208 0x700, /* ccr_base */
212 static struct pccard_config_entry pccard_sierra_a555_func1_cfe0 = {
213 0x22, /* cfe number */
214 PCCARD_CFE_IO8 | PCCARD_CFE_IRQLEVEL,
218 { { 0x0008, 0x3e8 } }, /* iospace */
219 0x3fbc, /* irqmask */
220 0, /* num_memspace */
225 static struct pccard_cis_quirk pccard_cis_quirks[] = {
226 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556, PCMCIA_CIS_INVALID,
227 &pccard_3cxem556_func0, &pccard_3cxem556_func0_cfe0 },
228 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556, PCMCIA_CIS_INVALID,
229 &pccard_3cxem556_func1, &pccard_3cxem556_func1_cfe0 },
230 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556INT, PCMCIA_CIS_INVALID,
231 &pccard_3cxem556_func0, &pccard_3cxem556_func0_cfe0 },
232 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556INT, PCMCIA_CIS_INVALID,
233 &pccard_3cxem556_func1, &pccard_3cxem556_func1_cfe0 },
234 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CCFEM556BI,
236 &pccard_3ccfem556bi_func0, &pccard_3ccfem556bi_func0_cfe0 },
237 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CCFEM556BI,
239 &pccard_3ccfem556bi_func1, &pccard_3ccfem556bi_func1_cfe0 },
240 { PCMCIA_VENDOR_SIERRA, PCMCIA_PRODUCT_SIERRA_A550,
242 &pccard_sierra_a555_func1, &pccard_sierra_a555_func1_cfe0 },
243 { PCMCIA_VENDOR_SIERRA, PCMCIA_PRODUCT_SIERRA_A555,
245 &pccard_sierra_a555_func1, &pccard_sierra_a555_func1_cfe0 },
246 { PCMCIA_VENDOR_SIERRA, PCMCIA_PRODUCT_SIERRA_A710,
248 &pccard_sierra_a555_func1, &pccard_sierra_a555_func1_cfe0 },
249 { PCMCIA_VENDOR_SIERRA, PCMCIA_PRODUCT_SIERRA_AC710,
251 &pccard_sierra_a555_func1, &pccard_sierra_a555_func1_cfe0 },
252 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3C1, PCMCIA_CIS_INVALID,
253 &pccard_3c1_func0, &pccard_3c1_func0_cfe0 },
254 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, PCMCIA_CIS_SVEC_LANCARD,
255 &pccard_sveclancard_func0, &pccard_sveclancard_func0_cfe0 },
256 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, PCMCIA_CIS_NDC_ND5100_E,
257 &pccard_ndc_nd5100_func0, &pccard_ndc_nd5100_func0_cfe0 },
260 static int n_pccard_cis_quirks =
261 sizeof(pccard_cis_quirks)/sizeof(pccard_cis_quirks[0]);
264 pccard_cis_quirk_match(struct pccard_softc *sc, struct pccard_cis_quirk *q)
266 if ((sc->card.manufacturer == q->manufacturer) &&
267 (sc->card.product == q->product) &&
268 (((sc->card.manufacturer != PCMCIA_VENDOR_INVALID) &&
269 (sc->card.product != PCMCIA_PRODUCT_INVALID)) ||
270 ((sc->card.manufacturer == PCMCIA_VENDOR_INVALID) &&
271 (sc->card.product == PCMCIA_PRODUCT_INVALID) &&
272 sc->card.cis1_info[0] &&
273 (strcmp(sc->card.cis1_info[0], q->cis1_info[0]) == 0) &&
274 sc->card.cis1_info[1] &&
275 (strcmp(sc->card.cis1_info[1], q->cis1_info[1]) == 0))))
280 void pccard_check_cis_quirks(device_t dev)
282 struct pccard_softc *sc = PCCARD_SOFTC(dev);
285 struct pccard_function *pf, *pf_next, *pf_last;
286 struct pccard_config_entry *cfe, *cfe_next;
287 struct pccard_cis_quirk *q;
292 for (i=0; i<n_pccard_cis_quirks; i++) {
293 q = &pccard_cis_quirks[i];
294 if (!pccard_cis_quirk_match(sc, q))
298 device_printf(dev, "using CIS quirks for ");
299 for (j = 0; j < 4; j++) {
300 if (sc->card.cis1_info[j] == NULL)
304 printf("%s", sc->card.cis1_info[j]);
309 for (pf = STAILQ_FIRST(&sc->card.pf_head); pf != NULL;
311 for (cfe = STAILQ_FIRST(&pf->cfe_head); cfe != NULL;
313 cfe_next = STAILQ_NEXT(cfe, cfe_list);
316 pf_next = STAILQ_NEXT(pf, pf_list);
320 STAILQ_INIT(&sc->card.pf_head);
324 if (pf_last == q->pf) {
325 cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT);
327 device_printf(dev, "no memory for quirk (1)\n");
331 STAILQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list);
333 pf = malloc(sizeof(*pf), M_DEVBUF, M_NOWAIT);
336 "no memory for pccard function\n");
340 STAILQ_INIT(&pf->cfe_head);
341 cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT);
344 device_printf(dev, "no memory for quirk (2)\n");
348 STAILQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list);
349 STAILQ_INSERT_TAIL(&sc->card.pf_head, pf, pf_list);