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 invokations 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 /*================================================================*/
114 /* System Includes */
115 #define WLAN_DBVAR prism2_debug
120 #include <linux/version.h>
122 #include <linux/module.h>
123 #include <linux/kernel.h>
124 #include <linux/sched.h>
125 #include <linux/types.h>
126 #include <linux/slab.h>
127 #include <linux/wireless.h>
128 #include <linux/netdevice.h>
129 #include <linux/timer.h>
131 #include <linux/delay.h>
132 #include <asm/byteorder.h>
133 #include <asm/bitops.h>
134 #include <linux/list.h>
135 #include <linux/usb.h>
137 #include "wlan_compat.h"
139 #define SUBMIT_URB(u,f) usb_submit_urb(u,f)
141 /*================================================================*/
142 /* Project Includes */
144 #include "p80211types.h"
145 #include "p80211hdr.h"
146 #include "p80211mgmt.h"
147 #include "p80211conv.h"
148 #include "p80211msg.h"
149 #include "p80211netdev.h"
150 #include "p80211req.h"
151 #include "p80211metadef.h"
152 #include "p80211metastruct.h"
154 #include "prism2mgmt.h"
156 /*================================================================*/
157 /* Local Constants */
164 typedef enum cmd_mode CMD_MODE;
166 #define THROTTLE_JIFFIES (HZ/8)
168 /*================================================================*/
171 #define ROUNDUP64(a) (((a)+63)&~63)
173 /*================================================================*/
176 /*================================================================*/
177 /* Local Static Definitions */
178 extern int prism2_debug;
180 /*================================================================*/
181 /* Local Function Declarations */
185 dbprint_urb(struct urb* urb);
189 hfa384x_int_rxmonitor(
190 wlandevice_t *wlandev,
191 hfa384x_usb_rxfrm_t *rxfrm);
194 hfa384x_usb_defer(struct work_struct *data);
197 submit_rx_urb(hfa384x_t *hw, gfp_t flags);
200 submit_tx_urb(hfa384x_t *hw, struct urb *tx_urb, gfp_t flags);
202 /*---------------------------------------------------*/
204 #ifdef URB_ONLY_CALLBACK
206 hfa384x_usbout_callback(struct urb *urb);
208 hfa384x_ctlxout_callback(struct urb *urb);
210 hfa384x_usbin_callback(struct urb *urb);
213 hfa384x_usbout_callback(struct urb *urb, struct pt_regs *regs);
215 hfa384x_ctlxout_callback(struct urb *urb, struct pt_regs *regs);
217 hfa384x_usbin_callback(struct urb *urb, struct pt_regs *regs);
221 hfa384x_usbin_txcompl(wlandevice_t *wlandev, hfa384x_usbin_t *usbin);
224 hfa384x_usbin_rx(wlandevice_t *wlandev, struct sk_buff *skb);
227 hfa384x_usbin_info(wlandevice_t *wlandev, hfa384x_usbin_t *usbin);
230 hfa384x_usbout_tx(wlandevice_t *wlandev, hfa384x_usbout_t *usbout);
232 static void hfa384x_usbin_ctlx(hfa384x_t *hw, hfa384x_usbin_t *usbin,
235 /*---------------------------------------------------*/
236 /* Functions to support the prism2 usb command queue */
239 hfa384x_usbctlxq_run(hfa384x_t *hw);
242 hfa384x_usbctlx_reqtimerfn(unsigned long data);
245 hfa384x_usbctlx_resptimerfn(unsigned long data);
248 hfa384x_usb_throttlefn(unsigned long data);
251 hfa384x_usbctlx_completion_task(unsigned long data);
254 hfa384x_usbctlx_reaper_task(unsigned long data);
257 hfa384x_usbctlx_submit(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
260 unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
262 struct usbctlx_completor
264 int (*complete)(struct usbctlx_completor*);
266 typedef struct usbctlx_completor usbctlx_completor_t;
269 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
270 hfa384x_usbctlx_t *ctlx,
271 usbctlx_completor_t *completor);
274 unlocked_usbctlx_cancel_async(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
277 hfa384x_cb_status(hfa384x_t *hw, const hfa384x_usbctlx_t *ctlx);
280 hfa384x_cb_rrid(hfa384x_t *hw, const hfa384x_usbctlx_t *ctlx);
283 usbctlx_get_status(const hfa384x_usb_cmdresp_t *cmdresp,
284 hfa384x_cmdresult_t *result);
287 usbctlx_get_rridresult(const hfa384x_usb_rridresp_t *rridresp,
288 hfa384x_rridresult_t *result);
290 /*---------------------------------------------------*/
291 /* Low level req/resp CTLX formatters and submitters */
296 hfa384x_metacmd_t *cmd,
298 ctlx_usercb_t usercb,
309 ctlx_usercb_t usercb,
320 ctlx_usercb_t usercb,
332 ctlx_usercb_t usercb,
344 ctlx_usercb_t usercb,
348 hfa384x_isgood_pdrcode(UINT16 pdrcode);
350 /*================================================================*/
351 /* Function Definitions */
352 static inline const char* ctlxstr(CTLX_STATE s)
354 static const char* ctlx_str[] = {
359 "Request packet submitted",
360 "Request packet completed",
361 "Response packet completed"
368 static inline hfa384x_usbctlx_t*
369 get_active_ctlx(hfa384x_t *hw)
371 return list_entry(hw->ctlxq.active.next, hfa384x_usbctlx_t, list);
377 dbprint_urb(struct urb* urb)
379 WLAN_LOG_DEBUG(3,"urb->pipe=0x%08x\n", urb->pipe);
380 WLAN_LOG_DEBUG(3,"urb->status=0x%08x\n", urb->status);
381 WLAN_LOG_DEBUG(3,"urb->transfer_flags=0x%08x\n", urb->transfer_flags);
382 WLAN_LOG_DEBUG(3,"urb->transfer_buffer=0x%08x\n", (UINT)urb->transfer_buffer);
383 WLAN_LOG_DEBUG(3,"urb->transfer_buffer_length=0x%08x\n", urb->transfer_buffer_length);
384 WLAN_LOG_DEBUG(3,"urb->actual_length=0x%08x\n", urb->actual_length);
385 WLAN_LOG_DEBUG(3,"urb->bandwidth=0x%08x\n", urb->bandwidth);
386 WLAN_LOG_DEBUG(3,"urb->setup_packet(ctl)=0x%08x\n", (UINT)urb->setup_packet);
387 WLAN_LOG_DEBUG(3,"urb->start_frame(iso/irq)=0x%08x\n", urb->start_frame);
388 WLAN_LOG_DEBUG(3,"urb->interval(irq)=0x%08x\n", urb->interval);
389 WLAN_LOG_DEBUG(3,"urb->error_count(iso)=0x%08x\n", urb->error_count);
390 WLAN_LOG_DEBUG(3,"urb->timeout=0x%08x\n", urb->timeout);
391 WLAN_LOG_DEBUG(3,"urb->context=0x%08x\n", (UINT)urb->context);
392 WLAN_LOG_DEBUG(3,"urb->complete=0x%08x\n", (UINT)urb->complete);
397 /*----------------------------------------------------------------
400 * Listen for input data on the BULK-IN pipe. If the pipe has
401 * stalled then schedule it to be reset.
405 * memflags memory allocation flags
408 * error code from submission
412 ----------------------------------------------------------------*/
414 submit_rx_urb(hfa384x_t *hw, gfp_t memflags)
421 skb = dev_alloc_skb(sizeof(hfa384x_usbin_t));
427 /* Post the IN urb */
428 usb_fill_bulk_urb(&hw->rx_urb, hw->usb,
430 skb->data, sizeof(hfa384x_usbin_t),
431 hfa384x_usbin_callback, hw->wlandev);
433 hw->rx_urb_skb = skb;
436 if ( !hw->wlandev->hwremoved && !test_bit(WORK_RX_HALT, &hw->usb_flags)) {
437 result = SUBMIT_URB(&hw->rx_urb, memflags);
439 /* Check whether we need to reset the RX pipe */
440 if (result == -EPIPE) {
441 WLAN_LOG_WARNING("%s rx pipe stalled: requesting reset\n",
442 hw->wlandev->netdev->name);
443 if ( !test_and_set_bit(WORK_RX_HALT, &hw->usb_flags) )
444 schedule_work(&hw->usb_work);
448 /* Don't leak memory if anything should go wrong */
451 hw->rx_urb_skb = NULL;
460 /*----------------------------------------------------------------
463 * Prepares and submits the URB of transmitted data. If the
464 * submission fails then it will schedule the output pipe to
469 * tx_urb URB of data for tranmission
470 * memflags memory allocation flags
473 * error code from submission
477 ----------------------------------------------------------------*/
479 submit_tx_urb(hfa384x_t *hw, struct urb *tx_urb, gfp_t memflags)
481 struct net_device *netdev = hw->wlandev->netdev;
487 if ( netif_running(netdev) ) {
489 if ( !hw->wlandev->hwremoved && !test_bit(WORK_TX_HALT, &hw->usb_flags) ) {
490 result = SUBMIT_URB(tx_urb, memflags);
492 /* Test whether we need to reset the TX pipe */
493 if (result == -EPIPE) {
494 WLAN_LOG_WARNING("%s tx pipe stalled: requesting reset\n",
496 set_bit(WORK_TX_HALT, &hw->usb_flags);
497 schedule_work(&hw->usb_work);
498 } else if (result == 0) {
499 netif_stop_queue(netdev);
509 /*----------------------------------------------------------------
512 * There are some things that the USB stack cannot do while
513 * in interrupt context, so we arrange this function to run
514 * in process context.
517 * hw device structure
523 * process (by design)
524 ----------------------------------------------------------------*/
526 hfa384x_usb_defer(struct work_struct *data)
528 hfa384x_t *hw = container_of(data, struct hfa384x, usb_work);
529 struct net_device *netdev = hw->wlandev->netdev;
533 /* Don't bother trying to reset anything if the plug
534 * has been pulled ...
536 if ( hw->wlandev->hwremoved ) {
541 /* Reception has stopped: try to reset the input pipe */
542 if (test_bit(WORK_RX_HALT, &hw->usb_flags)) {
545 usb_kill_urb(&hw->rx_urb); /* Cannot be holding spinlock! */
547 ret = usb_clear_halt(hw->usb, hw->endp_in);
550 "Failed to clear rx pipe for %s: err=%d\n",
553 printk(KERN_INFO "%s rx pipe reset complete.\n",
555 clear_bit(WORK_RX_HALT, &hw->usb_flags);
556 set_bit(WORK_RX_RESUME, &hw->usb_flags);
560 /* Resume receiving data back from the device. */
561 if ( test_bit(WORK_RX_RESUME, &hw->usb_flags) ) {
564 ret = submit_rx_urb(hw, GFP_KERNEL);
567 "Failed to resume %s rx pipe.\n", netdev->name);
569 clear_bit(WORK_RX_RESUME, &hw->usb_flags);
573 /* Transmission has stopped: try to reset the output pipe */
574 if (test_bit(WORK_TX_HALT, &hw->usb_flags)) {
577 usb_kill_urb(&hw->tx_urb);
578 ret = usb_clear_halt(hw->usb, hw->endp_out);
581 "Failed to clear tx pipe for %s: err=%d\n",
584 printk(KERN_INFO "%s tx pipe reset complete.\n",
586 clear_bit(WORK_TX_HALT, &hw->usb_flags);
587 set_bit(WORK_TX_RESUME, &hw->usb_flags);
589 /* Stopping the BULK-OUT pipe also blocked
590 * us from sending any more CTLX URBs, so
591 * we need to re-run our queue ...
593 hfa384x_usbctlxq_run(hw);
597 /* Resume transmitting. */
598 if ( test_and_clear_bit(WORK_TX_RESUME, &hw->usb_flags) ) {
599 p80211netdev_wake_queue(hw->wlandev);
606 /*----------------------------------------------------------------
609 * Sets up the hfa384x_t data structure for use. Note this
610 * does _not_ intialize the actual hardware, just the data structures
611 * we use to keep track of its state.
614 * hw device structure
615 * irq device irq number
616 * iobase i/o base address for register access
617 * membase memory base address for register access
626 ----------------------------------------------------------------*/
628 hfa384x_create( hfa384x_t *hw, struct usb_device *usb)
632 memset(hw, 0, sizeof(hfa384x_t));
635 /* set up the endpoints */
636 hw->endp_in = usb_rcvbulkpipe(usb, 1);
637 hw->endp_out = usb_sndbulkpipe(usb, 2);
639 /* Set up the waitq */
640 init_waitqueue_head(&hw->cmdq);
642 /* Initialize the command queue */
643 spin_lock_init(&hw->ctlxq.lock);
644 INIT_LIST_HEAD(&hw->ctlxq.pending);
645 INIT_LIST_HEAD(&hw->ctlxq.active);
646 INIT_LIST_HEAD(&hw->ctlxq.completing);
647 INIT_LIST_HEAD(&hw->ctlxq.reapable);
649 /* Initialize the authentication queue */
650 skb_queue_head_init(&hw->authq);
652 tasklet_init(&hw->reaper_bh,
653 hfa384x_usbctlx_reaper_task,
655 tasklet_init(&hw->completion_bh,
656 hfa384x_usbctlx_completion_task,
658 INIT_WORK2(&hw->link_bh, prism2sta_processing_defer);
659 INIT_WORK2(&hw->usb_work, hfa384x_usb_defer);
661 init_timer(&hw->throttle);
662 hw->throttle.function = hfa384x_usb_throttlefn;
663 hw->throttle.data = (unsigned long)hw;
665 init_timer(&hw->resptimer);
666 hw->resptimer.function = hfa384x_usbctlx_resptimerfn;
667 hw->resptimer.data = (unsigned long)hw;
669 init_timer(&hw->reqtimer);
670 hw->reqtimer.function = hfa384x_usbctlx_reqtimerfn;
671 hw->reqtimer.data = (unsigned long)hw;
673 usb_init_urb(&hw->rx_urb);
674 usb_init_urb(&hw->tx_urb);
675 usb_init_urb(&hw->ctlx_urb);
677 hw->link_status = HFA384x_LINK_NOTCONNECTED;
678 hw->state = HFA384x_STATE_INIT;
680 INIT_WORK2(&hw->commsqual_bh, prism2sta_commsqual_defer);
681 init_timer(&hw->commsqual_timer);
682 hw->commsqual_timer.data = (unsigned long) hw;
683 hw->commsqual_timer.function = prism2sta_commsqual_timer;
689 /*----------------------------------------------------------------
692 * Partner to hfa384x_create(). This function cleans up the hw
693 * structure so that it can be freed by the caller using a simple
694 * kfree. Currently, this function is just a placeholder. If, at some
695 * point in the future, an hw in the 'shutdown' state requires a 'deep'
696 * kfree, this is where it should be done. Note that if this function
697 * is called on a _running_ hw structure, the drvr_stop() function is
701 * hw device structure
704 * nothing, this function is not allowed to fail.
710 ----------------------------------------------------------------*/
712 hfa384x_destroy( hfa384x_t *hw)
718 if ( hw->state == HFA384x_STATE_RUNNING ) {
719 hfa384x_drvr_stop(hw);
721 hw->state = HFA384x_STATE_PREINIT;
723 if (hw->scanresults) {
724 kfree(hw->scanresults);
725 hw->scanresults = NULL;
728 /* Now to clean out the auth queue */
729 while ( (skb = skb_dequeue(&hw->authq)) ) {
737 /*----------------------------------------------------------------
739 static hfa384x_usbctlx_t* usbctlx_alloc(void)
741 hfa384x_usbctlx_t *ctlx;
743 ctlx = kmalloc(sizeof(*ctlx), in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
746 memset(ctlx, 0, sizeof(*ctlx));
747 init_completion(&ctlx->done);
754 /*----------------------------------------------------------------
756 ----------------------------------------------------------------*/
758 usbctlx_get_status(const hfa384x_usb_cmdresp_t *cmdresp,
759 hfa384x_cmdresult_t *result)
763 result->status = hfa384x2host_16(cmdresp->status);
764 result->resp0 = hfa384x2host_16(cmdresp->resp0);
765 result->resp1 = hfa384x2host_16(cmdresp->resp1);
766 result->resp2 = hfa384x2host_16(cmdresp->resp2);
768 WLAN_LOG_DEBUG(4, "cmdresult:status=0x%04x "
769 "resp0=0x%04x resp1=0x%04x resp2=0x%04x\n",
776 return (result->status & HFA384x_STATUS_RESULT);
780 usbctlx_get_rridresult(const hfa384x_usb_rridresp_t *rridresp,
781 hfa384x_rridresult_t *result)
785 result->rid = hfa384x2host_16(rridresp->rid);
786 result->riddata = rridresp->data;
787 result->riddata_len = ((hfa384x2host_16(rridresp->frmlen) - 1) * 2);
793 /*----------------------------------------------------------------
795 * This completor must be passed to hfa384x_usbctlx_complete_sync()
796 * when processing a CTLX that returns a hfa384x_cmdresult_t structure.
797 ----------------------------------------------------------------*/
798 struct usbctlx_cmd_completor
800 usbctlx_completor_t head;
802 const hfa384x_usb_cmdresp_t *cmdresp;
803 hfa384x_cmdresult_t *result;
805 typedef struct usbctlx_cmd_completor usbctlx_cmd_completor_t;
807 static int usbctlx_cmd_completor_fn(usbctlx_completor_t *head)
809 usbctlx_cmd_completor_t *complete = (usbctlx_cmd_completor_t*)head;
810 return usbctlx_get_status(complete->cmdresp, complete->result);
813 static inline usbctlx_completor_t*
814 init_cmd_completor(usbctlx_cmd_completor_t *completor,
815 const hfa384x_usb_cmdresp_t *cmdresp,
816 hfa384x_cmdresult_t *result)
818 completor->head.complete = usbctlx_cmd_completor_fn;
819 completor->cmdresp = cmdresp;
820 completor->result = result;
821 return &(completor->head);
824 /*----------------------------------------------------------------
826 * This completor must be passed to hfa384x_usbctlx_complete_sync()
827 * when processing a CTLX that reads a RID.
828 ----------------------------------------------------------------*/
829 struct usbctlx_rrid_completor
831 usbctlx_completor_t head;
833 const hfa384x_usb_rridresp_t *rridresp;
837 typedef struct usbctlx_rrid_completor usbctlx_rrid_completor_t;
839 static int usbctlx_rrid_completor_fn(usbctlx_completor_t *head)
841 usbctlx_rrid_completor_t *complete = (usbctlx_rrid_completor_t*)head;
842 hfa384x_rridresult_t rridresult;
844 usbctlx_get_rridresult(complete->rridresp, &rridresult);
846 /* Validate the length, note body len calculation in bytes */
847 if ( rridresult.riddata_len != complete->riddatalen ) {
849 "RID len mismatch, rid=0x%04x hlen=%d fwlen=%d\n",
851 complete->riddatalen,
852 rridresult.riddata_len);
856 memcpy(complete->riddata,
858 complete->riddatalen);
862 static inline usbctlx_completor_t*
863 init_rrid_completor(usbctlx_rrid_completor_t *completor,
864 const hfa384x_usb_rridresp_t *rridresp,
868 completor->head.complete = usbctlx_rrid_completor_fn;
869 completor->rridresp = rridresp;
870 completor->riddata = riddata;
871 completor->riddatalen = riddatalen;
872 return &(completor->head);
875 /*----------------------------------------------------------------
877 * Interprets the results of a synchronous RID-write
878 ----------------------------------------------------------------*/
879 typedef usbctlx_cmd_completor_t usbctlx_wrid_completor_t;
880 #define init_wrid_completor init_cmd_completor
882 /*----------------------------------------------------------------
884 * Interprets the results of a synchronous memory-write
885 ----------------------------------------------------------------*/
886 typedef usbctlx_cmd_completor_t usbctlx_wmem_completor_t;
887 #define init_wmem_completor init_cmd_completor
889 /*----------------------------------------------------------------
891 * Interprets the results of a synchronous memory-read
892 ----------------------------------------------------------------*/
893 struct usbctlx_rmem_completor
895 usbctlx_completor_t head;
897 const hfa384x_usb_rmemresp_t *rmemresp;
901 typedef struct usbctlx_rmem_completor usbctlx_rmem_completor_t;
903 static int usbctlx_rmem_completor_fn(usbctlx_completor_t *head)
905 usbctlx_rmem_completor_t *complete = (usbctlx_rmem_completor_t*)head;
907 WLAN_LOG_DEBUG(4,"rmemresp:len=%d\n", complete->rmemresp->frmlen);
908 memcpy(complete->data, complete->rmemresp->data, complete->len);
912 static inline usbctlx_completor_t*
913 init_rmem_completor(usbctlx_rmem_completor_t *completor,
914 hfa384x_usb_rmemresp_t *rmemresp,
918 completor->head.complete = usbctlx_rmem_completor_fn;
919 completor->rmemresp = rmemresp;
920 completor->data = data;
921 completor->len = len;
922 return &(completor->head);
925 /*----------------------------------------------------------------
928 * Ctlx_complete handler for async CMD type control exchanges.
929 * mark the hw struct as such.
931 * Note: If the handling is changed here, it should probably be
932 * changed in docmd as well.
936 * ctlx completed CTLX
945 ----------------------------------------------------------------*/
947 hfa384x_cb_status(hfa384x_t *hw, const hfa384x_usbctlx_t *ctlx)
951 if ( ctlx->usercb != NULL ) {
952 hfa384x_cmdresult_t cmdresult;
954 if (ctlx->state != CTLX_COMPLETE) {
955 memset(&cmdresult, 0, sizeof(cmdresult));
956 cmdresult.status = HFA384x_STATUS_RESULT_SET(HFA384x_CMD_ERR);
958 usbctlx_get_status(&ctlx->inbuf.cmdresp, &cmdresult);
961 ctlx->usercb(hw, &cmdresult, ctlx->usercb_data);
968 /*----------------------------------------------------------------
971 * CTLX completion handler for async RRID type control exchanges.
973 * Note: If the handling is changed here, it should probably be
974 * changed in dorrid as well.
978 * ctlx completed CTLX
987 ----------------------------------------------------------------*/
989 hfa384x_cb_rrid(hfa384x_t *hw, const hfa384x_usbctlx_t *ctlx)
993 if ( ctlx->usercb != NULL ) {
994 hfa384x_rridresult_t rridresult;
996 if (ctlx->state != CTLX_COMPLETE) {
997 memset(&rridresult, 0, sizeof(rridresult));
998 rridresult.rid = hfa384x2host_16(ctlx->outbuf.rridreq.rid);
1000 usbctlx_get_rridresult(&ctlx->inbuf.rridresp, &rridresult);
1003 ctlx->usercb(hw, &rridresult, ctlx->usercb_data);
1010 hfa384x_docmd_wait(hfa384x_t *hw, hfa384x_metacmd_t *cmd)
1012 return hfa384x_docmd(hw, DOWAIT, cmd, NULL, NULL, NULL);
1016 hfa384x_docmd_async(hfa384x_t *hw,
1017 hfa384x_metacmd_t *cmd,
1019 ctlx_usercb_t usercb,
1022 return hfa384x_docmd(hw, DOASYNC, cmd,
1023 cmdcb, usercb, usercb_data);
1027 hfa384x_dorrid_wait(hfa384x_t *hw, UINT16 rid, void *riddata, UINT riddatalen)
1029 return hfa384x_dorrid(hw, DOWAIT,
1030 rid, riddata, riddatalen,
1035 hfa384x_dorrid_async(hfa384x_t *hw,
1036 UINT16 rid, void *riddata, UINT riddatalen,
1038 ctlx_usercb_t usercb,
1041 return hfa384x_dorrid(hw, DOASYNC,
1042 rid, riddata, riddatalen,
1043 cmdcb, usercb, usercb_data);
1047 hfa384x_dowrid_wait(hfa384x_t *hw, UINT16 rid, void *riddata, UINT riddatalen)
1049 return hfa384x_dowrid(hw, DOWAIT,
1050 rid, riddata, riddatalen,
1055 hfa384x_dowrid_async(hfa384x_t *hw,
1056 UINT16 rid, void *riddata, UINT riddatalen,
1058 ctlx_usercb_t usercb,
1061 return hfa384x_dowrid(hw, DOASYNC,
1062 rid, riddata, riddatalen,
1063 cmdcb, usercb, usercb_data);
1067 hfa384x_dormem_wait(hfa384x_t *hw,
1068 UINT16 page, UINT16 offset, void *data, UINT len)
1070 return hfa384x_dormem(hw, DOWAIT,
1071 page, offset, data, len,
1076 hfa384x_dormem_async(hfa384x_t *hw,
1077 UINT16 page, UINT16 offset, void *data, UINT len,
1079 ctlx_usercb_t usercb,
1082 return hfa384x_dormem(hw, DOASYNC,
1083 page, offset, data, len,
1084 cmdcb, usercb, usercb_data);
1088 hfa384x_dowmem_wait(
1095 return hfa384x_dowmem(hw, DOWAIT,
1096 page, offset, data, len,
1101 hfa384x_dowmem_async(
1108 ctlx_usercb_t usercb,
1111 return hfa384x_dowmem(hw, DOASYNC,
1112 page, offset, data, len,
1113 cmdcb, usercb, usercb_data);
1116 /*----------------------------------------------------------------
1117 * hfa384x_cmd_initialize
1119 * Issues the initialize command and sets the hw->state based
1123 * hw device structure
1127 * >0 f/w reported error - f/w status code
1128 * <0 driver reported error
1134 ----------------------------------------------------------------*/
1136 hfa384x_cmd_initialize(hfa384x_t *hw)
1140 hfa384x_metacmd_t cmd;
1145 cmd.cmd = HFA384x_CMDCODE_INIT;
1150 result = hfa384x_docmd_wait(hw, &cmd);
1153 WLAN_LOG_DEBUG(3,"cmdresp.init: "
1154 "status=0x%04x, resp0=0x%04x, "
1155 "resp1=0x%04x, resp2=0x%04x\n",
1160 if ( result == 0 ) {
1161 for ( i = 0; i < HFA384x_NUMPORTS_MAX; i++) {
1162 hw->port_enabled[i] = 0;
1166 hw->link_status = HFA384x_LINK_NOTCONNECTED;
1173 /*----------------------------------------------------------------
1174 * hfa384x_cmd_disable
1176 * Issues the disable command to stop communications on one of
1180 * hw device structure
1181 * macport MAC port number (host order)
1185 * >0 f/w reported failure - f/w status code
1186 * <0 driver reported error (timeout|bad arg)
1192 ----------------------------------------------------------------*/
1193 int hfa384x_cmd_disable(hfa384x_t *hw, UINT16 macport)
1196 hfa384x_metacmd_t cmd;
1200 cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_DISABLE) |
1201 HFA384x_CMD_MACPORT_SET(macport);
1206 result = hfa384x_docmd_wait(hw, &cmd);
1213 /*----------------------------------------------------------------
1214 * hfa384x_cmd_enable
1216 * Issues the enable command to enable communications on one of
1220 * hw device structure
1221 * macport MAC port number
1225 * >0 f/w reported failure - f/w status code
1226 * <0 driver reported error (timeout|bad arg)
1232 ----------------------------------------------------------------*/
1233 int hfa384x_cmd_enable(hfa384x_t *hw, UINT16 macport)
1236 hfa384x_metacmd_t cmd;
1240 cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_ENABLE) |
1241 HFA384x_CMD_MACPORT_SET(macport);
1246 result = hfa384x_docmd_wait(hw, &cmd);
1253 /*----------------------------------------------------------------
1254 * hfa384x_cmd_notify
1256 * Sends an info frame to the firmware to alter the behavior
1257 * of the f/w asynch processes. Can only be called when the MAC
1258 * is in the enabled state.
1261 * hw device structure
1262 * reclaim [0|1] indicates whether the given FID will
1263 * be handed back (via Alloc event) for reuse.
1265 * fid FID of buffer containing the frame that was
1266 * previously copied to MAC memory via the bap.
1271 * >0 f/w reported failure - f/w status code
1272 * <0 driver reported error (timeout|bad arg)
1275 * hw->resp0 will contain the FID being used by async notify
1276 * process. If reclaim==0, resp0 will be the same as the fid
1277 * argument. If reclaim==1, resp0 will be the different.
1281 ----------------------------------------------------------------*/
1282 int hfa384x_cmd_notify(hfa384x_t *hw, UINT16 reclaim, UINT16 fid,
1283 void *buf, UINT16 len)
1289 cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_NOTIFY) |
1290 HFA384x_CMD_RECL_SET(reclaim);
1291 result = hfa384x_docmd_wait(hw, cmd);
1301 /*----------------------------------------------------------------
1302 * hfa384x_cmd_inquiry
1304 * Requests an info frame from the firmware. The info frame will
1305 * be delivered asynchronously via the Info event.
1308 * hw device structure
1309 * fid FID of the info frame requested. (host order)
1313 * >0 f/w reported failure - f/w status code
1314 * <0 driver reported error (timeout|bad arg)
1320 ----------------------------------------------------------------*/
1321 int hfa384x_cmd_inquiry(hfa384x_t *hw, UINT16 fid)
1324 hfa384x_metacmd_t cmd;
1328 cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_INQ);
1333 result = hfa384x_docmd_wait(hw, &cmd);
1341 /*----------------------------------------------------------------
1342 * hfa384x_cmd_monitor
1344 * Enables the 'monitor mode' of the MAC. Here's the description of
1345 * monitor mode that I've received thus far:
1347 * "The "monitor mode" of operation is that the MAC passes all
1348 * frames for which the PLCP checks are correct. All received
1349 * MPDUs are passed to the host with MAC Port = 7, with a
1350 * receive status of good, FCS error, or undecryptable. Passing
1351 * certain MPDUs is a violation of the 802.11 standard, but useful
1352 * for a debugging tool." Normal communication is not possible
1353 * while monitor mode is enabled.
1356 * hw device structure
1357 * enable a code (0x0b|0x0f) that enables/disables
1358 * monitor mode. (host order)
1362 * >0 f/w reported failure - f/w status code
1363 * <0 driver reported error (timeout|bad arg)
1369 ----------------------------------------------------------------*/
1370 int hfa384x_cmd_monitor(hfa384x_t *hw, UINT16 enable)
1373 hfa384x_metacmd_t cmd;
1377 cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_MONITOR) |
1378 HFA384x_CMD_AINFO_SET(enable);
1383 result = hfa384x_docmd_wait(hw, &cmd);
1390 /*----------------------------------------------------------------
1391 * hfa384x_cmd_download
1393 * Sets the controls for the MAC controller code/data download
1394 * process. The arguments set the mode and address associated
1395 * with a download. Note that the aux registers should be enabled
1396 * prior to setting one of the download enable modes.
1399 * hw device structure
1400 * mode 0 - Disable programming and begin code exec
1401 * 1 - Enable volatile mem programming
1402 * 2 - Enable non-volatile mem programming
1403 * 3 - Program non-volatile section from NV download
1407 * highaddr For mode 1, sets the high & low order bits of
1408 * the "destination address". This address will be
1409 * the execution start address when download is
1410 * subsequently disabled.
1411 * For mode 2, sets the high & low order bits of
1412 * the destination in NV ram.
1413 * For modes 0 & 3, should be zero. (host order)
1414 * NOTE: these are CMD format.
1415 * codelen Length of the data to write in mode 2,
1416 * zero otherwise. (host order)
1420 * >0 f/w reported failure - f/w status code
1421 * <0 driver reported error (timeout|bad arg)
1427 ----------------------------------------------------------------*/
1428 int hfa384x_cmd_download(hfa384x_t *hw, UINT16 mode, UINT16 lowaddr,
1429 UINT16 highaddr, UINT16 codelen)
1432 hfa384x_metacmd_t cmd;
1436 "mode=%d, lowaddr=0x%04x, highaddr=0x%04x, codelen=%d\n",
1437 mode, lowaddr, highaddr, codelen);
1439 cmd.cmd = (HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_DOWNLD) |
1440 HFA384x_CMD_PROGMODE_SET(mode));
1442 cmd.parm0 = lowaddr;
1443 cmd.parm1 = highaddr;
1444 cmd.parm2 = codelen;
1446 result = hfa384x_docmd_wait(hw, &cmd);
1453 /*----------------------------------------------------------------
1454 * hfa384x_copy_from_aux
1456 * Copies a collection of bytes from the controller memory. The
1457 * Auxiliary port MUST be enabled prior to calling this function.
1458 * We _might_ be in a download state.
1461 * hw device structure
1462 * cardaddr address in hfa384x data space to read
1463 * auxctl address space select
1464 * buf ptr to destination host buffer
1465 * len length of data to transfer (in bytes)
1471 * buf contains the data copied
1476 ----------------------------------------------------------------*/
1478 hfa384x_copy_from_aux(
1479 hfa384x_t *hw, UINT32 cardaddr, UINT32 auxctl, void *buf, UINT len)
1482 WLAN_LOG_ERROR("not used in USB.\n");
1487 /*----------------------------------------------------------------
1488 * hfa384x_copy_to_aux
1490 * Copies a collection of bytes to the controller memory. The
1491 * Auxiliary port MUST be enabled prior to calling this function.
1492 * We _might_ be in a download state.
1495 * hw device structure
1496 * cardaddr address in hfa384x data space to read
1497 * auxctl address space select
1498 * buf ptr to destination host buffer
1499 * len length of data to transfer (in bytes)
1505 * Controller memory now contains a copy of buf
1510 ----------------------------------------------------------------*/
1512 hfa384x_copy_to_aux(
1513 hfa384x_t *hw, UINT32 cardaddr, UINT32 auxctl, void *buf, UINT len)
1516 WLAN_LOG_ERROR("not used in USB.\n");
1521 /*----------------------------------------------------------------
1524 * Perform a reset of the hfa38xx MAC core. We assume that the hw
1525 * structure is in its "created" state. That is, it is initialized
1526 * with proper values. Note that if a reset is done after the
1527 * device has been active for awhile, the caller might have to clean
1528 * up some leftover cruft in the hw structure.
1531 * hw device structure
1532 * holdtime how long (in ms) to hold the reset
1533 * settletime how long (in ms) to wait after releasing
1543 ----------------------------------------------------------------*/
1544 int hfa384x_corereset(hfa384x_t *hw, int holdtime, int settletime, int genesis)
1550 result=usb_reset_device(hw->usb);
1552 WLAN_LOG_ERROR("usb_reset_device() failed, result=%d.\n",result);
1560 /*----------------------------------------------------------------
1561 * hfa384x_usbctlx_complete_sync
1563 * Waits for a synchronous CTLX object to complete,
1564 * and then handles the response.
1567 * hw device structure
1569 * completor functor object to decide what to
1570 * do with the CTLX's result.
1574 * -ERESTARTSYS Interrupted by a signal
1576 * -ENODEV Adapter was unplugged
1577 * ??? Result from completor
1583 ----------------------------------------------------------------*/
1584 static int hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
1585 hfa384x_usbctlx_t *ctlx,
1586 usbctlx_completor_t *completor)
1588 unsigned long flags;
1593 result = wait_for_completion_interruptible(&ctlx->done);
1595 spin_lock_irqsave(&hw->ctlxq.lock, flags);
1598 * We can only handle the CTLX if the USB disconnect
1599 * function has not run yet ...
1602 if ( hw->wlandev->hwremoved )
1604 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1607 else if ( result != 0 )
1612 * We were probably interrupted, so delete
1613 * this CTLX asynchronously, kill the timers
1614 * and the URB, and then start the next
1617 * NOTE: We can only delete the timers and
1618 * the URB if this CTLX is active.
1620 if (ctlx == get_active_ctlx(hw))
1622 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1624 del_singleshot_timer_sync(&hw->reqtimer);
1625 del_singleshot_timer_sync(&hw->resptimer);
1626 hw->req_timer_done = 1;
1627 hw->resp_timer_done = 1;
1628 usb_kill_urb(&hw->ctlx_urb);
1630 spin_lock_irqsave(&hw->ctlxq.lock, flags);
1635 * This scenario is so unlikely that I'm
1636 * happy with a grubby "goto" solution ...
1638 if ( hw->wlandev->hwremoved )
1643 * The completion task will send this CTLX
1644 * to the reaper the next time it runs. We
1645 * are no longer in a hurry.
1648 ctlx->state = CTLX_REQ_FAILED;
1649 list_move_tail(&ctlx->list, &hw->ctlxq.completing);
1651 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1654 hfa384x_usbctlxq_run(hw);
1656 if (ctlx->state == CTLX_COMPLETE) {
1657 result = completor->complete(completor);
1659 WLAN_LOG_WARNING("CTLX[%d] error: state(%s)\n",
1660 hfa384x2host_16(ctlx->outbuf.type),
1661 ctlxstr(ctlx->state));
1665 list_del(&ctlx->list);
1666 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1674 /*----------------------------------------------------------------
1677 * Constructs a command CTLX and submits it.
1679 * NOTE: Any changes to the 'post-submit' code in this function
1680 * need to be carried over to hfa384x_cbcmd() since the handling
1681 * is virtually identical.
1684 * hw device structure
1685 * mode DOWAIT or DOASYNC
1686 * cmd cmd structure. Includes all arguments and result
1687 * data points. All in host order. in host order
1688 * cmdcb command-specific callback
1689 * usercb user callback for async calls, NULL for DOWAIT calls
1690 * usercb_data user supplied data pointer for async calls, NULL
1696 * -ERESTARTSYS Awakened on signal
1697 * >0 command indicated error, Status and Resp0-2 are
1705 ----------------------------------------------------------------*/
1710 hfa384x_metacmd_t *cmd,
1712 ctlx_usercb_t usercb,
1716 hfa384x_usbctlx_t *ctlx;
1719 ctlx = usbctlx_alloc();
1720 if ( ctlx == NULL ) {
1725 /* Initialize the command */
1726 ctlx->outbuf.cmdreq.type = host2hfa384x_16(HFA384x_USB_CMDREQ);
1727 ctlx->outbuf.cmdreq.cmd = host2hfa384x_16(cmd->cmd);
1728 ctlx->outbuf.cmdreq.parm0 = host2hfa384x_16(cmd->parm0);
1729 ctlx->outbuf.cmdreq.parm1 = host2hfa384x_16(cmd->parm1);
1730 ctlx->outbuf.cmdreq.parm2 = host2hfa384x_16(cmd->parm2);
1732 ctlx->outbufsize = sizeof(ctlx->outbuf.cmdreq);
1734 WLAN_LOG_DEBUG(4, "cmdreq: cmd=0x%04x "
1735 "parm0=0x%04x parm1=0x%04x parm2=0x%04x\n",
1741 ctlx->reapable = mode;
1742 ctlx->cmdcb = cmdcb;
1743 ctlx->usercb = usercb;
1744 ctlx->usercb_data = usercb_data;
1746 result = hfa384x_usbctlx_submit(hw, ctlx);
1749 } else if (mode == DOWAIT) {
1750 usbctlx_cmd_completor_t completor;
1752 result = hfa384x_usbctlx_complete_sync(
1753 hw, ctlx, init_cmd_completor(&completor,
1754 &ctlx->inbuf.cmdresp,
1764 /*----------------------------------------------------------------
1767 * Constructs a read rid CTLX and issues it.
1769 * NOTE: Any changes to the 'post-submit' code in this function
1770 * need to be carried over to hfa384x_cbrrid() since the handling
1771 * is virtually identical.
1774 * hw device structure
1775 * mode DOWAIT or DOASYNC
1776 * rid Read RID number (host order)
1777 * riddata Caller supplied buffer that MAC formatted RID.data
1778 * record will be written to for DOWAIT calls. Should
1779 * be NULL for DOASYNC calls.
1780 * riddatalen Buffer length for DOWAIT calls. Zero for DOASYNC calls.
1781 * cmdcb command callback for async calls, NULL for DOWAIT calls
1782 * usercb user callback for async calls, NULL for DOWAIT calls
1783 * usercb_data user supplied data pointer for async calls, NULL
1789 * -ERESTARTSYS Awakened on signal
1790 * -ENODATA riddatalen != macdatalen
1791 * >0 command indicated error, Status and Resp0-2 are
1797 * interrupt (DOASYNC)
1798 * process (DOWAIT or DOASYNC)
1799 ----------------------------------------------------------------*/
1808 ctlx_usercb_t usercb,
1812 hfa384x_usbctlx_t *ctlx;
1815 ctlx = usbctlx_alloc();
1816 if ( ctlx == NULL ) {
1821 /* Initialize the command */
1822 ctlx->outbuf.rridreq.type = host2hfa384x_16(HFA384x_USB_RRIDREQ);
1823 ctlx->outbuf.rridreq.frmlen =
1824 host2hfa384x_16(sizeof(ctlx->outbuf.rridreq.rid));
1825 ctlx->outbuf.rridreq.rid = host2hfa384x_16(rid);
1827 ctlx->outbufsize = sizeof(ctlx->outbuf.rridreq);
1829 ctlx->reapable = mode;
1830 ctlx->cmdcb = cmdcb;
1831 ctlx->usercb = usercb;
1832 ctlx->usercb_data = usercb_data;
1834 /* Submit the CTLX */
1835 result = hfa384x_usbctlx_submit(hw, ctlx);
1838 } else if (mode == DOWAIT) {
1839 usbctlx_rrid_completor_t completor;
1841 result = hfa384x_usbctlx_complete_sync(
1842 hw, ctlx, init_rrid_completor(&completor,
1843 &ctlx->inbuf.rridresp,
1854 /*----------------------------------------------------------------
1857 * Constructs a write rid CTLX and issues it.
1859 * NOTE: Any changes to the 'post-submit' code in this function
1860 * need to be carried over to hfa384x_cbwrid() since the handling
1861 * is virtually identical.
1864 * hw device structure
1865 * CMD_MODE DOWAIT or DOASYNC
1867 * riddata Data portion of RID formatted for MAC
1868 * riddatalen Length of the data portion in bytes
1869 * cmdcb command callback for async calls, NULL for DOWAIT calls
1870 * usercb user callback for async calls, NULL for DOWAIT calls
1871 * usercb_data user supplied data pointer for async calls
1875 * -ETIMEDOUT timed out waiting for register ready or
1876 * command completion
1877 * >0 command indicated error, Status and Resp0-2 are
1883 * interrupt (DOASYNC)
1884 * process (DOWAIT or DOASYNC)
1885 ----------------------------------------------------------------*/
1894 ctlx_usercb_t usercb,
1898 hfa384x_usbctlx_t *ctlx;
1901 ctlx = usbctlx_alloc();
1902 if ( ctlx == NULL ) {
1907 /* Initialize the command */
1908 ctlx->outbuf.wridreq.type = host2hfa384x_16(HFA384x_USB_WRIDREQ);
1909 ctlx->outbuf.wridreq.frmlen = host2hfa384x_16(
1910 (sizeof(ctlx->outbuf.wridreq.rid) +
1911 riddatalen + 1) / 2);
1912 ctlx->outbuf.wridreq.rid = host2hfa384x_16(rid);
1913 memcpy(ctlx->outbuf.wridreq.data, riddata, riddatalen);
1915 ctlx->outbufsize = sizeof(ctlx->outbuf.wridreq.type) +
1916 sizeof(ctlx->outbuf.wridreq.frmlen) +
1917 sizeof(ctlx->outbuf.wridreq.rid) +
1920 ctlx->reapable = mode;
1921 ctlx->cmdcb = cmdcb;
1922 ctlx->usercb = usercb;
1923 ctlx->usercb_data = usercb_data;
1925 /* Submit the CTLX */
1926 result = hfa384x_usbctlx_submit(hw, ctlx);
1929 } else if (mode == DOWAIT) {
1930 usbctlx_wrid_completor_t completor;
1931 hfa384x_cmdresult_t wridresult;
1933 result = hfa384x_usbctlx_complete_sync(
1936 init_wrid_completor(&completor,
1937 &ctlx->inbuf.wridresp,
1946 /*----------------------------------------------------------------
1949 * Constructs a readmem CTLX and issues it.
1951 * NOTE: Any changes to the 'post-submit' code in this function
1952 * need to be carried over to hfa384x_cbrmem() since the handling
1953 * is virtually identical.
1956 * hw device structure
1957 * mode DOWAIT or DOASYNC
1958 * page MAC address space page (CMD format)
1959 * offset MAC address space offset
1960 * data Ptr to data buffer to receive read
1961 * len Length of the data to read (max == 2048)
1962 * cmdcb command callback for async calls, NULL for DOWAIT calls
1963 * usercb user callback for async calls, NULL for DOWAIT calls
1964 * usercb_data user supplied data pointer for async calls
1968 * -ETIMEDOUT timed out waiting for register ready or
1969 * command completion
1970 * >0 command indicated error, Status and Resp0-2 are
1976 * interrupt (DOASYNC)
1977 * process (DOWAIT or DOASYNC)
1978 ----------------------------------------------------------------*/
1988 ctlx_usercb_t usercb,
1992 hfa384x_usbctlx_t *ctlx;
1995 ctlx = usbctlx_alloc();
1996 if ( ctlx == NULL ) {
2001 /* Initialize the command */
2002 ctlx->outbuf.rmemreq.type = host2hfa384x_16(HFA384x_USB_RMEMREQ);
2003 ctlx->outbuf.rmemreq.frmlen = host2hfa384x_16(
2004 sizeof(ctlx->outbuf.rmemreq.offset) +
2005 sizeof(ctlx->outbuf.rmemreq.page) +
2007 ctlx->outbuf.rmemreq.offset = host2hfa384x_16(offset);
2008 ctlx->outbuf.rmemreq.page = host2hfa384x_16(page);
2010 ctlx->outbufsize = sizeof(ctlx->outbuf.rmemreq);
2013 "type=0x%04x frmlen=%d offset=0x%04x page=0x%04x\n",
2014 ctlx->outbuf.rmemreq.type,
2015 ctlx->outbuf.rmemreq.frmlen,
2016 ctlx->outbuf.rmemreq.offset,
2017 ctlx->outbuf.rmemreq.page);
2019 WLAN_LOG_DEBUG(4,"pktsize=%zd\n",
2020 ROUNDUP64(sizeof(ctlx->outbuf.rmemreq)));
2022 ctlx->reapable = mode;
2023 ctlx->cmdcb = cmdcb;
2024 ctlx->usercb = usercb;
2025 ctlx->usercb_data = usercb_data;
2027 result = hfa384x_usbctlx_submit(hw, ctlx);
2030 } else if ( mode == DOWAIT ) {
2031 usbctlx_rmem_completor_t completor;
2033 result = hfa384x_usbctlx_complete_sync(
2034 hw, ctlx, init_rmem_completor(&completor,
2035 &ctlx->inbuf.rmemresp,
2047 /*----------------------------------------------------------------
2050 * Constructs a writemem CTLX and issues it.
2052 * NOTE: Any changes to the 'post-submit' code in this function
2053 * need to be carried over to hfa384x_cbwmem() since the handling
2054 * is virtually identical.
2057 * hw device structure
2058 * mode DOWAIT or DOASYNC
2059 * page MAC address space page (CMD format)
2060 * offset MAC address space offset
2061 * data Ptr to data buffer containing write data
2062 * len Length of the data to read (max == 2048)
2063 * cmdcb command callback for async calls, NULL for DOWAIT calls
2064 * usercb user callback for async calls, NULL for DOWAIT calls
2065 * usercb_data user supplied data pointer for async calls.
2069 * -ETIMEDOUT timed out waiting for register ready or
2070 * command completion
2071 * >0 command indicated error, Status and Resp0-2 are
2077 * interrupt (DOWAIT)
2078 * process (DOWAIT or DOASYNC)
2079 ----------------------------------------------------------------*/
2089 ctlx_usercb_t usercb,
2093 hfa384x_usbctlx_t *ctlx;
2096 WLAN_LOG_DEBUG(5, "page=0x%04x offset=0x%04x len=%d\n",
2099 ctlx = usbctlx_alloc();
2100 if ( ctlx == NULL ) {
2105 /* Initialize the command */
2106 ctlx->outbuf.wmemreq.type = host2hfa384x_16(HFA384x_USB_WMEMREQ);
2107 ctlx->outbuf.wmemreq.frmlen = host2hfa384x_16(
2108 sizeof(ctlx->outbuf.wmemreq.offset) +
2109 sizeof(ctlx->outbuf.wmemreq.page) +
2111 ctlx->outbuf.wmemreq.offset = host2hfa384x_16(offset);
2112 ctlx->outbuf.wmemreq.page = host2hfa384x_16(page);
2113 memcpy(ctlx->outbuf.wmemreq.data, data, len);
2115 ctlx->outbufsize = sizeof(ctlx->outbuf.wmemreq.type) +
2116 sizeof(ctlx->outbuf.wmemreq.frmlen) +
2117 sizeof(ctlx->outbuf.wmemreq.offset) +
2118 sizeof(ctlx->outbuf.wmemreq.page) +
2121 ctlx->reapable = mode;
2122 ctlx->cmdcb = cmdcb;
2123 ctlx->usercb = usercb;
2124 ctlx->usercb_data = usercb_data;
2126 result = hfa384x_usbctlx_submit(hw, ctlx);
2129 } else if ( mode == DOWAIT ) {
2130 usbctlx_wmem_completor_t completor;
2131 hfa384x_cmdresult_t wmemresult;
2133 result = hfa384x_usbctlx_complete_sync(
2136 init_wmem_completor(&completor,
2137 &ctlx->inbuf.wmemresp,
2147 /*----------------------------------------------------------------
2148 * hfa384x_drvr_commtallies
2150 * Send a commtallies inquiry to the MAC. Note that this is an async
2151 * call that will result in an info frame arriving sometime later.
2154 * hw device structure
2163 ----------------------------------------------------------------*/
2164 int hfa384x_drvr_commtallies( hfa384x_t *hw )
2166 hfa384x_metacmd_t cmd;
2170 cmd.cmd = HFA384x_CMDCODE_INQ;
2171 cmd.parm0 = HFA384x_IT_COMMTALLIES;
2175 hfa384x_docmd_async(hw, &cmd, NULL, NULL, NULL);
2182 /*----------------------------------------------------------------
2183 * hfa384x_drvr_disable
2185 * Issues the disable command to stop communications on one of
2186 * the MACs 'ports'. Only macport 0 is valid for stations.
2187 * APs may also disable macports 1-6. Only ports that have been
2188 * previously enabled may be disabled.
2191 * hw device structure
2192 * macport MAC port number (host order)
2196 * >0 f/w reported failure - f/w status code
2197 * <0 driver reported error (timeout|bad arg)
2203 ----------------------------------------------------------------*/
2204 int hfa384x_drvr_disable(hfa384x_t *hw, UINT16 macport)
2209 if ((!hw->isap && macport != 0) ||
2210 (hw->isap && !(macport <= HFA384x_PORTID_MAX)) ||
2211 !(hw->port_enabled[macport]) ){
2214 result = hfa384x_cmd_disable(hw, macport);
2215 if ( result == 0 ) {
2216 hw->port_enabled[macport] = 0;
2224 /*----------------------------------------------------------------
2225 * hfa384x_drvr_enable
2227 * Issues the enable command to enable communications on one of
2228 * the MACs 'ports'. Only macport 0 is valid for stations.
2229 * APs may also enable macports 1-6. Only ports that are currently
2230 * disabled may be enabled.
2233 * hw device structure
2234 * macport MAC port number
2238 * >0 f/w reported failure - f/w status code
2239 * <0 driver reported error (timeout|bad arg)
2245 ----------------------------------------------------------------*/
2246 int hfa384x_drvr_enable(hfa384x_t *hw, UINT16 macport)
2251 if ((!hw->isap && macport != 0) ||
2252 (hw->isap && !(macport <= HFA384x_PORTID_MAX)) ||
2253 (hw->port_enabled[macport]) ){
2256 result = hfa384x_cmd_enable(hw, macport);
2257 if ( result == 0 ) {
2258 hw->port_enabled[macport] = 1;
2266 /*----------------------------------------------------------------
2267 * hfa384x_drvr_flashdl_enable
2269 * Begins the flash download state. Checks to see that we're not
2270 * already in a download state and that a port isn't enabled.
2271 * Sets the download state and retrieves the flash download
2272 * buffer location, buffer size, and timeout length.
2275 * hw device structure
2279 * >0 f/w reported error - f/w status code
2280 * <0 driver reported error
2286 ----------------------------------------------------------------*/
2287 int hfa384x_drvr_flashdl_enable(hfa384x_t *hw)
2293 /* Check that a port isn't active */
2294 for ( i = 0; i < HFA384x_PORTID_MAX; i++) {
2295 if ( hw->port_enabled[i] ) {
2296 WLAN_LOG_DEBUG(1,"called when port enabled.\n");
2301 /* Check that we're not already in a download state */
2302 if ( hw->dlstate != HFA384x_DLSTATE_DISABLED ) {
2306 /* Retrieve the buffer loc&size and timeout */
2307 if ( (result = hfa384x_drvr_getconfig(hw, HFA384x_RID_DOWNLOADBUFFER,
2308 &(hw->bufinfo), sizeof(hw->bufinfo))) ) {
2311 hw->bufinfo.page = hfa384x2host_16(hw->bufinfo.page);
2312 hw->bufinfo.offset = hfa384x2host_16(hw->bufinfo.offset);
2313 hw->bufinfo.len = hfa384x2host_16(hw->bufinfo.len);
2314 if ( (result = hfa384x_drvr_getconfig16(hw, HFA384x_RID_MAXLOADTIME,
2315 &(hw->dltimeout))) ) {
2318 hw->dltimeout = hfa384x2host_16(hw->dltimeout);
2320 WLAN_LOG_DEBUG(1,"flashdl_enable\n");
2322 hw->dlstate = HFA384x_DLSTATE_FLASHENABLED;
2328 /*----------------------------------------------------------------
2329 * hfa384x_drvr_flashdl_disable
2331 * Ends the flash download state. Note that this will cause the MAC
2332 * firmware to restart.
2335 * hw device structure
2339 * >0 f/w reported error - f/w status code
2340 * <0 driver reported error
2346 ----------------------------------------------------------------*/
2347 int hfa384x_drvr_flashdl_disable(hfa384x_t *hw)
2350 /* Check that we're already in the download state */
2351 if ( hw->dlstate != HFA384x_DLSTATE_FLASHENABLED ) {
2355 WLAN_LOG_DEBUG(1,"flashdl_enable\n");
2357 /* There isn't much we can do at this point, so I don't */
2358 /* bother w/ the return value */
2359 hfa384x_cmd_download(hw, HFA384x_PROGMODE_DISABLE, 0, 0 , 0);
2360 hw->dlstate = HFA384x_DLSTATE_DISABLED;
2367 /*----------------------------------------------------------------
2368 * hfa384x_drvr_flashdl_write
2370 * Performs a FLASH download of a chunk of data. First checks to see
2371 * that we're in the FLASH download state, then sets the download
2372 * mode, uses the aux functions to 1) copy the data to the flash
2373 * buffer, 2) sets the download 'write flash' mode, 3) readback and
2374 * compare. Lather rinse, repeat as many times an necessary to get
2375 * all the given data into flash.
2376 * When all data has been written using this function (possibly
2377 * repeatedly), call drvr_flashdl_disable() to end the download state
2378 * and restart the MAC.
2381 * hw device structure
2382 * daddr Card address to write to. (host order)
2383 * buf Ptr to data to write.
2384 * len Length of data (host order).
2388 * >0 f/w reported error - f/w status code
2389 * <0 driver reported error
2395 ----------------------------------------------------------------*/
2397 hfa384x_drvr_flashdl_write(
2419 WLAN_LOG_DEBUG(5,"daddr=0x%08x len=%d\n", daddr, len);
2421 /* Check that we're in the flash download state */
2422 if ( hw->dlstate != HFA384x_DLSTATE_FLASHENABLED ) {
2426 WLAN_LOG_INFO("Download %d bytes to flash @0x%06x\n", len, daddr);
2428 /* Convert to flat address for arithmetic */
2429 /* NOTE: dlbuffer RID stores the address in AUX format */
2430 dlbufaddr = HFA384x_ADDR_AUX_MKFLAT(
2431 hw->bufinfo.page, hw->bufinfo.offset);
2433 "dlbuf.page=0x%04x dlbuf.offset=0x%04x dlbufaddr=0x%08x\n",
2434 hw->bufinfo.page, hw->bufinfo.offset, dlbufaddr);
2437 WLAN_LOG_WARNING("dlbuf@0x%06lx len=%d to=%d\n", dlbufaddr, hw->bufinfo.len, hw->dltimeout);
2439 /* Calculations to determine how many fills of the dlbuffer to do
2440 * and how many USB wmemreq's to do for each fill. At this point
2441 * in time, the dlbuffer size and the wmemreq size are the same.
2442 * Therefore, nwrites should always be 1. The extra complexity
2443 * here is a hedge against future changes.
2446 /* Figure out how many times to do the flash programming */
2447 nburns = len / hw->bufinfo.len;
2448 nburns += (len % hw->bufinfo.len) ? 1 : 0;
2450 /* For each flash program cycle, how many USB wmemreq's are needed? */
2451 nwrites = hw->bufinfo.len / HFA384x_USB_RWMEM_MAXLEN;
2452 nwrites += (hw->bufinfo.len % HFA384x_USB_RWMEM_MAXLEN) ? 1 : 0;
2455 for ( i = 0; i < nburns; i++) {
2456 /* Get the dest address and len */
2457 burnlen = (len - (hw->bufinfo.len * i)) > hw->bufinfo.len ?
2459 (len - (hw->bufinfo.len * i));
2460 burndaddr = daddr + (hw->bufinfo.len * i);
2461 burnlo = HFA384x_ADDR_CMD_MKOFF(burndaddr);
2462 burnhi = HFA384x_ADDR_CMD_MKPAGE(burndaddr);
2464 WLAN_LOG_INFO("Writing %d bytes to flash @0x%06x\n",
2465 burnlen, burndaddr);
2467 /* Set the download mode */
2468 result = hfa384x_cmd_download(hw, HFA384x_PROGMODE_NV,
2469 burnlo, burnhi, burnlen);
2471 WLAN_LOG_ERROR("download(NV,lo=%x,hi=%x,len=%x) "
2472 "cmd failed, result=%d. Aborting d/l\n",
2473 burnlo, burnhi, burnlen, result);
2477 /* copy the data to the flash download buffer */
2478 for ( j=0; j < nwrites; j++) {
2480 (i*hw->bufinfo.len) +
2481 (j*HFA384x_USB_RWMEM_MAXLEN);
2483 writepage = HFA384x_ADDR_CMD_MKPAGE(
2485 (j*HFA384x_USB_RWMEM_MAXLEN));
2486 writeoffset = HFA384x_ADDR_CMD_MKOFF(
2488 (j*HFA384x_USB_RWMEM_MAXLEN));
2490 writelen = burnlen-(j*HFA384x_USB_RWMEM_MAXLEN);
2491 writelen = writelen > HFA384x_USB_RWMEM_MAXLEN ?
2492 HFA384x_USB_RWMEM_MAXLEN :
2495 result = hfa384x_dowmem_wait( hw,
2502 Comment out for debugging, assume the write was successful.
2505 "Write to dl buffer failed, "
2506 "result=0x%04x. Aborting.\n",
2514 /* set the download 'write flash' mode */
2515 result = hfa384x_cmd_download(hw,
2516 HFA384x_PROGMODE_NVWRITE,
2520 "download(NVWRITE,lo=%x,hi=%x,len=%x) "
2521 "cmd failed, result=%d. Aborting d/l\n",
2522 burnlo, burnhi, burnlen, result);
2526 /* TODO: We really should do a readback and compare. */
2531 /* Leave the firmware in the 'post-prog' mode. flashdl_disable will */
2532 /* actually disable programming mode. Remember, that will cause the */
2533 /* the firmware to effectively reset itself. */
2540 /*----------------------------------------------------------------
2541 * hfa384x_drvr_getconfig
2543 * Performs the sequence necessary to read a config/info item.
2546 * hw device structure
2547 * rid config/info record id (host order)
2548 * buf host side record buffer. Upon return it will
2549 * contain the body portion of the record (minus the
2551 * len buffer length (in bytes, should match record length)
2555 * >0 f/w reported error - f/w status code
2556 * <0 driver reported error
2557 * -ENODATA length mismatch between argument and retrieved
2564 ----------------------------------------------------------------*/
2565 int hfa384x_drvr_getconfig(hfa384x_t *hw, UINT16 rid, void *buf, UINT16 len)
2570 result = hfa384x_dorrid_wait(hw, rid, buf, len);
2576 /*----------------------------------------------------------------
2577 * hfa384x_drvr_getconfig_async
2579 * Performs the sequence necessary to perform an async read of
2580 * of a config/info item.
2583 * hw device structure
2584 * rid config/info record id (host order)
2585 * buf host side record buffer. Upon return it will
2586 * contain the body portion of the record (minus the
2588 * len buffer length (in bytes, should match record length)
2589 * cbfn caller supplied callback, called when the command
2590 * is done (successful or not).
2591 * cbfndata pointer to some caller supplied data that will be
2592 * passed in as an argument to the cbfn.
2595 * nothing the cbfn gets a status argument identifying if
2598 * Queues an hfa384x_usbcmd_t for subsequent execution.
2602 ----------------------------------------------------------------*/
2604 hfa384x_drvr_getconfig_async(
2607 ctlx_usercb_t usercb,
2610 return hfa384x_dorrid_async(hw, rid, NULL, 0,
2611 hfa384x_cb_rrid, usercb, usercb_data);
2614 /*----------------------------------------------------------------
2615 * hfa384x_drvr_setconfig_async
2617 * Performs the sequence necessary to write a config/info item.
2620 * hw device structure
2621 * rid config/info record id (in host order)
2622 * buf host side record buffer
2623 * len buffer length (in bytes)
2624 * usercb completion callback
2625 * usercb_data completion callback argument
2629 * >0 f/w reported error - f/w status code
2630 * <0 driver reported error
2636 ----------------------------------------------------------------*/
2638 hfa384x_drvr_setconfig_async(
2643 ctlx_usercb_t usercb,
2646 return hfa384x_dowrid_async(hw, rid, buf, len,
2647 hfa384x_cb_status, usercb, usercb_data);
2650 /*----------------------------------------------------------------
2651 * hfa384x_drvr_handover
2653 * Sends a handover notification to the MAC.
2656 * hw device structure
2657 * addr address of station that's left
2661 * -ERESTARTSYS received signal while waiting for semaphore.
2662 * -EIO failed to write to bap, or failed in cmd.
2668 ----------------------------------------------------------------*/
2669 int hfa384x_drvr_handover( hfa384x_t *hw, UINT8 *addr)
2672 WLAN_LOG_ERROR("Not currently supported in USB!\n");
2677 /*----------------------------------------------------------------
2678 * hfa384x_drvr_low_level
2680 * Write test commands to the card. Some test commands don't make
2681 * sense without prior set-up. For example, continous TX isn't very
2682 * useful until you set the channel. That functionality should be
2688 * -----------------------------------------------------------------*/
2689 int hfa384x_drvr_low_level(hfa384x_t *hw, hfa384x_metacmd_t *cmd)
2694 /* Do i need a host2hfa... conversion ? */
2696 result = hfa384x_docmd_wait(hw, cmd);
2702 /*----------------------------------------------------------------
2703 * hfa384x_drvr_mmi_read
2705 * Read mmi registers. mmi is intersil-speak for the baseband
2706 * processor registers.
2709 * hw device structure
2710 * register The test register to be accessed (must be even #).
2714 * >0 f/w reported error - f/w status code
2715 * <0 driver reported error
2721 ----------------------------------------------------------------*/
2722 int hfa384x_drvr_mmi_read(hfa384x_t *hw, UINT32 addr, UINT32 *resp)
2726 UINT16 cmd_code = (UINT16) 0x30;
2727 UINT16 param = (UINT16) addr;
2730 /* Do i need a host2hfa... conversion ? */
2731 result = hfa384x_docmd_wait(hw, cmd_code);
2739 /*----------------------------------------------------------------
2740 * hfa384x_drvr_mmi_write
2742 * Read mmi registers. mmi is intersil-speak for the baseband
2743 * processor registers.
2746 * hw device structure
2747 * addr The test register to be accessed (must be even #).
2748 * data The data value to write to the register.
2752 * >0 f/w reported error - f/w status code
2753 * <0 driver reported error
2759 ----------------------------------------------------------------*/
2762 hfa384x_drvr_mmi_write(hfa384x_t *hw, UINT32 addr, UINT32 data)
2766 UINT16 cmd_code = (UINT16) 0x31;
2767 UINT16 param0 = (UINT16) addr;
2768 UINT16 param1 = (UINT16) data;
2771 WLAN_LOG_DEBUG(1,"mmi write : addr = 0x%08lx\n", addr);
2772 WLAN_LOG_DEBUG(1,"mmi write : data = 0x%08lx\n", data);
2774 /* Do i need a host2hfa... conversion ? */
2775 result = hfa384x_docmd_wait(hw, cmd_code);
2784 /*----------------------------------------------------------------
2785 * hfa384x_drvr_ramdl_disable
2787 * Ends the ram download state.
2790 * hw device structure
2794 * >0 f/w reported error - f/w status code
2795 * <0 driver reported error
2801 ----------------------------------------------------------------*/
2803 hfa384x_drvr_ramdl_disable(hfa384x_t *hw)
2806 /* Check that we're already in the download state */
2807 if ( hw->dlstate != HFA384x_DLSTATE_RAMENABLED ) {
2811 WLAN_LOG_DEBUG(3,"ramdl_disable()\n");
2813 /* There isn't much we can do at this point, so I don't */
2814 /* bother w/ the return value */
2815 hfa384x_cmd_download(hw, HFA384x_PROGMODE_DISABLE, 0, 0 , 0);
2816 hw->dlstate = HFA384x_DLSTATE_DISABLED;
2823 /*----------------------------------------------------------------
2824 * hfa384x_drvr_ramdl_enable
2826 * Begins the ram download state. Checks to see that we're not
2827 * already in a download state and that a port isn't enabled.
2828 * Sets the download state and calls cmd_download with the
2829 * ENABLE_VOLATILE subcommand and the exeaddr argument.
2832 * hw device structure
2833 * exeaddr the card execution address that will be
2834 * jumped to when ramdl_disable() is called
2839 * >0 f/w reported error - f/w status code
2840 * <0 driver reported error
2846 ----------------------------------------------------------------*/
2848 hfa384x_drvr_ramdl_enable(hfa384x_t *hw, UINT32 exeaddr)
2855 /* Check that a port isn't active */
2856 for ( i = 0; i < HFA384x_PORTID_MAX; i++) {
2857 if ( hw->port_enabled[i] ) {
2859 "Can't download with a macport enabled.\n");
2864 /* Check that we're not already in a download state */
2865 if ( hw->dlstate != HFA384x_DLSTATE_DISABLED ) {
2867 "Download state not disabled.\n");
2871 WLAN_LOG_DEBUG(3,"ramdl_enable, exeaddr=0x%08x\n", exeaddr);
2873 /* Call the download(1,addr) function */
2874 lowaddr = HFA384x_ADDR_CMD_MKOFF(exeaddr);
2875 hiaddr = HFA384x_ADDR_CMD_MKPAGE(exeaddr);
2877 result = hfa384x_cmd_download(hw, HFA384x_PROGMODE_RAM,
2878 lowaddr, hiaddr, 0);
2881 /* Set the download state */
2882 hw->dlstate = HFA384x_DLSTATE_RAMENABLED;
2885 "cmd_download(0x%04x, 0x%04x) failed, result=%d.\n",
2896 /*----------------------------------------------------------------
2897 * hfa384x_drvr_ramdl_write
2899 * Performs a RAM download of a chunk of data. First checks to see
2900 * that we're in the RAM download state, then uses the [read|write]mem USB
2901 * commands to 1) copy the data, 2) readback and compare. The download
2902 * state is unaffected. When all data has been written using
2903 * this function, call drvr_ramdl_disable() to end the download state
2904 * and restart the MAC.
2907 * hw device structure
2908 * daddr Card address to write to. (host order)
2909 * buf Ptr to data to write.
2910 * len Length of data (host order).
2914 * >0 f/w reported error - f/w status code
2915 * <0 driver reported error
2921 ----------------------------------------------------------------*/
2923 hfa384x_drvr_ramdl_write(hfa384x_t *hw, UINT32 daddr, void* buf, UINT32 len)
2934 /* Check that we're in the ram download state */
2935 if ( hw->dlstate != HFA384x_DLSTATE_RAMENABLED ) {
2939 WLAN_LOG_INFO("Writing %d bytes to ram @0x%06x\n", len, daddr);
2941 /* How many dowmem calls? */
2942 nwrites = len / HFA384x_USB_RWMEM_MAXLEN;
2943 nwrites += len % HFA384x_USB_RWMEM_MAXLEN ? 1 : 0;
2945 /* Do blocking wmem's */
2946 for(i=0; i < nwrites; i++) {
2947 /* make address args */
2948 curraddr = daddr + (i * HFA384x_USB_RWMEM_MAXLEN);
2949 currpage = HFA384x_ADDR_CMD_MKPAGE(curraddr);
2950 curroffset = HFA384x_ADDR_CMD_MKOFF(curraddr);
2951 currlen = len - (i * HFA384x_USB_RWMEM_MAXLEN);
2952 if ( currlen > HFA384x_USB_RWMEM_MAXLEN) {
2953 currlen = HFA384x_USB_RWMEM_MAXLEN;
2956 /* Do blocking ctlx */
2957 result = hfa384x_dowmem_wait( hw,
2960 data + (i*HFA384x_USB_RWMEM_MAXLEN),
2965 /* TODO: We really should have a readback. */
2973 /*----------------------------------------------------------------
2974 * hfa384x_drvr_readpda
2976 * Performs the sequence to read the PDA space. Note there is no
2977 * drvr_writepda() function. Writing a PDA is
2978 * generally implemented by a calling component via calls to
2979 * cmd_download and writing to the flash download buffer via the
2983 * hw device structure
2984 * buf buffer to store PDA in
2989 * >0 f/w reported error - f/w status code
2990 * <0 driver reported error
2991 * -ETIMEOUT timout waiting for the cmd regs to become
2992 * available, or waiting for the control reg
2993 * to indicate the Aux port is enabled.
2994 * -ENODATA the buffer does NOT contain a valid PDA.
2995 * Either the card PDA is bad, or the auxdata
2996 * reads are giving us garbage.
3002 * process or non-card interrupt.
3003 ----------------------------------------------------------------*/
3004 int hfa384x_drvr_readpda(hfa384x_t *hw, void *buf, UINT len)
3010 int currpdr = 0; /* word offset of the current pdr */
3012 UINT16 pdrlen; /* pdr length in bytes, host order */
3013 UINT16 pdrcode; /* pdr code, host order */
3021 { HFA3842_PDA_BASE, 0},
3022 { HFA3841_PDA_BASE, 0},
3023 { HFA3841_PDA_BOGUS_BASE, 0}
3028 /* Read the pda from each known address. */
3029 for ( i = 0; i < ARRAY_SIZE(pdaloc); i++) {
3031 currpage = HFA384x_ADDR_CMD_MKPAGE(pdaloc[i].cardaddr);
3032 curroffset = HFA384x_ADDR_CMD_MKOFF(pdaloc[i].cardaddr);
3034 result = hfa384x_dormem_wait(hw,
3038 len); /* units of bytes */
3042 "Read from index %zd failed, continuing\n",
3047 /* Test for garbage */
3048 pdaok = 1; /* initially assume good */
3050 while ( pdaok && morepdrs ) {
3051 pdrlen = hfa384x2host_16(pda[currpdr]) * 2;
3052 pdrcode = hfa384x2host_16(pda[currpdr+1]);
3053 /* Test the record length */
3054 if ( pdrlen > HFA384x_PDR_LEN_MAX || pdrlen == 0) {
3055 WLAN_LOG_ERROR("pdrlen invalid=%d\n",
3061 if ( !hfa384x_isgood_pdrcode(pdrcode) ) {
3062 WLAN_LOG_ERROR("pdrcode invalid=%d\n",
3067 /* Test for completion */
3068 if ( pdrcode == HFA384x_PDR_END_OF_PDA) {
3072 /* Move to the next pdr (if necessary) */
3074 /* note the access to pda[], need words here */
3075 currpdr += hfa384x2host_16(pda[currpdr]) + 1;
3080 "PDA Read from 0x%08x in %s space.\n",
3082 pdaloc[i].auxctl == 0 ? "EXTDS" :
3083 pdaloc[i].auxctl == 1 ? "NV" :
3084 pdaloc[i].auxctl == 2 ? "PHY" :
3085 pdaloc[i].auxctl == 3 ? "ICSRAM" :
3090 result = pdaok ? 0 : -ENODATA;
3093 WLAN_LOG_DEBUG(3,"Failure: pda is not okay\n");
3101 /*----------------------------------------------------------------
3102 * hfa384x_drvr_setconfig
3104 * Performs the sequence necessary to write a config/info item.
3107 * hw device structure
3108 * rid config/info record id (in host order)
3109 * buf host side record buffer
3110 * len buffer length (in bytes)
3114 * >0 f/w reported error - f/w status code
3115 * <0 driver reported error
3121 ----------------------------------------------------------------*/
3122 int hfa384x_drvr_setconfig(hfa384x_t *hw, UINT16 rid, void *buf, UINT16 len)
3124 return hfa384x_dowrid_wait(hw, rid, buf, len);
3127 /*----------------------------------------------------------------
3128 * hfa384x_drvr_start
3130 * Issues the MAC initialize command, sets up some data structures,
3131 * and enables the interrupts. After this function completes, the
3132 * low-level stuff should be ready for any/all commands.
3135 * hw device structure
3138 * >0 f/w reported error - f/w status code
3139 * <0 driver reported error
3145 ----------------------------------------------------------------*/
3146 int hfa384x_drvr_start(hfa384x_t *hw)
3153 if (usb_clear_halt(hw->usb, hw->endp_in)) {
3155 "Failed to reset bulk in endpoint.\n");
3158 if (usb_clear_halt(hw->usb, hw->endp_out)) {
3160 "Failed to reset bulk out endpoint.\n");
3163 /* Synchronous unlink, in case we're trying to restart the driver */
3164 usb_kill_urb(&hw->rx_urb);
3166 /* Post the IN urb */
3167 result = submit_rx_urb(hw, GFP_KERNEL);
3170 "Fatal, failed to submit RX URB, result=%d\n",
3175 /* call initialize */
3176 result = hfa384x_cmd_initialize(hw);
3178 usb_kill_urb(&hw->rx_urb);
3180 "cmd_initialize() failed, result=%d\n",
3185 hw->state = HFA384x_STATE_RUNNING;
3193 /*----------------------------------------------------------------
3196 * Shuts down the MAC to the point where it is safe to unload the
3197 * driver. Any subsystem that may be holding a data or function
3198 * ptr into the driver must be cleared/deinitialized.
3201 * hw device structure
3204 * >0 f/w reported error - f/w status code
3205 * <0 driver reported error
3211 ----------------------------------------------------------------*/
3213 hfa384x_drvr_stop(hfa384x_t *hw)
3221 /* There's no need for spinlocks here. The USB "disconnect"
3222 * function sets this "removed" flag and then calls us.
3224 if ( !hw->wlandev->hwremoved ) {
3225 /* Call initialize to leave the MAC in its 'reset' state */
3226 hfa384x_cmd_initialize(hw);
3228 /* Cancel the rxurb */
3229 usb_kill_urb(&hw->rx_urb);
3232 hw->link_status = HFA384x_LINK_NOTCONNECTED;
3233 hw->state = HFA384x_STATE_INIT;
3235 del_timer_sync(&hw->commsqual_timer);
3237 /* Clear all the port status */
3238 for ( i = 0; i < HFA384x_NUMPORTS_MAX; i++) {
3239 hw->port_enabled[i] = 0;
3246 /*----------------------------------------------------------------
3247 * hfa384x_drvr_txframe
3249 * Takes a frame from prism2sta and queues it for transmission.
3252 * hw device structure
3253 * skb packet buffer struct. Contains an 802.11
3255 * p80211_hdr points to the 802.11 header for the packet.
3257 * 0 Success and more buffs available
3258 * 1 Success but no more buffs
3259 * 2 Allocation failure
3260 * 4 Buffer full or queue busy
3266 ----------------------------------------------------------------*/
3267 int hfa384x_drvr_txframe(hfa384x_t *hw, struct sk_buff *skb, p80211_hdr_t *p80211_hdr, p80211_metawep_t *p80211_wep)
3270 int usbpktlen = sizeof(hfa384x_tx_frame_t);
3277 if (hw->tx_urb.status == -EINPROGRESS) {
3278 WLAN_LOG_WARNING("TX URB already in use\n");
3283 /* Build Tx frame structure */
3284 /* Set up the control field */
3285 memset(&hw->txbuff.txfrm.desc, 0, sizeof(hw->txbuff.txfrm.desc));
3287 /* Setup the usb type field */
3288 hw->txbuff.type = host2hfa384x_16(HFA384x_USB_TXFRM);
3290 /* Set up the sw_support field to identify this frame */
3291 hw->txbuff.txfrm.desc.sw_support = 0x0123;
3293 /* Tx complete and Tx exception disable per dleach. Might be causing
3296 //#define DOEXC SLP -- doboth breaks horribly under load, doexc less so.
3298 hw->txbuff.txfrm.desc.tx_control =
3299 HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
3300 HFA384x_TX_TXEX_SET(1) | HFA384x_TX_TXOK_SET(1);
3301 #elif defined(DOEXC)
3302 hw->txbuff.txfrm.desc.tx_control =
3303 HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
3304 HFA384x_TX_TXEX_SET(1) | HFA384x_TX_TXOK_SET(0);
3306 hw->txbuff.txfrm.desc.tx_control =
3307 HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
3308 HFA384x_TX_TXEX_SET(0) | HFA384x_TX_TXOK_SET(0);
3310 hw->txbuff.txfrm.desc.tx_control =
3311 host2hfa384x_16(hw->txbuff.txfrm.desc.tx_control);
3313 /* copy the header over to the txdesc */
3314 memcpy(&(hw->txbuff.txfrm.desc.frame_control), p80211_hdr, sizeof(p80211_hdr_t));
3316 /* if we're using host WEP, increase size by IV+ICV */
3317 if (p80211_wep->data) {
3318 hw->txbuff.txfrm.desc.data_len = host2hfa384x_16(skb->len+8);
3319 // hw->txbuff.txfrm.desc.tx_control |= HFA384x_TX_NOENCRYPT_SET(1);
3322 hw->txbuff.txfrm.desc.data_len = host2hfa384x_16(skb->len);
3325 usbpktlen += skb->len;
3327 /* copy over the WEP IV if we are using host WEP */
3328 ptr = hw->txbuff.txfrm.data;
3329 if (p80211_wep->data) {
3330 memcpy(ptr, p80211_wep->iv, sizeof(p80211_wep->iv));
3331 ptr+= sizeof(p80211_wep->iv);
3332 memcpy(ptr, p80211_wep->data, skb->len);
3334 memcpy(ptr, skb->data, skb->len);
3336 /* copy over the packet data */
3339 /* copy over the WEP ICV if we are using host WEP */
3340 if (p80211_wep->data) {
3341 memcpy(ptr, p80211_wep->icv, sizeof(p80211_wep->icv));
3344 /* Send the USB packet */
3345 usb_fill_bulk_urb( &(hw->tx_urb), hw->usb,
3347 &(hw->txbuff), ROUNDUP64(usbpktlen),
3348 hfa384x_usbout_callback, hw->wlandev );
3349 hw->tx_urb.transfer_flags |= USB_QUEUE_BULK;
3352 ret = submit_tx_urb(hw, &hw->tx_urb, GFP_ATOMIC);
3355 "submit_tx_urb() failed, error=%d\n", ret);
3364 void hfa384x_tx_timeout(wlandevice_t *wlandev)
3366 hfa384x_t *hw = wlandev->priv;
3367 unsigned long flags;
3371 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3373 if ( !hw->wlandev->hwremoved &&
3374 /* Note the bitwise OR, not the logical OR. */
3375 ( !test_and_set_bit(WORK_TX_HALT, &hw->usb_flags) |
3376 !test_and_set_bit(WORK_RX_HALT, &hw->usb_flags) ) )
3378 schedule_work(&hw->usb_work);
3381 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3386 /*----------------------------------------------------------------
3387 * hfa384x_usbctlx_reaper_task
3389 * Tasklet to delete dead CTLX objects
3392 * data ptr to a hfa384x_t
3398 ----------------------------------------------------------------*/
3399 static void hfa384x_usbctlx_reaper_task(unsigned long data)
3401 hfa384x_t *hw = (hfa384x_t*)data;
3402 struct list_head *entry;
3403 struct list_head *temp;
3404 unsigned long flags;
3408 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3410 /* This list is guaranteed to be empty if someone
3411 * has unplugged the adapter.
3413 list_for_each_safe(entry, temp, &hw->ctlxq.reapable) {
3414 hfa384x_usbctlx_t *ctlx;
3416 ctlx = list_entry(entry, hfa384x_usbctlx_t, list);
3417 list_del(&ctlx->list);
3421 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3426 /*----------------------------------------------------------------
3427 * hfa384x_usbctlx_completion_task
3429 * Tasklet to call completion handlers for returned CTLXs
3432 * data ptr to hfa384x_t
3439 ----------------------------------------------------------------*/
3440 static void hfa384x_usbctlx_completion_task(unsigned long data)
3442 hfa384x_t *hw = (hfa384x_t*)data;
3443 struct list_head *entry;
3444 struct list_head *temp;
3445 unsigned long flags;
3451 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3453 /* This list is guaranteed to be empty if someone
3454 * has unplugged the adapter ...
3456 list_for_each_safe(entry, temp, &hw->ctlxq.completing) {
3457 hfa384x_usbctlx_t *ctlx;
3459 ctlx = list_entry(entry, hfa384x_usbctlx_t, list);
3461 /* Call the completion function that this
3462 * command was assigned, assuming it has one.
3464 if ( ctlx->cmdcb != NULL ) {
3465 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3466 ctlx->cmdcb(hw, ctlx);
3467 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3469 /* Make sure we don't try and complete
3470 * this CTLX more than once!
3474 /* Did someone yank the adapter out
3475 * while our list was (briefly) unlocked?
3477 if ( hw->wlandev->hwremoved )
3485 * "Reapable" CTLXs are ones which don't have any
3486 * threads waiting for them to die. Hence they must
3487 * be delivered to The Reaper!
3489 if ( ctlx->reapable ) {
3490 /* Move the CTLX off the "completing" list (hopefully)
3491 * on to the "reapable" list where the reaper task
3492 * can find it. And "reapable" means that this CTLX
3493 * isn't sitting on a wait-queue somewhere.
3495 list_move_tail(&ctlx->list, &hw->ctlxq.reapable);
3499 complete(&ctlx->done);
3501 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3504 tasklet_schedule(&hw->reaper_bh);
3509 /*----------------------------------------------------------------
3510 * unlocked_usbctlx_cancel_async
3512 * Mark the CTLX dead asynchronously, and ensure that the
3513 * next command on the queue is run afterwards.
3516 * hw ptr to the hfa384x_t structure
3517 * ctlx ptr to a CTLX structure
3520 * 0 the CTLX's URB is inactive
3521 * -EINPROGRESS the URB is currently being unlinked
3524 * Either process or interrupt, but presumably interrupt
3525 ----------------------------------------------------------------*/
3526 static int unlocked_usbctlx_cancel_async(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx)
3533 * Try to delete the URB containing our request packet.
3534 * If we succeed, then its completion handler will be
3535 * called with a status of -ECONNRESET.
3537 hw->ctlx_urb.transfer_flags |= URB_ASYNC_UNLINK;
3538 ret = usb_unlink_urb(&hw->ctlx_urb);
3540 if (ret != -EINPROGRESS) {
3542 * The OUT URB had either already completed
3543 * or was still in the pending queue, so the
3544 * URB's completion function will not be called.
3545 * We will have to complete the CTLX ourselves.
3547 ctlx->state = CTLX_REQ_FAILED;
3548 unlocked_usbctlx_complete(hw, ctlx);
3557 /*----------------------------------------------------------------
3558 * unlocked_usbctlx_complete
3560 * A CTLX has completed. It may have been successful, it may not
3561 * have been. At this point, the CTLX should be quiescent. The URBs
3562 * aren't active and the timers should have been stopped.
3564 * The CTLX is migrated to the "completing" queue, and the completing
3565 * tasklet is scheduled.
3568 * hw ptr to a hfa384x_t structure
3569 * ctlx ptr to a ctlx structure
3577 * Either, assume interrupt
3578 ----------------------------------------------------------------*/
3579 static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx)
3583 /* Timers have been stopped, and ctlx should be in
3584 * a terminal state. Retire it from the "active"
3587 list_move_tail(&ctlx->list, &hw->ctlxq.completing);
3588 tasklet_schedule(&hw->completion_bh);
3590 switch (ctlx->state) {
3592 case CTLX_REQ_FAILED:
3593 /* This are the correct terminating states. */
3597 WLAN_LOG_ERROR("CTLX[%d] not in a terminating state(%s)\n",
3598 hfa384x2host_16(ctlx->outbuf.type),
3599 ctlxstr(ctlx->state));
3606 /*----------------------------------------------------------------
3607 * hfa384x_usbctlxq_run
3609 * Checks to see if the head item is running. If not, starts it.
3612 * hw ptr to hfa384x_t
3621 ----------------------------------------------------------------*/
3623 hfa384x_usbctlxq_run(hfa384x_t *hw)
3625 unsigned long flags;
3629 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3631 /* Only one active CTLX at any one time, because there's no
3632 * other (reliable) way to match the response URB to the
3635 * Don't touch any of these CTLXs if the hardware
3636 * has been removed or the USB subsystem is stalled.
3638 if ( !list_empty(&hw->ctlxq.active) ||
3639 test_bit(WORK_TX_HALT, &hw->usb_flags) ||
3640 hw->wlandev->hwremoved )
3643 while ( !list_empty(&hw->ctlxq.pending) ) {
3644 hfa384x_usbctlx_t *head;
3647 /* This is the first pending command */
3648 head = list_entry(hw->ctlxq.pending.next,
3652 /* We need to split this off to avoid a race condition */
3653 list_move_tail(&head->list, &hw->ctlxq.active);
3655 /* Fill the out packet */
3656 usb_fill_bulk_urb( &(hw->ctlx_urb), hw->usb,
3658 &(head->outbuf), ROUNDUP64(head->outbufsize),
3659 hfa384x_ctlxout_callback, hw);
3660 hw->ctlx_urb.transfer_flags |= USB_QUEUE_BULK;
3662 /* Now submit the URB and update the CTLX's state
3664 if ((result = SUBMIT_URB(&hw->ctlx_urb, GFP_ATOMIC)) == 0) {
3665 /* This CTLX is now running on the active queue */
3666 head->state = CTLX_REQ_SUBMITTED;
3668 /* Start the OUT wait timer */
3669 hw->req_timer_done = 0;
3670 hw->reqtimer.expires = jiffies + HZ;
3671 add_timer(&hw->reqtimer);
3673 /* Start the IN wait timer */
3674 hw->resp_timer_done = 0;
3675 hw->resptimer.expires = jiffies + 2*HZ;
3676 add_timer(&hw->resptimer);
3681 if (result == -EPIPE) {
3682 /* The OUT pipe needs resetting, so put
3683 * this CTLX back in the "pending" queue
3684 * and schedule a reset ...
3686 WLAN_LOG_WARNING("%s tx pipe stalled: requesting reset\n",
3687 hw->wlandev->netdev->name);
3688 list_move(&head->list, &hw->ctlxq.pending);
3689 set_bit(WORK_TX_HALT, &hw->usb_flags);
3690 schedule_work(&hw->usb_work);
3694 if (result == -ESHUTDOWN) {
3695 WLAN_LOG_WARNING("%s urb shutdown!\n",
3696 hw->wlandev->netdev->name);
3700 WLAN_LOG_ERROR("Failed to submit CTLX[%d]: error=%d\n",
3701 hfa384x2host_16(head->outbuf.type), result);
3702 unlocked_usbctlx_complete(hw, head);
3706 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3712 /*----------------------------------------------------------------
3713 * hfa384x_usbin_callback
3715 * Callback for URBs on the BULKIN endpoint.
3718 * urb ptr to the completed urb
3727 ----------------------------------------------------------------*/
3728 #ifdef URB_ONLY_CALLBACK
3729 static void hfa384x_usbin_callback(struct urb *urb)
3731 static void hfa384x_usbin_callback(struct urb *urb, struct pt_regs *regs)
3734 wlandevice_t *wlandev = urb->context;
3736 hfa384x_usbin_t *usbin = (hfa384x_usbin_t *) urb->transfer_buffer;
3737 struct sk_buff *skb = NULL;
3752 !netif_device_present(wlandev->netdev) )
3759 skb = hw->rx_urb_skb;
3760 if (!skb || (skb->data != urb->transfer_buffer)) {
3763 hw->rx_urb_skb = NULL;
3765 /* Check for error conditions within the URB */
3766 switch (urb->status) {
3770 /* Check for short packet */
3771 if ( urb->actual_length == 0 ) {
3772 ++(wlandev->linux_stats.rx_errors);
3773 ++(wlandev->linux_stats.rx_length_errors);
3779 WLAN_LOG_WARNING("%s rx pipe stalled: requesting reset\n",
3780 wlandev->netdev->name);
3781 if ( !test_and_set_bit(WORK_RX_HALT, &hw->usb_flags) )
3782 schedule_work(&hw->usb_work);
3783 ++(wlandev->linux_stats.rx_errors);
3790 if ( !test_and_set_bit(THROTTLE_RX, &hw->usb_flags) &&
3791 !timer_pending(&hw->throttle) ) {
3792 mod_timer(&hw->throttle, jiffies + THROTTLE_JIFFIES);
3794 ++(wlandev->linux_stats.rx_errors);
3799 ++(wlandev->linux_stats.rx_over_errors);
3805 WLAN_LOG_DEBUG(3,"status=%d, device removed.\n", urb->status);
3811 WLAN_LOG_DEBUG(3,"status=%d, urb explicitly unlinked.\n", urb->status);
3816 WLAN_LOG_DEBUG(3,"urb status=%d, transfer flags=0x%x\n",
3817 urb->status, urb->transfer_flags);
3818 ++(wlandev->linux_stats.rx_errors);
3823 urb_status = urb->status;
3825 if (action != ABORT) {
3826 /* Repost the RX URB */
3827 result = submit_rx_urb(hw, GFP_ATOMIC);
3831 "Fatal, failed to resubmit rx_urb. error=%d\n",
3836 /* Handle any USB-IN packet */
3837 /* Note: the check of the sw_support field, the type field doesn't
3838 * have bit 12 set like the docs suggest.
3840 type = hfa384x2host_16(usbin->type);
3841 if (HFA384x_USB_ISRXFRM(type)) {
3842 if (action == HANDLE) {
3843 if (usbin->txfrm.desc.sw_support == 0x0123) {
3844 hfa384x_usbin_txcompl(wlandev, usbin);
3846 skb_put(skb, sizeof(*usbin));
3847 hfa384x_usbin_rx(wlandev, skb);
3853 if (HFA384x_USB_ISTXFRM(type)) {
3854 if (action == HANDLE)
3855 hfa384x_usbin_txcompl(wlandev, usbin);
3859 case HFA384x_USB_INFOFRM:
3860 if (action == ABORT)
3862 if (action == HANDLE)
3863 hfa384x_usbin_info(wlandev, usbin);
3866 case HFA384x_USB_CMDRESP:
3867 case HFA384x_USB_WRIDRESP:
3868 case HFA384x_USB_RRIDRESP:
3869 case HFA384x_USB_WMEMRESP:
3870 case HFA384x_USB_RMEMRESP:
3871 /* ALWAYS, ALWAYS, ALWAYS handle this CTLX!!!! */
3872 hfa384x_usbin_ctlx(hw, usbin, urb_status);
3875 case HFA384x_USB_BUFAVAIL:
3876 WLAN_LOG_DEBUG(3,"Received BUFAVAIL packet, frmlen=%d\n",
3877 usbin->bufavail.frmlen);
3880 case HFA384x_USB_ERROR:
3881 WLAN_LOG_DEBUG(3,"Received USB_ERROR packet, errortype=%d\n",
3882 usbin->usberror.errortype);
3886 WLAN_LOG_DEBUG(3,"Unrecognized USBIN packet, type=%x, status=%d\n",
3887 usbin->type, urb_status);
3900 /*----------------------------------------------------------------
3901 * hfa384x_usbin_ctlx
3903 * We've received a URB containing a Prism2 "response" message.
3904 * This message needs to be matched up with a CTLX on the active
3905 * queue and our state updated accordingly.
3908 * hw ptr to hfa384x_t
3909 * usbin ptr to USB IN packet
3910 * urb_status status of this Bulk-In URB
3919 ----------------------------------------------------------------*/
3920 static void hfa384x_usbin_ctlx(hfa384x_t *hw, hfa384x_usbin_t *usbin,
3923 hfa384x_usbctlx_t *ctlx;
3925 unsigned long flags;
3930 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3932 /* There can be only one CTLX on the active queue
3933 * at any one time, and this is the CTLX that the
3934 * timers are waiting for.
3936 if ( list_empty(&hw->ctlxq.active) ) {
3940 /* Remove the "response timeout". It's possible that
3941 * we are already too late, and that the timeout is
3942 * already running. And that's just too bad for us,
3943 * because we could lose our CTLX from the active
3946 if (del_timer(&hw->resptimer) == 0) {
3947 if (hw->resp_timer_done == 0) {
3948 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3953 hw->resp_timer_done = 1;
3956 ctlx = get_active_ctlx(hw);
3958 if (urb_status != 0) {
3960 * Bad CTLX, so get rid of it. But we only
3961 * remove it from the active queue if we're no
3962 * longer expecting the OUT URB to complete.
3964 if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0)
3967 const UINT16 intype = (usbin->type&~host2hfa384x_16(0x8000));
3970 * Check that our message is what we're expecting ...
3972 if (ctlx->outbuf.type != intype) {
3973 WLAN_LOG_WARNING("Expected IN[%d], received IN[%d] - ignored.\n",
3974 hfa384x2host_16(ctlx->outbuf.type),
3975 hfa384x2host_16(intype));
3979 /* This URB has succeeded, so grab the data ... */
3980 memcpy(&ctlx->inbuf, usbin, sizeof(ctlx->inbuf));
3982 switch (ctlx->state) {
3983 case CTLX_REQ_SUBMITTED:
3985 * We have received our response URB before
3986 * our request has been acknowledged. Odd,
3987 * but our OUT URB is still alive...
3989 WLAN_LOG_DEBUG(0, "Causality violation: please reboot Universe, or email linux-wlan-devel@lists.linux-wlan.com\n");
3990 ctlx->state = CTLX_RESP_COMPLETE;
3993 case CTLX_REQ_COMPLETE:
3995 * This is the usual path: our request
3996 * has already been acknowledged, and
3997 * now we have received the reply too.
3999 ctlx->state = CTLX_COMPLETE;
4000 unlocked_usbctlx_complete(hw, ctlx);
4006 * Throw this CTLX away ...
4008 WLAN_LOG_ERROR("Matched IN URB, CTLX[%d] in invalid state(%s)."
4010 hfa384x2host_16(ctlx->outbuf.type),
4011 ctlxstr(ctlx->state));
4012 if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0)
4019 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
4022 hfa384x_usbctlxq_run(hw);
4028 /*----------------------------------------------------------------
4029 * hfa384x_usbin_txcompl
4031 * At this point we have the results of a previous transmit.
4034 * wlandev wlan device
4035 * usbin ptr to the usb transfer buffer
4044 ----------------------------------------------------------------*/
4045 static void hfa384x_usbin_txcompl(wlandevice_t *wlandev, hfa384x_usbin_t *usbin)
4050 status = hfa384x2host_16(usbin->type); /* yeah I know it says type...*/
4052 /* Was there an error? */
4053 if (HFA384x_TXSTATUS_ISERROR(status)) {
4054 prism2sta_ev_txexc(wlandev, status);
4056 prism2sta_ev_tx(wlandev, status);
4058 // prism2sta_ev_alloc(wlandev);
4064 /*----------------------------------------------------------------
4067 * At this point we have a successful received a rx frame packet.
4070 * wlandev wlan device
4071 * usbin ptr to the usb transfer buffer
4080 ----------------------------------------------------------------*/
4081 static void hfa384x_usbin_rx(wlandevice_t *wlandev, struct sk_buff *skb)
4083 hfa384x_usbin_t *usbin = (hfa384x_usbin_t *) skb->data;
4084 hfa384x_t *hw = wlandev->priv;
4086 p80211_rxmeta_t *rxmeta;
4092 /* Byte order convert once up front. */
4093 usbin->rxfrm.desc.status =
4094 hfa384x2host_16(usbin->rxfrm.desc.status);
4095 usbin->rxfrm.desc.time =
4096 hfa384x2host_32(usbin->rxfrm.desc.time);
4098 /* Now handle frame based on port# */
4099 switch( HFA384x_RXSTATUS_MACPORT_GET(usbin->rxfrm.desc.status) )
4102 fc = ieee2host16(usbin->rxfrm.desc.frame_control);
4104 /* If exclude and we receive an unencrypted, drop it */
4105 if ( (wlandev->hostwep & HOSTWEP_EXCLUDEUNENCRYPTED) &&
4106 !WLAN_GET_FC_ISWEP(fc)){
4110 data_len = hfa384x2host_16(usbin->rxfrm.desc.data_len);
4112 /* How much header data do we have? */
4113 hdrlen = p80211_headerlen(fc);
4115 /* Pull off the descriptor */
4116 skb_pull(skb, sizeof(hfa384x_rx_frame_t));
4118 /* Now shunt the header block up against the data block
4119 * with an "overlapping" copy
4121 memmove(skb_push(skb, hdrlen),
4122 &usbin->rxfrm.desc.frame_control,
4125 skb->dev = wlandev->netdev;
4126 skb->dev->last_rx = jiffies;
4128 /* And set the frame length properly */
4129 skb_trim(skb, data_len + hdrlen);
4131 /* The prism2 series does not return the CRC */
4132 memset(skb_put(skb, WLAN_CRC_LEN), 0xff, WLAN_CRC_LEN);
4134 skb_reset_mac_header(skb);
4136 /* Attach the rxmeta, set some stuff */
4137 p80211skb_rxmeta_attach(wlandev, skb);
4138 rxmeta = P80211SKB_RXMETA(skb);
4139 rxmeta->mactime = usbin->rxfrm.desc.time;
4140 rxmeta->rxrate = usbin->rxfrm.desc.rate;
4141 rxmeta->signal = usbin->rxfrm.desc.signal - hw->dbmadjust;
4142 rxmeta->noise = usbin->rxfrm.desc.silence - hw->dbmadjust;
4144 prism2sta_ev_rx(wlandev, skb);
4149 if ( ! HFA384x_RXSTATUS_ISFCSERR(usbin->rxfrm.desc.status) ) {
4150 /* Copy to wlansnif skb */
4151 hfa384x_int_rxmonitor( wlandev, &usbin->rxfrm);
4154 WLAN_LOG_DEBUG(3,"Received monitor frame: FCSerr set\n");
4159 WLAN_LOG_WARNING("Received frame on unsupported port=%d\n",
4160 HFA384x_RXSTATUS_MACPORT_GET(usbin->rxfrm.desc.status) );
4170 /*----------------------------------------------------------------
4171 * hfa384x_int_rxmonitor
4173 * Helper function for int_rx. Handles monitor frames.
4174 * Note that this function allocates space for the FCS and sets it
4175 * to 0xffffffff. The hfa384x doesn't give us the FCS value but the
4176 * higher layers expect it. 0xffffffff is used as a flag to indicate
4180 * wlandev wlan device structure
4181 * rxfrm rx descriptor read from card in int_rx
4187 * Allocates an skb and passes it up via the PF_PACKET interface.
4190 ----------------------------------------------------------------*/
4191 static void hfa384x_int_rxmonitor( wlandevice_t *wlandev, hfa384x_usb_rxfrm_t *rxfrm)
4193 hfa384x_rx_frame_t *rxdesc = &(rxfrm->desc);
4197 p80211msg_lnxind_wlansniffrm_t *msg;
4200 struct sk_buff *skb;
4201 hfa384x_t *hw = wlandev->priv;
4205 /* Don't forget the status, time, and data_len fields are in host order */
4206 /* Figure out how big the frame is */
4207 fc = ieee2host16(rxdesc->frame_control);
4208 hdrlen = p80211_headerlen(fc);
4209 datalen = hfa384x2host_16(rxdesc->data_len);
4211 /* Allocate an ind message+framesize skb */
4212 skblen = sizeof(p80211msg_lnxind_wlansniffrm_t) +
4213 hdrlen + datalen + WLAN_CRC_LEN;
4215 /* sanity check the length */
4217 (sizeof(p80211msg_lnxind_wlansniffrm_t) +
4218 WLAN_HDR_A4_LEN + WLAN_DATA_MAXLEN + WLAN_CRC_LEN) ) {
4219 WLAN_LOG_DEBUG(1, "overlen frm: len=%zd\n",
4220 skblen - sizeof(p80211msg_lnxind_wlansniffrm_t));
4223 if ( (skb = dev_alloc_skb(skblen)) == NULL ) {
4224 WLAN_LOG_ERROR("alloc_skb failed trying to allocate %d bytes\n", skblen);
4228 /* only prepend the prism header if in the right mode */
4229 if ((wlandev->netdev->type == ARPHRD_IEEE80211_PRISM) &&
4230 (hw->sniffhdr == 0)) {
4231 datap = skb_put(skb, sizeof(p80211msg_lnxind_wlansniffrm_t));
4232 msg = (p80211msg_lnxind_wlansniffrm_t*) datap;
4234 /* Initialize the message members */
4235 msg->msgcode = DIDmsg_lnxind_wlansniffrm;
4236 msg->msglen = sizeof(p80211msg_lnxind_wlansniffrm_t);
4237 strcpy(msg->devname, wlandev->name);
4239 msg->hosttime.did = DIDmsg_lnxind_wlansniffrm_hosttime;
4240 msg->hosttime.status = 0;
4241 msg->hosttime.len = 4;
4242 msg->hosttime.data = jiffies;
4244 msg->mactime.did = DIDmsg_lnxind_wlansniffrm_mactime;
4245 msg->mactime.status = 0;
4246 msg->mactime.len = 4;
4247 msg->mactime.data = rxdesc->time;
4249 msg->channel.did = DIDmsg_lnxind_wlansniffrm_channel;
4250 msg->channel.status = 0;
4251 msg->channel.len = 4;
4252 msg->channel.data = hw->sniff_channel;
4254 msg->rssi.did = DIDmsg_lnxind_wlansniffrm_rssi;
4255 msg->rssi.status = P80211ENUM_msgitem_status_no_value;
4259 msg->sq.did = DIDmsg_lnxind_wlansniffrm_sq;
4260 msg->sq.status = P80211ENUM_msgitem_status_no_value;
4264 msg->signal.did = DIDmsg_lnxind_wlansniffrm_signal;
4265 msg->signal.status = 0;
4266 msg->signal.len = 4;
4267 msg->signal.data = rxdesc->signal;
4269 msg->noise.did = DIDmsg_lnxind_wlansniffrm_noise;
4270 msg->noise.status = 0;
4272 msg->noise.data = rxdesc->silence;
4274 msg->rate.did = DIDmsg_lnxind_wlansniffrm_rate;
4275 msg->rate.status = 0;
4277 msg->rate.data = rxdesc->rate / 5; /* set to 802.11 units */
4279 msg->istx.did = DIDmsg_lnxind_wlansniffrm_istx;
4280 msg->istx.status = 0;
4282 msg->istx.data = P80211ENUM_truth_false;
4284 msg->frmlen.did = DIDmsg_lnxind_wlansniffrm_frmlen;
4285 msg->frmlen.status = 0;
4286 msg->frmlen.len = 4;
4287 msg->frmlen.data = hdrlen + datalen + WLAN_CRC_LEN;
4288 } else if ((wlandev->netdev->type == ARPHRD_IEEE80211_PRISM) &&
4289 (hw->sniffhdr != 0)) {
4290 p80211_caphdr_t *caphdr;
4291 /* The NEW header format! */
4292 datap = skb_put(skb, sizeof(p80211_caphdr_t));
4293 caphdr = (p80211_caphdr_t*) datap;
4295 caphdr->version = htonl(P80211CAPTURE_VERSION);
4296 caphdr->length = htonl(sizeof(p80211_caphdr_t));
4297 caphdr->mactime = __cpu_to_be64(rxdesc->time) * 1000;
4298 caphdr->hosttime = __cpu_to_be64(jiffies);
4299 caphdr->phytype = htonl(4); /* dss_dot11_b */
4300 caphdr->channel = htonl(hw->sniff_channel);
4301 caphdr->datarate = htonl(rxdesc->rate);
4302 caphdr->antenna = htonl(0); /* unknown */
4303 caphdr->priority = htonl(0); /* unknown */
4304 caphdr->ssi_type = htonl(3); /* rssi_raw */
4305 caphdr->ssi_signal = htonl(rxdesc->signal);
4306 caphdr->ssi_noise = htonl(rxdesc->silence);
4307 caphdr->preamble = htonl(0); /* unknown */
4308 caphdr->encoding = htonl(1); /* cck */
4311 /* Copy the 802.11 header to the skb (ctl frames may be less than a full header) */
4312 datap = skb_put(skb, hdrlen);
4313 memcpy( datap, &(rxdesc->frame_control), hdrlen);
4315 /* If any, copy the data from the card to the skb */
4318 datap = skb_put(skb, datalen);
4319 memcpy(datap, rxfrm->data, datalen);
4321 /* check for unencrypted stuff if WEP bit set. */
4322 if (*(datap - hdrlen + 1) & 0x40) // wep set
4323 if ((*(datap) == 0xaa) && (*(datap+1) == 0xaa))
4324 *(datap - hdrlen + 1) &= 0xbf; // clear wep; it's the 802.2 header!
4327 if (hw->sniff_fcs) {
4329 datap = skb_put(skb, WLAN_CRC_LEN);
4330 memset( datap, 0xff, WLAN_CRC_LEN);
4333 /* pass it back up */
4334 prism2sta_ev_rx(wlandev, skb);
4342 /*----------------------------------------------------------------
4343 * hfa384x_usbin_info
4345 * At this point we have a successful received a Prism2 info frame.
4348 * wlandev wlan device
4349 * usbin ptr to the usb transfer buffer
4358 ----------------------------------------------------------------*/
4359 static void hfa384x_usbin_info(wlandevice_t *wlandev, hfa384x_usbin_t *usbin)
4363 usbin->infofrm.info.framelen = hfa384x2host_16(usbin->infofrm.info.framelen);
4364 prism2sta_ev_info(wlandev, &usbin->infofrm.info);
4371 /*----------------------------------------------------------------
4372 * hfa384x_usbout_callback
4374 * Callback for URBs on the BULKOUT endpoint.
4377 * urb ptr to the completed urb
4386 ----------------------------------------------------------------*/
4387 #ifdef URB_ONLY_CALLBACK
4388 static void hfa384x_usbout_callback(struct urb *urb)
4390 static void hfa384x_usbout_callback(struct urb *urb, struct pt_regs *regs)
4393 wlandevice_t *wlandev = urb->context;
4394 hfa384x_usbout_t *usbout = urb->transfer_buffer;
4404 switch(urb->status) {
4406 hfa384x_usbout_tx(wlandev, usbout);
4411 hfa384x_t *hw = wlandev->priv;
4412 WLAN_LOG_WARNING("%s tx pipe stalled: requesting reset\n",
4413 wlandev->netdev->name);
4414 if ( !test_and_set_bit(WORK_TX_HALT, &hw->usb_flags) )
4415 schedule_work(&hw->usb_work);
4416 ++(wlandev->linux_stats.tx_errors);
4424 hfa384x_t *hw = wlandev->priv;
4426 if ( !test_and_set_bit(THROTTLE_TX, &hw->usb_flags)
4427 && !timer_pending(&hw->throttle) ) {
4428 mod_timer(&hw->throttle,
4429 jiffies + THROTTLE_JIFFIES);
4431 ++(wlandev->linux_stats.tx_errors);
4432 netif_stop_queue(wlandev->netdev);
4438 /* Ignorable errors */
4442 WLAN_LOG_INFO("unknown urb->status=%d\n", urb->status);
4443 ++(wlandev->linux_stats.tx_errors);
4452 /*----------------------------------------------------------------
4453 * hfa384x_ctlxout_callback
4455 * Callback for control data on the BULKOUT endpoint.
4458 * urb ptr to the completed urb
4467 ----------------------------------------------------------------*/
4468 #ifdef URB_ONLY_CALLBACK
4469 static void hfa384x_ctlxout_callback(struct urb *urb)
4471 static void hfa384x_ctlxout_callback(struct urb *urb, struct pt_regs *regs)
4474 hfa384x_t *hw = urb->context;
4475 int delete_resptimer = 0;
4478 hfa384x_usbctlx_t *ctlx;
4479 unsigned long flags;
4483 WLAN_LOG_DEBUG(3,"urb->status=%d\n", urb->status);
4487 if ( (urb->status == -ESHUTDOWN) ||
4488 (urb->status == -ENODEV) ||
4493 spin_lock_irqsave(&hw->ctlxq.lock, flags);
4496 * Only one CTLX at a time on the "active" list, and
4497 * none at all if we are unplugged. However, we can
4498 * rely on the disconnect function to clean everything
4499 * up if someone unplugged the adapter.
4501 if ( list_empty(&hw->ctlxq.active) ) {
4502 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
4507 * Having something on the "active" queue means
4508 * that we have timers to worry about ...
4510 if (del_timer(&hw->reqtimer) == 0) {
4511 if (hw->req_timer_done == 0) {
4513 * This timer was actually running while we
4514 * were trying to delete it. Let it terminate
4515 * gracefully instead.
4517 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
4522 hw->req_timer_done = 1;
4525 ctlx = get_active_ctlx(hw);
4527 if ( urb->status == 0 ) {
4528 /* Request portion of a CTLX is successful */
4529 switch ( ctlx->state ) {
4530 case CTLX_REQ_SUBMITTED:
4531 /* This OUT-ACK received before IN */
4532 ctlx->state = CTLX_REQ_COMPLETE;
4535 case CTLX_RESP_COMPLETE:
4536 /* IN already received before this OUT-ACK,
4537 * so this command must now be complete.
4539 ctlx->state = CTLX_COMPLETE;
4540 unlocked_usbctlx_complete(hw, ctlx);
4545 /* This is NOT a valid CTLX "success" state! */
4547 "Illegal CTLX[%d] success state(%s, %d) in OUT URB\n",
4548 hfa384x2host_16(ctlx->outbuf.type),
4549 ctlxstr(ctlx->state), urb->status);
4553 /* If the pipe has stalled then we need to reset it */
4554 if ( (urb->status == -EPIPE) &&
4555 !test_and_set_bit(WORK_TX_HALT, &hw->usb_flags) ) {
4556 WLAN_LOG_WARNING("%s tx pipe stalled: requesting reset\n",
4557 hw->wlandev->netdev->name);
4558 schedule_work(&hw->usb_work);
4561 /* If someone cancels the OUT URB then its status
4562 * should be either -ECONNRESET or -ENOENT.
4564 ctlx->state = CTLX_REQ_FAILED;
4565 unlocked_usbctlx_complete(hw, ctlx);
4566 delete_resptimer = 1;
4571 if (delete_resptimer) {
4572 if ((timer_ok = del_timer(&hw->resptimer)) != 0) {
4573 hw->resp_timer_done = 1;
4577 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
4579 if ( !timer_ok && (hw->resp_timer_done == 0) ) {
4580 spin_lock_irqsave(&hw->ctlxq.lock, flags);
4585 hfa384x_usbctlxq_run(hw);
4592 /*----------------------------------------------------------------
4593 * hfa384x_usbctlx_reqtimerfn
4595 * Timer response function for CTLX request timeouts. If this
4596 * function is called, it means that the callback for the OUT
4597 * URB containing a Prism2.x XXX_Request was never called.
4600 * data a ptr to the hfa384x_t
4609 ----------------------------------------------------------------*/
4611 hfa384x_usbctlx_reqtimerfn(unsigned long data)
4613 hfa384x_t *hw = (hfa384x_t*)data;
4614 unsigned long flags;
4617 spin_lock_irqsave(&hw->ctlxq.lock, flags);
4619 hw->req_timer_done = 1;
4621 /* Removing the hardware automatically empties
4622 * the active list ...
4624 if ( !list_empty(&hw->ctlxq.active) )
4627 * We must ensure that our URB is removed from
4628 * the system, if it hasn't already expired.
4630 hw->ctlx_urb.transfer_flags |= URB_ASYNC_UNLINK;
4631 if (usb_unlink_urb(&hw->ctlx_urb) == -EINPROGRESS)
4633 hfa384x_usbctlx_t *ctlx = get_active_ctlx(hw);
4635 ctlx->state = CTLX_REQ_FAILED;
4637 /* This URB was active, but has now been
4638 * cancelled. It will now have a status of
4639 * -ECONNRESET in the callback function.
4641 * We are cancelling this CTLX, so we're
4642 * not going to need to wait for a response.
4643 * The URB's callback function will check
4644 * that this timer is truly dead.
4646 if (del_timer(&hw->resptimer) != 0)
4647 hw->resp_timer_done = 1;
4651 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
4657 /*----------------------------------------------------------------
4658 * hfa384x_usbctlx_resptimerfn
4660 * Timer response function for CTLX response timeouts. If this
4661 * function is called, it means that the callback for the IN
4662 * URB containing a Prism2.x XXX_Response was never called.
4665 * data a ptr to the hfa384x_t
4674 ----------------------------------------------------------------*/
4676 hfa384x_usbctlx_resptimerfn(unsigned long data)
4678 hfa384x_t *hw = (hfa384x_t*)data;
4679 unsigned long flags;
4683 spin_lock_irqsave(&hw->ctlxq.lock, flags);
4685 hw->resp_timer_done = 1;
4687 /* The active list will be empty if the
4688 * adapter has been unplugged ...
4690 if ( !list_empty(&hw->ctlxq.active) )
4692 hfa384x_usbctlx_t *ctlx = get_active_ctlx(hw);
4694 if ( unlocked_usbctlx_cancel_async(hw, ctlx) == 0 )
4696 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
4697 hfa384x_usbctlxq_run(hw);
4702 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
4708 /*----------------------------------------------------------------
4709 * hfa384x_usb_throttlefn
4722 ----------------------------------------------------------------*/
4724 hfa384x_usb_throttlefn(unsigned long data)
4726 hfa384x_t *hw = (hfa384x_t*)data;
4727 unsigned long flags;
4731 spin_lock_irqsave(&hw->ctlxq.lock, flags);
4734 * We need to check BOTH the RX and the TX throttle controls,
4735 * so we use the bitwise OR instead of the logical OR.
4737 WLAN_LOG_DEBUG(3, "flags=0x%lx\n", hw->usb_flags);
4738 if ( !hw->wlandev->hwremoved &&
4740 (test_and_clear_bit(THROTTLE_RX, &hw->usb_flags) &&
4741 !test_and_set_bit(WORK_RX_RESUME, &hw->usb_flags))
4743 (test_and_clear_bit(THROTTLE_TX, &hw->usb_flags) &&
4744 !test_and_set_bit(WORK_TX_RESUME, &hw->usb_flags))
4747 schedule_work(&hw->usb_work);
4750 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
4756 /*----------------------------------------------------------------
4757 * hfa384x_usbctlx_submit
4759 * Called from the doxxx functions to submit a CTLX to the queue
4762 * hw ptr to the hw struct
4763 * ctlx ctlx structure to enqueue
4766 * -ENODEV if the adapter is unplugged
4772 * process or interrupt
4773 ----------------------------------------------------------------*/
4775 hfa384x_usbctlx_submit(
4777 hfa384x_usbctlx_t *ctlx)
4779 unsigned long flags;
4784 spin_lock_irqsave(&hw->ctlxq.lock, flags);
4786 if (hw->wlandev->hwremoved) {
4787 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
4790 ctlx->state = CTLX_PENDING;
4791 list_add_tail(&ctlx->list, &hw->ctlxq.pending);
4793 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
4794 hfa384x_usbctlxq_run(hw);
4803 /*----------------------------------------------------------------
4806 * At this point we have finished a send of a frame. Mark the URB
4807 * as available and call ev_alloc to notify higher layers we're
4811 * wlandev wlan device
4812 * usbout ptr to the usb transfer buffer
4821 ----------------------------------------------------------------*/
4822 static void hfa384x_usbout_tx(wlandevice_t *wlandev, hfa384x_usbout_t *usbout)
4826 prism2sta_ev_alloc(wlandev);
4831 /*----------------------------------------------------------------
4832 * hfa384x_isgood_pdrcore
4834 * Quick check of PDR codes.
4837 * pdrcode PDR code number (host order)
4846 ----------------------------------------------------------------*/
4848 hfa384x_isgood_pdrcode(UINT16 pdrcode)
4851 case HFA384x_PDR_END_OF_PDA:
4852 case HFA384x_PDR_PCB_PARTNUM:
4853 case HFA384x_PDR_PDAVER:
4854 case HFA384x_PDR_NIC_SERIAL:
4855 case HFA384x_PDR_MKK_MEASUREMENTS:
4856 case HFA384x_PDR_NIC_RAMSIZE:
4857 case HFA384x_PDR_MFISUPRANGE:
4858 case HFA384x_PDR_CFISUPRANGE:
4859 case HFA384x_PDR_NICID:
4860 case HFA384x_PDR_MAC_ADDRESS:
4861 case HFA384x_PDR_REGDOMAIN:
4862 case HFA384x_PDR_ALLOWED_CHANNEL:
4863 case HFA384x_PDR_DEFAULT_CHANNEL:
4864 case HFA384x_PDR_TEMPTYPE:
4865 case HFA384x_PDR_IFR_SETTING:
4866 case HFA384x_PDR_RFR_SETTING:
4867 case HFA384x_PDR_HFA3861_BASELINE:
4868 case HFA384x_PDR_HFA3861_SHADOW:
4869 case HFA384x_PDR_HFA3861_IFRF:
4870 case HFA384x_PDR_HFA3861_CHCALSP:
4871 case HFA384x_PDR_HFA3861_CHCALI:
4872 case HFA384x_PDR_3842_NIC_CONFIG:
4873 case HFA384x_PDR_USB_ID:
4874 case HFA384x_PDR_PCI_ID:
4875 case HFA384x_PDR_PCI_IFCONF:
4876 case HFA384x_PDR_PCI_PMCONF:
4877 case HFA384x_PDR_RFENRGY:
4878 case HFA384x_PDR_HFA3861_MANF_TESTSP:
4879 case HFA384x_PDR_HFA3861_MANF_TESTI:
4884 if ( pdrcode < 0x1000 ) {
4885 /* code is OK, but we don't know exactly what it is */
4887 "Encountered unknown PDR#=0x%04x, "
4888 "assuming it's ok.\n",
4894 "Encountered unknown PDR#=0x%04x, "
4895 "(>=0x1000), assuming it's bad.\n",
4901 return 0; /* avoid compiler warnings */