pccard_cis_quirks.c revision 129740
1/*	$NetBSD: pcmcia_cis_quirks.c,v 1.6 2000/04/12 21:07:55 scw Exp $ */
2
3#include <sys/cdefs.h>
4__FBSDID("$FreeBSD: head/sys/dev/pccard/pccard_cis_quirks.c 129740 2004-05-26 00:53:10Z imp $");
5
6#define	PCCARDDEBUG
7
8/*
9 * Copyright (c) 1998 Marc Horowitz.  All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
24 *
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.
35 */
36
37#include <sys/param.h>
38#include <sys/systm.h>
39#include <sys/malloc.h>
40#include <sys/module.h>
41#include <sys/kernel.h>
42#include <sys/queue.h>
43#include <sys/types.h>
44
45#include <sys/bus.h>
46#include <machine/bus.h>
47#include <sys/rman.h>
48#include <machine/resource.h>
49
50#include "pccarddevs.h"
51#include <dev/pccard/pccardreg.h>
52#include <dev/pccard/pccardvar.h>
53#include <dev/pccard/pccard_cis.h>
54
55/* There are cards out there whose CIS flat-out lies.  This file
56   contains struct pccard_function chains for those devices. */
57
58/* these structures are just static templates which are then copied
59   into "live" allocated structures */
60
61struct pccard_function pccard_3cxem556_func0 = {
62	0,			/* function number */
63	PCCARD_FUNCTION_NETWORK,
64	0x07,			/* last cfe number */
65	0x800,			/* ccr_base */
66	0x63,			/* ccr_mask */
67};
68
69struct pccard_config_entry pccard_3cxem556_func0_cfe0 = {
70	0x07,			/* cfe number */
71	PCCARD_CFE_IO8 | PCCARD_CFE_IO16 | PCCARD_CFE_IRQLEVEL,
72	PCCARD_IFTYPE_IO,
73	1,			/* num_iospace */
74	4,			/* iomask */
75	{ { 0x0010, 0 } },	/* iospace */
76	0xffff,			/* irqmask */
77	0,			/* num_memspace */
78	{ },			/* memspace */
79	0,			/* maxtwins */
80};
81
82static struct pccard_function pccard_3cxem556_func1 = {
83	1,			/* function number */
84	PCCARD_FUNCTION_SERIAL,
85	0x27,			/* last cfe number */
86	0x900,			/* ccr_base */
87	0x63,			/* ccr_mask */
88};
89
90static struct pccard_config_entry pccard_3cxem556_func1_cfe0 = {
91	0x27,			/* cfe number */
92	PCCARD_CFE_IO8 | PCCARD_CFE_IRQLEVEL,
93	PCCARD_IFTYPE_IO,
94	1,			/* num_iospace */
95	3,			/* iomask */
96	{ { 0x0008, 0 } },	/* iospace */
97	0xffff,			/* irqmask */
98	0,			/* num_memspace */
99	{ },			/* memspace */
100	0,			/* maxtwins */
101};
102
103static struct pccard_function pccard_3ccfem556bi_func0 = {
104	0,			/* function number */
105	PCCARD_FUNCTION_NETWORK,
106	0x07,			/* last cfe number */
107	0x1000,			/* ccr_base */
108	0x267,			/* ccr_mask */
109};
110
111static struct pccard_config_entry pccard_3ccfem556bi_func0_cfe0 = {
112	0x07,			/* cfe number */
113	PCCARD_CFE_IO8 | PCCARD_CFE_IO16 | PCCARD_CFE_IRQLEVEL,
114	PCCARD_IFTYPE_IO,
115	1,			/* num_iospace */
116	5,			/* iomask */
117	{ { 0x0020, 0 } },	/* iospace */
118	0xffff,			/* irqmask */
119	0,			/* num_memspace */
120	{ },			/* memspace */
121	0,			/* maxtwins */
122};
123
124static struct pccard_function pccard_3ccfem556bi_func1 = {
125	1,			/* function number */
126	PCCARD_FUNCTION_SERIAL,
127	0x27,			/* last cfe number */
128	0x1100,			/* ccr_base */
129	0x277,			/* ccr_mask */
130};
131
132static struct pccard_config_entry pccard_3ccfem556bi_func1_cfe0 = {
133	0x27,			/* cfe number */
134	PCCARD_CFE_IO8 | PCCARD_CFE_IRQLEVEL,
135	PCCARD_IFTYPE_IO,
136	1,			/* num_iospace */
137	3,			/* iomask */
138	{ { 0x0008, 0 } },	/* iospace */
139	0xffff,			/* irqmask */
140	0,			/* num_memspace */
141	{ },			/* memspace */
142	0,			/* maxtwins */
143};
144
145static struct pccard_function pccard_sveclancard_func0 = {
146	0,			/* function number */
147	PCCARD_FUNCTION_NETWORK,
148	0x1,			/* last cfe number */
149	0x100,			/* ccr_base */
150	0x1,			/* ccr_mask */
151};
152
153static struct pccard_config_entry pccard_sveclancard_func0_cfe0 = {
154	0x1,			/* cfe number */
155	PCCARD_CFE_MWAIT_REQUIRED | PCCARD_CFE_RDYBSY_ACTIVE |
156	PCCARD_CFE_WP_ACTIVE | PCCARD_CFE_BVD_ACTIVE | PCCARD_CFE_IO16,
157	PCCARD_IFTYPE_IO,
158	1,			/* num_iospace */
159	5,			/* iomask */
160	{ { 0x20, 0x300 } },	/* iospace */
161	0xdeb8,			/* irqmask */
162	0,			/* num_memspace */
163	{ },			/* memspace */
164	0,			/* maxtwins */
165};
166
167static struct pccard_function pccard_ndc_nd5100_func0 = {
168	0,			/* function number */
169	PCCARD_FUNCTION_NETWORK,
170	0x23,			/* last cfe number */
171	0x3f8,			/* ccr_base */
172	0x3,			/* ccr_mask */
173};
174
175static struct pccard_config_entry pccard_ndc_nd5100_func0_cfe0 = {
176	0x20,			/* cfe number */
177	PCCARD_CFE_MWAIT_REQUIRED | PCCARD_CFE_IO16 | PCCARD_CFE_IRQLEVEL,
178	PCCARD_IFTYPE_IO,
179	1,			/* num_iospace */
180	5,			/* iomask */
181	{ { 0x20, 0x300 } },	/* iospace */
182	0xdeb8,			/* irqmask */
183	0,			/* num_memspace */
184	{ },			/* memspace */
185	0,			/* maxtwins */
186};
187
188static struct pccard_cis_quirk pccard_cis_quirks[] = {
189	{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556, PCMCIA_CIS_INVALID,
190	  &pccard_3cxem556_func0, &pccard_3cxem556_func0_cfe0 },
191	{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556, PCMCIA_CIS_INVALID,
192	  &pccard_3cxem556_func1, &pccard_3cxem556_func1_cfe0 },
193	{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556INT, PCMCIA_CIS_INVALID,
194	  &pccard_3cxem556_func0, &pccard_3cxem556_func0_cfe0 },
195	{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556INT, PCMCIA_CIS_INVALID,
196	  &pccard_3cxem556_func1, &pccard_3cxem556_func1_cfe0 },
197	{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CCFEM556BI,
198	  PCMCIA_CIS_INVALID,
199	  &pccard_3ccfem556bi_func0, &pccard_3ccfem556bi_func0_cfe0 },
200	{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CCFEM556BI,
201	  PCMCIA_CIS_INVALID,
202	  &pccard_3ccfem556bi_func1, &pccard_3ccfem556bi_func1_cfe0 },
203	{ PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, PCMCIA_CIS_SVEC_LANCARD,
204	  &pccard_sveclancard_func0, &pccard_sveclancard_func0_cfe0 },
205	{ PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, PCMCIA_CIS_NDC_ND5100_E,
206	  &pccard_ndc_nd5100_func0, &pccard_ndc_nd5100_func0_cfe0 },
207};
208
209static int n_pccard_cis_quirks =
210	sizeof(pccard_cis_quirks)/sizeof(pccard_cis_quirks[0]);
211
212static int
213pccard_cis_quirk_match(struct pccard_softc *sc, struct pccard_cis_quirk *q)
214{
215	if ((sc->card.manufacturer == q->manufacturer) &&
216		(sc->card.product == q->product) &&
217		(((sc->card.manufacturer != PCMCIA_VENDOR_INVALID) &&
218		  (sc->card.product != PCMCIA_PRODUCT_INVALID)) ||
219		 ((sc->card.manufacturer == PCMCIA_VENDOR_INVALID) &&
220		  (sc->card.product == PCMCIA_PRODUCT_INVALID) &&
221		  sc->card.cis1_info[0] &&
222		  (strcmp(sc->card.cis1_info[0], q->cis1_info[0]) == 0) &&
223		  sc->card.cis1_info[1] &&
224		  (strcmp(sc->card.cis1_info[1], q->cis1_info[1]) == 0))))
225		return (1);
226	return (0);
227}
228
229void pccard_check_cis_quirks(device_t dev)
230{
231	struct pccard_softc *sc = PCCARD_SOFTC(dev);
232	int wiped = 0;
233	int i, j;
234	struct pccard_function *pf, *pf_next, *pf_last;
235	struct pccard_config_entry *cfe, *cfe_next;
236	struct pccard_cis_quirk *q;
237
238	pf = NULL;
239	pf_last = NULL;
240
241	for (i=0; i<n_pccard_cis_quirks; i++) {
242		q = &pccard_cis_quirks[i];
243		if (!pccard_cis_quirk_match(sc, q))
244			continue;
245		if (!wiped) {
246			if (bootverbose) {
247				device_printf(dev, "using CIS quirks for ");
248				for (j = 0; j < 4; j++) {
249					if (sc->card.cis1_info[j] == NULL)
250						break;
251					if (j)
252						printf(", ");
253					printf("%s", sc->card.cis1_info[j]);
254				}
255				printf("\n");
256			}
257
258			for (pf = STAILQ_FIRST(&sc->card.pf_head); pf != NULL;
259			     pf = pf_next) {
260				for (cfe = STAILQ_FIRST(&pf->cfe_head); cfe != NULL;
261				     cfe = cfe_next) {
262					cfe_next = STAILQ_NEXT(cfe, cfe_list);
263					free(cfe, M_DEVBUF);
264				}
265				pf_next = STAILQ_NEXT(pf, pf_list);
266				free(pf, M_DEVBUF);
267			}
268
269			STAILQ_INIT(&sc->card.pf_head);
270			wiped = 1;
271		}
272
273		if (pf_last == q->pf) {
274			cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT);
275			*cfe = *q->cfe;
276			STAILQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list);
277		} else {
278			pf = malloc(sizeof(*pf), M_DEVBUF, M_NOWAIT);
279			*pf = *q->pf;
280			STAILQ_INIT(&pf->cfe_head);
281			cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT);
282			*cfe = *q->cfe;
283			STAILQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list);
284			STAILQ_INSERT_TAIL(&sc->card.pf_head, pf, pf_list);
285			pf_last = q->pf;
286		}
287	}
288}
289