1 /* src/prism2/driver/hfa384x_usb.c
3 * Functions that talk to the USB variantof the Intersil hfa384x MAC
5 * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
6 * --------------------------------------------------------------------
10 * The contents of this file are subject to the Mozilla Public
11 * License Version 1.1 (the "License"); you may not use this file
12 * except in compliance with the License. You may obtain a copy of
13 * the License at http://www.mozilla.org/MPL/
15 * Software distributed under the License is distributed on an "AS
16 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
17 * implied. See the License for the specific language governing
18 * rights and limitations under the License.
20 * Alternatively, the contents of this file may be used under the
21 * terms of the GNU Public License version 2 (the "GPL"), in which
22 * case the provisions of the GPL are applicable instead of the
23 * above. If you wish to allow the use of your version of this file
24 * only under the terms of the GPL and not to allow others to use
25 * your version of this file under the MPL, indicate your decision
26 * by deleting the provisions above and replace them with the notice
27 * and other provisions required by the GPL. If you do not delete
28 * the provisions above, a recipient may use your version of this
29 * file under either the MPL or the GPL.
31 * --------------------------------------------------------------------
33 * Inquiries regarding the linux-wlan Open Source project can be
36 * AbsoluteValue Systems Inc.
38 * http://www.linux-wlan.com
40 * --------------------------------------------------------------------
42 * Portions of the development of this software were funded by
43 * Intersil Corporation as part of PRISM(R) chipset product development.
45 * --------------------------------------------------------------------
47 * This file implements functions that correspond to the prism2/hfa384x
48 * 802.11 MAC hardware and firmware host interface.
50 * The functions can be considered to represent several levels of
51 * abstraction. The lowest level functions are simply C-callable wrappers
52 * around the register accesses. The next higher level represents C-callable
53 * prism2 API functions that match the Intersil documentation as closely
54 * as is reasonable. The next higher layer implements common sequences
55 * of invocations of the API layer (e.g. write to bap, followed by cmd).
58 * hfa384x_drvr_xxx Highest level abstractions provided by the
59 * hfa384x code. They are driver defined wrappers
60 * for common sequences. These functions generally
61 * use the services of the lower levels.
63 * hfa384x_drvr_xxxconfig An example of the drvr level abstraction. These
64 * functions are wrappers for the RID get/set
65 * sequence. They call copy_[to|from]_bap() and
66 * cmd_access(). These functions operate on the
67 * RIDs and buffers without validation. The caller
68 * is responsible for that.
70 * API wrapper functions:
71 * hfa384x_cmd_xxx functions that provide access to the f/w commands.
72 * The function arguments correspond to each command
73 * argument, even command arguments that get packed
74 * into single registers. These functions _just_
75 * issue the command by setting the cmd/parm regs
76 * & reading the status/resp regs. Additional
77 * activities required to fully use a command
78 * (read/write from/to bap, get/set int status etc.)
79 * are implemented separately. Think of these as
80 * C-callable prism2 commands.
82 * Lowest Layer Functions:
83 * hfa384x_docmd_xxx These functions implement the sequence required
84 * to issue any prism2 command. Primarily used by the
85 * hfa384x_cmd_xxx functions.
87 * hfa384x_bap_xxx BAP read/write access functions.
88 * Note: we usually use BAP0 for non-interrupt context
89 * and BAP1 for interrupt context.
91 * hfa384x_dl_xxx download related functions.
93 * Driver State Issues:
94 * Note that there are two pairs of functions that manage the
95 * 'initialized' and 'running' states of the hw/MAC combo. The four
96 * functions are create(), destroy(), start(), and stop(). create()
97 * sets up the data structures required to support the hfa384x_*
98 * functions and destroy() cleans them up. The start() function gets
99 * the actual hardware running and enables the interrupts. The stop()
100 * function shuts the hardware down. The sequence should be:
104 * . Do interesting things w/ the hardware
109 * Note that destroy() can be called without calling stop() first.
110 * --------------------------------------------------------------------
113 #include <linux/module.h>
114 #include <linux/kernel.h>
115 #include <linux/sched.h>
116 #include <linux/types.h>
117 #include <linux/slab.h>
118 #include <linux/wireless.h>
119 #include <linux/netdevice.h>
120 #include <linux/timer.h>
121 #include <linux/io.h>
122 #include <linux/delay.h>
123 #include <asm/byteorder.h>
124 #include <linux/bitops.h>
125 #include <linux/list.h>
126 #include <linux/usb.h>
127 #include <linux/byteorder/generic.h>
129 #include "p80211types.h"
130 #include "p80211hdr.h"
131 #include "p80211mgmt.h"
132 #include "p80211conv.h"
133 #include "p80211msg.h"
134 #include "p80211netdev.h"
135 #include "p80211req.h"
136 #include "p80211metadef.h"
137 #include "p80211metastruct.h"
139 #include "prism2mgmt.h"
146 #define THROTTLE_JIFFIES (HZ / 8)
147 #define URB_ASYNC_UNLINK 0
148 #define USB_QUEUE_BULK 0
150 #define ROUNDUP64(a) (((a) + 63) & ~63)
153 static void dbprint_urb(struct urb *urb);
157 hfa384x_int_rxmonitor(struct wlandevice *wlandev, struct hfa384x_usb_rxfrm *rxfrm);
159 static void hfa384x_usb_defer(struct work_struct *data);
161 static int submit_rx_urb(struct hfa384x *hw, gfp_t flags);
163 static int submit_tx_urb(struct hfa384x *hw, struct urb *tx_urb, gfp_t flags);
165 /*---------------------------------------------------*/
167 static void hfa384x_usbout_callback(struct urb *urb);
168 static void hfa384x_ctlxout_callback(struct urb *urb);
169 static void hfa384x_usbin_callback(struct urb *urb);
172 hfa384x_usbin_txcompl(struct wlandevice *wlandev, union hfa384x_usbin *usbin);
174 static void hfa384x_usbin_rx(struct wlandevice *wlandev, struct sk_buff *skb);
176 static void hfa384x_usbin_info(struct wlandevice *wlandev, union hfa384x_usbin *usbin);
178 static void hfa384x_usbin_ctlx(struct hfa384x *hw, union hfa384x_usbin *usbin,
181 /*---------------------------------------------------*/
182 /* Functions to support the prism2 usb command queue */
184 static void hfa384x_usbctlxq_run(struct hfa384x *hw);
186 static void hfa384x_usbctlx_reqtimerfn(unsigned long data);
188 static void hfa384x_usbctlx_resptimerfn(unsigned long data);
190 static void hfa384x_usb_throttlefn(unsigned long data);
192 static void hfa384x_usbctlx_completion_task(unsigned long data);
194 static void hfa384x_usbctlx_reaper_task(unsigned long data);
196 static int hfa384x_usbctlx_submit(struct hfa384x *hw, struct hfa384x_usbctlx *ctlx);
198 static void unlocked_usbctlx_complete(struct hfa384x *hw, struct hfa384x_usbctlx *ctlx);
200 struct usbctlx_completor {
201 int (*complete)(struct usbctlx_completor *);
205 hfa384x_usbctlx_complete_sync(struct hfa384x *hw,
206 struct hfa384x_usbctlx *ctlx,
207 struct usbctlx_completor *completor);
210 unlocked_usbctlx_cancel_async(struct hfa384x *hw, struct hfa384x_usbctlx *ctlx);
212 static void hfa384x_cb_status(struct hfa384x *hw, const struct hfa384x_usbctlx *ctlx);
215 usbctlx_get_status(const struct hfa384x_usb_statusresp *cmdresp,
216 struct hfa384x_cmdresult *result);
219 usbctlx_get_rridresult(const struct hfa384x_usb_rridresp *rridresp,
220 struct hfa384x_rridresult *result);
222 /*---------------------------------------------------*/
223 /* Low level req/resp CTLX formatters and submitters */
225 hfa384x_docmd(struct hfa384x *hw,
227 struct hfa384x_metacmd *cmd,
228 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
231 hfa384x_dorrid(struct hfa384x *hw,
235 unsigned int riddatalen,
236 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
239 hfa384x_dowrid(struct hfa384x *hw,
243 unsigned int riddatalen,
244 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
247 hfa384x_dormem(struct hfa384x *hw,
253 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
256 hfa384x_dowmem(struct hfa384x *hw,
262 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
264 static int hfa384x_isgood_pdrcode(u16 pdrcode);
266 static inline const char *ctlxstr(CTLX_STATE s)
268 static const char * const ctlx_str[] = {
273 "Request packet submitted",
274 "Request packet completed",
275 "Response packet completed"
281 static inline struct hfa384x_usbctlx *get_active_ctlx(struct hfa384x *hw)
283 return list_entry(hw->ctlxq.active.next, struct hfa384x_usbctlx, list);
287 void dbprint_urb(struct urb *urb)
289 pr_debug("urb->pipe=0x%08x\n", urb->pipe);
290 pr_debug("urb->status=0x%08x\n", urb->status);
291 pr_debug("urb->transfer_flags=0x%08x\n", urb->transfer_flags);
292 pr_debug("urb->transfer_buffer=0x%08x\n",
293 (unsigned int)urb->transfer_buffer);
294 pr_debug("urb->transfer_buffer_length=0x%08x\n",
295 urb->transfer_buffer_length);
296 pr_debug("urb->actual_length=0x%08x\n", urb->actual_length);
297 pr_debug("urb->bandwidth=0x%08x\n", urb->bandwidth);
298 pr_debug("urb->setup_packet(ctl)=0x%08x\n",
299 (unsigned int)urb->setup_packet);
300 pr_debug("urb->start_frame(iso/irq)=0x%08x\n", urb->start_frame);
301 pr_debug("urb->interval(irq)=0x%08x\n", urb->interval);
302 pr_debug("urb->error_count(iso)=0x%08x\n", urb->error_count);
303 pr_debug("urb->timeout=0x%08x\n", urb->timeout);
304 pr_debug("urb->context=0x%08x\n", (unsigned int)urb->context);
305 pr_debug("urb->complete=0x%08x\n", (unsigned int)urb->complete);
309 /*----------------------------------------------------------------
312 * Listen for input data on the BULK-IN pipe. If the pipe has
313 * stalled then schedule it to be reset.
317 * memflags memory allocation flags
320 * error code from submission
324 ----------------------------------------------------------------*/
325 static int submit_rx_urb(struct hfa384x *hw, gfp_t memflags)
330 skb = dev_alloc_skb(sizeof(union hfa384x_usbin));
336 /* Post the IN urb */
337 usb_fill_bulk_urb(&hw->rx_urb, hw->usb,
339 skb->data, sizeof(union hfa384x_usbin),
340 hfa384x_usbin_callback, hw->wlandev);
342 hw->rx_urb_skb = skb;
345 if (!hw->wlandev->hwremoved &&
346 !test_bit(WORK_RX_HALT, &hw->usb_flags)) {
347 result = usb_submit_urb(&hw->rx_urb, memflags);
349 /* Check whether we need to reset the RX pipe */
350 if (result == -EPIPE) {
351 netdev_warn(hw->wlandev->netdev,
352 "%s rx pipe stalled: requesting reset\n",
353 hw->wlandev->netdev->name);
354 if (!test_and_set_bit(WORK_RX_HALT, &hw->usb_flags))
355 schedule_work(&hw->usb_work);
359 /* Don't leak memory if anything should go wrong */
362 hw->rx_urb_skb = NULL;
369 /*----------------------------------------------------------------
372 * Prepares and submits the URB of transmitted data. If the
373 * submission fails then it will schedule the output pipe to
378 * tx_urb URB of data for transmission
379 * memflags memory allocation flags
382 * error code from submission
386 ----------------------------------------------------------------*/
387 static int submit_tx_urb(struct hfa384x *hw, struct urb *tx_urb, gfp_t memflags)
389 struct net_device *netdev = hw->wlandev->netdev;
393 if (netif_running(netdev)) {
394 if (!hw->wlandev->hwremoved &&
395 !test_bit(WORK_TX_HALT, &hw->usb_flags)) {
396 result = usb_submit_urb(tx_urb, memflags);
398 /* Test whether we need to reset the TX pipe */
399 if (result == -EPIPE) {
400 netdev_warn(hw->wlandev->netdev,
401 "%s tx pipe stalled: requesting reset\n",
403 set_bit(WORK_TX_HALT, &hw->usb_flags);
404 schedule_work(&hw->usb_work);
405 } else if (result == 0) {
406 netif_stop_queue(netdev);
414 /*----------------------------------------------------------------
417 * There are some things that the USB stack cannot do while
418 * in interrupt context, so we arrange this function to run
419 * in process context.
422 * hw device structure
428 * process (by design)
429 ----------------------------------------------------------------*/
430 static void hfa384x_usb_defer(struct work_struct *data)
432 struct hfa384x *hw = container_of(data, struct hfa384x, usb_work);
433 struct net_device *netdev = hw->wlandev->netdev;
435 /* Don't bother trying to reset anything if the plug
436 * has been pulled ...
438 if (hw->wlandev->hwremoved)
441 /* Reception has stopped: try to reset the input pipe */
442 if (test_bit(WORK_RX_HALT, &hw->usb_flags)) {
445 usb_kill_urb(&hw->rx_urb); /* Cannot be holding spinlock! */
447 ret = usb_clear_halt(hw->usb, hw->endp_in);
449 netdev_err(hw->wlandev->netdev,
450 "Failed to clear rx pipe for %s: err=%d\n",
453 netdev_info(hw->wlandev->netdev, "%s rx pipe reset complete.\n",
455 clear_bit(WORK_RX_HALT, &hw->usb_flags);
456 set_bit(WORK_RX_RESUME, &hw->usb_flags);
460 /* Resume receiving data back from the device. */
461 if (test_bit(WORK_RX_RESUME, &hw->usb_flags)) {
464 ret = submit_rx_urb(hw, GFP_KERNEL);
466 netdev_err(hw->wlandev->netdev,
467 "Failed to resume %s rx pipe.\n",
470 clear_bit(WORK_RX_RESUME, &hw->usb_flags);
474 /* Transmission has stopped: try to reset the output pipe */
475 if (test_bit(WORK_TX_HALT, &hw->usb_flags)) {
478 usb_kill_urb(&hw->tx_urb);
479 ret = usb_clear_halt(hw->usb, hw->endp_out);
481 netdev_err(hw->wlandev->netdev,
482 "Failed to clear tx pipe for %s: err=%d\n",
485 netdev_info(hw->wlandev->netdev, "%s tx pipe reset complete.\n",
487 clear_bit(WORK_TX_HALT, &hw->usb_flags);
488 set_bit(WORK_TX_RESUME, &hw->usb_flags);
490 /* Stopping the BULK-OUT pipe also blocked
491 * us from sending any more CTLX URBs, so
492 * we need to re-run our queue ...
494 hfa384x_usbctlxq_run(hw);
498 /* Resume transmitting. */
499 if (test_and_clear_bit(WORK_TX_RESUME, &hw->usb_flags))
500 netif_wake_queue(hw->wlandev->netdev);
503 /*----------------------------------------------------------------
506 * Sets up the struct hfa384x data structure for use. Note this
507 * does _not_ initialize the actual hardware, just the data structures
508 * we use to keep track of its state.
511 * hw device structure
512 * irq device irq number
513 * iobase i/o base address for register access
514 * membase memory base address for register access
523 ----------------------------------------------------------------*/
524 void hfa384x_create(struct hfa384x *hw, struct usb_device *usb)
528 /* Set up the waitq */
529 init_waitqueue_head(&hw->cmdq);
531 /* Initialize the command queue */
532 spin_lock_init(&hw->ctlxq.lock);
533 INIT_LIST_HEAD(&hw->ctlxq.pending);
534 INIT_LIST_HEAD(&hw->ctlxq.active);
535 INIT_LIST_HEAD(&hw->ctlxq.completing);
536 INIT_LIST_HEAD(&hw->ctlxq.reapable);
538 /* Initialize the authentication queue */
539 skb_queue_head_init(&hw->authq);
541 tasklet_init(&hw->reaper_bh,
542 hfa384x_usbctlx_reaper_task, (unsigned long)hw);
543 tasklet_init(&hw->completion_bh,
544 hfa384x_usbctlx_completion_task, (unsigned long)hw);
545 INIT_WORK(&hw->link_bh, prism2sta_processing_defer);
546 INIT_WORK(&hw->usb_work, hfa384x_usb_defer);
548 setup_timer(&hw->throttle, hfa384x_usb_throttlefn, (unsigned long)hw);
550 setup_timer(&hw->resptimer, hfa384x_usbctlx_resptimerfn,
553 setup_timer(&hw->reqtimer, hfa384x_usbctlx_reqtimerfn,
556 usb_init_urb(&hw->rx_urb);
557 usb_init_urb(&hw->tx_urb);
558 usb_init_urb(&hw->ctlx_urb);
560 hw->link_status = HFA384x_LINK_NOTCONNECTED;
561 hw->state = HFA384x_STATE_INIT;
563 INIT_WORK(&hw->commsqual_bh, prism2sta_commsqual_defer);
564 setup_timer(&hw->commsqual_timer, prism2sta_commsqual_timer,
568 /*----------------------------------------------------------------
571 * Partner to hfa384x_create(). This function cleans up the hw
572 * structure so that it can be freed by the caller using a simple
573 * kfree. Currently, this function is just a placeholder. If, at some
574 * point in the future, an hw in the 'shutdown' state requires a 'deep'
575 * kfree, this is where it should be done. Note that if this function
576 * is called on a _running_ hw structure, the drvr_stop() function is
580 * hw device structure
583 * nothing, this function is not allowed to fail.
589 ----------------------------------------------------------------*/
590 void hfa384x_destroy(struct hfa384x *hw)
594 if (hw->state == HFA384x_STATE_RUNNING)
595 hfa384x_drvr_stop(hw);
596 hw->state = HFA384x_STATE_PREINIT;
598 kfree(hw->scanresults);
599 hw->scanresults = NULL;
601 /* Now to clean out the auth queue */
602 while ((skb = skb_dequeue(&hw->authq)))
606 static struct hfa384x_usbctlx *usbctlx_alloc(void)
608 struct hfa384x_usbctlx *ctlx;
610 ctlx = kzalloc(sizeof(*ctlx),
611 in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
613 init_completion(&ctlx->done);
619 usbctlx_get_status(const struct hfa384x_usb_statusresp *cmdresp,
620 struct hfa384x_cmdresult *result)
622 result->status = le16_to_cpu(cmdresp->status);
623 result->resp0 = le16_to_cpu(cmdresp->resp0);
624 result->resp1 = le16_to_cpu(cmdresp->resp1);
625 result->resp2 = le16_to_cpu(cmdresp->resp2);
627 pr_debug("cmdresult:status=0x%04x resp0=0x%04x resp1=0x%04x resp2=0x%04x\n",
628 result->status, result->resp0, result->resp1, result->resp2);
630 return result->status & HFA384x_STATUS_RESULT;
634 usbctlx_get_rridresult(const struct hfa384x_usb_rridresp *rridresp,
635 struct hfa384x_rridresult *result)
637 result->rid = le16_to_cpu(rridresp->rid);
638 result->riddata = rridresp->data;
639 result->riddata_len = ((le16_to_cpu(rridresp->frmlen) - 1) * 2);
642 /*----------------------------------------------------------------
644 * This completor must be passed to hfa384x_usbctlx_complete_sync()
645 * when processing a CTLX that returns a struct hfa384x_cmdresult structure.
646 ----------------------------------------------------------------*/
647 struct usbctlx_cmd_completor {
648 struct usbctlx_completor head;
650 const struct hfa384x_usb_statusresp *cmdresp;
651 struct hfa384x_cmdresult *result;
654 static inline int usbctlx_cmd_completor_fn(struct usbctlx_completor *head)
656 struct usbctlx_cmd_completor *complete;
658 complete = (struct usbctlx_cmd_completor *)head;
659 return usbctlx_get_status(complete->cmdresp, complete->result);
662 static inline struct usbctlx_completor *init_cmd_completor(
663 struct usbctlx_cmd_completor
665 const struct hfa384x_usb_statusresp
667 struct hfa384x_cmdresult *result)
669 completor->head.complete = usbctlx_cmd_completor_fn;
670 completor->cmdresp = cmdresp;
671 completor->result = result;
672 return &(completor->head);
675 /*----------------------------------------------------------------
677 * This completor must be passed to hfa384x_usbctlx_complete_sync()
678 * when processing a CTLX that reads a RID.
679 ----------------------------------------------------------------*/
680 struct usbctlx_rrid_completor {
681 struct usbctlx_completor head;
683 const struct hfa384x_usb_rridresp *rridresp;
685 unsigned int riddatalen;
688 static int usbctlx_rrid_completor_fn(struct usbctlx_completor *head)
690 struct usbctlx_rrid_completor *complete;
691 struct hfa384x_rridresult rridresult;
693 complete = (struct usbctlx_rrid_completor *)head;
694 usbctlx_get_rridresult(complete->rridresp, &rridresult);
696 /* Validate the length, note body len calculation in bytes */
697 if (rridresult.riddata_len != complete->riddatalen) {
698 pr_warn("RID len mismatch, rid=0x%04x hlen=%d fwlen=%d\n",
700 complete->riddatalen, rridresult.riddata_len);
704 memcpy(complete->riddata, rridresult.riddata, complete->riddatalen);
708 static inline struct usbctlx_completor *init_rrid_completor(
709 struct usbctlx_rrid_completor
711 const struct hfa384x_usb_rridresp
714 unsigned int riddatalen)
716 completor->head.complete = usbctlx_rrid_completor_fn;
717 completor->rridresp = rridresp;
718 completor->riddata = riddata;
719 completor->riddatalen = riddatalen;
720 return &(completor->head);
723 /*----------------------------------------------------------------
725 * Interprets the results of a synchronous RID-write
726 ----------------------------------------------------------------*/
727 #define init_wrid_completor init_cmd_completor
729 /*----------------------------------------------------------------
731 * Interprets the results of a synchronous memory-write
732 ----------------------------------------------------------------*/
733 #define init_wmem_completor init_cmd_completor
735 /*----------------------------------------------------------------
737 * Interprets the results of a synchronous memory-read
738 ----------------------------------------------------------------*/
739 struct usbctlx_rmem_completor {
740 struct usbctlx_completor head;
742 const struct hfa384x_usb_rmemresp *rmemresp;
747 static int usbctlx_rmem_completor_fn(struct usbctlx_completor *head)
749 struct usbctlx_rmem_completor *complete =
750 (struct usbctlx_rmem_completor *)head;
752 pr_debug("rmemresp:len=%d\n", complete->rmemresp->frmlen);
753 memcpy(complete->data, complete->rmemresp->data, complete->len);
757 static inline struct usbctlx_completor *init_rmem_completor(
758 struct usbctlx_rmem_completor
760 struct hfa384x_usb_rmemresp
765 completor->head.complete = usbctlx_rmem_completor_fn;
766 completor->rmemresp = rmemresp;
767 completor->data = data;
768 completor->len = len;
769 return &(completor->head);
772 /*----------------------------------------------------------------
775 * Ctlx_complete handler for async CMD type control exchanges.
776 * mark the hw struct as such.
778 * Note: If the handling is changed here, it should probably be
779 * changed in docmd as well.
783 * ctlx completed CTLX
792 ----------------------------------------------------------------*/
793 static void hfa384x_cb_status(struct hfa384x *hw, const struct hfa384x_usbctlx *ctlx)
796 struct hfa384x_cmdresult cmdresult;
798 if (ctlx->state != CTLX_COMPLETE) {
799 memset(&cmdresult, 0, sizeof(cmdresult));
801 HFA384x_STATUS_RESULT_SET(HFA384x_CMD_ERR);
803 usbctlx_get_status(&ctlx->inbuf.cmdresp, &cmdresult);
806 ctlx->usercb(hw, &cmdresult, ctlx->usercb_data);
810 static inline int hfa384x_docmd_wait(struct hfa384x *hw, struct hfa384x_metacmd *cmd)
812 return hfa384x_docmd(hw, DOWAIT, cmd, NULL, NULL, NULL);
816 hfa384x_docmd_async(struct hfa384x *hw,
817 struct hfa384x_metacmd *cmd,
818 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
820 return hfa384x_docmd(hw, DOASYNC, cmd, cmdcb, usercb, usercb_data);
824 hfa384x_dorrid_wait(struct hfa384x *hw, u16 rid, void *riddata,
825 unsigned int riddatalen)
827 return hfa384x_dorrid(hw, DOWAIT,
828 rid, riddata, riddatalen, NULL, NULL, NULL);
832 hfa384x_dorrid_async(struct hfa384x *hw,
833 u16 rid, void *riddata, unsigned int riddatalen,
835 ctlx_usercb_t usercb, void *usercb_data)
837 return hfa384x_dorrid(hw, DOASYNC,
838 rid, riddata, riddatalen,
839 cmdcb, usercb, usercb_data);
843 hfa384x_dowrid_wait(struct hfa384x *hw, u16 rid, void *riddata,
844 unsigned int riddatalen)
846 return hfa384x_dowrid(hw, DOWAIT,
847 rid, riddata, riddatalen, NULL, NULL, NULL);
851 hfa384x_dowrid_async(struct hfa384x *hw,
852 u16 rid, void *riddata, unsigned int riddatalen,
854 ctlx_usercb_t usercb, void *usercb_data)
856 return hfa384x_dowrid(hw, DOASYNC,
857 rid, riddata, riddatalen,
858 cmdcb, usercb, usercb_data);
862 hfa384x_dormem_wait(struct hfa384x *hw,
863 u16 page, u16 offset, void *data, unsigned int len)
865 return hfa384x_dormem(hw, DOWAIT,
866 page, offset, data, len, NULL, NULL, NULL);
870 hfa384x_dormem_async(struct hfa384x *hw,
871 u16 page, u16 offset, void *data, unsigned int len,
873 ctlx_usercb_t usercb, void *usercb_data)
875 return hfa384x_dormem(hw, DOASYNC,
876 page, offset, data, len,
877 cmdcb, usercb, usercb_data);
881 hfa384x_dowmem_wait(struct hfa384x *hw,
882 u16 page, u16 offset, void *data, unsigned int len)
884 return hfa384x_dowmem(hw, DOWAIT,
885 page, offset, data, len, NULL, NULL, NULL);
889 hfa384x_dowmem_async(struct hfa384x *hw,
895 ctlx_usercb_t usercb, void *usercb_data)
897 return hfa384x_dowmem(hw, DOASYNC,
898 page, offset, data, len,
899 cmdcb, usercb, usercb_data);
902 /*----------------------------------------------------------------
903 * hfa384x_cmd_initialize
905 * Issues the initialize command and sets the hw->state based
909 * hw device structure
913 * >0 f/w reported error - f/w status code
914 * <0 driver reported error
920 ----------------------------------------------------------------*/
921 int hfa384x_cmd_initialize(struct hfa384x *hw)
925 struct hfa384x_metacmd cmd;
927 cmd.cmd = HFA384x_CMDCODE_INIT;
932 result = hfa384x_docmd_wait(hw, &cmd);
934 pr_debug("cmdresp.init: status=0x%04x, resp0=0x%04x, resp1=0x%04x, resp2=0x%04x\n",
936 cmd.result.resp0, cmd.result.resp1, cmd.result.resp2);
938 for (i = 0; i < HFA384x_NUMPORTS_MAX; i++)
939 hw->port_enabled[i] = 0;
942 hw->link_status = HFA384x_LINK_NOTCONNECTED;
947 /*----------------------------------------------------------------
948 * hfa384x_cmd_disable
950 * Issues the disable command to stop communications on one of
954 * hw device structure
955 * macport MAC port number (host order)
959 * >0 f/w reported failure - f/w status code
960 * <0 driver reported error (timeout|bad arg)
966 ----------------------------------------------------------------*/
967 int hfa384x_cmd_disable(struct hfa384x *hw, u16 macport)
969 struct hfa384x_metacmd cmd;
971 cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_DISABLE) |
972 HFA384x_CMD_MACPORT_SET(macport);
977 return hfa384x_docmd_wait(hw, &cmd);
980 /*----------------------------------------------------------------
983 * Issues the enable command to enable communications on one of
987 * hw device structure
988 * macport MAC port number
992 * >0 f/w reported failure - f/w status code
993 * <0 driver reported error (timeout|bad arg)
999 ----------------------------------------------------------------*/
1000 int hfa384x_cmd_enable(struct hfa384x *hw, u16 macport)
1002 struct hfa384x_metacmd cmd;
1004 cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_ENABLE) |
1005 HFA384x_CMD_MACPORT_SET(macport);
1010 return hfa384x_docmd_wait(hw, &cmd);
1013 /*----------------------------------------------------------------
1014 * hfa384x_cmd_monitor
1016 * Enables the 'monitor mode' of the MAC. Here's the description of
1017 * monitor mode that I've received thus far:
1019 * "The "monitor mode" of operation is that the MAC passes all
1020 * frames for which the PLCP checks are correct. All received
1021 * MPDUs are passed to the host with MAC Port = 7, with a
1022 * receive status of good, FCS error, or undecryptable. Passing
1023 * certain MPDUs is a violation of the 802.11 standard, but useful
1024 * for a debugging tool." Normal communication is not possible
1025 * while monitor mode is enabled.
1028 * hw device structure
1029 * enable a code (0x0b|0x0f) that enables/disables
1030 * monitor mode. (host order)
1034 * >0 f/w reported failure - f/w status code
1035 * <0 driver reported error (timeout|bad arg)
1041 ----------------------------------------------------------------*/
1042 int hfa384x_cmd_monitor(struct hfa384x *hw, u16 enable)
1044 struct hfa384x_metacmd cmd;
1046 cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_MONITOR) |
1047 HFA384x_CMD_AINFO_SET(enable);
1052 return hfa384x_docmd_wait(hw, &cmd);
1055 /*----------------------------------------------------------------
1056 * hfa384x_cmd_download
1058 * Sets the controls for the MAC controller code/data download
1059 * process. The arguments set the mode and address associated
1060 * with a download. Note that the aux registers should be enabled
1061 * prior to setting one of the download enable modes.
1064 * hw device structure
1065 * mode 0 - Disable programming and begin code exec
1066 * 1 - Enable volatile mem programming
1067 * 2 - Enable non-volatile mem programming
1068 * 3 - Program non-volatile section from NV download
1072 * highaddr For mode 1, sets the high & low order bits of
1073 * the "destination address". This address will be
1074 * the execution start address when download is
1075 * subsequently disabled.
1076 * For mode 2, sets the high & low order bits of
1077 * the destination in NV ram.
1078 * For modes 0 & 3, should be zero. (host order)
1079 * NOTE: these are CMD format.
1080 * codelen Length of the data to write in mode 2,
1081 * zero otherwise. (host order)
1085 * >0 f/w reported failure - f/w status code
1086 * <0 driver reported error (timeout|bad arg)
1092 ----------------------------------------------------------------*/
1093 int hfa384x_cmd_download(struct hfa384x *hw, u16 mode, u16 lowaddr,
1094 u16 highaddr, u16 codelen)
1096 struct hfa384x_metacmd cmd;
1098 pr_debug("mode=%d, lowaddr=0x%04x, highaddr=0x%04x, codelen=%d\n",
1099 mode, lowaddr, highaddr, codelen);
1101 cmd.cmd = (HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_DOWNLD) |
1102 HFA384x_CMD_PROGMODE_SET(mode));
1104 cmd.parm0 = lowaddr;
1105 cmd.parm1 = highaddr;
1106 cmd.parm2 = codelen;
1108 return hfa384x_docmd_wait(hw, &cmd);
1111 /*----------------------------------------------------------------
1114 * Perform a reset of the hfa38xx MAC core. We assume that the hw
1115 * structure is in its "created" state. That is, it is initialized
1116 * with proper values. Note that if a reset is done after the
1117 * device has been active for awhile, the caller might have to clean
1118 * up some leftover cruft in the hw structure.
1121 * hw device structure
1122 * holdtime how long (in ms) to hold the reset
1123 * settletime how long (in ms) to wait after releasing
1133 ----------------------------------------------------------------*/
1134 int hfa384x_corereset(struct hfa384x *hw, int holdtime, int settletime, int genesis)
1138 result = usb_reset_device(hw->usb);
1140 netdev_err(hw->wlandev->netdev, "usb_reset_device() failed, result=%d.\n",
1147 /*----------------------------------------------------------------
1148 * hfa384x_usbctlx_complete_sync
1150 * Waits for a synchronous CTLX object to complete,
1151 * and then handles the response.
1154 * hw device structure
1156 * completor functor object to decide what to
1157 * do with the CTLX's result.
1161 * -ERESTARTSYS Interrupted by a signal
1163 * -ENODEV Adapter was unplugged
1164 * ??? Result from completor
1170 ----------------------------------------------------------------*/
1171 static int hfa384x_usbctlx_complete_sync(struct hfa384x *hw,
1172 struct hfa384x_usbctlx *ctlx,
1173 struct usbctlx_completor *completor)
1175 unsigned long flags;
1178 result = wait_for_completion_interruptible(&ctlx->done);
1180 spin_lock_irqsave(&hw->ctlxq.lock, flags);
1183 * We can only handle the CTLX if the USB disconnect
1184 * function has not run yet ...
1187 if (hw->wlandev->hwremoved) {
1188 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1190 } else if (result != 0) {
1194 * We were probably interrupted, so delete
1195 * this CTLX asynchronously, kill the timers
1196 * and the URB, and then start the next
1199 * NOTE: We can only delete the timers and
1200 * the URB if this CTLX is active.
1202 if (ctlx == get_active_ctlx(hw)) {
1203 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1205 del_singleshot_timer_sync(&hw->reqtimer);
1206 del_singleshot_timer_sync(&hw->resptimer);
1207 hw->req_timer_done = 1;
1208 hw->resp_timer_done = 1;
1209 usb_kill_urb(&hw->ctlx_urb);
1211 spin_lock_irqsave(&hw->ctlxq.lock, flags);
1216 * This scenario is so unlikely that I'm
1217 * happy with a grubby "goto" solution ...
1219 if (hw->wlandev->hwremoved)
1224 * The completion task will send this CTLX
1225 * to the reaper the next time it runs. We
1226 * are no longer in a hurry.
1229 ctlx->state = CTLX_REQ_FAILED;
1230 list_move_tail(&ctlx->list, &hw->ctlxq.completing);
1232 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1235 hfa384x_usbctlxq_run(hw);
1237 if (ctlx->state == CTLX_COMPLETE) {
1238 result = completor->complete(completor);
1240 netdev_warn(hw->wlandev->netdev, "CTLX[%d] error: state(%s)\n",
1241 le16_to_cpu(ctlx->outbuf.type),
1242 ctlxstr(ctlx->state));
1246 list_del(&ctlx->list);
1247 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1254 /*----------------------------------------------------------------
1257 * Constructs a command CTLX and submits it.
1259 * NOTE: Any changes to the 'post-submit' code in this function
1260 * need to be carried over to hfa384x_cbcmd() since the handling
1261 * is virtually identical.
1264 * hw device structure
1265 * mode DOWAIT or DOASYNC
1266 * cmd cmd structure. Includes all arguments and result
1267 * data points. All in host order. in host order
1268 * cmdcb command-specific callback
1269 * usercb user callback for async calls, NULL for DOWAIT calls
1270 * usercb_data user supplied data pointer for async calls, NULL
1276 * -ERESTARTSYS Awakened on signal
1277 * >0 command indicated error, Status and Resp0-2 are
1285 ----------------------------------------------------------------*/
1287 hfa384x_docmd(struct hfa384x *hw,
1289 struct hfa384x_metacmd *cmd,
1290 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1293 struct hfa384x_usbctlx *ctlx;
1295 ctlx = usbctlx_alloc();
1301 /* Initialize the command */
1302 ctlx->outbuf.cmdreq.type = cpu_to_le16(HFA384x_USB_CMDREQ);
1303 ctlx->outbuf.cmdreq.cmd = cpu_to_le16(cmd->cmd);
1304 ctlx->outbuf.cmdreq.parm0 = cpu_to_le16(cmd->parm0);
1305 ctlx->outbuf.cmdreq.parm1 = cpu_to_le16(cmd->parm1);
1306 ctlx->outbuf.cmdreq.parm2 = cpu_to_le16(cmd->parm2);
1308 ctlx->outbufsize = sizeof(ctlx->outbuf.cmdreq);
1310 pr_debug("cmdreq: cmd=0x%04x parm0=0x%04x parm1=0x%04x parm2=0x%04x\n",
1311 cmd->cmd, cmd->parm0, cmd->parm1, cmd->parm2);
1313 ctlx->reapable = mode;
1314 ctlx->cmdcb = cmdcb;
1315 ctlx->usercb = usercb;
1316 ctlx->usercb_data = usercb_data;
1318 result = hfa384x_usbctlx_submit(hw, ctlx);
1321 } else if (mode == DOWAIT) {
1322 struct usbctlx_cmd_completor completor;
1325 hfa384x_usbctlx_complete_sync(hw, ctlx,
1326 init_cmd_completor(&completor,
1338 /*----------------------------------------------------------------
1341 * Constructs a read rid CTLX and issues it.
1343 * NOTE: Any changes to the 'post-submit' code in this function
1344 * need to be carried over to hfa384x_cbrrid() since the handling
1345 * is virtually identical.
1348 * hw device structure
1349 * mode DOWAIT or DOASYNC
1350 * rid Read RID number (host order)
1351 * riddata Caller supplied buffer that MAC formatted RID.data
1352 * record will be written to for DOWAIT calls. Should
1353 * be NULL for DOASYNC calls.
1354 * riddatalen Buffer length for DOWAIT calls. Zero for DOASYNC calls.
1355 * cmdcb command callback for async calls, NULL for DOWAIT calls
1356 * usercb user callback for async calls, NULL for DOWAIT calls
1357 * usercb_data user supplied data pointer for async calls, NULL
1363 * -ERESTARTSYS Awakened on signal
1364 * -ENODATA riddatalen != macdatalen
1365 * >0 command indicated error, Status and Resp0-2 are
1371 * interrupt (DOASYNC)
1372 * process (DOWAIT or DOASYNC)
1373 ----------------------------------------------------------------*/
1375 hfa384x_dorrid(struct hfa384x *hw,
1379 unsigned int riddatalen,
1380 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1383 struct hfa384x_usbctlx *ctlx;
1385 ctlx = usbctlx_alloc();
1391 /* Initialize the command */
1392 ctlx->outbuf.rridreq.type = cpu_to_le16(HFA384x_USB_RRIDREQ);
1393 ctlx->outbuf.rridreq.frmlen =
1394 cpu_to_le16(sizeof(ctlx->outbuf.rridreq.rid));
1395 ctlx->outbuf.rridreq.rid = cpu_to_le16(rid);
1397 ctlx->outbufsize = sizeof(ctlx->outbuf.rridreq);
1399 ctlx->reapable = mode;
1400 ctlx->cmdcb = cmdcb;
1401 ctlx->usercb = usercb;
1402 ctlx->usercb_data = usercb_data;
1404 /* Submit the CTLX */
1405 result = hfa384x_usbctlx_submit(hw, ctlx);
1408 } else if (mode == DOWAIT) {
1409 struct usbctlx_rrid_completor completor;
1412 hfa384x_usbctlx_complete_sync(hw, ctlx,
1415 &ctlx->inbuf.rridresp,
1416 riddata, riddatalen));
1423 /*----------------------------------------------------------------
1426 * Constructs a write rid CTLX and issues it.
1428 * NOTE: Any changes to the 'post-submit' code in this function
1429 * need to be carried over to hfa384x_cbwrid() since the handling
1430 * is virtually identical.
1433 * hw device structure
1434 * enum cmd_mode DOWAIT or DOASYNC
1436 * riddata Data portion of RID formatted for MAC
1437 * riddatalen Length of the data portion in bytes
1438 * cmdcb command callback for async calls, NULL for DOWAIT calls
1439 * usercb user callback for async calls, NULL for DOWAIT calls
1440 * usercb_data user supplied data pointer for async calls
1444 * -ETIMEDOUT timed out waiting for register ready or
1445 * command completion
1446 * >0 command indicated error, Status and Resp0-2 are
1452 * interrupt (DOASYNC)
1453 * process (DOWAIT or DOASYNC)
1454 ----------------------------------------------------------------*/
1456 hfa384x_dowrid(struct hfa384x *hw,
1460 unsigned int riddatalen,
1461 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1464 struct hfa384x_usbctlx *ctlx;
1466 ctlx = usbctlx_alloc();
1472 /* Initialize the command */
1473 ctlx->outbuf.wridreq.type = cpu_to_le16(HFA384x_USB_WRIDREQ);
1474 ctlx->outbuf.wridreq.frmlen = cpu_to_le16((sizeof
1475 (ctlx->outbuf.wridreq.rid) +
1476 riddatalen + 1) / 2);
1477 ctlx->outbuf.wridreq.rid = cpu_to_le16(rid);
1478 memcpy(ctlx->outbuf.wridreq.data, riddata, riddatalen);
1480 ctlx->outbufsize = sizeof(ctlx->outbuf.wridreq.type) +
1481 sizeof(ctlx->outbuf.wridreq.frmlen) +
1482 sizeof(ctlx->outbuf.wridreq.rid) + riddatalen;
1484 ctlx->reapable = mode;
1485 ctlx->cmdcb = cmdcb;
1486 ctlx->usercb = usercb;
1487 ctlx->usercb_data = usercb_data;
1489 /* Submit the CTLX */
1490 result = hfa384x_usbctlx_submit(hw, ctlx);
1493 } else if (mode == DOWAIT) {
1494 struct usbctlx_cmd_completor completor;
1495 struct hfa384x_cmdresult wridresult;
1497 result = hfa384x_usbctlx_complete_sync(hw,
1501 &ctlx->inbuf.wridresp,
1509 /*----------------------------------------------------------------
1512 * Constructs a readmem CTLX and issues it.
1514 * NOTE: Any changes to the 'post-submit' code in this function
1515 * need to be carried over to hfa384x_cbrmem() since the handling
1516 * is virtually identical.
1519 * hw device structure
1520 * mode DOWAIT or DOASYNC
1521 * page MAC address space page (CMD format)
1522 * offset MAC address space offset
1523 * data Ptr to data buffer to receive read
1524 * len Length of the data to read (max == 2048)
1525 * cmdcb command callback for async calls, NULL for DOWAIT calls
1526 * usercb user callback for async calls, NULL for DOWAIT calls
1527 * usercb_data user supplied data pointer for async calls
1531 * -ETIMEDOUT timed out waiting for register ready or
1532 * command completion
1533 * >0 command indicated error, Status and Resp0-2 are
1539 * interrupt (DOASYNC)
1540 * process (DOWAIT or DOASYNC)
1541 ----------------------------------------------------------------*/
1543 hfa384x_dormem(struct hfa384x *hw,
1549 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1552 struct hfa384x_usbctlx *ctlx;
1554 ctlx = usbctlx_alloc();
1560 /* Initialize the command */
1561 ctlx->outbuf.rmemreq.type = cpu_to_le16(HFA384x_USB_RMEMREQ);
1562 ctlx->outbuf.rmemreq.frmlen =
1563 cpu_to_le16(sizeof(ctlx->outbuf.rmemreq.offset) +
1564 sizeof(ctlx->outbuf.rmemreq.page) + len);
1565 ctlx->outbuf.rmemreq.offset = cpu_to_le16(offset);
1566 ctlx->outbuf.rmemreq.page = cpu_to_le16(page);
1568 ctlx->outbufsize = sizeof(ctlx->outbuf.rmemreq);
1570 pr_debug("type=0x%04x frmlen=%d offset=0x%04x page=0x%04x\n",
1571 ctlx->outbuf.rmemreq.type,
1572 ctlx->outbuf.rmemreq.frmlen,
1573 ctlx->outbuf.rmemreq.offset, ctlx->outbuf.rmemreq.page);
1575 pr_debug("pktsize=%zd\n", ROUNDUP64(sizeof(ctlx->outbuf.rmemreq)));
1577 ctlx->reapable = mode;
1578 ctlx->cmdcb = cmdcb;
1579 ctlx->usercb = usercb;
1580 ctlx->usercb_data = usercb_data;
1582 result = hfa384x_usbctlx_submit(hw, ctlx);
1585 } else if (mode == DOWAIT) {
1586 struct usbctlx_rmem_completor completor;
1589 hfa384x_usbctlx_complete_sync(hw, ctlx,
1592 &ctlx->inbuf.rmemresp, data,
1600 /*----------------------------------------------------------------
1603 * Constructs a writemem CTLX and issues it.
1605 * NOTE: Any changes to the 'post-submit' code in this function
1606 * need to be carried over to hfa384x_cbwmem() since the handling
1607 * is virtually identical.
1610 * hw device structure
1611 * mode DOWAIT or DOASYNC
1612 * page MAC address space page (CMD format)
1613 * offset MAC address space offset
1614 * data Ptr to data buffer containing write data
1615 * len Length of the data to read (max == 2048)
1616 * cmdcb command callback for async calls, NULL for DOWAIT calls
1617 * usercb user callback for async calls, NULL for DOWAIT calls
1618 * usercb_data user supplied data pointer for async calls.
1622 * -ETIMEDOUT timed out waiting for register ready or
1623 * command completion
1624 * >0 command indicated error, Status and Resp0-2 are
1630 * interrupt (DOWAIT)
1631 * process (DOWAIT or DOASYNC)
1632 ----------------------------------------------------------------*/
1634 hfa384x_dowmem(struct hfa384x *hw,
1640 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1643 struct hfa384x_usbctlx *ctlx;
1645 pr_debug("page=0x%04x offset=0x%04x len=%d\n", page, offset, len);
1647 ctlx = usbctlx_alloc();
1653 /* Initialize the command */
1654 ctlx->outbuf.wmemreq.type = cpu_to_le16(HFA384x_USB_WMEMREQ);
1655 ctlx->outbuf.wmemreq.frmlen =
1656 cpu_to_le16(sizeof(ctlx->outbuf.wmemreq.offset) +
1657 sizeof(ctlx->outbuf.wmemreq.page) + len);
1658 ctlx->outbuf.wmemreq.offset = cpu_to_le16(offset);
1659 ctlx->outbuf.wmemreq.page = cpu_to_le16(page);
1660 memcpy(ctlx->outbuf.wmemreq.data, data, len);
1662 ctlx->outbufsize = sizeof(ctlx->outbuf.wmemreq.type) +
1663 sizeof(ctlx->outbuf.wmemreq.frmlen) +
1664 sizeof(ctlx->outbuf.wmemreq.offset) +
1665 sizeof(ctlx->outbuf.wmemreq.page) + len;
1667 ctlx->reapable = mode;
1668 ctlx->cmdcb = cmdcb;
1669 ctlx->usercb = usercb;
1670 ctlx->usercb_data = usercb_data;
1672 result = hfa384x_usbctlx_submit(hw, ctlx);
1675 } else if (mode == DOWAIT) {
1676 struct usbctlx_cmd_completor completor;
1677 struct hfa384x_cmdresult wmemresult;
1679 result = hfa384x_usbctlx_complete_sync(hw,
1683 &ctlx->inbuf.wmemresp,
1691 /*----------------------------------------------------------------
1692 * hfa384x_drvr_disable
1694 * Issues the disable command to stop communications on one of
1695 * the MACs 'ports'. Only macport 0 is valid for stations.
1696 * APs may also disable macports 1-6. Only ports that have been
1697 * previously enabled may be disabled.
1700 * hw device structure
1701 * macport MAC port number (host order)
1705 * >0 f/w reported failure - f/w status code
1706 * <0 driver reported error (timeout|bad arg)
1712 ----------------------------------------------------------------*/
1713 int hfa384x_drvr_disable(struct hfa384x *hw, u16 macport)
1717 if ((!hw->isap && macport != 0) ||
1718 (hw->isap && !(macport <= HFA384x_PORTID_MAX)) ||
1719 !(hw->port_enabled[macport])) {
1722 result = hfa384x_cmd_disable(hw, macport);
1724 hw->port_enabled[macport] = 0;
1729 /*----------------------------------------------------------------
1730 * hfa384x_drvr_enable
1732 * Issues the enable command to enable communications on one of
1733 * the MACs 'ports'. Only macport 0 is valid for stations.
1734 * APs may also enable macports 1-6. Only ports that are currently
1735 * disabled may be enabled.
1738 * hw device structure
1739 * macport MAC port number
1743 * >0 f/w reported failure - f/w status code
1744 * <0 driver reported error (timeout|bad arg)
1750 ----------------------------------------------------------------*/
1751 int hfa384x_drvr_enable(struct hfa384x *hw, u16 macport)
1755 if ((!hw->isap && macport != 0) ||
1756 (hw->isap && !(macport <= HFA384x_PORTID_MAX)) ||
1757 (hw->port_enabled[macport])) {
1760 result = hfa384x_cmd_enable(hw, macport);
1762 hw->port_enabled[macport] = 1;
1767 /*----------------------------------------------------------------
1768 * hfa384x_drvr_flashdl_enable
1770 * Begins the flash download state. Checks to see that we're not
1771 * already in a download state and that a port isn't enabled.
1772 * Sets the download state and retrieves the flash download
1773 * buffer location, buffer size, and timeout length.
1776 * hw device structure
1780 * >0 f/w reported error - f/w status code
1781 * <0 driver reported error
1787 ----------------------------------------------------------------*/
1788 int hfa384x_drvr_flashdl_enable(struct hfa384x *hw)
1793 /* Check that a port isn't active */
1794 for (i = 0; i < HFA384x_PORTID_MAX; i++) {
1795 if (hw->port_enabled[i]) {
1796 pr_debug("called when port enabled.\n");
1801 /* Check that we're not already in a download state */
1802 if (hw->dlstate != HFA384x_DLSTATE_DISABLED)
1805 /* Retrieve the buffer loc&size and timeout */
1806 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_DOWNLOADBUFFER,
1807 &(hw->bufinfo), sizeof(hw->bufinfo));
1811 hw->bufinfo.page = le16_to_cpu(hw->bufinfo.page);
1812 hw->bufinfo.offset = le16_to_cpu(hw->bufinfo.offset);
1813 hw->bufinfo.len = le16_to_cpu(hw->bufinfo.len);
1814 result = hfa384x_drvr_getconfig16(hw, HFA384x_RID_MAXLOADTIME,
1819 hw->dltimeout = le16_to_cpu(hw->dltimeout);
1821 pr_debug("flashdl_enable\n");
1823 hw->dlstate = HFA384x_DLSTATE_FLASHENABLED;
1828 /*----------------------------------------------------------------
1829 * hfa384x_drvr_flashdl_disable
1831 * Ends the flash download state. Note that this will cause the MAC
1832 * firmware to restart.
1835 * hw device structure
1839 * >0 f/w reported error - f/w status code
1840 * <0 driver reported error
1846 ----------------------------------------------------------------*/
1847 int hfa384x_drvr_flashdl_disable(struct hfa384x *hw)
1849 /* Check that we're already in the download state */
1850 if (hw->dlstate != HFA384x_DLSTATE_FLASHENABLED)
1853 pr_debug("flashdl_enable\n");
1855 /* There isn't much we can do at this point, so I don't */
1856 /* bother w/ the return value */
1857 hfa384x_cmd_download(hw, HFA384x_PROGMODE_DISABLE, 0, 0, 0);
1858 hw->dlstate = HFA384x_DLSTATE_DISABLED;
1863 /*----------------------------------------------------------------
1864 * hfa384x_drvr_flashdl_write
1866 * Performs a FLASH download of a chunk of data. First checks to see
1867 * that we're in the FLASH download state, then sets the download
1868 * mode, uses the aux functions to 1) copy the data to the flash
1869 * buffer, 2) sets the download 'write flash' mode, 3) readback and
1870 * compare. Lather rinse, repeat as many times an necessary to get
1871 * all the given data into flash.
1872 * When all data has been written using this function (possibly
1873 * repeatedly), call drvr_flashdl_disable() to end the download state
1874 * and restart the MAC.
1877 * hw device structure
1878 * daddr Card address to write to. (host order)
1879 * buf Ptr to data to write.
1880 * len Length of data (host order).
1884 * >0 f/w reported error - f/w status code
1885 * <0 driver reported error
1891 ----------------------------------------------------------------*/
1892 int hfa384x_drvr_flashdl_write(struct hfa384x *hw, u32 daddr, void *buf, u32 len)
1909 pr_debug("daddr=0x%08x len=%d\n", daddr, len);
1911 /* Check that we're in the flash download state */
1912 if (hw->dlstate != HFA384x_DLSTATE_FLASHENABLED)
1915 netdev_info(hw->wlandev->netdev,
1916 "Download %d bytes to flash @0x%06x\n", len, daddr);
1918 /* Convert to flat address for arithmetic */
1919 /* NOTE: dlbuffer RID stores the address in AUX format */
1921 HFA384x_ADDR_AUX_MKFLAT(hw->bufinfo.page, hw->bufinfo.offset);
1922 pr_debug("dlbuf.page=0x%04x dlbuf.offset=0x%04x dlbufaddr=0x%08x\n",
1923 hw->bufinfo.page, hw->bufinfo.offset, dlbufaddr);
1924 /* Calculations to determine how many fills of the dlbuffer to do
1925 * and how many USB wmemreq's to do for each fill. At this point
1926 * in time, the dlbuffer size and the wmemreq size are the same.
1927 * Therefore, nwrites should always be 1. The extra complexity
1928 * here is a hedge against future changes.
1931 /* Figure out how many times to do the flash programming */
1932 nburns = len / hw->bufinfo.len;
1933 nburns += (len % hw->bufinfo.len) ? 1 : 0;
1935 /* For each flash program cycle, how many USB wmemreq's are needed? */
1936 nwrites = hw->bufinfo.len / HFA384x_USB_RWMEM_MAXLEN;
1937 nwrites += (hw->bufinfo.len % HFA384x_USB_RWMEM_MAXLEN) ? 1 : 0;
1940 for (i = 0; i < nburns; i++) {
1941 /* Get the dest address and len */
1942 burnlen = (len - (hw->bufinfo.len * i)) > hw->bufinfo.len ?
1943 hw->bufinfo.len : (len - (hw->bufinfo.len * i));
1944 burndaddr = daddr + (hw->bufinfo.len * i);
1945 burnlo = HFA384x_ADDR_CMD_MKOFF(burndaddr);
1946 burnhi = HFA384x_ADDR_CMD_MKPAGE(burndaddr);
1948 netdev_info(hw->wlandev->netdev, "Writing %d bytes to flash @0x%06x\n",
1949 burnlen, burndaddr);
1951 /* Set the download mode */
1952 result = hfa384x_cmd_download(hw, HFA384x_PROGMODE_NV,
1953 burnlo, burnhi, burnlen);
1955 netdev_err(hw->wlandev->netdev,
1956 "download(NV,lo=%x,hi=%x,len=%x) cmd failed, result=%d. Aborting d/l\n",
1957 burnlo, burnhi, burnlen, result);
1961 /* copy the data to the flash download buffer */
1962 for (j = 0; j < nwrites; j++) {
1964 (i * hw->bufinfo.len) +
1965 (j * HFA384x_USB_RWMEM_MAXLEN);
1967 writepage = HFA384x_ADDR_CMD_MKPAGE(dlbufaddr +
1968 (j * HFA384x_USB_RWMEM_MAXLEN));
1969 writeoffset = HFA384x_ADDR_CMD_MKOFF(dlbufaddr +
1970 (j * HFA384x_USB_RWMEM_MAXLEN));
1972 writelen = burnlen - (j * HFA384x_USB_RWMEM_MAXLEN);
1973 writelen = writelen > HFA384x_USB_RWMEM_MAXLEN ?
1974 HFA384x_USB_RWMEM_MAXLEN : writelen;
1976 result = hfa384x_dowmem_wait(hw,
1979 writebuf, writelen);
1982 /* set the download 'write flash' mode */
1983 result = hfa384x_cmd_download(hw,
1984 HFA384x_PROGMODE_NVWRITE,
1987 netdev_err(hw->wlandev->netdev,
1988 "download(NVWRITE,lo=%x,hi=%x,len=%x) cmd failed, result=%d. Aborting d/l\n",
1989 burnlo, burnhi, burnlen, result);
1993 /* TODO: We really should do a readback and compare. */
1998 /* Leave the firmware in the 'post-prog' mode. flashdl_disable will */
1999 /* actually disable programming mode. Remember, that will cause the */
2000 /* the firmware to effectively reset itself. */
2005 /*----------------------------------------------------------------
2006 * hfa384x_drvr_getconfig
2008 * Performs the sequence necessary to read a config/info item.
2011 * hw device structure
2012 * rid config/info record id (host order)
2013 * buf host side record buffer. Upon return it will
2014 * contain the body portion of the record (minus the
2016 * len buffer length (in bytes, should match record length)
2020 * >0 f/w reported error - f/w status code
2021 * <0 driver reported error
2022 * -ENODATA length mismatch between argument and retrieved
2029 ----------------------------------------------------------------*/
2030 int hfa384x_drvr_getconfig(struct hfa384x *hw, u16 rid, void *buf, u16 len)
2032 return hfa384x_dorrid_wait(hw, rid, buf, len);
2035 /*----------------------------------------------------------------
2036 * hfa384x_drvr_setconfig_async
2038 * Performs the sequence necessary to write a config/info item.
2041 * hw device structure
2042 * rid config/info record id (in host order)
2043 * buf host side record buffer
2044 * len buffer length (in bytes)
2045 * usercb completion callback
2046 * usercb_data completion callback argument
2050 * >0 f/w reported error - f/w status code
2051 * <0 driver reported error
2057 ----------------------------------------------------------------*/
2059 hfa384x_drvr_setconfig_async(struct hfa384x *hw,
2062 u16 len, ctlx_usercb_t usercb, void *usercb_data)
2064 return hfa384x_dowrid_async(hw, rid, buf, len,
2065 hfa384x_cb_status, usercb, usercb_data);
2068 /*----------------------------------------------------------------
2069 * hfa384x_drvr_ramdl_disable
2071 * Ends the ram download state.
2074 * hw device structure
2078 * >0 f/w reported error - f/w status code
2079 * <0 driver reported error
2085 ----------------------------------------------------------------*/
2086 int hfa384x_drvr_ramdl_disable(struct hfa384x *hw)
2088 /* Check that we're already in the download state */
2089 if (hw->dlstate != HFA384x_DLSTATE_RAMENABLED)
2092 pr_debug("ramdl_disable()\n");
2094 /* There isn't much we can do at this point, so I don't */
2095 /* bother w/ the return value */
2096 hfa384x_cmd_download(hw, HFA384x_PROGMODE_DISABLE, 0, 0, 0);
2097 hw->dlstate = HFA384x_DLSTATE_DISABLED;
2102 /*----------------------------------------------------------------
2103 * hfa384x_drvr_ramdl_enable
2105 * Begins the ram download state. Checks to see that we're not
2106 * already in a download state and that a port isn't enabled.
2107 * Sets the download state and calls cmd_download with the
2108 * ENABLE_VOLATILE subcommand and the exeaddr argument.
2111 * hw device structure
2112 * exeaddr the card execution address that will be
2113 * jumped to when ramdl_disable() is called
2118 * >0 f/w reported error - f/w status code
2119 * <0 driver reported error
2125 ----------------------------------------------------------------*/
2126 int hfa384x_drvr_ramdl_enable(struct hfa384x *hw, u32 exeaddr)
2133 /* Check that a port isn't active */
2134 for (i = 0; i < HFA384x_PORTID_MAX; i++) {
2135 if (hw->port_enabled[i]) {
2136 netdev_err(hw->wlandev->netdev,
2137 "Can't download with a macport enabled.\n");
2142 /* Check that we're not already in a download state */
2143 if (hw->dlstate != HFA384x_DLSTATE_DISABLED) {
2144 netdev_err(hw->wlandev->netdev, "Download state not disabled.\n");
2148 pr_debug("ramdl_enable, exeaddr=0x%08x\n", exeaddr);
2150 /* Call the download(1,addr) function */
2151 lowaddr = HFA384x_ADDR_CMD_MKOFF(exeaddr);
2152 hiaddr = HFA384x_ADDR_CMD_MKPAGE(exeaddr);
2154 result = hfa384x_cmd_download(hw, HFA384x_PROGMODE_RAM,
2155 lowaddr, hiaddr, 0);
2158 /* Set the download state */
2159 hw->dlstate = HFA384x_DLSTATE_RAMENABLED;
2161 pr_debug("cmd_download(0x%04x, 0x%04x) failed, result=%d.\n",
2162 lowaddr, hiaddr, result);
2168 /*----------------------------------------------------------------
2169 * hfa384x_drvr_ramdl_write
2171 * Performs a RAM download of a chunk of data. First checks to see
2172 * that we're in the RAM download state, then uses the [read|write]mem USB
2173 * commands to 1) copy the data, 2) readback and compare. The download
2174 * state is unaffected. When all data has been written using
2175 * this function, call drvr_ramdl_disable() to end the download state
2176 * and restart the MAC.
2179 * hw device structure
2180 * daddr Card address to write to. (host order)
2181 * buf Ptr to data to write.
2182 * len Length of data (host order).
2186 * >0 f/w reported error - f/w status code
2187 * <0 driver reported error
2193 ----------------------------------------------------------------*/
2194 int hfa384x_drvr_ramdl_write(struct hfa384x *hw, u32 daddr, void *buf, u32 len)
2205 /* Check that we're in the ram download state */
2206 if (hw->dlstate != HFA384x_DLSTATE_RAMENABLED)
2209 netdev_info(hw->wlandev->netdev, "Writing %d bytes to ram @0x%06x\n",
2212 /* How many dowmem calls? */
2213 nwrites = len / HFA384x_USB_RWMEM_MAXLEN;
2214 nwrites += len % HFA384x_USB_RWMEM_MAXLEN ? 1 : 0;
2216 /* Do blocking wmem's */
2217 for (i = 0; i < nwrites; i++) {
2218 /* make address args */
2219 curraddr = daddr + (i * HFA384x_USB_RWMEM_MAXLEN);
2220 currpage = HFA384x_ADDR_CMD_MKPAGE(curraddr);
2221 curroffset = HFA384x_ADDR_CMD_MKOFF(curraddr);
2222 currlen = len - (i * HFA384x_USB_RWMEM_MAXLEN);
2223 if (currlen > HFA384x_USB_RWMEM_MAXLEN)
2224 currlen = HFA384x_USB_RWMEM_MAXLEN;
2226 /* Do blocking ctlx */
2227 result = hfa384x_dowmem_wait(hw,
2231 (i * HFA384x_USB_RWMEM_MAXLEN),
2237 /* TODO: We really should have a readback. */
2243 /*----------------------------------------------------------------
2244 * hfa384x_drvr_readpda
2246 * Performs the sequence to read the PDA space. Note there is no
2247 * drvr_writepda() function. Writing a PDA is
2248 * generally implemented by a calling component via calls to
2249 * cmd_download and writing to the flash download buffer via the
2253 * hw device structure
2254 * buf buffer to store PDA in
2259 * >0 f/w reported error - f/w status code
2260 * <0 driver reported error
2261 * -ETIMEDOUT timeout waiting for the cmd regs to become
2262 * available, or waiting for the control reg
2263 * to indicate the Aux port is enabled.
2264 * -ENODATA the buffer does NOT contain a valid PDA.
2265 * Either the card PDA is bad, or the auxdata
2266 * reads are giving us garbage.
2272 * process or non-card interrupt.
2273 ----------------------------------------------------------------*/
2274 int hfa384x_drvr_readpda(struct hfa384x *hw, void *buf, unsigned int len)
2280 int currpdr = 0; /* word offset of the current pdr */
2282 u16 pdrlen; /* pdr length in bytes, host order */
2283 u16 pdrcode; /* pdr code, host order */
2291 HFA3842_PDA_BASE, 0}, {
2292 HFA3841_PDA_BASE, 0}, {
2293 HFA3841_PDA_BOGUS_BASE, 0}
2296 /* Read the pda from each known address. */
2297 for (i = 0; i < ARRAY_SIZE(pdaloc); i++) {
2299 currpage = HFA384x_ADDR_CMD_MKPAGE(pdaloc[i].cardaddr);
2300 curroffset = HFA384x_ADDR_CMD_MKOFF(pdaloc[i].cardaddr);
2302 /* units of bytes */
2303 result = hfa384x_dormem_wait(hw, currpage, curroffset, buf,
2307 netdev_warn(hw->wlandev->netdev,
2308 "Read from index %zd failed, continuing\n",
2313 /* Test for garbage */
2314 pdaok = 1; /* initially assume good */
2316 while (pdaok && morepdrs) {
2317 pdrlen = le16_to_cpu(pda[currpdr]) * 2;
2318 pdrcode = le16_to_cpu(pda[currpdr + 1]);
2319 /* Test the record length */
2320 if (pdrlen > HFA384x_PDR_LEN_MAX || pdrlen == 0) {
2321 netdev_err(hw->wlandev->netdev,
2322 "pdrlen invalid=%d\n", pdrlen);
2327 if (!hfa384x_isgood_pdrcode(pdrcode)) {
2328 netdev_err(hw->wlandev->netdev, "pdrcode invalid=%d\n",
2333 /* Test for completion */
2334 if (pdrcode == HFA384x_PDR_END_OF_PDA)
2337 /* Move to the next pdr (if necessary) */
2339 /* note the access to pda[], need words here */
2340 currpdr += le16_to_cpu(pda[currpdr]) + 1;
2344 netdev_info(hw->wlandev->netdev,
2345 "PDA Read from 0x%08x in %s space.\n",
2347 pdaloc[i].auxctl == 0 ? "EXTDS" :
2348 pdaloc[i].auxctl == 1 ? "NV" :
2349 pdaloc[i].auxctl == 2 ? "PHY" :
2350 pdaloc[i].auxctl == 3 ? "ICSRAM" :
2355 result = pdaok ? 0 : -ENODATA;
2358 pr_debug("Failure: pda is not okay\n");
2363 /*----------------------------------------------------------------
2364 * hfa384x_drvr_setconfig
2366 * Performs the sequence necessary to write a config/info item.
2369 * hw device structure
2370 * rid config/info record id (in host order)
2371 * buf host side record buffer
2372 * len buffer length (in bytes)
2376 * >0 f/w reported error - f/w status code
2377 * <0 driver reported error
2383 ----------------------------------------------------------------*/
2384 int hfa384x_drvr_setconfig(struct hfa384x *hw, u16 rid, void *buf, u16 len)
2386 return hfa384x_dowrid_wait(hw, rid, buf, len);
2389 /*----------------------------------------------------------------
2390 * hfa384x_drvr_start
2392 * Issues the MAC initialize command, sets up some data structures,
2393 * and enables the interrupts. After this function completes, the
2394 * low-level stuff should be ready for any/all commands.
2397 * hw device structure
2400 * >0 f/w reported error - f/w status code
2401 * <0 driver reported error
2407 ----------------------------------------------------------------*/
2409 int hfa384x_drvr_start(struct hfa384x *hw)
2411 int result, result1, result2;
2416 /* Clear endpoint stalls - but only do this if the endpoint
2417 * is showing a stall status. Some prism2 cards seem to behave
2418 * badly if a clear_halt is called when the endpoint is already
2422 usb_get_status(hw->usb, USB_RECIP_ENDPOINT, hw->endp_in, &status);
2424 netdev_err(hw->wlandev->netdev, "Cannot get bulk in endpoint status.\n");
2427 if ((status == 1) && usb_clear_halt(hw->usb, hw->endp_in))
2428 netdev_err(hw->wlandev->netdev, "Failed to reset bulk in endpoint.\n");
2431 usb_get_status(hw->usb, USB_RECIP_ENDPOINT, hw->endp_out, &status);
2433 netdev_err(hw->wlandev->netdev, "Cannot get bulk out endpoint status.\n");
2436 if ((status == 1) && usb_clear_halt(hw->usb, hw->endp_out))
2437 netdev_err(hw->wlandev->netdev, "Failed to reset bulk out endpoint.\n");
2439 /* Synchronous unlink, in case we're trying to restart the driver */
2440 usb_kill_urb(&hw->rx_urb);
2442 /* Post the IN urb */
2443 result = submit_rx_urb(hw, GFP_KERNEL);
2445 netdev_err(hw->wlandev->netdev,
2446 "Fatal, failed to submit RX URB, result=%d\n",
2451 /* Call initialize twice, with a 1 second sleep in between.
2452 * This is a nasty work-around since many prism2 cards seem to
2453 * need time to settle after an init from cold. The second
2454 * call to initialize in theory is not necessary - but we call
2455 * it anyway as a double insurance policy:
2456 * 1) If the first init should fail, the second may well succeed
2457 * and the card can still be used
2458 * 2) It helps ensures all is well with the card after the first
2459 * init and settle time.
2461 result1 = hfa384x_cmd_initialize(hw);
2463 result = hfa384x_cmd_initialize(hw);
2467 netdev_err(hw->wlandev->netdev,
2468 "cmd_initialize() failed on two attempts, results %d and %d\n",
2470 usb_kill_urb(&hw->rx_urb);
2473 pr_debug("First cmd_initialize() failed (result %d),\n",
2475 pr_debug("but second attempt succeeded. All should be ok\n");
2477 } else if (result2 != 0) {
2478 netdev_warn(hw->wlandev->netdev, "First cmd_initialize() succeeded, but second attempt failed (result=%d)\n",
2480 netdev_warn(hw->wlandev->netdev,
2481 "Most likely the card will be functional\n");
2485 hw->state = HFA384x_STATE_RUNNING;
2491 /*----------------------------------------------------------------
2494 * Shuts down the MAC to the point where it is safe to unload the
2495 * driver. Any subsystem that may be holding a data or function
2496 * ptr into the driver must be cleared/deinitialized.
2499 * hw device structure
2502 * >0 f/w reported error - f/w status code
2503 * <0 driver reported error
2509 ----------------------------------------------------------------*/
2510 int hfa384x_drvr_stop(struct hfa384x *hw)
2516 /* There's no need for spinlocks here. The USB "disconnect"
2517 * function sets this "removed" flag and then calls us.
2519 if (!hw->wlandev->hwremoved) {
2520 /* Call initialize to leave the MAC in its 'reset' state */
2521 hfa384x_cmd_initialize(hw);
2523 /* Cancel the rxurb */
2524 usb_kill_urb(&hw->rx_urb);
2527 hw->link_status = HFA384x_LINK_NOTCONNECTED;
2528 hw->state = HFA384x_STATE_INIT;
2530 del_timer_sync(&hw->commsqual_timer);
2532 /* Clear all the port status */
2533 for (i = 0; i < HFA384x_NUMPORTS_MAX; i++)
2534 hw->port_enabled[i] = 0;
2539 /*----------------------------------------------------------------
2540 * hfa384x_drvr_txframe
2542 * Takes a frame from prism2sta and queues it for transmission.
2545 * hw device structure
2546 * skb packet buffer struct. Contains an 802.11
2548 * p80211_hdr points to the 802.11 header for the packet.
2550 * 0 Success and more buffs available
2551 * 1 Success but no more buffs
2552 * 2 Allocation failure
2553 * 4 Buffer full or queue busy
2559 ----------------------------------------------------------------*/
2560 int hfa384x_drvr_txframe(struct hfa384x *hw, struct sk_buff *skb,
2561 union p80211_hdr *p80211_hdr,
2562 struct p80211_metawep *p80211_wep)
2564 int usbpktlen = sizeof(struct hfa384x_tx_frame);
2569 if (hw->tx_urb.status == -EINPROGRESS) {
2570 netdev_warn(hw->wlandev->netdev, "TX URB already in use\n");
2575 /* Build Tx frame structure */
2576 /* Set up the control field */
2577 memset(&hw->txbuff.txfrm.desc, 0, sizeof(hw->txbuff.txfrm.desc));
2579 /* Setup the usb type field */
2580 hw->txbuff.type = cpu_to_le16(HFA384x_USB_TXFRM);
2582 /* Set up the sw_support field to identify this frame */
2583 hw->txbuff.txfrm.desc.sw_support = 0x0123;
2585 /* Tx complete and Tx exception disable per dleach. Might be causing
2588 /* #define DOEXC SLP -- doboth breaks horribly under load, doexc less so. */
2590 hw->txbuff.txfrm.desc.tx_control =
2591 HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
2592 HFA384x_TX_TXEX_SET(1) | HFA384x_TX_TXOK_SET(1);
2593 #elif defined(DOEXC)
2594 hw->txbuff.txfrm.desc.tx_control =
2595 HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
2596 HFA384x_TX_TXEX_SET(1) | HFA384x_TX_TXOK_SET(0);
2598 hw->txbuff.txfrm.desc.tx_control =
2599 HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
2600 HFA384x_TX_TXEX_SET(0) | HFA384x_TX_TXOK_SET(0);
2602 hw->txbuff.txfrm.desc.tx_control =
2603 cpu_to_le16(hw->txbuff.txfrm.desc.tx_control);
2605 /* copy the header over to the txdesc */
2606 memcpy(&(hw->txbuff.txfrm.desc.frame_control), p80211_hdr,
2607 sizeof(union p80211_hdr));
2609 /* if we're using host WEP, increase size by IV+ICV */
2610 if (p80211_wep->data) {
2611 hw->txbuff.txfrm.desc.data_len = cpu_to_le16(skb->len + 8);
2614 hw->txbuff.txfrm.desc.data_len = cpu_to_le16(skb->len);
2617 usbpktlen += skb->len;
2619 /* copy over the WEP IV if we are using host WEP */
2620 ptr = hw->txbuff.txfrm.data;
2621 if (p80211_wep->data) {
2622 memcpy(ptr, p80211_wep->iv, sizeof(p80211_wep->iv));
2623 ptr += sizeof(p80211_wep->iv);
2624 memcpy(ptr, p80211_wep->data, skb->len);
2626 memcpy(ptr, skb->data, skb->len);
2628 /* copy over the packet data */
2631 /* copy over the WEP ICV if we are using host WEP */
2632 if (p80211_wep->data)
2633 memcpy(ptr, p80211_wep->icv, sizeof(p80211_wep->icv));
2635 /* Send the USB packet */
2636 usb_fill_bulk_urb(&(hw->tx_urb), hw->usb,
2638 &(hw->txbuff), ROUNDUP64(usbpktlen),
2639 hfa384x_usbout_callback, hw->wlandev);
2640 hw->tx_urb.transfer_flags |= USB_QUEUE_BULK;
2643 ret = submit_tx_urb(hw, &hw->tx_urb, GFP_ATOMIC);
2645 netdev_err(hw->wlandev->netdev,
2646 "submit_tx_urb() failed, error=%d\n", ret);
2654 void hfa384x_tx_timeout(struct wlandevice *wlandev)
2656 struct hfa384x *hw = wlandev->priv;
2657 unsigned long flags;
2659 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2661 if (!hw->wlandev->hwremoved) {
2664 sched = !test_and_set_bit(WORK_TX_HALT, &hw->usb_flags);
2665 sched |= !test_and_set_bit(WORK_RX_HALT, &hw->usb_flags);
2667 schedule_work(&hw->usb_work);
2670 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2673 /*----------------------------------------------------------------
2674 * hfa384x_usbctlx_reaper_task
2676 * Tasklet to delete dead CTLX objects
2679 * data ptr to a struct hfa384x
2685 ----------------------------------------------------------------*/
2686 static void hfa384x_usbctlx_reaper_task(unsigned long data)
2688 struct hfa384x *hw = (struct hfa384x *)data;
2689 struct hfa384x_usbctlx *ctlx, *temp;
2690 unsigned long flags;
2692 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2694 /* This list is guaranteed to be empty if someone
2695 * has unplugged the adapter.
2697 list_for_each_entry_safe(ctlx, temp, &hw->ctlxq.reapable, list) {
2698 list_del(&ctlx->list);
2702 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2705 /*----------------------------------------------------------------
2706 * hfa384x_usbctlx_completion_task
2708 * Tasklet to call completion handlers for returned CTLXs
2711 * data ptr to struct hfa384x
2718 ----------------------------------------------------------------*/
2719 static void hfa384x_usbctlx_completion_task(unsigned long data)
2721 struct hfa384x *hw = (struct hfa384x *)data;
2722 struct hfa384x_usbctlx *ctlx, *temp;
2723 unsigned long flags;
2727 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2729 /* This list is guaranteed to be empty if someone
2730 * has unplugged the adapter ...
2732 list_for_each_entry_safe(ctlx, temp, &hw->ctlxq.completing, list) {
2733 /* Call the completion function that this
2734 * command was assigned, assuming it has one.
2737 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2738 ctlx->cmdcb(hw, ctlx);
2739 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2741 /* Make sure we don't try and complete
2742 * this CTLX more than once!
2746 /* Did someone yank the adapter out
2747 * while our list was (briefly) unlocked?
2749 if (hw->wlandev->hwremoved) {
2756 * "Reapable" CTLXs are ones which don't have any
2757 * threads waiting for them to die. Hence they must
2758 * be delivered to The Reaper!
2760 if (ctlx->reapable) {
2761 /* Move the CTLX off the "completing" list (hopefully)
2762 * on to the "reapable" list where the reaper task
2763 * can find it. And "reapable" means that this CTLX
2764 * isn't sitting on a wait-queue somewhere.
2766 list_move_tail(&ctlx->list, &hw->ctlxq.reapable);
2770 complete(&ctlx->done);
2772 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2775 tasklet_schedule(&hw->reaper_bh);
2778 /*----------------------------------------------------------------
2779 * unlocked_usbctlx_cancel_async
2781 * Mark the CTLX dead asynchronously, and ensure that the
2782 * next command on the queue is run afterwards.
2785 * hw ptr to the struct hfa384x structure
2786 * ctlx ptr to a CTLX structure
2789 * 0 the CTLX's URB is inactive
2790 * -EINPROGRESS the URB is currently being unlinked
2793 * Either process or interrupt, but presumably interrupt
2794 ----------------------------------------------------------------*/
2795 static int unlocked_usbctlx_cancel_async(struct hfa384x *hw,
2796 struct hfa384x_usbctlx *ctlx)
2801 * Try to delete the URB containing our request packet.
2802 * If we succeed, then its completion handler will be
2803 * called with a status of -ECONNRESET.
2805 hw->ctlx_urb.transfer_flags |= URB_ASYNC_UNLINK;
2806 ret = usb_unlink_urb(&hw->ctlx_urb);
2808 if (ret != -EINPROGRESS) {
2810 * The OUT URB had either already completed
2811 * or was still in the pending queue, so the
2812 * URB's completion function will not be called.
2813 * We will have to complete the CTLX ourselves.
2815 ctlx->state = CTLX_REQ_FAILED;
2816 unlocked_usbctlx_complete(hw, ctlx);
2823 /*----------------------------------------------------------------
2824 * unlocked_usbctlx_complete
2826 * A CTLX has completed. It may have been successful, it may not
2827 * have been. At this point, the CTLX should be quiescent. The URBs
2828 * aren't active and the timers should have been stopped.
2830 * The CTLX is migrated to the "completing" queue, and the completing
2831 * tasklet is scheduled.
2834 * hw ptr to a struct hfa384x structure
2835 * ctlx ptr to a ctlx structure
2843 * Either, assume interrupt
2844 ----------------------------------------------------------------*/
2845 static void unlocked_usbctlx_complete(struct hfa384x *hw, struct hfa384x_usbctlx *ctlx)
2847 /* Timers have been stopped, and ctlx should be in
2848 * a terminal state. Retire it from the "active"
2851 list_move_tail(&ctlx->list, &hw->ctlxq.completing);
2852 tasklet_schedule(&hw->completion_bh);
2854 switch (ctlx->state) {
2856 case CTLX_REQ_FAILED:
2857 /* This are the correct terminating states. */
2861 netdev_err(hw->wlandev->netdev, "CTLX[%d] not in a terminating state(%s)\n",
2862 le16_to_cpu(ctlx->outbuf.type),
2863 ctlxstr(ctlx->state));
2868 /*----------------------------------------------------------------
2869 * hfa384x_usbctlxq_run
2871 * Checks to see if the head item is running. If not, starts it.
2874 * hw ptr to struct hfa384x
2883 ----------------------------------------------------------------*/
2884 static void hfa384x_usbctlxq_run(struct hfa384x *hw)
2886 unsigned long flags;
2889 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2891 /* Only one active CTLX at any one time, because there's no
2892 * other (reliable) way to match the response URB to the
2895 * Don't touch any of these CTLXs if the hardware
2896 * has been removed or the USB subsystem is stalled.
2898 if (!list_empty(&hw->ctlxq.active) ||
2899 test_bit(WORK_TX_HALT, &hw->usb_flags) || hw->wlandev->hwremoved)
2902 while (!list_empty(&hw->ctlxq.pending)) {
2903 struct hfa384x_usbctlx *head;
2906 /* This is the first pending command */
2907 head = list_entry(hw->ctlxq.pending.next,
2908 struct hfa384x_usbctlx, list);
2910 /* We need to split this off to avoid a race condition */
2911 list_move_tail(&head->list, &hw->ctlxq.active);
2913 /* Fill the out packet */
2914 usb_fill_bulk_urb(&(hw->ctlx_urb), hw->usb,
2916 &(head->outbuf), ROUNDUP64(head->outbufsize),
2917 hfa384x_ctlxout_callback, hw);
2918 hw->ctlx_urb.transfer_flags |= USB_QUEUE_BULK;
2920 /* Now submit the URB and update the CTLX's state */
2921 result = usb_submit_urb(&hw->ctlx_urb, GFP_ATOMIC);
2923 /* This CTLX is now running on the active queue */
2924 head->state = CTLX_REQ_SUBMITTED;
2926 /* Start the OUT wait timer */
2927 hw->req_timer_done = 0;
2928 hw->reqtimer.expires = jiffies + HZ;
2929 add_timer(&hw->reqtimer);
2931 /* Start the IN wait timer */
2932 hw->resp_timer_done = 0;
2933 hw->resptimer.expires = jiffies + 2 * HZ;
2934 add_timer(&hw->resptimer);
2939 if (result == -EPIPE) {
2940 /* The OUT pipe needs resetting, so put
2941 * this CTLX back in the "pending" queue
2942 * and schedule a reset ...
2944 netdev_warn(hw->wlandev->netdev,
2945 "%s tx pipe stalled: requesting reset\n",
2946 hw->wlandev->netdev->name);
2947 list_move(&head->list, &hw->ctlxq.pending);
2948 set_bit(WORK_TX_HALT, &hw->usb_flags);
2949 schedule_work(&hw->usb_work);
2953 if (result == -ESHUTDOWN) {
2954 netdev_warn(hw->wlandev->netdev, "%s urb shutdown!\n",
2955 hw->wlandev->netdev->name);
2959 netdev_err(hw->wlandev->netdev, "Failed to submit CTLX[%d]: error=%d\n",
2960 le16_to_cpu(head->outbuf.type), result);
2961 unlocked_usbctlx_complete(hw, head);
2965 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2968 /*----------------------------------------------------------------
2969 * hfa384x_usbin_callback
2971 * Callback for URBs on the BULKIN endpoint.
2974 * urb ptr to the completed urb
2983 ----------------------------------------------------------------*/
2984 static void hfa384x_usbin_callback(struct urb *urb)
2986 struct wlandevice *wlandev = urb->context;
2988 union hfa384x_usbin *usbin = (union hfa384x_usbin *)urb->transfer_buffer;
2989 struct sk_buff *skb = NULL;
3000 if (!wlandev || !wlandev->netdev || wlandev->hwremoved)
3007 skb = hw->rx_urb_skb;
3008 BUG_ON(!skb || (skb->data != urb->transfer_buffer));
3010 hw->rx_urb_skb = NULL;
3012 /* Check for error conditions within the URB */
3013 switch (urb->status) {
3017 /* Check for short packet */
3018 if (urb->actual_length == 0) {
3019 wlandev->netdev->stats.rx_errors++;
3020 wlandev->netdev->stats.rx_length_errors++;
3026 netdev_warn(hw->wlandev->netdev, "%s rx pipe stalled: requesting reset\n",
3027 wlandev->netdev->name);
3028 if (!test_and_set_bit(WORK_RX_HALT, &hw->usb_flags))
3029 schedule_work(&hw->usb_work);
3030 wlandev->netdev->stats.rx_errors++;
3037 if (!test_and_set_bit(THROTTLE_RX, &hw->usb_flags) &&
3038 !timer_pending(&hw->throttle)) {
3039 mod_timer(&hw->throttle, jiffies + THROTTLE_JIFFIES);
3041 wlandev->netdev->stats.rx_errors++;
3046 wlandev->netdev->stats.rx_over_errors++;
3052 pr_debug("status=%d, device removed.\n", urb->status);
3058 pr_debug("status=%d, urb explicitly unlinked.\n", urb->status);
3063 pr_debug("urb status=%d, transfer flags=0x%x\n",
3064 urb->status, urb->transfer_flags);
3065 wlandev->netdev->stats.rx_errors++;
3070 urb_status = urb->status;
3072 if (action != ABORT) {
3073 /* Repost the RX URB */
3074 result = submit_rx_urb(hw, GFP_ATOMIC);
3077 netdev_err(hw->wlandev->netdev,
3078 "Fatal, failed to resubmit rx_urb. error=%d\n",
3083 /* Handle any USB-IN packet */
3084 /* Note: the check of the sw_support field, the type field doesn't
3085 * have bit 12 set like the docs suggest.
3087 type = le16_to_cpu(usbin->type);
3088 if (HFA384x_USB_ISRXFRM(type)) {
3089 if (action == HANDLE) {
3090 if (usbin->txfrm.desc.sw_support == 0x0123) {
3091 hfa384x_usbin_txcompl(wlandev, usbin);
3093 skb_put(skb, sizeof(*usbin));
3094 hfa384x_usbin_rx(wlandev, skb);
3100 if (HFA384x_USB_ISTXFRM(type)) {
3101 if (action == HANDLE)
3102 hfa384x_usbin_txcompl(wlandev, usbin);
3106 case HFA384x_USB_INFOFRM:
3107 if (action == ABORT)
3109 if (action == HANDLE)
3110 hfa384x_usbin_info(wlandev, usbin);
3113 case HFA384x_USB_CMDRESP:
3114 case HFA384x_USB_WRIDRESP:
3115 case HFA384x_USB_RRIDRESP:
3116 case HFA384x_USB_WMEMRESP:
3117 case HFA384x_USB_RMEMRESP:
3118 /* ALWAYS, ALWAYS, ALWAYS handle this CTLX!!!! */
3119 hfa384x_usbin_ctlx(hw, usbin, urb_status);
3122 case HFA384x_USB_BUFAVAIL:
3123 pr_debug("Received BUFAVAIL packet, frmlen=%d\n",
3124 usbin->bufavail.frmlen);
3127 case HFA384x_USB_ERROR:
3128 pr_debug("Received USB_ERROR packet, errortype=%d\n",
3129 usbin->usberror.errortype);
3133 pr_debug("Unrecognized USBIN packet, type=%x, status=%d\n",
3134 usbin->type, urb_status);
3144 /*----------------------------------------------------------------
3145 * hfa384x_usbin_ctlx
3147 * We've received a URB containing a Prism2 "response" message.
3148 * This message needs to be matched up with a CTLX on the active
3149 * queue and our state updated accordingly.
3152 * hw ptr to struct hfa384x
3153 * usbin ptr to USB IN packet
3154 * urb_status status of this Bulk-In URB
3163 ----------------------------------------------------------------*/
3164 static void hfa384x_usbin_ctlx(struct hfa384x *hw, union hfa384x_usbin *usbin,
3167 struct hfa384x_usbctlx *ctlx;
3169 unsigned long flags;
3172 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3174 /* There can be only one CTLX on the active queue
3175 * at any one time, and this is the CTLX that the
3176 * timers are waiting for.
3178 if (list_empty(&hw->ctlxq.active))
3181 /* Remove the "response timeout". It's possible that
3182 * we are already too late, and that the timeout is
3183 * already running. And that's just too bad for us,
3184 * because we could lose our CTLX from the active
3187 if (del_timer(&hw->resptimer) == 0) {
3188 if (hw->resp_timer_done == 0) {
3189 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3193 hw->resp_timer_done = 1;
3196 ctlx = get_active_ctlx(hw);
3198 if (urb_status != 0) {
3200 * Bad CTLX, so get rid of it. But we only
3201 * remove it from the active queue if we're no
3202 * longer expecting the OUT URB to complete.
3204 if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0)
3207 const __le16 intype = (usbin->type & ~cpu_to_le16(0x8000));
3210 * Check that our message is what we're expecting ...
3212 if (ctlx->outbuf.type != intype) {
3213 netdev_warn(hw->wlandev->netdev,
3214 "Expected IN[%d], received IN[%d] - ignored.\n",
3215 le16_to_cpu(ctlx->outbuf.type),
3216 le16_to_cpu(intype));
3220 /* This URB has succeeded, so grab the data ... */
3221 memcpy(&ctlx->inbuf, usbin, sizeof(ctlx->inbuf));
3223 switch (ctlx->state) {
3224 case CTLX_REQ_SUBMITTED:
3226 * We have received our response URB before
3227 * our request has been acknowledged. Odd,
3228 * but our OUT URB is still alive...
3230 pr_debug("Causality violation: please reboot Universe\n");
3231 ctlx->state = CTLX_RESP_COMPLETE;
3234 case CTLX_REQ_COMPLETE:
3236 * This is the usual path: our request
3237 * has already been acknowledged, and
3238 * now we have received the reply too.
3240 ctlx->state = CTLX_COMPLETE;
3241 unlocked_usbctlx_complete(hw, ctlx);
3247 * Throw this CTLX away ...
3249 netdev_err(hw->wlandev->netdev,
3250 "Matched IN URB, CTLX[%d] in invalid state(%s). Discarded.\n",
3251 le16_to_cpu(ctlx->outbuf.type),
3252 ctlxstr(ctlx->state));
3253 if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0)
3260 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3263 hfa384x_usbctlxq_run(hw);
3266 /*----------------------------------------------------------------
3267 * hfa384x_usbin_txcompl
3269 * At this point we have the results of a previous transmit.
3272 * wlandev wlan device
3273 * usbin ptr to the usb transfer buffer
3282 ----------------------------------------------------------------*/
3283 static void hfa384x_usbin_txcompl(struct wlandevice *wlandev,
3284 union hfa384x_usbin *usbin)
3288 status = le16_to_cpu(usbin->type); /* yeah I know it says type... */
3290 /* Was there an error? */
3291 if (HFA384x_TXSTATUS_ISERROR(status))
3292 prism2sta_ev_txexc(wlandev, status);
3294 prism2sta_ev_tx(wlandev, status);
3297 /*----------------------------------------------------------------
3300 * At this point we have a successful received a rx frame packet.
3303 * wlandev wlan device
3304 * usbin ptr to the usb transfer buffer
3313 ----------------------------------------------------------------*/
3314 static void hfa384x_usbin_rx(struct wlandevice *wlandev, struct sk_buff *skb)
3316 union hfa384x_usbin *usbin = (union hfa384x_usbin *)skb->data;
3317 struct hfa384x *hw = wlandev->priv;
3319 struct p80211_rxmeta *rxmeta;
3323 /* Byte order convert once up front. */
3324 usbin->rxfrm.desc.status = le16_to_cpu(usbin->rxfrm.desc.status);
3325 usbin->rxfrm.desc.time = le32_to_cpu(usbin->rxfrm.desc.time);
3327 /* Now handle frame based on port# */
3328 switch (HFA384x_RXSTATUS_MACPORT_GET(usbin->rxfrm.desc.status)) {
3330 fc = le16_to_cpu(usbin->rxfrm.desc.frame_control);
3332 /* If exclude and we receive an unencrypted, drop it */
3333 if ((wlandev->hostwep & HOSTWEP_EXCLUDEUNENCRYPTED) &&
3334 !WLAN_GET_FC_ISWEP(fc)) {
3338 data_len = le16_to_cpu(usbin->rxfrm.desc.data_len);
3340 /* How much header data do we have? */
3341 hdrlen = p80211_headerlen(fc);
3343 /* Pull off the descriptor */
3344 skb_pull(skb, sizeof(struct hfa384x_rx_frame));
3346 /* Now shunt the header block up against the data block
3347 * with an "overlapping" copy
3349 memmove(skb_push(skb, hdrlen),
3350 &usbin->rxfrm.desc.frame_control, hdrlen);
3352 skb->dev = wlandev->netdev;
3353 skb->dev->last_rx = jiffies;
3355 /* And set the frame length properly */
3356 skb_trim(skb, data_len + hdrlen);
3358 /* The prism2 series does not return the CRC */
3359 memset(skb_put(skb, WLAN_CRC_LEN), 0xff, WLAN_CRC_LEN);
3361 skb_reset_mac_header(skb);
3363 /* Attach the rxmeta, set some stuff */
3364 p80211skb_rxmeta_attach(wlandev, skb);
3365 rxmeta = P80211SKB_RXMETA(skb);
3366 rxmeta->mactime = usbin->rxfrm.desc.time;
3367 rxmeta->rxrate = usbin->rxfrm.desc.rate;
3368 rxmeta->signal = usbin->rxfrm.desc.signal - hw->dbmadjust;
3369 rxmeta->noise = usbin->rxfrm.desc.silence - hw->dbmadjust;
3371 p80211netdev_rx(wlandev, skb);
3376 if (!HFA384x_RXSTATUS_ISFCSERR(usbin->rxfrm.desc.status)) {
3377 /* Copy to wlansnif skb */
3378 hfa384x_int_rxmonitor(wlandev, &usbin->rxfrm);
3381 pr_debug("Received monitor frame: FCSerr set\n");
3386 netdev_warn(hw->wlandev->netdev, "Received frame on unsupported port=%d\n",
3387 HFA384x_RXSTATUS_MACPORT_GET(
3388 usbin->rxfrm.desc.status));
3393 /*----------------------------------------------------------------
3394 * hfa384x_int_rxmonitor
3396 * Helper function for int_rx. Handles monitor frames.
3397 * Note that this function allocates space for the FCS and sets it
3398 * to 0xffffffff. The hfa384x doesn't give us the FCS value but the
3399 * higher layers expect it. 0xffffffff is used as a flag to indicate
3403 * wlandev wlan device structure
3404 * rxfrm rx descriptor read from card in int_rx
3410 * Allocates an skb and passes it up via the PF_PACKET interface.
3413 ----------------------------------------------------------------*/
3414 static void hfa384x_int_rxmonitor(struct wlandevice *wlandev,
3415 struct hfa384x_usb_rxfrm *rxfrm)
3417 struct hfa384x_rx_frame *rxdesc = &(rxfrm->desc);
3418 unsigned int hdrlen = 0;
3419 unsigned int datalen = 0;
3420 unsigned int skblen = 0;
3423 struct sk_buff *skb;
3424 struct hfa384x *hw = wlandev->priv;
3426 /* Remember the status, time, and data_len fields are in host order */
3427 /* Figure out how big the frame is */
3428 fc = le16_to_cpu(rxdesc->frame_control);
3429 hdrlen = p80211_headerlen(fc);
3430 datalen = le16_to_cpu(rxdesc->data_len);
3432 /* Allocate an ind message+framesize skb */
3433 skblen = sizeof(struct p80211_caphdr) + hdrlen + datalen + WLAN_CRC_LEN;
3435 /* sanity check the length */
3437 (sizeof(struct p80211_caphdr) +
3438 WLAN_HDR_A4_LEN + WLAN_DATA_MAXLEN + WLAN_CRC_LEN)) {
3439 pr_debug("overlen frm: len=%zd\n",
3440 skblen - sizeof(struct p80211_caphdr));
3445 skb = dev_alloc_skb(skblen);
3449 /* only prepend the prism header if in the right mode */
3450 if ((wlandev->netdev->type == ARPHRD_IEEE80211_PRISM) &&
3451 (hw->sniffhdr != 0)) {
3452 struct p80211_caphdr *caphdr;
3453 /* The NEW header format! */
3454 datap = skb_put(skb, sizeof(struct p80211_caphdr));
3455 caphdr = (struct p80211_caphdr *)datap;
3457 caphdr->version = htonl(P80211CAPTURE_VERSION);
3458 caphdr->length = htonl(sizeof(struct p80211_caphdr));
3459 caphdr->mactime = __cpu_to_be64(rxdesc->time) * 1000;
3460 caphdr->hosttime = __cpu_to_be64(jiffies);
3461 caphdr->phytype = htonl(4); /* dss_dot11_b */
3462 caphdr->channel = htonl(hw->sniff_channel);
3463 caphdr->datarate = htonl(rxdesc->rate);
3464 caphdr->antenna = htonl(0); /* unknown */
3465 caphdr->priority = htonl(0); /* unknown */
3466 caphdr->ssi_type = htonl(3); /* rssi_raw */
3467 caphdr->ssi_signal = htonl(rxdesc->signal);
3468 caphdr->ssi_noise = htonl(rxdesc->silence);
3469 caphdr->preamble = htonl(0); /* unknown */
3470 caphdr->encoding = htonl(1); /* cck */
3473 /* Copy the 802.11 header to the skb
3474 (ctl frames may be less than a full header) */
3475 datap = skb_put(skb, hdrlen);
3476 memcpy(datap, &(rxdesc->frame_control), hdrlen);
3478 /* If any, copy the data from the card to the skb */
3480 datap = skb_put(skb, datalen);
3481 memcpy(datap, rxfrm->data, datalen);
3483 /* check for unencrypted stuff if WEP bit set. */
3484 if (*(datap - hdrlen + 1) & 0x40) /* wep set */
3485 if ((*(datap) == 0xaa) && (*(datap + 1) == 0xaa))
3486 /* clear wep; it's the 802.2 header! */
3487 *(datap - hdrlen + 1) &= 0xbf;
3490 if (hw->sniff_fcs) {
3492 datap = skb_put(skb, WLAN_CRC_LEN);
3493 memset(datap, 0xff, WLAN_CRC_LEN);
3496 /* pass it back up */
3497 p80211netdev_rx(wlandev, skb);
3500 /*----------------------------------------------------------------
3501 * hfa384x_usbin_info
3503 * At this point we have a successful received a Prism2 info frame.
3506 * wlandev wlan device
3507 * usbin ptr to the usb transfer buffer
3516 ----------------------------------------------------------------*/
3517 static void hfa384x_usbin_info(struct wlandevice *wlandev,
3518 union hfa384x_usbin *usbin)
3520 usbin->infofrm.info.framelen =
3521 le16_to_cpu(usbin->infofrm.info.framelen);
3522 prism2sta_ev_info(wlandev, &usbin->infofrm.info);
3525 /*----------------------------------------------------------------
3526 * hfa384x_usbout_callback
3528 * Callback for URBs on the BULKOUT endpoint.
3531 * urb ptr to the completed urb
3540 ----------------------------------------------------------------*/
3541 static void hfa384x_usbout_callback(struct urb *urb)
3543 struct wlandevice *wlandev = urb->context;
3549 if (wlandev && wlandev->netdev) {
3550 switch (urb->status) {
3552 prism2sta_ev_alloc(wlandev);
3557 struct hfa384x *hw = wlandev->priv;
3559 netdev_warn(hw->wlandev->netdev,
3560 "%s tx pipe stalled: requesting reset\n",
3561 wlandev->netdev->name);
3562 if (!test_and_set_bit
3563 (WORK_TX_HALT, &hw->usb_flags))
3564 schedule_work(&hw->usb_work);
3565 wlandev->netdev->stats.tx_errors++;
3573 struct hfa384x *hw = wlandev->priv;
3575 if (!test_and_set_bit
3576 (THROTTLE_TX, &hw->usb_flags) &&
3577 !timer_pending(&hw->throttle)) {
3578 mod_timer(&hw->throttle,
3579 jiffies + THROTTLE_JIFFIES);
3581 wlandev->netdev->stats.tx_errors++;
3582 netif_stop_queue(wlandev->netdev);
3588 /* Ignorable errors */
3592 netdev_info(wlandev->netdev, "unknown urb->status=%d\n",
3594 wlandev->netdev->stats.tx_errors++;
3600 /*----------------------------------------------------------------
3601 * hfa384x_ctlxout_callback
3603 * Callback for control data on the BULKOUT endpoint.
3606 * urb ptr to the completed urb
3615 ----------------------------------------------------------------*/
3616 static void hfa384x_ctlxout_callback(struct urb *urb)
3618 struct hfa384x *hw = urb->context;
3619 int delete_resptimer = 0;
3622 struct hfa384x_usbctlx *ctlx;
3623 unsigned long flags;
3625 pr_debug("urb->status=%d\n", urb->status);
3629 if ((urb->status == -ESHUTDOWN) ||
3630 (urb->status == -ENODEV) || !hw)
3634 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3637 * Only one CTLX at a time on the "active" list, and
3638 * none at all if we are unplugged. However, we can
3639 * rely on the disconnect function to clean everything
3640 * up if someone unplugged the adapter.
3642 if (list_empty(&hw->ctlxq.active)) {
3643 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3648 * Having something on the "active" queue means
3649 * that we have timers to worry about ...
3651 if (del_timer(&hw->reqtimer) == 0) {
3652 if (hw->req_timer_done == 0) {
3654 * This timer was actually running while we
3655 * were trying to delete it. Let it terminate
3656 * gracefully instead.
3658 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3662 hw->req_timer_done = 1;
3665 ctlx = get_active_ctlx(hw);
3667 if (urb->status == 0) {
3668 /* Request portion of a CTLX is successful */
3669 switch (ctlx->state) {
3670 case CTLX_REQ_SUBMITTED:
3671 /* This OUT-ACK received before IN */
3672 ctlx->state = CTLX_REQ_COMPLETE;
3675 case CTLX_RESP_COMPLETE:
3676 /* IN already received before this OUT-ACK,
3677 * so this command must now be complete.
3679 ctlx->state = CTLX_COMPLETE;
3680 unlocked_usbctlx_complete(hw, ctlx);
3685 /* This is NOT a valid CTLX "success" state! */
3686 netdev_err(hw->wlandev->netdev,
3687 "Illegal CTLX[%d] success state(%s, %d) in OUT URB\n",
3688 le16_to_cpu(ctlx->outbuf.type),
3689 ctlxstr(ctlx->state), urb->status);
3693 /* If the pipe has stalled then we need to reset it */
3694 if ((urb->status == -EPIPE) &&
3695 !test_and_set_bit(WORK_TX_HALT, &hw->usb_flags)) {
3696 netdev_warn(hw->wlandev->netdev,
3697 "%s tx pipe stalled: requesting reset\n",
3698 hw->wlandev->netdev->name);
3699 schedule_work(&hw->usb_work);
3702 /* If someone cancels the OUT URB then its status
3703 * should be either -ECONNRESET or -ENOENT.
3705 ctlx->state = CTLX_REQ_FAILED;
3706 unlocked_usbctlx_complete(hw, ctlx);
3707 delete_resptimer = 1;
3712 if (delete_resptimer) {
3713 timer_ok = del_timer(&hw->resptimer);
3715 hw->resp_timer_done = 1;
3718 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3720 if (!timer_ok && (hw->resp_timer_done == 0)) {
3721 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3726 hfa384x_usbctlxq_run(hw);
3729 /*----------------------------------------------------------------
3730 * hfa384x_usbctlx_reqtimerfn
3732 * Timer response function for CTLX request timeouts. If this
3733 * function is called, it means that the callback for the OUT
3734 * URB containing a Prism2.x XXX_Request was never called.
3737 * data a ptr to the struct hfa384x
3746 ----------------------------------------------------------------*/
3747 static void hfa384x_usbctlx_reqtimerfn(unsigned long data)
3749 struct hfa384x *hw = (struct hfa384x *)data;
3750 unsigned long flags;
3752 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3754 hw->req_timer_done = 1;
3756 /* Removing the hardware automatically empties
3757 * the active list ...
3759 if (!list_empty(&hw->ctlxq.active)) {
3761 * We must ensure that our URB is removed from
3762 * the system, if it hasn't already expired.
3764 hw->ctlx_urb.transfer_flags |= URB_ASYNC_UNLINK;
3765 if (usb_unlink_urb(&hw->ctlx_urb) == -EINPROGRESS) {
3766 struct hfa384x_usbctlx *ctlx = get_active_ctlx(hw);
3768 ctlx->state = CTLX_REQ_FAILED;
3770 /* This URB was active, but has now been
3771 * cancelled. It will now have a status of
3772 * -ECONNRESET in the callback function.
3774 * We are cancelling this CTLX, so we're
3775 * not going to need to wait for a response.
3776 * The URB's callback function will check
3777 * that this timer is truly dead.
3779 if (del_timer(&hw->resptimer) != 0)
3780 hw->resp_timer_done = 1;
3784 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3787 /*----------------------------------------------------------------
3788 * hfa384x_usbctlx_resptimerfn
3790 * Timer response function for CTLX response timeouts. If this
3791 * function is called, it means that the callback for the IN
3792 * URB containing a Prism2.x XXX_Response was never called.
3795 * data a ptr to the struct hfa384x
3804 ----------------------------------------------------------------*/
3805 static void hfa384x_usbctlx_resptimerfn(unsigned long data)
3807 struct hfa384x *hw = (struct hfa384x *)data;
3808 unsigned long flags;
3810 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3812 hw->resp_timer_done = 1;
3814 /* The active list will be empty if the
3815 * adapter has been unplugged ...
3817 if (!list_empty(&hw->ctlxq.active)) {
3818 struct hfa384x_usbctlx *ctlx = get_active_ctlx(hw);
3820 if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0) {
3821 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3822 hfa384x_usbctlxq_run(hw);
3826 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3829 /*----------------------------------------------------------------
3830 * hfa384x_usb_throttlefn
3843 ----------------------------------------------------------------*/
3844 static void hfa384x_usb_throttlefn(unsigned long data)
3846 struct hfa384x *hw = (struct hfa384x *)data;
3847 unsigned long flags;
3849 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3852 * We need to check BOTH the RX and the TX throttle controls,
3853 * so we use the bitwise OR instead of the logical OR.
3855 pr_debug("flags=0x%lx\n", hw->usb_flags);
3856 if (!hw->wlandev->hwremoved &&
3857 ((test_and_clear_bit(THROTTLE_RX, &hw->usb_flags) &&
3858 !test_and_set_bit(WORK_RX_RESUME, &hw->usb_flags)) |
3859 (test_and_clear_bit(THROTTLE_TX, &hw->usb_flags) &&
3860 !test_and_set_bit(WORK_TX_RESUME, &hw->usb_flags))
3862 schedule_work(&hw->usb_work);
3865 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3868 /*----------------------------------------------------------------
3869 * hfa384x_usbctlx_submit
3871 * Called from the doxxx functions to submit a CTLX to the queue
3874 * hw ptr to the hw struct
3875 * ctlx ctlx structure to enqueue
3878 * -ENODEV if the adapter is unplugged
3884 * process or interrupt
3885 ----------------------------------------------------------------*/
3886 static int hfa384x_usbctlx_submit(struct hfa384x *hw, struct hfa384x_usbctlx *ctlx)
3888 unsigned long flags;
3890 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3892 if (hw->wlandev->hwremoved) {
3893 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3897 ctlx->state = CTLX_PENDING;
3898 list_add_tail(&ctlx->list, &hw->ctlxq.pending);
3899 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3900 hfa384x_usbctlxq_run(hw);
3905 /*----------------------------------------------------------------
3906 * hfa384x_isgood_pdrcore
3908 * Quick check of PDR codes.
3911 * pdrcode PDR code number (host order)
3920 ----------------------------------------------------------------*/
3921 static int hfa384x_isgood_pdrcode(u16 pdrcode)
3924 case HFA384x_PDR_END_OF_PDA:
3925 case HFA384x_PDR_PCB_PARTNUM:
3926 case HFA384x_PDR_PDAVER:
3927 case HFA384x_PDR_NIC_SERIAL:
3928 case HFA384x_PDR_MKK_MEASUREMENTS:
3929 case HFA384x_PDR_NIC_RAMSIZE:
3930 case HFA384x_PDR_MFISUPRANGE:
3931 case HFA384x_PDR_CFISUPRANGE:
3932 case HFA384x_PDR_NICID:
3933 case HFA384x_PDR_MAC_ADDRESS:
3934 case HFA384x_PDR_REGDOMAIN:
3935 case HFA384x_PDR_ALLOWED_CHANNEL:
3936 case HFA384x_PDR_DEFAULT_CHANNEL:
3937 case HFA384x_PDR_TEMPTYPE:
3938 case HFA384x_PDR_IFR_SETTING:
3939 case HFA384x_PDR_RFR_SETTING:
3940 case HFA384x_PDR_HFA3861_BASELINE:
3941 case HFA384x_PDR_HFA3861_SHADOW:
3942 case HFA384x_PDR_HFA3861_IFRF:
3943 case HFA384x_PDR_HFA3861_CHCALSP:
3944 case HFA384x_PDR_HFA3861_CHCALI:
3945 case HFA384x_PDR_3842_NIC_CONFIG:
3946 case HFA384x_PDR_USB_ID:
3947 case HFA384x_PDR_PCI_ID:
3948 case HFA384x_PDR_PCI_IFCONF:
3949 case HFA384x_PDR_PCI_PMCONF:
3950 case HFA384x_PDR_RFENRGY:
3951 case HFA384x_PDR_HFA3861_MANF_TESTSP:
3952 case HFA384x_PDR_HFA3861_MANF_TESTI:
3956 if (pdrcode < 0x1000) {
3957 /* code is OK, but we don't know exactly what it is */
3958 pr_debug("Encountered unknown PDR#=0x%04x, assuming it's ok.\n",
3965 pr_debug("Encountered unknown PDR#=0x%04x, (>=0x1000), assuming it's bad.\n",