113 #include <linux/module.h>
114 #include <linux/kernel.h>
115 #include <linux/sched.h>
116 #include <linux/types.h>
117 #include <linux/slab.h>
118 #include <linux/wireless.h>
119 #include <linux/netdevice.h>
123 #include <asm/byteorder.h>
124 #include <linux/bitops.h>
125 #include <linux/list.h>
129 #define SUBMIT_URB(u, f) usb_submit_urb(u, f)
148 #define THROTTLE_JIFFIES (HZ/8)
149 #define URB_ASYNC_UNLINK 0
150 #define USB_QUEUE_BULK 0
152 #define ROUNDUP64(a) (((a)+63)&~63)
155 static void dbprint_urb(
struct urb *
urb);
165 static int submit_tx_urb(hfa384x_t *
hw,
struct urb *tx_urb,
gfp_t flags);
169 static void hfa384x_usbout_callback(
struct urb *
urb);
170 static void hfa384x_ctlxout_callback(
struct urb *
urb);
171 static void hfa384x_usbin_callback(
struct urb *
urb);
189 static void hfa384x_usbctlxq_run(hfa384x_t *
hw);
191 static void hfa384x_usbctlx_reqtimerfn(
unsigned long data);
193 static void hfa384x_usbctlx_resptimerfn(
unsigned long data);
195 static void hfa384x_usb_throttlefn(
unsigned long data);
197 static void hfa384x_usbctlx_completion_task(
unsigned long data);
199 static void hfa384x_usbctlx_reaper_task(
unsigned long data);
201 static int hfa384x_usbctlx_submit(hfa384x_t *
hw, hfa384x_usbctlx_t *ctlx);
203 static void unlocked_usbctlx_complete(hfa384x_t *
hw, hfa384x_usbctlx_t *ctlx);
210 hfa384x_usbctlx_complete_sync(hfa384x_t *
hw,
211 hfa384x_usbctlx_t *ctlx,
215 unlocked_usbctlx_cancel_async(hfa384x_t *
hw, hfa384x_usbctlx_t *ctlx);
217 static void hfa384x_cb_status(hfa384x_t *
hw,
const hfa384x_usbctlx_t *ctlx);
219 static void hfa384x_cb_rrid(hfa384x_t *
hw,
const hfa384x_usbctlx_t *ctlx);
223 hfa384x_cmdresult_t *
result);
227 hfa384x_rridresult_t *
result);
232 hfa384x_docmd(hfa384x_t *
hw,
234 hfa384x_metacmd_t *
cmd,
235 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb,
void *usercb_data);
238 hfa384x_dorrid(hfa384x_t *
hw,
242 unsigned int riddatalen,
243 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb,
void *usercb_data);
246 hfa384x_dowrid(hfa384x_t *
hw,
250 unsigned int riddatalen,
251 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb,
void *usercb_data);
254 hfa384x_dormem(hfa384x_t *
hw,
260 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb,
void *usercb_data);
263 hfa384x_dowmem(hfa384x_t *
hw,
269 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb,
void *usercb_data);
271 static int hfa384x_isgood_pdrcode(
u16 pdrcode);
273 static inline const char *ctlxstr(CTLX_STATE
s)
275 static const char *ctlx_str[] = {
280 "Request packet submitted",
281 "Request packet completed",
282 "Response packet completed"
288 static inline hfa384x_usbctlx_t *get_active_ctlx(hfa384x_t *
hw)
290 return list_entry(hw->ctlxq.active.next, hfa384x_usbctlx_t,
list);
294 void dbprint_urb(
struct urb *
urb)
296 pr_debug(
"urb->pipe=0x%08x\n", urb->pipe);
297 pr_debug(
"urb->status=0x%08x\n", urb->status);
298 pr_debug(
"urb->transfer_flags=0x%08x\n", urb->transfer_flags);
299 pr_debug(
"urb->transfer_buffer=0x%08x\n",
300 (
unsigned int)urb->transfer_buffer);
301 pr_debug(
"urb->transfer_buffer_length=0x%08x\n",
302 urb->transfer_buffer_length);
303 pr_debug(
"urb->actual_length=0x%08x\n", urb->actual_length);
304 pr_debug(
"urb->bandwidth=0x%08x\n", urb->bandwidth);
305 pr_debug(
"urb->setup_packet(ctl)=0x%08x\n",
306 (
unsigned int)urb->setup_packet);
307 pr_debug(
"urb->start_frame(iso/irq)=0x%08x\n", urb->start_frame);
308 pr_debug(
"urb->interval(irq)=0x%08x\n", urb->interval);
309 pr_debug(
"urb->error_count(iso)=0x%08x\n", urb->error_count);
310 pr_debug(
"urb->timeout=0x%08x\n", urb->timeout);
311 pr_debug(
"urb->context=0x%08x\n", (
unsigned int)urb->context);
312 pr_debug(
"urb->complete=0x%08x\n", (
unsigned int)urb->complete);
332 static int submit_rx_urb(hfa384x_t *
hw,
gfp_t memflags)
344 usb_fill_bulk_urb(&hw->rx_urb, hw->usb,
347 hfa384x_usbin_callback, hw->wlandev);
349 hw->rx_urb_skb =
skb;
352 if (!hw->wlandev->hwremoved &&
353 !
test_bit(WORK_RX_HALT, &hw->usb_flags)) {
357 if (result == -
EPIPE) {
359 "%s rx pipe stalled: requesting reset\n",
360 hw->wlandev->netdev->name);
369 hw->rx_urb_skb =
NULL;
394 static int submit_tx_urb(hfa384x_t *hw,
struct urb *tx_urb,
gfp_t memflags)
396 struct net_device *netdev = hw->wlandev->netdev;
400 if (netif_running(netdev)) {
402 if (!hw->wlandev->hwremoved
403 && !
test_bit(WORK_TX_HALT, &hw->usb_flags)) {
407 if (result == -
EPIPE) {
409 "%s tx pipe stalled: requesting reset\n",
411 set_bit(WORK_TX_HALT, &hw->usb_flags);
413 }
else if (result == 0) {
414 netif_stop_queue(netdev);
440 hfa384x_t *hw =
container_of(data,
struct hfa384x, usb_work);
441 struct net_device *netdev = hw->wlandev->netdev;
446 if (hw->wlandev->hwremoved)
450 if (
test_bit(WORK_RX_HALT, &hw->usb_flags)) {
458 "Failed to clear rx pipe for %s: err=%d\n",
464 set_bit(WORK_RX_RESUME, &hw->usb_flags);
469 if (
test_bit(WORK_RX_RESUME, &hw->usb_flags)) {
475 "Failed to resume %s rx pipe.\n", netdev->
name);
477 clear_bit(WORK_RX_RESUME, &hw->usb_flags);
482 if (
test_bit(WORK_TX_HALT, &hw->usb_flags)) {
489 "Failed to clear tx pipe for %s: err=%d\n",
495 set_bit(WORK_TX_RESUME, &hw->usb_flags);
501 hfa384x_usbctlxq_run(hw);
507 netif_wake_queue(hw->wlandev->netdev);
533 memset(hw, 0,
sizeof(hfa384x_t));
537 hw->endp_in = usb_rcvbulkpipe(usb, 1);
538 hw->endp_out = usb_sndbulkpipe(usb, 2);
545 INIT_LIST_HEAD(&hw->ctlxq.pending);
546 INIT_LIST_HEAD(&hw->ctlxq.active);
547 INIT_LIST_HEAD(&hw->ctlxq.completing);
548 INIT_LIST_HEAD(&hw->ctlxq.reapable);
551 skb_queue_head_init(&hw->authq);
554 hfa384x_usbctlx_reaper_task, (
unsigned long)hw);
556 hfa384x_usbctlx_completion_task, (
unsigned long)hw);
558 INIT_WORK(&hw->usb_work, hfa384x_usb_defer);
561 hw->throttle.function = hfa384x_usb_throttlefn;
562 hw->throttle.data = (
unsigned long)hw;
565 hw->resptimer.function = hfa384x_usbctlx_resptimerfn;
566 hw->resptimer.data = (
unsigned long)hw;
569 hw->reqtimer.function = hfa384x_usbctlx_reqtimerfn;
570 hw->reqtimer.data = (
unsigned long)hw;
581 hw->commsqual_timer.data = (
unsigned long)hw;
615 kfree(hw->scanresults);
616 hw->scanresults =
NULL;
623 static hfa384x_usbctlx_t *usbctlx_alloc(
void)
625 hfa384x_usbctlx_t *ctlx;
629 memset(ctlx, 0,
sizeof(*ctlx));
630 init_completion(&ctlx->done);
638 hfa384x_cmdresult_t *result)
646 "resp0=0x%04x resp1=0x%04x resp2=0x%04x\n",
647 result->status, result->resp0, result->resp1, result->resp2);
654 hfa384x_rridresult_t *result)
657 result->riddata = rridresp->
data;
679 return usbctlx_get_status(complete->
cmdresp, complete->
result);
687 hfa384x_cmdresult_t *result)
689 completor->
head.complete = usbctlx_cmd_completor_fn;
692 return &(completor->
head);
711 hfa384x_rridresult_t rridresult;
714 usbctlx_get_rridresult(complete->
rridresp, &rridresult);
717 if (rridresult.riddata_len != complete->
riddatalen) {
719 "RID len mismatch, rid=0x%04x hlen=%d fwlen=%d\n",
721 complete->
riddatalen, rridresult.riddata_len);
735 unsigned int riddatalen)
737 completor->
head.complete = usbctlx_rrid_completor_fn;
741 return &(completor->
head);
749 #define init_wrid_completor init_cmd_completor
756 #define init_wmem_completor init_cmd_completor
788 completor->
head.complete = usbctlx_rmem_completor_fn;
791 completor->
len = len;
792 return &(completor->
head);
816 static void hfa384x_cb_status(hfa384x_t *hw,
const hfa384x_usbctlx_t *ctlx)
818 if (ctlx->usercb !=
NULL) {
819 hfa384x_cmdresult_t cmdresult;
821 if (ctlx->state != CTLX_COMPLETE) {
822 memset(&cmdresult, 0,
sizeof(cmdresult));
826 usbctlx_get_status(&ctlx->inbuf.cmdresp, &cmdresult);
829 ctlx->usercb(hw, &cmdresult, ctlx->usercb_data);
853 static void hfa384x_cb_rrid(hfa384x_t *hw,
const hfa384x_usbctlx_t *ctlx)
855 if (ctlx->usercb !=
NULL) {
856 hfa384x_rridresult_t rridresult;
858 if (ctlx->state != CTLX_COMPLETE) {
859 memset(&rridresult, 0,
sizeof(rridresult));
860 rridresult.rid =
le16_to_cpu(ctlx->outbuf.rridreq.rid);
862 usbctlx_get_rridresult(&ctlx->inbuf.rridresp,
866 ctlx->usercb(hw, &rridresult, ctlx->usercb_data);
870 static inline int hfa384x_docmd_wait(hfa384x_t *hw, hfa384x_metacmd_t *
cmd)
876 hfa384x_docmd_async(hfa384x_t *hw,
877 hfa384x_metacmd_t *
cmd,
878 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb,
void *usercb_data)
880 return hfa384x_docmd(hw,
DOASYNC, cmd, cmdcb, usercb, usercb_data);
884 hfa384x_dorrid_wait(hfa384x_t *hw,
u16 rid,
void *riddata,
885 unsigned int riddatalen)
887 return hfa384x_dorrid(hw,
DOWAIT,
892 hfa384x_dorrid_async(hfa384x_t *hw,
893 u16 rid,
void *riddata,
unsigned int riddatalen,
895 ctlx_usercb_t usercb,
void *usercb_data)
897 return hfa384x_dorrid(hw,
DOASYNC,
898 rid, riddata, riddatalen,
899 cmdcb, usercb, usercb_data);
903 hfa384x_dowrid_wait(hfa384x_t *hw,
u16 rid,
void *riddata,
904 unsigned int riddatalen)
906 return hfa384x_dowrid(hw,
DOWAIT,
911 hfa384x_dowrid_async(hfa384x_t *hw,
912 u16 rid,
void *riddata,
unsigned int riddatalen,
914 ctlx_usercb_t usercb,
void *usercb_data)
916 return hfa384x_dowrid(hw,
DOASYNC,
917 rid, riddata, riddatalen,
918 cmdcb, usercb, usercb_data);
922 hfa384x_dormem_wait(hfa384x_t *hw,
925 return hfa384x_dormem(hw,
DOWAIT,
930 hfa384x_dormem_async(hfa384x_t *hw,
933 ctlx_usercb_t usercb,
void *usercb_data)
935 return hfa384x_dormem(hw,
DOASYNC,
936 page, offset, data, len,
937 cmdcb, usercb, usercb_data);
941 hfa384x_dowmem_wait(hfa384x_t *hw,
944 return hfa384x_dowmem(hw,
DOWAIT,
949 hfa384x_dowmem_async(hfa384x_t *hw,
955 ctlx_usercb_t usercb,
void *usercb_data)
957 return hfa384x_dowmem(hw,
DOASYNC,
958 page, offset, data, len,
959 cmdcb, usercb, usercb_data);
985 hfa384x_metacmd_t
cmd;
992 result = hfa384x_docmd_wait(hw, &cmd);
995 "status=0x%04x, resp0=0x%04x, "
996 "resp1=0x%04x, resp2=0x%04x\n",
998 cmd.result.resp0, cmd.result.resp1, cmd.result.resp2);
1001 hw->port_enabled[i] = 0;
1032 hfa384x_metacmd_t
cmd;
1040 result = hfa384x_docmd_wait(hw, &cmd);
1068 hfa384x_metacmd_t
cmd;
1076 result = hfa384x_docmd_wait(hw, &cmd);
1113 hfa384x_metacmd_t
cmd;
1121 result = hfa384x_docmd_wait(hw, &cmd);
1165 u16 highaddr,
u16 codelen)
1168 hfa384x_metacmd_t
cmd;
1170 pr_debug(
"mode=%d, lowaddr=0x%04x, highaddr=0x%04x, codelen=%d\n",
1171 mode, lowaddr, highaddr, codelen);
1176 cmd.parm0 = lowaddr;
1177 cmd.parm1 = highaddr;
1178 cmd.parm2 = codelen;
1180 result = hfa384x_docmd_wait(hw, &cmd);
1245 static int hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
1246 hfa384x_usbctlx_t *ctlx,
1249 unsigned long flags;
1261 if (hw->wlandev->hwremoved) {
1262 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1264 }
else if (result != 0) {
1276 if (ctlx == get_active_ctlx(hw)) {
1277 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1281 hw->req_timer_done = 1;
1282 hw->resp_timer_done = 1;
1293 if (hw->wlandev->hwremoved)
1303 ctlx->state = CTLX_REQ_FAILED;
1304 list_move_tail(&ctlx->list, &hw->ctlxq.completing);
1306 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1309 hfa384x_usbctlxq_run(hw);
1311 if (ctlx->state == CTLX_COMPLETE) {
1312 result = completor->
complete(completor);
1316 ctlxstr(ctlx->state));
1321 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1361 hfa384x_docmd(hfa384x_t *hw,
1363 hfa384x_metacmd_t *
cmd,
1364 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb,
void *usercb_data)
1367 hfa384x_usbctlx_t *ctlx;
1369 ctlx = usbctlx_alloc();
1378 ctlx->outbuf.cmdreq.parm0 =
cpu_to_le16(cmd->parm0);
1379 ctlx->outbuf.cmdreq.parm1 =
cpu_to_le16(cmd->parm1);
1380 ctlx->outbuf.cmdreq.parm2 =
cpu_to_le16(cmd->parm2);
1382 ctlx->outbufsize =
sizeof(ctlx->outbuf.cmdreq);
1385 "parm0=0x%04x parm1=0x%04x parm2=0x%04x\n",
1386 cmd->cmd, cmd->parm0, cmd->parm1, cmd->parm2);
1388 ctlx->reapable =
mode;
1389 ctlx->cmdcb = cmdcb;
1390 ctlx->usercb = usercb;
1391 ctlx->usercb_data = usercb_data;
1393 result = hfa384x_usbctlx_submit(hw, ctlx);
1396 }
else if (mode ==
DOWAIT) {
1400 hfa384x_usbctlx_complete_sync(hw, ctlx,
1401 init_cmd_completor(&completor,
1450 hfa384x_dorrid(hfa384x_t *hw,
1454 unsigned int riddatalen,
1455 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb,
void *usercb_data)
1458 hfa384x_usbctlx_t *ctlx;
1460 ctlx = usbctlx_alloc();
1468 ctlx->outbuf.rridreq.frmlen =
1472 ctlx->outbufsize =
sizeof(ctlx->outbuf.rridreq);
1474 ctlx->reapable =
mode;
1475 ctlx->cmdcb = cmdcb;
1476 ctlx->usercb = usercb;
1477 ctlx->usercb_data = usercb_data;
1480 result = hfa384x_usbctlx_submit(hw, ctlx);
1483 }
else if (mode ==
DOWAIT) {
1487 hfa384x_usbctlx_complete_sync(hw, ctlx,
1490 &ctlx->inbuf.rridresp,
1491 riddata, riddatalen));
1531 hfa384x_dowrid(hfa384x_t *hw,
1535 unsigned int riddatalen,
1536 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb,
void *usercb_data)
1539 hfa384x_usbctlx_t *ctlx;
1541 ctlx = usbctlx_alloc();
1550 (ctlx->outbuf.wridreq.rid) +
1551 riddatalen + 1) / 2);
1553 memcpy(ctlx->outbuf.wridreq.data, riddata, riddatalen);
1555 ctlx->outbufsize =
sizeof(ctlx->outbuf.wridreq.type) +
1556 sizeof(ctlx->outbuf.wridreq.frmlen) +
1557 sizeof(ctlx->outbuf.wridreq.rid) + riddatalen;
1559 ctlx->reapable =
mode;
1560 ctlx->cmdcb = cmdcb;
1561 ctlx->usercb = usercb;
1562 ctlx->usercb_data = usercb_data;
1565 result = hfa384x_usbctlx_submit(hw, ctlx);
1568 }
else if (mode ==
DOWAIT) {
1570 hfa384x_cmdresult_t wridresult;
1572 result = hfa384x_usbctlx_complete_sync(hw,
1576 &ctlx->inbuf.wridresp,
1618 hfa384x_dormem(hfa384x_t *hw,
1624 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb,
void *usercb_data)
1627 hfa384x_usbctlx_t *ctlx;
1629 ctlx = usbctlx_alloc();
1637 ctlx->outbuf.rmemreq.frmlen =
1639 sizeof(ctlx->outbuf.rmemreq.page) + len);
1640 ctlx->outbuf.rmemreq.offset =
cpu_to_le16(offset);
1643 ctlx->outbufsize =
sizeof(ctlx->outbuf.rmemreq);
1645 pr_debug(
"type=0x%04x frmlen=%d offset=0x%04x page=0x%04x\n",
1646 ctlx->outbuf.rmemreq.type,
1647 ctlx->outbuf.rmemreq.frmlen,
1648 ctlx->outbuf.rmemreq.offset, ctlx->outbuf.rmemreq.page);
1652 ctlx->reapable =
mode;
1653 ctlx->cmdcb = cmdcb;
1654 ctlx->usercb = usercb;
1655 ctlx->usercb_data = usercb_data;
1657 result = hfa384x_usbctlx_submit(hw, ctlx);
1660 }
else if (mode ==
DOWAIT) {
1664 hfa384x_usbctlx_complete_sync(hw, ctlx,
1709 hfa384x_dowmem(hfa384x_t *hw,
1715 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb,
void *usercb_data)
1718 hfa384x_usbctlx_t *ctlx;
1720 pr_debug(
"page=0x%04x offset=0x%04x len=%d\n", page, offset, len);
1722 ctlx = usbctlx_alloc();
1730 ctlx->outbuf.wmemreq.frmlen =
1732 sizeof(ctlx->outbuf.wmemreq.page) + len);
1733 ctlx->outbuf.wmemreq.offset =
cpu_to_le16(offset);
1735 memcpy(ctlx->outbuf.wmemreq.data, data, len);
1737 ctlx->outbufsize =
sizeof(ctlx->outbuf.wmemreq.type) +
1738 sizeof(ctlx->outbuf.wmemreq.frmlen) +
1739 sizeof(ctlx->outbuf.wmemreq.offset) +
1740 sizeof(ctlx->outbuf.wmemreq.page) + len;
1742 ctlx->reapable =
mode;
1743 ctlx->cmdcb = cmdcb;
1744 ctlx->usercb = usercb;
1745 ctlx->usercb_data = usercb_data;
1747 result = hfa384x_usbctlx_submit(hw, ctlx);
1750 }
else if (mode ==
DOWAIT) {
1752 hfa384x_cmdresult_t wmemresult;
1754 result = hfa384x_usbctlx_complete_sync(hw,
1758 &ctlx->inbuf.wmemresp,
1785 hfa384x_metacmd_t
cmd;
1823 if ((!hw->isap && macport != 0) ||
1825 !(hw->port_enabled[macport])) {
1830 hw->port_enabled[macport] = 0;
1861 if ((!hw->isap && macport != 0) ||
1863 (hw->port_enabled[macport])) {
1868 hw->port_enabled[macport] = 1;
1901 if (hw->port_enabled[i]) {
1902 pr_debug(
"called when port enabled.\n");
1913 &(hw->bufinfo),
sizeof(hw->bufinfo));
1918 hw->bufinfo.offset =
le16_to_cpu(hw->bufinfo.offset);
2015 pr_debug(
"daddr=0x%08x len=%d\n", daddr, len);
2027 pr_debug(
"dlbuf.page=0x%04x dlbuf.offset=0x%04x dlbufaddr=0x%08x\n",
2028 hw->bufinfo.page, hw->bufinfo.offset, dlbufaddr);
2032 hw->bufinfo.len, hw->dltimeout);
2042 nburns = len / hw->bufinfo.len;
2043 nburns += (len % hw->bufinfo.len) ? 1 : 0;
2050 for (i = 0; i < nburns; i++) {
2052 burnlen = (len - (hw->bufinfo.len *
i)) > hw->bufinfo.len ?
2053 hw->bufinfo.len : (len - (hw->bufinfo.len *
i));
2054 burndaddr = daddr + (hw->bufinfo.len *
i);
2059 burnlen, burndaddr);
2063 burnlo, burnhi, burnlen);
2066 "cmd failed, result=%d. Aborting d/l\n",
2067 burnlo, burnhi, burnlen, result);
2072 for (j = 0; j < nwrites; j++) {
2074 (i * hw->bufinfo.len) +
2078 (j * HFA384x_USB_RWMEM_MAXLEN));
2080 (j * HFA384x_USB_RWMEM_MAXLEN));
2083 writelen = writelen > HFA384x_USB_RWMEM_MAXLEN ?
2084 HFA384x_USB_RWMEM_MAXLEN : writelen;
2086 result = hfa384x_dowmem_wait(hw,
2089 writebuf, writelen);
2098 "download(NVWRITE,lo=%x,hi=%x,len=%x) "
2099 "cmd failed, result=%d. Aborting d/l\n",
2100 burnlo, burnhi, burnlen, result);
2143 return hfa384x_dorrid_wait(hw, rid, buf, len);
2175 u16 rid, ctlx_usercb_t usercb,
void *usercb_data)
2177 return hfa384x_dorrid_async(hw, rid,
NULL, 0,
2178 hfa384x_cb_rrid, usercb, usercb_data);
2208 u16 len, ctlx_usercb_t usercb,
void *usercb_data)
2210 return hfa384x_dowrid_async(hw, rid, buf, len,
2211 hfa384x_cb_status, usercb, usercb_data);
2281 if (hw->port_enabled[i]) {
2283 "Can't download with a macport enabled.\n");
2294 pr_debug(
"ramdl_enable, exeaddr=0x%08x\n", exeaddr);
2301 lowaddr, hiaddr, 0);
2307 pr_debug(
"cmd_download(0x%04x, 0x%04x) failed, result=%d.\n",
2308 lowaddr, hiaddr, result);
2362 for (i = 0; i < nwrites; i++) {
2372 result = hfa384x_dowmem_wait(hw,
2448 result = hfa384x_dormem_wait(hw, currpage, curroffset, buf,
2453 "Read from index %zd failed, continuing\n", i);
2460 while (pdaok && morepdrs) {
2470 if (!hfa384x_isgood_pdrcode(pdrcode)) {
2488 "PDA Read from 0x%08x in %s space.\n",
2490 pdaloc[i].auxctl == 0 ?
"EXTDS" :
2491 pdaloc[i].auxctl == 1 ?
"NV" :
2492 pdaloc[i].auxctl == 2 ?
"PHY" :
2493 pdaloc[i].auxctl == 3 ?
"ICSRAM" :
2498 result = pdaok ? 0 : -
ENODATA;
2501 pr_debug(
"Failure: pda is not okay\n");
2529 return hfa384x_dowrid_wait(hw, rid, buf, len);
2554 int result, result1, result2;
2589 "Fatal, failed to submit RX URB, result=%d\n", result);
2609 "cmd_initialize() failed on two attempts, results %d and %d\n",
2614 pr_debug(
"First cmd_initialize() failed (result %d),\n",
2616 pr_debug(
"but second attempt succeeded. All should be ok\n");
2618 }
else if (result2 != 0) {
2619 printk(
KERN_WARNING "First cmd_initialize() succeeded, but second attempt failed (result=%d)\n",
2622 "Most likely the card will be functional\n");
2661 if (!hw->wlandev->hwremoved) {
2676 hw->port_enabled[i] = 0;
2719 memset(&hw->txbuff.txfrm.desc, 0,
sizeof(hw->txbuff.txfrm.desc));
2725 hw->txbuff.txfrm.desc.sw_support = 0x0123;
2732 hw->txbuff.txfrm.desc.tx_control =
2735 #elif defined(DOEXC)
2736 hw->txbuff.txfrm.desc.tx_control =
2740 hw->txbuff.txfrm.desc.tx_control =
2744 hw->txbuff.txfrm.desc.tx_control =
2748 memcpy(&(hw->txbuff.txfrm.desc.frame_control), p80211_hdr,
2749 sizeof(
union p80211_hdr));
2752 if (p80211_wep->
data) {
2759 usbpktlen += skb->
len;
2762 ptr = hw->txbuff.txfrm.data;
2763 if (p80211_wep->
data) {
2764 memcpy(ptr, p80211_wep->
iv,
sizeof(p80211_wep->
iv));
2765 ptr +=
sizeof(p80211_wep->
iv);
2774 if (p80211_wep->
data)
2778 usb_fill_bulk_urb(&(hw->tx_urb), hw->usb,
2781 hfa384x_usbout_callback, hw->wlandev);
2785 ret = submit_tx_urb(hw, &hw->tx_urb,
GFP_ATOMIC);
2797 hfa384x_t *hw = wlandev->
priv;
2798 unsigned long flags;
2802 if (!hw->wlandev->hwremoved) {
2811 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2827 static void hfa384x_usbctlx_reaper_task(
unsigned long data)
2829 hfa384x_t *hw = (hfa384x_t *) data;
2832 unsigned long flags;
2840 hfa384x_usbctlx_t *ctlx;
2847 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2865 static void hfa384x_usbctlx_completion_task(
unsigned long data)
2867 hfa384x_t *hw = (hfa384x_t *) data;
2870 unsigned long flags;
2880 hfa384x_usbctlx_t *ctlx;
2887 if (ctlx->cmdcb !=
NULL) {
2888 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2889 ctlx->cmdcb(hw, ctlx);
2900 if (hw->wlandev->hwremoved) {
2911 if (ctlx->reapable) {
2917 list_move_tail(&ctlx->list, &hw->ctlxq.reapable);
2923 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2926 tasklet_schedule(&hw->reaper_bh);
2946 static int unlocked_usbctlx_cancel_async(hfa384x_t *hw,
2947 hfa384x_usbctlx_t *ctlx)
2966 ctlx->state = CTLX_REQ_FAILED;
2967 unlocked_usbctlx_complete(hw, ctlx);
2996 static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx)
3002 list_move_tail(&ctlx->list, &hw->ctlxq.completing);
3003 tasklet_schedule(&hw->completion_bh);
3005 switch (ctlx->state) {
3007 case CTLX_REQ_FAILED:
3013 le16_to_cpu(ctlx->outbuf.type), ctlxstr(ctlx->state));
3034 static void hfa384x_usbctlxq_run(hfa384x_t *hw)
3036 unsigned long flags;
3048 if (!list_empty(&hw->ctlxq.active) ||
3049 test_bit(WORK_TX_HALT, &hw->usb_flags) || hw->wlandev->hwremoved)
3052 while (!list_empty(&hw->ctlxq.pending)) {
3053 hfa384x_usbctlx_t *
head;
3058 hfa384x_usbctlx_t,
list);
3061 list_move_tail(&head->list, &hw->ctlxq.active);
3064 usb_fill_bulk_urb(&(hw->ctlx_urb), hw->usb,
3066 &(head->outbuf),
ROUNDUP64(head->outbufsize),
3067 hfa384x_ctlxout_callback, hw);
3074 head->state = CTLX_REQ_SUBMITTED;
3077 hw->req_timer_done = 0;
3082 hw->resp_timer_done = 0;
3083 hw->resptimer.expires =
jiffies + 2 *
HZ;
3089 if (result == -
EPIPE) {
3095 "%s tx pipe stalled: requesting reset\n",
3096 hw->wlandev->netdev->name);
3097 list_move(&head->list, &hw->ctlxq.pending);
3098 set_bit(WORK_TX_HALT, &hw->usb_flags);
3105 hw->wlandev->netdev->name);
3111 unlocked_usbctlx_complete(hw, head);
3115 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3134 static void hfa384x_usbin_callback(
struct urb *urb)
3150 if (!wlandev || !wlandev->netdev || wlandev->hwremoved)
3157 skb = hw->rx_urb_skb;
3158 BUG_ON(!skb || (skb->
data != urb->transfer_buffer));
3160 hw->rx_urb_skb =
NULL;
3163 switch (urb->status) {
3168 if (urb->actual_length == 0) {
3169 ++(wlandev->linux_stats.rx_errors);
3170 ++(wlandev->linux_stats.rx_length_errors);
3177 wlandev->netdev->name);
3180 ++(wlandev->linux_stats.rx_errors);
3188 !timer_pending(&hw->throttle)) {
3191 ++(wlandev->linux_stats.rx_errors);
3196 ++(wlandev->linux_stats.rx_over_errors);
3202 pr_debug(
"status=%d, device removed.\n", urb->status);
3208 pr_debug(
"status=%d, urb explicitly unlinked.\n", urb->status);
3213 pr_debug(
"urb status=%d, transfer flags=0x%x\n",
3214 urb->status, urb->transfer_flags);
3215 ++(wlandev->linux_stats.rx_errors);
3220 urb_status = urb->status;
3228 "Fatal, failed to resubmit rx_urb. error=%d\n",
3240 if (usbin->txfrm.desc.sw_support == 0x0123) {
3241 hfa384x_usbin_txcompl(wlandev, usbin);
3244 hfa384x_usbin_rx(wlandev, skb);
3252 hfa384x_usbin_txcompl(wlandev, usbin);
3260 hfa384x_usbin_info(wlandev, usbin);
3269 hfa384x_usbin_ctlx(hw, usbin, urb_status);
3273 pr_debug(
"Received BUFAVAIL packet, frmlen=%d\n",
3274 usbin->bufavail.frmlen);
3278 pr_debug(
"Received USB_ERROR packet, errortype=%d\n",
3279 usbin->usberror.errortype);
3283 pr_debug(
"Unrecognized USBIN packet, type=%x, status=%d\n",
3284 usbin->type, urb_status);
3317 hfa384x_usbctlx_t *ctlx;
3319 unsigned long flags;
3328 if (list_empty(&hw->ctlxq.active))
3338 if (hw->resp_timer_done == 0) {
3339 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3343 hw->resp_timer_done = 1;
3346 ctlx = get_active_ctlx(hw);
3348 if (urb_status != 0) {
3354 if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0)
3362 if (ctlx->outbuf.type != intype) {
3364 "Expected IN[%d], received IN[%d] - ignored.\n",
3371 memcpy(&ctlx->inbuf, usbin,
sizeof(ctlx->inbuf));
3373 switch (ctlx->state) {
3374 case CTLX_REQ_SUBMITTED:
3380 pr_debug(
"Causality violation: please reboot Universe\n");
3381 ctlx->state = CTLX_RESP_COMPLETE;
3384 case CTLX_REQ_COMPLETE:
3390 ctlx->state = CTLX_COMPLETE;
3391 unlocked_usbctlx_complete(hw, ctlx);
3400 "Matched IN URB, CTLX[%d] in invalid state(%s)."
3403 ctlxstr(ctlx->state));
3404 if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0)
3411 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3414 hfa384x_usbctlxq_run(hw);
3434 static void hfa384x_usbin_txcompl(
wlandevice_t *wlandev,
3468 hfa384x_t *hw = wlandev->
priv;
3512 skb_reset_mac_header(skb);
3529 hfa384x_int_rxmonitor(wlandev, &usbin->
rxfrm);
3532 pr_debug(
"Received monitor frame: FCSerr set\n");
3568 static void hfa384x_int_rxmonitor(
wlandevice_t *wlandev,
3574 unsigned int skblen = 0;
3578 hfa384x_t *hw = wlandev->
priv;
3583 hdrlen = p80211_headerlen(fc);
3597 skb = dev_alloc_skb(skblen);
3600 "alloc_skb failed trying to allocate %d bytes\n",
3607 (hw->sniffhdr != 0)) {
3636 datap =
skb_put(skb, datalen);
3640 if (*(datap - hdrlen + 1) & 0x40)
3641 if ((*(datap) == 0xaa) && (*(datap + 1) == 0xaa))
3643 *(datap - hdrlen + 1) &= 0xbf;
3646 if (hw->sniff_fcs) {
3698 static void hfa384x_usbout_callback(
struct urb *urb)
3707 if (wlandev && wlandev->
netdev) {
3709 switch (urb->status) {
3711 hfa384x_usbout_tx(wlandev, usbout);
3716 hfa384x_t *hw = wlandev->
priv;
3718 "%s tx pipe stalled: requesting reset\n",
3721 (WORK_TX_HALT, &hw->usb_flags))
3731 hfa384x_t *hw = wlandev->
priv;
3734 (THROTTLE_TX, &hw->usb_flags)
3735 && !timer_pending(&hw->throttle)) {
3740 netif_stop_queue(wlandev->
netdev);
3774 static void hfa384x_ctlxout_callback(
struct urb *urb)
3776 hfa384x_t *hw = urb->context;
3777 int delete_resptimer = 0;
3780 hfa384x_usbctlx_t *ctlx;
3781 unsigned long flags;
3783 pr_debug(
"urb->status=%d\n", urb->status);
3800 if (list_empty(&hw->ctlxq.active)) {
3801 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3810 if (hw->req_timer_done == 0) {
3816 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3820 hw->req_timer_done = 1;
3823 ctlx = get_active_ctlx(hw);
3825 if (urb->status == 0) {
3827 switch (ctlx->state) {
3828 case CTLX_REQ_SUBMITTED:
3830 ctlx->state = CTLX_REQ_COMPLETE;
3833 case CTLX_RESP_COMPLETE:
3837 ctlx->state = CTLX_COMPLETE;
3838 unlocked_usbctlx_complete(hw, ctlx);
3845 "Illegal CTLX[%d] success state(%s, %d) in OUT URB\n",
3847 ctlxstr(ctlx->state), urb->status);
3852 if ((urb->status == -
EPIPE) &&
3855 "%s tx pipe stalled: requesting reset\n",
3856 hw->wlandev->netdev->name);
3863 ctlx->state = CTLX_REQ_FAILED;
3864 unlocked_usbctlx_complete(hw, ctlx);
3865 delete_resptimer = 1;
3870 if (delete_resptimer) {
3873 hw->resp_timer_done = 1;
3876 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3878 if (!timer_ok && (hw->resp_timer_done == 0)) {
3884 hfa384x_usbctlxq_run(hw);
3905 static void hfa384x_usbctlx_reqtimerfn(
unsigned long data)
3907 hfa384x_t *hw = (hfa384x_t *) data;
3908 unsigned long flags;
3912 hw->req_timer_done = 1;
3917 if (!list_empty(&hw->ctlxq.active)) {
3924 hfa384x_usbctlx_t *ctlx = get_active_ctlx(hw);
3926 ctlx->state = CTLX_REQ_FAILED;
3938 hw->resp_timer_done = 1;
3942 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3963 static void hfa384x_usbctlx_resptimerfn(
unsigned long data)
3965 hfa384x_t *hw = (hfa384x_t *) data;
3966 unsigned long flags;
3970 hw->resp_timer_done = 1;
3975 if (!list_empty(&hw->ctlxq.active)) {
3976 hfa384x_usbctlx_t *ctlx = get_active_ctlx(hw);
3978 if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0) {
3979 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3980 hfa384x_usbctlxq_run(hw);
3984 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
4002 static void hfa384x_usb_throttlefn(
unsigned long data)
4004 hfa384x_t *hw = (hfa384x_t *) data;
4005 unsigned long flags;
4013 pr_debug(
"flags=0x%lx\n", hw->usb_flags);
4014 if (!hw->wlandev->hwremoved &&
4024 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
4045 static int hfa384x_usbctlx_submit(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx)
4047 unsigned long flags;
4051 if (hw->wlandev->hwremoved) {
4052 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
4056 ctlx->state = CTLX_PENDING;
4058 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
4059 hfa384x_usbctlxq_run(hw);
4104 static int hfa384x_isgood_pdrcode(
u16 pdrcode)
4140 if (pdrcode < 0x1000) {
4142 pr_debug(
"Encountered unknown PDR#=0x%04x, "
4143 "assuming it's ok.\n", pdrcode);
4147 pr_debug(
"Encountered unknown PDR#=0x%04x, "
4148 "(>=0x1000), assuming it's bad.\n", pdrcode);