Commit | Line | Data |
---|---|---|
00b3ed16 GKH |
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 | |
3fc0d278 | 55 | * of invocations of the API layer (e.g. write to bap, followed by cmd). |
00b3ed16 GKH |
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 | |
631c8dec EH |
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 | |
00b3ed16 GKH |
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 | ||
00b3ed16 GKH |
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> | |
ef1a0ed7 | 121 | #include <linux/io.h> |
00b3ed16 GKH |
122 | #include <linux/delay.h> |
123 | #include <asm/byteorder.h> | |
ef1a0ed7 | 124 | #include <linux/bitops.h> |
00b3ed16 GKH |
125 | #include <linux/list.h> |
126 | #include <linux/usb.h> | |
ae26230b | 127 | #include <linux/byteorder/generic.h> |
00b3ed16 | 128 | |
00b3ed16 GKH |
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 | ||
21dc0f89 MM |
141 | enum cmd_mode { |
142 | DOWAIT = 0, | |
143 | DOASYNC | |
00b3ed16 | 144 | }; |
00b3ed16 | 145 | |
6c37e1f9 | 146 | #define THROTTLE_JIFFIES (HZ / 8) |
2d200d9f MM |
147 | #define URB_ASYNC_UNLINK 0 |
148 | #define USB_QUEUE_BULK 0 | |
00b3ed16 | 149 | |
6c37e1f9 | 150 | #define ROUNDUP64(a) (((a) + 63) & ~63) |
00b3ed16 | 151 | |
00b3ed16 | 152 | #ifdef DEBUG_USB |
21dc0f89 | 153 | static void dbprint_urb(struct urb *urb); |
00b3ed16 GKH |
154 | #endif |
155 | ||
156 | static void | |
684b2e08 | 157 | hfa384x_int_rxmonitor(struct wlandevice *wlandev, struct hfa384x_usb_rxfrm *rxfrm); |
00b3ed16 | 158 | |
21dc0f89 | 159 | static void hfa384x_usb_defer(struct work_struct *data); |
00b3ed16 | 160 | |
297f06ce | 161 | static int submit_rx_urb(hfa384x_t *hw, gfp_t flags); |
00b3ed16 | 162 | |
297f06ce | 163 | static int submit_tx_urb(hfa384x_t *hw, struct urb *tx_urb, gfp_t flags); |
00b3ed16 GKH |
164 | |
165 | /*---------------------------------------------------*/ | |
166 | /* Callbacks */ | |
21dc0f89 MM |
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); | |
00b3ed16 GKH |
170 | |
171 | static void | |
c9573a8d | 172 | hfa384x_usbin_txcompl(struct wlandevice *wlandev, hfa384x_usbin_t *usbin); |
00b3ed16 | 173 | |
c9573a8d | 174 | static void hfa384x_usbin_rx(struct wlandevice *wlandev, struct sk_buff *skb); |
00b3ed16 | 175 | |
c9573a8d | 176 | static void hfa384x_usbin_info(struct wlandevice *wlandev, hfa384x_usbin_t *usbin); |
00b3ed16 | 177 | |
297f06ce | 178 | static void hfa384x_usbin_ctlx(hfa384x_t *hw, hfa384x_usbin_t *usbin, |
00b3ed16 GKH |
179 | int urb_status); |
180 | ||
181 | /*---------------------------------------------------*/ | |
182 | /* Functions to support the prism2 usb command queue */ | |
183 | ||
297f06ce | 184 | static void hfa384x_usbctlxq_run(hfa384x_t *hw); |
00b3ed16 | 185 | |
21dc0f89 | 186 | static void hfa384x_usbctlx_reqtimerfn(unsigned long data); |
00b3ed16 | 187 | |
21dc0f89 | 188 | static void hfa384x_usbctlx_resptimerfn(unsigned long data); |
00b3ed16 | 189 | |
21dc0f89 | 190 | static void hfa384x_usb_throttlefn(unsigned long data); |
00b3ed16 | 191 | |
21dc0f89 | 192 | static void hfa384x_usbctlx_completion_task(unsigned long data); |
00b3ed16 | 193 | |
21dc0f89 | 194 | static void hfa384x_usbctlx_reaper_task(unsigned long data); |
00b3ed16 | 195 | |
297f06ce | 196 | static int hfa384x_usbctlx_submit(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx); |
00b3ed16 | 197 | |
297f06ce | 198 | static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx); |
00b3ed16 | 199 | |
21dc0f89 | 200 | struct usbctlx_completor { |
83f91687 | 201 | int (*complete)(struct usbctlx_completor *); |
00b3ed16 | 202 | }; |
00b3ed16 GKH |
203 | |
204 | static int | |
297f06ce MT |
205 | hfa384x_usbctlx_complete_sync(hfa384x_t *hw, |
206 | hfa384x_usbctlx_t *ctlx, | |
631c8dec | 207 | struct usbctlx_completor *completor); |
00b3ed16 GKH |
208 | |
209 | static int | |
297f06ce | 210 | unlocked_usbctlx_cancel_async(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx); |
00b3ed16 | 211 | |
297f06ce | 212 | static void hfa384x_cb_status(hfa384x_t *hw, const hfa384x_usbctlx_t *ctlx); |
00b3ed16 | 213 | |
00b3ed16 | 214 | static int |
385a79df | 215 | usbctlx_get_status(const struct hfa384x_usb_statusresp *cmdresp, |
297f06ce | 216 | hfa384x_cmdresult_t *result); |
00b3ed16 GKH |
217 | |
218 | static void | |
a988c9f3 | 219 | usbctlx_get_rridresult(const struct hfa384x_usb_rridresp *rridresp, |
297f06ce | 220 | hfa384x_rridresult_t *result); |
00b3ed16 GKH |
221 | |
222 | /*---------------------------------------------------*/ | |
223 | /* Low level req/resp CTLX formatters and submitters */ | |
224 | static int | |
297f06ce | 225 | hfa384x_docmd(hfa384x_t *hw, |
631c8dec | 226 | enum cmd_mode mode, |
297f06ce | 227 | hfa384x_metacmd_t *cmd, |
21dc0f89 | 228 | ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data); |
00b3ed16 GKH |
229 | |
230 | static int | |
297f06ce | 231 | hfa384x_dorrid(hfa384x_t *hw, |
631c8dec | 232 | enum cmd_mode mode, |
21dc0f89 MM |
233 | u16 rid, |
234 | void *riddata, | |
235 | unsigned int riddatalen, | |
236 | ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data); | |
00b3ed16 GKH |
237 | |
238 | static int | |
297f06ce | 239 | hfa384x_dowrid(hfa384x_t *hw, |
631c8dec | 240 | enum cmd_mode mode, |
21dc0f89 MM |
241 | u16 rid, |
242 | void *riddata, | |
243 | unsigned int riddatalen, | |
244 | ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data); | |
00b3ed16 GKH |
245 | |
246 | static int | |
297f06ce | 247 | hfa384x_dormem(hfa384x_t *hw, |
631c8dec | 248 | enum cmd_mode mode, |
21dc0f89 MM |
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); | |
00b3ed16 GKH |
254 | |
255 | static int | |
297f06ce | 256 | hfa384x_dowmem(hfa384x_t *hw, |
631c8dec | 257 | enum cmd_mode mode, |
21dc0f89 MM |
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); | |
00b3ed16 | 263 | |
21dc0f89 | 264 | static int hfa384x_isgood_pdrcode(u16 pdrcode); |
00b3ed16 | 265 | |
21dc0f89 | 266 | static inline const char *ctlxstr(CTLX_STATE s) |
00b3ed16 | 267 | { |
d6ae4a99 | 268 | static const char * const ctlx_str[] = { |
00b3ed16 GKH |
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 | ||
32adf1e5 | 281 | static inline hfa384x_usbctlx_t *get_active_ctlx(hfa384x_t *hw) |
00b3ed16 GKH |
282 | { |
283 | return list_entry(hw->ctlxq.active.next, hfa384x_usbctlx_t, list); | |
284 | } | |
285 | ||
00b3ed16 | 286 | #ifdef DEBUG_USB |
21dc0f89 | 287 | void dbprint_urb(struct urb *urb) |
00b3ed16 | 288 | { |
a7cf7bae MM |
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); | |
21dc0f89 | 292 | pr_debug("urb->transfer_buffer=0x%08x\n", |
75f49e07 | 293 | (unsigned int)urb->transfer_buffer); |
21dc0f89 | 294 | pr_debug("urb->transfer_buffer_length=0x%08x\n", |
75f49e07 | 295 | urb->transfer_buffer_length); |
a7cf7bae MM |
296 | pr_debug("urb->actual_length=0x%08x\n", urb->actual_length); |
297 | pr_debug("urb->bandwidth=0x%08x\n", urb->bandwidth); | |
21dc0f89 | 298 | pr_debug("urb->setup_packet(ctl)=0x%08x\n", |
75f49e07 MT |
299 | (unsigned int)urb->setup_packet); |
300 | pr_debug("urb->start_frame(iso/irq)=0x%08x\n", urb->start_frame); | |
a7cf7bae MM |
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); | |
75f49e07 | 305 | pr_debug("urb->complete=0x%08x\n", (unsigned int)urb->complete); |
00b3ed16 GKH |
306 | } |
307 | #endif | |
308 | ||
00b3ed16 GKH |
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 | ----------------------------------------------------------------*/ | |
297f06ce | 325 | static int submit_rx_urb(hfa384x_t *hw, gfp_t memflags) |
00b3ed16 GKH |
326 | { |
327 | struct sk_buff *skb; | |
328 | int result; | |
329 | ||
00b3ed16 | 330 | skb = dev_alloc_skb(sizeof(hfa384x_usbin_t)); |
e2e77528 | 331 | if (!skb) { |
00b3ed16 GKH |
332 | result = -ENOMEM; |
333 | goto done; | |
334 | } | |
335 | ||
336 | /* Post the IN urb */ | |
337 | usb_fill_bulk_urb(&hw->rx_urb, hw->usb, | |
21dc0f89 MM |
338 | hw->endp_in, |
339 | skb->data, sizeof(hfa384x_usbin_t), | |
340 | hfa384x_usbin_callback, hw->wlandev); | |
00b3ed16 GKH |
341 | |
342 | hw->rx_urb_skb = skb; | |
343 | ||
344 | result = -ENOLINK; | |
631c8dec | 345 | if (!hw->wlandev->hwremoved && |
3f2d6564 | 346 | !test_bit(WORK_RX_HALT, &hw->usb_flags)) { |
5850c251 | 347 | result = usb_submit_urb(&hw->rx_urb, memflags); |
00b3ed16 GKH |
348 | |
349 | /* Check whether we need to reset the RX pipe */ | |
350 | if (result == -EPIPE) { | |
263b8bb9 | 351 | netdev_warn(hw->wlandev->netdev, |
3f2d6564 SSA |
352 | "%s rx pipe stalled: requesting reset\n", |
353 | hw->wlandev->netdev->name); | |
21dc0f89 | 354 | if (!test_and_set_bit(WORK_RX_HALT, &hw->usb_flags)) |
00b3ed16 GKH |
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 | ||
21dc0f89 | 365 | done: |
00b3ed16 GKH |
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 | |
1a6dfce7 | 378 | * tx_urb URB of data for transmission |
00b3ed16 GKH |
379 | * memflags memory allocation flags |
380 | * | |
381 | * Returns: | |
382 | * error code from submission | |
383 | * | |
384 | * Call context: | |
385 | * Any | |
386 | ----------------------------------------------------------------*/ | |
297f06ce | 387 | static int submit_tx_urb(hfa384x_t *hw, struct urb *tx_urb, gfp_t memflags) |
00b3ed16 GKH |
388 | { |
389 | struct net_device *netdev = hw->wlandev->netdev; | |
390 | int result; | |
391 | ||
00b3ed16 | 392 | result = -ENOLINK; |
21dc0f89 | 393 | if (netif_running(netdev)) { |
a3542e66 SSA |
394 | if (!hw->wlandev->hwremoved && |
395 | !test_bit(WORK_TX_HALT, &hw->usb_flags)) { | |
5850c251 | 396 | result = usb_submit_urb(tx_urb, memflags); |
00b3ed16 GKH |
397 | |
398 | /* Test whether we need to reset the TX pipe */ | |
399 | if (result == -EPIPE) { | |
263b8bb9 | 400 | netdev_warn(hw->wlandev->netdev, |
3f2d6564 SSA |
401 | "%s tx pipe stalled: requesting reset\n", |
402 | netdev->name); | |
00b3ed16 GKH |
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 | ||
00b3ed16 GKH |
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 | ----------------------------------------------------------------*/ | |
21dc0f89 | 430 | static void hfa384x_usb_defer(struct work_struct *data) |
00b3ed16 GKH |
431 | { |
432 | hfa384x_t *hw = container_of(data, struct hfa384x, usb_work); | |
433 | struct net_device *netdev = hw->wlandev->netdev; | |
434 | ||
00b3ed16 GKH |
435 | /* Don't bother trying to reset anything if the plug |
436 | * has been pulled ... | |
437 | */ | |
21dc0f89 | 438 | if (hw->wlandev->hwremoved) |
00b3ed16 | 439 | return; |
00b3ed16 GKH |
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 | ||
631c8dec | 445 | usb_kill_urb(&hw->rx_urb); /* Cannot be holding spinlock! */ |
00b3ed16 GKH |
446 | |
447 | ret = usb_clear_halt(hw->usb, hw->endp_in); | |
448 | if (ret != 0) { | |
263b8bb9 | 449 | netdev_err(hw->wlandev->netdev, |
3f2d6564 SSA |
450 | "Failed to clear rx pipe for %s: err=%d\n", |
451 | netdev->name, ret); | |
00b3ed16 | 452 | } else { |
263b8bb9 | 453 | netdev_info(hw->wlandev->netdev, "%s rx pipe reset complete.\n", |
3f2d6564 | 454 | netdev->name); |
00b3ed16 GKH |
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. */ | |
21dc0f89 | 461 | if (test_bit(WORK_RX_RESUME, &hw->usb_flags)) { |
00b3ed16 GKH |
462 | int ret; |
463 | ||
464 | ret = submit_rx_urb(hw, GFP_KERNEL); | |
465 | if (ret != 0) { | |
263b8bb9 | 466 | netdev_err(hw->wlandev->netdev, |
3f2d6564 SSA |
467 | "Failed to resume %s rx pipe.\n", |
468 | netdev->name); | |
00b3ed16 GKH |
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) { | |
263b8bb9 | 481 | netdev_err(hw->wlandev->netdev, |
3f2d6564 SSA |
482 | "Failed to clear tx pipe for %s: err=%d\n", |
483 | netdev->name, ret); | |
00b3ed16 | 484 | } else { |
263b8bb9 | 485 | netdev_info(hw->wlandev->netdev, "%s tx pipe reset complete.\n", |
3f2d6564 | 486 | netdev->name); |
00b3ed16 GKH |
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. */ | |
21dc0f89 | 499 | if (test_and_clear_bit(WORK_TX_RESUME, &hw->usb_flags)) |
cbec30c4 | 500 | netif_wake_queue(hw->wlandev->netdev); |
00b3ed16 GKH |
501 | } |
502 | ||
00b3ed16 GKH |
503 | /*---------------------------------------------------------------- |
504 | * hfa384x_create | |
505 | * | |
506 | * Sets up the hfa384x_t data structure for use. Note this | |
9b0131cb | 507 | * does _not_ initialize the actual hardware, just the data structures |
00b3ed16 GKH |
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 | ----------------------------------------------------------------*/ | |
297f06ce | 524 | void hfa384x_create(hfa384x_t *hw, struct usb_device *usb) |
00b3ed16 | 525 | { |
00b3ed16 GKH |
526 | memset(hw, 0, sizeof(hfa384x_t)); |
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, | |
21dc0f89 | 547 | hfa384x_usbctlx_reaper_task, (unsigned long)hw); |
00b3ed16 | 548 | tasklet_init(&hw->completion_bh, |
21dc0f89 | 549 | hfa384x_usbctlx_completion_task, (unsigned long)hw); |
575a8a5c SP |
550 | INIT_WORK(&hw->link_bh, prism2sta_processing_defer); |
551 | INIT_WORK(&hw->usb_work, hfa384x_usb_defer); | |
00b3ed16 | 552 | |
2f83aeda | 553 | setup_timer(&hw->throttle, hfa384x_usb_throttlefn, (unsigned long)hw); |
00b3ed16 | 554 | |
2f83aeda AM |
555 | setup_timer(&hw->resptimer, hfa384x_usbctlx_resptimerfn, |
556 | (unsigned long)hw); | |
00b3ed16 | 557 | |
2f83aeda AM |
558 | setup_timer(&hw->reqtimer, hfa384x_usbctlx_reqtimerfn, |
559 | (unsigned long)hw); | |
00b3ed16 GKH |
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 | ||
21dc0f89 | 568 | INIT_WORK(&hw->commsqual_bh, prism2sta_commsqual_defer); |
2f83aeda AM |
569 | setup_timer(&hw->commsqual_timer, prism2sta_commsqual_timer, |
570 | (unsigned long)hw); | |
00b3ed16 GKH |
571 | } |
572 | ||
00b3ed16 GKH |
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 | ----------------------------------------------------------------*/ | |
297f06ce | 595 | void hfa384x_destroy(hfa384x_t *hw) |
00b3ed16 GKH |
596 | { |
597 | struct sk_buff *skb; | |
598 | ||
21dc0f89 | 599 | if (hw->state == HFA384x_STATE_RUNNING) |
00b3ed16 | 600 | hfa384x_drvr_stop(hw); |
00b3ed16 GKH |
601 | hw->state = HFA384x_STATE_PREINIT; |
602 | ||
a6f9c48f IM |
603 | kfree(hw->scanresults); |
604 | hw->scanresults = NULL; | |
00b3ed16 GKH |
605 | |
606 | /* Now to clean out the auth queue */ | |
21dc0f89 MM |
607 | while ((skb = skb_dequeue(&hw->authq))) |
608 | dev_kfree_skb(skb); | |
00b3ed16 GKH |
609 | } |
610 | ||
21dc0f89 | 611 | static hfa384x_usbctlx_t *usbctlx_alloc(void) |
00b3ed16 GKH |
612 | { |
613 | hfa384x_usbctlx_t *ctlx; | |
614 | ||
d0edf4bc NSN |
615 | ctlx = kzalloc(sizeof(*ctlx), |
616 | in_interrupt() ? GFP_ATOMIC : GFP_KERNEL); | |
02e02048 | 617 | if (ctlx) |
00b3ed16 | 618 | init_completion(&ctlx->done); |
00b3ed16 GKH |
619 | |
620 | return ctlx; | |
621 | } | |
622 | ||
00b3ed16 | 623 | static int |
385a79df | 624 | usbctlx_get_status(const struct hfa384x_usb_statusresp *cmdresp, |
297f06ce | 625 | hfa384x_cmdresult_t *result) |
00b3ed16 | 626 | { |
18c7f792 MM |
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); | |
00b3ed16 | 631 | |
a2120136 | 632 | pr_debug("cmdresult:status=0x%04x resp0=0x%04x resp1=0x%04x resp2=0x%04x\n", |
75f49e07 | 633 | result->status, result->resp0, result->resp1, result->resp2); |
00b3ed16 | 634 | |
21dc0f89 | 635 | return result->status & HFA384x_STATUS_RESULT; |
00b3ed16 GKH |
636 | } |
637 | ||
638 | static void | |
a988c9f3 | 639 | usbctlx_get_rridresult(const struct hfa384x_usb_rridresp *rridresp, |
297f06ce | 640 | hfa384x_rridresult_t *result) |
00b3ed16 | 641 | { |
18c7f792 | 642 | result->rid = le16_to_cpu(rridresp->rid); |
00b3ed16 | 643 | result->riddata = rridresp->data; |
18c7f792 | 644 | result->riddata_len = ((le16_to_cpu(rridresp->frmlen) - 1) * 2); |
00b3ed16 GKH |
645 | } |
646 | ||
00b3ed16 GKH |
647 | /*---------------------------------------------------------------- |
648 | * Completor object: | |
649 | * This completor must be passed to hfa384x_usbctlx_complete_sync() | |
650 | * when processing a CTLX that returns a hfa384x_cmdresult_t structure. | |
651 | ----------------------------------------------------------------*/ | |
21dc0f89 | 652 | struct usbctlx_cmd_completor { |
631c8dec | 653 | struct usbctlx_completor head; |
00b3ed16 | 654 | |
385a79df | 655 | const struct hfa384x_usb_statusresp *cmdresp; |
21dc0f89 | 656 | hfa384x_cmdresult_t *result; |
00b3ed16 | 657 | }; |
00b3ed16 | 658 | |
631c8dec | 659 | static inline int usbctlx_cmd_completor_fn(struct usbctlx_completor *head) |
00b3ed16 | 660 | { |
631c8dec EH |
661 | struct usbctlx_cmd_completor *complete; |
662 | ||
5d85fe34 | 663 | complete = (struct usbctlx_cmd_completor *)head; |
00b3ed16 GKH |
664 | return usbctlx_get_status(complete->cmdresp, complete->result); |
665 | } | |
666 | ||
631c8dec EH |
667 | static inline struct usbctlx_completor *init_cmd_completor( |
668 | struct usbctlx_cmd_completor | |
669 | *completor, | |
385a79df | 670 | const struct hfa384x_usb_statusresp |
631c8dec EH |
671 | *cmdresp, |
672 | hfa384x_cmdresult_t *result) | |
00b3ed16 GKH |
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 | ----------------------------------------------------------------*/ | |
21dc0f89 | 685 | struct usbctlx_rrid_completor { |
631c8dec | 686 | struct usbctlx_completor head; |
00b3ed16 | 687 | |
a988c9f3 | 688 | const struct hfa384x_usb_rridresp *rridresp; |
21dc0f89 MM |
689 | void *riddata; |
690 | unsigned int riddatalen; | |
00b3ed16 | 691 | }; |
00b3ed16 | 692 | |
631c8dec | 693 | static int usbctlx_rrid_completor_fn(struct usbctlx_completor *head) |
00b3ed16 | 694 | { |
631c8dec | 695 | struct usbctlx_rrid_completor *complete; |
00b3ed16 GKH |
696 | hfa384x_rridresult_t rridresult; |
697 | ||
5d85fe34 | 698 | complete = (struct usbctlx_rrid_completor *)head; |
00b3ed16 GKH |
699 | usbctlx_get_rridresult(complete->rridresp, &rridresult); |
700 | ||
701 | /* Validate the length, note body len calculation in bytes */ | |
21dc0f89 | 702 | if (rridresult.riddata_len != complete->riddatalen) { |
baa8a6c0 SSA |
703 | pr_warn("RID len mismatch, rid=0x%04x hlen=%d fwlen=%d\n", |
704 | rridresult.rid, | |
705 | complete->riddatalen, rridresult.riddata_len); | |
00b3ed16 GKH |
706 | return -ENODATA; |
707 | } | |
708 | ||
21dc0f89 | 709 | memcpy(complete->riddata, rridresult.riddata, complete->riddatalen); |
00b3ed16 GKH |
710 | return 0; |
711 | } | |
712 | ||
631c8dec EH |
713 | static inline struct usbctlx_completor *init_rrid_completor( |
714 | struct usbctlx_rrid_completor | |
715 | *completor, | |
a988c9f3 | 716 | const struct hfa384x_usb_rridresp |
631c8dec EH |
717 | *rridresp, |
718 | void *riddata, | |
719 | unsigned int riddatalen) | |
00b3ed16 GKH |
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 | ----------------------------------------------------------------*/ | |
00b3ed16 GKH |
732 | #define init_wrid_completor init_cmd_completor |
733 | ||
734 | /*---------------------------------------------------------------- | |
735 | * Completor object: | |
736 | * Interprets the results of a synchronous memory-write | |
737 | ----------------------------------------------------------------*/ | |
00b3ed16 GKH |
738 | #define init_wmem_completor init_cmd_completor |
739 | ||
740 | /*---------------------------------------------------------------- | |
741 | * Completor object: | |
742 | * Interprets the results of a synchronous memory-read | |
743 | ----------------------------------------------------------------*/ | |
21dc0f89 | 744 | struct usbctlx_rmem_completor { |
631c8dec | 745 | struct usbctlx_completor head; |
00b3ed16 | 746 | |
1ed54806 | 747 | const struct hfa384x_usb_rmemresp *rmemresp; |
21dc0f89 MM |
748 | void *data; |
749 | unsigned int len; | |
00b3ed16 | 750 | }; |
00b3ed16 | 751 | |
631c8dec | 752 | static int usbctlx_rmem_completor_fn(struct usbctlx_completor *head) |
00b3ed16 | 753 | { |
a03742ac SSA |
754 | struct usbctlx_rmem_completor *complete = |
755 | (struct usbctlx_rmem_completor *)head; | |
00b3ed16 | 756 | |
a7cf7bae | 757 | pr_debug("rmemresp:len=%d\n", complete->rmemresp->frmlen); |
00b3ed16 GKH |
758 | memcpy(complete->data, complete->rmemresp->data, complete->len); |
759 | return 0; | |
760 | } | |
761 | ||
631c8dec | 762 | static inline struct usbctlx_completor *init_rmem_completor( |
a03742ac | 763 | struct usbctlx_rmem_completor |
631c8dec | 764 | *completor, |
1ed54806 | 765 | struct hfa384x_usb_rmemresp |
631c8dec EH |
766 | *rmemresp, |
767 | void *data, | |
768 | unsigned int len) | |
00b3ed16 GKH |
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 | ----------------------------------------------------------------*/ | |
297f06ce | 798 | static void hfa384x_cb_status(hfa384x_t *hw, const hfa384x_usbctlx_t *ctlx) |
00b3ed16 | 799 | { |
02e02048 | 800 | if (ctlx->usercb) { |
00b3ed16 GKH |
801 | hfa384x_cmdresult_t cmdresult; |
802 | ||
803 | if (ctlx->state != CTLX_COMPLETE) { | |
804 | memset(&cmdresult, 0, sizeof(cmdresult)); | |
21dc0f89 MM |
805 | cmdresult.status = |
806 | HFA384x_STATUS_RESULT_SET(HFA384x_CMD_ERR); | |
00b3ed16 GKH |
807 | } else { |
808 | usbctlx_get_status(&ctlx->inbuf.cmdresp, &cmdresult); | |
809 | } | |
810 | ||
811 | ctlx->usercb(hw, &cmdresult, ctlx->usercb_data); | |
812 | } | |
00b3ed16 GKH |
813 | } |
814 | ||
297f06ce | 815 | static inline int hfa384x_docmd_wait(hfa384x_t *hw, hfa384x_metacmd_t *cmd) |
00b3ed16 GKH |
816 | { |
817 | return hfa384x_docmd(hw, DOWAIT, cmd, NULL, NULL, NULL); | |
818 | } | |
819 | ||
820 | static inline int | |
297f06ce MT |
821 | hfa384x_docmd_async(hfa384x_t *hw, |
822 | hfa384x_metacmd_t *cmd, | |
21dc0f89 | 823 | ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data) |
00b3ed16 | 824 | { |
21dc0f89 | 825 | return hfa384x_docmd(hw, DOASYNC, cmd, cmdcb, usercb, usercb_data); |
00b3ed16 GKH |
826 | } |
827 | ||
828 | static inline int | |
297f06ce | 829 | hfa384x_dorrid_wait(hfa384x_t *hw, u16 rid, void *riddata, |
21dc0f89 | 830 | unsigned int riddatalen) |
00b3ed16 GKH |
831 | { |
832 | return hfa384x_dorrid(hw, DOWAIT, | |
21dc0f89 | 833 | rid, riddata, riddatalen, NULL, NULL, NULL); |
00b3ed16 GKH |
834 | } |
835 | ||
836 | static inline int | |
297f06ce | 837 | hfa384x_dorrid_async(hfa384x_t *hw, |
21dc0f89 MM |
838 | u16 rid, void *riddata, unsigned int riddatalen, |
839 | ctlx_cmdcb_t cmdcb, | |
840 | ctlx_usercb_t usercb, void *usercb_data) | |
00b3ed16 GKH |
841 | { |
842 | return hfa384x_dorrid(hw, DOASYNC, | |
21dc0f89 MM |
843 | rid, riddata, riddatalen, |
844 | cmdcb, usercb, usercb_data); | |
00b3ed16 GKH |
845 | } |
846 | ||
847 | static inline int | |
297f06ce | 848 | hfa384x_dowrid_wait(hfa384x_t *hw, u16 rid, void *riddata, |
21dc0f89 | 849 | unsigned int riddatalen) |
00b3ed16 GKH |
850 | { |
851 | return hfa384x_dowrid(hw, DOWAIT, | |
21dc0f89 | 852 | rid, riddata, riddatalen, NULL, NULL, NULL); |
00b3ed16 GKH |
853 | } |
854 | ||
855 | static inline int | |
297f06ce | 856 | hfa384x_dowrid_async(hfa384x_t *hw, |
21dc0f89 MM |
857 | u16 rid, void *riddata, unsigned int riddatalen, |
858 | ctlx_cmdcb_t cmdcb, | |
859 | ctlx_usercb_t usercb, void *usercb_data) | |
00b3ed16 GKH |
860 | { |
861 | return hfa384x_dowrid(hw, DOASYNC, | |
21dc0f89 MM |
862 | rid, riddata, riddatalen, |
863 | cmdcb, usercb, usercb_data); | |
00b3ed16 GKH |
864 | } |
865 | ||
866 | static inline int | |
297f06ce | 867 | hfa384x_dormem_wait(hfa384x_t *hw, |
21dc0f89 | 868 | u16 page, u16 offset, void *data, unsigned int len) |
00b3ed16 GKH |
869 | { |
870 | return hfa384x_dormem(hw, DOWAIT, | |
21dc0f89 | 871 | page, offset, data, len, NULL, NULL, NULL); |
00b3ed16 GKH |
872 | } |
873 | ||
874 | static inline int | |
297f06ce | 875 | hfa384x_dormem_async(hfa384x_t *hw, |
21dc0f89 MM |
876 | u16 page, u16 offset, void *data, unsigned int len, |
877 | ctlx_cmdcb_t cmdcb, | |
878 | ctlx_usercb_t usercb, void *usercb_data) | |
00b3ed16 GKH |
879 | { |
880 | return hfa384x_dormem(hw, DOASYNC, | |
21dc0f89 MM |
881 | page, offset, data, len, |
882 | cmdcb, usercb, usercb_data); | |
00b3ed16 GKH |
883 | } |
884 | ||
885 | static inline int | |
297f06ce | 886 | hfa384x_dowmem_wait(hfa384x_t *hw, |
21dc0f89 | 887 | u16 page, u16 offset, void *data, unsigned int len) |
00b3ed16 GKH |
888 | { |
889 | return hfa384x_dowmem(hw, DOWAIT, | |
21dc0f89 | 890 | page, offset, data, len, NULL, NULL, NULL); |
00b3ed16 GKH |
891 | } |
892 | ||
893 | static inline int | |
297f06ce | 894 | hfa384x_dowmem_async(hfa384x_t *hw, |
21dc0f89 MM |
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) | |
00b3ed16 GKH |
901 | { |
902 | return hfa384x_dowmem(hw, DOASYNC, | |
21dc0f89 MM |
903 | page, offset, data, len, |
904 | cmdcb, usercb, usercb_data); | |
00b3ed16 GKH |
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 | ----------------------------------------------------------------*/ | |
297f06ce | 926 | int hfa384x_cmd_initialize(hfa384x_t *hw) |
00b3ed16 | 927 | { |
21dc0f89 MM |
928 | int result = 0; |
929 | int i; | |
00b3ed16 GKH |
930 | hfa384x_metacmd_t cmd; |
931 | ||
00b3ed16 GKH |
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 | ||
a2120136 | 939 | pr_debug("cmdresp.init: status=0x%04x, resp0=0x%04x, resp1=0x%04x, resp2=0x%04x\n", |
75f49e07 MT |
940 | cmd.result.status, |
941 | cmd.result.resp0, cmd.result.resp1, cmd.result.resp2); | |
21dc0f89 MM |
942 | if (result == 0) { |
943 | for (i = 0; i < HFA384x_NUMPORTS_MAX; i++) | |
00b3ed16 | 944 | hw->port_enabled[i] = 0; |
00b3ed16 GKH |
945 | } |
946 | ||
21dc0f89 | 947 | hw->link_status = HFA384x_LINK_NOTCONNECTED; |
00b3ed16 | 948 | |
00b3ed16 GKH |
949 | return result; |
950 | } | |
951 | ||
00b3ed16 GKH |
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 | ----------------------------------------------------------------*/ | |
297f06ce | 972 | int hfa384x_cmd_disable(hfa384x_t *hw, u16 macport) |
00b3ed16 | 973 | { |
00b3ed16 GKH |
974 | hfa384x_metacmd_t cmd; |
975 | ||
00b3ed16 | 976 | cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_DISABLE) | |
21dc0f89 | 977 | HFA384x_CMD_MACPORT_SET(macport); |
00b3ed16 GKH |
978 | cmd.parm0 = 0; |
979 | cmd.parm1 = 0; | |
980 | cmd.parm2 = 0; | |
981 | ||
ca026a35 | 982 | return hfa384x_docmd_wait(hw, &cmd); |
00b3ed16 GKH |
983 | } |
984 | ||
00b3ed16 GKH |
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 | ----------------------------------------------------------------*/ | |
297f06ce | 1005 | int hfa384x_cmd_enable(hfa384x_t *hw, u16 macport) |
00b3ed16 | 1006 | { |
00b3ed16 GKH |
1007 | hfa384x_metacmd_t cmd; |
1008 | ||
00b3ed16 | 1009 | cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_ENABLE) | |
21dc0f89 | 1010 | HFA384x_CMD_MACPORT_SET(macport); |
00b3ed16 GKH |
1011 | cmd.parm0 = 0; |
1012 | cmd.parm1 = 0; | |
1013 | cmd.parm2 = 0; | |
1014 | ||
ca026a35 | 1015 | return hfa384x_docmd_wait(hw, &cmd); |
00b3ed16 GKH |
1016 | } |
1017 | ||
00b3ed16 GKH |
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 | ----------------------------------------------------------------*/ | |
297f06ce | 1047 | int hfa384x_cmd_monitor(hfa384x_t *hw, u16 enable) |
00b3ed16 | 1048 | { |
00b3ed16 GKH |
1049 | hfa384x_metacmd_t cmd; |
1050 | ||
00b3ed16 | 1051 | cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_MONITOR) | |
21dc0f89 | 1052 | HFA384x_CMD_AINFO_SET(enable); |
00b3ed16 GKH |
1053 | cmd.parm0 = 0; |
1054 | cmd.parm1 = 0; | |
1055 | cmd.parm2 = 0; | |
1056 | ||
ca026a35 | 1057 | return hfa384x_docmd_wait(hw, &cmd); |
00b3ed16 GKH |
1058 | } |
1059 | ||
00b3ed16 GKH |
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 | ----------------------------------------------------------------*/ | |
297f06ce | 1098 | int hfa384x_cmd_download(hfa384x_t *hw, u16 mode, u16 lowaddr, |
21dc0f89 | 1099 | u16 highaddr, u16 codelen) |
00b3ed16 | 1100 | { |
00b3ed16 GKH |
1101 | hfa384x_metacmd_t cmd; |
1102 | ||
75f49e07 MT |
1103 | pr_debug("mode=%d, lowaddr=0x%04x, highaddr=0x%04x, codelen=%d\n", |
1104 | mode, lowaddr, highaddr, codelen); | |
00b3ed16 GKH |
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 | ||
ca026a35 | 1113 | return hfa384x_docmd_wait(hw, &cmd); |
00b3ed16 GKH |
1114 | } |
1115 | ||
00b3ed16 GKH |
1116 | /*---------------------------------------------------------------- |
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 | ----------------------------------------------------------------*/ | |
297f06ce | 1139 | int hfa384x_corereset(hfa384x_t *hw, int holdtime, int settletime, int genesis) |
00b3ed16 | 1140 | { |
df18b930 | 1141 | int result; |
00b3ed16 | 1142 | |
21dc0f89 MM |
1143 | result = usb_reset_device(hw->usb); |
1144 | if (result < 0) { | |
263b8bb9 | 1145 | netdev_err(hw->wlandev->netdev, "usb_reset_device() failed, result=%d.\n", |
3f2d6564 | 1146 | result); |
00b3ed16 GKH |
1147 | } |
1148 | ||
00b3ed16 GKH |
1149 | return result; |
1150 | } | |
1151 | ||
00b3ed16 GKH |
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 | |
631c8dec | 1160 | * ctlx CTLX ptr |
00b3ed16 GKH |
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 | ----------------------------------------------------------------*/ | |
297f06ce MT |
1176 | static int hfa384x_usbctlx_complete_sync(hfa384x_t *hw, |
1177 | hfa384x_usbctlx_t *ctlx, | |
631c8dec | 1178 | struct usbctlx_completor *completor) |
00b3ed16 GKH |
1179 | { |
1180 | unsigned long flags; | |
1181 | int result; | |
1182 | ||
00b3ed16 GKH |
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 | */ | |
21dc0f89 MM |
1191 | cleanup: |
1192 | if (hw->wlandev->hwremoved) { | |
00b3ed16 GKH |
1193 | spin_unlock_irqrestore(&hw->ctlxq.lock, flags); |
1194 | result = -ENODEV; | |
21dc0f89 | 1195 | } else if (result != 0) { |
00b3ed16 GKH |
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 | */ | |
21dc0f89 | 1207 | if (ctlx == get_active_ctlx(hw)) { |
00b3ed16 GKH |
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 | */ | |
21dc0f89 | 1224 | if (hw->wlandev->hwremoved) |
00b3ed16 GKH |
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 { | |
263b8bb9 | 1245 | netdev_warn(hw->wlandev->netdev, "CTLX[%d] error: state(%s)\n", |
3f2d6564 SSA |
1246 | le16_to_cpu(ctlx->outbuf.type), |
1247 | ctlxstr(ctlx->state)); | |
00b3ed16 GKH |
1248 | result = -EIO; |
1249 | } | |
1250 | ||
1251 | list_del(&ctlx->list); | |
1252 | spin_unlock_irqrestore(&hw->ctlxq.lock, flags); | |
1253 | kfree(ctlx); | |
1254 | } | |
1255 | ||
00b3ed16 GKH |
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 | |
297f06ce | 1292 | hfa384x_docmd(hfa384x_t *hw, |
631c8dec | 1293 | enum cmd_mode mode, |
297f06ce | 1294 | hfa384x_metacmd_t *cmd, |
21dc0f89 | 1295 | ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data) |
00b3ed16 | 1296 | { |
21dc0f89 MM |
1297 | int result; |
1298 | hfa384x_usbctlx_t *ctlx; | |
00b3ed16 | 1299 | |
00b3ed16 | 1300 | ctlx = usbctlx_alloc(); |
e2e77528 | 1301 | if (!ctlx) { |
00b3ed16 GKH |
1302 | result = -ENOMEM; |
1303 | goto done; | |
1304 | } | |
1305 | ||
1306 | /* Initialize the command */ | |
18c7f792 MM |
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); | |
00b3ed16 GKH |
1312 | |
1313 | ctlx->outbufsize = sizeof(ctlx->outbuf.cmdreq); | |
1314 | ||
a2120136 | 1315 | pr_debug("cmdreq: cmd=0x%04x parm0=0x%04x parm1=0x%04x parm2=0x%04x\n", |
75f49e07 | 1316 | cmd->cmd, cmd->parm0, cmd->parm1, cmd->parm2); |
00b3ed16 GKH |
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) { | |
631c8dec | 1327 | struct usbctlx_cmd_completor completor; |
00b3ed16 | 1328 | |
21dc0f89 MM |
1329 | result = |
1330 | hfa384x_usbctlx_complete_sync(hw, ctlx, | |
1331 | init_cmd_completor(&completor, | |
1332 | &ctlx-> | |
1333 | inbuf. | |
1334 | cmdresp, | |
1335 | &cmd-> | |
1336 | result)); | |
00b3ed16 GKH |
1337 | } |
1338 | ||
1339 | done: | |
00b3ed16 GKH |
1340 | return result; |
1341 | } | |
1342 | ||
00b3ed16 GKH |
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 | |
297f06ce | 1380 | hfa384x_dorrid(hfa384x_t *hw, |
631c8dec | 1381 | enum cmd_mode mode, |
21dc0f89 MM |
1382 | u16 rid, |
1383 | void *riddata, | |
1384 | unsigned int riddatalen, | |
1385 | ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data) | |
00b3ed16 | 1386 | { |
21dc0f89 MM |
1387 | int result; |
1388 | hfa384x_usbctlx_t *ctlx; | |
00b3ed16 | 1389 | |
00b3ed16 | 1390 | ctlx = usbctlx_alloc(); |
e2e77528 | 1391 | if (!ctlx) { |
00b3ed16 GKH |
1392 | result = -ENOMEM; |
1393 | goto done; | |
1394 | } | |
1395 | ||
1396 | /* Initialize the command */ | |
18c7f792 | 1397 | ctlx->outbuf.rridreq.type = cpu_to_le16(HFA384x_USB_RRIDREQ); |
00b3ed16 | 1398 | ctlx->outbuf.rridreq.frmlen = |
18c7f792 MM |
1399 | cpu_to_le16(sizeof(ctlx->outbuf.rridreq.rid)); |
1400 | ctlx->outbuf.rridreq.rid = cpu_to_le16(rid); | |
00b3ed16 GKH |
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) { | |
631c8dec | 1414 | struct usbctlx_rrid_completor completor; |
00b3ed16 | 1415 | |
21dc0f89 MM |
1416 | result = |
1417 | hfa384x_usbctlx_complete_sync(hw, ctlx, | |
1418 | init_rrid_completor | |
1419 | (&completor, | |
1420 | &ctlx->inbuf.rridresp, | |
1421 | riddata, riddatalen)); | |
00b3ed16 GKH |
1422 | } |
1423 | ||
1424 | done: | |
00b3ed16 GKH |
1425 | return result; |
1426 | } | |
1427 | ||
00b3ed16 GKH |
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 | |
631c8dec | 1439 | * enum cmd_mode DOWAIT or DOASYNC |
00b3ed16 GKH |
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 | |
297f06ce | 1461 | hfa384x_dowrid(hfa384x_t *hw, |
631c8dec | 1462 | enum cmd_mode mode, |
21dc0f89 MM |
1463 | u16 rid, |
1464 | void *riddata, | |
1465 | unsigned int riddatalen, | |
1466 | ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data) | |
00b3ed16 | 1467 | { |
21dc0f89 MM |
1468 | int result; |
1469 | hfa384x_usbctlx_t *ctlx; | |
00b3ed16 | 1470 | |
00b3ed16 | 1471 | ctlx = usbctlx_alloc(); |
e2e77528 | 1472 | if (!ctlx) { |
00b3ed16 GKH |
1473 | result = -ENOMEM; |
1474 | goto done; | |
1475 | } | |
1476 | ||
1477 | /* Initialize the command */ | |
18c7f792 MM |
1478 | ctlx->outbuf.wridreq.type = cpu_to_le16(HFA384x_USB_WRIDREQ); |
1479 | ctlx->outbuf.wridreq.frmlen = cpu_to_le16((sizeof | |
75f49e07 MT |
1480 | (ctlx->outbuf.wridreq.rid) + |
1481 | riddatalen + 1) / 2); | |
18c7f792 | 1482 | ctlx->outbuf.wridreq.rid = cpu_to_le16(rid); |
00b3ed16 GKH |
1483 | memcpy(ctlx->outbuf.wridreq.data, riddata, riddatalen); |
1484 | ||
1485 | ctlx->outbufsize = sizeof(ctlx->outbuf.wridreq.type) + | |
21dc0f89 MM |
1486 | sizeof(ctlx->outbuf.wridreq.frmlen) + |
1487 | sizeof(ctlx->outbuf.wridreq.rid) + riddatalen; | |
00b3ed16 GKH |
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) { | |
a03742ac | 1499 | struct usbctlx_cmd_completor completor; |
00b3ed16 GKH |
1500 | hfa384x_cmdresult_t wridresult; |
1501 | ||
21dc0f89 MM |
1502 | result = hfa384x_usbctlx_complete_sync(hw, |
1503 | ctlx, | |
1504 | init_wrid_completor | |
1505 | (&completor, | |
1506 | &ctlx->inbuf.wridresp, | |
1507 | &wridresult)); | |
00b3ed16 GKH |
1508 | } |
1509 | ||
1510 | done: | |
00b3ed16 GKH |
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 | |
297f06ce | 1548 | hfa384x_dormem(hfa384x_t *hw, |
631c8dec | 1549 | enum cmd_mode mode, |
21dc0f89 MM |
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) | |
00b3ed16 | 1555 | { |
21dc0f89 MM |
1556 | int result; |
1557 | hfa384x_usbctlx_t *ctlx; | |
00b3ed16 | 1558 | |
00b3ed16 | 1559 | ctlx = usbctlx_alloc(); |
e2e77528 | 1560 | if (!ctlx) { |
00b3ed16 GKH |
1561 | result = -ENOMEM; |
1562 | goto done; | |
1563 | } | |
1564 | ||
1565 | /* Initialize the command */ | |
18c7f792 | 1566 | ctlx->outbuf.rmemreq.type = cpu_to_le16(HFA384x_USB_RMEMREQ); |
21dc0f89 | 1567 | ctlx->outbuf.rmemreq.frmlen = |
18c7f792 | 1568 | cpu_to_le16(sizeof(ctlx->outbuf.rmemreq.offset) + |
75f49e07 | 1569 | sizeof(ctlx->outbuf.rmemreq.page) + len); |
18c7f792 MM |
1570 | ctlx->outbuf.rmemreq.offset = cpu_to_le16(offset); |
1571 | ctlx->outbuf.rmemreq.page = cpu_to_le16(page); | |
00b3ed16 GKH |
1572 | |
1573 | ctlx->outbufsize = sizeof(ctlx->outbuf.rmemreq); | |
1574 | ||
75f49e07 MT |
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); | |
00b3ed16 | 1579 | |
75f49e07 | 1580 | pr_debug("pktsize=%zd\n", ROUNDUP64(sizeof(ctlx->outbuf.rmemreq))); |
00b3ed16 GKH |
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); | |
21dc0f89 | 1590 | } else if (mode == DOWAIT) { |
a03742ac | 1591 | struct usbctlx_rmem_completor completor; |
21dc0f89 MM |
1592 | |
1593 | result = | |
1594 | hfa384x_usbctlx_complete_sync(hw, ctlx, | |
1595 | init_rmem_completor | |
1596 | (&completor, | |
1597 | &ctlx->inbuf.rmemresp, data, | |
1598 | len)); | |
00b3ed16 GKH |
1599 | } |
1600 | ||
1601 | done: | |
00b3ed16 GKH |
1602 | return result; |
1603 | } | |
1604 | ||
00b3ed16 GKH |
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 | |
297f06ce | 1639 | hfa384x_dowmem(hfa384x_t *hw, |
631c8dec | 1640 | enum cmd_mode mode, |
21dc0f89 MM |
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) | |
00b3ed16 | 1646 | { |
21dc0f89 MM |
1647 | int result; |
1648 | hfa384x_usbctlx_t *ctlx; | |
00b3ed16 | 1649 | |
75f49e07 | 1650 | pr_debug("page=0x%04x offset=0x%04x len=%d\n", page, offset, len); |
00b3ed16 GKH |
1651 | |
1652 | ctlx = usbctlx_alloc(); | |
e2e77528 | 1653 | if (!ctlx) { |
00b3ed16 GKH |
1654 | result = -ENOMEM; |
1655 | goto done; | |
1656 | } | |
1657 | ||
1658 | /* Initialize the command */ | |
18c7f792 | 1659 | ctlx->outbuf.wmemreq.type = cpu_to_le16(HFA384x_USB_WMEMREQ); |
21dc0f89 | 1660 | ctlx->outbuf.wmemreq.frmlen = |
18c7f792 | 1661 | cpu_to_le16(sizeof(ctlx->outbuf.wmemreq.offset) + |
75f49e07 | 1662 | sizeof(ctlx->outbuf.wmemreq.page) + len); |
18c7f792 MM |
1663 | ctlx->outbuf.wmemreq.offset = cpu_to_le16(offset); |
1664 | ctlx->outbuf.wmemreq.page = cpu_to_le16(page); | |
00b3ed16 GKH |
1665 | memcpy(ctlx->outbuf.wmemreq.data, data, len); |
1666 | ||
1667 | ctlx->outbufsize = sizeof(ctlx->outbuf.wmemreq.type) + | |
21dc0f89 MM |
1668 | sizeof(ctlx->outbuf.wmemreq.frmlen) + |
1669 | sizeof(ctlx->outbuf.wmemreq.offset) + | |
1670 | sizeof(ctlx->outbuf.wmemreq.page) + len; | |
00b3ed16 GKH |
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); | |
21dc0f89 | 1680 | } else if (mode == DOWAIT) { |
a03742ac | 1681 | struct usbctlx_cmd_completor completor; |
21dc0f89 MM |
1682 | hfa384x_cmdresult_t wmemresult; |
1683 | ||
1684 | result = hfa384x_usbctlx_complete_sync(hw, | |
1685 | ctlx, | |
1686 | init_wmem_completor | |
1687 | (&completor, | |
1688 | &ctlx->inbuf.wmemresp, | |
1689 | &wmemresult)); | |
00b3ed16 GKH |
1690 | } |
1691 | ||
1692 | done: | |
00b3ed16 GKH |
1693 | return result; |
1694 | } | |
1695 | ||
00b3ed16 GKH |
1696 | /*---------------------------------------------------------------- |
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 | ----------------------------------------------------------------*/ | |
297f06ce | 1718 | int hfa384x_drvr_disable(hfa384x_t *hw, u16 macport) |
00b3ed16 | 1719 | { |
21dc0f89 | 1720 | int result = 0; |
00b3ed16 | 1721 | |
00b3ed16 GKH |
1722 | if ((!hw->isap && macport != 0) || |
1723 | (hw->isap && !(macport <= HFA384x_PORTID_MAX)) || | |
21dc0f89 | 1724 | !(hw->port_enabled[macport])) { |
00b3ed16 GKH |
1725 | result = -EINVAL; |
1726 | } else { | |
1727 | result = hfa384x_cmd_disable(hw, macport); | |
21dc0f89 | 1728 | if (result == 0) |
00b3ed16 | 1729 | hw->port_enabled[macport] = 0; |
00b3ed16 | 1730 | } |
00b3ed16 GKH |
1731 | return result; |
1732 | } | |
1733 | ||
00b3ed16 GKH |
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 | ----------------------------------------------------------------*/ | |
297f06ce | 1756 | int hfa384x_drvr_enable(hfa384x_t *hw, u16 macport) |
00b3ed16 | 1757 | { |
21dc0f89 | 1758 | int result = 0; |
00b3ed16 | 1759 | |
00b3ed16 GKH |
1760 | if ((!hw->isap && macport != 0) || |
1761 | (hw->isap && !(macport <= HFA384x_PORTID_MAX)) || | |
21dc0f89 | 1762 | (hw->port_enabled[macport])) { |
00b3ed16 GKH |
1763 | result = -EINVAL; |
1764 | } else { | |
1765 | result = hfa384x_cmd_enable(hw, macport); | |
21dc0f89 | 1766 | if (result == 0) |
00b3ed16 | 1767 | hw->port_enabled[macport] = 1; |
00b3ed16 | 1768 | } |
00b3ed16 GKH |
1769 | return result; |
1770 | } | |
1771 | ||
00b3ed16 GKH |
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 | ----------------------------------------------------------------*/ | |
297f06ce | 1793 | int hfa384x_drvr_flashdl_enable(hfa384x_t *hw) |
00b3ed16 | 1794 | { |
21dc0f89 MM |
1795 | int result = 0; |
1796 | int i; | |
00b3ed16 | 1797 | |
00b3ed16 | 1798 | /* Check that a port isn't active */ |
21dc0f89 MM |
1799 | for (i = 0; i < HFA384x_PORTID_MAX; i++) { |
1800 | if (hw->port_enabled[i]) { | |
a7cf7bae | 1801 | pr_debug("called when port enabled.\n"); |
00b3ed16 GKH |
1802 | return -EINVAL; |
1803 | } | |
1804 | } | |
1805 | ||
1806 | /* Check that we're not already in a download state */ | |
21dc0f89 | 1807 | if (hw->dlstate != HFA384x_DLSTATE_DISABLED) |
00b3ed16 | 1808 | return -EINVAL; |
00b3ed16 GKH |
1809 | |
1810 | /* Retrieve the buffer loc&size and timeout */ | |
46800b22 | 1811 | result = hfa384x_drvr_getconfig(hw, HFA384x_RID_DOWNLOADBUFFER, |
3f4b4e77 AE |
1812 | &(hw->bufinfo), sizeof(hw->bufinfo)); |
1813 | if (result) | |
00b3ed16 | 1814 | return result; |
3f4b4e77 | 1815 | |
18c7f792 MM |
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); | |
46800b22 | 1819 | result = hfa384x_drvr_getconfig16(hw, HFA384x_RID_MAXLOADTIME, |
3f4b4e77 AE |
1820 | &(hw->dltimeout)); |
1821 | if (result) | |
00b3ed16 | 1822 | return result; |
3f4b4e77 | 1823 | |
18c7f792 | 1824 | hw->dltimeout = le16_to_cpu(hw->dltimeout); |
00b3ed16 | 1825 | |
a7cf7bae | 1826 | pr_debug("flashdl_enable\n"); |
00b3ed16 GKH |
1827 | |
1828 | hw->dlstate = HFA384x_DLSTATE_FLASHENABLED; | |
8a251b55 | 1829 | |
00b3ed16 GKH |
1830 | return result; |
1831 | } | |
1832 | ||
00b3ed16 GKH |
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 | ----------------------------------------------------------------*/ | |
297f06ce | 1852 | int hfa384x_drvr_flashdl_disable(hfa384x_t *hw) |
00b3ed16 | 1853 | { |
00b3ed16 | 1854 | /* Check that we're already in the download state */ |
21dc0f89 | 1855 | if (hw->dlstate != HFA384x_DLSTATE_FLASHENABLED) |
00b3ed16 | 1856 | return -EINVAL; |
00b3ed16 | 1857 | |
a7cf7bae | 1858 | pr_debug("flashdl_enable\n"); |
00b3ed16 GKH |
1859 | |
1860 | /* There isn't much we can do at this point, so I don't */ | |
1861 | /* bother w/ the return value */ | |
21dc0f89 | 1862 | hfa384x_cmd_download(hw, HFA384x_PROGMODE_DISABLE, 0, 0, 0); |
00b3ed16 GKH |
1863 | hw->dlstate = HFA384x_DLSTATE_DISABLED; |
1864 | ||
00b3ed16 GKH |
1865 | return 0; |
1866 | } | |
1867 | ||
00b3ed16 GKH |
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 | ----------------------------------------------------------------*/ | |
297f06ce | 1897 | int hfa384x_drvr_flashdl_write(hfa384x_t *hw, u32 daddr, void *buf, u32 len) |
00b3ed16 | 1898 | { |
21dc0f89 MM |
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; | |
00b3ed16 | 1913 | |
a7cf7bae | 1914 | pr_debug("daddr=0x%08x len=%d\n", daddr, len); |
00b3ed16 GKH |
1915 | |
1916 | /* Check that we're in the flash download state */ | |
21dc0f89 | 1917 | if (hw->dlstate != HFA384x_DLSTATE_FLASHENABLED) |
00b3ed16 | 1918 | return -EINVAL; |
00b3ed16 | 1919 | |
a2120136 SSA |
1920 | netdev_info(hw->wlandev->netdev, |
1921 | "Download %d bytes to flash @0x%06x\n", len, daddr); | |
00b3ed16 GKH |
1922 | |
1923 | /* Convert to flat address for arithmetic */ | |
1924 | /* NOTE: dlbuffer RID stores the address in AUX format */ | |
21dc0f89 MM |
1925 | dlbufaddr = |
1926 | HFA384x_ADDR_AUX_MKFLAT(hw->bufinfo.page, hw->bufinfo.offset); | |
75f49e07 MT |
1927 | pr_debug("dlbuf.page=0x%04x dlbuf.offset=0x%04x dlbufaddr=0x%08x\n", |
1928 | hw->bufinfo.page, hw->bufinfo.offset, dlbufaddr); | |
00b3ed16 GKH |
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 */ | |
21dc0f89 | 1945 | for (i = 0; i < nburns; i++) { |
00b3ed16 GKH |
1946 | /* Get the dest address and len */ |
1947 | burnlen = (len - (hw->bufinfo.len * i)) > hw->bufinfo.len ? | |
21dc0f89 | 1948 | hw->bufinfo.len : (len - (hw->bufinfo.len * i)); |
00b3ed16 GKH |
1949 | burndaddr = daddr + (hw->bufinfo.len * i); |
1950 | burnlo = HFA384x_ADDR_CMD_MKOFF(burndaddr); | |
1951 | burnhi = HFA384x_ADDR_CMD_MKPAGE(burndaddr); | |
1952 | ||
263b8bb9 | 1953 | netdev_info(hw->wlandev->netdev, "Writing %d bytes to flash @0x%06x\n", |
3f2d6564 | 1954 | burnlen, burndaddr); |
00b3ed16 GKH |
1955 | |
1956 | /* Set the download mode */ | |
1957 | result = hfa384x_cmd_download(hw, HFA384x_PROGMODE_NV, | |
21dc0f89 MM |
1958 | burnlo, burnhi, burnlen); |
1959 | if (result) { | |
a2120136 SSA |
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); | |
00b3ed16 GKH |
1963 | goto exit_proc; |
1964 | } | |
1965 | ||
1966 | /* copy the data to the flash download buffer */ | |
21dc0f89 | 1967 | for (j = 0; j < nwrites; j++) { |
00b3ed16 | 1968 | writebuf = buf + |
21dc0f89 MM |
1969 | (i * hw->bufinfo.len) + |
1970 | (j * HFA384x_USB_RWMEM_MAXLEN); | |
1971 | ||
1972 | writepage = HFA384x_ADDR_CMD_MKPAGE(dlbufaddr + | |
631c8dec EH |
1973 | (j * HFA384x_USB_RWMEM_MAXLEN)); |
1974 | writeoffset = HFA384x_ADDR_CMD_MKOFF(dlbufaddr + | |
1975 | (j * HFA384x_USB_RWMEM_MAXLEN)); | |
21dc0f89 MM |
1976 | |
1977 | writelen = burnlen - (j * HFA384x_USB_RWMEM_MAXLEN); | |
1978 | writelen = writelen > HFA384x_USB_RWMEM_MAXLEN ? | |
1979 | HFA384x_USB_RWMEM_MAXLEN : writelen; | |
1980 | ||
1981 | result = hfa384x_dowmem_wait(hw, | |
1982 | writepage, | |
1983 | writeoffset, | |
1984 | writebuf, writelen); | |
00b3ed16 GKH |
1985 | } |
1986 | ||
1987 | /* set the download 'write flash' mode */ | |
1988 | result = hfa384x_cmd_download(hw, | |
21dc0f89 MM |
1989 | HFA384x_PROGMODE_NVWRITE, |
1990 | 0, 0, 0); | |
1991 | if (result) { | |
263b8bb9 | 1992 | netdev_err(hw->wlandev->netdev, |
3f2d6564 SSA |
1993 | "download(NVWRITE,lo=%x,hi=%x,len=%x) cmd failed, result=%d. Aborting d/l\n", |
1994 | burnlo, burnhi, burnlen, result); | |
00b3ed16 GKH |
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 | ||
00b3ed16 GKH |
2007 | return result; |
2008 | } | |
2009 | ||
00b3ed16 GKH |
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 | |
631c8dec | 2027 | * -ENODATA length mismatch between argument and retrieved |
00b3ed16 GKH |
2028 | * record. |
2029 | * | |
2030 | * Side effects: | |
2031 | * | |
2032 | * Call context: | |
2033 | * process | |
2034 | ----------------------------------------------------------------*/ | |
297f06ce | 2035 | int hfa384x_drvr_getconfig(hfa384x_t *hw, u16 rid, void *buf, u16 len) |
00b3ed16 | 2036 | { |
102db1fc | 2037 | return hfa384x_dorrid_wait(hw, rid, buf, len); |
00b3ed16 GKH |
2038 | } |
2039 | ||
00b3ed16 GKH |
2040 | /*---------------------------------------------------------------- |
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 | |
297f06ce | 2064 | hfa384x_drvr_setconfig_async(hfa384x_t *hw, |
21dc0f89 MM |
2065 | u16 rid, |
2066 | void *buf, | |
2067 | u16 len, ctlx_usercb_t usercb, void *usercb_data) | |
00b3ed16 GKH |
2068 | { |
2069 | return hfa384x_dowrid_async(hw, rid, buf, len, | |
2070 | hfa384x_cb_status, usercb, usercb_data); | |
2071 | } | |
2072 | ||
00b3ed16 GKH |
2073 | /*---------------------------------------------------------------- |
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 | ----------------------------------------------------------------*/ | |
297f06ce | 2091 | int hfa384x_drvr_ramdl_disable(hfa384x_t *hw) |
00b3ed16 | 2092 | { |
00b3ed16 | 2093 | /* Check that we're already in the download state */ |
21dc0f89 | 2094 | if (hw->dlstate != HFA384x_DLSTATE_RAMENABLED) |
00b3ed16 | 2095 | return -EINVAL; |
00b3ed16 | 2096 | |
a7cf7bae | 2097 | pr_debug("ramdl_disable()\n"); |
00b3ed16 GKH |
2098 | |
2099 | /* There isn't much we can do at this point, so I don't */ | |
2100 | /* bother w/ the return value */ | |
21dc0f89 | 2101 | hfa384x_cmd_download(hw, HFA384x_PROGMODE_DISABLE, 0, 0, 0); |
00b3ed16 GKH |
2102 | hw->dlstate = HFA384x_DLSTATE_DISABLED; |
2103 | ||
00b3ed16 GKH |
2104 | return 0; |
2105 | } | |
2106 | ||
00b3ed16 GKH |
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 | ----------------------------------------------------------------*/ | |
297f06ce | 2131 | int hfa384x_drvr_ramdl_enable(hfa384x_t *hw, u32 exeaddr) |
00b3ed16 | 2132 | { |
21dc0f89 MM |
2133 | int result = 0; |
2134 | u16 lowaddr; | |
2135 | u16 hiaddr; | |
2136 | int i; | |
8a251b55 | 2137 | |
00b3ed16 | 2138 | /* Check that a port isn't active */ |
21dc0f89 MM |
2139 | for (i = 0; i < HFA384x_PORTID_MAX; i++) { |
2140 | if (hw->port_enabled[i]) { | |
263b8bb9 | 2141 | netdev_err(hw->wlandev->netdev, |
3f2d6564 | 2142 | "Can't download with a macport enabled.\n"); |
00b3ed16 GKH |
2143 | return -EINVAL; |
2144 | } | |
2145 | } | |
2146 | ||
2147 | /* Check that we're not already in a download state */ | |
21dc0f89 | 2148 | if (hw->dlstate != HFA384x_DLSTATE_DISABLED) { |
263b8bb9 | 2149 | netdev_err(hw->wlandev->netdev, "Download state not disabled.\n"); |
00b3ed16 GKH |
2150 | return -EINVAL; |
2151 | } | |
2152 | ||
a7cf7bae | 2153 | pr_debug("ramdl_enable, exeaddr=0x%08x\n", exeaddr); |
00b3ed16 GKH |
2154 | |
2155 | /* Call the download(1,addr) function */ | |
2156 | lowaddr = HFA384x_ADDR_CMD_MKOFF(exeaddr); | |
21dc0f89 | 2157 | hiaddr = HFA384x_ADDR_CMD_MKPAGE(exeaddr); |
00b3ed16 GKH |
2158 | |
2159 | result = hfa384x_cmd_download(hw, HFA384x_PROGMODE_RAM, | |
21dc0f89 | 2160 | lowaddr, hiaddr, 0); |
00b3ed16 | 2161 | |
21dc0f89 | 2162 | if (result == 0) { |
00b3ed16 GKH |
2163 | /* Set the download state */ |
2164 | hw->dlstate = HFA384x_DLSTATE_RAMENABLED; | |
2165 | } else { | |
75f49e07 MT |
2166 | pr_debug("cmd_download(0x%04x, 0x%04x) failed, result=%d.\n", |
2167 | lowaddr, hiaddr, result); | |
00b3ed16 GKH |
2168 | } |
2169 | ||
00b3ed16 GKH |
2170 | return result; |
2171 | } | |
2172 | ||
00b3ed16 GKH |
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 | ----------------------------------------------------------------*/ | |
297f06ce | 2199 | int hfa384x_drvr_ramdl_write(hfa384x_t *hw, u32 daddr, void *buf, u32 len) |
00b3ed16 | 2200 | { |
21dc0f89 MM |
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; | |
8a251b55 | 2209 | |
00b3ed16 | 2210 | /* Check that we're in the ram download state */ |
21dc0f89 | 2211 | if (hw->dlstate != HFA384x_DLSTATE_RAMENABLED) |
00b3ed16 | 2212 | return -EINVAL; |
00b3ed16 | 2213 | |
a2120136 SSA |
2214 | netdev_info(hw->wlandev->netdev, "Writing %d bytes to ram @0x%06x\n", |
2215 | len, daddr); | |
00b3ed16 GKH |
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 */ | |
21dc0f89 | 2222 | for (i = 0; i < nwrites; i++) { |
00b3ed16 GKH |
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); | |
21dc0f89 | 2228 | if (currlen > HFA384x_USB_RWMEM_MAXLEN) |
00b3ed16 | 2229 | currlen = HFA384x_USB_RWMEM_MAXLEN; |
00b3ed16 | 2230 | |
21dc0f89 MM |
2231 | /* Do blocking ctlx */ |
2232 | result = hfa384x_dowmem_wait(hw, | |
2233 | currpage, | |
2234 | curroffset, | |
2235 | data + | |
2236 | (i * HFA384x_USB_RWMEM_MAXLEN), | |
2237 | currlen); | |
00b3ed16 | 2238 | |
21dc0f89 MM |
2239 | if (result) |
2240 | break; | |
00b3ed16 GKH |
2241 | |
2242 | /* TODO: We really should have a readback. */ | |
2243 | } | |
2244 | ||
00b3ed16 GKH |
2245 | return result; |
2246 | } | |
2247 | ||
00b3ed16 GKH |
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 | |
1a6dfce7 | 2266 | * -ETIMEDOUT timeout waiting for the cmd regs to become |
00b3ed16 GKH |
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 | ----------------------------------------------------------------*/ | |
297f06ce | 2279 | int hfa384x_drvr_readpda(hfa384x_t *hw, void *buf, unsigned int len) |
00b3ed16 | 2280 | { |
21dc0f89 MM |
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; | |
00b3ed16 | 2291 | struct pdaloc { |
21dc0f89 MM |
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} | |
00b3ed16 GKH |
2299 | }; |
2300 | ||
00b3ed16 | 2301 | /* Read the pda from each known address. */ |
21dc0f89 | 2302 | for (i = 0; i < ARRAY_SIZE(pdaloc); i++) { |
00b3ed16 GKH |
2303 | /* Make address */ |
2304 | currpage = HFA384x_ADDR_CMD_MKPAGE(pdaloc[i].cardaddr); | |
2305 | curroffset = HFA384x_ADDR_CMD_MKOFF(pdaloc[i].cardaddr); | |
2306 | ||
631c8dec EH |
2307 | /* units of bytes */ |
2308 | result = hfa384x_dormem_wait(hw, currpage, curroffset, buf, | |
2309 | len); | |
00b3ed16 GKH |
2310 | |
2311 | if (result) { | |
263b8bb9 | 2312 | netdev_warn(hw->wlandev->netdev, |
3f2d6564 SSA |
2313 | "Read from index %zd failed, continuing\n", |
2314 | i); | |
00b3ed16 GKH |
2315 | continue; |
2316 | } | |
2317 | ||
2318 | /* Test for garbage */ | |
2319 | pdaok = 1; /* initially assume good */ | |
2320 | morepdrs = 1; | |
21dc0f89 | 2321 | while (pdaok && morepdrs) { |
18c7f792 MM |
2322 | pdrlen = le16_to_cpu(pda[currpdr]) * 2; |
2323 | pdrcode = le16_to_cpu(pda[currpdr + 1]); | |
00b3ed16 | 2324 | /* Test the record length */ |
21dc0f89 | 2325 | if (pdrlen > HFA384x_PDR_LEN_MAX || pdrlen == 0) { |
a2120136 SSA |
2326 | netdev_err(hw->wlandev->netdev, |
2327 | "pdrlen invalid=%d\n", pdrlen); | |
00b3ed16 GKH |
2328 | pdaok = 0; |
2329 | break; | |
2330 | } | |
2331 | /* Test the code */ | |
21dc0f89 | 2332 | if (!hfa384x_isgood_pdrcode(pdrcode)) { |
263b8bb9 | 2333 | netdev_err(hw->wlandev->netdev, "pdrcode invalid=%d\n", |
3f2d6564 | 2334 | pdrcode); |
00b3ed16 GKH |
2335 | pdaok = 0; |
2336 | break; | |
2337 | } | |
2338 | /* Test for completion */ | |
21dc0f89 | 2339 | if (pdrcode == HFA384x_PDR_END_OF_PDA) |
00b3ed16 | 2340 | morepdrs = 0; |
00b3ed16 GKH |
2341 | |
2342 | /* Move to the next pdr (if necessary) */ | |
21dc0f89 | 2343 | if (morepdrs) { |
00b3ed16 | 2344 | /* note the access to pda[], need words here */ |
18c7f792 | 2345 | currpdr += le16_to_cpu(pda[currpdr]) + 1; |
00b3ed16 GKH |
2346 | } |
2347 | } | |
21dc0f89 | 2348 | if (pdaok) { |
263b8bb9 | 2349 | netdev_info(hw->wlandev->netdev, |
3f2d6564 SSA |
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>"); | |
00b3ed16 GKH |
2357 | break; |
2358 | } | |
2359 | } | |
2360 | result = pdaok ? 0 : -ENODATA; | |
2361 | ||
21dc0f89 | 2362 | if (result) |
a7cf7bae | 2363 | pr_debug("Failure: pda is not okay\n"); |
00b3ed16 | 2364 | |
00b3ed16 GKH |
2365 | return result; |
2366 | } | |
2367 | ||
00b3ed16 GKH |
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 | ----------------------------------------------------------------*/ | |
297f06ce | 2389 | int hfa384x_drvr_setconfig(hfa384x_t *hw, u16 rid, void *buf, u16 len) |
00b3ed16 GKH |
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 | ----------------------------------------------------------------*/ | |
7b7e7e84 | 2413 | |
297f06ce | 2414 | int hfa384x_drvr_start(hfa384x_t *hw) |
00b3ed16 | 2415 | { |
21dc0f89 MM |
2416 | int result, result1, result2; |
2417 | u16 status; | |
00b3ed16 GKH |
2418 | |
2419 | might_sleep(); | |
2420 | ||
7b7e7e84 RK |
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 | */ | |
21dc0f89 MM |
2426 | result = |
2427 | usb_get_status(hw->usb, USB_RECIP_ENDPOINT, hw->endp_in, &status); | |
7b7e7e84 | 2428 | if (result < 0) { |
263b8bb9 | 2429 | netdev_err(hw->wlandev->netdev, "Cannot get bulk in endpoint status.\n"); |
7b7e7e84 RK |
2430 | goto done; |
2431 | } | |
21dc0f89 | 2432 | if ((status == 1) && usb_clear_halt(hw->usb, hw->endp_in)) |
263b8bb9 | 2433 | netdev_err(hw->wlandev->netdev, "Failed to reset bulk in endpoint.\n"); |
00b3ed16 | 2434 | |
21dc0f89 MM |
2435 | result = |
2436 | usb_get_status(hw->usb, USB_RECIP_ENDPOINT, hw->endp_out, &status); | |
7b7e7e84 | 2437 | if (result < 0) { |
263b8bb9 | 2438 | netdev_err(hw->wlandev->netdev, "Cannot get bulk out endpoint status.\n"); |
7b7e7e84 RK |
2439 | goto done; |
2440 | } | |
21dc0f89 | 2441 | if ((status == 1) && usb_clear_halt(hw->usb, hw->endp_out)) |
263b8bb9 | 2442 | netdev_err(hw->wlandev->netdev, "Failed to reset bulk out endpoint.\n"); |
00b3ed16 GKH |
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) { | |
263b8bb9 | 2450 | netdev_err(hw->wlandev->netdev, |
3f2d6564 SSA |
2451 | "Fatal, failed to submit RX URB, result=%d\n", |
2452 | result); | |
00b3ed16 GKH |
2453 | goto done; |
2454 | } | |
2455 | ||
7b7e7e84 RK |
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); | |
96b1971a SSA |
2468 | result = hfa384x_cmd_initialize(hw); |
2469 | result2 = result; | |
7b7e7e84 RK |
2470 | if (result1 != 0) { |
2471 | if (result2 != 0) { | |
263b8bb9 | 2472 | netdev_err(hw->wlandev->netdev, |
3f2d6564 SSA |
2473 | "cmd_initialize() failed on two attempts, results %d and %d\n", |
2474 | result1, result2); | |
7b7e7e84 RK |
2475 | usb_kill_urb(&hw->rx_urb); |
2476 | goto done; | |
2477 | } else { | |
75f49e07 MT |
2478 | pr_debug("First cmd_initialize() failed (result %d),\n", |
2479 | result1); | |
4ffab688 | 2480 | pr_debug("but second attempt succeeded. All should be ok\n"); |
7b7e7e84 RK |
2481 | } |
2482 | } else if (result2 != 0) { | |
263b8bb9 | 2483 | netdev_warn(hw->wlandev->netdev, "First cmd_initialize() succeeded, but second attempt failed (result=%d)\n", |
3f2d6564 | 2484 | result2); |
263b8bb9 | 2485 | netdev_warn(hw->wlandev->netdev, |
3f2d6564 | 2486 | "Most likely the card will be functional\n"); |
21dc0f89 | 2487 | goto done; |
00b3ed16 GKH |
2488 | } |
2489 | ||
2490 | hw->state = HFA384x_STATE_RUNNING; | |
2491 | ||
2492 | done: | |
00b3ed16 GKH |
2493 | return result; |
2494 | } | |
2495 | ||
00b3ed16 GKH |
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 | ----------------------------------------------------------------*/ | |
297f06ce | 2515 | int hfa384x_drvr_stop(hfa384x_t *hw) |
00b3ed16 | 2516 | { |
21dc0f89 | 2517 | int i; |
00b3ed16 GKH |
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 | */ | |
21dc0f89 | 2524 | if (!hw->wlandev->hwremoved) { |
00b3ed16 GKH |
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 */ | |
21dc0f89 | 2538 | for (i = 0; i < HFA384x_NUMPORTS_MAX; i++) |
00b3ed16 | 2539 | hw->port_enabled[i] = 0; |
00b3ed16 | 2540 | |
4764ca98 | 2541 | return 0; |
00b3ed16 GKH |
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 | ----------------------------------------------------------------*/ | |
297f06ce | 2565 | int hfa384x_drvr_txframe(hfa384x_t *hw, struct sk_buff *skb, |
93df38e5 | 2566 | union p80211_hdr *p80211_hdr, |
51e4896a | 2567 | struct p80211_metawep *p80211_wep) |
00b3ed16 | 2568 | { |
eb76afc9 | 2569 | int usbpktlen = sizeof(struct hfa384x_tx_frame); |
21dc0f89 MM |
2570 | int result; |
2571 | int ret; | |
2572 | char *ptr; | |
00b3ed16 | 2573 | |
00b3ed16 | 2574 | if (hw->tx_urb.status == -EINPROGRESS) { |
263b8bb9 | 2575 | netdev_warn(hw->wlandev->netdev, "TX URB already in use\n"); |
00b3ed16 GKH |
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 */ | |
18c7f792 | 2585 | hw->txbuff.type = cpu_to_le16(HFA384x_USB_TXFRM); |
00b3ed16 GKH |
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 | */ | |
21dc0f89 | 2593 | /* #define DOEXC SLP -- doboth breaks horribly under load, doexc less so. */ |
00b3ed16 GKH |
2594 | #if defined(DOBOTH) |
2595 | hw->txbuff.txfrm.desc.tx_control = | |
21dc0f89 MM |
2596 | HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) | |
2597 | HFA384x_TX_TXEX_SET(1) | HFA384x_TX_TXOK_SET(1); | |
00b3ed16 GKH |
2598 | #elif defined(DOEXC) |
2599 | hw->txbuff.txfrm.desc.tx_control = | |
21dc0f89 MM |
2600 | HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) | |
2601 | HFA384x_TX_TXEX_SET(1) | HFA384x_TX_TXOK_SET(0); | |
00b3ed16 GKH |
2602 | #else |
2603 | hw->txbuff.txfrm.desc.tx_control = | |
21dc0f89 MM |
2604 | HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) | |
2605 | HFA384x_TX_TXEX_SET(0) | HFA384x_TX_TXOK_SET(0); | |
00b3ed16 GKH |
2606 | #endif |
2607 | hw->txbuff.txfrm.desc.tx_control = | |
18c7f792 | 2608 | cpu_to_le16(hw->txbuff.txfrm.desc.tx_control); |
00b3ed16 GKH |
2609 | |
2610 | /* copy the header over to the txdesc */ | |
21dc0f89 | 2611 | memcpy(&(hw->txbuff.txfrm.desc.frame_control), p80211_hdr, |
93df38e5 | 2612 | sizeof(union p80211_hdr)); |
00b3ed16 GKH |
2613 | |
2614 | /* if we're using host WEP, increase size by IV+ICV */ | |
2615 | if (p80211_wep->data) { | |
18c7f792 | 2616 | hw->txbuff.txfrm.desc.data_len = cpu_to_le16(skb->len + 8); |
21dc0f89 | 2617 | usbpktlen += 8; |
00b3ed16 | 2618 | } else { |
18c7f792 | 2619 | hw->txbuff.txfrm.desc.data_len = cpu_to_le16(skb->len); |
00b3ed16 GKH |
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)); | |
21dc0f89 | 2628 | ptr += sizeof(p80211_wep->iv); |
00b3ed16 GKH |
2629 | memcpy(ptr, p80211_wep->data, skb->len); |
2630 | } else { | |
2631 | memcpy(ptr, skb->data, skb->len); | |
2632 | } | |
2633 | /* copy over the packet data */ | |
21dc0f89 | 2634 | ptr += skb->len; |
00b3ed16 GKH |
2635 | |
2636 | /* copy over the WEP ICV if we are using host WEP */ | |
21dc0f89 | 2637 | if (p80211_wep->data) |
00b3ed16 | 2638 | memcpy(ptr, p80211_wep->icv, sizeof(p80211_wep->icv)); |
00b3ed16 GKH |
2639 | |
2640 | /* Send the USB packet */ | |
21dc0f89 MM |
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); | |
00b3ed16 GKH |
2645 | hw->tx_urb.transfer_flags |= USB_QUEUE_BULK; |
2646 | ||
2647 | result = 1; | |
2648 | ret = submit_tx_urb(hw, &hw->tx_urb, GFP_ATOMIC); | |
21dc0f89 | 2649 | if (ret != 0) { |
a2120136 SSA |
2650 | netdev_err(hw->wlandev->netdev, |
2651 | "submit_tx_urb() failed, error=%d\n", ret); | |
00b3ed16 GKH |
2652 | result = 3; |
2653 | } | |
2654 | ||
21dc0f89 | 2655 | exit: |
00b3ed16 GKH |
2656 | return result; |
2657 | } | |
2658 | ||
c9573a8d | 2659 | void hfa384x_tx_timeout(struct wlandevice *wlandev) |
00b3ed16 | 2660 | { |
21dc0f89 | 2661 | hfa384x_t *hw = wlandev->priv; |
00b3ed16 GKH |
2662 | unsigned long flags; |
2663 | ||
00b3ed16 GKH |
2664 | spin_lock_irqsave(&hw->ctlxq.lock, flags); |
2665 | ||
59457897 DC |
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); | |
00b3ed16 GKH |
2673 | } |
2674 | ||
2675 | spin_unlock_irqrestore(&hw->ctlxq.lock, flags); | |
00b3ed16 GKH |
2676 | } |
2677 | ||
2678 | /*---------------------------------------------------------------- | |
2679 | * hfa384x_usbctlx_reaper_task | |
2680 | * | |
2681 | * Tasklet to delete dead CTLX objects | |
2682 | * | |
2683 | * Arguments: | |
2684 | * data ptr to a hfa384x_t | |
2685 | * | |
2686 | * Returns: | |
2687 | * | |
2688 | * Call context: | |
2689 | * Interrupt | |
2690 | ----------------------------------------------------------------*/ | |
2691 | static void hfa384x_usbctlx_reaper_task(unsigned long data) | |
2692 | { | |
5d85fe34 | 2693 | hfa384x_t *hw = (hfa384x_t *)data; |
57477bf0 | 2694 | hfa384x_usbctlx_t *ctlx, *temp; |
21dc0f89 | 2695 | unsigned long flags; |
00b3ed16 | 2696 | |
00b3ed16 GKH |
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 | */ | |
57477bf0 | 2702 | list_for_each_entry_safe(ctlx, temp, &hw->ctlxq.reapable, list) { |
00b3ed16 GKH |
2703 | list_del(&ctlx->list); |
2704 | kfree(ctlx); | |
2705 | } | |
2706 | ||
2707 | spin_unlock_irqrestore(&hw->ctlxq.lock, flags); | |
00b3ed16 GKH |
2708 | } |
2709 | ||
2710 | /*---------------------------------------------------------------- | |
2711 | * hfa384x_usbctlx_completion_task | |
2712 | * | |
2713 | * Tasklet to call completion handlers for returned CTLXs | |
2714 | * | |
2715 | * Arguments: | |
2716 | * data ptr to hfa384x_t | |
2717 | * | |
2718 | * Returns: | |
2719 | * Nothing | |
2720 | * | |
2721 | * Call context: | |
2722 | * Interrupt | |
2723 | ----------------------------------------------------------------*/ | |
2724 | static void hfa384x_usbctlx_completion_task(unsigned long data) | |
2725 | { | |
5d85fe34 | 2726 | hfa384x_t *hw = (hfa384x_t *)data; |
57477bf0 | 2727 | hfa384x_usbctlx_t *ctlx, *temp; |
00b3ed16 GKH |
2728 | unsigned long flags; |
2729 | ||
2730 | int reap = 0; | |
2731 | ||
00b3ed16 GKH |
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 | */ | |
57477bf0 | 2737 | list_for_each_entry_safe(ctlx, temp, &hw->ctlxq.completing, list) { |
00b3ed16 GKH |
2738 | /* Call the completion function that this |
2739 | * command was assigned, assuming it has one. | |
2740 | */ | |
02e02048 | 2741 | if (ctlx->cmdcb) { |
00b3ed16 GKH |
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 | */ | |
21dc0f89 | 2754 | if (hw->wlandev->hwremoved) { |
00b3ed16 GKH |
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 | */ | |
21dc0f89 | 2765 | if (ctlx->reapable) { |
00b3ed16 GKH |
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); | |
00b3ed16 GKH |
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: | |
2790 | * hw ptr to the hfa384x_t structure | |
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 | ----------------------------------------------------------------*/ | |
297f06ce MT |
2800 | static int unlocked_usbctlx_cancel_async(hfa384x_t *hw, |
2801 | hfa384x_usbctlx_t *ctlx) | |
00b3ed16 GKH |
2802 | { |
2803 | int ret; | |
2804 | ||
00b3ed16 GKH |
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 | ||
00b3ed16 GKH |
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: | |
2839 | * hw ptr to a hfa384x_t structure | |
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 | ----------------------------------------------------------------*/ | |
297f06ce | 2850 | static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx) |
00b3ed16 | 2851 | { |
00b3ed16 GKH |
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: | |
263b8bb9 | 2866 | netdev_err(hw->wlandev->netdev, "CTLX[%d] not in a terminating state(%s)\n", |
3f2d6564 SSA |
2867 | le16_to_cpu(ctlx->outbuf.type), |
2868 | ctlxstr(ctlx->state)); | |
00b3ed16 | 2869 | break; |
21dc0f89 | 2870 | } /* switch */ |
00b3ed16 GKH |
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: | |
2879 | * hw ptr to hfa384x_t | |
2880 | * | |
2881 | * Returns: | |
2882 | * nothing | |
2883 | * | |
2884 | * Side effects: | |
2885 | * | |
2886 | * Call context: | |
2887 | * any | |
2888 | ----------------------------------------------------------------*/ | |
297f06ce | 2889 | static void hfa384x_usbctlxq_run(hfa384x_t *hw) |
00b3ed16 | 2890 | { |
21dc0f89 | 2891 | unsigned long flags; |
00b3ed16 GKH |
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 | */ | |
21dc0f89 MM |
2903 | if (!list_empty(&hw->ctlxq.active) || |
2904 | test_bit(WORK_TX_HALT, &hw->usb_flags) || hw->wlandev->hwremoved) | |
00b3ed16 GKH |
2905 | goto unlock; |
2906 | ||
21dc0f89 MM |
2907 | while (!list_empty(&hw->ctlxq.pending)) { |
2908 | hfa384x_usbctlx_t *head; | |
2909 | int result; | |
00b3ed16 GKH |
2910 | |
2911 | /* This is the first pending command */ | |
2912 | head = list_entry(hw->ctlxq.pending.next, | |
21dc0f89 | 2913 | hfa384x_usbctlx_t, list); |
00b3ed16 GKH |
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 */ | |
21dc0f89 MM |
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); | |
00b3ed16 GKH |
2923 | hw->ctlx_urb.transfer_flags |= USB_QUEUE_BULK; |
2924 | ||
3f4b4e77 | 2925 | /* Now submit the URB and update the CTLX's state */ |
5850c251 | 2926 | result = usb_submit_urb(&hw->ctlx_urb, GFP_ATOMIC); |
46800b22 | 2927 | if (result == 0) { |
00b3ed16 GKH |
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; | |
21dc0f89 | 2938 | hw->resptimer.expires = jiffies + 2 * HZ; |
00b3ed16 GKH |
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 | */ | |
263b8bb9 | 2949 | netdev_warn(hw->wlandev->netdev, |
3f2d6564 SSA |
2950 | "%s tx pipe stalled: requesting reset\n", |
2951 | hw->wlandev->netdev->name); | |
00b3ed16 GKH |
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) { | |
263b8bb9 | 2959 | netdev_warn(hw->wlandev->netdev, "%s urb shutdown!\n", |
3f2d6564 | 2960 | hw->wlandev->netdev->name); |
00b3ed16 GKH |
2961 | break; |
2962 | } | |
2963 | ||
263b8bb9 | 2964 | netdev_err(hw->wlandev->netdev, "Failed to submit CTLX[%d]: error=%d\n", |
3f2d6564 | 2965 | le16_to_cpu(head->outbuf.type), result); |
00b3ed16 | 2966 | unlocked_usbctlx_complete(hw, head); |
21dc0f89 | 2967 | } /* while */ |
00b3ed16 | 2968 | |
21dc0f89 | 2969 | unlock: |
00b3ed16 | 2970 | spin_unlock_irqrestore(&hw->ctlxq.lock, flags); |
00b3ed16 GKH |
2971 | } |
2972 | ||
00b3ed16 GKH |
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 | ----------------------------------------------------------------*/ | |
00b3ed16 | 2989 | static void hfa384x_usbin_callback(struct urb *urb) |
00b3ed16 | 2990 | { |
c9573a8d | 2991 | struct wlandevice *wlandev = urb->context; |
21dc0f89 | 2992 | hfa384x_t *hw; |
5d85fe34 | 2993 | hfa384x_usbin_t *usbin = (hfa384x_usbin_t *)urb->transfer_buffer; |
21dc0f89 MM |
2994 | struct sk_buff *skb = NULL; |
2995 | int result; | |
2996 | int urb_status; | |
2997 | u16 type; | |
00b3ed16 GKH |
2998 | |
2999 | enum USBIN_ACTION { | |
3000 | HANDLE, | |
3001 | RESUBMIT, | |
3002 | ABORT | |
3003 | } action; | |
3004 | ||
21dc0f89 | 3005 | if (!wlandev || !wlandev->netdev || wlandev->hwremoved) |
00b3ed16 GKH |
3006 | goto exit; |
3007 | ||
3008 | hw = wlandev->priv; | |
3009 | if (!hw) | |
3010 | goto exit; | |
3011 | ||
3012 | skb = hw->rx_urb_skb; | |
2961f24f | 3013 | BUG_ON(!skb || (skb->data != urb->transfer_buffer)); |
21dc0f89 | 3014 | |
00b3ed16 GKH |
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 */ | |
21dc0f89 | 3023 | if (urb->actual_length == 0) { |
9630f6b9 TK |
3024 | wlandev->netdev->stats.rx_errors++; |
3025 | wlandev->netdev->stats.rx_length_errors++; | |
00b3ed16 GKH |
3026 | action = RESUBMIT; |
3027 | } | |
3028 | break; | |
3029 | ||
3030 | case -EPIPE: | |
263b8bb9 | 3031 | netdev_warn(hw->wlandev->netdev, "%s rx pipe stalled: requesting reset\n", |
3f2d6564 | 3032 | wlandev->netdev->name); |
21dc0f89 | 3033 | if (!test_and_set_bit(WORK_RX_HALT, &hw->usb_flags)) |
00b3ed16 | 3034 | schedule_work(&hw->usb_work); |
9630f6b9 | 3035 | wlandev->netdev->stats.rx_errors++; |
00b3ed16 GKH |
3036 | action = ABORT; |
3037 | break; | |
3038 | ||
3039 | case -EILSEQ: | |
3040 | case -ETIMEDOUT: | |
3041 | case -EPROTO: | |
21dc0f89 MM |
3042 | if (!test_and_set_bit(THROTTLE_RX, &hw->usb_flags) && |
3043 | !timer_pending(&hw->throttle)) { | |
00b3ed16 GKH |
3044 | mod_timer(&hw->throttle, jiffies + THROTTLE_JIFFIES); |
3045 | } | |
9630f6b9 | 3046 | wlandev->netdev->stats.rx_errors++; |
00b3ed16 GKH |
3047 | action = ABORT; |
3048 | break; | |
3049 | ||
3050 | case -EOVERFLOW: | |
9630f6b9 | 3051 | wlandev->netdev->stats.rx_over_errors++; |
00b3ed16 GKH |
3052 | action = RESUBMIT; |
3053 | break; | |
3054 | ||
3055 | case -ENODEV: | |
3056 | case -ESHUTDOWN: | |
a7cf7bae | 3057 | pr_debug("status=%d, device removed.\n", urb->status); |
00b3ed16 GKH |
3058 | action = ABORT; |
3059 | break; | |
3060 | ||
3061 | case -ENOENT: | |
3062 | case -ECONNRESET: | |
75f49e07 | 3063 | pr_debug("status=%d, urb explicitly unlinked.\n", urb->status); |
00b3ed16 GKH |
3064 | action = ABORT; |
3065 | break; | |
3066 | ||
3067 | default: | |
a7cf7bae | 3068 | pr_debug("urb status=%d, transfer flags=0x%x\n", |
75f49e07 | 3069 | urb->status, urb->transfer_flags); |
9630f6b9 | 3070 | wlandev->netdev->stats.rx_errors++; |
00b3ed16 GKH |
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) { | |
263b8bb9 | 3082 | netdev_err(hw->wlandev->netdev, |
3f2d6564 SSA |
3083 | "Fatal, failed to resubmit rx_urb. error=%d\n", |
3084 | result); | |
00b3ed16 GKH |
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 | */ | |
18c7f792 | 3092 | type = le16_to_cpu(usbin->type); |
00b3ed16 GKH |
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: | |
a7cf7bae | 3128 | pr_debug("Received BUFAVAIL packet, frmlen=%d\n", |
75f49e07 | 3129 | usbin->bufavail.frmlen); |
00b3ed16 GKH |
3130 | break; |
3131 | ||
3132 | case HFA384x_USB_ERROR: | |
a7cf7bae | 3133 | pr_debug("Received USB_ERROR packet, errortype=%d\n", |
75f49e07 | 3134 | usbin->usberror.errortype); |
00b3ed16 GKH |
3135 | break; |
3136 | ||
3137 | default: | |
75f49e07 MT |
3138 | pr_debug("Unrecognized USBIN packet, type=%x, status=%d\n", |
3139 | usbin->type, urb_status); | |
00b3ed16 | 3140 | break; |
21dc0f89 | 3141 | } /* switch */ |
00b3ed16 GKH |
3142 | |
3143 | exit: | |
3144 | ||
3145 | if (skb) | |
3146 | dev_kfree_skb(skb); | |
00b3ed16 GKH |
3147 | } |
3148 | ||
00b3ed16 GKH |
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: | |
3157 | * hw ptr to hfa384x_t | |
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 | ----------------------------------------------------------------*/ | |
297f06ce | 3169 | static void hfa384x_usbin_ctlx(hfa384x_t *hw, hfa384x_usbin_t *usbin, |
00b3ed16 GKH |
3170 | int urb_status) |
3171 | { | |
21dc0f89 MM |
3172 | hfa384x_usbctlx_t *ctlx; |
3173 | int run_queue = 0; | |
3174 | unsigned long flags; | |
00b3ed16 | 3175 | |
00b3ed16 GKH |
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 | */ | |
21dc0f89 | 3183 | if (list_empty(&hw->ctlxq.active)) |
00b3ed16 | 3184 | goto unlock; |
00b3ed16 GKH |
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 | } | |
21dc0f89 | 3197 | } else { |
00b3ed16 GKH |
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 { | |
a78d1312 | 3212 | const __le16 intype = (usbin->type & ~cpu_to_le16(0x8000)); |
00b3ed16 GKH |
3213 | |
3214 | /* | |
3215 | * Check that our message is what we're expecting ... | |
3216 | */ | |
3217 | if (ctlx->outbuf.type != intype) { | |
263b8bb9 | 3218 | netdev_warn(hw->wlandev->netdev, |
3f2d6564 SSA |
3219 | "Expected IN[%d], received IN[%d] - ignored.\n", |
3220 | le16_to_cpu(ctlx->outbuf.type), | |
3221 | le16_to_cpu(intype)); | |
00b3ed16 GKH |
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 | */ | |
4ffab688 | 3235 | pr_debug("Causality violation: please reboot Universe\n"); |
00b3ed16 GKH |
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 | */ | |
263b8bb9 | 3254 | netdev_err(hw->wlandev->netdev, |
3f2d6564 SSA |
3255 | "Matched IN URB, CTLX[%d] in invalid state(%s). Discarded.\n", |
3256 | le16_to_cpu(ctlx->outbuf.type), | |
3257 | ctlxstr(ctlx->state)); | |
00b3ed16 GKH |
3258 | if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0) |
3259 | run_queue = 1; | |
3260 | break; | |
21dc0f89 | 3261 | } /* switch */ |
00b3ed16 GKH |
3262 | } |
3263 | ||
3264 | unlock: | |
3265 | spin_unlock_irqrestore(&hw->ctlxq.lock, flags); | |
3266 | ||
3267 | if (run_queue) | |
3268 | hfa384x_usbctlxq_run(hw); | |
00b3ed16 GKH |
3269 | } |
3270 | ||
00b3ed16 GKH |
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 | ----------------------------------------------------------------*/ | |
c9573a8d | 3288 | static void hfa384x_usbin_txcompl(struct wlandevice *wlandev, |
297f06ce | 3289 | hfa384x_usbin_t *usbin) |
00b3ed16 | 3290 | { |
21dc0f89 | 3291 | u16 status; |
00b3ed16 | 3292 | |
631c8dec | 3293 | status = le16_to_cpu(usbin->type); /* yeah I know it says type... */ |
00b3ed16 GKH |
3294 | |
3295 | /* Was there an error? */ | |
21dc0f89 | 3296 | if (HFA384x_TXSTATUS_ISERROR(status)) |
00b3ed16 | 3297 | prism2sta_ev_txexc(wlandev, status); |
21dc0f89 | 3298 | else |
00b3ed16 | 3299 | prism2sta_ev_tx(wlandev, status); |
00b3ed16 GKH |
3300 | } |
3301 | ||
00b3ed16 GKH |
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 | ----------------------------------------------------------------*/ | |
c9573a8d | 3319 | static void hfa384x_usbin_rx(struct wlandevice *wlandev, struct sk_buff *skb) |
00b3ed16 | 3320 | { |
5d85fe34 | 3321 | hfa384x_usbin_t *usbin = (hfa384x_usbin_t *)skb->data; |
21dc0f89 MM |
3322 | hfa384x_t *hw = wlandev->priv; |
3323 | int hdrlen; | |
51e4896a | 3324 | struct p80211_rxmeta *rxmeta; |
21dc0f89 MM |
3325 | u16 data_len; |
3326 | u16 fc; | |
00b3ed16 | 3327 | |
00b3ed16 | 3328 | /* Byte order convert once up front. */ |
18c7f792 MM |
3329 | usbin->rxfrm.desc.status = le16_to_cpu(usbin->rxfrm.desc.status); |
3330 | usbin->rxfrm.desc.time = le32_to_cpu(usbin->rxfrm.desc.time); | |
00b3ed16 GKH |
3331 | |
3332 | /* Now handle frame based on port# */ | |
21dc0f89 | 3333 | switch (HFA384x_RXSTATUS_MACPORT_GET(usbin->rxfrm.desc.status)) { |
00b3ed16 | 3334 | case 0: |
ae26230b | 3335 | fc = le16_to_cpu(usbin->rxfrm.desc.frame_control); |
00b3ed16 GKH |
3336 | |
3337 | /* If exclude and we receive an unencrypted, drop it */ | |
21dc0f89 MM |
3338 | if ((wlandev->hostwep & HOSTWEP_EXCLUDEUNENCRYPTED) && |
3339 | !WLAN_GET_FC_ISWEP(fc)) { | |
cc5bcbbd | 3340 | break; |
00b3ed16 GKH |
3341 | } |
3342 | ||
18c7f792 | 3343 | data_len = le16_to_cpu(usbin->rxfrm.desc.data_len); |
00b3ed16 GKH |
3344 | |
3345 | /* How much header data do we have? */ | |
3346 | hdrlen = p80211_headerlen(fc); | |
3347 | ||
3348 | /* Pull off the descriptor */ | |
70adf509 | 3349 | skb_pull(skb, sizeof(struct hfa384x_rx_frame)); |
00b3ed16 GKH |
3350 | |
3351 | /* Now shunt the header block up against the data block | |
3352 | * with an "overlapping" copy | |
3353 | */ | |
3354 | memmove(skb_push(skb, hdrlen), | |
21dc0f89 | 3355 | &usbin->rxfrm.desc.frame_control, hdrlen); |
00b3ed16 GKH |
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 | ||
4e2cdf93 | 3376 | p80211netdev_rx(wlandev, skb); |
00b3ed16 GKH |
3377 | |
3378 | break; | |
3379 | ||
3380 | case 7: | |
21dc0f89 | 3381 | if (!HFA384x_RXSTATUS_ISFCSERR(usbin->rxfrm.desc.status)) { |
00b3ed16 | 3382 | /* Copy to wlansnif skb */ |
21dc0f89 | 3383 | hfa384x_int_rxmonitor(wlandev, &usbin->rxfrm); |
00b3ed16 GKH |
3384 | dev_kfree_skb(skb); |
3385 | } else { | |
75f49e07 | 3386 | pr_debug("Received monitor frame: FCSerr set\n"); |
00b3ed16 GKH |
3387 | } |
3388 | break; | |
3389 | ||
3390 | default: | |
263b8bb9 | 3391 | netdev_warn(hw->wlandev->netdev, "Received frame on unsupported port=%d\n", |
3f2d6564 SSA |
3392 | HFA384x_RXSTATUS_MACPORT_GET( |
3393 | usbin->rxfrm.desc.status)); | |
00b3ed16 GKH |
3394 | break; |
3395 | } | |
00b3ed16 GKH |
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 | ----------------------------------------------------------------*/ | |
c9573a8d | 3419 | static void hfa384x_int_rxmonitor(struct wlandevice *wlandev, |
684b2e08 | 3420 | struct hfa384x_usb_rxfrm *rxfrm) |
00b3ed16 | 3421 | { |
70adf509 | 3422 | struct hfa384x_rx_frame *rxdesc = &(rxfrm->desc); |
21dc0f89 MM |
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; | |
3429 | hfa384x_t *hw = wlandev->priv; | |
00b3ed16 | 3430 | |
631c8dec | 3431 | /* Remember the status, time, and data_len fields are in host order */ |
00b3ed16 | 3432 | /* Figure out how big the frame is */ |
ae26230b | 3433 | fc = le16_to_cpu(rxdesc->frame_control); |
00b3ed16 | 3434 | hdrlen = p80211_headerlen(fc); |
18c7f792 | 3435 | datalen = le16_to_cpu(rxdesc->data_len); |
00b3ed16 GKH |
3436 | |
3437 | /* Allocate an ind message+framesize skb */ | |
51e4896a | 3438 | skblen = sizeof(struct p80211_caphdr) + hdrlen + datalen + WLAN_CRC_LEN; |
00b3ed16 GKH |
3439 | |
3440 | /* sanity check the length */ | |
21dc0f89 | 3441 | if (skblen > |
51e4896a | 3442 | (sizeof(struct p80211_caphdr) + |
21dc0f89 | 3443 | WLAN_HDR_A4_LEN + WLAN_DATA_MAXLEN + WLAN_CRC_LEN)) { |
a7cf7bae | 3444 | pr_debug("overlen frm: len=%zd\n", |
51e4896a | 3445 | skblen - sizeof(struct p80211_caphdr)); |
00b3ed16 GKH |
3446 | } |
3447 | ||
46800b22 | 3448 | skb = dev_alloc_skb(skblen); |
e2e77528 | 3449 | if (!skb) |
00b3ed16 | 3450 | return; |
00b3ed16 GKH |
3451 | |
3452 | /* only prepend the prism header if in the right mode */ | |
3453 | if ((wlandev->netdev->type == ARPHRD_IEEE80211_PRISM) && | |
cbec30c4 | 3454 | (hw->sniffhdr != 0)) { |
51e4896a | 3455 | struct p80211_caphdr *caphdr; |
00b3ed16 | 3456 | /* The NEW header format! */ |
51e4896a | 3457 | datap = skb_put(skb, sizeof(struct p80211_caphdr)); |
5d85fe34 | 3458 | caphdr = (struct p80211_caphdr *)datap; |
21dc0f89 MM |
3459 | |
3460 | caphdr->version = htonl(P80211CAPTURE_VERSION); | |
51e4896a | 3461 | caphdr->length = htonl(sizeof(struct p80211_caphdr)); |
21dc0f89 MM |
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 */ | |
00b3ed16 GKH |
3474 | } |
3475 | ||
631c8dec EH |
3476 | /* Copy the 802.11 header to the skb |
3477 | (ctl frames may be less than a full header) */ | |
00b3ed16 | 3478 | datap = skb_put(skb, hdrlen); |
21dc0f89 | 3479 | memcpy(datap, &(rxdesc->frame_control), hdrlen); |
00b3ed16 GKH |
3480 | |
3481 | /* If any, copy the data from the card to the skb */ | |
21dc0f89 | 3482 | if (datalen > 0) { |
00b3ed16 GKH |
3483 | datap = skb_put(skb, datalen); |
3484 | memcpy(datap, rxfrm->data, datalen); | |
3485 | ||
3486 | /* check for unencrypted stuff if WEP bit set. */ | |
21dc0f89 MM |
3487 | if (*(datap - hdrlen + 1) & 0x40) /* wep set */ |
3488 | if ((*(datap) == 0xaa) && (*(datap + 1) == 0xaa)) | |
631c8dec EH |
3489 | /* clear wep; it's the 802.2 header! */ |
3490 | *(datap - hdrlen + 1) &= 0xbf; | |
00b3ed16 GKH |
3491 | } |
3492 | ||
3493 | if (hw->sniff_fcs) { | |
3494 | /* Set the FCS */ | |
3495 | datap = skb_put(skb, WLAN_CRC_LEN); | |
21dc0f89 | 3496 | memset(datap, 0xff, WLAN_CRC_LEN); |
00b3ed16 GKH |
3497 | } |
3498 | ||
3499 | /* pass it back up */ | |
4e2cdf93 | 3500 | p80211netdev_rx(wlandev, skb); |
00b3ed16 GKH |
3501 | } |
3502 | ||
00b3ed16 GKH |
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 | ----------------------------------------------------------------*/ | |
c9573a8d | 3520 | static void hfa384x_usbin_info(struct wlandevice *wlandev, hfa384x_usbin_t *usbin) |
00b3ed16 | 3521 | { |
21dc0f89 | 3522 | usbin->infofrm.info.framelen = |
18c7f792 | 3523 | le16_to_cpu(usbin->infofrm.info.framelen); |
00b3ed16 | 3524 | prism2sta_ev_info(wlandev, &usbin->infofrm.info); |
00b3ed16 GKH |
3525 | } |
3526 | ||
00b3ed16 GKH |
3527 | /*---------------------------------------------------------------- |
3528 | * hfa384x_usbout_callback | |
3529 | * | |
3530 | * Callback for URBs on the BULKOUT endpoint. | |
3531 | * | |
3532 | * Arguments: | |
3533 | * urb ptr to the completed urb | |
3534 | * | |
3535 | * Returns: | |
3536 | * nothing | |
3537 | * | |
3538 | * Side effects: | |
3539 | * | |
3540 | * Call context: | |
3541 | * interrupt | |
3542 | ----------------------------------------------------------------*/ | |
00b3ed16 | 3543 | static void hfa384x_usbout_callback(struct urb *urb) |
00b3ed16 | 3544 | { |
c9573a8d | 3545 | struct wlandevice *wlandev = urb->context; |
00b3ed16 GKH |
3546 | |
3547 | #ifdef DEBUG_USB | |
3548 | dbprint_urb(urb); | |
3549 | #endif | |
3550 | ||
21dc0f89 | 3551 | if (wlandev && wlandev->netdev) { |
21dc0f89 | 3552 | switch (urb->status) { |
00b3ed16 | 3553 | case 0: |
6ba714bb | 3554 | prism2sta_ev_alloc(wlandev); |
00b3ed16 GKH |
3555 | break; |
3556 | ||
3557 | case -EPIPE: | |
21dc0f89 MM |
3558 | { |
3559 | hfa384x_t *hw = wlandev->priv; | |
4d525ef6 | 3560 | |
263b8bb9 | 3561 | netdev_warn(hw->wlandev->netdev, |
3f2d6564 SSA |
3562 | "%s tx pipe stalled: requesting reset\n", |
3563 | wlandev->netdev->name); | |
21dc0f89 MM |
3564 | if (!test_and_set_bit |
3565 | (WORK_TX_HALT, &hw->usb_flags)) | |
3566 | schedule_work(&hw->usb_work); | |
9630f6b9 | 3567 | wlandev->netdev->stats.tx_errors++; |
21dc0f89 MM |
3568 | break; |
3569 | } | |
00b3ed16 GKH |
3570 | |
3571 | case -EPROTO: | |
3572 | case -ETIMEDOUT: | |
3573 | case -EILSEQ: | |
21dc0f89 MM |
3574 | { |
3575 | hfa384x_t *hw = wlandev->priv; | |
3576 | ||
3577 | if (!test_and_set_bit | |
a3542e66 SSA |
3578 | (THROTTLE_TX, &hw->usb_flags) && |
3579 | !timer_pending(&hw->throttle)) { | |
21dc0f89 MM |
3580 | mod_timer(&hw->throttle, |
3581 | jiffies + THROTTLE_JIFFIES); | |
3582 | } | |
9630f6b9 | 3583 | wlandev->netdev->stats.tx_errors++; |
21dc0f89 MM |
3584 | netif_stop_queue(wlandev->netdev); |
3585 | break; | |
00b3ed16 | 3586 | } |
00b3ed16 GKH |
3587 | |
3588 | case -ENOENT: | |
3589 | case -ESHUTDOWN: | |
3590 | /* Ignorable errors */ | |
3591 | break; | |
3592 | ||
3593 | default: | |
263b8bb9 | 3594 | netdev_info(wlandev->netdev, "unknown urb->status=%d\n", |
3f2d6564 | 3595 | urb->status); |
9630f6b9 | 3596 | wlandev->netdev->stats.tx_errors++; |
00b3ed16 | 3597 | break; |
21dc0f89 | 3598 | } /* switch */ |
00b3ed16 | 3599 | } |
00b3ed16 GKH |
3600 | } |
3601 | ||
00b3ed16 GKH |
3602 | /*---------------------------------------------------------------- |
3603 | * hfa384x_ctlxout_callback | |
3604 | * | |
3605 | * Callback for control data on the BULKOUT endpoint. | |
3606 | * | |
3607 | * Arguments: | |
3608 | * urb ptr to the completed urb | |
3609 | * | |
3610 | * Returns: | |
3611 | * nothing | |
3612 | * | |
3613 | * Side effects: | |
3614 | * | |
3615 | * Call context: | |
3616 | * interrupt | |
3617 | ----------------------------------------------------------------*/ | |
00b3ed16 | 3618 | static void hfa384x_ctlxout_callback(struct urb *urb) |
00b3ed16 | 3619 | { |
21dc0f89 MM |
3620 | hfa384x_t *hw = urb->context; |
3621 | int delete_resptimer = 0; | |
3622 | int timer_ok = 1; | |
3623 | int run_queue = 0; | |
3624 | hfa384x_usbctlx_t *ctlx; | |
3625 | unsigned long flags; | |
00b3ed16 | 3626 | |
a7cf7bae | 3627 | pr_debug("urb->status=%d\n", urb->status); |
00b3ed16 GKH |
3628 | #ifdef DEBUG_USB |
3629 | dbprint_urb(urb); | |
3630 | #endif | |
21dc0f89 | 3631 | if ((urb->status == -ESHUTDOWN) || |
02e02048 | 3632 | (urb->status == -ENODEV) || !hw) |
89e6302c | 3633 | return; |
00b3ed16 GKH |
3634 | |
3635 | retry: | |
3636 | spin_lock_irqsave(&hw->ctlxq.lock, flags); | |
3637 | ||
3638 | /* | |
3639 | * Only one CTLX at a time on the "active" list, and | |
3640 | * none at all if we are unplugged. However, we can | |
3641 | * rely on the disconnect function to clean everything | |
3642 | * up if someone unplugged the adapter. | |
3643 | */ | |
21dc0f89 | 3644 | if (list_empty(&hw->ctlxq.active)) { |
00b3ed16 | 3645 | spin_unlock_irqrestore(&hw->ctlxq.lock, flags); |
89e6302c | 3646 | return; |
00b3ed16 GKH |
3647 | } |
3648 | ||
3649 | /* | |
3650 | * Having something on the "active" queue means | |
3651 | * that we have timers to worry about ... | |
3652 | */ | |
3653 | if (del_timer(&hw->reqtimer) == 0) { | |
3654 | if (hw->req_timer_done == 0) { | |
3655 | /* | |
3656 | * This timer was actually running while we | |
3657 | * were trying to delete it. Let it terminate | |
3658 | * gracefully instead. | |
3659 | */ | |
3660 | spin_unlock_irqrestore(&hw->ctlxq.lock, flags); | |
3661 | goto retry; | |
3662 | } | |
21dc0f89 | 3663 | } else { |
00b3ed16 GKH |
3664 | hw->req_timer_done = 1; |
3665 | } | |
3666 | ||
3667 | ctlx = get_active_ctlx(hw); | |
3668 | ||
21dc0f89 | 3669 | if (urb->status == 0) { |
00b3ed16 | 3670 | /* Request portion of a CTLX is successful */ |
21dc0f89 | 3671 | switch (ctlx->state) { |
00b3ed16 GKH |
3672 | case CTLX_REQ_SUBMITTED: |
3673 | /* This OUT-ACK received before IN */ | |
3674 | ctlx->state = CTLX_REQ_COMPLETE; | |
3675 | break; | |
3676 | ||
3677 | case CTLX_RESP_COMPLETE: | |
3678 | /* IN already received before this OUT-ACK, | |
3679 | * so this command must now be complete. | |
3680 | */ | |
3681 | ctlx->state = CTLX_COMPLETE; | |
3682 | unlocked_usbctlx_complete(hw, ctlx); | |
3683 | run_queue = 1; | |
3684 | break; | |
3685 | ||
3686 | default: | |
3687 | /* This is NOT a valid CTLX "success" state! */ | |
263b8bb9 | 3688 | netdev_err(hw->wlandev->netdev, |
3f2d6564 SSA |
3689 | "Illegal CTLX[%d] success state(%s, %d) in OUT URB\n", |
3690 | le16_to_cpu(ctlx->outbuf.type), | |
3691 | ctlxstr(ctlx->state), urb->status); | |
00b3ed16 | 3692 | break; |
21dc0f89 | 3693 | } /* switch */ |
00b3ed16 GKH |
3694 | } else { |
3695 | /* If the pipe has stalled then we need to reset it */ | |
21dc0f89 MM |
3696 | if ((urb->status == -EPIPE) && |
3697 | !test_and_set_bit(WORK_TX_HALT, &hw->usb_flags)) { | |
263b8bb9 | 3698 | netdev_warn(hw->wlandev->netdev, |
3f2d6564 SSA |
3699 | "%s tx pipe stalled: requesting reset\n", |
3700 | hw->wlandev->netdev->name); | |
00b3ed16 GKH |
3701 | schedule_work(&hw->usb_work); |
3702 | } | |
3703 | ||
3704 | /* If someone cancels the OUT URB then its status | |
3705 | * should be either -ECONNRESET or -ENOENT. | |
3706 | */ | |
3707 | ctlx->state = CTLX_REQ_FAILED; | |
3708 | unlocked_usbctlx_complete(hw, ctlx); | |
3709 | delete_resptimer = 1; | |
3710 | run_queue = 1; | |
3711 | } | |
3712 | ||
21dc0f89 | 3713 | delresp: |
00b3ed16 | 3714 | if (delete_resptimer) { |
46800b22 | 3715 | timer_ok = del_timer(&hw->resptimer); |
3f4b4e77 | 3716 | if (timer_ok != 0) |
00b3ed16 | 3717 | hw->resp_timer_done = 1; |
00b3ed16 GKH |
3718 | } |
3719 | ||
3720 | spin_unlock_irqrestore(&hw->ctlxq.lock, flags); | |
3721 | ||
21dc0f89 | 3722 | if (!timer_ok && (hw->resp_timer_done == 0)) { |
00b3ed16 GKH |
3723 | spin_lock_irqsave(&hw->ctlxq.lock, flags); |
3724 | goto delresp; | |
3725 | } | |
3726 | ||
3727 | if (run_queue) | |
3728 | hfa384x_usbctlxq_run(hw); | |
00b3ed16 GKH |
3729 | } |
3730 | ||
00b3ed16 GKH |
3731 | /*---------------------------------------------------------------- |
3732 | * hfa384x_usbctlx_reqtimerfn | |
3733 | * | |
3734 | * Timer response function for CTLX request timeouts. If this | |
3735 | * function is called, it means that the callback for the OUT | |
3736 | * URB containing a Prism2.x XXX_Request was never called. | |
3737 | * | |
3738 | * Arguments: | |
3739 | * data a ptr to the hfa384x_t | |
3740 | * | |
3741 | * Returns: | |
3742 | * nothing | |
3743 | * | |
3744 | * Side effects: | |
3745 | * | |
3746 | * Call context: | |
3747 | * interrupt | |
3748 | ----------------------------------------------------------------*/ | |
21dc0f89 | 3749 | static void hfa384x_usbctlx_reqtimerfn(unsigned long data) |
00b3ed16 | 3750 | { |
5d85fe34 | 3751 | hfa384x_t *hw = (hfa384x_t *)data; |
21dc0f89 | 3752 | unsigned long flags; |
00b3ed16 GKH |
3753 | |
3754 | spin_lock_irqsave(&hw->ctlxq.lock, flags); | |
3755 | ||
3756 | hw->req_timer_done = 1; | |
3757 | ||
3758 | /* Removing the hardware automatically empties | |
3759 | * the active list ... | |
3760 | */ | |
21dc0f89 | 3761 | if (!list_empty(&hw->ctlxq.active)) { |
00b3ed16 GKH |
3762 | /* |
3763 | * We must ensure that our URB is removed from | |
3764 | * the system, if it hasn't already expired. | |
3765 | */ | |
3766 | hw->ctlx_urb.transfer_flags |= URB_ASYNC_UNLINK; | |
21dc0f89 | 3767 | if (usb_unlink_urb(&hw->ctlx_urb) == -EINPROGRESS) { |
00b3ed16 GKH |
3768 | hfa384x_usbctlx_t *ctlx = get_active_ctlx(hw); |
3769 | ||
3770 | ctlx->state = CTLX_REQ_FAILED; | |
3771 | ||
3772 | /* This URB was active, but has now been | |
3773 | * cancelled. It will now have a status of | |
3774 | * -ECONNRESET in the callback function. | |
3775 | * | |
3776 | * We are cancelling this CTLX, so we're | |
3777 | * not going to need to wait for a response. | |
3778 | * The URB's callback function will check | |
3779 | * that this timer is truly dead. | |
3780 | */ | |
3781 | if (del_timer(&hw->resptimer) != 0) | |
3782 | hw->resp_timer_done = 1; | |
3783 | } | |
3784 | } | |
3785 | ||
3786 | spin_unlock_irqrestore(&hw->ctlxq.lock, flags); | |
00b3ed16 GKH |
3787 | } |
3788 | ||
00b3ed16 GKH |
3789 | /*---------------------------------------------------------------- |
3790 | * hfa384x_usbctlx_resptimerfn | |
3791 | * | |
3792 | * Timer response function for CTLX response timeouts. If this | |
3793 | * function is called, it means that the callback for the IN | |
3794 | * URB containing a Prism2.x XXX_Response was never called. | |
3795 | * | |
3796 | * Arguments: | |
3797 | * data a ptr to the hfa384x_t | |
3798 | * | |
3799 | * Returns: | |
3800 | * nothing | |
3801 | * | |
3802 | * Side effects: | |
3803 | * | |
3804 | * Call context: | |
3805 | * interrupt | |
3806 | ----------------------------------------------------------------*/ | |
21dc0f89 | 3807 | static void hfa384x_usbctlx_resptimerfn(unsigned long data) |
00b3ed16 | 3808 | { |
5d85fe34 | 3809 | hfa384x_t *hw = (hfa384x_t *)data; |
21dc0f89 | 3810 | unsigned long flags; |
00b3ed16 | 3811 | |
00b3ed16 GKH |
3812 | spin_lock_irqsave(&hw->ctlxq.lock, flags); |
3813 | ||
3814 | hw->resp_timer_done = 1; | |
3815 | ||
3816 | /* The active list will be empty if the | |
3817 | * adapter has been unplugged ... | |
3818 | */ | |
21dc0f89 | 3819 | if (!list_empty(&hw->ctlxq.active)) { |
00b3ed16 GKH |
3820 | hfa384x_usbctlx_t *ctlx = get_active_ctlx(hw); |
3821 | ||
21dc0f89 | 3822 | if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0) { |
00b3ed16 GKH |
3823 | spin_unlock_irqrestore(&hw->ctlxq.lock, flags); |
3824 | hfa384x_usbctlxq_run(hw); | |
3f514258 | 3825 | return; |
00b3ed16 GKH |
3826 | } |
3827 | } | |
00b3ed16 | 3828 | spin_unlock_irqrestore(&hw->ctlxq.lock, flags); |
00b3ed16 GKH |
3829 | } |
3830 | ||
3831 | /*---------------------------------------------------------------- | |
3832 | * hfa384x_usb_throttlefn | |
3833 | * | |
3834 | * | |
3835 | * Arguments: | |
3836 | * data ptr to hw | |
3837 | * | |
3838 | * Returns: | |
3839 | * Nothing | |
3840 | * | |
3841 | * Side effects: | |
3842 | * | |
3843 | * Call context: | |
3844 | * Interrupt | |
3845 | ----------------------------------------------------------------*/ | |
21dc0f89 | 3846 | static void hfa384x_usb_throttlefn(unsigned long data) |
00b3ed16 | 3847 | { |
5d85fe34 | 3848 | hfa384x_t *hw = (hfa384x_t *)data; |
21dc0f89 | 3849 | unsigned long flags; |
00b3ed16 | 3850 | |
00b3ed16 GKH |
3851 | spin_lock_irqsave(&hw->ctlxq.lock, flags); |
3852 | ||
3853 | /* | |
3854 | * We need to check BOTH the RX and the TX throttle controls, | |
3855 | * so we use the bitwise OR instead of the logical OR. | |
3856 | */ | |
a7cf7bae | 3857 | pr_debug("flags=0x%lx\n", hw->usb_flags); |
21dc0f89 MM |
3858 | if (!hw->wlandev->hwremoved && |
3859 | ((test_and_clear_bit(THROTTLE_RX, &hw->usb_flags) && | |
6c37e1f9 | 3860 | !test_and_set_bit(WORK_RX_RESUME, &hw->usb_flags)) | |
21dc0f89 MM |
3861 | (test_and_clear_bit(THROTTLE_TX, &hw->usb_flags) && |
3862 | !test_and_set_bit(WORK_TX_RESUME, &hw->usb_flags)) | |
3863 | )) { | |
00b3ed16 GKH |
3864 | schedule_work(&hw->usb_work); |
3865 | } | |
3866 | ||
3867 | spin_unlock_irqrestore(&hw->ctlxq.lock, flags); | |
00b3ed16 GKH |
3868 | } |
3869 | ||
00b3ed16 GKH |
3870 | /*---------------------------------------------------------------- |
3871 | * hfa384x_usbctlx_submit | |
3872 | * | |
3873 | * Called from the doxxx functions to submit a CTLX to the queue | |
3874 | * | |
3875 | * Arguments: | |
3876 | * hw ptr to the hw struct | |
3877 | * ctlx ctlx structure to enqueue | |
3878 | * | |
3879 | * Returns: | |
3880 | * -ENODEV if the adapter is unplugged | |
3881 | * 0 | |
3882 | * | |
3883 | * Side effects: | |
3884 | * | |
3885 | * Call context: | |
3886 | * process or interrupt | |
3887 | ----------------------------------------------------------------*/ | |
297f06ce | 3888 | static int hfa384x_usbctlx_submit(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx) |
00b3ed16 GKH |
3889 | { |
3890 | unsigned long flags; | |
00b3ed16 | 3891 | |
00b3ed16 GKH |
3892 | spin_lock_irqsave(&hw->ctlxq.lock, flags); |
3893 | ||
3894 | if (hw->wlandev->hwremoved) { | |
3895 | spin_unlock_irqrestore(&hw->ctlxq.lock, flags); | |
675be12f | 3896 | return -ENODEV; |
00b3ed16 GKH |
3897 | } |
3898 | ||
675be12f DN |
3899 | ctlx->state = CTLX_PENDING; |
3900 | list_add_tail(&ctlx->list, &hw->ctlxq.pending); | |
3901 | spin_unlock_irqrestore(&hw->ctlxq.lock, flags); | |
3902 | hfa384x_usbctlxq_run(hw); | |
3903 | ||
3904 | return 0; | |
00b3ed16 GKH |
3905 | } |
3906 | ||
00b3ed16 GKH |
3907 | /*---------------------------------------------------------------- |
3908 | * hfa384x_isgood_pdrcore | |
3909 | * | |
3910 | * Quick check of PDR codes. | |
3911 | * | |
3912 | * Arguments: | |
3913 | * pdrcode PDR code number (host order) | |
3914 | * | |
3915 | * Returns: | |
3916 | * zero not good. | |
3917 | * one is good. | |
3918 | * | |
3919 | * Side effects: | |
3920 | * | |
3921 | * Call context: | |
3922 | ----------------------------------------------------------------*/ | |
21dc0f89 | 3923 | static int hfa384x_isgood_pdrcode(u16 pdrcode) |
00b3ed16 | 3924 | { |
21dc0f89 | 3925 | switch (pdrcode) { |
00b3ed16 GKH |
3926 | case HFA384x_PDR_END_OF_PDA: |
3927 | case HFA384x_PDR_PCB_PARTNUM: | |
3928 | case HFA384x_PDR_PDAVER: | |
3929 | case HFA384x_PDR_NIC_SERIAL: | |
3930 | case HFA384x_PDR_MKK_MEASUREMENTS: | |
3931 | case HFA384x_PDR_NIC_RAMSIZE: | |
3932 | case HFA384x_PDR_MFISUPRANGE: | |
3933 | case HFA384x_PDR_CFISUPRANGE: | |
3934 | case HFA384x_PDR_NICID: | |
3935 | case HFA384x_PDR_MAC_ADDRESS: | |
3936 | case HFA384x_PDR_REGDOMAIN: | |
3937 | case HFA384x_PDR_ALLOWED_CHANNEL: | |
3938 | case HFA384x_PDR_DEFAULT_CHANNEL: | |
3939 | case HFA384x_PDR_TEMPTYPE: | |
3940 | case HFA384x_PDR_IFR_SETTING: | |
3941 | case HFA384x_PDR_RFR_SETTING: | |
3942 | case HFA384x_PDR_HFA3861_BASELINE: | |
3943 | case HFA384x_PDR_HFA3861_SHADOW: | |
3944 | case HFA384x_PDR_HFA3861_IFRF: | |
3945 | case HFA384x_PDR_HFA3861_CHCALSP: | |
3946 | case HFA384x_PDR_HFA3861_CHCALI: | |
3947 | case HFA384x_PDR_3842_NIC_CONFIG: | |
3948 | case HFA384x_PDR_USB_ID: | |
3949 | case HFA384x_PDR_PCI_ID: | |
3950 | case HFA384x_PDR_PCI_IFCONF: | |
3951 | case HFA384x_PDR_PCI_PMCONF: | |
3952 | case HFA384x_PDR_RFENRGY: | |
3953 | case HFA384x_PDR_HFA3861_MANF_TESTSP: | |
3954 | case HFA384x_PDR_HFA3861_MANF_TESTI: | |
3955 | /* code is OK */ | |
3956 | return 1; | |
00b3ed16 | 3957 | default: |
21dc0f89 | 3958 | if (pdrcode < 0x1000) { |
00b3ed16 | 3959 | /* code is OK, but we don't know exactly what it is */ |
a2120136 SSA |
3960 | pr_debug("Encountered unknown PDR#=0x%04x, assuming it's ok.\n", |
3961 | pdrcode); | |
00b3ed16 | 3962 | return 1; |
00b3ed16 | 3963 | } |
81980c16 | 3964 | break; |
00b3ed16 | 3965 | } |
81980c16 EB |
3966 | /* bad code */ |
3967 | pr_debug("Encountered unknown PDR#=0x%04x, (>=0x1000), assuming it's bad.\n", | |
3968 | pdrcode); | |
3969 | return 0; | |
00b3ed16 | 3970 | } |