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