blob: 7843dfdaa3cf69cb348d006f0382cbc4409da42c [file] [log] [blame]
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001/* 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
Adam Buchbinder3fc0d272009-12-18 15:43:52 -050055* of invocations of the API layer (e.g. write to bap, followed by cmd).
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070056*
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
Edgardo Hames631c8de2010-03-08 17:02:37 -080065* sequence. They call copy_[to|from]_bap() and
66* cmd_access(). These functions operate on the
67* RIDs and buffers without validation. The caller
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -070068* 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
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700113#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>
Andrew Elwellef1a0ed2010-02-18 23:56:12 +0100121#include <linux/io.h>
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700122#include <linux/delay.h>
123#include <asm/byteorder.h>
Andrew Elwellef1a0ed2010-02-18 23:56:12 +0100124#include <linux/bitops.h>
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700125#include <linux/list.h>
126#include <linux/usb.h>
Moritz Muehlenhoffae262302009-01-21 22:00:45 +0100127#include <linux/byteorder/generic.h>
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700128
Svenne Krap5dd8acc2010-02-14 18:59:00 +0100129#define SUBMIT_URB(u, f) usb_submit_urb(u, f)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700130
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700131#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
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100143enum cmd_mode {
144 DOWAIT = 0,
145 DOASYNC
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700146};
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700147
148#define THROTTLE_JIFFIES (HZ/8)
Moritz Muehlenhoff2d200d92009-01-25 21:54:56 +0100149#define URB_ASYNC_UNLINK 0
150#define USB_QUEUE_BULK 0
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700151
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700152#define ROUNDUP64(a) (((a)+63)&~63)
153
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700154#ifdef DEBUG_USB
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100155static void dbprint_urb(struct urb *urb);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700156#endif
157
158static void
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530159hfa384x_int_rxmonitor(wlandevice_t *wlandev, hfa384x_usb_rxfrm_t *rxfrm);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700160
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100161static void hfa384x_usb_defer(struct work_struct *data);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700162
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530163static int submit_rx_urb(hfa384x_t *hw, gfp_t flags);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700164
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530165static int submit_tx_urb(hfa384x_t *hw, struct urb *tx_urb, gfp_t flags);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700166
167/*---------------------------------------------------*/
168/* Callbacks */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100169static void hfa384x_usbout_callback(struct urb *urb);
170static void hfa384x_ctlxout_callback(struct urb *urb);
171static void hfa384x_usbin_callback(struct urb *urb);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700172
173static void
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530174hfa384x_usbin_txcompl(wlandevice_t *wlandev, hfa384x_usbin_t * usbin);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700175
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530176static void hfa384x_usbin_rx(wlandevice_t *wlandev, struct sk_buff *skb);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700177
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530178static void hfa384x_usbin_info(wlandevice_t *wlandev, hfa384x_usbin_t * usbin);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700179
180static void
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530181hfa384x_usbout_tx(wlandevice_t *wlandev, hfa384x_usbout_t *usbout);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700182
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530183static void hfa384x_usbin_ctlx(hfa384x_t *hw, hfa384x_usbin_t *usbin,
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700184 int urb_status);
185
186/*---------------------------------------------------*/
187/* Functions to support the prism2 usb command queue */
188
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530189static void hfa384x_usbctlxq_run(hfa384x_t *hw);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700190
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100191static void hfa384x_usbctlx_reqtimerfn(unsigned long data);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700192
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100193static void hfa384x_usbctlx_resptimerfn(unsigned long data);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700194
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100195static void hfa384x_usb_throttlefn(unsigned long data);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700196
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100197static void hfa384x_usbctlx_completion_task(unsigned long data);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700198
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100199static void hfa384x_usbctlx_reaper_task(unsigned long data);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700200
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530201static int hfa384x_usbctlx_submit(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700202
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530203static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700204
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100205struct usbctlx_completor {
206 int (*complete) (struct usbctlx_completor *);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700207};
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700208
209static int
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530210hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
211 hfa384x_usbctlx_t *ctlx,
Edgardo Hames631c8de2010-03-08 17:02:37 -0800212 struct usbctlx_completor *completor);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700213
214static int
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530215unlocked_usbctlx_cancel_async(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700216
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530217static void hfa384x_cb_status(hfa384x_t *hw, const hfa384x_usbctlx_t *ctlx);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700218
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530219static void hfa384x_cb_rrid(hfa384x_t *hw, const hfa384x_usbctlx_t *ctlx);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700220
221static int
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530222usbctlx_get_status(const hfa384x_usb_cmdresp_t *cmdresp,
223 hfa384x_cmdresult_t *result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700224
225static void
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530226usbctlx_get_rridresult(const hfa384x_usb_rridresp_t *rridresp,
227 hfa384x_rridresult_t *result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700228
229/*---------------------------------------------------*/
230/* Low level req/resp CTLX formatters and submitters */
231static int
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530232hfa384x_docmd(hfa384x_t *hw,
Edgardo Hames631c8de2010-03-08 17:02:37 -0800233 enum cmd_mode mode,
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530234 hfa384x_metacmd_t *cmd,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100235 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700236
237static int
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530238hfa384x_dorrid(hfa384x_t *hw,
Edgardo Hames631c8de2010-03-08 17:02:37 -0800239 enum cmd_mode mode,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100240 u16 rid,
241 void *riddata,
242 unsigned int riddatalen,
243 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700244
245static int
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530246hfa384x_dowrid(hfa384x_t *hw,
Edgardo Hames631c8de2010-03-08 17:02:37 -0800247 enum cmd_mode mode,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100248 u16 rid,
249 void *riddata,
250 unsigned int riddatalen,
251 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700252
253static int
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530254hfa384x_dormem(hfa384x_t *hw,
Edgardo Hames631c8de2010-03-08 17:02:37 -0800255 enum cmd_mode mode,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100256 u16 page,
257 u16 offset,
258 void *data,
259 unsigned int len,
260 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700261
262static int
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530263hfa384x_dowmem(hfa384x_t *hw,
Edgardo Hames631c8de2010-03-08 17:02:37 -0800264 enum cmd_mode mode,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100265 u16 page,
266 u16 offset,
267 void *data,
268 unsigned int len,
269 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700270
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100271static int hfa384x_isgood_pdrcode(u16 pdrcode);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700272
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100273static inline const char *ctlxstr(CTLX_STATE s)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700274{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100275 static const char *ctlx_str[] = {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700276 "Initial state",
277 "Complete",
278 "Request failed",
279 "Request pending",
280 "Request packet submitted",
281 "Request packet completed",
282 "Response packet completed"
283 };
284
285 return ctlx_str[s];
286};
287
Mithlesh Thukral75f49e02009-05-25 19:06:16 +0530288static inline hfa384x_usbctlx_t *get_active_ctlx(hfa384x_t * hw)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700289{
290 return list_entry(hw->ctlxq.active.next, hfa384x_usbctlx_t, list);
291}
292
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700293#ifdef DEBUG_USB
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100294void dbprint_urb(struct urb *urb)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700295{
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +0100296 pr_debug("urb->pipe=0x%08x\n", urb->pipe);
297 pr_debug("urb->status=0x%08x\n", urb->status);
298 pr_debug("urb->transfer_flags=0x%08x\n", urb->transfer_flags);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100299 pr_debug("urb->transfer_buffer=0x%08x\n",
Mithlesh Thukral75f49e02009-05-25 19:06:16 +0530300 (unsigned int)urb->transfer_buffer);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100301 pr_debug("urb->transfer_buffer_length=0x%08x\n",
Mithlesh Thukral75f49e02009-05-25 19:06:16 +0530302 urb->transfer_buffer_length);
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +0100303 pr_debug("urb->actual_length=0x%08x\n", urb->actual_length);
304 pr_debug("urb->bandwidth=0x%08x\n", urb->bandwidth);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100305 pr_debug("urb->setup_packet(ctl)=0x%08x\n",
Mithlesh Thukral75f49e02009-05-25 19:06:16 +0530306 (unsigned int)urb->setup_packet);
307 pr_debug("urb->start_frame(iso/irq)=0x%08x\n", urb->start_frame);
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +0100308 pr_debug("urb->interval(irq)=0x%08x\n", urb->interval);
309 pr_debug("urb->error_count(iso)=0x%08x\n", urb->error_count);
310 pr_debug("urb->timeout=0x%08x\n", urb->timeout);
311 pr_debug("urb->context=0x%08x\n", (unsigned int)urb->context);
Mithlesh Thukral75f49e02009-05-25 19:06:16 +0530312 pr_debug("urb->complete=0x%08x\n", (unsigned int)urb->complete);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700313}
314#endif
315
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700316/*----------------------------------------------------------------
317* submit_rx_urb
318*
319* Listen for input data on the BULK-IN pipe. If the pipe has
320* stalled then schedule it to be reset.
321*
322* Arguments:
323* hw device struct
324* memflags memory allocation flags
325*
326* Returns:
327* error code from submission
328*
329* Call context:
330* Any
331----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530332static int submit_rx_urb(hfa384x_t *hw, gfp_t memflags)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700333{
334 struct sk_buff *skb;
335 int result;
336
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700337 skb = dev_alloc_skb(sizeof(hfa384x_usbin_t));
338 if (skb == NULL) {
339 result = -ENOMEM;
340 goto done;
341 }
342
343 /* Post the IN urb */
344 usb_fill_bulk_urb(&hw->rx_urb, hw->usb,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100345 hw->endp_in,
346 skb->data, sizeof(hfa384x_usbin_t),
347 hfa384x_usbin_callback, hw->wlandev);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700348
349 hw->rx_urb_skb = skb;
350
351 result = -ENOLINK;
Edgardo Hames631c8de2010-03-08 17:02:37 -0800352 if (!hw->wlandev->hwremoved &&
353 !test_bit(WORK_RX_HALT, &hw->usb_flags)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700354 result = SUBMIT_URB(&hw->rx_urb, memflags);
355
356 /* Check whether we need to reset the RX pipe */
357 if (result == -EPIPE) {
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100358 printk(KERN_WARNING
359 "%s rx pipe stalled: requesting reset\n",
360 hw->wlandev->netdev->name);
361 if (!test_and_set_bit(WORK_RX_HALT, &hw->usb_flags))
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700362 schedule_work(&hw->usb_work);
363 }
364 }
365
366 /* Don't leak memory if anything should go wrong */
367 if (result != 0) {
368 dev_kfree_skb(skb);
369 hw->rx_urb_skb = NULL;
370 }
371
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100372done:
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700373 return result;
374}
375
376/*----------------------------------------------------------------
377* submit_tx_urb
378*
379* Prepares and submits the URB of transmitted data. If the
380* submission fails then it will schedule the output pipe to
381* be reset.
382*
383* Arguments:
384* hw device struct
385* tx_urb URB of data for tranmission
386* memflags memory allocation flags
387*
388* Returns:
389* error code from submission
390*
391* Call context:
392* Any
393----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530394static int submit_tx_urb(hfa384x_t *hw, struct urb *tx_urb, gfp_t memflags)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700395{
396 struct net_device *netdev = hw->wlandev->netdev;
397 int result;
398
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700399 result = -ENOLINK;
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100400 if (netif_running(netdev)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700401
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100402 if (!hw->wlandev->hwremoved
403 && !test_bit(WORK_TX_HALT, &hw->usb_flags)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700404 result = SUBMIT_URB(tx_urb, memflags);
405
406 /* Test whether we need to reset the TX pipe */
407 if (result == -EPIPE) {
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100408 printk(KERN_WARNING
409 "%s tx pipe stalled: requesting reset\n",
410 netdev->name);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700411 set_bit(WORK_TX_HALT, &hw->usb_flags);
412 schedule_work(&hw->usb_work);
413 } else if (result == 0) {
414 netif_stop_queue(netdev);
415 }
416 }
417 }
418
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700419 return result;
420}
421
422/*----------------------------------------------------------------
423* hfa394x_usb_defer
424*
425* There are some things that the USB stack cannot do while
426* in interrupt context, so we arrange this function to run
427* in process context.
428*
429* Arguments:
430* hw device structure
431*
432* Returns:
433* nothing
434*
435* Call context:
436* process (by design)
437----------------------------------------------------------------*/
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100438static void hfa384x_usb_defer(struct work_struct *data)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700439{
440 hfa384x_t *hw = container_of(data, struct hfa384x, usb_work);
441 struct net_device *netdev = hw->wlandev->netdev;
442
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700443 /* Don't bother trying to reset anything if the plug
444 * has been pulled ...
445 */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100446 if (hw->wlandev->hwremoved)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700447 return;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700448
449 /* Reception has stopped: try to reset the input pipe */
450 if (test_bit(WORK_RX_HALT, &hw->usb_flags)) {
451 int ret;
452
Edgardo Hames631c8de2010-03-08 17:02:37 -0800453 usb_kill_urb(&hw->rx_urb); /* Cannot be holding spinlock! */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700454
455 ret = usb_clear_halt(hw->usb, hw->endp_in);
456 if (ret != 0) {
457 printk(KERN_ERR
458 "Failed to clear rx pipe for %s: err=%d\n",
459 netdev->name, ret);
460 } else {
461 printk(KERN_INFO "%s rx pipe reset complete.\n",
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100462 netdev->name);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700463 clear_bit(WORK_RX_HALT, &hw->usb_flags);
464 set_bit(WORK_RX_RESUME, &hw->usb_flags);
465 }
466 }
467
468 /* Resume receiving data back from the device. */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100469 if (test_bit(WORK_RX_RESUME, &hw->usb_flags)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700470 int ret;
471
472 ret = submit_rx_urb(hw, GFP_KERNEL);
473 if (ret != 0) {
474 printk(KERN_ERR
475 "Failed to resume %s rx pipe.\n", netdev->name);
476 } else {
477 clear_bit(WORK_RX_RESUME, &hw->usb_flags);
478 }
479 }
480
481 /* Transmission has stopped: try to reset the output pipe */
482 if (test_bit(WORK_TX_HALT, &hw->usb_flags)) {
483 int ret;
484
485 usb_kill_urb(&hw->tx_urb);
486 ret = usb_clear_halt(hw->usb, hw->endp_out);
487 if (ret != 0) {
488 printk(KERN_ERR
489 "Failed to clear tx pipe for %s: err=%d\n",
490 netdev->name, ret);
491 } else {
492 printk(KERN_INFO "%s tx pipe reset complete.\n",
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100493 netdev->name);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700494 clear_bit(WORK_TX_HALT, &hw->usb_flags);
495 set_bit(WORK_TX_RESUME, &hw->usb_flags);
496
497 /* Stopping the BULK-OUT pipe also blocked
498 * us from sending any more CTLX URBs, so
499 * we need to re-run our queue ...
500 */
501 hfa384x_usbctlxq_run(hw);
502 }
503 }
504
505 /* Resume transmitting. */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100506 if (test_and_clear_bit(WORK_TX_RESUME, &hw->usb_flags))
Solomon Peachycbec30c2008-10-29 10:42:57 -0400507 netif_wake_queue(hw->wlandev->netdev);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700508}
509
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700510/*----------------------------------------------------------------
511* hfa384x_create
512*
513* Sets up the hfa384x_t data structure for use. Note this
Uwe Kleine-König9b0131c2010-09-01 15:40:25 +0200514* does _not_ initialize the actual hardware, just the data structures
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700515* we use to keep track of its state.
516*
517* Arguments:
518* hw device structure
519* irq device irq number
520* iobase i/o base address for register access
521* membase memory base address for register access
522*
523* Returns:
524* nothing
525*
526* Side effects:
527*
528* Call context:
529* process
530----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530531void hfa384x_create(hfa384x_t *hw, struct usb_device *usb)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700532{
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700533 memset(hw, 0, sizeof(hfa384x_t));
534 hw->usb = usb;
535
536 /* set up the endpoints */
537 hw->endp_in = usb_rcvbulkpipe(usb, 1);
538 hw->endp_out = usb_sndbulkpipe(usb, 2);
539
540 /* Set up the waitq */
541 init_waitqueue_head(&hw->cmdq);
542
543 /* Initialize the command queue */
544 spin_lock_init(&hw->ctlxq.lock);
545 INIT_LIST_HEAD(&hw->ctlxq.pending);
546 INIT_LIST_HEAD(&hw->ctlxq.active);
547 INIT_LIST_HEAD(&hw->ctlxq.completing);
548 INIT_LIST_HEAD(&hw->ctlxq.reapable);
549
550 /* Initialize the authentication queue */
551 skb_queue_head_init(&hw->authq);
552
553 tasklet_init(&hw->reaper_bh,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100554 hfa384x_usbctlx_reaper_task, (unsigned long)hw);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700555 tasklet_init(&hw->completion_bh,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100556 hfa384x_usbctlx_completion_task, (unsigned long)hw);
Solomon Peachy575a8a52008-10-29 10:42:54 -0400557 INIT_WORK(&hw->link_bh, prism2sta_processing_defer);
558 INIT_WORK(&hw->usb_work, hfa384x_usb_defer);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700559
560 init_timer(&hw->throttle);
561 hw->throttle.function = hfa384x_usb_throttlefn;
562 hw->throttle.data = (unsigned long)hw;
563
564 init_timer(&hw->resptimer);
565 hw->resptimer.function = hfa384x_usbctlx_resptimerfn;
566 hw->resptimer.data = (unsigned long)hw;
567
568 init_timer(&hw->reqtimer);
569 hw->reqtimer.function = hfa384x_usbctlx_reqtimerfn;
570 hw->reqtimer.data = (unsigned long)hw;
571
572 usb_init_urb(&hw->rx_urb);
573 usb_init_urb(&hw->tx_urb);
574 usb_init_urb(&hw->ctlx_urb);
575
576 hw->link_status = HFA384x_LINK_NOTCONNECTED;
577 hw->state = HFA384x_STATE_INIT;
578
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100579 INIT_WORK(&hw->commsqual_bh, prism2sta_commsqual_defer);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700580 init_timer(&hw->commsqual_timer);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100581 hw->commsqual_timer.data = (unsigned long)hw;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700582 hw->commsqual_timer.function = prism2sta_commsqual_timer;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700583}
584
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700585/*----------------------------------------------------------------
586* hfa384x_destroy
587*
588* Partner to hfa384x_create(). This function cleans up the hw
589* structure so that it can be freed by the caller using a simple
590* kfree. Currently, this function is just a placeholder. If, at some
591* point in the future, an hw in the 'shutdown' state requires a 'deep'
592* kfree, this is where it should be done. Note that if this function
593* is called on a _running_ hw structure, the drvr_stop() function is
594* called.
595*
596* Arguments:
597* hw device structure
598*
599* Returns:
600* nothing, this function is not allowed to fail.
601*
602* Side effects:
603*
604* Call context:
605* process
606----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530607void hfa384x_destroy(hfa384x_t *hw)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700608{
609 struct sk_buff *skb;
610
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100611 if (hw->state == HFA384x_STATE_RUNNING)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700612 hfa384x_drvr_stop(hw);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700613 hw->state = HFA384x_STATE_PREINIT;
614
Ilia Mirkina6f9c482011-03-13 00:29:17 -0500615 kfree(hw->scanresults);
616 hw->scanresults = NULL;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700617
618 /* Now to clean out the auth queue */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100619 while ((skb = skb_dequeue(&hw->authq)))
620 dev_kfree_skb(skb);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700621}
622
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100623static hfa384x_usbctlx_t *usbctlx_alloc(void)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700624{
625 hfa384x_usbctlx_t *ctlx;
626
Svenne Krap5dd8acc2010-02-14 18:59:00 +0100627 ctlx = kmalloc(sizeof(*ctlx), in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100628 if (ctlx != NULL) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700629 memset(ctlx, 0, sizeof(*ctlx));
630 init_completion(&ctlx->done);
631 }
632
633 return ctlx;
634}
635
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700636static int
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530637usbctlx_get_status(const hfa384x_usb_cmdresp_t *cmdresp,
638 hfa384x_cmdresult_t *result)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700639{
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100640 result->status = le16_to_cpu(cmdresp->status);
641 result->resp0 = le16_to_cpu(cmdresp->resp0);
642 result->resp1 = le16_to_cpu(cmdresp->resp1);
643 result->resp2 = le16_to_cpu(cmdresp->resp2);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700644
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +0100645 pr_debug("cmdresult:status=0x%04x "
Mithlesh Thukral75f49e02009-05-25 19:06:16 +0530646 "resp0=0x%04x resp1=0x%04x resp2=0x%04x\n",
647 result->status, result->resp0, result->resp1, result->resp2);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700648
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100649 return result->status & HFA384x_STATUS_RESULT;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700650}
651
652static void
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530653usbctlx_get_rridresult(const hfa384x_usb_rridresp_t *rridresp,
654 hfa384x_rridresult_t *result)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700655{
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100656 result->rid = le16_to_cpu(rridresp->rid);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700657 result->riddata = rridresp->data;
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100658 result->riddata_len = ((le16_to_cpu(rridresp->frmlen) - 1) * 2);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700659
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700660}
661
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700662/*----------------------------------------------------------------
663* Completor object:
664* This completor must be passed to hfa384x_usbctlx_complete_sync()
665* when processing a CTLX that returns a hfa384x_cmdresult_t structure.
666----------------------------------------------------------------*/
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100667struct usbctlx_cmd_completor {
Edgardo Hames631c8de2010-03-08 17:02:37 -0800668 struct usbctlx_completor head;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700669
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100670 const hfa384x_usb_cmdresp_t *cmdresp;
671 hfa384x_cmdresult_t *result;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700672};
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700673
Edgardo Hames631c8de2010-03-08 17:02:37 -0800674static inline int usbctlx_cmd_completor_fn(struct usbctlx_completor *head)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700675{
Edgardo Hames631c8de2010-03-08 17:02:37 -0800676 struct usbctlx_cmd_completor *complete;
677
678 complete = (struct usbctlx_cmd_completor *) head;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700679 return usbctlx_get_status(complete->cmdresp, complete->result);
680}
681
Edgardo Hames631c8de2010-03-08 17:02:37 -0800682static inline struct usbctlx_completor *init_cmd_completor(
683 struct usbctlx_cmd_completor
684 *completor,
685 const hfa384x_usb_cmdresp_t
686 *cmdresp,
687 hfa384x_cmdresult_t *result)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700688{
689 completor->head.complete = usbctlx_cmd_completor_fn;
690 completor->cmdresp = cmdresp;
691 completor->result = result;
692 return &(completor->head);
693}
694
695/*----------------------------------------------------------------
696* Completor object:
697* This completor must be passed to hfa384x_usbctlx_complete_sync()
698* when processing a CTLX that reads a RID.
699----------------------------------------------------------------*/
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100700struct usbctlx_rrid_completor {
Edgardo Hames631c8de2010-03-08 17:02:37 -0800701 struct usbctlx_completor head;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700702
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100703 const hfa384x_usb_rridresp_t *rridresp;
704 void *riddata;
705 unsigned int riddatalen;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700706};
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700707
Edgardo Hames631c8de2010-03-08 17:02:37 -0800708static int usbctlx_rrid_completor_fn(struct usbctlx_completor *head)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700709{
Edgardo Hames631c8de2010-03-08 17:02:37 -0800710 struct usbctlx_rrid_completor *complete;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700711 hfa384x_rridresult_t rridresult;
712
Edgardo Hames631c8de2010-03-08 17:02:37 -0800713 complete = (struct usbctlx_rrid_completor *) head;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700714 usbctlx_get_rridresult(complete->rridresp, &rridresult);
715
716 /* Validate the length, note body len calculation in bytes */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100717 if (rridresult.riddata_len != complete->riddatalen) {
Moritz Muehlenhoff9b9556e2009-01-25 21:55:01 +0100718 printk(KERN_WARNING
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100719 "RID len mismatch, rid=0x%04x hlen=%d fwlen=%d\n",
720 rridresult.rid,
721 complete->riddatalen, rridresult.riddata_len);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700722 return -ENODATA;
723 }
724
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100725 memcpy(complete->riddata, rridresult.riddata, complete->riddatalen);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700726 return 0;
727}
728
Edgardo Hames631c8de2010-03-08 17:02:37 -0800729static inline struct usbctlx_completor *init_rrid_completor(
730 struct usbctlx_rrid_completor
731 *completor,
732 const hfa384x_usb_rridresp_t
733 *rridresp,
734 void *riddata,
735 unsigned int riddatalen)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700736{
737 completor->head.complete = usbctlx_rrid_completor_fn;
738 completor->rridresp = rridresp;
739 completor->riddata = riddata;
740 completor->riddatalen = riddatalen;
741 return &(completor->head);
742}
743
744/*----------------------------------------------------------------
745* Completor object:
746* Interprets the results of a synchronous RID-write
747----------------------------------------------------------------*/
Edgardo Hames631c8de2010-03-08 17:02:37 -0800748typedef struct usbctlx_cmd_completor usbctlx_wrid_completor_t;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700749#define init_wrid_completor init_cmd_completor
750
751/*----------------------------------------------------------------
752* Completor object:
753* Interprets the results of a synchronous memory-write
754----------------------------------------------------------------*/
Edgardo Hames631c8de2010-03-08 17:02:37 -0800755typedef struct usbctlx_cmd_completor usbctlx_wmem_completor_t;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700756#define init_wmem_completor init_cmd_completor
757
758/*----------------------------------------------------------------
759* Completor object:
760* Interprets the results of a synchronous memory-read
761----------------------------------------------------------------*/
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100762struct usbctlx_rmem_completor {
Edgardo Hames631c8de2010-03-08 17:02:37 -0800763 struct usbctlx_completor head;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700764
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100765 const hfa384x_usb_rmemresp_t *rmemresp;
766 void *data;
767 unsigned int len;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700768};
769typedef struct usbctlx_rmem_completor usbctlx_rmem_completor_t;
770
Edgardo Hames631c8de2010-03-08 17:02:37 -0800771static int usbctlx_rmem_completor_fn(struct usbctlx_completor *head)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700772{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100773 usbctlx_rmem_completor_t *complete = (usbctlx_rmem_completor_t *) head;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700774
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +0100775 pr_debug("rmemresp:len=%d\n", complete->rmemresp->frmlen);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700776 memcpy(complete->data, complete->rmemresp->data, complete->len);
777 return 0;
778}
779
Edgardo Hames631c8de2010-03-08 17:02:37 -0800780static inline struct usbctlx_completor *init_rmem_completor(
781 usbctlx_rmem_completor_t
782 *completor,
783 hfa384x_usb_rmemresp_t
784 *rmemresp,
785 void *data,
786 unsigned int len)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700787{
788 completor->head.complete = usbctlx_rmem_completor_fn;
789 completor->rmemresp = rmemresp;
790 completor->data = data;
791 completor->len = len;
792 return &(completor->head);
793}
794
795/*----------------------------------------------------------------
796* hfa384x_cb_status
797*
798* Ctlx_complete handler for async CMD type control exchanges.
799* mark the hw struct as such.
800*
801* Note: If the handling is changed here, it should probably be
802* changed in docmd as well.
803*
804* Arguments:
805* hw hw struct
806* ctlx completed CTLX
807*
808* Returns:
809* nothing
810*
811* Side effects:
812*
813* Call context:
814* interrupt
815----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530816static void hfa384x_cb_status(hfa384x_t *hw, const hfa384x_usbctlx_t *ctlx)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700817{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100818 if (ctlx->usercb != NULL) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700819 hfa384x_cmdresult_t cmdresult;
820
821 if (ctlx->state != CTLX_COMPLETE) {
822 memset(&cmdresult, 0, sizeof(cmdresult));
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100823 cmdresult.status =
824 HFA384x_STATUS_RESULT_SET(HFA384x_CMD_ERR);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700825 } else {
826 usbctlx_get_status(&ctlx->inbuf.cmdresp, &cmdresult);
827 }
828
829 ctlx->usercb(hw, &cmdresult, ctlx->usercb_data);
830 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700831}
832
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700833/*----------------------------------------------------------------
834* hfa384x_cb_rrid
835*
836* CTLX completion handler for async RRID type control exchanges.
837*
838* Note: If the handling is changed here, it should probably be
839* changed in dorrid as well.
840*
841* Arguments:
842* hw hw struct
843* ctlx completed CTLX
844*
845* Returns:
846* nothing
847*
848* Side effects:
849*
850* Call context:
851* interrupt
852----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530853static void hfa384x_cb_rrid(hfa384x_t *hw, const hfa384x_usbctlx_t *ctlx)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700854{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100855 if (ctlx->usercb != NULL) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700856 hfa384x_rridresult_t rridresult;
857
858 if (ctlx->state != CTLX_COMPLETE) {
859 memset(&rridresult, 0, sizeof(rridresult));
Mithlesh Thukral75f49e02009-05-25 19:06:16 +0530860 rridresult.rid = le16_to_cpu(ctlx->outbuf.rridreq.rid);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700861 } else {
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100862 usbctlx_get_rridresult(&ctlx->inbuf.rridresp,
863 &rridresult);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700864 }
865
866 ctlx->usercb(hw, &rridresult, ctlx->usercb_data);
867 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700868}
869
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530870static inline int hfa384x_docmd_wait(hfa384x_t *hw, hfa384x_metacmd_t *cmd)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700871{
872 return hfa384x_docmd(hw, DOWAIT, cmd, NULL, NULL, NULL);
873}
874
875static inline int
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530876hfa384x_docmd_async(hfa384x_t *hw,
877 hfa384x_metacmd_t *cmd,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100878 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700879{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100880 return hfa384x_docmd(hw, DOASYNC, cmd, cmdcb, usercb, usercb_data);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700881}
882
883static inline int
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530884hfa384x_dorrid_wait(hfa384x_t *hw, u16 rid, void *riddata,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100885 unsigned int riddatalen)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700886{
887 return hfa384x_dorrid(hw, DOWAIT,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100888 rid, riddata, riddatalen, NULL, NULL, NULL);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700889}
890
891static inline int
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530892hfa384x_dorrid_async(hfa384x_t *hw,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100893 u16 rid, void *riddata, unsigned int riddatalen,
894 ctlx_cmdcb_t cmdcb,
895 ctlx_usercb_t usercb, void *usercb_data)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700896{
897 return hfa384x_dorrid(hw, DOASYNC,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100898 rid, riddata, riddatalen,
899 cmdcb, usercb, usercb_data);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700900}
901
902static inline int
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530903hfa384x_dowrid_wait(hfa384x_t *hw, u16 rid, void *riddata,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100904 unsigned int riddatalen)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700905{
906 return hfa384x_dowrid(hw, DOWAIT,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100907 rid, riddata, riddatalen, NULL, NULL, NULL);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700908}
909
910static inline int
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530911hfa384x_dowrid_async(hfa384x_t *hw,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100912 u16 rid, void *riddata, unsigned int riddatalen,
913 ctlx_cmdcb_t cmdcb,
914 ctlx_usercb_t usercb, void *usercb_data)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700915{
916 return hfa384x_dowrid(hw, DOASYNC,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100917 rid, riddata, riddatalen,
918 cmdcb, usercb, usercb_data);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700919}
920
921static inline int
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530922hfa384x_dormem_wait(hfa384x_t *hw,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100923 u16 page, u16 offset, void *data, unsigned int len)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700924{
925 return hfa384x_dormem(hw, DOWAIT,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100926 page, offset, data, len, NULL, NULL, NULL);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700927}
928
929static inline int
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530930hfa384x_dormem_async(hfa384x_t *hw,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100931 u16 page, u16 offset, void *data, unsigned int len,
932 ctlx_cmdcb_t cmdcb,
933 ctlx_usercb_t usercb, void *usercb_data)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700934{
935 return hfa384x_dormem(hw, DOASYNC,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100936 page, offset, data, len,
937 cmdcb, usercb, usercb_data);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700938}
939
940static inline int
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530941hfa384x_dowmem_wait(hfa384x_t *hw,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100942 u16 page, u16 offset, void *data, unsigned int len)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700943{
944 return hfa384x_dowmem(hw, DOWAIT,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100945 page, offset, data, len, NULL, NULL, NULL);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700946}
947
948static inline int
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530949hfa384x_dowmem_async(hfa384x_t *hw,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100950 u16 page,
951 u16 offset,
952 void *data,
953 unsigned int len,
954 ctlx_cmdcb_t cmdcb,
955 ctlx_usercb_t usercb, void *usercb_data)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700956{
957 return hfa384x_dowmem(hw, DOASYNC,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100958 page, offset, data, len,
959 cmdcb, usercb, usercb_data);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700960}
961
962/*----------------------------------------------------------------
963* hfa384x_cmd_initialize
964*
965* Issues the initialize command and sets the hw->state based
966* on the result.
967*
968* Arguments:
969* hw device structure
970*
971* Returns:
972* 0 success
973* >0 f/w reported error - f/w status code
974* <0 driver reported error
975*
976* Side effects:
977*
978* Call context:
979* process
980----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +0530981int hfa384x_cmd_initialize(hfa384x_t *hw)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700982{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100983 int result = 0;
984 int i;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700985 hfa384x_metacmd_t cmd;
986
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700987 cmd.cmd = HFA384x_CMDCODE_INIT;
988 cmd.parm0 = 0;
989 cmd.parm1 = 0;
990 cmd.parm2 = 0;
991
992 result = hfa384x_docmd_wait(hw, &cmd);
993
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +0100994 pr_debug("cmdresp.init: "
Mithlesh Thukral75f49e02009-05-25 19:06:16 +0530995 "status=0x%04x, resp0=0x%04x, "
996 "resp1=0x%04x, resp2=0x%04x\n",
997 cmd.result.status,
998 cmd.result.resp0, cmd.result.resp1, cmd.result.resp2);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100999 if (result == 0) {
1000 for (i = 0; i < HFA384x_NUMPORTS_MAX; i++)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001001 hw->port_enabled[i] = 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001002 }
1003
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001004 hw->link_status = HFA384x_LINK_NOTCONNECTED;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001005
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001006 return result;
1007}
1008
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001009/*----------------------------------------------------------------
1010* hfa384x_cmd_disable
1011*
1012* Issues the disable command to stop communications on one of
1013* the MACs 'ports'.
1014*
1015* Arguments:
1016* hw device structure
1017* macport MAC port number (host order)
1018*
1019* Returns:
1020* 0 success
1021* >0 f/w reported failure - f/w status code
1022* <0 driver reported error (timeout|bad arg)
1023*
1024* Side effects:
1025*
1026* Call context:
1027* process
1028----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +05301029int hfa384x_cmd_disable(hfa384x_t *hw, u16 macport)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001030{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001031 int result = 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001032 hfa384x_metacmd_t cmd;
1033
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001034 cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_DISABLE) |
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001035 HFA384x_CMD_MACPORT_SET(macport);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001036 cmd.parm0 = 0;
1037 cmd.parm1 = 0;
1038 cmd.parm2 = 0;
1039
1040 result = hfa384x_docmd_wait(hw, &cmd);
1041
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001042 return result;
1043}
1044
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001045/*----------------------------------------------------------------
1046* hfa384x_cmd_enable
1047*
1048* Issues the enable command to enable communications on one of
1049* the MACs 'ports'.
1050*
1051* Arguments:
1052* hw device structure
1053* macport MAC port number
1054*
1055* Returns:
1056* 0 success
1057* >0 f/w reported failure - f/w status code
1058* <0 driver reported error (timeout|bad arg)
1059*
1060* Side effects:
1061*
1062* Call context:
1063* process
1064----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +05301065int hfa384x_cmd_enable(hfa384x_t *hw, u16 macport)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001066{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001067 int result = 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001068 hfa384x_metacmd_t cmd;
1069
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001070 cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_ENABLE) |
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001071 HFA384x_CMD_MACPORT_SET(macport);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001072 cmd.parm0 = 0;
1073 cmd.parm1 = 0;
1074 cmd.parm2 = 0;
1075
1076 result = hfa384x_docmd_wait(hw, &cmd);
1077
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001078 return result;
1079}
1080
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001081/*----------------------------------------------------------------
1082* hfa384x_cmd_monitor
1083*
1084* Enables the 'monitor mode' of the MAC. Here's the description of
1085* monitor mode that I've received thus far:
1086*
1087* "The "monitor mode" of operation is that the MAC passes all
1088* frames for which the PLCP checks are correct. All received
1089* MPDUs are passed to the host with MAC Port = 7, with a
1090* receive status of good, FCS error, or undecryptable. Passing
1091* certain MPDUs is a violation of the 802.11 standard, but useful
1092* for a debugging tool." Normal communication is not possible
1093* while monitor mode is enabled.
1094*
1095* Arguments:
1096* hw device structure
1097* enable a code (0x0b|0x0f) that enables/disables
1098* monitor mode. (host order)
1099*
1100* Returns:
1101* 0 success
1102* >0 f/w reported failure - f/w status code
1103* <0 driver reported error (timeout|bad arg)
1104*
1105* Side effects:
1106*
1107* Call context:
1108* process
1109----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +05301110int hfa384x_cmd_monitor(hfa384x_t *hw, u16 enable)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001111{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001112 int result = 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001113 hfa384x_metacmd_t cmd;
1114
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001115 cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_MONITOR) |
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001116 HFA384x_CMD_AINFO_SET(enable);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001117 cmd.parm0 = 0;
1118 cmd.parm1 = 0;
1119 cmd.parm2 = 0;
1120
1121 result = hfa384x_docmd_wait(hw, &cmd);
1122
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001123 return result;
1124}
1125
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001126/*----------------------------------------------------------------
1127* hfa384x_cmd_download
1128*
1129* Sets the controls for the MAC controller code/data download
1130* process. The arguments set the mode and address associated
1131* with a download. Note that the aux registers should be enabled
1132* prior to setting one of the download enable modes.
1133*
1134* Arguments:
1135* hw device structure
1136* mode 0 - Disable programming and begin code exec
1137* 1 - Enable volatile mem programming
1138* 2 - Enable non-volatile mem programming
1139* 3 - Program non-volatile section from NV download
1140* buffer.
1141* (host order)
1142* lowaddr
1143* highaddr For mode 1, sets the high & low order bits of
1144* the "destination address". This address will be
1145* the execution start address when download is
1146* subsequently disabled.
1147* For mode 2, sets the high & low order bits of
1148* the destination in NV ram.
1149* For modes 0 & 3, should be zero. (host order)
1150* NOTE: these are CMD format.
1151* codelen Length of the data to write in mode 2,
1152* zero otherwise. (host order)
1153*
1154* Returns:
1155* 0 success
1156* >0 f/w reported failure - f/w status code
1157* <0 driver reported error (timeout|bad arg)
1158*
1159* Side effects:
1160*
1161* Call context:
1162* process
1163----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +05301164int hfa384x_cmd_download(hfa384x_t *hw, u16 mode, u16 lowaddr,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001165 u16 highaddr, u16 codelen)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001166{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001167 int result = 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001168 hfa384x_metacmd_t cmd;
1169
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301170 pr_debug("mode=%d, lowaddr=0x%04x, highaddr=0x%04x, codelen=%d\n",
1171 mode, lowaddr, highaddr, codelen);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001172
1173 cmd.cmd = (HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_DOWNLD) |
1174 HFA384x_CMD_PROGMODE_SET(mode));
1175
1176 cmd.parm0 = lowaddr;
1177 cmd.parm1 = highaddr;
1178 cmd.parm2 = codelen;
1179
1180 result = hfa384x_docmd_wait(hw, &cmd);
1181
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001182 return result;
1183}
1184
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001185/*----------------------------------------------------------------
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001186* hfa384x_corereset
1187*
1188* Perform a reset of the hfa38xx MAC core. We assume that the hw
1189* structure is in its "created" state. That is, it is initialized
1190* with proper values. Note that if a reset is done after the
1191* device has been active for awhile, the caller might have to clean
1192* up some leftover cruft in the hw structure.
1193*
1194* Arguments:
1195* hw device structure
1196* holdtime how long (in ms) to hold the reset
1197* settletime how long (in ms) to wait after releasing
1198* the reset
1199*
1200* Returns:
1201* nothing
1202*
1203* Side effects:
1204*
1205* Call context:
1206* process
1207----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +05301208int hfa384x_corereset(hfa384x_t *hw, int holdtime, int settletime, int genesis)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001209{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001210 int result = 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001211
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001212 result = usb_reset_device(hw->usb);
1213 if (result < 0) {
1214 printk(KERN_ERR "usb_reset_device() failed, result=%d.\n",
1215 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001216 }
1217
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001218 return result;
1219}
1220
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001221/*----------------------------------------------------------------
1222* hfa384x_usbctlx_complete_sync
1223*
1224* Waits for a synchronous CTLX object to complete,
1225* and then handles the response.
1226*
1227* Arguments:
1228* hw device structure
Edgardo Hames631c8de2010-03-08 17:02:37 -08001229* ctlx CTLX ptr
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001230* completor functor object to decide what to
1231* do with the CTLX's result.
1232*
1233* Returns:
1234* 0 Success
1235* -ERESTARTSYS Interrupted by a signal
1236* -EIO CTLX failed
1237* -ENODEV Adapter was unplugged
1238* ??? Result from completor
1239*
1240* Side effects:
1241*
1242* Call context:
1243* process
1244----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +05301245static int hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
1246 hfa384x_usbctlx_t *ctlx,
Edgardo Hames631c8de2010-03-08 17:02:37 -08001247 struct usbctlx_completor *completor)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001248{
1249 unsigned long flags;
1250 int result;
1251
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001252 result = wait_for_completion_interruptible(&ctlx->done);
1253
1254 spin_lock_irqsave(&hw->ctlxq.lock, flags);
1255
1256 /*
1257 * We can only handle the CTLX if the USB disconnect
1258 * function has not run yet ...
1259 */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001260cleanup:
1261 if (hw->wlandev->hwremoved) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001262 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1263 result = -ENODEV;
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001264 } else if (result != 0) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001265 int runqueue = 0;
1266
1267 /*
1268 * We were probably interrupted, so delete
1269 * this CTLX asynchronously, kill the timers
1270 * and the URB, and then start the next
1271 * pending CTLX.
1272 *
1273 * NOTE: We can only delete the timers and
1274 * the URB if this CTLX is active.
1275 */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001276 if (ctlx == get_active_ctlx(hw)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001277 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1278
1279 del_singleshot_timer_sync(&hw->reqtimer);
1280 del_singleshot_timer_sync(&hw->resptimer);
1281 hw->req_timer_done = 1;
1282 hw->resp_timer_done = 1;
1283 usb_kill_urb(&hw->ctlx_urb);
1284
1285 spin_lock_irqsave(&hw->ctlxq.lock, flags);
1286
1287 runqueue = 1;
1288
1289 /*
1290 * This scenario is so unlikely that I'm
1291 * happy with a grubby "goto" solution ...
1292 */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001293 if (hw->wlandev->hwremoved)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001294 goto cleanup;
1295 }
1296
1297 /*
1298 * The completion task will send this CTLX
1299 * to the reaper the next time it runs. We
1300 * are no longer in a hurry.
1301 */
1302 ctlx->reapable = 1;
1303 ctlx->state = CTLX_REQ_FAILED;
1304 list_move_tail(&ctlx->list, &hw->ctlxq.completing);
1305
1306 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1307
1308 if (runqueue)
1309 hfa384x_usbctlxq_run(hw);
1310 } else {
1311 if (ctlx->state == CTLX_COMPLETE) {
1312 result = completor->complete(completor);
1313 } else {
Moritz Muehlenhoff9b9556e2009-01-25 21:55:01 +01001314 printk(KERN_WARNING "CTLX[%d] error: state(%s)\n",
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01001315 le16_to_cpu(ctlx->outbuf.type),
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001316 ctlxstr(ctlx->state));
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001317 result = -EIO;
1318 }
1319
1320 list_del(&ctlx->list);
1321 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1322 kfree(ctlx);
1323 }
1324
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001325 return result;
1326}
1327
1328/*----------------------------------------------------------------
1329* hfa384x_docmd
1330*
1331* Constructs a command CTLX and submits it.
1332*
1333* NOTE: Any changes to the 'post-submit' code in this function
1334* need to be carried over to hfa384x_cbcmd() since the handling
1335* is virtually identical.
1336*
1337* Arguments:
1338* hw device structure
1339* mode DOWAIT or DOASYNC
1340* cmd cmd structure. Includes all arguments and result
1341* data points. All in host order. in host order
1342* cmdcb command-specific callback
1343* usercb user callback for async calls, NULL for DOWAIT calls
1344* usercb_data user supplied data pointer for async calls, NULL
1345* for DOASYNC calls
1346*
1347* Returns:
1348* 0 success
1349* -EIO CTLX failure
1350* -ERESTARTSYS Awakened on signal
1351* >0 command indicated error, Status and Resp0-2 are
1352* in hw structure.
1353*
1354* Side effects:
1355*
1356*
1357* Call context:
1358* process
1359----------------------------------------------------------------*/
1360static int
Mithlesh Thukral297f06c2009-06-10 19:36:11 +05301361hfa384x_docmd(hfa384x_t *hw,
Edgardo Hames631c8de2010-03-08 17:02:37 -08001362 enum cmd_mode mode,
Mithlesh Thukral297f06c2009-06-10 19:36:11 +05301363 hfa384x_metacmd_t *cmd,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001364 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001365{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001366 int result;
1367 hfa384x_usbctlx_t *ctlx;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001368
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001369 ctlx = usbctlx_alloc();
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001370 if (ctlx == NULL) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001371 result = -ENOMEM;
1372 goto done;
1373 }
1374
1375 /* Initialize the command */
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01001376 ctlx->outbuf.cmdreq.type = cpu_to_le16(HFA384x_USB_CMDREQ);
1377 ctlx->outbuf.cmdreq.cmd = cpu_to_le16(cmd->cmd);
1378 ctlx->outbuf.cmdreq.parm0 = cpu_to_le16(cmd->parm0);
1379 ctlx->outbuf.cmdreq.parm1 = cpu_to_le16(cmd->parm1);
1380 ctlx->outbuf.cmdreq.parm2 = cpu_to_le16(cmd->parm2);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001381
1382 ctlx->outbufsize = sizeof(ctlx->outbuf.cmdreq);
1383
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +01001384 pr_debug("cmdreq: cmd=0x%04x "
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301385 "parm0=0x%04x parm1=0x%04x parm2=0x%04x\n",
1386 cmd->cmd, cmd->parm0, cmd->parm1, cmd->parm2);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001387
1388 ctlx->reapable = mode;
1389 ctlx->cmdcb = cmdcb;
1390 ctlx->usercb = usercb;
1391 ctlx->usercb_data = usercb_data;
1392
1393 result = hfa384x_usbctlx_submit(hw, ctlx);
1394 if (result != 0) {
1395 kfree(ctlx);
1396 } else if (mode == DOWAIT) {
Edgardo Hames631c8de2010-03-08 17:02:37 -08001397 struct usbctlx_cmd_completor completor;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001398
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001399 result =
1400 hfa384x_usbctlx_complete_sync(hw, ctlx,
1401 init_cmd_completor(&completor,
1402 &ctlx->
1403 inbuf.
1404 cmdresp,
1405 &cmd->
1406 result));
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001407 }
1408
1409done:
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001410 return result;
1411}
1412
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001413/*----------------------------------------------------------------
1414* hfa384x_dorrid
1415*
1416* Constructs a read rid CTLX and issues it.
1417*
1418* NOTE: Any changes to the 'post-submit' code in this function
1419* need to be carried over to hfa384x_cbrrid() since the handling
1420* is virtually identical.
1421*
1422* Arguments:
1423* hw device structure
1424* mode DOWAIT or DOASYNC
1425* rid Read RID number (host order)
1426* riddata Caller supplied buffer that MAC formatted RID.data
1427* record will be written to for DOWAIT calls. Should
1428* be NULL for DOASYNC calls.
1429* riddatalen Buffer length for DOWAIT calls. Zero for DOASYNC calls.
1430* cmdcb command callback for async calls, NULL for DOWAIT calls
1431* usercb user callback for async calls, NULL for DOWAIT calls
1432* usercb_data user supplied data pointer for async calls, NULL
1433* for DOWAIT calls
1434*
1435* Returns:
1436* 0 success
1437* -EIO CTLX failure
1438* -ERESTARTSYS Awakened on signal
1439* -ENODATA riddatalen != macdatalen
1440* >0 command indicated error, Status and Resp0-2 are
1441* in hw structure.
1442*
1443* Side effects:
1444*
1445* Call context:
1446* interrupt (DOASYNC)
1447* process (DOWAIT or DOASYNC)
1448----------------------------------------------------------------*/
1449static int
Mithlesh Thukral297f06c2009-06-10 19:36:11 +05301450hfa384x_dorrid(hfa384x_t *hw,
Edgardo Hames631c8de2010-03-08 17:02:37 -08001451 enum cmd_mode mode,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001452 u16 rid,
1453 void *riddata,
1454 unsigned int riddatalen,
1455 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001456{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001457 int result;
1458 hfa384x_usbctlx_t *ctlx;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001459
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001460 ctlx = usbctlx_alloc();
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001461 if (ctlx == NULL) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001462 result = -ENOMEM;
1463 goto done;
1464 }
1465
1466 /* Initialize the command */
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01001467 ctlx->outbuf.rridreq.type = cpu_to_le16(HFA384x_USB_RRIDREQ);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001468 ctlx->outbuf.rridreq.frmlen =
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01001469 cpu_to_le16(sizeof(ctlx->outbuf.rridreq.rid));
1470 ctlx->outbuf.rridreq.rid = cpu_to_le16(rid);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001471
1472 ctlx->outbufsize = sizeof(ctlx->outbuf.rridreq);
1473
1474 ctlx->reapable = mode;
1475 ctlx->cmdcb = cmdcb;
1476 ctlx->usercb = usercb;
1477 ctlx->usercb_data = usercb_data;
1478
1479 /* Submit the CTLX */
1480 result = hfa384x_usbctlx_submit(hw, ctlx);
1481 if (result != 0) {
1482 kfree(ctlx);
1483 } else if (mode == DOWAIT) {
Edgardo Hames631c8de2010-03-08 17:02:37 -08001484 struct usbctlx_rrid_completor completor;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001485
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001486 result =
1487 hfa384x_usbctlx_complete_sync(hw, ctlx,
1488 init_rrid_completor
1489 (&completor,
1490 &ctlx->inbuf.rridresp,
1491 riddata, riddatalen));
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001492 }
1493
1494done:
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001495 return result;
1496}
1497
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001498/*----------------------------------------------------------------
1499* hfa384x_dowrid
1500*
1501* Constructs a write rid CTLX and issues it.
1502*
1503* NOTE: Any changes to the 'post-submit' code in this function
1504* need to be carried over to hfa384x_cbwrid() since the handling
1505* is virtually identical.
1506*
1507* Arguments:
1508* hw device structure
Edgardo Hames631c8de2010-03-08 17:02:37 -08001509* enum cmd_mode DOWAIT or DOASYNC
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001510* rid RID code
1511* riddata Data portion of RID formatted for MAC
1512* riddatalen Length of the data portion in bytes
1513* cmdcb command callback for async calls, NULL for DOWAIT calls
1514* usercb user callback for async calls, NULL for DOWAIT calls
1515* usercb_data user supplied data pointer for async calls
1516*
1517* Returns:
1518* 0 success
1519* -ETIMEDOUT timed out waiting for register ready or
1520* command completion
1521* >0 command indicated error, Status and Resp0-2 are
1522* in hw structure.
1523*
1524* Side effects:
1525*
1526* Call context:
1527* interrupt (DOASYNC)
1528* process (DOWAIT or DOASYNC)
1529----------------------------------------------------------------*/
1530static int
Mithlesh Thukral297f06c2009-06-10 19:36:11 +05301531hfa384x_dowrid(hfa384x_t *hw,
Edgardo Hames631c8de2010-03-08 17:02:37 -08001532 enum cmd_mode mode,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001533 u16 rid,
1534 void *riddata,
1535 unsigned int riddatalen,
1536 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001537{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001538 int result;
1539 hfa384x_usbctlx_t *ctlx;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001540
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001541 ctlx = usbctlx_alloc();
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001542 if (ctlx == NULL) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001543 result = -ENOMEM;
1544 goto done;
1545 }
1546
1547 /* Initialize the command */
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01001548 ctlx->outbuf.wridreq.type = cpu_to_le16(HFA384x_USB_WRIDREQ);
1549 ctlx->outbuf.wridreq.frmlen = cpu_to_le16((sizeof
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301550 (ctlx->outbuf.wridreq.rid) +
1551 riddatalen + 1) / 2);
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01001552 ctlx->outbuf.wridreq.rid = cpu_to_le16(rid);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001553 memcpy(ctlx->outbuf.wridreq.data, riddata, riddatalen);
1554
1555 ctlx->outbufsize = sizeof(ctlx->outbuf.wridreq.type) +
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001556 sizeof(ctlx->outbuf.wridreq.frmlen) +
1557 sizeof(ctlx->outbuf.wridreq.rid) + riddatalen;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001558
1559 ctlx->reapable = mode;
1560 ctlx->cmdcb = cmdcb;
1561 ctlx->usercb = usercb;
1562 ctlx->usercb_data = usercb_data;
1563
1564 /* Submit the CTLX */
1565 result = hfa384x_usbctlx_submit(hw, ctlx);
1566 if (result != 0) {
1567 kfree(ctlx);
1568 } else if (mode == DOWAIT) {
1569 usbctlx_wrid_completor_t completor;
1570 hfa384x_cmdresult_t wridresult;
1571
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001572 result = hfa384x_usbctlx_complete_sync(hw,
1573 ctlx,
1574 init_wrid_completor
1575 (&completor,
1576 &ctlx->inbuf.wridresp,
1577 &wridresult));
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001578 }
1579
1580done:
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001581 return result;
1582}
1583
1584/*----------------------------------------------------------------
1585* hfa384x_dormem
1586*
1587* Constructs a readmem CTLX and issues it.
1588*
1589* NOTE: Any changes to the 'post-submit' code in this function
1590* need to be carried over to hfa384x_cbrmem() since the handling
1591* is virtually identical.
1592*
1593* Arguments:
1594* hw device structure
1595* mode DOWAIT or DOASYNC
1596* page MAC address space page (CMD format)
1597* offset MAC address space offset
1598* data Ptr to data buffer to receive read
1599* len Length of the data to read (max == 2048)
1600* cmdcb command callback for async calls, NULL for DOWAIT calls
1601* usercb user callback for async calls, NULL for DOWAIT calls
1602* usercb_data user supplied data pointer for async calls
1603*
1604* Returns:
1605* 0 success
1606* -ETIMEDOUT timed out waiting for register ready or
1607* command completion
1608* >0 command indicated error, Status and Resp0-2 are
1609* in hw structure.
1610*
1611* Side effects:
1612*
1613* Call context:
1614* interrupt (DOASYNC)
1615* process (DOWAIT or DOASYNC)
1616----------------------------------------------------------------*/
1617static int
Mithlesh Thukral297f06c2009-06-10 19:36:11 +05301618hfa384x_dormem(hfa384x_t *hw,
Edgardo Hames631c8de2010-03-08 17:02:37 -08001619 enum cmd_mode mode,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001620 u16 page,
1621 u16 offset,
1622 void *data,
1623 unsigned int len,
1624 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001625{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001626 int result;
1627 hfa384x_usbctlx_t *ctlx;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001628
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001629 ctlx = usbctlx_alloc();
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001630 if (ctlx == NULL) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001631 result = -ENOMEM;
1632 goto done;
1633 }
1634
1635 /* Initialize the command */
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01001636 ctlx->outbuf.rmemreq.type = cpu_to_le16(HFA384x_USB_RMEMREQ);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001637 ctlx->outbuf.rmemreq.frmlen =
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01001638 cpu_to_le16(sizeof(ctlx->outbuf.rmemreq.offset) +
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301639 sizeof(ctlx->outbuf.rmemreq.page) + len);
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01001640 ctlx->outbuf.rmemreq.offset = cpu_to_le16(offset);
1641 ctlx->outbuf.rmemreq.page = cpu_to_le16(page);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001642
1643 ctlx->outbufsize = sizeof(ctlx->outbuf.rmemreq);
1644
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301645 pr_debug("type=0x%04x frmlen=%d offset=0x%04x page=0x%04x\n",
1646 ctlx->outbuf.rmemreq.type,
1647 ctlx->outbuf.rmemreq.frmlen,
1648 ctlx->outbuf.rmemreq.offset, ctlx->outbuf.rmemreq.page);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001649
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301650 pr_debug("pktsize=%zd\n", ROUNDUP64(sizeof(ctlx->outbuf.rmemreq)));
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001651
1652 ctlx->reapable = mode;
1653 ctlx->cmdcb = cmdcb;
1654 ctlx->usercb = usercb;
1655 ctlx->usercb_data = usercb_data;
1656
1657 result = hfa384x_usbctlx_submit(hw, ctlx);
1658 if (result != 0) {
1659 kfree(ctlx);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001660 } else if (mode == DOWAIT) {
1661 usbctlx_rmem_completor_t completor;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001662
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001663 result =
1664 hfa384x_usbctlx_complete_sync(hw, ctlx,
1665 init_rmem_completor
1666 (&completor,
1667 &ctlx->inbuf.rmemresp, data,
1668 len));
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001669 }
1670
1671done:
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001672 return result;
1673}
1674
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001675/*----------------------------------------------------------------
1676* hfa384x_dowmem
1677*
1678* Constructs a writemem CTLX and issues it.
1679*
1680* NOTE: Any changes to the 'post-submit' code in this function
1681* need to be carried over to hfa384x_cbwmem() since the handling
1682* is virtually identical.
1683*
1684* Arguments:
1685* hw device structure
1686* mode DOWAIT or DOASYNC
1687* page MAC address space page (CMD format)
1688* offset MAC address space offset
1689* data Ptr to data buffer containing write data
1690* len Length of the data to read (max == 2048)
1691* cmdcb command callback for async calls, NULL for DOWAIT calls
1692* usercb user callback for async calls, NULL for DOWAIT calls
1693* usercb_data user supplied data pointer for async calls.
1694*
1695* Returns:
1696* 0 success
1697* -ETIMEDOUT timed out waiting for register ready or
1698* command completion
1699* >0 command indicated error, Status and Resp0-2 are
1700* in hw structure.
1701*
1702* Side effects:
1703*
1704* Call context:
1705* interrupt (DOWAIT)
1706* process (DOWAIT or DOASYNC)
1707----------------------------------------------------------------*/
1708static int
Mithlesh Thukral297f06c2009-06-10 19:36:11 +05301709hfa384x_dowmem(hfa384x_t *hw,
Edgardo Hames631c8de2010-03-08 17:02:37 -08001710 enum cmd_mode mode,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001711 u16 page,
1712 u16 offset,
1713 void *data,
1714 unsigned int len,
1715 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001716{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001717 int result;
1718 hfa384x_usbctlx_t *ctlx;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001719
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301720 pr_debug("page=0x%04x offset=0x%04x len=%d\n", page, offset, len);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001721
1722 ctlx = usbctlx_alloc();
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001723 if (ctlx == NULL) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001724 result = -ENOMEM;
1725 goto done;
1726 }
1727
1728 /* Initialize the command */
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01001729 ctlx->outbuf.wmemreq.type = cpu_to_le16(HFA384x_USB_WMEMREQ);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001730 ctlx->outbuf.wmemreq.frmlen =
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01001731 cpu_to_le16(sizeof(ctlx->outbuf.wmemreq.offset) +
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301732 sizeof(ctlx->outbuf.wmemreq.page) + len);
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01001733 ctlx->outbuf.wmemreq.offset = cpu_to_le16(offset);
1734 ctlx->outbuf.wmemreq.page = cpu_to_le16(page);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001735 memcpy(ctlx->outbuf.wmemreq.data, data, len);
1736
1737 ctlx->outbufsize = sizeof(ctlx->outbuf.wmemreq.type) +
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001738 sizeof(ctlx->outbuf.wmemreq.frmlen) +
1739 sizeof(ctlx->outbuf.wmemreq.offset) +
1740 sizeof(ctlx->outbuf.wmemreq.page) + len;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001741
1742 ctlx->reapable = mode;
1743 ctlx->cmdcb = cmdcb;
1744 ctlx->usercb = usercb;
1745 ctlx->usercb_data = usercb_data;
1746
1747 result = hfa384x_usbctlx_submit(hw, ctlx);
1748 if (result != 0) {
1749 kfree(ctlx);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001750 } else if (mode == DOWAIT) {
1751 usbctlx_wmem_completor_t completor;
1752 hfa384x_cmdresult_t wmemresult;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001753
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001754 result = hfa384x_usbctlx_complete_sync(hw,
1755 ctlx,
1756 init_wmem_completor
1757 (&completor,
1758 &ctlx->inbuf.wmemresp,
1759 &wmemresult));
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001760 }
1761
1762done:
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001763 return result;
1764}
1765
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001766/*----------------------------------------------------------------
1767* hfa384x_drvr_commtallies
1768*
1769* Send a commtallies inquiry to the MAC. Note that this is an async
1770* call that will result in an info frame arriving sometime later.
1771*
1772* Arguments:
1773* hw device structure
1774*
1775* Returns:
1776* zero success.
1777*
1778* Side effects:
1779*
1780* Call context:
1781* process
1782----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +05301783int hfa384x_drvr_commtallies(hfa384x_t *hw)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001784{
1785 hfa384x_metacmd_t cmd;
1786
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001787 cmd.cmd = HFA384x_CMDCODE_INQ;
1788 cmd.parm0 = HFA384x_IT_COMMTALLIES;
1789 cmd.parm1 = 0;
1790 cmd.parm2 = 0;
1791
1792 hfa384x_docmd_async(hw, &cmd, NULL, NULL, NULL);
1793
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001794 return 0;
1795}
1796
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001797/*----------------------------------------------------------------
1798* hfa384x_drvr_disable
1799*
1800* Issues the disable command to stop communications on one of
1801* the MACs 'ports'. Only macport 0 is valid for stations.
1802* APs may also disable macports 1-6. Only ports that have been
1803* previously enabled may be disabled.
1804*
1805* Arguments:
1806* hw device structure
1807* macport MAC port number (host order)
1808*
1809* Returns:
1810* 0 success
1811* >0 f/w reported failure - f/w status code
1812* <0 driver reported error (timeout|bad arg)
1813*
1814* Side effects:
1815*
1816* Call context:
1817* process
1818----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +05301819int hfa384x_drvr_disable(hfa384x_t *hw, u16 macport)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001820{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001821 int result = 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001822
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001823 if ((!hw->isap && macport != 0) ||
1824 (hw->isap && !(macport <= HFA384x_PORTID_MAX)) ||
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001825 !(hw->port_enabled[macport])) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001826 result = -EINVAL;
1827 } else {
1828 result = hfa384x_cmd_disable(hw, macport);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001829 if (result == 0)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001830 hw->port_enabled[macport] = 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001831 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001832 return result;
1833}
1834
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001835/*----------------------------------------------------------------
1836* hfa384x_drvr_enable
1837*
1838* Issues the enable command to enable communications on one of
1839* the MACs 'ports'. Only macport 0 is valid for stations.
1840* APs may also enable macports 1-6. Only ports that are currently
1841* disabled may be enabled.
1842*
1843* Arguments:
1844* hw device structure
1845* macport MAC port number
1846*
1847* Returns:
1848* 0 success
1849* >0 f/w reported failure - f/w status code
1850* <0 driver reported error (timeout|bad arg)
1851*
1852* Side effects:
1853*
1854* Call context:
1855* process
1856----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +05301857int hfa384x_drvr_enable(hfa384x_t *hw, u16 macport)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001858{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001859 int result = 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001860
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001861 if ((!hw->isap && macport != 0) ||
1862 (hw->isap && !(macport <= HFA384x_PORTID_MAX)) ||
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001863 (hw->port_enabled[macport])) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001864 result = -EINVAL;
1865 } else {
1866 result = hfa384x_cmd_enable(hw, macport);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001867 if (result == 0)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001868 hw->port_enabled[macport] = 1;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001869 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001870 return result;
1871}
1872
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001873/*----------------------------------------------------------------
1874* hfa384x_drvr_flashdl_enable
1875*
1876* Begins the flash download state. Checks to see that we're not
1877* already in a download state and that a port isn't enabled.
1878* Sets the download state and retrieves the flash download
1879* buffer location, buffer size, and timeout length.
1880*
1881* Arguments:
1882* hw device structure
1883*
1884* Returns:
1885* 0 success
1886* >0 f/w reported error - f/w status code
1887* <0 driver reported error
1888*
1889* Side effects:
1890*
1891* Call context:
1892* process
1893----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +05301894int hfa384x_drvr_flashdl_enable(hfa384x_t *hw)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001895{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001896 int result = 0;
1897 int i;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001898
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001899 /* Check that a port isn't active */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001900 for (i = 0; i < HFA384x_PORTID_MAX; i++) {
1901 if (hw->port_enabled[i]) {
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +01001902 pr_debug("called when port enabled.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001903 return -EINVAL;
1904 }
1905 }
1906
1907 /* Check that we're not already in a download state */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001908 if (hw->dlstate != HFA384x_DLSTATE_DISABLED)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001909 return -EINVAL;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001910
1911 /* Retrieve the buffer loc&size and timeout */
Svenne Krap46800b22010-02-14 18:59:42 +01001912 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_DOWNLOADBUFFER,
Andrew Elwell3f4b4e72010-02-18 23:56:13 +01001913 &(hw->bufinfo), sizeof(hw->bufinfo));
1914 if (result)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001915 return result;
Andrew Elwell3f4b4e72010-02-18 23:56:13 +01001916
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01001917 hw->bufinfo.page = le16_to_cpu(hw->bufinfo.page);
1918 hw->bufinfo.offset = le16_to_cpu(hw->bufinfo.offset);
1919 hw->bufinfo.len = le16_to_cpu(hw->bufinfo.len);
Svenne Krap46800b22010-02-14 18:59:42 +01001920 result = hfa384x_drvr_getconfig16(hw, HFA384x_RID_MAXLOADTIME,
Andrew Elwell3f4b4e72010-02-18 23:56:13 +01001921 &(hw->dltimeout));
1922 if (result)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001923 return result;
Andrew Elwell3f4b4e72010-02-18 23:56:13 +01001924
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01001925 hw->dltimeout = le16_to_cpu(hw->dltimeout);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001926
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +01001927 pr_debug("flashdl_enable\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001928
1929 hw->dlstate = HFA384x_DLSTATE_FLASHENABLED;
Moritz Muehlenhoff8a251b52009-01-21 22:00:44 +01001930
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001931 return result;
1932}
1933
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001934/*----------------------------------------------------------------
1935* hfa384x_drvr_flashdl_disable
1936*
1937* Ends the flash download state. Note that this will cause the MAC
1938* firmware to restart.
1939*
1940* Arguments:
1941* hw device structure
1942*
1943* Returns:
1944* 0 success
1945* >0 f/w reported error - f/w status code
1946* <0 driver reported error
1947*
1948* Side effects:
1949*
1950* Call context:
1951* process
1952----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +05301953int hfa384x_drvr_flashdl_disable(hfa384x_t *hw)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001954{
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001955 /* Check that we're already in the download state */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001956 if (hw->dlstate != HFA384x_DLSTATE_FLASHENABLED)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001957 return -EINVAL;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001958
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +01001959 pr_debug("flashdl_enable\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001960
1961 /* There isn't much we can do at this point, so I don't */
1962 /* bother w/ the return value */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001963 hfa384x_cmd_download(hw, HFA384x_PROGMODE_DISABLE, 0, 0, 0);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001964 hw->dlstate = HFA384x_DLSTATE_DISABLED;
1965
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001966 return 0;
1967}
1968
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001969/*----------------------------------------------------------------
1970* hfa384x_drvr_flashdl_write
1971*
1972* Performs a FLASH download of a chunk of data. First checks to see
1973* that we're in the FLASH download state, then sets the download
1974* mode, uses the aux functions to 1) copy the data to the flash
1975* buffer, 2) sets the download 'write flash' mode, 3) readback and
1976* compare. Lather rinse, repeat as many times an necessary to get
1977* all the given data into flash.
1978* When all data has been written using this function (possibly
1979* repeatedly), call drvr_flashdl_disable() to end the download state
1980* and restart the MAC.
1981*
1982* Arguments:
1983* hw device structure
1984* daddr Card address to write to. (host order)
1985* buf Ptr to data to write.
1986* len Length of data (host order).
1987*
1988* Returns:
1989* 0 success
1990* >0 f/w reported error - f/w status code
1991* <0 driver reported error
1992*
1993* Side effects:
1994*
1995* Call context:
1996* process
1997----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +05301998int hfa384x_drvr_flashdl_write(hfa384x_t *hw, u32 daddr, void *buf, u32 len)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001999{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002000 int result = 0;
2001 u32 dlbufaddr;
2002 int nburns;
2003 u32 burnlen;
2004 u32 burndaddr;
2005 u16 burnlo;
2006 u16 burnhi;
2007 int nwrites;
2008 u8 *writebuf;
2009 u16 writepage;
2010 u16 writeoffset;
2011 u32 writelen;
2012 int i;
2013 int j;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002014
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +01002015 pr_debug("daddr=0x%08x len=%d\n", daddr, len);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002016
2017 /* Check that we're in the flash download state */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002018 if (hw->dlstate != HFA384x_DLSTATE_FLASHENABLED)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002019 return -EINVAL;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002020
Moritz Muehlenhoff350f2f4b2009-01-25 21:54:57 +01002021 printk(KERN_INFO "Download %d bytes to flash @0x%06x\n", len, daddr);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002022
2023 /* Convert to flat address for arithmetic */
2024 /* NOTE: dlbuffer RID stores the address in AUX format */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002025 dlbufaddr =
2026 HFA384x_ADDR_AUX_MKFLAT(hw->bufinfo.page, hw->bufinfo.offset);
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05302027 pr_debug("dlbuf.page=0x%04x dlbuf.offset=0x%04x dlbufaddr=0x%08x\n",
2028 hw->bufinfo.page, hw->bufinfo.offset, dlbufaddr);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002029
2030#if 0
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002031 printk(KERN_WARNING "dlbuf@0x%06lx len=%d to=%d\n", dlbufaddr,
2032 hw->bufinfo.len, hw->dltimeout);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002033#endif
2034 /* Calculations to determine how many fills of the dlbuffer to do
2035 * and how many USB wmemreq's to do for each fill. At this point
2036 * in time, the dlbuffer size and the wmemreq size are the same.
2037 * Therefore, nwrites should always be 1. The extra complexity
2038 * here is a hedge against future changes.
2039 */
2040
2041 /* Figure out how many times to do the flash programming */
2042 nburns = len / hw->bufinfo.len;
2043 nburns += (len % hw->bufinfo.len) ? 1 : 0;
2044
2045 /* For each flash program cycle, how many USB wmemreq's are needed? */
2046 nwrites = hw->bufinfo.len / HFA384x_USB_RWMEM_MAXLEN;
2047 nwrites += (hw->bufinfo.len % HFA384x_USB_RWMEM_MAXLEN) ? 1 : 0;
2048
2049 /* For each burn */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002050 for (i = 0; i < nburns; i++) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002051 /* Get the dest address and len */
2052 burnlen = (len - (hw->bufinfo.len * i)) > hw->bufinfo.len ?
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002053 hw->bufinfo.len : (len - (hw->bufinfo.len * i));
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002054 burndaddr = daddr + (hw->bufinfo.len * i);
2055 burnlo = HFA384x_ADDR_CMD_MKOFF(burndaddr);
2056 burnhi = HFA384x_ADDR_CMD_MKPAGE(burndaddr);
2057
Moritz Muehlenhoff350f2f4b2009-01-25 21:54:57 +01002058 printk(KERN_INFO "Writing %d bytes to flash @0x%06x\n",
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002059 burnlen, burndaddr);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002060
2061 /* Set the download mode */
2062 result = hfa384x_cmd_download(hw, HFA384x_PROGMODE_NV,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002063 burnlo, burnhi, burnlen);
2064 if (result) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +01002065 printk(KERN_ERR "download(NV,lo=%x,hi=%x,len=%x) "
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002066 "cmd failed, result=%d. Aborting d/l\n",
2067 burnlo, burnhi, burnlen, result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002068 goto exit_proc;
2069 }
2070
2071 /* copy the data to the flash download buffer */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002072 for (j = 0; j < nwrites; j++) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002073 writebuf = buf +
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002074 (i * hw->bufinfo.len) +
2075 (j * HFA384x_USB_RWMEM_MAXLEN);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002076
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002077 writepage = HFA384x_ADDR_CMD_MKPAGE(dlbufaddr +
Edgardo Hames631c8de2010-03-08 17:02:37 -08002078 (j * HFA384x_USB_RWMEM_MAXLEN));
2079 writeoffset = HFA384x_ADDR_CMD_MKOFF(dlbufaddr +
2080 (j * HFA384x_USB_RWMEM_MAXLEN));
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002081
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002082 writelen = burnlen - (j * HFA384x_USB_RWMEM_MAXLEN);
2083 writelen = writelen > HFA384x_USB_RWMEM_MAXLEN ?
2084 HFA384x_USB_RWMEM_MAXLEN : writelen;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002085
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002086 result = hfa384x_dowmem_wait(hw,
2087 writepage,
2088 writeoffset,
2089 writebuf, writelen);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002090 }
2091
2092 /* set the download 'write flash' mode */
2093 result = hfa384x_cmd_download(hw,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002094 HFA384x_PROGMODE_NVWRITE,
2095 0, 0, 0);
2096 if (result) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +01002097 printk(KERN_ERR
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002098 "download(NVWRITE,lo=%x,hi=%x,len=%x) "
2099 "cmd failed, result=%d. Aborting d/l\n",
2100 burnlo, burnhi, burnlen, result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002101 goto exit_proc;
2102 }
2103
2104 /* TODO: We really should do a readback and compare. */
2105 }
2106
2107exit_proc:
2108
2109 /* Leave the firmware in the 'post-prog' mode. flashdl_disable will */
2110 /* actually disable programming mode. Remember, that will cause the */
2111 /* the firmware to effectively reset itself. */
2112
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002113 return result;
2114}
2115
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002116/*----------------------------------------------------------------
2117* hfa384x_drvr_getconfig
2118*
2119* Performs the sequence necessary to read a config/info item.
2120*
2121* Arguments:
2122* hw device structure
2123* rid config/info record id (host order)
2124* buf host side record buffer. Upon return it will
2125* contain the body portion of the record (minus the
2126* RID and len).
2127* len buffer length (in bytes, should match record length)
2128*
2129* Returns:
2130* 0 success
2131* >0 f/w reported error - f/w status code
2132* <0 driver reported error
Edgardo Hames631c8de2010-03-08 17:02:37 -08002133* -ENODATA length mismatch between argument and retrieved
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002134* record.
2135*
2136* Side effects:
2137*
2138* Call context:
2139* process
2140----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +05302141int hfa384x_drvr_getconfig(hfa384x_t *hw, u16 rid, void *buf, u16 len)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002142{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002143 int result;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002144
2145 result = hfa384x_dorrid_wait(hw, rid, buf, len);
2146
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002147 return result;
2148}
2149
2150/*----------------------------------------------------------------
2151 * hfa384x_drvr_getconfig_async
2152 *
2153 * Performs the sequence necessary to perform an async read of
2154 * of a config/info item.
2155 *
2156 * Arguments:
2157 * hw device structure
2158 * rid config/info record id (host order)
2159 * buf host side record buffer. Upon return it will
2160 * contain the body portion of the record (minus the
2161 * RID and len).
2162 * len buffer length (in bytes, should match record length)
2163 * cbfn caller supplied callback, called when the command
2164 * is done (successful or not).
2165 * cbfndata pointer to some caller supplied data that will be
2166 * passed in as an argument to the cbfn.
2167 *
2168 * Returns:
2169 * nothing the cbfn gets a status argument identifying if
2170 * any errors occur.
2171 * Side effects:
2172 * Queues an hfa384x_usbcmd_t for subsequent execution.
2173 *
2174 * Call context:
2175 * Any
2176 ----------------------------------------------------------------*/
2177int
Mithlesh Thukral297f06c2009-06-10 19:36:11 +05302178hfa384x_drvr_getconfig_async(hfa384x_t *hw,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002179 u16 rid, ctlx_usercb_t usercb, void *usercb_data)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002180{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002181 return hfa384x_dorrid_async(hw, rid, NULL, 0,
2182 hfa384x_cb_rrid, usercb, usercb_data);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002183}
2184
2185/*----------------------------------------------------------------
2186 * hfa384x_drvr_setconfig_async
2187 *
2188 * Performs the sequence necessary to write a config/info item.
2189 *
2190 * Arguments:
2191 * hw device structure
2192 * rid config/info record id (in host order)
2193 * buf host side record buffer
2194 * len buffer length (in bytes)
2195 * usercb completion callback
2196 * usercb_data completion callback argument
2197 *
2198 * Returns:
2199 * 0 success
2200 * >0 f/w reported error - f/w status code
2201 * <0 driver reported error
2202 *
2203 * Side effects:
2204 *
2205 * Call context:
2206 * process
2207 ----------------------------------------------------------------*/
2208int
Mithlesh Thukral297f06c2009-06-10 19:36:11 +05302209hfa384x_drvr_setconfig_async(hfa384x_t *hw,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002210 u16 rid,
2211 void *buf,
2212 u16 len, ctlx_usercb_t usercb, void *usercb_data)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002213{
2214 return hfa384x_dowrid_async(hw, rid, buf, len,
2215 hfa384x_cb_status, usercb, usercb_data);
2216}
2217
2218/*----------------------------------------------------------------
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002219* hfa384x_drvr_ramdl_disable
2220*
2221* Ends the ram download state.
2222*
2223* Arguments:
2224* hw device structure
2225*
2226* Returns:
2227* 0 success
2228* >0 f/w reported error - f/w status code
2229* <0 driver reported error
2230*
2231* Side effects:
2232*
2233* Call context:
2234* process
2235----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +05302236int hfa384x_drvr_ramdl_disable(hfa384x_t *hw)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002237{
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002238 /* Check that we're already in the download state */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002239 if (hw->dlstate != HFA384x_DLSTATE_RAMENABLED)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002240 return -EINVAL;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002241
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +01002242 pr_debug("ramdl_disable()\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002243
2244 /* There isn't much we can do at this point, so I don't */
2245 /* bother w/ the return value */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002246 hfa384x_cmd_download(hw, HFA384x_PROGMODE_DISABLE, 0, 0, 0);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002247 hw->dlstate = HFA384x_DLSTATE_DISABLED;
2248
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002249 return 0;
2250}
2251
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002252/*----------------------------------------------------------------
2253* hfa384x_drvr_ramdl_enable
2254*
2255* Begins the ram download state. Checks to see that we're not
2256* already in a download state and that a port isn't enabled.
2257* Sets the download state and calls cmd_download with the
2258* ENABLE_VOLATILE subcommand and the exeaddr argument.
2259*
2260* Arguments:
2261* hw device structure
2262* exeaddr the card execution address that will be
2263* jumped to when ramdl_disable() is called
2264* (host order).
2265*
2266* Returns:
2267* 0 success
2268* >0 f/w reported error - f/w status code
2269* <0 driver reported error
2270*
2271* Side effects:
2272*
2273* Call context:
2274* process
2275----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +05302276int hfa384x_drvr_ramdl_enable(hfa384x_t *hw, u32 exeaddr)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002277{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002278 int result = 0;
2279 u16 lowaddr;
2280 u16 hiaddr;
2281 int i;
Moritz Muehlenhoff8a251b52009-01-21 22:00:44 +01002282
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002283 /* Check that a port isn't active */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002284 for (i = 0; i < HFA384x_PORTID_MAX; i++) {
2285 if (hw->port_enabled[i]) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +01002286 printk(KERN_ERR
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002287 "Can't download with a macport enabled.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002288 return -EINVAL;
2289 }
2290 }
2291
2292 /* Check that we're not already in a download state */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002293 if (hw->dlstate != HFA384x_DLSTATE_DISABLED) {
2294 printk(KERN_ERR "Download state not disabled.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002295 return -EINVAL;
2296 }
2297
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +01002298 pr_debug("ramdl_enable, exeaddr=0x%08x\n", exeaddr);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002299
2300 /* Call the download(1,addr) function */
2301 lowaddr = HFA384x_ADDR_CMD_MKOFF(exeaddr);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002302 hiaddr = HFA384x_ADDR_CMD_MKPAGE(exeaddr);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002303
2304 result = hfa384x_cmd_download(hw, HFA384x_PROGMODE_RAM,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002305 lowaddr, hiaddr, 0);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002306
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002307 if (result == 0) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002308 /* Set the download state */
2309 hw->dlstate = HFA384x_DLSTATE_RAMENABLED;
2310 } else {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05302311 pr_debug("cmd_download(0x%04x, 0x%04x) failed, result=%d.\n",
2312 lowaddr, hiaddr, result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002313 }
2314
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002315 return result;
2316}
2317
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002318/*----------------------------------------------------------------
2319* hfa384x_drvr_ramdl_write
2320*
2321* Performs a RAM download of a chunk of data. First checks to see
2322* that we're in the RAM download state, then uses the [read|write]mem USB
2323* commands to 1) copy the data, 2) readback and compare. The download
2324* state is unaffected. When all data has been written using
2325* this function, call drvr_ramdl_disable() to end the download state
2326* and restart the MAC.
2327*
2328* Arguments:
2329* hw device structure
2330* daddr Card address to write to. (host order)
2331* buf Ptr to data to write.
2332* len Length of data (host order).
2333*
2334* Returns:
2335* 0 success
2336* >0 f/w reported error - f/w status code
2337* <0 driver reported error
2338*
2339* Side effects:
2340*
2341* Call context:
2342* process
2343----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +05302344int hfa384x_drvr_ramdl_write(hfa384x_t *hw, u32 daddr, void *buf, u32 len)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002345{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002346 int result = 0;
2347 int nwrites;
2348 u8 *data = buf;
2349 int i;
2350 u32 curraddr;
2351 u16 currpage;
2352 u16 curroffset;
2353 u16 currlen;
Moritz Muehlenhoff8a251b52009-01-21 22:00:44 +01002354
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002355 /* Check that we're in the ram download state */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002356 if (hw->dlstate != HFA384x_DLSTATE_RAMENABLED)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002357 return -EINVAL;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002358
Moritz Muehlenhoff350f2f4b2009-01-25 21:54:57 +01002359 printk(KERN_INFO "Writing %d bytes to ram @0x%06x\n", len, daddr);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002360
2361 /* How many dowmem calls? */
2362 nwrites = len / HFA384x_USB_RWMEM_MAXLEN;
2363 nwrites += len % HFA384x_USB_RWMEM_MAXLEN ? 1 : 0;
2364
2365 /* Do blocking wmem's */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002366 for (i = 0; i < nwrites; i++) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002367 /* make address args */
2368 curraddr = daddr + (i * HFA384x_USB_RWMEM_MAXLEN);
2369 currpage = HFA384x_ADDR_CMD_MKPAGE(curraddr);
2370 curroffset = HFA384x_ADDR_CMD_MKOFF(curraddr);
2371 currlen = len - (i * HFA384x_USB_RWMEM_MAXLEN);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002372 if (currlen > HFA384x_USB_RWMEM_MAXLEN)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002373 currlen = HFA384x_USB_RWMEM_MAXLEN;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002374
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002375 /* Do blocking ctlx */
2376 result = hfa384x_dowmem_wait(hw,
2377 currpage,
2378 curroffset,
2379 data +
2380 (i * HFA384x_USB_RWMEM_MAXLEN),
2381 currlen);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002382
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002383 if (result)
2384 break;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002385
2386 /* TODO: We really should have a readback. */
2387 }
2388
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002389 return result;
2390}
2391
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002392/*----------------------------------------------------------------
2393* hfa384x_drvr_readpda
2394*
2395* Performs the sequence to read the PDA space. Note there is no
2396* drvr_writepda() function. Writing a PDA is
2397* generally implemented by a calling component via calls to
2398* cmd_download and writing to the flash download buffer via the
2399* aux regs.
2400*
2401* Arguments:
2402* hw device structure
2403* buf buffer to store PDA in
2404* len buffer length
2405*
2406* Returns:
2407* 0 success
2408* >0 f/w reported error - f/w status code
2409* <0 driver reported error
Jean Delvare3ac49a12009-06-04 16:20:28 +02002410* -ETIMEDOUT timout waiting for the cmd regs to become
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002411* available, or waiting for the control reg
2412* to indicate the Aux port is enabled.
2413* -ENODATA the buffer does NOT contain a valid PDA.
2414* Either the card PDA is bad, or the auxdata
2415* reads are giving us garbage.
2416
2417*
2418* Side effects:
2419*
2420* Call context:
2421* process or non-card interrupt.
2422----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +05302423int hfa384x_drvr_readpda(hfa384x_t *hw, void *buf, unsigned int len)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002424{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002425 int result = 0;
2426 u16 *pda = buf;
2427 int pdaok = 0;
2428 int morepdrs = 1;
2429 int currpdr = 0; /* word offset of the current pdr */
2430 size_t i;
2431 u16 pdrlen; /* pdr length in bytes, host order */
2432 u16 pdrcode; /* pdr code, host order */
2433 u16 currpage;
2434 u16 curroffset;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002435 struct pdaloc {
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002436 u32 cardaddr;
2437 u16 auxctl;
2438 } pdaloc[] = {
2439 {
2440 HFA3842_PDA_BASE, 0}, {
2441 HFA3841_PDA_BASE, 0}, {
2442 HFA3841_PDA_BOGUS_BASE, 0}
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002443 };
2444
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002445 /* Read the pda from each known address. */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002446 for (i = 0; i < ARRAY_SIZE(pdaloc); i++) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002447 /* Make address */
2448 currpage = HFA384x_ADDR_CMD_MKPAGE(pdaloc[i].cardaddr);
2449 curroffset = HFA384x_ADDR_CMD_MKOFF(pdaloc[i].cardaddr);
2450
Edgardo Hames631c8de2010-03-08 17:02:37 -08002451 /* units of bytes */
2452 result = hfa384x_dormem_wait(hw, currpage, curroffset, buf,
2453 len);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002454
2455 if (result) {
Moritz Muehlenhoff9b9556e2009-01-25 21:55:01 +01002456 printk(KERN_WARNING
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002457 "Read from index %zd failed, continuing\n", i);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002458 continue;
2459 }
2460
2461 /* Test for garbage */
2462 pdaok = 1; /* initially assume good */
2463 morepdrs = 1;
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002464 while (pdaok && morepdrs) {
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01002465 pdrlen = le16_to_cpu(pda[currpdr]) * 2;
2466 pdrcode = le16_to_cpu(pda[currpdr + 1]);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002467 /* Test the record length */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002468 if (pdrlen > HFA384x_PDR_LEN_MAX || pdrlen == 0) {
2469 printk(KERN_ERR "pdrlen invalid=%d\n", pdrlen);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002470 pdaok = 0;
2471 break;
2472 }
2473 /* Test the code */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002474 if (!hfa384x_isgood_pdrcode(pdrcode)) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +01002475 printk(KERN_ERR "pdrcode invalid=%d\n",
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002476 pdrcode);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002477 pdaok = 0;
2478 break;
2479 }
2480 /* Test for completion */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002481 if (pdrcode == HFA384x_PDR_END_OF_PDA)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002482 morepdrs = 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002483
2484 /* Move to the next pdr (if necessary) */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002485 if (morepdrs) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002486 /* note the access to pda[], need words here */
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01002487 currpdr += le16_to_cpu(pda[currpdr]) + 1;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002488 }
2489 }
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002490 if (pdaok) {
Moritz Muehlenhoff350f2f4b2009-01-25 21:54:57 +01002491 printk(KERN_INFO
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002492 "PDA Read from 0x%08x in %s space.\n",
2493 pdaloc[i].cardaddr,
2494 pdaloc[i].auxctl == 0 ? "EXTDS" :
2495 pdaloc[i].auxctl == 1 ? "NV" :
2496 pdaloc[i].auxctl == 2 ? "PHY" :
2497 pdaloc[i].auxctl == 3 ? "ICSRAM" :
2498 "<bogus auxctl>");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002499 break;
2500 }
2501 }
2502 result = pdaok ? 0 : -ENODATA;
2503
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002504 if (result)
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +01002505 pr_debug("Failure: pda is not okay\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002506
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002507 return result;
2508}
2509
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002510/*----------------------------------------------------------------
2511* hfa384x_drvr_setconfig
2512*
2513* Performs the sequence necessary to write a config/info item.
2514*
2515* Arguments:
2516* hw device structure
2517* rid config/info record id (in host order)
2518* buf host side record buffer
2519* len buffer length (in bytes)
2520*
2521* Returns:
2522* 0 success
2523* >0 f/w reported error - f/w status code
2524* <0 driver reported error
2525*
2526* Side effects:
2527*
2528* Call context:
2529* process
2530----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +05302531int hfa384x_drvr_setconfig(hfa384x_t *hw, u16 rid, void *buf, u16 len)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002532{
2533 return hfa384x_dowrid_wait(hw, rid, buf, len);
2534}
2535
2536/*----------------------------------------------------------------
2537* hfa384x_drvr_start
2538*
2539* Issues the MAC initialize command, sets up some data structures,
2540* and enables the interrupts. After this function completes, the
2541* low-level stuff should be ready for any/all commands.
2542*
2543* Arguments:
2544* hw device structure
2545* Returns:
2546* 0 success
2547* >0 f/w reported error - f/w status code
2548* <0 driver reported error
2549*
2550* Side effects:
2551*
2552* Call context:
2553* process
2554----------------------------------------------------------------*/
Richard Kennedy7b7e7e82008-11-03 11:16:09 +00002555
Mithlesh Thukral297f06c2009-06-10 19:36:11 +05302556int hfa384x_drvr_start(hfa384x_t *hw)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002557{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002558 int result, result1, result2;
2559 u16 status;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002560
2561 might_sleep();
2562
Richard Kennedy7b7e7e82008-11-03 11:16:09 +00002563 /* Clear endpoint stalls - but only do this if the endpoint
2564 * is showing a stall status. Some prism2 cards seem to behave
2565 * badly if a clear_halt is called when the endpoint is already
2566 * ok
2567 */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002568 result =
2569 usb_get_status(hw->usb, USB_RECIP_ENDPOINT, hw->endp_in, &status);
Richard Kennedy7b7e7e82008-11-03 11:16:09 +00002570 if (result < 0) {
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002571 printk(KERN_ERR "Cannot get bulk in endpoint status.\n");
Richard Kennedy7b7e7e82008-11-03 11:16:09 +00002572 goto done;
2573 }
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002574 if ((status == 1) && usb_clear_halt(hw->usb, hw->endp_in))
2575 printk(KERN_ERR "Failed to reset bulk in endpoint.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002576
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002577 result =
2578 usb_get_status(hw->usb, USB_RECIP_ENDPOINT, hw->endp_out, &status);
Richard Kennedy7b7e7e82008-11-03 11:16:09 +00002579 if (result < 0) {
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002580 printk(KERN_ERR "Cannot get bulk out endpoint status.\n");
Richard Kennedy7b7e7e82008-11-03 11:16:09 +00002581 goto done;
2582 }
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002583 if ((status == 1) && usb_clear_halt(hw->usb, hw->endp_out))
2584 printk(KERN_ERR "Failed to reset bulk out endpoint.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002585
2586 /* Synchronous unlink, in case we're trying to restart the driver */
2587 usb_kill_urb(&hw->rx_urb);
2588
2589 /* Post the IN urb */
2590 result = submit_rx_urb(hw, GFP_KERNEL);
2591 if (result != 0) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +01002592 printk(KERN_ERR
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002593 "Fatal, failed to submit RX URB, result=%d\n", result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002594 goto done;
2595 }
2596
Richard Kennedy7b7e7e82008-11-03 11:16:09 +00002597 /* Call initialize twice, with a 1 second sleep in between.
2598 * This is a nasty work-around since many prism2 cards seem to
2599 * need time to settle after an init from cold. The second
2600 * call to initialize in theory is not necessary - but we call
2601 * it anyway as a double insurance policy:
2602 * 1) If the first init should fail, the second may well succeed
2603 * and the card can still be used
2604 * 2) It helps ensures all is well with the card after the first
2605 * init and settle time.
2606 */
2607 result1 = hfa384x_cmd_initialize(hw);
2608 msleep(1000);
2609 result = result2 = hfa384x_cmd_initialize(hw);
2610 if (result1 != 0) {
2611 if (result2 != 0) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +01002612 printk(KERN_ERR
Edgardo Hames4ffab682010-03-15 23:00:40 -03002613 "cmd_initialize() failed on two attempts, results %d and %d\n",
2614 result1, result2);
Richard Kennedy7b7e7e82008-11-03 11:16:09 +00002615 usb_kill_urb(&hw->rx_urb);
2616 goto done;
2617 } else {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05302618 pr_debug("First cmd_initialize() failed (result %d),\n",
2619 result1);
Edgardo Hames4ffab682010-03-15 23:00:40 -03002620 pr_debug("but second attempt succeeded. All should be ok\n");
Richard Kennedy7b7e7e82008-11-03 11:16:09 +00002621 }
2622 } else if (result2 != 0) {
Edgardo Hames4ffab682010-03-15 23:00:40 -03002623 printk(KERN_WARNING "First cmd_initialize() succeeded, but second attempt failed (result=%d)\n",
2624 result2);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002625 printk(KERN_WARNING
2626 "Most likely the card will be functional\n");
2627 goto done;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002628 }
2629
2630 hw->state = HFA384x_STATE_RUNNING;
2631
2632done:
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002633 return result;
2634}
2635
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002636/*----------------------------------------------------------------
2637* hfa384x_drvr_stop
2638*
2639* Shuts down the MAC to the point where it is safe to unload the
2640* driver. Any subsystem that may be holding a data or function
2641* ptr into the driver must be cleared/deinitialized.
2642*
2643* Arguments:
2644* hw device structure
2645* Returns:
2646* 0 success
2647* >0 f/w reported error - f/w status code
2648* <0 driver reported error
2649*
2650* Side effects:
2651*
2652* Call context:
2653* process
2654----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +05302655int hfa384x_drvr_stop(hfa384x_t *hw)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002656{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002657 int result = 0;
2658 int i;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002659
2660 might_sleep();
2661
2662 /* There's no need for spinlocks here. The USB "disconnect"
2663 * function sets this "removed" flag and then calls us.
2664 */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002665 if (!hw->wlandev->hwremoved) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002666 /* Call initialize to leave the MAC in its 'reset' state */
2667 hfa384x_cmd_initialize(hw);
2668
2669 /* Cancel the rxurb */
2670 usb_kill_urb(&hw->rx_urb);
2671 }
2672
2673 hw->link_status = HFA384x_LINK_NOTCONNECTED;
2674 hw->state = HFA384x_STATE_INIT;
2675
2676 del_timer_sync(&hw->commsqual_timer);
2677
2678 /* Clear all the port status */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002679 for (i = 0; i < HFA384x_NUMPORTS_MAX; i++)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002680 hw->port_enabled[i] = 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002681
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002682 return result;
2683}
2684
2685/*----------------------------------------------------------------
2686* hfa384x_drvr_txframe
2687*
2688* Takes a frame from prism2sta and queues it for transmission.
2689*
2690* Arguments:
2691* hw device structure
2692* skb packet buffer struct. Contains an 802.11
2693* data frame.
2694* p80211_hdr points to the 802.11 header for the packet.
2695* Returns:
2696* 0 Success and more buffs available
2697* 1 Success but no more buffs
2698* 2 Allocation failure
2699* 4 Buffer full or queue busy
2700*
2701* Side effects:
2702*
2703* Call context:
2704* interrupt
2705----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +05302706int hfa384x_drvr_txframe(hfa384x_t *hw, struct sk_buff *skb,
Edgardo Hames93df38e2010-07-30 22:51:55 -03002707 union p80211_hdr *p80211_hdr,
Edgardo Hames51e48962010-07-31 13:06:52 -03002708 struct p80211_metawep *p80211_wep)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002709{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002710 int usbpktlen = sizeof(hfa384x_tx_frame_t);
2711 int result;
2712 int ret;
2713 char *ptr;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002714
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002715 if (hw->tx_urb.status == -EINPROGRESS) {
Moritz Muehlenhoff9b9556e2009-01-25 21:55:01 +01002716 printk(KERN_WARNING "TX URB already in use\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002717 result = 3;
2718 goto exit;
2719 }
2720
2721 /* Build Tx frame structure */
2722 /* Set up the control field */
2723 memset(&hw->txbuff.txfrm.desc, 0, sizeof(hw->txbuff.txfrm.desc));
2724
2725 /* Setup the usb type field */
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01002726 hw->txbuff.type = cpu_to_le16(HFA384x_USB_TXFRM);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002727
2728 /* Set up the sw_support field to identify this frame */
2729 hw->txbuff.txfrm.desc.sw_support = 0x0123;
2730
2731/* Tx complete and Tx exception disable per dleach. Might be causing
2732 * buf depletion
2733 */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002734/* #define DOEXC SLP -- doboth breaks horribly under load, doexc less so. */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002735#if defined(DOBOTH)
2736 hw->txbuff.txfrm.desc.tx_control =
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002737 HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
2738 HFA384x_TX_TXEX_SET(1) | HFA384x_TX_TXOK_SET(1);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002739#elif defined(DOEXC)
2740 hw->txbuff.txfrm.desc.tx_control =
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002741 HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
2742 HFA384x_TX_TXEX_SET(1) | HFA384x_TX_TXOK_SET(0);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002743#else
2744 hw->txbuff.txfrm.desc.tx_control =
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002745 HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
2746 HFA384x_TX_TXEX_SET(0) | HFA384x_TX_TXOK_SET(0);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002747#endif
2748 hw->txbuff.txfrm.desc.tx_control =
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01002749 cpu_to_le16(hw->txbuff.txfrm.desc.tx_control);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002750
2751 /* copy the header over to the txdesc */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002752 memcpy(&(hw->txbuff.txfrm.desc.frame_control), p80211_hdr,
Edgardo Hames93df38e2010-07-30 22:51:55 -03002753 sizeof(union p80211_hdr));
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002754
2755 /* if we're using host WEP, increase size by IV+ICV */
2756 if (p80211_wep->data) {
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01002757 hw->txbuff.txfrm.desc.data_len = cpu_to_le16(skb->len + 8);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002758 usbpktlen += 8;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002759 } else {
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01002760 hw->txbuff.txfrm.desc.data_len = cpu_to_le16(skb->len);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002761 }
2762
2763 usbpktlen += skb->len;
2764
2765 /* copy over the WEP IV if we are using host WEP */
2766 ptr = hw->txbuff.txfrm.data;
2767 if (p80211_wep->data) {
2768 memcpy(ptr, p80211_wep->iv, sizeof(p80211_wep->iv));
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002769 ptr += sizeof(p80211_wep->iv);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002770 memcpy(ptr, p80211_wep->data, skb->len);
2771 } else {
2772 memcpy(ptr, skb->data, skb->len);
2773 }
2774 /* copy over the packet data */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002775 ptr += skb->len;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002776
2777 /* copy over the WEP ICV if we are using host WEP */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002778 if (p80211_wep->data)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002779 memcpy(ptr, p80211_wep->icv, sizeof(p80211_wep->icv));
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002780
2781 /* Send the USB packet */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002782 usb_fill_bulk_urb(&(hw->tx_urb), hw->usb,
2783 hw->endp_out,
2784 &(hw->txbuff), ROUNDUP64(usbpktlen),
2785 hfa384x_usbout_callback, hw->wlandev);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002786 hw->tx_urb.transfer_flags |= USB_QUEUE_BULK;
2787
2788 result = 1;
2789 ret = submit_tx_urb(hw, &hw->tx_urb, GFP_ATOMIC);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002790 if (ret != 0) {
2791 printk(KERN_ERR "submit_tx_urb() failed, error=%d\n", ret);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002792 result = 3;
2793 }
2794
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002795exit:
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002796 return result;
2797}
2798
Mithlesh Thukral297f06c2009-06-10 19:36:11 +05302799void hfa384x_tx_timeout(wlandevice_t *wlandev)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002800{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002801 hfa384x_t *hw = wlandev->priv;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002802 unsigned long flags;
2803
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002804 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2805
Dan Carpenter59457892010-06-17 14:08:47 +02002806 if (!hw->wlandev->hwremoved) {
2807 int sched;
2808
2809 sched = !test_and_set_bit(WORK_TX_HALT, &hw->usb_flags);
2810 sched |= !test_and_set_bit(WORK_RX_HALT, &hw->usb_flags);
2811 if (sched)
2812 schedule_work(&hw->usb_work);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002813 }
2814
2815 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002816}
2817
2818/*----------------------------------------------------------------
2819* hfa384x_usbctlx_reaper_task
2820*
2821* Tasklet to delete dead CTLX objects
2822*
2823* Arguments:
2824* data ptr to a hfa384x_t
2825*
2826* Returns:
2827*
2828* Call context:
2829* Interrupt
2830----------------------------------------------------------------*/
2831static void hfa384x_usbctlx_reaper_task(unsigned long data)
2832{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002833 hfa384x_t *hw = (hfa384x_t *) data;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002834 struct list_head *entry;
2835 struct list_head *temp;
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002836 unsigned long flags;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002837
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002838 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2839
2840 /* This list is guaranteed to be empty if someone
2841 * has unplugged the adapter.
2842 */
2843 list_for_each_safe(entry, temp, &hw->ctlxq.reapable) {
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002844 hfa384x_usbctlx_t *ctlx;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002845
2846 ctlx = list_entry(entry, hfa384x_usbctlx_t, list);
2847 list_del(&ctlx->list);
2848 kfree(ctlx);
2849 }
2850
2851 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2852
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002853}
2854
2855/*----------------------------------------------------------------
2856* hfa384x_usbctlx_completion_task
2857*
2858* Tasklet to call completion handlers for returned CTLXs
2859*
2860* Arguments:
2861* data ptr to hfa384x_t
2862*
2863* Returns:
2864* Nothing
2865*
2866* Call context:
2867* Interrupt
2868----------------------------------------------------------------*/
2869static void hfa384x_usbctlx_completion_task(unsigned long data)
2870{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002871 hfa384x_t *hw = (hfa384x_t *) data;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002872 struct list_head *entry;
2873 struct list_head *temp;
2874 unsigned long flags;
2875
2876 int reap = 0;
2877
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002878 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2879
2880 /* This list is guaranteed to be empty if someone
2881 * has unplugged the adapter ...
2882 */
2883 list_for_each_safe(entry, temp, &hw->ctlxq.completing) {
2884 hfa384x_usbctlx_t *ctlx;
2885
2886 ctlx = list_entry(entry, hfa384x_usbctlx_t, list);
2887
2888 /* Call the completion function that this
2889 * command was assigned, assuming it has one.
2890 */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002891 if (ctlx->cmdcb != NULL) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002892 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2893 ctlx->cmdcb(hw, ctlx);
2894 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2895
2896 /* Make sure we don't try and complete
2897 * this CTLX more than once!
2898 */
2899 ctlx->cmdcb = NULL;
2900
2901 /* Did someone yank the adapter out
2902 * while our list was (briefly) unlocked?
2903 */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002904 if (hw->wlandev->hwremoved) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002905 reap = 0;
2906 break;
2907 }
2908 }
2909
2910 /*
2911 * "Reapable" CTLXs are ones which don't have any
2912 * threads waiting for them to die. Hence they must
2913 * be delivered to The Reaper!
2914 */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002915 if (ctlx->reapable) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002916 /* Move the CTLX off the "completing" list (hopefully)
2917 * on to the "reapable" list where the reaper task
2918 * can find it. And "reapable" means that this CTLX
2919 * isn't sitting on a wait-queue somewhere.
2920 */
2921 list_move_tail(&ctlx->list, &hw->ctlxq.reapable);
2922 reap = 1;
2923 }
2924
2925 complete(&ctlx->done);
2926 }
2927 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2928
2929 if (reap)
2930 tasklet_schedule(&hw->reaper_bh);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002931}
2932
2933/*----------------------------------------------------------------
2934* unlocked_usbctlx_cancel_async
2935*
2936* Mark the CTLX dead asynchronously, and ensure that the
2937* next command on the queue is run afterwards.
2938*
2939* Arguments:
2940* hw ptr to the hfa384x_t structure
2941* ctlx ptr to a CTLX structure
2942*
2943* Returns:
2944* 0 the CTLX's URB is inactive
2945* -EINPROGRESS the URB is currently being unlinked
2946*
2947* Call context:
2948* Either process or interrupt, but presumably interrupt
2949----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +05302950static int unlocked_usbctlx_cancel_async(hfa384x_t *hw,
2951 hfa384x_usbctlx_t *ctlx)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002952{
2953 int ret;
2954
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002955 /*
2956 * Try to delete the URB containing our request packet.
2957 * If we succeed, then its completion handler will be
2958 * called with a status of -ECONNRESET.
2959 */
2960 hw->ctlx_urb.transfer_flags |= URB_ASYNC_UNLINK;
2961 ret = usb_unlink_urb(&hw->ctlx_urb);
2962
2963 if (ret != -EINPROGRESS) {
2964 /*
2965 * The OUT URB had either already completed
2966 * or was still in the pending queue, so the
2967 * URB's completion function will not be called.
2968 * We will have to complete the CTLX ourselves.
2969 */
2970 ctlx->state = CTLX_REQ_FAILED;
2971 unlocked_usbctlx_complete(hw, ctlx);
2972 ret = 0;
2973 }
2974
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002975 return ret;
2976}
2977
2978/*----------------------------------------------------------------
2979* unlocked_usbctlx_complete
2980*
2981* A CTLX has completed. It may have been successful, it may not
2982* have been. At this point, the CTLX should be quiescent. The URBs
2983* aren't active and the timers should have been stopped.
2984*
2985* The CTLX is migrated to the "completing" queue, and the completing
2986* tasklet is scheduled.
2987*
2988* Arguments:
2989* hw ptr to a hfa384x_t structure
2990* ctlx ptr to a ctlx structure
2991*
2992* Returns:
2993* nothing
2994*
2995* Side effects:
2996*
2997* Call context:
2998* Either, assume interrupt
2999----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +05303000static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003001{
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003002 /* Timers have been stopped, and ctlx should be in
3003 * a terminal state. Retire it from the "active"
3004 * queue.
3005 */
3006 list_move_tail(&ctlx->list, &hw->ctlxq.completing);
3007 tasklet_schedule(&hw->completion_bh);
3008
3009 switch (ctlx->state) {
3010 case CTLX_COMPLETE:
3011 case CTLX_REQ_FAILED:
3012 /* This are the correct terminating states. */
3013 break;
3014
3015 default:
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +01003016 printk(KERN_ERR "CTLX[%d] not in a terminating state(%s)\n",
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05303017 le16_to_cpu(ctlx->outbuf.type), ctlxstr(ctlx->state));
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003018 break;
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003019 } /* switch */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003020}
3021
3022/*----------------------------------------------------------------
3023* hfa384x_usbctlxq_run
3024*
3025* Checks to see if the head item is running. If not, starts it.
3026*
3027* Arguments:
3028* hw ptr to hfa384x_t
3029*
3030* Returns:
3031* nothing
3032*
3033* Side effects:
3034*
3035* Call context:
3036* any
3037----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +05303038static void hfa384x_usbctlxq_run(hfa384x_t *hw)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003039{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003040 unsigned long flags;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003041
3042 /* acquire lock */
3043 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3044
3045 /* Only one active CTLX at any one time, because there's no
3046 * other (reliable) way to match the response URB to the
3047 * correct CTLX.
3048 *
3049 * Don't touch any of these CTLXs if the hardware
3050 * has been removed or the USB subsystem is stalled.
3051 */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003052 if (!list_empty(&hw->ctlxq.active) ||
3053 test_bit(WORK_TX_HALT, &hw->usb_flags) || hw->wlandev->hwremoved)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003054 goto unlock;
3055
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003056 while (!list_empty(&hw->ctlxq.pending)) {
3057 hfa384x_usbctlx_t *head;
3058 int result;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003059
3060 /* This is the first pending command */
3061 head = list_entry(hw->ctlxq.pending.next,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003062 hfa384x_usbctlx_t, list);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003063
3064 /* We need to split this off to avoid a race condition */
3065 list_move_tail(&head->list, &hw->ctlxq.active);
3066
3067 /* Fill the out packet */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003068 usb_fill_bulk_urb(&(hw->ctlx_urb), hw->usb,
3069 hw->endp_out,
3070 &(head->outbuf), ROUNDUP64(head->outbufsize),
3071 hfa384x_ctlxout_callback, hw);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003072 hw->ctlx_urb.transfer_flags |= USB_QUEUE_BULK;
3073
Andrew Elwell3f4b4e72010-02-18 23:56:13 +01003074 /* Now submit the URB and update the CTLX's state */
Svenne Krap46800b22010-02-14 18:59:42 +01003075 result = SUBMIT_URB(&hw->ctlx_urb, GFP_ATOMIC);
3076 if (result == 0) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003077 /* This CTLX is now running on the active queue */
3078 head->state = CTLX_REQ_SUBMITTED;
3079
3080 /* Start the OUT wait timer */
3081 hw->req_timer_done = 0;
3082 hw->reqtimer.expires = jiffies + HZ;
3083 add_timer(&hw->reqtimer);
3084
3085 /* Start the IN wait timer */
3086 hw->resp_timer_done = 0;
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003087 hw->resptimer.expires = jiffies + 2 * HZ;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003088 add_timer(&hw->resptimer);
3089
3090 break;
3091 }
3092
3093 if (result == -EPIPE) {
3094 /* The OUT pipe needs resetting, so put
3095 * this CTLX back in the "pending" queue
3096 * and schedule a reset ...
3097 */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003098 printk(KERN_WARNING
3099 "%s tx pipe stalled: requesting reset\n",
3100 hw->wlandev->netdev->name);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003101 list_move(&head->list, &hw->ctlxq.pending);
3102 set_bit(WORK_TX_HALT, &hw->usb_flags);
3103 schedule_work(&hw->usb_work);
3104 break;
3105 }
3106
3107 if (result == -ESHUTDOWN) {
Moritz Muehlenhoff9b9556e2009-01-25 21:55:01 +01003108 printk(KERN_WARNING "%s urb shutdown!\n",
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003109 hw->wlandev->netdev->name);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003110 break;
3111 }
3112
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +01003113 printk(KERN_ERR "Failed to submit CTLX[%d]: error=%d\n",
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01003114 le16_to_cpu(head->outbuf.type), result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003115 unlocked_usbctlx_complete(hw, head);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003116 } /* while */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003117
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003118unlock:
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003119 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003120}
3121
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003122/*----------------------------------------------------------------
3123* hfa384x_usbin_callback
3124*
3125* Callback for URBs on the BULKIN endpoint.
3126*
3127* Arguments:
3128* urb ptr to the completed urb
3129*
3130* Returns:
3131* nothing
3132*
3133* Side effects:
3134*
3135* Call context:
3136* interrupt
3137----------------------------------------------------------------*/
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003138static void hfa384x_usbin_callback(struct urb *urb)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003139{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003140 wlandevice_t *wlandev = urb->context;
3141 hfa384x_t *hw;
3142 hfa384x_usbin_t *usbin = (hfa384x_usbin_t *) urb->transfer_buffer;
3143 struct sk_buff *skb = NULL;
3144 int result;
3145 int urb_status;
3146 u16 type;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003147
3148 enum USBIN_ACTION {
3149 HANDLE,
3150 RESUBMIT,
3151 ABORT
3152 } action;
3153
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003154 if (!wlandev || !wlandev->netdev || wlandev->hwremoved)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003155 goto exit;
3156
3157 hw = wlandev->priv;
3158 if (!hw)
3159 goto exit;
3160
3161 skb = hw->rx_urb_skb;
Stoyan Gaydarov2961f242009-03-10 00:10:27 -05003162 BUG_ON(!skb || (skb->data != urb->transfer_buffer));
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003163
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003164 hw->rx_urb_skb = NULL;
3165
3166 /* Check for error conditions within the URB */
3167 switch (urb->status) {
3168 case 0:
3169 action = HANDLE;
3170
3171 /* Check for short packet */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003172 if (urb->actual_length == 0) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003173 ++(wlandev->linux_stats.rx_errors);
3174 ++(wlandev->linux_stats.rx_length_errors);
3175 action = RESUBMIT;
3176 }
3177 break;
3178
3179 case -EPIPE:
Moritz Muehlenhoff9b9556e2009-01-25 21:55:01 +01003180 printk(KERN_WARNING "%s rx pipe stalled: requesting reset\n",
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003181 wlandev->netdev->name);
3182 if (!test_and_set_bit(WORK_RX_HALT, &hw->usb_flags))
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003183 schedule_work(&hw->usb_work);
3184 ++(wlandev->linux_stats.rx_errors);
3185 action = ABORT;
3186 break;
3187
3188 case -EILSEQ:
3189 case -ETIMEDOUT:
3190 case -EPROTO:
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003191 if (!test_and_set_bit(THROTTLE_RX, &hw->usb_flags) &&
3192 !timer_pending(&hw->throttle)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003193 mod_timer(&hw->throttle, jiffies + THROTTLE_JIFFIES);
3194 }
3195 ++(wlandev->linux_stats.rx_errors);
3196 action = ABORT;
3197 break;
3198
3199 case -EOVERFLOW:
3200 ++(wlandev->linux_stats.rx_over_errors);
3201 action = RESUBMIT;
3202 break;
3203
3204 case -ENODEV:
3205 case -ESHUTDOWN:
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +01003206 pr_debug("status=%d, device removed.\n", urb->status);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003207 action = ABORT;
3208 break;
3209
3210 case -ENOENT:
3211 case -ECONNRESET:
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05303212 pr_debug("status=%d, urb explicitly unlinked.\n", urb->status);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003213 action = ABORT;
3214 break;
3215
3216 default:
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +01003217 pr_debug("urb status=%d, transfer flags=0x%x\n",
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05303218 urb->status, urb->transfer_flags);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003219 ++(wlandev->linux_stats.rx_errors);
3220 action = RESUBMIT;
3221 break;
3222 }
3223
3224 urb_status = urb->status;
3225
3226 if (action != ABORT) {
3227 /* Repost the RX URB */
3228 result = submit_rx_urb(hw, GFP_ATOMIC);
3229
3230 if (result != 0) {
Moritz Muehlenhoffedbd6062009-01-25 21:55:00 +01003231 printk(KERN_ERR
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003232 "Fatal, failed to resubmit rx_urb. error=%d\n",
3233 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003234 }
3235 }
3236
3237 /* Handle any USB-IN packet */
3238 /* Note: the check of the sw_support field, the type field doesn't
3239 * have bit 12 set like the docs suggest.
3240 */
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01003241 type = le16_to_cpu(usbin->type);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003242 if (HFA384x_USB_ISRXFRM(type)) {
3243 if (action == HANDLE) {
3244 if (usbin->txfrm.desc.sw_support == 0x0123) {
3245 hfa384x_usbin_txcompl(wlandev, usbin);
3246 } else {
3247 skb_put(skb, sizeof(*usbin));
3248 hfa384x_usbin_rx(wlandev, skb);
3249 skb = NULL;
3250 }
3251 }
3252 goto exit;
3253 }
3254 if (HFA384x_USB_ISTXFRM(type)) {
3255 if (action == HANDLE)
3256 hfa384x_usbin_txcompl(wlandev, usbin);
3257 goto exit;
3258 }
3259 switch (type) {
3260 case HFA384x_USB_INFOFRM:
3261 if (action == ABORT)
3262 goto exit;
3263 if (action == HANDLE)
3264 hfa384x_usbin_info(wlandev, usbin);
3265 break;
3266
3267 case HFA384x_USB_CMDRESP:
3268 case HFA384x_USB_WRIDRESP:
3269 case HFA384x_USB_RRIDRESP:
3270 case HFA384x_USB_WMEMRESP:
3271 case HFA384x_USB_RMEMRESP:
3272 /* ALWAYS, ALWAYS, ALWAYS handle this CTLX!!!! */
3273 hfa384x_usbin_ctlx(hw, usbin, urb_status);
3274 break;
3275
3276 case HFA384x_USB_BUFAVAIL:
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +01003277 pr_debug("Received BUFAVAIL packet, frmlen=%d\n",
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05303278 usbin->bufavail.frmlen);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003279 break;
3280
3281 case HFA384x_USB_ERROR:
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +01003282 pr_debug("Received USB_ERROR packet, errortype=%d\n",
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05303283 usbin->usberror.errortype);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003284 break;
3285
3286 default:
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05303287 pr_debug("Unrecognized USBIN packet, type=%x, status=%d\n",
3288 usbin->type, urb_status);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003289 break;
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003290 } /* switch */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003291
3292exit:
3293
3294 if (skb)
3295 dev_kfree_skb(skb);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003296}
3297
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003298/*----------------------------------------------------------------
3299* hfa384x_usbin_ctlx
3300*
3301* We've received a URB containing a Prism2 "response" message.
3302* This message needs to be matched up with a CTLX on the active
3303* queue and our state updated accordingly.
3304*
3305* Arguments:
3306* hw ptr to hfa384x_t
3307* usbin ptr to USB IN packet
3308* urb_status status of this Bulk-In URB
3309*
3310* Returns:
3311* nothing
3312*
3313* Side effects:
3314*
3315* Call context:
3316* interrupt
3317----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +05303318static void hfa384x_usbin_ctlx(hfa384x_t *hw, hfa384x_usbin_t *usbin,
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003319 int urb_status)
3320{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003321 hfa384x_usbctlx_t *ctlx;
3322 int run_queue = 0;
3323 unsigned long flags;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003324
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003325retry:
3326 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3327
3328 /* There can be only one CTLX on the active queue
3329 * at any one time, and this is the CTLX that the
3330 * timers are waiting for.
3331 */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003332 if (list_empty(&hw->ctlxq.active))
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003333 goto unlock;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003334
3335 /* Remove the "response timeout". It's possible that
3336 * we are already too late, and that the timeout is
3337 * already running. And that's just too bad for us,
3338 * because we could lose our CTLX from the active
3339 * queue here ...
3340 */
3341 if (del_timer(&hw->resptimer) == 0) {
3342 if (hw->resp_timer_done == 0) {
3343 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3344 goto retry;
3345 }
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003346 } else {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003347 hw->resp_timer_done = 1;
3348 }
3349
3350 ctlx = get_active_ctlx(hw);
3351
3352 if (urb_status != 0) {
3353 /*
3354 * Bad CTLX, so get rid of it. But we only
3355 * remove it from the active queue if we're no
3356 * longer expecting the OUT URB to complete.
3357 */
3358 if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0)
3359 run_queue = 1;
3360 } else {
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01003361 const u16 intype = (usbin->type & ~cpu_to_le16(0x8000));
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003362
3363 /*
3364 * Check that our message is what we're expecting ...
3365 */
3366 if (ctlx->outbuf.type != intype) {
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003367 printk(KERN_WARNING
3368 "Expected IN[%d], received IN[%d] - ignored.\n",
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01003369 le16_to_cpu(ctlx->outbuf.type),
3370 le16_to_cpu(intype));
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003371 goto unlock;
3372 }
3373
3374 /* This URB has succeeded, so grab the data ... */
3375 memcpy(&ctlx->inbuf, usbin, sizeof(ctlx->inbuf));
3376
3377 switch (ctlx->state) {
3378 case CTLX_REQ_SUBMITTED:
3379 /*
3380 * We have received our response URB before
3381 * our request has been acknowledged. Odd,
3382 * but our OUT URB is still alive...
3383 */
Edgardo Hames4ffab682010-03-15 23:00:40 -03003384 pr_debug("Causality violation: please reboot Universe\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003385 ctlx->state = CTLX_RESP_COMPLETE;
3386 break;
3387
3388 case CTLX_REQ_COMPLETE:
3389 /*
3390 * This is the usual path: our request
3391 * has already been acknowledged, and
3392 * now we have received the reply too.
3393 */
3394 ctlx->state = CTLX_COMPLETE;
3395 unlocked_usbctlx_complete(hw, ctlx);
3396 run_queue = 1;
3397 break;
3398
3399 default:
3400 /*
3401 * Throw this CTLX away ...
3402 */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003403 printk(KERN_ERR
3404 "Matched IN URB, CTLX[%d] in invalid state(%s)."
3405 " Discarded.\n",
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01003406 le16_to_cpu(ctlx->outbuf.type),
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003407 ctlxstr(ctlx->state));
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003408 if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0)
3409 run_queue = 1;
3410 break;
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003411 } /* switch */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003412 }
3413
3414unlock:
3415 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3416
3417 if (run_queue)
3418 hfa384x_usbctlxq_run(hw);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003419}
3420
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003421/*----------------------------------------------------------------
3422* hfa384x_usbin_txcompl
3423*
3424* At this point we have the results of a previous transmit.
3425*
3426* Arguments:
3427* wlandev wlan device
3428* usbin ptr to the usb transfer buffer
3429*
3430* Returns:
3431* nothing
3432*
3433* Side effects:
3434*
3435* Call context:
3436* interrupt
3437----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +05303438static void hfa384x_usbin_txcompl(wlandevice_t *wlandev,
3439 hfa384x_usbin_t *usbin)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003440{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003441 u16 status;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003442
Edgardo Hames631c8de2010-03-08 17:02:37 -08003443 status = le16_to_cpu(usbin->type); /* yeah I know it says type... */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003444
3445 /* Was there an error? */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003446 if (HFA384x_TXSTATUS_ISERROR(status))
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003447 prism2sta_ev_txexc(wlandev, status);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003448 else
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003449 prism2sta_ev_tx(wlandev, status);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003450}
3451
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003452/*----------------------------------------------------------------
3453* hfa384x_usbin_rx
3454*
3455* At this point we have a successful received a rx frame packet.
3456*
3457* Arguments:
3458* wlandev wlan device
3459* usbin ptr to the usb transfer buffer
3460*
3461* Returns:
3462* nothing
3463*
3464* Side effects:
3465*
3466* Call context:
3467* interrupt
3468----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +05303469static void hfa384x_usbin_rx(wlandevice_t *wlandev, struct sk_buff *skb)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003470{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003471 hfa384x_usbin_t *usbin = (hfa384x_usbin_t *) skb->data;
3472 hfa384x_t *hw = wlandev->priv;
3473 int hdrlen;
Edgardo Hames51e48962010-07-31 13:06:52 -03003474 struct p80211_rxmeta *rxmeta;
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003475 u16 data_len;
3476 u16 fc;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003477
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003478 /* Byte order convert once up front. */
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01003479 usbin->rxfrm.desc.status = le16_to_cpu(usbin->rxfrm.desc.status);
3480 usbin->rxfrm.desc.time = le32_to_cpu(usbin->rxfrm.desc.time);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003481
3482 /* Now handle frame based on port# */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003483 switch (HFA384x_RXSTATUS_MACPORT_GET(usbin->rxfrm.desc.status)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003484 case 0:
Moritz Muehlenhoffae262302009-01-21 22:00:45 +01003485 fc = le16_to_cpu(usbin->rxfrm.desc.frame_control);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003486
3487 /* If exclude and we receive an unencrypted, drop it */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003488 if ((wlandev->hostwep & HOSTWEP_EXCLUDEUNENCRYPTED) &&
3489 !WLAN_GET_FC_ISWEP(fc)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003490 goto done;
3491 }
3492
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01003493 data_len = le16_to_cpu(usbin->rxfrm.desc.data_len);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003494
3495 /* How much header data do we have? */
3496 hdrlen = p80211_headerlen(fc);
3497
3498 /* Pull off the descriptor */
3499 skb_pull(skb, sizeof(hfa384x_rx_frame_t));
3500
3501 /* Now shunt the header block up against the data block
3502 * with an "overlapping" copy
3503 */
3504 memmove(skb_push(skb, hdrlen),
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003505 &usbin->rxfrm.desc.frame_control, hdrlen);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003506
3507 skb->dev = wlandev->netdev;
3508 skb->dev->last_rx = jiffies;
3509
3510 /* And set the frame length properly */
3511 skb_trim(skb, data_len + hdrlen);
3512
3513 /* The prism2 series does not return the CRC */
3514 memset(skb_put(skb, WLAN_CRC_LEN), 0xff, WLAN_CRC_LEN);
3515
3516 skb_reset_mac_header(skb);
3517
3518 /* Attach the rxmeta, set some stuff */
3519 p80211skb_rxmeta_attach(wlandev, skb);
3520 rxmeta = P80211SKB_RXMETA(skb);
3521 rxmeta->mactime = usbin->rxfrm.desc.time;
3522 rxmeta->rxrate = usbin->rxfrm.desc.rate;
3523 rxmeta->signal = usbin->rxfrm.desc.signal - hw->dbmadjust;
3524 rxmeta->noise = usbin->rxfrm.desc.silence - hw->dbmadjust;
3525
3526 prism2sta_ev_rx(wlandev, skb);
3527
3528 break;
3529
3530 case 7:
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003531 if (!HFA384x_RXSTATUS_ISFCSERR(usbin->rxfrm.desc.status)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003532 /* Copy to wlansnif skb */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003533 hfa384x_int_rxmonitor(wlandev, &usbin->rxfrm);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003534 dev_kfree_skb(skb);
3535 } else {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05303536 pr_debug("Received monitor frame: FCSerr set\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003537 }
3538 break;
3539
3540 default:
Moritz Muehlenhoff9b9556e2009-01-25 21:55:01 +01003541 printk(KERN_WARNING "Received frame on unsupported port=%d\n",
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003542 HFA384x_RXSTATUS_MACPORT_GET(usbin->rxfrm.desc.status));
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003543 goto done;
3544 break;
3545 }
3546
3547done:
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003548 return;
3549}
3550
3551/*----------------------------------------------------------------
3552* hfa384x_int_rxmonitor
3553*
3554* Helper function for int_rx. Handles monitor frames.
3555* Note that this function allocates space for the FCS and sets it
3556* to 0xffffffff. The hfa384x doesn't give us the FCS value but the
3557* higher layers expect it. 0xffffffff is used as a flag to indicate
3558* the FCS is bogus.
3559*
3560* Arguments:
3561* wlandev wlan device structure
3562* rxfrm rx descriptor read from card in int_rx
3563*
3564* Returns:
3565* nothing
3566*
3567* Side effects:
3568* Allocates an skb and passes it up via the PF_PACKET interface.
3569* Call context:
3570* interrupt
3571----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +05303572static void hfa384x_int_rxmonitor(wlandevice_t *wlandev,
3573 hfa384x_usb_rxfrm_t *rxfrm)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003574{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003575 hfa384x_rx_frame_t *rxdesc = &(rxfrm->desc);
3576 unsigned int hdrlen = 0;
3577 unsigned int datalen = 0;
3578 unsigned int skblen = 0;
3579 u8 *datap;
3580 u16 fc;
3581 struct sk_buff *skb;
3582 hfa384x_t *hw = wlandev->priv;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003583
Edgardo Hames631c8de2010-03-08 17:02:37 -08003584 /* Remember the status, time, and data_len fields are in host order */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003585 /* Figure out how big the frame is */
Moritz Muehlenhoffae262302009-01-21 22:00:45 +01003586 fc = le16_to_cpu(rxdesc->frame_control);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003587 hdrlen = p80211_headerlen(fc);
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01003588 datalen = le16_to_cpu(rxdesc->data_len);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003589
3590 /* Allocate an ind message+framesize skb */
Edgardo Hames51e48962010-07-31 13:06:52 -03003591 skblen = sizeof(struct p80211_caphdr) + hdrlen + datalen + WLAN_CRC_LEN;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003592
3593 /* sanity check the length */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003594 if (skblen >
Edgardo Hames51e48962010-07-31 13:06:52 -03003595 (sizeof(struct p80211_caphdr) +
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003596 WLAN_HDR_A4_LEN + WLAN_DATA_MAXLEN + WLAN_CRC_LEN)) {
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +01003597 pr_debug("overlen frm: len=%zd\n",
Edgardo Hames51e48962010-07-31 13:06:52 -03003598 skblen - sizeof(struct p80211_caphdr));
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003599 }
3600
Svenne Krap46800b22010-02-14 18:59:42 +01003601 skb = dev_alloc_skb(skblen);
3602 if (skb == NULL) {
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003603 printk(KERN_ERR
3604 "alloc_skb failed trying to allocate %d bytes\n",
3605 skblen);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003606 return;
3607 }
3608
3609 /* only prepend the prism header if in the right mode */
3610 if ((wlandev->netdev->type == ARPHRD_IEEE80211_PRISM) &&
Solomon Peachycbec30c2008-10-29 10:42:57 -04003611 (hw->sniffhdr != 0)) {
Edgardo Hames51e48962010-07-31 13:06:52 -03003612 struct p80211_caphdr *caphdr;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003613 /* The NEW header format! */
Edgardo Hames51e48962010-07-31 13:06:52 -03003614 datap = skb_put(skb, sizeof(struct p80211_caphdr));
3615 caphdr = (struct p80211_caphdr *) datap;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003616
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003617 caphdr->version = htonl(P80211CAPTURE_VERSION);
Edgardo Hames51e48962010-07-31 13:06:52 -03003618 caphdr->length = htonl(sizeof(struct p80211_caphdr));
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003619 caphdr->mactime = __cpu_to_be64(rxdesc->time) * 1000;
3620 caphdr->hosttime = __cpu_to_be64(jiffies);
3621 caphdr->phytype = htonl(4); /* dss_dot11_b */
3622 caphdr->channel = htonl(hw->sniff_channel);
3623 caphdr->datarate = htonl(rxdesc->rate);
3624 caphdr->antenna = htonl(0); /* unknown */
3625 caphdr->priority = htonl(0); /* unknown */
3626 caphdr->ssi_type = htonl(3); /* rssi_raw */
3627 caphdr->ssi_signal = htonl(rxdesc->signal);
3628 caphdr->ssi_noise = htonl(rxdesc->silence);
3629 caphdr->preamble = htonl(0); /* unknown */
3630 caphdr->encoding = htonl(1); /* cck */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003631 }
3632
Edgardo Hames631c8de2010-03-08 17:02:37 -08003633 /* Copy the 802.11 header to the skb
3634 (ctl frames may be less than a full header) */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003635 datap = skb_put(skb, hdrlen);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003636 memcpy(datap, &(rxdesc->frame_control), hdrlen);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003637
3638 /* If any, copy the data from the card to the skb */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003639 if (datalen > 0) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003640 datap = skb_put(skb, datalen);
3641 memcpy(datap, rxfrm->data, datalen);
3642
3643 /* check for unencrypted stuff if WEP bit set. */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003644 if (*(datap - hdrlen + 1) & 0x40) /* wep set */
3645 if ((*(datap) == 0xaa) && (*(datap + 1) == 0xaa))
Edgardo Hames631c8de2010-03-08 17:02:37 -08003646 /* clear wep; it's the 802.2 header! */
3647 *(datap - hdrlen + 1) &= 0xbf;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003648 }
3649
3650 if (hw->sniff_fcs) {
3651 /* Set the FCS */
3652 datap = skb_put(skb, WLAN_CRC_LEN);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003653 memset(datap, 0xff, WLAN_CRC_LEN);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003654 }
3655
3656 /* pass it back up */
3657 prism2sta_ev_rx(wlandev, skb);
3658
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003659 return;
3660}
3661
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003662/*----------------------------------------------------------------
3663* hfa384x_usbin_info
3664*
3665* At this point we have a successful received a Prism2 info frame.
3666*
3667* Arguments:
3668* wlandev wlan device
3669* usbin ptr to the usb transfer buffer
3670*
3671* Returns:
3672* nothing
3673*
3674* Side effects:
3675*
3676* Call context:
3677* interrupt
3678----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +05303679static void hfa384x_usbin_info(wlandevice_t *wlandev, hfa384x_usbin_t *usbin)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003680{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003681 usbin->infofrm.info.framelen =
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01003682 le16_to_cpu(usbin->infofrm.info.framelen);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003683 prism2sta_ev_info(wlandev, &usbin->infofrm.info);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003684}
3685
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003686/*----------------------------------------------------------------
3687* hfa384x_usbout_callback
3688*
3689* Callback for URBs on the BULKOUT endpoint.
3690*
3691* Arguments:
3692* urb ptr to the completed urb
3693*
3694* Returns:
3695* nothing
3696*
3697* Side effects:
3698*
3699* Call context:
3700* interrupt
3701----------------------------------------------------------------*/
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003702static void hfa384x_usbout_callback(struct urb *urb)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003703{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003704 wlandevice_t *wlandev = urb->context;
3705 hfa384x_usbout_t *usbout = urb->transfer_buffer;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003706
3707#ifdef DEBUG_USB
3708 dbprint_urb(urb);
3709#endif
3710
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003711 if (wlandev && wlandev->netdev) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003712
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003713 switch (urb->status) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003714 case 0:
3715 hfa384x_usbout_tx(wlandev, usbout);
3716 break;
3717
3718 case -EPIPE:
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003719 {
3720 hfa384x_t *hw = wlandev->priv;
3721 printk(KERN_WARNING
3722 "%s tx pipe stalled: requesting reset\n",
3723 wlandev->netdev->name);
3724 if (!test_and_set_bit
3725 (WORK_TX_HALT, &hw->usb_flags))
3726 schedule_work(&hw->usb_work);
3727 ++(wlandev->linux_stats.tx_errors);
3728 break;
3729 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003730
3731 case -EPROTO:
3732 case -ETIMEDOUT:
3733 case -EILSEQ:
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003734 {
3735 hfa384x_t *hw = wlandev->priv;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003736
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003737 if (!test_and_set_bit
3738 (THROTTLE_TX, &hw->usb_flags)
3739 && !timer_pending(&hw->throttle)) {
3740 mod_timer(&hw->throttle,
3741 jiffies + THROTTLE_JIFFIES);
3742 }
3743 ++(wlandev->linux_stats.tx_errors);
3744 netif_stop_queue(wlandev->netdev);
3745 break;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003746 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003747
3748 case -ENOENT:
3749 case -ESHUTDOWN:
3750 /* Ignorable errors */
3751 break;
3752
3753 default:
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003754 printk(KERN_INFO "unknown urb->status=%d\n",
3755 urb->status);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003756 ++(wlandev->linux_stats.tx_errors);
3757 break;
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003758 } /* switch */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003759 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003760}
3761
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003762/*----------------------------------------------------------------
3763* hfa384x_ctlxout_callback
3764*
3765* Callback for control data on the BULKOUT endpoint.
3766*
3767* Arguments:
3768* urb ptr to the completed urb
3769*
3770* Returns:
3771* nothing
3772*
3773* Side effects:
3774*
3775* Call context:
3776* interrupt
3777----------------------------------------------------------------*/
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003778static void hfa384x_ctlxout_callback(struct urb *urb)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003779{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003780 hfa384x_t *hw = urb->context;
3781 int delete_resptimer = 0;
3782 int timer_ok = 1;
3783 int run_queue = 0;
3784 hfa384x_usbctlx_t *ctlx;
3785 unsigned long flags;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003786
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +01003787 pr_debug("urb->status=%d\n", urb->status);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003788#ifdef DEBUG_USB
3789 dbprint_urb(urb);
3790#endif
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003791 if ((urb->status == -ESHUTDOWN) ||
3792 (urb->status == -ENODEV) || (hw == NULL))
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003793 goto done;
3794
3795retry:
3796 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3797
3798 /*
3799 * Only one CTLX at a time on the "active" list, and
3800 * none at all if we are unplugged. However, we can
3801 * rely on the disconnect function to clean everything
3802 * up if someone unplugged the adapter.
3803 */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003804 if (list_empty(&hw->ctlxq.active)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003805 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3806 goto done;
3807 }
3808
3809 /*
3810 * Having something on the "active" queue means
3811 * that we have timers to worry about ...
3812 */
3813 if (del_timer(&hw->reqtimer) == 0) {
3814 if (hw->req_timer_done == 0) {
3815 /*
3816 * This timer was actually running while we
3817 * were trying to delete it. Let it terminate
3818 * gracefully instead.
3819 */
3820 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3821 goto retry;
3822 }
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003823 } else {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003824 hw->req_timer_done = 1;
3825 }
3826
3827 ctlx = get_active_ctlx(hw);
3828
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003829 if (urb->status == 0) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003830 /* Request portion of a CTLX is successful */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003831 switch (ctlx->state) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003832 case CTLX_REQ_SUBMITTED:
3833 /* This OUT-ACK received before IN */
3834 ctlx->state = CTLX_REQ_COMPLETE;
3835 break;
3836
3837 case CTLX_RESP_COMPLETE:
3838 /* IN already received before this OUT-ACK,
3839 * so this command must now be complete.
3840 */
3841 ctlx->state = CTLX_COMPLETE;
3842 unlocked_usbctlx_complete(hw, ctlx);
3843 run_queue = 1;
3844 break;
3845
3846 default:
3847 /* This is NOT a valid CTLX "success" state! */
Edgardo Hames4ffab682010-03-15 23:00:40 -03003848 printk(KERN_ERR
3849 "Illegal CTLX[%d] success state(%s, %d) in OUT URB\n",
Edgardo Hames631c8de2010-03-08 17:02:37 -08003850 le16_to_cpu(ctlx->outbuf.type),
3851 ctlxstr(ctlx->state), urb->status);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003852 break;
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003853 } /* switch */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003854 } else {
3855 /* If the pipe has stalled then we need to reset it */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003856 if ((urb->status == -EPIPE) &&
3857 !test_and_set_bit(WORK_TX_HALT, &hw->usb_flags)) {
3858 printk(KERN_WARNING
3859 "%s tx pipe stalled: requesting reset\n",
3860 hw->wlandev->netdev->name);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003861 schedule_work(&hw->usb_work);
3862 }
3863
3864 /* If someone cancels the OUT URB then its status
3865 * should be either -ECONNRESET or -ENOENT.
3866 */
3867 ctlx->state = CTLX_REQ_FAILED;
3868 unlocked_usbctlx_complete(hw, ctlx);
3869 delete_resptimer = 1;
3870 run_queue = 1;
3871 }
3872
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003873delresp:
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003874 if (delete_resptimer) {
Svenne Krap46800b22010-02-14 18:59:42 +01003875 timer_ok = del_timer(&hw->resptimer);
Andrew Elwell3f4b4e72010-02-18 23:56:13 +01003876 if (timer_ok != 0)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003877 hw->resp_timer_done = 1;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003878 }
3879
3880 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3881
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003882 if (!timer_ok && (hw->resp_timer_done == 0)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003883 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3884 goto delresp;
3885 }
3886
3887 if (run_queue)
3888 hfa384x_usbctlxq_run(hw);
3889
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003890done:
3891 ;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003892}
3893
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003894/*----------------------------------------------------------------
3895* hfa384x_usbctlx_reqtimerfn
3896*
3897* Timer response function for CTLX request timeouts. If this
3898* function is called, it means that the callback for the OUT
3899* URB containing a Prism2.x XXX_Request was never called.
3900*
3901* Arguments:
3902* data a ptr to the hfa384x_t
3903*
3904* Returns:
3905* nothing
3906*
3907* Side effects:
3908*
3909* Call context:
3910* interrupt
3911----------------------------------------------------------------*/
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003912static void hfa384x_usbctlx_reqtimerfn(unsigned long data)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003913{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003914 hfa384x_t *hw = (hfa384x_t *) data;
3915 unsigned long flags;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003916
3917 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3918
3919 hw->req_timer_done = 1;
3920
3921 /* Removing the hardware automatically empties
3922 * the active list ...
3923 */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003924 if (!list_empty(&hw->ctlxq.active)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003925 /*
3926 * We must ensure that our URB is removed from
3927 * the system, if it hasn't already expired.
3928 */
3929 hw->ctlx_urb.transfer_flags |= URB_ASYNC_UNLINK;
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003930 if (usb_unlink_urb(&hw->ctlx_urb) == -EINPROGRESS) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003931 hfa384x_usbctlx_t *ctlx = get_active_ctlx(hw);
3932
3933 ctlx->state = CTLX_REQ_FAILED;
3934
3935 /* This URB was active, but has now been
3936 * cancelled. It will now have a status of
3937 * -ECONNRESET in the callback function.
3938 *
3939 * We are cancelling this CTLX, so we're
3940 * not going to need to wait for a response.
3941 * The URB's callback function will check
3942 * that this timer is truly dead.
3943 */
3944 if (del_timer(&hw->resptimer) != 0)
3945 hw->resp_timer_done = 1;
3946 }
3947 }
3948
3949 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003950}
3951
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003952/*----------------------------------------------------------------
3953* hfa384x_usbctlx_resptimerfn
3954*
3955* Timer response function for CTLX response timeouts. If this
3956* function is called, it means that the callback for the IN
3957* URB containing a Prism2.x XXX_Response was never called.
3958*
3959* Arguments:
3960* data a ptr to the hfa384x_t
3961*
3962* Returns:
3963* nothing
3964*
3965* Side effects:
3966*
3967* Call context:
3968* interrupt
3969----------------------------------------------------------------*/
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003970static void hfa384x_usbctlx_resptimerfn(unsigned long data)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003971{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003972 hfa384x_t *hw = (hfa384x_t *) data;
3973 unsigned long flags;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003974
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003975 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3976
3977 hw->resp_timer_done = 1;
3978
3979 /* The active list will be empty if the
3980 * adapter has been unplugged ...
3981 */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003982 if (!list_empty(&hw->ctlxq.active)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003983 hfa384x_usbctlx_t *ctlx = get_active_ctlx(hw);
3984
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003985 if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003986 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3987 hfa384x_usbctlxq_run(hw);
3988 goto done;
3989 }
3990 }
3991
3992 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3993
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003994done:
3995 ;
Moritz Muehlenhoff8a251b52009-01-21 22:00:44 +01003996
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003997}
3998
3999/*----------------------------------------------------------------
4000* hfa384x_usb_throttlefn
4001*
4002*
4003* Arguments:
4004* data ptr to hw
4005*
4006* Returns:
4007* Nothing
4008*
4009* Side effects:
4010*
4011* Call context:
4012* Interrupt
4013----------------------------------------------------------------*/
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01004014static void hfa384x_usb_throttlefn(unsigned long data)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07004015{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01004016 hfa384x_t *hw = (hfa384x_t *) data;
4017 unsigned long flags;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07004018
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07004019 spin_lock_irqsave(&hw->ctlxq.lock, flags);
4020
4021 /*
4022 * We need to check BOTH the RX and the TX throttle controls,
4023 * so we use the bitwise OR instead of the logical OR.
4024 */
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +01004025 pr_debug("flags=0x%lx\n", hw->usb_flags);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01004026 if (!hw->wlandev->hwremoved &&
4027 ((test_and_clear_bit(THROTTLE_RX, &hw->usb_flags) &&
4028 !test_and_set_bit(WORK_RX_RESUME, &hw->usb_flags))
4029 |
4030 (test_and_clear_bit(THROTTLE_TX, &hw->usb_flags) &&
4031 !test_and_set_bit(WORK_TX_RESUME, &hw->usb_flags))
4032 )) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07004033 schedule_work(&hw->usb_work);
4034 }
4035
4036 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07004037}
4038
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07004039/*----------------------------------------------------------------
4040* hfa384x_usbctlx_submit
4041*
4042* Called from the doxxx functions to submit a CTLX to the queue
4043*
4044* Arguments:
4045* hw ptr to the hw struct
4046* ctlx ctlx structure to enqueue
4047*
4048* Returns:
4049* -ENODEV if the adapter is unplugged
4050* 0
4051*
4052* Side effects:
4053*
4054* Call context:
4055* process or interrupt
4056----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +05304057static int hfa384x_usbctlx_submit(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07004058{
4059 unsigned long flags;
4060 int ret;
4061
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07004062 spin_lock_irqsave(&hw->ctlxq.lock, flags);
4063
4064 if (hw->wlandev->hwremoved) {
4065 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
4066 ret = -ENODEV;
4067 } else {
4068 ctlx->state = CTLX_PENDING;
4069 list_add_tail(&ctlx->list, &hw->ctlxq.pending);
4070
4071 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
4072 hfa384x_usbctlxq_run(hw);
4073 ret = 0;
4074 }
4075
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07004076 return ret;
4077}
4078
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07004079/*----------------------------------------------------------------
4080* hfa384x_usbout_tx
4081*
4082* At this point we have finished a send of a frame. Mark the URB
4083* as available and call ev_alloc to notify higher layers we're
4084* ready for more.
4085*
4086* Arguments:
4087* wlandev wlan device
4088* usbout ptr to the usb transfer buffer
4089*
4090* Returns:
4091* nothing
4092*
4093* Side effects:
4094*
4095* Call context:
4096* interrupt
4097----------------------------------------------------------------*/
Mithlesh Thukral297f06c2009-06-10 19:36:11 +05304098static void hfa384x_usbout_tx(wlandevice_t *wlandev, hfa384x_usbout_t *usbout)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07004099{
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07004100 prism2sta_ev_alloc(wlandev);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07004101}
4102
4103/*----------------------------------------------------------------
4104* hfa384x_isgood_pdrcore
4105*
4106* Quick check of PDR codes.
4107*
4108* Arguments:
4109* pdrcode PDR code number (host order)
4110*
4111* Returns:
4112* zero not good.
4113* one is good.
4114*
4115* Side effects:
4116*
4117* Call context:
4118----------------------------------------------------------------*/
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01004119static int hfa384x_isgood_pdrcode(u16 pdrcode)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07004120{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01004121 switch (pdrcode) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07004122 case HFA384x_PDR_END_OF_PDA:
4123 case HFA384x_PDR_PCB_PARTNUM:
4124 case HFA384x_PDR_PDAVER:
4125 case HFA384x_PDR_NIC_SERIAL:
4126 case HFA384x_PDR_MKK_MEASUREMENTS:
4127 case HFA384x_PDR_NIC_RAMSIZE:
4128 case HFA384x_PDR_MFISUPRANGE:
4129 case HFA384x_PDR_CFISUPRANGE:
4130 case HFA384x_PDR_NICID:
4131 case HFA384x_PDR_MAC_ADDRESS:
4132 case HFA384x_PDR_REGDOMAIN:
4133 case HFA384x_PDR_ALLOWED_CHANNEL:
4134 case HFA384x_PDR_DEFAULT_CHANNEL:
4135 case HFA384x_PDR_TEMPTYPE:
4136 case HFA384x_PDR_IFR_SETTING:
4137 case HFA384x_PDR_RFR_SETTING:
4138 case HFA384x_PDR_HFA3861_BASELINE:
4139 case HFA384x_PDR_HFA3861_SHADOW:
4140 case HFA384x_PDR_HFA3861_IFRF:
4141 case HFA384x_PDR_HFA3861_CHCALSP:
4142 case HFA384x_PDR_HFA3861_CHCALI:
4143 case HFA384x_PDR_3842_NIC_CONFIG:
4144 case HFA384x_PDR_USB_ID:
4145 case HFA384x_PDR_PCI_ID:
4146 case HFA384x_PDR_PCI_IFCONF:
4147 case HFA384x_PDR_PCI_PMCONF:
4148 case HFA384x_PDR_RFENRGY:
4149 case HFA384x_PDR_HFA3861_MANF_TESTSP:
4150 case HFA384x_PDR_HFA3861_MANF_TESTI:
4151 /* code is OK */
4152 return 1;
4153 break;
4154 default:
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01004155 if (pdrcode < 0x1000) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07004156 /* code is OK, but we don't know exactly what it is */
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05304157 pr_debug("Encountered unknown PDR#=0x%04x, "
4158 "assuming it's ok.\n", pdrcode);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07004159 return 1;
4160 } else {
4161 /* bad code */
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05304162 pr_debug("Encountered unknown PDR#=0x%04x, "
4163 "(>=0x1000), assuming it's bad.\n", pdrcode);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07004164 return 0;
4165 }
4166 break;
4167 }
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01004168 return 0; /* avoid compiler warnings */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07004169}