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