Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1 | /* src/prism2/driver/hfa384x_usb.c |
| 2 | * |
| 3 | * Functions that talk to the USB variantof the Intersil hfa384x MAC |
| 4 | * |
| 5 | * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved. |
| 6 | * -------------------------------------------------------------------- |
| 7 | * |
| 8 | * linux-wlan |
| 9 | * |
| 10 | * The contents of this file are subject to the Mozilla Public |
| 11 | * License Version 1.1 (the "License"); you may not use this file |
| 12 | * except in compliance with the License. You may obtain a copy of |
| 13 | * the License at http://www.mozilla.org/MPL/ |
| 14 | * |
| 15 | * Software distributed under the License is distributed on an "AS |
| 16 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or |
| 17 | * implied. See the License for the specific language governing |
| 18 | * rights and limitations under the License. |
| 19 | * |
| 20 | * Alternatively, the contents of this file may be used under the |
| 21 | * terms of the GNU Public License version 2 (the "GPL"), in which |
| 22 | * case the provisions of the GPL are applicable instead of the |
| 23 | * above. If you wish to allow the use of your version of this file |
| 24 | * only under the terms of the GPL and not to allow others to use |
| 25 | * your version of this file under the MPL, indicate your decision |
| 26 | * by deleting the provisions above and replace them with the notice |
| 27 | * and other provisions required by the GPL. If you do not delete |
| 28 | * the provisions above, a recipient may use your version of this |
| 29 | * file under either the MPL or the GPL. |
| 30 | * |
| 31 | * -------------------------------------------------------------------- |
| 32 | * |
| 33 | * Inquiries regarding the linux-wlan Open Source project can be |
| 34 | * made directly to: |
| 35 | * |
| 36 | * AbsoluteValue Systems Inc. |
| 37 | * info@linux-wlan.com |
| 38 | * http://www.linux-wlan.com |
| 39 | * |
| 40 | * -------------------------------------------------------------------- |
| 41 | * |
| 42 | * Portions of the development of this software were funded by |
| 43 | * Intersil Corporation as part of PRISM(R) chipset product development. |
| 44 | * |
| 45 | * -------------------------------------------------------------------- |
| 46 | * |
| 47 | * This file implements functions that correspond to the prism2/hfa384x |
| 48 | * 802.11 MAC hardware and firmware host interface. |
| 49 | * |
| 50 | * The functions can be considered to represent several levels of |
| 51 | * abstraction. The lowest level functions are simply C-callable wrappers |
| 52 | * around the register accesses. The next higher level represents C-callable |
| 53 | * prism2 API functions that match the Intersil documentation as closely |
| 54 | * as is reasonable. The next higher layer implements common sequences |
Adam Buchbinder | 3fc0d27 | 2009-12-18 15:43:52 -0500 | [diff] [blame] | 55 | * of invocations of the API layer (e.g. write to bap, followed by cmd). |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 56 | * |
| 57 | * Common sequences: |
| 58 | * hfa384x_drvr_xxx Highest level abstractions provided by the |
| 59 | * hfa384x code. They are driver defined wrappers |
| 60 | * for common sequences. These functions generally |
| 61 | * use the services of the lower levels. |
| 62 | * |
| 63 | * hfa384x_drvr_xxxconfig An example of the drvr level abstraction. These |
| 64 | * functions are wrappers for the RID get/set |
Edgardo Hames | 631c8de | 2010-03-08 17:02:37 -0800 | [diff] [blame] | 65 | * sequence. They call copy_[to|from]_bap() and |
| 66 | * cmd_access(). These functions operate on the |
| 67 | * RIDs and buffers without validation. The caller |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 68 | * is responsible for that. |
| 69 | * |
| 70 | * API wrapper functions: |
| 71 | * hfa384x_cmd_xxx functions that provide access to the f/w commands. |
| 72 | * The function arguments correspond to each command |
| 73 | * argument, even command arguments that get packed |
| 74 | * into single registers. These functions _just_ |
| 75 | * issue the command by setting the cmd/parm regs |
| 76 | * & reading the status/resp regs. Additional |
| 77 | * activities required to fully use a command |
| 78 | * (read/write from/to bap, get/set int status etc.) |
| 79 | * are implemented separately. Think of these as |
| 80 | * C-callable prism2 commands. |
| 81 | * |
| 82 | * Lowest Layer Functions: |
| 83 | * hfa384x_docmd_xxx These functions implement the sequence required |
| 84 | * to issue any prism2 command. Primarily used by the |
| 85 | * hfa384x_cmd_xxx functions. |
| 86 | * |
| 87 | * hfa384x_bap_xxx BAP read/write access functions. |
| 88 | * Note: we usually use BAP0 for non-interrupt context |
| 89 | * and BAP1 for interrupt context. |
| 90 | * |
| 91 | * hfa384x_dl_xxx download related functions. |
| 92 | * |
| 93 | * Driver State Issues: |
| 94 | * Note that there are two pairs of functions that manage the |
| 95 | * 'initialized' and 'running' states of the hw/MAC combo. The four |
| 96 | * functions are create(), destroy(), start(), and stop(). create() |
| 97 | * sets up the data structures required to support the hfa384x_* |
| 98 | * functions and destroy() cleans them up. The start() function gets |
| 99 | * the actual hardware running and enables the interrupts. The stop() |
| 100 | * function shuts the hardware down. The sequence should be: |
| 101 | * create() |
| 102 | * start() |
| 103 | * . |
| 104 | * . Do interesting things w/ the hardware |
| 105 | * . |
| 106 | * stop() |
| 107 | * destroy() |
| 108 | * |
| 109 | * Note that destroy() can be called without calling stop() first. |
| 110 | * -------------------------------------------------------------------- |
| 111 | */ |
| 112 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 113 | #include <linux/module.h> |
| 114 | #include <linux/kernel.h> |
| 115 | #include <linux/sched.h> |
| 116 | #include <linux/types.h> |
| 117 | #include <linux/slab.h> |
| 118 | #include <linux/wireless.h> |
| 119 | #include <linux/netdevice.h> |
| 120 | #include <linux/timer.h> |
Andrew Elwell | ef1a0ed | 2010-02-18 23:56:12 +0100 | [diff] [blame] | 121 | #include <linux/io.h> |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 122 | #include <linux/delay.h> |
| 123 | #include <asm/byteorder.h> |
Andrew Elwell | ef1a0ed | 2010-02-18 23:56:12 +0100 | [diff] [blame] | 124 | #include <linux/bitops.h> |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 125 | #include <linux/list.h> |
| 126 | #include <linux/usb.h> |
Moritz Muehlenhoff | ae26230 | 2009-01-21 22:00:45 +0100 | [diff] [blame] | 127 | #include <linux/byteorder/generic.h> |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 128 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 129 | #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 Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 141 | enum cmd_mode { |
| 142 | DOWAIT = 0, |
| 143 | DOASYNC |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 144 | }; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 145 | |
Bogicevic Sasa | 6c37e1f | 2015-12-14 06:25:59 -0800 | [diff] [blame] | 146 | #define THROTTLE_JIFFIES (HZ / 8) |
Moritz Muehlenhoff | 2d200d9 | 2009-01-25 21:54:56 +0100 | [diff] [blame] | 147 | #define URB_ASYNC_UNLINK 0 |
| 148 | #define USB_QUEUE_BULK 0 |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 149 | |
Bogicevic Sasa | 6c37e1f | 2015-12-14 06:25:59 -0800 | [diff] [blame] | 150 | #define ROUNDUP64(a) (((a) + 63) & ~63) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 151 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 152 | #ifdef DEBUG_USB |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 153 | static void dbprint_urb(struct urb *urb); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 154 | #endif |
| 155 | |
| 156 | static void |
Sergio Paracuellos | 684b2e0 | 2016-09-28 20:19:28 +0200 | [diff] [blame] | 157 | hfa384x_int_rxmonitor(struct wlandevice *wlandev, struct hfa384x_usb_rxfrm *rxfrm); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 158 | |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 159 | static void hfa384x_usb_defer(struct work_struct *data); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 160 | |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 161 | static int submit_rx_urb(struct hfa384x *hw, gfp_t flags); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 162 | |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 163 | static int submit_tx_urb(struct hfa384x *hw, struct urb *tx_urb, gfp_t flags); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 164 | |
| 165 | /*---------------------------------------------------*/ |
| 166 | /* Callbacks */ |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 167 | static void hfa384x_usbout_callback(struct urb *urb); |
| 168 | static void hfa384x_ctlxout_callback(struct urb *urb); |
| 169 | static void hfa384x_usbin_callback(struct urb *urb); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 170 | |
| 171 | static void |
Sergio Paracuellos | 3e4180c | 2016-09-28 20:19:38 +0200 | [diff] [blame] | 172 | hfa384x_usbin_txcompl(struct wlandevice *wlandev, union hfa384x_usbin *usbin); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 173 | |
sayli karnik | c9573a8 | 2016-09-18 15:11:14 +0530 | [diff] [blame] | 174 | static void hfa384x_usbin_rx(struct wlandevice *wlandev, struct sk_buff *skb); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 175 | |
Sergio Paracuellos | 3e4180c | 2016-09-28 20:19:38 +0200 | [diff] [blame] | 176 | static void hfa384x_usbin_info(struct wlandevice *wlandev, union hfa384x_usbin *usbin); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 177 | |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 178 | static void hfa384x_usbin_ctlx(struct hfa384x *hw, union hfa384x_usbin *usbin, |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 179 | int urb_status); |
| 180 | |
| 181 | /*---------------------------------------------------*/ |
| 182 | /* Functions to support the prism2 usb command queue */ |
| 183 | |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 184 | static void hfa384x_usbctlxq_run(struct hfa384x *hw); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 185 | |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 186 | static void hfa384x_usbctlx_reqtimerfn(unsigned long data); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 187 | |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 188 | static void hfa384x_usbctlx_resptimerfn(unsigned long data); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 189 | |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 190 | static void hfa384x_usb_throttlefn(unsigned long data); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 191 | |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 192 | static void hfa384x_usbctlx_completion_task(unsigned long data); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 193 | |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 194 | static void hfa384x_usbctlx_reaper_task(unsigned long data); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 195 | |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 196 | static int hfa384x_usbctlx_submit(struct hfa384x *hw, struct hfa384x_usbctlx *ctlx); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 197 | |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 198 | static void unlocked_usbctlx_complete(struct hfa384x *hw, struct hfa384x_usbctlx *ctlx); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 199 | |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 200 | struct usbctlx_completor { |
Sherif Shehab Aldin | 83f9168 | 2014-04-05 23:34:12 +0200 | [diff] [blame] | 201 | int (*complete)(struct usbctlx_completor *); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 202 | }; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 203 | |
| 204 | static int |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 205 | hfa384x_usbctlx_complete_sync(struct hfa384x *hw, |
Sergio Paracuellos | a10d36b | 2016-09-28 20:20:16 +0200 | [diff] [blame] | 206 | struct hfa384x_usbctlx *ctlx, |
Edgardo Hames | 631c8de | 2010-03-08 17:02:37 -0800 | [diff] [blame] | 207 | struct usbctlx_completor *completor); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 208 | |
| 209 | static int |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 210 | unlocked_usbctlx_cancel_async(struct hfa384x *hw, struct hfa384x_usbctlx *ctlx); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 211 | |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 212 | static void hfa384x_cb_status(struct hfa384x *hw, const struct hfa384x_usbctlx *ctlx); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 213 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 214 | static int |
Sergio Paracuellos | 385a79d | 2016-09-28 20:19:30 +0200 | [diff] [blame] | 215 | usbctlx_get_status(const struct hfa384x_usb_statusresp *cmdresp, |
Sergio Paracuellos | 501f5f9 | 2016-09-28 20:20:14 +0200 | [diff] [blame] | 216 | struct hfa384x_cmdresult *result); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 217 | |
| 218 | static void |
Sergio Paracuellos | a988c9f | 2016-09-28 20:19:32 +0200 | [diff] [blame] | 219 | usbctlx_get_rridresult(const struct hfa384x_usb_rridresp *rridresp, |
Sergio Paracuellos | b3fd890 | 2016-09-28 20:20:15 +0200 | [diff] [blame] | 220 | struct hfa384x_rridresult *result); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 221 | |
| 222 | /*---------------------------------------------------*/ |
| 223 | /* Low level req/resp CTLX formatters and submitters */ |
| 224 | static int |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 225 | hfa384x_docmd(struct hfa384x *hw, |
Edgardo Hames | 631c8de | 2010-03-08 17:02:37 -0800 | [diff] [blame] | 226 | enum cmd_mode mode, |
Sergio Paracuellos | e2f503c | 2016-09-28 20:20:18 +0200 | [diff] [blame] | 227 | struct hfa384x_metacmd *cmd, |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 228 | ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 229 | |
| 230 | static int |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 231 | hfa384x_dorrid(struct hfa384x *hw, |
Edgardo Hames | 631c8de | 2010-03-08 17:02:37 -0800 | [diff] [blame] | 232 | enum cmd_mode mode, |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 233 | u16 rid, |
| 234 | void *riddata, |
| 235 | unsigned int riddatalen, |
| 236 | ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 237 | |
| 238 | static int |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 239 | hfa384x_dowrid(struct hfa384x *hw, |
Edgardo Hames | 631c8de | 2010-03-08 17:02:37 -0800 | [diff] [blame] | 240 | enum cmd_mode mode, |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 241 | u16 rid, |
| 242 | void *riddata, |
| 243 | unsigned int riddatalen, |
| 244 | ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 245 | |
| 246 | static int |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 247 | hfa384x_dormem(struct hfa384x *hw, |
Edgardo Hames | 631c8de | 2010-03-08 17:02:37 -0800 | [diff] [blame] | 248 | enum cmd_mode mode, |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 249 | 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-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 254 | |
| 255 | static int |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 256 | hfa384x_dowmem(struct hfa384x *hw, |
Edgardo Hames | 631c8de | 2010-03-08 17:02:37 -0800 | [diff] [blame] | 257 | enum cmd_mode mode, |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 258 | 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-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 263 | |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 264 | static int hfa384x_isgood_pdrcode(u16 pdrcode); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 265 | |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 266 | static inline const char *ctlxstr(CTLX_STATE s) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 267 | { |
Sherif Shehab Aldin | d6ae4a9 | 2014-04-05 23:34:01 +0200 | [diff] [blame] | 268 | static const char * const ctlx_str[] = { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 269 | "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 Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 281 | static inline struct hfa384x_usbctlx *get_active_ctlx(struct hfa384x *hw) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 282 | { |
Sergio Paracuellos | a10d36b | 2016-09-28 20:20:16 +0200 | [diff] [blame] | 283 | return list_entry(hw->ctlxq.active.next, struct hfa384x_usbctlx, list); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 284 | } |
| 285 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 286 | #ifdef DEBUG_USB |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 287 | void dbprint_urb(struct urb *urb) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 288 | { |
Moritz Muehlenhoff | a7cf7ba | 2009-02-08 02:01:00 +0100 | [diff] [blame] | 289 | 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 Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 292 | pr_debug("urb->transfer_buffer=0x%08x\n", |
Mithlesh Thukral | 75f49e0 | 2009-05-25 19:06:16 +0530 | [diff] [blame] | 293 | (unsigned int)urb->transfer_buffer); |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 294 | pr_debug("urb->transfer_buffer_length=0x%08x\n", |
Mithlesh Thukral | 75f49e0 | 2009-05-25 19:06:16 +0530 | [diff] [blame] | 295 | urb->transfer_buffer_length); |
Moritz Muehlenhoff | a7cf7ba | 2009-02-08 02:01:00 +0100 | [diff] [blame] | 296 | pr_debug("urb->actual_length=0x%08x\n", urb->actual_length); |
| 297 | pr_debug("urb->bandwidth=0x%08x\n", urb->bandwidth); |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 298 | pr_debug("urb->setup_packet(ctl)=0x%08x\n", |
Mithlesh Thukral | 75f49e0 | 2009-05-25 19:06:16 +0530 | [diff] [blame] | 299 | (unsigned int)urb->setup_packet); |
| 300 | pr_debug("urb->start_frame(iso/irq)=0x%08x\n", urb->start_frame); |
Moritz Muehlenhoff | a7cf7ba | 2009-02-08 02:01:00 +0100 | [diff] [blame] | 301 | 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 Thukral | 75f49e0 | 2009-05-25 19:06:16 +0530 | [diff] [blame] | 305 | pr_debug("urb->complete=0x%08x\n", (unsigned int)urb->complete); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 306 | } |
| 307 | #endif |
| 308 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 309 | /*---------------------------------------------------------------- |
| 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 Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 325 | static int submit_rx_urb(struct hfa384x *hw, gfp_t memflags) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 326 | { |
| 327 | struct sk_buff *skb; |
| 328 | int result; |
| 329 | |
Sergio Paracuellos | 3e4180c | 2016-09-28 20:19:38 +0200 | [diff] [blame] | 330 | skb = dev_alloc_skb(sizeof(union hfa384x_usbin)); |
Eva Rachel Retuya | e2e7752 | 2016-02-27 20:39:25 +0800 | [diff] [blame] | 331 | if (!skb) { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 332 | result = -ENOMEM; |
| 333 | goto done; |
| 334 | } |
| 335 | |
| 336 | /* Post the IN urb */ |
| 337 | usb_fill_bulk_urb(&hw->rx_urb, hw->usb, |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 338 | hw->endp_in, |
Sergio Paracuellos | 3e4180c | 2016-09-28 20:19:38 +0200 | [diff] [blame] | 339 | skb->data, sizeof(union hfa384x_usbin), |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 340 | hfa384x_usbin_callback, hw->wlandev); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 341 | |
| 342 | hw->rx_urb_skb = skb; |
| 343 | |
| 344 | result = -ENOLINK; |
Edgardo Hames | 631c8de | 2010-03-08 17:02:37 -0800 | [diff] [blame] | 345 | if (!hw->wlandev->hwremoved && |
Sherif Shehab Aldin | 3f2d656 | 2014-04-05 23:34:40 +0200 | [diff] [blame] | 346 | !test_bit(WORK_RX_HALT, &hw->usb_flags)) { |
Amitoj Kaur Chawla | 5850c25 | 2016-02-24 21:55:49 +0530 | [diff] [blame] | 347 | result = usb_submit_urb(&hw->rx_urb, memflags); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 348 | |
| 349 | /* Check whether we need to reset the RX pipe */ |
| 350 | if (result == -EPIPE) { |
Avinash Kumar | 263b8bb | 2013-09-06 22:21:49 +0530 | [diff] [blame] | 351 | netdev_warn(hw->wlandev->netdev, |
Sherif Shehab Aldin | 3f2d656 | 2014-04-05 23:34:40 +0200 | [diff] [blame] | 352 | "%s rx pipe stalled: requesting reset\n", |
| 353 | hw->wlandev->netdev->name); |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 354 | if (!test_and_set_bit(WORK_RX_HALT, &hw->usb_flags)) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 355 | 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 Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 365 | done: |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 366 | 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 Iida | 1a6dfce | 2014-12-01 00:29:00 +0900 | [diff] [blame] | 378 | * tx_urb URB of data for transmission |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 379 | * memflags memory allocation flags |
| 380 | * |
| 381 | * Returns: |
| 382 | * error code from submission |
| 383 | * |
| 384 | * Call context: |
| 385 | * Any |
| 386 | ----------------------------------------------------------------*/ |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 387 | static int submit_tx_urb(struct hfa384x *hw, struct urb *tx_urb, gfp_t memflags) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 388 | { |
| 389 | struct net_device *netdev = hw->wlandev->netdev; |
| 390 | int result; |
| 391 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 392 | result = -ENOLINK; |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 393 | if (netif_running(netdev)) { |
Sherif Shehab Aldin | a3542e6 | 2014-04-05 23:34:48 +0200 | [diff] [blame] | 394 | if (!hw->wlandev->hwremoved && |
| 395 | !test_bit(WORK_TX_HALT, &hw->usb_flags)) { |
Amitoj Kaur Chawla | 5850c25 | 2016-02-24 21:55:49 +0530 | [diff] [blame] | 396 | result = usb_submit_urb(tx_urb, memflags); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 397 | |
| 398 | /* Test whether we need to reset the TX pipe */ |
| 399 | if (result == -EPIPE) { |
Avinash Kumar | 263b8bb | 2013-09-06 22:21:49 +0530 | [diff] [blame] | 400 | netdev_warn(hw->wlandev->netdev, |
Sherif Shehab Aldin | 3f2d656 | 2014-04-05 23:34:40 +0200 | [diff] [blame] | 401 | "%s tx pipe stalled: requesting reset\n", |
| 402 | netdev->name); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 403 | 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-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 411 | 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 Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 430 | static void hfa384x_usb_defer(struct work_struct *data) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 431 | { |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 432 | struct hfa384x *hw = container_of(data, struct hfa384x, usb_work); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 433 | struct net_device *netdev = hw->wlandev->netdev; |
| 434 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 435 | /* Don't bother trying to reset anything if the plug |
| 436 | * has been pulled ... |
| 437 | */ |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 438 | if (hw->wlandev->hwremoved) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 439 | return; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 440 | |
| 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 Hames | 631c8de | 2010-03-08 17:02:37 -0800 | [diff] [blame] | 445 | usb_kill_urb(&hw->rx_urb); /* Cannot be holding spinlock! */ |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 446 | |
| 447 | ret = usb_clear_halt(hw->usb, hw->endp_in); |
| 448 | if (ret != 0) { |
Avinash Kumar | 263b8bb | 2013-09-06 22:21:49 +0530 | [diff] [blame] | 449 | netdev_err(hw->wlandev->netdev, |
Sherif Shehab Aldin | 3f2d656 | 2014-04-05 23:34:40 +0200 | [diff] [blame] | 450 | "Failed to clear rx pipe for %s: err=%d\n", |
| 451 | netdev->name, ret); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 452 | } else { |
Avinash Kumar | 263b8bb | 2013-09-06 22:21:49 +0530 | [diff] [blame] | 453 | netdev_info(hw->wlandev->netdev, "%s rx pipe reset complete.\n", |
Sherif Shehab Aldin | 3f2d656 | 2014-04-05 23:34:40 +0200 | [diff] [blame] | 454 | netdev->name); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 455 | 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 Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 461 | if (test_bit(WORK_RX_RESUME, &hw->usb_flags)) { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 462 | int ret; |
| 463 | |
| 464 | ret = submit_rx_urb(hw, GFP_KERNEL); |
| 465 | if (ret != 0) { |
Avinash Kumar | 263b8bb | 2013-09-06 22:21:49 +0530 | [diff] [blame] | 466 | netdev_err(hw->wlandev->netdev, |
Sherif Shehab Aldin | 3f2d656 | 2014-04-05 23:34:40 +0200 | [diff] [blame] | 467 | "Failed to resume %s rx pipe.\n", |
| 468 | netdev->name); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 469 | } 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 Kumar | 263b8bb | 2013-09-06 22:21:49 +0530 | [diff] [blame] | 481 | netdev_err(hw->wlandev->netdev, |
Sherif Shehab Aldin | 3f2d656 | 2014-04-05 23:34:40 +0200 | [diff] [blame] | 482 | "Failed to clear tx pipe for %s: err=%d\n", |
| 483 | netdev->name, ret); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 484 | } else { |
Avinash Kumar | 263b8bb | 2013-09-06 22:21:49 +0530 | [diff] [blame] | 485 | netdev_info(hw->wlandev->netdev, "%s tx pipe reset complete.\n", |
Sherif Shehab Aldin | 3f2d656 | 2014-04-05 23:34:40 +0200 | [diff] [blame] | 486 | netdev->name); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 487 | 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 Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 499 | if (test_and_clear_bit(WORK_TX_RESUME, &hw->usb_flags)) |
Solomon Peachy | cbec30c | 2008-10-29 10:42:57 -0400 | [diff] [blame] | 500 | netif_wake_queue(hw->wlandev->netdev); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 501 | } |
| 502 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 503 | /*---------------------------------------------------------------- |
| 504 | * hfa384x_create |
| 505 | * |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 506 | * Sets up the struct hfa384x data structure for use. Note this |
Uwe Kleine-König | 9b0131c | 2010-09-01 15:40:25 +0200 | [diff] [blame] | 507 | * does _not_ initialize the actual hardware, just the data structures |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 508 | * 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 Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 524 | void hfa384x_create(struct hfa384x *hw, struct usb_device *usb) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 525 | { |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 526 | memset(hw, 0, sizeof(struct hfa384x)); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 527 | 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 Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 547 | hfa384x_usbctlx_reaper_task, (unsigned long)hw); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 548 | tasklet_init(&hw->completion_bh, |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 549 | hfa384x_usbctlx_completion_task, (unsigned long)hw); |
Solomon Peachy | 575a8a5 | 2008-10-29 10:42:54 -0400 | [diff] [blame] | 550 | INIT_WORK(&hw->link_bh, prism2sta_processing_defer); |
| 551 | INIT_WORK(&hw->usb_work, hfa384x_usb_defer); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 552 | |
Aya Mahfouz | 2f83aed | 2015-02-19 07:55:43 +0200 | [diff] [blame] | 553 | setup_timer(&hw->throttle, hfa384x_usb_throttlefn, (unsigned long)hw); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 554 | |
Aya Mahfouz | 2f83aed | 2015-02-19 07:55:43 +0200 | [diff] [blame] | 555 | setup_timer(&hw->resptimer, hfa384x_usbctlx_resptimerfn, |
| 556 | (unsigned long)hw); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 557 | |
Aya Mahfouz | 2f83aed | 2015-02-19 07:55:43 +0200 | [diff] [blame] | 558 | setup_timer(&hw->reqtimer, hfa384x_usbctlx_reqtimerfn, |
| 559 | (unsigned long)hw); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 560 | |
| 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 Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 568 | INIT_WORK(&hw->commsqual_bh, prism2sta_commsqual_defer); |
Aya Mahfouz | 2f83aed | 2015-02-19 07:55:43 +0200 | [diff] [blame] | 569 | setup_timer(&hw->commsqual_timer, prism2sta_commsqual_timer, |
| 570 | (unsigned long)hw); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 571 | } |
| 572 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 573 | /*---------------------------------------------------------------- |
| 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 Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 595 | void hfa384x_destroy(struct hfa384x *hw) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 596 | { |
| 597 | struct sk_buff *skb; |
| 598 | |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 599 | if (hw->state == HFA384x_STATE_RUNNING) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 600 | hfa384x_drvr_stop(hw); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 601 | hw->state = HFA384x_STATE_PREINIT; |
| 602 | |
Ilia Mirkin | a6f9c48 | 2011-03-13 00:29:17 -0500 | [diff] [blame] | 603 | kfree(hw->scanresults); |
| 604 | hw->scanresults = NULL; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 605 | |
| 606 | /* Now to clean out the auth queue */ |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 607 | while ((skb = skb_dequeue(&hw->authq))) |
| 608 | dev_kfree_skb(skb); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 609 | } |
| 610 | |
Sergio Paracuellos | a10d36b | 2016-09-28 20:20:16 +0200 | [diff] [blame] | 611 | static struct hfa384x_usbctlx *usbctlx_alloc(void) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 612 | { |
Sergio Paracuellos | a10d36b | 2016-09-28 20:20:16 +0200 | [diff] [blame] | 613 | struct hfa384x_usbctlx *ctlx; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 614 | |
Navya Sri Nizamkari | d0edf4b | 2015-03-10 17:55:40 +0530 | [diff] [blame] | 615 | ctlx = kzalloc(sizeof(*ctlx), |
| 616 | in_interrupt() ? GFP_ATOMIC : GFP_KERNEL); |
Nicholas Sim | 02e0204 | 2016-04-05 17:37:12 +0100 | [diff] [blame] | 617 | if (ctlx) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 618 | init_completion(&ctlx->done); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 619 | |
| 620 | return ctlx; |
| 621 | } |
| 622 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 623 | static int |
Sergio Paracuellos | 385a79d | 2016-09-28 20:19:30 +0200 | [diff] [blame] | 624 | usbctlx_get_status(const struct hfa384x_usb_statusresp *cmdresp, |
Sergio Paracuellos | 501f5f9 | 2016-09-28 20:20:14 +0200 | [diff] [blame] | 625 | struct hfa384x_cmdresult *result) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 626 | { |
Moritz Muehlenhoff | 18c7f79 | 2009-02-18 19:50:07 +0100 | [diff] [blame] | 627 | 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-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 631 | |
Sherif Shehab Aldin | a212013 | 2014-04-05 23:33:16 +0200 | [diff] [blame] | 632 | pr_debug("cmdresult:status=0x%04x resp0=0x%04x resp1=0x%04x resp2=0x%04x\n", |
Mithlesh Thukral | 75f49e0 | 2009-05-25 19:06:16 +0530 | [diff] [blame] | 633 | result->status, result->resp0, result->resp1, result->resp2); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 634 | |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 635 | return result->status & HFA384x_STATUS_RESULT; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | static void |
Sergio Paracuellos | a988c9f | 2016-09-28 20:19:32 +0200 | [diff] [blame] | 639 | usbctlx_get_rridresult(const struct hfa384x_usb_rridresp *rridresp, |
Sergio Paracuellos | b3fd890 | 2016-09-28 20:20:15 +0200 | [diff] [blame] | 640 | struct hfa384x_rridresult *result) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 641 | { |
Moritz Muehlenhoff | 18c7f79 | 2009-02-18 19:50:07 +0100 | [diff] [blame] | 642 | result->rid = le16_to_cpu(rridresp->rid); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 643 | result->riddata = rridresp->data; |
Moritz Muehlenhoff | 18c7f79 | 2009-02-18 19:50:07 +0100 | [diff] [blame] | 644 | result->riddata_len = ((le16_to_cpu(rridresp->frmlen) - 1) * 2); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 645 | } |
| 646 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 647 | /*---------------------------------------------------------------- |
| 648 | * Completor object: |
| 649 | * This completor must be passed to hfa384x_usbctlx_complete_sync() |
Sergio Paracuellos | 501f5f9 | 2016-09-28 20:20:14 +0200 | [diff] [blame] | 650 | * when processing a CTLX that returns a struct hfa384x_cmdresult structure. |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 651 | ----------------------------------------------------------------*/ |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 652 | struct usbctlx_cmd_completor { |
Edgardo Hames | 631c8de | 2010-03-08 17:02:37 -0800 | [diff] [blame] | 653 | struct usbctlx_completor head; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 654 | |
Sergio Paracuellos | 385a79d | 2016-09-28 20:19:30 +0200 | [diff] [blame] | 655 | const struct hfa384x_usb_statusresp *cmdresp; |
Sergio Paracuellos | 501f5f9 | 2016-09-28 20:20:14 +0200 | [diff] [blame] | 656 | struct hfa384x_cmdresult *result; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 657 | }; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 658 | |
Edgardo Hames | 631c8de | 2010-03-08 17:02:37 -0800 | [diff] [blame] | 659 | static inline int usbctlx_cmd_completor_fn(struct usbctlx_completor *head) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 660 | { |
Edgardo Hames | 631c8de | 2010-03-08 17:02:37 -0800 | [diff] [blame] | 661 | struct usbctlx_cmd_completor *complete; |
| 662 | |
Sherif Shehab Aldin | 5d85fe3 | 2014-04-05 23:35:15 +0200 | [diff] [blame] | 663 | complete = (struct usbctlx_cmd_completor *)head; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 664 | return usbctlx_get_status(complete->cmdresp, complete->result); |
| 665 | } |
| 666 | |
Edgardo Hames | 631c8de | 2010-03-08 17:02:37 -0800 | [diff] [blame] | 667 | static inline struct usbctlx_completor *init_cmd_completor( |
| 668 | struct usbctlx_cmd_completor |
| 669 | *completor, |
Sergio Paracuellos | 385a79d | 2016-09-28 20:19:30 +0200 | [diff] [blame] | 670 | const struct hfa384x_usb_statusresp |
Edgardo Hames | 631c8de | 2010-03-08 17:02:37 -0800 | [diff] [blame] | 671 | *cmdresp, |
Sergio Paracuellos | 501f5f9 | 2016-09-28 20:20:14 +0200 | [diff] [blame] | 672 | struct hfa384x_cmdresult *result) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 673 | { |
| 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 Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 685 | struct usbctlx_rrid_completor { |
Edgardo Hames | 631c8de | 2010-03-08 17:02:37 -0800 | [diff] [blame] | 686 | struct usbctlx_completor head; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 687 | |
Sergio Paracuellos | a988c9f | 2016-09-28 20:19:32 +0200 | [diff] [blame] | 688 | const struct hfa384x_usb_rridresp *rridresp; |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 689 | void *riddata; |
| 690 | unsigned int riddatalen; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 691 | }; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 692 | |
Edgardo Hames | 631c8de | 2010-03-08 17:02:37 -0800 | [diff] [blame] | 693 | static int usbctlx_rrid_completor_fn(struct usbctlx_completor *head) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 694 | { |
Edgardo Hames | 631c8de | 2010-03-08 17:02:37 -0800 | [diff] [blame] | 695 | struct usbctlx_rrid_completor *complete; |
Sergio Paracuellos | b3fd890 | 2016-09-28 20:20:15 +0200 | [diff] [blame] | 696 | struct hfa384x_rridresult rridresult; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 697 | |
Sherif Shehab Aldin | 5d85fe3 | 2014-04-05 23:35:15 +0200 | [diff] [blame] | 698 | complete = (struct usbctlx_rrid_completor *)head; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 699 | usbctlx_get_rridresult(complete->rridresp, &rridresult); |
| 700 | |
| 701 | /* Validate the length, note body len calculation in bytes */ |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 702 | if (rridresult.riddata_len != complete->riddatalen) { |
Sherif Shehab Aldin | baa8a6c | 2014-04-05 23:33:53 +0200 | [diff] [blame] | 703 | pr_warn("RID len mismatch, rid=0x%04x hlen=%d fwlen=%d\n", |
| 704 | rridresult.rid, |
| 705 | complete->riddatalen, rridresult.riddata_len); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 706 | return -ENODATA; |
| 707 | } |
| 708 | |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 709 | memcpy(complete->riddata, rridresult.riddata, complete->riddatalen); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 710 | return 0; |
| 711 | } |
| 712 | |
Edgardo Hames | 631c8de | 2010-03-08 17:02:37 -0800 | [diff] [blame] | 713 | static inline struct usbctlx_completor *init_rrid_completor( |
| 714 | struct usbctlx_rrid_completor |
| 715 | *completor, |
Sergio Paracuellos | a988c9f | 2016-09-28 20:19:32 +0200 | [diff] [blame] | 716 | const struct hfa384x_usb_rridresp |
Edgardo Hames | 631c8de | 2010-03-08 17:02:37 -0800 | [diff] [blame] | 717 | *rridresp, |
| 718 | void *riddata, |
| 719 | unsigned int riddatalen) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 720 | { |
| 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-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 732 | #define init_wrid_completor init_cmd_completor |
| 733 | |
| 734 | /*---------------------------------------------------------------- |
| 735 | * Completor object: |
| 736 | * Interprets the results of a synchronous memory-write |
| 737 | ----------------------------------------------------------------*/ |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 738 | #define init_wmem_completor init_cmd_completor |
| 739 | |
| 740 | /*---------------------------------------------------------------- |
| 741 | * Completor object: |
| 742 | * Interprets the results of a synchronous memory-read |
| 743 | ----------------------------------------------------------------*/ |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 744 | struct usbctlx_rmem_completor { |
Edgardo Hames | 631c8de | 2010-03-08 17:02:37 -0800 | [diff] [blame] | 745 | struct usbctlx_completor head; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 746 | |
Sergio Paracuellos | 1ed5480 | 2016-09-28 20:19:34 +0200 | [diff] [blame] | 747 | const struct hfa384x_usb_rmemresp *rmemresp; |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 748 | void *data; |
| 749 | unsigned int len; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 750 | }; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 751 | |
Edgardo Hames | 631c8de | 2010-03-08 17:02:37 -0800 | [diff] [blame] | 752 | static int usbctlx_rmem_completor_fn(struct usbctlx_completor *head) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 753 | { |
Sherif Shehab Aldin | a03742a | 2014-04-05 23:33:45 +0200 | [diff] [blame] | 754 | struct usbctlx_rmem_completor *complete = |
| 755 | (struct usbctlx_rmem_completor *)head; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 756 | |
Moritz Muehlenhoff | a7cf7ba | 2009-02-08 02:01:00 +0100 | [diff] [blame] | 757 | pr_debug("rmemresp:len=%d\n", complete->rmemresp->frmlen); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 758 | memcpy(complete->data, complete->rmemresp->data, complete->len); |
| 759 | return 0; |
| 760 | } |
| 761 | |
Edgardo Hames | 631c8de | 2010-03-08 17:02:37 -0800 | [diff] [blame] | 762 | static inline struct usbctlx_completor *init_rmem_completor( |
Sherif Shehab Aldin | a03742a | 2014-04-05 23:33:45 +0200 | [diff] [blame] | 763 | struct usbctlx_rmem_completor |
Edgardo Hames | 631c8de | 2010-03-08 17:02:37 -0800 | [diff] [blame] | 764 | *completor, |
Sergio Paracuellos | 1ed5480 | 2016-09-28 20:19:34 +0200 | [diff] [blame] | 765 | struct hfa384x_usb_rmemresp |
Edgardo Hames | 631c8de | 2010-03-08 17:02:37 -0800 | [diff] [blame] | 766 | *rmemresp, |
| 767 | void *data, |
| 768 | unsigned int len) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 769 | { |
| 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 Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 798 | static void hfa384x_cb_status(struct hfa384x *hw, const struct hfa384x_usbctlx *ctlx) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 799 | { |
Nicholas Sim | 02e0204 | 2016-04-05 17:37:12 +0100 | [diff] [blame] | 800 | if (ctlx->usercb) { |
Sergio Paracuellos | 501f5f9 | 2016-09-28 20:20:14 +0200 | [diff] [blame] | 801 | struct hfa384x_cmdresult cmdresult; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 802 | |
| 803 | if (ctlx->state != CTLX_COMPLETE) { |
| 804 | memset(&cmdresult, 0, sizeof(cmdresult)); |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 805 | cmdresult.status = |
| 806 | HFA384x_STATUS_RESULT_SET(HFA384x_CMD_ERR); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 807 | } else { |
| 808 | usbctlx_get_status(&ctlx->inbuf.cmdresp, &cmdresult); |
| 809 | } |
| 810 | |
| 811 | ctlx->usercb(hw, &cmdresult, ctlx->usercb_data); |
| 812 | } |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 813 | } |
| 814 | |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 815 | static inline int hfa384x_docmd_wait(struct hfa384x *hw, struct hfa384x_metacmd *cmd) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 816 | { |
| 817 | return hfa384x_docmd(hw, DOWAIT, cmd, NULL, NULL, NULL); |
| 818 | } |
| 819 | |
| 820 | static inline int |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 821 | hfa384x_docmd_async(struct hfa384x *hw, |
Sergio Paracuellos | e2f503c | 2016-09-28 20:20:18 +0200 | [diff] [blame] | 822 | struct hfa384x_metacmd *cmd, |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 823 | ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 824 | { |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 825 | return hfa384x_docmd(hw, DOASYNC, cmd, cmdcb, usercb, usercb_data); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 826 | } |
| 827 | |
| 828 | static inline int |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 829 | hfa384x_dorrid_wait(struct hfa384x *hw, u16 rid, void *riddata, |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 830 | unsigned int riddatalen) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 831 | { |
| 832 | return hfa384x_dorrid(hw, DOWAIT, |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 833 | rid, riddata, riddatalen, NULL, NULL, NULL); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | static inline int |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 837 | hfa384x_dorrid_async(struct hfa384x *hw, |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 838 | u16 rid, void *riddata, unsigned int riddatalen, |
| 839 | ctlx_cmdcb_t cmdcb, |
| 840 | ctlx_usercb_t usercb, void *usercb_data) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 841 | { |
| 842 | return hfa384x_dorrid(hw, DOASYNC, |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 843 | rid, riddata, riddatalen, |
| 844 | cmdcb, usercb, usercb_data); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 845 | } |
| 846 | |
| 847 | static inline int |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 848 | hfa384x_dowrid_wait(struct hfa384x *hw, u16 rid, void *riddata, |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 849 | unsigned int riddatalen) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 850 | { |
| 851 | return hfa384x_dowrid(hw, DOWAIT, |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 852 | rid, riddata, riddatalen, NULL, NULL, NULL); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | static inline int |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 856 | hfa384x_dowrid_async(struct hfa384x *hw, |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 857 | u16 rid, void *riddata, unsigned int riddatalen, |
| 858 | ctlx_cmdcb_t cmdcb, |
| 859 | ctlx_usercb_t usercb, void *usercb_data) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 860 | { |
| 861 | return hfa384x_dowrid(hw, DOASYNC, |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 862 | rid, riddata, riddatalen, |
| 863 | cmdcb, usercb, usercb_data); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 864 | } |
| 865 | |
| 866 | static inline int |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 867 | hfa384x_dormem_wait(struct hfa384x *hw, |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 868 | u16 page, u16 offset, void *data, unsigned int len) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 869 | { |
| 870 | return hfa384x_dormem(hw, DOWAIT, |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 871 | page, offset, data, len, NULL, NULL, NULL); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | static inline int |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 875 | hfa384x_dormem_async(struct hfa384x *hw, |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 876 | u16 page, u16 offset, void *data, unsigned int len, |
| 877 | ctlx_cmdcb_t cmdcb, |
| 878 | ctlx_usercb_t usercb, void *usercb_data) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 879 | { |
| 880 | return hfa384x_dormem(hw, DOASYNC, |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 881 | page, offset, data, len, |
| 882 | cmdcb, usercb, usercb_data); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | static inline int |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 886 | hfa384x_dowmem_wait(struct hfa384x *hw, |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 887 | u16 page, u16 offset, void *data, unsigned int len) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 888 | { |
| 889 | return hfa384x_dowmem(hw, DOWAIT, |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 890 | page, offset, data, len, NULL, NULL, NULL); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 891 | } |
| 892 | |
| 893 | static inline int |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 894 | hfa384x_dowmem_async(struct hfa384x *hw, |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 895 | 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-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 901 | { |
| 902 | return hfa384x_dowmem(hw, DOASYNC, |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 903 | page, offset, data, len, |
| 904 | cmdcb, usercb, usercb_data); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 905 | } |
| 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 Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 926 | int hfa384x_cmd_initialize(struct hfa384x *hw) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 927 | { |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 928 | int result = 0; |
| 929 | int i; |
Sergio Paracuellos | e2f503c | 2016-09-28 20:20:18 +0200 | [diff] [blame] | 930 | struct hfa384x_metacmd cmd; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 931 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 932 | 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 Aldin | a212013 | 2014-04-05 23:33:16 +0200 | [diff] [blame] | 939 | pr_debug("cmdresp.init: status=0x%04x, resp0=0x%04x, resp1=0x%04x, resp2=0x%04x\n", |
Mithlesh Thukral | 75f49e0 | 2009-05-25 19:06:16 +0530 | [diff] [blame] | 940 | cmd.result.status, |
| 941 | cmd.result.resp0, cmd.result.resp1, cmd.result.resp2); |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 942 | if (result == 0) { |
| 943 | for (i = 0; i < HFA384x_NUMPORTS_MAX; i++) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 944 | hw->port_enabled[i] = 0; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 945 | } |
| 946 | |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 947 | hw->link_status = HFA384x_LINK_NOTCONNECTED; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 948 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 949 | return result; |
| 950 | } |
| 951 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 952 | /*---------------------------------------------------------------- |
| 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 Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 972 | int hfa384x_cmd_disable(struct hfa384x *hw, u16 macport) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 973 | { |
Sergio Paracuellos | e2f503c | 2016-09-28 20:20:18 +0200 | [diff] [blame] | 974 | struct hfa384x_metacmd cmd; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 975 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 976 | cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_DISABLE) | |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 977 | HFA384x_CMD_MACPORT_SET(macport); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 978 | cmd.parm0 = 0; |
| 979 | cmd.parm1 = 0; |
| 980 | cmd.parm2 = 0; |
| 981 | |
Bhumika Goyal | ca026a3 | 2016-02-09 01:28:10 +0530 | [diff] [blame] | 982 | return hfa384x_docmd_wait(hw, &cmd); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 983 | } |
| 984 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 985 | /*---------------------------------------------------------------- |
| 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 Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 1005 | int hfa384x_cmd_enable(struct hfa384x *hw, u16 macport) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1006 | { |
Sergio Paracuellos | e2f503c | 2016-09-28 20:20:18 +0200 | [diff] [blame] | 1007 | struct hfa384x_metacmd cmd; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1008 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1009 | cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_ENABLE) | |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1010 | HFA384x_CMD_MACPORT_SET(macport); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1011 | cmd.parm0 = 0; |
| 1012 | cmd.parm1 = 0; |
| 1013 | cmd.parm2 = 0; |
| 1014 | |
Bhumika Goyal | ca026a3 | 2016-02-09 01:28:10 +0530 | [diff] [blame] | 1015 | return hfa384x_docmd_wait(hw, &cmd); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1016 | } |
| 1017 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1018 | /*---------------------------------------------------------------- |
| 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 Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 1047 | int hfa384x_cmd_monitor(struct hfa384x *hw, u16 enable) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1048 | { |
Sergio Paracuellos | e2f503c | 2016-09-28 20:20:18 +0200 | [diff] [blame] | 1049 | struct hfa384x_metacmd cmd; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1050 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1051 | cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_MONITOR) | |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1052 | HFA384x_CMD_AINFO_SET(enable); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1053 | cmd.parm0 = 0; |
| 1054 | cmd.parm1 = 0; |
| 1055 | cmd.parm2 = 0; |
| 1056 | |
Bhumika Goyal | ca026a3 | 2016-02-09 01:28:10 +0530 | [diff] [blame] | 1057 | return hfa384x_docmd_wait(hw, &cmd); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1058 | } |
| 1059 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1060 | /*---------------------------------------------------------------- |
| 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 Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 1098 | int hfa384x_cmd_download(struct hfa384x *hw, u16 mode, u16 lowaddr, |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1099 | u16 highaddr, u16 codelen) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1100 | { |
Sergio Paracuellos | e2f503c | 2016-09-28 20:20:18 +0200 | [diff] [blame] | 1101 | struct hfa384x_metacmd cmd; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1102 | |
Mithlesh Thukral | 75f49e0 | 2009-05-25 19:06:16 +0530 | [diff] [blame] | 1103 | pr_debug("mode=%d, lowaddr=0x%04x, highaddr=0x%04x, codelen=%d\n", |
| 1104 | mode, lowaddr, highaddr, codelen); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1105 | |
| 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 Goyal | ca026a3 | 2016-02-09 01:28:10 +0530 | [diff] [blame] | 1113 | return hfa384x_docmd_wait(hw, &cmd); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1114 | } |
| 1115 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1116 | /*---------------------------------------------------------------- |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1117 | * 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 Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 1139 | int hfa384x_corereset(struct hfa384x *hw, int holdtime, int settletime, int genesis) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1140 | { |
Amitoj Kaur Chawla | df18b93 | 2015-10-15 01:42:11 +0530 | [diff] [blame] | 1141 | int result; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1142 | |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1143 | result = usb_reset_device(hw->usb); |
| 1144 | if (result < 0) { |
Avinash Kumar | 263b8bb | 2013-09-06 22:21:49 +0530 | [diff] [blame] | 1145 | netdev_err(hw->wlandev->netdev, "usb_reset_device() failed, result=%d.\n", |
Sherif Shehab Aldin | 3f2d656 | 2014-04-05 23:34:40 +0200 | [diff] [blame] | 1146 | result); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1147 | } |
| 1148 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1149 | return result; |
| 1150 | } |
| 1151 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1152 | /*---------------------------------------------------------------- |
| 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 Hames | 631c8de | 2010-03-08 17:02:37 -0800 | [diff] [blame] | 1160 | * ctlx CTLX ptr |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1161 | * 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 Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 1176 | static int hfa384x_usbctlx_complete_sync(struct hfa384x *hw, |
Sergio Paracuellos | a10d36b | 2016-09-28 20:20:16 +0200 | [diff] [blame] | 1177 | struct hfa384x_usbctlx *ctlx, |
Edgardo Hames | 631c8de | 2010-03-08 17:02:37 -0800 | [diff] [blame] | 1178 | struct usbctlx_completor *completor) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1179 | { |
| 1180 | unsigned long flags; |
| 1181 | int result; |
| 1182 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1183 | 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 Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1191 | cleanup: |
| 1192 | if (hw->wlandev->hwremoved) { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1193 | spin_unlock_irqrestore(&hw->ctlxq.lock, flags); |
| 1194 | result = -ENODEV; |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1195 | } else if (result != 0) { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1196 | 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 Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1207 | if (ctlx == get_active_ctlx(hw)) { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1208 | 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 Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1224 | if (hw->wlandev->hwremoved) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1225 | 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 Kumar | 263b8bb | 2013-09-06 22:21:49 +0530 | [diff] [blame] | 1245 | netdev_warn(hw->wlandev->netdev, "CTLX[%d] error: state(%s)\n", |
Sherif Shehab Aldin | 3f2d656 | 2014-04-05 23:34:40 +0200 | [diff] [blame] | 1246 | le16_to_cpu(ctlx->outbuf.type), |
| 1247 | ctlxstr(ctlx->state)); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1248 | result = -EIO; |
| 1249 | } |
| 1250 | |
| 1251 | list_del(&ctlx->list); |
| 1252 | spin_unlock_irqrestore(&hw->ctlxq.lock, flags); |
| 1253 | kfree(ctlx); |
| 1254 | } |
| 1255 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1256 | 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 | ----------------------------------------------------------------*/ |
| 1291 | static int |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 1292 | hfa384x_docmd(struct hfa384x *hw, |
Edgardo Hames | 631c8de | 2010-03-08 17:02:37 -0800 | [diff] [blame] | 1293 | enum cmd_mode mode, |
Sergio Paracuellos | e2f503c | 2016-09-28 20:20:18 +0200 | [diff] [blame] | 1294 | struct hfa384x_metacmd *cmd, |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1295 | ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1296 | { |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1297 | int result; |
Sergio Paracuellos | a10d36b | 2016-09-28 20:20:16 +0200 | [diff] [blame] | 1298 | struct hfa384x_usbctlx *ctlx; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1299 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1300 | ctlx = usbctlx_alloc(); |
Eva Rachel Retuya | e2e7752 | 2016-02-27 20:39:25 +0800 | [diff] [blame] | 1301 | if (!ctlx) { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1302 | result = -ENOMEM; |
| 1303 | goto done; |
| 1304 | } |
| 1305 | |
| 1306 | /* Initialize the command */ |
Moritz Muehlenhoff | 18c7f79 | 2009-02-18 19:50:07 +0100 | [diff] [blame] | 1307 | 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-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1312 | |
| 1313 | ctlx->outbufsize = sizeof(ctlx->outbuf.cmdreq); |
| 1314 | |
Sherif Shehab Aldin | a212013 | 2014-04-05 23:33:16 +0200 | [diff] [blame] | 1315 | pr_debug("cmdreq: cmd=0x%04x parm0=0x%04x parm1=0x%04x parm2=0x%04x\n", |
Mithlesh Thukral | 75f49e0 | 2009-05-25 19:06:16 +0530 | [diff] [blame] | 1316 | cmd->cmd, cmd->parm0, cmd->parm1, cmd->parm2); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1317 | |
| 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 Hames | 631c8de | 2010-03-08 17:02:37 -0800 | [diff] [blame] | 1327 | struct usbctlx_cmd_completor completor; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1328 | |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1329 | 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-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1337 | } |
| 1338 | |
| 1339 | done: |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1340 | return result; |
| 1341 | } |
| 1342 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1343 | /*---------------------------------------------------------------- |
| 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 | ----------------------------------------------------------------*/ |
| 1379 | static int |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 1380 | hfa384x_dorrid(struct hfa384x *hw, |
Edgardo Hames | 631c8de | 2010-03-08 17:02:37 -0800 | [diff] [blame] | 1381 | enum cmd_mode mode, |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1382 | u16 rid, |
| 1383 | void *riddata, |
| 1384 | unsigned int riddatalen, |
| 1385 | ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1386 | { |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1387 | int result; |
Sergio Paracuellos | a10d36b | 2016-09-28 20:20:16 +0200 | [diff] [blame] | 1388 | struct hfa384x_usbctlx *ctlx; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1389 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1390 | ctlx = usbctlx_alloc(); |
Eva Rachel Retuya | e2e7752 | 2016-02-27 20:39:25 +0800 | [diff] [blame] | 1391 | if (!ctlx) { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1392 | result = -ENOMEM; |
| 1393 | goto done; |
| 1394 | } |
| 1395 | |
| 1396 | /* Initialize the command */ |
Moritz Muehlenhoff | 18c7f79 | 2009-02-18 19:50:07 +0100 | [diff] [blame] | 1397 | ctlx->outbuf.rridreq.type = cpu_to_le16(HFA384x_USB_RRIDREQ); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1398 | ctlx->outbuf.rridreq.frmlen = |
Moritz Muehlenhoff | 18c7f79 | 2009-02-18 19:50:07 +0100 | [diff] [blame] | 1399 | cpu_to_le16(sizeof(ctlx->outbuf.rridreq.rid)); |
| 1400 | ctlx->outbuf.rridreq.rid = cpu_to_le16(rid); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1401 | |
| 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 Hames | 631c8de | 2010-03-08 17:02:37 -0800 | [diff] [blame] | 1414 | struct usbctlx_rrid_completor completor; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1415 | |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1416 | result = |
| 1417 | hfa384x_usbctlx_complete_sync(hw, ctlx, |
| 1418 | init_rrid_completor |
| 1419 | (&completor, |
| 1420 | &ctlx->inbuf.rridresp, |
| 1421 | riddata, riddatalen)); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1422 | } |
| 1423 | |
| 1424 | done: |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1425 | return result; |
| 1426 | } |
| 1427 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1428 | /*---------------------------------------------------------------- |
| 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 Hames | 631c8de | 2010-03-08 17:02:37 -0800 | [diff] [blame] | 1439 | * enum cmd_mode DOWAIT or DOASYNC |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1440 | * 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 | ----------------------------------------------------------------*/ |
| 1460 | static int |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 1461 | hfa384x_dowrid(struct hfa384x *hw, |
Edgardo Hames | 631c8de | 2010-03-08 17:02:37 -0800 | [diff] [blame] | 1462 | enum cmd_mode mode, |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1463 | u16 rid, |
| 1464 | void *riddata, |
| 1465 | unsigned int riddatalen, |
| 1466 | ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1467 | { |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1468 | int result; |
Sergio Paracuellos | a10d36b | 2016-09-28 20:20:16 +0200 | [diff] [blame] | 1469 | struct hfa384x_usbctlx *ctlx; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1470 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1471 | ctlx = usbctlx_alloc(); |
Eva Rachel Retuya | e2e7752 | 2016-02-27 20:39:25 +0800 | [diff] [blame] | 1472 | if (!ctlx) { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1473 | result = -ENOMEM; |
| 1474 | goto done; |
| 1475 | } |
| 1476 | |
| 1477 | /* Initialize the command */ |
Moritz Muehlenhoff | 18c7f79 | 2009-02-18 19:50:07 +0100 | [diff] [blame] | 1478 | ctlx->outbuf.wridreq.type = cpu_to_le16(HFA384x_USB_WRIDREQ); |
| 1479 | ctlx->outbuf.wridreq.frmlen = cpu_to_le16((sizeof |
Mithlesh Thukral | 75f49e0 | 2009-05-25 19:06:16 +0530 | [diff] [blame] | 1480 | (ctlx->outbuf.wridreq.rid) + |
| 1481 | riddatalen + 1) / 2); |
Moritz Muehlenhoff | 18c7f79 | 2009-02-18 19:50:07 +0100 | [diff] [blame] | 1482 | ctlx->outbuf.wridreq.rid = cpu_to_le16(rid); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1483 | memcpy(ctlx->outbuf.wridreq.data, riddata, riddatalen); |
| 1484 | |
| 1485 | ctlx->outbufsize = sizeof(ctlx->outbuf.wridreq.type) + |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1486 | sizeof(ctlx->outbuf.wridreq.frmlen) + |
| 1487 | sizeof(ctlx->outbuf.wridreq.rid) + riddatalen; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1488 | |
| 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 Aldin | a03742a | 2014-04-05 23:33:45 +0200 | [diff] [blame] | 1499 | struct usbctlx_cmd_completor completor; |
Sergio Paracuellos | 501f5f9 | 2016-09-28 20:20:14 +0200 | [diff] [blame] | 1500 | struct hfa384x_cmdresult wridresult; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1501 | |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1502 | result = hfa384x_usbctlx_complete_sync(hw, |
| 1503 | ctlx, |
| 1504 | init_wrid_completor |
| 1505 | (&completor, |
| 1506 | &ctlx->inbuf.wridresp, |
| 1507 | &wridresult)); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1508 | } |
| 1509 | |
| 1510 | done: |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1511 | 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 | ----------------------------------------------------------------*/ |
| 1547 | static int |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 1548 | hfa384x_dormem(struct hfa384x *hw, |
Edgardo Hames | 631c8de | 2010-03-08 17:02:37 -0800 | [diff] [blame] | 1549 | enum cmd_mode mode, |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1550 | 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-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1555 | { |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1556 | int result; |
Sergio Paracuellos | a10d36b | 2016-09-28 20:20:16 +0200 | [diff] [blame] | 1557 | struct hfa384x_usbctlx *ctlx; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1558 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1559 | ctlx = usbctlx_alloc(); |
Eva Rachel Retuya | e2e7752 | 2016-02-27 20:39:25 +0800 | [diff] [blame] | 1560 | if (!ctlx) { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1561 | result = -ENOMEM; |
| 1562 | goto done; |
| 1563 | } |
| 1564 | |
| 1565 | /* Initialize the command */ |
Moritz Muehlenhoff | 18c7f79 | 2009-02-18 19:50:07 +0100 | [diff] [blame] | 1566 | ctlx->outbuf.rmemreq.type = cpu_to_le16(HFA384x_USB_RMEMREQ); |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1567 | ctlx->outbuf.rmemreq.frmlen = |
Moritz Muehlenhoff | 18c7f79 | 2009-02-18 19:50:07 +0100 | [diff] [blame] | 1568 | cpu_to_le16(sizeof(ctlx->outbuf.rmemreq.offset) + |
Mithlesh Thukral | 75f49e0 | 2009-05-25 19:06:16 +0530 | [diff] [blame] | 1569 | sizeof(ctlx->outbuf.rmemreq.page) + len); |
Moritz Muehlenhoff | 18c7f79 | 2009-02-18 19:50:07 +0100 | [diff] [blame] | 1570 | ctlx->outbuf.rmemreq.offset = cpu_to_le16(offset); |
| 1571 | ctlx->outbuf.rmemreq.page = cpu_to_le16(page); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1572 | |
| 1573 | ctlx->outbufsize = sizeof(ctlx->outbuf.rmemreq); |
| 1574 | |
Mithlesh Thukral | 75f49e0 | 2009-05-25 19:06:16 +0530 | [diff] [blame] | 1575 | 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-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1579 | |
Mithlesh Thukral | 75f49e0 | 2009-05-25 19:06:16 +0530 | [diff] [blame] | 1580 | pr_debug("pktsize=%zd\n", ROUNDUP64(sizeof(ctlx->outbuf.rmemreq))); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1581 | |
| 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 Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1590 | } else if (mode == DOWAIT) { |
Sherif Shehab Aldin | a03742a | 2014-04-05 23:33:45 +0200 | [diff] [blame] | 1591 | struct usbctlx_rmem_completor completor; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1592 | |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1593 | result = |
| 1594 | hfa384x_usbctlx_complete_sync(hw, ctlx, |
| 1595 | init_rmem_completor |
| 1596 | (&completor, |
| 1597 | &ctlx->inbuf.rmemresp, data, |
| 1598 | len)); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1599 | } |
| 1600 | |
| 1601 | done: |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1602 | return result; |
| 1603 | } |
| 1604 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1605 | /*---------------------------------------------------------------- |
| 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 | ----------------------------------------------------------------*/ |
| 1638 | static int |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 1639 | hfa384x_dowmem(struct hfa384x *hw, |
Edgardo Hames | 631c8de | 2010-03-08 17:02:37 -0800 | [diff] [blame] | 1640 | enum cmd_mode mode, |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1641 | 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-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1646 | { |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1647 | int result; |
Sergio Paracuellos | a10d36b | 2016-09-28 20:20:16 +0200 | [diff] [blame] | 1648 | struct hfa384x_usbctlx *ctlx; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1649 | |
Mithlesh Thukral | 75f49e0 | 2009-05-25 19:06:16 +0530 | [diff] [blame] | 1650 | pr_debug("page=0x%04x offset=0x%04x len=%d\n", page, offset, len); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1651 | |
| 1652 | ctlx = usbctlx_alloc(); |
Eva Rachel Retuya | e2e7752 | 2016-02-27 20:39:25 +0800 | [diff] [blame] | 1653 | if (!ctlx) { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1654 | result = -ENOMEM; |
| 1655 | goto done; |
| 1656 | } |
| 1657 | |
| 1658 | /* Initialize the command */ |
Moritz Muehlenhoff | 18c7f79 | 2009-02-18 19:50:07 +0100 | [diff] [blame] | 1659 | ctlx->outbuf.wmemreq.type = cpu_to_le16(HFA384x_USB_WMEMREQ); |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1660 | ctlx->outbuf.wmemreq.frmlen = |
Moritz Muehlenhoff | 18c7f79 | 2009-02-18 19:50:07 +0100 | [diff] [blame] | 1661 | cpu_to_le16(sizeof(ctlx->outbuf.wmemreq.offset) + |
Mithlesh Thukral | 75f49e0 | 2009-05-25 19:06:16 +0530 | [diff] [blame] | 1662 | sizeof(ctlx->outbuf.wmemreq.page) + len); |
Moritz Muehlenhoff | 18c7f79 | 2009-02-18 19:50:07 +0100 | [diff] [blame] | 1663 | ctlx->outbuf.wmemreq.offset = cpu_to_le16(offset); |
| 1664 | ctlx->outbuf.wmemreq.page = cpu_to_le16(page); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1665 | memcpy(ctlx->outbuf.wmemreq.data, data, len); |
| 1666 | |
| 1667 | ctlx->outbufsize = sizeof(ctlx->outbuf.wmemreq.type) + |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1668 | sizeof(ctlx->outbuf.wmemreq.frmlen) + |
| 1669 | sizeof(ctlx->outbuf.wmemreq.offset) + |
| 1670 | sizeof(ctlx->outbuf.wmemreq.page) + len; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1671 | |
| 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 Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1680 | } else if (mode == DOWAIT) { |
Sherif Shehab Aldin | a03742a | 2014-04-05 23:33:45 +0200 | [diff] [blame] | 1681 | struct usbctlx_cmd_completor completor; |
Sergio Paracuellos | 501f5f9 | 2016-09-28 20:20:14 +0200 | [diff] [blame] | 1682 | struct hfa384x_cmdresult wmemresult; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1683 | |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1684 | result = hfa384x_usbctlx_complete_sync(hw, |
| 1685 | ctlx, |
| 1686 | init_wmem_completor |
| 1687 | (&completor, |
| 1688 | &ctlx->inbuf.wmemresp, |
| 1689 | &wmemresult)); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1690 | } |
| 1691 | |
| 1692 | done: |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1693 | return result; |
| 1694 | } |
| 1695 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1696 | /*---------------------------------------------------------------- |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1697 | * 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 Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 1718 | int hfa384x_drvr_disable(struct hfa384x *hw, u16 macport) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1719 | { |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1720 | int result = 0; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1721 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1722 | if ((!hw->isap && macport != 0) || |
| 1723 | (hw->isap && !(macport <= HFA384x_PORTID_MAX)) || |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1724 | !(hw->port_enabled[macport])) { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1725 | result = -EINVAL; |
| 1726 | } else { |
| 1727 | result = hfa384x_cmd_disable(hw, macport); |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1728 | if (result == 0) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1729 | hw->port_enabled[macport] = 0; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1730 | } |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1731 | return result; |
| 1732 | } |
| 1733 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1734 | /*---------------------------------------------------------------- |
| 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 Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 1756 | int hfa384x_drvr_enable(struct hfa384x *hw, u16 macport) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1757 | { |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1758 | int result = 0; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1759 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1760 | if ((!hw->isap && macport != 0) || |
| 1761 | (hw->isap && !(macport <= HFA384x_PORTID_MAX)) || |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1762 | (hw->port_enabled[macport])) { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1763 | result = -EINVAL; |
| 1764 | } else { |
| 1765 | result = hfa384x_cmd_enable(hw, macport); |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1766 | if (result == 0) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1767 | hw->port_enabled[macport] = 1; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1768 | } |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1769 | return result; |
| 1770 | } |
| 1771 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1772 | /*---------------------------------------------------------------- |
| 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 Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 1793 | int hfa384x_drvr_flashdl_enable(struct hfa384x *hw) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1794 | { |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1795 | int result = 0; |
| 1796 | int i; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1797 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1798 | /* Check that a port isn't active */ |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1799 | for (i = 0; i < HFA384x_PORTID_MAX; i++) { |
| 1800 | if (hw->port_enabled[i]) { |
Moritz Muehlenhoff | a7cf7ba | 2009-02-08 02:01:00 +0100 | [diff] [blame] | 1801 | pr_debug("called when port enabled.\n"); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1802 | return -EINVAL; |
| 1803 | } |
| 1804 | } |
| 1805 | |
| 1806 | /* Check that we're not already in a download state */ |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1807 | if (hw->dlstate != HFA384x_DLSTATE_DISABLED) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1808 | return -EINVAL; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1809 | |
| 1810 | /* Retrieve the buffer loc&size and timeout */ |
Svenne Krap | 46800b2 | 2010-02-14 18:59:42 +0100 | [diff] [blame] | 1811 | result = hfa384x_drvr_getconfig(hw, HFA384x_RID_DOWNLOADBUFFER, |
Andrew Elwell | 3f4b4e7 | 2010-02-18 23:56:13 +0100 | [diff] [blame] | 1812 | &(hw->bufinfo), sizeof(hw->bufinfo)); |
| 1813 | if (result) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1814 | return result; |
Andrew Elwell | 3f4b4e7 | 2010-02-18 23:56:13 +0100 | [diff] [blame] | 1815 | |
Moritz Muehlenhoff | 18c7f79 | 2009-02-18 19:50:07 +0100 | [diff] [blame] | 1816 | 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 Krap | 46800b2 | 2010-02-14 18:59:42 +0100 | [diff] [blame] | 1819 | result = hfa384x_drvr_getconfig16(hw, HFA384x_RID_MAXLOADTIME, |
Andrew Elwell | 3f4b4e7 | 2010-02-18 23:56:13 +0100 | [diff] [blame] | 1820 | &(hw->dltimeout)); |
| 1821 | if (result) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1822 | return result; |
Andrew Elwell | 3f4b4e7 | 2010-02-18 23:56:13 +0100 | [diff] [blame] | 1823 | |
Moritz Muehlenhoff | 18c7f79 | 2009-02-18 19:50:07 +0100 | [diff] [blame] | 1824 | hw->dltimeout = le16_to_cpu(hw->dltimeout); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1825 | |
Moritz Muehlenhoff | a7cf7ba | 2009-02-08 02:01:00 +0100 | [diff] [blame] | 1826 | pr_debug("flashdl_enable\n"); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1827 | |
| 1828 | hw->dlstate = HFA384x_DLSTATE_FLASHENABLED; |
Moritz Muehlenhoff | 8a251b5 | 2009-01-21 22:00:44 +0100 | [diff] [blame] | 1829 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1830 | return result; |
| 1831 | } |
| 1832 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1833 | /*---------------------------------------------------------------- |
| 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 Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 1852 | int hfa384x_drvr_flashdl_disable(struct hfa384x *hw) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1853 | { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1854 | /* Check that we're already in the download state */ |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1855 | if (hw->dlstate != HFA384x_DLSTATE_FLASHENABLED) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1856 | return -EINVAL; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1857 | |
Moritz Muehlenhoff | a7cf7ba | 2009-02-08 02:01:00 +0100 | [diff] [blame] | 1858 | pr_debug("flashdl_enable\n"); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1859 | |
| 1860 | /* There isn't much we can do at this point, so I don't */ |
| 1861 | /* bother w/ the return value */ |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1862 | hfa384x_cmd_download(hw, HFA384x_PROGMODE_DISABLE, 0, 0, 0); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1863 | hw->dlstate = HFA384x_DLSTATE_DISABLED; |
| 1864 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1865 | return 0; |
| 1866 | } |
| 1867 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1868 | /*---------------------------------------------------------------- |
| 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 Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 1897 | int hfa384x_drvr_flashdl_write(struct hfa384x *hw, u32 daddr, void *buf, u32 len) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1898 | { |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1899 | 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-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1913 | |
Moritz Muehlenhoff | a7cf7ba | 2009-02-08 02:01:00 +0100 | [diff] [blame] | 1914 | pr_debug("daddr=0x%08x len=%d\n", daddr, len); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1915 | |
| 1916 | /* Check that we're in the flash download state */ |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1917 | if (hw->dlstate != HFA384x_DLSTATE_FLASHENABLED) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1918 | return -EINVAL; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1919 | |
Sherif Shehab Aldin | a212013 | 2014-04-05 23:33:16 +0200 | [diff] [blame] | 1920 | netdev_info(hw->wlandev->netdev, |
| 1921 | "Download %d bytes to flash @0x%06x\n", len, daddr); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1922 | |
| 1923 | /* Convert to flat address for arithmetic */ |
| 1924 | /* NOTE: dlbuffer RID stores the address in AUX format */ |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1925 | dlbufaddr = |
| 1926 | HFA384x_ADDR_AUX_MKFLAT(hw->bufinfo.page, hw->bufinfo.offset); |
Mithlesh Thukral | 75f49e0 | 2009-05-25 19:06:16 +0530 | [diff] [blame] | 1927 | pr_debug("dlbuf.page=0x%04x dlbuf.offset=0x%04x dlbufaddr=0x%08x\n", |
| 1928 | hw->bufinfo.page, hw->bufinfo.offset, dlbufaddr); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1929 | /* 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 Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1945 | for (i = 0; i < nburns; i++) { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1946 | /* Get the dest address and len */ |
| 1947 | burnlen = (len - (hw->bufinfo.len * i)) > hw->bufinfo.len ? |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1948 | hw->bufinfo.len : (len - (hw->bufinfo.len * i)); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1949 | burndaddr = daddr + (hw->bufinfo.len * i); |
| 1950 | burnlo = HFA384x_ADDR_CMD_MKOFF(burndaddr); |
| 1951 | burnhi = HFA384x_ADDR_CMD_MKPAGE(burndaddr); |
| 1952 | |
Avinash Kumar | 263b8bb | 2013-09-06 22:21:49 +0530 | [diff] [blame] | 1953 | netdev_info(hw->wlandev->netdev, "Writing %d bytes to flash @0x%06x\n", |
Sherif Shehab Aldin | 3f2d656 | 2014-04-05 23:34:40 +0200 | [diff] [blame] | 1954 | burnlen, burndaddr); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1955 | |
| 1956 | /* Set the download mode */ |
| 1957 | result = hfa384x_cmd_download(hw, HFA384x_PROGMODE_NV, |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1958 | burnlo, burnhi, burnlen); |
| 1959 | if (result) { |
Sherif Shehab Aldin | a212013 | 2014-04-05 23:33:16 +0200 | [diff] [blame] | 1960 | 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-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1963 | goto exit_proc; |
| 1964 | } |
| 1965 | |
| 1966 | /* copy the data to the flash download buffer */ |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1967 | for (j = 0; j < nwrites; j++) { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1968 | writebuf = buf + |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1969 | (i * hw->bufinfo.len) + |
| 1970 | (j * HFA384x_USB_RWMEM_MAXLEN); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1971 | |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1972 | writepage = HFA384x_ADDR_CMD_MKPAGE(dlbufaddr + |
Edgardo Hames | 631c8de | 2010-03-08 17:02:37 -0800 | [diff] [blame] | 1973 | (j * HFA384x_USB_RWMEM_MAXLEN)); |
| 1974 | writeoffset = HFA384x_ADDR_CMD_MKOFF(dlbufaddr + |
| 1975 | (j * HFA384x_USB_RWMEM_MAXLEN)); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1976 | |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1977 | writelen = burnlen - (j * HFA384x_USB_RWMEM_MAXLEN); |
| 1978 | writelen = writelen > HFA384x_USB_RWMEM_MAXLEN ? |
| 1979 | HFA384x_USB_RWMEM_MAXLEN : writelen; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1980 | |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1981 | result = hfa384x_dowmem_wait(hw, |
| 1982 | writepage, |
| 1983 | writeoffset, |
| 1984 | writebuf, writelen); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1985 | } |
| 1986 | |
| 1987 | /* set the download 'write flash' mode */ |
| 1988 | result = hfa384x_cmd_download(hw, |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 1989 | HFA384x_PROGMODE_NVWRITE, |
| 1990 | 0, 0, 0); |
| 1991 | if (result) { |
Avinash Kumar | 263b8bb | 2013-09-06 22:21:49 +0530 | [diff] [blame] | 1992 | netdev_err(hw->wlandev->netdev, |
Sherif Shehab Aldin | 3f2d656 | 2014-04-05 23:34:40 +0200 | [diff] [blame] | 1993 | "download(NVWRITE,lo=%x,hi=%x,len=%x) cmd failed, result=%d. Aborting d/l\n", |
| 1994 | burnlo, burnhi, burnlen, result); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 1995 | goto exit_proc; |
| 1996 | } |
| 1997 | |
| 1998 | /* TODO: We really should do a readback and compare. */ |
| 1999 | } |
| 2000 | |
| 2001 | exit_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-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2007 | return result; |
| 2008 | } |
| 2009 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2010 | /*---------------------------------------------------------------- |
| 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 Hames | 631c8de | 2010-03-08 17:02:37 -0800 | [diff] [blame] | 2027 | * -ENODATA length mismatch between argument and retrieved |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2028 | * record. |
| 2029 | * |
| 2030 | * Side effects: |
| 2031 | * |
| 2032 | * Call context: |
| 2033 | * process |
| 2034 | ----------------------------------------------------------------*/ |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 2035 | int hfa384x_drvr_getconfig(struct hfa384x *hw, u16 rid, void *buf, u16 len) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2036 | { |
Devendra Naga | 102db1f | 2012-09-09 18:41:00 +0530 | [diff] [blame] | 2037 | return hfa384x_dorrid_wait(hw, rid, buf, len); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2038 | } |
| 2039 | |
| 2040 | /*---------------------------------------------------------------- |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2041 | * 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 | ----------------------------------------------------------------*/ |
| 2063 | int |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 2064 | hfa384x_drvr_setconfig_async(struct hfa384x *hw, |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2065 | u16 rid, |
| 2066 | void *buf, |
| 2067 | u16 len, ctlx_usercb_t usercb, void *usercb_data) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2068 | { |
| 2069 | return hfa384x_dowrid_async(hw, rid, buf, len, |
| 2070 | hfa384x_cb_status, usercb, usercb_data); |
| 2071 | } |
| 2072 | |
| 2073 | /*---------------------------------------------------------------- |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2074 | * 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 Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 2091 | int hfa384x_drvr_ramdl_disable(struct hfa384x *hw) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2092 | { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2093 | /* Check that we're already in the download state */ |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2094 | if (hw->dlstate != HFA384x_DLSTATE_RAMENABLED) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2095 | return -EINVAL; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2096 | |
Moritz Muehlenhoff | a7cf7ba | 2009-02-08 02:01:00 +0100 | [diff] [blame] | 2097 | pr_debug("ramdl_disable()\n"); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2098 | |
| 2099 | /* There isn't much we can do at this point, so I don't */ |
| 2100 | /* bother w/ the return value */ |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2101 | hfa384x_cmd_download(hw, HFA384x_PROGMODE_DISABLE, 0, 0, 0); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2102 | hw->dlstate = HFA384x_DLSTATE_DISABLED; |
| 2103 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2104 | return 0; |
| 2105 | } |
| 2106 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2107 | /*---------------------------------------------------------------- |
| 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 Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 2131 | int hfa384x_drvr_ramdl_enable(struct hfa384x *hw, u32 exeaddr) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2132 | { |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2133 | int result = 0; |
| 2134 | u16 lowaddr; |
| 2135 | u16 hiaddr; |
| 2136 | int i; |
Moritz Muehlenhoff | 8a251b5 | 2009-01-21 22:00:44 +0100 | [diff] [blame] | 2137 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2138 | /* Check that a port isn't active */ |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2139 | for (i = 0; i < HFA384x_PORTID_MAX; i++) { |
| 2140 | if (hw->port_enabled[i]) { |
Avinash Kumar | 263b8bb | 2013-09-06 22:21:49 +0530 | [diff] [blame] | 2141 | netdev_err(hw->wlandev->netdev, |
Sherif Shehab Aldin | 3f2d656 | 2014-04-05 23:34:40 +0200 | [diff] [blame] | 2142 | "Can't download with a macport enabled.\n"); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2143 | return -EINVAL; |
| 2144 | } |
| 2145 | } |
| 2146 | |
| 2147 | /* Check that we're not already in a download state */ |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2148 | if (hw->dlstate != HFA384x_DLSTATE_DISABLED) { |
Avinash Kumar | 263b8bb | 2013-09-06 22:21:49 +0530 | [diff] [blame] | 2149 | netdev_err(hw->wlandev->netdev, "Download state not disabled.\n"); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2150 | return -EINVAL; |
| 2151 | } |
| 2152 | |
Moritz Muehlenhoff | a7cf7ba | 2009-02-08 02:01:00 +0100 | [diff] [blame] | 2153 | pr_debug("ramdl_enable, exeaddr=0x%08x\n", exeaddr); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2154 | |
| 2155 | /* Call the download(1,addr) function */ |
| 2156 | lowaddr = HFA384x_ADDR_CMD_MKOFF(exeaddr); |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2157 | hiaddr = HFA384x_ADDR_CMD_MKPAGE(exeaddr); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2158 | |
| 2159 | result = hfa384x_cmd_download(hw, HFA384x_PROGMODE_RAM, |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2160 | lowaddr, hiaddr, 0); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2161 | |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2162 | if (result == 0) { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2163 | /* Set the download state */ |
| 2164 | hw->dlstate = HFA384x_DLSTATE_RAMENABLED; |
| 2165 | } else { |
Mithlesh Thukral | 75f49e0 | 2009-05-25 19:06:16 +0530 | [diff] [blame] | 2166 | pr_debug("cmd_download(0x%04x, 0x%04x) failed, result=%d.\n", |
| 2167 | lowaddr, hiaddr, result); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2168 | } |
| 2169 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2170 | return result; |
| 2171 | } |
| 2172 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2173 | /*---------------------------------------------------------------- |
| 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 Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 2199 | int hfa384x_drvr_ramdl_write(struct hfa384x *hw, u32 daddr, void *buf, u32 len) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2200 | { |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2201 | 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 Muehlenhoff | 8a251b5 | 2009-01-21 22:00:44 +0100 | [diff] [blame] | 2209 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2210 | /* Check that we're in the ram download state */ |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2211 | if (hw->dlstate != HFA384x_DLSTATE_RAMENABLED) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2212 | return -EINVAL; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2213 | |
Sherif Shehab Aldin | a212013 | 2014-04-05 23:33:16 +0200 | [diff] [blame] | 2214 | netdev_info(hw->wlandev->netdev, "Writing %d bytes to ram @0x%06x\n", |
| 2215 | len, daddr); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2216 | |
| 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 Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2222 | for (i = 0; i < nwrites; i++) { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2223 | /* 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 Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2228 | if (currlen > HFA384x_USB_RWMEM_MAXLEN) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2229 | currlen = HFA384x_USB_RWMEM_MAXLEN; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2230 | |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2231 | /* 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-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2238 | |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2239 | if (result) |
| 2240 | break; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2241 | |
| 2242 | /* TODO: We really should have a readback. */ |
| 2243 | } |
| 2244 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2245 | return result; |
| 2246 | } |
| 2247 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2248 | /*---------------------------------------------------------------- |
| 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 Iida | 1a6dfce | 2014-12-01 00:29:00 +0900 | [diff] [blame] | 2266 | * -ETIMEDOUT timeout waiting for the cmd regs to become |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2267 | * 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 Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 2279 | int hfa384x_drvr_readpda(struct hfa384x *hw, void *buf, unsigned int len) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2280 | { |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2281 | 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-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2291 | struct pdaloc { |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2292 | 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-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2299 | }; |
| 2300 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2301 | /* Read the pda from each known address. */ |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2302 | for (i = 0; i < ARRAY_SIZE(pdaloc); i++) { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2303 | /* Make address */ |
| 2304 | currpage = HFA384x_ADDR_CMD_MKPAGE(pdaloc[i].cardaddr); |
| 2305 | curroffset = HFA384x_ADDR_CMD_MKOFF(pdaloc[i].cardaddr); |
| 2306 | |
Edgardo Hames | 631c8de | 2010-03-08 17:02:37 -0800 | [diff] [blame] | 2307 | /* units of bytes */ |
| 2308 | result = hfa384x_dormem_wait(hw, currpage, curroffset, buf, |
| 2309 | len); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2310 | |
| 2311 | if (result) { |
Avinash Kumar | 263b8bb | 2013-09-06 22:21:49 +0530 | [diff] [blame] | 2312 | netdev_warn(hw->wlandev->netdev, |
Sherif Shehab Aldin | 3f2d656 | 2014-04-05 23:34:40 +0200 | [diff] [blame] | 2313 | "Read from index %zd failed, continuing\n", |
| 2314 | i); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2315 | continue; |
| 2316 | } |
| 2317 | |
| 2318 | /* Test for garbage */ |
| 2319 | pdaok = 1; /* initially assume good */ |
| 2320 | morepdrs = 1; |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2321 | while (pdaok && morepdrs) { |
Moritz Muehlenhoff | 18c7f79 | 2009-02-18 19:50:07 +0100 | [diff] [blame] | 2322 | pdrlen = le16_to_cpu(pda[currpdr]) * 2; |
| 2323 | pdrcode = le16_to_cpu(pda[currpdr + 1]); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2324 | /* Test the record length */ |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2325 | if (pdrlen > HFA384x_PDR_LEN_MAX || pdrlen == 0) { |
Sherif Shehab Aldin | a212013 | 2014-04-05 23:33:16 +0200 | [diff] [blame] | 2326 | netdev_err(hw->wlandev->netdev, |
| 2327 | "pdrlen invalid=%d\n", pdrlen); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2328 | pdaok = 0; |
| 2329 | break; |
| 2330 | } |
| 2331 | /* Test the code */ |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2332 | if (!hfa384x_isgood_pdrcode(pdrcode)) { |
Avinash Kumar | 263b8bb | 2013-09-06 22:21:49 +0530 | [diff] [blame] | 2333 | netdev_err(hw->wlandev->netdev, "pdrcode invalid=%d\n", |
Sherif Shehab Aldin | 3f2d656 | 2014-04-05 23:34:40 +0200 | [diff] [blame] | 2334 | pdrcode); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2335 | pdaok = 0; |
| 2336 | break; |
| 2337 | } |
| 2338 | /* Test for completion */ |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2339 | if (pdrcode == HFA384x_PDR_END_OF_PDA) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2340 | morepdrs = 0; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2341 | |
| 2342 | /* Move to the next pdr (if necessary) */ |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2343 | if (morepdrs) { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2344 | /* note the access to pda[], need words here */ |
Moritz Muehlenhoff | 18c7f79 | 2009-02-18 19:50:07 +0100 | [diff] [blame] | 2345 | currpdr += le16_to_cpu(pda[currpdr]) + 1; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2346 | } |
| 2347 | } |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2348 | if (pdaok) { |
Avinash Kumar | 263b8bb | 2013-09-06 22:21:49 +0530 | [diff] [blame] | 2349 | netdev_info(hw->wlandev->netdev, |
Sherif Shehab Aldin | 3f2d656 | 2014-04-05 23:34:40 +0200 | [diff] [blame] | 2350 | "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-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2357 | break; |
| 2358 | } |
| 2359 | } |
| 2360 | result = pdaok ? 0 : -ENODATA; |
| 2361 | |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2362 | if (result) |
Moritz Muehlenhoff | a7cf7ba | 2009-02-08 02:01:00 +0100 | [diff] [blame] | 2363 | pr_debug("Failure: pda is not okay\n"); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2364 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2365 | return result; |
| 2366 | } |
| 2367 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2368 | /*---------------------------------------------------------------- |
| 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 Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 2389 | int hfa384x_drvr_setconfig(struct hfa384x *hw, u16 rid, void *buf, u16 len) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2390 | { |
| 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 Kennedy | 7b7e7e8 | 2008-11-03 11:16:09 +0000 | [diff] [blame] | 2413 | |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 2414 | int hfa384x_drvr_start(struct hfa384x *hw) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2415 | { |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2416 | int result, result1, result2; |
| 2417 | u16 status; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2418 | |
| 2419 | might_sleep(); |
| 2420 | |
Richard Kennedy | 7b7e7e8 | 2008-11-03 11:16:09 +0000 | [diff] [blame] | 2421 | /* 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 Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2426 | result = |
| 2427 | usb_get_status(hw->usb, USB_RECIP_ENDPOINT, hw->endp_in, &status); |
Richard Kennedy | 7b7e7e8 | 2008-11-03 11:16:09 +0000 | [diff] [blame] | 2428 | if (result < 0) { |
Avinash Kumar | 263b8bb | 2013-09-06 22:21:49 +0530 | [diff] [blame] | 2429 | netdev_err(hw->wlandev->netdev, "Cannot get bulk in endpoint status.\n"); |
Richard Kennedy | 7b7e7e8 | 2008-11-03 11:16:09 +0000 | [diff] [blame] | 2430 | goto done; |
| 2431 | } |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2432 | if ((status == 1) && usb_clear_halt(hw->usb, hw->endp_in)) |
Avinash Kumar | 263b8bb | 2013-09-06 22:21:49 +0530 | [diff] [blame] | 2433 | netdev_err(hw->wlandev->netdev, "Failed to reset bulk in endpoint.\n"); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2434 | |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2435 | result = |
| 2436 | usb_get_status(hw->usb, USB_RECIP_ENDPOINT, hw->endp_out, &status); |
Richard Kennedy | 7b7e7e8 | 2008-11-03 11:16:09 +0000 | [diff] [blame] | 2437 | if (result < 0) { |
Avinash Kumar | 263b8bb | 2013-09-06 22:21:49 +0530 | [diff] [blame] | 2438 | netdev_err(hw->wlandev->netdev, "Cannot get bulk out endpoint status.\n"); |
Richard Kennedy | 7b7e7e8 | 2008-11-03 11:16:09 +0000 | [diff] [blame] | 2439 | goto done; |
| 2440 | } |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2441 | if ((status == 1) && usb_clear_halt(hw->usb, hw->endp_out)) |
Avinash Kumar | 263b8bb | 2013-09-06 22:21:49 +0530 | [diff] [blame] | 2442 | netdev_err(hw->wlandev->netdev, "Failed to reset bulk out endpoint.\n"); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2443 | |
| 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 Kumar | 263b8bb | 2013-09-06 22:21:49 +0530 | [diff] [blame] | 2450 | netdev_err(hw->wlandev->netdev, |
Sherif Shehab Aldin | 3f2d656 | 2014-04-05 23:34:40 +0200 | [diff] [blame] | 2451 | "Fatal, failed to submit RX URB, result=%d\n", |
| 2452 | result); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2453 | goto done; |
| 2454 | } |
| 2455 | |
Richard Kennedy | 7b7e7e8 | 2008-11-03 11:16:09 +0000 | [diff] [blame] | 2456 | /* 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 Aldin | 96b1971 | 2014-04-05 23:34:56 +0200 | [diff] [blame] | 2468 | result = hfa384x_cmd_initialize(hw); |
| 2469 | result2 = result; |
Richard Kennedy | 7b7e7e8 | 2008-11-03 11:16:09 +0000 | [diff] [blame] | 2470 | if (result1 != 0) { |
| 2471 | if (result2 != 0) { |
Avinash Kumar | 263b8bb | 2013-09-06 22:21:49 +0530 | [diff] [blame] | 2472 | netdev_err(hw->wlandev->netdev, |
Sherif Shehab Aldin | 3f2d656 | 2014-04-05 23:34:40 +0200 | [diff] [blame] | 2473 | "cmd_initialize() failed on two attempts, results %d and %d\n", |
| 2474 | result1, result2); |
Richard Kennedy | 7b7e7e8 | 2008-11-03 11:16:09 +0000 | [diff] [blame] | 2475 | usb_kill_urb(&hw->rx_urb); |
| 2476 | goto done; |
| 2477 | } else { |
Mithlesh Thukral | 75f49e0 | 2009-05-25 19:06:16 +0530 | [diff] [blame] | 2478 | pr_debug("First cmd_initialize() failed (result %d),\n", |
| 2479 | result1); |
Edgardo Hames | 4ffab68 | 2010-03-15 23:00:40 -0300 | [diff] [blame] | 2480 | pr_debug("but second attempt succeeded. All should be ok\n"); |
Richard Kennedy | 7b7e7e8 | 2008-11-03 11:16:09 +0000 | [diff] [blame] | 2481 | } |
| 2482 | } else if (result2 != 0) { |
Avinash Kumar | 263b8bb | 2013-09-06 22:21:49 +0530 | [diff] [blame] | 2483 | netdev_warn(hw->wlandev->netdev, "First cmd_initialize() succeeded, but second attempt failed (result=%d)\n", |
Sherif Shehab Aldin | 3f2d656 | 2014-04-05 23:34:40 +0200 | [diff] [blame] | 2484 | result2); |
Avinash Kumar | 263b8bb | 2013-09-06 22:21:49 +0530 | [diff] [blame] | 2485 | netdev_warn(hw->wlandev->netdev, |
Sherif Shehab Aldin | 3f2d656 | 2014-04-05 23:34:40 +0200 | [diff] [blame] | 2486 | "Most likely the card will be functional\n"); |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2487 | goto done; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2488 | } |
| 2489 | |
| 2490 | hw->state = HFA384x_STATE_RUNNING; |
| 2491 | |
| 2492 | done: |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2493 | return result; |
| 2494 | } |
| 2495 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2496 | /*---------------------------------------------------------------- |
| 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 Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 2515 | int hfa384x_drvr_stop(struct hfa384x *hw) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2516 | { |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2517 | int i; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2518 | |
| 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 Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2524 | if (!hw->wlandev->hwremoved) { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2525 | /* 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 Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2538 | for (i = 0; i < HFA384x_NUMPORTS_MAX; i++) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2539 | hw->port_enabled[i] = 0; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2540 | |
Peter Senna Tschudin | 4764ca9 | 2014-05-26 16:08:50 +0200 | [diff] [blame] | 2541 | return 0; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2542 | } |
| 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 Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 2565 | int hfa384x_drvr_txframe(struct hfa384x *hw, struct sk_buff *skb, |
Edgardo Hames | 93df38e | 2010-07-30 22:51:55 -0300 | [diff] [blame] | 2566 | union p80211_hdr *p80211_hdr, |
Edgardo Hames | 51e4896 | 2010-07-31 13:06:52 -0300 | [diff] [blame] | 2567 | struct p80211_metawep *p80211_wep) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2568 | { |
Sergio Paracuellos | eb76afc | 2016-09-28 20:19:05 +0200 | [diff] [blame] | 2569 | int usbpktlen = sizeof(struct hfa384x_tx_frame); |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2570 | int result; |
| 2571 | int ret; |
| 2572 | char *ptr; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2573 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2574 | if (hw->tx_urb.status == -EINPROGRESS) { |
Avinash Kumar | 263b8bb | 2013-09-06 22:21:49 +0530 | [diff] [blame] | 2575 | netdev_warn(hw->wlandev->netdev, "TX URB already in use\n"); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2576 | 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 Muehlenhoff | 18c7f79 | 2009-02-18 19:50:07 +0100 | [diff] [blame] | 2585 | hw->txbuff.type = cpu_to_le16(HFA384x_USB_TXFRM); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2586 | |
| 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 Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2593 | /* #define DOEXC SLP -- doboth breaks horribly under load, doexc less so. */ |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2594 | #if defined(DOBOTH) |
| 2595 | hw->txbuff.txfrm.desc.tx_control = |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2596 | HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) | |
| 2597 | HFA384x_TX_TXEX_SET(1) | HFA384x_TX_TXOK_SET(1); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2598 | #elif defined(DOEXC) |
| 2599 | hw->txbuff.txfrm.desc.tx_control = |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2600 | HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) | |
| 2601 | HFA384x_TX_TXEX_SET(1) | HFA384x_TX_TXOK_SET(0); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2602 | #else |
| 2603 | hw->txbuff.txfrm.desc.tx_control = |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2604 | HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) | |
| 2605 | HFA384x_TX_TXEX_SET(0) | HFA384x_TX_TXOK_SET(0); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2606 | #endif |
| 2607 | hw->txbuff.txfrm.desc.tx_control = |
Moritz Muehlenhoff | 18c7f79 | 2009-02-18 19:50:07 +0100 | [diff] [blame] | 2608 | cpu_to_le16(hw->txbuff.txfrm.desc.tx_control); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2609 | |
| 2610 | /* copy the header over to the txdesc */ |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2611 | memcpy(&(hw->txbuff.txfrm.desc.frame_control), p80211_hdr, |
Edgardo Hames | 93df38e | 2010-07-30 22:51:55 -0300 | [diff] [blame] | 2612 | sizeof(union p80211_hdr)); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2613 | |
| 2614 | /* if we're using host WEP, increase size by IV+ICV */ |
| 2615 | if (p80211_wep->data) { |
Moritz Muehlenhoff | 18c7f79 | 2009-02-18 19:50:07 +0100 | [diff] [blame] | 2616 | hw->txbuff.txfrm.desc.data_len = cpu_to_le16(skb->len + 8); |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2617 | usbpktlen += 8; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2618 | } else { |
Moritz Muehlenhoff | 18c7f79 | 2009-02-18 19:50:07 +0100 | [diff] [blame] | 2619 | hw->txbuff.txfrm.desc.data_len = cpu_to_le16(skb->len); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2620 | } |
| 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 Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2628 | ptr += sizeof(p80211_wep->iv); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2629 | memcpy(ptr, p80211_wep->data, skb->len); |
| 2630 | } else { |
| 2631 | memcpy(ptr, skb->data, skb->len); |
| 2632 | } |
| 2633 | /* copy over the packet data */ |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2634 | ptr += skb->len; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2635 | |
| 2636 | /* copy over the WEP ICV if we are using host WEP */ |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2637 | if (p80211_wep->data) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2638 | memcpy(ptr, p80211_wep->icv, sizeof(p80211_wep->icv)); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2639 | |
| 2640 | /* Send the USB packet */ |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2641 | 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-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2645 | hw->tx_urb.transfer_flags |= USB_QUEUE_BULK; |
| 2646 | |
| 2647 | result = 1; |
| 2648 | ret = submit_tx_urb(hw, &hw->tx_urb, GFP_ATOMIC); |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2649 | if (ret != 0) { |
Sherif Shehab Aldin | a212013 | 2014-04-05 23:33:16 +0200 | [diff] [blame] | 2650 | netdev_err(hw->wlandev->netdev, |
| 2651 | "submit_tx_urb() failed, error=%d\n", ret); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2652 | result = 3; |
| 2653 | } |
| 2654 | |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2655 | exit: |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2656 | return result; |
| 2657 | } |
| 2658 | |
sayli karnik | c9573a8 | 2016-09-18 15:11:14 +0530 | [diff] [blame] | 2659 | void hfa384x_tx_timeout(struct wlandevice *wlandev) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2660 | { |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 2661 | struct hfa384x *hw = wlandev->priv; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2662 | unsigned long flags; |
| 2663 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2664 | spin_lock_irqsave(&hw->ctlxq.lock, flags); |
| 2665 | |
Dan Carpenter | 5945789 | 2010-06-17 14:08:47 +0200 | [diff] [blame] | 2666 | 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-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2673 | } |
| 2674 | |
| 2675 | spin_unlock_irqrestore(&hw->ctlxq.lock, flags); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2676 | } |
| 2677 | |
| 2678 | /*---------------------------------------------------------------- |
| 2679 | * hfa384x_usbctlx_reaper_task |
| 2680 | * |
| 2681 | * Tasklet to delete dead CTLX objects |
| 2682 | * |
| 2683 | * Arguments: |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 2684 | * data ptr to a struct hfa384x |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2685 | * |
| 2686 | * Returns: |
| 2687 | * |
| 2688 | * Call context: |
| 2689 | * Interrupt |
| 2690 | ----------------------------------------------------------------*/ |
| 2691 | static void hfa384x_usbctlx_reaper_task(unsigned long data) |
| 2692 | { |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 2693 | struct hfa384x *hw = (struct hfa384x *)data; |
Sergio Paracuellos | a10d36b | 2016-09-28 20:20:16 +0200 | [diff] [blame] | 2694 | struct hfa384x_usbctlx *ctlx, *temp; |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2695 | unsigned long flags; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2696 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2697 | 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 Tang | 57477bf | 2015-12-15 23:29:32 +0800 | [diff] [blame] | 2702 | list_for_each_entry_safe(ctlx, temp, &hw->ctlxq.reapable, list) { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2703 | list_del(&ctlx->list); |
| 2704 | kfree(ctlx); |
| 2705 | } |
| 2706 | |
| 2707 | spin_unlock_irqrestore(&hw->ctlxq.lock, flags); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2708 | } |
| 2709 | |
| 2710 | /*---------------------------------------------------------------- |
| 2711 | * hfa384x_usbctlx_completion_task |
| 2712 | * |
| 2713 | * Tasklet to call completion handlers for returned CTLXs |
| 2714 | * |
| 2715 | * Arguments: |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 2716 | * data ptr to struct hfa384x |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2717 | * |
| 2718 | * Returns: |
| 2719 | * Nothing |
| 2720 | * |
| 2721 | * Call context: |
| 2722 | * Interrupt |
| 2723 | ----------------------------------------------------------------*/ |
| 2724 | static void hfa384x_usbctlx_completion_task(unsigned long data) |
| 2725 | { |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 2726 | struct hfa384x *hw = (struct hfa384x *)data; |
Sergio Paracuellos | a10d36b | 2016-09-28 20:20:16 +0200 | [diff] [blame] | 2727 | struct hfa384x_usbctlx *ctlx, *temp; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2728 | unsigned long flags; |
| 2729 | |
| 2730 | int reap = 0; |
| 2731 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2732 | 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 Tang | 57477bf | 2015-12-15 23:29:32 +0800 | [diff] [blame] | 2737 | list_for_each_entry_safe(ctlx, temp, &hw->ctlxq.completing, list) { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2738 | /* Call the completion function that this |
| 2739 | * command was assigned, assuming it has one. |
| 2740 | */ |
Nicholas Sim | 02e0204 | 2016-04-05 17:37:12 +0100 | [diff] [blame] | 2741 | if (ctlx->cmdcb) { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2742 | 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 Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2754 | if (hw->wlandev->hwremoved) { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2755 | 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 Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2765 | if (ctlx->reapable) { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2766 | /* 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-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2781 | } |
| 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 Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 2790 | * hw ptr to the struct hfa384x structure |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2791 | * 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 Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 2800 | static int unlocked_usbctlx_cancel_async(struct hfa384x *hw, |
Sergio Paracuellos | a10d36b | 2016-09-28 20:20:16 +0200 | [diff] [blame] | 2801 | struct hfa384x_usbctlx *ctlx) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2802 | { |
| 2803 | int ret; |
| 2804 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2805 | /* |
| 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-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2825 | 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 Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 2839 | * hw ptr to a struct hfa384x structure |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2840 | * 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 Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 2850 | static void unlocked_usbctlx_complete(struct hfa384x *hw, struct hfa384x_usbctlx *ctlx) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2851 | { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2852 | /* 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 Kumar | 263b8bb | 2013-09-06 22:21:49 +0530 | [diff] [blame] | 2866 | netdev_err(hw->wlandev->netdev, "CTLX[%d] not in a terminating state(%s)\n", |
Sherif Shehab Aldin | 3f2d656 | 2014-04-05 23:34:40 +0200 | [diff] [blame] | 2867 | le16_to_cpu(ctlx->outbuf.type), |
| 2868 | ctlxstr(ctlx->state)); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2869 | break; |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2870 | } /* switch */ |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2871 | } |
| 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 Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 2879 | * hw ptr to struct hfa384x |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2880 | * |
| 2881 | * Returns: |
| 2882 | * nothing |
| 2883 | * |
| 2884 | * Side effects: |
| 2885 | * |
| 2886 | * Call context: |
| 2887 | * any |
| 2888 | ----------------------------------------------------------------*/ |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 2889 | static void hfa384x_usbctlxq_run(struct hfa384x *hw) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2890 | { |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2891 | unsigned long flags; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2892 | |
| 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 Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2903 | if (!list_empty(&hw->ctlxq.active) || |
| 2904 | test_bit(WORK_TX_HALT, &hw->usb_flags) || hw->wlandev->hwremoved) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2905 | goto unlock; |
| 2906 | |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2907 | while (!list_empty(&hw->ctlxq.pending)) { |
Sergio Paracuellos | a10d36b | 2016-09-28 20:20:16 +0200 | [diff] [blame] | 2908 | struct hfa384x_usbctlx *head; |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2909 | int result; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2910 | |
| 2911 | /* This is the first pending command */ |
| 2912 | head = list_entry(hw->ctlxq.pending.next, |
Sergio Paracuellos | a10d36b | 2016-09-28 20:20:16 +0200 | [diff] [blame] | 2913 | struct hfa384x_usbctlx, list); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2914 | |
| 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 Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2919 | 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-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2923 | hw->ctlx_urb.transfer_flags |= USB_QUEUE_BULK; |
| 2924 | |
Andrew Elwell | 3f4b4e7 | 2010-02-18 23:56:13 +0100 | [diff] [blame] | 2925 | /* Now submit the URB and update the CTLX's state */ |
Amitoj Kaur Chawla | 5850c25 | 2016-02-24 21:55:49 +0530 | [diff] [blame] | 2926 | result = usb_submit_urb(&hw->ctlx_urb, GFP_ATOMIC); |
Svenne Krap | 46800b2 | 2010-02-14 18:59:42 +0100 | [diff] [blame] | 2927 | if (result == 0) { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2928 | /* 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 Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2938 | hw->resptimer.expires = jiffies + 2 * HZ; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2939 | 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 Kumar | 263b8bb | 2013-09-06 22:21:49 +0530 | [diff] [blame] | 2949 | netdev_warn(hw->wlandev->netdev, |
Sherif Shehab Aldin | 3f2d656 | 2014-04-05 23:34:40 +0200 | [diff] [blame] | 2950 | "%s tx pipe stalled: requesting reset\n", |
| 2951 | hw->wlandev->netdev->name); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2952 | 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 Kumar | 263b8bb | 2013-09-06 22:21:49 +0530 | [diff] [blame] | 2959 | netdev_warn(hw->wlandev->netdev, "%s urb shutdown!\n", |
Sherif Shehab Aldin | 3f2d656 | 2014-04-05 23:34:40 +0200 | [diff] [blame] | 2960 | hw->wlandev->netdev->name); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2961 | break; |
| 2962 | } |
| 2963 | |
Avinash Kumar | 263b8bb | 2013-09-06 22:21:49 +0530 | [diff] [blame] | 2964 | netdev_err(hw->wlandev->netdev, "Failed to submit CTLX[%d]: error=%d\n", |
Sherif Shehab Aldin | 3f2d656 | 2014-04-05 23:34:40 +0200 | [diff] [blame] | 2965 | le16_to_cpu(head->outbuf.type), result); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2966 | unlocked_usbctlx_complete(hw, head); |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2967 | } /* while */ |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2968 | |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2969 | unlock: |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2970 | spin_unlock_irqrestore(&hw->ctlxq.lock, flags); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2971 | } |
| 2972 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2973 | /*---------------------------------------------------------------- |
| 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-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2989 | static void hfa384x_usbin_callback(struct urb *urb) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2990 | { |
sayli karnik | c9573a8 | 2016-09-18 15:11:14 +0530 | [diff] [blame] | 2991 | struct wlandevice *wlandev = urb->context; |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 2992 | struct hfa384x *hw; |
Sergio Paracuellos | 3e4180c | 2016-09-28 20:19:38 +0200 | [diff] [blame] | 2993 | union hfa384x_usbin *usbin = (union hfa384x_usbin *)urb->transfer_buffer; |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 2994 | struct sk_buff *skb = NULL; |
| 2995 | int result; |
| 2996 | int urb_status; |
| 2997 | u16 type; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2998 | |
| 2999 | enum USBIN_ACTION { |
| 3000 | HANDLE, |
| 3001 | RESUBMIT, |
| 3002 | ABORT |
| 3003 | } action; |
| 3004 | |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3005 | if (!wlandev || !wlandev->netdev || wlandev->hwremoved) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3006 | goto exit; |
| 3007 | |
| 3008 | hw = wlandev->priv; |
| 3009 | if (!hw) |
| 3010 | goto exit; |
| 3011 | |
| 3012 | skb = hw->rx_urb_skb; |
Stoyan Gaydarov | 2961f24 | 2009-03-10 00:10:27 -0500 | [diff] [blame] | 3013 | BUG_ON(!skb || (skb->data != urb->transfer_buffer)); |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3014 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3015 | 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 Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3023 | if (urb->actual_length == 0) { |
Tobias Klauser | 9630f6b | 2014-07-08 08:37:00 +0200 | [diff] [blame] | 3024 | wlandev->netdev->stats.rx_errors++; |
| 3025 | wlandev->netdev->stats.rx_length_errors++; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3026 | action = RESUBMIT; |
| 3027 | } |
| 3028 | break; |
| 3029 | |
| 3030 | case -EPIPE: |
Avinash Kumar | 263b8bb | 2013-09-06 22:21:49 +0530 | [diff] [blame] | 3031 | netdev_warn(hw->wlandev->netdev, "%s rx pipe stalled: requesting reset\n", |
Sherif Shehab Aldin | 3f2d656 | 2014-04-05 23:34:40 +0200 | [diff] [blame] | 3032 | wlandev->netdev->name); |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3033 | if (!test_and_set_bit(WORK_RX_HALT, &hw->usb_flags)) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3034 | schedule_work(&hw->usb_work); |
Tobias Klauser | 9630f6b | 2014-07-08 08:37:00 +0200 | [diff] [blame] | 3035 | wlandev->netdev->stats.rx_errors++; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3036 | action = ABORT; |
| 3037 | break; |
| 3038 | |
| 3039 | case -EILSEQ: |
| 3040 | case -ETIMEDOUT: |
| 3041 | case -EPROTO: |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3042 | if (!test_and_set_bit(THROTTLE_RX, &hw->usb_flags) && |
| 3043 | !timer_pending(&hw->throttle)) { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3044 | mod_timer(&hw->throttle, jiffies + THROTTLE_JIFFIES); |
| 3045 | } |
Tobias Klauser | 9630f6b | 2014-07-08 08:37:00 +0200 | [diff] [blame] | 3046 | wlandev->netdev->stats.rx_errors++; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3047 | action = ABORT; |
| 3048 | break; |
| 3049 | |
| 3050 | case -EOVERFLOW: |
Tobias Klauser | 9630f6b | 2014-07-08 08:37:00 +0200 | [diff] [blame] | 3051 | wlandev->netdev->stats.rx_over_errors++; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3052 | action = RESUBMIT; |
| 3053 | break; |
| 3054 | |
| 3055 | case -ENODEV: |
| 3056 | case -ESHUTDOWN: |
Moritz Muehlenhoff | a7cf7ba | 2009-02-08 02:01:00 +0100 | [diff] [blame] | 3057 | pr_debug("status=%d, device removed.\n", urb->status); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3058 | action = ABORT; |
| 3059 | break; |
| 3060 | |
| 3061 | case -ENOENT: |
| 3062 | case -ECONNRESET: |
Mithlesh Thukral | 75f49e0 | 2009-05-25 19:06:16 +0530 | [diff] [blame] | 3063 | pr_debug("status=%d, urb explicitly unlinked.\n", urb->status); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3064 | action = ABORT; |
| 3065 | break; |
| 3066 | |
| 3067 | default: |
Moritz Muehlenhoff | a7cf7ba | 2009-02-08 02:01:00 +0100 | [diff] [blame] | 3068 | pr_debug("urb status=%d, transfer flags=0x%x\n", |
Mithlesh Thukral | 75f49e0 | 2009-05-25 19:06:16 +0530 | [diff] [blame] | 3069 | urb->status, urb->transfer_flags); |
Tobias Klauser | 9630f6b | 2014-07-08 08:37:00 +0200 | [diff] [blame] | 3070 | wlandev->netdev->stats.rx_errors++; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3071 | 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 Kumar | 263b8bb | 2013-09-06 22:21:49 +0530 | [diff] [blame] | 3082 | netdev_err(hw->wlandev->netdev, |
Sherif Shehab Aldin | 3f2d656 | 2014-04-05 23:34:40 +0200 | [diff] [blame] | 3083 | "Fatal, failed to resubmit rx_urb. error=%d\n", |
| 3084 | result); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3085 | } |
| 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 Muehlenhoff | 18c7f79 | 2009-02-18 19:50:07 +0100 | [diff] [blame] | 3092 | type = le16_to_cpu(usbin->type); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3093 | 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 Muehlenhoff | a7cf7ba | 2009-02-08 02:01:00 +0100 | [diff] [blame] | 3128 | pr_debug("Received BUFAVAIL packet, frmlen=%d\n", |
Mithlesh Thukral | 75f49e0 | 2009-05-25 19:06:16 +0530 | [diff] [blame] | 3129 | usbin->bufavail.frmlen); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3130 | break; |
| 3131 | |
| 3132 | case HFA384x_USB_ERROR: |
Moritz Muehlenhoff | a7cf7ba | 2009-02-08 02:01:00 +0100 | [diff] [blame] | 3133 | pr_debug("Received USB_ERROR packet, errortype=%d\n", |
Mithlesh Thukral | 75f49e0 | 2009-05-25 19:06:16 +0530 | [diff] [blame] | 3134 | usbin->usberror.errortype); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3135 | break; |
| 3136 | |
| 3137 | default: |
Mithlesh Thukral | 75f49e0 | 2009-05-25 19:06:16 +0530 | [diff] [blame] | 3138 | pr_debug("Unrecognized USBIN packet, type=%x, status=%d\n", |
| 3139 | usbin->type, urb_status); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3140 | break; |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3141 | } /* switch */ |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3142 | |
| 3143 | exit: |
| 3144 | |
| 3145 | if (skb) |
| 3146 | dev_kfree_skb(skb); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3147 | } |
| 3148 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3149 | /*---------------------------------------------------------------- |
| 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 Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 3157 | * hw ptr to struct hfa384x |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3158 | * 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 Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 3169 | static void hfa384x_usbin_ctlx(struct hfa384x *hw, union hfa384x_usbin *usbin, |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3170 | int urb_status) |
| 3171 | { |
Sergio Paracuellos | a10d36b | 2016-09-28 20:20:16 +0200 | [diff] [blame] | 3172 | struct hfa384x_usbctlx *ctlx; |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3173 | int run_queue = 0; |
| 3174 | unsigned long flags; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3175 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3176 | retry: |
| 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 Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3183 | if (list_empty(&hw->ctlxq.active)) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3184 | goto unlock; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3185 | |
| 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 Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3197 | } else { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3198 | 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 Vertz | a78d131 | 2015-01-18 09:11:39 +0200 | [diff] [blame] | 3212 | const __le16 intype = (usbin->type & ~cpu_to_le16(0x8000)); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3213 | |
| 3214 | /* |
| 3215 | * Check that our message is what we're expecting ... |
| 3216 | */ |
| 3217 | if (ctlx->outbuf.type != intype) { |
Avinash Kumar | 263b8bb | 2013-09-06 22:21:49 +0530 | [diff] [blame] | 3218 | netdev_warn(hw->wlandev->netdev, |
Sherif Shehab Aldin | 3f2d656 | 2014-04-05 23:34:40 +0200 | [diff] [blame] | 3219 | "Expected IN[%d], received IN[%d] - ignored.\n", |
| 3220 | le16_to_cpu(ctlx->outbuf.type), |
| 3221 | le16_to_cpu(intype)); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3222 | 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 Hames | 4ffab68 | 2010-03-15 23:00:40 -0300 | [diff] [blame] | 3235 | pr_debug("Causality violation: please reboot Universe\n"); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3236 | 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 Kumar | 263b8bb | 2013-09-06 22:21:49 +0530 | [diff] [blame] | 3254 | netdev_err(hw->wlandev->netdev, |
Sherif Shehab Aldin | 3f2d656 | 2014-04-05 23:34:40 +0200 | [diff] [blame] | 3255 | "Matched IN URB, CTLX[%d] in invalid state(%s). Discarded.\n", |
| 3256 | le16_to_cpu(ctlx->outbuf.type), |
| 3257 | ctlxstr(ctlx->state)); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3258 | if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0) |
| 3259 | run_queue = 1; |
| 3260 | break; |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3261 | } /* switch */ |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3262 | } |
| 3263 | |
| 3264 | unlock: |
| 3265 | spin_unlock_irqrestore(&hw->ctlxq.lock, flags); |
| 3266 | |
| 3267 | if (run_queue) |
| 3268 | hfa384x_usbctlxq_run(hw); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3269 | } |
| 3270 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3271 | /*---------------------------------------------------------------- |
| 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 karnik | c9573a8 | 2016-09-18 15:11:14 +0530 | [diff] [blame] | 3288 | static void hfa384x_usbin_txcompl(struct wlandevice *wlandev, |
Sergio Paracuellos | 3e4180c | 2016-09-28 20:19:38 +0200 | [diff] [blame] | 3289 | union hfa384x_usbin *usbin) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3290 | { |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3291 | u16 status; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3292 | |
Edgardo Hames | 631c8de | 2010-03-08 17:02:37 -0800 | [diff] [blame] | 3293 | status = le16_to_cpu(usbin->type); /* yeah I know it says type... */ |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3294 | |
| 3295 | /* Was there an error? */ |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3296 | if (HFA384x_TXSTATUS_ISERROR(status)) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3297 | prism2sta_ev_txexc(wlandev, status); |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3298 | else |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3299 | prism2sta_ev_tx(wlandev, status); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3300 | } |
| 3301 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3302 | /*---------------------------------------------------------------- |
| 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 karnik | c9573a8 | 2016-09-18 15:11:14 +0530 | [diff] [blame] | 3319 | static void hfa384x_usbin_rx(struct wlandevice *wlandev, struct sk_buff *skb) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3320 | { |
Sergio Paracuellos | 3e4180c | 2016-09-28 20:19:38 +0200 | [diff] [blame] | 3321 | union hfa384x_usbin *usbin = (union hfa384x_usbin *)skb->data; |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 3322 | struct hfa384x *hw = wlandev->priv; |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3323 | int hdrlen; |
Edgardo Hames | 51e4896 | 2010-07-31 13:06:52 -0300 | [diff] [blame] | 3324 | struct p80211_rxmeta *rxmeta; |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3325 | u16 data_len; |
| 3326 | u16 fc; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3327 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3328 | /* Byte order convert once up front. */ |
Moritz Muehlenhoff | 18c7f79 | 2009-02-18 19:50:07 +0100 | [diff] [blame] | 3329 | 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-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3331 | |
| 3332 | /* Now handle frame based on port# */ |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3333 | switch (HFA384x_RXSTATUS_MACPORT_GET(usbin->rxfrm.desc.status)) { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3334 | case 0: |
Moritz Muehlenhoff | ae26230 | 2009-01-21 22:00:45 +0100 | [diff] [blame] | 3335 | fc = le16_to_cpu(usbin->rxfrm.desc.frame_control); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3336 | |
| 3337 | /* If exclude and we receive an unencrypted, drop it */ |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3338 | if ((wlandev->hostwep & HOSTWEP_EXCLUDEUNENCRYPTED) && |
| 3339 | !WLAN_GET_FC_ISWEP(fc)) { |
Ilja Sidoroff | cc5bcbb | 2014-09-08 17:37:53 +0300 | [diff] [blame] | 3340 | break; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3341 | } |
| 3342 | |
Moritz Muehlenhoff | 18c7f79 | 2009-02-18 19:50:07 +0100 | [diff] [blame] | 3343 | data_len = le16_to_cpu(usbin->rxfrm.desc.data_len); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3344 | |
| 3345 | /* How much header data do we have? */ |
| 3346 | hdrlen = p80211_headerlen(fc); |
| 3347 | |
| 3348 | /* Pull off the descriptor */ |
Sergio Paracuellos | 70adf50 | 2016-09-28 20:19:06 +0200 | [diff] [blame] | 3349 | skb_pull(skb, sizeof(struct hfa384x_rx_frame)); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3350 | |
| 3351 | /* Now shunt the header block up against the data block |
| 3352 | * with an "overlapping" copy |
| 3353 | */ |
| 3354 | memmove(skb_push(skb, hdrlen), |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3355 | &usbin->rxfrm.desc.frame_control, hdrlen); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3356 | |
| 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 Chawla | 4e2cdf9 | 2015-10-31 15:51:04 +0530 | [diff] [blame] | 3376 | p80211netdev_rx(wlandev, skb); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3377 | |
| 3378 | break; |
| 3379 | |
| 3380 | case 7: |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3381 | if (!HFA384x_RXSTATUS_ISFCSERR(usbin->rxfrm.desc.status)) { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3382 | /* Copy to wlansnif skb */ |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3383 | hfa384x_int_rxmonitor(wlandev, &usbin->rxfrm); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3384 | dev_kfree_skb(skb); |
| 3385 | } else { |
Mithlesh Thukral | 75f49e0 | 2009-05-25 19:06:16 +0530 | [diff] [blame] | 3386 | pr_debug("Received monitor frame: FCSerr set\n"); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3387 | } |
| 3388 | break; |
| 3389 | |
| 3390 | default: |
Avinash Kumar | 263b8bb | 2013-09-06 22:21:49 +0530 | [diff] [blame] | 3391 | netdev_warn(hw->wlandev->netdev, "Received frame on unsupported port=%d\n", |
Sherif Shehab Aldin | 3f2d656 | 2014-04-05 23:34:40 +0200 | [diff] [blame] | 3392 | HFA384x_RXSTATUS_MACPORT_GET( |
| 3393 | usbin->rxfrm.desc.status)); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3394 | break; |
| 3395 | } |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3396 | } |
| 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 karnik | c9573a8 | 2016-09-18 15:11:14 +0530 | [diff] [blame] | 3419 | static void hfa384x_int_rxmonitor(struct wlandevice *wlandev, |
Sergio Paracuellos | 684b2e0 | 2016-09-28 20:19:28 +0200 | [diff] [blame] | 3420 | struct hfa384x_usb_rxfrm *rxfrm) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3421 | { |
Sergio Paracuellos | 70adf50 | 2016-09-28 20:19:06 +0200 | [diff] [blame] | 3422 | struct hfa384x_rx_frame *rxdesc = &(rxfrm->desc); |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3423 | 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 Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 3429 | struct hfa384x *hw = wlandev->priv; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3430 | |
Edgardo Hames | 631c8de | 2010-03-08 17:02:37 -0800 | [diff] [blame] | 3431 | /* Remember the status, time, and data_len fields are in host order */ |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3432 | /* Figure out how big the frame is */ |
Moritz Muehlenhoff | ae26230 | 2009-01-21 22:00:45 +0100 | [diff] [blame] | 3433 | fc = le16_to_cpu(rxdesc->frame_control); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3434 | hdrlen = p80211_headerlen(fc); |
Moritz Muehlenhoff | 18c7f79 | 2009-02-18 19:50:07 +0100 | [diff] [blame] | 3435 | datalen = le16_to_cpu(rxdesc->data_len); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3436 | |
| 3437 | /* Allocate an ind message+framesize skb */ |
Edgardo Hames | 51e4896 | 2010-07-31 13:06:52 -0300 | [diff] [blame] | 3438 | skblen = sizeof(struct p80211_caphdr) + hdrlen + datalen + WLAN_CRC_LEN; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3439 | |
| 3440 | /* sanity check the length */ |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3441 | if (skblen > |
Edgardo Hames | 51e4896 | 2010-07-31 13:06:52 -0300 | [diff] [blame] | 3442 | (sizeof(struct p80211_caphdr) + |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3443 | WLAN_HDR_A4_LEN + WLAN_DATA_MAXLEN + WLAN_CRC_LEN)) { |
Moritz Muehlenhoff | a7cf7ba | 2009-02-08 02:01:00 +0100 | [diff] [blame] | 3444 | pr_debug("overlen frm: len=%zd\n", |
Edgardo Hames | 51e4896 | 2010-07-31 13:06:52 -0300 | [diff] [blame] | 3445 | skblen - sizeof(struct p80211_caphdr)); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3446 | } |
| 3447 | |
Svenne Krap | 46800b2 | 2010-02-14 18:59:42 +0100 | [diff] [blame] | 3448 | skb = dev_alloc_skb(skblen); |
Eva Rachel Retuya | e2e7752 | 2016-02-27 20:39:25 +0800 | [diff] [blame] | 3449 | if (!skb) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3450 | return; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3451 | |
| 3452 | /* only prepend the prism header if in the right mode */ |
| 3453 | if ((wlandev->netdev->type == ARPHRD_IEEE80211_PRISM) && |
Solomon Peachy | cbec30c | 2008-10-29 10:42:57 -0400 | [diff] [blame] | 3454 | (hw->sniffhdr != 0)) { |
Edgardo Hames | 51e4896 | 2010-07-31 13:06:52 -0300 | [diff] [blame] | 3455 | struct p80211_caphdr *caphdr; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3456 | /* The NEW header format! */ |
Edgardo Hames | 51e4896 | 2010-07-31 13:06:52 -0300 | [diff] [blame] | 3457 | datap = skb_put(skb, sizeof(struct p80211_caphdr)); |
Sherif Shehab Aldin | 5d85fe3 | 2014-04-05 23:35:15 +0200 | [diff] [blame] | 3458 | caphdr = (struct p80211_caphdr *)datap; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3459 | |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3460 | caphdr->version = htonl(P80211CAPTURE_VERSION); |
Edgardo Hames | 51e4896 | 2010-07-31 13:06:52 -0300 | [diff] [blame] | 3461 | caphdr->length = htonl(sizeof(struct p80211_caphdr)); |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3462 | 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-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3474 | } |
| 3475 | |
Edgardo Hames | 631c8de | 2010-03-08 17:02:37 -0800 | [diff] [blame] | 3476 | /* Copy the 802.11 header to the skb |
| 3477 | (ctl frames may be less than a full header) */ |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3478 | datap = skb_put(skb, hdrlen); |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3479 | memcpy(datap, &(rxdesc->frame_control), hdrlen); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3480 | |
| 3481 | /* If any, copy the data from the card to the skb */ |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3482 | if (datalen > 0) { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3483 | datap = skb_put(skb, datalen); |
| 3484 | memcpy(datap, rxfrm->data, datalen); |
| 3485 | |
| 3486 | /* check for unencrypted stuff if WEP bit set. */ |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3487 | if (*(datap - hdrlen + 1) & 0x40) /* wep set */ |
| 3488 | if ((*(datap) == 0xaa) && (*(datap + 1) == 0xaa)) |
Edgardo Hames | 631c8de | 2010-03-08 17:02:37 -0800 | [diff] [blame] | 3489 | /* clear wep; it's the 802.2 header! */ |
| 3490 | *(datap - hdrlen + 1) &= 0xbf; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3491 | } |
| 3492 | |
| 3493 | if (hw->sniff_fcs) { |
| 3494 | /* Set the FCS */ |
| 3495 | datap = skb_put(skb, WLAN_CRC_LEN); |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3496 | memset(datap, 0xff, WLAN_CRC_LEN); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3497 | } |
| 3498 | |
| 3499 | /* pass it back up */ |
Amitoj Kaur Chawla | 4e2cdf9 | 2015-10-31 15:51:04 +0530 | [diff] [blame] | 3500 | p80211netdev_rx(wlandev, skb); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3501 | } |
| 3502 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3503 | /*---------------------------------------------------------------- |
| 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 Paracuellos | 3e4180c | 2016-09-28 20:19:38 +0200 | [diff] [blame] | 3520 | static void hfa384x_usbin_info(struct wlandevice *wlandev, |
| 3521 | union hfa384x_usbin *usbin) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3522 | { |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3523 | usbin->infofrm.info.framelen = |
Moritz Muehlenhoff | 18c7f79 | 2009-02-18 19:50:07 +0100 | [diff] [blame] | 3524 | le16_to_cpu(usbin->infofrm.info.framelen); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3525 | prism2sta_ev_info(wlandev, &usbin->infofrm.info); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3526 | } |
| 3527 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3528 | /*---------------------------------------------------------------- |
| 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-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3544 | static void hfa384x_usbout_callback(struct urb *urb) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3545 | { |
sayli karnik | c9573a8 | 2016-09-18 15:11:14 +0530 | [diff] [blame] | 3546 | struct wlandevice *wlandev = urb->context; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3547 | |
| 3548 | #ifdef DEBUG_USB |
| 3549 | dbprint_urb(urb); |
| 3550 | #endif |
| 3551 | |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3552 | if (wlandev && wlandev->netdev) { |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3553 | switch (urb->status) { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3554 | case 0: |
Amitoj Kaur Chawla | 6ba714b | 2015-10-31 15:47:38 +0530 | [diff] [blame] | 3555 | prism2sta_ev_alloc(wlandev); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3556 | break; |
| 3557 | |
| 3558 | case -EPIPE: |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3559 | { |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 3560 | struct hfa384x *hw = wlandev->priv; |
Cheng-Wei Lee | 4d525ef | 2014-06-27 19:42:14 +0800 | [diff] [blame] | 3561 | |
Avinash Kumar | 263b8bb | 2013-09-06 22:21:49 +0530 | [diff] [blame] | 3562 | netdev_warn(hw->wlandev->netdev, |
Sherif Shehab Aldin | 3f2d656 | 2014-04-05 23:34:40 +0200 | [diff] [blame] | 3563 | "%s tx pipe stalled: requesting reset\n", |
| 3564 | wlandev->netdev->name); |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3565 | if (!test_and_set_bit |
| 3566 | (WORK_TX_HALT, &hw->usb_flags)) |
| 3567 | schedule_work(&hw->usb_work); |
Tobias Klauser | 9630f6b | 2014-07-08 08:37:00 +0200 | [diff] [blame] | 3568 | wlandev->netdev->stats.tx_errors++; |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3569 | break; |
| 3570 | } |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3571 | |
| 3572 | case -EPROTO: |
| 3573 | case -ETIMEDOUT: |
| 3574 | case -EILSEQ: |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3575 | { |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 3576 | struct hfa384x *hw = wlandev->priv; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3577 | |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3578 | if (!test_and_set_bit |
Sherif Shehab Aldin | a3542e6 | 2014-04-05 23:34:48 +0200 | [diff] [blame] | 3579 | (THROTTLE_TX, &hw->usb_flags) && |
| 3580 | !timer_pending(&hw->throttle)) { |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3581 | mod_timer(&hw->throttle, |
| 3582 | jiffies + THROTTLE_JIFFIES); |
| 3583 | } |
Tobias Klauser | 9630f6b | 2014-07-08 08:37:00 +0200 | [diff] [blame] | 3584 | wlandev->netdev->stats.tx_errors++; |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3585 | netif_stop_queue(wlandev->netdev); |
| 3586 | break; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3587 | } |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3588 | |
| 3589 | case -ENOENT: |
| 3590 | case -ESHUTDOWN: |
| 3591 | /* Ignorable errors */ |
| 3592 | break; |
| 3593 | |
| 3594 | default: |
Avinash Kumar | 263b8bb | 2013-09-06 22:21:49 +0530 | [diff] [blame] | 3595 | netdev_info(wlandev->netdev, "unknown urb->status=%d\n", |
Sherif Shehab Aldin | 3f2d656 | 2014-04-05 23:34:40 +0200 | [diff] [blame] | 3596 | urb->status); |
Tobias Klauser | 9630f6b | 2014-07-08 08:37:00 +0200 | [diff] [blame] | 3597 | wlandev->netdev->stats.tx_errors++; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3598 | break; |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3599 | } /* switch */ |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3600 | } |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3601 | } |
| 3602 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3603 | /*---------------------------------------------------------------- |
| 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-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3619 | static void hfa384x_ctlxout_callback(struct urb *urb) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3620 | { |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 3621 | struct hfa384x *hw = urb->context; |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3622 | int delete_resptimer = 0; |
| 3623 | int timer_ok = 1; |
| 3624 | int run_queue = 0; |
Sergio Paracuellos | a10d36b | 2016-09-28 20:20:16 +0200 | [diff] [blame] | 3625 | struct hfa384x_usbctlx *ctlx; |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3626 | unsigned long flags; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3627 | |
Moritz Muehlenhoff | a7cf7ba | 2009-02-08 02:01:00 +0100 | [diff] [blame] | 3628 | pr_debug("urb->status=%d\n", urb->status); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3629 | #ifdef DEBUG_USB |
| 3630 | dbprint_urb(urb); |
| 3631 | #endif |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3632 | if ((urb->status == -ESHUTDOWN) || |
Nicholas Sim | 02e0204 | 2016-04-05 17:37:12 +0100 | [diff] [blame] | 3633 | (urb->status == -ENODEV) || !hw) |
Devendra Naga | 89e6302 | 2012-09-09 18:40:54 +0530 | [diff] [blame] | 3634 | return; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3635 | |
| 3636 | retry: |
| 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 Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3645 | if (list_empty(&hw->ctlxq.active)) { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3646 | spin_unlock_irqrestore(&hw->ctlxq.lock, flags); |
Devendra Naga | 89e6302 | 2012-09-09 18:40:54 +0530 | [diff] [blame] | 3647 | return; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3648 | } |
| 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 Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3664 | } else { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3665 | hw->req_timer_done = 1; |
| 3666 | } |
| 3667 | |
| 3668 | ctlx = get_active_ctlx(hw); |
| 3669 | |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3670 | if (urb->status == 0) { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3671 | /* Request portion of a CTLX is successful */ |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3672 | switch (ctlx->state) { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3673 | 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 Kumar | 263b8bb | 2013-09-06 22:21:49 +0530 | [diff] [blame] | 3689 | netdev_err(hw->wlandev->netdev, |
Sherif Shehab Aldin | 3f2d656 | 2014-04-05 23:34:40 +0200 | [diff] [blame] | 3690 | "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-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3693 | break; |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3694 | } /* switch */ |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3695 | } else { |
| 3696 | /* If the pipe has stalled then we need to reset it */ |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3697 | if ((urb->status == -EPIPE) && |
| 3698 | !test_and_set_bit(WORK_TX_HALT, &hw->usb_flags)) { |
Avinash Kumar | 263b8bb | 2013-09-06 22:21:49 +0530 | [diff] [blame] | 3699 | netdev_warn(hw->wlandev->netdev, |
Sherif Shehab Aldin | 3f2d656 | 2014-04-05 23:34:40 +0200 | [diff] [blame] | 3700 | "%s tx pipe stalled: requesting reset\n", |
| 3701 | hw->wlandev->netdev->name); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3702 | 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 Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3714 | delresp: |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3715 | if (delete_resptimer) { |
Svenne Krap | 46800b2 | 2010-02-14 18:59:42 +0100 | [diff] [blame] | 3716 | timer_ok = del_timer(&hw->resptimer); |
Andrew Elwell | 3f4b4e7 | 2010-02-18 23:56:13 +0100 | [diff] [blame] | 3717 | if (timer_ok != 0) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3718 | hw->resp_timer_done = 1; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3719 | } |
| 3720 | |
| 3721 | spin_unlock_irqrestore(&hw->ctlxq.lock, flags); |
| 3722 | |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3723 | if (!timer_ok && (hw->resp_timer_done == 0)) { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3724 | spin_lock_irqsave(&hw->ctlxq.lock, flags); |
| 3725 | goto delresp; |
| 3726 | } |
| 3727 | |
| 3728 | if (run_queue) |
| 3729 | hfa384x_usbctlxq_run(hw); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3730 | } |
| 3731 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3732 | /*---------------------------------------------------------------- |
| 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 Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 3740 | * data a ptr to the struct hfa384x |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3741 | * |
| 3742 | * Returns: |
| 3743 | * nothing |
| 3744 | * |
| 3745 | * Side effects: |
| 3746 | * |
| 3747 | * Call context: |
| 3748 | * interrupt |
| 3749 | ----------------------------------------------------------------*/ |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3750 | static void hfa384x_usbctlx_reqtimerfn(unsigned long data) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3751 | { |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 3752 | struct hfa384x *hw = (struct hfa384x *)data; |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3753 | unsigned long flags; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3754 | |
| 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 Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3762 | if (!list_empty(&hw->ctlxq.active)) { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3763 | /* |
| 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 Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3768 | if (usb_unlink_urb(&hw->ctlx_urb) == -EINPROGRESS) { |
Sergio Paracuellos | a10d36b | 2016-09-28 20:20:16 +0200 | [diff] [blame] | 3769 | struct hfa384x_usbctlx *ctlx = get_active_ctlx(hw); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3770 | |
| 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-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3788 | } |
| 3789 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3790 | /*---------------------------------------------------------------- |
| 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 Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 3798 | * data a ptr to the struct hfa384x |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3799 | * |
| 3800 | * Returns: |
| 3801 | * nothing |
| 3802 | * |
| 3803 | * Side effects: |
| 3804 | * |
| 3805 | * Call context: |
| 3806 | * interrupt |
| 3807 | ----------------------------------------------------------------*/ |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3808 | static void hfa384x_usbctlx_resptimerfn(unsigned long data) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3809 | { |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 3810 | struct hfa384x *hw = (struct hfa384x *)data; |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3811 | unsigned long flags; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3812 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3813 | 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 Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3820 | if (!list_empty(&hw->ctlxq.active)) { |
Sergio Paracuellos | a10d36b | 2016-09-28 20:20:16 +0200 | [diff] [blame] | 3821 | struct hfa384x_usbctlx *ctlx = get_active_ctlx(hw); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3822 | |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3823 | if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0) { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3824 | spin_unlock_irqrestore(&hw->ctlxq.lock, flags); |
| 3825 | hfa384x_usbctlxq_run(hw); |
Devendra Naga | 3f51425 | 2012-09-09 18:40:53 +0530 | [diff] [blame] | 3826 | return; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3827 | } |
| 3828 | } |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3829 | spin_unlock_irqrestore(&hw->ctlxq.lock, flags); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3830 | } |
| 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 Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3847 | static void hfa384x_usb_throttlefn(unsigned long data) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3848 | { |
Sergio Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 3849 | struct hfa384x *hw = (struct hfa384x *)data; |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3850 | unsigned long flags; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3851 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3852 | 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 Muehlenhoff | a7cf7ba | 2009-02-08 02:01:00 +0100 | [diff] [blame] | 3858 | pr_debug("flags=0x%lx\n", hw->usb_flags); |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3859 | if (!hw->wlandev->hwremoved && |
| 3860 | ((test_and_clear_bit(THROTTLE_RX, &hw->usb_flags) && |
Bogicevic Sasa | 6c37e1f | 2015-12-14 06:25:59 -0800 | [diff] [blame] | 3861 | !test_and_set_bit(WORK_RX_RESUME, &hw->usb_flags)) | |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3862 | (test_and_clear_bit(THROTTLE_TX, &hw->usb_flags) && |
| 3863 | !test_and_set_bit(WORK_TX_RESUME, &hw->usb_flags)) |
| 3864 | )) { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3865 | schedule_work(&hw->usb_work); |
| 3866 | } |
| 3867 | |
| 3868 | spin_unlock_irqrestore(&hw->ctlxq.lock, flags); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3869 | } |
| 3870 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3871 | /*---------------------------------------------------------------- |
| 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 Paracuellos | 5a2214e | 2016-09-28 20:20:19 +0200 | [diff] [blame] | 3889 | static int hfa384x_usbctlx_submit(struct hfa384x *hw, struct hfa384x_usbctlx *ctlx) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3890 | { |
| 3891 | unsigned long flags; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3892 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3893 | spin_lock_irqsave(&hw->ctlxq.lock, flags); |
| 3894 | |
| 3895 | if (hw->wlandev->hwremoved) { |
| 3896 | spin_unlock_irqrestore(&hw->ctlxq.lock, flags); |
Devendra Naga | 675be12 | 2012-09-13 15:00:54 +0530 | [diff] [blame] | 3897 | return -ENODEV; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3898 | } |
| 3899 | |
Devendra Naga | 675be12 | 2012-09-13 15:00:54 +0530 | [diff] [blame] | 3900 | 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-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3906 | } |
| 3907 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3908 | /*---------------------------------------------------------------- |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3909 | * 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 Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3924 | static int hfa384x_isgood_pdrcode(u16 pdrcode) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3925 | { |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3926 | switch (pdrcode) { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3927 | 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-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3958 | default: |
Moritz Muehlenhoff | 21dc0f8 | 2009-02-08 02:21:00 +0100 | [diff] [blame] | 3959 | if (pdrcode < 0x1000) { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3960 | /* code is OK, but we don't know exactly what it is */ |
Sherif Shehab Aldin | a212013 | 2014-04-05 23:33:16 +0200 | [diff] [blame] | 3961 | pr_debug("Encountered unknown PDR#=0x%04x, assuming it's ok.\n", |
| 3962 | pdrcode); |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3963 | return 1; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3964 | } |
Eduardo Barretto | 81980c1 | 2014-12-19 23:34:33 -0200 | [diff] [blame] | 3965 | break; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3966 | } |
Eduardo Barretto | 81980c1 | 2014-12-19 23:34:33 -0200 | [diff] [blame] | 3967 | /* bad code */ |
| 3968 | pr_debug("Encountered unknown PDR#=0x%04x, (>=0x1000), assuming it's bad.\n", |
| 3969 | pdrcode); |
| 3970 | return 0; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 3971 | } |