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 variantof 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(unsigned long data);
196 static void hfa384x_usbctlx_reaper_task(unsigned long data);
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,
232 struct hfa384x_metacmd *cmd,
233 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
236 hfa384x_dorrid(struct hfa384x *hw,
240 unsigned int riddatalen,
241 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
244 hfa384x_dowrid(struct hfa384x *hw,
248 unsigned int riddatalen,
249 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
252 hfa384x_dormem(struct hfa384x *hw,
258 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
261 hfa384x_dowmem(struct hfa384x *hw,
267 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
269 static int hfa384x_isgood_pdrcode(u16 pdrcode);
271 static inline const char *ctlxstr(enum ctlx_state s)
273 static const char * const ctlx_str[] = {
278 "Request packet submitted",
279 "Request packet completed",
280 "Response packet completed"
286 static inline struct hfa384x_usbctlx *get_active_ctlx(struct hfa384x *hw)
288 return list_entry(hw->ctlxq.active.next, struct hfa384x_usbctlx, list);
292 void dbprint_urb(struct urb *urb)
294 pr_debug("urb->pipe=0x%08x\n", urb->pipe);
295 pr_debug("urb->status=0x%08x\n", urb->status);
296 pr_debug("urb->transfer_flags=0x%08x\n", urb->transfer_flags);
297 pr_debug("urb->transfer_buffer=0x%08x\n",
298 (unsigned int)urb->transfer_buffer);
299 pr_debug("urb->transfer_buffer_length=0x%08x\n",
300 urb->transfer_buffer_length);
301 pr_debug("urb->actual_length=0x%08x\n", urb->actual_length);
302 pr_debug("urb->bandwidth=0x%08x\n", urb->bandwidth);
303 pr_debug("urb->setup_packet(ctl)=0x%08x\n",
304 (unsigned int)urb->setup_packet);
305 pr_debug("urb->start_frame(iso/irq)=0x%08x\n", urb->start_frame);
306 pr_debug("urb->interval(irq)=0x%08x\n", urb->interval);
307 pr_debug("urb->error_count(iso)=0x%08x\n", urb->error_count);
308 pr_debug("urb->timeout=0x%08x\n", urb->timeout);
309 pr_debug("urb->context=0x%08x\n", (unsigned int)urb->context);
310 pr_debug("urb->complete=0x%08x\n", (unsigned int)urb->complete);
314 /*----------------------------------------------------------------
317 * Listen for input data on the BULK-IN pipe. If the pipe has
318 * stalled then schedule it to be reset.
322 * memflags memory allocation flags
325 * error code from submission
329 *----------------------------------------------------------------
331 static int submit_rx_urb(struct hfa384x *hw, gfp_t memflags)
336 skb = dev_alloc_skb(sizeof(union hfa384x_usbin));
342 /* Post the IN urb */
343 usb_fill_bulk_urb(&hw->rx_urb, hw->usb,
345 skb->data, sizeof(union hfa384x_usbin),
346 hfa384x_usbin_callback, hw->wlandev);
348 hw->rx_urb_skb = skb;
351 if (!hw->wlandev->hwremoved &&
352 !test_bit(WORK_RX_HALT, &hw->usb_flags)) {
353 result = usb_submit_urb(&hw->rx_urb, memflags);
355 /* Check whether we need to reset the RX pipe */
356 if (result == -EPIPE) {
357 netdev_warn(hw->wlandev->netdev,
358 "%s rx pipe stalled: requesting reset\n",
359 hw->wlandev->netdev->name);
360 if (!test_and_set_bit(WORK_RX_HALT, &hw->usb_flags))
361 schedule_work(&hw->usb_work);
365 /* Don't leak memory if anything should go wrong */
368 hw->rx_urb_skb = NULL;
375 /*----------------------------------------------------------------
378 * Prepares and submits the URB of transmitted data. If the
379 * submission fails then it will schedule the output pipe to
384 * tx_urb URB of data for transmission
385 * memflags memory allocation flags
388 * error code from submission
392 *----------------------------------------------------------------
394 static int submit_tx_urb(struct hfa384x *hw, struct urb *tx_urb, gfp_t memflags)
396 struct net_device *netdev = hw->wlandev->netdev;
400 if (netif_running(netdev)) {
401 if (!hw->wlandev->hwremoved &&
402 !test_bit(WORK_TX_HALT, &hw->usb_flags)) {
403 result = usb_submit_urb(tx_urb, memflags);
405 /* Test whether we need to reset the TX pipe */
406 if (result == -EPIPE) {
407 netdev_warn(hw->wlandev->netdev,
408 "%s tx pipe stalled: requesting reset\n",
410 set_bit(WORK_TX_HALT, &hw->usb_flags);
411 schedule_work(&hw->usb_work);
412 } else if (result == 0) {
413 netif_stop_queue(netdev);
421 /*----------------------------------------------------------------
424 * There are some things that the USB stack cannot do while
425 * in interrupt context, so we arrange this function to run
426 * in process context.
429 * hw device structure
435 * process (by design)
436 *----------------------------------------------------------------
438 static void hfa384x_usb_defer(struct work_struct *data)
440 struct hfa384x *hw = container_of(data, struct hfa384x, usb_work);
441 struct net_device *netdev = hw->wlandev->netdev;
443 /* Don't bother trying to reset anything if the plug
444 * has been pulled ...
446 if (hw->wlandev->hwremoved)
449 /* Reception has stopped: try to reset the input pipe */
450 if (test_bit(WORK_RX_HALT, &hw->usb_flags)) {
453 usb_kill_urb(&hw->rx_urb); /* Cannot be holding spinlock! */
455 ret = usb_clear_halt(hw->usb, hw->endp_in);
457 netdev_err(hw->wlandev->netdev,
458 "Failed to clear rx pipe for %s: err=%d\n",
461 netdev_info(hw->wlandev->netdev, "%s rx pipe reset complete.\n",
463 clear_bit(WORK_RX_HALT, &hw->usb_flags);
464 set_bit(WORK_RX_RESUME, &hw->usb_flags);
468 /* Resume receiving data back from the device. */
469 if (test_bit(WORK_RX_RESUME, &hw->usb_flags)) {
472 ret = submit_rx_urb(hw, GFP_KERNEL);
474 netdev_err(hw->wlandev->netdev,
475 "Failed to resume %s rx pipe.\n",
478 clear_bit(WORK_RX_RESUME, &hw->usb_flags);
482 /* Transmission has stopped: try to reset the output pipe */
483 if (test_bit(WORK_TX_HALT, &hw->usb_flags)) {
486 usb_kill_urb(&hw->tx_urb);
487 ret = usb_clear_halt(hw->usb, hw->endp_out);
489 netdev_err(hw->wlandev->netdev,
490 "Failed to clear tx pipe for %s: err=%d\n",
493 netdev_info(hw->wlandev->netdev, "%s tx pipe reset complete.\n",
495 clear_bit(WORK_TX_HALT, &hw->usb_flags);
496 set_bit(WORK_TX_RESUME, &hw->usb_flags);
498 /* Stopping the BULK-OUT pipe also blocked
499 * us from sending any more CTLX URBs, so
500 * we need to re-run our queue ...
502 hfa384x_usbctlxq_run(hw);
506 /* Resume transmitting. */
507 if (test_and_clear_bit(WORK_TX_RESUME, &hw->usb_flags))
508 netif_wake_queue(hw->wlandev->netdev);
511 /*----------------------------------------------------------------
514 * Sets up the struct hfa384x data structure for use. Note this
515 * does _not_ initialize the actual hardware, just the data structures
516 * we use to keep track of its state.
519 * hw device structure
520 * irq device irq number
521 * iobase i/o base address for register access
522 * membase memory base address for register access
531 *----------------------------------------------------------------
533 void hfa384x_create(struct hfa384x *hw, struct usb_device *usb)
537 /* Set up the waitq */
538 init_waitqueue_head(&hw->cmdq);
540 /* Initialize the command queue */
541 spin_lock_init(&hw->ctlxq.lock);
542 INIT_LIST_HEAD(&hw->ctlxq.pending);
543 INIT_LIST_HEAD(&hw->ctlxq.active);
544 INIT_LIST_HEAD(&hw->ctlxq.completing);
545 INIT_LIST_HEAD(&hw->ctlxq.reapable);
547 /* Initialize the authentication queue */
548 skb_queue_head_init(&hw->authq);
550 tasklet_init(&hw->reaper_bh,
551 hfa384x_usbctlx_reaper_task, (unsigned long)hw);
552 tasklet_init(&hw->completion_bh,
553 hfa384x_usbctlx_completion_task, (unsigned long)hw);
554 INIT_WORK(&hw->link_bh, prism2sta_processing_defer);
555 INIT_WORK(&hw->usb_work, hfa384x_usb_defer);
557 timer_setup(&hw->throttle, hfa384x_usb_throttlefn, 0);
559 timer_setup(&hw->resptimer, hfa384x_usbctlx_resptimerfn, 0);
561 timer_setup(&hw->reqtimer, hfa384x_usbctlx_reqtimerfn, 0);
563 usb_init_urb(&hw->rx_urb);
564 usb_init_urb(&hw->tx_urb);
565 usb_init_urb(&hw->ctlx_urb);
567 hw->link_status = HFA384x_LINK_NOTCONNECTED;
568 hw->state = HFA384x_STATE_INIT;
570 INIT_WORK(&hw->commsqual_bh, prism2sta_commsqual_defer);
571 timer_setup(&hw->commsqual_timer, prism2sta_commsqual_timer, 0);
574 /*----------------------------------------------------------------
577 * Partner to hfa384x_create(). This function cleans up the hw
578 * structure so that it can be freed by the caller using a simple
579 * kfree. Currently, this function is just a placeholder. If, at some
580 * point in the future, an hw in the 'shutdown' state requires a 'deep'
581 * kfree, this is where it should be done. Note that if this function
582 * is called on a _running_ hw structure, the drvr_stop() function is
586 * hw device structure
589 * nothing, this function is not allowed to fail.
595 *----------------------------------------------------------------
597 void hfa384x_destroy(struct hfa384x *hw)
601 if (hw->state == HFA384x_STATE_RUNNING)
602 hfa384x_drvr_stop(hw);
603 hw->state = HFA384x_STATE_PREINIT;
605 kfree(hw->scanresults);
606 hw->scanresults = NULL;
608 /* Now to clean out the auth queue */
609 while ((skb = skb_dequeue(&hw->authq)))
613 static struct hfa384x_usbctlx *usbctlx_alloc(void)
615 struct hfa384x_usbctlx *ctlx;
617 ctlx = kzalloc(sizeof(*ctlx),
618 in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
620 init_completion(&ctlx->done);
626 usbctlx_get_status(const struct hfa384x_usb_statusresp *cmdresp,
627 struct hfa384x_cmdresult *result)
629 result->status = le16_to_cpu(cmdresp->status);
630 result->resp0 = le16_to_cpu(cmdresp->resp0);
631 result->resp1 = le16_to_cpu(cmdresp->resp1);
632 result->resp2 = le16_to_cpu(cmdresp->resp2);
634 pr_debug("cmdresult:status=0x%04x resp0=0x%04x resp1=0x%04x resp2=0x%04x\n",
635 result->status, result->resp0, result->resp1, result->resp2);
637 return result->status & HFA384x_STATUS_RESULT;
641 usbctlx_get_rridresult(const struct hfa384x_usb_rridresp *rridresp,
642 struct hfa384x_rridresult *result)
644 result->rid = le16_to_cpu(rridresp->rid);
645 result->riddata = rridresp->data;
646 result->riddata_len = ((le16_to_cpu(rridresp->frmlen) - 1) * 2);
649 /*----------------------------------------------------------------
651 * This completor must be passed to hfa384x_usbctlx_complete_sync()
652 * when processing a CTLX that returns a struct hfa384x_cmdresult structure.
653 *----------------------------------------------------------------
655 struct usbctlx_cmd_completor {
656 struct usbctlx_completor head;
658 const struct hfa384x_usb_statusresp *cmdresp;
659 struct hfa384x_cmdresult *result;
662 static inline int usbctlx_cmd_completor_fn(struct usbctlx_completor *head)
664 struct usbctlx_cmd_completor *complete;
666 complete = (struct usbctlx_cmd_completor *)head;
667 return usbctlx_get_status(complete->cmdresp, complete->result);
670 static inline struct usbctlx_completor *
671 init_cmd_completor(struct usbctlx_cmd_completor *completor,
672 const struct hfa384x_usb_statusresp *cmdresp,
673 struct hfa384x_cmdresult *result)
675 completor->head.complete = usbctlx_cmd_completor_fn;
676 completor->cmdresp = cmdresp;
677 completor->result = result;
678 return &completor->head;
681 /*----------------------------------------------------------------
683 * This completor must be passed to hfa384x_usbctlx_complete_sync()
684 * when processing a CTLX that reads a RID.
685 *----------------------------------------------------------------
687 struct usbctlx_rrid_completor {
688 struct usbctlx_completor head;
690 const struct hfa384x_usb_rridresp *rridresp;
692 unsigned int riddatalen;
695 static int usbctlx_rrid_completor_fn(struct usbctlx_completor *head)
697 struct usbctlx_rrid_completor *complete;
698 struct hfa384x_rridresult rridresult;
700 complete = (struct usbctlx_rrid_completor *)head;
701 usbctlx_get_rridresult(complete->rridresp, &rridresult);
703 /* Validate the length, note body len calculation in bytes */
704 if (rridresult.riddata_len != complete->riddatalen) {
705 pr_warn("RID len mismatch, rid=0x%04x hlen=%d fwlen=%d\n",
707 complete->riddatalen, rridresult.riddata_len);
711 memcpy(complete->riddata, rridresult.riddata, complete->riddatalen);
715 static inline struct usbctlx_completor *
716 init_rrid_completor(struct usbctlx_rrid_completor *completor,
717 const struct hfa384x_usb_rridresp *rridresp,
719 unsigned int riddatalen)
721 completor->head.complete = usbctlx_rrid_completor_fn;
722 completor->rridresp = rridresp;
723 completor->riddata = riddata;
724 completor->riddatalen = riddatalen;
725 return &completor->head;
728 /*----------------------------------------------------------------
730 * Interprets the results of a synchronous RID-write
731 *----------------------------------------------------------------
733 #define init_wrid_completor init_cmd_completor
735 /*----------------------------------------------------------------
737 * Interprets the results of a synchronous memory-write
738 *----------------------------------------------------------------
740 #define init_wmem_completor init_cmd_completor
742 /*----------------------------------------------------------------
744 * Interprets the results of a synchronous memory-read
745 *----------------------------------------------------------------
747 struct usbctlx_rmem_completor {
748 struct usbctlx_completor head;
750 const struct hfa384x_usb_rmemresp *rmemresp;
755 static int usbctlx_rmem_completor_fn(struct usbctlx_completor *head)
757 struct usbctlx_rmem_completor *complete =
758 (struct usbctlx_rmem_completor *)head;
760 pr_debug("rmemresp:len=%d\n", complete->rmemresp->frmlen);
761 memcpy(complete->data, complete->rmemresp->data, complete->len);
765 static inline struct usbctlx_completor *
766 init_rmem_completor(struct usbctlx_rmem_completor *completor,
767 struct hfa384x_usb_rmemresp *rmemresp,
771 completor->head.complete = usbctlx_rmem_completor_fn;
772 completor->rmemresp = rmemresp;
773 completor->data = data;
774 completor->len = len;
775 return &completor->head;
778 /*----------------------------------------------------------------
781 * Ctlx_complete handler for async CMD type control exchanges.
782 * mark the hw struct as such.
784 * Note: If the handling is changed here, it should probably be
785 * changed in docmd as well.
789 * ctlx completed CTLX
798 *----------------------------------------------------------------
800 static void hfa384x_cb_status(struct hfa384x *hw,
801 const struct hfa384x_usbctlx *ctlx)
804 struct hfa384x_cmdresult cmdresult;
806 if (ctlx->state != CTLX_COMPLETE) {
807 memset(&cmdresult, 0, sizeof(cmdresult));
809 HFA384x_STATUS_RESULT_SET(HFA384x_CMD_ERR);
811 usbctlx_get_status(&ctlx->inbuf.cmdresp, &cmdresult);
814 ctlx->usercb(hw, &cmdresult, ctlx->usercb_data);
818 static inline int hfa384x_docmd_wait(struct hfa384x *hw,
819 struct hfa384x_metacmd *cmd)
821 return hfa384x_docmd(hw, DOWAIT, cmd, NULL, NULL, NULL);
825 hfa384x_docmd_async(struct hfa384x *hw,
826 struct hfa384x_metacmd *cmd,
827 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
829 return hfa384x_docmd(hw, DOASYNC, cmd, cmdcb, usercb, usercb_data);
833 hfa384x_dorrid_wait(struct hfa384x *hw, u16 rid, void *riddata,
834 unsigned int riddatalen)
836 return hfa384x_dorrid(hw, DOWAIT,
837 rid, riddata, riddatalen, NULL, NULL, NULL);
841 hfa384x_dorrid_async(struct hfa384x *hw,
842 u16 rid, void *riddata, unsigned int riddatalen,
844 ctlx_usercb_t usercb, void *usercb_data)
846 return hfa384x_dorrid(hw, DOASYNC,
847 rid, riddata, riddatalen,
848 cmdcb, usercb, usercb_data);
852 hfa384x_dowrid_wait(struct hfa384x *hw, u16 rid, void *riddata,
853 unsigned int riddatalen)
855 return hfa384x_dowrid(hw, DOWAIT,
856 rid, riddata, riddatalen, NULL, NULL, NULL);
860 hfa384x_dowrid_async(struct hfa384x *hw,
861 u16 rid, void *riddata, unsigned int riddatalen,
863 ctlx_usercb_t usercb, void *usercb_data)
865 return hfa384x_dowrid(hw, DOASYNC,
866 rid, riddata, riddatalen,
867 cmdcb, usercb, usercb_data);
871 hfa384x_dormem_wait(struct hfa384x *hw,
872 u16 page, u16 offset, void *data, unsigned int len)
874 return hfa384x_dormem(hw, DOWAIT,
875 page, offset, data, len, NULL, NULL, NULL);
879 hfa384x_dormem_async(struct hfa384x *hw,
880 u16 page, u16 offset, void *data, unsigned int len,
882 ctlx_usercb_t usercb, void *usercb_data)
884 return hfa384x_dormem(hw, DOASYNC,
885 page, offset, data, len,
886 cmdcb, usercb, usercb_data);
890 hfa384x_dowmem_wait(struct hfa384x *hw,
891 u16 page, u16 offset, void *data, unsigned int len)
893 return hfa384x_dowmem(hw, DOWAIT,
894 page, offset, data, len, NULL, NULL, NULL);
898 hfa384x_dowmem_async(struct hfa384x *hw,
904 ctlx_usercb_t usercb, void *usercb_data)
906 return hfa384x_dowmem(hw, DOASYNC,
907 page, offset, data, len,
908 cmdcb, usercb, usercb_data);
911 /*----------------------------------------------------------------
912 * hfa384x_cmd_initialize
914 * Issues the initialize command and sets the hw->state based
918 * hw device structure
922 * >0 f/w reported error - f/w status code
923 * <0 driver reported error
929 *----------------------------------------------------------------
931 int hfa384x_cmd_initialize(struct hfa384x *hw)
935 struct hfa384x_metacmd cmd;
937 cmd.cmd = HFA384x_CMDCODE_INIT;
942 result = hfa384x_docmd_wait(hw, &cmd);
944 pr_debug("cmdresp.init: status=0x%04x, resp0=0x%04x, resp1=0x%04x, resp2=0x%04x\n",
946 cmd.result.resp0, cmd.result.resp1, cmd.result.resp2);
948 for (i = 0; i < HFA384x_NUMPORTS_MAX; i++)
949 hw->port_enabled[i] = 0;
952 hw->link_status = HFA384x_LINK_NOTCONNECTED;
957 /*----------------------------------------------------------------
958 * hfa384x_cmd_disable
960 * Issues the disable command to stop communications on one of
964 * hw device structure
965 * macport MAC port number (host order)
969 * >0 f/w reported failure - f/w status code
970 * <0 driver reported error (timeout|bad arg)
976 *----------------------------------------------------------------
978 int hfa384x_cmd_disable(struct hfa384x *hw, u16 macport)
980 struct hfa384x_metacmd cmd;
982 cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_DISABLE) |
983 HFA384x_CMD_MACPORT_SET(macport);
988 return hfa384x_docmd_wait(hw, &cmd);
991 /*----------------------------------------------------------------
994 * Issues the enable command to enable communications on one of
998 * hw device structure
999 * macport MAC port number
1003 * >0 f/w reported failure - f/w status code
1004 * <0 driver reported error (timeout|bad arg)
1010 *----------------------------------------------------------------
1012 int hfa384x_cmd_enable(struct hfa384x *hw, u16 macport)
1014 struct hfa384x_metacmd cmd;
1016 cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_ENABLE) |
1017 HFA384x_CMD_MACPORT_SET(macport);
1022 return hfa384x_docmd_wait(hw, &cmd);
1025 /*----------------------------------------------------------------
1026 * hfa384x_cmd_monitor
1028 * Enables the 'monitor mode' of the MAC. Here's the description of
1029 * monitor mode that I've received thus far:
1031 * "The "monitor mode" of operation is that the MAC passes all
1032 * frames for which the PLCP checks are correct. All received
1033 * MPDUs are passed to the host with MAC Port = 7, with a
1034 * receive status of good, FCS error, or undecryptable. Passing
1035 * certain MPDUs is a violation of the 802.11 standard, but useful
1036 * for a debugging tool." Normal communication is not possible
1037 * while monitor mode is enabled.
1040 * hw device structure
1041 * enable a code (0x0b|0x0f) that enables/disables
1042 * monitor mode. (host order)
1046 * >0 f/w reported failure - f/w status code
1047 * <0 driver reported error (timeout|bad arg)
1053 *----------------------------------------------------------------
1055 int hfa384x_cmd_monitor(struct hfa384x *hw, u16 enable)
1057 struct hfa384x_metacmd cmd;
1059 cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_MONITOR) |
1060 HFA384x_CMD_AINFO_SET(enable);
1065 return hfa384x_docmd_wait(hw, &cmd);
1068 /*----------------------------------------------------------------
1069 * hfa384x_cmd_download
1071 * Sets the controls for the MAC controller code/data download
1072 * process. The arguments set the mode and address associated
1073 * with a download. Note that the aux registers should be enabled
1074 * prior to setting one of the download enable modes.
1077 * hw device structure
1078 * mode 0 - Disable programming and begin code exec
1079 * 1 - Enable volatile mem programming
1080 * 2 - Enable non-volatile mem programming
1081 * 3 - Program non-volatile section from NV download
1085 * highaddr For mode 1, sets the high & low order bits of
1086 * the "destination address". This address will be
1087 * the execution start address when download is
1088 * subsequently disabled.
1089 * For mode 2, sets the high & low order bits of
1090 * the destination in NV ram.
1091 * For modes 0 & 3, should be zero. (host order)
1092 * NOTE: these are CMD format.
1093 * codelen Length of the data to write in mode 2,
1094 * zero otherwise. (host order)
1098 * >0 f/w reported failure - f/w status code
1099 * <0 driver reported error (timeout|bad arg)
1105 *----------------------------------------------------------------
1107 int hfa384x_cmd_download(struct hfa384x *hw, u16 mode, u16 lowaddr,
1108 u16 highaddr, u16 codelen)
1110 struct hfa384x_metacmd cmd;
1112 pr_debug("mode=%d, lowaddr=0x%04x, highaddr=0x%04x, codelen=%d\n",
1113 mode, lowaddr, highaddr, codelen);
1115 cmd.cmd = (HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_DOWNLD) |
1116 HFA384x_CMD_PROGMODE_SET(mode));
1118 cmd.parm0 = lowaddr;
1119 cmd.parm1 = highaddr;
1120 cmd.parm2 = codelen;
1122 return hfa384x_docmd_wait(hw, &cmd);
1125 /*----------------------------------------------------------------
1128 * Perform a reset of the hfa38xx MAC core. We assume that the hw
1129 * structure is in its "created" state. That is, it is initialized
1130 * with proper values. Note that if a reset is done after the
1131 * device has been active for awhile, the caller might have to clean
1132 * up some leftover cruft in the hw structure.
1135 * hw device structure
1136 * holdtime how long (in ms) to hold the reset
1137 * settletime how long (in ms) to wait after releasing
1147 *----------------------------------------------------------------
1149 int hfa384x_corereset(struct hfa384x *hw, int holdtime,
1150 int settletime, int genesis)
1154 result = usb_reset_device(hw->usb);
1156 netdev_err(hw->wlandev->netdev, "usb_reset_device() failed, result=%d.\n",
1163 /*----------------------------------------------------------------
1164 * hfa384x_usbctlx_complete_sync
1166 * Waits for a synchronous CTLX object to complete,
1167 * and then handles the response.
1170 * hw device structure
1172 * completor functor object to decide what to
1173 * do with the CTLX's result.
1177 * -ERESTARTSYS Interrupted by a signal
1179 * -ENODEV Adapter was unplugged
1180 * ??? Result from completor
1186 *----------------------------------------------------------------
1188 static int hfa384x_usbctlx_complete_sync(struct hfa384x *hw,
1189 struct hfa384x_usbctlx *ctlx,
1190 struct usbctlx_completor *completor)
1192 unsigned long flags;
1195 result = wait_for_completion_interruptible(&ctlx->done);
1197 spin_lock_irqsave(&hw->ctlxq.lock, flags);
1200 * We can only handle the CTLX if the USB disconnect
1201 * function has not run yet ...
1204 if (hw->wlandev->hwremoved) {
1205 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1207 } else if (result != 0) {
1211 * We were probably interrupted, so delete
1212 * this CTLX asynchronously, kill the timers
1213 * and the URB, and then start the next
1216 * NOTE: We can only delete the timers and
1217 * the URB if this CTLX is active.
1219 if (ctlx == get_active_ctlx(hw)) {
1220 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1222 del_singleshot_timer_sync(&hw->reqtimer);
1223 del_singleshot_timer_sync(&hw->resptimer);
1224 hw->req_timer_done = 1;
1225 hw->resp_timer_done = 1;
1226 usb_kill_urb(&hw->ctlx_urb);
1228 spin_lock_irqsave(&hw->ctlxq.lock, flags);
1233 * This scenario is so unlikely that I'm
1234 * happy with a grubby "goto" solution ...
1236 if (hw->wlandev->hwremoved)
1241 * The completion task will send this CTLX
1242 * to the reaper the next time it runs. We
1243 * are no longer in a hurry.
1246 ctlx->state = CTLX_REQ_FAILED;
1247 list_move_tail(&ctlx->list, &hw->ctlxq.completing);
1249 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1252 hfa384x_usbctlxq_run(hw);
1254 if (ctlx->state == CTLX_COMPLETE) {
1255 result = completor->complete(completor);
1257 netdev_warn(hw->wlandev->netdev, "CTLX[%d] error: state(%s)\n",
1258 le16_to_cpu(ctlx->outbuf.type),
1259 ctlxstr(ctlx->state));
1263 list_del(&ctlx->list);
1264 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1271 /*----------------------------------------------------------------
1274 * Constructs a command CTLX and submits it.
1276 * NOTE: Any changes to the 'post-submit' code in this function
1277 * need to be carried over to hfa384x_cbcmd() since the handling
1278 * is virtually identical.
1281 * hw device structure
1282 * mode DOWAIT or DOASYNC
1283 * cmd cmd structure. Includes all arguments and result
1284 * data points. All in host order. in host order
1285 * cmdcb command-specific callback
1286 * usercb user callback for async calls, NULL for DOWAIT calls
1287 * usercb_data user supplied data pointer for async calls, NULL
1293 * -ERESTARTSYS Awakened on signal
1294 * >0 command indicated error, Status and Resp0-2 are
1302 *----------------------------------------------------------------
1305 hfa384x_docmd(struct hfa384x *hw,
1307 struct hfa384x_metacmd *cmd,
1308 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1311 struct hfa384x_usbctlx *ctlx;
1313 ctlx = usbctlx_alloc();
1319 /* Initialize the command */
1320 ctlx->outbuf.cmdreq.type = cpu_to_le16(HFA384x_USB_CMDREQ);
1321 ctlx->outbuf.cmdreq.cmd = cpu_to_le16(cmd->cmd);
1322 ctlx->outbuf.cmdreq.parm0 = cpu_to_le16(cmd->parm0);
1323 ctlx->outbuf.cmdreq.parm1 = cpu_to_le16(cmd->parm1);
1324 ctlx->outbuf.cmdreq.parm2 = cpu_to_le16(cmd->parm2);
1326 ctlx->outbufsize = sizeof(ctlx->outbuf.cmdreq);
1328 pr_debug("cmdreq: cmd=0x%04x parm0=0x%04x parm1=0x%04x parm2=0x%04x\n",
1329 cmd->cmd, cmd->parm0, cmd->parm1, cmd->parm2);
1331 ctlx->reapable = mode;
1332 ctlx->cmdcb = cmdcb;
1333 ctlx->usercb = usercb;
1334 ctlx->usercb_data = usercb_data;
1336 result = hfa384x_usbctlx_submit(hw, ctlx);
1339 } else if (mode == DOWAIT) {
1340 struct usbctlx_cmd_completor cmd_completor;
1341 struct usbctlx_completor *completor;
1343 completor = init_cmd_completor(&cmd_completor,
1344 &ctlx->inbuf.cmdresp,
1347 result = hfa384x_usbctlx_complete_sync(hw, ctlx, completor);
1354 /*----------------------------------------------------------------
1357 * Constructs a read rid CTLX and issues it.
1359 * NOTE: Any changes to the 'post-submit' code in this function
1360 * need to be carried over to hfa384x_cbrrid() since the handling
1361 * is virtually identical.
1364 * hw device structure
1365 * mode DOWAIT or DOASYNC
1366 * rid Read RID number (host order)
1367 * riddata Caller supplied buffer that MAC formatted RID.data
1368 * record will be written to for DOWAIT calls. Should
1369 * be NULL for DOASYNC calls.
1370 * riddatalen Buffer length for DOWAIT calls. Zero for DOASYNC calls.
1371 * cmdcb command callback for async calls, NULL for DOWAIT calls
1372 * usercb user callback for async calls, NULL for DOWAIT calls
1373 * usercb_data user supplied data pointer for async calls, NULL
1379 * -ERESTARTSYS Awakened on signal
1380 * -ENODATA riddatalen != macdatalen
1381 * >0 command indicated error, Status and Resp0-2 are
1387 * interrupt (DOASYNC)
1388 * process (DOWAIT or DOASYNC)
1389 *----------------------------------------------------------------
1392 hfa384x_dorrid(struct hfa384x *hw,
1396 unsigned int riddatalen,
1397 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1400 struct hfa384x_usbctlx *ctlx;
1402 ctlx = usbctlx_alloc();
1408 /* Initialize the command */
1409 ctlx->outbuf.rridreq.type = cpu_to_le16(HFA384x_USB_RRIDREQ);
1410 ctlx->outbuf.rridreq.frmlen =
1411 cpu_to_le16(sizeof(ctlx->outbuf.rridreq.rid));
1412 ctlx->outbuf.rridreq.rid = cpu_to_le16(rid);
1414 ctlx->outbufsize = sizeof(ctlx->outbuf.rridreq);
1416 ctlx->reapable = mode;
1417 ctlx->cmdcb = cmdcb;
1418 ctlx->usercb = usercb;
1419 ctlx->usercb_data = usercb_data;
1421 /* Submit the CTLX */
1422 result = hfa384x_usbctlx_submit(hw, ctlx);
1425 } else if (mode == DOWAIT) {
1426 struct usbctlx_rrid_completor completor;
1429 hfa384x_usbctlx_complete_sync(hw, ctlx,
1432 &ctlx->inbuf.rridresp,
1433 riddata, riddatalen));
1440 /*----------------------------------------------------------------
1443 * Constructs a write rid CTLX and issues it.
1445 * NOTE: Any changes to the 'post-submit' code in this function
1446 * need to be carried over to hfa384x_cbwrid() since the handling
1447 * is virtually identical.
1450 * hw device structure
1451 * enum cmd_mode DOWAIT or DOASYNC
1453 * riddata Data portion of RID formatted for MAC
1454 * riddatalen Length of the data portion in bytes
1455 * cmdcb command callback for async calls, NULL for DOWAIT calls
1456 * usercb user callback for async calls, NULL for DOWAIT calls
1457 * usercb_data user supplied data pointer for async calls
1461 * -ETIMEDOUT timed out waiting for register ready or
1462 * command completion
1463 * >0 command indicated error, Status and Resp0-2 are
1469 * interrupt (DOASYNC)
1470 * process (DOWAIT or DOASYNC)
1471 *----------------------------------------------------------------
1474 hfa384x_dowrid(struct hfa384x *hw,
1478 unsigned int riddatalen,
1479 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1482 struct hfa384x_usbctlx *ctlx;
1484 ctlx = usbctlx_alloc();
1490 /* Initialize the command */
1491 ctlx->outbuf.wridreq.type = cpu_to_le16(HFA384x_USB_WRIDREQ);
1492 ctlx->outbuf.wridreq.frmlen = cpu_to_le16((sizeof
1493 (ctlx->outbuf.wridreq.rid) +
1494 riddatalen + 1) / 2);
1495 ctlx->outbuf.wridreq.rid = cpu_to_le16(rid);
1496 memcpy(ctlx->outbuf.wridreq.data, riddata, riddatalen);
1498 ctlx->outbufsize = sizeof(ctlx->outbuf.wridreq.type) +
1499 sizeof(ctlx->outbuf.wridreq.frmlen) +
1500 sizeof(ctlx->outbuf.wridreq.rid) + riddatalen;
1502 ctlx->reapable = mode;
1503 ctlx->cmdcb = cmdcb;
1504 ctlx->usercb = usercb;
1505 ctlx->usercb_data = usercb_data;
1507 /* Submit the CTLX */
1508 result = hfa384x_usbctlx_submit(hw, ctlx);
1511 } else if (mode == DOWAIT) {
1512 struct usbctlx_cmd_completor completor;
1513 struct hfa384x_cmdresult wridresult;
1515 result = hfa384x_usbctlx_complete_sync(hw,
1519 &ctlx->inbuf.wridresp,
1527 /*----------------------------------------------------------------
1530 * Constructs a readmem CTLX and issues it.
1532 * NOTE: Any changes to the 'post-submit' code in this function
1533 * need to be carried over to hfa384x_cbrmem() since the handling
1534 * is virtually identical.
1537 * hw device structure
1538 * mode DOWAIT or DOASYNC
1539 * page MAC address space page (CMD format)
1540 * offset MAC address space offset
1541 * data Ptr to data buffer to receive read
1542 * len Length of the data to read (max == 2048)
1543 * cmdcb command callback for async calls, NULL for DOWAIT calls
1544 * usercb user callback for async calls, NULL for DOWAIT calls
1545 * usercb_data user supplied data pointer for async calls
1549 * -ETIMEDOUT timed out waiting for register ready or
1550 * command completion
1551 * >0 command indicated error, Status and Resp0-2 are
1557 * interrupt (DOASYNC)
1558 * process (DOWAIT or DOASYNC)
1559 *----------------------------------------------------------------
1562 hfa384x_dormem(struct hfa384x *hw,
1568 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1571 struct hfa384x_usbctlx *ctlx;
1573 ctlx = usbctlx_alloc();
1579 /* Initialize the command */
1580 ctlx->outbuf.rmemreq.type = cpu_to_le16(HFA384x_USB_RMEMREQ);
1581 ctlx->outbuf.rmemreq.frmlen =
1582 cpu_to_le16(sizeof(ctlx->outbuf.rmemreq.offset) +
1583 sizeof(ctlx->outbuf.rmemreq.page) + len);
1584 ctlx->outbuf.rmemreq.offset = cpu_to_le16(offset);
1585 ctlx->outbuf.rmemreq.page = cpu_to_le16(page);
1587 ctlx->outbufsize = sizeof(ctlx->outbuf.rmemreq);
1589 pr_debug("type=0x%04x frmlen=%d offset=0x%04x page=0x%04x\n",
1590 ctlx->outbuf.rmemreq.type,
1591 ctlx->outbuf.rmemreq.frmlen,
1592 ctlx->outbuf.rmemreq.offset, ctlx->outbuf.rmemreq.page);
1594 pr_debug("pktsize=%zd\n", ROUNDUP64(sizeof(ctlx->outbuf.rmemreq)));
1596 ctlx->reapable = mode;
1597 ctlx->cmdcb = cmdcb;
1598 ctlx->usercb = usercb;
1599 ctlx->usercb_data = usercb_data;
1601 result = hfa384x_usbctlx_submit(hw, ctlx);
1604 } else if (mode == DOWAIT) {
1605 struct usbctlx_rmem_completor completor;
1608 hfa384x_usbctlx_complete_sync(hw, ctlx,
1611 &ctlx->inbuf.rmemresp, data,
1619 /*----------------------------------------------------------------
1622 * Constructs a writemem CTLX and issues it.
1624 * NOTE: Any changes to the 'post-submit' code in this function
1625 * need to be carried over to hfa384x_cbwmem() since the handling
1626 * is virtually identical.
1629 * hw device structure
1630 * mode DOWAIT or DOASYNC
1631 * page MAC address space page (CMD format)
1632 * offset MAC address space offset
1633 * data Ptr to data buffer containing write data
1634 * len Length of the data to read (max == 2048)
1635 * cmdcb command callback for async calls, NULL for DOWAIT calls
1636 * usercb user callback for async calls, NULL for DOWAIT calls
1637 * usercb_data user supplied data pointer for async calls.
1641 * -ETIMEDOUT timed out waiting for register ready or
1642 * command completion
1643 * >0 command indicated error, Status and Resp0-2 are
1649 * interrupt (DOWAIT)
1650 * process (DOWAIT or DOASYNC)
1651 *----------------------------------------------------------------
1654 hfa384x_dowmem(struct hfa384x *hw,
1660 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1663 struct hfa384x_usbctlx *ctlx;
1665 pr_debug("page=0x%04x offset=0x%04x len=%d\n", page, offset, len);
1667 ctlx = usbctlx_alloc();
1673 /* Initialize the command */
1674 ctlx->outbuf.wmemreq.type = cpu_to_le16(HFA384x_USB_WMEMREQ);
1675 ctlx->outbuf.wmemreq.frmlen =
1676 cpu_to_le16(sizeof(ctlx->outbuf.wmemreq.offset) +
1677 sizeof(ctlx->outbuf.wmemreq.page) + len);
1678 ctlx->outbuf.wmemreq.offset = cpu_to_le16(offset);
1679 ctlx->outbuf.wmemreq.page = cpu_to_le16(page);
1680 memcpy(ctlx->outbuf.wmemreq.data, data, len);
1682 ctlx->outbufsize = sizeof(ctlx->outbuf.wmemreq.type) +
1683 sizeof(ctlx->outbuf.wmemreq.frmlen) +
1684 sizeof(ctlx->outbuf.wmemreq.offset) +
1685 sizeof(ctlx->outbuf.wmemreq.page) + len;
1687 ctlx->reapable = mode;
1688 ctlx->cmdcb = cmdcb;
1689 ctlx->usercb = usercb;
1690 ctlx->usercb_data = usercb_data;
1692 result = hfa384x_usbctlx_submit(hw, ctlx);
1695 } else if (mode == DOWAIT) {
1696 struct usbctlx_cmd_completor completor;
1697 struct hfa384x_cmdresult wmemresult;
1699 result = hfa384x_usbctlx_complete_sync(hw,
1703 &ctlx->inbuf.wmemresp,
1711 /*----------------------------------------------------------------
1712 * hfa384x_drvr_disable
1714 * Issues the disable command to stop communications on one of
1715 * the MACs 'ports'. Only macport 0 is valid for stations.
1716 * APs may also disable macports 1-6. Only ports that have been
1717 * previously enabled may be disabled.
1720 * hw device structure
1721 * macport MAC port number (host order)
1725 * >0 f/w reported failure - f/w status code
1726 * <0 driver reported error (timeout|bad arg)
1732 *----------------------------------------------------------------
1734 int hfa384x_drvr_disable(struct hfa384x *hw, u16 macport)
1738 if ((!hw->isap && macport != 0) ||
1739 (hw->isap && !(macport <= HFA384x_PORTID_MAX)) ||
1740 !(hw->port_enabled[macport])) {
1743 result = hfa384x_cmd_disable(hw, macport);
1745 hw->port_enabled[macport] = 0;
1750 /*----------------------------------------------------------------
1751 * hfa384x_drvr_enable
1753 * Issues the enable command to enable communications on one of
1754 * the MACs 'ports'. Only macport 0 is valid for stations.
1755 * APs may also enable macports 1-6. Only ports that are currently
1756 * disabled may be enabled.
1759 * hw device structure
1760 * macport MAC port number
1764 * >0 f/w reported failure - f/w status code
1765 * <0 driver reported error (timeout|bad arg)
1771 *----------------------------------------------------------------
1773 int hfa384x_drvr_enable(struct hfa384x *hw, u16 macport)
1777 if ((!hw->isap && macport != 0) ||
1778 (hw->isap && !(macport <= HFA384x_PORTID_MAX)) ||
1779 (hw->port_enabled[macport])) {
1782 result = hfa384x_cmd_enable(hw, macport);
1784 hw->port_enabled[macport] = 1;
1789 /*----------------------------------------------------------------
1790 * hfa384x_drvr_flashdl_enable
1792 * Begins the flash download state. Checks to see that we're not
1793 * already in a download state and that a port isn't enabled.
1794 * Sets the download state and retrieves the flash download
1795 * buffer location, buffer size, and timeout length.
1798 * hw device structure
1802 * >0 f/w reported error - f/w status code
1803 * <0 driver reported error
1809 *----------------------------------------------------------------
1811 int hfa384x_drvr_flashdl_enable(struct hfa384x *hw)
1816 /* Check that a port isn't active */
1817 for (i = 0; i < HFA384x_PORTID_MAX; i++) {
1818 if (hw->port_enabled[i]) {
1819 pr_debug("called when port enabled.\n");
1824 /* Check that we're not already in a download state */
1825 if (hw->dlstate != HFA384x_DLSTATE_DISABLED)
1828 /* Retrieve the buffer loc&size and timeout */
1829 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_DOWNLOADBUFFER,
1830 &hw->bufinfo, sizeof(hw->bufinfo));
1834 le16_to_cpus(&hw->bufinfo.page);
1835 le16_to_cpus(&hw->bufinfo.offset);
1836 le16_to_cpus(&hw->bufinfo.len);
1837 result = hfa384x_drvr_getconfig16(hw, HFA384x_RID_MAXLOADTIME,
1842 le16_to_cpus(&hw->dltimeout);
1844 pr_debug("flashdl_enable\n");
1846 hw->dlstate = HFA384x_DLSTATE_FLASHENABLED;
1851 /*----------------------------------------------------------------
1852 * hfa384x_drvr_flashdl_disable
1854 * Ends the flash download state. Note that this will cause the MAC
1855 * firmware to restart.
1858 * hw device structure
1862 * >0 f/w reported error - f/w status code
1863 * <0 driver reported error
1869 *----------------------------------------------------------------
1871 int hfa384x_drvr_flashdl_disable(struct hfa384x *hw)
1873 /* Check that we're already in the download state */
1874 if (hw->dlstate != HFA384x_DLSTATE_FLASHENABLED)
1877 pr_debug("flashdl_enable\n");
1879 /* There isn't much we can do at this point, so I don't */
1880 /* bother w/ the return value */
1881 hfa384x_cmd_download(hw, HFA384x_PROGMODE_DISABLE, 0, 0, 0);
1882 hw->dlstate = HFA384x_DLSTATE_DISABLED;
1887 /*----------------------------------------------------------------
1888 * hfa384x_drvr_flashdl_write
1890 * Performs a FLASH download of a chunk of data. First checks to see
1891 * that we're in the FLASH download state, then sets the download
1892 * mode, uses the aux functions to 1) copy the data to the flash
1893 * buffer, 2) sets the download 'write flash' mode, 3) readback and
1894 * compare. Lather rinse, repeat as many times an necessary to get
1895 * all the given data into flash.
1896 * When all data has been written using this function (possibly
1897 * repeatedly), call drvr_flashdl_disable() to end the download state
1898 * and restart the MAC.
1901 * hw device structure
1902 * daddr Card address to write to. (host order)
1903 * buf Ptr to data to write.
1904 * len Length of data (host order).
1908 * >0 f/w reported error - f/w status code
1909 * <0 driver reported error
1915 *----------------------------------------------------------------
1917 int hfa384x_drvr_flashdl_write(struct hfa384x *hw, u32 daddr,
1935 pr_debug("daddr=0x%08x len=%d\n", daddr, len);
1937 /* Check that we're in the flash download state */
1938 if (hw->dlstate != HFA384x_DLSTATE_FLASHENABLED)
1941 netdev_info(hw->wlandev->netdev,
1942 "Download %d bytes to flash @0x%06x\n", len, daddr);
1944 /* Convert to flat address for arithmetic */
1945 /* NOTE: dlbuffer RID stores the address in AUX format */
1947 HFA384x_ADDR_AUX_MKFLAT(hw->bufinfo.page, hw->bufinfo.offset);
1948 pr_debug("dlbuf.page=0x%04x dlbuf.offset=0x%04x dlbufaddr=0x%08x\n",
1949 hw->bufinfo.page, hw->bufinfo.offset, dlbufaddr);
1950 /* Calculations to determine how many fills of the dlbuffer to do
1951 * and how many USB wmemreq's to do for each fill. At this point
1952 * in time, the dlbuffer size and the wmemreq size are the same.
1953 * Therefore, nwrites should always be 1. The extra complexity
1954 * here is a hedge against future changes.
1957 /* Figure out how many times to do the flash programming */
1958 nburns = len / hw->bufinfo.len;
1959 nburns += (len % hw->bufinfo.len) ? 1 : 0;
1961 /* For each flash program cycle, how many USB wmemreq's are needed? */
1962 nwrites = hw->bufinfo.len / HFA384x_USB_RWMEM_MAXLEN;
1963 nwrites += (hw->bufinfo.len % HFA384x_USB_RWMEM_MAXLEN) ? 1 : 0;
1966 for (i = 0; i < nburns; i++) {
1967 /* Get the dest address and len */
1968 burnlen = (len - (hw->bufinfo.len * i)) > hw->bufinfo.len ?
1969 hw->bufinfo.len : (len - (hw->bufinfo.len * i));
1970 burndaddr = daddr + (hw->bufinfo.len * i);
1971 burnlo = HFA384x_ADDR_CMD_MKOFF(burndaddr);
1972 burnhi = HFA384x_ADDR_CMD_MKPAGE(burndaddr);
1974 netdev_info(hw->wlandev->netdev, "Writing %d bytes to flash @0x%06x\n",
1975 burnlen, burndaddr);
1977 /* Set the download mode */
1978 result = hfa384x_cmd_download(hw, HFA384x_PROGMODE_NV,
1979 burnlo, burnhi, burnlen);
1981 netdev_err(hw->wlandev->netdev,
1982 "download(NV,lo=%x,hi=%x,len=%x) cmd failed, result=%d. Aborting d/l\n",
1983 burnlo, burnhi, burnlen, result);
1987 /* copy the data to the flash download buffer */
1988 for (j = 0; j < nwrites; j++) {
1990 (i * hw->bufinfo.len) +
1991 (j * HFA384x_USB_RWMEM_MAXLEN);
1993 writepage = HFA384x_ADDR_CMD_MKPAGE(dlbufaddr +
1994 (j * HFA384x_USB_RWMEM_MAXLEN));
1995 writeoffset = HFA384x_ADDR_CMD_MKOFF(dlbufaddr +
1996 (j * HFA384x_USB_RWMEM_MAXLEN));
1998 writelen = burnlen - (j * HFA384x_USB_RWMEM_MAXLEN);
1999 writelen = writelen > HFA384x_USB_RWMEM_MAXLEN ?
2000 HFA384x_USB_RWMEM_MAXLEN : writelen;
2002 result = hfa384x_dowmem_wait(hw,
2005 writebuf, writelen);
2008 /* set the download 'write flash' mode */
2009 result = hfa384x_cmd_download(hw,
2010 HFA384x_PROGMODE_NVWRITE,
2013 netdev_err(hw->wlandev->netdev,
2014 "download(NVWRITE,lo=%x,hi=%x,len=%x) cmd failed, result=%d. Aborting d/l\n",
2015 burnlo, burnhi, burnlen, result);
2019 /* TODO: We really should do a readback and compare. */
2024 /* Leave the firmware in the 'post-prog' mode. flashdl_disable will */
2025 /* actually disable programming mode. Remember, that will cause the */
2026 /* the firmware to effectively reset itself. */
2031 /*----------------------------------------------------------------
2032 * hfa384x_drvr_getconfig
2034 * Performs the sequence necessary to read a config/info item.
2037 * hw device structure
2038 * rid config/info record id (host order)
2039 * buf host side record buffer. Upon return it will
2040 * contain the body portion of the record (minus the
2042 * len buffer length (in bytes, should match record length)
2046 * >0 f/w reported error - f/w status code
2047 * <0 driver reported error
2048 * -ENODATA length mismatch between argument and retrieved
2055 *----------------------------------------------------------------
2057 int hfa384x_drvr_getconfig(struct hfa384x *hw, u16 rid, void *buf, u16 len)
2059 return hfa384x_dorrid_wait(hw, rid, buf, len);
2062 /*----------------------------------------------------------------
2063 * hfa384x_drvr_setconfig_async
2065 * Performs the sequence necessary to write a config/info item.
2068 * hw device structure
2069 * rid config/info record id (in host order)
2070 * buf host side record buffer
2071 * len buffer length (in bytes)
2072 * usercb completion callback
2073 * usercb_data completion callback argument
2077 * >0 f/w reported error - f/w status code
2078 * <0 driver reported error
2084 *----------------------------------------------------------------
2087 hfa384x_drvr_setconfig_async(struct hfa384x *hw,
2090 u16 len, ctlx_usercb_t usercb, void *usercb_data)
2092 return hfa384x_dowrid_async(hw, rid, buf, len,
2093 hfa384x_cb_status, usercb, usercb_data);
2096 /*----------------------------------------------------------------
2097 * hfa384x_drvr_ramdl_disable
2099 * Ends the ram download state.
2102 * hw device structure
2106 * >0 f/w reported error - f/w status code
2107 * <0 driver reported error
2113 *----------------------------------------------------------------
2115 int hfa384x_drvr_ramdl_disable(struct hfa384x *hw)
2117 /* Check that we're already in the download state */
2118 if (hw->dlstate != HFA384x_DLSTATE_RAMENABLED)
2121 pr_debug("ramdl_disable()\n");
2123 /* There isn't much we can do at this point, so I don't */
2124 /* bother w/ the return value */
2125 hfa384x_cmd_download(hw, HFA384x_PROGMODE_DISABLE, 0, 0, 0);
2126 hw->dlstate = HFA384x_DLSTATE_DISABLED;
2131 /*----------------------------------------------------------------
2132 * hfa384x_drvr_ramdl_enable
2134 * Begins the ram download state. Checks to see that we're not
2135 * already in a download state and that a port isn't enabled.
2136 * Sets the download state and calls cmd_download with the
2137 * ENABLE_VOLATILE subcommand and the exeaddr argument.
2140 * hw device structure
2141 * exeaddr the card execution address that will be
2142 * jumped to when ramdl_disable() is called
2147 * >0 f/w reported error - f/w status code
2148 * <0 driver reported error
2154 *----------------------------------------------------------------
2156 int hfa384x_drvr_ramdl_enable(struct hfa384x *hw, u32 exeaddr)
2163 /* Check that a port isn't active */
2164 for (i = 0; i < HFA384x_PORTID_MAX; i++) {
2165 if (hw->port_enabled[i]) {
2166 netdev_err(hw->wlandev->netdev,
2167 "Can't download with a macport enabled.\n");
2172 /* Check that we're not already in a download state */
2173 if (hw->dlstate != HFA384x_DLSTATE_DISABLED) {
2174 netdev_err(hw->wlandev->netdev,
2175 "Download state not disabled.\n");
2179 pr_debug("ramdl_enable, exeaddr=0x%08x\n", exeaddr);
2181 /* Call the download(1,addr) function */
2182 lowaddr = HFA384x_ADDR_CMD_MKOFF(exeaddr);
2183 hiaddr = HFA384x_ADDR_CMD_MKPAGE(exeaddr);
2185 result = hfa384x_cmd_download(hw, HFA384x_PROGMODE_RAM,
2186 lowaddr, hiaddr, 0);
2189 /* Set the download state */
2190 hw->dlstate = HFA384x_DLSTATE_RAMENABLED;
2192 pr_debug("cmd_download(0x%04x, 0x%04x) failed, result=%d.\n",
2193 lowaddr, hiaddr, result);
2199 /*----------------------------------------------------------------
2200 * hfa384x_drvr_ramdl_write
2202 * Performs a RAM download of a chunk of data. First checks to see
2203 * that we're in the RAM download state, then uses the [read|write]mem USB
2204 * commands to 1) copy the data, 2) readback and compare. The download
2205 * state is unaffected. When all data has been written using
2206 * this function, call drvr_ramdl_disable() to end the download state
2207 * and restart the MAC.
2210 * hw device structure
2211 * daddr Card address to write to. (host order)
2212 * buf Ptr to data to write.
2213 * len Length of data (host order).
2217 * >0 f/w reported error - f/w status code
2218 * <0 driver reported error
2224 *----------------------------------------------------------------
2226 int hfa384x_drvr_ramdl_write(struct hfa384x *hw, u32 daddr, void *buf, u32 len)
2237 /* Check that we're in the ram download state */
2238 if (hw->dlstate != HFA384x_DLSTATE_RAMENABLED)
2241 netdev_info(hw->wlandev->netdev, "Writing %d bytes to ram @0x%06x\n",
2244 /* How many dowmem calls? */
2245 nwrites = len / HFA384x_USB_RWMEM_MAXLEN;
2246 nwrites += len % HFA384x_USB_RWMEM_MAXLEN ? 1 : 0;
2248 /* Do blocking wmem's */
2249 for (i = 0; i < nwrites; i++) {
2250 /* make address args */
2251 curraddr = daddr + (i * HFA384x_USB_RWMEM_MAXLEN);
2252 currpage = HFA384x_ADDR_CMD_MKPAGE(curraddr);
2253 curroffset = HFA384x_ADDR_CMD_MKOFF(curraddr);
2254 currlen = len - (i * HFA384x_USB_RWMEM_MAXLEN);
2255 if (currlen > HFA384x_USB_RWMEM_MAXLEN)
2256 currlen = HFA384x_USB_RWMEM_MAXLEN;
2258 /* Do blocking ctlx */
2259 result = hfa384x_dowmem_wait(hw,
2263 (i * HFA384x_USB_RWMEM_MAXLEN),
2269 /* TODO: We really should have a readback. */
2275 /*----------------------------------------------------------------
2276 * hfa384x_drvr_readpda
2278 * Performs the sequence to read the PDA space. Note there is no
2279 * drvr_writepda() function. Writing a PDA is
2280 * generally implemented by a calling component via calls to
2281 * cmd_download and writing to the flash download buffer via the
2285 * hw device structure
2286 * buf buffer to store PDA in
2291 * >0 f/w reported error - f/w status code
2292 * <0 driver reported error
2293 * -ETIMEDOUT timeout waiting for the cmd regs to become
2294 * available, or waiting for the control reg
2295 * to indicate the Aux port is enabled.
2296 * -ENODATA the buffer does NOT contain a valid PDA.
2297 * Either the card PDA is bad, or the auxdata
2298 * reads are giving us garbage.
2304 * process or non-card interrupt.
2305 *----------------------------------------------------------------
2307 int hfa384x_drvr_readpda(struct hfa384x *hw, void *buf, unsigned int len)
2313 int currpdr = 0; /* word offset of the current pdr */
2315 u16 pdrlen; /* pdr length in bytes, host order */
2316 u16 pdrcode; /* pdr code, host order */
2324 HFA3842_PDA_BASE, 0}, {
2325 HFA3841_PDA_BASE, 0}, {
2326 HFA3841_PDA_BOGUS_BASE, 0}
2329 /* Read the pda from each known address. */
2330 for (i = 0; i < ARRAY_SIZE(pdaloc); i++) {
2332 currpage = HFA384x_ADDR_CMD_MKPAGE(pdaloc[i].cardaddr);
2333 curroffset = HFA384x_ADDR_CMD_MKOFF(pdaloc[i].cardaddr);
2335 /* units of bytes */
2336 result = hfa384x_dormem_wait(hw, currpage, curroffset, buf,
2340 netdev_warn(hw->wlandev->netdev,
2341 "Read from index %zd failed, continuing\n",
2346 /* Test for garbage */
2347 pdaok = 1; /* initially assume good */
2349 while (pdaok && morepdrs) {
2350 pdrlen = le16_to_cpu(pda[currpdr]) * 2;
2351 pdrcode = le16_to_cpu(pda[currpdr + 1]);
2352 /* Test the record length */
2353 if (pdrlen > HFA384x_PDR_LEN_MAX || pdrlen == 0) {
2354 netdev_err(hw->wlandev->netdev,
2355 "pdrlen invalid=%d\n", pdrlen);
2360 if (!hfa384x_isgood_pdrcode(pdrcode)) {
2361 netdev_err(hw->wlandev->netdev, "pdrcode invalid=%d\n",
2366 /* Test for completion */
2367 if (pdrcode == HFA384x_PDR_END_OF_PDA)
2370 /* Move to the next pdr (if necessary) */
2372 /* note the access to pda[], need words here */
2373 currpdr += le16_to_cpu(pda[currpdr]) + 1;
2377 netdev_info(hw->wlandev->netdev,
2378 "PDA Read from 0x%08x in %s space.\n",
2380 pdaloc[i].auxctl == 0 ? "EXTDS" :
2381 pdaloc[i].auxctl == 1 ? "NV" :
2382 pdaloc[i].auxctl == 2 ? "PHY" :
2383 pdaloc[i].auxctl == 3 ? "ICSRAM" :
2388 result = pdaok ? 0 : -ENODATA;
2391 pr_debug("Failure: pda is not okay\n");
2396 /*----------------------------------------------------------------
2397 * hfa384x_drvr_setconfig
2399 * Performs the sequence necessary to write a config/info item.
2402 * hw device structure
2403 * rid config/info record id (in host order)
2404 * buf host side record buffer
2405 * len buffer length (in bytes)
2409 * >0 f/w reported error - f/w status code
2410 * <0 driver reported error
2416 *----------------------------------------------------------------
2418 int hfa384x_drvr_setconfig(struct hfa384x *hw, u16 rid, void *buf, u16 len)
2420 return hfa384x_dowrid_wait(hw, rid, buf, len);
2423 /*----------------------------------------------------------------
2424 * hfa384x_drvr_start
2426 * Issues the MAC initialize command, sets up some data structures,
2427 * and enables the interrupts. After this function completes, the
2428 * low-level stuff should be ready for any/all commands.
2431 * hw device structure
2434 * >0 f/w reported error - f/w status code
2435 * <0 driver reported error
2441 *----------------------------------------------------------------
2443 int hfa384x_drvr_start(struct hfa384x *hw)
2445 int result, result1, result2;
2450 /* Clear endpoint stalls - but only do this if the endpoint
2451 * is showing a stall status. Some prism2 cards seem to behave
2452 * badly if a clear_halt is called when the endpoint is already
2456 usb_get_std_status(hw->usb, USB_RECIP_ENDPOINT, hw->endp_in,
2459 netdev_err(hw->wlandev->netdev, "Cannot get bulk in endpoint status.\n");
2462 if ((status == 1) && usb_clear_halt(hw->usb, hw->endp_in))
2463 netdev_err(hw->wlandev->netdev, "Failed to reset bulk in endpoint.\n");
2466 usb_get_std_status(hw->usb, USB_RECIP_ENDPOINT, hw->endp_out,
2469 netdev_err(hw->wlandev->netdev, "Cannot get bulk out endpoint status.\n");
2472 if ((status == 1) && usb_clear_halt(hw->usb, hw->endp_out))
2473 netdev_err(hw->wlandev->netdev, "Failed to reset bulk out endpoint.\n");
2475 /* Synchronous unlink, in case we're trying to restart the driver */
2476 usb_kill_urb(&hw->rx_urb);
2478 /* Post the IN urb */
2479 result = submit_rx_urb(hw, GFP_KERNEL);
2481 netdev_err(hw->wlandev->netdev,
2482 "Fatal, failed to submit RX URB, result=%d\n",
2487 /* Call initialize twice, with a 1 second sleep in between.
2488 * This is a nasty work-around since many prism2 cards seem to
2489 * need time to settle after an init from cold. The second
2490 * call to initialize in theory is not necessary - but we call
2491 * it anyway as a double insurance policy:
2492 * 1) If the first init should fail, the second may well succeed
2493 * and the card can still be used
2494 * 2) It helps ensures all is well with the card after the first
2495 * init and settle time.
2497 result1 = hfa384x_cmd_initialize(hw);
2499 result = hfa384x_cmd_initialize(hw);
2503 netdev_err(hw->wlandev->netdev,
2504 "cmd_initialize() failed on two attempts, results %d and %d\n",
2506 usb_kill_urb(&hw->rx_urb);
2509 pr_debug("First cmd_initialize() failed (result %d),\n",
2511 pr_debug("but second attempt succeeded. All should be ok\n");
2513 } else if (result2 != 0) {
2514 netdev_warn(hw->wlandev->netdev, "First cmd_initialize() succeeded, but second attempt failed (result=%d)\n",
2516 netdev_warn(hw->wlandev->netdev,
2517 "Most likely the card will be functional\n");
2521 hw->state = HFA384x_STATE_RUNNING;
2527 /*----------------------------------------------------------------
2530 * Shuts down the MAC to the point where it is safe to unload the
2531 * driver. Any subsystem that may be holding a data or function
2532 * ptr into the driver must be cleared/deinitialized.
2535 * hw device structure
2538 * >0 f/w reported error - f/w status code
2539 * <0 driver reported error
2545 *----------------------------------------------------------------
2547 int hfa384x_drvr_stop(struct hfa384x *hw)
2553 /* There's no need for spinlocks here. The USB "disconnect"
2554 * function sets this "removed" flag and then calls us.
2556 if (!hw->wlandev->hwremoved) {
2557 /* Call initialize to leave the MAC in its 'reset' state */
2558 hfa384x_cmd_initialize(hw);
2560 /* Cancel the rxurb */
2561 usb_kill_urb(&hw->rx_urb);
2564 hw->link_status = HFA384x_LINK_NOTCONNECTED;
2565 hw->state = HFA384x_STATE_INIT;
2567 del_timer_sync(&hw->commsqual_timer);
2569 /* Clear all the port status */
2570 for (i = 0; i < HFA384x_NUMPORTS_MAX; i++)
2571 hw->port_enabled[i] = 0;
2576 /*----------------------------------------------------------------
2577 * hfa384x_drvr_txframe
2579 * Takes a frame from prism2sta and queues it for transmission.
2582 * hw device structure
2583 * skb packet buffer struct. Contains an 802.11
2585 * p80211_hdr points to the 802.11 header for the packet.
2587 * 0 Success and more buffs available
2588 * 1 Success but no more buffs
2589 * 2 Allocation failure
2590 * 4 Buffer full or queue busy
2596 *----------------------------------------------------------------
2598 int hfa384x_drvr_txframe(struct hfa384x *hw, struct sk_buff *skb,
2599 union p80211_hdr *p80211_hdr,
2600 struct p80211_metawep *p80211_wep)
2602 int usbpktlen = sizeof(struct hfa384x_tx_frame);
2607 if (hw->tx_urb.status == -EINPROGRESS) {
2608 netdev_warn(hw->wlandev->netdev, "TX URB already in use\n");
2613 /* Build Tx frame structure */
2614 /* Set up the control field */
2615 memset(&hw->txbuff.txfrm.desc, 0, sizeof(hw->txbuff.txfrm.desc));
2617 /* Setup the usb type field */
2618 hw->txbuff.type = cpu_to_le16(HFA384x_USB_TXFRM);
2620 /* Set up the sw_support field to identify this frame */
2621 hw->txbuff.txfrm.desc.sw_support = 0x0123;
2623 /* Tx complete and Tx exception disable per dleach. Might be causing
2626 /* #define DOEXC SLP -- doboth breaks horribly under load, doexc less so. */
2628 hw->txbuff.txfrm.desc.tx_control =
2629 HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
2630 HFA384x_TX_TXEX_SET(1) | HFA384x_TX_TXOK_SET(1);
2631 #elif defined(DOEXC)
2632 hw->txbuff.txfrm.desc.tx_control =
2633 HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
2634 HFA384x_TX_TXEX_SET(1) | HFA384x_TX_TXOK_SET(0);
2636 hw->txbuff.txfrm.desc.tx_control =
2637 HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
2638 HFA384x_TX_TXEX_SET(0) | HFA384x_TX_TXOK_SET(0);
2640 cpu_to_le16s(&hw->txbuff.txfrm.desc.tx_control);
2642 /* copy the header over to the txdesc */
2643 memcpy(&hw->txbuff.txfrm.desc.frame_control, p80211_hdr,
2644 sizeof(union p80211_hdr));
2646 /* if we're using host WEP, increase size by IV+ICV */
2647 if (p80211_wep->data) {
2648 hw->txbuff.txfrm.desc.data_len = cpu_to_le16(skb->len + 8);
2651 hw->txbuff.txfrm.desc.data_len = cpu_to_le16(skb->len);
2654 usbpktlen += skb->len;
2656 /* copy over the WEP IV if we are using host WEP */
2657 ptr = hw->txbuff.txfrm.data;
2658 if (p80211_wep->data) {
2659 memcpy(ptr, p80211_wep->iv, sizeof(p80211_wep->iv));
2660 ptr += sizeof(p80211_wep->iv);
2661 memcpy(ptr, p80211_wep->data, skb->len);
2663 memcpy(ptr, skb->data, skb->len);
2665 /* copy over the packet data */
2668 /* copy over the WEP ICV if we are using host WEP */
2669 if (p80211_wep->data)
2670 memcpy(ptr, p80211_wep->icv, sizeof(p80211_wep->icv));
2672 /* Send the USB packet */
2673 usb_fill_bulk_urb(&hw->tx_urb, hw->usb,
2675 &hw->txbuff, ROUNDUP64(usbpktlen),
2676 hfa384x_usbout_callback, hw->wlandev);
2677 hw->tx_urb.transfer_flags |= USB_QUEUE_BULK;
2680 ret = submit_tx_urb(hw, &hw->tx_urb, GFP_ATOMIC);
2682 netdev_err(hw->wlandev->netdev,
2683 "submit_tx_urb() failed, error=%d\n", ret);
2691 void hfa384x_tx_timeout(struct wlandevice *wlandev)
2693 struct hfa384x *hw = wlandev->priv;
2694 unsigned long flags;
2696 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2698 if (!hw->wlandev->hwremoved) {
2701 sched = !test_and_set_bit(WORK_TX_HALT, &hw->usb_flags);
2702 sched |= !test_and_set_bit(WORK_RX_HALT, &hw->usb_flags);
2704 schedule_work(&hw->usb_work);
2707 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2710 /*----------------------------------------------------------------
2711 * hfa384x_usbctlx_reaper_task
2713 * Tasklet to delete dead CTLX objects
2716 * data ptr to a struct hfa384x
2722 *----------------------------------------------------------------
2724 static void hfa384x_usbctlx_reaper_task(unsigned long data)
2726 struct hfa384x *hw = (struct hfa384x *)data;
2727 struct hfa384x_usbctlx *ctlx, *temp;
2728 unsigned long flags;
2730 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2732 /* This list is guaranteed to be empty if someone
2733 * has unplugged the adapter.
2735 list_for_each_entry_safe(ctlx, temp, &hw->ctlxq.reapable, list) {
2736 list_del(&ctlx->list);
2740 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2743 /*----------------------------------------------------------------
2744 * hfa384x_usbctlx_completion_task
2746 * Tasklet to call completion handlers for returned CTLXs
2749 * data ptr to struct hfa384x
2756 *----------------------------------------------------------------
2758 static void hfa384x_usbctlx_completion_task(unsigned long data)
2760 struct hfa384x *hw = (struct hfa384x *)data;
2761 struct hfa384x_usbctlx *ctlx, *temp;
2762 unsigned long flags;
2766 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2768 /* This list is guaranteed to be empty if someone
2769 * has unplugged the adapter ...
2771 list_for_each_entry_safe(ctlx, temp, &hw->ctlxq.completing, list) {
2772 /* Call the completion function that this
2773 * command was assigned, assuming it has one.
2776 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2777 ctlx->cmdcb(hw, ctlx);
2778 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2780 /* Make sure we don't try and complete
2781 * this CTLX more than once!
2785 /* Did someone yank the adapter out
2786 * while our list was (briefly) unlocked?
2788 if (hw->wlandev->hwremoved) {
2795 * "Reapable" CTLXs are ones which don't have any
2796 * threads waiting for them to die. Hence they must
2797 * be delivered to The Reaper!
2799 if (ctlx->reapable) {
2800 /* Move the CTLX off the "completing" list (hopefully)
2801 * on to the "reapable" list where the reaper task
2802 * can find it. And "reapable" means that this CTLX
2803 * isn't sitting on a wait-queue somewhere.
2805 list_move_tail(&ctlx->list, &hw->ctlxq.reapable);
2809 complete(&ctlx->done);
2811 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2814 tasklet_schedule(&hw->reaper_bh);
2817 /*----------------------------------------------------------------
2818 * unlocked_usbctlx_cancel_async
2820 * Mark the CTLX dead asynchronously, and ensure that the
2821 * next command on the queue is run afterwards.
2824 * hw ptr to the struct hfa384x structure
2825 * ctlx ptr to a CTLX structure
2828 * 0 the CTLX's URB is inactive
2829 * -EINPROGRESS the URB is currently being unlinked
2832 * Either process or interrupt, but presumably interrupt
2833 *----------------------------------------------------------------
2835 static int unlocked_usbctlx_cancel_async(struct hfa384x *hw,
2836 struct hfa384x_usbctlx *ctlx)
2841 * Try to delete the URB containing our request packet.
2842 * If we succeed, then its completion handler will be
2843 * called with a status of -ECONNRESET.
2845 hw->ctlx_urb.transfer_flags |= URB_ASYNC_UNLINK;
2846 ret = usb_unlink_urb(&hw->ctlx_urb);
2848 if (ret != -EINPROGRESS) {
2850 * The OUT URB had either already completed
2851 * or was still in the pending queue, so the
2852 * URB's completion function will not be called.
2853 * We will have to complete the CTLX ourselves.
2855 ctlx->state = CTLX_REQ_FAILED;
2856 unlocked_usbctlx_complete(hw, ctlx);
2863 /*----------------------------------------------------------------
2864 * unlocked_usbctlx_complete
2866 * A CTLX has completed. It may have been successful, it may not
2867 * have been. At this point, the CTLX should be quiescent. The URBs
2868 * aren't active and the timers should have been stopped.
2870 * The CTLX is migrated to the "completing" queue, and the completing
2871 * tasklet is scheduled.
2874 * hw ptr to a struct hfa384x structure
2875 * ctlx ptr to a ctlx structure
2883 * Either, assume interrupt
2884 *----------------------------------------------------------------
2886 static void unlocked_usbctlx_complete(struct hfa384x *hw,
2887 struct hfa384x_usbctlx *ctlx)
2889 /* Timers have been stopped, and ctlx should be in
2890 * a terminal state. Retire it from the "active"
2893 list_move_tail(&ctlx->list, &hw->ctlxq.completing);
2894 tasklet_schedule(&hw->completion_bh);
2896 switch (ctlx->state) {
2898 case CTLX_REQ_FAILED:
2899 /* This are the correct terminating states. */
2903 netdev_err(hw->wlandev->netdev, "CTLX[%d] not in a terminating state(%s)\n",
2904 le16_to_cpu(ctlx->outbuf.type),
2905 ctlxstr(ctlx->state));
2910 /*----------------------------------------------------------------
2911 * hfa384x_usbctlxq_run
2913 * Checks to see if the head item is running. If not, starts it.
2916 * hw ptr to struct hfa384x
2925 *----------------------------------------------------------------
2927 static void hfa384x_usbctlxq_run(struct hfa384x *hw)
2929 unsigned long flags;
2932 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2934 /* Only one active CTLX at any one time, because there's no
2935 * other (reliable) way to match the response URB to the
2938 * Don't touch any of these CTLXs if the hardware
2939 * has been removed or the USB subsystem is stalled.
2941 if (!list_empty(&hw->ctlxq.active) ||
2942 test_bit(WORK_TX_HALT, &hw->usb_flags) || hw->wlandev->hwremoved)
2945 while (!list_empty(&hw->ctlxq.pending)) {
2946 struct hfa384x_usbctlx *head;
2949 /* This is the first pending command */
2950 head = list_entry(hw->ctlxq.pending.next,
2951 struct hfa384x_usbctlx, list);
2953 /* We need to split this off to avoid a race condition */
2954 list_move_tail(&head->list, &hw->ctlxq.active);
2956 /* Fill the out packet */
2957 usb_fill_bulk_urb(&hw->ctlx_urb, hw->usb,
2959 &head->outbuf, ROUNDUP64(head->outbufsize),
2960 hfa384x_ctlxout_callback, hw);
2961 hw->ctlx_urb.transfer_flags |= USB_QUEUE_BULK;
2963 /* Now submit the URB and update the CTLX's state */
2964 result = usb_submit_urb(&hw->ctlx_urb, GFP_ATOMIC);
2966 /* This CTLX is now running on the active queue */
2967 head->state = CTLX_REQ_SUBMITTED;
2969 /* Start the OUT wait timer */
2970 hw->req_timer_done = 0;
2971 hw->reqtimer.expires = jiffies + HZ;
2972 add_timer(&hw->reqtimer);
2974 /* Start the IN wait timer */
2975 hw->resp_timer_done = 0;
2976 hw->resptimer.expires = jiffies + 2 * HZ;
2977 add_timer(&hw->resptimer);
2982 if (result == -EPIPE) {
2983 /* The OUT pipe needs resetting, so put
2984 * this CTLX back in the "pending" queue
2985 * and schedule a reset ...
2987 netdev_warn(hw->wlandev->netdev,
2988 "%s tx pipe stalled: requesting reset\n",
2989 hw->wlandev->netdev->name);
2990 list_move(&head->list, &hw->ctlxq.pending);
2991 set_bit(WORK_TX_HALT, &hw->usb_flags);
2992 schedule_work(&hw->usb_work);
2996 if (result == -ESHUTDOWN) {
2997 netdev_warn(hw->wlandev->netdev, "%s urb shutdown!\n",
2998 hw->wlandev->netdev->name);
3002 netdev_err(hw->wlandev->netdev, "Failed to submit CTLX[%d]: error=%d\n",
3003 le16_to_cpu(head->outbuf.type), result);
3004 unlocked_usbctlx_complete(hw, head);
3008 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3011 /*----------------------------------------------------------------
3012 * hfa384x_usbin_callback
3014 * Callback for URBs on the BULKIN endpoint.
3017 * urb ptr to the completed urb
3026 *----------------------------------------------------------------
3028 static void hfa384x_usbin_callback(struct urb *urb)
3030 struct wlandevice *wlandev = urb->context;
3032 union hfa384x_usbin *usbin;
3033 struct sk_buff *skb = NULL;
3044 if (!wlandev || !wlandev->netdev || wlandev->hwremoved)
3051 skb = hw->rx_urb_skb;
3052 if (!skb || (skb->data != urb->transfer_buffer)) {
3057 hw->rx_urb_skb = NULL;
3059 /* Check for error conditions within the URB */
3060 switch (urb->status) {
3064 /* Check for short packet */
3065 if (urb->actual_length == 0) {
3066 wlandev->netdev->stats.rx_errors++;
3067 wlandev->netdev->stats.rx_length_errors++;
3073 netdev_warn(hw->wlandev->netdev, "%s rx pipe stalled: requesting reset\n",
3074 wlandev->netdev->name);
3075 if (!test_and_set_bit(WORK_RX_HALT, &hw->usb_flags))
3076 schedule_work(&hw->usb_work);
3077 wlandev->netdev->stats.rx_errors++;
3084 if (!test_and_set_bit(THROTTLE_RX, &hw->usb_flags) &&
3085 !timer_pending(&hw->throttle)) {
3086 mod_timer(&hw->throttle, jiffies + THROTTLE_JIFFIES);
3088 wlandev->netdev->stats.rx_errors++;
3093 wlandev->netdev->stats.rx_over_errors++;
3099 pr_debug("status=%d, device removed.\n", urb->status);
3105 pr_debug("status=%d, urb explicitly unlinked.\n", urb->status);
3110 pr_debug("urb status=%d, transfer flags=0x%x\n",
3111 urb->status, urb->transfer_flags);
3112 wlandev->netdev->stats.rx_errors++;
3117 /* Save values from the RX URB before reposting overwrites it. */
3118 urb_status = urb->status;
3119 usbin = (union hfa384x_usbin *)urb->transfer_buffer;
3121 if (action != ABORT) {
3122 /* Repost the RX URB */
3123 result = submit_rx_urb(hw, GFP_ATOMIC);
3126 netdev_err(hw->wlandev->netdev,
3127 "Fatal, failed to resubmit rx_urb. error=%d\n",
3132 /* Handle any USB-IN packet */
3133 /* Note: the check of the sw_support field, the type field doesn't
3134 * have bit 12 set like the docs suggest.
3136 type = le16_to_cpu(usbin->type);
3137 if (HFA384x_USB_ISRXFRM(type)) {
3138 if (action == HANDLE) {
3139 if (usbin->txfrm.desc.sw_support == 0x0123) {
3140 hfa384x_usbin_txcompl(wlandev, usbin);
3142 skb_put(skb, sizeof(*usbin));
3143 hfa384x_usbin_rx(wlandev, skb);
3149 if (HFA384x_USB_ISTXFRM(type)) {
3150 if (action == HANDLE)
3151 hfa384x_usbin_txcompl(wlandev, usbin);
3155 case HFA384x_USB_INFOFRM:
3156 if (action == ABORT)
3158 if (action == HANDLE)
3159 hfa384x_usbin_info(wlandev, usbin);
3162 case HFA384x_USB_CMDRESP:
3163 case HFA384x_USB_WRIDRESP:
3164 case HFA384x_USB_RRIDRESP:
3165 case HFA384x_USB_WMEMRESP:
3166 case HFA384x_USB_RMEMRESP:
3167 /* ALWAYS, ALWAYS, ALWAYS handle this CTLX!!!! */
3168 hfa384x_usbin_ctlx(hw, usbin, urb_status);
3171 case HFA384x_USB_BUFAVAIL:
3172 pr_debug("Received BUFAVAIL packet, frmlen=%d\n",
3173 usbin->bufavail.frmlen);
3176 case HFA384x_USB_ERROR:
3177 pr_debug("Received USB_ERROR packet, errortype=%d\n",
3178 usbin->usberror.errortype);
3182 pr_debug("Unrecognized USBIN packet, type=%x, status=%d\n",
3183 usbin->type, urb_status);
3193 /*----------------------------------------------------------------
3194 * hfa384x_usbin_ctlx
3196 * We've received a URB containing a Prism2 "response" message.
3197 * This message needs to be matched up with a CTLX on the active
3198 * queue and our state updated accordingly.
3201 * hw ptr to struct hfa384x
3202 * usbin ptr to USB IN packet
3203 * urb_status status of this Bulk-In URB
3212 *----------------------------------------------------------------
3214 static void hfa384x_usbin_ctlx(struct hfa384x *hw, union hfa384x_usbin *usbin,
3217 struct hfa384x_usbctlx *ctlx;
3219 unsigned long flags;
3222 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3224 /* There can be only one CTLX on the active queue
3225 * at any one time, and this is the CTLX that the
3226 * timers are waiting for.
3228 if (list_empty(&hw->ctlxq.active))
3231 /* Remove the "response timeout". It's possible that
3232 * we are already too late, and that the timeout is
3233 * already running. And that's just too bad for us,
3234 * because we could lose our CTLX from the active
3237 if (del_timer(&hw->resptimer) == 0) {
3238 if (hw->resp_timer_done == 0) {
3239 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3243 hw->resp_timer_done = 1;
3246 ctlx = get_active_ctlx(hw);
3248 if (urb_status != 0) {
3250 * Bad CTLX, so get rid of it. But we only
3251 * remove it from the active queue if we're no
3252 * longer expecting the OUT URB to complete.
3254 if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0)
3257 const __le16 intype = (usbin->type & ~cpu_to_le16(0x8000));
3260 * Check that our message is what we're expecting ...
3262 if (ctlx->outbuf.type != intype) {
3263 netdev_warn(hw->wlandev->netdev,
3264 "Expected IN[%d], received IN[%d] - ignored.\n",
3265 le16_to_cpu(ctlx->outbuf.type),
3266 le16_to_cpu(intype));
3270 /* This URB has succeeded, so grab the data ... */
3271 memcpy(&ctlx->inbuf, usbin, sizeof(ctlx->inbuf));
3273 switch (ctlx->state) {
3274 case CTLX_REQ_SUBMITTED:
3276 * We have received our response URB before
3277 * our request has been acknowledged. Odd,
3278 * but our OUT URB is still alive...
3280 pr_debug("Causality violation: please reboot Universe\n");
3281 ctlx->state = CTLX_RESP_COMPLETE;
3284 case CTLX_REQ_COMPLETE:
3286 * This is the usual path: our request
3287 * has already been acknowledged, and
3288 * now we have received the reply too.
3290 ctlx->state = CTLX_COMPLETE;
3291 unlocked_usbctlx_complete(hw, ctlx);
3297 * Throw this CTLX away ...
3299 netdev_err(hw->wlandev->netdev,
3300 "Matched IN URB, CTLX[%d] in invalid state(%s). Discarded.\n",
3301 le16_to_cpu(ctlx->outbuf.type),
3302 ctlxstr(ctlx->state));
3303 if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0)
3310 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3313 hfa384x_usbctlxq_run(hw);
3316 /*----------------------------------------------------------------
3317 * hfa384x_usbin_txcompl
3319 * At this point we have the results of a previous transmit.
3322 * wlandev wlan device
3323 * usbin ptr to the usb transfer buffer
3332 *----------------------------------------------------------------
3334 static void hfa384x_usbin_txcompl(struct wlandevice *wlandev,
3335 union hfa384x_usbin *usbin)
3339 status = le16_to_cpu(usbin->type); /* yeah I know it says type... */
3341 /* Was there an error? */
3342 if (HFA384x_TXSTATUS_ISERROR(status))
3343 prism2sta_ev_txexc(wlandev, status);
3345 prism2sta_ev_tx(wlandev, status);
3348 /*----------------------------------------------------------------
3351 * At this point we have a successful received a rx frame packet.
3354 * wlandev wlan device
3355 * usbin ptr to the usb transfer buffer
3364 *----------------------------------------------------------------
3366 static void hfa384x_usbin_rx(struct wlandevice *wlandev, struct sk_buff *skb)
3368 union hfa384x_usbin *usbin = (union hfa384x_usbin *)skb->data;
3369 struct hfa384x *hw = wlandev->priv;
3371 struct p80211_rxmeta *rxmeta;
3375 /* Byte order convert once up front. */
3376 le16_to_cpus(&usbin->rxfrm.desc.status);
3377 le32_to_cpus(&usbin->rxfrm.desc.time);
3379 /* Now handle frame based on port# */
3380 switch (HFA384x_RXSTATUS_MACPORT_GET(usbin->rxfrm.desc.status)) {
3382 fc = le16_to_cpu(usbin->rxfrm.desc.frame_control);
3384 /* If exclude and we receive an unencrypted, drop it */
3385 if ((wlandev->hostwep & HOSTWEP_EXCLUDEUNENCRYPTED) &&
3386 !WLAN_GET_FC_ISWEP(fc)) {
3390 data_len = le16_to_cpu(usbin->rxfrm.desc.data_len);
3392 /* How much header data do we have? */
3393 hdrlen = p80211_headerlen(fc);
3395 /* Pull off the descriptor */
3396 skb_pull(skb, sizeof(struct hfa384x_rx_frame));
3398 /* Now shunt the header block up against the data block
3399 * with an "overlapping" copy
3401 memmove(skb_push(skb, hdrlen),
3402 &usbin->rxfrm.desc.frame_control, hdrlen);
3404 skb->dev = wlandev->netdev;
3406 /* And set the frame length properly */
3407 skb_trim(skb, data_len + hdrlen);
3409 /* The prism2 series does not return the CRC */
3410 memset(skb_put(skb, WLAN_CRC_LEN), 0xff, WLAN_CRC_LEN);
3412 skb_reset_mac_header(skb);
3414 /* Attach the rxmeta, set some stuff */
3415 p80211skb_rxmeta_attach(wlandev, skb);
3416 rxmeta = p80211skb_rxmeta(skb);
3417 rxmeta->mactime = usbin->rxfrm.desc.time;
3418 rxmeta->rxrate = usbin->rxfrm.desc.rate;
3419 rxmeta->signal = usbin->rxfrm.desc.signal - hw->dbmadjust;
3420 rxmeta->noise = usbin->rxfrm.desc.silence - hw->dbmadjust;
3422 p80211netdev_rx(wlandev, skb);
3427 if (!HFA384x_RXSTATUS_ISFCSERR(usbin->rxfrm.desc.status)) {
3428 /* Copy to wlansnif skb */
3429 hfa384x_int_rxmonitor(wlandev, &usbin->rxfrm);
3432 pr_debug("Received monitor frame: FCSerr set\n");
3437 netdev_warn(hw->wlandev->netdev, "Received frame on unsupported port=%d\n",
3438 HFA384x_RXSTATUS_MACPORT_GET(usbin->rxfrm.desc.status));
3443 /*----------------------------------------------------------------
3444 * hfa384x_int_rxmonitor
3446 * Helper function for int_rx. Handles monitor frames.
3447 * Note that this function allocates space for the FCS and sets it
3448 * to 0xffffffff. The hfa384x doesn't give us the FCS value but the
3449 * higher layers expect it. 0xffffffff is used as a flag to indicate
3453 * wlandev wlan device structure
3454 * rxfrm rx descriptor read from card in int_rx
3460 * Allocates an skb and passes it up via the PF_PACKET interface.
3463 *----------------------------------------------------------------
3465 static void hfa384x_int_rxmonitor(struct wlandevice *wlandev,
3466 struct hfa384x_usb_rxfrm *rxfrm)
3468 struct hfa384x_rx_frame *rxdesc = &rxfrm->desc;
3469 unsigned int hdrlen = 0;
3470 unsigned int datalen = 0;
3471 unsigned int skblen = 0;
3474 struct sk_buff *skb;
3475 struct hfa384x *hw = wlandev->priv;
3477 /* Remember the status, time, and data_len fields are in host order */
3478 /* Figure out how big the frame is */
3479 fc = le16_to_cpu(rxdesc->frame_control);
3480 hdrlen = p80211_headerlen(fc);
3481 datalen = le16_to_cpu(rxdesc->data_len);
3483 /* Allocate an ind message+framesize skb */
3484 skblen = sizeof(struct p80211_caphdr) + hdrlen + datalen + WLAN_CRC_LEN;
3486 /* sanity check the length */
3488 (sizeof(struct p80211_caphdr) +
3489 WLAN_HDR_A4_LEN + WLAN_DATA_MAXLEN + WLAN_CRC_LEN)) {
3490 pr_debug("overlen frm: len=%zd\n",
3491 skblen - sizeof(struct p80211_caphdr));
3496 skb = dev_alloc_skb(skblen);
3500 /* only prepend the prism header if in the right mode */
3501 if ((wlandev->netdev->type == ARPHRD_IEEE80211_PRISM) &&
3502 (hw->sniffhdr != 0)) {
3503 struct p80211_caphdr *caphdr;
3504 /* The NEW header format! */
3505 datap = skb_put(skb, sizeof(struct p80211_caphdr));
3506 caphdr = (struct p80211_caphdr *)datap;
3508 caphdr->version = htonl(P80211CAPTURE_VERSION);
3509 caphdr->length = htonl(sizeof(struct p80211_caphdr));
3510 caphdr->mactime = __cpu_to_be64(rxdesc->time * 1000);
3511 caphdr->hosttime = __cpu_to_be64(jiffies);
3512 caphdr->phytype = htonl(4); /* dss_dot11_b */
3513 caphdr->channel = htonl(hw->sniff_channel);
3514 caphdr->datarate = htonl(rxdesc->rate);
3515 caphdr->antenna = htonl(0); /* unknown */
3516 caphdr->priority = htonl(0); /* unknown */
3517 caphdr->ssi_type = htonl(3); /* rssi_raw */
3518 caphdr->ssi_signal = htonl(rxdesc->signal);
3519 caphdr->ssi_noise = htonl(rxdesc->silence);
3520 caphdr->preamble = htonl(0); /* unknown */
3521 caphdr->encoding = htonl(1); /* cck */
3524 /* Copy the 802.11 header to the skb
3525 * (ctl frames may be less than a full header)
3527 skb_put_data(skb, &rxdesc->frame_control, hdrlen);
3529 /* If any, copy the data from the card to the skb */
3531 datap = skb_put_data(skb, rxfrm->data, datalen);
3533 /* check for unencrypted stuff if WEP bit set. */
3534 if (*(datap - hdrlen + 1) & 0x40) /* wep set */
3535 if ((*(datap) == 0xaa) && (*(datap + 1) == 0xaa))
3536 /* clear wep; it's the 802.2 header! */
3537 *(datap - hdrlen + 1) &= 0xbf;
3540 if (hw->sniff_fcs) {
3542 datap = skb_put(skb, WLAN_CRC_LEN);
3543 memset(datap, 0xff, WLAN_CRC_LEN);
3546 /* pass it back up */
3547 p80211netdev_rx(wlandev, skb);
3550 /*----------------------------------------------------------------
3551 * hfa384x_usbin_info
3553 * At this point we have a successful received a Prism2 info frame.
3556 * wlandev wlan device
3557 * usbin ptr to the usb transfer buffer
3566 *----------------------------------------------------------------
3568 static void hfa384x_usbin_info(struct wlandevice *wlandev,
3569 union hfa384x_usbin *usbin)
3571 le16_to_cpus(&usbin->infofrm.info.framelen);
3572 prism2sta_ev_info(wlandev, &usbin->infofrm.info);
3575 /*----------------------------------------------------------------
3576 * hfa384x_usbout_callback
3578 * Callback for URBs on the BULKOUT endpoint.
3581 * urb ptr to the completed urb
3590 *----------------------------------------------------------------
3592 static void hfa384x_usbout_callback(struct urb *urb)
3594 struct wlandevice *wlandev = urb->context;
3600 if (wlandev && wlandev->netdev) {
3601 switch (urb->status) {
3603 prism2sta_ev_alloc(wlandev);
3608 struct hfa384x *hw = wlandev->priv;
3610 netdev_warn(hw->wlandev->netdev,
3611 "%s tx pipe stalled: requesting reset\n",
3612 wlandev->netdev->name);
3613 if (!test_and_set_bit
3614 (WORK_TX_HALT, &hw->usb_flags))
3615 schedule_work(&hw->usb_work);
3616 wlandev->netdev->stats.tx_errors++;
3624 struct hfa384x *hw = wlandev->priv;
3626 if (!test_and_set_bit
3627 (THROTTLE_TX, &hw->usb_flags) &&
3628 !timer_pending(&hw->throttle)) {
3629 mod_timer(&hw->throttle,
3630 jiffies + THROTTLE_JIFFIES);
3632 wlandev->netdev->stats.tx_errors++;
3633 netif_stop_queue(wlandev->netdev);
3639 /* Ignorable errors */
3643 netdev_info(wlandev->netdev, "unknown urb->status=%d\n",
3645 wlandev->netdev->stats.tx_errors++;
3651 /*----------------------------------------------------------------
3652 * hfa384x_ctlxout_callback
3654 * Callback for control data on the BULKOUT endpoint.
3657 * urb ptr to the completed urb
3666 *----------------------------------------------------------------
3668 static void hfa384x_ctlxout_callback(struct urb *urb)
3670 struct hfa384x *hw = urb->context;
3671 int delete_resptimer = 0;
3674 struct hfa384x_usbctlx *ctlx;
3675 unsigned long flags;
3677 pr_debug("urb->status=%d\n", urb->status);
3681 if ((urb->status == -ESHUTDOWN) ||
3682 (urb->status == -ENODEV) || !hw)
3686 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3689 * Only one CTLX at a time on the "active" list, and
3690 * none at all if we are unplugged. However, we can
3691 * rely on the disconnect function to clean everything
3692 * up if someone unplugged the adapter.
3694 if (list_empty(&hw->ctlxq.active)) {
3695 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3700 * Having something on the "active" queue means
3701 * that we have timers to worry about ...
3703 if (del_timer(&hw->reqtimer) == 0) {
3704 if (hw->req_timer_done == 0) {
3706 * This timer was actually running while we
3707 * were trying to delete it. Let it terminate
3708 * gracefully instead.
3710 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3714 hw->req_timer_done = 1;
3717 ctlx = get_active_ctlx(hw);
3719 if (urb->status == 0) {
3720 /* Request portion of a CTLX is successful */
3721 switch (ctlx->state) {
3722 case CTLX_REQ_SUBMITTED:
3723 /* This OUT-ACK received before IN */
3724 ctlx->state = CTLX_REQ_COMPLETE;
3727 case CTLX_RESP_COMPLETE:
3728 /* IN already received before this OUT-ACK,
3729 * so this command must now be complete.
3731 ctlx->state = CTLX_COMPLETE;
3732 unlocked_usbctlx_complete(hw, ctlx);
3737 /* This is NOT a valid CTLX "success" state! */
3738 netdev_err(hw->wlandev->netdev,
3739 "Illegal CTLX[%d] success state(%s, %d) in OUT URB\n",
3740 le16_to_cpu(ctlx->outbuf.type),
3741 ctlxstr(ctlx->state), urb->status);
3745 /* If the pipe has stalled then we need to reset it */
3746 if ((urb->status == -EPIPE) &&
3747 !test_and_set_bit(WORK_TX_HALT, &hw->usb_flags)) {
3748 netdev_warn(hw->wlandev->netdev,
3749 "%s tx pipe stalled: requesting reset\n",
3750 hw->wlandev->netdev->name);
3751 schedule_work(&hw->usb_work);
3754 /* If someone cancels the OUT URB then its status
3755 * should be either -ECONNRESET or -ENOENT.
3757 ctlx->state = CTLX_REQ_FAILED;
3758 unlocked_usbctlx_complete(hw, ctlx);
3759 delete_resptimer = 1;
3764 if (delete_resptimer) {
3765 timer_ok = del_timer(&hw->resptimer);
3767 hw->resp_timer_done = 1;
3770 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3772 if (!timer_ok && (hw->resp_timer_done == 0)) {
3773 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3778 hfa384x_usbctlxq_run(hw);
3781 /*----------------------------------------------------------------
3782 * hfa384x_usbctlx_reqtimerfn
3784 * Timer response function for CTLX request timeouts. If this
3785 * function is called, it means that the callback for the OUT
3786 * URB containing a Prism2.x XXX_Request was never called.
3789 * data a ptr to the struct hfa384x
3798 *----------------------------------------------------------------
3800 static void hfa384x_usbctlx_reqtimerfn(struct timer_list *t)
3802 struct hfa384x *hw = from_timer(hw, t, reqtimer);
3803 unsigned long flags;
3805 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3807 hw->req_timer_done = 1;
3809 /* Removing the hardware automatically empties
3810 * the active list ...
3812 if (!list_empty(&hw->ctlxq.active)) {
3814 * We must ensure that our URB is removed from
3815 * the system, if it hasn't already expired.
3817 hw->ctlx_urb.transfer_flags |= URB_ASYNC_UNLINK;
3818 if (usb_unlink_urb(&hw->ctlx_urb) == -EINPROGRESS) {
3819 struct hfa384x_usbctlx *ctlx = get_active_ctlx(hw);
3821 ctlx->state = CTLX_REQ_FAILED;
3823 /* This URB was active, but has now been
3824 * cancelled. It will now have a status of
3825 * -ECONNRESET in the callback function.
3827 * We are cancelling this CTLX, so we're
3828 * not going to need to wait for a response.
3829 * The URB's callback function will check
3830 * that this timer is truly dead.
3832 if (del_timer(&hw->resptimer) != 0)
3833 hw->resp_timer_done = 1;
3837 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3840 /*----------------------------------------------------------------
3841 * hfa384x_usbctlx_resptimerfn
3843 * Timer response function for CTLX response timeouts. If this
3844 * function is called, it means that the callback for the IN
3845 * URB containing a Prism2.x XXX_Response was never called.
3848 * data a ptr to the struct hfa384x
3857 *----------------------------------------------------------------
3859 static void hfa384x_usbctlx_resptimerfn(struct timer_list *t)
3861 struct hfa384x *hw = from_timer(hw, t, resptimer);
3862 unsigned long flags;
3864 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3866 hw->resp_timer_done = 1;
3868 /* The active list will be empty if the
3869 * adapter has been unplugged ...
3871 if (!list_empty(&hw->ctlxq.active)) {
3872 struct hfa384x_usbctlx *ctlx = get_active_ctlx(hw);
3874 if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0) {
3875 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3876 hfa384x_usbctlxq_run(hw);
3880 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3883 /*----------------------------------------------------------------
3884 * hfa384x_usb_throttlefn
3897 *----------------------------------------------------------------
3899 static void hfa384x_usb_throttlefn(struct timer_list *t)
3901 struct hfa384x *hw = from_timer(hw, t, throttle);
3902 unsigned long flags;
3904 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3906 pr_debug("flags=0x%lx\n", hw->usb_flags);
3907 if (!hw->wlandev->hwremoved) {
3908 bool rx_throttle = test_and_clear_bit(THROTTLE_RX, &hw->usb_flags) &&
3909 !test_and_set_bit(WORK_RX_RESUME, &hw->usb_flags);
3910 bool tx_throttle = test_and_clear_bit(THROTTLE_TX, &hw->usb_flags) &&
3911 !test_and_set_bit(WORK_TX_RESUME, &hw->usb_flags);
3913 * We need to check BOTH the RX and the TX throttle controls,
3914 * so we use the bitwise OR instead of the logical OR.
3916 if (rx_throttle | tx_throttle)
3917 schedule_work(&hw->usb_work);
3920 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3923 /*----------------------------------------------------------------
3924 * hfa384x_usbctlx_submit
3926 * Called from the doxxx functions to submit a CTLX to the queue
3929 * hw ptr to the hw struct
3930 * ctlx ctlx structure to enqueue
3933 * -ENODEV if the adapter is unplugged
3939 * process or interrupt
3940 *----------------------------------------------------------------
3942 static int hfa384x_usbctlx_submit(struct hfa384x *hw,
3943 struct hfa384x_usbctlx *ctlx)
3945 unsigned long flags;
3947 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3949 if (hw->wlandev->hwremoved) {
3950 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3954 ctlx->state = CTLX_PENDING;
3955 list_add_tail(&ctlx->list, &hw->ctlxq.pending);
3956 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3957 hfa384x_usbctlxq_run(hw);
3962 /*----------------------------------------------------------------
3963 * hfa384x_isgood_pdrcore
3965 * Quick check of PDR codes.
3968 * pdrcode PDR code number (host order)
3977 *----------------------------------------------------------------
3979 static int hfa384x_isgood_pdrcode(u16 pdrcode)
3982 case HFA384x_PDR_END_OF_PDA:
3983 case HFA384x_PDR_PCB_PARTNUM:
3984 case HFA384x_PDR_PDAVER:
3985 case HFA384x_PDR_NIC_SERIAL:
3986 case HFA384x_PDR_MKK_MEASUREMENTS:
3987 case HFA384x_PDR_NIC_RAMSIZE:
3988 case HFA384x_PDR_MFISUPRANGE:
3989 case HFA384x_PDR_CFISUPRANGE:
3990 case HFA384x_PDR_NICID:
3991 case HFA384x_PDR_MAC_ADDRESS:
3992 case HFA384x_PDR_REGDOMAIN:
3993 case HFA384x_PDR_ALLOWED_CHANNEL:
3994 case HFA384x_PDR_DEFAULT_CHANNEL:
3995 case HFA384x_PDR_TEMPTYPE:
3996 case HFA384x_PDR_IFR_SETTING:
3997 case HFA384x_PDR_RFR_SETTING:
3998 case HFA384x_PDR_HFA3861_BASELINE:
3999 case HFA384x_PDR_HFA3861_SHADOW:
4000 case HFA384x_PDR_HFA3861_IFRF:
4001 case HFA384x_PDR_HFA3861_CHCALSP:
4002 case HFA384x_PDR_HFA3861_CHCALI:
4003 case HFA384x_PDR_3842_NIC_CONFIG:
4004 case HFA384x_PDR_USB_ID:
4005 case HFA384x_PDR_PCI_ID:
4006 case HFA384x_PDR_PCI_IFCONF:
4007 case HFA384x_PDR_PCI_PMCONF:
4008 case HFA384x_PDR_RFENRGY:
4009 case HFA384x_PDR_HFA3861_MANF_TESTSP:
4010 case HFA384x_PDR_HFA3861_MANF_TESTI:
4014 if (pdrcode < 0x1000) {
4015 /* code is OK, but we don't know exactly what it is */
4016 pr_debug("Encountered unknown PDR#=0x%04x, assuming it's ok.\n",
4023 pr_debug("Encountered unknown PDR#=0x%04x, (>=0x1000), assuming it's bad.\n",