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.5 2006/10/25 20:55:51 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>
47 #include <bus/pccard/pccarddevs.h>
48 #include <bus/pccard/pccardreg.h>
49 #include <bus/pccard/pccardvar.h>
51 /* There are cards out there whose CIS flat-out lies. This file
52 contains struct pccard_function chains for those devices. */
54 /* these structures are just static templates which are then copied
55 into "live" allocated structures */
57 struct pccard_function pccard_3cxem556_func0
= {
58 0, /* function number */
59 PCCARD_FUNCTION_NETWORK
,
60 0x07, /* last cfe number */
65 struct pccard_config_entry pccard_3cxem556_func0_cfe0
= {
66 0x07, /* cfe number */
67 PCCARD_CFE_IO8
| PCCARD_CFE_IO16
| PCCARD_CFE_IRQLEVEL
,
71 { { 0x0010, 0 } }, /* iospace */
78 static struct pccard_function pccard_3cxem556_func1
= {
79 1, /* function number */
80 PCCARD_FUNCTION_SERIAL
,
81 0x27, /* last cfe number */
86 static struct pccard_config_entry pccard_3cxem556_func1_cfe0
= {
87 0x27, /* cfe number */
88 PCCARD_CFE_IO8
| PCCARD_CFE_IRQLEVEL
,
92 { { 0x0008, 0 } }, /* iospace */
99 static struct pccard_function pccard_3ccfem556bi_func0
= {
100 0, /* function number */
101 PCCARD_FUNCTION_NETWORK
,
102 0x07, /* last cfe number */
103 0x1000, /* ccr_base */
104 0x267, /* ccr_mask */
107 static struct pccard_config_entry pccard_3ccfem556bi_func0_cfe0
= {
108 0x07, /* cfe number */
109 PCCARD_CFE_IO8
| PCCARD_CFE_IO16
| PCCARD_CFE_IRQLEVEL
,
113 { { 0x0020, 0 } }, /* iospace */
114 0xffff, /* irqmask */
115 0, /* num_memspace */
120 static struct pccard_function pccard_3ccfem556bi_func1
= {
121 1, /* function number */
122 PCCARD_FUNCTION_SERIAL
,
123 0x27, /* last cfe number */
124 0x1100, /* ccr_base */
125 0x277, /* ccr_mask */
128 static struct pccard_config_entry pccard_3ccfem556bi_func1_cfe0
= {
129 0x27, /* cfe number */
130 PCCARD_CFE_IO8
| PCCARD_CFE_IRQLEVEL
,
134 { { 0x0008, 0 } }, /* iospace */
135 0xffff, /* irqmask */
136 0, /* num_memspace */
141 static struct pccard_function pccard_sveclancard_func0
= {
142 0, /* function number */
143 PCCARD_FUNCTION_NETWORK
,
144 0x1, /* last cfe number */
145 0x100, /* ccr_base */
149 static struct pccard_config_entry pccard_sveclancard_func0_cfe0
= {
150 0x1, /* cfe number */
151 PCCARD_CFE_MWAIT_REQUIRED
| PCCARD_CFE_RDYBSY_ACTIVE
|
152 PCCARD_CFE_WP_ACTIVE
| PCCARD_CFE_BVD_ACTIVE
| PCCARD_CFE_IO16
,
156 { { 0x20, 0x300 } }, /* iospace */
157 0xdeb8, /* irqmask */
158 0, /* num_memspace */
163 static struct pccard_function pccard_ndc_nd5100_func0
= {
164 0, /* function number */
165 PCCARD_FUNCTION_NETWORK
,
166 0x23, /* last cfe number */
167 0x3f8, /* ccr_base */
171 static struct pccard_config_entry pccard_ndc_nd5100_func0_cfe0
= {
172 0x20, /* cfe number */
173 PCCARD_CFE_MWAIT_REQUIRED
| PCCARD_CFE_IO16
| PCCARD_CFE_IRQLEVEL
,
177 { { 0x20, 0x300 } }, /* iospace */
178 0xdeb8, /* irqmask */
179 0, /* num_memspace */
184 static struct pccard_cis_quirk pccard_cis_quirks
[] = {
185 { PCMCIA_VENDOR_3COM
, PCMCIA_PRODUCT_3COM_3CXEM556
, PCMCIA_CIS_INVALID
,
186 &pccard_3cxem556_func0
, &pccard_3cxem556_func0_cfe0
},
187 { PCMCIA_VENDOR_3COM
, PCMCIA_PRODUCT_3COM_3CXEM556
, PCMCIA_CIS_INVALID
,
188 &pccard_3cxem556_func1
, &pccard_3cxem556_func1_cfe0
},
189 { PCMCIA_VENDOR_3COM
, PCMCIA_PRODUCT_3COM_3CXEM556INT
, PCMCIA_CIS_INVALID
,
190 &pccard_3cxem556_func0
, &pccard_3cxem556_func0_cfe0
},
191 { PCMCIA_VENDOR_3COM
, PCMCIA_PRODUCT_3COM_3CXEM556INT
, PCMCIA_CIS_INVALID
,
192 &pccard_3cxem556_func1
, &pccard_3cxem556_func1_cfe0
},
193 { PCMCIA_VENDOR_3COM
, PCMCIA_PRODUCT_3COM_3CCFEM556BI
,
195 &pccard_3ccfem556bi_func0
, &pccard_3ccfem556bi_func0_cfe0
},
196 { PCMCIA_VENDOR_3COM
, PCMCIA_PRODUCT_3COM_3CCFEM556BI
,
198 &pccard_3ccfem556bi_func1
, &pccard_3ccfem556bi_func1_cfe0
},
199 { PCMCIA_VENDOR_INVALID
, PCMCIA_PRODUCT_INVALID
, PCMCIA_CIS_SVEC_LANCARD
,
200 &pccard_sveclancard_func0
, &pccard_sveclancard_func0_cfe0
},
201 { PCMCIA_VENDOR_INVALID
, PCMCIA_PRODUCT_INVALID
, PCMCIA_CIS_NDC_ND5100_E
,
202 &pccard_ndc_nd5100_func0
, &pccard_ndc_nd5100_func0_cfe0
},
205 static int n_pccard_cis_quirks
=
206 sizeof(pccard_cis_quirks
)/sizeof(pccard_cis_quirks
[0]);
209 pccard_check_cis_quirks(device_t dev
)
211 struct pccard_softc
*sc
= PCCARD_SOFTC(dev
);
214 struct pccard_function
*pf
, *pf_next
, *pf_last
;
215 struct pccard_config_entry
*cfe
, *cfe_next
;
220 for (i
=0; i
<n_pccard_cis_quirks
; i
++) {
221 if ((sc
->card
.manufacturer
== pccard_cis_quirks
[i
].manufacturer
) &&
222 (sc
->card
.product
== pccard_cis_quirks
[i
].product
) &&
223 (((sc
->card
.manufacturer
!= PCMCIA_VENDOR_INVALID
) &&
224 (sc
->card
.product
!= PCMCIA_PRODUCT_INVALID
)) ||
225 ((sc
->card
.manufacturer
== PCMCIA_VENDOR_INVALID
) &&
226 (sc
->card
.product
== PCMCIA_PRODUCT_INVALID
) &&
227 sc
->card
.cis1_info
[0] &&
228 (strcmp(sc
->card
.cis1_info
[0],
229 pccard_cis_quirks
[i
].cis1_info
[0]) == 0) &&
230 sc
->card
.cis1_info
[1] &&
231 (strcmp(sc
->card
.cis1_info
[1],
232 pccard_cis_quirks
[i
].cis1_info
[1]) == 0)))) {
235 device_printf(dev
, "using CIS quirks for ");
236 for (j
= 0; j
< 4; j
++) {
237 if (sc
->card
.cis1_info
[j
] == NULL
)
241 printf("%s", sc
->card
.cis1_info
[j
]);
246 for (pf
= STAILQ_FIRST(&sc
->card
.pf_head
); pf
!= NULL
;
248 for (cfe
= STAILQ_FIRST(&pf
->cfe_head
); cfe
!= NULL
;
250 cfe_next
= STAILQ_NEXT(cfe
, cfe_list
);
251 kfree(cfe
, M_DEVBUF
);
253 pf_next
= STAILQ_NEXT(pf
, pf_list
);
257 STAILQ_INIT(&sc
->card
.pf_head
);
261 if (pf_last
== pccard_cis_quirks
[i
].pf
) {
262 cfe
= kmalloc(sizeof(*cfe
), M_DEVBUF
, M_INTWAIT
);
263 *cfe
= *pccard_cis_quirks
[i
].cfe
;
265 STAILQ_INSERT_TAIL(&pf
->cfe_head
, cfe
, cfe_list
);
267 pf
= kmalloc(sizeof(*pf
), M_DEVBUF
, M_INTWAIT
);
268 *pf
= *pccard_cis_quirks
[i
].pf
;
269 STAILQ_INIT(&pf
->cfe_head
);
271 cfe
= kmalloc(sizeof(*cfe
), M_DEVBUF
, M_INTWAIT
);
272 *cfe
= *pccard_cis_quirks
[i
].cfe
;
274 STAILQ_INSERT_TAIL(&pf
->cfe_head
, cfe
, cfe_list
);
275 STAILQ_INSERT_TAIL(&sc
->card
.pf_head
, pf
, pf_list
);
277 pf_last
= pccard_cis_quirks
[i
].pf
;