blob: e455dabedd1a26ebd69033561295a937edff663d [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"
Michal Kaziorb4aa5392015-03-31 10:26:24 +000031#include "wmi-tlv.h"
Michal Kaziord7579d12014-12-03 10:10:54 +020032#include "wmi-ops.h"
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +020033#include "wow.h"
Kalle Valo5e3dd152013-06-12 20:52:10 +030034
Michal Kaziordcc33092015-03-30 09:51:54 +030035/*********/
36/* Rates */
37/*********/
38
Michal Kaziordcc33092015-03-30 09:51:54 +030039static struct ieee80211_rate ath10k_rates[] = {
Michal Kazior5528e032015-03-30 09:51:56 +030040 { .bitrate = 10,
41 .hw_value = ATH10K_HW_RATE_CCK_LP_1M },
42 { .bitrate = 20,
43 .hw_value = ATH10K_HW_RATE_CCK_LP_2M,
44 .hw_value_short = ATH10K_HW_RATE_CCK_SP_2M,
45 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
46 { .bitrate = 55,
47 .hw_value = ATH10K_HW_RATE_CCK_LP_5_5M,
48 .hw_value_short = ATH10K_HW_RATE_CCK_SP_5_5M,
49 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
50 { .bitrate = 110,
51 .hw_value = ATH10K_HW_RATE_CCK_LP_11M,
52 .hw_value_short = ATH10K_HW_RATE_CCK_SP_11M,
53 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
Michal Kazior5653b392015-03-30 09:51:54 +030054
Michal Kazioraf001482015-03-30 09:51:56 +030055 { .bitrate = 60, .hw_value = ATH10K_HW_RATE_OFDM_6M },
56 { .bitrate = 90, .hw_value = ATH10K_HW_RATE_OFDM_9M },
57 { .bitrate = 120, .hw_value = ATH10K_HW_RATE_OFDM_12M },
58 { .bitrate = 180, .hw_value = ATH10K_HW_RATE_OFDM_18M },
59 { .bitrate = 240, .hw_value = ATH10K_HW_RATE_OFDM_24M },
60 { .bitrate = 360, .hw_value = ATH10K_HW_RATE_OFDM_36M },
61 { .bitrate = 480, .hw_value = ATH10K_HW_RATE_OFDM_48M },
62 { .bitrate = 540, .hw_value = ATH10K_HW_RATE_OFDM_54M },
Michal Kaziordcc33092015-03-30 09:51:54 +030063};
64
Michal Kazior8d7aa6b2015-03-30 09:51:57 +030065#define ATH10K_MAC_FIRST_OFDM_RATE_IDX 4
66
67#define ath10k_a_rates (ath10k_rates + ATH10K_MAC_FIRST_OFDM_RATE_IDX)
68#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - \
69 ATH10K_MAC_FIRST_OFDM_RATE_IDX)
Michal Kaziordcc33092015-03-30 09:51:54 +030070#define ath10k_g_rates (ath10k_rates + 0)
71#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
72
Michal Kazior486017c2015-03-30 09:51:54 +030073static bool ath10k_mac_bitrate_is_cck(int bitrate)
74{
75 switch (bitrate) {
76 case 10:
77 case 20:
78 case 55:
79 case 110:
80 return true;
81 }
82
83 return false;
84}
85
86static u8 ath10k_mac_bitrate_to_rate(int bitrate)
87{
88 return DIV_ROUND_UP(bitrate, 5) |
89 (ath10k_mac_bitrate_is_cck(bitrate) ? BIT(7) : 0);
90}
91
Michal Kazior5528e032015-03-30 09:51:56 +030092u8 ath10k_mac_hw_rate_to_idx(const struct ieee80211_supported_band *sband,
93 u8 hw_rate)
94{
95 const struct ieee80211_rate *rate;
96 int i;
97
98 for (i = 0; i < sband->n_bitrates; i++) {
99 rate = &sband->bitrates[i];
100
101 if (rate->hw_value == hw_rate)
102 return i;
103 else if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE &&
104 rate->hw_value_short == hw_rate)
105 return i;
106 }
107
108 return 0;
109}
110
Michal Kazior01cebe12015-03-30 09:51:56 +0300111u8 ath10k_mac_bitrate_to_idx(const struct ieee80211_supported_band *sband,
112 u32 bitrate)
113{
114 int i;
115
116 for (i = 0; i < sband->n_bitrates; i++)
117 if (sband->bitrates[i].bitrate == bitrate)
118 return i;
119
120 return 0;
121}
122
Kalle Valo5e3dd152013-06-12 20:52:10 +0300123/**********/
124/* Crypto */
125/**********/
126
127static int ath10k_send_key(struct ath10k_vif *arvif,
128 struct ieee80211_key_conf *key,
129 enum set_key_cmd cmd,
Michal Kazior370e5672015-02-18 14:02:26 +0100130 const u8 *macaddr, u32 flags)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300131{
Michal Kazior7aa7a722014-08-25 12:09:38 +0200132 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300133 struct wmi_vdev_install_key_arg arg = {
134 .vdev_id = arvif->vdev_id,
135 .key_idx = key->keyidx,
136 .key_len = key->keylen,
137 .key_data = key->key,
Michal Kazior370e5672015-02-18 14:02:26 +0100138 .key_flags = flags,
Kalle Valo5e3dd152013-06-12 20:52:10 +0300139 .macaddr = macaddr,
140 };
141
Michal Kazior548db542013-07-05 16:15:15 +0300142 lockdep_assert_held(&arvif->ar->conf_mutex);
143
Kalle Valo5e3dd152013-06-12 20:52:10 +0300144 switch (key->cipher) {
145 case WLAN_CIPHER_SUITE_CCMP:
146 arg.key_cipher = WMI_CIPHER_AES_CCM;
Marek Kwaczynskie4e82e92015-01-24 12:14:53 +0200147 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300148 break;
149 case WLAN_CIPHER_SUITE_TKIP:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300150 arg.key_cipher = WMI_CIPHER_TKIP;
151 arg.key_txmic_len = 8;
152 arg.key_rxmic_len = 8;
153 break;
154 case WLAN_CIPHER_SUITE_WEP40:
155 case WLAN_CIPHER_SUITE_WEP104:
156 arg.key_cipher = WMI_CIPHER_WEP;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300157 break;
Johannes Berg3cb10942015-01-22 21:38:45 +0100158 case WLAN_CIPHER_SUITE_AES_CMAC:
Bartosz Markowskid7131c02015-03-10 14:32:19 +0100159 WARN_ON(1);
160 return -EINVAL;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300161 default:
Michal Kazior7aa7a722014-08-25 12:09:38 +0200162 ath10k_warn(ar, "cipher %d is not supported\n", key->cipher);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300163 return -EOPNOTSUPP;
164 }
165
166 if (cmd == DISABLE_KEY) {
167 arg.key_cipher = WMI_CIPHER_NONE;
168 arg.key_data = NULL;
169 }
170
171 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
172}
173
174static int ath10k_install_key(struct ath10k_vif *arvif,
175 struct ieee80211_key_conf *key,
176 enum set_key_cmd cmd,
Michal Kazior370e5672015-02-18 14:02:26 +0100177 const u8 *macaddr, u32 flags)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300178{
179 struct ath10k *ar = arvif->ar;
180 int ret;
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +0300181 unsigned long time_left;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300182
Michal Kazior548db542013-07-05 16:15:15 +0300183 lockdep_assert_held(&ar->conf_mutex);
184
Wolfram Sang16735d02013-11-14 14:32:02 -0800185 reinit_completion(&ar->install_key_done);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300186
Michal Kazior370e5672015-02-18 14:02:26 +0100187 ret = ath10k_send_key(arvif, key, cmd, macaddr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300188 if (ret)
189 return ret;
190
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +0300191 time_left = wait_for_completion_timeout(&ar->install_key_done, 3 * HZ);
192 if (time_left == 0)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300193 return -ETIMEDOUT;
194
195 return 0;
196}
197
198static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
199 const u8 *addr)
200{
201 struct ath10k *ar = arvif->ar;
202 struct ath10k_peer *peer;
203 int ret;
204 int i;
Michal Kazior370e5672015-02-18 14:02:26 +0100205 u32 flags;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300206
207 lockdep_assert_held(&ar->conf_mutex);
208
209 spin_lock_bh(&ar->data_lock);
210 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
211 spin_unlock_bh(&ar->data_lock);
212
213 if (!peer)
214 return -ENOENT;
215
216 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
217 if (arvif->wep_keys[i] == NULL)
218 continue;
Michal Kazior370e5672015-02-18 14:02:26 +0100219
220 flags = 0;
221 flags |= WMI_KEY_PAIRWISE;
222
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200223 /* set TX_USAGE flag for default key id */
224 if (arvif->def_wep_key_idx == i)
Michal Kazior370e5672015-02-18 14:02:26 +0100225 flags |= WMI_KEY_TX_USAGE;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300226
227 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
Michal Kazior370e5672015-02-18 14:02:26 +0100228 addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300229 if (ret)
230 return ret;
231
Sujith Manoharanae167132014-11-25 11:46:59 +0530232 spin_lock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300233 peer->keys[i] = arvif->wep_keys[i];
Sujith Manoharanae167132014-11-25 11:46:59 +0530234 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300235 }
236
237 return 0;
238}
239
240static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
241 const u8 *addr)
242{
243 struct ath10k *ar = arvif->ar;
244 struct ath10k_peer *peer;
245 int first_errno = 0;
246 int ret;
247 int i;
Michal Kazior370e5672015-02-18 14:02:26 +0100248 u32 flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300249
250 lockdep_assert_held(&ar->conf_mutex);
251
252 spin_lock_bh(&ar->data_lock);
253 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
254 spin_unlock_bh(&ar->data_lock);
255
256 if (!peer)
257 return -ENOENT;
258
259 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
260 if (peer->keys[i] == NULL)
261 continue;
262
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200263 /* key flags are not required to delete the key */
Kalle Valo5e3dd152013-06-12 20:52:10 +0300264 ret = ath10k_install_key(arvif, peer->keys[i],
Michal Kazior370e5672015-02-18 14:02:26 +0100265 DISABLE_KEY, addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300266 if (ret && first_errno == 0)
267 first_errno = ret;
268
269 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200270 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300271 i, ret);
272
Sujith Manoharanae167132014-11-25 11:46:59 +0530273 spin_lock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300274 peer->keys[i] = NULL;
Sujith Manoharanae167132014-11-25 11:46:59 +0530275 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300276 }
277
278 return first_errno;
279}
280
Sujith Manoharan504f6cd2014-11-25 11:46:58 +0530281bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr,
282 u8 keyidx)
283{
284 struct ath10k_peer *peer;
285 int i;
286
287 lockdep_assert_held(&ar->data_lock);
288
289 /* We don't know which vdev this peer belongs to,
290 * since WMI doesn't give us that information.
291 *
292 * FIXME: multi-bss needs to be handled.
293 */
294 peer = ath10k_peer_find(ar, 0, addr);
295 if (!peer)
296 return false;
297
298 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
299 if (peer->keys[i] && peer->keys[i]->keyidx == keyidx)
300 return true;
301 }
302
303 return false;
304}
305
Kalle Valo5e3dd152013-06-12 20:52:10 +0300306static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
307 struct ieee80211_key_conf *key)
308{
309 struct ath10k *ar = arvif->ar;
310 struct ath10k_peer *peer;
311 u8 addr[ETH_ALEN];
312 int first_errno = 0;
313 int ret;
314 int i;
Michal Kazior370e5672015-02-18 14:02:26 +0100315 u32 flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300316
317 lockdep_assert_held(&ar->conf_mutex);
318
319 for (;;) {
320 /* since ath10k_install_key we can't hold data_lock all the
321 * time, so we try to remove the keys incrementally */
322 spin_lock_bh(&ar->data_lock);
323 i = 0;
324 list_for_each_entry(peer, &ar->peers, list) {
325 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
326 if (peer->keys[i] == key) {
Kalle Valob25f32c2014-09-14 12:50:49 +0300327 ether_addr_copy(addr, peer->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300328 peer->keys[i] = NULL;
329 break;
330 }
331 }
332
333 if (i < ARRAY_SIZE(peer->keys))
334 break;
335 }
336 spin_unlock_bh(&ar->data_lock);
337
338 if (i == ARRAY_SIZE(peer->keys))
339 break;
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200340 /* key flags are not required to delete the key */
Michal Kazior370e5672015-02-18 14:02:26 +0100341 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300342 if (ret && first_errno == 0)
343 first_errno = ret;
344
345 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200346 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +0200347 addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300348 }
349
350 return first_errno;
351}
352
Michal Kazior370e5672015-02-18 14:02:26 +0100353static int ath10k_mac_vif_sta_fix_wep_key(struct ath10k_vif *arvif)
354{
355 struct ath10k *ar = arvif->ar;
356 enum nl80211_iftype iftype = arvif->vif->type;
357 struct ieee80211_key_conf *key;
358 u32 flags = 0;
359 int num = 0;
360 int i;
361 int ret;
362
363 lockdep_assert_held(&ar->conf_mutex);
364
365 if (iftype != NL80211_IFTYPE_STATION)
366 return 0;
367
368 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
369 if (arvif->wep_keys[i]) {
370 key = arvif->wep_keys[i];
371 ++num;
372 }
373 }
374
375 if (num != 1)
376 return 0;
377
378 flags |= WMI_KEY_PAIRWISE;
379 flags |= WMI_KEY_TX_USAGE;
380
381 ret = ath10k_install_key(arvif, key, SET_KEY, arvif->bssid, flags);
382 if (ret) {
383 ath10k_warn(ar, "failed to install key %i on vdev %i: %d\n",
384 key->keyidx, arvif->vdev_id, ret);
385 return ret;
386 }
387
388 return 0;
389}
390
Michal Kaziorad325cb2015-02-18 14:02:27 +0100391static int ath10k_mac_vif_update_wep_key(struct ath10k_vif *arvif,
392 struct ieee80211_key_conf *key)
393{
394 struct ath10k *ar = arvif->ar;
395 struct ath10k_peer *peer;
396 int ret;
397
398 lockdep_assert_held(&ar->conf_mutex);
399
400 list_for_each_entry(peer, &ar->peers, list) {
401 if (!memcmp(peer->addr, arvif->vif->addr, ETH_ALEN))
402 continue;
403
404 if (!memcmp(peer->addr, arvif->bssid, ETH_ALEN))
405 continue;
406
407 if (peer->keys[key->keyidx] == key)
408 continue;
409
410 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vif vdev %i update key %i needs update\n",
411 arvif->vdev_id, key->keyidx);
412
413 ret = ath10k_install_peer_wep_keys(arvif, peer->addr);
414 if (ret) {
415 ath10k_warn(ar, "failed to update wep keys on vdev %i for peer %pM: %d\n",
416 arvif->vdev_id, peer->addr, ret);
417 return ret;
418 }
419 }
420
421 return 0;
422}
423
Kalle Valo5e3dd152013-06-12 20:52:10 +0300424/*********************/
425/* General utilities */
426/*********************/
427
428static inline enum wmi_phy_mode
429chan_to_phymode(const struct cfg80211_chan_def *chandef)
430{
431 enum wmi_phy_mode phymode = MODE_UNKNOWN;
432
433 switch (chandef->chan->band) {
434 case IEEE80211_BAND_2GHZ:
435 switch (chandef->width) {
436 case NL80211_CHAN_WIDTH_20_NOHT:
Peter Oh6faab122014-12-18 10:13:00 -0800437 if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM)
438 phymode = MODE_11B;
439 else
440 phymode = MODE_11G;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300441 break;
442 case NL80211_CHAN_WIDTH_20:
443 phymode = MODE_11NG_HT20;
444 break;
445 case NL80211_CHAN_WIDTH_40:
446 phymode = MODE_11NG_HT40;
447 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400448 case NL80211_CHAN_WIDTH_5:
449 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300450 case NL80211_CHAN_WIDTH_80:
451 case NL80211_CHAN_WIDTH_80P80:
452 case NL80211_CHAN_WIDTH_160:
453 phymode = MODE_UNKNOWN;
454 break;
455 }
456 break;
457 case IEEE80211_BAND_5GHZ:
458 switch (chandef->width) {
459 case NL80211_CHAN_WIDTH_20_NOHT:
460 phymode = MODE_11A;
461 break;
462 case NL80211_CHAN_WIDTH_20:
463 phymode = MODE_11NA_HT20;
464 break;
465 case NL80211_CHAN_WIDTH_40:
466 phymode = MODE_11NA_HT40;
467 break;
468 case NL80211_CHAN_WIDTH_80:
469 phymode = MODE_11AC_VHT80;
470 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400471 case NL80211_CHAN_WIDTH_5:
472 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300473 case NL80211_CHAN_WIDTH_80P80:
474 case NL80211_CHAN_WIDTH_160:
475 phymode = MODE_UNKNOWN;
476 break;
477 }
478 break;
479 default:
480 break;
481 }
482
483 WARN_ON(phymode == MODE_UNKNOWN);
484 return phymode;
485}
486
487static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
488{
489/*
490 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
491 * 0 for no restriction
492 * 1 for 1/4 us
493 * 2 for 1/2 us
494 * 3 for 1 us
495 * 4 for 2 us
496 * 5 for 4 us
497 * 6 for 8 us
498 * 7 for 16 us
499 */
500 switch (mpdudensity) {
501 case 0:
502 return 0;
503 case 1:
504 case 2:
505 case 3:
506 /* Our lower layer calculations limit our precision to
507 1 microsecond */
508 return 1;
509 case 4:
510 return 2;
511 case 5:
512 return 4;
513 case 6:
514 return 8;
515 case 7:
516 return 16;
517 default:
518 return 0;
519 }
520}
521
Michal Kazior500ff9f2015-03-31 10:26:21 +0000522int ath10k_mac_vif_chan(struct ieee80211_vif *vif,
523 struct cfg80211_chan_def *def)
524{
525 struct ieee80211_chanctx_conf *conf;
526
527 rcu_read_lock();
528 conf = rcu_dereference(vif->chanctx_conf);
529 if (!conf) {
530 rcu_read_unlock();
531 return -ENOENT;
532 }
533
534 *def = conf->def;
535 rcu_read_unlock();
536
537 return 0;
538}
539
540static void ath10k_mac_num_chanctxs_iter(struct ieee80211_hw *hw,
541 struct ieee80211_chanctx_conf *conf,
542 void *data)
543{
544 int *num = data;
545
546 (*num)++;
547}
548
549static int ath10k_mac_num_chanctxs(struct ath10k *ar)
550{
551 int num = 0;
552
553 ieee80211_iter_chan_contexts_atomic(ar->hw,
554 ath10k_mac_num_chanctxs_iter,
555 &num);
556
557 return num;
558}
559
560static void
561ath10k_mac_get_any_chandef_iter(struct ieee80211_hw *hw,
562 struct ieee80211_chanctx_conf *conf,
563 void *data)
564{
565 struct cfg80211_chan_def **def = data;
566
567 *def = &conf->def;
568}
569
Marek Puzyniak7390ed32015-03-30 09:51:52 +0300570static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr,
571 enum wmi_peer_type peer_type)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300572{
573 int ret;
574
575 lockdep_assert_held(&ar->conf_mutex);
576
Michal Kaziorcfd10612014-11-25 15:16:05 +0100577 if (ar->num_peers >= ar->max_num_peers)
578 return -ENOBUFS;
579
Marek Puzyniak7390ed32015-03-30 09:51:52 +0300580 ret = ath10k_wmi_peer_create(ar, vdev_id, addr, peer_type);
Ben Greear479398b2013-11-04 09:19:34 -0800581 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200582 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200583 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300584 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800585 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300586
587 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800588 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200589 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200590 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300591 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800592 }
Michal Kazior292a7532014-11-25 15:16:04 +0100593
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100594 ar->num_peers++;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300595
596 return 0;
597}
598
Kalle Valo5a13e762014-01-20 11:01:46 +0200599static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
600{
601 struct ath10k *ar = arvif->ar;
602 u32 param;
603 int ret;
604
605 param = ar->wmi.pdev_param->sta_kickout_th;
606 ret = ath10k_wmi_pdev_set_param(ar, param,
607 ATH10K_KICKOUT_THRESHOLD);
608 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200609 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200610 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200611 return ret;
612 }
613
614 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
615 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
616 ATH10K_KEEPALIVE_MIN_IDLE);
617 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200618 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200619 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200620 return ret;
621 }
622
623 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
624 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
625 ATH10K_KEEPALIVE_MAX_IDLE);
626 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200627 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200628 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200629 return ret;
630 }
631
632 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
633 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
634 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
635 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200636 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200637 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200638 return ret;
639 }
640
641 return 0;
642}
643
Vivek Natarajanacab6402014-11-26 09:06:12 +0200644static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
Michal Kazior424121c2013-07-22 14:13:31 +0200645{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200646 struct ath10k *ar = arvif->ar;
647 u32 vdev_param;
648
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200649 vdev_param = ar->wmi.vdev_param->rts_threshold;
650 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200651}
652
653static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
654{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200655 struct ath10k *ar = arvif->ar;
656 u32 vdev_param;
657
Michal Kazior424121c2013-07-22 14:13:31 +0200658 if (value != 0xFFFFFFFF)
659 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
660 ATH10K_FRAGMT_THRESHOLD_MIN,
661 ATH10K_FRAGMT_THRESHOLD_MAX);
662
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200663 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
664 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200665}
666
Kalle Valo5e3dd152013-06-12 20:52:10 +0300667static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
668{
669 int ret;
670
671 lockdep_assert_held(&ar->conf_mutex);
672
673 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
674 if (ret)
675 return ret;
676
677 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
678 if (ret)
679 return ret;
680
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100681 ar->num_peers--;
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100682
Kalle Valo5e3dd152013-06-12 20:52:10 +0300683 return 0;
684}
685
686static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
687{
688 struct ath10k_peer *peer, *tmp;
689
690 lockdep_assert_held(&ar->conf_mutex);
691
692 spin_lock_bh(&ar->data_lock);
693 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
694 if (peer->vdev_id != vdev_id)
695 continue;
696
Michal Kazior7aa7a722014-08-25 12:09:38 +0200697 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300698 peer->addr, vdev_id);
699
700 list_del(&peer->list);
701 kfree(peer);
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100702 ar->num_peers--;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300703 }
704 spin_unlock_bh(&ar->data_lock);
705}
706
Michal Kaziora96d7742013-07-16 09:38:56 +0200707static void ath10k_peer_cleanup_all(struct ath10k *ar)
708{
709 struct ath10k_peer *peer, *tmp;
710
711 lockdep_assert_held(&ar->conf_mutex);
712
713 spin_lock_bh(&ar->data_lock);
714 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
715 list_del(&peer->list);
716 kfree(peer);
717 }
718 spin_unlock_bh(&ar->data_lock);
Michal Kazior292a7532014-11-25 15:16:04 +0100719
720 ar->num_peers = 0;
Michal Kaziorcfd10612014-11-25 15:16:05 +0100721 ar->num_stations = 0;
Michal Kaziora96d7742013-07-16 09:38:56 +0200722}
723
Marek Puzyniak75d85fd2015-03-30 09:51:53 +0300724static int ath10k_mac_tdls_peer_update(struct ath10k *ar, u32 vdev_id,
725 struct ieee80211_sta *sta,
726 enum wmi_tdls_peer_state state)
727{
728 int ret;
729 struct wmi_tdls_peer_update_cmd_arg arg = {};
730 struct wmi_tdls_peer_capab_arg cap = {};
731 struct wmi_channel_arg chan_arg = {};
732
733 lockdep_assert_held(&ar->conf_mutex);
734
735 arg.vdev_id = vdev_id;
736 arg.peer_state = state;
737 ether_addr_copy(arg.addr, sta->addr);
738
739 cap.peer_max_sp = sta->max_sp;
740 cap.peer_uapsd_queues = sta->uapsd_queues;
741
742 if (state == WMI_TDLS_PEER_STATE_CONNECTED &&
743 !sta->tdls_initiator)
744 cap.is_peer_responder = 1;
745
746 ret = ath10k_wmi_tdls_peer_update(ar, &arg, &cap, &chan_arg);
747 if (ret) {
748 ath10k_warn(ar, "failed to update tdls peer %pM on vdev %i: %i\n",
749 arg.addr, vdev_id, ret);
750 return ret;
751 }
752
753 return 0;
754}
755
Kalle Valo5e3dd152013-06-12 20:52:10 +0300756/************************/
757/* Interface management */
758/************************/
759
Michal Kazior64badcb2014-09-18 11:18:02 +0300760void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
761{
762 struct ath10k *ar = arvif->ar;
763
764 lockdep_assert_held(&ar->data_lock);
765
766 if (!arvif->beacon)
767 return;
768
769 if (!arvif->beacon_buf)
770 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
771 arvif->beacon->len, DMA_TO_DEVICE);
772
Michal Kazioraf213192015-01-29 14:29:52 +0200773 if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED &&
774 arvif->beacon_state != ATH10K_BEACON_SENT))
775 return;
776
Michal Kazior64badcb2014-09-18 11:18:02 +0300777 dev_kfree_skb_any(arvif->beacon);
778
779 arvif->beacon = NULL;
Michal Kazioraf213192015-01-29 14:29:52 +0200780 arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
Michal Kazior64badcb2014-09-18 11:18:02 +0300781}
782
783static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
784{
785 struct ath10k *ar = arvif->ar;
786
787 lockdep_assert_held(&ar->data_lock);
788
789 ath10k_mac_vif_beacon_free(arvif);
790
791 if (arvif->beacon_buf) {
792 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
793 arvif->beacon_buf, arvif->beacon_paddr);
794 arvif->beacon_buf = NULL;
795 }
796}
797
Kalle Valo5e3dd152013-06-12 20:52:10 +0300798static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
799{
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +0300800 unsigned long time_left;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300801
Michal Kazior548db542013-07-05 16:15:15 +0300802 lockdep_assert_held(&ar->conf_mutex);
803
Michal Kazior7962b0d2014-10-28 10:34:38 +0100804 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
805 return -ESHUTDOWN;
806
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +0300807 time_left = wait_for_completion_timeout(&ar->vdev_setup_done,
808 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
809 if (time_left == 0)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300810 return -ETIMEDOUT;
811
812 return 0;
813}
814
Michal Kazior1bbc0972014-04-08 09:45:47 +0300815static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300816{
Michal Kazior500ff9f2015-03-31 10:26:21 +0000817 struct cfg80211_chan_def *chandef = NULL;
Michal Kaziorc930f742014-01-23 11:38:25 +0100818 struct ieee80211_channel *channel = chandef->chan;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300819 struct wmi_vdev_start_request_arg arg = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +0300820 int ret = 0;
821
822 lockdep_assert_held(&ar->conf_mutex);
823
Michal Kazior500ff9f2015-03-31 10:26:21 +0000824 ieee80211_iter_chan_contexts_atomic(ar->hw,
825 ath10k_mac_get_any_chandef_iter,
826 &chandef);
827 if (WARN_ON_ONCE(!chandef))
828 return -ENOENT;
829
830 channel = chandef->chan;
831
Kalle Valo5e3dd152013-06-12 20:52:10 +0300832 arg.vdev_id = vdev_id;
833 arg.channel.freq = channel->center_freq;
Michal Kaziorc930f742014-01-23 11:38:25 +0100834 arg.channel.band_center_freq1 = chandef->center_freq1;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300835
836 /* TODO setup this dynamically, what in case we
837 don't have any vifs? */
Michal Kaziorc930f742014-01-23 11:38:25 +0100838 arg.channel.mode = chan_to_phymode(chandef);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200839 arg.channel.chan_radar =
840 !!(channel->flags & IEEE80211_CHAN_RADAR);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300841
Michal Kazior89c5c842013-10-23 04:02:13 -0700842 arg.channel.min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -0700843 arg.channel.max_power = channel->max_power * 2;
844 arg.channel.max_reg_power = channel->max_reg_power * 2;
845 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300846
Michal Kazior7962b0d2014-10-28 10:34:38 +0100847 reinit_completion(&ar->vdev_setup_done);
848
Kalle Valo5e3dd152013-06-12 20:52:10 +0300849 ret = ath10k_wmi_vdev_start(ar, &arg);
850 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200851 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200852 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300853 return ret;
854 }
855
856 ret = ath10k_vdev_setup_sync(ar);
857 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +0200858 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200859 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300860 return ret;
861 }
862
863 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
864 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200865 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200866 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300867 goto vdev_stop;
868 }
869
870 ar->monitor_vdev_id = vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300871
Michal Kazior7aa7a722014-08-25 12:09:38 +0200872 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300873 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300874 return 0;
875
876vdev_stop:
877 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
878 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200879 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200880 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300881
882 return ret;
883}
884
Michal Kazior1bbc0972014-04-08 09:45:47 +0300885static int ath10k_monitor_vdev_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300886{
887 int ret = 0;
888
889 lockdep_assert_held(&ar->conf_mutex);
890
Marek Puzyniak52fa0192013-09-24 14:06:24 +0200891 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
892 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200893 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200894 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300895
Michal Kazior7962b0d2014-10-28 10:34:38 +0100896 reinit_completion(&ar->vdev_setup_done);
897
Kalle Valo5e3dd152013-06-12 20:52:10 +0300898 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
899 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200900 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200901 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300902
903 ret = ath10k_vdev_setup_sync(ar);
904 if (ret)
Ben Greear60028a82015-02-15 16:50:39 +0200905 ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200906 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300907
Michal Kazior7aa7a722014-08-25 12:09:38 +0200908 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300909 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300910 return ret;
911}
912
Michal Kazior1bbc0972014-04-08 09:45:47 +0300913static int ath10k_monitor_vdev_create(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300914{
915 int bit, ret = 0;
916
917 lockdep_assert_held(&ar->conf_mutex);
918
Ben Greeara9aefb32014-08-12 11:02:19 +0300919 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200920 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +0300921 return -ENOMEM;
922 }
923
Ben Greear16c11172014-09-23 14:17:16 -0700924 bit = __ffs64(ar->free_vdev_map);
Ben Greeara9aefb32014-08-12 11:02:19 +0300925
Ben Greear16c11172014-09-23 14:17:16 -0700926 ar->monitor_vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300927
928 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
929 WMI_VDEV_TYPE_MONITOR,
930 0, ar->mac_addr);
931 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200932 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200933 ar->monitor_vdev_id, ret);
Ben Greeara9aefb32014-08-12 11:02:19 +0300934 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300935 }
936
Ben Greear16c11172014-09-23 14:17:16 -0700937 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
Michal Kazior7aa7a722014-08-25 12:09:38 +0200938 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300939 ar->monitor_vdev_id);
940
Kalle Valo5e3dd152013-06-12 20:52:10 +0300941 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300942}
943
Michal Kazior1bbc0972014-04-08 09:45:47 +0300944static int ath10k_monitor_vdev_delete(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300945{
946 int ret = 0;
947
948 lockdep_assert_held(&ar->conf_mutex);
949
Kalle Valo5e3dd152013-06-12 20:52:10 +0300950 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
951 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200952 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200953 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300954 return ret;
955 }
956
Ben Greear16c11172014-09-23 14:17:16 -0700957 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300958
Michal Kazior7aa7a722014-08-25 12:09:38 +0200959 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300960 ar->monitor_vdev_id);
961 return ret;
962}
963
Michal Kazior1bbc0972014-04-08 09:45:47 +0300964static int ath10k_monitor_start(struct ath10k *ar)
965{
966 int ret;
967
968 lockdep_assert_held(&ar->conf_mutex);
969
Michal Kazior1bbc0972014-04-08 09:45:47 +0300970 ret = ath10k_monitor_vdev_create(ar);
971 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200972 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300973 return ret;
974 }
975
976 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
977 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200978 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300979 ath10k_monitor_vdev_delete(ar);
980 return ret;
981 }
982
983 ar->monitor_started = true;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200984 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
Michal Kazior1bbc0972014-04-08 09:45:47 +0300985
986 return 0;
987}
988
Michal Kazior19337472014-08-28 12:58:16 +0200989static int ath10k_monitor_stop(struct ath10k *ar)
Michal Kazior1bbc0972014-04-08 09:45:47 +0300990{
991 int ret;
992
993 lockdep_assert_held(&ar->conf_mutex);
994
Michal Kazior1bbc0972014-04-08 09:45:47 +0300995 ret = ath10k_monitor_vdev_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200996 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200997 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +0200998 return ret;
999 }
Michal Kazior1bbc0972014-04-08 09:45:47 +03001000
1001 ret = ath10k_monitor_vdev_delete(ar);
Michal Kazior19337472014-08-28 12:58:16 +02001002 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001003 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +02001004 return ret;
1005 }
Michal Kazior1bbc0972014-04-08 09:45:47 +03001006
1007 ar->monitor_started = false;
Michal Kazior7aa7a722014-08-25 12:09:38 +02001008 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
Michal Kazior19337472014-08-28 12:58:16 +02001009
1010 return 0;
1011}
1012
Vasanthakumar Thiagarajan54846212015-03-02 17:45:28 +05301013static bool ath10k_mac_should_disable_promisc(struct ath10k *ar)
1014{
1015 struct ath10k_vif *arvif;
1016
1017 if (!(ar->filter_flags & FIF_PROMISC_IN_BSS))
1018 return true;
1019
1020 if (!ar->num_started_vdevs)
1021 return false;
1022
1023 list_for_each_entry(arvif, &ar->arvifs, list)
1024 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1025 return false;
1026
1027 ath10k_dbg(ar, ATH10K_DBG_MAC,
1028 "mac disabling promiscuous mode because vdev is started\n");
1029 return true;
1030}
1031
Michal Kazior500ff9f2015-03-31 10:26:21 +00001032static bool ath10k_mac_monitor_vdev_is_needed(struct ath10k *ar)
1033{
1034 int num_ctx;
1035
1036 /* At least one chanctx is required to derive a channel to start
1037 * monitor vdev on.
1038 */
1039 num_ctx = ath10k_mac_num_chanctxs(ar);
1040 if (num_ctx == 0)
1041 return false;
1042
1043 /* If there's already an existing special monitor interface then don't
1044 * bother creating another monitor vdev.
1045 */
1046 if (ar->monitor_arvif)
1047 return false;
1048
1049 return ar->monitor ||
1050 !ath10k_mac_should_disable_promisc(ar) ||
1051 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1052}
1053
1054static bool ath10k_mac_monitor_vdev_is_allowed(struct ath10k *ar)
1055{
1056 int num_ctx;
1057
1058 num_ctx = ath10k_mac_num_chanctxs(ar);
1059
1060 /* FIXME: Current interface combinations and cfg80211/mac80211 code
1061 * shouldn't allow this but make sure to prevent handling the following
1062 * case anyway since multi-channel DFS hasn't been tested at all.
1063 */
1064 if (test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags) && num_ctx > 1)
1065 return false;
1066
1067 return true;
1068}
1069
Michal Kazior19337472014-08-28 12:58:16 +02001070static int ath10k_monitor_recalc(struct ath10k *ar)
1071{
Michal Kazior500ff9f2015-03-31 10:26:21 +00001072 bool needed;
1073 bool allowed;
1074 int ret;
Michal Kazior19337472014-08-28 12:58:16 +02001075
1076 lockdep_assert_held(&ar->conf_mutex);
1077
Michal Kazior500ff9f2015-03-31 10:26:21 +00001078 needed = ath10k_mac_monitor_vdev_is_needed(ar);
1079 allowed = ath10k_mac_monitor_vdev_is_allowed(ar);
Michal Kazior19337472014-08-28 12:58:16 +02001080
1081 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior500ff9f2015-03-31 10:26:21 +00001082 "mac monitor recalc started? %d needed? %d allowed? %d\n",
1083 ar->monitor_started, needed, allowed);
Michal Kazior19337472014-08-28 12:58:16 +02001084
Michal Kazior500ff9f2015-03-31 10:26:21 +00001085 if (WARN_ON(needed && !allowed)) {
1086 if (ar->monitor_started) {
1087 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopping disallowed monitor\n");
1088
1089 ret = ath10k_monitor_stop(ar);
1090 if (ret)
1091 ath10k_warn(ar, "failed to stop disallowed monitor: %d\n", ret);
1092 /* not serious */
1093 }
1094
1095 return -EPERM;
1096 }
1097
1098 if (needed == ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02001099 return 0;
1100
Michal Kazior500ff9f2015-03-31 10:26:21 +00001101 if (needed)
Michal Kazior19337472014-08-28 12:58:16 +02001102 return ath10k_monitor_start(ar);
Michal Kazior500ff9f2015-03-31 10:26:21 +00001103 else
1104 return ath10k_monitor_stop(ar);
Michal Kazior1bbc0972014-04-08 09:45:47 +03001105}
1106
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001107static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
1108{
1109 struct ath10k *ar = arvif->ar;
1110 u32 vdev_param, rts_cts = 0;
1111
1112 lockdep_assert_held(&ar->conf_mutex);
1113
1114 vdev_param = ar->wmi.vdev_param->enable_rtscts;
1115
Rajkumar Manoharan9a5ab0f2015-03-19 16:03:29 +02001116 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001117
1118 if (arvif->num_legacy_stations > 0)
1119 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
1120 WMI_RTSCTS_PROFILE);
Rajkumar Manoharan9a5ab0f2015-03-19 16:03:29 +02001121 else
1122 rts_cts |= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES,
1123 WMI_RTSCTS_PROFILE);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001124
1125 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
1126 rts_cts);
1127}
1128
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001129static int ath10k_start_cac(struct ath10k *ar)
1130{
1131 int ret;
1132
1133 lockdep_assert_held(&ar->conf_mutex);
1134
1135 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1136
Michal Kazior19337472014-08-28 12:58:16 +02001137 ret = ath10k_monitor_recalc(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001138 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001139 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001140 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1141 return ret;
1142 }
1143
Michal Kazior7aa7a722014-08-25 12:09:38 +02001144 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001145 ar->monitor_vdev_id);
1146
1147 return 0;
1148}
1149
1150static int ath10k_stop_cac(struct ath10k *ar)
1151{
1152 lockdep_assert_held(&ar->conf_mutex);
1153
1154 /* CAC is not running - do nothing */
1155 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
1156 return 0;
1157
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001158 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
Michal Kazior1bbc0972014-04-08 09:45:47 +03001159 ath10k_monitor_stop(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001160
Michal Kazior7aa7a722014-08-25 12:09:38 +02001161 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001162
1163 return 0;
1164}
1165
Michal Kazior500ff9f2015-03-31 10:26:21 +00001166static void ath10k_mac_has_radar_iter(struct ieee80211_hw *hw,
1167 struct ieee80211_chanctx_conf *conf,
1168 void *data)
1169{
1170 bool *ret = data;
1171
1172 if (!*ret && conf->radar_enabled)
1173 *ret = true;
1174}
1175
1176static bool ath10k_mac_has_radar_enabled(struct ath10k *ar)
1177{
1178 bool has_radar = false;
1179
1180 ieee80211_iter_chan_contexts_atomic(ar->hw,
1181 ath10k_mac_has_radar_iter,
1182 &has_radar);
1183
1184 return has_radar;
1185}
1186
Michal Kaziord6500972014-04-08 09:56:09 +03001187static void ath10k_recalc_radar_detection(struct ath10k *ar)
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001188{
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001189 int ret;
1190
1191 lockdep_assert_held(&ar->conf_mutex);
1192
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001193 ath10k_stop_cac(ar);
1194
Michal Kazior500ff9f2015-03-31 10:26:21 +00001195 if (!ath10k_mac_has_radar_enabled(ar))
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001196 return;
1197
Michal Kaziord6500972014-04-08 09:56:09 +03001198 if (ar->num_started_vdevs > 0)
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001199 return;
1200
1201 ret = ath10k_start_cac(ar);
1202 if (ret) {
1203 /*
1204 * Not possible to start CAC on current channel so starting
1205 * radiation is not allowed, make this channel DFS_UNAVAILABLE
1206 * by indicating that radar was detected.
1207 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02001208 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001209 ieee80211_radar_detected(ar->hw);
1210 }
1211}
1212
Vasanthakumar Thiagarajan822b7e02015-03-02 17:45:27 +05301213static int ath10k_vdev_stop(struct ath10k_vif *arvif)
1214{
1215 struct ath10k *ar = arvif->ar;
1216 int ret;
1217
1218 lockdep_assert_held(&ar->conf_mutex);
1219
1220 reinit_completion(&ar->vdev_setup_done);
1221
1222 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
1223 if (ret) {
1224 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
1225 arvif->vdev_id, ret);
1226 return ret;
1227 }
1228
1229 ret = ath10k_vdev_setup_sync(ar);
1230 if (ret) {
1231 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
1232 arvif->vdev_id, ret);
1233 return ret;
1234 }
1235
1236 WARN_ON(ar->num_started_vdevs == 0);
1237
1238 if (ar->num_started_vdevs != 0) {
1239 ar->num_started_vdevs--;
1240 ath10k_recalc_radar_detection(ar);
1241 }
1242
1243 return ret;
1244}
1245
Michal Kazior500ff9f2015-03-31 10:26:21 +00001246static int ath10k_vdev_start_restart(struct ath10k_vif *arvif,
1247 const struct cfg80211_chan_def *chandef,
1248 bool restart)
Michal Kazior72654fa2014-04-08 09:56:09 +03001249{
1250 struct ath10k *ar = arvif->ar;
Michal Kazior72654fa2014-04-08 09:56:09 +03001251 struct wmi_vdev_start_request_arg arg = {};
Vasanthakumar Thiagarajan54846212015-03-02 17:45:28 +05301252 int ret = 0, ret2;
Michal Kazior72654fa2014-04-08 09:56:09 +03001253
1254 lockdep_assert_held(&ar->conf_mutex);
1255
1256 reinit_completion(&ar->vdev_setup_done);
1257
1258 arg.vdev_id = arvif->vdev_id;
1259 arg.dtim_period = arvif->dtim_period;
1260 arg.bcn_intval = arvif->beacon_interval;
1261
1262 arg.channel.freq = chandef->chan->center_freq;
1263 arg.channel.band_center_freq1 = chandef->center_freq1;
1264 arg.channel.mode = chan_to_phymode(chandef);
1265
1266 arg.channel.min_power = 0;
1267 arg.channel.max_power = chandef->chan->max_power * 2;
1268 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
1269 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
1270
1271 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1272 arg.ssid = arvif->u.ap.ssid;
1273 arg.ssid_len = arvif->u.ap.ssid_len;
1274 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
1275
1276 /* For now allow DFS for AP mode */
1277 arg.channel.chan_radar =
1278 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
1279 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
1280 arg.ssid = arvif->vif->bss_conf.ssid;
1281 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
1282 }
1283
Michal Kazior7aa7a722014-08-25 12:09:38 +02001284 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior72654fa2014-04-08 09:56:09 +03001285 "mac vdev %d start center_freq %d phymode %s\n",
1286 arg.vdev_id, arg.channel.freq,
1287 ath10k_wmi_phymode_str(arg.channel.mode));
1288
Michal Kaziordc55e302014-07-29 12:53:36 +03001289 if (restart)
1290 ret = ath10k_wmi_vdev_restart(ar, &arg);
1291 else
1292 ret = ath10k_wmi_vdev_start(ar, &arg);
1293
Michal Kazior72654fa2014-04-08 09:56:09 +03001294 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001295 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +03001296 arg.vdev_id, ret);
1297 return ret;
1298 }
1299
1300 ret = ath10k_vdev_setup_sync(ar);
1301 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +02001302 ath10k_warn(ar,
1303 "failed to synchronize setup for vdev %i restart %d: %d\n",
1304 arg.vdev_id, restart, ret);
Michal Kazior72654fa2014-04-08 09:56:09 +03001305 return ret;
1306 }
1307
Michal Kaziord6500972014-04-08 09:56:09 +03001308 ar->num_started_vdevs++;
1309 ath10k_recalc_radar_detection(ar);
1310
Vasanthakumar Thiagarajan54846212015-03-02 17:45:28 +05301311 ret = ath10k_monitor_recalc(ar);
1312 if (ret) {
1313 ath10k_warn(ar, "mac failed to recalc monitor for vdev %i restart %d: %d\n",
1314 arg.vdev_id, restart, ret);
1315 ret2 = ath10k_vdev_stop(arvif);
1316 if (ret2)
1317 ath10k_warn(ar, "mac failed to stop vdev %i restart %d: %d\n",
1318 arg.vdev_id, restart, ret2);
1319 }
1320
Michal Kazior72654fa2014-04-08 09:56:09 +03001321 return ret;
1322}
1323
Michal Kazior500ff9f2015-03-31 10:26:21 +00001324static int ath10k_vdev_start(struct ath10k_vif *arvif,
1325 const struct cfg80211_chan_def *def)
Michal Kaziordc55e302014-07-29 12:53:36 +03001326{
Michal Kazior500ff9f2015-03-31 10:26:21 +00001327 return ath10k_vdev_start_restart(arvif, def, false);
Michal Kaziordc55e302014-07-29 12:53:36 +03001328}
1329
Michal Kazior500ff9f2015-03-31 10:26:21 +00001330static int ath10k_vdev_restart(struct ath10k_vif *arvif,
1331 const struct cfg80211_chan_def *def)
Michal Kaziordc55e302014-07-29 12:53:36 +03001332{
Michal Kazior500ff9f2015-03-31 10:26:21 +00001333 return ath10k_vdev_start_restart(arvif, def, true);
Michal Kaziordc55e302014-07-29 12:53:36 +03001334}
1335
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001336static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
1337 struct sk_buff *bcn)
1338{
1339 struct ath10k *ar = arvif->ar;
1340 struct ieee80211_mgmt *mgmt;
1341 const u8 *p2p_ie;
1342 int ret;
1343
1344 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1345 return 0;
1346
1347 if (arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1348 return 0;
1349
1350 mgmt = (void *)bcn->data;
1351 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1352 mgmt->u.beacon.variable,
1353 bcn->len - (mgmt->u.beacon.variable -
1354 bcn->data));
1355 if (!p2p_ie)
1356 return -ENOENT;
1357
1358 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1359 if (ret) {
1360 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1361 arvif->vdev_id, ret);
1362 return ret;
1363 }
1364
1365 return 0;
1366}
1367
1368static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1369 u8 oui_type, size_t ie_offset)
1370{
1371 size_t len;
1372 const u8 *next;
1373 const u8 *end;
1374 u8 *ie;
1375
1376 if (WARN_ON(skb->len < ie_offset))
1377 return -EINVAL;
1378
1379 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1380 skb->data + ie_offset,
1381 skb->len - ie_offset);
1382 if (!ie)
1383 return -ENOENT;
1384
1385 len = ie[1] + 2;
1386 end = skb->data + skb->len;
1387 next = ie + len;
1388
1389 if (WARN_ON(next > end))
1390 return -EINVAL;
1391
1392 memmove(ie, next, end - next);
1393 skb_trim(skb, skb->len - len);
1394
1395 return 0;
1396}
1397
1398static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1399{
1400 struct ath10k *ar = arvif->ar;
1401 struct ieee80211_hw *hw = ar->hw;
1402 struct ieee80211_vif *vif = arvif->vif;
1403 struct ieee80211_mutable_offsets offs = {};
1404 struct sk_buff *bcn;
1405 int ret;
1406
1407 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1408 return 0;
1409
Michal Kazior81a9a172015-03-05 16:02:17 +02001410 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
1411 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
1412 return 0;
1413
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001414 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1415 if (!bcn) {
1416 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1417 return -EPERM;
1418 }
1419
1420 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1421 if (ret) {
1422 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1423 kfree_skb(bcn);
1424 return ret;
1425 }
1426
1427 /* P2P IE is inserted by firmware automatically (as configured above)
1428 * so remove it from the base beacon template to avoid duplicate P2P
1429 * IEs in beacon frames.
1430 */
1431 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1432 offsetof(struct ieee80211_mgmt,
1433 u.beacon.variable));
1434
1435 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1436 0, NULL, 0);
1437 kfree_skb(bcn);
1438
1439 if (ret) {
1440 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1441 ret);
1442 return ret;
1443 }
1444
1445 return 0;
1446}
1447
1448static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1449{
1450 struct ath10k *ar = arvif->ar;
1451 struct ieee80211_hw *hw = ar->hw;
1452 struct ieee80211_vif *vif = arvif->vif;
1453 struct sk_buff *prb;
1454 int ret;
1455
1456 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1457 return 0;
1458
Michal Kazior81a9a172015-03-05 16:02:17 +02001459 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1460 return 0;
1461
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001462 prb = ieee80211_proberesp_get(hw, vif);
1463 if (!prb) {
1464 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1465 return -EPERM;
1466 }
1467
1468 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1469 kfree_skb(prb);
1470
1471 if (ret) {
1472 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1473 ret);
1474 return ret;
1475 }
1476
1477 return 0;
1478}
1479
Michal Kazior500ff9f2015-03-31 10:26:21 +00001480static int ath10k_mac_vif_fix_hidden_ssid(struct ath10k_vif *arvif)
1481{
1482 struct ath10k *ar = arvif->ar;
1483 struct cfg80211_chan_def def;
1484 int ret;
1485
1486 /* When originally vdev is started during assign_vif_chanctx() some
1487 * information is missing, notably SSID. Firmware revisions with beacon
1488 * offloading require the SSID to be provided during vdev (re)start to
1489 * handle hidden SSID properly.
1490 *
1491 * Vdev restart must be done after vdev has been both started and
1492 * upped. Otherwise some firmware revisions (at least 10.2) fail to
1493 * deliver vdev restart response event causing timeouts during vdev
1494 * syncing in ath10k.
1495 *
1496 * Note: The vdev down/up and template reinstallation could be skipped
1497 * since only wmi-tlv firmware are known to have beacon offload and
1498 * wmi-tlv doesn't seem to misbehave like 10.2 wrt vdev restart
1499 * response delivery. It's probably more robust to keep it as is.
1500 */
1501 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1502 return 0;
1503
1504 if (WARN_ON(!arvif->is_started))
1505 return -EINVAL;
1506
1507 if (WARN_ON(!arvif->is_up))
1508 return -EINVAL;
1509
1510 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
1511 return -EINVAL;
1512
1513 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1514 if (ret) {
1515 ath10k_warn(ar, "failed to bring down ap vdev %i: %d\n",
1516 arvif->vdev_id, ret);
1517 return ret;
1518 }
1519
1520 /* Vdev down reset beacon & presp templates. Reinstall them. Otherwise
1521 * firmware will crash upon vdev up.
1522 */
1523
1524 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1525 if (ret) {
1526 ath10k_warn(ar, "failed to update beacon template: %d\n", ret);
1527 return ret;
1528 }
1529
1530 ret = ath10k_mac_setup_prb_tmpl(arvif);
1531 if (ret) {
1532 ath10k_warn(ar, "failed to update presp template: %d\n", ret);
1533 return ret;
1534 }
1535
1536 ret = ath10k_vdev_restart(arvif, &def);
1537 if (ret) {
1538 ath10k_warn(ar, "failed to restart ap vdev %i: %d\n",
1539 arvif->vdev_id, ret);
1540 return ret;
1541 }
1542
1543 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1544 arvif->bssid);
1545 if (ret) {
1546 ath10k_warn(ar, "failed to bring up ap vdev %i: %d\n",
1547 arvif->vdev_id, ret);
1548 return ret;
1549 }
1550
1551 return 0;
1552}
1553
Kalle Valo5e3dd152013-06-12 20:52:10 +03001554static void ath10k_control_beaconing(struct ath10k_vif *arvif,
Kalle Valo5b07e072014-09-14 12:50:06 +03001555 struct ieee80211_bss_conf *info)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001556{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001557 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001558 int ret = 0;
1559
Michal Kazior548db542013-07-05 16:15:15 +03001560 lockdep_assert_held(&arvif->ar->conf_mutex);
1561
Kalle Valo5e3dd152013-06-12 20:52:10 +03001562 if (!info->enable_beacon) {
Michal Kazior500ff9f2015-03-31 10:26:21 +00001563 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1564 if (ret)
1565 ath10k_warn(ar, "failed to down vdev_id %i: %d\n",
1566 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001567
Michal Kaziorc930f742014-01-23 11:38:25 +01001568 arvif->is_up = false;
Michal Kazior8513d952015-03-09 14:19:24 +01001569
1570 spin_lock_bh(&arvif->ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03001571 ath10k_mac_vif_beacon_free(arvif);
Michal Kazior748afc42014-01-23 12:48:21 +01001572 spin_unlock_bh(&arvif->ar->data_lock);
1573
Kalle Valo5e3dd152013-06-12 20:52:10 +03001574 return;
1575 }
1576
1577 arvif->tx_seq_no = 0x1000;
1578
Michal Kaziorc930f742014-01-23 11:38:25 +01001579 arvif->aid = 0;
Kalle Valob25f32c2014-09-14 12:50:49 +03001580 ether_addr_copy(arvif->bssid, info->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01001581
1582 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1583 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001584 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001585 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001586 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001587 return;
1588 }
Michal Kaziorc930f742014-01-23 11:38:25 +01001589
Michal Kaziorc930f742014-01-23 11:38:25 +01001590 arvif->is_up = true;
1591
Michal Kazior500ff9f2015-03-31 10:26:21 +00001592 ret = ath10k_mac_vif_fix_hidden_ssid(arvif);
1593 if (ret) {
1594 ath10k_warn(ar, "failed to fix hidden ssid for vdev %i, expect trouble: %d\n",
1595 arvif->vdev_id, ret);
1596 return;
1597 }
1598
Michal Kazior7aa7a722014-08-25 12:09:38 +02001599 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001600}
1601
1602static void ath10k_control_ibss(struct ath10k_vif *arvif,
1603 struct ieee80211_bss_conf *info,
1604 const u8 self_peer[ETH_ALEN])
1605{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001606 struct ath10k *ar = arvif->ar;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001607 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001608 int ret = 0;
1609
Michal Kazior548db542013-07-05 16:15:15 +03001610 lockdep_assert_held(&arvif->ar->conf_mutex);
1611
Kalle Valo5e3dd152013-06-12 20:52:10 +03001612 if (!info->ibss_joined) {
1613 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
1614 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001615 ath10k_warn(ar, "failed to delete IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001616 self_peer, arvif->vdev_id, ret);
1617
Michal Kaziorc930f742014-01-23 11:38:25 +01001618 if (is_zero_ether_addr(arvif->bssid))
Kalle Valo5e3dd152013-06-12 20:52:10 +03001619 return;
1620
Michal Kaziorc930f742014-01-23 11:38:25 +01001621 memset(arvif->bssid, 0, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001622
1623 return;
1624 }
1625
Marek Puzyniak7390ed32015-03-30 09:51:52 +03001626 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer,
1627 WMI_PEER_TYPE_DEFAULT);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001628 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001629 ath10k_warn(ar, "failed to create IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001630 self_peer, arvif->vdev_id, ret);
1631 return;
1632 }
1633
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001634 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1635 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001636 ATH10K_DEFAULT_ATIM);
1637 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001638 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001639 arvif->vdev_id, ret);
1640}
1641
Michal Kazior9f9b5742014-12-12 12:41:36 +01001642static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1643{
1644 struct ath10k *ar = arvif->ar;
1645 u32 param;
1646 u32 value;
1647 int ret;
1648
1649 lockdep_assert_held(&arvif->ar->conf_mutex);
1650
1651 if (arvif->u.sta.uapsd)
1652 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1653 else
1654 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1655
1656 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1657 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1658 if (ret) {
1659 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1660 value, arvif->vdev_id, ret);
1661 return ret;
1662 }
1663
1664 return 0;
1665}
1666
1667static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1668{
1669 struct ath10k *ar = arvif->ar;
1670 u32 param;
1671 u32 value;
1672 int ret;
1673
1674 lockdep_assert_held(&arvif->ar->conf_mutex);
1675
1676 if (arvif->u.sta.uapsd)
1677 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1678 else
1679 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1680
1681 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1682 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1683 param, value);
1684 if (ret) {
1685 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1686 value, arvif->vdev_id, ret);
1687 return ret;
1688 }
1689
1690 return 0;
1691}
1692
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001693static int ath10k_mac_ps_vif_count(struct ath10k *ar)
1694{
1695 struct ath10k_vif *arvif;
1696 int num = 0;
1697
1698 lockdep_assert_held(&ar->conf_mutex);
1699
1700 list_for_each_entry(arvif, &ar->arvifs, list)
1701 if (arvif->ps)
1702 num++;
1703
1704 return num;
1705}
1706
Michal Kaziorad088bf2013-10-16 15:44:46 +03001707static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001708{
Michal Kaziorad088bf2013-10-16 15:44:46 +03001709 struct ath10k *ar = arvif->ar;
Michal Kazior526549a2014-12-12 12:41:37 +01001710 struct ieee80211_vif *vif = arvif->vif;
Michal Kaziorad088bf2013-10-16 15:44:46 +03001711 struct ieee80211_conf *conf = &ar->hw->conf;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001712 enum wmi_sta_powersave_param param;
1713 enum wmi_sta_ps_mode psmode;
1714 int ret;
Michal Kazior526549a2014-12-12 12:41:37 +01001715 int ps_timeout;
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001716 bool enable_ps;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001717
Michal Kazior548db542013-07-05 16:15:15 +03001718 lockdep_assert_held(&arvif->ar->conf_mutex);
1719
Michal Kaziorad088bf2013-10-16 15:44:46 +03001720 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1721 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001722
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001723 enable_ps = arvif->ps;
1724
1725 if (enable_ps && ath10k_mac_ps_vif_count(ar) > 1 &&
1726 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
1727 ar->fw_features)) {
1728 ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
1729 arvif->vdev_id);
1730 enable_ps = false;
1731 }
1732
1733 if (enable_ps) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001734 psmode = WMI_STA_PS_MODE_ENABLED;
1735 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1736
Michal Kazior526549a2014-12-12 12:41:37 +01001737 ps_timeout = conf->dynamic_ps_timeout;
1738 if (ps_timeout == 0) {
1739 /* Firmware doesn't like 0 */
1740 ps_timeout = ieee80211_tu_to_usec(
1741 vif->bss_conf.beacon_int) / 1000;
1742 }
1743
Michal Kaziorad088bf2013-10-16 15:44:46 +03001744 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
Michal Kazior526549a2014-12-12 12:41:37 +01001745 ps_timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001746 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001747 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001748 arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001749 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001750 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001751 } else {
1752 psmode = WMI_STA_PS_MODE_DISABLED;
1753 }
1754
Michal Kazior7aa7a722014-08-25 12:09:38 +02001755 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001756 arvif->vdev_id, psmode ? "enable" : "disable");
1757
Michal Kaziorad088bf2013-10-16 15:44:46 +03001758 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1759 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001760 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001761 psmode, arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001762 return ret;
1763 }
1764
1765 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001766}
1767
Michal Kazior46725b152015-01-28 09:57:49 +02001768static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1769{
1770 struct ath10k *ar = arvif->ar;
1771 struct wmi_sta_keepalive_arg arg = {};
1772 int ret;
1773
1774 lockdep_assert_held(&arvif->ar->conf_mutex);
1775
1776 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1777 return 0;
1778
1779 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1780 return 0;
1781
1782 /* Some firmware revisions have a bug and ignore the `enabled` field.
1783 * Instead use the interval to disable the keepalive.
1784 */
1785 arg.vdev_id = arvif->vdev_id;
1786 arg.enabled = 1;
1787 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1788 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1789
1790 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1791 if (ret) {
1792 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1793 arvif->vdev_id, ret);
1794 return ret;
1795 }
1796
1797 return 0;
1798}
1799
Michal Kazior81a9a172015-03-05 16:02:17 +02001800static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif)
1801{
1802 struct ath10k *ar = arvif->ar;
1803 struct ieee80211_vif *vif = arvif->vif;
1804 int ret;
1805
Michal Kazior8513d952015-03-09 14:19:24 +01001806 lockdep_assert_held(&arvif->ar->conf_mutex);
1807
1808 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)))
1809 return;
1810
Michal Kazior81a9a172015-03-05 16:02:17 +02001811 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1812 return;
1813
1814 if (!vif->csa_active)
1815 return;
1816
1817 if (!arvif->is_up)
1818 return;
1819
1820 if (!ieee80211_csa_is_complete(vif)) {
1821 ieee80211_csa_update_counter(vif);
1822
1823 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1824 if (ret)
1825 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
1826 ret);
1827
1828 ret = ath10k_mac_setup_prb_tmpl(arvif);
1829 if (ret)
1830 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
1831 ret);
1832 } else {
1833 ieee80211_csa_finish(vif);
1834 }
1835}
1836
1837static void ath10k_mac_vif_ap_csa_work(struct work_struct *work)
1838{
1839 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1840 ap_csa_work);
1841 struct ath10k *ar = arvif->ar;
1842
1843 mutex_lock(&ar->conf_mutex);
1844 ath10k_mac_vif_ap_csa_count_down(arvif);
1845 mutex_unlock(&ar->conf_mutex);
1846}
1847
Michal Kaziorcc9904e2015-03-10 16:22:01 +02001848static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac,
1849 struct ieee80211_vif *vif)
1850{
1851 struct sk_buff *skb = data;
1852 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1853 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1854
1855 if (vif->type != NL80211_IFTYPE_STATION)
1856 return;
1857
1858 if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
1859 return;
1860
1861 cancel_delayed_work(&arvif->connection_loss_work);
1862}
1863
1864void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb)
1865{
1866 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1867 IEEE80211_IFACE_ITER_NORMAL,
1868 ath10k_mac_handle_beacon_iter,
1869 skb);
1870}
1871
1872static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac,
1873 struct ieee80211_vif *vif)
1874{
1875 u32 *vdev_id = data;
1876 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1877 struct ath10k *ar = arvif->ar;
1878 struct ieee80211_hw *hw = ar->hw;
1879
1880 if (arvif->vdev_id != *vdev_id)
1881 return;
1882
1883 if (!arvif->is_up)
1884 return;
1885
1886 ieee80211_beacon_loss(vif);
1887
1888 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
1889 * (done by mac80211) succeeds but beacons do not resume then it
1890 * doesn't make sense to continue operation. Queue connection loss work
1891 * which can be cancelled when beacon is received.
1892 */
1893 ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
1894 ATH10K_CONNECTION_LOSS_HZ);
1895}
1896
1897void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id)
1898{
1899 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1900 IEEE80211_IFACE_ITER_NORMAL,
1901 ath10k_mac_handle_beacon_miss_iter,
1902 &vdev_id);
1903}
1904
1905static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work)
1906{
1907 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1908 connection_loss_work.work);
1909 struct ieee80211_vif *vif = arvif->vif;
1910
1911 if (!arvif->is_up)
1912 return;
1913
1914 ieee80211_connection_loss(vif);
1915}
1916
Kalle Valo5e3dd152013-06-12 20:52:10 +03001917/**********************/
1918/* Station management */
1919/**********************/
1920
Michal Kazior590922a2014-10-21 10:10:29 +03001921static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1922 struct ieee80211_vif *vif)
1923{
1924 /* Some firmware revisions have unstable STA powersave when listen
1925 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1926 * generate NullFunc frames properly even if buffered frames have been
1927 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1928 * buffered frames. Often pinging the device from AP would simply fail.
1929 *
1930 * As a workaround set it to 1.
1931 */
1932 if (vif->type == NL80211_IFTYPE_STATION)
1933 return 1;
1934
1935 return ar->hw->conf.listen_interval;
1936}
1937
Kalle Valo5e3dd152013-06-12 20:52:10 +03001938static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001939 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001940 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001941 struct wmi_peer_assoc_complete_arg *arg)
1942{
Michal Kazior590922a2014-10-21 10:10:29 +03001943 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorc51880e2015-03-30 09:51:57 +03001944 u32 aid;
Michal Kazior590922a2014-10-21 10:10:29 +03001945
Michal Kazior548db542013-07-05 16:15:15 +03001946 lockdep_assert_held(&ar->conf_mutex);
1947
Michal Kaziorc51880e2015-03-30 09:51:57 +03001948 if (vif->type == NL80211_IFTYPE_STATION)
1949 aid = vif->bss_conf.aid;
1950 else
1951 aid = sta->aid;
1952
Kalle Valob25f32c2014-09-14 12:50:49 +03001953 ether_addr_copy(arg->addr, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001954 arg->vdev_id = arvif->vdev_id;
Michal Kaziorc51880e2015-03-30 09:51:57 +03001955 arg->peer_aid = aid;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001956 arg->peer_flags |= WMI_PEER_AUTH;
Michal Kazior590922a2014-10-21 10:10:29 +03001957 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001958 arg->peer_num_spatial_streams = 1;
Michal Kazior590922a2014-10-21 10:10:29 +03001959 arg->peer_caps = vif->bss_conf.assoc_capability;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001960}
1961
1962static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001963 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001964 struct wmi_peer_assoc_complete_arg *arg)
1965{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001966 struct ieee80211_bss_conf *info = &vif->bss_conf;
Michal Kazior500ff9f2015-03-31 10:26:21 +00001967 struct cfg80211_chan_def def;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001968 struct cfg80211_bss *bss;
1969 const u8 *rsnie = NULL;
1970 const u8 *wpaie = NULL;
1971
Michal Kazior548db542013-07-05 16:15:15 +03001972 lockdep_assert_held(&ar->conf_mutex);
1973
Michal Kazior500ff9f2015-03-31 10:26:21 +00001974 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
1975 return;
1976
1977 bss = cfg80211_get_bss(ar->hw->wiphy, def.chan, info->bssid, NULL, 0,
1978 IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001979 if (bss) {
1980 const struct cfg80211_bss_ies *ies;
1981
1982 rcu_read_lock();
1983 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1984
1985 ies = rcu_dereference(bss->ies);
1986
1987 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
Kalle Valo5b07e072014-09-14 12:50:06 +03001988 WLAN_OUI_TYPE_MICROSOFT_WPA,
1989 ies->data,
1990 ies->len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001991 rcu_read_unlock();
1992 cfg80211_put_bss(ar->hw->wiphy, bss);
1993 }
1994
1995 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1996 if (rsnie || wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001997 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001998 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1999 }
2000
2001 if (wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002002 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002003 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
2004 }
2005}
2006
2007static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
Michal Kazior500ff9f2015-03-31 10:26:21 +00002008 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002009 struct ieee80211_sta *sta,
2010 struct wmi_peer_assoc_complete_arg *arg)
2011{
2012 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
Michal Kazior500ff9f2015-03-31 10:26:21 +00002013 struct cfg80211_chan_def def;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002014 const struct ieee80211_supported_band *sband;
2015 const struct ieee80211_rate *rates;
2016 u32 ratemask;
Michal Kazior486017c2015-03-30 09:51:54 +03002017 u8 rate;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002018 int i;
2019
Michal Kazior548db542013-07-05 16:15:15 +03002020 lockdep_assert_held(&ar->conf_mutex);
2021
Michal Kazior500ff9f2015-03-31 10:26:21 +00002022 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2023 return;
2024
2025 sband = ar->hw->wiphy->bands[def.chan->band];
2026 ratemask = sta->supp_rates[def.chan->band];
Kalle Valo5e3dd152013-06-12 20:52:10 +03002027 rates = sband->bitrates;
2028
2029 rateset->num_rates = 0;
2030
2031 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
2032 if (!(ratemask & 1))
2033 continue;
2034
Michal Kazior486017c2015-03-30 09:51:54 +03002035 rate = ath10k_mac_bitrate_to_rate(rates->bitrate);
2036 rateset->rates[rateset->num_rates] = rate;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002037 rateset->num_rates++;
2038 }
2039}
2040
2041static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
2042 struct ieee80211_sta *sta,
2043 struct wmi_peer_assoc_complete_arg *arg)
2044{
2045 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002046 int i, n;
Kalle Valoaf762c02014-09-14 12:50:17 +03002047 u32 stbc;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002048
Michal Kazior548db542013-07-05 16:15:15 +03002049 lockdep_assert_held(&ar->conf_mutex);
2050
Kalle Valo5e3dd152013-06-12 20:52:10 +03002051 if (!ht_cap->ht_supported)
2052 return;
2053
2054 arg->peer_flags |= WMI_PEER_HT;
2055 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2056 ht_cap->ampdu_factor)) - 1;
2057
2058 arg->peer_mpdu_density =
2059 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
2060
2061 arg->peer_ht_caps = ht_cap->cap;
2062 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
2063
2064 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
2065 arg->peer_flags |= WMI_PEER_LDPC;
2066
2067 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
2068 arg->peer_flags |= WMI_PEER_40MHZ;
2069 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
2070 }
2071
2072 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
2073 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2074
2075 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
2076 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2077
2078 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
2079 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
2080 arg->peer_flags |= WMI_PEER_STBC;
2081 }
2082
2083 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002084 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
2085 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
2086 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
2087 arg->peer_rate_caps |= stbc;
2088 arg->peer_flags |= WMI_PEER_STBC;
2089 }
2090
Kalle Valo5e3dd152013-06-12 20:52:10 +03002091 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
2092 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
2093 else if (ht_cap->mcs.rx_mask[1])
2094 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
2095
2096 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
2097 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
2098 arg->peer_ht_rates.rates[n++] = i;
2099
Bartosz Markowskifd71f802014-02-10 13:12:55 +01002100 /*
2101 * This is a workaround for HT-enabled STAs which break the spec
2102 * and have no HT capabilities RX mask (no HT RX MCS map).
2103 *
2104 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
2105 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
2106 *
2107 * Firmware asserts if such situation occurs.
2108 */
2109 if (n == 0) {
2110 arg->peer_ht_rates.num_rates = 8;
2111 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
2112 arg->peer_ht_rates.rates[i] = i;
2113 } else {
2114 arg->peer_ht_rates.num_rates = n;
2115 arg->peer_num_spatial_streams = sta->rx_nss;
2116 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002117
Michal Kazior7aa7a722014-08-25 12:09:38 +02002118 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03002119 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002120 arg->peer_ht_rates.num_rates,
2121 arg->peer_num_spatial_streams);
2122}
2123
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002124static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
2125 struct ath10k_vif *arvif,
2126 struct ieee80211_sta *sta)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002127{
2128 u32 uapsd = 0;
2129 u32 max_sp = 0;
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002130 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002131
Michal Kazior548db542013-07-05 16:15:15 +03002132 lockdep_assert_held(&ar->conf_mutex);
2133
Kalle Valo5e3dd152013-06-12 20:52:10 +03002134 if (sta->wme && sta->uapsd_queues) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002135 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002136 sta->uapsd_queues, sta->max_sp);
2137
Kalle Valo5e3dd152013-06-12 20:52:10 +03002138 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2139 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
2140 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
2141 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2142 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
2143 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
2144 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2145 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
2146 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
2147 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2148 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
2149 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
2150
Kalle Valo5e3dd152013-06-12 20:52:10 +03002151 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
2152 max_sp = sta->max_sp;
2153
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002154 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2155 sta->addr,
2156 WMI_AP_PS_PEER_PARAM_UAPSD,
2157 uapsd);
2158 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002159 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002160 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002161 return ret;
2162 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002163
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002164 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2165 sta->addr,
2166 WMI_AP_PS_PEER_PARAM_MAX_SP,
2167 max_sp);
2168 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002169 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002170 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002171 return ret;
2172 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002173
2174 /* TODO setup this based on STA listen interval and
2175 beacon interval. Currently we don't know
2176 sta->listen_interval - mac80211 patch required.
2177 Currently use 10 seconds */
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002178 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
Kalle Valo5b07e072014-09-14 12:50:06 +03002179 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
2180 10);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002181 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002182 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002183 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002184 return ret;
2185 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002186 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002187
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002188 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002189}
2190
2191static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
Michal Kazior500ff9f2015-03-31 10:26:21 +00002192 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002193 struct ieee80211_sta *sta,
2194 struct wmi_peer_assoc_complete_arg *arg)
2195{
2196 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
Michal Kazior500ff9f2015-03-31 10:26:21 +00002197 struct cfg80211_chan_def def;
Sujith Manoharana24b88b2013-10-07 19:51:57 -07002198 u8 ampdu_factor;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002199
Michal Kazior500ff9f2015-03-31 10:26:21 +00002200 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2201 return;
2202
Kalle Valo5e3dd152013-06-12 20:52:10 +03002203 if (!vht_cap->vht_supported)
2204 return;
2205
2206 arg->peer_flags |= WMI_PEER_VHT;
Yanbo Lid68bb122015-01-23 08:18:20 +08002207
Michal Kazior500ff9f2015-03-31 10:26:21 +00002208 if (def.chan->band == IEEE80211_BAND_2GHZ)
Yanbo Lid68bb122015-01-23 08:18:20 +08002209 arg->peer_flags |= WMI_PEER_VHT_2G;
2210
Kalle Valo5e3dd152013-06-12 20:52:10 +03002211 arg->peer_vht_caps = vht_cap->cap;
2212
Sujith Manoharana24b88b2013-10-07 19:51:57 -07002213 ampdu_factor = (vht_cap->cap &
2214 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
2215 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
2216
2217 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
2218 * zero in VHT IE. Using it would result in degraded throughput.
2219 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
2220 * it if VHT max_mpdu is smaller. */
2221 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
2222 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2223 ampdu_factor)) - 1);
2224
Kalle Valo5e3dd152013-06-12 20:52:10 +03002225 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2226 arg->peer_flags |= WMI_PEER_80MHZ;
2227
2228 arg->peer_vht_rates.rx_max_rate =
2229 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
2230 arg->peer_vht_rates.rx_mcs_set =
2231 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
2232 arg->peer_vht_rates.tx_max_rate =
2233 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
2234 arg->peer_vht_rates.tx_mcs_set =
2235 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
2236
Michal Kazior7aa7a722014-08-25 12:09:38 +02002237 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03002238 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002239}
2240
2241static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03002242 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002243 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002244 struct wmi_peer_assoc_complete_arg *arg)
2245{
Michal Kazior590922a2014-10-21 10:10:29 +03002246 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2247
Kalle Valo5e3dd152013-06-12 20:52:10 +03002248 switch (arvif->vdev_type) {
2249 case WMI_VDEV_TYPE_AP:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002250 if (sta->wme)
2251 arg->peer_flags |= WMI_PEER_QOS;
2252
2253 if (sta->wme && sta->uapsd_queues) {
2254 arg->peer_flags |= WMI_PEER_APSD;
2255 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
2256 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002257 break;
2258 case WMI_VDEV_TYPE_STA:
Michal Kazior590922a2014-10-21 10:10:29 +03002259 if (vif->bss_conf.qos)
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002260 arg->peer_flags |= WMI_PEER_QOS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002261 break;
Janusz Dziedzic627d9842014-12-17 12:29:54 +02002262 case WMI_VDEV_TYPE_IBSS:
2263 if (sta->wme)
2264 arg->peer_flags |= WMI_PEER_QOS;
2265 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002266 default:
2267 break;
2268 }
Janusz Dziedzic627d9842014-12-17 12:29:54 +02002269
2270 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
2271 sta->addr, !!(arg->peer_flags & WMI_PEER_QOS));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002272}
2273
Michal Kazior8d7aa6b2015-03-30 09:51:57 +03002274static bool ath10k_mac_sta_has_ofdm_only(struct ieee80211_sta *sta)
Michal Kazior91b12082014-12-12 12:41:35 +01002275{
Michal Kazior8d7aa6b2015-03-30 09:51:57 +03002276 return sta->supp_rates[IEEE80211_BAND_2GHZ] >>
2277 ATH10K_MAC_FIRST_OFDM_RATE_IDX;
Michal Kazior91b12082014-12-12 12:41:35 +01002278}
2279
Kalle Valo5e3dd152013-06-12 20:52:10 +03002280static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03002281 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002282 struct ieee80211_sta *sta,
2283 struct wmi_peer_assoc_complete_arg *arg)
2284{
Michal Kazior500ff9f2015-03-31 10:26:21 +00002285 struct cfg80211_chan_def def;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002286 enum wmi_phy_mode phymode = MODE_UNKNOWN;
2287
Michal Kazior500ff9f2015-03-31 10:26:21 +00002288 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2289 return;
2290
2291 switch (def.chan->band) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002292 case IEEE80211_BAND_2GHZ:
Yanbo Lid68bb122015-01-23 08:18:20 +08002293 if (sta->vht_cap.vht_supported) {
2294 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2295 phymode = MODE_11AC_VHT40;
2296 else
2297 phymode = MODE_11AC_VHT20;
2298 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002299 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2300 phymode = MODE_11NG_HT40;
2301 else
2302 phymode = MODE_11NG_HT20;
Michal Kazior8d7aa6b2015-03-30 09:51:57 +03002303 } else if (ath10k_mac_sta_has_ofdm_only(sta)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002304 phymode = MODE_11G;
Michal Kazior91b12082014-12-12 12:41:35 +01002305 } else {
2306 phymode = MODE_11B;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002307 }
2308
2309 break;
2310 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03002311 /*
2312 * Check VHT first.
2313 */
2314 if (sta->vht_cap.vht_supported) {
2315 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2316 phymode = MODE_11AC_VHT80;
2317 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2318 phymode = MODE_11AC_VHT40;
2319 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
2320 phymode = MODE_11AC_VHT20;
2321 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002322 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2323 phymode = MODE_11NA_HT40;
2324 else
2325 phymode = MODE_11NA_HT20;
2326 } else {
2327 phymode = MODE_11A;
2328 }
2329
2330 break;
2331 default:
2332 break;
2333 }
2334
Michal Kazior7aa7a722014-08-25 12:09:38 +02002335 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
Kalle Valo38a1d472013-09-08 17:56:14 +03002336 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03002337
Kalle Valo5e3dd152013-06-12 20:52:10 +03002338 arg->peer_phymode = phymode;
2339 WARN_ON(phymode == MODE_UNKNOWN);
2340}
2341
Kalle Valob9ada652013-10-16 15:44:46 +03002342static int ath10k_peer_assoc_prepare(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03002343 struct ieee80211_vif *vif,
Kalle Valob9ada652013-10-16 15:44:46 +03002344 struct ieee80211_sta *sta,
Kalle Valob9ada652013-10-16 15:44:46 +03002345 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002346{
Michal Kazior548db542013-07-05 16:15:15 +03002347 lockdep_assert_held(&ar->conf_mutex);
2348
Kalle Valob9ada652013-10-16 15:44:46 +03002349 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002350
Michal Kazior590922a2014-10-21 10:10:29 +03002351 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
2352 ath10k_peer_assoc_h_crypto(ar, vif, arg);
Michal Kazior500ff9f2015-03-31 10:26:21 +00002353 ath10k_peer_assoc_h_rates(ar, vif, sta, arg);
Kalle Valob9ada652013-10-16 15:44:46 +03002354 ath10k_peer_assoc_h_ht(ar, sta, arg);
Michal Kazior500ff9f2015-03-31 10:26:21 +00002355 ath10k_peer_assoc_h_vht(ar, vif, sta, arg);
Michal Kazior590922a2014-10-21 10:10:29 +03002356 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
2357 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002358
Kalle Valob9ada652013-10-16 15:44:46 +03002359 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002360}
2361
Michal Kazior90046f52014-02-14 14:45:51 +01002362static const u32 ath10k_smps_map[] = {
2363 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
2364 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
2365 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
2366 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
2367};
2368
2369static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
2370 const u8 *addr,
2371 const struct ieee80211_sta_ht_cap *ht_cap)
2372{
2373 int smps;
2374
2375 if (!ht_cap->ht_supported)
2376 return 0;
2377
2378 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
2379 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
2380
2381 if (smps >= ARRAY_SIZE(ath10k_smps_map))
2382 return -EINVAL;
2383
2384 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
2385 WMI_PEER_SMPS_STATE,
2386 ath10k_smps_map[smps]);
2387}
2388
Michal Kazior139e1702015-02-15 16:50:42 +02002389static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
2390 struct ieee80211_vif *vif,
2391 struct ieee80211_sta_vht_cap vht_cap)
2392{
2393 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2394 int ret;
2395 u32 param;
2396 u32 value;
2397
2398 if (!(ar->vht_cap_info &
2399 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2400 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
2401 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2402 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
2403 return 0;
2404
2405 param = ar->wmi.vdev_param->txbf;
2406 value = 0;
2407
2408 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
2409 return 0;
2410
2411 /* The following logic is correct. If a remote STA advertises support
2412 * for being a beamformer then we should enable us being a beamformee.
2413 */
2414
2415 if (ar->vht_cap_info &
2416 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2417 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
2418 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
2419 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2420
2421 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
2422 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
2423 }
2424
2425 if (ar->vht_cap_info &
2426 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2427 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
2428 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
2429 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2430
2431 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
2432 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
2433 }
2434
2435 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
2436 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2437
2438 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
2439 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2440
2441 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
2442 if (ret) {
2443 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
2444 value, ret);
2445 return ret;
2446 }
2447
2448 return 0;
2449}
2450
Kalle Valo5e3dd152013-06-12 20:52:10 +03002451/* can be called only in mac80211 callbacks due to `key_count` usage */
2452static void ath10k_bss_assoc(struct ieee80211_hw *hw,
2453 struct ieee80211_vif *vif,
2454 struct ieee80211_bss_conf *bss_conf)
2455{
2456 struct ath10k *ar = hw->priv;
2457 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior90046f52014-02-14 14:45:51 +01002458 struct ieee80211_sta_ht_cap ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02002459 struct ieee80211_sta_vht_cap vht_cap;
Kalle Valob9ada652013-10-16 15:44:46 +03002460 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002461 struct ieee80211_sta *ap_sta;
2462 int ret;
2463
Michal Kazior548db542013-07-05 16:15:15 +03002464 lockdep_assert_held(&ar->conf_mutex);
2465
Michal Kazior077efc82014-10-21 10:10:29 +03002466 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
2467 arvif->vdev_id, arvif->bssid, arvif->aid);
2468
Kalle Valo5e3dd152013-06-12 20:52:10 +03002469 rcu_read_lock();
2470
2471 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
2472 if (!ap_sta) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002473 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02002474 bss_conf->bssid, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002475 rcu_read_unlock();
2476 return;
2477 }
2478
Michal Kazior90046f52014-02-14 14:45:51 +01002479 /* ap_sta must be accessed only within rcu section which must be left
2480 * before calling ath10k_setup_peer_smps() which might sleep. */
2481 ht_cap = ap_sta->ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02002482 vht_cap = ap_sta->vht_cap;
Michal Kazior90046f52014-02-14 14:45:51 +01002483
Michal Kazior590922a2014-10-21 10:10:29 +03002484 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002485 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002486 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002487 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002488 rcu_read_unlock();
2489 return;
2490 }
2491
2492 rcu_read_unlock();
2493
Kalle Valob9ada652013-10-16 15:44:46 +03002494 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2495 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002496 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002497 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03002498 return;
2499 }
2500
Michal Kazior90046f52014-02-14 14:45:51 +01002501 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
2502 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002503 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002504 arvif->vdev_id, ret);
Michal Kazior90046f52014-02-14 14:45:51 +01002505 return;
2506 }
2507
Michal Kazior139e1702015-02-15 16:50:42 +02002508 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2509 if (ret) {
2510 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2511 arvif->vdev_id, bss_conf->bssid, ret);
2512 return;
2513 }
2514
Michal Kazior7aa7a722014-08-25 12:09:38 +02002515 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002516 "mac vdev %d up (associated) bssid %pM aid %d\n",
2517 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
2518
Michal Kazior077efc82014-10-21 10:10:29 +03002519 WARN_ON(arvif->is_up);
2520
Michal Kaziorc930f742014-01-23 11:38:25 +01002521 arvif->aid = bss_conf->aid;
Kalle Valob25f32c2014-09-14 12:50:49 +03002522 ether_addr_copy(arvif->bssid, bss_conf->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01002523
2524 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
2525 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002526 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002527 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01002528 return;
2529 }
2530
2531 arvif->is_up = true;
Michal Kazior0a987fb2015-02-13 13:30:15 +01002532
2533 /* Workaround: Some firmware revisions (tested with qca6174
2534 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2535 * poked with peer param command.
2536 */
2537 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
2538 WMI_PEER_DUMMY_VAR, 1);
2539 if (ret) {
2540 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2541 arvif->bssid, arvif->vdev_id, ret);
2542 return;
2543 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002544}
2545
Kalle Valo5e3dd152013-06-12 20:52:10 +03002546static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
2547 struct ieee80211_vif *vif)
2548{
2549 struct ath10k *ar = hw->priv;
2550 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior139e1702015-02-15 16:50:42 +02002551 struct ieee80211_sta_vht_cap vht_cap = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +03002552 int ret;
2553
Michal Kazior548db542013-07-05 16:15:15 +03002554 lockdep_assert_held(&ar->conf_mutex);
2555
Michal Kazior077efc82014-10-21 10:10:29 +03002556 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
2557 arvif->vdev_id, arvif->bssid);
Kalle Valo60c3daa2013-09-08 17:56:07 +03002558
Kalle Valo5e3dd152013-06-12 20:52:10 +03002559 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kazior077efc82014-10-21 10:10:29 +03002560 if (ret)
2561 ath10k_warn(ar, "faield to down vdev %i: %d\n",
2562 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002563
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02002564 arvif->def_wep_key_idx = -1;
2565
Michal Kazior139e1702015-02-15 16:50:42 +02002566 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2567 if (ret) {
2568 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
2569 arvif->vdev_id, ret);
2570 return;
2571 }
2572
Michal Kaziorc930f742014-01-23 11:38:25 +01002573 arvif->is_up = false;
Michal Kaziorcc9904e2015-03-10 16:22:01 +02002574
2575 cancel_delayed_work_sync(&arvif->connection_loss_work);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002576}
2577
Michal Kazior590922a2014-10-21 10:10:29 +03002578static int ath10k_station_assoc(struct ath10k *ar,
2579 struct ieee80211_vif *vif,
2580 struct ieee80211_sta *sta,
2581 bool reassoc)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002582{
Michal Kazior590922a2014-10-21 10:10:29 +03002583 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valob9ada652013-10-16 15:44:46 +03002584 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002585 int ret = 0;
2586
Michal Kazior548db542013-07-05 16:15:15 +03002587 lockdep_assert_held(&ar->conf_mutex);
2588
Michal Kazior590922a2014-10-21 10:10:29 +03002589 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002590 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002591 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02002592 sta->addr, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03002593 return ret;
2594 }
2595
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02002596 peer_arg.peer_reassoc = reassoc;
Kalle Valob9ada652013-10-16 15:44:46 +03002597 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2598 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002599 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002600 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002601 return ret;
2602 }
2603
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002604 /* Re-assoc is run only to update supported rates for given station. It
2605 * doesn't make much sense to reconfigure the peer completely.
2606 */
2607 if (!reassoc) {
2608 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
2609 &sta->ht_cap);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002610 if (ret) {
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002611 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002612 arvif->vdev_id, ret);
2613 return ret;
2614 }
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002615
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002616 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
2617 if (ret) {
2618 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
2619 sta->addr, arvif->vdev_id, ret);
2620 return ret;
2621 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002622
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002623 if (!sta->wme) {
2624 arvif->num_legacy_stations++;
2625 ret = ath10k_recalc_rtscts_prot(arvif);
2626 if (ret) {
2627 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2628 arvif->vdev_id, ret);
2629 return ret;
2630 }
2631 }
2632
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02002633 /* Plumb cached keys only for static WEP */
2634 if (arvif->def_wep_key_idx != -1) {
2635 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
2636 if (ret) {
2637 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
2638 arvif->vdev_id, ret);
2639 return ret;
2640 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002641 }
2642 }
2643
Kalle Valo5e3dd152013-06-12 20:52:10 +03002644 return ret;
2645}
2646
Michal Kazior590922a2014-10-21 10:10:29 +03002647static int ath10k_station_disassoc(struct ath10k *ar,
2648 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002649 struct ieee80211_sta *sta)
2650{
Michal Kazior590922a2014-10-21 10:10:29 +03002651 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002652 int ret = 0;
2653
2654 lockdep_assert_held(&ar->conf_mutex);
2655
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002656 if (!sta->wme) {
2657 arvif->num_legacy_stations--;
2658 ret = ath10k_recalc_rtscts_prot(arvif);
2659 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002660 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002661 arvif->vdev_id, ret);
2662 return ret;
2663 }
2664 }
2665
Kalle Valo5e3dd152013-06-12 20:52:10 +03002666 ret = ath10k_clear_peer_keys(arvif, sta->addr);
2667 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002668 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002669 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002670 return ret;
2671 }
2672
2673 return ret;
2674}
2675
2676/**************/
2677/* Regulatory */
2678/**************/
2679
2680static int ath10k_update_channel_list(struct ath10k *ar)
2681{
2682 struct ieee80211_hw *hw = ar->hw;
2683 struct ieee80211_supported_band **bands;
2684 enum ieee80211_band band;
2685 struct ieee80211_channel *channel;
2686 struct wmi_scan_chan_list_arg arg = {0};
2687 struct wmi_channel_arg *ch;
2688 bool passive;
2689 int len;
2690 int ret;
2691 int i;
2692
Michal Kazior548db542013-07-05 16:15:15 +03002693 lockdep_assert_held(&ar->conf_mutex);
2694
Kalle Valo5e3dd152013-06-12 20:52:10 +03002695 bands = hw->wiphy->bands;
2696 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2697 if (!bands[band])
2698 continue;
2699
2700 for (i = 0; i < bands[band]->n_channels; i++) {
2701 if (bands[band]->channels[i].flags &
2702 IEEE80211_CHAN_DISABLED)
2703 continue;
2704
2705 arg.n_channels++;
2706 }
2707 }
2708
2709 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
2710 arg.channels = kzalloc(len, GFP_KERNEL);
2711 if (!arg.channels)
2712 return -ENOMEM;
2713
2714 ch = arg.channels;
2715 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2716 if (!bands[band])
2717 continue;
2718
2719 for (i = 0; i < bands[band]->n_channels; i++) {
2720 channel = &bands[band]->channels[i];
2721
2722 if (channel->flags & IEEE80211_CHAN_DISABLED)
2723 continue;
2724
2725 ch->allow_ht = true;
2726
2727 /* FIXME: when should we really allow VHT? */
2728 ch->allow_vht = true;
2729
2730 ch->allow_ibss =
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002731 !(channel->flags & IEEE80211_CHAN_NO_IR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002732
2733 ch->ht40plus =
2734 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
2735
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002736 ch->chan_radar =
2737 !!(channel->flags & IEEE80211_CHAN_RADAR);
2738
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002739 passive = channel->flags & IEEE80211_CHAN_NO_IR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002740 ch->passive = passive;
2741
2742 ch->freq = channel->center_freq;
Michal Kazior2d667212014-09-18 15:21:21 +02002743 ch->band_center_freq1 = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07002744 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07002745 ch->max_power = channel->max_power * 2;
2746 ch->max_reg_power = channel->max_reg_power * 2;
2747 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002748 ch->reg_class_id = 0; /* FIXME */
2749
2750 /* FIXME: why use only legacy modes, why not any
2751 * HT/VHT modes? Would that even make any
2752 * difference? */
2753 if (channel->band == IEEE80211_BAND_2GHZ)
2754 ch->mode = MODE_11G;
2755 else
2756 ch->mode = MODE_11A;
2757
2758 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
2759 continue;
2760
Michal Kazior7aa7a722014-08-25 12:09:38 +02002761 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002762 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
2763 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002764 ch->freq, ch->max_power, ch->max_reg_power,
2765 ch->max_antenna_gain, ch->mode);
2766
2767 ch++;
2768 }
2769 }
2770
2771 ret = ath10k_wmi_scan_chan_list(ar, &arg);
2772 kfree(arg.channels);
2773
2774 return ret;
2775}
2776
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002777static enum wmi_dfs_region
2778ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
2779{
2780 switch (dfs_region) {
2781 case NL80211_DFS_UNSET:
2782 return WMI_UNINIT_DFS_DOMAIN;
2783 case NL80211_DFS_FCC:
2784 return WMI_FCC_DFS_DOMAIN;
2785 case NL80211_DFS_ETSI:
2786 return WMI_ETSI_DFS_DOMAIN;
2787 case NL80211_DFS_JP:
2788 return WMI_MKK4_DFS_DOMAIN;
2789 }
2790 return WMI_UNINIT_DFS_DOMAIN;
2791}
2792
Michal Kaziorf7843d72013-07-16 09:38:52 +02002793static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002794{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002795 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002796 int ret;
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002797 enum wmi_dfs_region wmi_dfs_reg;
2798 enum nl80211_dfs_regions nl_dfs_reg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002799
Michal Kaziorf7843d72013-07-16 09:38:52 +02002800 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002801
2802 ret = ath10k_update_channel_list(ar);
2803 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002804 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002805
2806 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002807
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002808 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
2809 nl_dfs_reg = ar->dfs_detector->region;
2810 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
2811 } else {
2812 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
2813 }
2814
Kalle Valo5e3dd152013-06-12 20:52:10 +03002815 /* Target allows setting up per-band regdomain but ath_common provides
2816 * a combined one only */
2817 ret = ath10k_wmi_pdev_set_regdomain(ar,
Kalle Valoef8c0012014-02-13 18:13:12 +02002818 regpair->reg_domain,
2819 regpair->reg_domain, /* 2ghz */
2820 regpair->reg_domain, /* 5ghz */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002821 regpair->reg_2ghz_ctl,
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002822 regpair->reg_5ghz_ctl,
2823 wmi_dfs_reg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002824 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002825 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02002826}
Michal Kazior548db542013-07-05 16:15:15 +03002827
Michal Kaziorf7843d72013-07-16 09:38:52 +02002828static void ath10k_reg_notifier(struct wiphy *wiphy,
2829 struct regulatory_request *request)
2830{
2831 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
2832 struct ath10k *ar = hw->priv;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002833 bool result;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002834
2835 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
2836
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002837 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002838 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002839 request->dfs_region);
2840 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
2841 request->dfs_region);
2842 if (!result)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002843 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002844 request->dfs_region);
2845 }
2846
Michal Kaziorf7843d72013-07-16 09:38:52 +02002847 mutex_lock(&ar->conf_mutex);
2848 if (ar->state == ATH10K_STATE_ON)
2849 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03002850 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002851}
2852
2853/***************/
2854/* TX handlers */
2855/***************/
2856
Michal Kazior96d828d2015-03-31 10:26:23 +00002857void ath10k_mac_tx_lock(struct ath10k *ar, int reason)
2858{
2859 lockdep_assert_held(&ar->htt.tx_lock);
2860
2861 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
2862 ar->tx_paused |= BIT(reason);
2863 ieee80211_stop_queues(ar->hw);
2864}
2865
2866static void ath10k_mac_tx_unlock_iter(void *data, u8 *mac,
2867 struct ieee80211_vif *vif)
2868{
2869 struct ath10k *ar = data;
2870 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2871
2872 if (arvif->tx_paused)
2873 return;
2874
2875 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
2876}
2877
2878void ath10k_mac_tx_unlock(struct ath10k *ar, int reason)
2879{
2880 lockdep_assert_held(&ar->htt.tx_lock);
2881
2882 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
2883 ar->tx_paused &= ~BIT(reason);
2884
2885 if (ar->tx_paused)
2886 return;
2887
2888 ieee80211_iterate_active_interfaces_atomic(ar->hw,
2889 IEEE80211_IFACE_ITER_RESUME_ALL,
2890 ath10k_mac_tx_unlock_iter,
2891 ar);
2892}
2893
2894void ath10k_mac_vif_tx_lock(struct ath10k_vif *arvif, int reason)
2895{
2896 struct ath10k *ar = arvif->ar;
2897
2898 lockdep_assert_held(&ar->htt.tx_lock);
2899
2900 WARN_ON(reason >= BITS_PER_LONG);
2901 arvif->tx_paused |= BIT(reason);
2902 ieee80211_stop_queue(ar->hw, arvif->vdev_id);
2903}
2904
2905void ath10k_mac_vif_tx_unlock(struct ath10k_vif *arvif, int reason)
2906{
2907 struct ath10k *ar = arvif->ar;
2908
2909 lockdep_assert_held(&ar->htt.tx_lock);
2910
2911 WARN_ON(reason >= BITS_PER_LONG);
2912 arvif->tx_paused &= ~BIT(reason);
2913
2914 if (ar->tx_paused)
2915 return;
2916
2917 if (arvif->tx_paused)
2918 return;
2919
2920 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
2921}
2922
Michal Kaziorb4aa5392015-03-31 10:26:24 +00002923static void ath10k_mac_vif_handle_tx_pause(struct ath10k_vif *arvif,
2924 enum wmi_tlv_tx_pause_id pause_id,
2925 enum wmi_tlv_tx_pause_action action)
2926{
2927 struct ath10k *ar = arvif->ar;
2928
2929 lockdep_assert_held(&ar->htt.tx_lock);
2930
2931 switch (pause_id) {
2932 case WMI_TLV_TX_PAUSE_ID_MCC:
2933 case WMI_TLV_TX_PAUSE_ID_P2P_CLI_NOA:
2934 case WMI_TLV_TX_PAUSE_ID_P2P_GO_PS:
2935 case WMI_TLV_TX_PAUSE_ID_AP_PS:
2936 case WMI_TLV_TX_PAUSE_ID_IBSS_PS:
2937 switch (action) {
2938 case WMI_TLV_TX_PAUSE_ACTION_STOP:
2939 ath10k_mac_vif_tx_lock(arvif, pause_id);
2940 break;
2941 case WMI_TLV_TX_PAUSE_ACTION_WAKE:
2942 ath10k_mac_vif_tx_unlock(arvif, pause_id);
2943 break;
2944 default:
2945 ath10k_warn(ar, "received unknown tx pause action %d on vdev %i, ignoring\n",
2946 action, arvif->vdev_id);
2947 break;
2948 }
2949 break;
2950 case WMI_TLV_TX_PAUSE_ID_AP_PEER_PS:
2951 case WMI_TLV_TX_PAUSE_ID_AP_PEER_UAPSD:
2952 case WMI_TLV_TX_PAUSE_ID_STA_ADD_BA:
2953 case WMI_TLV_TX_PAUSE_ID_HOST:
2954 default:
2955 /* FIXME: Some pause_ids aren't vdev specific. Instead they
2956 * target peer_id and tid. Implementing these could improve
2957 * traffic scheduling fairness across multiple connected
2958 * stations in AP/IBSS modes.
2959 */
2960 ath10k_dbg(ar, ATH10K_DBG_MAC,
2961 "mac ignoring unsupported tx pause vdev %i id %d\n",
2962 arvif->vdev_id, pause_id);
2963 break;
2964 }
2965}
2966
2967struct ath10k_mac_tx_pause {
2968 u32 vdev_id;
2969 enum wmi_tlv_tx_pause_id pause_id;
2970 enum wmi_tlv_tx_pause_action action;
2971};
2972
2973static void ath10k_mac_handle_tx_pause_iter(void *data, u8 *mac,
2974 struct ieee80211_vif *vif)
2975{
2976 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2977 struct ath10k_mac_tx_pause *arg = data;
2978
2979 ath10k_mac_vif_handle_tx_pause(arvif, arg->pause_id, arg->action);
2980}
2981
2982void ath10k_mac_handle_tx_pause(struct ath10k *ar, u32 vdev_id,
2983 enum wmi_tlv_tx_pause_id pause_id,
2984 enum wmi_tlv_tx_pause_action action)
2985{
2986 struct ath10k_mac_tx_pause arg = {
2987 .vdev_id = vdev_id,
2988 .pause_id = pause_id,
2989 .action = action,
2990 };
2991
2992 spin_lock_bh(&ar->htt.tx_lock);
2993 ieee80211_iterate_active_interfaces_atomic(ar->hw,
2994 IEEE80211_IFACE_ITER_RESUME_ALL,
2995 ath10k_mac_handle_tx_pause_iter,
2996 &arg);
2997 spin_unlock_bh(&ar->htt.tx_lock);
2998}
2999
Michal Kazior42c3aa62013-10-02 11:03:38 +02003000static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
3001{
3002 if (ieee80211_is_mgmt(hdr->frame_control))
3003 return HTT_DATA_TX_EXT_TID_MGMT;
3004
3005 if (!ieee80211_is_data_qos(hdr->frame_control))
3006 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
3007
3008 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
3009 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
3010
3011 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
3012}
3013
Michal Kazior2b37c292014-09-02 11:00:22 +03003014static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02003015{
Michal Kazior2b37c292014-09-02 11:00:22 +03003016 if (vif)
3017 return ath10k_vif_to_arvif(vif)->vdev_id;
Michal Kaziorddb6ad72013-10-02 11:03:39 +02003018
Michal Kazior1bbc0972014-04-08 09:45:47 +03003019 if (ar->monitor_started)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02003020 return ar->monitor_vdev_id;
3021
Michal Kazior7aa7a722014-08-25 12:09:38 +02003022 ath10k_warn(ar, "failed to resolve vdev id\n");
Michal Kaziorddb6ad72013-10-02 11:03:39 +02003023 return 0;
3024}
3025
Michal Kaziord740d8f2015-03-30 09:51:51 +03003026static enum ath10k_hw_txrx_mode
3027ath10k_tx_h_get_txmode(struct ath10k *ar, struct ieee80211_vif *vif,
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003028 struct ieee80211_sta *sta, struct sk_buff *skb)
Michal Kaziord740d8f2015-03-30 09:51:51 +03003029{
3030 const struct ieee80211_hdr *hdr = (void *)skb->data;
3031 __le16 fc = hdr->frame_control;
3032
3033 if (!vif || vif->type == NL80211_IFTYPE_MONITOR)
3034 return ATH10K_HW_TXRX_RAW;
3035
3036 if (ieee80211_is_mgmt(fc))
3037 return ATH10K_HW_TXRX_MGMT;
3038
3039 /* Workaround:
3040 *
3041 * NullFunc frames are mostly used to ping if a client or AP are still
3042 * reachable and responsive. This implies tx status reports must be
3043 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
3044 * come to a conclusion that the other end disappeared and tear down
3045 * BSS connection or it can never disconnect from BSS/client (which is
3046 * the case).
3047 *
3048 * Firmware with HTT older than 3.0 delivers incorrect tx status for
3049 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
3050 * which seems to deliver correct tx reports for NullFunc frames. The
3051 * downside of using it is it ignores client powersave state so it can
3052 * end up disconnecting sleeping clients in AP mode. It should fix STA
3053 * mode though because AP don't sleep.
3054 */
3055 if (ar->htt.target_version_major < 3 &&
3056 (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc)) &&
3057 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX, ar->fw_features))
3058 return ATH10K_HW_TXRX_MGMT;
3059
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003060 /* Workaround:
3061 *
3062 * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
3063 * NativeWifi txmode - it selects AP key instead of peer key. It seems
3064 * to work with Ethernet txmode so use it.
3065 */
3066 if (ieee80211_is_data_present(fc) && sta && sta->tdls)
3067 return ATH10K_HW_TXRX_ETHERNET;
3068
Michal Kaziord740d8f2015-03-30 09:51:51 +03003069 return ATH10K_HW_TXRX_NATIVE_WIFI;
3070}
3071
Michal Kazior4b604552014-07-21 21:03:09 +03003072/* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
3073 * Control in the header.
Kalle Valo5e3dd152013-06-12 20:52:10 +03003074 */
Michal Kazior4b604552014-07-21 21:03:09 +03003075static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003076{
3077 struct ieee80211_hdr *hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03003078 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003079 u8 *qos_ctl;
3080
3081 if (!ieee80211_is_data_qos(hdr->frame_control))
3082 return;
3083
3084 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02003085 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
3086 skb->data, (void *)qos_ctl - (void *)skb->data);
3087 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Michal Kaziorc21c64d2014-07-21 21:03:10 +03003088
Michal Kazior8bad8dc2015-03-11 14:25:26 +01003089 /* Some firmware revisions don't handle sending QoS NullFunc well.
3090 * These frames are mainly used for CQM purposes so it doesn't really
3091 * matter whether QoS NullFunc or NullFunc are sent.
Michal Kaziorc21c64d2014-07-21 21:03:10 +03003092 */
Michal Kaziorbf0a26d2015-01-24 12:14:51 +02003093 hdr = (void *)skb->data;
Michal Kazior8bad8dc2015-03-11 14:25:26 +01003094 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
Michal Kaziorc21c64d2014-07-21 21:03:10 +03003095 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
Michal Kazior8bad8dc2015-03-11 14:25:26 +01003096
3097 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003098}
3099
Michal Kaziord740d8f2015-03-30 09:51:51 +03003100static void ath10k_tx_h_8023(struct sk_buff *skb)
3101{
3102 struct ieee80211_hdr *hdr;
3103 struct rfc1042_hdr *rfc1042;
3104 struct ethhdr *eth;
3105 size_t hdrlen;
3106 u8 da[ETH_ALEN];
3107 u8 sa[ETH_ALEN];
3108 __be16 type;
3109
3110 hdr = (void *)skb->data;
3111 hdrlen = ieee80211_hdrlen(hdr->frame_control);
3112 rfc1042 = (void *)skb->data + hdrlen;
3113
3114 ether_addr_copy(da, ieee80211_get_DA(hdr));
3115 ether_addr_copy(sa, ieee80211_get_SA(hdr));
3116 type = rfc1042->snap_type;
3117
3118 skb_pull(skb, hdrlen + sizeof(*rfc1042));
3119 skb_push(skb, sizeof(*eth));
3120
3121 eth = (void *)skb->data;
3122 ether_addr_copy(eth->h_dest, da);
3123 ether_addr_copy(eth->h_source, sa);
3124 eth->h_proto = type;
3125}
3126
Michal Kazior4b604552014-07-21 21:03:09 +03003127static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
3128 struct ieee80211_vif *vif,
3129 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003130{
3131 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003132 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3133
3134 /* This is case only for P2P_GO */
3135 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
3136 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
3137 return;
3138
3139 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
3140 spin_lock_bh(&ar->data_lock);
3141 if (arvif->u.ap.noa_data)
3142 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
3143 GFP_ATOMIC))
3144 memcpy(skb_put(skb, arvif->u.ap.noa_len),
3145 arvif->u.ap.noa_data,
3146 arvif->u.ap.noa_len);
3147 spin_unlock_bh(&ar->data_lock);
3148 }
3149}
3150
Michal Kazior8d6d3622014-11-24 14:58:31 +01003151static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar)
3152{
3153 /* FIXME: Not really sure since when the behaviour changed. At some
3154 * point new firmware stopped requiring creation of peer entries for
3155 * offchannel tx (and actually creating them causes issues with wmi-htc
3156 * tx credit replenishment and reliability). Assuming it's at least 3.4
3157 * because that's when the `freq` was introduced to TX_FRM HTT command.
3158 */
3159 return !(ar->htt.target_version_major >= 3 &&
3160 ar->htt.target_version_minor >= 4);
3161}
3162
Michal Kaziord740d8f2015-03-30 09:51:51 +03003163static int ath10k_mac_tx_wmi_mgmt(struct ath10k *ar, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003164{
Michal Kaziord740d8f2015-03-30 09:51:51 +03003165 struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003166 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003167
Michal Kaziord740d8f2015-03-30 09:51:51 +03003168 spin_lock_bh(&ar->data_lock);
3169
3170 if (skb_queue_len(q) == ATH10K_MAX_NUM_MGMT_PENDING) {
3171 ath10k_warn(ar, "wmi mgmt tx queue is full\n");
3172 ret = -ENOSPC;
3173 goto unlock;
Michal Kazior961d4c32013-08-09 10:13:34 +02003174 }
3175
Michal Kaziord740d8f2015-03-30 09:51:51 +03003176 __skb_queue_tail(q, skb);
3177 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
3178
3179unlock:
3180 spin_unlock_bh(&ar->data_lock);
3181
3182 return ret;
3183}
3184
3185static void ath10k_mac_tx(struct ath10k *ar, struct sk_buff *skb)
3186{
3187 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3188 struct ath10k_htt *htt = &ar->htt;
3189 int ret = 0;
3190
3191 switch (cb->txmode) {
3192 case ATH10K_HW_TXRX_RAW:
3193 case ATH10K_HW_TXRX_NATIVE_WIFI:
3194 case ATH10K_HW_TXRX_ETHERNET:
3195 ret = ath10k_htt_tx(htt, skb);
3196 break;
3197 case ATH10K_HW_TXRX_MGMT:
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003198 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
Michal Kaziord740d8f2015-03-30 09:51:51 +03003199 ar->fw_features))
3200 ret = ath10k_mac_tx_wmi_mgmt(ar, skb);
3201 else if (ar->htt.target_version_major >= 3)
3202 ret = ath10k_htt_tx(htt, skb);
3203 else
3204 ret = ath10k_htt_mgmt_tx(htt, skb);
3205 break;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003206 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003207
3208 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003209 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
3210 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003211 ieee80211_free_txskb(ar->hw, skb);
3212 }
3213}
3214
3215void ath10k_offchan_tx_purge(struct ath10k *ar)
3216{
3217 struct sk_buff *skb;
3218
3219 for (;;) {
3220 skb = skb_dequeue(&ar->offchan_tx_queue);
3221 if (!skb)
3222 break;
3223
3224 ieee80211_free_txskb(ar->hw, skb);
3225 }
3226}
3227
3228void ath10k_offchan_tx_work(struct work_struct *work)
3229{
3230 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
3231 struct ath10k_peer *peer;
3232 struct ieee80211_hdr *hdr;
3233 struct sk_buff *skb;
3234 const u8 *peer_addr;
3235 int vdev_id;
3236 int ret;
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +03003237 unsigned long time_left;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003238
3239 /* FW requirement: We must create a peer before FW will send out
3240 * an offchannel frame. Otherwise the frame will be stuck and
3241 * never transmitted. We delete the peer upon tx completion.
3242 * It is unlikely that a peer for offchannel tx will already be
3243 * present. However it may be in some rare cases so account for that.
3244 * Otherwise we might remove a legitimate peer and break stuff. */
3245
3246 for (;;) {
3247 skb = skb_dequeue(&ar->offchan_tx_queue);
3248 if (!skb)
3249 break;
3250
3251 mutex_lock(&ar->conf_mutex);
3252
Michal Kazior7aa7a722014-08-25 12:09:38 +02003253 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003254 skb);
3255
3256 hdr = (struct ieee80211_hdr *)skb->data;
3257 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003258 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003259
3260 spin_lock_bh(&ar->data_lock);
3261 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
3262 spin_unlock_bh(&ar->data_lock);
3263
3264 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03003265 /* FIXME: should this use ath10k_warn()? */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003266 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003267 peer_addr, vdev_id);
3268
3269 if (!peer) {
Marek Puzyniak7390ed32015-03-30 09:51:52 +03003270 ret = ath10k_peer_create(ar, vdev_id, peer_addr,
3271 WMI_PEER_TYPE_DEFAULT);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003272 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003273 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003274 peer_addr, vdev_id, ret);
3275 }
3276
3277 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08003278 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003279 ar->offchan_tx_skb = skb;
3280 spin_unlock_bh(&ar->data_lock);
3281
Michal Kaziord740d8f2015-03-30 09:51:51 +03003282 ath10k_mac_tx(ar, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003283
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +03003284 time_left =
3285 wait_for_completion_timeout(&ar->offchan_tx_completed, 3 * HZ);
3286 if (time_left == 0)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003287 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003288 skb);
3289
3290 if (!peer) {
3291 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
3292 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003293 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003294 peer_addr, vdev_id, ret);
3295 }
3296
3297 mutex_unlock(&ar->conf_mutex);
3298 }
3299}
3300
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003301void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
3302{
3303 struct sk_buff *skb;
3304
3305 for (;;) {
3306 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3307 if (!skb)
3308 break;
3309
3310 ieee80211_free_txskb(ar->hw, skb);
3311 }
3312}
3313
3314void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
3315{
3316 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
3317 struct sk_buff *skb;
3318 int ret;
3319
3320 for (;;) {
3321 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3322 if (!skb)
3323 break;
3324
3325 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01003326 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003327 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02003328 ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01003329 ieee80211_free_txskb(ar->hw, skb);
3330 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003331 }
3332}
3333
Kalle Valo5e3dd152013-06-12 20:52:10 +03003334/************/
3335/* Scanning */
3336/************/
3337
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003338void __ath10k_scan_finish(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003339{
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003340 lockdep_assert_held(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003341
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003342 switch (ar->scan.state) {
3343 case ATH10K_SCAN_IDLE:
3344 break;
3345 case ATH10K_SCAN_RUNNING:
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003346 if (ar->scan.is_roc)
3347 ieee80211_remain_on_channel_expired(ar->hw);
John W. Linvillef6eaf1e2015-01-12 16:07:02 -05003348 /* fall through */
Michal Kazior7305d3e2014-11-24 14:58:33 +01003349 case ATH10K_SCAN_ABORTING:
3350 if (!ar->scan.is_roc)
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003351 ieee80211_scan_completed(ar->hw,
3352 (ar->scan.state ==
3353 ATH10K_SCAN_ABORTING));
3354 /* fall through */
3355 case ATH10K_SCAN_STARTING:
3356 ar->scan.state = ATH10K_SCAN_IDLE;
3357 ar->scan_channel = NULL;
3358 ath10k_offchan_tx_purge(ar);
3359 cancel_delayed_work(&ar->scan.timeout);
3360 complete_all(&ar->scan.completed);
3361 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003362 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003363}
Kalle Valo5e3dd152013-06-12 20:52:10 +03003364
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003365void ath10k_scan_finish(struct ath10k *ar)
3366{
3367 spin_lock_bh(&ar->data_lock);
3368 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003369 spin_unlock_bh(&ar->data_lock);
3370}
3371
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003372static int ath10k_scan_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003373{
3374 struct wmi_stop_scan_arg arg = {
3375 .req_id = 1, /* FIXME */
3376 .req_type = WMI_SCAN_STOP_ONE,
3377 .u.scan_id = ATH10K_SCAN_ID,
3378 };
3379 int ret;
3380
3381 lockdep_assert_held(&ar->conf_mutex);
3382
Kalle Valo5e3dd152013-06-12 20:52:10 +03003383 ret = ath10k_wmi_stop_scan(ar, &arg);
3384 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003385 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003386 goto out;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003387 }
3388
Kalle Valo5e3dd152013-06-12 20:52:10 +03003389 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003390 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003391 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003392 ret = -ETIMEDOUT;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003393 } else if (ret > 0) {
3394 ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003395 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003396
3397out:
3398 /* Scan state should be updated upon scan completion but in case
3399 * firmware fails to deliver the event (for whatever reason) it is
3400 * desired to clean up scan state anyway. Firmware may have just
3401 * dropped the scan completion event delivery due to transport pipe
3402 * being overflown with data and/or it can recover on its own before
3403 * next scan request is submitted.
3404 */
3405 spin_lock_bh(&ar->data_lock);
3406 if (ar->scan.state != ATH10K_SCAN_IDLE)
3407 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003408 spin_unlock_bh(&ar->data_lock);
3409
3410 return ret;
3411}
3412
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003413static void ath10k_scan_abort(struct ath10k *ar)
3414{
3415 int ret;
3416
3417 lockdep_assert_held(&ar->conf_mutex);
3418
3419 spin_lock_bh(&ar->data_lock);
3420
3421 switch (ar->scan.state) {
3422 case ATH10K_SCAN_IDLE:
3423 /* This can happen if timeout worker kicked in and called
3424 * abortion while scan completion was being processed.
3425 */
3426 break;
3427 case ATH10K_SCAN_STARTING:
3428 case ATH10K_SCAN_ABORTING:
Michal Kazior7aa7a722014-08-25 12:09:38 +02003429 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003430 ath10k_scan_state_str(ar->scan.state),
3431 ar->scan.state);
3432 break;
3433 case ATH10K_SCAN_RUNNING:
3434 ar->scan.state = ATH10K_SCAN_ABORTING;
3435 spin_unlock_bh(&ar->data_lock);
3436
3437 ret = ath10k_scan_stop(ar);
3438 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003439 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003440
3441 spin_lock_bh(&ar->data_lock);
3442 break;
3443 }
3444
3445 spin_unlock_bh(&ar->data_lock);
3446}
3447
3448void ath10k_scan_timeout_work(struct work_struct *work)
3449{
3450 struct ath10k *ar = container_of(work, struct ath10k,
3451 scan.timeout.work);
3452
3453 mutex_lock(&ar->conf_mutex);
3454 ath10k_scan_abort(ar);
3455 mutex_unlock(&ar->conf_mutex);
3456}
3457
Kalle Valo5e3dd152013-06-12 20:52:10 +03003458static int ath10k_start_scan(struct ath10k *ar,
3459 const struct wmi_start_scan_arg *arg)
3460{
3461 int ret;
3462
3463 lockdep_assert_held(&ar->conf_mutex);
3464
3465 ret = ath10k_wmi_start_scan(ar, arg);
3466 if (ret)
3467 return ret;
3468
Kalle Valo5e3dd152013-06-12 20:52:10 +03003469 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
3470 if (ret == 0) {
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003471 ret = ath10k_scan_stop(ar);
3472 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003473 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003474
3475 return -ETIMEDOUT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003476 }
3477
Ben Greear2f9eec02015-02-15 16:50:38 +02003478 /* If we failed to start the scan, return error code at
3479 * this point. This is probably due to some issue in the
3480 * firmware, but no need to wedge the driver due to that...
3481 */
3482 spin_lock_bh(&ar->data_lock);
3483 if (ar->scan.state == ATH10K_SCAN_IDLE) {
3484 spin_unlock_bh(&ar->data_lock);
3485 return -EINVAL;
3486 }
3487 spin_unlock_bh(&ar->data_lock);
3488
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003489 /* Add a 200ms margin to account for event/command processing */
3490 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
3491 msecs_to_jiffies(arg->max_scan_time+200));
Kalle Valo5e3dd152013-06-12 20:52:10 +03003492 return 0;
3493}
3494
3495/**********************/
3496/* mac80211 callbacks */
3497/**********************/
3498
3499static void ath10k_tx(struct ieee80211_hw *hw,
3500 struct ieee80211_tx_control *control,
3501 struct sk_buff *skb)
3502{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003503 struct ath10k *ar = hw->priv;
Michal Kazior4b604552014-07-21 21:03:09 +03003504 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3505 struct ieee80211_vif *vif = info->control.vif;
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003506 struct ieee80211_sta *sta = control->sta;
Michal Kazior4b604552014-07-21 21:03:09 +03003507 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Michal Kaziord740d8f2015-03-30 09:51:51 +03003508 __le16 fc = hdr->frame_control;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003509
3510 /* We should disable CCK RATE due to P2P */
3511 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003512 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003513
Michal Kazior4b604552014-07-21 21:03:09 +03003514 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
Michal Kazior6fcafef2015-03-30 09:51:51 +03003515 ATH10K_SKB_CB(skb)->htt.freq = 0;
Michal Kazior4b604552014-07-21 21:03:09 +03003516 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
Michal Kazior2b37c292014-09-02 11:00:22 +03003517 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003518 ATH10K_SKB_CB(skb)->txmode = ath10k_tx_h_get_txmode(ar, vif, sta, skb);
Michal Kaziord740d8f2015-03-30 09:51:51 +03003519 ATH10K_SKB_CB(skb)->is_protected = ieee80211_has_protected(fc);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003520
Michal Kaziord740d8f2015-03-30 09:51:51 +03003521 switch (ATH10K_SKB_CB(skb)->txmode) {
3522 case ATH10K_HW_TXRX_MGMT:
3523 case ATH10K_HW_TXRX_NATIVE_WIFI:
Michal Kazior4b604552014-07-21 21:03:09 +03003524 ath10k_tx_h_nwifi(hw, skb);
Michal Kazior4b604552014-07-21 21:03:09 +03003525 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
3526 ath10k_tx_h_seq_no(vif, skb);
Michal Kaziord740d8f2015-03-30 09:51:51 +03003527 break;
3528 case ATH10K_HW_TXRX_ETHERNET:
3529 ath10k_tx_h_8023(skb);
3530 break;
3531 case ATH10K_HW_TXRX_RAW:
3532 /* FIXME: Packet injection isn't implemented. It should be
3533 * doable with firmware 10.2 on qca988x.
3534 */
3535 WARN_ON_ONCE(1);
3536 ieee80211_free_txskb(hw, skb);
3537 return;
Michal Kaziorcf84bd42013-07-16 11:04:54 +02003538 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003539
Kalle Valo5e3dd152013-06-12 20:52:10 +03003540 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
3541 spin_lock_bh(&ar->data_lock);
Michal Kazior8d6d3622014-11-24 14:58:31 +01003542 ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003543 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003544 spin_unlock_bh(&ar->data_lock);
3545
Michal Kazior8d6d3622014-11-24 14:58:31 +01003546 if (ath10k_mac_need_offchan_tx_work(ar)) {
3547 ATH10K_SKB_CB(skb)->htt.freq = 0;
3548 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003549
Michal Kazior8d6d3622014-11-24 14:58:31 +01003550 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
3551 skb);
3552
3553 skb_queue_tail(&ar->offchan_tx_queue, skb);
3554 ieee80211_queue_work(hw, &ar->offchan_tx_work);
3555 return;
3556 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003557 }
3558
Michal Kaziord740d8f2015-03-30 09:51:51 +03003559 ath10k_mac_tx(ar, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003560}
3561
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003562/* Must not be called with conf_mutex held as workers can use that also. */
Michal Kazior7962b0d2014-10-28 10:34:38 +01003563void ath10k_drain_tx(struct ath10k *ar)
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003564{
3565 /* make sure rcu-protected mac80211 tx path itself is drained */
3566 synchronize_net();
3567
3568 ath10k_offchan_tx_purge(ar);
3569 ath10k_mgmt_over_wmi_tx_purge(ar);
3570
3571 cancel_work_sync(&ar->offchan_tx_work);
3572 cancel_work_sync(&ar->wmi_mgmt_tx_work);
3573}
3574
Michal Kazioraffd3212013-07-16 09:54:35 +02003575void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02003576{
Michal Kaziord9bc4b92014-04-23 19:30:06 +03003577 struct ath10k_vif *arvif;
3578
Michal Kazior818bdd12013-07-16 09:38:57 +02003579 lockdep_assert_held(&ar->conf_mutex);
3580
Michal Kazior19337472014-08-28 12:58:16 +02003581 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
3582 ar->filter_flags = 0;
3583 ar->monitor = false;
Michal Kazior500ff9f2015-03-31 10:26:21 +00003584 ar->monitor_arvif = NULL;
Michal Kazior19337472014-08-28 12:58:16 +02003585
3586 if (ar->monitor_started)
Michal Kazior1bbc0972014-04-08 09:45:47 +03003587 ath10k_monitor_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +02003588
3589 ar->monitor_started = false;
Michal Kazior96d828d2015-03-31 10:26:23 +00003590 ar->tx_paused = 0;
Michal Kazior1bbc0972014-04-08 09:45:47 +03003591
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003592 ath10k_scan_finish(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02003593 ath10k_peer_cleanup_all(ar);
3594 ath10k_core_stop(ar);
3595 ath10k_hif_power_down(ar);
3596
3597 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03003598 list_for_each_entry(arvif, &ar->arvifs, list)
3599 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kazior818bdd12013-07-16 09:38:57 +02003600 spin_unlock_bh(&ar->data_lock);
3601}
3602
Ben Greear46acf7b2014-05-16 17:15:38 +03003603static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
3604{
3605 struct ath10k *ar = hw->priv;
3606
3607 mutex_lock(&ar->conf_mutex);
3608
3609 if (ar->cfg_tx_chainmask) {
3610 *tx_ant = ar->cfg_tx_chainmask;
3611 *rx_ant = ar->cfg_rx_chainmask;
3612 } else {
3613 *tx_ant = ar->supp_tx_chainmask;
3614 *rx_ant = ar->supp_rx_chainmask;
3615 }
3616
3617 mutex_unlock(&ar->conf_mutex);
3618
3619 return 0;
3620}
3621
Ben Greear5572a952014-11-24 16:22:10 +02003622static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
3623{
3624 /* It is not clear that allowing gaps in chainmask
3625 * is helpful. Probably it will not do what user
3626 * is hoping for, so warn in that case.
3627 */
3628 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
3629 return;
3630
3631 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
3632 dbg, cm);
3633}
3634
Ben Greear46acf7b2014-05-16 17:15:38 +03003635static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
3636{
3637 int ret;
3638
3639 lockdep_assert_held(&ar->conf_mutex);
3640
Ben Greear5572a952014-11-24 16:22:10 +02003641 ath10k_check_chain_mask(ar, tx_ant, "tx");
3642 ath10k_check_chain_mask(ar, rx_ant, "rx");
3643
Ben Greear46acf7b2014-05-16 17:15:38 +03003644 ar->cfg_tx_chainmask = tx_ant;
3645 ar->cfg_rx_chainmask = rx_ant;
3646
3647 if ((ar->state != ATH10K_STATE_ON) &&
3648 (ar->state != ATH10K_STATE_RESTARTED))
3649 return 0;
3650
3651 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
3652 tx_ant);
3653 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003654 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03003655 ret, tx_ant);
3656 return ret;
3657 }
3658
3659 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
3660 rx_ant);
3661 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003662 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03003663 ret, rx_ant);
3664 return ret;
3665 }
3666
3667 return 0;
3668}
3669
3670static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
3671{
3672 struct ath10k *ar = hw->priv;
3673 int ret;
3674
3675 mutex_lock(&ar->conf_mutex);
3676 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
3677 mutex_unlock(&ar->conf_mutex);
3678 return ret;
3679}
3680
Kalle Valo5e3dd152013-06-12 20:52:10 +03003681static int ath10k_start(struct ieee80211_hw *hw)
3682{
3683 struct ath10k *ar = hw->priv;
Michal Kazior818bdd12013-07-16 09:38:57 +02003684 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003685
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003686 /*
3687 * This makes sense only when restarting hw. It is harmless to call
3688 * uncoditionally. This is necessary to make sure no HTT/WMI tx
3689 * commands will be submitted while restarting.
3690 */
3691 ath10k_drain_tx(ar);
3692
Michal Kazior548db542013-07-05 16:15:15 +03003693 mutex_lock(&ar->conf_mutex);
3694
Michal Kaziorc5058f52014-05-26 12:46:03 +03003695 switch (ar->state) {
3696 case ATH10K_STATE_OFF:
3697 ar->state = ATH10K_STATE_ON;
3698 break;
3699 case ATH10K_STATE_RESTARTING:
3700 ath10k_halt(ar);
3701 ar->state = ATH10K_STATE_RESTARTED;
3702 break;
3703 case ATH10K_STATE_ON:
3704 case ATH10K_STATE_RESTARTED:
3705 case ATH10K_STATE_WEDGED:
3706 WARN_ON(1);
Michal Kazior818bdd12013-07-16 09:38:57 +02003707 ret = -EINVAL;
Michal Kaziorae254432014-05-26 12:46:02 +03003708 goto err;
Kalle Valo43d2a302014-09-10 18:23:30 +03003709 case ATH10K_STATE_UTF:
3710 ret = -EBUSY;
3711 goto err;
Michal Kazior818bdd12013-07-16 09:38:57 +02003712 }
3713
3714 ret = ath10k_hif_power_up(ar);
3715 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003716 ath10k_err(ar, "Could not init hif: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003717 goto err_off;
Michal Kazior818bdd12013-07-16 09:38:57 +02003718 }
3719
Kalle Valo43d2a302014-09-10 18:23:30 +03003720 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
Michal Kazior818bdd12013-07-16 09:38:57 +02003721 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003722 ath10k_err(ar, "Could not init core: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003723 goto err_power_down;
Michal Kazior818bdd12013-07-16 09:38:57 +02003724 }
3725
Bartosz Markowski226a3392013-09-26 17:47:16 +02003726 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03003727 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003728 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003729 goto err_core_stop;
3730 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003731
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01003732 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03003733 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003734 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003735 goto err_core_stop;
3736 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003737
Michal Kaziorcf327842015-03-31 10:26:25 +00003738 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
3739 ret = ath10k_wmi_adaptive_qcs(ar, true);
3740 if (ret) {
3741 ath10k_warn(ar, "failed to enable adaptive qcs: %d\n",
3742 ret);
3743 goto err_core_stop;
3744 }
3745 }
3746
Ben Greear46acf7b2014-05-16 17:15:38 +03003747 if (ar->cfg_tx_chainmask)
3748 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
3749 ar->cfg_rx_chainmask);
3750
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003751 /*
3752 * By default FW set ARP frames ac to voice (6). In that case ARP
3753 * exchange is not working properly for UAPSD enabled AP. ARP requests
3754 * which arrives with access category 0 are processed by network stack
3755 * and send back with access category 0, but FW changes access category
3756 * to 6. Set ARP frames access category to best effort (0) solves
3757 * this problem.
3758 */
3759
3760 ret = ath10k_wmi_pdev_set_param(ar,
3761 ar->wmi.pdev_param->arp_ac_override, 0);
3762 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003763 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003764 ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003765 goto err_core_stop;
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003766 }
3767
Ashok Raj Nagarajan575f1c32015-03-19 16:37:59 +05303768 ret = ath10k_wmi_pdev_set_param(ar,
3769 ar->wmi.pdev_param->ani_enable, 1);
3770 if (ret) {
3771 ath10k_warn(ar, "failed to enable ani by default: %d\n",
3772 ret);
3773 goto err_core_stop;
3774 }
3775
Ashok Raj Nagarajanb3e71d72015-03-19 16:38:00 +05303776 ar->ani_enabled = true;
3777
Michal Kaziord6500972014-04-08 09:56:09 +03003778 ar->num_started_vdevs = 0;
Michal Kaziorf7843d72013-07-16 09:38:52 +02003779 ath10k_regd_update(ar);
3780
Simon Wunderlich855aed12014-08-02 09:12:54 +03003781 ath10k_spectral_start(ar);
Rajkumar Manoharan8515b5c2015-03-15 20:36:22 +05303782 ath10k_thermal_set_throttling(ar);
Simon Wunderlich855aed12014-08-02 09:12:54 +03003783
Michal Kaziorae254432014-05-26 12:46:02 +03003784 mutex_unlock(&ar->conf_mutex);
3785 return 0;
3786
3787err_core_stop:
3788 ath10k_core_stop(ar);
3789
3790err_power_down:
3791 ath10k_hif_power_down(ar);
3792
3793err_off:
3794 ar->state = ATH10K_STATE_OFF;
3795
3796err:
Michal Kazior548db542013-07-05 16:15:15 +03003797 mutex_unlock(&ar->conf_mutex);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01003798 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003799}
3800
3801static void ath10k_stop(struct ieee80211_hw *hw)
3802{
3803 struct ath10k *ar = hw->priv;
3804
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003805 ath10k_drain_tx(ar);
3806
Michal Kazior548db542013-07-05 16:15:15 +03003807 mutex_lock(&ar->conf_mutex);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003808 if (ar->state != ATH10K_STATE_OFF) {
Michal Kazior818bdd12013-07-16 09:38:57 +02003809 ath10k_halt(ar);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003810 ar->state = ATH10K_STATE_OFF;
3811 }
Michal Kazior548db542013-07-05 16:15:15 +03003812 mutex_unlock(&ar->conf_mutex);
3813
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003814 cancel_delayed_work_sync(&ar->scan.timeout);
Michal Kazioraffd3212013-07-16 09:54:35 +02003815 cancel_work_sync(&ar->restart_work);
3816}
3817
Michal Kaziorad088bf2013-10-16 15:44:46 +03003818static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02003819{
Michal Kaziorad088bf2013-10-16 15:44:46 +03003820 struct ath10k_vif *arvif;
3821 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02003822
3823 lockdep_assert_held(&ar->conf_mutex);
3824
Michal Kaziorad088bf2013-10-16 15:44:46 +03003825 list_for_each_entry(arvif, &ar->arvifs, list) {
3826 ret = ath10k_mac_vif_setup_ps(arvif);
3827 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003828 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03003829 break;
3830 }
3831 }
Michal Kazioraffd3212013-07-16 09:54:35 +02003832
Michal Kaziorad088bf2013-10-16 15:44:46 +03003833 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003834}
3835
Michal Kazior500ff9f2015-03-31 10:26:21 +00003836static void ath10k_mac_chan_reconfigure(struct ath10k *ar)
Michal Kaziorc930f742014-01-23 11:38:25 +01003837{
3838 struct ath10k_vif *arvif;
Michal Kazior500ff9f2015-03-31 10:26:21 +00003839 struct cfg80211_chan_def def;
Michal Kaziorc930f742014-01-23 11:38:25 +01003840 int ret;
3841
3842 lockdep_assert_held(&ar->conf_mutex);
3843
Michal Kazior500ff9f2015-03-31 10:26:21 +00003844 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac chan reconfigure\n");
Michal Kaziorc930f742014-01-23 11:38:25 +01003845
3846 /* First stop monitor interface. Some FW versions crash if there's a
3847 * lone monitor interface. */
Michal Kazior1bbc0972014-04-08 09:45:47 +03003848 if (ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02003849 ath10k_monitor_stop(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003850
3851 list_for_each_entry(arvif, &ar->arvifs, list) {
3852 if (!arvif->is_started)
3853 continue;
3854
Michal Kaziordc55e302014-07-29 12:53:36 +03003855 if (!arvif->is_up)
3856 continue;
3857
Michal Kaziorc930f742014-01-23 11:38:25 +01003858 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3859 continue;
3860
Michal Kaziordc55e302014-07-29 12:53:36 +03003861 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kaziorc930f742014-01-23 11:38:25 +01003862 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003863 ath10k_warn(ar, "failed to down vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003864 arvif->vdev_id, ret);
3865 continue;
3866 }
3867 }
3868
Michal Kaziordc55e302014-07-29 12:53:36 +03003869 /* all vdevs are downed now - attempt to restart and re-up them */
Michal Kaziorc930f742014-01-23 11:38:25 +01003870
3871 list_for_each_entry(arvif, &ar->arvifs, list) {
3872 if (!arvif->is_started)
3873 continue;
3874
3875 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3876 continue;
3877
Michal Kazior81a9a172015-03-05 16:02:17 +02003878 ret = ath10k_mac_setup_bcn_tmpl(arvif);
3879 if (ret)
3880 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
3881 ret);
3882
3883 ret = ath10k_mac_setup_prb_tmpl(arvif);
3884 if (ret)
3885 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
3886 ret);
3887
Michal Kazior500ff9f2015-03-31 10:26:21 +00003888 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
3889 continue;
3890
3891 ret = ath10k_vdev_restart(arvif, &def);
Michal Kaziorc930f742014-01-23 11:38:25 +01003892 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003893 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003894 arvif->vdev_id, ret);
3895 continue;
3896 }
3897
3898 if (!arvif->is_up)
3899 continue;
3900
3901 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
3902 arvif->bssid);
3903 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003904 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003905 arvif->vdev_id, ret);
3906 continue;
3907 }
3908 }
3909
Michal Kazior19337472014-08-28 12:58:16 +02003910 ath10k_monitor_recalc(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003911}
3912
Michal Kazior7d9d5582014-10-21 10:40:15 +03003913static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
3914{
3915 int ret;
3916 u32 param;
3917
3918 lockdep_assert_held(&ar->conf_mutex);
3919
3920 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
3921
3922 param = ar->wmi.pdev_param->txpower_limit2g;
3923 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3924 if (ret) {
3925 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
3926 txpower, ret);
3927 return ret;
3928 }
3929
3930 param = ar->wmi.pdev_param->txpower_limit5g;
3931 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3932 if (ret) {
3933 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
3934 txpower, ret);
3935 return ret;
3936 }
3937
3938 return 0;
3939}
3940
3941static int ath10k_mac_txpower_recalc(struct ath10k *ar)
3942{
3943 struct ath10k_vif *arvif;
3944 int ret, txpower = -1;
3945
3946 lockdep_assert_held(&ar->conf_mutex);
3947
3948 list_for_each_entry(arvif, &ar->arvifs, list) {
3949 WARN_ON(arvif->txpower < 0);
3950
3951 if (txpower == -1)
3952 txpower = arvif->txpower;
3953 else
3954 txpower = min(txpower, arvif->txpower);
3955 }
3956
3957 if (WARN_ON(txpower == -1))
3958 return -EINVAL;
3959
3960 ret = ath10k_mac_txpower_setup(ar, txpower);
3961 if (ret) {
3962 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
3963 txpower, ret);
3964 return ret;
3965 }
3966
3967 return 0;
3968}
3969
Kalle Valo5e3dd152013-06-12 20:52:10 +03003970static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
3971{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003972 struct ath10k *ar = hw->priv;
3973 struct ieee80211_conf *conf = &hw->conf;
3974 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003975
3976 mutex_lock(&ar->conf_mutex);
3977
Michal Kazioraffd3212013-07-16 09:54:35 +02003978 if (changed & IEEE80211_CONF_CHANGE_PS)
3979 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003980
3981 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
Michal Kazior19337472014-08-28 12:58:16 +02003982 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
3983 ret = ath10k_monitor_recalc(ar);
3984 if (ret)
3985 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003986 }
3987
3988 mutex_unlock(&ar->conf_mutex);
3989 return ret;
3990}
3991
Ben Greear5572a952014-11-24 16:22:10 +02003992static u32 get_nss_from_chainmask(u16 chain_mask)
3993{
3994 if ((chain_mask & 0x15) == 0x15)
3995 return 4;
3996 else if ((chain_mask & 0x7) == 0x7)
3997 return 3;
3998 else if ((chain_mask & 0x3) == 0x3)
3999 return 2;
4000 return 1;
4001}
4002
Kalle Valo5e3dd152013-06-12 20:52:10 +03004003/*
4004 * TODO:
4005 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
4006 * because we will send mgmt frames without CCK. This requirement
4007 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
4008 * in the TX packet.
4009 */
4010static int ath10k_add_interface(struct ieee80211_hw *hw,
4011 struct ieee80211_vif *vif)
4012{
4013 struct ath10k *ar = hw->priv;
4014 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4015 enum wmi_sta_powersave_param param;
4016 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02004017 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004018 int bit;
Michal Kazior96d828d2015-03-31 10:26:23 +00004019 int i;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004020 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004021
Johannes Berg848955c2014-11-11 12:48:42 +01004022 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
4023
Kalle Valo5e3dd152013-06-12 20:52:10 +03004024 mutex_lock(&ar->conf_mutex);
4025
Michal Kazior0dbd09e2013-07-31 10:55:14 +02004026 memset(arvif, 0, sizeof(*arvif));
4027
Kalle Valo5e3dd152013-06-12 20:52:10 +03004028 arvif->ar = ar;
4029 arvif->vif = vif;
4030
Ben Greeare63b33f2013-10-22 14:54:14 -07004031 INIT_LIST_HEAD(&arvif->list);
Michal Kazior81a9a172015-03-05 16:02:17 +02004032 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
Michal Kaziorcc9904e2015-03-10 16:22:01 +02004033 INIT_DELAYED_WORK(&arvif->connection_loss_work,
4034 ath10k_mac_vif_sta_connection_loss_work);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03004035
Ben Greeara9aefb32014-08-12 11:02:19 +03004036 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004037 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03004038 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03004039 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004040 }
Ben Greear16c11172014-09-23 14:17:16 -07004041 bit = __ffs64(ar->free_vdev_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004042
Ben Greear16c11172014-09-23 14:17:16 -07004043 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
4044 bit, ar->free_vdev_map);
4045
4046 arvif->vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004047 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004048
Kalle Valo5e3dd152013-06-12 20:52:10 +03004049 switch (vif->type) {
Michal Kazior75d2bd42014-12-12 12:41:39 +01004050 case NL80211_IFTYPE_P2P_DEVICE:
4051 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4052 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
4053 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004054 case NL80211_IFTYPE_UNSPECIFIED:
4055 case NL80211_IFTYPE_STATION:
4056 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4057 if (vif->p2p)
4058 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
4059 break;
4060 case NL80211_IFTYPE_ADHOC:
4061 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
4062 break;
4063 case NL80211_IFTYPE_AP:
4064 arvif->vdev_type = WMI_VDEV_TYPE_AP;
4065
4066 if (vif->p2p)
4067 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
4068 break;
4069 case NL80211_IFTYPE_MONITOR:
4070 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
4071 break;
4072 default:
4073 WARN_ON(1);
4074 break;
4075 }
4076
Michal Kazior96d828d2015-03-31 10:26:23 +00004077 /* Using vdev_id as queue number will make it very easy to do per-vif
4078 * tx queue locking. This shouldn't wrap due to interface combinations
4079 * but do a modulo for correctness sake and prevent using offchannel tx
4080 * queues for regular vif tx.
4081 */
4082 vif->cab_queue = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
4083 for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++)
4084 vif->hw_queue[i] = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
4085
Michal Kazior64badcb2014-09-18 11:18:02 +03004086 /* Some firmware revisions don't wait for beacon tx completion before
4087 * sending another SWBA event. This could lead to hardware using old
4088 * (freed) beacon data in some cases, e.g. tx credit starvation
4089 * combined with missed TBTT. This is very very rare.
4090 *
4091 * On non-IOMMU-enabled hosts this could be a possible security issue
4092 * because hw could beacon some random data on the air. On
4093 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
4094 * device would crash.
4095 *
4096 * Since there are no beacon tx completions (implicit nor explicit)
4097 * propagated to host the only workaround for this is to allocate a
4098 * DMA-coherent buffer for a lifetime of a vif and use it for all
4099 * beacon tx commands. Worst case for this approach is some beacons may
4100 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
4101 */
4102 if (vif->type == NL80211_IFTYPE_ADHOC ||
4103 vif->type == NL80211_IFTYPE_AP) {
4104 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
4105 IEEE80211_MAX_FRAME_LEN,
4106 &arvif->beacon_paddr,
Rajkumar Manoharan82d7aba2014-10-10 17:38:27 +05304107 GFP_ATOMIC);
Michal Kazior64badcb2014-09-18 11:18:02 +03004108 if (!arvif->beacon_buf) {
4109 ret = -ENOMEM;
4110 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
4111 ret);
4112 goto err;
4113 }
4114 }
4115
4116 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
4117 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
4118 arvif->beacon_buf ? "single-buf" : "per-skb");
Kalle Valo5e3dd152013-06-12 20:52:10 +03004119
4120 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
4121 arvif->vdev_subtype, vif->addr);
4122 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004123 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004124 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004125 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004126 }
4127
Ben Greear16c11172014-09-23 14:17:16 -07004128 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03004129 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004130
Michal Kazior46725b152015-01-28 09:57:49 +02004131 /* It makes no sense to have firmware do keepalives. mac80211 already
4132 * takes care of this with idle connection polling.
4133 */
4134 ret = ath10k_mac_vif_disable_keepalive(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004135 if (ret) {
Michal Kazior46725b152015-01-28 09:57:49 +02004136 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004137 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004138 goto err_vdev_delete;
4139 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004140
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004141 arvif->def_wep_key_idx = -1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004142
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004143 vdev_param = ar->wmi.vdev_param->tx_encap_type;
4144 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004145 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02004146 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14a2013-10-16 15:44:45 +03004147 if (ret && ret != -EOPNOTSUPP) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004148 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004149 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004150 goto err_vdev_delete;
4151 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004152
Ben Greear5572a952014-11-24 16:22:10 +02004153 if (ar->cfg_tx_chainmask) {
4154 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
4155
4156 vdev_param = ar->wmi.vdev_param->nss;
4157 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4158 nss);
4159 if (ret) {
4160 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
4161 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
4162 ret);
4163 goto err_vdev_delete;
4164 }
4165 }
4166
Kalle Valo5e3dd152013-06-12 20:52:10 +03004167 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
Marek Puzyniak7390ed32015-03-30 09:51:52 +03004168 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr,
4169 WMI_PEER_TYPE_DEFAULT);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004170 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004171 ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004172 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004173 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004174 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01004175
Kalle Valo5a13e762014-01-20 11:01:46 +02004176 ret = ath10k_mac_set_kickout(arvif);
4177 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004178 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004179 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +02004180 goto err_peer_delete;
4181 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004182 }
4183
4184 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
4185 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
4186 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4187 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4188 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004189 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004190 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004191 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004192 goto err_peer_delete;
4193 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004194
Michal Kazior9f9b5742014-12-12 12:41:36 +01004195 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004196 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01004197 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004198 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004199 goto err_peer_delete;
4200 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004201
Michal Kazior9f9b5742014-12-12 12:41:36 +01004202 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004203 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01004204 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004205 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004206 goto err_peer_delete;
4207 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004208 }
4209
Michal Kazior424121c2013-07-22 14:13:31 +02004210 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004211 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004212 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03004213 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004214 goto err_peer_delete;
4215 }
Michal Kazior679c54a2013-07-05 16:15:04 +03004216
Michal Kazior424121c2013-07-22 14:13:31 +02004217 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004218 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004219 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03004220 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004221 goto err_peer_delete;
4222 }
Michal Kazior679c54a2013-07-05 16:15:04 +03004223
Michal Kazior7d9d5582014-10-21 10:40:15 +03004224 arvif->txpower = vif->bss_conf.txpower;
4225 ret = ath10k_mac_txpower_recalc(ar);
4226 if (ret) {
4227 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
4228 goto err_peer_delete;
4229 }
4230
Michal Kazior500ff9f2015-03-31 10:26:21 +00004231 if (vif->type == NL80211_IFTYPE_MONITOR) {
4232 ar->monitor_arvif = arvif;
4233 ret = ath10k_monitor_recalc(ar);
4234 if (ret) {
4235 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4236 goto err_peer_delete;
4237 }
4238 }
4239
Kalle Valo5e3dd152013-06-12 20:52:10 +03004240 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004241 return 0;
4242
4243err_peer_delete:
4244 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
4245 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
4246
4247err_vdev_delete:
4248 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
Ben Greear16c11172014-09-23 14:17:16 -07004249 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03004250 list_del(&arvif->list);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004251
4252err:
Michal Kazior64badcb2014-09-18 11:18:02 +03004253 if (arvif->beacon_buf) {
4254 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
4255 arvif->beacon_buf, arvif->beacon_paddr);
4256 arvif->beacon_buf = NULL;
4257 }
4258
Michal Kazior9dad14a2013-10-16 15:44:45 +03004259 mutex_unlock(&ar->conf_mutex);
4260
Kalle Valo5e3dd152013-06-12 20:52:10 +03004261 return ret;
4262}
4263
Michal Kaziorb4aa5392015-03-31 10:26:24 +00004264static void ath10k_mac_vif_tx_unlock_all(struct ath10k_vif *arvif)
4265{
4266 int i;
4267
4268 for (i = 0; i < BITS_PER_LONG; i++)
4269 ath10k_mac_vif_tx_unlock(arvif, i);
4270}
4271
Kalle Valo5e3dd152013-06-12 20:52:10 +03004272static void ath10k_remove_interface(struct ieee80211_hw *hw,
4273 struct ieee80211_vif *vif)
4274{
4275 struct ath10k *ar = hw->priv;
4276 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4277 int ret;
4278
Michal Kazior81a9a172015-03-05 16:02:17 +02004279 cancel_work_sync(&arvif->ap_csa_work);
Michal Kaziorcc9904e2015-03-10 16:22:01 +02004280 cancel_delayed_work_sync(&arvif->connection_loss_work);
Michal Kazior81a9a172015-03-05 16:02:17 +02004281
Sujith Manoharan5d011f52014-11-25 11:47:00 +05304282 mutex_lock(&ar->conf_mutex);
4283
Michal Kaziored543882013-09-13 14:16:56 +02004284 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03004285 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kaziored543882013-09-13 14:16:56 +02004286 spin_unlock_bh(&ar->data_lock);
4287
Simon Wunderlich855aed12014-08-02 09:12:54 +03004288 ret = ath10k_spectral_vif_stop(arvif);
4289 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004290 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03004291 arvif->vdev_id, ret);
4292
Ben Greear16c11172014-09-23 14:17:16 -07004293 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03004294 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004295
4296 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
Michal Kazior2c512052015-02-15 16:50:40 +02004297 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
4298 vif->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004299 if (ret)
Michal Kazior2c512052015-02-15 16:50:40 +02004300 ath10k_warn(ar, "failed to submit AP self-peer removal on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004301 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004302
4303 kfree(arvif->u.ap.noa_data);
4304 }
4305
Michal Kazior7aa7a722014-08-25 12:09:38 +02004306 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004307 arvif->vdev_id);
4308
Kalle Valo5e3dd152013-06-12 20:52:10 +03004309 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
4310 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004311 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004312 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004313
Michal Kazior2c512052015-02-15 16:50:40 +02004314 /* Some firmware revisions don't notify host about self-peer removal
4315 * until after associated vdev is deleted.
4316 */
4317 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
4318 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
4319 vif->addr);
4320 if (ret)
4321 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
4322 arvif->vdev_id, ret);
4323
4324 spin_lock_bh(&ar->data_lock);
4325 ar->num_peers--;
4326 spin_unlock_bh(&ar->data_lock);
4327 }
4328
Kalle Valo5e3dd152013-06-12 20:52:10 +03004329 ath10k_peer_cleanup(ar, arvif->vdev_id);
4330
Michal Kazior500ff9f2015-03-31 10:26:21 +00004331 if (vif->type == NL80211_IFTYPE_MONITOR) {
4332 ar->monitor_arvif = NULL;
4333 ret = ath10k_monitor_recalc(ar);
4334 if (ret)
4335 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4336 }
4337
Michal Kaziorb4aa5392015-03-31 10:26:24 +00004338 spin_lock_bh(&ar->htt.tx_lock);
4339 ath10k_mac_vif_tx_unlock_all(arvif);
4340 spin_unlock_bh(&ar->htt.tx_lock);
4341
Kalle Valo5e3dd152013-06-12 20:52:10 +03004342 mutex_unlock(&ar->conf_mutex);
4343}
4344
4345/*
4346 * FIXME: Has to be verified.
4347 */
4348#define SUPPORTED_FILTERS \
4349 (FIF_PROMISC_IN_BSS | \
4350 FIF_ALLMULTI | \
4351 FIF_CONTROL | \
4352 FIF_PSPOLL | \
4353 FIF_OTHER_BSS | \
4354 FIF_BCN_PRBRESP_PROMISC | \
4355 FIF_PROBE_REQ | \
4356 FIF_FCSFAIL)
4357
4358static void ath10k_configure_filter(struct ieee80211_hw *hw,
4359 unsigned int changed_flags,
4360 unsigned int *total_flags,
4361 u64 multicast)
4362{
4363 struct ath10k *ar = hw->priv;
4364 int ret;
4365
4366 mutex_lock(&ar->conf_mutex);
4367
4368 changed_flags &= SUPPORTED_FILTERS;
4369 *total_flags &= SUPPORTED_FILTERS;
4370 ar->filter_flags = *total_flags;
4371
Michal Kazior19337472014-08-28 12:58:16 +02004372 ret = ath10k_monitor_recalc(ar);
4373 if (ret)
4374 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004375
4376 mutex_unlock(&ar->conf_mutex);
4377}
4378
4379static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
4380 struct ieee80211_vif *vif,
4381 struct ieee80211_bss_conf *info,
4382 u32 changed)
4383{
4384 struct ath10k *ar = hw->priv;
4385 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4386 int ret = 0;
Kalle Valoaf762c02014-09-14 12:50:17 +03004387 u32 vdev_param, pdev_param, slottime, preamble;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004388
4389 mutex_lock(&ar->conf_mutex);
4390
4391 if (changed & BSS_CHANGED_IBSS)
4392 ath10k_control_ibss(arvif, info, vif->addr);
4393
4394 if (changed & BSS_CHANGED_BEACON_INT) {
4395 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004396 vdev_param = ar->wmi.vdev_param->beacon_interval;
4397 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004398 arvif->beacon_interval);
Michal Kazior7aa7a722014-08-25 12:09:38 +02004399 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004400 "mac vdev %d beacon_interval %d\n",
4401 arvif->vdev_id, arvif->beacon_interval);
4402
Kalle Valo5e3dd152013-06-12 20:52:10 +03004403 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004404 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004405 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004406 }
4407
4408 if (changed & BSS_CHANGED_BEACON) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004409 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004410 "vdev %d set beacon tx mode to staggered\n",
4411 arvif->vdev_id);
4412
Bartosz Markowski226a3392013-09-26 17:47:16 +02004413 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
4414 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004415 WMI_BEACON_STAGGERED_MODE);
4416 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004417 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004418 arvif->vdev_id, ret);
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02004419
4420 ret = ath10k_mac_setup_bcn_tmpl(arvif);
4421 if (ret)
4422 ath10k_warn(ar, "failed to update beacon template: %d\n",
4423 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004424 }
4425
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02004426 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
4427 ret = ath10k_mac_setup_prb_tmpl(arvif);
4428 if (ret)
4429 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
4430 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004431 }
4432
Michal Kaziorba2479f2015-01-24 12:14:51 +02004433 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004434 arvif->dtim_period = info->dtim_period;
4435
Michal Kazior7aa7a722014-08-25 12:09:38 +02004436 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004437 "mac vdev %d dtim_period %d\n",
4438 arvif->vdev_id, arvif->dtim_period);
4439
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004440 vdev_param = ar->wmi.vdev_param->dtim_period;
4441 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004442 arvif->dtim_period);
4443 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004444 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004445 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004446 }
4447
4448 if (changed & BSS_CHANGED_SSID &&
4449 vif->type == NL80211_IFTYPE_AP) {
4450 arvif->u.ap.ssid_len = info->ssid_len;
4451 if (info->ssid_len)
4452 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
4453 arvif->u.ap.hidden_ssid = info->hidden_ssid;
4454 }
4455
Michal Kazior077efc82014-10-21 10:10:29 +03004456 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
4457 ether_addr_copy(arvif->bssid, info->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004458
4459 if (changed & BSS_CHANGED_BEACON_ENABLED)
4460 ath10k_control_beaconing(arvif, info);
4461
4462 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02004463 arvif->use_cts_prot = info->use_cts_prot;
Michal Kazior7aa7a722014-08-25 12:09:38 +02004464 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02004465 arvif->vdev_id, info->use_cts_prot);
Kalle Valo60c3daa2013-09-08 17:56:07 +03004466
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02004467 ret = ath10k_recalc_rtscts_prot(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004468 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004469 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004470 arvif->vdev_id, ret);
Michal Kaziora87fd4b2015-03-02 11:21:17 +01004471
4472 vdev_param = ar->wmi.vdev_param->protection_mode;
4473 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4474 info->use_cts_prot ? 1 : 0);
4475 if (ret)
4476 ath10k_warn(ar, "failed to set protection mode %d on vdev %i: %d\n",
4477 info->use_cts_prot, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004478 }
4479
4480 if (changed & BSS_CHANGED_ERP_SLOT) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004481 if (info->use_short_slot)
4482 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
4483
4484 else
4485 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
4486
Michal Kazior7aa7a722014-08-25 12:09:38 +02004487 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004488 arvif->vdev_id, slottime);
4489
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004490 vdev_param = ar->wmi.vdev_param->slot_time;
4491 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004492 slottime);
4493 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004494 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004495 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004496 }
4497
4498 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004499 if (info->use_short_preamble)
4500 preamble = WMI_VDEV_PREAMBLE_SHORT;
4501 else
4502 preamble = WMI_VDEV_PREAMBLE_LONG;
4503
Michal Kazior7aa7a722014-08-25 12:09:38 +02004504 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004505 "mac vdev %d preamble %dn",
4506 arvif->vdev_id, preamble);
4507
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004508 vdev_param = ar->wmi.vdev_param->preamble;
4509 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004510 preamble);
4511 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004512 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004513 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004514 }
4515
4516 if (changed & BSS_CHANGED_ASSOC) {
Michal Kaziore556f112014-08-28 12:58:17 +02004517 if (info->assoc) {
4518 /* Workaround: Make sure monitor vdev is not running
4519 * when associating to prevent some firmware revisions
4520 * (e.g. 10.1 and 10.2) from crashing.
4521 */
4522 if (ar->monitor_started)
4523 ath10k_monitor_stop(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004524 ath10k_bss_assoc(hw, vif, info);
Michal Kaziore556f112014-08-28 12:58:17 +02004525 ath10k_monitor_recalc(ar);
Michal Kazior077efc82014-10-21 10:10:29 +03004526 } else {
4527 ath10k_bss_disassoc(hw, vif);
Michal Kaziore556f112014-08-28 12:58:17 +02004528 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004529 }
4530
Michal Kazior7d9d5582014-10-21 10:40:15 +03004531 if (changed & BSS_CHANGED_TXPOWER) {
4532 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
4533 arvif->vdev_id, info->txpower);
4534
4535 arvif->txpower = info->txpower;
4536 ret = ath10k_mac_txpower_recalc(ar);
4537 if (ret)
4538 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
4539 }
4540
Michal Kaziorbf14e652014-12-12 12:41:38 +01004541 if (changed & BSS_CHANGED_PS) {
Michal Kaziorcffb41f2015-02-13 13:30:16 +01004542 arvif->ps = vif->bss_conf.ps;
4543
4544 ret = ath10k_config_ps(ar);
Michal Kaziorbf14e652014-12-12 12:41:38 +01004545 if (ret)
4546 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
4547 arvif->vdev_id, ret);
4548 }
4549
Kalle Valo5e3dd152013-06-12 20:52:10 +03004550 mutex_unlock(&ar->conf_mutex);
4551}
4552
4553static int ath10k_hw_scan(struct ieee80211_hw *hw,
4554 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02004555 struct ieee80211_scan_request *hw_req)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004556{
4557 struct ath10k *ar = hw->priv;
4558 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
David Spinadelc56ef672014-02-05 15:21:13 +02004559 struct cfg80211_scan_request *req = &hw_req->req;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004560 struct wmi_start_scan_arg arg;
4561 int ret = 0;
4562 int i;
4563
4564 mutex_lock(&ar->conf_mutex);
4565
4566 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004567 switch (ar->scan.state) {
4568 case ATH10K_SCAN_IDLE:
4569 reinit_completion(&ar->scan.started);
4570 reinit_completion(&ar->scan.completed);
4571 ar->scan.state = ATH10K_SCAN_STARTING;
4572 ar->scan.is_roc = false;
4573 ar->scan.vdev_id = arvif->vdev_id;
4574 ret = 0;
4575 break;
4576 case ATH10K_SCAN_STARTING:
4577 case ATH10K_SCAN_RUNNING:
4578 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004579 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004580 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004581 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004582 spin_unlock_bh(&ar->data_lock);
4583
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004584 if (ret)
4585 goto exit;
4586
Kalle Valo5e3dd152013-06-12 20:52:10 +03004587 memset(&arg, 0, sizeof(arg));
4588 ath10k_wmi_start_scan_init(ar, &arg);
4589 arg.vdev_id = arvif->vdev_id;
4590 arg.scan_id = ATH10K_SCAN_ID;
4591
4592 if (!req->no_cck)
4593 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
4594
4595 if (req->ie_len) {
4596 arg.ie_len = req->ie_len;
4597 memcpy(arg.ie, req->ie, arg.ie_len);
4598 }
4599
4600 if (req->n_ssids) {
4601 arg.n_ssids = req->n_ssids;
4602 for (i = 0; i < arg.n_ssids; i++) {
4603 arg.ssids[i].len = req->ssids[i].ssid_len;
4604 arg.ssids[i].ssid = req->ssids[i].ssid;
4605 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02004606 } else {
4607 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004608 }
4609
4610 if (req->n_channels) {
4611 arg.n_channels = req->n_channels;
4612 for (i = 0; i < arg.n_channels; i++)
4613 arg.channels[i] = req->channels[i]->center_freq;
4614 }
4615
4616 ret = ath10k_start_scan(ar, &arg);
4617 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004618 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004619 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004620 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004621 spin_unlock_bh(&ar->data_lock);
4622 }
4623
4624exit:
4625 mutex_unlock(&ar->conf_mutex);
4626 return ret;
4627}
4628
4629static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
4630 struct ieee80211_vif *vif)
4631{
4632 struct ath10k *ar = hw->priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004633
4634 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004635 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004636 mutex_unlock(&ar->conf_mutex);
Michal Kazior4eb2e162014-10-28 10:23:09 +01004637
4638 cancel_delayed_work_sync(&ar->scan.timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004639}
4640
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004641static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
4642 struct ath10k_vif *arvif,
4643 enum set_key_cmd cmd,
4644 struct ieee80211_key_conf *key)
4645{
4646 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
4647 int ret;
4648
4649 /* 10.1 firmware branch requires default key index to be set to group
4650 * key index after installing it. Otherwise FW/HW Txes corrupted
4651 * frames with multi-vif APs. This is not required for main firmware
4652 * branch (e.g. 636).
4653 *
4654 * FIXME: This has been tested only in AP. It remains unknown if this
4655 * is required for multi-vif STA interfaces on 10.1 */
4656
4657 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
4658 return;
4659
4660 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
4661 return;
4662
4663 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
4664 return;
4665
4666 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4667 return;
4668
4669 if (cmd != SET_KEY)
4670 return;
4671
4672 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4673 key->keyidx);
4674 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004675 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004676 arvif->vdev_id, ret);
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004677}
4678
Kalle Valo5e3dd152013-06-12 20:52:10 +03004679static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
4680 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
4681 struct ieee80211_key_conf *key)
4682{
4683 struct ath10k *ar = hw->priv;
4684 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4685 struct ath10k_peer *peer;
4686 const u8 *peer_addr;
4687 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
4688 key->cipher == WLAN_CIPHER_SUITE_WEP104;
4689 int ret = 0;
Michal Kazior370e5672015-02-18 14:02:26 +01004690 u32 flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004691
Bartosz Markowskid7131c02015-03-10 14:32:19 +01004692 /* this one needs to be done in software */
4693 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
4694 return 1;
4695
Kalle Valo5e3dd152013-06-12 20:52:10 +03004696 if (key->keyidx > WMI_MAX_KEY_INDEX)
4697 return -ENOSPC;
4698
4699 mutex_lock(&ar->conf_mutex);
4700
4701 if (sta)
4702 peer_addr = sta->addr;
4703 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
4704 peer_addr = vif->bss_conf.bssid;
4705 else
4706 peer_addr = vif->addr;
4707
4708 key->hw_key_idx = key->keyidx;
4709
4710 /* the peer should not disappear in mid-way (unless FW goes awry) since
4711 * we already hold conf_mutex. we just make sure its there now. */
4712 spin_lock_bh(&ar->data_lock);
4713 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4714 spin_unlock_bh(&ar->data_lock);
4715
4716 if (!peer) {
4717 if (cmd == SET_KEY) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004718 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03004719 peer_addr);
4720 ret = -EOPNOTSUPP;
4721 goto exit;
4722 } else {
4723 /* if the peer doesn't exist there is no key to disable
4724 * anymore */
4725 goto exit;
4726 }
4727 }
4728
Michal Kazior7cc45732015-03-09 14:24:17 +01004729 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4730 flags |= WMI_KEY_PAIRWISE;
4731 else
4732 flags |= WMI_KEY_GROUP;
4733
Kalle Valo5e3dd152013-06-12 20:52:10 +03004734 if (is_wep) {
4735 if (cmd == SET_KEY)
4736 arvif->wep_keys[key->keyidx] = key;
4737 else
4738 arvif->wep_keys[key->keyidx] = NULL;
4739
4740 if (cmd == DISABLE_KEY)
4741 ath10k_clear_vdev_key(arvif, key);
Michal Kazior370e5672015-02-18 14:02:26 +01004742
Michal Kaziorad325cb2015-02-18 14:02:27 +01004743 /* When WEP keys are uploaded it's possible that there are
4744 * stations associated already (e.g. when merging) without any
4745 * keys. Static WEP needs an explicit per-peer key upload.
4746 */
4747 if (vif->type == NL80211_IFTYPE_ADHOC &&
4748 cmd == SET_KEY)
4749 ath10k_mac_vif_update_wep_key(arvif, key);
4750
Michal Kazior370e5672015-02-18 14:02:26 +01004751 /* 802.1x never sets the def_wep_key_idx so each set_key()
4752 * call changes default tx key.
4753 *
4754 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
4755 * after first set_key().
4756 */
4757 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
4758 flags |= WMI_KEY_TX_USAGE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004759
Michal Kazior7cc45732015-03-09 14:24:17 +01004760 /* mac80211 uploads static WEP keys as groupwise while fw/hw
4761 * requires pairwise keys for non-self peers, i.e. BSSID in STA
4762 * mode and associated stations in AP/IBSS.
4763 *
4764 * Static WEP keys for peer_addr=vif->addr and 802.1X WEP keys
4765 * work fine when mapped directly from mac80211.
4766 *
4767 * Note: When installing first static WEP groupwise key (which
4768 * should be pairwise) def_wep_key_idx isn't known yet (it's
4769 * equal to -1). Since .set_default_unicast_key is called only
4770 * for static WEP it's used to re-upload the key as pairwise.
4771 */
4772 if (arvif->def_wep_key_idx >= 0 &&
4773 memcmp(peer_addr, arvif->vif->addr, ETH_ALEN)) {
4774 flags &= ~WMI_KEY_GROUP;
4775 flags |= WMI_KEY_PAIRWISE;
4776 }
Michal Kazior370e5672015-02-18 14:02:26 +01004777 }
4778
4779 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004780 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004781 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004782 arvif->vdev_id, peer_addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004783 goto exit;
4784 }
4785
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004786 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
4787
Kalle Valo5e3dd152013-06-12 20:52:10 +03004788 spin_lock_bh(&ar->data_lock);
4789 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4790 if (peer && cmd == SET_KEY)
4791 peer->keys[key->keyidx] = key;
4792 else if (peer && cmd == DISABLE_KEY)
4793 peer->keys[key->keyidx] = NULL;
4794 else if (peer == NULL)
4795 /* impossible unless FW goes crazy */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004796 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004797 spin_unlock_bh(&ar->data_lock);
4798
4799exit:
4800 mutex_unlock(&ar->conf_mutex);
4801 return ret;
4802}
4803
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004804static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
4805 struct ieee80211_vif *vif,
4806 int keyidx)
4807{
4808 struct ath10k *ar = hw->priv;
4809 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4810 int ret;
4811
4812 mutex_lock(&arvif->ar->conf_mutex);
4813
4814 if (arvif->ar->state != ATH10K_STATE_ON)
4815 goto unlock;
4816
4817 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
4818 arvif->vdev_id, keyidx);
4819
4820 ret = ath10k_wmi_vdev_set_param(arvif->ar,
4821 arvif->vdev_id,
4822 arvif->ar->wmi.vdev_param->def_keyid,
4823 keyidx);
4824
4825 if (ret) {
4826 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
4827 arvif->vdev_id,
4828 ret);
4829 goto unlock;
4830 }
4831
4832 arvif->def_wep_key_idx = keyidx;
Michal Kazior370e5672015-02-18 14:02:26 +01004833
4834 ret = ath10k_mac_vif_sta_fix_wep_key(arvif);
4835 if (ret) {
4836 ath10k_warn(ar, "failed to fix sta wep key on vdev %i: %d\n",
4837 arvif->vdev_id, ret);
4838 goto unlock;
4839 }
4840
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004841unlock:
4842 mutex_unlock(&arvif->ar->conf_mutex);
4843}
4844
Michal Kazior9797feb2014-02-14 14:49:48 +01004845static void ath10k_sta_rc_update_wk(struct work_struct *wk)
4846{
4847 struct ath10k *ar;
4848 struct ath10k_vif *arvif;
4849 struct ath10k_sta *arsta;
4850 struct ieee80211_sta *sta;
4851 u32 changed, bw, nss, smps;
4852 int err;
4853
4854 arsta = container_of(wk, struct ath10k_sta, update_wk);
4855 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
4856 arvif = arsta->arvif;
4857 ar = arvif->ar;
4858
4859 spin_lock_bh(&ar->data_lock);
4860
4861 changed = arsta->changed;
4862 arsta->changed = 0;
4863
4864 bw = arsta->bw;
4865 nss = arsta->nss;
4866 smps = arsta->smps;
4867
4868 spin_unlock_bh(&ar->data_lock);
4869
4870 mutex_lock(&ar->conf_mutex);
4871
4872 if (changed & IEEE80211_RC_BW_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004873 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004874 sta->addr, bw);
4875
4876 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4877 WMI_PEER_CHAN_WIDTH, bw);
4878 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004879 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004880 sta->addr, bw, err);
4881 }
4882
4883 if (changed & IEEE80211_RC_NSS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004884 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004885 sta->addr, nss);
4886
4887 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4888 WMI_PEER_NSS, nss);
4889 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004890 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004891 sta->addr, nss, err);
4892 }
4893
4894 if (changed & IEEE80211_RC_SMPS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004895 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004896 sta->addr, smps);
4897
4898 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4899 WMI_PEER_SMPS_STATE, smps);
4900 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004901 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004902 sta->addr, smps, err);
4903 }
4904
Janusz Dziedzic55884c02014-12-17 12:30:02 +02004905 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
4906 changed & IEEE80211_RC_NSS_CHANGED) {
4907 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004908 sta->addr);
4909
Michal Kazior590922a2014-10-21 10:10:29 +03004910 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004911 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004912 ath10k_warn(ar, "failed to reassociate station: %pM\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004913 sta->addr);
4914 }
4915
Michal Kazior9797feb2014-02-14 14:49:48 +01004916 mutex_unlock(&ar->conf_mutex);
4917}
4918
Marek Puzyniak7c354242015-03-30 09:51:52 +03004919static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif,
4920 struct ieee80211_sta *sta)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004921{
4922 struct ath10k *ar = arvif->ar;
4923
4924 lockdep_assert_held(&ar->conf_mutex);
4925
Marek Puzyniak7c354242015-03-30 09:51:52 +03004926 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004927 return 0;
4928
4929 if (ar->num_stations >= ar->max_num_stations)
4930 return -ENOBUFS;
4931
4932 ar->num_stations++;
4933
4934 return 0;
4935}
4936
Marek Puzyniak7c354242015-03-30 09:51:52 +03004937static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif,
4938 struct ieee80211_sta *sta)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004939{
4940 struct ath10k *ar = arvif->ar;
4941
4942 lockdep_assert_held(&ar->conf_mutex);
4943
Marek Puzyniak7c354242015-03-30 09:51:52 +03004944 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004945 return;
4946
4947 ar->num_stations--;
4948}
4949
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004950struct ath10k_mac_tdls_iter_data {
4951 u32 num_tdls_stations;
4952 struct ieee80211_vif *curr_vif;
4953};
4954
4955static void ath10k_mac_tdls_vif_stations_count_iter(void *data,
4956 struct ieee80211_sta *sta)
4957{
4958 struct ath10k_mac_tdls_iter_data *iter_data = data;
4959 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
4960 struct ieee80211_vif *sta_vif = arsta->arvif->vif;
4961
4962 if (sta->tdls && sta_vif == iter_data->curr_vif)
4963 iter_data->num_tdls_stations++;
4964}
4965
4966static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw *hw,
4967 struct ieee80211_vif *vif)
4968{
4969 struct ath10k_mac_tdls_iter_data data = {};
4970
4971 data.curr_vif = vif;
4972
4973 ieee80211_iterate_stations_atomic(hw,
4974 ath10k_mac_tdls_vif_stations_count_iter,
4975 &data);
4976 return data.num_tdls_stations;
4977}
4978
4979static void ath10k_mac_tdls_vifs_count_iter(void *data, u8 *mac,
4980 struct ieee80211_vif *vif)
4981{
4982 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4983 int *num_tdls_vifs = data;
4984
4985 if (vif->type != NL80211_IFTYPE_STATION)
4986 return;
4987
4988 if (ath10k_mac_tdls_vif_stations_count(arvif->ar->hw, vif) > 0)
4989 (*num_tdls_vifs)++;
4990}
4991
4992static int ath10k_mac_tdls_vifs_count(struct ieee80211_hw *hw)
4993{
4994 int num_tdls_vifs = 0;
4995
4996 ieee80211_iterate_active_interfaces_atomic(hw,
4997 IEEE80211_IFACE_ITER_NORMAL,
4998 ath10k_mac_tdls_vifs_count_iter,
4999 &num_tdls_vifs);
5000 return num_tdls_vifs;
5001}
5002
Kalle Valo5e3dd152013-06-12 20:52:10 +03005003static int ath10k_sta_state(struct ieee80211_hw *hw,
5004 struct ieee80211_vif *vif,
5005 struct ieee80211_sta *sta,
5006 enum ieee80211_sta_state old_state,
5007 enum ieee80211_sta_state new_state)
5008{
5009 struct ath10k *ar = hw->priv;
5010 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01005011 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005012 int ret = 0;
5013
Michal Kazior76f90022014-02-25 09:29:57 +02005014 if (old_state == IEEE80211_STA_NOTEXIST &&
5015 new_state == IEEE80211_STA_NONE) {
5016 memset(arsta, 0, sizeof(*arsta));
5017 arsta->arvif = arvif;
5018 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
5019 }
5020
Michal Kazior9797feb2014-02-14 14:49:48 +01005021 /* cancel must be done outside the mutex to avoid deadlock */
5022 if ((old_state == IEEE80211_STA_NONE &&
5023 new_state == IEEE80211_STA_NOTEXIST))
5024 cancel_work_sync(&arsta->update_wk);
5025
Kalle Valo5e3dd152013-06-12 20:52:10 +03005026 mutex_lock(&ar->conf_mutex);
5027
5028 if (old_state == IEEE80211_STA_NOTEXIST &&
Michal Kazior077efc82014-10-21 10:10:29 +03005029 new_state == IEEE80211_STA_NONE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03005030 /*
5031 * New station addition.
5032 */
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005033 enum wmi_peer_type peer_type = WMI_PEER_TYPE_DEFAULT;
5034 u32 num_tdls_stations;
5035 u32 num_tdls_vifs;
5036
Michal Kaziorcfd10612014-11-25 15:16:05 +01005037 ath10k_dbg(ar, ATH10K_DBG_MAC,
5038 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
5039 arvif->vdev_id, sta->addr,
5040 ar->num_stations + 1, ar->max_num_stations,
5041 ar->num_peers + 1, ar->max_num_peers);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01005042
Marek Puzyniak7c354242015-03-30 09:51:52 +03005043 ret = ath10k_mac_inc_num_stations(arvif, sta);
Michal Kaziorcfd10612014-11-25 15:16:05 +01005044 if (ret) {
5045 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
5046 ar->max_num_stations);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01005047 goto exit;
5048 }
5049
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005050 if (sta->tdls)
5051 peer_type = WMI_PEER_TYPE_TDLS;
5052
Marek Puzyniak7390ed32015-03-30 09:51:52 +03005053 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr,
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005054 peer_type);
Michal Kaziora52c0282014-11-25 15:16:03 +01005055 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005056 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 -08005057 sta->addr, arvif->vdev_id, ret);
Marek Puzyniak7c354242015-03-30 09:51:52 +03005058 ath10k_mac_dec_num_stations(arvif, sta);
Michal Kaziora52c0282014-11-25 15:16:03 +01005059 goto exit;
5060 }
Michal Kazior077efc82014-10-21 10:10:29 +03005061
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005062 if (!sta->tdls)
5063 goto exit;
5064
5065 num_tdls_stations = ath10k_mac_tdls_vif_stations_count(hw, vif);
5066 num_tdls_vifs = ath10k_mac_tdls_vifs_count(hw);
5067
5068 if (num_tdls_vifs >= ar->max_num_tdls_vdevs &&
5069 num_tdls_stations == 0) {
5070 ath10k_warn(ar, "vdev %i exceeded maximum number of tdls vdevs %i\n",
5071 arvif->vdev_id, ar->max_num_tdls_vdevs);
5072 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5073 ath10k_mac_dec_num_stations(arvif, sta);
5074 ret = -ENOBUFS;
5075 goto exit;
5076 }
5077
5078 if (num_tdls_stations == 0) {
5079 /* This is the first tdls peer in current vif */
5080 enum wmi_tdls_state state = WMI_TDLS_ENABLE_ACTIVE;
5081
5082 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5083 state);
5084 if (ret) {
5085 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
5086 arvif->vdev_id, ret);
5087 ath10k_peer_delete(ar, arvif->vdev_id,
5088 sta->addr);
5089 ath10k_mac_dec_num_stations(arvif, sta);
5090 goto exit;
5091 }
5092 }
5093
5094 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
5095 WMI_TDLS_PEER_STATE_PEERING);
5096 if (ret) {
5097 ath10k_warn(ar,
5098 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
5099 sta->addr, arvif->vdev_id, ret);
5100 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5101 ath10k_mac_dec_num_stations(arvif, sta);
5102
5103 if (num_tdls_stations != 0)
5104 goto exit;
5105 ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5106 WMI_TDLS_DISABLE);
5107 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005108 } else if ((old_state == IEEE80211_STA_NONE &&
5109 new_state == IEEE80211_STA_NOTEXIST)) {
5110 /*
5111 * Existing station deletion.
5112 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005113 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03005114 "mac vdev %d peer delete %pM (sta gone)\n",
5115 arvif->vdev_id, sta->addr);
Michal Kazior077efc82014-10-21 10:10:29 +03005116
Kalle Valo5e3dd152013-06-12 20:52:10 +03005117 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5118 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005119 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02005120 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005121
Marek Puzyniak7c354242015-03-30 09:51:52 +03005122 ath10k_mac_dec_num_stations(arvif, sta);
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005123
5124 if (!sta->tdls)
5125 goto exit;
5126
5127 if (ath10k_mac_tdls_vif_stations_count(hw, vif))
5128 goto exit;
5129
5130 /* This was the last tdls peer in current vif */
5131 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5132 WMI_TDLS_DISABLE);
5133 if (ret) {
5134 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
5135 arvif->vdev_id, ret);
5136 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005137 } else if (old_state == IEEE80211_STA_AUTH &&
5138 new_state == IEEE80211_STA_ASSOC &&
5139 (vif->type == NL80211_IFTYPE_AP ||
5140 vif->type == NL80211_IFTYPE_ADHOC)) {
5141 /*
5142 * New association.
5143 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005144 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03005145 sta->addr);
5146
Michal Kazior590922a2014-10-21 10:10:29 +03005147 ret = ath10k_station_assoc(ar, vif, sta, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005148 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005149 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02005150 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005151 } else if (old_state == IEEE80211_STA_ASSOC &&
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005152 new_state == IEEE80211_STA_AUTHORIZED &&
5153 sta->tdls) {
5154 /*
5155 * Tdls station authorized.
5156 */
5157 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac tdls sta %pM authorized\n",
5158 sta->addr);
5159
5160 ret = ath10k_station_assoc(ar, vif, sta, false);
5161 if (ret) {
5162 ath10k_warn(ar, "failed to associate tdls station %pM for vdev %i: %i\n",
5163 sta->addr, arvif->vdev_id, ret);
5164 goto exit;
5165 }
5166
5167 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
5168 WMI_TDLS_PEER_STATE_CONNECTED);
5169 if (ret)
5170 ath10k_warn(ar, "failed to update tdls peer %pM for vdev %i: %i\n",
5171 sta->addr, arvif->vdev_id, ret);
5172 } else if (old_state == IEEE80211_STA_ASSOC &&
5173 new_state == IEEE80211_STA_AUTH &&
5174 (vif->type == NL80211_IFTYPE_AP ||
5175 vif->type == NL80211_IFTYPE_ADHOC)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03005176 /*
5177 * Disassociation.
5178 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005179 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03005180 sta->addr);
5181
Michal Kazior590922a2014-10-21 10:10:29 +03005182 ret = ath10k_station_disassoc(ar, vif, sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005183 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005184 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02005185 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005186 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01005187exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005188 mutex_unlock(&ar->conf_mutex);
5189 return ret;
5190}
5191
5192static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
Kalle Valo5b07e072014-09-14 12:50:06 +03005193 u16 ac, bool enable)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005194{
5195 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorb0e56152015-01-24 12:14:52 +02005196 struct wmi_sta_uapsd_auto_trig_arg arg = {};
5197 u32 prio = 0, acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005198 u32 value = 0;
5199 int ret = 0;
5200
Michal Kazior548db542013-07-05 16:15:15 +03005201 lockdep_assert_held(&ar->conf_mutex);
5202
Kalle Valo5e3dd152013-06-12 20:52:10 +03005203 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
5204 return 0;
5205
5206 switch (ac) {
5207 case IEEE80211_AC_VO:
5208 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
5209 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005210 prio = 7;
5211 acc = 3;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005212 break;
5213 case IEEE80211_AC_VI:
5214 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
5215 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005216 prio = 5;
5217 acc = 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005218 break;
5219 case IEEE80211_AC_BE:
5220 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
5221 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005222 prio = 2;
5223 acc = 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005224 break;
5225 case IEEE80211_AC_BK:
5226 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
5227 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005228 prio = 0;
5229 acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005230 break;
5231 }
5232
5233 if (enable)
5234 arvif->u.sta.uapsd |= value;
5235 else
5236 arvif->u.sta.uapsd &= ~value;
5237
5238 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5239 WMI_STA_PS_PARAM_UAPSD,
5240 arvif->u.sta.uapsd);
5241 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005242 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005243 goto exit;
5244 }
5245
5246 if (arvif->u.sta.uapsd)
5247 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
5248 else
5249 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
5250
5251 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5252 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
5253 value);
5254 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005255 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005256
Michal Kazior9f9b5742014-12-12 12:41:36 +01005257 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
5258 if (ret) {
5259 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
5260 arvif->vdev_id, ret);
5261 return ret;
5262 }
5263
5264 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
5265 if (ret) {
5266 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
5267 arvif->vdev_id, ret);
5268 return ret;
5269 }
5270
Michal Kaziorb0e56152015-01-24 12:14:52 +02005271 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
5272 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
5273 /* Only userspace can make an educated decision when to send
5274 * trigger frame. The following effectively disables u-UAPSD
5275 * autotrigger in firmware (which is enabled by default
5276 * provided the autotrigger service is available).
5277 */
5278
5279 arg.wmm_ac = acc;
5280 arg.user_priority = prio;
5281 arg.service_interval = 0;
5282 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
5283 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
5284
5285 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
5286 arvif->bssid, &arg, 1);
5287 if (ret) {
5288 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
5289 ret);
5290 return ret;
5291 }
5292 }
5293
Kalle Valo5e3dd152013-06-12 20:52:10 +03005294exit:
5295 return ret;
5296}
5297
5298static int ath10k_conf_tx(struct ieee80211_hw *hw,
5299 struct ieee80211_vif *vif, u16 ac,
5300 const struct ieee80211_tx_queue_params *params)
5301{
5302 struct ath10k *ar = hw->priv;
Michal Kazior5e752e42015-01-19 09:53:41 +01005303 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005304 struct wmi_wmm_params_arg *p = NULL;
5305 int ret;
5306
5307 mutex_lock(&ar->conf_mutex);
5308
5309 switch (ac) {
5310 case IEEE80211_AC_VO:
Michal Kazior5e752e42015-01-19 09:53:41 +01005311 p = &arvif->wmm_params.ac_vo;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005312 break;
5313 case IEEE80211_AC_VI:
Michal Kazior5e752e42015-01-19 09:53:41 +01005314 p = &arvif->wmm_params.ac_vi;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005315 break;
5316 case IEEE80211_AC_BE:
Michal Kazior5e752e42015-01-19 09:53:41 +01005317 p = &arvif->wmm_params.ac_be;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005318 break;
5319 case IEEE80211_AC_BK:
Michal Kazior5e752e42015-01-19 09:53:41 +01005320 p = &arvif->wmm_params.ac_bk;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005321 break;
5322 }
5323
5324 if (WARN_ON(!p)) {
5325 ret = -EINVAL;
5326 goto exit;
5327 }
5328
5329 p->cwmin = params->cw_min;
5330 p->cwmax = params->cw_max;
5331 p->aifs = params->aifs;
5332
5333 /*
5334 * The channel time duration programmed in the HW is in absolute
5335 * microseconds, while mac80211 gives the txop in units of
5336 * 32 microseconds.
5337 */
5338 p->txop = params->txop * 32;
5339
Michal Kazior7fc979a2015-01-28 09:57:28 +02005340 if (ar->wmi.ops->gen_vdev_wmm_conf) {
5341 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
5342 &arvif->wmm_params);
5343 if (ret) {
5344 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
5345 arvif->vdev_id, ret);
5346 goto exit;
5347 }
5348 } else {
5349 /* This won't work well with multi-interface cases but it's
5350 * better than nothing.
5351 */
5352 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
5353 if (ret) {
5354 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
5355 goto exit;
5356 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005357 }
5358
5359 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
5360 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005361 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005362
5363exit:
5364 mutex_unlock(&ar->conf_mutex);
5365 return ret;
5366}
5367
5368#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
5369
5370static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
5371 struct ieee80211_vif *vif,
5372 struct ieee80211_channel *chan,
5373 int duration,
5374 enum ieee80211_roc_type type)
5375{
5376 struct ath10k *ar = hw->priv;
5377 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5378 struct wmi_start_scan_arg arg;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005379 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005380
5381 mutex_lock(&ar->conf_mutex);
5382
5383 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005384 switch (ar->scan.state) {
5385 case ATH10K_SCAN_IDLE:
5386 reinit_completion(&ar->scan.started);
5387 reinit_completion(&ar->scan.completed);
5388 reinit_completion(&ar->scan.on_channel);
5389 ar->scan.state = ATH10K_SCAN_STARTING;
5390 ar->scan.is_roc = true;
5391 ar->scan.vdev_id = arvif->vdev_id;
5392 ar->scan.roc_freq = chan->center_freq;
5393 ret = 0;
5394 break;
5395 case ATH10K_SCAN_STARTING:
5396 case ATH10K_SCAN_RUNNING:
5397 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005398 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005399 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005400 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005401 spin_unlock_bh(&ar->data_lock);
5402
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005403 if (ret)
5404 goto exit;
5405
Michal Kaziordcca0bd2014-11-24 14:58:32 +01005406 duration = max(duration, WMI_SCAN_CHAN_MIN_TIME_MSEC);
5407
Kalle Valo5e3dd152013-06-12 20:52:10 +03005408 memset(&arg, 0, sizeof(arg));
5409 ath10k_wmi_start_scan_init(ar, &arg);
5410 arg.vdev_id = arvif->vdev_id;
5411 arg.scan_id = ATH10K_SCAN_ID;
5412 arg.n_channels = 1;
5413 arg.channels[0] = chan->center_freq;
5414 arg.dwell_time_active = duration;
5415 arg.dwell_time_passive = duration;
5416 arg.max_scan_time = 2 * duration;
5417 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
5418 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
5419
5420 ret = ath10k_start_scan(ar, &arg);
5421 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005422 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005423 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005424 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005425 spin_unlock_bh(&ar->data_lock);
5426 goto exit;
5427 }
5428
5429 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
5430 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005431 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005432
5433 ret = ath10k_scan_stop(ar);
5434 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005435 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005436
Kalle Valo5e3dd152013-06-12 20:52:10 +03005437 ret = -ETIMEDOUT;
5438 goto exit;
5439 }
5440
5441 ret = 0;
5442exit:
5443 mutex_unlock(&ar->conf_mutex);
5444 return ret;
5445}
5446
5447static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
5448{
5449 struct ath10k *ar = hw->priv;
5450
5451 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005452 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005453 mutex_unlock(&ar->conf_mutex);
5454
Michal Kazior4eb2e162014-10-28 10:23:09 +01005455 cancel_delayed_work_sync(&ar->scan.timeout);
5456
Kalle Valo5e3dd152013-06-12 20:52:10 +03005457 return 0;
5458}
5459
5460/*
5461 * Both RTS and Fragmentation threshold are interface-specific
5462 * in ath10k, but device-specific in mac80211.
5463 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03005464
5465static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
5466{
Kalle Valo5e3dd152013-06-12 20:52:10 +03005467 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03005468 struct ath10k_vif *arvif;
5469 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03005470
Michal Kaziorad088bf2013-10-16 15:44:46 +03005471 mutex_lock(&ar->conf_mutex);
5472 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005473 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03005474 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03005475
Michal Kaziorad088bf2013-10-16 15:44:46 +03005476 ret = ath10k_mac_set_rts(arvif, value);
5477 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005478 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03005479 arvif->vdev_id, ret);
5480 break;
5481 }
5482 }
5483 mutex_unlock(&ar->conf_mutex);
5484
5485 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005486}
5487
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02005488static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5489 u32 queues, bool drop)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005490{
5491 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02005492 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005493 int ret;
5494
5495 /* mac80211 doesn't care if we really xmit queued frames or not
5496 * we'll collect those frames either way if we stop/delete vdevs */
5497 if (drop)
5498 return;
5499
Michal Kazior548db542013-07-05 16:15:15 +03005500 mutex_lock(&ar->conf_mutex);
5501
Michal Kazioraffd3212013-07-16 09:54:35 +02005502 if (ar->state == ATH10K_STATE_WEDGED)
5503 goto skip;
5504
Michal Kazioredb82362013-07-05 16:15:14 +03005505 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03005506 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02005507
Michal Kazioredb82362013-07-05 16:15:14 +03005508 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02005509 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03005510 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02005511
Michal Kazior7962b0d2014-10-28 10:34:38 +01005512 skip = (ar->state == ATH10K_STATE_WEDGED) ||
5513 test_bit(ATH10K_FLAG_CRASH_FLUSH,
5514 &ar->dev_flags);
Michal Kazioraffd3212013-07-16 09:54:35 +02005515
5516 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005517 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02005518
5519 if (ret <= 0 || skip)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005520 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
Ben Greear9ba4c782014-02-25 09:29:57 +02005521 skip, ar->state, ret);
Michal Kazior548db542013-07-05 16:15:15 +03005522
Michal Kazioraffd3212013-07-16 09:54:35 +02005523skip:
Michal Kazior548db542013-07-05 16:15:15 +03005524 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005525}
5526
5527/* TODO: Implement this function properly
5528 * For now it is needed to reply to Probe Requests in IBSS mode.
5529 * Propably we need this information from FW.
5530 */
5531static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
5532{
5533 return 1;
5534}
5535
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005536static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
5537 enum ieee80211_reconfig_type reconfig_type)
Michal Kazioraffd3212013-07-16 09:54:35 +02005538{
5539 struct ath10k *ar = hw->priv;
5540
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005541 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
5542 return;
5543
Michal Kazioraffd3212013-07-16 09:54:35 +02005544 mutex_lock(&ar->conf_mutex);
5545
5546 /* If device failed to restart it will be in a different state, e.g.
5547 * ATH10K_STATE_WEDGED */
5548 if (ar->state == ATH10K_STATE_RESTARTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005549 ath10k_info(ar, "device successfully recovered\n");
Michal Kazioraffd3212013-07-16 09:54:35 +02005550 ar->state = ATH10K_STATE_ON;
Michal Kazior7962b0d2014-10-28 10:34:38 +01005551 ieee80211_wake_queues(ar->hw);
Michal Kazioraffd3212013-07-16 09:54:35 +02005552 }
5553
5554 mutex_unlock(&ar->conf_mutex);
5555}
5556
Michal Kazior2e1dea42013-07-31 10:32:40 +02005557static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
5558 struct survey_info *survey)
5559{
5560 struct ath10k *ar = hw->priv;
5561 struct ieee80211_supported_band *sband;
5562 struct survey_info *ar_survey = &ar->survey[idx];
5563 int ret = 0;
5564
5565 mutex_lock(&ar->conf_mutex);
5566
5567 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
5568 if (sband && idx >= sband->n_channels) {
5569 idx -= sband->n_channels;
5570 sband = NULL;
5571 }
5572
5573 if (!sband)
5574 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
5575
5576 if (!sband || idx >= sband->n_channels) {
5577 ret = -ENOENT;
5578 goto exit;
5579 }
5580
5581 spin_lock_bh(&ar->data_lock);
5582 memcpy(survey, ar_survey, sizeof(*survey));
5583 spin_unlock_bh(&ar->data_lock);
5584
5585 survey->channel = &sband->channels[idx];
5586
Felix Fietkaufa1d4df2014-10-23 17:04:28 +03005587 if (ar->rx_channel == survey->channel)
5588 survey->filled |= SURVEY_INFO_IN_USE;
5589
Michal Kazior2e1dea42013-07-31 10:32:40 +02005590exit:
5591 mutex_unlock(&ar->conf_mutex);
5592 return ret;
5593}
5594
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005595/* Check if only one bit set */
5596static int ath10k_check_single_mask(u32 mask)
5597{
5598 int bit;
5599
5600 bit = ffs(mask);
5601 if (!bit)
5602 return 0;
5603
5604 mask &= ~BIT(bit - 1);
5605 if (mask)
5606 return 2;
5607
5608 return 1;
5609}
5610
5611static bool
5612ath10k_default_bitrate_mask(struct ath10k *ar,
5613 enum ieee80211_band band,
5614 const struct cfg80211_bitrate_mask *mask)
5615{
5616 u32 legacy = 0x00ff;
5617 u8 ht = 0xff, i;
5618 u16 vht = 0x3ff;
Ben Greearb116ea12014-11-24 16:22:10 +02005619 u16 nrf = ar->num_rf_chains;
5620
5621 if (ar->cfg_tx_chainmask)
5622 nrf = get_nss_from_chainmask(ar->cfg_tx_chainmask);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005623
5624 switch (band) {
5625 case IEEE80211_BAND_2GHZ:
5626 legacy = 0x00fff;
5627 vht = 0;
5628 break;
5629 case IEEE80211_BAND_5GHZ:
5630 break;
5631 default:
5632 return false;
5633 }
5634
5635 if (mask->control[band].legacy != legacy)
5636 return false;
5637
Ben Greearb116ea12014-11-24 16:22:10 +02005638 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005639 if (mask->control[band].ht_mcs[i] != ht)
5640 return false;
5641
Ben Greearb116ea12014-11-24 16:22:10 +02005642 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005643 if (mask->control[band].vht_mcs[i] != vht)
5644 return false;
5645
5646 return true;
5647}
5648
5649static bool
5650ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
5651 enum ieee80211_band band,
5652 u8 *fixed_nss)
5653{
5654 int ht_nss = 0, vht_nss = 0, i;
5655
5656 /* check legacy */
5657 if (ath10k_check_single_mask(mask->control[band].legacy))
5658 return false;
5659
5660 /* check HT */
5661 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
5662 if (mask->control[band].ht_mcs[i] == 0xff)
5663 continue;
5664 else if (mask->control[band].ht_mcs[i] == 0x00)
5665 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03005666
5667 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005668 }
5669
5670 ht_nss = i;
5671
5672 /* check VHT */
5673 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
5674 if (mask->control[band].vht_mcs[i] == 0x03ff)
5675 continue;
5676 else if (mask->control[band].vht_mcs[i] == 0x0000)
5677 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03005678
5679 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005680 }
5681
5682 vht_nss = i;
5683
5684 if (ht_nss > 0 && vht_nss > 0)
5685 return false;
5686
5687 if (ht_nss)
5688 *fixed_nss = ht_nss;
5689 else if (vht_nss)
5690 *fixed_nss = vht_nss;
5691 else
5692 return false;
5693
5694 return true;
5695}
5696
5697static bool
5698ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
5699 enum ieee80211_band band,
5700 enum wmi_rate_preamble *preamble)
5701{
5702 int legacy = 0, ht = 0, vht = 0, i;
5703
5704 *preamble = WMI_RATE_PREAMBLE_OFDM;
5705
5706 /* check legacy */
5707 legacy = ath10k_check_single_mask(mask->control[band].legacy);
5708 if (legacy > 1)
5709 return false;
5710
5711 /* check HT */
5712 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5713 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
5714 if (ht > 1)
5715 return false;
5716
5717 /* check VHT */
5718 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
5719 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
5720 if (vht > 1)
5721 return false;
5722
5723 /* Currently we support only one fixed_rate */
5724 if ((legacy + ht + vht) != 1)
5725 return false;
5726
5727 if (ht)
5728 *preamble = WMI_RATE_PREAMBLE_HT;
5729 else if (vht)
5730 *preamble = WMI_RATE_PREAMBLE_VHT;
5731
5732 return true;
5733}
5734
5735static bool
Michal Kazior7aa7a722014-08-25 12:09:38 +02005736ath10k_bitrate_mask_rate(struct ath10k *ar,
5737 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005738 enum ieee80211_band band,
5739 u8 *fixed_rate,
5740 u8 *fixed_nss)
5741{
Michal Kazioraf001482015-03-30 09:51:56 +03005742 struct ieee80211_supported_band *sband;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005743 u8 rate = 0, pream = 0, nss = 0, i;
5744 enum wmi_rate_preamble preamble;
5745
5746 /* Check if single rate correct */
5747 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
5748 return false;
5749
5750 pream = preamble;
5751
5752 switch (preamble) {
5753 case WMI_RATE_PREAMBLE_CCK:
5754 case WMI_RATE_PREAMBLE_OFDM:
5755 i = ffs(mask->control[band].legacy) - 1;
Michal Kazioraf001482015-03-30 09:51:56 +03005756 sband = &ar->mac.sbands[band];
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005757
Michal Kazioraf001482015-03-30 09:51:56 +03005758 if (WARN_ON(i >= sband->n_bitrates))
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005759 return false;
5760
Michal Kazioraf001482015-03-30 09:51:56 +03005761 rate = sband->bitrates[i].hw_value;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005762 break;
5763 case WMI_RATE_PREAMBLE_HT:
5764 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5765 if (mask->control[band].ht_mcs[i])
5766 break;
5767
5768 if (i == IEEE80211_HT_MCS_MASK_LEN)
5769 return false;
5770
5771 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
5772 nss = i;
5773 break;
5774 case WMI_RATE_PREAMBLE_VHT:
5775 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
5776 if (mask->control[band].vht_mcs[i])
5777 break;
5778
5779 if (i == NL80211_VHT_NSS_MAX)
5780 return false;
5781
5782 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
5783 nss = i;
5784 break;
5785 }
5786
5787 *fixed_nss = nss + 1;
5788 nss <<= 4;
5789 pream <<= 6;
5790
Michal Kazior7aa7a722014-08-25 12:09:38 +02005791 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 +01005792 pream, nss, rate);
5793
5794 *fixed_rate = pream | nss | rate;
5795
5796 return true;
5797}
5798
Michal Kazior7aa7a722014-08-25 12:09:38 +02005799static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
5800 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005801 enum ieee80211_band band,
5802 u8 *fixed_rate,
5803 u8 *fixed_nss)
5804{
5805 /* First check full NSS mask, if we can simply limit NSS */
5806 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
5807 return true;
5808
5809 /* Next Check single rate is set */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005810 return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005811}
5812
5813static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
5814 u8 fixed_rate,
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005815 u8 fixed_nss,
5816 u8 force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005817{
5818 struct ath10k *ar = arvif->ar;
5819 u32 vdev_param;
5820 int ret = 0;
5821
5822 mutex_lock(&ar->conf_mutex);
5823
5824 if (arvif->fixed_rate == fixed_rate &&
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005825 arvif->fixed_nss == fixed_nss &&
5826 arvif->force_sgi == force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005827 goto exit;
5828
5829 if (fixed_rate == WMI_FIXED_RATE_NONE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005830 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005831
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005832 if (force_sgi)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005833 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005834
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005835 vdev_param = ar->wmi.vdev_param->fixed_rate;
5836 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5837 vdev_param, fixed_rate);
5838 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005839 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005840 fixed_rate, ret);
5841 ret = -EINVAL;
5842 goto exit;
5843 }
5844
5845 arvif->fixed_rate = fixed_rate;
5846
5847 vdev_param = ar->wmi.vdev_param->nss;
5848 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5849 vdev_param, fixed_nss);
5850
5851 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005852 ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005853 fixed_nss, ret);
5854 ret = -EINVAL;
5855 goto exit;
5856 }
5857
5858 arvif->fixed_nss = fixed_nss;
5859
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005860 vdev_param = ar->wmi.vdev_param->sgi;
5861 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5862 force_sgi);
5863
5864 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005865 ath10k_warn(ar, "failed to set sgi param %d: %d\n",
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005866 force_sgi, ret);
5867 ret = -EINVAL;
5868 goto exit;
5869 }
5870
5871 arvif->force_sgi = force_sgi;
5872
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005873exit:
5874 mutex_unlock(&ar->conf_mutex);
5875 return ret;
5876}
5877
5878static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
5879 struct ieee80211_vif *vif,
5880 const struct cfg80211_bitrate_mask *mask)
5881{
5882 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior500ff9f2015-03-31 10:26:21 +00005883 struct cfg80211_chan_def def;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005884 struct ath10k *ar = arvif->ar;
Michal Kazior500ff9f2015-03-31 10:26:21 +00005885 enum ieee80211_band band;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005886 u8 fixed_rate = WMI_FIXED_RATE_NONE;
5887 u8 fixed_nss = ar->num_rf_chains;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005888 u8 force_sgi;
5889
Michal Kazior500ff9f2015-03-31 10:26:21 +00005890 if (ath10k_mac_vif_chan(vif, &def))
5891 return -EPERM;
5892
Ben Greearb116ea12014-11-24 16:22:10 +02005893 if (ar->cfg_tx_chainmask)
5894 fixed_nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
5895
Michal Kazior500ff9f2015-03-31 10:26:21 +00005896 band = def.chan->band;
5897
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005898 force_sgi = mask->control[band].gi;
5899 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
5900 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005901
5902 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005903 if (!ath10k_get_fixed_rate_nss(ar, mask, band,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005904 &fixed_rate,
5905 &fixed_nss))
5906 return -EINVAL;
5907 }
5908
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005909 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005910 ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005911 return -EINVAL;
5912 }
5913
5914 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
5915 fixed_nss, force_sgi);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005916}
5917
Michal Kazior9797feb2014-02-14 14:49:48 +01005918static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
5919 struct ieee80211_vif *vif,
5920 struct ieee80211_sta *sta,
5921 u32 changed)
5922{
5923 struct ath10k *ar = hw->priv;
5924 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5925 u32 bw, smps;
5926
5927 spin_lock_bh(&ar->data_lock);
5928
Michal Kazior7aa7a722014-08-25 12:09:38 +02005929 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior9797feb2014-02-14 14:49:48 +01005930 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
5931 sta->addr, changed, sta->bandwidth, sta->rx_nss,
5932 sta->smps_mode);
5933
5934 if (changed & IEEE80211_RC_BW_CHANGED) {
5935 bw = WMI_PEER_CHWIDTH_20MHZ;
5936
5937 switch (sta->bandwidth) {
5938 case IEEE80211_STA_RX_BW_20:
5939 bw = WMI_PEER_CHWIDTH_20MHZ;
5940 break;
5941 case IEEE80211_STA_RX_BW_40:
5942 bw = WMI_PEER_CHWIDTH_40MHZ;
5943 break;
5944 case IEEE80211_STA_RX_BW_80:
5945 bw = WMI_PEER_CHWIDTH_80MHZ;
5946 break;
5947 case IEEE80211_STA_RX_BW_160:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005948 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005949 sta->bandwidth, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005950 bw = WMI_PEER_CHWIDTH_20MHZ;
5951 break;
5952 }
5953
5954 arsta->bw = bw;
5955 }
5956
5957 if (changed & IEEE80211_RC_NSS_CHANGED)
5958 arsta->nss = sta->rx_nss;
5959
5960 if (changed & IEEE80211_RC_SMPS_CHANGED) {
5961 smps = WMI_PEER_SMPS_PS_NONE;
5962
5963 switch (sta->smps_mode) {
5964 case IEEE80211_SMPS_AUTOMATIC:
5965 case IEEE80211_SMPS_OFF:
5966 smps = WMI_PEER_SMPS_PS_NONE;
5967 break;
5968 case IEEE80211_SMPS_STATIC:
5969 smps = WMI_PEER_SMPS_STATIC;
5970 break;
5971 case IEEE80211_SMPS_DYNAMIC:
5972 smps = WMI_PEER_SMPS_DYNAMIC;
5973 break;
5974 case IEEE80211_SMPS_NUM_MODES:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005975 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005976 sta->smps_mode, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005977 smps = WMI_PEER_SMPS_PS_NONE;
5978 break;
5979 }
5980
5981 arsta->smps = smps;
5982 }
5983
Michal Kazior9797feb2014-02-14 14:49:48 +01005984 arsta->changed |= changed;
5985
5986 spin_unlock_bh(&ar->data_lock);
5987
5988 ieee80211_queue_work(hw, &arsta->update_wk);
5989}
5990
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02005991static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
5992{
5993 /*
5994 * FIXME: Return 0 for time being. Need to figure out whether FW
5995 * has the API to fetch 64-bit local TSF
5996 */
5997
5998 return 0;
5999}
6000
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02006001static int ath10k_ampdu_action(struct ieee80211_hw *hw,
6002 struct ieee80211_vif *vif,
6003 enum ieee80211_ampdu_mlme_action action,
6004 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
6005 u8 buf_size)
6006{
Michal Kazior7aa7a722014-08-25 12:09:38 +02006007 struct ath10k *ar = hw->priv;
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02006008 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6009
Michal Kazior7aa7a722014-08-25 12:09:38 +02006010 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 +02006011 arvif->vdev_id, sta->addr, tid, action);
6012
6013 switch (action) {
6014 case IEEE80211_AMPDU_RX_START:
6015 case IEEE80211_AMPDU_RX_STOP:
6016 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
6017 * creation/removal. Do we need to verify this?
6018 */
6019 return 0;
6020 case IEEE80211_AMPDU_TX_START:
6021 case IEEE80211_AMPDU_TX_STOP_CONT:
6022 case IEEE80211_AMPDU_TX_STOP_FLUSH:
6023 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
6024 case IEEE80211_AMPDU_TX_OPERATIONAL:
6025 /* Firmware offloads Tx aggregation entirely so deny mac80211
6026 * Tx aggregation requests.
6027 */
6028 return -EOPNOTSUPP;
6029 }
6030
6031 return -EINVAL;
6032}
6033
Michal Kazior500ff9f2015-03-31 10:26:21 +00006034static void
6035ath10k_mac_update_rx_channel(struct ath10k *ar)
6036{
6037 struct cfg80211_chan_def *def = NULL;
6038
6039 /* Both locks are required because ar->rx_channel is modified. This
6040 * allows readers to hold either lock.
6041 */
6042 lockdep_assert_held(&ar->conf_mutex);
6043 lockdep_assert_held(&ar->data_lock);
6044
6045 /* FIXME: Sort of an optimization and a workaround. Peers and vifs are
6046 * on a linked list now. Doing a lookup peer -> vif -> chanctx for each
6047 * ppdu on Rx may reduce performance on low-end systems. It should be
6048 * possible to make tables/hashmaps to speed the lookup up (be vary of
6049 * cpu data cache lines though regarding sizes) but to keep the initial
6050 * implementation simple and less intrusive fallback to the slow lookup
6051 * only for multi-channel cases. Single-channel cases will remain to
6052 * use the old channel derival and thus performance should not be
6053 * affected much.
6054 */
6055 rcu_read_lock();
6056 if (ath10k_mac_num_chanctxs(ar) == 1) {
6057 ieee80211_iter_chan_contexts_atomic(ar->hw,
6058 ath10k_mac_get_any_chandef_iter,
6059 &def);
6060 ar->rx_channel = def->chan;
6061 } else {
6062 ar->rx_channel = NULL;
6063 }
6064 rcu_read_unlock();
6065}
6066
6067static void
6068ath10k_mac_chan_ctx_init(struct ath10k *ar,
6069 struct ath10k_chanctx *arctx,
6070 struct ieee80211_chanctx_conf *conf)
6071{
6072 lockdep_assert_held(&ar->conf_mutex);
6073 lockdep_assert_held(&ar->data_lock);
6074
6075 memset(arctx, 0, sizeof(*arctx));
6076
6077 arctx->conf = *conf;
6078}
6079
6080static int
6081ath10k_mac_op_add_chanctx(struct ieee80211_hw *hw,
6082 struct ieee80211_chanctx_conf *ctx)
6083{
6084 struct ath10k *ar = hw->priv;
6085 struct ath10k_chanctx *arctx = (void *)ctx->drv_priv;
6086
6087 ath10k_dbg(ar, ATH10K_DBG_MAC,
6088 "mac chanctx add freq %hu width %d ptr %p\n",
6089 ctx->def.chan->center_freq, ctx->def.width, ctx);
6090
6091 mutex_lock(&ar->conf_mutex);
6092
6093 spin_lock_bh(&ar->data_lock);
6094 ath10k_mac_chan_ctx_init(ar, arctx, ctx);
6095 ath10k_mac_update_rx_channel(ar);
6096 spin_unlock_bh(&ar->data_lock);
6097
6098 ath10k_recalc_radar_detection(ar);
6099 ath10k_monitor_recalc(ar);
6100
6101 mutex_unlock(&ar->conf_mutex);
6102
6103 return 0;
6104}
6105
6106static void
6107ath10k_mac_op_remove_chanctx(struct ieee80211_hw *hw,
6108 struct ieee80211_chanctx_conf *ctx)
6109{
6110 struct ath10k *ar = hw->priv;
6111
6112 ath10k_dbg(ar, ATH10K_DBG_MAC,
6113 "mac chanctx remove freq %hu width %d ptr %p\n",
6114 ctx->def.chan->center_freq, ctx->def.width, ctx);
6115
6116 mutex_lock(&ar->conf_mutex);
6117
6118 spin_lock_bh(&ar->data_lock);
6119 ath10k_mac_update_rx_channel(ar);
6120 spin_unlock_bh(&ar->data_lock);
6121
6122 ath10k_recalc_radar_detection(ar);
6123 ath10k_monitor_recalc(ar);
6124
6125 mutex_unlock(&ar->conf_mutex);
6126}
6127
6128static void
6129ath10k_mac_op_change_chanctx(struct ieee80211_hw *hw,
6130 struct ieee80211_chanctx_conf *ctx,
6131 u32 changed)
6132{
6133 struct ath10k *ar = hw->priv;
6134 struct ath10k_chanctx *arctx = (void *)ctx->drv_priv;
6135
6136 mutex_lock(&ar->conf_mutex);
6137
6138 ath10k_dbg(ar, ATH10K_DBG_MAC,
6139 "mac chanctx change freq %hu->%hu width %d->%d ptr %p changed %x\n",
6140 arctx->conf.def.chan->center_freq,
6141 ctx->def.chan->center_freq,
6142 arctx->conf.def.width, ctx->def.width,
6143 ctx, changed);
6144
6145 /* This shouldn't really happen because channel switching should use
6146 * switch_vif_chanctx().
6147 */
6148 if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL))
6149 goto unlock;
6150
6151 spin_lock_bh(&ar->data_lock);
6152 arctx->conf = *ctx;
6153 spin_unlock_bh(&ar->data_lock);
6154
6155 ath10k_recalc_radar_detection(ar);
6156
6157 /* FIXME: How to configure Rx chains properly? */
6158
6159 /* No other actions are actually necessary. Firmware maintains channel
6160 * definitions per vdev internally and there's no host-side channel
6161 * context abstraction to configure, e.g. channel width.
6162 */
6163
6164unlock:
6165 mutex_unlock(&ar->conf_mutex);
6166}
6167
6168static int
6169ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
6170 struct ieee80211_vif *vif,
6171 struct ieee80211_chanctx_conf *ctx)
6172{
6173 struct ath10k *ar = hw->priv;
6174 struct ath10k_chanctx *arctx = (void *)ctx->drv_priv;
6175 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6176 int ret;
6177
6178 mutex_lock(&ar->conf_mutex);
6179
6180 ath10k_dbg(ar, ATH10K_DBG_MAC,
6181 "mac chanctx assign ptr %p vdev_id %i\n",
6182 ctx, arvif->vdev_id);
6183
6184 if (WARN_ON(arvif->is_started)) {
6185 mutex_unlock(&ar->conf_mutex);
6186 return -EBUSY;
6187 }
6188
6189 ret = ath10k_vdev_start(arvif, &arctx->conf.def);
6190 if (ret) {
6191 ath10k_warn(ar, "failed to start vdev %i addr %pM on freq %d: %d\n",
6192 arvif->vdev_id, vif->addr,
6193 arctx->conf.def.chan->center_freq, ret);
6194 goto err;
6195 }
6196
6197 arvif->is_started = true;
6198
6199 if (vif->type == NL80211_IFTYPE_MONITOR) {
6200 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, 0, vif->addr);
6201 if (ret) {
6202 ath10k_warn(ar, "failed to up monitor vdev %i: %d\n",
6203 arvif->vdev_id, ret);
6204 goto err_stop;
6205 }
6206
6207 arvif->is_up = true;
6208 }
6209
6210 mutex_unlock(&ar->conf_mutex);
6211 return 0;
6212
6213err_stop:
6214 ath10k_vdev_stop(arvif);
6215 arvif->is_started = false;
6216
6217err:
6218 mutex_unlock(&ar->conf_mutex);
6219 return ret;
6220}
6221
6222static void
6223ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
6224 struct ieee80211_vif *vif,
6225 struct ieee80211_chanctx_conf *ctx)
6226{
6227 struct ath10k *ar = hw->priv;
6228 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6229 int ret;
6230
6231 mutex_lock(&ar->conf_mutex);
6232
6233 ath10k_dbg(ar, ATH10K_DBG_MAC,
6234 "mac chanctx unassign ptr %p vdev_id %i\n",
6235 ctx, arvif->vdev_id);
6236
6237 WARN_ON(!arvif->is_started);
6238
6239 if (vif->type == NL80211_IFTYPE_MONITOR) {
6240 WARN_ON(!arvif->is_up);
6241
6242 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
6243 if (ret)
6244 ath10k_warn(ar, "failed to down monitor vdev %i: %d\n",
6245 arvif->vdev_id, ret);
6246
6247 arvif->is_up = false;
6248 }
6249
6250 ret = ath10k_vdev_stop(arvif);
6251 if (ret)
6252 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
6253 arvif->vdev_id, ret);
6254
6255 arvif->is_started = false;
6256
6257 mutex_unlock(&ar->conf_mutex);
6258}
6259
6260static int
6261ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw,
6262 struct ieee80211_vif_chanctx_switch *vifs,
6263 int n_vifs,
6264 enum ieee80211_chanctx_switch_mode mode)
6265{
6266 struct ath10k *ar = hw->priv;
6267 struct ath10k_vif *arvif;
6268 struct ath10k_chanctx *arctx_new, *arctx_old;
6269 int i;
6270
6271 mutex_lock(&ar->conf_mutex);
6272
6273 ath10k_dbg(ar, ATH10K_DBG_MAC,
6274 "mac chanctx switch n_vifs %d mode %d\n",
6275 n_vifs, mode);
6276
6277 spin_lock_bh(&ar->data_lock);
6278 for (i = 0; i < n_vifs; i++) {
6279 arvif = ath10k_vif_to_arvif(vifs[i].vif);
6280 arctx_new = (void *)vifs[i].new_ctx->drv_priv;
6281 arctx_old = (void *)vifs[i].old_ctx->drv_priv;
6282
6283 ath10k_dbg(ar, ATH10K_DBG_MAC,
6284 "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d ptr %p->%p\n",
6285 arvif->vdev_id,
6286 vifs[i].old_ctx->def.chan->center_freq,
6287 vifs[i].new_ctx->def.chan->center_freq,
6288 vifs[i].old_ctx->def.width,
6289 vifs[i].new_ctx->def.width,
6290 arctx_old, arctx_new);
6291
6292 if (mode == CHANCTX_SWMODE_SWAP_CONTEXTS) {
6293 ath10k_mac_chan_ctx_init(ar, arctx_new,
6294 vifs[i].new_ctx);
6295 }
6296
6297 arctx_new->conf = *vifs[i].new_ctx;
6298
6299 /* FIXME: ath10k_mac_chan_reconfigure() uses current, i.e. not
6300 * yet updated chanctx_conf pointer.
6301 */
6302 arctx_old->conf = *vifs[i].new_ctx;
6303 }
6304 ath10k_mac_update_rx_channel(ar);
6305 spin_unlock_bh(&ar->data_lock);
6306
6307 /* FIXME: Reconfigure only affected vifs */
6308 ath10k_mac_chan_reconfigure(ar);
6309
6310 mutex_unlock(&ar->conf_mutex);
6311 return 0;
6312}
6313
Kalle Valo5e3dd152013-06-12 20:52:10 +03006314static const struct ieee80211_ops ath10k_ops = {
6315 .tx = ath10k_tx,
6316 .start = ath10k_start,
6317 .stop = ath10k_stop,
6318 .config = ath10k_config,
6319 .add_interface = ath10k_add_interface,
6320 .remove_interface = ath10k_remove_interface,
6321 .configure_filter = ath10k_configure_filter,
6322 .bss_info_changed = ath10k_bss_info_changed,
6323 .hw_scan = ath10k_hw_scan,
6324 .cancel_hw_scan = ath10k_cancel_hw_scan,
6325 .set_key = ath10k_set_key,
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02006326 .set_default_unicast_key = ath10k_set_default_unicast_key,
Kalle Valo5e3dd152013-06-12 20:52:10 +03006327 .sta_state = ath10k_sta_state,
6328 .conf_tx = ath10k_conf_tx,
6329 .remain_on_channel = ath10k_remain_on_channel,
6330 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
6331 .set_rts_threshold = ath10k_set_rts_threshold,
Kalle Valo5e3dd152013-06-12 20:52:10 +03006332 .flush = ath10k_flush,
6333 .tx_last_beacon = ath10k_tx_last_beacon,
Ben Greear46acf7b2014-05-16 17:15:38 +03006334 .set_antenna = ath10k_set_antenna,
6335 .get_antenna = ath10k_get_antenna,
Eliad Pellercf2c92d2014-11-04 11:43:54 +02006336 .reconfig_complete = ath10k_reconfig_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02006337 .get_survey = ath10k_get_survey,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01006338 .set_bitrate_mask = ath10k_set_bitrate_mask,
Michal Kazior9797feb2014-02-14 14:49:48 +01006339 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02006340 .get_tsf = ath10k_get_tsf,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02006341 .ampdu_action = ath10k_ampdu_action,
Ben Greear6cddcc72014-09-29 14:41:46 +03006342 .get_et_sset_count = ath10k_debug_get_et_sset_count,
6343 .get_et_stats = ath10k_debug_get_et_stats,
6344 .get_et_strings = ath10k_debug_get_et_strings,
Michal Kazior500ff9f2015-03-31 10:26:21 +00006345 .add_chanctx = ath10k_mac_op_add_chanctx,
6346 .remove_chanctx = ath10k_mac_op_remove_chanctx,
6347 .change_chanctx = ath10k_mac_op_change_chanctx,
6348 .assign_vif_chanctx = ath10k_mac_op_assign_vif_chanctx,
6349 .unassign_vif_chanctx = ath10k_mac_op_unassign_vif_chanctx,
6350 .switch_vif_chanctx = ath10k_mac_op_switch_vif_chanctx,
Kalle Valo43d2a302014-09-10 18:23:30 +03006351
6352 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
6353
Michal Kazior8cd13ca2013-07-16 09:38:54 +02006354#ifdef CONFIG_PM
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +02006355 .suspend = ath10k_wow_op_suspend,
6356 .resume = ath10k_wow_op_resume,
Michal Kazior8cd13ca2013-07-16 09:38:54 +02006357#endif
Rajkumar Manoharanf5045982015-01-12 14:07:27 +02006358#ifdef CONFIG_MAC80211_DEBUGFS
6359 .sta_add_debugfs = ath10k_sta_add_debugfs,
6360#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03006361};
6362
Kalle Valo5e3dd152013-06-12 20:52:10 +03006363#define CHAN2G(_channel, _freq, _flags) { \
6364 .band = IEEE80211_BAND_2GHZ, \
6365 .hw_value = (_channel), \
6366 .center_freq = (_freq), \
6367 .flags = (_flags), \
6368 .max_antenna_gain = 0, \
6369 .max_power = 30, \
6370}
6371
6372#define CHAN5G(_channel, _freq, _flags) { \
6373 .band = IEEE80211_BAND_5GHZ, \
6374 .hw_value = (_channel), \
6375 .center_freq = (_freq), \
6376 .flags = (_flags), \
6377 .max_antenna_gain = 0, \
6378 .max_power = 30, \
6379}
6380
6381static const struct ieee80211_channel ath10k_2ghz_channels[] = {
6382 CHAN2G(1, 2412, 0),
6383 CHAN2G(2, 2417, 0),
6384 CHAN2G(3, 2422, 0),
6385 CHAN2G(4, 2427, 0),
6386 CHAN2G(5, 2432, 0),
6387 CHAN2G(6, 2437, 0),
6388 CHAN2G(7, 2442, 0),
6389 CHAN2G(8, 2447, 0),
6390 CHAN2G(9, 2452, 0),
6391 CHAN2G(10, 2457, 0),
6392 CHAN2G(11, 2462, 0),
6393 CHAN2G(12, 2467, 0),
6394 CHAN2G(13, 2472, 0),
6395 CHAN2G(14, 2484, 0),
6396};
6397
6398static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02006399 CHAN5G(36, 5180, 0),
6400 CHAN5G(40, 5200, 0),
6401 CHAN5G(44, 5220, 0),
6402 CHAN5G(48, 5240, 0),
6403 CHAN5G(52, 5260, 0),
6404 CHAN5G(56, 5280, 0),
6405 CHAN5G(60, 5300, 0),
6406 CHAN5G(64, 5320, 0),
6407 CHAN5G(100, 5500, 0),
6408 CHAN5G(104, 5520, 0),
6409 CHAN5G(108, 5540, 0),
6410 CHAN5G(112, 5560, 0),
6411 CHAN5G(116, 5580, 0),
6412 CHAN5G(120, 5600, 0),
6413 CHAN5G(124, 5620, 0),
6414 CHAN5G(128, 5640, 0),
6415 CHAN5G(132, 5660, 0),
6416 CHAN5G(136, 5680, 0),
6417 CHAN5G(140, 5700, 0),
Peter Oh4a7898f2015-03-18 11:39:18 -07006418 CHAN5G(144, 5720, 0),
Michal Kazior429ff562013-06-26 08:54:54 +02006419 CHAN5G(149, 5745, 0),
6420 CHAN5G(153, 5765, 0),
6421 CHAN5G(157, 5785, 0),
6422 CHAN5G(161, 5805, 0),
6423 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03006424};
6425
Michal Kaziore7b54192014-08-07 11:03:27 +02006426struct ath10k *ath10k_mac_create(size_t priv_size)
Kalle Valo5e3dd152013-06-12 20:52:10 +03006427{
6428 struct ieee80211_hw *hw;
6429 struct ath10k *ar;
6430
Michal Kaziore7b54192014-08-07 11:03:27 +02006431 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006432 if (!hw)
6433 return NULL;
6434
6435 ar = hw->priv;
6436 ar->hw = hw;
6437
6438 return ar;
6439}
6440
6441void ath10k_mac_destroy(struct ath10k *ar)
6442{
6443 ieee80211_free_hw(ar->hw);
6444}
6445
6446static const struct ieee80211_iface_limit ath10k_if_limits[] = {
6447 {
6448 .max = 8,
6449 .types = BIT(NL80211_IFTYPE_STATION)
6450 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02006451 },
6452 {
6453 .max = 3,
6454 .types = BIT(NL80211_IFTYPE_P2P_GO)
6455 },
6456 {
Michal Kazior75d2bd42014-12-12 12:41:39 +01006457 .max = 1,
6458 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
6459 },
6460 {
Michal Kaziord531cb82013-07-31 10:55:13 +02006461 .max = 7,
6462 .types = BIT(NL80211_IFTYPE_AP)
6463 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03006464};
6465
Bartosz Markowskif2595092013-12-10 16:20:39 +01006466static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006467 {
6468 .max = 8,
6469 .types = BIT(NL80211_IFTYPE_AP)
6470 },
6471};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006472
6473static const struct ieee80211_iface_combination ath10k_if_comb[] = {
6474 {
6475 .limits = ath10k_if_limits,
6476 .n_limits = ARRAY_SIZE(ath10k_if_limits),
6477 .max_interfaces = 8,
6478 .num_different_channels = 1,
6479 .beacon_int_infra_match = true,
6480 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01006481};
6482
6483static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006484 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01006485 .limits = ath10k_10x_if_limits,
6486 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006487 .max_interfaces = 8,
6488 .num_different_channels = 1,
6489 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01006490#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006491 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
6492 BIT(NL80211_CHAN_WIDTH_20) |
6493 BIT(NL80211_CHAN_WIDTH_40) |
6494 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006495#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01006496 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03006497};
6498
Michal Kaziorcf327842015-03-31 10:26:25 +00006499static const struct ieee80211_iface_limit ath10k_tlv_if_limit[] = {
6500 {
6501 .max = 2,
6502 .types = BIT(NL80211_IFTYPE_STATION) |
6503 BIT(NL80211_IFTYPE_AP) |
6504 BIT(NL80211_IFTYPE_P2P_CLIENT) |
6505 BIT(NL80211_IFTYPE_P2P_GO),
6506 },
6507 {
6508 .max = 1,
6509 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
6510 },
6511};
6512
6513static const struct ieee80211_iface_limit ath10k_tlv_if_limit_ibss[] = {
6514 {
6515 .max = 1,
6516 .types = BIT(NL80211_IFTYPE_STATION),
6517 },
6518 {
6519 .max = 1,
6520 .types = BIT(NL80211_IFTYPE_ADHOC),
6521 },
6522};
6523
6524/* FIXME: This is not thouroughly tested. These combinations may over- or
6525 * underestimate hw/fw capabilities.
6526 */
6527static struct ieee80211_iface_combination ath10k_tlv_if_comb[] = {
6528 {
6529 .limits = ath10k_tlv_if_limit,
6530 .num_different_channels = 1,
6531 .max_interfaces = 3,
6532 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
6533 },
6534 {
6535 .limits = ath10k_tlv_if_limit_ibss,
6536 .num_different_channels = 1,
6537 .max_interfaces = 2,
6538 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
6539 },
6540};
6541
6542static struct ieee80211_iface_combination ath10k_tlv_qcs_if_comb[] = {
6543 {
6544 .limits = ath10k_tlv_if_limit,
6545 .num_different_channels = 2,
6546 .max_interfaces = 3,
6547 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
6548 },
6549 {
6550 .limits = ath10k_tlv_if_limit_ibss,
6551 .num_different_channels = 1,
6552 .max_interfaces = 2,
6553 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
6554 },
6555};
6556
Kalle Valo5e3dd152013-06-12 20:52:10 +03006557static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
6558{
6559 struct ieee80211_sta_vht_cap vht_cap = {0};
6560 u16 mcs_map;
Michal Kaziorbc657a362015-02-26 11:11:22 +01006561 u32 val;
Michal Kazior8865bee42013-07-24 12:36:46 +02006562 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006563
6564 vht_cap.vht_supported = 1;
6565 vht_cap.cap = ar->vht_cap_info;
6566
Michal Kaziorbc657a362015-02-26 11:11:22 +01006567 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
6568 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
6569 val = ar->num_rf_chains - 1;
6570 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
6571 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
6572
6573 vht_cap.cap |= val;
6574 }
6575
6576 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
6577 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
6578 val = ar->num_rf_chains - 1;
6579 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
6580 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
6581
6582 vht_cap.cap |= val;
6583 }
6584
Michal Kazior8865bee42013-07-24 12:36:46 +02006585 mcs_map = 0;
6586 for (i = 0; i < 8; i++) {
6587 if (i < ar->num_rf_chains)
6588 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
6589 else
6590 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
6591 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03006592
6593 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
6594 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
6595
6596 return vht_cap;
6597}
6598
6599static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
6600{
6601 int i;
6602 struct ieee80211_sta_ht_cap ht_cap = {0};
6603
6604 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
6605 return ht_cap;
6606
6607 ht_cap.ht_supported = 1;
6608 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
6609 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
6610 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
6611 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
6612 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
6613
6614 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
6615 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
6616
6617 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
6618 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
6619
6620 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
6621 u32 smps;
6622
6623 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
6624 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
6625
6626 ht_cap.cap |= smps;
6627 }
6628
6629 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
6630 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
6631
6632 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
6633 u32 stbc;
6634
6635 stbc = ar->ht_cap_info;
6636 stbc &= WMI_HT_CAP_RX_STBC;
6637 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
6638 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
6639 stbc &= IEEE80211_HT_CAP_RX_STBC;
6640
6641 ht_cap.cap |= stbc;
6642 }
6643
6644 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
6645 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
6646
6647 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
6648 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
6649
6650 /* max AMSDU is implicitly taken from vht_cap_info */
6651 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
6652 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
6653
Michal Kazior8865bee42013-07-24 12:36:46 +02006654 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03006655 ht_cap.mcs.rx_mask[i] = 0xFF;
6656
6657 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
6658
6659 return ht_cap;
6660}
6661
Kalle Valo5e3dd152013-06-12 20:52:10 +03006662static void ath10k_get_arvif_iter(void *data, u8 *mac,
6663 struct ieee80211_vif *vif)
6664{
6665 struct ath10k_vif_iter *arvif_iter = data;
6666 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6667
6668 if (arvif->vdev_id == arvif_iter->vdev_id)
6669 arvif_iter->arvif = arvif;
6670}
6671
6672struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
6673{
6674 struct ath10k_vif_iter arvif_iter;
6675 u32 flags;
6676
6677 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
6678 arvif_iter.vdev_id = vdev_id;
6679
6680 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
6681 ieee80211_iterate_active_interfaces_atomic(ar->hw,
6682 flags,
6683 ath10k_get_arvif_iter,
6684 &arvif_iter);
6685 if (!arvif_iter.arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02006686 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006687 return NULL;
6688 }
6689
6690 return arvif_iter.arvif;
6691}
6692
6693int ath10k_mac_register(struct ath10k *ar)
6694{
Johannes Berg3cb10942015-01-22 21:38:45 +01006695 static const u32 cipher_suites[] = {
6696 WLAN_CIPHER_SUITE_WEP40,
6697 WLAN_CIPHER_SUITE_WEP104,
6698 WLAN_CIPHER_SUITE_TKIP,
6699 WLAN_CIPHER_SUITE_CCMP,
6700 WLAN_CIPHER_SUITE_AES_CMAC,
6701 };
Kalle Valo5e3dd152013-06-12 20:52:10 +03006702 struct ieee80211_supported_band *band;
6703 struct ieee80211_sta_vht_cap vht_cap;
6704 struct ieee80211_sta_ht_cap ht_cap;
6705 void *channels;
6706 int ret;
6707
6708 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
6709
6710 SET_IEEE80211_DEV(ar->hw, ar->dev);
6711
6712 ht_cap = ath10k_get_ht_cap(ar);
6713 vht_cap = ath10k_create_vht_cap(ar);
6714
Michal Kaziorc94aa7e2015-03-24 12:38:11 +00006715 BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels) +
6716 ARRAY_SIZE(ath10k_5ghz_channels)) !=
6717 ATH10K_NUM_CHANS);
6718
Kalle Valo5e3dd152013-06-12 20:52:10 +03006719 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
6720 channels = kmemdup(ath10k_2ghz_channels,
6721 sizeof(ath10k_2ghz_channels),
6722 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02006723 if (!channels) {
6724 ret = -ENOMEM;
6725 goto err_free;
6726 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03006727
6728 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
6729 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
6730 band->channels = channels;
6731 band->n_bitrates = ath10k_g_rates_size;
6732 band->bitrates = ath10k_g_rates;
6733 band->ht_cap = ht_cap;
6734
Yanbo Lid68bb122015-01-23 08:18:20 +08006735 /* Enable the VHT support at 2.4 GHz */
6736 band->vht_cap = vht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006737
6738 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
6739 }
6740
6741 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
6742 channels = kmemdup(ath10k_5ghz_channels,
6743 sizeof(ath10k_5ghz_channels),
6744 GFP_KERNEL);
6745 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02006746 ret = -ENOMEM;
6747 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006748 }
6749
6750 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
6751 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
6752 band->channels = channels;
6753 band->n_bitrates = ath10k_a_rates_size;
6754 band->bitrates = ath10k_a_rates;
6755 band->ht_cap = ht_cap;
6756 band->vht_cap = vht_cap;
6757 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
6758 }
6759
6760 ar->hw->wiphy->interface_modes =
6761 BIT(NL80211_IFTYPE_STATION) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01006762 BIT(NL80211_IFTYPE_AP);
6763
Ben Greear46acf7b2014-05-16 17:15:38 +03006764 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
6765 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
6766
Bartosz Markowskid3541812013-12-10 16:20:40 +01006767 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
6768 ar->hw->wiphy->interface_modes |=
Michal Kazior75d2bd42014-12-12 12:41:39 +01006769 BIT(NL80211_IFTYPE_P2P_DEVICE) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01006770 BIT(NL80211_IFTYPE_P2P_CLIENT) |
6771 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006772
6773 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
6774 IEEE80211_HW_SUPPORTS_PS |
6775 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
Kalle Valo5e3dd152013-06-12 20:52:10 +03006776 IEEE80211_HW_MFP_CAPABLE |
6777 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
6778 IEEE80211_HW_HAS_RATE_CONTROL |
Janusz Dziedzic2f0f1122014-02-26 18:42:09 +02006779 IEEE80211_HW_AP_LINK_PS |
Johannes Berg3cb10942015-01-22 21:38:45 +01006780 IEEE80211_HW_SPECTRUM_MGMT |
Michal Kaziorcc9904e2015-03-10 16:22:01 +02006781 IEEE80211_HW_SW_CRYPTO_CONTROL |
Michal Kazior500ff9f2015-03-31 10:26:21 +00006782 IEEE80211_HW_CONNECTION_MONITOR |
6783 IEEE80211_HW_WANT_MONITOR_VIF |
Michal Kazior96d828d2015-03-31 10:26:23 +00006784 IEEE80211_HW_CHANCTX_STA_CSA |
6785 IEEE80211_HW_QUEUE_CONTROL;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006786
Eliad Peller0d8614b2014-09-10 14:07:36 +03006787 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
6788
Kalle Valo5e3dd152013-06-12 20:52:10 +03006789 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
Eliad Peller0d8614b2014-09-10 14:07:36 +03006790 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006791
6792 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
6793 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
6794 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
6795 }
6796
6797 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
6798 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
6799
6800 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01006801 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006802 ar->hw->chanctx_data_size = sizeof(struct ath10k_chanctx);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006803
Kalle Valo5e3dd152013-06-12 20:52:10 +03006804 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
6805
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02006806 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
6807 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
6808
6809 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
6810 * that userspace (e.g. wpa_supplicant/hostapd) can generate
6811 * correct Probe Responses. This is more of a hack advert..
6812 */
6813 ar->hw->wiphy->probe_resp_offload |=
6814 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
6815 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
6816 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
6817 }
6818
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03006819 if (test_bit(WMI_SERVICE_TDLS, ar->wmi.svc_map))
6820 ar->hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
6821
Kalle Valo5e3dd152013-06-12 20:52:10 +03006822 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01006823 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006824 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
6825
6826 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
Rajkumar Manoharan78157a12014-11-17 16:44:15 +02006827 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
6828
Janusz.Dziedzic@tieto.com37a0b392015-03-12 13:11:41 +01006829 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
6830
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +02006831 ret = ath10k_wow_init(ar);
6832 if (ret) {
6833 ath10k_warn(ar, "failed to init wow: %d\n", ret);
6834 goto err_free;
6835 }
6836
Kalle Valo5e3dd152013-06-12 20:52:10 +03006837 /*
6838 * on LL hardware queues are managed entirely by the FW
6839 * so we only advertise to mac we can do the queues thing
6840 */
Michal Kazior96d828d2015-03-31 10:26:23 +00006841 ar->hw->queues = IEEE80211_MAX_QUEUES;
6842
6843 /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is
6844 * something that vdev_ids can't reach so that we don't stop the queue
6845 * accidentally.
6846 */
6847 ar->hw->offchannel_tx_hw_queue = IEEE80211_MAX_QUEUES - 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006848
Kalle Valo5cc7caf2014-12-17 12:20:54 +02006849 switch (ar->wmi.op_version) {
6850 case ATH10K_FW_WMI_OP_VERSION_MAIN:
Bartosz Markowskif2595092013-12-10 16:20:39 +01006851 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
6852 ar->hw->wiphy->n_iface_combinations =
6853 ARRAY_SIZE(ath10k_if_comb);
Michal Kaziorcf850d12014-07-24 20:07:00 +03006854 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
Kalle Valo5cc7caf2014-12-17 12:20:54 +02006855 break;
Michal Kaziorcf327842015-03-31 10:26:25 +00006856 case ATH10K_FW_WMI_OP_VERSION_TLV:
6857 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
6858 ar->hw->wiphy->iface_combinations =
6859 ath10k_tlv_qcs_if_comb;
6860 ar->hw->wiphy->n_iface_combinations =
6861 ARRAY_SIZE(ath10k_tlv_qcs_if_comb);
6862 } else {
6863 ar->hw->wiphy->iface_combinations = ath10k_tlv_if_comb;
6864 ar->hw->wiphy->n_iface_combinations =
6865 ARRAY_SIZE(ath10k_tlv_if_comb);
6866 }
6867 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
6868 break;
Kalle Valo5cc7caf2014-12-17 12:20:54 +02006869 case ATH10K_FW_WMI_OP_VERSION_10_1:
6870 case ATH10K_FW_WMI_OP_VERSION_10_2:
Rajkumar Manoharan4a16fbe2014-12-17 12:21:12 +02006871 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
Kalle Valo5cc7caf2014-12-17 12:20:54 +02006872 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
6873 ar->hw->wiphy->n_iface_combinations =
6874 ARRAY_SIZE(ath10k_10x_if_comb);
6875 break;
6876 case ATH10K_FW_WMI_OP_VERSION_UNSET:
6877 case ATH10K_FW_WMI_OP_VERSION_MAX:
6878 WARN_ON(1);
6879 ret = -EINVAL;
6880 goto err_free;
Bartosz Markowskif2595092013-12-10 16:20:39 +01006881 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03006882
Michal Kazior7c199992013-07-31 10:47:57 +02006883 ar->hw->netdev_features = NETIF_F_HW_CSUM;
6884
Janusz Dziedzic9702c682013-11-20 09:59:41 +02006885 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
6886 /* Init ath dfs pattern detector */
6887 ar->ath_common.debug_mask = ATH_DBG_DFS;
6888 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
6889 NL80211_DFS_UNSET);
6890
6891 if (!ar->dfs_detector)
Michal Kazior7aa7a722014-08-25 12:09:38 +02006892 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02006893 }
6894
Kalle Valo5e3dd152013-06-12 20:52:10 +03006895 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
6896 ath10k_reg_notifier);
6897 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02006898 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02006899 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006900 }
6901
Johannes Berg3cb10942015-01-22 21:38:45 +01006902 ar->hw->wiphy->cipher_suites = cipher_suites;
6903 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
6904
Kalle Valo5e3dd152013-06-12 20:52:10 +03006905 ret = ieee80211_register_hw(ar->hw);
6906 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02006907 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02006908 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006909 }
6910
6911 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
6912 ret = regulatory_hint(ar->hw->wiphy,
6913 ar->ath_common.regulatory.alpha2);
6914 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02006915 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006916 }
6917
6918 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02006919
6920err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03006921 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02006922err_free:
6923 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
6924 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
6925
Kalle Valo5e3dd152013-06-12 20:52:10 +03006926 return ret;
6927}
6928
6929void ath10k_mac_unregister(struct ath10k *ar)
6930{
6931 ieee80211_unregister_hw(ar->hw);
6932
Janusz Dziedzic9702c682013-11-20 09:59:41 +02006933 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
6934 ar->dfs_detector->exit(ar->dfs_detector);
6935
Kalle Valo5e3dd152013-06-12 20:52:10 +03006936 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
6937 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
6938
6939 SET_IEEE80211_DEV(ar->hw, NULL);
6940}