ath10k: add soft/hard firmware crash option to simulate_fw_crash
[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
16735d02 95 reinit_completion(&ar->install_key_done);
5e3dd157
KV
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);
479398b0 325 if (ret) {
69244e56
BG
326 ath10k_warn("Failed to create wmi peer %pM on vdev %i: %i\n",
327 addr, vdev_id, ret);
5e3dd157 328 return ret;
479398b0 329 }
5e3dd157
KV
330
331 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
479398b0 332 if (ret) {
69244e56
BG
333 ath10k_warn("Failed to wait for created wmi peer %pM on vdev %i: %i\n",
334 addr, vdev_id, ret);
5e3dd157 335 return ret;
479398b0 336 }
0e759f36
BM
337 spin_lock_bh(&ar->data_lock);
338 ar->num_peers++;
339 spin_unlock_bh(&ar->data_lock);
5e3dd157
KV
340
341 return 0;
342}
343
5a13e76e
KV
344static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
345{
346 struct ath10k *ar = arvif->ar;
347 u32 param;
348 int ret;
349
350 param = ar->wmi.pdev_param->sta_kickout_th;
351 ret = ath10k_wmi_pdev_set_param(ar, param,
352 ATH10K_KICKOUT_THRESHOLD);
353 if (ret) {
69244e56
BG
354 ath10k_warn("Failed to set kickout threshold on vdev %i: %d\n",
355 arvif->vdev_id, ret);
5a13e76e
KV
356 return ret;
357 }
358
359 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
360 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
361 ATH10K_KEEPALIVE_MIN_IDLE);
362 if (ret) {
69244e56
BG
363 ath10k_warn("Failed to set keepalive minimum idle time on vdev %i : %d\n",
364 arvif->vdev_id, ret);
5a13e76e
KV
365 return ret;
366 }
367
368 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
369 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
370 ATH10K_KEEPALIVE_MAX_IDLE);
371 if (ret) {
69244e56
BG
372 ath10k_warn("Failed to set keepalive maximum idle time on vdev %i: %d\n",
373 arvif->vdev_id, ret);
5a13e76e
KV
374 return ret;
375 }
376
377 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
378 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
379 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
380 if (ret) {
69244e56
BG
381 ath10k_warn("Failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
382 arvif->vdev_id, ret);
5a13e76e
KV
383 return ret;
384 }
385
386 return 0;
387}
388
424121c3
MK
389static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
390{
6d1506e7
BM
391 struct ath10k *ar = arvif->ar;
392 u32 vdev_param;
393
424121c3
MK
394 if (value != 0xFFFFFFFF)
395 value = min_t(u32, arvif->ar->hw->wiphy->rts_threshold,
396 ATH10K_RTS_MAX);
397
6d1506e7
BM
398 vdev_param = ar->wmi.vdev_param->rts_threshold;
399 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
424121c3
MK
400}
401
402static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
403{
6d1506e7
BM
404 struct ath10k *ar = arvif->ar;
405 u32 vdev_param;
406
424121c3
MK
407 if (value != 0xFFFFFFFF)
408 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
409 ATH10K_FRAGMT_THRESHOLD_MIN,
410 ATH10K_FRAGMT_THRESHOLD_MAX);
411
6d1506e7
BM
412 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
413 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
424121c3
MK
414}
415
5e3dd157
KV
416static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
417{
418 int ret;
419
420 lockdep_assert_held(&ar->conf_mutex);
421
422 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
423 if (ret)
424 return ret;
425
426 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
427 if (ret)
428 return ret;
429
0e759f36
BM
430 spin_lock_bh(&ar->data_lock);
431 ar->num_peers--;
432 spin_unlock_bh(&ar->data_lock);
433
5e3dd157
KV
434 return 0;
435}
436
437static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
438{
439 struct ath10k_peer *peer, *tmp;
440
441 lockdep_assert_held(&ar->conf_mutex);
442
443 spin_lock_bh(&ar->data_lock);
444 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
445 if (peer->vdev_id != vdev_id)
446 continue;
447
448 ath10k_warn("removing stale peer %pM from vdev_id %d\n",
449 peer->addr, vdev_id);
450
451 list_del(&peer->list);
452 kfree(peer);
0e759f36 453 ar->num_peers--;
5e3dd157
KV
454 }
455 spin_unlock_bh(&ar->data_lock);
456}
457
a96d7745
MK
458static void ath10k_peer_cleanup_all(struct ath10k *ar)
459{
460 struct ath10k_peer *peer, *tmp;
461
462 lockdep_assert_held(&ar->conf_mutex);
463
464 spin_lock_bh(&ar->data_lock);
465 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
466 list_del(&peer->list);
467 kfree(peer);
468 }
0e759f36 469 ar->num_peers = 0;
a96d7745
MK
470 spin_unlock_bh(&ar->data_lock);
471}
472
5e3dd157
KV
473/************************/
474/* Interface management */
475/************************/
476
477static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
478{
479 int ret;
480
548db54c
MK
481 lockdep_assert_held(&ar->conf_mutex);
482
5e3dd157
KV
483 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
484 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
485 if (ret == 0)
486 return -ETIMEDOUT;
487
488 return 0;
489}
490
491static int ath10k_vdev_start(struct ath10k_vif *arvif)
492{
493 struct ath10k *ar = arvif->ar;
c930f744 494 struct cfg80211_chan_def *chandef = &ar->chandef;
5e3dd157
KV
495 struct wmi_vdev_start_request_arg arg = {};
496 int ret = 0;
497
498 lockdep_assert_held(&ar->conf_mutex);
499
16735d02 500 reinit_completion(&ar->vdev_setup_done);
5e3dd157
KV
501
502 arg.vdev_id = arvif->vdev_id;
503 arg.dtim_period = arvif->dtim_period;
504 arg.bcn_intval = arvif->beacon_interval;
505
c930f744
MK
506 arg.channel.freq = chandef->chan->center_freq;
507 arg.channel.band_center_freq1 = chandef->center_freq1;
508 arg.channel.mode = chan_to_phymode(chandef);
5e3dd157 509
89c5c843 510 arg.channel.min_power = 0;
c930f744
MK
511 arg.channel.max_power = chandef->chan->max_power * 2;
512 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
513 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
5e3dd157
KV
514
515 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
516 arg.ssid = arvif->u.ap.ssid;
517 arg.ssid_len = arvif->u.ap.ssid_len;
518 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
e8a50f8b
MP
519
520 /* For now allow DFS for AP mode */
521 arg.channel.chan_radar =
c930f744 522 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
5e3dd157
KV
523 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
524 arg.ssid = arvif->vif->bss_conf.ssid;
525 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
526 }
527
38a1d47e
KV
528 ath10k_dbg(ATH10K_DBG_MAC,
529 "mac vdev %d start center_freq %d phymode %s\n",
530 arg.vdev_id, arg.channel.freq,
531 ath10k_wmi_phymode_str(arg.channel.mode));
532
5e3dd157
KV
533 ret = ath10k_wmi_vdev_start(ar, &arg);
534 if (ret) {
69244e56
BG
535 ath10k_warn("WMI vdev %i start failed: ret %d\n",
536 arg.vdev_id, ret);
5e3dd157
KV
537 return ret;
538 }
539
540 ret = ath10k_vdev_setup_sync(ar);
541 if (ret) {
69244e56
BG
542 ath10k_warn("vdev %i setup failed %d\n",
543 arg.vdev_id, ret);
5e3dd157
KV
544 return ret;
545 }
546
547 return ret;
548}
549
550static int ath10k_vdev_stop(struct ath10k_vif *arvif)
551{
552 struct ath10k *ar = arvif->ar;
553 int ret;
554
555 lockdep_assert_held(&ar->conf_mutex);
556
16735d02 557 reinit_completion(&ar->vdev_setup_done);
5e3dd157
KV
558
559 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
560 if (ret) {
69244e56
BG
561 ath10k_warn("WMI vdev %i stop failed: ret %d\n",
562 arvif->vdev_id, ret);
5e3dd157
KV
563 return ret;
564 }
565
566 ret = ath10k_vdev_setup_sync(ar);
567 if (ret) {
69244e56
BG
568 ath10k_warn("vdev %i setup sync failed %d\n",
569 arvif->vdev_id, ret);
5e3dd157
KV
570 return ret;
571 }
572
573 return ret;
574}
575
576static int ath10k_monitor_start(struct ath10k *ar, int vdev_id)
577{
c930f744
MK
578 struct cfg80211_chan_def *chandef = &ar->chandef;
579 struct ieee80211_channel *channel = chandef->chan;
5e3dd157 580 struct wmi_vdev_start_request_arg arg = {};
5e3dd157
KV
581 int ret = 0;
582
583 lockdep_assert_held(&ar->conf_mutex);
584
0ed00eea
MK
585 if (!ar->monitor_present) {
586 ath10k_warn("mac montor stop -- monitor is not present\n");
587 return -EINVAL;
588 }
589
5e3dd157
KV
590 arg.vdev_id = vdev_id;
591 arg.channel.freq = channel->center_freq;
c930f744 592 arg.channel.band_center_freq1 = chandef->center_freq1;
5e3dd157
KV
593
594 /* TODO setup this dynamically, what in case we
595 don't have any vifs? */
c930f744 596 arg.channel.mode = chan_to_phymode(chandef);
e8a50f8b
MP
597 arg.channel.chan_radar =
598 !!(channel->flags & IEEE80211_CHAN_RADAR);
5e3dd157 599
89c5c843 600 arg.channel.min_power = 0;
02256930
MK
601 arg.channel.max_power = channel->max_power * 2;
602 arg.channel.max_reg_power = channel->max_reg_power * 2;
603 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
5e3dd157
KV
604
605 ret = ath10k_wmi_vdev_start(ar, &arg);
606 if (ret) {
69244e56
BG
607 ath10k_warn("Monitor vdev %i start failed: ret %d\n",
608 vdev_id, ret);
5e3dd157
KV
609 return ret;
610 }
611
612 ret = ath10k_vdev_setup_sync(ar);
613 if (ret) {
69244e56
BG
614 ath10k_warn("Monitor vdev %i setup failed %d\n",
615 vdev_id, ret);
5e3dd157
KV
616 return ret;
617 }
618
619 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
620 if (ret) {
69244e56
BG
621 ath10k_warn("Monitor vdev %i up failed: %d\n",
622 vdev_id, ret);
5e3dd157
KV
623 goto vdev_stop;
624 }
625
626 ar->monitor_vdev_id = vdev_id;
627 ar->monitor_enabled = true;
628
629 return 0;
630
631vdev_stop:
632 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
633 if (ret)
69244e56
BG
634 ath10k_warn("Monitor vdev %i stop failed: %d\n",
635 ar->monitor_vdev_id, ret);
5e3dd157
KV
636
637 return ret;
638}
639
640static int ath10k_monitor_stop(struct ath10k *ar)
641{
642 int ret = 0;
643
644 lockdep_assert_held(&ar->conf_mutex);
645
0ed00eea
MK
646 if (!ar->monitor_present) {
647 ath10k_warn("mac montor stop -- monitor is not present\n");
648 return -EINVAL;
649 }
650
651 if (!ar->monitor_enabled) {
652 ath10k_warn("mac montor stop -- monitor is not enabled\n");
653 return -EINVAL;
654 }
655
52fa0191
MP
656 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
657 if (ret)
69244e56
BG
658 ath10k_warn("Monitor vdev %i down failed: %d\n",
659 ar->monitor_vdev_id, ret);
5e3dd157
KV
660
661 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
662 if (ret)
69244e56
BG
663 ath10k_warn("Monitor vdev %i stop failed: %d\n",
664 ar->monitor_vdev_id, ret);
5e3dd157
KV
665
666 ret = ath10k_vdev_setup_sync(ar);
667 if (ret)
69244e56
BG
668 ath10k_warn("Monitor_down sync failed, vdev %i: %d\n",
669 ar->monitor_vdev_id, ret);
5e3dd157
KV
670
671 ar->monitor_enabled = false;
672 return ret;
673}
674
675static int ath10k_monitor_create(struct ath10k *ar)
676{
677 int bit, ret = 0;
678
679 lockdep_assert_held(&ar->conf_mutex);
680
681 if (ar->monitor_present) {
682 ath10k_warn("Monitor mode already enabled\n");
683 return 0;
684 }
685
686 bit = ffs(ar->free_vdev_map);
687 if (bit == 0) {
688 ath10k_warn("No free VDEV slots\n");
689 return -ENOMEM;
690 }
691
692 ar->monitor_vdev_id = bit - 1;
693 ar->free_vdev_map &= ~(1 << ar->monitor_vdev_id);
694
695 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
696 WMI_VDEV_TYPE_MONITOR,
697 0, ar->mac_addr);
698 if (ret) {
69244e56
BG
699 ath10k_warn("WMI vdev %i monitor create failed: ret %d\n",
700 ar->monitor_vdev_id, ret);
5e3dd157
KV
701 goto vdev_fail;
702 }
703
60c3daa8 704 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
5e3dd157
KV
705 ar->monitor_vdev_id);
706
707 ar->monitor_present = true;
708 return 0;
709
710vdev_fail:
711 /*
712 * Restore the ID to the global map.
713 */
714 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
715 return ret;
716}
717
718static int ath10k_monitor_destroy(struct ath10k *ar)
719{
720 int ret = 0;
721
722 lockdep_assert_held(&ar->conf_mutex);
723
724 if (!ar->monitor_present)
725 return 0;
726
727 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
728 if (ret) {
69244e56
BG
729 ath10k_warn("WMI vdev %i monitor delete failed: %d\n",
730 ar->monitor_vdev_id, ret);
5e3dd157
KV
731 return ret;
732 }
733
734 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
735 ar->monitor_present = false;
736
60c3daa8 737 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
5e3dd157
KV
738 ar->monitor_vdev_id);
739 return ret;
740}
741
e81bd104
MK
742static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
743{
744 struct ath10k *ar = arvif->ar;
745 u32 vdev_param, rts_cts = 0;
746
747 lockdep_assert_held(&ar->conf_mutex);
748
749 vdev_param = ar->wmi.vdev_param->enable_rtscts;
750
751 if (arvif->use_cts_prot || arvif->num_legacy_stations > 0)
752 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
753
754 if (arvif->num_legacy_stations > 0)
755 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
756 WMI_RTSCTS_PROFILE);
757
758 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
759 rts_cts);
760}
761
e8a50f8b
MP
762static int ath10k_start_cac(struct ath10k *ar)
763{
764 int ret;
765
766 lockdep_assert_held(&ar->conf_mutex);
767
768 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
769
770 ret = ath10k_monitor_create(ar);
771 if (ret) {
772 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
773 return ret;
774 }
775
776 ret = ath10k_monitor_start(ar, ar->monitor_vdev_id);
777 if (ret) {
778 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
779 ath10k_monitor_destroy(ar);
780 return ret;
781 }
782
783 ath10k_dbg(ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
784 ar->monitor_vdev_id);
785
786 return 0;
787}
788
789static int ath10k_stop_cac(struct ath10k *ar)
790{
791 lockdep_assert_held(&ar->conf_mutex);
792
793 /* CAC is not running - do nothing */
794 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
795 return 0;
796
797 ath10k_monitor_stop(ar);
798 ath10k_monitor_destroy(ar);
799 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
800
801 ath10k_dbg(ATH10K_DBG_MAC, "mac cac finished\n");
802
803 return 0;
804}
805
806static const char *ath10k_dfs_state(enum nl80211_dfs_state dfs_state)
807{
808 switch (dfs_state) {
809 case NL80211_DFS_USABLE:
810 return "USABLE";
811 case NL80211_DFS_UNAVAILABLE:
812 return "UNAVAILABLE";
813 case NL80211_DFS_AVAILABLE:
814 return "AVAILABLE";
815 default:
816 WARN_ON(1);
817 return "bug";
818 }
819}
820
821static void ath10k_config_radar_detection(struct ath10k *ar)
822{
823 struct ieee80211_channel *chan = ar->hw->conf.chandef.chan;
824 bool radar = ar->hw->conf.radar_enabled;
825 bool chan_radar = !!(chan->flags & IEEE80211_CHAN_RADAR);
826 enum nl80211_dfs_state dfs_state = chan->dfs_state;
827 int ret;
828
829 lockdep_assert_held(&ar->conf_mutex);
830
831 ath10k_dbg(ATH10K_DBG_MAC,
832 "mac radar config update: chan %dMHz radar %d chan radar %d chan state %s\n",
833 chan->center_freq, radar, chan_radar,
834 ath10k_dfs_state(dfs_state));
835
836 /*
837 * It's safe to call it even if CAC is not started.
838 * This call here guarantees changing channel, etc. will stop CAC.
839 */
840 ath10k_stop_cac(ar);
841
842 if (!radar)
843 return;
844
845 if (!chan_radar)
846 return;
847
848 if (dfs_state != NL80211_DFS_USABLE)
849 return;
850
851 ret = ath10k_start_cac(ar);
852 if (ret) {
853 /*
854 * Not possible to start CAC on current channel so starting
855 * radiation is not allowed, make this channel DFS_UNAVAILABLE
856 * by indicating that radar was detected.
857 */
858 ath10k_warn("failed to start CAC (%d)\n", ret);
859 ieee80211_radar_detected(ar->hw);
860 }
861}
862
5e3dd157
KV
863static void ath10k_control_beaconing(struct ath10k_vif *arvif,
864 struct ieee80211_bss_conf *info)
865{
866 int ret = 0;
867
548db54c
MK
868 lockdep_assert_held(&arvif->ar->conf_mutex);
869
5e3dd157
KV
870 if (!info->enable_beacon) {
871 ath10k_vdev_stop(arvif);
c930f744
MK
872
873 arvif->is_started = false;
874 arvif->is_up = false;
875
748afc47
MK
876 spin_lock_bh(&arvif->ar->data_lock);
877 if (arvif->beacon) {
767d34fc
MK
878 dma_unmap_single(arvif->ar->dev,
879 ATH10K_SKB_CB(arvif->beacon)->paddr,
880 arvif->beacon->len, DMA_TO_DEVICE);
748afc47
MK
881 dev_kfree_skb_any(arvif->beacon);
882
883 arvif->beacon = NULL;
884 arvif->beacon_sent = false;
885 }
886 spin_unlock_bh(&arvif->ar->data_lock);
887
5e3dd157
KV
888 return;
889 }
890
891 arvif->tx_seq_no = 0x1000;
892
893 ret = ath10k_vdev_start(arvif);
894 if (ret)
895 return;
896
c930f744
MK
897 arvif->aid = 0;
898 memcpy(arvif->bssid, info->bssid, ETH_ALEN);
899
900 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
901 arvif->bssid);
5e3dd157 902 if (ret) {
69244e56
BG
903 ath10k_warn("Failed to bring up vdev %d: %i\n",
904 arvif->vdev_id, ret);
c930f744 905 ath10k_vdev_stop(arvif);
5e3dd157
KV
906 return;
907 }
c930f744
MK
908
909 arvif->is_started = true;
910 arvif->is_up = true;
911
60c3daa8 912 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
5e3dd157
KV
913}
914
915static void ath10k_control_ibss(struct ath10k_vif *arvif,
916 struct ieee80211_bss_conf *info,
917 const u8 self_peer[ETH_ALEN])
918{
6d1506e7 919 u32 vdev_param;
5e3dd157
KV
920 int ret = 0;
921
548db54c
MK
922 lockdep_assert_held(&arvif->ar->conf_mutex);
923
5e3dd157
KV
924 if (!info->ibss_joined) {
925 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
926 if (ret)
927 ath10k_warn("Failed to delete IBSS self peer:%pM for VDEV:%d ret:%d\n",
928 self_peer, arvif->vdev_id, ret);
929
c930f744 930 if (is_zero_ether_addr(arvif->bssid))
5e3dd157
KV
931 return;
932
933 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id,
c930f744 934 arvif->bssid);
5e3dd157
KV
935 if (ret) {
936 ath10k_warn("Failed to delete IBSS BSSID peer:%pM for VDEV:%d ret:%d\n",
c930f744 937 arvif->bssid, arvif->vdev_id, ret);
5e3dd157
KV
938 return;
939 }
940
c930f744 941 memset(arvif->bssid, 0, ETH_ALEN);
5e3dd157
KV
942
943 return;
944 }
945
946 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
947 if (ret) {
948 ath10k_warn("Failed to create IBSS self peer:%pM for VDEV:%d ret:%d\n",
949 self_peer, arvif->vdev_id, ret);
950 return;
951 }
952
6d1506e7
BM
953 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
954 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
5e3dd157
KV
955 ATH10K_DEFAULT_ATIM);
956 if (ret)
957 ath10k_warn("Failed to set IBSS ATIM for VDEV:%d ret:%d\n",
958 arvif->vdev_id, ret);
959}
960
961/*
962 * Review this when mac80211 gains per-interface powersave support.
963 */
ad088bfa 964static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
5e3dd157 965{
ad088bfa
MK
966 struct ath10k *ar = arvif->ar;
967 struct ieee80211_conf *conf = &ar->hw->conf;
5e3dd157
KV
968 enum wmi_sta_powersave_param param;
969 enum wmi_sta_ps_mode psmode;
970 int ret;
971
548db54c
MK
972 lockdep_assert_held(&arvif->ar->conf_mutex);
973
ad088bfa
MK
974 if (arvif->vif->type != NL80211_IFTYPE_STATION)
975 return 0;
5e3dd157
KV
976
977 if (conf->flags & IEEE80211_CONF_PS) {
978 psmode = WMI_STA_PS_MODE_ENABLED;
979 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
980
ad088bfa 981 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
5e3dd157
KV
982 conf->dynamic_ps_timeout);
983 if (ret) {
69244e56
BG
984 ath10k_warn("Failed to set inactivity time for vdev %d: %i\n",
985 arvif->vdev_id, ret);
ad088bfa 986 return ret;
5e3dd157 987 }
5e3dd157
KV
988 } else {
989 psmode = WMI_STA_PS_MODE_DISABLED;
990 }
991
60c3daa8
KV
992 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
993 arvif->vdev_id, psmode ? "enable" : "disable");
994
ad088bfa
MK
995 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
996 if (ret) {
5e3dd157
KV
997 ath10k_warn("Failed to set PS Mode: %d for VDEV: %d\n",
998 psmode, arvif->vdev_id);
ad088bfa
MK
999 return ret;
1000 }
1001
1002 return 0;
5e3dd157
KV
1003}
1004
1005/**********************/
1006/* Station management */
1007/**********************/
1008
1009static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
1010 struct ath10k_vif *arvif,
1011 struct ieee80211_sta *sta,
1012 struct ieee80211_bss_conf *bss_conf,
1013 struct wmi_peer_assoc_complete_arg *arg)
1014{
548db54c
MK
1015 lockdep_assert_held(&ar->conf_mutex);
1016
5e3dd157
KV
1017 memcpy(arg->addr, sta->addr, ETH_ALEN);
1018 arg->vdev_id = arvif->vdev_id;
1019 arg->peer_aid = sta->aid;
1020 arg->peer_flags |= WMI_PEER_AUTH;
1021
1022 if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
1023 /*
1024 * Seems FW have problems with Power Save in STA
1025 * mode when we setup this parameter to high (eg. 5).
1026 * Often we see that FW don't send NULL (with clean P flags)
1027 * frame even there is info about buffered frames in beacons.
1028 * Sometimes we have to wait more than 10 seconds before FW
1029 * will wakeup. Often sending one ping from AP to our device
1030 * just fail (more than 50%).
1031 *
1032 * Seems setting this FW parameter to 1 couse FW
1033 * will check every beacon and will wakup immediately
1034 * after detection buffered data.
1035 */
1036 arg->peer_listen_intval = 1;
1037 else
1038 arg->peer_listen_intval = ar->hw->conf.listen_interval;
1039
1040 arg->peer_num_spatial_streams = 1;
1041
1042 /*
1043 * The assoc capabilities are available only in managed mode.
1044 */
1045 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && bss_conf)
1046 arg->peer_caps = bss_conf->assoc_capability;
1047}
1048
1049static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
1050 struct ath10k_vif *arvif,
1051 struct wmi_peer_assoc_complete_arg *arg)
1052{
1053 struct ieee80211_vif *vif = arvif->vif;
1054 struct ieee80211_bss_conf *info = &vif->bss_conf;
1055 struct cfg80211_bss *bss;
1056 const u8 *rsnie = NULL;
1057 const u8 *wpaie = NULL;
1058
548db54c
MK
1059 lockdep_assert_held(&ar->conf_mutex);
1060
5e3dd157
KV
1061 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
1062 info->bssid, NULL, 0, 0, 0);
1063 if (bss) {
1064 const struct cfg80211_bss_ies *ies;
1065
1066 rcu_read_lock();
1067 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1068
1069 ies = rcu_dereference(bss->ies);
1070
1071 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
1072 WLAN_OUI_TYPE_MICROSOFT_WPA,
1073 ies->data,
1074 ies->len);
1075 rcu_read_unlock();
1076 cfg80211_put_bss(ar->hw->wiphy, bss);
1077 }
1078
1079 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1080 if (rsnie || wpaie) {
1081 ath10k_dbg(ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
1082 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1083 }
1084
1085 if (wpaie) {
1086 ath10k_dbg(ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
1087 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1088 }
1089}
1090
1091static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
1092 struct ieee80211_sta *sta,
1093 struct wmi_peer_assoc_complete_arg *arg)
1094{
1095 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1096 const struct ieee80211_supported_band *sband;
1097 const struct ieee80211_rate *rates;
1098 u32 ratemask;
1099 int i;
1100
548db54c
MK
1101 lockdep_assert_held(&ar->conf_mutex);
1102
5e3dd157
KV
1103 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
1104 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
1105 rates = sband->bitrates;
1106
1107 rateset->num_rates = 0;
1108
1109 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1110 if (!(ratemask & 1))
1111 continue;
1112
1113 rateset->rates[rateset->num_rates] = rates->hw_value;
1114 rateset->num_rates++;
1115 }
1116}
1117
1118static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1119 struct ieee80211_sta *sta,
1120 struct wmi_peer_assoc_complete_arg *arg)
1121{
1122 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
5e3dd157
KV
1123 int i, n;
1124
548db54c
MK
1125 lockdep_assert_held(&ar->conf_mutex);
1126
5e3dd157
KV
1127 if (!ht_cap->ht_supported)
1128 return;
1129
1130 arg->peer_flags |= WMI_PEER_HT;
1131 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1132 ht_cap->ampdu_factor)) - 1;
1133
1134 arg->peer_mpdu_density =
1135 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1136
1137 arg->peer_ht_caps = ht_cap->cap;
1138 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1139
1140 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1141 arg->peer_flags |= WMI_PEER_LDPC;
1142
1143 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1144 arg->peer_flags |= WMI_PEER_40MHZ;
1145 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1146 }
1147
1148 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1149 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1150
1151 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1152 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1153
1154 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1155 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1156 arg->peer_flags |= WMI_PEER_STBC;
1157 }
1158
1159 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
1160 u32 stbc;
1161 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1162 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1163 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1164 arg->peer_rate_caps |= stbc;
1165 arg->peer_flags |= WMI_PEER_STBC;
1166 }
1167
5e3dd157
KV
1168 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1169 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
1170 else if (ht_cap->mcs.rx_mask[1])
1171 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
1172
1173 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
1174 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
1175 arg->peer_ht_rates.rates[n++] = i;
1176
fd71f807
BM
1177 /*
1178 * This is a workaround for HT-enabled STAs which break the spec
1179 * and have no HT capabilities RX mask (no HT RX MCS map).
1180 *
1181 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1182 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1183 *
1184 * Firmware asserts if such situation occurs.
1185 */
1186 if (n == 0) {
1187 arg->peer_ht_rates.num_rates = 8;
1188 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1189 arg->peer_ht_rates.rates[i] = i;
1190 } else {
1191 arg->peer_ht_rates.num_rates = n;
1192 arg->peer_num_spatial_streams = sta->rx_nss;
1193 }
5e3dd157 1194
60c3daa8
KV
1195 ath10k_dbg(ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
1196 arg->addr,
5e3dd157
KV
1197 arg->peer_ht_rates.num_rates,
1198 arg->peer_num_spatial_streams);
1199}
1200
d3d3ff42
JD
1201static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1202 struct ath10k_vif *arvif,
1203 struct ieee80211_sta *sta)
5e3dd157
KV
1204{
1205 u32 uapsd = 0;
1206 u32 max_sp = 0;
d3d3ff42 1207 int ret = 0;
5e3dd157 1208
548db54c
MK
1209 lockdep_assert_held(&ar->conf_mutex);
1210
5e3dd157 1211 if (sta->wme && sta->uapsd_queues) {
60c3daa8 1212 ath10k_dbg(ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
5e3dd157
KV
1213 sta->uapsd_queues, sta->max_sp);
1214
5e3dd157
KV
1215 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1216 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1217 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1218 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1219 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1220 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1221 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1222 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1223 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1224 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1225 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1226 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1227
1228
1229 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1230 max_sp = sta->max_sp;
1231
d3d3ff42
JD
1232 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1233 sta->addr,
1234 WMI_AP_PS_PEER_PARAM_UAPSD,
1235 uapsd);
1236 if (ret) {
69244e56
BG
1237 ath10k_warn("failed to set ap ps peer param uapsd for vdev %i: %d\n",
1238 arvif->vdev_id, ret);
d3d3ff42
JD
1239 return ret;
1240 }
5e3dd157 1241
d3d3ff42
JD
1242 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1243 sta->addr,
1244 WMI_AP_PS_PEER_PARAM_MAX_SP,
1245 max_sp);
1246 if (ret) {
69244e56
BG
1247 ath10k_warn("failed to set ap ps peer param max sp for vdev %i: %d\n",
1248 arvif->vdev_id, ret);
d3d3ff42
JD
1249 return ret;
1250 }
5e3dd157
KV
1251
1252 /* TODO setup this based on STA listen interval and
1253 beacon interval. Currently we don't know
1254 sta->listen_interval - mac80211 patch required.
1255 Currently use 10 seconds */
d3d3ff42
JD
1256 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
1257 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME, 10);
1258 if (ret) {
69244e56
BG
1259 ath10k_warn("failed to set ap ps peer param ageout time for vdev %i: %d\n",
1260 arvif->vdev_id, ret);
d3d3ff42
JD
1261 return ret;
1262 }
5e3dd157 1263 }
5e3dd157 1264
d3d3ff42 1265 return 0;
5e3dd157
KV
1266}
1267
1268static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1269 struct ieee80211_sta *sta,
1270 struct wmi_peer_assoc_complete_arg *arg)
1271{
1272 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
a24b88b5 1273 u8 ampdu_factor;
5e3dd157
KV
1274
1275 if (!vht_cap->vht_supported)
1276 return;
1277
1278 arg->peer_flags |= WMI_PEER_VHT;
5e3dd157
KV
1279 arg->peer_vht_caps = vht_cap->cap;
1280
a24b88b5
SM
1281
1282 ampdu_factor = (vht_cap->cap &
1283 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1284 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1285
1286 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1287 * zero in VHT IE. Using it would result in degraded throughput.
1288 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1289 * it if VHT max_mpdu is smaller. */
1290 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1291 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1292 ampdu_factor)) - 1);
1293
5e3dd157
KV
1294 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1295 arg->peer_flags |= WMI_PEER_80MHZ;
1296
1297 arg->peer_vht_rates.rx_max_rate =
1298 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1299 arg->peer_vht_rates.rx_mcs_set =
1300 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1301 arg->peer_vht_rates.tx_max_rate =
1302 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1303 arg->peer_vht_rates.tx_mcs_set =
1304 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1305
60c3daa8
KV
1306 ath10k_dbg(ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
1307 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
5e3dd157
KV
1308}
1309
1310static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
1311 struct ath10k_vif *arvif,
1312 struct ieee80211_sta *sta,
1313 struct ieee80211_bss_conf *bss_conf,
1314 struct wmi_peer_assoc_complete_arg *arg)
1315{
1316 switch (arvif->vdev_type) {
1317 case WMI_VDEV_TYPE_AP:
d3d3ff42
JD
1318 if (sta->wme)
1319 arg->peer_flags |= WMI_PEER_QOS;
1320
1321 if (sta->wme && sta->uapsd_queues) {
1322 arg->peer_flags |= WMI_PEER_APSD;
1323 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1324 }
5e3dd157
KV
1325 break;
1326 case WMI_VDEV_TYPE_STA:
d3d3ff42
JD
1327 if (bss_conf->qos)
1328 arg->peer_flags |= WMI_PEER_QOS;
5e3dd157
KV
1329 break;
1330 default:
1331 break;
1332 }
1333}
1334
1335static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
1336 struct ath10k_vif *arvif,
1337 struct ieee80211_sta *sta,
1338 struct wmi_peer_assoc_complete_arg *arg)
1339{
1340 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1341
5e3dd157
KV
1342 switch (ar->hw->conf.chandef.chan->band) {
1343 case IEEE80211_BAND_2GHZ:
1344 if (sta->ht_cap.ht_supported) {
1345 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1346 phymode = MODE_11NG_HT40;
1347 else
1348 phymode = MODE_11NG_HT20;
1349 } else {
1350 phymode = MODE_11G;
1351 }
1352
1353 break;
1354 case IEEE80211_BAND_5GHZ:
7cc45e98
SM
1355 /*
1356 * Check VHT first.
1357 */
1358 if (sta->vht_cap.vht_supported) {
1359 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1360 phymode = MODE_11AC_VHT80;
1361 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1362 phymode = MODE_11AC_VHT40;
1363 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1364 phymode = MODE_11AC_VHT20;
1365 } else if (sta->ht_cap.ht_supported) {
5e3dd157
KV
1366 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1367 phymode = MODE_11NA_HT40;
1368 else
1369 phymode = MODE_11NA_HT20;
1370 } else {
1371 phymode = MODE_11A;
1372 }
1373
1374 break;
1375 default:
1376 break;
1377 }
1378
38a1d47e
KV
1379 ath10k_dbg(ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
1380 sta->addr, ath10k_wmi_phymode_str(phymode));
60c3daa8 1381
5e3dd157
KV
1382 arg->peer_phymode = phymode;
1383 WARN_ON(phymode == MODE_UNKNOWN);
1384}
1385
b9ada65d
KV
1386static int ath10k_peer_assoc_prepare(struct ath10k *ar,
1387 struct ath10k_vif *arvif,
1388 struct ieee80211_sta *sta,
1389 struct ieee80211_bss_conf *bss_conf,
1390 struct wmi_peer_assoc_complete_arg *arg)
5e3dd157 1391{
548db54c
MK
1392 lockdep_assert_held(&ar->conf_mutex);
1393
b9ada65d 1394 memset(arg, 0, sizeof(*arg));
5e3dd157 1395
b9ada65d
KV
1396 ath10k_peer_assoc_h_basic(ar, arvif, sta, bss_conf, arg);
1397 ath10k_peer_assoc_h_crypto(ar, arvif, arg);
1398 ath10k_peer_assoc_h_rates(ar, sta, arg);
1399 ath10k_peer_assoc_h_ht(ar, sta, arg);
1400 ath10k_peer_assoc_h_vht(ar, sta, arg);
1401 ath10k_peer_assoc_h_qos(ar, arvif, sta, bss_conf, arg);
1402 ath10k_peer_assoc_h_phymode(ar, arvif, sta, arg);
5e3dd157 1403
b9ada65d 1404 return 0;
5e3dd157
KV
1405}
1406
90046f50
MK
1407static const u32 ath10k_smps_map[] = {
1408 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
1409 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
1410 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
1411 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
1412};
1413
1414static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
1415 const u8 *addr,
1416 const struct ieee80211_sta_ht_cap *ht_cap)
1417{
1418 int smps;
1419
1420 if (!ht_cap->ht_supported)
1421 return 0;
1422
1423 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1424 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1425
1426 if (smps >= ARRAY_SIZE(ath10k_smps_map))
1427 return -EINVAL;
1428
1429 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
1430 WMI_PEER_SMPS_STATE,
1431 ath10k_smps_map[smps]);
1432}
1433
5e3dd157
KV
1434/* can be called only in mac80211 callbacks due to `key_count` usage */
1435static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1436 struct ieee80211_vif *vif,
1437 struct ieee80211_bss_conf *bss_conf)
1438{
1439 struct ath10k *ar = hw->priv;
1440 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
90046f50 1441 struct ieee80211_sta_ht_cap ht_cap;
b9ada65d 1442 struct wmi_peer_assoc_complete_arg peer_arg;
5e3dd157
KV
1443 struct ieee80211_sta *ap_sta;
1444 int ret;
1445
548db54c
MK
1446 lockdep_assert_held(&ar->conf_mutex);
1447
5e3dd157
KV
1448 rcu_read_lock();
1449
1450 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1451 if (!ap_sta) {
69244e56
BG
1452 ath10k_warn("Failed to find station entry for %pM, vdev %i\n",
1453 bss_conf->bssid, arvif->vdev_id);
5e3dd157
KV
1454 rcu_read_unlock();
1455 return;
1456 }
1457
90046f50
MK
1458 /* ap_sta must be accessed only within rcu section which must be left
1459 * before calling ath10k_setup_peer_smps() which might sleep. */
1460 ht_cap = ap_sta->ht_cap;
1461
b9ada65d
KV
1462 ret = ath10k_peer_assoc_prepare(ar, arvif, ap_sta,
1463 bss_conf, &peer_arg);
5e3dd157 1464 if (ret) {
69244e56
BG
1465 ath10k_warn("Peer assoc prepare failed for %pM vdev %i\n: %d",
1466 bss_conf->bssid, arvif->vdev_id, ret);
5e3dd157
KV
1467 rcu_read_unlock();
1468 return;
1469 }
1470
1471 rcu_read_unlock();
1472
b9ada65d
KV
1473 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1474 if (ret) {
69244e56
BG
1475 ath10k_warn("Peer assoc failed for %pM vdev %i\n: %d",
1476 bss_conf->bssid, arvif->vdev_id, ret);
b9ada65d
KV
1477 return;
1478 }
1479
90046f50
MK
1480 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
1481 if (ret) {
69244e56
BG
1482 ath10k_warn("failed to setup peer SMPS for vdev %i: %d\n",
1483 arvif->vdev_id, ret);
90046f50
MK
1484 return;
1485 }
1486
60c3daa8
KV
1487 ath10k_dbg(ATH10K_DBG_MAC,
1488 "mac vdev %d up (associated) bssid %pM aid %d\n",
1489 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1490
c930f744
MK
1491 arvif->aid = bss_conf->aid;
1492 memcpy(arvif->bssid, bss_conf->bssid, ETH_ALEN);
1493
1494 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
1495 if (ret) {
5e3dd157
KV
1496 ath10k_warn("VDEV: %d up failed: ret %d\n",
1497 arvif->vdev_id, ret);
c930f744
MK
1498 return;
1499 }
1500
1501 arvif->is_up = true;
5e3dd157
KV
1502}
1503
1504/*
1505 * FIXME: flush TIDs
1506 */
1507static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1508 struct ieee80211_vif *vif)
1509{
1510 struct ath10k *ar = hw->priv;
1511 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1512 int ret;
1513
548db54c
MK
1514 lockdep_assert_held(&ar->conf_mutex);
1515
5e3dd157
KV
1516 /*
1517 * For some reason, calling VDEV-DOWN before VDEV-STOP
1518 * makes the FW to send frames via HTT after disassociation.
1519 * No idea why this happens, even though VDEV-DOWN is supposed
1520 * to be analogous to link down, so just stop the VDEV.
1521 */
60c3daa8
KV
1522 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d stop (disassociated\n",
1523 arvif->vdev_id);
1524
1525 /* FIXME: check return value */
5e3dd157 1526 ret = ath10k_vdev_stop(arvif);
5e3dd157
KV
1527
1528 /*
1529 * If we don't call VDEV-DOWN after VDEV-STOP FW will remain active and
1530 * report beacons from previously associated network through HTT.
1531 * This in turn would spam mac80211 WARN_ON if we bring down all
1532 * interfaces as it expects there is no rx when no interface is
1533 * running.
1534 */
60c3daa8
KV
1535 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d down\n", arvif->vdev_id);
1536
1537 /* FIXME: why don't we print error if wmi call fails? */
5e3dd157 1538 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
5e3dd157 1539
cc4827b9 1540 arvif->def_wep_key_idx = 0;
c930f744
MK
1541
1542 arvif->is_started = false;
1543 arvif->is_up = false;
5e3dd157
KV
1544}
1545
1546static int ath10k_station_assoc(struct ath10k *ar, struct ath10k_vif *arvif,
44d6fa90 1547 struct ieee80211_sta *sta, bool reassoc)
5e3dd157 1548{
b9ada65d 1549 struct wmi_peer_assoc_complete_arg peer_arg;
5e3dd157
KV
1550 int ret = 0;
1551
548db54c
MK
1552 lockdep_assert_held(&ar->conf_mutex);
1553
b9ada65d
KV
1554 ret = ath10k_peer_assoc_prepare(ar, arvif, sta, NULL, &peer_arg);
1555 if (ret) {
69244e56
BG
1556 ath10k_warn("WMI peer assoc prepare failed for %pM vdev %i: %i\n",
1557 sta->addr, arvif->vdev_id, ret);
b9ada65d
KV
1558 return ret;
1559 }
1560
44d6fa90 1561 peer_arg.peer_reassoc = reassoc;
b9ada65d 1562 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
5e3dd157 1563 if (ret) {
69244e56
BG
1564 ath10k_warn("Peer assoc failed for STA %pM vdev %i: %d\n",
1565 sta->addr, arvif->vdev_id, ret);
5e3dd157
KV
1566 return ret;
1567 }
1568
90046f50
MK
1569 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr, &sta->ht_cap);
1570 if (ret) {
69244e56 1571 ath10k_warn("failed to setup peer SMPS for vdev: %d\n", ret);
90046f50
MK
1572 return ret;
1573 }
1574
e81bd104
MK
1575 if (!sta->wme) {
1576 arvif->num_legacy_stations++;
1577 ret = ath10k_recalc_rtscts_prot(arvif);
1578 if (ret) {
1579 ath10k_warn("failed to recalculate rts/cts prot for vdev %d: %d\n",
1580 arvif->vdev_id, ret);
1581 return ret;
1582 }
1583 }
1584
5e3dd157
KV
1585 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1586 if (ret) {
69244e56
BG
1587 ath10k_warn("could not install peer wep keys for vdev %i: %d\n",
1588 arvif->vdev_id, ret);
5e3dd157
KV
1589 return ret;
1590 }
1591
d3d3ff42
JD
1592 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
1593 if (ret) {
69244e56
BG
1594 ath10k_warn("could not set qos params for STA %pM for vdev %i: %d\n",
1595 sta->addr, arvif->vdev_id, ret);
d3d3ff42
JD
1596 return ret;
1597 }
1598
5e3dd157
KV
1599 return ret;
1600}
1601
1602static int ath10k_station_disassoc(struct ath10k *ar, struct ath10k_vif *arvif,
1603 struct ieee80211_sta *sta)
1604{
1605 int ret = 0;
1606
548db54c
MK
1607 lockdep_assert_held(&ar->conf_mutex);
1608
e81bd104
MK
1609 if (!sta->wme) {
1610 arvif->num_legacy_stations--;
1611 ret = ath10k_recalc_rtscts_prot(arvif);
1612 if (ret) {
1613 ath10k_warn("failed to recalculate rts/cts prot for vdev %d: %d\n",
1614 arvif->vdev_id, ret);
1615 return ret;
1616 }
1617 }
1618
5e3dd157
KV
1619 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1620 if (ret) {
69244e56
BG
1621 ath10k_warn("could not clear all peer wep keys for vdev %i: %d\n",
1622 arvif->vdev_id, ret);
5e3dd157
KV
1623 return ret;
1624 }
1625
1626 return ret;
1627}
1628
1629/**************/
1630/* Regulatory */
1631/**************/
1632
1633static int ath10k_update_channel_list(struct ath10k *ar)
1634{
1635 struct ieee80211_hw *hw = ar->hw;
1636 struct ieee80211_supported_band **bands;
1637 enum ieee80211_band band;
1638 struct ieee80211_channel *channel;
1639 struct wmi_scan_chan_list_arg arg = {0};
1640 struct wmi_channel_arg *ch;
1641 bool passive;
1642 int len;
1643 int ret;
1644 int i;
1645
548db54c
MK
1646 lockdep_assert_held(&ar->conf_mutex);
1647
5e3dd157
KV
1648 bands = hw->wiphy->bands;
1649 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1650 if (!bands[band])
1651 continue;
1652
1653 for (i = 0; i < bands[band]->n_channels; i++) {
1654 if (bands[band]->channels[i].flags &
1655 IEEE80211_CHAN_DISABLED)
1656 continue;
1657
1658 arg.n_channels++;
1659 }
1660 }
1661
1662 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
1663 arg.channels = kzalloc(len, GFP_KERNEL);
1664 if (!arg.channels)
1665 return -ENOMEM;
1666
1667 ch = arg.channels;
1668 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1669 if (!bands[band])
1670 continue;
1671
1672 for (i = 0; i < bands[band]->n_channels; i++) {
1673 channel = &bands[band]->channels[i];
1674
1675 if (channel->flags & IEEE80211_CHAN_DISABLED)
1676 continue;
1677
1678 ch->allow_ht = true;
1679
1680 /* FIXME: when should we really allow VHT? */
1681 ch->allow_vht = true;
1682
1683 ch->allow_ibss =
8fe02e16 1684 !(channel->flags & IEEE80211_CHAN_NO_IR);
5e3dd157
KV
1685
1686 ch->ht40plus =
1687 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
1688
e8a50f8b
MP
1689 ch->chan_radar =
1690 !!(channel->flags & IEEE80211_CHAN_RADAR);
1691
8fe02e16 1692 passive = channel->flags & IEEE80211_CHAN_NO_IR;
5e3dd157
KV
1693 ch->passive = passive;
1694
1695 ch->freq = channel->center_freq;
89c5c843 1696 ch->min_power = 0;
02256930
MK
1697 ch->max_power = channel->max_power * 2;
1698 ch->max_reg_power = channel->max_reg_power * 2;
1699 ch->max_antenna_gain = channel->max_antenna_gain * 2;
5e3dd157
KV
1700 ch->reg_class_id = 0; /* FIXME */
1701
1702 /* FIXME: why use only legacy modes, why not any
1703 * HT/VHT modes? Would that even make any
1704 * difference? */
1705 if (channel->band == IEEE80211_BAND_2GHZ)
1706 ch->mode = MODE_11G;
1707 else
1708 ch->mode = MODE_11A;
1709
1710 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
1711 continue;
1712
1713 ath10k_dbg(ATH10K_DBG_WMI,
60c3daa8
KV
1714 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1715 ch - arg.channels, arg.n_channels,
5e3dd157
KV
1716 ch->freq, ch->max_power, ch->max_reg_power,
1717 ch->max_antenna_gain, ch->mode);
1718
1719 ch++;
1720 }
1721 }
1722
1723 ret = ath10k_wmi_scan_chan_list(ar, &arg);
1724 kfree(arg.channels);
1725
1726 return ret;
1727}
1728
f7843d7f 1729static void ath10k_regd_update(struct ath10k *ar)
5e3dd157 1730{
5e3dd157 1731 struct reg_dmn_pair_mapping *regpair;
5e3dd157
KV
1732 int ret;
1733
f7843d7f 1734 lockdep_assert_held(&ar->conf_mutex);
5e3dd157
KV
1735
1736 ret = ath10k_update_channel_list(ar);
1737 if (ret)
1738 ath10k_warn("could not update channel list (%d)\n", ret);
1739
1740 regpair = ar->ath_common.regulatory.regpair;
f7843d7f 1741
5e3dd157
KV
1742 /* Target allows setting up per-band regdomain but ath_common provides
1743 * a combined one only */
1744 ret = ath10k_wmi_pdev_set_regdomain(ar,
ef8c0017
KV
1745 regpair->reg_domain,
1746 regpair->reg_domain, /* 2ghz */
1747 regpair->reg_domain, /* 5ghz */
5e3dd157
KV
1748 regpair->reg_2ghz_ctl,
1749 regpair->reg_5ghz_ctl);
1750 if (ret)
1751 ath10k_warn("could not set pdev regdomain (%d)\n", ret);
f7843d7f 1752}
548db54c 1753
f7843d7f
MK
1754static void ath10k_reg_notifier(struct wiphy *wiphy,
1755 struct regulatory_request *request)
1756{
1757 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1758 struct ath10k *ar = hw->priv;
9702c686 1759 bool result;
f7843d7f
MK
1760
1761 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
1762
9702c686
JD
1763 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
1764 ath10k_dbg(ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
1765 request->dfs_region);
1766 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
1767 request->dfs_region);
1768 if (!result)
1769 ath10k_warn("dfs region 0x%X not supported, will trigger radar for every pulse\n",
1770 request->dfs_region);
1771 }
1772
f7843d7f
MK
1773 mutex_lock(&ar->conf_mutex);
1774 if (ar->state == ATH10K_STATE_ON)
1775 ath10k_regd_update(ar);
548db54c 1776 mutex_unlock(&ar->conf_mutex);
5e3dd157
KV
1777}
1778
1779/***************/
1780/* TX handlers */
1781/***************/
1782
42c3aa6f
MK
1783static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
1784{
1785 if (ieee80211_is_mgmt(hdr->frame_control))
1786 return HTT_DATA_TX_EXT_TID_MGMT;
1787
1788 if (!ieee80211_is_data_qos(hdr->frame_control))
1789 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1790
1791 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
1792 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1793
1794 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
1795}
1796
ddb6ad77
MK
1797static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar,
1798 struct ieee80211_tx_info *info)
1799{
1800 if (info->control.vif)
1801 return ath10k_vif_to_arvif(info->control.vif)->vdev_id;
1802
1803 if (ar->monitor_enabled)
1804 return ar->monitor_vdev_id;
1805
1806 ath10k_warn("could not resolve vdev id\n");
1807 return 0;
1808}
1809
5e3dd157
KV
1810/*
1811 * Frames sent to the FW have to be in "Native Wifi" format.
1812 * Strip the QoS field from the 802.11 header.
1813 */
1814static void ath10k_tx_h_qos_workaround(struct ieee80211_hw *hw,
1815 struct ieee80211_tx_control *control,
1816 struct sk_buff *skb)
1817{
1818 struct ieee80211_hdr *hdr = (void *)skb->data;
1819 u8 *qos_ctl;
1820
1821 if (!ieee80211_is_data_qos(hdr->frame_control))
1822 return;
1823
1824 qos_ctl = ieee80211_get_qos_ctl(hdr);
ba0ccd7a
MK
1825 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
1826 skb->data, (void *)qos_ctl - (void *)skb->data);
1827 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
5e3dd157
KV
1828}
1829
cc4827b9
MK
1830static void ath10k_tx_wep_key_work(struct work_struct *work)
1831{
1832 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1833 wep_key_work);
1834 int ret, keyidx = arvif->def_wep_key_newidx;
1835
1836 if (arvif->def_wep_key_idx == keyidx)
1837 return;
1838
1839 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
1840 arvif->vdev_id, keyidx);
1841
1842 ret = ath10k_wmi_vdev_set_param(arvif->ar,
1843 arvif->vdev_id,
1844 arvif->ar->wmi.vdev_param->def_keyid,
1845 keyidx);
1846 if (ret) {
1847 ath10k_warn("could not update wep keyidx (%d)\n", ret);
1848 return;
1849 }
1850
1851 arvif->def_wep_key_idx = keyidx;
1852}
1853
5e3dd157
KV
1854static void ath10k_tx_h_update_wep_key(struct sk_buff *skb)
1855{
1856 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1857 struct ieee80211_vif *vif = info->control.vif;
1858 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1859 struct ath10k *ar = arvif->ar;
1860 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1861 struct ieee80211_key_conf *key = info->control.hw_key;
5e3dd157 1862
5e3dd157
KV
1863 if (!ieee80211_has_protected(hdr->frame_control))
1864 return;
1865
1866 if (!key)
1867 return;
1868
1869 if (key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
1870 key->cipher != WLAN_CIPHER_SUITE_WEP104)
1871 return;
1872
cc4827b9 1873 if (key->keyidx == arvif->def_wep_key_idx)
5e3dd157 1874 return;
5e3dd157 1875
cc4827b9
MK
1876 /* FIXME: Most likely a few frames will be TXed with an old key. Simply
1877 * queueing frames until key index is updated is not an option because
1878 * sk_buff may need more processing to be done, e.g. offchannel */
1879 arvif->def_wep_key_newidx = key->keyidx;
1880 ieee80211_queue_work(ar->hw, &arvif->wep_key_work);
5e3dd157
KV
1881}
1882
1883static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar, struct sk_buff *skb)
1884{
1885 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1886 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1887 struct ieee80211_vif *vif = info->control.vif;
1888 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1889
1890 /* This is case only for P2P_GO */
1891 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
1892 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1893 return;
1894
1895 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
1896 spin_lock_bh(&ar->data_lock);
1897 if (arvif->u.ap.noa_data)
1898 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
1899 GFP_ATOMIC))
1900 memcpy(skb_put(skb, arvif->u.ap.noa_len),
1901 arvif->u.ap.noa_data,
1902 arvif->u.ap.noa_len);
1903 spin_unlock_bh(&ar->data_lock);
1904 }
1905}
1906
1907static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
1908{
1909 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
5e00d31a 1910 int ret = 0;
5e3dd157 1911
961d4c38
MK
1912 if (ar->htt.target_version_major >= 3) {
1913 /* Since HTT 3.0 there is no separate mgmt tx command */
1914 ret = ath10k_htt_tx(&ar->htt, skb);
1915 goto exit;
1916 }
1917
5e00d31a
BM
1918 if (ieee80211_is_mgmt(hdr->frame_control)) {
1919 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
1920 ar->fw_features)) {
1921 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
1922 ATH10K_MAX_NUM_MGMT_PENDING) {
1923 ath10k_warn("wmi mgmt_tx queue limit reached\n");
1924 ret = -EBUSY;
1925 goto exit;
1926 }
1927
1928 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
1929 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
1930 } else {
1931 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
1932 }
1933 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
1934 ar->fw_features) &&
1935 ieee80211_is_nullfunc(hdr->frame_control)) {
5e3dd157
KV
1936 /* FW does not report tx status properly for NullFunc frames
1937 * unless they are sent through mgmt tx path. mac80211 sends
5e00d31a
BM
1938 * those frames when it detects link/beacon loss and depends
1939 * on the tx status to be correct. */
edb8236d 1940 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
5e00d31a 1941 } else {
edb8236d 1942 ret = ath10k_htt_tx(&ar->htt, skb);
5e00d31a 1943 }
5e3dd157 1944
961d4c38 1945exit:
5e3dd157
KV
1946 if (ret) {
1947 ath10k_warn("tx failed (%d). dropping packet.\n", ret);
1948 ieee80211_free_txskb(ar->hw, skb);
1949 }
1950}
1951
1952void ath10k_offchan_tx_purge(struct ath10k *ar)
1953{
1954 struct sk_buff *skb;
1955
1956 for (;;) {
1957 skb = skb_dequeue(&ar->offchan_tx_queue);
1958 if (!skb)
1959 break;
1960
1961 ieee80211_free_txskb(ar->hw, skb);
1962 }
1963}
1964
1965void ath10k_offchan_tx_work(struct work_struct *work)
1966{
1967 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
1968 struct ath10k_peer *peer;
1969 struct ieee80211_hdr *hdr;
1970 struct sk_buff *skb;
1971 const u8 *peer_addr;
1972 int vdev_id;
1973 int ret;
1974
1975 /* FW requirement: We must create a peer before FW will send out
1976 * an offchannel frame. Otherwise the frame will be stuck and
1977 * never transmitted. We delete the peer upon tx completion.
1978 * It is unlikely that a peer for offchannel tx will already be
1979 * present. However it may be in some rare cases so account for that.
1980 * Otherwise we might remove a legitimate peer and break stuff. */
1981
1982 for (;;) {
1983 skb = skb_dequeue(&ar->offchan_tx_queue);
1984 if (!skb)
1985 break;
1986
1987 mutex_lock(&ar->conf_mutex);
1988
60c3daa8 1989 ath10k_dbg(ATH10K_DBG_MAC, "mac offchannel skb %p\n",
5e3dd157
KV
1990 skb);
1991
1992 hdr = (struct ieee80211_hdr *)skb->data;
1993 peer_addr = ieee80211_get_DA(hdr);
5e00d31a 1994 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
5e3dd157
KV
1995
1996 spin_lock_bh(&ar->data_lock);
1997 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
1998 spin_unlock_bh(&ar->data_lock);
1999
2000 if (peer)
60c3daa8 2001 /* FIXME: should this use ath10k_warn()? */
5e3dd157
KV
2002 ath10k_dbg(ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
2003 peer_addr, vdev_id);
2004
2005 if (!peer) {
2006 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
2007 if (ret)
2008 ath10k_warn("peer %pM on vdev %d not created (%d)\n",
2009 peer_addr, vdev_id, ret);
2010 }
2011
2012 spin_lock_bh(&ar->data_lock);
16735d02 2013 reinit_completion(&ar->offchan_tx_completed);
5e3dd157
KV
2014 ar->offchan_tx_skb = skb;
2015 spin_unlock_bh(&ar->data_lock);
2016
2017 ath10k_tx_htt(ar, skb);
2018
2019 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
2020 3 * HZ);
2021 if (ret <= 0)
2022 ath10k_warn("timed out waiting for offchannel skb %p\n",
2023 skb);
2024
2025 if (!peer) {
2026 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
2027 if (ret)
2028 ath10k_warn("peer %pM on vdev %d not deleted (%d)\n",
2029 peer_addr, vdev_id, ret);
2030 }
2031
2032 mutex_unlock(&ar->conf_mutex);
2033 }
2034}
2035
5e00d31a
BM
2036void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
2037{
2038 struct sk_buff *skb;
2039
2040 for (;;) {
2041 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2042 if (!skb)
2043 break;
2044
2045 ieee80211_free_txskb(ar->hw, skb);
2046 }
2047}
2048
2049void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
2050{
2051 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
2052 struct sk_buff *skb;
2053 int ret;
2054
2055 for (;;) {
2056 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2057 if (!skb)
2058 break;
2059
2060 ret = ath10k_wmi_mgmt_tx(ar, skb);
5fb5e41f 2061 if (ret) {
5e00d31a 2062 ath10k_warn("wmi mgmt_tx failed (%d)\n", ret);
5fb5e41f
MK
2063 ieee80211_free_txskb(ar->hw, skb);
2064 }
5e00d31a
BM
2065 }
2066}
2067
5e3dd157
KV
2068/************/
2069/* Scanning */
2070/************/
2071
2072/*
2073 * This gets called if we dont get a heart-beat during scan.
2074 * This may indicate the FW has hung and we need to abort the
2075 * scan manually to prevent cancel_hw_scan() from deadlocking
2076 */
2077void ath10k_reset_scan(unsigned long ptr)
2078{
2079 struct ath10k *ar = (struct ath10k *)ptr;
2080
2081 spin_lock_bh(&ar->data_lock);
2082 if (!ar->scan.in_progress) {
2083 spin_unlock_bh(&ar->data_lock);
2084 return;
2085 }
2086
2087 ath10k_warn("scan timeout. resetting. fw issue?\n");
2088
2089 if (ar->scan.is_roc)
2090 ieee80211_remain_on_channel_expired(ar->hw);
2091 else
2092 ieee80211_scan_completed(ar->hw, 1 /* aborted */);
2093
2094 ar->scan.in_progress = false;
2095 complete_all(&ar->scan.completed);
2096 spin_unlock_bh(&ar->data_lock);
2097}
2098
2099static int ath10k_abort_scan(struct ath10k *ar)
2100{
2101 struct wmi_stop_scan_arg arg = {
2102 .req_id = 1, /* FIXME */
2103 .req_type = WMI_SCAN_STOP_ONE,
2104 .u.scan_id = ATH10K_SCAN_ID,
2105 };
2106 int ret;
2107
2108 lockdep_assert_held(&ar->conf_mutex);
2109
2110 del_timer_sync(&ar->scan.timeout);
2111
2112 spin_lock_bh(&ar->data_lock);
2113 if (!ar->scan.in_progress) {
2114 spin_unlock_bh(&ar->data_lock);
2115 return 0;
2116 }
2117
2118 ar->scan.aborting = true;
2119 spin_unlock_bh(&ar->data_lock);
2120
2121 ret = ath10k_wmi_stop_scan(ar, &arg);
2122 if (ret) {
2123 ath10k_warn("could not submit wmi stop scan (%d)\n", ret);
adb8c9b7
MK
2124 spin_lock_bh(&ar->data_lock);
2125 ar->scan.in_progress = false;
2126 ath10k_offchan_tx_purge(ar);
2127 spin_unlock_bh(&ar->data_lock);
5e3dd157
KV
2128 return -EIO;
2129 }
2130
5e3dd157
KV
2131 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
2132 if (ret == 0)
2133 ath10k_warn("timed out while waiting for scan to stop\n");
2134
2135 /* scan completion may be done right after we timeout here, so let's
2136 * check the in_progress and tell mac80211 scan is completed. if we
2137 * don't do that and FW fails to send us scan completion indication
2138 * then userspace won't be able to scan anymore */
2139 ret = 0;
2140
2141 spin_lock_bh(&ar->data_lock);
2142 if (ar->scan.in_progress) {
2143 ath10k_warn("could not stop scan. its still in progress\n");
2144 ar->scan.in_progress = false;
2145 ath10k_offchan_tx_purge(ar);
2146 ret = -ETIMEDOUT;
2147 }
2148 spin_unlock_bh(&ar->data_lock);
2149
2150 return ret;
2151}
2152
2153static int ath10k_start_scan(struct ath10k *ar,
2154 const struct wmi_start_scan_arg *arg)
2155{
2156 int ret;
2157
2158 lockdep_assert_held(&ar->conf_mutex);
2159
2160 ret = ath10k_wmi_start_scan(ar, arg);
2161 if (ret)
2162 return ret;
2163
5e3dd157
KV
2164 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
2165 if (ret == 0) {
2166 ath10k_abort_scan(ar);
2167 return ret;
2168 }
2169
2170 /* the scan can complete earlier, before we even
2171 * start the timer. in that case the timer handler
2172 * checks ar->scan.in_progress and bails out if its
2173 * false. Add a 200ms margin to account event/command
2174 * processing. */
2175 mod_timer(&ar->scan.timeout, jiffies +
2176 msecs_to_jiffies(arg->max_scan_time+200));
2177 return 0;
2178}
2179
2180/**********************/
2181/* mac80211 callbacks */
2182/**********************/
2183
2184static void ath10k_tx(struct ieee80211_hw *hw,
2185 struct ieee80211_tx_control *control,
2186 struct sk_buff *skb)
2187{
2188 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2189 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2190 struct ath10k *ar = hw->priv;
ddb6ad77 2191 u8 tid, vdev_id;
5e3dd157
KV
2192
2193 /* We should disable CCK RATE due to P2P */
2194 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
2195 ath10k_dbg(ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
2196
2197 /* we must calculate tid before we apply qos workaround
2198 * as we'd lose the qos control field */
42c3aa6f 2199 tid = ath10k_tx_h_get_tid(hdr);
ddb6ad77 2200 vdev_id = ath10k_tx_h_get_vdev_id(ar, info);
5e3dd157 2201
cf84bd4d
MK
2202 /* it makes no sense to process injected frames like that */
2203 if (info->control.vif &&
2204 info->control.vif->type != NL80211_IFTYPE_MONITOR) {
2205 ath10k_tx_h_qos_workaround(hw, control, skb);
2206 ath10k_tx_h_update_wep_key(skb);
2207 ath10k_tx_h_add_p2p_noa_ie(ar, skb);
2208 ath10k_tx_h_seq_no(skb);
2209 }
5e3dd157 2210
5e00d31a 2211 ATH10K_SKB_CB(skb)->vdev_id = vdev_id;
27bb178d 2212 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
5e3dd157
KV
2213 ATH10K_SKB_CB(skb)->htt.tid = tid;
2214
2215 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
2216 spin_lock_bh(&ar->data_lock);
2217 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
5e00d31a 2218 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
5e3dd157
KV
2219 spin_unlock_bh(&ar->data_lock);
2220
2221 ath10k_dbg(ATH10K_DBG_MAC, "queued offchannel skb %p\n", skb);
2222
2223 skb_queue_tail(&ar->offchan_tx_queue, skb);
2224 ieee80211_queue_work(hw, &ar->offchan_tx_work);
2225 return;
2226 }
2227
2228 ath10k_tx_htt(ar, skb);
2229}
2230
2231/*
2232 * Initialize various parameters with default vaules.
2233 */
affd3217 2234void ath10k_halt(struct ath10k *ar)
818bdd16
MK
2235{
2236 lockdep_assert_held(&ar->conf_mutex);
2237
e8a50f8b 2238 ath10k_stop_cac(ar);
818bdd16
MK
2239 del_timer_sync(&ar->scan.timeout);
2240 ath10k_offchan_tx_purge(ar);
5e00d31a 2241 ath10k_mgmt_over_wmi_tx_purge(ar);
818bdd16
MK
2242 ath10k_peer_cleanup_all(ar);
2243 ath10k_core_stop(ar);
2244 ath10k_hif_power_down(ar);
2245
2246 spin_lock_bh(&ar->data_lock);
2247 if (ar->scan.in_progress) {
2248 del_timer(&ar->scan.timeout);
2249 ar->scan.in_progress = false;
2250 ieee80211_scan_completed(ar->hw, true);
2251 }
2252 spin_unlock_bh(&ar->data_lock);
2253}
2254
5e3dd157
KV
2255static int ath10k_start(struct ieee80211_hw *hw)
2256{
2257 struct ath10k *ar = hw->priv;
818bdd16 2258 int ret = 0;
5e3dd157 2259
548db54c
MK
2260 mutex_lock(&ar->conf_mutex);
2261
affd3217
MK
2262 if (ar->state != ATH10K_STATE_OFF &&
2263 ar->state != ATH10K_STATE_RESTARTING) {
818bdd16
MK
2264 ret = -EINVAL;
2265 goto exit;
2266 }
2267
2268 ret = ath10k_hif_power_up(ar);
2269 if (ret) {
2270 ath10k_err("could not init hif (%d)\n", ret);
2271 ar->state = ATH10K_STATE_OFF;
2272 goto exit;
2273 }
2274
2275 ret = ath10k_core_start(ar);
2276 if (ret) {
2277 ath10k_err("could not init core (%d)\n", ret);
2278 ath10k_hif_power_down(ar);
2279 ar->state = ATH10K_STATE_OFF;
2280 goto exit;
2281 }
2282
affd3217
MK
2283 if (ar->state == ATH10K_STATE_OFF)
2284 ar->state = ATH10K_STATE_ON;
2285 else if (ar->state == ATH10K_STATE_RESTARTING)
2286 ar->state = ATH10K_STATE_RESTARTED;
2287
226a339b 2288 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
5e3dd157
KV
2289 if (ret)
2290 ath10k_warn("could not enable WMI_PDEV_PARAM_PMF_QOS (%d)\n",
2291 ret);
2292
c4dd0d01 2293 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
5e3dd157
KV
2294 if (ret)
2295 ath10k_warn("could not init WMI_PDEV_PARAM_DYNAMIC_BW (%d)\n",
2296 ret);
2297
ab6258ed
MP
2298 /*
2299 * By default FW set ARP frames ac to voice (6). In that case ARP
2300 * exchange is not working properly for UAPSD enabled AP. ARP requests
2301 * which arrives with access category 0 are processed by network stack
2302 * and send back with access category 0, but FW changes access category
2303 * to 6. Set ARP frames access category to best effort (0) solves
2304 * this problem.
2305 */
2306
2307 ret = ath10k_wmi_pdev_set_param(ar,
2308 ar->wmi.pdev_param->arp_ac_override, 0);
2309 if (ret) {
2310 ath10k_warn("could not set arp ac override parameter: %d\n",
2311 ret);
2312 goto exit;
2313 }
2314
f7843d7f 2315 ath10k_regd_update(ar);
c60bdd83 2316 ret = 0;
f7843d7f 2317
818bdd16 2318exit:
548db54c 2319 mutex_unlock(&ar->conf_mutex);
c60bdd83 2320 return ret;
5e3dd157
KV
2321}
2322
2323static void ath10k_stop(struct ieee80211_hw *hw)
2324{
2325 struct ath10k *ar = hw->priv;
2326
548db54c 2327 mutex_lock(&ar->conf_mutex);
affd3217
MK
2328 if (ar->state == ATH10K_STATE_ON ||
2329 ar->state == ATH10K_STATE_RESTARTED ||
2330 ar->state == ATH10K_STATE_WEDGED)
818bdd16 2331 ath10k_halt(ar);
a96d7745 2332
f7843d7f 2333 ar->state = ATH10K_STATE_OFF;
548db54c
MK
2334 mutex_unlock(&ar->conf_mutex);
2335
5e00d31a
BM
2336 ath10k_mgmt_over_wmi_tx_purge(ar);
2337
548db54c 2338 cancel_work_sync(&ar->offchan_tx_work);
5e00d31a 2339 cancel_work_sync(&ar->wmi_mgmt_tx_work);
affd3217 2340 cancel_work_sync(&ar->restart_work);
5e3dd157
KV
2341}
2342
ad088bfa 2343static int ath10k_config_ps(struct ath10k *ar)
5e3dd157 2344{
ad088bfa
MK
2345 struct ath10k_vif *arvif;
2346 int ret = 0;
affd3217
MK
2347
2348 lockdep_assert_held(&ar->conf_mutex);
2349
ad088bfa
MK
2350 list_for_each_entry(arvif, &ar->arvifs, list) {
2351 ret = ath10k_mac_vif_setup_ps(arvif);
2352 if (ret) {
2353 ath10k_warn("could not setup powersave (%d)\n", ret);
2354 break;
2355 }
2356 }
affd3217 2357
ad088bfa 2358 return ret;
affd3217
MK
2359}
2360
c930f744
MK
2361static const char *chandef_get_width(enum nl80211_chan_width width)
2362{
2363 switch (width) {
2364 case NL80211_CHAN_WIDTH_20_NOHT:
2365 return "20 (noht)";
2366 case NL80211_CHAN_WIDTH_20:
2367 return "20";
2368 case NL80211_CHAN_WIDTH_40:
2369 return "40";
2370 case NL80211_CHAN_WIDTH_80:
2371 return "80";
2372 case NL80211_CHAN_WIDTH_80P80:
2373 return "80+80";
2374 case NL80211_CHAN_WIDTH_160:
2375 return "160";
2376 case NL80211_CHAN_WIDTH_5:
2377 return "5";
2378 case NL80211_CHAN_WIDTH_10:
2379 return "10";
2380 }
2381 return "?";
2382}
2383
2384static void ath10k_config_chan(struct ath10k *ar)
2385{
2386 struct ath10k_vif *arvif;
2387 bool monitor_was_enabled;
2388 int ret;
2389
2390 lockdep_assert_held(&ar->conf_mutex);
2391
2392 ath10k_dbg(ATH10K_DBG_MAC,
2393 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
2394 ar->chandef.chan->center_freq,
2395 ar->chandef.center_freq1,
2396 ar->chandef.center_freq2,
2397 chandef_get_width(ar->chandef.width));
2398
2399 /* First stop monitor interface. Some FW versions crash if there's a
2400 * lone monitor interface. */
2401 monitor_was_enabled = ar->monitor_enabled;
2402
2403 if (ar->monitor_enabled)
2404 ath10k_monitor_stop(ar);
2405
2406 list_for_each_entry(arvif, &ar->arvifs, list) {
2407 if (!arvif->is_started)
2408 continue;
2409
2410 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2411 continue;
2412
2413 ret = ath10k_vdev_stop(arvif);
2414 if (ret) {
2415 ath10k_warn("could not stop vdev %d (%d)\n",
2416 arvif->vdev_id, ret);
2417 continue;
2418 }
2419 }
2420
2421 /* all vdevs are now stopped - now attempt to restart them */
2422
2423 list_for_each_entry(arvif, &ar->arvifs, list) {
2424 if (!arvif->is_started)
2425 continue;
2426
2427 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2428 continue;
2429
2430 ret = ath10k_vdev_start(arvif);
2431 if (ret) {
2432 ath10k_warn("could not start vdev %d (%d)\n",
2433 arvif->vdev_id, ret);
2434 continue;
2435 }
2436
2437 if (!arvif->is_up)
2438 continue;
2439
2440 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
2441 arvif->bssid);
2442 if (ret) {
2443 ath10k_warn("could not bring vdev up %d (%d)\n",
2444 arvif->vdev_id, ret);
2445 continue;
2446 }
2447 }
2448
2449 if (monitor_was_enabled)
2450 ath10k_monitor_start(ar, ar->monitor_vdev_id);
2451}
2452
affd3217
MK
2453static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
2454{
5e3dd157
KV
2455 struct ath10k *ar = hw->priv;
2456 struct ieee80211_conf *conf = &hw->conf;
2457 int ret = 0;
5474efe8 2458 u32 param;
5e3dd157
KV
2459
2460 mutex_lock(&ar->conf_mutex);
2461
2462 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
e8a50f8b
MP
2463 ath10k_dbg(ATH10K_DBG_MAC,
2464 "mac config channel %d mhz flags 0x%x\n",
2465 conf->chandef.chan->center_freq,
2466 conf->chandef.chan->flags);
2467
5e3dd157
KV
2468 spin_lock_bh(&ar->data_lock);
2469 ar->rx_channel = conf->chandef.chan;
2470 spin_unlock_bh(&ar->data_lock);
e8a50f8b
MP
2471
2472 ath10k_config_radar_detection(ar);
c930f744
MK
2473
2474 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
2475 ar->chandef = conf->chandef;
2476 ath10k_config_chan(ar);
2477 }
5e3dd157
KV
2478 }
2479
5474efe8
MK
2480 if (changed & IEEE80211_CONF_CHANGE_POWER) {
2481 ath10k_dbg(ATH10K_DBG_MAC, "mac config power %d\n",
2482 hw->conf.power_level);
2483
2484 param = ar->wmi.pdev_param->txpower_limit2g;
2485 ret = ath10k_wmi_pdev_set_param(ar, param,
2486 hw->conf.power_level * 2);
2487 if (ret)
2488 ath10k_warn("mac failed to set 2g txpower %d (%d)\n",
2489 hw->conf.power_level, ret);
2490
2491 param = ar->wmi.pdev_param->txpower_limit5g;
2492 ret = ath10k_wmi_pdev_set_param(ar, param,
2493 hw->conf.power_level * 2);
2494 if (ret)
2495 ath10k_warn("mac failed to set 5g txpower %d (%d)\n",
2496 hw->conf.power_level, ret);
5e3dd157
KV
2497 }
2498
affd3217
MK
2499 if (changed & IEEE80211_CONF_CHANGE_PS)
2500 ath10k_config_ps(ar);
5e3dd157
KV
2501
2502 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
2503 if (conf->flags & IEEE80211_CONF_MONITOR)
2504 ret = ath10k_monitor_create(ar);
2505 else
2506 ret = ath10k_monitor_destroy(ar);
2507 }
2508
2509 mutex_unlock(&ar->conf_mutex);
2510 return ret;
2511}
2512
2513/*
2514 * TODO:
2515 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
2516 * because we will send mgmt frames without CCK. This requirement
2517 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
2518 * in the TX packet.
2519 */
2520static int ath10k_add_interface(struct ieee80211_hw *hw,
2521 struct ieee80211_vif *vif)
2522{
2523 struct ath10k *ar = hw->priv;
2524 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2525 enum wmi_sta_powersave_param param;
2526 int ret = 0;
5a13e76e 2527 u32 value;
5e3dd157 2528 int bit;
6d1506e7 2529 u32 vdev_param;
5e3dd157
KV
2530
2531 mutex_lock(&ar->conf_mutex);
2532
0dbd09e6
MK
2533 memset(arvif, 0, sizeof(*arvif));
2534
5e3dd157
KV
2535 arvif->ar = ar;
2536 arvif->vif = vif;
2537
cc4827b9 2538 INIT_WORK(&arvif->wep_key_work, ath10k_tx_wep_key_work);
e63b33f3 2539 INIT_LIST_HEAD(&arvif->list);
cc4827b9 2540
5e3dd157
KV
2541 if ((vif->type == NL80211_IFTYPE_MONITOR) && ar->monitor_present) {
2542 ath10k_warn("Only one monitor interface allowed\n");
2543 ret = -EBUSY;
9dad14ae 2544 goto err;
5e3dd157
KV
2545 }
2546
2547 bit = ffs(ar->free_vdev_map);
2548 if (bit == 0) {
2549 ret = -EBUSY;
9dad14ae 2550 goto err;
5e3dd157
KV
2551 }
2552
2553 arvif->vdev_id = bit - 1;
2554 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
5e3dd157
KV
2555
2556 if (ar->p2p)
2557 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
2558
2559 switch (vif->type) {
2560 case NL80211_IFTYPE_UNSPECIFIED:
2561 case NL80211_IFTYPE_STATION:
2562 arvif->vdev_type = WMI_VDEV_TYPE_STA;
2563 if (vif->p2p)
2564 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
2565 break;
2566 case NL80211_IFTYPE_ADHOC:
2567 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
2568 break;
2569 case NL80211_IFTYPE_AP:
2570 arvif->vdev_type = WMI_VDEV_TYPE_AP;
2571
2572 if (vif->p2p)
2573 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
2574 break;
2575 case NL80211_IFTYPE_MONITOR:
2576 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
2577 break;
2578 default:
2579 WARN_ON(1);
2580 break;
2581 }
2582
60c3daa8 2583 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d\n",
5e3dd157
KV
2584 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype);
2585
2586 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
2587 arvif->vdev_subtype, vif->addr);
2588 if (ret) {
69244e56
BG
2589 ath10k_warn("WMI vdev %i create failed: ret %d\n",
2590 arvif->vdev_id, ret);
9dad14ae 2591 goto err;
5e3dd157
KV
2592 }
2593
9dad14ae 2594 ar->free_vdev_map &= ~BIT(arvif->vdev_id);
0579119f 2595 list_add(&arvif->list, &ar->arvifs);
9dad14ae 2596
6d1506e7
BM
2597 vdev_param = ar->wmi.vdev_param->def_keyid;
2598 ret = ath10k_wmi_vdev_set_param(ar, 0, vdev_param,
cc4827b9 2599 arvif->def_wep_key_idx);
9dad14ae 2600 if (ret) {
69244e56
BG
2601 ath10k_warn("Failed to set vdev %i default keyid: %d\n",
2602 arvif->vdev_id, ret);
9dad14ae
MK
2603 goto err_vdev_delete;
2604 }
5e3dd157 2605
6d1506e7
BM
2606 vdev_param = ar->wmi.vdev_param->tx_encap_type;
2607 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5e3dd157 2608 ATH10K_HW_TXRX_NATIVE_WIFI);
ebc9abdd 2609 /* 10.X firmware does not support this VDEV parameter. Do not warn */
9dad14ae 2610 if (ret && ret != -EOPNOTSUPP) {
69244e56
BG
2611 ath10k_warn("Failed to set vdev %i TX encap: %d\n",
2612 arvif->vdev_id, ret);
9dad14ae
MK
2613 goto err_vdev_delete;
2614 }
5e3dd157
KV
2615
2616 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2617 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
2618 if (ret) {
69244e56
BG
2619 ath10k_warn("Failed to create vdev %i peer for AP: %d\n",
2620 arvif->vdev_id, ret);
9dad14ae 2621 goto err_vdev_delete;
5e3dd157 2622 }
cdf07409 2623
5a13e76e
KV
2624 ret = ath10k_mac_set_kickout(arvif);
2625 if (ret) {
69244e56
BG
2626 ath10k_warn("Failed to set vdev %i kickout parameters: %d\n",
2627 arvif->vdev_id, ret);
5a13e76e
KV
2628 goto err_peer_delete;
2629 }
5e3dd157
KV
2630 }
2631
2632 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
2633 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
2634 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2635 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2636 param, value);
9dad14ae 2637 if (ret) {
69244e56
BG
2638 ath10k_warn("Failed to set vdev %i RX wake policy: %d\n",
2639 arvif->vdev_id, ret);
9dad14ae
MK
2640 goto err_peer_delete;
2641 }
5e3dd157
KV
2642
2643 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
2644 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
2645 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2646 param, value);
9dad14ae 2647 if (ret) {
69244e56
BG
2648 ath10k_warn("Failed to set vdev %i TX wake thresh: %d\n",
2649 arvif->vdev_id, ret);
9dad14ae
MK
2650 goto err_peer_delete;
2651 }
5e3dd157
KV
2652
2653 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
2654 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
2655 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2656 param, value);
9dad14ae 2657 if (ret) {
69244e56
BG
2658 ath10k_warn("Failed to set vdev %i PSPOLL count: %d\n",
2659 arvif->vdev_id, ret);
9dad14ae
MK
2660 goto err_peer_delete;
2661 }
5e3dd157
KV
2662 }
2663
424121c3 2664 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
9dad14ae 2665 if (ret) {
679c54a6
MK
2666 ath10k_warn("failed to set rts threshold for vdev %d (%d)\n",
2667 arvif->vdev_id, ret);
9dad14ae
MK
2668 goto err_peer_delete;
2669 }
679c54a6 2670
424121c3 2671 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
9dad14ae 2672 if (ret) {
679c54a6
MK
2673 ath10k_warn("failed to set frag threshold for vdev %d (%d)\n",
2674 arvif->vdev_id, ret);
9dad14ae
MK
2675 goto err_peer_delete;
2676 }
679c54a6 2677
5e3dd157
KV
2678 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2679 ar->monitor_present = true;
2680
5e3dd157 2681 mutex_unlock(&ar->conf_mutex);
9dad14ae
MK
2682 return 0;
2683
2684err_peer_delete:
2685 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
2686 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
2687
2688err_vdev_delete:
2689 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2690 ar->free_vdev_map &= ~BIT(arvif->vdev_id);
0579119f 2691 list_del(&arvif->list);
9dad14ae
MK
2692
2693err:
2694 mutex_unlock(&ar->conf_mutex);
2695
5e3dd157
KV
2696 return ret;
2697}
2698
2699static void ath10k_remove_interface(struct ieee80211_hw *hw,
2700 struct ieee80211_vif *vif)
2701{
2702 struct ath10k *ar = hw->priv;
2703 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2704 int ret;
2705
2706 mutex_lock(&ar->conf_mutex);
2707
cc4827b9
MK
2708 cancel_work_sync(&arvif->wep_key_work);
2709
ed54388a
MK
2710 spin_lock_bh(&ar->data_lock);
2711 if (arvif->beacon) {
2712 dev_kfree_skb_any(arvif->beacon);
2713 arvif->beacon = NULL;
2714 }
2715 spin_unlock_bh(&ar->data_lock);
2716
5e3dd157 2717 ar->free_vdev_map |= 1 << (arvif->vdev_id);
0579119f 2718 list_del(&arvif->list);
5e3dd157
KV
2719
2720 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2721 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
2722 if (ret)
69244e56
BG
2723 ath10k_warn("Failed to remove peer for AP vdev %i: %d\n",
2724 arvif->vdev_id, ret);
5e3dd157
KV
2725
2726 kfree(arvif->u.ap.noa_data);
2727 }
2728
69244e56 2729 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
60c3daa8
KV
2730 arvif->vdev_id);
2731
5e3dd157
KV
2732 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2733 if (ret)
69244e56
BG
2734 ath10k_warn("WMI vdev %i delete failed: %d\n",
2735 arvif->vdev_id, ret);
5e3dd157
KV
2736
2737 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2738 ar->monitor_present = false;
2739
2740 ath10k_peer_cleanup(ar, arvif->vdev_id);
2741
2742 mutex_unlock(&ar->conf_mutex);
2743}
2744
2745/*
2746 * FIXME: Has to be verified.
2747 */
2748#define SUPPORTED_FILTERS \
2749 (FIF_PROMISC_IN_BSS | \
2750 FIF_ALLMULTI | \
2751 FIF_CONTROL | \
2752 FIF_PSPOLL | \
2753 FIF_OTHER_BSS | \
2754 FIF_BCN_PRBRESP_PROMISC | \
2755 FIF_PROBE_REQ | \
2756 FIF_FCSFAIL)
2757
2758static void ath10k_configure_filter(struct ieee80211_hw *hw,
2759 unsigned int changed_flags,
2760 unsigned int *total_flags,
2761 u64 multicast)
2762{
2763 struct ath10k *ar = hw->priv;
2764 int ret;
2765
2766 mutex_lock(&ar->conf_mutex);
2767
2768 changed_flags &= SUPPORTED_FILTERS;
2769 *total_flags &= SUPPORTED_FILTERS;
2770 ar->filter_flags = *total_flags;
2771
afd0922e
MK
2772 /* Monitor must not be started if it wasn't created first.
2773 * Promiscuous mode may be started on a non-monitor interface - in
2774 * such case the monitor vdev is not created so starting the
2775 * monitor makes no sense. Since ath10k uses no special RX filters
2776 * (only BSS filter in STA mode) there's no need for any special
2777 * action here. */
5e3dd157 2778 if ((ar->filter_flags & FIF_PROMISC_IN_BSS) &&
afd0922e 2779 !ar->monitor_enabled && ar->monitor_present) {
60c3daa8
KV
2780 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor %d start\n",
2781 ar->monitor_vdev_id);
2782
5e3dd157
KV
2783 ret = ath10k_monitor_start(ar, ar->monitor_vdev_id);
2784 if (ret)
2785 ath10k_warn("Unable to start monitor mode\n");
5e3dd157 2786 } else if (!(ar->filter_flags & FIF_PROMISC_IN_BSS) &&
afd0922e 2787 ar->monitor_enabled && ar->monitor_present) {
60c3daa8
KV
2788 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor %d stop\n",
2789 ar->monitor_vdev_id);
2790
5e3dd157
KV
2791 ret = ath10k_monitor_stop(ar);
2792 if (ret)
2793 ath10k_warn("Unable to stop monitor mode\n");
5e3dd157
KV
2794 }
2795
2796 mutex_unlock(&ar->conf_mutex);
2797}
2798
2799static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
2800 struct ieee80211_vif *vif,
2801 struct ieee80211_bss_conf *info,
2802 u32 changed)
2803{
2804 struct ath10k *ar = hw->priv;
2805 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2806 int ret = 0;
226a339b 2807 u32 vdev_param, pdev_param;
5e3dd157
KV
2808
2809 mutex_lock(&ar->conf_mutex);
2810
2811 if (changed & BSS_CHANGED_IBSS)
2812 ath10k_control_ibss(arvif, info, vif->addr);
2813
2814 if (changed & BSS_CHANGED_BEACON_INT) {
2815 arvif->beacon_interval = info->beacon_int;
6d1506e7
BM
2816 vdev_param = ar->wmi.vdev_param->beacon_interval;
2817 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5e3dd157 2818 arvif->beacon_interval);
60c3daa8
KV
2819 ath10k_dbg(ATH10K_DBG_MAC,
2820 "mac vdev %d beacon_interval %d\n",
2821 arvif->vdev_id, arvif->beacon_interval);
2822
5e3dd157 2823 if (ret)
69244e56
BG
2824 ath10k_warn("Failed to set beacon interval for vdev %d: %i\n",
2825 arvif->vdev_id, ret);
5e3dd157
KV
2826 }
2827
2828 if (changed & BSS_CHANGED_BEACON) {
60c3daa8
KV
2829 ath10k_dbg(ATH10K_DBG_MAC,
2830 "vdev %d set beacon tx mode to staggered\n",
2831 arvif->vdev_id);
2832
226a339b
BM
2833 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
2834 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
5e3dd157
KV
2835 WMI_BEACON_STAGGERED_MODE);
2836 if (ret)
69244e56
BG
2837 ath10k_warn("Failed to set beacon mode for vdev %d: %i\n",
2838 arvif->vdev_id, ret);
5e3dd157
KV
2839 }
2840
b70727e8 2841 if (changed & BSS_CHANGED_BEACON_INFO) {
5e3dd157
KV
2842 arvif->dtim_period = info->dtim_period;
2843
60c3daa8
KV
2844 ath10k_dbg(ATH10K_DBG_MAC,
2845 "mac vdev %d dtim_period %d\n",
2846 arvif->vdev_id, arvif->dtim_period);
2847
6d1506e7
BM
2848 vdev_param = ar->wmi.vdev_param->dtim_period;
2849 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5e3dd157
KV
2850 arvif->dtim_period);
2851 if (ret)
69244e56
BG
2852 ath10k_warn("Failed to set dtim period for vdev %d: %i\n",
2853 arvif->vdev_id, ret);
5e3dd157
KV
2854 }
2855
2856 if (changed & BSS_CHANGED_SSID &&
2857 vif->type == NL80211_IFTYPE_AP) {
2858 arvif->u.ap.ssid_len = info->ssid_len;
2859 if (info->ssid_len)
2860 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
2861 arvif->u.ap.hidden_ssid = info->hidden_ssid;
2862 }
2863
2864 if (changed & BSS_CHANGED_BSSID) {
2865 if (!is_zero_ether_addr(info->bssid)) {
60c3daa8
KV
2866 ath10k_dbg(ATH10K_DBG_MAC,
2867 "mac vdev %d create peer %pM\n",
2868 arvif->vdev_id, info->bssid);
2869
5e3dd157
KV
2870 ret = ath10k_peer_create(ar, arvif->vdev_id,
2871 info->bssid);
2872 if (ret)
69244e56 2873 ath10k_warn("Failed to add peer %pM for vdev %d when changing bssid: %i\n",
479398b0 2874 info->bssid, arvif->vdev_id, ret);
5e3dd157
KV
2875
2876 if (vif->type == NL80211_IFTYPE_STATION) {
2877 /*
2878 * this is never erased as we it for crypto key
2879 * clearing; this is FW requirement
2880 */
c930f744 2881 memcpy(arvif->bssid, info->bssid, ETH_ALEN);
5e3dd157 2882
60c3daa8
KV
2883 ath10k_dbg(ATH10K_DBG_MAC,
2884 "mac vdev %d start %pM\n",
2885 arvif->vdev_id, info->bssid);
2886
5e3dd157 2887 ret = ath10k_vdev_start(arvif);
c930f744 2888 if (ret) {
69244e56
BG
2889 ath10k_warn("failed to start vdev %i: %d\n",
2890 arvif->vdev_id, ret);
75459e33 2891 goto exit;
c930f744
MK
2892 }
2893
2894 arvif->is_started = true;
5e3dd157
KV
2895 }
2896
2897 /*
2898 * Mac80211 does not keep IBSS bssid when leaving IBSS,
2899 * so driver need to store it. It is needed when leaving
2900 * IBSS in order to remove BSSID peer.
2901 */
2902 if (vif->type == NL80211_IFTYPE_ADHOC)
c930f744 2903 memcpy(arvif->bssid, info->bssid,
5e3dd157
KV
2904 ETH_ALEN);
2905 }
2906 }
2907
2908 if (changed & BSS_CHANGED_BEACON_ENABLED)
2909 ath10k_control_beaconing(arvif, info);
2910
2911 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
e81bd104 2912 arvif->use_cts_prot = info->use_cts_prot;
60c3daa8 2913 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
e81bd104 2914 arvif->vdev_id, info->use_cts_prot);
60c3daa8 2915
e81bd104 2916 ret = ath10k_recalc_rtscts_prot(arvif);
5e3dd157 2917 if (ret)
e81bd104 2918 ath10k_warn("Failed to recalculate rts/cts prot for vdev %d: %d\n",
69244e56 2919 arvif->vdev_id, ret);
5e3dd157
KV
2920 }
2921
2922 if (changed & BSS_CHANGED_ERP_SLOT) {
2923 u32 slottime;
2924 if (info->use_short_slot)
2925 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
2926
2927 else
2928 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
2929
60c3daa8
KV
2930 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
2931 arvif->vdev_id, slottime);
2932
6d1506e7
BM
2933 vdev_param = ar->wmi.vdev_param->slot_time;
2934 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5e3dd157
KV
2935 slottime);
2936 if (ret)
69244e56
BG
2937 ath10k_warn("Failed to set erp slot for vdev %d: %i\n",
2938 arvif->vdev_id, ret);
5e3dd157
KV
2939 }
2940
2941 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
2942 u32 preamble;
2943 if (info->use_short_preamble)
2944 preamble = WMI_VDEV_PREAMBLE_SHORT;
2945 else
2946 preamble = WMI_VDEV_PREAMBLE_LONG;
2947
60c3daa8
KV
2948 ath10k_dbg(ATH10K_DBG_MAC,
2949 "mac vdev %d preamble %dn",
2950 arvif->vdev_id, preamble);
2951
6d1506e7
BM
2952 vdev_param = ar->wmi.vdev_param->preamble;
2953 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5e3dd157
KV
2954 preamble);
2955 if (ret)
69244e56
BG
2956 ath10k_warn("Failed to set preamble for vdev %d: %i\n",
2957 arvif->vdev_id, ret);
5e3dd157
KV
2958 }
2959
2960 if (changed & BSS_CHANGED_ASSOC) {
2961 if (info->assoc)
2962 ath10k_bss_assoc(hw, vif, info);
2963 }
2964
75459e33 2965exit:
5e3dd157
KV
2966 mutex_unlock(&ar->conf_mutex);
2967}
2968
2969static int ath10k_hw_scan(struct ieee80211_hw *hw,
2970 struct ieee80211_vif *vif,
2971 struct cfg80211_scan_request *req)
2972{
2973 struct ath10k *ar = hw->priv;
2974 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2975 struct wmi_start_scan_arg arg;
2976 int ret = 0;
2977 int i;
2978
2979 mutex_lock(&ar->conf_mutex);
2980
2981 spin_lock_bh(&ar->data_lock);
2982 if (ar->scan.in_progress) {
2983 spin_unlock_bh(&ar->data_lock);
2984 ret = -EBUSY;
2985 goto exit;
2986 }
2987
16735d02
WS
2988 reinit_completion(&ar->scan.started);
2989 reinit_completion(&ar->scan.completed);
5e3dd157
KV
2990 ar->scan.in_progress = true;
2991 ar->scan.aborting = false;
2992 ar->scan.is_roc = false;
2993 ar->scan.vdev_id = arvif->vdev_id;
2994 spin_unlock_bh(&ar->data_lock);
2995
2996 memset(&arg, 0, sizeof(arg));
2997 ath10k_wmi_start_scan_init(ar, &arg);
2998 arg.vdev_id = arvif->vdev_id;
2999 arg.scan_id = ATH10K_SCAN_ID;
3000
3001 if (!req->no_cck)
3002 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
3003
3004 if (req->ie_len) {
3005 arg.ie_len = req->ie_len;
3006 memcpy(arg.ie, req->ie, arg.ie_len);
3007 }
3008
3009 if (req->n_ssids) {
3010 arg.n_ssids = req->n_ssids;
3011 for (i = 0; i < arg.n_ssids; i++) {
3012 arg.ssids[i].len = req->ssids[i].ssid_len;
3013 arg.ssids[i].ssid = req->ssids[i].ssid;
3014 }
dcd4a561
MK
3015 } else {
3016 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
5e3dd157
KV
3017 }
3018
3019 if (req->n_channels) {
3020 arg.n_channels = req->n_channels;
3021 for (i = 0; i < arg.n_channels; i++)
3022 arg.channels[i] = req->channels[i]->center_freq;
3023 }
3024
3025 ret = ath10k_start_scan(ar, &arg);
3026 if (ret) {
3027 ath10k_warn("could not start hw scan (%d)\n", ret);
3028 spin_lock_bh(&ar->data_lock);
3029 ar->scan.in_progress = false;
3030 spin_unlock_bh(&ar->data_lock);
3031 }
3032
3033exit:
3034 mutex_unlock(&ar->conf_mutex);
3035 return ret;
3036}
3037
3038static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
3039 struct ieee80211_vif *vif)
3040{
3041 struct ath10k *ar = hw->priv;
3042 int ret;
3043
3044 mutex_lock(&ar->conf_mutex);
3045 ret = ath10k_abort_scan(ar);
3046 if (ret) {
3047 ath10k_warn("couldn't abort scan (%d). forcefully sending scan completion to mac80211\n",
3048 ret);
3049 ieee80211_scan_completed(hw, 1 /* aborted */);
3050 }
3051 mutex_unlock(&ar->conf_mutex);
3052}
3053
cfb27d29
MK
3054static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
3055 struct ath10k_vif *arvif,
3056 enum set_key_cmd cmd,
3057 struct ieee80211_key_conf *key)
3058{
3059 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
3060 int ret;
3061
3062 /* 10.1 firmware branch requires default key index to be set to group
3063 * key index after installing it. Otherwise FW/HW Txes corrupted
3064 * frames with multi-vif APs. This is not required for main firmware
3065 * branch (e.g. 636).
3066 *
3067 * FIXME: This has been tested only in AP. It remains unknown if this
3068 * is required for multi-vif STA interfaces on 10.1 */
3069
3070 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
3071 return;
3072
3073 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
3074 return;
3075
3076 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
3077 return;
3078
3079 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3080 return;
3081
3082 if (cmd != SET_KEY)
3083 return;
3084
3085 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3086 key->keyidx);
3087 if (ret)
69244e56
BG
3088 ath10k_warn("failed to set vdev %i group key as default key: %d\n",
3089 arvif->vdev_id, ret);
cfb27d29
MK
3090}
3091
5e3dd157
KV
3092static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3093 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
3094 struct ieee80211_key_conf *key)
3095{
3096 struct ath10k *ar = hw->priv;
3097 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3098 struct ath10k_peer *peer;
3099 const u8 *peer_addr;
3100 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3101 key->cipher == WLAN_CIPHER_SUITE_WEP104;
3102 int ret = 0;
3103
3104 if (key->keyidx > WMI_MAX_KEY_INDEX)
3105 return -ENOSPC;
3106
3107 mutex_lock(&ar->conf_mutex);
3108
3109 if (sta)
3110 peer_addr = sta->addr;
3111 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
3112 peer_addr = vif->bss_conf.bssid;
3113 else
3114 peer_addr = vif->addr;
3115
3116 key->hw_key_idx = key->keyidx;
3117
3118 /* the peer should not disappear in mid-way (unless FW goes awry) since
3119 * we already hold conf_mutex. we just make sure its there now. */
3120 spin_lock_bh(&ar->data_lock);
3121 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3122 spin_unlock_bh(&ar->data_lock);
3123
3124 if (!peer) {
3125 if (cmd == SET_KEY) {
3126 ath10k_warn("cannot install key for non-existent peer %pM\n",
3127 peer_addr);
3128 ret = -EOPNOTSUPP;
3129 goto exit;
3130 } else {
3131 /* if the peer doesn't exist there is no key to disable
3132 * anymore */
3133 goto exit;
3134 }
3135 }
3136
3137 if (is_wep) {
3138 if (cmd == SET_KEY)
3139 arvif->wep_keys[key->keyidx] = key;
3140 else
3141 arvif->wep_keys[key->keyidx] = NULL;
3142
3143 if (cmd == DISABLE_KEY)
3144 ath10k_clear_vdev_key(arvif, key);
3145 }
3146
3147 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
3148 if (ret) {
69244e56
BG
3149 ath10k_warn("key installation failed for vdev %i peer %pM: %d\n",
3150 arvif->vdev_id, peer_addr, ret);
5e3dd157
KV
3151 goto exit;
3152 }
3153
cfb27d29
MK
3154 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
3155
5e3dd157
KV
3156 spin_lock_bh(&ar->data_lock);
3157 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3158 if (peer && cmd == SET_KEY)
3159 peer->keys[key->keyidx] = key;
3160 else if (peer && cmd == DISABLE_KEY)
3161 peer->keys[key->keyidx] = NULL;
3162 else if (peer == NULL)
3163 /* impossible unless FW goes crazy */
3164 ath10k_warn("peer %pM disappeared!\n", peer_addr);
3165 spin_unlock_bh(&ar->data_lock);
3166
3167exit:
3168 mutex_unlock(&ar->conf_mutex);
3169 return ret;
3170}
3171
9797febc
MK
3172static void ath10k_sta_rc_update_wk(struct work_struct *wk)
3173{
3174 struct ath10k *ar;
3175 struct ath10k_vif *arvif;
3176 struct ath10k_sta *arsta;
3177 struct ieee80211_sta *sta;
3178 u32 changed, bw, nss, smps;
3179 int err;
3180
3181 arsta = container_of(wk, struct ath10k_sta, update_wk);
3182 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
3183 arvif = arsta->arvif;
3184 ar = arvif->ar;
3185
3186 spin_lock_bh(&ar->data_lock);
3187
3188 changed = arsta->changed;
3189 arsta->changed = 0;
3190
3191 bw = arsta->bw;
3192 nss = arsta->nss;
3193 smps = arsta->smps;
3194
3195 spin_unlock_bh(&ar->data_lock);
3196
3197 mutex_lock(&ar->conf_mutex);
3198
3199 if (changed & IEEE80211_RC_BW_CHANGED) {
3200 ath10k_dbg(ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
3201 sta->addr, bw);
3202
3203 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3204 WMI_PEER_CHAN_WIDTH, bw);
3205 if (err)
3206 ath10k_warn("failed to update STA %pM peer bw %d: %d\n",
3207 sta->addr, bw, err);
3208 }
3209
3210 if (changed & IEEE80211_RC_NSS_CHANGED) {
3211 ath10k_dbg(ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
3212 sta->addr, nss);
3213
3214 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3215 WMI_PEER_NSS, nss);
3216 if (err)
3217 ath10k_warn("failed to update STA %pM nss %d: %d\n",
3218 sta->addr, nss, err);
3219 }
3220
3221 if (changed & IEEE80211_RC_SMPS_CHANGED) {
3222 ath10k_dbg(ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
3223 sta->addr, smps);
3224
3225 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3226 WMI_PEER_SMPS_STATE, smps);
3227 if (err)
3228 ath10k_warn("failed to update STA %pM smps %d: %d\n",
3229 sta->addr, smps, err);
3230 }
3231
44d6fa90
CYY
3232 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
3233 ath10k_dbg(ATH10K_DBG_MAC, "mac update sta %pM supp rates\n",
3234 sta->addr);
3235
3236 err = ath10k_station_assoc(ar, arvif, sta, true);
3237 if (err)
3238 ath10k_warn("Failed to reassociate station: %pM\n",
3239 sta->addr);
3240 }
3241
9797febc
MK
3242 mutex_unlock(&ar->conf_mutex);
3243}
3244
5e3dd157
KV
3245static int ath10k_sta_state(struct ieee80211_hw *hw,
3246 struct ieee80211_vif *vif,
3247 struct ieee80211_sta *sta,
3248 enum ieee80211_sta_state old_state,
3249 enum ieee80211_sta_state new_state)
3250{
3251 struct ath10k *ar = hw->priv;
3252 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
9797febc 3253 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
0e759f36 3254 int max_num_peers;
5e3dd157
KV
3255 int ret = 0;
3256
76f90024
MK
3257 if (old_state == IEEE80211_STA_NOTEXIST &&
3258 new_state == IEEE80211_STA_NONE) {
3259 memset(arsta, 0, sizeof(*arsta));
3260 arsta->arvif = arvif;
3261 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
3262 }
3263
9797febc
MK
3264 /* cancel must be done outside the mutex to avoid deadlock */
3265 if ((old_state == IEEE80211_STA_NONE &&
3266 new_state == IEEE80211_STA_NOTEXIST))
3267 cancel_work_sync(&arsta->update_wk);
3268
5e3dd157
KV
3269 mutex_lock(&ar->conf_mutex);
3270
3271 if (old_state == IEEE80211_STA_NOTEXIST &&
3272 new_state == IEEE80211_STA_NONE &&
3273 vif->type != NL80211_IFTYPE_STATION) {
3274 /*
3275 * New station addition.
3276 */
0e759f36
BM
3277 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features))
3278 max_num_peers = TARGET_10X_NUM_PEERS_MAX - 1;
3279 else
3280 max_num_peers = TARGET_NUM_PEERS;
3281
3282 if (ar->num_peers >= max_num_peers) {
3283 ath10k_warn("Number of peers exceeded: peers number %d (max peers %d)\n",
3284 ar->num_peers, max_num_peers);
3285 ret = -ENOBUFS;
3286 goto exit;
3287 }
3288
60c3daa8 3289 ath10k_dbg(ATH10K_DBG_MAC,
0e759f36
BM
3290 "mac vdev %d peer create %pM (new sta) num_peers %d\n",
3291 arvif->vdev_id, sta->addr, ar->num_peers);
60c3daa8 3292
5e3dd157
KV
3293 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
3294 if (ret)
479398b0
BG
3295 ath10k_warn("Failed to add peer %pM for vdev %d when adding a new sta: %i\n",
3296 sta->addr, arvif->vdev_id, ret);
5e3dd157
KV
3297 } else if ((old_state == IEEE80211_STA_NONE &&
3298 new_state == IEEE80211_STA_NOTEXIST)) {
3299 /*
3300 * Existing station deletion.
3301 */
60c3daa8
KV
3302 ath10k_dbg(ATH10K_DBG_MAC,
3303 "mac vdev %d peer delete %pM (sta gone)\n",
3304 arvif->vdev_id, sta->addr);
5e3dd157
KV
3305 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
3306 if (ret)
69244e56
BG
3307 ath10k_warn("Failed to delete peer %pM for vdev %d: %i\n",
3308 sta->addr, arvif->vdev_id, ret);
5e3dd157
KV
3309
3310 if (vif->type == NL80211_IFTYPE_STATION)
3311 ath10k_bss_disassoc(hw, vif);
3312 } else if (old_state == IEEE80211_STA_AUTH &&
3313 new_state == IEEE80211_STA_ASSOC &&
3314 (vif->type == NL80211_IFTYPE_AP ||
3315 vif->type == NL80211_IFTYPE_ADHOC)) {
3316 /*
3317 * New association.
3318 */
60c3daa8
KV
3319 ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM associated\n",
3320 sta->addr);
3321
44d6fa90 3322 ret = ath10k_station_assoc(ar, arvif, sta, false);
5e3dd157 3323 if (ret)
69244e56
BG
3324 ath10k_warn("Failed to associate station %pM for vdev %i: %i\n",
3325 sta->addr, arvif->vdev_id, ret);
5e3dd157
KV
3326 } else if (old_state == IEEE80211_STA_ASSOC &&
3327 new_state == IEEE80211_STA_AUTH &&
3328 (vif->type == NL80211_IFTYPE_AP ||
3329 vif->type == NL80211_IFTYPE_ADHOC)) {
3330 /*
3331 * Disassociation.
3332 */
60c3daa8
KV
3333 ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
3334 sta->addr);
3335
5e3dd157
KV
3336 ret = ath10k_station_disassoc(ar, arvif, sta);
3337 if (ret)
69244e56
BG
3338 ath10k_warn("Failed to disassociate station: %pM vdev %i ret %i\n",
3339 sta->addr, arvif->vdev_id, ret);
5e3dd157 3340 }
0e759f36 3341exit:
5e3dd157
KV
3342 mutex_unlock(&ar->conf_mutex);
3343 return ret;
3344}
3345
3346static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
3347 u16 ac, bool enable)
3348{
3349 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3350 u32 value = 0;
3351 int ret = 0;
3352
548db54c
MK
3353 lockdep_assert_held(&ar->conf_mutex);
3354
5e3dd157
KV
3355 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
3356 return 0;
3357
3358 switch (ac) {
3359 case IEEE80211_AC_VO:
3360 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
3361 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
3362 break;
3363 case IEEE80211_AC_VI:
3364 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
3365 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
3366 break;
3367 case IEEE80211_AC_BE:
3368 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
3369 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
3370 break;
3371 case IEEE80211_AC_BK:
3372 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
3373 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
3374 break;
3375 }
3376
3377 if (enable)
3378 arvif->u.sta.uapsd |= value;
3379 else
3380 arvif->u.sta.uapsd &= ~value;
3381
3382 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3383 WMI_STA_PS_PARAM_UAPSD,
3384 arvif->u.sta.uapsd);
3385 if (ret) {
3386 ath10k_warn("could not set uapsd params %d\n", ret);
3387 goto exit;
3388 }
3389
3390 if (arvif->u.sta.uapsd)
3391 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
3392 else
3393 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3394
3395 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3396 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
3397 value);
3398 if (ret)
3399 ath10k_warn("could not set rx wake param %d\n", ret);
3400
3401exit:
3402 return ret;
3403}
3404
3405static int ath10k_conf_tx(struct ieee80211_hw *hw,
3406 struct ieee80211_vif *vif, u16 ac,
3407 const struct ieee80211_tx_queue_params *params)
3408{
3409 struct ath10k *ar = hw->priv;
3410 struct wmi_wmm_params_arg *p = NULL;
3411 int ret;
3412
3413 mutex_lock(&ar->conf_mutex);
3414
3415 switch (ac) {
3416 case IEEE80211_AC_VO:
3417 p = &ar->wmm_params.ac_vo;
3418 break;
3419 case IEEE80211_AC_VI:
3420 p = &ar->wmm_params.ac_vi;
3421 break;
3422 case IEEE80211_AC_BE:
3423 p = &ar->wmm_params.ac_be;
3424 break;
3425 case IEEE80211_AC_BK:
3426 p = &ar->wmm_params.ac_bk;
3427 break;
3428 }
3429
3430 if (WARN_ON(!p)) {
3431 ret = -EINVAL;
3432 goto exit;
3433 }
3434
3435 p->cwmin = params->cw_min;
3436 p->cwmax = params->cw_max;
3437 p->aifs = params->aifs;
3438
3439 /*
3440 * The channel time duration programmed in the HW is in absolute
3441 * microseconds, while mac80211 gives the txop in units of
3442 * 32 microseconds.
3443 */
3444 p->txop = params->txop * 32;
3445
3446 /* FIXME: FW accepts wmm params per hw, not per vif */
3447 ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
3448 if (ret) {
3449 ath10k_warn("could not set wmm params %d\n", ret);
3450 goto exit;
3451 }
3452
3453 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
3454 if (ret)
3455 ath10k_warn("could not set sta uapsd %d\n", ret);
3456
3457exit:
3458 mutex_unlock(&ar->conf_mutex);
3459 return ret;
3460}
3461
3462#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
3463
3464static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
3465 struct ieee80211_vif *vif,
3466 struct ieee80211_channel *chan,
3467 int duration,
3468 enum ieee80211_roc_type type)
3469{
3470 struct ath10k *ar = hw->priv;
3471 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3472 struct wmi_start_scan_arg arg;
3473 int ret;
3474
3475 mutex_lock(&ar->conf_mutex);
3476
3477 spin_lock_bh(&ar->data_lock);
3478 if (ar->scan.in_progress) {
3479 spin_unlock_bh(&ar->data_lock);
3480 ret = -EBUSY;
3481 goto exit;
3482 }
3483
16735d02
WS
3484 reinit_completion(&ar->scan.started);
3485 reinit_completion(&ar->scan.completed);
3486 reinit_completion(&ar->scan.on_channel);
5e3dd157
KV
3487 ar->scan.in_progress = true;
3488 ar->scan.aborting = false;
3489 ar->scan.is_roc = true;
3490 ar->scan.vdev_id = arvif->vdev_id;
3491 ar->scan.roc_freq = chan->center_freq;
3492 spin_unlock_bh(&ar->data_lock);
3493
3494 memset(&arg, 0, sizeof(arg));
3495 ath10k_wmi_start_scan_init(ar, &arg);
3496 arg.vdev_id = arvif->vdev_id;
3497 arg.scan_id = ATH10K_SCAN_ID;
3498 arg.n_channels = 1;
3499 arg.channels[0] = chan->center_freq;
3500 arg.dwell_time_active = duration;
3501 arg.dwell_time_passive = duration;
3502 arg.max_scan_time = 2 * duration;
3503 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
3504 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
3505
3506 ret = ath10k_start_scan(ar, &arg);
3507 if (ret) {
3508 ath10k_warn("could not start roc scan (%d)\n", ret);
3509 spin_lock_bh(&ar->data_lock);
3510 ar->scan.in_progress = false;
3511 spin_unlock_bh(&ar->data_lock);
3512 goto exit;
3513 }
3514
3515 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
3516 if (ret == 0) {
3517 ath10k_warn("could not switch to channel for roc scan\n");
3518 ath10k_abort_scan(ar);
3519 ret = -ETIMEDOUT;
3520 goto exit;
3521 }
3522
3523 ret = 0;
3524exit:
3525 mutex_unlock(&ar->conf_mutex);
3526 return ret;
3527}
3528
3529static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
3530{
3531 struct ath10k *ar = hw->priv;
3532
3533 mutex_lock(&ar->conf_mutex);
3534 ath10k_abort_scan(ar);
3535 mutex_unlock(&ar->conf_mutex);
3536
3537 return 0;
3538}
3539
3540/*
3541 * Both RTS and Fragmentation threshold are interface-specific
3542 * in ath10k, but device-specific in mac80211.
3543 */
5e3dd157 3544
ad088bfa
MK
3545static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3546{
3547 struct ath10k *ar = hw->priv;
3548 struct ath10k_vif *arvif;
3549 int ret = 0;
548db54c 3550
5e3dd157 3551 mutex_lock(&ar->conf_mutex);
ad088bfa
MK
3552 list_for_each_entry(arvif, &ar->arvifs, list) {
3553 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
3554 arvif->vdev_id, value);
3555
3556 ret = ath10k_mac_set_rts(arvif, value);
3557 if (ret) {
3558 ath10k_warn("could not set rts threshold for vdev %d (%d)\n",
3559 arvif->vdev_id, ret);
3560 break;
3561 }
3562 }
5e3dd157
KV
3563 mutex_unlock(&ar->conf_mutex);
3564
ad088bfa 3565 return ret;
5e3dd157
KV
3566}
3567
ad088bfa 3568static int ath10k_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
5e3dd157 3569{
ad088bfa
MK
3570 struct ath10k *ar = hw->priv;
3571 struct ath10k_vif *arvif;
3572 int ret = 0;
548db54c 3573
5e3dd157 3574 mutex_lock(&ar->conf_mutex);
ad088bfa
MK
3575 list_for_each_entry(arvif, &ar->arvifs, list) {
3576 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d fragmentation threshold %d\n",
3577 arvif->vdev_id, value);
3578
3579 ret = ath10k_mac_set_rts(arvif, value);
3580 if (ret) {
3581 ath10k_warn("could not set fragmentation threshold for vdev %d (%d)\n",
3582 arvif->vdev_id, ret);
3583 break;
3584 }
3585 }
5e3dd157
KV
3586 mutex_unlock(&ar->conf_mutex);
3587
ad088bfa 3588 return ret;
5e3dd157
KV
3589}
3590
3591static void ath10k_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
3592{
3593 struct ath10k *ar = hw->priv;
affd3217 3594 bool skip;
5e3dd157
KV
3595 int ret;
3596
3597 /* mac80211 doesn't care if we really xmit queued frames or not
3598 * we'll collect those frames either way if we stop/delete vdevs */
3599 if (drop)
3600 return;
3601
548db54c
MK
3602 mutex_lock(&ar->conf_mutex);
3603
affd3217
MK
3604 if (ar->state == ATH10K_STATE_WEDGED)
3605 goto skip;
3606
edb8236d 3607 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
5e3dd157 3608 bool empty;
affd3217 3609
edb8236d 3610 spin_lock_bh(&ar->htt.tx_lock);
0945baf7 3611 empty = (ar->htt.num_pending_tx == 0);
edb8236d 3612 spin_unlock_bh(&ar->htt.tx_lock);
affd3217
MK
3613
3614 skip = (ar->state == ATH10K_STATE_WEDGED);
3615
3616 (empty || skip);
5e3dd157 3617 }), ATH10K_FLUSH_TIMEOUT_HZ);
affd3217
MK
3618
3619 if (ret <= 0 || skip)
9ba4c787
BG
3620 ath10k_warn("tx not flushed (skip %i ar-state %i): %i\n",
3621 skip, ar->state, ret);
548db54c 3622
affd3217 3623skip:
548db54c 3624 mutex_unlock(&ar->conf_mutex);
5e3dd157
KV
3625}
3626
3627/* TODO: Implement this function properly
3628 * For now it is needed to reply to Probe Requests in IBSS mode.
3629 * Propably we need this information from FW.
3630 */
3631static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
3632{
3633 return 1;
3634}
3635
8cd13cad
MK
3636#ifdef CONFIG_PM
3637static int ath10k_suspend(struct ieee80211_hw *hw,
3638 struct cfg80211_wowlan *wowlan)
3639{
3640 struct ath10k *ar = hw->priv;
3641 int ret;
3642
9042e17d
MP
3643 mutex_lock(&ar->conf_mutex);
3644
00f5482b 3645 ret = ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND);
8cd13cad 3646 if (ret) {
00f5482b
MP
3647 if (ret == -ETIMEDOUT)
3648 goto resume;
9042e17d
MP
3649 ret = 1;
3650 goto exit;
8cd13cad
MK
3651 }
3652
8cd13cad
MK
3653 ret = ath10k_hif_suspend(ar);
3654 if (ret) {
3655 ath10k_warn("could not suspend hif (%d)\n", ret);
3656 goto resume;
3657 }
3658
9042e17d
MP
3659 ret = 0;
3660 goto exit;
8cd13cad
MK
3661resume:
3662 ret = ath10k_wmi_pdev_resume_target(ar);
3663 if (ret)
3664 ath10k_warn("could not resume target (%d)\n", ret);
9042e17d
MP
3665
3666 ret = 1;
3667exit:
3668 mutex_unlock(&ar->conf_mutex);
3669 return ret;
8cd13cad
MK
3670}
3671
3672static int ath10k_resume(struct ieee80211_hw *hw)
3673{
3674 struct ath10k *ar = hw->priv;
3675 int ret;
3676
9042e17d
MP
3677 mutex_lock(&ar->conf_mutex);
3678
8cd13cad
MK
3679 ret = ath10k_hif_resume(ar);
3680 if (ret) {
3681 ath10k_warn("could not resume hif (%d)\n", ret);
9042e17d
MP
3682 ret = 1;
3683 goto exit;
8cd13cad
MK
3684 }
3685
3686 ret = ath10k_wmi_pdev_resume_target(ar);
3687 if (ret) {
3688 ath10k_warn("could not resume target (%d)\n", ret);
9042e17d
MP
3689 ret = 1;
3690 goto exit;
8cd13cad
MK
3691 }
3692
9042e17d
MP
3693 ret = 0;
3694exit:
3695 mutex_unlock(&ar->conf_mutex);
3696 return ret;
8cd13cad
MK
3697}
3698#endif
3699
affd3217
MK
3700static void ath10k_restart_complete(struct ieee80211_hw *hw)
3701{
3702 struct ath10k *ar = hw->priv;
3703
3704 mutex_lock(&ar->conf_mutex);
3705
3706 /* If device failed to restart it will be in a different state, e.g.
3707 * ATH10K_STATE_WEDGED */
3708 if (ar->state == ATH10K_STATE_RESTARTED) {
3709 ath10k_info("device successfully recovered\n");
3710 ar->state = ATH10K_STATE_ON;
3711 }
3712
3713 mutex_unlock(&ar->conf_mutex);
3714}
3715
2e1dea40
MK
3716static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
3717 struct survey_info *survey)
3718{
3719 struct ath10k *ar = hw->priv;
3720 struct ieee80211_supported_band *sband;
3721 struct survey_info *ar_survey = &ar->survey[idx];
3722 int ret = 0;
3723
3724 mutex_lock(&ar->conf_mutex);
3725
3726 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
3727 if (sband && idx >= sband->n_channels) {
3728 idx -= sband->n_channels;
3729 sband = NULL;
3730 }
3731
3732 if (!sband)
3733 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
3734
3735 if (!sband || idx >= sband->n_channels) {
3736 ret = -ENOENT;
3737 goto exit;
3738 }
3739
3740 spin_lock_bh(&ar->data_lock);
3741 memcpy(survey, ar_survey, sizeof(*survey));
3742 spin_unlock_bh(&ar->data_lock);
3743
3744 survey->channel = &sband->channels[idx];
3745
3746exit:
3747 mutex_unlock(&ar->conf_mutex);
3748 return ret;
3749}
3750
51ab1a0a
JD
3751/* Helper table for legacy fixed_rate/bitrate_mask */
3752static const u8 cck_ofdm_rate[] = {
3753 /* CCK */
3754 3, /* 1Mbps */
3755 2, /* 2Mbps */
3756 1, /* 5.5Mbps */
3757 0, /* 11Mbps */
3758 /* OFDM */
3759 3, /* 6Mbps */
3760 7, /* 9Mbps */
3761 2, /* 12Mbps */
3762 6, /* 18Mbps */
3763 1, /* 24Mbps */
3764 5, /* 36Mbps */
3765 0, /* 48Mbps */
3766 4, /* 54Mbps */
3767};
3768
3769/* Check if only one bit set */
3770static int ath10k_check_single_mask(u32 mask)
3771{
3772 int bit;
3773
3774 bit = ffs(mask);
3775 if (!bit)
3776 return 0;
3777
3778 mask &= ~BIT(bit - 1);
3779 if (mask)
3780 return 2;
3781
3782 return 1;
3783}
3784
3785static bool
3786ath10k_default_bitrate_mask(struct ath10k *ar,
3787 enum ieee80211_band band,
3788 const struct cfg80211_bitrate_mask *mask)
3789{
3790 u32 legacy = 0x00ff;
3791 u8 ht = 0xff, i;
3792 u16 vht = 0x3ff;
3793
3794 switch (band) {
3795 case IEEE80211_BAND_2GHZ:
3796 legacy = 0x00fff;
3797 vht = 0;
3798 break;
3799 case IEEE80211_BAND_5GHZ:
3800 break;
3801 default:
3802 return false;
3803 }
3804
3805 if (mask->control[band].legacy != legacy)
3806 return false;
3807
3808 for (i = 0; i < ar->num_rf_chains; i++)
3809 if (mask->control[band].ht_mcs[i] != ht)
3810 return false;
3811
3812 for (i = 0; i < ar->num_rf_chains; i++)
3813 if (mask->control[band].vht_mcs[i] != vht)
3814 return false;
3815
3816 return true;
3817}
3818
3819static bool
3820ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
3821 enum ieee80211_band band,
3822 u8 *fixed_nss)
3823{
3824 int ht_nss = 0, vht_nss = 0, i;
3825
3826 /* check legacy */
3827 if (ath10k_check_single_mask(mask->control[band].legacy))
3828 return false;
3829
3830 /* check HT */
3831 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
3832 if (mask->control[band].ht_mcs[i] == 0xff)
3833 continue;
3834 else if (mask->control[band].ht_mcs[i] == 0x00)
3835 break;
3836 else
3837 return false;
3838 }
3839
3840 ht_nss = i;
3841
3842 /* check VHT */
3843 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
3844 if (mask->control[band].vht_mcs[i] == 0x03ff)
3845 continue;
3846 else if (mask->control[band].vht_mcs[i] == 0x0000)
3847 break;
3848 else
3849 return false;
3850 }
3851
3852 vht_nss = i;
3853
3854 if (ht_nss > 0 && vht_nss > 0)
3855 return false;
3856
3857 if (ht_nss)
3858 *fixed_nss = ht_nss;
3859 else if (vht_nss)
3860 *fixed_nss = vht_nss;
3861 else
3862 return false;
3863
3864 return true;
3865}
3866
3867static bool
3868ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
3869 enum ieee80211_band band,
3870 enum wmi_rate_preamble *preamble)
3871{
3872 int legacy = 0, ht = 0, vht = 0, i;
3873
3874 *preamble = WMI_RATE_PREAMBLE_OFDM;
3875
3876 /* check legacy */
3877 legacy = ath10k_check_single_mask(mask->control[band].legacy);
3878 if (legacy > 1)
3879 return false;
3880
3881 /* check HT */
3882 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
3883 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
3884 if (ht > 1)
3885 return false;
3886
3887 /* check VHT */
3888 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
3889 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
3890 if (vht > 1)
3891 return false;
3892
3893 /* Currently we support only one fixed_rate */
3894 if ((legacy + ht + vht) != 1)
3895 return false;
3896
3897 if (ht)
3898 *preamble = WMI_RATE_PREAMBLE_HT;
3899 else if (vht)
3900 *preamble = WMI_RATE_PREAMBLE_VHT;
3901
3902 return true;
3903}
3904
3905static bool
3906ath10k_bitrate_mask_rate(const struct cfg80211_bitrate_mask *mask,
3907 enum ieee80211_band band,
3908 u8 *fixed_rate,
3909 u8 *fixed_nss)
3910{
3911 u8 rate = 0, pream = 0, nss = 0, i;
3912 enum wmi_rate_preamble preamble;
3913
3914 /* Check if single rate correct */
3915 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
3916 return false;
3917
3918 pream = preamble;
3919
3920 switch (preamble) {
3921 case WMI_RATE_PREAMBLE_CCK:
3922 case WMI_RATE_PREAMBLE_OFDM:
3923 i = ffs(mask->control[band].legacy) - 1;
3924
3925 if (band == IEEE80211_BAND_2GHZ && i < 4)
3926 pream = WMI_RATE_PREAMBLE_CCK;
3927
3928 if (band == IEEE80211_BAND_5GHZ)
3929 i += 4;
3930
3931 if (i >= ARRAY_SIZE(cck_ofdm_rate))
3932 return false;
3933
3934 rate = cck_ofdm_rate[i];
3935 break;
3936 case WMI_RATE_PREAMBLE_HT:
3937 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
3938 if (mask->control[band].ht_mcs[i])
3939 break;
3940
3941 if (i == IEEE80211_HT_MCS_MASK_LEN)
3942 return false;
3943
3944 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
3945 nss = i;
3946 break;
3947 case WMI_RATE_PREAMBLE_VHT:
3948 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
3949 if (mask->control[band].vht_mcs[i])
3950 break;
3951
3952 if (i == NL80211_VHT_NSS_MAX)
3953 return false;
3954
3955 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
3956 nss = i;
3957 break;
3958 }
3959
3960 *fixed_nss = nss + 1;
3961 nss <<= 4;
3962 pream <<= 6;
3963
3964 ath10k_dbg(ATH10K_DBG_MAC, "mac fixed rate pream 0x%02x nss 0x%02x rate 0x%02x\n",
3965 pream, nss, rate);
3966
3967 *fixed_rate = pream | nss | rate;
3968
3969 return true;
3970}
3971
3972static bool ath10k_get_fixed_rate_nss(const struct cfg80211_bitrate_mask *mask,
3973 enum ieee80211_band band,
3974 u8 *fixed_rate,
3975 u8 *fixed_nss)
3976{
3977 /* First check full NSS mask, if we can simply limit NSS */
3978 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
3979 return true;
3980
3981 /* Next Check single rate is set */
3982 return ath10k_bitrate_mask_rate(mask, band, fixed_rate, fixed_nss);
3983}
3984
3985static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
3986 u8 fixed_rate,
9f81f725
JD
3987 u8 fixed_nss,
3988 u8 force_sgi)
51ab1a0a
JD
3989{
3990 struct ath10k *ar = arvif->ar;
3991 u32 vdev_param;
3992 int ret = 0;
3993
3994 mutex_lock(&ar->conf_mutex);
3995
3996 if (arvif->fixed_rate == fixed_rate &&
9f81f725
JD
3997 arvif->fixed_nss == fixed_nss &&
3998 arvif->force_sgi == force_sgi)
51ab1a0a
JD
3999 goto exit;
4000
4001 if (fixed_rate == WMI_FIXED_RATE_NONE)
4002 ath10k_dbg(ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
4003
9f81f725
JD
4004 if (force_sgi)
4005 ath10k_dbg(ATH10K_DBG_MAC, "mac force sgi\n");
4006
51ab1a0a
JD
4007 vdev_param = ar->wmi.vdev_param->fixed_rate;
4008 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4009 vdev_param, fixed_rate);
4010 if (ret) {
4011 ath10k_warn("Could not set fixed_rate param 0x%02x: %d\n",
4012 fixed_rate, ret);
4013 ret = -EINVAL;
4014 goto exit;
4015 }
4016
4017 arvif->fixed_rate = fixed_rate;
4018
4019 vdev_param = ar->wmi.vdev_param->nss;
4020 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4021 vdev_param, fixed_nss);
4022
4023 if (ret) {
4024 ath10k_warn("Could not set fixed_nss param %d: %d\n",
4025 fixed_nss, ret);
4026 ret = -EINVAL;
4027 goto exit;
4028 }
4029
4030 arvif->fixed_nss = fixed_nss;
4031
9f81f725
JD
4032 vdev_param = ar->wmi.vdev_param->sgi;
4033 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4034 force_sgi);
4035
4036 if (ret) {
4037 ath10k_warn("Could not set sgi param %d: %d\n",
4038 force_sgi, ret);
4039 ret = -EINVAL;
4040 goto exit;
4041 }
4042
4043 arvif->force_sgi = force_sgi;
4044
51ab1a0a
JD
4045exit:
4046 mutex_unlock(&ar->conf_mutex);
4047 return ret;
4048}
4049
4050static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
4051 struct ieee80211_vif *vif,
4052 const struct cfg80211_bitrate_mask *mask)
4053{
4054 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4055 struct ath10k *ar = arvif->ar;
4056 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
4057 u8 fixed_rate = WMI_FIXED_RATE_NONE;
4058 u8 fixed_nss = ar->num_rf_chains;
9f81f725
JD
4059 u8 force_sgi;
4060
4061 force_sgi = mask->control[band].gi;
4062 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
4063 return -EINVAL;
51ab1a0a
JD
4064
4065 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
4066 if (!ath10k_get_fixed_rate_nss(mask, band,
4067 &fixed_rate,
4068 &fixed_nss))
4069 return -EINVAL;
4070 }
4071
9f81f725
JD
4072 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
4073 ath10k_warn("Could not force SGI usage for default rate settings\n");
4074 return -EINVAL;
4075 }
4076
4077 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
4078 fixed_nss, force_sgi);
51ab1a0a
JD
4079}
4080
c2df44b3
MK
4081static void ath10k_channel_switch_beacon(struct ieee80211_hw *hw,
4082 struct ieee80211_vif *vif,
4083 struct cfg80211_chan_def *chandef)
4084{
4085 /* there's no need to do anything here. vif->csa_active is enough */
4086 return;
4087}
4088
9797febc
MK
4089static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
4090 struct ieee80211_vif *vif,
4091 struct ieee80211_sta *sta,
4092 u32 changed)
4093{
4094 struct ath10k *ar = hw->priv;
4095 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
4096 u32 bw, smps;
4097
4098 spin_lock_bh(&ar->data_lock);
4099
4100 ath10k_dbg(ATH10K_DBG_MAC,
4101 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
4102 sta->addr, changed, sta->bandwidth, sta->rx_nss,
4103 sta->smps_mode);
4104
4105 if (changed & IEEE80211_RC_BW_CHANGED) {
4106 bw = WMI_PEER_CHWIDTH_20MHZ;
4107
4108 switch (sta->bandwidth) {
4109 case IEEE80211_STA_RX_BW_20:
4110 bw = WMI_PEER_CHWIDTH_20MHZ;
4111 break;
4112 case IEEE80211_STA_RX_BW_40:
4113 bw = WMI_PEER_CHWIDTH_40MHZ;
4114 break;
4115 case IEEE80211_STA_RX_BW_80:
4116 bw = WMI_PEER_CHWIDTH_80MHZ;
4117 break;
4118 case IEEE80211_STA_RX_BW_160:
4119 ath10k_warn("mac sta rc update for %pM: invalid bw %d\n",
4120 sta->addr, sta->bandwidth);
4121 bw = WMI_PEER_CHWIDTH_20MHZ;
4122 break;
4123 }
4124
4125 arsta->bw = bw;
4126 }
4127
4128 if (changed & IEEE80211_RC_NSS_CHANGED)
4129 arsta->nss = sta->rx_nss;
4130
4131 if (changed & IEEE80211_RC_SMPS_CHANGED) {
4132 smps = WMI_PEER_SMPS_PS_NONE;
4133
4134 switch (sta->smps_mode) {
4135 case IEEE80211_SMPS_AUTOMATIC:
4136 case IEEE80211_SMPS_OFF:
4137 smps = WMI_PEER_SMPS_PS_NONE;
4138 break;
4139 case IEEE80211_SMPS_STATIC:
4140 smps = WMI_PEER_SMPS_STATIC;
4141 break;
4142 case IEEE80211_SMPS_DYNAMIC:
4143 smps = WMI_PEER_SMPS_DYNAMIC;
4144 break;
4145 case IEEE80211_SMPS_NUM_MODES:
4146 ath10k_warn("mac sta rc update for %pM: invalid smps: %d\n",
4147 sta->addr, sta->smps_mode);
4148 smps = WMI_PEER_SMPS_PS_NONE;
4149 break;
4150 }
4151
4152 arsta->smps = smps;
4153 }
4154
9797febc
MK
4155 arsta->changed |= changed;
4156
4157 spin_unlock_bh(&ar->data_lock);
4158
4159 ieee80211_queue_work(hw, &arsta->update_wk);
4160}
4161
26ebbccf
CYY
4162static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
4163{
4164 /*
4165 * FIXME: Return 0 for time being. Need to figure out whether FW
4166 * has the API to fetch 64-bit local TSF
4167 */
4168
4169 return 0;
4170}
4171
5e3dd157
KV
4172static const struct ieee80211_ops ath10k_ops = {
4173 .tx = ath10k_tx,
4174 .start = ath10k_start,
4175 .stop = ath10k_stop,
4176 .config = ath10k_config,
4177 .add_interface = ath10k_add_interface,
4178 .remove_interface = ath10k_remove_interface,
4179 .configure_filter = ath10k_configure_filter,
4180 .bss_info_changed = ath10k_bss_info_changed,
4181 .hw_scan = ath10k_hw_scan,
4182 .cancel_hw_scan = ath10k_cancel_hw_scan,
4183 .set_key = ath10k_set_key,
4184 .sta_state = ath10k_sta_state,
4185 .conf_tx = ath10k_conf_tx,
4186 .remain_on_channel = ath10k_remain_on_channel,
4187 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
4188 .set_rts_threshold = ath10k_set_rts_threshold,
4189 .set_frag_threshold = ath10k_set_frag_threshold,
4190 .flush = ath10k_flush,
4191 .tx_last_beacon = ath10k_tx_last_beacon,
affd3217 4192 .restart_complete = ath10k_restart_complete,
2e1dea40 4193 .get_survey = ath10k_get_survey,
51ab1a0a 4194 .set_bitrate_mask = ath10k_set_bitrate_mask,
c2df44b3 4195 .channel_switch_beacon = ath10k_channel_switch_beacon,
9797febc 4196 .sta_rc_update = ath10k_sta_rc_update,
26ebbccf 4197 .get_tsf = ath10k_get_tsf,
8cd13cad
MK
4198#ifdef CONFIG_PM
4199 .suspend = ath10k_suspend,
4200 .resume = ath10k_resume,
4201#endif
5e3dd157
KV
4202};
4203
4204#define RATETAB_ENT(_rate, _rateid, _flags) { \
4205 .bitrate = (_rate), \
4206 .flags = (_flags), \
4207 .hw_value = (_rateid), \
4208}
4209
4210#define CHAN2G(_channel, _freq, _flags) { \
4211 .band = IEEE80211_BAND_2GHZ, \
4212 .hw_value = (_channel), \
4213 .center_freq = (_freq), \
4214 .flags = (_flags), \
4215 .max_antenna_gain = 0, \
4216 .max_power = 30, \
4217}
4218
4219#define CHAN5G(_channel, _freq, _flags) { \
4220 .band = IEEE80211_BAND_5GHZ, \
4221 .hw_value = (_channel), \
4222 .center_freq = (_freq), \
4223 .flags = (_flags), \
4224 .max_antenna_gain = 0, \
4225 .max_power = 30, \
4226}
4227
4228static const struct ieee80211_channel ath10k_2ghz_channels[] = {
4229 CHAN2G(1, 2412, 0),
4230 CHAN2G(2, 2417, 0),
4231 CHAN2G(3, 2422, 0),
4232 CHAN2G(4, 2427, 0),
4233 CHAN2G(5, 2432, 0),
4234 CHAN2G(6, 2437, 0),
4235 CHAN2G(7, 2442, 0),
4236 CHAN2G(8, 2447, 0),
4237 CHAN2G(9, 2452, 0),
4238 CHAN2G(10, 2457, 0),
4239 CHAN2G(11, 2462, 0),
4240 CHAN2G(12, 2467, 0),
4241 CHAN2G(13, 2472, 0),
4242 CHAN2G(14, 2484, 0),
4243};
4244
4245static const struct ieee80211_channel ath10k_5ghz_channels[] = {
429ff56a
MK
4246 CHAN5G(36, 5180, 0),
4247 CHAN5G(40, 5200, 0),
4248 CHAN5G(44, 5220, 0),
4249 CHAN5G(48, 5240, 0),
4250 CHAN5G(52, 5260, 0),
4251 CHAN5G(56, 5280, 0),
4252 CHAN5G(60, 5300, 0),
4253 CHAN5G(64, 5320, 0),
4254 CHAN5G(100, 5500, 0),
4255 CHAN5G(104, 5520, 0),
4256 CHAN5G(108, 5540, 0),
4257 CHAN5G(112, 5560, 0),
4258 CHAN5G(116, 5580, 0),
4259 CHAN5G(120, 5600, 0),
4260 CHAN5G(124, 5620, 0),
4261 CHAN5G(128, 5640, 0),
4262 CHAN5G(132, 5660, 0),
4263 CHAN5G(136, 5680, 0),
4264 CHAN5G(140, 5700, 0),
4265 CHAN5G(149, 5745, 0),
4266 CHAN5G(153, 5765, 0),
4267 CHAN5G(157, 5785, 0),
4268 CHAN5G(161, 5805, 0),
4269 CHAN5G(165, 5825, 0),
5e3dd157
KV
4270};
4271
4272static struct ieee80211_rate ath10k_rates[] = {
4273 /* CCK */
4274 RATETAB_ENT(10, 0x82, 0),
4275 RATETAB_ENT(20, 0x84, 0),
4276 RATETAB_ENT(55, 0x8b, 0),
4277 RATETAB_ENT(110, 0x96, 0),
4278 /* OFDM */
4279 RATETAB_ENT(60, 0x0c, 0),
4280 RATETAB_ENT(90, 0x12, 0),
4281 RATETAB_ENT(120, 0x18, 0),
4282 RATETAB_ENT(180, 0x24, 0),
4283 RATETAB_ENT(240, 0x30, 0),
4284 RATETAB_ENT(360, 0x48, 0),
4285 RATETAB_ENT(480, 0x60, 0),
4286 RATETAB_ENT(540, 0x6c, 0),
4287};
4288
4289#define ath10k_a_rates (ath10k_rates + 4)
4290#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
4291#define ath10k_g_rates (ath10k_rates + 0)
4292#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
4293
4294struct ath10k *ath10k_mac_create(void)
4295{
4296 struct ieee80211_hw *hw;
4297 struct ath10k *ar;
4298
4299 hw = ieee80211_alloc_hw(sizeof(struct ath10k), &ath10k_ops);
4300 if (!hw)
4301 return NULL;
4302
4303 ar = hw->priv;
4304 ar->hw = hw;
4305
4306 return ar;
4307}
4308
4309void ath10k_mac_destroy(struct ath10k *ar)
4310{
4311 ieee80211_free_hw(ar->hw);
4312}
4313
4314static const struct ieee80211_iface_limit ath10k_if_limits[] = {
4315 {
4316 .max = 8,
4317 .types = BIT(NL80211_IFTYPE_STATION)
4318 | BIT(NL80211_IFTYPE_P2P_CLIENT)
d531cb85
MK
4319 },
4320 {
4321 .max = 3,
4322 .types = BIT(NL80211_IFTYPE_P2P_GO)
4323 },
4324 {
4325 .max = 7,
4326 .types = BIT(NL80211_IFTYPE_AP)
4327 },
5e3dd157
KV
4328};
4329
f259509b 4330static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
e8a50f8b
MP
4331 {
4332 .max = 8,
4333 .types = BIT(NL80211_IFTYPE_AP)
4334 },
4335};
e8a50f8b
MP
4336
4337static const struct ieee80211_iface_combination ath10k_if_comb[] = {
4338 {
4339 .limits = ath10k_if_limits,
4340 .n_limits = ARRAY_SIZE(ath10k_if_limits),
4341 .max_interfaces = 8,
4342 .num_different_channels = 1,
4343 .beacon_int_infra_match = true,
4344 },
f259509b
BM
4345};
4346
4347static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
e8a50f8b 4348 {
f259509b
BM
4349 .limits = ath10k_10x_if_limits,
4350 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
e8a50f8b
MP
4351 .max_interfaces = 8,
4352 .num_different_channels = 1,
4353 .beacon_int_infra_match = true,
f259509b 4354#ifdef CONFIG_ATH10K_DFS_CERTIFIED
e8a50f8b
MP
4355 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
4356 BIT(NL80211_CHAN_WIDTH_20) |
4357 BIT(NL80211_CHAN_WIDTH_40) |
4358 BIT(NL80211_CHAN_WIDTH_80),
e8a50f8b 4359#endif
f259509b 4360 },
5e3dd157
KV
4361};
4362
4363static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
4364{
4365 struct ieee80211_sta_vht_cap vht_cap = {0};
4366 u16 mcs_map;
8865bee4 4367 int i;
5e3dd157
KV
4368
4369 vht_cap.vht_supported = 1;
4370 vht_cap.cap = ar->vht_cap_info;
4371
8865bee4
MK
4372 mcs_map = 0;
4373 for (i = 0; i < 8; i++) {
4374 if (i < ar->num_rf_chains)
4375 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
4376 else
4377 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
4378 }
5e3dd157
KV
4379
4380 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
4381 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
4382
4383 return vht_cap;
4384}
4385
4386static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
4387{
4388 int i;
4389 struct ieee80211_sta_ht_cap ht_cap = {0};
4390
4391 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
4392 return ht_cap;
4393
4394 ht_cap.ht_supported = 1;
4395 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
4396 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
4397 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
4398 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
4399 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
4400
4401 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
4402 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
4403
4404 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
4405 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
4406
4407 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
4408 u32 smps;
4409
4410 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
4411 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
4412
4413 ht_cap.cap |= smps;
4414 }
4415
4416 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
4417 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
4418
4419 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
4420 u32 stbc;
4421
4422 stbc = ar->ht_cap_info;
4423 stbc &= WMI_HT_CAP_RX_STBC;
4424 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
4425 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
4426 stbc &= IEEE80211_HT_CAP_RX_STBC;
4427
4428 ht_cap.cap |= stbc;
4429 }
4430
4431 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
4432 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
4433
4434 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
4435 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
4436
4437 /* max AMSDU is implicitly taken from vht_cap_info */
4438 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
4439 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
4440
8865bee4 4441 for (i = 0; i < ar->num_rf_chains; i++)
5e3dd157
KV
4442 ht_cap.mcs.rx_mask[i] = 0xFF;
4443
4444 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
4445
4446 return ht_cap;
4447}
4448
4449
4450static void ath10k_get_arvif_iter(void *data, u8 *mac,
4451 struct ieee80211_vif *vif)
4452{
4453 struct ath10k_vif_iter *arvif_iter = data;
4454 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4455
4456 if (arvif->vdev_id == arvif_iter->vdev_id)
4457 arvif_iter->arvif = arvif;
4458}
4459
4460struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
4461{
4462 struct ath10k_vif_iter arvif_iter;
4463 u32 flags;
4464
4465 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
4466 arvif_iter.vdev_id = vdev_id;
4467
4468 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
4469 ieee80211_iterate_active_interfaces_atomic(ar->hw,
4470 flags,
4471 ath10k_get_arvif_iter,
4472 &arvif_iter);
4473 if (!arvif_iter.arvif) {
69244e56 4474 ath10k_warn("No VIF found for vdev %d\n", vdev_id);
5e3dd157
KV
4475 return NULL;
4476 }
4477
4478 return arvif_iter.arvif;
4479}
4480
4481int ath10k_mac_register(struct ath10k *ar)
4482{
4483 struct ieee80211_supported_band *band;
4484 struct ieee80211_sta_vht_cap vht_cap;
4485 struct ieee80211_sta_ht_cap ht_cap;
4486 void *channels;
4487 int ret;
4488
4489 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
4490
4491 SET_IEEE80211_DEV(ar->hw, ar->dev);
4492
4493 ht_cap = ath10k_get_ht_cap(ar);
4494 vht_cap = ath10k_create_vht_cap(ar);
4495
4496 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
4497 channels = kmemdup(ath10k_2ghz_channels,
4498 sizeof(ath10k_2ghz_channels),
4499 GFP_KERNEL);
d6015b27
MK
4500 if (!channels) {
4501 ret = -ENOMEM;
4502 goto err_free;
4503 }
5e3dd157
KV
4504
4505 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
4506 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
4507 band->channels = channels;
4508 band->n_bitrates = ath10k_g_rates_size;
4509 band->bitrates = ath10k_g_rates;
4510 band->ht_cap = ht_cap;
4511
4512 /* vht is not supported in 2.4 GHz */
4513
4514 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
4515 }
4516
4517 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
4518 channels = kmemdup(ath10k_5ghz_channels,
4519 sizeof(ath10k_5ghz_channels),
4520 GFP_KERNEL);
4521 if (!channels) {
d6015b27
MK
4522 ret = -ENOMEM;
4523 goto err_free;
5e3dd157
KV
4524 }
4525
4526 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
4527 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
4528 band->channels = channels;
4529 band->n_bitrates = ath10k_a_rates_size;
4530 band->bitrates = ath10k_a_rates;
4531 band->ht_cap = ht_cap;
4532 band->vht_cap = vht_cap;
4533 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
4534 }
4535
4536 ar->hw->wiphy->interface_modes =
4537 BIT(NL80211_IFTYPE_STATION) |
4538 BIT(NL80211_IFTYPE_ADHOC) |
d354181f
BM
4539 BIT(NL80211_IFTYPE_AP);
4540
4541 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
4542 ar->hw->wiphy->interface_modes |=
4543 BIT(NL80211_IFTYPE_P2P_CLIENT) |
4544 BIT(NL80211_IFTYPE_P2P_GO);
5e3dd157
KV
4545
4546 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
4547 IEEE80211_HW_SUPPORTS_PS |
4548 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
4549 IEEE80211_HW_SUPPORTS_UAPSD |
4550 IEEE80211_HW_MFP_CAPABLE |
4551 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
4552 IEEE80211_HW_HAS_RATE_CONTROL |
4553 IEEE80211_HW_SUPPORTS_STATIC_SMPS |
4554 IEEE80211_HW_WANT_MONITOR_VIF |
2f0f1121
JD
4555 IEEE80211_HW_AP_LINK_PS |
4556 IEEE80211_HW_SPECTRUM_MGMT;
5e3dd157 4557
1f8bb151
MK
4558 /* MSDU can have HTT TX fragment pushed in front. The additional 4
4559 * bytes is used for padding/alignment if necessary. */
4560 ar->hw->extra_tx_headroom += sizeof(struct htt_data_tx_desc_frag)*2 + 4;
4561
5e3dd157
KV
4562 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
4563 ar->hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS;
4564
4565 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
4566 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
4567 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
4568 }
4569
4570 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
4571 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
4572
4573 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
9797febc 4574 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
5e3dd157 4575
5e3dd157
KV
4576 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
4577
4578 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
c2df44b3 4579 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
5e3dd157
KV
4580 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
4581
4582 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
4583 /*
4584 * on LL hardware queues are managed entirely by the FW
4585 * so we only advertise to mac we can do the queues thing
4586 */
4587 ar->hw->queues = 4;
4588
f259509b
BM
4589 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
4590 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
4591 ar->hw->wiphy->n_iface_combinations =
4592 ARRAY_SIZE(ath10k_10x_if_comb);
4593 } else {
4594 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
4595 ar->hw->wiphy->n_iface_combinations =
4596 ARRAY_SIZE(ath10k_if_comb);
4597 }
5e3dd157 4598
7c199997
MK
4599 ar->hw->netdev_features = NETIF_F_HW_CSUM;
4600
9702c686
JD
4601 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
4602 /* Init ath dfs pattern detector */
4603 ar->ath_common.debug_mask = ATH_DBG_DFS;
4604 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
4605 NL80211_DFS_UNSET);
4606
4607 if (!ar->dfs_detector)
4608 ath10k_warn("dfs pattern detector init failed\n");
4609 }
4610
5e3dd157
KV
4611 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
4612 ath10k_reg_notifier);
4613 if (ret) {
69244e56 4614 ath10k_err("Regulatory initialization failed: %i\n", ret);
d6015b27 4615 goto err_free;
5e3dd157
KV
4616 }
4617
4618 ret = ieee80211_register_hw(ar->hw);
4619 if (ret) {
4620 ath10k_err("ieee80211 registration failed: %d\n", ret);
d6015b27 4621 goto err_free;
5e3dd157
KV
4622 }
4623
4624 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
4625 ret = regulatory_hint(ar->hw->wiphy,
4626 ar->ath_common.regulatory.alpha2);
4627 if (ret)
d6015b27 4628 goto err_unregister;
5e3dd157
KV
4629 }
4630
4631 return 0;
d6015b27
MK
4632
4633err_unregister:
5e3dd157 4634 ieee80211_unregister_hw(ar->hw);
d6015b27
MK
4635err_free:
4636 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
4637 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
4638
5e3dd157
KV
4639 return ret;
4640}
4641
4642void ath10k_mac_unregister(struct ath10k *ar)
4643{
4644 ieee80211_unregister_hw(ar->hw);
4645
9702c686
JD
4646 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
4647 ar->dfs_detector->exit(ar->dfs_detector);
4648
5e3dd157
KV
4649 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
4650 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
4651
4652 SET_IEEE80211_DEV(ar->hw, NULL);
4653}
This page took 0.378538 seconds and 5 git commands to generate.