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 #include <linux/version.h>
115 #include <linux/module.h>
116 #include <linux/kernel.h>
117 #include <linux/sched.h>
118 #include <linux/types.h>
119 #include <linux/slab.h>
120 #include <linux/wireless.h>
121 #include <linux/netdevice.h>
122 #include <linux/timer.h>
124 #include <linux/delay.h>
125 #include <asm/byteorder.h>
126 #include <asm/bitops.h>
127 #include <linux/list.h>
128 #include <linux/usb.h>
129 #include <linux/byteorder/generic.h>
131 #define SUBMIT_URB(u,f) usb_submit_urb(u,f)
133 /*================================================================*/
134 /* Project Includes */
136 #include "p80211types.h"
137 #include "p80211hdr.h"
138 #include "p80211mgmt.h"
139 #include "p80211conv.h"
140 #include "p80211msg.h"
141 #include "p80211netdev.h"
142 #include "p80211req.h"
143 #include "p80211metadef.h"
144 #include "p80211metastruct.h"
146 #include "prism2mgmt.h"
152 typedef enum cmd_mode CMD_MODE;
154 #define THROTTLE_JIFFIES (HZ/8)
155 #define URB_ASYNC_UNLINK 0
156 #define USB_QUEUE_BULK 0
158 #define ROUNDUP64(a) (((a)+63)&~63)
161 static void dbprint_urb(struct urb *urb);
165 hfa384x_int_rxmonitor(wlandevice_t *wlandev, hfa384x_usb_rxfrm_t *rxfrm);
167 static void hfa384x_usb_defer(struct work_struct *data);
169 static int submit_rx_urb(hfa384x_t *hw, gfp_t flags);
171 static int submit_tx_urb(hfa384x_t *hw, struct urb *tx_urb, gfp_t flags);
173 /*---------------------------------------------------*/
175 static void hfa384x_usbout_callback(struct urb *urb);
176 static void hfa384x_ctlxout_callback(struct urb *urb);
177 static void hfa384x_usbin_callback(struct urb *urb);
180 hfa384x_usbin_txcompl(wlandevice_t *wlandev, hfa384x_usbin_t *usbin);
182 static void hfa384x_usbin_rx(wlandevice_t *wlandev, struct sk_buff *skb);
184 static void hfa384x_usbin_info(wlandevice_t *wlandev, hfa384x_usbin_t *usbin);
187 hfa384x_usbout_tx(wlandevice_t *wlandev, hfa384x_usbout_t *usbout);
189 static void hfa384x_usbin_ctlx(hfa384x_t *hw, hfa384x_usbin_t *usbin,
192 /*---------------------------------------------------*/
193 /* Functions to support the prism2 usb command queue */
195 static void hfa384x_usbctlxq_run(hfa384x_t *hw);
197 static void hfa384x_usbctlx_reqtimerfn(unsigned long data);
199 static void hfa384x_usbctlx_resptimerfn(unsigned long data);
201 static void hfa384x_usb_throttlefn(unsigned long data);
203 static void hfa384x_usbctlx_completion_task(unsigned long data);
205 static void hfa384x_usbctlx_reaper_task(unsigned long data);
207 static int hfa384x_usbctlx_submit(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
209 static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
211 struct usbctlx_completor {
212 int (*complete) (struct usbctlx_completor *);
214 typedef struct usbctlx_completor usbctlx_completor_t;
217 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
218 hfa384x_usbctlx_t *ctlx,
219 usbctlx_completor_t *completor);
222 unlocked_usbctlx_cancel_async(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
224 static void hfa384x_cb_status(hfa384x_t *hw, const hfa384x_usbctlx_t *ctlx);
226 static void hfa384x_cb_rrid(hfa384x_t *hw, const hfa384x_usbctlx_t *ctlx);
229 usbctlx_get_status(const hfa384x_usb_cmdresp_t *cmdresp,
230 hfa384x_cmdresult_t *result);
233 usbctlx_get_rridresult(const hfa384x_usb_rridresp_t *rridresp,
234 hfa384x_rridresult_t *result);
236 /*---------------------------------------------------*/
237 /* Low level req/resp CTLX formatters and submitters */
239 hfa384x_docmd(hfa384x_t *hw,
241 hfa384x_metacmd_t *cmd,
242 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
245 hfa384x_dorrid(hfa384x_t *hw,
249 unsigned int riddatalen,
250 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
253 hfa384x_dowrid(hfa384x_t *hw,
257 unsigned int riddatalen,
258 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
261 hfa384x_dormem(hfa384x_t *hw,
267 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
270 hfa384x_dowmem(hfa384x_t *hw,
276 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
278 static int hfa384x_isgood_pdrcode(u16 pdrcode);
280 static inline const char *ctlxstr(CTLX_STATE s)
282 static const char *ctlx_str[] = {
287 "Request packet submitted",
288 "Request packet completed",
289 "Response packet completed"
295 static inline hfa384x_usbctlx_t *get_active_ctlx(hfa384x_t *hw)
297 return list_entry(hw->ctlxq.active.next, hfa384x_usbctlx_t, list);
301 void dbprint_urb(struct urb *urb)
303 pr_debug("urb->pipe=0x%08x\n", urb->pipe);
304 pr_debug("urb->status=0x%08x\n", urb->status);
305 pr_debug("urb->transfer_flags=0x%08x\n", urb->transfer_flags);
306 pr_debug("urb->transfer_buffer=0x%08x\n",
307 (unsigned int)urb->transfer_buffer);
308 pr_debug("urb->transfer_buffer_length=0x%08x\n",
309 urb->transfer_buffer_length);
310 pr_debug("urb->actual_length=0x%08x\n", urb->actual_length);
311 pr_debug("urb->bandwidth=0x%08x\n", urb->bandwidth);
312 pr_debug("urb->setup_packet(ctl)=0x%08x\n",
313 (unsigned int)urb->setup_packet);
314 pr_debug("urb->start_frame(iso/irq)=0x%08x\n",
316 pr_debug("urb->interval(irq)=0x%08x\n", urb->interval);
317 pr_debug("urb->error_count(iso)=0x%08x\n", urb->error_count);
318 pr_debug("urb->timeout=0x%08x\n", urb->timeout);
319 pr_debug("urb->context=0x%08x\n", (unsigned int)urb->context);
320 pr_debug("urb->complete=0x%08x\n",
321 (unsigned int)urb->complete);
325 /*----------------------------------------------------------------
328 * Listen for input data on the BULK-IN pipe. If the pipe has
329 * stalled then schedule it to be reset.
333 * memflags memory allocation flags
336 * error code from submission
340 ----------------------------------------------------------------*/
341 static int submit_rx_urb(hfa384x_t *hw, gfp_t memflags)
346 skb = dev_alloc_skb(sizeof(hfa384x_usbin_t));
352 /* Post the IN urb */
353 usb_fill_bulk_urb(&hw->rx_urb, hw->usb,
355 skb->data, sizeof(hfa384x_usbin_t),
356 hfa384x_usbin_callback, hw->wlandev);
358 hw->rx_urb_skb = skb;
361 if (!hw->wlandev->hwremoved && !test_bit(WORK_RX_HALT, &hw->usb_flags)) {
362 result = SUBMIT_URB(&hw->rx_urb, memflags);
364 /* Check whether we need to reset the RX pipe */
365 if (result == -EPIPE) {
367 "%s rx pipe stalled: requesting reset\n",
368 hw->wlandev->netdev->name);
369 if (!test_and_set_bit(WORK_RX_HALT, &hw->usb_flags))
370 schedule_work(&hw->usb_work);
374 /* Don't leak memory if anything should go wrong */
377 hw->rx_urb_skb = NULL;
384 /*----------------------------------------------------------------
387 * Prepares and submits the URB of transmitted data. If the
388 * submission fails then it will schedule the output pipe to
393 * tx_urb URB of data for tranmission
394 * memflags memory allocation flags
397 * error code from submission
401 ----------------------------------------------------------------*/
402 static int submit_tx_urb(hfa384x_t *hw, struct urb *tx_urb, gfp_t memflags)
404 struct net_device *netdev = hw->wlandev->netdev;
408 if (netif_running(netdev)) {
410 if (!hw->wlandev->hwremoved
411 && !test_bit(WORK_TX_HALT, &hw->usb_flags)) {
412 result = SUBMIT_URB(tx_urb, memflags);
414 /* Test whether we need to reset the TX pipe */
415 if (result == -EPIPE) {
417 "%s tx pipe stalled: requesting reset\n",
419 set_bit(WORK_TX_HALT, &hw->usb_flags);
420 schedule_work(&hw->usb_work);
421 } else if (result == 0) {
422 netif_stop_queue(netdev);
430 /*----------------------------------------------------------------
433 * There are some things that the USB stack cannot do while
434 * in interrupt context, so we arrange this function to run
435 * in process context.
438 * hw device structure
444 * process (by design)
445 ----------------------------------------------------------------*/
446 static void hfa384x_usb_defer(struct work_struct *data)
448 hfa384x_t *hw = container_of(data, struct hfa384x, usb_work);
449 struct net_device *netdev = hw->wlandev->netdev;
451 /* Don't bother trying to reset anything if the plug
452 * has been pulled ...
454 if (hw->wlandev->hwremoved)
457 /* Reception has stopped: try to reset the input pipe */
458 if (test_bit(WORK_RX_HALT, &hw->usb_flags)) {
461 usb_kill_urb(&hw->rx_urb); /* Cannot be holding spinlock! */
463 ret = usb_clear_halt(hw->usb, hw->endp_in);
466 "Failed to clear rx pipe for %s: err=%d\n",
469 printk(KERN_INFO "%s rx pipe reset complete.\n",
471 clear_bit(WORK_RX_HALT, &hw->usb_flags);
472 set_bit(WORK_RX_RESUME, &hw->usb_flags);
476 /* Resume receiving data back from the device. */
477 if (test_bit(WORK_RX_RESUME, &hw->usb_flags)) {
480 ret = submit_rx_urb(hw, GFP_KERNEL);
483 "Failed to resume %s rx pipe.\n", netdev->name);
485 clear_bit(WORK_RX_RESUME, &hw->usb_flags);
489 /* Transmission has stopped: try to reset the output pipe */
490 if (test_bit(WORK_TX_HALT, &hw->usb_flags)) {
493 usb_kill_urb(&hw->tx_urb);
494 ret = usb_clear_halt(hw->usb, hw->endp_out);
497 "Failed to clear tx pipe for %s: err=%d\n",
500 printk(KERN_INFO "%s tx pipe reset complete.\n",
502 clear_bit(WORK_TX_HALT, &hw->usb_flags);
503 set_bit(WORK_TX_RESUME, &hw->usb_flags);
505 /* Stopping the BULK-OUT pipe also blocked
506 * us from sending any more CTLX URBs, so
507 * we need to re-run our queue ...
509 hfa384x_usbctlxq_run(hw);
513 /* Resume transmitting. */
514 if (test_and_clear_bit(WORK_TX_RESUME, &hw->usb_flags))
515 netif_wake_queue(hw->wlandev->netdev);
518 /*----------------------------------------------------------------
521 * Sets up the hfa384x_t data structure for use. Note this
522 * does _not_ intialize the actual hardware, just the data structures
523 * we use to keep track of its state.
526 * hw device structure
527 * irq device irq number
528 * iobase i/o base address for register access
529 * membase memory base address for register access
538 ----------------------------------------------------------------*/
539 void hfa384x_create(hfa384x_t *hw, struct usb_device *usb)
541 memset(hw, 0, sizeof(hfa384x_t));
544 /* set up the endpoints */
545 hw->endp_in = usb_rcvbulkpipe(usb, 1);
546 hw->endp_out = usb_sndbulkpipe(usb, 2);
548 /* Set up the waitq */
549 init_waitqueue_head(&hw->cmdq);
551 /* Initialize the command queue */
552 spin_lock_init(&hw->ctlxq.lock);
553 INIT_LIST_HEAD(&hw->ctlxq.pending);
554 INIT_LIST_HEAD(&hw->ctlxq.active);
555 INIT_LIST_HEAD(&hw->ctlxq.completing);
556 INIT_LIST_HEAD(&hw->ctlxq.reapable);
558 /* Initialize the authentication queue */
559 skb_queue_head_init(&hw->authq);
561 tasklet_init(&hw->reaper_bh,
562 hfa384x_usbctlx_reaper_task, (unsigned long)hw);
563 tasklet_init(&hw->completion_bh,
564 hfa384x_usbctlx_completion_task, (unsigned long)hw);
565 INIT_WORK(&hw->link_bh, prism2sta_processing_defer);
566 INIT_WORK(&hw->usb_work, hfa384x_usb_defer);
568 init_timer(&hw->throttle);
569 hw->throttle.function = hfa384x_usb_throttlefn;
570 hw->throttle.data = (unsigned long)hw;
572 init_timer(&hw->resptimer);
573 hw->resptimer.function = hfa384x_usbctlx_resptimerfn;
574 hw->resptimer.data = (unsigned long)hw;
576 init_timer(&hw->reqtimer);
577 hw->reqtimer.function = hfa384x_usbctlx_reqtimerfn;
578 hw->reqtimer.data = (unsigned long)hw;
580 usb_init_urb(&hw->rx_urb);
581 usb_init_urb(&hw->tx_urb);
582 usb_init_urb(&hw->ctlx_urb);
584 hw->link_status = HFA384x_LINK_NOTCONNECTED;
585 hw->state = HFA384x_STATE_INIT;
587 INIT_WORK(&hw->commsqual_bh, prism2sta_commsqual_defer);
588 init_timer(&hw->commsqual_timer);
589 hw->commsqual_timer.data = (unsigned long)hw;
590 hw->commsqual_timer.function = prism2sta_commsqual_timer;
593 /*----------------------------------------------------------------
596 * Partner to hfa384x_create(). This function cleans up the hw
597 * structure so that it can be freed by the caller using a simple
598 * kfree. Currently, this function is just a placeholder. If, at some
599 * point in the future, an hw in the 'shutdown' state requires a 'deep'
600 * kfree, this is where it should be done. Note that if this function
601 * is called on a _running_ hw structure, the drvr_stop() function is
605 * hw device structure
608 * nothing, this function is not allowed to fail.
614 ----------------------------------------------------------------*/
615 void hfa384x_destroy(hfa384x_t *hw)
619 if (hw->state == HFA384x_STATE_RUNNING)
620 hfa384x_drvr_stop(hw);
621 hw->state = HFA384x_STATE_PREINIT;
623 if (hw->scanresults) {
624 kfree(hw->scanresults);
625 hw->scanresults = NULL;
628 /* Now to clean out the auth queue */
629 while ((skb = skb_dequeue(&hw->authq)))
633 static hfa384x_usbctlx_t *usbctlx_alloc(void)
635 hfa384x_usbctlx_t *ctlx;
637 ctlx = kmalloc(sizeof(*ctlx), in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
639 memset(ctlx, 0, sizeof(*ctlx));
640 init_completion(&ctlx->done);
647 usbctlx_get_status(const hfa384x_usb_cmdresp_t *cmdresp,
648 hfa384x_cmdresult_t *result)
650 result->status = le16_to_cpu(cmdresp->status);
651 result->resp0 = le16_to_cpu(cmdresp->resp0);
652 result->resp1 = le16_to_cpu(cmdresp->resp1);
653 result->resp2 = le16_to_cpu(cmdresp->resp2);
655 pr_debug("cmdresult:status=0x%04x "
656 "resp0=0x%04x resp1=0x%04x resp2=0x%04x\n",
657 result->status, result->resp0, result->resp1, result->resp2);
659 return result->status & HFA384x_STATUS_RESULT;
663 usbctlx_get_rridresult(const hfa384x_usb_rridresp_t *rridresp,
664 hfa384x_rridresult_t *result)
666 result->rid = le16_to_cpu(rridresp->rid);
667 result->riddata = rridresp->data;
668 result->riddata_len = ((le16_to_cpu(rridresp->frmlen) - 1) * 2);
672 /*----------------------------------------------------------------
674 * This completor must be passed to hfa384x_usbctlx_complete_sync()
675 * when processing a CTLX that returns a hfa384x_cmdresult_t structure.
676 ----------------------------------------------------------------*/
677 struct usbctlx_cmd_completor {
678 usbctlx_completor_t head;
680 const hfa384x_usb_cmdresp_t *cmdresp;
681 hfa384x_cmdresult_t *result;
683 typedef struct usbctlx_cmd_completor usbctlx_cmd_completor_t;
685 static int usbctlx_cmd_completor_fn(usbctlx_completor_t *head)
687 usbctlx_cmd_completor_t *complete = (usbctlx_cmd_completor_t *) head;
688 return usbctlx_get_status(complete->cmdresp, complete->result);
691 static inline usbctlx_completor_t *init_cmd_completor(usbctlx_cmd_completor_t *
694 hfa384x_usb_cmdresp_t *
696 hfa384x_cmdresult_t *
699 completor->head.complete = usbctlx_cmd_completor_fn;
700 completor->cmdresp = cmdresp;
701 completor->result = result;
702 return &(completor->head);
705 /*----------------------------------------------------------------
707 * This completor must be passed to hfa384x_usbctlx_complete_sync()
708 * when processing a CTLX that reads a RID.
709 ----------------------------------------------------------------*/
710 struct usbctlx_rrid_completor {
711 usbctlx_completor_t head;
713 const hfa384x_usb_rridresp_t *rridresp;
715 unsigned int riddatalen;
717 typedef struct usbctlx_rrid_completor usbctlx_rrid_completor_t;
719 static int usbctlx_rrid_completor_fn(usbctlx_completor_t *head)
721 usbctlx_rrid_completor_t *complete = (usbctlx_rrid_completor_t *) head;
722 hfa384x_rridresult_t rridresult;
724 usbctlx_get_rridresult(complete->rridresp, &rridresult);
726 /* Validate the length, note body len calculation in bytes */
727 if (rridresult.riddata_len != complete->riddatalen) {
729 "RID len mismatch, rid=0x%04x hlen=%d fwlen=%d\n",
731 complete->riddatalen, rridresult.riddata_len);
735 memcpy(complete->riddata, rridresult.riddata, complete->riddatalen);
739 static inline usbctlx_completor_t *init_rrid_completor(usbctlx_rrid_completor_t
742 hfa384x_usb_rridresp_t *
743 rridresp, void *riddata,
744 unsigned int riddatalen)
746 completor->head.complete = usbctlx_rrid_completor_fn;
747 completor->rridresp = rridresp;
748 completor->riddata = riddata;
749 completor->riddatalen = riddatalen;
750 return &(completor->head);
753 /*----------------------------------------------------------------
755 * Interprets the results of a synchronous RID-write
756 ----------------------------------------------------------------*/
757 typedef usbctlx_cmd_completor_t usbctlx_wrid_completor_t;
758 #define init_wrid_completor init_cmd_completor
760 /*----------------------------------------------------------------
762 * Interprets the results of a synchronous memory-write
763 ----------------------------------------------------------------*/
764 typedef usbctlx_cmd_completor_t usbctlx_wmem_completor_t;
765 #define init_wmem_completor init_cmd_completor
767 /*----------------------------------------------------------------
769 * Interprets the results of a synchronous memory-read
770 ----------------------------------------------------------------*/
771 struct usbctlx_rmem_completor {
772 usbctlx_completor_t head;
774 const hfa384x_usb_rmemresp_t *rmemresp;
778 typedef struct usbctlx_rmem_completor usbctlx_rmem_completor_t;
780 static int usbctlx_rmem_completor_fn(usbctlx_completor_t *head)
782 usbctlx_rmem_completor_t *complete = (usbctlx_rmem_completor_t *) head;
784 pr_debug("rmemresp:len=%d\n", complete->rmemresp->frmlen);
785 memcpy(complete->data, complete->rmemresp->data, complete->len);
789 static inline usbctlx_completor_t *init_rmem_completor(usbctlx_rmem_completor_t
791 hfa384x_usb_rmemresp_t
792 *rmemresp, void *data,
795 completor->head.complete = usbctlx_rmem_completor_fn;
796 completor->rmemresp = rmemresp;
797 completor->data = data;
798 completor->len = len;
799 return &(completor->head);
802 /*----------------------------------------------------------------
805 * Ctlx_complete handler for async CMD type control exchanges.
806 * mark the hw struct as such.
808 * Note: If the handling is changed here, it should probably be
809 * changed in docmd as well.
813 * ctlx completed CTLX
822 ----------------------------------------------------------------*/
823 static void hfa384x_cb_status(hfa384x_t *hw, const hfa384x_usbctlx_t *ctlx)
825 if (ctlx->usercb != NULL) {
826 hfa384x_cmdresult_t cmdresult;
828 if (ctlx->state != CTLX_COMPLETE) {
829 memset(&cmdresult, 0, sizeof(cmdresult));
831 HFA384x_STATUS_RESULT_SET(HFA384x_CMD_ERR);
833 usbctlx_get_status(&ctlx->inbuf.cmdresp, &cmdresult);
836 ctlx->usercb(hw, &cmdresult, ctlx->usercb_data);
840 /*----------------------------------------------------------------
843 * CTLX completion handler for async RRID type control exchanges.
845 * Note: If the handling is changed here, it should probably be
846 * changed in dorrid as well.
850 * ctlx completed CTLX
859 ----------------------------------------------------------------*/
860 static void hfa384x_cb_rrid(hfa384x_t *hw, const hfa384x_usbctlx_t *ctlx)
862 if (ctlx->usercb != NULL) {
863 hfa384x_rridresult_t rridresult;
865 if (ctlx->state != CTLX_COMPLETE) {
866 memset(&rridresult, 0, sizeof(rridresult));
868 le16_to_cpu(ctlx->outbuf.rridreq.rid);
870 usbctlx_get_rridresult(&ctlx->inbuf.rridresp,
874 ctlx->usercb(hw, &rridresult, ctlx->usercb_data);
878 static inline int hfa384x_docmd_wait(hfa384x_t *hw, hfa384x_metacmd_t *cmd)
880 return hfa384x_docmd(hw, DOWAIT, cmd, NULL, NULL, NULL);
884 hfa384x_docmd_async(hfa384x_t *hw,
885 hfa384x_metacmd_t *cmd,
886 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
888 return hfa384x_docmd(hw, DOASYNC, cmd, cmdcb, usercb, usercb_data);
892 hfa384x_dorrid_wait(hfa384x_t *hw, u16 rid, void *riddata,
893 unsigned int riddatalen)
895 return hfa384x_dorrid(hw, DOWAIT,
896 rid, riddata, riddatalen, NULL, NULL, NULL);
900 hfa384x_dorrid_async(hfa384x_t *hw,
901 u16 rid, void *riddata, unsigned int riddatalen,
903 ctlx_usercb_t usercb, void *usercb_data)
905 return hfa384x_dorrid(hw, DOASYNC,
906 rid, riddata, riddatalen,
907 cmdcb, usercb, usercb_data);
911 hfa384x_dowrid_wait(hfa384x_t *hw, u16 rid, void *riddata,
912 unsigned int riddatalen)
914 return hfa384x_dowrid(hw, DOWAIT,
915 rid, riddata, riddatalen, NULL, NULL, NULL);
919 hfa384x_dowrid_async(hfa384x_t *hw,
920 u16 rid, void *riddata, unsigned int riddatalen,
922 ctlx_usercb_t usercb, void *usercb_data)
924 return hfa384x_dowrid(hw, DOASYNC,
925 rid, riddata, riddatalen,
926 cmdcb, usercb, usercb_data);
930 hfa384x_dormem_wait(hfa384x_t *hw,
931 u16 page, u16 offset, void *data, unsigned int len)
933 return hfa384x_dormem(hw, DOWAIT,
934 page, offset, data, len, NULL, NULL, NULL);
938 hfa384x_dormem_async(hfa384x_t *hw,
939 u16 page, u16 offset, void *data, unsigned int len,
941 ctlx_usercb_t usercb, void *usercb_data)
943 return hfa384x_dormem(hw, DOASYNC,
944 page, offset, data, len,
945 cmdcb, usercb, usercb_data);
949 hfa384x_dowmem_wait(hfa384x_t *hw,
950 u16 page, u16 offset, void *data, unsigned int len)
952 return hfa384x_dowmem(hw, DOWAIT,
953 page, offset, data, len, NULL, NULL, NULL);
957 hfa384x_dowmem_async(hfa384x_t *hw,
963 ctlx_usercb_t usercb, void *usercb_data)
965 return hfa384x_dowmem(hw, DOASYNC,
966 page, offset, data, len,
967 cmdcb, usercb, usercb_data);
970 /*----------------------------------------------------------------
971 * hfa384x_cmd_initialize
973 * Issues the initialize command and sets the hw->state based
977 * hw device structure
981 * >0 f/w reported error - f/w status code
982 * <0 driver reported error
988 ----------------------------------------------------------------*/
989 int hfa384x_cmd_initialize(hfa384x_t *hw)
993 hfa384x_metacmd_t cmd;
995 cmd.cmd = HFA384x_CMDCODE_INIT;
1000 result = hfa384x_docmd_wait(hw, &cmd);
1002 pr_debug("cmdresp.init: "
1003 "status=0x%04x, resp0=0x%04x, "
1004 "resp1=0x%04x, resp2=0x%04x\n",
1006 cmd.result.resp0, cmd.result.resp1, cmd.result.resp2);
1008 for (i = 0; i < HFA384x_NUMPORTS_MAX; i++)
1009 hw->port_enabled[i] = 0;
1012 hw->link_status = HFA384x_LINK_NOTCONNECTED;
1017 /*----------------------------------------------------------------
1018 * hfa384x_cmd_disable
1020 * Issues the disable command to stop communications on one of
1024 * hw device structure
1025 * macport MAC port number (host order)
1029 * >0 f/w reported failure - f/w status code
1030 * <0 driver reported error (timeout|bad arg)
1036 ----------------------------------------------------------------*/
1037 int hfa384x_cmd_disable(hfa384x_t *hw, u16 macport)
1040 hfa384x_metacmd_t cmd;
1042 cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_DISABLE) |
1043 HFA384x_CMD_MACPORT_SET(macport);
1048 result = hfa384x_docmd_wait(hw, &cmd);
1053 /*----------------------------------------------------------------
1054 * hfa384x_cmd_enable
1056 * Issues the enable command to enable communications on one of
1060 * hw device structure
1061 * macport MAC port number
1065 * >0 f/w reported failure - f/w status code
1066 * <0 driver reported error (timeout|bad arg)
1072 ----------------------------------------------------------------*/
1073 int hfa384x_cmd_enable(hfa384x_t *hw, u16 macport)
1076 hfa384x_metacmd_t cmd;
1078 cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_ENABLE) |
1079 HFA384x_CMD_MACPORT_SET(macport);
1084 result = hfa384x_docmd_wait(hw, &cmd);
1089 /*----------------------------------------------------------------
1090 * hfa384x_cmd_monitor
1092 * Enables the 'monitor mode' of the MAC. Here's the description of
1093 * monitor mode that I've received thus far:
1095 * "The "monitor mode" of operation is that the MAC passes all
1096 * frames for which the PLCP checks are correct. All received
1097 * MPDUs are passed to the host with MAC Port = 7, with a
1098 * receive status of good, FCS error, or undecryptable. Passing
1099 * certain MPDUs is a violation of the 802.11 standard, but useful
1100 * for a debugging tool." Normal communication is not possible
1101 * while monitor mode is enabled.
1104 * hw device structure
1105 * enable a code (0x0b|0x0f) that enables/disables
1106 * monitor mode. (host order)
1110 * >0 f/w reported failure - f/w status code
1111 * <0 driver reported error (timeout|bad arg)
1117 ----------------------------------------------------------------*/
1118 int hfa384x_cmd_monitor(hfa384x_t *hw, u16 enable)
1121 hfa384x_metacmd_t cmd;
1123 cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_MONITOR) |
1124 HFA384x_CMD_AINFO_SET(enable);
1129 result = hfa384x_docmd_wait(hw, &cmd);
1134 /*----------------------------------------------------------------
1135 * hfa384x_cmd_download
1137 * Sets the controls for the MAC controller code/data download
1138 * process. The arguments set the mode and address associated
1139 * with a download. Note that the aux registers should be enabled
1140 * prior to setting one of the download enable modes.
1143 * hw device structure
1144 * mode 0 - Disable programming and begin code exec
1145 * 1 - Enable volatile mem programming
1146 * 2 - Enable non-volatile mem programming
1147 * 3 - Program non-volatile section from NV download
1151 * highaddr For mode 1, sets the high & low order bits of
1152 * the "destination address". This address will be
1153 * the execution start address when download is
1154 * subsequently disabled.
1155 * For mode 2, sets the high & low order bits of
1156 * the destination in NV ram.
1157 * For modes 0 & 3, should be zero. (host order)
1158 * NOTE: these are CMD format.
1159 * codelen Length of the data to write in mode 2,
1160 * zero otherwise. (host order)
1164 * >0 f/w reported failure - f/w status code
1165 * <0 driver reported error (timeout|bad arg)
1171 ----------------------------------------------------------------*/
1172 int hfa384x_cmd_download(hfa384x_t *hw, u16 mode, u16 lowaddr,
1173 u16 highaddr, u16 codelen)
1176 hfa384x_metacmd_t cmd;
1179 "mode=%d, lowaddr=0x%04x, highaddr=0x%04x, codelen=%d\n",
1180 mode, lowaddr, highaddr, codelen);
1182 cmd.cmd = (HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_DOWNLD) |
1183 HFA384x_CMD_PROGMODE_SET(mode));
1185 cmd.parm0 = lowaddr;
1186 cmd.parm1 = highaddr;
1187 cmd.parm2 = codelen;
1189 result = hfa384x_docmd_wait(hw, &cmd);
1194 /*----------------------------------------------------------------
1197 * Perform a reset of the hfa38xx MAC core. We assume that the hw
1198 * structure is in its "created" state. That is, it is initialized
1199 * with proper values. Note that if a reset is done after the
1200 * device has been active for awhile, the caller might have to clean
1201 * up some leftover cruft in the hw structure.
1204 * hw device structure
1205 * holdtime how long (in ms) to hold the reset
1206 * settletime how long (in ms) to wait after releasing
1216 ----------------------------------------------------------------*/
1217 int hfa384x_corereset(hfa384x_t *hw, int holdtime, int settletime, int genesis)
1221 result = usb_reset_device(hw->usb);
1223 printk(KERN_ERR "usb_reset_device() failed, result=%d.\n",
1230 /*----------------------------------------------------------------
1231 * hfa384x_usbctlx_complete_sync
1233 * Waits for a synchronous CTLX object to complete,
1234 * and then handles the response.
1237 * hw device structure
1239 * completor functor object to decide what to
1240 * do with the CTLX's result.
1244 * -ERESTARTSYS Interrupted by a signal
1246 * -ENODEV Adapter was unplugged
1247 * ??? Result from completor
1253 ----------------------------------------------------------------*/
1254 static int hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
1255 hfa384x_usbctlx_t *ctlx,
1256 usbctlx_completor_t *completor)
1258 unsigned long flags;
1261 result = wait_for_completion_interruptible(&ctlx->done);
1263 spin_lock_irqsave(&hw->ctlxq.lock, flags);
1266 * We can only handle the CTLX if the USB disconnect
1267 * function has not run yet ...
1270 if (hw->wlandev->hwremoved) {
1271 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1273 } else if (result != 0) {
1277 * We were probably interrupted, so delete
1278 * this CTLX asynchronously, kill the timers
1279 * and the URB, and then start the next
1282 * NOTE: We can only delete the timers and
1283 * the URB if this CTLX is active.
1285 if (ctlx == get_active_ctlx(hw)) {
1286 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1288 del_singleshot_timer_sync(&hw->reqtimer);
1289 del_singleshot_timer_sync(&hw->resptimer);
1290 hw->req_timer_done = 1;
1291 hw->resp_timer_done = 1;
1292 usb_kill_urb(&hw->ctlx_urb);
1294 spin_lock_irqsave(&hw->ctlxq.lock, flags);
1299 * This scenario is so unlikely that I'm
1300 * happy with a grubby "goto" solution ...
1302 if (hw->wlandev->hwremoved)
1307 * The completion task will send this CTLX
1308 * to the reaper the next time it runs. We
1309 * are no longer in a hurry.
1312 ctlx->state = CTLX_REQ_FAILED;
1313 list_move_tail(&ctlx->list, &hw->ctlxq.completing);
1315 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1318 hfa384x_usbctlxq_run(hw);
1320 if (ctlx->state == CTLX_COMPLETE) {
1321 result = completor->complete(completor);
1323 printk(KERN_WARNING "CTLX[%d] error: state(%s)\n",
1324 le16_to_cpu(ctlx->outbuf.type),
1325 ctlxstr(ctlx->state));
1329 list_del(&ctlx->list);
1330 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1337 /*----------------------------------------------------------------
1340 * Constructs a command CTLX and submits it.
1342 * NOTE: Any changes to the 'post-submit' code in this function
1343 * need to be carried over to hfa384x_cbcmd() since the handling
1344 * is virtually identical.
1347 * hw device structure
1348 * mode DOWAIT or DOASYNC
1349 * cmd cmd structure. Includes all arguments and result
1350 * data points. All in host order. in host order
1351 * cmdcb command-specific callback
1352 * usercb user callback for async calls, NULL for DOWAIT calls
1353 * usercb_data user supplied data pointer for async calls, NULL
1359 * -ERESTARTSYS Awakened on signal
1360 * >0 command indicated error, Status and Resp0-2 are
1368 ----------------------------------------------------------------*/
1370 hfa384x_docmd(hfa384x_t *hw,
1372 hfa384x_metacmd_t *cmd,
1373 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1376 hfa384x_usbctlx_t *ctlx;
1378 ctlx = usbctlx_alloc();
1384 /* Initialize the command */
1385 ctlx->outbuf.cmdreq.type = cpu_to_le16(HFA384x_USB_CMDREQ);
1386 ctlx->outbuf.cmdreq.cmd = cpu_to_le16(cmd->cmd);
1387 ctlx->outbuf.cmdreq.parm0 = cpu_to_le16(cmd->parm0);
1388 ctlx->outbuf.cmdreq.parm1 = cpu_to_le16(cmd->parm1);
1389 ctlx->outbuf.cmdreq.parm2 = cpu_to_le16(cmd->parm2);
1391 ctlx->outbufsize = sizeof(ctlx->outbuf.cmdreq);
1393 pr_debug("cmdreq: cmd=0x%04x "
1394 "parm0=0x%04x parm1=0x%04x parm2=0x%04x\n",
1395 cmd->cmd, cmd->parm0, cmd->parm1, cmd->parm2);
1397 ctlx->reapable = mode;
1398 ctlx->cmdcb = cmdcb;
1399 ctlx->usercb = usercb;
1400 ctlx->usercb_data = usercb_data;
1402 result = hfa384x_usbctlx_submit(hw, ctlx);
1405 } else if (mode == DOWAIT) {
1406 usbctlx_cmd_completor_t completor;
1409 hfa384x_usbctlx_complete_sync(hw, ctlx,
1410 init_cmd_completor(&completor,
1422 /*----------------------------------------------------------------
1425 * Constructs a read rid CTLX and issues it.
1427 * NOTE: Any changes to the 'post-submit' code in this function
1428 * need to be carried over to hfa384x_cbrrid() since the handling
1429 * is virtually identical.
1432 * hw device structure
1433 * mode DOWAIT or DOASYNC
1434 * rid Read RID number (host order)
1435 * riddata Caller supplied buffer that MAC formatted RID.data
1436 * record will be written to for DOWAIT calls. Should
1437 * be NULL for DOASYNC calls.
1438 * riddatalen Buffer length for DOWAIT calls. Zero for DOASYNC calls.
1439 * cmdcb command callback for async calls, NULL for DOWAIT calls
1440 * usercb user callback for async calls, NULL for DOWAIT calls
1441 * usercb_data user supplied data pointer for async calls, NULL
1447 * -ERESTARTSYS Awakened on signal
1448 * -ENODATA riddatalen != macdatalen
1449 * >0 command indicated error, Status and Resp0-2 are
1455 * interrupt (DOASYNC)
1456 * process (DOWAIT or DOASYNC)
1457 ----------------------------------------------------------------*/
1459 hfa384x_dorrid(hfa384x_t *hw,
1463 unsigned int riddatalen,
1464 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1467 hfa384x_usbctlx_t *ctlx;
1469 ctlx = usbctlx_alloc();
1475 /* Initialize the command */
1476 ctlx->outbuf.rridreq.type = cpu_to_le16(HFA384x_USB_RRIDREQ);
1477 ctlx->outbuf.rridreq.frmlen =
1478 cpu_to_le16(sizeof(ctlx->outbuf.rridreq.rid));
1479 ctlx->outbuf.rridreq.rid = cpu_to_le16(rid);
1481 ctlx->outbufsize = sizeof(ctlx->outbuf.rridreq);
1483 ctlx->reapable = mode;
1484 ctlx->cmdcb = cmdcb;
1485 ctlx->usercb = usercb;
1486 ctlx->usercb_data = usercb_data;
1488 /* Submit the CTLX */
1489 result = hfa384x_usbctlx_submit(hw, ctlx);
1492 } else if (mode == DOWAIT) {
1493 usbctlx_rrid_completor_t completor;
1496 hfa384x_usbctlx_complete_sync(hw, ctlx,
1499 &ctlx->inbuf.rridresp,
1500 riddata, riddatalen));
1507 /*----------------------------------------------------------------
1510 * Constructs a write rid CTLX and issues it.
1512 * NOTE: Any changes to the 'post-submit' code in this function
1513 * need to be carried over to hfa384x_cbwrid() since the handling
1514 * is virtually identical.
1517 * hw device structure
1518 * CMD_MODE DOWAIT or DOASYNC
1520 * riddata Data portion of RID formatted for MAC
1521 * riddatalen Length of the data portion in bytes
1522 * cmdcb command callback for async calls, NULL for DOWAIT calls
1523 * usercb user callback for async calls, NULL for DOWAIT calls
1524 * usercb_data user supplied data pointer for async calls
1528 * -ETIMEDOUT timed out waiting for register ready or
1529 * command completion
1530 * >0 command indicated error, Status and Resp0-2 are
1536 * interrupt (DOASYNC)
1537 * process (DOWAIT or DOASYNC)
1538 ----------------------------------------------------------------*/
1540 hfa384x_dowrid(hfa384x_t *hw,
1544 unsigned int riddatalen,
1545 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1548 hfa384x_usbctlx_t *ctlx;
1550 ctlx = usbctlx_alloc();
1556 /* Initialize the command */
1557 ctlx->outbuf.wridreq.type = cpu_to_le16(HFA384x_USB_WRIDREQ);
1558 ctlx->outbuf.wridreq.frmlen = cpu_to_le16((sizeof
1559 (ctlx->outbuf.wridreq.
1562 ctlx->outbuf.wridreq.rid = cpu_to_le16(rid);
1563 memcpy(ctlx->outbuf.wridreq.data, riddata, riddatalen);
1565 ctlx->outbufsize = sizeof(ctlx->outbuf.wridreq.type) +
1566 sizeof(ctlx->outbuf.wridreq.frmlen) +
1567 sizeof(ctlx->outbuf.wridreq.rid) + riddatalen;
1569 ctlx->reapable = mode;
1570 ctlx->cmdcb = cmdcb;
1571 ctlx->usercb = usercb;
1572 ctlx->usercb_data = usercb_data;
1574 /* Submit the CTLX */
1575 result = hfa384x_usbctlx_submit(hw, ctlx);
1578 } else if (mode == DOWAIT) {
1579 usbctlx_wrid_completor_t completor;
1580 hfa384x_cmdresult_t wridresult;
1582 result = hfa384x_usbctlx_complete_sync(hw,
1586 &ctlx->inbuf.wridresp,
1594 /*----------------------------------------------------------------
1597 * Constructs a readmem CTLX and issues it.
1599 * NOTE: Any changes to the 'post-submit' code in this function
1600 * need to be carried over to hfa384x_cbrmem() since the handling
1601 * is virtually identical.
1604 * hw device structure
1605 * mode DOWAIT or DOASYNC
1606 * page MAC address space page (CMD format)
1607 * offset MAC address space offset
1608 * data Ptr to data buffer to receive read
1609 * len Length of the data to read (max == 2048)
1610 * cmdcb command callback for async calls, NULL for DOWAIT calls
1611 * usercb user callback for async calls, NULL for DOWAIT calls
1612 * usercb_data user supplied data pointer for async calls
1616 * -ETIMEDOUT timed out waiting for register ready or
1617 * command completion
1618 * >0 command indicated error, Status and Resp0-2 are
1624 * interrupt (DOASYNC)
1625 * process (DOWAIT or DOASYNC)
1626 ----------------------------------------------------------------*/
1628 hfa384x_dormem(hfa384x_t *hw,
1634 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1637 hfa384x_usbctlx_t *ctlx;
1639 ctlx = usbctlx_alloc();
1645 /* Initialize the command */
1646 ctlx->outbuf.rmemreq.type = cpu_to_le16(HFA384x_USB_RMEMREQ);
1647 ctlx->outbuf.rmemreq.frmlen =
1648 cpu_to_le16(sizeof(ctlx->outbuf.rmemreq.offset) +
1649 sizeof(ctlx->outbuf.rmemreq.page) + len);
1650 ctlx->outbuf.rmemreq.offset = cpu_to_le16(offset);
1651 ctlx->outbuf.rmemreq.page = cpu_to_le16(page);
1653 ctlx->outbufsize = sizeof(ctlx->outbuf.rmemreq);
1656 "type=0x%04x frmlen=%d offset=0x%04x page=0x%04x\n",
1657 ctlx->outbuf.rmemreq.type,
1658 ctlx->outbuf.rmemreq.frmlen,
1659 ctlx->outbuf.rmemreq.offset, ctlx->outbuf.rmemreq.page);
1661 pr_debug("pktsize=%zd\n",
1662 ROUNDUP64(sizeof(ctlx->outbuf.rmemreq)));
1664 ctlx->reapable = mode;
1665 ctlx->cmdcb = cmdcb;
1666 ctlx->usercb = usercb;
1667 ctlx->usercb_data = usercb_data;
1669 result = hfa384x_usbctlx_submit(hw, ctlx);
1672 } else if (mode == DOWAIT) {
1673 usbctlx_rmem_completor_t completor;
1676 hfa384x_usbctlx_complete_sync(hw, ctlx,
1679 &ctlx->inbuf.rmemresp, data,
1687 /*----------------------------------------------------------------
1690 * Constructs a writemem CTLX and issues it.
1692 * NOTE: Any changes to the 'post-submit' code in this function
1693 * need to be carried over to hfa384x_cbwmem() since the handling
1694 * is virtually identical.
1697 * hw device structure
1698 * mode DOWAIT or DOASYNC
1699 * page MAC address space page (CMD format)
1700 * offset MAC address space offset
1701 * data Ptr to data buffer containing write data
1702 * len Length of the data to read (max == 2048)
1703 * cmdcb command callback for async calls, NULL for DOWAIT calls
1704 * usercb user callback for async calls, NULL for DOWAIT calls
1705 * usercb_data user supplied data pointer for async calls.
1709 * -ETIMEDOUT timed out waiting for register ready or
1710 * command completion
1711 * >0 command indicated error, Status and Resp0-2 are
1717 * interrupt (DOWAIT)
1718 * process (DOWAIT or DOASYNC)
1719 ----------------------------------------------------------------*/
1721 hfa384x_dowmem(hfa384x_t *hw,
1727 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1730 hfa384x_usbctlx_t *ctlx;
1732 pr_debug("page=0x%04x offset=0x%04x len=%d\n",
1735 ctlx = usbctlx_alloc();
1741 /* Initialize the command */
1742 ctlx->outbuf.wmemreq.type = cpu_to_le16(HFA384x_USB_WMEMREQ);
1743 ctlx->outbuf.wmemreq.frmlen =
1744 cpu_to_le16(sizeof(ctlx->outbuf.wmemreq.offset) +
1745 sizeof(ctlx->outbuf.wmemreq.page) + len);
1746 ctlx->outbuf.wmemreq.offset = cpu_to_le16(offset);
1747 ctlx->outbuf.wmemreq.page = cpu_to_le16(page);
1748 memcpy(ctlx->outbuf.wmemreq.data, data, len);
1750 ctlx->outbufsize = sizeof(ctlx->outbuf.wmemreq.type) +
1751 sizeof(ctlx->outbuf.wmemreq.frmlen) +
1752 sizeof(ctlx->outbuf.wmemreq.offset) +
1753 sizeof(ctlx->outbuf.wmemreq.page) + len;
1755 ctlx->reapable = mode;
1756 ctlx->cmdcb = cmdcb;
1757 ctlx->usercb = usercb;
1758 ctlx->usercb_data = usercb_data;
1760 result = hfa384x_usbctlx_submit(hw, ctlx);
1763 } else if (mode == DOWAIT) {
1764 usbctlx_wmem_completor_t completor;
1765 hfa384x_cmdresult_t wmemresult;
1767 result = hfa384x_usbctlx_complete_sync(hw,
1771 &ctlx->inbuf.wmemresp,
1779 /*----------------------------------------------------------------
1780 * hfa384x_drvr_commtallies
1782 * Send a commtallies inquiry to the MAC. Note that this is an async
1783 * call that will result in an info frame arriving sometime later.
1786 * hw device structure
1795 ----------------------------------------------------------------*/
1796 int hfa384x_drvr_commtallies(hfa384x_t *hw)
1798 hfa384x_metacmd_t cmd;
1800 cmd.cmd = HFA384x_CMDCODE_INQ;
1801 cmd.parm0 = HFA384x_IT_COMMTALLIES;
1805 hfa384x_docmd_async(hw, &cmd, NULL, NULL, NULL);
1810 /*----------------------------------------------------------------
1811 * hfa384x_drvr_disable
1813 * Issues the disable command to stop communications on one of
1814 * the MACs 'ports'. Only macport 0 is valid for stations.
1815 * APs may also disable macports 1-6. Only ports that have been
1816 * previously enabled may be disabled.
1819 * hw device structure
1820 * macport MAC port number (host order)
1824 * >0 f/w reported failure - f/w status code
1825 * <0 driver reported error (timeout|bad arg)
1831 ----------------------------------------------------------------*/
1832 int hfa384x_drvr_disable(hfa384x_t *hw, u16 macport)
1836 if ((!hw->isap && macport != 0) ||
1837 (hw->isap && !(macport <= HFA384x_PORTID_MAX)) ||
1838 !(hw->port_enabled[macport])) {
1841 result = hfa384x_cmd_disable(hw, macport);
1843 hw->port_enabled[macport] = 0;
1848 /*----------------------------------------------------------------
1849 * hfa384x_drvr_enable
1851 * Issues the enable command to enable communications on one of
1852 * the MACs 'ports'. Only macport 0 is valid for stations.
1853 * APs may also enable macports 1-6. Only ports that are currently
1854 * disabled may be enabled.
1857 * hw device structure
1858 * macport MAC port number
1862 * >0 f/w reported failure - f/w status code
1863 * <0 driver reported error (timeout|bad arg)
1869 ----------------------------------------------------------------*/
1870 int hfa384x_drvr_enable(hfa384x_t *hw, u16 macport)
1874 if ((!hw->isap && macport != 0) ||
1875 (hw->isap && !(macport <= HFA384x_PORTID_MAX)) ||
1876 (hw->port_enabled[macport])) {
1879 result = hfa384x_cmd_enable(hw, macport);
1881 hw->port_enabled[macport] = 1;
1886 /*----------------------------------------------------------------
1887 * hfa384x_drvr_flashdl_enable
1889 * Begins the flash download state. Checks to see that we're not
1890 * already in a download state and that a port isn't enabled.
1891 * Sets the download state and retrieves the flash download
1892 * buffer location, buffer size, and timeout length.
1895 * hw device structure
1899 * >0 f/w reported error - f/w status code
1900 * <0 driver reported error
1906 ----------------------------------------------------------------*/
1907 int hfa384x_drvr_flashdl_enable(hfa384x_t *hw)
1912 /* Check that a port isn't active */
1913 for (i = 0; i < HFA384x_PORTID_MAX; i++) {
1914 if (hw->port_enabled[i]) {
1915 pr_debug("called when port enabled.\n");
1920 /* Check that we're not already in a download state */
1921 if (hw->dlstate != HFA384x_DLSTATE_DISABLED)
1924 /* Retrieve the buffer loc&size and timeout */
1925 if ((result = hfa384x_drvr_getconfig(hw, HFA384x_RID_DOWNLOADBUFFER,
1927 sizeof(hw->bufinfo)))) {
1930 hw->bufinfo.page = le16_to_cpu(hw->bufinfo.page);
1931 hw->bufinfo.offset = le16_to_cpu(hw->bufinfo.offset);
1932 hw->bufinfo.len = le16_to_cpu(hw->bufinfo.len);
1933 if ((result = hfa384x_drvr_getconfig16(hw, HFA384x_RID_MAXLOADTIME,
1934 &(hw->dltimeout)))) {
1937 hw->dltimeout = le16_to_cpu(hw->dltimeout);
1939 pr_debug("flashdl_enable\n");
1941 hw->dlstate = HFA384x_DLSTATE_FLASHENABLED;
1946 /*----------------------------------------------------------------
1947 * hfa384x_drvr_flashdl_disable
1949 * Ends the flash download state. Note that this will cause the MAC
1950 * firmware to restart.
1953 * hw device structure
1957 * >0 f/w reported error - f/w status code
1958 * <0 driver reported error
1964 ----------------------------------------------------------------*/
1965 int hfa384x_drvr_flashdl_disable(hfa384x_t *hw)
1967 /* Check that we're already in the download state */
1968 if (hw->dlstate != HFA384x_DLSTATE_FLASHENABLED)
1971 pr_debug("flashdl_enable\n");
1973 /* There isn't much we can do at this point, so I don't */
1974 /* bother w/ the return value */
1975 hfa384x_cmd_download(hw, HFA384x_PROGMODE_DISABLE, 0, 0, 0);
1976 hw->dlstate = HFA384x_DLSTATE_DISABLED;
1981 /*----------------------------------------------------------------
1982 * hfa384x_drvr_flashdl_write
1984 * Performs a FLASH download of a chunk of data. First checks to see
1985 * that we're in the FLASH download state, then sets the download
1986 * mode, uses the aux functions to 1) copy the data to the flash
1987 * buffer, 2) sets the download 'write flash' mode, 3) readback and
1988 * compare. Lather rinse, repeat as many times an necessary to get
1989 * all the given data into flash.
1990 * When all data has been written using this function (possibly
1991 * repeatedly), call drvr_flashdl_disable() to end the download state
1992 * and restart the MAC.
1995 * hw device structure
1996 * daddr Card address to write to. (host order)
1997 * buf Ptr to data to write.
1998 * len Length of data (host order).
2002 * >0 f/w reported error - f/w status code
2003 * <0 driver reported error
2009 ----------------------------------------------------------------*/
2010 int hfa384x_drvr_flashdl_write(hfa384x_t *hw, u32 daddr, void *buf, u32 len)
2027 pr_debug("daddr=0x%08x len=%d\n", daddr, len);
2029 /* Check that we're in the flash download state */
2030 if (hw->dlstate != HFA384x_DLSTATE_FLASHENABLED)
2033 printk(KERN_INFO "Download %d bytes to flash @0x%06x\n", len, daddr);
2035 /* Convert to flat address for arithmetic */
2036 /* NOTE: dlbuffer RID stores the address in AUX format */
2038 HFA384x_ADDR_AUX_MKFLAT(hw->bufinfo.page, hw->bufinfo.offset);
2040 "dlbuf.page=0x%04x dlbuf.offset=0x%04x dlbufaddr=0x%08x\n",
2041 hw->bufinfo.page, hw->bufinfo.offset, dlbufaddr);
2044 printk(KERN_WARNING "dlbuf@0x%06lx len=%d to=%d\n", dlbufaddr,
2045 hw->bufinfo.len, hw->dltimeout);
2047 /* Calculations to determine how many fills of the dlbuffer to do
2048 * and how many USB wmemreq's to do for each fill. At this point
2049 * in time, the dlbuffer size and the wmemreq size are the same.
2050 * Therefore, nwrites should always be 1. The extra complexity
2051 * here is a hedge against future changes.
2054 /* Figure out how many times to do the flash programming */
2055 nburns = len / hw->bufinfo.len;
2056 nburns += (len % hw->bufinfo.len) ? 1 : 0;
2058 /* For each flash program cycle, how many USB wmemreq's are needed? */
2059 nwrites = hw->bufinfo.len / HFA384x_USB_RWMEM_MAXLEN;
2060 nwrites += (hw->bufinfo.len % HFA384x_USB_RWMEM_MAXLEN) ? 1 : 0;
2063 for (i = 0; i < nburns; i++) {
2064 /* Get the dest address and len */
2065 burnlen = (len - (hw->bufinfo.len * i)) > hw->bufinfo.len ?
2066 hw->bufinfo.len : (len - (hw->bufinfo.len * i));
2067 burndaddr = daddr + (hw->bufinfo.len * i);
2068 burnlo = HFA384x_ADDR_CMD_MKOFF(burndaddr);
2069 burnhi = HFA384x_ADDR_CMD_MKPAGE(burndaddr);
2071 printk(KERN_INFO "Writing %d bytes to flash @0x%06x\n",
2072 burnlen, burndaddr);
2074 /* Set the download mode */
2075 result = hfa384x_cmd_download(hw, HFA384x_PROGMODE_NV,
2076 burnlo, burnhi, burnlen);
2078 printk(KERN_ERR "download(NV,lo=%x,hi=%x,len=%x) "
2079 "cmd failed, result=%d. Aborting d/l\n",
2080 burnlo, burnhi, burnlen, result);
2084 /* copy the data to the flash download buffer */
2085 for (j = 0; j < nwrites; j++) {
2087 (i * hw->bufinfo.len) +
2088 (j * HFA384x_USB_RWMEM_MAXLEN);
2090 writepage = HFA384x_ADDR_CMD_MKPAGE(dlbufaddr +
2092 HFA384x_USB_RWMEM_MAXLEN));
2094 HFA384x_ADDR_CMD_MKOFF(dlbufaddr +
2096 HFA384x_USB_RWMEM_MAXLEN));
2098 writelen = burnlen - (j * HFA384x_USB_RWMEM_MAXLEN);
2099 writelen = writelen > HFA384x_USB_RWMEM_MAXLEN ?
2100 HFA384x_USB_RWMEM_MAXLEN : writelen;
2102 result = hfa384x_dowmem_wait(hw,
2105 writebuf, writelen);
2108 /* set the download 'write flash' mode */
2109 result = hfa384x_cmd_download(hw,
2110 HFA384x_PROGMODE_NVWRITE,
2114 "download(NVWRITE,lo=%x,hi=%x,len=%x) "
2115 "cmd failed, result=%d. Aborting d/l\n",
2116 burnlo, burnhi, burnlen, result);
2120 /* TODO: We really should do a readback and compare. */
2125 /* Leave the firmware in the 'post-prog' mode. flashdl_disable will */
2126 /* actually disable programming mode. Remember, that will cause the */
2127 /* the firmware to effectively reset itself. */
2132 /*----------------------------------------------------------------
2133 * hfa384x_drvr_getconfig
2135 * Performs the sequence necessary to read a config/info item.
2138 * hw device structure
2139 * rid config/info record id (host order)
2140 * buf host side record buffer. Upon return it will
2141 * contain the body portion of the record (minus the
2143 * len buffer length (in bytes, should match record length)
2147 * >0 f/w reported error - f/w status code
2148 * <0 driver reported error
2149 * -ENODATA length mismatch between argument and retrieved
2156 ----------------------------------------------------------------*/
2157 int hfa384x_drvr_getconfig(hfa384x_t *hw, u16 rid, void *buf, u16 len)
2161 result = hfa384x_dorrid_wait(hw, rid, buf, len);
2166 /*----------------------------------------------------------------
2167 * hfa384x_drvr_getconfig_async
2169 * Performs the sequence necessary to perform an async read of
2170 * of a config/info item.
2173 * hw device structure
2174 * rid config/info record id (host order)
2175 * buf host side record buffer. Upon return it will
2176 * contain the body portion of the record (minus the
2178 * len buffer length (in bytes, should match record length)
2179 * cbfn caller supplied callback, called when the command
2180 * is done (successful or not).
2181 * cbfndata pointer to some caller supplied data that will be
2182 * passed in as an argument to the cbfn.
2185 * nothing the cbfn gets a status argument identifying if
2188 * Queues an hfa384x_usbcmd_t for subsequent execution.
2192 ----------------------------------------------------------------*/
2194 hfa384x_drvr_getconfig_async(hfa384x_t *hw,
2195 u16 rid, ctlx_usercb_t usercb, void *usercb_data)
2197 return hfa384x_dorrid_async(hw, rid, NULL, 0,
2198 hfa384x_cb_rrid, usercb, usercb_data);
2201 /*----------------------------------------------------------------
2202 * hfa384x_drvr_setconfig_async
2204 * Performs the sequence necessary to write a config/info item.
2207 * hw device structure
2208 * rid config/info record id (in host order)
2209 * buf host side record buffer
2210 * len buffer length (in bytes)
2211 * usercb completion callback
2212 * usercb_data completion callback argument
2216 * >0 f/w reported error - f/w status code
2217 * <0 driver reported error
2223 ----------------------------------------------------------------*/
2225 hfa384x_drvr_setconfig_async(hfa384x_t *hw,
2228 u16 len, ctlx_usercb_t usercb, void *usercb_data)
2230 return hfa384x_dowrid_async(hw, rid, buf, len,
2231 hfa384x_cb_status, usercb, usercb_data);
2234 /*----------------------------------------------------------------
2235 * hfa384x_drvr_ramdl_disable
2237 * Ends the ram download state.
2240 * hw device structure
2244 * >0 f/w reported error - f/w status code
2245 * <0 driver reported error
2251 ----------------------------------------------------------------*/
2252 int hfa384x_drvr_ramdl_disable(hfa384x_t *hw)
2254 /* Check that we're already in the download state */
2255 if (hw->dlstate != HFA384x_DLSTATE_RAMENABLED)
2258 pr_debug("ramdl_disable()\n");
2260 /* There isn't much we can do at this point, so I don't */
2261 /* bother w/ the return value */
2262 hfa384x_cmd_download(hw, HFA384x_PROGMODE_DISABLE, 0, 0, 0);
2263 hw->dlstate = HFA384x_DLSTATE_DISABLED;
2268 /*----------------------------------------------------------------
2269 * hfa384x_drvr_ramdl_enable
2271 * Begins the ram download state. Checks to see that we're not
2272 * already in a download state and that a port isn't enabled.
2273 * Sets the download state and calls cmd_download with the
2274 * ENABLE_VOLATILE subcommand and the exeaddr argument.
2277 * hw device structure
2278 * exeaddr the card execution address that will be
2279 * jumped to when ramdl_disable() is called
2284 * >0 f/w reported error - f/w status code
2285 * <0 driver reported error
2291 ----------------------------------------------------------------*/
2292 int hfa384x_drvr_ramdl_enable(hfa384x_t *hw, u32 exeaddr)
2299 /* Check that a port isn't active */
2300 for (i = 0; i < HFA384x_PORTID_MAX; i++) {
2301 if (hw->port_enabled[i]) {
2303 "Can't download with a macport enabled.\n");
2308 /* Check that we're not already in a download state */
2309 if (hw->dlstate != HFA384x_DLSTATE_DISABLED) {
2310 printk(KERN_ERR "Download state not disabled.\n");
2314 pr_debug("ramdl_enable, exeaddr=0x%08x\n", exeaddr);
2316 /* Call the download(1,addr) function */
2317 lowaddr = HFA384x_ADDR_CMD_MKOFF(exeaddr);
2318 hiaddr = HFA384x_ADDR_CMD_MKPAGE(exeaddr);
2320 result = hfa384x_cmd_download(hw, HFA384x_PROGMODE_RAM,
2321 lowaddr, hiaddr, 0);
2324 /* Set the download state */
2325 hw->dlstate = HFA384x_DLSTATE_RAMENABLED;
2328 "cmd_download(0x%04x, 0x%04x) failed, result=%d.\n",
2329 lowaddr, hiaddr, result);
2335 /*----------------------------------------------------------------
2336 * hfa384x_drvr_ramdl_write
2338 * Performs a RAM download of a chunk of data. First checks to see
2339 * that we're in the RAM download state, then uses the [read|write]mem USB
2340 * commands to 1) copy the data, 2) readback and compare. The download
2341 * state is unaffected. When all data has been written using
2342 * this function, call drvr_ramdl_disable() to end the download state
2343 * and restart the MAC.
2346 * hw device structure
2347 * daddr Card address to write to. (host order)
2348 * buf Ptr to data to write.
2349 * len Length of data (host order).
2353 * >0 f/w reported error - f/w status code
2354 * <0 driver reported error
2360 ----------------------------------------------------------------*/
2361 int hfa384x_drvr_ramdl_write(hfa384x_t *hw, u32 daddr, void *buf, u32 len)
2372 /* Check that we're in the ram download state */
2373 if (hw->dlstate != HFA384x_DLSTATE_RAMENABLED)
2376 printk(KERN_INFO "Writing %d bytes to ram @0x%06x\n", len, daddr);
2378 /* How many dowmem calls? */
2379 nwrites = len / HFA384x_USB_RWMEM_MAXLEN;
2380 nwrites += len % HFA384x_USB_RWMEM_MAXLEN ? 1 : 0;
2382 /* Do blocking wmem's */
2383 for (i = 0; i < nwrites; i++) {
2384 /* make address args */
2385 curraddr = daddr + (i * HFA384x_USB_RWMEM_MAXLEN);
2386 currpage = HFA384x_ADDR_CMD_MKPAGE(curraddr);
2387 curroffset = HFA384x_ADDR_CMD_MKOFF(curraddr);
2388 currlen = len - (i * HFA384x_USB_RWMEM_MAXLEN);
2389 if (currlen > HFA384x_USB_RWMEM_MAXLEN)
2390 currlen = HFA384x_USB_RWMEM_MAXLEN;
2392 /* Do blocking ctlx */
2393 result = hfa384x_dowmem_wait(hw,
2397 (i * HFA384x_USB_RWMEM_MAXLEN),
2403 /* TODO: We really should have a readback. */
2409 /*----------------------------------------------------------------
2410 * hfa384x_drvr_readpda
2412 * Performs the sequence to read the PDA space. Note there is no
2413 * drvr_writepda() function. Writing a PDA is
2414 * generally implemented by a calling component via calls to
2415 * cmd_download and writing to the flash download buffer via the
2419 * hw device structure
2420 * buf buffer to store PDA in
2425 * >0 f/w reported error - f/w status code
2426 * <0 driver reported error
2427 * -ETIMEOUT timout waiting for the cmd regs to become
2428 * available, or waiting for the control reg
2429 * to indicate the Aux port is enabled.
2430 * -ENODATA the buffer does NOT contain a valid PDA.
2431 * Either the card PDA is bad, or the auxdata
2432 * reads are giving us garbage.
2438 * process or non-card interrupt.
2439 ----------------------------------------------------------------*/
2440 int hfa384x_drvr_readpda(hfa384x_t *hw, void *buf, unsigned int len)
2446 int currpdr = 0; /* word offset of the current pdr */
2448 u16 pdrlen; /* pdr length in bytes, host order */
2449 u16 pdrcode; /* pdr code, host order */
2457 HFA3842_PDA_BASE, 0}, {
2458 HFA3841_PDA_BASE, 0}, {
2459 HFA3841_PDA_BOGUS_BASE, 0}
2462 /* Read the pda from each known address. */
2463 for (i = 0; i < ARRAY_SIZE(pdaloc); i++) {
2465 currpage = HFA384x_ADDR_CMD_MKPAGE(pdaloc[i].cardaddr);
2466 curroffset = HFA384x_ADDR_CMD_MKOFF(pdaloc[i].cardaddr);
2468 result = hfa384x_dormem_wait(hw, currpage, curroffset, buf, len); /* units of bytes */
2472 "Read from index %zd failed, continuing\n", i);
2476 /* Test for garbage */
2477 pdaok = 1; /* initially assume good */
2479 while (pdaok && morepdrs) {
2480 pdrlen = le16_to_cpu(pda[currpdr]) * 2;
2481 pdrcode = le16_to_cpu(pda[currpdr + 1]);
2482 /* Test the record length */
2483 if (pdrlen > HFA384x_PDR_LEN_MAX || pdrlen == 0) {
2484 printk(KERN_ERR "pdrlen invalid=%d\n", pdrlen);
2489 if (!hfa384x_isgood_pdrcode(pdrcode)) {
2490 printk(KERN_ERR "pdrcode invalid=%d\n",
2495 /* Test for completion */
2496 if (pdrcode == HFA384x_PDR_END_OF_PDA)
2499 /* Move to the next pdr (if necessary) */
2501 /* note the access to pda[], need words here */
2502 currpdr += le16_to_cpu(pda[currpdr]) + 1;
2507 "PDA Read from 0x%08x in %s space.\n",
2509 pdaloc[i].auxctl == 0 ? "EXTDS" :
2510 pdaloc[i].auxctl == 1 ? "NV" :
2511 pdaloc[i].auxctl == 2 ? "PHY" :
2512 pdaloc[i].auxctl == 3 ? "ICSRAM" :
2517 result = pdaok ? 0 : -ENODATA;
2520 pr_debug("Failure: pda is not okay\n");
2525 /*----------------------------------------------------------------
2526 * hfa384x_drvr_setconfig
2528 * Performs the sequence necessary to write a config/info item.
2531 * hw device structure
2532 * rid config/info record id (in host order)
2533 * buf host side record buffer
2534 * len buffer length (in bytes)
2538 * >0 f/w reported error - f/w status code
2539 * <0 driver reported error
2545 ----------------------------------------------------------------*/
2546 int hfa384x_drvr_setconfig(hfa384x_t *hw, u16 rid, void *buf, u16 len)
2548 return hfa384x_dowrid_wait(hw, rid, buf, len);
2551 /*----------------------------------------------------------------
2552 * hfa384x_drvr_start
2554 * Issues the MAC initialize command, sets up some data structures,
2555 * and enables the interrupts. After this function completes, the
2556 * low-level stuff should be ready for any/all commands.
2559 * hw device structure
2562 * >0 f/w reported error - f/w status code
2563 * <0 driver reported error
2569 ----------------------------------------------------------------*/
2571 int hfa384x_drvr_start(hfa384x_t *hw)
2573 int result, result1, result2;
2578 /* Clear endpoint stalls - but only do this if the endpoint
2579 * is showing a stall status. Some prism2 cards seem to behave
2580 * badly if a clear_halt is called when the endpoint is already
2584 usb_get_status(hw->usb, USB_RECIP_ENDPOINT, hw->endp_in, &status);
2586 printk(KERN_ERR "Cannot get bulk in endpoint status.\n");
2589 if ((status == 1) && usb_clear_halt(hw->usb, hw->endp_in))
2590 printk(KERN_ERR "Failed to reset bulk in endpoint.\n");
2593 usb_get_status(hw->usb, USB_RECIP_ENDPOINT, hw->endp_out, &status);
2595 printk(KERN_ERR "Cannot get bulk out endpoint status.\n");
2598 if ((status == 1) && usb_clear_halt(hw->usb, hw->endp_out))
2599 printk(KERN_ERR "Failed to reset bulk out endpoint.\n");
2601 /* Synchronous unlink, in case we're trying to restart the driver */
2602 usb_kill_urb(&hw->rx_urb);
2604 /* Post the IN urb */
2605 result = submit_rx_urb(hw, GFP_KERNEL);
2608 "Fatal, failed to submit RX URB, result=%d\n", result);
2612 /* Call initialize twice, with a 1 second sleep in between.
2613 * This is a nasty work-around since many prism2 cards seem to
2614 * need time to settle after an init from cold. The second
2615 * call to initialize in theory is not necessary - but we call
2616 * it anyway as a double insurance policy:
2617 * 1) If the first init should fail, the second may well succeed
2618 * and the card can still be used
2619 * 2) It helps ensures all is well with the card after the first
2620 * init and settle time.
2622 result1 = hfa384x_cmd_initialize(hw);
2624 result = result2 = hfa384x_cmd_initialize(hw);
2628 "cmd_initialize() failed on two attempts, results %d and %d\n",
2630 usb_kill_urb(&hw->rx_urb);
2634 "First cmd_initialize() failed (result %d),\n",
2637 "but second attempt succeeded. All should be ok\n");
2639 } else if (result2 != 0) {
2641 "First cmd_initialize() succeeded, but second attempt failed (result=%d)\n",
2644 "Most likely the card will be functional\n");
2648 hw->state = HFA384x_STATE_RUNNING;
2654 /*----------------------------------------------------------------
2657 * Shuts down the MAC to the point where it is safe to unload the
2658 * driver. Any subsystem that may be holding a data or function
2659 * ptr into the driver must be cleared/deinitialized.
2662 * hw device structure
2665 * >0 f/w reported error - f/w status code
2666 * <0 driver reported error
2672 ----------------------------------------------------------------*/
2673 int hfa384x_drvr_stop(hfa384x_t *hw)
2680 /* There's no need for spinlocks here. The USB "disconnect"
2681 * function sets this "removed" flag and then calls us.
2683 if (!hw->wlandev->hwremoved) {
2684 /* Call initialize to leave the MAC in its 'reset' state */
2685 hfa384x_cmd_initialize(hw);
2687 /* Cancel the rxurb */
2688 usb_kill_urb(&hw->rx_urb);
2691 hw->link_status = HFA384x_LINK_NOTCONNECTED;
2692 hw->state = HFA384x_STATE_INIT;
2694 del_timer_sync(&hw->commsqual_timer);
2696 /* Clear all the port status */
2697 for (i = 0; i < HFA384x_NUMPORTS_MAX; i++)
2698 hw->port_enabled[i] = 0;
2703 /*----------------------------------------------------------------
2704 * hfa384x_drvr_txframe
2706 * Takes a frame from prism2sta and queues it for transmission.
2709 * hw device structure
2710 * skb packet buffer struct. Contains an 802.11
2712 * p80211_hdr points to the 802.11 header for the packet.
2714 * 0 Success and more buffs available
2715 * 1 Success but no more buffs
2716 * 2 Allocation failure
2717 * 4 Buffer full or queue busy
2723 ----------------------------------------------------------------*/
2724 int hfa384x_drvr_txframe(hfa384x_t *hw, struct sk_buff *skb,
2725 p80211_hdr_t *p80211_hdr,
2726 p80211_metawep_t *p80211_wep)
2728 int usbpktlen = sizeof(hfa384x_tx_frame_t);
2733 if (hw->tx_urb.status == -EINPROGRESS) {
2734 printk(KERN_WARNING "TX URB already in use\n");
2739 /* Build Tx frame structure */
2740 /* Set up the control field */
2741 memset(&hw->txbuff.txfrm.desc, 0, sizeof(hw->txbuff.txfrm.desc));
2743 /* Setup the usb type field */
2744 hw->txbuff.type = cpu_to_le16(HFA384x_USB_TXFRM);
2746 /* Set up the sw_support field to identify this frame */
2747 hw->txbuff.txfrm.desc.sw_support = 0x0123;
2749 /* Tx complete and Tx exception disable per dleach. Might be causing
2752 /* #define DOEXC SLP -- doboth breaks horribly under load, doexc less so. */
2754 hw->txbuff.txfrm.desc.tx_control =
2755 HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
2756 HFA384x_TX_TXEX_SET(1) | HFA384x_TX_TXOK_SET(1);
2757 #elif defined(DOEXC)
2758 hw->txbuff.txfrm.desc.tx_control =
2759 HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
2760 HFA384x_TX_TXEX_SET(1) | HFA384x_TX_TXOK_SET(0);
2762 hw->txbuff.txfrm.desc.tx_control =
2763 HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
2764 HFA384x_TX_TXEX_SET(0) | HFA384x_TX_TXOK_SET(0);
2766 hw->txbuff.txfrm.desc.tx_control =
2767 cpu_to_le16(hw->txbuff.txfrm.desc.tx_control);
2769 /* copy the header over to the txdesc */
2770 memcpy(&(hw->txbuff.txfrm.desc.frame_control), p80211_hdr,
2771 sizeof(p80211_hdr_t));
2773 /* if we're using host WEP, increase size by IV+ICV */
2774 if (p80211_wep->data) {
2775 hw->txbuff.txfrm.desc.data_len = cpu_to_le16(skb->len + 8);
2778 hw->txbuff.txfrm.desc.data_len = cpu_to_le16(skb->len);
2781 usbpktlen += skb->len;
2783 /* copy over the WEP IV if we are using host WEP */
2784 ptr = hw->txbuff.txfrm.data;
2785 if (p80211_wep->data) {
2786 memcpy(ptr, p80211_wep->iv, sizeof(p80211_wep->iv));
2787 ptr += sizeof(p80211_wep->iv);
2788 memcpy(ptr, p80211_wep->data, skb->len);
2790 memcpy(ptr, skb->data, skb->len);
2792 /* copy over the packet data */
2795 /* copy over the WEP ICV if we are using host WEP */
2796 if (p80211_wep->data)
2797 memcpy(ptr, p80211_wep->icv, sizeof(p80211_wep->icv));
2799 /* Send the USB packet */
2800 usb_fill_bulk_urb(&(hw->tx_urb), hw->usb,
2802 &(hw->txbuff), ROUNDUP64(usbpktlen),
2803 hfa384x_usbout_callback, hw->wlandev);
2804 hw->tx_urb.transfer_flags |= USB_QUEUE_BULK;
2807 ret = submit_tx_urb(hw, &hw->tx_urb, GFP_ATOMIC);
2809 printk(KERN_ERR "submit_tx_urb() failed, error=%d\n", ret);
2817 void hfa384x_tx_timeout(wlandevice_t *wlandev)
2819 hfa384x_t *hw = wlandev->priv;
2820 unsigned long flags;
2822 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2824 if (!hw->wlandev->hwremoved &&
2825 /* Note the bitwise OR, not the logical OR. */
2826 (!test_and_set_bit(WORK_TX_HALT, &hw->usb_flags) |
2827 !test_and_set_bit(WORK_RX_HALT, &hw->usb_flags))) {
2828 schedule_work(&hw->usb_work);
2831 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2834 /*----------------------------------------------------------------
2835 * hfa384x_usbctlx_reaper_task
2837 * Tasklet to delete dead CTLX objects
2840 * data ptr to a hfa384x_t
2846 ----------------------------------------------------------------*/
2847 static void hfa384x_usbctlx_reaper_task(unsigned long data)
2849 hfa384x_t *hw = (hfa384x_t *) data;
2850 struct list_head *entry;
2851 struct list_head *temp;
2852 unsigned long flags;
2854 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2856 /* This list is guaranteed to be empty if someone
2857 * has unplugged the adapter.
2859 list_for_each_safe(entry, temp, &hw->ctlxq.reapable) {
2860 hfa384x_usbctlx_t *ctlx;
2862 ctlx = list_entry(entry, hfa384x_usbctlx_t, list);
2863 list_del(&ctlx->list);
2867 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2871 /*----------------------------------------------------------------
2872 * hfa384x_usbctlx_completion_task
2874 * Tasklet to call completion handlers for returned CTLXs
2877 * data ptr to hfa384x_t
2884 ----------------------------------------------------------------*/
2885 static void hfa384x_usbctlx_completion_task(unsigned long data)
2887 hfa384x_t *hw = (hfa384x_t *) data;
2888 struct list_head *entry;
2889 struct list_head *temp;
2890 unsigned long flags;
2894 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2896 /* This list is guaranteed to be empty if someone
2897 * has unplugged the adapter ...
2899 list_for_each_safe(entry, temp, &hw->ctlxq.completing) {
2900 hfa384x_usbctlx_t *ctlx;
2902 ctlx = list_entry(entry, hfa384x_usbctlx_t, list);
2904 /* Call the completion function that this
2905 * command was assigned, assuming it has one.
2907 if (ctlx->cmdcb != NULL) {
2908 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2909 ctlx->cmdcb(hw, ctlx);
2910 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2912 /* Make sure we don't try and complete
2913 * this CTLX more than once!
2917 /* Did someone yank the adapter out
2918 * while our list was (briefly) unlocked?
2920 if (hw->wlandev->hwremoved) {
2927 * "Reapable" CTLXs are ones which don't have any
2928 * threads waiting for them to die. Hence they must
2929 * be delivered to The Reaper!
2931 if (ctlx->reapable) {
2932 /* Move the CTLX off the "completing" list (hopefully)
2933 * on to the "reapable" list where the reaper task
2934 * can find it. And "reapable" means that this CTLX
2935 * isn't sitting on a wait-queue somewhere.
2937 list_move_tail(&ctlx->list, &hw->ctlxq.reapable);
2941 complete(&ctlx->done);
2943 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2946 tasklet_schedule(&hw->reaper_bh);
2949 /*----------------------------------------------------------------
2950 * unlocked_usbctlx_cancel_async
2952 * Mark the CTLX dead asynchronously, and ensure that the
2953 * next command on the queue is run afterwards.
2956 * hw ptr to the hfa384x_t structure
2957 * ctlx ptr to a CTLX structure
2960 * 0 the CTLX's URB is inactive
2961 * -EINPROGRESS the URB is currently being unlinked
2964 * Either process or interrupt, but presumably interrupt
2965 ----------------------------------------------------------------*/
2966 static int unlocked_usbctlx_cancel_async(hfa384x_t *hw,
2967 hfa384x_usbctlx_t *ctlx)
2972 * Try to delete the URB containing our request packet.
2973 * If we succeed, then its completion handler will be
2974 * called with a status of -ECONNRESET.
2976 hw->ctlx_urb.transfer_flags |= URB_ASYNC_UNLINK;
2977 ret = usb_unlink_urb(&hw->ctlx_urb);
2979 if (ret != -EINPROGRESS) {
2981 * The OUT URB had either already completed
2982 * or was still in the pending queue, so the
2983 * URB's completion function will not be called.
2984 * We will have to complete the CTLX ourselves.
2986 ctlx->state = CTLX_REQ_FAILED;
2987 unlocked_usbctlx_complete(hw, ctlx);
2994 /*----------------------------------------------------------------
2995 * unlocked_usbctlx_complete
2997 * A CTLX has completed. It may have been successful, it may not
2998 * have been. At this point, the CTLX should be quiescent. The URBs
2999 * aren't active and the timers should have been stopped.
3001 * The CTLX is migrated to the "completing" queue, and the completing
3002 * tasklet is scheduled.
3005 * hw ptr to a hfa384x_t structure
3006 * ctlx ptr to a ctlx structure
3014 * Either, assume interrupt
3015 ----------------------------------------------------------------*/
3016 static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx)
3018 /* Timers have been stopped, and ctlx should be in
3019 * a terminal state. Retire it from the "active"
3022 list_move_tail(&ctlx->list, &hw->ctlxq.completing);
3023 tasklet_schedule(&hw->completion_bh);
3025 switch (ctlx->state) {
3027 case CTLX_REQ_FAILED:
3028 /* This are the correct terminating states. */
3032 printk(KERN_ERR "CTLX[%d] not in a terminating state(%s)\n",
3033 le16_to_cpu(ctlx->outbuf.type),
3034 ctlxstr(ctlx->state));
3039 /*----------------------------------------------------------------
3040 * hfa384x_usbctlxq_run
3042 * Checks to see if the head item is running. If not, starts it.
3045 * hw ptr to hfa384x_t
3054 ----------------------------------------------------------------*/
3055 static void hfa384x_usbctlxq_run(hfa384x_t *hw)
3057 unsigned long flags;
3060 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3062 /* Only one active CTLX at any one time, because there's no
3063 * other (reliable) way to match the response URB to the
3066 * Don't touch any of these CTLXs if the hardware
3067 * has been removed or the USB subsystem is stalled.
3069 if (!list_empty(&hw->ctlxq.active) ||
3070 test_bit(WORK_TX_HALT, &hw->usb_flags) || hw->wlandev->hwremoved)
3073 while (!list_empty(&hw->ctlxq.pending)) {
3074 hfa384x_usbctlx_t *head;
3077 /* This is the first pending command */
3078 head = list_entry(hw->ctlxq.pending.next,
3079 hfa384x_usbctlx_t, list);
3081 /* We need to split this off to avoid a race condition */
3082 list_move_tail(&head->list, &hw->ctlxq.active);
3084 /* Fill the out packet */
3085 usb_fill_bulk_urb(&(hw->ctlx_urb), hw->usb,
3087 &(head->outbuf), ROUNDUP64(head->outbufsize),
3088 hfa384x_ctlxout_callback, hw);
3089 hw->ctlx_urb.transfer_flags |= USB_QUEUE_BULK;
3091 /* Now submit the URB and update the CTLX's state
3093 if ((result = SUBMIT_URB(&hw->ctlx_urb, GFP_ATOMIC)) == 0) {
3094 /* This CTLX is now running on the active queue */
3095 head->state = CTLX_REQ_SUBMITTED;
3097 /* Start the OUT wait timer */
3098 hw->req_timer_done = 0;
3099 hw->reqtimer.expires = jiffies + HZ;
3100 add_timer(&hw->reqtimer);
3102 /* Start the IN wait timer */
3103 hw->resp_timer_done = 0;
3104 hw->resptimer.expires = jiffies + 2 * HZ;
3105 add_timer(&hw->resptimer);
3110 if (result == -EPIPE) {
3111 /* The OUT pipe needs resetting, so put
3112 * this CTLX back in the "pending" queue
3113 * and schedule a reset ...
3116 "%s tx pipe stalled: requesting reset\n",
3117 hw->wlandev->netdev->name);
3118 list_move(&head->list, &hw->ctlxq.pending);
3119 set_bit(WORK_TX_HALT, &hw->usb_flags);
3120 schedule_work(&hw->usb_work);
3124 if (result == -ESHUTDOWN) {
3125 printk(KERN_WARNING "%s urb shutdown!\n",
3126 hw->wlandev->netdev->name);
3130 printk(KERN_ERR "Failed to submit CTLX[%d]: error=%d\n",
3131 le16_to_cpu(head->outbuf.type), result);
3132 unlocked_usbctlx_complete(hw, head);
3136 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3139 /*----------------------------------------------------------------
3140 * hfa384x_usbin_callback
3142 * Callback for URBs on the BULKIN endpoint.
3145 * urb ptr to the completed urb
3154 ----------------------------------------------------------------*/
3155 static void hfa384x_usbin_callback(struct urb *urb)
3157 wlandevice_t *wlandev = urb->context;
3159 hfa384x_usbin_t *usbin = (hfa384x_usbin_t *) urb->transfer_buffer;
3160 struct sk_buff *skb = NULL;
3171 if (!wlandev || !wlandev->netdev || wlandev->hwremoved)
3178 skb = hw->rx_urb_skb;
3179 BUG_ON(!skb || (skb->data != urb->transfer_buffer));
3181 hw->rx_urb_skb = NULL;
3183 /* Check for error conditions within the URB */
3184 switch (urb->status) {
3188 /* Check for short packet */
3189 if (urb->actual_length == 0) {
3190 ++(wlandev->linux_stats.rx_errors);
3191 ++(wlandev->linux_stats.rx_length_errors);
3197 printk(KERN_WARNING "%s rx pipe stalled: requesting reset\n",
3198 wlandev->netdev->name);
3199 if (!test_and_set_bit(WORK_RX_HALT, &hw->usb_flags))
3200 schedule_work(&hw->usb_work);
3201 ++(wlandev->linux_stats.rx_errors);
3208 if (!test_and_set_bit(THROTTLE_RX, &hw->usb_flags) &&
3209 !timer_pending(&hw->throttle)) {
3210 mod_timer(&hw->throttle, jiffies + THROTTLE_JIFFIES);
3212 ++(wlandev->linux_stats.rx_errors);
3217 ++(wlandev->linux_stats.rx_over_errors);
3223 pr_debug("status=%d, device removed.\n", urb->status);
3229 pr_debug("status=%d, urb explicitly unlinked.\n",
3235 pr_debug("urb status=%d, transfer flags=0x%x\n",
3236 urb->status, urb->transfer_flags);
3237 ++(wlandev->linux_stats.rx_errors);
3242 urb_status = urb->status;
3244 if (action != ABORT) {
3245 /* Repost the RX URB */
3246 result = submit_rx_urb(hw, GFP_ATOMIC);
3250 "Fatal, failed to resubmit rx_urb. error=%d\n",
3255 /* Handle any USB-IN packet */
3256 /* Note: the check of the sw_support field, the type field doesn't
3257 * have bit 12 set like the docs suggest.
3259 type = le16_to_cpu(usbin->type);
3260 if (HFA384x_USB_ISRXFRM(type)) {
3261 if (action == HANDLE) {
3262 if (usbin->txfrm.desc.sw_support == 0x0123) {
3263 hfa384x_usbin_txcompl(wlandev, usbin);
3265 skb_put(skb, sizeof(*usbin));
3266 hfa384x_usbin_rx(wlandev, skb);
3272 if (HFA384x_USB_ISTXFRM(type)) {
3273 if (action == HANDLE)
3274 hfa384x_usbin_txcompl(wlandev, usbin);
3278 case HFA384x_USB_INFOFRM:
3279 if (action == ABORT)
3281 if (action == HANDLE)
3282 hfa384x_usbin_info(wlandev, usbin);
3285 case HFA384x_USB_CMDRESP:
3286 case HFA384x_USB_WRIDRESP:
3287 case HFA384x_USB_RRIDRESP:
3288 case HFA384x_USB_WMEMRESP:
3289 case HFA384x_USB_RMEMRESP:
3290 /* ALWAYS, ALWAYS, ALWAYS handle this CTLX!!!! */
3291 hfa384x_usbin_ctlx(hw, usbin, urb_status);
3294 case HFA384x_USB_BUFAVAIL:
3295 pr_debug("Received BUFAVAIL packet, frmlen=%d\n",
3296 usbin->bufavail.frmlen);
3299 case HFA384x_USB_ERROR:
3300 pr_debug("Received USB_ERROR packet, errortype=%d\n",
3301 usbin->usberror.errortype);
3306 "Unrecognized USBIN packet, type=%x, status=%d\n",
3307 usbin->type, urb_status);
3317 /*----------------------------------------------------------------
3318 * hfa384x_usbin_ctlx
3320 * We've received a URB containing a Prism2 "response" message.
3321 * This message needs to be matched up with a CTLX on the active
3322 * queue and our state updated accordingly.
3325 * hw ptr to hfa384x_t
3326 * usbin ptr to USB IN packet
3327 * urb_status status of this Bulk-In URB
3336 ----------------------------------------------------------------*/
3337 static void hfa384x_usbin_ctlx(hfa384x_t *hw, hfa384x_usbin_t *usbin,
3340 hfa384x_usbctlx_t *ctlx;
3342 unsigned long flags;
3345 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3347 /* There can be only one CTLX on the active queue
3348 * at any one time, and this is the CTLX that the
3349 * timers are waiting for.
3351 if (list_empty(&hw->ctlxq.active))
3354 /* Remove the "response timeout". It's possible that
3355 * we are already too late, and that the timeout is
3356 * already running. And that's just too bad for us,
3357 * because we could lose our CTLX from the active
3360 if (del_timer(&hw->resptimer) == 0) {
3361 if (hw->resp_timer_done == 0) {
3362 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3366 hw->resp_timer_done = 1;
3369 ctlx = get_active_ctlx(hw);
3371 if (urb_status != 0) {
3373 * Bad CTLX, so get rid of it. But we only
3374 * remove it from the active queue if we're no
3375 * longer expecting the OUT URB to complete.
3377 if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0)
3380 const u16 intype = (usbin->type & ~cpu_to_le16(0x8000));
3383 * Check that our message is what we're expecting ...
3385 if (ctlx->outbuf.type != intype) {
3387 "Expected IN[%d], received IN[%d] - ignored.\n",
3388 le16_to_cpu(ctlx->outbuf.type),
3389 le16_to_cpu(intype));
3393 /* This URB has succeeded, so grab the data ... */
3394 memcpy(&ctlx->inbuf, usbin, sizeof(ctlx->inbuf));
3396 switch (ctlx->state) {
3397 case CTLX_REQ_SUBMITTED:
3399 * We have received our response URB before
3400 * our request has been acknowledged. Odd,
3401 * but our OUT URB is still alive...
3404 "Causality violation: please reboot Universe, or email linux-wlan-devel@lists.linux-wlan.com\n");
3405 ctlx->state = CTLX_RESP_COMPLETE;
3408 case CTLX_REQ_COMPLETE:
3410 * This is the usual path: our request
3411 * has already been acknowledged, and
3412 * now we have received the reply too.
3414 ctlx->state = CTLX_COMPLETE;
3415 unlocked_usbctlx_complete(hw, ctlx);
3421 * Throw this CTLX away ...
3424 "Matched IN URB, CTLX[%d] in invalid state(%s)."
3426 le16_to_cpu(ctlx->outbuf.type),
3427 ctlxstr(ctlx->state));
3428 if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0)
3435 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3438 hfa384x_usbctlxq_run(hw);
3441 /*----------------------------------------------------------------
3442 * hfa384x_usbin_txcompl
3444 * At this point we have the results of a previous transmit.
3447 * wlandev wlan device
3448 * usbin ptr to the usb transfer buffer
3457 ----------------------------------------------------------------*/
3458 static void hfa384x_usbin_txcompl(wlandevice_t *wlandev,
3459 hfa384x_usbin_t *usbin)
3463 status = le16_to_cpu(usbin->type); /* yeah I know it says type... */
3465 /* Was there an error? */
3466 if (HFA384x_TXSTATUS_ISERROR(status))
3467 prism2sta_ev_txexc(wlandev, status);
3469 prism2sta_ev_tx(wlandev, status);
3472 /*----------------------------------------------------------------
3475 * At this point we have a successful received a rx frame packet.
3478 * wlandev wlan device
3479 * usbin ptr to the usb transfer buffer
3488 ----------------------------------------------------------------*/
3489 static void hfa384x_usbin_rx(wlandevice_t *wlandev, struct sk_buff *skb)
3491 hfa384x_usbin_t *usbin = (hfa384x_usbin_t *) skb->data;
3492 hfa384x_t *hw = wlandev->priv;
3494 p80211_rxmeta_t *rxmeta;
3498 /* Byte order convert once up front. */
3499 usbin->rxfrm.desc.status = le16_to_cpu(usbin->rxfrm.desc.status);
3500 usbin->rxfrm.desc.time = le32_to_cpu(usbin->rxfrm.desc.time);
3502 /* Now handle frame based on port# */
3503 switch (HFA384x_RXSTATUS_MACPORT_GET(usbin->rxfrm.desc.status)) {
3505 fc = le16_to_cpu(usbin->rxfrm.desc.frame_control);
3507 /* If exclude and we receive an unencrypted, drop it */
3508 if ((wlandev->hostwep & HOSTWEP_EXCLUDEUNENCRYPTED) &&
3509 !WLAN_GET_FC_ISWEP(fc)) {
3513 data_len = le16_to_cpu(usbin->rxfrm.desc.data_len);
3515 /* How much header data do we have? */
3516 hdrlen = p80211_headerlen(fc);
3518 /* Pull off the descriptor */
3519 skb_pull(skb, sizeof(hfa384x_rx_frame_t));
3521 /* Now shunt the header block up against the data block
3522 * with an "overlapping" copy
3524 memmove(skb_push(skb, hdrlen),
3525 &usbin->rxfrm.desc.frame_control, hdrlen);
3527 skb->dev = wlandev->netdev;
3528 skb->dev->last_rx = jiffies;
3530 /* And set the frame length properly */
3531 skb_trim(skb, data_len + hdrlen);
3533 /* The prism2 series does not return the CRC */
3534 memset(skb_put(skb, WLAN_CRC_LEN), 0xff, WLAN_CRC_LEN);
3536 skb_reset_mac_header(skb);
3538 /* Attach the rxmeta, set some stuff */
3539 p80211skb_rxmeta_attach(wlandev, skb);
3540 rxmeta = P80211SKB_RXMETA(skb);
3541 rxmeta->mactime = usbin->rxfrm.desc.time;
3542 rxmeta->rxrate = usbin->rxfrm.desc.rate;
3543 rxmeta->signal = usbin->rxfrm.desc.signal - hw->dbmadjust;
3544 rxmeta->noise = usbin->rxfrm.desc.silence - hw->dbmadjust;
3546 prism2sta_ev_rx(wlandev, skb);
3551 if (!HFA384x_RXSTATUS_ISFCSERR(usbin->rxfrm.desc.status)) {
3552 /* Copy to wlansnif skb */
3553 hfa384x_int_rxmonitor(wlandev, &usbin->rxfrm);
3557 "Received monitor frame: FCSerr set\n");
3562 printk(KERN_WARNING "Received frame on unsupported port=%d\n",
3563 HFA384x_RXSTATUS_MACPORT_GET(usbin->rxfrm.desc.status));
3572 /*----------------------------------------------------------------
3573 * hfa384x_int_rxmonitor
3575 * Helper function for int_rx. Handles monitor frames.
3576 * Note that this function allocates space for the FCS and sets it
3577 * to 0xffffffff. The hfa384x doesn't give us the FCS value but the
3578 * higher layers expect it. 0xffffffff is used as a flag to indicate
3582 * wlandev wlan device structure
3583 * rxfrm rx descriptor read from card in int_rx
3589 * Allocates an skb and passes it up via the PF_PACKET interface.
3592 ----------------------------------------------------------------*/
3593 static void hfa384x_int_rxmonitor(wlandevice_t *wlandev,
3594 hfa384x_usb_rxfrm_t *rxfrm)
3596 hfa384x_rx_frame_t *rxdesc = &(rxfrm->desc);
3597 unsigned int hdrlen = 0;
3598 unsigned int datalen = 0;
3599 unsigned int skblen = 0;
3602 struct sk_buff *skb;
3603 hfa384x_t *hw = wlandev->priv;
3605 /* Don't forget the status, time, and data_len fields are in host order */
3606 /* Figure out how big the frame is */
3607 fc = le16_to_cpu(rxdesc->frame_control);
3608 hdrlen = p80211_headerlen(fc);
3609 datalen = le16_to_cpu(rxdesc->data_len);
3611 /* Allocate an ind message+framesize skb */
3612 skblen = sizeof(p80211_caphdr_t) + hdrlen + datalen + WLAN_CRC_LEN;
3614 /* sanity check the length */
3616 (sizeof(p80211_caphdr_t) +
3617 WLAN_HDR_A4_LEN + WLAN_DATA_MAXLEN + WLAN_CRC_LEN)) {
3618 pr_debug("overlen frm: len=%zd\n",
3619 skblen - sizeof(p80211_caphdr_t));
3622 if ((skb = dev_alloc_skb(skblen)) == NULL) {
3624 "alloc_skb failed trying to allocate %d bytes\n",
3629 /* only prepend the prism header if in the right mode */
3630 if ((wlandev->netdev->type == ARPHRD_IEEE80211_PRISM) &&
3631 (hw->sniffhdr != 0)) {
3632 p80211_caphdr_t *caphdr;
3633 /* The NEW header format! */
3634 datap = skb_put(skb, sizeof(p80211_caphdr_t));
3635 caphdr = (p80211_caphdr_t *) datap;
3637 caphdr->version = htonl(P80211CAPTURE_VERSION);
3638 caphdr->length = htonl(sizeof(p80211_caphdr_t));
3639 caphdr->mactime = __cpu_to_be64(rxdesc->time) * 1000;
3640 caphdr->hosttime = __cpu_to_be64(jiffies);
3641 caphdr->phytype = htonl(4); /* dss_dot11_b */
3642 caphdr->channel = htonl(hw->sniff_channel);
3643 caphdr->datarate = htonl(rxdesc->rate);
3644 caphdr->antenna = htonl(0); /* unknown */
3645 caphdr->priority = htonl(0); /* unknown */
3646 caphdr->ssi_type = htonl(3); /* rssi_raw */
3647 caphdr->ssi_signal = htonl(rxdesc->signal);
3648 caphdr->ssi_noise = htonl(rxdesc->silence);
3649 caphdr->preamble = htonl(0); /* unknown */
3650 caphdr->encoding = htonl(1); /* cck */
3653 /* Copy the 802.11 header to the skb (ctl frames may be less than a full header) */
3654 datap = skb_put(skb, hdrlen);
3655 memcpy(datap, &(rxdesc->frame_control), hdrlen);
3657 /* If any, copy the data from the card to the skb */
3659 datap = skb_put(skb, datalen);
3660 memcpy(datap, rxfrm->data, datalen);
3662 /* check for unencrypted stuff if WEP bit set. */
3663 if (*(datap - hdrlen + 1) & 0x40) /* wep set */
3664 if ((*(datap) == 0xaa) && (*(datap + 1) == 0xaa))
3665 *(datap - hdrlen + 1) &= 0xbf; // clear wep; it's the 802.2 header!
3668 if (hw->sniff_fcs) {
3670 datap = skb_put(skb, WLAN_CRC_LEN);
3671 memset(datap, 0xff, WLAN_CRC_LEN);
3674 /* pass it back up */
3675 prism2sta_ev_rx(wlandev, skb);
3680 /*----------------------------------------------------------------
3681 * hfa384x_usbin_info
3683 * At this point we have a successful received a Prism2 info frame.
3686 * wlandev wlan device
3687 * usbin ptr to the usb transfer buffer
3696 ----------------------------------------------------------------*/
3697 static void hfa384x_usbin_info(wlandevice_t * wlandev, hfa384x_usbin_t * usbin)
3699 usbin->infofrm.info.framelen =
3700 le16_to_cpu(usbin->infofrm.info.framelen);
3701 prism2sta_ev_info(wlandev, &usbin->infofrm.info);
3704 /*----------------------------------------------------------------
3705 * hfa384x_usbout_callback
3707 * Callback for URBs on the BULKOUT endpoint.
3710 * urb ptr to the completed urb
3719 ----------------------------------------------------------------*/
3720 static void hfa384x_usbout_callback(struct urb *urb)
3722 wlandevice_t *wlandev = urb->context;
3723 hfa384x_usbout_t *usbout = urb->transfer_buffer;
3729 if (wlandev && wlandev->netdev) {
3731 switch (urb->status) {
3733 hfa384x_usbout_tx(wlandev, usbout);
3738 hfa384x_t *hw = wlandev->priv;
3740 "%s tx pipe stalled: requesting reset\n",
3741 wlandev->netdev->name);
3742 if (!test_and_set_bit
3743 (WORK_TX_HALT, &hw->usb_flags))
3744 schedule_work(&hw->usb_work);
3745 ++(wlandev->linux_stats.tx_errors);
3753 hfa384x_t *hw = wlandev->priv;
3755 if (!test_and_set_bit
3756 (THROTTLE_TX, &hw->usb_flags)
3757 && !timer_pending(&hw->throttle)) {
3758 mod_timer(&hw->throttle,
3759 jiffies + THROTTLE_JIFFIES);
3761 ++(wlandev->linux_stats.tx_errors);
3762 netif_stop_queue(wlandev->netdev);
3768 /* Ignorable errors */
3772 printk(KERN_INFO "unknown urb->status=%d\n",
3774 ++(wlandev->linux_stats.tx_errors);
3780 /*----------------------------------------------------------------
3781 * hfa384x_ctlxout_callback
3783 * Callback for control data on the BULKOUT endpoint.
3786 * urb ptr to the completed urb
3795 ----------------------------------------------------------------*/
3796 static void hfa384x_ctlxout_callback(struct urb *urb)
3798 hfa384x_t *hw = urb->context;
3799 int delete_resptimer = 0;
3802 hfa384x_usbctlx_t *ctlx;
3803 unsigned long flags;
3805 pr_debug("urb->status=%d\n", urb->status);
3809 if ((urb->status == -ESHUTDOWN) ||
3810 (urb->status == -ENODEV) || (hw == NULL))
3814 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3817 * Only one CTLX at a time on the "active" list, and
3818 * none at all if we are unplugged. However, we can
3819 * rely on the disconnect function to clean everything
3820 * up if someone unplugged the adapter.
3822 if (list_empty(&hw->ctlxq.active)) {
3823 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3828 * Having something on the "active" queue means
3829 * that we have timers to worry about ...
3831 if (del_timer(&hw->reqtimer) == 0) {
3832 if (hw->req_timer_done == 0) {
3834 * This timer was actually running while we
3835 * were trying to delete it. Let it terminate
3836 * gracefully instead.
3838 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3842 hw->req_timer_done = 1;
3845 ctlx = get_active_ctlx(hw);
3847 if (urb->status == 0) {
3848 /* Request portion of a CTLX is successful */
3849 switch (ctlx->state) {
3850 case CTLX_REQ_SUBMITTED:
3851 /* This OUT-ACK received before IN */
3852 ctlx->state = CTLX_REQ_COMPLETE;
3855 case CTLX_RESP_COMPLETE:
3856 /* IN already received before this OUT-ACK,
3857 * so this command must now be complete.
3859 ctlx->state = CTLX_COMPLETE;
3860 unlocked_usbctlx_complete(hw, ctlx);
3865 /* This is NOT a valid CTLX "success" state! */
3867 "Illegal CTLX[%d] success state(%s, %d) in OUT URB\n",
3868 le16_to_cpu(ctlx->outbuf.type),
3869 ctlxstr(ctlx->state), urb->status);
3873 /* If the pipe has stalled then we need to reset it */
3874 if ((urb->status == -EPIPE) &&
3875 !test_and_set_bit(WORK_TX_HALT, &hw->usb_flags)) {
3877 "%s tx pipe stalled: requesting reset\n",
3878 hw->wlandev->netdev->name);
3879 schedule_work(&hw->usb_work);
3882 /* If someone cancels the OUT URB then its status
3883 * should be either -ECONNRESET or -ENOENT.
3885 ctlx->state = CTLX_REQ_FAILED;
3886 unlocked_usbctlx_complete(hw, ctlx);
3887 delete_resptimer = 1;
3892 if (delete_resptimer) {
3893 if ((timer_ok = del_timer(&hw->resptimer)) != 0) {
3894 hw->resp_timer_done = 1;
3898 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3900 if (!timer_ok && (hw->resp_timer_done == 0)) {
3901 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3906 hfa384x_usbctlxq_run(hw);
3912 /*----------------------------------------------------------------
3913 * hfa384x_usbctlx_reqtimerfn
3915 * Timer response function for CTLX request timeouts. If this
3916 * function is called, it means that the callback for the OUT
3917 * URB containing a Prism2.x XXX_Request was never called.
3920 * data a ptr to the hfa384x_t
3929 ----------------------------------------------------------------*/
3930 static void hfa384x_usbctlx_reqtimerfn(unsigned long data)
3932 hfa384x_t *hw = (hfa384x_t *) data;
3933 unsigned long flags;
3935 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3937 hw->req_timer_done = 1;
3939 /* Removing the hardware automatically empties
3940 * the active list ...
3942 if (!list_empty(&hw->ctlxq.active)) {
3944 * We must ensure that our URB is removed from
3945 * the system, if it hasn't already expired.
3947 hw->ctlx_urb.transfer_flags |= URB_ASYNC_UNLINK;
3948 if (usb_unlink_urb(&hw->ctlx_urb) == -EINPROGRESS) {
3949 hfa384x_usbctlx_t *ctlx = get_active_ctlx(hw);
3951 ctlx->state = CTLX_REQ_FAILED;
3953 /* This URB was active, but has now been
3954 * cancelled. It will now have a status of
3955 * -ECONNRESET in the callback function.
3957 * We are cancelling this CTLX, so we're
3958 * not going to need to wait for a response.
3959 * The URB's callback function will check
3960 * that this timer is truly dead.
3962 if (del_timer(&hw->resptimer) != 0)
3963 hw->resp_timer_done = 1;
3967 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3970 /*----------------------------------------------------------------
3971 * hfa384x_usbctlx_resptimerfn
3973 * Timer response function for CTLX response timeouts. If this
3974 * function is called, it means that the callback for the IN
3975 * URB containing a Prism2.x XXX_Response was never called.
3978 * data a ptr to the hfa384x_t
3987 ----------------------------------------------------------------*/
3988 static void hfa384x_usbctlx_resptimerfn(unsigned long data)
3990 hfa384x_t *hw = (hfa384x_t *) data;
3991 unsigned long flags;
3993 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3995 hw->resp_timer_done = 1;
3997 /* The active list will be empty if the
3998 * adapter has been unplugged ...
4000 if (!list_empty(&hw->ctlxq.active)) {
4001 hfa384x_usbctlx_t *ctlx = get_active_ctlx(hw);
4003 if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0) {
4004 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
4005 hfa384x_usbctlxq_run(hw);
4010 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
4017 /*----------------------------------------------------------------
4018 * hfa384x_usb_throttlefn
4031 ----------------------------------------------------------------*/
4032 static void hfa384x_usb_throttlefn(unsigned long data)
4034 hfa384x_t *hw = (hfa384x_t *) data;
4035 unsigned long flags;
4037 spin_lock_irqsave(&hw->ctlxq.lock, flags);
4040 * We need to check BOTH the RX and the TX throttle controls,
4041 * so we use the bitwise OR instead of the logical OR.
4043 pr_debug("flags=0x%lx\n", hw->usb_flags);
4044 if (!hw->wlandev->hwremoved &&
4045 ((test_and_clear_bit(THROTTLE_RX, &hw->usb_flags) &&
4046 !test_and_set_bit(WORK_RX_RESUME, &hw->usb_flags))
4048 (test_and_clear_bit(THROTTLE_TX, &hw->usb_flags) &&
4049 !test_and_set_bit(WORK_TX_RESUME, &hw->usb_flags))
4051 schedule_work(&hw->usb_work);
4054 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
4057 /*----------------------------------------------------------------
4058 * hfa384x_usbctlx_submit
4060 * Called from the doxxx functions to submit a CTLX to the queue
4063 * hw ptr to the hw struct
4064 * ctlx ctlx structure to enqueue
4067 * -ENODEV if the adapter is unplugged
4073 * process or interrupt
4074 ----------------------------------------------------------------*/
4075 static int hfa384x_usbctlx_submit(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx)
4077 unsigned long flags;
4080 spin_lock_irqsave(&hw->ctlxq.lock, flags);
4082 if (hw->wlandev->hwremoved) {
4083 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
4086 ctlx->state = CTLX_PENDING;
4087 list_add_tail(&ctlx->list, &hw->ctlxq.pending);
4089 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
4090 hfa384x_usbctlxq_run(hw);
4097 /*----------------------------------------------------------------
4100 * At this point we have finished a send of a frame. Mark the URB
4101 * as available and call ev_alloc to notify higher layers we're
4105 * wlandev wlan device
4106 * usbout ptr to the usb transfer buffer
4115 ----------------------------------------------------------------*/
4116 static void hfa384x_usbout_tx(wlandevice_t *wlandev, hfa384x_usbout_t *usbout)
4118 prism2sta_ev_alloc(wlandev);
4121 /*----------------------------------------------------------------
4122 * hfa384x_isgood_pdrcore
4124 * Quick check of PDR codes.
4127 * pdrcode PDR code number (host order)
4136 ----------------------------------------------------------------*/
4137 static int hfa384x_isgood_pdrcode(u16 pdrcode)
4140 case HFA384x_PDR_END_OF_PDA:
4141 case HFA384x_PDR_PCB_PARTNUM:
4142 case HFA384x_PDR_PDAVER:
4143 case HFA384x_PDR_NIC_SERIAL:
4144 case HFA384x_PDR_MKK_MEASUREMENTS:
4145 case HFA384x_PDR_NIC_RAMSIZE:
4146 case HFA384x_PDR_MFISUPRANGE:
4147 case HFA384x_PDR_CFISUPRANGE:
4148 case HFA384x_PDR_NICID:
4149 case HFA384x_PDR_MAC_ADDRESS:
4150 case HFA384x_PDR_REGDOMAIN:
4151 case HFA384x_PDR_ALLOWED_CHANNEL:
4152 case HFA384x_PDR_DEFAULT_CHANNEL:
4153 case HFA384x_PDR_TEMPTYPE:
4154 case HFA384x_PDR_IFR_SETTING:
4155 case HFA384x_PDR_RFR_SETTING:
4156 case HFA384x_PDR_HFA3861_BASELINE:
4157 case HFA384x_PDR_HFA3861_SHADOW:
4158 case HFA384x_PDR_HFA3861_IFRF:
4159 case HFA384x_PDR_HFA3861_CHCALSP:
4160 case HFA384x_PDR_HFA3861_CHCALI:
4161 case HFA384x_PDR_3842_NIC_CONFIG:
4162 case HFA384x_PDR_USB_ID:
4163 case HFA384x_PDR_PCI_ID:
4164 case HFA384x_PDR_PCI_IFCONF:
4165 case HFA384x_PDR_PCI_PMCONF:
4166 case HFA384x_PDR_RFENRGY:
4167 case HFA384x_PDR_HFA3861_MANF_TESTSP:
4168 case HFA384x_PDR_HFA3861_MANF_TESTI:
4173 if (pdrcode < 0x1000) {
4174 /* code is OK, but we don't know exactly what it is */
4176 "Encountered unknown PDR#=0x%04x, "
4177 "assuming it's ok.\n", pdrcode);
4182 "Encountered unknown PDR#=0x%04x, "
4183 "(>=0x1000), assuming it's bad.\n", pdrcode);
4188 return 0; /* avoid compiler warnings */