aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorPontus Fuchs <pontus.fuchs@gmail.com>2012-10-23 14:33:57 -0400
committerJohn W. Linville <linville@tuxdriver.com>2012-10-29 15:29:05 -0400
commitb7d572e1871df06a96a1c9591c71c5494ff6b624 (patch)
treec8c26cb954203540be57ee149b4b4f5f6c801ab6 /drivers
parent8ff5dc92fe8a50c8c86a8c5971edc78a2e422fb5 (diff)
ar5523: Add new driver
This driver is for the AR5523 chipset from Atheros. It was created in 2007 by Christoph Hellwig but it was never finished. I found it a couple of months ago and after some polishing it's working pretty fine. The driver was written with the FreeBSD driver (uath) as reference, which was written with the reverse-engineered windows driver as reference, hence the feature set is very limited. Station mode only, no HW crypto offload. Signed-off-by: Pontus Fuchs <pontus.fuchs@gmail.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/net/wireless/ath/Kconfig1
-rw-r--r--drivers/net/wireless/ath/Makefile1
-rw-r--r--drivers/net/wireless/ath/ar5523/Kconfig7
-rw-r--r--drivers/net/wireless/ath/ar5523/Makefile1
-rw-r--r--drivers/net/wireless/ath/ar5523/ar5523.c1806
-rw-r--r--drivers/net/wireless/ath/ar5523/ar5523.h152
-rw-r--r--drivers/net/wireless/ath/ar5523/ar5523_hw.h431
7 files changed, 2399 insertions, 0 deletions
diff --git a/drivers/net/wireless/ath/Kconfig b/drivers/net/wireless/ath/Kconfig
index 09602241901b..c25dcf192fec 100644
--- a/drivers/net/wireless/ath/Kconfig
+++ b/drivers/net/wireless/ath/Kconfig
@@ -26,5 +26,6 @@ source "drivers/net/wireless/ath/ath5k/Kconfig"
26source "drivers/net/wireless/ath/ath9k/Kconfig" 26source "drivers/net/wireless/ath/ath9k/Kconfig"
27source "drivers/net/wireless/ath/carl9170/Kconfig" 27source "drivers/net/wireless/ath/carl9170/Kconfig"
28source "drivers/net/wireless/ath/ath6kl/Kconfig" 28source "drivers/net/wireless/ath/ath6kl/Kconfig"
29source "drivers/net/wireless/ath/ar5523/Kconfig"
29 30
30endif 31endif
diff --git a/drivers/net/wireless/ath/Makefile b/drivers/net/wireless/ath/Makefile
index d716b748e574..1e18621326dc 100644
--- a/drivers/net/wireless/ath/Makefile
+++ b/drivers/net/wireless/ath/Makefile
@@ -2,6 +2,7 @@ obj-$(CONFIG_ATH5K) += ath5k/
2obj-$(CONFIG_ATH9K_HW) += ath9k/ 2obj-$(CONFIG_ATH9K_HW) += ath9k/
3obj-$(CONFIG_CARL9170) += carl9170/ 3obj-$(CONFIG_CARL9170) += carl9170/
4obj-$(CONFIG_ATH6KL) += ath6kl/ 4obj-$(CONFIG_ATH6KL) += ath6kl/
5obj-$(CONFIG_AR5523) += ar5523/
5 6
6obj-$(CONFIG_ATH_COMMON) += ath.o 7obj-$(CONFIG_ATH_COMMON) += ath.o
7 8
diff --git a/drivers/net/wireless/ath/ar5523/Kconfig b/drivers/net/wireless/ath/ar5523/Kconfig
new file mode 100644
index 000000000000..11d99ee8de51
--- /dev/null
+++ b/drivers/net/wireless/ath/ar5523/Kconfig
@@ -0,0 +1,7 @@
1config AR5523
2 tristate "Atheros AR5523 wireless driver support"
3 depends on MAC80211 && USB
4 select FW_LOADER
5 ---help---
6 This module add support for AR5523 based USB dongles such as D-Link
7 DWL-G132, Netgear WPN111 and many more.
diff --git a/drivers/net/wireless/ath/ar5523/Makefile b/drivers/net/wireless/ath/ar5523/Makefile
new file mode 100644
index 000000000000..ebf7f3bf0a33
--- /dev/null
+++ b/drivers/net/wireless/ath/ar5523/Makefile
@@ -0,0 +1 @@
obj-$(CONFIG_AR5523) := ar5523.o
diff --git a/drivers/net/wireless/ath/ar5523/ar5523.c b/drivers/net/wireless/ath/ar5523/ar5523.c
new file mode 100644
index 000000000000..f782b6e502bf
--- /dev/null
+++ b/drivers/net/wireless/ath/ar5523/ar5523.c
@@ -0,0 +1,1806 @@
1/*
2 * Copyright (c) 2006 Damien Bergamini <damien.bergamini@free.fr>
3 * Copyright (c) 2006 Sam Leffler, Errno Consulting
4 * Copyright (c) 2007 Christoph Hellwig <hch@lst.de>
5 * Copyright (c) 2008-2009 Weongyo Jeong <weongyo@freebsd.org>
6 * Copyright (c) 2012 Pontus Fuchs <pontus.fuchs@gmail.com>
7 *
8 * Permission to use, copy, modify, and/or distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 */
20
21/*
22 * This driver is based on the uath driver written by Damien Bergamini for
23 * OpenBSD, who did black-box analysis of the Windows binary driver to find
24 * out how the hardware works. It contains a lot magic numbers because of
25 * that and only has minimal functionality.
26 */
27#include <linux/compiler.h>
28#include <linux/init.h>
29#include <linux/kernel.h>
30#include <linux/module.h>
31#include <linux/list.h>
32#include <linux/completion.h>
33#include <linux/firmware.h>
34#include <linux/skbuff.h>
35#include <linux/usb.h>
36#include <net/mac80211.h>
37
38#include "ar5523.h"
39#include "ar5523_hw.h"
40
41/*
42 * Various supported device vendors/products.
43 * UB51: AR5005UG 802.11b/g, UB52: AR5005UX 802.11a/b/g
44 */
45
46static int ar5523_submit_rx_cmd(struct ar5523 *ar);
47static void ar5523_data_tx_pkt_put(struct ar5523 *ar);
48
49static void ar5523_read_reply(struct ar5523 *ar, struct ar5523_cmd_hdr *hdr,
50 struct ar5523_tx_cmd *cmd)
51{
52 int dlen, olen;
53 u32 *rp;
54
55 dlen = hdr->len - sizeof(*hdr);
56
57 if (dlen < 0) {
58 WARN_ON(1);
59 goto out;
60 }
61
62 ar5523_dbg(ar, "Code = %d len = %d\n", hdr->code & 0xff, dlen);
63
64 rp = (u32 *)(hdr + 1);
65 if (dlen >= sizeof(u32)) {
66 olen = be32_to_cpu(rp[0]);
67 dlen -= sizeof(u32);
68 if (olen == 0) {
69 /* convention is 0 =>'s one word */
70 olen = sizeof(u32);
71 }
72 } else
73 olen = 0;
74
75 if (cmd->odata) {
76 if (cmd->olen < olen) {
77 ar5523_err(ar, "olen to small %d < %d\n",
78 cmd->olen, olen);
79 cmd->olen = 0;
80 cmd->res = -EOVERFLOW;
81 } else {
82 cmd->olen = olen;
83 memcpy(cmd->odata, &rp[1], olen);
84 cmd->res = 0;
85 }
86 }
87
88out:
89 complete(&cmd->done);
90}
91
92static void ar5523_cmd_rx_cb(struct urb *urb)
93{
94 struct ar5523 *ar = urb->context;
95 struct ar5523_tx_cmd *cmd = &ar->tx_cmd;
96 struct ar5523_cmd_hdr *hdr = ar->rx_cmd_buf;
97 int dlen;
98
99 if (urb->status) {
100 if (urb->status != -ESHUTDOWN)
101 ar5523_err(ar, "RX USB error %d.\n", urb->status);
102 goto skip;
103 }
104
105 if (urb->actual_length < sizeof(struct ar5523_cmd_hdr)) {
106 ar5523_err(ar, "RX USB to short.\n");
107 goto skip;
108 }
109
110 ar5523_dbg(ar, "%s code %02x priv %d\n", __func__,
111 be32_to_cpu(hdr->code) & 0xff, hdr->priv);
112
113 hdr->code = be32_to_cpu(hdr->code);
114 hdr->len = be32_to_cpu(hdr->len);
115
116 switch (hdr->code & 0xff) {
117 default:
118 /* reply to a read command */
119 if (hdr->priv != AR5523_CMD_ID) {
120 ar5523_err(ar, "Unexpected command id: %02x\n",
121 hdr->code & 0xff);
122 goto skip;
123 }
124 ar5523_read_reply(ar, hdr, cmd);
125 break;
126
127 case WDCMSG_DEVICE_AVAIL:
128 ar5523_dbg(ar, "WDCMSG_DEVICE_AVAIL\n");
129 cmd->res = 0;
130 cmd->olen = 0;
131 complete(&cmd->done);
132 break;
133
134 case WDCMSG_SEND_COMPLETE:
135 ar5523_dbg(ar, "WDCMSG_SEND_COMPLETE: %d pending\n",
136 atomic_read(&ar->tx_nr_pending));
137 if (!test_bit(AR5523_HW_UP, &ar->flags))
138 ar5523_dbg(ar, "Unexpected WDCMSG_SEND_COMPLETE\n");
139 else {
140 mod_timer(&ar->tx_wd_timer,
141 jiffies + AR5523_TX_WD_TIMEOUT);
142 ar5523_data_tx_pkt_put(ar);
143
144 }
145 break;
146
147 case WDCMSG_TARGET_START:
148 /* This command returns a bogus id so it needs special
149 handling */
150 dlen = hdr->len - sizeof(*hdr);
151 if (dlen != (int)sizeof(u32)) {
152 ar5523_err(ar, "Invalid reply to WDCMSG_TARGET_START");
153 return;
154 }
155 memcpy(cmd->odata, hdr + 1, sizeof(u32));
156 cmd->olen = sizeof(u32);
157 cmd->res = 0;
158 complete(&cmd->done);
159 break;
160
161 case WDCMSG_STATS_UPDATE:
162 ar5523_dbg(ar, "WDCMSG_STATS_UPDATE\n");
163 break;
164 }
165
166skip:
167 ar5523_submit_rx_cmd(ar);
168}
169
170static int ar5523_alloc_rx_cmd(struct ar5523 *ar)
171{
172 ar->rx_cmd_urb = usb_alloc_urb(0, GFP_KERNEL);
173 if (!ar->rx_cmd_urb)
174 return -ENOMEM;
175
176 ar->rx_cmd_buf = usb_alloc_coherent(ar->dev, AR5523_MAX_RXCMDSZ,
177 GFP_KERNEL,
178 &ar->rx_cmd_urb->transfer_dma);
179 if (!ar->rx_cmd_buf) {
180 usb_free_urb(ar->rx_cmd_urb);
181 return -ENOMEM;
182 }
183 return 0;
184}
185
186static void ar5523_cancel_rx_cmd(struct ar5523 *ar)
187{
188 usb_kill_urb(ar->rx_cmd_urb);
189}
190
191static void ar5523_free_rx_cmd(struct ar5523 *ar)
192{
193 usb_free_coherent(ar->dev, AR5523_MAX_RXCMDSZ,
194 ar->rx_cmd_buf, ar->rx_cmd_urb->transfer_dma);
195 usb_free_urb(ar->rx_cmd_urb);
196}
197
198static int ar5523_submit_rx_cmd(struct ar5523 *ar)
199{
200 int error;
201
202 usb_fill_bulk_urb(ar->rx_cmd_urb, ar->dev,
203 ar5523_cmd_rx_pipe(ar->dev), ar->rx_cmd_buf,
204 AR5523_MAX_RXCMDSZ, ar5523_cmd_rx_cb, ar);
205 ar->rx_cmd_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
206
207 error = usb_submit_urb(ar->rx_cmd_urb, GFP_ATOMIC);
208 if (error) {
209 if (error != -ENODEV)
210 ar5523_err(ar, "error %d when submitting rx urb\n",
211 error);
212 return error;
213 }
214 return 0;
215}
216
217/*
218 * Command submitted cb
219 */
220static void ar5523_cmd_tx_cb(struct urb *urb)
221{
222 struct ar5523_tx_cmd *cmd = urb->context;
223 struct ar5523 *ar = cmd->ar;
224
225 if (urb->status) {
226 ar5523_err(ar, "Failed to TX command. Status = %d\n",
227 urb->status);
228 cmd->res = urb->status;
229 complete(&cmd->done);
230 return;
231 }
232
233 if (!(cmd->flags & AR5523_CMD_FLAG_READ)) {
234 cmd->res = 0;
235 complete(&cmd->done);
236 }
237}
238
239static int ar5523_cmd(struct ar5523 *ar, u32 code, const void *idata,
240 int ilen, void *odata, int olen, int flags)
241{
242 struct ar5523_cmd_hdr *hdr;
243 struct ar5523_tx_cmd *cmd = &ar->tx_cmd;
244 int xferlen, error;
245
246 /* always bulk-out a multiple of 4 bytes */
247 xferlen = (sizeof(struct ar5523_cmd_hdr) + ilen + 3) & ~3;
248
249 hdr = (struct ar5523_cmd_hdr *)cmd->buf_tx;
250 memset(hdr, 0, sizeof(struct ar5523_cmd_hdr));
251 hdr->len = cpu_to_be32(xferlen);
252 hdr->code = cpu_to_be32(code);
253 hdr->priv = AR5523_CMD_ID;
254
255 if (flags & AR5523_CMD_FLAG_MAGIC)
256 hdr->magic = cpu_to_be32(1 << 24);
257 memcpy(hdr + 1, idata, ilen);
258
259 cmd->odata = odata;
260 cmd->olen = olen;
261 cmd->flags = flags;
262
263 ar5523_dbg(ar, "do cmd %02x\n", code);
264
265 usb_fill_bulk_urb(cmd->urb_tx, ar->dev, ar5523_cmd_tx_pipe(ar->dev),
266 cmd->buf_tx, xferlen, ar5523_cmd_tx_cb, cmd);
267 cmd->urb_tx->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
268
269 error = usb_submit_urb(cmd->urb_tx, GFP_KERNEL);
270 if (error) {
271 ar5523_err(ar, "could not send command 0x%x, error=%d\n",
272 code, error);
273 return error;
274 }
275
276 if (!wait_for_completion_timeout(&cmd->done, 2 * HZ)) {
277 cmd->odata = NULL;
278 ar5523_err(ar, "timeout waiting for command %02x reply\n",
279 code);
280 cmd->res = -ETIMEDOUT;
281 }
282 return cmd->res;
283}
284
285static int ar5523_cmd_write(struct ar5523 *ar, u32 code, const void *data,
286 int len, int flags)
287{
288 flags &= ~AR5523_CMD_FLAG_READ;
289 return ar5523_cmd(ar, code, data, len, NULL, 0, flags);
290}
291
292static int ar5523_cmd_read(struct ar5523 *ar, u32 code, const void *idata,
293 int ilen, void *odata, int olen, int flags)
294{
295 flags |= AR5523_CMD_FLAG_READ;
296 return ar5523_cmd(ar, code, idata, ilen, odata, olen, flags);
297}
298
299static int ar5523_config(struct ar5523 *ar, u32 reg, u32 val)
300{
301 struct ar5523_write_mac write;
302 int error;
303
304 write.reg = cpu_to_be32(reg);
305 write.len = cpu_to_be32(0); /* 0 = single write */
306 *(u32 *)write.data = cpu_to_be32(val);
307
308 error = ar5523_cmd_write(ar, WDCMSG_TARGET_SET_CONFIG, &write,
309 3 * sizeof(u32), 0);
310 if (error != 0)
311 ar5523_err(ar, "could not write register 0x%02x\n", reg);
312 return error;
313}
314
315static int ar5523_config_multi(struct ar5523 *ar, u32 reg, const void *data,
316 int len)
317{
318 struct ar5523_write_mac write;
319 int error;
320
321 write.reg = cpu_to_be32(reg);
322 write.len = cpu_to_be32(len);
323 memcpy(write.data, data, len);
324
325 /* properly handle the case where len is zero (reset) */
326 error = ar5523_cmd_write(ar, WDCMSG_TARGET_SET_CONFIG, &write,
327 (len == 0) ? sizeof(u32) : 2 * sizeof(u32) + len, 0);
328 if (error != 0)
329 ar5523_err(ar, "could not write %d bytes to register 0x%02x\n",
330 len, reg);
331 return error;
332}
333
334static int ar5523_get_status(struct ar5523 *ar, u32 which, void *odata,
335 int olen)
336{
337 int error;
338
339 which = cpu_to_be32(which);
340 error = ar5523_cmd_read(ar, WDCMSG_TARGET_GET_STATUS,
341 &which, sizeof(which), odata, olen, AR5523_CMD_FLAG_MAGIC);
342 if (error != 0)
343 ar5523_err(ar, "could not read EEPROM offset 0x%02x\n",
344 be32_to_cpu(which));
345 return error;
346}
347
348static int ar5523_get_capability(struct ar5523 *ar, u32 cap, u32 *val)
349{
350 int error;
351
352 cap = cpu_to_be32(cap);
353 error = ar5523_cmd_read(ar, WDCMSG_TARGET_GET_CAPABILITY,
354 &cap, sizeof(cap), val, sizeof(u32), AR5523_CMD_FLAG_MAGIC);
355 if (error != 0) {
356 ar5523_err(ar, "could not read capability %u\n",
357 be32_to_cpu(cap));
358 return error;
359 }
360 *val = be32_to_cpu(*val);
361 return error;
362}
363
364static int ar5523_get_devcap(struct ar5523 *ar)
365{
366#define GETCAP(x) do { \
367 error = ar5523_get_capability(ar, x, &cap); \
368 if (error != 0) \
369 return error; \
370 ar5523_info(ar, "Cap: " \
371 "%s=0x%08x\n", #x, cap); \
372} while (0)
373 int error;
374 u32 cap;
375
376 /* collect device capabilities */
377 GETCAP(CAP_TARGET_VERSION);
378 GETCAP(CAP_TARGET_REVISION);
379 GETCAP(CAP_MAC_VERSION);
380 GETCAP(CAP_MAC_REVISION);
381 GETCAP(CAP_PHY_REVISION);
382 GETCAP(CAP_ANALOG_5GHz_REVISION);
383 GETCAP(CAP_ANALOG_2GHz_REVISION);
384
385 GETCAP(CAP_REG_DOMAIN);
386 GETCAP(CAP_REG_CAP_BITS);
387 GETCAP(CAP_WIRELESS_MODES);
388 GETCAP(CAP_CHAN_SPREAD_SUPPORT);
389 GETCAP(CAP_COMPRESS_SUPPORT);
390 GETCAP(CAP_BURST_SUPPORT);
391 GETCAP(CAP_FAST_FRAMES_SUPPORT);
392 GETCAP(CAP_CHAP_TUNING_SUPPORT);
393 GETCAP(CAP_TURBOG_SUPPORT);
394 GETCAP(CAP_TURBO_PRIME_SUPPORT);
395 GETCAP(CAP_DEVICE_TYPE);
396 GETCAP(CAP_WME_SUPPORT);
397 GETCAP(CAP_TOTAL_QUEUES);
398 GETCAP(CAP_CONNECTION_ID_MAX);
399
400 GETCAP(CAP_LOW_5GHZ_CHAN);
401 GETCAP(CAP_HIGH_5GHZ_CHAN);
402 GETCAP(CAP_LOW_2GHZ_CHAN);
403 GETCAP(CAP_HIGH_2GHZ_CHAN);
404 GETCAP(CAP_TWICE_ANTENNAGAIN_5G);
405 GETCAP(CAP_TWICE_ANTENNAGAIN_2G);
406
407 GETCAP(CAP_CIPHER_AES_CCM);
408 GETCAP(CAP_CIPHER_TKIP);
409 GETCAP(CAP_MIC_TKIP);
410 return 0;
411}
412
413static int ar5523_set_ledsteady(struct ar5523 *ar, int lednum, int ledmode)
414{
415 struct ar5523_cmd_ledsteady led;
416
417 led.lednum = cpu_to_be32(lednum);
418 led.ledmode = cpu_to_be32(ledmode);
419
420 ar5523_dbg(ar, "set %s led %s (steady)\n",
421 (lednum == UATH_LED_LINK) ? "link" : "activity",
422 ledmode ? "on" : "off");
423 return ar5523_cmd_write(ar, WDCMSG_SET_LED_STEADY, &led, sizeof(led),
424 0);
425}
426
427static int ar5523_set_rxfilter(struct ar5523 *ar, u32 bits, u32 op)
428{
429 struct ar5523_cmd_rx_filter rxfilter;
430
431 rxfilter.bits = cpu_to_be32(bits);
432 rxfilter.op = cpu_to_be32(op);
433
434 ar5523_dbg(ar, "setting Rx filter=0x%x flags=0x%x\n", bits, op);
435 return ar5523_cmd_write(ar, WDCMSG_RX_FILTER, &rxfilter,
436 sizeof(rxfilter), 0);
437}
438
439static int ar5523_reset_tx_queues(struct ar5523 *ar)
440{
441 __be32 qid = cpu_to_be32(0);
442
443 ar5523_dbg(ar, "resetting Tx queue\n");
444 return ar5523_cmd_write(ar, WDCMSG_RELEASE_TX_QUEUE,
445 &qid, sizeof(qid), 0);
446}
447
448static int ar5523_set_chan(struct ar5523 *ar)
449{
450 struct ieee80211_conf *conf = &ar->hw->conf;
451
452 struct ar5523_cmd_reset reset;
453
454 memset(&reset, 0, sizeof(reset));
455 reset.flags |= cpu_to_be32(UATH_CHAN_2GHZ);
456 reset.flags |= cpu_to_be32(UATH_CHAN_OFDM);
457 reset.freq = cpu_to_be32(conf->channel->center_freq);
458 reset.maxrdpower = cpu_to_be32(50); /* XXX */
459 reset.channelchange = cpu_to_be32(1);
460 reset.keeprccontent = cpu_to_be32(0);
461
462 ar5523_dbg(ar, "set chan flags 0x%x freq %d\n",
463 be32_to_cpu(reset.flags),
464 conf->channel->center_freq);
465 return ar5523_cmd_write(ar, WDCMSG_RESET, &reset, sizeof(reset), 0);
466}
467
468static int ar5523_queue_init(struct ar5523 *ar)
469{
470 struct ar5523_cmd_txq_setup qinfo;
471
472 ar5523_dbg(ar, "setting up Tx queue\n");
473 qinfo.qid = cpu_to_be32(0);
474 qinfo.len = cpu_to_be32(sizeof(qinfo.attr));
475 qinfo.attr.priority = cpu_to_be32(0); /* XXX */
476 qinfo.attr.aifs = cpu_to_be32(3);
477 qinfo.attr.logcwmin = cpu_to_be32(4);
478 qinfo.attr.logcwmax = cpu_to_be32(10);
479 qinfo.attr.bursttime = cpu_to_be32(0);
480 qinfo.attr.mode = cpu_to_be32(0);
481 qinfo.attr.qflags = cpu_to_be32(1); /* XXX? */
482 return ar5523_cmd_write(ar, WDCMSG_SETUP_TX_QUEUE, &qinfo,
483 sizeof(qinfo), 0);
484}
485
486static int ar5523_switch_chan(struct ar5523 *ar)
487{
488 int error;
489
490 error = ar5523_set_chan(ar);
491 if (error) {
492 ar5523_err(ar, "could not set chan, error %d\n", error);
493 goto out_err;
494 }
495
496 /* reset Tx rings */
497 error = ar5523_reset_tx_queues(ar);
498 if (error) {
499 ar5523_err(ar, "could not reset Tx queues, error %d\n",
500 error);
501 goto out_err;
502 }
503 /* set Tx rings WME properties */
504 error = ar5523_queue_init(ar);
505 if (error)
506 ar5523_err(ar, "could not init wme, error %d\n", error);
507
508out_err:
509 return error;
510}
511
512static void ar5523_rx_data_put(struct ar5523 *ar,
513 struct ar5523_rx_data *data)
514{
515 unsigned long flags;
516 spin_lock_irqsave(&ar->rx_data_list_lock, flags);
517 list_move(&data->list, &ar->rx_data_free);
518 spin_unlock_irqrestore(&ar->rx_data_list_lock, flags);
519}
520
521static void ar5523_data_rx_cb(struct urb *urb)
522{
523 struct ar5523_rx_data *data = urb->context;
524 struct ar5523 *ar = data->ar;
525 struct ar5523_rx_desc *desc;
526 struct ar5523_chunk *chunk;
527 struct ieee80211_hw *hw = ar->hw;
528 struct ieee80211_rx_status *rx_status;
529 u32 rxlen;
530 int usblen = urb->actual_length;
531 int hdrlen, pad;
532
533 ar5523_dbg(ar, "%s\n", __func__);
534 /* sync/async unlink faults aren't errors */
535 if (urb->status) {
536 if (urb->status != -ESHUTDOWN)
537 ar5523_err(ar, "%s: USB err: %d\n", __func__,
538 urb->status);
539 goto skip;
540 }
541
542 if (usblen < AR5523_MIN_RXBUFSZ) {
543 ar5523_err(ar, "RX: wrong xfer size (usblen=%d)\n", usblen);
544 goto skip;
545 }
546
547 chunk = (struct ar5523_chunk *) data->skb->data;
548
549 if (((chunk->flags & UATH_CFLAGS_FINAL) == 0) ||
550 chunk->seqnum != 0) {
551 ar5523_dbg(ar, "RX: No final flag. s: %d f: %02x l: %d\n",
552 chunk->seqnum, chunk->flags,
553 be16_to_cpu(chunk->length));
554 goto skip;
555 }
556
557 /* Rx descriptor is located at the end, 32-bit aligned */
558 desc = (struct ar5523_rx_desc *)
559 (data->skb->data + usblen - sizeof(struct ar5523_rx_desc));
560
561 rxlen = be32_to_cpu(desc->len);
562 if (rxlen > ar->rxbufsz) {
563 ar5523_dbg(ar, "RX: Bad descriptor (len=%d)\n",
564 be32_to_cpu(desc->len));
565 goto skip;
566 }
567
568 if (!rxlen) {
569 ar5523_dbg(ar, "RX: rxlen is 0\n");
570 goto skip;
571 }
572
573 if (be32_to_cpu(desc->status) != 0) {
574 ar5523_dbg(ar, "Bad RX status (0x%x len = %d). Skip\n",
575 be32_to_cpu(desc->status), be32_to_cpu(desc->len));
576 goto skip;
577 }
578
579 skb_reserve(data->skb, sizeof(*chunk));
580 skb_put(data->skb, rxlen - sizeof(struct ar5523_rx_desc));
581
582 hdrlen = ieee80211_get_hdrlen_from_skb(data->skb);
583 if (!IS_ALIGNED(hdrlen, 4)) {
584 ar5523_dbg(ar, "eek, alignment workaround activated\n");
585 pad = ALIGN(hdrlen, 4) - hdrlen;
586 memmove(data->skb->data + pad, data->skb->data, hdrlen);
587 skb_pull(data->skb, pad);
588 skb_put(data->skb, pad);
589 }
590
591 rx_status = IEEE80211_SKB_RXCB(data->skb);
592 memset(rx_status, 0, sizeof(*rx_status));
593 rx_status->freq = be32_to_cpu(desc->channel);
594 rx_status->band = hw->conf.channel->band;
595 rx_status->signal = -95 + be32_to_cpu(desc->rssi);
596
597 ieee80211_rx_irqsafe(hw, data->skb);
598 data->skb = NULL;
599
600skip:
601 if (data->skb) {
602 dev_kfree_skb_irq(data->skb);
603 data->skb = NULL;
604 }
605
606 ar5523_rx_data_put(ar, data);
607 if (atomic_inc_return(&ar->rx_data_free_cnt) >=
608 AR5523_RX_DATA_REFILL_COUNT &&
609 test_bit(AR5523_HW_UP, &ar->flags))
610 queue_work(ar->wq, &ar->rx_refill_work);
611}
612
613static void ar5523_rx_refill_work(struct work_struct *work)
614{
615 struct ar5523 *ar = container_of(work, struct ar5523, rx_refill_work);
616 struct ar5523_rx_data *data;
617 unsigned long flags;
618 int error;
619
620 ar5523_dbg(ar, "%s\n", __func__);
621 do {
622 spin_lock_irqsave(&ar->rx_data_list_lock, flags);
623
624 if (!list_empty(&ar->rx_data_free))
625 data = (struct ar5523_rx_data *) ar->rx_data_free.next;
626 else
627 data = NULL;
628 spin_unlock_irqrestore(&ar->rx_data_list_lock, flags);
629
630 if (!data)
631 goto done;
632
633 data->skb = alloc_skb(ar->rxbufsz, GFP_KERNEL);
634 if (!data->skb) {
635 ar5523_err(ar, "could not allocate rx skbuff\n");
636 return;
637 }
638
639 usb_fill_bulk_urb(data->urb, ar->dev,
640 ar5523_data_rx_pipe(ar->dev), data->skb->data,
641 ar->rxbufsz, ar5523_data_rx_cb, data);
642
643 spin_lock_irqsave(&ar->rx_data_list_lock, flags);
644 list_move(&data->list, &ar->rx_data_used);
645 spin_unlock_irqrestore(&ar->rx_data_list_lock, flags);
646 atomic_dec(&ar->rx_data_free_cnt);
647
648 error = usb_submit_urb(data->urb, GFP_KERNEL);
649 if (error) {
650 kfree_skb(data->skb);
651 if (error != -ENODEV)
652 ar5523_err(ar, "Err sending rx data urb %d\n",
653 error);
654 ar5523_rx_data_put(ar, data);
655 atomic_inc(&ar->rx_data_free_cnt);
656 return;
657 }
658
659 } while (true);
660done:
661 return;
662}
663
664static void ar5523_cancel_rx_bufs(struct ar5523 *ar)
665{
666 struct ar5523_rx_data *data;
667 unsigned long flags;
668
669 do {
670 spin_lock_irqsave(&ar->rx_data_list_lock, flags);
671 if (!list_empty(&ar->rx_data_used))
672 data = (struct ar5523_rx_data *) ar->rx_data_used.next;
673 else
674 data = NULL;
675 spin_unlock_irqrestore(&ar->rx_data_list_lock, flags);
676
677 if (!data)
678 break;
679
680 usb_kill_urb(data->urb);
681 list_move(&data->list, &ar->rx_data_free);
682 atomic_inc(&ar->rx_data_free_cnt);
683 } while (data);
684}
685
686static void ar5523_free_rx_bufs(struct ar5523 *ar)
687{
688 struct ar5523_rx_data *data;
689
690 ar5523_cancel_rx_bufs(ar);
691 while (!list_empty(&ar->rx_data_free)) {
692 data = (struct ar5523_rx_data *) ar->rx_data_free.next;
693 list_del(&data->list);
694 usb_free_urb(data->urb);
695 }
696}
697
698static int ar5523_alloc_rx_bufs(struct ar5523 *ar)
699{
700 int i;
701
702 for (i = 0; i < AR5523_RX_DATA_COUNT; i++) {
703 struct ar5523_rx_data *data = &ar->rx_data[i];
704
705 data->ar = ar;
706 data->urb = usb_alloc_urb(0, GFP_KERNEL);
707 if (!data->urb) {
708 ar5523_err(ar, "could not allocate rx data urb\n");
709 goto err;
710 }
711 list_add_tail(&data->list, &ar->rx_data_free);
712 atomic_inc(&ar->rx_data_free_cnt);
713 }
714 return 0;
715
716err:
717 ar5523_free_rx_bufs(ar);
718 return -ENOMEM;
719}
720
721static void ar5523_data_tx_pkt_put(struct ar5523 *ar)
722{
723 atomic_dec(&ar->tx_nr_total);
724 if (!atomic_dec_return(&ar->tx_nr_pending)) {
725 del_timer(&ar->tx_wd_timer);
726 wake_up(&ar->tx_flush_waitq);
727 }
728
729 if (atomic_read(&ar->tx_nr_total) < AR5523_TX_DATA_RESTART_COUNT) {
730 ar5523_dbg(ar, "restart tx queue\n");
731 ieee80211_wake_queues(ar->hw);
732 }
733}
734
735static void ar5523_data_tx_cb(struct urb *urb)
736{
737 struct sk_buff *skb = urb->context;
738 struct ieee80211_tx_info *txi = IEEE80211_SKB_CB(skb);
739 struct ar5523_tx_data *data = (struct ar5523_tx_data *)
740 txi->driver_data;
741 struct ar5523 *ar = data->ar;
742 unsigned long flags;
743
744 ar5523_dbg(ar, "data tx urb completed: %d\n", urb->status);
745
746 spin_lock_irqsave(&ar->tx_data_list_lock, flags);
747 list_del(&data->list);
748 spin_unlock_irqrestore(&ar->tx_data_list_lock, flags);
749
750 if (urb->status) {
751 ar5523_dbg(ar, "%s: urb status: %d\n", __func__, urb->status);
752 ar5523_data_tx_pkt_put(ar);
753 ieee80211_free_txskb(ar->hw, skb);
754 } else {
755 skb_pull(skb, sizeof(struct ar5523_tx_desc) + sizeof(__be32));
756 ieee80211_tx_status_irqsafe(ar->hw, skb);
757 }
758 usb_free_urb(urb);
759}
760
761static void ar5523_tx(struct ieee80211_hw *hw,
762 struct ieee80211_tx_control *control,
763 struct sk_buff *skb)
764{
765 struct ieee80211_tx_info *txi = IEEE80211_SKB_CB(skb);
766 struct ar5523_tx_data *data = (struct ar5523_tx_data *)
767 txi->driver_data;
768 struct ar5523 *ar = hw->priv;
769 unsigned long flags;
770
771 ar5523_dbg(ar, "tx called\n");
772 if (atomic_inc_return(&ar->tx_nr_total) >= AR5523_TX_DATA_COUNT) {
773 ar5523_dbg(ar, "tx queue full\n");
774 ar5523_dbg(ar, "stop queues (tot %d pend %d)\n",
775 atomic_read(&ar->tx_nr_total),
776 atomic_read(&ar->tx_nr_pending));
777 ieee80211_stop_queues(hw);
778 }
779
780 data->skb = skb;
781
782 spin_lock_irqsave(&ar->tx_data_list_lock, flags);
783 list_add_tail(&data->list, &ar->tx_queue_pending);
784 spin_unlock_irqrestore(&ar->tx_data_list_lock, flags);
785
786 ieee80211_queue_work(ar->hw, &ar->tx_work);
787}
788
789static void ar5523_tx_work_locked(struct ar5523 *ar)
790{
791 struct ar5523_tx_data *data;
792 struct ar5523_tx_desc *desc;
793 struct ar5523_chunk *chunk;
794 struct ieee80211_tx_info *txi;
795 struct urb *urb;
796 struct sk_buff *skb;
797 int error = 0, paylen;
798 u32 txqid;
799 unsigned long flags;
800
801 BUILD_BUG_ON(sizeof(struct ar5523_tx_data) >
802 IEEE80211_TX_INFO_DRIVER_DATA_SIZE);
803
804 ar5523_dbg(ar, "%s\n", __func__);
805 do {
806 spin_lock_irqsave(&ar->tx_data_list_lock, flags);
807 if (!list_empty(&ar->tx_queue_pending)) {
808 data = (struct ar5523_tx_data *)
809 ar->tx_queue_pending.next;
810 list_del(&data->list);
811 } else
812 data = NULL;
813 spin_unlock_irqrestore(&ar->tx_data_list_lock, flags);
814
815 if (!data)
816 break;
817
818 skb = data->skb;
819 txqid = 0;
820 txi = IEEE80211_SKB_CB(skb);
821 paylen = skb->len;
822 urb = usb_alloc_urb(0, GFP_KERNEL);
823 if (!urb) {
824 ar5523_err(ar, "Failed to allocate TX urb\n");
825 ieee80211_free_txskb(ar->hw, skb);
826 continue;
827 }
828
829 data->ar = ar;
830 data->urb = urb;
831
832 desc = (struct ar5523_tx_desc *)skb_push(skb, sizeof(*desc));
833 chunk = (struct ar5523_chunk *)skb_push(skb, sizeof(*chunk));
834
835 chunk->seqnum = 0;
836 chunk->flags = UATH_CFLAGS_FINAL;
837 chunk->length = cpu_to_be16(skb->len);
838
839 desc->msglen = cpu_to_be32(skb->len);
840 desc->msgid = AR5523_DATA_ID;
841 desc->buflen = cpu_to_be32(paylen);
842 desc->type = cpu_to_be32(WDCMSG_SEND);
843 desc->flags = cpu_to_be32(UATH_TX_NOTIFY);
844
845 if (test_bit(AR5523_CONNECTED, &ar->flags))
846 desc->connid = cpu_to_be32(AR5523_ID_BSS);
847 else
848 desc->connid = cpu_to_be32(AR5523_ID_BROADCAST);
849
850 if (txi->flags & IEEE80211_TX_CTL_USE_MINRATE)
851 txqid |= UATH_TXQID_MINRATE;
852
853 desc->txqid = cpu_to_be32(txqid);
854
855 urb->transfer_flags = URB_ZERO_PACKET;
856 usb_fill_bulk_urb(urb, ar->dev, ar5523_data_tx_pipe(ar->dev),
857 skb->data, skb->len, ar5523_data_tx_cb, skb);
858
859 spin_lock_irqsave(&ar->tx_data_list_lock, flags);
860 list_add_tail(&data->list, &ar->tx_queue_submitted);
861 spin_unlock_irqrestore(&ar->tx_data_list_lock, flags);
862 mod_timer(&ar->tx_wd_timer, jiffies + AR5523_TX_WD_TIMEOUT);
863 atomic_inc(&ar->tx_nr_pending);
864
865 ar5523_dbg(ar, "TX Frame (%d pending)\n",
866 atomic_read(&ar->tx_nr_pending));
867 error = usb_submit_urb(urb, GFP_KERNEL);
868 if (error) {
869 ar5523_err(ar, "error %d when submitting tx urb\n",
870 error);
871 spin_lock_irqsave(&ar->tx_data_list_lock, flags);
872 list_del(&data->list);
873 spin_unlock_irqrestore(&ar->tx_data_list_lock, flags);
874 atomic_dec(&ar->tx_nr_pending);
875 ar5523_data_tx_pkt_put(ar);
876 usb_free_urb(urb);
877 ieee80211_free_txskb(ar->hw, skb);
878 }
879 } while (true);
880}
881
882static void ar5523_tx_work(struct work_struct *work)
883{
884 struct ar5523 *ar = container_of(work, struct ar5523, tx_work);
885
886 ar5523_dbg(ar, "%s\n", __func__);
887 mutex_lock(&ar->mutex);
888 ar5523_tx_work_locked(ar);
889 mutex_unlock(&ar->mutex);
890}
891
892static void ar5523_tx_wd_timer(unsigned long arg)
893{
894 struct ar5523 *ar = (struct ar5523 *) arg;
895
896 ar5523_dbg(ar, "TX watchdog timer triggered\n");
897 ieee80211_queue_work(ar->hw, &ar->tx_wd_work);
898}
899
900static void ar5523_tx_wd_work(struct work_struct *work)
901{
902 struct ar5523 *ar = container_of(work, struct ar5523, tx_wd_work);
903
904 /* Occasionally the TX queues stop responding. The only way to
905 * recover seems to be to reset the dongle.
906 */
907
908 mutex_lock(&ar->mutex);
909 ar5523_err(ar, "TX queue stuck (tot %d pend %d)\n",
910 atomic_read(&ar->tx_nr_total),
911 atomic_read(&ar->tx_nr_pending));
912
913 ar5523_err(ar, "Will restart dongle.\n");
914 ar5523_cmd_write(ar, WDCMSG_TARGET_RESET, NULL, 0, 0);
915 mutex_unlock(&ar->mutex);
916}
917
918static void ar5523_flush_tx(struct ar5523 *ar)
919{
920 ar5523_tx_work_locked(ar);
921
922 /* Don't waste time trying to flush if USB is disconnected */
923 if (test_bit(AR5523_USB_DISCONNECTED, &ar->flags))
924 return;
925 if (!wait_event_timeout(ar->tx_flush_waitq,
926 !atomic_read(&ar->tx_nr_pending), AR5523_FLUSH_TIMEOUT))
927 ar5523_err(ar, "flush timeout (tot %d pend %d)\n",
928 atomic_read(&ar->tx_nr_total),
929 atomic_read(&ar->tx_nr_pending));
930}
931
932static void ar5523_free_tx_cmd(struct ar5523 *ar)
933{
934 struct ar5523_tx_cmd *cmd = &ar->tx_cmd;
935
936 usb_free_coherent(ar->dev, AR5523_MAX_RXCMDSZ, cmd->buf_tx,
937 cmd->urb_tx->transfer_dma);
938 usb_free_urb(cmd->urb_tx);
939}
940
941static int ar5523_alloc_tx_cmd(struct ar5523 *ar)
942{
943 struct ar5523_tx_cmd *cmd = &ar->tx_cmd;
944
945 cmd->ar = ar;
946 init_completion(&cmd->done);
947
948 cmd->urb_tx = usb_alloc_urb(0, GFP_KERNEL);
949 if (!cmd->urb_tx) {
950 ar5523_err(ar, "could not allocate urb\n");
951 return -ENOMEM;
952 }
953 cmd->buf_tx = usb_alloc_coherent(ar->dev, AR5523_MAX_TXCMDSZ,
954 GFP_KERNEL,
955 &cmd->urb_tx->transfer_dma);
956 if (!cmd->buf_tx) {
957 usb_free_urb(cmd->urb_tx);
958 return -ENOMEM;
959 }
960 return 0;
961}
962
963/*
964 * This function is called periodically (every second) when associated to
965 * query device statistics.
966 */
967static void ar5523_stat_work(struct work_struct *work)
968{
969 struct ar5523 *ar = container_of(work, struct ar5523, stat_work.work);
970 int error;
971
972 ar5523_dbg(ar, "%s\n", __func__);
973 mutex_lock(&ar->mutex);
974
975 /*
976 * Send request for statistics asynchronously once a second. This
977 * seems to be important. Throughput is a lot better if this is done.
978 */
979 error = ar5523_cmd_write(ar, WDCMSG_TARGET_GET_STATS, NULL, 0, 0);
980 if (error)
981 ar5523_err(ar, "could not query stats, error %d\n", error);
982 mutex_unlock(&ar->mutex);
983 ieee80211_queue_delayed_work(ar->hw, &ar->stat_work, HZ);
984}
985
986/*
987 * Interface routines to the mac80211 stack.
988 */
989static int ar5523_start(struct ieee80211_hw *hw)
990{
991 struct ar5523 *ar = hw->priv;
992 int error;
993 __be32 val;
994
995 ar5523_dbg(ar, "start called\n");
996
997 mutex_lock(&ar->mutex);
998 val = cpu_to_be32(0);
999 ar5523_cmd_write(ar, WDCMSG_BIND, &val, sizeof(val), 0);
1000
1001 /* set MAC address */
1002 ar5523_config_multi(ar, CFG_MAC_ADDR, &ar->hw->wiphy->perm_addr,
1003 ETH_ALEN);
1004
1005 /* XXX honor net80211 state */
1006 ar5523_config(ar, CFG_RATE_CONTROL_ENABLE, 0x00000001);
1007 ar5523_config(ar, CFG_DIVERSITY_CTL, 0x00000001);
1008 ar5523_config(ar, CFG_ABOLT, 0x0000003f);
1009 ar5523_config(ar, CFG_WME_ENABLED, 0x00000000);
1010
1011 ar5523_config(ar, CFG_SERVICE_TYPE, 1);
1012 ar5523_config(ar, CFG_TP_SCALE, 0x00000000);
1013 ar5523_config(ar, CFG_TPC_HALF_DBM5, 0x0000003c);
1014 ar5523_config(ar, CFG_TPC_HALF_DBM2, 0x0000003c);
1015 ar5523_config(ar, CFG_OVERRD_TX_POWER, 0x00000000);
1016 ar5523_config(ar, CFG_GMODE_PROTECTION, 0x00000000);
1017 ar5523_config(ar, CFG_GMODE_PROTECT_RATE_INDEX, 0x00000003);
1018 ar5523_config(ar, CFG_PROTECTION_TYPE, 0x00000000);
1019 ar5523_config(ar, CFG_MODE_CTS, 0x00000002);
1020
1021 error = ar5523_cmd_read(ar, WDCMSG_TARGET_START, NULL, 0,
1022 &val, sizeof(val), AR5523_CMD_FLAG_MAGIC);
1023 if (error) {
1024 ar5523_dbg(ar, "could not start target, error %d\n", error);
1025 goto err;
1026 }
1027 ar5523_dbg(ar, "WDCMSG_TARGET_START returns handle: 0x%x\n",
1028 be32_to_cpu(val));
1029
1030 ar5523_switch_chan(ar);
1031
1032 val = cpu_to_be32(TARGET_DEVICE_AWAKE);
1033 ar5523_cmd_write(ar, WDCMSG_SET_PWR_MODE, &val, sizeof(val), 0);
1034 /* XXX? check */
1035 ar5523_cmd_write(ar, WDCMSG_RESET_KEY_CACHE, NULL, 0, 0);
1036
1037 set_bit(AR5523_HW_UP, &ar->flags);
1038 queue_work(ar->wq, &ar->rx_refill_work);
1039
1040 /* enable Rx */
1041 ar5523_set_rxfilter(ar, 0, UATH_FILTER_OP_INIT);
1042 ar5523_set_rxfilter(ar,
1043 UATH_FILTER_RX_UCAST | UATH_FILTER_RX_MCAST |
1044 UATH_FILTER_RX_BCAST | UATH_FILTER_RX_BEACON,
1045 UATH_FILTER_OP_SET);
1046
1047 ar5523_set_ledsteady(ar, UATH_LED_ACTIVITY, UATH_LED_ON);
1048 ar5523_dbg(ar, "start OK\n");
1049
1050err:
1051 mutex_unlock(&ar->mutex);
1052 return error;
1053}
1054
1055static void ar5523_stop(struct ieee80211_hw *hw)
1056{
1057 struct ar5523 *ar = hw->priv;
1058
1059 ar5523_dbg(ar, "stop called\n");
1060
1061 cancel_delayed_work_sync(&ar->stat_work);
1062 mutex_lock(&ar->mutex);
1063 clear_bit(AR5523_HW_UP, &ar->flags);
1064
1065 ar5523_set_ledsteady(ar, UATH_LED_LINK, UATH_LED_OFF);
1066 ar5523_set_ledsteady(ar, UATH_LED_ACTIVITY, UATH_LED_OFF);
1067
1068 ar5523_cmd_write(ar, WDCMSG_TARGET_STOP, NULL, 0, 0);
1069
1070 del_timer_sync(&ar->tx_wd_timer);
1071 cancel_work_sync(&ar->tx_wd_work);
1072 cancel_work_sync(&ar->rx_refill_work);
1073 ar5523_cancel_rx_bufs(ar);
1074 mutex_unlock(&ar->mutex);
1075}
1076
1077static int ar5523_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1078{
1079 struct ar5523 *ar = hw->priv;
1080 int ret;
1081
1082 ar5523_dbg(ar, "set_rts_threshold called\n");
1083 mutex_lock(&ar->mutex);
1084
1085 ret = ar5523_config(ar, CFG_USER_RTS_THRESHOLD, value);
1086
1087 mutex_unlock(&ar->mutex);
1088 return ret;
1089}
1090
1091static void ar5523_flush(struct ieee80211_hw *hw, bool drop)
1092{
1093 struct ar5523 *ar = hw->priv;
1094
1095 ar5523_dbg(ar, "flush called\n");
1096 ar5523_flush_tx(ar);
1097}
1098
1099static int ar5523_add_interface(struct ieee80211_hw *hw,
1100 struct ieee80211_vif *vif)
1101{
1102 struct ar5523 *ar = hw->priv;
1103
1104 ar5523_dbg(ar, "add interface called\n");
1105
1106 if (ar->vif) {
1107 ar5523_dbg(ar, "invalid add_interface\n");
1108 return -EOPNOTSUPP;
1109 }
1110
1111 switch (vif->type) {
1112 case NL80211_IFTYPE_STATION:
1113 ar->vif = vif;
1114 break;
1115 default:
1116 return -EOPNOTSUPP;
1117 }
1118 return 0;
1119}
1120
1121static void ar5523_remove_interface(struct ieee80211_hw *hw,
1122 struct ieee80211_vif *vif)
1123{
1124 struct ar5523 *ar = hw->priv;
1125
1126 ar5523_dbg(ar, "remove interface called\n");
1127 ar->vif = NULL;
1128}
1129
1130static int ar5523_hwconfig(struct ieee80211_hw *hw, u32 changed)
1131{
1132 struct ar5523 *ar = hw->priv;
1133
1134 ar5523_dbg(ar, "config called\n");
1135 mutex_lock(&ar->mutex);
1136 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
1137 ar5523_dbg(ar, "Do channel switch\n");
1138 ar5523_flush_tx(ar);
1139 ar5523_switch_chan(ar);
1140 }
1141 mutex_unlock(&ar->mutex);
1142 return 0;
1143}
1144
1145static int ar5523_get_wlan_mode(struct ar5523 *ar,
1146 struct ieee80211_bss_conf *bss_conf)
1147{
1148 struct ieee80211_supported_band *band;
1149 int bit;
1150 struct ieee80211_sta *sta;
1151 u32 sta_rate_set;
1152
1153 band = ar->hw->wiphy->bands[ar->hw->conf.channel->band];
1154 sta = ieee80211_find_sta(ar->vif, bss_conf->bssid);
1155 if (!sta) {
1156 ar5523_info(ar, "STA not found!\n");
1157 return WLAN_MODE_11b;
1158 }
1159 sta_rate_set = sta->supp_rates[ar->hw->conf.channel->band];
1160
1161 for (bit = 0; bit < band->n_bitrates; bit++) {
1162 if (sta_rate_set & 1) {
1163 int rate = band->bitrates[bit].bitrate;
1164 switch (rate) {
1165 case 60:
1166 case 90:
1167 case 120:
1168 case 180:
1169 case 240:
1170 case 360:
1171 case 480:
1172 case 540:
1173 return WLAN_MODE_11g;
1174 }
1175 }
1176 sta_rate_set >>= 1;
1177 }
1178 return WLAN_MODE_11b;
1179}
1180
1181static void ar5523_create_rateset(struct ar5523 *ar,
1182 struct ieee80211_bss_conf *bss_conf,
1183 struct ar5523_cmd_rateset *rs,
1184 bool basic)
1185{
1186 struct ieee80211_supported_band *band;
1187 struct ieee80211_sta *sta;
1188 int bit, i = 0;
1189 u32 sta_rate_set, basic_rate_set;
1190
1191 sta = ieee80211_find_sta(ar->vif, bss_conf->bssid);
1192 basic_rate_set = bss_conf->basic_rates;
1193 if (!sta) {
1194 ar5523_info(ar, "STA not found. Cannot set rates\n");
1195 sta_rate_set = bss_conf->basic_rates;
1196 }
1197 sta_rate_set = sta->supp_rates[ar->hw->conf.channel->band];
1198
1199 ar5523_dbg(ar, "sta rate_set = %08x\n", sta_rate_set);
1200
1201 band = ar->hw->wiphy->bands[ar->hw->conf.channel->band];
1202 for (bit = 0; bit < band->n_bitrates; bit++) {
1203 BUG_ON(i >= AR5523_MAX_NRATES);
1204 ar5523_dbg(ar, "Considering rate %d : %d\n",
1205 band->bitrates[bit].hw_value, sta_rate_set & 1);
1206 if (sta_rate_set & 1) {
1207 rs->set[i] = band->bitrates[bit].hw_value;
1208 if (basic_rate_set & 1 && basic)
1209 rs->set[i] |= 0x80;
1210 i++;
1211 }
1212 sta_rate_set >>= 1;
1213 basic_rate_set >>= 1;
1214 }
1215
1216 rs->length = i;
1217}
1218
1219static int ar5523_set_basic_rates(struct ar5523 *ar,
1220 struct ieee80211_bss_conf *bss)
1221{
1222 struct ar5523_cmd_rates rates;
1223
1224 memset(&rates, 0, sizeof(rates));
1225 rates.connid = cpu_to_be32(2); /* XXX */
1226 rates.size = cpu_to_be32(sizeof(struct ar5523_cmd_rateset));
1227 ar5523_create_rateset(ar, bss, &rates.rateset, true);
1228
1229 return ar5523_cmd_write(ar, WDCMSG_SET_BASIC_RATE, &rates,
1230 sizeof(rates), 0);
1231}
1232
1233static int ar5523_create_connection(struct ar5523 *ar,
1234 struct ieee80211_vif *vif,
1235 struct ieee80211_bss_conf *bss)
1236{
1237 struct ar5523_cmd_create_connection create;
1238 int wlan_mode;
1239
1240 memset(&create, 0, sizeof(create));
1241 create.connid = cpu_to_be32(2);
1242 create.bssid = cpu_to_be32(0);
1243 /* XXX packed or not? */
1244 create.size = cpu_to_be32(sizeof(struct ar5523_cmd_rateset));
1245
1246 ar5523_create_rateset(ar, bss, &create.connattr.rateset, false);
1247
1248 wlan_mode = ar5523_get_wlan_mode(ar, bss);
1249 create.connattr.wlanmode = cpu_to_be32(wlan_mode);
1250
1251 return ar5523_cmd_write(ar, WDCMSG_CREATE_CONNECTION, &create,
1252 sizeof(create), 0);
1253}
1254
1255static int ar5523_write_associd(struct ar5523 *ar,
1256 struct ieee80211_bss_conf *bss)
1257{
1258 struct ar5523_cmd_set_associd associd;
1259
1260 memset(&associd, 0, sizeof(associd));
1261 associd.defaultrateix = cpu_to_be32(0); /* XXX */
1262 associd.associd = cpu_to_be32(bss->aid);
1263 associd.timoffset = cpu_to_be32(0x3b); /* XXX */
1264 memcpy(associd.bssid, bss->bssid, ETH_ALEN);
1265 return ar5523_cmd_write(ar, WDCMSG_WRITE_ASSOCID, &associd,
1266 sizeof(associd), 0);
1267}
1268
1269static void ar5523_bss_info_changed(struct ieee80211_hw *hw,
1270 struct ieee80211_vif *vif,
1271 struct ieee80211_bss_conf *bss,
1272 u32 changed)
1273{
1274 struct ar5523 *ar = hw->priv;
1275 int error;
1276
1277 ar5523_dbg(ar, "bss_info_changed called\n");
1278 mutex_lock(&ar->mutex);
1279
1280 if (!(changed & BSS_CHANGED_ASSOC))
1281 goto out_unlock;
1282
1283 if (bss->assoc) {
1284 error = ar5523_create_connection(ar, vif, bss);
1285 if (error) {
1286 ar5523_err(ar, "could not create connection\n");
1287 goto out_unlock;
1288 }
1289
1290 error = ar5523_set_basic_rates(ar, bss);
1291 if (error) {
1292 ar5523_err(ar, "could not set negotiated rate set\n");
1293 goto out_unlock;
1294 }
1295
1296 error = ar5523_write_associd(ar, bss);
1297 if (error) {
1298 ar5523_err(ar, "could not set association\n");
1299 goto out_unlock;
1300 }
1301
1302 /* turn link LED on */
1303 ar5523_set_ledsteady(ar, UATH_LED_LINK, UATH_LED_ON);
1304 set_bit(AR5523_CONNECTED, &ar->flags);
1305 ieee80211_queue_delayed_work(hw, &ar->stat_work, HZ);
1306
1307 } else {
1308 cancel_delayed_work(&ar->stat_work);
1309 clear_bit(AR5523_CONNECTED, &ar->flags);
1310 ar5523_set_ledsteady(ar, UATH_LED_LINK, UATH_LED_OFF);
1311 }
1312
1313out_unlock:
1314 mutex_unlock(&ar->mutex);
1315
1316}
1317
1318#define AR5523_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \
1319 FIF_ALLMULTI | \
1320 FIF_FCSFAIL | \
1321 FIF_OTHER_BSS)
1322
1323static void ar5523_configure_filter(struct ieee80211_hw *hw,
1324 unsigned int changed_flags,
1325 unsigned int *total_flags,
1326 u64 multicast)
1327{
1328 struct ar5523 *ar = hw->priv;
1329 u32 filter = 0;
1330
1331 ar5523_dbg(ar, "configure_filter called\n");
1332 mutex_lock(&ar->mutex);
1333 ar5523_flush_tx(ar);
1334
1335 *total_flags &= AR5523_SUPPORTED_FILTERS;
1336
1337 /* The filters seems strange. UATH_FILTER_RX_BCAST and
1338 * UATH_FILTER_RX_MCAST does not result in those frames being RXed.
1339 * The only way I have found to get [mb]cast frames seems to be
1340 * to set UATH_FILTER_RX_PROM. */
1341 filter |= UATH_FILTER_RX_UCAST | UATH_FILTER_RX_MCAST |
1342 UATH_FILTER_RX_BCAST | UATH_FILTER_RX_BEACON |
1343 UATH_FILTER_RX_PROM;
1344
1345 ar5523_set_rxfilter(ar, 0, UATH_FILTER_OP_INIT);
1346 ar5523_set_rxfilter(ar, filter, UATH_FILTER_OP_SET);
1347
1348 mutex_unlock(&ar->mutex);
1349}
1350
1351static const struct ieee80211_ops ar5523_ops = {
1352 .start = ar5523_start,
1353 .stop = ar5523_stop,
1354 .tx = ar5523_tx,
1355 .set_rts_threshold = ar5523_set_rts_threshold,
1356 .add_interface = ar5523_add_interface,
1357 .remove_interface = ar5523_remove_interface,
1358 .config = ar5523_hwconfig,
1359 .bss_info_changed = ar5523_bss_info_changed,
1360 .configure_filter = ar5523_configure_filter,
1361 .flush = ar5523_flush,
1362};
1363
1364static int ar5523_host_available(struct ar5523 *ar)
1365{
1366 struct ar5523_cmd_host_available setup;
1367
1368 /* inform target the host is available */
1369 setup.sw_ver_major = cpu_to_be32(ATH_SW_VER_MAJOR);
1370 setup.sw_ver_minor = cpu_to_be32(ATH_SW_VER_MINOR);
1371 setup.sw_ver_patch = cpu_to_be32(ATH_SW_VER_PATCH);
1372 setup.sw_ver_build = cpu_to_be32(ATH_SW_VER_BUILD);
1373 return ar5523_cmd_read(ar, WDCMSG_HOST_AVAILABLE,
1374 &setup, sizeof(setup), NULL, 0, 0);
1375}
1376
1377static int ar5523_get_devstatus(struct ar5523 *ar)
1378{
1379 u8 macaddr[ETH_ALEN];
1380 int error;
1381
1382 /* retrieve MAC address */
1383 error = ar5523_get_status(ar, ST_MAC_ADDR, macaddr, ETH_ALEN);
1384 if (error) {
1385 ar5523_err(ar, "could not read MAC address\n");
1386 return error;
1387 }
1388
1389 SET_IEEE80211_PERM_ADDR(ar->hw, macaddr);
1390
1391 error = ar5523_get_status(ar, ST_SERIAL_NUMBER,
1392 &ar->serial[0], sizeof(ar->serial));
1393 if (error) {
1394 ar5523_err(ar, "could not read device serial number\n");
1395 return error;
1396 }
1397 return 0;
1398}
1399
1400#define AR5523_SANE_RXBUFSZ 2000
1401
1402static int ar5523_get_max_rxsz(struct ar5523 *ar)
1403{
1404 int error;
1405 __be32 rxsize;
1406
1407 /* Get max rx size */
1408 error = ar5523_get_status(ar, ST_WDC_TRANSPORT_CHUNK_SIZE, &rxsize,
1409 sizeof(rxsize));
1410 if (error != 0) {
1411 ar5523_err(ar, "could not read max RX size\n");
1412 return error;
1413 }
1414
1415 ar->rxbufsz = be32_to_cpu(rxsize);
1416
1417 if (!ar->rxbufsz || ar->rxbufsz > AR5523_SANE_RXBUFSZ) {
1418 ar5523_err(ar, "Bad rxbufsz from device. Using %d instead\n",
1419 AR5523_SANE_RXBUFSZ);
1420 ar->rxbufsz = AR5523_SANE_RXBUFSZ;
1421 }
1422
1423 ar5523_dbg(ar, "Max RX buf size: %d\n", ar->rxbufsz);
1424 return 0;
1425}
1426
1427/*
1428 * This is copied from rtl818x, but we should probably move this
1429 * to common code as in OpenBSD.
1430 */
1431static const struct ieee80211_rate ar5523_rates[] = {
1432 { .bitrate = 10, .hw_value = 2, },
1433 { .bitrate = 20, .hw_value = 4 },
1434 { .bitrate = 55, .hw_value = 11, },
1435 { .bitrate = 110, .hw_value = 22, },
1436 { .bitrate = 60, .hw_value = 12, },
1437 { .bitrate = 90, .hw_value = 18, },
1438 { .bitrate = 120, .hw_value = 24, },
1439 { .bitrate = 180, .hw_value = 36, },
1440 { .bitrate = 240, .hw_value = 48, },
1441 { .bitrate = 360, .hw_value = 72, },
1442 { .bitrate = 480, .hw_value = 96, },
1443 { .bitrate = 540, .hw_value = 108, },
1444};
1445
1446static const struct ieee80211_channel ar5523_channels[] = {
1447 { .center_freq = 2412 },
1448 { .center_freq = 2417 },
1449 { .center_freq = 2422 },
1450 { .center_freq = 2427 },
1451 { .center_freq = 2432 },
1452 { .center_freq = 2437 },
1453 { .center_freq = 2442 },
1454 { .center_freq = 2447 },
1455 { .center_freq = 2452 },
1456 { .center_freq = 2457 },
1457 { .center_freq = 2462 },
1458 { .center_freq = 2467 },
1459 { .center_freq = 2472 },
1460 { .center_freq = 2484 },
1461};
1462
1463static int ar5523_init_modes(struct ar5523 *ar)
1464{
1465 BUILD_BUG_ON(sizeof(ar->channels) != sizeof(ar5523_channels));
1466 BUILD_BUG_ON(sizeof(ar->rates) != sizeof(ar5523_rates));
1467
1468 memcpy(ar->channels, ar5523_channels, sizeof(ar5523_channels));
1469 memcpy(ar->rates, ar5523_rates, sizeof(ar5523_rates));
1470
1471 ar->band.band = IEEE80211_BAND_2GHZ;
1472 ar->band.channels = ar->channels;
1473 ar->band.n_channels = ARRAY_SIZE(ar5523_channels);
1474 ar->band.bitrates = ar->rates;
1475 ar->band.n_bitrates = ARRAY_SIZE(ar5523_rates);
1476 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &ar->band;
1477 return 0;
1478}
1479
1480/*
1481 * Load the MIPS R4000 microcode into the device. Once the image is loaded,
1482 * the device will detach itself from the bus and reattach later with a new
1483 * product Id (a la ezusb).
1484 */
1485static int ar5523_load_firmware(struct usb_device *dev)
1486{
1487 struct ar5523_fwblock *txblock, *rxblock;
1488 const struct firmware *fw;
1489 void *fwbuf;
1490 int len, offset;
1491 int foolen; /* XXX(hch): handle short transfers */
1492 int error = -ENXIO;
1493
1494 if (request_firmware(&fw, AR5523_FIRMWARE_FILE, &dev->dev)) {
1495 dev_err(&dev->dev, "no firmware found: %s\n",
1496 AR5523_FIRMWARE_FILE);
1497 return -ENOENT;
1498 }
1499
1500 txblock = kmalloc(sizeof(*txblock), GFP_KERNEL);
1501 if (!txblock)
1502 goto out;
1503
1504 rxblock = kmalloc(sizeof(*rxblock), GFP_KERNEL);
1505 if (!rxblock)
1506 goto out_free_txblock;
1507
1508 fwbuf = kmalloc(AR5523_MAX_FWBLOCK_SIZE, GFP_KERNEL);
1509 if (!fwbuf)
1510 goto out_free_rxblock;
1511
1512 memset(txblock, 0, sizeof(struct ar5523_fwblock));
1513 txblock->flags = cpu_to_be32(AR5523_WRITE_BLOCK);
1514 txblock->total = cpu_to_be32(fw->size);
1515
1516 offset = 0;
1517 len = fw->size;
1518 while (len > 0) {
1519 int mlen = min(len, AR5523_MAX_FWBLOCK_SIZE);
1520
1521 txblock->remain = cpu_to_be32(len - mlen);
1522 txblock->len = cpu_to_be32(mlen);
1523
1524 /* send firmware block meta-data */
1525 error = usb_bulk_msg(dev, ar5523_cmd_tx_pipe(dev),
1526 txblock, sizeof(*txblock), &foolen,
1527 AR5523_CMD_TIMEOUT);
1528 if (error) {
1529 dev_err(&dev->dev,
1530 "could not send firmware block info\n");
1531 goto out_free_fwbuf;
1532 }
1533
1534 /* send firmware block data */
1535 memcpy(fwbuf, fw->data + offset, mlen);
1536 error = usb_bulk_msg(dev, ar5523_data_tx_pipe(dev),
1537 fwbuf, mlen, &foolen,
1538 AR5523_DATA_TIMEOUT);
1539 if (error) {
1540 dev_err(&dev->dev,
1541 "could not send firmware block data\n");
1542 goto out_free_fwbuf;
1543 }
1544
1545 /* wait for ack from firmware */
1546 error = usb_bulk_msg(dev, ar5523_cmd_rx_pipe(dev),
1547 rxblock, sizeof(*rxblock), &foolen,
1548 AR5523_CMD_TIMEOUT);
1549 if (error) {
1550 dev_err(&dev->dev,
1551 "could not read firmware answer\n");
1552 goto out_free_fwbuf;
1553 }
1554
1555 len -= mlen;
1556 offset += mlen;
1557 }
1558
1559 /*
1560 * Set the error to -ENXIO to make sure we continue probing for
1561 * a driver.
1562 */
1563 error = -ENXIO;
1564
1565 out_free_fwbuf:
1566 kfree(fwbuf);
1567 out_free_rxblock:
1568 kfree(rxblock);
1569 out_free_txblock:
1570 kfree(txblock);
1571 out:
1572 release_firmware(fw);
1573 return error;
1574}
1575
1576static int ar5523_probe(struct usb_interface *intf,
1577 const struct usb_device_id *id)
1578{
1579 struct usb_device *dev = interface_to_usbdev(intf);
1580 struct ieee80211_hw *hw;
1581 struct ar5523 *ar;
1582 int error = -ENOMEM;
1583
1584 /*
1585 * Load firmware if the device requires it. This will return
1586 * -ENXIO on success and we'll get called back afer the usb
1587 * id changes to indicate that the firmware is present.
1588 */
1589 if (id->driver_info & AR5523_FLAG_PRE_FIRMWARE)
1590 return ar5523_load_firmware(dev);
1591
1592
1593 hw = ieee80211_alloc_hw(sizeof(*ar), &ar5523_ops);
1594 if (!hw)
1595 goto out;
1596 SET_IEEE80211_DEV(hw, &intf->dev);
1597
1598 ar = hw->priv;
1599 ar->hw = hw;
1600 ar->dev = dev;
1601 mutex_init(&ar->mutex);
1602
1603 INIT_DELAYED_WORK(&ar->stat_work, ar5523_stat_work);
1604 init_timer(&ar->tx_wd_timer);
1605 setup_timer(&ar->tx_wd_timer, ar5523_tx_wd_timer, (unsigned long) ar);
1606 INIT_WORK(&ar->tx_wd_work, ar5523_tx_wd_work);
1607 INIT_WORK(&ar->tx_work, ar5523_tx_work);
1608 INIT_LIST_HEAD(&ar->tx_queue_pending);
1609 INIT_LIST_HEAD(&ar->tx_queue_submitted);
1610 spin_lock_init(&ar->tx_data_list_lock);
1611 atomic_set(&ar->tx_nr_total, 0);
1612 atomic_set(&ar->tx_nr_pending, 0);
1613 init_waitqueue_head(&ar->tx_flush_waitq);
1614
1615 atomic_set(&ar->rx_data_free_cnt, 0);
1616 INIT_WORK(&ar->rx_refill_work, ar5523_rx_refill_work);
1617 INIT_LIST_HEAD(&ar->rx_data_free);
1618 INIT_LIST_HEAD(&ar->rx_data_used);
1619 spin_lock_init(&ar->rx_data_list_lock);
1620
1621 ar->wq = create_singlethread_workqueue("ar5523");
1622 if (!ar->wq) {
1623 ar5523_err(ar, "Could not create wq\n");
1624 goto out_free_ar;
1625 }
1626
1627 error = ar5523_alloc_rx_bufs(ar);
1628 if (error) {
1629 ar5523_err(ar, "Could not allocate rx buffers\n");
1630 goto out_free_wq;
1631 }
1632
1633 error = ar5523_alloc_rx_cmd(ar);
1634 if (error) {
1635 ar5523_err(ar, "Could not allocate rx command buffers\n");
1636 goto out_free_rx_bufs;
1637 }
1638
1639 error = ar5523_alloc_tx_cmd(ar);
1640 if (error) {
1641 ar5523_err(ar, "Could not allocate tx command buffers\n");
1642 goto out_free_rx_cmd;
1643 }
1644
1645 error = ar5523_submit_rx_cmd(ar);
1646 if (error) {
1647 ar5523_err(ar, "Failed to submit rx cmd\n");
1648 goto out_free_tx_cmd;
1649 }
1650
1651 /*
1652 * We're now ready to send/receive firmware commands.
1653 */
1654 error = ar5523_host_available(ar);
1655 if (error) {
1656 ar5523_err(ar, "could not initialize adapter\n");
1657 goto out_cancel_rx_cmd;
1658 }
1659
1660 error = ar5523_get_max_rxsz(ar);
1661 if (error) {
1662 ar5523_err(ar, "could not get caps from adapter\n");
1663 goto out_cancel_rx_cmd;
1664 }
1665
1666 error = ar5523_get_devcap(ar);
1667 if (error) {
1668 ar5523_err(ar, "could not get caps from adapter\n");
1669 goto out_cancel_rx_cmd;
1670 }
1671
1672 error = ar5523_get_devstatus(ar);
1673 if (error != 0) {
1674 ar5523_err(ar, "could not get device status\n");
1675 goto out_cancel_rx_cmd;
1676 }
1677
1678 ar5523_info(ar, "MAC/BBP AR5523, RF AR%c112\n",
1679 (id->driver_info & AR5523_FLAG_ABG) ? '5' : '2');
1680
1681 ar->vif = NULL;
1682 hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
1683 IEEE80211_HW_SIGNAL_DBM |
1684 IEEE80211_HW_HAS_RATE_CONTROL;
1685 hw->extra_tx_headroom = sizeof(struct ar5523_tx_desc) +
1686 sizeof(struct ar5523_chunk);
1687 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
1688 hw->queues = 1;
1689
1690 error = ar5523_init_modes(ar);
1691 if (error)
1692 goto out_cancel_rx_cmd;
1693
1694 usb_set_intfdata(intf, hw);
1695
1696 error = ieee80211_register_hw(hw);
1697 if (error) {
1698 ar5523_err(ar, "could not register device\n");
1699 goto out_cancel_rx_cmd;
1700 }
1701
1702 ar5523_info(ar, "Found and initialized AR5523 device\n");
1703 return 0;
1704
1705out_cancel_rx_cmd:
1706 ar5523_cancel_rx_cmd(ar);
1707out_free_tx_cmd:
1708 ar5523_free_tx_cmd(ar);
1709out_free_rx_cmd:
1710 ar5523_free_rx_cmd(ar);
1711out_free_rx_bufs:
1712 ar5523_free_rx_bufs(ar);
1713out_free_wq:
1714 destroy_workqueue(ar->wq);
1715out_free_ar:
1716 ieee80211_free_hw(hw);
1717out:
1718 return error;
1719}
1720
1721static void ar5523_disconnect(struct usb_interface *intf)
1722{
1723 struct ieee80211_hw *hw = usb_get_intfdata(intf);
1724 struct ar5523 *ar = hw->priv;
1725
1726 ar5523_dbg(ar, "detaching\n");
1727 set_bit(AR5523_USB_DISCONNECTED, &ar->flags);
1728
1729 ieee80211_unregister_hw(hw);
1730
1731 ar5523_cancel_rx_cmd(ar);
1732 ar5523_free_tx_cmd(ar);
1733 ar5523_free_rx_cmd(ar);
1734 ar5523_free_rx_bufs(ar);
1735
1736 destroy_workqueue(ar->wq);
1737
1738 ieee80211_free_hw(hw);
1739 usb_set_intfdata(intf, NULL);
1740}
1741
1742#define AR5523_DEVICE_UG(vendor, device) \
1743 { USB_DEVICE((vendor), (device)) }, \
1744 { USB_DEVICE((vendor), (device) + 1), \
1745 .driver_info = AR5523_FLAG_PRE_FIRMWARE }
1746#define AR5523_DEVICE_UX(vendor, device) \
1747 { USB_DEVICE((vendor), (device)), \
1748 .driver_info = AR5523_FLAG_ABG }, \
1749 { USB_DEVICE((vendor), (device) + 1), \
1750 .driver_info = AR5523_FLAG_ABG|AR5523_FLAG_PRE_FIRMWARE }
1751
1752static struct usb_device_id ar5523_id_table[] = {
1753 AR5523_DEVICE_UG(0x168c, 0x0001), /* Atheros / AR5523 */
1754 AR5523_DEVICE_UG(0x0cf3, 0x0001), /* Atheros2 / AR5523_1 */
1755 AR5523_DEVICE_UG(0x0cf3, 0x0003), /* Atheros2 / AR5523_2 */
1756 AR5523_DEVICE_UX(0x0cf3, 0x0005), /* Atheros2 / AR5523_3 */
1757 AR5523_DEVICE_UG(0x0d8e, 0x7801), /* Conceptronic / AR5523_1 */
1758 AR5523_DEVICE_UX(0x0d8e, 0x7811), /* Conceptronic / AR5523_2 */
1759 AR5523_DEVICE_UX(0x2001, 0x3a00), /* Dlink / DWLAG132 */
1760 AR5523_DEVICE_UG(0x2001, 0x3a02), /* Dlink / DWLG132 */
1761 AR5523_DEVICE_UX(0x2001, 0x3a04), /* Dlink / DWLAG122 */
1762 AR5523_DEVICE_UG(0x1690, 0x0712), /* Gigaset / AR5523 */
1763 AR5523_DEVICE_UG(0x1690, 0x0710), /* Gigaset / SMCWUSBTG */
1764 AR5523_DEVICE_UG(0x129b, 0x160c), /* Gigaset / USB stick 108
1765 (CyberTAN Technology) */
1766 AR5523_DEVICE_UG(0x16ab, 0x7801), /* Globalsun / AR5523_1 */
1767 AR5523_DEVICE_UX(0x16ab, 0x7811), /* Globalsun / AR5523_2 */
1768 AR5523_DEVICE_UG(0x0d8e, 0x7802), /* Globalsun / AR5523_3 */
1769 AR5523_DEVICE_UX(0x0846, 0x4300), /* Netgear / WG111U */
1770 AR5523_DEVICE_UG(0x0846, 0x4250), /* Netgear / WG111T */
1771 AR5523_DEVICE_UG(0x0846, 0x5f00), /* Netgear / WPN111 */
1772 AR5523_DEVICE_UG(0x157e, 0x3006), /* Umedia / AR5523_1 */
1773 AR5523_DEVICE_UX(0x157e, 0x3205), /* Umedia / AR5523_2 */
1774 AR5523_DEVICE_UG(0x157e, 0x3006), /* Umedia / TEW444UBEU */
1775 AR5523_DEVICE_UG(0x1435, 0x0826), /* Wistronneweb / AR5523_1 */
1776 AR5523_DEVICE_UX(0x1435, 0x0828), /* Wistronneweb / AR5523_2 */
1777 AR5523_DEVICE_UG(0x0cde, 0x0012), /* Zcom / AR5523 */
1778 AR5523_DEVICE_UG(0x1385, 0x4250), /* Netgear3 / WG111T (2) */
1779 AR5523_DEVICE_UG(0x1385, 0x5f00), /* Netgear / WPN111 */
1780 AR5523_DEVICE_UG(0x1385, 0x5f02), /* Netgear / WPN111 */
1781 { }
1782};
1783MODULE_DEVICE_TABLE(usb, ar5523_id_table);
1784
1785static struct usb_driver ar5523_driver = {
1786 .name = "ar5523",
1787 .id_table = ar5523_id_table,
1788 .probe = ar5523_probe,
1789 .disconnect = ar5523_disconnect,
1790};
1791
1792static int __init ar5523_init(void)
1793{
1794 return usb_register(&ar5523_driver);
1795}
1796
1797static void __exit ar5523_exit(void)
1798{
1799 usb_deregister(&ar5523_driver);
1800}
1801
1802MODULE_LICENSE("Dual BSD/GPL");
1803MODULE_FIRMWARE(AR5523_FIRMWARE_FILE);
1804
1805module_init(ar5523_init);
1806module_exit(ar5523_exit);
diff --git a/drivers/net/wireless/ath/ar5523/ar5523.h b/drivers/net/wireless/ath/ar5523/ar5523.h
new file mode 100644
index 000000000000..6086ba3fb543
--- /dev/null
+++ b/drivers/net/wireless/ath/ar5523/ar5523.h
@@ -0,0 +1,152 @@
1/*
2 * Copyright (c) 2006 Damien Bergamini <damien.bergamini@free.fr>
3 * Copyright (c) 2006 Sam Leffler, Errno Consulting
4 * Copyright (c) 2007 Christoph Hellwig <hch@lst.de>
5 * Copyright (c) 2008-2009 Weongyo Jeong <weongyo@freebsd.org>
6 * Copyright (c) 2012 Pontus Fuchs <pontus.fuchs@gmail.com>
7 *
8 * Permission to use, copy, modify, and/or distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 */
20
21#define AR5523_FLAG_PRE_FIRMWARE (1 << 0)
22#define AR5523_FLAG_ABG (1 << 1)
23
24#define AR5523_FIRMWARE_FILE "ar5523.bin"
25
26#define AR5523_CMD_TX_PIPE 0x01
27#define AR5523_DATA_TX_PIPE 0x02
28#define AR5523_CMD_RX_PIPE 0x81
29#define AR5523_DATA_RX_PIPE 0x82
30
31#define ar5523_cmd_tx_pipe(dev) \
32 usb_sndbulkpipe((dev), AR5523_CMD_TX_PIPE)
33#define ar5523_data_tx_pipe(dev) \
34 usb_sndbulkpipe((dev), AR5523_DATA_TX_PIPE)
35#define ar5523_cmd_rx_pipe(dev) \
36 usb_rcvbulkpipe((dev), AR5523_CMD_RX_PIPE)
37#define ar5523_data_rx_pipe(dev) \
38 usb_rcvbulkpipe((dev), AR5523_DATA_RX_PIPE)
39
40#define AR5523_DATA_TIMEOUT 10000
41#define AR5523_CMD_TIMEOUT 1000
42
43#define AR5523_TX_DATA_COUNT 8
44#define AR5523_TX_DATA_RESTART_COUNT 2
45#define AR5523_RX_DATA_COUNT 16
46#define AR5523_RX_DATA_REFILL_COUNT 8
47
48#define AR5523_CMD_ID 1
49#define AR5523_DATA_ID 2
50
51#define AR5523_TX_WD_TIMEOUT (HZ * 2)
52#define AR5523_FLUSH_TIMEOUT (HZ * 3)
53
54enum AR5523_flags {
55 AR5523_HW_UP,
56 AR5523_USB_DISCONNECTED,
57 AR5523_CONNECTED
58};
59
60struct ar5523_tx_cmd {
61 struct ar5523 *ar;
62 struct urb *urb_tx;
63 void *buf_tx;
64 void *odata;
65 int olen;
66 int flags;
67 int res;
68 struct completion done;
69};
70
71/* This struct is placed in tx_info->driver_data. It must not be larger
72 * than IEEE80211_TX_INFO_DRIVER_DATA_SIZE.
73 */
74struct ar5523_tx_data {
75 struct list_head list;
76 struct ar5523 *ar;
77 struct sk_buff *skb;
78 struct urb *urb;
79};
80
81struct ar5523_rx_data {
82 struct list_head list;
83 struct ar5523 *ar;
84 struct urb *urb;
85 struct sk_buff *skb;
86};
87
88struct ar5523 {
89 struct usb_device *dev;
90 struct ieee80211_hw *hw;
91
92 unsigned long flags;
93 struct mutex mutex;
94 struct workqueue_struct *wq;
95
96 struct ar5523_tx_cmd tx_cmd;
97
98 struct delayed_work stat_work;
99
100 struct timer_list tx_wd_timer;
101 struct work_struct tx_wd_work;
102 struct work_struct tx_work;
103 struct list_head tx_queue_pending;
104 struct list_head tx_queue_submitted;
105 spinlock_t tx_data_list_lock;
106 wait_queue_head_t tx_flush_waitq;
107
108 /* Queued + Submitted TX frames */
109 atomic_t tx_nr_total;
110
111 /* Submitted TX frames */
112 atomic_t tx_nr_pending;
113
114 void *rx_cmd_buf;
115 struct urb *rx_cmd_urb;
116
117 struct ar5523_rx_data rx_data[AR5523_RX_DATA_COUNT];
118 spinlock_t rx_data_list_lock;
119 struct list_head rx_data_free;
120 struct list_head rx_data_used;
121 atomic_t rx_data_free_cnt;
122
123 struct work_struct rx_refill_work;
124
125 int rxbufsz;
126 u8 serial[16];
127
128 struct ieee80211_channel channels[14];
129 struct ieee80211_rate rates[12];
130 struct ieee80211_supported_band band;
131 struct ieee80211_vif *vif;
132};
133
134/* flags for sending firmware commands */
135#define AR5523_CMD_FLAG_READ (1 << 1)
136#define AR5523_CMD_FLAG_MAGIC (1 << 2)
137
138#define ar5523_dbg(ar, format, arg...) \
139 dev_dbg(&(ar)->dev->dev, format, ## arg)
140
141/* On USB hot-unplug there can be a lot of URBs in flight and they'll all
142 * fail. Instead of dealing with them in every possible place just surpress
143 * any messages on USB disconnect.
144 */
145#define ar5523_err(ar, format, arg...) \
146do { \
147 if (!test_bit(AR5523_USB_DISCONNECTED, &ar->flags)) { \
148 dev_err(&(ar)->dev->dev, format, ## arg); \
149 } \
150} while (0)
151#define ar5523_info(ar, format, arg...) \
152 dev_info(&(ar)->dev->dev, format, ## arg)
diff --git a/drivers/net/wireless/ath/ar5523/ar5523_hw.h b/drivers/net/wireless/ath/ar5523/ar5523_hw.h
new file mode 100644
index 000000000000..a0e8bf460316
--- /dev/null
+++ b/drivers/net/wireless/ath/ar5523/ar5523_hw.h
@@ -0,0 +1,431 @@
1/*
2 * Copyright (c) 2006 Damien Bergamini <damien.bergamini@free.fr>
3 * Copyright (c) 2006 Sam Leffler, Errno Consulting
4 * Copyright (c) 2007 Christoph Hellwig <hch@lst.de>
5 * Copyright (c) 2008-2009 Weongyo Jeong <weongyo@freebsd.org>
6 * Copyright (c) 2012 Pontus Fuchs <pontus.fuchs@gmail.com>
7 *
8 * Permission to use, copy, modify, and/or distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 */
20
21/* all fields are big endian */
22struct ar5523_fwblock {
23 __be32 flags;
24#define AR5523_WRITE_BLOCK (1 << 4)
25
26 __be32 len;
27#define AR5523_MAX_FWBLOCK_SIZE 2048
28
29 __be32 total;
30 __be32 remain;
31 __be32 rxtotal;
32 __be32 pad[123];
33} __packed;
34
35#define AR5523_MAX_RXCMDSZ 1024
36#define AR5523_MAX_TXCMDSZ 1024
37
38struct ar5523_cmd_hdr {
39 __be32 len;
40 __be32 code;
41/* NB: these are defined for rev 1.5 firmware; rev 1.6 is different */
42/* messages from Host -> Target */
43#define WDCMSG_HOST_AVAILABLE 0x01
44#define WDCMSG_BIND 0x02
45#define WDCMSG_TARGET_RESET 0x03
46#define WDCMSG_TARGET_GET_CAPABILITY 0x04
47#define WDCMSG_TARGET_SET_CONFIG 0x05
48#define WDCMSG_TARGET_GET_STATUS 0x06
49#define WDCMSG_TARGET_GET_STATS 0x07
50#define WDCMSG_TARGET_START 0x08
51#define WDCMSG_TARGET_STOP 0x09
52#define WDCMSG_TARGET_ENABLE 0x0a
53#define WDCMSG_TARGET_DISABLE 0x0b
54#define WDCMSG_CREATE_CONNECTION 0x0c
55#define WDCMSG_UPDATE_CONNECT_ATTR 0x0d
56#define WDCMSG_DELETE_CONNECT 0x0e
57#define WDCMSG_SEND 0x0f
58#define WDCMSG_FLUSH 0x10
59/* messages from Target -> Host */
60#define WDCMSG_STATS_UPDATE 0x11
61#define WDCMSG_BMISS 0x12
62#define WDCMSG_DEVICE_AVAIL 0x13
63#define WDCMSG_SEND_COMPLETE 0x14
64#define WDCMSG_DATA_AVAIL 0x15
65#define WDCMSG_SET_PWR_MODE 0x16
66#define WDCMSG_BMISS_ACK 0x17
67#define WDCMSG_SET_LED_STEADY 0x18
68#define WDCMSG_SET_LED_BLINK 0x19
69/* more messages */
70#define WDCMSG_SETUP_BEACON_DESC 0x1a
71#define WDCMSG_BEACON_INIT 0x1b
72#define WDCMSG_RESET_KEY_CACHE 0x1c
73#define WDCMSG_RESET_KEY_CACHE_ENTRY 0x1d
74#define WDCMSG_SET_KEY_CACHE_ENTRY 0x1e
75#define WDCMSG_SET_DECOMP_MASK 0x1f
76#define WDCMSG_SET_REGULATORY_DOMAIN 0x20
77#define WDCMSG_SET_LED_STATE 0x21
78#define WDCMSG_WRITE_ASSOCID 0x22
79#define WDCMSG_SET_STA_BEACON_TIMERS 0x23
80#define WDCMSG_GET_TSF 0x24
81#define WDCMSG_RESET_TSF 0x25
82#define WDCMSG_SET_ADHOC_MODE 0x26
83#define WDCMSG_SET_BASIC_RATE 0x27
84#define WDCMSG_MIB_CONTROL 0x28
85#define WDCMSG_GET_CHANNEL_DATA 0x29
86#define WDCMSG_GET_CUR_RSSI 0x2a
87#define WDCMSG_SET_ANTENNA_SWITCH 0x2b
88#define WDCMSG_USE_SHORT_SLOT_TIME 0x2f
89#define WDCMSG_SET_POWER_MODE 0x30
90#define WDCMSG_SETUP_PSPOLL_DESC 0x31
91#define WDCMSG_SET_RX_MULTICAST_FILTER 0x32
92#define WDCMSG_RX_FILTER 0x33
93#define WDCMSG_PER_CALIBRATION 0x34
94#define WDCMSG_RESET 0x35
95#define WDCMSG_DISABLE 0x36
96#define WDCMSG_PHY_DISABLE 0x37
97#define WDCMSG_SET_TX_POWER_LIMIT 0x38
98#define WDCMSG_SET_TX_QUEUE_PARAMS 0x39
99#define WDCMSG_SETUP_TX_QUEUE 0x3a
100#define WDCMSG_RELEASE_TX_QUEUE 0x3b
101#define WDCMSG_SET_DEFAULT_KEY 0x43
102
103 __u32 priv; /* driver private data,
104 don't care about endianess */
105 __be32 magic;
106 __be32 reserved2[4];
107};
108
109struct ar5523_cmd_host_available {
110 __be32 sw_ver_major;
111 __be32 sw_ver_minor;
112 __be32 sw_ver_patch;
113 __be32 sw_ver_build;
114} __packed;
115
116#define ATH_SW_VER_MAJOR 1
117#define ATH_SW_VER_MINOR 5
118#define ATH_SW_VER_PATCH 0
119#define ATH_SW_VER_BUILD 9999
120
121struct ar5523_chunk {
122 u8 seqnum; /* sequence number for ordering */
123 u8 flags;
124#define UATH_CFLAGS_FINAL 0x01 /* final chunk of a msg */
125#define UATH_CFLAGS_RXMSG 0x02 /* chunk contains rx completion */
126#define UATH_CFLAGS_DEBUG 0x04 /* for debugging */
127 __be16 length; /* chunk size in bytes */
128 /* chunk data follows */
129} __packed;
130
131/*
132 * Message format for a WDCMSG_DATA_AVAIL message from Target to Host.
133 */
134struct ar5523_rx_desc {
135 __be32 len; /* msg length including header */
136 __be32 code; /* WDCMSG_DATA_AVAIL */
137 __be32 gennum; /* generation number */
138 __be32 status; /* start of RECEIVE_INFO */
139#define UATH_STATUS_OK 0
140#define UATH_STATUS_STOP_IN_PROGRESS 1
141#define UATH_STATUS_CRC_ERR 2
142#define UATH_STATUS_PHY_ERR 3
143#define UATH_STATUS_DECRYPT_CRC_ERR 4
144#define UATH_STATUS_DECRYPT_MIC_ERR 5
145#define UATH_STATUS_DECOMP_ERR 6
146#define UATH_STATUS_KEY_ERR 7
147#define UATH_STATUS_ERR 8
148 __be32 tstamp_low; /* low-order 32-bits of rx timestamp */
149 __be32 tstamp_high; /* high-order 32-bits of rx timestamp */
150 __be32 framelen; /* frame length */
151 __be32 rate; /* rx rate code */
152 __be32 antenna;
153 __be32 rssi;
154 __be32 channel;
155 __be32 phyerror;
156 __be32 connix; /* key table ix for bss traffic */
157 __be32 decrypterror;
158 __be32 keycachemiss;
159 __be32 pad; /* XXX? */
160} __packed;
161
162struct ar5523_tx_desc {
163 __be32 msglen;
164 __be32 msgid; /* msg id (supplied by host) */
165 __be32 type; /* opcode: WDMSG_SEND or WDCMSG_FLUSH */
166 __be32 txqid; /* tx queue id and flags */
167#define UATH_TXQID_MASK 0x0f
168#define UATH_TXQID_MINRATE 0x10 /* use min tx rate */
169#define UATH_TXQID_FF 0x20 /* content is fast frame */
170 __be32 connid; /* tx connection id */
171#define UATH_ID_INVALID 0xffffffff /* for sending prior to connection */
172 __be32 flags; /* non-zero if response desired */
173#define UATH_TX_NOTIFY (1 << 24) /* f/w will send a UATH_NOTIF_TX */
174 __be32 buflen; /* payload length */
175} __packed;
176
177
178#define AR5523_ID_BSS 2
179#define AR5523_ID_BROADCAST 0xffffffff
180
181/* structure for command UATH_CMD_WRITE_MAC */
182struct ar5523_write_mac {
183 __be32 reg;
184 __be32 len;
185 u8 data[32];
186} __packed;
187
188struct ar5523_cmd_rateset {
189 __u8 length;
190#define AR5523_MAX_NRATES 32
191 __u8 set[AR5523_MAX_NRATES];
192};
193
194struct ar5523_cmd_set_associd { /* AR5523_WRITE_ASSOCID */
195 __be32 defaultrateix;
196 __be32 associd;
197 __be32 timoffset;
198 __be32 turboprime;
199 __u8 bssid[6];
200} __packed;
201
202/* structure for command WDCMSG_RESET */
203struct ar5523_cmd_reset {
204 __be32 flags; /* channel flags */
205#define UATH_CHAN_TURBO 0x0100
206#define UATH_CHAN_CCK 0x0200
207#define UATH_CHAN_OFDM 0x0400
208#define UATH_CHAN_2GHZ 0x1000
209#define UATH_CHAN_5GHZ 0x2000
210 __be32 freq; /* channel frequency */
211 __be32 maxrdpower;
212 __be32 cfgctl;
213 __be32 twiceantennareduction;
214 __be32 channelchange;
215 __be32 keeprccontent;
216} __packed;
217
218/* structure for command WDCMSG_SET_BASIC_RATE */
219struct ar5523_cmd_rates {
220 __be32 connid;
221 __be32 keeprccontent;
222 __be32 size;
223 struct ar5523_cmd_rateset rateset;
224} __packed;
225
226enum {
227 WLAN_MODE_NONE = 0,
228 WLAN_MODE_11b,
229 WLAN_MODE_11a,
230 WLAN_MODE_11g,
231 WLAN_MODE_11a_TURBO,
232 WLAN_MODE_11g_TURBO,
233 WLAN_MODE_11a_TURBO_PRIME,
234 WLAN_MODE_11g_TURBO_PRIME,
235 WLAN_MODE_11a_XR,
236 WLAN_MODE_11g_XR,
237};
238
239struct ar5523_cmd_connection_attr {
240 __be32 longpreambleonly;
241 struct ar5523_cmd_rateset rateset;
242 __be32 wlanmode;
243} __packed;
244
245/* structure for command AR5523_CREATE_CONNECTION */
246struct ar5523_cmd_create_connection {
247 __be32 connid;
248 __be32 bssid;
249 __be32 size;
250 struct ar5523_cmd_connection_attr connattr;
251} __packed;
252
253struct ar5523_cmd_ledsteady { /* WDCMSG_SET_LED_STEADY */
254 __be32 lednum;
255#define UATH_LED_LINK 0
256#define UATH_LED_ACTIVITY 1
257 __be32 ledmode;
258#define UATH_LED_OFF 0
259#define UATH_LED_ON 1
260} __packed;
261
262struct ar5523_cmd_ledblink { /* WDCMSG_SET_LED_BLINK */
263 __be32 lednum;
264 __be32 ledmode;
265 __be32 blinkrate;
266 __be32 slowmode;
267} __packed;
268
269struct ar5523_cmd_ledstate { /* WDCMSG_SET_LED_STATE */
270 __be32 connected;
271} __packed;
272
273struct ar5523_cmd_txq_attr {
274 __be32 priority;
275 __be32 aifs;
276 __be32 logcwmin;
277 __be32 logcwmax;
278 __be32 bursttime;
279 __be32 mode;
280 __be32 qflags;
281} __packed;
282
283struct ar5523_cmd_txq_setup { /* WDCMSG_SETUP_TX_QUEUE */
284 __be32 qid;
285 __be32 len;
286 struct ar5523_cmd_txq_attr attr;
287} __packed;
288
289struct ar5523_cmd_rx_filter { /* WDCMSG_RX_FILTER */
290 __be32 bits;
291#define UATH_FILTER_RX_UCAST 0x00000001
292#define UATH_FILTER_RX_MCAST 0x00000002
293#define UATH_FILTER_RX_BCAST 0x00000004
294#define UATH_FILTER_RX_CONTROL 0x00000008
295#define UATH_FILTER_RX_BEACON 0x00000010 /* beacon frames */
296#define UATH_FILTER_RX_PROM 0x00000020 /* promiscuous mode */
297#define UATH_FILTER_RX_PHY_ERR 0x00000040 /* phy errors */
298#define UATH_FILTER_RX_PHY_RADAR 0x00000080 /* radar phy errors */
299#define UATH_FILTER_RX_XR_POOL 0x00000400 /* XR group polls */
300#define UATH_FILTER_RX_PROBE_REQ 0x00000800
301 __be32 op;
302#define UATH_FILTER_OP_INIT 0x0
303#define UATH_FILTER_OP_SET 0x1
304#define UATH_FILTER_OP_CLEAR 0x2
305#define UATH_FILTER_OP_TEMP 0x3
306#define UATH_FILTER_OP_RESTORE 0x4
307} __packed;
308
309enum {
310 CFG_NONE, /* Sentinal to indicate "no config" */
311 CFG_REG_DOMAIN, /* Regulatory Domain */
312 CFG_RATE_CONTROL_ENABLE,
313 CFG_DEF_XMIT_DATA_RATE, /* NB: if rate control is not enabled */
314 CFG_HW_TX_RETRIES,
315 CFG_SW_TX_RETRIES,
316 CFG_SLOW_CLOCK_ENABLE,
317 CFG_COMP_PROC,
318 CFG_USER_RTS_THRESHOLD,
319 CFG_XR2NORM_RATE_THRESHOLD,
320 CFG_XRMODE_SWITCH_COUNT,
321 CFG_PROTECTION_TYPE,
322 CFG_BURST_SEQ_THRESHOLD,
323 CFG_ABOLT,
324 CFG_IQ_LOG_COUNT_MAX,
325 CFG_MODE_CTS,
326 CFG_WME_ENABLED,
327 CFG_GPRS_CBR_PERIOD,
328 CFG_SERVICE_TYPE,
329 /* MAC Address to use. Overrides EEPROM */
330 CFG_MAC_ADDR,
331 CFG_DEBUG_EAR,
332 CFG_INIT_REGS,
333 /* An ID for use in error & debug messages */
334 CFG_DEBUG_ID,
335 CFG_COMP_WIN_SZ,
336 CFG_DIVERSITY_CTL,
337 CFG_TP_SCALE,
338 CFG_TPC_HALF_DBM5,
339 CFG_TPC_HALF_DBM2,
340 CFG_OVERRD_TX_POWER,
341 CFG_USE_32KHZ_CLOCK,
342 CFG_GMODE_PROTECTION,
343 CFG_GMODE_PROTECT_RATE_INDEX,
344 CFG_GMODE_NON_ERP_PREAMBLE,
345 CFG_WDC_TRANSPORT_CHUNK_SIZE,
346};
347
348enum {
349 /* Sentinal to indicate "no capability" */
350 CAP_NONE,
351 CAP_ALL, /* ALL capabilities */
352 CAP_TARGET_VERSION,
353 CAP_TARGET_REVISION,
354 CAP_MAC_VERSION,
355 CAP_MAC_REVISION,
356 CAP_PHY_REVISION,
357 CAP_ANALOG_5GHz_REVISION,
358 CAP_ANALOG_2GHz_REVISION,
359 /* Target supports WDC message debug features */
360 CAP_DEBUG_WDCMSG_SUPPORT,
361
362 CAP_REG_DOMAIN,
363 CAP_COUNTRY_CODE,
364 CAP_REG_CAP_BITS,
365
366 CAP_WIRELESS_MODES,
367 CAP_CHAN_SPREAD_SUPPORT,
368 CAP_SLEEP_AFTER_BEACON_BROKEN,
369 CAP_COMPRESS_SUPPORT,
370 CAP_BURST_SUPPORT,
371 CAP_FAST_FRAMES_SUPPORT,
372 CAP_CHAP_TUNING_SUPPORT,
373 CAP_TURBOG_SUPPORT,
374 CAP_TURBO_PRIME_SUPPORT,
375 CAP_DEVICE_TYPE,
376 CAP_XR_SUPPORT,
377 CAP_WME_SUPPORT,
378 CAP_TOTAL_QUEUES,
379 CAP_CONNECTION_ID_MAX, /* Should absorb CAP_KEY_CACHE_SIZE */
380
381 CAP_LOW_5GHZ_CHAN,
382 CAP_HIGH_5GHZ_CHAN,
383 CAP_LOW_2GHZ_CHAN,
384 CAP_HIGH_2GHZ_CHAN,
385
386 CAP_MIC_AES_CCM,
387 CAP_MIC_CKIP,
388 CAP_MIC_TKIP,
389 CAP_MIC_TKIP_WME,
390 CAP_CIPHER_AES_CCM,
391 CAP_CIPHER_CKIP,
392 CAP_CIPHER_TKIP,
393
394 CAP_TWICE_ANTENNAGAIN_5G,
395 CAP_TWICE_ANTENNAGAIN_2G,
396};
397
398enum {
399 ST_NONE, /* Sentinal to indicate "no status" */
400 ST_ALL,
401 ST_SERVICE_TYPE,
402 ST_WLAN_MODE,
403 ST_FREQ,
404 ST_BAND,
405 ST_LAST_RSSI,
406 ST_PS_FRAMES_DROPPED,
407 ST_CACHED_DEF_ANT,
408 ST_COUNT_OTHER_RX_ANT,
409 ST_USE_FAST_DIVERSITY,
410 ST_MAC_ADDR,
411 ST_RX_GENERATION_NUM,
412 ST_TX_QUEUE_DEPTH,
413 ST_SERIAL_NUMBER,
414 ST_WDC_TRANSPORT_CHUNK_SIZE,
415};
416
417enum {
418 TARGET_DEVICE_AWAKE,
419 TARGET_DEVICE_SLEEP,
420 TARGET_DEVICE_PWRDN,
421 TARGET_DEVICE_PWRSAVE,
422 TARGET_DEVICE_SUSPEND,
423 TARGET_DEVICE_RESUME,
424};
425
426/* this is in net/ieee80211.h, but that conflicts with the mac80211 headers */
427#define IEEE80211_2ADDR_LEN 16
428
429#define AR5523_MIN_RXBUFSZ \
430 (((sizeof(__be32) + IEEE80211_2ADDR_LEN + \
431 sizeof(struct ar5523_rx_desc)) + 3) & ~3)