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 "
411 "write %02x %02x %02x %02x read %02x %02x %02x %02x\n",
412 hcr
, initseq
[0], initseq
[1], initseq
[2], initseq
[3],
413 readbuf
[0], readbuf
[1], readbuf
[2], readbuf
[3]);
419 static int prism2_get_ram_size(local_info_t
*local
)
423 /* Try to enable genesis mode; 0x1F for x8 SRAM or 0x0F for x16 SRAM */
424 if (prism2_enable_genesis(local
, 0x1f) == 0)
426 else if (prism2_enable_genesis(local
, 0x0f) == 0)
431 /* Disable genesis mode */
432 local
->func
->genesis_reset(local
, ret
== 16 ? 0x07 : 0x17);
438 static int prism2_download_genesis(local_info_t
*local
,
439 struct prism2_download_data
*param
)
441 struct net_device
*dev
= local
->dev
;
445 if (local
->hw_downloading
) {
446 printk(KERN_WARNING
"%s: Already downloading - aborting new "
447 "request\n", dev
->name
);
451 if (!local
->func
->genesis_reset
|| !local
->func
->cor_sreset
) {
452 printk(KERN_INFO
"%s: Genesis mode downloading not supported "
453 "with this hwmodel\n", dev
->name
);
457 local
->hw_downloading
= 1;
459 if (prism2_enable_aux_port(dev
, 1)) {
460 printk(KERN_DEBUG
"%s: failed to enable AUX port\n",
466 if (local
->sram_type
== -1) {
467 /* 0x1F for x8 SRAM or 0x0F for x16 SRAM */
468 if (prism2_enable_genesis(local
, 0x1f) == 0) {
470 PDEBUG(DEBUG_EXTRA2
, "%s: Genesis mode OK using x8 "
471 "SRAM\n", dev
->name
);
472 } else if (prism2_enable_genesis(local
, 0x0f) == 0) {
474 PDEBUG(DEBUG_EXTRA2
, "%s: Genesis mode OK using x16 "
475 "SRAM\n", dev
->name
);
477 printk(KERN_DEBUG
"%s: Could not initiate genesis "
478 "mode\n", dev
->name
);
483 if (prism2_enable_genesis(local
, local
->sram_type
== 8 ?
485 printk(KERN_DEBUG
"%s: Failed to set Genesis "
486 "mode (sram_type=%d)\n", dev
->name
,
491 ram16
= local
->sram_type
!= 8;
494 for (i
= 0; i
< param
->num_areas
; i
++) {
495 PDEBUG(DEBUG_EXTRA2
, "%s: Writing %d bytes at 0x%08x\n",
496 dev
->name
, param
->data
[i
].len
, param
->data
[i
].addr
);
497 if (hfa384x_to_aux(dev
, param
->data
[i
].addr
,
498 param
->data
[i
].len
, param
->data
[i
].data
)) {
499 printk(KERN_WARNING
"%s: RAM download at 0x%08x "
500 "(len=%d) failed\n", dev
->name
,
501 param
->data
[i
].addr
, param
->data
[i
].len
);
507 PDEBUG(DEBUG_EXTRA2
, "Disable genesis mode\n");
508 local
->func
->genesis_reset(local
, ram16
? 0x07 : 0x17);
509 if (prism2_enable_aux_port(dev
, 0)) {
510 printk(KERN_DEBUG
"%s: Failed to disable AUX port\n",
515 local
->hw_downloading
= 0;
517 PDEBUG(DEBUG_EXTRA2
, "Trying to initialize card\n");
519 * Make sure the INIT command does not generate a command completion
520 * event by disabling interrupts.
522 hfa384x_disable_interrupts(dev
);
523 if (prism2_hw_init(dev
, 1)) {
524 printk(KERN_DEBUG
"%s: Initialization after genesis mode "
525 "download failed\n", dev
->name
);
530 PDEBUG(DEBUG_EXTRA2
, "Card initialized - running PRI only\n");
531 if (prism2_hw_init2(dev
, 1)) {
532 printk(KERN_DEBUG
"%s: Initialization(2) after genesis mode "
533 "download failed\n", dev
->name
);
539 local
->hw_downloading
= 0;
544 #ifdef PRISM2_NON_VOLATILE_DOWNLOAD
545 /* Note! Non-volatile downloading functionality has not yet been tested
546 * thoroughly and it may corrupt flash image and effectively kill the card that
547 * is being updated. You have been warned. */
549 static inline int prism2_download_block(struct net_device
*dev
,
551 u32 bufaddr
, int rest_len
)
556 block_len
= rest_len
< 4096 ? rest_len
: 4096;
558 param0
= addr
& 0xffff;
561 HFA384X_OUTW(block_len
, HFA384X_PARAM2_OFF
);
562 HFA384X_OUTW(param1
, HFA384X_PARAM1_OFF
);
564 if (hfa384x_cmd_wait(dev
, HFA384X_CMDCODE_DOWNLOAD
|
565 (HFA384X_PROGMODE_ENABLE_NON_VOLATILE
<< 8),
567 printk(KERN_WARNING
"%s: Flash download command execution "
568 "failed\n", dev
->name
);
572 if (hfa384x_to_aux(dev
, bufaddr
, block_len
, data
)) {
573 printk(KERN_WARNING
"%s: flash download at 0x%08x "
574 "(len=%d) failed\n", dev
->name
, addr
, block_len
);
578 HFA384X_OUTW(0, HFA384X_PARAM2_OFF
);
579 HFA384X_OUTW(0, HFA384X_PARAM1_OFF
);
580 if (hfa384x_cmd_wait(dev
, HFA384X_CMDCODE_DOWNLOAD
|
581 (HFA384X_PROGMODE_PROGRAM_NON_VOLATILE
<< 8),
583 printk(KERN_WARNING
"%s: Flash write command execution "
584 "failed\n", dev
->name
);
592 static int prism2_download_nonvolatile(local_info_t
*local
,
593 struct prism2_download_data
*dl
)
595 struct net_device
*dev
= local
->dev
;
604 if (local
->hw_downloading
) {
605 printk(KERN_WARNING
"%s: Already downloading - aborting new "
606 "request\n", dev
->name
);
610 ret
= local
->func
->get_rid(dev
, HFA384X_RID_DOWNLOADBUFFER
,
614 printk(KERN_WARNING
"%s: Could not read download buffer "
615 "parameters\n", dev
->name
);
619 printk(KERN_DEBUG
"Download buffer: %d bytes at 0x%04x:0x%04x\n",
620 le16_to_cpu(dlbuffer
.len
),
621 le16_to_cpu(dlbuffer
.page
),
622 le16_to_cpu(dlbuffer
.offset
));
624 bufaddr
= (le16_to_cpu(dlbuffer
.page
) << 7) + le16_to_cpu(dlbuffer
.offset
);
626 local
->hw_downloading
= 1;
628 if (!local
->pri_only
) {
629 prism2_hw_shutdown(dev
, 0);
631 if (prism2_hw_init(dev
, 0)) {
632 printk(KERN_WARNING
"%s: Could not initialize card for"
633 " download\n", dev
->name
);
639 hfa384x_disable_interrupts(dev
);
641 if (prism2_enable_aux_port(dev
, 1)) {
642 printk(KERN_WARNING
"%s: Could not enable AUX port\n",
648 printk(KERN_DEBUG
"%s: starting flash download\n", dev
->name
);
649 for (i
= 0; i
< dl
->num_areas
; i
++) {
650 int rest_len
= dl
->data
[i
].len
;
653 while (rest_len
> 0) {
656 block_len
= prism2_download_block(
657 dev
, dl
->data
[i
].addr
+ data_off
,
658 dl
->data
[i
].data
+ data_off
, bufaddr
,
666 rest_len
-= block_len
;
667 data_off
+= block_len
;
671 HFA384X_OUTW(0, HFA384X_PARAM1_OFF
);
672 HFA384X_OUTW(0, HFA384X_PARAM2_OFF
);
673 if (hfa384x_cmd_wait(dev
, HFA384X_CMDCODE_DOWNLOAD
|
674 (HFA384X_PROGMODE_DISABLE
<< 8), 0)) {
675 printk(KERN_WARNING
"%s: Download command execution failed\n",
681 if (prism2_enable_aux_port(dev
, 0)) {
682 printk(KERN_DEBUG
"%s: Disabling AUX port failed\n",
684 /* continue anyway.. restart should have taken care of this */
689 local
->func
->hw_reset(dev
);
690 local
->hw_downloading
= 0;
691 if (prism2_hw_config(dev
, 2)) {
692 printk(KERN_WARNING
"%s: Card configuration after flash "
693 "download failed\n", dev
->name
);
696 printk(KERN_INFO
"%s: Card initialized successfully after "
697 "flash download\n", dev
->name
);
701 local
->hw_downloading
= 0;
704 #endif /* PRISM2_NON_VOLATILE_DOWNLOAD */
707 static void prism2_download_free_data(struct prism2_download_data
*dl
)
714 for (i
= 0; i
< dl
->num_areas
; i
++)
715 kfree(dl
->data
[i
].data
);
720 static int prism2_download(local_info_t
*local
,
721 struct prism2_download_param
*param
)
726 struct prism2_download_data
*dl
= NULL
;
728 printk(KERN_DEBUG
"prism2_download: dl_cmd=%d start_addr=0x%08x "
730 param
->dl_cmd
, param
->start_addr
, param
->num_areas
);
732 if (param
->num_areas
> 100) {
737 dl
= kzalloc(sizeof(*dl
) + param
->num_areas
*
738 sizeof(struct prism2_download_data_area
), GFP_KERNEL
);
743 dl
->dl_cmd
= param
->dl_cmd
;
744 dl
->start_addr
= param
->start_addr
;
745 dl
->num_areas
= param
->num_areas
;
746 for (i
= 0; i
< param
->num_areas
; i
++) {
748 " area %d: addr=0x%08x len=%d ptr=0x%p\n",
749 i
, param
->data
[i
].addr
, param
->data
[i
].len
,
752 dl
->data
[i
].addr
= param
->data
[i
].addr
;
753 dl
->data
[i
].len
= param
->data
[i
].len
;
755 total_len
+= param
->data
[i
].len
;
756 if (param
->data
[i
].len
> PRISM2_MAX_DOWNLOAD_AREA_LEN
||
757 total_len
> PRISM2_MAX_DOWNLOAD_LEN
) {
762 dl
->data
[i
].data
= kmalloc(dl
->data
[i
].len
, GFP_KERNEL
);
763 if (dl
->data
[i
].data
== NULL
) {
768 if (copy_from_user(dl
->data
[i
].data
, param
->data
[i
].ptr
,
769 param
->data
[i
].len
)) {
775 switch (param
->dl_cmd
) {
776 case PRISM2_DOWNLOAD_VOLATILE
:
777 case PRISM2_DOWNLOAD_VOLATILE_PERSISTENT
:
778 ret
= prism2_download_volatile(local
, dl
);
780 case PRISM2_DOWNLOAD_VOLATILE_GENESIS
:
781 case PRISM2_DOWNLOAD_VOLATILE_GENESIS_PERSISTENT
:
782 ret
= prism2_download_genesis(local
, dl
);
784 case PRISM2_DOWNLOAD_NON_VOLATILE
:
785 #ifdef PRISM2_NON_VOLATILE_DOWNLOAD
786 ret
= prism2_download_nonvolatile(local
, dl
);
787 #else /* PRISM2_NON_VOLATILE_DOWNLOAD */
788 printk(KERN_INFO
"%s: non-volatile downloading not enabled\n",
791 #endif /* PRISM2_NON_VOLATILE_DOWNLOAD */
794 printk(KERN_DEBUG
"%s: unsupported download command %d\n",
795 local
->dev
->name
, param
->dl_cmd
);
801 if (ret
== 0 && dl
&&
802 param
->dl_cmd
== PRISM2_DOWNLOAD_VOLATILE_GENESIS_PERSISTENT
) {
803 prism2_download_free_data(local
->dl_pri
);
805 } else if (ret
== 0 && dl
&&
806 param
->dl_cmd
== PRISM2_DOWNLOAD_VOLATILE_PERSISTENT
) {
807 prism2_download_free_data(local
->dl_sec
);
810 prism2_download_free_data(dl
);