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);
156 static void hfa384x_int_rxmonitor(struct wlandevice *wlandev,
157 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,
177 union hfa384x_usbin *usbin);
179 static void hfa384x_usbin_ctlx(struct hfa384x *hw, union hfa384x_usbin *usbin,
182 /*---------------------------------------------------*/
183 /* Functions to support the prism2 usb command queue */
185 static void hfa384x_usbctlxq_run(struct hfa384x *hw);
187 static void hfa384x_usbctlx_reqtimerfn(struct timer_list *t);
189 static void hfa384x_usbctlx_resptimerfn(struct timer_list *t);
191 static void hfa384x_usb_throttlefn(struct timer_list *t);
193 static void hfa384x_usbctlx_completion_task(unsigned long data);
195 static void hfa384x_usbctlx_reaper_task(unsigned long data);
197 static int hfa384x_usbctlx_submit(struct hfa384x *hw,
198 struct hfa384x_usbctlx *ctlx);
200 static void unlocked_usbctlx_complete(struct hfa384x *hw,
201 struct hfa384x_usbctlx *ctlx);
203 struct usbctlx_completor {
204 int (*complete)(struct usbctlx_completor *);
208 hfa384x_usbctlx_complete_sync(struct hfa384x *hw,
209 struct hfa384x_usbctlx *ctlx,
210 struct usbctlx_completor *completor);
213 unlocked_usbctlx_cancel_async(struct hfa384x *hw, struct hfa384x_usbctlx *ctlx);
215 static void hfa384x_cb_status(struct hfa384x *hw,
216 const struct hfa384x_usbctlx *ctlx);
219 usbctlx_get_status(const struct hfa384x_usb_statusresp *cmdresp,
220 struct hfa384x_cmdresult *result);
223 usbctlx_get_rridresult(const struct hfa384x_usb_rridresp *rridresp,
224 struct hfa384x_rridresult *result);
226 /*---------------------------------------------------*/
227 /* Low level req/resp CTLX formatters and submitters */
229 hfa384x_docmd(struct hfa384x *hw,
231 struct hfa384x_metacmd *cmd,
232 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
235 hfa384x_dorrid(struct hfa384x *hw,
239 unsigned int riddatalen,
240 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
243 hfa384x_dowrid(struct hfa384x *hw,
247 unsigned int riddatalen,
248 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
251 hfa384x_dormem(struct hfa384x *hw,
257 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
260 hfa384x_dowmem(struct hfa384x *hw,
266 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
268 static int hfa384x_isgood_pdrcode(u16 pdrcode);
270 static inline const char *ctlxstr(enum ctlx_state s)
272 static const char * const ctlx_str[] = {
277 "Request packet submitted",
278 "Request packet completed",
279 "Response packet completed"
285 static inline struct hfa384x_usbctlx *get_active_ctlx(struct hfa384x *hw)
287 return list_entry(hw->ctlxq.active.next, struct hfa384x_usbctlx, list);
291 void dbprint_urb(struct urb *urb)
293 pr_debug("urb->pipe=0x%08x\n", urb->pipe);
294 pr_debug("urb->status=0x%08x\n", urb->status);
295 pr_debug("urb->transfer_flags=0x%08x\n", urb->transfer_flags);
296 pr_debug("urb->transfer_buffer=0x%08x\n",
297 (unsigned int)urb->transfer_buffer);
298 pr_debug("urb->transfer_buffer_length=0x%08x\n",
299 urb->transfer_buffer_length);
300 pr_debug("urb->actual_length=0x%08x\n", urb->actual_length);
301 pr_debug("urb->bandwidth=0x%08x\n", urb->bandwidth);
302 pr_debug("urb->setup_packet(ctl)=0x%08x\n",
303 (unsigned int)urb->setup_packet);
304 pr_debug("urb->start_frame(iso/irq)=0x%08x\n", urb->start_frame);
305 pr_debug("urb->interval(irq)=0x%08x\n", urb->interval);
306 pr_debug("urb->error_count(iso)=0x%08x\n", urb->error_count);
307 pr_debug("urb->timeout=0x%08x\n", urb->timeout);
308 pr_debug("urb->context=0x%08x\n", (unsigned int)urb->context);
309 pr_debug("urb->complete=0x%08x\n", (unsigned int)urb->complete);
313 /*----------------------------------------------------------------
316 * Listen for input data on the BULK-IN pipe. If the pipe has
317 * stalled then schedule it to be reset.
321 * memflags memory allocation flags
324 * error code from submission
328 *----------------------------------------------------------------
330 static int submit_rx_urb(struct hfa384x *hw, gfp_t memflags)
335 skb = dev_alloc_skb(sizeof(union hfa384x_usbin));
341 /* Post the IN urb */
342 usb_fill_bulk_urb(&hw->rx_urb, hw->usb,
344 skb->data, sizeof(union hfa384x_usbin),
345 hfa384x_usbin_callback, hw->wlandev);
347 hw->rx_urb_skb = skb;
350 if (!hw->wlandev->hwremoved &&
351 !test_bit(WORK_RX_HALT, &hw->usb_flags)) {
352 result = usb_submit_urb(&hw->rx_urb, memflags);
354 /* Check whether we need to reset the RX pipe */
355 if (result == -EPIPE) {
356 netdev_warn(hw->wlandev->netdev,
357 "%s rx pipe stalled: requesting reset\n",
358 hw->wlandev->netdev->name);
359 if (!test_and_set_bit(WORK_RX_HALT, &hw->usb_flags))
360 schedule_work(&hw->usb_work);
364 /* Don't leak memory if anything should go wrong */
367 hw->rx_urb_skb = NULL;
374 /*----------------------------------------------------------------
377 * Prepares and submits the URB of transmitted data. If the
378 * submission fails then it will schedule the output pipe to
383 * tx_urb URB of data for transmission
384 * memflags memory allocation flags
387 * error code from submission
391 *----------------------------------------------------------------
393 static int submit_tx_urb(struct hfa384x *hw, struct urb *tx_urb, gfp_t memflags)
395 struct net_device *netdev = hw->wlandev->netdev;
399 if (netif_running(netdev)) {
400 if (!hw->wlandev->hwremoved &&
401 !test_bit(WORK_TX_HALT, &hw->usb_flags)) {
402 result = usb_submit_urb(tx_urb, memflags);
404 /* Test whether we need to reset the TX pipe */
405 if (result == -EPIPE) {
406 netdev_warn(hw->wlandev->netdev,
407 "%s tx pipe stalled: requesting reset\n",
409 set_bit(WORK_TX_HALT, &hw->usb_flags);
410 schedule_work(&hw->usb_work);
411 } else if (result == 0) {
412 netif_stop_queue(netdev);
420 /*----------------------------------------------------------------
423 * There are some things that the USB stack cannot do while
424 * in interrupt context, so we arrange this function to run
425 * in process context.
428 * hw device structure
434 * process (by design)
435 *----------------------------------------------------------------
437 static void hfa384x_usb_defer(struct work_struct *data)
439 struct hfa384x *hw = container_of(data, struct hfa384x, usb_work);
440 struct net_device *netdev = hw->wlandev->netdev;
442 /* Don't bother trying to reset anything if the plug
443 * has been pulled ...
445 if (hw->wlandev->hwremoved)
448 /* Reception has stopped: try to reset the input pipe */
449 if (test_bit(WORK_RX_HALT, &hw->usb_flags)) {
452 usb_kill_urb(&hw->rx_urb); /* Cannot be holding spinlock! */
454 ret = usb_clear_halt(hw->usb, hw->endp_in);
456 netdev_err(hw->wlandev->netdev,
457 "Failed to clear rx pipe for %s: err=%d\n",
460 netdev_info(hw->wlandev->netdev, "%s rx pipe reset complete.\n",
462 clear_bit(WORK_RX_HALT, &hw->usb_flags);
463 set_bit(WORK_RX_RESUME, &hw->usb_flags);
467 /* Resume receiving data back from the device. */
468 if (test_bit(WORK_RX_RESUME, &hw->usb_flags)) {
471 ret = submit_rx_urb(hw, GFP_KERNEL);
473 netdev_err(hw->wlandev->netdev,
474 "Failed to resume %s rx pipe.\n",
477 clear_bit(WORK_RX_RESUME, &hw->usb_flags);
481 /* Transmission has stopped: try to reset the output pipe */
482 if (test_bit(WORK_TX_HALT, &hw->usb_flags)) {
485 usb_kill_urb(&hw->tx_urb);
486 ret = usb_clear_halt(hw->usb, hw->endp_out);
488 netdev_err(hw->wlandev->netdev,
489 "Failed to clear tx pipe for %s: err=%d\n",
492 netdev_info(hw->wlandev->netdev, "%s tx pipe reset complete.\n",
494 clear_bit(WORK_TX_HALT, &hw->usb_flags);
495 set_bit(WORK_TX_RESUME, &hw->usb_flags);
497 /* Stopping the BULK-OUT pipe also blocked
498 * us from sending any more CTLX URBs, so
499 * we need to re-run our queue ...
501 hfa384x_usbctlxq_run(hw);
505 /* Resume transmitting. */
506 if (test_and_clear_bit(WORK_TX_RESUME, &hw->usb_flags))
507 netif_wake_queue(hw->wlandev->netdev);
510 /*----------------------------------------------------------------
513 * Sets up the struct hfa384x data structure for use. Note this
514 * does _not_ initialize the actual hardware, just the data structures
515 * we use to keep track of its state.
518 * hw device structure
519 * irq device irq number
520 * iobase i/o base address for register access
521 * membase memory base address for register access
530 *----------------------------------------------------------------
532 void hfa384x_create(struct hfa384x *hw, struct usb_device *usb)
534 memset(hw, 0, sizeof(*hw));
537 /* set up the endpoints */
538 hw->endp_in = usb_rcvbulkpipe(usb, 1);
539 hw->endp_out = usb_sndbulkpipe(usb, 2);
541 /* Set up the waitq */
542 init_waitqueue_head(&hw->cmdq);
544 /* Initialize the command queue */
545 spin_lock_init(&hw->ctlxq.lock);
546 INIT_LIST_HEAD(&hw->ctlxq.pending);
547 INIT_LIST_HEAD(&hw->ctlxq.active);
548 INIT_LIST_HEAD(&hw->ctlxq.completing);
549 INIT_LIST_HEAD(&hw->ctlxq.reapable);
551 /* Initialize the authentication queue */
552 skb_queue_head_init(&hw->authq);
554 tasklet_init(&hw->reaper_bh,
555 hfa384x_usbctlx_reaper_task, (unsigned long)hw);
556 tasklet_init(&hw->completion_bh,
557 hfa384x_usbctlx_completion_task, (unsigned long)hw);
558 INIT_WORK(&hw->link_bh, prism2sta_processing_defer);
559 INIT_WORK(&hw->usb_work, hfa384x_usb_defer);
561 timer_setup(&hw->throttle, hfa384x_usb_throttlefn, 0);
563 timer_setup(&hw->resptimer, hfa384x_usbctlx_resptimerfn, 0);
565 timer_setup(&hw->reqtimer, hfa384x_usbctlx_reqtimerfn, 0);
567 usb_init_urb(&hw->rx_urb);
568 usb_init_urb(&hw->tx_urb);
569 usb_init_urb(&hw->ctlx_urb);
571 hw->link_status = HFA384x_LINK_NOTCONNECTED;
572 hw->state = HFA384x_STATE_INIT;
574 INIT_WORK(&hw->commsqual_bh, prism2sta_commsqual_defer);
575 timer_setup(&hw->commsqual_timer, prism2sta_commsqual_timer, 0);
578 /*----------------------------------------------------------------
581 * Partner to hfa384x_create(). This function cleans up the hw
582 * structure so that it can be freed by the caller using a simple
583 * kfree. Currently, this function is just a placeholder. If, at some
584 * point in the future, an hw in the 'shutdown' state requires a 'deep'
585 * kfree, this is where it should be done. Note that if this function
586 * is called on a _running_ hw structure, the drvr_stop() function is
590 * hw device structure
593 * nothing, this function is not allowed to fail.
599 *----------------------------------------------------------------
601 void hfa384x_destroy(struct hfa384x *hw)
605 if (hw->state == HFA384x_STATE_RUNNING)
606 hfa384x_drvr_stop(hw);
607 hw->state = HFA384x_STATE_PREINIT;
609 kfree(hw->scanresults);
610 hw->scanresults = NULL;
612 /* Now to clean out the auth queue */
613 while ((skb = skb_dequeue(&hw->authq)))
617 static struct hfa384x_usbctlx *usbctlx_alloc(void)
619 struct hfa384x_usbctlx *ctlx;
621 ctlx = kzalloc(sizeof(*ctlx),
622 in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
624 init_completion(&ctlx->done);
630 usbctlx_get_status(const struct hfa384x_usb_statusresp *cmdresp,
631 struct hfa384x_cmdresult *result)
633 result->status = le16_to_cpu(cmdresp->status);
634 result->resp0 = le16_to_cpu(cmdresp->resp0);
635 result->resp1 = le16_to_cpu(cmdresp->resp1);
636 result->resp2 = le16_to_cpu(cmdresp->resp2);
638 pr_debug("cmdresult:status=0x%04x resp0=0x%04x resp1=0x%04x resp2=0x%04x\n",
639 result->status, result->resp0, result->resp1, result->resp2);
641 return result->status & HFA384x_STATUS_RESULT;
645 usbctlx_get_rridresult(const struct hfa384x_usb_rridresp *rridresp,
646 struct hfa384x_rridresult *result)
648 result->rid = le16_to_cpu(rridresp->rid);
649 result->riddata = rridresp->data;
650 result->riddata_len = ((le16_to_cpu(rridresp->frmlen) - 1) * 2);
653 /*----------------------------------------------------------------
655 * This completor must be passed to hfa384x_usbctlx_complete_sync()
656 * when processing a CTLX that returns a struct hfa384x_cmdresult structure.
657 *----------------------------------------------------------------
659 struct usbctlx_cmd_completor {
660 struct usbctlx_completor head;
662 const struct hfa384x_usb_statusresp *cmdresp;
663 struct hfa384x_cmdresult *result;
666 static inline int usbctlx_cmd_completor_fn(struct usbctlx_completor *head)
668 struct usbctlx_cmd_completor *complete;
670 complete = (struct usbctlx_cmd_completor *)head;
671 return usbctlx_get_status(complete->cmdresp, complete->result);
674 static inline struct usbctlx_completor *
675 init_cmd_completor(struct usbctlx_cmd_completor *completor,
676 const struct hfa384x_usb_statusresp *cmdresp,
677 struct hfa384x_cmdresult *result)
679 completor->head.complete = usbctlx_cmd_completor_fn;
680 completor->cmdresp = cmdresp;
681 completor->result = result;
682 return &completor->head;
685 /*----------------------------------------------------------------
687 * This completor must be passed to hfa384x_usbctlx_complete_sync()
688 * when processing a CTLX that reads a RID.
689 *----------------------------------------------------------------
691 struct usbctlx_rrid_completor {
692 struct usbctlx_completor head;
694 const struct hfa384x_usb_rridresp *rridresp;
696 unsigned int riddatalen;
699 static int usbctlx_rrid_completor_fn(struct usbctlx_completor *head)
701 struct usbctlx_rrid_completor *complete;
702 struct hfa384x_rridresult rridresult;
704 complete = (struct usbctlx_rrid_completor *)head;
705 usbctlx_get_rridresult(complete->rridresp, &rridresult);
707 /* Validate the length, note body len calculation in bytes */
708 if (rridresult.riddata_len != complete->riddatalen) {
709 pr_warn("RID len mismatch, rid=0x%04x hlen=%d fwlen=%d\n",
711 complete->riddatalen, rridresult.riddata_len);
715 memcpy(complete->riddata, rridresult.riddata, complete->riddatalen);
719 static inline struct usbctlx_completor *
720 init_rrid_completor(struct usbctlx_rrid_completor *completor,
721 const struct hfa384x_usb_rridresp *rridresp,
723 unsigned int riddatalen)
725 completor->head.complete = usbctlx_rrid_completor_fn;
726 completor->rridresp = rridresp;
727 completor->riddata = riddata;
728 completor->riddatalen = riddatalen;
729 return &completor->head;
732 /*----------------------------------------------------------------
734 * Interprets the results of a synchronous RID-write
735 *----------------------------------------------------------------
737 #define init_wrid_completor init_cmd_completor
739 /*----------------------------------------------------------------
741 * Interprets the results of a synchronous memory-write
742 *----------------------------------------------------------------
744 #define init_wmem_completor init_cmd_completor
746 /*----------------------------------------------------------------
748 * Interprets the results of a synchronous memory-read
749 *----------------------------------------------------------------
751 struct usbctlx_rmem_completor {
752 struct usbctlx_completor head;
754 const struct hfa384x_usb_rmemresp *rmemresp;
759 static int usbctlx_rmem_completor_fn(struct usbctlx_completor *head)
761 struct usbctlx_rmem_completor *complete =
762 (struct usbctlx_rmem_completor *)head;
764 pr_debug("rmemresp:len=%d\n", complete->rmemresp->frmlen);
765 memcpy(complete->data, complete->rmemresp->data, complete->len);
769 static inline struct usbctlx_completor *
770 init_rmem_completor(struct usbctlx_rmem_completor *completor,
771 struct hfa384x_usb_rmemresp *rmemresp,
775 completor->head.complete = usbctlx_rmem_completor_fn;
776 completor->rmemresp = rmemresp;
777 completor->data = data;
778 completor->len = len;
779 return &completor->head;
782 /*----------------------------------------------------------------
785 * Ctlx_complete handler for async CMD type control exchanges.
786 * mark the hw struct as such.
788 * Note: If the handling is changed here, it should probably be
789 * changed in docmd as well.
793 * ctlx completed CTLX
802 *----------------------------------------------------------------
804 static void hfa384x_cb_status(struct hfa384x *hw,
805 const struct hfa384x_usbctlx *ctlx)
808 struct hfa384x_cmdresult cmdresult;
810 if (ctlx->state != CTLX_COMPLETE) {
811 memset(&cmdresult, 0, sizeof(cmdresult));
813 HFA384x_STATUS_RESULT_SET(HFA384x_CMD_ERR);
815 usbctlx_get_status(&ctlx->inbuf.cmdresp, &cmdresult);
818 ctlx->usercb(hw, &cmdresult, ctlx->usercb_data);
822 static inline int hfa384x_docmd_wait(struct hfa384x *hw,
823 struct hfa384x_metacmd *cmd)
825 return hfa384x_docmd(hw, DOWAIT, cmd, NULL, NULL, NULL);
829 hfa384x_docmd_async(struct hfa384x *hw,
830 struct hfa384x_metacmd *cmd,
831 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
833 return hfa384x_docmd(hw, DOASYNC, cmd, cmdcb, usercb, usercb_data);
837 hfa384x_dorrid_wait(struct hfa384x *hw, u16 rid, void *riddata,
838 unsigned int riddatalen)
840 return hfa384x_dorrid(hw, DOWAIT,
841 rid, riddata, riddatalen, NULL, NULL, NULL);
845 hfa384x_dorrid_async(struct hfa384x *hw,
846 u16 rid, void *riddata, unsigned int riddatalen,
848 ctlx_usercb_t usercb, void *usercb_data)
850 return hfa384x_dorrid(hw, DOASYNC,
851 rid, riddata, riddatalen,
852 cmdcb, usercb, usercb_data);
856 hfa384x_dowrid_wait(struct hfa384x *hw, u16 rid, void *riddata,
857 unsigned int riddatalen)
859 return hfa384x_dowrid(hw, DOWAIT,
860 rid, riddata, riddatalen, NULL, NULL, NULL);
864 hfa384x_dowrid_async(struct hfa384x *hw,
865 u16 rid, void *riddata, unsigned int riddatalen,
867 ctlx_usercb_t usercb, void *usercb_data)
869 return hfa384x_dowrid(hw, DOASYNC,
870 rid, riddata, riddatalen,
871 cmdcb, usercb, usercb_data);
875 hfa384x_dormem_wait(struct hfa384x *hw,
876 u16 page, u16 offset, void *data, unsigned int len)
878 return hfa384x_dormem(hw, DOWAIT,
879 page, offset, data, len, NULL, NULL, NULL);
883 hfa384x_dormem_async(struct hfa384x *hw,
884 u16 page, u16 offset, void *data, unsigned int len,
886 ctlx_usercb_t usercb, void *usercb_data)
888 return hfa384x_dormem(hw, DOASYNC,
889 page, offset, data, len,
890 cmdcb, usercb, usercb_data);
894 hfa384x_dowmem_wait(struct hfa384x *hw,
895 u16 page, u16 offset, void *data, unsigned int len)
897 return hfa384x_dowmem(hw, DOWAIT,
898 page, offset, data, len, NULL, NULL, NULL);
902 hfa384x_dowmem_async(struct hfa384x *hw,
908 ctlx_usercb_t usercb, void *usercb_data)
910 return hfa384x_dowmem(hw, DOASYNC,
911 page, offset, data, len,
912 cmdcb, usercb, usercb_data);
915 /*----------------------------------------------------------------
916 * hfa384x_cmd_initialize
918 * Issues the initialize command and sets the hw->state based
922 * hw device structure
926 * >0 f/w reported error - f/w status code
927 * <0 driver reported error
933 *----------------------------------------------------------------
935 int hfa384x_cmd_initialize(struct hfa384x *hw)
939 struct hfa384x_metacmd cmd;
941 cmd.cmd = HFA384x_CMDCODE_INIT;
946 result = hfa384x_docmd_wait(hw, &cmd);
948 pr_debug("cmdresp.init: status=0x%04x, resp0=0x%04x, resp1=0x%04x, resp2=0x%04x\n",
950 cmd.result.resp0, cmd.result.resp1, cmd.result.resp2);
952 for (i = 0; i < HFA384x_NUMPORTS_MAX; i++)
953 hw->port_enabled[i] = 0;
956 hw->link_status = HFA384x_LINK_NOTCONNECTED;
961 /*----------------------------------------------------------------
962 * hfa384x_cmd_disable
964 * Issues the disable command to stop communications on one of
968 * hw device structure
969 * macport MAC port number (host order)
973 * >0 f/w reported failure - f/w status code
974 * <0 driver reported error (timeout|bad arg)
980 *----------------------------------------------------------------
982 int hfa384x_cmd_disable(struct hfa384x *hw, u16 macport)
984 struct hfa384x_metacmd cmd;
986 cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_DISABLE) |
987 HFA384x_CMD_MACPORT_SET(macport);
992 return hfa384x_docmd_wait(hw, &cmd);
995 /*----------------------------------------------------------------
998 * Issues the enable command to enable communications on one of
1002 * hw device structure
1003 * macport MAC port number
1007 * >0 f/w reported failure - f/w status code
1008 * <0 driver reported error (timeout|bad arg)
1014 *----------------------------------------------------------------
1016 int hfa384x_cmd_enable(struct hfa384x *hw, u16 macport)
1018 struct hfa384x_metacmd cmd;
1020 cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_ENABLE) |
1021 HFA384x_CMD_MACPORT_SET(macport);
1026 return hfa384x_docmd_wait(hw, &cmd);
1029 /*----------------------------------------------------------------
1030 * hfa384x_cmd_monitor
1032 * Enables the 'monitor mode' of the MAC. Here's the description of
1033 * monitor mode that I've received thus far:
1035 * "The "monitor mode" of operation is that the MAC passes all
1036 * frames for which the PLCP checks are correct. All received
1037 * MPDUs are passed to the host with MAC Port = 7, with a
1038 * receive status of good, FCS error, or undecryptable. Passing
1039 * certain MPDUs is a violation of the 802.11 standard, but useful
1040 * for a debugging tool." Normal communication is not possible
1041 * while monitor mode is enabled.
1044 * hw device structure
1045 * enable a code (0x0b|0x0f) that enables/disables
1046 * monitor mode. (host order)
1050 * >0 f/w reported failure - f/w status code
1051 * <0 driver reported error (timeout|bad arg)
1057 *----------------------------------------------------------------
1059 int hfa384x_cmd_monitor(struct hfa384x *hw, u16 enable)
1061 struct hfa384x_metacmd cmd;
1063 cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_MONITOR) |
1064 HFA384x_CMD_AINFO_SET(enable);
1069 return hfa384x_docmd_wait(hw, &cmd);
1072 /*----------------------------------------------------------------
1073 * hfa384x_cmd_download
1075 * Sets the controls for the MAC controller code/data download
1076 * process. The arguments set the mode and address associated
1077 * with a download. Note that the aux registers should be enabled
1078 * prior to setting one of the download enable modes.
1081 * hw device structure
1082 * mode 0 - Disable programming and begin code exec
1083 * 1 - Enable volatile mem programming
1084 * 2 - Enable non-volatile mem programming
1085 * 3 - Program non-volatile section from NV download
1089 * highaddr For mode 1, sets the high & low order bits of
1090 * the "destination address". This address will be
1091 * the execution start address when download is
1092 * subsequently disabled.
1093 * For mode 2, sets the high & low order bits of
1094 * the destination in NV ram.
1095 * For modes 0 & 3, should be zero. (host order)
1096 * NOTE: these are CMD format.
1097 * codelen Length of the data to write in mode 2,
1098 * zero otherwise. (host order)
1102 * >0 f/w reported failure - f/w status code
1103 * <0 driver reported error (timeout|bad arg)
1109 *----------------------------------------------------------------
1111 int hfa384x_cmd_download(struct hfa384x *hw, u16 mode, u16 lowaddr,
1112 u16 highaddr, u16 codelen)
1114 struct hfa384x_metacmd cmd;
1116 pr_debug("mode=%d, lowaddr=0x%04x, highaddr=0x%04x, codelen=%d\n",
1117 mode, lowaddr, highaddr, codelen);
1119 cmd.cmd = (HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_DOWNLD) |
1120 HFA384x_CMD_PROGMODE_SET(mode));
1122 cmd.parm0 = lowaddr;
1123 cmd.parm1 = highaddr;
1124 cmd.parm2 = codelen;
1126 return hfa384x_docmd_wait(hw, &cmd);
1129 /*----------------------------------------------------------------
1132 * Perform a reset of the hfa38xx MAC core. We assume that the hw
1133 * structure is in its "created" state. That is, it is initialized
1134 * with proper values. Note that if a reset is done after the
1135 * device has been active for awhile, the caller might have to clean
1136 * up some leftover cruft in the hw structure.
1139 * hw device structure
1140 * holdtime how long (in ms) to hold the reset
1141 * settletime how long (in ms) to wait after releasing
1151 *----------------------------------------------------------------
1153 int hfa384x_corereset(struct hfa384x *hw, int holdtime,
1154 int settletime, int genesis)
1158 result = usb_reset_device(hw->usb);
1160 netdev_err(hw->wlandev->netdev, "usb_reset_device() failed, result=%d.\n",
1167 /*----------------------------------------------------------------
1168 * hfa384x_usbctlx_complete_sync
1170 * Waits for a synchronous CTLX object to complete,
1171 * and then handles the response.
1174 * hw device structure
1176 * completor functor object to decide what to
1177 * do with the CTLX's result.
1181 * -ERESTARTSYS Interrupted by a signal
1183 * -ENODEV Adapter was unplugged
1184 * ??? Result from completor
1190 *----------------------------------------------------------------
1192 static int hfa384x_usbctlx_complete_sync(struct hfa384x *hw,
1193 struct hfa384x_usbctlx *ctlx,
1194 struct usbctlx_completor *completor)
1196 unsigned long flags;
1199 result = wait_for_completion_interruptible(&ctlx->done);
1201 spin_lock_irqsave(&hw->ctlxq.lock, flags);
1204 * We can only handle the CTLX if the USB disconnect
1205 * function has not run yet ...
1208 if (hw->wlandev->hwremoved) {
1209 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1211 } else if (result != 0) {
1215 * We were probably interrupted, so delete
1216 * this CTLX asynchronously, kill the timers
1217 * and the URB, and then start the next
1220 * NOTE: We can only delete the timers and
1221 * the URB if this CTLX is active.
1223 if (ctlx == get_active_ctlx(hw)) {
1224 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1226 del_singleshot_timer_sync(&hw->reqtimer);
1227 del_singleshot_timer_sync(&hw->resptimer);
1228 hw->req_timer_done = 1;
1229 hw->resp_timer_done = 1;
1230 usb_kill_urb(&hw->ctlx_urb);
1232 spin_lock_irqsave(&hw->ctlxq.lock, flags);
1237 * This scenario is so unlikely that I'm
1238 * happy with a grubby "goto" solution ...
1240 if (hw->wlandev->hwremoved)
1245 * The completion task will send this CTLX
1246 * to the reaper the next time it runs. We
1247 * are no longer in a hurry.
1250 ctlx->state = CTLX_REQ_FAILED;
1251 list_move_tail(&ctlx->list, &hw->ctlxq.completing);
1253 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1256 hfa384x_usbctlxq_run(hw);
1258 if (ctlx->state == CTLX_COMPLETE) {
1259 result = completor->complete(completor);
1261 netdev_warn(hw->wlandev->netdev, "CTLX[%d] error: state(%s)\n",
1262 le16_to_cpu(ctlx->outbuf.type),
1263 ctlxstr(ctlx->state));
1267 list_del(&ctlx->list);
1268 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1275 /*----------------------------------------------------------------
1278 * Constructs a command CTLX and submits it.
1280 * NOTE: Any changes to the 'post-submit' code in this function
1281 * need to be carried over to hfa384x_cbcmd() since the handling
1282 * is virtually identical.
1285 * hw device structure
1286 * mode DOWAIT or DOASYNC
1287 * cmd cmd structure. Includes all arguments and result
1288 * data points. All in host order. in host order
1289 * cmdcb command-specific callback
1290 * usercb user callback for async calls, NULL for DOWAIT calls
1291 * usercb_data user supplied data pointer for async calls, NULL
1297 * -ERESTARTSYS Awakened on signal
1298 * >0 command indicated error, Status and Resp0-2 are
1306 *----------------------------------------------------------------
1309 hfa384x_docmd(struct hfa384x *hw,
1311 struct hfa384x_metacmd *cmd,
1312 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1315 struct hfa384x_usbctlx *ctlx;
1317 ctlx = usbctlx_alloc();
1323 /* Initialize the command */
1324 ctlx->outbuf.cmdreq.type = cpu_to_le16(HFA384x_USB_CMDREQ);
1325 ctlx->outbuf.cmdreq.cmd = cpu_to_le16(cmd->cmd);
1326 ctlx->outbuf.cmdreq.parm0 = cpu_to_le16(cmd->parm0);
1327 ctlx->outbuf.cmdreq.parm1 = cpu_to_le16(cmd->parm1);
1328 ctlx->outbuf.cmdreq.parm2 = cpu_to_le16(cmd->parm2);
1330 ctlx->outbufsize = sizeof(ctlx->outbuf.cmdreq);
1332 pr_debug("cmdreq: cmd=0x%04x parm0=0x%04x parm1=0x%04x parm2=0x%04x\n",
1333 cmd->cmd, cmd->parm0, cmd->parm1, cmd->parm2);
1335 ctlx->reapable = mode;
1336 ctlx->cmdcb = cmdcb;
1337 ctlx->usercb = usercb;
1338 ctlx->usercb_data = usercb_data;
1340 result = hfa384x_usbctlx_submit(hw, ctlx);
1343 } else if (mode == DOWAIT) {
1344 struct usbctlx_cmd_completor cmd_completor;
1345 struct usbctlx_completor *completor;
1347 completor = init_cmd_completor(&cmd_completor,
1348 &ctlx->inbuf.cmdresp,
1351 result = hfa384x_usbctlx_complete_sync(hw, ctlx, completor);
1358 /*----------------------------------------------------------------
1361 * Constructs a read rid CTLX and issues it.
1363 * NOTE: Any changes to the 'post-submit' code in this function
1364 * need to be carried over to hfa384x_cbrrid() since the handling
1365 * is virtually identical.
1368 * hw device structure
1369 * mode DOWAIT or DOASYNC
1370 * rid Read RID number (host order)
1371 * riddata Caller supplied buffer that MAC formatted RID.data
1372 * record will be written to for DOWAIT calls. Should
1373 * be NULL for DOASYNC calls.
1374 * riddatalen Buffer length for DOWAIT calls. Zero for DOASYNC calls.
1375 * cmdcb command callback for async calls, NULL for DOWAIT calls
1376 * usercb user callback for async calls, NULL for DOWAIT calls
1377 * usercb_data user supplied data pointer for async calls, NULL
1383 * -ERESTARTSYS Awakened on signal
1384 * -ENODATA riddatalen != macdatalen
1385 * >0 command indicated error, Status and Resp0-2 are
1391 * interrupt (DOASYNC)
1392 * process (DOWAIT or DOASYNC)
1393 *----------------------------------------------------------------
1396 hfa384x_dorrid(struct hfa384x *hw,
1400 unsigned int riddatalen,
1401 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1404 struct hfa384x_usbctlx *ctlx;
1406 ctlx = usbctlx_alloc();
1412 /* Initialize the command */
1413 ctlx->outbuf.rridreq.type = cpu_to_le16(HFA384x_USB_RRIDREQ);
1414 ctlx->outbuf.rridreq.frmlen =
1415 cpu_to_le16(sizeof(ctlx->outbuf.rridreq.rid));
1416 ctlx->outbuf.rridreq.rid = cpu_to_le16(rid);
1418 ctlx->outbufsize = sizeof(ctlx->outbuf.rridreq);
1420 ctlx->reapable = mode;
1421 ctlx->cmdcb = cmdcb;
1422 ctlx->usercb = usercb;
1423 ctlx->usercb_data = usercb_data;
1425 /* Submit the CTLX */
1426 result = hfa384x_usbctlx_submit(hw, ctlx);
1429 } else if (mode == DOWAIT) {
1430 struct usbctlx_rrid_completor completor;
1433 hfa384x_usbctlx_complete_sync(hw, ctlx,
1436 &ctlx->inbuf.rridresp,
1437 riddata, riddatalen));
1444 /*----------------------------------------------------------------
1447 * Constructs a write rid CTLX and issues it.
1449 * NOTE: Any changes to the 'post-submit' code in this function
1450 * need to be carried over to hfa384x_cbwrid() since the handling
1451 * is virtually identical.
1454 * hw device structure
1455 * enum cmd_mode DOWAIT or DOASYNC
1457 * riddata Data portion of RID formatted for MAC
1458 * riddatalen Length of the data portion in bytes
1459 * cmdcb command callback for async calls, NULL for DOWAIT calls
1460 * usercb user callback for async calls, NULL for DOWAIT calls
1461 * usercb_data user supplied data pointer for async calls
1465 * -ETIMEDOUT timed out waiting for register ready or
1466 * command completion
1467 * >0 command indicated error, Status and Resp0-2 are
1473 * interrupt (DOASYNC)
1474 * process (DOWAIT or DOASYNC)
1475 *----------------------------------------------------------------
1478 hfa384x_dowrid(struct hfa384x *hw,
1482 unsigned int riddatalen,
1483 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1486 struct hfa384x_usbctlx *ctlx;
1488 ctlx = usbctlx_alloc();
1494 /* Initialize the command */
1495 ctlx->outbuf.wridreq.type = cpu_to_le16(HFA384x_USB_WRIDREQ);
1496 ctlx->outbuf.wridreq.frmlen = cpu_to_le16((sizeof
1497 (ctlx->outbuf.wridreq.rid) +
1498 riddatalen + 1) / 2);
1499 ctlx->outbuf.wridreq.rid = cpu_to_le16(rid);
1500 memcpy(ctlx->outbuf.wridreq.data, riddata, riddatalen);
1502 ctlx->outbufsize = sizeof(ctlx->outbuf.wridreq.type) +
1503 sizeof(ctlx->outbuf.wridreq.frmlen) +
1504 sizeof(ctlx->outbuf.wridreq.rid) + riddatalen;
1506 ctlx->reapable = mode;
1507 ctlx->cmdcb = cmdcb;
1508 ctlx->usercb = usercb;
1509 ctlx->usercb_data = usercb_data;
1511 /* Submit the CTLX */
1512 result = hfa384x_usbctlx_submit(hw, ctlx);
1515 } else if (mode == DOWAIT) {
1516 struct usbctlx_cmd_completor completor;
1517 struct hfa384x_cmdresult wridresult;
1519 result = hfa384x_usbctlx_complete_sync(hw,
1523 &ctlx->inbuf.wridresp,
1531 /*----------------------------------------------------------------
1534 * Constructs a readmem CTLX and issues it.
1536 * NOTE: Any changes to the 'post-submit' code in this function
1537 * need to be carried over to hfa384x_cbrmem() since the handling
1538 * is virtually identical.
1541 * hw device structure
1542 * mode DOWAIT or DOASYNC
1543 * page MAC address space page (CMD format)
1544 * offset MAC address space offset
1545 * data Ptr to data buffer to receive read
1546 * len Length of the data to read (max == 2048)
1547 * cmdcb command callback for async calls, NULL for DOWAIT calls
1548 * usercb user callback for async calls, NULL for DOWAIT calls
1549 * usercb_data user supplied data pointer for async calls
1553 * -ETIMEDOUT timed out waiting for register ready or
1554 * command completion
1555 * >0 command indicated error, Status and Resp0-2 are
1561 * interrupt (DOASYNC)
1562 * process (DOWAIT or DOASYNC)
1563 *----------------------------------------------------------------
1566 hfa384x_dormem(struct hfa384x *hw,
1572 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1575 struct hfa384x_usbctlx *ctlx;
1577 ctlx = usbctlx_alloc();
1583 /* Initialize the command */
1584 ctlx->outbuf.rmemreq.type = cpu_to_le16(HFA384x_USB_RMEMREQ);
1585 ctlx->outbuf.rmemreq.frmlen =
1586 cpu_to_le16(sizeof(ctlx->outbuf.rmemreq.offset) +
1587 sizeof(ctlx->outbuf.rmemreq.page) + len);
1588 ctlx->outbuf.rmemreq.offset = cpu_to_le16(offset);
1589 ctlx->outbuf.rmemreq.page = cpu_to_le16(page);
1591 ctlx->outbufsize = sizeof(ctlx->outbuf.rmemreq);
1593 pr_debug("type=0x%04x frmlen=%d offset=0x%04x page=0x%04x\n",
1594 ctlx->outbuf.rmemreq.type,
1595 ctlx->outbuf.rmemreq.frmlen,
1596 ctlx->outbuf.rmemreq.offset, ctlx->outbuf.rmemreq.page);
1598 pr_debug("pktsize=%zd\n", ROUNDUP64(sizeof(ctlx->outbuf.rmemreq)));
1600 ctlx->reapable = mode;
1601 ctlx->cmdcb = cmdcb;
1602 ctlx->usercb = usercb;
1603 ctlx->usercb_data = usercb_data;
1605 result = hfa384x_usbctlx_submit(hw, ctlx);
1608 } else if (mode == DOWAIT) {
1609 struct usbctlx_rmem_completor completor;
1612 hfa384x_usbctlx_complete_sync(hw, ctlx,
1615 &ctlx->inbuf.rmemresp, data,
1623 /*----------------------------------------------------------------
1626 * Constructs a writemem CTLX and issues it.
1628 * NOTE: Any changes to the 'post-submit' code in this function
1629 * need to be carried over to hfa384x_cbwmem() since the handling
1630 * is virtually identical.
1633 * hw device structure
1634 * mode DOWAIT or DOASYNC
1635 * page MAC address space page (CMD format)
1636 * offset MAC address space offset
1637 * data Ptr to data buffer containing write data
1638 * len Length of the data to read (max == 2048)
1639 * cmdcb command callback for async calls, NULL for DOWAIT calls
1640 * usercb user callback for async calls, NULL for DOWAIT calls
1641 * usercb_data user supplied data pointer for async calls.
1645 * -ETIMEDOUT timed out waiting for register ready or
1646 * command completion
1647 * >0 command indicated error, Status and Resp0-2 are
1653 * interrupt (DOWAIT)
1654 * process (DOWAIT or DOASYNC)
1655 *----------------------------------------------------------------
1658 hfa384x_dowmem(struct hfa384x *hw,
1664 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1667 struct hfa384x_usbctlx *ctlx;
1669 pr_debug("page=0x%04x offset=0x%04x len=%d\n", page, offset, len);
1671 ctlx = usbctlx_alloc();
1677 /* Initialize the command */
1678 ctlx->outbuf.wmemreq.type = cpu_to_le16(HFA384x_USB_WMEMREQ);
1679 ctlx->outbuf.wmemreq.frmlen =
1680 cpu_to_le16(sizeof(ctlx->outbuf.wmemreq.offset) +
1681 sizeof(ctlx->outbuf.wmemreq.page) + len);
1682 ctlx->outbuf.wmemreq.offset = cpu_to_le16(offset);
1683 ctlx->outbuf.wmemreq.page = cpu_to_le16(page);
1684 memcpy(ctlx->outbuf.wmemreq.data, data, len);
1686 ctlx->outbufsize = sizeof(ctlx->outbuf.wmemreq.type) +
1687 sizeof(ctlx->outbuf.wmemreq.frmlen) +
1688 sizeof(ctlx->outbuf.wmemreq.offset) +
1689 sizeof(ctlx->outbuf.wmemreq.page) + len;
1691 ctlx->reapable = mode;
1692 ctlx->cmdcb = cmdcb;
1693 ctlx->usercb = usercb;
1694 ctlx->usercb_data = usercb_data;
1696 result = hfa384x_usbctlx_submit(hw, ctlx);
1699 } else if (mode == DOWAIT) {
1700 struct usbctlx_cmd_completor completor;
1701 struct hfa384x_cmdresult wmemresult;
1703 result = hfa384x_usbctlx_complete_sync(hw,
1707 &ctlx->inbuf.wmemresp,
1715 /*----------------------------------------------------------------
1716 * hfa384x_drvr_disable
1718 * Issues the disable command to stop communications on one of
1719 * the MACs 'ports'. Only macport 0 is valid for stations.
1720 * APs may also disable macports 1-6. Only ports that have been
1721 * previously enabled may be disabled.
1724 * hw device structure
1725 * macport MAC port number (host order)
1729 * >0 f/w reported failure - f/w status code
1730 * <0 driver reported error (timeout|bad arg)
1736 *----------------------------------------------------------------
1738 int hfa384x_drvr_disable(struct hfa384x *hw, u16 macport)
1742 if ((!hw->isap && macport != 0) ||
1743 (hw->isap && !(macport <= HFA384x_PORTID_MAX)) ||
1744 !(hw->port_enabled[macport])) {
1747 result = hfa384x_cmd_disable(hw, macport);
1749 hw->port_enabled[macport] = 0;
1754 /*----------------------------------------------------------------
1755 * hfa384x_drvr_enable
1757 * Issues the enable command to enable communications on one of
1758 * the MACs 'ports'. Only macport 0 is valid for stations.
1759 * APs may also enable macports 1-6. Only ports that are currently
1760 * disabled may be enabled.
1763 * hw device structure
1764 * macport MAC port number
1768 * >0 f/w reported failure - f/w status code
1769 * <0 driver reported error (timeout|bad arg)
1775 *----------------------------------------------------------------
1777 int hfa384x_drvr_enable(struct hfa384x *hw, u16 macport)
1781 if ((!hw->isap && macport != 0) ||
1782 (hw->isap && !(macport <= HFA384x_PORTID_MAX)) ||
1783 (hw->port_enabled[macport])) {
1786 result = hfa384x_cmd_enable(hw, macport);
1788 hw->port_enabled[macport] = 1;
1793 /*----------------------------------------------------------------
1794 * hfa384x_drvr_flashdl_enable
1796 * Begins the flash download state. Checks to see that we're not
1797 * already in a download state and that a port isn't enabled.
1798 * Sets the download state and retrieves the flash download
1799 * buffer location, buffer size, and timeout length.
1802 * hw device structure
1806 * >0 f/w reported error - f/w status code
1807 * <0 driver reported error
1813 *----------------------------------------------------------------
1815 int hfa384x_drvr_flashdl_enable(struct hfa384x *hw)
1820 /* Check that a port isn't active */
1821 for (i = 0; i < HFA384x_PORTID_MAX; i++) {
1822 if (hw->port_enabled[i]) {
1823 pr_debug("called when port enabled.\n");
1828 /* Check that we're not already in a download state */
1829 if (hw->dlstate != HFA384x_DLSTATE_DISABLED)
1832 /* Retrieve the buffer loc&size and timeout */
1833 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_DOWNLOADBUFFER,
1834 &hw->bufinfo, sizeof(hw->bufinfo));
1838 le16_to_cpus(&hw->bufinfo.page);
1839 le16_to_cpus(&hw->bufinfo.offset);
1840 le16_to_cpus(&hw->bufinfo.len);
1841 result = hfa384x_drvr_getconfig16(hw, HFA384x_RID_MAXLOADTIME,
1846 le16_to_cpus(&hw->dltimeout);
1848 pr_debug("flashdl_enable\n");
1850 hw->dlstate = HFA384x_DLSTATE_FLASHENABLED;
1855 /*----------------------------------------------------------------
1856 * hfa384x_drvr_flashdl_disable
1858 * Ends the flash download state. Note that this will cause the MAC
1859 * firmware to restart.
1862 * hw device structure
1866 * >0 f/w reported error - f/w status code
1867 * <0 driver reported error
1873 *----------------------------------------------------------------
1875 int hfa384x_drvr_flashdl_disable(struct hfa384x *hw)
1877 /* Check that we're already in the download state */
1878 if (hw->dlstate != HFA384x_DLSTATE_FLASHENABLED)
1881 pr_debug("flashdl_enable\n");
1883 /* There isn't much we can do at this point, so I don't */
1884 /* bother w/ the return value */
1885 hfa384x_cmd_download(hw, HFA384x_PROGMODE_DISABLE, 0, 0, 0);
1886 hw->dlstate = HFA384x_DLSTATE_DISABLED;
1891 /*----------------------------------------------------------------
1892 * hfa384x_drvr_flashdl_write
1894 * Performs a FLASH download of a chunk of data. First checks to see
1895 * that we're in the FLASH download state, then sets the download
1896 * mode, uses the aux functions to 1) copy the data to the flash
1897 * buffer, 2) sets the download 'write flash' mode, 3) readback and
1898 * compare. Lather rinse, repeat as many times an necessary to get
1899 * all the given data into flash.
1900 * When all data has been written using this function (possibly
1901 * repeatedly), call drvr_flashdl_disable() to end the download state
1902 * and restart the MAC.
1905 * hw device structure
1906 * daddr Card address to write to. (host order)
1907 * buf Ptr to data to write.
1908 * len Length of data (host order).
1912 * >0 f/w reported error - f/w status code
1913 * <0 driver reported error
1919 *----------------------------------------------------------------
1921 int hfa384x_drvr_flashdl_write(struct hfa384x *hw, u32 daddr,
1939 pr_debug("daddr=0x%08x len=%d\n", daddr, len);
1941 /* Check that we're in the flash download state */
1942 if (hw->dlstate != HFA384x_DLSTATE_FLASHENABLED)
1945 netdev_info(hw->wlandev->netdev,
1946 "Download %d bytes to flash @0x%06x\n", len, daddr);
1948 /* Convert to flat address for arithmetic */
1949 /* NOTE: dlbuffer RID stores the address in AUX format */
1951 HFA384x_ADDR_AUX_MKFLAT(hw->bufinfo.page, hw->bufinfo.offset);
1952 pr_debug("dlbuf.page=0x%04x dlbuf.offset=0x%04x dlbufaddr=0x%08x\n",
1953 hw->bufinfo.page, hw->bufinfo.offset, dlbufaddr);
1954 /* Calculations to determine how many fills of the dlbuffer to do
1955 * and how many USB wmemreq's to do for each fill. At this point
1956 * in time, the dlbuffer size and the wmemreq size are the same.
1957 * Therefore, nwrites should always be 1. The extra complexity
1958 * here is a hedge against future changes.
1961 /* Figure out how many times to do the flash programming */
1962 nburns = len / hw->bufinfo.len;
1963 nburns += (len % hw->bufinfo.len) ? 1 : 0;
1965 /* For each flash program cycle, how many USB wmemreq's are needed? */
1966 nwrites = hw->bufinfo.len / HFA384x_USB_RWMEM_MAXLEN;
1967 nwrites += (hw->bufinfo.len % HFA384x_USB_RWMEM_MAXLEN) ? 1 : 0;
1970 for (i = 0; i < nburns; i++) {
1971 /* Get the dest address and len */
1972 burnlen = (len - (hw->bufinfo.len * i)) > hw->bufinfo.len ?
1973 hw->bufinfo.len : (len - (hw->bufinfo.len * i));
1974 burndaddr = daddr + (hw->bufinfo.len * i);
1975 burnlo = HFA384x_ADDR_CMD_MKOFF(burndaddr);
1976 burnhi = HFA384x_ADDR_CMD_MKPAGE(burndaddr);
1978 netdev_info(hw->wlandev->netdev, "Writing %d bytes to flash @0x%06x\n",
1979 burnlen, burndaddr);
1981 /* Set the download mode */
1982 result = hfa384x_cmd_download(hw, HFA384x_PROGMODE_NV,
1983 burnlo, burnhi, burnlen);
1985 netdev_err(hw->wlandev->netdev,
1986 "download(NV,lo=%x,hi=%x,len=%x) cmd failed, result=%d. Aborting d/l\n",
1987 burnlo, burnhi, burnlen, result);
1991 /* copy the data to the flash download buffer */
1992 for (j = 0; j < nwrites; j++) {
1994 (i * hw->bufinfo.len) +
1995 (j * HFA384x_USB_RWMEM_MAXLEN);
1997 writepage = HFA384x_ADDR_CMD_MKPAGE(dlbufaddr +
1998 (j * HFA384x_USB_RWMEM_MAXLEN));
1999 writeoffset = HFA384x_ADDR_CMD_MKOFF(dlbufaddr +
2000 (j * HFA384x_USB_RWMEM_MAXLEN));
2002 writelen = burnlen - (j * HFA384x_USB_RWMEM_MAXLEN);
2003 writelen = writelen > HFA384x_USB_RWMEM_MAXLEN ?
2004 HFA384x_USB_RWMEM_MAXLEN : writelen;
2006 result = hfa384x_dowmem_wait(hw,
2009 writebuf, writelen);
2012 /* set the download 'write flash' mode */
2013 result = hfa384x_cmd_download(hw,
2014 HFA384x_PROGMODE_NVWRITE,
2017 netdev_err(hw->wlandev->netdev,
2018 "download(NVWRITE,lo=%x,hi=%x,len=%x) cmd failed, result=%d. Aborting d/l\n",
2019 burnlo, burnhi, burnlen, result);
2023 /* TODO: We really should do a readback and compare. */
2028 /* Leave the firmware in the 'post-prog' mode. flashdl_disable will */
2029 /* actually disable programming mode. Remember, that will cause the */
2030 /* the firmware to effectively reset itself. */
2035 /*----------------------------------------------------------------
2036 * hfa384x_drvr_getconfig
2038 * Performs the sequence necessary to read a config/info item.
2041 * hw device structure
2042 * rid config/info record id (host order)
2043 * buf host side record buffer. Upon return it will
2044 * contain the body portion of the record (minus the
2046 * len buffer length (in bytes, should match record length)
2050 * >0 f/w reported error - f/w status code
2051 * <0 driver reported error
2052 * -ENODATA length mismatch between argument and retrieved
2059 *----------------------------------------------------------------
2061 int hfa384x_drvr_getconfig(struct hfa384x *hw, u16 rid, void *buf, u16 len)
2063 return hfa384x_dorrid_wait(hw, rid, buf, len);
2066 /*----------------------------------------------------------------
2067 * hfa384x_drvr_setconfig_async
2069 * Performs the sequence necessary to write a config/info item.
2072 * hw device structure
2073 * rid config/info record id (in host order)
2074 * buf host side record buffer
2075 * len buffer length (in bytes)
2076 * usercb completion callback
2077 * usercb_data completion callback argument
2081 * >0 f/w reported error - f/w status code
2082 * <0 driver reported error
2088 *----------------------------------------------------------------
2091 hfa384x_drvr_setconfig_async(struct hfa384x *hw,
2094 u16 len, ctlx_usercb_t usercb, void *usercb_data)
2096 return hfa384x_dowrid_async(hw, rid, buf, len,
2097 hfa384x_cb_status, usercb, usercb_data);
2100 /*----------------------------------------------------------------
2101 * hfa384x_drvr_ramdl_disable
2103 * Ends the ram download state.
2106 * hw device structure
2110 * >0 f/w reported error - f/w status code
2111 * <0 driver reported error
2117 *----------------------------------------------------------------
2119 int hfa384x_drvr_ramdl_disable(struct hfa384x *hw)
2121 /* Check that we're already in the download state */
2122 if (hw->dlstate != HFA384x_DLSTATE_RAMENABLED)
2125 pr_debug("ramdl_disable()\n");
2127 /* There isn't much we can do at this point, so I don't */
2128 /* bother w/ the return value */
2129 hfa384x_cmd_download(hw, HFA384x_PROGMODE_DISABLE, 0, 0, 0);
2130 hw->dlstate = HFA384x_DLSTATE_DISABLED;
2135 /*----------------------------------------------------------------
2136 * hfa384x_drvr_ramdl_enable
2138 * Begins the ram download state. Checks to see that we're not
2139 * already in a download state and that a port isn't enabled.
2140 * Sets the download state and calls cmd_download with the
2141 * ENABLE_VOLATILE subcommand and the exeaddr argument.
2144 * hw device structure
2145 * exeaddr the card execution address that will be
2146 * jumped to when ramdl_disable() is called
2151 * >0 f/w reported error - f/w status code
2152 * <0 driver reported error
2158 *----------------------------------------------------------------
2160 int hfa384x_drvr_ramdl_enable(struct hfa384x *hw, u32 exeaddr)
2167 /* Check that a port isn't active */
2168 for (i = 0; i < HFA384x_PORTID_MAX; i++) {
2169 if (hw->port_enabled[i]) {
2170 netdev_err(hw->wlandev->netdev,
2171 "Can't download with a macport enabled.\n");
2176 /* Check that we're not already in a download state */
2177 if (hw->dlstate != HFA384x_DLSTATE_DISABLED) {
2178 netdev_err(hw->wlandev->netdev,
2179 "Download state not disabled.\n");
2183 pr_debug("ramdl_enable, exeaddr=0x%08x\n", exeaddr);
2185 /* Call the download(1,addr) function */
2186 lowaddr = HFA384x_ADDR_CMD_MKOFF(exeaddr);
2187 hiaddr = HFA384x_ADDR_CMD_MKPAGE(exeaddr);
2189 result = hfa384x_cmd_download(hw, HFA384x_PROGMODE_RAM,
2190 lowaddr, hiaddr, 0);
2193 /* Set the download state */
2194 hw->dlstate = HFA384x_DLSTATE_RAMENABLED;
2196 pr_debug("cmd_download(0x%04x, 0x%04x) failed, result=%d.\n",
2197 lowaddr, hiaddr, result);
2203 /*----------------------------------------------------------------
2204 * hfa384x_drvr_ramdl_write
2206 * Performs a RAM download of a chunk of data. First checks to see
2207 * that we're in the RAM download state, then uses the [read|write]mem USB
2208 * commands to 1) copy the data, 2) readback and compare. The download
2209 * state is unaffected. When all data has been written using
2210 * this function, call drvr_ramdl_disable() to end the download state
2211 * and restart the MAC.
2214 * hw device structure
2215 * daddr Card address to write to. (host order)
2216 * buf Ptr to data to write.
2217 * len Length of data (host order).
2221 * >0 f/w reported error - f/w status code
2222 * <0 driver reported error
2228 *----------------------------------------------------------------
2230 int hfa384x_drvr_ramdl_write(struct hfa384x *hw, u32 daddr, void *buf, u32 len)
2241 /* Check that we're in the ram download state */
2242 if (hw->dlstate != HFA384x_DLSTATE_RAMENABLED)
2245 netdev_info(hw->wlandev->netdev, "Writing %d bytes to ram @0x%06x\n",
2248 /* How many dowmem calls? */
2249 nwrites = len / HFA384x_USB_RWMEM_MAXLEN;
2250 nwrites += len % HFA384x_USB_RWMEM_MAXLEN ? 1 : 0;
2252 /* Do blocking wmem's */
2253 for (i = 0; i < nwrites; i++) {
2254 /* make address args */
2255 curraddr = daddr + (i * HFA384x_USB_RWMEM_MAXLEN);
2256 currpage = HFA384x_ADDR_CMD_MKPAGE(curraddr);
2257 curroffset = HFA384x_ADDR_CMD_MKOFF(curraddr);
2258 currlen = len - (i * HFA384x_USB_RWMEM_MAXLEN);
2259 if (currlen > HFA384x_USB_RWMEM_MAXLEN)
2260 currlen = HFA384x_USB_RWMEM_MAXLEN;
2262 /* Do blocking ctlx */
2263 result = hfa384x_dowmem_wait(hw,
2267 (i * HFA384x_USB_RWMEM_MAXLEN),
2273 /* TODO: We really should have a readback. */
2279 /*----------------------------------------------------------------
2280 * hfa384x_drvr_readpda
2282 * Performs the sequence to read the PDA space. Note there is no
2283 * drvr_writepda() function. Writing a PDA is
2284 * generally implemented by a calling component via calls to
2285 * cmd_download and writing to the flash download buffer via the
2289 * hw device structure
2290 * buf buffer to store PDA in
2295 * >0 f/w reported error - f/w status code
2296 * <0 driver reported error
2297 * -ETIMEDOUT timeout waiting for the cmd regs to become
2298 * available, or waiting for the control reg
2299 * to indicate the Aux port is enabled.
2300 * -ENODATA the buffer does NOT contain a valid PDA.
2301 * Either the card PDA is bad, or the auxdata
2302 * reads are giving us garbage.
2308 * process or non-card interrupt.
2309 *----------------------------------------------------------------
2311 int hfa384x_drvr_readpda(struct hfa384x *hw, void *buf, unsigned int len)
2317 int currpdr = 0; /* word offset of the current pdr */
2319 u16 pdrlen; /* pdr length in bytes, host order */
2320 u16 pdrcode; /* pdr code, host order */
2328 HFA3842_PDA_BASE, 0}, {
2329 HFA3841_PDA_BASE, 0}, {
2330 HFA3841_PDA_BOGUS_BASE, 0}
2333 /* Read the pda from each known address. */
2334 for (i = 0; i < ARRAY_SIZE(pdaloc); i++) {
2336 currpage = HFA384x_ADDR_CMD_MKPAGE(pdaloc[i].cardaddr);
2337 curroffset = HFA384x_ADDR_CMD_MKOFF(pdaloc[i].cardaddr);
2339 /* units of bytes */
2340 result = hfa384x_dormem_wait(hw, currpage, curroffset, buf,
2344 netdev_warn(hw->wlandev->netdev,
2345 "Read from index %zd failed, continuing\n",
2350 /* Test for garbage */
2351 pdaok = 1; /* initially assume good */
2353 while (pdaok && morepdrs) {
2354 pdrlen = le16_to_cpu(pda[currpdr]) * 2;
2355 pdrcode = le16_to_cpu(pda[currpdr + 1]);
2356 /* Test the record length */
2357 if (pdrlen > HFA384x_PDR_LEN_MAX || pdrlen == 0) {
2358 netdev_err(hw->wlandev->netdev,
2359 "pdrlen invalid=%d\n", pdrlen);
2364 if (!hfa384x_isgood_pdrcode(pdrcode)) {
2365 netdev_err(hw->wlandev->netdev, "pdrcode invalid=%d\n",
2370 /* Test for completion */
2371 if (pdrcode == HFA384x_PDR_END_OF_PDA)
2374 /* Move to the next pdr (if necessary) */
2376 /* note the access to pda[], need words here */
2377 currpdr += le16_to_cpu(pda[currpdr]) + 1;
2381 netdev_info(hw->wlandev->netdev,
2382 "PDA Read from 0x%08x in %s space.\n",
2384 pdaloc[i].auxctl == 0 ? "EXTDS" :
2385 pdaloc[i].auxctl == 1 ? "NV" :
2386 pdaloc[i].auxctl == 2 ? "PHY" :
2387 pdaloc[i].auxctl == 3 ? "ICSRAM" :
2392 result = pdaok ? 0 : -ENODATA;
2395 pr_debug("Failure: pda is not okay\n");
2400 /*----------------------------------------------------------------
2401 * hfa384x_drvr_setconfig
2403 * Performs the sequence necessary to write a config/info item.
2406 * hw device structure
2407 * rid config/info record id (in host order)
2408 * buf host side record buffer
2409 * len buffer length (in bytes)
2413 * >0 f/w reported error - f/w status code
2414 * <0 driver reported error
2420 *----------------------------------------------------------------
2422 int hfa384x_drvr_setconfig(struct hfa384x *hw, u16 rid, void *buf, u16 len)
2424 return hfa384x_dowrid_wait(hw, rid, buf, len);
2427 /*----------------------------------------------------------------
2428 * hfa384x_drvr_start
2430 * Issues the MAC initialize command, sets up some data structures,
2431 * and enables the interrupts. After this function completes, the
2432 * low-level stuff should be ready for any/all commands.
2435 * hw device structure
2438 * >0 f/w reported error - f/w status code
2439 * <0 driver reported error
2445 *----------------------------------------------------------------
2447 int hfa384x_drvr_start(struct hfa384x *hw)
2449 int result, result1, result2;
2454 /* Clear endpoint stalls - but only do this if the endpoint
2455 * is showing a stall status. Some prism2 cards seem to behave
2456 * badly if a clear_halt is called when the endpoint is already
2460 usb_get_std_status(hw->usb, USB_RECIP_ENDPOINT, hw->endp_in, &status);
2462 netdev_err(hw->wlandev->netdev, "Cannot get bulk in endpoint status.\n");
2465 if ((status == 1) && usb_clear_halt(hw->usb, hw->endp_in))
2466 netdev_err(hw->wlandev->netdev, "Failed to reset bulk in endpoint.\n");
2469 usb_get_std_status(hw->usb, USB_RECIP_ENDPOINT, hw->endp_out, &status);
2471 netdev_err(hw->wlandev->netdev, "Cannot get bulk out endpoint status.\n");
2474 if ((status == 1) && usb_clear_halt(hw->usb, hw->endp_out))
2475 netdev_err(hw->wlandev->netdev, "Failed to reset bulk out endpoint.\n");
2477 /* Synchronous unlink, in case we're trying to restart the driver */
2478 usb_kill_urb(&hw->rx_urb);
2480 /* Post the IN urb */
2481 result = submit_rx_urb(hw, GFP_KERNEL);
2483 netdev_err(hw->wlandev->netdev,
2484 "Fatal, failed to submit RX URB, result=%d\n",
2489 /* Call initialize twice, with a 1 second sleep in between.
2490 * This is a nasty work-around since many prism2 cards seem to
2491 * need time to settle after an init from cold. The second
2492 * call to initialize in theory is not necessary - but we call
2493 * it anyway as a double insurance policy:
2494 * 1) If the first init should fail, the second may well succeed
2495 * and the card can still be used
2496 * 2) It helps ensures all is well with the card after the first
2497 * init and settle time.
2499 result1 = hfa384x_cmd_initialize(hw);
2501 result = hfa384x_cmd_initialize(hw);
2505 netdev_err(hw->wlandev->netdev,
2506 "cmd_initialize() failed on two attempts, results %d and %d\n",
2508 usb_kill_urb(&hw->rx_urb);
2511 pr_debug("First cmd_initialize() failed (result %d),\n",
2513 pr_debug("but second attempt succeeded. All should be ok\n");
2515 } else if (result2 != 0) {
2516 netdev_warn(hw->wlandev->netdev, "First cmd_initialize() succeeded, but second attempt failed (result=%d)\n",
2518 netdev_warn(hw->wlandev->netdev,
2519 "Most likely the card will be functional\n");
2523 hw->state = HFA384x_STATE_RUNNING;
2529 /*----------------------------------------------------------------
2532 * Shuts down the MAC to the point where it is safe to unload the
2533 * driver. Any subsystem that may be holding a data or function
2534 * ptr into the driver must be cleared/deinitialized.
2537 * hw device structure
2540 * >0 f/w reported error - f/w status code
2541 * <0 driver reported error
2547 *----------------------------------------------------------------
2549 int hfa384x_drvr_stop(struct hfa384x *hw)
2555 /* There's no need for spinlocks here. The USB "disconnect"
2556 * function sets this "removed" flag and then calls us.
2558 if (!hw->wlandev->hwremoved) {
2559 /* Call initialize to leave the MAC in its 'reset' state */
2560 hfa384x_cmd_initialize(hw);
2562 /* Cancel the rxurb */
2563 usb_kill_urb(&hw->rx_urb);
2566 hw->link_status = HFA384x_LINK_NOTCONNECTED;
2567 hw->state = HFA384x_STATE_INIT;
2569 del_timer_sync(&hw->commsqual_timer);
2571 /* Clear all the port status */
2572 for (i = 0; i < HFA384x_NUMPORTS_MAX; i++)
2573 hw->port_enabled[i] = 0;
2578 /*----------------------------------------------------------------
2579 * hfa384x_drvr_txframe
2581 * Takes a frame from prism2sta and queues it for transmission.
2584 * hw device structure
2585 * skb packet buffer struct. Contains an 802.11
2587 * p80211_hdr points to the 802.11 header for the packet.
2589 * 0 Success and more buffs available
2590 * 1 Success but no more buffs
2591 * 2 Allocation failure
2592 * 4 Buffer full or queue busy
2598 *----------------------------------------------------------------
2600 int hfa384x_drvr_txframe(struct hfa384x *hw, struct sk_buff *skb,
2601 union p80211_hdr *p80211_hdr,
2602 struct p80211_metawep *p80211_wep)
2604 int usbpktlen = sizeof(struct hfa384x_tx_frame);
2609 if (hw->tx_urb.status == -EINPROGRESS) {
2610 netdev_warn(hw->wlandev->netdev, "TX URB already in use\n");
2615 /* Build Tx frame structure */
2616 /* Set up the control field */
2617 memset(&hw->txbuff.txfrm.desc, 0, sizeof(hw->txbuff.txfrm.desc));
2619 /* Setup the usb type field */
2620 hw->txbuff.type = cpu_to_le16(HFA384x_USB_TXFRM);
2622 /* Set up the sw_support field to identify this frame */
2623 hw->txbuff.txfrm.desc.sw_support = 0x0123;
2625 /* Tx complete and Tx exception disable per dleach. Might be causing
2628 /* #define DOEXC SLP -- doboth breaks horribly under load, doexc less so. */
2630 hw->txbuff.txfrm.desc.tx_control =
2631 HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
2632 HFA384x_TX_TXEX_SET(1) | HFA384x_TX_TXOK_SET(1);
2633 #elif defined(DOEXC)
2634 hw->txbuff.txfrm.desc.tx_control =
2635 HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
2636 HFA384x_TX_TXEX_SET(1) | HFA384x_TX_TXOK_SET(0);
2638 hw->txbuff.txfrm.desc.tx_control =
2639 HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
2640 HFA384x_TX_TXEX_SET(0) | HFA384x_TX_TXOK_SET(0);
2642 cpu_to_le16s(&hw->txbuff.txfrm.desc.tx_control);
2644 /* copy the header over to the txdesc */
2645 memcpy(&hw->txbuff.txfrm.desc.frame_control, p80211_hdr,
2646 sizeof(union p80211_hdr));
2648 /* if we're using host WEP, increase size by IV+ICV */
2649 if (p80211_wep->data) {
2650 hw->txbuff.txfrm.desc.data_len = cpu_to_le16(skb->len + 8);
2653 hw->txbuff.txfrm.desc.data_len = cpu_to_le16(skb->len);
2656 usbpktlen += skb->len;
2658 /* copy over the WEP IV if we are using host WEP */
2659 ptr = hw->txbuff.txfrm.data;
2660 if (p80211_wep->data) {
2661 memcpy(ptr, p80211_wep->iv, sizeof(p80211_wep->iv));
2662 ptr += sizeof(p80211_wep->iv);
2663 memcpy(ptr, p80211_wep->data, skb->len);
2665 memcpy(ptr, skb->data, skb->len);
2667 /* copy over the packet data */
2670 /* copy over the WEP ICV if we are using host WEP */
2671 if (p80211_wep->data)
2672 memcpy(ptr, p80211_wep->icv, sizeof(p80211_wep->icv));
2674 /* Send the USB packet */
2675 usb_fill_bulk_urb(&hw->tx_urb, hw->usb,
2677 &hw->txbuff, ROUNDUP64(usbpktlen),
2678 hfa384x_usbout_callback, hw->wlandev);
2679 hw->tx_urb.transfer_flags |= USB_QUEUE_BULK;
2682 ret = submit_tx_urb(hw, &hw->tx_urb, GFP_ATOMIC);
2684 netdev_err(hw->wlandev->netdev,
2685 "submit_tx_urb() failed, error=%d\n", ret);
2693 void hfa384x_tx_timeout(struct wlandevice *wlandev)
2695 struct hfa384x *hw = wlandev->priv;
2696 unsigned long flags;
2698 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2700 if (!hw->wlandev->hwremoved) {
2703 sched = !test_and_set_bit(WORK_TX_HALT, &hw->usb_flags);
2704 sched |= !test_and_set_bit(WORK_RX_HALT, &hw->usb_flags);
2706 schedule_work(&hw->usb_work);
2709 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2712 /*----------------------------------------------------------------
2713 * hfa384x_usbctlx_reaper_task
2715 * Tasklet to delete dead CTLX objects
2718 * data ptr to a struct hfa384x
2724 *----------------------------------------------------------------
2726 static void hfa384x_usbctlx_reaper_task(unsigned long data)
2728 struct hfa384x *hw = (struct hfa384x *)data;
2729 struct hfa384x_usbctlx *ctlx, *temp;
2730 unsigned long flags;
2732 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2734 /* This list is guaranteed to be empty if someone
2735 * has unplugged the adapter.
2737 list_for_each_entry_safe(ctlx, temp, &hw->ctlxq.reapable, list) {
2738 list_del(&ctlx->list);
2742 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2745 /*----------------------------------------------------------------
2746 * hfa384x_usbctlx_completion_task
2748 * Tasklet to call completion handlers for returned CTLXs
2751 * data ptr to struct hfa384x
2758 *----------------------------------------------------------------
2760 static void hfa384x_usbctlx_completion_task(unsigned long data)
2762 struct hfa384x *hw = (struct hfa384x *)data;
2763 struct hfa384x_usbctlx *ctlx, *temp;
2764 unsigned long flags;
2768 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2770 /* This list is guaranteed to be empty if someone
2771 * has unplugged the adapter ...
2773 list_for_each_entry_safe(ctlx, temp, &hw->ctlxq.completing, list) {
2774 /* Call the completion function that this
2775 * command was assigned, assuming it has one.
2778 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2779 ctlx->cmdcb(hw, ctlx);
2780 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2782 /* Make sure we don't try and complete
2783 * this CTLX more than once!
2787 /* Did someone yank the adapter out
2788 * while our list was (briefly) unlocked?
2790 if (hw->wlandev->hwremoved) {
2797 * "Reapable" CTLXs are ones which don't have any
2798 * threads waiting for them to die. Hence they must
2799 * be delivered to The Reaper!
2801 if (ctlx->reapable) {
2802 /* Move the CTLX off the "completing" list (hopefully)
2803 * on to the "reapable" list where the reaper task
2804 * can find it. And "reapable" means that this CTLX
2805 * isn't sitting on a wait-queue somewhere.
2807 list_move_tail(&ctlx->list, &hw->ctlxq.reapable);
2811 complete(&ctlx->done);
2813 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2816 tasklet_schedule(&hw->reaper_bh);
2819 /*----------------------------------------------------------------
2820 * unlocked_usbctlx_cancel_async
2822 * Mark the CTLX dead asynchronously, and ensure that the
2823 * next command on the queue is run afterwards.
2826 * hw ptr to the struct hfa384x structure
2827 * ctlx ptr to a CTLX structure
2830 * 0 the CTLX's URB is inactive
2831 * -EINPROGRESS the URB is currently being unlinked
2834 * Either process or interrupt, but presumably interrupt
2835 *----------------------------------------------------------------
2837 static int unlocked_usbctlx_cancel_async(struct hfa384x *hw,
2838 struct hfa384x_usbctlx *ctlx)
2843 * Try to delete the URB containing our request packet.
2844 * If we succeed, then its completion handler will be
2845 * called with a status of -ECONNRESET.
2847 hw->ctlx_urb.transfer_flags |= URB_ASYNC_UNLINK;
2848 ret = usb_unlink_urb(&hw->ctlx_urb);
2850 if (ret != -EINPROGRESS) {
2852 * The OUT URB had either already completed
2853 * or was still in the pending queue, so the
2854 * URB's completion function will not be called.
2855 * We will have to complete the CTLX ourselves.
2857 ctlx->state = CTLX_REQ_FAILED;
2858 unlocked_usbctlx_complete(hw, ctlx);
2865 /*----------------------------------------------------------------
2866 * unlocked_usbctlx_complete
2868 * A CTLX has completed. It may have been successful, it may not
2869 * have been. At this point, the CTLX should be quiescent. The URBs
2870 * aren't active and the timers should have been stopped.
2872 * The CTLX is migrated to the "completing" queue, and the completing
2873 * tasklet is scheduled.
2876 * hw ptr to a struct hfa384x structure
2877 * ctlx ptr to a ctlx structure
2885 * Either, assume interrupt
2886 *----------------------------------------------------------------
2888 static void unlocked_usbctlx_complete(struct hfa384x *hw,
2889 struct hfa384x_usbctlx *ctlx)
2891 /* Timers have been stopped, and ctlx should be in
2892 * a terminal state. Retire it from the "active"
2895 list_move_tail(&ctlx->list, &hw->ctlxq.completing);
2896 tasklet_schedule(&hw->completion_bh);
2898 switch (ctlx->state) {
2900 case CTLX_REQ_FAILED:
2901 /* This are the correct terminating states. */
2905 netdev_err(hw->wlandev->netdev, "CTLX[%d] not in a terminating state(%s)\n",
2906 le16_to_cpu(ctlx->outbuf.type),
2907 ctlxstr(ctlx->state));
2912 /*----------------------------------------------------------------
2913 * hfa384x_usbctlxq_run
2915 * Checks to see if the head item is running. If not, starts it.
2918 * hw ptr to struct hfa384x
2927 *----------------------------------------------------------------
2929 static void hfa384x_usbctlxq_run(struct hfa384x *hw)
2931 unsigned long flags;
2934 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2936 /* Only one active CTLX at any one time, because there's no
2937 * other (reliable) way to match the response URB to the
2940 * Don't touch any of these CTLXs if the hardware
2941 * has been removed or the USB subsystem is stalled.
2943 if (!list_empty(&hw->ctlxq.active) ||
2944 test_bit(WORK_TX_HALT, &hw->usb_flags) || hw->wlandev->hwremoved)
2947 while (!list_empty(&hw->ctlxq.pending)) {
2948 struct hfa384x_usbctlx *head;
2951 /* This is the first pending command */
2952 head = list_entry(hw->ctlxq.pending.next,
2953 struct hfa384x_usbctlx, list);
2955 /* We need to split this off to avoid a race condition */
2956 list_move_tail(&head->list, &hw->ctlxq.active);
2958 /* Fill the out packet */
2959 usb_fill_bulk_urb(&hw->ctlx_urb, hw->usb,
2961 &head->outbuf, ROUNDUP64(head->outbufsize),
2962 hfa384x_ctlxout_callback, hw);
2963 hw->ctlx_urb.transfer_flags |= USB_QUEUE_BULK;
2965 /* Now submit the URB and update the CTLX's state */
2966 result = usb_submit_urb(&hw->ctlx_urb, GFP_ATOMIC);
2968 /* This CTLX is now running on the active queue */
2969 head->state = CTLX_REQ_SUBMITTED;
2971 /* Start the OUT wait timer */
2972 hw->req_timer_done = 0;
2973 hw->reqtimer.expires = jiffies + HZ;
2974 add_timer(&hw->reqtimer);
2976 /* Start the IN wait timer */
2977 hw->resp_timer_done = 0;
2978 hw->resptimer.expires = jiffies + 2 * HZ;
2979 add_timer(&hw->resptimer);
2984 if (result == -EPIPE) {
2985 /* The OUT pipe needs resetting, so put
2986 * this CTLX back in the "pending" queue
2987 * and schedule a reset ...
2989 netdev_warn(hw->wlandev->netdev,
2990 "%s tx pipe stalled: requesting reset\n",
2991 hw->wlandev->netdev->name);
2992 list_move(&head->list, &hw->ctlxq.pending);
2993 set_bit(WORK_TX_HALT, &hw->usb_flags);
2994 schedule_work(&hw->usb_work);
2998 if (result == -ESHUTDOWN) {
2999 netdev_warn(hw->wlandev->netdev, "%s urb shutdown!\n",
3000 hw->wlandev->netdev->name);
3004 netdev_err(hw->wlandev->netdev, "Failed to submit CTLX[%d]: error=%d\n",
3005 le16_to_cpu(head->outbuf.type), result);
3006 unlocked_usbctlx_complete(hw, head);
3010 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3013 /*----------------------------------------------------------------
3014 * hfa384x_usbin_callback
3016 * Callback for URBs on the BULKIN endpoint.
3019 * urb ptr to the completed urb
3028 *----------------------------------------------------------------
3030 static void hfa384x_usbin_callback(struct urb *urb)
3032 struct wlandevice *wlandev = urb->context;
3034 union hfa384x_usbin *usbin;
3035 struct sk_buff *skb = NULL;
3046 if (!wlandev || !wlandev->netdev || wlandev->hwremoved)
3053 skb = hw->rx_urb_skb;
3054 if (!skb || (skb->data != urb->transfer_buffer)) {
3059 hw->rx_urb_skb = NULL;
3061 /* Check for error conditions within the URB */
3062 switch (urb->status) {
3066 /* Check for short packet */
3067 if (urb->actual_length == 0) {
3068 wlandev->netdev->stats.rx_errors++;
3069 wlandev->netdev->stats.rx_length_errors++;
3075 netdev_warn(hw->wlandev->netdev, "%s rx pipe stalled: requesting reset\n",
3076 wlandev->netdev->name);
3077 if (!test_and_set_bit(WORK_RX_HALT, &hw->usb_flags))
3078 schedule_work(&hw->usb_work);
3079 wlandev->netdev->stats.rx_errors++;
3086 if (!test_and_set_bit(THROTTLE_RX, &hw->usb_flags) &&
3087 !timer_pending(&hw->throttle)) {
3088 mod_timer(&hw->throttle, jiffies + THROTTLE_JIFFIES);
3090 wlandev->netdev->stats.rx_errors++;
3095 wlandev->netdev->stats.rx_over_errors++;
3101 pr_debug("status=%d, device removed.\n", urb->status);
3107 pr_debug("status=%d, urb explicitly unlinked.\n", urb->status);
3112 pr_debug("urb status=%d, transfer flags=0x%x\n",
3113 urb->status, urb->transfer_flags);
3114 wlandev->netdev->stats.rx_errors++;
3119 urb_status = urb->status;
3121 if (action != ABORT) {
3122 /* Repost the RX URB */
3123 result = submit_rx_urb(hw, GFP_ATOMIC);
3126 netdev_err(hw->wlandev->netdev,
3127 "Fatal, failed to resubmit rx_urb. error=%d\n",
3132 /* Handle any USB-IN packet */
3133 /* Note: the check of the sw_support field, the type field doesn't
3134 * have bit 12 set like the docs suggest.
3136 usbin = (union hfa384x_usbin *)urb->transfer_buffer;
3137 type = le16_to_cpu(usbin->type);
3138 if (HFA384x_USB_ISRXFRM(type)) {
3139 if (action == HANDLE) {
3140 if (usbin->txfrm.desc.sw_support == 0x0123) {
3141 hfa384x_usbin_txcompl(wlandev, usbin);
3143 skb_put(skb, sizeof(*usbin));
3144 hfa384x_usbin_rx(wlandev, skb);
3150 if (HFA384x_USB_ISTXFRM(type)) {
3151 if (action == HANDLE)
3152 hfa384x_usbin_txcompl(wlandev, usbin);
3156 case HFA384x_USB_INFOFRM:
3157 if (action == ABORT)
3159 if (action == HANDLE)
3160 hfa384x_usbin_info(wlandev, usbin);
3163 case HFA384x_USB_CMDRESP:
3164 case HFA384x_USB_WRIDRESP:
3165 case HFA384x_USB_RRIDRESP:
3166 case HFA384x_USB_WMEMRESP:
3167 case HFA384x_USB_RMEMRESP:
3168 /* ALWAYS, ALWAYS, ALWAYS handle this CTLX!!!! */
3169 hfa384x_usbin_ctlx(hw, usbin, urb_status);
3172 case HFA384x_USB_BUFAVAIL:
3173 pr_debug("Received BUFAVAIL packet, frmlen=%d\n",
3174 usbin->bufavail.frmlen);
3177 case HFA384x_USB_ERROR:
3178 pr_debug("Received USB_ERROR packet, errortype=%d\n",
3179 usbin->usberror.errortype);
3183 pr_debug("Unrecognized USBIN packet, type=%x, status=%d\n",
3184 usbin->type, urb_status);
3194 /*----------------------------------------------------------------
3195 * hfa384x_usbin_ctlx
3197 * We've received a URB containing a Prism2 "response" message.
3198 * This message needs to be matched up with a CTLX on the active
3199 * queue and our state updated accordingly.
3202 * hw ptr to struct hfa384x
3203 * usbin ptr to USB IN packet
3204 * urb_status status of this Bulk-In URB
3213 *----------------------------------------------------------------
3215 static void hfa384x_usbin_ctlx(struct hfa384x *hw, union hfa384x_usbin *usbin,
3218 struct hfa384x_usbctlx *ctlx;
3220 unsigned long flags;
3223 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3225 /* There can be only one CTLX on the active queue
3226 * at any one time, and this is the CTLX that the
3227 * timers are waiting for.
3229 if (list_empty(&hw->ctlxq.active))
3232 /* Remove the "response timeout". It's possible that
3233 * we are already too late, and that the timeout is
3234 * already running. And that's just too bad for us,
3235 * because we could lose our CTLX from the active
3238 if (del_timer(&hw->resptimer) == 0) {
3239 if (hw->resp_timer_done == 0) {
3240 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3244 hw->resp_timer_done = 1;
3247 ctlx = get_active_ctlx(hw);
3249 if (urb_status != 0) {
3251 * Bad CTLX, so get rid of it. But we only
3252 * remove it from the active queue if we're no
3253 * longer expecting the OUT URB to complete.
3255 if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0)
3258 const __le16 intype = (usbin->type & ~cpu_to_le16(0x8000));
3261 * Check that our message is what we're expecting ...
3263 if (ctlx->outbuf.type != intype) {
3264 netdev_warn(hw->wlandev->netdev,
3265 "Expected IN[%d], received IN[%d] - ignored.\n",
3266 le16_to_cpu(ctlx->outbuf.type),
3267 le16_to_cpu(intype));
3271 /* This URB has succeeded, so grab the data ... */
3272 memcpy(&ctlx->inbuf, usbin, sizeof(ctlx->inbuf));
3274 switch (ctlx->state) {
3275 case CTLX_REQ_SUBMITTED:
3277 * We have received our response URB before
3278 * our request has been acknowledged. Odd,
3279 * but our OUT URB is still alive...
3281 pr_debug("Causality violation: please reboot Universe\n");
3282 ctlx->state = CTLX_RESP_COMPLETE;
3285 case CTLX_REQ_COMPLETE:
3287 * This is the usual path: our request
3288 * has already been acknowledged, and
3289 * now we have received the reply too.
3291 ctlx->state = CTLX_COMPLETE;
3292 unlocked_usbctlx_complete(hw, ctlx);
3298 * Throw this CTLX away ...
3300 netdev_err(hw->wlandev->netdev,
3301 "Matched IN URB, CTLX[%d] in invalid state(%s). Discarded.\n",
3302 le16_to_cpu(ctlx->outbuf.type),
3303 ctlxstr(ctlx->state));
3304 if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0)
3311 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3314 hfa384x_usbctlxq_run(hw);
3317 /*----------------------------------------------------------------
3318 * hfa384x_usbin_txcompl
3320 * At this point we have the results of a previous transmit.
3323 * wlandev wlan device
3324 * usbin ptr to the usb transfer buffer
3333 *----------------------------------------------------------------
3335 static void hfa384x_usbin_txcompl(struct wlandevice *wlandev,
3336 union hfa384x_usbin *usbin)
3340 status = le16_to_cpu(usbin->type); /* yeah I know it says type... */
3342 /* Was there an error? */
3343 if (HFA384x_TXSTATUS_ISERROR(status))
3344 prism2sta_ev_txexc(wlandev, status);
3346 prism2sta_ev_tx(wlandev, status);
3349 /*----------------------------------------------------------------
3352 * At this point we have a successful received a rx frame packet.
3355 * wlandev wlan device
3356 * usbin ptr to the usb transfer buffer
3365 *----------------------------------------------------------------
3367 static void hfa384x_usbin_rx(struct wlandevice *wlandev, struct sk_buff *skb)
3369 union hfa384x_usbin *usbin = (union hfa384x_usbin *)skb->data;
3370 struct hfa384x *hw = wlandev->priv;
3372 struct p80211_rxmeta *rxmeta;
3376 /* Byte order convert once up front. */
3377 le16_to_cpus(&usbin->rxfrm.desc.status);
3378 le32_to_cpus(&usbin->rxfrm.desc.time);
3380 /* Now handle frame based on port# */
3381 switch (HFA384x_RXSTATUS_MACPORT_GET(usbin->rxfrm.desc.status)) {
3383 fc = le16_to_cpu(usbin->rxfrm.desc.frame_control);
3385 /* If exclude and we receive an unencrypted, drop it */
3386 if ((wlandev->hostwep & HOSTWEP_EXCLUDEUNENCRYPTED) &&
3387 !WLAN_GET_FC_ISWEP(fc)) {
3391 data_len = le16_to_cpu(usbin->rxfrm.desc.data_len);
3393 /* How much header data do we have? */
3394 hdrlen = p80211_headerlen(fc);
3396 /* Pull off the descriptor */
3397 skb_pull(skb, sizeof(struct hfa384x_rx_frame));
3399 /* Now shunt the header block up against the data block
3400 * with an "overlapping" copy
3402 memmove(skb_push(skb, hdrlen),
3403 &usbin->rxfrm.desc.frame_control, hdrlen);
3405 skb->dev = wlandev->netdev;
3407 /* And set the frame length properly */
3408 skb_trim(skb, data_len + hdrlen);
3410 /* The prism2 series does not return the CRC */
3411 memset(skb_put(skb, WLAN_CRC_LEN), 0xff, WLAN_CRC_LEN);
3413 skb_reset_mac_header(skb);
3415 /* Attach the rxmeta, set some stuff */
3416 p80211skb_rxmeta_attach(wlandev, skb);
3417 rxmeta = P80211SKB_RXMETA(skb);
3418 rxmeta->mactime = usbin->rxfrm.desc.time;
3419 rxmeta->rxrate = usbin->rxfrm.desc.rate;
3420 rxmeta->signal = usbin->rxfrm.desc.signal - hw->dbmadjust;
3421 rxmeta->noise = usbin->rxfrm.desc.silence - hw->dbmadjust;
3423 p80211netdev_rx(wlandev, skb);
3428 if (!HFA384x_RXSTATUS_ISFCSERR(usbin->rxfrm.desc.status)) {
3429 /* Copy to wlansnif skb */
3430 hfa384x_int_rxmonitor(wlandev, &usbin->rxfrm);
3433 pr_debug("Received monitor frame: FCSerr set\n");
3438 netdev_warn(hw->wlandev->netdev, "Received frame on unsupported port=%d\n",
3439 HFA384x_RXSTATUS_MACPORT_GET(
3440 usbin->rxfrm.desc.status));
3445 /*----------------------------------------------------------------
3446 * hfa384x_int_rxmonitor
3448 * Helper function for int_rx. Handles monitor frames.
3449 * Note that this function allocates space for the FCS and sets it
3450 * to 0xffffffff. The hfa384x doesn't give us the FCS value but the
3451 * higher layers expect it. 0xffffffff is used as a flag to indicate
3455 * wlandev wlan device structure
3456 * rxfrm rx descriptor read from card in int_rx
3462 * Allocates an skb and passes it up via the PF_PACKET interface.
3465 *----------------------------------------------------------------
3467 static void hfa384x_int_rxmonitor(struct wlandevice *wlandev,
3468 struct hfa384x_usb_rxfrm *rxfrm)
3470 struct hfa384x_rx_frame *rxdesc = &rxfrm->desc;
3471 unsigned int hdrlen = 0;
3472 unsigned int datalen = 0;
3473 unsigned int skblen = 0;
3476 struct sk_buff *skb;
3477 struct hfa384x *hw = wlandev->priv;
3479 /* Remember the status, time, and data_len fields are in host order */
3480 /* Figure out how big the frame is */
3481 fc = le16_to_cpu(rxdesc->frame_control);
3482 hdrlen = p80211_headerlen(fc);
3483 datalen = le16_to_cpu(rxdesc->data_len);
3485 /* Allocate an ind message+framesize skb */
3486 skblen = sizeof(struct p80211_caphdr) + hdrlen + datalen + WLAN_CRC_LEN;
3488 /* sanity check the length */
3490 (sizeof(struct p80211_caphdr) +
3491 WLAN_HDR_A4_LEN + WLAN_DATA_MAXLEN + WLAN_CRC_LEN)) {
3492 pr_debug("overlen frm: len=%zd\n",
3493 skblen - sizeof(struct p80211_caphdr));
3496 skb = dev_alloc_skb(skblen);
3500 /* only prepend the prism header if in the right mode */
3501 if ((wlandev->netdev->type == ARPHRD_IEEE80211_PRISM) &&
3502 (hw->sniffhdr != 0)) {
3503 struct p80211_caphdr *caphdr;
3504 /* The NEW header format! */
3505 datap = skb_put(skb, sizeof(struct p80211_caphdr));
3506 caphdr = (struct p80211_caphdr *)datap;
3508 caphdr->version = htonl(P80211CAPTURE_VERSION);
3509 caphdr->length = htonl(sizeof(struct p80211_caphdr));
3510 caphdr->mactime = __cpu_to_be64(rxdesc->time * 1000);
3511 caphdr->hosttime = __cpu_to_be64(jiffies);
3512 caphdr->phytype = htonl(4); /* dss_dot11_b */
3513 caphdr->channel = htonl(hw->sniff_channel);
3514 caphdr->datarate = htonl(rxdesc->rate);
3515 caphdr->antenna = htonl(0); /* unknown */
3516 caphdr->priority = htonl(0); /* unknown */
3517 caphdr->ssi_type = htonl(3); /* rssi_raw */
3518 caphdr->ssi_signal = htonl(rxdesc->signal);
3519 caphdr->ssi_noise = htonl(rxdesc->silence);
3520 caphdr->preamble = htonl(0); /* unknown */
3521 caphdr->encoding = htonl(1); /* cck */
3524 /* Copy the 802.11 header to the skb
3525 * (ctl frames may be less than a full header)
3527 skb_put_data(skb, &rxdesc->frame_control, hdrlen);
3529 /* If any, copy the data from the card to the skb */
3531 datap = skb_put_data(skb, rxfrm->data, datalen);
3533 /* check for unencrypted stuff if WEP bit set. */
3534 if (*(datap - hdrlen + 1) & 0x40) /* wep set */
3535 if ((*(datap) == 0xaa) && (*(datap + 1) == 0xaa))
3536 /* clear wep; it's the 802.2 header! */
3537 *(datap - hdrlen + 1) &= 0xbf;
3540 if (hw->sniff_fcs) {
3542 datap = skb_put(skb, WLAN_CRC_LEN);
3543 memset(datap, 0xff, WLAN_CRC_LEN);
3546 /* pass it back up */
3547 p80211netdev_rx(wlandev, skb);
3550 /*----------------------------------------------------------------
3551 * hfa384x_usbin_info
3553 * At this point we have a successful received a Prism2 info frame.
3556 * wlandev wlan device
3557 * usbin ptr to the usb transfer buffer
3566 *----------------------------------------------------------------
3568 static void hfa384x_usbin_info(struct wlandevice *wlandev,
3569 union hfa384x_usbin *usbin)
3571 le16_to_cpus(&usbin->infofrm.info.framelen);
3572 prism2sta_ev_info(wlandev, &usbin->infofrm.info);
3575 /*----------------------------------------------------------------
3576 * hfa384x_usbout_callback
3578 * Callback for URBs on the BULKOUT endpoint.
3581 * urb ptr to the completed urb
3590 *----------------------------------------------------------------
3592 static void hfa384x_usbout_callback(struct urb *urb)
3594 struct wlandevice *wlandev = urb->context;
3600 if (wlandev && wlandev->netdev) {
3601 switch (urb->status) {
3603 prism2sta_ev_alloc(wlandev);
3608 struct hfa384x *hw = wlandev->priv;
3610 netdev_warn(hw->wlandev->netdev,
3611 "%s tx pipe stalled: requesting reset\n",
3612 wlandev->netdev->name);
3613 if (!test_and_set_bit
3614 (WORK_TX_HALT, &hw->usb_flags))
3615 schedule_work(&hw->usb_work);
3616 wlandev->netdev->stats.tx_errors++;
3624 struct hfa384x *hw = wlandev->priv;
3626 if (!test_and_set_bit
3627 (THROTTLE_TX, &hw->usb_flags) &&
3628 !timer_pending(&hw->throttle)) {
3629 mod_timer(&hw->throttle,
3630 jiffies + THROTTLE_JIFFIES);
3632 wlandev->netdev->stats.tx_errors++;
3633 netif_stop_queue(wlandev->netdev);
3639 /* Ignorable errors */
3643 netdev_info(wlandev->netdev, "unknown urb->status=%d\n",
3645 wlandev->netdev->stats.tx_errors++;
3651 /*----------------------------------------------------------------
3652 * hfa384x_ctlxout_callback
3654 * Callback for control data on the BULKOUT endpoint.
3657 * urb ptr to the completed urb
3666 *----------------------------------------------------------------
3668 static void hfa384x_ctlxout_callback(struct urb *urb)
3670 struct hfa384x *hw = urb->context;
3671 int delete_resptimer = 0;
3674 struct hfa384x_usbctlx *ctlx;
3675 unsigned long flags;
3677 pr_debug("urb->status=%d\n", urb->status);
3681 if ((urb->status == -ESHUTDOWN) ||
3682 (urb->status == -ENODEV) || !hw)
3686 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3689 * Only one CTLX at a time on the "active" list, and
3690 * none at all if we are unplugged. However, we can
3691 * rely on the disconnect function to clean everything
3692 * up if someone unplugged the adapter.
3694 if (list_empty(&hw->ctlxq.active)) {
3695 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3700 * Having something on the "active" queue means
3701 * that we have timers to worry about ...
3703 if (del_timer(&hw->reqtimer) == 0) {
3704 if (hw->req_timer_done == 0) {
3706 * This timer was actually running while we
3707 * were trying to delete it. Let it terminate
3708 * gracefully instead.
3710 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3714 hw->req_timer_done = 1;
3717 ctlx = get_active_ctlx(hw);
3719 if (urb->status == 0) {
3720 /* Request portion of a CTLX is successful */
3721 switch (ctlx->state) {
3722 case CTLX_REQ_SUBMITTED:
3723 /* This OUT-ACK received before IN */
3724 ctlx->state = CTLX_REQ_COMPLETE;
3727 case CTLX_RESP_COMPLETE:
3728 /* IN already received before this OUT-ACK,
3729 * so this command must now be complete.
3731 ctlx->state = CTLX_COMPLETE;
3732 unlocked_usbctlx_complete(hw, ctlx);
3737 /* This is NOT a valid CTLX "success" state! */
3738 netdev_err(hw->wlandev->netdev,
3739 "Illegal CTLX[%d] success state(%s, %d) in OUT URB\n",
3740 le16_to_cpu(ctlx->outbuf.type),
3741 ctlxstr(ctlx->state), urb->status);
3745 /* If the pipe has stalled then we need to reset it */
3746 if ((urb->status == -EPIPE) &&
3747 !test_and_set_bit(WORK_TX_HALT, &hw->usb_flags)) {
3748 netdev_warn(hw->wlandev->netdev,
3749 "%s tx pipe stalled: requesting reset\n",
3750 hw->wlandev->netdev->name);
3751 schedule_work(&hw->usb_work);
3754 /* If someone cancels the OUT URB then its status
3755 * should be either -ECONNRESET or -ENOENT.
3757 ctlx->state = CTLX_REQ_FAILED;
3758 unlocked_usbctlx_complete(hw, ctlx);
3759 delete_resptimer = 1;
3764 if (delete_resptimer) {
3765 timer_ok = del_timer(&hw->resptimer);
3767 hw->resp_timer_done = 1;
3770 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3772 if (!timer_ok && (hw->resp_timer_done == 0)) {
3773 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3778 hfa384x_usbctlxq_run(hw);
3781 /*----------------------------------------------------------------
3782 * hfa384x_usbctlx_reqtimerfn
3784 * Timer response function for CTLX request timeouts. If this
3785 * function is called, it means that the callback for the OUT
3786 * URB containing a Prism2.x XXX_Request was never called.
3789 * data a ptr to the struct hfa384x
3798 *----------------------------------------------------------------
3800 static void hfa384x_usbctlx_reqtimerfn(struct timer_list *t)
3802 struct hfa384x *hw = from_timer(hw, t, reqtimer);
3803 unsigned long flags;
3805 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3807 hw->req_timer_done = 1;
3809 /* Removing the hardware automatically empties
3810 * the active list ...
3812 if (!list_empty(&hw->ctlxq.active)) {
3814 * We must ensure that our URB is removed from
3815 * the system, if it hasn't already expired.
3817 hw->ctlx_urb.transfer_flags |= URB_ASYNC_UNLINK;
3818 if (usb_unlink_urb(&hw->ctlx_urb) == -EINPROGRESS) {
3819 struct hfa384x_usbctlx *ctlx = get_active_ctlx(hw);
3821 ctlx->state = CTLX_REQ_FAILED;
3823 /* This URB was active, but has now been
3824 * cancelled. It will now have a status of
3825 * -ECONNRESET in the callback function.
3827 * We are cancelling this CTLX, so we're
3828 * not going to need to wait for a response.
3829 * The URB's callback function will check
3830 * that this timer is truly dead.
3832 if (del_timer(&hw->resptimer) != 0)
3833 hw->resp_timer_done = 1;
3837 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3840 /*----------------------------------------------------------------
3841 * hfa384x_usbctlx_resptimerfn
3843 * Timer response function for CTLX response timeouts. If this
3844 * function is called, it means that the callback for the IN
3845 * URB containing a Prism2.x XXX_Response was never called.
3848 * data a ptr to the struct hfa384x
3857 *----------------------------------------------------------------
3859 static void hfa384x_usbctlx_resptimerfn(struct timer_list *t)
3861 struct hfa384x *hw = from_timer(hw, t, resptimer);
3862 unsigned long flags;
3864 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3866 hw->resp_timer_done = 1;
3868 /* The active list will be empty if the
3869 * adapter has been unplugged ...
3871 if (!list_empty(&hw->ctlxq.active)) {
3872 struct hfa384x_usbctlx *ctlx = get_active_ctlx(hw);
3874 if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0) {
3875 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3876 hfa384x_usbctlxq_run(hw);
3880 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3883 /*----------------------------------------------------------------
3884 * hfa384x_usb_throttlefn
3897 *----------------------------------------------------------------
3899 static void hfa384x_usb_throttlefn(struct timer_list *t)
3901 struct hfa384x *hw = from_timer(hw, t, throttle);
3902 unsigned long flags;
3904 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3907 * We need to check BOTH the RX and the TX throttle controls,
3908 * so we use the bitwise OR instead of the logical OR.
3910 pr_debug("flags=0x%lx\n", hw->usb_flags);
3911 if (!hw->wlandev->hwremoved &&
3912 ((test_and_clear_bit(THROTTLE_RX, &hw->usb_flags) &&
3913 !test_and_set_bit(WORK_RX_RESUME, &hw->usb_flags)) |
3914 (test_and_clear_bit(THROTTLE_TX, &hw->usb_flags) &&
3915 !test_and_set_bit(WORK_TX_RESUME, &hw->usb_flags))
3917 schedule_work(&hw->usb_work);
3920 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3923 /*----------------------------------------------------------------
3924 * hfa384x_usbctlx_submit
3926 * Called from the doxxx functions to submit a CTLX to the queue
3929 * hw ptr to the hw struct
3930 * ctlx ctlx structure to enqueue
3933 * -ENODEV if the adapter is unplugged
3939 * process or interrupt
3940 *----------------------------------------------------------------
3942 static int hfa384x_usbctlx_submit(struct hfa384x *hw,
3943 struct hfa384x_usbctlx *ctlx)
3945 unsigned long flags;
3947 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3949 if (hw->wlandev->hwremoved) {
3950 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3954 ctlx->state = CTLX_PENDING;
3955 list_add_tail(&ctlx->list, &hw->ctlxq.pending);
3956 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3957 hfa384x_usbctlxq_run(hw);
3962 /*----------------------------------------------------------------
3963 * hfa384x_isgood_pdrcore
3965 * Quick check of PDR codes.
3968 * pdrcode PDR code number (host order)
3977 *----------------------------------------------------------------
3979 static int hfa384x_isgood_pdrcode(u16 pdrcode)
3982 case HFA384x_PDR_END_OF_PDA:
3983 case HFA384x_PDR_PCB_PARTNUM:
3984 case HFA384x_PDR_PDAVER:
3985 case HFA384x_PDR_NIC_SERIAL:
3986 case HFA384x_PDR_MKK_MEASUREMENTS:
3987 case HFA384x_PDR_NIC_RAMSIZE:
3988 case HFA384x_PDR_MFISUPRANGE:
3989 case HFA384x_PDR_CFISUPRANGE:
3990 case HFA384x_PDR_NICID:
3991 case HFA384x_PDR_MAC_ADDRESS:
3992 case HFA384x_PDR_REGDOMAIN:
3993 case HFA384x_PDR_ALLOWED_CHANNEL:
3994 case HFA384x_PDR_DEFAULT_CHANNEL:
3995 case HFA384x_PDR_TEMPTYPE:
3996 case HFA384x_PDR_IFR_SETTING:
3997 case HFA384x_PDR_RFR_SETTING:
3998 case HFA384x_PDR_HFA3861_BASELINE:
3999 case HFA384x_PDR_HFA3861_SHADOW:
4000 case HFA384x_PDR_HFA3861_IFRF:
4001 case HFA384x_PDR_HFA3861_CHCALSP:
4002 case HFA384x_PDR_HFA3861_CHCALI:
4003 case HFA384x_PDR_3842_NIC_CONFIG:
4004 case HFA384x_PDR_USB_ID:
4005 case HFA384x_PDR_PCI_ID:
4006 case HFA384x_PDR_PCI_IFCONF:
4007 case HFA384x_PDR_PCI_PMCONF:
4008 case HFA384x_PDR_RFENRGY:
4009 case HFA384x_PDR_HFA3861_MANF_TESTSP:
4010 case HFA384x_PDR_HFA3861_MANF_TESTI:
4014 if (pdrcode < 0x1000) {
4015 /* code is OK, but we don't know exactly what it is */
4016 pr_debug("Encountered unknown PDR#=0x%04x, assuming it's ok.\n",
4023 pr_debug("Encountered unknown PDR#=0x%04x, (>=0x1000), assuming it's bad.\n",