1 /* src/prism2/driver/hfa384x_usb.c
3 * Functions that talk to the USB variantof the Intersil hfa384x MAC
5 * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
6 * --------------------------------------------------------------------
10 * The contents of this file are subject to the Mozilla Public
11 * License Version 1.1 (the "License"); you may not use this file
12 * except in compliance with the License. You may obtain a copy of
13 * the License at http://www.mozilla.org/MPL/
15 * Software distributed under the License is distributed on an "AS
16 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
17 * implied. See the License for the specific language governing
18 * rights and limitations under the License.
20 * Alternatively, the contents of this file may be used under the
21 * terms of the GNU Public License version 2 (the "GPL"), in which
22 * case the provisions of the GPL are applicable instead of the
23 * above. If you wish to allow the use of your version of this file
24 * only under the terms of the GPL and not to allow others to use
25 * your version of this file under the MPL, indicate your decision
26 * by deleting the provisions above and replace them with the notice
27 * and other provisions required by the GPL. If you do not delete
28 * the provisions above, a recipient may use your version of this
29 * file under either the MPL or the GPL.
31 * --------------------------------------------------------------------
33 * Inquiries regarding the linux-wlan Open Source project can be
36 * AbsoluteValue Systems Inc.
38 * http://www.linux-wlan.com
40 * --------------------------------------------------------------------
42 * Portions of the development of this software were funded by
43 * Intersil Corporation as part of PRISM(R) chipset product development.
45 * --------------------------------------------------------------------
47 * This file implements functions that correspond to the prism2/hfa384x
48 * 802.11 MAC hardware and firmware host interface.
50 * The functions can be considered to represent several levels of
51 * abstraction. The lowest level functions are simply C-callable wrappers
52 * around the register accesses. The next higher level represents C-callable
53 * prism2 API functions that match the Intersil documentation as closely
54 * as is reasonable. The next higher layer implements common sequences
55 * of invocations of the API layer (e.g. write to bap, followed by cmd).
58 * hfa384x_drvr_xxx Highest level abstractions provided by the
59 * hfa384x code. They are driver defined wrappers
60 * for common sequences. These functions generally
61 * use the services of the lower levels.
63 * hfa384x_drvr_xxxconfig An example of the drvr level abstraction. These
64 * functions are wrappers for the RID get/set
65 * sequence. They call copy_[to|from]_bap() and
66 * cmd_access(). These functions operate on the
67 * RIDs and buffers without validation. The caller
68 * is responsible for that.
70 * API wrapper functions:
71 * hfa384x_cmd_xxx functions that provide access to the f/w commands.
72 * The function arguments correspond to each command
73 * argument, even command arguments that get packed
74 * into single registers. These functions _just_
75 * issue the command by setting the cmd/parm regs
76 * & reading the status/resp regs. Additional
77 * activities required to fully use a command
78 * (read/write from/to bap, get/set int status etc.)
79 * are implemented separately. Think of these as
80 * C-callable prism2 commands.
82 * Lowest Layer Functions:
83 * hfa384x_docmd_xxx These functions implement the sequence required
84 * to issue any prism2 command. Primarily used by the
85 * hfa384x_cmd_xxx functions.
87 * hfa384x_bap_xxx BAP read/write access functions.
88 * Note: we usually use BAP0 for non-interrupt context
89 * and BAP1 for interrupt context.
91 * hfa384x_dl_xxx download related functions.
93 * Driver State Issues:
94 * Note that there are two pairs of functions that manage the
95 * 'initialized' and 'running' states of the hw/MAC combo. The four
96 * functions are create(), destroy(), start(), and stop(). create()
97 * sets up the data structures required to support the hfa384x_*
98 * functions and destroy() cleans them up. The start() function gets
99 * the actual hardware running and enables the interrupts. The stop()
100 * function shuts the hardware down. The sequence should be:
104 * . Do interesting things w/ the hardware
109 * Note that destroy() can be called without calling stop() first.
110 * --------------------------------------------------------------------
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>
120 #include <linux/timer.h>
121 #include <linux/io.h>
122 #include <linux/delay.h>
123 #include <asm/byteorder.h>
124 #include <linux/bitops.h>
125 #include <linux/list.h>
126 #include <linux/usb.h>
127 #include <linux/byteorder/generic.h>
129 #define SUBMIT_URB(u, f) usb_submit_urb(u, f)
131 #include "p80211types.h"
132 #include "p80211hdr.h"
133 #include "p80211mgmt.h"
134 #include "p80211conv.h"
135 #include "p80211msg.h"
136 #include "p80211netdev.h"
137 #include "p80211req.h"
138 #include "p80211metadef.h"
139 #include "p80211metastruct.h"
141 #include "prism2mgmt.h"
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);
159 hfa384x_int_rxmonitor(wlandevice_t *wlandev, hfa384x_usb_rxfrm_t *rxfrm);
161 static void hfa384x_usb_defer(struct work_struct *data);
163 static int submit_rx_urb(hfa384x_t *hw, gfp_t flags);
165 static int submit_tx_urb(hfa384x_t *hw, struct urb *tx_urb, gfp_t flags);
167 /*---------------------------------------------------*/
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);
174 hfa384x_usbin_txcompl(wlandevice_t *wlandev, hfa384x_usbin_t *usbin);
176 static void hfa384x_usbin_rx(wlandevice_t *wlandev, struct sk_buff *skb);
178 static void hfa384x_usbin_info(wlandevice_t *wlandev, hfa384x_usbin_t *usbin);
181 hfa384x_usbout_tx(wlandevice_t *wlandev, hfa384x_usbout_t *usbout);
183 static void hfa384x_usbin_ctlx(hfa384x_t *hw, hfa384x_usbin_t *usbin,
186 /*---------------------------------------------------*/
187 /* Functions to support the prism2 usb command queue */
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);
205 struct usbctlx_completor {
206 int (*complete)(struct usbctlx_completor *);
210 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
211 hfa384x_usbctlx_t *ctlx,
212 struct usbctlx_completor *completor);
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);
222 usbctlx_get_status(const hfa384x_usb_cmdresp_t *cmdresp,
223 hfa384x_cmdresult_t *result);
226 usbctlx_get_rridresult(const hfa384x_usb_rridresp_t *rridresp,
227 hfa384x_rridresult_t *result);
229 /*---------------------------------------------------*/
230 /* Low level req/resp CTLX formatters and submitters */
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 * const 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);
316 /*----------------------------------------------------------------
319 * Listen for input data on the BULK-IN pipe. If the pipe has
320 * stalled then schedule it to be reset.
324 * memflags memory allocation flags
327 * error code from submission
331 ----------------------------------------------------------------*/
332 static int submit_rx_urb(hfa384x_t *hw, gfp_t memflags)
337 skb = dev_alloc_skb(sizeof(hfa384x_usbin_t));
343 /* Post the IN urb */
344 usb_fill_bulk_urb(&hw->rx_urb, hw->usb,
346 skb->data, sizeof(hfa384x_usbin_t),
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)) {
354 result = SUBMIT_URB(&hw->rx_urb, memflags);
356 /* Check whether we need to reset the RX pipe */
357 if (result == -EPIPE) {
358 netdev_warn(hw->wlandev->netdev,
359 "%s rx pipe stalled: requesting reset\n",
360 hw->wlandev->netdev->name);
361 if (!test_and_set_bit(WORK_RX_HALT, &hw->usb_flags))
362 schedule_work(&hw->usb_work);
366 /* Don't leak memory if anything should go wrong */
369 hw->rx_urb_skb = NULL;
376 /*----------------------------------------------------------------
379 * Prepares and submits the URB of transmitted data. If the
380 * submission fails then it will schedule the output pipe to
385 * tx_urb URB of data for tranmission
386 * memflags memory allocation flags
389 * error code from submission
393 ----------------------------------------------------------------*/
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)) {
404 result = SUBMIT_URB(tx_urb, memflags);
406 /* Test whether we need to reset the TX pipe */
407 if (result == -EPIPE) {
408 netdev_warn(hw->wlandev->netdev,
409 "%s tx pipe stalled: requesting reset\n",
411 set_bit(WORK_TX_HALT, &hw->usb_flags);
412 schedule_work(&hw->usb_work);
413 } else if (result == 0) {
414 netif_stop_queue(netdev);
422 /*----------------------------------------------------------------
425 * There are some things that the USB stack cannot do while
426 * in interrupt context, so we arrange this function to run
427 * in process context.
430 * hw device structure
436 * process (by design)
437 ----------------------------------------------------------------*/
438 static void hfa384x_usb_defer(struct work_struct *data)
440 hfa384x_t *hw = container_of(data, struct hfa384x, usb_work);
441 struct net_device *netdev = hw->wlandev->netdev;
443 /* Don't bother trying to reset anything if the plug
444 * has been pulled ...
446 if (hw->wlandev->hwremoved)
449 /* Reception has stopped: try to reset the input pipe */
450 if (test_bit(WORK_RX_HALT, &hw->usb_flags)) {
453 usb_kill_urb(&hw->rx_urb); /* Cannot be holding spinlock! */
455 ret = usb_clear_halt(hw->usb, hw->endp_in);
457 netdev_err(hw->wlandev->netdev,
458 "Failed to clear rx pipe for %s: err=%d\n",
461 netdev_info(hw->wlandev->netdev, "%s rx pipe reset complete.\n",
463 clear_bit(WORK_RX_HALT, &hw->usb_flags);
464 set_bit(WORK_RX_RESUME, &hw->usb_flags);
468 /* Resume receiving data back from the device. */
469 if (test_bit(WORK_RX_RESUME, &hw->usb_flags)) {
472 ret = submit_rx_urb(hw, GFP_KERNEL);
474 netdev_err(hw->wlandev->netdev,
475 "Failed to resume %s rx pipe.\n",
478 clear_bit(WORK_RX_RESUME, &hw->usb_flags);
482 /* Transmission has stopped: try to reset the output pipe */
483 if (test_bit(WORK_TX_HALT, &hw->usb_flags)) {
486 usb_kill_urb(&hw->tx_urb);
487 ret = usb_clear_halt(hw->usb, hw->endp_out);
489 netdev_err(hw->wlandev->netdev,
490 "Failed to clear tx pipe for %s: err=%d\n",
493 netdev_info(hw->wlandev->netdev, "%s tx pipe reset complete.\n",
495 clear_bit(WORK_TX_HALT, &hw->usb_flags);
496 set_bit(WORK_TX_RESUME, &hw->usb_flags);
498 /* Stopping the BULK-OUT pipe also blocked
499 * us from sending any more CTLX URBs, so
500 * we need to re-run our queue ...
502 hfa384x_usbctlxq_run(hw);
506 /* Resume transmitting. */
507 if (test_and_clear_bit(WORK_TX_RESUME, &hw->usb_flags))
508 netif_wake_queue(hw->wlandev->netdev);
511 /*----------------------------------------------------------------
514 * Sets up the hfa384x_t data structure for use. Note this
515 * does _not_ initialize the actual hardware, just the data structures
516 * we use to keep track of its state.
519 * hw device structure
520 * irq device irq number
521 * iobase i/o base address for register access
522 * membase memory base address for register access
531 ----------------------------------------------------------------*/
532 void hfa384x_create(hfa384x_t *hw, struct usb_device *usb)
534 memset(hw, 0, sizeof(hfa384x_t));
537 /* set up the endpoints */
538 hw->endp_in = usb_rcvbulkpipe(usb, 1);
539 hw->endp_out = usb_sndbulkpipe(usb, 2);
541 /* Set up the waitq */
542 init_waitqueue_head(&hw->cmdq);
544 /* Initialize the command queue */
545 spin_lock_init(&hw->ctlxq.lock);
546 INIT_LIST_HEAD(&hw->ctlxq.pending);
547 INIT_LIST_HEAD(&hw->ctlxq.active);
548 INIT_LIST_HEAD(&hw->ctlxq.completing);
549 INIT_LIST_HEAD(&hw->ctlxq.reapable);
551 /* Initialize the authentication queue */
552 skb_queue_head_init(&hw->authq);
554 tasklet_init(&hw->reaper_bh,
555 hfa384x_usbctlx_reaper_task, (unsigned long)hw);
556 tasklet_init(&hw->completion_bh,
557 hfa384x_usbctlx_completion_task, (unsigned long)hw);
558 INIT_WORK(&hw->link_bh, prism2sta_processing_defer);
559 INIT_WORK(&hw->usb_work, hfa384x_usb_defer);
561 init_timer(&hw->throttle);
562 hw->throttle.function = hfa384x_usb_throttlefn;
563 hw->throttle.data = (unsigned long)hw;
565 init_timer(&hw->resptimer);
566 hw->resptimer.function = hfa384x_usbctlx_resptimerfn;
567 hw->resptimer.data = (unsigned long)hw;
569 init_timer(&hw->reqtimer);
570 hw->reqtimer.function = hfa384x_usbctlx_reqtimerfn;
571 hw->reqtimer.data = (unsigned long)hw;
573 usb_init_urb(&hw->rx_urb);
574 usb_init_urb(&hw->tx_urb);
575 usb_init_urb(&hw->ctlx_urb);
577 hw->link_status = HFA384x_LINK_NOTCONNECTED;
578 hw->state = HFA384x_STATE_INIT;
580 INIT_WORK(&hw->commsqual_bh, prism2sta_commsqual_defer);
581 init_timer(&hw->commsqual_timer);
582 hw->commsqual_timer.data = (unsigned long)hw;
583 hw->commsqual_timer.function = prism2sta_commsqual_timer;
586 /*----------------------------------------------------------------
589 * Partner to hfa384x_create(). This function cleans up the hw
590 * structure so that it can be freed by the caller using a simple
591 * kfree. Currently, this function is just a placeholder. If, at some
592 * point in the future, an hw in the 'shutdown' state requires a 'deep'
593 * kfree, this is where it should be done. Note that if this function
594 * is called on a _running_ hw structure, the drvr_stop() function is
598 * hw device structure
601 * nothing, this function is not allowed to fail.
607 ----------------------------------------------------------------*/
608 void hfa384x_destroy(hfa384x_t *hw)
612 if (hw->state == HFA384x_STATE_RUNNING)
613 hfa384x_drvr_stop(hw);
614 hw->state = HFA384x_STATE_PREINIT;
616 kfree(hw->scanresults);
617 hw->scanresults = NULL;
619 /* Now to clean out the auth queue */
620 while ((skb = skb_dequeue(&hw->authq)))
624 static hfa384x_usbctlx_t *usbctlx_alloc(void)
626 hfa384x_usbctlx_t *ctlx;
628 ctlx = kmalloc(sizeof(*ctlx), in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
630 memset(ctlx, 0, sizeof(*ctlx));
631 init_completion(&ctlx->done);
638 usbctlx_get_status(const hfa384x_usb_cmdresp_t *cmdresp,
639 hfa384x_cmdresult_t *result)
641 result->status = le16_to_cpu(cmdresp->status);
642 result->resp0 = le16_to_cpu(cmdresp->resp0);
643 result->resp1 = le16_to_cpu(cmdresp->resp1);
644 result->resp2 = le16_to_cpu(cmdresp->resp2);
646 pr_debug("cmdresult:status=0x%04x resp0=0x%04x resp1=0x%04x resp2=0x%04x\n",
647 result->status, result->resp0, result->resp1, result->resp2);
649 return result->status & HFA384x_STATUS_RESULT;
653 usbctlx_get_rridresult(const hfa384x_usb_rridresp_t *rridresp,
654 hfa384x_rridresult_t *result)
656 result->rid = le16_to_cpu(rridresp->rid);
657 result->riddata = rridresp->data;
658 result->riddata_len = ((le16_to_cpu(rridresp->frmlen) - 1) * 2);
662 /*----------------------------------------------------------------
664 * This completor must be passed to hfa384x_usbctlx_complete_sync()
665 * when processing a CTLX that returns a hfa384x_cmdresult_t structure.
666 ----------------------------------------------------------------*/
667 struct usbctlx_cmd_completor {
668 struct usbctlx_completor head;
670 const hfa384x_usb_cmdresp_t *cmdresp;
671 hfa384x_cmdresult_t *result;
674 static inline int usbctlx_cmd_completor_fn(struct usbctlx_completor *head)
676 struct usbctlx_cmd_completor *complete;
678 complete = (struct usbctlx_cmd_completor *) head;
679 return usbctlx_get_status(complete->cmdresp, complete->result);
682 static inline struct usbctlx_completor *init_cmd_completor(
683 struct usbctlx_cmd_completor
685 const hfa384x_usb_cmdresp_t
687 hfa384x_cmdresult_t *result)
689 completor->head.complete = usbctlx_cmd_completor_fn;
690 completor->cmdresp = cmdresp;
691 completor->result = result;
692 return &(completor->head);
695 /*----------------------------------------------------------------
697 * This completor must be passed to hfa384x_usbctlx_complete_sync()
698 * when processing a CTLX that reads a RID.
699 ----------------------------------------------------------------*/
700 struct usbctlx_rrid_completor {
701 struct usbctlx_completor head;
703 const hfa384x_usb_rridresp_t *rridresp;
705 unsigned int riddatalen;
708 static int usbctlx_rrid_completor_fn(struct usbctlx_completor *head)
710 struct usbctlx_rrid_completor *complete;
711 hfa384x_rridresult_t rridresult;
713 complete = (struct usbctlx_rrid_completor *) head;
714 usbctlx_get_rridresult(complete->rridresp, &rridresult);
716 /* Validate the length, note body len calculation in bytes */
717 if (rridresult.riddata_len != complete->riddatalen) {
718 pr_warn("RID len mismatch, rid=0x%04x hlen=%d fwlen=%d\n",
720 complete->riddatalen, rridresult.riddata_len);
724 memcpy(complete->riddata, rridresult.riddata, complete->riddatalen);
728 static inline struct usbctlx_completor *init_rrid_completor(
729 struct usbctlx_rrid_completor
731 const hfa384x_usb_rridresp_t
734 unsigned int riddatalen)
736 completor->head.complete = usbctlx_rrid_completor_fn;
737 completor->rridresp = rridresp;
738 completor->riddata = riddata;
739 completor->riddatalen = riddatalen;
740 return &(completor->head);
743 /*----------------------------------------------------------------
745 * Interprets the results of a synchronous RID-write
746 ----------------------------------------------------------------*/
747 #define init_wrid_completor init_cmd_completor
749 /*----------------------------------------------------------------
751 * Interprets the results of a synchronous memory-write
752 ----------------------------------------------------------------*/
753 #define init_wmem_completor init_cmd_completor
755 /*----------------------------------------------------------------
757 * Interprets the results of a synchronous memory-read
758 ----------------------------------------------------------------*/
759 struct usbctlx_rmem_completor {
760 struct usbctlx_completor head;
762 const hfa384x_usb_rmemresp_t *rmemresp;
767 static int usbctlx_rmem_completor_fn(struct usbctlx_completor *head)
769 struct usbctlx_rmem_completor *complete =
770 (struct usbctlx_rmem_completor *)head;
772 pr_debug("rmemresp:len=%d\n", complete->rmemresp->frmlen);
773 memcpy(complete->data, complete->rmemresp->data, complete->len);
777 static inline struct usbctlx_completor *init_rmem_completor(
778 struct usbctlx_rmem_completor
780 hfa384x_usb_rmemresp_t
785 completor->head.complete = usbctlx_rmem_completor_fn;
786 completor->rmemresp = rmemresp;
787 completor->data = data;
788 completor->len = len;
789 return &(completor->head);
792 /*----------------------------------------------------------------
795 * Ctlx_complete handler for async CMD type control exchanges.
796 * mark the hw struct as such.
798 * Note: If the handling is changed here, it should probably be
799 * changed in docmd as well.
803 * ctlx completed CTLX
812 ----------------------------------------------------------------*/
813 static void hfa384x_cb_status(hfa384x_t *hw, const hfa384x_usbctlx_t *ctlx)
815 if (ctlx->usercb != NULL) {
816 hfa384x_cmdresult_t cmdresult;
818 if (ctlx->state != CTLX_COMPLETE) {
819 memset(&cmdresult, 0, sizeof(cmdresult));
821 HFA384x_STATUS_RESULT_SET(HFA384x_CMD_ERR);
823 usbctlx_get_status(&ctlx->inbuf.cmdresp, &cmdresult);
826 ctlx->usercb(hw, &cmdresult, ctlx->usercb_data);
830 /*----------------------------------------------------------------
833 * CTLX completion handler for async RRID type control exchanges.
835 * Note: If the handling is changed here, it should probably be
836 * changed in dorrid as well.
840 * ctlx completed CTLX
849 ----------------------------------------------------------------*/
850 static void hfa384x_cb_rrid(hfa384x_t *hw, const hfa384x_usbctlx_t *ctlx)
852 if (ctlx->usercb != NULL) {
853 hfa384x_rridresult_t rridresult;
855 if (ctlx->state != CTLX_COMPLETE) {
856 memset(&rridresult, 0, sizeof(rridresult));
857 rridresult.rid = le16_to_cpu(ctlx->outbuf.rridreq.rid);
859 usbctlx_get_rridresult(&ctlx->inbuf.rridresp,
863 ctlx->usercb(hw, &rridresult, ctlx->usercb_data);
867 static inline int hfa384x_docmd_wait(hfa384x_t *hw, hfa384x_metacmd_t *cmd)
869 return hfa384x_docmd(hw, DOWAIT, cmd, NULL, NULL, NULL);
873 hfa384x_docmd_async(hfa384x_t *hw,
874 hfa384x_metacmd_t *cmd,
875 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
877 return hfa384x_docmd(hw, DOASYNC, cmd, cmdcb, usercb, usercb_data);
881 hfa384x_dorrid_wait(hfa384x_t *hw, u16 rid, void *riddata,
882 unsigned int riddatalen)
884 return hfa384x_dorrid(hw, DOWAIT,
885 rid, riddata, riddatalen, NULL, NULL, NULL);
889 hfa384x_dorrid_async(hfa384x_t *hw,
890 u16 rid, void *riddata, unsigned int riddatalen,
892 ctlx_usercb_t usercb, void *usercb_data)
894 return hfa384x_dorrid(hw, DOASYNC,
895 rid, riddata, riddatalen,
896 cmdcb, usercb, usercb_data);
900 hfa384x_dowrid_wait(hfa384x_t *hw, u16 rid, void *riddata,
901 unsigned int riddatalen)
903 return hfa384x_dowrid(hw, DOWAIT,
904 rid, riddata, riddatalen, NULL, NULL, NULL);
908 hfa384x_dowrid_async(hfa384x_t *hw,
909 u16 rid, void *riddata, unsigned int riddatalen,
911 ctlx_usercb_t usercb, void *usercb_data)
913 return hfa384x_dowrid(hw, DOASYNC,
914 rid, riddata, riddatalen,
915 cmdcb, usercb, usercb_data);
919 hfa384x_dormem_wait(hfa384x_t *hw,
920 u16 page, u16 offset, void *data, unsigned int len)
922 return hfa384x_dormem(hw, DOWAIT,
923 page, offset, data, len, NULL, NULL, NULL);
927 hfa384x_dormem_async(hfa384x_t *hw,
928 u16 page, u16 offset, void *data, unsigned int len,
930 ctlx_usercb_t usercb, void *usercb_data)
932 return hfa384x_dormem(hw, DOASYNC,
933 page, offset, data, len,
934 cmdcb, usercb, usercb_data);
938 hfa384x_dowmem_wait(hfa384x_t *hw,
939 u16 page, u16 offset, void *data, unsigned int len)
941 return hfa384x_dowmem(hw, DOWAIT,
942 page, offset, data, len, NULL, NULL, NULL);
946 hfa384x_dowmem_async(hfa384x_t *hw,
952 ctlx_usercb_t usercb, void *usercb_data)
954 return hfa384x_dowmem(hw, DOASYNC,
955 page, offset, data, len,
956 cmdcb, usercb, usercb_data);
959 /*----------------------------------------------------------------
960 * hfa384x_cmd_initialize
962 * Issues the initialize command and sets the hw->state based
966 * hw device structure
970 * >0 f/w reported error - f/w status code
971 * <0 driver reported error
977 ----------------------------------------------------------------*/
978 int hfa384x_cmd_initialize(hfa384x_t *hw)
982 hfa384x_metacmd_t cmd;
984 cmd.cmd = HFA384x_CMDCODE_INIT;
989 result = hfa384x_docmd_wait(hw, &cmd);
991 pr_debug("cmdresp.init: status=0x%04x, resp0=0x%04x, resp1=0x%04x, resp2=0x%04x\n",
993 cmd.result.resp0, cmd.result.resp1, cmd.result.resp2);
995 for (i = 0; i < HFA384x_NUMPORTS_MAX; i++)
996 hw->port_enabled[i] = 0;
999 hw->link_status = HFA384x_LINK_NOTCONNECTED;
1004 /*----------------------------------------------------------------
1005 * hfa384x_cmd_disable
1007 * Issues the disable command to stop communications on one of
1011 * hw device structure
1012 * macport MAC port number (host order)
1016 * >0 f/w reported failure - f/w status code
1017 * <0 driver reported error (timeout|bad arg)
1023 ----------------------------------------------------------------*/
1024 int hfa384x_cmd_disable(hfa384x_t *hw, u16 macport)
1027 hfa384x_metacmd_t cmd;
1029 cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_DISABLE) |
1030 HFA384x_CMD_MACPORT_SET(macport);
1035 result = hfa384x_docmd_wait(hw, &cmd);
1040 /*----------------------------------------------------------------
1041 * hfa384x_cmd_enable
1043 * Issues the enable command to enable communications on one of
1047 * hw device structure
1048 * macport MAC port number
1052 * >0 f/w reported failure - f/w status code
1053 * <0 driver reported error (timeout|bad arg)
1059 ----------------------------------------------------------------*/
1060 int hfa384x_cmd_enable(hfa384x_t *hw, u16 macport)
1063 hfa384x_metacmd_t cmd;
1065 cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_ENABLE) |
1066 HFA384x_CMD_MACPORT_SET(macport);
1071 result = hfa384x_docmd_wait(hw, &cmd);
1076 /*----------------------------------------------------------------
1077 * hfa384x_cmd_monitor
1079 * Enables the 'monitor mode' of the MAC. Here's the description of
1080 * monitor mode that I've received thus far:
1082 * "The "monitor mode" of operation is that the MAC passes all
1083 * frames for which the PLCP checks are correct. All received
1084 * MPDUs are passed to the host with MAC Port = 7, with a
1085 * receive status of good, FCS error, or undecryptable. Passing
1086 * certain MPDUs is a violation of the 802.11 standard, but useful
1087 * for a debugging tool." Normal communication is not possible
1088 * while monitor mode is enabled.
1091 * hw device structure
1092 * enable a code (0x0b|0x0f) that enables/disables
1093 * monitor mode. (host order)
1097 * >0 f/w reported failure - f/w status code
1098 * <0 driver reported error (timeout|bad arg)
1104 ----------------------------------------------------------------*/
1105 int hfa384x_cmd_monitor(hfa384x_t *hw, u16 enable)
1108 hfa384x_metacmd_t cmd;
1110 cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_MONITOR) |
1111 HFA384x_CMD_AINFO_SET(enable);
1116 result = hfa384x_docmd_wait(hw, &cmd);
1121 /*----------------------------------------------------------------
1122 * hfa384x_cmd_download
1124 * Sets the controls for the MAC controller code/data download
1125 * process. The arguments set the mode and address associated
1126 * with a download. Note that the aux registers should be enabled
1127 * prior to setting one of the download enable modes.
1130 * hw device structure
1131 * mode 0 - Disable programming and begin code exec
1132 * 1 - Enable volatile mem programming
1133 * 2 - Enable non-volatile mem programming
1134 * 3 - Program non-volatile section from NV download
1138 * highaddr For mode 1, sets the high & low order bits of
1139 * the "destination address". This address will be
1140 * the execution start address when download is
1141 * subsequently disabled.
1142 * For mode 2, sets the high & low order bits of
1143 * the destination in NV ram.
1144 * For modes 0 & 3, should be zero. (host order)
1145 * NOTE: these are CMD format.
1146 * codelen Length of the data to write in mode 2,
1147 * zero otherwise. (host order)
1151 * >0 f/w reported failure - f/w status code
1152 * <0 driver reported error (timeout|bad arg)
1158 ----------------------------------------------------------------*/
1159 int hfa384x_cmd_download(hfa384x_t *hw, u16 mode, u16 lowaddr,
1160 u16 highaddr, u16 codelen)
1163 hfa384x_metacmd_t cmd;
1165 pr_debug("mode=%d, lowaddr=0x%04x, highaddr=0x%04x, codelen=%d\n",
1166 mode, lowaddr, highaddr, codelen);
1168 cmd.cmd = (HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_DOWNLD) |
1169 HFA384x_CMD_PROGMODE_SET(mode));
1171 cmd.parm0 = lowaddr;
1172 cmd.parm1 = highaddr;
1173 cmd.parm2 = codelen;
1175 result = hfa384x_docmd_wait(hw, &cmd);
1180 /*----------------------------------------------------------------
1183 * Perform a reset of the hfa38xx MAC core. We assume that the hw
1184 * structure is in its "created" state. That is, it is initialized
1185 * with proper values. Note that if a reset is done after the
1186 * device has been active for awhile, the caller might have to clean
1187 * up some leftover cruft in the hw structure.
1190 * hw device structure
1191 * holdtime how long (in ms) to hold the reset
1192 * settletime how long (in ms) to wait after releasing
1202 ----------------------------------------------------------------*/
1203 int hfa384x_corereset(hfa384x_t *hw, int holdtime, int settletime, int genesis)
1207 result = usb_reset_device(hw->usb);
1209 netdev_err(hw->wlandev->netdev, "usb_reset_device() failed, result=%d.\n",
1216 /*----------------------------------------------------------------
1217 * hfa384x_usbctlx_complete_sync
1219 * Waits for a synchronous CTLX object to complete,
1220 * and then handles the response.
1223 * hw device structure
1225 * completor functor object to decide what to
1226 * do with the CTLX's result.
1230 * -ERESTARTSYS Interrupted by a signal
1232 * -ENODEV Adapter was unplugged
1233 * ??? Result from completor
1239 ----------------------------------------------------------------*/
1240 static int hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
1241 hfa384x_usbctlx_t *ctlx,
1242 struct usbctlx_completor *completor)
1244 unsigned long flags;
1247 result = wait_for_completion_interruptible(&ctlx->done);
1249 spin_lock_irqsave(&hw->ctlxq.lock, flags);
1252 * We can only handle the CTLX if the USB disconnect
1253 * function has not run yet ...
1256 if (hw->wlandev->hwremoved) {
1257 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1259 } else if (result != 0) {
1263 * We were probably interrupted, so delete
1264 * this CTLX asynchronously, kill the timers
1265 * and the URB, and then start the next
1268 * NOTE: We can only delete the timers and
1269 * the URB if this CTLX is active.
1271 if (ctlx == get_active_ctlx(hw)) {
1272 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1274 del_singleshot_timer_sync(&hw->reqtimer);
1275 del_singleshot_timer_sync(&hw->resptimer);
1276 hw->req_timer_done = 1;
1277 hw->resp_timer_done = 1;
1278 usb_kill_urb(&hw->ctlx_urb);
1280 spin_lock_irqsave(&hw->ctlxq.lock, flags);
1285 * This scenario is so unlikely that I'm
1286 * happy with a grubby "goto" solution ...
1288 if (hw->wlandev->hwremoved)
1293 * The completion task will send this CTLX
1294 * to the reaper the next time it runs. We
1295 * are no longer in a hurry.
1298 ctlx->state = CTLX_REQ_FAILED;
1299 list_move_tail(&ctlx->list, &hw->ctlxq.completing);
1301 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1304 hfa384x_usbctlxq_run(hw);
1306 if (ctlx->state == CTLX_COMPLETE) {
1307 result = completor->complete(completor);
1309 netdev_warn(hw->wlandev->netdev, "CTLX[%d] error: state(%s)\n",
1310 le16_to_cpu(ctlx->outbuf.type),
1311 ctlxstr(ctlx->state));
1315 list_del(&ctlx->list);
1316 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1323 /*----------------------------------------------------------------
1326 * Constructs a command CTLX and submits it.
1328 * NOTE: Any changes to the 'post-submit' code in this function
1329 * need to be carried over to hfa384x_cbcmd() since the handling
1330 * is virtually identical.
1333 * hw device structure
1334 * mode DOWAIT or DOASYNC
1335 * cmd cmd structure. Includes all arguments and result
1336 * data points. All in host order. in host order
1337 * cmdcb command-specific callback
1338 * usercb user callback for async calls, NULL for DOWAIT calls
1339 * usercb_data user supplied data pointer for async calls, NULL
1345 * -ERESTARTSYS Awakened on signal
1346 * >0 command indicated error, Status and Resp0-2 are
1354 ----------------------------------------------------------------*/
1356 hfa384x_docmd(hfa384x_t *hw,
1358 hfa384x_metacmd_t *cmd,
1359 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1362 hfa384x_usbctlx_t *ctlx;
1364 ctlx = usbctlx_alloc();
1370 /* Initialize the command */
1371 ctlx->outbuf.cmdreq.type = cpu_to_le16(HFA384x_USB_CMDREQ);
1372 ctlx->outbuf.cmdreq.cmd = cpu_to_le16(cmd->cmd);
1373 ctlx->outbuf.cmdreq.parm0 = cpu_to_le16(cmd->parm0);
1374 ctlx->outbuf.cmdreq.parm1 = cpu_to_le16(cmd->parm1);
1375 ctlx->outbuf.cmdreq.parm2 = cpu_to_le16(cmd->parm2);
1377 ctlx->outbufsize = sizeof(ctlx->outbuf.cmdreq);
1379 pr_debug("cmdreq: cmd=0x%04x parm0=0x%04x parm1=0x%04x parm2=0x%04x\n",
1380 cmd->cmd, cmd->parm0, cmd->parm1, cmd->parm2);
1382 ctlx->reapable = mode;
1383 ctlx->cmdcb = cmdcb;
1384 ctlx->usercb = usercb;
1385 ctlx->usercb_data = usercb_data;
1387 result = hfa384x_usbctlx_submit(hw, ctlx);
1390 } else if (mode == DOWAIT) {
1391 struct usbctlx_cmd_completor completor;
1394 hfa384x_usbctlx_complete_sync(hw, ctlx,
1395 init_cmd_completor(&completor,
1407 /*----------------------------------------------------------------
1410 * Constructs a read rid CTLX and issues it.
1412 * NOTE: Any changes to the 'post-submit' code in this function
1413 * need to be carried over to hfa384x_cbrrid() since the handling
1414 * is virtually identical.
1417 * hw device structure
1418 * mode DOWAIT or DOASYNC
1419 * rid Read RID number (host order)
1420 * riddata Caller supplied buffer that MAC formatted RID.data
1421 * record will be written to for DOWAIT calls. Should
1422 * be NULL for DOASYNC calls.
1423 * riddatalen Buffer length for DOWAIT calls. Zero for DOASYNC calls.
1424 * cmdcb command callback for async calls, NULL for DOWAIT calls
1425 * usercb user callback for async calls, NULL for DOWAIT calls
1426 * usercb_data user supplied data pointer for async calls, NULL
1432 * -ERESTARTSYS Awakened on signal
1433 * -ENODATA riddatalen != macdatalen
1434 * >0 command indicated error, Status and Resp0-2 are
1440 * interrupt (DOASYNC)
1441 * process (DOWAIT or DOASYNC)
1442 ----------------------------------------------------------------*/
1444 hfa384x_dorrid(hfa384x_t *hw,
1448 unsigned int riddatalen,
1449 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1452 hfa384x_usbctlx_t *ctlx;
1454 ctlx = usbctlx_alloc();
1460 /* Initialize the command */
1461 ctlx->outbuf.rridreq.type = cpu_to_le16(HFA384x_USB_RRIDREQ);
1462 ctlx->outbuf.rridreq.frmlen =
1463 cpu_to_le16(sizeof(ctlx->outbuf.rridreq.rid));
1464 ctlx->outbuf.rridreq.rid = cpu_to_le16(rid);
1466 ctlx->outbufsize = sizeof(ctlx->outbuf.rridreq);
1468 ctlx->reapable = mode;
1469 ctlx->cmdcb = cmdcb;
1470 ctlx->usercb = usercb;
1471 ctlx->usercb_data = usercb_data;
1473 /* Submit the CTLX */
1474 result = hfa384x_usbctlx_submit(hw, ctlx);
1477 } else if (mode == DOWAIT) {
1478 struct usbctlx_rrid_completor completor;
1481 hfa384x_usbctlx_complete_sync(hw, ctlx,
1484 &ctlx->inbuf.rridresp,
1485 riddata, riddatalen));
1492 /*----------------------------------------------------------------
1495 * Constructs a write rid CTLX and issues it.
1497 * NOTE: Any changes to the 'post-submit' code in this function
1498 * need to be carried over to hfa384x_cbwrid() since the handling
1499 * is virtually identical.
1502 * hw device structure
1503 * enum cmd_mode DOWAIT or DOASYNC
1505 * riddata Data portion of RID formatted for MAC
1506 * riddatalen Length of the data portion in bytes
1507 * cmdcb command callback for async calls, NULL for DOWAIT calls
1508 * usercb user callback for async calls, NULL for DOWAIT calls
1509 * usercb_data user supplied data pointer for async calls
1513 * -ETIMEDOUT timed out waiting for register ready or
1514 * command completion
1515 * >0 command indicated error, Status and Resp0-2 are
1521 * interrupt (DOASYNC)
1522 * process (DOWAIT or DOASYNC)
1523 ----------------------------------------------------------------*/
1525 hfa384x_dowrid(hfa384x_t *hw,
1529 unsigned int riddatalen,
1530 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1533 hfa384x_usbctlx_t *ctlx;
1535 ctlx = usbctlx_alloc();
1541 /* Initialize the command */
1542 ctlx->outbuf.wridreq.type = cpu_to_le16(HFA384x_USB_WRIDREQ);
1543 ctlx->outbuf.wridreq.frmlen = cpu_to_le16((sizeof
1544 (ctlx->outbuf.wridreq.rid) +
1545 riddatalen + 1) / 2);
1546 ctlx->outbuf.wridreq.rid = cpu_to_le16(rid);
1547 memcpy(ctlx->outbuf.wridreq.data, riddata, riddatalen);
1549 ctlx->outbufsize = sizeof(ctlx->outbuf.wridreq.type) +
1550 sizeof(ctlx->outbuf.wridreq.frmlen) +
1551 sizeof(ctlx->outbuf.wridreq.rid) + riddatalen;
1553 ctlx->reapable = mode;
1554 ctlx->cmdcb = cmdcb;
1555 ctlx->usercb = usercb;
1556 ctlx->usercb_data = usercb_data;
1558 /* Submit the CTLX */
1559 result = hfa384x_usbctlx_submit(hw, ctlx);
1562 } else if (mode == DOWAIT) {
1563 struct usbctlx_cmd_completor completor;
1564 hfa384x_cmdresult_t wridresult;
1566 result = hfa384x_usbctlx_complete_sync(hw,
1570 &ctlx->inbuf.wridresp,
1578 /*----------------------------------------------------------------
1581 * Constructs a readmem CTLX and issues it.
1583 * NOTE: Any changes to the 'post-submit' code in this function
1584 * need to be carried over to hfa384x_cbrmem() since the handling
1585 * is virtually identical.
1588 * hw device structure
1589 * mode DOWAIT or DOASYNC
1590 * page MAC address space page (CMD format)
1591 * offset MAC address space offset
1592 * data Ptr to data buffer to receive read
1593 * len Length of the data to read (max == 2048)
1594 * cmdcb command callback for async calls, NULL for DOWAIT calls
1595 * usercb user callback for async calls, NULL for DOWAIT calls
1596 * usercb_data user supplied data pointer for async calls
1600 * -ETIMEDOUT timed out waiting for register ready or
1601 * command completion
1602 * >0 command indicated error, Status and Resp0-2 are
1608 * interrupt (DOASYNC)
1609 * process (DOWAIT or DOASYNC)
1610 ----------------------------------------------------------------*/
1612 hfa384x_dormem(hfa384x_t *hw,
1618 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1621 hfa384x_usbctlx_t *ctlx;
1623 ctlx = usbctlx_alloc();
1629 /* Initialize the command */
1630 ctlx->outbuf.rmemreq.type = cpu_to_le16(HFA384x_USB_RMEMREQ);
1631 ctlx->outbuf.rmemreq.frmlen =
1632 cpu_to_le16(sizeof(ctlx->outbuf.rmemreq.offset) +
1633 sizeof(ctlx->outbuf.rmemreq.page) + len);
1634 ctlx->outbuf.rmemreq.offset = cpu_to_le16(offset);
1635 ctlx->outbuf.rmemreq.page = cpu_to_le16(page);
1637 ctlx->outbufsize = sizeof(ctlx->outbuf.rmemreq);
1639 pr_debug("type=0x%04x frmlen=%d offset=0x%04x page=0x%04x\n",
1640 ctlx->outbuf.rmemreq.type,
1641 ctlx->outbuf.rmemreq.frmlen,
1642 ctlx->outbuf.rmemreq.offset, ctlx->outbuf.rmemreq.page);
1644 pr_debug("pktsize=%zd\n", ROUNDUP64(sizeof(ctlx->outbuf.rmemreq)));
1646 ctlx->reapable = mode;
1647 ctlx->cmdcb = cmdcb;
1648 ctlx->usercb = usercb;
1649 ctlx->usercb_data = usercb_data;
1651 result = hfa384x_usbctlx_submit(hw, ctlx);
1654 } else if (mode == DOWAIT) {
1655 struct usbctlx_rmem_completor completor;
1658 hfa384x_usbctlx_complete_sync(hw, ctlx,
1661 &ctlx->inbuf.rmemresp, data,
1669 /*----------------------------------------------------------------
1672 * Constructs a writemem CTLX and issues it.
1674 * NOTE: Any changes to the 'post-submit' code in this function
1675 * need to be carried over to hfa384x_cbwmem() since the handling
1676 * is virtually identical.
1679 * hw device structure
1680 * mode DOWAIT or DOASYNC
1681 * page MAC address space page (CMD format)
1682 * offset MAC address space offset
1683 * data Ptr to data buffer containing write data
1684 * len Length of the data to read (max == 2048)
1685 * cmdcb command callback for async calls, NULL for DOWAIT calls
1686 * usercb user callback for async calls, NULL for DOWAIT calls
1687 * usercb_data user supplied data pointer for async calls.
1691 * -ETIMEDOUT timed out waiting for register ready or
1692 * command completion
1693 * >0 command indicated error, Status and Resp0-2 are
1699 * interrupt (DOWAIT)
1700 * process (DOWAIT or DOASYNC)
1701 ----------------------------------------------------------------*/
1703 hfa384x_dowmem(hfa384x_t *hw,
1709 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1712 hfa384x_usbctlx_t *ctlx;
1714 pr_debug("page=0x%04x offset=0x%04x len=%d\n", page, offset, len);
1716 ctlx = usbctlx_alloc();
1722 /* Initialize the command */
1723 ctlx->outbuf.wmemreq.type = cpu_to_le16(HFA384x_USB_WMEMREQ);
1724 ctlx->outbuf.wmemreq.frmlen =
1725 cpu_to_le16(sizeof(ctlx->outbuf.wmemreq.offset) +
1726 sizeof(ctlx->outbuf.wmemreq.page) + len);
1727 ctlx->outbuf.wmemreq.offset = cpu_to_le16(offset);
1728 ctlx->outbuf.wmemreq.page = cpu_to_le16(page);
1729 memcpy(ctlx->outbuf.wmemreq.data, data, len);
1731 ctlx->outbufsize = sizeof(ctlx->outbuf.wmemreq.type) +
1732 sizeof(ctlx->outbuf.wmemreq.frmlen) +
1733 sizeof(ctlx->outbuf.wmemreq.offset) +
1734 sizeof(ctlx->outbuf.wmemreq.page) + len;
1736 ctlx->reapable = mode;
1737 ctlx->cmdcb = cmdcb;
1738 ctlx->usercb = usercb;
1739 ctlx->usercb_data = usercb_data;
1741 result = hfa384x_usbctlx_submit(hw, ctlx);
1744 } else if (mode == DOWAIT) {
1745 struct usbctlx_cmd_completor completor;
1746 hfa384x_cmdresult_t wmemresult;
1748 result = hfa384x_usbctlx_complete_sync(hw,
1752 &ctlx->inbuf.wmemresp,
1760 /*----------------------------------------------------------------
1761 * hfa384x_drvr_commtallies
1763 * Send a commtallies inquiry to the MAC. Note that this is an async
1764 * call that will result in an info frame arriving sometime later.
1767 * hw device structure
1776 ----------------------------------------------------------------*/
1777 int hfa384x_drvr_commtallies(hfa384x_t *hw)
1779 hfa384x_metacmd_t cmd;
1781 cmd.cmd = HFA384x_CMDCODE_INQ;
1782 cmd.parm0 = HFA384x_IT_COMMTALLIES;
1786 hfa384x_docmd_async(hw, &cmd, NULL, NULL, NULL);
1791 /*----------------------------------------------------------------
1792 * hfa384x_drvr_disable
1794 * Issues the disable command to stop communications on one of
1795 * the MACs 'ports'. Only macport 0 is valid for stations.
1796 * APs may also disable macports 1-6. Only ports that have been
1797 * previously enabled may be disabled.
1800 * hw device structure
1801 * macport MAC port number (host order)
1805 * >0 f/w reported failure - f/w status code
1806 * <0 driver reported error (timeout|bad arg)
1812 ----------------------------------------------------------------*/
1813 int hfa384x_drvr_disable(hfa384x_t *hw, u16 macport)
1817 if ((!hw->isap && macport != 0) ||
1818 (hw->isap && !(macport <= HFA384x_PORTID_MAX)) ||
1819 !(hw->port_enabled[macport])) {
1822 result = hfa384x_cmd_disable(hw, macport);
1824 hw->port_enabled[macport] = 0;
1829 /*----------------------------------------------------------------
1830 * hfa384x_drvr_enable
1832 * Issues the enable command to enable communications on one of
1833 * the MACs 'ports'. Only macport 0 is valid for stations.
1834 * APs may also enable macports 1-6. Only ports that are currently
1835 * disabled may be enabled.
1838 * hw device structure
1839 * macport MAC port number
1843 * >0 f/w reported failure - f/w status code
1844 * <0 driver reported error (timeout|bad arg)
1850 ----------------------------------------------------------------*/
1851 int hfa384x_drvr_enable(hfa384x_t *hw, u16 macport)
1855 if ((!hw->isap && macport != 0) ||
1856 (hw->isap && !(macport <= HFA384x_PORTID_MAX)) ||
1857 (hw->port_enabled[macport])) {
1860 result = hfa384x_cmd_enable(hw, macport);
1862 hw->port_enabled[macport] = 1;
1867 /*----------------------------------------------------------------
1868 * hfa384x_drvr_flashdl_enable
1870 * Begins the flash download state. Checks to see that we're not
1871 * already in a download state and that a port isn't enabled.
1872 * Sets the download state and retrieves the flash download
1873 * buffer location, buffer size, and timeout length.
1876 * hw device structure
1880 * >0 f/w reported error - f/w status code
1881 * <0 driver reported error
1887 ----------------------------------------------------------------*/
1888 int hfa384x_drvr_flashdl_enable(hfa384x_t *hw)
1893 /* Check that a port isn't active */
1894 for (i = 0; i < HFA384x_PORTID_MAX; i++) {
1895 if (hw->port_enabled[i]) {
1896 pr_debug("called when port enabled.\n");
1901 /* Check that we're not already in a download state */
1902 if (hw->dlstate != HFA384x_DLSTATE_DISABLED)
1905 /* Retrieve the buffer loc&size and timeout */
1906 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_DOWNLOADBUFFER,
1907 &(hw->bufinfo), sizeof(hw->bufinfo));
1911 hw->bufinfo.page = le16_to_cpu(hw->bufinfo.page);
1912 hw->bufinfo.offset = le16_to_cpu(hw->bufinfo.offset);
1913 hw->bufinfo.len = le16_to_cpu(hw->bufinfo.len);
1914 result = hfa384x_drvr_getconfig16(hw, HFA384x_RID_MAXLOADTIME,
1919 hw->dltimeout = le16_to_cpu(hw->dltimeout);
1921 pr_debug("flashdl_enable\n");
1923 hw->dlstate = HFA384x_DLSTATE_FLASHENABLED;
1928 /*----------------------------------------------------------------
1929 * hfa384x_drvr_flashdl_disable
1931 * Ends the flash download state. Note that this will cause the MAC
1932 * firmware to restart.
1935 * hw device structure
1939 * >0 f/w reported error - f/w status code
1940 * <0 driver reported error
1946 ----------------------------------------------------------------*/
1947 int hfa384x_drvr_flashdl_disable(hfa384x_t *hw)
1949 /* Check that we're already in the download state */
1950 if (hw->dlstate != HFA384x_DLSTATE_FLASHENABLED)
1953 pr_debug("flashdl_enable\n");
1955 /* There isn't much we can do at this point, so I don't */
1956 /* bother w/ the return value */
1957 hfa384x_cmd_download(hw, HFA384x_PROGMODE_DISABLE, 0, 0, 0);
1958 hw->dlstate = HFA384x_DLSTATE_DISABLED;
1963 /*----------------------------------------------------------------
1964 * hfa384x_drvr_flashdl_write
1966 * Performs a FLASH download of a chunk of data. First checks to see
1967 * that we're in the FLASH download state, then sets the download
1968 * mode, uses the aux functions to 1) copy the data to the flash
1969 * buffer, 2) sets the download 'write flash' mode, 3) readback and
1970 * compare. Lather rinse, repeat as many times an necessary to get
1971 * all the given data into flash.
1972 * When all data has been written using this function (possibly
1973 * repeatedly), call drvr_flashdl_disable() to end the download state
1974 * and restart the MAC.
1977 * hw device structure
1978 * daddr Card address to write to. (host order)
1979 * buf Ptr to data to write.
1980 * len Length of data (host order).
1984 * >0 f/w reported error - f/w status code
1985 * <0 driver reported error
1991 ----------------------------------------------------------------*/
1992 int hfa384x_drvr_flashdl_write(hfa384x_t *hw, u32 daddr, void *buf, u32 len)
2009 pr_debug("daddr=0x%08x len=%d\n", daddr, len);
2011 /* Check that we're in the flash download state */
2012 if (hw->dlstate != HFA384x_DLSTATE_FLASHENABLED)
2015 netdev_info(hw->wlandev->netdev,
2016 "Download %d bytes to flash @0x%06x\n", len, daddr);
2018 /* Convert to flat address for arithmetic */
2019 /* NOTE: dlbuffer RID stores the address in AUX format */
2021 HFA384x_ADDR_AUX_MKFLAT(hw->bufinfo.page, hw->bufinfo.offset);
2022 pr_debug("dlbuf.page=0x%04x dlbuf.offset=0x%04x dlbufaddr=0x%08x\n",
2023 hw->bufinfo.page, hw->bufinfo.offset, dlbufaddr);
2026 netdev_warn(hw->wlandev->netdev,
2027 "dlbuf@0x%06lx len=%d to=%d\n", dlbufaddr,
2028 hw->bufinfo.len, hw->dltimeout);
2030 /* Calculations to determine how many fills of the dlbuffer to do
2031 * and how many USB wmemreq's to do for each fill. At this point
2032 * in time, the dlbuffer size and the wmemreq size are the same.
2033 * Therefore, nwrites should always be 1. The extra complexity
2034 * here is a hedge against future changes.
2037 /* Figure out how many times to do the flash programming */
2038 nburns = len / hw->bufinfo.len;
2039 nburns += (len % hw->bufinfo.len) ? 1 : 0;
2041 /* For each flash program cycle, how many USB wmemreq's are needed? */
2042 nwrites = hw->bufinfo.len / HFA384x_USB_RWMEM_MAXLEN;
2043 nwrites += (hw->bufinfo.len % HFA384x_USB_RWMEM_MAXLEN) ? 1 : 0;
2046 for (i = 0; i < nburns; i++) {
2047 /* Get the dest address and len */
2048 burnlen = (len - (hw->bufinfo.len * i)) > hw->bufinfo.len ?
2049 hw->bufinfo.len : (len - (hw->bufinfo.len * i));
2050 burndaddr = daddr + (hw->bufinfo.len * i);
2051 burnlo = HFA384x_ADDR_CMD_MKOFF(burndaddr);
2052 burnhi = HFA384x_ADDR_CMD_MKPAGE(burndaddr);
2054 netdev_info(hw->wlandev->netdev, "Writing %d bytes to flash @0x%06x\n",
2055 burnlen, burndaddr);
2057 /* Set the download mode */
2058 result = hfa384x_cmd_download(hw, HFA384x_PROGMODE_NV,
2059 burnlo, burnhi, burnlen);
2061 netdev_err(hw->wlandev->netdev,
2062 "download(NV,lo=%x,hi=%x,len=%x) cmd failed, result=%d. Aborting d/l\n",
2063 burnlo, burnhi, burnlen, result);
2067 /* copy the data to the flash download buffer */
2068 for (j = 0; j < nwrites; j++) {
2070 (i * hw->bufinfo.len) +
2071 (j * HFA384x_USB_RWMEM_MAXLEN);
2073 writepage = HFA384x_ADDR_CMD_MKPAGE(dlbufaddr +
2074 (j * HFA384x_USB_RWMEM_MAXLEN));
2075 writeoffset = HFA384x_ADDR_CMD_MKOFF(dlbufaddr +
2076 (j * HFA384x_USB_RWMEM_MAXLEN));
2078 writelen = burnlen - (j * HFA384x_USB_RWMEM_MAXLEN);
2079 writelen = writelen > HFA384x_USB_RWMEM_MAXLEN ?
2080 HFA384x_USB_RWMEM_MAXLEN : writelen;
2082 result = hfa384x_dowmem_wait(hw,
2085 writebuf, writelen);
2088 /* set the download 'write flash' mode */
2089 result = hfa384x_cmd_download(hw,
2090 HFA384x_PROGMODE_NVWRITE,
2093 netdev_err(hw->wlandev->netdev,
2094 "download(NVWRITE,lo=%x,hi=%x,len=%x) cmd failed, result=%d. Aborting d/l\n",
2095 burnlo, burnhi, burnlen, result);
2099 /* TODO: We really should do a readback and compare. */
2104 /* Leave the firmware in the 'post-prog' mode. flashdl_disable will */
2105 /* actually disable programming mode. Remember, that will cause the */
2106 /* the firmware to effectively reset itself. */
2111 /*----------------------------------------------------------------
2112 * hfa384x_drvr_getconfig
2114 * Performs the sequence necessary to read a config/info item.
2117 * hw device structure
2118 * rid config/info record id (host order)
2119 * buf host side record buffer. Upon return it will
2120 * contain the body portion of the record (minus the
2122 * len buffer length (in bytes, should match record length)
2126 * >0 f/w reported error - f/w status code
2127 * <0 driver reported error
2128 * -ENODATA length mismatch between argument and retrieved
2135 ----------------------------------------------------------------*/
2136 int hfa384x_drvr_getconfig(hfa384x_t *hw, u16 rid, void *buf, u16 len)
2138 return hfa384x_dorrid_wait(hw, rid, buf, len);
2141 /*----------------------------------------------------------------
2142 * hfa384x_drvr_getconfig_async
2144 * Performs the sequence necessary to perform an async read of
2145 * of a config/info item.
2148 * hw device structure
2149 * rid config/info record id (host order)
2150 * buf host side record buffer. Upon return it will
2151 * contain the body portion of the record (minus the
2153 * len buffer length (in bytes, should match record length)
2154 * cbfn caller supplied callback, called when the command
2155 * is done (successful or not).
2156 * cbfndata pointer to some caller supplied data that will be
2157 * passed in as an argument to the cbfn.
2160 * nothing the cbfn gets a status argument identifying if
2163 * Queues an hfa384x_usbcmd_t for subsequent execution.
2167 ----------------------------------------------------------------*/
2169 hfa384x_drvr_getconfig_async(hfa384x_t *hw,
2170 u16 rid, ctlx_usercb_t usercb, void *usercb_data)
2172 return hfa384x_dorrid_async(hw, rid, NULL, 0,
2173 hfa384x_cb_rrid, usercb, usercb_data);
2176 /*----------------------------------------------------------------
2177 * hfa384x_drvr_setconfig_async
2179 * Performs the sequence necessary to write a config/info item.
2182 * hw device structure
2183 * rid config/info record id (in host order)
2184 * buf host side record buffer
2185 * len buffer length (in bytes)
2186 * usercb completion callback
2187 * usercb_data completion callback argument
2191 * >0 f/w reported error - f/w status code
2192 * <0 driver reported error
2198 ----------------------------------------------------------------*/
2200 hfa384x_drvr_setconfig_async(hfa384x_t *hw,
2203 u16 len, ctlx_usercb_t usercb, void *usercb_data)
2205 return hfa384x_dowrid_async(hw, rid, buf, len,
2206 hfa384x_cb_status, usercb, usercb_data);
2209 /*----------------------------------------------------------------
2210 * hfa384x_drvr_ramdl_disable
2212 * Ends the ram download state.
2215 * hw device structure
2219 * >0 f/w reported error - f/w status code
2220 * <0 driver reported error
2226 ----------------------------------------------------------------*/
2227 int hfa384x_drvr_ramdl_disable(hfa384x_t *hw)
2229 /* Check that we're already in the download state */
2230 if (hw->dlstate != HFA384x_DLSTATE_RAMENABLED)
2233 pr_debug("ramdl_disable()\n");
2235 /* There isn't much we can do at this point, so I don't */
2236 /* bother w/ the return value */
2237 hfa384x_cmd_download(hw, HFA384x_PROGMODE_DISABLE, 0, 0, 0);
2238 hw->dlstate = HFA384x_DLSTATE_DISABLED;
2243 /*----------------------------------------------------------------
2244 * hfa384x_drvr_ramdl_enable
2246 * Begins the ram download state. Checks to see that we're not
2247 * already in a download state and that a port isn't enabled.
2248 * Sets the download state and calls cmd_download with the
2249 * ENABLE_VOLATILE subcommand and the exeaddr argument.
2252 * hw device structure
2253 * exeaddr the card execution address that will be
2254 * jumped to when ramdl_disable() is called
2259 * >0 f/w reported error - f/w status code
2260 * <0 driver reported error
2266 ----------------------------------------------------------------*/
2267 int hfa384x_drvr_ramdl_enable(hfa384x_t *hw, u32 exeaddr)
2274 /* Check that a port isn't active */
2275 for (i = 0; i < HFA384x_PORTID_MAX; i++) {
2276 if (hw->port_enabled[i]) {
2277 netdev_err(hw->wlandev->netdev,
2278 "Can't download with a macport enabled.\n");
2283 /* Check that we're not already in a download state */
2284 if (hw->dlstate != HFA384x_DLSTATE_DISABLED) {
2285 netdev_err(hw->wlandev->netdev, "Download state not disabled.\n");
2289 pr_debug("ramdl_enable, exeaddr=0x%08x\n", exeaddr);
2291 /* Call the download(1,addr) function */
2292 lowaddr = HFA384x_ADDR_CMD_MKOFF(exeaddr);
2293 hiaddr = HFA384x_ADDR_CMD_MKPAGE(exeaddr);
2295 result = hfa384x_cmd_download(hw, HFA384x_PROGMODE_RAM,
2296 lowaddr, hiaddr, 0);
2299 /* Set the download state */
2300 hw->dlstate = HFA384x_DLSTATE_RAMENABLED;
2302 pr_debug("cmd_download(0x%04x, 0x%04x) failed, result=%d.\n",
2303 lowaddr, hiaddr, result);
2309 /*----------------------------------------------------------------
2310 * hfa384x_drvr_ramdl_write
2312 * Performs a RAM download of a chunk of data. First checks to see
2313 * that we're in the RAM download state, then uses the [read|write]mem USB
2314 * commands to 1) copy the data, 2) readback and compare. The download
2315 * state is unaffected. When all data has been written using
2316 * this function, call drvr_ramdl_disable() to end the download state
2317 * and restart the MAC.
2320 * hw device structure
2321 * daddr Card address to write to. (host order)
2322 * buf Ptr to data to write.
2323 * len Length of data (host order).
2327 * >0 f/w reported error - f/w status code
2328 * <0 driver reported error
2334 ----------------------------------------------------------------*/
2335 int hfa384x_drvr_ramdl_write(hfa384x_t *hw, u32 daddr, void *buf, u32 len)
2346 /* Check that we're in the ram download state */
2347 if (hw->dlstate != HFA384x_DLSTATE_RAMENABLED)
2350 netdev_info(hw->wlandev->netdev, "Writing %d bytes to ram @0x%06x\n",
2353 /* How many dowmem calls? */
2354 nwrites = len / HFA384x_USB_RWMEM_MAXLEN;
2355 nwrites += len % HFA384x_USB_RWMEM_MAXLEN ? 1 : 0;
2357 /* Do blocking wmem's */
2358 for (i = 0; i < nwrites; i++) {
2359 /* make address args */
2360 curraddr = daddr + (i * HFA384x_USB_RWMEM_MAXLEN);
2361 currpage = HFA384x_ADDR_CMD_MKPAGE(curraddr);
2362 curroffset = HFA384x_ADDR_CMD_MKOFF(curraddr);
2363 currlen = len - (i * HFA384x_USB_RWMEM_MAXLEN);
2364 if (currlen > HFA384x_USB_RWMEM_MAXLEN)
2365 currlen = HFA384x_USB_RWMEM_MAXLEN;
2367 /* Do blocking ctlx */
2368 result = hfa384x_dowmem_wait(hw,
2372 (i * HFA384x_USB_RWMEM_MAXLEN),
2378 /* TODO: We really should have a readback. */
2384 /*----------------------------------------------------------------
2385 * hfa384x_drvr_readpda
2387 * Performs the sequence to read the PDA space. Note there is no
2388 * drvr_writepda() function. Writing a PDA is
2389 * generally implemented by a calling component via calls to
2390 * cmd_download and writing to the flash download buffer via the
2394 * hw device structure
2395 * buf buffer to store PDA in
2400 * >0 f/w reported error - f/w status code
2401 * <0 driver reported error
2402 * -ETIMEDOUT timout waiting for the cmd regs to become
2403 * available, or waiting for the control reg
2404 * to indicate the Aux port is enabled.
2405 * -ENODATA the buffer does NOT contain a valid PDA.
2406 * Either the card PDA is bad, or the auxdata
2407 * reads are giving us garbage.
2413 * process or non-card interrupt.
2414 ----------------------------------------------------------------*/
2415 int hfa384x_drvr_readpda(hfa384x_t *hw, void *buf, unsigned int len)
2421 int currpdr = 0; /* word offset of the current pdr */
2423 u16 pdrlen; /* pdr length in bytes, host order */
2424 u16 pdrcode; /* pdr code, host order */
2432 HFA3842_PDA_BASE, 0}, {
2433 HFA3841_PDA_BASE, 0}, {
2434 HFA3841_PDA_BOGUS_BASE, 0}
2437 /* Read the pda from each known address. */
2438 for (i = 0; i < ARRAY_SIZE(pdaloc); i++) {
2440 currpage = HFA384x_ADDR_CMD_MKPAGE(pdaloc[i].cardaddr);
2441 curroffset = HFA384x_ADDR_CMD_MKOFF(pdaloc[i].cardaddr);
2443 /* units of bytes */
2444 result = hfa384x_dormem_wait(hw, currpage, curroffset, buf,
2448 netdev_warn(hw->wlandev->netdev,
2449 "Read from index %zd failed, continuing\n",
2454 /* Test for garbage */
2455 pdaok = 1; /* initially assume good */
2457 while (pdaok && morepdrs) {
2458 pdrlen = le16_to_cpu(pda[currpdr]) * 2;
2459 pdrcode = le16_to_cpu(pda[currpdr + 1]);
2460 /* Test the record length */
2461 if (pdrlen > HFA384x_PDR_LEN_MAX || pdrlen == 0) {
2462 netdev_err(hw->wlandev->netdev,
2463 "pdrlen invalid=%d\n", pdrlen);
2468 if (!hfa384x_isgood_pdrcode(pdrcode)) {
2469 netdev_err(hw->wlandev->netdev, "pdrcode invalid=%d\n",
2474 /* Test for completion */
2475 if (pdrcode == HFA384x_PDR_END_OF_PDA)
2478 /* Move to the next pdr (if necessary) */
2480 /* note the access to pda[], need words here */
2481 currpdr += le16_to_cpu(pda[currpdr]) + 1;
2485 netdev_info(hw->wlandev->netdev,
2486 "PDA Read from 0x%08x in %s space.\n",
2488 pdaloc[i].auxctl == 0 ? "EXTDS" :
2489 pdaloc[i].auxctl == 1 ? "NV" :
2490 pdaloc[i].auxctl == 2 ? "PHY" :
2491 pdaloc[i].auxctl == 3 ? "ICSRAM" :
2496 result = pdaok ? 0 : -ENODATA;
2499 pr_debug("Failure: pda is not okay\n");
2504 /*----------------------------------------------------------------
2505 * hfa384x_drvr_setconfig
2507 * Performs the sequence necessary to write a config/info item.
2510 * hw device structure
2511 * rid config/info record id (in host order)
2512 * buf host side record buffer
2513 * len buffer length (in bytes)
2517 * >0 f/w reported error - f/w status code
2518 * <0 driver reported error
2524 ----------------------------------------------------------------*/
2525 int hfa384x_drvr_setconfig(hfa384x_t *hw, u16 rid, void *buf, u16 len)
2527 return hfa384x_dowrid_wait(hw, rid, buf, len);
2530 /*----------------------------------------------------------------
2531 * hfa384x_drvr_start
2533 * Issues the MAC initialize command, sets up some data structures,
2534 * and enables the interrupts. After this function completes, the
2535 * low-level stuff should be ready for any/all commands.
2538 * hw device structure
2541 * >0 f/w reported error - f/w status code
2542 * <0 driver reported error
2548 ----------------------------------------------------------------*/
2550 int hfa384x_drvr_start(hfa384x_t *hw)
2552 int result, result1, result2;
2557 /* Clear endpoint stalls - but only do this if the endpoint
2558 * is showing a stall status. Some prism2 cards seem to behave
2559 * badly if a clear_halt is called when the endpoint is already
2563 usb_get_status(hw->usb, USB_RECIP_ENDPOINT, hw->endp_in, &status);
2565 netdev_err(hw->wlandev->netdev, "Cannot get bulk in endpoint status.\n");
2568 if ((status == 1) && usb_clear_halt(hw->usb, hw->endp_in))
2569 netdev_err(hw->wlandev->netdev, "Failed to reset bulk in endpoint.\n");
2572 usb_get_status(hw->usb, USB_RECIP_ENDPOINT, hw->endp_out, &status);
2574 netdev_err(hw->wlandev->netdev, "Cannot get bulk out endpoint status.\n");
2577 if ((status == 1) && usb_clear_halt(hw->usb, hw->endp_out))
2578 netdev_err(hw->wlandev->netdev, "Failed to reset bulk out endpoint.\n");
2580 /* Synchronous unlink, in case we're trying to restart the driver */
2581 usb_kill_urb(&hw->rx_urb);
2583 /* Post the IN urb */
2584 result = submit_rx_urb(hw, GFP_KERNEL);
2586 netdev_err(hw->wlandev->netdev,
2587 "Fatal, failed to submit RX URB, result=%d\n",
2592 /* Call initialize twice, with a 1 second sleep in between.
2593 * This is a nasty work-around since many prism2 cards seem to
2594 * need time to settle after an init from cold. The second
2595 * call to initialize in theory is not necessary - but we call
2596 * it anyway as a double insurance policy:
2597 * 1) If the first init should fail, the second may well succeed
2598 * and the card can still be used
2599 * 2) It helps ensures all is well with the card after the first
2600 * init and settle time.
2602 result1 = hfa384x_cmd_initialize(hw);
2604 result = result2 = hfa384x_cmd_initialize(hw);
2607 netdev_err(hw->wlandev->netdev,
2608 "cmd_initialize() failed on two attempts, results %d and %d\n",
2610 usb_kill_urb(&hw->rx_urb);
2613 pr_debug("First cmd_initialize() failed (result %d),\n",
2615 pr_debug("but second attempt succeeded. All should be ok\n");
2617 } else if (result2 != 0) {
2618 netdev_warn(hw->wlandev->netdev, "First cmd_initialize() succeeded, but second attempt failed (result=%d)\n",
2620 netdev_warn(hw->wlandev->netdev,
2621 "Most likely the card will be functional\n");
2625 hw->state = HFA384x_STATE_RUNNING;
2631 /*----------------------------------------------------------------
2634 * Shuts down the MAC to the point where it is safe to unload the
2635 * driver. Any subsystem that may be holding a data or function
2636 * ptr into the driver must be cleared/deinitialized.
2639 * hw device structure
2642 * >0 f/w reported error - f/w status code
2643 * <0 driver reported error
2649 ----------------------------------------------------------------*/
2650 int hfa384x_drvr_stop(hfa384x_t *hw)
2657 /* There's no need for spinlocks here. The USB "disconnect"
2658 * function sets this "removed" flag and then calls us.
2660 if (!hw->wlandev->hwremoved) {
2661 /* Call initialize to leave the MAC in its 'reset' state */
2662 hfa384x_cmd_initialize(hw);
2664 /* Cancel the rxurb */
2665 usb_kill_urb(&hw->rx_urb);
2668 hw->link_status = HFA384x_LINK_NOTCONNECTED;
2669 hw->state = HFA384x_STATE_INIT;
2671 del_timer_sync(&hw->commsqual_timer);
2673 /* Clear all the port status */
2674 for (i = 0; i < HFA384x_NUMPORTS_MAX; i++)
2675 hw->port_enabled[i] = 0;
2680 /*----------------------------------------------------------------
2681 * hfa384x_drvr_txframe
2683 * Takes a frame from prism2sta and queues it for transmission.
2686 * hw device structure
2687 * skb packet buffer struct. Contains an 802.11
2689 * p80211_hdr points to the 802.11 header for the packet.
2691 * 0 Success and more buffs available
2692 * 1 Success but no more buffs
2693 * 2 Allocation failure
2694 * 4 Buffer full or queue busy
2700 ----------------------------------------------------------------*/
2701 int hfa384x_drvr_txframe(hfa384x_t *hw, struct sk_buff *skb,
2702 union p80211_hdr *p80211_hdr,
2703 struct p80211_metawep *p80211_wep)
2705 int usbpktlen = sizeof(hfa384x_tx_frame_t);
2710 if (hw->tx_urb.status == -EINPROGRESS) {
2711 netdev_warn(hw->wlandev->netdev, "TX URB already in use\n");
2716 /* Build Tx frame structure */
2717 /* Set up the control field */
2718 memset(&hw->txbuff.txfrm.desc, 0, sizeof(hw->txbuff.txfrm.desc));
2720 /* Setup the usb type field */
2721 hw->txbuff.type = cpu_to_le16(HFA384x_USB_TXFRM);
2723 /* Set up the sw_support field to identify this frame */
2724 hw->txbuff.txfrm.desc.sw_support = 0x0123;
2726 /* Tx complete and Tx exception disable per dleach. Might be causing
2729 /* #define DOEXC SLP -- doboth breaks horribly under load, doexc less so. */
2731 hw->txbuff.txfrm.desc.tx_control =
2732 HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
2733 HFA384x_TX_TXEX_SET(1) | HFA384x_TX_TXOK_SET(1);
2734 #elif defined(DOEXC)
2735 hw->txbuff.txfrm.desc.tx_control =
2736 HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
2737 HFA384x_TX_TXEX_SET(1) | HFA384x_TX_TXOK_SET(0);
2739 hw->txbuff.txfrm.desc.tx_control =
2740 HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
2741 HFA384x_TX_TXEX_SET(0) | HFA384x_TX_TXOK_SET(0);
2743 hw->txbuff.txfrm.desc.tx_control =
2744 cpu_to_le16(hw->txbuff.txfrm.desc.tx_control);
2746 /* copy the header over to the txdesc */
2747 memcpy(&(hw->txbuff.txfrm.desc.frame_control), p80211_hdr,
2748 sizeof(union p80211_hdr));
2750 /* if we're using host WEP, increase size by IV+ICV */
2751 if (p80211_wep->data) {
2752 hw->txbuff.txfrm.desc.data_len = cpu_to_le16(skb->len + 8);
2755 hw->txbuff.txfrm.desc.data_len = cpu_to_le16(skb->len);
2758 usbpktlen += skb->len;
2760 /* copy over the WEP IV if we are using host WEP */
2761 ptr = hw->txbuff.txfrm.data;
2762 if (p80211_wep->data) {
2763 memcpy(ptr, p80211_wep->iv, sizeof(p80211_wep->iv));
2764 ptr += sizeof(p80211_wep->iv);
2765 memcpy(ptr, p80211_wep->data, skb->len);
2767 memcpy(ptr, skb->data, skb->len);
2769 /* copy over the packet data */
2772 /* copy over the WEP ICV if we are using host WEP */
2773 if (p80211_wep->data)
2774 memcpy(ptr, p80211_wep->icv, sizeof(p80211_wep->icv));
2776 /* Send the USB packet */
2777 usb_fill_bulk_urb(&(hw->tx_urb), hw->usb,
2779 &(hw->txbuff), ROUNDUP64(usbpktlen),
2780 hfa384x_usbout_callback, hw->wlandev);
2781 hw->tx_urb.transfer_flags |= USB_QUEUE_BULK;
2784 ret = submit_tx_urb(hw, &hw->tx_urb, GFP_ATOMIC);
2786 netdev_err(hw->wlandev->netdev,
2787 "submit_tx_urb() failed, error=%d\n", ret);
2795 void hfa384x_tx_timeout(wlandevice_t *wlandev)
2797 hfa384x_t *hw = wlandev->priv;
2798 unsigned long flags;
2800 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2802 if (!hw->wlandev->hwremoved) {
2805 sched = !test_and_set_bit(WORK_TX_HALT, &hw->usb_flags);
2806 sched |= !test_and_set_bit(WORK_RX_HALT, &hw->usb_flags);
2808 schedule_work(&hw->usb_work);
2811 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2814 /*----------------------------------------------------------------
2815 * hfa384x_usbctlx_reaper_task
2817 * Tasklet to delete dead CTLX objects
2820 * data ptr to a hfa384x_t
2826 ----------------------------------------------------------------*/
2827 static void hfa384x_usbctlx_reaper_task(unsigned long data)
2829 hfa384x_t *hw = (hfa384x_t *) data;
2830 struct list_head *entry;
2831 struct list_head *temp;
2832 unsigned long flags;
2834 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2836 /* This list is guaranteed to be empty if someone
2837 * has unplugged the adapter.
2839 list_for_each_safe(entry, temp, &hw->ctlxq.reapable) {
2840 hfa384x_usbctlx_t *ctlx;
2842 ctlx = list_entry(entry, hfa384x_usbctlx_t, list);
2843 list_del(&ctlx->list);
2847 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2851 /*----------------------------------------------------------------
2852 * hfa384x_usbctlx_completion_task
2854 * Tasklet to call completion handlers for returned CTLXs
2857 * data ptr to hfa384x_t
2864 ----------------------------------------------------------------*/
2865 static void hfa384x_usbctlx_completion_task(unsigned long data)
2867 hfa384x_t *hw = (hfa384x_t *) data;
2868 struct list_head *entry;
2869 struct list_head *temp;
2870 unsigned long flags;
2874 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2876 /* This list is guaranteed to be empty if someone
2877 * has unplugged the adapter ...
2879 list_for_each_safe(entry, temp, &hw->ctlxq.completing) {
2880 hfa384x_usbctlx_t *ctlx;
2882 ctlx = list_entry(entry, hfa384x_usbctlx_t, list);
2884 /* Call the completion function that this
2885 * command was assigned, assuming it has one.
2887 if (ctlx->cmdcb != NULL) {
2888 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2889 ctlx->cmdcb(hw, ctlx);
2890 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2892 /* Make sure we don't try and complete
2893 * this CTLX more than once!
2897 /* Did someone yank the adapter out
2898 * while our list was (briefly) unlocked?
2900 if (hw->wlandev->hwremoved) {
2907 * "Reapable" CTLXs are ones which don't have any
2908 * threads waiting for them to die. Hence they must
2909 * be delivered to The Reaper!
2911 if (ctlx->reapable) {
2912 /* Move the CTLX off the "completing" list (hopefully)
2913 * on to the "reapable" list where the reaper task
2914 * can find it. And "reapable" means that this CTLX
2915 * isn't sitting on a wait-queue somewhere.
2917 list_move_tail(&ctlx->list, &hw->ctlxq.reapable);
2921 complete(&ctlx->done);
2923 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2926 tasklet_schedule(&hw->reaper_bh);
2929 /*----------------------------------------------------------------
2930 * unlocked_usbctlx_cancel_async
2932 * Mark the CTLX dead asynchronously, and ensure that the
2933 * next command on the queue is run afterwards.
2936 * hw ptr to the hfa384x_t structure
2937 * ctlx ptr to a CTLX structure
2940 * 0 the CTLX's URB is inactive
2941 * -EINPROGRESS the URB is currently being unlinked
2944 * Either process or interrupt, but presumably interrupt
2945 ----------------------------------------------------------------*/
2946 static int unlocked_usbctlx_cancel_async(hfa384x_t *hw,
2947 hfa384x_usbctlx_t *ctlx)
2952 * Try to delete the URB containing our request packet.
2953 * If we succeed, then its completion handler will be
2954 * called with a status of -ECONNRESET.
2956 hw->ctlx_urb.transfer_flags |= URB_ASYNC_UNLINK;
2957 ret = usb_unlink_urb(&hw->ctlx_urb);
2959 if (ret != -EINPROGRESS) {
2961 * The OUT URB had either already completed
2962 * or was still in the pending queue, so the
2963 * URB's completion function will not be called.
2964 * We will have to complete the CTLX ourselves.
2966 ctlx->state = CTLX_REQ_FAILED;
2967 unlocked_usbctlx_complete(hw, ctlx);
2974 /*----------------------------------------------------------------
2975 * unlocked_usbctlx_complete
2977 * A CTLX has completed. It may have been successful, it may not
2978 * have been. At this point, the CTLX should be quiescent. The URBs
2979 * aren't active and the timers should have been stopped.
2981 * The CTLX is migrated to the "completing" queue, and the completing
2982 * tasklet is scheduled.
2985 * hw ptr to a hfa384x_t structure
2986 * ctlx ptr to a ctlx structure
2994 * Either, assume interrupt
2995 ----------------------------------------------------------------*/
2996 static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx)
2998 /* Timers have been stopped, and ctlx should be in
2999 * a terminal state. Retire it from the "active"
3002 list_move_tail(&ctlx->list, &hw->ctlxq.completing);
3003 tasklet_schedule(&hw->completion_bh);
3005 switch (ctlx->state) {
3007 case CTLX_REQ_FAILED:
3008 /* This are the correct terminating states. */
3012 netdev_err(hw->wlandev->netdev, "CTLX[%d] not in a terminating state(%s)\n",
3013 le16_to_cpu(ctlx->outbuf.type),
3014 ctlxstr(ctlx->state));
3019 /*----------------------------------------------------------------
3020 * hfa384x_usbctlxq_run
3022 * Checks to see if the head item is running. If not, starts it.
3025 * hw ptr to hfa384x_t
3034 ----------------------------------------------------------------*/
3035 static void hfa384x_usbctlxq_run(hfa384x_t *hw)
3037 unsigned long flags;
3040 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3042 /* Only one active CTLX at any one time, because there's no
3043 * other (reliable) way to match the response URB to the
3046 * Don't touch any of these CTLXs if the hardware
3047 * has been removed or the USB subsystem is stalled.
3049 if (!list_empty(&hw->ctlxq.active) ||
3050 test_bit(WORK_TX_HALT, &hw->usb_flags) || hw->wlandev->hwremoved)
3053 while (!list_empty(&hw->ctlxq.pending)) {
3054 hfa384x_usbctlx_t *head;
3057 /* This is the first pending command */
3058 head = list_entry(hw->ctlxq.pending.next,
3059 hfa384x_usbctlx_t, list);
3061 /* We need to split this off to avoid a race condition */
3062 list_move_tail(&head->list, &hw->ctlxq.active);
3064 /* Fill the out packet */
3065 usb_fill_bulk_urb(&(hw->ctlx_urb), hw->usb,
3067 &(head->outbuf), ROUNDUP64(head->outbufsize),
3068 hfa384x_ctlxout_callback, hw);
3069 hw->ctlx_urb.transfer_flags |= USB_QUEUE_BULK;
3071 /* Now submit the URB and update the CTLX's state */
3072 result = SUBMIT_URB(&hw->ctlx_urb, GFP_ATOMIC);
3074 /* This CTLX is now running on the active queue */
3075 head->state = CTLX_REQ_SUBMITTED;
3077 /* Start the OUT wait timer */
3078 hw->req_timer_done = 0;
3079 hw->reqtimer.expires = jiffies + HZ;
3080 add_timer(&hw->reqtimer);
3082 /* Start the IN wait timer */
3083 hw->resp_timer_done = 0;
3084 hw->resptimer.expires = jiffies + 2 * HZ;
3085 add_timer(&hw->resptimer);
3090 if (result == -EPIPE) {
3091 /* The OUT pipe needs resetting, so put
3092 * this CTLX back in the "pending" queue
3093 * and schedule a reset ...
3095 netdev_warn(hw->wlandev->netdev,
3096 "%s tx pipe stalled: requesting reset\n",
3097 hw->wlandev->netdev->name);
3098 list_move(&head->list, &hw->ctlxq.pending);
3099 set_bit(WORK_TX_HALT, &hw->usb_flags);
3100 schedule_work(&hw->usb_work);
3104 if (result == -ESHUTDOWN) {
3105 netdev_warn(hw->wlandev->netdev, "%s urb shutdown!\n",
3106 hw->wlandev->netdev->name);
3110 netdev_err(hw->wlandev->netdev, "Failed to submit CTLX[%d]: error=%d\n",
3111 le16_to_cpu(head->outbuf.type), result);
3112 unlocked_usbctlx_complete(hw, head);
3116 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3119 /*----------------------------------------------------------------
3120 * hfa384x_usbin_callback
3122 * Callback for URBs on the BULKIN endpoint.
3125 * urb ptr to the completed urb
3134 ----------------------------------------------------------------*/
3135 static void hfa384x_usbin_callback(struct urb *urb)
3137 wlandevice_t *wlandev = urb->context;
3139 hfa384x_usbin_t *usbin = (hfa384x_usbin_t *) urb->transfer_buffer;
3140 struct sk_buff *skb = NULL;
3151 if (!wlandev || !wlandev->netdev || wlandev->hwremoved)
3158 skb = hw->rx_urb_skb;
3159 BUG_ON(!skb || (skb->data != urb->transfer_buffer));
3161 hw->rx_urb_skb = NULL;
3163 /* Check for error conditions within the URB */
3164 switch (urb->status) {
3168 /* Check for short packet */
3169 if (urb->actual_length == 0) {
3170 ++(wlandev->linux_stats.rx_errors);
3171 ++(wlandev->linux_stats.rx_length_errors);
3177 netdev_warn(hw->wlandev->netdev, "%s rx pipe stalled: requesting reset\n",
3178 wlandev->netdev->name);
3179 if (!test_and_set_bit(WORK_RX_HALT, &hw->usb_flags))
3180 schedule_work(&hw->usb_work);
3181 ++(wlandev->linux_stats.rx_errors);
3188 if (!test_and_set_bit(THROTTLE_RX, &hw->usb_flags) &&
3189 !timer_pending(&hw->throttle)) {
3190 mod_timer(&hw->throttle, jiffies + THROTTLE_JIFFIES);
3192 ++(wlandev->linux_stats.rx_errors);
3197 ++(wlandev->linux_stats.rx_over_errors);
3203 pr_debug("status=%d, device removed.\n", urb->status);
3209 pr_debug("status=%d, urb explicitly unlinked.\n", urb->status);
3214 pr_debug("urb status=%d, transfer flags=0x%x\n",
3215 urb->status, urb->transfer_flags);
3216 ++(wlandev->linux_stats.rx_errors);
3221 urb_status = urb->status;
3223 if (action != ABORT) {
3224 /* Repost the RX URB */
3225 result = submit_rx_urb(hw, GFP_ATOMIC);
3228 netdev_err(hw->wlandev->netdev,
3229 "Fatal, failed to resubmit rx_urb. error=%d\n",
3234 /* Handle any USB-IN packet */
3235 /* Note: the check of the sw_support field, the type field doesn't
3236 * have bit 12 set like the docs suggest.
3238 type = le16_to_cpu(usbin->type);
3239 if (HFA384x_USB_ISRXFRM(type)) {
3240 if (action == HANDLE) {
3241 if (usbin->txfrm.desc.sw_support == 0x0123) {
3242 hfa384x_usbin_txcompl(wlandev, usbin);
3244 skb_put(skb, sizeof(*usbin));
3245 hfa384x_usbin_rx(wlandev, skb);
3251 if (HFA384x_USB_ISTXFRM(type)) {
3252 if (action == HANDLE)
3253 hfa384x_usbin_txcompl(wlandev, usbin);
3257 case HFA384x_USB_INFOFRM:
3258 if (action == ABORT)
3260 if (action == HANDLE)
3261 hfa384x_usbin_info(wlandev, usbin);
3264 case HFA384x_USB_CMDRESP:
3265 case HFA384x_USB_WRIDRESP:
3266 case HFA384x_USB_RRIDRESP:
3267 case HFA384x_USB_WMEMRESP:
3268 case HFA384x_USB_RMEMRESP:
3269 /* ALWAYS, ALWAYS, ALWAYS handle this CTLX!!!! */
3270 hfa384x_usbin_ctlx(hw, usbin, urb_status);
3273 case HFA384x_USB_BUFAVAIL:
3274 pr_debug("Received BUFAVAIL packet, frmlen=%d\n",
3275 usbin->bufavail.frmlen);
3278 case HFA384x_USB_ERROR:
3279 pr_debug("Received USB_ERROR packet, errortype=%d\n",
3280 usbin->usberror.errortype);
3284 pr_debug("Unrecognized USBIN packet, type=%x, status=%d\n",
3285 usbin->type, urb_status);
3295 /*----------------------------------------------------------------
3296 * hfa384x_usbin_ctlx
3298 * We've received a URB containing a Prism2 "response" message.
3299 * This message needs to be matched up with a CTLX on the active
3300 * queue and our state updated accordingly.
3303 * hw ptr to hfa384x_t
3304 * usbin ptr to USB IN packet
3305 * urb_status status of this Bulk-In URB
3314 ----------------------------------------------------------------*/
3315 static void hfa384x_usbin_ctlx(hfa384x_t *hw, hfa384x_usbin_t *usbin,
3318 hfa384x_usbctlx_t *ctlx;
3320 unsigned long flags;
3323 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3325 /* There can be only one CTLX on the active queue
3326 * at any one time, and this is the CTLX that the
3327 * timers are waiting for.
3329 if (list_empty(&hw->ctlxq.active))
3332 /* Remove the "response timeout". It's possible that
3333 * we are already too late, and that the timeout is
3334 * already running. And that's just too bad for us,
3335 * because we could lose our CTLX from the active
3338 if (del_timer(&hw->resptimer) == 0) {
3339 if (hw->resp_timer_done == 0) {
3340 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3344 hw->resp_timer_done = 1;
3347 ctlx = get_active_ctlx(hw);
3349 if (urb_status != 0) {
3351 * Bad CTLX, so get rid of it. But we only
3352 * remove it from the active queue if we're no
3353 * longer expecting the OUT URB to complete.
3355 if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0)
3358 const u16 intype = (usbin->type & ~cpu_to_le16(0x8000));
3361 * Check that our message is what we're expecting ...
3363 if (ctlx->outbuf.type != intype) {
3364 netdev_warn(hw->wlandev->netdev,
3365 "Expected IN[%d], received IN[%d] - ignored.\n",
3366 le16_to_cpu(ctlx->outbuf.type),
3367 le16_to_cpu(intype));
3371 /* This URB has succeeded, so grab the data ... */
3372 memcpy(&ctlx->inbuf, usbin, sizeof(ctlx->inbuf));
3374 switch (ctlx->state) {
3375 case CTLX_REQ_SUBMITTED:
3377 * We have received our response URB before
3378 * our request has been acknowledged. Odd,
3379 * but our OUT URB is still alive...
3381 pr_debug("Causality violation: please reboot Universe\n");
3382 ctlx->state = CTLX_RESP_COMPLETE;
3385 case CTLX_REQ_COMPLETE:
3387 * This is the usual path: our request
3388 * has already been acknowledged, and
3389 * now we have received the reply too.
3391 ctlx->state = CTLX_COMPLETE;
3392 unlocked_usbctlx_complete(hw, ctlx);
3398 * Throw this CTLX away ...
3400 netdev_err(hw->wlandev->netdev,
3401 "Matched IN URB, CTLX[%d] in invalid state(%s). Discarded.\n",
3402 le16_to_cpu(ctlx->outbuf.type),
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);
3417 /*----------------------------------------------------------------
3418 * hfa384x_usbin_txcompl
3420 * At this point we have the results of a previous transmit.
3423 * wlandev wlan device
3424 * usbin ptr to the usb transfer buffer
3433 ----------------------------------------------------------------*/
3434 static void hfa384x_usbin_txcompl(wlandevice_t *wlandev,
3435 hfa384x_usbin_t *usbin)
3439 status = le16_to_cpu(usbin->type); /* yeah I know it says type... */
3441 /* Was there an error? */
3442 if (HFA384x_TXSTATUS_ISERROR(status))
3443 prism2sta_ev_txexc(wlandev, status);
3445 prism2sta_ev_tx(wlandev, status);
3448 /*----------------------------------------------------------------
3451 * At this point we have a successful received a rx frame packet.
3454 * wlandev wlan device
3455 * usbin ptr to the usb transfer buffer
3464 ----------------------------------------------------------------*/
3465 static void hfa384x_usbin_rx(wlandevice_t *wlandev, struct sk_buff *skb)
3467 hfa384x_usbin_t *usbin = (hfa384x_usbin_t *) skb->data;
3468 hfa384x_t *hw = wlandev->priv;
3470 struct p80211_rxmeta *rxmeta;
3474 /* Byte order convert once up front. */
3475 usbin->rxfrm.desc.status = le16_to_cpu(usbin->rxfrm.desc.status);
3476 usbin->rxfrm.desc.time = le32_to_cpu(usbin->rxfrm.desc.time);
3478 /* Now handle frame based on port# */
3479 switch (HFA384x_RXSTATUS_MACPORT_GET(usbin->rxfrm.desc.status)) {
3481 fc = le16_to_cpu(usbin->rxfrm.desc.frame_control);
3483 /* If exclude and we receive an unencrypted, drop it */
3484 if ((wlandev->hostwep & HOSTWEP_EXCLUDEUNENCRYPTED) &&
3485 !WLAN_GET_FC_ISWEP(fc)) {
3489 data_len = le16_to_cpu(usbin->rxfrm.desc.data_len);
3491 /* How much header data do we have? */
3492 hdrlen = p80211_headerlen(fc);
3494 /* Pull off the descriptor */
3495 skb_pull(skb, sizeof(hfa384x_rx_frame_t));
3497 /* Now shunt the header block up against the data block
3498 * with an "overlapping" copy
3500 memmove(skb_push(skb, hdrlen),
3501 &usbin->rxfrm.desc.frame_control, hdrlen);
3503 skb->dev = wlandev->netdev;
3504 skb->dev->last_rx = jiffies;
3506 /* And set the frame length properly */
3507 skb_trim(skb, data_len + hdrlen);
3509 /* The prism2 series does not return the CRC */
3510 memset(skb_put(skb, WLAN_CRC_LEN), 0xff, WLAN_CRC_LEN);
3512 skb_reset_mac_header(skb);
3514 /* Attach the rxmeta, set some stuff */
3515 p80211skb_rxmeta_attach(wlandev, skb);
3516 rxmeta = P80211SKB_RXMETA(skb);
3517 rxmeta->mactime = usbin->rxfrm.desc.time;
3518 rxmeta->rxrate = usbin->rxfrm.desc.rate;
3519 rxmeta->signal = usbin->rxfrm.desc.signal - hw->dbmadjust;
3520 rxmeta->noise = usbin->rxfrm.desc.silence - hw->dbmadjust;
3522 prism2sta_ev_rx(wlandev, skb);
3527 if (!HFA384x_RXSTATUS_ISFCSERR(usbin->rxfrm.desc.status)) {
3528 /* Copy to wlansnif skb */
3529 hfa384x_int_rxmonitor(wlandev, &usbin->rxfrm);
3532 pr_debug("Received monitor frame: FCSerr set\n");
3537 netdev_warn(hw->wlandev->netdev, "Received frame on unsupported port=%d\n",
3538 HFA384x_RXSTATUS_MACPORT_GET(
3539 usbin->rxfrm.desc.status));
3548 /*----------------------------------------------------------------
3549 * hfa384x_int_rxmonitor
3551 * Helper function for int_rx. Handles monitor frames.
3552 * Note that this function allocates space for the FCS and sets it
3553 * to 0xffffffff. The hfa384x doesn't give us the FCS value but the
3554 * higher layers expect it. 0xffffffff is used as a flag to indicate
3558 * wlandev wlan device structure
3559 * rxfrm rx descriptor read from card in int_rx
3565 * Allocates an skb and passes it up via the PF_PACKET interface.
3568 ----------------------------------------------------------------*/
3569 static void hfa384x_int_rxmonitor(wlandevice_t *wlandev,
3570 hfa384x_usb_rxfrm_t *rxfrm)
3572 hfa384x_rx_frame_t *rxdesc = &(rxfrm->desc);
3573 unsigned int hdrlen = 0;
3574 unsigned int datalen = 0;
3575 unsigned int skblen = 0;
3578 struct sk_buff *skb;
3579 hfa384x_t *hw = wlandev->priv;
3581 /* Remember the status, time, and data_len fields are in host order */
3582 /* Figure out how big the frame is */
3583 fc = le16_to_cpu(rxdesc->frame_control);
3584 hdrlen = p80211_headerlen(fc);
3585 datalen = le16_to_cpu(rxdesc->data_len);
3587 /* Allocate an ind message+framesize skb */
3588 skblen = sizeof(struct p80211_caphdr) + hdrlen + datalen + WLAN_CRC_LEN;
3590 /* sanity check the length */
3592 (sizeof(struct p80211_caphdr) +
3593 WLAN_HDR_A4_LEN + WLAN_DATA_MAXLEN + WLAN_CRC_LEN)) {
3594 pr_debug("overlen frm: len=%zd\n",
3595 skblen - sizeof(struct p80211_caphdr));
3598 skb = dev_alloc_skb(skblen);
3600 netdev_err(hw->wlandev->netdev,
3601 "alloc_skb failed trying to allocate %d bytes\n",
3606 /* only prepend the prism header if in the right mode */
3607 if ((wlandev->netdev->type == ARPHRD_IEEE80211_PRISM) &&
3608 (hw->sniffhdr != 0)) {
3609 struct p80211_caphdr *caphdr;
3610 /* The NEW header format! */
3611 datap = skb_put(skb, sizeof(struct p80211_caphdr));
3612 caphdr = (struct p80211_caphdr *) datap;
3614 caphdr->version = htonl(P80211CAPTURE_VERSION);
3615 caphdr->length = htonl(sizeof(struct p80211_caphdr));
3616 caphdr->mactime = __cpu_to_be64(rxdesc->time) * 1000;
3617 caphdr->hosttime = __cpu_to_be64(jiffies);
3618 caphdr->phytype = htonl(4); /* dss_dot11_b */
3619 caphdr->channel = htonl(hw->sniff_channel);
3620 caphdr->datarate = htonl(rxdesc->rate);
3621 caphdr->antenna = htonl(0); /* unknown */
3622 caphdr->priority = htonl(0); /* unknown */
3623 caphdr->ssi_type = htonl(3); /* rssi_raw */
3624 caphdr->ssi_signal = htonl(rxdesc->signal);
3625 caphdr->ssi_noise = htonl(rxdesc->silence);
3626 caphdr->preamble = htonl(0); /* unknown */
3627 caphdr->encoding = htonl(1); /* cck */
3630 /* Copy the 802.11 header to the skb
3631 (ctl frames may be less than a full header) */
3632 datap = skb_put(skb, hdrlen);
3633 memcpy(datap, &(rxdesc->frame_control), hdrlen);
3635 /* If any, copy the data from the card to the skb */
3637 datap = skb_put(skb, datalen);
3638 memcpy(datap, rxfrm->data, datalen);
3640 /* check for unencrypted stuff if WEP bit set. */
3641 if (*(datap - hdrlen + 1) & 0x40) /* wep set */
3642 if ((*(datap) == 0xaa) && (*(datap + 1) == 0xaa))
3643 /* clear wep; it's the 802.2 header! */
3644 *(datap - hdrlen + 1) &= 0xbf;
3647 if (hw->sniff_fcs) {
3649 datap = skb_put(skb, WLAN_CRC_LEN);
3650 memset(datap, 0xff, WLAN_CRC_LEN);
3653 /* pass it back up */
3654 prism2sta_ev_rx(wlandev, skb);
3659 /*----------------------------------------------------------------
3660 * hfa384x_usbin_info
3662 * At this point we have a successful received a Prism2 info frame.
3665 * wlandev wlan device
3666 * usbin ptr to the usb transfer buffer
3675 ----------------------------------------------------------------*/
3676 static void hfa384x_usbin_info(wlandevice_t *wlandev, hfa384x_usbin_t *usbin)
3678 usbin->infofrm.info.framelen =
3679 le16_to_cpu(usbin->infofrm.info.framelen);
3680 prism2sta_ev_info(wlandev, &usbin->infofrm.info);
3683 /*----------------------------------------------------------------
3684 * hfa384x_usbout_callback
3686 * Callback for URBs on the BULKOUT endpoint.
3689 * urb ptr to the completed urb
3698 ----------------------------------------------------------------*/
3699 static void hfa384x_usbout_callback(struct urb *urb)
3701 wlandevice_t *wlandev = urb->context;
3702 hfa384x_usbout_t *usbout = urb->transfer_buffer;
3708 if (wlandev && wlandev->netdev) {
3710 switch (urb->status) {
3712 hfa384x_usbout_tx(wlandev, usbout);
3717 hfa384x_t *hw = wlandev->priv;
3718 netdev_warn(hw->wlandev->netdev,
3719 "%s tx pipe stalled: requesting reset\n",
3720 wlandev->netdev->name);
3721 if (!test_and_set_bit
3722 (WORK_TX_HALT, &hw->usb_flags))
3723 schedule_work(&hw->usb_work);
3724 ++(wlandev->linux_stats.tx_errors);
3732 hfa384x_t *hw = wlandev->priv;
3734 if (!test_and_set_bit
3735 (THROTTLE_TX, &hw->usb_flags)
3736 && !timer_pending(&hw->throttle)) {
3737 mod_timer(&hw->throttle,
3738 jiffies + THROTTLE_JIFFIES);
3740 ++(wlandev->linux_stats.tx_errors);
3741 netif_stop_queue(wlandev->netdev);
3747 /* Ignorable errors */
3751 netdev_info(wlandev->netdev, "unknown urb->status=%d\n",
3753 ++(wlandev->linux_stats.tx_errors);
3759 /*----------------------------------------------------------------
3760 * hfa384x_ctlxout_callback
3762 * Callback for control data on the BULKOUT endpoint.
3765 * urb ptr to the completed urb
3774 ----------------------------------------------------------------*/
3775 static void hfa384x_ctlxout_callback(struct urb *urb)
3777 hfa384x_t *hw = urb->context;
3778 int delete_resptimer = 0;
3781 hfa384x_usbctlx_t *ctlx;
3782 unsigned long flags;
3784 pr_debug("urb->status=%d\n", urb->status);
3788 if ((urb->status == -ESHUTDOWN) ||
3789 (urb->status == -ENODEV) || (hw == NULL))
3793 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3796 * Only one CTLX at a time on the "active" list, and
3797 * none at all if we are unplugged. However, we can
3798 * rely on the disconnect function to clean everything
3799 * up if someone unplugged the adapter.
3801 if (list_empty(&hw->ctlxq.active)) {
3802 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3807 * Having something on the "active" queue means
3808 * that we have timers to worry about ...
3810 if (del_timer(&hw->reqtimer) == 0) {
3811 if (hw->req_timer_done == 0) {
3813 * This timer was actually running while we
3814 * were trying to delete it. Let it terminate
3815 * gracefully instead.
3817 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3821 hw->req_timer_done = 1;
3824 ctlx = get_active_ctlx(hw);
3826 if (urb->status == 0) {
3827 /* Request portion of a CTLX is successful */
3828 switch (ctlx->state) {
3829 case CTLX_REQ_SUBMITTED:
3830 /* This OUT-ACK received before IN */
3831 ctlx->state = CTLX_REQ_COMPLETE;
3834 case CTLX_RESP_COMPLETE:
3835 /* IN already received before this OUT-ACK,
3836 * so this command must now be complete.
3838 ctlx->state = CTLX_COMPLETE;
3839 unlocked_usbctlx_complete(hw, ctlx);
3844 /* This is NOT a valid CTLX "success" state! */
3845 netdev_err(hw->wlandev->netdev,
3846 "Illegal CTLX[%d] success state(%s, %d) in OUT URB\n",
3847 le16_to_cpu(ctlx->outbuf.type),
3848 ctlxstr(ctlx->state), urb->status);
3852 /* If the pipe has stalled then we need to reset it */
3853 if ((urb->status == -EPIPE) &&
3854 !test_and_set_bit(WORK_TX_HALT, &hw->usb_flags)) {
3855 netdev_warn(hw->wlandev->netdev,
3856 "%s tx pipe stalled: requesting reset\n",
3857 hw->wlandev->netdev->name);
3858 schedule_work(&hw->usb_work);
3861 /* If someone cancels the OUT URB then its status
3862 * should be either -ECONNRESET or -ENOENT.
3864 ctlx->state = CTLX_REQ_FAILED;
3865 unlocked_usbctlx_complete(hw, ctlx);
3866 delete_resptimer = 1;
3871 if (delete_resptimer) {
3872 timer_ok = del_timer(&hw->resptimer);
3874 hw->resp_timer_done = 1;
3877 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3879 if (!timer_ok && (hw->resp_timer_done == 0)) {
3880 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3885 hfa384x_usbctlxq_run(hw);
3888 /*----------------------------------------------------------------
3889 * hfa384x_usbctlx_reqtimerfn
3891 * Timer response function for CTLX request timeouts. If this
3892 * function is called, it means that the callback for the OUT
3893 * URB containing a Prism2.x XXX_Request was never called.
3896 * data a ptr to the hfa384x_t
3905 ----------------------------------------------------------------*/
3906 static void hfa384x_usbctlx_reqtimerfn(unsigned long data)
3908 hfa384x_t *hw = (hfa384x_t *) data;
3909 unsigned long flags;
3911 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3913 hw->req_timer_done = 1;
3915 /* Removing the hardware automatically empties
3916 * the active list ...
3918 if (!list_empty(&hw->ctlxq.active)) {
3920 * We must ensure that our URB is removed from
3921 * the system, if it hasn't already expired.
3923 hw->ctlx_urb.transfer_flags |= URB_ASYNC_UNLINK;
3924 if (usb_unlink_urb(&hw->ctlx_urb) == -EINPROGRESS) {
3925 hfa384x_usbctlx_t *ctlx = get_active_ctlx(hw);
3927 ctlx->state = CTLX_REQ_FAILED;
3929 /* This URB was active, but has now been
3930 * cancelled. It will now have a status of
3931 * -ECONNRESET in the callback function.
3933 * We are cancelling this CTLX, so we're
3934 * not going to need to wait for a response.
3935 * The URB's callback function will check
3936 * that this timer is truly dead.
3938 if (del_timer(&hw->resptimer) != 0)
3939 hw->resp_timer_done = 1;
3943 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3946 /*----------------------------------------------------------------
3947 * hfa384x_usbctlx_resptimerfn
3949 * Timer response function for CTLX response timeouts. If this
3950 * function is called, it means that the callback for the IN
3951 * URB containing a Prism2.x XXX_Response was never called.
3954 * data a ptr to the hfa384x_t
3963 ----------------------------------------------------------------*/
3964 static void hfa384x_usbctlx_resptimerfn(unsigned long data)
3966 hfa384x_t *hw = (hfa384x_t *) data;
3967 unsigned long flags;
3969 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3971 hw->resp_timer_done = 1;
3973 /* The active list will be empty if the
3974 * adapter has been unplugged ...
3976 if (!list_empty(&hw->ctlxq.active)) {
3977 hfa384x_usbctlx_t *ctlx = get_active_ctlx(hw);
3979 if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0) {
3980 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3981 hfa384x_usbctlxq_run(hw);
3985 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3988 /*----------------------------------------------------------------
3989 * hfa384x_usb_throttlefn
4002 ----------------------------------------------------------------*/
4003 static void hfa384x_usb_throttlefn(unsigned long data)
4005 hfa384x_t *hw = (hfa384x_t *) data;
4006 unsigned long flags;
4008 spin_lock_irqsave(&hw->ctlxq.lock, flags);
4011 * We need to check BOTH the RX and the TX throttle controls,
4012 * so we use the bitwise OR instead of the logical OR.
4014 pr_debug("flags=0x%lx\n", hw->usb_flags);
4015 if (!hw->wlandev->hwremoved &&
4016 ((test_and_clear_bit(THROTTLE_RX, &hw->usb_flags) &&
4017 !test_and_set_bit(WORK_RX_RESUME, &hw->usb_flags))
4019 (test_and_clear_bit(THROTTLE_TX, &hw->usb_flags) &&
4020 !test_and_set_bit(WORK_TX_RESUME, &hw->usb_flags))
4022 schedule_work(&hw->usb_work);
4025 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
4028 /*----------------------------------------------------------------
4029 * hfa384x_usbctlx_submit
4031 * Called from the doxxx functions to submit a CTLX to the queue
4034 * hw ptr to the hw struct
4035 * ctlx ctlx structure to enqueue
4038 * -ENODEV if the adapter is unplugged
4044 * process or interrupt
4045 ----------------------------------------------------------------*/
4046 static int hfa384x_usbctlx_submit(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx)
4048 unsigned long flags;
4050 spin_lock_irqsave(&hw->ctlxq.lock, flags);
4052 if (hw->wlandev->hwremoved) {
4053 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
4057 ctlx->state = CTLX_PENDING;
4058 list_add_tail(&ctlx->list, &hw->ctlxq.pending);
4059 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
4060 hfa384x_usbctlxq_run(hw);
4065 /*----------------------------------------------------------------
4068 * At this point we have finished a send of a frame. Mark the URB
4069 * as available and call ev_alloc to notify higher layers we're
4073 * wlandev wlan device
4074 * usbout ptr to the usb transfer buffer
4083 ----------------------------------------------------------------*/
4084 static void hfa384x_usbout_tx(wlandevice_t *wlandev, hfa384x_usbout_t *usbout)
4086 prism2sta_ev_alloc(wlandev);
4089 /*----------------------------------------------------------------
4090 * hfa384x_isgood_pdrcore
4092 * Quick check of PDR codes.
4095 * pdrcode PDR code number (host order)
4104 ----------------------------------------------------------------*/
4105 static int hfa384x_isgood_pdrcode(u16 pdrcode)
4108 case HFA384x_PDR_END_OF_PDA:
4109 case HFA384x_PDR_PCB_PARTNUM:
4110 case HFA384x_PDR_PDAVER:
4111 case HFA384x_PDR_NIC_SERIAL:
4112 case HFA384x_PDR_MKK_MEASUREMENTS:
4113 case HFA384x_PDR_NIC_RAMSIZE:
4114 case HFA384x_PDR_MFISUPRANGE:
4115 case HFA384x_PDR_CFISUPRANGE:
4116 case HFA384x_PDR_NICID:
4117 case HFA384x_PDR_MAC_ADDRESS:
4118 case HFA384x_PDR_REGDOMAIN:
4119 case HFA384x_PDR_ALLOWED_CHANNEL:
4120 case HFA384x_PDR_DEFAULT_CHANNEL:
4121 case HFA384x_PDR_TEMPTYPE:
4122 case HFA384x_PDR_IFR_SETTING:
4123 case HFA384x_PDR_RFR_SETTING:
4124 case HFA384x_PDR_HFA3861_BASELINE:
4125 case HFA384x_PDR_HFA3861_SHADOW:
4126 case HFA384x_PDR_HFA3861_IFRF:
4127 case HFA384x_PDR_HFA3861_CHCALSP:
4128 case HFA384x_PDR_HFA3861_CHCALI:
4129 case HFA384x_PDR_3842_NIC_CONFIG:
4130 case HFA384x_PDR_USB_ID:
4131 case HFA384x_PDR_PCI_ID:
4132 case HFA384x_PDR_PCI_IFCONF:
4133 case HFA384x_PDR_PCI_PMCONF:
4134 case HFA384x_PDR_RFENRGY:
4135 case HFA384x_PDR_HFA3861_MANF_TESTSP:
4136 case HFA384x_PDR_HFA3861_MANF_TESTI:
4141 if (pdrcode < 0x1000) {
4142 /* code is OK, but we don't know exactly what it is */
4143 pr_debug("Encountered unknown PDR#=0x%04x, assuming it's ok.\n",
4148 pr_debug("Encountered unknown PDR#=0x%04x, (>=0x1000), assuming it's bad.\n",
4154 return 0; /* avoid compiler warnings */