1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114#include <linux/module.h>
115#include <linux/kernel.h>
116#include <linux/sched.h>
117#include <linux/types.h>
118#include <linux/slab.h>
119#include <linux/wireless.h>
120#include <linux/netdevice.h>
121#include <linux/timer.h>
122#include <linux/io.h>
123#include <linux/delay.h>
124#include <asm/byteorder.h>
125#include <linux/bitops.h>
126#include <linux/list.h>
127#include <linux/usb.h>
128#include <linux/byteorder/generic.h>
129
130#include "p80211types.h"
131#include "p80211hdr.h"
132#include "p80211mgmt.h"
133#include "p80211conv.h"
134#include "p80211msg.h"
135#include "p80211netdev.h"
136#include "p80211req.h"
137#include "p80211metadef.h"
138#include "p80211metastruct.h"
139#include "hfa384x.h"
140#include "prism2mgmt.h"
141
142enum cmd_mode {
143 DOWAIT = 0,
144 DOASYNC
145};
146
147#define THROTTLE_JIFFIES (HZ / 8)
148#define URB_ASYNC_UNLINK 0
149#define USB_QUEUE_BULK 0
150
151#define ROUNDUP64(a) (((a) + 63) & ~63)
152
153#ifdef DEBUG_USB
154static void dbprint_urb(struct urb *urb);
155#endif
156
157static void hfa384x_int_rxmonitor(struct wlandevice *wlandev,
158 struct hfa384x_usb_rxfrm *rxfrm);
159
160static void hfa384x_usb_defer(struct work_struct *data);
161
162static int submit_rx_urb(struct hfa384x *hw, gfp_t flags);
163
164static int submit_tx_urb(struct hfa384x *hw, struct urb *tx_urb, gfp_t flags);
165
166
167
168static void hfa384x_usbout_callback(struct urb *urb);
169static void hfa384x_ctlxout_callback(struct urb *urb);
170static void hfa384x_usbin_callback(struct urb *urb);
171
172static void
173hfa384x_usbin_txcompl(struct wlandevice *wlandev, union hfa384x_usbin *usbin);
174
175static void hfa384x_usbin_rx(struct wlandevice *wlandev, struct sk_buff *skb);
176
177static void hfa384x_usbin_info(struct wlandevice *wlandev,
178 union hfa384x_usbin *usbin);
179
180static void hfa384x_usbin_ctlx(struct hfa384x *hw, union hfa384x_usbin *usbin,
181 int urb_status);
182
183
184
185
186static void hfa384x_usbctlxq_run(struct hfa384x *hw);
187
188static void hfa384x_usbctlx_reqtimerfn(struct timer_list *t);
189
190static void hfa384x_usbctlx_resptimerfn(struct timer_list *t);
191
192static void hfa384x_usb_throttlefn(struct timer_list *t);
193
194static void hfa384x_usbctlx_completion_task(unsigned long data);
195
196static void hfa384x_usbctlx_reaper_task(unsigned long data);
197
198static int hfa384x_usbctlx_submit(struct hfa384x *hw,
199 struct hfa384x_usbctlx *ctlx);
200
201static void unlocked_usbctlx_complete(struct hfa384x *hw,
202 struct hfa384x_usbctlx *ctlx);
203
204struct usbctlx_completor {
205 int (*complete)(struct usbctlx_completor *completor);
206};
207
208static int
209hfa384x_usbctlx_complete_sync(struct hfa384x *hw,
210 struct hfa384x_usbctlx *ctlx,
211 struct usbctlx_completor *completor);
212
213static int
214unlocked_usbctlx_cancel_async(struct hfa384x *hw, struct hfa384x_usbctlx *ctlx);
215
216static void hfa384x_cb_status(struct hfa384x *hw,
217 const struct hfa384x_usbctlx *ctlx);
218
219static int
220usbctlx_get_status(const struct hfa384x_usb_statusresp *cmdresp,
221 struct hfa384x_cmdresult *result);
222
223static void
224usbctlx_get_rridresult(const struct hfa384x_usb_rridresp *rridresp,
225 struct hfa384x_rridresult *result);
226
227
228
229static inline int
230hfa384x_docmd(struct hfa384x *hw,
231 struct hfa384x_metacmd *cmd);
232
233static int
234hfa384x_dorrid(struct hfa384x *hw,
235 enum cmd_mode mode,
236 u16 rid,
237 void *riddata,
238 unsigned int riddatalen,
239 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
240
241static int
242hfa384x_dowrid(struct hfa384x *hw,
243 enum cmd_mode mode,
244 u16 rid,
245 void *riddata,
246 unsigned int riddatalen,
247 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
248
249static int
250hfa384x_dormem(struct hfa384x *hw,
251 u16 page,
252 u16 offset,
253 void *data,
254 unsigned int len);
255
256static int
257hfa384x_dowmem(struct hfa384x *hw,
258 u16 page,
259 u16 offset,
260 void *data,
261 unsigned int len);
262
263static int hfa384x_isgood_pdrcode(u16 pdrcode);
264
265static inline const char *ctlxstr(enum ctlx_state s)
266{
267 static const char * const ctlx_str[] = {
268 "Initial state",
269 "Complete",
270 "Request failed",
271 "Request pending",
272 "Request packet submitted",
273 "Request packet completed",
274 "Response packet completed"
275 };
276
277 return ctlx_str[s];
278};
279
280static inline struct hfa384x_usbctlx *get_active_ctlx(struct hfa384x *hw)
281{
282 return list_entry(hw->ctlxq.active.next, struct hfa384x_usbctlx, list);
283}
284
285#ifdef DEBUG_USB
286void dbprint_urb(struct urb *urb)
287{
288 pr_debug("urb->pipe=0x%08x\n", urb->pipe);
289 pr_debug("urb->status=0x%08x\n", urb->status);
290 pr_debug("urb->transfer_flags=0x%08x\n", urb->transfer_flags);
291 pr_debug("urb->transfer_buffer=0x%08x\n",
292 (unsigned int)urb->transfer_buffer);
293 pr_debug("urb->transfer_buffer_length=0x%08x\n",
294 urb->transfer_buffer_length);
295 pr_debug("urb->actual_length=0x%08x\n", urb->actual_length);
296 pr_debug("urb->setup_packet(ctl)=0x%08x\n",
297 (unsigned int)urb->setup_packet);
298 pr_debug("urb->start_frame(iso/irq)=0x%08x\n", urb->start_frame);
299 pr_debug("urb->interval(irq)=0x%08x\n", urb->interval);
300 pr_debug("urb->error_count(iso)=0x%08x\n", urb->error_count);
301 pr_debug("urb->context=0x%08x\n", (unsigned int)urb->context);
302 pr_debug("urb->complete=0x%08x\n", (unsigned int)urb->complete);
303}
304#endif
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323static int submit_rx_urb(struct hfa384x *hw, gfp_t memflags)
324{
325 struct sk_buff *skb;
326 int result;
327
328 skb = dev_alloc_skb(sizeof(union hfa384x_usbin));
329 if (!skb) {
330 result = -ENOMEM;
331 goto done;
332 }
333
334
335 usb_fill_bulk_urb(&hw->rx_urb, hw->usb,
336 hw->endp_in,
337 skb->data, sizeof(union hfa384x_usbin),
338 hfa384x_usbin_callback, hw->wlandev);
339
340 hw->rx_urb_skb = skb;
341
342 result = -ENOLINK;
343 if (!hw->wlandev->hwremoved &&
344 !test_bit(WORK_RX_HALT, &hw->usb_flags)) {
345 result = usb_submit_urb(&hw->rx_urb, memflags);
346
347
348 if (result == -EPIPE) {
349 netdev_warn(hw->wlandev->netdev,
350 "%s rx pipe stalled: requesting reset\n",
351 hw->wlandev->netdev->name);
352 if (!test_and_set_bit(WORK_RX_HALT, &hw->usb_flags))
353 schedule_work(&hw->usb_work);
354 }
355 }
356
357
358 if (result != 0) {
359 dev_kfree_skb(skb);
360 hw->rx_urb_skb = NULL;
361 }
362
363done:
364 return result;
365}
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386static int submit_tx_urb(struct hfa384x *hw, struct urb *tx_urb, gfp_t memflags)
387{
388 struct net_device *netdev = hw->wlandev->netdev;
389 int result;
390
391 result = -ENOLINK;
392 if (netif_running(netdev)) {
393 if (!hw->wlandev->hwremoved &&
394 !test_bit(WORK_TX_HALT, &hw->usb_flags)) {
395 result = usb_submit_urb(tx_urb, memflags);
396
397
398 if (result == -EPIPE) {
399 netdev_warn(hw->wlandev->netdev,
400 "%s tx pipe stalled: requesting reset\n",
401 netdev->name);
402 set_bit(WORK_TX_HALT, &hw->usb_flags);
403 schedule_work(&hw->usb_work);
404 } else if (result == 0) {
405 netif_stop_queue(netdev);
406 }
407 }
408 }
409
410 return result;
411}
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430static void hfa384x_usb_defer(struct work_struct *data)
431{
432 struct hfa384x *hw = container_of(data, struct hfa384x, usb_work);
433 struct net_device *netdev = hw->wlandev->netdev;
434
435
436
437
438 if (hw->wlandev->hwremoved)
439 return;
440
441
442 if (test_bit(WORK_RX_HALT, &hw->usb_flags)) {
443 int ret;
444
445 usb_kill_urb(&hw->rx_urb);
446
447 ret = usb_clear_halt(hw->usb, hw->endp_in);
448 if (ret != 0) {
449 netdev_err(hw->wlandev->netdev,
450 "Failed to clear rx pipe for %s: err=%d\n",
451 netdev->name, ret);
452 } else {
453 netdev_info(hw->wlandev->netdev, "%s rx pipe reset complete.\n",
454 netdev->name);
455 clear_bit(WORK_RX_HALT, &hw->usb_flags);
456 set_bit(WORK_RX_RESUME, &hw->usb_flags);
457 }
458 }
459
460
461 if (test_bit(WORK_RX_RESUME, &hw->usb_flags)) {
462 int ret;
463
464 ret = submit_rx_urb(hw, GFP_KERNEL);
465 if (ret != 0) {
466 netdev_err(hw->wlandev->netdev,
467 "Failed to resume %s rx pipe.\n",
468 netdev->name);
469 } else {
470 clear_bit(WORK_RX_RESUME, &hw->usb_flags);
471 }
472 }
473
474
475 if (test_bit(WORK_TX_HALT, &hw->usb_flags)) {
476 int ret;
477
478 usb_kill_urb(&hw->tx_urb);
479 ret = usb_clear_halt(hw->usb, hw->endp_out);
480 if (ret != 0) {
481 netdev_err(hw->wlandev->netdev,
482 "Failed to clear tx pipe for %s: err=%d\n",
483 netdev->name, ret);
484 } else {
485 netdev_info(hw->wlandev->netdev, "%s tx pipe reset complete.\n",
486 netdev->name);
487 clear_bit(WORK_TX_HALT, &hw->usb_flags);
488 set_bit(WORK_TX_RESUME, &hw->usb_flags);
489
490
491
492
493
494 hfa384x_usbctlxq_run(hw);
495 }
496 }
497
498
499 if (test_and_clear_bit(WORK_TX_RESUME, &hw->usb_flags))
500 netif_wake_queue(hw->wlandev->netdev);
501}
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525void hfa384x_create(struct hfa384x *hw, struct usb_device *usb)
526{
527 hw->usb = usb;
528
529
530 init_waitqueue_head(&hw->cmdq);
531
532
533 spin_lock_init(&hw->ctlxq.lock);
534 INIT_LIST_HEAD(&hw->ctlxq.pending);
535 INIT_LIST_HEAD(&hw->ctlxq.active);
536 INIT_LIST_HEAD(&hw->ctlxq.completing);
537 INIT_LIST_HEAD(&hw->ctlxq.reapable);
538
539
540 skb_queue_head_init(&hw->authq);
541
542 tasklet_init(&hw->reaper_bh,
543 hfa384x_usbctlx_reaper_task, (unsigned long)hw);
544 tasklet_init(&hw->completion_bh,
545 hfa384x_usbctlx_completion_task, (unsigned long)hw);
546 INIT_WORK(&hw->link_bh, prism2sta_processing_defer);
547 INIT_WORK(&hw->usb_work, hfa384x_usb_defer);
548
549 timer_setup(&hw->throttle, hfa384x_usb_throttlefn, 0);
550
551 timer_setup(&hw->resptimer, hfa384x_usbctlx_resptimerfn, 0);
552
553 timer_setup(&hw->reqtimer, hfa384x_usbctlx_reqtimerfn, 0);
554
555 usb_init_urb(&hw->rx_urb);
556 usb_init_urb(&hw->tx_urb);
557 usb_init_urb(&hw->ctlx_urb);
558
559 hw->link_status = HFA384x_LINK_NOTCONNECTED;
560 hw->state = HFA384x_STATE_INIT;
561
562 INIT_WORK(&hw->commsqual_bh, prism2sta_commsqual_defer);
563 timer_setup(&hw->commsqual_timer, prism2sta_commsqual_timer, 0);
564}
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589void hfa384x_destroy(struct hfa384x *hw)
590{
591 struct sk_buff *skb;
592
593 if (hw->state == HFA384x_STATE_RUNNING)
594 hfa384x_drvr_stop(hw);
595 hw->state = HFA384x_STATE_PREINIT;
596
597 kfree(hw->scanresults);
598 hw->scanresults = NULL;
599
600
601 while ((skb = skb_dequeue(&hw->authq)))
602 dev_kfree_skb(skb);
603}
604
605static struct hfa384x_usbctlx *usbctlx_alloc(void)
606{
607 struct hfa384x_usbctlx *ctlx;
608
609 ctlx = kzalloc(sizeof(*ctlx),
610 in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
611 if (ctlx)
612 init_completion(&ctlx->done);
613
614 return ctlx;
615}
616
617static int
618usbctlx_get_status(const struct hfa384x_usb_statusresp *cmdresp,
619 struct hfa384x_cmdresult *result)
620{
621 result->status = le16_to_cpu(cmdresp->status);
622 result->resp0 = le16_to_cpu(cmdresp->resp0);
623 result->resp1 = le16_to_cpu(cmdresp->resp1);
624 result->resp2 = le16_to_cpu(cmdresp->resp2);
625
626 pr_debug("cmdresult:status=0x%04x resp0=0x%04x resp1=0x%04x resp2=0x%04x\n",
627 result->status, result->resp0, result->resp1, result->resp2);
628
629 return result->status & HFA384x_STATUS_RESULT;
630}
631
632static void
633usbctlx_get_rridresult(const struct hfa384x_usb_rridresp *rridresp,
634 struct hfa384x_rridresult *result)
635{
636 result->rid = le16_to_cpu(rridresp->rid);
637 result->riddata = rridresp->data;
638 result->riddata_len = ((le16_to_cpu(rridresp->frmlen) - 1) * 2);
639}
640
641
642
643
644
645
646
647struct usbctlx_cmd_completor {
648 struct usbctlx_completor head;
649
650 const struct hfa384x_usb_statusresp *cmdresp;
651 struct hfa384x_cmdresult *result;
652};
653
654static inline int usbctlx_cmd_completor_fn(struct usbctlx_completor *head)
655{
656 struct usbctlx_cmd_completor *complete;
657
658 complete = (struct usbctlx_cmd_completor *)head;
659 return usbctlx_get_status(complete->cmdresp, complete->result);
660}
661
662static inline struct usbctlx_completor *
663init_cmd_completor(struct usbctlx_cmd_completor *completor,
664 const struct hfa384x_usb_statusresp *cmdresp,
665 struct hfa384x_cmdresult *result)
666{
667 completor->head.complete = usbctlx_cmd_completor_fn;
668 completor->cmdresp = cmdresp;
669 completor->result = result;
670 return &completor->head;
671}
672
673
674
675
676
677
678
679struct usbctlx_rrid_completor {
680 struct usbctlx_completor head;
681
682 const struct hfa384x_usb_rridresp *rridresp;
683 void *riddata;
684 unsigned int riddatalen;
685};
686
687static int usbctlx_rrid_completor_fn(struct usbctlx_completor *head)
688{
689 struct usbctlx_rrid_completor *complete;
690 struct hfa384x_rridresult rridresult;
691
692 complete = (struct usbctlx_rrid_completor *)head;
693 usbctlx_get_rridresult(complete->rridresp, &rridresult);
694
695
696 if (rridresult.riddata_len != complete->riddatalen) {
697 pr_warn("RID len mismatch, rid=0x%04x hlen=%d fwlen=%d\n",
698 rridresult.rid,
699 complete->riddatalen, rridresult.riddata_len);
700 return -ENODATA;
701 }
702
703 memcpy(complete->riddata, rridresult.riddata, complete->riddatalen);
704 return 0;
705}
706
707static inline struct usbctlx_completor *
708init_rrid_completor(struct usbctlx_rrid_completor *completor,
709 const struct hfa384x_usb_rridresp *rridresp,
710 void *riddata,
711 unsigned int riddatalen)
712{
713 completor->head.complete = usbctlx_rrid_completor_fn;
714 completor->rridresp = rridresp;
715 completor->riddata = riddata;
716 completor->riddatalen = riddatalen;
717 return &completor->head;
718}
719
720
721
722
723
724
725#define init_wrid_completor init_cmd_completor
726
727
728
729
730
731
732#define init_wmem_completor init_cmd_completor
733
734
735
736
737
738
739struct usbctlx_rmem_completor {
740 struct usbctlx_completor head;
741
742 const struct hfa384x_usb_rmemresp *rmemresp;
743 void *data;
744 unsigned int len;
745};
746
747static int usbctlx_rmem_completor_fn(struct usbctlx_completor *head)
748{
749 struct usbctlx_rmem_completor *complete =
750 (struct usbctlx_rmem_completor *)head;
751
752 pr_debug("rmemresp:len=%d\n", complete->rmemresp->frmlen);
753 memcpy(complete->data, complete->rmemresp->data, complete->len);
754 return 0;
755}
756
757static inline struct usbctlx_completor *
758init_rmem_completor(struct usbctlx_rmem_completor *completor,
759 struct hfa384x_usb_rmemresp *rmemresp,
760 void *data,
761 unsigned int len)
762{
763 completor->head.complete = usbctlx_rmem_completor_fn;
764 completor->rmemresp = rmemresp;
765 completor->data = data;
766 completor->len = len;
767 return &completor->head;
768}
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792static void hfa384x_cb_status(struct hfa384x *hw,
793 const struct hfa384x_usbctlx *ctlx)
794{
795 if (ctlx->usercb) {
796 struct hfa384x_cmdresult cmdresult;
797
798 if (ctlx->state != CTLX_COMPLETE) {
799 memset(&cmdresult, 0, sizeof(cmdresult));
800 cmdresult.status =
801 HFA384x_STATUS_RESULT_SET(HFA384x_CMD_ERR);
802 } else {
803 usbctlx_get_status(&ctlx->inbuf.cmdresp, &cmdresult);
804 }
805
806 ctlx->usercb(hw, &cmdresult, ctlx->usercb_data);
807 }
808}
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830int hfa384x_cmd_initialize(struct hfa384x *hw)
831{
832 int result = 0;
833 int i;
834 struct hfa384x_metacmd cmd;
835
836 cmd.cmd = HFA384x_CMDCODE_INIT;
837 cmd.parm0 = 0;
838 cmd.parm1 = 0;
839 cmd.parm2 = 0;
840
841 result = hfa384x_docmd(hw, &cmd);
842
843 pr_debug("cmdresp.init: status=0x%04x, resp0=0x%04x, resp1=0x%04x, resp2=0x%04x\n",
844 cmd.result.status,
845 cmd.result.resp0, cmd.result.resp1, cmd.result.resp2);
846 if (result == 0) {
847 for (i = 0; i < HFA384x_NUMPORTS_MAX; i++)
848 hw->port_enabled[i] = 0;
849 }
850
851 hw->link_status = HFA384x_LINK_NOTCONNECTED;
852
853 return result;
854}
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877int hfa384x_cmd_disable(struct hfa384x *hw, u16 macport)
878{
879 struct hfa384x_metacmd cmd;
880
881 cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_DISABLE) |
882 HFA384x_CMD_MACPORT_SET(macport);
883 cmd.parm0 = 0;
884 cmd.parm1 = 0;
885 cmd.parm2 = 0;
886
887 return hfa384x_docmd(hw, &cmd);
888}
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911int hfa384x_cmd_enable(struct hfa384x *hw, u16 macport)
912{
913 struct hfa384x_metacmd cmd;
914
915 cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_ENABLE) |
916 HFA384x_CMD_MACPORT_SET(macport);
917 cmd.parm0 = 0;
918 cmd.parm1 = 0;
919 cmd.parm2 = 0;
920
921 return hfa384x_docmd(hw, &cmd);
922}
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954int hfa384x_cmd_monitor(struct hfa384x *hw, u16 enable)
955{
956 struct hfa384x_metacmd cmd;
957
958 cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_MONITOR) |
959 HFA384x_CMD_AINFO_SET(enable);
960 cmd.parm0 = 0;
961 cmd.parm1 = 0;
962 cmd.parm2 = 0;
963
964 return hfa384x_docmd(hw, &cmd);
965}
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006int hfa384x_cmd_download(struct hfa384x *hw, u16 mode, u16 lowaddr,
1007 u16 highaddr, u16 codelen)
1008{
1009 struct hfa384x_metacmd cmd;
1010
1011 pr_debug("mode=%d, lowaddr=0x%04x, highaddr=0x%04x, codelen=%d\n",
1012 mode, lowaddr, highaddr, codelen);
1013
1014 cmd.cmd = (HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_DOWNLD) |
1015 HFA384x_CMD_PROGMODE_SET(mode));
1016
1017 cmd.parm0 = lowaddr;
1018 cmd.parm1 = highaddr;
1019 cmd.parm2 = codelen;
1020
1021 return hfa384x_docmd(hw, &cmd);
1022}
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048int hfa384x_corereset(struct hfa384x *hw, int holdtime,
1049 int settletime, int genesis)
1050{
1051 int result;
1052
1053 result = usb_reset_device(hw->usb);
1054 if (result < 0) {
1055 netdev_err(hw->wlandev->netdev, "usb_reset_device() failed, result=%d.\n",
1056 result);
1057 }
1058
1059 return result;
1060}
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087static int hfa384x_usbctlx_complete_sync(struct hfa384x *hw,
1088 struct hfa384x_usbctlx *ctlx,
1089 struct usbctlx_completor *completor)
1090{
1091 unsigned long flags;
1092 int result;
1093
1094 result = wait_for_completion_interruptible(&ctlx->done);
1095
1096 spin_lock_irqsave(&hw->ctlxq.lock, flags);
1097
1098
1099
1100
1101
1102cleanup:
1103 if (hw->wlandev->hwremoved) {
1104 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1105 result = -ENODEV;
1106 } else if (result != 0) {
1107 int runqueue = 0;
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118 if (ctlx == get_active_ctlx(hw)) {
1119 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1120
1121 del_singleshot_timer_sync(&hw->reqtimer);
1122 del_singleshot_timer_sync(&hw->resptimer);
1123 hw->req_timer_done = 1;
1124 hw->resp_timer_done = 1;
1125 usb_kill_urb(&hw->ctlx_urb);
1126
1127 spin_lock_irqsave(&hw->ctlxq.lock, flags);
1128
1129 runqueue = 1;
1130
1131
1132
1133
1134
1135 if (hw->wlandev->hwremoved)
1136 goto cleanup;
1137 }
1138
1139
1140
1141
1142
1143
1144 ctlx->reapable = 1;
1145 ctlx->state = CTLX_REQ_FAILED;
1146 list_move_tail(&ctlx->list, &hw->ctlxq.completing);
1147
1148 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1149
1150 if (runqueue)
1151 hfa384x_usbctlxq_run(hw);
1152 } else {
1153 if (ctlx->state == CTLX_COMPLETE) {
1154 result = completor->complete(completor);
1155 } else {
1156 netdev_warn(hw->wlandev->netdev, "CTLX[%d] error: state(%s)\n",
1157 le16_to_cpu(ctlx->outbuf.type),
1158 ctlxstr(ctlx->state));
1159 result = -EIO;
1160 }
1161
1162 list_del(&ctlx->list);
1163 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1164 kfree(ctlx);
1165 }
1166
1167 return result;
1168}
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198static inline int
1199hfa384x_docmd(struct hfa384x *hw,
1200 struct hfa384x_metacmd *cmd)
1201{
1202 int result;
1203 struct hfa384x_usbctlx *ctlx;
1204
1205 ctlx = usbctlx_alloc();
1206 if (!ctlx) {
1207 result = -ENOMEM;
1208 goto done;
1209 }
1210
1211
1212 ctlx->outbuf.cmdreq.type = cpu_to_le16(HFA384x_USB_CMDREQ);
1213 ctlx->outbuf.cmdreq.cmd = cpu_to_le16(cmd->cmd);
1214 ctlx->outbuf.cmdreq.parm0 = cpu_to_le16(cmd->parm0);
1215 ctlx->outbuf.cmdreq.parm1 = cpu_to_le16(cmd->parm1);
1216 ctlx->outbuf.cmdreq.parm2 = cpu_to_le16(cmd->parm2);
1217
1218 ctlx->outbufsize = sizeof(ctlx->outbuf.cmdreq);
1219
1220 pr_debug("cmdreq: cmd=0x%04x parm0=0x%04x parm1=0x%04x parm2=0x%04x\n",
1221 cmd->cmd, cmd->parm0, cmd->parm1, cmd->parm2);
1222
1223 ctlx->reapable = DOWAIT;
1224 ctlx->cmdcb = NULL;
1225 ctlx->usercb = NULL;
1226 ctlx->usercb_data = NULL;
1227
1228 result = hfa384x_usbctlx_submit(hw, ctlx);
1229 if (result != 0) {
1230 kfree(ctlx);
1231 } else {
1232 struct usbctlx_cmd_completor cmd_completor;
1233 struct usbctlx_completor *completor;
1234
1235 completor = init_cmd_completor(&cmd_completor,
1236 &ctlx->inbuf.cmdresp,
1237 &cmd->result);
1238
1239 result = hfa384x_usbctlx_complete_sync(hw, ctlx, completor);
1240 }
1241
1242done:
1243 return result;
1244}
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283static int
1284hfa384x_dorrid(struct hfa384x *hw,
1285 enum cmd_mode mode,
1286 u16 rid,
1287 void *riddata,
1288 unsigned int riddatalen,
1289 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1290{
1291 int result;
1292 struct hfa384x_usbctlx *ctlx;
1293
1294 ctlx = usbctlx_alloc();
1295 if (!ctlx) {
1296 result = -ENOMEM;
1297 goto done;
1298 }
1299
1300
1301 ctlx->outbuf.rridreq.type = cpu_to_le16(HFA384x_USB_RRIDREQ);
1302 ctlx->outbuf.rridreq.frmlen =
1303 cpu_to_le16(sizeof(ctlx->outbuf.rridreq.rid));
1304 ctlx->outbuf.rridreq.rid = cpu_to_le16(rid);
1305
1306 ctlx->outbufsize = sizeof(ctlx->outbuf.rridreq);
1307
1308 ctlx->reapable = mode;
1309 ctlx->cmdcb = cmdcb;
1310 ctlx->usercb = usercb;
1311 ctlx->usercb_data = usercb_data;
1312
1313
1314 result = hfa384x_usbctlx_submit(hw, ctlx);
1315 if (result != 0) {
1316 kfree(ctlx);
1317 } else if (mode == DOWAIT) {
1318 struct usbctlx_rrid_completor completor;
1319
1320 result =
1321 hfa384x_usbctlx_complete_sync(hw, ctlx,
1322 init_rrid_completor
1323 (&completor,
1324 &ctlx->inbuf.rridresp,
1325 riddata, riddatalen));
1326 }
1327
1328done:
1329 return result;
1330}
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365static int
1366hfa384x_dowrid(struct hfa384x *hw,
1367 enum cmd_mode mode,
1368 u16 rid,
1369 void *riddata,
1370 unsigned int riddatalen,
1371 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1372{
1373 int result;
1374 struct hfa384x_usbctlx *ctlx;
1375
1376 ctlx = usbctlx_alloc();
1377 if (!ctlx) {
1378 result = -ENOMEM;
1379 goto done;
1380 }
1381
1382
1383 ctlx->outbuf.wridreq.type = cpu_to_le16(HFA384x_USB_WRIDREQ);
1384 ctlx->outbuf.wridreq.frmlen = cpu_to_le16((sizeof
1385 (ctlx->outbuf.wridreq.rid) +
1386 riddatalen + 1) / 2);
1387 ctlx->outbuf.wridreq.rid = cpu_to_le16(rid);
1388 memcpy(ctlx->outbuf.wridreq.data, riddata, riddatalen);
1389
1390 ctlx->outbufsize = sizeof(ctlx->outbuf.wridreq.type) +
1391 sizeof(ctlx->outbuf.wridreq.frmlen) +
1392 sizeof(ctlx->outbuf.wridreq.rid) + riddatalen;
1393
1394 ctlx->reapable = mode;
1395 ctlx->cmdcb = cmdcb;
1396 ctlx->usercb = usercb;
1397 ctlx->usercb_data = usercb_data;
1398
1399
1400 result = hfa384x_usbctlx_submit(hw, ctlx);
1401 if (result != 0) {
1402 kfree(ctlx);
1403 } else if (mode == DOWAIT) {
1404 struct usbctlx_cmd_completor completor;
1405 struct hfa384x_cmdresult wridresult;
1406
1407 result = hfa384x_usbctlx_complete_sync(hw,
1408 ctlx,
1409 init_wrid_completor
1410 (&completor,
1411 &ctlx->inbuf.wridresp,
1412 &wridresult));
1413 }
1414
1415done:
1416 return result;
1417}
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448static int
1449hfa384x_dormem(struct hfa384x *hw,
1450 u16 page,
1451 u16 offset,
1452 void *data,
1453 unsigned int len)
1454{
1455 int result;
1456 struct hfa384x_usbctlx *ctlx;
1457
1458 ctlx = usbctlx_alloc();
1459 if (!ctlx) {
1460 result = -ENOMEM;
1461 goto done;
1462 }
1463
1464
1465 ctlx->outbuf.rmemreq.type = cpu_to_le16(HFA384x_USB_RMEMREQ);
1466 ctlx->outbuf.rmemreq.frmlen =
1467 cpu_to_le16(sizeof(ctlx->outbuf.rmemreq.offset) +
1468 sizeof(ctlx->outbuf.rmemreq.page) + len);
1469 ctlx->outbuf.rmemreq.offset = cpu_to_le16(offset);
1470 ctlx->outbuf.rmemreq.page = cpu_to_le16(page);
1471
1472 ctlx->outbufsize = sizeof(ctlx->outbuf.rmemreq);
1473
1474 pr_debug("type=0x%04x frmlen=%d offset=0x%04x page=0x%04x\n",
1475 ctlx->outbuf.rmemreq.type,
1476 ctlx->outbuf.rmemreq.frmlen,
1477 ctlx->outbuf.rmemreq.offset, ctlx->outbuf.rmemreq.page);
1478
1479 pr_debug("pktsize=%zd\n", ROUNDUP64(sizeof(ctlx->outbuf.rmemreq)));
1480
1481 ctlx->reapable = DOWAIT;
1482 ctlx->cmdcb = NULL;
1483 ctlx->usercb = NULL;
1484 ctlx->usercb_data = NULL;
1485
1486 result = hfa384x_usbctlx_submit(hw, ctlx);
1487 if (result != 0) {
1488 kfree(ctlx);
1489 } else {
1490 struct usbctlx_rmem_completor completor;
1491
1492 result =
1493 hfa384x_usbctlx_complete_sync(hw, ctlx,
1494 init_rmem_completor
1495 (&completor,
1496 &ctlx->inbuf.rmemresp, data,
1497 len));
1498 }
1499
1500done:
1501 return result;
1502}
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534static int
1535hfa384x_dowmem(struct hfa384x *hw,
1536 u16 page,
1537 u16 offset,
1538 void *data,
1539 unsigned int len)
1540{
1541 int result;
1542 struct hfa384x_usbctlx *ctlx;
1543
1544 pr_debug("page=0x%04x offset=0x%04x len=%d\n", page, offset, len);
1545
1546 ctlx = usbctlx_alloc();
1547 if (!ctlx) {
1548 result = -ENOMEM;
1549 goto done;
1550 }
1551
1552
1553 ctlx->outbuf.wmemreq.type = cpu_to_le16(HFA384x_USB_WMEMREQ);
1554 ctlx->outbuf.wmemreq.frmlen =
1555 cpu_to_le16(sizeof(ctlx->outbuf.wmemreq.offset) +
1556 sizeof(ctlx->outbuf.wmemreq.page) + len);
1557 ctlx->outbuf.wmemreq.offset = cpu_to_le16(offset);
1558 ctlx->outbuf.wmemreq.page = cpu_to_le16(page);
1559 memcpy(ctlx->outbuf.wmemreq.data, data, len);
1560
1561 ctlx->outbufsize = sizeof(ctlx->outbuf.wmemreq.type) +
1562 sizeof(ctlx->outbuf.wmemreq.frmlen) +
1563 sizeof(ctlx->outbuf.wmemreq.offset) +
1564 sizeof(ctlx->outbuf.wmemreq.page) + len;
1565
1566 ctlx->reapable = DOWAIT;
1567 ctlx->cmdcb = NULL;
1568 ctlx->usercb = NULL;
1569 ctlx->usercb_data = NULL;
1570
1571 result = hfa384x_usbctlx_submit(hw, ctlx);
1572 if (result != 0) {
1573 kfree(ctlx);
1574 } else {
1575 struct usbctlx_cmd_completor completor;
1576 struct hfa384x_cmdresult wmemresult;
1577
1578 result = hfa384x_usbctlx_complete_sync(hw,
1579 ctlx,
1580 init_wmem_completor
1581 (&completor,
1582 &ctlx->inbuf.wmemresp,
1583 &wmemresult));
1584 }
1585
1586done:
1587 return result;
1588}
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613int hfa384x_drvr_disable(struct hfa384x *hw, u16 macport)
1614{
1615 int result = 0;
1616
1617 if ((!hw->isap && macport != 0) ||
1618 (hw->isap && !(macport <= HFA384x_PORTID_MAX)) ||
1619 !(hw->port_enabled[macport])) {
1620 result = -EINVAL;
1621 } else {
1622 result = hfa384x_cmd_disable(hw, macport);
1623 if (result == 0)
1624 hw->port_enabled[macport] = 0;
1625 }
1626 return result;
1627}
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652int hfa384x_drvr_enable(struct hfa384x *hw, u16 macport)
1653{
1654 int result = 0;
1655
1656 if ((!hw->isap && macport != 0) ||
1657 (hw->isap && !(macport <= HFA384x_PORTID_MAX)) ||
1658 (hw->port_enabled[macport])) {
1659 result = -EINVAL;
1660 } else {
1661 result = hfa384x_cmd_enable(hw, macport);
1662 if (result == 0)
1663 hw->port_enabled[macport] = 1;
1664 }
1665 return result;
1666}
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690int hfa384x_drvr_flashdl_enable(struct hfa384x *hw)
1691{
1692 int result = 0;
1693 int i;
1694
1695
1696 for (i = 0; i < HFA384x_PORTID_MAX; i++) {
1697 if (hw->port_enabled[i]) {
1698 pr_debug("called when port enabled.\n");
1699 return -EINVAL;
1700 }
1701 }
1702
1703
1704 if (hw->dlstate != HFA384x_DLSTATE_DISABLED)
1705 return -EINVAL;
1706
1707
1708 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_DOWNLOADBUFFER,
1709 &hw->bufinfo, sizeof(hw->bufinfo));
1710 if (result)
1711 return result;
1712
1713 le16_to_cpus(&hw->bufinfo.page);
1714 le16_to_cpus(&hw->bufinfo.offset);
1715 le16_to_cpus(&hw->bufinfo.len);
1716 result = hfa384x_drvr_getconfig16(hw, HFA384x_RID_MAXLOADTIME,
1717 &hw->dltimeout);
1718 if (result)
1719 return result;
1720
1721 le16_to_cpus(&hw->dltimeout);
1722
1723 pr_debug("flashdl_enable\n");
1724
1725 hw->dlstate = HFA384x_DLSTATE_FLASHENABLED;
1726
1727 return result;
1728}
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750int hfa384x_drvr_flashdl_disable(struct hfa384x *hw)
1751{
1752
1753 if (hw->dlstate != HFA384x_DLSTATE_FLASHENABLED)
1754 return -EINVAL;
1755
1756 pr_debug("flashdl_enable\n");
1757
1758
1759
1760 hfa384x_cmd_download(hw, HFA384x_PROGMODE_DISABLE, 0, 0, 0);
1761 hw->dlstate = HFA384x_DLSTATE_DISABLED;
1762
1763 return 0;
1764}
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796int hfa384x_drvr_flashdl_write(struct hfa384x *hw, u32 daddr,
1797 void *buf, u32 len)
1798{
1799 int result = 0;
1800 u32 dlbufaddr;
1801 int nburns;
1802 u32 burnlen;
1803 u32 burndaddr;
1804 u16 burnlo;
1805 u16 burnhi;
1806 int nwrites;
1807 u8 *writebuf;
1808 u16 writepage;
1809 u16 writeoffset;
1810 u32 writelen;
1811 int i;
1812 int j;
1813
1814 pr_debug("daddr=0x%08x len=%d\n", daddr, len);
1815
1816
1817 if (hw->dlstate != HFA384x_DLSTATE_FLASHENABLED)
1818 return -EINVAL;
1819
1820 netdev_info(hw->wlandev->netdev,
1821 "Download %d bytes to flash @0x%06x\n", len, daddr);
1822
1823
1824
1825 dlbufaddr =
1826 HFA384x_ADDR_AUX_MKFLAT(hw->bufinfo.page, hw->bufinfo.offset);
1827 pr_debug("dlbuf.page=0x%04x dlbuf.offset=0x%04x dlbufaddr=0x%08x\n",
1828 hw->bufinfo.page, hw->bufinfo.offset, dlbufaddr);
1829
1830
1831
1832
1833
1834
1835
1836
1837 nburns = len / hw->bufinfo.len;
1838 nburns += (len % hw->bufinfo.len) ? 1 : 0;
1839
1840
1841 nwrites = hw->bufinfo.len / HFA384x_USB_RWMEM_MAXLEN;
1842 nwrites += (hw->bufinfo.len % HFA384x_USB_RWMEM_MAXLEN) ? 1 : 0;
1843
1844
1845 for (i = 0; i < nburns; i++) {
1846
1847 burnlen = (len - (hw->bufinfo.len * i)) > hw->bufinfo.len ?
1848 hw->bufinfo.len : (len - (hw->bufinfo.len * i));
1849 burndaddr = daddr + (hw->bufinfo.len * i);
1850 burnlo = HFA384x_ADDR_CMD_MKOFF(burndaddr);
1851 burnhi = HFA384x_ADDR_CMD_MKPAGE(burndaddr);
1852
1853 netdev_info(hw->wlandev->netdev, "Writing %d bytes to flash @0x%06x\n",
1854 burnlen, burndaddr);
1855
1856
1857 result = hfa384x_cmd_download(hw, HFA384x_PROGMODE_NV,
1858 burnlo, burnhi, burnlen);
1859 if (result) {
1860 netdev_err(hw->wlandev->netdev,
1861 "download(NV,lo=%x,hi=%x,len=%x) cmd failed, result=%d. Aborting d/l\n",
1862 burnlo, burnhi, burnlen, result);
1863 goto exit_proc;
1864 }
1865
1866
1867 for (j = 0; j < nwrites; j++) {
1868 writebuf = buf +
1869 (i * hw->bufinfo.len) +
1870 (j * HFA384x_USB_RWMEM_MAXLEN);
1871
1872 writepage = HFA384x_ADDR_CMD_MKPAGE(dlbufaddr +
1873 (j * HFA384x_USB_RWMEM_MAXLEN));
1874 writeoffset = HFA384x_ADDR_CMD_MKOFF(dlbufaddr +
1875 (j * HFA384x_USB_RWMEM_MAXLEN));
1876
1877 writelen = burnlen - (j * HFA384x_USB_RWMEM_MAXLEN);
1878 writelen = writelen > HFA384x_USB_RWMEM_MAXLEN ?
1879 HFA384x_USB_RWMEM_MAXLEN : writelen;
1880
1881 result = hfa384x_dowmem(hw,
1882 writepage,
1883 writeoffset,
1884 writebuf, writelen);
1885 }
1886
1887
1888 result = hfa384x_cmd_download(hw,
1889 HFA384x_PROGMODE_NVWRITE,
1890 0, 0, 0);
1891 if (result) {
1892 netdev_err(hw->wlandev->netdev,
1893 "download(NVWRITE,lo=%x,hi=%x,len=%x) cmd failed, result=%d. Aborting d/l\n",
1894 burnlo, burnhi, burnlen, result);
1895 goto exit_proc;
1896 }
1897
1898
1899 }
1900
1901exit_proc:
1902
1903
1904
1905
1906
1907 return result;
1908}
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936int hfa384x_drvr_getconfig(struct hfa384x *hw, u16 rid, void *buf, u16 len)
1937{
1938 return hfa384x_dorrid(hw, DOWAIT, rid, buf, len, NULL, NULL, NULL);
1939}
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965int
1966hfa384x_drvr_setconfig_async(struct hfa384x *hw,
1967 u16 rid,
1968 void *buf,
1969 u16 len, ctlx_usercb_t usercb, void *usercb_data)
1970{
1971 return hfa384x_dowrid(hw, DOASYNC, rid, buf, len, hfa384x_cb_status,
1972 usercb, usercb_data);
1973}
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994int hfa384x_drvr_ramdl_disable(struct hfa384x *hw)
1995{
1996
1997 if (hw->dlstate != HFA384x_DLSTATE_RAMENABLED)
1998 return -EINVAL;
1999
2000 pr_debug("ramdl_disable()\n");
2001
2002
2003
2004 hfa384x_cmd_download(hw, HFA384x_PROGMODE_DISABLE, 0, 0, 0);
2005 hw->dlstate = HFA384x_DLSTATE_DISABLED;
2006
2007 return 0;
2008}
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035int hfa384x_drvr_ramdl_enable(struct hfa384x *hw, u32 exeaddr)
2036{
2037 int result = 0;
2038 u16 lowaddr;
2039 u16 hiaddr;
2040 int i;
2041
2042
2043 for (i = 0; i < HFA384x_PORTID_MAX; i++) {
2044 if (hw->port_enabled[i]) {
2045 netdev_err(hw->wlandev->netdev,
2046 "Can't download with a macport enabled.\n");
2047 return -EINVAL;
2048 }
2049 }
2050
2051
2052 if (hw->dlstate != HFA384x_DLSTATE_DISABLED) {
2053 netdev_err(hw->wlandev->netdev,
2054 "Download state not disabled.\n");
2055 return -EINVAL;
2056 }
2057
2058 pr_debug("ramdl_enable, exeaddr=0x%08x\n", exeaddr);
2059
2060
2061 lowaddr = HFA384x_ADDR_CMD_MKOFF(exeaddr);
2062 hiaddr = HFA384x_ADDR_CMD_MKPAGE(exeaddr);
2063
2064 result = hfa384x_cmd_download(hw, HFA384x_PROGMODE_RAM,
2065 lowaddr, hiaddr, 0);
2066
2067 if (result == 0) {
2068
2069 hw->dlstate = HFA384x_DLSTATE_RAMENABLED;
2070 } else {
2071 pr_debug("cmd_download(0x%04x, 0x%04x) failed, result=%d.\n",
2072 lowaddr, hiaddr, result);
2073 }
2074
2075 return result;
2076}
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105int hfa384x_drvr_ramdl_write(struct hfa384x *hw, u32 daddr, void *buf, u32 len)
2106{
2107 int result = 0;
2108 int nwrites;
2109 u8 *data = buf;
2110 int i;
2111 u32 curraddr;
2112 u16 currpage;
2113 u16 curroffset;
2114 u16 currlen;
2115
2116
2117 if (hw->dlstate != HFA384x_DLSTATE_RAMENABLED)
2118 return -EINVAL;
2119
2120 netdev_info(hw->wlandev->netdev, "Writing %d bytes to ram @0x%06x\n",
2121 len, daddr);
2122
2123
2124 nwrites = len / HFA384x_USB_RWMEM_MAXLEN;
2125 nwrites += len % HFA384x_USB_RWMEM_MAXLEN ? 1 : 0;
2126
2127
2128 for (i = 0; i < nwrites; i++) {
2129
2130 curraddr = daddr + (i * HFA384x_USB_RWMEM_MAXLEN);
2131 currpage = HFA384x_ADDR_CMD_MKPAGE(curraddr);
2132 curroffset = HFA384x_ADDR_CMD_MKOFF(curraddr);
2133 currlen = len - (i * HFA384x_USB_RWMEM_MAXLEN);
2134 if (currlen > HFA384x_USB_RWMEM_MAXLEN)
2135 currlen = HFA384x_USB_RWMEM_MAXLEN;
2136
2137
2138 result = hfa384x_dowmem(hw,
2139 currpage,
2140 curroffset,
2141 data + (i * HFA384x_USB_RWMEM_MAXLEN),
2142 currlen);
2143
2144 if (result)
2145 break;
2146
2147
2148 }
2149
2150 return result;
2151}
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185int hfa384x_drvr_readpda(struct hfa384x *hw, void *buf, unsigned int len)
2186{
2187 int result = 0;
2188 __le16 *pda = buf;
2189 int pdaok = 0;
2190 int morepdrs = 1;
2191 int currpdr = 0;
2192 size_t i;
2193 u16 pdrlen;
2194 u16 pdrcode;
2195 u16 currpage;
2196 u16 curroffset;
2197 struct pdaloc {
2198 u32 cardaddr;
2199 u16 auxctl;
2200 } pdaloc[] = {
2201 {
2202 HFA3842_PDA_BASE, 0}, {
2203 HFA3841_PDA_BASE, 0}, {
2204 HFA3841_PDA_BOGUS_BASE, 0}
2205 };
2206
2207
2208 for (i = 0; i < ARRAY_SIZE(pdaloc); i++) {
2209
2210 currpage = HFA384x_ADDR_CMD_MKPAGE(pdaloc[i].cardaddr);
2211 curroffset = HFA384x_ADDR_CMD_MKOFF(pdaloc[i].cardaddr);
2212
2213
2214 result = hfa384x_dormem(hw, currpage, curroffset, buf,
2215 len);
2216
2217 if (result) {
2218 netdev_warn(hw->wlandev->netdev,
2219 "Read from index %zd failed, continuing\n",
2220 i);
2221 continue;
2222 }
2223
2224
2225 pdaok = 1;
2226 morepdrs = 1;
2227 while (pdaok && morepdrs) {
2228 pdrlen = le16_to_cpu(pda[currpdr]) * 2;
2229 pdrcode = le16_to_cpu(pda[currpdr + 1]);
2230
2231 if (pdrlen > HFA384x_PDR_LEN_MAX || pdrlen == 0) {
2232 netdev_err(hw->wlandev->netdev,
2233 "pdrlen invalid=%d\n", pdrlen);
2234 pdaok = 0;
2235 break;
2236 }
2237
2238 if (!hfa384x_isgood_pdrcode(pdrcode)) {
2239 netdev_err(hw->wlandev->netdev, "pdrcode invalid=%d\n",
2240 pdrcode);
2241 pdaok = 0;
2242 break;
2243 }
2244
2245 if (pdrcode == HFA384x_PDR_END_OF_PDA)
2246 morepdrs = 0;
2247
2248
2249 if (morepdrs) {
2250
2251 currpdr += le16_to_cpu(pda[currpdr]) + 1;
2252 }
2253 }
2254 if (pdaok) {
2255 netdev_info(hw->wlandev->netdev,
2256 "PDA Read from 0x%08x in %s space.\n",
2257 pdaloc[i].cardaddr,
2258 pdaloc[i].auxctl == 0 ? "EXTDS" :
2259 pdaloc[i].auxctl == 1 ? "NV" :
2260 pdaloc[i].auxctl == 2 ? "PHY" :
2261 pdaloc[i].auxctl == 3 ? "ICSRAM" :
2262 "<bogus auxctl>");
2263 break;
2264 }
2265 }
2266 result = pdaok ? 0 : -ENODATA;
2267
2268 if (result)
2269 pr_debug("Failure: pda is not okay\n");
2270
2271 return result;
2272}
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296int hfa384x_drvr_setconfig(struct hfa384x *hw, u16 rid, void *buf, u16 len)
2297{
2298 return hfa384x_dowrid(hw, DOWAIT, rid, buf, len, NULL, NULL, NULL);
2299}
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321int hfa384x_drvr_start(struct hfa384x *hw)
2322{
2323 int result, result1, result2;
2324 u16 status;
2325
2326 might_sleep();
2327
2328
2329
2330
2331
2332
2333 result =
2334 usb_get_std_status(hw->usb, USB_RECIP_ENDPOINT, hw->endp_in,
2335 &status);
2336 if (result < 0) {
2337 netdev_err(hw->wlandev->netdev, "Cannot get bulk in endpoint status.\n");
2338 goto done;
2339 }
2340 if ((status == 1) && usb_clear_halt(hw->usb, hw->endp_in))
2341 netdev_err(hw->wlandev->netdev, "Failed to reset bulk in endpoint.\n");
2342
2343 result =
2344 usb_get_std_status(hw->usb, USB_RECIP_ENDPOINT, hw->endp_out,
2345 &status);
2346 if (result < 0) {
2347 netdev_err(hw->wlandev->netdev, "Cannot get bulk out endpoint status.\n");
2348 goto done;
2349 }
2350 if ((status == 1) && usb_clear_halt(hw->usb, hw->endp_out))
2351 netdev_err(hw->wlandev->netdev, "Failed to reset bulk out endpoint.\n");
2352
2353
2354 usb_kill_urb(&hw->rx_urb);
2355
2356
2357 result = submit_rx_urb(hw, GFP_KERNEL);
2358 if (result != 0) {
2359 netdev_err(hw->wlandev->netdev,
2360 "Fatal, failed to submit RX URB, result=%d\n",
2361 result);
2362 goto done;
2363 }
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375 result1 = hfa384x_cmd_initialize(hw);
2376 msleep(1000);
2377 result = hfa384x_cmd_initialize(hw);
2378 result2 = result;
2379 if (result1 != 0) {
2380 if (result2 != 0) {
2381 netdev_err(hw->wlandev->netdev,
2382 "cmd_initialize() failed on two attempts, results %d and %d\n",
2383 result1, result2);
2384 usb_kill_urb(&hw->rx_urb);
2385 goto done;
2386 } else {
2387 pr_debug("First cmd_initialize() failed (result %d),\n",
2388 result1);
2389 pr_debug("but second attempt succeeded. All should be ok\n");
2390 }
2391 } else if (result2 != 0) {
2392 netdev_warn(hw->wlandev->netdev, "First cmd_initialize() succeeded, but second attempt failed (result=%d)\n",
2393 result2);
2394 netdev_warn(hw->wlandev->netdev,
2395 "Most likely the card will be functional\n");
2396 goto done;
2397 }
2398
2399 hw->state = HFA384x_STATE_RUNNING;
2400
2401done:
2402 return result;
2403}
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425int hfa384x_drvr_stop(struct hfa384x *hw)
2426{
2427 int i;
2428
2429 might_sleep();
2430
2431
2432
2433
2434 if (!hw->wlandev->hwremoved) {
2435
2436 hfa384x_cmd_initialize(hw);
2437
2438
2439 usb_kill_urb(&hw->rx_urb);
2440 }
2441
2442 hw->link_status = HFA384x_LINK_NOTCONNECTED;
2443 hw->state = HFA384x_STATE_INIT;
2444
2445 del_timer_sync(&hw->commsqual_timer);
2446
2447
2448 for (i = 0; i < HFA384x_NUMPORTS_MAX; i++)
2449 hw->port_enabled[i] = 0;
2450
2451 return 0;
2452}
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476int hfa384x_drvr_txframe(struct hfa384x *hw, struct sk_buff *skb,
2477 union p80211_hdr *p80211_hdr,
2478 struct p80211_metawep *p80211_wep)
2479{
2480 int usbpktlen = sizeof(struct hfa384x_tx_frame);
2481 int result;
2482 int ret;
2483 char *ptr;
2484
2485 if (hw->tx_urb.status == -EINPROGRESS) {
2486 netdev_warn(hw->wlandev->netdev, "TX URB already in use\n");
2487 result = 3;
2488 goto exit;
2489 }
2490
2491
2492
2493 memset(&hw->txbuff.txfrm.desc, 0, sizeof(hw->txbuff.txfrm.desc));
2494
2495
2496 hw->txbuff.type = cpu_to_le16(HFA384x_USB_TXFRM);
2497
2498
2499 hw->txbuff.txfrm.desc.sw_support = 0x0123;
2500
2501
2502
2503
2504
2505#if defined(DOBOTH)
2506 hw->txbuff.txfrm.desc.tx_control =
2507 HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
2508 HFA384x_TX_TXEX_SET(1) | HFA384x_TX_TXOK_SET(1);
2509#elif defined(DOEXC)
2510 hw->txbuff.txfrm.desc.tx_control =
2511 HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
2512 HFA384x_TX_TXEX_SET(1) | HFA384x_TX_TXOK_SET(0);
2513#else
2514 hw->txbuff.txfrm.desc.tx_control =
2515 HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
2516 HFA384x_TX_TXEX_SET(0) | HFA384x_TX_TXOK_SET(0);
2517#endif
2518 cpu_to_le16s(&hw->txbuff.txfrm.desc.tx_control);
2519
2520
2521 memcpy(&hw->txbuff.txfrm.desc.frame_control, p80211_hdr,
2522 sizeof(union p80211_hdr));
2523
2524
2525 if (p80211_wep->data) {
2526 hw->txbuff.txfrm.desc.data_len = cpu_to_le16(skb->len + 8);
2527 usbpktlen += 8;
2528 } else {
2529 hw->txbuff.txfrm.desc.data_len = cpu_to_le16(skb->len);
2530 }
2531
2532 usbpktlen += skb->len;
2533
2534
2535 ptr = hw->txbuff.txfrm.data;
2536 if (p80211_wep->data) {
2537 memcpy(ptr, p80211_wep->iv, sizeof(p80211_wep->iv));
2538 ptr += sizeof(p80211_wep->iv);
2539 memcpy(ptr, p80211_wep->data, skb->len);
2540 } else {
2541 memcpy(ptr, skb->data, skb->len);
2542 }
2543
2544 ptr += skb->len;
2545
2546
2547 if (p80211_wep->data)
2548 memcpy(ptr, p80211_wep->icv, sizeof(p80211_wep->icv));
2549
2550
2551 usb_fill_bulk_urb(&hw->tx_urb, hw->usb,
2552 hw->endp_out,
2553 &hw->txbuff, ROUNDUP64(usbpktlen),
2554 hfa384x_usbout_callback, hw->wlandev);
2555 hw->tx_urb.transfer_flags |= USB_QUEUE_BULK;
2556
2557 result = 1;
2558 ret = submit_tx_urb(hw, &hw->tx_urb, GFP_ATOMIC);
2559 if (ret != 0) {
2560 netdev_err(hw->wlandev->netdev,
2561 "submit_tx_urb() failed, error=%d\n", ret);
2562 result = 3;
2563 }
2564
2565exit:
2566 return result;
2567}
2568
2569void hfa384x_tx_timeout(struct wlandevice *wlandev)
2570{
2571 struct hfa384x *hw = wlandev->priv;
2572 unsigned long flags;
2573
2574 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2575
2576 if (!hw->wlandev->hwremoved) {
2577 int sched;
2578
2579 sched = !test_and_set_bit(WORK_TX_HALT, &hw->usb_flags);
2580 sched |= !test_and_set_bit(WORK_RX_HALT, &hw->usb_flags);
2581 if (sched)
2582 schedule_work(&hw->usb_work);
2583 }
2584
2585 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2586}
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602static void hfa384x_usbctlx_reaper_task(unsigned long data)
2603{
2604 struct hfa384x *hw = (struct hfa384x *)data;
2605 struct hfa384x_usbctlx *ctlx, *temp;
2606 unsigned long flags;
2607
2608 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2609
2610
2611
2612
2613 list_for_each_entry_safe(ctlx, temp, &hw->ctlxq.reapable, list) {
2614 list_del(&ctlx->list);
2615 kfree(ctlx);
2616 }
2617
2618 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2619}
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636static void hfa384x_usbctlx_completion_task(unsigned long data)
2637{
2638 struct hfa384x *hw = (struct hfa384x *)data;
2639 struct hfa384x_usbctlx *ctlx, *temp;
2640 unsigned long flags;
2641
2642 int reap = 0;
2643
2644 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2645
2646
2647
2648
2649 list_for_each_entry_safe(ctlx, temp, &hw->ctlxq.completing, list) {
2650
2651
2652
2653 if (ctlx->cmdcb) {
2654 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2655 ctlx->cmdcb(hw, ctlx);
2656 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2657
2658
2659
2660
2661 ctlx->cmdcb = NULL;
2662
2663
2664
2665
2666 if (hw->wlandev->hwremoved) {
2667 reap = 0;
2668 break;
2669 }
2670 }
2671
2672
2673
2674
2675
2676
2677 if (ctlx->reapable) {
2678
2679
2680
2681
2682
2683 list_move_tail(&ctlx->list, &hw->ctlxq.reapable);
2684 reap = 1;
2685 }
2686
2687 complete(&ctlx->done);
2688 }
2689 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2690
2691 if (reap)
2692 tasklet_schedule(&hw->reaper_bh);
2693}
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713static int unlocked_usbctlx_cancel_async(struct hfa384x *hw,
2714 struct hfa384x_usbctlx *ctlx)
2715{
2716 int ret;
2717
2718
2719
2720
2721
2722
2723 hw->ctlx_urb.transfer_flags |= URB_ASYNC_UNLINK;
2724 ret = usb_unlink_urb(&hw->ctlx_urb);
2725
2726 if (ret != -EINPROGRESS) {
2727
2728
2729
2730
2731
2732
2733 ctlx->state = CTLX_REQ_FAILED;
2734 unlocked_usbctlx_complete(hw, ctlx);
2735 ret = 0;
2736 }
2737
2738 return ret;
2739}
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764static void unlocked_usbctlx_complete(struct hfa384x *hw,
2765 struct hfa384x_usbctlx *ctlx)
2766{
2767
2768
2769
2770
2771 list_move_tail(&ctlx->list, &hw->ctlxq.completing);
2772 tasklet_schedule(&hw->completion_bh);
2773
2774 switch (ctlx->state) {
2775 case CTLX_COMPLETE:
2776 case CTLX_REQ_FAILED:
2777
2778 break;
2779
2780 default:
2781 netdev_err(hw->wlandev->netdev, "CTLX[%d] not in a terminating state(%s)\n",
2782 le16_to_cpu(ctlx->outbuf.type),
2783 ctlxstr(ctlx->state));
2784 break;
2785 }
2786}
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805static void hfa384x_usbctlxq_run(struct hfa384x *hw)
2806{
2807 unsigned long flags;
2808
2809
2810 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2811
2812
2813
2814
2815
2816
2817
2818
2819 if (!list_empty(&hw->ctlxq.active) ||
2820 test_bit(WORK_TX_HALT, &hw->usb_flags) || hw->wlandev->hwremoved)
2821 goto unlock;
2822
2823 while (!list_empty(&hw->ctlxq.pending)) {
2824 struct hfa384x_usbctlx *head;
2825 int result;
2826
2827
2828 head = list_entry(hw->ctlxq.pending.next,
2829 struct hfa384x_usbctlx, list);
2830
2831
2832 list_move_tail(&head->list, &hw->ctlxq.active);
2833
2834
2835 usb_fill_bulk_urb(&hw->ctlx_urb, hw->usb,
2836 hw->endp_out,
2837 &head->outbuf, ROUNDUP64(head->outbufsize),
2838 hfa384x_ctlxout_callback, hw);
2839 hw->ctlx_urb.transfer_flags |= USB_QUEUE_BULK;
2840
2841
2842 result = usb_submit_urb(&hw->ctlx_urb, GFP_ATOMIC);
2843 if (result == 0) {
2844
2845 head->state = CTLX_REQ_SUBMITTED;
2846
2847
2848 hw->req_timer_done = 0;
2849 hw->reqtimer.expires = jiffies + HZ;
2850 add_timer(&hw->reqtimer);
2851
2852
2853 hw->resp_timer_done = 0;
2854 hw->resptimer.expires = jiffies + 2 * HZ;
2855 add_timer(&hw->resptimer);
2856
2857 break;
2858 }
2859
2860 if (result == -EPIPE) {
2861
2862
2863
2864
2865 netdev_warn(hw->wlandev->netdev,
2866 "%s tx pipe stalled: requesting reset\n",
2867 hw->wlandev->netdev->name);
2868 list_move(&head->list, &hw->ctlxq.pending);
2869 set_bit(WORK_TX_HALT, &hw->usb_flags);
2870 schedule_work(&hw->usb_work);
2871 break;
2872 }
2873
2874 if (result == -ESHUTDOWN) {
2875 netdev_warn(hw->wlandev->netdev, "%s urb shutdown!\n",
2876 hw->wlandev->netdev->name);
2877 break;
2878 }
2879
2880 netdev_err(hw->wlandev->netdev, "Failed to submit CTLX[%d]: error=%d\n",
2881 le16_to_cpu(head->outbuf.type), result);
2882 unlocked_usbctlx_complete(hw, head);
2883 }
2884
2885unlock:
2886 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2887}
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906static void hfa384x_usbin_callback(struct urb *urb)
2907{
2908 struct wlandevice *wlandev = urb->context;
2909 struct hfa384x *hw;
2910 union hfa384x_usbin *usbin;
2911 struct sk_buff *skb = NULL;
2912 int result;
2913 int urb_status;
2914 u16 type;
2915
2916 enum USBIN_ACTION {
2917 HANDLE,
2918 RESUBMIT,
2919 ABORT
2920 } action;
2921
2922 if (!wlandev || !wlandev->netdev || wlandev->hwremoved)
2923 goto exit;
2924
2925 hw = wlandev->priv;
2926 if (!hw)
2927 goto exit;
2928
2929 skb = hw->rx_urb_skb;
2930 if (!skb || (skb->data != urb->transfer_buffer)) {
2931 WARN_ON(1);
2932 return;
2933 }
2934
2935 hw->rx_urb_skb = NULL;
2936
2937
2938 switch (urb->status) {
2939 case 0:
2940 action = HANDLE;
2941
2942
2943 if (urb->actual_length == 0) {
2944 wlandev->netdev->stats.rx_errors++;
2945 wlandev->netdev->stats.rx_length_errors++;
2946 action = RESUBMIT;
2947 }
2948 break;
2949
2950 case -EPIPE:
2951 netdev_warn(hw->wlandev->netdev, "%s rx pipe stalled: requesting reset\n",
2952 wlandev->netdev->name);
2953 if (!test_and_set_bit(WORK_RX_HALT, &hw->usb_flags))
2954 schedule_work(&hw->usb_work);
2955 wlandev->netdev->stats.rx_errors++;
2956 action = ABORT;
2957 break;
2958
2959 case -EILSEQ:
2960 case -ETIMEDOUT:
2961 case -EPROTO:
2962 if (!test_and_set_bit(THROTTLE_RX, &hw->usb_flags) &&
2963 !timer_pending(&hw->throttle)) {
2964 mod_timer(&hw->throttle, jiffies + THROTTLE_JIFFIES);
2965 }
2966 wlandev->netdev->stats.rx_errors++;
2967 action = ABORT;
2968 break;
2969
2970 case -EOVERFLOW:
2971 wlandev->netdev->stats.rx_over_errors++;
2972 action = RESUBMIT;
2973 break;
2974
2975 case -ENODEV:
2976 case -ESHUTDOWN:
2977 pr_debug("status=%d, device removed.\n", urb->status);
2978 action = ABORT;
2979 break;
2980
2981 case -ENOENT:
2982 case -ECONNRESET:
2983 pr_debug("status=%d, urb explicitly unlinked.\n", urb->status);
2984 action = ABORT;
2985 break;
2986
2987 default:
2988 pr_debug("urb status=%d, transfer flags=0x%x\n",
2989 urb->status, urb->transfer_flags);
2990 wlandev->netdev->stats.rx_errors++;
2991 action = RESUBMIT;
2992 break;
2993 }
2994
2995
2996 urb_status = urb->status;
2997 usbin = (union hfa384x_usbin *)urb->transfer_buffer;
2998
2999 if (action != ABORT) {
3000
3001 result = submit_rx_urb(hw, GFP_ATOMIC);
3002
3003 if (result != 0) {
3004 netdev_err(hw->wlandev->netdev,
3005 "Fatal, failed to resubmit rx_urb. error=%d\n",
3006 result);
3007 }
3008 }
3009
3010
3011
3012
3013
3014 type = le16_to_cpu(usbin->type);
3015 if (HFA384x_USB_ISRXFRM(type)) {
3016 if (action == HANDLE) {
3017 if (usbin->txfrm.desc.sw_support == 0x0123) {
3018 hfa384x_usbin_txcompl(wlandev, usbin);
3019 } else {
3020 skb_put(skb, sizeof(*usbin));
3021 hfa384x_usbin_rx(wlandev, skb);
3022 skb = NULL;
3023 }
3024 }
3025 goto exit;
3026 }
3027 if (HFA384x_USB_ISTXFRM(type)) {
3028 if (action == HANDLE)
3029 hfa384x_usbin_txcompl(wlandev, usbin);
3030 goto exit;
3031 }
3032 switch (type) {
3033 case HFA384x_USB_INFOFRM:
3034 if (action == ABORT)
3035 goto exit;
3036 if (action == HANDLE)
3037 hfa384x_usbin_info(wlandev, usbin);
3038 break;
3039
3040 case HFA384x_USB_CMDRESP:
3041 case HFA384x_USB_WRIDRESP:
3042 case HFA384x_USB_RRIDRESP:
3043 case HFA384x_USB_WMEMRESP:
3044 case HFA384x_USB_RMEMRESP:
3045
3046 hfa384x_usbin_ctlx(hw, usbin, urb_status);
3047 break;
3048
3049 case HFA384x_USB_BUFAVAIL:
3050 pr_debug("Received BUFAVAIL packet, frmlen=%d\n",
3051 usbin->bufavail.frmlen);
3052 break;
3053
3054 case HFA384x_USB_ERROR:
3055 pr_debug("Received USB_ERROR packet, errortype=%d\n",
3056 usbin->usberror.errortype);
3057 break;
3058
3059 default:
3060 pr_debug("Unrecognized USBIN packet, type=%x, status=%d\n",
3061 usbin->type, urb_status);
3062 break;
3063 }
3064
3065exit:
3066
3067 if (skb)
3068 dev_kfree_skb(skb);
3069}
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092static void hfa384x_usbin_ctlx(struct hfa384x *hw, union hfa384x_usbin *usbin,
3093 int urb_status)
3094{
3095 struct hfa384x_usbctlx *ctlx;
3096 int run_queue = 0;
3097 unsigned long flags;
3098
3099retry:
3100 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3101
3102
3103
3104
3105
3106 if (list_empty(&hw->ctlxq.active))
3107 goto unlock;
3108
3109
3110
3111
3112
3113
3114
3115 if (del_timer(&hw->resptimer) == 0) {
3116 if (hw->resp_timer_done == 0) {
3117 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3118 goto retry;
3119 }
3120 } else {
3121 hw->resp_timer_done = 1;
3122 }
3123
3124 ctlx = get_active_ctlx(hw);
3125
3126 if (urb_status != 0) {
3127
3128
3129
3130
3131
3132 if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0)
3133 run_queue = 1;
3134 } else {
3135 const __le16 intype = (usbin->type & ~cpu_to_le16(0x8000));
3136
3137
3138
3139
3140 if (ctlx->outbuf.type != intype) {
3141 netdev_warn(hw->wlandev->netdev,
3142 "Expected IN[%d], received IN[%d] - ignored.\n",
3143 le16_to_cpu(ctlx->outbuf.type),
3144 le16_to_cpu(intype));
3145 goto unlock;
3146 }
3147
3148
3149 memcpy(&ctlx->inbuf, usbin, sizeof(ctlx->inbuf));
3150
3151 switch (ctlx->state) {
3152 case CTLX_REQ_SUBMITTED:
3153
3154
3155
3156
3157
3158 pr_debug("Causality violation: please reboot Universe\n");
3159 ctlx->state = CTLX_RESP_COMPLETE;
3160 break;
3161
3162 case CTLX_REQ_COMPLETE:
3163
3164
3165
3166
3167
3168 ctlx->state = CTLX_COMPLETE;
3169 unlocked_usbctlx_complete(hw, ctlx);
3170 run_queue = 1;
3171 break;
3172
3173 default:
3174
3175
3176
3177 netdev_err(hw->wlandev->netdev,
3178 "Matched IN URB, CTLX[%d] in invalid state(%s). Discarded.\n",
3179 le16_to_cpu(ctlx->outbuf.type),
3180 ctlxstr(ctlx->state));
3181 if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0)
3182 run_queue = 1;
3183 break;
3184 }
3185 }
3186
3187unlock:
3188 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3189
3190 if (run_queue)
3191 hfa384x_usbctlxq_run(hw);
3192}
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212static void hfa384x_usbin_txcompl(struct wlandevice *wlandev,
3213 union hfa384x_usbin *usbin)
3214{
3215 u16 status;
3216
3217 status = le16_to_cpu(usbin->type);
3218
3219
3220 if (HFA384x_TXSTATUS_ISERROR(status))
3221 prism2sta_ev_txexc(wlandev, status);
3222 else
3223 prism2sta_ev_tx(wlandev, status);
3224}
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244static void hfa384x_usbin_rx(struct wlandevice *wlandev, struct sk_buff *skb)
3245{
3246 union hfa384x_usbin *usbin = (union hfa384x_usbin *)skb->data;
3247 struct hfa384x *hw = wlandev->priv;
3248 int hdrlen;
3249 struct p80211_rxmeta *rxmeta;
3250 u16 data_len;
3251 u16 fc;
3252 u16 status;
3253
3254
3255 le16_to_cpus(&usbin->rxfrm.desc.status);
3256 le32_to_cpus(&usbin->rxfrm.desc.time);
3257
3258
3259 status = HFA384x_RXSTATUS_MACPORT_GET(usbin->rxfrm.desc.status);
3260
3261 switch (status) {
3262 case 0:
3263 fc = le16_to_cpu(usbin->rxfrm.desc.frame_control);
3264
3265
3266 if ((wlandev->hostwep & HOSTWEP_EXCLUDEUNENCRYPTED) &&
3267 !WLAN_GET_FC_ISWEP(fc)) {
3268 break;
3269 }
3270
3271 data_len = le16_to_cpu(usbin->rxfrm.desc.data_len);
3272
3273
3274 hdrlen = p80211_headerlen(fc);
3275
3276
3277 skb_pull(skb, sizeof(struct hfa384x_rx_frame));
3278
3279
3280
3281
3282 memmove(skb_push(skb, hdrlen),
3283 &usbin->rxfrm.desc.frame_control, hdrlen);
3284
3285 skb->dev = wlandev->netdev;
3286
3287
3288 skb_trim(skb, data_len + hdrlen);
3289
3290
3291 memset(skb_put(skb, WLAN_CRC_LEN), 0xff, WLAN_CRC_LEN);
3292
3293 skb_reset_mac_header(skb);
3294
3295
3296 p80211skb_rxmeta_attach(wlandev, skb);
3297 rxmeta = p80211skb_rxmeta(skb);
3298 rxmeta->mactime = usbin->rxfrm.desc.time;
3299 rxmeta->rxrate = usbin->rxfrm.desc.rate;
3300 rxmeta->signal = usbin->rxfrm.desc.signal - hw->dbmadjust;
3301 rxmeta->noise = usbin->rxfrm.desc.silence - hw->dbmadjust;
3302
3303 p80211netdev_rx(wlandev, skb);
3304
3305 break;
3306
3307 case 7:
3308 if (!HFA384x_RXSTATUS_ISFCSERR(usbin->rxfrm.desc.status)) {
3309
3310 hfa384x_int_rxmonitor(wlandev, &usbin->rxfrm);
3311 dev_kfree_skb(skb);
3312 } else {
3313 pr_debug("Received monitor frame: FCSerr set\n");
3314 }
3315 break;
3316
3317 default:
3318 netdev_warn(hw->wlandev->netdev,
3319 "Received frame on unsupported port=%d\n",
3320 status);
3321 break;
3322 }
3323}
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347static void hfa384x_int_rxmonitor(struct wlandevice *wlandev,
3348 struct hfa384x_usb_rxfrm *rxfrm)
3349{
3350 struct hfa384x_rx_frame *rxdesc = &rxfrm->desc;
3351 unsigned int hdrlen = 0;
3352 unsigned int datalen = 0;
3353 unsigned int skblen = 0;
3354 u8 *datap;
3355 u16 fc;
3356 struct sk_buff *skb;
3357 struct hfa384x *hw = wlandev->priv;
3358
3359
3360
3361 fc = le16_to_cpu(rxdesc->frame_control);
3362 hdrlen = p80211_headerlen(fc);
3363 datalen = le16_to_cpu(rxdesc->data_len);
3364
3365
3366 skblen = sizeof(struct p80211_caphdr) + hdrlen + datalen + WLAN_CRC_LEN;
3367
3368
3369 if (skblen >
3370 (sizeof(struct p80211_caphdr) +
3371 WLAN_HDR_A4_LEN + WLAN_DATA_MAXLEN + WLAN_CRC_LEN)) {
3372 pr_debug("overlen frm: len=%zd\n",
3373 skblen - sizeof(struct p80211_caphdr));
3374
3375 return;
3376 }
3377
3378 skb = dev_alloc_skb(skblen);
3379 if (!skb)
3380 return;
3381
3382
3383 if ((wlandev->netdev->type == ARPHRD_IEEE80211_PRISM) &&
3384 (hw->sniffhdr != 0)) {
3385 struct p80211_caphdr *caphdr;
3386
3387 datap = skb_put(skb, sizeof(struct p80211_caphdr));
3388 caphdr = (struct p80211_caphdr *)datap;
3389
3390 caphdr->version = htonl(P80211CAPTURE_VERSION);
3391 caphdr->length = htonl(sizeof(struct p80211_caphdr));
3392 caphdr->mactime = __cpu_to_be64(rxdesc->time * 1000);
3393 caphdr->hosttime = __cpu_to_be64(jiffies);
3394 caphdr->phytype = htonl(4);
3395 caphdr->channel = htonl(hw->sniff_channel);
3396 caphdr->datarate = htonl(rxdesc->rate);
3397 caphdr->antenna = htonl(0);
3398 caphdr->priority = htonl(0);
3399 caphdr->ssi_type = htonl(3);
3400 caphdr->ssi_signal = htonl(rxdesc->signal);
3401 caphdr->ssi_noise = htonl(rxdesc->silence);
3402 caphdr->preamble = htonl(0);
3403 caphdr->encoding = htonl(1);
3404 }
3405
3406
3407
3408
3409 skb_put_data(skb, &rxdesc->frame_control, hdrlen);
3410
3411
3412 if (datalen > 0) {
3413 datap = skb_put_data(skb, rxfrm->data, datalen);
3414
3415
3416 if (*(datap - hdrlen + 1) & 0x40)
3417 if ((*(datap) == 0xaa) && (*(datap + 1) == 0xaa))
3418
3419 *(datap - hdrlen + 1) &= 0xbf;
3420 }
3421
3422 if (hw->sniff_fcs) {
3423
3424 datap = skb_put(skb, WLAN_CRC_LEN);
3425 memset(datap, 0xff, WLAN_CRC_LEN);
3426 }
3427
3428
3429 p80211netdev_rx(wlandev, skb);
3430}
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450static void hfa384x_usbin_info(struct wlandevice *wlandev,
3451 union hfa384x_usbin *usbin)
3452{
3453 le16_to_cpus(&usbin->infofrm.info.framelen);
3454 prism2sta_ev_info(wlandev, &usbin->infofrm.info);
3455}
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474static void hfa384x_usbout_callback(struct urb *urb)
3475{
3476 struct wlandevice *wlandev = urb->context;
3477
3478#ifdef DEBUG_USB
3479 dbprint_urb(urb);
3480#endif
3481
3482 if (wlandev && wlandev->netdev) {
3483 switch (urb->status) {
3484 case 0:
3485 prism2sta_ev_alloc(wlandev);
3486 break;
3487
3488 case -EPIPE: {
3489 struct hfa384x *hw = wlandev->priv;
3490
3491 netdev_warn(hw->wlandev->netdev,
3492 "%s tx pipe stalled: requesting reset\n",
3493 wlandev->netdev->name);
3494 if (!test_and_set_bit(WORK_TX_HALT, &hw->usb_flags))
3495 schedule_work(&hw->usb_work);
3496 wlandev->netdev->stats.tx_errors++;
3497 break;
3498 }
3499
3500 case -EPROTO:
3501 case -ETIMEDOUT:
3502 case -EILSEQ: {
3503 struct hfa384x *hw = wlandev->priv;
3504
3505 if (!test_and_set_bit(THROTTLE_TX, &hw->usb_flags) &&
3506 !timer_pending(&hw->throttle)) {
3507 mod_timer(&hw->throttle,
3508 jiffies + THROTTLE_JIFFIES);
3509 }
3510 wlandev->netdev->stats.tx_errors++;
3511 netif_stop_queue(wlandev->netdev);
3512 break;
3513 }
3514
3515 case -ENOENT:
3516 case -ESHUTDOWN:
3517
3518 break;
3519
3520 default:
3521 netdev_info(wlandev->netdev, "unknown urb->status=%d\n",
3522 urb->status);
3523 wlandev->netdev->stats.tx_errors++;
3524 break;
3525 }
3526 }
3527}
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546static void hfa384x_ctlxout_callback(struct urb *urb)
3547{
3548 struct hfa384x *hw = urb->context;
3549 int delete_resptimer = 0;
3550 int timer_ok = 1;
3551 int run_queue = 0;
3552 struct hfa384x_usbctlx *ctlx;
3553 unsigned long flags;
3554
3555 pr_debug("urb->status=%d\n", urb->status);
3556#ifdef DEBUG_USB
3557 dbprint_urb(urb);
3558#endif
3559 if ((urb->status == -ESHUTDOWN) ||
3560 (urb->status == -ENODEV) || !hw)
3561 return;
3562
3563retry:
3564 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3565
3566
3567
3568
3569
3570
3571
3572 if (list_empty(&hw->ctlxq.active)) {
3573 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3574 return;
3575 }
3576
3577
3578
3579
3580
3581 if (del_timer(&hw->reqtimer) == 0) {
3582 if (hw->req_timer_done == 0) {
3583
3584
3585
3586
3587
3588 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3589 goto retry;
3590 }
3591 } else {
3592 hw->req_timer_done = 1;
3593 }
3594
3595 ctlx = get_active_ctlx(hw);
3596
3597 if (urb->status == 0) {
3598
3599 switch (ctlx->state) {
3600 case CTLX_REQ_SUBMITTED:
3601
3602 ctlx->state = CTLX_REQ_COMPLETE;
3603 break;
3604
3605 case CTLX_RESP_COMPLETE:
3606
3607
3608
3609 ctlx->state = CTLX_COMPLETE;
3610 unlocked_usbctlx_complete(hw, ctlx);
3611 run_queue = 1;
3612 break;
3613
3614 default:
3615
3616 netdev_err(hw->wlandev->netdev,
3617 "Illegal CTLX[%d] success state(%s, %d) in OUT URB\n",
3618 le16_to_cpu(ctlx->outbuf.type),
3619 ctlxstr(ctlx->state), urb->status);
3620 break;
3621 }
3622 } else {
3623
3624 if ((urb->status == -EPIPE) &&
3625 !test_and_set_bit(WORK_TX_HALT, &hw->usb_flags)) {
3626 netdev_warn(hw->wlandev->netdev,
3627 "%s tx pipe stalled: requesting reset\n",
3628 hw->wlandev->netdev->name);
3629 schedule_work(&hw->usb_work);
3630 }
3631
3632
3633
3634
3635 ctlx->state = CTLX_REQ_FAILED;
3636 unlocked_usbctlx_complete(hw, ctlx);
3637 delete_resptimer = 1;
3638 run_queue = 1;
3639 }
3640
3641delresp:
3642 if (delete_resptimer) {
3643 timer_ok = del_timer(&hw->resptimer);
3644 if (timer_ok != 0)
3645 hw->resp_timer_done = 1;
3646 }
3647
3648 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3649
3650 if (!timer_ok && (hw->resp_timer_done == 0)) {
3651 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3652 goto delresp;
3653 }
3654
3655 if (run_queue)
3656 hfa384x_usbctlxq_run(hw);
3657}
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678static void hfa384x_usbctlx_reqtimerfn(struct timer_list *t)
3679{
3680 struct hfa384x *hw = from_timer(hw, t, reqtimer);
3681 unsigned long flags;
3682
3683 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3684
3685 hw->req_timer_done = 1;
3686
3687
3688
3689
3690 if (!list_empty(&hw->ctlxq.active)) {
3691
3692
3693
3694
3695 hw->ctlx_urb.transfer_flags |= URB_ASYNC_UNLINK;
3696 if (usb_unlink_urb(&hw->ctlx_urb) == -EINPROGRESS) {
3697 struct hfa384x_usbctlx *ctlx = get_active_ctlx(hw);
3698
3699 ctlx->state = CTLX_REQ_FAILED;
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710 if (del_timer(&hw->resptimer) != 0)
3711 hw->resp_timer_done = 1;
3712 }
3713 }
3714
3715 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3716}
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737static void hfa384x_usbctlx_resptimerfn(struct timer_list *t)
3738{
3739 struct hfa384x *hw = from_timer(hw, t, resptimer);
3740 unsigned long flags;
3741
3742 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3743
3744 hw->resp_timer_done = 1;
3745
3746
3747
3748
3749 if (!list_empty(&hw->ctlxq.active)) {
3750 struct hfa384x_usbctlx *ctlx = get_active_ctlx(hw);
3751
3752 if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0) {
3753 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3754 hfa384x_usbctlxq_run(hw);
3755 return;
3756 }
3757 }
3758 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3759}
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777static void hfa384x_usb_throttlefn(struct timer_list *t)
3778{
3779 struct hfa384x *hw = from_timer(hw, t, throttle);
3780 unsigned long flags;
3781
3782 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3783
3784
3785
3786
3787
3788 pr_debug("flags=0x%lx\n", hw->usb_flags);
3789 if (!hw->wlandev->hwremoved &&
3790 ((test_and_clear_bit(THROTTLE_RX, &hw->usb_flags) &&
3791 !test_and_set_bit(WORK_RX_RESUME, &hw->usb_flags)) |
3792 (test_and_clear_bit(THROTTLE_TX, &hw->usb_flags) &&
3793 !test_and_set_bit(WORK_TX_RESUME, &hw->usb_flags))
3794 )) {
3795 schedule_work(&hw->usb_work);
3796 }
3797
3798 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3799}
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820static int hfa384x_usbctlx_submit(struct hfa384x *hw,
3821 struct hfa384x_usbctlx *ctlx)
3822{
3823 unsigned long flags;
3824
3825 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3826
3827 if (hw->wlandev->hwremoved) {
3828 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3829 return -ENODEV;
3830 }
3831
3832 ctlx->state = CTLX_PENDING;
3833 list_add_tail(&ctlx->list, &hw->ctlxq.pending);
3834 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3835 hfa384x_usbctlxq_run(hw);
3836
3837 return 0;
3838}
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857static int hfa384x_isgood_pdrcode(u16 pdrcode)
3858{
3859 switch (pdrcode) {
3860 case HFA384x_PDR_END_OF_PDA:
3861 case HFA384x_PDR_PCB_PARTNUM:
3862 case HFA384x_PDR_PDAVER:
3863 case HFA384x_PDR_NIC_SERIAL:
3864 case HFA384x_PDR_MKK_MEASUREMENTS:
3865 case HFA384x_PDR_NIC_RAMSIZE:
3866 case HFA384x_PDR_MFISUPRANGE:
3867 case HFA384x_PDR_CFISUPRANGE:
3868 case HFA384x_PDR_NICID:
3869 case HFA384x_PDR_MAC_ADDRESS:
3870 case HFA384x_PDR_REGDOMAIN:
3871 case HFA384x_PDR_ALLOWED_CHANNEL:
3872 case HFA384x_PDR_DEFAULT_CHANNEL:
3873 case HFA384x_PDR_TEMPTYPE:
3874 case HFA384x_PDR_IFR_SETTING:
3875 case HFA384x_PDR_RFR_SETTING:
3876 case HFA384x_PDR_HFA3861_BASELINE:
3877 case HFA384x_PDR_HFA3861_SHADOW:
3878 case HFA384x_PDR_HFA3861_IFRF:
3879 case HFA384x_PDR_HFA3861_CHCALSP:
3880 case HFA384x_PDR_HFA3861_CHCALI:
3881 case HFA384x_PDR_3842_NIC_CONFIG:
3882 case HFA384x_PDR_USB_ID:
3883 case HFA384x_PDR_PCI_ID:
3884 case HFA384x_PDR_PCI_IFCONF:
3885 case HFA384x_PDR_PCI_PMCONF:
3886 case HFA384x_PDR_RFENRGY:
3887 case HFA384x_PDR_HFA3861_MANF_TESTSP:
3888 case HFA384x_PDR_HFA3861_MANF_TESTI:
3889
3890 return 1;
3891 default:
3892 if (pdrcode < 0x1000) {
3893
3894 pr_debug("Encountered unknown PDR#=0x%04x, assuming it's ok.\n",
3895 pdrcode);
3896 return 1;
3897 }
3898 break;
3899 }
3900
3901 pr_debug("Encountered unknown PDR#=0x%04x, (>=0x1000), assuming it's bad.\n",
3902 pdrcode);
3903 return 0;
3904}
3905