blob: 99a9bad3f398cc87238b1d1c37868b7585a795b3 [file] [log] [blame]
Kalle Valo5e3dd152013-06-12 20:52:10 +03001/*
2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include "mac.h"
19
20#include <net/mac80211.h>
21#include <linux/etherdevice.h>
22
Michal Kazior8cd13ca2013-07-16 09:38:54 +020023#include "hif.h"
Kalle Valo5e3dd152013-06-12 20:52:10 +030024#include "core.h"
25#include "debug.h"
26#include "wmi.h"
27#include "htt.h"
28#include "txrx.h"
29
30/**********/
31/* Crypto */
32/**********/
33
34static int ath10k_send_key(struct ath10k_vif *arvif,
35 struct ieee80211_key_conf *key,
36 enum set_key_cmd cmd,
37 const u8 *macaddr)
38{
39 struct wmi_vdev_install_key_arg arg = {
40 .vdev_id = arvif->vdev_id,
41 .key_idx = key->keyidx,
42 .key_len = key->keylen,
43 .key_data = key->key,
44 .macaddr = macaddr,
45 };
46
Michal Kazior548db542013-07-05 16:15:15 +030047 lockdep_assert_held(&arvif->ar->conf_mutex);
48
Kalle Valo5e3dd152013-06-12 20:52:10 +030049 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
50 arg.key_flags = WMI_KEY_PAIRWISE;
51 else
52 arg.key_flags = WMI_KEY_GROUP;
53
54 switch (key->cipher) {
55 case WLAN_CIPHER_SUITE_CCMP:
56 arg.key_cipher = WMI_CIPHER_AES_CCM;
57 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
58 break;
59 case WLAN_CIPHER_SUITE_TKIP:
Kalle Valo5e3dd152013-06-12 20:52:10 +030060 arg.key_cipher = WMI_CIPHER_TKIP;
61 arg.key_txmic_len = 8;
62 arg.key_rxmic_len = 8;
63 break;
64 case WLAN_CIPHER_SUITE_WEP40:
65 case WLAN_CIPHER_SUITE_WEP104:
66 arg.key_cipher = WMI_CIPHER_WEP;
67 /* AP/IBSS mode requires self-key to be groupwise
68 * Otherwise pairwise key must be set */
69 if (memcmp(macaddr, arvif->vif->addr, ETH_ALEN))
70 arg.key_flags = WMI_KEY_PAIRWISE;
71 break;
72 default:
73 ath10k_warn("cipher %d is not supported\n", key->cipher);
74 return -EOPNOTSUPP;
75 }
76
77 if (cmd == DISABLE_KEY) {
78 arg.key_cipher = WMI_CIPHER_NONE;
79 arg.key_data = NULL;
80 }
81
82 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
83}
84
85static int ath10k_install_key(struct ath10k_vif *arvif,
86 struct ieee80211_key_conf *key,
87 enum set_key_cmd cmd,
88 const u8 *macaddr)
89{
90 struct ath10k *ar = arvif->ar;
91 int ret;
92
Michal Kazior548db542013-07-05 16:15:15 +030093 lockdep_assert_held(&ar->conf_mutex);
94
Kalle Valo5e3dd152013-06-12 20:52:10 +030095 INIT_COMPLETION(ar->install_key_done);
96
97 ret = ath10k_send_key(arvif, key, cmd, macaddr);
98 if (ret)
99 return ret;
100
101 ret = wait_for_completion_timeout(&ar->install_key_done, 3*HZ);
102 if (ret == 0)
103 return -ETIMEDOUT;
104
105 return 0;
106}
107
108static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
109 const u8 *addr)
110{
111 struct ath10k *ar = arvif->ar;
112 struct ath10k_peer *peer;
113 int ret;
114 int i;
115
116 lockdep_assert_held(&ar->conf_mutex);
117
118 spin_lock_bh(&ar->data_lock);
119 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
120 spin_unlock_bh(&ar->data_lock);
121
122 if (!peer)
123 return -ENOENT;
124
125 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
126 if (arvif->wep_keys[i] == NULL)
127 continue;
128
129 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
130 addr);
131 if (ret)
132 return ret;
133
134 peer->keys[i] = arvif->wep_keys[i];
135 }
136
137 return 0;
138}
139
140static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
141 const u8 *addr)
142{
143 struct ath10k *ar = arvif->ar;
144 struct ath10k_peer *peer;
145 int first_errno = 0;
146 int ret;
147 int i;
148
149 lockdep_assert_held(&ar->conf_mutex);
150
151 spin_lock_bh(&ar->data_lock);
152 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
153 spin_unlock_bh(&ar->data_lock);
154
155 if (!peer)
156 return -ENOENT;
157
158 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
159 if (peer->keys[i] == NULL)
160 continue;
161
162 ret = ath10k_install_key(arvif, peer->keys[i],
163 DISABLE_KEY, addr);
164 if (ret && first_errno == 0)
165 first_errno = ret;
166
167 if (ret)
168 ath10k_warn("could not remove peer wep key %d (%d)\n",
169 i, ret);
170
171 peer->keys[i] = NULL;
172 }
173
174 return first_errno;
175}
176
177static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
178 struct ieee80211_key_conf *key)
179{
180 struct ath10k *ar = arvif->ar;
181 struct ath10k_peer *peer;
182 u8 addr[ETH_ALEN];
183 int first_errno = 0;
184 int ret;
185 int i;
186
187 lockdep_assert_held(&ar->conf_mutex);
188
189 for (;;) {
190 /* since ath10k_install_key we can't hold data_lock all the
191 * time, so we try to remove the keys incrementally */
192 spin_lock_bh(&ar->data_lock);
193 i = 0;
194 list_for_each_entry(peer, &ar->peers, list) {
195 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
196 if (peer->keys[i] == key) {
197 memcpy(addr, peer->addr, ETH_ALEN);
198 peer->keys[i] = NULL;
199 break;
200 }
201 }
202
203 if (i < ARRAY_SIZE(peer->keys))
204 break;
205 }
206 spin_unlock_bh(&ar->data_lock);
207
208 if (i == ARRAY_SIZE(peer->keys))
209 break;
210
211 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr);
212 if (ret && first_errno == 0)
213 first_errno = ret;
214
215 if (ret)
216 ath10k_warn("could not remove key for %pM\n", addr);
217 }
218
219 return first_errno;
220}
221
222
223/*********************/
224/* General utilities */
225/*********************/
226
227static inline enum wmi_phy_mode
228chan_to_phymode(const struct cfg80211_chan_def *chandef)
229{
230 enum wmi_phy_mode phymode = MODE_UNKNOWN;
231
232 switch (chandef->chan->band) {
233 case IEEE80211_BAND_2GHZ:
234 switch (chandef->width) {
235 case NL80211_CHAN_WIDTH_20_NOHT:
236 phymode = MODE_11G;
237 break;
238 case NL80211_CHAN_WIDTH_20:
239 phymode = MODE_11NG_HT20;
240 break;
241 case NL80211_CHAN_WIDTH_40:
242 phymode = MODE_11NG_HT40;
243 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400244 case NL80211_CHAN_WIDTH_5:
245 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300246 case NL80211_CHAN_WIDTH_80:
247 case NL80211_CHAN_WIDTH_80P80:
248 case NL80211_CHAN_WIDTH_160:
249 phymode = MODE_UNKNOWN;
250 break;
251 }
252 break;
253 case IEEE80211_BAND_5GHZ:
254 switch (chandef->width) {
255 case NL80211_CHAN_WIDTH_20_NOHT:
256 phymode = MODE_11A;
257 break;
258 case NL80211_CHAN_WIDTH_20:
259 phymode = MODE_11NA_HT20;
260 break;
261 case NL80211_CHAN_WIDTH_40:
262 phymode = MODE_11NA_HT40;
263 break;
264 case NL80211_CHAN_WIDTH_80:
265 phymode = MODE_11AC_VHT80;
266 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400267 case NL80211_CHAN_WIDTH_5:
268 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300269 case NL80211_CHAN_WIDTH_80P80:
270 case NL80211_CHAN_WIDTH_160:
271 phymode = MODE_UNKNOWN;
272 break;
273 }
274 break;
275 default:
276 break;
277 }
278
279 WARN_ON(phymode == MODE_UNKNOWN);
280 return phymode;
281}
282
283static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
284{
285/*
286 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
287 * 0 for no restriction
288 * 1 for 1/4 us
289 * 2 for 1/2 us
290 * 3 for 1 us
291 * 4 for 2 us
292 * 5 for 4 us
293 * 6 for 8 us
294 * 7 for 16 us
295 */
296 switch (mpdudensity) {
297 case 0:
298 return 0;
299 case 1:
300 case 2:
301 case 3:
302 /* Our lower layer calculations limit our precision to
303 1 microsecond */
304 return 1;
305 case 4:
306 return 2;
307 case 5:
308 return 4;
309 case 6:
310 return 8;
311 case 7:
312 return 16;
313 default:
314 return 0;
315 }
316}
317
318static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr)
319{
320 int ret;
321
322 lockdep_assert_held(&ar->conf_mutex);
323
324 ret = ath10k_wmi_peer_create(ar, vdev_id, addr);
325 if (ret)
326 return ret;
327
328 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
329 if (ret)
330 return ret;
331
332 return 0;
333}
334
Michal Kazior424121c2013-07-22 14:13:31 +0200335static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
336{
337 if (value != 0xFFFFFFFF)
338 value = min_t(u32, arvif->ar->hw->wiphy->rts_threshold,
339 ATH10K_RTS_MAX);
340
341 return ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id,
342 WMI_VDEV_PARAM_RTS_THRESHOLD,
343 value);
344}
345
346static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
347{
348 if (value != 0xFFFFFFFF)
349 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
350 ATH10K_FRAGMT_THRESHOLD_MIN,
351 ATH10K_FRAGMT_THRESHOLD_MAX);
352
353 return ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id,
354 WMI_VDEV_PARAM_FRAGMENTATION_THRESHOLD,
355 value);
356}
357
Kalle Valo5e3dd152013-06-12 20:52:10 +0300358static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
359{
360 int ret;
361
362 lockdep_assert_held(&ar->conf_mutex);
363
364 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
365 if (ret)
366 return ret;
367
368 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
369 if (ret)
370 return ret;
371
372 return 0;
373}
374
375static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
376{
377 struct ath10k_peer *peer, *tmp;
378
379 lockdep_assert_held(&ar->conf_mutex);
380
381 spin_lock_bh(&ar->data_lock);
382 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
383 if (peer->vdev_id != vdev_id)
384 continue;
385
386 ath10k_warn("removing stale peer %pM from vdev_id %d\n",
387 peer->addr, vdev_id);
388
389 list_del(&peer->list);
390 kfree(peer);
391 }
392 spin_unlock_bh(&ar->data_lock);
393}
394
Michal Kaziora96d7742013-07-16 09:38:56 +0200395static void ath10k_peer_cleanup_all(struct ath10k *ar)
396{
397 struct ath10k_peer *peer, *tmp;
398
399 lockdep_assert_held(&ar->conf_mutex);
400
401 spin_lock_bh(&ar->data_lock);
402 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
403 list_del(&peer->list);
404 kfree(peer);
405 }
406 spin_unlock_bh(&ar->data_lock);
407}
408
Kalle Valo5e3dd152013-06-12 20:52:10 +0300409/************************/
410/* Interface management */
411/************************/
412
413static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
414{
415 int ret;
416
Michal Kazior548db542013-07-05 16:15:15 +0300417 lockdep_assert_held(&ar->conf_mutex);
418
Kalle Valo5e3dd152013-06-12 20:52:10 +0300419 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
420 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
421 if (ret == 0)
422 return -ETIMEDOUT;
423
424 return 0;
425}
426
427static int ath10k_vdev_start(struct ath10k_vif *arvif)
428{
429 struct ath10k *ar = arvif->ar;
430 struct ieee80211_conf *conf = &ar->hw->conf;
431 struct ieee80211_channel *channel = conf->chandef.chan;
432 struct wmi_vdev_start_request_arg arg = {};
433 int ret = 0;
434
435 lockdep_assert_held(&ar->conf_mutex);
436
437 INIT_COMPLETION(ar->vdev_setup_done);
438
439 arg.vdev_id = arvif->vdev_id;
440 arg.dtim_period = arvif->dtim_period;
441 arg.bcn_intval = arvif->beacon_interval;
442
443 arg.channel.freq = channel->center_freq;
444
445 arg.channel.band_center_freq1 = conf->chandef.center_freq1;
446
447 arg.channel.mode = chan_to_phymode(&conf->chandef);
448
449 arg.channel.min_power = channel->max_power * 3;
450 arg.channel.max_power = channel->max_power * 4;
451 arg.channel.max_reg_power = channel->max_reg_power * 4;
452 arg.channel.max_antenna_gain = channel->max_antenna_gain;
453
454 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
455 arg.ssid = arvif->u.ap.ssid;
456 arg.ssid_len = arvif->u.ap.ssid_len;
457 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
458 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
459 arg.ssid = arvif->vif->bss_conf.ssid;
460 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
461 }
462
Kalle Valo38a1d472013-09-08 17:56:14 +0300463 ath10k_dbg(ATH10K_DBG_MAC,
464 "mac vdev %d start center_freq %d phymode %s\n",
465 arg.vdev_id, arg.channel.freq,
466 ath10k_wmi_phymode_str(arg.channel.mode));
467
Kalle Valo5e3dd152013-06-12 20:52:10 +0300468 ret = ath10k_wmi_vdev_start(ar, &arg);
469 if (ret) {
470 ath10k_warn("WMI vdev start failed: ret %d\n", ret);
471 return ret;
472 }
473
474 ret = ath10k_vdev_setup_sync(ar);
475 if (ret) {
476 ath10k_warn("vdev setup failed %d\n", ret);
477 return ret;
478 }
479
480 return ret;
481}
482
483static int ath10k_vdev_stop(struct ath10k_vif *arvif)
484{
485 struct ath10k *ar = arvif->ar;
486 int ret;
487
488 lockdep_assert_held(&ar->conf_mutex);
489
490 INIT_COMPLETION(ar->vdev_setup_done);
491
492 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
493 if (ret) {
494 ath10k_warn("WMI vdev stop failed: ret %d\n", ret);
495 return ret;
496 }
497
498 ret = ath10k_vdev_setup_sync(ar);
499 if (ret) {
500 ath10k_warn("vdev setup failed %d\n", ret);
501 return ret;
502 }
503
504 return ret;
505}
506
507static int ath10k_monitor_start(struct ath10k *ar, int vdev_id)
508{
509 struct ieee80211_channel *channel = ar->hw->conf.chandef.chan;
510 struct wmi_vdev_start_request_arg arg = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +0300511 int ret = 0;
512
513 lockdep_assert_held(&ar->conf_mutex);
514
Kalle Valo5e3dd152013-06-12 20:52:10 +0300515 arg.vdev_id = vdev_id;
516 arg.channel.freq = channel->center_freq;
517 arg.channel.band_center_freq1 = ar->hw->conf.chandef.center_freq1;
518
519 /* TODO setup this dynamically, what in case we
520 don't have any vifs? */
521 arg.channel.mode = chan_to_phymode(&ar->hw->conf.chandef);
522
523 arg.channel.min_power = channel->max_power * 3;
524 arg.channel.max_power = channel->max_power * 4;
525 arg.channel.max_reg_power = channel->max_reg_power * 4;
526 arg.channel.max_antenna_gain = channel->max_antenna_gain;
527
528 ret = ath10k_wmi_vdev_start(ar, &arg);
529 if (ret) {
530 ath10k_warn("Monitor vdev start failed: ret %d\n", ret);
531 return ret;
532 }
533
534 ret = ath10k_vdev_setup_sync(ar);
535 if (ret) {
536 ath10k_warn("Monitor vdev setup failed %d\n", ret);
537 return ret;
538 }
539
540 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
541 if (ret) {
542 ath10k_warn("Monitor vdev up failed: %d\n", ret);
543 goto vdev_stop;
544 }
545
546 ar->monitor_vdev_id = vdev_id;
547 ar->monitor_enabled = true;
548
549 return 0;
550
551vdev_stop:
552 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
553 if (ret)
554 ath10k_warn("Monitor vdev stop failed: %d\n", ret);
555
556 return ret;
557}
558
559static int ath10k_monitor_stop(struct ath10k *ar)
560{
561 int ret = 0;
562
563 lockdep_assert_held(&ar->conf_mutex);
564
565 /* For some reasons, ath10k_wmi_vdev_down() here couse
566 * often ath10k_wmi_vdev_stop() to fail. Next we could
567 * not run monitor vdev and driver reload
568 * required. Don't see such problems we skip
569 * ath10k_wmi_vdev_down() here.
570 */
571
572 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
573 if (ret)
574 ath10k_warn("Monitor vdev stop failed: %d\n", ret);
575
576 ret = ath10k_vdev_setup_sync(ar);
577 if (ret)
578 ath10k_warn("Monitor_down sync failed: %d\n", ret);
579
580 ar->monitor_enabled = false;
581 return ret;
582}
583
584static int ath10k_monitor_create(struct ath10k *ar)
585{
586 int bit, ret = 0;
587
588 lockdep_assert_held(&ar->conf_mutex);
589
590 if (ar->monitor_present) {
591 ath10k_warn("Monitor mode already enabled\n");
592 return 0;
593 }
594
595 bit = ffs(ar->free_vdev_map);
596 if (bit == 0) {
597 ath10k_warn("No free VDEV slots\n");
598 return -ENOMEM;
599 }
600
601 ar->monitor_vdev_id = bit - 1;
602 ar->free_vdev_map &= ~(1 << ar->monitor_vdev_id);
603
604 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
605 WMI_VDEV_TYPE_MONITOR,
606 0, ar->mac_addr);
607 if (ret) {
608 ath10k_warn("WMI vdev monitor create failed: ret %d\n", ret);
609 goto vdev_fail;
610 }
611
Kalle Valo60c3daa2013-09-08 17:56:07 +0300612 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300613 ar->monitor_vdev_id);
614
615 ar->monitor_present = true;
616 return 0;
617
618vdev_fail:
619 /*
620 * Restore the ID to the global map.
621 */
622 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
623 return ret;
624}
625
626static int ath10k_monitor_destroy(struct ath10k *ar)
627{
628 int ret = 0;
629
630 lockdep_assert_held(&ar->conf_mutex);
631
632 if (!ar->monitor_present)
633 return 0;
634
635 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
636 if (ret) {
637 ath10k_warn("WMI vdev monitor delete failed: %d\n", ret);
638 return ret;
639 }
640
641 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
642 ar->monitor_present = false;
643
Kalle Valo60c3daa2013-09-08 17:56:07 +0300644 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300645 ar->monitor_vdev_id);
646 return ret;
647}
648
649static void ath10k_control_beaconing(struct ath10k_vif *arvif,
650 struct ieee80211_bss_conf *info)
651{
652 int ret = 0;
653
Michal Kazior548db542013-07-05 16:15:15 +0300654 lockdep_assert_held(&arvif->ar->conf_mutex);
655
Kalle Valo5e3dd152013-06-12 20:52:10 +0300656 if (!info->enable_beacon) {
657 ath10k_vdev_stop(arvif);
658 return;
659 }
660
661 arvif->tx_seq_no = 0x1000;
662
663 ret = ath10k_vdev_start(arvif);
664 if (ret)
665 return;
666
667 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, 0, info->bssid);
668 if (ret) {
669 ath10k_warn("Failed to bring up VDEV: %d\n",
670 arvif->vdev_id);
671 return;
672 }
Kalle Valo60c3daa2013-09-08 17:56:07 +0300673 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300674}
675
676static void ath10k_control_ibss(struct ath10k_vif *arvif,
677 struct ieee80211_bss_conf *info,
678 const u8 self_peer[ETH_ALEN])
679{
680 int ret = 0;
681
Michal Kazior548db542013-07-05 16:15:15 +0300682 lockdep_assert_held(&arvif->ar->conf_mutex);
683
Kalle Valo5e3dd152013-06-12 20:52:10 +0300684 if (!info->ibss_joined) {
685 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
686 if (ret)
687 ath10k_warn("Failed to delete IBSS self peer:%pM for VDEV:%d ret:%d\n",
688 self_peer, arvif->vdev_id, ret);
689
690 if (is_zero_ether_addr(arvif->u.ibss.bssid))
691 return;
692
693 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id,
694 arvif->u.ibss.bssid);
695 if (ret) {
696 ath10k_warn("Failed to delete IBSS BSSID peer:%pM for VDEV:%d ret:%d\n",
697 arvif->u.ibss.bssid, arvif->vdev_id, ret);
698 return;
699 }
700
701 memset(arvif->u.ibss.bssid, 0, ETH_ALEN);
702
703 return;
704 }
705
706 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
707 if (ret) {
708 ath10k_warn("Failed to create IBSS self peer:%pM for VDEV:%d ret:%d\n",
709 self_peer, arvif->vdev_id, ret);
710 return;
711 }
712
713 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id,
714 WMI_VDEV_PARAM_ATIM_WINDOW,
715 ATH10K_DEFAULT_ATIM);
716 if (ret)
717 ath10k_warn("Failed to set IBSS ATIM for VDEV:%d ret:%d\n",
718 arvif->vdev_id, ret);
719}
720
721/*
722 * Review this when mac80211 gains per-interface powersave support.
723 */
724static void ath10k_ps_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
725{
726 struct ath10k_generic_iter *ar_iter = data;
727 struct ieee80211_conf *conf = &ar_iter->ar->hw->conf;
728 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
729 enum wmi_sta_powersave_param param;
730 enum wmi_sta_ps_mode psmode;
731 int ret;
732
Michal Kazior548db542013-07-05 16:15:15 +0300733 lockdep_assert_held(&arvif->ar->conf_mutex);
734
Kalle Valo5e3dd152013-06-12 20:52:10 +0300735 if (vif->type != NL80211_IFTYPE_STATION)
736 return;
737
738 if (conf->flags & IEEE80211_CONF_PS) {
739 psmode = WMI_STA_PS_MODE_ENABLED;
740 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
741
742 ret = ath10k_wmi_set_sta_ps_param(ar_iter->ar,
743 arvif->vdev_id,
744 param,
745 conf->dynamic_ps_timeout);
746 if (ret) {
747 ath10k_warn("Failed to set inactivity time for VDEV: %d\n",
748 arvif->vdev_id);
749 return;
750 }
751
752 ar_iter->ret = ret;
753 } else {
754 psmode = WMI_STA_PS_MODE_DISABLED;
755 }
756
Kalle Valo60c3daa2013-09-08 17:56:07 +0300757 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
758 arvif->vdev_id, psmode ? "enable" : "disable");
759
Kalle Valo5e3dd152013-06-12 20:52:10 +0300760 ar_iter->ret = ath10k_wmi_set_psmode(ar_iter->ar, arvif->vdev_id,
761 psmode);
762 if (ar_iter->ret)
763 ath10k_warn("Failed to set PS Mode: %d for VDEV: %d\n",
764 psmode, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300765}
766
767/**********************/
768/* Station management */
769/**********************/
770
771static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
772 struct ath10k_vif *arvif,
773 struct ieee80211_sta *sta,
774 struct ieee80211_bss_conf *bss_conf,
775 struct wmi_peer_assoc_complete_arg *arg)
776{
Michal Kazior548db542013-07-05 16:15:15 +0300777 lockdep_assert_held(&ar->conf_mutex);
778
Kalle Valo5e3dd152013-06-12 20:52:10 +0300779 memcpy(arg->addr, sta->addr, ETH_ALEN);
780 arg->vdev_id = arvif->vdev_id;
781 arg->peer_aid = sta->aid;
782 arg->peer_flags |= WMI_PEER_AUTH;
783
784 if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
785 /*
786 * Seems FW have problems with Power Save in STA
787 * mode when we setup this parameter to high (eg. 5).
788 * Often we see that FW don't send NULL (with clean P flags)
789 * frame even there is info about buffered frames in beacons.
790 * Sometimes we have to wait more than 10 seconds before FW
791 * will wakeup. Often sending one ping from AP to our device
792 * just fail (more than 50%).
793 *
794 * Seems setting this FW parameter to 1 couse FW
795 * will check every beacon and will wakup immediately
796 * after detection buffered data.
797 */
798 arg->peer_listen_intval = 1;
799 else
800 arg->peer_listen_intval = ar->hw->conf.listen_interval;
801
802 arg->peer_num_spatial_streams = 1;
803
804 /*
805 * The assoc capabilities are available only in managed mode.
806 */
807 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && bss_conf)
808 arg->peer_caps = bss_conf->assoc_capability;
809}
810
811static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
812 struct ath10k_vif *arvif,
813 struct wmi_peer_assoc_complete_arg *arg)
814{
815 struct ieee80211_vif *vif = arvif->vif;
816 struct ieee80211_bss_conf *info = &vif->bss_conf;
817 struct cfg80211_bss *bss;
818 const u8 *rsnie = NULL;
819 const u8 *wpaie = NULL;
820
Michal Kazior548db542013-07-05 16:15:15 +0300821 lockdep_assert_held(&ar->conf_mutex);
822
Kalle Valo5e3dd152013-06-12 20:52:10 +0300823 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
824 info->bssid, NULL, 0, 0, 0);
825 if (bss) {
826 const struct cfg80211_bss_ies *ies;
827
828 rcu_read_lock();
829 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
830
831 ies = rcu_dereference(bss->ies);
832
833 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
834 WLAN_OUI_TYPE_MICROSOFT_WPA,
835 ies->data,
836 ies->len);
837 rcu_read_unlock();
838 cfg80211_put_bss(ar->hw->wiphy, bss);
839 }
840
841 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
842 if (rsnie || wpaie) {
843 ath10k_dbg(ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
844 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
845 }
846
847 if (wpaie) {
848 ath10k_dbg(ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
849 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
850 }
851}
852
853static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
854 struct ieee80211_sta *sta,
855 struct wmi_peer_assoc_complete_arg *arg)
856{
857 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
858 const struct ieee80211_supported_band *sband;
859 const struct ieee80211_rate *rates;
860 u32 ratemask;
861 int i;
862
Michal Kazior548db542013-07-05 16:15:15 +0300863 lockdep_assert_held(&ar->conf_mutex);
864
Kalle Valo5e3dd152013-06-12 20:52:10 +0300865 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
866 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
867 rates = sband->bitrates;
868
869 rateset->num_rates = 0;
870
871 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
872 if (!(ratemask & 1))
873 continue;
874
875 rateset->rates[rateset->num_rates] = rates->hw_value;
876 rateset->num_rates++;
877 }
878}
879
880static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
881 struct ieee80211_sta *sta,
882 struct wmi_peer_assoc_complete_arg *arg)
883{
884 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
885 int smps;
886 int i, n;
887
Michal Kazior548db542013-07-05 16:15:15 +0300888 lockdep_assert_held(&ar->conf_mutex);
889
Kalle Valo5e3dd152013-06-12 20:52:10 +0300890 if (!ht_cap->ht_supported)
891 return;
892
893 arg->peer_flags |= WMI_PEER_HT;
894 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
895 ht_cap->ampdu_factor)) - 1;
896
897 arg->peer_mpdu_density =
898 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
899
900 arg->peer_ht_caps = ht_cap->cap;
901 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
902
903 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
904 arg->peer_flags |= WMI_PEER_LDPC;
905
906 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
907 arg->peer_flags |= WMI_PEER_40MHZ;
908 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
909 }
910
911 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
912 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
913
914 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
915 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
916
917 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
918 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
919 arg->peer_flags |= WMI_PEER_STBC;
920 }
921
922 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
923 u32 stbc;
924 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
925 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
926 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
927 arg->peer_rate_caps |= stbc;
928 arg->peer_flags |= WMI_PEER_STBC;
929 }
930
931 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
932 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
933
934 if (smps == WLAN_HT_CAP_SM_PS_STATIC) {
935 arg->peer_flags |= WMI_PEER_SPATIAL_MUX;
936 arg->peer_flags |= WMI_PEER_STATIC_MIMOPS;
937 } else if (smps == WLAN_HT_CAP_SM_PS_DYNAMIC) {
938 arg->peer_flags |= WMI_PEER_SPATIAL_MUX;
939 arg->peer_flags |= WMI_PEER_DYN_MIMOPS;
940 }
941
942 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
943 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
944 else if (ht_cap->mcs.rx_mask[1])
945 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
946
947 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
948 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
949 arg->peer_ht_rates.rates[n++] = i;
950
951 arg->peer_ht_rates.num_rates = n;
952 arg->peer_num_spatial_streams = max((n+7) / 8, 1);
953
Kalle Valo60c3daa2013-09-08 17:56:07 +0300954 ath10k_dbg(ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
955 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +0300956 arg->peer_ht_rates.num_rates,
957 arg->peer_num_spatial_streams);
958}
959
960static void ath10k_peer_assoc_h_qos_ap(struct ath10k *ar,
961 struct ath10k_vif *arvif,
962 struct ieee80211_sta *sta,
963 struct ieee80211_bss_conf *bss_conf,
964 struct wmi_peer_assoc_complete_arg *arg)
965{
966 u32 uapsd = 0;
967 u32 max_sp = 0;
968
Michal Kazior548db542013-07-05 16:15:15 +0300969 lockdep_assert_held(&ar->conf_mutex);
970
Kalle Valo5e3dd152013-06-12 20:52:10 +0300971 if (sta->wme)
972 arg->peer_flags |= WMI_PEER_QOS;
973
974 if (sta->wme && sta->uapsd_queues) {
Kalle Valo60c3daa2013-09-08 17:56:07 +0300975 ath10k_dbg(ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300976 sta->uapsd_queues, sta->max_sp);
977
978 arg->peer_flags |= WMI_PEER_APSD;
Janusz Dziedzicc69029b2013-08-07 12:10:49 +0200979 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300980
981 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
982 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
983 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
984 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
985 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
986 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
987 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
988 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
989 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
990 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
991 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
992 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
993
994
995 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
996 max_sp = sta->max_sp;
997
998 ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
999 sta->addr,
1000 WMI_AP_PS_PEER_PARAM_UAPSD,
1001 uapsd);
1002
1003 ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1004 sta->addr,
1005 WMI_AP_PS_PEER_PARAM_MAX_SP,
1006 max_sp);
1007
1008 /* TODO setup this based on STA listen interval and
1009 beacon interval. Currently we don't know
1010 sta->listen_interval - mac80211 patch required.
1011 Currently use 10 seconds */
1012 ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1013 sta->addr,
1014 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
1015 10);
1016 }
1017}
1018
1019static void ath10k_peer_assoc_h_qos_sta(struct ath10k *ar,
1020 struct ath10k_vif *arvif,
1021 struct ieee80211_sta *sta,
1022 struct ieee80211_bss_conf *bss_conf,
1023 struct wmi_peer_assoc_complete_arg *arg)
1024{
1025 if (bss_conf->qos)
1026 arg->peer_flags |= WMI_PEER_QOS;
1027}
1028
1029static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1030 struct ieee80211_sta *sta,
1031 struct wmi_peer_assoc_complete_arg *arg)
1032{
1033 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
1034
1035 if (!vht_cap->vht_supported)
1036 return;
1037
1038 arg->peer_flags |= WMI_PEER_VHT;
1039
1040 arg->peer_vht_caps = vht_cap->cap;
1041
1042 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1043 arg->peer_flags |= WMI_PEER_80MHZ;
1044
1045 arg->peer_vht_rates.rx_max_rate =
1046 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1047 arg->peer_vht_rates.rx_mcs_set =
1048 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1049 arg->peer_vht_rates.tx_max_rate =
1050 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1051 arg->peer_vht_rates.tx_mcs_set =
1052 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1053
Kalle Valo60c3daa2013-09-08 17:56:07 +03001054 ath10k_dbg(ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
1055 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001056}
1057
1058static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
1059 struct ath10k_vif *arvif,
1060 struct ieee80211_sta *sta,
1061 struct ieee80211_bss_conf *bss_conf,
1062 struct wmi_peer_assoc_complete_arg *arg)
1063{
1064 switch (arvif->vdev_type) {
1065 case WMI_VDEV_TYPE_AP:
1066 ath10k_peer_assoc_h_qos_ap(ar, arvif, sta, bss_conf, arg);
1067 break;
1068 case WMI_VDEV_TYPE_STA:
1069 ath10k_peer_assoc_h_qos_sta(ar, arvif, sta, bss_conf, arg);
1070 break;
1071 default:
1072 break;
1073 }
1074}
1075
1076static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
1077 struct ath10k_vif *arvif,
1078 struct ieee80211_sta *sta,
1079 struct wmi_peer_assoc_complete_arg *arg)
1080{
1081 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1082
Kalle Valo5e3dd152013-06-12 20:52:10 +03001083 switch (ar->hw->conf.chandef.chan->band) {
1084 case IEEE80211_BAND_2GHZ:
1085 if (sta->ht_cap.ht_supported) {
1086 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1087 phymode = MODE_11NG_HT40;
1088 else
1089 phymode = MODE_11NG_HT20;
1090 } else {
1091 phymode = MODE_11G;
1092 }
1093
1094 break;
1095 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03001096 /*
1097 * Check VHT first.
1098 */
1099 if (sta->vht_cap.vht_supported) {
1100 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1101 phymode = MODE_11AC_VHT80;
1102 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1103 phymode = MODE_11AC_VHT40;
1104 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1105 phymode = MODE_11AC_VHT20;
1106 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001107 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1108 phymode = MODE_11NA_HT40;
1109 else
1110 phymode = MODE_11NA_HT20;
1111 } else {
1112 phymode = MODE_11A;
1113 }
1114
1115 break;
1116 default:
1117 break;
1118 }
1119
Kalle Valo38a1d472013-09-08 17:56:14 +03001120 ath10k_dbg(ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
1121 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03001122
Kalle Valo5e3dd152013-06-12 20:52:10 +03001123 arg->peer_phymode = phymode;
1124 WARN_ON(phymode == MODE_UNKNOWN);
1125}
1126
1127static int ath10k_peer_assoc(struct ath10k *ar,
1128 struct ath10k_vif *arvif,
1129 struct ieee80211_sta *sta,
1130 struct ieee80211_bss_conf *bss_conf)
1131{
1132 struct wmi_peer_assoc_complete_arg arg;
1133
Michal Kazior548db542013-07-05 16:15:15 +03001134 lockdep_assert_held(&ar->conf_mutex);
1135
Kalle Valo5e3dd152013-06-12 20:52:10 +03001136 memset(&arg, 0, sizeof(struct wmi_peer_assoc_complete_arg));
1137
1138 ath10k_peer_assoc_h_basic(ar, arvif, sta, bss_conf, &arg);
1139 ath10k_peer_assoc_h_crypto(ar, arvif, &arg);
1140 ath10k_peer_assoc_h_rates(ar, sta, &arg);
1141 ath10k_peer_assoc_h_ht(ar, sta, &arg);
1142 ath10k_peer_assoc_h_vht(ar, sta, &arg);
1143 ath10k_peer_assoc_h_qos(ar, arvif, sta, bss_conf, &arg);
1144 ath10k_peer_assoc_h_phymode(ar, arvif, sta, &arg);
1145
1146 return ath10k_wmi_peer_assoc(ar, &arg);
1147}
1148
1149/* can be called only in mac80211 callbacks due to `key_count` usage */
1150static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1151 struct ieee80211_vif *vif,
1152 struct ieee80211_bss_conf *bss_conf)
1153{
1154 struct ath10k *ar = hw->priv;
1155 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1156 struct ieee80211_sta *ap_sta;
1157 int ret;
1158
Michal Kazior548db542013-07-05 16:15:15 +03001159 lockdep_assert_held(&ar->conf_mutex);
1160
Kalle Valo5e3dd152013-06-12 20:52:10 +03001161 rcu_read_lock();
1162
1163 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1164 if (!ap_sta) {
1165 ath10k_warn("Failed to find station entry for %pM\n",
1166 bss_conf->bssid);
1167 rcu_read_unlock();
1168 return;
1169 }
1170
1171 ret = ath10k_peer_assoc(ar, arvif, ap_sta, bss_conf);
1172 if (ret) {
1173 ath10k_warn("Peer assoc failed for %pM\n", bss_conf->bssid);
1174 rcu_read_unlock();
1175 return;
1176 }
1177
1178 rcu_read_unlock();
1179
Kalle Valo60c3daa2013-09-08 17:56:07 +03001180 ath10k_dbg(ATH10K_DBG_MAC,
1181 "mac vdev %d up (associated) bssid %pM aid %d\n",
1182 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1183
Kalle Valo5e3dd152013-06-12 20:52:10 +03001184 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, bss_conf->aid,
1185 bss_conf->bssid);
1186 if (ret)
1187 ath10k_warn("VDEV: %d up failed: ret %d\n",
1188 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001189}
1190
1191/*
1192 * FIXME: flush TIDs
1193 */
1194static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1195 struct ieee80211_vif *vif)
1196{
1197 struct ath10k *ar = hw->priv;
1198 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1199 int ret;
1200
Michal Kazior548db542013-07-05 16:15:15 +03001201 lockdep_assert_held(&ar->conf_mutex);
1202
Kalle Valo5e3dd152013-06-12 20:52:10 +03001203 /*
1204 * For some reason, calling VDEV-DOWN before VDEV-STOP
1205 * makes the FW to send frames via HTT after disassociation.
1206 * No idea why this happens, even though VDEV-DOWN is supposed
1207 * to be analogous to link down, so just stop the VDEV.
1208 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03001209 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d stop (disassociated\n",
1210 arvif->vdev_id);
1211
1212 /* FIXME: check return value */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001213 ret = ath10k_vdev_stop(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001214
1215 /*
1216 * If we don't call VDEV-DOWN after VDEV-STOP FW will remain active and
1217 * report beacons from previously associated network through HTT.
1218 * This in turn would spam mac80211 WARN_ON if we bring down all
1219 * interfaces as it expects there is no rx when no interface is
1220 * running.
1221 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03001222 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d down\n", arvif->vdev_id);
1223
1224 /* FIXME: why don't we print error if wmi call fails? */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001225 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001226
Kalle Valo5e3dd152013-06-12 20:52:10 +03001227 arvif->def_wep_key_index = 0;
1228}
1229
1230static int ath10k_station_assoc(struct ath10k *ar, struct ath10k_vif *arvif,
1231 struct ieee80211_sta *sta)
1232{
1233 int ret = 0;
1234
Michal Kazior548db542013-07-05 16:15:15 +03001235 lockdep_assert_held(&ar->conf_mutex);
1236
Kalle Valo5e3dd152013-06-12 20:52:10 +03001237 ret = ath10k_peer_assoc(ar, arvif, sta, NULL);
1238 if (ret) {
1239 ath10k_warn("WMI peer assoc failed for %pM\n", sta->addr);
1240 return ret;
1241 }
1242
1243 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1244 if (ret) {
1245 ath10k_warn("could not install peer wep keys (%d)\n", ret);
1246 return ret;
1247 }
1248
1249 return ret;
1250}
1251
1252static int ath10k_station_disassoc(struct ath10k *ar, struct ath10k_vif *arvif,
1253 struct ieee80211_sta *sta)
1254{
1255 int ret = 0;
1256
Michal Kazior548db542013-07-05 16:15:15 +03001257 lockdep_assert_held(&ar->conf_mutex);
1258
Kalle Valo5e3dd152013-06-12 20:52:10 +03001259 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1260 if (ret) {
1261 ath10k_warn("could not clear all peer wep keys (%d)\n", ret);
1262 return ret;
1263 }
1264
1265 return ret;
1266}
1267
1268/**************/
1269/* Regulatory */
1270/**************/
1271
1272static int ath10k_update_channel_list(struct ath10k *ar)
1273{
1274 struct ieee80211_hw *hw = ar->hw;
1275 struct ieee80211_supported_band **bands;
1276 enum ieee80211_band band;
1277 struct ieee80211_channel *channel;
1278 struct wmi_scan_chan_list_arg arg = {0};
1279 struct wmi_channel_arg *ch;
1280 bool passive;
1281 int len;
1282 int ret;
1283 int i;
1284
Michal Kazior548db542013-07-05 16:15:15 +03001285 lockdep_assert_held(&ar->conf_mutex);
1286
Kalle Valo5e3dd152013-06-12 20:52:10 +03001287 bands = hw->wiphy->bands;
1288 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1289 if (!bands[band])
1290 continue;
1291
1292 for (i = 0; i < bands[band]->n_channels; i++) {
1293 if (bands[band]->channels[i].flags &
1294 IEEE80211_CHAN_DISABLED)
1295 continue;
1296
1297 arg.n_channels++;
1298 }
1299 }
1300
1301 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
1302 arg.channels = kzalloc(len, GFP_KERNEL);
1303 if (!arg.channels)
1304 return -ENOMEM;
1305
1306 ch = arg.channels;
1307 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1308 if (!bands[band])
1309 continue;
1310
1311 for (i = 0; i < bands[band]->n_channels; i++) {
1312 channel = &bands[band]->channels[i];
1313
1314 if (channel->flags & IEEE80211_CHAN_DISABLED)
1315 continue;
1316
1317 ch->allow_ht = true;
1318
1319 /* FIXME: when should we really allow VHT? */
1320 ch->allow_vht = true;
1321
1322 ch->allow_ibss =
1323 !(channel->flags & IEEE80211_CHAN_NO_IBSS);
1324
1325 ch->ht40plus =
1326 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
1327
1328 passive = channel->flags & IEEE80211_CHAN_PASSIVE_SCAN;
1329 ch->passive = passive;
1330
1331 ch->freq = channel->center_freq;
1332 ch->min_power = channel->max_power * 3;
1333 ch->max_power = channel->max_power * 4;
1334 ch->max_reg_power = channel->max_reg_power * 4;
1335 ch->max_antenna_gain = channel->max_antenna_gain;
1336 ch->reg_class_id = 0; /* FIXME */
1337
1338 /* FIXME: why use only legacy modes, why not any
1339 * HT/VHT modes? Would that even make any
1340 * difference? */
1341 if (channel->band == IEEE80211_BAND_2GHZ)
1342 ch->mode = MODE_11G;
1343 else
1344 ch->mode = MODE_11A;
1345
1346 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
1347 continue;
1348
1349 ath10k_dbg(ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03001350 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1351 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001352 ch->freq, ch->max_power, ch->max_reg_power,
1353 ch->max_antenna_gain, ch->mode);
1354
1355 ch++;
1356 }
1357 }
1358
1359 ret = ath10k_wmi_scan_chan_list(ar, &arg);
1360 kfree(arg.channels);
1361
1362 return ret;
1363}
1364
Michal Kaziorf7843d72013-07-16 09:38:52 +02001365static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001366{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001367 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001368 int ret;
1369
Michal Kaziorf7843d72013-07-16 09:38:52 +02001370 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001371
1372 ret = ath10k_update_channel_list(ar);
1373 if (ret)
1374 ath10k_warn("could not update channel list (%d)\n", ret);
1375
1376 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02001377
Kalle Valo5e3dd152013-06-12 20:52:10 +03001378 /* Target allows setting up per-band regdomain but ath_common provides
1379 * a combined one only */
1380 ret = ath10k_wmi_pdev_set_regdomain(ar,
1381 regpair->regDmnEnum,
1382 regpair->regDmnEnum, /* 2ghz */
1383 regpair->regDmnEnum, /* 5ghz */
1384 regpair->reg_2ghz_ctl,
1385 regpair->reg_5ghz_ctl);
1386 if (ret)
1387 ath10k_warn("could not set pdev regdomain (%d)\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02001388}
Michal Kazior548db542013-07-05 16:15:15 +03001389
Michal Kaziorf7843d72013-07-16 09:38:52 +02001390static void ath10k_reg_notifier(struct wiphy *wiphy,
1391 struct regulatory_request *request)
1392{
1393 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1394 struct ath10k *ar = hw->priv;
1395
1396 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
1397
1398 mutex_lock(&ar->conf_mutex);
1399 if (ar->state == ATH10K_STATE_ON)
1400 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03001401 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001402}
1403
1404/***************/
1405/* TX handlers */
1406/***************/
1407
1408/*
1409 * Frames sent to the FW have to be in "Native Wifi" format.
1410 * Strip the QoS field from the 802.11 header.
1411 */
1412static void ath10k_tx_h_qos_workaround(struct ieee80211_hw *hw,
1413 struct ieee80211_tx_control *control,
1414 struct sk_buff *skb)
1415{
1416 struct ieee80211_hdr *hdr = (void *)skb->data;
1417 u8 *qos_ctl;
1418
1419 if (!ieee80211_is_data_qos(hdr->frame_control))
1420 return;
1421
1422 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02001423 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
1424 skb->data, (void *)qos_ctl - (void *)skb->data);
1425 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001426}
1427
1428static void ath10k_tx_h_update_wep_key(struct sk_buff *skb)
1429{
1430 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1431 struct ieee80211_vif *vif = info->control.vif;
1432 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1433 struct ath10k *ar = arvif->ar;
1434 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1435 struct ieee80211_key_conf *key = info->control.hw_key;
1436 int ret;
1437
Kalle Valo5e3dd152013-06-12 20:52:10 +03001438 if (!ieee80211_has_protected(hdr->frame_control))
1439 return;
1440
1441 if (!key)
1442 return;
1443
1444 if (key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
1445 key->cipher != WLAN_CIPHER_SUITE_WEP104)
1446 return;
1447
1448 if (key->keyidx == arvif->def_wep_key_index)
1449 return;
1450
Kalle Valo60c3daa2013-09-08 17:56:07 +03001451 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d keyidx %d\n",
1452 arvif->vdev_id, key->keyidx);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001453
1454 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
1455 WMI_VDEV_PARAM_DEF_KEYID,
1456 key->keyidx);
1457 if (ret) {
1458 ath10k_warn("could not update wep keyidx (%d)\n", ret);
1459 return;
1460 }
1461
1462 arvif->def_wep_key_index = key->keyidx;
1463}
1464
1465static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar, struct sk_buff *skb)
1466{
1467 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1468 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1469 struct ieee80211_vif *vif = info->control.vif;
1470 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1471
1472 /* This is case only for P2P_GO */
1473 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
1474 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1475 return;
1476
1477 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
1478 spin_lock_bh(&ar->data_lock);
1479 if (arvif->u.ap.noa_data)
1480 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
1481 GFP_ATOMIC))
1482 memcpy(skb_put(skb, arvif->u.ap.noa_len),
1483 arvif->u.ap.noa_data,
1484 arvif->u.ap.noa_len);
1485 spin_unlock_bh(&ar->data_lock);
1486 }
1487}
1488
1489static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
1490{
1491 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1492 int ret;
1493
Michal Kazior961d4c32013-08-09 10:13:34 +02001494 if (ar->htt.target_version_major >= 3) {
1495 /* Since HTT 3.0 there is no separate mgmt tx command */
1496 ret = ath10k_htt_tx(&ar->htt, skb);
1497 goto exit;
1498 }
1499
Kalle Valo5e3dd152013-06-12 20:52:10 +03001500 if (ieee80211_is_mgmt(hdr->frame_control))
Michal Kazioredb82362013-07-05 16:15:14 +03001501 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001502 else if (ieee80211_is_nullfunc(hdr->frame_control))
1503 /* FW does not report tx status properly for NullFunc frames
1504 * unless they are sent through mgmt tx path. mac80211 sends
1505 * those frames when it detects link/beacon loss and depends on
1506 * the tx status to be correct. */
Michal Kazioredb82362013-07-05 16:15:14 +03001507 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001508 else
Michal Kazioredb82362013-07-05 16:15:14 +03001509 ret = ath10k_htt_tx(&ar->htt, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001510
Michal Kazior961d4c32013-08-09 10:13:34 +02001511exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03001512 if (ret) {
1513 ath10k_warn("tx failed (%d). dropping packet.\n", ret);
1514 ieee80211_free_txskb(ar->hw, skb);
1515 }
1516}
1517
1518void ath10k_offchan_tx_purge(struct ath10k *ar)
1519{
1520 struct sk_buff *skb;
1521
1522 for (;;) {
1523 skb = skb_dequeue(&ar->offchan_tx_queue);
1524 if (!skb)
1525 break;
1526
1527 ieee80211_free_txskb(ar->hw, skb);
1528 }
1529}
1530
1531void ath10k_offchan_tx_work(struct work_struct *work)
1532{
1533 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
1534 struct ath10k_peer *peer;
1535 struct ieee80211_hdr *hdr;
1536 struct sk_buff *skb;
1537 const u8 *peer_addr;
1538 int vdev_id;
1539 int ret;
1540
1541 /* FW requirement: We must create a peer before FW will send out
1542 * an offchannel frame. Otherwise the frame will be stuck and
1543 * never transmitted. We delete the peer upon tx completion.
1544 * It is unlikely that a peer for offchannel tx will already be
1545 * present. However it may be in some rare cases so account for that.
1546 * Otherwise we might remove a legitimate peer and break stuff. */
1547
1548 for (;;) {
1549 skb = skb_dequeue(&ar->offchan_tx_queue);
1550 if (!skb)
1551 break;
1552
1553 mutex_lock(&ar->conf_mutex);
1554
Kalle Valo60c3daa2013-09-08 17:56:07 +03001555 ath10k_dbg(ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001556 skb);
1557
1558 hdr = (struct ieee80211_hdr *)skb->data;
1559 peer_addr = ieee80211_get_DA(hdr);
1560 vdev_id = ATH10K_SKB_CB(skb)->htt.vdev_id;
1561
1562 spin_lock_bh(&ar->data_lock);
1563 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
1564 spin_unlock_bh(&ar->data_lock);
1565
1566 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03001567 /* FIXME: should this use ath10k_warn()? */
Kalle Valo5e3dd152013-06-12 20:52:10 +03001568 ath10k_dbg(ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
1569 peer_addr, vdev_id);
1570
1571 if (!peer) {
1572 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
1573 if (ret)
1574 ath10k_warn("peer %pM on vdev %d not created (%d)\n",
1575 peer_addr, vdev_id, ret);
1576 }
1577
1578 spin_lock_bh(&ar->data_lock);
1579 INIT_COMPLETION(ar->offchan_tx_completed);
1580 ar->offchan_tx_skb = skb;
1581 spin_unlock_bh(&ar->data_lock);
1582
1583 ath10k_tx_htt(ar, skb);
1584
1585 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
1586 3 * HZ);
1587 if (ret <= 0)
1588 ath10k_warn("timed out waiting for offchannel skb %p\n",
1589 skb);
1590
1591 if (!peer) {
1592 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
1593 if (ret)
1594 ath10k_warn("peer %pM on vdev %d not deleted (%d)\n",
1595 peer_addr, vdev_id, ret);
1596 }
1597
1598 mutex_unlock(&ar->conf_mutex);
1599 }
1600}
1601
1602/************/
1603/* Scanning */
1604/************/
1605
1606/*
1607 * This gets called if we dont get a heart-beat during scan.
1608 * This may indicate the FW has hung and we need to abort the
1609 * scan manually to prevent cancel_hw_scan() from deadlocking
1610 */
1611void ath10k_reset_scan(unsigned long ptr)
1612{
1613 struct ath10k *ar = (struct ath10k *)ptr;
1614
1615 spin_lock_bh(&ar->data_lock);
1616 if (!ar->scan.in_progress) {
1617 spin_unlock_bh(&ar->data_lock);
1618 return;
1619 }
1620
1621 ath10k_warn("scan timeout. resetting. fw issue?\n");
1622
1623 if (ar->scan.is_roc)
1624 ieee80211_remain_on_channel_expired(ar->hw);
1625 else
1626 ieee80211_scan_completed(ar->hw, 1 /* aborted */);
1627
1628 ar->scan.in_progress = false;
1629 complete_all(&ar->scan.completed);
1630 spin_unlock_bh(&ar->data_lock);
1631}
1632
1633static int ath10k_abort_scan(struct ath10k *ar)
1634{
1635 struct wmi_stop_scan_arg arg = {
1636 .req_id = 1, /* FIXME */
1637 .req_type = WMI_SCAN_STOP_ONE,
1638 .u.scan_id = ATH10K_SCAN_ID,
1639 };
1640 int ret;
1641
1642 lockdep_assert_held(&ar->conf_mutex);
1643
1644 del_timer_sync(&ar->scan.timeout);
1645
1646 spin_lock_bh(&ar->data_lock);
1647 if (!ar->scan.in_progress) {
1648 spin_unlock_bh(&ar->data_lock);
1649 return 0;
1650 }
1651
1652 ar->scan.aborting = true;
1653 spin_unlock_bh(&ar->data_lock);
1654
1655 ret = ath10k_wmi_stop_scan(ar, &arg);
1656 if (ret) {
1657 ath10k_warn("could not submit wmi stop scan (%d)\n", ret);
Michal Kazioradb8c9b2013-07-05 16:15:16 +03001658 spin_lock_bh(&ar->data_lock);
1659 ar->scan.in_progress = false;
1660 ath10k_offchan_tx_purge(ar);
1661 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001662 return -EIO;
1663 }
1664
Kalle Valo5e3dd152013-06-12 20:52:10 +03001665 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
1666 if (ret == 0)
1667 ath10k_warn("timed out while waiting for scan to stop\n");
1668
1669 /* scan completion may be done right after we timeout here, so let's
1670 * check the in_progress and tell mac80211 scan is completed. if we
1671 * don't do that and FW fails to send us scan completion indication
1672 * then userspace won't be able to scan anymore */
1673 ret = 0;
1674
1675 spin_lock_bh(&ar->data_lock);
1676 if (ar->scan.in_progress) {
1677 ath10k_warn("could not stop scan. its still in progress\n");
1678 ar->scan.in_progress = false;
1679 ath10k_offchan_tx_purge(ar);
1680 ret = -ETIMEDOUT;
1681 }
1682 spin_unlock_bh(&ar->data_lock);
1683
1684 return ret;
1685}
1686
1687static int ath10k_start_scan(struct ath10k *ar,
1688 const struct wmi_start_scan_arg *arg)
1689{
1690 int ret;
1691
1692 lockdep_assert_held(&ar->conf_mutex);
1693
1694 ret = ath10k_wmi_start_scan(ar, arg);
1695 if (ret)
1696 return ret;
1697
Kalle Valo5e3dd152013-06-12 20:52:10 +03001698 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
1699 if (ret == 0) {
1700 ath10k_abort_scan(ar);
1701 return ret;
1702 }
1703
1704 /* the scan can complete earlier, before we even
1705 * start the timer. in that case the timer handler
1706 * checks ar->scan.in_progress and bails out if its
1707 * false. Add a 200ms margin to account event/command
1708 * processing. */
1709 mod_timer(&ar->scan.timeout, jiffies +
1710 msecs_to_jiffies(arg->max_scan_time+200));
1711 return 0;
1712}
1713
1714/**********************/
1715/* mac80211 callbacks */
1716/**********************/
1717
1718static void ath10k_tx(struct ieee80211_hw *hw,
1719 struct ieee80211_tx_control *control,
1720 struct sk_buff *skb)
1721{
1722 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1723 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1724 struct ath10k *ar = hw->priv;
1725 struct ath10k_vif *arvif = NULL;
1726 u32 vdev_id = 0;
1727 u8 tid;
1728
1729 if (info->control.vif) {
1730 arvif = ath10k_vif_to_arvif(info->control.vif);
1731 vdev_id = arvif->vdev_id;
1732 } else if (ar->monitor_enabled) {
1733 vdev_id = ar->monitor_vdev_id;
1734 }
1735
1736 /* We should disable CCK RATE due to P2P */
1737 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
1738 ath10k_dbg(ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
1739
1740 /* we must calculate tid before we apply qos workaround
1741 * as we'd lose the qos control field */
1742 tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
Michal Kazior961d4c32013-08-09 10:13:34 +02001743 if (ieee80211_is_mgmt(hdr->frame_control)) {
1744 tid = HTT_DATA_TX_EXT_TID_MGMT;
1745 } else if (ieee80211_is_data_qos(hdr->frame_control) &&
1746 is_unicast_ether_addr(ieee80211_get_DA(hdr))) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001747 u8 *qc = ieee80211_get_qos_ctl(hdr);
1748 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
1749 }
1750
Michal Kaziorcf84bd42013-07-16 11:04:54 +02001751 /* it makes no sense to process injected frames like that */
1752 if (info->control.vif &&
1753 info->control.vif->type != NL80211_IFTYPE_MONITOR) {
1754 ath10k_tx_h_qos_workaround(hw, control, skb);
1755 ath10k_tx_h_update_wep_key(skb);
1756 ath10k_tx_h_add_p2p_noa_ie(ar, skb);
1757 ath10k_tx_h_seq_no(skb);
1758 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001759
Michal Kazior27bb1782013-09-18 14:43:19 +02001760 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001761 ATH10K_SKB_CB(skb)->htt.vdev_id = vdev_id;
1762 ATH10K_SKB_CB(skb)->htt.tid = tid;
1763
1764 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
1765 spin_lock_bh(&ar->data_lock);
1766 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
1767 ATH10K_SKB_CB(skb)->htt.vdev_id = ar->scan.vdev_id;
1768 spin_unlock_bh(&ar->data_lock);
1769
1770 ath10k_dbg(ATH10K_DBG_MAC, "queued offchannel skb %p\n", skb);
1771
1772 skb_queue_tail(&ar->offchan_tx_queue, skb);
1773 ieee80211_queue_work(hw, &ar->offchan_tx_work);
1774 return;
1775 }
1776
1777 ath10k_tx_htt(ar, skb);
1778}
1779
1780/*
1781 * Initialize various parameters with default vaules.
1782 */
Michal Kazioraffd3212013-07-16 09:54:35 +02001783void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02001784{
1785 lockdep_assert_held(&ar->conf_mutex);
1786
1787 del_timer_sync(&ar->scan.timeout);
1788 ath10k_offchan_tx_purge(ar);
1789 ath10k_peer_cleanup_all(ar);
1790 ath10k_core_stop(ar);
1791 ath10k_hif_power_down(ar);
1792
1793 spin_lock_bh(&ar->data_lock);
1794 if (ar->scan.in_progress) {
1795 del_timer(&ar->scan.timeout);
1796 ar->scan.in_progress = false;
1797 ieee80211_scan_completed(ar->hw, true);
1798 }
1799 spin_unlock_bh(&ar->data_lock);
1800}
1801
Kalle Valo5e3dd152013-06-12 20:52:10 +03001802static int ath10k_start(struct ieee80211_hw *hw)
1803{
1804 struct ath10k *ar = hw->priv;
Michal Kazior818bdd12013-07-16 09:38:57 +02001805 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001806
Michal Kazior548db542013-07-05 16:15:15 +03001807 mutex_lock(&ar->conf_mutex);
1808
Michal Kazioraffd3212013-07-16 09:54:35 +02001809 if (ar->state != ATH10K_STATE_OFF &&
1810 ar->state != ATH10K_STATE_RESTARTING) {
Michal Kazior818bdd12013-07-16 09:38:57 +02001811 ret = -EINVAL;
1812 goto exit;
1813 }
1814
1815 ret = ath10k_hif_power_up(ar);
1816 if (ret) {
1817 ath10k_err("could not init hif (%d)\n", ret);
1818 ar->state = ATH10K_STATE_OFF;
1819 goto exit;
1820 }
1821
1822 ret = ath10k_core_start(ar);
1823 if (ret) {
1824 ath10k_err("could not init core (%d)\n", ret);
1825 ath10k_hif_power_down(ar);
1826 ar->state = ATH10K_STATE_OFF;
1827 goto exit;
1828 }
1829
Michal Kazioraffd3212013-07-16 09:54:35 +02001830 if (ar->state == ATH10K_STATE_OFF)
1831 ar->state = ATH10K_STATE_ON;
1832 else if (ar->state == ATH10K_STATE_RESTARTING)
1833 ar->state = ATH10K_STATE_RESTARTED;
1834
Kalle Valo5e3dd152013-06-12 20:52:10 +03001835 ret = ath10k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_PMF_QOS, 1);
1836 if (ret)
1837 ath10k_warn("could not enable WMI_PDEV_PARAM_PMF_QOS (%d)\n",
1838 ret);
1839
1840 ret = ath10k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_DYNAMIC_BW, 0);
1841 if (ret)
1842 ath10k_warn("could not init WMI_PDEV_PARAM_DYNAMIC_BW (%d)\n",
1843 ret);
1844
Michal Kaziorf7843d72013-07-16 09:38:52 +02001845 ath10k_regd_update(ar);
1846
Michal Kazior818bdd12013-07-16 09:38:57 +02001847exit:
Michal Kazior548db542013-07-05 16:15:15 +03001848 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001849 return 0;
1850}
1851
1852static void ath10k_stop(struct ieee80211_hw *hw)
1853{
1854 struct ath10k *ar = hw->priv;
1855
Michal Kazior548db542013-07-05 16:15:15 +03001856 mutex_lock(&ar->conf_mutex);
Michal Kazioraffd3212013-07-16 09:54:35 +02001857 if (ar->state == ATH10K_STATE_ON ||
1858 ar->state == ATH10K_STATE_RESTARTED ||
1859 ar->state == ATH10K_STATE_WEDGED)
Michal Kazior818bdd12013-07-16 09:38:57 +02001860 ath10k_halt(ar);
Michal Kaziora96d7742013-07-16 09:38:56 +02001861
Michal Kaziorf7843d72013-07-16 09:38:52 +02001862 ar->state = ATH10K_STATE_OFF;
Michal Kazior548db542013-07-05 16:15:15 +03001863 mutex_unlock(&ar->conf_mutex);
1864
1865 cancel_work_sync(&ar->offchan_tx_work);
Michal Kazioraffd3212013-07-16 09:54:35 +02001866 cancel_work_sync(&ar->restart_work);
1867}
1868
1869static void ath10k_config_ps(struct ath10k *ar)
1870{
1871 struct ath10k_generic_iter ar_iter;
1872
1873 lockdep_assert_held(&ar->conf_mutex);
1874
1875 /* During HW reconfiguration mac80211 reports all interfaces that were
1876 * running until reconfiguration was started. Since FW doesn't have any
1877 * vdevs at this point we must not iterate over this interface list.
1878 * This setting will be updated upon add_interface(). */
1879 if (ar->state == ATH10K_STATE_RESTARTED)
1880 return;
1881
1882 memset(&ar_iter, 0, sizeof(struct ath10k_generic_iter));
1883 ar_iter.ar = ar;
1884
1885 ieee80211_iterate_active_interfaces_atomic(
1886 ar->hw, IEEE80211_IFACE_ITER_NORMAL,
1887 ath10k_ps_iter, &ar_iter);
1888
1889 if (ar_iter.ret)
1890 ath10k_warn("failed to set ps config (%d)\n", ar_iter.ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001891}
1892
1893static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
1894{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001895 struct ath10k *ar = hw->priv;
1896 struct ieee80211_conf *conf = &hw->conf;
1897 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001898
1899 mutex_lock(&ar->conf_mutex);
1900
1901 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03001902 ath10k_dbg(ATH10K_DBG_MAC, "mac config channel %d mhz\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001903 conf->chandef.chan->center_freq);
1904 spin_lock_bh(&ar->data_lock);
1905 ar->rx_channel = conf->chandef.chan;
1906 spin_unlock_bh(&ar->data_lock);
1907 }
1908
Michal Kazioraffd3212013-07-16 09:54:35 +02001909 if (changed & IEEE80211_CONF_CHANGE_PS)
1910 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001911
1912 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1913 if (conf->flags & IEEE80211_CONF_MONITOR)
1914 ret = ath10k_monitor_create(ar);
1915 else
1916 ret = ath10k_monitor_destroy(ar);
1917 }
1918
1919 mutex_unlock(&ar->conf_mutex);
1920 return ret;
1921}
1922
1923/*
1924 * TODO:
1925 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
1926 * because we will send mgmt frames without CCK. This requirement
1927 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
1928 * in the TX packet.
1929 */
1930static int ath10k_add_interface(struct ieee80211_hw *hw,
1931 struct ieee80211_vif *vif)
1932{
1933 struct ath10k *ar = hw->priv;
1934 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1935 enum wmi_sta_powersave_param param;
1936 int ret = 0;
Michal Kazior424121c2013-07-22 14:13:31 +02001937 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001938 int bit;
1939
1940 mutex_lock(&ar->conf_mutex);
1941
Michal Kazior0dbd09e2013-07-31 10:55:14 +02001942 memset(arvif, 0, sizeof(*arvif));
1943
Kalle Valo5e3dd152013-06-12 20:52:10 +03001944 arvif->ar = ar;
1945 arvif->vif = vif;
1946
1947 if ((vif->type == NL80211_IFTYPE_MONITOR) && ar->monitor_present) {
1948 ath10k_warn("Only one monitor interface allowed\n");
1949 ret = -EBUSY;
1950 goto exit;
1951 }
1952
1953 bit = ffs(ar->free_vdev_map);
1954 if (bit == 0) {
1955 ret = -EBUSY;
1956 goto exit;
1957 }
1958
1959 arvif->vdev_id = bit - 1;
1960 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
1961 ar->free_vdev_map &= ~(1 << arvif->vdev_id);
1962
1963 if (ar->p2p)
1964 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
1965
1966 switch (vif->type) {
1967 case NL80211_IFTYPE_UNSPECIFIED:
1968 case NL80211_IFTYPE_STATION:
1969 arvif->vdev_type = WMI_VDEV_TYPE_STA;
1970 if (vif->p2p)
1971 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
1972 break;
1973 case NL80211_IFTYPE_ADHOC:
1974 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
1975 break;
1976 case NL80211_IFTYPE_AP:
1977 arvif->vdev_type = WMI_VDEV_TYPE_AP;
1978
1979 if (vif->p2p)
1980 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
1981 break;
1982 case NL80211_IFTYPE_MONITOR:
1983 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
1984 break;
1985 default:
1986 WARN_ON(1);
1987 break;
1988 }
1989
Kalle Valo60c3daa2013-09-08 17:56:07 +03001990 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001991 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype);
1992
1993 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
1994 arvif->vdev_subtype, vif->addr);
1995 if (ret) {
1996 ath10k_warn("WMI vdev create failed: ret %d\n", ret);
1997 goto exit;
1998 }
1999
2000 ret = ath10k_wmi_vdev_set_param(ar, 0, WMI_VDEV_PARAM_DEF_KEYID,
2001 arvif->def_wep_key_index);
2002 if (ret)
2003 ath10k_warn("Failed to set default keyid: %d\n", ret);
2004
2005 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2006 WMI_VDEV_PARAM_TX_ENCAP_TYPE,
2007 ATH10K_HW_TXRX_NATIVE_WIFI);
2008 if (ret)
2009 ath10k_warn("Failed to set TX encap: %d\n", ret);
2010
2011 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2012 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
2013 if (ret) {
2014 ath10k_warn("Failed to create peer for AP: %d\n", ret);
2015 goto exit;
2016 }
2017 }
2018
2019 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
2020 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
2021 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2022 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2023 param, value);
2024 if (ret)
2025 ath10k_warn("Failed to set RX wake policy: %d\n", ret);
2026
2027 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
2028 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
2029 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2030 param, value);
2031 if (ret)
2032 ath10k_warn("Failed to set TX wake thresh: %d\n", ret);
2033
2034 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
2035 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
2036 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2037 param, value);
2038 if (ret)
2039 ath10k_warn("Failed to set PSPOLL count: %d\n", ret);
2040 }
2041
Michal Kazior424121c2013-07-22 14:13:31 +02002042 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior679c54a2013-07-05 16:15:04 +03002043 if (ret)
2044 ath10k_warn("failed to set rts threshold for vdev %d (%d)\n",
2045 arvif->vdev_id, ret);
2046
Michal Kazior424121c2013-07-22 14:13:31 +02002047 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior679c54a2013-07-05 16:15:04 +03002048 if (ret)
2049 ath10k_warn("failed to set frag threshold for vdev %d (%d)\n",
2050 arvif->vdev_id, ret);
2051
Kalle Valo5e3dd152013-06-12 20:52:10 +03002052 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2053 ar->monitor_present = true;
2054
2055exit:
2056 mutex_unlock(&ar->conf_mutex);
2057 return ret;
2058}
2059
2060static void ath10k_remove_interface(struct ieee80211_hw *hw,
2061 struct ieee80211_vif *vif)
2062{
2063 struct ath10k *ar = hw->priv;
2064 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2065 int ret;
2066
2067 mutex_lock(&ar->conf_mutex);
2068
Michal Kaziored543882013-09-13 14:16:56 +02002069 spin_lock_bh(&ar->data_lock);
2070 if (arvif->beacon) {
2071 dev_kfree_skb_any(arvif->beacon);
2072 arvif->beacon = NULL;
2073 }
2074 spin_unlock_bh(&ar->data_lock);
2075
Kalle Valo5e3dd152013-06-12 20:52:10 +03002076 ar->free_vdev_map |= 1 << (arvif->vdev_id);
2077
2078 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2079 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
2080 if (ret)
2081 ath10k_warn("Failed to remove peer for AP: %d\n", ret);
2082
2083 kfree(arvif->u.ap.noa_data);
2084 }
2085
Kalle Valo60c3daa2013-09-08 17:56:07 +03002086 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev delete %d (remove interface)\n",
2087 arvif->vdev_id);
2088
Kalle Valo5e3dd152013-06-12 20:52:10 +03002089 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2090 if (ret)
2091 ath10k_warn("WMI vdev delete failed: %d\n", ret);
2092
2093 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2094 ar->monitor_present = false;
2095
2096 ath10k_peer_cleanup(ar, arvif->vdev_id);
2097
2098 mutex_unlock(&ar->conf_mutex);
2099}
2100
2101/*
2102 * FIXME: Has to be verified.
2103 */
2104#define SUPPORTED_FILTERS \
2105 (FIF_PROMISC_IN_BSS | \
2106 FIF_ALLMULTI | \
2107 FIF_CONTROL | \
2108 FIF_PSPOLL | \
2109 FIF_OTHER_BSS | \
2110 FIF_BCN_PRBRESP_PROMISC | \
2111 FIF_PROBE_REQ | \
2112 FIF_FCSFAIL)
2113
2114static void ath10k_configure_filter(struct ieee80211_hw *hw,
2115 unsigned int changed_flags,
2116 unsigned int *total_flags,
2117 u64 multicast)
2118{
2119 struct ath10k *ar = hw->priv;
2120 int ret;
2121
2122 mutex_lock(&ar->conf_mutex);
2123
2124 changed_flags &= SUPPORTED_FILTERS;
2125 *total_flags &= SUPPORTED_FILTERS;
2126 ar->filter_flags = *total_flags;
2127
2128 if ((ar->filter_flags & FIF_PROMISC_IN_BSS) &&
2129 !ar->monitor_enabled) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03002130 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor %d start\n",
2131 ar->monitor_vdev_id);
2132
Kalle Valo5e3dd152013-06-12 20:52:10 +03002133 ret = ath10k_monitor_start(ar, ar->monitor_vdev_id);
2134 if (ret)
2135 ath10k_warn("Unable to start monitor mode\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002136 } else if (!(ar->filter_flags & FIF_PROMISC_IN_BSS) &&
2137 ar->monitor_enabled) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03002138 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor %d stop\n",
2139 ar->monitor_vdev_id);
2140
Kalle Valo5e3dd152013-06-12 20:52:10 +03002141 ret = ath10k_monitor_stop(ar);
2142 if (ret)
2143 ath10k_warn("Unable to stop monitor mode\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03002144 }
2145
2146 mutex_unlock(&ar->conf_mutex);
2147}
2148
2149static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
2150 struct ieee80211_vif *vif,
2151 struct ieee80211_bss_conf *info,
2152 u32 changed)
2153{
2154 struct ath10k *ar = hw->priv;
2155 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2156 int ret = 0;
2157
2158 mutex_lock(&ar->conf_mutex);
2159
2160 if (changed & BSS_CHANGED_IBSS)
2161 ath10k_control_ibss(arvif, info, vif->addr);
2162
2163 if (changed & BSS_CHANGED_BEACON_INT) {
2164 arvif->beacon_interval = info->beacon_int;
2165 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2166 WMI_VDEV_PARAM_BEACON_INTERVAL,
2167 arvif->beacon_interval);
Kalle Valo60c3daa2013-09-08 17:56:07 +03002168 ath10k_dbg(ATH10K_DBG_MAC,
2169 "mac vdev %d beacon_interval %d\n",
2170 arvif->vdev_id, arvif->beacon_interval);
2171
Kalle Valo5e3dd152013-06-12 20:52:10 +03002172 if (ret)
2173 ath10k_warn("Failed to set beacon interval for VDEV: %d\n",
2174 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002175 }
2176
2177 if (changed & BSS_CHANGED_BEACON) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03002178 ath10k_dbg(ATH10K_DBG_MAC,
2179 "vdev %d set beacon tx mode to staggered\n",
2180 arvif->vdev_id);
2181
Kalle Valo5e3dd152013-06-12 20:52:10 +03002182 ret = ath10k_wmi_pdev_set_param(ar,
2183 WMI_PDEV_PARAM_BEACON_TX_MODE,
2184 WMI_BEACON_STAGGERED_MODE);
2185 if (ret)
2186 ath10k_warn("Failed to set beacon mode for VDEV: %d\n",
2187 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002188 }
2189
John W. Linvilleb70727e2013-06-13 13:34:29 -04002190 if (changed & BSS_CHANGED_BEACON_INFO) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002191 arvif->dtim_period = info->dtim_period;
2192
Kalle Valo60c3daa2013-09-08 17:56:07 +03002193 ath10k_dbg(ATH10K_DBG_MAC,
2194 "mac vdev %d dtim_period %d\n",
2195 arvif->vdev_id, arvif->dtim_period);
2196
Kalle Valo5e3dd152013-06-12 20:52:10 +03002197 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2198 WMI_VDEV_PARAM_DTIM_PERIOD,
2199 arvif->dtim_period);
2200 if (ret)
2201 ath10k_warn("Failed to set dtim period for VDEV: %d\n",
2202 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002203 }
2204
2205 if (changed & BSS_CHANGED_SSID &&
2206 vif->type == NL80211_IFTYPE_AP) {
2207 arvif->u.ap.ssid_len = info->ssid_len;
2208 if (info->ssid_len)
2209 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
2210 arvif->u.ap.hidden_ssid = info->hidden_ssid;
2211 }
2212
2213 if (changed & BSS_CHANGED_BSSID) {
2214 if (!is_zero_ether_addr(info->bssid)) {
Kalle Valo60c3daa2013-09-08 17:56:07 +03002215 ath10k_dbg(ATH10K_DBG_MAC,
2216 "mac vdev %d create peer %pM\n",
2217 arvif->vdev_id, info->bssid);
2218
Kalle Valo5e3dd152013-06-12 20:52:10 +03002219 ret = ath10k_peer_create(ar, arvif->vdev_id,
2220 info->bssid);
2221 if (ret)
2222 ath10k_warn("Failed to add peer: %pM for VDEV: %d\n",
2223 info->bssid, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002224
2225 if (vif->type == NL80211_IFTYPE_STATION) {
2226 /*
2227 * this is never erased as we it for crypto key
2228 * clearing; this is FW requirement
2229 */
2230 memcpy(arvif->u.sta.bssid, info->bssid,
2231 ETH_ALEN);
2232
Kalle Valo60c3daa2013-09-08 17:56:07 +03002233 ath10k_dbg(ATH10K_DBG_MAC,
2234 "mac vdev %d start %pM\n",
2235 arvif->vdev_id, info->bssid);
2236
2237 /* FIXME: check return value */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002238 ret = ath10k_vdev_start(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002239 }
2240
2241 /*
2242 * Mac80211 does not keep IBSS bssid when leaving IBSS,
2243 * so driver need to store it. It is needed when leaving
2244 * IBSS in order to remove BSSID peer.
2245 */
2246 if (vif->type == NL80211_IFTYPE_ADHOC)
2247 memcpy(arvif->u.ibss.bssid, info->bssid,
2248 ETH_ALEN);
2249 }
2250 }
2251
2252 if (changed & BSS_CHANGED_BEACON_ENABLED)
2253 ath10k_control_beaconing(arvif, info);
2254
2255 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
2256 u32 cts_prot;
2257 if (info->use_cts_prot)
2258 cts_prot = 1;
2259 else
2260 cts_prot = 0;
2261
Kalle Valo60c3daa2013-09-08 17:56:07 +03002262 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
2263 arvif->vdev_id, cts_prot);
2264
Kalle Valo5e3dd152013-06-12 20:52:10 +03002265 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2266 WMI_VDEV_PARAM_ENABLE_RTSCTS,
2267 cts_prot);
2268 if (ret)
2269 ath10k_warn("Failed to set CTS prot for VDEV: %d\n",
2270 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002271 }
2272
2273 if (changed & BSS_CHANGED_ERP_SLOT) {
2274 u32 slottime;
2275 if (info->use_short_slot)
2276 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
2277
2278 else
2279 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
2280
Kalle Valo60c3daa2013-09-08 17:56:07 +03002281 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
2282 arvif->vdev_id, slottime);
2283
Kalle Valo5e3dd152013-06-12 20:52:10 +03002284 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2285 WMI_VDEV_PARAM_SLOT_TIME,
2286 slottime);
2287 if (ret)
2288 ath10k_warn("Failed to set erp slot for VDEV: %d\n",
2289 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002290 }
2291
2292 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
2293 u32 preamble;
2294 if (info->use_short_preamble)
2295 preamble = WMI_VDEV_PREAMBLE_SHORT;
2296 else
2297 preamble = WMI_VDEV_PREAMBLE_LONG;
2298
Kalle Valo60c3daa2013-09-08 17:56:07 +03002299 ath10k_dbg(ATH10K_DBG_MAC,
2300 "mac vdev %d preamble %dn",
2301 arvif->vdev_id, preamble);
2302
Kalle Valo5e3dd152013-06-12 20:52:10 +03002303 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2304 WMI_VDEV_PARAM_PREAMBLE,
2305 preamble);
2306 if (ret)
2307 ath10k_warn("Failed to set preamble for VDEV: %d\n",
2308 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002309 }
2310
2311 if (changed & BSS_CHANGED_ASSOC) {
2312 if (info->assoc)
2313 ath10k_bss_assoc(hw, vif, info);
2314 }
2315
2316 mutex_unlock(&ar->conf_mutex);
2317}
2318
2319static int ath10k_hw_scan(struct ieee80211_hw *hw,
2320 struct ieee80211_vif *vif,
2321 struct cfg80211_scan_request *req)
2322{
2323 struct ath10k *ar = hw->priv;
2324 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2325 struct wmi_start_scan_arg arg;
2326 int ret = 0;
2327 int i;
2328
2329 mutex_lock(&ar->conf_mutex);
2330
2331 spin_lock_bh(&ar->data_lock);
2332 if (ar->scan.in_progress) {
2333 spin_unlock_bh(&ar->data_lock);
2334 ret = -EBUSY;
2335 goto exit;
2336 }
2337
2338 INIT_COMPLETION(ar->scan.started);
2339 INIT_COMPLETION(ar->scan.completed);
2340 ar->scan.in_progress = true;
2341 ar->scan.aborting = false;
2342 ar->scan.is_roc = false;
2343 ar->scan.vdev_id = arvif->vdev_id;
2344 spin_unlock_bh(&ar->data_lock);
2345
2346 memset(&arg, 0, sizeof(arg));
2347 ath10k_wmi_start_scan_init(ar, &arg);
2348 arg.vdev_id = arvif->vdev_id;
2349 arg.scan_id = ATH10K_SCAN_ID;
2350
2351 if (!req->no_cck)
2352 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
2353
2354 if (req->ie_len) {
2355 arg.ie_len = req->ie_len;
2356 memcpy(arg.ie, req->ie, arg.ie_len);
2357 }
2358
2359 if (req->n_ssids) {
2360 arg.n_ssids = req->n_ssids;
2361 for (i = 0; i < arg.n_ssids; i++) {
2362 arg.ssids[i].len = req->ssids[i].ssid_len;
2363 arg.ssids[i].ssid = req->ssids[i].ssid;
2364 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02002365 } else {
2366 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002367 }
2368
2369 if (req->n_channels) {
2370 arg.n_channels = req->n_channels;
2371 for (i = 0; i < arg.n_channels; i++)
2372 arg.channels[i] = req->channels[i]->center_freq;
2373 }
2374
2375 ret = ath10k_start_scan(ar, &arg);
2376 if (ret) {
2377 ath10k_warn("could not start hw scan (%d)\n", ret);
2378 spin_lock_bh(&ar->data_lock);
2379 ar->scan.in_progress = false;
2380 spin_unlock_bh(&ar->data_lock);
2381 }
2382
2383exit:
2384 mutex_unlock(&ar->conf_mutex);
2385 return ret;
2386}
2387
2388static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
2389 struct ieee80211_vif *vif)
2390{
2391 struct ath10k *ar = hw->priv;
2392 int ret;
2393
2394 mutex_lock(&ar->conf_mutex);
2395 ret = ath10k_abort_scan(ar);
2396 if (ret) {
2397 ath10k_warn("couldn't abort scan (%d). forcefully sending scan completion to mac80211\n",
2398 ret);
2399 ieee80211_scan_completed(hw, 1 /* aborted */);
2400 }
2401 mutex_unlock(&ar->conf_mutex);
2402}
2403
2404static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2405 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
2406 struct ieee80211_key_conf *key)
2407{
2408 struct ath10k *ar = hw->priv;
2409 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2410 struct ath10k_peer *peer;
2411 const u8 *peer_addr;
2412 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
2413 key->cipher == WLAN_CIPHER_SUITE_WEP104;
2414 int ret = 0;
2415
2416 if (key->keyidx > WMI_MAX_KEY_INDEX)
2417 return -ENOSPC;
2418
2419 mutex_lock(&ar->conf_mutex);
2420
2421 if (sta)
2422 peer_addr = sta->addr;
2423 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
2424 peer_addr = vif->bss_conf.bssid;
2425 else
2426 peer_addr = vif->addr;
2427
2428 key->hw_key_idx = key->keyidx;
2429
2430 /* the peer should not disappear in mid-way (unless FW goes awry) since
2431 * we already hold conf_mutex. we just make sure its there now. */
2432 spin_lock_bh(&ar->data_lock);
2433 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
2434 spin_unlock_bh(&ar->data_lock);
2435
2436 if (!peer) {
2437 if (cmd == SET_KEY) {
2438 ath10k_warn("cannot install key for non-existent peer %pM\n",
2439 peer_addr);
2440 ret = -EOPNOTSUPP;
2441 goto exit;
2442 } else {
2443 /* if the peer doesn't exist there is no key to disable
2444 * anymore */
2445 goto exit;
2446 }
2447 }
2448
2449 if (is_wep) {
2450 if (cmd == SET_KEY)
2451 arvif->wep_keys[key->keyidx] = key;
2452 else
2453 arvif->wep_keys[key->keyidx] = NULL;
2454
2455 if (cmd == DISABLE_KEY)
2456 ath10k_clear_vdev_key(arvif, key);
2457 }
2458
2459 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
2460 if (ret) {
2461 ath10k_warn("ath10k_install_key failed (%d)\n", ret);
2462 goto exit;
2463 }
2464
2465 spin_lock_bh(&ar->data_lock);
2466 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
2467 if (peer && cmd == SET_KEY)
2468 peer->keys[key->keyidx] = key;
2469 else if (peer && cmd == DISABLE_KEY)
2470 peer->keys[key->keyidx] = NULL;
2471 else if (peer == NULL)
2472 /* impossible unless FW goes crazy */
2473 ath10k_warn("peer %pM disappeared!\n", peer_addr);
2474 spin_unlock_bh(&ar->data_lock);
2475
2476exit:
2477 mutex_unlock(&ar->conf_mutex);
2478 return ret;
2479}
2480
2481static int ath10k_sta_state(struct ieee80211_hw *hw,
2482 struct ieee80211_vif *vif,
2483 struct ieee80211_sta *sta,
2484 enum ieee80211_sta_state old_state,
2485 enum ieee80211_sta_state new_state)
2486{
2487 struct ath10k *ar = hw->priv;
2488 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2489 int ret = 0;
2490
2491 mutex_lock(&ar->conf_mutex);
2492
2493 if (old_state == IEEE80211_STA_NOTEXIST &&
2494 new_state == IEEE80211_STA_NONE &&
2495 vif->type != NL80211_IFTYPE_STATION) {
2496 /*
2497 * New station addition.
2498 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03002499 ath10k_dbg(ATH10K_DBG_MAC,
2500 "mac vdev %d peer create %pM (new sta)\n",
2501 arvif->vdev_id, sta->addr);
2502
Kalle Valo5e3dd152013-06-12 20:52:10 +03002503 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
2504 if (ret)
2505 ath10k_warn("Failed to add peer: %pM for VDEV: %d\n",
2506 sta->addr, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002507 } else if ((old_state == IEEE80211_STA_NONE &&
2508 new_state == IEEE80211_STA_NOTEXIST)) {
2509 /*
2510 * Existing station deletion.
2511 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03002512 ath10k_dbg(ATH10K_DBG_MAC,
2513 "mac vdev %d peer delete %pM (sta gone)\n",
2514 arvif->vdev_id, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002515 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
2516 if (ret)
2517 ath10k_warn("Failed to delete peer: %pM for VDEV: %d\n",
2518 sta->addr, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002519
2520 if (vif->type == NL80211_IFTYPE_STATION)
2521 ath10k_bss_disassoc(hw, vif);
2522 } else if (old_state == IEEE80211_STA_AUTH &&
2523 new_state == IEEE80211_STA_ASSOC &&
2524 (vif->type == NL80211_IFTYPE_AP ||
2525 vif->type == NL80211_IFTYPE_ADHOC)) {
2526 /*
2527 * New association.
2528 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03002529 ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM associated\n",
2530 sta->addr);
2531
Kalle Valo5e3dd152013-06-12 20:52:10 +03002532 ret = ath10k_station_assoc(ar, arvif, sta);
2533 if (ret)
2534 ath10k_warn("Failed to associate station: %pM\n",
2535 sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002536 } else if (old_state == IEEE80211_STA_ASSOC &&
2537 new_state == IEEE80211_STA_AUTH &&
2538 (vif->type == NL80211_IFTYPE_AP ||
2539 vif->type == NL80211_IFTYPE_ADHOC)) {
2540 /*
2541 * Disassociation.
2542 */
Kalle Valo60c3daa2013-09-08 17:56:07 +03002543 ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
2544 sta->addr);
2545
Kalle Valo5e3dd152013-06-12 20:52:10 +03002546 ret = ath10k_station_disassoc(ar, arvif, sta);
2547 if (ret)
2548 ath10k_warn("Failed to disassociate station: %pM\n",
2549 sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002550 }
2551
2552 mutex_unlock(&ar->conf_mutex);
2553 return ret;
2554}
2555
2556static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
2557 u16 ac, bool enable)
2558{
2559 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2560 u32 value = 0;
2561 int ret = 0;
2562
Michal Kazior548db542013-07-05 16:15:15 +03002563 lockdep_assert_held(&ar->conf_mutex);
2564
Kalle Valo5e3dd152013-06-12 20:52:10 +03002565 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
2566 return 0;
2567
2568 switch (ac) {
2569 case IEEE80211_AC_VO:
2570 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
2571 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
2572 break;
2573 case IEEE80211_AC_VI:
2574 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
2575 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
2576 break;
2577 case IEEE80211_AC_BE:
2578 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
2579 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
2580 break;
2581 case IEEE80211_AC_BK:
2582 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
2583 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
2584 break;
2585 }
2586
2587 if (enable)
2588 arvif->u.sta.uapsd |= value;
2589 else
2590 arvif->u.sta.uapsd &= ~value;
2591
2592 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2593 WMI_STA_PS_PARAM_UAPSD,
2594 arvif->u.sta.uapsd);
2595 if (ret) {
2596 ath10k_warn("could not set uapsd params %d\n", ret);
2597 goto exit;
2598 }
2599
2600 if (arvif->u.sta.uapsd)
2601 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
2602 else
2603 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2604
2605 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2606 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
2607 value);
2608 if (ret)
2609 ath10k_warn("could not set rx wake param %d\n", ret);
2610
2611exit:
2612 return ret;
2613}
2614
2615static int ath10k_conf_tx(struct ieee80211_hw *hw,
2616 struct ieee80211_vif *vif, u16 ac,
2617 const struct ieee80211_tx_queue_params *params)
2618{
2619 struct ath10k *ar = hw->priv;
2620 struct wmi_wmm_params_arg *p = NULL;
2621 int ret;
2622
2623 mutex_lock(&ar->conf_mutex);
2624
2625 switch (ac) {
2626 case IEEE80211_AC_VO:
2627 p = &ar->wmm_params.ac_vo;
2628 break;
2629 case IEEE80211_AC_VI:
2630 p = &ar->wmm_params.ac_vi;
2631 break;
2632 case IEEE80211_AC_BE:
2633 p = &ar->wmm_params.ac_be;
2634 break;
2635 case IEEE80211_AC_BK:
2636 p = &ar->wmm_params.ac_bk;
2637 break;
2638 }
2639
2640 if (WARN_ON(!p)) {
2641 ret = -EINVAL;
2642 goto exit;
2643 }
2644
2645 p->cwmin = params->cw_min;
2646 p->cwmax = params->cw_max;
2647 p->aifs = params->aifs;
2648
2649 /*
2650 * The channel time duration programmed in the HW is in absolute
2651 * microseconds, while mac80211 gives the txop in units of
2652 * 32 microseconds.
2653 */
2654 p->txop = params->txop * 32;
2655
2656 /* FIXME: FW accepts wmm params per hw, not per vif */
2657 ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
2658 if (ret) {
2659 ath10k_warn("could not set wmm params %d\n", ret);
2660 goto exit;
2661 }
2662
2663 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
2664 if (ret)
2665 ath10k_warn("could not set sta uapsd %d\n", ret);
2666
2667exit:
2668 mutex_unlock(&ar->conf_mutex);
2669 return ret;
2670}
2671
2672#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
2673
2674static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
2675 struct ieee80211_vif *vif,
2676 struct ieee80211_channel *chan,
2677 int duration,
2678 enum ieee80211_roc_type type)
2679{
2680 struct ath10k *ar = hw->priv;
2681 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2682 struct wmi_start_scan_arg arg;
2683 int ret;
2684
2685 mutex_lock(&ar->conf_mutex);
2686
2687 spin_lock_bh(&ar->data_lock);
2688 if (ar->scan.in_progress) {
2689 spin_unlock_bh(&ar->data_lock);
2690 ret = -EBUSY;
2691 goto exit;
2692 }
2693
2694 INIT_COMPLETION(ar->scan.started);
2695 INIT_COMPLETION(ar->scan.completed);
2696 INIT_COMPLETION(ar->scan.on_channel);
2697 ar->scan.in_progress = true;
2698 ar->scan.aborting = false;
2699 ar->scan.is_roc = true;
2700 ar->scan.vdev_id = arvif->vdev_id;
2701 ar->scan.roc_freq = chan->center_freq;
2702 spin_unlock_bh(&ar->data_lock);
2703
2704 memset(&arg, 0, sizeof(arg));
2705 ath10k_wmi_start_scan_init(ar, &arg);
2706 arg.vdev_id = arvif->vdev_id;
2707 arg.scan_id = ATH10K_SCAN_ID;
2708 arg.n_channels = 1;
2709 arg.channels[0] = chan->center_freq;
2710 arg.dwell_time_active = duration;
2711 arg.dwell_time_passive = duration;
2712 arg.max_scan_time = 2 * duration;
2713 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
2714 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
2715
2716 ret = ath10k_start_scan(ar, &arg);
2717 if (ret) {
2718 ath10k_warn("could not start roc scan (%d)\n", ret);
2719 spin_lock_bh(&ar->data_lock);
2720 ar->scan.in_progress = false;
2721 spin_unlock_bh(&ar->data_lock);
2722 goto exit;
2723 }
2724
2725 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
2726 if (ret == 0) {
2727 ath10k_warn("could not switch to channel for roc scan\n");
2728 ath10k_abort_scan(ar);
2729 ret = -ETIMEDOUT;
2730 goto exit;
2731 }
2732
2733 ret = 0;
2734exit:
2735 mutex_unlock(&ar->conf_mutex);
2736 return ret;
2737}
2738
2739static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
2740{
2741 struct ath10k *ar = hw->priv;
2742
2743 mutex_lock(&ar->conf_mutex);
2744 ath10k_abort_scan(ar);
2745 mutex_unlock(&ar->conf_mutex);
2746
2747 return 0;
2748}
2749
2750/*
2751 * Both RTS and Fragmentation threshold are interface-specific
2752 * in ath10k, but device-specific in mac80211.
2753 */
2754static void ath10k_set_rts_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
2755{
2756 struct ath10k_generic_iter *ar_iter = data;
2757 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2758 u32 rts = ar_iter->ar->hw->wiphy->rts_threshold;
2759
Michal Kazior548db542013-07-05 16:15:15 +03002760 lockdep_assert_held(&arvif->ar->conf_mutex);
2761
Michal Kazioraffd3212013-07-16 09:54:35 +02002762 /* During HW reconfiguration mac80211 reports all interfaces that were
2763 * running until reconfiguration was started. Since FW doesn't have any
2764 * vdevs at this point we must not iterate over this interface list.
2765 * This setting will be updated upon add_interface(). */
2766 if (ar_iter->ar->state == ATH10K_STATE_RESTARTED)
2767 return;
2768
Kalle Valo60c3daa2013-09-08 17:56:07 +03002769 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d rts_threshold %d\n",
2770 arvif->vdev_id, rts);
2771
Michal Kazior424121c2013-07-22 14:13:31 +02002772 ar_iter->ret = ath10k_mac_set_rts(arvif, rts);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002773 if (ar_iter->ret)
2774 ath10k_warn("Failed to set RTS threshold for VDEV: %d\n",
2775 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002776}
2777
2778static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
2779{
2780 struct ath10k_generic_iter ar_iter;
2781 struct ath10k *ar = hw->priv;
2782
2783 memset(&ar_iter, 0, sizeof(struct ath10k_generic_iter));
2784 ar_iter.ar = ar;
2785
2786 mutex_lock(&ar->conf_mutex);
Michal Kazior80c78c62013-07-05 16:15:03 +03002787 ieee80211_iterate_active_interfaces_atomic(
Michal Kazior671b96d2013-07-05 16:15:05 +03002788 hw, IEEE80211_IFACE_ITER_NORMAL,
Michal Kazior80c78c62013-07-05 16:15:03 +03002789 ath10k_set_rts_iter, &ar_iter);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002790 mutex_unlock(&ar->conf_mutex);
2791
2792 return ar_iter.ret;
2793}
2794
2795static void ath10k_set_frag_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
2796{
2797 struct ath10k_generic_iter *ar_iter = data;
2798 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2799 u32 frag = ar_iter->ar->hw->wiphy->frag_threshold;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002800
Michal Kazior548db542013-07-05 16:15:15 +03002801 lockdep_assert_held(&arvif->ar->conf_mutex);
2802
Michal Kazioraffd3212013-07-16 09:54:35 +02002803 /* During HW reconfiguration mac80211 reports all interfaces that were
2804 * running until reconfiguration was started. Since FW doesn't have any
2805 * vdevs at this point we must not iterate over this interface list.
2806 * This setting will be updated upon add_interface(). */
2807 if (ar_iter->ar->state == ATH10K_STATE_RESTARTED)
2808 return;
2809
Kalle Valo60c3daa2013-09-08 17:56:07 +03002810 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d fragmentation_threshold %d\n",
2811 arvif->vdev_id, frag);
2812
Michal Kazior424121c2013-07-22 14:13:31 +02002813 ar_iter->ret = ath10k_mac_set_frag(arvif, frag);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002814 if (ar_iter->ret)
2815 ath10k_warn("Failed to set frag threshold for VDEV: %d\n",
2816 arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002817}
2818
2819static int ath10k_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
2820{
2821 struct ath10k_generic_iter ar_iter;
2822 struct ath10k *ar = hw->priv;
2823
2824 memset(&ar_iter, 0, sizeof(struct ath10k_generic_iter));
2825 ar_iter.ar = ar;
2826
2827 mutex_lock(&ar->conf_mutex);
Michal Kazior80c78c62013-07-05 16:15:03 +03002828 ieee80211_iterate_active_interfaces_atomic(
Michal Kazior671b96d2013-07-05 16:15:05 +03002829 hw, IEEE80211_IFACE_ITER_NORMAL,
Michal Kazior80c78c62013-07-05 16:15:03 +03002830 ath10k_set_frag_iter, &ar_iter);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002831 mutex_unlock(&ar->conf_mutex);
2832
2833 return ar_iter.ret;
2834}
2835
2836static void ath10k_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
2837{
2838 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02002839 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002840 int ret;
2841
2842 /* mac80211 doesn't care if we really xmit queued frames or not
2843 * we'll collect those frames either way if we stop/delete vdevs */
2844 if (drop)
2845 return;
2846
Michal Kazior548db542013-07-05 16:15:15 +03002847 mutex_lock(&ar->conf_mutex);
2848
Michal Kazioraffd3212013-07-16 09:54:35 +02002849 if (ar->state == ATH10K_STATE_WEDGED)
2850 goto skip;
2851
Michal Kazioredb82362013-07-05 16:15:14 +03002852 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03002853 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02002854
Michal Kazioredb82362013-07-05 16:15:14 +03002855 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02002856 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03002857 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02002858
2859 skip = (ar->state == ATH10K_STATE_WEDGED);
2860
2861 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002862 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02002863
2864 if (ret <= 0 || skip)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002865 ath10k_warn("tx not flushed\n");
Michal Kazior548db542013-07-05 16:15:15 +03002866
Michal Kazioraffd3212013-07-16 09:54:35 +02002867skip:
Michal Kazior548db542013-07-05 16:15:15 +03002868 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002869}
2870
2871/* TODO: Implement this function properly
2872 * For now it is needed to reply to Probe Requests in IBSS mode.
2873 * Propably we need this information from FW.
2874 */
2875static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
2876{
2877 return 1;
2878}
2879
Michal Kazior8cd13ca2013-07-16 09:38:54 +02002880#ifdef CONFIG_PM
2881static int ath10k_suspend(struct ieee80211_hw *hw,
2882 struct cfg80211_wowlan *wowlan)
2883{
2884 struct ath10k *ar = hw->priv;
2885 int ret;
2886
2887 ar->is_target_paused = false;
2888
2889 ret = ath10k_wmi_pdev_suspend_target(ar);
2890 if (ret) {
2891 ath10k_warn("could not suspend target (%d)\n", ret);
2892 return 1;
2893 }
2894
2895 ret = wait_event_interruptible_timeout(ar->event_queue,
2896 ar->is_target_paused == true,
2897 1 * HZ);
2898 if (ret < 0) {
2899 ath10k_warn("suspend interrupted (%d)\n", ret);
2900 goto resume;
2901 } else if (ret == 0) {
2902 ath10k_warn("suspend timed out - target pause event never came\n");
2903 goto resume;
2904 }
2905
2906 ret = ath10k_hif_suspend(ar);
2907 if (ret) {
2908 ath10k_warn("could not suspend hif (%d)\n", ret);
2909 goto resume;
2910 }
2911
2912 return 0;
2913resume:
2914 ret = ath10k_wmi_pdev_resume_target(ar);
2915 if (ret)
2916 ath10k_warn("could not resume target (%d)\n", ret);
2917 return 1;
2918}
2919
2920static int ath10k_resume(struct ieee80211_hw *hw)
2921{
2922 struct ath10k *ar = hw->priv;
2923 int ret;
2924
2925 ret = ath10k_hif_resume(ar);
2926 if (ret) {
2927 ath10k_warn("could not resume hif (%d)\n", ret);
2928 return 1;
2929 }
2930
2931 ret = ath10k_wmi_pdev_resume_target(ar);
2932 if (ret) {
2933 ath10k_warn("could not resume target (%d)\n", ret);
2934 return 1;
2935 }
2936
2937 return 0;
2938}
2939#endif
2940
Michal Kazioraffd3212013-07-16 09:54:35 +02002941static void ath10k_restart_complete(struct ieee80211_hw *hw)
2942{
2943 struct ath10k *ar = hw->priv;
2944
2945 mutex_lock(&ar->conf_mutex);
2946
2947 /* If device failed to restart it will be in a different state, e.g.
2948 * ATH10K_STATE_WEDGED */
2949 if (ar->state == ATH10K_STATE_RESTARTED) {
2950 ath10k_info("device successfully recovered\n");
2951 ar->state = ATH10K_STATE_ON;
2952 }
2953
2954 mutex_unlock(&ar->conf_mutex);
2955}
2956
Michal Kazior2e1dea42013-07-31 10:32:40 +02002957static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
2958 struct survey_info *survey)
2959{
2960 struct ath10k *ar = hw->priv;
2961 struct ieee80211_supported_band *sband;
2962 struct survey_info *ar_survey = &ar->survey[idx];
2963 int ret = 0;
2964
2965 mutex_lock(&ar->conf_mutex);
2966
2967 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
2968 if (sband && idx >= sband->n_channels) {
2969 idx -= sband->n_channels;
2970 sband = NULL;
2971 }
2972
2973 if (!sband)
2974 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
2975
2976 if (!sband || idx >= sband->n_channels) {
2977 ret = -ENOENT;
2978 goto exit;
2979 }
2980
2981 spin_lock_bh(&ar->data_lock);
2982 memcpy(survey, ar_survey, sizeof(*survey));
2983 spin_unlock_bh(&ar->data_lock);
2984
2985 survey->channel = &sband->channels[idx];
2986
2987exit:
2988 mutex_unlock(&ar->conf_mutex);
2989 return ret;
2990}
2991
Kalle Valo5e3dd152013-06-12 20:52:10 +03002992static const struct ieee80211_ops ath10k_ops = {
2993 .tx = ath10k_tx,
2994 .start = ath10k_start,
2995 .stop = ath10k_stop,
2996 .config = ath10k_config,
2997 .add_interface = ath10k_add_interface,
2998 .remove_interface = ath10k_remove_interface,
2999 .configure_filter = ath10k_configure_filter,
3000 .bss_info_changed = ath10k_bss_info_changed,
3001 .hw_scan = ath10k_hw_scan,
3002 .cancel_hw_scan = ath10k_cancel_hw_scan,
3003 .set_key = ath10k_set_key,
3004 .sta_state = ath10k_sta_state,
3005 .conf_tx = ath10k_conf_tx,
3006 .remain_on_channel = ath10k_remain_on_channel,
3007 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
3008 .set_rts_threshold = ath10k_set_rts_threshold,
3009 .set_frag_threshold = ath10k_set_frag_threshold,
3010 .flush = ath10k_flush,
3011 .tx_last_beacon = ath10k_tx_last_beacon,
Michal Kazioraffd3212013-07-16 09:54:35 +02003012 .restart_complete = ath10k_restart_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02003013 .get_survey = ath10k_get_survey,
Michal Kazior8cd13ca2013-07-16 09:38:54 +02003014#ifdef CONFIG_PM
3015 .suspend = ath10k_suspend,
3016 .resume = ath10k_resume,
3017#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03003018};
3019
3020#define RATETAB_ENT(_rate, _rateid, _flags) { \
3021 .bitrate = (_rate), \
3022 .flags = (_flags), \
3023 .hw_value = (_rateid), \
3024}
3025
3026#define CHAN2G(_channel, _freq, _flags) { \
3027 .band = IEEE80211_BAND_2GHZ, \
3028 .hw_value = (_channel), \
3029 .center_freq = (_freq), \
3030 .flags = (_flags), \
3031 .max_antenna_gain = 0, \
3032 .max_power = 30, \
3033}
3034
3035#define CHAN5G(_channel, _freq, _flags) { \
3036 .band = IEEE80211_BAND_5GHZ, \
3037 .hw_value = (_channel), \
3038 .center_freq = (_freq), \
3039 .flags = (_flags), \
3040 .max_antenna_gain = 0, \
3041 .max_power = 30, \
3042}
3043
3044static const struct ieee80211_channel ath10k_2ghz_channels[] = {
3045 CHAN2G(1, 2412, 0),
3046 CHAN2G(2, 2417, 0),
3047 CHAN2G(3, 2422, 0),
3048 CHAN2G(4, 2427, 0),
3049 CHAN2G(5, 2432, 0),
3050 CHAN2G(6, 2437, 0),
3051 CHAN2G(7, 2442, 0),
3052 CHAN2G(8, 2447, 0),
3053 CHAN2G(9, 2452, 0),
3054 CHAN2G(10, 2457, 0),
3055 CHAN2G(11, 2462, 0),
3056 CHAN2G(12, 2467, 0),
3057 CHAN2G(13, 2472, 0),
3058 CHAN2G(14, 2484, 0),
3059};
3060
3061static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02003062 CHAN5G(36, 5180, 0),
3063 CHAN5G(40, 5200, 0),
3064 CHAN5G(44, 5220, 0),
3065 CHAN5G(48, 5240, 0),
3066 CHAN5G(52, 5260, 0),
3067 CHAN5G(56, 5280, 0),
3068 CHAN5G(60, 5300, 0),
3069 CHAN5G(64, 5320, 0),
3070 CHAN5G(100, 5500, 0),
3071 CHAN5G(104, 5520, 0),
3072 CHAN5G(108, 5540, 0),
3073 CHAN5G(112, 5560, 0),
3074 CHAN5G(116, 5580, 0),
3075 CHAN5G(120, 5600, 0),
3076 CHAN5G(124, 5620, 0),
3077 CHAN5G(128, 5640, 0),
3078 CHAN5G(132, 5660, 0),
3079 CHAN5G(136, 5680, 0),
3080 CHAN5G(140, 5700, 0),
3081 CHAN5G(149, 5745, 0),
3082 CHAN5G(153, 5765, 0),
3083 CHAN5G(157, 5785, 0),
3084 CHAN5G(161, 5805, 0),
3085 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03003086};
3087
3088static struct ieee80211_rate ath10k_rates[] = {
3089 /* CCK */
3090 RATETAB_ENT(10, 0x82, 0),
3091 RATETAB_ENT(20, 0x84, 0),
3092 RATETAB_ENT(55, 0x8b, 0),
3093 RATETAB_ENT(110, 0x96, 0),
3094 /* OFDM */
3095 RATETAB_ENT(60, 0x0c, 0),
3096 RATETAB_ENT(90, 0x12, 0),
3097 RATETAB_ENT(120, 0x18, 0),
3098 RATETAB_ENT(180, 0x24, 0),
3099 RATETAB_ENT(240, 0x30, 0),
3100 RATETAB_ENT(360, 0x48, 0),
3101 RATETAB_ENT(480, 0x60, 0),
3102 RATETAB_ENT(540, 0x6c, 0),
3103};
3104
3105#define ath10k_a_rates (ath10k_rates + 4)
3106#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
3107#define ath10k_g_rates (ath10k_rates + 0)
3108#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
3109
3110struct ath10k *ath10k_mac_create(void)
3111{
3112 struct ieee80211_hw *hw;
3113 struct ath10k *ar;
3114
3115 hw = ieee80211_alloc_hw(sizeof(struct ath10k), &ath10k_ops);
3116 if (!hw)
3117 return NULL;
3118
3119 ar = hw->priv;
3120 ar->hw = hw;
3121
3122 return ar;
3123}
3124
3125void ath10k_mac_destroy(struct ath10k *ar)
3126{
3127 ieee80211_free_hw(ar->hw);
3128}
3129
3130static const struct ieee80211_iface_limit ath10k_if_limits[] = {
3131 {
3132 .max = 8,
3133 .types = BIT(NL80211_IFTYPE_STATION)
3134 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02003135 },
3136 {
3137 .max = 3,
3138 .types = BIT(NL80211_IFTYPE_P2P_GO)
3139 },
3140 {
3141 .max = 7,
3142 .types = BIT(NL80211_IFTYPE_AP)
3143 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03003144};
3145
3146static const struct ieee80211_iface_combination ath10k_if_comb = {
3147 .limits = ath10k_if_limits,
3148 .n_limits = ARRAY_SIZE(ath10k_if_limits),
3149 .max_interfaces = 8,
3150 .num_different_channels = 1,
3151 .beacon_int_infra_match = true,
3152};
3153
3154static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
3155{
3156 struct ieee80211_sta_vht_cap vht_cap = {0};
3157 u16 mcs_map;
Michal Kazior8865bee42013-07-24 12:36:46 +02003158 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003159
3160 vht_cap.vht_supported = 1;
3161 vht_cap.cap = ar->vht_cap_info;
3162
Michal Kazior8865bee42013-07-24 12:36:46 +02003163 mcs_map = 0;
3164 for (i = 0; i < 8; i++) {
3165 if (i < ar->num_rf_chains)
3166 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
3167 else
3168 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
3169 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003170
3171 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
3172 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
3173
3174 return vht_cap;
3175}
3176
3177static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
3178{
3179 int i;
3180 struct ieee80211_sta_ht_cap ht_cap = {0};
3181
3182 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
3183 return ht_cap;
3184
3185 ht_cap.ht_supported = 1;
3186 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
3187 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
3188 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
3189 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
3190 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
3191
3192 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
3193 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
3194
3195 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
3196 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
3197
3198 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
3199 u32 smps;
3200
3201 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
3202 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
3203
3204 ht_cap.cap |= smps;
3205 }
3206
3207 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
3208 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
3209
3210 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
3211 u32 stbc;
3212
3213 stbc = ar->ht_cap_info;
3214 stbc &= WMI_HT_CAP_RX_STBC;
3215 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
3216 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
3217 stbc &= IEEE80211_HT_CAP_RX_STBC;
3218
3219 ht_cap.cap |= stbc;
3220 }
3221
3222 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
3223 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
3224
3225 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
3226 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
3227
3228 /* max AMSDU is implicitly taken from vht_cap_info */
3229 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
3230 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
3231
Michal Kazior8865bee42013-07-24 12:36:46 +02003232 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003233 ht_cap.mcs.rx_mask[i] = 0xFF;
3234
3235 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
3236
3237 return ht_cap;
3238}
3239
3240
3241static void ath10k_get_arvif_iter(void *data, u8 *mac,
3242 struct ieee80211_vif *vif)
3243{
3244 struct ath10k_vif_iter *arvif_iter = data;
3245 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3246
3247 if (arvif->vdev_id == arvif_iter->vdev_id)
3248 arvif_iter->arvif = arvif;
3249}
3250
3251struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
3252{
3253 struct ath10k_vif_iter arvif_iter;
3254 u32 flags;
3255
3256 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
3257 arvif_iter.vdev_id = vdev_id;
3258
3259 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
3260 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3261 flags,
3262 ath10k_get_arvif_iter,
3263 &arvif_iter);
3264 if (!arvif_iter.arvif) {
3265 ath10k_warn("No VIF found for VDEV: %d\n", vdev_id);
3266 return NULL;
3267 }
3268
3269 return arvif_iter.arvif;
3270}
3271
3272int ath10k_mac_register(struct ath10k *ar)
3273{
3274 struct ieee80211_supported_band *band;
3275 struct ieee80211_sta_vht_cap vht_cap;
3276 struct ieee80211_sta_ht_cap ht_cap;
3277 void *channels;
3278 int ret;
3279
3280 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
3281
3282 SET_IEEE80211_DEV(ar->hw, ar->dev);
3283
3284 ht_cap = ath10k_get_ht_cap(ar);
3285 vht_cap = ath10k_create_vht_cap(ar);
3286
3287 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
3288 channels = kmemdup(ath10k_2ghz_channels,
3289 sizeof(ath10k_2ghz_channels),
3290 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02003291 if (!channels) {
3292 ret = -ENOMEM;
3293 goto err_free;
3294 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003295
3296 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
3297 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
3298 band->channels = channels;
3299 band->n_bitrates = ath10k_g_rates_size;
3300 band->bitrates = ath10k_g_rates;
3301 band->ht_cap = ht_cap;
3302
3303 /* vht is not supported in 2.4 GHz */
3304
3305 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
3306 }
3307
3308 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
3309 channels = kmemdup(ath10k_5ghz_channels,
3310 sizeof(ath10k_5ghz_channels),
3311 GFP_KERNEL);
3312 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02003313 ret = -ENOMEM;
3314 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003315 }
3316
3317 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
3318 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
3319 band->channels = channels;
3320 band->n_bitrates = ath10k_a_rates_size;
3321 band->bitrates = ath10k_a_rates;
3322 band->ht_cap = ht_cap;
3323 band->vht_cap = vht_cap;
3324 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
3325 }
3326
3327 ar->hw->wiphy->interface_modes =
3328 BIT(NL80211_IFTYPE_STATION) |
3329 BIT(NL80211_IFTYPE_ADHOC) |
3330 BIT(NL80211_IFTYPE_AP) |
3331 BIT(NL80211_IFTYPE_P2P_CLIENT) |
3332 BIT(NL80211_IFTYPE_P2P_GO);
3333
3334 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
3335 IEEE80211_HW_SUPPORTS_PS |
3336 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
3337 IEEE80211_HW_SUPPORTS_UAPSD |
3338 IEEE80211_HW_MFP_CAPABLE |
3339 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
3340 IEEE80211_HW_HAS_RATE_CONTROL |
3341 IEEE80211_HW_SUPPORTS_STATIC_SMPS |
3342 IEEE80211_HW_WANT_MONITOR_VIF |
3343 IEEE80211_HW_AP_LINK_PS;
3344
Michal Kazior1f8bb152013-09-18 14:43:22 +02003345 /* MSDU can have HTT TX fragment pushed in front. The additional 4
3346 * bytes is used for padding/alignment if necessary. */
3347 ar->hw->extra_tx_headroom += sizeof(struct htt_data_tx_desc_frag)*2 + 4;
3348
Kalle Valo5e3dd152013-06-12 20:52:10 +03003349 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
3350 ar->hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS;
3351
3352 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
3353 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
3354 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
3355 }
3356
3357 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
3358 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
3359
3360 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
3361
3362 ar->hw->channel_change_time = 5000;
3363 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
3364
3365 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
3366 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
3367
3368 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
3369 /*
3370 * on LL hardware queues are managed entirely by the FW
3371 * so we only advertise to mac we can do the queues thing
3372 */
3373 ar->hw->queues = 4;
3374
3375 ar->hw->wiphy->iface_combinations = &ath10k_if_comb;
3376 ar->hw->wiphy->n_iface_combinations = 1;
3377
Michal Kazior7c199992013-07-31 10:47:57 +02003378 ar->hw->netdev_features = NETIF_F_HW_CSUM;
3379
Kalle Valo5e3dd152013-06-12 20:52:10 +03003380 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
3381 ath10k_reg_notifier);
3382 if (ret) {
3383 ath10k_err("Regulatory initialization failed\n");
Michal Kaziord6015b22013-07-22 14:13:30 +02003384 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003385 }
3386
3387 ret = ieee80211_register_hw(ar->hw);
3388 if (ret) {
3389 ath10k_err("ieee80211 registration failed: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02003390 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003391 }
3392
3393 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
3394 ret = regulatory_hint(ar->hw->wiphy,
3395 ar->ath_common.regulatory.alpha2);
3396 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02003397 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003398 }
3399
3400 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02003401
3402err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03003403 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02003404err_free:
3405 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
3406 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
3407
Kalle Valo5e3dd152013-06-12 20:52:10 +03003408 return ret;
3409}
3410
3411void ath10k_mac_unregister(struct ath10k *ar)
3412{
3413 ieee80211_unregister_hw(ar->hw);
3414
3415 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
3416 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
3417
3418 SET_IEEE80211_DEV(ar->hw, NULL);
3419}