pccard_cis_quirks.c revision 120868
134689Sbde/*	$NetBSD: pcmcia_cis_quirks.c,v 1.6 2000/04/12 21:07:55 scw Exp $ */
250476Speter
31573Srgrimes#include <sys/cdefs.h>
434689Sbde__FBSDID("$FreeBSD: head/sys/dev/pccard/pccard_cis_quirks.c 120868 2003-10-07 03:33:54Z imp $");
534689Sbde
634689Sbde#define	PCCARDDEBUG
738752Sbde
881920Skris/*
979471Smarkm * Copyright (c) 1998 Marc Horowitz.  All rights reserved.
1081133Stmm *
1159897Sjoe * Redistribution and use in source and binary forms, with or without
1279471Smarkm * modification, are permitted provided that the following conditions
1350731Speter * are met:
1459353Skris * 1. Redistributions of source code must retain the above copyright
1541257Sjdp *    notice, this list of conditions and the following disclaimer.
1682355Smarkm * 2. Redistributions in binary form must reproduce the above copyright
1794690Sdes *    notice, this list of conditions and the following disclaimer in the
1841257Sjdp *    documentation and/or other materials provided with the distribution.
1956081Sbde * 3. All advertising materials mentioning features or use of this software
2094690Sdes *    must display the following acknowledgement:
2134689Sbde *	This product includes software developed by Marc Horowitz.
2234689Sbde * 4. The name of the author may not be used to endorse or promote products
2334689Sbde *    derived from this software without specific prior written permission.
2481133Stmm *
2594690Sdes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
2678560Sobrien * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27111204Sobrien * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28110546Sphk * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2990796Sgshapiro * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
3056058Srwatson * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3196505Sru * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32101207Srwatson * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33101207Srwatson * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
3434689Sbde * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35103436Speter */
36103436Speter
3772309Sobrien#include <sys/param.h>
3834689Sbde#include <sys/systm.h>
3972309Sobrien#include <sys/malloc.h>
4072309Sobrien#include <sys/module.h>
411573Srgrimes#include <sys/kernel.h>
421573Srgrimes#include <sys/queue.h>
43108753Smarcel#include <sys/types.h>
4434689Sbde
4517706Sjulian#include <sys/bus.h>
4617706Sjulian#include <machine/bus.h>
4753927Speter#include <sys/rman.h>
4853922Speter#include <machine/resource.h>
4953922Speter
5053922Speter#include <dev/pccard/pccarddevs.h>
5186252Sgshapiro#include <dev/pccard/pccardreg.h>
5290796Sgshapiro#include <dev/pccard/pccardvar.h>
5390796Sgshapiro#include <dev/pccard/pccard_cis.h>
5486252Sgshapiro
5586252Sgshapiro/* There are cards out there whose CIS flat-out lies.  This file
5686252Sgshapiro   contains struct pccard_function chains for those devices. */
5786252Sgshapiro
5834689Sbde/* these structures are just static templates which are then copied
5938477Sgpalmer   into "live" allocated structures */
6052228Sbp
6187960Ssheldonhstruct pccard_function pccard_3cxem556_func0 = {
6234689Sbde	0,			/* function number */
6336026Sjb	PCCARD_FUNCTION_NETWORK,
6434689Sbde	0x07,			/* last cfe number */
6541912Sdfr	0x800,			/* ccr_base */
6641912Sdfr	0x63,			/* ccr_mask */
6772309Sobrien};
6841912Sdfr
6941912Sdfrstruct pccard_config_entry pccard_3cxem556_func0_cfe0 = {
70111204Sobrien	0x07,			/* cfe number */
71111204Sobrien	PCCARD_CFE_IO8 | PCCARD_CFE_IO16 | PCCARD_CFE_IRQLEVEL,
72111204Sobrien	PCCARD_IFTYPE_IO,
73111204Sobrien	1,			/* num_iospace */
7451994Smarkm	4,			/* iomask */
75111987Smarkm	{ { 0x0010, 0 } },	/* iospace */
76111987Smarkm	0xffff,			/* irqmask */
77111987Smarkm	0,			/* num_memspace */
7834689Sbde	{ },			/* memspace */
7934689Sbde	0,			/* maxtwins */
8020845Speter};
8196687Sobrien
8296687Sobrienstatic struct pccard_function pccard_3cxem556_func1 = {
8381054Ssobomax	1,			/* function number */
8481054Ssobomax	PCCARD_FUNCTION_SERIAL,
8581054Ssobomax	0x27,			/* last cfe number */
861573Srgrimes	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