1 // SPDX-License-Identifier: GPL-2.0
2 static int prism2_enable_aux_port(struct net_device *dev, int enable)
7 struct hostap_interface *iface;
10 iface = netdev_priv(dev);
15 PDEBUG(DEBUG_EXTRA2, "%s: no PRI f/w - assuming Aux "
16 "port is already enabled\n", dev->name);
21 spin_lock_irqsave(&local->cmdlock, flags);
23 /* wait until busy bit is clear */
24 tries = HFA384X_CMD_BUSY_TIMEOUT;
25 while (HFA384X_INW(HFA384X_CMD_OFF) & HFA384X_CMD_BUSY && tries > 0) {
30 reg = HFA384X_INW(HFA384X_CMD_OFF);
31 spin_unlock_irqrestore(&local->cmdlock, flags);
32 printk("%s: prism2_enable_aux_port - timeout - reg=0x%04x\n",
37 val = HFA384X_INW(HFA384X_CONTROL_OFF);
40 HFA384X_OUTW(HFA384X_AUX_MAGIC0, HFA384X_PARAM0_OFF);
41 HFA384X_OUTW(HFA384X_AUX_MAGIC1, HFA384X_PARAM1_OFF);
42 HFA384X_OUTW(HFA384X_AUX_MAGIC2, HFA384X_PARAM2_OFF);
44 if ((val & HFA384X_AUX_PORT_MASK) != HFA384X_AUX_PORT_DISABLED)
45 printk("prism2_enable_aux_port: was not disabled!?\n");
46 val &= ~HFA384X_AUX_PORT_MASK;
47 val |= HFA384X_AUX_PORT_ENABLE;
49 HFA384X_OUTW(0, HFA384X_PARAM0_OFF);
50 HFA384X_OUTW(0, HFA384X_PARAM1_OFF);
51 HFA384X_OUTW(0, HFA384X_PARAM2_OFF);
53 if ((val & HFA384X_AUX_PORT_MASK) != HFA384X_AUX_PORT_ENABLED)
54 printk("prism2_enable_aux_port: was not enabled!?\n");
55 val &= ~HFA384X_AUX_PORT_MASK;
56 val |= HFA384X_AUX_PORT_DISABLE;
58 HFA384X_OUTW(val, HFA384X_CONTROL_OFF);
64 val = HFA384X_INW(HFA384X_CONTROL_OFF);
65 val &= HFA384X_AUX_PORT_MASK;
67 if ((enable && val == HFA384X_AUX_PORT_ENABLED) ||
68 (!enable && val == HFA384X_AUX_PORT_DISABLED))
75 spin_unlock_irqrestore(&local->cmdlock, flags);
78 printk("prism2_enable_aux_port(%d) timed out\n",
87 static int hfa384x_from_aux(struct net_device *dev, unsigned int addr, int len,
91 if (addr & 1 || len & 1)
97 HFA384X_OUTW(page, HFA384X_AUXPAGE_OFF);
98 HFA384X_OUTW(offset, HFA384X_AUXOFFSET_OFF);
104 __le16 *pos = (__le16 *) buf;
106 *pos++ = HFA384X_INW_DATA(HFA384X_AUXDATA_OFF);
110 #else /* PRISM2_PCI */
111 HFA384X_INSW(HFA384X_AUXDATA_OFF, buf, len / 2);
112 #endif /* PRISM2_PCI */
118 static int hfa384x_to_aux(struct net_device *dev, unsigned int addr, int len,
122 if (addr & 1 || len & 1)
126 offset = addr & 0x7f;
128 HFA384X_OUTW(page, HFA384X_AUXPAGE_OFF);
129 HFA384X_OUTW(offset, HFA384X_AUXOFFSET_OFF);
135 __le16 *pos = (__le16 *) buf;
137 HFA384X_OUTW_DATA(*pos++, HFA384X_AUXDATA_OFF);
141 #else /* PRISM2_PCI */
142 HFA384X_OUTSW(HFA384X_AUXDATA_OFF, buf, len / 2);
143 #endif /* PRISM2_PCI */
149 static int prism2_pda_ok(u8 *buf)
151 __le16 *pda = (__le16 *) buf;
155 if (buf[0] == 0xff && buf[1] == 0x00 && buf[2] == 0xff &&
160 while (pos + 1 < PRISM2_PDA_SIZE / 2) {
161 len = le16_to_cpu(pda[pos]);
162 pdr = le16_to_cpu(pda[pos + 1]);
163 if (len == 0 || pos + len > PRISM2_PDA_SIZE / 2)
166 if (pdr == 0x0000 && len == 2) {
178 #define prism2_download_aux_dump_npages 65536
180 struct prism2_download_aux_dump {
185 static int prism2_download_aux_dump_proc_show(struct seq_file *m, void *v)
187 struct prism2_download_aux_dump *ctx = m->private;
189 hfa384x_from_aux(ctx->local->dev, (unsigned long)v - 1, 0x80, ctx->page);
190 seq_write(m, ctx->page, 0x80);
194 static void *prism2_download_aux_dump_proc_start(struct seq_file *m, loff_t *_pos)
196 struct prism2_download_aux_dump *ctx = m->private;
197 prism2_enable_aux_port(ctx->local->dev, 1);
198 if (*_pos >= prism2_download_aux_dump_npages)
200 return (void *)((unsigned long)*_pos + 1);
203 static void *prism2_download_aux_dump_proc_next(struct seq_file *m, void *v, loff_t *_pos)
206 if (*_pos >= prism2_download_aux_dump_npages)
208 return (void *)((unsigned long)*_pos + 1);
211 static void prism2_download_aux_dump_proc_stop(struct seq_file *m, void *v)
213 struct prism2_download_aux_dump *ctx = m->private;
214 prism2_enable_aux_port(ctx->local->dev, 0);
217 static const struct seq_operations prism2_download_aux_dump_proc_seqops = {
218 .start = prism2_download_aux_dump_proc_start,
219 .next = prism2_download_aux_dump_proc_next,
220 .stop = prism2_download_aux_dump_proc_stop,
221 .show = prism2_download_aux_dump_proc_show,
224 static int prism2_download_aux_dump_proc_open(struct inode *inode, struct file *file)
226 int ret = seq_open_private(file, &prism2_download_aux_dump_proc_seqops,
227 sizeof(struct prism2_download_aux_dump));
229 struct seq_file *m = file->private_data;
230 m->private = PDE_DATA(inode);
235 static const struct file_operations prism2_download_aux_dump_proc_fops = {
236 .open = prism2_download_aux_dump_proc_open,
239 .release = seq_release_private,
243 static u8 * prism2_read_pda(struct net_device *dev)
246 int res, i, found = 0;
247 #define NUM_PDA_ADDRS 4
248 unsigned int pda_addr[NUM_PDA_ADDRS] = {
249 0x7f0000 /* others than HFA3841 */,
250 0x3f0000 /* HFA3841 */,
251 0x390000 /* apparently used in older cards */,
252 0x7f0002 /* Intel PRO/Wireless 2011B (PCI) */,
255 buf = kmalloc(PRISM2_PDA_SIZE, GFP_KERNEL);
259 /* Note: wlan card should be in initial state (just after init cmd)
260 * and no other operations should be performed concurrently. */
262 prism2_enable_aux_port(dev, 1);
264 for (i = 0; i < NUM_PDA_ADDRS; i++) {
265 PDEBUG(DEBUG_EXTRA2, "%s: trying to read PDA from 0x%08x",
266 dev->name, pda_addr[i]);
267 res = hfa384x_from_aux(dev, pda_addr[i], PRISM2_PDA_SIZE, buf);
270 if (res == 0 && prism2_pda_ok(buf)) {
271 PDEBUG2(DEBUG_EXTRA2, ": OK\n");
275 PDEBUG2(DEBUG_EXTRA2, ": failed\n");
279 prism2_enable_aux_port(dev, 0);
282 printk(KERN_DEBUG "%s: valid PDA not found\n", dev->name);
291 static int prism2_download_volatile(local_info_t *local,
292 struct prism2_download_data *param)
294 struct net_device *dev = local->dev;
298 if (local->hw_downloading) {
299 printk(KERN_WARNING "%s: Already downloading - aborting new "
300 "request\n", dev->name);
304 local->hw_downloading = 1;
305 if (local->pri_only) {
306 hfa384x_disable_interrupts(dev);
308 prism2_hw_shutdown(dev, 0);
310 if (prism2_hw_init(dev, 0)) {
311 printk(KERN_WARNING "%s: Could not initialize card for"
312 " download\n", dev->name);
318 if (prism2_enable_aux_port(dev, 1)) {
319 printk(KERN_WARNING "%s: Could not enable AUX port\n",
325 param0 = param->start_addr & 0xffff;
326 param1 = param->start_addr >> 16;
328 HFA384X_OUTW(0, HFA384X_PARAM2_OFF);
329 HFA384X_OUTW(param1, HFA384X_PARAM1_OFF);
330 if (hfa384x_cmd_wait(dev, HFA384X_CMDCODE_DOWNLOAD |
331 (HFA384X_PROGMODE_ENABLE_VOLATILE << 8),
333 printk(KERN_WARNING "%s: Download command execution failed\n",
339 for (i = 0; i < param->num_areas; i++) {
340 PDEBUG(DEBUG_EXTRA2, "%s: Writing %d bytes at 0x%08x\n",
341 dev->name, param->data[i].len, param->data[i].addr);
342 if (hfa384x_to_aux(dev, param->data[i].addr,
343 param->data[i].len, param->data[i].data)) {
344 printk(KERN_WARNING "%s: RAM download at 0x%08x "
345 "(len=%d) failed\n", dev->name,
346 param->data[i].addr, param->data[i].len);
352 HFA384X_OUTW(param1, HFA384X_PARAM1_OFF);
353 HFA384X_OUTW(0, HFA384X_PARAM2_OFF);
354 if (hfa384x_cmd_no_wait(dev, HFA384X_CMDCODE_DOWNLOAD |
355 (HFA384X_PROGMODE_DISABLE << 8), param0)) {
356 printk(KERN_WARNING "%s: Download command execution failed\n",
361 /* ProgMode disable causes the hardware to restart itself from the
362 * given starting address. Give hw some time and ACK command just in
363 * case restart did not happen. */
365 HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_EVACK_OFF);
367 if (prism2_enable_aux_port(dev, 0)) {
368 printk(KERN_DEBUG "%s: Disabling AUX port failed\n",
370 /* continue anyway.. restart should have taken care of this */
374 local->hw_downloading = 0;
375 if (prism2_hw_config(dev, 2)) {
376 printk(KERN_WARNING "%s: Card configuration after RAM "
377 "download failed\n", dev->name);
383 local->hw_downloading = 0;
388 static int prism2_enable_genesis(local_info_t *local, int hcr)
390 struct net_device *dev = local->dev;
391 u8 initseq[4] = { 0x00, 0xe1, 0xa1, 0xff };
394 printk(KERN_DEBUG "%s: test Genesis mode with HCR 0x%02x\n",
396 local->func->cor_sreset(local);
397 hfa384x_to_aux(dev, 0x7e0038, sizeof(initseq), initseq);
398 local->func->genesis_reset(local, hcr);
401 hfa384x_from_aux(dev, 0x7e0038, sizeof(readbuf), readbuf);
402 hfa384x_to_aux(dev, 0x7e0038, sizeof(initseq), initseq);
403 hfa384x_from_aux(dev, 0x7e0038, sizeof(readbuf), readbuf);
405 if (memcmp(initseq, readbuf, sizeof(initseq)) == 0) {
406 printk(KERN_DEBUG "Readback test succeeded, HCR 0x%02x\n",
410 printk(KERN_DEBUG "Readback test failed, HCR 0x%02x write %4ph read %4ph\n",
411 hcr, initseq, readbuf);
417 static int prism2_get_ram_size(local_info_t *local)
421 /* Try to enable genesis mode; 0x1F for x8 SRAM or 0x0F for x16 SRAM */
422 if (prism2_enable_genesis(local, 0x1f) == 0)
424 else if (prism2_enable_genesis(local, 0x0f) == 0)
429 /* Disable genesis mode */
430 local->func->genesis_reset(local, ret == 16 ? 0x07 : 0x17);
436 static int prism2_download_genesis(local_info_t *local,
437 struct prism2_download_data *param)
439 struct net_device *dev = local->dev;
443 if (local->hw_downloading) {
444 printk(KERN_WARNING "%s: Already downloading - aborting new "
445 "request\n", dev->name);
449 if (!local->func->genesis_reset || !local->func->cor_sreset) {
450 printk(KERN_INFO "%s: Genesis mode downloading not supported "
451 "with this hwmodel\n", dev->name);
455 local->hw_downloading = 1;
457 if (prism2_enable_aux_port(dev, 1)) {
458 printk(KERN_DEBUG "%s: failed to enable AUX port\n",
464 if (local->sram_type == -1) {
465 /* 0x1F for x8 SRAM or 0x0F for x16 SRAM */
466 if (prism2_enable_genesis(local, 0x1f) == 0) {
468 PDEBUG(DEBUG_EXTRA2, "%s: Genesis mode OK using x8 "
469 "SRAM\n", dev->name);
470 } else if (prism2_enable_genesis(local, 0x0f) == 0) {
472 PDEBUG(DEBUG_EXTRA2, "%s: Genesis mode OK using x16 "
473 "SRAM\n", dev->name);
475 printk(KERN_DEBUG "%s: Could not initiate genesis "
476 "mode\n", dev->name);
481 if (prism2_enable_genesis(local, local->sram_type == 8 ?
483 printk(KERN_DEBUG "%s: Failed to set Genesis "
484 "mode (sram_type=%d)\n", dev->name,
489 ram16 = local->sram_type != 8;
492 for (i = 0; i < param->num_areas; i++) {
493 PDEBUG(DEBUG_EXTRA2, "%s: Writing %d bytes at 0x%08x\n",
494 dev->name, param->data[i].len, param->data[i].addr);
495 if (hfa384x_to_aux(dev, param->data[i].addr,
496 param->data[i].len, param->data[i].data)) {
497 printk(KERN_WARNING "%s: RAM download at 0x%08x "
498 "(len=%d) failed\n", dev->name,
499 param->data[i].addr, param->data[i].len);
505 PDEBUG(DEBUG_EXTRA2, "Disable genesis mode\n");
506 local->func->genesis_reset(local, ram16 ? 0x07 : 0x17);
507 if (prism2_enable_aux_port(dev, 0)) {
508 printk(KERN_DEBUG "%s: Failed to disable AUX port\n",
513 local->hw_downloading = 0;
515 PDEBUG(DEBUG_EXTRA2, "Trying to initialize card\n");
517 * Make sure the INIT command does not generate a command completion
518 * event by disabling interrupts.
520 hfa384x_disable_interrupts(dev);
521 if (prism2_hw_init(dev, 1)) {
522 printk(KERN_DEBUG "%s: Initialization after genesis mode "
523 "download failed\n", dev->name);
528 PDEBUG(DEBUG_EXTRA2, "Card initialized - running PRI only\n");
529 if (prism2_hw_init2(dev, 1)) {
530 printk(KERN_DEBUG "%s: Initialization(2) after genesis mode "
531 "download failed\n", dev->name);
537 local->hw_downloading = 0;
542 #ifdef PRISM2_NON_VOLATILE_DOWNLOAD
543 /* Note! Non-volatile downloading functionality has not yet been tested
544 * thoroughly and it may corrupt flash image and effectively kill the card that
545 * is being updated. You have been warned. */
547 static inline int prism2_download_block(struct net_device *dev,
549 u32 bufaddr, int rest_len)
554 block_len = rest_len < 4096 ? rest_len : 4096;
556 param0 = addr & 0xffff;
559 HFA384X_OUTW(block_len, HFA384X_PARAM2_OFF);
560 HFA384X_OUTW(param1, HFA384X_PARAM1_OFF);
562 if (hfa384x_cmd_wait(dev, HFA384X_CMDCODE_DOWNLOAD |
563 (HFA384X_PROGMODE_ENABLE_NON_VOLATILE << 8),
565 printk(KERN_WARNING "%s: Flash download command execution "
566 "failed\n", dev->name);
570 if (hfa384x_to_aux(dev, bufaddr, block_len, data)) {
571 printk(KERN_WARNING "%s: flash download at 0x%08x "
572 "(len=%d) failed\n", dev->name, addr, block_len);
576 HFA384X_OUTW(0, HFA384X_PARAM2_OFF);
577 HFA384X_OUTW(0, HFA384X_PARAM1_OFF);
578 if (hfa384x_cmd_wait(dev, HFA384X_CMDCODE_DOWNLOAD |
579 (HFA384X_PROGMODE_PROGRAM_NON_VOLATILE << 8),
581 printk(KERN_WARNING "%s: Flash write command execution "
582 "failed\n", dev->name);
590 static int prism2_download_nonvolatile(local_info_t *local,
591 struct prism2_download_data *dl)
593 struct net_device *dev = local->dev;
602 if (local->hw_downloading) {
603 printk(KERN_WARNING "%s: Already downloading - aborting new "
604 "request\n", dev->name);
608 ret = local->func->get_rid(dev, HFA384X_RID_DOWNLOADBUFFER,
612 printk(KERN_WARNING "%s: Could not read download buffer "
613 "parameters\n", dev->name);
617 printk(KERN_DEBUG "Download buffer: %d bytes at 0x%04x:0x%04x\n",
618 le16_to_cpu(dlbuffer.len),
619 le16_to_cpu(dlbuffer.page),
620 le16_to_cpu(dlbuffer.offset));
622 bufaddr = (le16_to_cpu(dlbuffer.page) << 7) + le16_to_cpu(dlbuffer.offset);
624 local->hw_downloading = 1;
626 if (!local->pri_only) {
627 prism2_hw_shutdown(dev, 0);
629 if (prism2_hw_init(dev, 0)) {
630 printk(KERN_WARNING "%s: Could not initialize card for"
631 " download\n", dev->name);
637 hfa384x_disable_interrupts(dev);
639 if (prism2_enable_aux_port(dev, 1)) {
640 printk(KERN_WARNING "%s: Could not enable AUX port\n",
646 printk(KERN_DEBUG "%s: starting flash download\n", dev->name);
647 for (i = 0; i < dl->num_areas; i++) {
648 int rest_len = dl->data[i].len;
651 while (rest_len > 0) {
654 block_len = prism2_download_block(
655 dev, dl->data[i].addr + data_off,
656 dl->data[i].data + data_off, bufaddr,
664 rest_len -= block_len;
665 data_off += block_len;
669 HFA384X_OUTW(0, HFA384X_PARAM1_OFF);
670 HFA384X_OUTW(0, HFA384X_PARAM2_OFF);
671 if (hfa384x_cmd_wait(dev, HFA384X_CMDCODE_DOWNLOAD |
672 (HFA384X_PROGMODE_DISABLE << 8), 0)) {
673 printk(KERN_WARNING "%s: Download command execution failed\n",
679 if (prism2_enable_aux_port(dev, 0)) {
680 printk(KERN_DEBUG "%s: Disabling AUX port failed\n",
682 /* continue anyway.. restart should have taken care of this */
687 local->func->hw_reset(dev);
688 local->hw_downloading = 0;
689 if (prism2_hw_config(dev, 2)) {
690 printk(KERN_WARNING "%s: Card configuration after flash "
691 "download failed\n", dev->name);
694 printk(KERN_INFO "%s: Card initialized successfully after "
695 "flash download\n", dev->name);
699 local->hw_downloading = 0;
702 #endif /* PRISM2_NON_VOLATILE_DOWNLOAD */
705 static void prism2_download_free_data(struct prism2_download_data *dl)
712 for (i = 0; i < dl->num_areas; i++)
713 kfree(dl->data[i].data);
718 static int prism2_download(local_info_t *local,
719 struct prism2_download_param *param)
724 struct prism2_download_data *dl = NULL;
726 printk(KERN_DEBUG "prism2_download: dl_cmd=%d start_addr=0x%08x "
728 param->dl_cmd, param->start_addr, param->num_areas);
730 if (param->num_areas > 100) {
735 dl = kzalloc(sizeof(*dl) + param->num_areas *
736 sizeof(struct prism2_download_data_area), GFP_KERNEL);
741 dl->dl_cmd = param->dl_cmd;
742 dl->start_addr = param->start_addr;
743 dl->num_areas = param->num_areas;
744 for (i = 0; i < param->num_areas; i++) {
746 " area %d: addr=0x%08x len=%d ptr=0x%p\n",
747 i, param->data[i].addr, param->data[i].len,
750 dl->data[i].addr = param->data[i].addr;
751 dl->data[i].len = param->data[i].len;
753 total_len += param->data[i].len;
754 if (param->data[i].len > PRISM2_MAX_DOWNLOAD_AREA_LEN ||
755 total_len > PRISM2_MAX_DOWNLOAD_LEN) {
760 dl->data[i].data = kmalloc(dl->data[i].len, GFP_KERNEL);
761 if (dl->data[i].data == NULL) {
766 if (copy_from_user(dl->data[i].data, param->data[i].ptr,
767 param->data[i].len)) {
773 switch (param->dl_cmd) {
774 case PRISM2_DOWNLOAD_VOLATILE:
775 case PRISM2_DOWNLOAD_VOLATILE_PERSISTENT:
776 ret = prism2_download_volatile(local, dl);
778 case PRISM2_DOWNLOAD_VOLATILE_GENESIS:
779 case PRISM2_DOWNLOAD_VOLATILE_GENESIS_PERSISTENT:
780 ret = prism2_download_genesis(local, dl);
782 case PRISM2_DOWNLOAD_NON_VOLATILE:
783 #ifdef PRISM2_NON_VOLATILE_DOWNLOAD
784 ret = prism2_download_nonvolatile(local, dl);
785 #else /* PRISM2_NON_VOLATILE_DOWNLOAD */
786 printk(KERN_INFO "%s: non-volatile downloading not enabled\n",
789 #endif /* PRISM2_NON_VOLATILE_DOWNLOAD */
792 printk(KERN_DEBUG "%s: unsupported download command %d\n",
793 local->dev->name, param->dl_cmd);
799 if (ret == 0 && dl &&
800 param->dl_cmd == PRISM2_DOWNLOAD_VOLATILE_GENESIS_PERSISTENT) {
801 prism2_download_free_data(local->dl_pri);
803 } else if (ret == 0 && dl &&
804 param->dl_cmd == PRISM2_DOWNLOAD_VOLATILE_PERSISTENT) {
805 prism2_download_free_data(local->dl_sec);
808 prism2_download_free_data(dl);