xref: /openbsd/sys/dev/pcmcia/pcmcia_cis_quirks.c (revision 78b63d65)
1 /*	$OpenBSD: pcmcia_cis_quirks.c,v 1.5 2001/05/24 04:09:47 angelos Exp $	*/
2 /*	$NetBSD: pcmcia_cis_quirks.c,v 1.3 1998/12/29 09:00:28 marc Exp $	*/
3 
4 /*
5  * Copyright (c) 1998 Marc Horowitz.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *	This product includes software developed by Marc Horowitz.
18  * 4. The name of the author may not be used to endorse or promote products
19  *    derived from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #include <sys/types.h>
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/device.h>
37 #include <sys/mbuf.h>
38 
39 #include <dev/pcmcia/pcmciadevs.h>
40 #include <dev/pcmcia/pcmciareg.h>
41 #include <dev/pcmcia/pcmciachip.h>
42 #include <dev/pcmcia/pcmciavar.h>
43 
44 /* There are cards out there whose CIS flat-out lies.  This file
45    contains struct pcmcia_function chains for those devices. */
46 
47 /* these structures are just static templates which are then copied
48    into "live" allocated structures */
49 
50 struct pcmcia_function pcmcia_3cxem556_func0 = {
51 	0,			/* function number */
52 	PCMCIA_FUNCTION_NETWORK,
53 	0x07,			/* last cfe number */
54 	0x800,			/* ccr_base */
55 	0x63,			/* ccr_mask */
56 };
57 
58 struct pcmcia_config_entry pcmcia_3cxem556_func0_cfe0 = {
59 	0x07,			/* cfe number */
60 	PCMCIA_CFE_IO8 | PCMCIA_CFE_IO16 | PCMCIA_CFE_IRQLEVEL,
61 	PCMCIA_IFTYPE_IO,
62 	1,			/* num_iospace */
63 	4,			/* iomask */
64 	{ { 0x0010, 0 } },	/* iospace */
65 	0xffff,			/* irqmask */
66 	0,			/* num_memspace */
67 	{ },			/* memspace */
68 	0,			/* maxtwins */
69 };
70 
71 static struct pcmcia_function pcmcia_3cxem556_func1 = {
72 	1,			/* function number */
73 	PCMCIA_FUNCTION_SERIAL,
74 	0x27,			/* last cfe number */
75 	0x900,			/* ccr_base */
76 	0x63,			/* ccr_mask */
77 };
78 
79 static struct pcmcia_config_entry pcmcia_3cxem556_func1_cfe0 = {
80 	0x27,			/* cfe number */
81 	PCMCIA_CFE_IO8 | PCMCIA_CFE_IRQLEVEL,
82 	PCMCIA_IFTYPE_IO,
83 	1,			/* num_iospace */
84 	3,			/* iomask */
85 	{ { 0x0008, 0 } },	/* iospace */
86 	0xffff,			/* irqmask */
87 	0,			/* num_memspace */
88 	{ },			/* memspace */
89 	0,			/* maxtwins */
90 };
91 
92 struct pcmcia_function pcmcia_megahertz_xjem1144_func0 = {
93 	0,			/* function number */
94 	PCMCIA_FUNCTION_NETWORK,
95 	0x07,			/* last cfe number */
96 	0x200,			/* ccr_base */
97 	0x63,			/* ccr_mask */
98 };
99 
100 struct pcmcia_config_entry pcmcia_megahertz_xjem1144_func0_cfe0 = {
101 	0x07,			/* cfe number */
102 	PCMCIA_CFE_IO8 | PCMCIA_CFE_IO16 | PCMCIA_CFE_IRQLEVEL,
103 	PCMCIA_IFTYPE_IO,
104 	1,			/* num_iospace */
105 	4,			/* iomask */
106 	{ { 0x0010, 0 } },	/* iospace */
107 	0xffff,			/* irqmask */
108 	0,			/* num_memspace */
109 	{ },			/* memspace */
110 	0,			/* maxtwins */
111 };
112 
113 static struct pcmcia_function pcmcia_megahertz_xjem1144_func1 = {
114 	1,			/* function number */
115 	PCMCIA_FUNCTION_SERIAL,
116 	0x35,			/* last cfe number */
117 	0x300,			/* ccr_base */
118 	0x3,			/* ccr_mask */
119 };
120 
121 static struct pcmcia_config_entry pcmcia_megahertz_xjem1144_func1_cfe0 = {
122 	0x35,			/* cfe number */
123 	PCMCIA_CFE_IO8 | PCMCIA_CFE_IRQLEVEL, PCMCIA_IFTYPE_IO,
124 	1,			/* num_iospace */
125 	0,			/* iomask */
126 	{ { 0x0008, 0x2f8 } },	/* iospace */
127 	0xffff,			/* irqmask */
128 	0,			/* num_memspace */
129 	{ },			/* memspace */
130 	0,			/* maxtwins */
131 };
132 
133 static struct pcmcia_function pcmcia_sveclancard_func0 = {
134 	0,			/* function number */
135 	PCMCIA_FUNCTION_NETWORK,
136 	0x1,			/* last cfe number */
137 	0x100,			/* ccr_base */
138 	0x1,			/* ccr_mask */
139 };
140 
141 static struct pcmcia_config_entry pcmcia_sveclancard_func0_cfe0 = {
142 	0x1,			/* cfe number */
143 	PCMCIA_CFE_MWAIT_REQUIRED | PCMCIA_CFE_RDYBSY_ACTIVE |
144 	PCMCIA_CFE_WP_ACTIVE | PCMCIA_CFE_BVD_ACTIVE | PCMCIA_CFE_IO16,
145 	PCMCIA_IFTYPE_IO,
146 	1,			/* num_iospace */
147 	5,			/* iomask */
148 	{ { 0x20, 0x300 } },	/* iospace */
149 	0xdeb8,			/* irqmask */
150 	0,			/* num_memspace */
151 	{ },			/* memspace */
152 	0,			/* maxtwins */
153 };
154 
155 static struct pcmcia_cis_quirk pcmcia_cis_quirks[] = {
156 	{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556, PCMCIA_CIS_INVALID,
157 	  &pcmcia_3cxem556_func0, &pcmcia_3cxem556_func0_cfe0 },
158 	{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556, PCMCIA_CIS_INVALID,
159 	  &pcmcia_3cxem556_func1, &pcmcia_3cxem556_func1_cfe0 },
160 	{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556B,
161 	  PCMCIA_CIS_INVALID,
162 	  &pcmcia_3cxem556_func0, &pcmcia_3cxem556_func0_cfe0 },
163 	{ PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556B,
164 	  PCMCIA_CIS_INVALID,
165 	  &pcmcia_3cxem556_func1, &pcmcia_3cxem556_func1_cfe0 },
166 	{ PCMCIA_VENDOR_MEGAHERTZ2, PCMCIA_PRODUCT_MEGAHERTZ2_XJEM1144,
167 	  PCMCIA_CIS_INVALID,
168 	  &pcmcia_megahertz_xjem1144_func0,
169 	  &pcmcia_megahertz_xjem1144_func0_cfe0 },
170 	{ PCMCIA_VENDOR_MEGAHERTZ2, PCMCIA_PRODUCT_MEGAHERTZ2_XJEM1144,
171 	  PCMCIA_CIS_INVALID,
172 	  &pcmcia_megahertz_xjem1144_func1,
173 	  &pcmcia_megahertz_xjem1144_func1_cfe0 },
174 	{ PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
175 	  PCMCIA_CIS_SVEC_LANCARD,
176 	  &pcmcia_sveclancard_func0, &pcmcia_sveclancard_func0_cfe0 },
177 };
178 
179 void pcmcia_check_cis_quirks(sc)
180 	struct pcmcia_softc *sc;
181 {
182 	int wiped = 0;
183 	int i, j;
184 	struct pcmcia_function *pf, *pf_next, *pf_last;
185 	struct pcmcia_config_entry *cfe, *cfe_next;
186 
187 	pf = NULL;
188 	pf_last = NULL;
189 
190 
191 	for (i = 0; i < sizeof(pcmcia_cis_quirks)/sizeof(pcmcia_cis_quirks[0]);
192 	    i++) {
193 		if ((sc->card.manufacturer == pcmcia_cis_quirks[i].manufacturer) &&
194 			(sc->card.product == pcmcia_cis_quirks[i].product) &&
195 			(((sc->card.manufacturer != PCMCIA_VENDOR_INVALID) &&
196 			  (sc->card.product != PCMCIA_PRODUCT_INVALID)) ||
197 			 ((sc->card.manufacturer == PCMCIA_VENDOR_INVALID) &&
198 			  (sc->card.product == PCMCIA_PRODUCT_INVALID) &&
199 			  sc->card.cis1_info[0] &&
200 			  (strcmp(sc->card.cis1_info[0],
201 					  pcmcia_cis_quirks[i].cis1_info[0]) == 0) &&
202 			  sc->card.cis1_info[1] &&
203 			  (strcmp(sc->card.cis1_info[1],
204 					  pcmcia_cis_quirks[i].cis1_info[1]) == 0)))) {
205 			if (!wiped) {
206 				if (pcmcia_verbose) {
207 					printf("%s: using CIS quirks for ", sc->dev.dv_xname);
208 					for (j = 0; j < 4; j++) {
209 						if (sc->card.cis1_info[j] == NULL)
210 							break;
211 						if (j)
212 							printf(", ");
213 						printf("%s", sc->card.cis1_info[j]);
214 					}
215 					printf("\n");
216 				}
217 
218 				for (pf = SIMPLEQ_FIRST(&sc->card.pf_head); pf != NULL;
219 				     pf = pf_next) {
220 					for (cfe = SIMPLEQ_FIRST(&pf->cfe_head); cfe != NULL;
221 					     cfe = cfe_next) {
222 						cfe_next = SIMPLEQ_NEXT(cfe, cfe_list);
223 						free(cfe, M_DEVBUF);
224 					}
225 					pf_next = SIMPLEQ_NEXT(pf, pf_list);
226 					free(pf, M_DEVBUF);
227 				}
228 
229 				SIMPLEQ_INIT(&sc->card.pf_head);
230 				wiped = 1;
231 			}
232 
233 			if (pf_last == pcmcia_cis_quirks[i].pf) {
234 				cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT);
235 				if (cfe == NULL)
236 					return;
237 				*cfe = *pcmcia_cis_quirks[i].cfe;
238 
239 				SIMPLEQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list);
240 			} else {
241 				pf = malloc(sizeof(*pf), M_DEVBUF, M_NOWAIT);
242 				if (pf == NULL)
243 					return;
244 				*pf = *pcmcia_cis_quirks[i].pf;
245 				SIMPLEQ_INIT(&pf->cfe_head);
246 
247 				cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT);
248 				if (cfe == NULL)
249 					return;
250 				*cfe = *pcmcia_cis_quirks[i].cfe;
251 
252 				SIMPLEQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list);
253 				SIMPLEQ_INSERT_TAIL(&sc->card.pf_head, pf, pf_list);
254 
255 				pf_last = pcmcia_cis_quirks[i].pf;
256 			}
257 		}
258 	}
259 }
260