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.7 2002/02/09 21:34:06 imp Exp $ */
3 /* $DragonFly: src/sys/bus/pccard/pccard_cis_quirks.c,v 1.4 2006/09/05 00:55:36 dillon Exp $ */
8 * Copyright (c) 1998 Marc Horowitz. All rights reserved.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by Marc Horowitz.
21 * 4. The name of the author may not be used to endorse or promote products
22 * derived from this software without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/malloc.h>
39 #include <sys/module.h>
40 #include <sys/kernel.h>
41 #include <sys/queue.h>
42 #include <sys/types.h>
45 #include <machine/bus.h>
47 #include <machine/resource.h>
49 #include <bus/pccard/pccarddevs.h>
50 #include <bus/pccard/pccardreg.h>
51 #include <bus/pccard/pccardvar.h>
53 /* There are cards out there whose CIS flat-out lies. This file
54 contains struct pccard_function chains for those devices. */
56 /* these structures are just static templates which are then copied
57 into "live" allocated structures */
59 struct pccard_function pccard_3cxem556_func0 = {
60 0, /* function number */
61 PCCARD_FUNCTION_NETWORK,
62 0x07, /* last cfe number */
67 struct pccard_config_entry pccard_3cxem556_func0_cfe0 = {
68 0x07, /* cfe number */
69 PCCARD_CFE_IO8 | PCCARD_CFE_IO16 | PCCARD_CFE_IRQLEVEL,
73 { { 0x0010, 0 } }, /* iospace */
80 static struct pccard_function pccard_3cxem556_func1 = {
81 1, /* function number */
82 PCCARD_FUNCTION_SERIAL,
83 0x27, /* last cfe number */
88 static struct pccard_config_entry pccard_3cxem556_func1_cfe0 = {
89 0x27, /* cfe number */
90 PCCARD_CFE_IO8 | PCCARD_CFE_IRQLEVEL,
94 { { 0x0008, 0 } }, /* iospace */
101 static struct pccard_function pccard_3ccfem556bi_func0 = {
102 0, /* function number */
103 PCCARD_FUNCTION_NETWORK,
104 0x07, /* last cfe number */
105 0x1000, /* ccr_base */
106 0x267, /* ccr_mask */
109 static struct pccard_config_entry pccard_3ccfem556bi_func0_cfe0 = {
110 0x07, /* cfe number */
111 PCCARD_CFE_IO8 | PCCARD_CFE_IO16 | PCCARD_CFE_IRQLEVEL,
115 { { 0x0020, 0 } }, /* iospace */
116 0xffff, /* irqmask */
117 0, /* num_memspace */
122 static struct pccard_function pccard_3ccfem556bi_func1 = {
123 1, /* function number */
124 PCCARD_FUNCTION_SERIAL,
125 0x27, /* last cfe number */
126 0x1100, /* ccr_base */
127 0x277, /* ccr_mask */
130 static struct pccard_config_entry pccard_3ccfem556bi_func1_cfe0 = {
131 0x27, /* cfe number */
132 PCCARD_CFE_IO8 | PCCARD_CFE_IRQLEVEL,
136 { { 0x0008, 0 } }, /* iospace */
137 0xffff, /* irqmask */
138 0, /* num_memspace */
143 static struct pccard_function pccard_sveclancard_func0 = {
144 0, /* function number */
145 PCCARD_FUNCTION_NETWORK,
146 0x1, /* last cfe number */
147 0x100, /* ccr_base */
151 static struct pccard_config_entry pccard_sveclancard_func0_cfe0 = {
152 0x1, /* cfe number */
153 PCCARD_CFE_MWAIT_REQUIRED | PCCARD_CFE_RDYBSY_ACTIVE |
154 PCCARD_CFE_WP_ACTIVE | PCCARD_CFE_BVD_ACTIVE | PCCARD_CFE_IO16,
158 { { 0x20, 0x300 } }, /* iospace */
159 0xdeb8, /* irqmask */
160 0, /* num_memspace */
165 static struct pccard_function pccard_ndc_nd5100_func0 = {
166 0, /* function number */
167 PCCARD_FUNCTION_NETWORK,
168 0x23, /* last cfe number */
169 0x3f8, /* ccr_base */
173 static struct pccard_config_entry pccard_ndc_nd5100_func0_cfe0 = {
174 0x20, /* cfe number */
175 PCCARD_CFE_MWAIT_REQUIRED | PCCARD_CFE_IO16 | PCCARD_CFE_IRQLEVEL,
179 { { 0x20, 0x300 } }, /* iospace */
180 0xdeb8, /* irqmask */
181 0, /* num_memspace */
186 static struct pccard_cis_quirk pccard_cis_quirks[] = {
187 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556, PCMCIA_CIS_INVALID,
188 &pccard_3cxem556_func0, &pccard_3cxem556_func0_cfe0 },
189 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556, PCMCIA_CIS_INVALID,
190 &pccard_3cxem556_func1, &pccard_3cxem556_func1_cfe0 },
191 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556INT, PCMCIA_CIS_INVALID,
192 &pccard_3cxem556_func0, &pccard_3cxem556_func0_cfe0 },
193 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556INT, PCMCIA_CIS_INVALID,
194 &pccard_3cxem556_func1, &pccard_3cxem556_func1_cfe0 },
195 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CCFEM556BI,
197 &pccard_3ccfem556bi_func0, &pccard_3ccfem556bi_func0_cfe0 },
198 { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CCFEM556BI,
200 &pccard_3ccfem556bi_func1, &pccard_3ccfem556bi_func1_cfe0 },
201 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, PCMCIA_CIS_SVEC_LANCARD,
202 &pccard_sveclancard_func0, &pccard_sveclancard_func0_cfe0 },
203 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, PCMCIA_CIS_NDC_ND5100_E,
204 &pccard_ndc_nd5100_func0, &pccard_ndc_nd5100_func0_cfe0 },
207 static int n_pccard_cis_quirks =
208 sizeof(pccard_cis_quirks)/sizeof(pccard_cis_quirks[0]);
211 pccard_check_cis_quirks(device_t dev)
213 struct pccard_softc *sc = PCCARD_SOFTC(dev);
216 struct pccard_function *pf, *pf_next, *pf_last;
217 struct pccard_config_entry *cfe, *cfe_next;
222 for (i=0; i<n_pccard_cis_quirks; i++) {
223 if ((sc->card.manufacturer == pccard_cis_quirks[i].manufacturer) &&
224 (sc->card.product == pccard_cis_quirks[i].product) &&
225 (((sc->card.manufacturer != PCMCIA_VENDOR_INVALID) &&
226 (sc->card.product != PCMCIA_PRODUCT_INVALID)) ||
227 ((sc->card.manufacturer == PCMCIA_VENDOR_INVALID) &&
228 (sc->card.product == PCMCIA_PRODUCT_INVALID) &&
229 sc->card.cis1_info[0] &&
230 (strcmp(sc->card.cis1_info[0],
231 pccard_cis_quirks[i].cis1_info[0]) == 0) &&
232 sc->card.cis1_info[1] &&
233 (strcmp(sc->card.cis1_info[1],
234 pccard_cis_quirks[i].cis1_info[1]) == 0)))) {
237 device_printf(dev, "using CIS quirks for ");
238 for (j = 0; j < 4; j++) {
239 if (sc->card.cis1_info[j] == NULL)
243 printf("%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 == pccard_cis_quirks[i].pf) {
264 cfe = kmalloc(sizeof(*cfe), M_DEVBUF, M_INTWAIT);
265 *cfe = *pccard_cis_quirks[i].cfe;
267 STAILQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list);
269 pf = kmalloc(sizeof(*pf), M_DEVBUF, M_INTWAIT);
270 *pf = *pccard_cis_quirks[i].pf;
271 STAILQ_INIT(&pf->cfe_head);
273 cfe = kmalloc(sizeof(*cfe), M_DEVBUF, M_INTWAIT);
274 *cfe = *pccard_cis_quirks[i].cfe;
276 STAILQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list);
277 STAILQ_INSERT_TAIL(&sc->card.pf_head, pf, pf_list);
279 pf_last = pccard_cis_quirks[i].pf;