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