blob: 200752750181ffdb87f49819f5b6e8caea84f338 [file] [log] [blame]
Kalle Valo5e3dd152013-06-12 20:52:10 +03001/*
2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include "mac.h"
19
20#include <net/mac80211.h>
21#include <linux/etherdevice.h>
22
Michal Kazior8cd13ca2013-07-16 09:38:54 +020023#include "hif.h"
Kalle Valo5e3dd152013-06-12 20:52:10 +030024#include "core.h"
25#include "debug.h"
26#include "wmi.h"
27#include "htt.h"
28#include "txrx.h"
Kalle Valo43d2a302014-09-10 18:23:30 +030029#include "testmode.h"
Michal Kaziord7579d12014-12-03 10:10:54 +020030#include "wmi.h"
31#include "wmi-ops.h"
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +020032#include "wow.h"
Kalle Valo5e3dd152013-06-12 20:52:10 +030033
Michal Kaziordcc33092015-03-30 09:51:54 +030034/*********/
35/* Rates */
36/*********/
37
Michal Kaziordcc33092015-03-30 09:51:54 +030038static struct ieee80211_rate ath10k_rates[] = {
Michal Kazior5528e032015-03-30 09:51:56 +030039 { .bitrate = 10,
40 .hw_value = ATH10K_HW_RATE_CCK_LP_1M },
41 { .bitrate = 20,
42 .hw_value = ATH10K_HW_RATE_CCK_LP_2M,
43 .hw_value_short = ATH10K_HW_RATE_CCK_SP_2M,
44 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
45 { .bitrate = 55,
46 .hw_value = ATH10K_HW_RATE_CCK_LP_5_5M,
47 .hw_value_short = ATH10K_HW_RATE_CCK_SP_5_5M,
48 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
49 { .bitrate = 110,
50 .hw_value = ATH10K_HW_RATE_CCK_LP_11M,
51 .hw_value_short = ATH10K_HW_RATE_CCK_SP_11M,
52 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
Michal Kazior5653b392015-03-30 09:51:54 +030053
Michal Kazioraf001482015-03-30 09:51:56 +030054 { .bitrate = 60, .hw_value = ATH10K_HW_RATE_OFDM_6M },
55 { .bitrate = 90, .hw_value = ATH10K_HW_RATE_OFDM_9M },
56 { .bitrate = 120, .hw_value = ATH10K_HW_RATE_OFDM_12M },
57 { .bitrate = 180, .hw_value = ATH10K_HW_RATE_OFDM_18M },
58 { .bitrate = 240, .hw_value = ATH10K_HW_RATE_OFDM_24M },
59 { .bitrate = 360, .hw_value = ATH10K_HW_RATE_OFDM_36M },
60 { .bitrate = 480, .hw_value = ATH10K_HW_RATE_OFDM_48M },
61 { .bitrate = 540, .hw_value = ATH10K_HW_RATE_OFDM_54M },
Michal Kaziordcc33092015-03-30 09:51:54 +030062};
63
Michal Kazior8d7aa6b2015-03-30 09:51:57 +030064#define ATH10K_MAC_FIRST_OFDM_RATE_IDX 4
65
66#define ath10k_a_rates (ath10k_rates + ATH10K_MAC_FIRST_OFDM_RATE_IDX)
67#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - \
68 ATH10K_MAC_FIRST_OFDM_RATE_IDX)
Michal Kaziordcc33092015-03-30 09:51:54 +030069#define ath10k_g_rates (ath10k_rates + 0)
70#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
71
Michal Kazior486017c2015-03-30 09:51:54 +030072static bool ath10k_mac_bitrate_is_cck(int bitrate)
73{
74 switch (bitrate) {
75 case 10:
76 case 20:
77 case 55:
78 case 110:
79 return true;
80 }
81
82 return false;
83}
84
85static u8 ath10k_mac_bitrate_to_rate(int bitrate)
86{
87 return DIV_ROUND_UP(bitrate, 5) |
88 (ath10k_mac_bitrate_is_cck(bitrate) ? BIT(7) : 0);
89}
90
Michal Kazior5528e032015-03-30 09:51:56 +030091u8 ath10k_mac_hw_rate_to_idx(const struct ieee80211_supported_band *sband,
92 u8 hw_rate)
93{
94 const struct ieee80211_rate *rate;
95 int i;
96
97 for (i = 0; i < sband->n_bitrates; i++) {
98 rate = &sband->bitrates[i];
99
100 if (rate->hw_value == hw_rate)
101 return i;
102 else if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE &&
103 rate->hw_value_short == hw_rate)
104 return i;
105 }
106
107 return 0;
108}
109
Michal Kazior01cebe12015-03-30 09:51:56 +0300110u8 ath10k_mac_bitrate_to_idx(const struct ieee80211_supported_band *sband,
111 u32 bitrate)
112{
113 int i;
114
115 for (i = 0; i < sband->n_bitrates; i++)
116 if (sband->bitrates[i].bitrate == bitrate)
117 return i;
118
119 return 0;
120}
121
Kalle Valo5e3dd152013-06-12 20:52:10 +0300122/**********/
123/* Crypto */
124/**********/
125
126static int ath10k_send_key(struct ath10k_vif *arvif,
127 struct ieee80211_key_conf *key,
128 enum set_key_cmd cmd,
Michal Kazior370e5672015-02-18 14:02:26 +0100129 const u8 *macaddr, u32 flags)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300130{
Michal Kazior7aa7a722014-08-25 12:09:38 +0200131 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300132 struct wmi_vdev_install_key_arg arg = {
133 .vdev_id = arvif->vdev_id,
134 .key_idx = key->keyidx,
135 .key_len = key->keylen,
136 .key_data = key->key,
Michal Kazior370e5672015-02-18 14:02:26 +0100137 .key_flags = flags,
Kalle Valo5e3dd152013-06-12 20:52:10 +0300138 .macaddr = macaddr,
139 };
140
Michal Kazior548db542013-07-05 16:15:15 +0300141 lockdep_assert_held(&arvif->ar->conf_mutex);
142
Kalle Valo5e3dd152013-06-12 20:52:10 +0300143 switch (key->cipher) {
144 case WLAN_CIPHER_SUITE_CCMP:
145 arg.key_cipher = WMI_CIPHER_AES_CCM;
Marek Kwaczynskie4e82e92015-01-24 12:14:53 +0200146 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300147 break;
148 case WLAN_CIPHER_SUITE_TKIP:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300149 arg.key_cipher = WMI_CIPHER_TKIP;
150 arg.key_txmic_len = 8;
151 arg.key_rxmic_len = 8;
152 break;
153 case WLAN_CIPHER_SUITE_WEP40:
154 case WLAN_CIPHER_SUITE_WEP104:
155 arg.key_cipher = WMI_CIPHER_WEP;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300156 break;
Johannes Berg3cb10942015-01-22 21:38:45 +0100157 case WLAN_CIPHER_SUITE_AES_CMAC:
Bartosz Markowskid7131c02015-03-10 14:32:19 +0100158 WARN_ON(1);
159 return -EINVAL;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300160 default:
Michal Kazior7aa7a722014-08-25 12:09:38 +0200161 ath10k_warn(ar, "cipher %d is not supported\n", key->cipher);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300162 return -EOPNOTSUPP;
163 }
164
165 if (cmd == DISABLE_KEY) {
166 arg.key_cipher = WMI_CIPHER_NONE;
167 arg.key_data = NULL;
168 }
169
170 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
171}
172
173static int ath10k_install_key(struct ath10k_vif *arvif,
174 struct ieee80211_key_conf *key,
175 enum set_key_cmd cmd,
Michal Kazior370e5672015-02-18 14:02:26 +0100176 const u8 *macaddr, u32 flags)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300177{
178 struct ath10k *ar = arvif->ar;
179 int ret;
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +0300180 unsigned long time_left;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300181
Michal Kazior548db542013-07-05 16:15:15 +0300182 lockdep_assert_held(&ar->conf_mutex);
183
Wolfram Sang16735d02013-11-14 14:32:02 -0800184 reinit_completion(&ar->install_key_done);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300185
Michal Kazior370e5672015-02-18 14:02:26 +0100186 ret = ath10k_send_key(arvif, key, cmd, macaddr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300187 if (ret)
188 return ret;
189
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +0300190 time_left = wait_for_completion_timeout(&ar->install_key_done, 3 * HZ);
191 if (time_left == 0)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300192 return -ETIMEDOUT;
193
194 return 0;
195}
196
197static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
198 const u8 *addr)
199{
200 struct ath10k *ar = arvif->ar;
201 struct ath10k_peer *peer;
202 int ret;
203 int i;
Michal Kazior370e5672015-02-18 14:02:26 +0100204 u32 flags;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300205
206 lockdep_assert_held(&ar->conf_mutex);
207
208 spin_lock_bh(&ar->data_lock);
209 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
210 spin_unlock_bh(&ar->data_lock);
211
212 if (!peer)
213 return -ENOENT;
214
215 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
216 if (arvif->wep_keys[i] == NULL)
217 continue;
Michal Kazior370e5672015-02-18 14:02:26 +0100218
219 flags = 0;
220 flags |= WMI_KEY_PAIRWISE;
221
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200222 /* set TX_USAGE flag for default key id */
223 if (arvif->def_wep_key_idx == i)
Michal Kazior370e5672015-02-18 14:02:26 +0100224 flags |= WMI_KEY_TX_USAGE;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300225
226 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
Michal Kazior370e5672015-02-18 14:02:26 +0100227 addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300228 if (ret)
229 return ret;
230
Sujith Manoharanae167132014-11-25 11:46:59 +0530231 spin_lock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300232 peer->keys[i] = arvif->wep_keys[i];
Sujith Manoharanae167132014-11-25 11:46:59 +0530233 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300234 }
235
236 return 0;
237}
238
239static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
240 const u8 *addr)
241{
242 struct ath10k *ar = arvif->ar;
243 struct ath10k_peer *peer;
244 int first_errno = 0;
245 int ret;
246 int i;
Michal Kazior370e5672015-02-18 14:02:26 +0100247 u32 flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300248
249 lockdep_assert_held(&ar->conf_mutex);
250
251 spin_lock_bh(&ar->data_lock);
252 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
253 spin_unlock_bh(&ar->data_lock);
254
255 if (!peer)
256 return -ENOENT;
257
258 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
259 if (peer->keys[i] == NULL)
260 continue;
261
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200262 /* key flags are not required to delete the key */
Kalle Valo5e3dd152013-06-12 20:52:10 +0300263 ret = ath10k_install_key(arvif, peer->keys[i],
Michal Kazior370e5672015-02-18 14:02:26 +0100264 DISABLE_KEY, addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300265 if (ret && first_errno == 0)
266 first_errno = ret;
267
268 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200269 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300270 i, ret);
271
Sujith Manoharanae167132014-11-25 11:46:59 +0530272 spin_lock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300273 peer->keys[i] = NULL;
Sujith Manoharanae167132014-11-25 11:46:59 +0530274 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300275 }
276
277 return first_errno;
278}
279
Sujith Manoharan504f6cd2014-11-25 11:46:58 +0530280bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr,
281 u8 keyidx)
282{
283 struct ath10k_peer *peer;
284 int i;
285
286 lockdep_assert_held(&ar->data_lock);
287
288 /* We don't know which vdev this peer belongs to,
289 * since WMI doesn't give us that information.
290 *
291 * FIXME: multi-bss needs to be handled.
292 */
293 peer = ath10k_peer_find(ar, 0, addr);
294 if (!peer)
295 return false;
296
297 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
298 if (peer->keys[i] && peer->keys[i]->keyidx == keyidx)
299 return true;
300 }
301
302 return false;
303}
304
Kalle Valo5e3dd152013-06-12 20:52:10 +0300305static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
306 struct ieee80211_key_conf *key)
307{
308 struct ath10k *ar = arvif->ar;
309 struct ath10k_peer *peer;
310 u8 addr[ETH_ALEN];
311 int first_errno = 0;
312 int ret;
313 int i;
Michal Kazior370e5672015-02-18 14:02:26 +0100314 u32 flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300315
316 lockdep_assert_held(&ar->conf_mutex);
317
318 for (;;) {
319 /* since ath10k_install_key we can't hold data_lock all the
320 * time, so we try to remove the keys incrementally */
321 spin_lock_bh(&ar->data_lock);
322 i = 0;
323 list_for_each_entry(peer, &ar->peers, list) {
324 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
325 if (peer->keys[i] == key) {
Kalle Valob25f32c2014-09-14 12:50:49 +0300326 ether_addr_copy(addr, peer->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300327 peer->keys[i] = NULL;
328 break;
329 }
330 }
331
332 if (i < ARRAY_SIZE(peer->keys))
333 break;
334 }
335 spin_unlock_bh(&ar->data_lock);
336
337 if (i == ARRAY_SIZE(peer->keys))
338 break;
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200339 /* key flags are not required to delete the key */
Michal Kazior370e5672015-02-18 14:02:26 +0100340 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300341 if (ret && first_errno == 0)
342 first_errno = ret;
343
344 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200345 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +0200346 addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300347 }
348
349 return first_errno;
350}
351
Michal Kazior370e5672015-02-18 14:02:26 +0100352static int ath10k_mac_vif_sta_fix_wep_key(struct ath10k_vif *arvif)
353{
354 struct ath10k *ar = arvif->ar;
355 enum nl80211_iftype iftype = arvif->vif->type;
356 struct ieee80211_key_conf *key;
357 u32 flags = 0;
358 int num = 0;
359 int i;
360 int ret;
361
362 lockdep_assert_held(&ar->conf_mutex);
363
364 if (iftype != NL80211_IFTYPE_STATION)
365 return 0;
366
367 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
368 if (arvif->wep_keys[i]) {
369 key = arvif->wep_keys[i];
370 ++num;
371 }
372 }
373
374 if (num != 1)
375 return 0;
376
377 flags |= WMI_KEY_PAIRWISE;
378 flags |= WMI_KEY_TX_USAGE;
379
380 ret = ath10k_install_key(arvif, key, SET_KEY, arvif->bssid, flags);
381 if (ret) {
382 ath10k_warn(ar, "failed to install key %i on vdev %i: %d\n",
383 key->keyidx, arvif->vdev_id, ret);
384 return ret;
385 }
386
387 return 0;
388}
389
Michal Kaziorad325cb2015-02-18 14:02:27 +0100390static int ath10k_mac_vif_update_wep_key(struct ath10k_vif *arvif,
391 struct ieee80211_key_conf *key)
392{
393 struct ath10k *ar = arvif->ar;
394 struct ath10k_peer *peer;
395 int ret;
396
397 lockdep_assert_held(&ar->conf_mutex);
398
399 list_for_each_entry(peer, &ar->peers, list) {
400 if (!memcmp(peer->addr, arvif->vif->addr, ETH_ALEN))
401 continue;
402
403 if (!memcmp(peer->addr, arvif->bssid, ETH_ALEN))
404 continue;
405
406 if (peer->keys[key->keyidx] == key)
407 continue;
408
409 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vif vdev %i update key %i needs update\n",
410 arvif->vdev_id, key->keyidx);
411
412 ret = ath10k_install_peer_wep_keys(arvif, peer->addr);
413 if (ret) {
414 ath10k_warn(ar, "failed to update wep keys on vdev %i for peer %pM: %d\n",
415 arvif->vdev_id, peer->addr, ret);
416 return ret;
417 }
418 }
419
420 return 0;
421}
422
Kalle Valo5e3dd152013-06-12 20:52:10 +0300423/*********************/
424/* General utilities */
425/*********************/
426
427static inline enum wmi_phy_mode
428chan_to_phymode(const struct cfg80211_chan_def *chandef)
429{
430 enum wmi_phy_mode phymode = MODE_UNKNOWN;
431
432 switch (chandef->chan->band) {
433 case IEEE80211_BAND_2GHZ:
434 switch (chandef->width) {
435 case NL80211_CHAN_WIDTH_20_NOHT:
Peter Oh6faab122014-12-18 10:13:00 -0800436 if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM)
437 phymode = MODE_11B;
438 else
439 phymode = MODE_11G;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300440 break;
441 case NL80211_CHAN_WIDTH_20:
442 phymode = MODE_11NG_HT20;
443 break;
444 case NL80211_CHAN_WIDTH_40:
445 phymode = MODE_11NG_HT40;
446 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400447 case NL80211_CHAN_WIDTH_5:
448 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300449 case NL80211_CHAN_WIDTH_80:
450 case NL80211_CHAN_WIDTH_80P80:
451 case NL80211_CHAN_WIDTH_160:
452 phymode = MODE_UNKNOWN;
453 break;
454 }
455 break;
456 case IEEE80211_BAND_5GHZ:
457 switch (chandef->width) {
458 case NL80211_CHAN_WIDTH_20_NOHT:
459 phymode = MODE_11A;
460 break;
461 case NL80211_CHAN_WIDTH_20:
462 phymode = MODE_11NA_HT20;
463 break;
464 case NL80211_CHAN_WIDTH_40:
465 phymode = MODE_11NA_HT40;
466 break;
467 case NL80211_CHAN_WIDTH_80:
468 phymode = MODE_11AC_VHT80;
469 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400470 case NL80211_CHAN_WIDTH_5:
471 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300472 case NL80211_CHAN_WIDTH_80P80:
473 case NL80211_CHAN_WIDTH_160:
474 phymode = MODE_UNKNOWN;
475 break;
476 }
477 break;
478 default:
479 break;
480 }
481
482 WARN_ON(phymode == MODE_UNKNOWN);
483 return phymode;
484}
485
486static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
487{
488/*
489 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
490 * 0 for no restriction
491 * 1 for 1/4 us
492 * 2 for 1/2 us
493 * 3 for 1 us
494 * 4 for 2 us
495 * 5 for 4 us
496 * 6 for 8 us
497 * 7 for 16 us
498 */
499 switch (mpdudensity) {
500 case 0:
501 return 0;
502 case 1:
503 case 2:
504 case 3:
505 /* Our lower layer calculations limit our precision to
506 1 microsecond */
507 return 1;
508 case 4:
509 return 2;
510 case 5:
511 return 4;
512 case 6:
513 return 8;
514 case 7:
515 return 16;
516 default:
517 return 0;
518 }
519}
520
Michal Kazior500ff9f2015-03-31 10:26:21 +0000521int ath10k_mac_vif_chan(struct ieee80211_vif *vif,
522 struct cfg80211_chan_def *def)
523{
524 struct ieee80211_chanctx_conf *conf;
525
526 rcu_read_lock();
527 conf = rcu_dereference(vif->chanctx_conf);
528 if (!conf) {
529 rcu_read_unlock();
530 return -ENOENT;
531 }
532
533 *def = conf->def;
534 rcu_read_unlock();
535
536 return 0;
537}
538
539static void ath10k_mac_num_chanctxs_iter(struct ieee80211_hw *hw,
540 struct ieee80211_chanctx_conf *conf,
541 void *data)
542{
543 int *num = data;
544
545 (*num)++;
546}
547
548static int ath10k_mac_num_chanctxs(struct ath10k *ar)
549{
550 int num = 0;
551
552 ieee80211_iter_chan_contexts_atomic(ar->hw,
553 ath10k_mac_num_chanctxs_iter,
554 &num);
555
556 return num;
557}
558
559static void
560ath10k_mac_get_any_chandef_iter(struct ieee80211_hw *hw,
561 struct ieee80211_chanctx_conf *conf,
562 void *data)
563{
564 struct cfg80211_chan_def **def = data;
565
566 *def = &conf->def;
567}
568
Marek Puzyniak7390ed32015-03-30 09:51:52 +0300569static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr,
570 enum wmi_peer_type peer_type)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300571{
572 int ret;
573
574 lockdep_assert_held(&ar->conf_mutex);
575
Michal Kaziorcfd10612014-11-25 15:16:05 +0100576 if (ar->num_peers >= ar->max_num_peers)
577 return -ENOBUFS;
578
Marek Puzyniak7390ed32015-03-30 09:51:52 +0300579 ret = ath10k_wmi_peer_create(ar, vdev_id, addr, peer_type);
Ben Greear479398b2013-11-04 09:19:34 -0800580 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200581 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200582 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300583 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800584 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300585
586 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800587 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200588 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200589 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300590 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800591 }
Michal Kazior292a7532014-11-25 15:16:04 +0100592
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100593 ar->num_peers++;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300594
595 return 0;
596}
597
Kalle Valo5a13e762014-01-20 11:01:46 +0200598static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
599{
600 struct ath10k *ar = arvif->ar;
601 u32 param;
602 int ret;
603
604 param = ar->wmi.pdev_param->sta_kickout_th;
605 ret = ath10k_wmi_pdev_set_param(ar, param,
606 ATH10K_KICKOUT_THRESHOLD);
607 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200608 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200609 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200610 return ret;
611 }
612
613 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
614 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
615 ATH10K_KEEPALIVE_MIN_IDLE);
616 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200617 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200618 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200619 return ret;
620 }
621
622 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
623 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
624 ATH10K_KEEPALIVE_MAX_IDLE);
625 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200626 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200627 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200628 return ret;
629 }
630
631 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
632 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
633 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
634 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200635 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200636 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200637 return ret;
638 }
639
640 return 0;
641}
642
Vivek Natarajanacab6402014-11-26 09:06:12 +0200643static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
Michal Kazior424121c2013-07-22 14:13:31 +0200644{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200645 struct ath10k *ar = arvif->ar;
646 u32 vdev_param;
647
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200648 vdev_param = ar->wmi.vdev_param->rts_threshold;
649 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200650}
651
652static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
653{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200654 struct ath10k *ar = arvif->ar;
655 u32 vdev_param;
656
Michal Kazior424121c2013-07-22 14:13:31 +0200657 if (value != 0xFFFFFFFF)
658 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
659 ATH10K_FRAGMT_THRESHOLD_MIN,
660 ATH10K_FRAGMT_THRESHOLD_MAX);
661
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200662 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
663 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200664}
665
Kalle Valo5e3dd152013-06-12 20:52:10 +0300666static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
667{
668 int ret;
669
670 lockdep_assert_held(&ar->conf_mutex);
671
672 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
673 if (ret)
674 return ret;
675
676 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
677 if (ret)
678 return ret;
679
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100680 ar->num_peers--;
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100681
Kalle Valo5e3dd152013-06-12 20:52:10 +0300682 return 0;
683}
684
685static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
686{
687 struct ath10k_peer *peer, *tmp;
688
689 lockdep_assert_held(&ar->conf_mutex);
690
691 spin_lock_bh(&ar->data_lock);
692 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
693 if (peer->vdev_id != vdev_id)
694 continue;
695
Michal Kazior7aa7a722014-08-25 12:09:38 +0200696 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300697 peer->addr, vdev_id);
698
699 list_del(&peer->list);
700 kfree(peer);
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100701 ar->num_peers--;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300702 }
703 spin_unlock_bh(&ar->data_lock);
704}
705
Michal Kaziora96d7742013-07-16 09:38:56 +0200706static void ath10k_peer_cleanup_all(struct ath10k *ar)
707{
708 struct ath10k_peer *peer, *tmp;
709
710 lockdep_assert_held(&ar->conf_mutex);
711
712 spin_lock_bh(&ar->data_lock);
713 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
714 list_del(&peer->list);
715 kfree(peer);
716 }
717 spin_unlock_bh(&ar->data_lock);
Michal Kazior292a7532014-11-25 15:16:04 +0100718
719 ar->num_peers = 0;
Michal Kaziorcfd10612014-11-25 15:16:05 +0100720 ar->num_stations = 0;
Michal Kaziora96d7742013-07-16 09:38:56 +0200721}
722
Marek Puzyniak75d85fd2015-03-30 09:51:53 +0300723static int ath10k_mac_tdls_peer_update(struct ath10k *ar, u32 vdev_id,
724 struct ieee80211_sta *sta,
725 enum wmi_tdls_peer_state state)
726{
727 int ret;
728 struct wmi_tdls_peer_update_cmd_arg arg = {};
729 struct wmi_tdls_peer_capab_arg cap = {};
730 struct wmi_channel_arg chan_arg = {};
731
732 lockdep_assert_held(&ar->conf_mutex);
733
734 arg.vdev_id = vdev_id;
735 arg.peer_state = state;
736 ether_addr_copy(arg.addr, sta->addr);
737
738 cap.peer_max_sp = sta->max_sp;
739 cap.peer_uapsd_queues = sta->uapsd_queues;
740
741 if (state == WMI_TDLS_PEER_STATE_CONNECTED &&
742 !sta->tdls_initiator)
743 cap.is_peer_responder = 1;
744
745 ret = ath10k_wmi_tdls_peer_update(ar, &arg, &cap, &chan_arg);
746 if (ret) {
747 ath10k_warn(ar, "failed to update tdls peer %pM on vdev %i: %i\n",
748 arg.addr, vdev_id, ret);
749 return ret;
750 }
751
752 return 0;
753}
754
Kalle Valo5e3dd152013-06-12 20:52:10 +0300755/************************/
756/* Interface management */
757/************************/
758
Michal Kazior64badcb2014-09-18 11:18:02 +0300759void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
760{
761 struct ath10k *ar = arvif->ar;
762
763 lockdep_assert_held(&ar->data_lock);
764
765 if (!arvif->beacon)
766 return;
767
768 if (!arvif->beacon_buf)
769 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
770 arvif->beacon->len, DMA_TO_DEVICE);
771
Michal Kazioraf213192015-01-29 14:29:52 +0200772 if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED &&
773 arvif->beacon_state != ATH10K_BEACON_SENT))
774 return;
775
Michal Kazior64badcb2014-09-18 11:18:02 +0300776 dev_kfree_skb_any(arvif->beacon);
777
778 arvif->beacon = NULL;
Michal Kazioraf213192015-01-29 14:29:52 +0200779 arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
Michal Kazior64badcb2014-09-18 11:18:02 +0300780}
781
782static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
783{
784 struct ath10k *ar = arvif->ar;
785
786 lockdep_assert_held(&ar->data_lock);
787
788 ath10k_mac_vif_beacon_free(arvif);
789
790 if (arvif->beacon_buf) {
791 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
792 arvif->beacon_buf, arvif->beacon_paddr);
793 arvif->beacon_buf = NULL;
794 }
795}
796
Kalle Valo5e3dd152013-06-12 20:52:10 +0300797static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
798{
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +0300799 unsigned long time_left;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300800
Michal Kazior548db542013-07-05 16:15:15 +0300801 lockdep_assert_held(&ar->conf_mutex);
802
Michal Kazior7962b0d2014-10-28 10:34:38 +0100803 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
804 return -ESHUTDOWN;
805
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +0300806 time_left = wait_for_completion_timeout(&ar->vdev_setup_done,
807 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
808 if (time_left == 0)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300809 return -ETIMEDOUT;
810
811 return 0;
812}
813
Michal Kazior1bbc0972014-04-08 09:45:47 +0300814static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300815{
Michal Kazior500ff9f2015-03-31 10:26:21 +0000816 struct cfg80211_chan_def *chandef = NULL;
Michal Kaziorc930f742014-01-23 11:38:25 +0100817 struct ieee80211_channel *channel = chandef->chan;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300818 struct wmi_vdev_start_request_arg arg = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +0300819 int ret = 0;
820
821 lockdep_assert_held(&ar->conf_mutex);
822
Michal Kazior500ff9f2015-03-31 10:26:21 +0000823 ieee80211_iter_chan_contexts_atomic(ar->hw,
824 ath10k_mac_get_any_chandef_iter,
825 &chandef);
826 if (WARN_ON_ONCE(!chandef))
827 return -ENOENT;
828
829 channel = chandef->chan;
830
Kalle Valo5e3dd152013-06-12 20:52:10 +0300831 arg.vdev_id = vdev_id;
832 arg.channel.freq = channel->center_freq;
Michal Kaziorc930f742014-01-23 11:38:25 +0100833 arg.channel.band_center_freq1 = chandef->center_freq1;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300834
835 /* TODO setup this dynamically, what in case we
836 don't have any vifs? */
Michal Kaziorc930f742014-01-23 11:38:25 +0100837 arg.channel.mode = chan_to_phymode(chandef);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200838 arg.channel.chan_radar =
839 !!(channel->flags & IEEE80211_CHAN_RADAR);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300840
Michal Kazior89c5c842013-10-23 04:02:13 -0700841 arg.channel.min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -0700842 arg.channel.max_power = channel->max_power * 2;
843 arg.channel.max_reg_power = channel->max_reg_power * 2;
844 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300845
Michal Kazior7962b0d2014-10-28 10:34:38 +0100846 reinit_completion(&ar->vdev_setup_done);
847
Kalle Valo5e3dd152013-06-12 20:52:10 +0300848 ret = ath10k_wmi_vdev_start(ar, &arg);
849 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200850 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200851 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300852 return ret;
853 }
854
855 ret = ath10k_vdev_setup_sync(ar);
856 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +0200857 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200858 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300859 return ret;
860 }
861
862 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
863 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200864 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200865 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300866 goto vdev_stop;
867 }
868
869 ar->monitor_vdev_id = vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300870
Michal Kazior7aa7a722014-08-25 12:09:38 +0200871 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300872 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300873 return 0;
874
875vdev_stop:
876 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
877 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200878 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200879 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300880
881 return ret;
882}
883
Michal Kazior1bbc0972014-04-08 09:45:47 +0300884static int ath10k_monitor_vdev_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300885{
886 int ret = 0;
887
888 lockdep_assert_held(&ar->conf_mutex);
889
Marek Puzyniak52fa0192013-09-24 14:06:24 +0200890 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
891 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200892 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200893 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300894
Michal Kazior7962b0d2014-10-28 10:34:38 +0100895 reinit_completion(&ar->vdev_setup_done);
896
Kalle Valo5e3dd152013-06-12 20:52:10 +0300897 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
898 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200899 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200900 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300901
902 ret = ath10k_vdev_setup_sync(ar);
903 if (ret)
Ben Greear60028a82015-02-15 16:50:39 +0200904 ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200905 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300906
Michal Kazior7aa7a722014-08-25 12:09:38 +0200907 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300908 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300909 return ret;
910}
911
Michal Kazior1bbc0972014-04-08 09:45:47 +0300912static int ath10k_monitor_vdev_create(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300913{
914 int bit, ret = 0;
915
916 lockdep_assert_held(&ar->conf_mutex);
917
Ben Greeara9aefb32014-08-12 11:02:19 +0300918 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200919 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +0300920 return -ENOMEM;
921 }
922
Ben Greear16c11172014-09-23 14:17:16 -0700923 bit = __ffs64(ar->free_vdev_map);
Ben Greeara9aefb32014-08-12 11:02:19 +0300924
Ben Greear16c11172014-09-23 14:17:16 -0700925 ar->monitor_vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300926
927 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
928 WMI_VDEV_TYPE_MONITOR,
929 0, ar->mac_addr);
930 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200931 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200932 ar->monitor_vdev_id, ret);
Ben Greeara9aefb32014-08-12 11:02:19 +0300933 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300934 }
935
Ben Greear16c11172014-09-23 14:17:16 -0700936 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
Michal Kazior7aa7a722014-08-25 12:09:38 +0200937 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300938 ar->monitor_vdev_id);
939
Kalle Valo5e3dd152013-06-12 20:52:10 +0300940 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300941}
942
Michal Kazior1bbc0972014-04-08 09:45:47 +0300943static int ath10k_monitor_vdev_delete(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300944{
945 int ret = 0;
946
947 lockdep_assert_held(&ar->conf_mutex);
948
Kalle Valo5e3dd152013-06-12 20:52:10 +0300949 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
950 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200951 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200952 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300953 return ret;
954 }
955
Ben Greear16c11172014-09-23 14:17:16 -0700956 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300957
Michal Kazior7aa7a722014-08-25 12:09:38 +0200958 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300959 ar->monitor_vdev_id);
960 return ret;
961}
962
Michal Kazior1bbc0972014-04-08 09:45:47 +0300963static int ath10k_monitor_start(struct ath10k *ar)
964{
965 int ret;
966
967 lockdep_assert_held(&ar->conf_mutex);
968
Michal Kazior1bbc0972014-04-08 09:45:47 +0300969 ret = ath10k_monitor_vdev_create(ar);
970 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200971 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300972 return ret;
973 }
974
975 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
976 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200977 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300978 ath10k_monitor_vdev_delete(ar);
979 return ret;
980 }
981
982 ar->monitor_started = true;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200983 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
Michal Kazior1bbc0972014-04-08 09:45:47 +0300984
985 return 0;
986}
987
Michal Kazior19337472014-08-28 12:58:16 +0200988static int ath10k_monitor_stop(struct ath10k *ar)
Michal Kazior1bbc0972014-04-08 09:45:47 +0300989{
990 int ret;
991
992 lockdep_assert_held(&ar->conf_mutex);
993
Michal Kazior1bbc0972014-04-08 09:45:47 +0300994 ret = ath10k_monitor_vdev_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200995 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200996 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +0200997 return ret;
998 }
Michal Kazior1bbc0972014-04-08 09:45:47 +0300999
1000 ret = ath10k_monitor_vdev_delete(ar);
Michal Kazior19337472014-08-28 12:58:16 +02001001 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001002 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +02001003 return ret;
1004 }
Michal Kazior1bbc0972014-04-08 09:45:47 +03001005
1006 ar->monitor_started = false;
Michal Kazior7aa7a722014-08-25 12:09:38 +02001007 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
Michal Kazior19337472014-08-28 12:58:16 +02001008
1009 return 0;
1010}
1011
Vasanthakumar Thiagarajan54846212015-03-02 17:45:28 +05301012static bool ath10k_mac_should_disable_promisc(struct ath10k *ar)
1013{
1014 struct ath10k_vif *arvif;
1015
1016 if (!(ar->filter_flags & FIF_PROMISC_IN_BSS))
1017 return true;
1018
1019 if (!ar->num_started_vdevs)
1020 return false;
1021
1022 list_for_each_entry(arvif, &ar->arvifs, list)
1023 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1024 return false;
1025
1026 ath10k_dbg(ar, ATH10K_DBG_MAC,
1027 "mac disabling promiscuous mode because vdev is started\n");
1028 return true;
1029}
1030
Michal Kazior500ff9f2015-03-31 10:26:21 +00001031static bool ath10k_mac_monitor_vdev_is_needed(struct ath10k *ar)
1032{
1033 int num_ctx;
1034
1035 /* At least one chanctx is required to derive a channel to start
1036 * monitor vdev on.
1037 */
1038 num_ctx = ath10k_mac_num_chanctxs(ar);
1039 if (num_ctx == 0)
1040 return false;
1041
1042 /* If there's already an existing special monitor interface then don't
1043 * bother creating another monitor vdev.
1044 */
1045 if (ar->monitor_arvif)
1046 return false;
1047
1048 return ar->monitor ||
1049 !ath10k_mac_should_disable_promisc(ar) ||
1050 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1051}
1052
1053static bool ath10k_mac_monitor_vdev_is_allowed(struct ath10k *ar)
1054{
1055 int num_ctx;
1056
1057 num_ctx = ath10k_mac_num_chanctxs(ar);
1058
1059 /* FIXME: Current interface combinations and cfg80211/mac80211 code
1060 * shouldn't allow this but make sure to prevent handling the following
1061 * case anyway since multi-channel DFS hasn't been tested at all.
1062 */
1063 if (test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags) && num_ctx > 1)
1064 return false;
1065
1066 return true;
1067}
1068
Michal Kazior19337472014-08-28 12:58:16 +02001069static int ath10k_monitor_recalc(struct ath10k *ar)
1070{
Michal Kazior500ff9f2015-03-31 10:26:21 +00001071 bool needed;
1072 bool allowed;
1073 int ret;
Michal Kazior19337472014-08-28 12:58:16 +02001074
1075 lockdep_assert_held(&ar->conf_mutex);
1076
Michal Kazior500ff9f2015-03-31 10:26:21 +00001077 needed = ath10k_mac_monitor_vdev_is_needed(ar);
1078 allowed = ath10k_mac_monitor_vdev_is_allowed(ar);
Michal Kazior19337472014-08-28 12:58:16 +02001079
1080 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior500ff9f2015-03-31 10:26:21 +00001081 "mac monitor recalc started? %d needed? %d allowed? %d\n",
1082 ar->monitor_started, needed, allowed);
Michal Kazior19337472014-08-28 12:58:16 +02001083
Michal Kazior500ff9f2015-03-31 10:26:21 +00001084 if (WARN_ON(needed && !allowed)) {
1085 if (ar->monitor_started) {
1086 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopping disallowed monitor\n");
1087
1088 ret = ath10k_monitor_stop(ar);
1089 if (ret)
1090 ath10k_warn(ar, "failed to stop disallowed monitor: %d\n", ret);
1091 /* not serious */
1092 }
1093
1094 return -EPERM;
1095 }
1096
1097 if (needed == ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02001098 return 0;
1099
Michal Kazior500ff9f2015-03-31 10:26:21 +00001100 if (needed)
Michal Kazior19337472014-08-28 12:58:16 +02001101 return ath10k_monitor_start(ar);
Michal Kazior500ff9f2015-03-31 10:26:21 +00001102 else
1103 return ath10k_monitor_stop(ar);
Michal Kazior1bbc0972014-04-08 09:45:47 +03001104}
1105
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001106static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
1107{
1108 struct ath10k *ar = arvif->ar;
1109 u32 vdev_param, rts_cts = 0;
1110
1111 lockdep_assert_held(&ar->conf_mutex);
1112
1113 vdev_param = ar->wmi.vdev_param->enable_rtscts;
1114
Rajkumar Manoharan9a5ab0f2015-03-19 16:03:29 +02001115 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001116
1117 if (arvif->num_legacy_stations > 0)
1118 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
1119 WMI_RTSCTS_PROFILE);
Rajkumar Manoharan9a5ab0f2015-03-19 16:03:29 +02001120 else
1121 rts_cts |= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES,
1122 WMI_RTSCTS_PROFILE);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001123
1124 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
1125 rts_cts);
1126}
1127
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001128static int ath10k_start_cac(struct ath10k *ar)
1129{
1130 int ret;
1131
1132 lockdep_assert_held(&ar->conf_mutex);
1133
1134 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1135
Michal Kazior19337472014-08-28 12:58:16 +02001136 ret = ath10k_monitor_recalc(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001137 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001138 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001139 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1140 return ret;
1141 }
1142
Michal Kazior7aa7a722014-08-25 12:09:38 +02001143 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001144 ar->monitor_vdev_id);
1145
1146 return 0;
1147}
1148
1149static int ath10k_stop_cac(struct ath10k *ar)
1150{
1151 lockdep_assert_held(&ar->conf_mutex);
1152
1153 /* CAC is not running - do nothing */
1154 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
1155 return 0;
1156
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001157 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
Michal Kazior1bbc0972014-04-08 09:45:47 +03001158 ath10k_monitor_stop(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001159
Michal Kazior7aa7a722014-08-25 12:09:38 +02001160 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001161
1162 return 0;
1163}
1164
Michal Kazior500ff9f2015-03-31 10:26:21 +00001165static void ath10k_mac_has_radar_iter(struct ieee80211_hw *hw,
1166 struct ieee80211_chanctx_conf *conf,
1167 void *data)
1168{
1169 bool *ret = data;
1170
1171 if (!*ret && conf->radar_enabled)
1172 *ret = true;
1173}
1174
1175static bool ath10k_mac_has_radar_enabled(struct ath10k *ar)
1176{
1177 bool has_radar = false;
1178
1179 ieee80211_iter_chan_contexts_atomic(ar->hw,
1180 ath10k_mac_has_radar_iter,
1181 &has_radar);
1182
1183 return has_radar;
1184}
1185
Michal Kaziord6500972014-04-08 09:56:09 +03001186static void ath10k_recalc_radar_detection(struct ath10k *ar)
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001187{
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001188 int ret;
1189
1190 lockdep_assert_held(&ar->conf_mutex);
1191
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001192 ath10k_stop_cac(ar);
1193
Michal Kazior500ff9f2015-03-31 10:26:21 +00001194 if (!ath10k_mac_has_radar_enabled(ar))
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001195 return;
1196
Michal Kaziord6500972014-04-08 09:56:09 +03001197 if (ar->num_started_vdevs > 0)
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001198 return;
1199
1200 ret = ath10k_start_cac(ar);
1201 if (ret) {
1202 /*
1203 * Not possible to start CAC on current channel so starting
1204 * radiation is not allowed, make this channel DFS_UNAVAILABLE
1205 * by indicating that radar was detected.
1206 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02001207 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001208 ieee80211_radar_detected(ar->hw);
1209 }
1210}
1211
Vasanthakumar Thiagarajan822b7e02015-03-02 17:45:27 +05301212static int ath10k_vdev_stop(struct ath10k_vif *arvif)
1213{
1214 struct ath10k *ar = arvif->ar;
1215 int ret;
1216
1217 lockdep_assert_held(&ar->conf_mutex);
1218
1219 reinit_completion(&ar->vdev_setup_done);
1220
1221 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
1222 if (ret) {
1223 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
1224 arvif->vdev_id, ret);
1225 return ret;
1226 }
1227
1228 ret = ath10k_vdev_setup_sync(ar);
1229 if (ret) {
1230 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
1231 arvif->vdev_id, ret);
1232 return ret;
1233 }
1234
1235 WARN_ON(ar->num_started_vdevs == 0);
1236
1237 if (ar->num_started_vdevs != 0) {
1238 ar->num_started_vdevs--;
1239 ath10k_recalc_radar_detection(ar);
1240 }
1241
1242 return ret;
1243}
1244
Michal Kazior500ff9f2015-03-31 10:26:21 +00001245static int ath10k_vdev_start_restart(struct ath10k_vif *arvif,
1246 const struct cfg80211_chan_def *chandef,
1247 bool restart)
Michal Kazior72654fa2014-04-08 09:56:09 +03001248{
1249 struct ath10k *ar = arvif->ar;
Michal Kazior72654fa2014-04-08 09:56:09 +03001250 struct wmi_vdev_start_request_arg arg = {};
Vasanthakumar Thiagarajan54846212015-03-02 17:45:28 +05301251 int ret = 0, ret2;
Michal Kazior72654fa2014-04-08 09:56:09 +03001252
1253 lockdep_assert_held(&ar->conf_mutex);
1254
1255 reinit_completion(&ar->vdev_setup_done);
1256
1257 arg.vdev_id = arvif->vdev_id;
1258 arg.dtim_period = arvif->dtim_period;
1259 arg.bcn_intval = arvif->beacon_interval;
1260
1261 arg.channel.freq = chandef->chan->center_freq;
1262 arg.channel.band_center_freq1 = chandef->center_freq1;
1263 arg.channel.mode = chan_to_phymode(chandef);
1264
1265 arg.channel.min_power = 0;
1266 arg.channel.max_power = chandef->chan->max_power * 2;
1267 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
1268 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
1269
1270 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1271 arg.ssid = arvif->u.ap.ssid;
1272 arg.ssid_len = arvif->u.ap.ssid_len;
1273 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
1274
1275 /* For now allow DFS for AP mode */
1276 arg.channel.chan_radar =
1277 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
1278 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
1279 arg.ssid = arvif->vif->bss_conf.ssid;
1280 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
1281 }
1282
Michal Kazior7aa7a722014-08-25 12:09:38 +02001283 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior72654fa2014-04-08 09:56:09 +03001284 "mac vdev %d start center_freq %d phymode %s\n",
1285 arg.vdev_id, arg.channel.freq,
1286 ath10k_wmi_phymode_str(arg.channel.mode));
1287
Michal Kaziordc55e302014-07-29 12:53:36 +03001288 if (restart)
1289 ret = ath10k_wmi_vdev_restart(ar, &arg);
1290 else
1291 ret = ath10k_wmi_vdev_start(ar, &arg);
1292
Michal Kazior72654fa2014-04-08 09:56:09 +03001293 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001294 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +03001295 arg.vdev_id, ret);
1296 return ret;
1297 }
1298
1299 ret = ath10k_vdev_setup_sync(ar);
1300 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +02001301 ath10k_warn(ar,
1302 "failed to synchronize setup for vdev %i restart %d: %d\n",
1303 arg.vdev_id, restart, ret);
Michal Kazior72654fa2014-04-08 09:56:09 +03001304 return ret;
1305 }
1306
Michal Kaziord6500972014-04-08 09:56:09 +03001307 ar->num_started_vdevs++;
1308 ath10k_recalc_radar_detection(ar);
1309
Vasanthakumar Thiagarajan54846212015-03-02 17:45:28 +05301310 ret = ath10k_monitor_recalc(ar);
1311 if (ret) {
1312 ath10k_warn(ar, "mac failed to recalc monitor for vdev %i restart %d: %d\n",
1313 arg.vdev_id, restart, ret);
1314 ret2 = ath10k_vdev_stop(arvif);
1315 if (ret2)
1316 ath10k_warn(ar, "mac failed to stop vdev %i restart %d: %d\n",
1317 arg.vdev_id, restart, ret2);
1318 }
1319
Michal Kazior72654fa2014-04-08 09:56:09 +03001320 return ret;
1321}
1322
Michal Kazior500ff9f2015-03-31 10:26:21 +00001323static int ath10k_vdev_start(struct ath10k_vif *arvif,
1324 const struct cfg80211_chan_def *def)
Michal Kaziordc55e302014-07-29 12:53:36 +03001325{
Michal Kazior500ff9f2015-03-31 10:26:21 +00001326 return ath10k_vdev_start_restart(arvif, def, false);
Michal Kaziordc55e302014-07-29 12:53:36 +03001327}
1328
Michal Kazior500ff9f2015-03-31 10:26:21 +00001329static int ath10k_vdev_restart(struct ath10k_vif *arvif,
1330 const struct cfg80211_chan_def *def)
Michal Kaziordc55e302014-07-29 12:53:36 +03001331{
Michal Kazior500ff9f2015-03-31 10:26:21 +00001332 return ath10k_vdev_start_restart(arvif, def, true);
Michal Kaziordc55e302014-07-29 12:53:36 +03001333}
1334
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001335static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
1336 struct sk_buff *bcn)
1337{
1338 struct ath10k *ar = arvif->ar;
1339 struct ieee80211_mgmt *mgmt;
1340 const u8 *p2p_ie;
1341 int ret;
1342
1343 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1344 return 0;
1345
1346 if (arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1347 return 0;
1348
1349 mgmt = (void *)bcn->data;
1350 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1351 mgmt->u.beacon.variable,
1352 bcn->len - (mgmt->u.beacon.variable -
1353 bcn->data));
1354 if (!p2p_ie)
1355 return -ENOENT;
1356
1357 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1358 if (ret) {
1359 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1360 arvif->vdev_id, ret);
1361 return ret;
1362 }
1363
1364 return 0;
1365}
1366
1367static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1368 u8 oui_type, size_t ie_offset)
1369{
1370 size_t len;
1371 const u8 *next;
1372 const u8 *end;
1373 u8 *ie;
1374
1375 if (WARN_ON(skb->len < ie_offset))
1376 return -EINVAL;
1377
1378 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1379 skb->data + ie_offset,
1380 skb->len - ie_offset);
1381 if (!ie)
1382 return -ENOENT;
1383
1384 len = ie[1] + 2;
1385 end = skb->data + skb->len;
1386 next = ie + len;
1387
1388 if (WARN_ON(next > end))
1389 return -EINVAL;
1390
1391 memmove(ie, next, end - next);
1392 skb_trim(skb, skb->len - len);
1393
1394 return 0;
1395}
1396
1397static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1398{
1399 struct ath10k *ar = arvif->ar;
1400 struct ieee80211_hw *hw = ar->hw;
1401 struct ieee80211_vif *vif = arvif->vif;
1402 struct ieee80211_mutable_offsets offs = {};
1403 struct sk_buff *bcn;
1404 int ret;
1405
1406 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1407 return 0;
1408
Michal Kazior81a9a172015-03-05 16:02:17 +02001409 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
1410 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
1411 return 0;
1412
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001413 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1414 if (!bcn) {
1415 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1416 return -EPERM;
1417 }
1418
1419 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1420 if (ret) {
1421 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1422 kfree_skb(bcn);
1423 return ret;
1424 }
1425
1426 /* P2P IE is inserted by firmware automatically (as configured above)
1427 * so remove it from the base beacon template to avoid duplicate P2P
1428 * IEs in beacon frames.
1429 */
1430 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1431 offsetof(struct ieee80211_mgmt,
1432 u.beacon.variable));
1433
1434 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1435 0, NULL, 0);
1436 kfree_skb(bcn);
1437
1438 if (ret) {
1439 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1440 ret);
1441 return ret;
1442 }
1443
1444 return 0;
1445}
1446
1447static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1448{
1449 struct ath10k *ar = arvif->ar;
1450 struct ieee80211_hw *hw = ar->hw;
1451 struct ieee80211_vif *vif = arvif->vif;
1452 struct sk_buff *prb;
1453 int ret;
1454
1455 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1456 return 0;
1457
Michal Kazior81a9a172015-03-05 16:02:17 +02001458 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1459 return 0;
1460
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001461 prb = ieee80211_proberesp_get(hw, vif);
1462 if (!prb) {
1463 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1464 return -EPERM;
1465 }
1466
1467 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1468 kfree_skb(prb);
1469
1470 if (ret) {
1471 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1472 ret);
1473 return ret;
1474 }
1475
1476 return 0;
1477}
1478
Michal Kazior500ff9f2015-03-31 10:26:21 +00001479static int ath10k_mac_vif_fix_hidden_ssid(struct ath10k_vif *arvif)
1480{
1481 struct ath10k *ar = arvif->ar;
1482 struct cfg80211_chan_def def;
1483 int ret;
1484
1485 /* When originally vdev is started during assign_vif_chanctx() some
1486 * information is missing, notably SSID. Firmware revisions with beacon
1487 * offloading require the SSID to be provided during vdev (re)start to
1488 * handle hidden SSID properly.
1489 *
1490 * Vdev restart must be done after vdev has been both started and
1491 * upped. Otherwise some firmware revisions (at least 10.2) fail to
1492 * deliver vdev restart response event causing timeouts during vdev
1493 * syncing in ath10k.
1494 *
1495 * Note: The vdev down/up and template reinstallation could be skipped
1496 * since only wmi-tlv firmware are known to have beacon offload and
1497 * wmi-tlv doesn't seem to misbehave like 10.2 wrt vdev restart
1498 * response delivery. It's probably more robust to keep it as is.
1499 */
1500 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1501 return 0;
1502
1503 if (WARN_ON(!arvif->is_started))
1504 return -EINVAL;
1505
1506 if (WARN_ON(!arvif->is_up))
1507 return -EINVAL;
1508
1509 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
1510 return -EINVAL;
1511
1512 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1513 if (ret) {
1514 ath10k_warn(ar, "failed to bring down ap vdev %i: %d\n",
1515 arvif->vdev_id, ret);
1516 return ret;
1517 }
1518
1519 /* Vdev down reset beacon & presp templates. Reinstall them. Otherwise
1520 * firmware will crash upon vdev up.
1521 */
1522
1523 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1524 if (ret) {
1525 ath10k_warn(ar, "failed to update beacon template: %d\n", ret);
1526 return ret;
1527 }
1528
1529 ret = ath10k_mac_setup_prb_tmpl(arvif);
1530 if (ret) {
1531 ath10k_warn(ar, "failed to update presp template: %d\n", ret);
1532 return ret;
1533 }
1534
1535 ret = ath10k_vdev_restart(arvif, &def);
1536 if (ret) {
1537 ath10k_warn(ar, "failed to restart ap vdev %i: %d\n",
1538 arvif->vdev_id, ret);
1539 return ret;
1540 }
1541
1542 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1543 arvif->bssid);
1544 if (ret) {
1545 ath10k_warn(ar, "failed to bring up ap vdev %i: %d\n",
1546 arvif->vdev_id, ret);
1547 return ret;
1548 }
1549
1550 return 0;
1551}
1552
Kalle Valo5e3dd152013-06-12 20:52:10 +03001553static void ath10k_control_beaconing(struct ath10k_vif *arvif,
Kalle Valo5b07e072014-09-14 12:50:06 +03001554 struct ieee80211_bss_conf *info)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001555{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001556 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001557 int ret = 0;
1558
Michal Kazior548db542013-07-05 16:15:15 +03001559 lockdep_assert_held(&arvif->ar->conf_mutex);
1560
Kalle Valo5e3dd152013-06-12 20:52:10 +03001561 if (!info->enable_beacon) {
Michal Kazior500ff9f2015-03-31 10:26:21 +00001562 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1563 if (ret)
1564 ath10k_warn(ar, "failed to down vdev_id %i: %d\n",
1565 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001566
Michal Kaziorc930f742014-01-23 11:38:25 +01001567 arvif->is_up = false;
Michal Kazior8513d952015-03-09 14:19:24 +01001568
1569 spin_lock_bh(&arvif->ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03001570 ath10k_mac_vif_beacon_free(arvif);
Michal Kazior748afc42014-01-23 12:48:21 +01001571 spin_unlock_bh(&arvif->ar->data_lock);
1572
Kalle Valo5e3dd152013-06-12 20:52:10 +03001573 return;
1574 }
1575
1576 arvif->tx_seq_no = 0x1000;
1577
Michal Kaziorc930f742014-01-23 11:38:25 +01001578 arvif->aid = 0;
Kalle Valob25f32c2014-09-14 12:50:49 +03001579 ether_addr_copy(arvif->bssid, info->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01001580
1581 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1582 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001583 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001584 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001585 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001586 return;
1587 }
Michal Kaziorc930f742014-01-23 11:38:25 +01001588
Michal Kaziorc930f742014-01-23 11:38:25 +01001589 arvif->is_up = true;
1590
Michal Kazior500ff9f2015-03-31 10:26:21 +00001591 ret = ath10k_mac_vif_fix_hidden_ssid(arvif);
1592 if (ret) {
1593 ath10k_warn(ar, "failed to fix hidden ssid for vdev %i, expect trouble: %d\n",
1594 arvif->vdev_id, ret);
1595 return;
1596 }
1597
Michal Kazior7aa7a722014-08-25 12:09:38 +02001598 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001599}
1600
1601static void ath10k_control_ibss(struct ath10k_vif *arvif,
1602 struct ieee80211_bss_conf *info,
1603 const u8 self_peer[ETH_ALEN])
1604{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001605 struct ath10k *ar = arvif->ar;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001606 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001607 int ret = 0;
1608
Michal Kazior548db542013-07-05 16:15:15 +03001609 lockdep_assert_held(&arvif->ar->conf_mutex);
1610
Kalle Valo5e3dd152013-06-12 20:52:10 +03001611 if (!info->ibss_joined) {
1612 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
1613 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001614 ath10k_warn(ar, "failed to delete IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001615 self_peer, arvif->vdev_id, ret);
1616
Michal Kaziorc930f742014-01-23 11:38:25 +01001617 if (is_zero_ether_addr(arvif->bssid))
Kalle Valo5e3dd152013-06-12 20:52:10 +03001618 return;
1619
Michal Kaziorc930f742014-01-23 11:38:25 +01001620 memset(arvif->bssid, 0, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001621
1622 return;
1623 }
1624
Marek Puzyniak7390ed32015-03-30 09:51:52 +03001625 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer,
1626 WMI_PEER_TYPE_DEFAULT);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001627 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001628 ath10k_warn(ar, "failed to create IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001629 self_peer, arvif->vdev_id, ret);
1630 return;
1631 }
1632
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001633 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1634 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001635 ATH10K_DEFAULT_ATIM);
1636 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001637 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001638 arvif->vdev_id, ret);
1639}
1640
Michal Kazior9f9b5742014-12-12 12:41:36 +01001641static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1642{
1643 struct ath10k *ar = arvif->ar;
1644 u32 param;
1645 u32 value;
1646 int ret;
1647
1648 lockdep_assert_held(&arvif->ar->conf_mutex);
1649
1650 if (arvif->u.sta.uapsd)
1651 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1652 else
1653 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1654
1655 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1656 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1657 if (ret) {
1658 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1659 value, arvif->vdev_id, ret);
1660 return ret;
1661 }
1662
1663 return 0;
1664}
1665
1666static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1667{
1668 struct ath10k *ar = arvif->ar;
1669 u32 param;
1670 u32 value;
1671 int ret;
1672
1673 lockdep_assert_held(&arvif->ar->conf_mutex);
1674
1675 if (arvif->u.sta.uapsd)
1676 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1677 else
1678 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1679
1680 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1681 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1682 param, value);
1683 if (ret) {
1684 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1685 value, arvif->vdev_id, ret);
1686 return ret;
1687 }
1688
1689 return 0;
1690}
1691
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001692static int ath10k_mac_ps_vif_count(struct ath10k *ar)
1693{
1694 struct ath10k_vif *arvif;
1695 int num = 0;
1696
1697 lockdep_assert_held(&ar->conf_mutex);
1698
1699 list_for_each_entry(arvif, &ar->arvifs, list)
1700 if (arvif->ps)
1701 num++;
1702
1703 return num;
1704}
1705
Michal Kaziorad088bf2013-10-16 15:44:46 +03001706static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001707{
Michal Kaziorad088bf2013-10-16 15:44:46 +03001708 struct ath10k *ar = arvif->ar;
Michal Kazior526549a2014-12-12 12:41:37 +01001709 struct ieee80211_vif *vif = arvif->vif;
Michal Kaziorad088bf2013-10-16 15:44:46 +03001710 struct ieee80211_conf *conf = &ar->hw->conf;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001711 enum wmi_sta_powersave_param param;
1712 enum wmi_sta_ps_mode psmode;
1713 int ret;
Michal Kazior526549a2014-12-12 12:41:37 +01001714 int ps_timeout;
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001715 bool enable_ps;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001716
Michal Kazior548db542013-07-05 16:15:15 +03001717 lockdep_assert_held(&arvif->ar->conf_mutex);
1718
Michal Kaziorad088bf2013-10-16 15:44:46 +03001719 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1720 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001721
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001722 enable_ps = arvif->ps;
1723
1724 if (enable_ps && ath10k_mac_ps_vif_count(ar) > 1 &&
1725 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
1726 ar->fw_features)) {
1727 ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
1728 arvif->vdev_id);
1729 enable_ps = false;
1730 }
1731
1732 if (enable_ps) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001733 psmode = WMI_STA_PS_MODE_ENABLED;
1734 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1735
Michal Kazior526549a2014-12-12 12:41:37 +01001736 ps_timeout = conf->dynamic_ps_timeout;
1737 if (ps_timeout == 0) {
1738 /* Firmware doesn't like 0 */
1739 ps_timeout = ieee80211_tu_to_usec(
1740 vif->bss_conf.beacon_int) / 1000;
1741 }
1742
Michal Kaziorad088bf2013-10-16 15:44:46 +03001743 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
Michal Kazior526549a2014-12-12 12:41:37 +01001744 ps_timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001745 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001746 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001747 arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001748 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001749 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001750 } else {
1751 psmode = WMI_STA_PS_MODE_DISABLED;
1752 }
1753
Michal Kazior7aa7a722014-08-25 12:09:38 +02001754 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001755 arvif->vdev_id, psmode ? "enable" : "disable");
1756
Michal Kaziorad088bf2013-10-16 15:44:46 +03001757 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1758 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001759 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001760 psmode, arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001761 return ret;
1762 }
1763
1764 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001765}
1766
Michal Kazior46725b152015-01-28 09:57:49 +02001767static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1768{
1769 struct ath10k *ar = arvif->ar;
1770 struct wmi_sta_keepalive_arg arg = {};
1771 int ret;
1772
1773 lockdep_assert_held(&arvif->ar->conf_mutex);
1774
1775 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1776 return 0;
1777
1778 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1779 return 0;
1780
1781 /* Some firmware revisions have a bug and ignore the `enabled` field.
1782 * Instead use the interval to disable the keepalive.
1783 */
1784 arg.vdev_id = arvif->vdev_id;
1785 arg.enabled = 1;
1786 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1787 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1788
1789 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1790 if (ret) {
1791 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1792 arvif->vdev_id, ret);
1793 return ret;
1794 }
1795
1796 return 0;
1797}
1798
Michal Kazior81a9a172015-03-05 16:02:17 +02001799static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif)
1800{
1801 struct ath10k *ar = arvif->ar;
1802 struct ieee80211_vif *vif = arvif->vif;
1803 int ret;
1804
Michal Kazior8513d952015-03-09 14:19:24 +01001805 lockdep_assert_held(&arvif->ar->conf_mutex);
1806
1807 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)))
1808 return;
1809
Michal Kazior81a9a172015-03-05 16:02:17 +02001810 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1811 return;
1812
1813 if (!vif->csa_active)
1814 return;
1815
1816 if (!arvif->is_up)
1817 return;
1818
1819 if (!ieee80211_csa_is_complete(vif)) {
1820 ieee80211_csa_update_counter(vif);
1821
1822 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1823 if (ret)
1824 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
1825 ret);
1826
1827 ret = ath10k_mac_setup_prb_tmpl(arvif);
1828 if (ret)
1829 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
1830 ret);
1831 } else {
1832 ieee80211_csa_finish(vif);
1833 }
1834}
1835
1836static void ath10k_mac_vif_ap_csa_work(struct work_struct *work)
1837{
1838 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1839 ap_csa_work);
1840 struct ath10k *ar = arvif->ar;
1841
1842 mutex_lock(&ar->conf_mutex);
1843 ath10k_mac_vif_ap_csa_count_down(arvif);
1844 mutex_unlock(&ar->conf_mutex);
1845}
1846
Michal Kaziorcc9904e2015-03-10 16:22:01 +02001847static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac,
1848 struct ieee80211_vif *vif)
1849{
1850 struct sk_buff *skb = data;
1851 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1852 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1853
1854 if (vif->type != NL80211_IFTYPE_STATION)
1855 return;
1856
1857 if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
1858 return;
1859
1860 cancel_delayed_work(&arvif->connection_loss_work);
1861}
1862
1863void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb)
1864{
1865 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1866 IEEE80211_IFACE_ITER_NORMAL,
1867 ath10k_mac_handle_beacon_iter,
1868 skb);
1869}
1870
1871static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac,
1872 struct ieee80211_vif *vif)
1873{
1874 u32 *vdev_id = data;
1875 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1876 struct ath10k *ar = arvif->ar;
1877 struct ieee80211_hw *hw = ar->hw;
1878
1879 if (arvif->vdev_id != *vdev_id)
1880 return;
1881
1882 if (!arvif->is_up)
1883 return;
1884
1885 ieee80211_beacon_loss(vif);
1886
1887 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
1888 * (done by mac80211) succeeds but beacons do not resume then it
1889 * doesn't make sense to continue operation. Queue connection loss work
1890 * which can be cancelled when beacon is received.
1891 */
1892 ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
1893 ATH10K_CONNECTION_LOSS_HZ);
1894}
1895
1896void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id)
1897{
1898 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1899 IEEE80211_IFACE_ITER_NORMAL,
1900 ath10k_mac_handle_beacon_miss_iter,
1901 &vdev_id);
1902}
1903
1904static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work)
1905{
1906 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1907 connection_loss_work.work);
1908 struct ieee80211_vif *vif = arvif->vif;
1909
1910 if (!arvif->is_up)
1911 return;
1912
1913 ieee80211_connection_loss(vif);
1914}
1915
Kalle Valo5e3dd152013-06-12 20:52:10 +03001916/**********************/
1917/* Station management */
1918/**********************/
1919
Michal Kazior590922a2014-10-21 10:10:29 +03001920static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1921 struct ieee80211_vif *vif)
1922{
1923 /* Some firmware revisions have unstable STA powersave when listen
1924 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1925 * generate NullFunc frames properly even if buffered frames have been
1926 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1927 * buffered frames. Often pinging the device from AP would simply fail.
1928 *
1929 * As a workaround set it to 1.
1930 */
1931 if (vif->type == NL80211_IFTYPE_STATION)
1932 return 1;
1933
1934 return ar->hw->conf.listen_interval;
1935}
1936
Kalle Valo5e3dd152013-06-12 20:52:10 +03001937static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001938 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001939 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001940 struct wmi_peer_assoc_complete_arg *arg)
1941{
Michal Kazior590922a2014-10-21 10:10:29 +03001942 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorc51880e2015-03-30 09:51:57 +03001943 u32 aid;
Michal Kazior590922a2014-10-21 10:10:29 +03001944
Michal Kazior548db542013-07-05 16:15:15 +03001945 lockdep_assert_held(&ar->conf_mutex);
1946
Michal Kaziorc51880e2015-03-30 09:51:57 +03001947 if (vif->type == NL80211_IFTYPE_STATION)
1948 aid = vif->bss_conf.aid;
1949 else
1950 aid = sta->aid;
1951
Kalle Valob25f32c2014-09-14 12:50:49 +03001952 ether_addr_copy(arg->addr, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001953 arg->vdev_id = arvif->vdev_id;
Michal Kaziorc51880e2015-03-30 09:51:57 +03001954 arg->peer_aid = aid;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001955 arg->peer_flags |= WMI_PEER_AUTH;
Michal Kazior590922a2014-10-21 10:10:29 +03001956 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001957 arg->peer_num_spatial_streams = 1;
Michal Kazior590922a2014-10-21 10:10:29 +03001958 arg->peer_caps = vif->bss_conf.assoc_capability;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001959}
1960
1961static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001962 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001963 struct wmi_peer_assoc_complete_arg *arg)
1964{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001965 struct ieee80211_bss_conf *info = &vif->bss_conf;
Michal Kazior500ff9f2015-03-31 10:26:21 +00001966 struct cfg80211_chan_def def;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001967 struct cfg80211_bss *bss;
1968 const u8 *rsnie = NULL;
1969 const u8 *wpaie = NULL;
1970
Michal Kazior548db542013-07-05 16:15:15 +03001971 lockdep_assert_held(&ar->conf_mutex);
1972
Michal Kazior500ff9f2015-03-31 10:26:21 +00001973 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
1974 return;
1975
1976 bss = cfg80211_get_bss(ar->hw->wiphy, def.chan, info->bssid, NULL, 0,
1977 IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001978 if (bss) {
1979 const struct cfg80211_bss_ies *ies;
1980
1981 rcu_read_lock();
1982 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1983
1984 ies = rcu_dereference(bss->ies);
1985
1986 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
Kalle Valo5b07e072014-09-14 12:50:06 +03001987 WLAN_OUI_TYPE_MICROSOFT_WPA,
1988 ies->data,
1989 ies->len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001990 rcu_read_unlock();
1991 cfg80211_put_bss(ar->hw->wiphy, bss);
1992 }
1993
1994 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1995 if (rsnie || wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001996 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001997 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1998 }
1999
2000 if (wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002001 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002002 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
2003 }
2004}
2005
2006static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
Michal Kazior500ff9f2015-03-31 10:26:21 +00002007 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002008 struct ieee80211_sta *sta,
2009 struct wmi_peer_assoc_complete_arg *arg)
2010{
2011 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
Michal Kazior500ff9f2015-03-31 10:26:21 +00002012 struct cfg80211_chan_def def;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002013 const struct ieee80211_supported_band *sband;
2014 const struct ieee80211_rate *rates;
2015 u32 ratemask;
Michal Kazior486017c2015-03-30 09:51:54 +03002016 u8 rate;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002017 int i;
2018
Michal Kazior548db542013-07-05 16:15:15 +03002019 lockdep_assert_held(&ar->conf_mutex);
2020
Michal Kazior500ff9f2015-03-31 10:26:21 +00002021 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2022 return;
2023
2024 sband = ar->hw->wiphy->bands[def.chan->band];
2025 ratemask = sta->supp_rates[def.chan->band];
Kalle Valo5e3dd152013-06-12 20:52:10 +03002026 rates = sband->bitrates;
2027
2028 rateset->num_rates = 0;
2029
2030 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
2031 if (!(ratemask & 1))
2032 continue;
2033
Michal Kazior486017c2015-03-30 09:51:54 +03002034 rate = ath10k_mac_bitrate_to_rate(rates->bitrate);
2035 rateset->rates[rateset->num_rates] = rate;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002036 rateset->num_rates++;
2037 }
2038}
2039
2040static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
2041 struct ieee80211_sta *sta,
2042 struct wmi_peer_assoc_complete_arg *arg)
2043{
2044 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002045 int i, n;
Kalle Valoaf762c02014-09-14 12:50:17 +03002046 u32 stbc;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002047
Michal Kazior548db542013-07-05 16:15:15 +03002048 lockdep_assert_held(&ar->conf_mutex);
2049
Kalle Valo5e3dd152013-06-12 20:52:10 +03002050 if (!ht_cap->ht_supported)
2051 return;
2052
2053 arg->peer_flags |= WMI_PEER_HT;
2054 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2055 ht_cap->ampdu_factor)) - 1;
2056
2057 arg->peer_mpdu_density =
2058 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
2059
2060 arg->peer_ht_caps = ht_cap->cap;
2061 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
2062
2063 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
2064 arg->peer_flags |= WMI_PEER_LDPC;
2065
2066 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
2067 arg->peer_flags |= WMI_PEER_40MHZ;
2068 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
2069 }
2070
2071 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
2072 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2073
2074 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
2075 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2076
2077 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
2078 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
2079 arg->peer_flags |= WMI_PEER_STBC;
2080 }
2081
2082 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002083 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
2084 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
2085 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
2086 arg->peer_rate_caps |= stbc;
2087 arg->peer_flags |= WMI_PEER_STBC;
2088 }
2089
Kalle Valo5e3dd152013-06-12 20:52:10 +03002090 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
2091 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
2092 else if (ht_cap->mcs.rx_mask[1])
2093 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
2094
2095 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
2096 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
2097 arg->peer_ht_rates.rates[n++] = i;
2098
Bartosz Markowskifd71f802014-02-10 13:12:55 +01002099 /*
2100 * This is a workaround for HT-enabled STAs which break the spec
2101 * and have no HT capabilities RX mask (no HT RX MCS map).
2102 *
2103 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
2104 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
2105 *
2106 * Firmware asserts if such situation occurs.
2107 */
2108 if (n == 0) {
2109 arg->peer_ht_rates.num_rates = 8;
2110 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
2111 arg->peer_ht_rates.rates[i] = i;
2112 } else {
2113 arg->peer_ht_rates.num_rates = n;
2114 arg->peer_num_spatial_streams = sta->rx_nss;
2115 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002116
Michal Kazior7aa7a722014-08-25 12:09:38 +02002117 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03002118 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002119 arg->peer_ht_rates.num_rates,
2120 arg->peer_num_spatial_streams);
2121}
2122
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002123static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
2124 struct ath10k_vif *arvif,
2125 struct ieee80211_sta *sta)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002126{
2127 u32 uapsd = 0;
2128 u32 max_sp = 0;
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002129 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002130
Michal Kazior548db542013-07-05 16:15:15 +03002131 lockdep_assert_held(&ar->conf_mutex);
2132
Kalle Valo5e3dd152013-06-12 20:52:10 +03002133 if (sta->wme && sta->uapsd_queues) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002134 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002135 sta->uapsd_queues, sta->max_sp);
2136
Kalle Valo5e3dd152013-06-12 20:52:10 +03002137 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2138 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
2139 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
2140 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2141 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
2142 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
2143 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2144 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
2145 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
2146 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2147 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
2148 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
2149
Kalle Valo5e3dd152013-06-12 20:52:10 +03002150 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
2151 max_sp = sta->max_sp;
2152
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002153 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2154 sta->addr,
2155 WMI_AP_PS_PEER_PARAM_UAPSD,
2156 uapsd);
2157 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002158 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002159 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002160 return ret;
2161 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002162
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002163 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2164 sta->addr,
2165 WMI_AP_PS_PEER_PARAM_MAX_SP,
2166 max_sp);
2167 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002168 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002169 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002170 return ret;
2171 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002172
2173 /* TODO setup this based on STA listen interval and
2174 beacon interval. Currently we don't know
2175 sta->listen_interval - mac80211 patch required.
2176 Currently use 10 seconds */
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002177 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
Kalle Valo5b07e072014-09-14 12:50:06 +03002178 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
2179 10);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002180 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002181 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002182 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002183 return ret;
2184 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002185 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002186
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002187 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002188}
2189
2190static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
Michal Kazior500ff9f2015-03-31 10:26:21 +00002191 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002192 struct ieee80211_sta *sta,
2193 struct wmi_peer_assoc_complete_arg *arg)
2194{
2195 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
Michal Kazior500ff9f2015-03-31 10:26:21 +00002196 struct cfg80211_chan_def def;
Sujith Manoharana24b88b2013-10-07 19:51:57 -07002197 u8 ampdu_factor;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002198
Michal Kazior500ff9f2015-03-31 10:26:21 +00002199 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2200 return;
2201
Kalle Valo5e3dd152013-06-12 20:52:10 +03002202 if (!vht_cap->vht_supported)
2203 return;
2204
2205 arg->peer_flags |= WMI_PEER_VHT;
Yanbo Lid68bb122015-01-23 08:18:20 +08002206
Michal Kazior500ff9f2015-03-31 10:26:21 +00002207 if (def.chan->band == IEEE80211_BAND_2GHZ)
Yanbo Lid68bb122015-01-23 08:18:20 +08002208 arg->peer_flags |= WMI_PEER_VHT_2G;
2209
Kalle Valo5e3dd152013-06-12 20:52:10 +03002210 arg->peer_vht_caps = vht_cap->cap;
2211
Sujith Manoharana24b88b2013-10-07 19:51:57 -07002212 ampdu_factor = (vht_cap->cap &
2213 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
2214 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
2215
2216 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
2217 * zero in VHT IE. Using it would result in degraded throughput.
2218 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
2219 * it if VHT max_mpdu is smaller. */
2220 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
2221 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2222 ampdu_factor)) - 1);
2223
Kalle Valo5e3dd152013-06-12 20:52:10 +03002224 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2225 arg->peer_flags |= WMI_PEER_80MHZ;
2226
2227 arg->peer_vht_rates.rx_max_rate =
2228 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
2229 arg->peer_vht_rates.rx_mcs_set =
2230 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
2231 arg->peer_vht_rates.tx_max_rate =
2232 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
2233 arg->peer_vht_rates.tx_mcs_set =
2234 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
2235
Michal Kazior7aa7a722014-08-25 12:09:38 +02002236 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03002237 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002238}
2239
2240static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03002241 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002242 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002243 struct wmi_peer_assoc_complete_arg *arg)
2244{
Michal Kazior590922a2014-10-21 10:10:29 +03002245 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2246
Kalle Valo5e3dd152013-06-12 20:52:10 +03002247 switch (arvif->vdev_type) {
2248 case WMI_VDEV_TYPE_AP:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002249 if (sta->wme)
2250 arg->peer_flags |= WMI_PEER_QOS;
2251
2252 if (sta->wme && sta->uapsd_queues) {
2253 arg->peer_flags |= WMI_PEER_APSD;
2254 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
2255 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002256 break;
2257 case WMI_VDEV_TYPE_STA:
Michal Kazior590922a2014-10-21 10:10:29 +03002258 if (vif->bss_conf.qos)
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002259 arg->peer_flags |= WMI_PEER_QOS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002260 break;
Janusz Dziedzic627d9842014-12-17 12:29:54 +02002261 case WMI_VDEV_TYPE_IBSS:
2262 if (sta->wme)
2263 arg->peer_flags |= WMI_PEER_QOS;
2264 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002265 default:
2266 break;
2267 }
Janusz Dziedzic627d9842014-12-17 12:29:54 +02002268
2269 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
2270 sta->addr, !!(arg->peer_flags & WMI_PEER_QOS));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002271}
2272
Michal Kazior8d7aa6b2015-03-30 09:51:57 +03002273static bool ath10k_mac_sta_has_ofdm_only(struct ieee80211_sta *sta)
Michal Kazior91b12082014-12-12 12:41:35 +01002274{
Michal Kazior8d7aa6b2015-03-30 09:51:57 +03002275 return sta->supp_rates[IEEE80211_BAND_2GHZ] >>
2276 ATH10K_MAC_FIRST_OFDM_RATE_IDX;
Michal Kazior91b12082014-12-12 12:41:35 +01002277}
2278
Kalle Valo5e3dd152013-06-12 20:52:10 +03002279static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03002280 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002281 struct ieee80211_sta *sta,
2282 struct wmi_peer_assoc_complete_arg *arg)
2283{
Michal Kazior500ff9f2015-03-31 10:26:21 +00002284 struct cfg80211_chan_def def;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002285 enum wmi_phy_mode phymode = MODE_UNKNOWN;
2286
Michal Kazior500ff9f2015-03-31 10:26:21 +00002287 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2288 return;
2289
2290 switch (def.chan->band) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002291 case IEEE80211_BAND_2GHZ:
Yanbo Lid68bb122015-01-23 08:18:20 +08002292 if (sta->vht_cap.vht_supported) {
2293 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2294 phymode = MODE_11AC_VHT40;
2295 else
2296 phymode = MODE_11AC_VHT20;
2297 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002298 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2299 phymode = MODE_11NG_HT40;
2300 else
2301 phymode = MODE_11NG_HT20;
Michal Kazior8d7aa6b2015-03-30 09:51:57 +03002302 } else if (ath10k_mac_sta_has_ofdm_only(sta)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002303 phymode = MODE_11G;
Michal Kazior91b12082014-12-12 12:41:35 +01002304 } else {
2305 phymode = MODE_11B;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002306 }
2307
2308 break;
2309 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03002310 /*
2311 * Check VHT first.
2312 */
2313 if (sta->vht_cap.vht_supported) {
2314 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2315 phymode = MODE_11AC_VHT80;
2316 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2317 phymode = MODE_11AC_VHT40;
2318 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
2319 phymode = MODE_11AC_VHT20;
2320 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002321 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2322 phymode = MODE_11NA_HT40;
2323 else
2324 phymode = MODE_11NA_HT20;
2325 } else {
2326 phymode = MODE_11A;
2327 }
2328
2329 break;
2330 default:
2331 break;
2332 }
2333
Michal Kazior7aa7a722014-08-25 12:09:38 +02002334 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
Kalle Valo38a1d472013-09-08 17:56:14 +03002335 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03002336
Kalle Valo5e3dd152013-06-12 20:52:10 +03002337 arg->peer_phymode = phymode;
2338 WARN_ON(phymode == MODE_UNKNOWN);
2339}
2340
Kalle Valob9ada652013-10-16 15:44:46 +03002341static int ath10k_peer_assoc_prepare(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03002342 struct ieee80211_vif *vif,
Kalle Valob9ada652013-10-16 15:44:46 +03002343 struct ieee80211_sta *sta,
Kalle Valob9ada652013-10-16 15:44:46 +03002344 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002345{
Michal Kazior548db542013-07-05 16:15:15 +03002346 lockdep_assert_held(&ar->conf_mutex);
2347
Kalle Valob9ada652013-10-16 15:44:46 +03002348 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002349
Michal Kazior590922a2014-10-21 10:10:29 +03002350 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
2351 ath10k_peer_assoc_h_crypto(ar, vif, arg);
Michal Kazior500ff9f2015-03-31 10:26:21 +00002352 ath10k_peer_assoc_h_rates(ar, vif, sta, arg);
Kalle Valob9ada652013-10-16 15:44:46 +03002353 ath10k_peer_assoc_h_ht(ar, sta, arg);
Michal Kazior500ff9f2015-03-31 10:26:21 +00002354 ath10k_peer_assoc_h_vht(ar, vif, sta, arg);
Michal Kazior590922a2014-10-21 10:10:29 +03002355 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
2356 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002357
Kalle Valob9ada652013-10-16 15:44:46 +03002358 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002359}
2360
Michal Kazior90046f52014-02-14 14:45:51 +01002361static const u32 ath10k_smps_map[] = {
2362 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
2363 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
2364 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
2365 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
2366};
2367
2368static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
2369 const u8 *addr,
2370 const struct ieee80211_sta_ht_cap *ht_cap)
2371{
2372 int smps;
2373
2374 if (!ht_cap->ht_supported)
2375 return 0;
2376
2377 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
2378 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
2379
2380 if (smps >= ARRAY_SIZE(ath10k_smps_map))
2381 return -EINVAL;
2382
2383 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
2384 WMI_PEER_SMPS_STATE,
2385 ath10k_smps_map[smps]);
2386}
2387
Michal Kazior139e1702015-02-15 16:50:42 +02002388static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
2389 struct ieee80211_vif *vif,
2390 struct ieee80211_sta_vht_cap vht_cap)
2391{
2392 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2393 int ret;
2394 u32 param;
2395 u32 value;
2396
2397 if (!(ar->vht_cap_info &
2398 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2399 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
2400 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2401 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
2402 return 0;
2403
2404 param = ar->wmi.vdev_param->txbf;
2405 value = 0;
2406
2407 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
2408 return 0;
2409
2410 /* The following logic is correct. If a remote STA advertises support
2411 * for being a beamformer then we should enable us being a beamformee.
2412 */
2413
2414 if (ar->vht_cap_info &
2415 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2416 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
2417 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
2418 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2419
2420 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
2421 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
2422 }
2423
2424 if (ar->vht_cap_info &
2425 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2426 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
2427 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
2428 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2429
2430 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
2431 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
2432 }
2433
2434 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
2435 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2436
2437 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
2438 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2439
2440 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
2441 if (ret) {
2442 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
2443 value, ret);
2444 return ret;
2445 }
2446
2447 return 0;
2448}
2449
Kalle Valo5e3dd152013-06-12 20:52:10 +03002450/* can be called only in mac80211 callbacks due to `key_count` usage */
2451static void ath10k_bss_assoc(struct ieee80211_hw *hw,
2452 struct ieee80211_vif *vif,
2453 struct ieee80211_bss_conf *bss_conf)
2454{
2455 struct ath10k *ar = hw->priv;
2456 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior90046f52014-02-14 14:45:51 +01002457 struct ieee80211_sta_ht_cap ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02002458 struct ieee80211_sta_vht_cap vht_cap;
Kalle Valob9ada652013-10-16 15:44:46 +03002459 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002460 struct ieee80211_sta *ap_sta;
2461 int ret;
2462
Michal Kazior548db542013-07-05 16:15:15 +03002463 lockdep_assert_held(&ar->conf_mutex);
2464
Michal Kazior077efc82014-10-21 10:10:29 +03002465 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
2466 arvif->vdev_id, arvif->bssid, arvif->aid);
2467
Kalle Valo5e3dd152013-06-12 20:52:10 +03002468 rcu_read_lock();
2469
2470 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
2471 if (!ap_sta) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002472 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02002473 bss_conf->bssid, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002474 rcu_read_unlock();
2475 return;
2476 }
2477
Michal Kazior90046f52014-02-14 14:45:51 +01002478 /* ap_sta must be accessed only within rcu section which must be left
2479 * before calling ath10k_setup_peer_smps() which might sleep. */
2480 ht_cap = ap_sta->ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02002481 vht_cap = ap_sta->vht_cap;
Michal Kazior90046f52014-02-14 14:45:51 +01002482
Michal Kazior590922a2014-10-21 10:10:29 +03002483 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002484 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002485 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002486 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002487 rcu_read_unlock();
2488 return;
2489 }
2490
2491 rcu_read_unlock();
2492
Kalle Valob9ada652013-10-16 15:44:46 +03002493 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2494 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002495 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002496 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03002497 return;
2498 }
2499
Michal Kazior90046f52014-02-14 14:45:51 +01002500 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
2501 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002502 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002503 arvif->vdev_id, ret);
Michal Kazior90046f52014-02-14 14:45:51 +01002504 return;
2505 }
2506
Michal Kazior139e1702015-02-15 16:50:42 +02002507 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2508 if (ret) {
2509 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2510 arvif->vdev_id, bss_conf->bssid, ret);
2511 return;
2512 }
2513
Michal Kazior7aa7a722014-08-25 12:09:38 +02002514 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002515 "mac vdev %d up (associated) bssid %pM aid %d\n",
2516 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
2517
Michal Kazior077efc82014-10-21 10:10:29 +03002518 WARN_ON(arvif->is_up);
2519
Michal Kaziorc930f742014-01-23 11:38:25 +01002520 arvif->aid = bss_conf->aid;
Kalle Valob25f32c2014-09-14 12:50:49 +03002521 ether_addr_copy(arvif->bssid, bss_conf->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01002522
2523 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
2524 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002525 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002526 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01002527 return;
2528 }
2529
2530 arvif->is_up = true;
Michal Kazior0a987fb2015-02-13 13:30:15 +01002531
2532 /* Workaround: Some firmware revisions (tested with qca6174
2533 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2534 * poked with peer param command.
2535 */
2536 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
2537 WMI_PEER_DUMMY_VAR, 1);
2538 if (ret) {
2539 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2540 arvif->bssid, arvif->vdev_id, ret);
2541 return;
2542 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002543}
2544
Kalle Valo5e3dd152013-06-12 20:52:10 +03002545static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
2546 struct ieee80211_vif *vif)
2547{
2548 struct ath10k *ar = hw->priv;
2549 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior139e1702015-02-15 16:50:42 +02002550 struct ieee80211_sta_vht_cap vht_cap = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +03002551 int ret;
2552
Michal Kazior548db542013-07-05 16:15:15 +03002553 lockdep_assert_held(&ar->conf_mutex);
2554
Michal Kazior077efc82014-10-21 10:10:29 +03002555 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
2556 arvif->vdev_id, arvif->bssid);
Kalle Valo60c3daa2013-09-08 17:56:07 +03002557
Kalle Valo5e3dd152013-06-12 20:52:10 +03002558 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kazior077efc82014-10-21 10:10:29 +03002559 if (ret)
2560 ath10k_warn(ar, "faield to down vdev %i: %d\n",
2561 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002562
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02002563 arvif->def_wep_key_idx = -1;
2564
Michal Kazior139e1702015-02-15 16:50:42 +02002565 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2566 if (ret) {
2567 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
2568 arvif->vdev_id, ret);
2569 return;
2570 }
2571
Michal Kaziorc930f742014-01-23 11:38:25 +01002572 arvif->is_up = false;
Michal Kaziorcc9904e2015-03-10 16:22:01 +02002573
2574 cancel_delayed_work_sync(&arvif->connection_loss_work);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002575}
2576
Michal Kazior590922a2014-10-21 10:10:29 +03002577static int ath10k_station_assoc(struct ath10k *ar,
2578 struct ieee80211_vif *vif,
2579 struct ieee80211_sta *sta,
2580 bool reassoc)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002581{
Michal Kazior590922a2014-10-21 10:10:29 +03002582 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valob9ada652013-10-16 15:44:46 +03002583 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002584 int ret = 0;
2585
Michal Kazior548db542013-07-05 16:15:15 +03002586 lockdep_assert_held(&ar->conf_mutex);
2587
Michal Kazior590922a2014-10-21 10:10:29 +03002588 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002589 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002590 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02002591 sta->addr, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03002592 return ret;
2593 }
2594
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02002595 peer_arg.peer_reassoc = reassoc;
Kalle Valob9ada652013-10-16 15:44:46 +03002596 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2597 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002598 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002599 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002600 return ret;
2601 }
2602
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002603 /* Re-assoc is run only to update supported rates for given station. It
2604 * doesn't make much sense to reconfigure the peer completely.
2605 */
2606 if (!reassoc) {
2607 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
2608 &sta->ht_cap);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002609 if (ret) {
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002610 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002611 arvif->vdev_id, ret);
2612 return ret;
2613 }
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002614
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002615 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
2616 if (ret) {
2617 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
2618 sta->addr, arvif->vdev_id, ret);
2619 return ret;
2620 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002621
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002622 if (!sta->wme) {
2623 arvif->num_legacy_stations++;
2624 ret = ath10k_recalc_rtscts_prot(arvif);
2625 if (ret) {
2626 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2627 arvif->vdev_id, ret);
2628 return ret;
2629 }
2630 }
2631
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02002632 /* Plumb cached keys only for static WEP */
2633 if (arvif->def_wep_key_idx != -1) {
2634 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
2635 if (ret) {
2636 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
2637 arvif->vdev_id, ret);
2638 return ret;
2639 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002640 }
2641 }
2642
Kalle Valo5e3dd152013-06-12 20:52:10 +03002643 return ret;
2644}
2645
Michal Kazior590922a2014-10-21 10:10:29 +03002646static int ath10k_station_disassoc(struct ath10k *ar,
2647 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002648 struct ieee80211_sta *sta)
2649{
Michal Kazior590922a2014-10-21 10:10:29 +03002650 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002651 int ret = 0;
2652
2653 lockdep_assert_held(&ar->conf_mutex);
2654
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002655 if (!sta->wme) {
2656 arvif->num_legacy_stations--;
2657 ret = ath10k_recalc_rtscts_prot(arvif);
2658 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002659 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002660 arvif->vdev_id, ret);
2661 return ret;
2662 }
2663 }
2664
Kalle Valo5e3dd152013-06-12 20:52:10 +03002665 ret = ath10k_clear_peer_keys(arvif, sta->addr);
2666 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002667 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002668 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002669 return ret;
2670 }
2671
2672 return ret;
2673}
2674
2675/**************/
2676/* Regulatory */
2677/**************/
2678
2679static int ath10k_update_channel_list(struct ath10k *ar)
2680{
2681 struct ieee80211_hw *hw = ar->hw;
2682 struct ieee80211_supported_band **bands;
2683 enum ieee80211_band band;
2684 struct ieee80211_channel *channel;
2685 struct wmi_scan_chan_list_arg arg = {0};
2686 struct wmi_channel_arg *ch;
2687 bool passive;
2688 int len;
2689 int ret;
2690 int i;
2691
Michal Kazior548db542013-07-05 16:15:15 +03002692 lockdep_assert_held(&ar->conf_mutex);
2693
Kalle Valo5e3dd152013-06-12 20:52:10 +03002694 bands = hw->wiphy->bands;
2695 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2696 if (!bands[band])
2697 continue;
2698
2699 for (i = 0; i < bands[band]->n_channels; i++) {
2700 if (bands[band]->channels[i].flags &
2701 IEEE80211_CHAN_DISABLED)
2702 continue;
2703
2704 arg.n_channels++;
2705 }
2706 }
2707
2708 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
2709 arg.channels = kzalloc(len, GFP_KERNEL);
2710 if (!arg.channels)
2711 return -ENOMEM;
2712
2713 ch = arg.channels;
2714 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2715 if (!bands[band])
2716 continue;
2717
2718 for (i = 0; i < bands[band]->n_channels; i++) {
2719 channel = &bands[band]->channels[i];
2720
2721 if (channel->flags & IEEE80211_CHAN_DISABLED)
2722 continue;
2723
2724 ch->allow_ht = true;
2725
2726 /* FIXME: when should we really allow VHT? */
2727 ch->allow_vht = true;
2728
2729 ch->allow_ibss =
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002730 !(channel->flags & IEEE80211_CHAN_NO_IR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002731
2732 ch->ht40plus =
2733 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
2734
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002735 ch->chan_radar =
2736 !!(channel->flags & IEEE80211_CHAN_RADAR);
2737
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002738 passive = channel->flags & IEEE80211_CHAN_NO_IR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002739 ch->passive = passive;
2740
2741 ch->freq = channel->center_freq;
Michal Kazior2d667212014-09-18 15:21:21 +02002742 ch->band_center_freq1 = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07002743 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07002744 ch->max_power = channel->max_power * 2;
2745 ch->max_reg_power = channel->max_reg_power * 2;
2746 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002747 ch->reg_class_id = 0; /* FIXME */
2748
2749 /* FIXME: why use only legacy modes, why not any
2750 * HT/VHT modes? Would that even make any
2751 * difference? */
2752 if (channel->band == IEEE80211_BAND_2GHZ)
2753 ch->mode = MODE_11G;
2754 else
2755 ch->mode = MODE_11A;
2756
2757 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
2758 continue;
2759
Michal Kazior7aa7a722014-08-25 12:09:38 +02002760 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002761 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
2762 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002763 ch->freq, ch->max_power, ch->max_reg_power,
2764 ch->max_antenna_gain, ch->mode);
2765
2766 ch++;
2767 }
2768 }
2769
2770 ret = ath10k_wmi_scan_chan_list(ar, &arg);
2771 kfree(arg.channels);
2772
2773 return ret;
2774}
2775
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002776static enum wmi_dfs_region
2777ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
2778{
2779 switch (dfs_region) {
2780 case NL80211_DFS_UNSET:
2781 return WMI_UNINIT_DFS_DOMAIN;
2782 case NL80211_DFS_FCC:
2783 return WMI_FCC_DFS_DOMAIN;
2784 case NL80211_DFS_ETSI:
2785 return WMI_ETSI_DFS_DOMAIN;
2786 case NL80211_DFS_JP:
2787 return WMI_MKK4_DFS_DOMAIN;
2788 }
2789 return WMI_UNINIT_DFS_DOMAIN;
2790}
2791
Michal Kaziorf7843d72013-07-16 09:38:52 +02002792static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002793{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002794 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002795 int ret;
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002796 enum wmi_dfs_region wmi_dfs_reg;
2797 enum nl80211_dfs_regions nl_dfs_reg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002798
Michal Kaziorf7843d72013-07-16 09:38:52 +02002799 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002800
2801 ret = ath10k_update_channel_list(ar);
2802 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002803 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002804
2805 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002806
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002807 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
2808 nl_dfs_reg = ar->dfs_detector->region;
2809 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
2810 } else {
2811 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
2812 }
2813
Kalle Valo5e3dd152013-06-12 20:52:10 +03002814 /* Target allows setting up per-band regdomain but ath_common provides
2815 * a combined one only */
2816 ret = ath10k_wmi_pdev_set_regdomain(ar,
Kalle Valoef8c0012014-02-13 18:13:12 +02002817 regpair->reg_domain,
2818 regpair->reg_domain, /* 2ghz */
2819 regpair->reg_domain, /* 5ghz */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002820 regpair->reg_2ghz_ctl,
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002821 regpair->reg_5ghz_ctl,
2822 wmi_dfs_reg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002823 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002824 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02002825}
Michal Kazior548db542013-07-05 16:15:15 +03002826
Michal Kaziorf7843d72013-07-16 09:38:52 +02002827static void ath10k_reg_notifier(struct wiphy *wiphy,
2828 struct regulatory_request *request)
2829{
2830 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
2831 struct ath10k *ar = hw->priv;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002832 bool result;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002833
2834 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
2835
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002836 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002837 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002838 request->dfs_region);
2839 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
2840 request->dfs_region);
2841 if (!result)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002842 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002843 request->dfs_region);
2844 }
2845
Michal Kaziorf7843d72013-07-16 09:38:52 +02002846 mutex_lock(&ar->conf_mutex);
2847 if (ar->state == ATH10K_STATE_ON)
2848 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03002849 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002850}
2851
2852/***************/
2853/* TX handlers */
2854/***************/
2855
Michal Kazior42c3aa62013-10-02 11:03:38 +02002856static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
2857{
2858 if (ieee80211_is_mgmt(hdr->frame_control))
2859 return HTT_DATA_TX_EXT_TID_MGMT;
2860
2861 if (!ieee80211_is_data_qos(hdr->frame_control))
2862 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2863
2864 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
2865 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2866
2867 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
2868}
2869
Michal Kazior2b37c292014-09-02 11:00:22 +03002870static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002871{
Michal Kazior2b37c292014-09-02 11:00:22 +03002872 if (vif)
2873 return ath10k_vif_to_arvif(vif)->vdev_id;
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002874
Michal Kazior1bbc0972014-04-08 09:45:47 +03002875 if (ar->monitor_started)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002876 return ar->monitor_vdev_id;
2877
Michal Kazior7aa7a722014-08-25 12:09:38 +02002878 ath10k_warn(ar, "failed to resolve vdev id\n");
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002879 return 0;
2880}
2881
Michal Kaziord740d8f2015-03-30 09:51:51 +03002882static enum ath10k_hw_txrx_mode
2883ath10k_tx_h_get_txmode(struct ath10k *ar, struct ieee80211_vif *vif,
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03002884 struct ieee80211_sta *sta, struct sk_buff *skb)
Michal Kaziord740d8f2015-03-30 09:51:51 +03002885{
2886 const struct ieee80211_hdr *hdr = (void *)skb->data;
2887 __le16 fc = hdr->frame_control;
2888
2889 if (!vif || vif->type == NL80211_IFTYPE_MONITOR)
2890 return ATH10K_HW_TXRX_RAW;
2891
2892 if (ieee80211_is_mgmt(fc))
2893 return ATH10K_HW_TXRX_MGMT;
2894
2895 /* Workaround:
2896 *
2897 * NullFunc frames are mostly used to ping if a client or AP are still
2898 * reachable and responsive. This implies tx status reports must be
2899 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
2900 * come to a conclusion that the other end disappeared and tear down
2901 * BSS connection or it can never disconnect from BSS/client (which is
2902 * the case).
2903 *
2904 * Firmware with HTT older than 3.0 delivers incorrect tx status for
2905 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
2906 * which seems to deliver correct tx reports for NullFunc frames. The
2907 * downside of using it is it ignores client powersave state so it can
2908 * end up disconnecting sleeping clients in AP mode. It should fix STA
2909 * mode though because AP don't sleep.
2910 */
2911 if (ar->htt.target_version_major < 3 &&
2912 (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc)) &&
2913 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX, ar->fw_features))
2914 return ATH10K_HW_TXRX_MGMT;
2915
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03002916 /* Workaround:
2917 *
2918 * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
2919 * NativeWifi txmode - it selects AP key instead of peer key. It seems
2920 * to work with Ethernet txmode so use it.
2921 */
2922 if (ieee80211_is_data_present(fc) && sta && sta->tdls)
2923 return ATH10K_HW_TXRX_ETHERNET;
2924
Michal Kaziord740d8f2015-03-30 09:51:51 +03002925 return ATH10K_HW_TXRX_NATIVE_WIFI;
2926}
2927
Michal Kazior4b604552014-07-21 21:03:09 +03002928/* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
2929 * Control in the header.
Kalle Valo5e3dd152013-06-12 20:52:10 +03002930 */
Michal Kazior4b604552014-07-21 21:03:09 +03002931static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002932{
2933 struct ieee80211_hdr *hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002934 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002935 u8 *qos_ctl;
2936
2937 if (!ieee80211_is_data_qos(hdr->frame_control))
2938 return;
2939
2940 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02002941 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
2942 skb->data, (void *)qos_ctl - (void *)skb->data);
2943 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002944
Michal Kazior8bad8dc2015-03-11 14:25:26 +01002945 /* Some firmware revisions don't handle sending QoS NullFunc well.
2946 * These frames are mainly used for CQM purposes so it doesn't really
2947 * matter whether QoS NullFunc or NullFunc are sent.
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002948 */
Michal Kaziorbf0a26d2015-01-24 12:14:51 +02002949 hdr = (void *)skb->data;
Michal Kazior8bad8dc2015-03-11 14:25:26 +01002950 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002951 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
Michal Kazior8bad8dc2015-03-11 14:25:26 +01002952
2953 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002954}
2955
Michal Kaziord740d8f2015-03-30 09:51:51 +03002956static void ath10k_tx_h_8023(struct sk_buff *skb)
2957{
2958 struct ieee80211_hdr *hdr;
2959 struct rfc1042_hdr *rfc1042;
2960 struct ethhdr *eth;
2961 size_t hdrlen;
2962 u8 da[ETH_ALEN];
2963 u8 sa[ETH_ALEN];
2964 __be16 type;
2965
2966 hdr = (void *)skb->data;
2967 hdrlen = ieee80211_hdrlen(hdr->frame_control);
2968 rfc1042 = (void *)skb->data + hdrlen;
2969
2970 ether_addr_copy(da, ieee80211_get_DA(hdr));
2971 ether_addr_copy(sa, ieee80211_get_SA(hdr));
2972 type = rfc1042->snap_type;
2973
2974 skb_pull(skb, hdrlen + sizeof(*rfc1042));
2975 skb_push(skb, sizeof(*eth));
2976
2977 eth = (void *)skb->data;
2978 ether_addr_copy(eth->h_dest, da);
2979 ether_addr_copy(eth->h_source, sa);
2980 eth->h_proto = type;
2981}
2982
Michal Kazior4b604552014-07-21 21:03:09 +03002983static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
2984 struct ieee80211_vif *vif,
2985 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002986{
2987 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002988 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2989
2990 /* This is case only for P2P_GO */
2991 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
2992 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
2993 return;
2994
2995 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
2996 spin_lock_bh(&ar->data_lock);
2997 if (arvif->u.ap.noa_data)
2998 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
2999 GFP_ATOMIC))
3000 memcpy(skb_put(skb, arvif->u.ap.noa_len),
3001 arvif->u.ap.noa_data,
3002 arvif->u.ap.noa_len);
3003 spin_unlock_bh(&ar->data_lock);
3004 }
3005}
3006
Michal Kazior8d6d3622014-11-24 14:58:31 +01003007static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar)
3008{
3009 /* FIXME: Not really sure since when the behaviour changed. At some
3010 * point new firmware stopped requiring creation of peer entries for
3011 * offchannel tx (and actually creating them causes issues with wmi-htc
3012 * tx credit replenishment and reliability). Assuming it's at least 3.4
3013 * because that's when the `freq` was introduced to TX_FRM HTT command.
3014 */
3015 return !(ar->htt.target_version_major >= 3 &&
3016 ar->htt.target_version_minor >= 4);
3017}
3018
Michal Kaziord740d8f2015-03-30 09:51:51 +03003019static int ath10k_mac_tx_wmi_mgmt(struct ath10k *ar, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003020{
Michal Kaziord740d8f2015-03-30 09:51:51 +03003021 struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003022 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003023
Michal Kaziord740d8f2015-03-30 09:51:51 +03003024 spin_lock_bh(&ar->data_lock);
3025
3026 if (skb_queue_len(q) == ATH10K_MAX_NUM_MGMT_PENDING) {
3027 ath10k_warn(ar, "wmi mgmt tx queue is full\n");
3028 ret = -ENOSPC;
3029 goto unlock;
Michal Kazior961d4c32013-08-09 10:13:34 +02003030 }
3031
Michal Kaziord740d8f2015-03-30 09:51:51 +03003032 __skb_queue_tail(q, skb);
3033 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
3034
3035unlock:
3036 spin_unlock_bh(&ar->data_lock);
3037
3038 return ret;
3039}
3040
3041static void ath10k_mac_tx(struct ath10k *ar, struct sk_buff *skb)
3042{
3043 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3044 struct ath10k_htt *htt = &ar->htt;
3045 int ret = 0;
3046
3047 switch (cb->txmode) {
3048 case ATH10K_HW_TXRX_RAW:
3049 case ATH10K_HW_TXRX_NATIVE_WIFI:
3050 case ATH10K_HW_TXRX_ETHERNET:
3051 ret = ath10k_htt_tx(htt, skb);
3052 break;
3053 case ATH10K_HW_TXRX_MGMT:
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003054 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
Michal Kaziord740d8f2015-03-30 09:51:51 +03003055 ar->fw_features))
3056 ret = ath10k_mac_tx_wmi_mgmt(ar, skb);
3057 else if (ar->htt.target_version_major >= 3)
3058 ret = ath10k_htt_tx(htt, skb);
3059 else
3060 ret = ath10k_htt_mgmt_tx(htt, skb);
3061 break;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003062 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003063
3064 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003065 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
3066 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003067 ieee80211_free_txskb(ar->hw, skb);
3068 }
3069}
3070
3071void ath10k_offchan_tx_purge(struct ath10k *ar)
3072{
3073 struct sk_buff *skb;
3074
3075 for (;;) {
3076 skb = skb_dequeue(&ar->offchan_tx_queue);
3077 if (!skb)
3078 break;
3079
3080 ieee80211_free_txskb(ar->hw, skb);
3081 }
3082}
3083
3084void ath10k_offchan_tx_work(struct work_struct *work)
3085{
3086 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
3087 struct ath10k_peer *peer;
3088 struct ieee80211_hdr *hdr;
3089 struct sk_buff *skb;
3090 const u8 *peer_addr;
3091 int vdev_id;
3092 int ret;
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +03003093 unsigned long time_left;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003094
3095 /* FW requirement: We must create a peer before FW will send out
3096 * an offchannel frame. Otherwise the frame will be stuck and
3097 * never transmitted. We delete the peer upon tx completion.
3098 * It is unlikely that a peer for offchannel tx will already be
3099 * present. However it may be in some rare cases so account for that.
3100 * Otherwise we might remove a legitimate peer and break stuff. */
3101
3102 for (;;) {
3103 skb = skb_dequeue(&ar->offchan_tx_queue);
3104 if (!skb)
3105 break;
3106
3107 mutex_lock(&ar->conf_mutex);
3108
Michal Kazior7aa7a722014-08-25 12:09:38 +02003109 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003110 skb);
3111
3112 hdr = (struct ieee80211_hdr *)skb->data;
3113 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003114 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003115
3116 spin_lock_bh(&ar->data_lock);
3117 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
3118 spin_unlock_bh(&ar->data_lock);
3119
3120 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03003121 /* FIXME: should this use ath10k_warn()? */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003122 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003123 peer_addr, vdev_id);
3124
3125 if (!peer) {
Marek Puzyniak7390ed32015-03-30 09:51:52 +03003126 ret = ath10k_peer_create(ar, vdev_id, peer_addr,
3127 WMI_PEER_TYPE_DEFAULT);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003128 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003129 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003130 peer_addr, vdev_id, ret);
3131 }
3132
3133 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08003134 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003135 ar->offchan_tx_skb = skb;
3136 spin_unlock_bh(&ar->data_lock);
3137
Michal Kaziord740d8f2015-03-30 09:51:51 +03003138 ath10k_mac_tx(ar, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003139
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +03003140 time_left =
3141 wait_for_completion_timeout(&ar->offchan_tx_completed, 3 * HZ);
3142 if (time_left == 0)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003143 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003144 skb);
3145
3146 if (!peer) {
3147 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
3148 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003149 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003150 peer_addr, vdev_id, ret);
3151 }
3152
3153 mutex_unlock(&ar->conf_mutex);
3154 }
3155}
3156
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003157void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
3158{
3159 struct sk_buff *skb;
3160
3161 for (;;) {
3162 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3163 if (!skb)
3164 break;
3165
3166 ieee80211_free_txskb(ar->hw, skb);
3167 }
3168}
3169
3170void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
3171{
3172 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
3173 struct sk_buff *skb;
3174 int ret;
3175
3176 for (;;) {
3177 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3178 if (!skb)
3179 break;
3180
3181 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01003182 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003183 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02003184 ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01003185 ieee80211_free_txskb(ar->hw, skb);
3186 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003187 }
3188}
3189
Kalle Valo5e3dd152013-06-12 20:52:10 +03003190/************/
3191/* Scanning */
3192/************/
3193
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003194void __ath10k_scan_finish(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003195{
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003196 lockdep_assert_held(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003197
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003198 switch (ar->scan.state) {
3199 case ATH10K_SCAN_IDLE:
3200 break;
3201 case ATH10K_SCAN_RUNNING:
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003202 if (ar->scan.is_roc)
3203 ieee80211_remain_on_channel_expired(ar->hw);
John W. Linvillef6eaf1e2015-01-12 16:07:02 -05003204 /* fall through */
Michal Kazior7305d3e2014-11-24 14:58:33 +01003205 case ATH10K_SCAN_ABORTING:
3206 if (!ar->scan.is_roc)
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003207 ieee80211_scan_completed(ar->hw,
3208 (ar->scan.state ==
3209 ATH10K_SCAN_ABORTING));
3210 /* fall through */
3211 case ATH10K_SCAN_STARTING:
3212 ar->scan.state = ATH10K_SCAN_IDLE;
3213 ar->scan_channel = NULL;
3214 ath10k_offchan_tx_purge(ar);
3215 cancel_delayed_work(&ar->scan.timeout);
3216 complete_all(&ar->scan.completed);
3217 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003218 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003219}
Kalle Valo5e3dd152013-06-12 20:52:10 +03003220
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003221void ath10k_scan_finish(struct ath10k *ar)
3222{
3223 spin_lock_bh(&ar->data_lock);
3224 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003225 spin_unlock_bh(&ar->data_lock);
3226}
3227
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003228static int ath10k_scan_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003229{
3230 struct wmi_stop_scan_arg arg = {
3231 .req_id = 1, /* FIXME */
3232 .req_type = WMI_SCAN_STOP_ONE,
3233 .u.scan_id = ATH10K_SCAN_ID,
3234 };
3235 int ret;
3236
3237 lockdep_assert_held(&ar->conf_mutex);
3238
Kalle Valo5e3dd152013-06-12 20:52:10 +03003239 ret = ath10k_wmi_stop_scan(ar, &arg);
3240 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003241 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003242 goto out;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003243 }
3244
Kalle Valo5e3dd152013-06-12 20:52:10 +03003245 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003246 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003247 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003248 ret = -ETIMEDOUT;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003249 } else if (ret > 0) {
3250 ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003251 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003252
3253out:
3254 /* Scan state should be updated upon scan completion but in case
3255 * firmware fails to deliver the event (for whatever reason) it is
3256 * desired to clean up scan state anyway. Firmware may have just
3257 * dropped the scan completion event delivery due to transport pipe
3258 * being overflown with data and/or it can recover on its own before
3259 * next scan request is submitted.
3260 */
3261 spin_lock_bh(&ar->data_lock);
3262 if (ar->scan.state != ATH10K_SCAN_IDLE)
3263 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003264 spin_unlock_bh(&ar->data_lock);
3265
3266 return ret;
3267}
3268
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003269static void ath10k_scan_abort(struct ath10k *ar)
3270{
3271 int ret;
3272
3273 lockdep_assert_held(&ar->conf_mutex);
3274
3275 spin_lock_bh(&ar->data_lock);
3276
3277 switch (ar->scan.state) {
3278 case ATH10K_SCAN_IDLE:
3279 /* This can happen if timeout worker kicked in and called
3280 * abortion while scan completion was being processed.
3281 */
3282 break;
3283 case ATH10K_SCAN_STARTING:
3284 case ATH10K_SCAN_ABORTING:
Michal Kazior7aa7a722014-08-25 12:09:38 +02003285 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003286 ath10k_scan_state_str(ar->scan.state),
3287 ar->scan.state);
3288 break;
3289 case ATH10K_SCAN_RUNNING:
3290 ar->scan.state = ATH10K_SCAN_ABORTING;
3291 spin_unlock_bh(&ar->data_lock);
3292
3293 ret = ath10k_scan_stop(ar);
3294 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003295 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003296
3297 spin_lock_bh(&ar->data_lock);
3298 break;
3299 }
3300
3301 spin_unlock_bh(&ar->data_lock);
3302}
3303
3304void ath10k_scan_timeout_work(struct work_struct *work)
3305{
3306 struct ath10k *ar = container_of(work, struct ath10k,
3307 scan.timeout.work);
3308
3309 mutex_lock(&ar->conf_mutex);
3310 ath10k_scan_abort(ar);
3311 mutex_unlock(&ar->conf_mutex);
3312}
3313
Kalle Valo5e3dd152013-06-12 20:52:10 +03003314static int ath10k_start_scan(struct ath10k *ar,
3315 const struct wmi_start_scan_arg *arg)
3316{
3317 int ret;
3318
3319 lockdep_assert_held(&ar->conf_mutex);
3320
3321 ret = ath10k_wmi_start_scan(ar, arg);
3322 if (ret)
3323 return ret;
3324
Kalle Valo5e3dd152013-06-12 20:52:10 +03003325 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
3326 if (ret == 0) {
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003327 ret = ath10k_scan_stop(ar);
3328 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003329 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003330
3331 return -ETIMEDOUT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003332 }
3333
Ben Greear2f9eec02015-02-15 16:50:38 +02003334 /* If we failed to start the scan, return error code at
3335 * this point. This is probably due to some issue in the
3336 * firmware, but no need to wedge the driver due to that...
3337 */
3338 spin_lock_bh(&ar->data_lock);
3339 if (ar->scan.state == ATH10K_SCAN_IDLE) {
3340 spin_unlock_bh(&ar->data_lock);
3341 return -EINVAL;
3342 }
3343 spin_unlock_bh(&ar->data_lock);
3344
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003345 /* Add a 200ms margin to account for event/command processing */
3346 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
3347 msecs_to_jiffies(arg->max_scan_time+200));
Kalle Valo5e3dd152013-06-12 20:52:10 +03003348 return 0;
3349}
3350
3351/**********************/
3352/* mac80211 callbacks */
3353/**********************/
3354
3355static void ath10k_tx(struct ieee80211_hw *hw,
3356 struct ieee80211_tx_control *control,
3357 struct sk_buff *skb)
3358{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003359 struct ath10k *ar = hw->priv;
Michal Kazior4b604552014-07-21 21:03:09 +03003360 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3361 struct ieee80211_vif *vif = info->control.vif;
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003362 struct ieee80211_sta *sta = control->sta;
Michal Kazior4b604552014-07-21 21:03:09 +03003363 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Michal Kaziord740d8f2015-03-30 09:51:51 +03003364 __le16 fc = hdr->frame_control;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003365
3366 /* We should disable CCK RATE due to P2P */
3367 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003368 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003369
Michal Kazior4b604552014-07-21 21:03:09 +03003370 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
Michal Kazior6fcafef2015-03-30 09:51:51 +03003371 ATH10K_SKB_CB(skb)->htt.freq = 0;
Michal Kazior4b604552014-07-21 21:03:09 +03003372 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
Michal Kazior2b37c292014-09-02 11:00:22 +03003373 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003374 ATH10K_SKB_CB(skb)->txmode = ath10k_tx_h_get_txmode(ar, vif, sta, skb);
Michal Kaziord740d8f2015-03-30 09:51:51 +03003375 ATH10K_SKB_CB(skb)->is_protected = ieee80211_has_protected(fc);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003376
Michal Kaziord740d8f2015-03-30 09:51:51 +03003377 switch (ATH10K_SKB_CB(skb)->txmode) {
3378 case ATH10K_HW_TXRX_MGMT:
3379 case ATH10K_HW_TXRX_NATIVE_WIFI:
Michal Kazior4b604552014-07-21 21:03:09 +03003380 ath10k_tx_h_nwifi(hw, skb);
Michal Kazior4b604552014-07-21 21:03:09 +03003381 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
3382 ath10k_tx_h_seq_no(vif, skb);
Michal Kaziord740d8f2015-03-30 09:51:51 +03003383 break;
3384 case ATH10K_HW_TXRX_ETHERNET:
3385 ath10k_tx_h_8023(skb);
3386 break;
3387 case ATH10K_HW_TXRX_RAW:
3388 /* FIXME: Packet injection isn't implemented. It should be
3389 * doable with firmware 10.2 on qca988x.
3390 */
3391 WARN_ON_ONCE(1);
3392 ieee80211_free_txskb(hw, skb);
3393 return;
Michal Kaziorcf84bd42013-07-16 11:04:54 +02003394 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003395
Kalle Valo5e3dd152013-06-12 20:52:10 +03003396 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
3397 spin_lock_bh(&ar->data_lock);
Michal Kazior8d6d3622014-11-24 14:58:31 +01003398 ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003399 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003400 spin_unlock_bh(&ar->data_lock);
3401
Michal Kazior8d6d3622014-11-24 14:58:31 +01003402 if (ath10k_mac_need_offchan_tx_work(ar)) {
3403 ATH10K_SKB_CB(skb)->htt.freq = 0;
3404 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003405
Michal Kazior8d6d3622014-11-24 14:58:31 +01003406 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
3407 skb);
3408
3409 skb_queue_tail(&ar->offchan_tx_queue, skb);
3410 ieee80211_queue_work(hw, &ar->offchan_tx_work);
3411 return;
3412 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003413 }
3414
Michal Kaziord740d8f2015-03-30 09:51:51 +03003415 ath10k_mac_tx(ar, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003416}
3417
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003418/* Must not be called with conf_mutex held as workers can use that also. */
Michal Kazior7962b0d2014-10-28 10:34:38 +01003419void ath10k_drain_tx(struct ath10k *ar)
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003420{
3421 /* make sure rcu-protected mac80211 tx path itself is drained */
3422 synchronize_net();
3423
3424 ath10k_offchan_tx_purge(ar);
3425 ath10k_mgmt_over_wmi_tx_purge(ar);
3426
3427 cancel_work_sync(&ar->offchan_tx_work);
3428 cancel_work_sync(&ar->wmi_mgmt_tx_work);
3429}
3430
Michal Kazioraffd3212013-07-16 09:54:35 +02003431void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02003432{
Michal Kaziord9bc4b92014-04-23 19:30:06 +03003433 struct ath10k_vif *arvif;
3434
Michal Kazior818bdd12013-07-16 09:38:57 +02003435 lockdep_assert_held(&ar->conf_mutex);
3436
Michal Kazior19337472014-08-28 12:58:16 +02003437 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
3438 ar->filter_flags = 0;
3439 ar->monitor = false;
Michal Kazior500ff9f2015-03-31 10:26:21 +00003440 ar->monitor_arvif = NULL;
Michal Kazior19337472014-08-28 12:58:16 +02003441
3442 if (ar->monitor_started)
Michal Kazior1bbc0972014-04-08 09:45:47 +03003443 ath10k_monitor_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +02003444
3445 ar->monitor_started = false;
Michal Kazior1bbc0972014-04-08 09:45:47 +03003446
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003447 ath10k_scan_finish(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02003448 ath10k_peer_cleanup_all(ar);
3449 ath10k_core_stop(ar);
3450 ath10k_hif_power_down(ar);
3451
3452 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03003453 list_for_each_entry(arvif, &ar->arvifs, list)
3454 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kazior818bdd12013-07-16 09:38:57 +02003455 spin_unlock_bh(&ar->data_lock);
3456}
3457
Ben Greear46acf7b2014-05-16 17:15:38 +03003458static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
3459{
3460 struct ath10k *ar = hw->priv;
3461
3462 mutex_lock(&ar->conf_mutex);
3463
3464 if (ar->cfg_tx_chainmask) {
3465 *tx_ant = ar->cfg_tx_chainmask;
3466 *rx_ant = ar->cfg_rx_chainmask;
3467 } else {
3468 *tx_ant = ar->supp_tx_chainmask;
3469 *rx_ant = ar->supp_rx_chainmask;
3470 }
3471
3472 mutex_unlock(&ar->conf_mutex);
3473
3474 return 0;
3475}
3476
Ben Greear5572a952014-11-24 16:22:10 +02003477static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
3478{
3479 /* It is not clear that allowing gaps in chainmask
3480 * is helpful. Probably it will not do what user
3481 * is hoping for, so warn in that case.
3482 */
3483 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
3484 return;
3485
3486 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
3487 dbg, cm);
3488}
3489
Ben Greear46acf7b2014-05-16 17:15:38 +03003490static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
3491{
3492 int ret;
3493
3494 lockdep_assert_held(&ar->conf_mutex);
3495
Ben Greear5572a952014-11-24 16:22:10 +02003496 ath10k_check_chain_mask(ar, tx_ant, "tx");
3497 ath10k_check_chain_mask(ar, rx_ant, "rx");
3498
Ben Greear46acf7b2014-05-16 17:15:38 +03003499 ar->cfg_tx_chainmask = tx_ant;
3500 ar->cfg_rx_chainmask = rx_ant;
3501
3502 if ((ar->state != ATH10K_STATE_ON) &&
3503 (ar->state != ATH10K_STATE_RESTARTED))
3504 return 0;
3505
3506 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
3507 tx_ant);
3508 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003509 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03003510 ret, tx_ant);
3511 return ret;
3512 }
3513
3514 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
3515 rx_ant);
3516 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003517 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03003518 ret, rx_ant);
3519 return ret;
3520 }
3521
3522 return 0;
3523}
3524
3525static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
3526{
3527 struct ath10k *ar = hw->priv;
3528 int ret;
3529
3530 mutex_lock(&ar->conf_mutex);
3531 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
3532 mutex_unlock(&ar->conf_mutex);
3533 return ret;
3534}
3535
Kalle Valo5e3dd152013-06-12 20:52:10 +03003536static int ath10k_start(struct ieee80211_hw *hw)
3537{
3538 struct ath10k *ar = hw->priv;
Michal Kazior818bdd12013-07-16 09:38:57 +02003539 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003540
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003541 /*
3542 * This makes sense only when restarting hw. It is harmless to call
3543 * uncoditionally. This is necessary to make sure no HTT/WMI tx
3544 * commands will be submitted while restarting.
3545 */
3546 ath10k_drain_tx(ar);
3547
Michal Kazior548db542013-07-05 16:15:15 +03003548 mutex_lock(&ar->conf_mutex);
3549
Michal Kaziorc5058f52014-05-26 12:46:03 +03003550 switch (ar->state) {
3551 case ATH10K_STATE_OFF:
3552 ar->state = ATH10K_STATE_ON;
3553 break;
3554 case ATH10K_STATE_RESTARTING:
3555 ath10k_halt(ar);
3556 ar->state = ATH10K_STATE_RESTARTED;
3557 break;
3558 case ATH10K_STATE_ON:
3559 case ATH10K_STATE_RESTARTED:
3560 case ATH10K_STATE_WEDGED:
3561 WARN_ON(1);
Michal Kazior818bdd12013-07-16 09:38:57 +02003562 ret = -EINVAL;
Michal Kaziorae254432014-05-26 12:46:02 +03003563 goto err;
Kalle Valo43d2a302014-09-10 18:23:30 +03003564 case ATH10K_STATE_UTF:
3565 ret = -EBUSY;
3566 goto err;
Michal Kazior818bdd12013-07-16 09:38:57 +02003567 }
3568
3569 ret = ath10k_hif_power_up(ar);
3570 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003571 ath10k_err(ar, "Could not init hif: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003572 goto err_off;
Michal Kazior818bdd12013-07-16 09:38:57 +02003573 }
3574
Kalle Valo43d2a302014-09-10 18:23:30 +03003575 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
Michal Kazior818bdd12013-07-16 09:38:57 +02003576 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003577 ath10k_err(ar, "Could not init core: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003578 goto err_power_down;
Michal Kazior818bdd12013-07-16 09:38:57 +02003579 }
3580
Bartosz Markowski226a3392013-09-26 17:47:16 +02003581 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03003582 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003583 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003584 goto err_core_stop;
3585 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003586
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01003587 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03003588 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003589 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003590 goto err_core_stop;
3591 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003592
Ben Greear46acf7b2014-05-16 17:15:38 +03003593 if (ar->cfg_tx_chainmask)
3594 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
3595 ar->cfg_rx_chainmask);
3596
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003597 /*
3598 * By default FW set ARP frames ac to voice (6). In that case ARP
3599 * exchange is not working properly for UAPSD enabled AP. ARP requests
3600 * which arrives with access category 0 are processed by network stack
3601 * and send back with access category 0, but FW changes access category
3602 * to 6. Set ARP frames access category to best effort (0) solves
3603 * this problem.
3604 */
3605
3606 ret = ath10k_wmi_pdev_set_param(ar,
3607 ar->wmi.pdev_param->arp_ac_override, 0);
3608 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003609 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003610 ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003611 goto err_core_stop;
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003612 }
3613
Ashok Raj Nagarajan575f1c32015-03-19 16:37:59 +05303614 ret = ath10k_wmi_pdev_set_param(ar,
3615 ar->wmi.pdev_param->ani_enable, 1);
3616 if (ret) {
3617 ath10k_warn(ar, "failed to enable ani by default: %d\n",
3618 ret);
3619 goto err_core_stop;
3620 }
3621
Ashok Raj Nagarajanb3e71d72015-03-19 16:38:00 +05303622 ar->ani_enabled = true;
3623
Michal Kaziord6500972014-04-08 09:56:09 +03003624 ar->num_started_vdevs = 0;
Michal Kaziorf7843d72013-07-16 09:38:52 +02003625 ath10k_regd_update(ar);
3626
Simon Wunderlich855aed12014-08-02 09:12:54 +03003627 ath10k_spectral_start(ar);
Rajkumar Manoharan8515b5c2015-03-15 20:36:22 +05303628 ath10k_thermal_set_throttling(ar);
Simon Wunderlich855aed12014-08-02 09:12:54 +03003629
Michal Kaziorae254432014-05-26 12:46:02 +03003630 mutex_unlock(&ar->conf_mutex);
3631 return 0;
3632
3633err_core_stop:
3634 ath10k_core_stop(ar);
3635
3636err_power_down:
3637 ath10k_hif_power_down(ar);
3638
3639err_off:
3640 ar->state = ATH10K_STATE_OFF;
3641
3642err:
Michal Kazior548db542013-07-05 16:15:15 +03003643 mutex_unlock(&ar->conf_mutex);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01003644 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003645}
3646
3647static void ath10k_stop(struct ieee80211_hw *hw)
3648{
3649 struct ath10k *ar = hw->priv;
3650
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003651 ath10k_drain_tx(ar);
3652
Michal Kazior548db542013-07-05 16:15:15 +03003653 mutex_lock(&ar->conf_mutex);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003654 if (ar->state != ATH10K_STATE_OFF) {
Michal Kazior818bdd12013-07-16 09:38:57 +02003655 ath10k_halt(ar);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003656 ar->state = ATH10K_STATE_OFF;
3657 }
Michal Kazior548db542013-07-05 16:15:15 +03003658 mutex_unlock(&ar->conf_mutex);
3659
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003660 cancel_delayed_work_sync(&ar->scan.timeout);
Michal Kazioraffd3212013-07-16 09:54:35 +02003661 cancel_work_sync(&ar->restart_work);
3662}
3663
Michal Kaziorad088bf2013-10-16 15:44:46 +03003664static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02003665{
Michal Kaziorad088bf2013-10-16 15:44:46 +03003666 struct ath10k_vif *arvif;
3667 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02003668
3669 lockdep_assert_held(&ar->conf_mutex);
3670
Michal Kaziorad088bf2013-10-16 15:44:46 +03003671 list_for_each_entry(arvif, &ar->arvifs, list) {
3672 ret = ath10k_mac_vif_setup_ps(arvif);
3673 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003674 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03003675 break;
3676 }
3677 }
Michal Kazioraffd3212013-07-16 09:54:35 +02003678
Michal Kaziorad088bf2013-10-16 15:44:46 +03003679 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003680}
3681
Michal Kazior500ff9f2015-03-31 10:26:21 +00003682static void ath10k_mac_chan_reconfigure(struct ath10k *ar)
Michal Kaziorc930f742014-01-23 11:38:25 +01003683{
3684 struct ath10k_vif *arvif;
Michal Kazior500ff9f2015-03-31 10:26:21 +00003685 struct cfg80211_chan_def def;
Michal Kaziorc930f742014-01-23 11:38:25 +01003686 int ret;
3687
3688 lockdep_assert_held(&ar->conf_mutex);
3689
Michal Kazior500ff9f2015-03-31 10:26:21 +00003690 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac chan reconfigure\n");
Michal Kaziorc930f742014-01-23 11:38:25 +01003691
3692 /* First stop monitor interface. Some FW versions crash if there's a
3693 * lone monitor interface. */
Michal Kazior1bbc0972014-04-08 09:45:47 +03003694 if (ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02003695 ath10k_monitor_stop(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003696
3697 list_for_each_entry(arvif, &ar->arvifs, list) {
3698 if (!arvif->is_started)
3699 continue;
3700
Michal Kaziordc55e302014-07-29 12:53:36 +03003701 if (!arvif->is_up)
3702 continue;
3703
Michal Kaziorc930f742014-01-23 11:38:25 +01003704 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3705 continue;
3706
Michal Kaziordc55e302014-07-29 12:53:36 +03003707 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kaziorc930f742014-01-23 11:38:25 +01003708 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003709 ath10k_warn(ar, "failed to down vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003710 arvif->vdev_id, ret);
3711 continue;
3712 }
3713 }
3714
Michal Kaziordc55e302014-07-29 12:53:36 +03003715 /* all vdevs are downed now - attempt to restart and re-up them */
Michal Kaziorc930f742014-01-23 11:38:25 +01003716
3717 list_for_each_entry(arvif, &ar->arvifs, list) {
3718 if (!arvif->is_started)
3719 continue;
3720
3721 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3722 continue;
3723
Michal Kazior81a9a172015-03-05 16:02:17 +02003724 ret = ath10k_mac_setup_bcn_tmpl(arvif);
3725 if (ret)
3726 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
3727 ret);
3728
3729 ret = ath10k_mac_setup_prb_tmpl(arvif);
3730 if (ret)
3731 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
3732 ret);
3733
Michal Kazior500ff9f2015-03-31 10:26:21 +00003734 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
3735 continue;
3736
3737 ret = ath10k_vdev_restart(arvif, &def);
Michal Kaziorc930f742014-01-23 11:38:25 +01003738 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003739 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003740 arvif->vdev_id, ret);
3741 continue;
3742 }
3743
3744 if (!arvif->is_up)
3745 continue;
3746
3747 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
3748 arvif->bssid);
3749 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003750 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003751 arvif->vdev_id, ret);
3752 continue;
3753 }
3754 }
3755
Michal Kazior19337472014-08-28 12:58:16 +02003756 ath10k_monitor_recalc(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003757}
3758
Michal Kazior7d9d5582014-10-21 10:40:15 +03003759static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
3760{
3761 int ret;
3762 u32 param;
3763
3764 lockdep_assert_held(&ar->conf_mutex);
3765
3766 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
3767
3768 param = ar->wmi.pdev_param->txpower_limit2g;
3769 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3770 if (ret) {
3771 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
3772 txpower, ret);
3773 return ret;
3774 }
3775
3776 param = ar->wmi.pdev_param->txpower_limit5g;
3777 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3778 if (ret) {
3779 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
3780 txpower, ret);
3781 return ret;
3782 }
3783
3784 return 0;
3785}
3786
3787static int ath10k_mac_txpower_recalc(struct ath10k *ar)
3788{
3789 struct ath10k_vif *arvif;
3790 int ret, txpower = -1;
3791
3792 lockdep_assert_held(&ar->conf_mutex);
3793
3794 list_for_each_entry(arvif, &ar->arvifs, list) {
3795 WARN_ON(arvif->txpower < 0);
3796
3797 if (txpower == -1)
3798 txpower = arvif->txpower;
3799 else
3800 txpower = min(txpower, arvif->txpower);
3801 }
3802
3803 if (WARN_ON(txpower == -1))
3804 return -EINVAL;
3805
3806 ret = ath10k_mac_txpower_setup(ar, txpower);
3807 if (ret) {
3808 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
3809 txpower, ret);
3810 return ret;
3811 }
3812
3813 return 0;
3814}
3815
Kalle Valo5e3dd152013-06-12 20:52:10 +03003816static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
3817{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003818 struct ath10k *ar = hw->priv;
3819 struct ieee80211_conf *conf = &hw->conf;
3820 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003821
3822 mutex_lock(&ar->conf_mutex);
3823
Michal Kazioraffd3212013-07-16 09:54:35 +02003824 if (changed & IEEE80211_CONF_CHANGE_PS)
3825 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003826
3827 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
Michal Kazior19337472014-08-28 12:58:16 +02003828 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
3829 ret = ath10k_monitor_recalc(ar);
3830 if (ret)
3831 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003832 }
3833
3834 mutex_unlock(&ar->conf_mutex);
3835 return ret;
3836}
3837
Ben Greear5572a952014-11-24 16:22:10 +02003838static u32 get_nss_from_chainmask(u16 chain_mask)
3839{
3840 if ((chain_mask & 0x15) == 0x15)
3841 return 4;
3842 else if ((chain_mask & 0x7) == 0x7)
3843 return 3;
3844 else if ((chain_mask & 0x3) == 0x3)
3845 return 2;
3846 return 1;
3847}
3848
Kalle Valo5e3dd152013-06-12 20:52:10 +03003849/*
3850 * TODO:
3851 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
3852 * because we will send mgmt frames without CCK. This requirement
3853 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
3854 * in the TX packet.
3855 */
3856static int ath10k_add_interface(struct ieee80211_hw *hw,
3857 struct ieee80211_vif *vif)
3858{
3859 struct ath10k *ar = hw->priv;
3860 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3861 enum wmi_sta_powersave_param param;
3862 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02003863 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003864 int bit;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003865 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003866
Johannes Berg848955c2014-11-11 12:48:42 +01003867 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
3868
Kalle Valo5e3dd152013-06-12 20:52:10 +03003869 mutex_lock(&ar->conf_mutex);
3870
Michal Kazior0dbd09e2013-07-31 10:55:14 +02003871 memset(arvif, 0, sizeof(*arvif));
3872
Kalle Valo5e3dd152013-06-12 20:52:10 +03003873 arvif->ar = ar;
3874 arvif->vif = vif;
3875
Ben Greeare63b33f2013-10-22 14:54:14 -07003876 INIT_LIST_HEAD(&arvif->list);
Michal Kazior81a9a172015-03-05 16:02:17 +02003877 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
Michal Kaziorcc9904e2015-03-10 16:22:01 +02003878 INIT_DELAYED_WORK(&arvif->connection_loss_work,
3879 ath10k_mac_vif_sta_connection_loss_work);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03003880
Ben Greeara9aefb32014-08-12 11:02:19 +03003881 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003882 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003883 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03003884 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003885 }
Ben Greear16c11172014-09-23 14:17:16 -07003886 bit = __ffs64(ar->free_vdev_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003887
Ben Greear16c11172014-09-23 14:17:16 -07003888 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
3889 bit, ar->free_vdev_map);
3890
3891 arvif->vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003892 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003893
Kalle Valo5e3dd152013-06-12 20:52:10 +03003894 switch (vif->type) {
Michal Kazior75d2bd42014-12-12 12:41:39 +01003895 case NL80211_IFTYPE_P2P_DEVICE:
3896 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3897 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
3898 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003899 case NL80211_IFTYPE_UNSPECIFIED:
3900 case NL80211_IFTYPE_STATION:
3901 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3902 if (vif->p2p)
3903 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
3904 break;
3905 case NL80211_IFTYPE_ADHOC:
3906 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
3907 break;
3908 case NL80211_IFTYPE_AP:
3909 arvif->vdev_type = WMI_VDEV_TYPE_AP;
3910
3911 if (vif->p2p)
3912 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
3913 break;
3914 case NL80211_IFTYPE_MONITOR:
3915 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
3916 break;
3917 default:
3918 WARN_ON(1);
3919 break;
3920 }
3921
Michal Kazior64badcb2014-09-18 11:18:02 +03003922 /* Some firmware revisions don't wait for beacon tx completion before
3923 * sending another SWBA event. This could lead to hardware using old
3924 * (freed) beacon data in some cases, e.g. tx credit starvation
3925 * combined with missed TBTT. This is very very rare.
3926 *
3927 * On non-IOMMU-enabled hosts this could be a possible security issue
3928 * because hw could beacon some random data on the air. On
3929 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
3930 * device would crash.
3931 *
3932 * Since there are no beacon tx completions (implicit nor explicit)
3933 * propagated to host the only workaround for this is to allocate a
3934 * DMA-coherent buffer for a lifetime of a vif and use it for all
3935 * beacon tx commands. Worst case for this approach is some beacons may
3936 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
3937 */
3938 if (vif->type == NL80211_IFTYPE_ADHOC ||
3939 vif->type == NL80211_IFTYPE_AP) {
3940 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
3941 IEEE80211_MAX_FRAME_LEN,
3942 &arvif->beacon_paddr,
Rajkumar Manoharan82d7aba2014-10-10 17:38:27 +05303943 GFP_ATOMIC);
Michal Kazior64badcb2014-09-18 11:18:02 +03003944 if (!arvif->beacon_buf) {
3945 ret = -ENOMEM;
3946 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
3947 ret);
3948 goto err;
3949 }
3950 }
3951
3952 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
3953 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
3954 arvif->beacon_buf ? "single-buf" : "per-skb");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003955
3956 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
3957 arvif->vdev_subtype, vif->addr);
3958 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003959 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003960 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003961 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003962 }
3963
Ben Greear16c11172014-09-23 14:17:16 -07003964 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03003965 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003966
Michal Kazior46725b152015-01-28 09:57:49 +02003967 /* It makes no sense to have firmware do keepalives. mac80211 already
3968 * takes care of this with idle connection polling.
3969 */
3970 ret = ath10k_mac_vif_disable_keepalive(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003971 if (ret) {
Michal Kazior46725b152015-01-28 09:57:49 +02003972 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003973 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003974 goto err_vdev_delete;
3975 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003976
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02003977 arvif->def_wep_key_idx = -1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003978
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003979 vdev_param = ar->wmi.vdev_param->tx_encap_type;
3980 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003981 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02003982 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14a2013-10-16 15:44:45 +03003983 if (ret && ret != -EOPNOTSUPP) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003984 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003985 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003986 goto err_vdev_delete;
3987 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003988
Ben Greear5572a952014-11-24 16:22:10 +02003989 if (ar->cfg_tx_chainmask) {
3990 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
3991
3992 vdev_param = ar->wmi.vdev_param->nss;
3993 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3994 nss);
3995 if (ret) {
3996 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
3997 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
3998 ret);
3999 goto err_vdev_delete;
4000 }
4001 }
4002
Kalle Valo5e3dd152013-06-12 20:52:10 +03004003 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
Marek Puzyniak7390ed32015-03-30 09:51:52 +03004004 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr,
4005 WMI_PEER_TYPE_DEFAULT);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004006 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004007 ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004008 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004009 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004010 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01004011
Kalle Valo5a13e762014-01-20 11:01:46 +02004012 ret = ath10k_mac_set_kickout(arvif);
4013 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004014 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004015 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +02004016 goto err_peer_delete;
4017 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004018 }
4019
4020 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
4021 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
4022 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4023 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4024 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004025 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004026 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004027 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004028 goto err_peer_delete;
4029 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004030
Michal Kazior9f9b5742014-12-12 12:41:36 +01004031 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004032 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01004033 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004034 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004035 goto err_peer_delete;
4036 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004037
Michal Kazior9f9b5742014-12-12 12:41:36 +01004038 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004039 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01004040 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004041 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004042 goto err_peer_delete;
4043 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004044 }
4045
Michal Kazior424121c2013-07-22 14:13:31 +02004046 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004047 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004048 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03004049 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004050 goto err_peer_delete;
4051 }
Michal Kazior679c54a2013-07-05 16:15:04 +03004052
Michal Kazior424121c2013-07-22 14:13:31 +02004053 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004054 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004055 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03004056 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004057 goto err_peer_delete;
4058 }
Michal Kazior679c54a2013-07-05 16:15:04 +03004059
Michal Kazior7d9d5582014-10-21 10:40:15 +03004060 arvif->txpower = vif->bss_conf.txpower;
4061 ret = ath10k_mac_txpower_recalc(ar);
4062 if (ret) {
4063 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
4064 goto err_peer_delete;
4065 }
4066
Michal Kazior500ff9f2015-03-31 10:26:21 +00004067 if (vif->type == NL80211_IFTYPE_MONITOR) {
4068 ar->monitor_arvif = arvif;
4069 ret = ath10k_monitor_recalc(ar);
4070 if (ret) {
4071 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4072 goto err_peer_delete;
4073 }
4074 }
4075
Kalle Valo5e3dd152013-06-12 20:52:10 +03004076 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004077 return 0;
4078
4079err_peer_delete:
4080 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
4081 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
4082
4083err_vdev_delete:
4084 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
Ben Greear16c11172014-09-23 14:17:16 -07004085 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03004086 list_del(&arvif->list);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004087
4088err:
Michal Kazior64badcb2014-09-18 11:18:02 +03004089 if (arvif->beacon_buf) {
4090 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
4091 arvif->beacon_buf, arvif->beacon_paddr);
4092 arvif->beacon_buf = NULL;
4093 }
4094
Michal Kazior9dad14a2013-10-16 15:44:45 +03004095 mutex_unlock(&ar->conf_mutex);
4096
Kalle Valo5e3dd152013-06-12 20:52:10 +03004097 return ret;
4098}
4099
4100static void ath10k_remove_interface(struct ieee80211_hw *hw,
4101 struct ieee80211_vif *vif)
4102{
4103 struct ath10k *ar = hw->priv;
4104 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4105 int ret;
4106
Michal Kazior81a9a172015-03-05 16:02:17 +02004107 cancel_work_sync(&arvif->ap_csa_work);
Michal Kaziorcc9904e2015-03-10 16:22:01 +02004108 cancel_delayed_work_sync(&arvif->connection_loss_work);
Michal Kazior81a9a172015-03-05 16:02:17 +02004109
Sujith Manoharan5d011f52014-11-25 11:47:00 +05304110 mutex_lock(&ar->conf_mutex);
4111
Michal Kaziored543882013-09-13 14:16:56 +02004112 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03004113 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kaziored543882013-09-13 14:16:56 +02004114 spin_unlock_bh(&ar->data_lock);
4115
Simon Wunderlich855aed12014-08-02 09:12:54 +03004116 ret = ath10k_spectral_vif_stop(arvif);
4117 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004118 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03004119 arvif->vdev_id, ret);
4120
Ben Greear16c11172014-09-23 14:17:16 -07004121 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03004122 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004123
4124 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
Michal Kazior2c512052015-02-15 16:50:40 +02004125 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
4126 vif->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004127 if (ret)
Michal Kazior2c512052015-02-15 16:50:40 +02004128 ath10k_warn(ar, "failed to submit AP self-peer removal on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004129 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004130
4131 kfree(arvif->u.ap.noa_data);
4132 }
4133
Michal Kazior7aa7a722014-08-25 12:09:38 +02004134 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004135 arvif->vdev_id);
4136
Kalle Valo5e3dd152013-06-12 20:52:10 +03004137 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
4138 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004139 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004140 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004141
Michal Kazior2c512052015-02-15 16:50:40 +02004142 /* Some firmware revisions don't notify host about self-peer removal
4143 * until after associated vdev is deleted.
4144 */
4145 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
4146 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
4147 vif->addr);
4148 if (ret)
4149 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
4150 arvif->vdev_id, ret);
4151
4152 spin_lock_bh(&ar->data_lock);
4153 ar->num_peers--;
4154 spin_unlock_bh(&ar->data_lock);
4155 }
4156
Kalle Valo5e3dd152013-06-12 20:52:10 +03004157 ath10k_peer_cleanup(ar, arvif->vdev_id);
4158
Michal Kazior500ff9f2015-03-31 10:26:21 +00004159 if (vif->type == NL80211_IFTYPE_MONITOR) {
4160 ar->monitor_arvif = NULL;
4161 ret = ath10k_monitor_recalc(ar);
4162 if (ret)
4163 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4164 }
4165
Kalle Valo5e3dd152013-06-12 20:52:10 +03004166 mutex_unlock(&ar->conf_mutex);
4167}
4168
4169/*
4170 * FIXME: Has to be verified.
4171 */
4172#define SUPPORTED_FILTERS \
4173 (FIF_PROMISC_IN_BSS | \
4174 FIF_ALLMULTI | \
4175 FIF_CONTROL | \
4176 FIF_PSPOLL | \
4177 FIF_OTHER_BSS | \
4178 FIF_BCN_PRBRESP_PROMISC | \
4179 FIF_PROBE_REQ | \
4180 FIF_FCSFAIL)
4181
4182static void ath10k_configure_filter(struct ieee80211_hw *hw,
4183 unsigned int changed_flags,
4184 unsigned int *total_flags,
4185 u64 multicast)
4186{
4187 struct ath10k *ar = hw->priv;
4188 int ret;
4189
4190 mutex_lock(&ar->conf_mutex);
4191
4192 changed_flags &= SUPPORTED_FILTERS;
4193 *total_flags &= SUPPORTED_FILTERS;
4194 ar->filter_flags = *total_flags;
4195
Michal Kazior19337472014-08-28 12:58:16 +02004196 ret = ath10k_monitor_recalc(ar);
4197 if (ret)
4198 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004199
4200 mutex_unlock(&ar->conf_mutex);
4201}
4202
4203static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
4204 struct ieee80211_vif *vif,
4205 struct ieee80211_bss_conf *info,
4206 u32 changed)
4207{
4208 struct ath10k *ar = hw->priv;
4209 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4210 int ret = 0;
Kalle Valoaf762c02014-09-14 12:50:17 +03004211 u32 vdev_param, pdev_param, slottime, preamble;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004212
4213 mutex_lock(&ar->conf_mutex);
4214
4215 if (changed & BSS_CHANGED_IBSS)
4216 ath10k_control_ibss(arvif, info, vif->addr);
4217
4218 if (changed & BSS_CHANGED_BEACON_INT) {
4219 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004220 vdev_param = ar->wmi.vdev_param->beacon_interval;
4221 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004222 arvif->beacon_interval);
Michal Kazior7aa7a722014-08-25 12:09:38 +02004223 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004224 "mac vdev %d beacon_interval %d\n",
4225 arvif->vdev_id, arvif->beacon_interval);
4226
Kalle Valo5e3dd152013-06-12 20:52:10 +03004227 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004228 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004229 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004230 }
4231
4232 if (changed & BSS_CHANGED_BEACON) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004233 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004234 "vdev %d set beacon tx mode to staggered\n",
4235 arvif->vdev_id);
4236
Bartosz Markowski226a3392013-09-26 17:47:16 +02004237 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
4238 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004239 WMI_BEACON_STAGGERED_MODE);
4240 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004241 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004242 arvif->vdev_id, ret);
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02004243
4244 ret = ath10k_mac_setup_bcn_tmpl(arvif);
4245 if (ret)
4246 ath10k_warn(ar, "failed to update beacon template: %d\n",
4247 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004248 }
4249
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02004250 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
4251 ret = ath10k_mac_setup_prb_tmpl(arvif);
4252 if (ret)
4253 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
4254 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004255 }
4256
Michal Kaziorba2479f2015-01-24 12:14:51 +02004257 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004258 arvif->dtim_period = info->dtim_period;
4259
Michal Kazior7aa7a722014-08-25 12:09:38 +02004260 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004261 "mac vdev %d dtim_period %d\n",
4262 arvif->vdev_id, arvif->dtim_period);
4263
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004264 vdev_param = ar->wmi.vdev_param->dtim_period;
4265 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004266 arvif->dtim_period);
4267 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004268 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004269 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004270 }
4271
4272 if (changed & BSS_CHANGED_SSID &&
4273 vif->type == NL80211_IFTYPE_AP) {
4274 arvif->u.ap.ssid_len = info->ssid_len;
4275 if (info->ssid_len)
4276 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
4277 arvif->u.ap.hidden_ssid = info->hidden_ssid;
4278 }
4279
Michal Kazior077efc82014-10-21 10:10:29 +03004280 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
4281 ether_addr_copy(arvif->bssid, info->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004282
4283 if (changed & BSS_CHANGED_BEACON_ENABLED)
4284 ath10k_control_beaconing(arvif, info);
4285
4286 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02004287 arvif->use_cts_prot = info->use_cts_prot;
Michal Kazior7aa7a722014-08-25 12:09:38 +02004288 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02004289 arvif->vdev_id, info->use_cts_prot);
Kalle Valo60c3daa2013-09-08 17:56:07 +03004290
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02004291 ret = ath10k_recalc_rtscts_prot(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004292 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004293 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004294 arvif->vdev_id, ret);
Michal Kaziora87fd4b2015-03-02 11:21:17 +01004295
4296 vdev_param = ar->wmi.vdev_param->protection_mode;
4297 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4298 info->use_cts_prot ? 1 : 0);
4299 if (ret)
4300 ath10k_warn(ar, "failed to set protection mode %d on vdev %i: %d\n",
4301 info->use_cts_prot, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004302 }
4303
4304 if (changed & BSS_CHANGED_ERP_SLOT) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004305 if (info->use_short_slot)
4306 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
4307
4308 else
4309 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
4310
Michal Kazior7aa7a722014-08-25 12:09:38 +02004311 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004312 arvif->vdev_id, slottime);
4313
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004314 vdev_param = ar->wmi.vdev_param->slot_time;
4315 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004316 slottime);
4317 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004318 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004319 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004320 }
4321
4322 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004323 if (info->use_short_preamble)
4324 preamble = WMI_VDEV_PREAMBLE_SHORT;
4325 else
4326 preamble = WMI_VDEV_PREAMBLE_LONG;
4327
Michal Kazior7aa7a722014-08-25 12:09:38 +02004328 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004329 "mac vdev %d preamble %dn",
4330 arvif->vdev_id, preamble);
4331
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004332 vdev_param = ar->wmi.vdev_param->preamble;
4333 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004334 preamble);
4335 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004336 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004337 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004338 }
4339
4340 if (changed & BSS_CHANGED_ASSOC) {
Michal Kaziore556f112014-08-28 12:58:17 +02004341 if (info->assoc) {
4342 /* Workaround: Make sure monitor vdev is not running
4343 * when associating to prevent some firmware revisions
4344 * (e.g. 10.1 and 10.2) from crashing.
4345 */
4346 if (ar->monitor_started)
4347 ath10k_monitor_stop(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004348 ath10k_bss_assoc(hw, vif, info);
Michal Kaziore556f112014-08-28 12:58:17 +02004349 ath10k_monitor_recalc(ar);
Michal Kazior077efc82014-10-21 10:10:29 +03004350 } else {
4351 ath10k_bss_disassoc(hw, vif);
Michal Kaziore556f112014-08-28 12:58:17 +02004352 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004353 }
4354
Michal Kazior7d9d5582014-10-21 10:40:15 +03004355 if (changed & BSS_CHANGED_TXPOWER) {
4356 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
4357 arvif->vdev_id, info->txpower);
4358
4359 arvif->txpower = info->txpower;
4360 ret = ath10k_mac_txpower_recalc(ar);
4361 if (ret)
4362 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
4363 }
4364
Michal Kaziorbf14e652014-12-12 12:41:38 +01004365 if (changed & BSS_CHANGED_PS) {
Michal Kaziorcffb41f2015-02-13 13:30:16 +01004366 arvif->ps = vif->bss_conf.ps;
4367
4368 ret = ath10k_config_ps(ar);
Michal Kaziorbf14e652014-12-12 12:41:38 +01004369 if (ret)
4370 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
4371 arvif->vdev_id, ret);
4372 }
4373
Kalle Valo5e3dd152013-06-12 20:52:10 +03004374 mutex_unlock(&ar->conf_mutex);
4375}
4376
4377static int ath10k_hw_scan(struct ieee80211_hw *hw,
4378 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02004379 struct ieee80211_scan_request *hw_req)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004380{
4381 struct ath10k *ar = hw->priv;
4382 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
David Spinadelc56ef672014-02-05 15:21:13 +02004383 struct cfg80211_scan_request *req = &hw_req->req;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004384 struct wmi_start_scan_arg arg;
4385 int ret = 0;
4386 int i;
4387
4388 mutex_lock(&ar->conf_mutex);
4389
4390 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004391 switch (ar->scan.state) {
4392 case ATH10K_SCAN_IDLE:
4393 reinit_completion(&ar->scan.started);
4394 reinit_completion(&ar->scan.completed);
4395 ar->scan.state = ATH10K_SCAN_STARTING;
4396 ar->scan.is_roc = false;
4397 ar->scan.vdev_id = arvif->vdev_id;
4398 ret = 0;
4399 break;
4400 case ATH10K_SCAN_STARTING:
4401 case ATH10K_SCAN_RUNNING:
4402 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004403 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004404 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004405 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004406 spin_unlock_bh(&ar->data_lock);
4407
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004408 if (ret)
4409 goto exit;
4410
Kalle Valo5e3dd152013-06-12 20:52:10 +03004411 memset(&arg, 0, sizeof(arg));
4412 ath10k_wmi_start_scan_init(ar, &arg);
4413 arg.vdev_id = arvif->vdev_id;
4414 arg.scan_id = ATH10K_SCAN_ID;
4415
4416 if (!req->no_cck)
4417 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
4418
4419 if (req->ie_len) {
4420 arg.ie_len = req->ie_len;
4421 memcpy(arg.ie, req->ie, arg.ie_len);
4422 }
4423
4424 if (req->n_ssids) {
4425 arg.n_ssids = req->n_ssids;
4426 for (i = 0; i < arg.n_ssids; i++) {
4427 arg.ssids[i].len = req->ssids[i].ssid_len;
4428 arg.ssids[i].ssid = req->ssids[i].ssid;
4429 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02004430 } else {
4431 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004432 }
4433
4434 if (req->n_channels) {
4435 arg.n_channels = req->n_channels;
4436 for (i = 0; i < arg.n_channels; i++)
4437 arg.channels[i] = req->channels[i]->center_freq;
4438 }
4439
4440 ret = ath10k_start_scan(ar, &arg);
4441 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004442 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004443 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004444 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004445 spin_unlock_bh(&ar->data_lock);
4446 }
4447
4448exit:
4449 mutex_unlock(&ar->conf_mutex);
4450 return ret;
4451}
4452
4453static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
4454 struct ieee80211_vif *vif)
4455{
4456 struct ath10k *ar = hw->priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004457
4458 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004459 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004460 mutex_unlock(&ar->conf_mutex);
Michal Kazior4eb2e162014-10-28 10:23:09 +01004461
4462 cancel_delayed_work_sync(&ar->scan.timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004463}
4464
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004465static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
4466 struct ath10k_vif *arvif,
4467 enum set_key_cmd cmd,
4468 struct ieee80211_key_conf *key)
4469{
4470 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
4471 int ret;
4472
4473 /* 10.1 firmware branch requires default key index to be set to group
4474 * key index after installing it. Otherwise FW/HW Txes corrupted
4475 * frames with multi-vif APs. This is not required for main firmware
4476 * branch (e.g. 636).
4477 *
4478 * FIXME: This has been tested only in AP. It remains unknown if this
4479 * is required for multi-vif STA interfaces on 10.1 */
4480
4481 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
4482 return;
4483
4484 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
4485 return;
4486
4487 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
4488 return;
4489
4490 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4491 return;
4492
4493 if (cmd != SET_KEY)
4494 return;
4495
4496 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4497 key->keyidx);
4498 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004499 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004500 arvif->vdev_id, ret);
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004501}
4502
Kalle Valo5e3dd152013-06-12 20:52:10 +03004503static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
4504 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
4505 struct ieee80211_key_conf *key)
4506{
4507 struct ath10k *ar = hw->priv;
4508 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4509 struct ath10k_peer *peer;
4510 const u8 *peer_addr;
4511 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
4512 key->cipher == WLAN_CIPHER_SUITE_WEP104;
4513 int ret = 0;
Michal Kazior370e5672015-02-18 14:02:26 +01004514 u32 flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004515
Bartosz Markowskid7131c02015-03-10 14:32:19 +01004516 /* this one needs to be done in software */
4517 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
4518 return 1;
4519
Kalle Valo5e3dd152013-06-12 20:52:10 +03004520 if (key->keyidx > WMI_MAX_KEY_INDEX)
4521 return -ENOSPC;
4522
4523 mutex_lock(&ar->conf_mutex);
4524
4525 if (sta)
4526 peer_addr = sta->addr;
4527 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
4528 peer_addr = vif->bss_conf.bssid;
4529 else
4530 peer_addr = vif->addr;
4531
4532 key->hw_key_idx = key->keyidx;
4533
4534 /* the peer should not disappear in mid-way (unless FW goes awry) since
4535 * we already hold conf_mutex. we just make sure its there now. */
4536 spin_lock_bh(&ar->data_lock);
4537 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4538 spin_unlock_bh(&ar->data_lock);
4539
4540 if (!peer) {
4541 if (cmd == SET_KEY) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004542 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03004543 peer_addr);
4544 ret = -EOPNOTSUPP;
4545 goto exit;
4546 } else {
4547 /* if the peer doesn't exist there is no key to disable
4548 * anymore */
4549 goto exit;
4550 }
4551 }
4552
Michal Kazior7cc45732015-03-09 14:24:17 +01004553 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4554 flags |= WMI_KEY_PAIRWISE;
4555 else
4556 flags |= WMI_KEY_GROUP;
4557
Kalle Valo5e3dd152013-06-12 20:52:10 +03004558 if (is_wep) {
4559 if (cmd == SET_KEY)
4560 arvif->wep_keys[key->keyidx] = key;
4561 else
4562 arvif->wep_keys[key->keyidx] = NULL;
4563
4564 if (cmd == DISABLE_KEY)
4565 ath10k_clear_vdev_key(arvif, key);
Michal Kazior370e5672015-02-18 14:02:26 +01004566
Michal Kaziorad325cb2015-02-18 14:02:27 +01004567 /* When WEP keys are uploaded it's possible that there are
4568 * stations associated already (e.g. when merging) without any
4569 * keys. Static WEP needs an explicit per-peer key upload.
4570 */
4571 if (vif->type == NL80211_IFTYPE_ADHOC &&
4572 cmd == SET_KEY)
4573 ath10k_mac_vif_update_wep_key(arvif, key);
4574
Michal Kazior370e5672015-02-18 14:02:26 +01004575 /* 802.1x never sets the def_wep_key_idx so each set_key()
4576 * call changes default tx key.
4577 *
4578 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
4579 * after first set_key().
4580 */
4581 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
4582 flags |= WMI_KEY_TX_USAGE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004583
Michal Kazior7cc45732015-03-09 14:24:17 +01004584 /* mac80211 uploads static WEP keys as groupwise while fw/hw
4585 * requires pairwise keys for non-self peers, i.e. BSSID in STA
4586 * mode and associated stations in AP/IBSS.
4587 *
4588 * Static WEP keys for peer_addr=vif->addr and 802.1X WEP keys
4589 * work fine when mapped directly from mac80211.
4590 *
4591 * Note: When installing first static WEP groupwise key (which
4592 * should be pairwise) def_wep_key_idx isn't known yet (it's
4593 * equal to -1). Since .set_default_unicast_key is called only
4594 * for static WEP it's used to re-upload the key as pairwise.
4595 */
4596 if (arvif->def_wep_key_idx >= 0 &&
4597 memcmp(peer_addr, arvif->vif->addr, ETH_ALEN)) {
4598 flags &= ~WMI_KEY_GROUP;
4599 flags |= WMI_KEY_PAIRWISE;
4600 }
Michal Kazior370e5672015-02-18 14:02:26 +01004601 }
4602
4603 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004604 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004605 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004606 arvif->vdev_id, peer_addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004607 goto exit;
4608 }
4609
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004610 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
4611
Kalle Valo5e3dd152013-06-12 20:52:10 +03004612 spin_lock_bh(&ar->data_lock);
4613 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4614 if (peer && cmd == SET_KEY)
4615 peer->keys[key->keyidx] = key;
4616 else if (peer && cmd == DISABLE_KEY)
4617 peer->keys[key->keyidx] = NULL;
4618 else if (peer == NULL)
4619 /* impossible unless FW goes crazy */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004620 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004621 spin_unlock_bh(&ar->data_lock);
4622
4623exit:
4624 mutex_unlock(&ar->conf_mutex);
4625 return ret;
4626}
4627
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004628static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
4629 struct ieee80211_vif *vif,
4630 int keyidx)
4631{
4632 struct ath10k *ar = hw->priv;
4633 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4634 int ret;
4635
4636 mutex_lock(&arvif->ar->conf_mutex);
4637
4638 if (arvif->ar->state != ATH10K_STATE_ON)
4639 goto unlock;
4640
4641 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
4642 arvif->vdev_id, keyidx);
4643
4644 ret = ath10k_wmi_vdev_set_param(arvif->ar,
4645 arvif->vdev_id,
4646 arvif->ar->wmi.vdev_param->def_keyid,
4647 keyidx);
4648
4649 if (ret) {
4650 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
4651 arvif->vdev_id,
4652 ret);
4653 goto unlock;
4654 }
4655
4656 arvif->def_wep_key_idx = keyidx;
Michal Kazior370e5672015-02-18 14:02:26 +01004657
4658 ret = ath10k_mac_vif_sta_fix_wep_key(arvif);
4659 if (ret) {
4660 ath10k_warn(ar, "failed to fix sta wep key on vdev %i: %d\n",
4661 arvif->vdev_id, ret);
4662 goto unlock;
4663 }
4664
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004665unlock:
4666 mutex_unlock(&arvif->ar->conf_mutex);
4667}
4668
Michal Kazior9797feb2014-02-14 14:49:48 +01004669static void ath10k_sta_rc_update_wk(struct work_struct *wk)
4670{
4671 struct ath10k *ar;
4672 struct ath10k_vif *arvif;
4673 struct ath10k_sta *arsta;
4674 struct ieee80211_sta *sta;
4675 u32 changed, bw, nss, smps;
4676 int err;
4677
4678 arsta = container_of(wk, struct ath10k_sta, update_wk);
4679 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
4680 arvif = arsta->arvif;
4681 ar = arvif->ar;
4682
4683 spin_lock_bh(&ar->data_lock);
4684
4685 changed = arsta->changed;
4686 arsta->changed = 0;
4687
4688 bw = arsta->bw;
4689 nss = arsta->nss;
4690 smps = arsta->smps;
4691
4692 spin_unlock_bh(&ar->data_lock);
4693
4694 mutex_lock(&ar->conf_mutex);
4695
4696 if (changed & IEEE80211_RC_BW_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004697 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004698 sta->addr, bw);
4699
4700 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4701 WMI_PEER_CHAN_WIDTH, bw);
4702 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004703 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004704 sta->addr, bw, err);
4705 }
4706
4707 if (changed & IEEE80211_RC_NSS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004708 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004709 sta->addr, nss);
4710
4711 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4712 WMI_PEER_NSS, nss);
4713 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004714 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004715 sta->addr, nss, err);
4716 }
4717
4718 if (changed & IEEE80211_RC_SMPS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004719 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004720 sta->addr, smps);
4721
4722 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4723 WMI_PEER_SMPS_STATE, smps);
4724 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004725 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004726 sta->addr, smps, err);
4727 }
4728
Janusz Dziedzic55884c02014-12-17 12:30:02 +02004729 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
4730 changed & IEEE80211_RC_NSS_CHANGED) {
4731 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004732 sta->addr);
4733
Michal Kazior590922a2014-10-21 10:10:29 +03004734 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004735 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004736 ath10k_warn(ar, "failed to reassociate station: %pM\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004737 sta->addr);
4738 }
4739
Michal Kazior9797feb2014-02-14 14:49:48 +01004740 mutex_unlock(&ar->conf_mutex);
4741}
4742
Marek Puzyniak7c354242015-03-30 09:51:52 +03004743static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif,
4744 struct ieee80211_sta *sta)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004745{
4746 struct ath10k *ar = arvif->ar;
4747
4748 lockdep_assert_held(&ar->conf_mutex);
4749
Marek Puzyniak7c354242015-03-30 09:51:52 +03004750 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004751 return 0;
4752
4753 if (ar->num_stations >= ar->max_num_stations)
4754 return -ENOBUFS;
4755
4756 ar->num_stations++;
4757
4758 return 0;
4759}
4760
Marek Puzyniak7c354242015-03-30 09:51:52 +03004761static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif,
4762 struct ieee80211_sta *sta)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004763{
4764 struct ath10k *ar = arvif->ar;
4765
4766 lockdep_assert_held(&ar->conf_mutex);
4767
Marek Puzyniak7c354242015-03-30 09:51:52 +03004768 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004769 return;
4770
4771 ar->num_stations--;
4772}
4773
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004774struct ath10k_mac_tdls_iter_data {
4775 u32 num_tdls_stations;
4776 struct ieee80211_vif *curr_vif;
4777};
4778
4779static void ath10k_mac_tdls_vif_stations_count_iter(void *data,
4780 struct ieee80211_sta *sta)
4781{
4782 struct ath10k_mac_tdls_iter_data *iter_data = data;
4783 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
4784 struct ieee80211_vif *sta_vif = arsta->arvif->vif;
4785
4786 if (sta->tdls && sta_vif == iter_data->curr_vif)
4787 iter_data->num_tdls_stations++;
4788}
4789
4790static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw *hw,
4791 struct ieee80211_vif *vif)
4792{
4793 struct ath10k_mac_tdls_iter_data data = {};
4794
4795 data.curr_vif = vif;
4796
4797 ieee80211_iterate_stations_atomic(hw,
4798 ath10k_mac_tdls_vif_stations_count_iter,
4799 &data);
4800 return data.num_tdls_stations;
4801}
4802
4803static void ath10k_mac_tdls_vifs_count_iter(void *data, u8 *mac,
4804 struct ieee80211_vif *vif)
4805{
4806 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4807 int *num_tdls_vifs = data;
4808
4809 if (vif->type != NL80211_IFTYPE_STATION)
4810 return;
4811
4812 if (ath10k_mac_tdls_vif_stations_count(arvif->ar->hw, vif) > 0)
4813 (*num_tdls_vifs)++;
4814}
4815
4816static int ath10k_mac_tdls_vifs_count(struct ieee80211_hw *hw)
4817{
4818 int num_tdls_vifs = 0;
4819
4820 ieee80211_iterate_active_interfaces_atomic(hw,
4821 IEEE80211_IFACE_ITER_NORMAL,
4822 ath10k_mac_tdls_vifs_count_iter,
4823 &num_tdls_vifs);
4824 return num_tdls_vifs;
4825}
4826
Kalle Valo5e3dd152013-06-12 20:52:10 +03004827static int ath10k_sta_state(struct ieee80211_hw *hw,
4828 struct ieee80211_vif *vif,
4829 struct ieee80211_sta *sta,
4830 enum ieee80211_sta_state old_state,
4831 enum ieee80211_sta_state new_state)
4832{
4833 struct ath10k *ar = hw->priv;
4834 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01004835 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004836 int ret = 0;
4837
Michal Kazior76f90022014-02-25 09:29:57 +02004838 if (old_state == IEEE80211_STA_NOTEXIST &&
4839 new_state == IEEE80211_STA_NONE) {
4840 memset(arsta, 0, sizeof(*arsta));
4841 arsta->arvif = arvif;
4842 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
4843 }
4844
Michal Kazior9797feb2014-02-14 14:49:48 +01004845 /* cancel must be done outside the mutex to avoid deadlock */
4846 if ((old_state == IEEE80211_STA_NONE &&
4847 new_state == IEEE80211_STA_NOTEXIST))
4848 cancel_work_sync(&arsta->update_wk);
4849
Kalle Valo5e3dd152013-06-12 20:52:10 +03004850 mutex_lock(&ar->conf_mutex);
4851
4852 if (old_state == IEEE80211_STA_NOTEXIST &&
Michal Kazior077efc82014-10-21 10:10:29 +03004853 new_state == IEEE80211_STA_NONE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004854 /*
4855 * New station addition.
4856 */
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004857 enum wmi_peer_type peer_type = WMI_PEER_TYPE_DEFAULT;
4858 u32 num_tdls_stations;
4859 u32 num_tdls_vifs;
4860
Michal Kaziorcfd10612014-11-25 15:16:05 +01004861 ath10k_dbg(ar, ATH10K_DBG_MAC,
4862 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
4863 arvif->vdev_id, sta->addr,
4864 ar->num_stations + 1, ar->max_num_stations,
4865 ar->num_peers + 1, ar->max_num_peers);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004866
Marek Puzyniak7c354242015-03-30 09:51:52 +03004867 ret = ath10k_mac_inc_num_stations(arvif, sta);
Michal Kaziorcfd10612014-11-25 15:16:05 +01004868 if (ret) {
4869 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
4870 ar->max_num_stations);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004871 goto exit;
4872 }
4873
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004874 if (sta->tdls)
4875 peer_type = WMI_PEER_TYPE_TDLS;
4876
Marek Puzyniak7390ed32015-03-30 09:51:52 +03004877 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr,
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004878 peer_type);
Michal Kaziora52c0282014-11-25 15:16:03 +01004879 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004880 ath10k_warn(ar, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
Ben Greear479398b2013-11-04 09:19:34 -08004881 sta->addr, arvif->vdev_id, ret);
Marek Puzyniak7c354242015-03-30 09:51:52 +03004882 ath10k_mac_dec_num_stations(arvif, sta);
Michal Kaziora52c0282014-11-25 15:16:03 +01004883 goto exit;
4884 }
Michal Kazior077efc82014-10-21 10:10:29 +03004885
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004886 if (!sta->tdls)
4887 goto exit;
4888
4889 num_tdls_stations = ath10k_mac_tdls_vif_stations_count(hw, vif);
4890 num_tdls_vifs = ath10k_mac_tdls_vifs_count(hw);
4891
4892 if (num_tdls_vifs >= ar->max_num_tdls_vdevs &&
4893 num_tdls_stations == 0) {
4894 ath10k_warn(ar, "vdev %i exceeded maximum number of tdls vdevs %i\n",
4895 arvif->vdev_id, ar->max_num_tdls_vdevs);
4896 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
4897 ath10k_mac_dec_num_stations(arvif, sta);
4898 ret = -ENOBUFS;
4899 goto exit;
4900 }
4901
4902 if (num_tdls_stations == 0) {
4903 /* This is the first tdls peer in current vif */
4904 enum wmi_tdls_state state = WMI_TDLS_ENABLE_ACTIVE;
4905
4906 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
4907 state);
4908 if (ret) {
4909 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
4910 arvif->vdev_id, ret);
4911 ath10k_peer_delete(ar, arvif->vdev_id,
4912 sta->addr);
4913 ath10k_mac_dec_num_stations(arvif, sta);
4914 goto exit;
4915 }
4916 }
4917
4918 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
4919 WMI_TDLS_PEER_STATE_PEERING);
4920 if (ret) {
4921 ath10k_warn(ar,
4922 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
4923 sta->addr, arvif->vdev_id, ret);
4924 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
4925 ath10k_mac_dec_num_stations(arvif, sta);
4926
4927 if (num_tdls_stations != 0)
4928 goto exit;
4929 ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
4930 WMI_TDLS_DISABLE);
4931 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004932 } else if ((old_state == IEEE80211_STA_NONE &&
4933 new_state == IEEE80211_STA_NOTEXIST)) {
4934 /*
4935 * Existing station deletion.
4936 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004937 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004938 "mac vdev %d peer delete %pM (sta gone)\n",
4939 arvif->vdev_id, sta->addr);
Michal Kazior077efc82014-10-21 10:10:29 +03004940
Kalle Valo5e3dd152013-06-12 20:52:10 +03004941 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
4942 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004943 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004944 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004945
Marek Puzyniak7c354242015-03-30 09:51:52 +03004946 ath10k_mac_dec_num_stations(arvif, sta);
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004947
4948 if (!sta->tdls)
4949 goto exit;
4950
4951 if (ath10k_mac_tdls_vif_stations_count(hw, vif))
4952 goto exit;
4953
4954 /* This was the last tdls peer in current vif */
4955 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
4956 WMI_TDLS_DISABLE);
4957 if (ret) {
4958 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
4959 arvif->vdev_id, ret);
4960 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004961 } else if (old_state == IEEE80211_STA_AUTH &&
4962 new_state == IEEE80211_STA_ASSOC &&
4963 (vif->type == NL80211_IFTYPE_AP ||
4964 vif->type == NL80211_IFTYPE_ADHOC)) {
4965 /*
4966 * New association.
4967 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004968 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004969 sta->addr);
4970
Michal Kazior590922a2014-10-21 10:10:29 +03004971 ret = ath10k_station_assoc(ar, vif, sta, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004972 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004973 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004974 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004975 } else if (old_state == IEEE80211_STA_ASSOC &&
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004976 new_state == IEEE80211_STA_AUTHORIZED &&
4977 sta->tdls) {
4978 /*
4979 * Tdls station authorized.
4980 */
4981 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac tdls sta %pM authorized\n",
4982 sta->addr);
4983
4984 ret = ath10k_station_assoc(ar, vif, sta, false);
4985 if (ret) {
4986 ath10k_warn(ar, "failed to associate tdls station %pM for vdev %i: %i\n",
4987 sta->addr, arvif->vdev_id, ret);
4988 goto exit;
4989 }
4990
4991 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
4992 WMI_TDLS_PEER_STATE_CONNECTED);
4993 if (ret)
4994 ath10k_warn(ar, "failed to update tdls peer %pM for vdev %i: %i\n",
4995 sta->addr, arvif->vdev_id, ret);
4996 } else if (old_state == IEEE80211_STA_ASSOC &&
4997 new_state == IEEE80211_STA_AUTH &&
4998 (vif->type == NL80211_IFTYPE_AP ||
4999 vif->type == NL80211_IFTYPE_ADHOC)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03005000 /*
5001 * Disassociation.
5002 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005003 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03005004 sta->addr);
5005
Michal Kazior590922a2014-10-21 10:10:29 +03005006 ret = ath10k_station_disassoc(ar, vif, sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005007 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005008 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02005009 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005010 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01005011exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005012 mutex_unlock(&ar->conf_mutex);
5013 return ret;
5014}
5015
5016static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
Kalle Valo5b07e072014-09-14 12:50:06 +03005017 u16 ac, bool enable)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005018{
5019 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorb0e56152015-01-24 12:14:52 +02005020 struct wmi_sta_uapsd_auto_trig_arg arg = {};
5021 u32 prio = 0, acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005022 u32 value = 0;
5023 int ret = 0;
5024
Michal Kazior548db542013-07-05 16:15:15 +03005025 lockdep_assert_held(&ar->conf_mutex);
5026
Kalle Valo5e3dd152013-06-12 20:52:10 +03005027 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
5028 return 0;
5029
5030 switch (ac) {
5031 case IEEE80211_AC_VO:
5032 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
5033 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005034 prio = 7;
5035 acc = 3;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005036 break;
5037 case IEEE80211_AC_VI:
5038 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
5039 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005040 prio = 5;
5041 acc = 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005042 break;
5043 case IEEE80211_AC_BE:
5044 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
5045 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005046 prio = 2;
5047 acc = 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005048 break;
5049 case IEEE80211_AC_BK:
5050 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
5051 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005052 prio = 0;
5053 acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005054 break;
5055 }
5056
5057 if (enable)
5058 arvif->u.sta.uapsd |= value;
5059 else
5060 arvif->u.sta.uapsd &= ~value;
5061
5062 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5063 WMI_STA_PS_PARAM_UAPSD,
5064 arvif->u.sta.uapsd);
5065 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005066 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005067 goto exit;
5068 }
5069
5070 if (arvif->u.sta.uapsd)
5071 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
5072 else
5073 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
5074
5075 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5076 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
5077 value);
5078 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005079 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005080
Michal Kazior9f9b5742014-12-12 12:41:36 +01005081 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
5082 if (ret) {
5083 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
5084 arvif->vdev_id, ret);
5085 return ret;
5086 }
5087
5088 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
5089 if (ret) {
5090 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
5091 arvif->vdev_id, ret);
5092 return ret;
5093 }
5094
Michal Kaziorb0e56152015-01-24 12:14:52 +02005095 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
5096 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
5097 /* Only userspace can make an educated decision when to send
5098 * trigger frame. The following effectively disables u-UAPSD
5099 * autotrigger in firmware (which is enabled by default
5100 * provided the autotrigger service is available).
5101 */
5102
5103 arg.wmm_ac = acc;
5104 arg.user_priority = prio;
5105 arg.service_interval = 0;
5106 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
5107 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
5108
5109 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
5110 arvif->bssid, &arg, 1);
5111 if (ret) {
5112 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
5113 ret);
5114 return ret;
5115 }
5116 }
5117
Kalle Valo5e3dd152013-06-12 20:52:10 +03005118exit:
5119 return ret;
5120}
5121
5122static int ath10k_conf_tx(struct ieee80211_hw *hw,
5123 struct ieee80211_vif *vif, u16 ac,
5124 const struct ieee80211_tx_queue_params *params)
5125{
5126 struct ath10k *ar = hw->priv;
Michal Kazior5e752e42015-01-19 09:53:41 +01005127 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005128 struct wmi_wmm_params_arg *p = NULL;
5129 int ret;
5130
5131 mutex_lock(&ar->conf_mutex);
5132
5133 switch (ac) {
5134 case IEEE80211_AC_VO:
Michal Kazior5e752e42015-01-19 09:53:41 +01005135 p = &arvif->wmm_params.ac_vo;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005136 break;
5137 case IEEE80211_AC_VI:
Michal Kazior5e752e42015-01-19 09:53:41 +01005138 p = &arvif->wmm_params.ac_vi;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005139 break;
5140 case IEEE80211_AC_BE:
Michal Kazior5e752e42015-01-19 09:53:41 +01005141 p = &arvif->wmm_params.ac_be;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005142 break;
5143 case IEEE80211_AC_BK:
Michal Kazior5e752e42015-01-19 09:53:41 +01005144 p = &arvif->wmm_params.ac_bk;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005145 break;
5146 }
5147
5148 if (WARN_ON(!p)) {
5149 ret = -EINVAL;
5150 goto exit;
5151 }
5152
5153 p->cwmin = params->cw_min;
5154 p->cwmax = params->cw_max;
5155 p->aifs = params->aifs;
5156
5157 /*
5158 * The channel time duration programmed in the HW is in absolute
5159 * microseconds, while mac80211 gives the txop in units of
5160 * 32 microseconds.
5161 */
5162 p->txop = params->txop * 32;
5163
Michal Kazior7fc979a2015-01-28 09:57:28 +02005164 if (ar->wmi.ops->gen_vdev_wmm_conf) {
5165 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
5166 &arvif->wmm_params);
5167 if (ret) {
5168 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
5169 arvif->vdev_id, ret);
5170 goto exit;
5171 }
5172 } else {
5173 /* This won't work well with multi-interface cases but it's
5174 * better than nothing.
5175 */
5176 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
5177 if (ret) {
5178 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
5179 goto exit;
5180 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005181 }
5182
5183 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
5184 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005185 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005186
5187exit:
5188 mutex_unlock(&ar->conf_mutex);
5189 return ret;
5190}
5191
5192#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
5193
5194static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
5195 struct ieee80211_vif *vif,
5196 struct ieee80211_channel *chan,
5197 int duration,
5198 enum ieee80211_roc_type type)
5199{
5200 struct ath10k *ar = hw->priv;
5201 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5202 struct wmi_start_scan_arg arg;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005203 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005204
5205 mutex_lock(&ar->conf_mutex);
5206
5207 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005208 switch (ar->scan.state) {
5209 case ATH10K_SCAN_IDLE:
5210 reinit_completion(&ar->scan.started);
5211 reinit_completion(&ar->scan.completed);
5212 reinit_completion(&ar->scan.on_channel);
5213 ar->scan.state = ATH10K_SCAN_STARTING;
5214 ar->scan.is_roc = true;
5215 ar->scan.vdev_id = arvif->vdev_id;
5216 ar->scan.roc_freq = chan->center_freq;
5217 ret = 0;
5218 break;
5219 case ATH10K_SCAN_STARTING:
5220 case ATH10K_SCAN_RUNNING:
5221 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005222 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005223 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005224 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005225 spin_unlock_bh(&ar->data_lock);
5226
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005227 if (ret)
5228 goto exit;
5229
Michal Kaziordcca0bd2014-11-24 14:58:32 +01005230 duration = max(duration, WMI_SCAN_CHAN_MIN_TIME_MSEC);
5231
Kalle Valo5e3dd152013-06-12 20:52:10 +03005232 memset(&arg, 0, sizeof(arg));
5233 ath10k_wmi_start_scan_init(ar, &arg);
5234 arg.vdev_id = arvif->vdev_id;
5235 arg.scan_id = ATH10K_SCAN_ID;
5236 arg.n_channels = 1;
5237 arg.channels[0] = chan->center_freq;
5238 arg.dwell_time_active = duration;
5239 arg.dwell_time_passive = duration;
5240 arg.max_scan_time = 2 * duration;
5241 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
5242 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
5243
5244 ret = ath10k_start_scan(ar, &arg);
5245 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005246 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005247 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005248 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005249 spin_unlock_bh(&ar->data_lock);
5250 goto exit;
5251 }
5252
5253 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
5254 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005255 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005256
5257 ret = ath10k_scan_stop(ar);
5258 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005259 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005260
Kalle Valo5e3dd152013-06-12 20:52:10 +03005261 ret = -ETIMEDOUT;
5262 goto exit;
5263 }
5264
5265 ret = 0;
5266exit:
5267 mutex_unlock(&ar->conf_mutex);
5268 return ret;
5269}
5270
5271static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
5272{
5273 struct ath10k *ar = hw->priv;
5274
5275 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005276 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005277 mutex_unlock(&ar->conf_mutex);
5278
Michal Kazior4eb2e162014-10-28 10:23:09 +01005279 cancel_delayed_work_sync(&ar->scan.timeout);
5280
Kalle Valo5e3dd152013-06-12 20:52:10 +03005281 return 0;
5282}
5283
5284/*
5285 * Both RTS and Fragmentation threshold are interface-specific
5286 * in ath10k, but device-specific in mac80211.
5287 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03005288
5289static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
5290{
Kalle Valo5e3dd152013-06-12 20:52:10 +03005291 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03005292 struct ath10k_vif *arvif;
5293 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03005294
Michal Kaziorad088bf2013-10-16 15:44:46 +03005295 mutex_lock(&ar->conf_mutex);
5296 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005297 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03005298 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03005299
Michal Kaziorad088bf2013-10-16 15:44:46 +03005300 ret = ath10k_mac_set_rts(arvif, value);
5301 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005302 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03005303 arvif->vdev_id, ret);
5304 break;
5305 }
5306 }
5307 mutex_unlock(&ar->conf_mutex);
5308
5309 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005310}
5311
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02005312static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5313 u32 queues, bool drop)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005314{
5315 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02005316 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005317 int ret;
5318
5319 /* mac80211 doesn't care if we really xmit queued frames or not
5320 * we'll collect those frames either way if we stop/delete vdevs */
5321 if (drop)
5322 return;
5323
Michal Kazior548db542013-07-05 16:15:15 +03005324 mutex_lock(&ar->conf_mutex);
5325
Michal Kazioraffd3212013-07-16 09:54:35 +02005326 if (ar->state == ATH10K_STATE_WEDGED)
5327 goto skip;
5328
Michal Kazioredb82362013-07-05 16:15:14 +03005329 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03005330 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02005331
Michal Kazioredb82362013-07-05 16:15:14 +03005332 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02005333 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03005334 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02005335
Michal Kazior7962b0d2014-10-28 10:34:38 +01005336 skip = (ar->state == ATH10K_STATE_WEDGED) ||
5337 test_bit(ATH10K_FLAG_CRASH_FLUSH,
5338 &ar->dev_flags);
Michal Kazioraffd3212013-07-16 09:54:35 +02005339
5340 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005341 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02005342
5343 if (ret <= 0 || skip)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005344 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
Ben Greear9ba4c782014-02-25 09:29:57 +02005345 skip, ar->state, ret);
Michal Kazior548db542013-07-05 16:15:15 +03005346
Michal Kazioraffd3212013-07-16 09:54:35 +02005347skip:
Michal Kazior548db542013-07-05 16:15:15 +03005348 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005349}
5350
5351/* TODO: Implement this function properly
5352 * For now it is needed to reply to Probe Requests in IBSS mode.
5353 * Propably we need this information from FW.
5354 */
5355static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
5356{
5357 return 1;
5358}
5359
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005360static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
5361 enum ieee80211_reconfig_type reconfig_type)
Michal Kazioraffd3212013-07-16 09:54:35 +02005362{
5363 struct ath10k *ar = hw->priv;
5364
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005365 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
5366 return;
5367
Michal Kazioraffd3212013-07-16 09:54:35 +02005368 mutex_lock(&ar->conf_mutex);
5369
5370 /* If device failed to restart it will be in a different state, e.g.
5371 * ATH10K_STATE_WEDGED */
5372 if (ar->state == ATH10K_STATE_RESTARTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005373 ath10k_info(ar, "device successfully recovered\n");
Michal Kazioraffd3212013-07-16 09:54:35 +02005374 ar->state = ATH10K_STATE_ON;
Michal Kazior7962b0d2014-10-28 10:34:38 +01005375 ieee80211_wake_queues(ar->hw);
Michal Kazioraffd3212013-07-16 09:54:35 +02005376 }
5377
5378 mutex_unlock(&ar->conf_mutex);
5379}
5380
Michal Kazior2e1dea42013-07-31 10:32:40 +02005381static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
5382 struct survey_info *survey)
5383{
5384 struct ath10k *ar = hw->priv;
5385 struct ieee80211_supported_band *sband;
5386 struct survey_info *ar_survey = &ar->survey[idx];
5387 int ret = 0;
5388
5389 mutex_lock(&ar->conf_mutex);
5390
5391 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
5392 if (sband && idx >= sband->n_channels) {
5393 idx -= sband->n_channels;
5394 sband = NULL;
5395 }
5396
5397 if (!sband)
5398 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
5399
5400 if (!sband || idx >= sband->n_channels) {
5401 ret = -ENOENT;
5402 goto exit;
5403 }
5404
5405 spin_lock_bh(&ar->data_lock);
5406 memcpy(survey, ar_survey, sizeof(*survey));
5407 spin_unlock_bh(&ar->data_lock);
5408
5409 survey->channel = &sband->channels[idx];
5410
Felix Fietkaufa1d4df2014-10-23 17:04:28 +03005411 if (ar->rx_channel == survey->channel)
5412 survey->filled |= SURVEY_INFO_IN_USE;
5413
Michal Kazior2e1dea42013-07-31 10:32:40 +02005414exit:
5415 mutex_unlock(&ar->conf_mutex);
5416 return ret;
5417}
5418
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005419/* Check if only one bit set */
5420static int ath10k_check_single_mask(u32 mask)
5421{
5422 int bit;
5423
5424 bit = ffs(mask);
5425 if (!bit)
5426 return 0;
5427
5428 mask &= ~BIT(bit - 1);
5429 if (mask)
5430 return 2;
5431
5432 return 1;
5433}
5434
5435static bool
5436ath10k_default_bitrate_mask(struct ath10k *ar,
5437 enum ieee80211_band band,
5438 const struct cfg80211_bitrate_mask *mask)
5439{
5440 u32 legacy = 0x00ff;
5441 u8 ht = 0xff, i;
5442 u16 vht = 0x3ff;
Ben Greearb116ea12014-11-24 16:22:10 +02005443 u16 nrf = ar->num_rf_chains;
5444
5445 if (ar->cfg_tx_chainmask)
5446 nrf = get_nss_from_chainmask(ar->cfg_tx_chainmask);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005447
5448 switch (band) {
5449 case IEEE80211_BAND_2GHZ:
5450 legacy = 0x00fff;
5451 vht = 0;
5452 break;
5453 case IEEE80211_BAND_5GHZ:
5454 break;
5455 default:
5456 return false;
5457 }
5458
5459 if (mask->control[band].legacy != legacy)
5460 return false;
5461
Ben Greearb116ea12014-11-24 16:22:10 +02005462 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005463 if (mask->control[band].ht_mcs[i] != ht)
5464 return false;
5465
Ben Greearb116ea12014-11-24 16:22:10 +02005466 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005467 if (mask->control[band].vht_mcs[i] != vht)
5468 return false;
5469
5470 return true;
5471}
5472
5473static bool
5474ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
5475 enum ieee80211_band band,
5476 u8 *fixed_nss)
5477{
5478 int ht_nss = 0, vht_nss = 0, i;
5479
5480 /* check legacy */
5481 if (ath10k_check_single_mask(mask->control[band].legacy))
5482 return false;
5483
5484 /* check HT */
5485 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
5486 if (mask->control[band].ht_mcs[i] == 0xff)
5487 continue;
5488 else if (mask->control[band].ht_mcs[i] == 0x00)
5489 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03005490
5491 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005492 }
5493
5494 ht_nss = i;
5495
5496 /* check VHT */
5497 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
5498 if (mask->control[band].vht_mcs[i] == 0x03ff)
5499 continue;
5500 else if (mask->control[band].vht_mcs[i] == 0x0000)
5501 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03005502
5503 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005504 }
5505
5506 vht_nss = i;
5507
5508 if (ht_nss > 0 && vht_nss > 0)
5509 return false;
5510
5511 if (ht_nss)
5512 *fixed_nss = ht_nss;
5513 else if (vht_nss)
5514 *fixed_nss = vht_nss;
5515 else
5516 return false;
5517
5518 return true;
5519}
5520
5521static bool
5522ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
5523 enum ieee80211_band band,
5524 enum wmi_rate_preamble *preamble)
5525{
5526 int legacy = 0, ht = 0, vht = 0, i;
5527
5528 *preamble = WMI_RATE_PREAMBLE_OFDM;
5529
5530 /* check legacy */
5531 legacy = ath10k_check_single_mask(mask->control[band].legacy);
5532 if (legacy > 1)
5533 return false;
5534
5535 /* check HT */
5536 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5537 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
5538 if (ht > 1)
5539 return false;
5540
5541 /* check VHT */
5542 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
5543 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
5544 if (vht > 1)
5545 return false;
5546
5547 /* Currently we support only one fixed_rate */
5548 if ((legacy + ht + vht) != 1)
5549 return false;
5550
5551 if (ht)
5552 *preamble = WMI_RATE_PREAMBLE_HT;
5553 else if (vht)
5554 *preamble = WMI_RATE_PREAMBLE_VHT;
5555
5556 return true;
5557}
5558
5559static bool
Michal Kazior7aa7a722014-08-25 12:09:38 +02005560ath10k_bitrate_mask_rate(struct ath10k *ar,
5561 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005562 enum ieee80211_band band,
5563 u8 *fixed_rate,
5564 u8 *fixed_nss)
5565{
Michal Kazioraf001482015-03-30 09:51:56 +03005566 struct ieee80211_supported_band *sband;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005567 u8 rate = 0, pream = 0, nss = 0, i;
5568 enum wmi_rate_preamble preamble;
5569
5570 /* Check if single rate correct */
5571 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
5572 return false;
5573
5574 pream = preamble;
5575
5576 switch (preamble) {
5577 case WMI_RATE_PREAMBLE_CCK:
5578 case WMI_RATE_PREAMBLE_OFDM:
5579 i = ffs(mask->control[band].legacy) - 1;
Michal Kazioraf001482015-03-30 09:51:56 +03005580 sband = &ar->mac.sbands[band];
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005581
Michal Kazioraf001482015-03-30 09:51:56 +03005582 if (WARN_ON(i >= sband->n_bitrates))
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005583 return false;
5584
Michal Kazioraf001482015-03-30 09:51:56 +03005585 rate = sband->bitrates[i].hw_value;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005586 break;
5587 case WMI_RATE_PREAMBLE_HT:
5588 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5589 if (mask->control[band].ht_mcs[i])
5590 break;
5591
5592 if (i == IEEE80211_HT_MCS_MASK_LEN)
5593 return false;
5594
5595 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
5596 nss = i;
5597 break;
5598 case WMI_RATE_PREAMBLE_VHT:
5599 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
5600 if (mask->control[band].vht_mcs[i])
5601 break;
5602
5603 if (i == NL80211_VHT_NSS_MAX)
5604 return false;
5605
5606 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
5607 nss = i;
5608 break;
5609 }
5610
5611 *fixed_nss = nss + 1;
5612 nss <<= 4;
5613 pream <<= 6;
5614
Michal Kazior7aa7a722014-08-25 12:09:38 +02005615 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac fixed rate pream 0x%02x nss 0x%02x rate 0x%02x\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005616 pream, nss, rate);
5617
5618 *fixed_rate = pream | nss | rate;
5619
5620 return true;
5621}
5622
Michal Kazior7aa7a722014-08-25 12:09:38 +02005623static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
5624 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005625 enum ieee80211_band band,
5626 u8 *fixed_rate,
5627 u8 *fixed_nss)
5628{
5629 /* First check full NSS mask, if we can simply limit NSS */
5630 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
5631 return true;
5632
5633 /* Next Check single rate is set */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005634 return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005635}
5636
5637static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
5638 u8 fixed_rate,
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005639 u8 fixed_nss,
5640 u8 force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005641{
5642 struct ath10k *ar = arvif->ar;
5643 u32 vdev_param;
5644 int ret = 0;
5645
5646 mutex_lock(&ar->conf_mutex);
5647
5648 if (arvif->fixed_rate == fixed_rate &&
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005649 arvif->fixed_nss == fixed_nss &&
5650 arvif->force_sgi == force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005651 goto exit;
5652
5653 if (fixed_rate == WMI_FIXED_RATE_NONE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005654 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005655
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005656 if (force_sgi)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005657 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005658
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005659 vdev_param = ar->wmi.vdev_param->fixed_rate;
5660 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5661 vdev_param, fixed_rate);
5662 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005663 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005664 fixed_rate, ret);
5665 ret = -EINVAL;
5666 goto exit;
5667 }
5668
5669 arvif->fixed_rate = fixed_rate;
5670
5671 vdev_param = ar->wmi.vdev_param->nss;
5672 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5673 vdev_param, fixed_nss);
5674
5675 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005676 ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005677 fixed_nss, ret);
5678 ret = -EINVAL;
5679 goto exit;
5680 }
5681
5682 arvif->fixed_nss = fixed_nss;
5683
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005684 vdev_param = ar->wmi.vdev_param->sgi;
5685 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5686 force_sgi);
5687
5688 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005689 ath10k_warn(ar, "failed to set sgi param %d: %d\n",
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005690 force_sgi, ret);
5691 ret = -EINVAL;
5692 goto exit;
5693 }
5694
5695 arvif->force_sgi = force_sgi;
5696
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005697exit:
5698 mutex_unlock(&ar->conf_mutex);
5699 return ret;
5700}
5701
5702static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
5703 struct ieee80211_vif *vif,
5704 const struct cfg80211_bitrate_mask *mask)
5705{
5706 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior500ff9f2015-03-31 10:26:21 +00005707 struct cfg80211_chan_def def;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005708 struct ath10k *ar = arvif->ar;
Michal Kazior500ff9f2015-03-31 10:26:21 +00005709 enum ieee80211_band band;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005710 u8 fixed_rate = WMI_FIXED_RATE_NONE;
5711 u8 fixed_nss = ar->num_rf_chains;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005712 u8 force_sgi;
5713
Michal Kazior500ff9f2015-03-31 10:26:21 +00005714 if (ath10k_mac_vif_chan(vif, &def))
5715 return -EPERM;
5716
Ben Greearb116ea12014-11-24 16:22:10 +02005717 if (ar->cfg_tx_chainmask)
5718 fixed_nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
5719
Michal Kazior500ff9f2015-03-31 10:26:21 +00005720 band = def.chan->band;
5721
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005722 force_sgi = mask->control[band].gi;
5723 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
5724 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005725
5726 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005727 if (!ath10k_get_fixed_rate_nss(ar, mask, band,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005728 &fixed_rate,
5729 &fixed_nss))
5730 return -EINVAL;
5731 }
5732
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005733 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005734 ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005735 return -EINVAL;
5736 }
5737
5738 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
5739 fixed_nss, force_sgi);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005740}
5741
Michal Kazior9797feb2014-02-14 14:49:48 +01005742static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
5743 struct ieee80211_vif *vif,
5744 struct ieee80211_sta *sta,
5745 u32 changed)
5746{
5747 struct ath10k *ar = hw->priv;
5748 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5749 u32 bw, smps;
5750
5751 spin_lock_bh(&ar->data_lock);
5752
Michal Kazior7aa7a722014-08-25 12:09:38 +02005753 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior9797feb2014-02-14 14:49:48 +01005754 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
5755 sta->addr, changed, sta->bandwidth, sta->rx_nss,
5756 sta->smps_mode);
5757
5758 if (changed & IEEE80211_RC_BW_CHANGED) {
5759 bw = WMI_PEER_CHWIDTH_20MHZ;
5760
5761 switch (sta->bandwidth) {
5762 case IEEE80211_STA_RX_BW_20:
5763 bw = WMI_PEER_CHWIDTH_20MHZ;
5764 break;
5765 case IEEE80211_STA_RX_BW_40:
5766 bw = WMI_PEER_CHWIDTH_40MHZ;
5767 break;
5768 case IEEE80211_STA_RX_BW_80:
5769 bw = WMI_PEER_CHWIDTH_80MHZ;
5770 break;
5771 case IEEE80211_STA_RX_BW_160:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005772 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005773 sta->bandwidth, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005774 bw = WMI_PEER_CHWIDTH_20MHZ;
5775 break;
5776 }
5777
5778 arsta->bw = bw;
5779 }
5780
5781 if (changed & IEEE80211_RC_NSS_CHANGED)
5782 arsta->nss = sta->rx_nss;
5783
5784 if (changed & IEEE80211_RC_SMPS_CHANGED) {
5785 smps = WMI_PEER_SMPS_PS_NONE;
5786
5787 switch (sta->smps_mode) {
5788 case IEEE80211_SMPS_AUTOMATIC:
5789 case IEEE80211_SMPS_OFF:
5790 smps = WMI_PEER_SMPS_PS_NONE;
5791 break;
5792 case IEEE80211_SMPS_STATIC:
5793 smps = WMI_PEER_SMPS_STATIC;
5794 break;
5795 case IEEE80211_SMPS_DYNAMIC:
5796 smps = WMI_PEER_SMPS_DYNAMIC;
5797 break;
5798 case IEEE80211_SMPS_NUM_MODES:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005799 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005800 sta->smps_mode, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005801 smps = WMI_PEER_SMPS_PS_NONE;
5802 break;
5803 }
5804
5805 arsta->smps = smps;
5806 }
5807
Michal Kazior9797feb2014-02-14 14:49:48 +01005808 arsta->changed |= changed;
5809
5810 spin_unlock_bh(&ar->data_lock);
5811
5812 ieee80211_queue_work(hw, &arsta->update_wk);
5813}
5814
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02005815static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
5816{
5817 /*
5818 * FIXME: Return 0 for time being. Need to figure out whether FW
5819 * has the API to fetch 64-bit local TSF
5820 */
5821
5822 return 0;
5823}
5824
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005825static int ath10k_ampdu_action(struct ieee80211_hw *hw,
5826 struct ieee80211_vif *vif,
5827 enum ieee80211_ampdu_mlme_action action,
5828 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
5829 u8 buf_size)
5830{
Michal Kazior7aa7a722014-08-25 12:09:38 +02005831 struct ath10k *ar = hw->priv;
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005832 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5833
Michal Kazior7aa7a722014-08-25 12:09:38 +02005834 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005835 arvif->vdev_id, sta->addr, tid, action);
5836
5837 switch (action) {
5838 case IEEE80211_AMPDU_RX_START:
5839 case IEEE80211_AMPDU_RX_STOP:
5840 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
5841 * creation/removal. Do we need to verify this?
5842 */
5843 return 0;
5844 case IEEE80211_AMPDU_TX_START:
5845 case IEEE80211_AMPDU_TX_STOP_CONT:
5846 case IEEE80211_AMPDU_TX_STOP_FLUSH:
5847 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
5848 case IEEE80211_AMPDU_TX_OPERATIONAL:
5849 /* Firmware offloads Tx aggregation entirely so deny mac80211
5850 * Tx aggregation requests.
5851 */
5852 return -EOPNOTSUPP;
5853 }
5854
5855 return -EINVAL;
5856}
5857
Michal Kazior500ff9f2015-03-31 10:26:21 +00005858static void
5859ath10k_mac_update_rx_channel(struct ath10k *ar)
5860{
5861 struct cfg80211_chan_def *def = NULL;
5862
5863 /* Both locks are required because ar->rx_channel is modified. This
5864 * allows readers to hold either lock.
5865 */
5866 lockdep_assert_held(&ar->conf_mutex);
5867 lockdep_assert_held(&ar->data_lock);
5868
5869 /* FIXME: Sort of an optimization and a workaround. Peers and vifs are
5870 * on a linked list now. Doing a lookup peer -> vif -> chanctx for each
5871 * ppdu on Rx may reduce performance on low-end systems. It should be
5872 * possible to make tables/hashmaps to speed the lookup up (be vary of
5873 * cpu data cache lines though regarding sizes) but to keep the initial
5874 * implementation simple and less intrusive fallback to the slow lookup
5875 * only for multi-channel cases. Single-channel cases will remain to
5876 * use the old channel derival and thus performance should not be
5877 * affected much.
5878 */
5879 rcu_read_lock();
5880 if (ath10k_mac_num_chanctxs(ar) == 1) {
5881 ieee80211_iter_chan_contexts_atomic(ar->hw,
5882 ath10k_mac_get_any_chandef_iter,
5883 &def);
5884 ar->rx_channel = def->chan;
5885 } else {
5886 ar->rx_channel = NULL;
5887 }
5888 rcu_read_unlock();
5889}
5890
5891static void
5892ath10k_mac_chan_ctx_init(struct ath10k *ar,
5893 struct ath10k_chanctx *arctx,
5894 struct ieee80211_chanctx_conf *conf)
5895{
5896 lockdep_assert_held(&ar->conf_mutex);
5897 lockdep_assert_held(&ar->data_lock);
5898
5899 memset(arctx, 0, sizeof(*arctx));
5900
5901 arctx->conf = *conf;
5902}
5903
5904static int
5905ath10k_mac_op_add_chanctx(struct ieee80211_hw *hw,
5906 struct ieee80211_chanctx_conf *ctx)
5907{
5908 struct ath10k *ar = hw->priv;
5909 struct ath10k_chanctx *arctx = (void *)ctx->drv_priv;
5910
5911 ath10k_dbg(ar, ATH10K_DBG_MAC,
5912 "mac chanctx add freq %hu width %d ptr %p\n",
5913 ctx->def.chan->center_freq, ctx->def.width, ctx);
5914
5915 mutex_lock(&ar->conf_mutex);
5916
5917 spin_lock_bh(&ar->data_lock);
5918 ath10k_mac_chan_ctx_init(ar, arctx, ctx);
5919 ath10k_mac_update_rx_channel(ar);
5920 spin_unlock_bh(&ar->data_lock);
5921
5922 ath10k_recalc_radar_detection(ar);
5923 ath10k_monitor_recalc(ar);
5924
5925 mutex_unlock(&ar->conf_mutex);
5926
5927 return 0;
5928}
5929
5930static void
5931ath10k_mac_op_remove_chanctx(struct ieee80211_hw *hw,
5932 struct ieee80211_chanctx_conf *ctx)
5933{
5934 struct ath10k *ar = hw->priv;
5935
5936 ath10k_dbg(ar, ATH10K_DBG_MAC,
5937 "mac chanctx remove freq %hu width %d ptr %p\n",
5938 ctx->def.chan->center_freq, ctx->def.width, ctx);
5939
5940 mutex_lock(&ar->conf_mutex);
5941
5942 spin_lock_bh(&ar->data_lock);
5943 ath10k_mac_update_rx_channel(ar);
5944 spin_unlock_bh(&ar->data_lock);
5945
5946 ath10k_recalc_radar_detection(ar);
5947 ath10k_monitor_recalc(ar);
5948
5949 mutex_unlock(&ar->conf_mutex);
5950}
5951
5952static void
5953ath10k_mac_op_change_chanctx(struct ieee80211_hw *hw,
5954 struct ieee80211_chanctx_conf *ctx,
5955 u32 changed)
5956{
5957 struct ath10k *ar = hw->priv;
5958 struct ath10k_chanctx *arctx = (void *)ctx->drv_priv;
5959
5960 mutex_lock(&ar->conf_mutex);
5961
5962 ath10k_dbg(ar, ATH10K_DBG_MAC,
5963 "mac chanctx change freq %hu->%hu width %d->%d ptr %p changed %x\n",
5964 arctx->conf.def.chan->center_freq,
5965 ctx->def.chan->center_freq,
5966 arctx->conf.def.width, ctx->def.width,
5967 ctx, changed);
5968
5969 /* This shouldn't really happen because channel switching should use
5970 * switch_vif_chanctx().
5971 */
5972 if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL))
5973 goto unlock;
5974
5975 spin_lock_bh(&ar->data_lock);
5976 arctx->conf = *ctx;
5977 spin_unlock_bh(&ar->data_lock);
5978
5979 ath10k_recalc_radar_detection(ar);
5980
5981 /* FIXME: How to configure Rx chains properly? */
5982
5983 /* No other actions are actually necessary. Firmware maintains channel
5984 * definitions per vdev internally and there's no host-side channel
5985 * context abstraction to configure, e.g. channel width.
5986 */
5987
5988unlock:
5989 mutex_unlock(&ar->conf_mutex);
5990}
5991
5992static int
5993ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
5994 struct ieee80211_vif *vif,
5995 struct ieee80211_chanctx_conf *ctx)
5996{
5997 struct ath10k *ar = hw->priv;
5998 struct ath10k_chanctx *arctx = (void *)ctx->drv_priv;
5999 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6000 int ret;
6001
6002 mutex_lock(&ar->conf_mutex);
6003
6004 ath10k_dbg(ar, ATH10K_DBG_MAC,
6005 "mac chanctx assign ptr %p vdev_id %i\n",
6006 ctx, arvif->vdev_id);
6007
6008 if (WARN_ON(arvif->is_started)) {
6009 mutex_unlock(&ar->conf_mutex);
6010 return -EBUSY;
6011 }
6012
6013 ret = ath10k_vdev_start(arvif, &arctx->conf.def);
6014 if (ret) {
6015 ath10k_warn(ar, "failed to start vdev %i addr %pM on freq %d: %d\n",
6016 arvif->vdev_id, vif->addr,
6017 arctx->conf.def.chan->center_freq, ret);
6018 goto err;
6019 }
6020
6021 arvif->is_started = true;
6022
6023 if (vif->type == NL80211_IFTYPE_MONITOR) {
6024 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, 0, vif->addr);
6025 if (ret) {
6026 ath10k_warn(ar, "failed to up monitor vdev %i: %d\n",
6027 arvif->vdev_id, ret);
6028 goto err_stop;
6029 }
6030
6031 arvif->is_up = true;
6032 }
6033
6034 mutex_unlock(&ar->conf_mutex);
6035 return 0;
6036
6037err_stop:
6038 ath10k_vdev_stop(arvif);
6039 arvif->is_started = false;
6040
6041err:
6042 mutex_unlock(&ar->conf_mutex);
6043 return ret;
6044}
6045
6046static void
6047ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
6048 struct ieee80211_vif *vif,
6049 struct ieee80211_chanctx_conf *ctx)
6050{
6051 struct ath10k *ar = hw->priv;
6052 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6053 int ret;
6054
6055 mutex_lock(&ar->conf_mutex);
6056
6057 ath10k_dbg(ar, ATH10K_DBG_MAC,
6058 "mac chanctx unassign ptr %p vdev_id %i\n",
6059 ctx, arvif->vdev_id);
6060
6061 WARN_ON(!arvif->is_started);
6062
6063 if (vif->type == NL80211_IFTYPE_MONITOR) {
6064 WARN_ON(!arvif->is_up);
6065
6066 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
6067 if (ret)
6068 ath10k_warn(ar, "failed to down monitor vdev %i: %d\n",
6069 arvif->vdev_id, ret);
6070
6071 arvif->is_up = false;
6072 }
6073
6074 ret = ath10k_vdev_stop(arvif);
6075 if (ret)
6076 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
6077 arvif->vdev_id, ret);
6078
6079 arvif->is_started = false;
6080
6081 mutex_unlock(&ar->conf_mutex);
6082}
6083
6084static int
6085ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw,
6086 struct ieee80211_vif_chanctx_switch *vifs,
6087 int n_vifs,
6088 enum ieee80211_chanctx_switch_mode mode)
6089{
6090 struct ath10k *ar = hw->priv;
6091 struct ath10k_vif *arvif;
6092 struct ath10k_chanctx *arctx_new, *arctx_old;
6093 int i;
6094
6095 mutex_lock(&ar->conf_mutex);
6096
6097 ath10k_dbg(ar, ATH10K_DBG_MAC,
6098 "mac chanctx switch n_vifs %d mode %d\n",
6099 n_vifs, mode);
6100
6101 spin_lock_bh(&ar->data_lock);
6102 for (i = 0; i < n_vifs; i++) {
6103 arvif = ath10k_vif_to_arvif(vifs[i].vif);
6104 arctx_new = (void *)vifs[i].new_ctx->drv_priv;
6105 arctx_old = (void *)vifs[i].old_ctx->drv_priv;
6106
6107 ath10k_dbg(ar, ATH10K_DBG_MAC,
6108 "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d ptr %p->%p\n",
6109 arvif->vdev_id,
6110 vifs[i].old_ctx->def.chan->center_freq,
6111 vifs[i].new_ctx->def.chan->center_freq,
6112 vifs[i].old_ctx->def.width,
6113 vifs[i].new_ctx->def.width,
6114 arctx_old, arctx_new);
6115
6116 if (mode == CHANCTX_SWMODE_SWAP_CONTEXTS) {
6117 ath10k_mac_chan_ctx_init(ar, arctx_new,
6118 vifs[i].new_ctx);
6119 }
6120
6121 arctx_new->conf = *vifs[i].new_ctx;
6122
6123 /* FIXME: ath10k_mac_chan_reconfigure() uses current, i.e. not
6124 * yet updated chanctx_conf pointer.
6125 */
6126 arctx_old->conf = *vifs[i].new_ctx;
6127 }
6128 ath10k_mac_update_rx_channel(ar);
6129 spin_unlock_bh(&ar->data_lock);
6130
6131 /* FIXME: Reconfigure only affected vifs */
6132 ath10k_mac_chan_reconfigure(ar);
6133
6134 mutex_unlock(&ar->conf_mutex);
6135 return 0;
6136}
6137
Kalle Valo5e3dd152013-06-12 20:52:10 +03006138static const struct ieee80211_ops ath10k_ops = {
6139 .tx = ath10k_tx,
6140 .start = ath10k_start,
6141 .stop = ath10k_stop,
6142 .config = ath10k_config,
6143 .add_interface = ath10k_add_interface,
6144 .remove_interface = ath10k_remove_interface,
6145 .configure_filter = ath10k_configure_filter,
6146 .bss_info_changed = ath10k_bss_info_changed,
6147 .hw_scan = ath10k_hw_scan,
6148 .cancel_hw_scan = ath10k_cancel_hw_scan,
6149 .set_key = ath10k_set_key,
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02006150 .set_default_unicast_key = ath10k_set_default_unicast_key,
Kalle Valo5e3dd152013-06-12 20:52:10 +03006151 .sta_state = ath10k_sta_state,
6152 .conf_tx = ath10k_conf_tx,
6153 .remain_on_channel = ath10k_remain_on_channel,
6154 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
6155 .set_rts_threshold = ath10k_set_rts_threshold,
Kalle Valo5e3dd152013-06-12 20:52:10 +03006156 .flush = ath10k_flush,
6157 .tx_last_beacon = ath10k_tx_last_beacon,
Ben Greear46acf7b2014-05-16 17:15:38 +03006158 .set_antenna = ath10k_set_antenna,
6159 .get_antenna = ath10k_get_antenna,
Eliad Pellercf2c92d2014-11-04 11:43:54 +02006160 .reconfig_complete = ath10k_reconfig_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02006161 .get_survey = ath10k_get_survey,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01006162 .set_bitrate_mask = ath10k_set_bitrate_mask,
Michal Kazior9797feb2014-02-14 14:49:48 +01006163 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02006164 .get_tsf = ath10k_get_tsf,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02006165 .ampdu_action = ath10k_ampdu_action,
Ben Greear6cddcc72014-09-29 14:41:46 +03006166 .get_et_sset_count = ath10k_debug_get_et_sset_count,
6167 .get_et_stats = ath10k_debug_get_et_stats,
6168 .get_et_strings = ath10k_debug_get_et_strings,
Michal Kazior500ff9f2015-03-31 10:26:21 +00006169 .add_chanctx = ath10k_mac_op_add_chanctx,
6170 .remove_chanctx = ath10k_mac_op_remove_chanctx,
6171 .change_chanctx = ath10k_mac_op_change_chanctx,
6172 .assign_vif_chanctx = ath10k_mac_op_assign_vif_chanctx,
6173 .unassign_vif_chanctx = ath10k_mac_op_unassign_vif_chanctx,
6174 .switch_vif_chanctx = ath10k_mac_op_switch_vif_chanctx,
Kalle Valo43d2a302014-09-10 18:23:30 +03006175
6176 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
6177
Michal Kazior8cd13ca2013-07-16 09:38:54 +02006178#ifdef CONFIG_PM
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +02006179 .suspend = ath10k_wow_op_suspend,
6180 .resume = ath10k_wow_op_resume,
Michal Kazior8cd13ca2013-07-16 09:38:54 +02006181#endif
Rajkumar Manoharanf5045982015-01-12 14:07:27 +02006182#ifdef CONFIG_MAC80211_DEBUGFS
6183 .sta_add_debugfs = ath10k_sta_add_debugfs,
6184#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03006185};
6186
Kalle Valo5e3dd152013-06-12 20:52:10 +03006187#define CHAN2G(_channel, _freq, _flags) { \
6188 .band = IEEE80211_BAND_2GHZ, \
6189 .hw_value = (_channel), \
6190 .center_freq = (_freq), \
6191 .flags = (_flags), \
6192 .max_antenna_gain = 0, \
6193 .max_power = 30, \
6194}
6195
6196#define CHAN5G(_channel, _freq, _flags) { \
6197 .band = IEEE80211_BAND_5GHZ, \
6198 .hw_value = (_channel), \
6199 .center_freq = (_freq), \
6200 .flags = (_flags), \
6201 .max_antenna_gain = 0, \
6202 .max_power = 30, \
6203}
6204
6205static const struct ieee80211_channel ath10k_2ghz_channels[] = {
6206 CHAN2G(1, 2412, 0),
6207 CHAN2G(2, 2417, 0),
6208 CHAN2G(3, 2422, 0),
6209 CHAN2G(4, 2427, 0),
6210 CHAN2G(5, 2432, 0),
6211 CHAN2G(6, 2437, 0),
6212 CHAN2G(7, 2442, 0),
6213 CHAN2G(8, 2447, 0),
6214 CHAN2G(9, 2452, 0),
6215 CHAN2G(10, 2457, 0),
6216 CHAN2G(11, 2462, 0),
6217 CHAN2G(12, 2467, 0),
6218 CHAN2G(13, 2472, 0),
6219 CHAN2G(14, 2484, 0),
6220};
6221
6222static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02006223 CHAN5G(36, 5180, 0),
6224 CHAN5G(40, 5200, 0),
6225 CHAN5G(44, 5220, 0),
6226 CHAN5G(48, 5240, 0),
6227 CHAN5G(52, 5260, 0),
6228 CHAN5G(56, 5280, 0),
6229 CHAN5G(60, 5300, 0),
6230 CHAN5G(64, 5320, 0),
6231 CHAN5G(100, 5500, 0),
6232 CHAN5G(104, 5520, 0),
6233 CHAN5G(108, 5540, 0),
6234 CHAN5G(112, 5560, 0),
6235 CHAN5G(116, 5580, 0),
6236 CHAN5G(120, 5600, 0),
6237 CHAN5G(124, 5620, 0),
6238 CHAN5G(128, 5640, 0),
6239 CHAN5G(132, 5660, 0),
6240 CHAN5G(136, 5680, 0),
6241 CHAN5G(140, 5700, 0),
Peter Oh4a7898f2015-03-18 11:39:18 -07006242 CHAN5G(144, 5720, 0),
Michal Kazior429ff562013-06-26 08:54:54 +02006243 CHAN5G(149, 5745, 0),
6244 CHAN5G(153, 5765, 0),
6245 CHAN5G(157, 5785, 0),
6246 CHAN5G(161, 5805, 0),
6247 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03006248};
6249
Michal Kaziore7b54192014-08-07 11:03:27 +02006250struct ath10k *ath10k_mac_create(size_t priv_size)
Kalle Valo5e3dd152013-06-12 20:52:10 +03006251{
6252 struct ieee80211_hw *hw;
6253 struct ath10k *ar;
6254
Michal Kaziore7b54192014-08-07 11:03:27 +02006255 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006256 if (!hw)
6257 return NULL;
6258
6259 ar = hw->priv;
6260 ar->hw = hw;
6261
6262 return ar;
6263}
6264
6265void ath10k_mac_destroy(struct ath10k *ar)
6266{
6267 ieee80211_free_hw(ar->hw);
6268}
6269
6270static const struct ieee80211_iface_limit ath10k_if_limits[] = {
6271 {
6272 .max = 8,
6273 .types = BIT(NL80211_IFTYPE_STATION)
6274 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02006275 },
6276 {
6277 .max = 3,
6278 .types = BIT(NL80211_IFTYPE_P2P_GO)
6279 },
6280 {
Michal Kazior75d2bd42014-12-12 12:41:39 +01006281 .max = 1,
6282 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
6283 },
6284 {
Michal Kaziord531cb82013-07-31 10:55:13 +02006285 .max = 7,
6286 .types = BIT(NL80211_IFTYPE_AP)
6287 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03006288};
6289
Bartosz Markowskif2595092013-12-10 16:20:39 +01006290static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006291 {
6292 .max = 8,
6293 .types = BIT(NL80211_IFTYPE_AP)
6294 },
6295};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006296
6297static const struct ieee80211_iface_combination ath10k_if_comb[] = {
6298 {
6299 .limits = ath10k_if_limits,
6300 .n_limits = ARRAY_SIZE(ath10k_if_limits),
6301 .max_interfaces = 8,
6302 .num_different_channels = 1,
6303 .beacon_int_infra_match = true,
6304 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01006305};
6306
6307static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006308 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01006309 .limits = ath10k_10x_if_limits,
6310 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006311 .max_interfaces = 8,
6312 .num_different_channels = 1,
6313 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01006314#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006315 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
6316 BIT(NL80211_CHAN_WIDTH_20) |
6317 BIT(NL80211_CHAN_WIDTH_40) |
6318 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006319#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01006320 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03006321};
6322
6323static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
6324{
6325 struct ieee80211_sta_vht_cap vht_cap = {0};
6326 u16 mcs_map;
Michal Kaziorbc657a362015-02-26 11:11:22 +01006327 u32 val;
Michal Kazior8865bee42013-07-24 12:36:46 +02006328 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006329
6330 vht_cap.vht_supported = 1;
6331 vht_cap.cap = ar->vht_cap_info;
6332
Michal Kaziorbc657a362015-02-26 11:11:22 +01006333 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
6334 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
6335 val = ar->num_rf_chains - 1;
6336 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
6337 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
6338
6339 vht_cap.cap |= val;
6340 }
6341
6342 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
6343 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
6344 val = ar->num_rf_chains - 1;
6345 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
6346 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
6347
6348 vht_cap.cap |= val;
6349 }
6350
Michal Kazior8865bee42013-07-24 12:36:46 +02006351 mcs_map = 0;
6352 for (i = 0; i < 8; i++) {
6353 if (i < ar->num_rf_chains)
6354 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
6355 else
6356 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
6357 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03006358
6359 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
6360 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
6361
6362 return vht_cap;
6363}
6364
6365static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
6366{
6367 int i;
6368 struct ieee80211_sta_ht_cap ht_cap = {0};
6369
6370 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
6371 return ht_cap;
6372
6373 ht_cap.ht_supported = 1;
6374 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
6375 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
6376 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
6377 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
6378 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
6379
6380 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
6381 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
6382
6383 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
6384 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
6385
6386 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
6387 u32 smps;
6388
6389 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
6390 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
6391
6392 ht_cap.cap |= smps;
6393 }
6394
6395 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
6396 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
6397
6398 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
6399 u32 stbc;
6400
6401 stbc = ar->ht_cap_info;
6402 stbc &= WMI_HT_CAP_RX_STBC;
6403 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
6404 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
6405 stbc &= IEEE80211_HT_CAP_RX_STBC;
6406
6407 ht_cap.cap |= stbc;
6408 }
6409
6410 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
6411 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
6412
6413 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
6414 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
6415
6416 /* max AMSDU is implicitly taken from vht_cap_info */
6417 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
6418 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
6419
Michal Kazior8865bee42013-07-24 12:36:46 +02006420 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03006421 ht_cap.mcs.rx_mask[i] = 0xFF;
6422
6423 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
6424
6425 return ht_cap;
6426}
6427
Kalle Valo5e3dd152013-06-12 20:52:10 +03006428static void ath10k_get_arvif_iter(void *data, u8 *mac,
6429 struct ieee80211_vif *vif)
6430{
6431 struct ath10k_vif_iter *arvif_iter = data;
6432 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6433
6434 if (arvif->vdev_id == arvif_iter->vdev_id)
6435 arvif_iter->arvif = arvif;
6436}
6437
6438struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
6439{
6440 struct ath10k_vif_iter arvif_iter;
6441 u32 flags;
6442
6443 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
6444 arvif_iter.vdev_id = vdev_id;
6445
6446 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
6447 ieee80211_iterate_active_interfaces_atomic(ar->hw,
6448 flags,
6449 ath10k_get_arvif_iter,
6450 &arvif_iter);
6451 if (!arvif_iter.arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02006452 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006453 return NULL;
6454 }
6455
6456 return arvif_iter.arvif;
6457}
6458
6459int ath10k_mac_register(struct ath10k *ar)
6460{
Johannes Berg3cb10942015-01-22 21:38:45 +01006461 static const u32 cipher_suites[] = {
6462 WLAN_CIPHER_SUITE_WEP40,
6463 WLAN_CIPHER_SUITE_WEP104,
6464 WLAN_CIPHER_SUITE_TKIP,
6465 WLAN_CIPHER_SUITE_CCMP,
6466 WLAN_CIPHER_SUITE_AES_CMAC,
6467 };
Kalle Valo5e3dd152013-06-12 20:52:10 +03006468 struct ieee80211_supported_band *band;
6469 struct ieee80211_sta_vht_cap vht_cap;
6470 struct ieee80211_sta_ht_cap ht_cap;
6471 void *channels;
6472 int ret;
6473
6474 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
6475
6476 SET_IEEE80211_DEV(ar->hw, ar->dev);
6477
6478 ht_cap = ath10k_get_ht_cap(ar);
6479 vht_cap = ath10k_create_vht_cap(ar);
6480
Michal Kaziorc94aa7e2015-03-24 12:38:11 +00006481 BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels) +
6482 ARRAY_SIZE(ath10k_5ghz_channels)) !=
6483 ATH10K_NUM_CHANS);
6484
Kalle Valo5e3dd152013-06-12 20:52:10 +03006485 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
6486 channels = kmemdup(ath10k_2ghz_channels,
6487 sizeof(ath10k_2ghz_channels),
6488 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02006489 if (!channels) {
6490 ret = -ENOMEM;
6491 goto err_free;
6492 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03006493
6494 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
6495 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
6496 band->channels = channels;
6497 band->n_bitrates = ath10k_g_rates_size;
6498 band->bitrates = ath10k_g_rates;
6499 band->ht_cap = ht_cap;
6500
Yanbo Lid68bb122015-01-23 08:18:20 +08006501 /* Enable the VHT support at 2.4 GHz */
6502 band->vht_cap = vht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006503
6504 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
6505 }
6506
6507 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
6508 channels = kmemdup(ath10k_5ghz_channels,
6509 sizeof(ath10k_5ghz_channels),
6510 GFP_KERNEL);
6511 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02006512 ret = -ENOMEM;
6513 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006514 }
6515
6516 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
6517 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
6518 band->channels = channels;
6519 band->n_bitrates = ath10k_a_rates_size;
6520 band->bitrates = ath10k_a_rates;
6521 band->ht_cap = ht_cap;
6522 band->vht_cap = vht_cap;
6523 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
6524 }
6525
6526 ar->hw->wiphy->interface_modes =
6527 BIT(NL80211_IFTYPE_STATION) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01006528 BIT(NL80211_IFTYPE_AP);
6529
Ben Greear46acf7b2014-05-16 17:15:38 +03006530 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
6531 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
6532
Bartosz Markowskid3541812013-12-10 16:20:40 +01006533 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
6534 ar->hw->wiphy->interface_modes |=
Michal Kazior75d2bd42014-12-12 12:41:39 +01006535 BIT(NL80211_IFTYPE_P2P_DEVICE) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01006536 BIT(NL80211_IFTYPE_P2P_CLIENT) |
6537 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006538
6539 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
6540 IEEE80211_HW_SUPPORTS_PS |
6541 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
Kalle Valo5e3dd152013-06-12 20:52:10 +03006542 IEEE80211_HW_MFP_CAPABLE |
6543 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
6544 IEEE80211_HW_HAS_RATE_CONTROL |
Janusz Dziedzic2f0f1122014-02-26 18:42:09 +02006545 IEEE80211_HW_AP_LINK_PS |
Johannes Berg3cb10942015-01-22 21:38:45 +01006546 IEEE80211_HW_SPECTRUM_MGMT |
Michal Kaziorcc9904e2015-03-10 16:22:01 +02006547 IEEE80211_HW_SW_CRYPTO_CONTROL |
Michal Kazior500ff9f2015-03-31 10:26:21 +00006548 IEEE80211_HW_CONNECTION_MONITOR |
6549 IEEE80211_HW_WANT_MONITOR_VIF |
6550 IEEE80211_HW_CHANCTX_STA_CSA;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006551
Eliad Peller0d8614b2014-09-10 14:07:36 +03006552 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
6553
Kalle Valo5e3dd152013-06-12 20:52:10 +03006554 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
Eliad Peller0d8614b2014-09-10 14:07:36 +03006555 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006556
6557 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
6558 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
6559 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
6560 }
6561
6562 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
6563 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
6564
6565 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01006566 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006567 ar->hw->chanctx_data_size = sizeof(struct ath10k_chanctx);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006568
Kalle Valo5e3dd152013-06-12 20:52:10 +03006569 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
6570
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02006571 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
6572 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
6573
6574 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
6575 * that userspace (e.g. wpa_supplicant/hostapd) can generate
6576 * correct Probe Responses. This is more of a hack advert..
6577 */
6578 ar->hw->wiphy->probe_resp_offload |=
6579 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
6580 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
6581 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
6582 }
6583
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03006584 if (test_bit(WMI_SERVICE_TDLS, ar->wmi.svc_map))
6585 ar->hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
6586
Kalle Valo5e3dd152013-06-12 20:52:10 +03006587 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01006588 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006589 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
6590
6591 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
Rajkumar Manoharan78157a12014-11-17 16:44:15 +02006592 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
6593
Janusz.Dziedzic@tieto.com37a0b392015-03-12 13:11:41 +01006594 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
6595
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +02006596 ret = ath10k_wow_init(ar);
6597 if (ret) {
6598 ath10k_warn(ar, "failed to init wow: %d\n", ret);
6599 goto err_free;
6600 }
6601
Kalle Valo5e3dd152013-06-12 20:52:10 +03006602 /*
6603 * on LL hardware queues are managed entirely by the FW
6604 * so we only advertise to mac we can do the queues thing
6605 */
6606 ar->hw->queues = 4;
6607
Kalle Valo5cc7caf2014-12-17 12:20:54 +02006608 switch (ar->wmi.op_version) {
6609 case ATH10K_FW_WMI_OP_VERSION_MAIN:
6610 case ATH10K_FW_WMI_OP_VERSION_TLV:
Bartosz Markowskif2595092013-12-10 16:20:39 +01006611 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
6612 ar->hw->wiphy->n_iface_combinations =
6613 ARRAY_SIZE(ath10k_if_comb);
Michal Kaziorcf850d12014-07-24 20:07:00 +03006614 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
Kalle Valo5cc7caf2014-12-17 12:20:54 +02006615 break;
6616 case ATH10K_FW_WMI_OP_VERSION_10_1:
6617 case ATH10K_FW_WMI_OP_VERSION_10_2:
Rajkumar Manoharan4a16fbe2014-12-17 12:21:12 +02006618 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
Kalle Valo5cc7caf2014-12-17 12:20:54 +02006619 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
6620 ar->hw->wiphy->n_iface_combinations =
6621 ARRAY_SIZE(ath10k_10x_if_comb);
6622 break;
6623 case ATH10K_FW_WMI_OP_VERSION_UNSET:
6624 case ATH10K_FW_WMI_OP_VERSION_MAX:
6625 WARN_ON(1);
6626 ret = -EINVAL;
6627 goto err_free;
Bartosz Markowskif2595092013-12-10 16:20:39 +01006628 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03006629
Michal Kazior7c199992013-07-31 10:47:57 +02006630 ar->hw->netdev_features = NETIF_F_HW_CSUM;
6631
Janusz Dziedzic9702c682013-11-20 09:59:41 +02006632 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
6633 /* Init ath dfs pattern detector */
6634 ar->ath_common.debug_mask = ATH_DBG_DFS;
6635 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
6636 NL80211_DFS_UNSET);
6637
6638 if (!ar->dfs_detector)
Michal Kazior7aa7a722014-08-25 12:09:38 +02006639 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02006640 }
6641
Kalle Valo5e3dd152013-06-12 20:52:10 +03006642 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
6643 ath10k_reg_notifier);
6644 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02006645 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02006646 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006647 }
6648
Johannes Berg3cb10942015-01-22 21:38:45 +01006649 ar->hw->wiphy->cipher_suites = cipher_suites;
6650 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
6651
Kalle Valo5e3dd152013-06-12 20:52:10 +03006652 ret = ieee80211_register_hw(ar->hw);
6653 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02006654 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02006655 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006656 }
6657
6658 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
6659 ret = regulatory_hint(ar->hw->wiphy,
6660 ar->ath_common.regulatory.alpha2);
6661 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02006662 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006663 }
6664
6665 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02006666
6667err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03006668 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02006669err_free:
6670 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
6671 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
6672
Kalle Valo5e3dd152013-06-12 20:52:10 +03006673 return ret;
6674}
6675
6676void ath10k_mac_unregister(struct ath10k *ar)
6677{
6678 ieee80211_unregister_hw(ar->hw);
6679
Janusz Dziedzic9702c682013-11-20 09:59:41 +02006680 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
6681 ar->dfs_detector->exit(ar->dfs_detector);
6682
Kalle Valo5e3dd152013-06-12 20:52:10 +03006683 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
6684 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
6685
6686 SET_IEEE80211_DEV(ar->hw, NULL);
6687}