ath10k: Initialize list-head on vif creation.
[deliverable/linux.git] / drivers / net / wireless / ath / ath10k / mac.c
CommitLineData
5e3dd157
KV
1/*
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
8cd13cad 23#include "hif.h"
5e3dd157
KV
24#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
548db54c
MK
47 lockdep_assert_held(&arvif->ar->conf_mutex);
48
5e3dd157
KV
49 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:
5e3dd157
KV
60 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
548db54c
MK
93 lockdep_assert_held(&ar->conf_mutex);
94
5e3dd157
KV
95 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;
0f817ed5
JL
244 case NL80211_CHAN_WIDTH_5:
245 case NL80211_CHAN_WIDTH_10:
5e3dd157
KV
246 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;
0f817ed5
JL
267 case NL80211_CHAN_WIDTH_5:
268 case NL80211_CHAN_WIDTH_10:
5e3dd157
KV
269 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
424121c3
MK
335static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
336{
6d1506e7
BM
337 struct ath10k *ar = arvif->ar;
338 u32 vdev_param;
339
424121c3
MK
340 if (value != 0xFFFFFFFF)
341 value = min_t(u32, arvif->ar->hw->wiphy->rts_threshold,
342 ATH10K_RTS_MAX);
343
6d1506e7
BM
344 vdev_param = ar->wmi.vdev_param->rts_threshold;
345 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
424121c3
MK
346}
347
348static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
349{
6d1506e7
BM
350 struct ath10k *ar = arvif->ar;
351 u32 vdev_param;
352
424121c3
MK
353 if (value != 0xFFFFFFFF)
354 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
355 ATH10K_FRAGMT_THRESHOLD_MIN,
356 ATH10K_FRAGMT_THRESHOLD_MAX);
357
6d1506e7
BM
358 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
359 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
424121c3
MK
360}
361
5e3dd157
KV
362static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
363{
364 int ret;
365
366 lockdep_assert_held(&ar->conf_mutex);
367
368 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
369 if (ret)
370 return ret;
371
372 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
373 if (ret)
374 return ret;
375
376 return 0;
377}
378
379static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
380{
381 struct ath10k_peer *peer, *tmp;
382
383 lockdep_assert_held(&ar->conf_mutex);
384
385 spin_lock_bh(&ar->data_lock);
386 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
387 if (peer->vdev_id != vdev_id)
388 continue;
389
390 ath10k_warn("removing stale peer %pM from vdev_id %d\n",
391 peer->addr, vdev_id);
392
393 list_del(&peer->list);
394 kfree(peer);
395 }
396 spin_unlock_bh(&ar->data_lock);
397}
398
a96d7745
MK
399static void ath10k_peer_cleanup_all(struct ath10k *ar)
400{
401 struct ath10k_peer *peer, *tmp;
402
403 lockdep_assert_held(&ar->conf_mutex);
404
405 spin_lock_bh(&ar->data_lock);
406 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
407 list_del(&peer->list);
408 kfree(peer);
409 }
410 spin_unlock_bh(&ar->data_lock);
411}
412
5e3dd157
KV
413/************************/
414/* Interface management */
415/************************/
416
417static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
418{
419 int ret;
420
548db54c
MK
421 lockdep_assert_held(&ar->conf_mutex);
422
5e3dd157
KV
423 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
424 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
425 if (ret == 0)
426 return -ETIMEDOUT;
427
428 return 0;
429}
430
431static int ath10k_vdev_start(struct ath10k_vif *arvif)
432{
433 struct ath10k *ar = arvif->ar;
434 struct ieee80211_conf *conf = &ar->hw->conf;
435 struct ieee80211_channel *channel = conf->chandef.chan;
436 struct wmi_vdev_start_request_arg arg = {};
437 int ret = 0;
438
439 lockdep_assert_held(&ar->conf_mutex);
440
441 INIT_COMPLETION(ar->vdev_setup_done);
442
443 arg.vdev_id = arvif->vdev_id;
444 arg.dtim_period = arvif->dtim_period;
445 arg.bcn_intval = arvif->beacon_interval;
446
447 arg.channel.freq = channel->center_freq;
448
449 arg.channel.band_center_freq1 = conf->chandef.center_freq1;
450
451 arg.channel.mode = chan_to_phymode(&conf->chandef);
452
453 arg.channel.min_power = channel->max_power * 3;
454 arg.channel.max_power = channel->max_power * 4;
455 arg.channel.max_reg_power = channel->max_reg_power * 4;
456 arg.channel.max_antenna_gain = channel->max_antenna_gain;
457
458 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
459 arg.ssid = arvif->u.ap.ssid;
460 arg.ssid_len = arvif->u.ap.ssid_len;
461 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
462 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
463 arg.ssid = arvif->vif->bss_conf.ssid;
464 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
465 }
466
38a1d47e
KV
467 ath10k_dbg(ATH10K_DBG_MAC,
468 "mac vdev %d start center_freq %d phymode %s\n",
469 arg.vdev_id, arg.channel.freq,
470 ath10k_wmi_phymode_str(arg.channel.mode));
471
5e3dd157
KV
472 ret = ath10k_wmi_vdev_start(ar, &arg);
473 if (ret) {
474 ath10k_warn("WMI vdev start failed: ret %d\n", ret);
475 return ret;
476 }
477
478 ret = ath10k_vdev_setup_sync(ar);
479 if (ret) {
480 ath10k_warn("vdev setup failed %d\n", ret);
481 return ret;
482 }
483
484 return ret;
485}
486
487static int ath10k_vdev_stop(struct ath10k_vif *arvif)
488{
489 struct ath10k *ar = arvif->ar;
490 int ret;
491
492 lockdep_assert_held(&ar->conf_mutex);
493
494 INIT_COMPLETION(ar->vdev_setup_done);
495
496 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
497 if (ret) {
498 ath10k_warn("WMI vdev stop failed: ret %d\n", ret);
499 return ret;
500 }
501
502 ret = ath10k_vdev_setup_sync(ar);
503 if (ret) {
504 ath10k_warn("vdev setup failed %d\n", ret);
505 return ret;
506 }
507
508 return ret;
509}
510
511static int ath10k_monitor_start(struct ath10k *ar, int vdev_id)
512{
513 struct ieee80211_channel *channel = ar->hw->conf.chandef.chan;
514 struct wmi_vdev_start_request_arg arg = {};
5e3dd157
KV
515 int ret = 0;
516
517 lockdep_assert_held(&ar->conf_mutex);
518
0ed00eea
MK
519 if (!ar->monitor_present) {
520 ath10k_warn("mac montor stop -- monitor is not present\n");
521 return -EINVAL;
522 }
523
5e3dd157
KV
524 arg.vdev_id = vdev_id;
525 arg.channel.freq = channel->center_freq;
526 arg.channel.band_center_freq1 = ar->hw->conf.chandef.center_freq1;
527
528 /* TODO setup this dynamically, what in case we
529 don't have any vifs? */
530 arg.channel.mode = chan_to_phymode(&ar->hw->conf.chandef);
531
532 arg.channel.min_power = channel->max_power * 3;
533 arg.channel.max_power = channel->max_power * 4;
534 arg.channel.max_reg_power = channel->max_reg_power * 4;
535 arg.channel.max_antenna_gain = channel->max_antenna_gain;
536
537 ret = ath10k_wmi_vdev_start(ar, &arg);
538 if (ret) {
539 ath10k_warn("Monitor vdev start failed: ret %d\n", ret);
540 return ret;
541 }
542
543 ret = ath10k_vdev_setup_sync(ar);
544 if (ret) {
545 ath10k_warn("Monitor vdev setup failed %d\n", ret);
546 return ret;
547 }
548
549 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
550 if (ret) {
551 ath10k_warn("Monitor vdev up failed: %d\n", ret);
552 goto vdev_stop;
553 }
554
555 ar->monitor_vdev_id = vdev_id;
556 ar->monitor_enabled = true;
557
558 return 0;
559
560vdev_stop:
561 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
562 if (ret)
563 ath10k_warn("Monitor vdev stop failed: %d\n", ret);
564
565 return ret;
566}
567
568static int ath10k_monitor_stop(struct ath10k *ar)
569{
570 int ret = 0;
571
572 lockdep_assert_held(&ar->conf_mutex);
573
0ed00eea
MK
574 if (!ar->monitor_present) {
575 ath10k_warn("mac montor stop -- monitor is not present\n");
576 return -EINVAL;
577 }
578
579 if (!ar->monitor_enabled) {
580 ath10k_warn("mac montor stop -- monitor is not enabled\n");
581 return -EINVAL;
582 }
583
52fa0191
MP
584 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
585 if (ret)
586 ath10k_warn("Monitor vdev down failed: %d\n", ret);
5e3dd157
KV
587
588 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
589 if (ret)
590 ath10k_warn("Monitor vdev stop failed: %d\n", ret);
591
592 ret = ath10k_vdev_setup_sync(ar);
593 if (ret)
594 ath10k_warn("Monitor_down sync failed: %d\n", ret);
595
596 ar->monitor_enabled = false;
597 return ret;
598}
599
600static int ath10k_monitor_create(struct ath10k *ar)
601{
602 int bit, ret = 0;
603
604 lockdep_assert_held(&ar->conf_mutex);
605
606 if (ar->monitor_present) {
607 ath10k_warn("Monitor mode already enabled\n");
608 return 0;
609 }
610
611 bit = ffs(ar->free_vdev_map);
612 if (bit == 0) {
613 ath10k_warn("No free VDEV slots\n");
614 return -ENOMEM;
615 }
616
617 ar->monitor_vdev_id = bit - 1;
618 ar->free_vdev_map &= ~(1 << ar->monitor_vdev_id);
619
620 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
621 WMI_VDEV_TYPE_MONITOR,
622 0, ar->mac_addr);
623 if (ret) {
624 ath10k_warn("WMI vdev monitor create failed: ret %d\n", ret);
625 goto vdev_fail;
626 }
627
60c3daa8 628 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
5e3dd157
KV
629 ar->monitor_vdev_id);
630
631 ar->monitor_present = true;
632 return 0;
633
634vdev_fail:
635 /*
636 * Restore the ID to the global map.
637 */
638 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
639 return ret;
640}
641
642static int ath10k_monitor_destroy(struct ath10k *ar)
643{
644 int ret = 0;
645
646 lockdep_assert_held(&ar->conf_mutex);
647
648 if (!ar->monitor_present)
649 return 0;
650
651 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
652 if (ret) {
653 ath10k_warn("WMI vdev monitor delete failed: %d\n", ret);
654 return ret;
655 }
656
657 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
658 ar->monitor_present = false;
659
60c3daa8 660 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
5e3dd157
KV
661 ar->monitor_vdev_id);
662 return ret;
663}
664
665static void ath10k_control_beaconing(struct ath10k_vif *arvif,
666 struct ieee80211_bss_conf *info)
667{
668 int ret = 0;
669
548db54c
MK
670 lockdep_assert_held(&arvif->ar->conf_mutex);
671
5e3dd157
KV
672 if (!info->enable_beacon) {
673 ath10k_vdev_stop(arvif);
674 return;
675 }
676
677 arvif->tx_seq_no = 0x1000;
678
679 ret = ath10k_vdev_start(arvif);
680 if (ret)
681 return;
682
683 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, 0, info->bssid);
684 if (ret) {
685 ath10k_warn("Failed to bring up VDEV: %d\n",
686 arvif->vdev_id);
687 return;
688 }
60c3daa8 689 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
5e3dd157
KV
690}
691
692static void ath10k_control_ibss(struct ath10k_vif *arvif,
693 struct ieee80211_bss_conf *info,
694 const u8 self_peer[ETH_ALEN])
695{
6d1506e7 696 u32 vdev_param;
5e3dd157
KV
697 int ret = 0;
698
548db54c
MK
699 lockdep_assert_held(&arvif->ar->conf_mutex);
700
5e3dd157
KV
701 if (!info->ibss_joined) {
702 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
703 if (ret)
704 ath10k_warn("Failed to delete IBSS self peer:%pM for VDEV:%d ret:%d\n",
705 self_peer, arvif->vdev_id, ret);
706
707 if (is_zero_ether_addr(arvif->u.ibss.bssid))
708 return;
709
710 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id,
711 arvif->u.ibss.bssid);
712 if (ret) {
713 ath10k_warn("Failed to delete IBSS BSSID peer:%pM for VDEV:%d ret:%d\n",
714 arvif->u.ibss.bssid, arvif->vdev_id, ret);
715 return;
716 }
717
718 memset(arvif->u.ibss.bssid, 0, ETH_ALEN);
719
720 return;
721 }
722
723 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
724 if (ret) {
725 ath10k_warn("Failed to create IBSS self peer:%pM for VDEV:%d ret:%d\n",
726 self_peer, arvif->vdev_id, ret);
727 return;
728 }
729
6d1506e7
BM
730 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
731 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
5e3dd157
KV
732 ATH10K_DEFAULT_ATIM);
733 if (ret)
734 ath10k_warn("Failed to set IBSS ATIM for VDEV:%d ret:%d\n",
735 arvif->vdev_id, ret);
736}
737
738/*
739 * Review this when mac80211 gains per-interface powersave support.
740 */
ad088bfa 741static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
5e3dd157 742{
ad088bfa
MK
743 struct ath10k *ar = arvif->ar;
744 struct ieee80211_conf *conf = &ar->hw->conf;
5e3dd157
KV
745 enum wmi_sta_powersave_param param;
746 enum wmi_sta_ps_mode psmode;
747 int ret;
748
548db54c
MK
749 lockdep_assert_held(&arvif->ar->conf_mutex);
750
ad088bfa
MK
751 if (arvif->vif->type != NL80211_IFTYPE_STATION)
752 return 0;
5e3dd157
KV
753
754 if (conf->flags & IEEE80211_CONF_PS) {
755 psmode = WMI_STA_PS_MODE_ENABLED;
756 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
757
ad088bfa 758 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
5e3dd157
KV
759 conf->dynamic_ps_timeout);
760 if (ret) {
761 ath10k_warn("Failed to set inactivity time for VDEV: %d\n",
762 arvif->vdev_id);
ad088bfa 763 return ret;
5e3dd157 764 }
5e3dd157
KV
765 } else {
766 psmode = WMI_STA_PS_MODE_DISABLED;
767 }
768
60c3daa8
KV
769 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
770 arvif->vdev_id, psmode ? "enable" : "disable");
771
ad088bfa
MK
772 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
773 if (ret) {
5e3dd157
KV
774 ath10k_warn("Failed to set PS Mode: %d for VDEV: %d\n",
775 psmode, arvif->vdev_id);
ad088bfa
MK
776 return ret;
777 }
778
779 return 0;
5e3dd157
KV
780}
781
782/**********************/
783/* Station management */
784/**********************/
785
786static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
787 struct ath10k_vif *arvif,
788 struct ieee80211_sta *sta,
789 struct ieee80211_bss_conf *bss_conf,
790 struct wmi_peer_assoc_complete_arg *arg)
791{
548db54c
MK
792 lockdep_assert_held(&ar->conf_mutex);
793
5e3dd157
KV
794 memcpy(arg->addr, sta->addr, ETH_ALEN);
795 arg->vdev_id = arvif->vdev_id;
796 arg->peer_aid = sta->aid;
797 arg->peer_flags |= WMI_PEER_AUTH;
798
799 if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
800 /*
801 * Seems FW have problems with Power Save in STA
802 * mode when we setup this parameter to high (eg. 5).
803 * Often we see that FW don't send NULL (with clean P flags)
804 * frame even there is info about buffered frames in beacons.
805 * Sometimes we have to wait more than 10 seconds before FW
806 * will wakeup. Often sending one ping from AP to our device
807 * just fail (more than 50%).
808 *
809 * Seems setting this FW parameter to 1 couse FW
810 * will check every beacon and will wakup immediately
811 * after detection buffered data.
812 */
813 arg->peer_listen_intval = 1;
814 else
815 arg->peer_listen_intval = ar->hw->conf.listen_interval;
816
817 arg->peer_num_spatial_streams = 1;
818
819 /*
820 * The assoc capabilities are available only in managed mode.
821 */
822 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && bss_conf)
823 arg->peer_caps = bss_conf->assoc_capability;
824}
825
826static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
827 struct ath10k_vif *arvif,
828 struct wmi_peer_assoc_complete_arg *arg)
829{
830 struct ieee80211_vif *vif = arvif->vif;
831 struct ieee80211_bss_conf *info = &vif->bss_conf;
832 struct cfg80211_bss *bss;
833 const u8 *rsnie = NULL;
834 const u8 *wpaie = NULL;
835
548db54c
MK
836 lockdep_assert_held(&ar->conf_mutex);
837
5e3dd157
KV
838 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
839 info->bssid, NULL, 0, 0, 0);
840 if (bss) {
841 const struct cfg80211_bss_ies *ies;
842
843 rcu_read_lock();
844 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
845
846 ies = rcu_dereference(bss->ies);
847
848 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
849 WLAN_OUI_TYPE_MICROSOFT_WPA,
850 ies->data,
851 ies->len);
852 rcu_read_unlock();
853 cfg80211_put_bss(ar->hw->wiphy, bss);
854 }
855
856 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
857 if (rsnie || wpaie) {
858 ath10k_dbg(ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
859 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
860 }
861
862 if (wpaie) {
863 ath10k_dbg(ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
864 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
865 }
866}
867
868static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
869 struct ieee80211_sta *sta,
870 struct wmi_peer_assoc_complete_arg *arg)
871{
872 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
873 const struct ieee80211_supported_band *sband;
874 const struct ieee80211_rate *rates;
875 u32 ratemask;
876 int i;
877
548db54c
MK
878 lockdep_assert_held(&ar->conf_mutex);
879
5e3dd157
KV
880 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
881 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
882 rates = sband->bitrates;
883
884 rateset->num_rates = 0;
885
886 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
887 if (!(ratemask & 1))
888 continue;
889
890 rateset->rates[rateset->num_rates] = rates->hw_value;
891 rateset->num_rates++;
892 }
893}
894
895static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
896 struct ieee80211_sta *sta,
897 struct wmi_peer_assoc_complete_arg *arg)
898{
899 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
900 int smps;
901 int i, n;
902
548db54c
MK
903 lockdep_assert_held(&ar->conf_mutex);
904
5e3dd157
KV
905 if (!ht_cap->ht_supported)
906 return;
907
908 arg->peer_flags |= WMI_PEER_HT;
909 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
910 ht_cap->ampdu_factor)) - 1;
911
912 arg->peer_mpdu_density =
913 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
914
915 arg->peer_ht_caps = ht_cap->cap;
916 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
917
918 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
919 arg->peer_flags |= WMI_PEER_LDPC;
920
921 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
922 arg->peer_flags |= WMI_PEER_40MHZ;
923 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
924 }
925
926 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
927 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
928
929 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
930 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
931
932 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
933 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
934 arg->peer_flags |= WMI_PEER_STBC;
935 }
936
937 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
938 u32 stbc;
939 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
940 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
941 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
942 arg->peer_rate_caps |= stbc;
943 arg->peer_flags |= WMI_PEER_STBC;
944 }
945
946 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
947 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
948
949 if (smps == WLAN_HT_CAP_SM_PS_STATIC) {
950 arg->peer_flags |= WMI_PEER_SPATIAL_MUX;
951 arg->peer_flags |= WMI_PEER_STATIC_MIMOPS;
952 } else if (smps == WLAN_HT_CAP_SM_PS_DYNAMIC) {
953 arg->peer_flags |= WMI_PEER_SPATIAL_MUX;
954 arg->peer_flags |= WMI_PEER_DYN_MIMOPS;
955 }
956
957 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
958 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
959 else if (ht_cap->mcs.rx_mask[1])
960 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
961
962 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
963 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
964 arg->peer_ht_rates.rates[n++] = i;
965
966 arg->peer_ht_rates.num_rates = n;
967 arg->peer_num_spatial_streams = max((n+7) / 8, 1);
968
60c3daa8
KV
969 ath10k_dbg(ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
970 arg->addr,
5e3dd157
KV
971 arg->peer_ht_rates.num_rates,
972 arg->peer_num_spatial_streams);
973}
974
975static void ath10k_peer_assoc_h_qos_ap(struct ath10k *ar,
976 struct ath10k_vif *arvif,
977 struct ieee80211_sta *sta,
978 struct ieee80211_bss_conf *bss_conf,
979 struct wmi_peer_assoc_complete_arg *arg)
980{
981 u32 uapsd = 0;
982 u32 max_sp = 0;
983
548db54c
MK
984 lockdep_assert_held(&ar->conf_mutex);
985
5e3dd157
KV
986 if (sta->wme)
987 arg->peer_flags |= WMI_PEER_QOS;
988
989 if (sta->wme && sta->uapsd_queues) {
60c3daa8 990 ath10k_dbg(ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
5e3dd157
KV
991 sta->uapsd_queues, sta->max_sp);
992
993 arg->peer_flags |= WMI_PEER_APSD;
c69029b1 994 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
5e3dd157
KV
995
996 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
997 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
998 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
999 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1000 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1001 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1002 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1003 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1004 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1005 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1006 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1007 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1008
1009
1010 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1011 max_sp = sta->max_sp;
1012
1013 ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1014 sta->addr,
1015 WMI_AP_PS_PEER_PARAM_UAPSD,
1016 uapsd);
1017
1018 ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1019 sta->addr,
1020 WMI_AP_PS_PEER_PARAM_MAX_SP,
1021 max_sp);
1022
1023 /* TODO setup this based on STA listen interval and
1024 beacon interval. Currently we don't know
1025 sta->listen_interval - mac80211 patch required.
1026 Currently use 10 seconds */
1027 ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1028 sta->addr,
1029 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
1030 10);
1031 }
1032}
1033
1034static void ath10k_peer_assoc_h_qos_sta(struct ath10k *ar,
1035 struct ath10k_vif *arvif,
1036 struct ieee80211_sta *sta,
1037 struct ieee80211_bss_conf *bss_conf,
1038 struct wmi_peer_assoc_complete_arg *arg)
1039{
1040 if (bss_conf->qos)
1041 arg->peer_flags |= WMI_PEER_QOS;
1042}
1043
1044static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1045 struct ieee80211_sta *sta,
1046 struct wmi_peer_assoc_complete_arg *arg)
1047{
1048 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
a24b88b5 1049 u8 ampdu_factor;
5e3dd157
KV
1050
1051 if (!vht_cap->vht_supported)
1052 return;
1053
1054 arg->peer_flags |= WMI_PEER_VHT;
5e3dd157
KV
1055 arg->peer_vht_caps = vht_cap->cap;
1056
a24b88b5
SM
1057
1058 ampdu_factor = (vht_cap->cap &
1059 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1060 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1061
1062 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1063 * zero in VHT IE. Using it would result in degraded throughput.
1064 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1065 * it if VHT max_mpdu is smaller. */
1066 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1067 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1068 ampdu_factor)) - 1);
1069
5e3dd157
KV
1070 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1071 arg->peer_flags |= WMI_PEER_80MHZ;
1072
1073 arg->peer_vht_rates.rx_max_rate =
1074 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1075 arg->peer_vht_rates.rx_mcs_set =
1076 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1077 arg->peer_vht_rates.tx_max_rate =
1078 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1079 arg->peer_vht_rates.tx_mcs_set =
1080 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1081
60c3daa8
KV
1082 ath10k_dbg(ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
1083 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
5e3dd157
KV
1084}
1085
1086static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
1087 struct ath10k_vif *arvif,
1088 struct ieee80211_sta *sta,
1089 struct ieee80211_bss_conf *bss_conf,
1090 struct wmi_peer_assoc_complete_arg *arg)
1091{
1092 switch (arvif->vdev_type) {
1093 case WMI_VDEV_TYPE_AP:
1094 ath10k_peer_assoc_h_qos_ap(ar, arvif, sta, bss_conf, arg);
1095 break;
1096 case WMI_VDEV_TYPE_STA:
1097 ath10k_peer_assoc_h_qos_sta(ar, arvif, sta, bss_conf, arg);
1098 break;
1099 default:
1100 break;
1101 }
1102}
1103
1104static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
1105 struct ath10k_vif *arvif,
1106 struct ieee80211_sta *sta,
1107 struct wmi_peer_assoc_complete_arg *arg)
1108{
1109 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1110
5e3dd157
KV
1111 switch (ar->hw->conf.chandef.chan->band) {
1112 case IEEE80211_BAND_2GHZ:
1113 if (sta->ht_cap.ht_supported) {
1114 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1115 phymode = MODE_11NG_HT40;
1116 else
1117 phymode = MODE_11NG_HT20;
1118 } else {
1119 phymode = MODE_11G;
1120 }
1121
1122 break;
1123 case IEEE80211_BAND_5GHZ:
7cc45e98
SM
1124 /*
1125 * Check VHT first.
1126 */
1127 if (sta->vht_cap.vht_supported) {
1128 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1129 phymode = MODE_11AC_VHT80;
1130 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1131 phymode = MODE_11AC_VHT40;
1132 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1133 phymode = MODE_11AC_VHT20;
1134 } else if (sta->ht_cap.ht_supported) {
5e3dd157
KV
1135 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1136 phymode = MODE_11NA_HT40;
1137 else
1138 phymode = MODE_11NA_HT20;
1139 } else {
1140 phymode = MODE_11A;
1141 }
1142
1143 break;
1144 default:
1145 break;
1146 }
1147
38a1d47e
KV
1148 ath10k_dbg(ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
1149 sta->addr, ath10k_wmi_phymode_str(phymode));
60c3daa8 1150
5e3dd157
KV
1151 arg->peer_phymode = phymode;
1152 WARN_ON(phymode == MODE_UNKNOWN);
1153}
1154
b9ada65d
KV
1155static int ath10k_peer_assoc_prepare(struct ath10k *ar,
1156 struct ath10k_vif *arvif,
1157 struct ieee80211_sta *sta,
1158 struct ieee80211_bss_conf *bss_conf,
1159 struct wmi_peer_assoc_complete_arg *arg)
5e3dd157 1160{
548db54c
MK
1161 lockdep_assert_held(&ar->conf_mutex);
1162
b9ada65d 1163 memset(arg, 0, sizeof(*arg));
5e3dd157 1164
b9ada65d
KV
1165 ath10k_peer_assoc_h_basic(ar, arvif, sta, bss_conf, arg);
1166 ath10k_peer_assoc_h_crypto(ar, arvif, arg);
1167 ath10k_peer_assoc_h_rates(ar, sta, arg);
1168 ath10k_peer_assoc_h_ht(ar, sta, arg);
1169 ath10k_peer_assoc_h_vht(ar, sta, arg);
1170 ath10k_peer_assoc_h_qos(ar, arvif, sta, bss_conf, arg);
1171 ath10k_peer_assoc_h_phymode(ar, arvif, sta, arg);
5e3dd157 1172
b9ada65d 1173 return 0;
5e3dd157
KV
1174}
1175
1176/* can be called only in mac80211 callbacks due to `key_count` usage */
1177static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1178 struct ieee80211_vif *vif,
1179 struct ieee80211_bss_conf *bss_conf)
1180{
1181 struct ath10k *ar = hw->priv;
1182 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
b9ada65d 1183 struct wmi_peer_assoc_complete_arg peer_arg;
5e3dd157
KV
1184 struct ieee80211_sta *ap_sta;
1185 int ret;
1186
548db54c
MK
1187 lockdep_assert_held(&ar->conf_mutex);
1188
5e3dd157
KV
1189 rcu_read_lock();
1190
1191 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1192 if (!ap_sta) {
1193 ath10k_warn("Failed to find station entry for %pM\n",
1194 bss_conf->bssid);
1195 rcu_read_unlock();
1196 return;
1197 }
1198
b9ada65d
KV
1199 ret = ath10k_peer_assoc_prepare(ar, arvif, ap_sta,
1200 bss_conf, &peer_arg);
5e3dd157 1201 if (ret) {
b9ada65d
KV
1202 ath10k_warn("Peer assoc prepare failed for %pM\n: %d",
1203 bss_conf->bssid, ret);
5e3dd157
KV
1204 rcu_read_unlock();
1205 return;
1206 }
1207
1208 rcu_read_unlock();
1209
b9ada65d
KV
1210 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1211 if (ret) {
1212 ath10k_warn("Peer assoc failed for %pM\n: %d",
1213 bss_conf->bssid, ret);
1214 return;
1215 }
1216
60c3daa8
KV
1217 ath10k_dbg(ATH10K_DBG_MAC,
1218 "mac vdev %d up (associated) bssid %pM aid %d\n",
1219 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1220
5e3dd157
KV
1221 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, bss_conf->aid,
1222 bss_conf->bssid);
1223 if (ret)
1224 ath10k_warn("VDEV: %d up failed: ret %d\n",
1225 arvif->vdev_id, ret);
5e3dd157
KV
1226}
1227
1228/*
1229 * FIXME: flush TIDs
1230 */
1231static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1232 struct ieee80211_vif *vif)
1233{
1234 struct ath10k *ar = hw->priv;
1235 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1236 int ret;
1237
548db54c
MK
1238 lockdep_assert_held(&ar->conf_mutex);
1239
5e3dd157
KV
1240 /*
1241 * For some reason, calling VDEV-DOWN before VDEV-STOP
1242 * makes the FW to send frames via HTT after disassociation.
1243 * No idea why this happens, even though VDEV-DOWN is supposed
1244 * to be analogous to link down, so just stop the VDEV.
1245 */
60c3daa8
KV
1246 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d stop (disassociated\n",
1247 arvif->vdev_id);
1248
1249 /* FIXME: check return value */
5e3dd157 1250 ret = ath10k_vdev_stop(arvif);
5e3dd157
KV
1251
1252 /*
1253 * If we don't call VDEV-DOWN after VDEV-STOP FW will remain active and
1254 * report beacons from previously associated network through HTT.
1255 * This in turn would spam mac80211 WARN_ON if we bring down all
1256 * interfaces as it expects there is no rx when no interface is
1257 * running.
1258 */
60c3daa8
KV
1259 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d down\n", arvif->vdev_id);
1260
1261 /* FIXME: why don't we print error if wmi call fails? */
5e3dd157 1262 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
5e3dd157 1263
cc4827b9 1264 arvif->def_wep_key_idx = 0;
5e3dd157
KV
1265}
1266
1267static int ath10k_station_assoc(struct ath10k *ar, struct ath10k_vif *arvif,
1268 struct ieee80211_sta *sta)
1269{
b9ada65d 1270 struct wmi_peer_assoc_complete_arg peer_arg;
5e3dd157
KV
1271 int ret = 0;
1272
548db54c
MK
1273 lockdep_assert_held(&ar->conf_mutex);
1274
b9ada65d
KV
1275 ret = ath10k_peer_assoc_prepare(ar, arvif, sta, NULL, &peer_arg);
1276 if (ret) {
1277 ath10k_warn("WMI peer assoc prepare failed for %pM\n",
1278 sta->addr);
1279 return ret;
1280 }
1281
1282 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
5e3dd157 1283 if (ret) {
b9ada65d
KV
1284 ath10k_warn("Peer assoc failed for STA %pM\n: %d",
1285 sta->addr, ret);
5e3dd157
KV
1286 return ret;
1287 }
1288
1289 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1290 if (ret) {
1291 ath10k_warn("could not install peer wep keys (%d)\n", ret);
1292 return ret;
1293 }
1294
1295 return ret;
1296}
1297
1298static int ath10k_station_disassoc(struct ath10k *ar, struct ath10k_vif *arvif,
1299 struct ieee80211_sta *sta)
1300{
1301 int ret = 0;
1302
548db54c
MK
1303 lockdep_assert_held(&ar->conf_mutex);
1304
5e3dd157
KV
1305 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1306 if (ret) {
1307 ath10k_warn("could not clear all peer wep keys (%d)\n", ret);
1308 return ret;
1309 }
1310
1311 return ret;
1312}
1313
1314/**************/
1315/* Regulatory */
1316/**************/
1317
1318static int ath10k_update_channel_list(struct ath10k *ar)
1319{
1320 struct ieee80211_hw *hw = ar->hw;
1321 struct ieee80211_supported_band **bands;
1322 enum ieee80211_band band;
1323 struct ieee80211_channel *channel;
1324 struct wmi_scan_chan_list_arg arg = {0};
1325 struct wmi_channel_arg *ch;
1326 bool passive;
1327 int len;
1328 int ret;
1329 int i;
1330
548db54c
MK
1331 lockdep_assert_held(&ar->conf_mutex);
1332
5e3dd157
KV
1333 bands = hw->wiphy->bands;
1334 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1335 if (!bands[band])
1336 continue;
1337
1338 for (i = 0; i < bands[band]->n_channels; i++) {
1339 if (bands[band]->channels[i].flags &
1340 IEEE80211_CHAN_DISABLED)
1341 continue;
1342
1343 arg.n_channels++;
1344 }
1345 }
1346
1347 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
1348 arg.channels = kzalloc(len, GFP_KERNEL);
1349 if (!arg.channels)
1350 return -ENOMEM;
1351
1352 ch = arg.channels;
1353 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1354 if (!bands[band])
1355 continue;
1356
1357 for (i = 0; i < bands[band]->n_channels; i++) {
1358 channel = &bands[band]->channels[i];
1359
1360 if (channel->flags & IEEE80211_CHAN_DISABLED)
1361 continue;
1362
1363 ch->allow_ht = true;
1364
1365 /* FIXME: when should we really allow VHT? */
1366 ch->allow_vht = true;
1367
1368 ch->allow_ibss =
1369 !(channel->flags & IEEE80211_CHAN_NO_IBSS);
1370
1371 ch->ht40plus =
1372 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
1373
1374 passive = channel->flags & IEEE80211_CHAN_PASSIVE_SCAN;
1375 ch->passive = passive;
1376
1377 ch->freq = channel->center_freq;
1378 ch->min_power = channel->max_power * 3;
1379 ch->max_power = channel->max_power * 4;
1380 ch->max_reg_power = channel->max_reg_power * 4;
1381 ch->max_antenna_gain = channel->max_antenna_gain;
1382 ch->reg_class_id = 0; /* FIXME */
1383
1384 /* FIXME: why use only legacy modes, why not any
1385 * HT/VHT modes? Would that even make any
1386 * difference? */
1387 if (channel->band == IEEE80211_BAND_2GHZ)
1388 ch->mode = MODE_11G;
1389 else
1390 ch->mode = MODE_11A;
1391
1392 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
1393 continue;
1394
1395 ath10k_dbg(ATH10K_DBG_WMI,
60c3daa8
KV
1396 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1397 ch - arg.channels, arg.n_channels,
5e3dd157
KV
1398 ch->freq, ch->max_power, ch->max_reg_power,
1399 ch->max_antenna_gain, ch->mode);
1400
1401 ch++;
1402 }
1403 }
1404
1405 ret = ath10k_wmi_scan_chan_list(ar, &arg);
1406 kfree(arg.channels);
1407
1408 return ret;
1409}
1410
f7843d7f 1411static void ath10k_regd_update(struct ath10k *ar)
5e3dd157 1412{
5e3dd157 1413 struct reg_dmn_pair_mapping *regpair;
5e3dd157
KV
1414 int ret;
1415
f7843d7f 1416 lockdep_assert_held(&ar->conf_mutex);
5e3dd157
KV
1417
1418 ret = ath10k_update_channel_list(ar);
1419 if (ret)
1420 ath10k_warn("could not update channel list (%d)\n", ret);
1421
1422 regpair = ar->ath_common.regulatory.regpair;
f7843d7f 1423
5e3dd157
KV
1424 /* Target allows setting up per-band regdomain but ath_common provides
1425 * a combined one only */
1426 ret = ath10k_wmi_pdev_set_regdomain(ar,
1427 regpair->regDmnEnum,
1428 regpair->regDmnEnum, /* 2ghz */
1429 regpair->regDmnEnum, /* 5ghz */
1430 regpair->reg_2ghz_ctl,
1431 regpair->reg_5ghz_ctl);
1432 if (ret)
1433 ath10k_warn("could not set pdev regdomain (%d)\n", ret);
f7843d7f 1434}
548db54c 1435
f7843d7f
MK
1436static void ath10k_reg_notifier(struct wiphy *wiphy,
1437 struct regulatory_request *request)
1438{
1439 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1440 struct ath10k *ar = hw->priv;
1441
1442 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
1443
1444 mutex_lock(&ar->conf_mutex);
1445 if (ar->state == ATH10K_STATE_ON)
1446 ath10k_regd_update(ar);
548db54c 1447 mutex_unlock(&ar->conf_mutex);
5e3dd157
KV
1448}
1449
1450/***************/
1451/* TX handlers */
1452/***************/
1453
42c3aa6f
MK
1454static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
1455{
1456 if (ieee80211_is_mgmt(hdr->frame_control))
1457 return HTT_DATA_TX_EXT_TID_MGMT;
1458
1459 if (!ieee80211_is_data_qos(hdr->frame_control))
1460 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1461
1462 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
1463 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1464
1465 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
1466}
1467
ddb6ad77
MK
1468static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar,
1469 struct ieee80211_tx_info *info)
1470{
1471 if (info->control.vif)
1472 return ath10k_vif_to_arvif(info->control.vif)->vdev_id;
1473
1474 if (ar->monitor_enabled)
1475 return ar->monitor_vdev_id;
1476
1477 ath10k_warn("could not resolve vdev id\n");
1478 return 0;
1479}
1480
5e3dd157
KV
1481/*
1482 * Frames sent to the FW have to be in "Native Wifi" format.
1483 * Strip the QoS field from the 802.11 header.
1484 */
1485static void ath10k_tx_h_qos_workaround(struct ieee80211_hw *hw,
1486 struct ieee80211_tx_control *control,
1487 struct sk_buff *skb)
1488{
1489 struct ieee80211_hdr *hdr = (void *)skb->data;
1490 u8 *qos_ctl;
1491
1492 if (!ieee80211_is_data_qos(hdr->frame_control))
1493 return;
1494
1495 qos_ctl = ieee80211_get_qos_ctl(hdr);
ba0ccd7a
MK
1496 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
1497 skb->data, (void *)qos_ctl - (void *)skb->data);
1498 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
5e3dd157
KV
1499}
1500
cc4827b9
MK
1501static void ath10k_tx_wep_key_work(struct work_struct *work)
1502{
1503 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1504 wep_key_work);
1505 int ret, keyidx = arvif->def_wep_key_newidx;
1506
1507 if (arvif->def_wep_key_idx == keyidx)
1508 return;
1509
1510 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
1511 arvif->vdev_id, keyidx);
1512
1513 ret = ath10k_wmi_vdev_set_param(arvif->ar,
1514 arvif->vdev_id,
1515 arvif->ar->wmi.vdev_param->def_keyid,
1516 keyidx);
1517 if (ret) {
1518 ath10k_warn("could not update wep keyidx (%d)\n", ret);
1519 return;
1520 }
1521
1522 arvif->def_wep_key_idx = keyidx;
1523}
1524
5e3dd157
KV
1525static void ath10k_tx_h_update_wep_key(struct sk_buff *skb)
1526{
1527 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1528 struct ieee80211_vif *vif = info->control.vif;
1529 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1530 struct ath10k *ar = arvif->ar;
1531 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1532 struct ieee80211_key_conf *key = info->control.hw_key;
5e3dd157 1533
5e3dd157
KV
1534 if (!ieee80211_has_protected(hdr->frame_control))
1535 return;
1536
1537 if (!key)
1538 return;
1539
1540 if (key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
1541 key->cipher != WLAN_CIPHER_SUITE_WEP104)
1542 return;
1543
cc4827b9 1544 if (key->keyidx == arvif->def_wep_key_idx)
5e3dd157 1545 return;
5e3dd157 1546
cc4827b9
MK
1547 /* FIXME: Most likely a few frames will be TXed with an old key. Simply
1548 * queueing frames until key index is updated is not an option because
1549 * sk_buff may need more processing to be done, e.g. offchannel */
1550 arvif->def_wep_key_newidx = key->keyidx;
1551 ieee80211_queue_work(ar->hw, &arvif->wep_key_work);
5e3dd157
KV
1552}
1553
1554static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar, struct sk_buff *skb)
1555{
1556 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1557 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1558 struct ieee80211_vif *vif = info->control.vif;
1559 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1560
1561 /* This is case only for P2P_GO */
1562 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
1563 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1564 return;
1565
1566 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
1567 spin_lock_bh(&ar->data_lock);
1568 if (arvif->u.ap.noa_data)
1569 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
1570 GFP_ATOMIC))
1571 memcpy(skb_put(skb, arvif->u.ap.noa_len),
1572 arvif->u.ap.noa_data,
1573 arvif->u.ap.noa_len);
1574 spin_unlock_bh(&ar->data_lock);
1575 }
1576}
1577
1578static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
1579{
1580 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
5e00d31a 1581 int ret = 0;
5e3dd157 1582
961d4c38
MK
1583 if (ar->htt.target_version_major >= 3) {
1584 /* Since HTT 3.0 there is no separate mgmt tx command */
1585 ret = ath10k_htt_tx(&ar->htt, skb);
1586 goto exit;
1587 }
1588
5e00d31a
BM
1589 if (ieee80211_is_mgmt(hdr->frame_control)) {
1590 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
1591 ar->fw_features)) {
1592 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
1593 ATH10K_MAX_NUM_MGMT_PENDING) {
1594 ath10k_warn("wmi mgmt_tx queue limit reached\n");
1595 ret = -EBUSY;
1596 goto exit;
1597 }
1598
1599 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
1600 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
1601 } else {
1602 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
1603 }
1604 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
1605 ar->fw_features) &&
1606 ieee80211_is_nullfunc(hdr->frame_control)) {
5e3dd157
KV
1607 /* FW does not report tx status properly for NullFunc frames
1608 * unless they are sent through mgmt tx path. mac80211 sends
5e00d31a
BM
1609 * those frames when it detects link/beacon loss and depends
1610 * on the tx status to be correct. */
edb8236d 1611 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
5e00d31a 1612 } else {
edb8236d 1613 ret = ath10k_htt_tx(&ar->htt, skb);
5e00d31a 1614 }
5e3dd157 1615
961d4c38 1616exit:
5e3dd157
KV
1617 if (ret) {
1618 ath10k_warn("tx failed (%d). dropping packet.\n", ret);
1619 ieee80211_free_txskb(ar->hw, skb);
1620 }
1621}
1622
1623void ath10k_offchan_tx_purge(struct ath10k *ar)
1624{
1625 struct sk_buff *skb;
1626
1627 for (;;) {
1628 skb = skb_dequeue(&ar->offchan_tx_queue);
1629 if (!skb)
1630 break;
1631
1632 ieee80211_free_txskb(ar->hw, skb);
1633 }
1634}
1635
1636void ath10k_offchan_tx_work(struct work_struct *work)
1637{
1638 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
1639 struct ath10k_peer *peer;
1640 struct ieee80211_hdr *hdr;
1641 struct sk_buff *skb;
1642 const u8 *peer_addr;
1643 int vdev_id;
1644 int ret;
1645
1646 /* FW requirement: We must create a peer before FW will send out
1647 * an offchannel frame. Otherwise the frame will be stuck and
1648 * never transmitted. We delete the peer upon tx completion.
1649 * It is unlikely that a peer for offchannel tx will already be
1650 * present. However it may be in some rare cases so account for that.
1651 * Otherwise we might remove a legitimate peer and break stuff. */
1652
1653 for (;;) {
1654 skb = skb_dequeue(&ar->offchan_tx_queue);
1655 if (!skb)
1656 break;
1657
1658 mutex_lock(&ar->conf_mutex);
1659
60c3daa8 1660 ath10k_dbg(ATH10K_DBG_MAC, "mac offchannel skb %p\n",
5e3dd157
KV
1661 skb);
1662
1663 hdr = (struct ieee80211_hdr *)skb->data;
1664 peer_addr = ieee80211_get_DA(hdr);
5e00d31a 1665 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
5e3dd157
KV
1666
1667 spin_lock_bh(&ar->data_lock);
1668 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
1669 spin_unlock_bh(&ar->data_lock);
1670
1671 if (peer)
60c3daa8 1672 /* FIXME: should this use ath10k_warn()? */
5e3dd157
KV
1673 ath10k_dbg(ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
1674 peer_addr, vdev_id);
1675
1676 if (!peer) {
1677 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
1678 if (ret)
1679 ath10k_warn("peer %pM on vdev %d not created (%d)\n",
1680 peer_addr, vdev_id, ret);
1681 }
1682
1683 spin_lock_bh(&ar->data_lock);
1684 INIT_COMPLETION(ar->offchan_tx_completed);
1685 ar->offchan_tx_skb = skb;
1686 spin_unlock_bh(&ar->data_lock);
1687
1688 ath10k_tx_htt(ar, skb);
1689
1690 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
1691 3 * HZ);
1692 if (ret <= 0)
1693 ath10k_warn("timed out waiting for offchannel skb %p\n",
1694 skb);
1695
1696 if (!peer) {
1697 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
1698 if (ret)
1699 ath10k_warn("peer %pM on vdev %d not deleted (%d)\n",
1700 peer_addr, vdev_id, ret);
1701 }
1702
1703 mutex_unlock(&ar->conf_mutex);
1704 }
1705}
1706
5e00d31a
BM
1707void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
1708{
1709 struct sk_buff *skb;
1710
1711 for (;;) {
1712 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
1713 if (!skb)
1714 break;
1715
1716 ieee80211_free_txskb(ar->hw, skb);
1717 }
1718}
1719
1720void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
1721{
1722 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
1723 struct sk_buff *skb;
1724 int ret;
1725
1726 for (;;) {
1727 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
1728 if (!skb)
1729 break;
1730
1731 ret = ath10k_wmi_mgmt_tx(ar, skb);
1732 if (ret)
1733 ath10k_warn("wmi mgmt_tx failed (%d)\n", ret);
1734 }
1735}
1736
5e3dd157
KV
1737/************/
1738/* Scanning */
1739/************/
1740
1741/*
1742 * This gets called if we dont get a heart-beat during scan.
1743 * This may indicate the FW has hung and we need to abort the
1744 * scan manually to prevent cancel_hw_scan() from deadlocking
1745 */
1746void ath10k_reset_scan(unsigned long ptr)
1747{
1748 struct ath10k *ar = (struct ath10k *)ptr;
1749
1750 spin_lock_bh(&ar->data_lock);
1751 if (!ar->scan.in_progress) {
1752 spin_unlock_bh(&ar->data_lock);
1753 return;
1754 }
1755
1756 ath10k_warn("scan timeout. resetting. fw issue?\n");
1757
1758 if (ar->scan.is_roc)
1759 ieee80211_remain_on_channel_expired(ar->hw);
1760 else
1761 ieee80211_scan_completed(ar->hw, 1 /* aborted */);
1762
1763 ar->scan.in_progress = false;
1764 complete_all(&ar->scan.completed);
1765 spin_unlock_bh(&ar->data_lock);
1766}
1767
1768static int ath10k_abort_scan(struct ath10k *ar)
1769{
1770 struct wmi_stop_scan_arg arg = {
1771 .req_id = 1, /* FIXME */
1772 .req_type = WMI_SCAN_STOP_ONE,
1773 .u.scan_id = ATH10K_SCAN_ID,
1774 };
1775 int ret;
1776
1777 lockdep_assert_held(&ar->conf_mutex);
1778
1779 del_timer_sync(&ar->scan.timeout);
1780
1781 spin_lock_bh(&ar->data_lock);
1782 if (!ar->scan.in_progress) {
1783 spin_unlock_bh(&ar->data_lock);
1784 return 0;
1785 }
1786
1787 ar->scan.aborting = true;
1788 spin_unlock_bh(&ar->data_lock);
1789
1790 ret = ath10k_wmi_stop_scan(ar, &arg);
1791 if (ret) {
1792 ath10k_warn("could not submit wmi stop scan (%d)\n", ret);
adb8c9b7
MK
1793 spin_lock_bh(&ar->data_lock);
1794 ar->scan.in_progress = false;
1795 ath10k_offchan_tx_purge(ar);
1796 spin_unlock_bh(&ar->data_lock);
5e3dd157
KV
1797 return -EIO;
1798 }
1799
5e3dd157
KV
1800 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
1801 if (ret == 0)
1802 ath10k_warn("timed out while waiting for scan to stop\n");
1803
1804 /* scan completion may be done right after we timeout here, so let's
1805 * check the in_progress and tell mac80211 scan is completed. if we
1806 * don't do that and FW fails to send us scan completion indication
1807 * then userspace won't be able to scan anymore */
1808 ret = 0;
1809
1810 spin_lock_bh(&ar->data_lock);
1811 if (ar->scan.in_progress) {
1812 ath10k_warn("could not stop scan. its still in progress\n");
1813 ar->scan.in_progress = false;
1814 ath10k_offchan_tx_purge(ar);
1815 ret = -ETIMEDOUT;
1816 }
1817 spin_unlock_bh(&ar->data_lock);
1818
1819 return ret;
1820}
1821
1822static int ath10k_start_scan(struct ath10k *ar,
1823 const struct wmi_start_scan_arg *arg)
1824{
1825 int ret;
1826
1827 lockdep_assert_held(&ar->conf_mutex);
1828
1829 ret = ath10k_wmi_start_scan(ar, arg);
1830 if (ret)
1831 return ret;
1832
5e3dd157
KV
1833 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
1834 if (ret == 0) {
1835 ath10k_abort_scan(ar);
1836 return ret;
1837 }
1838
1839 /* the scan can complete earlier, before we even
1840 * start the timer. in that case the timer handler
1841 * checks ar->scan.in_progress and bails out if its
1842 * false. Add a 200ms margin to account event/command
1843 * processing. */
1844 mod_timer(&ar->scan.timeout, jiffies +
1845 msecs_to_jiffies(arg->max_scan_time+200));
1846 return 0;
1847}
1848
1849/**********************/
1850/* mac80211 callbacks */
1851/**********************/
1852
1853static void ath10k_tx(struct ieee80211_hw *hw,
1854 struct ieee80211_tx_control *control,
1855 struct sk_buff *skb)
1856{
1857 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1858 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1859 struct ath10k *ar = hw->priv;
ddb6ad77 1860 u8 tid, vdev_id;
5e3dd157
KV
1861
1862 /* We should disable CCK RATE due to P2P */
1863 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
1864 ath10k_dbg(ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
1865
1866 /* we must calculate tid before we apply qos workaround
1867 * as we'd lose the qos control field */
42c3aa6f 1868 tid = ath10k_tx_h_get_tid(hdr);
ddb6ad77 1869 vdev_id = ath10k_tx_h_get_vdev_id(ar, info);
5e3dd157 1870
cf84bd4d
MK
1871 /* it makes no sense to process injected frames like that */
1872 if (info->control.vif &&
1873 info->control.vif->type != NL80211_IFTYPE_MONITOR) {
1874 ath10k_tx_h_qos_workaround(hw, control, skb);
1875 ath10k_tx_h_update_wep_key(skb);
1876 ath10k_tx_h_add_p2p_noa_ie(ar, skb);
1877 ath10k_tx_h_seq_no(skb);
1878 }
5e3dd157 1879
5e00d31a 1880 ATH10K_SKB_CB(skb)->vdev_id = vdev_id;
27bb178d 1881 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
5e3dd157
KV
1882 ATH10K_SKB_CB(skb)->htt.tid = tid;
1883
1884 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
1885 spin_lock_bh(&ar->data_lock);
1886 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
5e00d31a 1887 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
5e3dd157
KV
1888 spin_unlock_bh(&ar->data_lock);
1889
1890 ath10k_dbg(ATH10K_DBG_MAC, "queued offchannel skb %p\n", skb);
1891
1892 skb_queue_tail(&ar->offchan_tx_queue, skb);
1893 ieee80211_queue_work(hw, &ar->offchan_tx_work);
1894 return;
1895 }
1896
1897 ath10k_tx_htt(ar, skb);
1898}
1899
1900/*
1901 * Initialize various parameters with default vaules.
1902 */
affd3217 1903void ath10k_halt(struct ath10k *ar)
818bdd16
MK
1904{
1905 lockdep_assert_held(&ar->conf_mutex);
1906
1907 del_timer_sync(&ar->scan.timeout);
1908 ath10k_offchan_tx_purge(ar);
5e00d31a 1909 ath10k_mgmt_over_wmi_tx_purge(ar);
818bdd16
MK
1910 ath10k_peer_cleanup_all(ar);
1911 ath10k_core_stop(ar);
1912 ath10k_hif_power_down(ar);
1913
1914 spin_lock_bh(&ar->data_lock);
1915 if (ar->scan.in_progress) {
1916 del_timer(&ar->scan.timeout);
1917 ar->scan.in_progress = false;
1918 ieee80211_scan_completed(ar->hw, true);
1919 }
1920 spin_unlock_bh(&ar->data_lock);
1921}
1922
5e3dd157
KV
1923static int ath10k_start(struct ieee80211_hw *hw)
1924{
1925 struct ath10k *ar = hw->priv;
818bdd16 1926 int ret = 0;
5e3dd157 1927
548db54c
MK
1928 mutex_lock(&ar->conf_mutex);
1929
affd3217
MK
1930 if (ar->state != ATH10K_STATE_OFF &&
1931 ar->state != ATH10K_STATE_RESTARTING) {
818bdd16
MK
1932 ret = -EINVAL;
1933 goto exit;
1934 }
1935
1936 ret = ath10k_hif_power_up(ar);
1937 if (ret) {
1938 ath10k_err("could not init hif (%d)\n", ret);
1939 ar->state = ATH10K_STATE_OFF;
1940 goto exit;
1941 }
1942
1943 ret = ath10k_core_start(ar);
1944 if (ret) {
1945 ath10k_err("could not init core (%d)\n", ret);
1946 ath10k_hif_power_down(ar);
1947 ar->state = ATH10K_STATE_OFF;
1948 goto exit;
1949 }
1950
affd3217
MK
1951 if (ar->state == ATH10K_STATE_OFF)
1952 ar->state = ATH10K_STATE_ON;
1953 else if (ar->state == ATH10K_STATE_RESTARTING)
1954 ar->state = ATH10K_STATE_RESTARTED;
1955
226a339b 1956 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
5e3dd157
KV
1957 if (ret)
1958 ath10k_warn("could not enable WMI_PDEV_PARAM_PMF_QOS (%d)\n",
1959 ret);
1960
226a339b 1961 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 0);
5e3dd157
KV
1962 if (ret)
1963 ath10k_warn("could not init WMI_PDEV_PARAM_DYNAMIC_BW (%d)\n",
1964 ret);
1965
f7843d7f
MK
1966 ath10k_regd_update(ar);
1967
818bdd16 1968exit:
548db54c 1969 mutex_unlock(&ar->conf_mutex);
5e3dd157
KV
1970 return 0;
1971}
1972
1973static void ath10k_stop(struct ieee80211_hw *hw)
1974{
1975 struct ath10k *ar = hw->priv;
1976
548db54c 1977 mutex_lock(&ar->conf_mutex);
affd3217
MK
1978 if (ar->state == ATH10K_STATE_ON ||
1979 ar->state == ATH10K_STATE_RESTARTED ||
1980 ar->state == ATH10K_STATE_WEDGED)
818bdd16 1981 ath10k_halt(ar);
a96d7745 1982
f7843d7f 1983 ar->state = ATH10K_STATE_OFF;
548db54c
MK
1984 mutex_unlock(&ar->conf_mutex);
1985
5e00d31a
BM
1986 ath10k_mgmt_over_wmi_tx_purge(ar);
1987
548db54c 1988 cancel_work_sync(&ar->offchan_tx_work);
5e00d31a 1989 cancel_work_sync(&ar->wmi_mgmt_tx_work);
affd3217 1990 cancel_work_sync(&ar->restart_work);
5e3dd157
KV
1991}
1992
ad088bfa 1993static int ath10k_config_ps(struct ath10k *ar)
5e3dd157 1994{
ad088bfa
MK
1995 struct ath10k_vif *arvif;
1996 int ret = 0;
affd3217
MK
1997
1998 lockdep_assert_held(&ar->conf_mutex);
1999
ad088bfa
MK
2000 list_for_each_entry(arvif, &ar->arvifs, list) {
2001 ret = ath10k_mac_vif_setup_ps(arvif);
2002 if (ret) {
2003 ath10k_warn("could not setup powersave (%d)\n", ret);
2004 break;
2005 }
2006 }
affd3217 2007
ad088bfa 2008 return ret;
affd3217
MK
2009}
2010
2011static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
2012{
5e3dd157
KV
2013 struct ath10k *ar = hw->priv;
2014 struct ieee80211_conf *conf = &hw->conf;
2015 int ret = 0;
5e3dd157
KV
2016
2017 mutex_lock(&ar->conf_mutex);
2018
2019 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
60c3daa8 2020 ath10k_dbg(ATH10K_DBG_MAC, "mac config channel %d mhz\n",
5e3dd157
KV
2021 conf->chandef.chan->center_freq);
2022 spin_lock_bh(&ar->data_lock);
2023 ar->rx_channel = conf->chandef.chan;
2024 spin_unlock_bh(&ar->data_lock);
2025 }
2026
affd3217
MK
2027 if (changed & IEEE80211_CONF_CHANGE_PS)
2028 ath10k_config_ps(ar);
5e3dd157
KV
2029
2030 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
2031 if (conf->flags & IEEE80211_CONF_MONITOR)
2032 ret = ath10k_monitor_create(ar);
2033 else
2034 ret = ath10k_monitor_destroy(ar);
2035 }
2036
2037 mutex_unlock(&ar->conf_mutex);
2038 return ret;
2039}
2040
2041/*
2042 * TODO:
2043 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
2044 * because we will send mgmt frames without CCK. This requirement
2045 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
2046 * in the TX packet.
2047 */
2048static int ath10k_add_interface(struct ieee80211_hw *hw,
2049 struct ieee80211_vif *vif)
2050{
2051 struct ath10k *ar = hw->priv;
2052 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2053 enum wmi_sta_powersave_param param;
2054 int ret = 0;
424121c3 2055 u32 value;
5e3dd157 2056 int bit;
6d1506e7 2057 u32 vdev_param;
5e3dd157
KV
2058
2059 mutex_lock(&ar->conf_mutex);
2060
0dbd09e6
MK
2061 memset(arvif, 0, sizeof(*arvif));
2062
5e3dd157
KV
2063 arvif->ar = ar;
2064 arvif->vif = vif;
2065
cc4827b9 2066 INIT_WORK(&arvif->wep_key_work, ath10k_tx_wep_key_work);
e63b33f3 2067 INIT_LIST_HEAD(&arvif->list);
cc4827b9 2068
5e3dd157
KV
2069 if ((vif->type == NL80211_IFTYPE_MONITOR) && ar->monitor_present) {
2070 ath10k_warn("Only one monitor interface allowed\n");
2071 ret = -EBUSY;
9dad14ae 2072 goto err;
5e3dd157
KV
2073 }
2074
2075 bit = ffs(ar->free_vdev_map);
2076 if (bit == 0) {
2077 ret = -EBUSY;
9dad14ae 2078 goto err;
5e3dd157
KV
2079 }
2080
2081 arvif->vdev_id = bit - 1;
2082 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
5e3dd157
KV
2083
2084 if (ar->p2p)
2085 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
2086
2087 switch (vif->type) {
2088 case NL80211_IFTYPE_UNSPECIFIED:
2089 case NL80211_IFTYPE_STATION:
2090 arvif->vdev_type = WMI_VDEV_TYPE_STA;
2091 if (vif->p2p)
2092 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
2093 break;
2094 case NL80211_IFTYPE_ADHOC:
2095 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
2096 break;
2097 case NL80211_IFTYPE_AP:
2098 arvif->vdev_type = WMI_VDEV_TYPE_AP;
2099
2100 if (vif->p2p)
2101 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
2102 break;
2103 case NL80211_IFTYPE_MONITOR:
2104 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
2105 break;
2106 default:
2107 WARN_ON(1);
2108 break;
2109 }
2110
60c3daa8 2111 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d\n",
5e3dd157
KV
2112 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype);
2113
2114 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
2115 arvif->vdev_subtype, vif->addr);
2116 if (ret) {
2117 ath10k_warn("WMI vdev create failed: ret %d\n", ret);
9dad14ae 2118 goto err;
5e3dd157
KV
2119 }
2120
9dad14ae 2121 ar->free_vdev_map &= ~BIT(arvif->vdev_id);
0579119f 2122 list_add(&arvif->list, &ar->arvifs);
9dad14ae 2123
6d1506e7
BM
2124 vdev_param = ar->wmi.vdev_param->def_keyid;
2125 ret = ath10k_wmi_vdev_set_param(ar, 0, vdev_param,
cc4827b9 2126 arvif->def_wep_key_idx);
9dad14ae 2127 if (ret) {
5e3dd157 2128 ath10k_warn("Failed to set default keyid: %d\n", ret);
9dad14ae
MK
2129 goto err_vdev_delete;
2130 }
5e3dd157 2131
6d1506e7
BM
2132 vdev_param = ar->wmi.vdev_param->tx_encap_type;
2133 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5e3dd157 2134 ATH10K_HW_TXRX_NATIVE_WIFI);
ebc9abdd 2135 /* 10.X firmware does not support this VDEV parameter. Do not warn */
9dad14ae 2136 if (ret && ret != -EOPNOTSUPP) {
5e3dd157 2137 ath10k_warn("Failed to set TX encap: %d\n", ret);
9dad14ae
MK
2138 goto err_vdev_delete;
2139 }
5e3dd157
KV
2140
2141 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2142 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
2143 if (ret) {
2144 ath10k_warn("Failed to create peer for AP: %d\n", ret);
9dad14ae 2145 goto err_vdev_delete;
5e3dd157
KV
2146 }
2147 }
2148
2149 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
2150 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
2151 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2152 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2153 param, value);
9dad14ae 2154 if (ret) {
5e3dd157 2155 ath10k_warn("Failed to set RX wake policy: %d\n", ret);
9dad14ae
MK
2156 goto err_peer_delete;
2157 }
5e3dd157
KV
2158
2159 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
2160 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
2161 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2162 param, value);
9dad14ae 2163 if (ret) {
5e3dd157 2164 ath10k_warn("Failed to set TX wake thresh: %d\n", ret);
9dad14ae
MK
2165 goto err_peer_delete;
2166 }
5e3dd157
KV
2167
2168 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
2169 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
2170 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2171 param, value);
9dad14ae 2172 if (ret) {
5e3dd157 2173 ath10k_warn("Failed to set PSPOLL count: %d\n", ret);
9dad14ae
MK
2174 goto err_peer_delete;
2175 }
5e3dd157
KV
2176 }
2177
424121c3 2178 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
9dad14ae 2179 if (ret) {
679c54a6
MK
2180 ath10k_warn("failed to set rts threshold for vdev %d (%d)\n",
2181 arvif->vdev_id, ret);
9dad14ae
MK
2182 goto err_peer_delete;
2183 }
679c54a6 2184
424121c3 2185 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
9dad14ae 2186 if (ret) {
679c54a6
MK
2187 ath10k_warn("failed to set frag threshold for vdev %d (%d)\n",
2188 arvif->vdev_id, ret);
9dad14ae
MK
2189 goto err_peer_delete;
2190 }
679c54a6 2191
5e3dd157
KV
2192 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2193 ar->monitor_present = true;
2194
5e3dd157 2195 mutex_unlock(&ar->conf_mutex);
9dad14ae
MK
2196 return 0;
2197
2198err_peer_delete:
2199 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
2200 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
2201
2202err_vdev_delete:
2203 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2204 ar->free_vdev_map &= ~BIT(arvif->vdev_id);
0579119f 2205 list_del(&arvif->list);
9dad14ae
MK
2206
2207err:
2208 mutex_unlock(&ar->conf_mutex);
2209
5e3dd157
KV
2210 return ret;
2211}
2212
2213static void ath10k_remove_interface(struct ieee80211_hw *hw,
2214 struct ieee80211_vif *vif)
2215{
2216 struct ath10k *ar = hw->priv;
2217 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2218 int ret;
2219
2220 mutex_lock(&ar->conf_mutex);
2221
cc4827b9
MK
2222 cancel_work_sync(&arvif->wep_key_work);
2223
ed54388a
MK
2224 spin_lock_bh(&ar->data_lock);
2225 if (arvif->beacon) {
2226 dev_kfree_skb_any(arvif->beacon);
2227 arvif->beacon = NULL;
2228 }
2229 spin_unlock_bh(&ar->data_lock);
2230
5e3dd157 2231 ar->free_vdev_map |= 1 << (arvif->vdev_id);
0579119f 2232 list_del(&arvif->list);
5e3dd157
KV
2233
2234 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2235 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
2236 if (ret)
2237 ath10k_warn("Failed to remove peer for AP: %d\n", ret);
2238
2239 kfree(arvif->u.ap.noa_data);
2240 }
2241
60c3daa8
KV
2242 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev delete %d (remove interface)\n",
2243 arvif->vdev_id);
2244
5e3dd157
KV
2245 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2246 if (ret)
2247 ath10k_warn("WMI vdev delete failed: %d\n", ret);
2248
2249 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2250 ar->monitor_present = false;
2251
2252 ath10k_peer_cleanup(ar, arvif->vdev_id);
2253
2254 mutex_unlock(&ar->conf_mutex);
2255}
2256
2257/*
2258 * FIXME: Has to be verified.
2259 */
2260#define SUPPORTED_FILTERS \
2261 (FIF_PROMISC_IN_BSS | \
2262 FIF_ALLMULTI | \
2263 FIF_CONTROL | \
2264 FIF_PSPOLL | \
2265 FIF_OTHER_BSS | \
2266 FIF_BCN_PRBRESP_PROMISC | \
2267 FIF_PROBE_REQ | \
2268 FIF_FCSFAIL)
2269
2270static void ath10k_configure_filter(struct ieee80211_hw *hw,
2271 unsigned int changed_flags,
2272 unsigned int *total_flags,
2273 u64 multicast)
2274{
2275 struct ath10k *ar = hw->priv;
2276 int ret;
2277
2278 mutex_lock(&ar->conf_mutex);
2279
2280 changed_flags &= SUPPORTED_FILTERS;
2281 *total_flags &= SUPPORTED_FILTERS;
2282 ar->filter_flags = *total_flags;
2283
afd0922e
MK
2284 /* Monitor must not be started if it wasn't created first.
2285 * Promiscuous mode may be started on a non-monitor interface - in
2286 * such case the monitor vdev is not created so starting the
2287 * monitor makes no sense. Since ath10k uses no special RX filters
2288 * (only BSS filter in STA mode) there's no need for any special
2289 * action here. */
5e3dd157 2290 if ((ar->filter_flags & FIF_PROMISC_IN_BSS) &&
afd0922e 2291 !ar->monitor_enabled && ar->monitor_present) {
60c3daa8
KV
2292 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor %d start\n",
2293 ar->monitor_vdev_id);
2294
5e3dd157
KV
2295 ret = ath10k_monitor_start(ar, ar->monitor_vdev_id);
2296 if (ret)
2297 ath10k_warn("Unable to start monitor mode\n");
5e3dd157 2298 } else if (!(ar->filter_flags & FIF_PROMISC_IN_BSS) &&
afd0922e 2299 ar->monitor_enabled && ar->monitor_present) {
60c3daa8
KV
2300 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor %d stop\n",
2301 ar->monitor_vdev_id);
2302
5e3dd157
KV
2303 ret = ath10k_monitor_stop(ar);
2304 if (ret)
2305 ath10k_warn("Unable to stop monitor mode\n");
5e3dd157
KV
2306 }
2307
2308 mutex_unlock(&ar->conf_mutex);
2309}
2310
2311static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
2312 struct ieee80211_vif *vif,
2313 struct ieee80211_bss_conf *info,
2314 u32 changed)
2315{
2316 struct ath10k *ar = hw->priv;
2317 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2318 int ret = 0;
226a339b 2319 u32 vdev_param, pdev_param;
5e3dd157
KV
2320
2321 mutex_lock(&ar->conf_mutex);
2322
2323 if (changed & BSS_CHANGED_IBSS)
2324 ath10k_control_ibss(arvif, info, vif->addr);
2325
2326 if (changed & BSS_CHANGED_BEACON_INT) {
2327 arvif->beacon_interval = info->beacon_int;
6d1506e7
BM
2328 vdev_param = ar->wmi.vdev_param->beacon_interval;
2329 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5e3dd157 2330 arvif->beacon_interval);
60c3daa8
KV
2331 ath10k_dbg(ATH10K_DBG_MAC,
2332 "mac vdev %d beacon_interval %d\n",
2333 arvif->vdev_id, arvif->beacon_interval);
2334
5e3dd157
KV
2335 if (ret)
2336 ath10k_warn("Failed to set beacon interval for VDEV: %d\n",
2337 arvif->vdev_id);
5e3dd157
KV
2338 }
2339
2340 if (changed & BSS_CHANGED_BEACON) {
60c3daa8
KV
2341 ath10k_dbg(ATH10K_DBG_MAC,
2342 "vdev %d set beacon tx mode to staggered\n",
2343 arvif->vdev_id);
2344
226a339b
BM
2345 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
2346 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
5e3dd157
KV
2347 WMI_BEACON_STAGGERED_MODE);
2348 if (ret)
2349 ath10k_warn("Failed to set beacon mode for VDEV: %d\n",
2350 arvif->vdev_id);
5e3dd157
KV
2351 }
2352
b70727e8 2353 if (changed & BSS_CHANGED_BEACON_INFO) {
5e3dd157
KV
2354 arvif->dtim_period = info->dtim_period;
2355
60c3daa8
KV
2356 ath10k_dbg(ATH10K_DBG_MAC,
2357 "mac vdev %d dtim_period %d\n",
2358 arvif->vdev_id, arvif->dtim_period);
2359
6d1506e7
BM
2360 vdev_param = ar->wmi.vdev_param->dtim_period;
2361 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5e3dd157
KV
2362 arvif->dtim_period);
2363 if (ret)
2364 ath10k_warn("Failed to set dtim period for VDEV: %d\n",
2365 arvif->vdev_id);
5e3dd157
KV
2366 }
2367
2368 if (changed & BSS_CHANGED_SSID &&
2369 vif->type == NL80211_IFTYPE_AP) {
2370 arvif->u.ap.ssid_len = info->ssid_len;
2371 if (info->ssid_len)
2372 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
2373 arvif->u.ap.hidden_ssid = info->hidden_ssid;
2374 }
2375
2376 if (changed & BSS_CHANGED_BSSID) {
2377 if (!is_zero_ether_addr(info->bssid)) {
60c3daa8
KV
2378 ath10k_dbg(ATH10K_DBG_MAC,
2379 "mac vdev %d create peer %pM\n",
2380 arvif->vdev_id, info->bssid);
2381
5e3dd157
KV
2382 ret = ath10k_peer_create(ar, arvif->vdev_id,
2383 info->bssid);
2384 if (ret)
2385 ath10k_warn("Failed to add peer: %pM for VDEV: %d\n",
2386 info->bssid, arvif->vdev_id);
5e3dd157
KV
2387
2388 if (vif->type == NL80211_IFTYPE_STATION) {
2389 /*
2390 * this is never erased as we it for crypto key
2391 * clearing; this is FW requirement
2392 */
2393 memcpy(arvif->u.sta.bssid, info->bssid,
2394 ETH_ALEN);
2395
60c3daa8
KV
2396 ath10k_dbg(ATH10K_DBG_MAC,
2397 "mac vdev %d start %pM\n",
2398 arvif->vdev_id, info->bssid);
2399
2400 /* FIXME: check return value */
5e3dd157 2401 ret = ath10k_vdev_start(arvif);
5e3dd157
KV
2402 }
2403
2404 /*
2405 * Mac80211 does not keep IBSS bssid when leaving IBSS,
2406 * so driver need to store it. It is needed when leaving
2407 * IBSS in order to remove BSSID peer.
2408 */
2409 if (vif->type == NL80211_IFTYPE_ADHOC)
2410 memcpy(arvif->u.ibss.bssid, info->bssid,
2411 ETH_ALEN);
2412 }
2413 }
2414
2415 if (changed & BSS_CHANGED_BEACON_ENABLED)
2416 ath10k_control_beaconing(arvif, info);
2417
2418 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
2419 u32 cts_prot;
2420 if (info->use_cts_prot)
2421 cts_prot = 1;
2422 else
2423 cts_prot = 0;
2424
60c3daa8
KV
2425 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
2426 arvif->vdev_id, cts_prot);
2427
6d1506e7
BM
2428 vdev_param = ar->wmi.vdev_param->enable_rtscts;
2429 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5e3dd157
KV
2430 cts_prot);
2431 if (ret)
2432 ath10k_warn("Failed to set CTS prot for VDEV: %d\n",
2433 arvif->vdev_id);
5e3dd157
KV
2434 }
2435
2436 if (changed & BSS_CHANGED_ERP_SLOT) {
2437 u32 slottime;
2438 if (info->use_short_slot)
2439 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
2440
2441 else
2442 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
2443
60c3daa8
KV
2444 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
2445 arvif->vdev_id, slottime);
2446
6d1506e7
BM
2447 vdev_param = ar->wmi.vdev_param->slot_time;
2448 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5e3dd157
KV
2449 slottime);
2450 if (ret)
2451 ath10k_warn("Failed to set erp slot for VDEV: %d\n",
2452 arvif->vdev_id);
5e3dd157
KV
2453 }
2454
2455 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
2456 u32 preamble;
2457 if (info->use_short_preamble)
2458 preamble = WMI_VDEV_PREAMBLE_SHORT;
2459 else
2460 preamble = WMI_VDEV_PREAMBLE_LONG;
2461
60c3daa8
KV
2462 ath10k_dbg(ATH10K_DBG_MAC,
2463 "mac vdev %d preamble %dn",
2464 arvif->vdev_id, preamble);
2465
6d1506e7
BM
2466 vdev_param = ar->wmi.vdev_param->preamble;
2467 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5e3dd157
KV
2468 preamble);
2469 if (ret)
2470 ath10k_warn("Failed to set preamble for VDEV: %d\n",
2471 arvif->vdev_id);
5e3dd157
KV
2472 }
2473
2474 if (changed & BSS_CHANGED_ASSOC) {
2475 if (info->assoc)
2476 ath10k_bss_assoc(hw, vif, info);
2477 }
2478
2479 mutex_unlock(&ar->conf_mutex);
2480}
2481
2482static int ath10k_hw_scan(struct ieee80211_hw *hw,
2483 struct ieee80211_vif *vif,
2484 struct cfg80211_scan_request *req)
2485{
2486 struct ath10k *ar = hw->priv;
2487 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2488 struct wmi_start_scan_arg arg;
2489 int ret = 0;
2490 int i;
2491
2492 mutex_lock(&ar->conf_mutex);
2493
2494 spin_lock_bh(&ar->data_lock);
2495 if (ar->scan.in_progress) {
2496 spin_unlock_bh(&ar->data_lock);
2497 ret = -EBUSY;
2498 goto exit;
2499 }
2500
2501 INIT_COMPLETION(ar->scan.started);
2502 INIT_COMPLETION(ar->scan.completed);
2503 ar->scan.in_progress = true;
2504 ar->scan.aborting = false;
2505 ar->scan.is_roc = false;
2506 ar->scan.vdev_id = arvif->vdev_id;
2507 spin_unlock_bh(&ar->data_lock);
2508
2509 memset(&arg, 0, sizeof(arg));
2510 ath10k_wmi_start_scan_init(ar, &arg);
2511 arg.vdev_id = arvif->vdev_id;
2512 arg.scan_id = ATH10K_SCAN_ID;
2513
2514 if (!req->no_cck)
2515 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
2516
2517 if (req->ie_len) {
2518 arg.ie_len = req->ie_len;
2519 memcpy(arg.ie, req->ie, arg.ie_len);
2520 }
2521
2522 if (req->n_ssids) {
2523 arg.n_ssids = req->n_ssids;
2524 for (i = 0; i < arg.n_ssids; i++) {
2525 arg.ssids[i].len = req->ssids[i].ssid_len;
2526 arg.ssids[i].ssid = req->ssids[i].ssid;
2527 }
dcd4a561
MK
2528 } else {
2529 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
5e3dd157
KV
2530 }
2531
2532 if (req->n_channels) {
2533 arg.n_channels = req->n_channels;
2534 for (i = 0; i < arg.n_channels; i++)
2535 arg.channels[i] = req->channels[i]->center_freq;
2536 }
2537
2538 ret = ath10k_start_scan(ar, &arg);
2539 if (ret) {
2540 ath10k_warn("could not start hw scan (%d)\n", ret);
2541 spin_lock_bh(&ar->data_lock);
2542 ar->scan.in_progress = false;
2543 spin_unlock_bh(&ar->data_lock);
2544 }
2545
2546exit:
2547 mutex_unlock(&ar->conf_mutex);
2548 return ret;
2549}
2550
2551static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
2552 struct ieee80211_vif *vif)
2553{
2554 struct ath10k *ar = hw->priv;
2555 int ret;
2556
2557 mutex_lock(&ar->conf_mutex);
2558 ret = ath10k_abort_scan(ar);
2559 if (ret) {
2560 ath10k_warn("couldn't abort scan (%d). forcefully sending scan completion to mac80211\n",
2561 ret);
2562 ieee80211_scan_completed(hw, 1 /* aborted */);
2563 }
2564 mutex_unlock(&ar->conf_mutex);
2565}
2566
2567static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2568 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
2569 struct ieee80211_key_conf *key)
2570{
2571 struct ath10k *ar = hw->priv;
2572 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2573 struct ath10k_peer *peer;
2574 const u8 *peer_addr;
2575 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
2576 key->cipher == WLAN_CIPHER_SUITE_WEP104;
2577 int ret = 0;
2578
2579 if (key->keyidx > WMI_MAX_KEY_INDEX)
2580 return -ENOSPC;
2581
2582 mutex_lock(&ar->conf_mutex);
2583
2584 if (sta)
2585 peer_addr = sta->addr;
2586 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
2587 peer_addr = vif->bss_conf.bssid;
2588 else
2589 peer_addr = vif->addr;
2590
2591 key->hw_key_idx = key->keyidx;
2592
2593 /* the peer should not disappear in mid-way (unless FW goes awry) since
2594 * we already hold conf_mutex. we just make sure its there now. */
2595 spin_lock_bh(&ar->data_lock);
2596 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
2597 spin_unlock_bh(&ar->data_lock);
2598
2599 if (!peer) {
2600 if (cmd == SET_KEY) {
2601 ath10k_warn("cannot install key for non-existent peer %pM\n",
2602 peer_addr);
2603 ret = -EOPNOTSUPP;
2604 goto exit;
2605 } else {
2606 /* if the peer doesn't exist there is no key to disable
2607 * anymore */
2608 goto exit;
2609 }
2610 }
2611
2612 if (is_wep) {
2613 if (cmd == SET_KEY)
2614 arvif->wep_keys[key->keyidx] = key;
2615 else
2616 arvif->wep_keys[key->keyidx] = NULL;
2617
2618 if (cmd == DISABLE_KEY)
2619 ath10k_clear_vdev_key(arvif, key);
2620 }
2621
2622 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
2623 if (ret) {
2624 ath10k_warn("ath10k_install_key failed (%d)\n", ret);
2625 goto exit;
2626 }
2627
2628 spin_lock_bh(&ar->data_lock);
2629 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
2630 if (peer && cmd == SET_KEY)
2631 peer->keys[key->keyidx] = key;
2632 else if (peer && cmd == DISABLE_KEY)
2633 peer->keys[key->keyidx] = NULL;
2634 else if (peer == NULL)
2635 /* impossible unless FW goes crazy */
2636 ath10k_warn("peer %pM disappeared!\n", peer_addr);
2637 spin_unlock_bh(&ar->data_lock);
2638
2639exit:
2640 mutex_unlock(&ar->conf_mutex);
2641 return ret;
2642}
2643
2644static int ath10k_sta_state(struct ieee80211_hw *hw,
2645 struct ieee80211_vif *vif,
2646 struct ieee80211_sta *sta,
2647 enum ieee80211_sta_state old_state,
2648 enum ieee80211_sta_state new_state)
2649{
2650 struct ath10k *ar = hw->priv;
2651 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2652 int ret = 0;
2653
2654 mutex_lock(&ar->conf_mutex);
2655
2656 if (old_state == IEEE80211_STA_NOTEXIST &&
2657 new_state == IEEE80211_STA_NONE &&
2658 vif->type != NL80211_IFTYPE_STATION) {
2659 /*
2660 * New station addition.
2661 */
60c3daa8
KV
2662 ath10k_dbg(ATH10K_DBG_MAC,
2663 "mac vdev %d peer create %pM (new sta)\n",
2664 arvif->vdev_id, sta->addr);
2665
5e3dd157
KV
2666 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
2667 if (ret)
2668 ath10k_warn("Failed to add peer: %pM for VDEV: %d\n",
2669 sta->addr, arvif->vdev_id);
5e3dd157
KV
2670 } else if ((old_state == IEEE80211_STA_NONE &&
2671 new_state == IEEE80211_STA_NOTEXIST)) {
2672 /*
2673 * Existing station deletion.
2674 */
60c3daa8
KV
2675 ath10k_dbg(ATH10K_DBG_MAC,
2676 "mac vdev %d peer delete %pM (sta gone)\n",
2677 arvif->vdev_id, sta->addr);
5e3dd157
KV
2678 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
2679 if (ret)
2680 ath10k_warn("Failed to delete peer: %pM for VDEV: %d\n",
2681 sta->addr, arvif->vdev_id);
5e3dd157
KV
2682
2683 if (vif->type == NL80211_IFTYPE_STATION)
2684 ath10k_bss_disassoc(hw, vif);
2685 } else if (old_state == IEEE80211_STA_AUTH &&
2686 new_state == IEEE80211_STA_ASSOC &&
2687 (vif->type == NL80211_IFTYPE_AP ||
2688 vif->type == NL80211_IFTYPE_ADHOC)) {
2689 /*
2690 * New association.
2691 */
60c3daa8
KV
2692 ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM associated\n",
2693 sta->addr);
2694
5e3dd157
KV
2695 ret = ath10k_station_assoc(ar, arvif, sta);
2696 if (ret)
2697 ath10k_warn("Failed to associate station: %pM\n",
2698 sta->addr);
5e3dd157
KV
2699 } else if (old_state == IEEE80211_STA_ASSOC &&
2700 new_state == IEEE80211_STA_AUTH &&
2701 (vif->type == NL80211_IFTYPE_AP ||
2702 vif->type == NL80211_IFTYPE_ADHOC)) {
2703 /*
2704 * Disassociation.
2705 */
60c3daa8
KV
2706 ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
2707 sta->addr);
2708
5e3dd157
KV
2709 ret = ath10k_station_disassoc(ar, arvif, sta);
2710 if (ret)
2711 ath10k_warn("Failed to disassociate station: %pM\n",
2712 sta->addr);
5e3dd157
KV
2713 }
2714
2715 mutex_unlock(&ar->conf_mutex);
2716 return ret;
2717}
2718
2719static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
2720 u16 ac, bool enable)
2721{
2722 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2723 u32 value = 0;
2724 int ret = 0;
2725
548db54c
MK
2726 lockdep_assert_held(&ar->conf_mutex);
2727
5e3dd157
KV
2728 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
2729 return 0;
2730
2731 switch (ac) {
2732 case IEEE80211_AC_VO:
2733 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
2734 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
2735 break;
2736 case IEEE80211_AC_VI:
2737 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
2738 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
2739 break;
2740 case IEEE80211_AC_BE:
2741 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
2742 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
2743 break;
2744 case IEEE80211_AC_BK:
2745 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
2746 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
2747 break;
2748 }
2749
2750 if (enable)
2751 arvif->u.sta.uapsd |= value;
2752 else
2753 arvif->u.sta.uapsd &= ~value;
2754
2755 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2756 WMI_STA_PS_PARAM_UAPSD,
2757 arvif->u.sta.uapsd);
2758 if (ret) {
2759 ath10k_warn("could not set uapsd params %d\n", ret);
2760 goto exit;
2761 }
2762
2763 if (arvif->u.sta.uapsd)
2764 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
2765 else
2766 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2767
2768 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2769 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
2770 value);
2771 if (ret)
2772 ath10k_warn("could not set rx wake param %d\n", ret);
2773
2774exit:
2775 return ret;
2776}
2777
2778static int ath10k_conf_tx(struct ieee80211_hw *hw,
2779 struct ieee80211_vif *vif, u16 ac,
2780 const struct ieee80211_tx_queue_params *params)
2781{
2782 struct ath10k *ar = hw->priv;
2783 struct wmi_wmm_params_arg *p = NULL;
2784 int ret;
2785
2786 mutex_lock(&ar->conf_mutex);
2787
2788 switch (ac) {
2789 case IEEE80211_AC_VO:
2790 p = &ar->wmm_params.ac_vo;
2791 break;
2792 case IEEE80211_AC_VI:
2793 p = &ar->wmm_params.ac_vi;
2794 break;
2795 case IEEE80211_AC_BE:
2796 p = &ar->wmm_params.ac_be;
2797 break;
2798 case IEEE80211_AC_BK:
2799 p = &ar->wmm_params.ac_bk;
2800 break;
2801 }
2802
2803 if (WARN_ON(!p)) {
2804 ret = -EINVAL;
2805 goto exit;
2806 }
2807
2808 p->cwmin = params->cw_min;
2809 p->cwmax = params->cw_max;
2810 p->aifs = params->aifs;
2811
2812 /*
2813 * The channel time duration programmed in the HW is in absolute
2814 * microseconds, while mac80211 gives the txop in units of
2815 * 32 microseconds.
2816 */
2817 p->txop = params->txop * 32;
2818
2819 /* FIXME: FW accepts wmm params per hw, not per vif */
2820 ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
2821 if (ret) {
2822 ath10k_warn("could not set wmm params %d\n", ret);
2823 goto exit;
2824 }
2825
2826 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
2827 if (ret)
2828 ath10k_warn("could not set sta uapsd %d\n", ret);
2829
2830exit:
2831 mutex_unlock(&ar->conf_mutex);
2832 return ret;
2833}
2834
2835#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
2836
2837static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
2838 struct ieee80211_vif *vif,
2839 struct ieee80211_channel *chan,
2840 int duration,
2841 enum ieee80211_roc_type type)
2842{
2843 struct ath10k *ar = hw->priv;
2844 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2845 struct wmi_start_scan_arg arg;
2846 int ret;
2847
2848 mutex_lock(&ar->conf_mutex);
2849
2850 spin_lock_bh(&ar->data_lock);
2851 if (ar->scan.in_progress) {
2852 spin_unlock_bh(&ar->data_lock);
2853 ret = -EBUSY;
2854 goto exit;
2855 }
2856
2857 INIT_COMPLETION(ar->scan.started);
2858 INIT_COMPLETION(ar->scan.completed);
2859 INIT_COMPLETION(ar->scan.on_channel);
2860 ar->scan.in_progress = true;
2861 ar->scan.aborting = false;
2862 ar->scan.is_roc = true;
2863 ar->scan.vdev_id = arvif->vdev_id;
2864 ar->scan.roc_freq = chan->center_freq;
2865 spin_unlock_bh(&ar->data_lock);
2866
2867 memset(&arg, 0, sizeof(arg));
2868 ath10k_wmi_start_scan_init(ar, &arg);
2869 arg.vdev_id = arvif->vdev_id;
2870 arg.scan_id = ATH10K_SCAN_ID;
2871 arg.n_channels = 1;
2872 arg.channels[0] = chan->center_freq;
2873 arg.dwell_time_active = duration;
2874 arg.dwell_time_passive = duration;
2875 arg.max_scan_time = 2 * duration;
2876 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
2877 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
2878
2879 ret = ath10k_start_scan(ar, &arg);
2880 if (ret) {
2881 ath10k_warn("could not start roc scan (%d)\n", ret);
2882 spin_lock_bh(&ar->data_lock);
2883 ar->scan.in_progress = false;
2884 spin_unlock_bh(&ar->data_lock);
2885 goto exit;
2886 }
2887
2888 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
2889 if (ret == 0) {
2890 ath10k_warn("could not switch to channel for roc scan\n");
2891 ath10k_abort_scan(ar);
2892 ret = -ETIMEDOUT;
2893 goto exit;
2894 }
2895
2896 ret = 0;
2897exit:
2898 mutex_unlock(&ar->conf_mutex);
2899 return ret;
2900}
2901
2902static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
2903{
2904 struct ath10k *ar = hw->priv;
2905
2906 mutex_lock(&ar->conf_mutex);
2907 ath10k_abort_scan(ar);
2908 mutex_unlock(&ar->conf_mutex);
2909
2910 return 0;
2911}
2912
2913/*
2914 * Both RTS and Fragmentation threshold are interface-specific
2915 * in ath10k, but device-specific in mac80211.
2916 */
5e3dd157 2917
ad088bfa
MK
2918static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
2919{
2920 struct ath10k *ar = hw->priv;
2921 struct ath10k_vif *arvif;
2922 int ret = 0;
548db54c 2923
5e3dd157 2924 mutex_lock(&ar->conf_mutex);
ad088bfa
MK
2925 list_for_each_entry(arvif, &ar->arvifs, list) {
2926 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
2927 arvif->vdev_id, value);
2928
2929 ret = ath10k_mac_set_rts(arvif, value);
2930 if (ret) {
2931 ath10k_warn("could not set rts threshold for vdev %d (%d)\n",
2932 arvif->vdev_id, ret);
2933 break;
2934 }
2935 }
5e3dd157
KV
2936 mutex_unlock(&ar->conf_mutex);
2937
ad088bfa 2938 return ret;
5e3dd157
KV
2939}
2940
ad088bfa 2941static int ath10k_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
5e3dd157 2942{
ad088bfa
MK
2943 struct ath10k *ar = hw->priv;
2944 struct ath10k_vif *arvif;
2945 int ret = 0;
548db54c 2946
5e3dd157 2947 mutex_lock(&ar->conf_mutex);
ad088bfa
MK
2948 list_for_each_entry(arvif, &ar->arvifs, list) {
2949 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d fragmentation threshold %d\n",
2950 arvif->vdev_id, value);
2951
2952 ret = ath10k_mac_set_rts(arvif, value);
2953 if (ret) {
2954 ath10k_warn("could not set fragmentation threshold for vdev %d (%d)\n",
2955 arvif->vdev_id, ret);
2956 break;
2957 }
2958 }
5e3dd157
KV
2959 mutex_unlock(&ar->conf_mutex);
2960
ad088bfa 2961 return ret;
5e3dd157
KV
2962}
2963
2964static void ath10k_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
2965{
2966 struct ath10k *ar = hw->priv;
affd3217 2967 bool skip;
5e3dd157
KV
2968 int ret;
2969
2970 /* mac80211 doesn't care if we really xmit queued frames or not
2971 * we'll collect those frames either way if we stop/delete vdevs */
2972 if (drop)
2973 return;
2974
548db54c
MK
2975 mutex_lock(&ar->conf_mutex);
2976
affd3217
MK
2977 if (ar->state == ATH10K_STATE_WEDGED)
2978 goto skip;
2979
edb8236d 2980 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
5e3dd157 2981 bool empty;
affd3217 2982
edb8236d 2983 spin_lock_bh(&ar->htt.tx_lock);
0945baf7 2984 empty = (ar->htt.num_pending_tx == 0);
edb8236d 2985 spin_unlock_bh(&ar->htt.tx_lock);
affd3217
MK
2986
2987 skip = (ar->state == ATH10K_STATE_WEDGED);
2988
2989 (empty || skip);
5e3dd157 2990 }), ATH10K_FLUSH_TIMEOUT_HZ);
affd3217
MK
2991
2992 if (ret <= 0 || skip)
5e3dd157 2993 ath10k_warn("tx not flushed\n");
548db54c 2994
affd3217 2995skip:
548db54c 2996 mutex_unlock(&ar->conf_mutex);
5e3dd157
KV
2997}
2998
2999/* TODO: Implement this function properly
3000 * For now it is needed to reply to Probe Requests in IBSS mode.
3001 * Propably we need this information from FW.
3002 */
3003static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
3004{
3005 return 1;
3006}
3007
8cd13cad
MK
3008#ifdef CONFIG_PM
3009static int ath10k_suspend(struct ieee80211_hw *hw,
3010 struct cfg80211_wowlan *wowlan)
3011{
3012 struct ath10k *ar = hw->priv;
3013 int ret;
3014
3015 ar->is_target_paused = false;
3016
3017 ret = ath10k_wmi_pdev_suspend_target(ar);
3018 if (ret) {
3019 ath10k_warn("could not suspend target (%d)\n", ret);
3020 return 1;
3021 }
3022
3023 ret = wait_event_interruptible_timeout(ar->event_queue,
3024 ar->is_target_paused == true,
3025 1 * HZ);
3026 if (ret < 0) {
3027 ath10k_warn("suspend interrupted (%d)\n", ret);
3028 goto resume;
3029 } else if (ret == 0) {
3030 ath10k_warn("suspend timed out - target pause event never came\n");
3031 goto resume;
3032 }
3033
3034 ret = ath10k_hif_suspend(ar);
3035 if (ret) {
3036 ath10k_warn("could not suspend hif (%d)\n", ret);
3037 goto resume;
3038 }
3039
3040 return 0;
3041resume:
3042 ret = ath10k_wmi_pdev_resume_target(ar);
3043 if (ret)
3044 ath10k_warn("could not resume target (%d)\n", ret);
3045 return 1;
3046}
3047
3048static int ath10k_resume(struct ieee80211_hw *hw)
3049{
3050 struct ath10k *ar = hw->priv;
3051 int ret;
3052
3053 ret = ath10k_hif_resume(ar);
3054 if (ret) {
3055 ath10k_warn("could not resume hif (%d)\n", ret);
3056 return 1;
3057 }
3058
3059 ret = ath10k_wmi_pdev_resume_target(ar);
3060 if (ret) {
3061 ath10k_warn("could not resume target (%d)\n", ret);
3062 return 1;
3063 }
3064
3065 return 0;
3066}
3067#endif
3068
affd3217
MK
3069static void ath10k_restart_complete(struct ieee80211_hw *hw)
3070{
3071 struct ath10k *ar = hw->priv;
3072
3073 mutex_lock(&ar->conf_mutex);
3074
3075 /* If device failed to restart it will be in a different state, e.g.
3076 * ATH10K_STATE_WEDGED */
3077 if (ar->state == ATH10K_STATE_RESTARTED) {
3078 ath10k_info("device successfully recovered\n");
3079 ar->state = ATH10K_STATE_ON;
3080 }
3081
3082 mutex_unlock(&ar->conf_mutex);
3083}
3084
2e1dea40
MK
3085static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
3086 struct survey_info *survey)
3087{
3088 struct ath10k *ar = hw->priv;
3089 struct ieee80211_supported_band *sband;
3090 struct survey_info *ar_survey = &ar->survey[idx];
3091 int ret = 0;
3092
3093 mutex_lock(&ar->conf_mutex);
3094
3095 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
3096 if (sband && idx >= sband->n_channels) {
3097 idx -= sband->n_channels;
3098 sband = NULL;
3099 }
3100
3101 if (!sband)
3102 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
3103
3104 if (!sband || idx >= sband->n_channels) {
3105 ret = -ENOENT;
3106 goto exit;
3107 }
3108
3109 spin_lock_bh(&ar->data_lock);
3110 memcpy(survey, ar_survey, sizeof(*survey));
3111 spin_unlock_bh(&ar->data_lock);
3112
3113 survey->channel = &sband->channels[idx];
3114
3115exit:
3116 mutex_unlock(&ar->conf_mutex);
3117 return ret;
3118}
3119
5e3dd157
KV
3120static const struct ieee80211_ops ath10k_ops = {
3121 .tx = ath10k_tx,
3122 .start = ath10k_start,
3123 .stop = ath10k_stop,
3124 .config = ath10k_config,
3125 .add_interface = ath10k_add_interface,
3126 .remove_interface = ath10k_remove_interface,
3127 .configure_filter = ath10k_configure_filter,
3128 .bss_info_changed = ath10k_bss_info_changed,
3129 .hw_scan = ath10k_hw_scan,
3130 .cancel_hw_scan = ath10k_cancel_hw_scan,
3131 .set_key = ath10k_set_key,
3132 .sta_state = ath10k_sta_state,
3133 .conf_tx = ath10k_conf_tx,
3134 .remain_on_channel = ath10k_remain_on_channel,
3135 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
3136 .set_rts_threshold = ath10k_set_rts_threshold,
3137 .set_frag_threshold = ath10k_set_frag_threshold,
3138 .flush = ath10k_flush,
3139 .tx_last_beacon = ath10k_tx_last_beacon,
affd3217 3140 .restart_complete = ath10k_restart_complete,
2e1dea40 3141 .get_survey = ath10k_get_survey,
8cd13cad
MK
3142#ifdef CONFIG_PM
3143 .suspend = ath10k_suspend,
3144 .resume = ath10k_resume,
3145#endif
5e3dd157
KV
3146};
3147
3148#define RATETAB_ENT(_rate, _rateid, _flags) { \
3149 .bitrate = (_rate), \
3150 .flags = (_flags), \
3151 .hw_value = (_rateid), \
3152}
3153
3154#define CHAN2G(_channel, _freq, _flags) { \
3155 .band = IEEE80211_BAND_2GHZ, \
3156 .hw_value = (_channel), \
3157 .center_freq = (_freq), \
3158 .flags = (_flags), \
3159 .max_antenna_gain = 0, \
3160 .max_power = 30, \
3161}
3162
3163#define CHAN5G(_channel, _freq, _flags) { \
3164 .band = IEEE80211_BAND_5GHZ, \
3165 .hw_value = (_channel), \
3166 .center_freq = (_freq), \
3167 .flags = (_flags), \
3168 .max_antenna_gain = 0, \
3169 .max_power = 30, \
3170}
3171
3172static const struct ieee80211_channel ath10k_2ghz_channels[] = {
3173 CHAN2G(1, 2412, 0),
3174 CHAN2G(2, 2417, 0),
3175 CHAN2G(3, 2422, 0),
3176 CHAN2G(4, 2427, 0),
3177 CHAN2G(5, 2432, 0),
3178 CHAN2G(6, 2437, 0),
3179 CHAN2G(7, 2442, 0),
3180 CHAN2G(8, 2447, 0),
3181 CHAN2G(9, 2452, 0),
3182 CHAN2G(10, 2457, 0),
3183 CHAN2G(11, 2462, 0),
3184 CHAN2G(12, 2467, 0),
3185 CHAN2G(13, 2472, 0),
3186 CHAN2G(14, 2484, 0),
3187};
3188
3189static const struct ieee80211_channel ath10k_5ghz_channels[] = {
429ff56a
MK
3190 CHAN5G(36, 5180, 0),
3191 CHAN5G(40, 5200, 0),
3192 CHAN5G(44, 5220, 0),
3193 CHAN5G(48, 5240, 0),
3194 CHAN5G(52, 5260, 0),
3195 CHAN5G(56, 5280, 0),
3196 CHAN5G(60, 5300, 0),
3197 CHAN5G(64, 5320, 0),
3198 CHAN5G(100, 5500, 0),
3199 CHAN5G(104, 5520, 0),
3200 CHAN5G(108, 5540, 0),
3201 CHAN5G(112, 5560, 0),
3202 CHAN5G(116, 5580, 0),
3203 CHAN5G(120, 5600, 0),
3204 CHAN5G(124, 5620, 0),
3205 CHAN5G(128, 5640, 0),
3206 CHAN5G(132, 5660, 0),
3207 CHAN5G(136, 5680, 0),
3208 CHAN5G(140, 5700, 0),
3209 CHAN5G(149, 5745, 0),
3210 CHAN5G(153, 5765, 0),
3211 CHAN5G(157, 5785, 0),
3212 CHAN5G(161, 5805, 0),
3213 CHAN5G(165, 5825, 0),
5e3dd157
KV
3214};
3215
3216static struct ieee80211_rate ath10k_rates[] = {
3217 /* CCK */
3218 RATETAB_ENT(10, 0x82, 0),
3219 RATETAB_ENT(20, 0x84, 0),
3220 RATETAB_ENT(55, 0x8b, 0),
3221 RATETAB_ENT(110, 0x96, 0),
3222 /* OFDM */
3223 RATETAB_ENT(60, 0x0c, 0),
3224 RATETAB_ENT(90, 0x12, 0),
3225 RATETAB_ENT(120, 0x18, 0),
3226 RATETAB_ENT(180, 0x24, 0),
3227 RATETAB_ENT(240, 0x30, 0),
3228 RATETAB_ENT(360, 0x48, 0),
3229 RATETAB_ENT(480, 0x60, 0),
3230 RATETAB_ENT(540, 0x6c, 0),
3231};
3232
3233#define ath10k_a_rates (ath10k_rates + 4)
3234#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
3235#define ath10k_g_rates (ath10k_rates + 0)
3236#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
3237
3238struct ath10k *ath10k_mac_create(void)
3239{
3240 struct ieee80211_hw *hw;
3241 struct ath10k *ar;
3242
3243 hw = ieee80211_alloc_hw(sizeof(struct ath10k), &ath10k_ops);
3244 if (!hw)
3245 return NULL;
3246
3247 ar = hw->priv;
3248 ar->hw = hw;
3249
3250 return ar;
3251}
3252
3253void ath10k_mac_destroy(struct ath10k *ar)
3254{
3255 ieee80211_free_hw(ar->hw);
3256}
3257
3258static const struct ieee80211_iface_limit ath10k_if_limits[] = {
3259 {
3260 .max = 8,
3261 .types = BIT(NL80211_IFTYPE_STATION)
3262 | BIT(NL80211_IFTYPE_P2P_CLIENT)
d531cb85
MK
3263 },
3264 {
3265 .max = 3,
3266 .types = BIT(NL80211_IFTYPE_P2P_GO)
3267 },
3268 {
3269 .max = 7,
3270 .types = BIT(NL80211_IFTYPE_AP)
3271 },
5e3dd157
KV
3272};
3273
3274static const struct ieee80211_iface_combination ath10k_if_comb = {
3275 .limits = ath10k_if_limits,
3276 .n_limits = ARRAY_SIZE(ath10k_if_limits),
3277 .max_interfaces = 8,
3278 .num_different_channels = 1,
3279 .beacon_int_infra_match = true,
3280};
3281
3282static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
3283{
3284 struct ieee80211_sta_vht_cap vht_cap = {0};
3285 u16 mcs_map;
8865bee4 3286 int i;
5e3dd157
KV
3287
3288 vht_cap.vht_supported = 1;
3289 vht_cap.cap = ar->vht_cap_info;
3290
8865bee4
MK
3291 mcs_map = 0;
3292 for (i = 0; i < 8; i++) {
3293 if (i < ar->num_rf_chains)
3294 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
3295 else
3296 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
3297 }
5e3dd157
KV
3298
3299 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
3300 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
3301
3302 return vht_cap;
3303}
3304
3305static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
3306{
3307 int i;
3308 struct ieee80211_sta_ht_cap ht_cap = {0};
3309
3310 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
3311 return ht_cap;
3312
3313 ht_cap.ht_supported = 1;
3314 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
3315 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
3316 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
3317 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
3318 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
3319
3320 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
3321 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
3322
3323 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
3324 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
3325
3326 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
3327 u32 smps;
3328
3329 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
3330 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
3331
3332 ht_cap.cap |= smps;
3333 }
3334
3335 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
3336 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
3337
3338 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
3339 u32 stbc;
3340
3341 stbc = ar->ht_cap_info;
3342 stbc &= WMI_HT_CAP_RX_STBC;
3343 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
3344 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
3345 stbc &= IEEE80211_HT_CAP_RX_STBC;
3346
3347 ht_cap.cap |= stbc;
3348 }
3349
3350 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
3351 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
3352
3353 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
3354 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
3355
3356 /* max AMSDU is implicitly taken from vht_cap_info */
3357 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
3358 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
3359
8865bee4 3360 for (i = 0; i < ar->num_rf_chains; i++)
5e3dd157
KV
3361 ht_cap.mcs.rx_mask[i] = 0xFF;
3362
3363 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
3364
3365 return ht_cap;
3366}
3367
3368
3369static void ath10k_get_arvif_iter(void *data, u8 *mac,
3370 struct ieee80211_vif *vif)
3371{
3372 struct ath10k_vif_iter *arvif_iter = data;
3373 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3374
3375 if (arvif->vdev_id == arvif_iter->vdev_id)
3376 arvif_iter->arvif = arvif;
3377}
3378
3379struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
3380{
3381 struct ath10k_vif_iter arvif_iter;
3382 u32 flags;
3383
3384 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
3385 arvif_iter.vdev_id = vdev_id;
3386
3387 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
3388 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3389 flags,
3390 ath10k_get_arvif_iter,
3391 &arvif_iter);
3392 if (!arvif_iter.arvif) {
3393 ath10k_warn("No VIF found for VDEV: %d\n", vdev_id);
3394 return NULL;
3395 }
3396
3397 return arvif_iter.arvif;
3398}
3399
3400int ath10k_mac_register(struct ath10k *ar)
3401{
3402 struct ieee80211_supported_band *band;
3403 struct ieee80211_sta_vht_cap vht_cap;
3404 struct ieee80211_sta_ht_cap ht_cap;
3405 void *channels;
3406 int ret;
3407
3408 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
3409
3410 SET_IEEE80211_DEV(ar->hw, ar->dev);
3411
3412 ht_cap = ath10k_get_ht_cap(ar);
3413 vht_cap = ath10k_create_vht_cap(ar);
3414
3415 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
3416 channels = kmemdup(ath10k_2ghz_channels,
3417 sizeof(ath10k_2ghz_channels),
3418 GFP_KERNEL);
d6015b27
MK
3419 if (!channels) {
3420 ret = -ENOMEM;
3421 goto err_free;
3422 }
5e3dd157
KV
3423
3424 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
3425 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
3426 band->channels = channels;
3427 band->n_bitrates = ath10k_g_rates_size;
3428 band->bitrates = ath10k_g_rates;
3429 band->ht_cap = ht_cap;
3430
3431 /* vht is not supported in 2.4 GHz */
3432
3433 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
3434 }
3435
3436 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
3437 channels = kmemdup(ath10k_5ghz_channels,
3438 sizeof(ath10k_5ghz_channels),
3439 GFP_KERNEL);
3440 if (!channels) {
d6015b27
MK
3441 ret = -ENOMEM;
3442 goto err_free;
5e3dd157
KV
3443 }
3444
3445 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
3446 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
3447 band->channels = channels;
3448 band->n_bitrates = ath10k_a_rates_size;
3449 band->bitrates = ath10k_a_rates;
3450 band->ht_cap = ht_cap;
3451 band->vht_cap = vht_cap;
3452 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
3453 }
3454
3455 ar->hw->wiphy->interface_modes =
3456 BIT(NL80211_IFTYPE_STATION) |
3457 BIT(NL80211_IFTYPE_ADHOC) |
3458 BIT(NL80211_IFTYPE_AP) |
3459 BIT(NL80211_IFTYPE_P2P_CLIENT) |
3460 BIT(NL80211_IFTYPE_P2P_GO);
3461
3462 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
3463 IEEE80211_HW_SUPPORTS_PS |
3464 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
3465 IEEE80211_HW_SUPPORTS_UAPSD |
3466 IEEE80211_HW_MFP_CAPABLE |
3467 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
3468 IEEE80211_HW_HAS_RATE_CONTROL |
3469 IEEE80211_HW_SUPPORTS_STATIC_SMPS |
3470 IEEE80211_HW_WANT_MONITOR_VIF |
3471 IEEE80211_HW_AP_LINK_PS;
3472
1f8bb151
MK
3473 /* MSDU can have HTT TX fragment pushed in front. The additional 4
3474 * bytes is used for padding/alignment if necessary. */
3475 ar->hw->extra_tx_headroom += sizeof(struct htt_data_tx_desc_frag)*2 + 4;
3476
5e3dd157
KV
3477 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
3478 ar->hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS;
3479
3480 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
3481 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
3482 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
3483 }
3484
3485 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
3486 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
3487
3488 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
3489
3490 ar->hw->channel_change_time = 5000;
3491 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
3492
3493 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
3494 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
3495
3496 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
3497 /*
3498 * on LL hardware queues are managed entirely by the FW
3499 * so we only advertise to mac we can do the queues thing
3500 */
3501 ar->hw->queues = 4;
3502
3503 ar->hw->wiphy->iface_combinations = &ath10k_if_comb;
3504 ar->hw->wiphy->n_iface_combinations = 1;
3505
7c199997
MK
3506 ar->hw->netdev_features = NETIF_F_HW_CSUM;
3507
5e3dd157
KV
3508 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
3509 ath10k_reg_notifier);
3510 if (ret) {
3511 ath10k_err("Regulatory initialization failed\n");
d6015b27 3512 goto err_free;
5e3dd157
KV
3513 }
3514
3515 ret = ieee80211_register_hw(ar->hw);
3516 if (ret) {
3517 ath10k_err("ieee80211 registration failed: %d\n", ret);
d6015b27 3518 goto err_free;
5e3dd157
KV
3519 }
3520
3521 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
3522 ret = regulatory_hint(ar->hw->wiphy,
3523 ar->ath_common.regulatory.alpha2);
3524 if (ret)
d6015b27 3525 goto err_unregister;
5e3dd157
KV
3526 }
3527
3528 return 0;
d6015b27
MK
3529
3530err_unregister:
5e3dd157 3531 ieee80211_unregister_hw(ar->hw);
d6015b27
MK
3532err_free:
3533 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
3534 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
3535
5e3dd157
KV
3536 return ret;
3537}
3538
3539void ath10k_mac_unregister(struct ath10k *ar)
3540{
3541 ieee80211_unregister_hw(ar->hw);
3542
3543 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
3544 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
3545
3546 SET_IEEE80211_DEV(ar->hw, NULL);
3547}
This page took 0.238287 seconds and 5 git commands to generate.