1 /* $NetBSD: pcmcia_cis_quirks.c,v 1.6 2000/04/12 21:07:55 scw Exp $ */
2 /* $FreeBSD: src/sys/dev/pccard/pccard_cis_quirks.c,v 1.15 2005/03/26 21:30:49 sam Exp $ */
7 * Copyright (c) 1998 Marc Horowitz. All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by Marc Horowitz.
20 * 4. The name of the author may not be used to endorse or promote products
21 * derived from this software without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include <sys/param.h>
37 #include <sys/malloc.h>
38 #include <sys/systm.h>
40 #include <bus/pccard/pccard_cis.h>
41 #include <bus/pccard/pccardvar.h>
43 #include "pccarddevs.h"
45 /* There are cards out there whose CIS flat-out lies. This file
46 contains struct pccard_function chains for those devices. */
48 /* these structures are just static templates which are then copied
49 into "live" allocated structures */
51 struct pccard_function pccard_3cxem556_func0 = {
52 0, /* function number */
53 PCCARD_FUNCTION_NETWORK,
54 0x07, /* last cfe number */
59 struct pccard_config_entry pccard_3cxem556_func0_cfe0 = {
60 0x07, /* cfe number */
61 PCCARD_CFE_IO8 | PCCARD_CFE_IO16 | PCCARD_CFE_IRQLEVEL,
65 { { 0x0010, 0 } }, /* iospace */
72 static struct pccard_function pccard_3cxem556_func1 = {
73 1, /* function number */
74 PCCARD_FUNCTION_SERIAL,
75 0x27, /* last cfe number */
80 static struct pccard_config_entry pccard_3cxem556_func1_cfe0 = {
81 0x27, /* cfe number */
82 PCCARD_CFE_IO8 | PCCARD_CFE_IRQLEVEL,
86 { { 0x0008, 0 } }, /* iospace */
93 static struct pccard_function pccard_3ccfem556bi_func0 = {
94 0, /* function number */
95 PCCARD_FUNCTION_NETWORK,
96 0x07, /* last cfe number */
97 0x1000, /* ccr_base */
101 static struct pccard_config_entry pccard_3ccfem556bi_func0_cfe0 = {
102 0x07, /* cfe number */
103 PCCARD_CFE_IO8 | PCCARD_CFE_IO16 | PCCARD_CFE_IRQLEVEL,
107 { { 0x0020, 0 } }, /* iospace */
108 0xffff, /* irqmask */
109 0, /* num_memspace */
114 static struct pccard_function pccard_3ccfem556bi_func1 = {
115 1, /* function number */
116 PCCARD_FUNCTION_SERIAL,
117 0x27, /* last cfe number */
118 0x1100, /* ccr_base */
119 0x277, /* ccr_mask */
122 static struct pccard_config_entry pccard_3ccfem556bi_func1_cfe0 = {
123 0x27, /* cfe number */
124 PCCARD_CFE_IO8 | PCCARD_CFE_IRQLEVEL,
128 { { 0x0008, 0 } }, /* iospace */
129 0xffff, /* irqmask */
130 0, /* num_memspace */
135 static struct pccard_function pccard_sveclancard_func0 = {
136 0, /* function number */
137 PCCARD_FUNCTION_NETWORK,
138 0x1, /* last cfe number */
139 0x100, /* ccr_base */
143 static struct pccard_config_entry pccard_sveclancard_func0_cfe0 = {
144 0x1, /* cfe number */
145 PCCARD_CFE_MWAIT_REQUIRED | PCCARD_CFE_RDYBSY_ACTIVE |
146 PCCARD_CFE_WP_ACTIVE | PCCARD_CFE_BVD_ACTIVE | PCCARD_CFE_IO16,
150 { { 0x20, 0x300 } }, /* iospace */
151 0xdeb8, /* irqmask */
152 0, /* num_memspace */
157 static struct pccard_function pccard_ndc_nd5100_func0 = {
158 0, /* function number */
159 PCCARD_FUNCTION_NETWORK,
160 0x23, /* last cfe number */
161 0x3f8, /* ccr_base */
165 static struct pccard_config_entry pccard_ndc_nd5100_func0_cfe0 = {
166 0x20, /* cfe number */
167 PCCARD_CFE_MWAIT_REQUIRED | PCCARD_CFE_IO16 | PCCARD_CFE_IRQLEVEL,
171 { { 0x20, 0x300 } }, /* iospace */
172 0xdeb8, /* irqmask */
173 0, /* num_memspace */
178 static struct pccard_cis_quirk pccard_cis_quirks[] = {
179 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556, PCMCIA_CIS_INVALID,
180 &pccard_3cxem556_func0, &pccard_3cxem556_func0_cfe0 },
181 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556, PCMCIA_CIS_INVALID,
182 &pccard_3cxem556_func1, &pccard_3cxem556_func1_cfe0 },
183 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556INT, PCMCIA_CIS_INVALID,
184 &pccard_3cxem556_func0, &pccard_3cxem556_func0_cfe0 },
185 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556INT, PCMCIA_CIS_INVALID,
186 &pccard_3cxem556_func1, &pccard_3cxem556_func1_cfe0 },
187 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CCFEM556BI,
189 &pccard_3ccfem556bi_func0, &pccard_3ccfem556bi_func0_cfe0 },
190 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CCFEM556BI,
192 &pccard_3ccfem556bi_func1, &pccard_3ccfem556bi_func1_cfe0 },
193 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, PCMCIA_CIS_SVEC_LANCARD,
194 &pccard_sveclancard_func0, &pccard_sveclancard_func0_cfe0 },
195 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, PCMCIA_CIS_NDC_ND5100_E,
196 &pccard_ndc_nd5100_func0, &pccard_ndc_nd5100_func0_cfe0 },
199 static int n_pccard_cis_quirks = NELEM(pccard_cis_quirks);
202 pccard_cis_quirk_match(struct pccard_softc *sc, struct pccard_cis_quirk *q)
204 if ((sc->card.manufacturer == q->manufacturer) &&
205 (sc->card.product == q->product) &&
206 (((sc->card.manufacturer != PCMCIA_VENDOR_INVALID) &&
207 (sc->card.product != PCMCIA_PRODUCT_INVALID)) ||
208 ((sc->card.manufacturer == PCMCIA_VENDOR_INVALID) &&
209 (sc->card.product == PCMCIA_PRODUCT_INVALID) &&
210 sc->card.cis1_info[0] &&
211 (strcmp(sc->card.cis1_info[0], q->cis1_info[0]) == 0) &&
212 sc->card.cis1_info[1] &&
213 (strcmp(sc->card.cis1_info[1], q->cis1_info[1]) == 0))))
219 pccard_check_cis_quirks(device_t dev)
221 struct pccard_softc *sc = PCCARD_SOFTC(dev);
224 struct pccard_function *pf, *pf_next, *pf_last;
225 struct pccard_config_entry *cfe, *cfe_next;
226 struct pccard_cis_quirk *q;
231 for (i=0; i<n_pccard_cis_quirks; i++) {
232 q = &pccard_cis_quirks[i];
233 if (!pccard_cis_quirk_match(sc, q))
237 device_printf(dev, "using CIS quirks for ");
238 for (j = 0; j < 4; j++) {
239 if (sc->card.cis1_info[j] == NULL)
243 kprintf("%s", sc->card.cis1_info[j]);
248 for (pf = STAILQ_FIRST(&sc->card.pf_head); pf != NULL;
250 for (cfe = STAILQ_FIRST(&pf->cfe_head); cfe != NULL;
252 cfe_next = STAILQ_NEXT(cfe, cfe_list);
253 kfree(cfe, M_DEVBUF);
255 pf_next = STAILQ_NEXT(pf, pf_list);
259 STAILQ_INIT(&sc->card.pf_head);
263 if (pf_last == q->pf) {
264 cfe = kmalloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT);
266 device_printf(dev, "no memory for quirk (1)\n");
270 STAILQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list);
272 pf = kmalloc(sizeof(*pf), M_DEVBUF, M_NOWAIT);
275 "no memory for pccard function\n");
279 STAILQ_INIT(&pf->cfe_head);
280 cfe = kmalloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT);
283 device_printf(dev, "no memory for quirk (2)\n");
287 STAILQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list);
288 STAILQ_INSERT_TAIL(&sc->card.pf_head, pf, pf_list);