]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - sys/dev/pccard/pccard_cis_quirks.c
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / sys / dev / pccard / pccard_cis_quirks.c
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$");
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/malloc.h>
40 #include <sys/systm.h>
41
42 #include <machine/bus.h>
43
44 #include <dev/pccard/pccard_cis.h>
45 #include <dev/pccard/pccardvar.h>
46 #include <dev/pccard/pccardvarp.h>
47
48 #include "pccarddevs.h"
49
50 /* There are cards out there whose CIS flat-out lies.  This file
51    contains struct pccard_function chains for those devices. */
52
53 /* these structures are just static templates which are then copied
54    into "live" allocated structures */
55
56 struct pccard_function pccard_3cxem556_func0 = {
57         0,                      /* function number */
58         PCCARD_FUNCTION_NETWORK,
59         0x07,                   /* last cfe number */
60         0x800,                  /* ccr_base */
61         0x63,                   /* ccr_mask */
62 };
63
64 struct pccard_config_entry pccard_3cxem556_func0_cfe0 = {
65         0x07,                   /* cfe number */
66         PCCARD_CFE_IO8 | PCCARD_CFE_IO16 | PCCARD_CFE_IRQLEVEL,
67         PCCARD_IFTYPE_IO,
68         1,                      /* num_iospace */
69         4,                      /* iomask */
70         { { 0x0010, 0 } },      /* iospace */
71         0xffff,                 /* irqmask */
72         0,                      /* num_memspace */
73         { },                    /* memspace */
74         0,                      /* maxtwins */
75 };
76
77 static struct pccard_function pccard_3cxem556_func1 = {
78         1,                      /* function number */
79         PCCARD_FUNCTION_SERIAL,
80         0x27,                   /* last cfe number */
81         0x900,                  /* ccr_base */
82         0x63,                   /* ccr_mask */
83 };
84
85 static struct pccard_config_entry pccard_3cxem556_func1_cfe0 = {
86         0x27,                   /* cfe number */
87         PCCARD_CFE_IO8 | PCCARD_CFE_IRQLEVEL,
88         PCCARD_IFTYPE_IO,
89         1,                      /* num_iospace */
90         3,                      /* iomask */
91         { { 0x0008, 0 } },      /* iospace */
92         0xffff,                 /* irqmask */
93         0,                      /* num_memspace */
94         { },                    /* memspace */
95         0,                      /* maxtwins */
96 };
97
98 static struct pccard_function pccard_3ccfem556bi_func0 = {
99         0,                      /* function number */
100         PCCARD_FUNCTION_NETWORK,
101         0x07,                   /* last cfe number */
102         0x1000,                 /* ccr_base */
103         0x267,                  /* ccr_mask */
104 };
105
106 static struct pccard_config_entry pccard_3ccfem556bi_func0_cfe0 = {
107         0x07,                   /* cfe number */
108         PCCARD_CFE_IO8 | PCCARD_CFE_IO16 | PCCARD_CFE_IRQLEVEL,
109         PCCARD_IFTYPE_IO,
110         1,                      /* num_iospace */
111         5,                      /* iomask */
112         { { 0x0020, 0 } },      /* iospace */
113         0xffff,                 /* irqmask */
114         0,                      /* num_memspace */
115         { },                    /* memspace */
116         0,                      /* maxtwins */
117 };
118
119 static struct pccard_function pccard_3ccfem556bi_func1 = {
120         1,                      /* function number */
121         PCCARD_FUNCTION_SERIAL,
122         0x27,                   /* last cfe number */
123         0x1100,                 /* ccr_base */
124         0x277,                  /* ccr_mask */
125 };
126
127 static struct pccard_config_entry pccard_3ccfem556bi_func1_cfe0 = {
128         0x27,                   /* cfe number */
129         PCCARD_CFE_IO8 | PCCARD_CFE_IRQLEVEL,
130         PCCARD_IFTYPE_IO,
131         1,                      /* num_iospace */
132         3,                      /* iomask */
133         { { 0x0008, 0 } },      /* iospace */
134         0xffff,                 /* irqmask */
135         0,                      /* num_memspace */
136         { },                    /* memspace */
137         0,                      /* maxtwins */
138 };
139
140 static struct pccard_function pccard_3c1_func0 = {
141         0,                      /* function number */
142         PCCARD_FUNCTION_NETWORK,
143         0x05,                   /* last cfe number */
144         0x400,                  /* ccr_base */
145         0x267,                  /* ccr_mask */
146 };
147
148 static struct pccard_config_entry pccard_3c1_func0_cfe0 = {
149         0x05,                   /* cfe number */
150         PCCARD_CFE_IO8 | PCCARD_CFE_IO16 | PCCARD_CFE_IRQLEVEL,
151         PCCARD_IFTYPE_IO,
152         1,                      /* num_iospace */
153         5,                      /* iomask */
154         { { 0x0010, 0 } },      /* iospace */
155         0xffff,                 /* irqmask */
156         0,                      /* num_memspace */
157         { },                    /* memspace */
158         0,                      /* maxtwins */
159 };
160
161 static struct pccard_function pccard_sveclancard_func0 = {
162         0,                      /* function number */
163         PCCARD_FUNCTION_NETWORK,
164         0x1,                    /* last cfe number */
165         0x100,                  /* ccr_base */
166         0x1,                    /* ccr_mask */
167 };
168
169 static struct pccard_config_entry pccard_sveclancard_func0_cfe0 = {
170         0x1,                    /* cfe number */
171         PCCARD_CFE_MWAIT_REQUIRED | PCCARD_CFE_RDYBSY_ACTIVE |
172         PCCARD_CFE_WP_ACTIVE | PCCARD_CFE_BVD_ACTIVE | PCCARD_CFE_IO16,
173         PCCARD_IFTYPE_IO,
174         1,                      /* num_iospace */
175         5,                      /* iomask */
176         { { 0x20, 0x300 } },    /* iospace */
177         0xdeb8,                 /* irqmask */
178         0,                      /* num_memspace */
179         { },                    /* memspace */
180         0,                      /* maxtwins */
181 };
182
183 static struct pccard_function pccard_ndc_nd5100_func0 = {
184         0,                      /* function number */
185         PCCARD_FUNCTION_NETWORK,
186         0x23,                   /* last cfe number */
187         0x3f8,                  /* ccr_base */
188         0x3,                    /* ccr_mask */
189 };
190
191 static struct pccard_config_entry pccard_ndc_nd5100_func0_cfe0 = {
192         0x20,                   /* cfe number */
193         PCCARD_CFE_MWAIT_REQUIRED | PCCARD_CFE_IO16 | PCCARD_CFE_IRQLEVEL,
194         PCCARD_IFTYPE_IO,
195         1,                      /* num_iospace */
196         5,                      /* iomask */
197         { { 0x20, 0x300 } },    /* iospace */
198         0xdeb8,                 /* irqmask */
199         0,                      /* num_memspace */
200         { },                    /* memspace */
201         0,                      /* maxtwins */
202 };
203
204 static struct pccard_function pccard_sierra_a555_func1 = {
205         1,                      /* function number */
206         PCCARD_FUNCTION_SERIAL,
207         0x24,                   /* last cfe number */
208         0x700,                  /* ccr_base */
209         0x73,                   /* ccr_mask */
210 };
211
212 static struct pccard_config_entry pccard_sierra_a555_func1_cfe0 = {
213         0x22,                   /* cfe number */
214         PCCARD_CFE_IO8 | PCCARD_CFE_IRQLEVEL, 
215         PCCARD_IFTYPE_IO,
216         1,                      /* num_iospace */
217         0,                      /* iomask */
218         { { 0x0008, 0x3e8 } },  /* iospace */
219         0x3fbc,                 /* irqmask */
220         0,                      /* num_memspace */
221         { },                    /* memspace */
222         0,                      /* maxtwins */
223 };
224
225 static struct pccard_cis_quirk pccard_cis_quirks[] = {
226         { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556, PCMCIA_CIS_INVALID, 
227           &pccard_3cxem556_func0, &pccard_3cxem556_func0_cfe0 },
228         { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556, PCMCIA_CIS_INVALID,
229           &pccard_3cxem556_func1, &pccard_3cxem556_func1_cfe0 },
230         { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556INT, PCMCIA_CIS_INVALID, 
231           &pccard_3cxem556_func0, &pccard_3cxem556_func0_cfe0 },
232         { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CXEM556INT, PCMCIA_CIS_INVALID,
233           &pccard_3cxem556_func1, &pccard_3cxem556_func1_cfe0 },
234         { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CCFEM556BI,
235           PCMCIA_CIS_INVALID,
236           &pccard_3ccfem556bi_func0, &pccard_3ccfem556bi_func0_cfe0 },
237         { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CCFEM556BI,
238           PCMCIA_CIS_INVALID,
239           &pccard_3ccfem556bi_func1, &pccard_3ccfem556bi_func1_cfe0 },
240         { PCMCIA_VENDOR_SIERRA, PCMCIA_PRODUCT_SIERRA_A550,
241           PCMCIA_CIS_INVALID,
242           &pccard_sierra_a555_func1, &pccard_sierra_a555_func1_cfe0 },
243         { PCMCIA_VENDOR_SIERRA, PCMCIA_PRODUCT_SIERRA_A555,
244           PCMCIA_CIS_INVALID,
245           &pccard_sierra_a555_func1, &pccard_sierra_a555_func1_cfe0 },
246         { PCMCIA_VENDOR_SIERRA, PCMCIA_PRODUCT_SIERRA_A710,
247           PCMCIA_CIS_INVALID,
248           &pccard_sierra_a555_func1, &pccard_sierra_a555_func1_cfe0 },
249         { PCMCIA_VENDOR_SIERRA, PCMCIA_PRODUCT_SIERRA_AC710,
250           PCMCIA_CIS_INVALID,
251           &pccard_sierra_a555_func1, &pccard_sierra_a555_func1_cfe0 },
252         { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3C1, PCMCIA_CIS_INVALID,
253           &pccard_3c1_func0, &pccard_3c1_func0_cfe0 },
254         { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, PCMCIA_CIS_SVEC_LANCARD,
255           &pccard_sveclancard_func0, &pccard_sveclancard_func0_cfe0 },
256         { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID, PCMCIA_CIS_NDC_ND5100_E,
257           &pccard_ndc_nd5100_func0, &pccard_ndc_nd5100_func0_cfe0 },
258 };
259         
260 static int n_pccard_cis_quirks =
261         sizeof(pccard_cis_quirks)/sizeof(pccard_cis_quirks[0]);
262
263 static int
264 pccard_cis_quirk_match(struct pccard_softc *sc, struct pccard_cis_quirk *q)
265 {
266         if ((sc->card.manufacturer == q->manufacturer) &&
267                 (sc->card.product == q->product) &&
268                 (((sc->card.manufacturer != PCMCIA_VENDOR_INVALID) &&
269                   (sc->card.product != PCMCIA_PRODUCT_INVALID)) ||
270                  ((sc->card.manufacturer == PCMCIA_VENDOR_INVALID) &&
271                   (sc->card.product == PCMCIA_PRODUCT_INVALID) &&
272                   sc->card.cis1_info[0] &&
273                   (strcmp(sc->card.cis1_info[0], q->cis1_info[0]) == 0) &&
274                   sc->card.cis1_info[1] &&
275                   (strcmp(sc->card.cis1_info[1], q->cis1_info[1]) == 0))))
276                 return (1);
277         return (0);
278 }
279
280 void pccard_check_cis_quirks(device_t dev)
281 {
282         struct pccard_softc *sc = PCCARD_SOFTC(dev);
283         int wiped = 0;
284         int i, j;
285         struct pccard_function *pf, *pf_next, *pf_last;
286         struct pccard_config_entry *cfe, *cfe_next;
287         struct pccard_cis_quirk *q;
288
289         pf = NULL;
290         pf_last = NULL;
291
292         for (i=0; i<n_pccard_cis_quirks; i++) {
293                 q = &pccard_cis_quirks[i];
294                 if (!pccard_cis_quirk_match(sc, q))
295                         continue;
296                 if (!wiped) {
297                         if (bootverbose) {
298                                 device_printf(dev, "using CIS quirks for ");
299                                 for (j = 0; j < 4; j++) {
300                                         if (sc->card.cis1_info[j] == NULL)
301                                                 break;
302                                         if (j)
303                                                 printf(", ");
304                                         printf("%s", sc->card.cis1_info[j]);
305                                 }
306                                 printf("\n");
307                         }
308
309                         for (pf = STAILQ_FIRST(&sc->card.pf_head); pf != NULL;
310                              pf = pf_next) {
311                                 for (cfe = STAILQ_FIRST(&pf->cfe_head); cfe != NULL;
312                                      cfe = cfe_next) {
313                                         cfe_next = STAILQ_NEXT(cfe, cfe_list);
314                                         free(cfe, M_DEVBUF);
315                                 }
316                                 pf_next = STAILQ_NEXT(pf, pf_list);
317                                 free(pf, M_DEVBUF);
318                         }
319
320                         STAILQ_INIT(&sc->card.pf_head);
321                         wiped = 1;
322                 }
323
324                 if (pf_last == q->pf) {
325                         cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT);
326                         if (cfe == NULL) {
327                                 device_printf(dev, "no memory for quirk (1)\n");
328                                 continue;
329                         }
330                         *cfe = *q->cfe;
331                         STAILQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list);
332                 } else {
333                         pf = malloc(sizeof(*pf), M_DEVBUF, M_NOWAIT);
334                         if (pf == NULL) {
335                                 device_printf(dev,
336                                         "no memory for pccard function\n");
337                                 continue;
338                         }
339                         *pf = *q->pf;
340                         STAILQ_INIT(&pf->cfe_head);
341                         cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT);
342                         if (cfe == NULL) {
343                                 free(pf, M_DEVBUF);
344                                 device_printf(dev, "no memory for quirk (2)\n");
345                                 continue;
346                         }
347                         *cfe = *q->cfe;
348                         STAILQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list);
349                         STAILQ_INSERT_TAIL(&sc->card.pf_head, pf, pf_list);
350                         pf_last = q->pf;
351                 }
352         }
353 }