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