]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/net/wireless/ath/ar9170/main.c
ar9170: kill duplicated HT feature flag
[mirror_ubuntu-artful-kernel.git] / drivers / net / wireless / ath / ar9170 / main.c
1 /*
2 * Atheros AR9170 driver
3 *
4 * mac80211 interaction code
5 *
6 * Copyright 2008, Johannes Berg <johannes@sipsolutions.net>
7 * Copyright 2009, Christian Lamparter <chunkeey@web.de>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; see the file COPYING. If not, see
21 * http://www.gnu.org/licenses/.
22 *
23 * This file incorporates work covered by the following copyright and
24 * permission notice:
25 * Copyright (c) 2007-2008 Atheros Communications, Inc.
26 *
27 * Permission to use, copy, modify, and/or distribute this software for any
28 * purpose with or without fee is hereby granted, provided that the above
29 * copyright notice and this permission notice appear in all copies.
30 *
31 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
32 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
33 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
34 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
35 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
36 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
37 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
38 */
39
40 #include <linux/init.h>
41 #include <linux/module.h>
42 #include <linux/etherdevice.h>
43 #include <net/mac80211.h>
44 #include "ar9170.h"
45 #include "hw.h"
46 #include "cmd.h"
47
48 static int modparam_nohwcrypt;
49 module_param_named(nohwcrypt, modparam_nohwcrypt, bool, S_IRUGO);
50 MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
51
52 #define RATE(_bitrate, _hw_rate, _txpidx, _flags) { \
53 .bitrate = (_bitrate), \
54 .flags = (_flags), \
55 .hw_value = (_hw_rate) | (_txpidx) << 4, \
56 }
57
58 static struct ieee80211_rate __ar9170_ratetable[] = {
59 RATE(10, 0, 0, 0),
60 RATE(20, 1, 1, IEEE80211_RATE_SHORT_PREAMBLE),
61 RATE(55, 2, 2, IEEE80211_RATE_SHORT_PREAMBLE),
62 RATE(110, 3, 3, IEEE80211_RATE_SHORT_PREAMBLE),
63 RATE(60, 0xb, 0, 0),
64 RATE(90, 0xf, 0, 0),
65 RATE(120, 0xa, 0, 0),
66 RATE(180, 0xe, 0, 0),
67 RATE(240, 0x9, 0, 0),
68 RATE(360, 0xd, 1, 0),
69 RATE(480, 0x8, 2, 0),
70 RATE(540, 0xc, 3, 0),
71 };
72 #undef RATE
73
74 #define ar9170_g_ratetable (__ar9170_ratetable + 0)
75 #define ar9170_g_ratetable_size 12
76 #define ar9170_a_ratetable (__ar9170_ratetable + 4)
77 #define ar9170_a_ratetable_size 8
78
79 /*
80 * NB: The hw_value is used as an index into the ar9170_phy_freq_params
81 * array in phy.c so that we don't have to do frequency lookups!
82 */
83 #define CHAN(_freq, _idx) { \
84 .center_freq = (_freq), \
85 .hw_value = (_idx), \
86 .max_power = 18, /* XXX */ \
87 }
88
89 static struct ieee80211_channel ar9170_2ghz_chantable[] = {
90 CHAN(2412, 0),
91 CHAN(2417, 1),
92 CHAN(2422, 2),
93 CHAN(2427, 3),
94 CHAN(2432, 4),
95 CHAN(2437, 5),
96 CHAN(2442, 6),
97 CHAN(2447, 7),
98 CHAN(2452, 8),
99 CHAN(2457, 9),
100 CHAN(2462, 10),
101 CHAN(2467, 11),
102 CHAN(2472, 12),
103 CHAN(2484, 13),
104 };
105
106 static struct ieee80211_channel ar9170_5ghz_chantable[] = {
107 CHAN(4920, 14),
108 CHAN(4940, 15),
109 CHAN(4960, 16),
110 CHAN(4980, 17),
111 CHAN(5040, 18),
112 CHAN(5060, 19),
113 CHAN(5080, 20),
114 CHAN(5180, 21),
115 CHAN(5200, 22),
116 CHAN(5220, 23),
117 CHAN(5240, 24),
118 CHAN(5260, 25),
119 CHAN(5280, 26),
120 CHAN(5300, 27),
121 CHAN(5320, 28),
122 CHAN(5500, 29),
123 CHAN(5520, 30),
124 CHAN(5540, 31),
125 CHAN(5560, 32),
126 CHAN(5580, 33),
127 CHAN(5600, 34),
128 CHAN(5620, 35),
129 CHAN(5640, 36),
130 CHAN(5660, 37),
131 CHAN(5680, 38),
132 CHAN(5700, 39),
133 CHAN(5745, 40),
134 CHAN(5765, 41),
135 CHAN(5785, 42),
136 CHAN(5805, 43),
137 CHAN(5825, 44),
138 CHAN(5170, 45),
139 CHAN(5190, 46),
140 CHAN(5210, 47),
141 CHAN(5230, 48),
142 };
143 #undef CHAN
144
145 #define AR9170_HT_CAP \
146 { \
147 .ht_supported = true, \
148 .cap = IEEE80211_HT_CAP_MAX_AMSDU | \
149 IEEE80211_HT_CAP_SUP_WIDTH_20_40 | \
150 IEEE80211_HT_CAP_SGI_40 | \
151 IEEE80211_HT_CAP_DSSSCCK40 | \
152 IEEE80211_HT_CAP_SM_PS, \
153 .ampdu_factor = 3, \
154 .ampdu_density = 6, \
155 .mcs = { \
156 .rx_mask = { 0xFF, 0xFF, 0, 0, 0, 0, 0, 0, 0, 0, }, \
157 }, \
158 }
159
160 static struct ieee80211_supported_band ar9170_band_2GHz = {
161 .channels = ar9170_2ghz_chantable,
162 .n_channels = ARRAY_SIZE(ar9170_2ghz_chantable),
163 .bitrates = ar9170_g_ratetable,
164 .n_bitrates = ar9170_g_ratetable_size,
165 .ht_cap = AR9170_HT_CAP,
166 };
167
168 static struct ieee80211_supported_band ar9170_band_5GHz = {
169 .channels = ar9170_5ghz_chantable,
170 .n_channels = ARRAY_SIZE(ar9170_5ghz_chantable),
171 .bitrates = ar9170_a_ratetable,
172 .n_bitrates = ar9170_a_ratetable_size,
173 .ht_cap = AR9170_HT_CAP,
174 };
175
176 #ifdef AR9170_QUEUE_DEBUG
177 /*
178 * In case some wants works with AR9170's crazy tx_status queueing techniques.
179 * He might need this rather useful probing function.
180 *
181 * NOTE: caller must hold the queue's spinlock!
182 */
183
184 static void ar9170_print_txheader(struct ar9170 *ar, struct sk_buff *skb)
185 {
186 struct ar9170_tx_control *txc = (void *) skb->data;
187 struct ieee80211_hdr *hdr = (void *)txc->frame_data;
188
189 printk(KERN_DEBUG "%s: => FRAME [skb:%p, queue:%d, DA:[%pM] "
190 "mac_control:%04x, phy_control:%08x]\n",
191 wiphy_name(ar->hw->wiphy), skb, skb_get_queue_mapping(skb),
192 ieee80211_get_DA(hdr), le16_to_cpu(txc->mac_control),
193 le32_to_cpu(txc->phy_control));
194 }
195
196 static void ar9170_dump_station_tx_status_queue(struct ar9170 *ar,
197 struct sk_buff_head *queue)
198 {
199 struct sk_buff *skb;
200 int i = 0;
201
202 printk(KERN_DEBUG "---[ cut here ]---\n");
203 printk(KERN_DEBUG "%s: %d entries in tx_status queue.\n",
204 wiphy_name(ar->hw->wiphy), skb_queue_len(queue));
205
206 skb_queue_walk(queue, skb) {
207 struct ar9170_tx_control *txc = (void *) skb->data;
208 struct ieee80211_hdr *hdr = (void *)txc->frame_data;
209
210 printk(KERN_DEBUG "index:%d => \n", i);
211 ar9170_print_txheader(ar, skb);
212 }
213 printk(KERN_DEBUG "---[ end ]---\n");
214 }
215 #endif /* AR9170_QUEUE_DEBUG */
216
217 void ar9170_handle_tx_status(struct ar9170 *ar, struct sk_buff *skb,
218 bool valid_status, u16 tx_status)
219 {
220 struct ieee80211_tx_info *txinfo;
221 unsigned int retries = 0, queue = skb_get_queue_mapping(skb);
222 unsigned long flags;
223
224 spin_lock_irqsave(&ar->tx_stats_lock, flags);
225 ar->tx_stats[queue].len--;
226 if (ieee80211_queue_stopped(ar->hw, queue))
227 ieee80211_wake_queue(ar->hw, queue);
228 spin_unlock_irqrestore(&ar->tx_stats_lock, flags);
229
230 txinfo = IEEE80211_SKB_CB(skb);
231 ieee80211_tx_info_clear_status(txinfo);
232
233 switch (tx_status) {
234 case AR9170_TX_STATUS_RETRY:
235 retries = 2;
236 case AR9170_TX_STATUS_COMPLETE:
237 txinfo->flags |= IEEE80211_TX_STAT_ACK;
238 break;
239
240 case AR9170_TX_STATUS_FAILED:
241 retries = ar->hw->conf.long_frame_max_tx_count;
242 break;
243
244 default:
245 printk(KERN_ERR "%s: invalid tx_status response (%x).\n",
246 wiphy_name(ar->hw->wiphy), tx_status);
247 break;
248 }
249
250 if (valid_status)
251 txinfo->status.rates[0].count = retries + 1;
252
253 skb_pull(skb, sizeof(struct ar9170_tx_control));
254 ieee80211_tx_status_irqsafe(ar->hw, skb);
255 }
256
257 static struct sk_buff *ar9170_find_skb_in_queue(struct ar9170 *ar,
258 const u8 *mac,
259 const u32 queue,
260 struct sk_buff_head *q)
261 {
262 unsigned long flags;
263 struct sk_buff *skb;
264
265 spin_lock_irqsave(&q->lock, flags);
266 skb_queue_walk(q, skb) {
267 struct ar9170_tx_control *txc = (void *) skb->data;
268 struct ieee80211_hdr *hdr = (void *) txc->frame_data;
269 u32 txc_queue = (le32_to_cpu(txc->phy_control) &
270 AR9170_TX_PHY_QOS_MASK) >>
271 AR9170_TX_PHY_QOS_SHIFT;
272
273 if ((queue != txc_queue) ||
274 (compare_ether_addr(ieee80211_get_DA(hdr), mac)))
275 continue;
276
277 __skb_unlink(skb, q);
278 spin_unlock_irqrestore(&q->lock, flags);
279 return skb;
280 }
281 spin_unlock_irqrestore(&q->lock, flags);
282 return NULL;
283 }
284
285 static struct sk_buff *ar9170_find_queued_skb(struct ar9170 *ar, const u8 *mac,
286 const u32 queue)
287 {
288 struct ieee80211_sta *sta;
289 struct sk_buff *skb;
290
291 /*
292 * Unfortunately, the firmware does not tell to which (queued) frame
293 * this transmission status report belongs to.
294 *
295 * So we have to make risky guesses - with the scarce information
296 * the firmware provided (-> destination MAC, and phy_control) -
297 * and hope that we picked the right one...
298 */
299 rcu_read_lock();
300 sta = ieee80211_find_sta(ar->hw, mac);
301
302 if (likely(sta)) {
303 struct ar9170_sta_info *sta_priv = (void *) sta->drv_priv;
304 skb = skb_dequeue(&sta_priv->tx_status[queue]);
305 rcu_read_unlock();
306 if (likely(skb))
307 return skb;
308 } else
309 rcu_read_unlock();
310
311 /* scan the waste queue for candidates */
312 skb = ar9170_find_skb_in_queue(ar, mac, queue,
313 &ar->global_tx_status_waste);
314 if (!skb) {
315 /* so it still _must_ be in the global list. */
316 skb = ar9170_find_skb_in_queue(ar, mac, queue,
317 &ar->global_tx_status);
318 }
319
320 #ifdef AR9170_QUEUE_DEBUG
321 if (unlikely((!skb) && net_ratelimit())) {
322 printk(KERN_ERR "%s: ESS:[%pM] does not have any "
323 "outstanding frames in this queue (%d).\n",
324 wiphy_name(ar->hw->wiphy), mac, queue);
325 }
326 #endif /* AR9170_QUEUE_DEBUG */
327 return skb;
328 }
329
330 /*
331 * This worker tries to keep the global tx_status queue empty.
332 * So we can guarantee that incoming tx_status reports for
333 * unregistered stations are always synced with the actual
334 * frame - which we think - belongs to.
335 */
336
337 static void ar9170_tx_status_janitor(struct work_struct *work)
338 {
339 struct ar9170 *ar = container_of(work, struct ar9170,
340 tx_status_janitor.work);
341 struct sk_buff *skb;
342
343 if (unlikely(!IS_STARTED(ar)))
344 return ;
345
346 mutex_lock(&ar->mutex);
347 /* recycle the garbage back to mac80211... one by one. */
348 while ((skb = skb_dequeue(&ar->global_tx_status_waste))) {
349 #ifdef AR9170_QUEUE_DEBUG
350 printk(KERN_DEBUG "%s: dispose queued frame =>\n",
351 wiphy_name(ar->hw->wiphy));
352 ar9170_print_txheader(ar, skb);
353 #endif /* AR9170_QUEUE_DEBUG */
354 ar9170_handle_tx_status(ar, skb, false,
355 AR9170_TX_STATUS_FAILED);
356 }
357
358 while ((skb = skb_dequeue(&ar->global_tx_status))) {
359 #ifdef AR9170_QUEUE_DEBUG
360 printk(KERN_DEBUG "%s: moving frame into waste queue =>\n",
361 wiphy_name(ar->hw->wiphy));
362
363 ar9170_print_txheader(ar, skb);
364 #endif /* AR9170_QUEUE_DEBUG */
365 skb_queue_tail(&ar->global_tx_status_waste, skb);
366 }
367
368 /* recall the janitor in 100ms - if there's garbage in the can. */
369 if (skb_queue_len(&ar->global_tx_status_waste) > 0)
370 queue_delayed_work(ar->hw->workqueue, &ar->tx_status_janitor,
371 msecs_to_jiffies(100));
372
373 mutex_unlock(&ar->mutex);
374 }
375
376 static void ar9170_handle_command_response(struct ar9170 *ar,
377 void *buf, u32 len)
378 {
379 struct ar9170_cmd_response *cmd = (void *) buf;
380
381 if ((cmd->type & 0xc0) != 0xc0) {
382 ar->callback_cmd(ar, len, buf);
383 return;
384 }
385
386 /* hardware event handlers */
387 switch (cmd->type) {
388 case 0xc1: {
389 /*
390 * TX status notification:
391 * bytes: 0c c1 XX YY M1 M2 M3 M4 M5 M6 R4 R3 R2 R1 S2 S1
392 *
393 * XX always 81
394 * YY always 00
395 * M1-M6 is the MAC address
396 * R1-R4 is the transmit rate
397 * S1-S2 is the transmit status
398 */
399
400 struct sk_buff *skb;
401 u32 queue = (le32_to_cpu(cmd->tx_status.rate) &
402 AR9170_TX_PHY_QOS_MASK) >> AR9170_TX_PHY_QOS_SHIFT;
403
404 skb = ar9170_find_queued_skb(ar, cmd->tx_status.dst, queue);
405 if (unlikely(!skb))
406 return ;
407
408 ar9170_handle_tx_status(ar, skb, true,
409 le16_to_cpu(cmd->tx_status.status));
410 break;
411 }
412
413 case 0xc0:
414 /*
415 * pre-TBTT event
416 */
417 if (ar->vif && ar->vif->type == NL80211_IFTYPE_AP)
418 queue_work(ar->hw->workqueue, &ar->beacon_work);
419 break;
420
421 case 0xc2:
422 /*
423 * (IBSS) beacon send notification
424 * bytes: 04 c2 XX YY B4 B3 B2 B1
425 *
426 * XX always 80
427 * YY always 00
428 * B1-B4 "should" be the number of send out beacons.
429 */
430 break;
431
432 case 0xc3:
433 /* End of Atim Window */
434 break;
435
436 case 0xc4:
437 case 0xc5:
438 /* BlockACK events */
439 break;
440
441 case 0xc6:
442 /* Watchdog Interrupt */
443 break;
444
445 case 0xc9:
446 /* retransmission issue / SIFS/EIFS collision ?! */
447 break;
448
449 default:
450 printk(KERN_INFO "received unhandled event %x\n", cmd->type);
451 print_hex_dump_bytes("dump:", DUMP_PREFIX_NONE, buf, len);
452 break;
453 }
454 }
455
456 static void ar9170_rx_reset_rx_mpdu(struct ar9170 *ar)
457 {
458 memset(&ar->rx_mpdu.plcp, 0, sizeof(struct ar9170_rx_head));
459 ar->rx_mpdu.has_plcp = false;
460 }
461
462 static int ar9170_nag_limiter(struct ar9170 *ar)
463 {
464 bool print_message;
465
466 /*
467 * we expect all sorts of errors in promiscuous mode.
468 * don't bother with it, it's OK!
469 */
470 if (ar->sniffer_enabled)
471 return false;
472
473 /*
474 * only go for frequent errors! The hardware tends to
475 * do some stupid thing once in a while under load, in
476 * noisy environments or just for fun!
477 */
478 if (time_before(jiffies, ar->bad_hw_nagger) && net_ratelimit())
479 print_message = true;
480 else
481 print_message = false;
482
483 /* reset threshold for "once in a while" */
484 ar->bad_hw_nagger = jiffies + HZ / 4;
485 return print_message;
486 }
487
488 static int ar9170_rx_mac_status(struct ar9170 *ar,
489 struct ar9170_rx_head *head,
490 struct ar9170_rx_macstatus *mac,
491 struct ieee80211_rx_status *status)
492 {
493 u8 error, decrypt;
494
495 BUILD_BUG_ON(sizeof(struct ar9170_rx_head) != 12);
496 BUILD_BUG_ON(sizeof(struct ar9170_rx_macstatus) != 4);
497
498 error = mac->error;
499 if (error & AR9170_RX_ERROR_MMIC) {
500 status->flag |= RX_FLAG_MMIC_ERROR;
501 error &= ~AR9170_RX_ERROR_MMIC;
502 }
503
504 if (error & AR9170_RX_ERROR_PLCP) {
505 status->flag |= RX_FLAG_FAILED_PLCP_CRC;
506 error &= ~AR9170_RX_ERROR_PLCP;
507
508 if (!(ar->filter_state & FIF_PLCPFAIL))
509 return -EINVAL;
510 }
511
512 if (error & AR9170_RX_ERROR_FCS) {
513 status->flag |= RX_FLAG_FAILED_FCS_CRC;
514 error &= ~AR9170_RX_ERROR_FCS;
515
516 if (!(ar->filter_state & FIF_FCSFAIL))
517 return -EINVAL;
518 }
519
520 decrypt = ar9170_get_decrypt_type(mac);
521 if (!(decrypt & AR9170_RX_ENC_SOFTWARE) &&
522 decrypt != AR9170_ENC_ALG_NONE)
523 status->flag |= RX_FLAG_DECRYPTED;
524
525 /* ignore wrong RA errors */
526 error &= ~AR9170_RX_ERROR_WRONG_RA;
527
528 if (error & AR9170_RX_ERROR_DECRYPT) {
529 error &= ~AR9170_RX_ERROR_DECRYPT;
530 /*
531 * Rx decryption is done in place,
532 * the original data is lost anyway.
533 */
534
535 return -EINVAL;
536 }
537
538 /* drop any other error frames */
539 if (unlikely(error)) {
540 /* TODO: update netdevice's RX dropped/errors statistics */
541
542 if (ar9170_nag_limiter(ar))
543 printk(KERN_DEBUG "%s: received frame with "
544 "suspicious error code (%#x).\n",
545 wiphy_name(ar->hw->wiphy), error);
546
547 return -EINVAL;
548 }
549
550 status->band = ar->channel->band;
551 status->freq = ar->channel->center_freq;
552
553 switch (mac->status & AR9170_RX_STATUS_MODULATION_MASK) {
554 case AR9170_RX_STATUS_MODULATION_CCK:
555 if (mac->status & AR9170_RX_STATUS_SHORT_PREAMBLE)
556 status->flag |= RX_FLAG_SHORTPRE;
557 switch (head->plcp[0]) {
558 case 0x0a:
559 status->rate_idx = 0;
560 break;
561 case 0x14:
562 status->rate_idx = 1;
563 break;
564 case 0x37:
565 status->rate_idx = 2;
566 break;
567 case 0x6e:
568 status->rate_idx = 3;
569 break;
570 default:
571 if (ar9170_nag_limiter(ar))
572 printk(KERN_ERR "%s: invalid plcp cck rate "
573 "(%x).\n", wiphy_name(ar->hw->wiphy),
574 head->plcp[0]);
575 return -EINVAL;
576 }
577 break;
578
579 case AR9170_RX_STATUS_MODULATION_OFDM:
580 switch (head->plcp[0] & 0xf) {
581 case 0xb:
582 status->rate_idx = 0;
583 break;
584 case 0xf:
585 status->rate_idx = 1;
586 break;
587 case 0xa:
588 status->rate_idx = 2;
589 break;
590 case 0xe:
591 status->rate_idx = 3;
592 break;
593 case 0x9:
594 status->rate_idx = 4;
595 break;
596 case 0xd:
597 status->rate_idx = 5;
598 break;
599 case 0x8:
600 status->rate_idx = 6;
601 break;
602 case 0xc:
603 status->rate_idx = 7;
604 break;
605 default:
606 if (ar9170_nag_limiter(ar))
607 printk(KERN_ERR "%s: invalid plcp ofdm rate "
608 "(%x).\n", wiphy_name(ar->hw->wiphy),
609 head->plcp[0]);
610 return -EINVAL;
611 }
612 if (status->band == IEEE80211_BAND_2GHZ)
613 status->rate_idx += 4;
614 break;
615
616 case AR9170_RX_STATUS_MODULATION_HT:
617 if (head->plcp[3] & 0x80)
618 status->flag |= RX_FLAG_40MHZ;
619 if (head->plcp[6] & 0x80)
620 status->flag |= RX_FLAG_SHORT_GI;
621
622 status->rate_idx = clamp(0, 75, head->plcp[6] & 0x7f);
623 status->flag |= RX_FLAG_HT;
624 break;
625
626 case AR9170_RX_STATUS_MODULATION_DUPOFDM:
627 /* XXX */
628 if (ar9170_nag_limiter(ar))
629 printk(KERN_ERR "%s: invalid modulation\n",
630 wiphy_name(ar->hw->wiphy));
631 return -EINVAL;
632 }
633
634 return 0;
635 }
636
637 static void ar9170_rx_phy_status(struct ar9170 *ar,
638 struct ar9170_rx_phystatus *phy,
639 struct ieee80211_rx_status *status)
640 {
641 int i;
642
643 BUILD_BUG_ON(sizeof(struct ar9170_rx_phystatus) != 20);
644
645 for (i = 0; i < 3; i++)
646 if (phy->rssi[i] != 0x80)
647 status->antenna |= BIT(i);
648
649 /* post-process RSSI */
650 for (i = 0; i < 7; i++)
651 if (phy->rssi[i] & 0x80)
652 phy->rssi[i] = ((phy->rssi[i] & 0x7f) + 1) & 0x7f;
653
654 /* TODO: we could do something with phy_errors */
655 status->signal = ar->noise[0] + phy->rssi_combined;
656 status->noise = ar->noise[0];
657 }
658
659 static struct sk_buff *ar9170_rx_copy_data(u8 *buf, int len)
660 {
661 struct sk_buff *skb;
662 int reserved = 0;
663 struct ieee80211_hdr *hdr = (void *) buf;
664
665 if (ieee80211_is_data_qos(hdr->frame_control)) {
666 u8 *qc = ieee80211_get_qos_ctl(hdr);
667 reserved += NET_IP_ALIGN;
668
669 if (*qc & IEEE80211_QOS_CONTROL_A_MSDU_PRESENT)
670 reserved += NET_IP_ALIGN;
671 }
672
673 if (ieee80211_has_a4(hdr->frame_control))
674 reserved += NET_IP_ALIGN;
675
676 reserved = 32 + (reserved & NET_IP_ALIGN);
677
678 skb = dev_alloc_skb(len + reserved);
679 if (likely(skb)) {
680 skb_reserve(skb, reserved);
681 memcpy(skb_put(skb, len), buf, len);
682 }
683
684 return skb;
685 }
686
687 /*
688 * If the frame alignment is right (or the kernel has
689 * CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS), and there
690 * is only a single MPDU in the USB frame, then we could
691 * submit to mac80211 the SKB directly. However, since
692 * there may be multiple packets in one SKB in stream
693 * mode, and we need to observe the proper ordering,
694 * this is non-trivial.
695 */
696
697 static void ar9170_handle_mpdu(struct ar9170 *ar, u8 *buf, int len)
698 {
699 struct ar9170_rx_head *head;
700 struct ar9170_rx_macstatus *mac;
701 struct ar9170_rx_phystatus *phy = NULL;
702 struct ieee80211_rx_status status;
703 struct sk_buff *skb;
704 int mpdu_len;
705
706 if (unlikely(!IS_STARTED(ar) || len < (sizeof(*mac))))
707 return ;
708
709 /* Received MPDU */
710 mpdu_len = len - sizeof(*mac);
711
712 mac = (void *)(buf + mpdu_len);
713 if (unlikely(mac->error & AR9170_RX_ERROR_FATAL)) {
714 /* this frame is too damaged and can't be used - drop it */
715
716 return ;
717 }
718
719 switch (mac->status & AR9170_RX_STATUS_MPDU_MASK) {
720 case AR9170_RX_STATUS_MPDU_FIRST:
721 /* first mpdu packet has the plcp header */
722 if (likely(mpdu_len >= sizeof(struct ar9170_rx_head))) {
723 head = (void *) buf;
724 memcpy(&ar->rx_mpdu.plcp, (void *) buf,
725 sizeof(struct ar9170_rx_head));
726
727 mpdu_len -= sizeof(struct ar9170_rx_head);
728 buf += sizeof(struct ar9170_rx_head);
729 ar->rx_mpdu.has_plcp = true;
730 } else {
731 if (ar9170_nag_limiter(ar))
732 printk(KERN_ERR "%s: plcp info is clipped.\n",
733 wiphy_name(ar->hw->wiphy));
734 return ;
735 }
736 break;
737
738 case AR9170_RX_STATUS_MPDU_LAST:
739 /* last mpdu has a extra tail with phy status information */
740
741 if (likely(mpdu_len >= sizeof(struct ar9170_rx_phystatus))) {
742 mpdu_len -= sizeof(struct ar9170_rx_phystatus);
743 phy = (void *)(buf + mpdu_len);
744 } else {
745 if (ar9170_nag_limiter(ar))
746 printk(KERN_ERR "%s: frame tail is clipped.\n",
747 wiphy_name(ar->hw->wiphy));
748 return ;
749 }
750
751 case AR9170_RX_STATUS_MPDU_MIDDLE:
752 /* middle mpdus are just data */
753 if (unlikely(!ar->rx_mpdu.has_plcp)) {
754 if (!ar9170_nag_limiter(ar))
755 return ;
756
757 printk(KERN_ERR "%s: rx stream did not start "
758 "with a first_mpdu frame tag.\n",
759 wiphy_name(ar->hw->wiphy));
760
761 return ;
762 }
763
764 head = &ar->rx_mpdu.plcp;
765 break;
766
767 case AR9170_RX_STATUS_MPDU_SINGLE:
768 /* single mpdu - has plcp (head) and phy status (tail) */
769 head = (void *) buf;
770
771 mpdu_len -= sizeof(struct ar9170_rx_head);
772 mpdu_len -= sizeof(struct ar9170_rx_phystatus);
773
774 buf += sizeof(struct ar9170_rx_head);
775 phy = (void *)(buf + mpdu_len);
776 break;
777
778 default:
779 BUG_ON(1);
780 break;
781 }
782
783 if (unlikely(mpdu_len < FCS_LEN))
784 return ;
785
786 memset(&status, 0, sizeof(status));
787 if (unlikely(ar9170_rx_mac_status(ar, head, mac, &status)))
788 return ;
789
790 if (phy)
791 ar9170_rx_phy_status(ar, phy, &status);
792
793 skb = ar9170_rx_copy_data(buf, mpdu_len);
794 if (likely(skb))
795 ieee80211_rx_irqsafe(ar->hw, skb, &status);
796 }
797
798 void ar9170_rx(struct ar9170 *ar, struct sk_buff *skb)
799 {
800 unsigned int i, tlen, resplen, wlen = 0, clen = 0;
801 u8 *tbuf, *respbuf;
802
803 tbuf = skb->data;
804 tlen = skb->len;
805
806 while (tlen >= 4) {
807 clen = tbuf[1] << 8 | tbuf[0];
808 wlen = ALIGN(clen, 4);
809
810 /* check if this is stream has a valid tag.*/
811 if (tbuf[2] != 0 || tbuf[3] != 0x4e) {
812 /*
813 * TODO: handle the highly unlikely event that the
814 * corrupted stream has the TAG at the right position.
815 */
816
817 /* check if the frame can be repaired. */
818 if (!ar->rx_failover_missing) {
819 /* this is no "short read". */
820 if (ar9170_nag_limiter(ar)) {
821 printk(KERN_ERR "%s: missing tag!\n",
822 wiphy_name(ar->hw->wiphy));
823 goto err_telluser;
824 } else
825 goto err_silent;
826 }
827
828 if (ar->rx_failover_missing > tlen) {
829 if (ar9170_nag_limiter(ar)) {
830 printk(KERN_ERR "%s: possible multi "
831 "stream corruption!\n",
832 wiphy_name(ar->hw->wiphy));
833 goto err_telluser;
834 } else
835 goto err_silent;
836 }
837
838 memcpy(skb_put(ar->rx_failover, tlen), tbuf, tlen);
839 ar->rx_failover_missing -= tlen;
840
841 if (ar->rx_failover_missing <= 0) {
842 /*
843 * nested ar9170_rx call!
844 * termination is guranteed, even when the
845 * combined frame also have a element with
846 * a bad tag.
847 */
848
849 ar->rx_failover_missing = 0;
850 ar9170_rx(ar, ar->rx_failover);
851
852 skb_reset_tail_pointer(ar->rx_failover);
853 skb_trim(ar->rx_failover, 0);
854 }
855
856 return ;
857 }
858
859 /* check if stream is clipped */
860 if (wlen > tlen - 4) {
861 if (ar->rx_failover_missing) {
862 /* TODO: handle double stream corruption. */
863 if (ar9170_nag_limiter(ar)) {
864 printk(KERN_ERR "%s: double rx stream "
865 "corruption!\n",
866 wiphy_name(ar->hw->wiphy));
867 goto err_telluser;
868 } else
869 goto err_silent;
870 }
871
872 /*
873 * save incomplete data set.
874 * the firmware will resend the missing bits when
875 * the rx - descriptor comes round again.
876 */
877
878 memcpy(skb_put(ar->rx_failover, tlen), tbuf, tlen);
879 ar->rx_failover_missing = clen - tlen;
880 return ;
881 }
882 resplen = clen;
883 respbuf = tbuf + 4;
884 tbuf += wlen + 4;
885 tlen -= wlen + 4;
886
887 i = 0;
888
889 /* weird thing, but this is the same in the original driver */
890 while (resplen > 2 && i < 12 &&
891 respbuf[0] == 0xff && respbuf[1] == 0xff) {
892 i += 2;
893 resplen -= 2;
894 respbuf += 2;
895 }
896
897 if (resplen < 4)
898 continue;
899
900 /* found the 6 * 0xffff marker? */
901 if (i == 12)
902 ar9170_handle_command_response(ar, respbuf, resplen);
903 else
904 ar9170_handle_mpdu(ar, respbuf, clen);
905 }
906
907 if (tlen) {
908 if (net_ratelimit())
909 printk(KERN_ERR "%s: %d bytes of unprocessed "
910 "data left in rx stream!\n",
911 wiphy_name(ar->hw->wiphy), tlen);
912
913 goto err_telluser;
914 }
915
916 return ;
917
918 err_telluser:
919 printk(KERN_ERR "%s: damaged RX stream data [want:%d, "
920 "data:%d, rx:%d, pending:%d ]\n",
921 wiphy_name(ar->hw->wiphy), clen, wlen, tlen,
922 ar->rx_failover_missing);
923
924 if (ar->rx_failover_missing)
925 print_hex_dump_bytes("rxbuf:", DUMP_PREFIX_OFFSET,
926 ar->rx_failover->data,
927 ar->rx_failover->len);
928
929 print_hex_dump_bytes("stream:", DUMP_PREFIX_OFFSET,
930 skb->data, skb->len);
931
932 printk(KERN_ERR "%s: please check your hardware and cables, if "
933 "you see this message frequently.\n",
934 wiphy_name(ar->hw->wiphy));
935
936 err_silent:
937 if (ar->rx_failover_missing) {
938 skb_reset_tail_pointer(ar->rx_failover);
939 skb_trim(ar->rx_failover, 0);
940 ar->rx_failover_missing = 0;
941 }
942 }
943
944 #define AR9170_FILL_QUEUE(queue, ai_fs, cwmin, cwmax, _txop) \
945 do { \
946 queue.aifs = ai_fs; \
947 queue.cw_min = cwmin; \
948 queue.cw_max = cwmax; \
949 queue.txop = _txop; \
950 } while (0)
951
952 static int ar9170_op_start(struct ieee80211_hw *hw)
953 {
954 struct ar9170 *ar = hw->priv;
955 int err, i;
956
957 mutex_lock(&ar->mutex);
958
959 ar->filter_changed = 0;
960
961 /* reinitialize queues statistics */
962 memset(&ar->tx_stats, 0, sizeof(ar->tx_stats));
963 for (i = 0; i < ARRAY_SIZE(ar->tx_stats); i++)
964 ar->tx_stats[i].limit = 8;
965
966 /* reset QoS defaults */
967 AR9170_FILL_QUEUE(ar->edcf[0], 3, 15, 1023, 0); /* BEST EFFORT*/
968 AR9170_FILL_QUEUE(ar->edcf[1], 7, 15, 1023, 0); /* BACKGROUND */
969 AR9170_FILL_QUEUE(ar->edcf[2], 2, 7, 15, 94); /* VIDEO */
970 AR9170_FILL_QUEUE(ar->edcf[3], 2, 3, 7, 47); /* VOICE */
971 AR9170_FILL_QUEUE(ar->edcf[4], 2, 3, 7, 0); /* SPECIAL */
972
973 ar->bad_hw_nagger = jiffies;
974
975 err = ar->open(ar);
976 if (err)
977 goto out;
978
979 err = ar9170_init_mac(ar);
980 if (err)
981 goto out;
982
983 err = ar9170_set_qos(ar);
984 if (err)
985 goto out;
986
987 err = ar9170_init_phy(ar, IEEE80211_BAND_2GHZ);
988 if (err)
989 goto out;
990
991 err = ar9170_init_rf(ar);
992 if (err)
993 goto out;
994
995 /* start DMA */
996 err = ar9170_write_reg(ar, 0x1c3d30, 0x100);
997 if (err)
998 goto out;
999
1000 ar->state = AR9170_STARTED;
1001
1002 out:
1003 mutex_unlock(&ar->mutex);
1004 return err;
1005 }
1006
1007 static void ar9170_op_stop(struct ieee80211_hw *hw)
1008 {
1009 struct ar9170 *ar = hw->priv;
1010
1011 if (IS_STARTED(ar))
1012 ar->state = AR9170_IDLE;
1013
1014 flush_workqueue(ar->hw->workqueue);
1015
1016 mutex_lock(&ar->mutex);
1017 cancel_delayed_work_sync(&ar->tx_status_janitor);
1018 cancel_work_sync(&ar->filter_config_work);
1019 cancel_work_sync(&ar->beacon_work);
1020 skb_queue_purge(&ar->global_tx_status_waste);
1021 skb_queue_purge(&ar->global_tx_status);
1022
1023 if (IS_ACCEPTING_CMD(ar)) {
1024 ar9170_set_leds_state(ar, 0);
1025
1026 /* stop DMA */
1027 ar9170_write_reg(ar, 0x1c3d30, 0);
1028 ar->stop(ar);
1029 }
1030
1031 mutex_unlock(&ar->mutex);
1032 }
1033
1034 int ar9170_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
1035 {
1036 struct ar9170 *ar = hw->priv;
1037 struct ieee80211_hdr *hdr;
1038 struct ar9170_tx_control *txc;
1039 struct ieee80211_tx_info *info;
1040 struct ieee80211_rate *rate = NULL;
1041 struct ieee80211_tx_rate *txrate;
1042 unsigned int queue = skb_get_queue_mapping(skb);
1043 unsigned long flags = 0;
1044 struct ar9170_sta_info *sta_info = NULL;
1045 u32 power, chains;
1046 u16 keytype = 0;
1047 u16 len, icv = 0;
1048 int err;
1049 bool tx_status;
1050
1051 if (unlikely(!IS_STARTED(ar)))
1052 goto err_free;
1053
1054 hdr = (void *)skb->data;
1055 info = IEEE80211_SKB_CB(skb);
1056 len = skb->len;
1057
1058 spin_lock_irqsave(&ar->tx_stats_lock, flags);
1059 if (ar->tx_stats[queue].limit < ar->tx_stats[queue].len) {
1060 spin_unlock_irqrestore(&ar->tx_stats_lock, flags);
1061 return NETDEV_TX_OK;
1062 }
1063
1064 ar->tx_stats[queue].len++;
1065 ar->tx_stats[queue].count++;
1066 if (ar->tx_stats[queue].limit == ar->tx_stats[queue].len)
1067 ieee80211_stop_queue(hw, queue);
1068
1069 spin_unlock_irqrestore(&ar->tx_stats_lock, flags);
1070
1071 txc = (void *)skb_push(skb, sizeof(*txc));
1072
1073 tx_status = (((info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE) != 0) ||
1074 ((info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS) != 0));
1075
1076 if (info->control.hw_key) {
1077 icv = info->control.hw_key->icv_len;
1078
1079 switch (info->control.hw_key->alg) {
1080 case ALG_WEP:
1081 keytype = AR9170_TX_MAC_ENCR_RC4;
1082 break;
1083 case ALG_TKIP:
1084 keytype = AR9170_TX_MAC_ENCR_RC4;
1085 break;
1086 case ALG_CCMP:
1087 keytype = AR9170_TX_MAC_ENCR_AES;
1088 break;
1089 default:
1090 WARN_ON(1);
1091 goto err_dequeue;
1092 }
1093 }
1094
1095 /* Length */
1096 txc->length = cpu_to_le16(len + icv + 4);
1097
1098 txc->mac_control = cpu_to_le16(AR9170_TX_MAC_HW_DURATION |
1099 AR9170_TX_MAC_BACKOFF);
1100 txc->mac_control |= cpu_to_le16(ar9170_qos_hwmap[queue] <<
1101 AR9170_TX_MAC_QOS_SHIFT);
1102 txc->mac_control |= cpu_to_le16(keytype);
1103 txc->phy_control = cpu_to_le32(0);
1104
1105 if (info->flags & IEEE80211_TX_CTL_NO_ACK)
1106 txc->mac_control |= cpu_to_le16(AR9170_TX_MAC_NO_ACK);
1107
1108 if (info->flags & IEEE80211_TX_CTL_AMPDU)
1109 txc->mac_control |= cpu_to_le16(AR9170_TX_MAC_AGGR);
1110
1111 txrate = &info->control.rates[0];
1112
1113 if (txrate->flags & IEEE80211_TX_RC_USE_CTS_PROTECT)
1114 txc->mac_control |= cpu_to_le16(AR9170_TX_MAC_PROT_CTS);
1115 else if (txrate->flags & IEEE80211_TX_RC_USE_RTS_CTS)
1116 txc->mac_control |= cpu_to_le16(AR9170_TX_MAC_PROT_RTS);
1117
1118 if (txrate->flags & IEEE80211_TX_RC_GREEN_FIELD)
1119 txc->phy_control |= cpu_to_le32(AR9170_TX_PHY_GREENFIELD);
1120
1121 if (txrate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
1122 txc->phy_control |= cpu_to_le32(AR9170_TX_PHY_SHORT_PREAMBLE);
1123
1124 if (txrate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
1125 txc->phy_control |= cpu_to_le32(AR9170_TX_PHY_BW_40MHZ);
1126 /* this works because 40 MHz is 2 and dup is 3 */
1127 if (txrate->flags & IEEE80211_TX_RC_DUP_DATA)
1128 txc->phy_control |= cpu_to_le32(AR9170_TX_PHY_BW_40MHZ_DUP);
1129
1130 if (txrate->flags & IEEE80211_TX_RC_SHORT_GI)
1131 txc->phy_control |= cpu_to_le32(AR9170_TX_PHY_SHORT_GI);
1132
1133 if (txrate->flags & IEEE80211_TX_RC_MCS) {
1134 u32 r = txrate->idx;
1135 u8 *txpower;
1136
1137 r <<= AR9170_TX_PHY_MCS_SHIFT;
1138 if (WARN_ON(r & ~AR9170_TX_PHY_MCS_MASK))
1139 goto err_dequeue;
1140 txc->phy_control |= cpu_to_le32(r & AR9170_TX_PHY_MCS_MASK);
1141 txc->phy_control |= cpu_to_le32(AR9170_TX_PHY_MOD_HT);
1142
1143 if (txrate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH) {
1144 if (info->band == IEEE80211_BAND_5GHZ)
1145 txpower = ar->power_5G_ht40;
1146 else
1147 txpower = ar->power_2G_ht40;
1148 } else {
1149 if (info->band == IEEE80211_BAND_5GHZ)
1150 txpower = ar->power_5G_ht20;
1151 else
1152 txpower = ar->power_2G_ht20;
1153 }
1154
1155 power = txpower[(txrate->idx) & 7];
1156 } else {
1157 u8 *txpower;
1158 u32 mod;
1159 u32 phyrate;
1160 u8 idx = txrate->idx;
1161
1162 if (info->band != IEEE80211_BAND_2GHZ) {
1163 idx += 4;
1164 txpower = ar->power_5G_leg;
1165 mod = AR9170_TX_PHY_MOD_OFDM;
1166 } else {
1167 if (idx < 4) {
1168 txpower = ar->power_2G_cck;
1169 mod = AR9170_TX_PHY_MOD_CCK;
1170 } else {
1171 mod = AR9170_TX_PHY_MOD_OFDM;
1172 txpower = ar->power_2G_ofdm;
1173 }
1174 }
1175
1176 rate = &__ar9170_ratetable[idx];
1177
1178 phyrate = rate->hw_value & 0xF;
1179 power = txpower[(rate->hw_value & 0x30) >> 4];
1180 phyrate <<= AR9170_TX_PHY_MCS_SHIFT;
1181
1182 txc->phy_control |= cpu_to_le32(mod);
1183 txc->phy_control |= cpu_to_le32(phyrate);
1184 }
1185
1186 power <<= AR9170_TX_PHY_TX_PWR_SHIFT;
1187 power &= AR9170_TX_PHY_TX_PWR_MASK;
1188 txc->phy_control |= cpu_to_le32(power);
1189
1190 /* set TX chains */
1191 if (ar->eeprom.tx_mask == 1) {
1192 chains = AR9170_TX_PHY_TXCHAIN_1;
1193 } else {
1194 chains = AR9170_TX_PHY_TXCHAIN_2;
1195
1196 /* >= 36M legacy OFDM - use only one chain */
1197 if (rate && rate->bitrate >= 360)
1198 chains = AR9170_TX_PHY_TXCHAIN_1;
1199 }
1200 txc->phy_control |= cpu_to_le32(chains << AR9170_TX_PHY_TXCHAIN_SHIFT);
1201
1202 if (tx_status) {
1203 txc->mac_control |= cpu_to_le16(AR9170_TX_MAC_RATE_PROBE);
1204 /*
1205 * WARNING:
1206 * Putting the QoS queue bits into an unexplored territory is
1207 * certainly not elegant.
1208 *
1209 * In my defense: This idea provides a reasonable way to
1210 * smuggle valuable information to the tx_status callback.
1211 * Also, the idea behind this bit-abuse came straight from
1212 * the original driver code.
1213 */
1214
1215 txc->phy_control |=
1216 cpu_to_le32(queue << AR9170_TX_PHY_QOS_SHIFT);
1217
1218 if (info->control.sta) {
1219 sta_info = (void *) info->control.sta->drv_priv;
1220 skb_queue_tail(&sta_info->tx_status[queue], skb);
1221 } else {
1222 skb_queue_tail(&ar->global_tx_status, skb);
1223
1224 queue_delayed_work(ar->hw->workqueue,
1225 &ar->tx_status_janitor,
1226 msecs_to_jiffies(100));
1227 }
1228 }
1229
1230 err = ar->tx(ar, skb, tx_status, 0);
1231 if (unlikely(tx_status && err)) {
1232 if (info->control.sta)
1233 skb_unlink(skb, &sta_info->tx_status[queue]);
1234 else
1235 skb_unlink(skb, &ar->global_tx_status);
1236 }
1237
1238 return NETDEV_TX_OK;
1239
1240 err_dequeue:
1241 spin_lock_irqsave(&ar->tx_stats_lock, flags);
1242 ar->tx_stats[queue].len--;
1243 ar->tx_stats[queue].count--;
1244 spin_unlock_irqrestore(&ar->tx_stats_lock, flags);
1245
1246 err_free:
1247 dev_kfree_skb(skb);
1248 return NETDEV_TX_OK;
1249 }
1250
1251 static int ar9170_op_add_interface(struct ieee80211_hw *hw,
1252 struct ieee80211_if_init_conf *conf)
1253 {
1254 struct ar9170 *ar = hw->priv;
1255 int err = 0;
1256
1257 mutex_lock(&ar->mutex);
1258
1259 if (ar->vif) {
1260 err = -EBUSY;
1261 goto unlock;
1262 }
1263
1264 ar->vif = conf->vif;
1265 memcpy(ar->mac_addr, conf->mac_addr, ETH_ALEN);
1266
1267 if (modparam_nohwcrypt || (ar->vif->type != NL80211_IFTYPE_STATION)) {
1268 ar->rx_software_decryption = true;
1269 ar->disable_offload = true;
1270 }
1271
1272 ar->cur_filter = 0;
1273 ar->want_filter = AR9170_MAC_REG_FTF_DEFAULTS;
1274 err = ar9170_update_frame_filter(ar);
1275 if (err)
1276 goto unlock;
1277
1278 err = ar9170_set_operating_mode(ar);
1279
1280 unlock:
1281 mutex_unlock(&ar->mutex);
1282 return err;
1283 }
1284
1285 static void ar9170_op_remove_interface(struct ieee80211_hw *hw,
1286 struct ieee80211_if_init_conf *conf)
1287 {
1288 struct ar9170 *ar = hw->priv;
1289
1290 mutex_lock(&ar->mutex);
1291 ar->vif = NULL;
1292 ar->want_filter = 0;
1293 ar9170_update_frame_filter(ar);
1294 ar9170_set_beacon_timers(ar);
1295 dev_kfree_skb(ar->beacon);
1296 ar->beacon = NULL;
1297 ar->sniffer_enabled = false;
1298 ar->rx_software_decryption = false;
1299 ar9170_set_operating_mode(ar);
1300 mutex_unlock(&ar->mutex);
1301 }
1302
1303 static int ar9170_op_config(struct ieee80211_hw *hw, u32 changed)
1304 {
1305 struct ar9170 *ar = hw->priv;
1306 int err = 0;
1307
1308 mutex_lock(&ar->mutex);
1309
1310 if (changed & IEEE80211_CONF_CHANGE_RADIO_ENABLED) {
1311 /* TODO */
1312 err = 0;
1313 }
1314
1315 if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) {
1316 /* TODO */
1317 err = 0;
1318 }
1319
1320 if (changed & IEEE80211_CONF_CHANGE_PS) {
1321 /* TODO */
1322 err = 0;
1323 }
1324
1325 if (changed & IEEE80211_CONF_CHANGE_POWER) {
1326 /* TODO */
1327 err = 0;
1328 }
1329
1330 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
1331 /*
1332 * is it long_frame_max_tx_count or short_frame_max_tx_count?
1333 */
1334
1335 err = ar9170_set_hwretry_limit(ar,
1336 ar->hw->conf.long_frame_max_tx_count);
1337 if (err)
1338 goto out;
1339 }
1340
1341 if (changed & BSS_CHANGED_BEACON_INT) {
1342 err = ar9170_set_beacon_timers(ar);
1343 if (err)
1344 goto out;
1345 }
1346
1347 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
1348
1349 /* adjust slot time for 5 GHz */
1350 err = ar9170_set_slot_time(ar);
1351 if (err)
1352 goto out;
1353
1354 err = ar9170_set_dyn_sifs_ack(ar);
1355 if (err)
1356 goto out;
1357
1358 err = ar9170_set_channel(ar, hw->conf.channel,
1359 AR9170_RFI_NONE,
1360 nl80211_to_ar9170(hw->conf.channel_type));
1361 if (err)
1362 goto out;
1363 }
1364
1365 out:
1366 mutex_unlock(&ar->mutex);
1367 return err;
1368 }
1369
1370 static void ar9170_set_filters(struct work_struct *work)
1371 {
1372 struct ar9170 *ar = container_of(work, struct ar9170,
1373 filter_config_work);
1374 int err;
1375
1376 if (unlikely(!IS_STARTED(ar)))
1377 return ;
1378
1379 mutex_lock(&ar->mutex);
1380 if (test_and_clear_bit(AR9170_FILTER_CHANGED_MODE,
1381 &ar->filter_changed)) {
1382 err = ar9170_set_operating_mode(ar);
1383 if (err)
1384 goto unlock;
1385 }
1386
1387 if (test_and_clear_bit(AR9170_FILTER_CHANGED_MULTICAST,
1388 &ar->filter_changed)) {
1389 err = ar9170_update_multicast(ar);
1390 if (err)
1391 goto unlock;
1392 }
1393
1394 if (test_and_clear_bit(AR9170_FILTER_CHANGED_FRAMEFILTER,
1395 &ar->filter_changed)) {
1396 err = ar9170_update_frame_filter(ar);
1397 if (err)
1398 goto unlock;
1399 }
1400
1401 unlock:
1402 mutex_unlock(&ar->mutex);
1403 }
1404
1405 static void ar9170_op_configure_filter(struct ieee80211_hw *hw,
1406 unsigned int changed_flags,
1407 unsigned int *new_flags,
1408 int mc_count, struct dev_mc_list *mclist)
1409 {
1410 struct ar9170 *ar = hw->priv;
1411
1412 /* mask supported flags */
1413 *new_flags &= FIF_ALLMULTI | FIF_CONTROL | FIF_BCN_PRBRESP_PROMISC |
1414 FIF_PROMISC_IN_BSS | FIF_FCSFAIL | FIF_PLCPFAIL;
1415 ar->filter_state = *new_flags;
1416 /*
1417 * We can support more by setting the sniffer bit and
1418 * then checking the error flags, later.
1419 */
1420
1421 if (changed_flags & FIF_ALLMULTI) {
1422 if (*new_flags & FIF_ALLMULTI) {
1423 ar->want_mc_hash = ~0ULL;
1424 } else {
1425 u64 mchash;
1426 int i;
1427
1428 /* always get broadcast frames */
1429 mchash = 1ULL << (0xff >> 2);
1430
1431 for (i = 0; i < mc_count; i++) {
1432 if (WARN_ON(!mclist))
1433 break;
1434 mchash |= 1ULL << (mclist->dmi_addr[5] >> 2);
1435 mclist = mclist->next;
1436 }
1437 ar->want_mc_hash = mchash;
1438 }
1439 set_bit(AR9170_FILTER_CHANGED_MULTICAST, &ar->filter_changed);
1440 }
1441
1442 if (changed_flags & FIF_CONTROL) {
1443 u32 filter = AR9170_MAC_REG_FTF_PSPOLL |
1444 AR9170_MAC_REG_FTF_RTS |
1445 AR9170_MAC_REG_FTF_CTS |
1446 AR9170_MAC_REG_FTF_ACK |
1447 AR9170_MAC_REG_FTF_CFE |
1448 AR9170_MAC_REG_FTF_CFE_ACK;
1449
1450 if (*new_flags & FIF_CONTROL)
1451 ar->want_filter = ar->cur_filter | filter;
1452 else
1453 ar->want_filter = ar->cur_filter & ~filter;
1454
1455 set_bit(AR9170_FILTER_CHANGED_FRAMEFILTER,
1456 &ar->filter_changed);
1457 }
1458
1459 if (changed_flags & FIF_PROMISC_IN_BSS) {
1460 ar->sniffer_enabled = ((*new_flags) & FIF_PROMISC_IN_BSS) != 0;
1461 set_bit(AR9170_FILTER_CHANGED_MODE,
1462 &ar->filter_changed);
1463 }
1464
1465 if (likely(IS_STARTED(ar)))
1466 queue_work(ar->hw->workqueue, &ar->filter_config_work);
1467 }
1468
1469 static void ar9170_op_bss_info_changed(struct ieee80211_hw *hw,
1470 struct ieee80211_vif *vif,
1471 struct ieee80211_bss_conf *bss_conf,
1472 u32 changed)
1473 {
1474 struct ar9170 *ar = hw->priv;
1475 int err = 0;
1476
1477 mutex_lock(&ar->mutex);
1478
1479 if (changed & BSS_CHANGED_BSSID) {
1480 memcpy(ar->bssid, bss_conf->bssid, ETH_ALEN);
1481 err = ar9170_set_operating_mode(ar);
1482 if (err)
1483 goto out;
1484 }
1485
1486 if (changed & (BSS_CHANGED_BEACON | BSS_CHANGED_BEACON_ENABLED)) {
1487 err = ar9170_update_beacon(ar);
1488 if (err)
1489 goto out;
1490
1491 err = ar9170_set_beacon_timers(ar);
1492 if (err)
1493 goto out;
1494 }
1495
1496 if (changed & BSS_CHANGED_ASSOC) {
1497 ar->state = bss_conf->assoc ? AR9170_ASSOCIATED : ar->state;
1498
1499 #ifndef CONFIG_AR9170_LEDS
1500 /* enable assoc LED. */
1501 err = ar9170_set_leds_state(ar, bss_conf->assoc ? 2 : 0);
1502 #endif /* CONFIG_AR9170_LEDS */
1503 }
1504
1505 if (changed & BSS_CHANGED_BEACON_INT) {
1506 err = ar9170_set_beacon_timers(ar);
1507 if (err)
1508 goto out;
1509 }
1510
1511 if (changed & BSS_CHANGED_HT) {
1512 /* TODO */
1513 err = 0;
1514 }
1515
1516 if (changed & BSS_CHANGED_ERP_SLOT) {
1517 err = ar9170_set_slot_time(ar);
1518 if (err)
1519 goto out;
1520 }
1521
1522 if (changed & BSS_CHANGED_BASIC_RATES) {
1523 err = ar9170_set_basic_rates(ar);
1524 if (err)
1525 goto out;
1526 }
1527
1528 out:
1529 mutex_unlock(&ar->mutex);
1530 }
1531
1532 static u64 ar9170_op_get_tsf(struct ieee80211_hw *hw)
1533 {
1534 struct ar9170 *ar = hw->priv;
1535 int err;
1536 u32 tsf_low;
1537 u32 tsf_high;
1538 u64 tsf;
1539
1540 mutex_lock(&ar->mutex);
1541 err = ar9170_read_reg(ar, AR9170_MAC_REG_TSF_L, &tsf_low);
1542 if (!err)
1543 err = ar9170_read_reg(ar, AR9170_MAC_REG_TSF_H, &tsf_high);
1544 mutex_unlock(&ar->mutex);
1545
1546 if (WARN_ON(err))
1547 return 0;
1548
1549 tsf = tsf_high;
1550 tsf = (tsf << 32) | tsf_low;
1551 return tsf;
1552 }
1553
1554 static int ar9170_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
1555 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
1556 struct ieee80211_key_conf *key)
1557 {
1558 struct ar9170 *ar = hw->priv;
1559 int err = 0, i;
1560 u8 ktype;
1561
1562 if ((!ar->vif) || (ar->disable_offload))
1563 return -EOPNOTSUPP;
1564
1565 switch (key->alg) {
1566 case ALG_WEP:
1567 if (key->keylen == WLAN_KEY_LEN_WEP40)
1568 ktype = AR9170_ENC_ALG_WEP64;
1569 else
1570 ktype = AR9170_ENC_ALG_WEP128;
1571 break;
1572 case ALG_TKIP:
1573 ktype = AR9170_ENC_ALG_TKIP;
1574 break;
1575 case ALG_CCMP:
1576 ktype = AR9170_ENC_ALG_AESCCMP;
1577 break;
1578 default:
1579 return -EOPNOTSUPP;
1580 }
1581
1582 mutex_lock(&ar->mutex);
1583 if (cmd == SET_KEY) {
1584 if (unlikely(!IS_STARTED(ar))) {
1585 err = -EOPNOTSUPP;
1586 goto out;
1587 }
1588
1589 /* group keys need all-zeroes address */
1590 if (!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE))
1591 sta = NULL;
1592
1593 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) {
1594 for (i = 0; i < 64; i++)
1595 if (!(ar->usedkeys & BIT(i)))
1596 break;
1597 if (i == 64) {
1598 ar->rx_software_decryption = true;
1599 ar9170_set_operating_mode(ar);
1600 err = -ENOSPC;
1601 goto out;
1602 }
1603 } else {
1604 i = 64 + key->keyidx;
1605 }
1606
1607 key->hw_key_idx = i;
1608
1609 err = ar9170_upload_key(ar, i, sta ? sta->addr : NULL, ktype, 0,
1610 key->key, min_t(u8, 16, key->keylen));
1611 if (err)
1612 goto out;
1613
1614 if (key->alg == ALG_TKIP) {
1615 err = ar9170_upload_key(ar, i, sta ? sta->addr : NULL,
1616 ktype, 1, key->key + 16, 16);
1617 if (err)
1618 goto out;
1619
1620 /*
1621 * hardware is not capable generating the MMIC
1622 * for fragmented frames!
1623 */
1624 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1625 }
1626
1627 if (i < 64)
1628 ar->usedkeys |= BIT(i);
1629
1630 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1631 } else {
1632 if (unlikely(!IS_STARTED(ar))) {
1633 /* The device is gone... together with the key ;-) */
1634 err = 0;
1635 goto out;
1636 }
1637
1638 err = ar9170_disable_key(ar, key->hw_key_idx);
1639 if (err)
1640 goto out;
1641
1642 if (key->hw_key_idx < 64) {
1643 ar->usedkeys &= ~BIT(key->hw_key_idx);
1644 } else {
1645 err = ar9170_upload_key(ar, key->hw_key_idx, NULL,
1646 AR9170_ENC_ALG_NONE, 0,
1647 NULL, 0);
1648 if (err)
1649 goto out;
1650
1651 if (key->alg == ALG_TKIP) {
1652 err = ar9170_upload_key(ar, key->hw_key_idx,
1653 NULL,
1654 AR9170_ENC_ALG_NONE, 1,
1655 NULL, 0);
1656 if (err)
1657 goto out;
1658 }
1659
1660 }
1661 }
1662
1663 ar9170_regwrite_begin(ar);
1664 ar9170_regwrite(AR9170_MAC_REG_ROLL_CALL_TBL_L, ar->usedkeys);
1665 ar9170_regwrite(AR9170_MAC_REG_ROLL_CALL_TBL_H, ar->usedkeys >> 32);
1666 ar9170_regwrite_finish();
1667 err = ar9170_regwrite_result();
1668
1669 out:
1670 mutex_unlock(&ar->mutex);
1671
1672 return err;
1673 }
1674
1675 static void ar9170_sta_notify(struct ieee80211_hw *hw,
1676 struct ieee80211_vif *vif,
1677 enum sta_notify_cmd cmd,
1678 struct ieee80211_sta *sta)
1679 {
1680 struct ar9170 *ar = hw->priv;
1681 struct ar9170_sta_info *info = (void *) sta->drv_priv;
1682 struct sk_buff *skb;
1683 unsigned int i;
1684
1685 switch (cmd) {
1686 case STA_NOTIFY_ADD:
1687 for (i = 0; i < ar->hw->queues; i++)
1688 skb_queue_head_init(&info->tx_status[i]);
1689 break;
1690
1691 case STA_NOTIFY_REMOVE:
1692
1693 /*
1694 * transfer all outstanding frames that need a tx_status
1695 * reports to the global tx_status queue
1696 */
1697
1698 for (i = 0; i < ar->hw->queues; i++) {
1699 while ((skb = skb_dequeue(&info->tx_status[i]))) {
1700 #ifdef AR9170_QUEUE_DEBUG
1701 printk(KERN_DEBUG "%s: queueing frame in "
1702 "global tx_status queue =>\n",
1703 wiphy_name(ar->hw->wiphy));
1704
1705 ar9170_print_txheader(ar, skb);
1706 #endif /* AR9170_QUEUE_DEBUG */
1707 skb_queue_tail(&ar->global_tx_status, skb);
1708 }
1709 }
1710 queue_delayed_work(ar->hw->workqueue, &ar->tx_status_janitor,
1711 msecs_to_jiffies(100));
1712 break;
1713
1714 default:
1715 break;
1716 }
1717 }
1718
1719 static int ar9170_get_stats(struct ieee80211_hw *hw,
1720 struct ieee80211_low_level_stats *stats)
1721 {
1722 struct ar9170 *ar = hw->priv;
1723 u32 val;
1724 int err;
1725
1726 mutex_lock(&ar->mutex);
1727 err = ar9170_read_reg(ar, AR9170_MAC_REG_TX_RETRY, &val);
1728 ar->stats.dot11ACKFailureCount += val;
1729
1730 memcpy(stats, &ar->stats, sizeof(*stats));
1731 mutex_unlock(&ar->mutex);
1732
1733 return 0;
1734 }
1735
1736 static int ar9170_get_tx_stats(struct ieee80211_hw *hw,
1737 struct ieee80211_tx_queue_stats *tx_stats)
1738 {
1739 struct ar9170 *ar = hw->priv;
1740
1741 spin_lock_bh(&ar->tx_stats_lock);
1742 memcpy(tx_stats, ar->tx_stats, sizeof(tx_stats[0]) * hw->queues);
1743 spin_unlock_bh(&ar->tx_stats_lock);
1744
1745 return 0;
1746 }
1747
1748 static int ar9170_conf_tx(struct ieee80211_hw *hw, u16 queue,
1749 const struct ieee80211_tx_queue_params *param)
1750 {
1751 struct ar9170 *ar = hw->priv;
1752 int ret;
1753
1754 mutex_lock(&ar->mutex);
1755 if ((param) && !(queue > ar->hw->queues)) {
1756 memcpy(&ar->edcf[ar9170_qos_hwmap[queue]],
1757 param, sizeof(*param));
1758
1759 ret = ar9170_set_qos(ar);
1760 } else
1761 ret = -EINVAL;
1762
1763 mutex_unlock(&ar->mutex);
1764 return ret;
1765 }
1766
1767 static int ar9170_ampdu_action(struct ieee80211_hw *hw,
1768 enum ieee80211_ampdu_mlme_action action,
1769 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
1770 {
1771 switch (action) {
1772 case IEEE80211_AMPDU_RX_START:
1773 case IEEE80211_AMPDU_RX_STOP:
1774 /*
1775 * Something goes wrong -- RX locks up
1776 * after a while of receiving aggregated
1777 * frames -- not enabling for now.
1778 */
1779 return -EOPNOTSUPP;
1780 default:
1781 return -EOPNOTSUPP;
1782 }
1783 }
1784
1785 static const struct ieee80211_ops ar9170_ops = {
1786 .start = ar9170_op_start,
1787 .stop = ar9170_op_stop,
1788 .tx = ar9170_op_tx,
1789 .add_interface = ar9170_op_add_interface,
1790 .remove_interface = ar9170_op_remove_interface,
1791 .config = ar9170_op_config,
1792 .configure_filter = ar9170_op_configure_filter,
1793 .conf_tx = ar9170_conf_tx,
1794 .bss_info_changed = ar9170_op_bss_info_changed,
1795 .get_tsf = ar9170_op_get_tsf,
1796 .set_key = ar9170_set_key,
1797 .sta_notify = ar9170_sta_notify,
1798 .get_stats = ar9170_get_stats,
1799 .get_tx_stats = ar9170_get_tx_stats,
1800 .ampdu_action = ar9170_ampdu_action,
1801 };
1802
1803 void *ar9170_alloc(size_t priv_size)
1804 {
1805 struct ieee80211_hw *hw;
1806 struct ar9170 *ar;
1807 struct sk_buff *skb;
1808 int i;
1809
1810 /*
1811 * this buffer is used for rx stream reconstruction.
1812 * Under heavy load this device (or the transport layer?)
1813 * tends to split the streams into seperate rx descriptors.
1814 */
1815
1816 skb = __dev_alloc_skb(AR9170_MAX_RX_BUFFER_SIZE, GFP_KERNEL);
1817 if (!skb)
1818 goto err_nomem;
1819
1820 hw = ieee80211_alloc_hw(priv_size, &ar9170_ops);
1821 if (!hw)
1822 goto err_nomem;
1823
1824 ar = hw->priv;
1825 ar->hw = hw;
1826 ar->rx_failover = skb;
1827
1828 mutex_init(&ar->mutex);
1829 spin_lock_init(&ar->cmdlock);
1830 spin_lock_init(&ar->tx_stats_lock);
1831 skb_queue_head_init(&ar->global_tx_status);
1832 skb_queue_head_init(&ar->global_tx_status_waste);
1833 ar9170_rx_reset_rx_mpdu(ar);
1834 INIT_WORK(&ar->filter_config_work, ar9170_set_filters);
1835 INIT_WORK(&ar->beacon_work, ar9170_new_beacon);
1836 INIT_DELAYED_WORK(&ar->tx_status_janitor, ar9170_tx_status_janitor);
1837
1838 /* all hw supports 2.4 GHz, so set channel to 1 by default */
1839 ar->channel = &ar9170_2ghz_chantable[0];
1840
1841 /* first part of wiphy init */
1842 ar->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1843 BIT(NL80211_IFTYPE_WDS) |
1844 BIT(NL80211_IFTYPE_ADHOC);
1845 ar->hw->flags |= IEEE80211_HW_RX_INCLUDES_FCS |
1846 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
1847 IEEE80211_HW_SIGNAL_DBM |
1848 IEEE80211_HW_NOISE_DBM;
1849
1850 ar->hw->queues = __AR9170_NUM_TXQ;
1851 ar->hw->extra_tx_headroom = 8;
1852 ar->hw->sta_data_size = sizeof(struct ar9170_sta_info);
1853
1854 ar->hw->max_rates = 1;
1855 ar->hw->max_rate_tries = 3;
1856
1857 for (i = 0; i < ARRAY_SIZE(ar->noise); i++)
1858 ar->noise[i] = -95; /* ATH_DEFAULT_NOISE_FLOOR */
1859
1860 return ar;
1861
1862 err_nomem:
1863 kfree_skb(skb);
1864 return ERR_PTR(-ENOMEM);
1865 }
1866
1867 static int ar9170_read_eeprom(struct ar9170 *ar)
1868 {
1869 #define RW 8 /* number of words to read at once */
1870 #define RB (sizeof(u32) * RW)
1871 DECLARE_MAC_BUF(mbuf);
1872 u8 *eeprom = (void *)&ar->eeprom;
1873 u8 *addr = ar->eeprom.mac_address;
1874 __le32 offsets[RW];
1875 int i, j, err, bands = 0;
1876
1877 BUILD_BUG_ON(sizeof(ar->eeprom) & 3);
1878
1879 BUILD_BUG_ON(RB > AR9170_MAX_CMD_LEN - 4);
1880 #ifndef __CHECKER__
1881 /* don't want to handle trailing remains */
1882 BUILD_BUG_ON(sizeof(ar->eeprom) % RB);
1883 #endif
1884
1885 for (i = 0; i < sizeof(ar->eeprom)/RB; i++) {
1886 for (j = 0; j < RW; j++)
1887 offsets[j] = cpu_to_le32(AR9170_EEPROM_START +
1888 RB * i + 4 * j);
1889
1890 err = ar->exec_cmd(ar, AR9170_CMD_RREG,
1891 RB, (u8 *) &offsets,
1892 RB, eeprom + RB * i);
1893 if (err)
1894 return err;
1895 }
1896
1897 #undef RW
1898 #undef RB
1899
1900 if (ar->eeprom.length == cpu_to_le16(0xFFFF))
1901 return -ENODATA;
1902
1903 if (ar->eeprom.operating_flags & AR9170_OPFLAG_2GHZ) {
1904 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &ar9170_band_2GHz;
1905 bands++;
1906 }
1907 if (ar->eeprom.operating_flags & AR9170_OPFLAG_5GHZ) {
1908 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &ar9170_band_5GHz;
1909 bands++;
1910 }
1911 /*
1912 * I measured this, a bandswitch takes roughly
1913 * 135 ms and a frequency switch about 80.
1914 *
1915 * FIXME: measure these values again once EEPROM settings
1916 * are used, that will influence them!
1917 */
1918 if (bands == 2)
1919 ar->hw->channel_change_time = 135 * 1000;
1920 else
1921 ar->hw->channel_change_time = 80 * 1000;
1922
1923 ar->regulatory.current_rd = le16_to_cpu(ar->eeprom.reg_domain[0]);
1924 ar->regulatory.current_rd_ext = le16_to_cpu(ar->eeprom.reg_domain[1]);
1925
1926 /* second part of wiphy init */
1927 SET_IEEE80211_PERM_ADDR(ar->hw, addr);
1928
1929 return bands ? 0 : -EINVAL;
1930 }
1931
1932 static int ar9170_reg_notifier(struct wiphy *wiphy,
1933 struct regulatory_request *request)
1934 {
1935 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1936 struct ar9170 *ar = hw->priv;
1937
1938 return ath_reg_notifier_apply(wiphy, request, &ar->regulatory);
1939 }
1940
1941 int ar9170_register(struct ar9170 *ar, struct device *pdev)
1942 {
1943 int err;
1944
1945 /* try to read EEPROM, init MAC addr */
1946 err = ar9170_read_eeprom(ar);
1947 if (err)
1948 goto err_out;
1949
1950 err = ath_regd_init(&ar->regulatory, ar->hw->wiphy,
1951 ar9170_reg_notifier);
1952 if (err)
1953 goto err_out;
1954
1955 err = ieee80211_register_hw(ar->hw);
1956 if (err)
1957 goto err_out;
1958
1959 if (!ath_is_world_regd(&ar->regulatory))
1960 regulatory_hint(ar->hw->wiphy, ar->regulatory.alpha2);
1961
1962 err = ar9170_init_leds(ar);
1963 if (err)
1964 goto err_unreg;
1965
1966 #ifdef CONFIG_AR9170_LEDS
1967 err = ar9170_register_leds(ar);
1968 if (err)
1969 goto err_unreg;
1970 #endif /* CONFIG_AR9170_LEDS */
1971
1972 dev_info(pdev, "Atheros AR9170 is registered as '%s'\n",
1973 wiphy_name(ar->hw->wiphy));
1974
1975 return err;
1976
1977 err_unreg:
1978 ieee80211_unregister_hw(ar->hw);
1979
1980 err_out:
1981 return err;
1982 }
1983
1984 void ar9170_unregister(struct ar9170 *ar)
1985 {
1986 #ifdef CONFIG_AR9170_LEDS
1987 ar9170_unregister_leds(ar);
1988 #endif /* CONFIG_AR9170_LEDS */
1989
1990 kfree_skb(ar->rx_failover);
1991 ieee80211_unregister_hw(ar->hw);
1992 mutex_destroy(&ar->mutex);
1993 }