1 /* src/prism2/driver/hfa384x_usb.c
3 * Functions that talk to the USB variantof the Intersil hfa384x MAC
5 * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
6 * --------------------------------------------------------------------
10 * The contents of this file are subject to the Mozilla Public
11 * License Version 1.1 (the "License"); you may not use this file
12 * except in compliance with the License. You may obtain a copy of
13 * the License at http://www.mozilla.org/MPL/
15 * Software distributed under the License is distributed on an "AS
16 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
17 * implied. See the License for the specific language governing
18 * rights and limitations under the License.
20 * Alternatively, the contents of this file may be used under the
21 * terms of the GNU Public License version 2 (the "GPL"), in which
22 * case the provisions of the GPL are applicable instead of the
23 * above. If you wish to allow the use of your version of this file
24 * only under the terms of the GPL and not to allow others to use
25 * your version of this file under the MPL, indicate your decision
26 * by deleting the provisions above and replace them with the notice
27 * and other provisions required by the GPL. If you do not delete
28 * the provisions above, a recipient may use your version of this
29 * file under either the MPL or the GPL.
31 * --------------------------------------------------------------------
33 * Inquiries regarding the linux-wlan Open Source project can be
36 * AbsoluteValue Systems Inc.
38 * http://www.linux-wlan.com
40 * --------------------------------------------------------------------
42 * Portions of the development of this software were funded by
43 * Intersil Corporation as part of PRISM(R) chipset product development.
45 * --------------------------------------------------------------------
47 * This file implements functions that correspond to the prism2/hfa384x
48 * 802.11 MAC hardware and firmware host interface.
50 * The functions can be considered to represent several levels of
51 * abstraction. The lowest level functions are simply C-callable wrappers
52 * around the register accesses. The next higher level represents C-callable
53 * prism2 API functions that match the Intersil documentation as closely
54 * as is reasonable. The next higher layer implements common sequences
55 * of invocations of the API layer (e.g. write to bap, followed by cmd).
58 * hfa384x_drvr_xxx Highest level abstractions provided by the
59 * hfa384x code. They are driver defined wrappers
60 * for common sequences. These functions generally
61 * use the services of the lower levels.
63 * hfa384x_drvr_xxxconfig An example of the drvr level abstraction. These
64 * functions are wrappers for the RID get/set
65 * sequence. They call copy_[to|from]_bap() and
66 * cmd_access(). These functions operate on the
67 * RIDs and buffers without validation. The caller
68 * is responsible for that.
70 * API wrapper functions:
71 * hfa384x_cmd_xxx functions that provide access to the f/w commands.
72 * The function arguments correspond to each command
73 * argument, even command arguments that get packed
74 * into single registers. These functions _just_
75 * issue the command by setting the cmd/parm regs
76 * & reading the status/resp regs. Additional
77 * activities required to fully use a command
78 * (read/write from/to bap, get/set int status etc.)
79 * are implemented separately. Think of these as
80 * C-callable prism2 commands.
82 * Lowest Layer Functions:
83 * hfa384x_docmd_xxx These functions implement the sequence required
84 * to issue any prism2 command. Primarily used by the
85 * hfa384x_cmd_xxx functions.
87 * hfa384x_bap_xxx BAP read/write access functions.
88 * Note: we usually use BAP0 for non-interrupt context
89 * and BAP1 for interrupt context.
91 * hfa384x_dl_xxx download related functions.
93 * Driver State Issues:
94 * Note that there are two pairs of functions that manage the
95 * 'initialized' and 'running' states of the hw/MAC combo. The four
96 * functions are create(), destroy(), start(), and stop(). create()
97 * sets up the data structures required to support the hfa384x_*
98 * functions and destroy() cleans them up. The start() function gets
99 * the actual hardware running and enables the interrupts. The stop()
100 * function shuts the hardware down. The sequence should be:
104 * . Do interesting things w/ the hardware
109 * Note that destroy() can be called without calling stop() first.
110 * --------------------------------------------------------------------
113 #include <linux/module.h>
114 #include <linux/kernel.h>
115 #include <linux/sched.h>
116 #include <linux/types.h>
117 #include <linux/slab.h>
118 #include <linux/wireless.h>
119 #include <linux/netdevice.h>
120 #include <linux/timer.h>
121 #include <linux/io.h>
122 #include <linux/delay.h>
123 #include <asm/byteorder.h>
124 #include <linux/bitops.h>
125 #include <linux/list.h>
126 #include <linux/usb.h>
127 #include <linux/byteorder/generic.h>
129 #define SUBMIT_URB(u, f) usb_submit_urb(u, f)
131 #include "p80211types.h"
132 #include "p80211hdr.h"
133 #include "p80211mgmt.h"
134 #include "p80211conv.h"
135 #include "p80211msg.h"
136 #include "p80211netdev.h"
137 #include "p80211req.h"
138 #include "p80211metadef.h"
139 #include "p80211metastruct.h"
141 #include "prism2mgmt.h"
148 #define THROTTLE_JIFFIES (HZ/8)
149 #define URB_ASYNC_UNLINK 0
150 #define USB_QUEUE_BULK 0
152 #define ROUNDUP64(a) (((a)+63)&~63)
155 static void dbprint_urb(struct urb *urb);
159 hfa384x_int_rxmonitor(wlandevice_t *wlandev, hfa384x_usb_rxfrm_t *rxfrm);
161 static void hfa384x_usb_defer(struct work_struct *data);
163 static int submit_rx_urb(hfa384x_t *hw, gfp_t flags);
165 static int submit_tx_urb(hfa384x_t *hw, struct urb *tx_urb, gfp_t flags);
167 /*---------------------------------------------------*/
169 static void hfa384x_usbout_callback(struct urb *urb);
170 static void hfa384x_ctlxout_callback(struct urb *urb);
171 static void hfa384x_usbin_callback(struct urb *urb);
174 hfa384x_usbin_txcompl(wlandevice_t *wlandev, hfa384x_usbin_t *usbin);
176 static void hfa384x_usbin_rx(wlandevice_t *wlandev, struct sk_buff *skb);
178 static void hfa384x_usbin_info(wlandevice_t *wlandev, hfa384x_usbin_t *usbin);
181 hfa384x_usbout_tx(wlandevice_t *wlandev, hfa384x_usbout_t *usbout);
183 static void hfa384x_usbin_ctlx(hfa384x_t *hw, hfa384x_usbin_t *usbin,
186 /*---------------------------------------------------*/
187 /* Functions to support the prism2 usb command queue */
189 static void hfa384x_usbctlxq_run(hfa384x_t *hw);
191 static void hfa384x_usbctlx_reqtimerfn(unsigned long data);
193 static void hfa384x_usbctlx_resptimerfn(unsigned long data);
195 static void hfa384x_usb_throttlefn(unsigned long data);
197 static void hfa384x_usbctlx_completion_task(unsigned long data);
199 static void hfa384x_usbctlx_reaper_task(unsigned long data);
201 static int hfa384x_usbctlx_submit(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
203 static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
205 struct usbctlx_completor {
206 int (*complete)(struct usbctlx_completor *);
210 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
211 hfa384x_usbctlx_t *ctlx,
212 struct usbctlx_completor *completor);
215 unlocked_usbctlx_cancel_async(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
217 static void hfa384x_cb_status(hfa384x_t *hw, const hfa384x_usbctlx_t *ctlx);
219 static void hfa384x_cb_rrid(hfa384x_t *hw, const hfa384x_usbctlx_t *ctlx);
222 usbctlx_get_status(const hfa384x_usb_cmdresp_t *cmdresp,
223 hfa384x_cmdresult_t *result);
226 usbctlx_get_rridresult(const hfa384x_usb_rridresp_t *rridresp,
227 hfa384x_rridresult_t *result);
229 /*---------------------------------------------------*/
230 /* Low level req/resp CTLX formatters and submitters */
232 hfa384x_docmd(hfa384x_t *hw,
234 hfa384x_metacmd_t *cmd,
235 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
238 hfa384x_dorrid(hfa384x_t *hw,
242 unsigned int riddatalen,
243 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
246 hfa384x_dowrid(hfa384x_t *hw,
250 unsigned int riddatalen,
251 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
254 hfa384x_dormem(hfa384x_t *hw,
260 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
263 hfa384x_dowmem(hfa384x_t *hw,
269 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
271 static int hfa384x_isgood_pdrcode(u16 pdrcode);
273 static inline const char *ctlxstr(CTLX_STATE s)
275 static const char * const ctlx_str[] = {
280 "Request packet submitted",
281 "Request packet completed",
282 "Response packet completed"
288 static inline hfa384x_usbctlx_t *get_active_ctlx(hfa384x_t *hw)
290 return list_entry(hw->ctlxq.active.next, hfa384x_usbctlx_t, list);
294 void dbprint_urb(struct urb *urb)
296 pr_debug("urb->pipe=0x%08x\n", urb->pipe);
297 pr_debug("urb->status=0x%08x\n", urb->status);
298 pr_debug("urb->transfer_flags=0x%08x\n", urb->transfer_flags);
299 pr_debug("urb->transfer_buffer=0x%08x\n",
300 (unsigned int)urb->transfer_buffer);
301 pr_debug("urb->transfer_buffer_length=0x%08x\n",
302 urb->transfer_buffer_length);
303 pr_debug("urb->actual_length=0x%08x\n", urb->actual_length);
304 pr_debug("urb->bandwidth=0x%08x\n", urb->bandwidth);
305 pr_debug("urb->setup_packet(ctl)=0x%08x\n",
306 (unsigned int)urb->setup_packet);
307 pr_debug("urb->start_frame(iso/irq)=0x%08x\n", urb->start_frame);
308 pr_debug("urb->interval(irq)=0x%08x\n", urb->interval);
309 pr_debug("urb->error_count(iso)=0x%08x\n", urb->error_count);
310 pr_debug("urb->timeout=0x%08x\n", urb->timeout);
311 pr_debug("urb->context=0x%08x\n", (unsigned int)urb->context);
312 pr_debug("urb->complete=0x%08x\n", (unsigned int)urb->complete);
316 /*----------------------------------------------------------------
319 * Listen for input data on the BULK-IN pipe. If the pipe has
320 * stalled then schedule it to be reset.
324 * memflags memory allocation flags
327 * error code from submission
331 ----------------------------------------------------------------*/
332 static int submit_rx_urb(hfa384x_t *hw, gfp_t memflags)
337 skb = dev_alloc_skb(sizeof(hfa384x_usbin_t));
343 /* Post the IN urb */
344 usb_fill_bulk_urb(&hw->rx_urb, hw->usb,
346 skb->data, sizeof(hfa384x_usbin_t),
347 hfa384x_usbin_callback, hw->wlandev);
349 hw->rx_urb_skb = skb;
352 if (!hw->wlandev->hwremoved &&
353 !test_bit(WORK_RX_HALT, &hw->usb_flags)) {
354 result = SUBMIT_URB(&hw->rx_urb, memflags);
356 /* Check whether we need to reset the RX pipe */
357 if (result == -EPIPE) {
358 netdev_warn(hw->wlandev->netdev,
359 "%s rx pipe stalled: requesting reset\n",
360 hw->wlandev->netdev->name);
361 if (!test_and_set_bit(WORK_RX_HALT, &hw->usb_flags))
362 schedule_work(&hw->usb_work);
366 /* Don't leak memory if anything should go wrong */
369 hw->rx_urb_skb = NULL;
376 /*----------------------------------------------------------------
379 * Prepares and submits the URB of transmitted data. If the
380 * submission fails then it will schedule the output pipe to
385 * tx_urb URB of data for transmission
386 * memflags memory allocation flags
389 * error code from submission
393 ----------------------------------------------------------------*/
394 static int submit_tx_urb(hfa384x_t *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 = 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 ----------------------------------------------------------------*/
437 static void hfa384x_usb_defer(struct work_struct *data)
439 hfa384x_t *hw = container_of(data, struct hfa384x, usb_work);
440 struct net_device *netdev = hw->wlandev->netdev;
442 /* Don't bother trying to reset anything if the plug
443 * has been pulled ...
445 if (hw->wlandev->hwremoved)
448 /* Reception has stopped: try to reset the input pipe */
449 if (test_bit(WORK_RX_HALT, &hw->usb_flags)) {
452 usb_kill_urb(&hw->rx_urb); /* Cannot be holding spinlock! */
454 ret = usb_clear_halt(hw->usb, hw->endp_in);
456 netdev_err(hw->wlandev->netdev,
457 "Failed to clear rx pipe for %s: err=%d\n",
460 netdev_info(hw->wlandev->netdev, "%s rx pipe reset complete.\n",
462 clear_bit(WORK_RX_HALT, &hw->usb_flags);
463 set_bit(WORK_RX_RESUME, &hw->usb_flags);
467 /* Resume receiving data back from the device. */
468 if (test_bit(WORK_RX_RESUME, &hw->usb_flags)) {
471 ret = submit_rx_urb(hw, GFP_KERNEL);
473 netdev_err(hw->wlandev->netdev,
474 "Failed to resume %s rx pipe.\n",
477 clear_bit(WORK_RX_RESUME, &hw->usb_flags);
481 /* Transmission has stopped: try to reset the output pipe */
482 if (test_bit(WORK_TX_HALT, &hw->usb_flags)) {
485 usb_kill_urb(&hw->tx_urb);
486 ret = usb_clear_halt(hw->usb, hw->endp_out);
488 netdev_err(hw->wlandev->netdev,
489 "Failed to clear tx pipe for %s: err=%d\n",
492 netdev_info(hw->wlandev->netdev, "%s tx pipe reset complete.\n",
494 clear_bit(WORK_TX_HALT, &hw->usb_flags);
495 set_bit(WORK_TX_RESUME, &hw->usb_flags);
497 /* Stopping the BULK-OUT pipe also blocked
498 * us from sending any more CTLX URBs, so
499 * we need to re-run our queue ...
501 hfa384x_usbctlxq_run(hw);
505 /* Resume transmitting. */
506 if (test_and_clear_bit(WORK_TX_RESUME, &hw->usb_flags))
507 netif_wake_queue(hw->wlandev->netdev);
510 /*----------------------------------------------------------------
513 * Sets up the hfa384x_t data structure for use. Note this
514 * does _not_ initialize the actual hardware, just the data structures
515 * we use to keep track of its state.
518 * hw device structure
519 * irq device irq number
520 * iobase i/o base address for register access
521 * membase memory base address for register access
530 ----------------------------------------------------------------*/
531 void hfa384x_create(hfa384x_t *hw, struct usb_device *usb)
533 memset(hw, 0, sizeof(hfa384x_t));
536 /* set up the endpoints */
537 hw->endp_in = usb_rcvbulkpipe(usb, 1);
538 hw->endp_out = usb_sndbulkpipe(usb, 2);
540 /* Set up the waitq */
541 init_waitqueue_head(&hw->cmdq);
543 /* Initialize the command queue */
544 spin_lock_init(&hw->ctlxq.lock);
545 INIT_LIST_HEAD(&hw->ctlxq.pending);
546 INIT_LIST_HEAD(&hw->ctlxq.active);
547 INIT_LIST_HEAD(&hw->ctlxq.completing);
548 INIT_LIST_HEAD(&hw->ctlxq.reapable);
550 /* Initialize the authentication queue */
551 skb_queue_head_init(&hw->authq);
553 tasklet_init(&hw->reaper_bh,
554 hfa384x_usbctlx_reaper_task, (unsigned long)hw);
555 tasklet_init(&hw->completion_bh,
556 hfa384x_usbctlx_completion_task, (unsigned long)hw);
557 INIT_WORK(&hw->link_bh, prism2sta_processing_defer);
558 INIT_WORK(&hw->usb_work, hfa384x_usb_defer);
560 setup_timer(&hw->throttle, hfa384x_usb_throttlefn, (unsigned long)hw);
562 setup_timer(&hw->resptimer, hfa384x_usbctlx_resptimerfn,
565 setup_timer(&hw->reqtimer, hfa384x_usbctlx_reqtimerfn,
568 usb_init_urb(&hw->rx_urb);
569 usb_init_urb(&hw->tx_urb);
570 usb_init_urb(&hw->ctlx_urb);
572 hw->link_status = HFA384x_LINK_NOTCONNECTED;
573 hw->state = HFA384x_STATE_INIT;
575 INIT_WORK(&hw->commsqual_bh, prism2sta_commsqual_defer);
576 setup_timer(&hw->commsqual_timer, prism2sta_commsqual_timer,
580 /*----------------------------------------------------------------
583 * Partner to hfa384x_create(). This function cleans up the hw
584 * structure so that it can be freed by the caller using a simple
585 * kfree. Currently, this function is just a placeholder. If, at some
586 * point in the future, an hw in the 'shutdown' state requires a 'deep'
587 * kfree, this is where it should be done. Note that if this function
588 * is called on a _running_ hw structure, the drvr_stop() function is
592 * hw device structure
595 * nothing, this function is not allowed to fail.
601 ----------------------------------------------------------------*/
602 void hfa384x_destroy(hfa384x_t *hw)
606 if (hw->state == HFA384x_STATE_RUNNING)
607 hfa384x_drvr_stop(hw);
608 hw->state = HFA384x_STATE_PREINIT;
610 kfree(hw->scanresults);
611 hw->scanresults = NULL;
613 /* Now to clean out the auth queue */
614 while ((skb = skb_dequeue(&hw->authq)))
618 static hfa384x_usbctlx_t *usbctlx_alloc(void)
620 hfa384x_usbctlx_t *ctlx;
622 ctlx = kzalloc(sizeof(*ctlx),
623 in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
625 init_completion(&ctlx->done);
631 usbctlx_get_status(const hfa384x_usb_cmdresp_t *cmdresp,
632 hfa384x_cmdresult_t *result)
634 result->status = le16_to_cpu(cmdresp->status);
635 result->resp0 = le16_to_cpu(cmdresp->resp0);
636 result->resp1 = le16_to_cpu(cmdresp->resp1);
637 result->resp2 = le16_to_cpu(cmdresp->resp2);
639 pr_debug("cmdresult:status=0x%04x resp0=0x%04x resp1=0x%04x resp2=0x%04x\n",
640 result->status, result->resp0, result->resp1, result->resp2);
642 return result->status & HFA384x_STATUS_RESULT;
646 usbctlx_get_rridresult(const hfa384x_usb_rridresp_t *rridresp,
647 hfa384x_rridresult_t *result)
649 result->rid = le16_to_cpu(rridresp->rid);
650 result->riddata = rridresp->data;
651 result->riddata_len = ((le16_to_cpu(rridresp->frmlen) - 1) * 2);
654 /*----------------------------------------------------------------
656 * This completor must be passed to hfa384x_usbctlx_complete_sync()
657 * when processing a CTLX that returns a hfa384x_cmdresult_t structure.
658 ----------------------------------------------------------------*/
659 struct usbctlx_cmd_completor {
660 struct usbctlx_completor head;
662 const hfa384x_usb_cmdresp_t *cmdresp;
663 hfa384x_cmdresult_t *result;
666 static inline int usbctlx_cmd_completor_fn(struct usbctlx_completor *head)
668 struct usbctlx_cmd_completor *complete;
670 complete = (struct usbctlx_cmd_completor *)head;
671 return usbctlx_get_status(complete->cmdresp, complete->result);
674 static inline struct usbctlx_completor *init_cmd_completor(
675 struct usbctlx_cmd_completor
677 const hfa384x_usb_cmdresp_t
679 hfa384x_cmdresult_t *result)
681 completor->head.complete = usbctlx_cmd_completor_fn;
682 completor->cmdresp = cmdresp;
683 completor->result = result;
684 return &(completor->head);
687 /*----------------------------------------------------------------
689 * This completor must be passed to hfa384x_usbctlx_complete_sync()
690 * when processing a CTLX that reads a RID.
691 ----------------------------------------------------------------*/
692 struct usbctlx_rrid_completor {
693 struct usbctlx_completor head;
695 const hfa384x_usb_rridresp_t *rridresp;
697 unsigned int riddatalen;
700 static int usbctlx_rrid_completor_fn(struct usbctlx_completor *head)
702 struct usbctlx_rrid_completor *complete;
703 hfa384x_rridresult_t rridresult;
705 complete = (struct usbctlx_rrid_completor *)head;
706 usbctlx_get_rridresult(complete->rridresp, &rridresult);
708 /* Validate the length, note body len calculation in bytes */
709 if (rridresult.riddata_len != complete->riddatalen) {
710 pr_warn("RID len mismatch, rid=0x%04x hlen=%d fwlen=%d\n",
712 complete->riddatalen, rridresult.riddata_len);
716 memcpy(complete->riddata, rridresult.riddata, complete->riddatalen);
720 static inline struct usbctlx_completor *init_rrid_completor(
721 struct usbctlx_rrid_completor
723 const hfa384x_usb_rridresp_t
726 unsigned int riddatalen)
728 completor->head.complete = usbctlx_rrid_completor_fn;
729 completor->rridresp = rridresp;
730 completor->riddata = riddata;
731 completor->riddatalen = riddatalen;
732 return &(completor->head);
735 /*----------------------------------------------------------------
737 * Interprets the results of a synchronous RID-write
738 ----------------------------------------------------------------*/
739 #define init_wrid_completor init_cmd_completor
741 /*----------------------------------------------------------------
743 * Interprets the results of a synchronous memory-write
744 ----------------------------------------------------------------*/
745 #define init_wmem_completor init_cmd_completor
747 /*----------------------------------------------------------------
749 * Interprets the results of a synchronous memory-read
750 ----------------------------------------------------------------*/
751 struct usbctlx_rmem_completor {
752 struct usbctlx_completor head;
754 const hfa384x_usb_rmemresp_t *rmemresp;
759 static int usbctlx_rmem_completor_fn(struct usbctlx_completor *head)
761 struct usbctlx_rmem_completor *complete =
762 (struct usbctlx_rmem_completor *)head;
764 pr_debug("rmemresp:len=%d\n", complete->rmemresp->frmlen);
765 memcpy(complete->data, complete->rmemresp->data, complete->len);
769 static inline struct usbctlx_completor *init_rmem_completor(
770 struct usbctlx_rmem_completor
772 hfa384x_usb_rmemresp_t
777 completor->head.complete = usbctlx_rmem_completor_fn;
778 completor->rmemresp = rmemresp;
779 completor->data = data;
780 completor->len = len;
781 return &(completor->head);
784 /*----------------------------------------------------------------
787 * Ctlx_complete handler for async CMD type control exchanges.
788 * mark the hw struct as such.
790 * Note: If the handling is changed here, it should probably be
791 * changed in docmd as well.
795 * ctlx completed CTLX
804 ----------------------------------------------------------------*/
805 static void hfa384x_cb_status(hfa384x_t *hw, const hfa384x_usbctlx_t *ctlx)
807 if (ctlx->usercb != NULL) {
808 hfa384x_cmdresult_t cmdresult;
810 if (ctlx->state != CTLX_COMPLETE) {
811 memset(&cmdresult, 0, sizeof(cmdresult));
813 HFA384x_STATUS_RESULT_SET(HFA384x_CMD_ERR);
815 usbctlx_get_status(&ctlx->inbuf.cmdresp, &cmdresult);
818 ctlx->usercb(hw, &cmdresult, ctlx->usercb_data);
822 /*----------------------------------------------------------------
825 * CTLX completion handler for async RRID type control exchanges.
827 * Note: If the handling is changed here, it should probably be
828 * changed in dorrid as well.
832 * ctlx completed CTLX
841 ----------------------------------------------------------------*/
842 static void hfa384x_cb_rrid(hfa384x_t *hw, const hfa384x_usbctlx_t *ctlx)
844 if (ctlx->usercb != NULL) {
845 hfa384x_rridresult_t rridresult;
847 if (ctlx->state != CTLX_COMPLETE) {
848 memset(&rridresult, 0, sizeof(rridresult));
849 rridresult.rid = le16_to_cpu(ctlx->outbuf.rridreq.rid);
851 usbctlx_get_rridresult(&ctlx->inbuf.rridresp,
855 ctlx->usercb(hw, &rridresult, ctlx->usercb_data);
859 static inline int hfa384x_docmd_wait(hfa384x_t *hw, hfa384x_metacmd_t *cmd)
861 return hfa384x_docmd(hw, DOWAIT, cmd, NULL, NULL, NULL);
865 hfa384x_docmd_async(hfa384x_t *hw,
866 hfa384x_metacmd_t *cmd,
867 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
869 return hfa384x_docmd(hw, DOASYNC, cmd, cmdcb, usercb, usercb_data);
873 hfa384x_dorrid_wait(hfa384x_t *hw, u16 rid, void *riddata,
874 unsigned int riddatalen)
876 return hfa384x_dorrid(hw, DOWAIT,
877 rid, riddata, riddatalen, NULL, NULL, NULL);
881 hfa384x_dorrid_async(hfa384x_t *hw,
882 u16 rid, void *riddata, unsigned int riddatalen,
884 ctlx_usercb_t usercb, void *usercb_data)
886 return hfa384x_dorrid(hw, DOASYNC,
887 rid, riddata, riddatalen,
888 cmdcb, usercb, usercb_data);
892 hfa384x_dowrid_wait(hfa384x_t *hw, u16 rid, void *riddata,
893 unsigned int riddatalen)
895 return hfa384x_dowrid(hw, DOWAIT,
896 rid, riddata, riddatalen, NULL, NULL, NULL);
900 hfa384x_dowrid_async(hfa384x_t *hw,
901 u16 rid, void *riddata, unsigned int riddatalen,
903 ctlx_usercb_t usercb, void *usercb_data)
905 return hfa384x_dowrid(hw, DOASYNC,
906 rid, riddata, riddatalen,
907 cmdcb, usercb, usercb_data);
911 hfa384x_dormem_wait(hfa384x_t *hw,
912 u16 page, u16 offset, void *data, unsigned int len)
914 return hfa384x_dormem(hw, DOWAIT,
915 page, offset, data, len, NULL, NULL, NULL);
919 hfa384x_dormem_async(hfa384x_t *hw,
920 u16 page, u16 offset, void *data, unsigned int len,
922 ctlx_usercb_t usercb, void *usercb_data)
924 return hfa384x_dormem(hw, DOASYNC,
925 page, offset, data, len,
926 cmdcb, usercb, usercb_data);
930 hfa384x_dowmem_wait(hfa384x_t *hw,
931 u16 page, u16 offset, void *data, unsigned int len)
933 return hfa384x_dowmem(hw, DOWAIT,
934 page, offset, data, len, NULL, NULL, NULL);
938 hfa384x_dowmem_async(hfa384x_t *hw,
944 ctlx_usercb_t usercb, void *usercb_data)
946 return hfa384x_dowmem(hw, DOASYNC,
947 page, offset, data, len,
948 cmdcb, usercb, usercb_data);
951 /*----------------------------------------------------------------
952 * hfa384x_cmd_initialize
954 * Issues the initialize command and sets the hw->state based
958 * hw device structure
962 * >0 f/w reported error - f/w status code
963 * <0 driver reported error
969 ----------------------------------------------------------------*/
970 int hfa384x_cmd_initialize(hfa384x_t *hw)
974 hfa384x_metacmd_t cmd;
976 cmd.cmd = HFA384x_CMDCODE_INIT;
981 result = hfa384x_docmd_wait(hw, &cmd);
983 pr_debug("cmdresp.init: status=0x%04x, resp0=0x%04x, resp1=0x%04x, resp2=0x%04x\n",
985 cmd.result.resp0, cmd.result.resp1, cmd.result.resp2);
987 for (i = 0; i < HFA384x_NUMPORTS_MAX; i++)
988 hw->port_enabled[i] = 0;
991 hw->link_status = HFA384x_LINK_NOTCONNECTED;
996 /*----------------------------------------------------------------
997 * hfa384x_cmd_disable
999 * Issues the disable command to stop communications on one of
1003 * hw device structure
1004 * macport MAC port number (host order)
1008 * >0 f/w reported failure - f/w status code
1009 * <0 driver reported error (timeout|bad arg)
1015 ----------------------------------------------------------------*/
1016 int hfa384x_cmd_disable(hfa384x_t *hw, u16 macport)
1019 hfa384x_metacmd_t cmd;
1021 cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_DISABLE) |
1022 HFA384x_CMD_MACPORT_SET(macport);
1027 result = hfa384x_docmd_wait(hw, &cmd);
1032 /*----------------------------------------------------------------
1033 * hfa384x_cmd_enable
1035 * Issues the enable command to enable communications on one of
1039 * hw device structure
1040 * macport MAC port number
1044 * >0 f/w reported failure - f/w status code
1045 * <0 driver reported error (timeout|bad arg)
1051 ----------------------------------------------------------------*/
1052 int hfa384x_cmd_enable(hfa384x_t *hw, u16 macport)
1055 hfa384x_metacmd_t cmd;
1057 cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_ENABLE) |
1058 HFA384x_CMD_MACPORT_SET(macport);
1063 result = hfa384x_docmd_wait(hw, &cmd);
1068 /*----------------------------------------------------------------
1069 * hfa384x_cmd_monitor
1071 * Enables the 'monitor mode' of the MAC. Here's the description of
1072 * monitor mode that I've received thus far:
1074 * "The "monitor mode" of operation is that the MAC passes all
1075 * frames for which the PLCP checks are correct. All received
1076 * MPDUs are passed to the host with MAC Port = 7, with a
1077 * receive status of good, FCS error, or undecryptable. Passing
1078 * certain MPDUs is a violation of the 802.11 standard, but useful
1079 * for a debugging tool." Normal communication is not possible
1080 * while monitor mode is enabled.
1083 * hw device structure
1084 * enable a code (0x0b|0x0f) that enables/disables
1085 * monitor mode. (host order)
1089 * >0 f/w reported failure - f/w status code
1090 * <0 driver reported error (timeout|bad arg)
1096 ----------------------------------------------------------------*/
1097 int hfa384x_cmd_monitor(hfa384x_t *hw, u16 enable)
1100 hfa384x_metacmd_t cmd;
1102 cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_MONITOR) |
1103 HFA384x_CMD_AINFO_SET(enable);
1108 result = hfa384x_docmd_wait(hw, &cmd);
1113 /*----------------------------------------------------------------
1114 * hfa384x_cmd_download
1116 * Sets the controls for the MAC controller code/data download
1117 * process. The arguments set the mode and address associated
1118 * with a download. Note that the aux registers should be enabled
1119 * prior to setting one of the download enable modes.
1122 * hw device structure
1123 * mode 0 - Disable programming and begin code exec
1124 * 1 - Enable volatile mem programming
1125 * 2 - Enable non-volatile mem programming
1126 * 3 - Program non-volatile section from NV download
1130 * highaddr For mode 1, sets the high & low order bits of
1131 * the "destination address". This address will be
1132 * the execution start address when download is
1133 * subsequently disabled.
1134 * For mode 2, sets the high & low order bits of
1135 * the destination in NV ram.
1136 * For modes 0 & 3, should be zero. (host order)
1137 * NOTE: these are CMD format.
1138 * codelen Length of the data to write in mode 2,
1139 * zero otherwise. (host order)
1143 * >0 f/w reported failure - f/w status code
1144 * <0 driver reported error (timeout|bad arg)
1150 ----------------------------------------------------------------*/
1151 int hfa384x_cmd_download(hfa384x_t *hw, u16 mode, u16 lowaddr,
1152 u16 highaddr, u16 codelen)
1155 hfa384x_metacmd_t cmd;
1157 pr_debug("mode=%d, lowaddr=0x%04x, highaddr=0x%04x, codelen=%d\n",
1158 mode, lowaddr, highaddr, codelen);
1160 cmd.cmd = (HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_DOWNLD) |
1161 HFA384x_CMD_PROGMODE_SET(mode));
1163 cmd.parm0 = lowaddr;
1164 cmd.parm1 = highaddr;
1165 cmd.parm2 = codelen;
1167 result = hfa384x_docmd_wait(hw, &cmd);
1172 /*----------------------------------------------------------------
1175 * Perform a reset of the hfa38xx MAC core. We assume that the hw
1176 * structure is in its "created" state. That is, it is initialized
1177 * with proper values. Note that if a reset is done after the
1178 * device has been active for awhile, the caller might have to clean
1179 * up some leftover cruft in the hw structure.
1182 * hw device structure
1183 * holdtime how long (in ms) to hold the reset
1184 * settletime how long (in ms) to wait after releasing
1194 ----------------------------------------------------------------*/
1195 int hfa384x_corereset(hfa384x_t *hw, int holdtime, int settletime, int genesis)
1199 result = usb_reset_device(hw->usb);
1201 netdev_err(hw->wlandev->netdev, "usb_reset_device() failed, result=%d.\n",
1208 /*----------------------------------------------------------------
1209 * hfa384x_usbctlx_complete_sync
1211 * Waits for a synchronous CTLX object to complete,
1212 * and then handles the response.
1215 * hw device structure
1217 * completor functor object to decide what to
1218 * do with the CTLX's result.
1222 * -ERESTARTSYS Interrupted by a signal
1224 * -ENODEV Adapter was unplugged
1225 * ??? Result from completor
1231 ----------------------------------------------------------------*/
1232 static int hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
1233 hfa384x_usbctlx_t *ctlx,
1234 struct usbctlx_completor *completor)
1236 unsigned long flags;
1239 result = wait_for_completion_interruptible(&ctlx->done);
1241 spin_lock_irqsave(&hw->ctlxq.lock, flags);
1244 * We can only handle the CTLX if the USB disconnect
1245 * function has not run yet ...
1248 if (hw->wlandev->hwremoved) {
1249 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1251 } else if (result != 0) {
1255 * We were probably interrupted, so delete
1256 * this CTLX asynchronously, kill the timers
1257 * and the URB, and then start the next
1260 * NOTE: We can only delete the timers and
1261 * the URB if this CTLX is active.
1263 if (ctlx == get_active_ctlx(hw)) {
1264 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1266 del_singleshot_timer_sync(&hw->reqtimer);
1267 del_singleshot_timer_sync(&hw->resptimer);
1268 hw->req_timer_done = 1;
1269 hw->resp_timer_done = 1;
1270 usb_kill_urb(&hw->ctlx_urb);
1272 spin_lock_irqsave(&hw->ctlxq.lock, flags);
1277 * This scenario is so unlikely that I'm
1278 * happy with a grubby "goto" solution ...
1280 if (hw->wlandev->hwremoved)
1285 * The completion task will send this CTLX
1286 * to the reaper the next time it runs. We
1287 * are no longer in a hurry.
1290 ctlx->state = CTLX_REQ_FAILED;
1291 list_move_tail(&ctlx->list, &hw->ctlxq.completing);
1293 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1296 hfa384x_usbctlxq_run(hw);
1298 if (ctlx->state == CTLX_COMPLETE) {
1299 result = completor->complete(completor);
1301 netdev_warn(hw->wlandev->netdev, "CTLX[%d] error: state(%s)\n",
1302 le16_to_cpu(ctlx->outbuf.type),
1303 ctlxstr(ctlx->state));
1307 list_del(&ctlx->list);
1308 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1315 /*----------------------------------------------------------------
1318 * Constructs a command CTLX and submits it.
1320 * NOTE: Any changes to the 'post-submit' code in this function
1321 * need to be carried over to hfa384x_cbcmd() since the handling
1322 * is virtually identical.
1325 * hw device structure
1326 * mode DOWAIT or DOASYNC
1327 * cmd cmd structure. Includes all arguments and result
1328 * data points. All in host order. in host order
1329 * cmdcb command-specific callback
1330 * usercb user callback for async calls, NULL for DOWAIT calls
1331 * usercb_data user supplied data pointer for async calls, NULL
1337 * -ERESTARTSYS Awakened on signal
1338 * >0 command indicated error, Status and Resp0-2 are
1346 ----------------------------------------------------------------*/
1348 hfa384x_docmd(hfa384x_t *hw,
1350 hfa384x_metacmd_t *cmd,
1351 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1354 hfa384x_usbctlx_t *ctlx;
1356 ctlx = usbctlx_alloc();
1362 /* Initialize the command */
1363 ctlx->outbuf.cmdreq.type = cpu_to_le16(HFA384x_USB_CMDREQ);
1364 ctlx->outbuf.cmdreq.cmd = cpu_to_le16(cmd->cmd);
1365 ctlx->outbuf.cmdreq.parm0 = cpu_to_le16(cmd->parm0);
1366 ctlx->outbuf.cmdreq.parm1 = cpu_to_le16(cmd->parm1);
1367 ctlx->outbuf.cmdreq.parm2 = cpu_to_le16(cmd->parm2);
1369 ctlx->outbufsize = sizeof(ctlx->outbuf.cmdreq);
1371 pr_debug("cmdreq: cmd=0x%04x parm0=0x%04x parm1=0x%04x parm2=0x%04x\n",
1372 cmd->cmd, cmd->parm0, cmd->parm1, cmd->parm2);
1374 ctlx->reapable = mode;
1375 ctlx->cmdcb = cmdcb;
1376 ctlx->usercb = usercb;
1377 ctlx->usercb_data = usercb_data;
1379 result = hfa384x_usbctlx_submit(hw, ctlx);
1382 } else if (mode == DOWAIT) {
1383 struct usbctlx_cmd_completor completor;
1386 hfa384x_usbctlx_complete_sync(hw, ctlx,
1387 init_cmd_completor(&completor,
1399 /*----------------------------------------------------------------
1402 * Constructs a read rid CTLX and issues it.
1404 * NOTE: Any changes to the 'post-submit' code in this function
1405 * need to be carried over to hfa384x_cbrrid() since the handling
1406 * is virtually identical.
1409 * hw device structure
1410 * mode DOWAIT or DOASYNC
1411 * rid Read RID number (host order)
1412 * riddata Caller supplied buffer that MAC formatted RID.data
1413 * record will be written to for DOWAIT calls. Should
1414 * be NULL for DOASYNC calls.
1415 * riddatalen Buffer length for DOWAIT calls. Zero for DOASYNC calls.
1416 * cmdcb command callback for async calls, NULL for DOWAIT calls
1417 * usercb user callback for async calls, NULL for DOWAIT calls
1418 * usercb_data user supplied data pointer for async calls, NULL
1424 * -ERESTARTSYS Awakened on signal
1425 * -ENODATA riddatalen != macdatalen
1426 * >0 command indicated error, Status and Resp0-2 are
1432 * interrupt (DOASYNC)
1433 * process (DOWAIT or DOASYNC)
1434 ----------------------------------------------------------------*/
1436 hfa384x_dorrid(hfa384x_t *hw,
1440 unsigned int riddatalen,
1441 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1444 hfa384x_usbctlx_t *ctlx;
1446 ctlx = usbctlx_alloc();
1452 /* Initialize the command */
1453 ctlx->outbuf.rridreq.type = cpu_to_le16(HFA384x_USB_RRIDREQ);
1454 ctlx->outbuf.rridreq.frmlen =
1455 cpu_to_le16(sizeof(ctlx->outbuf.rridreq.rid));
1456 ctlx->outbuf.rridreq.rid = cpu_to_le16(rid);
1458 ctlx->outbufsize = sizeof(ctlx->outbuf.rridreq);
1460 ctlx->reapable = mode;
1461 ctlx->cmdcb = cmdcb;
1462 ctlx->usercb = usercb;
1463 ctlx->usercb_data = usercb_data;
1465 /* Submit the CTLX */
1466 result = hfa384x_usbctlx_submit(hw, ctlx);
1469 } else if (mode == DOWAIT) {
1470 struct usbctlx_rrid_completor completor;
1473 hfa384x_usbctlx_complete_sync(hw, ctlx,
1476 &ctlx->inbuf.rridresp,
1477 riddata, riddatalen));
1484 /*----------------------------------------------------------------
1487 * Constructs a write rid CTLX and issues it.
1489 * NOTE: Any changes to the 'post-submit' code in this function
1490 * need to be carried over to hfa384x_cbwrid() since the handling
1491 * is virtually identical.
1494 * hw device structure
1495 * enum cmd_mode DOWAIT or DOASYNC
1497 * riddata Data portion of RID formatted for MAC
1498 * riddatalen Length of the data portion in bytes
1499 * cmdcb command callback for async calls, NULL for DOWAIT calls
1500 * usercb user callback for async calls, NULL for DOWAIT calls
1501 * usercb_data user supplied data pointer for async calls
1505 * -ETIMEDOUT timed out waiting for register ready or
1506 * command completion
1507 * >0 command indicated error, Status and Resp0-2 are
1513 * interrupt (DOASYNC)
1514 * process (DOWAIT or DOASYNC)
1515 ----------------------------------------------------------------*/
1517 hfa384x_dowrid(hfa384x_t *hw,
1521 unsigned int riddatalen,
1522 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1525 hfa384x_usbctlx_t *ctlx;
1527 ctlx = usbctlx_alloc();
1533 /* Initialize the command */
1534 ctlx->outbuf.wridreq.type = cpu_to_le16(HFA384x_USB_WRIDREQ);
1535 ctlx->outbuf.wridreq.frmlen = cpu_to_le16((sizeof
1536 (ctlx->outbuf.wridreq.rid) +
1537 riddatalen + 1) / 2);
1538 ctlx->outbuf.wridreq.rid = cpu_to_le16(rid);
1539 memcpy(ctlx->outbuf.wridreq.data, riddata, riddatalen);
1541 ctlx->outbufsize = sizeof(ctlx->outbuf.wridreq.type) +
1542 sizeof(ctlx->outbuf.wridreq.frmlen) +
1543 sizeof(ctlx->outbuf.wridreq.rid) + riddatalen;
1545 ctlx->reapable = mode;
1546 ctlx->cmdcb = cmdcb;
1547 ctlx->usercb = usercb;
1548 ctlx->usercb_data = usercb_data;
1550 /* Submit the CTLX */
1551 result = hfa384x_usbctlx_submit(hw, ctlx);
1554 } else if (mode == DOWAIT) {
1555 struct usbctlx_cmd_completor completor;
1556 hfa384x_cmdresult_t wridresult;
1558 result = hfa384x_usbctlx_complete_sync(hw,
1562 &ctlx->inbuf.wridresp,
1570 /*----------------------------------------------------------------
1573 * Constructs a readmem CTLX and issues it.
1575 * NOTE: Any changes to the 'post-submit' code in this function
1576 * need to be carried over to hfa384x_cbrmem() since the handling
1577 * is virtually identical.
1580 * hw device structure
1581 * mode DOWAIT or DOASYNC
1582 * page MAC address space page (CMD format)
1583 * offset MAC address space offset
1584 * data Ptr to data buffer to receive read
1585 * len Length of the data to read (max == 2048)
1586 * cmdcb command callback for async calls, NULL for DOWAIT calls
1587 * usercb user callback for async calls, NULL for DOWAIT calls
1588 * usercb_data user supplied data pointer for async calls
1592 * -ETIMEDOUT timed out waiting for register ready or
1593 * command completion
1594 * >0 command indicated error, Status and Resp0-2 are
1600 * interrupt (DOASYNC)
1601 * process (DOWAIT or DOASYNC)
1602 ----------------------------------------------------------------*/
1604 hfa384x_dormem(hfa384x_t *hw,
1610 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1613 hfa384x_usbctlx_t *ctlx;
1615 ctlx = usbctlx_alloc();
1621 /* Initialize the command */
1622 ctlx->outbuf.rmemreq.type = cpu_to_le16(HFA384x_USB_RMEMREQ);
1623 ctlx->outbuf.rmemreq.frmlen =
1624 cpu_to_le16(sizeof(ctlx->outbuf.rmemreq.offset) +
1625 sizeof(ctlx->outbuf.rmemreq.page) + len);
1626 ctlx->outbuf.rmemreq.offset = cpu_to_le16(offset);
1627 ctlx->outbuf.rmemreq.page = cpu_to_le16(page);
1629 ctlx->outbufsize = sizeof(ctlx->outbuf.rmemreq);
1631 pr_debug("type=0x%04x frmlen=%d offset=0x%04x page=0x%04x\n",
1632 ctlx->outbuf.rmemreq.type,
1633 ctlx->outbuf.rmemreq.frmlen,
1634 ctlx->outbuf.rmemreq.offset, ctlx->outbuf.rmemreq.page);
1636 pr_debug("pktsize=%zd\n", ROUNDUP64(sizeof(ctlx->outbuf.rmemreq)));
1638 ctlx->reapable = mode;
1639 ctlx->cmdcb = cmdcb;
1640 ctlx->usercb = usercb;
1641 ctlx->usercb_data = usercb_data;
1643 result = hfa384x_usbctlx_submit(hw, ctlx);
1646 } else if (mode == DOWAIT) {
1647 struct usbctlx_rmem_completor completor;
1650 hfa384x_usbctlx_complete_sync(hw, ctlx,
1653 &ctlx->inbuf.rmemresp, data,
1661 /*----------------------------------------------------------------
1664 * Constructs a writemem CTLX and issues it.
1666 * NOTE: Any changes to the 'post-submit' code in this function
1667 * need to be carried over to hfa384x_cbwmem() since the handling
1668 * is virtually identical.
1671 * hw device structure
1672 * mode DOWAIT or DOASYNC
1673 * page MAC address space page (CMD format)
1674 * offset MAC address space offset
1675 * data Ptr to data buffer containing write data
1676 * len Length of the data to read (max == 2048)
1677 * cmdcb command callback for async calls, NULL for DOWAIT calls
1678 * usercb user callback for async calls, NULL for DOWAIT calls
1679 * usercb_data user supplied data pointer for async calls.
1683 * -ETIMEDOUT timed out waiting for register ready or
1684 * command completion
1685 * >0 command indicated error, Status and Resp0-2 are
1691 * interrupt (DOWAIT)
1692 * process (DOWAIT or DOASYNC)
1693 ----------------------------------------------------------------*/
1695 hfa384x_dowmem(hfa384x_t *hw,
1701 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1704 hfa384x_usbctlx_t *ctlx;
1706 pr_debug("page=0x%04x offset=0x%04x len=%d\n", page, offset, len);
1708 ctlx = usbctlx_alloc();
1714 /* Initialize the command */
1715 ctlx->outbuf.wmemreq.type = cpu_to_le16(HFA384x_USB_WMEMREQ);
1716 ctlx->outbuf.wmemreq.frmlen =
1717 cpu_to_le16(sizeof(ctlx->outbuf.wmemreq.offset) +
1718 sizeof(ctlx->outbuf.wmemreq.page) + len);
1719 ctlx->outbuf.wmemreq.offset = cpu_to_le16(offset);
1720 ctlx->outbuf.wmemreq.page = cpu_to_le16(page);
1721 memcpy(ctlx->outbuf.wmemreq.data, data, len);
1723 ctlx->outbufsize = sizeof(ctlx->outbuf.wmemreq.type) +
1724 sizeof(ctlx->outbuf.wmemreq.frmlen) +
1725 sizeof(ctlx->outbuf.wmemreq.offset) +
1726 sizeof(ctlx->outbuf.wmemreq.page) + len;
1728 ctlx->reapable = mode;
1729 ctlx->cmdcb = cmdcb;
1730 ctlx->usercb = usercb;
1731 ctlx->usercb_data = usercb_data;
1733 result = hfa384x_usbctlx_submit(hw, ctlx);
1736 } else if (mode == DOWAIT) {
1737 struct usbctlx_cmd_completor completor;
1738 hfa384x_cmdresult_t wmemresult;
1740 result = hfa384x_usbctlx_complete_sync(hw,
1744 &ctlx->inbuf.wmemresp,
1752 /*----------------------------------------------------------------
1753 * hfa384x_drvr_commtallies
1755 * Send a commtallies inquiry to the MAC. Note that this is an async
1756 * call that will result in an info frame arriving sometime later.
1759 * hw device structure
1768 ----------------------------------------------------------------*/
1769 int hfa384x_drvr_commtallies(hfa384x_t *hw)
1771 hfa384x_metacmd_t cmd;
1773 cmd.cmd = HFA384x_CMDCODE_INQ;
1774 cmd.parm0 = HFA384x_IT_COMMTALLIES;
1778 hfa384x_docmd_async(hw, &cmd, NULL, NULL, NULL);
1783 /*----------------------------------------------------------------
1784 * hfa384x_drvr_disable
1786 * Issues the disable command to stop communications on one of
1787 * the MACs 'ports'. Only macport 0 is valid for stations.
1788 * APs may also disable macports 1-6. Only ports that have been
1789 * previously enabled may be disabled.
1792 * hw device structure
1793 * macport MAC port number (host order)
1797 * >0 f/w reported failure - f/w status code
1798 * <0 driver reported error (timeout|bad arg)
1804 ----------------------------------------------------------------*/
1805 int hfa384x_drvr_disable(hfa384x_t *hw, u16 macport)
1809 if ((!hw->isap && macport != 0) ||
1810 (hw->isap && !(macport <= HFA384x_PORTID_MAX)) ||
1811 !(hw->port_enabled[macport])) {
1814 result = hfa384x_cmd_disable(hw, macport);
1816 hw->port_enabled[macport] = 0;
1821 /*----------------------------------------------------------------
1822 * hfa384x_drvr_enable
1824 * Issues the enable command to enable communications on one of
1825 * the MACs 'ports'. Only macport 0 is valid for stations.
1826 * APs may also enable macports 1-6. Only ports that are currently
1827 * disabled may be enabled.
1830 * hw device structure
1831 * macport MAC port number
1835 * >0 f/w reported failure - f/w status code
1836 * <0 driver reported error (timeout|bad arg)
1842 ----------------------------------------------------------------*/
1843 int hfa384x_drvr_enable(hfa384x_t *hw, u16 macport)
1847 if ((!hw->isap && macport != 0) ||
1848 (hw->isap && !(macport <= HFA384x_PORTID_MAX)) ||
1849 (hw->port_enabled[macport])) {
1852 result = hfa384x_cmd_enable(hw, macport);
1854 hw->port_enabled[macport] = 1;
1859 /*----------------------------------------------------------------
1860 * hfa384x_drvr_flashdl_enable
1862 * Begins the flash download state. Checks to see that we're not
1863 * already in a download state and that a port isn't enabled.
1864 * Sets the download state and retrieves the flash download
1865 * buffer location, buffer size, and timeout length.
1868 * hw device structure
1872 * >0 f/w reported error - f/w status code
1873 * <0 driver reported error
1879 ----------------------------------------------------------------*/
1880 int hfa384x_drvr_flashdl_enable(hfa384x_t *hw)
1885 /* Check that a port isn't active */
1886 for (i = 0; i < HFA384x_PORTID_MAX; i++) {
1887 if (hw->port_enabled[i]) {
1888 pr_debug("called when port enabled.\n");
1893 /* Check that we're not already in a download state */
1894 if (hw->dlstate != HFA384x_DLSTATE_DISABLED)
1897 /* Retrieve the buffer loc&size and timeout */
1898 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_DOWNLOADBUFFER,
1899 &(hw->bufinfo), sizeof(hw->bufinfo));
1903 hw->bufinfo.page = le16_to_cpu(hw->bufinfo.page);
1904 hw->bufinfo.offset = le16_to_cpu(hw->bufinfo.offset);
1905 hw->bufinfo.len = le16_to_cpu(hw->bufinfo.len);
1906 result = hfa384x_drvr_getconfig16(hw, HFA384x_RID_MAXLOADTIME,
1911 hw->dltimeout = le16_to_cpu(hw->dltimeout);
1913 pr_debug("flashdl_enable\n");
1915 hw->dlstate = HFA384x_DLSTATE_FLASHENABLED;
1920 /*----------------------------------------------------------------
1921 * hfa384x_drvr_flashdl_disable
1923 * Ends the flash download state. Note that this will cause the MAC
1924 * firmware to restart.
1927 * hw device structure
1931 * >0 f/w reported error - f/w status code
1932 * <0 driver reported error
1938 ----------------------------------------------------------------*/
1939 int hfa384x_drvr_flashdl_disable(hfa384x_t *hw)
1941 /* Check that we're already in the download state */
1942 if (hw->dlstate != HFA384x_DLSTATE_FLASHENABLED)
1945 pr_debug("flashdl_enable\n");
1947 /* There isn't much we can do at this point, so I don't */
1948 /* bother w/ the return value */
1949 hfa384x_cmd_download(hw, HFA384x_PROGMODE_DISABLE, 0, 0, 0);
1950 hw->dlstate = HFA384x_DLSTATE_DISABLED;
1955 /*----------------------------------------------------------------
1956 * hfa384x_drvr_flashdl_write
1958 * Performs a FLASH download of a chunk of data. First checks to see
1959 * that we're in the FLASH download state, then sets the download
1960 * mode, uses the aux functions to 1) copy the data to the flash
1961 * buffer, 2) sets the download 'write flash' mode, 3) readback and
1962 * compare. Lather rinse, repeat as many times an necessary to get
1963 * all the given data into flash.
1964 * When all data has been written using this function (possibly
1965 * repeatedly), call drvr_flashdl_disable() to end the download state
1966 * and restart the MAC.
1969 * hw device structure
1970 * daddr Card address to write to. (host order)
1971 * buf Ptr to data to write.
1972 * len Length of data (host order).
1976 * >0 f/w reported error - f/w status code
1977 * <0 driver reported error
1983 ----------------------------------------------------------------*/
1984 int hfa384x_drvr_flashdl_write(hfa384x_t *hw, u32 daddr, void *buf, u32 len)
2001 pr_debug("daddr=0x%08x len=%d\n", daddr, len);
2003 /* Check that we're in the flash download state */
2004 if (hw->dlstate != HFA384x_DLSTATE_FLASHENABLED)
2007 netdev_info(hw->wlandev->netdev,
2008 "Download %d bytes to flash @0x%06x\n", len, daddr);
2010 /* Convert to flat address for arithmetic */
2011 /* NOTE: dlbuffer RID stores the address in AUX format */
2013 HFA384x_ADDR_AUX_MKFLAT(hw->bufinfo.page, hw->bufinfo.offset);
2014 pr_debug("dlbuf.page=0x%04x dlbuf.offset=0x%04x dlbufaddr=0x%08x\n",
2015 hw->bufinfo.page, hw->bufinfo.offset, dlbufaddr);
2016 /* Calculations to determine how many fills of the dlbuffer to do
2017 * and how many USB wmemreq's to do for each fill. At this point
2018 * in time, the dlbuffer size and the wmemreq size are the same.
2019 * Therefore, nwrites should always be 1. The extra complexity
2020 * here is a hedge against future changes.
2023 /* Figure out how many times to do the flash programming */
2024 nburns = len / hw->bufinfo.len;
2025 nburns += (len % hw->bufinfo.len) ? 1 : 0;
2027 /* For each flash program cycle, how many USB wmemreq's are needed? */
2028 nwrites = hw->bufinfo.len / HFA384x_USB_RWMEM_MAXLEN;
2029 nwrites += (hw->bufinfo.len % HFA384x_USB_RWMEM_MAXLEN) ? 1 : 0;
2032 for (i = 0; i < nburns; i++) {
2033 /* Get the dest address and len */
2034 burnlen = (len - (hw->bufinfo.len * i)) > hw->bufinfo.len ?
2035 hw->bufinfo.len : (len - (hw->bufinfo.len * i));
2036 burndaddr = daddr + (hw->bufinfo.len * i);
2037 burnlo = HFA384x_ADDR_CMD_MKOFF(burndaddr);
2038 burnhi = HFA384x_ADDR_CMD_MKPAGE(burndaddr);
2040 netdev_info(hw->wlandev->netdev, "Writing %d bytes to flash @0x%06x\n",
2041 burnlen, burndaddr);
2043 /* Set the download mode */
2044 result = hfa384x_cmd_download(hw, HFA384x_PROGMODE_NV,
2045 burnlo, burnhi, burnlen);
2047 netdev_err(hw->wlandev->netdev,
2048 "download(NV,lo=%x,hi=%x,len=%x) cmd failed, result=%d. Aborting d/l\n",
2049 burnlo, burnhi, burnlen, result);
2053 /* copy the data to the flash download buffer */
2054 for (j = 0; j < nwrites; j++) {
2056 (i * hw->bufinfo.len) +
2057 (j * HFA384x_USB_RWMEM_MAXLEN);
2059 writepage = HFA384x_ADDR_CMD_MKPAGE(dlbufaddr +
2060 (j * HFA384x_USB_RWMEM_MAXLEN));
2061 writeoffset = HFA384x_ADDR_CMD_MKOFF(dlbufaddr +
2062 (j * HFA384x_USB_RWMEM_MAXLEN));
2064 writelen = burnlen - (j * HFA384x_USB_RWMEM_MAXLEN);
2065 writelen = writelen > HFA384x_USB_RWMEM_MAXLEN ?
2066 HFA384x_USB_RWMEM_MAXLEN : writelen;
2068 result = hfa384x_dowmem_wait(hw,
2071 writebuf, writelen);
2074 /* set the download 'write flash' mode */
2075 result = hfa384x_cmd_download(hw,
2076 HFA384x_PROGMODE_NVWRITE,
2079 netdev_err(hw->wlandev->netdev,
2080 "download(NVWRITE,lo=%x,hi=%x,len=%x) cmd failed, result=%d. Aborting d/l\n",
2081 burnlo, burnhi, burnlen, result);
2085 /* TODO: We really should do a readback and compare. */
2090 /* Leave the firmware in the 'post-prog' mode. flashdl_disable will */
2091 /* actually disable programming mode. Remember, that will cause the */
2092 /* the firmware to effectively reset itself. */
2097 /*----------------------------------------------------------------
2098 * hfa384x_drvr_getconfig
2100 * Performs the sequence necessary to read a config/info item.
2103 * hw device structure
2104 * rid config/info record id (host order)
2105 * buf host side record buffer. Upon return it will
2106 * contain the body portion of the record (minus the
2108 * len buffer length (in bytes, should match record length)
2112 * >0 f/w reported error - f/w status code
2113 * <0 driver reported error
2114 * -ENODATA length mismatch between argument and retrieved
2121 ----------------------------------------------------------------*/
2122 int hfa384x_drvr_getconfig(hfa384x_t *hw, u16 rid, void *buf, u16 len)
2124 return hfa384x_dorrid_wait(hw, rid, buf, len);
2127 /*----------------------------------------------------------------
2128 * hfa384x_drvr_getconfig_async
2130 * Performs the sequence necessary to perform an async read of
2131 * of a config/info item.
2134 * hw device structure
2135 * rid config/info record id (host order)
2136 * buf host side record buffer. Upon return it will
2137 * contain the body portion of the record (minus the
2139 * len buffer length (in bytes, should match record length)
2140 * cbfn caller supplied callback, called when the command
2141 * is done (successful or not).
2142 * cbfndata pointer to some caller supplied data that will be
2143 * passed in as an argument to the cbfn.
2146 * nothing the cbfn gets a status argument identifying if
2149 * Queues an hfa384x_usbcmd_t for subsequent execution.
2153 ----------------------------------------------------------------*/
2155 hfa384x_drvr_getconfig_async(hfa384x_t *hw,
2156 u16 rid, ctlx_usercb_t usercb, void *usercb_data)
2158 return hfa384x_dorrid_async(hw, rid, NULL, 0,
2159 hfa384x_cb_rrid, usercb, usercb_data);
2162 /*----------------------------------------------------------------
2163 * hfa384x_drvr_setconfig_async
2165 * Performs the sequence necessary to write a config/info item.
2168 * hw device structure
2169 * rid config/info record id (in host order)
2170 * buf host side record buffer
2171 * len buffer length (in bytes)
2172 * usercb completion callback
2173 * usercb_data completion callback argument
2177 * >0 f/w reported error - f/w status code
2178 * <0 driver reported error
2184 ----------------------------------------------------------------*/
2186 hfa384x_drvr_setconfig_async(hfa384x_t *hw,
2189 u16 len, ctlx_usercb_t usercb, void *usercb_data)
2191 return hfa384x_dowrid_async(hw, rid, buf, len,
2192 hfa384x_cb_status, usercb, usercb_data);
2195 /*----------------------------------------------------------------
2196 * hfa384x_drvr_ramdl_disable
2198 * Ends the ram download state.
2201 * hw device structure
2205 * >0 f/w reported error - f/w status code
2206 * <0 driver reported error
2212 ----------------------------------------------------------------*/
2213 int hfa384x_drvr_ramdl_disable(hfa384x_t *hw)
2215 /* Check that we're already in the download state */
2216 if (hw->dlstate != HFA384x_DLSTATE_RAMENABLED)
2219 pr_debug("ramdl_disable()\n");
2221 /* There isn't much we can do at this point, so I don't */
2222 /* bother w/ the return value */
2223 hfa384x_cmd_download(hw, HFA384x_PROGMODE_DISABLE, 0, 0, 0);
2224 hw->dlstate = HFA384x_DLSTATE_DISABLED;
2229 /*----------------------------------------------------------------
2230 * hfa384x_drvr_ramdl_enable
2232 * Begins the ram download state. Checks to see that we're not
2233 * already in a download state and that a port isn't enabled.
2234 * Sets the download state and calls cmd_download with the
2235 * ENABLE_VOLATILE subcommand and the exeaddr argument.
2238 * hw device structure
2239 * exeaddr the card execution address that will be
2240 * jumped to when ramdl_disable() is called
2245 * >0 f/w reported error - f/w status code
2246 * <0 driver reported error
2252 ----------------------------------------------------------------*/
2253 int hfa384x_drvr_ramdl_enable(hfa384x_t *hw, u32 exeaddr)
2260 /* Check that a port isn't active */
2261 for (i = 0; i < HFA384x_PORTID_MAX; i++) {
2262 if (hw->port_enabled[i]) {
2263 netdev_err(hw->wlandev->netdev,
2264 "Can't download with a macport enabled.\n");
2269 /* Check that we're not already in a download state */
2270 if (hw->dlstate != HFA384x_DLSTATE_DISABLED) {
2271 netdev_err(hw->wlandev->netdev, "Download state not disabled.\n");
2275 pr_debug("ramdl_enable, exeaddr=0x%08x\n", exeaddr);
2277 /* Call the download(1,addr) function */
2278 lowaddr = HFA384x_ADDR_CMD_MKOFF(exeaddr);
2279 hiaddr = HFA384x_ADDR_CMD_MKPAGE(exeaddr);
2281 result = hfa384x_cmd_download(hw, HFA384x_PROGMODE_RAM,
2282 lowaddr, hiaddr, 0);
2285 /* Set the download state */
2286 hw->dlstate = HFA384x_DLSTATE_RAMENABLED;
2288 pr_debug("cmd_download(0x%04x, 0x%04x) failed, result=%d.\n",
2289 lowaddr, hiaddr, result);
2295 /*----------------------------------------------------------------
2296 * hfa384x_drvr_ramdl_write
2298 * Performs a RAM download of a chunk of data. First checks to see
2299 * that we're in the RAM download state, then uses the [read|write]mem USB
2300 * commands to 1) copy the data, 2) readback and compare. The download
2301 * state is unaffected. When all data has been written using
2302 * this function, call drvr_ramdl_disable() to end the download state
2303 * and restart the MAC.
2306 * hw device structure
2307 * daddr Card address to write to. (host order)
2308 * buf Ptr to data to write.
2309 * len Length of data (host order).
2313 * >0 f/w reported error - f/w status code
2314 * <0 driver reported error
2320 ----------------------------------------------------------------*/
2321 int hfa384x_drvr_ramdl_write(hfa384x_t *hw, u32 daddr, void *buf, u32 len)
2332 /* Check that we're in the ram download state */
2333 if (hw->dlstate != HFA384x_DLSTATE_RAMENABLED)
2336 netdev_info(hw->wlandev->netdev, "Writing %d bytes to ram @0x%06x\n",
2339 /* How many dowmem calls? */
2340 nwrites = len / HFA384x_USB_RWMEM_MAXLEN;
2341 nwrites += len % HFA384x_USB_RWMEM_MAXLEN ? 1 : 0;
2343 /* Do blocking wmem's */
2344 for (i = 0; i < nwrites; i++) {
2345 /* make address args */
2346 curraddr = daddr + (i * HFA384x_USB_RWMEM_MAXLEN);
2347 currpage = HFA384x_ADDR_CMD_MKPAGE(curraddr);
2348 curroffset = HFA384x_ADDR_CMD_MKOFF(curraddr);
2349 currlen = len - (i * HFA384x_USB_RWMEM_MAXLEN);
2350 if (currlen > HFA384x_USB_RWMEM_MAXLEN)
2351 currlen = HFA384x_USB_RWMEM_MAXLEN;
2353 /* Do blocking ctlx */
2354 result = hfa384x_dowmem_wait(hw,
2358 (i * HFA384x_USB_RWMEM_MAXLEN),
2364 /* TODO: We really should have a readback. */
2370 /*----------------------------------------------------------------
2371 * hfa384x_drvr_readpda
2373 * Performs the sequence to read the PDA space. Note there is no
2374 * drvr_writepda() function. Writing a PDA is
2375 * generally implemented by a calling component via calls to
2376 * cmd_download and writing to the flash download buffer via the
2380 * hw device structure
2381 * buf buffer to store PDA in
2386 * >0 f/w reported error - f/w status code
2387 * <0 driver reported error
2388 * -ETIMEDOUT timeout waiting for the cmd regs to become
2389 * available, or waiting for the control reg
2390 * to indicate the Aux port is enabled.
2391 * -ENODATA the buffer does NOT contain a valid PDA.
2392 * Either the card PDA is bad, or the auxdata
2393 * reads are giving us garbage.
2399 * process or non-card interrupt.
2400 ----------------------------------------------------------------*/
2401 int hfa384x_drvr_readpda(hfa384x_t *hw, void *buf, unsigned int len)
2407 int currpdr = 0; /* word offset of the current pdr */
2409 u16 pdrlen; /* pdr length in bytes, host order */
2410 u16 pdrcode; /* pdr code, host order */
2418 HFA3842_PDA_BASE, 0}, {
2419 HFA3841_PDA_BASE, 0}, {
2420 HFA3841_PDA_BOGUS_BASE, 0}
2423 /* Read the pda from each known address. */
2424 for (i = 0; i < ARRAY_SIZE(pdaloc); i++) {
2426 currpage = HFA384x_ADDR_CMD_MKPAGE(pdaloc[i].cardaddr);
2427 curroffset = HFA384x_ADDR_CMD_MKOFF(pdaloc[i].cardaddr);
2429 /* units of bytes */
2430 result = hfa384x_dormem_wait(hw, currpage, curroffset, buf,
2434 netdev_warn(hw->wlandev->netdev,
2435 "Read from index %zd failed, continuing\n",
2440 /* Test for garbage */
2441 pdaok = 1; /* initially assume good */
2443 while (pdaok && morepdrs) {
2444 pdrlen = le16_to_cpu(pda[currpdr]) * 2;
2445 pdrcode = le16_to_cpu(pda[currpdr + 1]);
2446 /* Test the record length */
2447 if (pdrlen > HFA384x_PDR_LEN_MAX || pdrlen == 0) {
2448 netdev_err(hw->wlandev->netdev,
2449 "pdrlen invalid=%d\n", pdrlen);
2454 if (!hfa384x_isgood_pdrcode(pdrcode)) {
2455 netdev_err(hw->wlandev->netdev, "pdrcode invalid=%d\n",
2460 /* Test for completion */
2461 if (pdrcode == HFA384x_PDR_END_OF_PDA)
2464 /* Move to the next pdr (if necessary) */
2466 /* note the access to pda[], need words here */
2467 currpdr += le16_to_cpu(pda[currpdr]) + 1;
2471 netdev_info(hw->wlandev->netdev,
2472 "PDA Read from 0x%08x in %s space.\n",
2474 pdaloc[i].auxctl == 0 ? "EXTDS" :
2475 pdaloc[i].auxctl == 1 ? "NV" :
2476 pdaloc[i].auxctl == 2 ? "PHY" :
2477 pdaloc[i].auxctl == 3 ? "ICSRAM" :
2482 result = pdaok ? 0 : -ENODATA;
2485 pr_debug("Failure: pda is not okay\n");
2490 /*----------------------------------------------------------------
2491 * hfa384x_drvr_setconfig
2493 * Performs the sequence necessary to write a config/info item.
2496 * hw device structure
2497 * rid config/info record id (in host order)
2498 * buf host side record buffer
2499 * len buffer length (in bytes)
2503 * >0 f/w reported error - f/w status code
2504 * <0 driver reported error
2510 ----------------------------------------------------------------*/
2511 int hfa384x_drvr_setconfig(hfa384x_t *hw, u16 rid, void *buf, u16 len)
2513 return hfa384x_dowrid_wait(hw, rid, buf, len);
2516 /*----------------------------------------------------------------
2517 * hfa384x_drvr_start
2519 * Issues the MAC initialize command, sets up some data structures,
2520 * and enables the interrupts. After this function completes, the
2521 * low-level stuff should be ready for any/all commands.
2524 * hw device structure
2527 * >0 f/w reported error - f/w status code
2528 * <0 driver reported error
2534 ----------------------------------------------------------------*/
2536 int hfa384x_drvr_start(hfa384x_t *hw)
2538 int result, result1, result2;
2543 /* Clear endpoint stalls - but only do this if the endpoint
2544 * is showing a stall status. Some prism2 cards seem to behave
2545 * badly if a clear_halt is called when the endpoint is already
2549 usb_get_status(hw->usb, USB_RECIP_ENDPOINT, hw->endp_in, &status);
2551 netdev_err(hw->wlandev->netdev, "Cannot get bulk in endpoint status.\n");
2554 if ((status == 1) && usb_clear_halt(hw->usb, hw->endp_in))
2555 netdev_err(hw->wlandev->netdev, "Failed to reset bulk in endpoint.\n");
2558 usb_get_status(hw->usb, USB_RECIP_ENDPOINT, hw->endp_out, &status);
2560 netdev_err(hw->wlandev->netdev, "Cannot get bulk out endpoint status.\n");
2563 if ((status == 1) && usb_clear_halt(hw->usb, hw->endp_out))
2564 netdev_err(hw->wlandev->netdev, "Failed to reset bulk out endpoint.\n");
2566 /* Synchronous unlink, in case we're trying to restart the driver */
2567 usb_kill_urb(&hw->rx_urb);
2569 /* Post the IN urb */
2570 result = submit_rx_urb(hw, GFP_KERNEL);
2572 netdev_err(hw->wlandev->netdev,
2573 "Fatal, failed to submit RX URB, result=%d\n",
2578 /* Call initialize twice, with a 1 second sleep in between.
2579 * This is a nasty work-around since many prism2 cards seem to
2580 * need time to settle after an init from cold. The second
2581 * call to initialize in theory is not necessary - but we call
2582 * it anyway as a double insurance policy:
2583 * 1) If the first init should fail, the second may well succeed
2584 * and the card can still be used
2585 * 2) It helps ensures all is well with the card after the first
2586 * init and settle time.
2588 result1 = hfa384x_cmd_initialize(hw);
2590 result = hfa384x_cmd_initialize(hw);
2594 netdev_err(hw->wlandev->netdev,
2595 "cmd_initialize() failed on two attempts, results %d and %d\n",
2597 usb_kill_urb(&hw->rx_urb);
2600 pr_debug("First cmd_initialize() failed (result %d),\n",
2602 pr_debug("but second attempt succeeded. All should be ok\n");
2604 } else if (result2 != 0) {
2605 netdev_warn(hw->wlandev->netdev, "First cmd_initialize() succeeded, but second attempt failed (result=%d)\n",
2607 netdev_warn(hw->wlandev->netdev,
2608 "Most likely the card will be functional\n");
2612 hw->state = HFA384x_STATE_RUNNING;
2618 /*----------------------------------------------------------------
2621 * Shuts down the MAC to the point where it is safe to unload the
2622 * driver. Any subsystem that may be holding a data or function
2623 * ptr into the driver must be cleared/deinitialized.
2626 * hw device structure
2629 * >0 f/w reported error - f/w status code
2630 * <0 driver reported error
2636 ----------------------------------------------------------------*/
2637 int hfa384x_drvr_stop(hfa384x_t *hw)
2643 /* There's no need for spinlocks here. The USB "disconnect"
2644 * function sets this "removed" flag and then calls us.
2646 if (!hw->wlandev->hwremoved) {
2647 /* Call initialize to leave the MAC in its 'reset' state */
2648 hfa384x_cmd_initialize(hw);
2650 /* Cancel the rxurb */
2651 usb_kill_urb(&hw->rx_urb);
2654 hw->link_status = HFA384x_LINK_NOTCONNECTED;
2655 hw->state = HFA384x_STATE_INIT;
2657 del_timer_sync(&hw->commsqual_timer);
2659 /* Clear all the port status */
2660 for (i = 0; i < HFA384x_NUMPORTS_MAX; i++)
2661 hw->port_enabled[i] = 0;
2666 /*----------------------------------------------------------------
2667 * hfa384x_drvr_txframe
2669 * Takes a frame from prism2sta and queues it for transmission.
2672 * hw device structure
2673 * skb packet buffer struct. Contains an 802.11
2675 * p80211_hdr points to the 802.11 header for the packet.
2677 * 0 Success and more buffs available
2678 * 1 Success but no more buffs
2679 * 2 Allocation failure
2680 * 4 Buffer full or queue busy
2686 ----------------------------------------------------------------*/
2687 int hfa384x_drvr_txframe(hfa384x_t *hw, struct sk_buff *skb,
2688 union p80211_hdr *p80211_hdr,
2689 struct p80211_metawep *p80211_wep)
2691 int usbpktlen = sizeof(hfa384x_tx_frame_t);
2696 if (hw->tx_urb.status == -EINPROGRESS) {
2697 netdev_warn(hw->wlandev->netdev, "TX URB already in use\n");
2702 /* Build Tx frame structure */
2703 /* Set up the control field */
2704 memset(&hw->txbuff.txfrm.desc, 0, sizeof(hw->txbuff.txfrm.desc));
2706 /* Setup the usb type field */
2707 hw->txbuff.type = cpu_to_le16(HFA384x_USB_TXFRM);
2709 /* Set up the sw_support field to identify this frame */
2710 hw->txbuff.txfrm.desc.sw_support = 0x0123;
2712 /* Tx complete and Tx exception disable per dleach. Might be causing
2715 /* #define DOEXC SLP -- doboth breaks horribly under load, doexc less so. */
2717 hw->txbuff.txfrm.desc.tx_control =
2718 HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
2719 HFA384x_TX_TXEX_SET(1) | HFA384x_TX_TXOK_SET(1);
2720 #elif defined(DOEXC)
2721 hw->txbuff.txfrm.desc.tx_control =
2722 HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
2723 HFA384x_TX_TXEX_SET(1) | HFA384x_TX_TXOK_SET(0);
2725 hw->txbuff.txfrm.desc.tx_control =
2726 HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
2727 HFA384x_TX_TXEX_SET(0) | HFA384x_TX_TXOK_SET(0);
2729 hw->txbuff.txfrm.desc.tx_control =
2730 cpu_to_le16(hw->txbuff.txfrm.desc.tx_control);
2732 /* copy the header over to the txdesc */
2733 memcpy(&(hw->txbuff.txfrm.desc.frame_control), p80211_hdr,
2734 sizeof(union p80211_hdr));
2736 /* if we're using host WEP, increase size by IV+ICV */
2737 if (p80211_wep->data) {
2738 hw->txbuff.txfrm.desc.data_len = cpu_to_le16(skb->len + 8);
2741 hw->txbuff.txfrm.desc.data_len = cpu_to_le16(skb->len);
2744 usbpktlen += skb->len;
2746 /* copy over the WEP IV if we are using host WEP */
2747 ptr = hw->txbuff.txfrm.data;
2748 if (p80211_wep->data) {
2749 memcpy(ptr, p80211_wep->iv, sizeof(p80211_wep->iv));
2750 ptr += sizeof(p80211_wep->iv);
2751 memcpy(ptr, p80211_wep->data, skb->len);
2753 memcpy(ptr, skb->data, skb->len);
2755 /* copy over the packet data */
2758 /* copy over the WEP ICV if we are using host WEP */
2759 if (p80211_wep->data)
2760 memcpy(ptr, p80211_wep->icv, sizeof(p80211_wep->icv));
2762 /* Send the USB packet */
2763 usb_fill_bulk_urb(&(hw->tx_urb), hw->usb,
2765 &(hw->txbuff), ROUNDUP64(usbpktlen),
2766 hfa384x_usbout_callback, hw->wlandev);
2767 hw->tx_urb.transfer_flags |= USB_QUEUE_BULK;
2770 ret = submit_tx_urb(hw, &hw->tx_urb, GFP_ATOMIC);
2772 netdev_err(hw->wlandev->netdev,
2773 "submit_tx_urb() failed, error=%d\n", ret);
2781 void hfa384x_tx_timeout(wlandevice_t *wlandev)
2783 hfa384x_t *hw = wlandev->priv;
2784 unsigned long flags;
2786 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2788 if (!hw->wlandev->hwremoved) {
2791 sched = !test_and_set_bit(WORK_TX_HALT, &hw->usb_flags);
2792 sched |= !test_and_set_bit(WORK_RX_HALT, &hw->usb_flags);
2794 schedule_work(&hw->usb_work);
2797 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2800 /*----------------------------------------------------------------
2801 * hfa384x_usbctlx_reaper_task
2803 * Tasklet to delete dead CTLX objects
2806 * data ptr to a hfa384x_t
2812 ----------------------------------------------------------------*/
2813 static void hfa384x_usbctlx_reaper_task(unsigned long data)
2815 hfa384x_t *hw = (hfa384x_t *)data;
2816 struct list_head *entry;
2817 struct list_head *temp;
2818 unsigned long flags;
2820 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2822 /* This list is guaranteed to be empty if someone
2823 * has unplugged the adapter.
2825 list_for_each_safe(entry, temp, &hw->ctlxq.reapable) {
2826 hfa384x_usbctlx_t *ctlx;
2828 ctlx = list_entry(entry, hfa384x_usbctlx_t, list);
2829 list_del(&ctlx->list);
2833 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2836 /*----------------------------------------------------------------
2837 * hfa384x_usbctlx_completion_task
2839 * Tasklet to call completion handlers for returned CTLXs
2842 * data ptr to hfa384x_t
2849 ----------------------------------------------------------------*/
2850 static void hfa384x_usbctlx_completion_task(unsigned long data)
2852 hfa384x_t *hw = (hfa384x_t *)data;
2853 struct list_head *entry;
2854 struct list_head *temp;
2855 unsigned long flags;
2859 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2861 /* This list is guaranteed to be empty if someone
2862 * has unplugged the adapter ...
2864 list_for_each_safe(entry, temp, &hw->ctlxq.completing) {
2865 hfa384x_usbctlx_t *ctlx;
2867 ctlx = list_entry(entry, hfa384x_usbctlx_t, list);
2869 /* Call the completion function that this
2870 * command was assigned, assuming it has one.
2872 if (ctlx->cmdcb != NULL) {
2873 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2874 ctlx->cmdcb(hw, ctlx);
2875 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2877 /* Make sure we don't try and complete
2878 * this CTLX more than once!
2882 /* Did someone yank the adapter out
2883 * while our list was (briefly) unlocked?
2885 if (hw->wlandev->hwremoved) {
2892 * "Reapable" CTLXs are ones which don't have any
2893 * threads waiting for them to die. Hence they must
2894 * be delivered to The Reaper!
2896 if (ctlx->reapable) {
2897 /* Move the CTLX off the "completing" list (hopefully)
2898 * on to the "reapable" list where the reaper task
2899 * can find it. And "reapable" means that this CTLX
2900 * isn't sitting on a wait-queue somewhere.
2902 list_move_tail(&ctlx->list, &hw->ctlxq.reapable);
2906 complete(&ctlx->done);
2908 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2911 tasklet_schedule(&hw->reaper_bh);
2914 /*----------------------------------------------------------------
2915 * unlocked_usbctlx_cancel_async
2917 * Mark the CTLX dead asynchronously, and ensure that the
2918 * next command on the queue is run afterwards.
2921 * hw ptr to the hfa384x_t structure
2922 * ctlx ptr to a CTLX structure
2925 * 0 the CTLX's URB is inactive
2926 * -EINPROGRESS the URB is currently being unlinked
2929 * Either process or interrupt, but presumably interrupt
2930 ----------------------------------------------------------------*/
2931 static int unlocked_usbctlx_cancel_async(hfa384x_t *hw,
2932 hfa384x_usbctlx_t *ctlx)
2937 * Try to delete the URB containing our request packet.
2938 * If we succeed, then its completion handler will be
2939 * called with a status of -ECONNRESET.
2941 hw->ctlx_urb.transfer_flags |= URB_ASYNC_UNLINK;
2942 ret = usb_unlink_urb(&hw->ctlx_urb);
2944 if (ret != -EINPROGRESS) {
2946 * The OUT URB had either already completed
2947 * or was still in the pending queue, so the
2948 * URB's completion function will not be called.
2949 * We will have to complete the CTLX ourselves.
2951 ctlx->state = CTLX_REQ_FAILED;
2952 unlocked_usbctlx_complete(hw, ctlx);
2959 /*----------------------------------------------------------------
2960 * unlocked_usbctlx_complete
2962 * A CTLX has completed. It may have been successful, it may not
2963 * have been. At this point, the CTLX should be quiescent. The URBs
2964 * aren't active and the timers should have been stopped.
2966 * The CTLX is migrated to the "completing" queue, and the completing
2967 * tasklet is scheduled.
2970 * hw ptr to a hfa384x_t structure
2971 * ctlx ptr to a ctlx structure
2979 * Either, assume interrupt
2980 ----------------------------------------------------------------*/
2981 static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx)
2983 /* Timers have been stopped, and ctlx should be in
2984 * a terminal state. Retire it from the "active"
2987 list_move_tail(&ctlx->list, &hw->ctlxq.completing);
2988 tasklet_schedule(&hw->completion_bh);
2990 switch (ctlx->state) {
2992 case CTLX_REQ_FAILED:
2993 /* This are the correct terminating states. */
2997 netdev_err(hw->wlandev->netdev, "CTLX[%d] not in a terminating state(%s)\n",
2998 le16_to_cpu(ctlx->outbuf.type),
2999 ctlxstr(ctlx->state));
3004 /*----------------------------------------------------------------
3005 * hfa384x_usbctlxq_run
3007 * Checks to see if the head item is running. If not, starts it.
3010 * hw ptr to hfa384x_t
3019 ----------------------------------------------------------------*/
3020 static void hfa384x_usbctlxq_run(hfa384x_t *hw)
3022 unsigned long flags;
3025 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3027 /* Only one active CTLX at any one time, because there's no
3028 * other (reliable) way to match the response URB to the
3031 * Don't touch any of these CTLXs if the hardware
3032 * has been removed or the USB subsystem is stalled.
3034 if (!list_empty(&hw->ctlxq.active) ||
3035 test_bit(WORK_TX_HALT, &hw->usb_flags) || hw->wlandev->hwremoved)
3038 while (!list_empty(&hw->ctlxq.pending)) {
3039 hfa384x_usbctlx_t *head;
3042 /* This is the first pending command */
3043 head = list_entry(hw->ctlxq.pending.next,
3044 hfa384x_usbctlx_t, list);
3046 /* We need to split this off to avoid a race condition */
3047 list_move_tail(&head->list, &hw->ctlxq.active);
3049 /* Fill the out packet */
3050 usb_fill_bulk_urb(&(hw->ctlx_urb), hw->usb,
3052 &(head->outbuf), ROUNDUP64(head->outbufsize),
3053 hfa384x_ctlxout_callback, hw);
3054 hw->ctlx_urb.transfer_flags |= USB_QUEUE_BULK;
3056 /* Now submit the URB and update the CTLX's state */
3057 result = SUBMIT_URB(&hw->ctlx_urb, GFP_ATOMIC);
3059 /* This CTLX is now running on the active queue */
3060 head->state = CTLX_REQ_SUBMITTED;
3062 /* Start the OUT wait timer */
3063 hw->req_timer_done = 0;
3064 hw->reqtimer.expires = jiffies + HZ;
3065 add_timer(&hw->reqtimer);
3067 /* Start the IN wait timer */
3068 hw->resp_timer_done = 0;
3069 hw->resptimer.expires = jiffies + 2 * HZ;
3070 add_timer(&hw->resptimer);
3075 if (result == -EPIPE) {
3076 /* The OUT pipe needs resetting, so put
3077 * this CTLX back in the "pending" queue
3078 * and schedule a reset ...
3080 netdev_warn(hw->wlandev->netdev,
3081 "%s tx pipe stalled: requesting reset\n",
3082 hw->wlandev->netdev->name);
3083 list_move(&head->list, &hw->ctlxq.pending);
3084 set_bit(WORK_TX_HALT, &hw->usb_flags);
3085 schedule_work(&hw->usb_work);
3089 if (result == -ESHUTDOWN) {
3090 netdev_warn(hw->wlandev->netdev, "%s urb shutdown!\n",
3091 hw->wlandev->netdev->name);
3095 netdev_err(hw->wlandev->netdev, "Failed to submit CTLX[%d]: error=%d\n",
3096 le16_to_cpu(head->outbuf.type), result);
3097 unlocked_usbctlx_complete(hw, head);
3101 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3104 /*----------------------------------------------------------------
3105 * hfa384x_usbin_callback
3107 * Callback for URBs on the BULKIN endpoint.
3110 * urb ptr to the completed urb
3119 ----------------------------------------------------------------*/
3120 static void hfa384x_usbin_callback(struct urb *urb)
3122 wlandevice_t *wlandev = urb->context;
3124 hfa384x_usbin_t *usbin = (hfa384x_usbin_t *)urb->transfer_buffer;
3125 struct sk_buff *skb = NULL;
3136 if (!wlandev || !wlandev->netdev || wlandev->hwremoved)
3143 skb = hw->rx_urb_skb;
3144 BUG_ON(!skb || (skb->data != urb->transfer_buffer));
3146 hw->rx_urb_skb = NULL;
3148 /* Check for error conditions within the URB */
3149 switch (urb->status) {
3153 /* Check for short packet */
3154 if (urb->actual_length == 0) {
3155 wlandev->netdev->stats.rx_errors++;
3156 wlandev->netdev->stats.rx_length_errors++;
3162 netdev_warn(hw->wlandev->netdev, "%s rx pipe stalled: requesting reset\n",
3163 wlandev->netdev->name);
3164 if (!test_and_set_bit(WORK_RX_HALT, &hw->usb_flags))
3165 schedule_work(&hw->usb_work);
3166 wlandev->netdev->stats.rx_errors++;
3173 if (!test_and_set_bit(THROTTLE_RX, &hw->usb_flags) &&
3174 !timer_pending(&hw->throttle)) {
3175 mod_timer(&hw->throttle, jiffies + THROTTLE_JIFFIES);
3177 wlandev->netdev->stats.rx_errors++;
3182 wlandev->netdev->stats.rx_over_errors++;
3188 pr_debug("status=%d, device removed.\n", urb->status);
3194 pr_debug("status=%d, urb explicitly unlinked.\n", urb->status);
3199 pr_debug("urb status=%d, transfer flags=0x%x\n",
3200 urb->status, urb->transfer_flags);
3201 wlandev->netdev->stats.rx_errors++;
3206 urb_status = urb->status;
3208 if (action != ABORT) {
3209 /* Repost the RX URB */
3210 result = submit_rx_urb(hw, GFP_ATOMIC);
3213 netdev_err(hw->wlandev->netdev,
3214 "Fatal, failed to resubmit rx_urb. error=%d\n",
3219 /* Handle any USB-IN packet */
3220 /* Note: the check of the sw_support field, the type field doesn't
3221 * have bit 12 set like the docs suggest.
3223 type = le16_to_cpu(usbin->type);
3224 if (HFA384x_USB_ISRXFRM(type)) {
3225 if (action == HANDLE) {
3226 if (usbin->txfrm.desc.sw_support == 0x0123) {
3227 hfa384x_usbin_txcompl(wlandev, usbin);
3229 skb_put(skb, sizeof(*usbin));
3230 hfa384x_usbin_rx(wlandev, skb);
3236 if (HFA384x_USB_ISTXFRM(type)) {
3237 if (action == HANDLE)
3238 hfa384x_usbin_txcompl(wlandev, usbin);
3242 case HFA384x_USB_INFOFRM:
3243 if (action == ABORT)
3245 if (action == HANDLE)
3246 hfa384x_usbin_info(wlandev, usbin);
3249 case HFA384x_USB_CMDRESP:
3250 case HFA384x_USB_WRIDRESP:
3251 case HFA384x_USB_RRIDRESP:
3252 case HFA384x_USB_WMEMRESP:
3253 case HFA384x_USB_RMEMRESP:
3254 /* ALWAYS, ALWAYS, ALWAYS handle this CTLX!!!! */
3255 hfa384x_usbin_ctlx(hw, usbin, urb_status);
3258 case HFA384x_USB_BUFAVAIL:
3259 pr_debug("Received BUFAVAIL packet, frmlen=%d\n",
3260 usbin->bufavail.frmlen);
3263 case HFA384x_USB_ERROR:
3264 pr_debug("Received USB_ERROR packet, errortype=%d\n",
3265 usbin->usberror.errortype);
3269 pr_debug("Unrecognized USBIN packet, type=%x, status=%d\n",
3270 usbin->type, urb_status);
3280 /*----------------------------------------------------------------
3281 * hfa384x_usbin_ctlx
3283 * We've received a URB containing a Prism2 "response" message.
3284 * This message needs to be matched up with a CTLX on the active
3285 * queue and our state updated accordingly.
3288 * hw ptr to hfa384x_t
3289 * usbin ptr to USB IN packet
3290 * urb_status status of this Bulk-In URB
3299 ----------------------------------------------------------------*/
3300 static void hfa384x_usbin_ctlx(hfa384x_t *hw, hfa384x_usbin_t *usbin,
3303 hfa384x_usbctlx_t *ctlx;
3305 unsigned long flags;
3308 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3310 /* There can be only one CTLX on the active queue
3311 * at any one time, and this is the CTLX that the
3312 * timers are waiting for.
3314 if (list_empty(&hw->ctlxq.active))
3317 /* Remove the "response timeout". It's possible that
3318 * we are already too late, and that the timeout is
3319 * already running. And that's just too bad for us,
3320 * because we could lose our CTLX from the active
3323 if (del_timer(&hw->resptimer) == 0) {
3324 if (hw->resp_timer_done == 0) {
3325 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3329 hw->resp_timer_done = 1;
3332 ctlx = get_active_ctlx(hw);
3334 if (urb_status != 0) {
3336 * Bad CTLX, so get rid of it. But we only
3337 * remove it from the active queue if we're no
3338 * longer expecting the OUT URB to complete.
3340 if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0)
3343 const __le16 intype = (usbin->type & ~cpu_to_le16(0x8000));
3346 * Check that our message is what we're expecting ...
3348 if (ctlx->outbuf.type != intype) {
3349 netdev_warn(hw->wlandev->netdev,
3350 "Expected IN[%d], received IN[%d] - ignored.\n",
3351 le16_to_cpu(ctlx->outbuf.type),
3352 le16_to_cpu(intype));
3356 /* This URB has succeeded, so grab the data ... */
3357 memcpy(&ctlx->inbuf, usbin, sizeof(ctlx->inbuf));
3359 switch (ctlx->state) {
3360 case CTLX_REQ_SUBMITTED:
3362 * We have received our response URB before
3363 * our request has been acknowledged. Odd,
3364 * but our OUT URB is still alive...
3366 pr_debug("Causality violation: please reboot Universe\n");
3367 ctlx->state = CTLX_RESP_COMPLETE;
3370 case CTLX_REQ_COMPLETE:
3372 * This is the usual path: our request
3373 * has already been acknowledged, and
3374 * now we have received the reply too.
3376 ctlx->state = CTLX_COMPLETE;
3377 unlocked_usbctlx_complete(hw, ctlx);
3383 * Throw this CTLX away ...
3385 netdev_err(hw->wlandev->netdev,
3386 "Matched IN URB, CTLX[%d] in invalid state(%s). Discarded.\n",
3387 le16_to_cpu(ctlx->outbuf.type),
3388 ctlxstr(ctlx->state));
3389 if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0)
3396 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3399 hfa384x_usbctlxq_run(hw);
3402 /*----------------------------------------------------------------
3403 * hfa384x_usbin_txcompl
3405 * At this point we have the results of a previous transmit.
3408 * wlandev wlan device
3409 * usbin ptr to the usb transfer buffer
3418 ----------------------------------------------------------------*/
3419 static void hfa384x_usbin_txcompl(wlandevice_t *wlandev,
3420 hfa384x_usbin_t *usbin)
3424 status = le16_to_cpu(usbin->type); /* yeah I know it says type... */
3426 /* Was there an error? */
3427 if (HFA384x_TXSTATUS_ISERROR(status))
3428 prism2sta_ev_txexc(wlandev, status);
3430 prism2sta_ev_tx(wlandev, status);
3433 /*----------------------------------------------------------------
3436 * At this point we have a successful received a rx frame packet.
3439 * wlandev wlan device
3440 * usbin ptr to the usb transfer buffer
3449 ----------------------------------------------------------------*/
3450 static void hfa384x_usbin_rx(wlandevice_t *wlandev, struct sk_buff *skb)
3452 hfa384x_usbin_t *usbin = (hfa384x_usbin_t *)skb->data;
3453 hfa384x_t *hw = wlandev->priv;
3455 struct p80211_rxmeta *rxmeta;
3459 /* Byte order convert once up front. */
3460 usbin->rxfrm.desc.status = le16_to_cpu(usbin->rxfrm.desc.status);
3461 usbin->rxfrm.desc.time = le32_to_cpu(usbin->rxfrm.desc.time);
3463 /* Now handle frame based on port# */
3464 switch (HFA384x_RXSTATUS_MACPORT_GET(usbin->rxfrm.desc.status)) {
3466 fc = le16_to_cpu(usbin->rxfrm.desc.frame_control);
3468 /* If exclude and we receive an unencrypted, drop it */
3469 if ((wlandev->hostwep & HOSTWEP_EXCLUDEUNENCRYPTED) &&
3470 !WLAN_GET_FC_ISWEP(fc)) {
3474 data_len = le16_to_cpu(usbin->rxfrm.desc.data_len);
3476 /* How much header data do we have? */
3477 hdrlen = p80211_headerlen(fc);
3479 /* Pull off the descriptor */
3480 skb_pull(skb, sizeof(hfa384x_rx_frame_t));
3482 /* Now shunt the header block up against the data block
3483 * with an "overlapping" copy
3485 memmove(skb_push(skb, hdrlen),
3486 &usbin->rxfrm.desc.frame_control, hdrlen);
3488 skb->dev = wlandev->netdev;
3489 skb->dev->last_rx = jiffies;
3491 /* And set the frame length properly */
3492 skb_trim(skb, data_len + hdrlen);
3494 /* The prism2 series does not return the CRC */
3495 memset(skb_put(skb, WLAN_CRC_LEN), 0xff, WLAN_CRC_LEN);
3497 skb_reset_mac_header(skb);
3499 /* Attach the rxmeta, set some stuff */
3500 p80211skb_rxmeta_attach(wlandev, skb);
3501 rxmeta = P80211SKB_RXMETA(skb);
3502 rxmeta->mactime = usbin->rxfrm.desc.time;
3503 rxmeta->rxrate = usbin->rxfrm.desc.rate;
3504 rxmeta->signal = usbin->rxfrm.desc.signal - hw->dbmadjust;
3505 rxmeta->noise = usbin->rxfrm.desc.silence - hw->dbmadjust;
3507 prism2sta_ev_rx(wlandev, skb);
3512 if (!HFA384x_RXSTATUS_ISFCSERR(usbin->rxfrm.desc.status)) {
3513 /* Copy to wlansnif skb */
3514 hfa384x_int_rxmonitor(wlandev, &usbin->rxfrm);
3517 pr_debug("Received monitor frame: FCSerr set\n");
3522 netdev_warn(hw->wlandev->netdev, "Received frame on unsupported port=%d\n",
3523 HFA384x_RXSTATUS_MACPORT_GET(
3524 usbin->rxfrm.desc.status));
3529 /*----------------------------------------------------------------
3530 * hfa384x_int_rxmonitor
3532 * Helper function for int_rx. Handles monitor frames.
3533 * Note that this function allocates space for the FCS and sets it
3534 * to 0xffffffff. The hfa384x doesn't give us the FCS value but the
3535 * higher layers expect it. 0xffffffff is used as a flag to indicate
3539 * wlandev wlan device structure
3540 * rxfrm rx descriptor read from card in int_rx
3546 * Allocates an skb and passes it up via the PF_PACKET interface.
3549 ----------------------------------------------------------------*/
3550 static void hfa384x_int_rxmonitor(wlandevice_t *wlandev,
3551 hfa384x_usb_rxfrm_t *rxfrm)
3553 hfa384x_rx_frame_t *rxdesc = &(rxfrm->desc);
3554 unsigned int hdrlen = 0;
3555 unsigned int datalen = 0;
3556 unsigned int skblen = 0;
3559 struct sk_buff *skb;
3560 hfa384x_t *hw = wlandev->priv;
3562 /* Remember the status, time, and data_len fields are in host order */
3563 /* Figure out how big the frame is */
3564 fc = le16_to_cpu(rxdesc->frame_control);
3565 hdrlen = p80211_headerlen(fc);
3566 datalen = le16_to_cpu(rxdesc->data_len);
3568 /* Allocate an ind message+framesize skb */
3569 skblen = sizeof(struct p80211_caphdr) + hdrlen + datalen + WLAN_CRC_LEN;
3571 /* sanity check the length */
3573 (sizeof(struct p80211_caphdr) +
3574 WLAN_HDR_A4_LEN + WLAN_DATA_MAXLEN + WLAN_CRC_LEN)) {
3575 pr_debug("overlen frm: len=%zd\n",
3576 skblen - sizeof(struct p80211_caphdr));
3579 skb = dev_alloc_skb(skblen);
3583 /* only prepend the prism header if in the right mode */
3584 if ((wlandev->netdev->type == ARPHRD_IEEE80211_PRISM) &&
3585 (hw->sniffhdr != 0)) {
3586 struct p80211_caphdr *caphdr;
3587 /* The NEW header format! */
3588 datap = skb_put(skb, sizeof(struct p80211_caphdr));
3589 caphdr = (struct p80211_caphdr *)datap;
3591 caphdr->version = htonl(P80211CAPTURE_VERSION);
3592 caphdr->length = htonl(sizeof(struct p80211_caphdr));
3593 caphdr->mactime = __cpu_to_be64(rxdesc->time) * 1000;
3594 caphdr->hosttime = __cpu_to_be64(jiffies);
3595 caphdr->phytype = htonl(4); /* dss_dot11_b */
3596 caphdr->channel = htonl(hw->sniff_channel);
3597 caphdr->datarate = htonl(rxdesc->rate);
3598 caphdr->antenna = htonl(0); /* unknown */
3599 caphdr->priority = htonl(0); /* unknown */
3600 caphdr->ssi_type = htonl(3); /* rssi_raw */
3601 caphdr->ssi_signal = htonl(rxdesc->signal);
3602 caphdr->ssi_noise = htonl(rxdesc->silence);
3603 caphdr->preamble = htonl(0); /* unknown */
3604 caphdr->encoding = htonl(1); /* cck */
3607 /* Copy the 802.11 header to the skb
3608 (ctl frames may be less than a full header) */
3609 datap = skb_put(skb, hdrlen);
3610 memcpy(datap, &(rxdesc->frame_control), hdrlen);
3612 /* If any, copy the data from the card to the skb */
3614 datap = skb_put(skb, datalen);
3615 memcpy(datap, rxfrm->data, datalen);
3617 /* check for unencrypted stuff if WEP bit set. */
3618 if (*(datap - hdrlen + 1) & 0x40) /* wep set */
3619 if ((*(datap) == 0xaa) && (*(datap + 1) == 0xaa))
3620 /* clear wep; it's the 802.2 header! */
3621 *(datap - hdrlen + 1) &= 0xbf;
3624 if (hw->sniff_fcs) {
3626 datap = skb_put(skb, WLAN_CRC_LEN);
3627 memset(datap, 0xff, WLAN_CRC_LEN);
3630 /* pass it back up */
3631 prism2sta_ev_rx(wlandev, skb);
3634 /*----------------------------------------------------------------
3635 * hfa384x_usbin_info
3637 * At this point we have a successful received a Prism2 info frame.
3640 * wlandev wlan device
3641 * usbin ptr to the usb transfer buffer
3650 ----------------------------------------------------------------*/
3651 static void hfa384x_usbin_info(wlandevice_t *wlandev, hfa384x_usbin_t *usbin)
3653 usbin->infofrm.info.framelen =
3654 le16_to_cpu(usbin->infofrm.info.framelen);
3655 prism2sta_ev_info(wlandev, &usbin->infofrm.info);
3658 /*----------------------------------------------------------------
3659 * hfa384x_usbout_callback
3661 * Callback for URBs on the BULKOUT endpoint.
3664 * urb ptr to the completed urb
3673 ----------------------------------------------------------------*/
3674 static void hfa384x_usbout_callback(struct urb *urb)
3676 wlandevice_t *wlandev = urb->context;
3677 hfa384x_usbout_t *usbout = urb->transfer_buffer;
3683 if (wlandev && wlandev->netdev) {
3684 switch (urb->status) {
3686 hfa384x_usbout_tx(wlandev, usbout);
3691 hfa384x_t *hw = wlandev->priv;
3693 netdev_warn(hw->wlandev->netdev,
3694 "%s tx pipe stalled: requesting reset\n",
3695 wlandev->netdev->name);
3696 if (!test_and_set_bit
3697 (WORK_TX_HALT, &hw->usb_flags))
3698 schedule_work(&hw->usb_work);
3699 wlandev->netdev->stats.tx_errors++;
3707 hfa384x_t *hw = wlandev->priv;
3709 if (!test_and_set_bit
3710 (THROTTLE_TX, &hw->usb_flags) &&
3711 !timer_pending(&hw->throttle)) {
3712 mod_timer(&hw->throttle,
3713 jiffies + THROTTLE_JIFFIES);
3715 wlandev->netdev->stats.tx_errors++;
3716 netif_stop_queue(wlandev->netdev);
3722 /* Ignorable errors */
3726 netdev_info(wlandev->netdev, "unknown urb->status=%d\n",
3728 wlandev->netdev->stats.tx_errors++;
3734 /*----------------------------------------------------------------
3735 * hfa384x_ctlxout_callback
3737 * Callback for control data on the BULKOUT endpoint.
3740 * urb ptr to the completed urb
3749 ----------------------------------------------------------------*/
3750 static void hfa384x_ctlxout_callback(struct urb *urb)
3752 hfa384x_t *hw = urb->context;
3753 int delete_resptimer = 0;
3756 hfa384x_usbctlx_t *ctlx;
3757 unsigned long flags;
3759 pr_debug("urb->status=%d\n", urb->status);
3763 if ((urb->status == -ESHUTDOWN) ||
3764 (urb->status == -ENODEV) || (hw == NULL))
3768 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3771 * Only one CTLX at a time on the "active" list, and
3772 * none at all if we are unplugged. However, we can
3773 * rely on the disconnect function to clean everything
3774 * up if someone unplugged the adapter.
3776 if (list_empty(&hw->ctlxq.active)) {
3777 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3782 * Having something on the "active" queue means
3783 * that we have timers to worry about ...
3785 if (del_timer(&hw->reqtimer) == 0) {
3786 if (hw->req_timer_done == 0) {
3788 * This timer was actually running while we
3789 * were trying to delete it. Let it terminate
3790 * gracefully instead.
3792 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3796 hw->req_timer_done = 1;
3799 ctlx = get_active_ctlx(hw);
3801 if (urb->status == 0) {
3802 /* Request portion of a CTLX is successful */
3803 switch (ctlx->state) {
3804 case CTLX_REQ_SUBMITTED:
3805 /* This OUT-ACK received before IN */
3806 ctlx->state = CTLX_REQ_COMPLETE;
3809 case CTLX_RESP_COMPLETE:
3810 /* IN already received before this OUT-ACK,
3811 * so this command must now be complete.
3813 ctlx->state = CTLX_COMPLETE;
3814 unlocked_usbctlx_complete(hw, ctlx);
3819 /* This is NOT a valid CTLX "success" state! */
3820 netdev_err(hw->wlandev->netdev,
3821 "Illegal CTLX[%d] success state(%s, %d) in OUT URB\n",
3822 le16_to_cpu(ctlx->outbuf.type),
3823 ctlxstr(ctlx->state), urb->status);
3827 /* If the pipe has stalled then we need to reset it */
3828 if ((urb->status == -EPIPE) &&
3829 !test_and_set_bit(WORK_TX_HALT, &hw->usb_flags)) {
3830 netdev_warn(hw->wlandev->netdev,
3831 "%s tx pipe stalled: requesting reset\n",
3832 hw->wlandev->netdev->name);
3833 schedule_work(&hw->usb_work);
3836 /* If someone cancels the OUT URB then its status
3837 * should be either -ECONNRESET or -ENOENT.
3839 ctlx->state = CTLX_REQ_FAILED;
3840 unlocked_usbctlx_complete(hw, ctlx);
3841 delete_resptimer = 1;
3846 if (delete_resptimer) {
3847 timer_ok = del_timer(&hw->resptimer);
3849 hw->resp_timer_done = 1;
3852 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3854 if (!timer_ok && (hw->resp_timer_done == 0)) {
3855 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3860 hfa384x_usbctlxq_run(hw);
3863 /*----------------------------------------------------------------
3864 * hfa384x_usbctlx_reqtimerfn
3866 * Timer response function for CTLX request timeouts. If this
3867 * function is called, it means that the callback for the OUT
3868 * URB containing a Prism2.x XXX_Request was never called.
3871 * data a ptr to the hfa384x_t
3880 ----------------------------------------------------------------*/
3881 static void hfa384x_usbctlx_reqtimerfn(unsigned long data)
3883 hfa384x_t *hw = (hfa384x_t *)data;
3884 unsigned long flags;
3886 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3888 hw->req_timer_done = 1;
3890 /* Removing the hardware automatically empties
3891 * the active list ...
3893 if (!list_empty(&hw->ctlxq.active)) {
3895 * We must ensure that our URB is removed from
3896 * the system, if it hasn't already expired.
3898 hw->ctlx_urb.transfer_flags |= URB_ASYNC_UNLINK;
3899 if (usb_unlink_urb(&hw->ctlx_urb) == -EINPROGRESS) {
3900 hfa384x_usbctlx_t *ctlx = get_active_ctlx(hw);
3902 ctlx->state = CTLX_REQ_FAILED;
3904 /* This URB was active, but has now been
3905 * cancelled. It will now have a status of
3906 * -ECONNRESET in the callback function.
3908 * We are cancelling this CTLX, so we're
3909 * not going to need to wait for a response.
3910 * The URB's callback function will check
3911 * that this timer is truly dead.
3913 if (del_timer(&hw->resptimer) != 0)
3914 hw->resp_timer_done = 1;
3918 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3921 /*----------------------------------------------------------------
3922 * hfa384x_usbctlx_resptimerfn
3924 * Timer response function for CTLX response timeouts. If this
3925 * function is called, it means that the callback for the IN
3926 * URB containing a Prism2.x XXX_Response was never called.
3929 * data a ptr to the hfa384x_t
3938 ----------------------------------------------------------------*/
3939 static void hfa384x_usbctlx_resptimerfn(unsigned long data)
3941 hfa384x_t *hw = (hfa384x_t *)data;
3942 unsigned long flags;
3944 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3946 hw->resp_timer_done = 1;
3948 /* The active list will be empty if the
3949 * adapter has been unplugged ...
3951 if (!list_empty(&hw->ctlxq.active)) {
3952 hfa384x_usbctlx_t *ctlx = get_active_ctlx(hw);
3954 if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0) {
3955 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3956 hfa384x_usbctlxq_run(hw);
3960 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3963 /*----------------------------------------------------------------
3964 * hfa384x_usb_throttlefn
3977 ----------------------------------------------------------------*/
3978 static void hfa384x_usb_throttlefn(unsigned long data)
3980 hfa384x_t *hw = (hfa384x_t *)data;
3981 unsigned long flags;
3983 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3986 * We need to check BOTH the RX and the TX throttle controls,
3987 * so we use the bitwise OR instead of the logical OR.
3989 pr_debug("flags=0x%lx\n", hw->usb_flags);
3990 if (!hw->wlandev->hwremoved &&
3991 ((test_and_clear_bit(THROTTLE_RX, &hw->usb_flags) &&
3992 !test_and_set_bit(WORK_RX_RESUME, &hw->usb_flags))
3994 (test_and_clear_bit(THROTTLE_TX, &hw->usb_flags) &&
3995 !test_and_set_bit(WORK_TX_RESUME, &hw->usb_flags))
3997 schedule_work(&hw->usb_work);
4000 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
4003 /*----------------------------------------------------------------
4004 * hfa384x_usbctlx_submit
4006 * Called from the doxxx functions to submit a CTLX to the queue
4009 * hw ptr to the hw struct
4010 * ctlx ctlx structure to enqueue
4013 * -ENODEV if the adapter is unplugged
4019 * process or interrupt
4020 ----------------------------------------------------------------*/
4021 static int hfa384x_usbctlx_submit(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx)
4023 unsigned long flags;
4025 spin_lock_irqsave(&hw->ctlxq.lock, flags);
4027 if (hw->wlandev->hwremoved) {
4028 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
4032 ctlx->state = CTLX_PENDING;
4033 list_add_tail(&ctlx->list, &hw->ctlxq.pending);
4034 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
4035 hfa384x_usbctlxq_run(hw);
4040 /*----------------------------------------------------------------
4043 * At this point we have finished a send of a frame. Mark the URB
4044 * as available and call ev_alloc to notify higher layers we're
4048 * wlandev wlan device
4049 * usbout ptr to the usb transfer buffer
4058 ----------------------------------------------------------------*/
4059 static void hfa384x_usbout_tx(wlandevice_t *wlandev, hfa384x_usbout_t *usbout)
4061 prism2sta_ev_alloc(wlandev);
4064 /*----------------------------------------------------------------
4065 * hfa384x_isgood_pdrcore
4067 * Quick check of PDR codes.
4070 * pdrcode PDR code number (host order)
4079 ----------------------------------------------------------------*/
4080 static int hfa384x_isgood_pdrcode(u16 pdrcode)
4083 case HFA384x_PDR_END_OF_PDA:
4084 case HFA384x_PDR_PCB_PARTNUM:
4085 case HFA384x_PDR_PDAVER:
4086 case HFA384x_PDR_NIC_SERIAL:
4087 case HFA384x_PDR_MKK_MEASUREMENTS:
4088 case HFA384x_PDR_NIC_RAMSIZE:
4089 case HFA384x_PDR_MFISUPRANGE:
4090 case HFA384x_PDR_CFISUPRANGE:
4091 case HFA384x_PDR_NICID:
4092 case HFA384x_PDR_MAC_ADDRESS:
4093 case HFA384x_PDR_REGDOMAIN:
4094 case HFA384x_PDR_ALLOWED_CHANNEL:
4095 case HFA384x_PDR_DEFAULT_CHANNEL:
4096 case HFA384x_PDR_TEMPTYPE:
4097 case HFA384x_PDR_IFR_SETTING:
4098 case HFA384x_PDR_RFR_SETTING:
4099 case HFA384x_PDR_HFA3861_BASELINE:
4100 case HFA384x_PDR_HFA3861_SHADOW:
4101 case HFA384x_PDR_HFA3861_IFRF:
4102 case HFA384x_PDR_HFA3861_CHCALSP:
4103 case HFA384x_PDR_HFA3861_CHCALI:
4104 case HFA384x_PDR_3842_NIC_CONFIG:
4105 case HFA384x_PDR_USB_ID:
4106 case HFA384x_PDR_PCI_ID:
4107 case HFA384x_PDR_PCI_IFCONF:
4108 case HFA384x_PDR_PCI_PMCONF:
4109 case HFA384x_PDR_RFENRGY:
4110 case HFA384x_PDR_HFA3861_MANF_TESTSP:
4111 case HFA384x_PDR_HFA3861_MANF_TESTI:
4115 if (pdrcode < 0x1000) {
4116 /* code is OK, but we don't know exactly what it is */
4117 pr_debug("Encountered unknown PDR#=0x%04x, assuming it's ok.\n",
4124 pr_debug("Encountered unknown PDR#=0x%04x, (>=0x1000), assuming it's bad.\n",