Staging: wlan-ng: Remove function hfa384x_drvr_commtallies
[deliverable/linux.git] / drivers / staging / wlan-ng / hfa384x_usb.c
1 /* src/prism2/driver/hfa384x_usb.c
2 *
3 * Functions that talk to the USB variantof the Intersil hfa384x MAC
4 *
5 * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
6 * --------------------------------------------------------------------
7 *
8 * linux-wlan
9 *
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/
14 *
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.
19 *
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.
30 *
31 * --------------------------------------------------------------------
32 *
33 * Inquiries regarding the linux-wlan Open Source project can be
34 * made directly to:
35 *
36 * AbsoluteValue Systems Inc.
37 * info@linux-wlan.com
38 * http://www.linux-wlan.com
39 *
40 * --------------------------------------------------------------------
41 *
42 * Portions of the development of this software were funded by
43 * Intersil Corporation as part of PRISM(R) chipset product development.
44 *
45 * --------------------------------------------------------------------
46 *
47 * This file implements functions that correspond to the prism2/hfa384x
48 * 802.11 MAC hardware and firmware host interface.
49 *
50 * The functions can be considered to represent several levels of
51 * abstraction. The lowest level functions are simply C-callable wrappers
52 * around the register accesses. The next higher level represents C-callable
53 * prism2 API functions that match the Intersil documentation as closely
54 * as is reasonable. The next higher layer implements common sequences
55 * of invocations of the API layer (e.g. write to bap, followed by cmd).
56 *
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.
62 *
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.
69 *
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.
81 *
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.
86 *
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.
90 *
91 * hfa384x_dl_xxx download related functions.
92 *
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()
103 * .
104 * . Do interesting things w/ the hardware
105 * .
106 * stop()
107 * destroy()
108 *
109 * Note that destroy() can be called without calling stop() first.
110 * --------------------------------------------------------------------
111 */
112
113 #include <linux/module.h>
114 #include <linux/kernel.h>
115 #include <linux/sched.h>
116 #include <linux/types.h>
117 #include <linux/slab.h>
118 #include <linux/wireless.h>
119 #include <linux/netdevice.h>
120 #include <linux/timer.h>
121 #include <linux/io.h>
122 #include <linux/delay.h>
123 #include <asm/byteorder.h>
124 #include <linux/bitops.h>
125 #include <linux/list.h>
126 #include <linux/usb.h>
127 #include <linux/byteorder/generic.h>
128
129 #define SUBMIT_URB(u, f) usb_submit_urb(u, f)
130
131 #include "p80211types.h"
132 #include "p80211hdr.h"
133 #include "p80211mgmt.h"
134 #include "p80211conv.h"
135 #include "p80211msg.h"
136 #include "p80211netdev.h"
137 #include "p80211req.h"
138 #include "p80211metadef.h"
139 #include "p80211metastruct.h"
140 #include "hfa384x.h"
141 #include "prism2mgmt.h"
142
143 enum cmd_mode {
144 DOWAIT = 0,
145 DOASYNC
146 };
147
148 #define THROTTLE_JIFFIES (HZ / 8)
149 #define URB_ASYNC_UNLINK 0
150 #define USB_QUEUE_BULK 0
151
152 #define ROUNDUP64(a) (((a) + 63) & ~63)
153
154 #ifdef DEBUG_USB
155 static void dbprint_urb(struct urb *urb);
156 #endif
157
158 static void
159 hfa384x_int_rxmonitor(wlandevice_t *wlandev, hfa384x_usb_rxfrm_t *rxfrm);
160
161 static void hfa384x_usb_defer(struct work_struct *data);
162
163 static int submit_rx_urb(hfa384x_t *hw, gfp_t flags);
164
165 static int submit_tx_urb(hfa384x_t *hw, struct urb *tx_urb, gfp_t flags);
166
167 /*---------------------------------------------------*/
168 /* Callbacks */
169 static void hfa384x_usbout_callback(struct urb *urb);
170 static void hfa384x_ctlxout_callback(struct urb *urb);
171 static void hfa384x_usbin_callback(struct urb *urb);
172
173 static void
174 hfa384x_usbin_txcompl(wlandevice_t *wlandev, hfa384x_usbin_t *usbin);
175
176 static void hfa384x_usbin_rx(wlandevice_t *wlandev, struct sk_buff *skb);
177
178 static void hfa384x_usbin_info(wlandevice_t *wlandev, hfa384x_usbin_t *usbin);
179
180 static void hfa384x_usbin_ctlx(hfa384x_t *hw, hfa384x_usbin_t *usbin,
181 int urb_status);
182
183 /*---------------------------------------------------*/
184 /* Functions to support the prism2 usb command queue */
185
186 static void hfa384x_usbctlxq_run(hfa384x_t *hw);
187
188 static void hfa384x_usbctlx_reqtimerfn(unsigned long data);
189
190 static void hfa384x_usbctlx_resptimerfn(unsigned long data);
191
192 static void hfa384x_usb_throttlefn(unsigned long data);
193
194 static void hfa384x_usbctlx_completion_task(unsigned long data);
195
196 static void hfa384x_usbctlx_reaper_task(unsigned long data);
197
198 static int hfa384x_usbctlx_submit(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
199
200 static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
201
202 struct usbctlx_completor {
203 int (*complete)(struct usbctlx_completor *);
204 };
205
206 static int
207 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
208 hfa384x_usbctlx_t *ctlx,
209 struct usbctlx_completor *completor);
210
211 static int
212 unlocked_usbctlx_cancel_async(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
213
214 static void hfa384x_cb_status(hfa384x_t *hw, const hfa384x_usbctlx_t *ctlx);
215
216 static void hfa384x_cb_rrid(hfa384x_t *hw, const hfa384x_usbctlx_t *ctlx);
217
218 static int
219 usbctlx_get_status(const hfa384x_usb_cmdresp_t *cmdresp,
220 hfa384x_cmdresult_t *result);
221
222 static void
223 usbctlx_get_rridresult(const hfa384x_usb_rridresp_t *rridresp,
224 hfa384x_rridresult_t *result);
225
226 /*---------------------------------------------------*/
227 /* Low level req/resp CTLX formatters and submitters */
228 static int
229 hfa384x_docmd(hfa384x_t *hw,
230 enum cmd_mode mode,
231 hfa384x_metacmd_t *cmd,
232 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
233
234 static int
235 hfa384x_dorrid(hfa384x_t *hw,
236 enum cmd_mode mode,
237 u16 rid,
238 void *riddata,
239 unsigned int riddatalen,
240 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
241
242 static int
243 hfa384x_dowrid(hfa384x_t *hw,
244 enum cmd_mode mode,
245 u16 rid,
246 void *riddata,
247 unsigned int riddatalen,
248 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
249
250 static int
251 hfa384x_dormem(hfa384x_t *hw,
252 enum cmd_mode mode,
253 u16 page,
254 u16 offset,
255 void *data,
256 unsigned int len,
257 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
258
259 static int
260 hfa384x_dowmem(hfa384x_t *hw,
261 enum cmd_mode mode,
262 u16 page,
263 u16 offset,
264 void *data,
265 unsigned int len,
266 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
267
268 static int hfa384x_isgood_pdrcode(u16 pdrcode);
269
270 static inline const char *ctlxstr(CTLX_STATE s)
271 {
272 static const char * const ctlx_str[] = {
273 "Initial state",
274 "Complete",
275 "Request failed",
276 "Request pending",
277 "Request packet submitted",
278 "Request packet completed",
279 "Response packet completed"
280 };
281
282 return ctlx_str[s];
283 };
284
285 static inline hfa384x_usbctlx_t *get_active_ctlx(hfa384x_t *hw)
286 {
287 return list_entry(hw->ctlxq.active.next, hfa384x_usbctlx_t, list);
288 }
289
290 #ifdef DEBUG_USB
291 void dbprint_urb(struct urb *urb)
292 {
293 pr_debug("urb->pipe=0x%08x\n", urb->pipe);
294 pr_debug("urb->status=0x%08x\n", urb->status);
295 pr_debug("urb->transfer_flags=0x%08x\n", urb->transfer_flags);
296 pr_debug("urb->transfer_buffer=0x%08x\n",
297 (unsigned int)urb->transfer_buffer);
298 pr_debug("urb->transfer_buffer_length=0x%08x\n",
299 urb->transfer_buffer_length);
300 pr_debug("urb->actual_length=0x%08x\n", urb->actual_length);
301 pr_debug("urb->bandwidth=0x%08x\n", urb->bandwidth);
302 pr_debug("urb->setup_packet(ctl)=0x%08x\n",
303 (unsigned int)urb->setup_packet);
304 pr_debug("urb->start_frame(iso/irq)=0x%08x\n", urb->start_frame);
305 pr_debug("urb->interval(irq)=0x%08x\n", urb->interval);
306 pr_debug("urb->error_count(iso)=0x%08x\n", urb->error_count);
307 pr_debug("urb->timeout=0x%08x\n", urb->timeout);
308 pr_debug("urb->context=0x%08x\n", (unsigned int)urb->context);
309 pr_debug("urb->complete=0x%08x\n", (unsigned int)urb->complete);
310 }
311 #endif
312
313 /*----------------------------------------------------------------
314 * submit_rx_urb
315 *
316 * Listen for input data on the BULK-IN pipe. If the pipe has
317 * stalled then schedule it to be reset.
318 *
319 * Arguments:
320 * hw device struct
321 * memflags memory allocation flags
322 *
323 * Returns:
324 * error code from submission
325 *
326 * Call context:
327 * Any
328 ----------------------------------------------------------------*/
329 static int submit_rx_urb(hfa384x_t *hw, gfp_t memflags)
330 {
331 struct sk_buff *skb;
332 int result;
333
334 skb = dev_alloc_skb(sizeof(hfa384x_usbin_t));
335 if (skb == NULL) {
336 result = -ENOMEM;
337 goto done;
338 }
339
340 /* Post the IN urb */
341 usb_fill_bulk_urb(&hw->rx_urb, hw->usb,
342 hw->endp_in,
343 skb->data, sizeof(hfa384x_usbin_t),
344 hfa384x_usbin_callback, hw->wlandev);
345
346 hw->rx_urb_skb = skb;
347
348 result = -ENOLINK;
349 if (!hw->wlandev->hwremoved &&
350 !test_bit(WORK_RX_HALT, &hw->usb_flags)) {
351 result = SUBMIT_URB(&hw->rx_urb, memflags);
352
353 /* Check whether we need to reset the RX pipe */
354 if (result == -EPIPE) {
355 netdev_warn(hw->wlandev->netdev,
356 "%s rx pipe stalled: requesting reset\n",
357 hw->wlandev->netdev->name);
358 if (!test_and_set_bit(WORK_RX_HALT, &hw->usb_flags))
359 schedule_work(&hw->usb_work);
360 }
361 }
362
363 /* Don't leak memory if anything should go wrong */
364 if (result != 0) {
365 dev_kfree_skb(skb);
366 hw->rx_urb_skb = NULL;
367 }
368
369 done:
370 return result;
371 }
372
373 /*----------------------------------------------------------------
374 * submit_tx_urb
375 *
376 * Prepares and submits the URB of transmitted data. If the
377 * submission fails then it will schedule the output pipe to
378 * be reset.
379 *
380 * Arguments:
381 * hw device struct
382 * tx_urb URB of data for transmission
383 * memflags memory allocation flags
384 *
385 * Returns:
386 * error code from submission
387 *
388 * Call context:
389 * Any
390 ----------------------------------------------------------------*/
391 static int submit_tx_urb(hfa384x_t *hw, struct urb *tx_urb, gfp_t memflags)
392 {
393 struct net_device *netdev = hw->wlandev->netdev;
394 int result;
395
396 result = -ENOLINK;
397 if (netif_running(netdev)) {
398 if (!hw->wlandev->hwremoved &&
399 !test_bit(WORK_TX_HALT, &hw->usb_flags)) {
400 result = SUBMIT_URB(tx_urb, memflags);
401
402 /* Test whether we need to reset the TX pipe */
403 if (result == -EPIPE) {
404 netdev_warn(hw->wlandev->netdev,
405 "%s tx pipe stalled: requesting reset\n",
406 netdev->name);
407 set_bit(WORK_TX_HALT, &hw->usb_flags);
408 schedule_work(&hw->usb_work);
409 } else if (result == 0) {
410 netif_stop_queue(netdev);
411 }
412 }
413 }
414
415 return result;
416 }
417
418 /*----------------------------------------------------------------
419 * hfa394x_usb_defer
420 *
421 * There are some things that the USB stack cannot do while
422 * in interrupt context, so we arrange this function to run
423 * in process context.
424 *
425 * Arguments:
426 * hw device structure
427 *
428 * Returns:
429 * nothing
430 *
431 * Call context:
432 * process (by design)
433 ----------------------------------------------------------------*/
434 static void hfa384x_usb_defer(struct work_struct *data)
435 {
436 hfa384x_t *hw = container_of(data, struct hfa384x, usb_work);
437 struct net_device *netdev = hw->wlandev->netdev;
438
439 /* Don't bother trying to reset anything if the plug
440 * has been pulled ...
441 */
442 if (hw->wlandev->hwremoved)
443 return;
444
445 /* Reception has stopped: try to reset the input pipe */
446 if (test_bit(WORK_RX_HALT, &hw->usb_flags)) {
447 int ret;
448
449 usb_kill_urb(&hw->rx_urb); /* Cannot be holding spinlock! */
450
451 ret = usb_clear_halt(hw->usb, hw->endp_in);
452 if (ret != 0) {
453 netdev_err(hw->wlandev->netdev,
454 "Failed to clear rx pipe for %s: err=%d\n",
455 netdev->name, ret);
456 } else {
457 netdev_info(hw->wlandev->netdev, "%s rx pipe reset complete.\n",
458 netdev->name);
459 clear_bit(WORK_RX_HALT, &hw->usb_flags);
460 set_bit(WORK_RX_RESUME, &hw->usb_flags);
461 }
462 }
463
464 /* Resume receiving data back from the device. */
465 if (test_bit(WORK_RX_RESUME, &hw->usb_flags)) {
466 int ret;
467
468 ret = submit_rx_urb(hw, GFP_KERNEL);
469 if (ret != 0) {
470 netdev_err(hw->wlandev->netdev,
471 "Failed to resume %s rx pipe.\n",
472 netdev->name);
473 } else {
474 clear_bit(WORK_RX_RESUME, &hw->usb_flags);
475 }
476 }
477
478 /* Transmission has stopped: try to reset the output pipe */
479 if (test_bit(WORK_TX_HALT, &hw->usb_flags)) {
480 int ret;
481
482 usb_kill_urb(&hw->tx_urb);
483 ret = usb_clear_halt(hw->usb, hw->endp_out);
484 if (ret != 0) {
485 netdev_err(hw->wlandev->netdev,
486 "Failed to clear tx pipe for %s: err=%d\n",
487 netdev->name, ret);
488 } else {
489 netdev_info(hw->wlandev->netdev, "%s tx pipe reset complete.\n",
490 netdev->name);
491 clear_bit(WORK_TX_HALT, &hw->usb_flags);
492 set_bit(WORK_TX_RESUME, &hw->usb_flags);
493
494 /* Stopping the BULK-OUT pipe also blocked
495 * us from sending any more CTLX URBs, so
496 * we need to re-run our queue ...
497 */
498 hfa384x_usbctlxq_run(hw);
499 }
500 }
501
502 /* Resume transmitting. */
503 if (test_and_clear_bit(WORK_TX_RESUME, &hw->usb_flags))
504 netif_wake_queue(hw->wlandev->netdev);
505 }
506
507 /*----------------------------------------------------------------
508 * hfa384x_create
509 *
510 * Sets up the hfa384x_t data structure for use. Note this
511 * does _not_ initialize the actual hardware, just the data structures
512 * we use to keep track of its state.
513 *
514 * Arguments:
515 * hw device structure
516 * irq device irq number
517 * iobase i/o base address for register access
518 * membase memory base address for register access
519 *
520 * Returns:
521 * nothing
522 *
523 * Side effects:
524 *
525 * Call context:
526 * process
527 ----------------------------------------------------------------*/
528 void hfa384x_create(hfa384x_t *hw, struct usb_device *usb)
529 {
530 memset(hw, 0, sizeof(hfa384x_t));
531 hw->usb = usb;
532
533 /* set up the endpoints */
534 hw->endp_in = usb_rcvbulkpipe(usb, 1);
535 hw->endp_out = usb_sndbulkpipe(usb, 2);
536
537 /* Set up the waitq */
538 init_waitqueue_head(&hw->cmdq);
539
540 /* Initialize the command queue */
541 spin_lock_init(&hw->ctlxq.lock);
542 INIT_LIST_HEAD(&hw->ctlxq.pending);
543 INIT_LIST_HEAD(&hw->ctlxq.active);
544 INIT_LIST_HEAD(&hw->ctlxq.completing);
545 INIT_LIST_HEAD(&hw->ctlxq.reapable);
546
547 /* Initialize the authentication queue */
548 skb_queue_head_init(&hw->authq);
549
550 tasklet_init(&hw->reaper_bh,
551 hfa384x_usbctlx_reaper_task, (unsigned long)hw);
552 tasklet_init(&hw->completion_bh,
553 hfa384x_usbctlx_completion_task, (unsigned long)hw);
554 INIT_WORK(&hw->link_bh, prism2sta_processing_defer);
555 INIT_WORK(&hw->usb_work, hfa384x_usb_defer);
556
557 setup_timer(&hw->throttle, hfa384x_usb_throttlefn, (unsigned long)hw);
558
559 setup_timer(&hw->resptimer, hfa384x_usbctlx_resptimerfn,
560 (unsigned long)hw);
561
562 setup_timer(&hw->reqtimer, hfa384x_usbctlx_reqtimerfn,
563 (unsigned long)hw);
564
565 usb_init_urb(&hw->rx_urb);
566 usb_init_urb(&hw->tx_urb);
567 usb_init_urb(&hw->ctlx_urb);
568
569 hw->link_status = HFA384x_LINK_NOTCONNECTED;
570 hw->state = HFA384x_STATE_INIT;
571
572 INIT_WORK(&hw->commsqual_bh, prism2sta_commsqual_defer);
573 setup_timer(&hw->commsqual_timer, prism2sta_commsqual_timer,
574 (unsigned long)hw);
575 }
576
577 /*----------------------------------------------------------------
578 * hfa384x_destroy
579 *
580 * Partner to hfa384x_create(). This function cleans up the hw
581 * structure so that it can be freed by the caller using a simple
582 * kfree. Currently, this function is just a placeholder. If, at some
583 * point in the future, an hw in the 'shutdown' state requires a 'deep'
584 * kfree, this is where it should be done. Note that if this function
585 * is called on a _running_ hw structure, the drvr_stop() function is
586 * called.
587 *
588 * Arguments:
589 * hw device structure
590 *
591 * Returns:
592 * nothing, this function is not allowed to fail.
593 *
594 * Side effects:
595 *
596 * Call context:
597 * process
598 ----------------------------------------------------------------*/
599 void hfa384x_destroy(hfa384x_t *hw)
600 {
601 struct sk_buff *skb;
602
603 if (hw->state == HFA384x_STATE_RUNNING)
604 hfa384x_drvr_stop(hw);
605 hw->state = HFA384x_STATE_PREINIT;
606
607 kfree(hw->scanresults);
608 hw->scanresults = NULL;
609
610 /* Now to clean out the auth queue */
611 while ((skb = skb_dequeue(&hw->authq)))
612 dev_kfree_skb(skb);
613 }
614
615 static hfa384x_usbctlx_t *usbctlx_alloc(void)
616 {
617 hfa384x_usbctlx_t *ctlx;
618
619 ctlx = kzalloc(sizeof(*ctlx),
620 in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
621 if (ctlx != NULL)
622 init_completion(&ctlx->done);
623
624 return ctlx;
625 }
626
627 static int
628 usbctlx_get_status(const hfa384x_usb_cmdresp_t *cmdresp,
629 hfa384x_cmdresult_t *result)
630 {
631 result->status = le16_to_cpu(cmdresp->status);
632 result->resp0 = le16_to_cpu(cmdresp->resp0);
633 result->resp1 = le16_to_cpu(cmdresp->resp1);
634 result->resp2 = le16_to_cpu(cmdresp->resp2);
635
636 pr_debug("cmdresult:status=0x%04x resp0=0x%04x resp1=0x%04x resp2=0x%04x\n",
637 result->status, result->resp0, result->resp1, result->resp2);
638
639 return result->status & HFA384x_STATUS_RESULT;
640 }
641
642 static void
643 usbctlx_get_rridresult(const hfa384x_usb_rridresp_t *rridresp,
644 hfa384x_rridresult_t *result)
645 {
646 result->rid = le16_to_cpu(rridresp->rid);
647 result->riddata = rridresp->data;
648 result->riddata_len = ((le16_to_cpu(rridresp->frmlen) - 1) * 2);
649 }
650
651 /*----------------------------------------------------------------
652 * Completor object:
653 * This completor must be passed to hfa384x_usbctlx_complete_sync()
654 * when processing a CTLX that returns a hfa384x_cmdresult_t structure.
655 ----------------------------------------------------------------*/
656 struct usbctlx_cmd_completor {
657 struct usbctlx_completor head;
658
659 const hfa384x_usb_cmdresp_t *cmdresp;
660 hfa384x_cmdresult_t *result;
661 };
662
663 static inline int usbctlx_cmd_completor_fn(struct usbctlx_completor *head)
664 {
665 struct usbctlx_cmd_completor *complete;
666
667 complete = (struct usbctlx_cmd_completor *)head;
668 return usbctlx_get_status(complete->cmdresp, complete->result);
669 }
670
671 static inline struct usbctlx_completor *init_cmd_completor(
672 struct usbctlx_cmd_completor
673 *completor,
674 const hfa384x_usb_cmdresp_t
675 *cmdresp,
676 hfa384x_cmdresult_t *result)
677 {
678 completor->head.complete = usbctlx_cmd_completor_fn;
679 completor->cmdresp = cmdresp;
680 completor->result = result;
681 return &(completor->head);
682 }
683
684 /*----------------------------------------------------------------
685 * Completor object:
686 * This completor must be passed to hfa384x_usbctlx_complete_sync()
687 * when processing a CTLX that reads a RID.
688 ----------------------------------------------------------------*/
689 struct usbctlx_rrid_completor {
690 struct usbctlx_completor head;
691
692 const hfa384x_usb_rridresp_t *rridresp;
693 void *riddata;
694 unsigned int riddatalen;
695 };
696
697 static int usbctlx_rrid_completor_fn(struct usbctlx_completor *head)
698 {
699 struct usbctlx_rrid_completor *complete;
700 hfa384x_rridresult_t rridresult;
701
702 complete = (struct usbctlx_rrid_completor *)head;
703 usbctlx_get_rridresult(complete->rridresp, &rridresult);
704
705 /* Validate the length, note body len calculation in bytes */
706 if (rridresult.riddata_len != complete->riddatalen) {
707 pr_warn("RID len mismatch, rid=0x%04x hlen=%d fwlen=%d\n",
708 rridresult.rid,
709 complete->riddatalen, rridresult.riddata_len);
710 return -ENODATA;
711 }
712
713 memcpy(complete->riddata, rridresult.riddata, complete->riddatalen);
714 return 0;
715 }
716
717 static inline struct usbctlx_completor *init_rrid_completor(
718 struct usbctlx_rrid_completor
719 *completor,
720 const hfa384x_usb_rridresp_t
721 *rridresp,
722 void *riddata,
723 unsigned int riddatalen)
724 {
725 completor->head.complete = usbctlx_rrid_completor_fn;
726 completor->rridresp = rridresp;
727 completor->riddata = riddata;
728 completor->riddatalen = riddatalen;
729 return &(completor->head);
730 }
731
732 /*----------------------------------------------------------------
733 * Completor object:
734 * Interprets the results of a synchronous RID-write
735 ----------------------------------------------------------------*/
736 #define init_wrid_completor init_cmd_completor
737
738 /*----------------------------------------------------------------
739 * Completor object:
740 * Interprets the results of a synchronous memory-write
741 ----------------------------------------------------------------*/
742 #define init_wmem_completor init_cmd_completor
743
744 /*----------------------------------------------------------------
745 * Completor object:
746 * Interprets the results of a synchronous memory-read
747 ----------------------------------------------------------------*/
748 struct usbctlx_rmem_completor {
749 struct usbctlx_completor head;
750
751 const hfa384x_usb_rmemresp_t *rmemresp;
752 void *data;
753 unsigned int len;
754 };
755
756 static int usbctlx_rmem_completor_fn(struct usbctlx_completor *head)
757 {
758 struct usbctlx_rmem_completor *complete =
759 (struct usbctlx_rmem_completor *)head;
760
761 pr_debug("rmemresp:len=%d\n", complete->rmemresp->frmlen);
762 memcpy(complete->data, complete->rmemresp->data, complete->len);
763 return 0;
764 }
765
766 static inline struct usbctlx_completor *init_rmem_completor(
767 struct usbctlx_rmem_completor
768 *completor,
769 hfa384x_usb_rmemresp_t
770 *rmemresp,
771 void *data,
772 unsigned int len)
773 {
774 completor->head.complete = usbctlx_rmem_completor_fn;
775 completor->rmemresp = rmemresp;
776 completor->data = data;
777 completor->len = len;
778 return &(completor->head);
779 }
780
781 /*----------------------------------------------------------------
782 * hfa384x_cb_status
783 *
784 * Ctlx_complete handler for async CMD type control exchanges.
785 * mark the hw struct as such.
786 *
787 * Note: If the handling is changed here, it should probably be
788 * changed in docmd as well.
789 *
790 * Arguments:
791 * hw hw struct
792 * ctlx completed CTLX
793 *
794 * Returns:
795 * nothing
796 *
797 * Side effects:
798 *
799 * Call context:
800 * interrupt
801 ----------------------------------------------------------------*/
802 static void hfa384x_cb_status(hfa384x_t *hw, const hfa384x_usbctlx_t *ctlx)
803 {
804 if (ctlx->usercb != NULL) {
805 hfa384x_cmdresult_t cmdresult;
806
807 if (ctlx->state != CTLX_COMPLETE) {
808 memset(&cmdresult, 0, sizeof(cmdresult));
809 cmdresult.status =
810 HFA384x_STATUS_RESULT_SET(HFA384x_CMD_ERR);
811 } else {
812 usbctlx_get_status(&ctlx->inbuf.cmdresp, &cmdresult);
813 }
814
815 ctlx->usercb(hw, &cmdresult, ctlx->usercb_data);
816 }
817 }
818
819 /*----------------------------------------------------------------
820 * hfa384x_cb_rrid
821 *
822 * CTLX completion handler for async RRID type control exchanges.
823 *
824 * Note: If the handling is changed here, it should probably be
825 * changed in dorrid as well.
826 *
827 * Arguments:
828 * hw hw struct
829 * ctlx completed CTLX
830 *
831 * Returns:
832 * nothing
833 *
834 * Side effects:
835 *
836 * Call context:
837 * interrupt
838 ----------------------------------------------------------------*/
839 static void hfa384x_cb_rrid(hfa384x_t *hw, const hfa384x_usbctlx_t *ctlx)
840 {
841 if (ctlx->usercb != NULL) {
842 hfa384x_rridresult_t rridresult;
843
844 if (ctlx->state != CTLX_COMPLETE) {
845 memset(&rridresult, 0, sizeof(rridresult));
846 rridresult.rid = le16_to_cpu(ctlx->outbuf.rridreq.rid);
847 } else {
848 usbctlx_get_rridresult(&ctlx->inbuf.rridresp,
849 &rridresult);
850 }
851
852 ctlx->usercb(hw, &rridresult, ctlx->usercb_data);
853 }
854 }
855
856 static inline int hfa384x_docmd_wait(hfa384x_t *hw, hfa384x_metacmd_t *cmd)
857 {
858 return hfa384x_docmd(hw, DOWAIT, cmd, NULL, NULL, NULL);
859 }
860
861 static inline int
862 hfa384x_docmd_async(hfa384x_t *hw,
863 hfa384x_metacmd_t *cmd,
864 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
865 {
866 return hfa384x_docmd(hw, DOASYNC, cmd, cmdcb, usercb, usercb_data);
867 }
868
869 static inline int
870 hfa384x_dorrid_wait(hfa384x_t *hw, u16 rid, void *riddata,
871 unsigned int riddatalen)
872 {
873 return hfa384x_dorrid(hw, DOWAIT,
874 rid, riddata, riddatalen, NULL, NULL, NULL);
875 }
876
877 static inline int
878 hfa384x_dorrid_async(hfa384x_t *hw,
879 u16 rid, void *riddata, unsigned int riddatalen,
880 ctlx_cmdcb_t cmdcb,
881 ctlx_usercb_t usercb, void *usercb_data)
882 {
883 return hfa384x_dorrid(hw, DOASYNC,
884 rid, riddata, riddatalen,
885 cmdcb, usercb, usercb_data);
886 }
887
888 static inline int
889 hfa384x_dowrid_wait(hfa384x_t *hw, u16 rid, void *riddata,
890 unsigned int riddatalen)
891 {
892 return hfa384x_dowrid(hw, DOWAIT,
893 rid, riddata, riddatalen, NULL, NULL, NULL);
894 }
895
896 static inline int
897 hfa384x_dowrid_async(hfa384x_t *hw,
898 u16 rid, void *riddata, unsigned int riddatalen,
899 ctlx_cmdcb_t cmdcb,
900 ctlx_usercb_t usercb, void *usercb_data)
901 {
902 return hfa384x_dowrid(hw, DOASYNC,
903 rid, riddata, riddatalen,
904 cmdcb, usercb, usercb_data);
905 }
906
907 static inline int
908 hfa384x_dormem_wait(hfa384x_t *hw,
909 u16 page, u16 offset, void *data, unsigned int len)
910 {
911 return hfa384x_dormem(hw, DOWAIT,
912 page, offset, data, len, NULL, NULL, NULL);
913 }
914
915 static inline int
916 hfa384x_dormem_async(hfa384x_t *hw,
917 u16 page, u16 offset, void *data, unsigned int len,
918 ctlx_cmdcb_t cmdcb,
919 ctlx_usercb_t usercb, void *usercb_data)
920 {
921 return hfa384x_dormem(hw, DOASYNC,
922 page, offset, data, len,
923 cmdcb, usercb, usercb_data);
924 }
925
926 static inline int
927 hfa384x_dowmem_wait(hfa384x_t *hw,
928 u16 page, u16 offset, void *data, unsigned int len)
929 {
930 return hfa384x_dowmem(hw, DOWAIT,
931 page, offset, data, len, NULL, NULL, NULL);
932 }
933
934 static inline int
935 hfa384x_dowmem_async(hfa384x_t *hw,
936 u16 page,
937 u16 offset,
938 void *data,
939 unsigned int len,
940 ctlx_cmdcb_t cmdcb,
941 ctlx_usercb_t usercb, void *usercb_data)
942 {
943 return hfa384x_dowmem(hw, DOASYNC,
944 page, offset, data, len,
945 cmdcb, usercb, usercb_data);
946 }
947
948 /*----------------------------------------------------------------
949 * hfa384x_cmd_initialize
950 *
951 * Issues the initialize command and sets the hw->state based
952 * on the result.
953 *
954 * Arguments:
955 * hw device structure
956 *
957 * Returns:
958 * 0 success
959 * >0 f/w reported error - f/w status code
960 * <0 driver reported error
961 *
962 * Side effects:
963 *
964 * Call context:
965 * process
966 ----------------------------------------------------------------*/
967 int hfa384x_cmd_initialize(hfa384x_t *hw)
968 {
969 int result = 0;
970 int i;
971 hfa384x_metacmd_t cmd;
972
973 cmd.cmd = HFA384x_CMDCODE_INIT;
974 cmd.parm0 = 0;
975 cmd.parm1 = 0;
976 cmd.parm2 = 0;
977
978 result = hfa384x_docmd_wait(hw, &cmd);
979
980 pr_debug("cmdresp.init: status=0x%04x, resp0=0x%04x, resp1=0x%04x, resp2=0x%04x\n",
981 cmd.result.status,
982 cmd.result.resp0, cmd.result.resp1, cmd.result.resp2);
983 if (result == 0) {
984 for (i = 0; i < HFA384x_NUMPORTS_MAX; i++)
985 hw->port_enabled[i] = 0;
986 }
987
988 hw->link_status = HFA384x_LINK_NOTCONNECTED;
989
990 return result;
991 }
992
993 /*----------------------------------------------------------------
994 * hfa384x_cmd_disable
995 *
996 * Issues the disable command to stop communications on one of
997 * the MACs 'ports'.
998 *
999 * Arguments:
1000 * hw device structure
1001 * macport MAC port number (host order)
1002 *
1003 * Returns:
1004 * 0 success
1005 * >0 f/w reported failure - f/w status code
1006 * <0 driver reported error (timeout|bad arg)
1007 *
1008 * Side effects:
1009 *
1010 * Call context:
1011 * process
1012 ----------------------------------------------------------------*/
1013 int hfa384x_cmd_disable(hfa384x_t *hw, u16 macport)
1014 {
1015 hfa384x_metacmd_t cmd;
1016
1017 cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_DISABLE) |
1018 HFA384x_CMD_MACPORT_SET(macport);
1019 cmd.parm0 = 0;
1020 cmd.parm1 = 0;
1021 cmd.parm2 = 0;
1022
1023 return hfa384x_docmd_wait(hw, &cmd);
1024 }
1025
1026 /*----------------------------------------------------------------
1027 * hfa384x_cmd_enable
1028 *
1029 * Issues the enable command to enable communications on one of
1030 * the MACs 'ports'.
1031 *
1032 * Arguments:
1033 * hw device structure
1034 * macport MAC port number
1035 *
1036 * Returns:
1037 * 0 success
1038 * >0 f/w reported failure - f/w status code
1039 * <0 driver reported error (timeout|bad arg)
1040 *
1041 * Side effects:
1042 *
1043 * Call context:
1044 * process
1045 ----------------------------------------------------------------*/
1046 int hfa384x_cmd_enable(hfa384x_t *hw, u16 macport)
1047 {
1048 hfa384x_metacmd_t cmd;
1049
1050 cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_ENABLE) |
1051 HFA384x_CMD_MACPORT_SET(macport);
1052 cmd.parm0 = 0;
1053 cmd.parm1 = 0;
1054 cmd.parm2 = 0;
1055
1056 return hfa384x_docmd_wait(hw, &cmd);
1057 }
1058
1059 /*----------------------------------------------------------------
1060 * hfa384x_cmd_monitor
1061 *
1062 * Enables the 'monitor mode' of the MAC. Here's the description of
1063 * monitor mode that I've received thus far:
1064 *
1065 * "The "monitor mode" of operation is that the MAC passes all
1066 * frames for which the PLCP checks are correct. All received
1067 * MPDUs are passed to the host with MAC Port = 7, with a
1068 * receive status of good, FCS error, or undecryptable. Passing
1069 * certain MPDUs is a violation of the 802.11 standard, but useful
1070 * for a debugging tool." Normal communication is not possible
1071 * while monitor mode is enabled.
1072 *
1073 * Arguments:
1074 * hw device structure
1075 * enable a code (0x0b|0x0f) that enables/disables
1076 * monitor mode. (host order)
1077 *
1078 * Returns:
1079 * 0 success
1080 * >0 f/w reported failure - f/w status code
1081 * <0 driver reported error (timeout|bad arg)
1082 *
1083 * Side effects:
1084 *
1085 * Call context:
1086 * process
1087 ----------------------------------------------------------------*/
1088 int hfa384x_cmd_monitor(hfa384x_t *hw, u16 enable)
1089 {
1090 hfa384x_metacmd_t cmd;
1091
1092 cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_MONITOR) |
1093 HFA384x_CMD_AINFO_SET(enable);
1094 cmd.parm0 = 0;
1095 cmd.parm1 = 0;
1096 cmd.parm2 = 0;
1097
1098 return hfa384x_docmd_wait(hw, &cmd);
1099 }
1100
1101 /*----------------------------------------------------------------
1102 * hfa384x_cmd_download
1103 *
1104 * Sets the controls for the MAC controller code/data download
1105 * process. The arguments set the mode and address associated
1106 * with a download. Note that the aux registers should be enabled
1107 * prior to setting one of the download enable modes.
1108 *
1109 * Arguments:
1110 * hw device structure
1111 * mode 0 - Disable programming and begin code exec
1112 * 1 - Enable volatile mem programming
1113 * 2 - Enable non-volatile mem programming
1114 * 3 - Program non-volatile section from NV download
1115 * buffer.
1116 * (host order)
1117 * lowaddr
1118 * highaddr For mode 1, sets the high & low order bits of
1119 * the "destination address". This address will be
1120 * the execution start address when download is
1121 * subsequently disabled.
1122 * For mode 2, sets the high & low order bits of
1123 * the destination in NV ram.
1124 * For modes 0 & 3, should be zero. (host order)
1125 * NOTE: these are CMD format.
1126 * codelen Length of the data to write in mode 2,
1127 * zero otherwise. (host order)
1128 *
1129 * Returns:
1130 * 0 success
1131 * >0 f/w reported failure - f/w status code
1132 * <0 driver reported error (timeout|bad arg)
1133 *
1134 * Side effects:
1135 *
1136 * Call context:
1137 * process
1138 ----------------------------------------------------------------*/
1139 int hfa384x_cmd_download(hfa384x_t *hw, u16 mode, u16 lowaddr,
1140 u16 highaddr, u16 codelen)
1141 {
1142 hfa384x_metacmd_t cmd;
1143
1144 pr_debug("mode=%d, lowaddr=0x%04x, highaddr=0x%04x, codelen=%d\n",
1145 mode, lowaddr, highaddr, codelen);
1146
1147 cmd.cmd = (HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_DOWNLD) |
1148 HFA384x_CMD_PROGMODE_SET(mode));
1149
1150 cmd.parm0 = lowaddr;
1151 cmd.parm1 = highaddr;
1152 cmd.parm2 = codelen;
1153
1154 return hfa384x_docmd_wait(hw, &cmd);
1155 }
1156
1157 /*----------------------------------------------------------------
1158 * hfa384x_corereset
1159 *
1160 * Perform a reset of the hfa38xx MAC core. We assume that the hw
1161 * structure is in its "created" state. That is, it is initialized
1162 * with proper values. Note that if a reset is done after the
1163 * device has been active for awhile, the caller might have to clean
1164 * up some leftover cruft in the hw structure.
1165 *
1166 * Arguments:
1167 * hw device structure
1168 * holdtime how long (in ms) to hold the reset
1169 * settletime how long (in ms) to wait after releasing
1170 * the reset
1171 *
1172 * Returns:
1173 * nothing
1174 *
1175 * Side effects:
1176 *
1177 * Call context:
1178 * process
1179 ----------------------------------------------------------------*/
1180 int hfa384x_corereset(hfa384x_t *hw, int holdtime, int settletime, int genesis)
1181 {
1182 int result;
1183
1184 result = usb_reset_device(hw->usb);
1185 if (result < 0) {
1186 netdev_err(hw->wlandev->netdev, "usb_reset_device() failed, result=%d.\n",
1187 result);
1188 }
1189
1190 return result;
1191 }
1192
1193 /*----------------------------------------------------------------
1194 * hfa384x_usbctlx_complete_sync
1195 *
1196 * Waits for a synchronous CTLX object to complete,
1197 * and then handles the response.
1198 *
1199 * Arguments:
1200 * hw device structure
1201 * ctlx CTLX ptr
1202 * completor functor object to decide what to
1203 * do with the CTLX's result.
1204 *
1205 * Returns:
1206 * 0 Success
1207 * -ERESTARTSYS Interrupted by a signal
1208 * -EIO CTLX failed
1209 * -ENODEV Adapter was unplugged
1210 * ??? Result from completor
1211 *
1212 * Side effects:
1213 *
1214 * Call context:
1215 * process
1216 ----------------------------------------------------------------*/
1217 static int hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
1218 hfa384x_usbctlx_t *ctlx,
1219 struct usbctlx_completor *completor)
1220 {
1221 unsigned long flags;
1222 int result;
1223
1224 result = wait_for_completion_interruptible(&ctlx->done);
1225
1226 spin_lock_irqsave(&hw->ctlxq.lock, flags);
1227
1228 /*
1229 * We can only handle the CTLX if the USB disconnect
1230 * function has not run yet ...
1231 */
1232 cleanup:
1233 if (hw->wlandev->hwremoved) {
1234 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1235 result = -ENODEV;
1236 } else if (result != 0) {
1237 int runqueue = 0;
1238
1239 /*
1240 * We were probably interrupted, so delete
1241 * this CTLX asynchronously, kill the timers
1242 * and the URB, and then start the next
1243 * pending CTLX.
1244 *
1245 * NOTE: We can only delete the timers and
1246 * the URB if this CTLX is active.
1247 */
1248 if (ctlx == get_active_ctlx(hw)) {
1249 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1250
1251 del_singleshot_timer_sync(&hw->reqtimer);
1252 del_singleshot_timer_sync(&hw->resptimer);
1253 hw->req_timer_done = 1;
1254 hw->resp_timer_done = 1;
1255 usb_kill_urb(&hw->ctlx_urb);
1256
1257 spin_lock_irqsave(&hw->ctlxq.lock, flags);
1258
1259 runqueue = 1;
1260
1261 /*
1262 * This scenario is so unlikely that I'm
1263 * happy with a grubby "goto" solution ...
1264 */
1265 if (hw->wlandev->hwremoved)
1266 goto cleanup;
1267 }
1268
1269 /*
1270 * The completion task will send this CTLX
1271 * to the reaper the next time it runs. We
1272 * are no longer in a hurry.
1273 */
1274 ctlx->reapable = 1;
1275 ctlx->state = CTLX_REQ_FAILED;
1276 list_move_tail(&ctlx->list, &hw->ctlxq.completing);
1277
1278 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1279
1280 if (runqueue)
1281 hfa384x_usbctlxq_run(hw);
1282 } else {
1283 if (ctlx->state == CTLX_COMPLETE) {
1284 result = completor->complete(completor);
1285 } else {
1286 netdev_warn(hw->wlandev->netdev, "CTLX[%d] error: state(%s)\n",
1287 le16_to_cpu(ctlx->outbuf.type),
1288 ctlxstr(ctlx->state));
1289 result = -EIO;
1290 }
1291
1292 list_del(&ctlx->list);
1293 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1294 kfree(ctlx);
1295 }
1296
1297 return result;
1298 }
1299
1300 /*----------------------------------------------------------------
1301 * hfa384x_docmd
1302 *
1303 * Constructs a command CTLX and submits it.
1304 *
1305 * NOTE: Any changes to the 'post-submit' code in this function
1306 * need to be carried over to hfa384x_cbcmd() since the handling
1307 * is virtually identical.
1308 *
1309 * Arguments:
1310 * hw device structure
1311 * mode DOWAIT or DOASYNC
1312 * cmd cmd structure. Includes all arguments and result
1313 * data points. All in host order. in host order
1314 * cmdcb command-specific callback
1315 * usercb user callback for async calls, NULL for DOWAIT calls
1316 * usercb_data user supplied data pointer for async calls, NULL
1317 * for DOASYNC calls
1318 *
1319 * Returns:
1320 * 0 success
1321 * -EIO CTLX failure
1322 * -ERESTARTSYS Awakened on signal
1323 * >0 command indicated error, Status and Resp0-2 are
1324 * in hw structure.
1325 *
1326 * Side effects:
1327 *
1328 *
1329 * Call context:
1330 * process
1331 ----------------------------------------------------------------*/
1332 static int
1333 hfa384x_docmd(hfa384x_t *hw,
1334 enum cmd_mode mode,
1335 hfa384x_metacmd_t *cmd,
1336 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1337 {
1338 int result;
1339 hfa384x_usbctlx_t *ctlx;
1340
1341 ctlx = usbctlx_alloc();
1342 if (ctlx == NULL) {
1343 result = -ENOMEM;
1344 goto done;
1345 }
1346
1347 /* Initialize the command */
1348 ctlx->outbuf.cmdreq.type = cpu_to_le16(HFA384x_USB_CMDREQ);
1349 ctlx->outbuf.cmdreq.cmd = cpu_to_le16(cmd->cmd);
1350 ctlx->outbuf.cmdreq.parm0 = cpu_to_le16(cmd->parm0);
1351 ctlx->outbuf.cmdreq.parm1 = cpu_to_le16(cmd->parm1);
1352 ctlx->outbuf.cmdreq.parm2 = cpu_to_le16(cmd->parm2);
1353
1354 ctlx->outbufsize = sizeof(ctlx->outbuf.cmdreq);
1355
1356 pr_debug("cmdreq: cmd=0x%04x parm0=0x%04x parm1=0x%04x parm2=0x%04x\n",
1357 cmd->cmd, cmd->parm0, cmd->parm1, cmd->parm2);
1358
1359 ctlx->reapable = mode;
1360 ctlx->cmdcb = cmdcb;
1361 ctlx->usercb = usercb;
1362 ctlx->usercb_data = usercb_data;
1363
1364 result = hfa384x_usbctlx_submit(hw, ctlx);
1365 if (result != 0) {
1366 kfree(ctlx);
1367 } else if (mode == DOWAIT) {
1368 struct usbctlx_cmd_completor completor;
1369
1370 result =
1371 hfa384x_usbctlx_complete_sync(hw, ctlx,
1372 init_cmd_completor(&completor,
1373 &ctlx->
1374 inbuf.
1375 cmdresp,
1376 &cmd->
1377 result));
1378 }
1379
1380 done:
1381 return result;
1382 }
1383
1384 /*----------------------------------------------------------------
1385 * hfa384x_dorrid
1386 *
1387 * Constructs a read rid CTLX and issues it.
1388 *
1389 * NOTE: Any changes to the 'post-submit' code in this function
1390 * need to be carried over to hfa384x_cbrrid() since the handling
1391 * is virtually identical.
1392 *
1393 * Arguments:
1394 * hw device structure
1395 * mode DOWAIT or DOASYNC
1396 * rid Read RID number (host order)
1397 * riddata Caller supplied buffer that MAC formatted RID.data
1398 * record will be written to for DOWAIT calls. Should
1399 * be NULL for DOASYNC calls.
1400 * riddatalen Buffer length for DOWAIT calls. Zero for DOASYNC calls.
1401 * cmdcb command callback for async calls, NULL for DOWAIT calls
1402 * usercb user callback for async calls, NULL for DOWAIT calls
1403 * usercb_data user supplied data pointer for async calls, NULL
1404 * for DOWAIT calls
1405 *
1406 * Returns:
1407 * 0 success
1408 * -EIO CTLX failure
1409 * -ERESTARTSYS Awakened on signal
1410 * -ENODATA riddatalen != macdatalen
1411 * >0 command indicated error, Status and Resp0-2 are
1412 * in hw structure.
1413 *
1414 * Side effects:
1415 *
1416 * Call context:
1417 * interrupt (DOASYNC)
1418 * process (DOWAIT or DOASYNC)
1419 ----------------------------------------------------------------*/
1420 static int
1421 hfa384x_dorrid(hfa384x_t *hw,
1422 enum cmd_mode mode,
1423 u16 rid,
1424 void *riddata,
1425 unsigned int riddatalen,
1426 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1427 {
1428 int result;
1429 hfa384x_usbctlx_t *ctlx;
1430
1431 ctlx = usbctlx_alloc();
1432 if (ctlx == NULL) {
1433 result = -ENOMEM;
1434 goto done;
1435 }
1436
1437 /* Initialize the command */
1438 ctlx->outbuf.rridreq.type = cpu_to_le16(HFA384x_USB_RRIDREQ);
1439 ctlx->outbuf.rridreq.frmlen =
1440 cpu_to_le16(sizeof(ctlx->outbuf.rridreq.rid));
1441 ctlx->outbuf.rridreq.rid = cpu_to_le16(rid);
1442
1443 ctlx->outbufsize = sizeof(ctlx->outbuf.rridreq);
1444
1445 ctlx->reapable = mode;
1446 ctlx->cmdcb = cmdcb;
1447 ctlx->usercb = usercb;
1448 ctlx->usercb_data = usercb_data;
1449
1450 /* Submit the CTLX */
1451 result = hfa384x_usbctlx_submit(hw, ctlx);
1452 if (result != 0) {
1453 kfree(ctlx);
1454 } else if (mode == DOWAIT) {
1455 struct usbctlx_rrid_completor completor;
1456
1457 result =
1458 hfa384x_usbctlx_complete_sync(hw, ctlx,
1459 init_rrid_completor
1460 (&completor,
1461 &ctlx->inbuf.rridresp,
1462 riddata, riddatalen));
1463 }
1464
1465 done:
1466 return result;
1467 }
1468
1469 /*----------------------------------------------------------------
1470 * hfa384x_dowrid
1471 *
1472 * Constructs a write rid CTLX and issues it.
1473 *
1474 * NOTE: Any changes to the 'post-submit' code in this function
1475 * need to be carried over to hfa384x_cbwrid() since the handling
1476 * is virtually identical.
1477 *
1478 * Arguments:
1479 * hw device structure
1480 * enum cmd_mode DOWAIT or DOASYNC
1481 * rid RID code
1482 * riddata Data portion of RID formatted for MAC
1483 * riddatalen Length of the data portion in bytes
1484 * cmdcb command callback for async calls, NULL for DOWAIT calls
1485 * usercb user callback for async calls, NULL for DOWAIT calls
1486 * usercb_data user supplied data pointer for async calls
1487 *
1488 * Returns:
1489 * 0 success
1490 * -ETIMEDOUT timed out waiting for register ready or
1491 * command completion
1492 * >0 command indicated error, Status and Resp0-2 are
1493 * in hw structure.
1494 *
1495 * Side effects:
1496 *
1497 * Call context:
1498 * interrupt (DOASYNC)
1499 * process (DOWAIT or DOASYNC)
1500 ----------------------------------------------------------------*/
1501 static int
1502 hfa384x_dowrid(hfa384x_t *hw,
1503 enum cmd_mode mode,
1504 u16 rid,
1505 void *riddata,
1506 unsigned int riddatalen,
1507 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1508 {
1509 int result;
1510 hfa384x_usbctlx_t *ctlx;
1511
1512 ctlx = usbctlx_alloc();
1513 if (ctlx == NULL) {
1514 result = -ENOMEM;
1515 goto done;
1516 }
1517
1518 /* Initialize the command */
1519 ctlx->outbuf.wridreq.type = cpu_to_le16(HFA384x_USB_WRIDREQ);
1520 ctlx->outbuf.wridreq.frmlen = cpu_to_le16((sizeof
1521 (ctlx->outbuf.wridreq.rid) +
1522 riddatalen + 1) / 2);
1523 ctlx->outbuf.wridreq.rid = cpu_to_le16(rid);
1524 memcpy(ctlx->outbuf.wridreq.data, riddata, riddatalen);
1525
1526 ctlx->outbufsize = sizeof(ctlx->outbuf.wridreq.type) +
1527 sizeof(ctlx->outbuf.wridreq.frmlen) +
1528 sizeof(ctlx->outbuf.wridreq.rid) + riddatalen;
1529
1530 ctlx->reapable = mode;
1531 ctlx->cmdcb = cmdcb;
1532 ctlx->usercb = usercb;
1533 ctlx->usercb_data = usercb_data;
1534
1535 /* Submit the CTLX */
1536 result = hfa384x_usbctlx_submit(hw, ctlx);
1537 if (result != 0) {
1538 kfree(ctlx);
1539 } else if (mode == DOWAIT) {
1540 struct usbctlx_cmd_completor completor;
1541 hfa384x_cmdresult_t wridresult;
1542
1543 result = hfa384x_usbctlx_complete_sync(hw,
1544 ctlx,
1545 init_wrid_completor
1546 (&completor,
1547 &ctlx->inbuf.wridresp,
1548 &wridresult));
1549 }
1550
1551 done:
1552 return result;
1553 }
1554
1555 /*----------------------------------------------------------------
1556 * hfa384x_dormem
1557 *
1558 * Constructs a readmem CTLX and issues it.
1559 *
1560 * NOTE: Any changes to the 'post-submit' code in this function
1561 * need to be carried over to hfa384x_cbrmem() since the handling
1562 * is virtually identical.
1563 *
1564 * Arguments:
1565 * hw device structure
1566 * mode DOWAIT or DOASYNC
1567 * page MAC address space page (CMD format)
1568 * offset MAC address space offset
1569 * data Ptr to data buffer to receive read
1570 * len Length of the data to read (max == 2048)
1571 * cmdcb command callback for async calls, NULL for DOWAIT calls
1572 * usercb user callback for async calls, NULL for DOWAIT calls
1573 * usercb_data user supplied data pointer for async calls
1574 *
1575 * Returns:
1576 * 0 success
1577 * -ETIMEDOUT timed out waiting for register ready or
1578 * command completion
1579 * >0 command indicated error, Status and Resp0-2 are
1580 * in hw structure.
1581 *
1582 * Side effects:
1583 *
1584 * Call context:
1585 * interrupt (DOASYNC)
1586 * process (DOWAIT or DOASYNC)
1587 ----------------------------------------------------------------*/
1588 static int
1589 hfa384x_dormem(hfa384x_t *hw,
1590 enum cmd_mode mode,
1591 u16 page,
1592 u16 offset,
1593 void *data,
1594 unsigned int len,
1595 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1596 {
1597 int result;
1598 hfa384x_usbctlx_t *ctlx;
1599
1600 ctlx = usbctlx_alloc();
1601 if (ctlx == NULL) {
1602 result = -ENOMEM;
1603 goto done;
1604 }
1605
1606 /* Initialize the command */
1607 ctlx->outbuf.rmemreq.type = cpu_to_le16(HFA384x_USB_RMEMREQ);
1608 ctlx->outbuf.rmemreq.frmlen =
1609 cpu_to_le16(sizeof(ctlx->outbuf.rmemreq.offset) +
1610 sizeof(ctlx->outbuf.rmemreq.page) + len);
1611 ctlx->outbuf.rmemreq.offset = cpu_to_le16(offset);
1612 ctlx->outbuf.rmemreq.page = cpu_to_le16(page);
1613
1614 ctlx->outbufsize = sizeof(ctlx->outbuf.rmemreq);
1615
1616 pr_debug("type=0x%04x frmlen=%d offset=0x%04x page=0x%04x\n",
1617 ctlx->outbuf.rmemreq.type,
1618 ctlx->outbuf.rmemreq.frmlen,
1619 ctlx->outbuf.rmemreq.offset, ctlx->outbuf.rmemreq.page);
1620
1621 pr_debug("pktsize=%zd\n", ROUNDUP64(sizeof(ctlx->outbuf.rmemreq)));
1622
1623 ctlx->reapable = mode;
1624 ctlx->cmdcb = cmdcb;
1625 ctlx->usercb = usercb;
1626 ctlx->usercb_data = usercb_data;
1627
1628 result = hfa384x_usbctlx_submit(hw, ctlx);
1629 if (result != 0) {
1630 kfree(ctlx);
1631 } else if (mode == DOWAIT) {
1632 struct usbctlx_rmem_completor completor;
1633
1634 result =
1635 hfa384x_usbctlx_complete_sync(hw, ctlx,
1636 init_rmem_completor
1637 (&completor,
1638 &ctlx->inbuf.rmemresp, data,
1639 len));
1640 }
1641
1642 done:
1643 return result;
1644 }
1645
1646 /*----------------------------------------------------------------
1647 * hfa384x_dowmem
1648 *
1649 * Constructs a writemem CTLX and issues it.
1650 *
1651 * NOTE: Any changes to the 'post-submit' code in this function
1652 * need to be carried over to hfa384x_cbwmem() since the handling
1653 * is virtually identical.
1654 *
1655 * Arguments:
1656 * hw device structure
1657 * mode DOWAIT or DOASYNC
1658 * page MAC address space page (CMD format)
1659 * offset MAC address space offset
1660 * data Ptr to data buffer containing write data
1661 * len Length of the data to read (max == 2048)
1662 * cmdcb command callback for async calls, NULL for DOWAIT calls
1663 * usercb user callback for async calls, NULL for DOWAIT calls
1664 * usercb_data user supplied data pointer for async calls.
1665 *
1666 * Returns:
1667 * 0 success
1668 * -ETIMEDOUT timed out waiting for register ready or
1669 * command completion
1670 * >0 command indicated error, Status and Resp0-2 are
1671 * in hw structure.
1672 *
1673 * Side effects:
1674 *
1675 * Call context:
1676 * interrupt (DOWAIT)
1677 * process (DOWAIT or DOASYNC)
1678 ----------------------------------------------------------------*/
1679 static int
1680 hfa384x_dowmem(hfa384x_t *hw,
1681 enum cmd_mode mode,
1682 u16 page,
1683 u16 offset,
1684 void *data,
1685 unsigned int len,
1686 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
1687 {
1688 int result;
1689 hfa384x_usbctlx_t *ctlx;
1690
1691 pr_debug("page=0x%04x offset=0x%04x len=%d\n", page, offset, len);
1692
1693 ctlx = usbctlx_alloc();
1694 if (ctlx == NULL) {
1695 result = -ENOMEM;
1696 goto done;
1697 }
1698
1699 /* Initialize the command */
1700 ctlx->outbuf.wmemreq.type = cpu_to_le16(HFA384x_USB_WMEMREQ);
1701 ctlx->outbuf.wmemreq.frmlen =
1702 cpu_to_le16(sizeof(ctlx->outbuf.wmemreq.offset) +
1703 sizeof(ctlx->outbuf.wmemreq.page) + len);
1704 ctlx->outbuf.wmemreq.offset = cpu_to_le16(offset);
1705 ctlx->outbuf.wmemreq.page = cpu_to_le16(page);
1706 memcpy(ctlx->outbuf.wmemreq.data, data, len);
1707
1708 ctlx->outbufsize = sizeof(ctlx->outbuf.wmemreq.type) +
1709 sizeof(ctlx->outbuf.wmemreq.frmlen) +
1710 sizeof(ctlx->outbuf.wmemreq.offset) +
1711 sizeof(ctlx->outbuf.wmemreq.page) + len;
1712
1713 ctlx->reapable = mode;
1714 ctlx->cmdcb = cmdcb;
1715 ctlx->usercb = usercb;
1716 ctlx->usercb_data = usercb_data;
1717
1718 result = hfa384x_usbctlx_submit(hw, ctlx);
1719 if (result != 0) {
1720 kfree(ctlx);
1721 } else if (mode == DOWAIT) {
1722 struct usbctlx_cmd_completor completor;
1723 hfa384x_cmdresult_t wmemresult;
1724
1725 result = hfa384x_usbctlx_complete_sync(hw,
1726 ctlx,
1727 init_wmem_completor
1728 (&completor,
1729 &ctlx->inbuf.wmemresp,
1730 &wmemresult));
1731 }
1732
1733 done:
1734 return result;
1735 }
1736
1737 /*----------------------------------------------------------------
1738 * hfa384x_drvr_disable
1739 *
1740 * Issues the disable command to stop communications on one of
1741 * the MACs 'ports'. Only macport 0 is valid for stations.
1742 * APs may also disable macports 1-6. Only ports that have been
1743 * previously enabled may be disabled.
1744 *
1745 * Arguments:
1746 * hw device structure
1747 * macport MAC port number (host order)
1748 *
1749 * Returns:
1750 * 0 success
1751 * >0 f/w reported failure - f/w status code
1752 * <0 driver reported error (timeout|bad arg)
1753 *
1754 * Side effects:
1755 *
1756 * Call context:
1757 * process
1758 ----------------------------------------------------------------*/
1759 int hfa384x_drvr_disable(hfa384x_t *hw, u16 macport)
1760 {
1761 int result = 0;
1762
1763 if ((!hw->isap && macport != 0) ||
1764 (hw->isap && !(macport <= HFA384x_PORTID_MAX)) ||
1765 !(hw->port_enabled[macport])) {
1766 result = -EINVAL;
1767 } else {
1768 result = hfa384x_cmd_disable(hw, macport);
1769 if (result == 0)
1770 hw->port_enabled[macport] = 0;
1771 }
1772 return result;
1773 }
1774
1775 /*----------------------------------------------------------------
1776 * hfa384x_drvr_enable
1777 *
1778 * Issues the enable command to enable communications on one of
1779 * the MACs 'ports'. Only macport 0 is valid for stations.
1780 * APs may also enable macports 1-6. Only ports that are currently
1781 * disabled may be enabled.
1782 *
1783 * Arguments:
1784 * hw device structure
1785 * macport MAC port number
1786 *
1787 * Returns:
1788 * 0 success
1789 * >0 f/w reported failure - f/w status code
1790 * <0 driver reported error (timeout|bad arg)
1791 *
1792 * Side effects:
1793 *
1794 * Call context:
1795 * process
1796 ----------------------------------------------------------------*/
1797 int hfa384x_drvr_enable(hfa384x_t *hw, u16 macport)
1798 {
1799 int result = 0;
1800
1801 if ((!hw->isap && macport != 0) ||
1802 (hw->isap && !(macport <= HFA384x_PORTID_MAX)) ||
1803 (hw->port_enabled[macport])) {
1804 result = -EINVAL;
1805 } else {
1806 result = hfa384x_cmd_enable(hw, macport);
1807 if (result == 0)
1808 hw->port_enabled[macport] = 1;
1809 }
1810 return result;
1811 }
1812
1813 /*----------------------------------------------------------------
1814 * hfa384x_drvr_flashdl_enable
1815 *
1816 * Begins the flash download state. Checks to see that we're not
1817 * already in a download state and that a port isn't enabled.
1818 * Sets the download state and retrieves the flash download
1819 * buffer location, buffer size, and timeout length.
1820 *
1821 * Arguments:
1822 * hw device structure
1823 *
1824 * Returns:
1825 * 0 success
1826 * >0 f/w reported error - f/w status code
1827 * <0 driver reported error
1828 *
1829 * Side effects:
1830 *
1831 * Call context:
1832 * process
1833 ----------------------------------------------------------------*/
1834 int hfa384x_drvr_flashdl_enable(hfa384x_t *hw)
1835 {
1836 int result = 0;
1837 int i;
1838
1839 /* Check that a port isn't active */
1840 for (i = 0; i < HFA384x_PORTID_MAX; i++) {
1841 if (hw->port_enabled[i]) {
1842 pr_debug("called when port enabled.\n");
1843 return -EINVAL;
1844 }
1845 }
1846
1847 /* Check that we're not already in a download state */
1848 if (hw->dlstate != HFA384x_DLSTATE_DISABLED)
1849 return -EINVAL;
1850
1851 /* Retrieve the buffer loc&size and timeout */
1852 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_DOWNLOADBUFFER,
1853 &(hw->bufinfo), sizeof(hw->bufinfo));
1854 if (result)
1855 return result;
1856
1857 hw->bufinfo.page = le16_to_cpu(hw->bufinfo.page);
1858 hw->bufinfo.offset = le16_to_cpu(hw->bufinfo.offset);
1859 hw->bufinfo.len = le16_to_cpu(hw->bufinfo.len);
1860 result = hfa384x_drvr_getconfig16(hw, HFA384x_RID_MAXLOADTIME,
1861 &(hw->dltimeout));
1862 if (result)
1863 return result;
1864
1865 hw->dltimeout = le16_to_cpu(hw->dltimeout);
1866
1867 pr_debug("flashdl_enable\n");
1868
1869 hw->dlstate = HFA384x_DLSTATE_FLASHENABLED;
1870
1871 return result;
1872 }
1873
1874 /*----------------------------------------------------------------
1875 * hfa384x_drvr_flashdl_disable
1876 *
1877 * Ends the flash download state. Note that this will cause the MAC
1878 * firmware to restart.
1879 *
1880 * Arguments:
1881 * hw device structure
1882 *
1883 * Returns:
1884 * 0 success
1885 * >0 f/w reported error - f/w status code
1886 * <0 driver reported error
1887 *
1888 * Side effects:
1889 *
1890 * Call context:
1891 * process
1892 ----------------------------------------------------------------*/
1893 int hfa384x_drvr_flashdl_disable(hfa384x_t *hw)
1894 {
1895 /* Check that we're already in the download state */
1896 if (hw->dlstate != HFA384x_DLSTATE_FLASHENABLED)
1897 return -EINVAL;
1898
1899 pr_debug("flashdl_enable\n");
1900
1901 /* There isn't much we can do at this point, so I don't */
1902 /* bother w/ the return value */
1903 hfa384x_cmd_download(hw, HFA384x_PROGMODE_DISABLE, 0, 0, 0);
1904 hw->dlstate = HFA384x_DLSTATE_DISABLED;
1905
1906 return 0;
1907 }
1908
1909 /*----------------------------------------------------------------
1910 * hfa384x_drvr_flashdl_write
1911 *
1912 * Performs a FLASH download of a chunk of data. First checks to see
1913 * that we're in the FLASH download state, then sets the download
1914 * mode, uses the aux functions to 1) copy the data to the flash
1915 * buffer, 2) sets the download 'write flash' mode, 3) readback and
1916 * compare. Lather rinse, repeat as many times an necessary to get
1917 * all the given data into flash.
1918 * When all data has been written using this function (possibly
1919 * repeatedly), call drvr_flashdl_disable() to end the download state
1920 * and restart the MAC.
1921 *
1922 * Arguments:
1923 * hw device structure
1924 * daddr Card address to write to. (host order)
1925 * buf Ptr to data to write.
1926 * len Length of data (host order).
1927 *
1928 * Returns:
1929 * 0 success
1930 * >0 f/w reported error - f/w status code
1931 * <0 driver reported error
1932 *
1933 * Side effects:
1934 *
1935 * Call context:
1936 * process
1937 ----------------------------------------------------------------*/
1938 int hfa384x_drvr_flashdl_write(hfa384x_t *hw, u32 daddr, void *buf, u32 len)
1939 {
1940 int result = 0;
1941 u32 dlbufaddr;
1942 int nburns;
1943 u32 burnlen;
1944 u32 burndaddr;
1945 u16 burnlo;
1946 u16 burnhi;
1947 int nwrites;
1948 u8 *writebuf;
1949 u16 writepage;
1950 u16 writeoffset;
1951 u32 writelen;
1952 int i;
1953 int j;
1954
1955 pr_debug("daddr=0x%08x len=%d\n", daddr, len);
1956
1957 /* Check that we're in the flash download state */
1958 if (hw->dlstate != HFA384x_DLSTATE_FLASHENABLED)
1959 return -EINVAL;
1960
1961 netdev_info(hw->wlandev->netdev,
1962 "Download %d bytes to flash @0x%06x\n", len, daddr);
1963
1964 /* Convert to flat address for arithmetic */
1965 /* NOTE: dlbuffer RID stores the address in AUX format */
1966 dlbufaddr =
1967 HFA384x_ADDR_AUX_MKFLAT(hw->bufinfo.page, hw->bufinfo.offset);
1968 pr_debug("dlbuf.page=0x%04x dlbuf.offset=0x%04x dlbufaddr=0x%08x\n",
1969 hw->bufinfo.page, hw->bufinfo.offset, dlbufaddr);
1970 /* Calculations to determine how many fills of the dlbuffer to do
1971 * and how many USB wmemreq's to do for each fill. At this point
1972 * in time, the dlbuffer size and the wmemreq size are the same.
1973 * Therefore, nwrites should always be 1. The extra complexity
1974 * here is a hedge against future changes.
1975 */
1976
1977 /* Figure out how many times to do the flash programming */
1978 nburns = len / hw->bufinfo.len;
1979 nburns += (len % hw->bufinfo.len) ? 1 : 0;
1980
1981 /* For each flash program cycle, how many USB wmemreq's are needed? */
1982 nwrites = hw->bufinfo.len / HFA384x_USB_RWMEM_MAXLEN;
1983 nwrites += (hw->bufinfo.len % HFA384x_USB_RWMEM_MAXLEN) ? 1 : 0;
1984
1985 /* For each burn */
1986 for (i = 0; i < nburns; i++) {
1987 /* Get the dest address and len */
1988 burnlen = (len - (hw->bufinfo.len * i)) > hw->bufinfo.len ?
1989 hw->bufinfo.len : (len - (hw->bufinfo.len * i));
1990 burndaddr = daddr + (hw->bufinfo.len * i);
1991 burnlo = HFA384x_ADDR_CMD_MKOFF(burndaddr);
1992 burnhi = HFA384x_ADDR_CMD_MKPAGE(burndaddr);
1993
1994 netdev_info(hw->wlandev->netdev, "Writing %d bytes to flash @0x%06x\n",
1995 burnlen, burndaddr);
1996
1997 /* Set the download mode */
1998 result = hfa384x_cmd_download(hw, HFA384x_PROGMODE_NV,
1999 burnlo, burnhi, burnlen);
2000 if (result) {
2001 netdev_err(hw->wlandev->netdev,
2002 "download(NV,lo=%x,hi=%x,len=%x) cmd failed, result=%d. Aborting d/l\n",
2003 burnlo, burnhi, burnlen, result);
2004 goto exit_proc;
2005 }
2006
2007 /* copy the data to the flash download buffer */
2008 for (j = 0; j < nwrites; j++) {
2009 writebuf = buf +
2010 (i * hw->bufinfo.len) +
2011 (j * HFA384x_USB_RWMEM_MAXLEN);
2012
2013 writepage = HFA384x_ADDR_CMD_MKPAGE(dlbufaddr +
2014 (j * HFA384x_USB_RWMEM_MAXLEN));
2015 writeoffset = HFA384x_ADDR_CMD_MKOFF(dlbufaddr +
2016 (j * HFA384x_USB_RWMEM_MAXLEN));
2017
2018 writelen = burnlen - (j * HFA384x_USB_RWMEM_MAXLEN);
2019 writelen = writelen > HFA384x_USB_RWMEM_MAXLEN ?
2020 HFA384x_USB_RWMEM_MAXLEN : writelen;
2021
2022 result = hfa384x_dowmem_wait(hw,
2023 writepage,
2024 writeoffset,
2025 writebuf, writelen);
2026 }
2027
2028 /* set the download 'write flash' mode */
2029 result = hfa384x_cmd_download(hw,
2030 HFA384x_PROGMODE_NVWRITE,
2031 0, 0, 0);
2032 if (result) {
2033 netdev_err(hw->wlandev->netdev,
2034 "download(NVWRITE,lo=%x,hi=%x,len=%x) cmd failed, result=%d. Aborting d/l\n",
2035 burnlo, burnhi, burnlen, result);
2036 goto exit_proc;
2037 }
2038
2039 /* TODO: We really should do a readback and compare. */
2040 }
2041
2042 exit_proc:
2043
2044 /* Leave the firmware in the 'post-prog' mode. flashdl_disable will */
2045 /* actually disable programming mode. Remember, that will cause the */
2046 /* the firmware to effectively reset itself. */
2047
2048 return result;
2049 }
2050
2051 /*----------------------------------------------------------------
2052 * hfa384x_drvr_getconfig
2053 *
2054 * Performs the sequence necessary to read a config/info item.
2055 *
2056 * Arguments:
2057 * hw device structure
2058 * rid config/info record id (host order)
2059 * buf host side record buffer. Upon return it will
2060 * contain the body portion of the record (minus the
2061 * RID and len).
2062 * len buffer length (in bytes, should match record length)
2063 *
2064 * Returns:
2065 * 0 success
2066 * >0 f/w reported error - f/w status code
2067 * <0 driver reported error
2068 * -ENODATA length mismatch between argument and retrieved
2069 * record.
2070 *
2071 * Side effects:
2072 *
2073 * Call context:
2074 * process
2075 ----------------------------------------------------------------*/
2076 int hfa384x_drvr_getconfig(hfa384x_t *hw, u16 rid, void *buf, u16 len)
2077 {
2078 return hfa384x_dorrid_wait(hw, rid, buf, len);
2079 }
2080
2081 /*----------------------------------------------------------------
2082 * hfa384x_drvr_getconfig_async
2083 *
2084 * Performs the sequence necessary to perform an async read of
2085 * of a config/info item.
2086 *
2087 * Arguments:
2088 * hw device structure
2089 * rid config/info record id (host order)
2090 * buf host side record buffer. Upon return it will
2091 * contain the body portion of the record (minus the
2092 * RID and len).
2093 * len buffer length (in bytes, should match record length)
2094 * cbfn caller supplied callback, called when the command
2095 * is done (successful or not).
2096 * cbfndata pointer to some caller supplied data that will be
2097 * passed in as an argument to the cbfn.
2098 *
2099 * Returns:
2100 * nothing the cbfn gets a status argument identifying if
2101 * any errors occur.
2102 * Side effects:
2103 * Queues an hfa384x_usbcmd_t for subsequent execution.
2104 *
2105 * Call context:
2106 * Any
2107 ----------------------------------------------------------------*/
2108 int
2109 hfa384x_drvr_getconfig_async(hfa384x_t *hw,
2110 u16 rid, ctlx_usercb_t usercb, void *usercb_data)
2111 {
2112 return hfa384x_dorrid_async(hw, rid, NULL, 0,
2113 hfa384x_cb_rrid, usercb, usercb_data);
2114 }
2115
2116 /*----------------------------------------------------------------
2117 * hfa384x_drvr_setconfig_async
2118 *
2119 * Performs the sequence necessary to write a config/info item.
2120 *
2121 * Arguments:
2122 * hw device structure
2123 * rid config/info record id (in host order)
2124 * buf host side record buffer
2125 * len buffer length (in bytes)
2126 * usercb completion callback
2127 * usercb_data completion callback argument
2128 *
2129 * Returns:
2130 * 0 success
2131 * >0 f/w reported error - f/w status code
2132 * <0 driver reported error
2133 *
2134 * Side effects:
2135 *
2136 * Call context:
2137 * process
2138 ----------------------------------------------------------------*/
2139 int
2140 hfa384x_drvr_setconfig_async(hfa384x_t *hw,
2141 u16 rid,
2142 void *buf,
2143 u16 len, ctlx_usercb_t usercb, void *usercb_data)
2144 {
2145 return hfa384x_dowrid_async(hw, rid, buf, len,
2146 hfa384x_cb_status, usercb, usercb_data);
2147 }
2148
2149 /*----------------------------------------------------------------
2150 * hfa384x_drvr_ramdl_disable
2151 *
2152 * Ends the ram download state.
2153 *
2154 * Arguments:
2155 * hw device structure
2156 *
2157 * Returns:
2158 * 0 success
2159 * >0 f/w reported error - f/w status code
2160 * <0 driver reported error
2161 *
2162 * Side effects:
2163 *
2164 * Call context:
2165 * process
2166 ----------------------------------------------------------------*/
2167 int hfa384x_drvr_ramdl_disable(hfa384x_t *hw)
2168 {
2169 /* Check that we're already in the download state */
2170 if (hw->dlstate != HFA384x_DLSTATE_RAMENABLED)
2171 return -EINVAL;
2172
2173 pr_debug("ramdl_disable()\n");
2174
2175 /* There isn't much we can do at this point, so I don't */
2176 /* bother w/ the return value */
2177 hfa384x_cmd_download(hw, HFA384x_PROGMODE_DISABLE, 0, 0, 0);
2178 hw->dlstate = HFA384x_DLSTATE_DISABLED;
2179
2180 return 0;
2181 }
2182
2183 /*----------------------------------------------------------------
2184 * hfa384x_drvr_ramdl_enable
2185 *
2186 * Begins the ram download state. Checks to see that we're not
2187 * already in a download state and that a port isn't enabled.
2188 * Sets the download state and calls cmd_download with the
2189 * ENABLE_VOLATILE subcommand and the exeaddr argument.
2190 *
2191 * Arguments:
2192 * hw device structure
2193 * exeaddr the card execution address that will be
2194 * jumped to when ramdl_disable() is called
2195 * (host order).
2196 *
2197 * Returns:
2198 * 0 success
2199 * >0 f/w reported error - f/w status code
2200 * <0 driver reported error
2201 *
2202 * Side effects:
2203 *
2204 * Call context:
2205 * process
2206 ----------------------------------------------------------------*/
2207 int hfa384x_drvr_ramdl_enable(hfa384x_t *hw, u32 exeaddr)
2208 {
2209 int result = 0;
2210 u16 lowaddr;
2211 u16 hiaddr;
2212 int i;
2213
2214 /* Check that a port isn't active */
2215 for (i = 0; i < HFA384x_PORTID_MAX; i++) {
2216 if (hw->port_enabled[i]) {
2217 netdev_err(hw->wlandev->netdev,
2218 "Can't download with a macport enabled.\n");
2219 return -EINVAL;
2220 }
2221 }
2222
2223 /* Check that we're not already in a download state */
2224 if (hw->dlstate != HFA384x_DLSTATE_DISABLED) {
2225 netdev_err(hw->wlandev->netdev, "Download state not disabled.\n");
2226 return -EINVAL;
2227 }
2228
2229 pr_debug("ramdl_enable, exeaddr=0x%08x\n", exeaddr);
2230
2231 /* Call the download(1,addr) function */
2232 lowaddr = HFA384x_ADDR_CMD_MKOFF(exeaddr);
2233 hiaddr = HFA384x_ADDR_CMD_MKPAGE(exeaddr);
2234
2235 result = hfa384x_cmd_download(hw, HFA384x_PROGMODE_RAM,
2236 lowaddr, hiaddr, 0);
2237
2238 if (result == 0) {
2239 /* Set the download state */
2240 hw->dlstate = HFA384x_DLSTATE_RAMENABLED;
2241 } else {
2242 pr_debug("cmd_download(0x%04x, 0x%04x) failed, result=%d.\n",
2243 lowaddr, hiaddr, result);
2244 }
2245
2246 return result;
2247 }
2248
2249 /*----------------------------------------------------------------
2250 * hfa384x_drvr_ramdl_write
2251 *
2252 * Performs a RAM download of a chunk of data. First checks to see
2253 * that we're in the RAM download state, then uses the [read|write]mem USB
2254 * commands to 1) copy the data, 2) readback and compare. The download
2255 * state is unaffected. When all data has been written using
2256 * this function, call drvr_ramdl_disable() to end the download state
2257 * and restart the MAC.
2258 *
2259 * Arguments:
2260 * hw device structure
2261 * daddr Card address to write to. (host order)
2262 * buf Ptr to data to write.
2263 * len Length of data (host order).
2264 *
2265 * Returns:
2266 * 0 success
2267 * >0 f/w reported error - f/w status code
2268 * <0 driver reported error
2269 *
2270 * Side effects:
2271 *
2272 * Call context:
2273 * process
2274 ----------------------------------------------------------------*/
2275 int hfa384x_drvr_ramdl_write(hfa384x_t *hw, u32 daddr, void *buf, u32 len)
2276 {
2277 int result = 0;
2278 int nwrites;
2279 u8 *data = buf;
2280 int i;
2281 u32 curraddr;
2282 u16 currpage;
2283 u16 curroffset;
2284 u16 currlen;
2285
2286 /* Check that we're in the ram download state */
2287 if (hw->dlstate != HFA384x_DLSTATE_RAMENABLED)
2288 return -EINVAL;
2289
2290 netdev_info(hw->wlandev->netdev, "Writing %d bytes to ram @0x%06x\n",
2291 len, daddr);
2292
2293 /* How many dowmem calls? */
2294 nwrites = len / HFA384x_USB_RWMEM_MAXLEN;
2295 nwrites += len % HFA384x_USB_RWMEM_MAXLEN ? 1 : 0;
2296
2297 /* Do blocking wmem's */
2298 for (i = 0; i < nwrites; i++) {
2299 /* make address args */
2300 curraddr = daddr + (i * HFA384x_USB_RWMEM_MAXLEN);
2301 currpage = HFA384x_ADDR_CMD_MKPAGE(curraddr);
2302 curroffset = HFA384x_ADDR_CMD_MKOFF(curraddr);
2303 currlen = len - (i * HFA384x_USB_RWMEM_MAXLEN);
2304 if (currlen > HFA384x_USB_RWMEM_MAXLEN)
2305 currlen = HFA384x_USB_RWMEM_MAXLEN;
2306
2307 /* Do blocking ctlx */
2308 result = hfa384x_dowmem_wait(hw,
2309 currpage,
2310 curroffset,
2311 data +
2312 (i * HFA384x_USB_RWMEM_MAXLEN),
2313 currlen);
2314
2315 if (result)
2316 break;
2317
2318 /* TODO: We really should have a readback. */
2319 }
2320
2321 return result;
2322 }
2323
2324 /*----------------------------------------------------------------
2325 * hfa384x_drvr_readpda
2326 *
2327 * Performs the sequence to read the PDA space. Note there is no
2328 * drvr_writepda() function. Writing a PDA is
2329 * generally implemented by a calling component via calls to
2330 * cmd_download and writing to the flash download buffer via the
2331 * aux regs.
2332 *
2333 * Arguments:
2334 * hw device structure
2335 * buf buffer to store PDA in
2336 * len buffer length
2337 *
2338 * Returns:
2339 * 0 success
2340 * >0 f/w reported error - f/w status code
2341 * <0 driver reported error
2342 * -ETIMEDOUT timeout waiting for the cmd regs to become
2343 * available, or waiting for the control reg
2344 * to indicate the Aux port is enabled.
2345 * -ENODATA the buffer does NOT contain a valid PDA.
2346 * Either the card PDA is bad, or the auxdata
2347 * reads are giving us garbage.
2348
2349 *
2350 * Side effects:
2351 *
2352 * Call context:
2353 * process or non-card interrupt.
2354 ----------------------------------------------------------------*/
2355 int hfa384x_drvr_readpda(hfa384x_t *hw, void *buf, unsigned int len)
2356 {
2357 int result = 0;
2358 u16 *pda = buf;
2359 int pdaok = 0;
2360 int morepdrs = 1;
2361 int currpdr = 0; /* word offset of the current pdr */
2362 size_t i;
2363 u16 pdrlen; /* pdr length in bytes, host order */
2364 u16 pdrcode; /* pdr code, host order */
2365 u16 currpage;
2366 u16 curroffset;
2367 struct pdaloc {
2368 u32 cardaddr;
2369 u16 auxctl;
2370 } pdaloc[] = {
2371 {
2372 HFA3842_PDA_BASE, 0}, {
2373 HFA3841_PDA_BASE, 0}, {
2374 HFA3841_PDA_BOGUS_BASE, 0}
2375 };
2376
2377 /* Read the pda from each known address. */
2378 for (i = 0; i < ARRAY_SIZE(pdaloc); i++) {
2379 /* Make address */
2380 currpage = HFA384x_ADDR_CMD_MKPAGE(pdaloc[i].cardaddr);
2381 curroffset = HFA384x_ADDR_CMD_MKOFF(pdaloc[i].cardaddr);
2382
2383 /* units of bytes */
2384 result = hfa384x_dormem_wait(hw, currpage, curroffset, buf,
2385 len);
2386
2387 if (result) {
2388 netdev_warn(hw->wlandev->netdev,
2389 "Read from index %zd failed, continuing\n",
2390 i);
2391 continue;
2392 }
2393
2394 /* Test for garbage */
2395 pdaok = 1; /* initially assume good */
2396 morepdrs = 1;
2397 while (pdaok && morepdrs) {
2398 pdrlen = le16_to_cpu(pda[currpdr]) * 2;
2399 pdrcode = le16_to_cpu(pda[currpdr + 1]);
2400 /* Test the record length */
2401 if (pdrlen > HFA384x_PDR_LEN_MAX || pdrlen == 0) {
2402 netdev_err(hw->wlandev->netdev,
2403 "pdrlen invalid=%d\n", pdrlen);
2404 pdaok = 0;
2405 break;
2406 }
2407 /* Test the code */
2408 if (!hfa384x_isgood_pdrcode(pdrcode)) {
2409 netdev_err(hw->wlandev->netdev, "pdrcode invalid=%d\n",
2410 pdrcode);
2411 pdaok = 0;
2412 break;
2413 }
2414 /* Test for completion */
2415 if (pdrcode == HFA384x_PDR_END_OF_PDA)
2416 morepdrs = 0;
2417
2418 /* Move to the next pdr (if necessary) */
2419 if (morepdrs) {
2420 /* note the access to pda[], need words here */
2421 currpdr += le16_to_cpu(pda[currpdr]) + 1;
2422 }
2423 }
2424 if (pdaok) {
2425 netdev_info(hw->wlandev->netdev,
2426 "PDA Read from 0x%08x in %s space.\n",
2427 pdaloc[i].cardaddr,
2428 pdaloc[i].auxctl == 0 ? "EXTDS" :
2429 pdaloc[i].auxctl == 1 ? "NV" :
2430 pdaloc[i].auxctl == 2 ? "PHY" :
2431 pdaloc[i].auxctl == 3 ? "ICSRAM" :
2432 "<bogus auxctl>");
2433 break;
2434 }
2435 }
2436 result = pdaok ? 0 : -ENODATA;
2437
2438 if (result)
2439 pr_debug("Failure: pda is not okay\n");
2440
2441 return result;
2442 }
2443
2444 /*----------------------------------------------------------------
2445 * hfa384x_drvr_setconfig
2446 *
2447 * Performs the sequence necessary to write a config/info item.
2448 *
2449 * Arguments:
2450 * hw device structure
2451 * rid config/info record id (in host order)
2452 * buf host side record buffer
2453 * len buffer length (in bytes)
2454 *
2455 * Returns:
2456 * 0 success
2457 * >0 f/w reported error - f/w status code
2458 * <0 driver reported error
2459 *
2460 * Side effects:
2461 *
2462 * Call context:
2463 * process
2464 ----------------------------------------------------------------*/
2465 int hfa384x_drvr_setconfig(hfa384x_t *hw, u16 rid, void *buf, u16 len)
2466 {
2467 return hfa384x_dowrid_wait(hw, rid, buf, len);
2468 }
2469
2470 /*----------------------------------------------------------------
2471 * hfa384x_drvr_start
2472 *
2473 * Issues the MAC initialize command, sets up some data structures,
2474 * and enables the interrupts. After this function completes, the
2475 * low-level stuff should be ready for any/all commands.
2476 *
2477 * Arguments:
2478 * hw device structure
2479 * Returns:
2480 * 0 success
2481 * >0 f/w reported error - f/w status code
2482 * <0 driver reported error
2483 *
2484 * Side effects:
2485 *
2486 * Call context:
2487 * process
2488 ----------------------------------------------------------------*/
2489
2490 int hfa384x_drvr_start(hfa384x_t *hw)
2491 {
2492 int result, result1, result2;
2493 u16 status;
2494
2495 might_sleep();
2496
2497 /* Clear endpoint stalls - but only do this if the endpoint
2498 * is showing a stall status. Some prism2 cards seem to behave
2499 * badly if a clear_halt is called when the endpoint is already
2500 * ok
2501 */
2502 result =
2503 usb_get_status(hw->usb, USB_RECIP_ENDPOINT, hw->endp_in, &status);
2504 if (result < 0) {
2505 netdev_err(hw->wlandev->netdev, "Cannot get bulk in endpoint status.\n");
2506 goto done;
2507 }
2508 if ((status == 1) && usb_clear_halt(hw->usb, hw->endp_in))
2509 netdev_err(hw->wlandev->netdev, "Failed to reset bulk in endpoint.\n");
2510
2511 result =
2512 usb_get_status(hw->usb, USB_RECIP_ENDPOINT, hw->endp_out, &status);
2513 if (result < 0) {
2514 netdev_err(hw->wlandev->netdev, "Cannot get bulk out endpoint status.\n");
2515 goto done;
2516 }
2517 if ((status == 1) && usb_clear_halt(hw->usb, hw->endp_out))
2518 netdev_err(hw->wlandev->netdev, "Failed to reset bulk out endpoint.\n");
2519
2520 /* Synchronous unlink, in case we're trying to restart the driver */
2521 usb_kill_urb(&hw->rx_urb);
2522
2523 /* Post the IN urb */
2524 result = submit_rx_urb(hw, GFP_KERNEL);
2525 if (result != 0) {
2526 netdev_err(hw->wlandev->netdev,
2527 "Fatal, failed to submit RX URB, result=%d\n",
2528 result);
2529 goto done;
2530 }
2531
2532 /* Call initialize twice, with a 1 second sleep in between.
2533 * This is a nasty work-around since many prism2 cards seem to
2534 * need time to settle after an init from cold. The second
2535 * call to initialize in theory is not necessary - but we call
2536 * it anyway as a double insurance policy:
2537 * 1) If the first init should fail, the second may well succeed
2538 * and the card can still be used
2539 * 2) It helps ensures all is well with the card after the first
2540 * init and settle time.
2541 */
2542 result1 = hfa384x_cmd_initialize(hw);
2543 msleep(1000);
2544 result = hfa384x_cmd_initialize(hw);
2545 result2 = result;
2546 if (result1 != 0) {
2547 if (result2 != 0) {
2548 netdev_err(hw->wlandev->netdev,
2549 "cmd_initialize() failed on two attempts, results %d and %d\n",
2550 result1, result2);
2551 usb_kill_urb(&hw->rx_urb);
2552 goto done;
2553 } else {
2554 pr_debug("First cmd_initialize() failed (result %d),\n",
2555 result1);
2556 pr_debug("but second attempt succeeded. All should be ok\n");
2557 }
2558 } else if (result2 != 0) {
2559 netdev_warn(hw->wlandev->netdev, "First cmd_initialize() succeeded, but second attempt failed (result=%d)\n",
2560 result2);
2561 netdev_warn(hw->wlandev->netdev,
2562 "Most likely the card will be functional\n");
2563 goto done;
2564 }
2565
2566 hw->state = HFA384x_STATE_RUNNING;
2567
2568 done:
2569 return result;
2570 }
2571
2572 /*----------------------------------------------------------------
2573 * hfa384x_drvr_stop
2574 *
2575 * Shuts down the MAC to the point where it is safe to unload the
2576 * driver. Any subsystem that may be holding a data or function
2577 * ptr into the driver must be cleared/deinitialized.
2578 *
2579 * Arguments:
2580 * hw device structure
2581 * Returns:
2582 * 0 success
2583 * >0 f/w reported error - f/w status code
2584 * <0 driver reported error
2585 *
2586 * Side effects:
2587 *
2588 * Call context:
2589 * process
2590 ----------------------------------------------------------------*/
2591 int hfa384x_drvr_stop(hfa384x_t *hw)
2592 {
2593 int i;
2594
2595 might_sleep();
2596
2597 /* There's no need for spinlocks here. The USB "disconnect"
2598 * function sets this "removed" flag and then calls us.
2599 */
2600 if (!hw->wlandev->hwremoved) {
2601 /* Call initialize to leave the MAC in its 'reset' state */
2602 hfa384x_cmd_initialize(hw);
2603
2604 /* Cancel the rxurb */
2605 usb_kill_urb(&hw->rx_urb);
2606 }
2607
2608 hw->link_status = HFA384x_LINK_NOTCONNECTED;
2609 hw->state = HFA384x_STATE_INIT;
2610
2611 del_timer_sync(&hw->commsqual_timer);
2612
2613 /* Clear all the port status */
2614 for (i = 0; i < HFA384x_NUMPORTS_MAX; i++)
2615 hw->port_enabled[i] = 0;
2616
2617 return 0;
2618 }
2619
2620 /*----------------------------------------------------------------
2621 * hfa384x_drvr_txframe
2622 *
2623 * Takes a frame from prism2sta and queues it for transmission.
2624 *
2625 * Arguments:
2626 * hw device structure
2627 * skb packet buffer struct. Contains an 802.11
2628 * data frame.
2629 * p80211_hdr points to the 802.11 header for the packet.
2630 * Returns:
2631 * 0 Success and more buffs available
2632 * 1 Success but no more buffs
2633 * 2 Allocation failure
2634 * 4 Buffer full or queue busy
2635 *
2636 * Side effects:
2637 *
2638 * Call context:
2639 * interrupt
2640 ----------------------------------------------------------------*/
2641 int hfa384x_drvr_txframe(hfa384x_t *hw, struct sk_buff *skb,
2642 union p80211_hdr *p80211_hdr,
2643 struct p80211_metawep *p80211_wep)
2644 {
2645 int usbpktlen = sizeof(hfa384x_tx_frame_t);
2646 int result;
2647 int ret;
2648 char *ptr;
2649
2650 if (hw->tx_urb.status == -EINPROGRESS) {
2651 netdev_warn(hw->wlandev->netdev, "TX URB already in use\n");
2652 result = 3;
2653 goto exit;
2654 }
2655
2656 /* Build Tx frame structure */
2657 /* Set up the control field */
2658 memset(&hw->txbuff.txfrm.desc, 0, sizeof(hw->txbuff.txfrm.desc));
2659
2660 /* Setup the usb type field */
2661 hw->txbuff.type = cpu_to_le16(HFA384x_USB_TXFRM);
2662
2663 /* Set up the sw_support field to identify this frame */
2664 hw->txbuff.txfrm.desc.sw_support = 0x0123;
2665
2666 /* Tx complete and Tx exception disable per dleach. Might be causing
2667 * buf depletion
2668 */
2669 /* #define DOEXC SLP -- doboth breaks horribly under load, doexc less so. */
2670 #if defined(DOBOTH)
2671 hw->txbuff.txfrm.desc.tx_control =
2672 HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
2673 HFA384x_TX_TXEX_SET(1) | HFA384x_TX_TXOK_SET(1);
2674 #elif defined(DOEXC)
2675 hw->txbuff.txfrm.desc.tx_control =
2676 HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
2677 HFA384x_TX_TXEX_SET(1) | HFA384x_TX_TXOK_SET(0);
2678 #else
2679 hw->txbuff.txfrm.desc.tx_control =
2680 HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
2681 HFA384x_TX_TXEX_SET(0) | HFA384x_TX_TXOK_SET(0);
2682 #endif
2683 hw->txbuff.txfrm.desc.tx_control =
2684 cpu_to_le16(hw->txbuff.txfrm.desc.tx_control);
2685
2686 /* copy the header over to the txdesc */
2687 memcpy(&(hw->txbuff.txfrm.desc.frame_control), p80211_hdr,
2688 sizeof(union p80211_hdr));
2689
2690 /* if we're using host WEP, increase size by IV+ICV */
2691 if (p80211_wep->data) {
2692 hw->txbuff.txfrm.desc.data_len = cpu_to_le16(skb->len + 8);
2693 usbpktlen += 8;
2694 } else {
2695 hw->txbuff.txfrm.desc.data_len = cpu_to_le16(skb->len);
2696 }
2697
2698 usbpktlen += skb->len;
2699
2700 /* copy over the WEP IV if we are using host WEP */
2701 ptr = hw->txbuff.txfrm.data;
2702 if (p80211_wep->data) {
2703 memcpy(ptr, p80211_wep->iv, sizeof(p80211_wep->iv));
2704 ptr += sizeof(p80211_wep->iv);
2705 memcpy(ptr, p80211_wep->data, skb->len);
2706 } else {
2707 memcpy(ptr, skb->data, skb->len);
2708 }
2709 /* copy over the packet data */
2710 ptr += skb->len;
2711
2712 /* copy over the WEP ICV if we are using host WEP */
2713 if (p80211_wep->data)
2714 memcpy(ptr, p80211_wep->icv, sizeof(p80211_wep->icv));
2715
2716 /* Send the USB packet */
2717 usb_fill_bulk_urb(&(hw->tx_urb), hw->usb,
2718 hw->endp_out,
2719 &(hw->txbuff), ROUNDUP64(usbpktlen),
2720 hfa384x_usbout_callback, hw->wlandev);
2721 hw->tx_urb.transfer_flags |= USB_QUEUE_BULK;
2722
2723 result = 1;
2724 ret = submit_tx_urb(hw, &hw->tx_urb, GFP_ATOMIC);
2725 if (ret != 0) {
2726 netdev_err(hw->wlandev->netdev,
2727 "submit_tx_urb() failed, error=%d\n", ret);
2728 result = 3;
2729 }
2730
2731 exit:
2732 return result;
2733 }
2734
2735 void hfa384x_tx_timeout(wlandevice_t *wlandev)
2736 {
2737 hfa384x_t *hw = wlandev->priv;
2738 unsigned long flags;
2739
2740 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2741
2742 if (!hw->wlandev->hwremoved) {
2743 int sched;
2744
2745 sched = !test_and_set_bit(WORK_TX_HALT, &hw->usb_flags);
2746 sched |= !test_and_set_bit(WORK_RX_HALT, &hw->usb_flags);
2747 if (sched)
2748 schedule_work(&hw->usb_work);
2749 }
2750
2751 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2752 }
2753
2754 /*----------------------------------------------------------------
2755 * hfa384x_usbctlx_reaper_task
2756 *
2757 * Tasklet to delete dead CTLX objects
2758 *
2759 * Arguments:
2760 * data ptr to a hfa384x_t
2761 *
2762 * Returns:
2763 *
2764 * Call context:
2765 * Interrupt
2766 ----------------------------------------------------------------*/
2767 static void hfa384x_usbctlx_reaper_task(unsigned long data)
2768 {
2769 hfa384x_t *hw = (hfa384x_t *)data;
2770 hfa384x_usbctlx_t *ctlx, *temp;
2771 unsigned long flags;
2772
2773 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2774
2775 /* This list is guaranteed to be empty if someone
2776 * has unplugged the adapter.
2777 */
2778 list_for_each_entry_safe(ctlx, temp, &hw->ctlxq.reapable, list) {
2779 list_del(&ctlx->list);
2780 kfree(ctlx);
2781 }
2782
2783 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2784 }
2785
2786 /*----------------------------------------------------------------
2787 * hfa384x_usbctlx_completion_task
2788 *
2789 * Tasklet to call completion handlers for returned CTLXs
2790 *
2791 * Arguments:
2792 * data ptr to hfa384x_t
2793 *
2794 * Returns:
2795 * Nothing
2796 *
2797 * Call context:
2798 * Interrupt
2799 ----------------------------------------------------------------*/
2800 static void hfa384x_usbctlx_completion_task(unsigned long data)
2801 {
2802 hfa384x_t *hw = (hfa384x_t *)data;
2803 hfa384x_usbctlx_t *ctlx, *temp;
2804 unsigned long flags;
2805
2806 int reap = 0;
2807
2808 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2809
2810 /* This list is guaranteed to be empty if someone
2811 * has unplugged the adapter ...
2812 */
2813 list_for_each_entry_safe(ctlx, temp, &hw->ctlxq.completing, list) {
2814 /* Call the completion function that this
2815 * command was assigned, assuming it has one.
2816 */
2817 if (ctlx->cmdcb != NULL) {
2818 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2819 ctlx->cmdcb(hw, ctlx);
2820 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2821
2822 /* Make sure we don't try and complete
2823 * this CTLX more than once!
2824 */
2825 ctlx->cmdcb = NULL;
2826
2827 /* Did someone yank the adapter out
2828 * while our list was (briefly) unlocked?
2829 */
2830 if (hw->wlandev->hwremoved) {
2831 reap = 0;
2832 break;
2833 }
2834 }
2835
2836 /*
2837 * "Reapable" CTLXs are ones which don't have any
2838 * threads waiting for them to die. Hence they must
2839 * be delivered to The Reaper!
2840 */
2841 if (ctlx->reapable) {
2842 /* Move the CTLX off the "completing" list (hopefully)
2843 * on to the "reapable" list where the reaper task
2844 * can find it. And "reapable" means that this CTLX
2845 * isn't sitting on a wait-queue somewhere.
2846 */
2847 list_move_tail(&ctlx->list, &hw->ctlxq.reapable);
2848 reap = 1;
2849 }
2850
2851 complete(&ctlx->done);
2852 }
2853 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2854
2855 if (reap)
2856 tasklet_schedule(&hw->reaper_bh);
2857 }
2858
2859 /*----------------------------------------------------------------
2860 * unlocked_usbctlx_cancel_async
2861 *
2862 * Mark the CTLX dead asynchronously, and ensure that the
2863 * next command on the queue is run afterwards.
2864 *
2865 * Arguments:
2866 * hw ptr to the hfa384x_t structure
2867 * ctlx ptr to a CTLX structure
2868 *
2869 * Returns:
2870 * 0 the CTLX's URB is inactive
2871 * -EINPROGRESS the URB is currently being unlinked
2872 *
2873 * Call context:
2874 * Either process or interrupt, but presumably interrupt
2875 ----------------------------------------------------------------*/
2876 static int unlocked_usbctlx_cancel_async(hfa384x_t *hw,
2877 hfa384x_usbctlx_t *ctlx)
2878 {
2879 int ret;
2880
2881 /*
2882 * Try to delete the URB containing our request packet.
2883 * If we succeed, then its completion handler will be
2884 * called with a status of -ECONNRESET.
2885 */
2886 hw->ctlx_urb.transfer_flags |= URB_ASYNC_UNLINK;
2887 ret = usb_unlink_urb(&hw->ctlx_urb);
2888
2889 if (ret != -EINPROGRESS) {
2890 /*
2891 * The OUT URB had either already completed
2892 * or was still in the pending queue, so the
2893 * URB's completion function will not be called.
2894 * We will have to complete the CTLX ourselves.
2895 */
2896 ctlx->state = CTLX_REQ_FAILED;
2897 unlocked_usbctlx_complete(hw, ctlx);
2898 ret = 0;
2899 }
2900
2901 return ret;
2902 }
2903
2904 /*----------------------------------------------------------------
2905 * unlocked_usbctlx_complete
2906 *
2907 * A CTLX has completed. It may have been successful, it may not
2908 * have been. At this point, the CTLX should be quiescent. The URBs
2909 * aren't active and the timers should have been stopped.
2910 *
2911 * The CTLX is migrated to the "completing" queue, and the completing
2912 * tasklet is scheduled.
2913 *
2914 * Arguments:
2915 * hw ptr to a hfa384x_t structure
2916 * ctlx ptr to a ctlx structure
2917 *
2918 * Returns:
2919 * nothing
2920 *
2921 * Side effects:
2922 *
2923 * Call context:
2924 * Either, assume interrupt
2925 ----------------------------------------------------------------*/
2926 static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx)
2927 {
2928 /* Timers have been stopped, and ctlx should be in
2929 * a terminal state. Retire it from the "active"
2930 * queue.
2931 */
2932 list_move_tail(&ctlx->list, &hw->ctlxq.completing);
2933 tasklet_schedule(&hw->completion_bh);
2934
2935 switch (ctlx->state) {
2936 case CTLX_COMPLETE:
2937 case CTLX_REQ_FAILED:
2938 /* This are the correct terminating states. */
2939 break;
2940
2941 default:
2942 netdev_err(hw->wlandev->netdev, "CTLX[%d] not in a terminating state(%s)\n",
2943 le16_to_cpu(ctlx->outbuf.type),
2944 ctlxstr(ctlx->state));
2945 break;
2946 } /* switch */
2947 }
2948
2949 /*----------------------------------------------------------------
2950 * hfa384x_usbctlxq_run
2951 *
2952 * Checks to see if the head item is running. If not, starts it.
2953 *
2954 * Arguments:
2955 * hw ptr to hfa384x_t
2956 *
2957 * Returns:
2958 * nothing
2959 *
2960 * Side effects:
2961 *
2962 * Call context:
2963 * any
2964 ----------------------------------------------------------------*/
2965 static void hfa384x_usbctlxq_run(hfa384x_t *hw)
2966 {
2967 unsigned long flags;
2968
2969 /* acquire lock */
2970 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2971
2972 /* Only one active CTLX at any one time, because there's no
2973 * other (reliable) way to match the response URB to the
2974 * correct CTLX.
2975 *
2976 * Don't touch any of these CTLXs if the hardware
2977 * has been removed or the USB subsystem is stalled.
2978 */
2979 if (!list_empty(&hw->ctlxq.active) ||
2980 test_bit(WORK_TX_HALT, &hw->usb_flags) || hw->wlandev->hwremoved)
2981 goto unlock;
2982
2983 while (!list_empty(&hw->ctlxq.pending)) {
2984 hfa384x_usbctlx_t *head;
2985 int result;
2986
2987 /* This is the first pending command */
2988 head = list_entry(hw->ctlxq.pending.next,
2989 hfa384x_usbctlx_t, list);
2990
2991 /* We need to split this off to avoid a race condition */
2992 list_move_tail(&head->list, &hw->ctlxq.active);
2993
2994 /* Fill the out packet */
2995 usb_fill_bulk_urb(&(hw->ctlx_urb), hw->usb,
2996 hw->endp_out,
2997 &(head->outbuf), ROUNDUP64(head->outbufsize),
2998 hfa384x_ctlxout_callback, hw);
2999 hw->ctlx_urb.transfer_flags |= USB_QUEUE_BULK;
3000
3001 /* Now submit the URB and update the CTLX's state */
3002 result = SUBMIT_URB(&hw->ctlx_urb, GFP_ATOMIC);
3003 if (result == 0) {
3004 /* This CTLX is now running on the active queue */
3005 head->state = CTLX_REQ_SUBMITTED;
3006
3007 /* Start the OUT wait timer */
3008 hw->req_timer_done = 0;
3009 hw->reqtimer.expires = jiffies + HZ;
3010 add_timer(&hw->reqtimer);
3011
3012 /* Start the IN wait timer */
3013 hw->resp_timer_done = 0;
3014 hw->resptimer.expires = jiffies + 2 * HZ;
3015 add_timer(&hw->resptimer);
3016
3017 break;
3018 }
3019
3020 if (result == -EPIPE) {
3021 /* The OUT pipe needs resetting, so put
3022 * this CTLX back in the "pending" queue
3023 * and schedule a reset ...
3024 */
3025 netdev_warn(hw->wlandev->netdev,
3026 "%s tx pipe stalled: requesting reset\n",
3027 hw->wlandev->netdev->name);
3028 list_move(&head->list, &hw->ctlxq.pending);
3029 set_bit(WORK_TX_HALT, &hw->usb_flags);
3030 schedule_work(&hw->usb_work);
3031 break;
3032 }
3033
3034 if (result == -ESHUTDOWN) {
3035 netdev_warn(hw->wlandev->netdev, "%s urb shutdown!\n",
3036 hw->wlandev->netdev->name);
3037 break;
3038 }
3039
3040 netdev_err(hw->wlandev->netdev, "Failed to submit CTLX[%d]: error=%d\n",
3041 le16_to_cpu(head->outbuf.type), result);
3042 unlocked_usbctlx_complete(hw, head);
3043 } /* while */
3044
3045 unlock:
3046 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3047 }
3048
3049 /*----------------------------------------------------------------
3050 * hfa384x_usbin_callback
3051 *
3052 * Callback for URBs on the BULKIN endpoint.
3053 *
3054 * Arguments:
3055 * urb ptr to the completed urb
3056 *
3057 * Returns:
3058 * nothing
3059 *
3060 * Side effects:
3061 *
3062 * Call context:
3063 * interrupt
3064 ----------------------------------------------------------------*/
3065 static void hfa384x_usbin_callback(struct urb *urb)
3066 {
3067 wlandevice_t *wlandev = urb->context;
3068 hfa384x_t *hw;
3069 hfa384x_usbin_t *usbin = (hfa384x_usbin_t *)urb->transfer_buffer;
3070 struct sk_buff *skb = NULL;
3071 int result;
3072 int urb_status;
3073 u16 type;
3074
3075 enum USBIN_ACTION {
3076 HANDLE,
3077 RESUBMIT,
3078 ABORT
3079 } action;
3080
3081 if (!wlandev || !wlandev->netdev || wlandev->hwremoved)
3082 goto exit;
3083
3084 hw = wlandev->priv;
3085 if (!hw)
3086 goto exit;
3087
3088 skb = hw->rx_urb_skb;
3089 BUG_ON(!skb || (skb->data != urb->transfer_buffer));
3090
3091 hw->rx_urb_skb = NULL;
3092
3093 /* Check for error conditions within the URB */
3094 switch (urb->status) {
3095 case 0:
3096 action = HANDLE;
3097
3098 /* Check for short packet */
3099 if (urb->actual_length == 0) {
3100 wlandev->netdev->stats.rx_errors++;
3101 wlandev->netdev->stats.rx_length_errors++;
3102 action = RESUBMIT;
3103 }
3104 break;
3105
3106 case -EPIPE:
3107 netdev_warn(hw->wlandev->netdev, "%s rx pipe stalled: requesting reset\n",
3108 wlandev->netdev->name);
3109 if (!test_and_set_bit(WORK_RX_HALT, &hw->usb_flags))
3110 schedule_work(&hw->usb_work);
3111 wlandev->netdev->stats.rx_errors++;
3112 action = ABORT;
3113 break;
3114
3115 case -EILSEQ:
3116 case -ETIMEDOUT:
3117 case -EPROTO:
3118 if (!test_and_set_bit(THROTTLE_RX, &hw->usb_flags) &&
3119 !timer_pending(&hw->throttle)) {
3120 mod_timer(&hw->throttle, jiffies + THROTTLE_JIFFIES);
3121 }
3122 wlandev->netdev->stats.rx_errors++;
3123 action = ABORT;
3124 break;
3125
3126 case -EOVERFLOW:
3127 wlandev->netdev->stats.rx_over_errors++;
3128 action = RESUBMIT;
3129 break;
3130
3131 case -ENODEV:
3132 case -ESHUTDOWN:
3133 pr_debug("status=%d, device removed.\n", urb->status);
3134 action = ABORT;
3135 break;
3136
3137 case -ENOENT:
3138 case -ECONNRESET:
3139 pr_debug("status=%d, urb explicitly unlinked.\n", urb->status);
3140 action = ABORT;
3141 break;
3142
3143 default:
3144 pr_debug("urb status=%d, transfer flags=0x%x\n",
3145 urb->status, urb->transfer_flags);
3146 wlandev->netdev->stats.rx_errors++;
3147 action = RESUBMIT;
3148 break;
3149 }
3150
3151 urb_status = urb->status;
3152
3153 if (action != ABORT) {
3154 /* Repost the RX URB */
3155 result = submit_rx_urb(hw, GFP_ATOMIC);
3156
3157 if (result != 0) {
3158 netdev_err(hw->wlandev->netdev,
3159 "Fatal, failed to resubmit rx_urb. error=%d\n",
3160 result);
3161 }
3162 }
3163
3164 /* Handle any USB-IN packet */
3165 /* Note: the check of the sw_support field, the type field doesn't
3166 * have bit 12 set like the docs suggest.
3167 */
3168 type = le16_to_cpu(usbin->type);
3169 if (HFA384x_USB_ISRXFRM(type)) {
3170 if (action == HANDLE) {
3171 if (usbin->txfrm.desc.sw_support == 0x0123) {
3172 hfa384x_usbin_txcompl(wlandev, usbin);
3173 } else {
3174 skb_put(skb, sizeof(*usbin));
3175 hfa384x_usbin_rx(wlandev, skb);
3176 skb = NULL;
3177 }
3178 }
3179 goto exit;
3180 }
3181 if (HFA384x_USB_ISTXFRM(type)) {
3182 if (action == HANDLE)
3183 hfa384x_usbin_txcompl(wlandev, usbin);
3184 goto exit;
3185 }
3186 switch (type) {
3187 case HFA384x_USB_INFOFRM:
3188 if (action == ABORT)
3189 goto exit;
3190 if (action == HANDLE)
3191 hfa384x_usbin_info(wlandev, usbin);
3192 break;
3193
3194 case HFA384x_USB_CMDRESP:
3195 case HFA384x_USB_WRIDRESP:
3196 case HFA384x_USB_RRIDRESP:
3197 case HFA384x_USB_WMEMRESP:
3198 case HFA384x_USB_RMEMRESP:
3199 /* ALWAYS, ALWAYS, ALWAYS handle this CTLX!!!! */
3200 hfa384x_usbin_ctlx(hw, usbin, urb_status);
3201 break;
3202
3203 case HFA384x_USB_BUFAVAIL:
3204 pr_debug("Received BUFAVAIL packet, frmlen=%d\n",
3205 usbin->bufavail.frmlen);
3206 break;
3207
3208 case HFA384x_USB_ERROR:
3209 pr_debug("Received USB_ERROR packet, errortype=%d\n",
3210 usbin->usberror.errortype);
3211 break;
3212
3213 default:
3214 pr_debug("Unrecognized USBIN packet, type=%x, status=%d\n",
3215 usbin->type, urb_status);
3216 break;
3217 } /* switch */
3218
3219 exit:
3220
3221 if (skb)
3222 dev_kfree_skb(skb);
3223 }
3224
3225 /*----------------------------------------------------------------
3226 * hfa384x_usbin_ctlx
3227 *
3228 * We've received a URB containing a Prism2 "response" message.
3229 * This message needs to be matched up with a CTLX on the active
3230 * queue and our state updated accordingly.
3231 *
3232 * Arguments:
3233 * hw ptr to hfa384x_t
3234 * usbin ptr to USB IN packet
3235 * urb_status status of this Bulk-In URB
3236 *
3237 * Returns:
3238 * nothing
3239 *
3240 * Side effects:
3241 *
3242 * Call context:
3243 * interrupt
3244 ----------------------------------------------------------------*/
3245 static void hfa384x_usbin_ctlx(hfa384x_t *hw, hfa384x_usbin_t *usbin,
3246 int urb_status)
3247 {
3248 hfa384x_usbctlx_t *ctlx;
3249 int run_queue = 0;
3250 unsigned long flags;
3251
3252 retry:
3253 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3254
3255 /* There can be only one CTLX on the active queue
3256 * at any one time, and this is the CTLX that the
3257 * timers are waiting for.
3258 */
3259 if (list_empty(&hw->ctlxq.active))
3260 goto unlock;
3261
3262 /* Remove the "response timeout". It's possible that
3263 * we are already too late, and that the timeout is
3264 * already running. And that's just too bad for us,
3265 * because we could lose our CTLX from the active
3266 * queue here ...
3267 */
3268 if (del_timer(&hw->resptimer) == 0) {
3269 if (hw->resp_timer_done == 0) {
3270 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3271 goto retry;
3272 }
3273 } else {
3274 hw->resp_timer_done = 1;
3275 }
3276
3277 ctlx = get_active_ctlx(hw);
3278
3279 if (urb_status != 0) {
3280 /*
3281 * Bad CTLX, so get rid of it. But we only
3282 * remove it from the active queue if we're no
3283 * longer expecting the OUT URB to complete.
3284 */
3285 if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0)
3286 run_queue = 1;
3287 } else {
3288 const __le16 intype = (usbin->type & ~cpu_to_le16(0x8000));
3289
3290 /*
3291 * Check that our message is what we're expecting ...
3292 */
3293 if (ctlx->outbuf.type != intype) {
3294 netdev_warn(hw->wlandev->netdev,
3295 "Expected IN[%d], received IN[%d] - ignored.\n",
3296 le16_to_cpu(ctlx->outbuf.type),
3297 le16_to_cpu(intype));
3298 goto unlock;
3299 }
3300
3301 /* This URB has succeeded, so grab the data ... */
3302 memcpy(&ctlx->inbuf, usbin, sizeof(ctlx->inbuf));
3303
3304 switch (ctlx->state) {
3305 case CTLX_REQ_SUBMITTED:
3306 /*
3307 * We have received our response URB before
3308 * our request has been acknowledged. Odd,
3309 * but our OUT URB is still alive...
3310 */
3311 pr_debug("Causality violation: please reboot Universe\n");
3312 ctlx->state = CTLX_RESP_COMPLETE;
3313 break;
3314
3315 case CTLX_REQ_COMPLETE:
3316 /*
3317 * This is the usual path: our request
3318 * has already been acknowledged, and
3319 * now we have received the reply too.
3320 */
3321 ctlx->state = CTLX_COMPLETE;
3322 unlocked_usbctlx_complete(hw, ctlx);
3323 run_queue = 1;
3324 break;
3325
3326 default:
3327 /*
3328 * Throw this CTLX away ...
3329 */
3330 netdev_err(hw->wlandev->netdev,
3331 "Matched IN URB, CTLX[%d] in invalid state(%s). Discarded.\n",
3332 le16_to_cpu(ctlx->outbuf.type),
3333 ctlxstr(ctlx->state));
3334 if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0)
3335 run_queue = 1;
3336 break;
3337 } /* switch */
3338 }
3339
3340 unlock:
3341 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3342
3343 if (run_queue)
3344 hfa384x_usbctlxq_run(hw);
3345 }
3346
3347 /*----------------------------------------------------------------
3348 * hfa384x_usbin_txcompl
3349 *
3350 * At this point we have the results of a previous transmit.
3351 *
3352 * Arguments:
3353 * wlandev wlan device
3354 * usbin ptr to the usb transfer buffer
3355 *
3356 * Returns:
3357 * nothing
3358 *
3359 * Side effects:
3360 *
3361 * Call context:
3362 * interrupt
3363 ----------------------------------------------------------------*/
3364 static void hfa384x_usbin_txcompl(wlandevice_t *wlandev,
3365 hfa384x_usbin_t *usbin)
3366 {
3367 u16 status;
3368
3369 status = le16_to_cpu(usbin->type); /* yeah I know it says type... */
3370
3371 /* Was there an error? */
3372 if (HFA384x_TXSTATUS_ISERROR(status))
3373 prism2sta_ev_txexc(wlandev, status);
3374 else
3375 prism2sta_ev_tx(wlandev, status);
3376 }
3377
3378 /*----------------------------------------------------------------
3379 * hfa384x_usbin_rx
3380 *
3381 * At this point we have a successful received a rx frame packet.
3382 *
3383 * Arguments:
3384 * wlandev wlan device
3385 * usbin ptr to the usb transfer buffer
3386 *
3387 * Returns:
3388 * nothing
3389 *
3390 * Side effects:
3391 *
3392 * Call context:
3393 * interrupt
3394 ----------------------------------------------------------------*/
3395 static void hfa384x_usbin_rx(wlandevice_t *wlandev, struct sk_buff *skb)
3396 {
3397 hfa384x_usbin_t *usbin = (hfa384x_usbin_t *)skb->data;
3398 hfa384x_t *hw = wlandev->priv;
3399 int hdrlen;
3400 struct p80211_rxmeta *rxmeta;
3401 u16 data_len;
3402 u16 fc;
3403
3404 /* Byte order convert once up front. */
3405 usbin->rxfrm.desc.status = le16_to_cpu(usbin->rxfrm.desc.status);
3406 usbin->rxfrm.desc.time = le32_to_cpu(usbin->rxfrm.desc.time);
3407
3408 /* Now handle frame based on port# */
3409 switch (HFA384x_RXSTATUS_MACPORT_GET(usbin->rxfrm.desc.status)) {
3410 case 0:
3411 fc = le16_to_cpu(usbin->rxfrm.desc.frame_control);
3412
3413 /* If exclude and we receive an unencrypted, drop it */
3414 if ((wlandev->hostwep & HOSTWEP_EXCLUDEUNENCRYPTED) &&
3415 !WLAN_GET_FC_ISWEP(fc)) {
3416 break;
3417 }
3418
3419 data_len = le16_to_cpu(usbin->rxfrm.desc.data_len);
3420
3421 /* How much header data do we have? */
3422 hdrlen = p80211_headerlen(fc);
3423
3424 /* Pull off the descriptor */
3425 skb_pull(skb, sizeof(hfa384x_rx_frame_t));
3426
3427 /* Now shunt the header block up against the data block
3428 * with an "overlapping" copy
3429 */
3430 memmove(skb_push(skb, hdrlen),
3431 &usbin->rxfrm.desc.frame_control, hdrlen);
3432
3433 skb->dev = wlandev->netdev;
3434 skb->dev->last_rx = jiffies;
3435
3436 /* And set the frame length properly */
3437 skb_trim(skb, data_len + hdrlen);
3438
3439 /* The prism2 series does not return the CRC */
3440 memset(skb_put(skb, WLAN_CRC_LEN), 0xff, WLAN_CRC_LEN);
3441
3442 skb_reset_mac_header(skb);
3443
3444 /* Attach the rxmeta, set some stuff */
3445 p80211skb_rxmeta_attach(wlandev, skb);
3446 rxmeta = P80211SKB_RXMETA(skb);
3447 rxmeta->mactime = usbin->rxfrm.desc.time;
3448 rxmeta->rxrate = usbin->rxfrm.desc.rate;
3449 rxmeta->signal = usbin->rxfrm.desc.signal - hw->dbmadjust;
3450 rxmeta->noise = usbin->rxfrm.desc.silence - hw->dbmadjust;
3451
3452 p80211netdev_rx(wlandev, skb);
3453
3454 break;
3455
3456 case 7:
3457 if (!HFA384x_RXSTATUS_ISFCSERR(usbin->rxfrm.desc.status)) {
3458 /* Copy to wlansnif skb */
3459 hfa384x_int_rxmonitor(wlandev, &usbin->rxfrm);
3460 dev_kfree_skb(skb);
3461 } else {
3462 pr_debug("Received monitor frame: FCSerr set\n");
3463 }
3464 break;
3465
3466 default:
3467 netdev_warn(hw->wlandev->netdev, "Received frame on unsupported port=%d\n",
3468 HFA384x_RXSTATUS_MACPORT_GET(
3469 usbin->rxfrm.desc.status));
3470 break;
3471 }
3472 }
3473
3474 /*----------------------------------------------------------------
3475 * hfa384x_int_rxmonitor
3476 *
3477 * Helper function for int_rx. Handles monitor frames.
3478 * Note that this function allocates space for the FCS and sets it
3479 * to 0xffffffff. The hfa384x doesn't give us the FCS value but the
3480 * higher layers expect it. 0xffffffff is used as a flag to indicate
3481 * the FCS is bogus.
3482 *
3483 * Arguments:
3484 * wlandev wlan device structure
3485 * rxfrm rx descriptor read from card in int_rx
3486 *
3487 * Returns:
3488 * nothing
3489 *
3490 * Side effects:
3491 * Allocates an skb and passes it up via the PF_PACKET interface.
3492 * Call context:
3493 * interrupt
3494 ----------------------------------------------------------------*/
3495 static void hfa384x_int_rxmonitor(wlandevice_t *wlandev,
3496 hfa384x_usb_rxfrm_t *rxfrm)
3497 {
3498 hfa384x_rx_frame_t *rxdesc = &(rxfrm->desc);
3499 unsigned int hdrlen = 0;
3500 unsigned int datalen = 0;
3501 unsigned int skblen = 0;
3502 u8 *datap;
3503 u16 fc;
3504 struct sk_buff *skb;
3505 hfa384x_t *hw = wlandev->priv;
3506
3507 /* Remember the status, time, and data_len fields are in host order */
3508 /* Figure out how big the frame is */
3509 fc = le16_to_cpu(rxdesc->frame_control);
3510 hdrlen = p80211_headerlen(fc);
3511 datalen = le16_to_cpu(rxdesc->data_len);
3512
3513 /* Allocate an ind message+framesize skb */
3514 skblen = sizeof(struct p80211_caphdr) + hdrlen + datalen + WLAN_CRC_LEN;
3515
3516 /* sanity check the length */
3517 if (skblen >
3518 (sizeof(struct p80211_caphdr) +
3519 WLAN_HDR_A4_LEN + WLAN_DATA_MAXLEN + WLAN_CRC_LEN)) {
3520 pr_debug("overlen frm: len=%zd\n",
3521 skblen - sizeof(struct p80211_caphdr));
3522 }
3523
3524 skb = dev_alloc_skb(skblen);
3525 if (skb == NULL)
3526 return;
3527
3528 /* only prepend the prism header if in the right mode */
3529 if ((wlandev->netdev->type == ARPHRD_IEEE80211_PRISM) &&
3530 (hw->sniffhdr != 0)) {
3531 struct p80211_caphdr *caphdr;
3532 /* The NEW header format! */
3533 datap = skb_put(skb, sizeof(struct p80211_caphdr));
3534 caphdr = (struct p80211_caphdr *)datap;
3535
3536 caphdr->version = htonl(P80211CAPTURE_VERSION);
3537 caphdr->length = htonl(sizeof(struct p80211_caphdr));
3538 caphdr->mactime = __cpu_to_be64(rxdesc->time) * 1000;
3539 caphdr->hosttime = __cpu_to_be64(jiffies);
3540 caphdr->phytype = htonl(4); /* dss_dot11_b */
3541 caphdr->channel = htonl(hw->sniff_channel);
3542 caphdr->datarate = htonl(rxdesc->rate);
3543 caphdr->antenna = htonl(0); /* unknown */
3544 caphdr->priority = htonl(0); /* unknown */
3545 caphdr->ssi_type = htonl(3); /* rssi_raw */
3546 caphdr->ssi_signal = htonl(rxdesc->signal);
3547 caphdr->ssi_noise = htonl(rxdesc->silence);
3548 caphdr->preamble = htonl(0); /* unknown */
3549 caphdr->encoding = htonl(1); /* cck */
3550 }
3551
3552 /* Copy the 802.11 header to the skb
3553 (ctl frames may be less than a full header) */
3554 datap = skb_put(skb, hdrlen);
3555 memcpy(datap, &(rxdesc->frame_control), hdrlen);
3556
3557 /* If any, copy the data from the card to the skb */
3558 if (datalen > 0) {
3559 datap = skb_put(skb, datalen);
3560 memcpy(datap, rxfrm->data, datalen);
3561
3562 /* check for unencrypted stuff if WEP bit set. */
3563 if (*(datap - hdrlen + 1) & 0x40) /* wep set */
3564 if ((*(datap) == 0xaa) && (*(datap + 1) == 0xaa))
3565 /* clear wep; it's the 802.2 header! */
3566 *(datap - hdrlen + 1) &= 0xbf;
3567 }
3568
3569 if (hw->sniff_fcs) {
3570 /* Set the FCS */
3571 datap = skb_put(skb, WLAN_CRC_LEN);
3572 memset(datap, 0xff, WLAN_CRC_LEN);
3573 }
3574
3575 /* pass it back up */
3576 p80211netdev_rx(wlandev, skb);
3577 }
3578
3579 /*----------------------------------------------------------------
3580 * hfa384x_usbin_info
3581 *
3582 * At this point we have a successful received a Prism2 info frame.
3583 *
3584 * Arguments:
3585 * wlandev wlan device
3586 * usbin ptr to the usb transfer buffer
3587 *
3588 * Returns:
3589 * nothing
3590 *
3591 * Side effects:
3592 *
3593 * Call context:
3594 * interrupt
3595 ----------------------------------------------------------------*/
3596 static void hfa384x_usbin_info(wlandevice_t *wlandev, hfa384x_usbin_t *usbin)
3597 {
3598 usbin->infofrm.info.framelen =
3599 le16_to_cpu(usbin->infofrm.info.framelen);
3600 prism2sta_ev_info(wlandev, &usbin->infofrm.info);
3601 }
3602
3603 /*----------------------------------------------------------------
3604 * hfa384x_usbout_callback
3605 *
3606 * Callback for URBs on the BULKOUT endpoint.
3607 *
3608 * Arguments:
3609 * urb ptr to the completed urb
3610 *
3611 * Returns:
3612 * nothing
3613 *
3614 * Side effects:
3615 *
3616 * Call context:
3617 * interrupt
3618 ----------------------------------------------------------------*/
3619 static void hfa384x_usbout_callback(struct urb *urb)
3620 {
3621 wlandevice_t *wlandev = urb->context;
3622
3623 #ifdef DEBUG_USB
3624 dbprint_urb(urb);
3625 #endif
3626
3627 if (wlandev && wlandev->netdev) {
3628 switch (urb->status) {
3629 case 0:
3630 prism2sta_ev_alloc(wlandev);
3631 break;
3632
3633 case -EPIPE:
3634 {
3635 hfa384x_t *hw = wlandev->priv;
3636
3637 netdev_warn(hw->wlandev->netdev,
3638 "%s tx pipe stalled: requesting reset\n",
3639 wlandev->netdev->name);
3640 if (!test_and_set_bit
3641 (WORK_TX_HALT, &hw->usb_flags))
3642 schedule_work(&hw->usb_work);
3643 wlandev->netdev->stats.tx_errors++;
3644 break;
3645 }
3646
3647 case -EPROTO:
3648 case -ETIMEDOUT:
3649 case -EILSEQ:
3650 {
3651 hfa384x_t *hw = wlandev->priv;
3652
3653 if (!test_and_set_bit
3654 (THROTTLE_TX, &hw->usb_flags) &&
3655 !timer_pending(&hw->throttle)) {
3656 mod_timer(&hw->throttle,
3657 jiffies + THROTTLE_JIFFIES);
3658 }
3659 wlandev->netdev->stats.tx_errors++;
3660 netif_stop_queue(wlandev->netdev);
3661 break;
3662 }
3663
3664 case -ENOENT:
3665 case -ESHUTDOWN:
3666 /* Ignorable errors */
3667 break;
3668
3669 default:
3670 netdev_info(wlandev->netdev, "unknown urb->status=%d\n",
3671 urb->status);
3672 wlandev->netdev->stats.tx_errors++;
3673 break;
3674 } /* switch */
3675 }
3676 }
3677
3678 /*----------------------------------------------------------------
3679 * hfa384x_ctlxout_callback
3680 *
3681 * Callback for control data on the BULKOUT endpoint.
3682 *
3683 * Arguments:
3684 * urb ptr to the completed urb
3685 *
3686 * Returns:
3687 * nothing
3688 *
3689 * Side effects:
3690 *
3691 * Call context:
3692 * interrupt
3693 ----------------------------------------------------------------*/
3694 static void hfa384x_ctlxout_callback(struct urb *urb)
3695 {
3696 hfa384x_t *hw = urb->context;
3697 int delete_resptimer = 0;
3698 int timer_ok = 1;
3699 int run_queue = 0;
3700 hfa384x_usbctlx_t *ctlx;
3701 unsigned long flags;
3702
3703 pr_debug("urb->status=%d\n", urb->status);
3704 #ifdef DEBUG_USB
3705 dbprint_urb(urb);
3706 #endif
3707 if ((urb->status == -ESHUTDOWN) ||
3708 (urb->status == -ENODEV) || (hw == NULL))
3709 return;
3710
3711 retry:
3712 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3713
3714 /*
3715 * Only one CTLX at a time on the "active" list, and
3716 * none at all if we are unplugged. However, we can
3717 * rely on the disconnect function to clean everything
3718 * up if someone unplugged the adapter.
3719 */
3720 if (list_empty(&hw->ctlxq.active)) {
3721 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3722 return;
3723 }
3724
3725 /*
3726 * Having something on the "active" queue means
3727 * that we have timers to worry about ...
3728 */
3729 if (del_timer(&hw->reqtimer) == 0) {
3730 if (hw->req_timer_done == 0) {
3731 /*
3732 * This timer was actually running while we
3733 * were trying to delete it. Let it terminate
3734 * gracefully instead.
3735 */
3736 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3737 goto retry;
3738 }
3739 } else {
3740 hw->req_timer_done = 1;
3741 }
3742
3743 ctlx = get_active_ctlx(hw);
3744
3745 if (urb->status == 0) {
3746 /* Request portion of a CTLX is successful */
3747 switch (ctlx->state) {
3748 case CTLX_REQ_SUBMITTED:
3749 /* This OUT-ACK received before IN */
3750 ctlx->state = CTLX_REQ_COMPLETE;
3751 break;
3752
3753 case CTLX_RESP_COMPLETE:
3754 /* IN already received before this OUT-ACK,
3755 * so this command must now be complete.
3756 */
3757 ctlx->state = CTLX_COMPLETE;
3758 unlocked_usbctlx_complete(hw, ctlx);
3759 run_queue = 1;
3760 break;
3761
3762 default:
3763 /* This is NOT a valid CTLX "success" state! */
3764 netdev_err(hw->wlandev->netdev,
3765 "Illegal CTLX[%d] success state(%s, %d) in OUT URB\n",
3766 le16_to_cpu(ctlx->outbuf.type),
3767 ctlxstr(ctlx->state), urb->status);
3768 break;
3769 } /* switch */
3770 } else {
3771 /* If the pipe has stalled then we need to reset it */
3772 if ((urb->status == -EPIPE) &&
3773 !test_and_set_bit(WORK_TX_HALT, &hw->usb_flags)) {
3774 netdev_warn(hw->wlandev->netdev,
3775 "%s tx pipe stalled: requesting reset\n",
3776 hw->wlandev->netdev->name);
3777 schedule_work(&hw->usb_work);
3778 }
3779
3780 /* If someone cancels the OUT URB then its status
3781 * should be either -ECONNRESET or -ENOENT.
3782 */
3783 ctlx->state = CTLX_REQ_FAILED;
3784 unlocked_usbctlx_complete(hw, ctlx);
3785 delete_resptimer = 1;
3786 run_queue = 1;
3787 }
3788
3789 delresp:
3790 if (delete_resptimer) {
3791 timer_ok = del_timer(&hw->resptimer);
3792 if (timer_ok != 0)
3793 hw->resp_timer_done = 1;
3794 }
3795
3796 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3797
3798 if (!timer_ok && (hw->resp_timer_done == 0)) {
3799 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3800 goto delresp;
3801 }
3802
3803 if (run_queue)
3804 hfa384x_usbctlxq_run(hw);
3805 }
3806
3807 /*----------------------------------------------------------------
3808 * hfa384x_usbctlx_reqtimerfn
3809 *
3810 * Timer response function for CTLX request timeouts. If this
3811 * function is called, it means that the callback for the OUT
3812 * URB containing a Prism2.x XXX_Request was never called.
3813 *
3814 * Arguments:
3815 * data a ptr to the hfa384x_t
3816 *
3817 * Returns:
3818 * nothing
3819 *
3820 * Side effects:
3821 *
3822 * Call context:
3823 * interrupt
3824 ----------------------------------------------------------------*/
3825 static void hfa384x_usbctlx_reqtimerfn(unsigned long data)
3826 {
3827 hfa384x_t *hw = (hfa384x_t *)data;
3828 unsigned long flags;
3829
3830 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3831
3832 hw->req_timer_done = 1;
3833
3834 /* Removing the hardware automatically empties
3835 * the active list ...
3836 */
3837 if (!list_empty(&hw->ctlxq.active)) {
3838 /*
3839 * We must ensure that our URB is removed from
3840 * the system, if it hasn't already expired.
3841 */
3842 hw->ctlx_urb.transfer_flags |= URB_ASYNC_UNLINK;
3843 if (usb_unlink_urb(&hw->ctlx_urb) == -EINPROGRESS) {
3844 hfa384x_usbctlx_t *ctlx = get_active_ctlx(hw);
3845
3846 ctlx->state = CTLX_REQ_FAILED;
3847
3848 /* This URB was active, but has now been
3849 * cancelled. It will now have a status of
3850 * -ECONNRESET in the callback function.
3851 *
3852 * We are cancelling this CTLX, so we're
3853 * not going to need to wait for a response.
3854 * The URB's callback function will check
3855 * that this timer is truly dead.
3856 */
3857 if (del_timer(&hw->resptimer) != 0)
3858 hw->resp_timer_done = 1;
3859 }
3860 }
3861
3862 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3863 }
3864
3865 /*----------------------------------------------------------------
3866 * hfa384x_usbctlx_resptimerfn
3867 *
3868 * Timer response function for CTLX response timeouts. If this
3869 * function is called, it means that the callback for the IN
3870 * URB containing a Prism2.x XXX_Response was never called.
3871 *
3872 * Arguments:
3873 * data a ptr to the hfa384x_t
3874 *
3875 * Returns:
3876 * nothing
3877 *
3878 * Side effects:
3879 *
3880 * Call context:
3881 * interrupt
3882 ----------------------------------------------------------------*/
3883 static void hfa384x_usbctlx_resptimerfn(unsigned long data)
3884 {
3885 hfa384x_t *hw = (hfa384x_t *)data;
3886 unsigned long flags;
3887
3888 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3889
3890 hw->resp_timer_done = 1;
3891
3892 /* The active list will be empty if the
3893 * adapter has been unplugged ...
3894 */
3895 if (!list_empty(&hw->ctlxq.active)) {
3896 hfa384x_usbctlx_t *ctlx = get_active_ctlx(hw);
3897
3898 if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0) {
3899 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3900 hfa384x_usbctlxq_run(hw);
3901 return;
3902 }
3903 }
3904 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3905 }
3906
3907 /*----------------------------------------------------------------
3908 * hfa384x_usb_throttlefn
3909 *
3910 *
3911 * Arguments:
3912 * data ptr to hw
3913 *
3914 * Returns:
3915 * Nothing
3916 *
3917 * Side effects:
3918 *
3919 * Call context:
3920 * Interrupt
3921 ----------------------------------------------------------------*/
3922 static void hfa384x_usb_throttlefn(unsigned long data)
3923 {
3924 hfa384x_t *hw = (hfa384x_t *)data;
3925 unsigned long flags;
3926
3927 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3928
3929 /*
3930 * We need to check BOTH the RX and the TX throttle controls,
3931 * so we use the bitwise OR instead of the logical OR.
3932 */
3933 pr_debug("flags=0x%lx\n", hw->usb_flags);
3934 if (!hw->wlandev->hwremoved &&
3935 ((test_and_clear_bit(THROTTLE_RX, &hw->usb_flags) &&
3936 !test_and_set_bit(WORK_RX_RESUME, &hw->usb_flags)) |
3937 (test_and_clear_bit(THROTTLE_TX, &hw->usb_flags) &&
3938 !test_and_set_bit(WORK_TX_RESUME, &hw->usb_flags))
3939 )) {
3940 schedule_work(&hw->usb_work);
3941 }
3942
3943 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3944 }
3945
3946 /*----------------------------------------------------------------
3947 * hfa384x_usbctlx_submit
3948 *
3949 * Called from the doxxx functions to submit a CTLX to the queue
3950 *
3951 * Arguments:
3952 * hw ptr to the hw struct
3953 * ctlx ctlx structure to enqueue
3954 *
3955 * Returns:
3956 * -ENODEV if the adapter is unplugged
3957 * 0
3958 *
3959 * Side effects:
3960 *
3961 * Call context:
3962 * process or interrupt
3963 ----------------------------------------------------------------*/
3964 static int hfa384x_usbctlx_submit(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx)
3965 {
3966 unsigned long flags;
3967
3968 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3969
3970 if (hw->wlandev->hwremoved) {
3971 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3972 return -ENODEV;
3973 }
3974
3975 ctlx->state = CTLX_PENDING;
3976 list_add_tail(&ctlx->list, &hw->ctlxq.pending);
3977 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3978 hfa384x_usbctlxq_run(hw);
3979
3980 return 0;
3981 }
3982
3983 /*----------------------------------------------------------------
3984 * hfa384x_isgood_pdrcore
3985 *
3986 * Quick check of PDR codes.
3987 *
3988 * Arguments:
3989 * pdrcode PDR code number (host order)
3990 *
3991 * Returns:
3992 * zero not good.
3993 * one is good.
3994 *
3995 * Side effects:
3996 *
3997 * Call context:
3998 ----------------------------------------------------------------*/
3999 static int hfa384x_isgood_pdrcode(u16 pdrcode)
4000 {
4001 switch (pdrcode) {
4002 case HFA384x_PDR_END_OF_PDA:
4003 case HFA384x_PDR_PCB_PARTNUM:
4004 case HFA384x_PDR_PDAVER:
4005 case HFA384x_PDR_NIC_SERIAL:
4006 case HFA384x_PDR_MKK_MEASUREMENTS:
4007 case HFA384x_PDR_NIC_RAMSIZE:
4008 case HFA384x_PDR_MFISUPRANGE:
4009 case HFA384x_PDR_CFISUPRANGE:
4010 case HFA384x_PDR_NICID:
4011 case HFA384x_PDR_MAC_ADDRESS:
4012 case HFA384x_PDR_REGDOMAIN:
4013 case HFA384x_PDR_ALLOWED_CHANNEL:
4014 case HFA384x_PDR_DEFAULT_CHANNEL:
4015 case HFA384x_PDR_TEMPTYPE:
4016 case HFA384x_PDR_IFR_SETTING:
4017 case HFA384x_PDR_RFR_SETTING:
4018 case HFA384x_PDR_HFA3861_BASELINE:
4019 case HFA384x_PDR_HFA3861_SHADOW:
4020 case HFA384x_PDR_HFA3861_IFRF:
4021 case HFA384x_PDR_HFA3861_CHCALSP:
4022 case HFA384x_PDR_HFA3861_CHCALI:
4023 case HFA384x_PDR_3842_NIC_CONFIG:
4024 case HFA384x_PDR_USB_ID:
4025 case HFA384x_PDR_PCI_ID:
4026 case HFA384x_PDR_PCI_IFCONF:
4027 case HFA384x_PDR_PCI_PMCONF:
4028 case HFA384x_PDR_RFENRGY:
4029 case HFA384x_PDR_HFA3861_MANF_TESTSP:
4030 case HFA384x_PDR_HFA3861_MANF_TESTI:
4031 /* code is OK */
4032 return 1;
4033 default:
4034 if (pdrcode < 0x1000) {
4035 /* code is OK, but we don't know exactly what it is */
4036 pr_debug("Encountered unknown PDR#=0x%04x, assuming it's ok.\n",
4037 pdrcode);
4038 return 1;
4039 }
4040 break;
4041 }
4042 /* bad code */
4043 pr_debug("Encountered unknown PDR#=0x%04x, (>=0x1000), assuming it's bad.\n",
4044 pdrcode);
4045 return 0;
4046 }
This page took 0.21634 seconds and 5 git commands to generate.