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 #define prism2_download_aux_dump_npages 65536
179 struct prism2_download_aux_dump
{
184 static int prism2_download_aux_dump_proc_show(struct seq_file
*m
, void *v
)
186 struct prism2_download_aux_dump
*ctx
= m
->private;
188 hfa384x_from_aux(ctx
->local
->dev
, (unsigned long)v
- 1, 0x80, ctx
->page
);
189 seq_write(m
, ctx
->page
, 0x80);
193 static void *prism2_download_aux_dump_proc_start(struct seq_file
*m
, loff_t
*_pos
)
195 struct prism2_download_aux_dump
*ctx
= m
->private;
196 prism2_enable_aux_port(ctx
->local
->dev
, 1);
197 if (*_pos
>= prism2_download_aux_dump_npages
)
199 return (void *)((unsigned long)*_pos
+ 1);
202 static void *prism2_download_aux_dump_proc_next(struct seq_file
*m
, void *v
, loff_t
*_pos
)
205 if (*_pos
>= prism2_download_aux_dump_npages
)
207 return (void *)((unsigned long)*_pos
+ 1);
210 static void prism2_download_aux_dump_proc_stop(struct seq_file
*m
, void *v
)
212 struct prism2_download_aux_dump
*ctx
= m
->private;
213 prism2_enable_aux_port(ctx
->local
->dev
, 0);
216 static const struct seq_operations prism2_download_aux_dump_proc_seqops
= {
217 .start
= prism2_download_aux_dump_proc_start
,
218 .next
= prism2_download_aux_dump_proc_next
,
219 .stop
= prism2_download_aux_dump_proc_stop
,
220 .show
= prism2_download_aux_dump_proc_show
,
223 static int prism2_download_aux_dump_proc_open(struct inode
*inode
, struct file
*file
)
225 int ret
= seq_open_private(file
, &prism2_download_aux_dump_proc_seqops
,
226 sizeof(struct prism2_download_aux_dump
));
228 struct seq_file
*m
= file
->private_data
;
229 m
->private = PDE_DATA(inode
);
234 static const struct file_operations prism2_download_aux_dump_proc_fops
= {
235 .open
= prism2_download_aux_dump_proc_open
,
238 .release
= seq_release_private
,
242 static u8
* prism2_read_pda(struct net_device
*dev
)
245 int res
, i
, found
= 0;
246 #define NUM_PDA_ADDRS 4
247 unsigned int pda_addr
[NUM_PDA_ADDRS
] = {
248 0x7f0000 /* others than HFA3841 */,
249 0x3f0000 /* HFA3841 */,
250 0x390000 /* apparently used in older cards */,
251 0x7f0002 /* Intel PRO/Wireless 2011B (PCI) */,
254 buf
= kmalloc(PRISM2_PDA_SIZE
, GFP_KERNEL
);
258 /* Note: wlan card should be in initial state (just after init cmd)
259 * and no other operations should be performed concurrently. */
261 prism2_enable_aux_port(dev
, 1);
263 for (i
= 0; i
< NUM_PDA_ADDRS
; i
++) {
264 PDEBUG(DEBUG_EXTRA2
, "%s: trying to read PDA from 0x%08x",
265 dev
->name
, pda_addr
[i
]);
266 res
= hfa384x_from_aux(dev
, pda_addr
[i
], PRISM2_PDA_SIZE
, buf
);
269 if (res
== 0 && prism2_pda_ok(buf
)) {
270 PDEBUG2(DEBUG_EXTRA2
, ": OK\n");
274 PDEBUG2(DEBUG_EXTRA2
, ": failed\n");
278 prism2_enable_aux_port(dev
, 0);
281 printk(KERN_DEBUG
"%s: valid PDA not found\n", dev
->name
);
290 static int prism2_download_volatile(local_info_t
*local
,
291 struct prism2_download_data
*param
)
293 struct net_device
*dev
= local
->dev
;
297 if (local
->hw_downloading
) {
298 printk(KERN_WARNING
"%s: Already downloading - aborting new "
299 "request\n", dev
->name
);
303 local
->hw_downloading
= 1;
304 if (local
->pri_only
) {
305 hfa384x_disable_interrupts(dev
);
307 prism2_hw_shutdown(dev
, 0);
309 if (prism2_hw_init(dev
, 0)) {
310 printk(KERN_WARNING
"%s: Could not initialize card for"
311 " download\n", dev
->name
);
317 if (prism2_enable_aux_port(dev
, 1)) {
318 printk(KERN_WARNING
"%s: Could not enable AUX port\n",
324 param0
= param
->start_addr
& 0xffff;
325 param1
= param
->start_addr
>> 16;
327 HFA384X_OUTW(0, HFA384X_PARAM2_OFF
);
328 HFA384X_OUTW(param1
, HFA384X_PARAM1_OFF
);
329 if (hfa384x_cmd_wait(dev
, HFA384X_CMDCODE_DOWNLOAD
|
330 (HFA384X_PROGMODE_ENABLE_VOLATILE
<< 8),
332 printk(KERN_WARNING
"%s: Download command execution failed\n",
338 for (i
= 0; i
< param
->num_areas
; i
++) {
339 PDEBUG(DEBUG_EXTRA2
, "%s: Writing %d bytes at 0x%08x\n",
340 dev
->name
, param
->data
[i
].len
, param
->data
[i
].addr
);
341 if (hfa384x_to_aux(dev
, param
->data
[i
].addr
,
342 param
->data
[i
].len
, param
->data
[i
].data
)) {
343 printk(KERN_WARNING
"%s: RAM download at 0x%08x "
344 "(len=%d) failed\n", dev
->name
,
345 param
->data
[i
].addr
, param
->data
[i
].len
);
351 HFA384X_OUTW(param1
, HFA384X_PARAM1_OFF
);
352 HFA384X_OUTW(0, HFA384X_PARAM2_OFF
);
353 if (hfa384x_cmd_no_wait(dev
, HFA384X_CMDCODE_DOWNLOAD
|
354 (HFA384X_PROGMODE_DISABLE
<< 8), param0
)) {
355 printk(KERN_WARNING
"%s: Download command execution failed\n",
360 /* ProgMode disable causes the hardware to restart itself from the
361 * given starting address. Give hw some time and ACK command just in
362 * case restart did not happen. */
364 HFA384X_OUTW(HFA384X_EV_CMD
, HFA384X_EVACK_OFF
);
366 if (prism2_enable_aux_port(dev
, 0)) {
367 printk(KERN_DEBUG
"%s: Disabling AUX port failed\n",
369 /* continue anyway.. restart should have taken care of this */
373 local
->hw_downloading
= 0;
374 if (prism2_hw_config(dev
, 2)) {
375 printk(KERN_WARNING
"%s: Card configuration after RAM "
376 "download failed\n", dev
->name
);
382 local
->hw_downloading
= 0;
387 static int prism2_enable_genesis(local_info_t
*local
, int hcr
)
389 struct net_device
*dev
= local
->dev
;
390 u8 initseq
[4] = { 0x00, 0xe1, 0xa1, 0xff };
393 printk(KERN_DEBUG
"%s: test Genesis mode with HCR 0x%02x\n",
395 local
->func
->cor_sreset(local
);
396 hfa384x_to_aux(dev
, 0x7e0038, sizeof(initseq
), initseq
);
397 local
->func
->genesis_reset(local
, hcr
);
400 hfa384x_from_aux(dev
, 0x7e0038, sizeof(readbuf
), readbuf
);
401 hfa384x_to_aux(dev
, 0x7e0038, sizeof(initseq
), initseq
);
402 hfa384x_from_aux(dev
, 0x7e0038, sizeof(readbuf
), readbuf
);
404 if (memcmp(initseq
, readbuf
, sizeof(initseq
)) == 0) {
405 printk(KERN_DEBUG
"Readback test succeeded, HCR 0x%02x\n",
409 printk(KERN_DEBUG
"Readback test failed, HCR 0x%02x "
410 "write %02x %02x %02x %02x read %02x %02x %02x %02x\n",
411 hcr
, initseq
[0], initseq
[1], initseq
[2], initseq
[3],
412 readbuf
[0], readbuf
[1], readbuf
[2], readbuf
[3]);
418 static int prism2_get_ram_size(local_info_t
*local
)
422 /* Try to enable genesis mode; 0x1F for x8 SRAM or 0x0F for x16 SRAM */
423 if (prism2_enable_genesis(local
, 0x1f) == 0)
425 else if (prism2_enable_genesis(local
, 0x0f) == 0)
430 /* Disable genesis mode */
431 local
->func
->genesis_reset(local
, ret
== 16 ? 0x07 : 0x17);
437 static int prism2_download_genesis(local_info_t
*local
,
438 struct prism2_download_data
*param
)
440 struct net_device
*dev
= local
->dev
;
444 if (local
->hw_downloading
) {
445 printk(KERN_WARNING
"%s: Already downloading - aborting new "
446 "request\n", dev
->name
);
450 if (!local
->func
->genesis_reset
|| !local
->func
->cor_sreset
) {
451 printk(KERN_INFO
"%s: Genesis mode downloading not supported "
452 "with this hwmodel\n", dev
->name
);
456 local
->hw_downloading
= 1;
458 if (prism2_enable_aux_port(dev
, 1)) {
459 printk(KERN_DEBUG
"%s: failed to enable AUX port\n",
465 if (local
->sram_type
== -1) {
466 /* 0x1F for x8 SRAM or 0x0F for x16 SRAM */
467 if (prism2_enable_genesis(local
, 0x1f) == 0) {
469 PDEBUG(DEBUG_EXTRA2
, "%s: Genesis mode OK using x8 "
470 "SRAM\n", dev
->name
);
471 } else if (prism2_enable_genesis(local
, 0x0f) == 0) {
473 PDEBUG(DEBUG_EXTRA2
, "%s: Genesis mode OK using x16 "
474 "SRAM\n", dev
->name
);
476 printk(KERN_DEBUG
"%s: Could not initiate genesis "
477 "mode\n", dev
->name
);
482 if (prism2_enable_genesis(local
, local
->sram_type
== 8 ?
484 printk(KERN_DEBUG
"%s: Failed to set Genesis "
485 "mode (sram_type=%d)\n", dev
->name
,
490 ram16
= local
->sram_type
!= 8;
493 for (i
= 0; i
< param
->num_areas
; i
++) {
494 PDEBUG(DEBUG_EXTRA2
, "%s: Writing %d bytes at 0x%08x\n",
495 dev
->name
, param
->data
[i
].len
, param
->data
[i
].addr
);
496 if (hfa384x_to_aux(dev
, param
->data
[i
].addr
,
497 param
->data
[i
].len
, param
->data
[i
].data
)) {
498 printk(KERN_WARNING
"%s: RAM download at 0x%08x "
499 "(len=%d) failed\n", dev
->name
,
500 param
->data
[i
].addr
, param
->data
[i
].len
);
506 PDEBUG(DEBUG_EXTRA2
, "Disable genesis mode\n");
507 local
->func
->genesis_reset(local
, ram16
? 0x07 : 0x17);
508 if (prism2_enable_aux_port(dev
, 0)) {
509 printk(KERN_DEBUG
"%s: Failed to disable AUX port\n",
514 local
->hw_downloading
= 0;
516 PDEBUG(DEBUG_EXTRA2
, "Trying to initialize card\n");
518 * Make sure the INIT command does not generate a command completion
519 * event by disabling interrupts.
521 hfa384x_disable_interrupts(dev
);
522 if (prism2_hw_init(dev
, 1)) {
523 printk(KERN_DEBUG
"%s: Initialization after genesis mode "
524 "download failed\n", dev
->name
);
529 PDEBUG(DEBUG_EXTRA2
, "Card initialized - running PRI only\n");
530 if (prism2_hw_init2(dev
, 1)) {
531 printk(KERN_DEBUG
"%s: Initialization(2) after genesis mode "
532 "download failed\n", dev
->name
);
538 local
->hw_downloading
= 0;
543 #ifdef PRISM2_NON_VOLATILE_DOWNLOAD
544 /* Note! Non-volatile downloading functionality has not yet been tested
545 * thoroughly and it may corrupt flash image and effectively kill the card that
546 * is being updated. You have been warned. */
548 static inline int prism2_download_block(struct net_device
*dev
,
550 u32 bufaddr
, int rest_len
)
555 block_len
= rest_len
< 4096 ? rest_len
: 4096;
557 param0
= addr
& 0xffff;
560 HFA384X_OUTW(block_len
, HFA384X_PARAM2_OFF
);
561 HFA384X_OUTW(param1
, HFA384X_PARAM1_OFF
);
563 if (hfa384x_cmd_wait(dev
, HFA384X_CMDCODE_DOWNLOAD
|
564 (HFA384X_PROGMODE_ENABLE_NON_VOLATILE
<< 8),
566 printk(KERN_WARNING
"%s: Flash download command execution "
567 "failed\n", dev
->name
);
571 if (hfa384x_to_aux(dev
, bufaddr
, block_len
, data
)) {
572 printk(KERN_WARNING
"%s: flash download at 0x%08x "
573 "(len=%d) failed\n", dev
->name
, addr
, block_len
);
577 HFA384X_OUTW(0, HFA384X_PARAM2_OFF
);
578 HFA384X_OUTW(0, HFA384X_PARAM1_OFF
);
579 if (hfa384x_cmd_wait(dev
, HFA384X_CMDCODE_DOWNLOAD
|
580 (HFA384X_PROGMODE_PROGRAM_NON_VOLATILE
<< 8),
582 printk(KERN_WARNING
"%s: Flash write command execution "
583 "failed\n", dev
->name
);
591 static int prism2_download_nonvolatile(local_info_t
*local
,
592 struct prism2_download_data
*dl
)
594 struct net_device
*dev
= local
->dev
;
603 if (local
->hw_downloading
) {
604 printk(KERN_WARNING
"%s: Already downloading - aborting new "
605 "request\n", dev
->name
);
609 ret
= local
->func
->get_rid(dev
, HFA384X_RID_DOWNLOADBUFFER
,
613 printk(KERN_WARNING
"%s: Could not read download buffer "
614 "parameters\n", dev
->name
);
618 printk(KERN_DEBUG
"Download buffer: %d bytes at 0x%04x:0x%04x\n",
619 le16_to_cpu(dlbuffer
.len
),
620 le16_to_cpu(dlbuffer
.page
),
621 le16_to_cpu(dlbuffer
.offset
));
623 bufaddr
= (le16_to_cpu(dlbuffer
.page
) << 7) + le16_to_cpu(dlbuffer
.offset
);
625 local
->hw_downloading
= 1;
627 if (!local
->pri_only
) {
628 prism2_hw_shutdown(dev
, 0);
630 if (prism2_hw_init(dev
, 0)) {
631 printk(KERN_WARNING
"%s: Could not initialize card for"
632 " download\n", dev
->name
);
638 hfa384x_disable_interrupts(dev
);
640 if (prism2_enable_aux_port(dev
, 1)) {
641 printk(KERN_WARNING
"%s: Could not enable AUX port\n",
647 printk(KERN_DEBUG
"%s: starting flash download\n", dev
->name
);
648 for (i
= 0; i
< dl
->num_areas
; i
++) {
649 int rest_len
= dl
->data
[i
].len
;
652 while (rest_len
> 0) {
655 block_len
= prism2_download_block(
656 dev
, dl
->data
[i
].addr
+ data_off
,
657 dl
->data
[i
].data
+ data_off
, bufaddr
,
665 rest_len
-= block_len
;
666 data_off
+= block_len
;
670 HFA384X_OUTW(0, HFA384X_PARAM1_OFF
);
671 HFA384X_OUTW(0, HFA384X_PARAM2_OFF
);
672 if (hfa384x_cmd_wait(dev
, HFA384X_CMDCODE_DOWNLOAD
|
673 (HFA384X_PROGMODE_DISABLE
<< 8), 0)) {
674 printk(KERN_WARNING
"%s: Download command execution failed\n",
680 if (prism2_enable_aux_port(dev
, 0)) {
681 printk(KERN_DEBUG
"%s: Disabling AUX port failed\n",
683 /* continue anyway.. restart should have taken care of this */
688 local
->func
->hw_reset(dev
);
689 local
->hw_downloading
= 0;
690 if (prism2_hw_config(dev
, 2)) {
691 printk(KERN_WARNING
"%s: Card configuration after flash "
692 "download failed\n", dev
->name
);
695 printk(KERN_INFO
"%s: Card initialized successfully after "
696 "flash download\n", dev
->name
);
700 local
->hw_downloading
= 0;
703 #endif /* PRISM2_NON_VOLATILE_DOWNLOAD */
706 static void prism2_download_free_data(struct prism2_download_data
*dl
)
713 for (i
= 0; i
< dl
->num_areas
; i
++)
714 kfree(dl
->data
[i
].data
);
719 static int prism2_download(local_info_t
*local
,
720 struct prism2_download_param
*param
)
725 struct prism2_download_data
*dl
= NULL
;
727 printk(KERN_DEBUG
"prism2_download: dl_cmd=%d start_addr=0x%08x "
729 param
->dl_cmd
, param
->start_addr
, param
->num_areas
);
731 if (param
->num_areas
> 100) {
736 dl
= kzalloc(sizeof(*dl
) + param
->num_areas
*
737 sizeof(struct prism2_download_data_area
), GFP_KERNEL
);
742 dl
->dl_cmd
= param
->dl_cmd
;
743 dl
->start_addr
= param
->start_addr
;
744 dl
->num_areas
= param
->num_areas
;
745 for (i
= 0; i
< param
->num_areas
; i
++) {
747 " area %d: addr=0x%08x len=%d ptr=0x%p\n",
748 i
, param
->data
[i
].addr
, param
->data
[i
].len
,
751 dl
->data
[i
].addr
= param
->data
[i
].addr
;
752 dl
->data
[i
].len
= param
->data
[i
].len
;
754 total_len
+= param
->data
[i
].len
;
755 if (param
->data
[i
].len
> PRISM2_MAX_DOWNLOAD_AREA_LEN
||
756 total_len
> PRISM2_MAX_DOWNLOAD_LEN
) {
761 dl
->data
[i
].data
= kmalloc(dl
->data
[i
].len
, GFP_KERNEL
);
762 if (dl
->data
[i
].data
== NULL
) {
767 if (copy_from_user(dl
->data
[i
].data
, param
->data
[i
].ptr
,
768 param
->data
[i
].len
)) {
774 switch (param
->dl_cmd
) {
775 case PRISM2_DOWNLOAD_VOLATILE
:
776 case PRISM2_DOWNLOAD_VOLATILE_PERSISTENT
:
777 ret
= prism2_download_volatile(local
, dl
);
779 case PRISM2_DOWNLOAD_VOLATILE_GENESIS
:
780 case PRISM2_DOWNLOAD_VOLATILE_GENESIS_PERSISTENT
:
781 ret
= prism2_download_genesis(local
, dl
);
783 case PRISM2_DOWNLOAD_NON_VOLATILE
:
784 #ifdef PRISM2_NON_VOLATILE_DOWNLOAD
785 ret
= prism2_download_nonvolatile(local
, dl
);
786 #else /* PRISM2_NON_VOLATILE_DOWNLOAD */
787 printk(KERN_INFO
"%s: non-volatile downloading not enabled\n",
790 #endif /* PRISM2_NON_VOLATILE_DOWNLOAD */
793 printk(KERN_DEBUG
"%s: unsupported download command %d\n",
794 local
->dev
->name
, param
->dl_cmd
);
800 if (ret
== 0 && dl
&&
801 param
->dl_cmd
== PRISM2_DOWNLOAD_VOLATILE_GENESIS_PERSISTENT
) {
802 prism2_download_free_data(local
->dl_pri
);
804 } else if (ret
== 0 && dl
&&
805 param
->dl_cmd
== PRISM2_DOWNLOAD_VOLATILE_PERSISTENT
) {
806 prism2_download_free_data(local
->dl_sec
);
809 prism2_download_free_data(dl
);