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