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);
180 static void hfa384x_usbin_ctlx(hfa384x_t *hw, hfa384x_usbin_t *usbin,
183 /*---------------------------------------------------*/
184 /* Functions to support the prism2 usb command queue */
186 static void hfa384x_usbctlxq_run(hfa384x_t *hw);
188 static void hfa384x_usbctlx_reqtimerfn(unsigned long data);
190 static void hfa384x_usbctlx_resptimerfn(unsigned long data);
192 static void hfa384x_usb_throttlefn(unsigned long data);
194 static void hfa384x_usbctlx_completion_task(unsigned long data);
196 static void hfa384x_usbctlx_reaper_task(unsigned long data);
198 static int hfa384x_usbctlx_submit(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
200 static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
202 struct usbctlx_completor {
203 int (*complete)(struct usbctlx_completor *);
207 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
208 hfa384x_usbctlx_t *ctlx,
209 struct usbctlx_completor *completor);
212 unlocked_usbctlx_cancel_async(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
214 static void hfa384x_cb_status(hfa384x_t *hw, const hfa384x_usbctlx_t *ctlx);
216 static void hfa384x_cb_rrid(hfa384x_t *hw, const hfa384x_usbctlx_t *ctlx);
219 usbctlx_get_status(const hfa384x_usb_cmdresp_t *cmdresp,
220 hfa384x_cmdresult_t *result);
223 usbctlx_get_rridresult(const hfa384x_usb_rridresp_t *rridresp,
224 hfa384x_rridresult_t *result);
226 /*---------------------------------------------------*/
227 /* Low level req/resp CTLX formatters and submitters */
229 hfa384x_docmd(hfa384x_t *hw,
231 hfa384x_metacmd_t *cmd,
232 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
235 hfa384x_dorrid(hfa384x_t *hw,
239 unsigned int riddatalen,
240 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
243 hfa384x_dowrid(hfa384x_t *hw,
247 unsigned int riddatalen,
248 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
251 hfa384x_dormem(hfa384x_t *hw,
257 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
260 hfa384x_dowmem(hfa384x_t *hw,
266 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
268 static int hfa384x_isgood_pdrcode(u16 pdrcode);
270 static inline const char *ctlxstr(CTLX_STATE s)
272 static const char * const ctlx_str[] = {
277 "Request packet submitted",
278 "Request packet completed",
279 "Response packet completed"
285 static inline hfa384x_usbctlx_t *get_active_ctlx(hfa384x_t *hw)
287 return list_entry(hw->ctlxq.active.next, hfa384x_usbctlx_t, list);
291 void dbprint_urb(struct urb *urb)
293 pr_debug("urb->pipe=0x%08x\n", urb->pipe);
294 pr_debug("urb->status=0x%08x\n", urb->status);
295 pr_debug("urb->transfer_flags=0x%08x\n", urb->transfer_flags);
296 pr_debug("urb->transfer_buffer=0x%08x\n",
297 (unsigned int)urb->transfer_buffer);
298 pr_debug("urb->transfer_buffer_length=0x%08x\n",
299 urb->transfer_buffer_length);
300 pr_debug("urb->actual_length=0x%08x\n", urb->actual_length);
301 pr_debug("urb->bandwidth=0x%08x\n", urb->bandwidth);
302 pr_debug("urb->setup_packet(ctl)=0x%08x\n",
303 (unsigned int)urb->setup_packet);
304 pr_debug("urb->start_frame(iso/irq)=0x%08x\n", urb->start_frame);
305 pr_debug("urb->interval(irq)=0x%08x\n", urb->interval);
306 pr_debug("urb->error_count(iso)=0x%08x\n", urb->error_count);
307 pr_debug("urb->timeout=0x%08x\n", urb->timeout);
308 pr_debug("urb->context=0x%08x\n", (unsigned int)urb->context);
309 pr_debug("urb->complete=0x%08x\n", (unsigned int)urb->complete);
313 /*----------------------------------------------------------------
316 * Listen for input data on the BULK-IN pipe. If the pipe has
317 * stalled then schedule it to be reset.
321 * memflags memory allocation flags
324 * error code from submission
328 ----------------------------------------------------------------*/
329 static int submit_rx_urb(hfa384x_t *hw, gfp_t memflags)
334 skb = dev_alloc_skb(sizeof(hfa384x_usbin_t));
340 /* Post the IN urb */
341 usb_fill_bulk_urb(&hw->rx_urb, hw->usb,
343 skb->data, sizeof(hfa384x_usbin_t),
344 hfa384x_usbin_callback, hw->wlandev);
346 hw->rx_urb_skb = skb;
349 if (!hw->wlandev->hwremoved &&
350 !test_bit(WORK_RX_HALT, &hw->usb_flags)) {
351 result = SUBMIT_URB(&hw->rx_urb, memflags);
353 /* Check whether we need to reset the RX pipe */
354 if (result == -EPIPE) {
355 netdev_warn(hw->wlandev->netdev,
356 "%s rx pipe stalled: requesting reset\n",
357 hw->wlandev->netdev->name);
358 if (!test_and_set_bit(WORK_RX_HALT, &hw->usb_flags))
359 schedule_work(&hw->usb_work);
363 /* Don't leak memory if anything should go wrong */
366 hw->rx_urb_skb = NULL;
373 /*----------------------------------------------------------------
376 * Prepares and submits the URB of transmitted data. If the
377 * submission fails then it will schedule the output pipe to
382 * tx_urb URB of data for transmission
383 * memflags memory allocation flags
386 * error code from submission
390 ----------------------------------------------------------------*/
391 static int submit_tx_urb(hfa384x_t *hw, struct urb *tx_urb, gfp_t memflags)
393 struct net_device *netdev = hw->wlandev->netdev;
397 if (netif_running(netdev)) {
398 if (!hw->wlandev->hwremoved &&
399 !test_bit(WORK_TX_HALT, &hw->usb_flags)) {
400 result = SUBMIT_URB(tx_urb, memflags);
402 /* Test whether we need to reset the TX pipe */
403 if (result == -EPIPE) {
404 netdev_warn(hw->wlandev->netdev,
405 "%s tx pipe stalled: requesting reset\n",
407 set_bit(WORK_TX_HALT, &hw->usb_flags);
408 schedule_work(&hw->usb_work);
409 } else if (result == 0) {
410 netif_stop_queue(netdev);
418 /*----------------------------------------------------------------
421 * There are some things that the USB stack cannot do while
422 * in interrupt context, so we arrange this function to run
423 * in process context.
426 * hw device structure
432 * process (by design)
433 ----------------------------------------------------------------*/
434 static void hfa384x_usb_defer(struct work_struct *data)
436 hfa384x_t *hw = container_of(data, struct hfa384x, usb_work);
437 struct net_device *netdev = hw->wlandev->netdev;
439 /* Don't bother trying to reset anything if the plug
440 * has been pulled ...
442 if (hw->wlandev->hwremoved)
445 /* Reception has stopped: try to reset the input pipe */
446 if (test_bit(WORK_RX_HALT, &hw->usb_flags)) {
449 usb_kill_urb(&hw->rx_urb); /* Cannot be holding spinlock! */
451 ret = usb_clear_halt(hw->usb, hw->endp_in);
453 netdev_err(hw->wlandev->netdev,
454 "Failed to clear rx pipe for %s: err=%d\n",
457 netdev_info(hw->wlandev->netdev, "%s rx pipe reset complete.\n",
459 clear_bit(WORK_RX_HALT, &hw->usb_flags);
460 set_bit(WORK_RX_RESUME, &hw->usb_flags);
464 /* Resume receiving data back from the device. */
465 if (test_bit(WORK_RX_RESUME, &hw->usb_flags)) {
468 ret = submit_rx_urb(hw, GFP_KERNEL);
470 netdev_err(hw->wlandev->netdev,
471 "Failed to resume %s rx pipe.\n",
474 clear_bit(WORK_RX_RESUME, &hw->usb_flags);
478 /* Transmission has stopped: try to reset the output pipe */
479 if (test_bit(WORK_TX_HALT, &hw->usb_flags)) {
482 usb_kill_urb(&hw->tx_urb);
483 ret = usb_clear_halt(hw->usb, hw->endp_out);
485 netdev_err(hw->wlandev->netdev,
486 "Failed to clear tx pipe for %s: err=%d\n",
489 netdev_info(hw->wlandev->netdev, "%s tx pipe reset complete.\n",
491 clear_bit(WORK_TX_HALT, &hw->usb_flags);
492 set_bit(WORK_TX_RESUME, &hw->usb_flags);
494 /* Stopping the BULK-OUT pipe also blocked
495 * us from sending any more CTLX URBs, so
496 * we need to re-run our queue ...
498 hfa384x_usbctlxq_run(hw);
502 /* Resume transmitting. */
503 if (test_and_clear_bit(WORK_TX_RESUME, &hw->usb_flags))
504 netif_wake_queue(hw->wlandev->netdev);
507 /*----------------------------------------------------------------
510 * Sets up the hfa384x_t data structure for use. Note this
511 * does _not_ initialize the actual hardware, just the data structures
512 * we use to keep track of its state.
515 * hw device structure
516 * irq device irq number
517 * iobase i/o base address for register access
518 * membase memory base address for register access
527 ----------------------------------------------------------------*/
528 void hfa384x_create(hfa384x_t *hw, struct usb_device *usb)
530 memset(hw, 0, sizeof(hfa384x_t));
533 /* set up the endpoints */
534 hw->endp_in = usb_rcvbulkpipe(usb, 1);
535 hw->endp_out = usb_sndbulkpipe(usb, 2);
537 /* Set up the waitq */
538 init_waitqueue_head(&hw->cmdq);
540 /* Initialize the command queue */
541 spin_lock_init(&hw->ctlxq.lock);
542 INIT_LIST_HEAD(&hw->ctlxq.pending);
543 INIT_LIST_HEAD(&hw->ctlxq.active);
544 INIT_LIST_HEAD(&hw->ctlxq.completing);
545 INIT_LIST_HEAD(&hw->ctlxq.reapable);
547 /* Initialize the authentication queue */
548 skb_queue_head_init(&hw->authq);
550 tasklet_init(&hw->reaper_bh,
551 hfa384x_usbctlx_reaper_task, (unsigned long)hw);
552 tasklet_init(&hw->completion_bh,
553 hfa384x_usbctlx_completion_task, (unsigned long)hw);
554 INIT_WORK(&hw->link_bh, prism2sta_processing_defer);
555 INIT_WORK(&hw->usb_work, hfa384x_usb_defer);
557 setup_timer(&hw->throttle, hfa384x_usb_throttlefn, (unsigned long)hw);
559 setup_timer(&hw->resptimer, hfa384x_usbctlx_resptimerfn,
562 setup_timer(&hw->reqtimer, hfa384x_usbctlx_reqtimerfn,
565 usb_init_urb(&hw->rx_urb);
566 usb_init_urb(&hw->tx_urb);
567 usb_init_urb(&hw->ctlx_urb);
569 hw->link_status = HFA384x_LINK_NOTCONNECTED;
570 hw->state = HFA384x_STATE_INIT;
572 INIT_WORK(&hw->commsqual_bh, prism2sta_commsqual_defer);
573 setup_timer(&hw->commsqual_timer, prism2sta_commsqual_timer,
577 /*----------------------------------------------------------------
580 * Partner to hfa384x_create(). This function cleans up the hw
581 * structure so that it can be freed by the caller using a simple
582 * kfree. Currently, this function is just a placeholder. If, at some
583 * point in the future, an hw in the 'shutdown' state requires a 'deep'
584 * kfree, this is where it should be done. Note that if this function
585 * is called on a _running_ hw structure, the drvr_stop() function is
589 * hw device structure
592 * nothing, this function is not allowed to fail.
598 ----------------------------------------------------------------*/
599 void hfa384x_destroy(hfa384x_t *hw)
603 if (hw->state == HFA384x_STATE_RUNNING)
604 hfa384x_drvr_stop(hw);
605 hw->state = HFA384x_STATE_PREINIT;
607 kfree(hw->scanresults);
608 hw->scanresults = NULL;
610 /* Now to clean out the auth queue */
611 while ((skb = skb_dequeue(&hw->authq)))
615 static hfa384x_usbctlx_t *usbctlx_alloc(void)
617 hfa384x_usbctlx_t *ctlx;
619 ctlx = kzalloc(sizeof(*ctlx),
620 in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
622 init_completion(&ctlx->done);
628 usbctlx_get_status(const hfa384x_usb_cmdresp_t *cmdresp,
629 hfa384x_cmdresult_t *result)
631 result->status = le16_to_cpu(cmdresp->status);
632 result->resp0 = le16_to_cpu(cmdresp->resp0);
633 result->resp1 = le16_to_cpu(cmdresp->resp1);
634 result->resp2 = le16_to_cpu(cmdresp->resp2);
636 pr_debug("cmdresult:status=0x%04x resp0=0x%04x resp1=0x%04x resp2=0x%04x\n",
637 result->status, result->resp0, result->resp1, result->resp2);
639 return result->status & HFA384x_STATUS_RESULT;
643 usbctlx_get_rridresult(const hfa384x_usb_rridresp_t *rridresp,
644 hfa384x_rridresult_t *result)
646 result->rid = le16_to_cpu(rridresp->rid);
647 result->riddata = rridresp->data;
648 result->riddata_len = ((le16_to_cpu(rridresp->frmlen) - 1) * 2);
651 /*----------------------------------------------------------------
653 * This completor must be passed to hfa384x_usbctlx_complete_sync()
654 * when processing a CTLX that returns a hfa384x_cmdresult_t structure.
655 ----------------------------------------------------------------*/
656 struct usbctlx_cmd_completor {
657 struct usbctlx_completor head;
659 const hfa384x_usb_cmdresp_t *cmdresp;
660 hfa384x_cmdresult_t *result;
663 static inline int usbctlx_cmd_completor_fn(struct usbctlx_completor *head)
665 struct usbctlx_cmd_completor *complete;
667 complete = (struct usbctlx_cmd_completor *)head;
668 return usbctlx_get_status(complete->cmdresp, complete->result);
671 static inline struct usbctlx_completor *init_cmd_completor(
672 struct usbctlx_cmd_completor
674 const hfa384x_usb_cmdresp_t
676 hfa384x_cmdresult_t *result)
678 completor->head.complete = usbctlx_cmd_completor_fn;
679 completor->cmdresp = cmdresp;
680 completor->result = result;
681 return &(completor->head);
684 /*----------------------------------------------------------------
686 * This completor must be passed to hfa384x_usbctlx_complete_sync()
687 * when processing a CTLX that reads a RID.
688 ----------------------------------------------------------------*/
689 struct usbctlx_rrid_completor {
690 struct usbctlx_completor head;
692 const hfa384x_usb_rridresp_t *rridresp;
694 unsigned int riddatalen;
697 static int usbctlx_rrid_completor_fn(struct usbctlx_completor *head)
699 struct usbctlx_rrid_completor *complete;
700 hfa384x_rridresult_t rridresult;
702 complete = (struct usbctlx_rrid_completor *)head;
703 usbctlx_get_rridresult(complete->rridresp, &rridresult);
705 /* Validate the length, note body len calculation in bytes */
706 if (rridresult.riddata_len != complete->riddatalen) {
707 pr_warn("RID len mismatch, rid=0x%04x hlen=%d fwlen=%d\n",
709 complete->riddatalen, rridresult.riddata_len);
713 memcpy(complete->riddata, rridresult.riddata, complete->riddatalen);
717 static inline struct usbctlx_completor *init_rrid_completor(
718 struct usbctlx_rrid_completor
720 const hfa384x_usb_rridresp_t
723 unsigned int riddatalen)
725 completor->head.complete = usbctlx_rrid_completor_fn;
726 completor->rridresp = rridresp;
727 completor->riddata = riddata;
728 completor->riddatalen = riddatalen;
729 return &(completor->head);
732 /*----------------------------------------------------------------
734 * Interprets the results of a synchronous RID-write
735 ----------------------------------------------------------------*/
736 #define init_wrid_completor init_cmd_completor
738 /*----------------------------------------------------------------
740 * Interprets the results of a synchronous memory-write
741 ----------------------------------------------------------------*/
742 #define init_wmem_completor init_cmd_completor
744 /*----------------------------------------------------------------
746 * Interprets the results of a synchronous memory-read
747 ----------------------------------------------------------------*/
748 struct usbctlx_rmem_completor {
749 struct usbctlx_completor head;
751 const hfa384x_usb_rmemresp_t *rmemresp;
756 static int usbctlx_rmem_completor_fn(struct usbctlx_completor *head)
758 struct usbctlx_rmem_completor *complete =
759 (struct usbctlx_rmem_completor *)head;
761 pr_debug("rmemresp:len=%d\n", complete->rmemresp->frmlen);
762 memcpy(complete->data, complete->rmemresp->data, complete->len);
766 static inline struct usbctlx_completor *init_rmem_completor(
767 struct usbctlx_rmem_completor
769 hfa384x_usb_rmemresp_t
774 completor->head.complete = usbctlx_rmem_completor_fn;
775 completor->rmemresp = rmemresp;
776 completor->data = data;
777 completor->len = len;
778 return &(completor->head);
781 /*----------------------------------------------------------------
784 * Ctlx_complete handler for async CMD type control exchanges.
785 * mark the hw struct as such.
787 * Note: If the handling is changed here, it should probably be
788 * changed in docmd as well.
792 * ctlx completed CTLX
801 ----------------------------------------------------------------*/
802 static void hfa384x_cb_status(hfa384x_t *hw, const hfa384x_usbctlx_t *ctlx)
804 if (ctlx->usercb != NULL) {
805 hfa384x_cmdresult_t cmdresult;
807 if (ctlx->state != CTLX_COMPLETE) {
808 memset(&cmdresult, 0, sizeof(cmdresult));
810 HFA384x_STATUS_RESULT_SET(HFA384x_CMD_ERR);
812 usbctlx_get_status(&ctlx->inbuf.cmdresp, &cmdresult);
815 ctlx->usercb(hw, &cmdresult, ctlx->usercb_data);
819 /*----------------------------------------------------------------
822 * CTLX completion handler for async RRID type control exchanges.
824 * Note: If the handling is changed here, it should probably be
825 * changed in dorrid as well.
829 * ctlx completed CTLX
838 ----------------------------------------------------------------*/
839 static void hfa384x_cb_rrid(hfa384x_t *hw, const hfa384x_usbctlx_t *ctlx)
841 if (ctlx->usercb != NULL) {
842 hfa384x_rridresult_t rridresult;
844 if (ctlx->state != CTLX_COMPLETE) {
845 memset(&rridresult, 0, sizeof(rridresult));
846 rridresult.rid = le16_to_cpu(ctlx->outbuf.rridreq.rid);
848 usbctlx_get_rridresult(&ctlx->inbuf.rridresp,
852 ctlx->usercb(hw, &rridresult, ctlx->usercb_data);
856 static inline int hfa384x_docmd_wait(hfa384x_t *hw, hfa384x_metacmd_t *cmd)
858 return hfa384x_docmd(hw, DOWAIT, cmd, NULL, NULL, NULL);
862 hfa384x_docmd_async(hfa384x_t *hw,
863 hfa384x_metacmd_t *cmd,
864 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
866 return hfa384x_docmd(hw, DOASYNC, cmd, cmdcb, usercb, usercb_data);
870 hfa384x_dorrid_wait(hfa384x_t *hw, u16 rid, void *riddata,
871 unsigned int riddatalen)
873 return hfa384x_dorrid(hw, DOWAIT,
874 rid, riddata, riddatalen, NULL, NULL, NULL);
878 hfa384x_dorrid_async(hfa384x_t *hw,
879 u16 rid, void *riddata, unsigned int riddatalen,
881 ctlx_usercb_t usercb, void *usercb_data)
883 return hfa384x_dorrid(hw, DOASYNC,
884 rid, riddata, riddatalen,
885 cmdcb, usercb, usercb_data);
889 hfa384x_dowrid_wait(hfa384x_t *hw, u16 rid, void *riddata,
890 unsigned int riddatalen)
892 return hfa384x_dowrid(hw, DOWAIT,
893 rid, riddata, riddatalen, NULL, NULL, NULL);
897 hfa384x_dowrid_async(hfa384x_t *hw,
898 u16 rid, void *riddata, unsigned int riddatalen,
900 ctlx_usercb_t usercb, void *usercb_data)
902 return hfa384x_dowrid(hw, DOASYNC,
903 rid, riddata, riddatalen,
904 cmdcb, usercb, usercb_data);
908 hfa384x_dormem_wait(hfa384x_t *hw,
909 u16 page, u16 offset, void *data, unsigned int len)
911 return hfa384x_dormem(hw, DOWAIT,
912 page, offset, data, len, NULL, NULL, NULL);
916 hfa384x_dormem_async(hfa384x_t *hw,
917 u16 page, u16 offset, void *data, unsigned int len,
919 ctlx_usercb_t usercb, void *usercb_data)
921 return hfa384x_dormem(hw, DOASYNC,
922 page, offset, data, len,
923 cmdcb, usercb, usercb_data);
927 hfa384x_dowmem_wait(hfa384x_t *hw,
928 u16 page, u16 offset, void *data, unsigned int len)
930 return hfa384x_dowmem(hw, DOWAIT,
931 page, offset, data, len, NULL, NULL, NULL);
935 hfa384x_dowmem_async(hfa384x_t *hw,
941 ctlx_usercb_t usercb, void *usercb_data)
943 return hfa384x_dowmem(hw, DOASYNC,
944 page, offset, data, len,
945 cmdcb, usercb, usercb_data);
948 /*----------------------------------------------------------------
949 * hfa384x_cmd_initialize
951 * Issues the initialize command and sets the hw->state based
955 * hw device structure
959 * >0 f/w reported error - f/w status code
960 * <0 driver reported error
966 ----------------------------------------------------------------*/
967 int hfa384x_cmd_initialize(hfa384x_t *hw)
971 hfa384x_metacmd_t cmd;
973 cmd.cmd = HFA384x_CMDCODE_INIT;
978 result = hfa384x_docmd_wait(hw, &cmd);
980 pr_debug("cmdresp.init: status=0x%04x, resp0=0x%04x, resp1=0x%04x, resp2=0x%04x\n",
982 cmd.result.resp0, cmd.result.resp1, cmd.result.resp2);
984 for (i = 0; i < HFA384x_NUMPORTS_MAX; i++)
985 hw->port_enabled[i] = 0;
988 hw->link_status = HFA384x_LINK_NOTCONNECTED;
993 /*----------------------------------------------------------------
994 * hfa384x_cmd_disable
996 * Issues the disable command to stop communications on one of
1000 * hw device structure
1001 * macport MAC port number (host order)
1005 * >0 f/w reported failure - f/w status code
1006 * <0 driver reported error (timeout|bad arg)
1012 ----------------------------------------------------------------*/
1013 int hfa384x_cmd_disable(hfa384x_t *hw, u16 macport)
1015 hfa384x_metacmd_t cmd;
1017 cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_DISABLE) |
1018 HFA384x_CMD_MACPORT_SET(macport);
1023 return hfa384x_docmd_wait(hw, &cmd);
1026 /*----------------------------------------------------------------
1027 * hfa384x_cmd_enable
1029 * Issues the enable command to enable communications on one of
1033 * hw device structure
1034 * macport MAC port number
1038 * >0 f/w reported failure - f/w status code
1039 * <0 driver reported error (timeout|bad arg)
1045 ----------------------------------------------------------------*/
1046 int hfa384x_cmd_enable(hfa384x_t *hw, u16 macport)
1048 hfa384x_metacmd_t cmd;
1050 cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_ENABLE) |
1051 HFA384x_CMD_MACPORT_SET(macport);
1056 return hfa384x_docmd_wait(hw, &cmd);
1059 /*----------------------------------------------------------------
1060 * hfa384x_cmd_monitor
1062 * Enables the 'monitor mode' of the MAC. Here's the description of
1063 * monitor mode that I've received thus far:
1065 * "The "monitor mode" of operation is that the MAC passes all
1066 * frames for which the PLCP checks are correct. All received
1067 * MPDUs are passed to the host with MAC Port = 7, with a
1068 * receive status of good, FCS error, or undecryptable. Passing
1069 * certain MPDUs is a violation of the 802.11 standard, but useful
1070 * for a debugging tool." Normal communication is not possible
1071 * while monitor mode is enabled.
1074 * hw device structure
1075 * enable a code (0x0b|0x0f) that enables/disables
1076 * monitor mode. (host order)
1080 * >0 f/w reported failure - f/w status code
1081 * <0 driver reported error (timeout|bad arg)
1087 ----------------------------------------------------------------*/
1088 int hfa384x_cmd_monitor(hfa384x_t *hw, u16 enable)
1090 hfa384x_metacmd_t cmd;
1092 cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_MONITOR) |
1093 HFA384x_CMD_AINFO_SET(enable);
1098 return hfa384x_docmd_wait(hw, &cmd);
1101 /*----------------------------------------------------------------
1102 * hfa384x_cmd_download
1104 * Sets the controls for the MAC controller code/data download
1105 * process. The arguments set the mode and address associated
1106 * with a download. Note that the aux registers should be enabled
1107 * prior to setting one of the download enable modes.
1110 * hw device structure
1111 * mode 0 - Disable programming and begin code exec
1112 * 1 - Enable volatile mem programming
1113 * 2 - Enable non-volatile mem programming
1114 * 3 - Program non-volatile section from NV download
1118 * highaddr For mode 1, sets the high & low order bits of
1119 * the "destination address". This address will be
1120 * the execution start address when download is
1121 * subsequently disabled.
1122 * For mode 2, sets the high & low order bits of
1123 * the destination in NV ram.
1124 * For modes 0 & 3, should be zero. (host order)
1125 * NOTE: these are CMD format.
1126 * codelen Length of the data to write in mode 2,
1127 * zero otherwise. (host order)
1131 * >0 f/w reported failure - f/w status code
1132 * <0 driver reported error (timeout|bad arg)
1138 ----------------------------------------------------------------*/
1139 int hfa384x_cmd_download(hfa384x_t *hw, u16 mode, u16 lowaddr,
1140 u16 highaddr, u16 codelen)
1142 hfa384x_metacmd_t cmd;
1144 pr_debug("mode=%d, lowaddr=0x%04x, highaddr=0x%04x, codelen=%d\n",
1145 mode, lowaddr, highaddr, codelen);
1147 cmd.cmd = (HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_DOWNLD) |
1148 HFA384x_CMD_PROGMODE_SET(mode));
1150 cmd.parm0 = lowaddr;
1151 cmd.parm1 = highaddr;
1152 cmd.parm2 = codelen;
1154 return hfa384x_docmd_wait(hw, &cmd);
1157 /*----------------------------------------------------------------
1160 * Perform a reset of the hfa38xx MAC core. We assume that the hw
1161 * structure is in its "created" state. That is, it is initialized
1162 * with proper values. Note that if a reset is done after the
1163 * device has been active for awhile, the caller might have to clean
1164 * up some leftover cruft in the hw structure.
1167 * hw device structure
1168 * holdtime how long (in ms) to hold the reset
1169 * settletime how long (in ms) to wait after releasing
1179 ----------------------------------------------------------------*/
1180 int hfa384x_corereset(hfa384x_t *hw, int holdtime, int settletime, int genesis)
1184 result = usb_reset_device(hw->usb);
1186 netdev_err(hw->wlandev->netdev, "usb_reset_device() failed, result=%d.\n",
1193 /*----------------------------------------------------------------
1194 * hfa384x_usbctlx_complete_sync
1196 * Waits for a synchronous CTLX object to complete,
1197 * and then handles the response.
1200 * hw device structure
1202 * completor functor object to decide what to
1203 * do with the CTLX's result.
1207 * -ERESTARTSYS Interrupted by a signal
1209 * -ENODEV Adapter was unplugged
1210 * ??? Result from completor
1216 ----------------------------------------------------------------*/
1217 static int hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
1218 hfa384x_usbctlx_t *ctlx,
1219 struct usbctlx_completor *completor)
1221 unsigned long flags;
1224 result = wait_for_completion_interruptible(&ctlx->done);
1226 spin_lock_irqsave(&hw->ctlxq.lock, flags);
1229 * We can only handle the CTLX if the USB disconnect
1230 * function has not run yet ...
1233 if (hw->wlandev->hwremoved) {
1234 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1236 } else if (result != 0) {
1240 * We were probably interrupted, so delete
1241 * this CTLX asynchronously, kill the timers
1242 * and the URB, and then start the next
1245 * NOTE: We can only delete the timers and
1246 * the URB if this CTLX is active.
1248 if (ctlx == get_active_ctlx(hw)) {
1249 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1251 del_singleshot_timer_sync(&hw->reqtimer);
1252 del_singleshot_timer_sync(&hw->resptimer);
1253 hw->req_timer_done = 1;
1254 hw->resp_timer_done = 1;
1255 usb_kill_urb(&hw->ctlx_urb);
1257 spin_lock_irqsave(&hw->ctlxq.lock, flags);
1262 * This scenario is so unlikely that I'm
1263 * happy with a grubby "goto" solution ...
1265 if (hw->wlandev->hwremoved)
1270 * The completion task will send this CTLX
1271 * to the reaper the next time it runs. We
1272 * are no longer in a hurry.
1275 ctlx->state = CTLX_REQ_FAILED;
1276 list_move_tail(&ctlx->list, &hw->ctlxq.completing);
1278 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1281 hfa384x_usbctlxq_run(hw);
1283 if (ctlx->state == CTLX_COMPLETE) {
1284 result = completor->complete(completor);
1286 netdev_warn(hw->wlandev->netdev, "CTLX[%d] error: state(%s)\n",
1287 le16_to_cpu(ctlx->outbuf.type),
1288 ctlxstr(ctlx->state));
1292 list_del(&ctlx->list);
1293 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1300 /*----------------------------------------------------------------
1303 * Constructs a command CTLX and submits it.
1305 * NOTE: Any changes to the 'post-submit' code in this function
1306 * need to be carried over to hfa384x_cbcmd() since the handling
1307 * is virtually identical.
1310 * hw device structure
1311 * mode DOWAIT or DOASYNC
1312 * cmd cmd structure. Includes all arguments and result
1313 * data points. All in host order. in host order
1314 * cmdcb command-specific callback
1315 * usercb user callback for async calls, NULL for DOWAIT calls
1316 * usercb_data user supplied data pointer for async calls, NULL
1322 * -ERESTARTSYS Awakened on signal
1323 * >0 command indicated error, Status and Resp0-2 are
1331 ----------------------------------------------------------------*/
1333 hfa384x_docmd(hfa384x_t *hw,
1335 hfa384x_metacmd_t *cmd,
1336 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1339 hfa384x_usbctlx_t *ctlx;
1341 ctlx = usbctlx_alloc();
1347 /* Initialize the command */
1348 ctlx->outbuf.cmdreq.type = cpu_to_le16(HFA384x_USB_CMDREQ);
1349 ctlx->outbuf.cmdreq.cmd = cpu_to_le16(cmd->cmd);
1350 ctlx->outbuf.cmdreq.parm0 = cpu_to_le16(cmd->parm0);
1351 ctlx->outbuf.cmdreq.parm1 = cpu_to_le16(cmd->parm1);
1352 ctlx->outbuf.cmdreq.parm2 = cpu_to_le16(cmd->parm2);
1354 ctlx->outbufsize = sizeof(ctlx->outbuf.cmdreq);
1356 pr_debug("cmdreq: cmd=0x%04x parm0=0x%04x parm1=0x%04x parm2=0x%04x\n",
1357 cmd->cmd, cmd->parm0, cmd->parm1, cmd->parm2);
1359 ctlx->reapable = mode;
1360 ctlx->cmdcb = cmdcb;
1361 ctlx->usercb = usercb;
1362 ctlx->usercb_data = usercb_data;
1364 result = hfa384x_usbctlx_submit(hw, ctlx);
1367 } else if (mode == DOWAIT) {
1368 struct usbctlx_cmd_completor completor;
1371 hfa384x_usbctlx_complete_sync(hw, ctlx,
1372 init_cmd_completor(&completor,
1384 /*----------------------------------------------------------------
1387 * Constructs a read rid CTLX and issues it.
1389 * NOTE: Any changes to the 'post-submit' code in this function
1390 * need to be carried over to hfa384x_cbrrid() since the handling
1391 * is virtually identical.
1394 * hw device structure
1395 * mode DOWAIT or DOASYNC
1396 * rid Read RID number (host order)
1397 * riddata Caller supplied buffer that MAC formatted RID.data
1398 * record will be written to for DOWAIT calls. Should
1399 * be NULL for DOASYNC calls.
1400 * riddatalen Buffer length for DOWAIT calls. Zero for DOASYNC calls.
1401 * cmdcb command callback for async calls, NULL for DOWAIT calls
1402 * usercb user callback for async calls, NULL for DOWAIT calls
1403 * usercb_data user supplied data pointer for async calls, NULL
1409 * -ERESTARTSYS Awakened on signal
1410 * -ENODATA riddatalen != macdatalen
1411 * >0 command indicated error, Status and Resp0-2 are
1417 * interrupt (DOASYNC)
1418 * process (DOWAIT or DOASYNC)
1419 ----------------------------------------------------------------*/
1421 hfa384x_dorrid(hfa384x_t *hw,
1425 unsigned int riddatalen,
1426 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1429 hfa384x_usbctlx_t *ctlx;
1431 ctlx = usbctlx_alloc();
1437 /* Initialize the command */
1438 ctlx->outbuf.rridreq.type = cpu_to_le16(HFA384x_USB_RRIDREQ);
1439 ctlx->outbuf.rridreq.frmlen =
1440 cpu_to_le16(sizeof(ctlx->outbuf.rridreq.rid));
1441 ctlx->outbuf.rridreq.rid = cpu_to_le16(rid);
1443 ctlx->outbufsize = sizeof(ctlx->outbuf.rridreq);
1445 ctlx->reapable = mode;
1446 ctlx->cmdcb = cmdcb;
1447 ctlx->usercb = usercb;
1448 ctlx->usercb_data = usercb_data;
1450 /* Submit the CTLX */
1451 result = hfa384x_usbctlx_submit(hw, ctlx);
1454 } else if (mode == DOWAIT) {
1455 struct usbctlx_rrid_completor completor;
1458 hfa384x_usbctlx_complete_sync(hw, ctlx,
1461 &ctlx->inbuf.rridresp,
1462 riddata, riddatalen));
1469 /*----------------------------------------------------------------
1472 * Constructs a write rid CTLX and issues it.
1474 * NOTE: Any changes to the 'post-submit' code in this function
1475 * need to be carried over to hfa384x_cbwrid() since the handling
1476 * is virtually identical.
1479 * hw device structure
1480 * enum cmd_mode DOWAIT or DOASYNC
1482 * riddata Data portion of RID formatted for MAC
1483 * riddatalen Length of the data portion in bytes
1484 * cmdcb command callback for async calls, NULL for DOWAIT calls
1485 * usercb user callback for async calls, NULL for DOWAIT calls
1486 * usercb_data user supplied data pointer for async calls
1490 * -ETIMEDOUT timed out waiting for register ready or
1491 * command completion
1492 * >0 command indicated error, Status and Resp0-2 are
1498 * interrupt (DOASYNC)
1499 * process (DOWAIT or DOASYNC)
1500 ----------------------------------------------------------------*/
1502 hfa384x_dowrid(hfa384x_t *hw,
1506 unsigned int riddatalen,
1507 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1510 hfa384x_usbctlx_t *ctlx;
1512 ctlx = usbctlx_alloc();
1518 /* Initialize the command */
1519 ctlx->outbuf.wridreq.type = cpu_to_le16(HFA384x_USB_WRIDREQ);
1520 ctlx->outbuf.wridreq.frmlen = cpu_to_le16((sizeof
1521 (ctlx->outbuf.wridreq.rid) +
1522 riddatalen + 1) / 2);
1523 ctlx->outbuf.wridreq.rid = cpu_to_le16(rid);
1524 memcpy(ctlx->outbuf.wridreq.data, riddata, riddatalen);
1526 ctlx->outbufsize = sizeof(ctlx->outbuf.wridreq.type) +
1527 sizeof(ctlx->outbuf.wridreq.frmlen) +
1528 sizeof(ctlx->outbuf.wridreq.rid) + riddatalen;
1530 ctlx->reapable = mode;
1531 ctlx->cmdcb = cmdcb;
1532 ctlx->usercb = usercb;
1533 ctlx->usercb_data = usercb_data;
1535 /* Submit the CTLX */
1536 result = hfa384x_usbctlx_submit(hw, ctlx);
1539 } else if (mode == DOWAIT) {
1540 struct usbctlx_cmd_completor completor;
1541 hfa384x_cmdresult_t wridresult;
1543 result = hfa384x_usbctlx_complete_sync(hw,
1547 &ctlx->inbuf.wridresp,
1555 /*----------------------------------------------------------------
1558 * Constructs a readmem CTLX and issues it.
1560 * NOTE: Any changes to the 'post-submit' code in this function
1561 * need to be carried over to hfa384x_cbrmem() since the handling
1562 * is virtually identical.
1565 * hw device structure
1566 * mode DOWAIT or DOASYNC
1567 * page MAC address space page (CMD format)
1568 * offset MAC address space offset
1569 * data Ptr to data buffer to receive read
1570 * len Length of the data to read (max == 2048)
1571 * cmdcb command callback for async calls, NULL for DOWAIT calls
1572 * usercb user callback for async calls, NULL for DOWAIT calls
1573 * usercb_data user supplied data pointer for async calls
1577 * -ETIMEDOUT timed out waiting for register ready or
1578 * command completion
1579 * >0 command indicated error, Status and Resp0-2 are
1585 * interrupt (DOASYNC)
1586 * process (DOWAIT or DOASYNC)
1587 ----------------------------------------------------------------*/
1589 hfa384x_dormem(hfa384x_t *hw,
1595 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1598 hfa384x_usbctlx_t *ctlx;
1600 ctlx = usbctlx_alloc();
1606 /* Initialize the command */
1607 ctlx->outbuf.rmemreq.type = cpu_to_le16(HFA384x_USB_RMEMREQ);
1608 ctlx->outbuf.rmemreq.frmlen =
1609 cpu_to_le16(sizeof(ctlx->outbuf.rmemreq.offset) +
1610 sizeof(ctlx->outbuf.rmemreq.page) + len);
1611 ctlx->outbuf.rmemreq.offset = cpu_to_le16(offset);
1612 ctlx->outbuf.rmemreq.page = cpu_to_le16(page);
1614 ctlx->outbufsize = sizeof(ctlx->outbuf.rmemreq);
1616 pr_debug("type=0x%04x frmlen=%d offset=0x%04x page=0x%04x\n",
1617 ctlx->outbuf.rmemreq.type,
1618 ctlx->outbuf.rmemreq.frmlen,
1619 ctlx->outbuf.rmemreq.offset, ctlx->outbuf.rmemreq.page);
1621 pr_debug("pktsize=%zd\n", ROUNDUP64(sizeof(ctlx->outbuf.rmemreq)));
1623 ctlx->reapable = mode;
1624 ctlx->cmdcb = cmdcb;
1625 ctlx->usercb = usercb;
1626 ctlx->usercb_data = usercb_data;
1628 result = hfa384x_usbctlx_submit(hw, ctlx);
1631 } else if (mode == DOWAIT) {
1632 struct usbctlx_rmem_completor completor;
1635 hfa384x_usbctlx_complete_sync(hw, ctlx,
1638 &ctlx->inbuf.rmemresp, data,
1646 /*----------------------------------------------------------------
1649 * Constructs a writemem CTLX and issues it.
1651 * NOTE: Any changes to the 'post-submit' code in this function
1652 * need to be carried over to hfa384x_cbwmem() since the handling
1653 * is virtually identical.
1656 * hw device structure
1657 * mode DOWAIT or DOASYNC
1658 * page MAC address space page (CMD format)
1659 * offset MAC address space offset
1660 * data Ptr to data buffer containing write data
1661 * len Length of the data to read (max == 2048)
1662 * cmdcb command callback for async calls, NULL for DOWAIT calls
1663 * usercb user callback for async calls, NULL for DOWAIT calls
1664 * usercb_data user supplied data pointer for async calls.
1668 * -ETIMEDOUT timed out waiting for register ready or
1669 * command completion
1670 * >0 command indicated error, Status and Resp0-2 are
1676 * interrupt (DOWAIT)
1677 * process (DOWAIT or DOASYNC)
1678 ----------------------------------------------------------------*/
1680 hfa384x_dowmem(hfa384x_t *hw,
1686 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1689 hfa384x_usbctlx_t *ctlx;
1691 pr_debug("page=0x%04x offset=0x%04x len=%d\n", page, offset, len);
1693 ctlx = usbctlx_alloc();
1699 /* Initialize the command */
1700 ctlx->outbuf.wmemreq.type = cpu_to_le16(HFA384x_USB_WMEMREQ);
1701 ctlx->outbuf.wmemreq.frmlen =
1702 cpu_to_le16(sizeof(ctlx->outbuf.wmemreq.offset) +
1703 sizeof(ctlx->outbuf.wmemreq.page) + len);
1704 ctlx->outbuf.wmemreq.offset = cpu_to_le16(offset);
1705 ctlx->outbuf.wmemreq.page = cpu_to_le16(page);
1706 memcpy(ctlx->outbuf.wmemreq.data, data, len);
1708 ctlx->outbufsize = sizeof(ctlx->outbuf.wmemreq.type) +
1709 sizeof(ctlx->outbuf.wmemreq.frmlen) +
1710 sizeof(ctlx->outbuf.wmemreq.offset) +
1711 sizeof(ctlx->outbuf.wmemreq.page) + len;
1713 ctlx->reapable = mode;
1714 ctlx->cmdcb = cmdcb;
1715 ctlx->usercb = usercb;
1716 ctlx->usercb_data = usercb_data;
1718 result = hfa384x_usbctlx_submit(hw, ctlx);
1721 } else if (mode == DOWAIT) {
1722 struct usbctlx_cmd_completor completor;
1723 hfa384x_cmdresult_t wmemresult;
1725 result = hfa384x_usbctlx_complete_sync(hw,
1729 &ctlx->inbuf.wmemresp,
1737 /*----------------------------------------------------------------
1738 * hfa384x_drvr_commtallies
1740 * Send a commtallies inquiry to the MAC. Note that this is an async
1741 * call that will result in an info frame arriving sometime later.
1744 * hw device structure
1753 ----------------------------------------------------------------*/
1754 int hfa384x_drvr_commtallies(hfa384x_t *hw)
1756 hfa384x_metacmd_t cmd;
1758 cmd.cmd = HFA384x_CMDCODE_INQ;
1759 cmd.parm0 = HFA384x_IT_COMMTALLIES;
1763 hfa384x_docmd_async(hw, &cmd, NULL, NULL, NULL);
1768 /*----------------------------------------------------------------
1769 * hfa384x_drvr_disable
1771 * Issues the disable command to stop communications on one of
1772 * the MACs 'ports'. Only macport 0 is valid for stations.
1773 * APs may also disable macports 1-6. Only ports that have been
1774 * previously enabled may be disabled.
1777 * hw device structure
1778 * macport MAC port number (host order)
1782 * >0 f/w reported failure - f/w status code
1783 * <0 driver reported error (timeout|bad arg)
1789 ----------------------------------------------------------------*/
1790 int hfa384x_drvr_disable(hfa384x_t *hw, u16 macport)
1794 if ((!hw->isap && macport != 0) ||
1795 (hw->isap && !(macport <= HFA384x_PORTID_MAX)) ||
1796 !(hw->port_enabled[macport])) {
1799 result = hfa384x_cmd_disable(hw, macport);
1801 hw->port_enabled[macport] = 0;
1806 /*----------------------------------------------------------------
1807 * hfa384x_drvr_enable
1809 * Issues the enable command to enable communications on one of
1810 * the MACs 'ports'. Only macport 0 is valid for stations.
1811 * APs may also enable macports 1-6. Only ports that are currently
1812 * disabled may be enabled.
1815 * hw device structure
1816 * macport MAC port number
1820 * >0 f/w reported failure - f/w status code
1821 * <0 driver reported error (timeout|bad arg)
1827 ----------------------------------------------------------------*/
1828 int hfa384x_drvr_enable(hfa384x_t *hw, u16 macport)
1832 if ((!hw->isap && macport != 0) ||
1833 (hw->isap && !(macport <= HFA384x_PORTID_MAX)) ||
1834 (hw->port_enabled[macport])) {
1837 result = hfa384x_cmd_enable(hw, macport);
1839 hw->port_enabled[macport] = 1;
1844 /*----------------------------------------------------------------
1845 * hfa384x_drvr_flashdl_enable
1847 * Begins the flash download state. Checks to see that we're not
1848 * already in a download state and that a port isn't enabled.
1849 * Sets the download state and retrieves the flash download
1850 * buffer location, buffer size, and timeout length.
1853 * hw device structure
1857 * >0 f/w reported error - f/w status code
1858 * <0 driver reported error
1864 ----------------------------------------------------------------*/
1865 int hfa384x_drvr_flashdl_enable(hfa384x_t *hw)
1870 /* Check that a port isn't active */
1871 for (i = 0; i < HFA384x_PORTID_MAX; i++) {
1872 if (hw->port_enabled[i]) {
1873 pr_debug("called when port enabled.\n");
1878 /* Check that we're not already in a download state */
1879 if (hw->dlstate != HFA384x_DLSTATE_DISABLED)
1882 /* Retrieve the buffer loc&size and timeout */
1883 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_DOWNLOADBUFFER,
1884 &(hw->bufinfo), sizeof(hw->bufinfo));
1888 hw->bufinfo.page = le16_to_cpu(hw->bufinfo.page);
1889 hw->bufinfo.offset = le16_to_cpu(hw->bufinfo.offset);
1890 hw->bufinfo.len = le16_to_cpu(hw->bufinfo.len);
1891 result = hfa384x_drvr_getconfig16(hw, HFA384x_RID_MAXLOADTIME,
1896 hw->dltimeout = le16_to_cpu(hw->dltimeout);
1898 pr_debug("flashdl_enable\n");
1900 hw->dlstate = HFA384x_DLSTATE_FLASHENABLED;
1905 /*----------------------------------------------------------------
1906 * hfa384x_drvr_flashdl_disable
1908 * Ends the flash download state. Note that this will cause the MAC
1909 * firmware to restart.
1912 * hw device structure
1916 * >0 f/w reported error - f/w status code
1917 * <0 driver reported error
1923 ----------------------------------------------------------------*/
1924 int hfa384x_drvr_flashdl_disable(hfa384x_t *hw)
1926 /* Check that we're already in the download state */
1927 if (hw->dlstate != HFA384x_DLSTATE_FLASHENABLED)
1930 pr_debug("flashdl_enable\n");
1932 /* There isn't much we can do at this point, so I don't */
1933 /* bother w/ the return value */
1934 hfa384x_cmd_download(hw, HFA384x_PROGMODE_DISABLE, 0, 0, 0);
1935 hw->dlstate = HFA384x_DLSTATE_DISABLED;
1940 /*----------------------------------------------------------------
1941 * hfa384x_drvr_flashdl_write
1943 * Performs a FLASH download of a chunk of data. First checks to see
1944 * that we're in the FLASH download state, then sets the download
1945 * mode, uses the aux functions to 1) copy the data to the flash
1946 * buffer, 2) sets the download 'write flash' mode, 3) readback and
1947 * compare. Lather rinse, repeat as many times an necessary to get
1948 * all the given data into flash.
1949 * When all data has been written using this function (possibly
1950 * repeatedly), call drvr_flashdl_disable() to end the download state
1951 * and restart the MAC.
1954 * hw device structure
1955 * daddr Card address to write to. (host order)
1956 * buf Ptr to data to write.
1957 * len Length of data (host order).
1961 * >0 f/w reported error - f/w status code
1962 * <0 driver reported error
1968 ----------------------------------------------------------------*/
1969 int hfa384x_drvr_flashdl_write(hfa384x_t *hw, u32 daddr, void *buf, u32 len)
1986 pr_debug("daddr=0x%08x len=%d\n", daddr, len);
1988 /* Check that we're in the flash download state */
1989 if (hw->dlstate != HFA384x_DLSTATE_FLASHENABLED)
1992 netdev_info(hw->wlandev->netdev,
1993 "Download %d bytes to flash @0x%06x\n", len, daddr);
1995 /* Convert to flat address for arithmetic */
1996 /* NOTE: dlbuffer RID stores the address in AUX format */
1998 HFA384x_ADDR_AUX_MKFLAT(hw->bufinfo.page, hw->bufinfo.offset);
1999 pr_debug("dlbuf.page=0x%04x dlbuf.offset=0x%04x dlbufaddr=0x%08x\n",
2000 hw->bufinfo.page, hw->bufinfo.offset, dlbufaddr);
2001 /* Calculations to determine how many fills of the dlbuffer to do
2002 * and how many USB wmemreq's to do for each fill. At this point
2003 * in time, the dlbuffer size and the wmemreq size are the same.
2004 * Therefore, nwrites should always be 1. The extra complexity
2005 * here is a hedge against future changes.
2008 /* Figure out how many times to do the flash programming */
2009 nburns = len / hw->bufinfo.len;
2010 nburns += (len % hw->bufinfo.len) ? 1 : 0;
2012 /* For each flash program cycle, how many USB wmemreq's are needed? */
2013 nwrites = hw->bufinfo.len / HFA384x_USB_RWMEM_MAXLEN;
2014 nwrites += (hw->bufinfo.len % HFA384x_USB_RWMEM_MAXLEN) ? 1 : 0;
2017 for (i = 0; i < nburns; i++) {
2018 /* Get the dest address and len */
2019 burnlen = (len - (hw->bufinfo.len * i)) > hw->bufinfo.len ?
2020 hw->bufinfo.len : (len - (hw->bufinfo.len * i));
2021 burndaddr = daddr + (hw->bufinfo.len * i);
2022 burnlo = HFA384x_ADDR_CMD_MKOFF(burndaddr);
2023 burnhi = HFA384x_ADDR_CMD_MKPAGE(burndaddr);
2025 netdev_info(hw->wlandev->netdev, "Writing %d bytes to flash @0x%06x\n",
2026 burnlen, burndaddr);
2028 /* Set the download mode */
2029 result = hfa384x_cmd_download(hw, HFA384x_PROGMODE_NV,
2030 burnlo, burnhi, burnlen);
2032 netdev_err(hw->wlandev->netdev,
2033 "download(NV,lo=%x,hi=%x,len=%x) cmd failed, result=%d. Aborting d/l\n",
2034 burnlo, burnhi, burnlen, result);
2038 /* copy the data to the flash download buffer */
2039 for (j = 0; j < nwrites; j++) {
2041 (i * hw->bufinfo.len) +
2042 (j * HFA384x_USB_RWMEM_MAXLEN);
2044 writepage = HFA384x_ADDR_CMD_MKPAGE(dlbufaddr +
2045 (j * HFA384x_USB_RWMEM_MAXLEN));
2046 writeoffset = HFA384x_ADDR_CMD_MKOFF(dlbufaddr +
2047 (j * HFA384x_USB_RWMEM_MAXLEN));
2049 writelen = burnlen - (j * HFA384x_USB_RWMEM_MAXLEN);
2050 writelen = writelen > HFA384x_USB_RWMEM_MAXLEN ?
2051 HFA384x_USB_RWMEM_MAXLEN : writelen;
2053 result = hfa384x_dowmem_wait(hw,
2056 writebuf, writelen);
2059 /* set the download 'write flash' mode */
2060 result = hfa384x_cmd_download(hw,
2061 HFA384x_PROGMODE_NVWRITE,
2064 netdev_err(hw->wlandev->netdev,
2065 "download(NVWRITE,lo=%x,hi=%x,len=%x) cmd failed, result=%d. Aborting d/l\n",
2066 burnlo, burnhi, burnlen, result);
2070 /* TODO: We really should do a readback and compare. */
2075 /* Leave the firmware in the 'post-prog' mode. flashdl_disable will */
2076 /* actually disable programming mode. Remember, that will cause the */
2077 /* the firmware to effectively reset itself. */
2082 /*----------------------------------------------------------------
2083 * hfa384x_drvr_getconfig
2085 * Performs the sequence necessary to read a config/info item.
2088 * hw device structure
2089 * rid config/info record id (host order)
2090 * buf host side record buffer. Upon return it will
2091 * contain the body portion of the record (minus the
2093 * len buffer length (in bytes, should match record length)
2097 * >0 f/w reported error - f/w status code
2098 * <0 driver reported error
2099 * -ENODATA length mismatch between argument and retrieved
2106 ----------------------------------------------------------------*/
2107 int hfa384x_drvr_getconfig(hfa384x_t *hw, u16 rid, void *buf, u16 len)
2109 return hfa384x_dorrid_wait(hw, rid, buf, len);
2112 /*----------------------------------------------------------------
2113 * hfa384x_drvr_getconfig_async
2115 * Performs the sequence necessary to perform an async read of
2116 * of a config/info item.
2119 * hw device structure
2120 * rid config/info record id (host order)
2121 * buf host side record buffer. Upon return it will
2122 * contain the body portion of the record (minus the
2124 * len buffer length (in bytes, should match record length)
2125 * cbfn caller supplied callback, called when the command
2126 * is done (successful or not).
2127 * cbfndata pointer to some caller supplied data that will be
2128 * passed in as an argument to the cbfn.
2131 * nothing the cbfn gets a status argument identifying if
2134 * Queues an hfa384x_usbcmd_t for subsequent execution.
2138 ----------------------------------------------------------------*/
2140 hfa384x_drvr_getconfig_async(hfa384x_t *hw,
2141 u16 rid, ctlx_usercb_t usercb, void *usercb_data)
2143 return hfa384x_dorrid_async(hw, rid, NULL, 0,
2144 hfa384x_cb_rrid, usercb, usercb_data);
2147 /*----------------------------------------------------------------
2148 * hfa384x_drvr_setconfig_async
2150 * Performs the sequence necessary to write a config/info item.
2153 * hw device structure
2154 * rid config/info record id (in host order)
2155 * buf host side record buffer
2156 * len buffer length (in bytes)
2157 * usercb completion callback
2158 * usercb_data completion callback argument
2162 * >0 f/w reported error - f/w status code
2163 * <0 driver reported error
2169 ----------------------------------------------------------------*/
2171 hfa384x_drvr_setconfig_async(hfa384x_t *hw,
2174 u16 len, ctlx_usercb_t usercb, void *usercb_data)
2176 return hfa384x_dowrid_async(hw, rid, buf, len,
2177 hfa384x_cb_status, usercb, usercb_data);
2180 /*----------------------------------------------------------------
2181 * hfa384x_drvr_ramdl_disable
2183 * Ends the ram download state.
2186 * hw device structure
2190 * >0 f/w reported error - f/w status code
2191 * <0 driver reported error
2197 ----------------------------------------------------------------*/
2198 int hfa384x_drvr_ramdl_disable(hfa384x_t *hw)
2200 /* Check that we're already in the download state */
2201 if (hw->dlstate != HFA384x_DLSTATE_RAMENABLED)
2204 pr_debug("ramdl_disable()\n");
2206 /* There isn't much we can do at this point, so I don't */
2207 /* bother w/ the return value */
2208 hfa384x_cmd_download(hw, HFA384x_PROGMODE_DISABLE, 0, 0, 0);
2209 hw->dlstate = HFA384x_DLSTATE_DISABLED;
2214 /*----------------------------------------------------------------
2215 * hfa384x_drvr_ramdl_enable
2217 * Begins the ram download state. Checks to see that we're not
2218 * already in a download state and that a port isn't enabled.
2219 * Sets the download state and calls cmd_download with the
2220 * ENABLE_VOLATILE subcommand and the exeaddr argument.
2223 * hw device structure
2224 * exeaddr the card execution address that will be
2225 * jumped to when ramdl_disable() is called
2230 * >0 f/w reported error - f/w status code
2231 * <0 driver reported error
2237 ----------------------------------------------------------------*/
2238 int hfa384x_drvr_ramdl_enable(hfa384x_t *hw, u32 exeaddr)
2245 /* Check that a port isn't active */
2246 for (i = 0; i < HFA384x_PORTID_MAX; i++) {
2247 if (hw->port_enabled[i]) {
2248 netdev_err(hw->wlandev->netdev,
2249 "Can't download with a macport enabled.\n");
2254 /* Check that we're not already in a download state */
2255 if (hw->dlstate != HFA384x_DLSTATE_DISABLED) {
2256 netdev_err(hw->wlandev->netdev, "Download state not disabled.\n");
2260 pr_debug("ramdl_enable, exeaddr=0x%08x\n", exeaddr);
2262 /* Call the download(1,addr) function */
2263 lowaddr = HFA384x_ADDR_CMD_MKOFF(exeaddr);
2264 hiaddr = HFA384x_ADDR_CMD_MKPAGE(exeaddr);
2266 result = hfa384x_cmd_download(hw, HFA384x_PROGMODE_RAM,
2267 lowaddr, hiaddr, 0);
2270 /* Set the download state */
2271 hw->dlstate = HFA384x_DLSTATE_RAMENABLED;
2273 pr_debug("cmd_download(0x%04x, 0x%04x) failed, result=%d.\n",
2274 lowaddr, hiaddr, result);
2280 /*----------------------------------------------------------------
2281 * hfa384x_drvr_ramdl_write
2283 * Performs a RAM download of a chunk of data. First checks to see
2284 * that we're in the RAM download state, then uses the [read|write]mem USB
2285 * commands to 1) copy the data, 2) readback and compare. The download
2286 * state is unaffected. When all data has been written using
2287 * this function, call drvr_ramdl_disable() to end the download state
2288 * and restart the MAC.
2291 * hw device structure
2292 * daddr Card address to write to. (host order)
2293 * buf Ptr to data to write.
2294 * len Length of data (host order).
2298 * >0 f/w reported error - f/w status code
2299 * <0 driver reported error
2305 ----------------------------------------------------------------*/
2306 int hfa384x_drvr_ramdl_write(hfa384x_t *hw, u32 daddr, void *buf, u32 len)
2317 /* Check that we're in the ram download state */
2318 if (hw->dlstate != HFA384x_DLSTATE_RAMENABLED)
2321 netdev_info(hw->wlandev->netdev, "Writing %d bytes to ram @0x%06x\n",
2324 /* How many dowmem calls? */
2325 nwrites = len / HFA384x_USB_RWMEM_MAXLEN;
2326 nwrites += len % HFA384x_USB_RWMEM_MAXLEN ? 1 : 0;
2328 /* Do blocking wmem's */
2329 for (i = 0; i < nwrites; i++) {
2330 /* make address args */
2331 curraddr = daddr + (i * HFA384x_USB_RWMEM_MAXLEN);
2332 currpage = HFA384x_ADDR_CMD_MKPAGE(curraddr);
2333 curroffset = HFA384x_ADDR_CMD_MKOFF(curraddr);
2334 currlen = len - (i * HFA384x_USB_RWMEM_MAXLEN);
2335 if (currlen > HFA384x_USB_RWMEM_MAXLEN)
2336 currlen = HFA384x_USB_RWMEM_MAXLEN;
2338 /* Do blocking ctlx */
2339 result = hfa384x_dowmem_wait(hw,
2343 (i * HFA384x_USB_RWMEM_MAXLEN),
2349 /* TODO: We really should have a readback. */
2355 /*----------------------------------------------------------------
2356 * hfa384x_drvr_readpda
2358 * Performs the sequence to read the PDA space. Note there is no
2359 * drvr_writepda() function. Writing a PDA is
2360 * generally implemented by a calling component via calls to
2361 * cmd_download and writing to the flash download buffer via the
2365 * hw device structure
2366 * buf buffer to store PDA in
2371 * >0 f/w reported error - f/w status code
2372 * <0 driver reported error
2373 * -ETIMEDOUT timeout waiting for the cmd regs to become
2374 * available, or waiting for the control reg
2375 * to indicate the Aux port is enabled.
2376 * -ENODATA the buffer does NOT contain a valid PDA.
2377 * Either the card PDA is bad, or the auxdata
2378 * reads are giving us garbage.
2384 * process or non-card interrupt.
2385 ----------------------------------------------------------------*/
2386 int hfa384x_drvr_readpda(hfa384x_t *hw, void *buf, unsigned int len)
2392 int currpdr = 0; /* word offset of the current pdr */
2394 u16 pdrlen; /* pdr length in bytes, host order */
2395 u16 pdrcode; /* pdr code, host order */
2403 HFA3842_PDA_BASE, 0}, {
2404 HFA3841_PDA_BASE, 0}, {
2405 HFA3841_PDA_BOGUS_BASE, 0}
2408 /* Read the pda from each known address. */
2409 for (i = 0; i < ARRAY_SIZE(pdaloc); i++) {
2411 currpage = HFA384x_ADDR_CMD_MKPAGE(pdaloc[i].cardaddr);
2412 curroffset = HFA384x_ADDR_CMD_MKOFF(pdaloc[i].cardaddr);
2414 /* units of bytes */
2415 result = hfa384x_dormem_wait(hw, currpage, curroffset, buf,
2419 netdev_warn(hw->wlandev->netdev,
2420 "Read from index %zd failed, continuing\n",
2425 /* Test for garbage */
2426 pdaok = 1; /* initially assume good */
2428 while (pdaok && morepdrs) {
2429 pdrlen = le16_to_cpu(pda[currpdr]) * 2;
2430 pdrcode = le16_to_cpu(pda[currpdr + 1]);
2431 /* Test the record length */
2432 if (pdrlen > HFA384x_PDR_LEN_MAX || pdrlen == 0) {
2433 netdev_err(hw->wlandev->netdev,
2434 "pdrlen invalid=%d\n", pdrlen);
2439 if (!hfa384x_isgood_pdrcode(pdrcode)) {
2440 netdev_err(hw->wlandev->netdev, "pdrcode invalid=%d\n",
2445 /* Test for completion */
2446 if (pdrcode == HFA384x_PDR_END_OF_PDA)
2449 /* Move to the next pdr (if necessary) */
2451 /* note the access to pda[], need words here */
2452 currpdr += le16_to_cpu(pda[currpdr]) + 1;
2456 netdev_info(hw->wlandev->netdev,
2457 "PDA Read from 0x%08x in %s space.\n",
2459 pdaloc[i].auxctl == 0 ? "EXTDS" :
2460 pdaloc[i].auxctl == 1 ? "NV" :
2461 pdaloc[i].auxctl == 2 ? "PHY" :
2462 pdaloc[i].auxctl == 3 ? "ICSRAM" :
2467 result = pdaok ? 0 : -ENODATA;
2470 pr_debug("Failure: pda is not okay\n");
2475 /*----------------------------------------------------------------
2476 * hfa384x_drvr_setconfig
2478 * Performs the sequence necessary to write a config/info item.
2481 * hw device structure
2482 * rid config/info record id (in host order)
2483 * buf host side record buffer
2484 * len buffer length (in bytes)
2488 * >0 f/w reported error - f/w status code
2489 * <0 driver reported error
2495 ----------------------------------------------------------------*/
2496 int hfa384x_drvr_setconfig(hfa384x_t *hw, u16 rid, void *buf, u16 len)
2498 return hfa384x_dowrid_wait(hw, rid, buf, len);
2501 /*----------------------------------------------------------------
2502 * hfa384x_drvr_start
2504 * Issues the MAC initialize command, sets up some data structures,
2505 * and enables the interrupts. After this function completes, the
2506 * low-level stuff should be ready for any/all commands.
2509 * hw device structure
2512 * >0 f/w reported error - f/w status code
2513 * <0 driver reported error
2519 ----------------------------------------------------------------*/
2521 int hfa384x_drvr_start(hfa384x_t *hw)
2523 int result, result1, result2;
2528 /* Clear endpoint stalls - but only do this if the endpoint
2529 * is showing a stall status. Some prism2 cards seem to behave
2530 * badly if a clear_halt is called when the endpoint is already
2534 usb_get_status(hw->usb, USB_RECIP_ENDPOINT, hw->endp_in, &status);
2536 netdev_err(hw->wlandev->netdev, "Cannot get bulk in endpoint status.\n");
2539 if ((status == 1) && usb_clear_halt(hw->usb, hw->endp_in))
2540 netdev_err(hw->wlandev->netdev, "Failed to reset bulk in endpoint.\n");
2543 usb_get_status(hw->usb, USB_RECIP_ENDPOINT, hw->endp_out, &status);
2545 netdev_err(hw->wlandev->netdev, "Cannot get bulk out endpoint status.\n");
2548 if ((status == 1) && usb_clear_halt(hw->usb, hw->endp_out))
2549 netdev_err(hw->wlandev->netdev, "Failed to reset bulk out endpoint.\n");
2551 /* Synchronous unlink, in case we're trying to restart the driver */
2552 usb_kill_urb(&hw->rx_urb);
2554 /* Post the IN urb */
2555 result = submit_rx_urb(hw, GFP_KERNEL);
2557 netdev_err(hw->wlandev->netdev,
2558 "Fatal, failed to submit RX URB, result=%d\n",
2563 /* Call initialize twice, with a 1 second sleep in between.
2564 * This is a nasty work-around since many prism2 cards seem to
2565 * need time to settle after an init from cold. The second
2566 * call to initialize in theory is not necessary - but we call
2567 * it anyway as a double insurance policy:
2568 * 1) If the first init should fail, the second may well succeed
2569 * and the card can still be used
2570 * 2) It helps ensures all is well with the card after the first
2571 * init and settle time.
2573 result1 = hfa384x_cmd_initialize(hw);
2575 result = hfa384x_cmd_initialize(hw);
2579 netdev_err(hw->wlandev->netdev,
2580 "cmd_initialize() failed on two attempts, results %d and %d\n",
2582 usb_kill_urb(&hw->rx_urb);
2585 pr_debug("First cmd_initialize() failed (result %d),\n",
2587 pr_debug("but second attempt succeeded. All should be ok\n");
2589 } else if (result2 != 0) {
2590 netdev_warn(hw->wlandev->netdev, "First cmd_initialize() succeeded, but second attempt failed (result=%d)\n",
2592 netdev_warn(hw->wlandev->netdev,
2593 "Most likely the card will be functional\n");
2597 hw->state = HFA384x_STATE_RUNNING;
2603 /*----------------------------------------------------------------
2606 * Shuts down the MAC to the point where it is safe to unload the
2607 * driver. Any subsystem that may be holding a data or function
2608 * ptr into the driver must be cleared/deinitialized.
2611 * hw device structure
2614 * >0 f/w reported error - f/w status code
2615 * <0 driver reported error
2621 ----------------------------------------------------------------*/
2622 int hfa384x_drvr_stop(hfa384x_t *hw)
2628 /* There's no need for spinlocks here. The USB "disconnect"
2629 * function sets this "removed" flag and then calls us.
2631 if (!hw->wlandev->hwremoved) {
2632 /* Call initialize to leave the MAC in its 'reset' state */
2633 hfa384x_cmd_initialize(hw);
2635 /* Cancel the rxurb */
2636 usb_kill_urb(&hw->rx_urb);
2639 hw->link_status = HFA384x_LINK_NOTCONNECTED;
2640 hw->state = HFA384x_STATE_INIT;
2642 del_timer_sync(&hw->commsqual_timer);
2644 /* Clear all the port status */
2645 for (i = 0; i < HFA384x_NUMPORTS_MAX; i++)
2646 hw->port_enabled[i] = 0;
2651 /*----------------------------------------------------------------
2652 * hfa384x_drvr_txframe
2654 * Takes a frame from prism2sta and queues it for transmission.
2657 * hw device structure
2658 * skb packet buffer struct. Contains an 802.11
2660 * p80211_hdr points to the 802.11 header for the packet.
2662 * 0 Success and more buffs available
2663 * 1 Success but no more buffs
2664 * 2 Allocation failure
2665 * 4 Buffer full or queue busy
2671 ----------------------------------------------------------------*/
2672 int hfa384x_drvr_txframe(hfa384x_t *hw, struct sk_buff *skb,
2673 union p80211_hdr *p80211_hdr,
2674 struct p80211_metawep *p80211_wep)
2676 int usbpktlen = sizeof(hfa384x_tx_frame_t);
2681 if (hw->tx_urb.status == -EINPROGRESS) {
2682 netdev_warn(hw->wlandev->netdev, "TX URB already in use\n");
2687 /* Build Tx frame structure */
2688 /* Set up the control field */
2689 memset(&hw->txbuff.txfrm.desc, 0, sizeof(hw->txbuff.txfrm.desc));
2691 /* Setup the usb type field */
2692 hw->txbuff.type = cpu_to_le16(HFA384x_USB_TXFRM);
2694 /* Set up the sw_support field to identify this frame */
2695 hw->txbuff.txfrm.desc.sw_support = 0x0123;
2697 /* Tx complete and Tx exception disable per dleach. Might be causing
2700 /* #define DOEXC SLP -- doboth breaks horribly under load, doexc less so. */
2702 hw->txbuff.txfrm.desc.tx_control =
2703 HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
2704 HFA384x_TX_TXEX_SET(1) | HFA384x_TX_TXOK_SET(1);
2705 #elif defined(DOEXC)
2706 hw->txbuff.txfrm.desc.tx_control =
2707 HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
2708 HFA384x_TX_TXEX_SET(1) | HFA384x_TX_TXOK_SET(0);
2710 hw->txbuff.txfrm.desc.tx_control =
2711 HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
2712 HFA384x_TX_TXEX_SET(0) | HFA384x_TX_TXOK_SET(0);
2714 hw->txbuff.txfrm.desc.tx_control =
2715 cpu_to_le16(hw->txbuff.txfrm.desc.tx_control);
2717 /* copy the header over to the txdesc */
2718 memcpy(&(hw->txbuff.txfrm.desc.frame_control), p80211_hdr,
2719 sizeof(union p80211_hdr));
2721 /* if we're using host WEP, increase size by IV+ICV */
2722 if (p80211_wep->data) {
2723 hw->txbuff.txfrm.desc.data_len = cpu_to_le16(skb->len + 8);
2726 hw->txbuff.txfrm.desc.data_len = cpu_to_le16(skb->len);
2729 usbpktlen += skb->len;
2731 /* copy over the WEP IV if we are using host WEP */
2732 ptr = hw->txbuff.txfrm.data;
2733 if (p80211_wep->data) {
2734 memcpy(ptr, p80211_wep->iv, sizeof(p80211_wep->iv));
2735 ptr += sizeof(p80211_wep->iv);
2736 memcpy(ptr, p80211_wep->data, skb->len);
2738 memcpy(ptr, skb->data, skb->len);
2740 /* copy over the packet data */
2743 /* copy over the WEP ICV if we are using host WEP */
2744 if (p80211_wep->data)
2745 memcpy(ptr, p80211_wep->icv, sizeof(p80211_wep->icv));
2747 /* Send the USB packet */
2748 usb_fill_bulk_urb(&(hw->tx_urb), hw->usb,
2750 &(hw->txbuff), ROUNDUP64(usbpktlen),
2751 hfa384x_usbout_callback, hw->wlandev);
2752 hw->tx_urb.transfer_flags |= USB_QUEUE_BULK;
2755 ret = submit_tx_urb(hw, &hw->tx_urb, GFP_ATOMIC);
2757 netdev_err(hw->wlandev->netdev,
2758 "submit_tx_urb() failed, error=%d\n", ret);
2766 void hfa384x_tx_timeout(wlandevice_t *wlandev)
2768 hfa384x_t *hw = wlandev->priv;
2769 unsigned long flags;
2771 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2773 if (!hw->wlandev->hwremoved) {
2776 sched = !test_and_set_bit(WORK_TX_HALT, &hw->usb_flags);
2777 sched |= !test_and_set_bit(WORK_RX_HALT, &hw->usb_flags);
2779 schedule_work(&hw->usb_work);
2782 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2785 /*----------------------------------------------------------------
2786 * hfa384x_usbctlx_reaper_task
2788 * Tasklet to delete dead CTLX objects
2791 * data ptr to a hfa384x_t
2797 ----------------------------------------------------------------*/
2798 static void hfa384x_usbctlx_reaper_task(unsigned long data)
2800 hfa384x_t *hw = (hfa384x_t *)data;
2801 hfa384x_usbctlx_t *ctlx, *temp;
2802 unsigned long flags;
2804 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2806 /* This list is guaranteed to be empty if someone
2807 * has unplugged the adapter.
2809 list_for_each_entry_safe(ctlx, temp, &hw->ctlxq.reapable, list) {
2810 list_del(&ctlx->list);
2814 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2817 /*----------------------------------------------------------------
2818 * hfa384x_usbctlx_completion_task
2820 * Tasklet to call completion handlers for returned CTLXs
2823 * data ptr to hfa384x_t
2830 ----------------------------------------------------------------*/
2831 static void hfa384x_usbctlx_completion_task(unsigned long data)
2833 hfa384x_t *hw = (hfa384x_t *)data;
2834 hfa384x_usbctlx_t *ctlx, *temp;
2835 unsigned long flags;
2839 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2841 /* This list is guaranteed to be empty if someone
2842 * has unplugged the adapter ...
2844 list_for_each_entry_safe(ctlx, temp, &hw->ctlxq.completing, list) {
2845 /* Call the completion function that this
2846 * command was assigned, assuming it has one.
2848 if (ctlx->cmdcb != NULL) {
2849 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2850 ctlx->cmdcb(hw, ctlx);
2851 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2853 /* Make sure we don't try and complete
2854 * this CTLX more than once!
2858 /* Did someone yank the adapter out
2859 * while our list was (briefly) unlocked?
2861 if (hw->wlandev->hwremoved) {
2868 * "Reapable" CTLXs are ones which don't have any
2869 * threads waiting for them to die. Hence they must
2870 * be delivered to The Reaper!
2872 if (ctlx->reapable) {
2873 /* Move the CTLX off the "completing" list (hopefully)
2874 * on to the "reapable" list where the reaper task
2875 * can find it. And "reapable" means that this CTLX
2876 * isn't sitting on a wait-queue somewhere.
2878 list_move_tail(&ctlx->list, &hw->ctlxq.reapable);
2882 complete(&ctlx->done);
2884 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2887 tasklet_schedule(&hw->reaper_bh);
2890 /*----------------------------------------------------------------
2891 * unlocked_usbctlx_cancel_async
2893 * Mark the CTLX dead asynchronously, and ensure that the
2894 * next command on the queue is run afterwards.
2897 * hw ptr to the hfa384x_t structure
2898 * ctlx ptr to a CTLX structure
2901 * 0 the CTLX's URB is inactive
2902 * -EINPROGRESS the URB is currently being unlinked
2905 * Either process or interrupt, but presumably interrupt
2906 ----------------------------------------------------------------*/
2907 static int unlocked_usbctlx_cancel_async(hfa384x_t *hw,
2908 hfa384x_usbctlx_t *ctlx)
2913 * Try to delete the URB containing our request packet.
2914 * If we succeed, then its completion handler will be
2915 * called with a status of -ECONNRESET.
2917 hw->ctlx_urb.transfer_flags |= URB_ASYNC_UNLINK;
2918 ret = usb_unlink_urb(&hw->ctlx_urb);
2920 if (ret != -EINPROGRESS) {
2922 * The OUT URB had either already completed
2923 * or was still in the pending queue, so the
2924 * URB's completion function will not be called.
2925 * We will have to complete the CTLX ourselves.
2927 ctlx->state = CTLX_REQ_FAILED;
2928 unlocked_usbctlx_complete(hw, ctlx);
2935 /*----------------------------------------------------------------
2936 * unlocked_usbctlx_complete
2938 * A CTLX has completed. It may have been successful, it may not
2939 * have been. At this point, the CTLX should be quiescent. The URBs
2940 * aren't active and the timers should have been stopped.
2942 * The CTLX is migrated to the "completing" queue, and the completing
2943 * tasklet is scheduled.
2946 * hw ptr to a hfa384x_t structure
2947 * ctlx ptr to a ctlx structure
2955 * Either, assume interrupt
2956 ----------------------------------------------------------------*/
2957 static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx)
2959 /* Timers have been stopped, and ctlx should be in
2960 * a terminal state. Retire it from the "active"
2963 list_move_tail(&ctlx->list, &hw->ctlxq.completing);
2964 tasklet_schedule(&hw->completion_bh);
2966 switch (ctlx->state) {
2968 case CTLX_REQ_FAILED:
2969 /* This are the correct terminating states. */
2973 netdev_err(hw->wlandev->netdev, "CTLX[%d] not in a terminating state(%s)\n",
2974 le16_to_cpu(ctlx->outbuf.type),
2975 ctlxstr(ctlx->state));
2980 /*----------------------------------------------------------------
2981 * hfa384x_usbctlxq_run
2983 * Checks to see if the head item is running. If not, starts it.
2986 * hw ptr to hfa384x_t
2995 ----------------------------------------------------------------*/
2996 static void hfa384x_usbctlxq_run(hfa384x_t *hw)
2998 unsigned long flags;
3001 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3003 /* Only one active CTLX at any one time, because there's no
3004 * other (reliable) way to match the response URB to the
3007 * Don't touch any of these CTLXs if the hardware
3008 * has been removed or the USB subsystem is stalled.
3010 if (!list_empty(&hw->ctlxq.active) ||
3011 test_bit(WORK_TX_HALT, &hw->usb_flags) || hw->wlandev->hwremoved)
3014 while (!list_empty(&hw->ctlxq.pending)) {
3015 hfa384x_usbctlx_t *head;
3018 /* This is the first pending command */
3019 head = list_entry(hw->ctlxq.pending.next,
3020 hfa384x_usbctlx_t, list);
3022 /* We need to split this off to avoid a race condition */
3023 list_move_tail(&head->list, &hw->ctlxq.active);
3025 /* Fill the out packet */
3026 usb_fill_bulk_urb(&(hw->ctlx_urb), hw->usb,
3028 &(head->outbuf), ROUNDUP64(head->outbufsize),
3029 hfa384x_ctlxout_callback, hw);
3030 hw->ctlx_urb.transfer_flags |= USB_QUEUE_BULK;
3032 /* Now submit the URB and update the CTLX's state */
3033 result = SUBMIT_URB(&hw->ctlx_urb, GFP_ATOMIC);
3035 /* This CTLX is now running on the active queue */
3036 head->state = CTLX_REQ_SUBMITTED;
3038 /* Start the OUT wait timer */
3039 hw->req_timer_done = 0;
3040 hw->reqtimer.expires = jiffies + HZ;
3041 add_timer(&hw->reqtimer);
3043 /* Start the IN wait timer */
3044 hw->resp_timer_done = 0;
3045 hw->resptimer.expires = jiffies + 2 * HZ;
3046 add_timer(&hw->resptimer);
3051 if (result == -EPIPE) {
3052 /* The OUT pipe needs resetting, so put
3053 * this CTLX back in the "pending" queue
3054 * and schedule a reset ...
3056 netdev_warn(hw->wlandev->netdev,
3057 "%s tx pipe stalled: requesting reset\n",
3058 hw->wlandev->netdev->name);
3059 list_move(&head->list, &hw->ctlxq.pending);
3060 set_bit(WORK_TX_HALT, &hw->usb_flags);
3061 schedule_work(&hw->usb_work);
3065 if (result == -ESHUTDOWN) {
3066 netdev_warn(hw->wlandev->netdev, "%s urb shutdown!\n",
3067 hw->wlandev->netdev->name);
3071 netdev_err(hw->wlandev->netdev, "Failed to submit CTLX[%d]: error=%d\n",
3072 le16_to_cpu(head->outbuf.type), result);
3073 unlocked_usbctlx_complete(hw, head);
3077 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3080 /*----------------------------------------------------------------
3081 * hfa384x_usbin_callback
3083 * Callback for URBs on the BULKIN endpoint.
3086 * urb ptr to the completed urb
3095 ----------------------------------------------------------------*/
3096 static void hfa384x_usbin_callback(struct urb *urb)
3098 wlandevice_t *wlandev = urb->context;
3100 hfa384x_usbin_t *usbin = (hfa384x_usbin_t *)urb->transfer_buffer;
3101 struct sk_buff *skb = NULL;
3112 if (!wlandev || !wlandev->netdev || wlandev->hwremoved)
3119 skb = hw->rx_urb_skb;
3120 BUG_ON(!skb || (skb->data != urb->transfer_buffer));
3122 hw->rx_urb_skb = NULL;
3124 /* Check for error conditions within the URB */
3125 switch (urb->status) {
3129 /* Check for short packet */
3130 if (urb->actual_length == 0) {
3131 wlandev->netdev->stats.rx_errors++;
3132 wlandev->netdev->stats.rx_length_errors++;
3138 netdev_warn(hw->wlandev->netdev, "%s rx pipe stalled: requesting reset\n",
3139 wlandev->netdev->name);
3140 if (!test_and_set_bit(WORK_RX_HALT, &hw->usb_flags))
3141 schedule_work(&hw->usb_work);
3142 wlandev->netdev->stats.rx_errors++;
3149 if (!test_and_set_bit(THROTTLE_RX, &hw->usb_flags) &&
3150 !timer_pending(&hw->throttle)) {
3151 mod_timer(&hw->throttle, jiffies + THROTTLE_JIFFIES);
3153 wlandev->netdev->stats.rx_errors++;
3158 wlandev->netdev->stats.rx_over_errors++;
3164 pr_debug("status=%d, device removed.\n", urb->status);
3170 pr_debug("status=%d, urb explicitly unlinked.\n", urb->status);
3175 pr_debug("urb status=%d, transfer flags=0x%x\n",
3176 urb->status, urb->transfer_flags);
3177 wlandev->netdev->stats.rx_errors++;
3182 urb_status = urb->status;
3184 if (action != ABORT) {
3185 /* Repost the RX URB */
3186 result = submit_rx_urb(hw, GFP_ATOMIC);
3189 netdev_err(hw->wlandev->netdev,
3190 "Fatal, failed to resubmit rx_urb. error=%d\n",
3195 /* Handle any USB-IN packet */
3196 /* Note: the check of the sw_support field, the type field doesn't
3197 * have bit 12 set like the docs suggest.
3199 type = le16_to_cpu(usbin->type);
3200 if (HFA384x_USB_ISRXFRM(type)) {
3201 if (action == HANDLE) {
3202 if (usbin->txfrm.desc.sw_support == 0x0123) {
3203 hfa384x_usbin_txcompl(wlandev, usbin);
3205 skb_put(skb, sizeof(*usbin));
3206 hfa384x_usbin_rx(wlandev, skb);
3212 if (HFA384x_USB_ISTXFRM(type)) {
3213 if (action == HANDLE)
3214 hfa384x_usbin_txcompl(wlandev, usbin);
3218 case HFA384x_USB_INFOFRM:
3219 if (action == ABORT)
3221 if (action == HANDLE)
3222 hfa384x_usbin_info(wlandev, usbin);
3225 case HFA384x_USB_CMDRESP:
3226 case HFA384x_USB_WRIDRESP:
3227 case HFA384x_USB_RRIDRESP:
3228 case HFA384x_USB_WMEMRESP:
3229 case HFA384x_USB_RMEMRESP:
3230 /* ALWAYS, ALWAYS, ALWAYS handle this CTLX!!!! */
3231 hfa384x_usbin_ctlx(hw, usbin, urb_status);
3234 case HFA384x_USB_BUFAVAIL:
3235 pr_debug("Received BUFAVAIL packet, frmlen=%d\n",
3236 usbin->bufavail.frmlen);
3239 case HFA384x_USB_ERROR:
3240 pr_debug("Received USB_ERROR packet, errortype=%d\n",
3241 usbin->usberror.errortype);
3245 pr_debug("Unrecognized USBIN packet, type=%x, status=%d\n",
3246 usbin->type, urb_status);
3256 /*----------------------------------------------------------------
3257 * hfa384x_usbin_ctlx
3259 * We've received a URB containing a Prism2 "response" message.
3260 * This message needs to be matched up with a CTLX on the active
3261 * queue and our state updated accordingly.
3264 * hw ptr to hfa384x_t
3265 * usbin ptr to USB IN packet
3266 * urb_status status of this Bulk-In URB
3275 ----------------------------------------------------------------*/
3276 static void hfa384x_usbin_ctlx(hfa384x_t *hw, hfa384x_usbin_t *usbin,
3279 hfa384x_usbctlx_t *ctlx;
3281 unsigned long flags;
3284 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3286 /* There can be only one CTLX on the active queue
3287 * at any one time, and this is the CTLX that the
3288 * timers are waiting for.
3290 if (list_empty(&hw->ctlxq.active))
3293 /* Remove the "response timeout". It's possible that
3294 * we are already too late, and that the timeout is
3295 * already running. And that's just too bad for us,
3296 * because we could lose our CTLX from the active
3299 if (del_timer(&hw->resptimer) == 0) {
3300 if (hw->resp_timer_done == 0) {
3301 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3305 hw->resp_timer_done = 1;
3308 ctlx = get_active_ctlx(hw);
3310 if (urb_status != 0) {
3312 * Bad CTLX, so get rid of it. But we only
3313 * remove it from the active queue if we're no
3314 * longer expecting the OUT URB to complete.
3316 if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0)
3319 const __le16 intype = (usbin->type & ~cpu_to_le16(0x8000));
3322 * Check that our message is what we're expecting ...
3324 if (ctlx->outbuf.type != intype) {
3325 netdev_warn(hw->wlandev->netdev,
3326 "Expected IN[%d], received IN[%d] - ignored.\n",
3327 le16_to_cpu(ctlx->outbuf.type),
3328 le16_to_cpu(intype));
3332 /* This URB has succeeded, so grab the data ... */
3333 memcpy(&ctlx->inbuf, usbin, sizeof(ctlx->inbuf));
3335 switch (ctlx->state) {
3336 case CTLX_REQ_SUBMITTED:
3338 * We have received our response URB before
3339 * our request has been acknowledged. Odd,
3340 * but our OUT URB is still alive...
3342 pr_debug("Causality violation: please reboot Universe\n");
3343 ctlx->state = CTLX_RESP_COMPLETE;
3346 case CTLX_REQ_COMPLETE:
3348 * This is the usual path: our request
3349 * has already been acknowledged, and
3350 * now we have received the reply too.
3352 ctlx->state = CTLX_COMPLETE;
3353 unlocked_usbctlx_complete(hw, ctlx);
3359 * Throw this CTLX away ...
3361 netdev_err(hw->wlandev->netdev,
3362 "Matched IN URB, CTLX[%d] in invalid state(%s). Discarded.\n",
3363 le16_to_cpu(ctlx->outbuf.type),
3364 ctlxstr(ctlx->state));
3365 if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0)
3372 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3375 hfa384x_usbctlxq_run(hw);
3378 /*----------------------------------------------------------------
3379 * hfa384x_usbin_txcompl
3381 * At this point we have the results of a previous transmit.
3384 * wlandev wlan device
3385 * usbin ptr to the usb transfer buffer
3394 ----------------------------------------------------------------*/
3395 static void hfa384x_usbin_txcompl(wlandevice_t *wlandev,
3396 hfa384x_usbin_t *usbin)
3400 status = le16_to_cpu(usbin->type); /* yeah I know it says type... */
3402 /* Was there an error? */
3403 if (HFA384x_TXSTATUS_ISERROR(status))
3404 prism2sta_ev_txexc(wlandev, status);
3406 prism2sta_ev_tx(wlandev, status);
3409 /*----------------------------------------------------------------
3412 * At this point we have a successful received a rx frame packet.
3415 * wlandev wlan device
3416 * usbin ptr to the usb transfer buffer
3425 ----------------------------------------------------------------*/
3426 static void hfa384x_usbin_rx(wlandevice_t *wlandev, struct sk_buff *skb)
3428 hfa384x_usbin_t *usbin = (hfa384x_usbin_t *)skb->data;
3429 hfa384x_t *hw = wlandev->priv;
3431 struct p80211_rxmeta *rxmeta;
3435 /* Byte order convert once up front. */
3436 usbin->rxfrm.desc.status = le16_to_cpu(usbin->rxfrm.desc.status);
3437 usbin->rxfrm.desc.time = le32_to_cpu(usbin->rxfrm.desc.time);
3439 /* Now handle frame based on port# */
3440 switch (HFA384x_RXSTATUS_MACPORT_GET(usbin->rxfrm.desc.status)) {
3442 fc = le16_to_cpu(usbin->rxfrm.desc.frame_control);
3444 /* If exclude and we receive an unencrypted, drop it */
3445 if ((wlandev->hostwep & HOSTWEP_EXCLUDEUNENCRYPTED) &&
3446 !WLAN_GET_FC_ISWEP(fc)) {
3450 data_len = le16_to_cpu(usbin->rxfrm.desc.data_len);
3452 /* How much header data do we have? */
3453 hdrlen = p80211_headerlen(fc);
3455 /* Pull off the descriptor */
3456 skb_pull(skb, sizeof(hfa384x_rx_frame_t));
3458 /* Now shunt the header block up against the data block
3459 * with an "overlapping" copy
3461 memmove(skb_push(skb, hdrlen),
3462 &usbin->rxfrm.desc.frame_control, hdrlen);
3464 skb->dev = wlandev->netdev;
3465 skb->dev->last_rx = jiffies;
3467 /* And set the frame length properly */
3468 skb_trim(skb, data_len + hdrlen);
3470 /* The prism2 series does not return the CRC */
3471 memset(skb_put(skb, WLAN_CRC_LEN), 0xff, WLAN_CRC_LEN);
3473 skb_reset_mac_header(skb);
3475 /* Attach the rxmeta, set some stuff */
3476 p80211skb_rxmeta_attach(wlandev, skb);
3477 rxmeta = P80211SKB_RXMETA(skb);
3478 rxmeta->mactime = usbin->rxfrm.desc.time;
3479 rxmeta->rxrate = usbin->rxfrm.desc.rate;
3480 rxmeta->signal = usbin->rxfrm.desc.signal - hw->dbmadjust;
3481 rxmeta->noise = usbin->rxfrm.desc.silence - hw->dbmadjust;
3483 p80211netdev_rx(wlandev, skb);
3488 if (!HFA384x_RXSTATUS_ISFCSERR(usbin->rxfrm.desc.status)) {
3489 /* Copy to wlansnif skb */
3490 hfa384x_int_rxmonitor(wlandev, &usbin->rxfrm);
3493 pr_debug("Received monitor frame: FCSerr set\n");
3498 netdev_warn(hw->wlandev->netdev, "Received frame on unsupported port=%d\n",
3499 HFA384x_RXSTATUS_MACPORT_GET(
3500 usbin->rxfrm.desc.status));
3505 /*----------------------------------------------------------------
3506 * hfa384x_int_rxmonitor
3508 * Helper function for int_rx. Handles monitor frames.
3509 * Note that this function allocates space for the FCS and sets it
3510 * to 0xffffffff. The hfa384x doesn't give us the FCS value but the
3511 * higher layers expect it. 0xffffffff is used as a flag to indicate
3515 * wlandev wlan device structure
3516 * rxfrm rx descriptor read from card in int_rx
3522 * Allocates an skb and passes it up via the PF_PACKET interface.
3525 ----------------------------------------------------------------*/
3526 static void hfa384x_int_rxmonitor(wlandevice_t *wlandev,
3527 hfa384x_usb_rxfrm_t *rxfrm)
3529 hfa384x_rx_frame_t *rxdesc = &(rxfrm->desc);
3530 unsigned int hdrlen = 0;
3531 unsigned int datalen = 0;
3532 unsigned int skblen = 0;
3535 struct sk_buff *skb;
3536 hfa384x_t *hw = wlandev->priv;
3538 /* Remember the status, time, and data_len fields are in host order */
3539 /* Figure out how big the frame is */
3540 fc = le16_to_cpu(rxdesc->frame_control);
3541 hdrlen = p80211_headerlen(fc);
3542 datalen = le16_to_cpu(rxdesc->data_len);
3544 /* Allocate an ind message+framesize skb */
3545 skblen = sizeof(struct p80211_caphdr) + hdrlen + datalen + WLAN_CRC_LEN;
3547 /* sanity check the length */
3549 (sizeof(struct p80211_caphdr) +
3550 WLAN_HDR_A4_LEN + WLAN_DATA_MAXLEN + WLAN_CRC_LEN)) {
3551 pr_debug("overlen frm: len=%zd\n",
3552 skblen - sizeof(struct p80211_caphdr));
3555 skb = dev_alloc_skb(skblen);
3559 /* only prepend the prism header if in the right mode */
3560 if ((wlandev->netdev->type == ARPHRD_IEEE80211_PRISM) &&
3561 (hw->sniffhdr != 0)) {
3562 struct p80211_caphdr *caphdr;
3563 /* The NEW header format! */
3564 datap = skb_put(skb, sizeof(struct p80211_caphdr));
3565 caphdr = (struct p80211_caphdr *)datap;
3567 caphdr->version = htonl(P80211CAPTURE_VERSION);
3568 caphdr->length = htonl(sizeof(struct p80211_caphdr));
3569 caphdr->mactime = __cpu_to_be64(rxdesc->time) * 1000;
3570 caphdr->hosttime = __cpu_to_be64(jiffies);
3571 caphdr->phytype = htonl(4); /* dss_dot11_b */
3572 caphdr->channel = htonl(hw->sniff_channel);
3573 caphdr->datarate = htonl(rxdesc->rate);
3574 caphdr->antenna = htonl(0); /* unknown */
3575 caphdr->priority = htonl(0); /* unknown */
3576 caphdr->ssi_type = htonl(3); /* rssi_raw */
3577 caphdr->ssi_signal = htonl(rxdesc->signal);
3578 caphdr->ssi_noise = htonl(rxdesc->silence);
3579 caphdr->preamble = htonl(0); /* unknown */
3580 caphdr->encoding = htonl(1); /* cck */
3583 /* Copy the 802.11 header to the skb
3584 (ctl frames may be less than a full header) */
3585 datap = skb_put(skb, hdrlen);
3586 memcpy(datap, &(rxdesc->frame_control), hdrlen);
3588 /* If any, copy the data from the card to the skb */
3590 datap = skb_put(skb, datalen);
3591 memcpy(datap, rxfrm->data, datalen);
3593 /* check for unencrypted stuff if WEP bit set. */
3594 if (*(datap - hdrlen + 1) & 0x40) /* wep set */
3595 if ((*(datap) == 0xaa) && (*(datap + 1) == 0xaa))
3596 /* clear wep; it's the 802.2 header! */
3597 *(datap - hdrlen + 1) &= 0xbf;
3600 if (hw->sniff_fcs) {
3602 datap = skb_put(skb, WLAN_CRC_LEN);
3603 memset(datap, 0xff, WLAN_CRC_LEN);
3606 /* pass it back up */
3607 p80211netdev_rx(wlandev, skb);
3610 /*----------------------------------------------------------------
3611 * hfa384x_usbin_info
3613 * At this point we have a successful received a Prism2 info frame.
3616 * wlandev wlan device
3617 * usbin ptr to the usb transfer buffer
3626 ----------------------------------------------------------------*/
3627 static void hfa384x_usbin_info(wlandevice_t *wlandev, hfa384x_usbin_t *usbin)
3629 usbin->infofrm.info.framelen =
3630 le16_to_cpu(usbin->infofrm.info.framelen);
3631 prism2sta_ev_info(wlandev, &usbin->infofrm.info);
3634 /*----------------------------------------------------------------
3635 * hfa384x_usbout_callback
3637 * Callback for URBs on the BULKOUT endpoint.
3640 * urb ptr to the completed urb
3649 ----------------------------------------------------------------*/
3650 static void hfa384x_usbout_callback(struct urb *urb)
3652 wlandevice_t *wlandev = urb->context;
3658 if (wlandev && wlandev->netdev) {
3659 switch (urb->status) {
3661 prism2sta_ev_alloc(wlandev);
3666 hfa384x_t *hw = wlandev->priv;
3668 netdev_warn(hw->wlandev->netdev,
3669 "%s tx pipe stalled: requesting reset\n",
3670 wlandev->netdev->name);
3671 if (!test_and_set_bit
3672 (WORK_TX_HALT, &hw->usb_flags))
3673 schedule_work(&hw->usb_work);
3674 wlandev->netdev->stats.tx_errors++;
3682 hfa384x_t *hw = wlandev->priv;
3684 if (!test_and_set_bit
3685 (THROTTLE_TX, &hw->usb_flags) &&
3686 !timer_pending(&hw->throttle)) {
3687 mod_timer(&hw->throttle,
3688 jiffies + THROTTLE_JIFFIES);
3690 wlandev->netdev->stats.tx_errors++;
3691 netif_stop_queue(wlandev->netdev);
3697 /* Ignorable errors */
3701 netdev_info(wlandev->netdev, "unknown urb->status=%d\n",
3703 wlandev->netdev->stats.tx_errors++;
3709 /*----------------------------------------------------------------
3710 * hfa384x_ctlxout_callback
3712 * Callback for control data on the BULKOUT endpoint.
3715 * urb ptr to the completed urb
3724 ----------------------------------------------------------------*/
3725 static void hfa384x_ctlxout_callback(struct urb *urb)
3727 hfa384x_t *hw = urb->context;
3728 int delete_resptimer = 0;
3731 hfa384x_usbctlx_t *ctlx;
3732 unsigned long flags;
3734 pr_debug("urb->status=%d\n", urb->status);
3738 if ((urb->status == -ESHUTDOWN) ||
3739 (urb->status == -ENODEV) || (hw == NULL))
3743 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3746 * Only one CTLX at a time on the "active" list, and
3747 * none at all if we are unplugged. However, we can
3748 * rely on the disconnect function to clean everything
3749 * up if someone unplugged the adapter.
3751 if (list_empty(&hw->ctlxq.active)) {
3752 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3757 * Having something on the "active" queue means
3758 * that we have timers to worry about ...
3760 if (del_timer(&hw->reqtimer) == 0) {
3761 if (hw->req_timer_done == 0) {
3763 * This timer was actually running while we
3764 * were trying to delete it. Let it terminate
3765 * gracefully instead.
3767 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3771 hw->req_timer_done = 1;
3774 ctlx = get_active_ctlx(hw);
3776 if (urb->status == 0) {
3777 /* Request portion of a CTLX is successful */
3778 switch (ctlx->state) {
3779 case CTLX_REQ_SUBMITTED:
3780 /* This OUT-ACK received before IN */
3781 ctlx->state = CTLX_REQ_COMPLETE;
3784 case CTLX_RESP_COMPLETE:
3785 /* IN already received before this OUT-ACK,
3786 * so this command must now be complete.
3788 ctlx->state = CTLX_COMPLETE;
3789 unlocked_usbctlx_complete(hw, ctlx);
3794 /* This is NOT a valid CTLX "success" state! */
3795 netdev_err(hw->wlandev->netdev,
3796 "Illegal CTLX[%d] success state(%s, %d) in OUT URB\n",
3797 le16_to_cpu(ctlx->outbuf.type),
3798 ctlxstr(ctlx->state), urb->status);
3802 /* If the pipe has stalled then we need to reset it */
3803 if ((urb->status == -EPIPE) &&
3804 !test_and_set_bit(WORK_TX_HALT, &hw->usb_flags)) {
3805 netdev_warn(hw->wlandev->netdev,
3806 "%s tx pipe stalled: requesting reset\n",
3807 hw->wlandev->netdev->name);
3808 schedule_work(&hw->usb_work);
3811 /* If someone cancels the OUT URB then its status
3812 * should be either -ECONNRESET or -ENOENT.
3814 ctlx->state = CTLX_REQ_FAILED;
3815 unlocked_usbctlx_complete(hw, ctlx);
3816 delete_resptimer = 1;
3821 if (delete_resptimer) {
3822 timer_ok = del_timer(&hw->resptimer);
3824 hw->resp_timer_done = 1;
3827 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3829 if (!timer_ok && (hw->resp_timer_done == 0)) {
3830 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3835 hfa384x_usbctlxq_run(hw);
3838 /*----------------------------------------------------------------
3839 * hfa384x_usbctlx_reqtimerfn
3841 * Timer response function for CTLX request timeouts. If this
3842 * function is called, it means that the callback for the OUT
3843 * URB containing a Prism2.x XXX_Request was never called.
3846 * data a ptr to the hfa384x_t
3855 ----------------------------------------------------------------*/
3856 static void hfa384x_usbctlx_reqtimerfn(unsigned long data)
3858 hfa384x_t *hw = (hfa384x_t *)data;
3859 unsigned long flags;
3861 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3863 hw->req_timer_done = 1;
3865 /* Removing the hardware automatically empties
3866 * the active list ...
3868 if (!list_empty(&hw->ctlxq.active)) {
3870 * We must ensure that our URB is removed from
3871 * the system, if it hasn't already expired.
3873 hw->ctlx_urb.transfer_flags |= URB_ASYNC_UNLINK;
3874 if (usb_unlink_urb(&hw->ctlx_urb) == -EINPROGRESS) {
3875 hfa384x_usbctlx_t *ctlx = get_active_ctlx(hw);
3877 ctlx->state = CTLX_REQ_FAILED;
3879 /* This URB was active, but has now been
3880 * cancelled. It will now have a status of
3881 * -ECONNRESET in the callback function.
3883 * We are cancelling this CTLX, so we're
3884 * not going to need to wait for a response.
3885 * The URB's callback function will check
3886 * that this timer is truly dead.
3888 if (del_timer(&hw->resptimer) != 0)
3889 hw->resp_timer_done = 1;
3893 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3896 /*----------------------------------------------------------------
3897 * hfa384x_usbctlx_resptimerfn
3899 * Timer response function for CTLX response timeouts. If this
3900 * function is called, it means that the callback for the IN
3901 * URB containing a Prism2.x XXX_Response was never called.
3904 * data a ptr to the hfa384x_t
3913 ----------------------------------------------------------------*/
3914 static void hfa384x_usbctlx_resptimerfn(unsigned long data)
3916 hfa384x_t *hw = (hfa384x_t *)data;
3917 unsigned long flags;
3919 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3921 hw->resp_timer_done = 1;
3923 /* The active list will be empty if the
3924 * adapter has been unplugged ...
3926 if (!list_empty(&hw->ctlxq.active)) {
3927 hfa384x_usbctlx_t *ctlx = get_active_ctlx(hw);
3929 if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0) {
3930 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3931 hfa384x_usbctlxq_run(hw);
3935 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3938 /*----------------------------------------------------------------
3939 * hfa384x_usb_throttlefn
3952 ----------------------------------------------------------------*/
3953 static void hfa384x_usb_throttlefn(unsigned long data)
3955 hfa384x_t *hw = (hfa384x_t *)data;
3956 unsigned long flags;
3958 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3961 * We need to check BOTH the RX and the TX throttle controls,
3962 * so we use the bitwise OR instead of the logical OR.
3964 pr_debug("flags=0x%lx\n", hw->usb_flags);
3965 if (!hw->wlandev->hwremoved &&
3966 ((test_and_clear_bit(THROTTLE_RX, &hw->usb_flags) &&
3967 !test_and_set_bit(WORK_RX_RESUME, &hw->usb_flags)) |
3968 (test_and_clear_bit(THROTTLE_TX, &hw->usb_flags) &&
3969 !test_and_set_bit(WORK_TX_RESUME, &hw->usb_flags))
3971 schedule_work(&hw->usb_work);
3974 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3977 /*----------------------------------------------------------------
3978 * hfa384x_usbctlx_submit
3980 * Called from the doxxx functions to submit a CTLX to the queue
3983 * hw ptr to the hw struct
3984 * ctlx ctlx structure to enqueue
3987 * -ENODEV if the adapter is unplugged
3993 * process or interrupt
3994 ----------------------------------------------------------------*/
3995 static int hfa384x_usbctlx_submit(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx)
3997 unsigned long flags;
3999 spin_lock_irqsave(&hw->ctlxq.lock, flags);
4001 if (hw->wlandev->hwremoved) {
4002 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
4006 ctlx->state = CTLX_PENDING;
4007 list_add_tail(&ctlx->list, &hw->ctlxq.pending);
4008 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
4009 hfa384x_usbctlxq_run(hw);
4014 /*----------------------------------------------------------------
4015 * hfa384x_isgood_pdrcore
4017 * Quick check of PDR codes.
4020 * pdrcode PDR code number (host order)
4029 ----------------------------------------------------------------*/
4030 static int hfa384x_isgood_pdrcode(u16 pdrcode)
4033 case HFA384x_PDR_END_OF_PDA:
4034 case HFA384x_PDR_PCB_PARTNUM:
4035 case HFA384x_PDR_PDAVER:
4036 case HFA384x_PDR_NIC_SERIAL:
4037 case HFA384x_PDR_MKK_MEASUREMENTS:
4038 case HFA384x_PDR_NIC_RAMSIZE:
4039 case HFA384x_PDR_MFISUPRANGE:
4040 case HFA384x_PDR_CFISUPRANGE:
4041 case HFA384x_PDR_NICID:
4042 case HFA384x_PDR_MAC_ADDRESS:
4043 case HFA384x_PDR_REGDOMAIN:
4044 case HFA384x_PDR_ALLOWED_CHANNEL:
4045 case HFA384x_PDR_DEFAULT_CHANNEL:
4046 case HFA384x_PDR_TEMPTYPE:
4047 case HFA384x_PDR_IFR_SETTING:
4048 case HFA384x_PDR_RFR_SETTING:
4049 case HFA384x_PDR_HFA3861_BASELINE:
4050 case HFA384x_PDR_HFA3861_SHADOW:
4051 case HFA384x_PDR_HFA3861_IFRF:
4052 case HFA384x_PDR_HFA3861_CHCALSP:
4053 case HFA384x_PDR_HFA3861_CHCALI:
4054 case HFA384x_PDR_3842_NIC_CONFIG:
4055 case HFA384x_PDR_USB_ID:
4056 case HFA384x_PDR_PCI_ID:
4057 case HFA384x_PDR_PCI_IFCONF:
4058 case HFA384x_PDR_PCI_PMCONF:
4059 case HFA384x_PDR_RFENRGY:
4060 case HFA384x_PDR_HFA3861_MANF_TESTSP:
4061 case HFA384x_PDR_HFA3861_MANF_TESTI:
4065 if (pdrcode < 0x1000) {
4066 /* code is OK, but we don't know exactly what it is */
4067 pr_debug("Encountered unknown PDR#=0x%04x, assuming it's ok.\n",
4074 pr_debug("Encountered unknown PDR#=0x%04x, (>=0x1000), assuming it's bad.\n",