blob: 6a107f8a06e2929d32431f7190d5065eb365e0e9 [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
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700129#include "p80211types.h"
130#include "p80211hdr.h"
131#include "p80211mgmt.h"
132#include "p80211conv.h"
133#include "p80211msg.h"
134#include "p80211netdev.h"
135#include "p80211req.h"
136#include "p80211metadef.h"
137#include "p80211metastruct.h"
138#include "hfa384x.h"
139#include "prism2mgmt.h"
140
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100141enum cmd_mode {
142 DOWAIT = 0,
143 DOASYNC
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700144};
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700145
Bogicevic Sasa6c37e1f2015-12-14 06:25:59 -0800146#define THROTTLE_JIFFIES (HZ / 8)
Moritz Muehlenhoff2d200d92009-01-25 21:54:56 +0100147#define URB_ASYNC_UNLINK 0
148#define USB_QUEUE_BULK 0
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700149
Bogicevic Sasa6c37e1f2015-12-14 06:25:59 -0800150#define ROUNDUP64(a) (((a) + 63) & ~63)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700151
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700152#ifdef DEBUG_USB
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100153static void dbprint_urb(struct urb *urb);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700154#endif
155
156static void
Sergio Paracuellos684b2e02016-09-28 20:19:28 +0200157hfa384x_int_rxmonitor(struct wlandevice *wlandev, struct hfa384x_usb_rxfrm *rxfrm);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700158
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100159static void hfa384x_usb_defer(struct work_struct *data);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700160
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +0200161static int submit_rx_urb(struct hfa384x *hw, gfp_t flags);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700162
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +0200163static int submit_tx_urb(struct hfa384x *hw, struct urb *tx_urb, gfp_t flags);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700164
165/*---------------------------------------------------*/
166/* Callbacks */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100167static void hfa384x_usbout_callback(struct urb *urb);
168static void hfa384x_ctlxout_callback(struct urb *urb);
169static void hfa384x_usbin_callback(struct urb *urb);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700170
171static void
Sergio Paracuellos3e4180c2016-09-28 20:19:38 +0200172hfa384x_usbin_txcompl(struct wlandevice *wlandev, union hfa384x_usbin *usbin);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700173
sayli karnikc9573a82016-09-18 15:11:14 +0530174static void hfa384x_usbin_rx(struct wlandevice *wlandev, struct sk_buff *skb);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700175
Sergio Paracuellos3e4180c2016-09-28 20:19:38 +0200176static void hfa384x_usbin_info(struct wlandevice *wlandev, union hfa384x_usbin *usbin);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700177
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +0200178static void hfa384x_usbin_ctlx(struct hfa384x *hw, union hfa384x_usbin *usbin,
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700179 int urb_status);
180
181/*---------------------------------------------------*/
182/* Functions to support the prism2 usb command queue */
183
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +0200184static void hfa384x_usbctlxq_run(struct hfa384x *hw);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700185
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100186static void hfa384x_usbctlx_reqtimerfn(unsigned long data);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700187
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100188static void hfa384x_usbctlx_resptimerfn(unsigned long data);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700189
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100190static void hfa384x_usb_throttlefn(unsigned long data);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700191
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100192static void hfa384x_usbctlx_completion_task(unsigned long data);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700193
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100194static void hfa384x_usbctlx_reaper_task(unsigned long data);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700195
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +0200196static int hfa384x_usbctlx_submit(struct hfa384x *hw, struct hfa384x_usbctlx *ctlx);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700197
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +0200198static void unlocked_usbctlx_complete(struct hfa384x *hw, struct hfa384x_usbctlx *ctlx);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700199
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100200struct usbctlx_completor {
Sherif Shehab Aldin83f91682014-04-05 23:34:12 +0200201 int (*complete)(struct usbctlx_completor *);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700202};
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700203
204static int
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +0200205hfa384x_usbctlx_complete_sync(struct hfa384x *hw,
Sergio Paracuellosa10d36b2016-09-28 20:20:16 +0200206 struct hfa384x_usbctlx *ctlx,
Edgardo Hames631c8de2010-03-08 17:02:37 -0800207 struct usbctlx_completor *completor);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700208
209static int
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +0200210unlocked_usbctlx_cancel_async(struct hfa384x *hw, struct hfa384x_usbctlx *ctlx);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700211
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +0200212static void hfa384x_cb_status(struct hfa384x *hw, const struct hfa384x_usbctlx *ctlx);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700213
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700214static int
Sergio Paracuellos385a79d2016-09-28 20:19:30 +0200215usbctlx_get_status(const struct hfa384x_usb_statusresp *cmdresp,
Sergio Paracuellos501f5f92016-09-28 20:20:14 +0200216 struct hfa384x_cmdresult *result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700217
218static void
Sergio Paracuellosa988c9f2016-09-28 20:19:32 +0200219usbctlx_get_rridresult(const struct hfa384x_usb_rridresp *rridresp,
Sergio Paracuellosb3fd8902016-09-28 20:20:15 +0200220 struct hfa384x_rridresult *result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700221
222/*---------------------------------------------------*/
223/* Low level req/resp CTLX formatters and submitters */
224static int
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +0200225hfa384x_docmd(struct hfa384x *hw,
Edgardo Hames631c8de2010-03-08 17:02:37 -0800226 enum cmd_mode mode,
Sergio Paracuellose2f503c2016-09-28 20:20:18 +0200227 struct hfa384x_metacmd *cmd,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100228 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700229
230static int
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +0200231hfa384x_dorrid(struct hfa384x *hw,
Edgardo Hames631c8de2010-03-08 17:02:37 -0800232 enum cmd_mode mode,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100233 u16 rid,
234 void *riddata,
235 unsigned int riddatalen,
236 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700237
238static int
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +0200239hfa384x_dowrid(struct hfa384x *hw,
Edgardo Hames631c8de2010-03-08 17:02:37 -0800240 enum cmd_mode mode,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100241 u16 rid,
242 void *riddata,
243 unsigned int riddatalen,
244 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700245
246static int
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +0200247hfa384x_dormem(struct hfa384x *hw,
Edgardo Hames631c8de2010-03-08 17:02:37 -0800248 enum cmd_mode mode,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100249 u16 page,
250 u16 offset,
251 void *data,
252 unsigned int len,
253 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700254
255static int
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +0200256hfa384x_dowmem(struct hfa384x *hw,
Edgardo Hames631c8de2010-03-08 17:02:37 -0800257 enum cmd_mode mode,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100258 u16 page,
259 u16 offset,
260 void *data,
261 unsigned int len,
262 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700263
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100264static int hfa384x_isgood_pdrcode(u16 pdrcode);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700265
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100266static inline const char *ctlxstr(CTLX_STATE s)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700267{
Sherif Shehab Aldind6ae4a92014-04-05 23:34:01 +0200268 static const char * const ctlx_str[] = {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700269 "Initial state",
270 "Complete",
271 "Request failed",
272 "Request pending",
273 "Request packet submitted",
274 "Request packet completed",
275 "Response packet completed"
276 };
277
278 return ctlx_str[s];
279};
280
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +0200281static inline struct hfa384x_usbctlx *get_active_ctlx(struct hfa384x *hw)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700282{
Sergio Paracuellosa10d36b2016-09-28 20:20:16 +0200283 return list_entry(hw->ctlxq.active.next, struct hfa384x_usbctlx, list);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700284}
285
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700286#ifdef DEBUG_USB
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100287void dbprint_urb(struct urb *urb)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700288{
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +0100289 pr_debug("urb->pipe=0x%08x\n", urb->pipe);
290 pr_debug("urb->status=0x%08x\n", urb->status);
291 pr_debug("urb->transfer_flags=0x%08x\n", urb->transfer_flags);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100292 pr_debug("urb->transfer_buffer=0x%08x\n",
Mithlesh Thukral75f49e02009-05-25 19:06:16 +0530293 (unsigned int)urb->transfer_buffer);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100294 pr_debug("urb->transfer_buffer_length=0x%08x\n",
Mithlesh Thukral75f49e02009-05-25 19:06:16 +0530295 urb->transfer_buffer_length);
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +0100296 pr_debug("urb->actual_length=0x%08x\n", urb->actual_length);
297 pr_debug("urb->bandwidth=0x%08x\n", urb->bandwidth);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100298 pr_debug("urb->setup_packet(ctl)=0x%08x\n",
Mithlesh Thukral75f49e02009-05-25 19:06:16 +0530299 (unsigned int)urb->setup_packet);
300 pr_debug("urb->start_frame(iso/irq)=0x%08x\n", urb->start_frame);
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +0100301 pr_debug("urb->interval(irq)=0x%08x\n", urb->interval);
302 pr_debug("urb->error_count(iso)=0x%08x\n", urb->error_count);
303 pr_debug("urb->timeout=0x%08x\n", urb->timeout);
304 pr_debug("urb->context=0x%08x\n", (unsigned int)urb->context);
Mithlesh Thukral75f49e02009-05-25 19:06:16 +0530305 pr_debug("urb->complete=0x%08x\n", (unsigned int)urb->complete);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700306}
307#endif
308
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700309/*----------------------------------------------------------------
310* submit_rx_urb
311*
312* Listen for input data on the BULK-IN pipe. If the pipe has
313* stalled then schedule it to be reset.
314*
315* Arguments:
316* hw device struct
317* memflags memory allocation flags
318*
319* Returns:
320* error code from submission
321*
322* Call context:
323* Any
324----------------------------------------------------------------*/
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +0200325static int submit_rx_urb(struct hfa384x *hw, gfp_t memflags)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700326{
327 struct sk_buff *skb;
328 int result;
329
Sergio Paracuellos3e4180c2016-09-28 20:19:38 +0200330 skb = dev_alloc_skb(sizeof(union hfa384x_usbin));
Eva Rachel Retuyae2e77522016-02-27 20:39:25 +0800331 if (!skb) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700332 result = -ENOMEM;
333 goto done;
334 }
335
336 /* Post the IN urb */
337 usb_fill_bulk_urb(&hw->rx_urb, hw->usb,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100338 hw->endp_in,
Sergio Paracuellos3e4180c2016-09-28 20:19:38 +0200339 skb->data, sizeof(union hfa384x_usbin),
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100340 hfa384x_usbin_callback, hw->wlandev);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700341
342 hw->rx_urb_skb = skb;
343
344 result = -ENOLINK;
Edgardo Hames631c8de2010-03-08 17:02:37 -0800345 if (!hw->wlandev->hwremoved &&
Sherif Shehab Aldin3f2d6562014-04-05 23:34:40 +0200346 !test_bit(WORK_RX_HALT, &hw->usb_flags)) {
Amitoj Kaur Chawla5850c252016-02-24 21:55:49 +0530347 result = usb_submit_urb(&hw->rx_urb, memflags);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700348
349 /* Check whether we need to reset the RX pipe */
350 if (result == -EPIPE) {
Avinash Kumar263b8bb2013-09-06 22:21:49 +0530351 netdev_warn(hw->wlandev->netdev,
Sherif Shehab Aldin3f2d6562014-04-05 23:34:40 +0200352 "%s rx pipe stalled: requesting reset\n",
353 hw->wlandev->netdev->name);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100354 if (!test_and_set_bit(WORK_RX_HALT, &hw->usb_flags))
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700355 schedule_work(&hw->usb_work);
356 }
357 }
358
359 /* Don't leak memory if anything should go wrong */
360 if (result != 0) {
361 dev_kfree_skb(skb);
362 hw->rx_urb_skb = NULL;
363 }
364
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100365done:
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700366 return result;
367}
368
369/*----------------------------------------------------------------
370* submit_tx_urb
371*
372* Prepares and submits the URB of transmitted data. If the
373* submission fails then it will schedule the output pipe to
374* be reset.
375*
376* Arguments:
377* hw device struct
Masanari Iida1a6dfce2014-12-01 00:29:00 +0900378* tx_urb URB of data for transmission
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700379* memflags memory allocation flags
380*
381* Returns:
382* error code from submission
383*
384* Call context:
385* Any
386----------------------------------------------------------------*/
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +0200387static int submit_tx_urb(struct hfa384x *hw, struct urb *tx_urb, gfp_t memflags)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700388{
389 struct net_device *netdev = hw->wlandev->netdev;
390 int result;
391
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700392 result = -ENOLINK;
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100393 if (netif_running(netdev)) {
Sherif Shehab Aldina3542e62014-04-05 23:34:48 +0200394 if (!hw->wlandev->hwremoved &&
395 !test_bit(WORK_TX_HALT, &hw->usb_flags)) {
Amitoj Kaur Chawla5850c252016-02-24 21:55:49 +0530396 result = usb_submit_urb(tx_urb, memflags);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700397
398 /* Test whether we need to reset the TX pipe */
399 if (result == -EPIPE) {
Avinash Kumar263b8bb2013-09-06 22:21:49 +0530400 netdev_warn(hw->wlandev->netdev,
Sherif Shehab Aldin3f2d6562014-04-05 23:34:40 +0200401 "%s tx pipe stalled: requesting reset\n",
402 netdev->name);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700403 set_bit(WORK_TX_HALT, &hw->usb_flags);
404 schedule_work(&hw->usb_work);
405 } else if (result == 0) {
406 netif_stop_queue(netdev);
407 }
408 }
409 }
410
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700411 return result;
412}
413
414/*----------------------------------------------------------------
415* hfa394x_usb_defer
416*
417* There are some things that the USB stack cannot do while
418* in interrupt context, so we arrange this function to run
419* in process context.
420*
421* Arguments:
422* hw device structure
423*
424* Returns:
425* nothing
426*
427* Call context:
428* process (by design)
429----------------------------------------------------------------*/
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100430static void hfa384x_usb_defer(struct work_struct *data)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700431{
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +0200432 struct hfa384x *hw = container_of(data, struct hfa384x, usb_work);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700433 struct net_device *netdev = hw->wlandev->netdev;
434
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700435 /* Don't bother trying to reset anything if the plug
436 * has been pulled ...
437 */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100438 if (hw->wlandev->hwremoved)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700439 return;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700440
441 /* Reception has stopped: try to reset the input pipe */
442 if (test_bit(WORK_RX_HALT, &hw->usb_flags)) {
443 int ret;
444
Edgardo Hames631c8de2010-03-08 17:02:37 -0800445 usb_kill_urb(&hw->rx_urb); /* Cannot be holding spinlock! */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700446
447 ret = usb_clear_halt(hw->usb, hw->endp_in);
448 if (ret != 0) {
Avinash Kumar263b8bb2013-09-06 22:21:49 +0530449 netdev_err(hw->wlandev->netdev,
Sherif Shehab Aldin3f2d6562014-04-05 23:34:40 +0200450 "Failed to clear rx pipe for %s: err=%d\n",
451 netdev->name, ret);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700452 } else {
Avinash Kumar263b8bb2013-09-06 22:21:49 +0530453 netdev_info(hw->wlandev->netdev, "%s rx pipe reset complete.\n",
Sherif Shehab Aldin3f2d6562014-04-05 23:34:40 +0200454 netdev->name);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700455 clear_bit(WORK_RX_HALT, &hw->usb_flags);
456 set_bit(WORK_RX_RESUME, &hw->usb_flags);
457 }
458 }
459
460 /* Resume receiving data back from the device. */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100461 if (test_bit(WORK_RX_RESUME, &hw->usb_flags)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700462 int ret;
463
464 ret = submit_rx_urb(hw, GFP_KERNEL);
465 if (ret != 0) {
Avinash Kumar263b8bb2013-09-06 22:21:49 +0530466 netdev_err(hw->wlandev->netdev,
Sherif Shehab Aldin3f2d6562014-04-05 23:34:40 +0200467 "Failed to resume %s rx pipe.\n",
468 netdev->name);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700469 } else {
470 clear_bit(WORK_RX_RESUME, &hw->usb_flags);
471 }
472 }
473
474 /* Transmission has stopped: try to reset the output pipe */
475 if (test_bit(WORK_TX_HALT, &hw->usb_flags)) {
476 int ret;
477
478 usb_kill_urb(&hw->tx_urb);
479 ret = usb_clear_halt(hw->usb, hw->endp_out);
480 if (ret != 0) {
Avinash Kumar263b8bb2013-09-06 22:21:49 +0530481 netdev_err(hw->wlandev->netdev,
Sherif Shehab Aldin3f2d6562014-04-05 23:34:40 +0200482 "Failed to clear tx pipe for %s: err=%d\n",
483 netdev->name, ret);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700484 } else {
Avinash Kumar263b8bb2013-09-06 22:21:49 +0530485 netdev_info(hw->wlandev->netdev, "%s tx pipe reset complete.\n",
Sherif Shehab Aldin3f2d6562014-04-05 23:34:40 +0200486 netdev->name);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700487 clear_bit(WORK_TX_HALT, &hw->usb_flags);
488 set_bit(WORK_TX_RESUME, &hw->usb_flags);
489
490 /* Stopping the BULK-OUT pipe also blocked
491 * us from sending any more CTLX URBs, so
492 * we need to re-run our queue ...
493 */
494 hfa384x_usbctlxq_run(hw);
495 }
496 }
497
498 /* Resume transmitting. */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100499 if (test_and_clear_bit(WORK_TX_RESUME, &hw->usb_flags))
Solomon Peachycbec30c2008-10-29 10:42:57 -0400500 netif_wake_queue(hw->wlandev->netdev);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700501}
502
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700503/*----------------------------------------------------------------
504* hfa384x_create
505*
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +0200506* Sets up the struct hfa384x data structure for use. Note this
Uwe Kleine-König9b0131c2010-09-01 15:40:25 +0200507* does _not_ initialize the actual hardware, just the data structures
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700508* we use to keep track of its state.
509*
510* Arguments:
511* hw device structure
512* irq device irq number
513* iobase i/o base address for register access
514* membase memory base address for register access
515*
516* Returns:
517* nothing
518*
519* Side effects:
520*
521* Call context:
522* process
523----------------------------------------------------------------*/
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +0200524void hfa384x_create(struct hfa384x *hw, struct usb_device *usb)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700525{
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +0200526 memset(hw, 0, sizeof(struct hfa384x));
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700527 hw->usb = usb;
528
529 /* set up the endpoints */
530 hw->endp_in = usb_rcvbulkpipe(usb, 1);
531 hw->endp_out = usb_sndbulkpipe(usb, 2);
532
533 /* Set up the waitq */
534 init_waitqueue_head(&hw->cmdq);
535
536 /* Initialize the command queue */
537 spin_lock_init(&hw->ctlxq.lock);
538 INIT_LIST_HEAD(&hw->ctlxq.pending);
539 INIT_LIST_HEAD(&hw->ctlxq.active);
540 INIT_LIST_HEAD(&hw->ctlxq.completing);
541 INIT_LIST_HEAD(&hw->ctlxq.reapable);
542
543 /* Initialize the authentication queue */
544 skb_queue_head_init(&hw->authq);
545
546 tasklet_init(&hw->reaper_bh,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100547 hfa384x_usbctlx_reaper_task, (unsigned long)hw);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700548 tasklet_init(&hw->completion_bh,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100549 hfa384x_usbctlx_completion_task, (unsigned long)hw);
Solomon Peachy575a8a52008-10-29 10:42:54 -0400550 INIT_WORK(&hw->link_bh, prism2sta_processing_defer);
551 INIT_WORK(&hw->usb_work, hfa384x_usb_defer);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700552
Aya Mahfouz2f83aed2015-02-19 07:55:43 +0200553 setup_timer(&hw->throttle, hfa384x_usb_throttlefn, (unsigned long)hw);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700554
Aya Mahfouz2f83aed2015-02-19 07:55:43 +0200555 setup_timer(&hw->resptimer, hfa384x_usbctlx_resptimerfn,
556 (unsigned long)hw);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700557
Aya Mahfouz2f83aed2015-02-19 07:55:43 +0200558 setup_timer(&hw->reqtimer, hfa384x_usbctlx_reqtimerfn,
559 (unsigned long)hw);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700560
561 usb_init_urb(&hw->rx_urb);
562 usb_init_urb(&hw->tx_urb);
563 usb_init_urb(&hw->ctlx_urb);
564
565 hw->link_status = HFA384x_LINK_NOTCONNECTED;
566 hw->state = HFA384x_STATE_INIT;
567
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100568 INIT_WORK(&hw->commsqual_bh, prism2sta_commsqual_defer);
Aya Mahfouz2f83aed2015-02-19 07:55:43 +0200569 setup_timer(&hw->commsqual_timer, prism2sta_commsqual_timer,
570 (unsigned long)hw);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700571}
572
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700573/*----------------------------------------------------------------
574* hfa384x_destroy
575*
576* Partner to hfa384x_create(). This function cleans up the hw
577* structure so that it can be freed by the caller using a simple
578* kfree. Currently, this function is just a placeholder. If, at some
579* point in the future, an hw in the 'shutdown' state requires a 'deep'
580* kfree, this is where it should be done. Note that if this function
581* is called on a _running_ hw structure, the drvr_stop() function is
582* called.
583*
584* Arguments:
585* hw device structure
586*
587* Returns:
588* nothing, this function is not allowed to fail.
589*
590* Side effects:
591*
592* Call context:
593* process
594----------------------------------------------------------------*/
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +0200595void hfa384x_destroy(struct hfa384x *hw)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700596{
597 struct sk_buff *skb;
598
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100599 if (hw->state == HFA384x_STATE_RUNNING)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700600 hfa384x_drvr_stop(hw);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700601 hw->state = HFA384x_STATE_PREINIT;
602
Ilia Mirkina6f9c482011-03-13 00:29:17 -0500603 kfree(hw->scanresults);
604 hw->scanresults = NULL;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700605
606 /* Now to clean out the auth queue */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100607 while ((skb = skb_dequeue(&hw->authq)))
608 dev_kfree_skb(skb);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700609}
610
Sergio Paracuellosa10d36b2016-09-28 20:20:16 +0200611static struct hfa384x_usbctlx *usbctlx_alloc(void)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700612{
Sergio Paracuellosa10d36b2016-09-28 20:20:16 +0200613 struct hfa384x_usbctlx *ctlx;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700614
Navya Sri Nizamkarid0edf4b2015-03-10 17:55:40 +0530615 ctlx = kzalloc(sizeof(*ctlx),
616 in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
Nicholas Sim02e02042016-04-05 17:37:12 +0100617 if (ctlx)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700618 init_completion(&ctlx->done);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700619
620 return ctlx;
621}
622
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700623static int
Sergio Paracuellos385a79d2016-09-28 20:19:30 +0200624usbctlx_get_status(const struct hfa384x_usb_statusresp *cmdresp,
Sergio Paracuellos501f5f92016-09-28 20:20:14 +0200625 struct hfa384x_cmdresult *result)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700626{
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100627 result->status = le16_to_cpu(cmdresp->status);
628 result->resp0 = le16_to_cpu(cmdresp->resp0);
629 result->resp1 = le16_to_cpu(cmdresp->resp1);
630 result->resp2 = le16_to_cpu(cmdresp->resp2);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700631
Sherif Shehab Aldina2120132014-04-05 23:33:16 +0200632 pr_debug("cmdresult:status=0x%04x resp0=0x%04x resp1=0x%04x resp2=0x%04x\n",
Mithlesh Thukral75f49e02009-05-25 19:06:16 +0530633 result->status, result->resp0, result->resp1, result->resp2);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700634
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100635 return result->status & HFA384x_STATUS_RESULT;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700636}
637
638static void
Sergio Paracuellosa988c9f2016-09-28 20:19:32 +0200639usbctlx_get_rridresult(const struct hfa384x_usb_rridresp *rridresp,
Sergio Paracuellosb3fd8902016-09-28 20:20:15 +0200640 struct hfa384x_rridresult *result)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700641{
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100642 result->rid = le16_to_cpu(rridresp->rid);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700643 result->riddata = rridresp->data;
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +0100644 result->riddata_len = ((le16_to_cpu(rridresp->frmlen) - 1) * 2);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700645}
646
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700647/*----------------------------------------------------------------
648* Completor object:
649* This completor must be passed to hfa384x_usbctlx_complete_sync()
Sergio Paracuellos501f5f92016-09-28 20:20:14 +0200650* when processing a CTLX that returns a struct hfa384x_cmdresult structure.
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700651----------------------------------------------------------------*/
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100652struct usbctlx_cmd_completor {
Edgardo Hames631c8de2010-03-08 17:02:37 -0800653 struct usbctlx_completor head;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700654
Sergio Paracuellos385a79d2016-09-28 20:19:30 +0200655 const struct hfa384x_usb_statusresp *cmdresp;
Sergio Paracuellos501f5f92016-09-28 20:20:14 +0200656 struct hfa384x_cmdresult *result;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700657};
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700658
Edgardo Hames631c8de2010-03-08 17:02:37 -0800659static inline int usbctlx_cmd_completor_fn(struct usbctlx_completor *head)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700660{
Edgardo Hames631c8de2010-03-08 17:02:37 -0800661 struct usbctlx_cmd_completor *complete;
662
Sherif Shehab Aldin5d85fe32014-04-05 23:35:15 +0200663 complete = (struct usbctlx_cmd_completor *)head;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700664 return usbctlx_get_status(complete->cmdresp, complete->result);
665}
666
Edgardo Hames631c8de2010-03-08 17:02:37 -0800667static inline struct usbctlx_completor *init_cmd_completor(
668 struct usbctlx_cmd_completor
669 *completor,
Sergio Paracuellos385a79d2016-09-28 20:19:30 +0200670 const struct hfa384x_usb_statusresp
Edgardo Hames631c8de2010-03-08 17:02:37 -0800671 *cmdresp,
Sergio Paracuellos501f5f92016-09-28 20:20:14 +0200672 struct hfa384x_cmdresult *result)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700673{
674 completor->head.complete = usbctlx_cmd_completor_fn;
675 completor->cmdresp = cmdresp;
676 completor->result = result;
677 return &(completor->head);
678}
679
680/*----------------------------------------------------------------
681* Completor object:
682* This completor must be passed to hfa384x_usbctlx_complete_sync()
683* when processing a CTLX that reads a RID.
684----------------------------------------------------------------*/
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100685struct usbctlx_rrid_completor {
Edgardo Hames631c8de2010-03-08 17:02:37 -0800686 struct usbctlx_completor head;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700687
Sergio Paracuellosa988c9f2016-09-28 20:19:32 +0200688 const struct hfa384x_usb_rridresp *rridresp;
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100689 void *riddata;
690 unsigned int riddatalen;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700691};
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700692
Edgardo Hames631c8de2010-03-08 17:02:37 -0800693static int usbctlx_rrid_completor_fn(struct usbctlx_completor *head)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700694{
Edgardo Hames631c8de2010-03-08 17:02:37 -0800695 struct usbctlx_rrid_completor *complete;
Sergio Paracuellosb3fd8902016-09-28 20:20:15 +0200696 struct hfa384x_rridresult rridresult;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700697
Sherif Shehab Aldin5d85fe32014-04-05 23:35:15 +0200698 complete = (struct usbctlx_rrid_completor *)head;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700699 usbctlx_get_rridresult(complete->rridresp, &rridresult);
700
701 /* Validate the length, note body len calculation in bytes */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100702 if (rridresult.riddata_len != complete->riddatalen) {
Sherif Shehab Aldinbaa8a6c2014-04-05 23:33:53 +0200703 pr_warn("RID len mismatch, rid=0x%04x hlen=%d fwlen=%d\n",
704 rridresult.rid,
705 complete->riddatalen, rridresult.riddata_len);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700706 return -ENODATA;
707 }
708
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100709 memcpy(complete->riddata, rridresult.riddata, complete->riddatalen);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700710 return 0;
711}
712
Edgardo Hames631c8de2010-03-08 17:02:37 -0800713static inline struct usbctlx_completor *init_rrid_completor(
714 struct usbctlx_rrid_completor
715 *completor,
Sergio Paracuellosa988c9f2016-09-28 20:19:32 +0200716 const struct hfa384x_usb_rridresp
Edgardo Hames631c8de2010-03-08 17:02:37 -0800717 *rridresp,
718 void *riddata,
719 unsigned int riddatalen)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700720{
721 completor->head.complete = usbctlx_rrid_completor_fn;
722 completor->rridresp = rridresp;
723 completor->riddata = riddata;
724 completor->riddatalen = riddatalen;
725 return &(completor->head);
726}
727
728/*----------------------------------------------------------------
729* Completor object:
730* Interprets the results of a synchronous RID-write
731----------------------------------------------------------------*/
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700732#define init_wrid_completor init_cmd_completor
733
734/*----------------------------------------------------------------
735* Completor object:
736* Interprets the results of a synchronous memory-write
737----------------------------------------------------------------*/
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700738#define init_wmem_completor init_cmd_completor
739
740/*----------------------------------------------------------------
741* Completor object:
742* Interprets the results of a synchronous memory-read
743----------------------------------------------------------------*/
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100744struct usbctlx_rmem_completor {
Edgardo Hames631c8de2010-03-08 17:02:37 -0800745 struct usbctlx_completor head;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700746
Sergio Paracuellos1ed54802016-09-28 20:19:34 +0200747 const struct hfa384x_usb_rmemresp *rmemresp;
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100748 void *data;
749 unsigned int len;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700750};
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700751
Edgardo Hames631c8de2010-03-08 17:02:37 -0800752static int usbctlx_rmem_completor_fn(struct usbctlx_completor *head)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700753{
Sherif Shehab Aldina03742a2014-04-05 23:33:45 +0200754 struct usbctlx_rmem_completor *complete =
755 (struct usbctlx_rmem_completor *)head;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700756
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +0100757 pr_debug("rmemresp:len=%d\n", complete->rmemresp->frmlen);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700758 memcpy(complete->data, complete->rmemresp->data, complete->len);
759 return 0;
760}
761
Edgardo Hames631c8de2010-03-08 17:02:37 -0800762static inline struct usbctlx_completor *init_rmem_completor(
Sherif Shehab Aldina03742a2014-04-05 23:33:45 +0200763 struct usbctlx_rmem_completor
Edgardo Hames631c8de2010-03-08 17:02:37 -0800764 *completor,
Sergio Paracuellos1ed54802016-09-28 20:19:34 +0200765 struct hfa384x_usb_rmemresp
Edgardo Hames631c8de2010-03-08 17:02:37 -0800766 *rmemresp,
767 void *data,
768 unsigned int len)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700769{
770 completor->head.complete = usbctlx_rmem_completor_fn;
771 completor->rmemresp = rmemresp;
772 completor->data = data;
773 completor->len = len;
774 return &(completor->head);
775}
776
777/*----------------------------------------------------------------
778* hfa384x_cb_status
779*
780* Ctlx_complete handler for async CMD type control exchanges.
781* mark the hw struct as such.
782*
783* Note: If the handling is changed here, it should probably be
784* changed in docmd as well.
785*
786* Arguments:
787* hw hw struct
788* ctlx completed CTLX
789*
790* Returns:
791* nothing
792*
793* Side effects:
794*
795* Call context:
796* interrupt
797----------------------------------------------------------------*/
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +0200798static void hfa384x_cb_status(struct hfa384x *hw, const struct hfa384x_usbctlx *ctlx)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700799{
Nicholas Sim02e02042016-04-05 17:37:12 +0100800 if (ctlx->usercb) {
Sergio Paracuellos501f5f92016-09-28 20:20:14 +0200801 struct hfa384x_cmdresult cmdresult;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700802
803 if (ctlx->state != CTLX_COMPLETE) {
804 memset(&cmdresult, 0, sizeof(cmdresult));
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100805 cmdresult.status =
806 HFA384x_STATUS_RESULT_SET(HFA384x_CMD_ERR);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700807 } else {
808 usbctlx_get_status(&ctlx->inbuf.cmdresp, &cmdresult);
809 }
810
811 ctlx->usercb(hw, &cmdresult, ctlx->usercb_data);
812 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700813}
814
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +0200815static inline int hfa384x_docmd_wait(struct hfa384x *hw, struct hfa384x_metacmd *cmd)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700816{
817 return hfa384x_docmd(hw, DOWAIT, cmd, NULL, NULL, NULL);
818}
819
820static inline int
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +0200821hfa384x_docmd_async(struct hfa384x *hw,
Sergio Paracuellose2f503c2016-09-28 20:20:18 +0200822 struct hfa384x_metacmd *cmd,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100823 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700824{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100825 return hfa384x_docmd(hw, DOASYNC, cmd, cmdcb, usercb, usercb_data);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700826}
827
828static inline int
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +0200829hfa384x_dorrid_wait(struct hfa384x *hw, u16 rid, void *riddata,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100830 unsigned int riddatalen)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700831{
832 return hfa384x_dorrid(hw, DOWAIT,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100833 rid, riddata, riddatalen, NULL, NULL, NULL);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700834}
835
836static inline int
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +0200837hfa384x_dorrid_async(struct hfa384x *hw,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100838 u16 rid, void *riddata, unsigned int riddatalen,
839 ctlx_cmdcb_t cmdcb,
840 ctlx_usercb_t usercb, void *usercb_data)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700841{
842 return hfa384x_dorrid(hw, DOASYNC,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100843 rid, riddata, riddatalen,
844 cmdcb, usercb, usercb_data);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700845}
846
847static inline int
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +0200848hfa384x_dowrid_wait(struct hfa384x *hw, u16 rid, void *riddata,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100849 unsigned int riddatalen)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700850{
851 return hfa384x_dowrid(hw, DOWAIT,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100852 rid, riddata, riddatalen, NULL, NULL, NULL);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700853}
854
855static inline int
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +0200856hfa384x_dowrid_async(struct hfa384x *hw,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100857 u16 rid, void *riddata, unsigned int riddatalen,
858 ctlx_cmdcb_t cmdcb,
859 ctlx_usercb_t usercb, void *usercb_data)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700860{
861 return hfa384x_dowrid(hw, DOASYNC,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100862 rid, riddata, riddatalen,
863 cmdcb, usercb, usercb_data);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700864}
865
866static inline int
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +0200867hfa384x_dormem_wait(struct hfa384x *hw,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100868 u16 page, u16 offset, void *data, unsigned int len)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700869{
870 return hfa384x_dormem(hw, DOWAIT,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100871 page, offset, data, len, NULL, NULL, NULL);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700872}
873
874static inline int
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +0200875hfa384x_dormem_async(struct hfa384x *hw,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100876 u16 page, u16 offset, void *data, unsigned int len,
877 ctlx_cmdcb_t cmdcb,
878 ctlx_usercb_t usercb, void *usercb_data)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700879{
880 return hfa384x_dormem(hw, DOASYNC,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100881 page, offset, data, len,
882 cmdcb, usercb, usercb_data);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700883}
884
885static inline int
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +0200886hfa384x_dowmem_wait(struct hfa384x *hw,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100887 u16 page, u16 offset, void *data, unsigned int len)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700888{
889 return hfa384x_dowmem(hw, DOWAIT,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100890 page, offset, data, len, NULL, NULL, NULL);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700891}
892
893static inline int
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +0200894hfa384x_dowmem_async(struct hfa384x *hw,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100895 u16 page,
896 u16 offset,
897 void *data,
898 unsigned int len,
899 ctlx_cmdcb_t cmdcb,
900 ctlx_usercb_t usercb, void *usercb_data)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700901{
902 return hfa384x_dowmem(hw, DOASYNC,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100903 page, offset, data, len,
904 cmdcb, usercb, usercb_data);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700905}
906
907/*----------------------------------------------------------------
908* hfa384x_cmd_initialize
909*
910* Issues the initialize command and sets the hw->state based
911* on the result.
912*
913* Arguments:
914* hw device structure
915*
916* Returns:
917* 0 success
918* >0 f/w reported error - f/w status code
919* <0 driver reported error
920*
921* Side effects:
922*
923* Call context:
924* process
925----------------------------------------------------------------*/
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +0200926int hfa384x_cmd_initialize(struct hfa384x *hw)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700927{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100928 int result = 0;
929 int i;
Sergio Paracuellose2f503c2016-09-28 20:20:18 +0200930 struct hfa384x_metacmd cmd;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700931
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700932 cmd.cmd = HFA384x_CMDCODE_INIT;
933 cmd.parm0 = 0;
934 cmd.parm1 = 0;
935 cmd.parm2 = 0;
936
937 result = hfa384x_docmd_wait(hw, &cmd);
938
Sherif Shehab Aldina2120132014-04-05 23:33:16 +0200939 pr_debug("cmdresp.init: status=0x%04x, resp0=0x%04x, resp1=0x%04x, resp2=0x%04x\n",
Mithlesh Thukral75f49e02009-05-25 19:06:16 +0530940 cmd.result.status,
941 cmd.result.resp0, cmd.result.resp1, cmd.result.resp2);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100942 if (result == 0) {
943 for (i = 0; i < HFA384x_NUMPORTS_MAX; i++)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700944 hw->port_enabled[i] = 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700945 }
946
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100947 hw->link_status = HFA384x_LINK_NOTCONNECTED;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700948
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700949 return result;
950}
951
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700952/*----------------------------------------------------------------
953* hfa384x_cmd_disable
954*
955* Issues the disable command to stop communications on one of
956* the MACs 'ports'.
957*
958* Arguments:
959* hw device structure
960* macport MAC port number (host order)
961*
962* Returns:
963* 0 success
964* >0 f/w reported failure - f/w status code
965* <0 driver reported error (timeout|bad arg)
966*
967* Side effects:
968*
969* Call context:
970* process
971----------------------------------------------------------------*/
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +0200972int hfa384x_cmd_disable(struct hfa384x *hw, u16 macport)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700973{
Sergio Paracuellose2f503c2016-09-28 20:20:18 +0200974 struct hfa384x_metacmd cmd;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700975
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700976 cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_DISABLE) |
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +0100977 HFA384x_CMD_MACPORT_SET(macport);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700978 cmd.parm0 = 0;
979 cmd.parm1 = 0;
980 cmd.parm2 = 0;
981
Bhumika Goyalca026a32016-02-09 01:28:10 +0530982 return hfa384x_docmd_wait(hw, &cmd);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700983}
984
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -0700985/*----------------------------------------------------------------
986* hfa384x_cmd_enable
987*
988* Issues the enable command to enable communications on one of
989* the MACs 'ports'.
990*
991* Arguments:
992* hw device structure
993* macport MAC port number
994*
995* Returns:
996* 0 success
997* >0 f/w reported failure - f/w status code
998* <0 driver reported error (timeout|bad arg)
999*
1000* Side effects:
1001*
1002* Call context:
1003* process
1004----------------------------------------------------------------*/
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02001005int hfa384x_cmd_enable(struct hfa384x *hw, u16 macport)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001006{
Sergio Paracuellose2f503c2016-09-28 20:20:18 +02001007 struct hfa384x_metacmd cmd;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001008
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001009 cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_ENABLE) |
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001010 HFA384x_CMD_MACPORT_SET(macport);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001011 cmd.parm0 = 0;
1012 cmd.parm1 = 0;
1013 cmd.parm2 = 0;
1014
Bhumika Goyalca026a32016-02-09 01:28:10 +05301015 return hfa384x_docmd_wait(hw, &cmd);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001016}
1017
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001018/*----------------------------------------------------------------
1019* hfa384x_cmd_monitor
1020*
1021* Enables the 'monitor mode' of the MAC. Here's the description of
1022* monitor mode that I've received thus far:
1023*
1024* "The "monitor mode" of operation is that the MAC passes all
1025* frames for which the PLCP checks are correct. All received
1026* MPDUs are passed to the host with MAC Port = 7, with a
1027* receive status of good, FCS error, or undecryptable. Passing
1028* certain MPDUs is a violation of the 802.11 standard, but useful
1029* for a debugging tool." Normal communication is not possible
1030* while monitor mode is enabled.
1031*
1032* Arguments:
1033* hw device structure
1034* enable a code (0x0b|0x0f) that enables/disables
1035* monitor mode. (host order)
1036*
1037* Returns:
1038* 0 success
1039* >0 f/w reported failure - f/w status code
1040* <0 driver reported error (timeout|bad arg)
1041*
1042* Side effects:
1043*
1044* Call context:
1045* process
1046----------------------------------------------------------------*/
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02001047int hfa384x_cmd_monitor(struct hfa384x *hw, u16 enable)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001048{
Sergio Paracuellose2f503c2016-09-28 20:20:18 +02001049 struct hfa384x_metacmd cmd;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001050
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001051 cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_MONITOR) |
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001052 HFA384x_CMD_AINFO_SET(enable);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001053 cmd.parm0 = 0;
1054 cmd.parm1 = 0;
1055 cmd.parm2 = 0;
1056
Bhumika Goyalca026a32016-02-09 01:28:10 +05301057 return hfa384x_docmd_wait(hw, &cmd);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001058}
1059
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001060/*----------------------------------------------------------------
1061* hfa384x_cmd_download
1062*
1063* Sets the controls for the MAC controller code/data download
1064* process. The arguments set the mode and address associated
1065* with a download. Note that the aux registers should be enabled
1066* prior to setting one of the download enable modes.
1067*
1068* Arguments:
1069* hw device structure
1070* mode 0 - Disable programming and begin code exec
1071* 1 - Enable volatile mem programming
1072* 2 - Enable non-volatile mem programming
1073* 3 - Program non-volatile section from NV download
1074* buffer.
1075* (host order)
1076* lowaddr
1077* highaddr For mode 1, sets the high & low order bits of
1078* the "destination address". This address will be
1079* the execution start address when download is
1080* subsequently disabled.
1081* For mode 2, sets the high & low order bits of
1082* the destination in NV ram.
1083* For modes 0 & 3, should be zero. (host order)
1084* NOTE: these are CMD format.
1085* codelen Length of the data to write in mode 2,
1086* zero otherwise. (host order)
1087*
1088* Returns:
1089* 0 success
1090* >0 f/w reported failure - f/w status code
1091* <0 driver reported error (timeout|bad arg)
1092*
1093* Side effects:
1094*
1095* Call context:
1096* process
1097----------------------------------------------------------------*/
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02001098int hfa384x_cmd_download(struct hfa384x *hw, u16 mode, u16 lowaddr,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001099 u16 highaddr, u16 codelen)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001100{
Sergio Paracuellose2f503c2016-09-28 20:20:18 +02001101 struct hfa384x_metacmd cmd;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001102
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301103 pr_debug("mode=%d, lowaddr=0x%04x, highaddr=0x%04x, codelen=%d\n",
1104 mode, lowaddr, highaddr, codelen);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001105
1106 cmd.cmd = (HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_DOWNLD) |
1107 HFA384x_CMD_PROGMODE_SET(mode));
1108
1109 cmd.parm0 = lowaddr;
1110 cmd.parm1 = highaddr;
1111 cmd.parm2 = codelen;
1112
Bhumika Goyalca026a32016-02-09 01:28:10 +05301113 return hfa384x_docmd_wait(hw, &cmd);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001114}
1115
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001116/*----------------------------------------------------------------
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001117* hfa384x_corereset
1118*
1119* Perform a reset of the hfa38xx MAC core. We assume that the hw
1120* structure is in its "created" state. That is, it is initialized
1121* with proper values. Note that if a reset is done after the
1122* device has been active for awhile, the caller might have to clean
1123* up some leftover cruft in the hw structure.
1124*
1125* Arguments:
1126* hw device structure
1127* holdtime how long (in ms) to hold the reset
1128* settletime how long (in ms) to wait after releasing
1129* the reset
1130*
1131* Returns:
1132* nothing
1133*
1134* Side effects:
1135*
1136* Call context:
1137* process
1138----------------------------------------------------------------*/
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02001139int hfa384x_corereset(struct hfa384x *hw, int holdtime, int settletime, int genesis)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001140{
Amitoj Kaur Chawladf18b932015-10-15 01:42:11 +05301141 int result;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001142
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001143 result = usb_reset_device(hw->usb);
1144 if (result < 0) {
Avinash Kumar263b8bb2013-09-06 22:21:49 +05301145 netdev_err(hw->wlandev->netdev, "usb_reset_device() failed, result=%d.\n",
Sherif Shehab Aldin3f2d6562014-04-05 23:34:40 +02001146 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001147 }
1148
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001149 return result;
1150}
1151
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001152/*----------------------------------------------------------------
1153* hfa384x_usbctlx_complete_sync
1154*
1155* Waits for a synchronous CTLX object to complete,
1156* and then handles the response.
1157*
1158* Arguments:
1159* hw device structure
Edgardo Hames631c8de2010-03-08 17:02:37 -08001160* ctlx CTLX ptr
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001161* completor functor object to decide what to
1162* do with the CTLX's result.
1163*
1164* Returns:
1165* 0 Success
1166* -ERESTARTSYS Interrupted by a signal
1167* -EIO CTLX failed
1168* -ENODEV Adapter was unplugged
1169* ??? Result from completor
1170*
1171* Side effects:
1172*
1173* Call context:
1174* process
1175----------------------------------------------------------------*/
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02001176static int hfa384x_usbctlx_complete_sync(struct hfa384x *hw,
Sergio Paracuellosa10d36b2016-09-28 20:20:16 +02001177 struct hfa384x_usbctlx *ctlx,
Edgardo Hames631c8de2010-03-08 17:02:37 -08001178 struct usbctlx_completor *completor)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001179{
1180 unsigned long flags;
1181 int result;
1182
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001183 result = wait_for_completion_interruptible(&ctlx->done);
1184
1185 spin_lock_irqsave(&hw->ctlxq.lock, flags);
1186
1187 /*
1188 * We can only handle the CTLX if the USB disconnect
1189 * function has not run yet ...
1190 */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001191cleanup:
1192 if (hw->wlandev->hwremoved) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001193 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1194 result = -ENODEV;
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001195 } else if (result != 0) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001196 int runqueue = 0;
1197
1198 /*
1199 * We were probably interrupted, so delete
1200 * this CTLX asynchronously, kill the timers
1201 * and the URB, and then start the next
1202 * pending CTLX.
1203 *
1204 * NOTE: We can only delete the timers and
1205 * the URB if this CTLX is active.
1206 */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001207 if (ctlx == get_active_ctlx(hw)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001208 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1209
1210 del_singleshot_timer_sync(&hw->reqtimer);
1211 del_singleshot_timer_sync(&hw->resptimer);
1212 hw->req_timer_done = 1;
1213 hw->resp_timer_done = 1;
1214 usb_kill_urb(&hw->ctlx_urb);
1215
1216 spin_lock_irqsave(&hw->ctlxq.lock, flags);
1217
1218 runqueue = 1;
1219
1220 /*
1221 * This scenario is so unlikely that I'm
1222 * happy with a grubby "goto" solution ...
1223 */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001224 if (hw->wlandev->hwremoved)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001225 goto cleanup;
1226 }
1227
1228 /*
1229 * The completion task will send this CTLX
1230 * to the reaper the next time it runs. We
1231 * are no longer in a hurry.
1232 */
1233 ctlx->reapable = 1;
1234 ctlx->state = CTLX_REQ_FAILED;
1235 list_move_tail(&ctlx->list, &hw->ctlxq.completing);
1236
1237 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1238
1239 if (runqueue)
1240 hfa384x_usbctlxq_run(hw);
1241 } else {
1242 if (ctlx->state == CTLX_COMPLETE) {
1243 result = completor->complete(completor);
1244 } else {
Avinash Kumar263b8bb2013-09-06 22:21:49 +05301245 netdev_warn(hw->wlandev->netdev, "CTLX[%d] error: state(%s)\n",
Sherif Shehab Aldin3f2d6562014-04-05 23:34:40 +02001246 le16_to_cpu(ctlx->outbuf.type),
1247 ctlxstr(ctlx->state));
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001248 result = -EIO;
1249 }
1250
1251 list_del(&ctlx->list);
1252 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
1253 kfree(ctlx);
1254 }
1255
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001256 return result;
1257}
1258
1259/*----------------------------------------------------------------
1260* hfa384x_docmd
1261*
1262* Constructs a command CTLX and submits it.
1263*
1264* NOTE: Any changes to the 'post-submit' code in this function
1265* need to be carried over to hfa384x_cbcmd() since the handling
1266* is virtually identical.
1267*
1268* Arguments:
1269* hw device structure
1270* mode DOWAIT or DOASYNC
1271* cmd cmd structure. Includes all arguments and result
1272* data points. All in host order. in host order
1273* cmdcb command-specific callback
1274* usercb user callback for async calls, NULL for DOWAIT calls
1275* usercb_data user supplied data pointer for async calls, NULL
1276* for DOASYNC calls
1277*
1278* Returns:
1279* 0 success
1280* -EIO CTLX failure
1281* -ERESTARTSYS Awakened on signal
1282* >0 command indicated error, Status and Resp0-2 are
1283* in hw structure.
1284*
1285* Side effects:
1286*
1287*
1288* Call context:
1289* process
1290----------------------------------------------------------------*/
1291static int
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02001292hfa384x_docmd(struct hfa384x *hw,
Edgardo Hames631c8de2010-03-08 17:02:37 -08001293 enum cmd_mode mode,
Sergio Paracuellose2f503c2016-09-28 20:20:18 +02001294 struct hfa384x_metacmd *cmd,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001295 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001296{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001297 int result;
Sergio Paracuellosa10d36b2016-09-28 20:20:16 +02001298 struct hfa384x_usbctlx *ctlx;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001299
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001300 ctlx = usbctlx_alloc();
Eva Rachel Retuyae2e77522016-02-27 20:39:25 +08001301 if (!ctlx) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001302 result = -ENOMEM;
1303 goto done;
1304 }
1305
1306 /* Initialize the command */
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01001307 ctlx->outbuf.cmdreq.type = cpu_to_le16(HFA384x_USB_CMDREQ);
1308 ctlx->outbuf.cmdreq.cmd = cpu_to_le16(cmd->cmd);
1309 ctlx->outbuf.cmdreq.parm0 = cpu_to_le16(cmd->parm0);
1310 ctlx->outbuf.cmdreq.parm1 = cpu_to_le16(cmd->parm1);
1311 ctlx->outbuf.cmdreq.parm2 = cpu_to_le16(cmd->parm2);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001312
1313 ctlx->outbufsize = sizeof(ctlx->outbuf.cmdreq);
1314
Sherif Shehab Aldina2120132014-04-05 23:33:16 +02001315 pr_debug("cmdreq: cmd=0x%04x parm0=0x%04x parm1=0x%04x parm2=0x%04x\n",
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301316 cmd->cmd, cmd->parm0, cmd->parm1, cmd->parm2);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001317
1318 ctlx->reapable = mode;
1319 ctlx->cmdcb = cmdcb;
1320 ctlx->usercb = usercb;
1321 ctlx->usercb_data = usercb_data;
1322
1323 result = hfa384x_usbctlx_submit(hw, ctlx);
1324 if (result != 0) {
1325 kfree(ctlx);
1326 } else if (mode == DOWAIT) {
Edgardo Hames631c8de2010-03-08 17:02:37 -08001327 struct usbctlx_cmd_completor completor;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001328
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001329 result =
1330 hfa384x_usbctlx_complete_sync(hw, ctlx,
1331 init_cmd_completor(&completor,
1332 &ctlx->
1333 inbuf.
1334 cmdresp,
1335 &cmd->
1336 result));
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001337 }
1338
1339done:
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001340 return result;
1341}
1342
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001343/*----------------------------------------------------------------
1344* hfa384x_dorrid
1345*
1346* Constructs a read rid CTLX and issues it.
1347*
1348* NOTE: Any changes to the 'post-submit' code in this function
1349* need to be carried over to hfa384x_cbrrid() since the handling
1350* is virtually identical.
1351*
1352* Arguments:
1353* hw device structure
1354* mode DOWAIT or DOASYNC
1355* rid Read RID number (host order)
1356* riddata Caller supplied buffer that MAC formatted RID.data
1357* record will be written to for DOWAIT calls. Should
1358* be NULL for DOASYNC calls.
1359* riddatalen Buffer length for DOWAIT calls. Zero for DOASYNC calls.
1360* cmdcb command callback for async calls, NULL for DOWAIT calls
1361* usercb user callback for async calls, NULL for DOWAIT calls
1362* usercb_data user supplied data pointer for async calls, NULL
1363* for DOWAIT calls
1364*
1365* Returns:
1366* 0 success
1367* -EIO CTLX failure
1368* -ERESTARTSYS Awakened on signal
1369* -ENODATA riddatalen != macdatalen
1370* >0 command indicated error, Status and Resp0-2 are
1371* in hw structure.
1372*
1373* Side effects:
1374*
1375* Call context:
1376* interrupt (DOASYNC)
1377* process (DOWAIT or DOASYNC)
1378----------------------------------------------------------------*/
1379static int
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02001380hfa384x_dorrid(struct hfa384x *hw,
Edgardo Hames631c8de2010-03-08 17:02:37 -08001381 enum cmd_mode mode,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001382 u16 rid,
1383 void *riddata,
1384 unsigned int riddatalen,
1385 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001386{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001387 int result;
Sergio Paracuellosa10d36b2016-09-28 20:20:16 +02001388 struct hfa384x_usbctlx *ctlx;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001389
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001390 ctlx = usbctlx_alloc();
Eva Rachel Retuyae2e77522016-02-27 20:39:25 +08001391 if (!ctlx) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001392 result = -ENOMEM;
1393 goto done;
1394 }
1395
1396 /* Initialize the command */
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01001397 ctlx->outbuf.rridreq.type = cpu_to_le16(HFA384x_USB_RRIDREQ);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001398 ctlx->outbuf.rridreq.frmlen =
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01001399 cpu_to_le16(sizeof(ctlx->outbuf.rridreq.rid));
1400 ctlx->outbuf.rridreq.rid = cpu_to_le16(rid);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001401
1402 ctlx->outbufsize = sizeof(ctlx->outbuf.rridreq);
1403
1404 ctlx->reapable = mode;
1405 ctlx->cmdcb = cmdcb;
1406 ctlx->usercb = usercb;
1407 ctlx->usercb_data = usercb_data;
1408
1409 /* Submit the CTLX */
1410 result = hfa384x_usbctlx_submit(hw, ctlx);
1411 if (result != 0) {
1412 kfree(ctlx);
1413 } else if (mode == DOWAIT) {
Edgardo Hames631c8de2010-03-08 17:02:37 -08001414 struct usbctlx_rrid_completor completor;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001415
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001416 result =
1417 hfa384x_usbctlx_complete_sync(hw, ctlx,
1418 init_rrid_completor
1419 (&completor,
1420 &ctlx->inbuf.rridresp,
1421 riddata, riddatalen));
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001422 }
1423
1424done:
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001425 return result;
1426}
1427
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001428/*----------------------------------------------------------------
1429* hfa384x_dowrid
1430*
1431* Constructs a write rid CTLX and issues it.
1432*
1433* NOTE: Any changes to the 'post-submit' code in this function
1434* need to be carried over to hfa384x_cbwrid() since the handling
1435* is virtually identical.
1436*
1437* Arguments:
1438* hw device structure
Edgardo Hames631c8de2010-03-08 17:02:37 -08001439* enum cmd_mode DOWAIT or DOASYNC
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001440* rid RID code
1441* riddata Data portion of RID formatted for MAC
1442* riddatalen Length of the data portion in bytes
1443* cmdcb command callback for async calls, NULL for DOWAIT calls
1444* usercb user callback for async calls, NULL for DOWAIT calls
1445* usercb_data user supplied data pointer for async calls
1446*
1447* Returns:
1448* 0 success
1449* -ETIMEDOUT timed out waiting for register ready or
1450* command completion
1451* >0 command indicated error, Status and Resp0-2 are
1452* in hw structure.
1453*
1454* Side effects:
1455*
1456* Call context:
1457* interrupt (DOASYNC)
1458* process (DOWAIT or DOASYNC)
1459----------------------------------------------------------------*/
1460static int
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02001461hfa384x_dowrid(struct hfa384x *hw,
Edgardo Hames631c8de2010-03-08 17:02:37 -08001462 enum cmd_mode mode,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001463 u16 rid,
1464 void *riddata,
1465 unsigned int riddatalen,
1466 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001467{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001468 int result;
Sergio Paracuellosa10d36b2016-09-28 20:20:16 +02001469 struct hfa384x_usbctlx *ctlx;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001470
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001471 ctlx = usbctlx_alloc();
Eva Rachel Retuyae2e77522016-02-27 20:39:25 +08001472 if (!ctlx) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001473 result = -ENOMEM;
1474 goto done;
1475 }
1476
1477 /* Initialize the command */
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01001478 ctlx->outbuf.wridreq.type = cpu_to_le16(HFA384x_USB_WRIDREQ);
1479 ctlx->outbuf.wridreq.frmlen = cpu_to_le16((sizeof
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301480 (ctlx->outbuf.wridreq.rid) +
1481 riddatalen + 1) / 2);
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01001482 ctlx->outbuf.wridreq.rid = cpu_to_le16(rid);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001483 memcpy(ctlx->outbuf.wridreq.data, riddata, riddatalen);
1484
1485 ctlx->outbufsize = sizeof(ctlx->outbuf.wridreq.type) +
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001486 sizeof(ctlx->outbuf.wridreq.frmlen) +
1487 sizeof(ctlx->outbuf.wridreq.rid) + riddatalen;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001488
1489 ctlx->reapable = mode;
1490 ctlx->cmdcb = cmdcb;
1491 ctlx->usercb = usercb;
1492 ctlx->usercb_data = usercb_data;
1493
1494 /* Submit the CTLX */
1495 result = hfa384x_usbctlx_submit(hw, ctlx);
1496 if (result != 0) {
1497 kfree(ctlx);
1498 } else if (mode == DOWAIT) {
Sherif Shehab Aldina03742a2014-04-05 23:33:45 +02001499 struct usbctlx_cmd_completor completor;
Sergio Paracuellos501f5f92016-09-28 20:20:14 +02001500 struct hfa384x_cmdresult wridresult;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001501
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001502 result = hfa384x_usbctlx_complete_sync(hw,
1503 ctlx,
1504 init_wrid_completor
1505 (&completor,
1506 &ctlx->inbuf.wridresp,
1507 &wridresult));
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001508 }
1509
1510done:
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001511 return result;
1512}
1513
1514/*----------------------------------------------------------------
1515* hfa384x_dormem
1516*
1517* Constructs a readmem CTLX and issues it.
1518*
1519* NOTE: Any changes to the 'post-submit' code in this function
1520* need to be carried over to hfa384x_cbrmem() since the handling
1521* is virtually identical.
1522*
1523* Arguments:
1524* hw device structure
1525* mode DOWAIT or DOASYNC
1526* page MAC address space page (CMD format)
1527* offset MAC address space offset
1528* data Ptr to data buffer to receive read
1529* len Length of the data to read (max == 2048)
1530* cmdcb command callback for async calls, NULL for DOWAIT calls
1531* usercb user callback for async calls, NULL for DOWAIT calls
1532* usercb_data user supplied data pointer for async calls
1533*
1534* Returns:
1535* 0 success
1536* -ETIMEDOUT timed out waiting for register ready or
1537* command completion
1538* >0 command indicated error, Status and Resp0-2 are
1539* in hw structure.
1540*
1541* Side effects:
1542*
1543* Call context:
1544* interrupt (DOASYNC)
1545* process (DOWAIT or DOASYNC)
1546----------------------------------------------------------------*/
1547static int
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02001548hfa384x_dormem(struct hfa384x *hw,
Edgardo Hames631c8de2010-03-08 17:02:37 -08001549 enum cmd_mode mode,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001550 u16 page,
1551 u16 offset,
1552 void *data,
1553 unsigned int len,
1554 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001555{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001556 int result;
Sergio Paracuellosa10d36b2016-09-28 20:20:16 +02001557 struct hfa384x_usbctlx *ctlx;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001558
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001559 ctlx = usbctlx_alloc();
Eva Rachel Retuyae2e77522016-02-27 20:39:25 +08001560 if (!ctlx) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001561 result = -ENOMEM;
1562 goto done;
1563 }
1564
1565 /* Initialize the command */
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01001566 ctlx->outbuf.rmemreq.type = cpu_to_le16(HFA384x_USB_RMEMREQ);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001567 ctlx->outbuf.rmemreq.frmlen =
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01001568 cpu_to_le16(sizeof(ctlx->outbuf.rmemreq.offset) +
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301569 sizeof(ctlx->outbuf.rmemreq.page) + len);
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01001570 ctlx->outbuf.rmemreq.offset = cpu_to_le16(offset);
1571 ctlx->outbuf.rmemreq.page = cpu_to_le16(page);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001572
1573 ctlx->outbufsize = sizeof(ctlx->outbuf.rmemreq);
1574
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301575 pr_debug("type=0x%04x frmlen=%d offset=0x%04x page=0x%04x\n",
1576 ctlx->outbuf.rmemreq.type,
1577 ctlx->outbuf.rmemreq.frmlen,
1578 ctlx->outbuf.rmemreq.offset, ctlx->outbuf.rmemreq.page);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001579
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301580 pr_debug("pktsize=%zd\n", ROUNDUP64(sizeof(ctlx->outbuf.rmemreq)));
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001581
1582 ctlx->reapable = mode;
1583 ctlx->cmdcb = cmdcb;
1584 ctlx->usercb = usercb;
1585 ctlx->usercb_data = usercb_data;
1586
1587 result = hfa384x_usbctlx_submit(hw, ctlx);
1588 if (result != 0) {
1589 kfree(ctlx);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001590 } else if (mode == DOWAIT) {
Sherif Shehab Aldina03742a2014-04-05 23:33:45 +02001591 struct usbctlx_rmem_completor completor;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001592
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001593 result =
1594 hfa384x_usbctlx_complete_sync(hw, ctlx,
1595 init_rmem_completor
1596 (&completor,
1597 &ctlx->inbuf.rmemresp, data,
1598 len));
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001599 }
1600
1601done:
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001602 return result;
1603}
1604
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001605/*----------------------------------------------------------------
1606* hfa384x_dowmem
1607*
1608* Constructs a writemem CTLX and issues it.
1609*
1610* NOTE: Any changes to the 'post-submit' code in this function
1611* need to be carried over to hfa384x_cbwmem() since the handling
1612* is virtually identical.
1613*
1614* Arguments:
1615* hw device structure
1616* mode DOWAIT or DOASYNC
1617* page MAC address space page (CMD format)
1618* offset MAC address space offset
1619* data Ptr to data buffer containing write data
1620* len Length of the data to read (max == 2048)
1621* cmdcb command callback for async calls, NULL for DOWAIT calls
1622* usercb user callback for async calls, NULL for DOWAIT calls
1623* usercb_data user supplied data pointer for async calls.
1624*
1625* Returns:
1626* 0 success
1627* -ETIMEDOUT timed out waiting for register ready or
1628* command completion
1629* >0 command indicated error, Status and Resp0-2 are
1630* in hw structure.
1631*
1632* Side effects:
1633*
1634* Call context:
1635* interrupt (DOWAIT)
1636* process (DOWAIT or DOASYNC)
1637----------------------------------------------------------------*/
1638static int
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02001639hfa384x_dowmem(struct hfa384x *hw,
Edgardo Hames631c8de2010-03-08 17:02:37 -08001640 enum cmd_mode mode,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001641 u16 page,
1642 u16 offset,
1643 void *data,
1644 unsigned int len,
1645 ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001646{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001647 int result;
Sergio Paracuellosa10d36b2016-09-28 20:20:16 +02001648 struct hfa384x_usbctlx *ctlx;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001649
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301650 pr_debug("page=0x%04x offset=0x%04x len=%d\n", page, offset, len);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001651
1652 ctlx = usbctlx_alloc();
Eva Rachel Retuyae2e77522016-02-27 20:39:25 +08001653 if (!ctlx) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001654 result = -ENOMEM;
1655 goto done;
1656 }
1657
1658 /* Initialize the command */
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01001659 ctlx->outbuf.wmemreq.type = cpu_to_le16(HFA384x_USB_WMEMREQ);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001660 ctlx->outbuf.wmemreq.frmlen =
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01001661 cpu_to_le16(sizeof(ctlx->outbuf.wmemreq.offset) +
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301662 sizeof(ctlx->outbuf.wmemreq.page) + len);
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01001663 ctlx->outbuf.wmemreq.offset = cpu_to_le16(offset);
1664 ctlx->outbuf.wmemreq.page = cpu_to_le16(page);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001665 memcpy(ctlx->outbuf.wmemreq.data, data, len);
1666
1667 ctlx->outbufsize = sizeof(ctlx->outbuf.wmemreq.type) +
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001668 sizeof(ctlx->outbuf.wmemreq.frmlen) +
1669 sizeof(ctlx->outbuf.wmemreq.offset) +
1670 sizeof(ctlx->outbuf.wmemreq.page) + len;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001671
1672 ctlx->reapable = mode;
1673 ctlx->cmdcb = cmdcb;
1674 ctlx->usercb = usercb;
1675 ctlx->usercb_data = usercb_data;
1676
1677 result = hfa384x_usbctlx_submit(hw, ctlx);
1678 if (result != 0) {
1679 kfree(ctlx);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001680 } else if (mode == DOWAIT) {
Sherif Shehab Aldina03742a2014-04-05 23:33:45 +02001681 struct usbctlx_cmd_completor completor;
Sergio Paracuellos501f5f92016-09-28 20:20:14 +02001682 struct hfa384x_cmdresult wmemresult;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001683
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001684 result = hfa384x_usbctlx_complete_sync(hw,
1685 ctlx,
1686 init_wmem_completor
1687 (&completor,
1688 &ctlx->inbuf.wmemresp,
1689 &wmemresult));
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001690 }
1691
1692done:
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001693 return result;
1694}
1695
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001696/*----------------------------------------------------------------
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001697* hfa384x_drvr_disable
1698*
1699* Issues the disable command to stop communications on one of
1700* the MACs 'ports'. Only macport 0 is valid for stations.
1701* APs may also disable macports 1-6. Only ports that have been
1702* previously enabled may be disabled.
1703*
1704* Arguments:
1705* hw device structure
1706* macport MAC port number (host order)
1707*
1708* Returns:
1709* 0 success
1710* >0 f/w reported failure - f/w status code
1711* <0 driver reported error (timeout|bad arg)
1712*
1713* Side effects:
1714*
1715* Call context:
1716* process
1717----------------------------------------------------------------*/
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02001718int hfa384x_drvr_disable(struct hfa384x *hw, u16 macport)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001719{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001720 int result = 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001721
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001722 if ((!hw->isap && macport != 0) ||
1723 (hw->isap && !(macport <= HFA384x_PORTID_MAX)) ||
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001724 !(hw->port_enabled[macport])) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001725 result = -EINVAL;
1726 } else {
1727 result = hfa384x_cmd_disable(hw, macport);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001728 if (result == 0)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001729 hw->port_enabled[macport] = 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001730 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001731 return result;
1732}
1733
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001734/*----------------------------------------------------------------
1735* hfa384x_drvr_enable
1736*
1737* Issues the enable command to enable communications on one of
1738* the MACs 'ports'. Only macport 0 is valid for stations.
1739* APs may also enable macports 1-6. Only ports that are currently
1740* disabled may be enabled.
1741*
1742* Arguments:
1743* hw device structure
1744* macport MAC port number
1745*
1746* Returns:
1747* 0 success
1748* >0 f/w reported failure - f/w status code
1749* <0 driver reported error (timeout|bad arg)
1750*
1751* Side effects:
1752*
1753* Call context:
1754* process
1755----------------------------------------------------------------*/
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02001756int hfa384x_drvr_enable(struct hfa384x *hw, u16 macport)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001757{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001758 int result = 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001759
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001760 if ((!hw->isap && macport != 0) ||
1761 (hw->isap && !(macport <= HFA384x_PORTID_MAX)) ||
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001762 (hw->port_enabled[macport])) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001763 result = -EINVAL;
1764 } else {
1765 result = hfa384x_cmd_enable(hw, macport);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001766 if (result == 0)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001767 hw->port_enabled[macport] = 1;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001768 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001769 return result;
1770}
1771
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001772/*----------------------------------------------------------------
1773* hfa384x_drvr_flashdl_enable
1774*
1775* Begins the flash download state. Checks to see that we're not
1776* already in a download state and that a port isn't enabled.
1777* Sets the download state and retrieves the flash download
1778* buffer location, buffer size, and timeout length.
1779*
1780* Arguments:
1781* hw device structure
1782*
1783* Returns:
1784* 0 success
1785* >0 f/w reported error - f/w status code
1786* <0 driver reported error
1787*
1788* Side effects:
1789*
1790* Call context:
1791* process
1792----------------------------------------------------------------*/
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02001793int hfa384x_drvr_flashdl_enable(struct hfa384x *hw)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001794{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001795 int result = 0;
1796 int i;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001797
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001798 /* Check that a port isn't active */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001799 for (i = 0; i < HFA384x_PORTID_MAX; i++) {
1800 if (hw->port_enabled[i]) {
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +01001801 pr_debug("called when port enabled.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001802 return -EINVAL;
1803 }
1804 }
1805
1806 /* Check that we're not already in a download state */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001807 if (hw->dlstate != HFA384x_DLSTATE_DISABLED)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001808 return -EINVAL;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001809
1810 /* Retrieve the buffer loc&size and timeout */
Svenne Krap46800b22010-02-14 18:59:42 +01001811 result = hfa384x_drvr_getconfig(hw, HFA384x_RID_DOWNLOADBUFFER,
Andrew Elwell3f4b4e72010-02-18 23:56:13 +01001812 &(hw->bufinfo), sizeof(hw->bufinfo));
1813 if (result)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001814 return result;
Andrew Elwell3f4b4e72010-02-18 23:56:13 +01001815
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01001816 hw->bufinfo.page = le16_to_cpu(hw->bufinfo.page);
1817 hw->bufinfo.offset = le16_to_cpu(hw->bufinfo.offset);
1818 hw->bufinfo.len = le16_to_cpu(hw->bufinfo.len);
Svenne Krap46800b22010-02-14 18:59:42 +01001819 result = hfa384x_drvr_getconfig16(hw, HFA384x_RID_MAXLOADTIME,
Andrew Elwell3f4b4e72010-02-18 23:56:13 +01001820 &(hw->dltimeout));
1821 if (result)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001822 return result;
Andrew Elwell3f4b4e72010-02-18 23:56:13 +01001823
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01001824 hw->dltimeout = le16_to_cpu(hw->dltimeout);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001825
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +01001826 pr_debug("flashdl_enable\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001827
1828 hw->dlstate = HFA384x_DLSTATE_FLASHENABLED;
Moritz Muehlenhoff8a251b52009-01-21 22:00:44 +01001829
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001830 return result;
1831}
1832
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001833/*----------------------------------------------------------------
1834* hfa384x_drvr_flashdl_disable
1835*
1836* Ends the flash download state. Note that this will cause the MAC
1837* firmware to restart.
1838*
1839* Arguments:
1840* hw device structure
1841*
1842* Returns:
1843* 0 success
1844* >0 f/w reported error - f/w status code
1845* <0 driver reported error
1846*
1847* Side effects:
1848*
1849* Call context:
1850* process
1851----------------------------------------------------------------*/
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02001852int hfa384x_drvr_flashdl_disable(struct hfa384x *hw)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001853{
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001854 /* Check that we're already in the download state */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001855 if (hw->dlstate != HFA384x_DLSTATE_FLASHENABLED)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001856 return -EINVAL;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001857
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +01001858 pr_debug("flashdl_enable\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001859
1860 /* There isn't much we can do at this point, so I don't */
1861 /* bother w/ the return value */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001862 hfa384x_cmd_download(hw, HFA384x_PROGMODE_DISABLE, 0, 0, 0);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001863 hw->dlstate = HFA384x_DLSTATE_DISABLED;
1864
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001865 return 0;
1866}
1867
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001868/*----------------------------------------------------------------
1869* hfa384x_drvr_flashdl_write
1870*
1871* Performs a FLASH download of a chunk of data. First checks to see
1872* that we're in the FLASH download state, then sets the download
1873* mode, uses the aux functions to 1) copy the data to the flash
1874* buffer, 2) sets the download 'write flash' mode, 3) readback and
1875* compare. Lather rinse, repeat as many times an necessary to get
1876* all the given data into flash.
1877* When all data has been written using this function (possibly
1878* repeatedly), call drvr_flashdl_disable() to end the download state
1879* and restart the MAC.
1880*
1881* Arguments:
1882* hw device structure
1883* daddr Card address to write to. (host order)
1884* buf Ptr to data to write.
1885* len Length of data (host order).
1886*
1887* Returns:
1888* 0 success
1889* >0 f/w reported error - f/w status code
1890* <0 driver reported error
1891*
1892* Side effects:
1893*
1894* Call context:
1895* process
1896----------------------------------------------------------------*/
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02001897int hfa384x_drvr_flashdl_write(struct hfa384x *hw, u32 daddr, void *buf, u32 len)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001898{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001899 int result = 0;
1900 u32 dlbufaddr;
1901 int nburns;
1902 u32 burnlen;
1903 u32 burndaddr;
1904 u16 burnlo;
1905 u16 burnhi;
1906 int nwrites;
1907 u8 *writebuf;
1908 u16 writepage;
1909 u16 writeoffset;
1910 u32 writelen;
1911 int i;
1912 int j;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001913
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +01001914 pr_debug("daddr=0x%08x len=%d\n", daddr, len);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001915
1916 /* Check that we're in the flash download state */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001917 if (hw->dlstate != HFA384x_DLSTATE_FLASHENABLED)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001918 return -EINVAL;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001919
Sherif Shehab Aldina2120132014-04-05 23:33:16 +02001920 netdev_info(hw->wlandev->netdev,
1921 "Download %d bytes to flash @0x%06x\n", len, daddr);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001922
1923 /* Convert to flat address for arithmetic */
1924 /* NOTE: dlbuffer RID stores the address in AUX format */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001925 dlbufaddr =
1926 HFA384x_ADDR_AUX_MKFLAT(hw->bufinfo.page, hw->bufinfo.offset);
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05301927 pr_debug("dlbuf.page=0x%04x dlbuf.offset=0x%04x dlbufaddr=0x%08x\n",
1928 hw->bufinfo.page, hw->bufinfo.offset, dlbufaddr);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001929 /* Calculations to determine how many fills of the dlbuffer to do
1930 * and how many USB wmemreq's to do for each fill. At this point
1931 * in time, the dlbuffer size and the wmemreq size are the same.
1932 * Therefore, nwrites should always be 1. The extra complexity
1933 * here is a hedge against future changes.
1934 */
1935
1936 /* Figure out how many times to do the flash programming */
1937 nburns = len / hw->bufinfo.len;
1938 nburns += (len % hw->bufinfo.len) ? 1 : 0;
1939
1940 /* For each flash program cycle, how many USB wmemreq's are needed? */
1941 nwrites = hw->bufinfo.len / HFA384x_USB_RWMEM_MAXLEN;
1942 nwrites += (hw->bufinfo.len % HFA384x_USB_RWMEM_MAXLEN) ? 1 : 0;
1943
1944 /* For each burn */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001945 for (i = 0; i < nburns; i++) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001946 /* Get the dest address and len */
1947 burnlen = (len - (hw->bufinfo.len * i)) > hw->bufinfo.len ?
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001948 hw->bufinfo.len : (len - (hw->bufinfo.len * i));
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001949 burndaddr = daddr + (hw->bufinfo.len * i);
1950 burnlo = HFA384x_ADDR_CMD_MKOFF(burndaddr);
1951 burnhi = HFA384x_ADDR_CMD_MKPAGE(burndaddr);
1952
Avinash Kumar263b8bb2013-09-06 22:21:49 +05301953 netdev_info(hw->wlandev->netdev, "Writing %d bytes to flash @0x%06x\n",
Sherif Shehab Aldin3f2d6562014-04-05 23:34:40 +02001954 burnlen, burndaddr);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001955
1956 /* Set the download mode */
1957 result = hfa384x_cmd_download(hw, HFA384x_PROGMODE_NV,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001958 burnlo, burnhi, burnlen);
1959 if (result) {
Sherif Shehab Aldina2120132014-04-05 23:33:16 +02001960 netdev_err(hw->wlandev->netdev,
1961 "download(NV,lo=%x,hi=%x,len=%x) cmd failed, result=%d. Aborting d/l\n",
1962 burnlo, burnhi, burnlen, result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001963 goto exit_proc;
1964 }
1965
1966 /* copy the data to the flash download buffer */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001967 for (j = 0; j < nwrites; j++) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001968 writebuf = buf +
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001969 (i * hw->bufinfo.len) +
1970 (j * HFA384x_USB_RWMEM_MAXLEN);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001971
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001972 writepage = HFA384x_ADDR_CMD_MKPAGE(dlbufaddr +
Edgardo Hames631c8de2010-03-08 17:02:37 -08001973 (j * HFA384x_USB_RWMEM_MAXLEN));
1974 writeoffset = HFA384x_ADDR_CMD_MKOFF(dlbufaddr +
1975 (j * HFA384x_USB_RWMEM_MAXLEN));
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001976
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001977 writelen = burnlen - (j * HFA384x_USB_RWMEM_MAXLEN);
1978 writelen = writelen > HFA384x_USB_RWMEM_MAXLEN ?
1979 HFA384x_USB_RWMEM_MAXLEN : writelen;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001980
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001981 result = hfa384x_dowmem_wait(hw,
1982 writepage,
1983 writeoffset,
1984 writebuf, writelen);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001985 }
1986
1987 /* set the download 'write flash' mode */
1988 result = hfa384x_cmd_download(hw,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01001989 HFA384x_PROGMODE_NVWRITE,
1990 0, 0, 0);
1991 if (result) {
Avinash Kumar263b8bb2013-09-06 22:21:49 +05301992 netdev_err(hw->wlandev->netdev,
Sherif Shehab Aldin3f2d6562014-04-05 23:34:40 +02001993 "download(NVWRITE,lo=%x,hi=%x,len=%x) cmd failed, result=%d. Aborting d/l\n",
1994 burnlo, burnhi, burnlen, result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07001995 goto exit_proc;
1996 }
1997
1998 /* TODO: We really should do a readback and compare. */
1999 }
2000
2001exit_proc:
2002
2003 /* Leave the firmware in the 'post-prog' mode. flashdl_disable will */
2004 /* actually disable programming mode. Remember, that will cause the */
2005 /* the firmware to effectively reset itself. */
2006
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002007 return result;
2008}
2009
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002010/*----------------------------------------------------------------
2011* hfa384x_drvr_getconfig
2012*
2013* Performs the sequence necessary to read a config/info item.
2014*
2015* Arguments:
2016* hw device structure
2017* rid config/info record id (host order)
2018* buf host side record buffer. Upon return it will
2019* contain the body portion of the record (minus the
2020* RID and len).
2021* len buffer length (in bytes, should match record length)
2022*
2023* Returns:
2024* 0 success
2025* >0 f/w reported error - f/w status code
2026* <0 driver reported error
Edgardo Hames631c8de2010-03-08 17:02:37 -08002027* -ENODATA length mismatch between argument and retrieved
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002028* record.
2029*
2030* Side effects:
2031*
2032* Call context:
2033* process
2034----------------------------------------------------------------*/
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02002035int hfa384x_drvr_getconfig(struct hfa384x *hw, u16 rid, void *buf, u16 len)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002036{
Devendra Naga102db1f2012-09-09 18:41:00 +05302037 return hfa384x_dorrid_wait(hw, rid, buf, len);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002038}
2039
2040/*----------------------------------------------------------------
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002041 * hfa384x_drvr_setconfig_async
2042 *
2043 * Performs the sequence necessary to write a config/info item.
2044 *
2045 * Arguments:
2046 * hw device structure
2047 * rid config/info record id (in host order)
2048 * buf host side record buffer
2049 * len buffer length (in bytes)
2050 * usercb completion callback
2051 * usercb_data completion callback argument
2052 *
2053 * Returns:
2054 * 0 success
2055 * >0 f/w reported error - f/w status code
2056 * <0 driver reported error
2057 *
2058 * Side effects:
2059 *
2060 * Call context:
2061 * process
2062 ----------------------------------------------------------------*/
2063int
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02002064hfa384x_drvr_setconfig_async(struct hfa384x *hw,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002065 u16 rid,
2066 void *buf,
2067 u16 len, ctlx_usercb_t usercb, void *usercb_data)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002068{
2069 return hfa384x_dowrid_async(hw, rid, buf, len,
2070 hfa384x_cb_status, usercb, usercb_data);
2071}
2072
2073/*----------------------------------------------------------------
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002074* hfa384x_drvr_ramdl_disable
2075*
2076* Ends the ram download state.
2077*
2078* Arguments:
2079* hw device structure
2080*
2081* Returns:
2082* 0 success
2083* >0 f/w reported error - f/w status code
2084* <0 driver reported error
2085*
2086* Side effects:
2087*
2088* Call context:
2089* process
2090----------------------------------------------------------------*/
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02002091int hfa384x_drvr_ramdl_disable(struct hfa384x *hw)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002092{
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002093 /* Check that we're already in the download state */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002094 if (hw->dlstate != HFA384x_DLSTATE_RAMENABLED)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002095 return -EINVAL;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002096
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +01002097 pr_debug("ramdl_disable()\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002098
2099 /* There isn't much we can do at this point, so I don't */
2100 /* bother w/ the return value */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002101 hfa384x_cmd_download(hw, HFA384x_PROGMODE_DISABLE, 0, 0, 0);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002102 hw->dlstate = HFA384x_DLSTATE_DISABLED;
2103
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002104 return 0;
2105}
2106
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002107/*----------------------------------------------------------------
2108* hfa384x_drvr_ramdl_enable
2109*
2110* Begins the ram download state. Checks to see that we're not
2111* already in a download state and that a port isn't enabled.
2112* Sets the download state and calls cmd_download with the
2113* ENABLE_VOLATILE subcommand and the exeaddr argument.
2114*
2115* Arguments:
2116* hw device structure
2117* exeaddr the card execution address that will be
2118* jumped to when ramdl_disable() is called
2119* (host order).
2120*
2121* Returns:
2122* 0 success
2123* >0 f/w reported error - f/w status code
2124* <0 driver reported error
2125*
2126* Side effects:
2127*
2128* Call context:
2129* process
2130----------------------------------------------------------------*/
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02002131int hfa384x_drvr_ramdl_enable(struct hfa384x *hw, u32 exeaddr)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002132{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002133 int result = 0;
2134 u16 lowaddr;
2135 u16 hiaddr;
2136 int i;
Moritz Muehlenhoff8a251b52009-01-21 22:00:44 +01002137
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002138 /* Check that a port isn't active */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002139 for (i = 0; i < HFA384x_PORTID_MAX; i++) {
2140 if (hw->port_enabled[i]) {
Avinash Kumar263b8bb2013-09-06 22:21:49 +05302141 netdev_err(hw->wlandev->netdev,
Sherif Shehab Aldin3f2d6562014-04-05 23:34:40 +02002142 "Can't download with a macport enabled.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002143 return -EINVAL;
2144 }
2145 }
2146
2147 /* Check that we're not already in a download state */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002148 if (hw->dlstate != HFA384x_DLSTATE_DISABLED) {
Avinash Kumar263b8bb2013-09-06 22:21:49 +05302149 netdev_err(hw->wlandev->netdev, "Download state not disabled.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002150 return -EINVAL;
2151 }
2152
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +01002153 pr_debug("ramdl_enable, exeaddr=0x%08x\n", exeaddr);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002154
2155 /* Call the download(1,addr) function */
2156 lowaddr = HFA384x_ADDR_CMD_MKOFF(exeaddr);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002157 hiaddr = HFA384x_ADDR_CMD_MKPAGE(exeaddr);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002158
2159 result = hfa384x_cmd_download(hw, HFA384x_PROGMODE_RAM,
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002160 lowaddr, hiaddr, 0);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002161
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002162 if (result == 0) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002163 /* Set the download state */
2164 hw->dlstate = HFA384x_DLSTATE_RAMENABLED;
2165 } else {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05302166 pr_debug("cmd_download(0x%04x, 0x%04x) failed, result=%d.\n",
2167 lowaddr, hiaddr, result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002168 }
2169
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002170 return result;
2171}
2172
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002173/*----------------------------------------------------------------
2174* hfa384x_drvr_ramdl_write
2175*
2176* Performs a RAM download of a chunk of data. First checks to see
2177* that we're in the RAM download state, then uses the [read|write]mem USB
2178* commands to 1) copy the data, 2) readback and compare. The download
2179* state is unaffected. When all data has been written using
2180* this function, call drvr_ramdl_disable() to end the download state
2181* and restart the MAC.
2182*
2183* Arguments:
2184* hw device structure
2185* daddr Card address to write to. (host order)
2186* buf Ptr to data to write.
2187* len Length of data (host order).
2188*
2189* Returns:
2190* 0 success
2191* >0 f/w reported error - f/w status code
2192* <0 driver reported error
2193*
2194* Side effects:
2195*
2196* Call context:
2197* process
2198----------------------------------------------------------------*/
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02002199int hfa384x_drvr_ramdl_write(struct hfa384x *hw, u32 daddr, void *buf, u32 len)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002200{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002201 int result = 0;
2202 int nwrites;
2203 u8 *data = buf;
2204 int i;
2205 u32 curraddr;
2206 u16 currpage;
2207 u16 curroffset;
2208 u16 currlen;
Moritz Muehlenhoff8a251b52009-01-21 22:00:44 +01002209
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002210 /* Check that we're in the ram download state */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002211 if (hw->dlstate != HFA384x_DLSTATE_RAMENABLED)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002212 return -EINVAL;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002213
Sherif Shehab Aldina2120132014-04-05 23:33:16 +02002214 netdev_info(hw->wlandev->netdev, "Writing %d bytes to ram @0x%06x\n",
2215 len, daddr);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002216
2217 /* How many dowmem calls? */
2218 nwrites = len / HFA384x_USB_RWMEM_MAXLEN;
2219 nwrites += len % HFA384x_USB_RWMEM_MAXLEN ? 1 : 0;
2220
2221 /* Do blocking wmem's */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002222 for (i = 0; i < nwrites; i++) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002223 /* make address args */
2224 curraddr = daddr + (i * HFA384x_USB_RWMEM_MAXLEN);
2225 currpage = HFA384x_ADDR_CMD_MKPAGE(curraddr);
2226 curroffset = HFA384x_ADDR_CMD_MKOFF(curraddr);
2227 currlen = len - (i * HFA384x_USB_RWMEM_MAXLEN);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002228 if (currlen > HFA384x_USB_RWMEM_MAXLEN)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002229 currlen = HFA384x_USB_RWMEM_MAXLEN;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002230
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002231 /* Do blocking ctlx */
2232 result = hfa384x_dowmem_wait(hw,
2233 currpage,
2234 curroffset,
2235 data +
2236 (i * HFA384x_USB_RWMEM_MAXLEN),
2237 currlen);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002238
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002239 if (result)
2240 break;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002241
2242 /* TODO: We really should have a readback. */
2243 }
2244
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002245 return result;
2246}
2247
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002248/*----------------------------------------------------------------
2249* hfa384x_drvr_readpda
2250*
2251* Performs the sequence to read the PDA space. Note there is no
2252* drvr_writepda() function. Writing a PDA is
2253* generally implemented by a calling component via calls to
2254* cmd_download and writing to the flash download buffer via the
2255* aux regs.
2256*
2257* Arguments:
2258* hw device structure
2259* buf buffer to store PDA in
2260* len buffer length
2261*
2262* Returns:
2263* 0 success
2264* >0 f/w reported error - f/w status code
2265* <0 driver reported error
Masanari Iida1a6dfce2014-12-01 00:29:00 +09002266* -ETIMEDOUT timeout waiting for the cmd regs to become
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002267* available, or waiting for the control reg
2268* to indicate the Aux port is enabled.
2269* -ENODATA the buffer does NOT contain a valid PDA.
2270* Either the card PDA is bad, or the auxdata
2271* reads are giving us garbage.
2272
2273*
2274* Side effects:
2275*
2276* Call context:
2277* process or non-card interrupt.
2278----------------------------------------------------------------*/
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02002279int hfa384x_drvr_readpda(struct hfa384x *hw, void *buf, unsigned int len)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002280{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002281 int result = 0;
2282 u16 *pda = buf;
2283 int pdaok = 0;
2284 int morepdrs = 1;
2285 int currpdr = 0; /* word offset of the current pdr */
2286 size_t i;
2287 u16 pdrlen; /* pdr length in bytes, host order */
2288 u16 pdrcode; /* pdr code, host order */
2289 u16 currpage;
2290 u16 curroffset;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002291 struct pdaloc {
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002292 u32 cardaddr;
2293 u16 auxctl;
2294 } pdaloc[] = {
2295 {
2296 HFA3842_PDA_BASE, 0}, {
2297 HFA3841_PDA_BASE, 0}, {
2298 HFA3841_PDA_BOGUS_BASE, 0}
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002299 };
2300
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002301 /* Read the pda from each known address. */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002302 for (i = 0; i < ARRAY_SIZE(pdaloc); i++) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002303 /* Make address */
2304 currpage = HFA384x_ADDR_CMD_MKPAGE(pdaloc[i].cardaddr);
2305 curroffset = HFA384x_ADDR_CMD_MKOFF(pdaloc[i].cardaddr);
2306
Edgardo Hames631c8de2010-03-08 17:02:37 -08002307 /* units of bytes */
2308 result = hfa384x_dormem_wait(hw, currpage, curroffset, buf,
2309 len);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002310
2311 if (result) {
Avinash Kumar263b8bb2013-09-06 22:21:49 +05302312 netdev_warn(hw->wlandev->netdev,
Sherif Shehab Aldin3f2d6562014-04-05 23:34:40 +02002313 "Read from index %zd failed, continuing\n",
2314 i);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002315 continue;
2316 }
2317
2318 /* Test for garbage */
2319 pdaok = 1; /* initially assume good */
2320 morepdrs = 1;
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002321 while (pdaok && morepdrs) {
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01002322 pdrlen = le16_to_cpu(pda[currpdr]) * 2;
2323 pdrcode = le16_to_cpu(pda[currpdr + 1]);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002324 /* Test the record length */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002325 if (pdrlen > HFA384x_PDR_LEN_MAX || pdrlen == 0) {
Sherif Shehab Aldina2120132014-04-05 23:33:16 +02002326 netdev_err(hw->wlandev->netdev,
2327 "pdrlen invalid=%d\n", pdrlen);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002328 pdaok = 0;
2329 break;
2330 }
2331 /* Test the code */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002332 if (!hfa384x_isgood_pdrcode(pdrcode)) {
Avinash Kumar263b8bb2013-09-06 22:21:49 +05302333 netdev_err(hw->wlandev->netdev, "pdrcode invalid=%d\n",
Sherif Shehab Aldin3f2d6562014-04-05 23:34:40 +02002334 pdrcode);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002335 pdaok = 0;
2336 break;
2337 }
2338 /* Test for completion */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002339 if (pdrcode == HFA384x_PDR_END_OF_PDA)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002340 morepdrs = 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002341
2342 /* Move to the next pdr (if necessary) */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002343 if (morepdrs) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002344 /* note the access to pda[], need words here */
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01002345 currpdr += le16_to_cpu(pda[currpdr]) + 1;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002346 }
2347 }
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002348 if (pdaok) {
Avinash Kumar263b8bb2013-09-06 22:21:49 +05302349 netdev_info(hw->wlandev->netdev,
Sherif Shehab Aldin3f2d6562014-04-05 23:34:40 +02002350 "PDA Read from 0x%08x in %s space.\n",
2351 pdaloc[i].cardaddr,
2352 pdaloc[i].auxctl == 0 ? "EXTDS" :
2353 pdaloc[i].auxctl == 1 ? "NV" :
2354 pdaloc[i].auxctl == 2 ? "PHY" :
2355 pdaloc[i].auxctl == 3 ? "ICSRAM" :
2356 "<bogus auxctl>");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002357 break;
2358 }
2359 }
2360 result = pdaok ? 0 : -ENODATA;
2361
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002362 if (result)
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +01002363 pr_debug("Failure: pda is not okay\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002364
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002365 return result;
2366}
2367
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002368/*----------------------------------------------------------------
2369* hfa384x_drvr_setconfig
2370*
2371* Performs the sequence necessary to write a config/info item.
2372*
2373* Arguments:
2374* hw device structure
2375* rid config/info record id (in host order)
2376* buf host side record buffer
2377* len buffer length (in bytes)
2378*
2379* Returns:
2380* 0 success
2381* >0 f/w reported error - f/w status code
2382* <0 driver reported error
2383*
2384* Side effects:
2385*
2386* Call context:
2387* process
2388----------------------------------------------------------------*/
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02002389int hfa384x_drvr_setconfig(struct hfa384x *hw, u16 rid, void *buf, u16 len)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002390{
2391 return hfa384x_dowrid_wait(hw, rid, buf, len);
2392}
2393
2394/*----------------------------------------------------------------
2395* hfa384x_drvr_start
2396*
2397* Issues the MAC initialize command, sets up some data structures,
2398* and enables the interrupts. After this function completes, the
2399* low-level stuff should be ready for any/all commands.
2400*
2401* Arguments:
2402* hw device structure
2403* Returns:
2404* 0 success
2405* >0 f/w reported error - f/w status code
2406* <0 driver reported error
2407*
2408* Side effects:
2409*
2410* Call context:
2411* process
2412----------------------------------------------------------------*/
Richard Kennedy7b7e7e82008-11-03 11:16:09 +00002413
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02002414int hfa384x_drvr_start(struct hfa384x *hw)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002415{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002416 int result, result1, result2;
2417 u16 status;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002418
2419 might_sleep();
2420
Richard Kennedy7b7e7e82008-11-03 11:16:09 +00002421 /* Clear endpoint stalls - but only do this if the endpoint
2422 * is showing a stall status. Some prism2 cards seem to behave
2423 * badly if a clear_halt is called when the endpoint is already
2424 * ok
2425 */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002426 result =
2427 usb_get_status(hw->usb, USB_RECIP_ENDPOINT, hw->endp_in, &status);
Richard Kennedy7b7e7e82008-11-03 11:16:09 +00002428 if (result < 0) {
Avinash Kumar263b8bb2013-09-06 22:21:49 +05302429 netdev_err(hw->wlandev->netdev, "Cannot get bulk in endpoint status.\n");
Richard Kennedy7b7e7e82008-11-03 11:16:09 +00002430 goto done;
2431 }
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002432 if ((status == 1) && usb_clear_halt(hw->usb, hw->endp_in))
Avinash Kumar263b8bb2013-09-06 22:21:49 +05302433 netdev_err(hw->wlandev->netdev, "Failed to reset bulk in endpoint.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002434
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002435 result =
2436 usb_get_status(hw->usb, USB_RECIP_ENDPOINT, hw->endp_out, &status);
Richard Kennedy7b7e7e82008-11-03 11:16:09 +00002437 if (result < 0) {
Avinash Kumar263b8bb2013-09-06 22:21:49 +05302438 netdev_err(hw->wlandev->netdev, "Cannot get bulk out endpoint status.\n");
Richard Kennedy7b7e7e82008-11-03 11:16:09 +00002439 goto done;
2440 }
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002441 if ((status == 1) && usb_clear_halt(hw->usb, hw->endp_out))
Avinash Kumar263b8bb2013-09-06 22:21:49 +05302442 netdev_err(hw->wlandev->netdev, "Failed to reset bulk out endpoint.\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002443
2444 /* Synchronous unlink, in case we're trying to restart the driver */
2445 usb_kill_urb(&hw->rx_urb);
2446
2447 /* Post the IN urb */
2448 result = submit_rx_urb(hw, GFP_KERNEL);
2449 if (result != 0) {
Avinash Kumar263b8bb2013-09-06 22:21:49 +05302450 netdev_err(hw->wlandev->netdev,
Sherif Shehab Aldin3f2d6562014-04-05 23:34:40 +02002451 "Fatal, failed to submit RX URB, result=%d\n",
2452 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002453 goto done;
2454 }
2455
Richard Kennedy7b7e7e82008-11-03 11:16:09 +00002456 /* Call initialize twice, with a 1 second sleep in between.
2457 * This is a nasty work-around since many prism2 cards seem to
2458 * need time to settle after an init from cold. The second
2459 * call to initialize in theory is not necessary - but we call
2460 * it anyway as a double insurance policy:
2461 * 1) If the first init should fail, the second may well succeed
2462 * and the card can still be used
2463 * 2) It helps ensures all is well with the card after the first
2464 * init and settle time.
2465 */
2466 result1 = hfa384x_cmd_initialize(hw);
2467 msleep(1000);
Sherif Shehab Aldin96b19712014-04-05 23:34:56 +02002468 result = hfa384x_cmd_initialize(hw);
2469 result2 = result;
Richard Kennedy7b7e7e82008-11-03 11:16:09 +00002470 if (result1 != 0) {
2471 if (result2 != 0) {
Avinash Kumar263b8bb2013-09-06 22:21:49 +05302472 netdev_err(hw->wlandev->netdev,
Sherif Shehab Aldin3f2d6562014-04-05 23:34:40 +02002473 "cmd_initialize() failed on two attempts, results %d and %d\n",
2474 result1, result2);
Richard Kennedy7b7e7e82008-11-03 11:16:09 +00002475 usb_kill_urb(&hw->rx_urb);
2476 goto done;
2477 } else {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05302478 pr_debug("First cmd_initialize() failed (result %d),\n",
2479 result1);
Edgardo Hames4ffab682010-03-15 23:00:40 -03002480 pr_debug("but second attempt succeeded. All should be ok\n");
Richard Kennedy7b7e7e82008-11-03 11:16:09 +00002481 }
2482 } else if (result2 != 0) {
Avinash Kumar263b8bb2013-09-06 22:21:49 +05302483 netdev_warn(hw->wlandev->netdev, "First cmd_initialize() succeeded, but second attempt failed (result=%d)\n",
Sherif Shehab Aldin3f2d6562014-04-05 23:34:40 +02002484 result2);
Avinash Kumar263b8bb2013-09-06 22:21:49 +05302485 netdev_warn(hw->wlandev->netdev,
Sherif Shehab Aldin3f2d6562014-04-05 23:34:40 +02002486 "Most likely the card will be functional\n");
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002487 goto done;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002488 }
2489
2490 hw->state = HFA384x_STATE_RUNNING;
2491
2492done:
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002493 return result;
2494}
2495
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002496/*----------------------------------------------------------------
2497* hfa384x_drvr_stop
2498*
2499* Shuts down the MAC to the point where it is safe to unload the
2500* driver. Any subsystem that may be holding a data or function
2501* ptr into the driver must be cleared/deinitialized.
2502*
2503* Arguments:
2504* hw device structure
2505* Returns:
2506* 0 success
2507* >0 f/w reported error - f/w status code
2508* <0 driver reported error
2509*
2510* Side effects:
2511*
2512* Call context:
2513* process
2514----------------------------------------------------------------*/
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02002515int hfa384x_drvr_stop(struct hfa384x *hw)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002516{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002517 int i;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002518
2519 might_sleep();
2520
2521 /* There's no need for spinlocks here. The USB "disconnect"
2522 * function sets this "removed" flag and then calls us.
2523 */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002524 if (!hw->wlandev->hwremoved) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002525 /* Call initialize to leave the MAC in its 'reset' state */
2526 hfa384x_cmd_initialize(hw);
2527
2528 /* Cancel the rxurb */
2529 usb_kill_urb(&hw->rx_urb);
2530 }
2531
2532 hw->link_status = HFA384x_LINK_NOTCONNECTED;
2533 hw->state = HFA384x_STATE_INIT;
2534
2535 del_timer_sync(&hw->commsqual_timer);
2536
2537 /* Clear all the port status */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002538 for (i = 0; i < HFA384x_NUMPORTS_MAX; i++)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002539 hw->port_enabled[i] = 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002540
Peter Senna Tschudin4764ca92014-05-26 16:08:50 +02002541 return 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002542}
2543
2544/*----------------------------------------------------------------
2545* hfa384x_drvr_txframe
2546*
2547* Takes a frame from prism2sta and queues it for transmission.
2548*
2549* Arguments:
2550* hw device structure
2551* skb packet buffer struct. Contains an 802.11
2552* data frame.
2553* p80211_hdr points to the 802.11 header for the packet.
2554* Returns:
2555* 0 Success and more buffs available
2556* 1 Success but no more buffs
2557* 2 Allocation failure
2558* 4 Buffer full or queue busy
2559*
2560* Side effects:
2561*
2562* Call context:
2563* interrupt
2564----------------------------------------------------------------*/
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02002565int hfa384x_drvr_txframe(struct hfa384x *hw, struct sk_buff *skb,
Edgardo Hames93df38e2010-07-30 22:51:55 -03002566 union p80211_hdr *p80211_hdr,
Edgardo Hames51e48962010-07-31 13:06:52 -03002567 struct p80211_metawep *p80211_wep)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002568{
Sergio Paracuelloseb76afc2016-09-28 20:19:05 +02002569 int usbpktlen = sizeof(struct hfa384x_tx_frame);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002570 int result;
2571 int ret;
2572 char *ptr;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002573
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002574 if (hw->tx_urb.status == -EINPROGRESS) {
Avinash Kumar263b8bb2013-09-06 22:21:49 +05302575 netdev_warn(hw->wlandev->netdev, "TX URB already in use\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002576 result = 3;
2577 goto exit;
2578 }
2579
2580 /* Build Tx frame structure */
2581 /* Set up the control field */
2582 memset(&hw->txbuff.txfrm.desc, 0, sizeof(hw->txbuff.txfrm.desc));
2583
2584 /* Setup the usb type field */
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01002585 hw->txbuff.type = cpu_to_le16(HFA384x_USB_TXFRM);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002586
2587 /* Set up the sw_support field to identify this frame */
2588 hw->txbuff.txfrm.desc.sw_support = 0x0123;
2589
2590/* Tx complete and Tx exception disable per dleach. Might be causing
2591 * buf depletion
2592 */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002593/* #define DOEXC SLP -- doboth breaks horribly under load, doexc less so. */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002594#if defined(DOBOTH)
2595 hw->txbuff.txfrm.desc.tx_control =
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002596 HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
2597 HFA384x_TX_TXEX_SET(1) | HFA384x_TX_TXOK_SET(1);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002598#elif defined(DOEXC)
2599 hw->txbuff.txfrm.desc.tx_control =
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002600 HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
2601 HFA384x_TX_TXEX_SET(1) | HFA384x_TX_TXOK_SET(0);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002602#else
2603 hw->txbuff.txfrm.desc.tx_control =
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002604 HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
2605 HFA384x_TX_TXEX_SET(0) | HFA384x_TX_TXOK_SET(0);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002606#endif
2607 hw->txbuff.txfrm.desc.tx_control =
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01002608 cpu_to_le16(hw->txbuff.txfrm.desc.tx_control);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002609
2610 /* copy the header over to the txdesc */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002611 memcpy(&(hw->txbuff.txfrm.desc.frame_control), p80211_hdr,
Edgardo Hames93df38e2010-07-30 22:51:55 -03002612 sizeof(union p80211_hdr));
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002613
2614 /* if we're using host WEP, increase size by IV+ICV */
2615 if (p80211_wep->data) {
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01002616 hw->txbuff.txfrm.desc.data_len = cpu_to_le16(skb->len + 8);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002617 usbpktlen += 8;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002618 } else {
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01002619 hw->txbuff.txfrm.desc.data_len = cpu_to_le16(skb->len);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002620 }
2621
2622 usbpktlen += skb->len;
2623
2624 /* copy over the WEP IV if we are using host WEP */
2625 ptr = hw->txbuff.txfrm.data;
2626 if (p80211_wep->data) {
2627 memcpy(ptr, p80211_wep->iv, sizeof(p80211_wep->iv));
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002628 ptr += sizeof(p80211_wep->iv);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002629 memcpy(ptr, p80211_wep->data, skb->len);
2630 } else {
2631 memcpy(ptr, skb->data, skb->len);
2632 }
2633 /* copy over the packet data */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002634 ptr += skb->len;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002635
2636 /* copy over the WEP ICV if we are using host WEP */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002637 if (p80211_wep->data)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002638 memcpy(ptr, p80211_wep->icv, sizeof(p80211_wep->icv));
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002639
2640 /* Send the USB packet */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002641 usb_fill_bulk_urb(&(hw->tx_urb), hw->usb,
2642 hw->endp_out,
2643 &(hw->txbuff), ROUNDUP64(usbpktlen),
2644 hfa384x_usbout_callback, hw->wlandev);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002645 hw->tx_urb.transfer_flags |= USB_QUEUE_BULK;
2646
2647 result = 1;
2648 ret = submit_tx_urb(hw, &hw->tx_urb, GFP_ATOMIC);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002649 if (ret != 0) {
Sherif Shehab Aldina2120132014-04-05 23:33:16 +02002650 netdev_err(hw->wlandev->netdev,
2651 "submit_tx_urb() failed, error=%d\n", ret);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002652 result = 3;
2653 }
2654
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002655exit:
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002656 return result;
2657}
2658
sayli karnikc9573a82016-09-18 15:11:14 +05302659void hfa384x_tx_timeout(struct wlandevice *wlandev)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002660{
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02002661 struct hfa384x *hw = wlandev->priv;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002662 unsigned long flags;
2663
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002664 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2665
Dan Carpenter59457892010-06-17 14:08:47 +02002666 if (!hw->wlandev->hwremoved) {
2667 int sched;
2668
2669 sched = !test_and_set_bit(WORK_TX_HALT, &hw->usb_flags);
2670 sched |= !test_and_set_bit(WORK_RX_HALT, &hw->usb_flags);
2671 if (sched)
2672 schedule_work(&hw->usb_work);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002673 }
2674
2675 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002676}
2677
2678/*----------------------------------------------------------------
2679* hfa384x_usbctlx_reaper_task
2680*
2681* Tasklet to delete dead CTLX objects
2682*
2683* Arguments:
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02002684* data ptr to a struct hfa384x
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002685*
2686* Returns:
2687*
2688* Call context:
2689* Interrupt
2690----------------------------------------------------------------*/
2691static void hfa384x_usbctlx_reaper_task(unsigned long data)
2692{
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02002693 struct hfa384x *hw = (struct hfa384x *)data;
Sergio Paracuellosa10d36b2016-09-28 20:20:16 +02002694 struct hfa384x_usbctlx *ctlx, *temp;
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002695 unsigned long flags;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002696
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002697 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2698
2699 /* This list is guaranteed to be empty if someone
2700 * has unplugged the adapter.
2701 */
Geliang Tang57477bf2015-12-15 23:29:32 +08002702 list_for_each_entry_safe(ctlx, temp, &hw->ctlxq.reapable, list) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002703 list_del(&ctlx->list);
2704 kfree(ctlx);
2705 }
2706
2707 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002708}
2709
2710/*----------------------------------------------------------------
2711* hfa384x_usbctlx_completion_task
2712*
2713* Tasklet to call completion handlers for returned CTLXs
2714*
2715* Arguments:
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02002716* data ptr to struct hfa384x
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002717*
2718* Returns:
2719* Nothing
2720*
2721* Call context:
2722* Interrupt
2723----------------------------------------------------------------*/
2724static void hfa384x_usbctlx_completion_task(unsigned long data)
2725{
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02002726 struct hfa384x *hw = (struct hfa384x *)data;
Sergio Paracuellosa10d36b2016-09-28 20:20:16 +02002727 struct hfa384x_usbctlx *ctlx, *temp;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002728 unsigned long flags;
2729
2730 int reap = 0;
2731
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002732 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2733
2734 /* This list is guaranteed to be empty if someone
2735 * has unplugged the adapter ...
2736 */
Geliang Tang57477bf2015-12-15 23:29:32 +08002737 list_for_each_entry_safe(ctlx, temp, &hw->ctlxq.completing, list) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002738 /* Call the completion function that this
2739 * command was assigned, assuming it has one.
2740 */
Nicholas Sim02e02042016-04-05 17:37:12 +01002741 if (ctlx->cmdcb) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002742 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2743 ctlx->cmdcb(hw, ctlx);
2744 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2745
2746 /* Make sure we don't try and complete
2747 * this CTLX more than once!
2748 */
2749 ctlx->cmdcb = NULL;
2750
2751 /* Did someone yank the adapter out
2752 * while our list was (briefly) unlocked?
2753 */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002754 if (hw->wlandev->hwremoved) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002755 reap = 0;
2756 break;
2757 }
2758 }
2759
2760 /*
2761 * "Reapable" CTLXs are ones which don't have any
2762 * threads waiting for them to die. Hence they must
2763 * be delivered to The Reaper!
2764 */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002765 if (ctlx->reapable) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002766 /* Move the CTLX off the "completing" list (hopefully)
2767 * on to the "reapable" list where the reaper task
2768 * can find it. And "reapable" means that this CTLX
2769 * isn't sitting on a wait-queue somewhere.
2770 */
2771 list_move_tail(&ctlx->list, &hw->ctlxq.reapable);
2772 reap = 1;
2773 }
2774
2775 complete(&ctlx->done);
2776 }
2777 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
2778
2779 if (reap)
2780 tasklet_schedule(&hw->reaper_bh);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002781}
2782
2783/*----------------------------------------------------------------
2784* unlocked_usbctlx_cancel_async
2785*
2786* Mark the CTLX dead asynchronously, and ensure that the
2787* next command on the queue is run afterwards.
2788*
2789* Arguments:
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02002790* hw ptr to the struct hfa384x structure
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002791* ctlx ptr to a CTLX structure
2792*
2793* Returns:
2794* 0 the CTLX's URB is inactive
2795* -EINPROGRESS the URB is currently being unlinked
2796*
2797* Call context:
2798* Either process or interrupt, but presumably interrupt
2799----------------------------------------------------------------*/
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02002800static int unlocked_usbctlx_cancel_async(struct hfa384x *hw,
Sergio Paracuellosa10d36b2016-09-28 20:20:16 +02002801 struct hfa384x_usbctlx *ctlx)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002802{
2803 int ret;
2804
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002805 /*
2806 * Try to delete the URB containing our request packet.
2807 * If we succeed, then its completion handler will be
2808 * called with a status of -ECONNRESET.
2809 */
2810 hw->ctlx_urb.transfer_flags |= URB_ASYNC_UNLINK;
2811 ret = usb_unlink_urb(&hw->ctlx_urb);
2812
2813 if (ret != -EINPROGRESS) {
2814 /*
2815 * The OUT URB had either already completed
2816 * or was still in the pending queue, so the
2817 * URB's completion function will not be called.
2818 * We will have to complete the CTLX ourselves.
2819 */
2820 ctlx->state = CTLX_REQ_FAILED;
2821 unlocked_usbctlx_complete(hw, ctlx);
2822 ret = 0;
2823 }
2824
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002825 return ret;
2826}
2827
2828/*----------------------------------------------------------------
2829* unlocked_usbctlx_complete
2830*
2831* A CTLX has completed. It may have been successful, it may not
2832* have been. At this point, the CTLX should be quiescent. The URBs
2833* aren't active and the timers should have been stopped.
2834*
2835* The CTLX is migrated to the "completing" queue, and the completing
2836* tasklet is scheduled.
2837*
2838* Arguments:
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02002839* hw ptr to a struct hfa384x structure
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002840* ctlx ptr to a ctlx structure
2841*
2842* Returns:
2843* nothing
2844*
2845* Side effects:
2846*
2847* Call context:
2848* Either, assume interrupt
2849----------------------------------------------------------------*/
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02002850static void unlocked_usbctlx_complete(struct hfa384x *hw, struct hfa384x_usbctlx *ctlx)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002851{
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002852 /* Timers have been stopped, and ctlx should be in
2853 * a terminal state. Retire it from the "active"
2854 * queue.
2855 */
2856 list_move_tail(&ctlx->list, &hw->ctlxq.completing);
2857 tasklet_schedule(&hw->completion_bh);
2858
2859 switch (ctlx->state) {
2860 case CTLX_COMPLETE:
2861 case CTLX_REQ_FAILED:
2862 /* This are the correct terminating states. */
2863 break;
2864
2865 default:
Avinash Kumar263b8bb2013-09-06 22:21:49 +05302866 netdev_err(hw->wlandev->netdev, "CTLX[%d] not in a terminating state(%s)\n",
Sherif Shehab Aldin3f2d6562014-04-05 23:34:40 +02002867 le16_to_cpu(ctlx->outbuf.type),
2868 ctlxstr(ctlx->state));
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002869 break;
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002870 } /* switch */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002871}
2872
2873/*----------------------------------------------------------------
2874* hfa384x_usbctlxq_run
2875*
2876* Checks to see if the head item is running. If not, starts it.
2877*
2878* Arguments:
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02002879* hw ptr to struct hfa384x
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002880*
2881* Returns:
2882* nothing
2883*
2884* Side effects:
2885*
2886* Call context:
2887* any
2888----------------------------------------------------------------*/
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02002889static void hfa384x_usbctlxq_run(struct hfa384x *hw)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002890{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002891 unsigned long flags;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002892
2893 /* acquire lock */
2894 spin_lock_irqsave(&hw->ctlxq.lock, flags);
2895
2896 /* Only one active CTLX at any one time, because there's no
2897 * other (reliable) way to match the response URB to the
2898 * correct CTLX.
2899 *
2900 * Don't touch any of these CTLXs if the hardware
2901 * has been removed or the USB subsystem is stalled.
2902 */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002903 if (!list_empty(&hw->ctlxq.active) ||
2904 test_bit(WORK_TX_HALT, &hw->usb_flags) || hw->wlandev->hwremoved)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002905 goto unlock;
2906
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002907 while (!list_empty(&hw->ctlxq.pending)) {
Sergio Paracuellosa10d36b2016-09-28 20:20:16 +02002908 struct hfa384x_usbctlx *head;
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002909 int result;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002910
2911 /* This is the first pending command */
2912 head = list_entry(hw->ctlxq.pending.next,
Sergio Paracuellosa10d36b2016-09-28 20:20:16 +02002913 struct hfa384x_usbctlx, list);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002914
2915 /* We need to split this off to avoid a race condition */
2916 list_move_tail(&head->list, &hw->ctlxq.active);
2917
2918 /* Fill the out packet */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002919 usb_fill_bulk_urb(&(hw->ctlx_urb), hw->usb,
2920 hw->endp_out,
2921 &(head->outbuf), ROUNDUP64(head->outbufsize),
2922 hfa384x_ctlxout_callback, hw);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002923 hw->ctlx_urb.transfer_flags |= USB_QUEUE_BULK;
2924
Andrew Elwell3f4b4e72010-02-18 23:56:13 +01002925 /* Now submit the URB and update the CTLX's state */
Amitoj Kaur Chawla5850c252016-02-24 21:55:49 +05302926 result = usb_submit_urb(&hw->ctlx_urb, GFP_ATOMIC);
Svenne Krap46800b22010-02-14 18:59:42 +01002927 if (result == 0) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002928 /* This CTLX is now running on the active queue */
2929 head->state = CTLX_REQ_SUBMITTED;
2930
2931 /* Start the OUT wait timer */
2932 hw->req_timer_done = 0;
2933 hw->reqtimer.expires = jiffies + HZ;
2934 add_timer(&hw->reqtimer);
2935
2936 /* Start the IN wait timer */
2937 hw->resp_timer_done = 0;
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002938 hw->resptimer.expires = jiffies + 2 * HZ;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002939 add_timer(&hw->resptimer);
2940
2941 break;
2942 }
2943
2944 if (result == -EPIPE) {
2945 /* The OUT pipe needs resetting, so put
2946 * this CTLX back in the "pending" queue
2947 * and schedule a reset ...
2948 */
Avinash Kumar263b8bb2013-09-06 22:21:49 +05302949 netdev_warn(hw->wlandev->netdev,
Sherif Shehab Aldin3f2d6562014-04-05 23:34:40 +02002950 "%s tx pipe stalled: requesting reset\n",
2951 hw->wlandev->netdev->name);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002952 list_move(&head->list, &hw->ctlxq.pending);
2953 set_bit(WORK_TX_HALT, &hw->usb_flags);
2954 schedule_work(&hw->usb_work);
2955 break;
2956 }
2957
2958 if (result == -ESHUTDOWN) {
Avinash Kumar263b8bb2013-09-06 22:21:49 +05302959 netdev_warn(hw->wlandev->netdev, "%s urb shutdown!\n",
Sherif Shehab Aldin3f2d6562014-04-05 23:34:40 +02002960 hw->wlandev->netdev->name);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002961 break;
2962 }
2963
Avinash Kumar263b8bb2013-09-06 22:21:49 +05302964 netdev_err(hw->wlandev->netdev, "Failed to submit CTLX[%d]: error=%d\n",
Sherif Shehab Aldin3f2d6562014-04-05 23:34:40 +02002965 le16_to_cpu(head->outbuf.type), result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002966 unlocked_usbctlx_complete(hw, head);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002967 } /* while */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002968
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002969unlock:
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002970 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002971}
2972
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002973/*----------------------------------------------------------------
2974* hfa384x_usbin_callback
2975*
2976* Callback for URBs on the BULKIN endpoint.
2977*
2978* Arguments:
2979* urb ptr to the completed urb
2980*
2981* Returns:
2982* nothing
2983*
2984* Side effects:
2985*
2986* Call context:
2987* interrupt
2988----------------------------------------------------------------*/
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002989static void hfa384x_usbin_callback(struct urb *urb)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002990{
sayli karnikc9573a82016-09-18 15:11:14 +05302991 struct wlandevice *wlandev = urb->context;
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02002992 struct hfa384x *hw;
Sergio Paracuellos3e4180c2016-09-28 20:19:38 +02002993 union hfa384x_usbin *usbin = (union hfa384x_usbin *)urb->transfer_buffer;
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01002994 struct sk_buff *skb = NULL;
2995 int result;
2996 int urb_status;
2997 u16 type;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07002998
2999 enum USBIN_ACTION {
3000 HANDLE,
3001 RESUBMIT,
3002 ABORT
3003 } action;
3004
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003005 if (!wlandev || !wlandev->netdev || wlandev->hwremoved)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003006 goto exit;
3007
3008 hw = wlandev->priv;
3009 if (!hw)
3010 goto exit;
3011
3012 skb = hw->rx_urb_skb;
Stoyan Gaydarov2961f242009-03-10 00:10:27 -05003013 BUG_ON(!skb || (skb->data != urb->transfer_buffer));
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003014
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003015 hw->rx_urb_skb = NULL;
3016
3017 /* Check for error conditions within the URB */
3018 switch (urb->status) {
3019 case 0:
3020 action = HANDLE;
3021
3022 /* Check for short packet */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003023 if (urb->actual_length == 0) {
Tobias Klauser9630f6b2014-07-08 08:37:00 +02003024 wlandev->netdev->stats.rx_errors++;
3025 wlandev->netdev->stats.rx_length_errors++;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003026 action = RESUBMIT;
3027 }
3028 break;
3029
3030 case -EPIPE:
Avinash Kumar263b8bb2013-09-06 22:21:49 +05303031 netdev_warn(hw->wlandev->netdev, "%s rx pipe stalled: requesting reset\n",
Sherif Shehab Aldin3f2d6562014-04-05 23:34:40 +02003032 wlandev->netdev->name);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003033 if (!test_and_set_bit(WORK_RX_HALT, &hw->usb_flags))
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003034 schedule_work(&hw->usb_work);
Tobias Klauser9630f6b2014-07-08 08:37:00 +02003035 wlandev->netdev->stats.rx_errors++;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003036 action = ABORT;
3037 break;
3038
3039 case -EILSEQ:
3040 case -ETIMEDOUT:
3041 case -EPROTO:
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003042 if (!test_and_set_bit(THROTTLE_RX, &hw->usb_flags) &&
3043 !timer_pending(&hw->throttle)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003044 mod_timer(&hw->throttle, jiffies + THROTTLE_JIFFIES);
3045 }
Tobias Klauser9630f6b2014-07-08 08:37:00 +02003046 wlandev->netdev->stats.rx_errors++;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003047 action = ABORT;
3048 break;
3049
3050 case -EOVERFLOW:
Tobias Klauser9630f6b2014-07-08 08:37:00 +02003051 wlandev->netdev->stats.rx_over_errors++;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003052 action = RESUBMIT;
3053 break;
3054
3055 case -ENODEV:
3056 case -ESHUTDOWN:
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +01003057 pr_debug("status=%d, device removed.\n", urb->status);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003058 action = ABORT;
3059 break;
3060
3061 case -ENOENT:
3062 case -ECONNRESET:
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05303063 pr_debug("status=%d, urb explicitly unlinked.\n", urb->status);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003064 action = ABORT;
3065 break;
3066
3067 default:
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +01003068 pr_debug("urb status=%d, transfer flags=0x%x\n",
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05303069 urb->status, urb->transfer_flags);
Tobias Klauser9630f6b2014-07-08 08:37:00 +02003070 wlandev->netdev->stats.rx_errors++;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003071 action = RESUBMIT;
3072 break;
3073 }
3074
3075 urb_status = urb->status;
3076
3077 if (action != ABORT) {
3078 /* Repost the RX URB */
3079 result = submit_rx_urb(hw, GFP_ATOMIC);
3080
3081 if (result != 0) {
Avinash Kumar263b8bb2013-09-06 22:21:49 +05303082 netdev_err(hw->wlandev->netdev,
Sherif Shehab Aldin3f2d6562014-04-05 23:34:40 +02003083 "Fatal, failed to resubmit rx_urb. error=%d\n",
3084 result);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003085 }
3086 }
3087
3088 /* Handle any USB-IN packet */
3089 /* Note: the check of the sw_support field, the type field doesn't
3090 * have bit 12 set like the docs suggest.
3091 */
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01003092 type = le16_to_cpu(usbin->type);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003093 if (HFA384x_USB_ISRXFRM(type)) {
3094 if (action == HANDLE) {
3095 if (usbin->txfrm.desc.sw_support == 0x0123) {
3096 hfa384x_usbin_txcompl(wlandev, usbin);
3097 } else {
3098 skb_put(skb, sizeof(*usbin));
3099 hfa384x_usbin_rx(wlandev, skb);
3100 skb = NULL;
3101 }
3102 }
3103 goto exit;
3104 }
3105 if (HFA384x_USB_ISTXFRM(type)) {
3106 if (action == HANDLE)
3107 hfa384x_usbin_txcompl(wlandev, usbin);
3108 goto exit;
3109 }
3110 switch (type) {
3111 case HFA384x_USB_INFOFRM:
3112 if (action == ABORT)
3113 goto exit;
3114 if (action == HANDLE)
3115 hfa384x_usbin_info(wlandev, usbin);
3116 break;
3117
3118 case HFA384x_USB_CMDRESP:
3119 case HFA384x_USB_WRIDRESP:
3120 case HFA384x_USB_RRIDRESP:
3121 case HFA384x_USB_WMEMRESP:
3122 case HFA384x_USB_RMEMRESP:
3123 /* ALWAYS, ALWAYS, ALWAYS handle this CTLX!!!! */
3124 hfa384x_usbin_ctlx(hw, usbin, urb_status);
3125 break;
3126
3127 case HFA384x_USB_BUFAVAIL:
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +01003128 pr_debug("Received BUFAVAIL packet, frmlen=%d\n",
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05303129 usbin->bufavail.frmlen);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003130 break;
3131
3132 case HFA384x_USB_ERROR:
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +01003133 pr_debug("Received USB_ERROR packet, errortype=%d\n",
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05303134 usbin->usberror.errortype);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003135 break;
3136
3137 default:
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05303138 pr_debug("Unrecognized USBIN packet, type=%x, status=%d\n",
3139 usbin->type, urb_status);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003140 break;
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003141 } /* switch */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003142
3143exit:
3144
3145 if (skb)
3146 dev_kfree_skb(skb);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003147}
3148
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003149/*----------------------------------------------------------------
3150* hfa384x_usbin_ctlx
3151*
3152* We've received a URB containing a Prism2 "response" message.
3153* This message needs to be matched up with a CTLX on the active
3154* queue and our state updated accordingly.
3155*
3156* Arguments:
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02003157* hw ptr to struct hfa384x
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003158* usbin ptr to USB IN packet
3159* urb_status status of this Bulk-In URB
3160*
3161* Returns:
3162* nothing
3163*
3164* Side effects:
3165*
3166* Call context:
3167* interrupt
3168----------------------------------------------------------------*/
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02003169static void hfa384x_usbin_ctlx(struct hfa384x *hw, union hfa384x_usbin *usbin,
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003170 int urb_status)
3171{
Sergio Paracuellosa10d36b2016-09-28 20:20:16 +02003172 struct hfa384x_usbctlx *ctlx;
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003173 int run_queue = 0;
3174 unsigned long flags;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003175
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003176retry:
3177 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3178
3179 /* There can be only one CTLX on the active queue
3180 * at any one time, and this is the CTLX that the
3181 * timers are waiting for.
3182 */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003183 if (list_empty(&hw->ctlxq.active))
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003184 goto unlock;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003185
3186 /* Remove the "response timeout". It's possible that
3187 * we are already too late, and that the timeout is
3188 * already running. And that's just too bad for us,
3189 * because we could lose our CTLX from the active
3190 * queue here ...
3191 */
3192 if (del_timer(&hw->resptimer) == 0) {
3193 if (hw->resp_timer_done == 0) {
3194 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3195 goto retry;
3196 }
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003197 } else {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003198 hw->resp_timer_done = 1;
3199 }
3200
3201 ctlx = get_active_ctlx(hw);
3202
3203 if (urb_status != 0) {
3204 /*
3205 * Bad CTLX, so get rid of it. But we only
3206 * remove it from the active queue if we're no
3207 * longer expecting the OUT URB to complete.
3208 */
3209 if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0)
3210 run_queue = 1;
3211 } else {
Asaf Vertza78d1312015-01-18 09:11:39 +02003212 const __le16 intype = (usbin->type & ~cpu_to_le16(0x8000));
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003213
3214 /*
3215 * Check that our message is what we're expecting ...
3216 */
3217 if (ctlx->outbuf.type != intype) {
Avinash Kumar263b8bb2013-09-06 22:21:49 +05303218 netdev_warn(hw->wlandev->netdev,
Sherif Shehab Aldin3f2d6562014-04-05 23:34:40 +02003219 "Expected IN[%d], received IN[%d] - ignored.\n",
3220 le16_to_cpu(ctlx->outbuf.type),
3221 le16_to_cpu(intype));
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003222 goto unlock;
3223 }
3224
3225 /* This URB has succeeded, so grab the data ... */
3226 memcpy(&ctlx->inbuf, usbin, sizeof(ctlx->inbuf));
3227
3228 switch (ctlx->state) {
3229 case CTLX_REQ_SUBMITTED:
3230 /*
3231 * We have received our response URB before
3232 * our request has been acknowledged. Odd,
3233 * but our OUT URB is still alive...
3234 */
Edgardo Hames4ffab682010-03-15 23:00:40 -03003235 pr_debug("Causality violation: please reboot Universe\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003236 ctlx->state = CTLX_RESP_COMPLETE;
3237 break;
3238
3239 case CTLX_REQ_COMPLETE:
3240 /*
3241 * This is the usual path: our request
3242 * has already been acknowledged, and
3243 * now we have received the reply too.
3244 */
3245 ctlx->state = CTLX_COMPLETE;
3246 unlocked_usbctlx_complete(hw, ctlx);
3247 run_queue = 1;
3248 break;
3249
3250 default:
3251 /*
3252 * Throw this CTLX away ...
3253 */
Avinash Kumar263b8bb2013-09-06 22:21:49 +05303254 netdev_err(hw->wlandev->netdev,
Sherif Shehab Aldin3f2d6562014-04-05 23:34:40 +02003255 "Matched IN URB, CTLX[%d] in invalid state(%s). Discarded.\n",
3256 le16_to_cpu(ctlx->outbuf.type),
3257 ctlxstr(ctlx->state));
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003258 if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0)
3259 run_queue = 1;
3260 break;
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003261 } /* switch */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003262 }
3263
3264unlock:
3265 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3266
3267 if (run_queue)
3268 hfa384x_usbctlxq_run(hw);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003269}
3270
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003271/*----------------------------------------------------------------
3272* hfa384x_usbin_txcompl
3273*
3274* At this point we have the results of a previous transmit.
3275*
3276* Arguments:
3277* wlandev wlan device
3278* usbin ptr to the usb transfer buffer
3279*
3280* Returns:
3281* nothing
3282*
3283* Side effects:
3284*
3285* Call context:
3286* interrupt
3287----------------------------------------------------------------*/
sayli karnikc9573a82016-09-18 15:11:14 +05303288static void hfa384x_usbin_txcompl(struct wlandevice *wlandev,
Sergio Paracuellos3e4180c2016-09-28 20:19:38 +02003289 union hfa384x_usbin *usbin)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003290{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003291 u16 status;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003292
Edgardo Hames631c8de2010-03-08 17:02:37 -08003293 status = le16_to_cpu(usbin->type); /* yeah I know it says type... */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003294
3295 /* Was there an error? */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003296 if (HFA384x_TXSTATUS_ISERROR(status))
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003297 prism2sta_ev_txexc(wlandev, status);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003298 else
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003299 prism2sta_ev_tx(wlandev, status);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003300}
3301
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003302/*----------------------------------------------------------------
3303* hfa384x_usbin_rx
3304*
3305* At this point we have a successful received a rx frame packet.
3306*
3307* Arguments:
3308* wlandev wlan device
3309* usbin ptr to the usb transfer buffer
3310*
3311* Returns:
3312* nothing
3313*
3314* Side effects:
3315*
3316* Call context:
3317* interrupt
3318----------------------------------------------------------------*/
sayli karnikc9573a82016-09-18 15:11:14 +05303319static void hfa384x_usbin_rx(struct wlandevice *wlandev, struct sk_buff *skb)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003320{
Sergio Paracuellos3e4180c2016-09-28 20:19:38 +02003321 union hfa384x_usbin *usbin = (union hfa384x_usbin *)skb->data;
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02003322 struct hfa384x *hw = wlandev->priv;
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003323 int hdrlen;
Edgardo Hames51e48962010-07-31 13:06:52 -03003324 struct p80211_rxmeta *rxmeta;
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003325 u16 data_len;
3326 u16 fc;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003327
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003328 /* Byte order convert once up front. */
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01003329 usbin->rxfrm.desc.status = le16_to_cpu(usbin->rxfrm.desc.status);
3330 usbin->rxfrm.desc.time = le32_to_cpu(usbin->rxfrm.desc.time);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003331
3332 /* Now handle frame based on port# */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003333 switch (HFA384x_RXSTATUS_MACPORT_GET(usbin->rxfrm.desc.status)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003334 case 0:
Moritz Muehlenhoffae262302009-01-21 22:00:45 +01003335 fc = le16_to_cpu(usbin->rxfrm.desc.frame_control);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003336
3337 /* If exclude and we receive an unencrypted, drop it */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003338 if ((wlandev->hostwep & HOSTWEP_EXCLUDEUNENCRYPTED) &&
3339 !WLAN_GET_FC_ISWEP(fc)) {
Ilja Sidoroffcc5bcbb2014-09-08 17:37:53 +03003340 break;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003341 }
3342
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01003343 data_len = le16_to_cpu(usbin->rxfrm.desc.data_len);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003344
3345 /* How much header data do we have? */
3346 hdrlen = p80211_headerlen(fc);
3347
3348 /* Pull off the descriptor */
Sergio Paracuellos70adf502016-09-28 20:19:06 +02003349 skb_pull(skb, sizeof(struct hfa384x_rx_frame));
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003350
3351 /* Now shunt the header block up against the data block
3352 * with an "overlapping" copy
3353 */
3354 memmove(skb_push(skb, hdrlen),
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003355 &usbin->rxfrm.desc.frame_control, hdrlen);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003356
3357 skb->dev = wlandev->netdev;
3358 skb->dev->last_rx = jiffies;
3359
3360 /* And set the frame length properly */
3361 skb_trim(skb, data_len + hdrlen);
3362
3363 /* The prism2 series does not return the CRC */
3364 memset(skb_put(skb, WLAN_CRC_LEN), 0xff, WLAN_CRC_LEN);
3365
3366 skb_reset_mac_header(skb);
3367
3368 /* Attach the rxmeta, set some stuff */
3369 p80211skb_rxmeta_attach(wlandev, skb);
3370 rxmeta = P80211SKB_RXMETA(skb);
3371 rxmeta->mactime = usbin->rxfrm.desc.time;
3372 rxmeta->rxrate = usbin->rxfrm.desc.rate;
3373 rxmeta->signal = usbin->rxfrm.desc.signal - hw->dbmadjust;
3374 rxmeta->noise = usbin->rxfrm.desc.silence - hw->dbmadjust;
3375
Amitoj Kaur Chawla4e2cdf92015-10-31 15:51:04 +05303376 p80211netdev_rx(wlandev, skb);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003377
3378 break;
3379
3380 case 7:
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003381 if (!HFA384x_RXSTATUS_ISFCSERR(usbin->rxfrm.desc.status)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003382 /* Copy to wlansnif skb */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003383 hfa384x_int_rxmonitor(wlandev, &usbin->rxfrm);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003384 dev_kfree_skb(skb);
3385 } else {
Mithlesh Thukral75f49e02009-05-25 19:06:16 +05303386 pr_debug("Received monitor frame: FCSerr set\n");
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003387 }
3388 break;
3389
3390 default:
Avinash Kumar263b8bb2013-09-06 22:21:49 +05303391 netdev_warn(hw->wlandev->netdev, "Received frame on unsupported port=%d\n",
Sherif Shehab Aldin3f2d6562014-04-05 23:34:40 +02003392 HFA384x_RXSTATUS_MACPORT_GET(
3393 usbin->rxfrm.desc.status));
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003394 break;
3395 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003396}
3397
3398/*----------------------------------------------------------------
3399* hfa384x_int_rxmonitor
3400*
3401* Helper function for int_rx. Handles monitor frames.
3402* Note that this function allocates space for the FCS and sets it
3403* to 0xffffffff. The hfa384x doesn't give us the FCS value but the
3404* higher layers expect it. 0xffffffff is used as a flag to indicate
3405* the FCS is bogus.
3406*
3407* Arguments:
3408* wlandev wlan device structure
3409* rxfrm rx descriptor read from card in int_rx
3410*
3411* Returns:
3412* nothing
3413*
3414* Side effects:
3415* Allocates an skb and passes it up via the PF_PACKET interface.
3416* Call context:
3417* interrupt
3418----------------------------------------------------------------*/
sayli karnikc9573a82016-09-18 15:11:14 +05303419static void hfa384x_int_rxmonitor(struct wlandevice *wlandev,
Sergio Paracuellos684b2e02016-09-28 20:19:28 +02003420 struct hfa384x_usb_rxfrm *rxfrm)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003421{
Sergio Paracuellos70adf502016-09-28 20:19:06 +02003422 struct hfa384x_rx_frame *rxdesc = &(rxfrm->desc);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003423 unsigned int hdrlen = 0;
3424 unsigned int datalen = 0;
3425 unsigned int skblen = 0;
3426 u8 *datap;
3427 u16 fc;
3428 struct sk_buff *skb;
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02003429 struct hfa384x *hw = wlandev->priv;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003430
Edgardo Hames631c8de2010-03-08 17:02:37 -08003431 /* Remember the status, time, and data_len fields are in host order */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003432 /* Figure out how big the frame is */
Moritz Muehlenhoffae262302009-01-21 22:00:45 +01003433 fc = le16_to_cpu(rxdesc->frame_control);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003434 hdrlen = p80211_headerlen(fc);
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01003435 datalen = le16_to_cpu(rxdesc->data_len);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003436
3437 /* Allocate an ind message+framesize skb */
Edgardo Hames51e48962010-07-31 13:06:52 -03003438 skblen = sizeof(struct p80211_caphdr) + hdrlen + datalen + WLAN_CRC_LEN;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003439
3440 /* sanity check the length */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003441 if (skblen >
Edgardo Hames51e48962010-07-31 13:06:52 -03003442 (sizeof(struct p80211_caphdr) +
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003443 WLAN_HDR_A4_LEN + WLAN_DATA_MAXLEN + WLAN_CRC_LEN)) {
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +01003444 pr_debug("overlen frm: len=%zd\n",
Edgardo Hames51e48962010-07-31 13:06:52 -03003445 skblen - sizeof(struct p80211_caphdr));
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003446 }
3447
Svenne Krap46800b22010-02-14 18:59:42 +01003448 skb = dev_alloc_skb(skblen);
Eva Rachel Retuyae2e77522016-02-27 20:39:25 +08003449 if (!skb)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003450 return;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003451
3452 /* only prepend the prism header if in the right mode */
3453 if ((wlandev->netdev->type == ARPHRD_IEEE80211_PRISM) &&
Solomon Peachycbec30c2008-10-29 10:42:57 -04003454 (hw->sniffhdr != 0)) {
Edgardo Hames51e48962010-07-31 13:06:52 -03003455 struct p80211_caphdr *caphdr;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003456 /* The NEW header format! */
Edgardo Hames51e48962010-07-31 13:06:52 -03003457 datap = skb_put(skb, sizeof(struct p80211_caphdr));
Sherif Shehab Aldin5d85fe32014-04-05 23:35:15 +02003458 caphdr = (struct p80211_caphdr *)datap;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003459
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003460 caphdr->version = htonl(P80211CAPTURE_VERSION);
Edgardo Hames51e48962010-07-31 13:06:52 -03003461 caphdr->length = htonl(sizeof(struct p80211_caphdr));
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003462 caphdr->mactime = __cpu_to_be64(rxdesc->time) * 1000;
3463 caphdr->hosttime = __cpu_to_be64(jiffies);
3464 caphdr->phytype = htonl(4); /* dss_dot11_b */
3465 caphdr->channel = htonl(hw->sniff_channel);
3466 caphdr->datarate = htonl(rxdesc->rate);
3467 caphdr->antenna = htonl(0); /* unknown */
3468 caphdr->priority = htonl(0); /* unknown */
3469 caphdr->ssi_type = htonl(3); /* rssi_raw */
3470 caphdr->ssi_signal = htonl(rxdesc->signal);
3471 caphdr->ssi_noise = htonl(rxdesc->silence);
3472 caphdr->preamble = htonl(0); /* unknown */
3473 caphdr->encoding = htonl(1); /* cck */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003474 }
3475
Edgardo Hames631c8de2010-03-08 17:02:37 -08003476 /* Copy the 802.11 header to the skb
3477 (ctl frames may be less than a full header) */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003478 datap = skb_put(skb, hdrlen);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003479 memcpy(datap, &(rxdesc->frame_control), hdrlen);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003480
3481 /* If any, copy the data from the card to the skb */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003482 if (datalen > 0) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003483 datap = skb_put(skb, datalen);
3484 memcpy(datap, rxfrm->data, datalen);
3485
3486 /* check for unencrypted stuff if WEP bit set. */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003487 if (*(datap - hdrlen + 1) & 0x40) /* wep set */
3488 if ((*(datap) == 0xaa) && (*(datap + 1) == 0xaa))
Edgardo Hames631c8de2010-03-08 17:02:37 -08003489 /* clear wep; it's the 802.2 header! */
3490 *(datap - hdrlen + 1) &= 0xbf;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003491 }
3492
3493 if (hw->sniff_fcs) {
3494 /* Set the FCS */
3495 datap = skb_put(skb, WLAN_CRC_LEN);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003496 memset(datap, 0xff, WLAN_CRC_LEN);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003497 }
3498
3499 /* pass it back up */
Amitoj Kaur Chawla4e2cdf92015-10-31 15:51:04 +05303500 p80211netdev_rx(wlandev, skb);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003501}
3502
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003503/*----------------------------------------------------------------
3504* hfa384x_usbin_info
3505*
3506* At this point we have a successful received a Prism2 info frame.
3507*
3508* Arguments:
3509* wlandev wlan device
3510* usbin ptr to the usb transfer buffer
3511*
3512* Returns:
3513* nothing
3514*
3515* Side effects:
3516*
3517* Call context:
3518* interrupt
3519----------------------------------------------------------------*/
Sergio Paracuellos3e4180c2016-09-28 20:19:38 +02003520static void hfa384x_usbin_info(struct wlandevice *wlandev,
3521 union hfa384x_usbin *usbin)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003522{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003523 usbin->infofrm.info.framelen =
Moritz Muehlenhoff18c7f792009-02-18 19:50:07 +01003524 le16_to_cpu(usbin->infofrm.info.framelen);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003525 prism2sta_ev_info(wlandev, &usbin->infofrm.info);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003526}
3527
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003528/*----------------------------------------------------------------
3529* hfa384x_usbout_callback
3530*
3531* Callback for URBs on the BULKOUT endpoint.
3532*
3533* Arguments:
3534* urb ptr to the completed urb
3535*
3536* Returns:
3537* nothing
3538*
3539* Side effects:
3540*
3541* Call context:
3542* interrupt
3543----------------------------------------------------------------*/
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003544static void hfa384x_usbout_callback(struct urb *urb)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003545{
sayli karnikc9573a82016-09-18 15:11:14 +05303546 struct wlandevice *wlandev = urb->context;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003547
3548#ifdef DEBUG_USB
3549 dbprint_urb(urb);
3550#endif
3551
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003552 if (wlandev && wlandev->netdev) {
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003553 switch (urb->status) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003554 case 0:
Amitoj Kaur Chawla6ba714b2015-10-31 15:47:38 +05303555 prism2sta_ev_alloc(wlandev);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003556 break;
3557
3558 case -EPIPE:
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003559 {
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02003560 struct hfa384x *hw = wlandev->priv;
Cheng-Wei Lee4d525ef2014-06-27 19:42:14 +08003561
Avinash Kumar263b8bb2013-09-06 22:21:49 +05303562 netdev_warn(hw->wlandev->netdev,
Sherif Shehab Aldin3f2d6562014-04-05 23:34:40 +02003563 "%s tx pipe stalled: requesting reset\n",
3564 wlandev->netdev->name);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003565 if (!test_and_set_bit
3566 (WORK_TX_HALT, &hw->usb_flags))
3567 schedule_work(&hw->usb_work);
Tobias Klauser9630f6b2014-07-08 08:37:00 +02003568 wlandev->netdev->stats.tx_errors++;
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003569 break;
3570 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003571
3572 case -EPROTO:
3573 case -ETIMEDOUT:
3574 case -EILSEQ:
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003575 {
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02003576 struct hfa384x *hw = wlandev->priv;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003577
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003578 if (!test_and_set_bit
Sherif Shehab Aldina3542e62014-04-05 23:34:48 +02003579 (THROTTLE_TX, &hw->usb_flags) &&
3580 !timer_pending(&hw->throttle)) {
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003581 mod_timer(&hw->throttle,
3582 jiffies + THROTTLE_JIFFIES);
3583 }
Tobias Klauser9630f6b2014-07-08 08:37:00 +02003584 wlandev->netdev->stats.tx_errors++;
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003585 netif_stop_queue(wlandev->netdev);
3586 break;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003587 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003588
3589 case -ENOENT:
3590 case -ESHUTDOWN:
3591 /* Ignorable errors */
3592 break;
3593
3594 default:
Avinash Kumar263b8bb2013-09-06 22:21:49 +05303595 netdev_info(wlandev->netdev, "unknown urb->status=%d\n",
Sherif Shehab Aldin3f2d6562014-04-05 23:34:40 +02003596 urb->status);
Tobias Klauser9630f6b2014-07-08 08:37:00 +02003597 wlandev->netdev->stats.tx_errors++;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003598 break;
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003599 } /* switch */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003600 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003601}
3602
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003603/*----------------------------------------------------------------
3604* hfa384x_ctlxout_callback
3605*
3606* Callback for control data on the BULKOUT endpoint.
3607*
3608* Arguments:
3609* urb ptr to the completed urb
3610*
3611* Returns:
3612* nothing
3613*
3614* Side effects:
3615*
3616* Call context:
3617* interrupt
3618----------------------------------------------------------------*/
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003619static void hfa384x_ctlxout_callback(struct urb *urb)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003620{
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02003621 struct hfa384x *hw = urb->context;
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003622 int delete_resptimer = 0;
3623 int timer_ok = 1;
3624 int run_queue = 0;
Sergio Paracuellosa10d36b2016-09-28 20:20:16 +02003625 struct hfa384x_usbctlx *ctlx;
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003626 unsigned long flags;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003627
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +01003628 pr_debug("urb->status=%d\n", urb->status);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003629#ifdef DEBUG_USB
3630 dbprint_urb(urb);
3631#endif
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003632 if ((urb->status == -ESHUTDOWN) ||
Nicholas Sim02e02042016-04-05 17:37:12 +01003633 (urb->status == -ENODEV) || !hw)
Devendra Naga89e63022012-09-09 18:40:54 +05303634 return;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003635
3636retry:
3637 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3638
3639 /*
3640 * Only one CTLX at a time on the "active" list, and
3641 * none at all if we are unplugged. However, we can
3642 * rely on the disconnect function to clean everything
3643 * up if someone unplugged the adapter.
3644 */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003645 if (list_empty(&hw->ctlxq.active)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003646 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
Devendra Naga89e63022012-09-09 18:40:54 +05303647 return;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003648 }
3649
3650 /*
3651 * Having something on the "active" queue means
3652 * that we have timers to worry about ...
3653 */
3654 if (del_timer(&hw->reqtimer) == 0) {
3655 if (hw->req_timer_done == 0) {
3656 /*
3657 * This timer was actually running while we
3658 * were trying to delete it. Let it terminate
3659 * gracefully instead.
3660 */
3661 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3662 goto retry;
3663 }
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003664 } else {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003665 hw->req_timer_done = 1;
3666 }
3667
3668 ctlx = get_active_ctlx(hw);
3669
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003670 if (urb->status == 0) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003671 /* Request portion of a CTLX is successful */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003672 switch (ctlx->state) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003673 case CTLX_REQ_SUBMITTED:
3674 /* This OUT-ACK received before IN */
3675 ctlx->state = CTLX_REQ_COMPLETE;
3676 break;
3677
3678 case CTLX_RESP_COMPLETE:
3679 /* IN already received before this OUT-ACK,
3680 * so this command must now be complete.
3681 */
3682 ctlx->state = CTLX_COMPLETE;
3683 unlocked_usbctlx_complete(hw, ctlx);
3684 run_queue = 1;
3685 break;
3686
3687 default:
3688 /* This is NOT a valid CTLX "success" state! */
Avinash Kumar263b8bb2013-09-06 22:21:49 +05303689 netdev_err(hw->wlandev->netdev,
Sherif Shehab Aldin3f2d6562014-04-05 23:34:40 +02003690 "Illegal CTLX[%d] success state(%s, %d) in OUT URB\n",
3691 le16_to_cpu(ctlx->outbuf.type),
3692 ctlxstr(ctlx->state), urb->status);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003693 break;
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003694 } /* switch */
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003695 } else {
3696 /* If the pipe has stalled then we need to reset it */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003697 if ((urb->status == -EPIPE) &&
3698 !test_and_set_bit(WORK_TX_HALT, &hw->usb_flags)) {
Avinash Kumar263b8bb2013-09-06 22:21:49 +05303699 netdev_warn(hw->wlandev->netdev,
Sherif Shehab Aldin3f2d6562014-04-05 23:34:40 +02003700 "%s tx pipe stalled: requesting reset\n",
3701 hw->wlandev->netdev->name);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003702 schedule_work(&hw->usb_work);
3703 }
3704
3705 /* If someone cancels the OUT URB then its status
3706 * should be either -ECONNRESET or -ENOENT.
3707 */
3708 ctlx->state = CTLX_REQ_FAILED;
3709 unlocked_usbctlx_complete(hw, ctlx);
3710 delete_resptimer = 1;
3711 run_queue = 1;
3712 }
3713
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003714delresp:
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003715 if (delete_resptimer) {
Svenne Krap46800b22010-02-14 18:59:42 +01003716 timer_ok = del_timer(&hw->resptimer);
Andrew Elwell3f4b4e72010-02-18 23:56:13 +01003717 if (timer_ok != 0)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003718 hw->resp_timer_done = 1;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003719 }
3720
3721 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3722
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003723 if (!timer_ok && (hw->resp_timer_done == 0)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003724 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3725 goto delresp;
3726 }
3727
3728 if (run_queue)
3729 hfa384x_usbctlxq_run(hw);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003730}
3731
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003732/*----------------------------------------------------------------
3733* hfa384x_usbctlx_reqtimerfn
3734*
3735* Timer response function for CTLX request timeouts. If this
3736* function is called, it means that the callback for the OUT
3737* URB containing a Prism2.x XXX_Request was never called.
3738*
3739* Arguments:
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02003740* data a ptr to the struct hfa384x
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003741*
3742* Returns:
3743* nothing
3744*
3745* Side effects:
3746*
3747* Call context:
3748* interrupt
3749----------------------------------------------------------------*/
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003750static void hfa384x_usbctlx_reqtimerfn(unsigned long data)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003751{
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02003752 struct hfa384x *hw = (struct hfa384x *)data;
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003753 unsigned long flags;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003754
3755 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3756
3757 hw->req_timer_done = 1;
3758
3759 /* Removing the hardware automatically empties
3760 * the active list ...
3761 */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003762 if (!list_empty(&hw->ctlxq.active)) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003763 /*
3764 * We must ensure that our URB is removed from
3765 * the system, if it hasn't already expired.
3766 */
3767 hw->ctlx_urb.transfer_flags |= URB_ASYNC_UNLINK;
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003768 if (usb_unlink_urb(&hw->ctlx_urb) == -EINPROGRESS) {
Sergio Paracuellosa10d36b2016-09-28 20:20:16 +02003769 struct hfa384x_usbctlx *ctlx = get_active_ctlx(hw);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003770
3771 ctlx->state = CTLX_REQ_FAILED;
3772
3773 /* This URB was active, but has now been
3774 * cancelled. It will now have a status of
3775 * -ECONNRESET in the callback function.
3776 *
3777 * We are cancelling this CTLX, so we're
3778 * not going to need to wait for a response.
3779 * The URB's callback function will check
3780 * that this timer is truly dead.
3781 */
3782 if (del_timer(&hw->resptimer) != 0)
3783 hw->resp_timer_done = 1;
3784 }
3785 }
3786
3787 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003788}
3789
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003790/*----------------------------------------------------------------
3791* hfa384x_usbctlx_resptimerfn
3792*
3793* Timer response function for CTLX response timeouts. If this
3794* function is called, it means that the callback for the IN
3795* URB containing a Prism2.x XXX_Response was never called.
3796*
3797* Arguments:
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02003798* data a ptr to the struct hfa384x
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003799*
3800* Returns:
3801* nothing
3802*
3803* Side effects:
3804*
3805* Call context:
3806* interrupt
3807----------------------------------------------------------------*/
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003808static void hfa384x_usbctlx_resptimerfn(unsigned long data)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003809{
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02003810 struct hfa384x *hw = (struct hfa384x *)data;
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003811 unsigned long flags;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003812
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003813 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3814
3815 hw->resp_timer_done = 1;
3816
3817 /* The active list will be empty if the
3818 * adapter has been unplugged ...
3819 */
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003820 if (!list_empty(&hw->ctlxq.active)) {
Sergio Paracuellosa10d36b2016-09-28 20:20:16 +02003821 struct hfa384x_usbctlx *ctlx = get_active_ctlx(hw);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003822
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003823 if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003824 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3825 hfa384x_usbctlxq_run(hw);
Devendra Naga3f514252012-09-09 18:40:53 +05303826 return;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003827 }
3828 }
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003829 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003830}
3831
3832/*----------------------------------------------------------------
3833* hfa384x_usb_throttlefn
3834*
3835*
3836* Arguments:
3837* data ptr to hw
3838*
3839* Returns:
3840* Nothing
3841*
3842* Side effects:
3843*
3844* Call context:
3845* Interrupt
3846----------------------------------------------------------------*/
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003847static void hfa384x_usb_throttlefn(unsigned long data)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003848{
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02003849 struct hfa384x *hw = (struct hfa384x *)data;
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003850 unsigned long flags;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003851
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003852 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3853
3854 /*
3855 * We need to check BOTH the RX and the TX throttle controls,
3856 * so we use the bitwise OR instead of the logical OR.
3857 */
Moritz Muehlenhoffa7cf7ba2009-02-08 02:01:00 +01003858 pr_debug("flags=0x%lx\n", hw->usb_flags);
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003859 if (!hw->wlandev->hwremoved &&
3860 ((test_and_clear_bit(THROTTLE_RX, &hw->usb_flags) &&
Bogicevic Sasa6c37e1f2015-12-14 06:25:59 -08003861 !test_and_set_bit(WORK_RX_RESUME, &hw->usb_flags)) |
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003862 (test_and_clear_bit(THROTTLE_TX, &hw->usb_flags) &&
3863 !test_and_set_bit(WORK_TX_RESUME, &hw->usb_flags))
3864 )) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003865 schedule_work(&hw->usb_work);
3866 }
3867
3868 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003869}
3870
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003871/*----------------------------------------------------------------
3872* hfa384x_usbctlx_submit
3873*
3874* Called from the doxxx functions to submit a CTLX to the queue
3875*
3876* Arguments:
3877* hw ptr to the hw struct
3878* ctlx ctlx structure to enqueue
3879*
3880* Returns:
3881* -ENODEV if the adapter is unplugged
3882* 0
3883*
3884* Side effects:
3885*
3886* Call context:
3887* process or interrupt
3888----------------------------------------------------------------*/
Sergio Paracuellos5a2214e2016-09-28 20:20:19 +02003889static int hfa384x_usbctlx_submit(struct hfa384x *hw, struct hfa384x_usbctlx *ctlx)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003890{
3891 unsigned long flags;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003892
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003893 spin_lock_irqsave(&hw->ctlxq.lock, flags);
3894
3895 if (hw->wlandev->hwremoved) {
3896 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
Devendra Naga675be122012-09-13 15:00:54 +05303897 return -ENODEV;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003898 }
3899
Devendra Naga675be122012-09-13 15:00:54 +05303900 ctlx->state = CTLX_PENDING;
3901 list_add_tail(&ctlx->list, &hw->ctlxq.pending);
3902 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
3903 hfa384x_usbctlxq_run(hw);
3904
3905 return 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003906}
3907
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003908/*----------------------------------------------------------------
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003909* hfa384x_isgood_pdrcore
3910*
3911* Quick check of PDR codes.
3912*
3913* Arguments:
3914* pdrcode PDR code number (host order)
3915*
3916* Returns:
3917* zero not good.
3918* one is good.
3919*
3920* Side effects:
3921*
3922* Call context:
3923----------------------------------------------------------------*/
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003924static int hfa384x_isgood_pdrcode(u16 pdrcode)
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003925{
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003926 switch (pdrcode) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003927 case HFA384x_PDR_END_OF_PDA:
3928 case HFA384x_PDR_PCB_PARTNUM:
3929 case HFA384x_PDR_PDAVER:
3930 case HFA384x_PDR_NIC_SERIAL:
3931 case HFA384x_PDR_MKK_MEASUREMENTS:
3932 case HFA384x_PDR_NIC_RAMSIZE:
3933 case HFA384x_PDR_MFISUPRANGE:
3934 case HFA384x_PDR_CFISUPRANGE:
3935 case HFA384x_PDR_NICID:
3936 case HFA384x_PDR_MAC_ADDRESS:
3937 case HFA384x_PDR_REGDOMAIN:
3938 case HFA384x_PDR_ALLOWED_CHANNEL:
3939 case HFA384x_PDR_DEFAULT_CHANNEL:
3940 case HFA384x_PDR_TEMPTYPE:
3941 case HFA384x_PDR_IFR_SETTING:
3942 case HFA384x_PDR_RFR_SETTING:
3943 case HFA384x_PDR_HFA3861_BASELINE:
3944 case HFA384x_PDR_HFA3861_SHADOW:
3945 case HFA384x_PDR_HFA3861_IFRF:
3946 case HFA384x_PDR_HFA3861_CHCALSP:
3947 case HFA384x_PDR_HFA3861_CHCALI:
3948 case HFA384x_PDR_3842_NIC_CONFIG:
3949 case HFA384x_PDR_USB_ID:
3950 case HFA384x_PDR_PCI_ID:
3951 case HFA384x_PDR_PCI_IFCONF:
3952 case HFA384x_PDR_PCI_PMCONF:
3953 case HFA384x_PDR_RFENRGY:
3954 case HFA384x_PDR_HFA3861_MANF_TESTSP:
3955 case HFA384x_PDR_HFA3861_MANF_TESTI:
3956 /* code is OK */
3957 return 1;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003958 default:
Moritz Muehlenhoff21dc0f82009-02-08 02:21:00 +01003959 if (pdrcode < 0x1000) {
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003960 /* code is OK, but we don't know exactly what it is */
Sherif Shehab Aldina2120132014-04-05 23:33:16 +02003961 pr_debug("Encountered unknown PDR#=0x%04x, assuming it's ok.\n",
3962 pdrcode);
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003963 return 1;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003964 }
Eduardo Barretto81980c12014-12-19 23:34:33 -02003965 break;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003966 }
Eduardo Barretto81980c12014-12-19 23:34:33 -02003967 /* bad code */
3968 pr_debug("Encountered unknown PDR#=0x%04x, (>=0x1000), assuming it's bad.\n",
3969 pdrcode);
3970 return 0;
Greg Kroah-Hartman00b3ed12008-10-02 11:29:28 -07003971}