if_wi_pcmcia.c revision 1.86 1 1.86 christos /* $NetBSD: if_wi_pcmcia.c,v 1.86 2010/11/23 04:33:10 christos Exp $ */
2 1.1 ichiro
3 1.1 ichiro /*-
4 1.53 mycroft * Copyright (c) 2001, 2004 The NetBSD Foundation, Inc.
5 1.1 ichiro * All rights reserved.
6 1.1 ichiro *
7 1.1 ichiro * This code is derived from software contributed to The NetBSD Foundation
8 1.53 mycroft * by Ichiro FUKUHARA (ichiro (at) ichiro.org), and by Charles M. Hannum.
9 1.1 ichiro *
10 1.1 ichiro * Redistribution and use in source and binary forms, with or without
11 1.1 ichiro * modification, are permitted provided that the following conditions
12 1.1 ichiro * are met:
13 1.1 ichiro * 1. Redistributions of source code must retain the above copyright
14 1.1 ichiro * notice, this list of conditions and the following disclaimer.
15 1.1 ichiro * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 ichiro * notice, this list of conditions and the following disclaimer in the
17 1.1 ichiro * documentation and/or other materials provided with the distribution.
18 1.1 ichiro *
19 1.1 ichiro * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 ichiro * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 ichiro * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 ichiro * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 ichiro * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 ichiro * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 ichiro * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 ichiro * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 ichiro * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 ichiro * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 ichiro * POSSIBILITY OF SUCH DAMAGE.
30 1.1 ichiro */
31 1.1 ichiro
32 1.1 ichiro /*
33 1.1 ichiro * PCMCIA attachment for Lucent & Intersil WaveLAN PCMCIA card
34 1.1 ichiro */
35 1.12 lukem
36 1.12 lukem #include <sys/cdefs.h>
37 1.86 christos __KERNEL_RCSID(0, "$NetBSD: if_wi_pcmcia.c,v 1.86 2010/11/23 04:33:10 christos Exp $");
38 1.1 ichiro
39 1.1 ichiro #include <sys/param.h>
40 1.1 ichiro #include <sys/systm.h>
41 1.1 ichiro #include <sys/callout.h>
42 1.1 ichiro #include <sys/device.h>
43 1.17 onoe #include <sys/proc.h>
44 1.1 ichiro #include <sys/socket.h>
45 1.1 ichiro
46 1.1 ichiro #include <net/if.h>
47 1.1 ichiro #include <net/if_ether.h>
48 1.1 ichiro #include <net/if_media.h>
49 1.35 dyoung
50 1.66 dyoung #include <net80211/ieee80211_netbsd.h>
51 1.35 dyoung #include <net80211/ieee80211_var.h>
52 1.37 dyoung #include <net80211/ieee80211_radiotap.h>
53 1.38 dyoung #include <net80211/ieee80211_rssadapt.h>
54 1.1 ichiro
55 1.76 ad #include <sys/cpu.h>
56 1.76 ad #include <sys/bus.h>
57 1.76 ad #include <sys/intr.h>
58 1.1 ichiro
59 1.1 ichiro #include <dev/ic/wi_ieee.h>
60 1.1 ichiro #include <dev/ic/wireg.h>
61 1.1 ichiro #include <dev/ic/wivar.h>
62 1.1 ichiro
63 1.1 ichiro #include <dev/pcmcia/pcmciareg.h>
64 1.1 ichiro #include <dev/pcmcia/pcmciavar.h>
65 1.1 ichiro #include <dev/pcmcia/pcmciadevs.h>
66 1.1 ichiro
67 1.80 ad #ifdef _MODULE
68 1.74 dsl #define WI_PCMCIA_SPECTRUM24T_FW 1
69 1.74 dsl #else
70 1.73 dsl #include <opt_if_wi_pcmcia.h>
71 1.74 dsl #endif
72 1.73 dsl
73 1.73 dsl #if WI_PCMCIA_SPECTRUM24T_FW
74 1.17 onoe #include <dev/microcode/wi/spectrum24t_cf.h>
75 1.73 dsl #endif
76 1.17 onoe
77 1.84 cegger static int wi_pcmcia_match(device_t, cfdata_t, void *);
78 1.60 perry static int wi_pcmcia_validate_config(struct pcmcia_config_entry *);
79 1.84 cegger static void wi_pcmcia_attach(device_t, device_t, void *);
80 1.84 cegger static int wi_pcmcia_detach(device_t, int);
81 1.86 christos static int wi_pcmcia_enable(device_t, int);
82 1.1 ichiro
83 1.73 dsl #if WI_PCMCIA_SPECTRUM24T_FW
84 1.17 onoe /* support to download firmware for symbol CF card */
85 1.60 perry static int wi_pcmcia_load_firm(struct wi_softc *, const void *, int, const void *, int);
86 1.60 perry static int wi_pcmcia_write_firm(struct wi_softc *, const void *, int, const void *, int);
87 1.60 perry static int wi_pcmcia_set_hcr(struct wi_softc *, int);
88 1.73 dsl #endif
89 1.17 onoe
90 1.1 ichiro struct wi_pcmcia_softc {
91 1.1 ichiro struct wi_softc sc_wi;
92 1.1 ichiro
93 1.17 onoe int sc_symbol_cf; /* Spectrum24t CF card */
94 1.52 mycroft
95 1.52 mycroft struct pcmcia_function *sc_pf; /* PCMCIA function */
96 1.52 mycroft int sc_state;
97 1.52 mycroft #define WI_PCMCIA_ATTACHED 3
98 1.1 ichiro };
99 1.1 ichiro
100 1.86 christos CFATTACH_DECL_NEW(wi_pcmcia, sizeof(struct wi_pcmcia_softc),
101 1.29 thorpej wi_pcmcia_match, wi_pcmcia_attach, wi_pcmcia_detach, wi_activate);
102 1.1 ichiro
103 1.56 mycroft static const struct pcmcia_product wi_pcmcia_products[] = {
104 1.47 mycroft { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
105 1.42 mycroft PCMCIA_CIS_SMC_2632W },
106 1.42 mycroft
107 1.47 mycroft { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
108 1.42 mycroft PCMCIA_CIS_NANOSPEED_PRISM2 },
109 1.42 mycroft
110 1.47 mycroft { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
111 1.42 mycroft PCMCIA_CIS_NEC_CMZ_RT_WP },
112 1.42 mycroft
113 1.47 mycroft { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
114 1.42 mycroft PCMCIA_CIS_NTT_ME_WLAN },
115 1.42 mycroft
116 1.47 mycroft { PCMCIA_VENDOR_LUCENT, PCMCIA_PRODUCT_LUCENT_HERMES,
117 1.47 mycroft PCMCIA_CIS_INVALID },
118 1.47 mycroft
119 1.47 mycroft { PCMCIA_VENDOR_LUCENT, PCMCIA_PRODUCT_LUCENT_HERMES2,
120 1.47 mycroft PCMCIA_CIS_INVALID },
121 1.42 mycroft
122 1.42 mycroft { PCMCIA_VENDOR_3COM, PCMCIA_PRODUCT_3COM_3CRWE737A,
123 1.42 mycroft PCMCIA_CIS_3COM_3CRWE737A },
124 1.42 mycroft
125 1.67 dyoung { PCMCIA_VENDOR_ALVARION,
126 1.67 dyoung PCMCIA_PRODUCT_ALVARION_BREEZENET,
127 1.67 dyoung PCMCIA_CIS_ALVARION_BREEZENET },
128 1.67 dyoung
129 1.42 mycroft { PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_WIRELESS_LAN_PCC_11,
130 1.42 mycroft PCMCIA_CIS_COREGA_WIRELESS_LAN_PCC_11 },
131 1.42 mycroft
132 1.42 mycroft { PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_WIRELESS_LAN_PCCA_11,
133 1.42 mycroft PCMCIA_CIS_COREGA_WIRELESS_LAN_PCCA_11 },
134 1.42 mycroft
135 1.42 mycroft { PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_WIRELESS_LAN_PCCB_11,
136 1.42 mycroft PCMCIA_CIS_COREGA_WIRELESS_LAN_PCCB_11 },
137 1.42 mycroft
138 1.42 mycroft { PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_WIRELESS_LAN_PCCL_11,
139 1.42 mycroft PCMCIA_CIS_COREGA_WIRELESS_LAN_PCCL_11 },
140 1.42 mycroft
141 1.42 mycroft { PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_WIRELESS_LAN_WLCFL_11,
142 1.42 mycroft PCMCIA_CIS_COREGA_WIRELESS_LAN_WLCFL_11 },
143 1.42 mycroft
144 1.42 mycroft { PCMCIA_VENDOR_INTEL, PCMCIA_PRODUCT_INTEL_PRO_WLAN_2011,
145 1.42 mycroft PCMCIA_CIS_INTEL_PRO_WLAN_2011 },
146 1.42 mycroft
147 1.59 imp { PCMCIA_VENDOR_INTERSIL2, PCMCIA_PRODUCT_INTERSIL2_PRISM2,
148 1.59 imp PCMCIA_CIS_INTERSIL2_PRISM2 },
149 1.42 mycroft
150 1.59 imp { PCMCIA_VENDOR_INTERSIL2, PCMCIA_PRODUCT_GEMTEK_WLAN,
151 1.42 mycroft PCMCIA_CIS_GEMTEK_WLAN },
152 1.42 mycroft
153 1.42 mycroft { PCMCIA_VENDOR_SAMSUNG, PCMCIA_PRODUCT_SAMSUNG_SWL_2000N,
154 1.42 mycroft PCMCIA_CIS_SAMSUNG_SWL_2000N },
155 1.42 mycroft
156 1.42 mycroft { PCMCIA_VENDOR_ELSA, PCMCIA_PRODUCT_ELSA_XI300_IEEE,
157 1.42 mycroft PCMCIA_CIS_ELSA_XI300_IEEE },
158 1.42 mycroft
159 1.42 mycroft { PCMCIA_VENDOR_ELSA, PCMCIA_PRODUCT_ELSA_XI325_IEEE,
160 1.42 mycroft PCMCIA_CIS_ELSA_XI325_IEEE },
161 1.42 mycroft
162 1.42 mycroft { PCMCIA_VENDOR_ELSA, PCMCIA_PRODUCT_ELSA_XI800_IEEE,
163 1.42 mycroft PCMCIA_CIS_ELSA_XI800_IEEE },
164 1.42 mycroft
165 1.64 martin { PCMCIA_VENDOR_ELSA, PCMCIA_PRODUCT_ELSA_SMC2531WB,
166 1.64 martin PCMCIA_CIS_ELSA_SMC2531WB },
167 1.64 martin
168 1.42 mycroft { PCMCIA_VENDOR_COMPAQ, PCMCIA_PRODUCT_COMPAQ_NC5004,
169 1.42 mycroft PCMCIA_CIS_COMPAQ_NC5004 },
170 1.42 mycroft
171 1.42 mycroft { PCMCIA_VENDOR_CONTEC, PCMCIA_PRODUCT_CONTEC_FX_DS110_PCC,
172 1.42 mycroft PCMCIA_CIS_CONTEC_FX_DS110_PCC },
173 1.42 mycroft
174 1.42 mycroft { PCMCIA_VENDOR_TDK, PCMCIA_PRODUCT_TDK_LAK_CD011WL,
175 1.42 mycroft PCMCIA_CIS_TDK_LAK_CD011WL },
176 1.42 mycroft
177 1.42 mycroft { PCMCIA_VENDOR_IODATA2, PCMCIA_PRODUCT_IODATA2_WNB11PCM,
178 1.42 mycroft PCMCIA_CIS_IODATA2_WNB11PCM },
179 1.42 mycroft
180 1.42 mycroft { PCMCIA_VENDOR_IODATA2, PCMCIA_PRODUCT_IODATA2_WCF12,
181 1.42 mycroft PCMCIA_CIS_IODATA2_WCF12 },
182 1.42 mycroft
183 1.42 mycroft { PCMCIA_VENDOR_BUFFALO, PCMCIA_PRODUCT_BUFFALO_WLI_PCM_S11,
184 1.42 mycroft PCMCIA_CIS_BUFFALO_WLI_PCM_S11 },
185 1.42 mycroft
186 1.42 mycroft { PCMCIA_VENDOR_BUFFALO, PCMCIA_PRODUCT_BUFFALO_WLI_CF_S11G,
187 1.42 mycroft PCMCIA_CIS_BUFFALO_WLI_CF_S11G },
188 1.42 mycroft
189 1.42 mycroft { PCMCIA_VENDOR_EMTAC, PCMCIA_PRODUCT_EMTAC_WLAN,
190 1.42 mycroft PCMCIA_CIS_EMTAC_WLAN },
191 1.42 mycroft
192 1.59 imp { PCMCIA_VENDOR_INTERSIL, PCMCIA_PRODUCT_INTERSIL_ISL37100P,
193 1.59 imp PCMCIA_CIS_INTERSIL_ISL37100P },
194 1.59 imp
195 1.59 imp { PCMCIA_VENDOR_INTERSIL, PCMCIA_PRODUCT_INTERSIL_ISL37110P,
196 1.59 imp PCMCIA_CIS_INTERSIL_ISL37110P },
197 1.59 imp
198 1.59 imp { PCMCIA_VENDOR_INTERSIL, PCMCIA_PRODUCT_INTERSIL_ISL37300P,
199 1.59 imp PCMCIA_CIS_INTERSIL_ISL37300P },
200 1.42 mycroft
201 1.45 mycroft { PCMCIA_VENDOR_SIMPLETECH, PCMCIA_PRODUCT_SIMPLETECH_SPECTRUM24,
202 1.45 mycroft PCMCIA_CIS_SIMPLETECH_SPECTRUM24 },
203 1.42 mycroft
204 1.42 mycroft { PCMCIA_VENDOR_ERICSSON, PCMCIA_PRODUCT_ERICSSON_WIRELESSLAN,
205 1.42 mycroft PCMCIA_CIS_ERICSSON_WIRELESSLAN },
206 1.42 mycroft
207 1.42 mycroft { PCMCIA_VENDOR_SYMBOL, PCMCIA_PRODUCT_SYMBOL_LA4100,
208 1.42 mycroft PCMCIA_CIS_SYMBOL_LA4100 },
209 1.42 mycroft
210 1.42 mycroft { PCMCIA_VENDOR_LINKSYS2, PCMCIA_PRODUCT_LINKSYS2_IWN,
211 1.42 mycroft PCMCIA_CIS_NANOSPEED_PRISM2 },
212 1.42 mycroft
213 1.42 mycroft { PCMCIA_VENDOR_LINKSYS2, PCMCIA_PRODUCT_LINKSYS2_IWN3,
214 1.42 mycroft PCMCIA_CIS_LINKSYS2_IWN3 },
215 1.42 mycroft
216 1.42 mycroft { PCMCIA_VENDOR_LINKSYS2, PCMCIA_PRODUCT_LINKSYS2_WCF11,
217 1.42 mycroft PCMCIA_CIS_LINKSYS2_WCF11 },
218 1.42 mycroft
219 1.62 christos { PCMCIA_VENDOR_MICROSOFT, PCMCIA_PRODUCT_MICROSOFT_MN_520,
220 1.62 christos PCMCIA_CIS_MICROSOFT_MN_520 },
221 1.62 christos
222 1.42 mycroft { PCMCIA_VENDOR_PLANEX, PCMCIA_PRODUCT_PLANEX_GWNS11H,
223 1.42 mycroft PCMCIA_CIS_PLANEX_GWNS11H },
224 1.42 mycroft
225 1.42 mycroft { PCMCIA_VENDOR_BAY, PCMCIA_PRODUCT_BAY_EMOBILITY_11B,
226 1.42 mycroft PCMCIA_CIS_BAY_EMOBILITY_11B },
227 1.42 mycroft
228 1.42 mycroft { PCMCIA_VENDOR_ACTIONTEC, PCMCIA_PRODUCT_ACTIONTEC_PRISM,
229 1.42 mycroft PCMCIA_CIS_ACTIONTEC_PRISM },
230 1.42 mycroft
231 1.42 mycroft { PCMCIA_VENDOR_DLINK_2, PCMCIA_PRODUCT_DLINK_DWL650H,
232 1.42 mycroft PCMCIA_CIS_DLINK_DWL650H },
233 1.42 mycroft
234 1.42 mycroft { PCMCIA_VENDOR_FUJITSU, PCMCIA_PRODUCT_FUJITSU_WL110,
235 1.42 mycroft PCMCIA_CIS_FUJITSU_WL110 },
236 1.42 mycroft
237 1.42 mycroft { PCMCIA_VENDOR_ARTEM, PCMCIA_PRODUCT_ARTEM_ONAIR,
238 1.42 mycroft PCMCIA_CIS_ARTEM_ONAIR },
239 1.44 mycroft
240 1.44 mycroft { PCMCIA_VENDOR_ASUSTEK, PCMCIA_PRODUCT_ASUSTEK_WL_100,
241 1.44 mycroft PCMCIA_CIS_ASUSTEK_WL_100 },
242 1.63 martin
243 1.63 martin { PCMCIA_VENDOR_PROXIM, PCMCIA_PRODUCT_PROXIM_RANGELANDS_8430,
244 1.63 martin PCMCIA_CIS_PROXIM_RANGELANDS_8430 },
245 1.69 scottr
246 1.69 scottr { PCMCIA_VENDOR_SIEMENS, PCMCIA_PRODUCT_SIEMENS_SS1021,
247 1.69 scottr PCMCIA_CIS_SIEMENS_SS1021 },
248 1.1 ichiro };
249 1.56 mycroft static const size_t wi_pcmcia_nproducts =
250 1.56 mycroft sizeof(wi_pcmcia_products) / sizeof(wi_pcmcia_products[0]);
251 1.1 ichiro
252 1.1 ichiro static int
253 1.86 christos wi_pcmcia_match(device_t parent, cfdata_t match, void *aux)
254 1.1 ichiro {
255 1.1 ichiro struct pcmcia_attach_args *pa = aux;
256 1.1 ichiro
257 1.56 mycroft if (pcmcia_product_lookup(pa, wi_pcmcia_products, wi_pcmcia_nproducts,
258 1.56 mycroft sizeof(wi_pcmcia_products[0]), NULL))
259 1.1 ichiro return (1);
260 1.1 ichiro return (0);
261 1.1 ichiro }
262 1.1 ichiro
263 1.1 ichiro static int
264 1.86 christos wi_pcmcia_enable(device_t self, int onoff)
265 1.1 ichiro {
266 1.86 christos struct wi_pcmcia_softc *psc = device_private(self);
267 1.86 christos struct wi_softc *sc = &psc->sc_wi;
268 1.1 ichiro struct pcmcia_function *pf = psc->sc_pf;
269 1.54 mycroft int error;
270 1.1 ichiro
271 1.86 christos if (onoff) {
272 1.86 christos /* establish the interrupt. */
273 1.86 christos sc->sc_ih = pcmcia_intr_establish(pf, IPL_NET, wi_intr, sc);
274 1.86 christos if (!sc->sc_ih)
275 1.86 christos return EIO;
276 1.86 christos
277 1.86 christos error = pcmcia_function_enable(pf);
278 1.86 christos if (error) {
279 1.86 christos pcmcia_intr_disestablish(pf, sc->sc_ih);
280 1.86 christos sc->sc_ih = 0;
281 1.86 christos return EIO;
282 1.86 christos }
283 1.54 mycroft
284 1.86 christos if (psc->sc_symbol_cf) {
285 1.73 dsl #if WI_PCMCIA_SPECTRUM24T_FW
286 1.86 christos if (wi_pcmcia_load_firm(sc,
287 1.86 christos spectrum24t_primsym, sizeof(spectrum24t_primsym),
288 1.86 christos spectrum24t_secsym, sizeof(spectrum24t_secsym))) {
289 1.86 christos aprint_error_dev(sc->sc_dev,
290 1.86 christos "couldn't load firmware\n");
291 1.86 christos wi_pcmcia_enable(self, 0);
292 1.86 christos return EIO;
293 1.86 christos }
294 1.73 dsl #else
295 1.86 christos aprint_error_dev(sc->sc_dev,
296 1.86 christos "firmware load not configured\n");
297 1.86 christos return EIO;
298 1.73 dsl #endif
299 1.86 christos }
300 1.86 christos DELAY(1000);
301 1.86 christos } else {
302 1.86 christos pcmcia_function_disable(psc->sc_pf);
303 1.86 christos pcmcia_intr_disestablish(psc->sc_pf, sc->sc_ih);
304 1.86 christos sc->sc_ih = 0;
305 1.17 onoe }
306 1.58 mycroft
307 1.86 christos return 0;
308 1.1 ichiro }
309 1.1 ichiro
310 1.52 mycroft static int
311 1.81 dsl wi_pcmcia_validate_config(struct pcmcia_config_entry *cfe)
312 1.52 mycroft {
313 1.52 mycroft if (cfe->iftype != PCMCIA_IFTYPE_IO ||
314 1.52 mycroft cfe->num_iospace != 1 ||
315 1.52 mycroft cfe->iospace[0].length < WI_IOSIZE)
316 1.52 mycroft return (EINVAL);
317 1.52 mycroft cfe->num_memspace = 0;
318 1.52 mycroft return (0);
319 1.52 mycroft }
320 1.52 mycroft
321 1.1 ichiro static void
322 1.86 christos wi_pcmcia_attach(device_t parent, device_t self, void *aux)
323 1.1 ichiro {
324 1.86 christos struct wi_pcmcia_softc *psc = device_private(self);
325 1.1 ichiro struct wi_softc *sc = &psc->sc_wi;
326 1.1 ichiro struct pcmcia_attach_args *pa = aux;
327 1.1 ichiro struct pcmcia_config_entry *cfe;
328 1.47 mycroft int haveaddr;
329 1.52 mycroft int error;
330 1.1 ichiro
331 1.75 uwe aprint_naive("\n");
332 1.75 uwe
333 1.86 christos sc->sc_dev = self;
334 1.1 ichiro psc->sc_pf = pa->pf;
335 1.1 ichiro
336 1.52 mycroft error = pcmcia_function_configure(pa->pf, wi_pcmcia_validate_config);
337 1.52 mycroft if (error) {
338 1.78 cegger aprint_error_dev(self, "configure failed, error=%d\n",
339 1.52 mycroft error);
340 1.52 mycroft return;
341 1.1 ichiro }
342 1.1 ichiro
343 1.52 mycroft cfe = pa->pf->cfe;
344 1.52 mycroft sc->sc_iot = cfe->iospace[0].handle.iot;
345 1.52 mycroft sc->sc_ioh = cfe->iospace[0].handle.ioh;
346 1.50 mycroft
347 1.56 mycroft if (pa->manufacturer == PCMCIA_VENDOR_SYMBOL &&
348 1.56 mycroft pa->product == PCMCIA_PRODUCT_SYMBOL_LA4100)
349 1.17 onoe psc->sc_symbol_cf = 1;
350 1.30 onoe /*
351 1.30 onoe * XXX: Sony PEGA-WL100 CF card has a same vendor/product id as
352 1.30 onoe * Intel PCMCIA card. It may be incorrect to detect by the
353 1.30 onoe * initial value of COR register.
354 1.30 onoe */
355 1.56 mycroft if (pa->manufacturer == PCMCIA_VENDOR_INTEL &&
356 1.56 mycroft pa->product == PCMCIA_PRODUCT_INTEL_PRO_WLAN_2011 &&
357 1.30 onoe CSR_READ_2(sc, WI_COR) == WI_COR_IOMODE)
358 1.30 onoe psc->sc_symbol_cf = 1;
359 1.30 onoe
360 1.86 christos error = wi_pcmcia_enable(self, 1);
361 1.54 mycroft if (error)
362 1.52 mycroft goto fail;
363 1.61 perry
364 1.50 mycroft sc->sc_pci = 0;
365 1.50 mycroft sc->sc_enable = wi_pcmcia_enable;
366 1.1 ichiro
367 1.78 cegger printf("%s:", device_xname(self));
368 1.46 mycroft
369 1.47 mycroft haveaddr = pa->pf->pf_funce_lan_nidlen == IEEE80211_ADDR_LEN;
370 1.47 mycroft if (wi_attach(sc, haveaddr ? pa->pf->pf_funce_lan_nid : 0) != 0) {
371 1.78 cegger aprint_error_dev(self, "failed to attach controller\n");
372 1.52 mycroft goto fail2;
373 1.1 ichiro }
374 1.1 ichiro
375 1.85 tsutsui if (pmf_device_register(self, NULL, NULL))
376 1.85 tsutsui pmf_class_network_register(self, &sc->sc_if);
377 1.85 tsutsui else
378 1.77 jmcneill aprint_error_dev(self, "couldn't establish power handler\n");
379 1.1 ichiro
380 1.86 christos wi_pcmcia_enable(self, 0);
381 1.52 mycroft psc->sc_state = WI_PCMCIA_ATTACHED;
382 1.1 ichiro return;
383 1.1 ichiro
384 1.52 mycroft fail2:
385 1.86 christos wi_pcmcia_enable(self, 0);
386 1.52 mycroft fail:
387 1.52 mycroft pcmcia_function_unconfigure(pa->pf);
388 1.1 ichiro }
389 1.1 ichiro
390 1.1 ichiro static int
391 1.84 cegger wi_pcmcia_detach(device_t self, int flags)
392 1.1 ichiro {
393 1.86 christos struct wi_pcmcia_softc *psc = device_private(self);
394 1.1 ichiro int error;
395 1.1 ichiro
396 1.52 mycroft if (psc->sc_state != WI_PCMCIA_ATTACHED)
397 1.1 ichiro return (0);
398 1.1 ichiro
399 1.1 ichiro error = wi_detach(&psc->sc_wi);
400 1.1 ichiro if (error != 0)
401 1.1 ichiro return (error);
402 1.1 ichiro
403 1.52 mycroft pcmcia_function_unconfigure(psc->sc_pf);
404 1.1 ichiro
405 1.1 ichiro return (0);
406 1.1 ichiro }
407 1.1 ichiro
408 1.17 onoe /*
409 1.17 onoe * Special routines to download firmware for Symbol CF card.
410 1.17 onoe * XXX: This should be modified generic into any PRISM-2 based card.
411 1.17 onoe */
412 1.17 onoe
413 1.17 onoe #define WI_SBCF_PDIADDR 0x3100
414 1.17 onoe
415 1.17 onoe /* unaligned load little endian */
416 1.17 onoe #define GETLE32(p) ((p)[0] | ((p)[1]<<8) | ((p)[2]<<16) | ((p)[3]<<24))
417 1.17 onoe #define GETLE16(p) ((p)[0] | ((p)[1]<<8))
418 1.17 onoe
419 1.73 dsl #if WI_PCMCIA_SPECTRUM24T_FW
420 1.17 onoe static int
421 1.86 christos wi_pcmcia_load_firm(struct wi_softc *sc, const void *primsym, int primlen,
422 1.86 christos const void *secsym, int seclen)
423 1.17 onoe {
424 1.17 onoe u_int8_t ebuf[256];
425 1.17 onoe int i;
426 1.17 onoe
427 1.17 onoe /* load primary code and run it */
428 1.17 onoe wi_pcmcia_set_hcr(sc, WI_HCR_EEHOLD);
429 1.17 onoe if (wi_pcmcia_write_firm(sc, primsym, primlen, NULL, 0))
430 1.17 onoe return EIO;
431 1.17 onoe wi_pcmcia_set_hcr(sc, WI_HCR_RUN);
432 1.17 onoe for (i = 0; ; i++) {
433 1.17 onoe if (i == 10)
434 1.17 onoe return ETIMEDOUT;
435 1.17 onoe tsleep(sc, PWAIT, "wiinit", 1);
436 1.17 onoe if (CSR_READ_2(sc, WI_CNTL) == WI_CNTL_AUX_ENA_STAT)
437 1.17 onoe break;
438 1.17 onoe /* write the magic key value to unlock aux port */
439 1.17 onoe CSR_WRITE_2(sc, WI_PARAM0, WI_AUX_KEY0);
440 1.17 onoe CSR_WRITE_2(sc, WI_PARAM1, WI_AUX_KEY1);
441 1.17 onoe CSR_WRITE_2(sc, WI_PARAM2, WI_AUX_KEY2);
442 1.17 onoe CSR_WRITE_2(sc, WI_CNTL, WI_CNTL_AUX_ENA_CNTL);
443 1.17 onoe }
444 1.17 onoe
445 1.17 onoe /* issue read EEPROM command: XXX copied from wi_cmd() */
446 1.17 onoe CSR_WRITE_2(sc, WI_PARAM0, 0);
447 1.17 onoe CSR_WRITE_2(sc, WI_PARAM1, 0);
448 1.17 onoe CSR_WRITE_2(sc, WI_PARAM2, 0);
449 1.17 onoe CSR_WRITE_2(sc, WI_COMMAND, WI_CMD_READEE);
450 1.17 onoe for (i = 0; i < WI_TIMEOUT; i++) {
451 1.17 onoe if (CSR_READ_2(sc, WI_EVENT_STAT) & WI_EV_CMD)
452 1.17 onoe break;
453 1.17 onoe DELAY(1);
454 1.17 onoe }
455 1.17 onoe CSR_WRITE_2(sc, WI_EVENT_ACK, WI_EV_CMD);
456 1.17 onoe
457 1.17 onoe CSR_WRITE_2(sc, WI_AUX_PAGE, WI_SBCF_PDIADDR / WI_AUX_PGSZ);
458 1.17 onoe CSR_WRITE_2(sc, WI_AUX_OFFSET, WI_SBCF_PDIADDR % WI_AUX_PGSZ);
459 1.17 onoe CSR_READ_MULTI_STREAM_2(sc, WI_AUX_DATA,
460 1.17 onoe (u_int16_t *)ebuf, sizeof(ebuf) / 2);
461 1.17 onoe if (GETLE16(ebuf) > sizeof(ebuf))
462 1.17 onoe return EIO;
463 1.17 onoe if (wi_pcmcia_write_firm(sc, secsym, seclen, ebuf + 4, GETLE16(ebuf)))
464 1.17 onoe return EIO;
465 1.17 onoe return 0;
466 1.17 onoe }
467 1.17 onoe
468 1.17 onoe static int
469 1.86 christos wi_pcmcia_write_firm(struct wi_softc *sc, const void *buf, int buflen,
470 1.86 christos const void *ebuf, int ebuflen)
471 1.17 onoe {
472 1.17 onoe const u_int8_t *p, *ep, *q, *eq;
473 1.65 itohy char *endp;
474 1.17 onoe u_int32_t addr, id, eid;
475 1.17 onoe int i, len, elen, nblk, pdrlen;
476 1.17 onoe
477 1.17 onoe /*
478 1.17 onoe * Parse the header of the firmware image.
479 1.17 onoe */
480 1.17 onoe p = buf;
481 1.17 onoe ep = p + buflen;
482 1.17 onoe while (p < ep && *p++ != ' '); /* FILE: */
483 1.17 onoe while (p < ep && *p++ != ' '); /* filename */
484 1.17 onoe while (p < ep && *p++ != ' '); /* type of the firmware */
485 1.65 itohy nblk = strtoul(p, &endp, 10);
486 1.65 itohy p = (void *)endp;
487 1.65 itohy pdrlen = strtoul(p + 1, &endp, 10);
488 1.65 itohy p = (void *)endp;
489 1.17 onoe while (p < ep && *p++ != 0x1a); /* skip rest of header */
490 1.17 onoe
491 1.17 onoe /*
492 1.17 onoe * Block records: address[4], length[2], data[length];
493 1.17 onoe */
494 1.17 onoe for (i = 0; i < nblk; i++) {
495 1.17 onoe addr = GETLE32(p); p += 4;
496 1.17 onoe len = GETLE16(p); p += 2;
497 1.17 onoe CSR_WRITE_2(sc, WI_AUX_PAGE, addr / WI_AUX_PGSZ);
498 1.17 onoe CSR_WRITE_2(sc, WI_AUX_OFFSET, addr % WI_AUX_PGSZ);
499 1.17 onoe CSR_WRITE_MULTI_STREAM_2(sc, WI_AUX_DATA,
500 1.17 onoe (const u_int16_t *)p, len / 2);
501 1.17 onoe p += len;
502 1.17 onoe }
503 1.61 perry
504 1.17 onoe /*
505 1.17 onoe * PDR: id[4], address[4], length[4];
506 1.17 onoe */
507 1.17 onoe for (i = 0; i < pdrlen; ) {
508 1.17 onoe id = GETLE32(p); p += 4; i += 4;
509 1.17 onoe addr = GETLE32(p); p += 4; i += 4;
510 1.17 onoe len = GETLE32(p); p += 4; i += 4;
511 1.17 onoe /* replace PDR entry with the values from EEPROM, if any */
512 1.17 onoe for (q = ebuf, eq = q + ebuflen; q < eq; q += elen * 2) {
513 1.17 onoe elen = GETLE16(q); q += 2;
514 1.17 onoe eid = GETLE16(q); q += 2;
515 1.17 onoe elen--; /* elen includes eid */
516 1.17 onoe if (eid == 0)
517 1.17 onoe break;
518 1.17 onoe if (eid != id)
519 1.17 onoe continue;
520 1.17 onoe CSR_WRITE_2(sc, WI_AUX_PAGE, addr / WI_AUX_PGSZ);
521 1.17 onoe CSR_WRITE_2(sc, WI_AUX_OFFSET, addr % WI_AUX_PGSZ);
522 1.17 onoe CSR_WRITE_MULTI_STREAM_2(sc, WI_AUX_DATA,
523 1.17 onoe (const u_int16_t *)q, len / 2);
524 1.17 onoe break;
525 1.17 onoe }
526 1.17 onoe }
527 1.17 onoe return 0;
528 1.17 onoe }
529 1.17 onoe
530 1.17 onoe static int
531 1.81 dsl wi_pcmcia_set_hcr(struct wi_softc *sc, int mode)
532 1.17 onoe {
533 1.17 onoe u_int16_t hcr;
534 1.17 onoe
535 1.17 onoe CSR_WRITE_2(sc, WI_COR, WI_COR_RESET);
536 1.17 onoe tsleep(sc, PWAIT, "wiinit", 1);
537 1.17 onoe hcr = CSR_READ_2(sc, WI_HCR);
538 1.17 onoe hcr = (hcr & WI_HCR_4WIRE) | (mode & ~WI_HCR_4WIRE);
539 1.17 onoe CSR_WRITE_2(sc, WI_HCR, hcr);
540 1.17 onoe tsleep(sc, PWAIT, "wiinit", 1);
541 1.17 onoe CSR_WRITE_2(sc, WI_COR, WI_COR_IOMODE);
542 1.17 onoe tsleep(sc, PWAIT, "wiinit", 1);
543 1.17 onoe return 0;
544 1.1 ichiro }
545 1.73 dsl #endif
546