added 2.6.29.6 aldebaran kernel
[nao-ulib.git] / kernel / 2.6.29.6-aldebaran-rt / drivers / staging / wlan-ng / hfa384x_usb.c
blob8a75b50f8635edf10f4de6531bca5a2aaa932d23
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 * --------------------------------------------------------------------
8 * linux-wlan
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
34 * made directly to:
36 * AbsoluteValue Systems Inc.
37 * info@linux-wlan.com
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 invokations of the API layer (e.g. write to bap, followed by cmd).
57 * Common sequences:
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:
101 * create()
102 * start()
104 * . Do interesting things w/ the hardware
106 * stop()
107 * destroy()
109 * Note that destroy() can be called without calling stop() first.
110 * --------------------------------------------------------------------
113 /*================================================================*/
114 /* System Includes */
115 #define WLAN_DBVAR prism2_debug
117 #include <linux/version.h>
119 #include <linux/module.h>
120 #include <linux/kernel.h>
121 #include <linux/sched.h>
122 #include <linux/types.h>
123 #include <linux/slab.h>
124 #include <linux/wireless.h>
125 #include <linux/netdevice.h>
126 #include <linux/timer.h>
127 #include <asm/io.h>
128 #include <linux/delay.h>
129 #include <asm/byteorder.h>
130 #include <asm/bitops.h>
131 #include <linux/list.h>
132 #include <linux/usb.h>
134 #include "wlan_compat.h"
136 #define SUBMIT_URB(u,f) usb_submit_urb(u,f)
138 /*================================================================*/
139 /* Project Includes */
141 #include "p80211types.h"
142 #include "p80211hdr.h"
143 #include "p80211mgmt.h"
144 #include "p80211conv.h"
145 #include "p80211msg.h"
146 #include "p80211netdev.h"
147 #include "p80211req.h"
148 #include "p80211metadef.h"
149 #include "p80211metastruct.h"
150 #include "hfa384x.h"
151 #include "prism2mgmt.h"
153 /*================================================================*/
154 /* Local Constants */
156 enum cmd_mode
158 DOWAIT = 0,
159 DOASYNC
161 typedef enum cmd_mode CMD_MODE;
163 #define THROTTLE_JIFFIES (HZ/8)
165 /*================================================================*/
166 /* Local Macros */
168 #define ROUNDUP64(a) (((a)+63)&~63)
170 /*================================================================*/
171 /* Local Types */
173 /*================================================================*/
174 /* Local Static Definitions */
175 extern int prism2_debug;
177 /*================================================================*/
178 /* Local Function Declarations */
180 #ifdef DEBUG_USB
181 static void
182 dbprint_urb(struct urb* urb);
183 #endif
185 static void
186 hfa384x_int_rxmonitor(
187 wlandevice_t *wlandev,
188 hfa384x_usb_rxfrm_t *rxfrm);
190 static void
191 hfa384x_usb_defer(struct work_struct *data);
193 static int
194 submit_rx_urb(hfa384x_t *hw, gfp_t flags);
196 static int
197 submit_tx_urb(hfa384x_t *hw, struct urb *tx_urb, gfp_t flags);
199 /*---------------------------------------------------*/
200 /* Callbacks */
201 static void
202 hfa384x_usbout_callback(struct urb *urb);
203 static void
204 hfa384x_ctlxout_callback(struct urb *urb);
205 static void
206 hfa384x_usbin_callback(struct urb *urb);
208 static void
209 hfa384x_usbin_txcompl(wlandevice_t *wlandev, hfa384x_usbin_t *usbin);
211 static void
212 hfa384x_usbin_rx(wlandevice_t *wlandev, struct sk_buff *skb);
214 static void
215 hfa384x_usbin_info(wlandevice_t *wlandev, hfa384x_usbin_t *usbin);
217 static void
218 hfa384x_usbout_tx(wlandevice_t *wlandev, hfa384x_usbout_t *usbout);
220 static void hfa384x_usbin_ctlx(hfa384x_t *hw, hfa384x_usbin_t *usbin,
221 int urb_status);
223 /*---------------------------------------------------*/
224 /* Functions to support the prism2 usb command queue */
226 static void
227 hfa384x_usbctlxq_run(hfa384x_t *hw);
229 static void
230 hfa384x_usbctlx_reqtimerfn(unsigned long data);
232 static void
233 hfa384x_usbctlx_resptimerfn(unsigned long data);
235 static void
236 hfa384x_usb_throttlefn(unsigned long data);
238 static void
239 hfa384x_usbctlx_completion_task(unsigned long data);
241 static void
242 hfa384x_usbctlx_reaper_task(unsigned long data);
244 static int
245 hfa384x_usbctlx_submit(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
247 static void
248 unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
250 struct usbctlx_completor
252 int (*complete)(struct usbctlx_completor*);
254 typedef struct usbctlx_completor usbctlx_completor_t;
256 static int
257 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
258 hfa384x_usbctlx_t *ctlx,
259 usbctlx_completor_t *completor);
261 static int
262 unlocked_usbctlx_cancel_async(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
264 static void
265 hfa384x_cb_status(hfa384x_t *hw, const hfa384x_usbctlx_t *ctlx);
267 static void
268 hfa384x_cb_rrid(hfa384x_t *hw, const hfa384x_usbctlx_t *ctlx);
270 static int
271 usbctlx_get_status(const hfa384x_usb_cmdresp_t *cmdresp,
272 hfa384x_cmdresult_t *result);
274 static void
275 usbctlx_get_rridresult(const hfa384x_usb_rridresp_t *rridresp,
276 hfa384x_rridresult_t *result);
278 /*---------------------------------------------------*/
279 /* Low level req/resp CTLX formatters and submitters */
280 static int
281 hfa384x_docmd(
282 hfa384x_t *hw,
283 CMD_MODE mode,
284 hfa384x_metacmd_t *cmd,
285 ctlx_cmdcb_t cmdcb,
286 ctlx_usercb_t usercb,
287 void *usercb_data);
289 static int
290 hfa384x_dorrid(
291 hfa384x_t *hw,
292 CMD_MODE mode,
293 u16 rid,
294 void *riddata,
295 unsigned int riddatalen,
296 ctlx_cmdcb_t cmdcb,
297 ctlx_usercb_t usercb,
298 void *usercb_data);
300 static int
301 hfa384x_dowrid(
302 hfa384x_t *hw,
303 CMD_MODE mode,
304 u16 rid,
305 void *riddata,
306 unsigned int riddatalen,
307 ctlx_cmdcb_t cmdcb,
308 ctlx_usercb_t usercb,
309 void *usercb_data);
311 static int
312 hfa384x_dormem(
313 hfa384x_t *hw,
314 CMD_MODE mode,
315 u16 page,
316 u16 offset,
317 void *data,
318 unsigned int len,
319 ctlx_cmdcb_t cmdcb,
320 ctlx_usercb_t usercb,
321 void *usercb_data);
323 static int
324 hfa384x_dowmem(
325 hfa384x_t *hw,
326 CMD_MODE mode,
327 u16 page,
328 u16 offset,
329 void *data,
330 unsigned int len,
331 ctlx_cmdcb_t cmdcb,
332 ctlx_usercb_t usercb,
333 void *usercb_data);
335 static int
336 hfa384x_isgood_pdrcode(u16 pdrcode);
338 /*================================================================*/
339 /* Function Definitions */
340 static inline const char* ctlxstr(CTLX_STATE s)
342 static const char* ctlx_str[] = {
343 "Initial state",
344 "Complete",
345 "Request failed",
346 "Request pending",
347 "Request packet submitted",
348 "Request packet completed",
349 "Response packet completed"
352 return ctlx_str[s];
356 static inline hfa384x_usbctlx_t*
357 get_active_ctlx(hfa384x_t *hw)
359 return list_entry(hw->ctlxq.active.next, hfa384x_usbctlx_t, list);
363 #ifdef DEBUG_USB
364 void
365 dbprint_urb(struct urb* urb)
367 WLAN_LOG_DEBUG(3,"urb->pipe=0x%08x\n", urb->pipe);
368 WLAN_LOG_DEBUG(3,"urb->status=0x%08x\n", urb->status);
369 WLAN_LOG_DEBUG(3,"urb->transfer_flags=0x%08x\n", urb->transfer_flags);
370 WLAN_LOG_DEBUG(3,"urb->transfer_buffer=0x%08x\n", (unsigned int)urb->transfer_buffer);
371 WLAN_LOG_DEBUG(3,"urb->transfer_buffer_length=0x%08x\n", urb->transfer_buffer_length);
372 WLAN_LOG_DEBUG(3,"urb->actual_length=0x%08x\n", urb->actual_length);
373 WLAN_LOG_DEBUG(3,"urb->bandwidth=0x%08x\n", urb->bandwidth);
374 WLAN_LOG_DEBUG(3,"urb->setup_packet(ctl)=0x%08x\n", (unsigned int)urb->setup_packet);
375 WLAN_LOG_DEBUG(3,"urb->start_frame(iso/irq)=0x%08x\n", urb->start_frame);
376 WLAN_LOG_DEBUG(3,"urb->interval(irq)=0x%08x\n", urb->interval);
377 WLAN_LOG_DEBUG(3,"urb->error_count(iso)=0x%08x\n", urb->error_count);
378 WLAN_LOG_DEBUG(3,"urb->timeout=0x%08x\n", urb->timeout);
379 WLAN_LOG_DEBUG(3,"urb->context=0x%08x\n", (unsigned int)urb->context);
380 WLAN_LOG_DEBUG(3,"urb->complete=0x%08x\n", (unsigned int)urb->complete);
382 #endif
385 /*----------------------------------------------------------------
386 * submit_rx_urb
388 * Listen for input data on the BULK-IN pipe. If the pipe has
389 * stalled then schedule it to be reset.
391 * Arguments:
392 * hw device struct
393 * memflags memory allocation flags
395 * Returns:
396 * error code from submission
398 * Call context:
399 * Any
400 ----------------------------------------------------------------*/
401 static int
402 submit_rx_urb(hfa384x_t *hw, gfp_t memflags)
404 struct sk_buff *skb;
405 int result;
407 DBFENTER;
409 skb = dev_alloc_skb(sizeof(hfa384x_usbin_t));
410 if (skb == NULL) {
411 result = -ENOMEM;
412 goto done;
415 /* Post the IN urb */
416 usb_fill_bulk_urb(&hw->rx_urb, hw->usb,
417 hw->endp_in,
418 skb->data, sizeof(hfa384x_usbin_t),
419 hfa384x_usbin_callback, hw->wlandev);
421 hw->rx_urb_skb = skb;
423 result = -ENOLINK;
424 if ( !hw->wlandev->hwremoved && !test_bit(WORK_RX_HALT, &hw->usb_flags)) {
425 result = SUBMIT_URB(&hw->rx_urb, memflags);
427 /* Check whether we need to reset the RX pipe */
428 if (result == -EPIPE) {
429 WLAN_LOG_WARNING("%s rx pipe stalled: requesting reset\n",
430 hw->wlandev->netdev->name);
431 if ( !test_and_set_bit(WORK_RX_HALT, &hw->usb_flags) )
432 schedule_work(&hw->usb_work);
436 /* Don't leak memory if anything should go wrong */
437 if (result != 0) {
438 dev_kfree_skb(skb);
439 hw->rx_urb_skb = NULL;
442 done:
444 DBFEXIT;
445 return result;
448 /*----------------------------------------------------------------
449 * submit_tx_urb
451 * Prepares and submits the URB of transmitted data. If the
452 * submission fails then it will schedule the output pipe to
453 * be reset.
455 * Arguments:
456 * hw device struct
457 * tx_urb URB of data for tranmission
458 * memflags memory allocation flags
460 * Returns:
461 * error code from submission
463 * Call context:
464 * Any
465 ----------------------------------------------------------------*/
466 static int
467 submit_tx_urb(hfa384x_t *hw, struct urb *tx_urb, gfp_t memflags)
469 struct net_device *netdev = hw->wlandev->netdev;
470 int result;
472 DBFENTER;
474 result = -ENOLINK;
475 if ( netif_running(netdev) ) {
477 if ( !hw->wlandev->hwremoved && !test_bit(WORK_TX_HALT, &hw->usb_flags) ) {
478 result = SUBMIT_URB(tx_urb, memflags);
480 /* Test whether we need to reset the TX pipe */
481 if (result == -EPIPE) {
482 WLAN_LOG_WARNING("%s tx pipe stalled: requesting reset\n",
483 netdev->name);
484 set_bit(WORK_TX_HALT, &hw->usb_flags);
485 schedule_work(&hw->usb_work);
486 } else if (result == 0) {
487 netif_stop_queue(netdev);
492 DBFEXIT;
494 return result;
497 /*----------------------------------------------------------------
498 * hfa394x_usb_defer
500 * There are some things that the USB stack cannot do while
501 * in interrupt context, so we arrange this function to run
502 * in process context.
504 * Arguments:
505 * hw device structure
507 * Returns:
508 * nothing
510 * Call context:
511 * process (by design)
512 ----------------------------------------------------------------*/
513 static void
514 hfa384x_usb_defer(struct work_struct *data)
516 hfa384x_t *hw = container_of(data, struct hfa384x, usb_work);
517 struct net_device *netdev = hw->wlandev->netdev;
519 DBFENTER;
521 /* Don't bother trying to reset anything if the plug
522 * has been pulled ...
524 if ( hw->wlandev->hwremoved ) {
525 DBFEXIT;
526 return;
529 /* Reception has stopped: try to reset the input pipe */
530 if (test_bit(WORK_RX_HALT, &hw->usb_flags)) {
531 int ret;
533 usb_kill_urb(&hw->rx_urb); /* Cannot be holding spinlock! */
535 ret = usb_clear_halt(hw->usb, hw->endp_in);
536 if (ret != 0) {
537 printk(KERN_ERR
538 "Failed to clear rx pipe for %s: err=%d\n",
539 netdev->name, ret);
540 } else {
541 printk(KERN_INFO "%s rx pipe reset complete.\n",
542 netdev->name);
543 clear_bit(WORK_RX_HALT, &hw->usb_flags);
544 set_bit(WORK_RX_RESUME, &hw->usb_flags);
548 /* Resume receiving data back from the device. */
549 if ( test_bit(WORK_RX_RESUME, &hw->usb_flags) ) {
550 int ret;
552 ret = submit_rx_urb(hw, GFP_KERNEL);
553 if (ret != 0) {
554 printk(KERN_ERR
555 "Failed to resume %s rx pipe.\n", netdev->name);
556 } else {
557 clear_bit(WORK_RX_RESUME, &hw->usb_flags);
561 /* Transmission has stopped: try to reset the output pipe */
562 if (test_bit(WORK_TX_HALT, &hw->usb_flags)) {
563 int ret;
565 usb_kill_urb(&hw->tx_urb);
566 ret = usb_clear_halt(hw->usb, hw->endp_out);
567 if (ret != 0) {
568 printk(KERN_ERR
569 "Failed to clear tx pipe for %s: err=%d\n",
570 netdev->name, ret);
571 } else {
572 printk(KERN_INFO "%s tx pipe reset complete.\n",
573 netdev->name);
574 clear_bit(WORK_TX_HALT, &hw->usb_flags);
575 set_bit(WORK_TX_RESUME, &hw->usb_flags);
577 /* Stopping the BULK-OUT pipe also blocked
578 * us from sending any more CTLX URBs, so
579 * we need to re-run our queue ...
581 hfa384x_usbctlxq_run(hw);
585 /* Resume transmitting. */
586 if ( test_and_clear_bit(WORK_TX_RESUME, &hw->usb_flags) ) {
587 netif_wake_queue(hw->wlandev->netdev);
590 DBFEXIT;
594 /*----------------------------------------------------------------
595 * hfa384x_create
597 * Sets up the hfa384x_t data structure for use. Note this
598 * does _not_ intialize the actual hardware, just the data structures
599 * we use to keep track of its state.
601 * Arguments:
602 * hw device structure
603 * irq device irq number
604 * iobase i/o base address for register access
605 * membase memory base address for register access
607 * Returns:
608 * nothing
610 * Side effects:
612 * Call context:
613 * process
614 ----------------------------------------------------------------*/
615 void
616 hfa384x_create( hfa384x_t *hw, struct usb_device *usb)
618 DBFENTER;
620 memset(hw, 0, sizeof(hfa384x_t));
621 hw->usb = usb;
623 /* set up the endpoints */
624 hw->endp_in = usb_rcvbulkpipe(usb, 1);
625 hw->endp_out = usb_sndbulkpipe(usb, 2);
627 /* Set up the waitq */
628 init_waitqueue_head(&hw->cmdq);
630 /* Initialize the command queue */
631 spin_lock_init(&hw->ctlxq.lock);
632 INIT_LIST_HEAD(&hw->ctlxq.pending);
633 INIT_LIST_HEAD(&hw->ctlxq.active);
634 INIT_LIST_HEAD(&hw->ctlxq.completing);
635 INIT_LIST_HEAD(&hw->ctlxq.reapable);
637 /* Initialize the authentication queue */
638 skb_queue_head_init(&hw->authq);
640 tasklet_init(&hw->reaper_bh,
641 hfa384x_usbctlx_reaper_task,
642 (unsigned long)hw);
643 tasklet_init(&hw->completion_bh,
644 hfa384x_usbctlx_completion_task,
645 (unsigned long)hw);
646 INIT_WORK(&hw->link_bh, prism2sta_processing_defer);
647 INIT_WORK(&hw->usb_work, hfa384x_usb_defer);
649 init_timer(&hw->throttle);
650 hw->throttle.function = hfa384x_usb_throttlefn;
651 hw->throttle.data = (unsigned long)hw;
653 init_timer(&hw->resptimer);
654 hw->resptimer.function = hfa384x_usbctlx_resptimerfn;
655 hw->resptimer.data = (unsigned long)hw;
657 init_timer(&hw->reqtimer);
658 hw->reqtimer.function = hfa384x_usbctlx_reqtimerfn;
659 hw->reqtimer.data = (unsigned long)hw;
661 usb_init_urb(&hw->rx_urb);
662 usb_init_urb(&hw->tx_urb);
663 usb_init_urb(&hw->ctlx_urb);
665 hw->link_status = HFA384x_LINK_NOTCONNECTED;
666 hw->state = HFA384x_STATE_INIT;
668 INIT_WORK(&hw->commsqual_bh, prism2sta_commsqual_defer);
669 init_timer(&hw->commsqual_timer);
670 hw->commsqual_timer.data = (unsigned long) hw;
671 hw->commsqual_timer.function = prism2sta_commsqual_timer;
673 DBFEXIT;
677 /*----------------------------------------------------------------
678 * hfa384x_destroy
680 * Partner to hfa384x_create(). This function cleans up the hw
681 * structure so that it can be freed by the caller using a simple
682 * kfree. Currently, this function is just a placeholder. If, at some
683 * point in the future, an hw in the 'shutdown' state requires a 'deep'
684 * kfree, this is where it should be done. Note that if this function
685 * is called on a _running_ hw structure, the drvr_stop() function is
686 * called.
688 * Arguments:
689 * hw device structure
691 * Returns:
692 * nothing, this function is not allowed to fail.
694 * Side effects:
696 * Call context:
697 * process
698 ----------------------------------------------------------------*/
699 void
700 hfa384x_destroy( hfa384x_t *hw)
702 struct sk_buff *skb;
704 DBFENTER;
706 if ( hw->state == HFA384x_STATE_RUNNING ) {
707 hfa384x_drvr_stop(hw);
709 hw->state = HFA384x_STATE_PREINIT;
711 if (hw->scanresults) {
712 kfree(hw->scanresults);
713 hw->scanresults = NULL;
716 /* Now to clean out the auth queue */
717 while ( (skb = skb_dequeue(&hw->authq)) ) {
718 dev_kfree_skb(skb);
721 DBFEXIT;
725 /*----------------------------------------------------------------
727 static hfa384x_usbctlx_t* usbctlx_alloc(void)
729 hfa384x_usbctlx_t *ctlx;
731 ctlx = kmalloc(sizeof(*ctlx), in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
732 if (ctlx != NULL)
734 memset(ctlx, 0, sizeof(*ctlx));
735 init_completion(&ctlx->done);
738 return ctlx;
742 /*----------------------------------------------------------------
744 ----------------------------------------------------------------*/
745 static int
746 usbctlx_get_status(const hfa384x_usb_cmdresp_t *cmdresp,
747 hfa384x_cmdresult_t *result)
749 DBFENTER;
751 result->status = hfa384x2host_16(cmdresp->status);
752 result->resp0 = hfa384x2host_16(cmdresp->resp0);
753 result->resp1 = hfa384x2host_16(cmdresp->resp1);
754 result->resp2 = hfa384x2host_16(cmdresp->resp2);
756 WLAN_LOG_DEBUG(4, "cmdresult:status=0x%04x "
757 "resp0=0x%04x resp1=0x%04x resp2=0x%04x\n",
758 result->status,
759 result->resp0,
760 result->resp1,
761 result->resp2);
763 DBFEXIT;
764 return (result->status & HFA384x_STATUS_RESULT);
767 static void
768 usbctlx_get_rridresult(const hfa384x_usb_rridresp_t *rridresp,
769 hfa384x_rridresult_t *result)
771 DBFENTER;
773 result->rid = hfa384x2host_16(rridresp->rid);
774 result->riddata = rridresp->data;
775 result->riddata_len = ((hfa384x2host_16(rridresp->frmlen) - 1) * 2);
777 DBFEXIT;
781 /*----------------------------------------------------------------
782 * Completor object:
783 * This completor must be passed to hfa384x_usbctlx_complete_sync()
784 * when processing a CTLX that returns a hfa384x_cmdresult_t structure.
785 ----------------------------------------------------------------*/
786 struct usbctlx_cmd_completor
788 usbctlx_completor_t head;
790 const hfa384x_usb_cmdresp_t *cmdresp;
791 hfa384x_cmdresult_t *result;
793 typedef struct usbctlx_cmd_completor usbctlx_cmd_completor_t;
795 static int usbctlx_cmd_completor_fn(usbctlx_completor_t *head)
797 usbctlx_cmd_completor_t *complete = (usbctlx_cmd_completor_t*)head;
798 return usbctlx_get_status(complete->cmdresp, complete->result);
801 static inline usbctlx_completor_t*
802 init_cmd_completor(usbctlx_cmd_completor_t *completor,
803 const hfa384x_usb_cmdresp_t *cmdresp,
804 hfa384x_cmdresult_t *result)
806 completor->head.complete = usbctlx_cmd_completor_fn;
807 completor->cmdresp = cmdresp;
808 completor->result = result;
809 return &(completor->head);
812 /*----------------------------------------------------------------
813 * Completor object:
814 * This completor must be passed to hfa384x_usbctlx_complete_sync()
815 * when processing a CTLX that reads a RID.
816 ----------------------------------------------------------------*/
817 struct usbctlx_rrid_completor
819 usbctlx_completor_t head;
821 const hfa384x_usb_rridresp_t *rridresp;
822 void *riddata;
823 unsigned int riddatalen;
825 typedef struct usbctlx_rrid_completor usbctlx_rrid_completor_t;
827 static int usbctlx_rrid_completor_fn(usbctlx_completor_t *head)
829 usbctlx_rrid_completor_t *complete = (usbctlx_rrid_completor_t*)head;
830 hfa384x_rridresult_t rridresult;
832 usbctlx_get_rridresult(complete->rridresp, &rridresult);
834 /* Validate the length, note body len calculation in bytes */
835 if ( rridresult.riddata_len != complete->riddatalen ) {
836 WLAN_LOG_WARNING(
837 "RID len mismatch, rid=0x%04x hlen=%d fwlen=%d\n",
838 rridresult.rid,
839 complete->riddatalen,
840 rridresult.riddata_len);
841 return -ENODATA;
844 memcpy(complete->riddata,
845 rridresult.riddata,
846 complete->riddatalen);
847 return 0;
850 static inline usbctlx_completor_t*
851 init_rrid_completor(usbctlx_rrid_completor_t *completor,
852 const hfa384x_usb_rridresp_t *rridresp,
853 void *riddata,
854 unsigned int riddatalen)
856 completor->head.complete = usbctlx_rrid_completor_fn;
857 completor->rridresp = rridresp;
858 completor->riddata = riddata;
859 completor->riddatalen = riddatalen;
860 return &(completor->head);
863 /*----------------------------------------------------------------
864 * Completor object:
865 * Interprets the results of a synchronous RID-write
866 ----------------------------------------------------------------*/
867 typedef usbctlx_cmd_completor_t usbctlx_wrid_completor_t;
868 #define init_wrid_completor init_cmd_completor
870 /*----------------------------------------------------------------
871 * Completor object:
872 * Interprets the results of a synchronous memory-write
873 ----------------------------------------------------------------*/
874 typedef usbctlx_cmd_completor_t usbctlx_wmem_completor_t;
875 #define init_wmem_completor init_cmd_completor
877 /*----------------------------------------------------------------
878 * Completor object:
879 * Interprets the results of a synchronous memory-read
880 ----------------------------------------------------------------*/
881 struct usbctlx_rmem_completor
883 usbctlx_completor_t head;
885 const hfa384x_usb_rmemresp_t *rmemresp;
886 void *data;
887 unsigned int len;
889 typedef struct usbctlx_rmem_completor usbctlx_rmem_completor_t;
891 static int usbctlx_rmem_completor_fn(usbctlx_completor_t *head)
893 usbctlx_rmem_completor_t *complete = (usbctlx_rmem_completor_t*)head;
895 WLAN_LOG_DEBUG(4,"rmemresp:len=%d\n", complete->rmemresp->frmlen);
896 memcpy(complete->data, complete->rmemresp->data, complete->len);
897 return 0;
900 static inline usbctlx_completor_t*
901 init_rmem_completor(usbctlx_rmem_completor_t *completor,
902 hfa384x_usb_rmemresp_t *rmemresp,
903 void *data,
904 unsigned int len)
906 completor->head.complete = usbctlx_rmem_completor_fn;
907 completor->rmemresp = rmemresp;
908 completor->data = data;
909 completor->len = len;
910 return &(completor->head);
913 /*----------------------------------------------------------------
914 * hfa384x_cb_status
916 * Ctlx_complete handler for async CMD type control exchanges.
917 * mark the hw struct as such.
919 * Note: If the handling is changed here, it should probably be
920 * changed in docmd as well.
922 * Arguments:
923 * hw hw struct
924 * ctlx completed CTLX
926 * Returns:
927 * nothing
929 * Side effects:
931 * Call context:
932 * interrupt
933 ----------------------------------------------------------------*/
934 static void
935 hfa384x_cb_status(hfa384x_t *hw, const hfa384x_usbctlx_t *ctlx)
937 DBFENTER;
939 if ( ctlx->usercb != NULL ) {
940 hfa384x_cmdresult_t cmdresult;
942 if (ctlx->state != CTLX_COMPLETE) {
943 memset(&cmdresult, 0, sizeof(cmdresult));
944 cmdresult.status = HFA384x_STATUS_RESULT_SET(HFA384x_CMD_ERR);
945 } else {
946 usbctlx_get_status(&ctlx->inbuf.cmdresp, &cmdresult);
949 ctlx->usercb(hw, &cmdresult, ctlx->usercb_data);
952 DBFEXIT;
956 /*----------------------------------------------------------------
957 * hfa384x_cb_rrid
959 * CTLX completion handler for async RRID type control exchanges.
961 * Note: If the handling is changed here, it should probably be
962 * changed in dorrid as well.
964 * Arguments:
965 * hw hw struct
966 * ctlx completed CTLX
968 * Returns:
969 * nothing
971 * Side effects:
973 * Call context:
974 * interrupt
975 ----------------------------------------------------------------*/
976 static void
977 hfa384x_cb_rrid(hfa384x_t *hw, const hfa384x_usbctlx_t *ctlx)
979 DBFENTER;
981 if ( ctlx->usercb != NULL ) {
982 hfa384x_rridresult_t rridresult;
984 if (ctlx->state != CTLX_COMPLETE) {
985 memset(&rridresult, 0, sizeof(rridresult));
986 rridresult.rid = hfa384x2host_16(ctlx->outbuf.rridreq.rid);
987 } else {
988 usbctlx_get_rridresult(&ctlx->inbuf.rridresp, &rridresult);
991 ctlx->usercb(hw, &rridresult, ctlx->usercb_data);
994 DBFEXIT;
997 static inline int
998 hfa384x_docmd_wait(hfa384x_t *hw, hfa384x_metacmd_t *cmd)
1000 return hfa384x_docmd(hw, DOWAIT, cmd, NULL, NULL, NULL);
1003 static inline int
1004 hfa384x_docmd_async(hfa384x_t *hw,
1005 hfa384x_metacmd_t *cmd,
1006 ctlx_cmdcb_t cmdcb,
1007 ctlx_usercb_t usercb,
1008 void *usercb_data)
1010 return hfa384x_docmd(hw, DOASYNC, cmd,
1011 cmdcb, usercb, usercb_data);
1014 static inline int
1015 hfa384x_dorrid_wait(hfa384x_t *hw, u16 rid, void *riddata, unsigned int riddatalen)
1017 return hfa384x_dorrid(hw, DOWAIT,
1018 rid, riddata, riddatalen,
1019 NULL, NULL, NULL);
1022 static inline int
1023 hfa384x_dorrid_async(hfa384x_t *hw,
1024 u16 rid, void *riddata, unsigned int riddatalen,
1025 ctlx_cmdcb_t cmdcb,
1026 ctlx_usercb_t usercb,
1027 void *usercb_data)
1029 return hfa384x_dorrid(hw, DOASYNC,
1030 rid, riddata, riddatalen,
1031 cmdcb, usercb, usercb_data);
1034 static inline int
1035 hfa384x_dowrid_wait(hfa384x_t *hw, u16 rid, void *riddata, unsigned int riddatalen)
1037 return hfa384x_dowrid(hw, DOWAIT,
1038 rid, riddata, riddatalen,
1039 NULL, NULL, NULL);
1042 static inline int
1043 hfa384x_dowrid_async(hfa384x_t *hw,
1044 u16 rid, void *riddata, unsigned int riddatalen,
1045 ctlx_cmdcb_t cmdcb,
1046 ctlx_usercb_t usercb,
1047 void *usercb_data)
1049 return hfa384x_dowrid(hw, DOASYNC,
1050 rid, riddata, riddatalen,
1051 cmdcb, usercb, usercb_data);
1054 static inline int
1055 hfa384x_dormem_wait(hfa384x_t *hw,
1056 u16 page, u16 offset, void *data, unsigned int len)
1058 return hfa384x_dormem(hw, DOWAIT,
1059 page, offset, data, len,
1060 NULL, NULL, NULL);
1063 static inline int
1064 hfa384x_dormem_async(hfa384x_t *hw,
1065 u16 page, u16 offset, void *data, unsigned int len,
1066 ctlx_cmdcb_t cmdcb,
1067 ctlx_usercb_t usercb,
1068 void *usercb_data)
1070 return hfa384x_dormem(hw, DOASYNC,
1071 page, offset, data, len,
1072 cmdcb, usercb, usercb_data);
1075 static inline int
1076 hfa384x_dowmem_wait(
1077 hfa384x_t *hw,
1078 u16 page,
1079 u16 offset,
1080 void *data,
1081 unsigned int len)
1083 return hfa384x_dowmem(hw, DOWAIT,
1084 page, offset, data, len,
1085 NULL, NULL, NULL);
1088 static inline int
1089 hfa384x_dowmem_async(
1090 hfa384x_t *hw,
1091 u16 page,
1092 u16 offset,
1093 void *data,
1094 unsigned int len,
1095 ctlx_cmdcb_t cmdcb,
1096 ctlx_usercb_t usercb,
1097 void *usercb_data)
1099 return hfa384x_dowmem(hw, DOASYNC,
1100 page, offset, data, len,
1101 cmdcb, usercb, usercb_data);
1104 /*----------------------------------------------------------------
1105 * hfa384x_cmd_initialize
1107 * Issues the initialize command and sets the hw->state based
1108 * on the result.
1110 * Arguments:
1111 * hw device structure
1113 * Returns:
1114 * 0 success
1115 * >0 f/w reported error - f/w status code
1116 * <0 driver reported error
1118 * Side effects:
1120 * Call context:
1121 * process
1122 ----------------------------------------------------------------*/
1124 hfa384x_cmd_initialize(hfa384x_t *hw)
1126 int result = 0;
1127 int i;
1128 hfa384x_metacmd_t cmd;
1130 DBFENTER;
1133 cmd.cmd = HFA384x_CMDCODE_INIT;
1134 cmd.parm0 = 0;
1135 cmd.parm1 = 0;
1136 cmd.parm2 = 0;
1138 result = hfa384x_docmd_wait(hw, &cmd);
1141 WLAN_LOG_DEBUG(3,"cmdresp.init: "
1142 "status=0x%04x, resp0=0x%04x, "
1143 "resp1=0x%04x, resp2=0x%04x\n",
1144 cmd.result.status,
1145 cmd.result.resp0,
1146 cmd.result.resp1,
1147 cmd.result.resp2);
1148 if ( result == 0 ) {
1149 for ( i = 0; i < HFA384x_NUMPORTS_MAX; i++) {
1150 hw->port_enabled[i] = 0;
1154 hw->link_status = HFA384x_LINK_NOTCONNECTED;
1156 DBFEXIT;
1157 return result;
1161 /*----------------------------------------------------------------
1162 * hfa384x_cmd_disable
1164 * Issues the disable command to stop communications on one of
1165 * the MACs 'ports'.
1167 * Arguments:
1168 * hw device structure
1169 * macport MAC port number (host order)
1171 * Returns:
1172 * 0 success
1173 * >0 f/w reported failure - f/w status code
1174 * <0 driver reported error (timeout|bad arg)
1176 * Side effects:
1178 * Call context:
1179 * process
1180 ----------------------------------------------------------------*/
1181 int hfa384x_cmd_disable(hfa384x_t *hw, u16 macport)
1183 int result = 0;
1184 hfa384x_metacmd_t cmd;
1186 DBFENTER;
1188 cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_DISABLE) |
1189 HFA384x_CMD_MACPORT_SET(macport);
1190 cmd.parm0 = 0;
1191 cmd.parm1 = 0;
1192 cmd.parm2 = 0;
1194 result = hfa384x_docmd_wait(hw, &cmd);
1196 DBFEXIT;
1197 return result;
1201 /*----------------------------------------------------------------
1202 * hfa384x_cmd_enable
1204 * Issues the enable command to enable communications on one of
1205 * the MACs 'ports'.
1207 * Arguments:
1208 * hw device structure
1209 * macport MAC port number
1211 * Returns:
1212 * 0 success
1213 * >0 f/w reported failure - f/w status code
1214 * <0 driver reported error (timeout|bad arg)
1216 * Side effects:
1218 * Call context:
1219 * process
1220 ----------------------------------------------------------------*/
1221 int hfa384x_cmd_enable(hfa384x_t *hw, u16 macport)
1223 int result = 0;
1224 hfa384x_metacmd_t cmd;
1226 DBFENTER;
1228 cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_ENABLE) |
1229 HFA384x_CMD_MACPORT_SET(macport);
1230 cmd.parm0 = 0;
1231 cmd.parm1 = 0;
1232 cmd.parm2 = 0;
1234 result = hfa384x_docmd_wait(hw, &cmd);
1236 DBFEXIT;
1237 return result;
1240 /*----------------------------------------------------------------
1241 * hfa384x_cmd_monitor
1243 * Enables the 'monitor mode' of the MAC. Here's the description of
1244 * monitor mode that I've received thus far:
1246 * "The "monitor mode" of operation is that the MAC passes all
1247 * frames for which the PLCP checks are correct. All received
1248 * MPDUs are passed to the host with MAC Port = 7, with a
1249 * receive status of good, FCS error, or undecryptable. Passing
1250 * certain MPDUs is a violation of the 802.11 standard, but useful
1251 * for a debugging tool." Normal communication is not possible
1252 * while monitor mode is enabled.
1254 * Arguments:
1255 * hw device structure
1256 * enable a code (0x0b|0x0f) that enables/disables
1257 * monitor mode. (host order)
1259 * Returns:
1260 * 0 success
1261 * >0 f/w reported failure - f/w status code
1262 * <0 driver reported error (timeout|bad arg)
1264 * Side effects:
1266 * Call context:
1267 * process
1268 ----------------------------------------------------------------*/
1269 int hfa384x_cmd_monitor(hfa384x_t *hw, u16 enable)
1271 int result = 0;
1272 hfa384x_metacmd_t cmd;
1274 DBFENTER;
1276 cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_MONITOR) |
1277 HFA384x_CMD_AINFO_SET(enable);
1278 cmd.parm0 = 0;
1279 cmd.parm1 = 0;
1280 cmd.parm2 = 0;
1282 result = hfa384x_docmd_wait(hw, &cmd);
1284 DBFEXIT;
1285 return result;
1289 /*----------------------------------------------------------------
1290 * hfa384x_cmd_download
1292 * Sets the controls for the MAC controller code/data download
1293 * process. The arguments set the mode and address associated
1294 * with a download. Note that the aux registers should be enabled
1295 * prior to setting one of the download enable modes.
1297 * Arguments:
1298 * hw device structure
1299 * mode 0 - Disable programming and begin code exec
1300 * 1 - Enable volatile mem programming
1301 * 2 - Enable non-volatile mem programming
1302 * 3 - Program non-volatile section from NV download
1303 * buffer.
1304 * (host order)
1305 * lowaddr
1306 * highaddr For mode 1, sets the high & low order bits of
1307 * the "destination address". This address will be
1308 * the execution start address when download is
1309 * subsequently disabled.
1310 * For mode 2, sets the high & low order bits of
1311 * the destination in NV ram.
1312 * For modes 0 & 3, should be zero. (host order)
1313 * NOTE: these are CMD format.
1314 * codelen Length of the data to write in mode 2,
1315 * zero otherwise. (host order)
1317 * Returns:
1318 * 0 success
1319 * >0 f/w reported failure - f/w status code
1320 * <0 driver reported error (timeout|bad arg)
1322 * Side effects:
1324 * Call context:
1325 * process
1326 ----------------------------------------------------------------*/
1327 int hfa384x_cmd_download(hfa384x_t *hw, u16 mode, u16 lowaddr,
1328 u16 highaddr, u16 codelen)
1330 int result = 0;
1331 hfa384x_metacmd_t cmd;
1333 DBFENTER;
1334 WLAN_LOG_DEBUG(5,
1335 "mode=%d, lowaddr=0x%04x, highaddr=0x%04x, codelen=%d\n",
1336 mode, lowaddr, highaddr, codelen);
1338 cmd.cmd = (HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_DOWNLD) |
1339 HFA384x_CMD_PROGMODE_SET(mode));
1341 cmd.parm0 = lowaddr;
1342 cmd.parm1 = highaddr;
1343 cmd.parm2 = codelen;
1345 result = hfa384x_docmd_wait(hw, &cmd);
1347 DBFEXIT;
1348 return result;
1352 /*----------------------------------------------------------------
1353 * hfa384x_copy_from_aux
1355 * Copies a collection of bytes from the controller memory. The
1356 * Auxiliary port MUST be enabled prior to calling this function.
1357 * We _might_ be in a download state.
1359 * Arguments:
1360 * hw device structure
1361 * cardaddr address in hfa384x data space to read
1362 * auxctl address space select
1363 * buf ptr to destination host buffer
1364 * len length of data to transfer (in bytes)
1366 * Returns:
1367 * nothing
1369 * Side effects:
1370 * buf contains the data copied
1372 * Call context:
1373 * process
1374 * interrupt
1375 ----------------------------------------------------------------*/
1376 void
1377 hfa384x_copy_from_aux(
1378 hfa384x_t *hw, u32 cardaddr, u32 auxctl, void *buf, unsigned int len)
1380 DBFENTER;
1381 WLAN_LOG_ERROR("not used in USB.\n");
1382 DBFEXIT;
1386 /*----------------------------------------------------------------
1387 * hfa384x_copy_to_aux
1389 * Copies a collection of bytes to the controller memory. The
1390 * Auxiliary port MUST be enabled prior to calling this function.
1391 * We _might_ be in a download state.
1393 * Arguments:
1394 * hw device structure
1395 * cardaddr address in hfa384x data space to read
1396 * auxctl address space select
1397 * buf ptr to destination host buffer
1398 * len length of data to transfer (in bytes)
1400 * Returns:
1401 * nothing
1403 * Side effects:
1404 * Controller memory now contains a copy of buf
1406 * Call context:
1407 * process
1408 * interrupt
1409 ----------------------------------------------------------------*/
1410 void
1411 hfa384x_copy_to_aux(
1412 hfa384x_t *hw, u32 cardaddr, u32 auxctl, void *buf, unsigned int len)
1414 DBFENTER;
1415 WLAN_LOG_ERROR("not used in USB.\n");
1416 DBFEXIT;
1420 /*----------------------------------------------------------------
1421 * hfa384x_corereset
1423 * Perform a reset of the hfa38xx MAC core. We assume that the hw
1424 * structure is in its "created" state. That is, it is initialized
1425 * with proper values. Note that if a reset is done after the
1426 * device has been active for awhile, the caller might have to clean
1427 * up some leftover cruft in the hw structure.
1429 * Arguments:
1430 * hw device structure
1431 * holdtime how long (in ms) to hold the reset
1432 * settletime how long (in ms) to wait after releasing
1433 * the reset
1435 * Returns:
1436 * nothing
1438 * Side effects:
1440 * Call context:
1441 * process
1442 ----------------------------------------------------------------*/
1443 int hfa384x_corereset(hfa384x_t *hw, int holdtime, int settletime, int genesis)
1445 int result = 0;
1447 DBFENTER;
1449 result=usb_reset_device(hw->usb);
1450 if(result<0) {
1451 WLAN_LOG_ERROR("usb_reset_device() failed, result=%d.\n",result);
1454 DBFEXIT;
1455 return result;
1459 /*----------------------------------------------------------------
1460 * hfa384x_usbctlx_complete_sync
1462 * Waits for a synchronous CTLX object to complete,
1463 * and then handles the response.
1465 * Arguments:
1466 * hw device structure
1467 * ctlx CTLX ptr
1468 * completor functor object to decide what to
1469 * do with the CTLX's result.
1471 * Returns:
1472 * 0 Success
1473 * -ERESTARTSYS Interrupted by a signal
1474 * -EIO CTLX failed
1475 * -ENODEV Adapter was unplugged
1476 * ??? Result from completor
1478 * Side effects:
1480 * Call context:
1481 * process
1482 ----------------------------------------------------------------*/
1483 static int hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
1484 hfa384x_usbctlx_t *ctlx,
1485 usbctlx_completor_t *completor)
1487 unsigned long flags;
1488 int result;
1490 DBFENTER;
1492 result = wait_for_completion_interruptible(&ctlx->done);
1494 spin_lock_irqsave(&hw->ctlxq.lock, flags);
1497 * We can only handle the CTLX if the USB disconnect
1498 * function has not run yet ...
1500 cleanup:
1501 if ( hw->wlandev->hwremoved )
1503 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1504 result = -ENODEV;
1506 else if ( result != 0 )
1508 int runqueue = 0;
1511 * We were probably interrupted, so delete
1512 * this CTLX asynchronously, kill the timers
1513 * and the URB, and then start the next
1514 * pending CTLX.
1516 * NOTE: We can only delete the timers and
1517 * the URB if this CTLX is active.
1519 if (ctlx == get_active_ctlx(hw))
1521 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1523 del_singleshot_timer_sync(&hw->reqtimer);
1524 del_singleshot_timer_sync(&hw->resptimer);
1525 hw->req_timer_done = 1;
1526 hw->resp_timer_done = 1;
1527 usb_kill_urb(&hw->ctlx_urb);
1529 spin_lock_irqsave(&hw->ctlxq.lock, flags);
1531 runqueue = 1;
1534 * This scenario is so unlikely that I'm
1535 * happy with a grubby "goto" solution ...
1537 if ( hw->wlandev->hwremoved )
1538 goto cleanup;
1542 * The completion task will send this CTLX
1543 * to the reaper the next time it runs. We
1544 * are no longer in a hurry.
1546 ctlx->reapable = 1;
1547 ctlx->state = CTLX_REQ_FAILED;
1548 list_move_tail(&ctlx->list, &hw->ctlxq.completing);
1550 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1552 if (runqueue)
1553 hfa384x_usbctlxq_run(hw);
1554 } else {
1555 if (ctlx->state == CTLX_COMPLETE) {
1556 result = completor->complete(completor);
1557 } else {
1558 WLAN_LOG_WARNING("CTLX[%d] error: state(%s)\n",
1559 hfa384x2host_16(ctlx->outbuf.type),
1560 ctlxstr(ctlx->state));
1561 result = -EIO;
1564 list_del(&ctlx->list);
1565 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1566 kfree(ctlx);
1569 DBFEXIT;
1570 return result;
1573 /*----------------------------------------------------------------
1574 * hfa384x_docmd
1576 * Constructs a command CTLX and submits it.
1578 * NOTE: Any changes to the 'post-submit' code in this function
1579 * need to be carried over to hfa384x_cbcmd() since the handling
1580 * is virtually identical.
1582 * Arguments:
1583 * hw device structure
1584 * mode DOWAIT or DOASYNC
1585 * cmd cmd structure. Includes all arguments and result
1586 * data points. All in host order. in host order
1587 * cmdcb command-specific callback
1588 * usercb user callback for async calls, NULL for DOWAIT calls
1589 * usercb_data user supplied data pointer for async calls, NULL
1590 * for DOASYNC calls
1592 * Returns:
1593 * 0 success
1594 * -EIO CTLX failure
1595 * -ERESTARTSYS Awakened on signal
1596 * >0 command indicated error, Status and Resp0-2 are
1597 * in hw structure.
1599 * Side effects:
1602 * Call context:
1603 * process
1604 ----------------------------------------------------------------*/
1605 static int
1606 hfa384x_docmd(
1607 hfa384x_t *hw,
1608 CMD_MODE mode,
1609 hfa384x_metacmd_t *cmd,
1610 ctlx_cmdcb_t cmdcb,
1611 ctlx_usercb_t usercb,
1612 void *usercb_data)
1614 int result;
1615 hfa384x_usbctlx_t *ctlx;
1617 DBFENTER;
1618 ctlx = usbctlx_alloc();
1619 if ( ctlx == NULL ) {
1620 result = -ENOMEM;
1621 goto done;
1624 /* Initialize the command */
1625 ctlx->outbuf.cmdreq.type = host2hfa384x_16(HFA384x_USB_CMDREQ);
1626 ctlx->outbuf.cmdreq.cmd = host2hfa384x_16(cmd->cmd);
1627 ctlx->outbuf.cmdreq.parm0 = host2hfa384x_16(cmd->parm0);
1628 ctlx->outbuf.cmdreq.parm1 = host2hfa384x_16(cmd->parm1);
1629 ctlx->outbuf.cmdreq.parm2 = host2hfa384x_16(cmd->parm2);
1631 ctlx->outbufsize = sizeof(ctlx->outbuf.cmdreq);
1633 WLAN_LOG_DEBUG(4, "cmdreq: cmd=0x%04x "
1634 "parm0=0x%04x parm1=0x%04x parm2=0x%04x\n",
1635 cmd->cmd,
1636 cmd->parm0,
1637 cmd->parm1,
1638 cmd->parm2);
1640 ctlx->reapable = mode;
1641 ctlx->cmdcb = cmdcb;
1642 ctlx->usercb = usercb;
1643 ctlx->usercb_data = usercb_data;
1645 result = hfa384x_usbctlx_submit(hw, ctlx);
1646 if (result != 0) {
1647 kfree(ctlx);
1648 } else if (mode == DOWAIT) {
1649 usbctlx_cmd_completor_t completor;
1651 result = hfa384x_usbctlx_complete_sync(
1652 hw, ctlx, init_cmd_completor(&completor,
1653 &ctlx->inbuf.cmdresp,
1654 &cmd->result) );
1657 done:
1658 DBFEXIT;
1659 return result;
1663 /*----------------------------------------------------------------
1664 * hfa384x_dorrid
1666 * Constructs a read rid CTLX and issues it.
1668 * NOTE: Any changes to the 'post-submit' code in this function
1669 * need to be carried over to hfa384x_cbrrid() since the handling
1670 * is virtually identical.
1672 * Arguments:
1673 * hw device structure
1674 * mode DOWAIT or DOASYNC
1675 * rid Read RID number (host order)
1676 * riddata Caller supplied buffer that MAC formatted RID.data
1677 * record will be written to for DOWAIT calls. Should
1678 * be NULL for DOASYNC calls.
1679 * riddatalen Buffer length for DOWAIT calls. Zero for DOASYNC calls.
1680 * cmdcb command callback for async calls, NULL for DOWAIT calls
1681 * usercb user callback for async calls, NULL for DOWAIT calls
1682 * usercb_data user supplied data pointer for async calls, NULL
1683 * for DOWAIT calls
1685 * Returns:
1686 * 0 success
1687 * -EIO CTLX failure
1688 * -ERESTARTSYS Awakened on signal
1689 * -ENODATA riddatalen != macdatalen
1690 * >0 command indicated error, Status and Resp0-2 are
1691 * in hw structure.
1693 * Side effects:
1695 * Call context:
1696 * interrupt (DOASYNC)
1697 * process (DOWAIT or DOASYNC)
1698 ----------------------------------------------------------------*/
1699 static int
1700 hfa384x_dorrid(
1701 hfa384x_t *hw,
1702 CMD_MODE mode,
1703 u16 rid,
1704 void *riddata,
1705 unsigned int riddatalen,
1706 ctlx_cmdcb_t cmdcb,
1707 ctlx_usercb_t usercb,
1708 void *usercb_data)
1710 int result;
1711 hfa384x_usbctlx_t *ctlx;
1713 DBFENTER;
1714 ctlx = usbctlx_alloc();
1715 if ( ctlx == NULL ) {
1716 result = -ENOMEM;
1717 goto done;
1720 /* Initialize the command */
1721 ctlx->outbuf.rridreq.type = host2hfa384x_16(HFA384x_USB_RRIDREQ);
1722 ctlx->outbuf.rridreq.frmlen =
1723 host2hfa384x_16(sizeof(ctlx->outbuf.rridreq.rid));
1724 ctlx->outbuf.rridreq.rid = host2hfa384x_16(rid);
1726 ctlx->outbufsize = sizeof(ctlx->outbuf.rridreq);
1728 ctlx->reapable = mode;
1729 ctlx->cmdcb = cmdcb;
1730 ctlx->usercb = usercb;
1731 ctlx->usercb_data = usercb_data;
1733 /* Submit the CTLX */
1734 result = hfa384x_usbctlx_submit(hw, ctlx);
1735 if (result != 0) {
1736 kfree(ctlx);
1737 } else if (mode == DOWAIT) {
1738 usbctlx_rrid_completor_t completor;
1740 result = hfa384x_usbctlx_complete_sync(
1741 hw, ctlx, init_rrid_completor(&completor,
1742 &ctlx->inbuf.rridresp,
1743 riddata,
1744 riddatalen) );
1747 done:
1748 DBFEXIT;
1749 return result;
1753 /*----------------------------------------------------------------
1754 * hfa384x_dowrid
1756 * Constructs a write rid CTLX and issues it.
1758 * NOTE: Any changes to the 'post-submit' code in this function
1759 * need to be carried over to hfa384x_cbwrid() since the handling
1760 * is virtually identical.
1762 * Arguments:
1763 * hw device structure
1764 * CMD_MODE DOWAIT or DOASYNC
1765 * rid RID code
1766 * riddata Data portion of RID formatted for MAC
1767 * riddatalen Length of the data portion in bytes
1768 * cmdcb command callback for async calls, NULL for DOWAIT calls
1769 * usercb user callback for async calls, NULL for DOWAIT calls
1770 * usercb_data user supplied data pointer for async calls
1772 * Returns:
1773 * 0 success
1774 * -ETIMEDOUT timed out waiting for register ready or
1775 * command completion
1776 * >0 command indicated error, Status and Resp0-2 are
1777 * in hw structure.
1779 * Side effects:
1781 * Call context:
1782 * interrupt (DOASYNC)
1783 * process (DOWAIT or DOASYNC)
1784 ----------------------------------------------------------------*/
1785 static int
1786 hfa384x_dowrid(
1787 hfa384x_t *hw,
1788 CMD_MODE mode,
1789 u16 rid,
1790 void *riddata,
1791 unsigned int riddatalen,
1792 ctlx_cmdcb_t cmdcb,
1793 ctlx_usercb_t usercb,
1794 void *usercb_data)
1796 int result;
1797 hfa384x_usbctlx_t *ctlx;
1799 DBFENTER;
1800 ctlx = usbctlx_alloc();
1801 if ( ctlx == NULL ) {
1802 result = -ENOMEM;
1803 goto done;
1806 /* Initialize the command */
1807 ctlx->outbuf.wridreq.type = host2hfa384x_16(HFA384x_USB_WRIDREQ);
1808 ctlx->outbuf.wridreq.frmlen = host2hfa384x_16(
1809 (sizeof(ctlx->outbuf.wridreq.rid) +
1810 riddatalen + 1) / 2);
1811 ctlx->outbuf.wridreq.rid = host2hfa384x_16(rid);
1812 memcpy(ctlx->outbuf.wridreq.data, riddata, riddatalen);
1814 ctlx->outbufsize = sizeof(ctlx->outbuf.wridreq.type) +
1815 sizeof(ctlx->outbuf.wridreq.frmlen) +
1816 sizeof(ctlx->outbuf.wridreq.rid) +
1817 riddatalen;
1819 ctlx->reapable = mode;
1820 ctlx->cmdcb = cmdcb;
1821 ctlx->usercb = usercb;
1822 ctlx->usercb_data = usercb_data;
1824 /* Submit the CTLX */
1825 result = hfa384x_usbctlx_submit(hw, ctlx);
1826 if (result != 0) {
1827 kfree(ctlx);
1828 } else if (mode == DOWAIT) {
1829 usbctlx_wrid_completor_t completor;
1830 hfa384x_cmdresult_t wridresult;
1832 result = hfa384x_usbctlx_complete_sync(
1834 ctlx,
1835 init_wrid_completor(&completor,
1836 &ctlx->inbuf.wridresp,
1837 &wridresult) );
1840 done:
1841 DBFEXIT;
1842 return result;
1845 /*----------------------------------------------------------------
1846 * hfa384x_dormem
1848 * Constructs a readmem CTLX and issues it.
1850 * NOTE: Any changes to the 'post-submit' code in this function
1851 * need to be carried over to hfa384x_cbrmem() since the handling
1852 * is virtually identical.
1854 * Arguments:
1855 * hw device structure
1856 * mode DOWAIT or DOASYNC
1857 * page MAC address space page (CMD format)
1858 * offset MAC address space offset
1859 * data Ptr to data buffer to receive read
1860 * len Length of the data to read (max == 2048)
1861 * cmdcb command callback for async calls, NULL for DOWAIT calls
1862 * usercb user callback for async calls, NULL for DOWAIT calls
1863 * usercb_data user supplied data pointer for async calls
1865 * Returns:
1866 * 0 success
1867 * -ETIMEDOUT timed out waiting for register ready or
1868 * command completion
1869 * >0 command indicated error, Status and Resp0-2 are
1870 * in hw structure.
1872 * Side effects:
1874 * Call context:
1875 * interrupt (DOASYNC)
1876 * process (DOWAIT or DOASYNC)
1877 ----------------------------------------------------------------*/
1878 static int
1879 hfa384x_dormem(
1880 hfa384x_t *hw,
1881 CMD_MODE mode,
1882 u16 page,
1883 u16 offset,
1884 void *data,
1885 unsigned int len,
1886 ctlx_cmdcb_t cmdcb,
1887 ctlx_usercb_t usercb,
1888 void *usercb_data)
1890 int result;
1891 hfa384x_usbctlx_t *ctlx;
1893 DBFENTER;
1894 ctlx = usbctlx_alloc();
1895 if ( ctlx == NULL ) {
1896 result = -ENOMEM;
1897 goto done;
1900 /* Initialize the command */
1901 ctlx->outbuf.rmemreq.type = host2hfa384x_16(HFA384x_USB_RMEMREQ);
1902 ctlx->outbuf.rmemreq.frmlen = host2hfa384x_16(
1903 sizeof(ctlx->outbuf.rmemreq.offset) +
1904 sizeof(ctlx->outbuf.rmemreq.page) +
1905 len);
1906 ctlx->outbuf.rmemreq.offset = host2hfa384x_16(offset);
1907 ctlx->outbuf.rmemreq.page = host2hfa384x_16(page);
1909 ctlx->outbufsize = sizeof(ctlx->outbuf.rmemreq);
1911 WLAN_LOG_DEBUG(4,
1912 "type=0x%04x frmlen=%d offset=0x%04x page=0x%04x\n",
1913 ctlx->outbuf.rmemreq.type,
1914 ctlx->outbuf.rmemreq.frmlen,
1915 ctlx->outbuf.rmemreq.offset,
1916 ctlx->outbuf.rmemreq.page);
1918 WLAN_LOG_DEBUG(4,"pktsize=%zd\n",
1919 ROUNDUP64(sizeof(ctlx->outbuf.rmemreq)));
1921 ctlx->reapable = mode;
1922 ctlx->cmdcb = cmdcb;
1923 ctlx->usercb = usercb;
1924 ctlx->usercb_data = usercb_data;
1926 result = hfa384x_usbctlx_submit(hw, ctlx);
1927 if (result != 0) {
1928 kfree(ctlx);
1929 } else if ( mode == DOWAIT ) {
1930 usbctlx_rmem_completor_t completor;
1932 result = hfa384x_usbctlx_complete_sync(
1933 hw, ctlx, init_rmem_completor(&completor,
1934 &ctlx->inbuf.rmemresp,
1935 data,
1936 len) );
1939 done:
1940 DBFEXIT;
1941 return result;
1946 /*----------------------------------------------------------------
1947 * hfa384x_dowmem
1949 * Constructs a writemem CTLX and issues it.
1951 * NOTE: Any changes to the 'post-submit' code in this function
1952 * need to be carried over to hfa384x_cbwmem() since the handling
1953 * is virtually identical.
1955 * Arguments:
1956 * hw device structure
1957 * mode DOWAIT or DOASYNC
1958 * page MAC address space page (CMD format)
1959 * offset MAC address space offset
1960 * data Ptr to data buffer containing write data
1961 * len Length of the data to read (max == 2048)
1962 * cmdcb command callback for async calls, NULL for DOWAIT calls
1963 * usercb user callback for async calls, NULL for DOWAIT calls
1964 * usercb_data user supplied data pointer for async calls.
1966 * Returns:
1967 * 0 success
1968 * -ETIMEDOUT timed out waiting for register ready or
1969 * command completion
1970 * >0 command indicated error, Status and Resp0-2 are
1971 * in hw structure.
1973 * Side effects:
1975 * Call context:
1976 * interrupt (DOWAIT)
1977 * process (DOWAIT or DOASYNC)
1978 ----------------------------------------------------------------*/
1979 static int
1980 hfa384x_dowmem(
1981 hfa384x_t *hw,
1982 CMD_MODE mode,
1983 u16 page,
1984 u16 offset,
1985 void *data,
1986 unsigned int len,
1987 ctlx_cmdcb_t cmdcb,
1988 ctlx_usercb_t usercb,
1989 void *usercb_data)
1991 int result;
1992 hfa384x_usbctlx_t *ctlx;
1994 DBFENTER;
1995 WLAN_LOG_DEBUG(5, "page=0x%04x offset=0x%04x len=%d\n",
1996 page,offset,len);
1998 ctlx = usbctlx_alloc();
1999 if ( ctlx == NULL ) {
2000 result = -ENOMEM;
2001 goto done;
2004 /* Initialize the command */
2005 ctlx->outbuf.wmemreq.type = host2hfa384x_16(HFA384x_USB_WMEMREQ);
2006 ctlx->outbuf.wmemreq.frmlen = host2hfa384x_16(
2007 sizeof(ctlx->outbuf.wmemreq.offset) +
2008 sizeof(ctlx->outbuf.wmemreq.page) +
2009 len);
2010 ctlx->outbuf.wmemreq.offset = host2hfa384x_16(offset);
2011 ctlx->outbuf.wmemreq.page = host2hfa384x_16(page);
2012 memcpy(ctlx->outbuf.wmemreq.data, data, len);
2014 ctlx->outbufsize = sizeof(ctlx->outbuf.wmemreq.type) +
2015 sizeof(ctlx->outbuf.wmemreq.frmlen) +
2016 sizeof(ctlx->outbuf.wmemreq.offset) +
2017 sizeof(ctlx->outbuf.wmemreq.page) +
2018 len;
2020 ctlx->reapable = mode;
2021 ctlx->cmdcb = cmdcb;
2022 ctlx->usercb = usercb;
2023 ctlx->usercb_data = usercb_data;
2025 result = hfa384x_usbctlx_submit(hw, ctlx);
2026 if (result != 0) {
2027 kfree(ctlx);
2028 } else if ( mode == DOWAIT ) {
2029 usbctlx_wmem_completor_t completor;
2030 hfa384x_cmdresult_t wmemresult;
2032 result = hfa384x_usbctlx_complete_sync(
2034 ctlx,
2035 init_wmem_completor(&completor,
2036 &ctlx->inbuf.wmemresp,
2037 &wmemresult) );
2040 done:
2041 DBFEXIT;
2042 return result;
2046 /*----------------------------------------------------------------
2047 * hfa384x_drvr_commtallies
2049 * Send a commtallies inquiry to the MAC. Note that this is an async
2050 * call that will result in an info frame arriving sometime later.
2052 * Arguments:
2053 * hw device structure
2055 * Returns:
2056 * zero success.
2058 * Side effects:
2060 * Call context:
2061 * process
2062 ----------------------------------------------------------------*/
2063 int hfa384x_drvr_commtallies( hfa384x_t *hw )
2065 hfa384x_metacmd_t cmd;
2067 DBFENTER;
2069 cmd.cmd = HFA384x_CMDCODE_INQ;
2070 cmd.parm0 = HFA384x_IT_COMMTALLIES;
2071 cmd.parm1 = 0;
2072 cmd.parm2 = 0;
2074 hfa384x_docmd_async(hw, &cmd, NULL, NULL, NULL);
2076 DBFEXIT;
2077 return 0;
2081 /*----------------------------------------------------------------
2082 * hfa384x_drvr_disable
2084 * Issues the disable command to stop communications on one of
2085 * the MACs 'ports'. Only macport 0 is valid for stations.
2086 * APs may also disable macports 1-6. Only ports that have been
2087 * previously enabled may be disabled.
2089 * Arguments:
2090 * hw device structure
2091 * macport MAC port number (host order)
2093 * Returns:
2094 * 0 success
2095 * >0 f/w reported failure - f/w status code
2096 * <0 driver reported error (timeout|bad arg)
2098 * Side effects:
2100 * Call context:
2101 * process
2102 ----------------------------------------------------------------*/
2103 int hfa384x_drvr_disable(hfa384x_t *hw, u16 macport)
2105 int result = 0;
2107 DBFENTER;
2108 if ((!hw->isap && macport != 0) ||
2109 (hw->isap && !(macport <= HFA384x_PORTID_MAX)) ||
2110 !(hw->port_enabled[macport]) ){
2111 result = -EINVAL;
2112 } else {
2113 result = hfa384x_cmd_disable(hw, macport);
2114 if ( result == 0 ) {
2115 hw->port_enabled[macport] = 0;
2118 DBFEXIT;
2119 return result;
2123 /*----------------------------------------------------------------
2124 * hfa384x_drvr_enable
2126 * Issues the enable command to enable communications on one of
2127 * the MACs 'ports'. Only macport 0 is valid for stations.
2128 * APs may also enable macports 1-6. Only ports that are currently
2129 * disabled may be enabled.
2131 * Arguments:
2132 * hw device structure
2133 * macport MAC port number
2135 * Returns:
2136 * 0 success
2137 * >0 f/w reported failure - f/w status code
2138 * <0 driver reported error (timeout|bad arg)
2140 * Side effects:
2142 * Call context:
2143 * process
2144 ----------------------------------------------------------------*/
2145 int hfa384x_drvr_enable(hfa384x_t *hw, u16 macport)
2147 int result = 0;
2149 DBFENTER;
2150 if ((!hw->isap && macport != 0) ||
2151 (hw->isap && !(macport <= HFA384x_PORTID_MAX)) ||
2152 (hw->port_enabled[macport]) ){
2153 result = -EINVAL;
2154 } else {
2155 result = hfa384x_cmd_enable(hw, macport);
2156 if ( result == 0 ) {
2157 hw->port_enabled[macport] = 1;
2160 DBFEXIT;
2161 return result;
2165 /*----------------------------------------------------------------
2166 * hfa384x_drvr_flashdl_enable
2168 * Begins the flash download state. Checks to see that we're not
2169 * already in a download state and that a port isn't enabled.
2170 * Sets the download state and retrieves the flash download
2171 * buffer location, buffer size, and timeout length.
2173 * Arguments:
2174 * hw device structure
2176 * Returns:
2177 * 0 success
2178 * >0 f/w reported error - f/w status code
2179 * <0 driver reported error
2181 * Side effects:
2183 * Call context:
2184 * process
2185 ----------------------------------------------------------------*/
2186 int hfa384x_drvr_flashdl_enable(hfa384x_t *hw)
2188 int result = 0;
2189 int i;
2191 DBFENTER;
2192 /* Check that a port isn't active */
2193 for ( i = 0; i < HFA384x_PORTID_MAX; i++) {
2194 if ( hw->port_enabled[i] ) {
2195 WLAN_LOG_DEBUG(1,"called when port enabled.\n");
2196 return -EINVAL;
2200 /* Check that we're not already in a download state */
2201 if ( hw->dlstate != HFA384x_DLSTATE_DISABLED ) {
2202 return -EINVAL;
2205 /* Retrieve the buffer loc&size and timeout */
2206 if ( (result = hfa384x_drvr_getconfig(hw, HFA384x_RID_DOWNLOADBUFFER,
2207 &(hw->bufinfo), sizeof(hw->bufinfo))) ) {
2208 return result;
2210 hw->bufinfo.page = hfa384x2host_16(hw->bufinfo.page);
2211 hw->bufinfo.offset = hfa384x2host_16(hw->bufinfo.offset);
2212 hw->bufinfo.len = hfa384x2host_16(hw->bufinfo.len);
2213 if ( (result = hfa384x_drvr_getconfig16(hw, HFA384x_RID_MAXLOADTIME,
2214 &(hw->dltimeout))) ) {
2215 return result;
2217 hw->dltimeout = hfa384x2host_16(hw->dltimeout);
2219 WLAN_LOG_DEBUG(1,"flashdl_enable\n");
2221 hw->dlstate = HFA384x_DLSTATE_FLASHENABLED;
2222 DBFEXIT;
2223 return result;
2227 /*----------------------------------------------------------------
2228 * hfa384x_drvr_flashdl_disable
2230 * Ends the flash download state. Note that this will cause the MAC
2231 * firmware to restart.
2233 * Arguments:
2234 * hw device structure
2236 * Returns:
2237 * 0 success
2238 * >0 f/w reported error - f/w status code
2239 * <0 driver reported error
2241 * Side effects:
2243 * Call context:
2244 * process
2245 ----------------------------------------------------------------*/
2246 int hfa384x_drvr_flashdl_disable(hfa384x_t *hw)
2248 DBFENTER;
2249 /* Check that we're already in the download state */
2250 if ( hw->dlstate != HFA384x_DLSTATE_FLASHENABLED ) {
2251 return -EINVAL;
2254 WLAN_LOG_DEBUG(1,"flashdl_enable\n");
2256 /* There isn't much we can do at this point, so I don't */
2257 /* bother w/ the return value */
2258 hfa384x_cmd_download(hw, HFA384x_PROGMODE_DISABLE, 0, 0 , 0);
2259 hw->dlstate = HFA384x_DLSTATE_DISABLED;
2261 DBFEXIT;
2262 return 0;
2266 /*----------------------------------------------------------------
2267 * hfa384x_drvr_flashdl_write
2269 * Performs a FLASH download of a chunk of data. First checks to see
2270 * that we're in the FLASH download state, then sets the download
2271 * mode, uses the aux functions to 1) copy the data to the flash
2272 * buffer, 2) sets the download 'write flash' mode, 3) readback and
2273 * compare. Lather rinse, repeat as many times an necessary to get
2274 * all the given data into flash.
2275 * When all data has been written using this function (possibly
2276 * repeatedly), call drvr_flashdl_disable() to end the download state
2277 * and restart the MAC.
2279 * Arguments:
2280 * hw device structure
2281 * daddr Card address to write to. (host order)
2282 * buf Ptr to data to write.
2283 * len Length of data (host order).
2285 * Returns:
2286 * 0 success
2287 * >0 f/w reported error - f/w status code
2288 * <0 driver reported error
2290 * Side effects:
2292 * Call context:
2293 * process
2294 ----------------------------------------------------------------*/
2296 hfa384x_drvr_flashdl_write(
2297 hfa384x_t *hw,
2298 u32 daddr,
2299 void *buf,
2300 u32 len)
2302 int result = 0;
2303 u32 dlbufaddr;
2304 int nburns;
2305 u32 burnlen;
2306 u32 burndaddr;
2307 u16 burnlo;
2308 u16 burnhi;
2309 int nwrites;
2310 u8 *writebuf;
2311 u16 writepage;
2312 u16 writeoffset;
2313 u32 writelen;
2314 int i;
2315 int j;
2317 DBFENTER;
2318 WLAN_LOG_DEBUG(5,"daddr=0x%08x len=%d\n", daddr, len);
2320 /* Check that we're in the flash download state */
2321 if ( hw->dlstate != HFA384x_DLSTATE_FLASHENABLED ) {
2322 return -EINVAL;
2325 WLAN_LOG_INFO("Download %d bytes to flash @0x%06x\n", len, daddr);
2327 /* Convert to flat address for arithmetic */
2328 /* NOTE: dlbuffer RID stores the address in AUX format */
2329 dlbufaddr = HFA384x_ADDR_AUX_MKFLAT(
2330 hw->bufinfo.page, hw->bufinfo.offset);
2331 WLAN_LOG_DEBUG(5,
2332 "dlbuf.page=0x%04x dlbuf.offset=0x%04x dlbufaddr=0x%08x\n",
2333 hw->bufinfo.page, hw->bufinfo.offset, dlbufaddr);
2335 #if 0
2336 WLAN_LOG_WARNING("dlbuf@0x%06lx len=%d to=%d\n", dlbufaddr, hw->bufinfo.len, hw->dltimeout);
2337 #endif
2338 /* Calculations to determine how many fills of the dlbuffer to do
2339 * and how many USB wmemreq's to do for each fill. At this point
2340 * in time, the dlbuffer size and the wmemreq size are the same.
2341 * Therefore, nwrites should always be 1. The extra complexity
2342 * here is a hedge against future changes.
2345 /* Figure out how many times to do the flash programming */
2346 nburns = len / hw->bufinfo.len;
2347 nburns += (len % hw->bufinfo.len) ? 1 : 0;
2349 /* For each flash program cycle, how many USB wmemreq's are needed? */
2350 nwrites = hw->bufinfo.len / HFA384x_USB_RWMEM_MAXLEN;
2351 nwrites += (hw->bufinfo.len % HFA384x_USB_RWMEM_MAXLEN) ? 1 : 0;
2353 /* For each burn */
2354 for ( i = 0; i < nburns; i++) {
2355 /* Get the dest address and len */
2356 burnlen = (len - (hw->bufinfo.len * i)) > hw->bufinfo.len ?
2357 hw->bufinfo.len :
2358 (len - (hw->bufinfo.len * i));
2359 burndaddr = daddr + (hw->bufinfo.len * i);
2360 burnlo = HFA384x_ADDR_CMD_MKOFF(burndaddr);
2361 burnhi = HFA384x_ADDR_CMD_MKPAGE(burndaddr);
2363 WLAN_LOG_INFO("Writing %d bytes to flash @0x%06x\n",
2364 burnlen, burndaddr);
2366 /* Set the download mode */
2367 result = hfa384x_cmd_download(hw, HFA384x_PROGMODE_NV,
2368 burnlo, burnhi, burnlen);
2369 if ( result ) {
2370 WLAN_LOG_ERROR("download(NV,lo=%x,hi=%x,len=%x) "
2371 "cmd failed, result=%d. Aborting d/l\n",
2372 burnlo, burnhi, burnlen, result);
2373 goto exit_proc;
2376 /* copy the data to the flash download buffer */
2377 for ( j=0; j < nwrites; j++) {
2378 writebuf = buf +
2379 (i*hw->bufinfo.len) +
2380 (j*HFA384x_USB_RWMEM_MAXLEN);
2382 writepage = HFA384x_ADDR_CMD_MKPAGE(
2383 dlbufaddr +
2384 (j*HFA384x_USB_RWMEM_MAXLEN));
2385 writeoffset = HFA384x_ADDR_CMD_MKOFF(
2386 dlbufaddr +
2387 (j*HFA384x_USB_RWMEM_MAXLEN));
2389 writelen = burnlen-(j*HFA384x_USB_RWMEM_MAXLEN);
2390 writelen = writelen > HFA384x_USB_RWMEM_MAXLEN ?
2391 HFA384x_USB_RWMEM_MAXLEN :
2392 writelen;
2394 result = hfa384x_dowmem_wait( hw,
2395 writepage,
2396 writeoffset,
2397 writebuf,
2398 writelen );
2399 #if 0
2401 Comment out for debugging, assume the write was successful.
2402 if (result) {
2403 WLAN_LOG_ERROR(
2404 "Write to dl buffer failed, "
2405 "result=0x%04x. Aborting.\n",
2406 result);
2407 goto exit_proc;
2409 #endif
2413 /* set the download 'write flash' mode */
2414 result = hfa384x_cmd_download(hw,
2415 HFA384x_PROGMODE_NVWRITE,
2416 0,0,0);
2417 if ( result ) {
2418 WLAN_LOG_ERROR(
2419 "download(NVWRITE,lo=%x,hi=%x,len=%x) "
2420 "cmd failed, result=%d. Aborting d/l\n",
2421 burnlo, burnhi, burnlen, result);
2422 goto exit_proc;
2425 /* TODO: We really should do a readback and compare. */
2428 exit_proc:
2430 /* Leave the firmware in the 'post-prog' mode. flashdl_disable will */
2431 /* actually disable programming mode. Remember, that will cause the */
2432 /* the firmware to effectively reset itself. */
2434 DBFEXIT;
2435 return result;
2439 /*----------------------------------------------------------------
2440 * hfa384x_drvr_getconfig
2442 * Performs the sequence necessary to read a config/info item.
2444 * Arguments:
2445 * hw device structure
2446 * rid config/info record id (host order)
2447 * buf host side record buffer. Upon return it will
2448 * contain the body portion of the record (minus the
2449 * RID and len).
2450 * len buffer length (in bytes, should match record length)
2452 * Returns:
2453 * 0 success
2454 * >0 f/w reported error - f/w status code
2455 * <0 driver reported error
2456 * -ENODATA length mismatch between argument and retrieved
2457 * record.
2459 * Side effects:
2461 * Call context:
2462 * process
2463 ----------------------------------------------------------------*/
2464 int hfa384x_drvr_getconfig(hfa384x_t *hw, u16 rid, void *buf, u16 len)
2466 int result;
2467 DBFENTER;
2469 result = hfa384x_dorrid_wait(hw, rid, buf, len);
2471 DBFEXIT;
2472 return result;
2475 /*----------------------------------------------------------------
2476 * hfa384x_drvr_getconfig_async
2478 * Performs the sequence necessary to perform an async read of
2479 * of a config/info item.
2481 * Arguments:
2482 * hw device structure
2483 * rid config/info record id (host order)
2484 * buf host side record buffer. Upon return it will
2485 * contain the body portion of the record (minus the
2486 * RID and len).
2487 * len buffer length (in bytes, should match record length)
2488 * cbfn caller supplied callback, called when the command
2489 * is done (successful or not).
2490 * cbfndata pointer to some caller supplied data that will be
2491 * passed in as an argument to the cbfn.
2493 * Returns:
2494 * nothing the cbfn gets a status argument identifying if
2495 * any errors occur.
2496 * Side effects:
2497 * Queues an hfa384x_usbcmd_t for subsequent execution.
2499 * Call context:
2500 * Any
2501 ----------------------------------------------------------------*/
2503 hfa384x_drvr_getconfig_async(
2504 hfa384x_t *hw,
2505 u16 rid,
2506 ctlx_usercb_t usercb,
2507 void *usercb_data)
2509 return hfa384x_dorrid_async(hw, rid, NULL, 0,
2510 hfa384x_cb_rrid, usercb, usercb_data);
2513 /*----------------------------------------------------------------
2514 * hfa384x_drvr_setconfig_async
2516 * Performs the sequence necessary to write a config/info item.
2518 * Arguments:
2519 * hw device structure
2520 * rid config/info record id (in host order)
2521 * buf host side record buffer
2522 * len buffer length (in bytes)
2523 * usercb completion callback
2524 * usercb_data completion callback argument
2526 * Returns:
2527 * 0 success
2528 * >0 f/w reported error - f/w status code
2529 * <0 driver reported error
2531 * Side effects:
2533 * Call context:
2534 * process
2535 ----------------------------------------------------------------*/
2537 hfa384x_drvr_setconfig_async(
2538 hfa384x_t *hw,
2539 u16 rid,
2540 void *buf,
2541 u16 len,
2542 ctlx_usercb_t usercb,
2543 void *usercb_data)
2545 return hfa384x_dowrid_async(hw, rid, buf, len,
2546 hfa384x_cb_status, usercb, usercb_data);
2549 /*----------------------------------------------------------------
2550 * hfa384x_drvr_handover
2552 * Sends a handover notification to the MAC.
2554 * Arguments:
2555 * hw device structure
2556 * addr address of station that's left
2558 * Returns:
2559 * zero success.
2560 * -ERESTARTSYS received signal while waiting for semaphore.
2561 * -EIO failed to write to bap, or failed in cmd.
2563 * Side effects:
2565 * Call context:
2566 * process
2567 ----------------------------------------------------------------*/
2568 int hfa384x_drvr_handover( hfa384x_t *hw, u8 *addr)
2570 DBFENTER;
2571 WLAN_LOG_ERROR("Not currently supported in USB!\n");
2572 DBFEXIT;
2573 return -EIO;
2576 /*----------------------------------------------------------------
2577 * hfa384x_drvr_low_level
2579 * Write test commands to the card. Some test commands don't make
2580 * sense without prior set-up. For example, continous TX isn't very
2581 * useful until you set the channel. That functionality should be
2583 * Side effects:
2585 * Call context:
2586 * process thread
2587 * -----------------------------------------------------------------*/
2588 int hfa384x_drvr_low_level(hfa384x_t *hw, hfa384x_metacmd_t *cmd)
2590 int result;
2591 DBFENTER;
2593 /* Do i need a host2hfa... conversion ? */
2595 result = hfa384x_docmd_wait(hw, cmd);
2597 DBFEXIT;
2598 return result;
2601 /*----------------------------------------------------------------
2602 * hfa384x_drvr_ramdl_disable
2604 * Ends the ram download state.
2606 * Arguments:
2607 * hw device structure
2609 * Returns:
2610 * 0 success
2611 * >0 f/w reported error - f/w status code
2612 * <0 driver reported error
2614 * Side effects:
2616 * Call context:
2617 * process
2618 ----------------------------------------------------------------*/
2620 hfa384x_drvr_ramdl_disable(hfa384x_t *hw)
2622 DBFENTER;
2623 /* Check that we're already in the download state */
2624 if ( hw->dlstate != HFA384x_DLSTATE_RAMENABLED ) {
2625 return -EINVAL;
2628 WLAN_LOG_DEBUG(3,"ramdl_disable()\n");
2630 /* There isn't much we can do at this point, so I don't */
2631 /* bother w/ the return value */
2632 hfa384x_cmd_download(hw, HFA384x_PROGMODE_DISABLE, 0, 0 , 0);
2633 hw->dlstate = HFA384x_DLSTATE_DISABLED;
2635 DBFEXIT;
2636 return 0;
2640 /*----------------------------------------------------------------
2641 * hfa384x_drvr_ramdl_enable
2643 * Begins the ram download state. Checks to see that we're not
2644 * already in a download state and that a port isn't enabled.
2645 * Sets the download state and calls cmd_download with the
2646 * ENABLE_VOLATILE subcommand and the exeaddr argument.
2648 * Arguments:
2649 * hw device structure
2650 * exeaddr the card execution address that will be
2651 * jumped to when ramdl_disable() is called
2652 * (host order).
2654 * Returns:
2655 * 0 success
2656 * >0 f/w reported error - f/w status code
2657 * <0 driver reported error
2659 * Side effects:
2661 * Call context:
2662 * process
2663 ----------------------------------------------------------------*/
2665 hfa384x_drvr_ramdl_enable(hfa384x_t *hw, u32 exeaddr)
2667 int result = 0;
2668 u16 lowaddr;
2669 u16 hiaddr;
2670 int i;
2671 DBFENTER;
2672 /* Check that a port isn't active */
2673 for ( i = 0; i < HFA384x_PORTID_MAX; i++) {
2674 if ( hw->port_enabled[i] ) {
2675 WLAN_LOG_ERROR(
2676 "Can't download with a macport enabled.\n");
2677 return -EINVAL;
2681 /* Check that we're not already in a download state */
2682 if ( hw->dlstate != HFA384x_DLSTATE_DISABLED ) {
2683 WLAN_LOG_ERROR(
2684 "Download state not disabled.\n");
2685 return -EINVAL;
2688 WLAN_LOG_DEBUG(3,"ramdl_enable, exeaddr=0x%08x\n", exeaddr);
2690 /* Call the download(1,addr) function */
2691 lowaddr = HFA384x_ADDR_CMD_MKOFF(exeaddr);
2692 hiaddr = HFA384x_ADDR_CMD_MKPAGE(exeaddr);
2694 result = hfa384x_cmd_download(hw, HFA384x_PROGMODE_RAM,
2695 lowaddr, hiaddr, 0);
2697 if ( result == 0) {
2698 /* Set the download state */
2699 hw->dlstate = HFA384x_DLSTATE_RAMENABLED;
2700 } else {
2701 WLAN_LOG_DEBUG(1,
2702 "cmd_download(0x%04x, 0x%04x) failed, result=%d.\n",
2703 lowaddr,
2704 hiaddr,
2705 result);
2708 DBFEXIT;
2709 return result;
2713 /*----------------------------------------------------------------
2714 * hfa384x_drvr_ramdl_write
2716 * Performs a RAM download of a chunk of data. First checks to see
2717 * that we're in the RAM download state, then uses the [read|write]mem USB
2718 * commands to 1) copy the data, 2) readback and compare. The download
2719 * state is unaffected. When all data has been written using
2720 * this function, call drvr_ramdl_disable() to end the download state
2721 * and restart the MAC.
2723 * Arguments:
2724 * hw device structure
2725 * daddr Card address to write to. (host order)
2726 * buf Ptr to data to write.
2727 * len Length of data (host order).
2729 * Returns:
2730 * 0 success
2731 * >0 f/w reported error - f/w status code
2732 * <0 driver reported error
2734 * Side effects:
2736 * Call context:
2737 * process
2738 ----------------------------------------------------------------*/
2740 hfa384x_drvr_ramdl_write(hfa384x_t *hw, u32 daddr, void* buf, u32 len)
2742 int result = 0;
2743 int nwrites;
2744 u8 *data = buf;
2745 int i;
2746 u32 curraddr;
2747 u16 currpage;
2748 u16 curroffset;
2749 u16 currlen;
2750 DBFENTER;
2751 /* Check that we're in the ram download state */
2752 if ( hw->dlstate != HFA384x_DLSTATE_RAMENABLED ) {
2753 return -EINVAL;
2756 WLAN_LOG_INFO("Writing %d bytes to ram @0x%06x\n", len, daddr);
2758 /* How many dowmem calls? */
2759 nwrites = len / HFA384x_USB_RWMEM_MAXLEN;
2760 nwrites += len % HFA384x_USB_RWMEM_MAXLEN ? 1 : 0;
2762 /* Do blocking wmem's */
2763 for(i=0; i < nwrites; i++) {
2764 /* make address args */
2765 curraddr = daddr + (i * HFA384x_USB_RWMEM_MAXLEN);
2766 currpage = HFA384x_ADDR_CMD_MKPAGE(curraddr);
2767 curroffset = HFA384x_ADDR_CMD_MKOFF(curraddr);
2768 currlen = len - (i * HFA384x_USB_RWMEM_MAXLEN);
2769 if ( currlen > HFA384x_USB_RWMEM_MAXLEN) {
2770 currlen = HFA384x_USB_RWMEM_MAXLEN;
2773 /* Do blocking ctlx */
2774 result = hfa384x_dowmem_wait( hw,
2775 currpage,
2776 curroffset,
2777 data + (i*HFA384x_USB_RWMEM_MAXLEN),
2778 currlen );
2780 if (result) break;
2782 /* TODO: We really should have a readback. */
2785 DBFEXIT;
2786 return result;
2790 /*----------------------------------------------------------------
2791 * hfa384x_drvr_readpda
2793 * Performs the sequence to read the PDA space. Note there is no
2794 * drvr_writepda() function. Writing a PDA is
2795 * generally implemented by a calling component via calls to
2796 * cmd_download and writing to the flash download buffer via the
2797 * aux regs.
2799 * Arguments:
2800 * hw device structure
2801 * buf buffer to store PDA in
2802 * len buffer length
2804 * Returns:
2805 * 0 success
2806 * >0 f/w reported error - f/w status code
2807 * <0 driver reported error
2808 * -ETIMEOUT timout waiting for the cmd regs to become
2809 * available, or waiting for the control reg
2810 * to indicate the Aux port is enabled.
2811 * -ENODATA the buffer does NOT contain a valid PDA.
2812 * Either the card PDA is bad, or the auxdata
2813 * reads are giving us garbage.
2816 * Side effects:
2818 * Call context:
2819 * process or non-card interrupt.
2820 ----------------------------------------------------------------*/
2821 int hfa384x_drvr_readpda(hfa384x_t *hw, void *buf, unsigned int len)
2823 int result = 0;
2824 u16 *pda = buf;
2825 int pdaok = 0;
2826 int morepdrs = 1;
2827 int currpdr = 0; /* word offset of the current pdr */
2828 size_t i;
2829 u16 pdrlen; /* pdr length in bytes, host order */
2830 u16 pdrcode; /* pdr code, host order */
2831 u16 currpage;
2832 u16 curroffset;
2833 struct pdaloc {
2834 u32 cardaddr;
2835 u16 auxctl;
2836 } pdaloc[] =
2838 { HFA3842_PDA_BASE, 0},
2839 { HFA3841_PDA_BASE, 0},
2840 { HFA3841_PDA_BOGUS_BASE, 0}
2843 DBFENTER;
2845 /* Read the pda from each known address. */
2846 for ( i = 0; i < ARRAY_SIZE(pdaloc); i++) {
2847 /* Make address */
2848 currpage = HFA384x_ADDR_CMD_MKPAGE(pdaloc[i].cardaddr);
2849 curroffset = HFA384x_ADDR_CMD_MKOFF(pdaloc[i].cardaddr);
2851 result = hfa384x_dormem_wait(hw,
2852 currpage,
2853 curroffset,
2854 buf,
2855 len); /* units of bytes */
2857 if (result) {
2858 WLAN_LOG_WARNING(
2859 "Read from index %zd failed, continuing\n",
2860 i );
2861 continue;
2864 /* Test for garbage */
2865 pdaok = 1; /* initially assume good */
2866 morepdrs = 1;
2867 while ( pdaok && morepdrs ) {
2868 pdrlen = hfa384x2host_16(pda[currpdr]) * 2;
2869 pdrcode = hfa384x2host_16(pda[currpdr+1]);
2870 /* Test the record length */
2871 if ( pdrlen > HFA384x_PDR_LEN_MAX || pdrlen == 0) {
2872 WLAN_LOG_ERROR("pdrlen invalid=%d\n",
2873 pdrlen);
2874 pdaok = 0;
2875 break;
2877 /* Test the code */
2878 if ( !hfa384x_isgood_pdrcode(pdrcode) ) {
2879 WLAN_LOG_ERROR("pdrcode invalid=%d\n",
2880 pdrcode);
2881 pdaok = 0;
2882 break;
2884 /* Test for completion */
2885 if ( pdrcode == HFA384x_PDR_END_OF_PDA) {
2886 morepdrs = 0;
2889 /* Move to the next pdr (if necessary) */
2890 if ( morepdrs ) {
2891 /* note the access to pda[], need words here */
2892 currpdr += hfa384x2host_16(pda[currpdr]) + 1;
2895 if ( pdaok ) {
2896 WLAN_LOG_INFO(
2897 "PDA Read from 0x%08x in %s space.\n",
2898 pdaloc[i].cardaddr,
2899 pdaloc[i].auxctl == 0 ? "EXTDS" :
2900 pdaloc[i].auxctl == 1 ? "NV" :
2901 pdaloc[i].auxctl == 2 ? "PHY" :
2902 pdaloc[i].auxctl == 3 ? "ICSRAM" :
2903 "<bogus auxctl>");
2904 break;
2907 result = pdaok ? 0 : -ENODATA;
2909 if ( result ) {
2910 WLAN_LOG_DEBUG(3,"Failure: pda is not okay\n");
2913 DBFEXIT;
2914 return result;
2918 /*----------------------------------------------------------------
2919 * hfa384x_drvr_setconfig
2921 * Performs the sequence necessary to write a config/info item.
2923 * Arguments:
2924 * hw device structure
2925 * rid config/info record id (in host order)
2926 * buf host side record buffer
2927 * len buffer length (in bytes)
2929 * Returns:
2930 * 0 success
2931 * >0 f/w reported error - f/w status code
2932 * <0 driver reported error
2934 * Side effects:
2936 * Call context:
2937 * process
2938 ----------------------------------------------------------------*/
2939 int hfa384x_drvr_setconfig(hfa384x_t *hw, u16 rid, void *buf, u16 len)
2941 return hfa384x_dowrid_wait(hw, rid, buf, len);
2944 /*----------------------------------------------------------------
2945 * hfa384x_drvr_start
2947 * Issues the MAC initialize command, sets up some data structures,
2948 * and enables the interrupts. After this function completes, the
2949 * low-level stuff should be ready for any/all commands.
2951 * Arguments:
2952 * hw device structure
2953 * Returns:
2954 * 0 success
2955 * >0 f/w reported error - f/w status code
2956 * <0 driver reported error
2958 * Side effects:
2960 * Call context:
2961 * process
2962 ----------------------------------------------------------------*/
2964 int hfa384x_drvr_start(hfa384x_t *hw)
2966 int result, result1, result2;
2967 u16 status;
2968 DBFENTER;
2970 might_sleep();
2972 /* Clear endpoint stalls - but only do this if the endpoint
2973 * is showing a stall status. Some prism2 cards seem to behave
2974 * badly if a clear_halt is called when the endpoint is already
2975 * ok
2977 result = usb_get_status(hw->usb, USB_RECIP_ENDPOINT, hw->endp_in, &status);
2978 if (result < 0) {
2979 WLAN_LOG_ERROR(
2980 "Cannot get bulk in endpoint status.\n");
2981 goto done;
2983 if ((status == 1) && usb_clear_halt(hw->usb, hw->endp_in)) {
2984 WLAN_LOG_ERROR(
2985 "Failed to reset bulk in endpoint.\n");
2988 result = usb_get_status(hw->usb, USB_RECIP_ENDPOINT, hw->endp_out, &status);
2989 if (result < 0) {
2990 WLAN_LOG_ERROR(
2991 "Cannot get bulk out endpoint status.\n");
2992 goto done;
2994 if ((status == 1) && usb_clear_halt(hw->usb, hw->endp_out)) {
2995 WLAN_LOG_ERROR(
2996 "Failed to reset bulk out endpoint.\n");
2999 /* Synchronous unlink, in case we're trying to restart the driver */
3000 usb_kill_urb(&hw->rx_urb);
3002 /* Post the IN urb */
3003 result = submit_rx_urb(hw, GFP_KERNEL);
3004 if (result != 0) {
3005 WLAN_LOG_ERROR(
3006 "Fatal, failed to submit RX URB, result=%d\n",
3007 result);
3008 goto done;
3011 /* Call initialize twice, with a 1 second sleep in between.
3012 * This is a nasty work-around since many prism2 cards seem to
3013 * need time to settle after an init from cold. The second
3014 * call to initialize in theory is not necessary - but we call
3015 * it anyway as a double insurance policy:
3016 * 1) If the first init should fail, the second may well succeed
3017 * and the card can still be used
3018 * 2) It helps ensures all is well with the card after the first
3019 * init and settle time.
3021 result1 = hfa384x_cmd_initialize(hw);
3022 msleep(1000);
3023 result = result2 = hfa384x_cmd_initialize(hw);
3024 if (result1 != 0) {
3025 if (result2 != 0) {
3026 WLAN_LOG_ERROR(
3027 "cmd_initialize() failed on two attempts, results %d and %d\n",
3028 result1, result2);
3029 usb_kill_urb(&hw->rx_urb);
3030 goto done;
3031 } else {
3032 WLAN_LOG_DEBUG(0, "First cmd_initialize() failed (result %d),\n",
3033 result1);
3034 WLAN_LOG_DEBUG(0, "but second attempt succeeded. All should be ok\n");
3036 } else if (result2 != 0) {
3037 WLAN_LOG_WARNING(
3038 "First cmd_initialize() succeeded, but second attempt failed (result=%d)\n",
3039 result2);
3040 WLAN_LOG_WARNING("Most likely the card will be functional\n");
3041 goto done;
3044 hw->state = HFA384x_STATE_RUNNING;
3046 done:
3047 DBFEXIT;
3048 return result;
3052 /*----------------------------------------------------------------
3053 * hfa384x_drvr_stop
3055 * Shuts down the MAC to the point where it is safe to unload the
3056 * driver. Any subsystem that may be holding a data or function
3057 * ptr into the driver must be cleared/deinitialized.
3059 * Arguments:
3060 * hw device structure
3061 * Returns:
3062 * 0 success
3063 * >0 f/w reported error - f/w status code
3064 * <0 driver reported error
3066 * Side effects:
3068 * Call context:
3069 * process
3070 ----------------------------------------------------------------*/
3072 hfa384x_drvr_stop(hfa384x_t *hw)
3074 int result = 0;
3075 int i;
3076 DBFENTER;
3078 might_sleep();
3080 /* There's no need for spinlocks here. The USB "disconnect"
3081 * function sets this "removed" flag and then calls us.
3083 if ( !hw->wlandev->hwremoved ) {
3084 /* Call initialize to leave the MAC in its 'reset' state */
3085 hfa384x_cmd_initialize(hw);
3087 /* Cancel the rxurb */
3088 usb_kill_urb(&hw->rx_urb);
3091 hw->link_status = HFA384x_LINK_NOTCONNECTED;
3092 hw->state = HFA384x_STATE_INIT;
3094 del_timer_sync(&hw->commsqual_timer);
3096 /* Clear all the port status */
3097 for ( i = 0; i < HFA384x_NUMPORTS_MAX; i++) {
3098 hw->port_enabled[i] = 0;
3101 DBFEXIT;
3102 return result;
3105 /*----------------------------------------------------------------
3106 * hfa384x_drvr_txframe
3108 * Takes a frame from prism2sta and queues it for transmission.
3110 * Arguments:
3111 * hw device structure
3112 * skb packet buffer struct. Contains an 802.11
3113 * data frame.
3114 * p80211_hdr points to the 802.11 header for the packet.
3115 * Returns:
3116 * 0 Success and more buffs available
3117 * 1 Success but no more buffs
3118 * 2 Allocation failure
3119 * 4 Buffer full or queue busy
3121 * Side effects:
3123 * Call context:
3124 * interrupt
3125 ----------------------------------------------------------------*/
3126 int hfa384x_drvr_txframe(hfa384x_t *hw, struct sk_buff *skb, p80211_hdr_t *p80211_hdr, p80211_metawep_t *p80211_wep)
3129 int usbpktlen = sizeof(hfa384x_tx_frame_t);
3130 int result;
3131 int ret;
3132 char *ptr;
3134 DBFENTER;
3136 if (hw->tx_urb.status == -EINPROGRESS) {
3137 WLAN_LOG_WARNING("TX URB already in use\n");
3138 result = 3;
3139 goto exit;
3142 /* Build Tx frame structure */
3143 /* Set up the control field */
3144 memset(&hw->txbuff.txfrm.desc, 0, sizeof(hw->txbuff.txfrm.desc));
3146 /* Setup the usb type field */
3147 hw->txbuff.type = host2hfa384x_16(HFA384x_USB_TXFRM);
3149 /* Set up the sw_support field to identify this frame */
3150 hw->txbuff.txfrm.desc.sw_support = 0x0123;
3152 /* Tx complete and Tx exception disable per dleach. Might be causing
3153 * buf depletion
3155 //#define DOEXC SLP -- doboth breaks horribly under load, doexc less so.
3156 #if defined(DOBOTH)
3157 hw->txbuff.txfrm.desc.tx_control =
3158 HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
3159 HFA384x_TX_TXEX_SET(1) | HFA384x_TX_TXOK_SET(1);
3160 #elif defined(DOEXC)
3161 hw->txbuff.txfrm.desc.tx_control =
3162 HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
3163 HFA384x_TX_TXEX_SET(1) | HFA384x_TX_TXOK_SET(0);
3164 #else
3165 hw->txbuff.txfrm.desc.tx_control =
3166 HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
3167 HFA384x_TX_TXEX_SET(0) | HFA384x_TX_TXOK_SET(0);
3168 #endif
3169 hw->txbuff.txfrm.desc.tx_control =
3170 host2hfa384x_16(hw->txbuff.txfrm.desc.tx_control);
3172 /* copy the header over to the txdesc */
3173 memcpy(&(hw->txbuff.txfrm.desc.frame_control), p80211_hdr, sizeof(p80211_hdr_t));
3175 /* if we're using host WEP, increase size by IV+ICV */
3176 if (p80211_wep->data) {
3177 hw->txbuff.txfrm.desc.data_len = host2hfa384x_16(skb->len+8);
3178 // hw->txbuff.txfrm.desc.tx_control |= HFA384x_TX_NOENCRYPT_SET(1);
3179 usbpktlen+=8;
3180 } else {
3181 hw->txbuff.txfrm.desc.data_len = host2hfa384x_16(skb->len);
3184 usbpktlen += skb->len;
3186 /* copy over the WEP IV if we are using host WEP */
3187 ptr = hw->txbuff.txfrm.data;
3188 if (p80211_wep->data) {
3189 memcpy(ptr, p80211_wep->iv, sizeof(p80211_wep->iv));
3190 ptr+= sizeof(p80211_wep->iv);
3191 memcpy(ptr, p80211_wep->data, skb->len);
3192 } else {
3193 memcpy(ptr, skb->data, skb->len);
3195 /* copy over the packet data */
3196 ptr+= skb->len;
3198 /* copy over the WEP ICV if we are using host WEP */
3199 if (p80211_wep->data) {
3200 memcpy(ptr, p80211_wep->icv, sizeof(p80211_wep->icv));
3203 /* Send the USB packet */
3204 usb_fill_bulk_urb( &(hw->tx_urb), hw->usb,
3205 hw->endp_out,
3206 &(hw->txbuff), ROUNDUP64(usbpktlen),
3207 hfa384x_usbout_callback, hw->wlandev );
3208 hw->tx_urb.transfer_flags |= USB_QUEUE_BULK;
3210 result = 1;
3211 ret = submit_tx_urb(hw, &hw->tx_urb, GFP_ATOMIC);
3212 if ( ret != 0 ) {
3213 WLAN_LOG_ERROR(
3214 "submit_tx_urb() failed, error=%d\n", ret);
3215 result = 3;
3218 exit:
3219 DBFEXIT;
3220 return result;
3223 void hfa384x_tx_timeout(wlandevice_t *wlandev)
3225 hfa384x_t *hw = wlandev->priv;
3226 unsigned long flags;
3228 DBFENTER;
3230 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3232 if ( !hw->wlandev->hwremoved &&
3233 /* Note the bitwise OR, not the logical OR. */
3234 ( !test_and_set_bit(WORK_TX_HALT, &hw->usb_flags) |
3235 !test_and_set_bit(WORK_RX_HALT, &hw->usb_flags) ) )
3237 schedule_work(&hw->usb_work);
3240 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3242 DBFEXIT;
3245 /*----------------------------------------------------------------
3246 * hfa384x_usbctlx_reaper_task
3248 * Tasklet to delete dead CTLX objects
3250 * Arguments:
3251 * data ptr to a hfa384x_t
3253 * Returns:
3255 * Call context:
3256 * Interrupt
3257 ----------------------------------------------------------------*/
3258 static void hfa384x_usbctlx_reaper_task(unsigned long data)
3260 hfa384x_t *hw = (hfa384x_t*)data;
3261 struct list_head *entry;
3262 struct list_head *temp;
3263 unsigned long flags;
3265 DBFENTER;
3267 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3269 /* This list is guaranteed to be empty if someone
3270 * has unplugged the adapter.
3272 list_for_each_safe(entry, temp, &hw->ctlxq.reapable) {
3273 hfa384x_usbctlx_t *ctlx;
3275 ctlx = list_entry(entry, hfa384x_usbctlx_t, list);
3276 list_del(&ctlx->list);
3277 kfree(ctlx);
3280 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3282 DBFEXIT;
3285 /*----------------------------------------------------------------
3286 * hfa384x_usbctlx_completion_task
3288 * Tasklet to call completion handlers for returned CTLXs
3290 * Arguments:
3291 * data ptr to hfa384x_t
3293 * Returns:
3294 * Nothing
3296 * Call context:
3297 * Interrupt
3298 ----------------------------------------------------------------*/
3299 static void hfa384x_usbctlx_completion_task(unsigned long data)
3301 hfa384x_t *hw = (hfa384x_t*)data;
3302 struct list_head *entry;
3303 struct list_head *temp;
3304 unsigned long flags;
3306 int reap = 0;
3308 DBFENTER;
3310 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3312 /* This list is guaranteed to be empty if someone
3313 * has unplugged the adapter ...
3315 list_for_each_safe(entry, temp, &hw->ctlxq.completing) {
3316 hfa384x_usbctlx_t *ctlx;
3318 ctlx = list_entry(entry, hfa384x_usbctlx_t, list);
3320 /* Call the completion function that this
3321 * command was assigned, assuming it has one.
3323 if ( ctlx->cmdcb != NULL ) {
3324 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3325 ctlx->cmdcb(hw, ctlx);
3326 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3328 /* Make sure we don't try and complete
3329 * this CTLX more than once!
3331 ctlx->cmdcb = NULL;
3333 /* Did someone yank the adapter out
3334 * while our list was (briefly) unlocked?
3336 if ( hw->wlandev->hwremoved )
3338 reap = 0;
3339 break;
3344 * "Reapable" CTLXs are ones which don't have any
3345 * threads waiting for them to die. Hence they must
3346 * be delivered to The Reaper!
3348 if ( ctlx->reapable ) {
3349 /* Move the CTLX off the "completing" list (hopefully)
3350 * on to the "reapable" list where the reaper task
3351 * can find it. And "reapable" means that this CTLX
3352 * isn't sitting on a wait-queue somewhere.
3354 list_move_tail(&ctlx->list, &hw->ctlxq.reapable);
3355 reap = 1;
3358 complete(&ctlx->done);
3360 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3362 if (reap)
3363 tasklet_schedule(&hw->reaper_bh);
3365 DBFEXIT;
3368 /*----------------------------------------------------------------
3369 * unlocked_usbctlx_cancel_async
3371 * Mark the CTLX dead asynchronously, and ensure that the
3372 * next command on the queue is run afterwards.
3374 * Arguments:
3375 * hw ptr to the hfa384x_t structure
3376 * ctlx ptr to a CTLX structure
3378 * Returns:
3379 * 0 the CTLX's URB is inactive
3380 * -EINPROGRESS the URB is currently being unlinked
3382 * Call context:
3383 * Either process or interrupt, but presumably interrupt
3384 ----------------------------------------------------------------*/
3385 static int unlocked_usbctlx_cancel_async(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx)
3387 int ret;
3389 DBFENTER;
3392 * Try to delete the URB containing our request packet.
3393 * If we succeed, then its completion handler will be
3394 * called with a status of -ECONNRESET.
3396 hw->ctlx_urb.transfer_flags |= URB_ASYNC_UNLINK;
3397 ret = usb_unlink_urb(&hw->ctlx_urb);
3399 if (ret != -EINPROGRESS) {
3401 * The OUT URB had either already completed
3402 * or was still in the pending queue, so the
3403 * URB's completion function will not be called.
3404 * We will have to complete the CTLX ourselves.
3406 ctlx->state = CTLX_REQ_FAILED;
3407 unlocked_usbctlx_complete(hw, ctlx);
3408 ret = 0;
3411 DBFEXIT;
3413 return ret;
3416 /*----------------------------------------------------------------
3417 * unlocked_usbctlx_complete
3419 * A CTLX has completed. It may have been successful, it may not
3420 * have been. At this point, the CTLX should be quiescent. The URBs
3421 * aren't active and the timers should have been stopped.
3423 * The CTLX is migrated to the "completing" queue, and the completing
3424 * tasklet is scheduled.
3426 * Arguments:
3427 * hw ptr to a hfa384x_t structure
3428 * ctlx ptr to a ctlx structure
3430 * Returns:
3431 * nothing
3433 * Side effects:
3435 * Call context:
3436 * Either, assume interrupt
3437 ----------------------------------------------------------------*/
3438 static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx)
3440 DBFENTER;
3442 /* Timers have been stopped, and ctlx should be in
3443 * a terminal state. Retire it from the "active"
3444 * queue.
3446 list_move_tail(&ctlx->list, &hw->ctlxq.completing);
3447 tasklet_schedule(&hw->completion_bh);
3449 switch (ctlx->state) {
3450 case CTLX_COMPLETE:
3451 case CTLX_REQ_FAILED:
3452 /* This are the correct terminating states. */
3453 break;
3455 default:
3456 WLAN_LOG_ERROR("CTLX[%d] not in a terminating state(%s)\n",
3457 hfa384x2host_16(ctlx->outbuf.type),
3458 ctlxstr(ctlx->state));
3459 break;
3460 } /* switch */
3462 DBFEXIT;
3465 /*----------------------------------------------------------------
3466 * hfa384x_usbctlxq_run
3468 * Checks to see if the head item is running. If not, starts it.
3470 * Arguments:
3471 * hw ptr to hfa384x_t
3473 * Returns:
3474 * nothing
3476 * Side effects:
3478 * Call context:
3479 * any
3480 ----------------------------------------------------------------*/
3481 static void
3482 hfa384x_usbctlxq_run(hfa384x_t *hw)
3484 unsigned long flags;
3485 DBFENTER;
3487 /* acquire lock */
3488 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3490 /* Only one active CTLX at any one time, because there's no
3491 * other (reliable) way to match the response URB to the
3492 * correct CTLX.
3494 * Don't touch any of these CTLXs if the hardware
3495 * has been removed or the USB subsystem is stalled.
3497 if ( !list_empty(&hw->ctlxq.active) ||
3498 test_bit(WORK_TX_HALT, &hw->usb_flags) ||
3499 hw->wlandev->hwremoved )
3500 goto unlock;
3502 while ( !list_empty(&hw->ctlxq.pending) ) {
3503 hfa384x_usbctlx_t *head;
3504 int result;
3506 /* This is the first pending command */
3507 head = list_entry(hw->ctlxq.pending.next,
3508 hfa384x_usbctlx_t,
3509 list);
3511 /* We need to split this off to avoid a race condition */
3512 list_move_tail(&head->list, &hw->ctlxq.active);
3514 /* Fill the out packet */
3515 usb_fill_bulk_urb( &(hw->ctlx_urb), hw->usb,
3516 hw->endp_out,
3517 &(head->outbuf), ROUNDUP64(head->outbufsize),
3518 hfa384x_ctlxout_callback, hw);
3519 hw->ctlx_urb.transfer_flags |= USB_QUEUE_BULK;
3521 /* Now submit the URB and update the CTLX's state
3523 if ((result = SUBMIT_URB(&hw->ctlx_urb, GFP_ATOMIC)) == 0) {
3524 /* This CTLX is now running on the active queue */
3525 head->state = CTLX_REQ_SUBMITTED;
3527 /* Start the OUT wait timer */
3528 hw->req_timer_done = 0;
3529 hw->reqtimer.expires = jiffies + HZ;
3530 add_timer(&hw->reqtimer);
3532 /* Start the IN wait timer */
3533 hw->resp_timer_done = 0;
3534 hw->resptimer.expires = jiffies + 2*HZ;
3535 add_timer(&hw->resptimer);
3537 break;
3540 if (result == -EPIPE) {
3541 /* The OUT pipe needs resetting, so put
3542 * this CTLX back in the "pending" queue
3543 * and schedule a reset ...
3545 WLAN_LOG_WARNING("%s tx pipe stalled: requesting reset\n",
3546 hw->wlandev->netdev->name);
3547 list_move(&head->list, &hw->ctlxq.pending);
3548 set_bit(WORK_TX_HALT, &hw->usb_flags);
3549 schedule_work(&hw->usb_work);
3550 break;
3553 if (result == -ESHUTDOWN) {
3554 WLAN_LOG_WARNING("%s urb shutdown!\n",
3555 hw->wlandev->netdev->name);
3556 break;
3559 WLAN_LOG_ERROR("Failed to submit CTLX[%d]: error=%d\n",
3560 hfa384x2host_16(head->outbuf.type), result);
3561 unlocked_usbctlx_complete(hw, head);
3562 } /* while */
3564 unlock:
3565 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3567 DBFEXIT;
3571 /*----------------------------------------------------------------
3572 * hfa384x_usbin_callback
3574 * Callback for URBs on the BULKIN endpoint.
3576 * Arguments:
3577 * urb ptr to the completed urb
3579 * Returns:
3580 * nothing
3582 * Side effects:
3584 * Call context:
3585 * interrupt
3586 ----------------------------------------------------------------*/
3587 static void hfa384x_usbin_callback(struct urb *urb)
3589 wlandevice_t *wlandev = urb->context;
3590 hfa384x_t *hw;
3591 hfa384x_usbin_t *usbin = (hfa384x_usbin_t *) urb->transfer_buffer;
3592 struct sk_buff *skb = NULL;
3593 int result;
3594 int urb_status;
3595 u16 type;
3597 enum USBIN_ACTION {
3598 HANDLE,
3599 RESUBMIT,
3600 ABORT
3601 } action;
3603 DBFENTER;
3605 if ( !wlandev ||
3606 !wlandev->netdev ||
3607 wlandev->hwremoved )
3608 goto exit;
3610 hw = wlandev->priv;
3611 if (!hw)
3612 goto exit;
3614 skb = hw->rx_urb_skb;
3615 if (!skb || (skb->data != urb->transfer_buffer)) {
3616 BUG();
3618 hw->rx_urb_skb = NULL;
3620 /* Check for error conditions within the URB */
3621 switch (urb->status) {
3622 case 0:
3623 action = HANDLE;
3625 /* Check for short packet */
3626 if ( urb->actual_length == 0 ) {
3627 ++(wlandev->linux_stats.rx_errors);
3628 ++(wlandev->linux_stats.rx_length_errors);
3629 action = RESUBMIT;
3631 break;
3633 case -EPIPE:
3634 WLAN_LOG_WARNING("%s rx pipe stalled: requesting reset\n",
3635 wlandev->netdev->name);
3636 if ( !test_and_set_bit(WORK_RX_HALT, &hw->usb_flags) )
3637 schedule_work(&hw->usb_work);
3638 ++(wlandev->linux_stats.rx_errors);
3639 action = ABORT;
3640 break;
3642 case -EILSEQ:
3643 case -ETIMEDOUT:
3644 case -EPROTO:
3645 if ( !test_and_set_bit(THROTTLE_RX, &hw->usb_flags) &&
3646 !timer_pending(&hw->throttle) ) {
3647 mod_timer(&hw->throttle, jiffies + THROTTLE_JIFFIES);
3649 ++(wlandev->linux_stats.rx_errors);
3650 action = ABORT;
3651 break;
3653 case -EOVERFLOW:
3654 ++(wlandev->linux_stats.rx_over_errors);
3655 action = RESUBMIT;
3656 break;
3658 case -ENODEV:
3659 case -ESHUTDOWN:
3660 WLAN_LOG_DEBUG(3,"status=%d, device removed.\n", urb->status);
3661 action = ABORT;
3662 break;
3664 case -ENOENT:
3665 case -ECONNRESET:
3666 WLAN_LOG_DEBUG(3,"status=%d, urb explicitly unlinked.\n", urb->status);
3667 action = ABORT;
3668 break;
3670 default:
3671 WLAN_LOG_DEBUG(3,"urb status=%d, transfer flags=0x%x\n",
3672 urb->status, urb->transfer_flags);
3673 ++(wlandev->linux_stats.rx_errors);
3674 action = RESUBMIT;
3675 break;
3678 urb_status = urb->status;
3680 if (action != ABORT) {
3681 /* Repost the RX URB */
3682 result = submit_rx_urb(hw, GFP_ATOMIC);
3684 if (result != 0) {
3685 WLAN_LOG_ERROR(
3686 "Fatal, failed to resubmit rx_urb. error=%d\n",
3687 result);
3691 /* Handle any USB-IN packet */
3692 /* Note: the check of the sw_support field, the type field doesn't
3693 * have bit 12 set like the docs suggest.
3695 type = hfa384x2host_16(usbin->type);
3696 if (HFA384x_USB_ISRXFRM(type)) {
3697 if (action == HANDLE) {
3698 if (usbin->txfrm.desc.sw_support == 0x0123) {
3699 hfa384x_usbin_txcompl(wlandev, usbin);
3700 } else {
3701 skb_put(skb, sizeof(*usbin));
3702 hfa384x_usbin_rx(wlandev, skb);
3703 skb = NULL;
3706 goto exit;
3708 if (HFA384x_USB_ISTXFRM(type)) {
3709 if (action == HANDLE)
3710 hfa384x_usbin_txcompl(wlandev, usbin);
3711 goto exit;
3713 switch (type) {
3714 case HFA384x_USB_INFOFRM:
3715 if (action == ABORT)
3716 goto exit;
3717 if (action == HANDLE)
3718 hfa384x_usbin_info(wlandev, usbin);
3719 break;
3721 case HFA384x_USB_CMDRESP:
3722 case HFA384x_USB_WRIDRESP:
3723 case HFA384x_USB_RRIDRESP:
3724 case HFA384x_USB_WMEMRESP:
3725 case HFA384x_USB_RMEMRESP:
3726 /* ALWAYS, ALWAYS, ALWAYS handle this CTLX!!!! */
3727 hfa384x_usbin_ctlx(hw, usbin, urb_status);
3728 break;
3730 case HFA384x_USB_BUFAVAIL:
3731 WLAN_LOG_DEBUG(3,"Received BUFAVAIL packet, frmlen=%d\n",
3732 usbin->bufavail.frmlen);
3733 break;
3735 case HFA384x_USB_ERROR:
3736 WLAN_LOG_DEBUG(3,"Received USB_ERROR packet, errortype=%d\n",
3737 usbin->usberror.errortype);
3738 break;
3740 default:
3741 WLAN_LOG_DEBUG(3,"Unrecognized USBIN packet, type=%x, status=%d\n",
3742 usbin->type, urb_status);
3743 break;
3744 } /* switch */
3746 exit:
3748 if (skb)
3749 dev_kfree_skb(skb);
3751 DBFEXIT;
3755 /*----------------------------------------------------------------
3756 * hfa384x_usbin_ctlx
3758 * We've received a URB containing a Prism2 "response" message.
3759 * This message needs to be matched up with a CTLX on the active
3760 * queue and our state updated accordingly.
3762 * Arguments:
3763 * hw ptr to hfa384x_t
3764 * usbin ptr to USB IN packet
3765 * urb_status status of this Bulk-In URB
3767 * Returns:
3768 * nothing
3770 * Side effects:
3772 * Call context:
3773 * interrupt
3774 ----------------------------------------------------------------*/
3775 static void hfa384x_usbin_ctlx(hfa384x_t *hw, hfa384x_usbin_t *usbin,
3776 int urb_status)
3778 hfa384x_usbctlx_t *ctlx;
3779 int run_queue = 0;
3780 unsigned long flags;
3782 DBFENTER;
3784 retry:
3785 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3787 /* There can be only one CTLX on the active queue
3788 * at any one time, and this is the CTLX that the
3789 * timers are waiting for.
3791 if ( list_empty(&hw->ctlxq.active) ) {
3792 goto unlock;
3795 /* Remove the "response timeout". It's possible that
3796 * we are already too late, and that the timeout is
3797 * already running. And that's just too bad for us,
3798 * because we could lose our CTLX from the active
3799 * queue here ...
3801 if (del_timer(&hw->resptimer) == 0) {
3802 if (hw->resp_timer_done == 0) {
3803 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3804 goto retry;
3807 else {
3808 hw->resp_timer_done = 1;
3811 ctlx = get_active_ctlx(hw);
3813 if (urb_status != 0) {
3815 * Bad CTLX, so get rid of it. But we only
3816 * remove it from the active queue if we're no
3817 * longer expecting the OUT URB to complete.
3819 if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0)
3820 run_queue = 1;
3821 } else {
3822 const u16 intype = (usbin->type&~host2hfa384x_16(0x8000));
3825 * Check that our message is what we're expecting ...
3827 if (ctlx->outbuf.type != intype) {
3828 WLAN_LOG_WARNING("Expected IN[%d], received IN[%d] - ignored.\n",
3829 hfa384x2host_16(ctlx->outbuf.type),
3830 hfa384x2host_16(intype));
3831 goto unlock;
3834 /* This URB has succeeded, so grab the data ... */
3835 memcpy(&ctlx->inbuf, usbin, sizeof(ctlx->inbuf));
3837 switch (ctlx->state) {
3838 case CTLX_REQ_SUBMITTED:
3840 * We have received our response URB before
3841 * our request has been acknowledged. Odd,
3842 * but our OUT URB is still alive...
3844 WLAN_LOG_DEBUG(0, "Causality violation: please reboot Universe, or email linux-wlan-devel@lists.linux-wlan.com\n");
3845 ctlx->state = CTLX_RESP_COMPLETE;
3846 break;
3848 case CTLX_REQ_COMPLETE:
3850 * This is the usual path: our request
3851 * has already been acknowledged, and
3852 * now we have received the reply too.
3854 ctlx->state = CTLX_COMPLETE;
3855 unlocked_usbctlx_complete(hw, ctlx);
3856 run_queue = 1;
3857 break;
3859 default:
3861 * Throw this CTLX away ...
3863 WLAN_LOG_ERROR("Matched IN URB, CTLX[%d] in invalid state(%s)."
3864 " Discarded.\n",
3865 hfa384x2host_16(ctlx->outbuf.type),
3866 ctlxstr(ctlx->state));
3867 if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0)
3868 run_queue = 1;
3869 break;
3870 } /* switch */
3873 unlock:
3874 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3876 if (run_queue)
3877 hfa384x_usbctlxq_run(hw);
3879 DBFEXIT;
3883 /*----------------------------------------------------------------
3884 * hfa384x_usbin_txcompl
3886 * At this point we have the results of a previous transmit.
3888 * Arguments:
3889 * wlandev wlan device
3890 * usbin ptr to the usb transfer buffer
3892 * Returns:
3893 * nothing
3895 * Side effects:
3897 * Call context:
3898 * interrupt
3899 ----------------------------------------------------------------*/
3900 static void hfa384x_usbin_txcompl(wlandevice_t *wlandev, hfa384x_usbin_t *usbin)
3902 u16 status;
3903 DBFENTER;
3905 status = hfa384x2host_16(usbin->type); /* yeah I know it says type...*/
3907 /* Was there an error? */
3908 if (HFA384x_TXSTATUS_ISERROR(status)) {
3909 prism2sta_ev_txexc(wlandev, status);
3910 } else {
3911 prism2sta_ev_tx(wlandev, status);
3913 // prism2sta_ev_alloc(wlandev);
3915 DBFEXIT;
3919 /*----------------------------------------------------------------
3920 * hfa384x_usbin_rx
3922 * At this point we have a successful received a rx frame packet.
3924 * Arguments:
3925 * wlandev wlan device
3926 * usbin ptr to the usb transfer buffer
3928 * Returns:
3929 * nothing
3931 * Side effects:
3933 * Call context:
3934 * interrupt
3935 ----------------------------------------------------------------*/
3936 static void hfa384x_usbin_rx(wlandevice_t *wlandev, struct sk_buff *skb)
3938 hfa384x_usbin_t *usbin = (hfa384x_usbin_t *) skb->data;
3939 hfa384x_t *hw = wlandev->priv;
3940 int hdrlen;
3941 p80211_rxmeta_t *rxmeta;
3942 u16 data_len;
3943 u16 fc;
3945 DBFENTER;
3947 /* Byte order convert once up front. */
3948 usbin->rxfrm.desc.status =
3949 hfa384x2host_16(usbin->rxfrm.desc.status);
3950 usbin->rxfrm.desc.time =
3951 hfa384x2host_32(usbin->rxfrm.desc.time);
3953 /* Now handle frame based on port# */
3954 switch( HFA384x_RXSTATUS_MACPORT_GET(usbin->rxfrm.desc.status) )
3956 case 0:
3957 fc = ieee2host16(usbin->rxfrm.desc.frame_control);
3959 /* If exclude and we receive an unencrypted, drop it */
3960 if ( (wlandev->hostwep & HOSTWEP_EXCLUDEUNENCRYPTED) &&
3961 !WLAN_GET_FC_ISWEP(fc)){
3962 goto done;
3965 data_len = hfa384x2host_16(usbin->rxfrm.desc.data_len);
3967 /* How much header data do we have? */
3968 hdrlen = p80211_headerlen(fc);
3970 /* Pull off the descriptor */
3971 skb_pull(skb, sizeof(hfa384x_rx_frame_t));
3973 /* Now shunt the header block up against the data block
3974 * with an "overlapping" copy
3976 memmove(skb_push(skb, hdrlen),
3977 &usbin->rxfrm.desc.frame_control,
3978 hdrlen);
3980 skb->dev = wlandev->netdev;
3981 skb->dev->last_rx = jiffies;
3983 /* And set the frame length properly */
3984 skb_trim(skb, data_len + hdrlen);
3986 /* The prism2 series does not return the CRC */
3987 memset(skb_put(skb, WLAN_CRC_LEN), 0xff, WLAN_CRC_LEN);
3989 skb_reset_mac_header(skb);
3991 /* Attach the rxmeta, set some stuff */
3992 p80211skb_rxmeta_attach(wlandev, skb);
3993 rxmeta = P80211SKB_RXMETA(skb);
3994 rxmeta->mactime = usbin->rxfrm.desc.time;
3995 rxmeta->rxrate = usbin->rxfrm.desc.rate;
3996 rxmeta->signal = usbin->rxfrm.desc.signal - hw->dbmadjust;
3997 rxmeta->noise = usbin->rxfrm.desc.silence - hw->dbmadjust;
3999 prism2sta_ev_rx(wlandev, skb);
4001 break;
4003 case 7:
4004 if ( ! HFA384x_RXSTATUS_ISFCSERR(usbin->rxfrm.desc.status) ) {
4005 /* Copy to wlansnif skb */
4006 hfa384x_int_rxmonitor( wlandev, &usbin->rxfrm);
4007 dev_kfree_skb(skb);
4008 } else {
4009 WLAN_LOG_DEBUG(3,"Received monitor frame: FCSerr set\n");
4011 break;
4013 default:
4014 WLAN_LOG_WARNING("Received frame on unsupported port=%d\n",
4015 HFA384x_RXSTATUS_MACPORT_GET(usbin->rxfrm.desc.status) );
4016 goto done;
4017 break;
4020 done:
4021 DBFEXIT;
4022 return;
4025 /*----------------------------------------------------------------
4026 * hfa384x_int_rxmonitor
4028 * Helper function for int_rx. Handles monitor frames.
4029 * Note that this function allocates space for the FCS and sets it
4030 * to 0xffffffff. The hfa384x doesn't give us the FCS value but the
4031 * higher layers expect it. 0xffffffff is used as a flag to indicate
4032 * the FCS is bogus.
4034 * Arguments:
4035 * wlandev wlan device structure
4036 * rxfrm rx descriptor read from card in int_rx
4038 * Returns:
4039 * nothing
4041 * Side effects:
4042 * Allocates an skb and passes it up via the PF_PACKET interface.
4043 * Call context:
4044 * interrupt
4045 ----------------------------------------------------------------*/
4046 static void hfa384x_int_rxmonitor( wlandevice_t *wlandev, hfa384x_usb_rxfrm_t *rxfrm)
4048 hfa384x_rx_frame_t *rxdesc = &(rxfrm->desc);
4049 unsigned int hdrlen = 0;
4050 unsigned int datalen = 0;
4051 unsigned int skblen = 0;
4052 u8 *datap;
4053 u16 fc;
4054 struct sk_buff *skb;
4055 hfa384x_t *hw = wlandev->priv;
4058 DBFENTER;
4059 /* Don't forget the status, time, and data_len fields are in host order */
4060 /* Figure out how big the frame is */
4061 fc = ieee2host16(rxdesc->frame_control);
4062 hdrlen = p80211_headerlen(fc);
4063 datalen = hfa384x2host_16(rxdesc->data_len);
4065 /* Allocate an ind message+framesize skb */
4066 skblen = sizeof(p80211_caphdr_t) +
4067 hdrlen + datalen + WLAN_CRC_LEN;
4069 /* sanity check the length */
4070 if ( skblen >
4071 (sizeof(p80211_caphdr_t) +
4072 WLAN_HDR_A4_LEN + WLAN_DATA_MAXLEN + WLAN_CRC_LEN) ) {
4073 WLAN_LOG_DEBUG(1, "overlen frm: len=%zd\n",
4074 skblen - sizeof(p80211_caphdr_t));
4077 if ( (skb = dev_alloc_skb(skblen)) == NULL ) {
4078 WLAN_LOG_ERROR("alloc_skb failed trying to allocate %d bytes\n", skblen);
4079 return;
4082 /* only prepend the prism header if in the right mode */
4083 if ((wlandev->netdev->type == ARPHRD_IEEE80211_PRISM) &&
4084 (hw->sniffhdr != 0)) {
4085 p80211_caphdr_t *caphdr;
4086 /* The NEW header format! */
4087 datap = skb_put(skb, sizeof(p80211_caphdr_t));
4088 caphdr = (p80211_caphdr_t*) datap;
4090 caphdr->version = htonl(P80211CAPTURE_VERSION);
4091 caphdr->length = htonl(sizeof(p80211_caphdr_t));
4092 caphdr->mactime = __cpu_to_be64(rxdesc->time) * 1000;
4093 caphdr->hosttime = __cpu_to_be64(jiffies);
4094 caphdr->phytype = htonl(4); /* dss_dot11_b */
4095 caphdr->channel = htonl(hw->sniff_channel);
4096 caphdr->datarate = htonl(rxdesc->rate);
4097 caphdr->antenna = htonl(0); /* unknown */
4098 caphdr->priority = htonl(0); /* unknown */
4099 caphdr->ssi_type = htonl(3); /* rssi_raw */
4100 caphdr->ssi_signal = htonl(rxdesc->signal);
4101 caphdr->ssi_noise = htonl(rxdesc->silence);
4102 caphdr->preamble = htonl(0); /* unknown */
4103 caphdr->encoding = htonl(1); /* cck */
4106 /* Copy the 802.11 header to the skb (ctl frames may be less than a full header) */
4107 datap = skb_put(skb, hdrlen);
4108 memcpy( datap, &(rxdesc->frame_control), hdrlen);
4110 /* If any, copy the data from the card to the skb */
4111 if ( datalen > 0 )
4113 datap = skb_put(skb, datalen);
4114 memcpy(datap, rxfrm->data, datalen);
4116 /* check for unencrypted stuff if WEP bit set. */
4117 if (*(datap - hdrlen + 1) & 0x40) // wep set
4118 if ((*(datap) == 0xaa) && (*(datap+1) == 0xaa))
4119 *(datap - hdrlen + 1) &= 0xbf; // clear wep; it's the 802.2 header!
4122 if (hw->sniff_fcs) {
4123 /* Set the FCS */
4124 datap = skb_put(skb, WLAN_CRC_LEN);
4125 memset( datap, 0xff, WLAN_CRC_LEN);
4128 /* pass it back up */
4129 prism2sta_ev_rx(wlandev, skb);
4131 DBFEXIT;
4132 return;
4137 /*----------------------------------------------------------------
4138 * hfa384x_usbin_info
4140 * At this point we have a successful received a Prism2 info frame.
4142 * Arguments:
4143 * wlandev wlan device
4144 * usbin ptr to the usb transfer buffer
4146 * Returns:
4147 * nothing
4149 * Side effects:
4151 * Call context:
4152 * interrupt
4153 ----------------------------------------------------------------*/
4154 static void hfa384x_usbin_info(wlandevice_t *wlandev, hfa384x_usbin_t *usbin)
4156 DBFENTER;
4158 usbin->infofrm.info.framelen = hfa384x2host_16(usbin->infofrm.info.framelen);
4159 prism2sta_ev_info(wlandev, &usbin->infofrm.info);
4161 DBFEXIT;
4166 /*----------------------------------------------------------------
4167 * hfa384x_usbout_callback
4169 * Callback for URBs on the BULKOUT endpoint.
4171 * Arguments:
4172 * urb ptr to the completed urb
4174 * Returns:
4175 * nothing
4177 * Side effects:
4179 * Call context:
4180 * interrupt
4181 ----------------------------------------------------------------*/
4182 static void hfa384x_usbout_callback(struct urb *urb)
4184 wlandevice_t *wlandev = urb->context;
4185 hfa384x_usbout_t *usbout = urb->transfer_buffer;
4186 DBFENTER;
4188 #ifdef DEBUG_USB
4189 dbprint_urb(urb);
4190 #endif
4192 if ( wlandev &&
4193 wlandev->netdev ) {
4195 switch(urb->status) {
4196 case 0:
4197 hfa384x_usbout_tx(wlandev, usbout);
4198 break;
4200 case -EPIPE:
4202 hfa384x_t *hw = wlandev->priv;
4203 WLAN_LOG_WARNING("%s tx pipe stalled: requesting reset\n",
4204 wlandev->netdev->name);
4205 if ( !test_and_set_bit(WORK_TX_HALT, &hw->usb_flags) )
4206 schedule_work(&hw->usb_work);
4207 ++(wlandev->linux_stats.tx_errors);
4208 break;
4211 case -EPROTO:
4212 case -ETIMEDOUT:
4213 case -EILSEQ:
4215 hfa384x_t *hw = wlandev->priv;
4217 if ( !test_and_set_bit(THROTTLE_TX, &hw->usb_flags)
4218 && !timer_pending(&hw->throttle) ) {
4219 mod_timer(&hw->throttle,
4220 jiffies + THROTTLE_JIFFIES);
4222 ++(wlandev->linux_stats.tx_errors);
4223 netif_stop_queue(wlandev->netdev);
4224 break;
4227 case -ENOENT:
4228 case -ESHUTDOWN:
4229 /* Ignorable errors */
4230 break;
4232 default:
4233 WLAN_LOG_INFO("unknown urb->status=%d\n", urb->status);
4234 ++(wlandev->linux_stats.tx_errors);
4235 break;
4236 } /* switch */
4239 DBFEXIT;
4243 /*----------------------------------------------------------------
4244 * hfa384x_ctlxout_callback
4246 * Callback for control data on the BULKOUT endpoint.
4248 * Arguments:
4249 * urb ptr to the completed urb
4251 * Returns:
4252 * nothing
4254 * Side effects:
4256 * Call context:
4257 * interrupt
4258 ----------------------------------------------------------------*/
4259 static void hfa384x_ctlxout_callback(struct urb *urb)
4261 hfa384x_t *hw = urb->context;
4262 int delete_resptimer = 0;
4263 int timer_ok = 1;
4264 int run_queue = 0;
4265 hfa384x_usbctlx_t *ctlx;
4266 unsigned long flags;
4268 DBFENTER;
4270 WLAN_LOG_DEBUG(3,"urb->status=%d\n", urb->status);
4271 #ifdef DEBUG_USB
4272 dbprint_urb(urb);
4273 #endif
4274 if ( (urb->status == -ESHUTDOWN) ||
4275 (urb->status == -ENODEV) ||
4276 (hw == NULL) )
4277 goto done;
4279 retry:
4280 spin_lock_irqsave(&hw->ctlxq.lock, flags);
4283 * Only one CTLX at a time on the "active" list, and
4284 * none at all if we are unplugged. However, we can
4285 * rely on the disconnect function to clean everything
4286 * up if someone unplugged the adapter.
4288 if ( list_empty(&hw->ctlxq.active) ) {
4289 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
4290 goto done;
4294 * Having something on the "active" queue means
4295 * that we have timers to worry about ...
4297 if (del_timer(&hw->reqtimer) == 0) {
4298 if (hw->req_timer_done == 0) {
4300 * This timer was actually running while we
4301 * were trying to delete it. Let it terminate
4302 * gracefully instead.
4304 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
4305 goto retry;
4308 else {
4309 hw->req_timer_done = 1;
4312 ctlx = get_active_ctlx(hw);
4314 if ( urb->status == 0 ) {
4315 /* Request portion of a CTLX is successful */
4316 switch ( ctlx->state ) {
4317 case CTLX_REQ_SUBMITTED:
4318 /* This OUT-ACK received before IN */
4319 ctlx->state = CTLX_REQ_COMPLETE;
4320 break;
4322 case CTLX_RESP_COMPLETE:
4323 /* IN already received before this OUT-ACK,
4324 * so this command must now be complete.
4326 ctlx->state = CTLX_COMPLETE;
4327 unlocked_usbctlx_complete(hw, ctlx);
4328 run_queue = 1;
4329 break;
4331 default:
4332 /* This is NOT a valid CTLX "success" state! */
4333 WLAN_LOG_ERROR(
4334 "Illegal CTLX[%d] success state(%s, %d) in OUT URB\n",
4335 hfa384x2host_16(ctlx->outbuf.type),
4336 ctlxstr(ctlx->state), urb->status);
4337 break;
4338 } /* switch */
4339 } else {
4340 /* If the pipe has stalled then we need to reset it */
4341 if ( (urb->status == -EPIPE) &&
4342 !test_and_set_bit(WORK_TX_HALT, &hw->usb_flags) ) {
4343 WLAN_LOG_WARNING("%s tx pipe stalled: requesting reset\n",
4344 hw->wlandev->netdev->name);
4345 schedule_work(&hw->usb_work);
4348 /* If someone cancels the OUT URB then its status
4349 * should be either -ECONNRESET or -ENOENT.
4351 ctlx->state = CTLX_REQ_FAILED;
4352 unlocked_usbctlx_complete(hw, ctlx);
4353 delete_resptimer = 1;
4354 run_queue = 1;
4357 delresp:
4358 if (delete_resptimer) {
4359 if ((timer_ok = del_timer(&hw->resptimer)) != 0) {
4360 hw->resp_timer_done = 1;
4364 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
4366 if ( !timer_ok && (hw->resp_timer_done == 0) ) {
4367 spin_lock_irqsave(&hw->ctlxq.lock, flags);
4368 goto delresp;
4371 if (run_queue)
4372 hfa384x_usbctlxq_run(hw);
4374 done:
4375 DBFEXIT;
4379 /*----------------------------------------------------------------
4380 * hfa384x_usbctlx_reqtimerfn
4382 * Timer response function for CTLX request timeouts. If this
4383 * function is called, it means that the callback for the OUT
4384 * URB containing a Prism2.x XXX_Request was never called.
4386 * Arguments:
4387 * data a ptr to the hfa384x_t
4389 * Returns:
4390 * nothing
4392 * Side effects:
4394 * Call context:
4395 * interrupt
4396 ----------------------------------------------------------------*/
4397 static void
4398 hfa384x_usbctlx_reqtimerfn(unsigned long data)
4400 hfa384x_t *hw = (hfa384x_t*)data;
4401 unsigned long flags;
4402 DBFENTER;
4404 spin_lock_irqsave(&hw->ctlxq.lock, flags);
4406 hw->req_timer_done = 1;
4408 /* Removing the hardware automatically empties
4409 * the active list ...
4411 if ( !list_empty(&hw->ctlxq.active) )
4414 * We must ensure that our URB is removed from
4415 * the system, if it hasn't already expired.
4417 hw->ctlx_urb.transfer_flags |= URB_ASYNC_UNLINK;
4418 if (usb_unlink_urb(&hw->ctlx_urb) == -EINPROGRESS)
4420 hfa384x_usbctlx_t *ctlx = get_active_ctlx(hw);
4422 ctlx->state = CTLX_REQ_FAILED;
4424 /* This URB was active, but has now been
4425 * cancelled. It will now have a status of
4426 * -ECONNRESET in the callback function.
4428 * We are cancelling this CTLX, so we're
4429 * not going to need to wait for a response.
4430 * The URB's callback function will check
4431 * that this timer is truly dead.
4433 if (del_timer(&hw->resptimer) != 0)
4434 hw->resp_timer_done = 1;
4438 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
4440 DBFEXIT;
4444 /*----------------------------------------------------------------
4445 * hfa384x_usbctlx_resptimerfn
4447 * Timer response function for CTLX response timeouts. If this
4448 * function is called, it means that the callback for the IN
4449 * URB containing a Prism2.x XXX_Response was never called.
4451 * Arguments:
4452 * data a ptr to the hfa384x_t
4454 * Returns:
4455 * nothing
4457 * Side effects:
4459 * Call context:
4460 * interrupt
4461 ----------------------------------------------------------------*/
4462 static void
4463 hfa384x_usbctlx_resptimerfn(unsigned long data)
4465 hfa384x_t *hw = (hfa384x_t*)data;
4466 unsigned long flags;
4468 DBFENTER;
4470 spin_lock_irqsave(&hw->ctlxq.lock, flags);
4472 hw->resp_timer_done = 1;
4474 /* The active list will be empty if the
4475 * adapter has been unplugged ...
4477 if ( !list_empty(&hw->ctlxq.active) )
4479 hfa384x_usbctlx_t *ctlx = get_active_ctlx(hw);
4481 if ( unlocked_usbctlx_cancel_async(hw, ctlx) == 0 )
4483 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
4484 hfa384x_usbctlxq_run(hw);
4485 goto done;
4489 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
4491 done:
4492 DBFEXIT;
4495 /*----------------------------------------------------------------
4496 * hfa384x_usb_throttlefn
4499 * Arguments:
4500 * data ptr to hw
4502 * Returns:
4503 * Nothing
4505 * Side effects:
4507 * Call context:
4508 * Interrupt
4509 ----------------------------------------------------------------*/
4510 static void
4511 hfa384x_usb_throttlefn(unsigned long data)
4513 hfa384x_t *hw = (hfa384x_t*)data;
4514 unsigned long flags;
4516 DBFENTER;
4518 spin_lock_irqsave(&hw->ctlxq.lock, flags);
4521 * We need to check BOTH the RX and the TX throttle controls,
4522 * so we use the bitwise OR instead of the logical OR.
4524 WLAN_LOG_DEBUG(3, "flags=0x%lx\n", hw->usb_flags);
4525 if ( !hw->wlandev->hwremoved &&
4527 (test_and_clear_bit(THROTTLE_RX, &hw->usb_flags) &&
4528 !test_and_set_bit(WORK_RX_RESUME, &hw->usb_flags))
4530 (test_and_clear_bit(THROTTLE_TX, &hw->usb_flags) &&
4531 !test_and_set_bit(WORK_TX_RESUME, &hw->usb_flags))
4534 schedule_work(&hw->usb_work);
4537 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
4539 DBFEXIT;
4543 /*----------------------------------------------------------------
4544 * hfa384x_usbctlx_submit
4546 * Called from the doxxx functions to submit a CTLX to the queue
4548 * Arguments:
4549 * hw ptr to the hw struct
4550 * ctlx ctlx structure to enqueue
4552 * Returns:
4553 * -ENODEV if the adapter is unplugged
4556 * Side effects:
4558 * Call context:
4559 * process or interrupt
4560 ----------------------------------------------------------------*/
4561 static int
4562 hfa384x_usbctlx_submit(
4563 hfa384x_t *hw,
4564 hfa384x_usbctlx_t *ctlx)
4566 unsigned long flags;
4567 int ret;
4569 DBFENTER;
4571 spin_lock_irqsave(&hw->ctlxq.lock, flags);
4573 if (hw->wlandev->hwremoved) {
4574 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
4575 ret = -ENODEV;
4576 } else {
4577 ctlx->state = CTLX_PENDING;
4578 list_add_tail(&ctlx->list, &hw->ctlxq.pending);
4580 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
4581 hfa384x_usbctlxq_run(hw);
4582 ret = 0;
4585 DBFEXIT;
4586 return ret;
4590 /*----------------------------------------------------------------
4591 * hfa384x_usbout_tx
4593 * At this point we have finished a send of a frame. Mark the URB
4594 * as available and call ev_alloc to notify higher layers we're
4595 * ready for more.
4597 * Arguments:
4598 * wlandev wlan device
4599 * usbout ptr to the usb transfer buffer
4601 * Returns:
4602 * nothing
4604 * Side effects:
4606 * Call context:
4607 * interrupt
4608 ----------------------------------------------------------------*/
4609 static void hfa384x_usbout_tx(wlandevice_t *wlandev, hfa384x_usbout_t *usbout)
4611 DBFENTER;
4613 prism2sta_ev_alloc(wlandev);
4615 DBFEXIT;
4618 /*----------------------------------------------------------------
4619 * hfa384x_isgood_pdrcore
4621 * Quick check of PDR codes.
4623 * Arguments:
4624 * pdrcode PDR code number (host order)
4626 * Returns:
4627 * zero not good.
4628 * one is good.
4630 * Side effects:
4632 * Call context:
4633 ----------------------------------------------------------------*/
4634 static int
4635 hfa384x_isgood_pdrcode(u16 pdrcode)
4637 switch(pdrcode) {
4638 case HFA384x_PDR_END_OF_PDA:
4639 case HFA384x_PDR_PCB_PARTNUM:
4640 case HFA384x_PDR_PDAVER:
4641 case HFA384x_PDR_NIC_SERIAL:
4642 case HFA384x_PDR_MKK_MEASUREMENTS:
4643 case HFA384x_PDR_NIC_RAMSIZE:
4644 case HFA384x_PDR_MFISUPRANGE:
4645 case HFA384x_PDR_CFISUPRANGE:
4646 case HFA384x_PDR_NICID:
4647 case HFA384x_PDR_MAC_ADDRESS:
4648 case HFA384x_PDR_REGDOMAIN:
4649 case HFA384x_PDR_ALLOWED_CHANNEL:
4650 case HFA384x_PDR_DEFAULT_CHANNEL:
4651 case HFA384x_PDR_TEMPTYPE:
4652 case HFA384x_PDR_IFR_SETTING:
4653 case HFA384x_PDR_RFR_SETTING:
4654 case HFA384x_PDR_HFA3861_BASELINE:
4655 case HFA384x_PDR_HFA3861_SHADOW:
4656 case HFA384x_PDR_HFA3861_IFRF:
4657 case HFA384x_PDR_HFA3861_CHCALSP:
4658 case HFA384x_PDR_HFA3861_CHCALI:
4659 case HFA384x_PDR_3842_NIC_CONFIG:
4660 case HFA384x_PDR_USB_ID:
4661 case HFA384x_PDR_PCI_ID:
4662 case HFA384x_PDR_PCI_IFCONF:
4663 case HFA384x_PDR_PCI_PMCONF:
4664 case HFA384x_PDR_RFENRGY:
4665 case HFA384x_PDR_HFA3861_MANF_TESTSP:
4666 case HFA384x_PDR_HFA3861_MANF_TESTI:
4667 /* code is OK */
4668 return 1;
4669 break;
4670 default:
4671 if ( pdrcode < 0x1000 ) {
4672 /* code is OK, but we don't know exactly what it is */
4673 WLAN_LOG_DEBUG(3,
4674 "Encountered unknown PDR#=0x%04x, "
4675 "assuming it's ok.\n",
4676 pdrcode);
4677 return 1;
4678 } else {
4679 /* bad code */
4680 WLAN_LOG_DEBUG(3,
4681 "Encountered unknown PDR#=0x%04x, "
4682 "(>=0x1000), assuming it's bad.\n",
4683 pdrcode);
4684 return 0;
4686 break;
4688 return 0; /* avoid compiler warnings */