pccard_cis_quirks.c revision 52506
1/*	$NetBSD: pcmcia_cis_quirks.c,v 1.3 1998/12/29 09:00:28 marc Exp $	*/
2/* $FreeBSD: head/sys/dev/pccard/pccard_cis_quirks.c 52506 1999-10-26 06:52:31Z imp $ */
3
4#define	PCCARDDEBUG
5
6/*
7 * Copyright (c) 1998 Marc Horowitz.  All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 *    notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 *    notice, this list of conditions and the following disclaimer in the
16 *    documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 *    must display the following acknowledgement:
19 *	This product includes software developed by Marc Horowitz.
20 * 4. The name of the author may not be used to endorse or promote products
21 *    derived from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35#include <sys/param.h>
36#include <sys/systm.h>
37#include <sys/malloc.h>
38#include <sys/module.h>
39#include <sys/kernel.h>
40#include <sys/queue.h>
41#include <sys/types.h>
42
43#include <sys/bus.h>
44#include <machine/bus.h>
45#include <sys/rman.h>
46#include <machine/resource.h>
47
48#include <dev/pccard/pccarddevs.h>
49#include <dev/pccard/pccardreg.h>
50#include <dev/pccard/pccardchip.h>
51#include <dev/pccard/pccardvar.h>
52
53/* There are cards out there whose CIS flat-out lies.  This file
54   contains struct pccard_function chains for those devices. */
55
56/* these structures are just static templates which are then copied
57   into "live" allocated structures */
58
59struct pccard_function pccard_3cxem556_func0 = {
60	0,			/* function number */
61	PCCARD_FUNCTION_NETWORK,
62	0x07,			/* last cfe number */
63	0x800,			/* ccr_base */
64	0x63,			/* ccr_mask */
65};
66
67struct pccard_config_entry pccard_3cxem556_func0_cfe0 = {
68	0x07,			/* cfe number */
69	PCCARD_CFE_IO8 | PCCARD_CFE_IO16 | PCCARD_CFE_IRQLEVEL,
70	PCCARD_IFTYPE_IO,
71	1,			/* num_iospace */
72	4,			/* iomask */
73	{ { 0x0010, 0 } },	/* iospace */
74	0xffff,			/* irqmask */
75	0,			/* num_memspace */
76	{ },			/* memspace */
77	0,			/* maxtwins */
78};
79
80static struct pccard_function pccard_3cxem556_func1 = {
81	1,			/* function number */
82	PCCARD_FUNCTION_SERIAL,
83	0x27,			/* last cfe number */
84	0x900,			/* ccr_base */
85	0x63,			/* ccr_mask */
86};
87
88static struct pccard_config_entry pccard_3cxem556_func1_cfe0 = {
89	0x27,			/* cfe number */
90	PCCARD_CFE_IO8 | PCCARD_CFE_IRQLEVEL,
91	PCCARD_IFTYPE_IO,
92	1,			/* num_iospace */
93	3,			/* iomask */
94	{ { 0x0008, 0 } },	/* iospace */
95	0xffff,			/* irqmask */
96	0,			/* num_memspace */
97	{ },			/* memspace */
98	0,			/* maxtwins */
99};
100
101static struct pccard_function pccard_sveclancard_func0 = {
102	0,			/* function number */
103	PCCARD_FUNCTION_NETWORK,
104	0x1,			/* last cfe number */
105	0x100,			/* ccr_base */
106	0x1,			/* ccr_mask */
107};
108
109static struct pccard_config_entry pccard_sveclancard_func0_cfe0 = {
110	0x1,			/* cfe number */
111	PCCARD_CFE_MWAIT_REQUIRED | PCCARD_CFE_RDYBSY_ACTIVE |
112	PCCARD_CFE_WP_ACTIVE | PCCARD_CFE_BVD_ACTIVE | PCCARD_CFE_IO16,
113	PCCARD_IFTYPE_IO,
114	1,			/* num_iospace */
115	5,			/* iomask */
116	{ { 0x20, 0x300 } },	/* iospace */
117	0xdeb8,			/* irqmask */
118	0,			/* num_memspace */
119	{ },			/* memspace */
120	0,			/* maxtwins */
121};
122
123static struct pccard_cis_quirk pccard_cis_quirks[] = {
124	{ PCCARD_VENDOR_3COM, PCCARD_PRODUCT_3COM_3CXEM556, PCCARD_CIS_INVALID,
125	  &pccard_3cxem556_func0, &pccard_3cxem556_func0_cfe0 },
126	{ PCCARD_VENDOR_3COM, PCCARD_PRODUCT_3COM_3CXEM556, PCCARD_CIS_INVALID,
127	  &pccard_3cxem556_func1, &pccard_3cxem556_func1_cfe0 },
128	{ PCCARD_VENDOR_INVALID, PCCARD_PRODUCT_INVALID, PCCARD_CIS_SVEC_LANCARD,
129	  &pccard_sveclancard_func0, &pccard_sveclancard_func0_cfe0 },
130};
131
132static int n_pccard_cis_quirks =
133	sizeof(pccard_cis_quirks)/sizeof(pccard_cis_quirks[0]);
134
135void pccard_check_cis_quirks(device_t dev)
136{
137	struct pccard_softc *sc = (struct pccard_softc *)
138	    device_get_softc(dev);
139	int wiped = 0;
140	int i, j;
141	struct pccard_function *pf, *pf_next, *pf_last;
142	struct pccard_config_entry *cfe, *cfe_next;
143
144	pf = NULL;
145	pf_last = NULL;
146
147	for (i=0; i<n_pccard_cis_quirks; i++) {
148		if ((sc->card.manufacturer == pccard_cis_quirks[i].manufacturer) &&
149			(sc->card.product == pccard_cis_quirks[i].product) &&
150			(((sc->card.manufacturer != PCCARD_VENDOR_INVALID) &&
151			  (sc->card.product != PCCARD_PRODUCT_INVALID)) ||
152			 ((sc->card.manufacturer == PCCARD_VENDOR_INVALID) &&
153			  (sc->card.product == PCCARD_PRODUCT_INVALID) &&
154			  sc->card.cis1_info[0] &&
155			  (strcmp(sc->card.cis1_info[0],
156					  pccard_cis_quirks[i].cis1_info[0]) == 0) &&
157			  sc->card.cis1_info[1] &&
158			  (strcmp(sc->card.cis1_info[1],
159					  pccard_cis_quirks[i].cis1_info[1]) == 0)))) {
160			if (!wiped) {
161				if (pccard_verbose) {
162					device_printf(dev, "using CIS quirks for ");
163					for (j = 0; j < 4; j++) {
164						if (sc->card.cis1_info[j] == NULL)
165							break;
166						if (j)
167							printf(", ");
168						printf("%s", sc->card.cis1_info[j]);
169					}
170					printf("\n");
171				}
172
173				for (pf = STAILQ_FIRST(&sc->card.pf_head); pf != NULL;
174				     pf = pf_next) {
175					for (cfe = STAILQ_FIRST(&pf->cfe_head); cfe != NULL;
176					     cfe = cfe_next) {
177						cfe_next = STAILQ_NEXT(cfe, cfe_list);
178						free(cfe, M_DEVBUF);
179					}
180					pf_next = STAILQ_NEXT(pf, pf_list);
181					free(pf, M_DEVBUF);
182				}
183
184				STAILQ_INIT(&sc->card.pf_head);
185				wiped = 1;
186			}
187
188			if (pf_last == pccard_cis_quirks[i].pf) {
189				cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT);
190				*cfe = *pccard_cis_quirks[i].cfe;
191
192				STAILQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list);
193			} else {
194				pf = malloc(sizeof(*pf), M_DEVBUF, M_NOWAIT);
195				*pf = *pccard_cis_quirks[i].pf;
196				STAILQ_INIT(&pf->cfe_head);
197
198				cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT);
199				*cfe = *pccard_cis_quirks[i].cfe;
200
201				STAILQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list);
202				STAILQ_INSERT_TAIL(&sc->card.pf_head, pf, pf_list);
203
204				pf_last = pccard_cis_quirks[i].pf;
205			}
206		}
207	}
208}
209