1 static int prism2_enable_aux_port(struct net_device *dev, int enable)
6 struct hostap_interface *iface;
9 iface = netdev_priv(dev);
14 PDEBUG(DEBUG_EXTRA2, "%s: no PRI f/w - assuming Aux "
15 "port is already enabled\n", dev->name);
20 spin_lock_irqsave(&local->cmdlock, flags);
22 /* wait until busy bit is clear */
23 tries = HFA384X_CMD_BUSY_TIMEOUT;
24 while (HFA384X_INW(HFA384X_CMD_OFF) & HFA384X_CMD_BUSY && tries > 0) {
29 reg = HFA384X_INW(HFA384X_CMD_OFF);
30 spin_unlock_irqrestore(&local->cmdlock, flags);
31 printk("%s: prism2_enable_aux_port - timeout - reg=0x%04x\n",
36 val = HFA384X_INW(HFA384X_CONTROL_OFF);
39 HFA384X_OUTW(HFA384X_AUX_MAGIC0, HFA384X_PARAM0_OFF);
40 HFA384X_OUTW(HFA384X_AUX_MAGIC1, HFA384X_PARAM1_OFF);
41 HFA384X_OUTW(HFA384X_AUX_MAGIC2, HFA384X_PARAM2_OFF);
43 if ((val & HFA384X_AUX_PORT_MASK) != HFA384X_AUX_PORT_DISABLED)
44 printk("prism2_enable_aux_port: was not disabled!?\n");
45 val &= ~HFA384X_AUX_PORT_MASK;
46 val |= HFA384X_AUX_PORT_ENABLE;
48 HFA384X_OUTW(0, HFA384X_PARAM0_OFF);
49 HFA384X_OUTW(0, HFA384X_PARAM1_OFF);
50 HFA384X_OUTW(0, HFA384X_PARAM2_OFF);
52 if ((val & HFA384X_AUX_PORT_MASK) != HFA384X_AUX_PORT_ENABLED)
53 printk("prism2_enable_aux_port: was not enabled!?\n");
54 val &= ~HFA384X_AUX_PORT_MASK;
55 val |= HFA384X_AUX_PORT_DISABLE;
57 HFA384X_OUTW(val, HFA384X_CONTROL_OFF);
63 val = HFA384X_INW(HFA384X_CONTROL_OFF);
64 val &= HFA384X_AUX_PORT_MASK;
66 if ((enable && val == HFA384X_AUX_PORT_ENABLED) ||
67 (!enable && val == HFA384X_AUX_PORT_DISABLED))
74 spin_unlock_irqrestore(&local->cmdlock, flags);
77 printk("prism2_enable_aux_port(%d) timed out\n",
86 static int hfa384x_from_aux(struct net_device *dev, unsigned int addr, int len,
90 if (addr & 1 || len & 1)
96 HFA384X_OUTW(page, HFA384X_AUXPAGE_OFF);
97 HFA384X_OUTW(offset, HFA384X_AUXOFFSET_OFF);
103 __le16 *pos = (__le16 *) buf;
105 *pos++ = HFA384X_INW_DATA(HFA384X_AUXDATA_OFF);
109 #else /* PRISM2_PCI */
110 HFA384X_INSW(HFA384X_AUXDATA_OFF, buf, len / 2);
111 #endif /* PRISM2_PCI */
117 static int hfa384x_to_aux(struct net_device *dev, unsigned int addr, int len,
121 if (addr & 1 || len & 1)
125 offset = addr & 0x7f;
127 HFA384X_OUTW(page, HFA384X_AUXPAGE_OFF);
128 HFA384X_OUTW(offset, HFA384X_AUXOFFSET_OFF);
134 __le16 *pos = (__le16 *) buf;
136 HFA384X_OUTW_DATA(*pos++, HFA384X_AUXDATA_OFF);
140 #else /* PRISM2_PCI */
141 HFA384X_OUTSW(HFA384X_AUXDATA_OFF, buf, len / 2);
142 #endif /* PRISM2_PCI */
148 static int prism2_pda_ok(u8 *buf)
150 __le16 *pda = (__le16 *) buf;
154 if (buf[0] == 0xff && buf[1] == 0x00 && buf[2] == 0xff &&
159 while (pos + 1 < PRISM2_PDA_SIZE / 2) {
160 len = le16_to_cpu(pda[pos]);
161 pdr = le16_to_cpu(pda[pos + 1]);
162 if (len == 0 || pos + len > PRISM2_PDA_SIZE / 2)
165 if (pdr == 0x0000 && len == 2) {
177 static int prism2_download_aux_dump(struct net_device *dev,
178 unsigned int addr, int len, u8 *buf)
182 prism2_enable_aux_port(dev, 1);
183 res = hfa384x_from_aux(dev, addr, len, buf);
184 prism2_enable_aux_port(dev, 0);
192 static u8 * prism2_read_pda(struct net_device *dev)
195 int res, i, found = 0;
196 #define NUM_PDA_ADDRS 4
197 unsigned int pda_addr[NUM_PDA_ADDRS] = {
198 0x7f0000 /* others than HFA3841 */,
199 0x3f0000 /* HFA3841 */,
200 0x390000 /* apparently used in older cards */,
201 0x7f0002 /* Intel PRO/Wireless 2011B (PCI) */,
204 buf = kmalloc(PRISM2_PDA_SIZE, GFP_KERNEL);
208 /* Note: wlan card should be in initial state (just after init cmd)
209 * and no other operations should be performed concurrently. */
211 prism2_enable_aux_port(dev, 1);
213 for (i = 0; i < NUM_PDA_ADDRS; i++) {
214 PDEBUG(DEBUG_EXTRA2, "%s: trying to read PDA from 0x%08x",
215 dev->name, pda_addr[i]);
216 res = hfa384x_from_aux(dev, pda_addr[i], PRISM2_PDA_SIZE, buf);
219 if (res == 0 && prism2_pda_ok(buf)) {
220 PDEBUG2(DEBUG_EXTRA2, ": OK\n");
224 PDEBUG2(DEBUG_EXTRA2, ": failed\n");
228 prism2_enable_aux_port(dev, 0);
231 printk(KERN_DEBUG "%s: valid PDA not found\n", dev->name);
240 static int prism2_download_volatile(local_info_t *local,
241 struct prism2_download_data *param)
243 struct net_device *dev = local->dev;
247 if (local->hw_downloading) {
248 printk(KERN_WARNING "%s: Already downloading - aborting new "
249 "request\n", dev->name);
253 local->hw_downloading = 1;
254 if (local->pri_only) {
255 hfa384x_disable_interrupts(dev);
257 prism2_hw_shutdown(dev, 0);
259 if (prism2_hw_init(dev, 0)) {
260 printk(KERN_WARNING "%s: Could not initialize card for"
261 " download\n", dev->name);
267 if (prism2_enable_aux_port(dev, 1)) {
268 printk(KERN_WARNING "%s: Could not enable AUX port\n",
274 param0 = param->start_addr & 0xffff;
275 param1 = param->start_addr >> 16;
277 HFA384X_OUTW(0, HFA384X_PARAM2_OFF);
278 HFA384X_OUTW(param1, HFA384X_PARAM1_OFF);
279 if (hfa384x_cmd_wait(dev, HFA384X_CMDCODE_DOWNLOAD |
280 (HFA384X_PROGMODE_ENABLE_VOLATILE << 8),
282 printk(KERN_WARNING "%s: Download command execution failed\n",
288 for (i = 0; i < param->num_areas; i++) {
289 PDEBUG(DEBUG_EXTRA2, "%s: Writing %d bytes at 0x%08x\n",
290 dev->name, param->data[i].len, param->data[i].addr);
291 if (hfa384x_to_aux(dev, param->data[i].addr,
292 param->data[i].len, param->data[i].data)) {
293 printk(KERN_WARNING "%s: RAM download at 0x%08x "
294 "(len=%d) failed\n", dev->name,
295 param->data[i].addr, param->data[i].len);
301 HFA384X_OUTW(param1, HFA384X_PARAM1_OFF);
302 HFA384X_OUTW(0, HFA384X_PARAM2_OFF);
303 if (hfa384x_cmd_no_wait(dev, HFA384X_CMDCODE_DOWNLOAD |
304 (HFA384X_PROGMODE_DISABLE << 8), param0)) {
305 printk(KERN_WARNING "%s: Download command execution failed\n",
310 /* ProgMode disable causes the hardware to restart itself from the
311 * given starting address. Give hw some time and ACK command just in
312 * case restart did not happen. */
314 HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_EVACK_OFF);
316 if (prism2_enable_aux_port(dev, 0)) {
317 printk(KERN_DEBUG "%s: Disabling AUX port failed\n",
319 /* continue anyway.. restart should have taken care of this */
323 local->hw_downloading = 0;
324 if (prism2_hw_config(dev, 2)) {
325 printk(KERN_WARNING "%s: Card configuration after RAM "
326 "download failed\n", dev->name);
332 local->hw_downloading = 0;
337 static int prism2_enable_genesis(local_info_t *local, int hcr)
339 struct net_device *dev = local->dev;
340 u8 initseq[4] = { 0x00, 0xe1, 0xa1, 0xff };
343 printk(KERN_DEBUG "%s: test Genesis mode with HCR 0x%02x\n",
345 local->func->cor_sreset(local);
346 hfa384x_to_aux(dev, 0x7e0038, sizeof(initseq), initseq);
347 local->func->genesis_reset(local, hcr);
350 hfa384x_from_aux(dev, 0x7e0038, sizeof(readbuf), readbuf);
351 hfa384x_to_aux(dev, 0x7e0038, sizeof(initseq), initseq);
352 hfa384x_from_aux(dev, 0x7e0038, sizeof(readbuf), readbuf);
354 if (memcmp(initseq, readbuf, sizeof(initseq)) == 0) {
355 printk(KERN_DEBUG "Readback test succeeded, HCR 0x%02x\n",
359 printk(KERN_DEBUG "Readback test failed, HCR 0x%02x "
360 "write %02x %02x %02x %02x read %02x %02x %02x %02x\n",
361 hcr, initseq[0], initseq[1], initseq[2], initseq[3],
362 readbuf[0], readbuf[1], readbuf[2], readbuf[3]);
368 static int prism2_get_ram_size(local_info_t *local)
372 /* Try to enable genesis mode; 0x1F for x8 SRAM or 0x0F for x16 SRAM */
373 if (prism2_enable_genesis(local, 0x1f) == 0)
375 else if (prism2_enable_genesis(local, 0x0f) == 0)
380 /* Disable genesis mode */
381 local->func->genesis_reset(local, ret == 16 ? 0x07 : 0x17);
387 static int prism2_download_genesis(local_info_t *local,
388 struct prism2_download_data *param)
390 struct net_device *dev = local->dev;
394 if (local->hw_downloading) {
395 printk(KERN_WARNING "%s: Already downloading - aborting new "
396 "request\n", dev->name);
400 if (!local->func->genesis_reset || !local->func->cor_sreset) {
401 printk(KERN_INFO "%s: Genesis mode downloading not supported "
402 "with this hwmodel\n", dev->name);
406 local->hw_downloading = 1;
408 if (prism2_enable_aux_port(dev, 1)) {
409 printk(KERN_DEBUG "%s: failed to enable AUX port\n",
415 if (local->sram_type == -1) {
416 /* 0x1F for x8 SRAM or 0x0F for x16 SRAM */
417 if (prism2_enable_genesis(local, 0x1f) == 0) {
419 PDEBUG(DEBUG_EXTRA2, "%s: Genesis mode OK using x8 "
420 "SRAM\n", dev->name);
421 } else if (prism2_enable_genesis(local, 0x0f) == 0) {
423 PDEBUG(DEBUG_EXTRA2, "%s: Genesis mode OK using x16 "
424 "SRAM\n", dev->name);
426 printk(KERN_DEBUG "%s: Could not initiate genesis "
427 "mode\n", dev->name);
432 if (prism2_enable_genesis(local, local->sram_type == 8 ?
434 printk(KERN_DEBUG "%s: Failed to set Genesis "
435 "mode (sram_type=%d)\n", dev->name,
440 ram16 = local->sram_type != 8;
443 for (i = 0; i < param->num_areas; i++) {
444 PDEBUG(DEBUG_EXTRA2, "%s: Writing %d bytes at 0x%08x\n",
445 dev->name, param->data[i].len, param->data[i].addr);
446 if (hfa384x_to_aux(dev, param->data[i].addr,
447 param->data[i].len, param->data[i].data)) {
448 printk(KERN_WARNING "%s: RAM download at 0x%08x "
449 "(len=%d) failed\n", dev->name,
450 param->data[i].addr, param->data[i].len);
456 PDEBUG(DEBUG_EXTRA2, "Disable genesis mode\n");
457 local->func->genesis_reset(local, ram16 ? 0x07 : 0x17);
458 if (prism2_enable_aux_port(dev, 0)) {
459 printk(KERN_DEBUG "%s: Failed to disable AUX port\n",
464 local->hw_downloading = 0;
466 PDEBUG(DEBUG_EXTRA2, "Trying to initialize card\n");
468 * Make sure the INIT command does not generate a command completion
469 * event by disabling interrupts.
471 hfa384x_disable_interrupts(dev);
472 if (prism2_hw_init(dev, 1)) {
473 printk(KERN_DEBUG "%s: Initialization after genesis mode "
474 "download failed\n", dev->name);
479 PDEBUG(DEBUG_EXTRA2, "Card initialized - running PRI only\n");
480 if (prism2_hw_init2(dev, 1)) {
481 printk(KERN_DEBUG "%s: Initialization(2) after genesis mode "
482 "download failed\n", dev->name);
488 local->hw_downloading = 0;
493 #ifdef PRISM2_NON_VOLATILE_DOWNLOAD
494 /* Note! Non-volatile downloading functionality has not yet been tested
495 * thoroughly and it may corrupt flash image and effectively kill the card that
496 * is being updated. You have been warned. */
498 static inline int prism2_download_block(struct net_device *dev,
500 u32 bufaddr, int rest_len)
505 block_len = rest_len < 4096 ? rest_len : 4096;
507 param0 = addr & 0xffff;
510 HFA384X_OUTW(block_len, HFA384X_PARAM2_OFF);
511 HFA384X_OUTW(param1, HFA384X_PARAM1_OFF);
513 if (hfa384x_cmd_wait(dev, HFA384X_CMDCODE_DOWNLOAD |
514 (HFA384X_PROGMODE_ENABLE_NON_VOLATILE << 8),
516 printk(KERN_WARNING "%s: Flash download command execution "
517 "failed\n", dev->name);
521 if (hfa384x_to_aux(dev, bufaddr, block_len, data)) {
522 printk(KERN_WARNING "%s: flash download at 0x%08x "
523 "(len=%d) failed\n", dev->name, addr, block_len);
527 HFA384X_OUTW(0, HFA384X_PARAM2_OFF);
528 HFA384X_OUTW(0, HFA384X_PARAM1_OFF);
529 if (hfa384x_cmd_wait(dev, HFA384X_CMDCODE_DOWNLOAD |
530 (HFA384X_PROGMODE_PROGRAM_NON_VOLATILE << 8),
532 printk(KERN_WARNING "%s: Flash write command execution "
533 "failed\n", dev->name);
541 static int prism2_download_nonvolatile(local_info_t *local,
542 struct prism2_download_data *dl)
544 struct net_device *dev = local->dev;
553 if (local->hw_downloading) {
554 printk(KERN_WARNING "%s: Already downloading - aborting new "
555 "request\n", dev->name);
559 ret = local->func->get_rid(dev, HFA384X_RID_DOWNLOADBUFFER,
563 printk(KERN_WARNING "%s: Could not read download buffer "
564 "parameters\n", dev->name);
568 printk(KERN_DEBUG "Download buffer: %d bytes at 0x%04x:0x%04x\n",
569 le16_to_cpu(dlbuffer.len),
570 le16_to_cpu(dlbuffer.page),
571 le16_to_cpu(dlbuffer.offset));
573 bufaddr = (le16_to_cpu(dlbuffer.page) << 7) + le16_to_cpu(dlbuffer.offset);
575 local->hw_downloading = 1;
577 if (!local->pri_only) {
578 prism2_hw_shutdown(dev, 0);
580 if (prism2_hw_init(dev, 0)) {
581 printk(KERN_WARNING "%s: Could not initialize card for"
582 " download\n", dev->name);
588 hfa384x_disable_interrupts(dev);
590 if (prism2_enable_aux_port(dev, 1)) {
591 printk(KERN_WARNING "%s: Could not enable AUX port\n",
597 printk(KERN_DEBUG "%s: starting flash download\n", dev->name);
598 for (i = 0; i < dl->num_areas; i++) {
599 int rest_len = dl->data[i].len;
602 while (rest_len > 0) {
605 block_len = prism2_download_block(
606 dev, dl->data[i].addr + data_off,
607 dl->data[i].data + data_off, bufaddr,
615 rest_len -= block_len;
616 data_off += block_len;
620 HFA384X_OUTW(0, HFA384X_PARAM1_OFF);
621 HFA384X_OUTW(0, HFA384X_PARAM2_OFF);
622 if (hfa384x_cmd_wait(dev, HFA384X_CMDCODE_DOWNLOAD |
623 (HFA384X_PROGMODE_DISABLE << 8), 0)) {
624 printk(KERN_WARNING "%s: Download command execution failed\n",
630 if (prism2_enable_aux_port(dev, 0)) {
631 printk(KERN_DEBUG "%s: Disabling AUX port failed\n",
633 /* continue anyway.. restart should have taken care of this */
638 local->func->hw_reset(dev);
639 local->hw_downloading = 0;
640 if (prism2_hw_config(dev, 2)) {
641 printk(KERN_WARNING "%s: Card configuration after flash "
642 "download failed\n", dev->name);
645 printk(KERN_INFO "%s: Card initialized successfully after "
646 "flash download\n", dev->name);
650 local->hw_downloading = 0;
653 #endif /* PRISM2_NON_VOLATILE_DOWNLOAD */
656 static void prism2_download_free_data(struct prism2_download_data *dl)
663 for (i = 0; i < dl->num_areas; i++)
664 kfree(dl->data[i].data);
669 static int prism2_download(local_info_t *local,
670 struct prism2_download_param *param)
675 struct prism2_download_data *dl = NULL;
677 printk(KERN_DEBUG "prism2_download: dl_cmd=%d start_addr=0x%08x "
679 param->dl_cmd, param->start_addr, param->num_areas);
681 if (param->num_areas > 100) {
686 dl = kzalloc(sizeof(*dl) + param->num_areas *
687 sizeof(struct prism2_download_data_area), GFP_KERNEL);
692 dl->dl_cmd = param->dl_cmd;
693 dl->start_addr = param->start_addr;
694 dl->num_areas = param->num_areas;
695 for (i = 0; i < param->num_areas; i++) {
697 " area %d: addr=0x%08x len=%d ptr=0x%p\n",
698 i, param->data[i].addr, param->data[i].len,
701 dl->data[i].addr = param->data[i].addr;
702 dl->data[i].len = param->data[i].len;
704 total_len += param->data[i].len;
705 if (param->data[i].len > PRISM2_MAX_DOWNLOAD_AREA_LEN ||
706 total_len > PRISM2_MAX_DOWNLOAD_LEN) {
711 dl->data[i].data = kmalloc(dl->data[i].len, GFP_KERNEL);
712 if (dl->data[i].data == NULL) {
717 if (copy_from_user(dl->data[i].data, param->data[i].ptr,
718 param->data[i].len)) {
724 switch (param->dl_cmd) {
725 case PRISM2_DOWNLOAD_VOLATILE:
726 case PRISM2_DOWNLOAD_VOLATILE_PERSISTENT:
727 ret = prism2_download_volatile(local, dl);
729 case PRISM2_DOWNLOAD_VOLATILE_GENESIS:
730 case PRISM2_DOWNLOAD_VOLATILE_GENESIS_PERSISTENT:
731 ret = prism2_download_genesis(local, dl);
733 case PRISM2_DOWNLOAD_NON_VOLATILE:
734 #ifdef PRISM2_NON_VOLATILE_DOWNLOAD
735 ret = prism2_download_nonvolatile(local, dl);
736 #else /* PRISM2_NON_VOLATILE_DOWNLOAD */
737 printk(KERN_INFO "%s: non-volatile downloading not enabled\n",
740 #endif /* PRISM2_NON_VOLATILE_DOWNLOAD */
743 printk(KERN_DEBUG "%s: unsupported download command %d\n",
744 local->dev->name, param->dl_cmd);
750 if (ret == 0 && dl &&
751 param->dl_cmd == PRISM2_DOWNLOAD_VOLATILE_GENESIS_PERSISTENT) {
752 prism2_download_free_data(local->dl_pri);
754 } else if (ret == 0 && dl &&
755 param->dl_cmd == PRISM2_DOWNLOAD_VOLATILE_PERSISTENT) {
756 prism2_download_free_data(local->dl_sec);
759 prism2_download_free_data(dl);