1 // SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1)
2 /* src/prism2/driver/hfa384x_usb.c
4 * Functions that talk to the USB variant of the Intersil hfa384x MAC
6 * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
7 * --------------------------------------------------------------------
11 * The contents of this file are subject to the Mozilla Public
12 * License Version 1.1 (the "License"); you may not use this file
13 * except in compliance with the License. You may obtain a copy of
14 * the License at http://www.mozilla.org/MPL/
16 * Software distributed under the License is distributed on an "AS
17 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
18 * implied. See the License for the specific language governing
19 * rights and limitations under the License.
21 * Alternatively, the contents of this file may be used under the
22 * terms of the GNU Public License version 2 (the "GPL"), in which
23 * case the provisions of the GPL are applicable instead of the
24 * above. If you wish to allow the use of your version of this file
25 * only under the terms of the GPL and not to allow others to use
26 * your version of this file under the MPL, indicate your decision
27 * by deleting the provisions above and replace them with the notice
28 * and other provisions required by the GPL. If you do not delete
29 * the provisions above, a recipient may use your version of this
30 * file under either the MPL or the GPL.
32 * --------------------------------------------------------------------
34 * Inquiries regarding the linux-wlan Open Source project can be
37 * AbsoluteValue Systems Inc.
39 * http://www.linux-wlan.com
41 * --------------------------------------------------------------------
43 * Portions of the development of this software were funded by
44 * Intersil Corporation as part of PRISM(R) chipset product development.
46 * --------------------------------------------------------------------
48 * This file implements functions that correspond to the prism2/hfa384x
49 * 802.11 MAC hardware and firmware host interface.
51 * The functions can be considered to represent several levels of
52 * abstraction. The lowest level functions are simply C-callable wrappers
53 * around the register accesses. The next higher level represents C-callable
54 * prism2 API functions that match the Intersil documentation as closely
55 * as is reasonable. The next higher layer implements common sequences
56 * of invocations of the API layer (e.g. write to bap, followed by cmd).
59 * hfa384x_drvr_xxx Highest level abstractions provided by the
60 * hfa384x code. They are driver defined wrappers
61 * for common sequences. These functions generally
62 * use the services of the lower levels.
64 * hfa384x_drvr_xxxconfig An example of the drvr level abstraction. These
65 * functions are wrappers for the RID get/set
66 * sequence. They call copy_[to|from]_bap() and
67 * cmd_access(). These functions operate on the
68 * RIDs and buffers without validation. The caller
69 * is responsible for that.
71 * API wrapper functions:
72 * hfa384x_cmd_xxx functions that provide access to the f/w commands.
73 * The function arguments correspond to each command
74 * argument, even command arguments that get packed
75 * into single registers. These functions _just_
76 * issue the command by setting the cmd/parm regs
77 * & reading the status/resp regs. Additional
78 * activities required to fully use a command
79 * (read/write from/to bap, get/set int status etc.)
80 * are implemented separately. Think of these as
81 * C-callable prism2 commands.
83 * Lowest Layer Functions:
84 * hfa384x_docmd_xxx These functions implement the sequence required
85 * to issue any prism2 command. Primarily used by the
86 * hfa384x_cmd_xxx functions.
88 * hfa384x_bap_xxx BAP read/write access functions.
89 * Note: we usually use BAP0 for non-interrupt context
90 * and BAP1 for interrupt context.
92 * hfa384x_dl_xxx download related functions.
94 * Driver State Issues:
95 * Note that there are two pairs of functions that manage the
96 * 'initialized' and 'running' states of the hw/MAC combo. The four
97 * functions are create(), destroy(), start(), and stop(). create()
98 * sets up the data structures required to support the hfa384x_*
99 * functions and destroy() cleans them up. The start() function gets
100 * the actual hardware running and enables the interrupts. The stop()
101 * function shuts the hardware down. The sequence should be:
105 * . Do interesting things w/ the hardware
110 * Note that destroy() can be called without calling stop() first.
111 * --------------------------------------------------------------------
114 #include <linux/module.h>
115 #include <linux/kernel.h>
116 #include <linux/sched.h>
117 #include <linux/types.h>
118 #include <linux/slab.h>
119 #include <linux/wireless.h>
120 #include <linux/netdevice.h>
121 #include <linux/timer.h>
122 #include <linux/io.h>
123 #include <linux/delay.h>
124 #include <asm/byteorder.h>
125 #include <linux/bitops.h>
126 #include <linux/list.h>
127 #include <linux/usb.h>
128 #include <linux/byteorder/generic.h>
130 #include "p80211types.h"
131 #include "p80211hdr.h"
132 #include "p80211mgmt.h"
133 #include "p80211conv.h"
134 #include "p80211msg.h"
135 #include "p80211netdev.h"
136 #include "p80211req.h"
137 #include "p80211metadef.h"
138 #include "p80211metastruct.h"
140 #include "prism2mgmt.h"
147 #define THROTTLE_JIFFIES (HZ / 8)
148 #define URB_ASYNC_UNLINK 0
149 #define USB_QUEUE_BULK 0
151 #define ROUNDUP64(a) (((a) + 63) & ~63)
154 static void dbprint_urb(struct urb *urb);
157 static void hfa384x_int_rxmonitor(struct wlandevice *wlandev,
158 struct hfa384x_usb_rxfrm *rxfrm);
160 static void hfa384x_usb_defer(struct work_struct *data);
162 static int submit_rx_urb(struct hfa384x *hw, gfp_t flags);
164 static int submit_tx_urb(struct hfa384x *hw, struct urb *tx_urb, gfp_t flags);
166 /*---------------------------------------------------*/
168 static void hfa384x_usbout_callback(struct urb *urb);
169 static void hfa384x_ctlxout_callback(struct urb *urb);
170 static void hfa384x_usbin_callback(struct urb *urb);
173 hfa384x_usbin_txcompl(struct wlandevice *wlandev, union hfa384x_usbin *usbin);
175 static void hfa384x_usbin_rx(struct wlandevice *wlandev, struct sk_buff *skb);
177 static void hfa384x_usbin_info(struct wlandevice *wlandev,
178 union hfa384x_usbin *usbin);
180 static void hfa384x_usbin_ctlx(struct hfa384x *hw, union hfa384x_usbin *usbin,
183 /*---------------------------------------------------*/
184 /* Functions to support the prism2 usb command queue */
186 static void hfa384x_usbctlxq_run(struct hfa384x *hw);
188 static void hfa384x_usbctlx_reqtimerfn(struct timer_list *t);
190 static void hfa384x_usbctlx_resptimerfn(struct timer_list *t);
192 static void hfa384x_usb_throttlefn(struct timer_list *t);
194 static void hfa384x_usbctlx_completion_task(struct tasklet_struct *t);
196 static void hfa384x_usbctlx_reaper_task(struct tasklet_struct *t);
198 static int hfa384x_usbctlx_submit(struct hfa384x *hw,
199 struct hfa384x_usbctlx *ctlx);
201 static void unlocked_usbctlx_complete(struct hfa384x *hw,
202 struct hfa384x_usbctlx *ctlx);
204 struct usbctlx_completor {
205 int (*complete)(struct usbctlx_completor *completor);
209 hfa384x_usbctlx_complete_sync(struct hfa384x *hw,
210 struct hfa384x_usbctlx *ctlx,
211 struct usbctlx_completor *completor);
214 unlocked_usbctlx_cancel_async(struct hfa384x *hw, struct hfa384x_usbctlx *ctlx);
216 static void hfa384x_cb_status(struct hfa384x *hw,
217 const struct hfa384x_usbctlx *ctlx);
220 usbctlx_get_status(const struct hfa384x_usb_statusresp *cmdresp,
221 struct hfa384x_cmdresult *result);
224 usbctlx_get_rridresult(const struct hfa384x_usb_rridresp *rridresp,
225 struct hfa384x_rridresult *result);
227 /*---------------------------------------------------*/
228 /* Low level req/resp CTLX formatters and submitters */
230 hfa384x_docmd(struct hfa384x *hw,
231 struct hfa384x_metacmd *cmd);
234 hfa384x_dorrid(struct hfa384x *hw,
238 unsigned int riddatalen,
239 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
242 hfa384x_dowrid(struct hfa384x *hw,
246 unsigned int riddatalen,
247 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
250 hfa384x_dormem(struct hfa384x *hw,
257 hfa384x_dowmem(struct hfa384x *hw,
263 static int hfa384x_isgood_pdrcode(u16 pdrcode);
265 static inline const char *ctlxstr(enum ctlx_state s)
267 static const char * const ctlx_str[] = {
272 "Request packet submitted",
273 "Request packet completed",
274 "Response packet completed"
280 static inline struct hfa384x_usbctlx *get_active_ctlx(struct hfa384x *hw)
282 return list_entry(hw->ctlxq.active.next, struct hfa384x_usbctlx, list);
286 void dbprint_urb(struct urb *urb)
288 pr_debug("urb->pipe=0x%08x\n", urb->pipe);
289 pr_debug("urb->status=0x%08x\n", urb->status);
290 pr_debug("urb->transfer_flags=0x%08x\n", urb->transfer_flags);
291 pr_debug("urb->transfer_buffer=0x%08x\n",
292 (unsigned int)urb->transfer_buffer);
293 pr_debug("urb->transfer_buffer_length=0x%08x\n",
294 urb->transfer_buffer_length);
295 pr_debug("urb->actual_length=0x%08x\n", urb->actual_length);
296 pr_debug("urb->setup_packet(ctl)=0x%08x\n",
297 (unsigned int)urb->setup_packet);
298 pr_debug("urb->start_frame(iso/irq)=0x%08x\n", urb->start_frame);
299 pr_debug("urb->interval(irq)=0x%08x\n", urb->interval);
300 pr_debug("urb->error_count(iso)=0x%08x\n", urb->error_count);
301 pr_debug("urb->context=0x%08x\n", (unsigned int)urb->context);
302 pr_debug("urb->complete=0x%08x\n", (unsigned int)urb->complete);
306 /*----------------------------------------------------------------
309 * Listen for input data on the BULK-IN pipe. If the pipe has
310 * stalled then schedule it to be reset.
314 * memflags memory allocation flags
317 * error code from submission
321 *----------------------------------------------------------------
323 static int submit_rx_urb(struct hfa384x *hw, gfp_t memflags)
328 skb = dev_alloc_skb(sizeof(union hfa384x_usbin));
334 /* Post the IN urb */
335 usb_fill_bulk_urb(&hw->rx_urb, hw->usb,
337 skb->data, sizeof(union hfa384x_usbin),
338 hfa384x_usbin_callback, hw->wlandev);
340 hw->rx_urb_skb = skb;
343 if (!hw->wlandev->hwremoved &&
344 !test_bit(WORK_RX_HALT, &hw->usb_flags)) {
345 result = usb_submit_urb(&hw->rx_urb, memflags);
347 /* Check whether we need to reset the RX pipe */
348 if (result == -EPIPE) {
349 netdev_warn(hw->wlandev->netdev,
350 "%s rx pipe stalled: requesting reset\n",
351 hw->wlandev->netdev->name);
352 if (!test_and_set_bit(WORK_RX_HALT, &hw->usb_flags))
353 schedule_work(&hw->usb_work);
357 /* Don't leak memory if anything should go wrong */
360 hw->rx_urb_skb = NULL;
367 /*----------------------------------------------------------------
370 * Prepares and submits the URB of transmitted data. If the
371 * submission fails then it will schedule the output pipe to
376 * tx_urb URB of data for transmission
377 * memflags memory allocation flags
380 * error code from submission
384 *----------------------------------------------------------------
386 static int submit_tx_urb(struct hfa384x *hw, struct urb *tx_urb, gfp_t memflags)
388 struct net_device *netdev = hw->wlandev->netdev;
392 if (netif_running(netdev)) {
393 if (!hw->wlandev->hwremoved &&
394 !test_bit(WORK_TX_HALT, &hw->usb_flags)) {
395 result = usb_submit_urb(tx_urb, memflags);
397 /* Test whether we need to reset the TX pipe */
398 if (result == -EPIPE) {
399 netdev_warn(hw->wlandev->netdev,
400 "%s tx pipe stalled: requesting reset\n",
402 set_bit(WORK_TX_HALT, &hw->usb_flags);
403 schedule_work(&hw->usb_work);
404 } else if (result == 0) {
405 netif_stop_queue(netdev);
413 /*----------------------------------------------------------------
416 * There are some things that the USB stack cannot do while
417 * in interrupt context, so we arrange this function to run
418 * in process context.
421 * hw device structure
427 * process (by design)
428 *----------------------------------------------------------------
430 static void hfa384x_usb_defer(struct work_struct *data)
432 struct hfa384x *hw = container_of(data, struct hfa384x, usb_work);
433 struct net_device *netdev = hw->wlandev->netdev;
435 /* Don't bother trying to reset anything if the plug
436 * has been pulled ...
438 if (hw->wlandev->hwremoved)
441 /* Reception has stopped: try to reset the input pipe */
442 if (test_bit(WORK_RX_HALT, &hw->usb_flags)) {
445 usb_kill_urb(&hw->rx_urb); /* Cannot be holding spinlock! */
447 ret = usb_clear_halt(hw->usb, hw->endp_in);
449 netdev_err(hw->wlandev->netdev,
450 "Failed to clear rx pipe for %s: err=%d\n",
453 netdev_info(hw->wlandev->netdev, "%s rx pipe reset complete.\n",
455 clear_bit(WORK_RX_HALT, &hw->usb_flags);
456 set_bit(WORK_RX_RESUME, &hw->usb_flags);
460 /* Resume receiving data back from the device. */
461 if (test_bit(WORK_RX_RESUME, &hw->usb_flags)) {
464 ret = submit_rx_urb(hw, GFP_KERNEL);
466 netdev_err(hw->wlandev->netdev,
467 "Failed to resume %s rx pipe.\n",
470 clear_bit(WORK_RX_RESUME, &hw->usb_flags);
474 /* Transmission has stopped: try to reset the output pipe */
475 if (test_bit(WORK_TX_HALT, &hw->usb_flags)) {
478 usb_kill_urb(&hw->tx_urb);
479 ret = usb_clear_halt(hw->usb, hw->endp_out);
481 netdev_err(hw->wlandev->netdev,
482 "Failed to clear tx pipe for %s: err=%d\n",
485 netdev_info(hw->wlandev->netdev, "%s tx pipe reset complete.\n",
487 clear_bit(WORK_TX_HALT, &hw->usb_flags);
488 set_bit(WORK_TX_RESUME, &hw->usb_flags);
490 /* Stopping the BULK-OUT pipe also blocked
491 * us from sending any more CTLX URBs, so
492 * we need to re-run our queue ...
494 hfa384x_usbctlxq_run(hw);
498 /* Resume transmitting. */
499 if (test_and_clear_bit(WORK_TX_RESUME, &hw->usb_flags))
500 netif_wake_queue(hw->wlandev->netdev);
503 /*----------------------------------------------------------------
506 * Sets up the struct hfa384x data structure for use. Note this
507 * does _not_ initialize the actual hardware, just the data structures
508 * we use to keep track of its state.
511 * hw device structure
512 * irq device irq number
513 * iobase i/o base address for register access
514 * membase memory base address for register access
523 *----------------------------------------------------------------
525 void hfa384x_create(struct hfa384x *hw, struct usb_device *usb)
529 /* Set up the waitq */
530 init_waitqueue_head(&hw->cmdq);
532 /* Initialize the command queue */
533 spin_lock_init(&hw->ctlxq.lock);
534 INIT_LIST_HEAD(&hw->ctlxq.pending);
535 INIT_LIST_HEAD(&hw->ctlxq.active);
536 INIT_LIST_HEAD(&hw->ctlxq.completing);
537 INIT_LIST_HEAD(&hw->ctlxq.reapable);
539 /* Initialize the authentication queue */
540 skb_queue_head_init(&hw->authq);
542 tasklet_setup(&hw->reaper_bh, hfa384x_usbctlx_reaper_task);
543 tasklet_setup(&hw->completion_bh, hfa384x_usbctlx_completion_task);
544 INIT_WORK(&hw->link_bh, prism2sta_processing_defer);
545 INIT_WORK(&hw->usb_work, hfa384x_usb_defer);
547 timer_setup(&hw->throttle, hfa384x_usb_throttlefn, 0);
549 timer_setup(&hw->resptimer, hfa384x_usbctlx_resptimerfn, 0);
551 timer_setup(&hw->reqtimer, hfa384x_usbctlx_reqtimerfn, 0);
553 usb_init_urb(&hw->rx_urb);
554 usb_init_urb(&hw->tx_urb);
555 usb_init_urb(&hw->ctlx_urb);
557 hw->link_status = HFA384x_LINK_NOTCONNECTED;
558 hw->state = HFA384x_STATE_INIT;
560 INIT_WORK(&hw->commsqual_bh, prism2sta_commsqual_defer);
561 timer_setup(&hw->commsqual_timer, prism2sta_commsqual_timer, 0);
564 /*----------------------------------------------------------------
567 * Partner to hfa384x_create(). This function cleans up the hw
568 * structure so that it can be freed by the caller using a simple
569 * kfree. Currently, this function is just a placeholder. If, at some
570 * point in the future, an hw in the 'shutdown' state requires a 'deep'
571 * kfree, this is where it should be done. Note that if this function
572 * is called on a _running_ hw structure, the drvr_stop() function is
576 * hw device structure
579 * nothing, this function is not allowed to fail.
585 *----------------------------------------------------------------
587 void hfa384x_destroy(struct hfa384x *hw)
591 if (hw->state == HFA384x_STATE_RUNNING)
592 hfa384x_drvr_stop(hw);
593 hw->state = HFA384x_STATE_PREINIT;
595 kfree(hw->scanresults);
596 hw->scanresults = NULL;
598 /* Now to clean out the auth queue */
599 while ((skb = skb_dequeue(&hw->authq)))
603 static struct hfa384x_usbctlx *usbctlx_alloc(void)
605 struct hfa384x_usbctlx *ctlx;
607 ctlx = kzalloc(sizeof(*ctlx),
608 in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
610 init_completion(&ctlx->done);
616 usbctlx_get_status(const struct hfa384x_usb_statusresp *cmdresp,
617 struct hfa384x_cmdresult *result)
619 result->status = le16_to_cpu(cmdresp->status);
620 result->resp0 = le16_to_cpu(cmdresp->resp0);
621 result->resp1 = le16_to_cpu(cmdresp->resp1);
622 result->resp2 = le16_to_cpu(cmdresp->resp2);
624 pr_debug("cmdresult:status=0x%04x resp0=0x%04x resp1=0x%04x resp2=0x%04x\n",
625 result->status, result->resp0, result->resp1, result->resp2);
627 return result->status & HFA384x_STATUS_RESULT;
631 usbctlx_get_rridresult(const struct hfa384x_usb_rridresp *rridresp,
632 struct hfa384x_rridresult *result)
634 result->rid = le16_to_cpu(rridresp->rid);
635 result->riddata = rridresp->data;
636 result->riddata_len = ((le16_to_cpu(rridresp->frmlen) - 1) * 2);
639 /*----------------------------------------------------------------
641 * This completor must be passed to hfa384x_usbctlx_complete_sync()
642 * when processing a CTLX that returns a struct hfa384x_cmdresult structure.
643 *----------------------------------------------------------------
645 struct usbctlx_cmd_completor {
646 struct usbctlx_completor head;
648 const struct hfa384x_usb_statusresp *cmdresp;
649 struct hfa384x_cmdresult *result;
652 static inline int usbctlx_cmd_completor_fn(struct usbctlx_completor *head)
654 struct usbctlx_cmd_completor *complete;
656 complete = (struct usbctlx_cmd_completor *)head;
657 return usbctlx_get_status(complete->cmdresp, complete->result);
660 static inline struct usbctlx_completor *
661 init_cmd_completor(struct usbctlx_cmd_completor *completor,
662 const struct hfa384x_usb_statusresp *cmdresp,
663 struct hfa384x_cmdresult *result)
665 completor->head.complete = usbctlx_cmd_completor_fn;
666 completor->cmdresp = cmdresp;
667 completor->result = result;
668 return &completor->head;
671 /*----------------------------------------------------------------
673 * This completor must be passed to hfa384x_usbctlx_complete_sync()
674 * when processing a CTLX that reads a RID.
675 *----------------------------------------------------------------
677 struct usbctlx_rrid_completor {
678 struct usbctlx_completor head;
680 const struct hfa384x_usb_rridresp *rridresp;
682 unsigned int riddatalen;
685 static int usbctlx_rrid_completor_fn(struct usbctlx_completor *head)
687 struct usbctlx_rrid_completor *complete;
688 struct hfa384x_rridresult rridresult;
690 complete = (struct usbctlx_rrid_completor *)head;
691 usbctlx_get_rridresult(complete->rridresp, &rridresult);
693 /* Validate the length, note body len calculation in bytes */
694 if (rridresult.riddata_len != complete->riddatalen) {
695 pr_warn("RID len mismatch, rid=0x%04x hlen=%d fwlen=%d\n",
697 complete->riddatalen, rridresult.riddata_len);
701 memcpy(complete->riddata, rridresult.riddata, complete->riddatalen);
705 static inline struct usbctlx_completor *
706 init_rrid_completor(struct usbctlx_rrid_completor *completor,
707 const struct hfa384x_usb_rridresp *rridresp,
709 unsigned int riddatalen)
711 completor->head.complete = usbctlx_rrid_completor_fn;
712 completor->rridresp = rridresp;
713 completor->riddata = riddata;
714 completor->riddatalen = riddatalen;
715 return &completor->head;
718 /*----------------------------------------------------------------
720 * Interprets the results of a synchronous RID-write
721 *----------------------------------------------------------------
723 #define init_wrid_completor init_cmd_completor
725 /*----------------------------------------------------------------
727 * Interprets the results of a synchronous memory-write
728 *----------------------------------------------------------------
730 #define init_wmem_completor init_cmd_completor
732 /*----------------------------------------------------------------
734 * Interprets the results of a synchronous memory-read
735 *----------------------------------------------------------------
737 struct usbctlx_rmem_completor {
738 struct usbctlx_completor head;
740 const struct hfa384x_usb_rmemresp *rmemresp;
745 static int usbctlx_rmem_completor_fn(struct usbctlx_completor *head)
747 struct usbctlx_rmem_completor *complete =
748 (struct usbctlx_rmem_completor *)head;
750 pr_debug("rmemresp:len=%d\n", complete->rmemresp->frmlen);
751 memcpy(complete->data, complete->rmemresp->data, complete->len);
755 static inline struct usbctlx_completor *
756 init_rmem_completor(struct usbctlx_rmem_completor *completor,
757 struct hfa384x_usb_rmemresp *rmemresp,
761 completor->head.complete = usbctlx_rmem_completor_fn;
762 completor->rmemresp = rmemresp;
763 completor->data = data;
764 completor->len = len;
765 return &completor->head;
768 /*----------------------------------------------------------------
771 * Ctlx_complete handler for async CMD type control exchanges.
772 * mark the hw struct as such.
774 * Note: If the handling is changed here, it should probably be
775 * changed in docmd as well.
779 * ctlx completed CTLX
788 *----------------------------------------------------------------
790 static void hfa384x_cb_status(struct hfa384x *hw,
791 const struct hfa384x_usbctlx *ctlx)
794 struct hfa384x_cmdresult cmdresult;
796 if (ctlx->state != CTLX_COMPLETE) {
797 memset(&cmdresult, 0, sizeof(cmdresult));
799 HFA384x_STATUS_RESULT_SET(HFA384x_CMD_ERR);
801 usbctlx_get_status(&ctlx->inbuf.cmdresp, &cmdresult);
804 ctlx->usercb(hw, &cmdresult, ctlx->usercb_data);
808 /*----------------------------------------------------------------
809 * hfa384x_cmd_initialize
811 * Issues the initialize command and sets the hw->state based
815 * hw device structure
819 * >0 f/w reported error - f/w status code
820 * <0 driver reported error
826 *----------------------------------------------------------------
828 int hfa384x_cmd_initialize(struct hfa384x *hw)
832 struct hfa384x_metacmd cmd;
834 cmd.cmd = HFA384x_CMDCODE_INIT;
839 result = hfa384x_docmd(hw, &cmd);
841 pr_debug("cmdresp.init: status=0x%04x, resp0=0x%04x, resp1=0x%04x, resp2=0x%04x\n",
843 cmd.result.resp0, cmd.result.resp1, cmd.result.resp2);
845 for (i = 0; i < HFA384x_NUMPORTS_MAX; i++)
846 hw->port_enabled[i] = 0;
849 hw->link_status = HFA384x_LINK_NOTCONNECTED;
854 /*----------------------------------------------------------------
855 * hfa384x_cmd_disable
857 * Issues the disable command to stop communications on one of
861 * hw device structure
862 * macport MAC port number (host order)
866 * >0 f/w reported failure - f/w status code
867 * <0 driver reported error (timeout|bad arg)
873 *----------------------------------------------------------------
875 int hfa384x_cmd_disable(struct hfa384x *hw, u16 macport)
877 struct hfa384x_metacmd cmd;
879 cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_DISABLE) |
880 HFA384x_CMD_MACPORT_SET(macport);
885 return hfa384x_docmd(hw, &cmd);
888 /*----------------------------------------------------------------
891 * Issues the enable command to enable communications on one of
895 * hw device structure
896 * macport MAC port number
900 * >0 f/w reported failure - f/w status code
901 * <0 driver reported error (timeout|bad arg)
907 *----------------------------------------------------------------
909 int hfa384x_cmd_enable(struct hfa384x *hw, u16 macport)
911 struct hfa384x_metacmd cmd;
913 cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_ENABLE) |
914 HFA384x_CMD_MACPORT_SET(macport);
919 return hfa384x_docmd(hw, &cmd);
922 /*----------------------------------------------------------------
923 * hfa384x_cmd_monitor
925 * Enables the 'monitor mode' of the MAC. Here's the description of
926 * monitor mode that I've received thus far:
928 * "The "monitor mode" of operation is that the MAC passes all
929 * frames for which the PLCP checks are correct. All received
930 * MPDUs are passed to the host with MAC Port = 7, with a
931 * receive status of good, FCS error, or undecryptable. Passing
932 * certain MPDUs is a violation of the 802.11 standard, but useful
933 * for a debugging tool." Normal communication is not possible
934 * while monitor mode is enabled.
937 * hw device structure
938 * enable a code (0x0b|0x0f) that enables/disables
939 * monitor mode. (host order)
943 * >0 f/w reported failure - f/w status code
944 * <0 driver reported error (timeout|bad arg)
950 *----------------------------------------------------------------
952 int hfa384x_cmd_monitor(struct hfa384x *hw, u16 enable)
954 struct hfa384x_metacmd cmd;
956 cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_MONITOR) |
957 HFA384x_CMD_AINFO_SET(enable);
962 return hfa384x_docmd(hw, &cmd);
965 /*----------------------------------------------------------------
966 * hfa384x_cmd_download
968 * Sets the controls for the MAC controller code/data download
969 * process. The arguments set the mode and address associated
970 * with a download. Note that the aux registers should be enabled
971 * prior to setting one of the download enable modes.
974 * hw device structure
975 * mode 0 - Disable programming and begin code exec
976 * 1 - Enable volatile mem programming
977 * 2 - Enable non-volatile mem programming
978 * 3 - Program non-volatile section from NV download
982 * highaddr For mode 1, sets the high & low order bits of
983 * the "destination address". This address will be
984 * the execution start address when download is
985 * subsequently disabled.
986 * For mode 2, sets the high & low order bits of
987 * the destination in NV ram.
988 * For modes 0 & 3, should be zero. (host order)
989 * NOTE: these are CMD format.
990 * codelen Length of the data to write in mode 2,
991 * zero otherwise. (host order)
995 * >0 f/w reported failure - f/w status code
996 * <0 driver reported error (timeout|bad arg)
1002 *----------------------------------------------------------------
1004 int hfa384x_cmd_download(struct hfa384x *hw, u16 mode, u16 lowaddr,
1005 u16 highaddr, u16 codelen)
1007 struct hfa384x_metacmd cmd;
1009 pr_debug("mode=%d, lowaddr=0x%04x, highaddr=0x%04x, codelen=%d\n",
1010 mode, lowaddr, highaddr, codelen);
1012 cmd.cmd = (HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_DOWNLD) |
1013 HFA384x_CMD_PROGMODE_SET(mode));
1015 cmd.parm0 = lowaddr;
1016 cmd.parm1 = highaddr;
1017 cmd.parm2 = codelen;
1019 return hfa384x_docmd(hw, &cmd);
1022 /*----------------------------------------------------------------
1025 * Perform a reset of the hfa38xx MAC core. We assume that the hw
1026 * structure is in its "created" state. That is, it is initialized
1027 * with proper values. Note that if a reset is done after the
1028 * device has been active for awhile, the caller might have to clean
1029 * up some leftover cruft in the hw structure.
1032 * hw device structure
1033 * holdtime how long (in ms) to hold the reset
1034 * settletime how long (in ms) to wait after releasing
1044 *----------------------------------------------------------------
1046 int hfa384x_corereset(struct hfa384x *hw, int holdtime,
1047 int settletime, int genesis)
1051 result = usb_reset_device(hw->usb);
1053 netdev_err(hw->wlandev->netdev, "usb_reset_device() failed, result=%d.\n",
1060 /*----------------------------------------------------------------
1061 * hfa384x_usbctlx_complete_sync
1063 * Waits for a synchronous CTLX object to complete,
1064 * and then handles the response.
1067 * hw device structure
1069 * completor functor object to decide what to
1070 * do with the CTLX's result.
1074 * -ERESTARTSYS Interrupted by a signal
1076 * -ENODEV Adapter was unplugged
1077 * ??? Result from completor
1083 *----------------------------------------------------------------
1085 static int hfa384x_usbctlx_complete_sync(struct hfa384x *hw,
1086 struct hfa384x_usbctlx *ctlx,
1087 struct usbctlx_completor *completor)
1089 unsigned long flags;
1092 result = wait_for_completion_interruptible(&ctlx->done);
1094 spin_lock_irqsave(&hw->ctlxq.lock, flags);
1097 * We can only handle the CTLX if the USB disconnect
1098 * function has not run yet ...
1101 if (hw->wlandev->hwremoved) {
1102 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1104 } else if (result != 0) {
1108 * We were probably interrupted, so delete
1109 * this CTLX asynchronously, kill the timers
1110 * and the URB, and then start the next
1113 * NOTE: We can only delete the timers and
1114 * the URB if this CTLX is active.
1116 if (ctlx == get_active_ctlx(hw)) {
1117 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1119 del_singleshot_timer_sync(&hw->reqtimer);
1120 del_singleshot_timer_sync(&hw->resptimer);
1121 hw->req_timer_done = 1;
1122 hw->resp_timer_done = 1;
1123 usb_kill_urb(&hw->ctlx_urb);
1125 spin_lock_irqsave(&hw->ctlxq.lock, flags);
1130 * This scenario is so unlikely that I'm
1131 * happy with a grubby "goto" solution ...
1133 if (hw->wlandev->hwremoved)
1138 * The completion task will send this CTLX
1139 * to the reaper the next time it runs. We
1140 * are no longer in a hurry.
1143 ctlx->state = CTLX_REQ_FAILED;
1144 list_move_tail(&ctlx->list, &hw->ctlxq.completing);
1146 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1149 hfa384x_usbctlxq_run(hw);
1151 if (ctlx->state == CTLX_COMPLETE) {
1152 result = completor->complete(completor);
1154 netdev_warn(hw->wlandev->netdev, "CTLX[%d] error: state(%s)\n",
1155 le16_to_cpu(ctlx->outbuf.type),
1156 ctlxstr(ctlx->state));
1160 list_del(&ctlx->list);
1161 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1168 /*----------------------------------------------------------------
1171 * Constructs a command CTLX and submits it.
1173 * NOTE: Any changes to the 'post-submit' code in this function
1174 * need to be carried over to hfa384x_cbcmd() since the handling
1175 * is virtually identical.
1178 * hw device structure
1179 * cmd cmd structure. Includes all arguments and result
1180 * data points. All in host order. in host order
1185 * -ERESTARTSYS Awakened on signal
1186 * >0 command indicated error, Status and Resp0-2 are
1194 *----------------------------------------------------------------
1197 hfa384x_docmd(struct hfa384x *hw,
1198 struct hfa384x_metacmd *cmd)
1201 struct hfa384x_usbctlx *ctlx;
1203 ctlx = usbctlx_alloc();
1209 /* Initialize the command */
1210 ctlx->outbuf.cmdreq.type = cpu_to_le16(HFA384x_USB_CMDREQ);
1211 ctlx->outbuf.cmdreq.cmd = cpu_to_le16(cmd->cmd);
1212 ctlx->outbuf.cmdreq.parm0 = cpu_to_le16(cmd->parm0);
1213 ctlx->outbuf.cmdreq.parm1 = cpu_to_le16(cmd->parm1);
1214 ctlx->outbuf.cmdreq.parm2 = cpu_to_le16(cmd->parm2);
1216 ctlx->outbufsize = sizeof(ctlx->outbuf.cmdreq);
1218 pr_debug("cmdreq: cmd=0x%04x parm0=0x%04x parm1=0x%04x parm2=0x%04x\n",
1219 cmd->cmd, cmd->parm0, cmd->parm1, cmd->parm2);
1221 ctlx->reapable = DOWAIT;
1223 ctlx->usercb = NULL;
1224 ctlx->usercb_data = NULL;
1226 result = hfa384x_usbctlx_submit(hw, ctlx);
1230 struct usbctlx_cmd_completor cmd_completor;
1231 struct usbctlx_completor *completor;
1233 completor = init_cmd_completor(&cmd_completor,
1234 &ctlx->inbuf.cmdresp,
1237 result = hfa384x_usbctlx_complete_sync(hw, ctlx, completor);
1244 /*----------------------------------------------------------------
1247 * Constructs a read rid CTLX and issues it.
1249 * NOTE: Any changes to the 'post-submit' code in this function
1250 * need to be carried over to hfa384x_cbrrid() since the handling
1251 * is virtually identical.
1254 * hw device structure
1255 * mode DOWAIT or DOASYNC
1256 * rid Read RID number (host order)
1257 * riddata Caller supplied buffer that MAC formatted RID.data
1258 * record will be written to for DOWAIT calls. Should
1259 * be NULL for DOASYNC calls.
1260 * riddatalen Buffer length for DOWAIT calls. Zero for DOASYNC calls.
1261 * cmdcb command callback for async calls, NULL for DOWAIT calls
1262 * usercb user callback for async calls, NULL for DOWAIT calls
1263 * usercb_data user supplied data pointer for async calls, NULL
1269 * -ERESTARTSYS Awakened on signal
1270 * -ENODATA riddatalen != macdatalen
1271 * >0 command indicated error, Status and Resp0-2 are
1277 * interrupt (DOASYNC)
1278 * process (DOWAIT or DOASYNC)
1279 *----------------------------------------------------------------
1282 hfa384x_dorrid(struct hfa384x *hw,
1286 unsigned int riddatalen,
1287 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1290 struct hfa384x_usbctlx *ctlx;
1292 ctlx = usbctlx_alloc();
1298 /* Initialize the command */
1299 ctlx->outbuf.rridreq.type = cpu_to_le16(HFA384x_USB_RRIDREQ);
1300 ctlx->outbuf.rridreq.frmlen =
1301 cpu_to_le16(sizeof(ctlx->outbuf.rridreq.rid));
1302 ctlx->outbuf.rridreq.rid = cpu_to_le16(rid);
1304 ctlx->outbufsize = sizeof(ctlx->outbuf.rridreq);
1306 ctlx->reapable = mode;
1307 ctlx->cmdcb = cmdcb;
1308 ctlx->usercb = usercb;
1309 ctlx->usercb_data = usercb_data;
1311 /* Submit the CTLX */
1312 result = hfa384x_usbctlx_submit(hw, ctlx);
1315 } else if (mode == DOWAIT) {
1316 struct usbctlx_rrid_completor completor;
1319 hfa384x_usbctlx_complete_sync(hw, ctlx,
1322 &ctlx->inbuf.rridresp,
1323 riddata, riddatalen));
1330 /*----------------------------------------------------------------
1333 * Constructs a write rid CTLX and issues it.
1335 * NOTE: Any changes to the 'post-submit' code in this function
1336 * need to be carried over to hfa384x_cbwrid() since the handling
1337 * is virtually identical.
1340 * hw device structure
1341 * enum cmd_mode DOWAIT or DOASYNC
1343 * riddata Data portion of RID formatted for MAC
1344 * riddatalen Length of the data portion in bytes
1345 * cmdcb command callback for async calls, NULL for DOWAIT calls
1346 * usercb user callback for async calls, NULL for DOWAIT calls
1347 * usercb_data user supplied data pointer for async calls
1351 * -ETIMEDOUT timed out waiting for register ready or
1352 * command completion
1353 * >0 command indicated error, Status and Resp0-2 are
1359 * interrupt (DOASYNC)
1360 * process (DOWAIT or DOASYNC)
1361 *----------------------------------------------------------------
1364 hfa384x_dowrid(struct hfa384x *hw,
1368 unsigned int riddatalen,
1369 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1372 struct hfa384x_usbctlx *ctlx;
1374 ctlx = usbctlx_alloc();
1380 /* Initialize the command */
1381 ctlx->outbuf.wridreq.type = cpu_to_le16(HFA384x_USB_WRIDREQ);
1382 ctlx->outbuf.wridreq.frmlen = cpu_to_le16((sizeof
1383 (ctlx->outbuf.wridreq.rid) +
1384 riddatalen + 1) / 2);
1385 ctlx->outbuf.wridreq.rid = cpu_to_le16(rid);
1386 memcpy(ctlx->outbuf.wridreq.data, riddata, riddatalen);
1388 ctlx->outbufsize = sizeof(ctlx->outbuf.wridreq.type) +
1389 sizeof(ctlx->outbuf.wridreq.frmlen) +
1390 sizeof(ctlx->outbuf.wridreq.rid) + riddatalen;
1392 ctlx->reapable = mode;
1393 ctlx->cmdcb = cmdcb;
1394 ctlx->usercb = usercb;
1395 ctlx->usercb_data = usercb_data;
1397 /* Submit the CTLX */
1398 result = hfa384x_usbctlx_submit(hw, ctlx);
1401 } else if (mode == DOWAIT) {
1402 struct usbctlx_cmd_completor completor;
1403 struct hfa384x_cmdresult wridresult;
1405 result = hfa384x_usbctlx_complete_sync(hw,
1409 &ctlx->inbuf.wridresp,
1417 /*----------------------------------------------------------------
1420 * Constructs a readmem CTLX and issues it.
1422 * NOTE: Any changes to the 'post-submit' code in this function
1423 * need to be carried over to hfa384x_cbrmem() since the handling
1424 * is virtually identical.
1427 * hw device structure
1428 * page MAC address space page (CMD format)
1429 * offset MAC address space offset
1430 * data Ptr to data buffer to receive read
1431 * len Length of the data to read (max == 2048)
1435 * -ETIMEDOUT timed out waiting for register ready or
1436 * command completion
1437 * >0 command indicated error, Status and Resp0-2 are
1444 *----------------------------------------------------------------
1447 hfa384x_dormem(struct hfa384x *hw,
1454 struct hfa384x_usbctlx *ctlx;
1456 ctlx = usbctlx_alloc();
1462 /* Initialize the command */
1463 ctlx->outbuf.rmemreq.type = cpu_to_le16(HFA384x_USB_RMEMREQ);
1464 ctlx->outbuf.rmemreq.frmlen =
1465 cpu_to_le16(sizeof(ctlx->outbuf.rmemreq.offset) +
1466 sizeof(ctlx->outbuf.rmemreq.page) + len);
1467 ctlx->outbuf.rmemreq.offset = cpu_to_le16(offset);
1468 ctlx->outbuf.rmemreq.page = cpu_to_le16(page);
1470 ctlx->outbufsize = sizeof(ctlx->outbuf.rmemreq);
1472 pr_debug("type=0x%04x frmlen=%d offset=0x%04x page=0x%04x\n",
1473 ctlx->outbuf.rmemreq.type,
1474 ctlx->outbuf.rmemreq.frmlen,
1475 ctlx->outbuf.rmemreq.offset, ctlx->outbuf.rmemreq.page);
1477 pr_debug("pktsize=%zd\n", ROUNDUP64(sizeof(ctlx->outbuf.rmemreq)));
1479 ctlx->reapable = DOWAIT;
1481 ctlx->usercb = NULL;
1482 ctlx->usercb_data = NULL;
1484 result = hfa384x_usbctlx_submit(hw, ctlx);
1488 struct usbctlx_rmem_completor completor;
1491 hfa384x_usbctlx_complete_sync(hw, ctlx,
1494 &ctlx->inbuf.rmemresp, data,
1502 /*----------------------------------------------------------------
1505 * Constructs a writemem CTLX and issues it.
1507 * NOTE: Any changes to the 'post-submit' code in this function
1508 * need to be carried over to hfa384x_cbwmem() since the handling
1509 * is virtually identical.
1512 * hw device structure
1513 * page MAC address space page (CMD format)
1514 * offset MAC address space offset
1515 * data Ptr to data buffer containing write data
1516 * len Length of the data to read (max == 2048)
1520 * -ETIMEDOUT timed out waiting for register ready or
1521 * command completion
1522 * >0 command indicated error, Status and Resp0-2 are
1528 * interrupt (DOWAIT)
1530 *----------------------------------------------------------------
1533 hfa384x_dowmem(struct hfa384x *hw,
1540 struct hfa384x_usbctlx *ctlx;
1542 pr_debug("page=0x%04x offset=0x%04x len=%d\n", page, offset, len);
1544 ctlx = usbctlx_alloc();
1550 /* Initialize the command */
1551 ctlx->outbuf.wmemreq.type = cpu_to_le16(HFA384x_USB_WMEMREQ);
1552 ctlx->outbuf.wmemreq.frmlen =
1553 cpu_to_le16(sizeof(ctlx->outbuf.wmemreq.offset) +
1554 sizeof(ctlx->outbuf.wmemreq.page) + len);
1555 ctlx->outbuf.wmemreq.offset = cpu_to_le16(offset);
1556 ctlx->outbuf.wmemreq.page = cpu_to_le16(page);
1557 memcpy(ctlx->outbuf.wmemreq.data, data, len);
1559 ctlx->outbufsize = sizeof(ctlx->outbuf.wmemreq.type) +
1560 sizeof(ctlx->outbuf.wmemreq.frmlen) +
1561 sizeof(ctlx->outbuf.wmemreq.offset) +
1562 sizeof(ctlx->outbuf.wmemreq.page) + len;
1564 ctlx->reapable = DOWAIT;
1566 ctlx->usercb = NULL;
1567 ctlx->usercb_data = NULL;
1569 result = hfa384x_usbctlx_submit(hw, ctlx);
1573 struct usbctlx_cmd_completor completor;
1574 struct hfa384x_cmdresult wmemresult;
1576 result = hfa384x_usbctlx_complete_sync(hw,
1580 &ctlx->inbuf.wmemresp,
1588 /*----------------------------------------------------------------
1589 * hfa384x_drvr_disable
1591 * Issues the disable command to stop communications on one of
1592 * the MACs 'ports'. Only macport 0 is valid for stations.
1593 * APs may also disable macports 1-6. Only ports that have been
1594 * previously enabled may be disabled.
1597 * hw device structure
1598 * macport MAC port number (host order)
1602 * >0 f/w reported failure - f/w status code
1603 * <0 driver reported error (timeout|bad arg)
1609 *----------------------------------------------------------------
1611 int hfa384x_drvr_disable(struct hfa384x *hw, u16 macport)
1615 if ((!hw->isap && macport != 0) ||
1616 (hw->isap && !(macport <= HFA384x_PORTID_MAX)) ||
1617 !(hw->port_enabled[macport])) {
1620 result = hfa384x_cmd_disable(hw, macport);
1622 hw->port_enabled[macport] = 0;
1627 /*----------------------------------------------------------------
1628 * hfa384x_drvr_enable
1630 * Issues the enable command to enable communications on one of
1631 * the MACs 'ports'. Only macport 0 is valid for stations.
1632 * APs may also enable macports 1-6. Only ports that are currently
1633 * disabled may be enabled.
1636 * hw device structure
1637 * macport MAC port number
1641 * >0 f/w reported failure - f/w status code
1642 * <0 driver reported error (timeout|bad arg)
1648 *----------------------------------------------------------------
1650 int hfa384x_drvr_enable(struct hfa384x *hw, u16 macport)
1654 if ((!hw->isap && macport != 0) ||
1655 (hw->isap && !(macport <= HFA384x_PORTID_MAX)) ||
1656 (hw->port_enabled[macport])) {
1659 result = hfa384x_cmd_enable(hw, macport);
1661 hw->port_enabled[macport] = 1;
1666 /*----------------------------------------------------------------
1667 * hfa384x_drvr_flashdl_enable
1669 * Begins the flash download state. Checks to see that we're not
1670 * already in a download state and that a port isn't enabled.
1671 * Sets the download state and retrieves the flash download
1672 * buffer location, buffer size, and timeout length.
1675 * hw device structure
1679 * >0 f/w reported error - f/w status code
1680 * <0 driver reported error
1686 *----------------------------------------------------------------
1688 int hfa384x_drvr_flashdl_enable(struct hfa384x *hw)
1693 /* Check that a port isn't active */
1694 for (i = 0; i < HFA384x_PORTID_MAX; i++) {
1695 if (hw->port_enabled[i]) {
1696 pr_debug("called when port enabled.\n");
1701 /* Check that we're not already in a download state */
1702 if (hw->dlstate != HFA384x_DLSTATE_DISABLED)
1705 /* Retrieve the buffer loc&size and timeout */
1706 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_DOWNLOADBUFFER,
1707 &hw->bufinfo, sizeof(hw->bufinfo));
1711 le16_to_cpus(&hw->bufinfo.page);
1712 le16_to_cpus(&hw->bufinfo.offset);
1713 le16_to_cpus(&hw->bufinfo.len);
1714 result = hfa384x_drvr_getconfig16(hw, HFA384x_RID_MAXLOADTIME,
1719 le16_to_cpus(&hw->dltimeout);
1721 pr_debug("flashdl_enable\n");
1723 hw->dlstate = HFA384x_DLSTATE_FLASHENABLED;
1728 /*----------------------------------------------------------------
1729 * hfa384x_drvr_flashdl_disable
1731 * Ends the flash download state. Note that this will cause the MAC
1732 * firmware to restart.
1735 * hw device structure
1739 * >0 f/w reported error - f/w status code
1740 * <0 driver reported error
1746 *----------------------------------------------------------------
1748 int hfa384x_drvr_flashdl_disable(struct hfa384x *hw)
1750 /* Check that we're already in the download state */
1751 if (hw->dlstate != HFA384x_DLSTATE_FLASHENABLED)
1754 pr_debug("flashdl_enable\n");
1756 /* There isn't much we can do at this point, so I don't */
1757 /* bother w/ the return value */
1758 hfa384x_cmd_download(hw, HFA384x_PROGMODE_DISABLE, 0, 0, 0);
1759 hw->dlstate = HFA384x_DLSTATE_DISABLED;
1764 /*----------------------------------------------------------------
1765 * hfa384x_drvr_flashdl_write
1767 * Performs a FLASH download of a chunk of data. First checks to see
1768 * that we're in the FLASH download state, then sets the download
1769 * mode, uses the aux functions to 1) copy the data to the flash
1770 * buffer, 2) sets the download 'write flash' mode, 3) readback and
1771 * compare. Lather rinse, repeat as many times an necessary to get
1772 * all the given data into flash.
1773 * When all data has been written using this function (possibly
1774 * repeatedly), call drvr_flashdl_disable() to end the download state
1775 * and restart the MAC.
1778 * hw device structure
1779 * daddr Card address to write to. (host order)
1780 * buf Ptr to data to write.
1781 * len Length of data (host order).
1785 * >0 f/w reported error - f/w status code
1786 * <0 driver reported error
1792 *----------------------------------------------------------------
1794 int hfa384x_drvr_flashdl_write(struct hfa384x *hw, u32 daddr,
1812 pr_debug("daddr=0x%08x len=%d\n", daddr, len);
1814 /* Check that we're in the flash download state */
1815 if (hw->dlstate != HFA384x_DLSTATE_FLASHENABLED)
1818 netdev_info(hw->wlandev->netdev,
1819 "Download %d bytes to flash @0x%06x\n", len, daddr);
1821 /* Convert to flat address for arithmetic */
1822 /* NOTE: dlbuffer RID stores the address in AUX format */
1824 HFA384x_ADDR_AUX_MKFLAT(hw->bufinfo.page, hw->bufinfo.offset);
1825 pr_debug("dlbuf.page=0x%04x dlbuf.offset=0x%04x dlbufaddr=0x%08x\n",
1826 hw->bufinfo.page, hw->bufinfo.offset, dlbufaddr);
1827 /* Calculations to determine how many fills of the dlbuffer to do
1828 * and how many USB wmemreq's to do for each fill. At this point
1829 * in time, the dlbuffer size and the wmemreq size are the same.
1830 * Therefore, nwrites should always be 1. The extra complexity
1831 * here is a hedge against future changes.
1834 /* Figure out how many times to do the flash programming */
1835 nburns = len / hw->bufinfo.len;
1836 nburns += (len % hw->bufinfo.len) ? 1 : 0;
1838 /* For each flash program cycle, how many USB wmemreq's are needed? */
1839 nwrites = hw->bufinfo.len / HFA384x_USB_RWMEM_MAXLEN;
1840 nwrites += (hw->bufinfo.len % HFA384x_USB_RWMEM_MAXLEN) ? 1 : 0;
1843 for (i = 0; i < nburns; i++) {
1844 /* Get the dest address and len */
1845 burnlen = (len - (hw->bufinfo.len * i)) > hw->bufinfo.len ?
1846 hw->bufinfo.len : (len - (hw->bufinfo.len * i));
1847 burndaddr = daddr + (hw->bufinfo.len * i);
1848 burnlo = HFA384x_ADDR_CMD_MKOFF(burndaddr);
1849 burnhi = HFA384x_ADDR_CMD_MKPAGE(burndaddr);
1851 netdev_info(hw->wlandev->netdev, "Writing %d bytes to flash @0x%06x\n",
1852 burnlen, burndaddr);
1854 /* Set the download mode */
1855 result = hfa384x_cmd_download(hw, HFA384x_PROGMODE_NV,
1856 burnlo, burnhi, burnlen);
1858 netdev_err(hw->wlandev->netdev,
1859 "download(NV,lo=%x,hi=%x,len=%x) cmd failed, result=%d. Aborting d/l\n",
1860 burnlo, burnhi, burnlen, result);
1864 /* copy the data to the flash download buffer */
1865 for (j = 0; j < nwrites; j++) {
1867 (i * hw->bufinfo.len) +
1868 (j * HFA384x_USB_RWMEM_MAXLEN);
1870 writepage = HFA384x_ADDR_CMD_MKPAGE(dlbufaddr +
1871 (j * HFA384x_USB_RWMEM_MAXLEN));
1872 writeoffset = HFA384x_ADDR_CMD_MKOFF(dlbufaddr +
1873 (j * HFA384x_USB_RWMEM_MAXLEN));
1875 writelen = burnlen - (j * HFA384x_USB_RWMEM_MAXLEN);
1876 writelen = writelen > HFA384x_USB_RWMEM_MAXLEN ?
1877 HFA384x_USB_RWMEM_MAXLEN : writelen;
1879 result = hfa384x_dowmem(hw,
1882 writebuf, writelen);
1885 /* set the download 'write flash' mode */
1886 result = hfa384x_cmd_download(hw,
1887 HFA384x_PROGMODE_NVWRITE,
1890 netdev_err(hw->wlandev->netdev,
1891 "download(NVWRITE,lo=%x,hi=%x,len=%x) cmd failed, result=%d. Aborting d/l\n",
1892 burnlo, burnhi, burnlen, result);
1896 /* TODO: We really should do a readback and compare. */
1901 /* Leave the firmware in the 'post-prog' mode. flashdl_disable will */
1902 /* actually disable programming mode. Remember, that will cause the */
1903 /* the firmware to effectively reset itself. */
1908 /*----------------------------------------------------------------
1909 * hfa384x_drvr_getconfig
1911 * Performs the sequence necessary to read a config/info item.
1914 * hw device structure
1915 * rid config/info record id (host order)
1916 * buf host side record buffer. Upon return it will
1917 * contain the body portion of the record (minus the
1919 * len buffer length (in bytes, should match record length)
1923 * >0 f/w reported error - f/w status code
1924 * <0 driver reported error
1925 * -ENODATA length mismatch between argument and retrieved
1932 *----------------------------------------------------------------
1934 int hfa384x_drvr_getconfig(struct hfa384x *hw, u16 rid, void *buf, u16 len)
1936 return hfa384x_dorrid(hw, DOWAIT, rid, buf, len, NULL, NULL, NULL);
1939 /*----------------------------------------------------------------
1940 * hfa384x_drvr_setconfig_async
1942 * Performs the sequence necessary to write a config/info item.
1945 * hw device structure
1946 * rid config/info record id (in host order)
1947 * buf host side record buffer
1948 * len buffer length (in bytes)
1949 * usercb completion callback
1950 * usercb_data completion callback argument
1954 * >0 f/w reported error - f/w status code
1955 * <0 driver reported error
1961 *----------------------------------------------------------------
1964 hfa384x_drvr_setconfig_async(struct hfa384x *hw,
1967 u16 len, ctlx_usercb_t usercb, void *usercb_data)
1969 return hfa384x_dowrid(hw, DOASYNC, rid, buf, len, hfa384x_cb_status,
1970 usercb, usercb_data);
1973 /*----------------------------------------------------------------
1974 * hfa384x_drvr_ramdl_disable
1976 * Ends the ram download state.
1979 * hw device structure
1983 * >0 f/w reported error - f/w status code
1984 * <0 driver reported error
1990 *----------------------------------------------------------------
1992 int hfa384x_drvr_ramdl_disable(struct hfa384x *hw)
1994 /* Check that we're already in the download state */
1995 if (hw->dlstate != HFA384x_DLSTATE_RAMENABLED)
1998 pr_debug("ramdl_disable()\n");
2000 /* There isn't much we can do at this point, so I don't */
2001 /* bother w/ the return value */
2002 hfa384x_cmd_download(hw, HFA384x_PROGMODE_DISABLE, 0, 0, 0);
2003 hw->dlstate = HFA384x_DLSTATE_DISABLED;
2008 /*----------------------------------------------------------------
2009 * hfa384x_drvr_ramdl_enable
2011 * Begins the ram download state. Checks to see that we're not
2012 * already in a download state and that a port isn't enabled.
2013 * Sets the download state and calls cmd_download with the
2014 * ENABLE_VOLATILE subcommand and the exeaddr argument.
2017 * hw device structure
2018 * exeaddr the card execution address that will be
2019 * jumped to when ramdl_disable() is called
2024 * >0 f/w reported error - f/w status code
2025 * <0 driver reported error
2031 *----------------------------------------------------------------
2033 int hfa384x_drvr_ramdl_enable(struct hfa384x *hw, u32 exeaddr)
2040 /* Check that a port isn't active */
2041 for (i = 0; i < HFA384x_PORTID_MAX; i++) {
2042 if (hw->port_enabled[i]) {
2043 netdev_err(hw->wlandev->netdev,
2044 "Can't download with a macport enabled.\n");
2049 /* Check that we're not already in a download state */
2050 if (hw->dlstate != HFA384x_DLSTATE_DISABLED) {
2051 netdev_err(hw->wlandev->netdev,
2052 "Download state not disabled.\n");
2056 pr_debug("ramdl_enable, exeaddr=0x%08x\n", exeaddr);
2058 /* Call the download(1,addr) function */
2059 lowaddr = HFA384x_ADDR_CMD_MKOFF(exeaddr);
2060 hiaddr = HFA384x_ADDR_CMD_MKPAGE(exeaddr);
2062 result = hfa384x_cmd_download(hw, HFA384x_PROGMODE_RAM,
2063 lowaddr, hiaddr, 0);
2066 /* Set the download state */
2067 hw->dlstate = HFA384x_DLSTATE_RAMENABLED;
2069 pr_debug("cmd_download(0x%04x, 0x%04x) failed, result=%d.\n",
2070 lowaddr, hiaddr, result);
2076 /*----------------------------------------------------------------
2077 * hfa384x_drvr_ramdl_write
2079 * Performs a RAM download of a chunk of data. First checks to see
2080 * that we're in the RAM download state, then uses the [read|write]mem USB
2081 * commands to 1) copy the data, 2) readback and compare. The download
2082 * state is unaffected. When all data has been written using
2083 * this function, call drvr_ramdl_disable() to end the download state
2084 * and restart the MAC.
2087 * hw device structure
2088 * daddr Card address to write to. (host order)
2089 * buf Ptr to data to write.
2090 * len Length of data (host order).
2094 * >0 f/w reported error - f/w status code
2095 * <0 driver reported error
2101 *----------------------------------------------------------------
2103 int hfa384x_drvr_ramdl_write(struct hfa384x *hw, u32 daddr, void *buf, u32 len)
2114 /* Check that we're in the ram download state */
2115 if (hw->dlstate != HFA384x_DLSTATE_RAMENABLED)
2118 netdev_info(hw->wlandev->netdev, "Writing %d bytes to ram @0x%06x\n",
2121 /* How many dowmem calls? */
2122 nwrites = len / HFA384x_USB_RWMEM_MAXLEN;
2123 nwrites += len % HFA384x_USB_RWMEM_MAXLEN ? 1 : 0;
2125 /* Do blocking wmem's */
2126 for (i = 0; i < nwrites; i++) {
2127 /* make address args */
2128 curraddr = daddr + (i * HFA384x_USB_RWMEM_MAXLEN);
2129 currpage = HFA384x_ADDR_CMD_MKPAGE(curraddr);
2130 curroffset = HFA384x_ADDR_CMD_MKOFF(curraddr);
2131 currlen = len - (i * HFA384x_USB_RWMEM_MAXLEN);
2132 if (currlen > HFA384x_USB_RWMEM_MAXLEN)
2133 currlen = HFA384x_USB_RWMEM_MAXLEN;
2135 /* Do blocking ctlx */
2136 result = hfa384x_dowmem(hw,
2139 data + (i * HFA384x_USB_RWMEM_MAXLEN),
2145 /* TODO: We really should have a readback. */
2151 /*----------------------------------------------------------------
2152 * hfa384x_drvr_readpda
2154 * Performs the sequence to read the PDA space. Note there is no
2155 * drvr_writepda() function. Writing a PDA is
2156 * generally implemented by a calling component via calls to
2157 * cmd_download and writing to the flash download buffer via the
2161 * hw device structure
2162 * buf buffer to store PDA in
2167 * >0 f/w reported error - f/w status code
2168 * <0 driver reported error
2169 * -ETIMEDOUT timeout waiting for the cmd regs to become
2170 * available, or waiting for the control reg
2171 * to indicate the Aux port is enabled.
2172 * -ENODATA the buffer does NOT contain a valid PDA.
2173 * Either the card PDA is bad, or the auxdata
2174 * reads are giving us garbage.
2180 * process or non-card interrupt.
2181 *----------------------------------------------------------------
2183 int hfa384x_drvr_readpda(struct hfa384x *hw, void *buf, unsigned int len)
2189 int currpdr = 0; /* word offset of the current pdr */
2191 u16 pdrlen; /* pdr length in bytes, host order */
2192 u16 pdrcode; /* pdr code, host order */
2200 HFA3842_PDA_BASE, 0}, {
2201 HFA3841_PDA_BASE, 0}, {
2202 HFA3841_PDA_BOGUS_BASE, 0}
2205 /* Read the pda from each known address. */
2206 for (i = 0; i < ARRAY_SIZE(pdaloc); i++) {
2208 currpage = HFA384x_ADDR_CMD_MKPAGE(pdaloc[i].cardaddr);
2209 curroffset = HFA384x_ADDR_CMD_MKOFF(pdaloc[i].cardaddr);
2211 /* units of bytes */
2212 result = hfa384x_dormem(hw, currpage, curroffset, buf,
2216 netdev_warn(hw->wlandev->netdev,
2217 "Read from index %zd failed, continuing\n",
2222 /* Test for garbage */
2223 pdaok = 1; /* initially assume good */
2225 while (pdaok && morepdrs) {
2226 pdrlen = le16_to_cpu(pda[currpdr]) * 2;
2227 pdrcode = le16_to_cpu(pda[currpdr + 1]);
2228 /* Test the record length */
2229 if (pdrlen > HFA384x_PDR_LEN_MAX || pdrlen == 0) {
2230 netdev_err(hw->wlandev->netdev,
2231 "pdrlen invalid=%d\n", pdrlen);
2236 if (!hfa384x_isgood_pdrcode(pdrcode)) {
2237 netdev_err(hw->wlandev->netdev, "pdrcode invalid=%d\n",
2242 /* Test for completion */
2243 if (pdrcode == HFA384x_PDR_END_OF_PDA)
2246 /* Move to the next pdr (if necessary) */
2248 /* note the access to pda[], need words here */
2249 currpdr += le16_to_cpu(pda[currpdr]) + 1;
2253 netdev_info(hw->wlandev->netdev,
2254 "PDA Read from 0x%08x in %s space.\n",
2256 pdaloc[i].auxctl == 0 ? "EXTDS" :
2257 pdaloc[i].auxctl == 1 ? "NV" :
2258 pdaloc[i].auxctl == 2 ? "PHY" :
2259 pdaloc[i].auxctl == 3 ? "ICSRAM" :
2264 result = pdaok ? 0 : -ENODATA;
2267 pr_debug("Failure: pda is not okay\n");
2272 /*----------------------------------------------------------------
2273 * hfa384x_drvr_setconfig
2275 * Performs the sequence necessary to write a config/info item.
2278 * hw device structure
2279 * rid config/info record id (in host order)
2280 * buf host side record buffer
2281 * len buffer length (in bytes)
2285 * >0 f/w reported error - f/w status code
2286 * <0 driver reported error
2292 *----------------------------------------------------------------
2294 int hfa384x_drvr_setconfig(struct hfa384x *hw, u16 rid, void *buf, u16 len)
2296 return hfa384x_dowrid(hw, DOWAIT, rid, buf, len, NULL, NULL, NULL);
2299 /*----------------------------------------------------------------
2300 * hfa384x_drvr_start
2302 * Issues the MAC initialize command, sets up some data structures,
2303 * and enables the interrupts. After this function completes, the
2304 * low-level stuff should be ready for any/all commands.
2307 * hw device structure
2310 * >0 f/w reported error - f/w status code
2311 * <0 driver reported error
2317 *----------------------------------------------------------------
2319 int hfa384x_drvr_start(struct hfa384x *hw)
2321 int result, result1, result2;
2326 /* Clear endpoint stalls - but only do this if the endpoint
2327 * is showing a stall status. Some prism2 cards seem to behave
2328 * badly if a clear_halt is called when the endpoint is already
2332 usb_get_std_status(hw->usb, USB_RECIP_ENDPOINT, hw->endp_in,
2335 netdev_err(hw->wlandev->netdev, "Cannot get bulk in endpoint status.\n");
2338 if ((status == 1) && usb_clear_halt(hw->usb, hw->endp_in))
2339 netdev_err(hw->wlandev->netdev, "Failed to reset bulk in endpoint.\n");
2342 usb_get_std_status(hw->usb, USB_RECIP_ENDPOINT, hw->endp_out,
2345 netdev_err(hw->wlandev->netdev, "Cannot get bulk out endpoint status.\n");
2348 if ((status == 1) && usb_clear_halt(hw->usb, hw->endp_out))
2349 netdev_err(hw->wlandev->netdev, "Failed to reset bulk out endpoint.\n");
2351 /* Synchronous unlink, in case we're trying to restart the driver */
2352 usb_kill_urb(&hw->rx_urb);
2354 /* Post the IN urb */
2355 result = submit_rx_urb(hw, GFP_KERNEL);
2357 netdev_err(hw->wlandev->netdev,
2358 "Fatal, failed to submit RX URB, result=%d\n",
2363 /* Call initialize twice, with a 1 second sleep in between.
2364 * This is a nasty work-around since many prism2 cards seem to
2365 * need time to settle after an init from cold. The second
2366 * call to initialize in theory is not necessary - but we call
2367 * it anyway as a double insurance policy:
2368 * 1) If the first init should fail, the second may well succeed
2369 * and the card can still be used
2370 * 2) It helps ensures all is well with the card after the first
2371 * init and settle time.
2373 result1 = hfa384x_cmd_initialize(hw);
2375 result = hfa384x_cmd_initialize(hw);
2379 netdev_err(hw->wlandev->netdev,
2380 "cmd_initialize() failed on two attempts, results %d and %d\n",
2382 usb_kill_urb(&hw->rx_urb);
2385 pr_debug("First cmd_initialize() failed (result %d),\n",
2387 pr_debug("but second attempt succeeded. All should be ok\n");
2389 } else if (result2 != 0) {
2390 netdev_warn(hw->wlandev->netdev, "First cmd_initialize() succeeded, but second attempt failed (result=%d)\n",
2392 netdev_warn(hw->wlandev->netdev,
2393 "Most likely the card will be functional\n");
2397 hw->state = HFA384x_STATE_RUNNING;
2403 /*----------------------------------------------------------------
2406 * Shuts down the MAC to the point where it is safe to unload the
2407 * driver. Any subsystem that may be holding a data or function
2408 * ptr into the driver must be cleared/deinitialized.
2411 * hw device structure
2414 * >0 f/w reported error - f/w status code
2415 * <0 driver reported error
2421 *----------------------------------------------------------------
2423 int hfa384x_drvr_stop(struct hfa384x *hw)
2429 /* There's no need for spinlocks here. The USB "disconnect"
2430 * function sets this "removed" flag and then calls us.
2432 if (!hw->wlandev->hwremoved) {
2433 /* Call initialize to leave the MAC in its 'reset' state */
2434 hfa384x_cmd_initialize(hw);
2436 /* Cancel the rxurb */
2437 usb_kill_urb(&hw->rx_urb);
2440 hw->link_status = HFA384x_LINK_NOTCONNECTED;
2441 hw->state = HFA384x_STATE_INIT;
2443 del_timer_sync(&hw->commsqual_timer);
2445 /* Clear all the port status */
2446 for (i = 0; i < HFA384x_NUMPORTS_MAX; i++)
2447 hw->port_enabled[i] = 0;
2452 /*----------------------------------------------------------------
2453 * hfa384x_drvr_txframe
2455 * Takes a frame from prism2sta and queues it for transmission.
2458 * hw device structure
2459 * skb packet buffer struct. Contains an 802.11
2461 * p80211_hdr points to the 802.11 header for the packet.
2463 * 0 Success and more buffs available
2464 * 1 Success but no more buffs
2465 * 2 Allocation failure
2466 * 4 Buffer full or queue busy
2472 *----------------------------------------------------------------
2474 int hfa384x_drvr_txframe(struct hfa384x *hw, struct sk_buff *skb,
2475 struct p80211_hdr *p80211_hdr,
2476 struct p80211_metawep *p80211_wep)
2478 int usbpktlen = sizeof(struct hfa384x_tx_frame);
2483 if (hw->tx_urb.status == -EINPROGRESS) {
2484 netdev_warn(hw->wlandev->netdev, "TX URB already in use\n");
2489 /* Build Tx frame structure */
2490 /* Set up the control field */
2491 memset(&hw->txbuff.txfrm.desc, 0, sizeof(hw->txbuff.txfrm.desc));
2493 /* Setup the usb type field */
2494 hw->txbuff.type = cpu_to_le16(HFA384x_USB_TXFRM);
2496 /* Set up the sw_support field to identify this frame */
2497 hw->txbuff.txfrm.desc.sw_support = 0x0123;
2499 /* Tx complete and Tx exception disable per dleach. Might be causing
2502 /* #define DOEXC SLP -- doboth breaks horribly under load, doexc less so. */
2504 hw->txbuff.txfrm.desc.tx_control =
2505 HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
2506 HFA384x_TX_TXEX_SET(1) | HFA384x_TX_TXOK_SET(1);
2507 #elif defined(DOEXC)
2508 hw->txbuff.txfrm.desc.tx_control =
2509 HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
2510 HFA384x_TX_TXEX_SET(1) | HFA384x_TX_TXOK_SET(0);
2512 hw->txbuff.txfrm.desc.tx_control =
2513 HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
2514 HFA384x_TX_TXEX_SET(0) | HFA384x_TX_TXOK_SET(0);
2516 cpu_to_le16s(&hw->txbuff.txfrm.desc.tx_control);
2518 /* copy the header over to the txdesc */
2519 hw->txbuff.txfrm.desc.hdr = *p80211_hdr;
2521 /* if we're using host WEP, increase size by IV+ICV */
2522 if (p80211_wep->data) {
2523 hw->txbuff.txfrm.desc.data_len = cpu_to_le16(skb->len + 8);
2526 hw->txbuff.txfrm.desc.data_len = cpu_to_le16(skb->len);
2529 usbpktlen += skb->len;
2531 /* copy over the WEP IV if we are using host WEP */
2532 ptr = hw->txbuff.txfrm.data;
2533 if (p80211_wep->data) {
2534 memcpy(ptr, p80211_wep->iv, sizeof(p80211_wep->iv));
2535 ptr += sizeof(p80211_wep->iv);
2536 memcpy(ptr, p80211_wep->data, skb->len);
2538 memcpy(ptr, skb->data, skb->len);
2540 /* copy over the packet data */
2543 /* copy over the WEP ICV if we are using host WEP */
2544 if (p80211_wep->data)
2545 memcpy(ptr, p80211_wep->icv, sizeof(p80211_wep->icv));
2547 /* Send the USB packet */
2548 usb_fill_bulk_urb(&hw->tx_urb, hw->usb,
2550 &hw->txbuff, ROUNDUP64(usbpktlen),
2551 hfa384x_usbout_callback, hw->wlandev);
2552 hw->tx_urb.transfer_flags |= USB_QUEUE_BULK;
2555 ret = submit_tx_urb(hw, &hw->tx_urb, GFP_ATOMIC);
2557 netdev_err(hw->wlandev->netdev,
2558 "submit_tx_urb() failed, error=%d\n", ret);
2566 void hfa384x_tx_timeout(struct wlandevice *wlandev)
2568 struct hfa384x *hw = wlandev->priv;
2569 unsigned long flags;
2571 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2573 if (!hw->wlandev->hwremoved) {
2576 sched = !test_and_set_bit(WORK_TX_HALT, &hw->usb_flags);
2577 sched |= !test_and_set_bit(WORK_RX_HALT, &hw->usb_flags);
2579 schedule_work(&hw->usb_work);
2582 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2585 /*----------------------------------------------------------------
2586 * hfa384x_usbctlx_reaper_task
2588 * Tasklet to delete dead CTLX objects
2591 * data ptr to a struct hfa384x
2597 *----------------------------------------------------------------
2599 static void hfa384x_usbctlx_reaper_task(struct tasklet_struct *t)
2601 struct hfa384x *hw = from_tasklet(hw, t, reaper_bh);
2602 struct hfa384x_usbctlx *ctlx, *temp;
2603 unsigned long flags;
2605 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2607 /* This list is guaranteed to be empty if someone
2608 * has unplugged the adapter.
2610 list_for_each_entry_safe(ctlx, temp, &hw->ctlxq.reapable, list) {
2611 list_del(&ctlx->list);
2615 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2618 /*----------------------------------------------------------------
2619 * hfa384x_usbctlx_completion_task
2621 * Tasklet to call completion handlers for returned CTLXs
2624 * data ptr to struct hfa384x
2631 *----------------------------------------------------------------
2633 static void hfa384x_usbctlx_completion_task(struct tasklet_struct *t)
2635 struct hfa384x *hw = from_tasklet(hw, t, completion_bh);
2636 struct hfa384x_usbctlx *ctlx, *temp;
2637 unsigned long flags;
2641 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2643 /* This list is guaranteed to be empty if someone
2644 * has unplugged the adapter ...
2646 list_for_each_entry_safe(ctlx, temp, &hw->ctlxq.completing, list) {
2647 /* Call the completion function that this
2648 * command was assigned, assuming it has one.
2651 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2652 ctlx->cmdcb(hw, ctlx);
2653 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2655 /* Make sure we don't try and complete
2656 * this CTLX more than once!
2660 /* Did someone yank the adapter out
2661 * while our list was (briefly) unlocked?
2663 if (hw->wlandev->hwremoved) {
2670 * "Reapable" CTLXs are ones which don't have any
2671 * threads waiting for them to die. Hence they must
2672 * be delivered to The Reaper!
2674 if (ctlx->reapable) {
2675 /* Move the CTLX off the "completing" list (hopefully)
2676 * on to the "reapable" list where the reaper task
2677 * can find it. And "reapable" means that this CTLX
2678 * isn't sitting on a wait-queue somewhere.
2680 list_move_tail(&ctlx->list, &hw->ctlxq.reapable);
2684 complete(&ctlx->done);
2686 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2689 tasklet_schedule(&hw->reaper_bh);
2692 /*----------------------------------------------------------------
2693 * unlocked_usbctlx_cancel_async
2695 * Mark the CTLX dead asynchronously, and ensure that the
2696 * next command on the queue is run afterwards.
2699 * hw ptr to the struct hfa384x structure
2700 * ctlx ptr to a CTLX structure
2703 * 0 the CTLX's URB is inactive
2704 * -EINPROGRESS the URB is currently being unlinked
2707 * Either process or interrupt, but presumably interrupt
2708 *----------------------------------------------------------------
2710 static int unlocked_usbctlx_cancel_async(struct hfa384x *hw,
2711 struct hfa384x_usbctlx *ctlx)
2716 * Try to delete the URB containing our request packet.
2717 * If we succeed, then its completion handler will be
2718 * called with a status of -ECONNRESET.
2720 hw->ctlx_urb.transfer_flags |= URB_ASYNC_UNLINK;
2721 ret = usb_unlink_urb(&hw->ctlx_urb);
2723 if (ret != -EINPROGRESS) {
2725 * The OUT URB had either already completed
2726 * or was still in the pending queue, so the
2727 * URB's completion function will not be called.
2728 * We will have to complete the CTLX ourselves.
2730 ctlx->state = CTLX_REQ_FAILED;
2731 unlocked_usbctlx_complete(hw, ctlx);
2738 /*----------------------------------------------------------------
2739 * unlocked_usbctlx_complete
2741 * A CTLX has completed. It may have been successful, it may not
2742 * have been. At this point, the CTLX should be quiescent. The URBs
2743 * aren't active and the timers should have been stopped.
2745 * The CTLX is migrated to the "completing" queue, and the completing
2746 * tasklet is scheduled.
2749 * hw ptr to a struct hfa384x structure
2750 * ctlx ptr to a ctlx structure
2758 * Either, assume interrupt
2759 *----------------------------------------------------------------
2761 static void unlocked_usbctlx_complete(struct hfa384x *hw,
2762 struct hfa384x_usbctlx *ctlx)
2764 /* Timers have been stopped, and ctlx should be in
2765 * a terminal state. Retire it from the "active"
2768 list_move_tail(&ctlx->list, &hw->ctlxq.completing);
2769 tasklet_schedule(&hw->completion_bh);
2771 switch (ctlx->state) {
2773 case CTLX_REQ_FAILED:
2774 /* This are the correct terminating states. */
2778 netdev_err(hw->wlandev->netdev, "CTLX[%d] not in a terminating state(%s)\n",
2779 le16_to_cpu(ctlx->outbuf.type),
2780 ctlxstr(ctlx->state));
2785 /*----------------------------------------------------------------
2786 * hfa384x_usbctlxq_run
2788 * Checks to see if the head item is running. If not, starts it.
2791 * hw ptr to struct hfa384x
2800 *----------------------------------------------------------------
2802 static void hfa384x_usbctlxq_run(struct hfa384x *hw)
2804 unsigned long flags;
2807 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2809 /* Only one active CTLX at any one time, because there's no
2810 * other (reliable) way to match the response URB to the
2813 * Don't touch any of these CTLXs if the hardware
2814 * has been removed or the USB subsystem is stalled.
2816 if (!list_empty(&hw->ctlxq.active) ||
2817 test_bit(WORK_TX_HALT, &hw->usb_flags) || hw->wlandev->hwremoved)
2820 while (!list_empty(&hw->ctlxq.pending)) {
2821 struct hfa384x_usbctlx *head;
2824 /* This is the first pending command */
2825 head = list_entry(hw->ctlxq.pending.next,
2826 struct hfa384x_usbctlx, list);
2828 /* We need to split this off to avoid a race condition */
2829 list_move_tail(&head->list, &hw->ctlxq.active);
2831 /* Fill the out packet */
2832 usb_fill_bulk_urb(&hw->ctlx_urb, hw->usb,
2834 &head->outbuf, ROUNDUP64(head->outbufsize),
2835 hfa384x_ctlxout_callback, hw);
2836 hw->ctlx_urb.transfer_flags |= USB_QUEUE_BULK;
2838 /* Now submit the URB and update the CTLX's state */
2839 result = usb_submit_urb(&hw->ctlx_urb, GFP_ATOMIC);
2841 /* This CTLX is now running on the active queue */
2842 head->state = CTLX_REQ_SUBMITTED;
2844 /* Start the OUT wait timer */
2845 hw->req_timer_done = 0;
2846 hw->reqtimer.expires = jiffies + HZ;
2847 add_timer(&hw->reqtimer);
2849 /* Start the IN wait timer */
2850 hw->resp_timer_done = 0;
2851 hw->resptimer.expires = jiffies + 2 * HZ;
2852 add_timer(&hw->resptimer);
2857 if (result == -EPIPE) {
2858 /* The OUT pipe needs resetting, so put
2859 * this CTLX back in the "pending" queue
2860 * and schedule a reset ...
2862 netdev_warn(hw->wlandev->netdev,
2863 "%s tx pipe stalled: requesting reset\n",
2864 hw->wlandev->netdev->name);
2865 list_move(&head->list, &hw->ctlxq.pending);
2866 set_bit(WORK_TX_HALT, &hw->usb_flags);
2867 schedule_work(&hw->usb_work);
2871 if (result == -ESHUTDOWN) {
2872 netdev_warn(hw->wlandev->netdev, "%s urb shutdown!\n",
2873 hw->wlandev->netdev->name);
2877 netdev_err(hw->wlandev->netdev, "Failed to submit CTLX[%d]: error=%d\n",
2878 le16_to_cpu(head->outbuf.type), result);
2879 unlocked_usbctlx_complete(hw, head);
2883 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2886 /*----------------------------------------------------------------
2887 * hfa384x_usbin_callback
2889 * Callback for URBs on the BULKIN endpoint.
2892 * urb ptr to the completed urb
2901 *----------------------------------------------------------------
2903 static void hfa384x_usbin_callback(struct urb *urb)
2905 struct wlandevice *wlandev = urb->context;
2907 union hfa384x_usbin *usbin;
2908 struct sk_buff *skb = NULL;
2919 if (!wlandev || !wlandev->netdev || wlandev->hwremoved)
2926 skb = hw->rx_urb_skb;
2927 if (!skb || (skb->data != urb->transfer_buffer)) {
2932 hw->rx_urb_skb = NULL;
2934 /* Check for error conditions within the URB */
2935 switch (urb->status) {
2939 /* Check for short packet */
2940 if (urb->actual_length == 0) {
2941 wlandev->netdev->stats.rx_errors++;
2942 wlandev->netdev->stats.rx_length_errors++;
2948 netdev_warn(hw->wlandev->netdev, "%s rx pipe stalled: requesting reset\n",
2949 wlandev->netdev->name);
2950 if (!test_and_set_bit(WORK_RX_HALT, &hw->usb_flags))
2951 schedule_work(&hw->usb_work);
2952 wlandev->netdev->stats.rx_errors++;
2959 if (!test_and_set_bit(THROTTLE_RX, &hw->usb_flags) &&
2960 !timer_pending(&hw->throttle)) {
2961 mod_timer(&hw->throttle, jiffies + THROTTLE_JIFFIES);
2963 wlandev->netdev->stats.rx_errors++;
2968 wlandev->netdev->stats.rx_over_errors++;
2974 pr_debug("status=%d, device removed.\n", urb->status);
2980 pr_debug("status=%d, urb explicitly unlinked.\n", urb->status);
2985 pr_debug("urb status=%d, transfer flags=0x%x\n",
2986 urb->status, urb->transfer_flags);
2987 wlandev->netdev->stats.rx_errors++;
2992 /* Save values from the RX URB before reposting overwrites it. */
2993 urb_status = urb->status;
2994 usbin = (union hfa384x_usbin *)urb->transfer_buffer;
2996 if (action != ABORT) {
2997 /* Repost the RX URB */
2998 result = submit_rx_urb(hw, GFP_ATOMIC);
3001 netdev_err(hw->wlandev->netdev,
3002 "Fatal, failed to resubmit rx_urb. error=%d\n",
3007 /* Handle any USB-IN packet */
3008 /* Note: the check of the sw_support field, the type field doesn't
3009 * have bit 12 set like the docs suggest.
3011 type = le16_to_cpu(usbin->type);
3012 if (HFA384x_USB_ISRXFRM(type)) {
3013 if (action == HANDLE) {
3014 if (usbin->txfrm.desc.sw_support == 0x0123) {
3015 hfa384x_usbin_txcompl(wlandev, usbin);
3017 skb_put(skb, sizeof(*usbin));
3018 hfa384x_usbin_rx(wlandev, skb);
3024 if (HFA384x_USB_ISTXFRM(type)) {
3025 if (action == HANDLE)
3026 hfa384x_usbin_txcompl(wlandev, usbin);
3030 case HFA384x_USB_INFOFRM:
3031 if (action == ABORT)
3033 if (action == HANDLE)
3034 hfa384x_usbin_info(wlandev, usbin);
3037 case HFA384x_USB_CMDRESP:
3038 case HFA384x_USB_WRIDRESP:
3039 case HFA384x_USB_RRIDRESP:
3040 case HFA384x_USB_WMEMRESP:
3041 case HFA384x_USB_RMEMRESP:
3042 /* ALWAYS, ALWAYS, ALWAYS handle this CTLX!!!! */
3043 hfa384x_usbin_ctlx(hw, usbin, urb_status);
3046 case HFA384x_USB_BUFAVAIL:
3047 pr_debug("Received BUFAVAIL packet, frmlen=%d\n",
3048 usbin->bufavail.frmlen);
3051 case HFA384x_USB_ERROR:
3052 pr_debug("Received USB_ERROR packet, errortype=%d\n",
3053 usbin->usberror.errortype);
3057 pr_debug("Unrecognized USBIN packet, type=%x, status=%d\n",
3058 usbin->type, urb_status);
3068 /*----------------------------------------------------------------
3069 * hfa384x_usbin_ctlx
3071 * We've received a URB containing a Prism2 "response" message.
3072 * This message needs to be matched up with a CTLX on the active
3073 * queue and our state updated accordingly.
3076 * hw ptr to struct hfa384x
3077 * usbin ptr to USB IN packet
3078 * urb_status status of this Bulk-In URB
3087 *----------------------------------------------------------------
3089 static void hfa384x_usbin_ctlx(struct hfa384x *hw, union hfa384x_usbin *usbin,
3092 struct hfa384x_usbctlx *ctlx;
3094 unsigned long flags;
3097 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3099 /* There can be only one CTLX on the active queue
3100 * at any one time, and this is the CTLX that the
3101 * timers are waiting for.
3103 if (list_empty(&hw->ctlxq.active))
3106 /* Remove the "response timeout". It's possible that
3107 * we are already too late, and that the timeout is
3108 * already running. And that's just too bad for us,
3109 * because we could lose our CTLX from the active
3112 if (del_timer(&hw->resptimer) == 0) {
3113 if (hw->resp_timer_done == 0) {
3114 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3118 hw->resp_timer_done = 1;
3121 ctlx = get_active_ctlx(hw);
3123 if (urb_status != 0) {
3125 * Bad CTLX, so get rid of it. But we only
3126 * remove it from the active queue if we're no
3127 * longer expecting the OUT URB to complete.
3129 if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0)
3132 const __le16 intype = (usbin->type & ~cpu_to_le16(0x8000));
3135 * Check that our message is what we're expecting ...
3137 if (ctlx->outbuf.type != intype) {
3138 netdev_warn(hw->wlandev->netdev,
3139 "Expected IN[%d], received IN[%d] - ignored.\n",
3140 le16_to_cpu(ctlx->outbuf.type),
3141 le16_to_cpu(intype));
3145 /* This URB has succeeded, so grab the data ... */
3146 memcpy(&ctlx->inbuf, usbin, sizeof(ctlx->inbuf));
3148 switch (ctlx->state) {
3149 case CTLX_REQ_SUBMITTED:
3151 * We have received our response URB before
3152 * our request has been acknowledged. Odd,
3153 * but our OUT URB is still alive...
3155 pr_debug("Causality violation: please reboot Universe\n");
3156 ctlx->state = CTLX_RESP_COMPLETE;
3159 case CTLX_REQ_COMPLETE:
3161 * This is the usual path: our request
3162 * has already been acknowledged, and
3163 * now we have received the reply too.
3165 ctlx->state = CTLX_COMPLETE;
3166 unlocked_usbctlx_complete(hw, ctlx);
3172 * Throw this CTLX away ...
3174 netdev_err(hw->wlandev->netdev,
3175 "Matched IN URB, CTLX[%d] in invalid state(%s). Discarded.\n",
3176 le16_to_cpu(ctlx->outbuf.type),
3177 ctlxstr(ctlx->state));
3178 if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0)
3185 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3188 hfa384x_usbctlxq_run(hw);
3191 /*----------------------------------------------------------------
3192 * hfa384x_usbin_txcompl
3194 * At this point we have the results of a previous transmit.
3197 * wlandev wlan device
3198 * usbin ptr to the usb transfer buffer
3207 *----------------------------------------------------------------
3209 static void hfa384x_usbin_txcompl(struct wlandevice *wlandev,
3210 union hfa384x_usbin *usbin)
3214 status = le16_to_cpu(usbin->type); /* yeah I know it says type... */
3216 /* Was there an error? */
3217 if (HFA384x_TXSTATUS_ISERROR(status))
3218 prism2sta_ev_txexc(wlandev, status);
3220 prism2sta_ev_tx(wlandev, status);
3223 /*----------------------------------------------------------------
3226 * At this point we have a successful received a rx frame packet.
3229 * wlandev wlan device
3230 * usbin ptr to the usb transfer buffer
3239 *----------------------------------------------------------------
3241 static void hfa384x_usbin_rx(struct wlandevice *wlandev, struct sk_buff *skb)
3243 union hfa384x_usbin *usbin = (union hfa384x_usbin *)skb->data;
3244 struct hfa384x *hw = wlandev->priv;
3246 struct p80211_rxmeta *rxmeta;
3251 /* Byte order convert once up front. */
3252 le16_to_cpus(&usbin->rxfrm.desc.status);
3253 le32_to_cpus(&usbin->rxfrm.desc.time);
3255 /* Now handle frame based on port# */
3256 status = HFA384x_RXSTATUS_MACPORT_GET(usbin->rxfrm.desc.status);
3260 fc = le16_to_cpu(usbin->rxfrm.desc.hdr.frame_control);
3262 /* If exclude and we receive an unencrypted, drop it */
3263 if ((wlandev->hostwep & HOSTWEP_EXCLUDEUNENCRYPTED) &&
3264 !WLAN_GET_FC_ISWEP(fc)) {
3268 data_len = le16_to_cpu(usbin->rxfrm.desc.data_len);
3270 /* How much header data do we have? */
3271 hdrlen = p80211_headerlen(fc);
3273 /* Pull off the descriptor */
3274 skb_pull(skb, sizeof(struct hfa384x_rx_frame));
3276 /* Now shunt the header block up against the data block
3277 * with an "overlapping" copy
3279 memmove(skb_push(skb, hdrlen),
3280 &usbin->rxfrm.desc.hdr, hdrlen);
3282 skb->dev = wlandev->netdev;
3284 /* And set the frame length properly */
3285 skb_trim(skb, data_len + hdrlen);
3287 /* The prism2 series does not return the CRC */
3288 memset(skb_put(skb, WLAN_CRC_LEN), 0xff, WLAN_CRC_LEN);
3290 skb_reset_mac_header(skb);
3292 /* Attach the rxmeta, set some stuff */
3293 p80211skb_rxmeta_attach(wlandev, skb);
3294 rxmeta = p80211skb_rxmeta(skb);
3295 rxmeta->mactime = usbin->rxfrm.desc.time;
3296 rxmeta->rxrate = usbin->rxfrm.desc.rate;
3297 rxmeta->signal = usbin->rxfrm.desc.signal - hw->dbmadjust;
3298 rxmeta->noise = usbin->rxfrm.desc.silence - hw->dbmadjust;
3300 p80211netdev_rx(wlandev, skb);
3305 if (!HFA384x_RXSTATUS_ISFCSERR(usbin->rxfrm.desc.status)) {
3306 /* Copy to wlansnif skb */
3307 hfa384x_int_rxmonitor(wlandev, &usbin->rxfrm);
3310 pr_debug("Received monitor frame: FCSerr set\n");
3315 netdev_warn(hw->wlandev->netdev,
3316 "Received frame on unsupported port=%d\n",
3322 /*----------------------------------------------------------------
3323 * hfa384x_int_rxmonitor
3325 * Helper function for int_rx. Handles monitor frames.
3326 * Note that this function allocates space for the FCS and sets it
3327 * to 0xffffffff. The hfa384x doesn't give us the FCS value but the
3328 * higher layers expect it. 0xffffffff is used as a flag to indicate
3332 * wlandev wlan device structure
3333 * rxfrm rx descriptor read from card in int_rx
3339 * Allocates an skb and passes it up via the PF_PACKET interface.
3342 *----------------------------------------------------------------
3344 static void hfa384x_int_rxmonitor(struct wlandevice *wlandev,
3345 struct hfa384x_usb_rxfrm *rxfrm)
3347 struct hfa384x_rx_frame *rxdesc = &rxfrm->desc;
3348 unsigned int hdrlen = 0;
3349 unsigned int datalen = 0;
3350 unsigned int skblen = 0;
3353 struct sk_buff *skb;
3354 struct hfa384x *hw = wlandev->priv;
3356 /* Remember the status, time, and data_len fields are in host order */
3357 /* Figure out how big the frame is */
3358 fc = le16_to_cpu(rxdesc->hdr.frame_control);
3359 hdrlen = p80211_headerlen(fc);
3360 datalen = le16_to_cpu(rxdesc->data_len);
3362 /* Allocate an ind message+framesize skb */
3363 skblen = sizeof(struct p80211_caphdr) + hdrlen + datalen + WLAN_CRC_LEN;
3365 /* sanity check the length */
3367 (sizeof(struct p80211_caphdr) +
3368 WLAN_HDR_A4_LEN + WLAN_DATA_MAXLEN + WLAN_CRC_LEN)) {
3369 pr_debug("overlen frm: len=%zd\n",
3370 skblen - sizeof(struct p80211_caphdr));
3375 skb = dev_alloc_skb(skblen);
3379 /* only prepend the prism header if in the right mode */
3380 if ((wlandev->netdev->type == ARPHRD_IEEE80211_PRISM) &&
3381 (hw->sniffhdr != 0)) {
3382 struct p80211_caphdr *caphdr;
3383 /* The NEW header format! */
3384 datap = skb_put(skb, sizeof(struct p80211_caphdr));
3385 caphdr = (struct p80211_caphdr *)datap;
3387 caphdr->version = htonl(P80211CAPTURE_VERSION);
3388 caphdr->length = htonl(sizeof(struct p80211_caphdr));
3389 caphdr->mactime = __cpu_to_be64(rxdesc->time * 1000);
3390 caphdr->hosttime = __cpu_to_be64(jiffies);
3391 caphdr->phytype = htonl(4); /* dss_dot11_b */
3392 caphdr->channel = htonl(hw->sniff_channel);
3393 caphdr->datarate = htonl(rxdesc->rate);
3394 caphdr->antenna = htonl(0); /* unknown */
3395 caphdr->priority = htonl(0); /* unknown */
3396 caphdr->ssi_type = htonl(3); /* rssi_raw */
3397 caphdr->ssi_signal = htonl(rxdesc->signal);
3398 caphdr->ssi_noise = htonl(rxdesc->silence);
3399 caphdr->preamble = htonl(0); /* unknown */
3400 caphdr->encoding = htonl(1); /* cck */
3403 /* Copy the 802.11 header to the skb
3404 * (ctl frames may be less than a full header)
3406 skb_put_data(skb, &rxdesc->hdr.frame_control, hdrlen);
3408 /* If any, copy the data from the card to the skb */
3410 datap = skb_put_data(skb, rxfrm->data, datalen);
3412 /* check for unencrypted stuff if WEP bit set. */
3413 if (*(datap - hdrlen + 1) & 0x40) /* wep set */
3414 if ((*(datap) == 0xaa) && (*(datap + 1) == 0xaa))
3415 /* clear wep; it's the 802.2 header! */
3416 *(datap - hdrlen + 1) &= 0xbf;
3419 if (hw->sniff_fcs) {
3421 datap = skb_put(skb, WLAN_CRC_LEN);
3422 memset(datap, 0xff, WLAN_CRC_LEN);
3425 /* pass it back up */
3426 p80211netdev_rx(wlandev, skb);
3429 /*----------------------------------------------------------------
3430 * hfa384x_usbin_info
3432 * At this point we have a successful received a Prism2 info frame.
3435 * wlandev wlan device
3436 * usbin ptr to the usb transfer buffer
3445 *----------------------------------------------------------------
3447 static void hfa384x_usbin_info(struct wlandevice *wlandev,
3448 union hfa384x_usbin *usbin)
3450 le16_to_cpus(&usbin->infofrm.info.framelen);
3451 prism2sta_ev_info(wlandev, &usbin->infofrm.info);
3454 /*----------------------------------------------------------------
3455 * hfa384x_usbout_callback
3457 * Callback for URBs on the BULKOUT endpoint.
3460 * urb ptr to the completed urb
3469 *----------------------------------------------------------------
3471 static void hfa384x_usbout_callback(struct urb *urb)
3473 struct wlandevice *wlandev = urb->context;
3479 if (wlandev && wlandev->netdev) {
3480 switch (urb->status) {
3482 prism2sta_ev_alloc(wlandev);
3486 struct hfa384x *hw = wlandev->priv;
3488 netdev_warn(hw->wlandev->netdev,
3489 "%s tx pipe stalled: requesting reset\n",
3490 wlandev->netdev->name);
3491 if (!test_and_set_bit(WORK_TX_HALT, &hw->usb_flags))
3492 schedule_work(&hw->usb_work);
3493 wlandev->netdev->stats.tx_errors++;
3500 struct hfa384x *hw = wlandev->priv;
3502 if (!test_and_set_bit(THROTTLE_TX, &hw->usb_flags) &&
3503 !timer_pending(&hw->throttle)) {
3504 mod_timer(&hw->throttle,
3505 jiffies + THROTTLE_JIFFIES);
3507 wlandev->netdev->stats.tx_errors++;
3508 netif_stop_queue(wlandev->netdev);
3514 /* Ignorable errors */
3518 netdev_info(wlandev->netdev, "unknown urb->status=%d\n",
3520 wlandev->netdev->stats.tx_errors++;
3526 /*----------------------------------------------------------------
3527 * hfa384x_ctlxout_callback
3529 * Callback for control data on the BULKOUT endpoint.
3532 * urb ptr to the completed urb
3541 *----------------------------------------------------------------
3543 static void hfa384x_ctlxout_callback(struct urb *urb)
3545 struct hfa384x *hw = urb->context;
3546 int delete_resptimer = 0;
3549 struct hfa384x_usbctlx *ctlx;
3550 unsigned long flags;
3552 pr_debug("urb->status=%d\n", urb->status);
3556 if ((urb->status == -ESHUTDOWN) ||
3557 (urb->status == -ENODEV) || !hw)
3561 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3564 * Only one CTLX at a time on the "active" list, and
3565 * none at all if we are unplugged. However, we can
3566 * rely on the disconnect function to clean everything
3567 * up if someone unplugged the adapter.
3569 if (list_empty(&hw->ctlxq.active)) {
3570 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3575 * Having something on the "active" queue means
3576 * that we have timers to worry about ...
3578 if (del_timer(&hw->reqtimer) == 0) {
3579 if (hw->req_timer_done == 0) {
3581 * This timer was actually running while we
3582 * were trying to delete it. Let it terminate
3583 * gracefully instead.
3585 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3589 hw->req_timer_done = 1;
3592 ctlx = get_active_ctlx(hw);
3594 if (urb->status == 0) {
3595 /* Request portion of a CTLX is successful */
3596 switch (ctlx->state) {
3597 case CTLX_REQ_SUBMITTED:
3598 /* This OUT-ACK received before IN */
3599 ctlx->state = CTLX_REQ_COMPLETE;
3602 case CTLX_RESP_COMPLETE:
3603 /* IN already received before this OUT-ACK,
3604 * so this command must now be complete.
3606 ctlx->state = CTLX_COMPLETE;
3607 unlocked_usbctlx_complete(hw, ctlx);
3612 /* This is NOT a valid CTLX "success" state! */
3613 netdev_err(hw->wlandev->netdev,
3614 "Illegal CTLX[%d] success state(%s, %d) in OUT URB\n",
3615 le16_to_cpu(ctlx->outbuf.type),
3616 ctlxstr(ctlx->state), urb->status);
3620 /* If the pipe has stalled then we need to reset it */
3621 if ((urb->status == -EPIPE) &&
3622 !test_and_set_bit(WORK_TX_HALT, &hw->usb_flags)) {
3623 netdev_warn(hw->wlandev->netdev,
3624 "%s tx pipe stalled: requesting reset\n",
3625 hw->wlandev->netdev->name);
3626 schedule_work(&hw->usb_work);
3629 /* If someone cancels the OUT URB then its status
3630 * should be either -ECONNRESET or -ENOENT.
3632 ctlx->state = CTLX_REQ_FAILED;
3633 unlocked_usbctlx_complete(hw, ctlx);
3634 delete_resptimer = 1;
3639 if (delete_resptimer) {
3640 timer_ok = del_timer(&hw->resptimer);
3642 hw->resp_timer_done = 1;
3645 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3647 if (!timer_ok && (hw->resp_timer_done == 0)) {
3648 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3653 hfa384x_usbctlxq_run(hw);
3656 /*----------------------------------------------------------------
3657 * hfa384x_usbctlx_reqtimerfn
3659 * Timer response function for CTLX request timeouts. If this
3660 * function is called, it means that the callback for the OUT
3661 * URB containing a Prism2.x XXX_Request was never called.
3664 * data a ptr to the struct hfa384x
3673 *----------------------------------------------------------------
3675 static void hfa384x_usbctlx_reqtimerfn(struct timer_list *t)
3677 struct hfa384x *hw = from_timer(hw, t, reqtimer);
3678 unsigned long flags;
3680 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3682 hw->req_timer_done = 1;
3684 /* Removing the hardware automatically empties
3685 * the active list ...
3687 if (!list_empty(&hw->ctlxq.active)) {
3689 * We must ensure that our URB is removed from
3690 * the system, if it hasn't already expired.
3692 hw->ctlx_urb.transfer_flags |= URB_ASYNC_UNLINK;
3693 if (usb_unlink_urb(&hw->ctlx_urb) == -EINPROGRESS) {
3694 struct hfa384x_usbctlx *ctlx = get_active_ctlx(hw);
3696 ctlx->state = CTLX_REQ_FAILED;
3698 /* This URB was active, but has now been
3699 * cancelled. It will now have a status of
3700 * -ECONNRESET in the callback function.
3702 * We are cancelling this CTLX, so we're
3703 * not going to need to wait for a response.
3704 * The URB's callback function will check
3705 * that this timer is truly dead.
3707 if (del_timer(&hw->resptimer) != 0)
3708 hw->resp_timer_done = 1;
3712 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3715 /*----------------------------------------------------------------
3716 * hfa384x_usbctlx_resptimerfn
3718 * Timer response function for CTLX response timeouts. If this
3719 * function is called, it means that the callback for the IN
3720 * URB containing a Prism2.x XXX_Response was never called.
3723 * data a ptr to the struct hfa384x
3732 *----------------------------------------------------------------
3734 static void hfa384x_usbctlx_resptimerfn(struct timer_list *t)
3736 struct hfa384x *hw = from_timer(hw, t, resptimer);
3737 unsigned long flags;
3739 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3741 hw->resp_timer_done = 1;
3743 /* The active list will be empty if the
3744 * adapter has been unplugged ...
3746 if (!list_empty(&hw->ctlxq.active)) {
3747 struct hfa384x_usbctlx *ctlx = get_active_ctlx(hw);
3749 if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0) {
3750 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3751 hfa384x_usbctlxq_run(hw);
3755 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3758 /*----------------------------------------------------------------
3759 * hfa384x_usb_throttlefn
3772 *----------------------------------------------------------------
3774 static void hfa384x_usb_throttlefn(struct timer_list *t)
3776 struct hfa384x *hw = from_timer(hw, t, throttle);
3777 unsigned long flags;
3779 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3781 pr_debug("flags=0x%lx\n", hw->usb_flags);
3782 if (!hw->wlandev->hwremoved) {
3783 bool rx_throttle = test_and_clear_bit(THROTTLE_RX, &hw->usb_flags) &&
3784 !test_and_set_bit(WORK_RX_RESUME, &hw->usb_flags);
3785 bool tx_throttle = test_and_clear_bit(THROTTLE_TX, &hw->usb_flags) &&
3786 !test_and_set_bit(WORK_TX_RESUME, &hw->usb_flags);
3788 * We need to check BOTH the RX and the TX throttle controls,
3789 * so we use the bitwise OR instead of the logical OR.
3791 if (rx_throttle | tx_throttle)
3792 schedule_work(&hw->usb_work);
3795 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3798 /*----------------------------------------------------------------
3799 * hfa384x_usbctlx_submit
3801 * Called from the doxxx functions to submit a CTLX to the queue
3804 * hw ptr to the hw struct
3805 * ctlx ctlx structure to enqueue
3808 * -ENODEV if the adapter is unplugged
3814 * process or interrupt
3815 *----------------------------------------------------------------
3817 static int hfa384x_usbctlx_submit(struct hfa384x *hw,
3818 struct hfa384x_usbctlx *ctlx)
3820 unsigned long flags;
3822 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3824 if (hw->wlandev->hwremoved) {
3825 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3829 ctlx->state = CTLX_PENDING;
3830 list_add_tail(&ctlx->list, &hw->ctlxq.pending);
3831 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3832 hfa384x_usbctlxq_run(hw);
3837 /*----------------------------------------------------------------
3838 * hfa384x_isgood_pdrcore
3840 * Quick check of PDR codes.
3843 * pdrcode PDR code number (host order)
3852 *----------------------------------------------------------------
3854 static int hfa384x_isgood_pdrcode(u16 pdrcode)
3857 case HFA384x_PDR_END_OF_PDA:
3858 case HFA384x_PDR_PCB_PARTNUM:
3859 case HFA384x_PDR_PDAVER:
3860 case HFA384x_PDR_NIC_SERIAL:
3861 case HFA384x_PDR_MKK_MEASUREMENTS:
3862 case HFA384x_PDR_NIC_RAMSIZE:
3863 case HFA384x_PDR_MFISUPRANGE:
3864 case HFA384x_PDR_CFISUPRANGE:
3865 case HFA384x_PDR_NICID:
3866 case HFA384x_PDR_MAC_ADDRESS:
3867 case HFA384x_PDR_REGDOMAIN:
3868 case HFA384x_PDR_ALLOWED_CHANNEL:
3869 case HFA384x_PDR_DEFAULT_CHANNEL:
3870 case HFA384x_PDR_TEMPTYPE:
3871 case HFA384x_PDR_IFR_SETTING:
3872 case HFA384x_PDR_RFR_SETTING:
3873 case HFA384x_PDR_HFA3861_BASELINE:
3874 case HFA384x_PDR_HFA3861_SHADOW:
3875 case HFA384x_PDR_HFA3861_IFRF:
3876 case HFA384x_PDR_HFA3861_CHCALSP:
3877 case HFA384x_PDR_HFA3861_CHCALI:
3878 case HFA384x_PDR_3842_NIC_CONFIG:
3879 case HFA384x_PDR_USB_ID:
3880 case HFA384x_PDR_PCI_ID:
3881 case HFA384x_PDR_PCI_IFCONF:
3882 case HFA384x_PDR_PCI_PMCONF:
3883 case HFA384x_PDR_RFENRGY:
3884 case HFA384x_PDR_HFA3861_MANF_TESTSP:
3885 case HFA384x_PDR_HFA3861_MANF_TESTI:
3889 if (pdrcode < 0x1000) {
3890 /* code is OK, but we don't know exactly what it is */
3891 pr_debug("Encountered unknown PDR#=0x%04x, assuming it's ok.\n",
3898 pr_debug("Encountered unknown PDR#=0x%04x, (>=0x1000), assuming it's bad.\n",