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>
42 #include <bus/pccard/pccarddevs.h>
44 /* There are cards out there whose CIS flat-out lies. This file
45 contains struct pccard_function chains for those devices. */
47 /* these structures are just static templates which are then copied
48 into "live" allocated structures */
50 struct pccard_function pccard_3cxem556_func0 = {
51 0, /* function number */
52 PCCARD_FUNCTION_NETWORK,
53 0x07, /* last cfe number */
58 struct pccard_config_entry pccard_3cxem556_func0_cfe0 = {
59 0x07, /* cfe number */
60 PCCARD_CFE_IO8 | PCCARD_CFE_IO16 | PCCARD_CFE_IRQLEVEL,
64 { { 0x0010, 0 } }, /* iospace */
71 static struct pccard_function pccard_3cxem556_func1 = {
72 1, /* function number */
73 PCCARD_FUNCTION_SERIAL,
74 0x27, /* last cfe number */
79 static struct pccard_config_entry pccard_3cxem556_func1_cfe0 = {
80 0x27, /* cfe number */
81 PCCARD_CFE_IO8 | PCCARD_CFE_IRQLEVEL,
85 { { 0x0008, 0 } }, /* iospace */
92 static struct pccard_function pccard_3ccfem556bi_func0 = {
93 0, /* function number */
94 PCCARD_FUNCTION_NETWORK,
95 0x07, /* last cfe number */
96 0x1000, /* ccr_base */
100 static struct pccard_config_entry pccard_3ccfem556bi_func0_cfe0 = {
101 0x07, /* cfe number */
102 PCCARD_CFE_IO8 | PCCARD_CFE_IO16 | PCCARD_CFE_IRQLEVEL,
106 { { 0x0020, 0 } }, /* iospace */
107 0xffff, /* irqmask */
108 0, /* num_memspace */
113 static struct pccard_function pccard_3ccfem556bi_func1 = {
114 1, /* function number */
115 PCCARD_FUNCTION_SERIAL,
116 0x27, /* last cfe number */
117 0x1100, /* ccr_base */
118 0x277, /* ccr_mask */
121 static struct pccard_config_entry pccard_3ccfem556bi_func1_cfe0 = {
122 0x27, /* cfe number */
123 PCCARD_CFE_IO8 | PCCARD_CFE_IRQLEVEL,
127 { { 0x0008, 0 } }, /* iospace */
128 0xffff, /* irqmask */
129 0, /* num_memspace */
134 static struct pccard_function pccard_sveclancard_func0 = {
135 0, /* function number */
136 PCCARD_FUNCTION_NETWORK,
137 0x1, /* last cfe number */
138 0x100, /* ccr_base */
142 static struct pccard_config_entry pccard_sveclancard_func0_cfe0 = {
143 0x1, /* cfe number */
144 PCCARD_CFE_MWAIT_REQUIRED | PCCARD_CFE_RDYBSY_ACTIVE |
145 PCCARD_CFE_WP_ACTIVE | PCCARD_CFE_BVD_ACTIVE | PCCARD_CFE_IO16,
149 { { 0x20, 0x300 } }, /* iospace */
150 0xdeb8, /* irqmask */
151 0, /* num_memspace */
156 static struct pccard_function pccard_ndc_nd5100_func0 = {
157 0, /* function number */
158 PCCARD_FUNCTION_NETWORK,
159 0x23, /* last cfe number */
160 0x3f8, /* ccr_base */
164 static struct pccard_config_entry pccard_ndc_nd5100_func0_cfe0 = {
165 0x20, /* cfe number */
166 PCCARD_CFE_MWAIT_REQUIRED | PCCARD_CFE_IO16 | PCCARD_CFE_IRQLEVEL,
170 { { 0x20, 0x300 } }, /* iospace */
171 0xdeb8, /* irqmask */
172 0, /* num_memspace */
177 static struct pccard_cis_quirk pccard_cis_quirks[] = {
178 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556, PCMCIA_CIS_INVALID,
179 &pccard_3cxem556_func0, &pccard_3cxem556_func0_cfe0 },
180 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556, PCMCIA_CIS_INVALID,
181 &pccard_3cxem556_func1, &pccard_3cxem556_func1_cfe0 },
182 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556INT, PCMCIA_CIS_INVALID,
183 &pccard_3cxem556_func0, &pccard_3cxem556_func0_cfe0 },
184 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556INT, PCMCIA_CIS_INVALID,
185 &pccard_3cxem556_func1, &pccard_3cxem556_func1_cfe0 },
186 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CCFEM556BI,
188 &pccard_3ccfem556bi_func0, &pccard_3ccfem556bi_func0_cfe0 },
189 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CCFEM556BI,
191 &pccard_3ccfem556bi_func1, &pccard_3ccfem556bi_func1_cfe0 },
192 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, PCMCIA_CIS_SVEC_LANCARD,
193 &pccard_sveclancard_func0, &pccard_sveclancard_func0_cfe0 },
194 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, PCMCIA_CIS_NDC_ND5100_E,
195 &pccard_ndc_nd5100_func0, &pccard_ndc_nd5100_func0_cfe0 },
198 static int n_pccard_cis_quirks = NELEM(pccard_cis_quirks);
201 pccard_cis_quirk_match(struct pccard_softc *sc, struct pccard_cis_quirk *q)
203 if ((sc->card.manufacturer == q->manufacturer) &&
204 (sc->card.product == q->product) &&
205 (((sc->card.manufacturer != PCMCIA_VENDOR_INVALID) &&
206 (sc->card.product != PCMCIA_PRODUCT_INVALID)) ||
207 ((sc->card.manufacturer == PCMCIA_VENDOR_INVALID) &&
208 (sc->card.product == PCMCIA_PRODUCT_INVALID) &&
209 sc->card.cis1_info[0] &&
210 (strcmp(sc->card.cis1_info[0], q->cis1_info[0]) == 0) &&
211 sc->card.cis1_info[1] &&
212 (strcmp(sc->card.cis1_info[1], q->cis1_info[1]) == 0))))
218 pccard_check_cis_quirks(device_t dev)
220 struct pccard_softc *sc = PCCARD_SOFTC(dev);
223 struct pccard_function *pf, *pf_next, *pf_last;
224 struct pccard_config_entry *cfe, *cfe_next;
225 struct pccard_cis_quirk *q;
230 for (i=0; i<n_pccard_cis_quirks; i++) {
231 q = &pccard_cis_quirks[i];
232 if (!pccard_cis_quirk_match(sc, q))
236 device_printf(dev, "using CIS quirks for ");
237 for (j = 0; j < 4; j++) {
238 if (sc->card.cis1_info[j] == NULL)
242 kprintf("%s", sc->card.cis1_info[j]);
247 for (pf = STAILQ_FIRST(&sc->card.pf_head); pf != NULL;
249 for (cfe = STAILQ_FIRST(&pf->cfe_head); cfe != NULL;
251 cfe_next = STAILQ_NEXT(cfe, cfe_list);
252 kfree(cfe, M_DEVBUF);
254 pf_next = STAILQ_NEXT(pf, pf_list);
258 STAILQ_INIT(&sc->card.pf_head);
262 if (pf_last == q->pf) {
263 cfe = kmalloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT);
265 device_printf(dev, "no memory for quirk (1)\n");
269 STAILQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list);
271 pf = kmalloc(sizeof(*pf), M_DEVBUF, M_NOWAIT);
274 "no memory for pccard function\n");
278 STAILQ_INIT(&pf->cfe_head);
279 cfe = kmalloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT);
282 device_printf(dev, "no memory for quirk (2)\n");
286 STAILQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list);
287 STAILQ_INSERT_TAIL(&sc->card.pf_head, pf, pf_list);