blob: 2da66ca635fd9e88222e78ccc27b0281ff84f219 [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
Ben Greear46acf7b2014-05-16 17:15:38 +03003738 if (ar->cfg_tx_chainmask)
3739 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
3740 ar->cfg_rx_chainmask);
3741
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003742 /*
3743 * By default FW set ARP frames ac to voice (6). In that case ARP
3744 * exchange is not working properly for UAPSD enabled AP. ARP requests
3745 * which arrives with access category 0 are processed by network stack
3746 * and send back with access category 0, but FW changes access category
3747 * to 6. Set ARP frames access category to best effort (0) solves
3748 * this problem.
3749 */
3750
3751 ret = ath10k_wmi_pdev_set_param(ar,
3752 ar->wmi.pdev_param->arp_ac_override, 0);
3753 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003754 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003755 ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003756 goto err_core_stop;
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003757 }
3758
Ashok Raj Nagarajan575f1c32015-03-19 16:37:59 +05303759 ret = ath10k_wmi_pdev_set_param(ar,
3760 ar->wmi.pdev_param->ani_enable, 1);
3761 if (ret) {
3762 ath10k_warn(ar, "failed to enable ani by default: %d\n",
3763 ret);
3764 goto err_core_stop;
3765 }
3766
Ashok Raj Nagarajanb3e71d72015-03-19 16:38:00 +05303767 ar->ani_enabled = true;
3768
Michal Kaziord6500972014-04-08 09:56:09 +03003769 ar->num_started_vdevs = 0;
Michal Kaziorf7843d72013-07-16 09:38:52 +02003770 ath10k_regd_update(ar);
3771
Simon Wunderlich855aed12014-08-02 09:12:54 +03003772 ath10k_spectral_start(ar);
Rajkumar Manoharan8515b5c2015-03-15 20:36:22 +05303773 ath10k_thermal_set_throttling(ar);
Simon Wunderlich855aed12014-08-02 09:12:54 +03003774
Michal Kaziorae254432014-05-26 12:46:02 +03003775 mutex_unlock(&ar->conf_mutex);
3776 return 0;
3777
3778err_core_stop:
3779 ath10k_core_stop(ar);
3780
3781err_power_down:
3782 ath10k_hif_power_down(ar);
3783
3784err_off:
3785 ar->state = ATH10K_STATE_OFF;
3786
3787err:
Michal Kazior548db542013-07-05 16:15:15 +03003788 mutex_unlock(&ar->conf_mutex);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01003789 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003790}
3791
3792static void ath10k_stop(struct ieee80211_hw *hw)
3793{
3794 struct ath10k *ar = hw->priv;
3795
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003796 ath10k_drain_tx(ar);
3797
Michal Kazior548db542013-07-05 16:15:15 +03003798 mutex_lock(&ar->conf_mutex);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003799 if (ar->state != ATH10K_STATE_OFF) {
Michal Kazior818bdd12013-07-16 09:38:57 +02003800 ath10k_halt(ar);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003801 ar->state = ATH10K_STATE_OFF;
3802 }
Michal Kazior548db542013-07-05 16:15:15 +03003803 mutex_unlock(&ar->conf_mutex);
3804
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003805 cancel_delayed_work_sync(&ar->scan.timeout);
Michal Kazioraffd3212013-07-16 09:54:35 +02003806 cancel_work_sync(&ar->restart_work);
3807}
3808
Michal Kaziorad088bf2013-10-16 15:44:46 +03003809static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02003810{
Michal Kaziorad088bf2013-10-16 15:44:46 +03003811 struct ath10k_vif *arvif;
3812 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02003813
3814 lockdep_assert_held(&ar->conf_mutex);
3815
Michal Kaziorad088bf2013-10-16 15:44:46 +03003816 list_for_each_entry(arvif, &ar->arvifs, list) {
3817 ret = ath10k_mac_vif_setup_ps(arvif);
3818 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003819 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03003820 break;
3821 }
3822 }
Michal Kazioraffd3212013-07-16 09:54:35 +02003823
Michal Kaziorad088bf2013-10-16 15:44:46 +03003824 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003825}
3826
Michal Kazior500ff9f2015-03-31 10:26:21 +00003827static void ath10k_mac_chan_reconfigure(struct ath10k *ar)
Michal Kaziorc930f742014-01-23 11:38:25 +01003828{
3829 struct ath10k_vif *arvif;
Michal Kazior500ff9f2015-03-31 10:26:21 +00003830 struct cfg80211_chan_def def;
Michal Kaziorc930f742014-01-23 11:38:25 +01003831 int ret;
3832
3833 lockdep_assert_held(&ar->conf_mutex);
3834
Michal Kazior500ff9f2015-03-31 10:26:21 +00003835 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac chan reconfigure\n");
Michal Kaziorc930f742014-01-23 11:38:25 +01003836
3837 /* First stop monitor interface. Some FW versions crash if there's a
3838 * lone monitor interface. */
Michal Kazior1bbc0972014-04-08 09:45:47 +03003839 if (ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02003840 ath10k_monitor_stop(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003841
3842 list_for_each_entry(arvif, &ar->arvifs, list) {
3843 if (!arvif->is_started)
3844 continue;
3845
Michal Kaziordc55e302014-07-29 12:53:36 +03003846 if (!arvif->is_up)
3847 continue;
3848
Michal Kaziorc930f742014-01-23 11:38:25 +01003849 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3850 continue;
3851
Michal Kaziordc55e302014-07-29 12:53:36 +03003852 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kaziorc930f742014-01-23 11:38:25 +01003853 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003854 ath10k_warn(ar, "failed to down vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003855 arvif->vdev_id, ret);
3856 continue;
3857 }
3858 }
3859
Michal Kaziordc55e302014-07-29 12:53:36 +03003860 /* all vdevs are downed now - attempt to restart and re-up them */
Michal Kaziorc930f742014-01-23 11:38:25 +01003861
3862 list_for_each_entry(arvif, &ar->arvifs, list) {
3863 if (!arvif->is_started)
3864 continue;
3865
3866 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3867 continue;
3868
Michal Kazior81a9a172015-03-05 16:02:17 +02003869 ret = ath10k_mac_setup_bcn_tmpl(arvif);
3870 if (ret)
3871 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
3872 ret);
3873
3874 ret = ath10k_mac_setup_prb_tmpl(arvif);
3875 if (ret)
3876 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
3877 ret);
3878
Michal Kazior500ff9f2015-03-31 10:26:21 +00003879 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
3880 continue;
3881
3882 ret = ath10k_vdev_restart(arvif, &def);
Michal Kaziorc930f742014-01-23 11:38:25 +01003883 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003884 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003885 arvif->vdev_id, ret);
3886 continue;
3887 }
3888
3889 if (!arvif->is_up)
3890 continue;
3891
3892 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
3893 arvif->bssid);
3894 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003895 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003896 arvif->vdev_id, ret);
3897 continue;
3898 }
3899 }
3900
Michal Kazior19337472014-08-28 12:58:16 +02003901 ath10k_monitor_recalc(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003902}
3903
Michal Kazior7d9d5582014-10-21 10:40:15 +03003904static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
3905{
3906 int ret;
3907 u32 param;
3908
3909 lockdep_assert_held(&ar->conf_mutex);
3910
3911 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
3912
3913 param = ar->wmi.pdev_param->txpower_limit2g;
3914 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3915 if (ret) {
3916 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
3917 txpower, ret);
3918 return ret;
3919 }
3920
3921 param = ar->wmi.pdev_param->txpower_limit5g;
3922 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3923 if (ret) {
3924 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
3925 txpower, ret);
3926 return ret;
3927 }
3928
3929 return 0;
3930}
3931
3932static int ath10k_mac_txpower_recalc(struct ath10k *ar)
3933{
3934 struct ath10k_vif *arvif;
3935 int ret, txpower = -1;
3936
3937 lockdep_assert_held(&ar->conf_mutex);
3938
3939 list_for_each_entry(arvif, &ar->arvifs, list) {
3940 WARN_ON(arvif->txpower < 0);
3941
3942 if (txpower == -1)
3943 txpower = arvif->txpower;
3944 else
3945 txpower = min(txpower, arvif->txpower);
3946 }
3947
3948 if (WARN_ON(txpower == -1))
3949 return -EINVAL;
3950
3951 ret = ath10k_mac_txpower_setup(ar, txpower);
3952 if (ret) {
3953 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
3954 txpower, ret);
3955 return ret;
3956 }
3957
3958 return 0;
3959}
3960
Kalle Valo5e3dd152013-06-12 20:52:10 +03003961static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
3962{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003963 struct ath10k *ar = hw->priv;
3964 struct ieee80211_conf *conf = &hw->conf;
3965 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003966
3967 mutex_lock(&ar->conf_mutex);
3968
Michal Kazioraffd3212013-07-16 09:54:35 +02003969 if (changed & IEEE80211_CONF_CHANGE_PS)
3970 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003971
3972 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
Michal Kazior19337472014-08-28 12:58:16 +02003973 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
3974 ret = ath10k_monitor_recalc(ar);
3975 if (ret)
3976 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003977 }
3978
3979 mutex_unlock(&ar->conf_mutex);
3980 return ret;
3981}
3982
Ben Greear5572a952014-11-24 16:22:10 +02003983static u32 get_nss_from_chainmask(u16 chain_mask)
3984{
3985 if ((chain_mask & 0x15) == 0x15)
3986 return 4;
3987 else if ((chain_mask & 0x7) == 0x7)
3988 return 3;
3989 else if ((chain_mask & 0x3) == 0x3)
3990 return 2;
3991 return 1;
3992}
3993
Kalle Valo5e3dd152013-06-12 20:52:10 +03003994/*
3995 * TODO:
3996 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
3997 * because we will send mgmt frames without CCK. This requirement
3998 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
3999 * in the TX packet.
4000 */
4001static int ath10k_add_interface(struct ieee80211_hw *hw,
4002 struct ieee80211_vif *vif)
4003{
4004 struct ath10k *ar = hw->priv;
4005 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4006 enum wmi_sta_powersave_param param;
4007 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02004008 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004009 int bit;
Michal Kazior96d828d2015-03-31 10:26:23 +00004010 int i;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004011 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004012
Johannes Berg848955c2014-11-11 12:48:42 +01004013 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
4014
Kalle Valo5e3dd152013-06-12 20:52:10 +03004015 mutex_lock(&ar->conf_mutex);
4016
Michal Kazior0dbd09e2013-07-31 10:55:14 +02004017 memset(arvif, 0, sizeof(*arvif));
4018
Kalle Valo5e3dd152013-06-12 20:52:10 +03004019 arvif->ar = ar;
4020 arvif->vif = vif;
4021
Ben Greeare63b33f2013-10-22 14:54:14 -07004022 INIT_LIST_HEAD(&arvif->list);
Michal Kazior81a9a172015-03-05 16:02:17 +02004023 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
Michal Kaziorcc9904e2015-03-10 16:22:01 +02004024 INIT_DELAYED_WORK(&arvif->connection_loss_work,
4025 ath10k_mac_vif_sta_connection_loss_work);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03004026
Ben Greeara9aefb32014-08-12 11:02:19 +03004027 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004028 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03004029 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03004030 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004031 }
Ben Greear16c11172014-09-23 14:17:16 -07004032 bit = __ffs64(ar->free_vdev_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004033
Ben Greear16c11172014-09-23 14:17:16 -07004034 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
4035 bit, ar->free_vdev_map);
4036
4037 arvif->vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004038 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004039
Kalle Valo5e3dd152013-06-12 20:52:10 +03004040 switch (vif->type) {
Michal Kazior75d2bd42014-12-12 12:41:39 +01004041 case NL80211_IFTYPE_P2P_DEVICE:
4042 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4043 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
4044 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004045 case NL80211_IFTYPE_UNSPECIFIED:
4046 case NL80211_IFTYPE_STATION:
4047 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4048 if (vif->p2p)
4049 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
4050 break;
4051 case NL80211_IFTYPE_ADHOC:
4052 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
4053 break;
4054 case NL80211_IFTYPE_AP:
4055 arvif->vdev_type = WMI_VDEV_TYPE_AP;
4056
4057 if (vif->p2p)
4058 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
4059 break;
4060 case NL80211_IFTYPE_MONITOR:
4061 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
4062 break;
4063 default:
4064 WARN_ON(1);
4065 break;
4066 }
4067
Michal Kazior96d828d2015-03-31 10:26:23 +00004068 /* Using vdev_id as queue number will make it very easy to do per-vif
4069 * tx queue locking. This shouldn't wrap due to interface combinations
4070 * but do a modulo for correctness sake and prevent using offchannel tx
4071 * queues for regular vif tx.
4072 */
4073 vif->cab_queue = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
4074 for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++)
4075 vif->hw_queue[i] = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
4076
Michal Kazior64badcb2014-09-18 11:18:02 +03004077 /* Some firmware revisions don't wait for beacon tx completion before
4078 * sending another SWBA event. This could lead to hardware using old
4079 * (freed) beacon data in some cases, e.g. tx credit starvation
4080 * combined with missed TBTT. This is very very rare.
4081 *
4082 * On non-IOMMU-enabled hosts this could be a possible security issue
4083 * because hw could beacon some random data on the air. On
4084 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
4085 * device would crash.
4086 *
4087 * Since there are no beacon tx completions (implicit nor explicit)
4088 * propagated to host the only workaround for this is to allocate a
4089 * DMA-coherent buffer for a lifetime of a vif and use it for all
4090 * beacon tx commands. Worst case for this approach is some beacons may
4091 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
4092 */
4093 if (vif->type == NL80211_IFTYPE_ADHOC ||
4094 vif->type == NL80211_IFTYPE_AP) {
4095 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
4096 IEEE80211_MAX_FRAME_LEN,
4097 &arvif->beacon_paddr,
Rajkumar Manoharan82d7aba2014-10-10 17:38:27 +05304098 GFP_ATOMIC);
Michal Kazior64badcb2014-09-18 11:18:02 +03004099 if (!arvif->beacon_buf) {
4100 ret = -ENOMEM;
4101 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
4102 ret);
4103 goto err;
4104 }
4105 }
4106
4107 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
4108 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
4109 arvif->beacon_buf ? "single-buf" : "per-skb");
Kalle Valo5e3dd152013-06-12 20:52:10 +03004110
4111 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
4112 arvif->vdev_subtype, vif->addr);
4113 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004114 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004115 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004116 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004117 }
4118
Ben Greear16c11172014-09-23 14:17:16 -07004119 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03004120 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004121
Michal Kazior46725b152015-01-28 09:57:49 +02004122 /* It makes no sense to have firmware do keepalives. mac80211 already
4123 * takes care of this with idle connection polling.
4124 */
4125 ret = ath10k_mac_vif_disable_keepalive(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004126 if (ret) {
Michal Kazior46725b152015-01-28 09:57:49 +02004127 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004128 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004129 goto err_vdev_delete;
4130 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004131
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004132 arvif->def_wep_key_idx = -1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004133
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004134 vdev_param = ar->wmi.vdev_param->tx_encap_type;
4135 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004136 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02004137 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14a2013-10-16 15:44:45 +03004138 if (ret && ret != -EOPNOTSUPP) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004139 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004140 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004141 goto err_vdev_delete;
4142 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004143
Ben Greear5572a952014-11-24 16:22:10 +02004144 if (ar->cfg_tx_chainmask) {
4145 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
4146
4147 vdev_param = ar->wmi.vdev_param->nss;
4148 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4149 nss);
4150 if (ret) {
4151 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
4152 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
4153 ret);
4154 goto err_vdev_delete;
4155 }
4156 }
4157
Kalle Valo5e3dd152013-06-12 20:52:10 +03004158 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
Marek Puzyniak7390ed32015-03-30 09:51:52 +03004159 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr,
4160 WMI_PEER_TYPE_DEFAULT);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004161 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004162 ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004163 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004164 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004165 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01004166
Kalle Valo5a13e762014-01-20 11:01:46 +02004167 ret = ath10k_mac_set_kickout(arvif);
4168 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004169 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004170 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +02004171 goto err_peer_delete;
4172 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004173 }
4174
4175 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
4176 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
4177 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4178 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4179 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004180 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004181 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004182 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004183 goto err_peer_delete;
4184 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004185
Michal Kazior9f9b5742014-12-12 12:41:36 +01004186 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004187 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01004188 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004189 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004190 goto err_peer_delete;
4191 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004192
Michal Kazior9f9b5742014-12-12 12:41:36 +01004193 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004194 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01004195 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004196 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004197 goto err_peer_delete;
4198 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004199 }
4200
Michal Kazior424121c2013-07-22 14:13:31 +02004201 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004202 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004203 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03004204 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004205 goto err_peer_delete;
4206 }
Michal Kazior679c54a2013-07-05 16:15:04 +03004207
Michal Kazior424121c2013-07-22 14:13:31 +02004208 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004209 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004210 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03004211 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004212 goto err_peer_delete;
4213 }
Michal Kazior679c54a2013-07-05 16:15:04 +03004214
Michal Kazior7d9d5582014-10-21 10:40:15 +03004215 arvif->txpower = vif->bss_conf.txpower;
4216 ret = ath10k_mac_txpower_recalc(ar);
4217 if (ret) {
4218 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
4219 goto err_peer_delete;
4220 }
4221
Michal Kazior500ff9f2015-03-31 10:26:21 +00004222 if (vif->type == NL80211_IFTYPE_MONITOR) {
4223 ar->monitor_arvif = arvif;
4224 ret = ath10k_monitor_recalc(ar);
4225 if (ret) {
4226 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4227 goto err_peer_delete;
4228 }
4229 }
4230
Kalle Valo5e3dd152013-06-12 20:52:10 +03004231 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004232 return 0;
4233
4234err_peer_delete:
4235 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
4236 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
4237
4238err_vdev_delete:
4239 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
Ben Greear16c11172014-09-23 14:17:16 -07004240 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03004241 list_del(&arvif->list);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004242
4243err:
Michal Kazior64badcb2014-09-18 11:18:02 +03004244 if (arvif->beacon_buf) {
4245 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
4246 arvif->beacon_buf, arvif->beacon_paddr);
4247 arvif->beacon_buf = NULL;
4248 }
4249
Michal Kazior9dad14a2013-10-16 15:44:45 +03004250 mutex_unlock(&ar->conf_mutex);
4251
Kalle Valo5e3dd152013-06-12 20:52:10 +03004252 return ret;
4253}
4254
Michal Kaziorb4aa5392015-03-31 10:26:24 +00004255static void ath10k_mac_vif_tx_unlock_all(struct ath10k_vif *arvif)
4256{
4257 int i;
4258
4259 for (i = 0; i < BITS_PER_LONG; i++)
4260 ath10k_mac_vif_tx_unlock(arvif, i);
4261}
4262
Kalle Valo5e3dd152013-06-12 20:52:10 +03004263static void ath10k_remove_interface(struct ieee80211_hw *hw,
4264 struct ieee80211_vif *vif)
4265{
4266 struct ath10k *ar = hw->priv;
4267 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4268 int ret;
4269
Michal Kazior81a9a172015-03-05 16:02:17 +02004270 cancel_work_sync(&arvif->ap_csa_work);
Michal Kaziorcc9904e2015-03-10 16:22:01 +02004271 cancel_delayed_work_sync(&arvif->connection_loss_work);
Michal Kazior81a9a172015-03-05 16:02:17 +02004272
Sujith Manoharan5d011f52014-11-25 11:47:00 +05304273 mutex_lock(&ar->conf_mutex);
4274
Michal Kaziored543882013-09-13 14:16:56 +02004275 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03004276 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kaziored543882013-09-13 14:16:56 +02004277 spin_unlock_bh(&ar->data_lock);
4278
Simon Wunderlich855aed12014-08-02 09:12:54 +03004279 ret = ath10k_spectral_vif_stop(arvif);
4280 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004281 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03004282 arvif->vdev_id, ret);
4283
Ben Greear16c11172014-09-23 14:17:16 -07004284 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03004285 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004286
4287 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
Michal Kazior2c512052015-02-15 16:50:40 +02004288 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
4289 vif->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004290 if (ret)
Michal Kazior2c512052015-02-15 16:50:40 +02004291 ath10k_warn(ar, "failed to submit AP self-peer removal on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004292 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004293
4294 kfree(arvif->u.ap.noa_data);
4295 }
4296
Michal Kazior7aa7a722014-08-25 12:09:38 +02004297 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004298 arvif->vdev_id);
4299
Kalle Valo5e3dd152013-06-12 20:52:10 +03004300 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
4301 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004302 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004303 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004304
Michal Kazior2c512052015-02-15 16:50:40 +02004305 /* Some firmware revisions don't notify host about self-peer removal
4306 * until after associated vdev is deleted.
4307 */
4308 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
4309 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
4310 vif->addr);
4311 if (ret)
4312 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
4313 arvif->vdev_id, ret);
4314
4315 spin_lock_bh(&ar->data_lock);
4316 ar->num_peers--;
4317 spin_unlock_bh(&ar->data_lock);
4318 }
4319
Kalle Valo5e3dd152013-06-12 20:52:10 +03004320 ath10k_peer_cleanup(ar, arvif->vdev_id);
4321
Michal Kazior500ff9f2015-03-31 10:26:21 +00004322 if (vif->type == NL80211_IFTYPE_MONITOR) {
4323 ar->monitor_arvif = NULL;
4324 ret = ath10k_monitor_recalc(ar);
4325 if (ret)
4326 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4327 }
4328
Michal Kaziorb4aa5392015-03-31 10:26:24 +00004329 spin_lock_bh(&ar->htt.tx_lock);
4330 ath10k_mac_vif_tx_unlock_all(arvif);
4331 spin_unlock_bh(&ar->htt.tx_lock);
4332
Kalle Valo5e3dd152013-06-12 20:52:10 +03004333 mutex_unlock(&ar->conf_mutex);
4334}
4335
4336/*
4337 * FIXME: Has to be verified.
4338 */
4339#define SUPPORTED_FILTERS \
4340 (FIF_PROMISC_IN_BSS | \
4341 FIF_ALLMULTI | \
4342 FIF_CONTROL | \
4343 FIF_PSPOLL | \
4344 FIF_OTHER_BSS | \
4345 FIF_BCN_PRBRESP_PROMISC | \
4346 FIF_PROBE_REQ | \
4347 FIF_FCSFAIL)
4348
4349static void ath10k_configure_filter(struct ieee80211_hw *hw,
4350 unsigned int changed_flags,
4351 unsigned int *total_flags,
4352 u64 multicast)
4353{
4354 struct ath10k *ar = hw->priv;
4355 int ret;
4356
4357 mutex_lock(&ar->conf_mutex);
4358
4359 changed_flags &= SUPPORTED_FILTERS;
4360 *total_flags &= SUPPORTED_FILTERS;
4361 ar->filter_flags = *total_flags;
4362
Michal Kazior19337472014-08-28 12:58:16 +02004363 ret = ath10k_monitor_recalc(ar);
4364 if (ret)
4365 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004366
4367 mutex_unlock(&ar->conf_mutex);
4368}
4369
4370static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
4371 struct ieee80211_vif *vif,
4372 struct ieee80211_bss_conf *info,
4373 u32 changed)
4374{
4375 struct ath10k *ar = hw->priv;
4376 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4377 int ret = 0;
Kalle Valoaf762c02014-09-14 12:50:17 +03004378 u32 vdev_param, pdev_param, slottime, preamble;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004379
4380 mutex_lock(&ar->conf_mutex);
4381
4382 if (changed & BSS_CHANGED_IBSS)
4383 ath10k_control_ibss(arvif, info, vif->addr);
4384
4385 if (changed & BSS_CHANGED_BEACON_INT) {
4386 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004387 vdev_param = ar->wmi.vdev_param->beacon_interval;
4388 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004389 arvif->beacon_interval);
Michal Kazior7aa7a722014-08-25 12:09:38 +02004390 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004391 "mac vdev %d beacon_interval %d\n",
4392 arvif->vdev_id, arvif->beacon_interval);
4393
Kalle Valo5e3dd152013-06-12 20:52:10 +03004394 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004395 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004396 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004397 }
4398
4399 if (changed & BSS_CHANGED_BEACON) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004400 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004401 "vdev %d set beacon tx mode to staggered\n",
4402 arvif->vdev_id);
4403
Bartosz Markowski226a3392013-09-26 17:47:16 +02004404 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
4405 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004406 WMI_BEACON_STAGGERED_MODE);
4407 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004408 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004409 arvif->vdev_id, ret);
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02004410
4411 ret = ath10k_mac_setup_bcn_tmpl(arvif);
4412 if (ret)
4413 ath10k_warn(ar, "failed to update beacon template: %d\n",
4414 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004415 }
4416
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02004417 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
4418 ret = ath10k_mac_setup_prb_tmpl(arvif);
4419 if (ret)
4420 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
4421 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004422 }
4423
Michal Kaziorba2479f2015-01-24 12:14:51 +02004424 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004425 arvif->dtim_period = info->dtim_period;
4426
Michal Kazior7aa7a722014-08-25 12:09:38 +02004427 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004428 "mac vdev %d dtim_period %d\n",
4429 arvif->vdev_id, arvif->dtim_period);
4430
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004431 vdev_param = ar->wmi.vdev_param->dtim_period;
4432 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004433 arvif->dtim_period);
4434 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004435 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004436 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004437 }
4438
4439 if (changed & BSS_CHANGED_SSID &&
4440 vif->type == NL80211_IFTYPE_AP) {
4441 arvif->u.ap.ssid_len = info->ssid_len;
4442 if (info->ssid_len)
4443 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
4444 arvif->u.ap.hidden_ssid = info->hidden_ssid;
4445 }
4446
Michal Kazior077efc82014-10-21 10:10:29 +03004447 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
4448 ether_addr_copy(arvif->bssid, info->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004449
4450 if (changed & BSS_CHANGED_BEACON_ENABLED)
4451 ath10k_control_beaconing(arvif, info);
4452
4453 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02004454 arvif->use_cts_prot = info->use_cts_prot;
Michal Kazior7aa7a722014-08-25 12:09:38 +02004455 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02004456 arvif->vdev_id, info->use_cts_prot);
Kalle Valo60c3daa2013-09-08 17:56:07 +03004457
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02004458 ret = ath10k_recalc_rtscts_prot(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004459 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004460 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004461 arvif->vdev_id, ret);
Michal Kaziora87fd4b2015-03-02 11:21:17 +01004462
4463 vdev_param = ar->wmi.vdev_param->protection_mode;
4464 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4465 info->use_cts_prot ? 1 : 0);
4466 if (ret)
4467 ath10k_warn(ar, "failed to set protection mode %d on vdev %i: %d\n",
4468 info->use_cts_prot, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004469 }
4470
4471 if (changed & BSS_CHANGED_ERP_SLOT) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004472 if (info->use_short_slot)
4473 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
4474
4475 else
4476 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
4477
Michal Kazior7aa7a722014-08-25 12:09:38 +02004478 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004479 arvif->vdev_id, slottime);
4480
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004481 vdev_param = ar->wmi.vdev_param->slot_time;
4482 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004483 slottime);
4484 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004485 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004486 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004487 }
4488
4489 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004490 if (info->use_short_preamble)
4491 preamble = WMI_VDEV_PREAMBLE_SHORT;
4492 else
4493 preamble = WMI_VDEV_PREAMBLE_LONG;
4494
Michal Kazior7aa7a722014-08-25 12:09:38 +02004495 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004496 "mac vdev %d preamble %dn",
4497 arvif->vdev_id, preamble);
4498
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004499 vdev_param = ar->wmi.vdev_param->preamble;
4500 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004501 preamble);
4502 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004503 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004504 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004505 }
4506
4507 if (changed & BSS_CHANGED_ASSOC) {
Michal Kaziore556f112014-08-28 12:58:17 +02004508 if (info->assoc) {
4509 /* Workaround: Make sure monitor vdev is not running
4510 * when associating to prevent some firmware revisions
4511 * (e.g. 10.1 and 10.2) from crashing.
4512 */
4513 if (ar->monitor_started)
4514 ath10k_monitor_stop(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004515 ath10k_bss_assoc(hw, vif, info);
Michal Kaziore556f112014-08-28 12:58:17 +02004516 ath10k_monitor_recalc(ar);
Michal Kazior077efc82014-10-21 10:10:29 +03004517 } else {
4518 ath10k_bss_disassoc(hw, vif);
Michal Kaziore556f112014-08-28 12:58:17 +02004519 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004520 }
4521
Michal Kazior7d9d5582014-10-21 10:40:15 +03004522 if (changed & BSS_CHANGED_TXPOWER) {
4523 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
4524 arvif->vdev_id, info->txpower);
4525
4526 arvif->txpower = info->txpower;
4527 ret = ath10k_mac_txpower_recalc(ar);
4528 if (ret)
4529 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
4530 }
4531
Michal Kaziorbf14e652014-12-12 12:41:38 +01004532 if (changed & BSS_CHANGED_PS) {
Michal Kaziorcffb41f2015-02-13 13:30:16 +01004533 arvif->ps = vif->bss_conf.ps;
4534
4535 ret = ath10k_config_ps(ar);
Michal Kaziorbf14e652014-12-12 12:41:38 +01004536 if (ret)
4537 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
4538 arvif->vdev_id, ret);
4539 }
4540
Kalle Valo5e3dd152013-06-12 20:52:10 +03004541 mutex_unlock(&ar->conf_mutex);
4542}
4543
4544static int ath10k_hw_scan(struct ieee80211_hw *hw,
4545 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02004546 struct ieee80211_scan_request *hw_req)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004547{
4548 struct ath10k *ar = hw->priv;
4549 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
David Spinadelc56ef672014-02-05 15:21:13 +02004550 struct cfg80211_scan_request *req = &hw_req->req;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004551 struct wmi_start_scan_arg arg;
4552 int ret = 0;
4553 int i;
4554
4555 mutex_lock(&ar->conf_mutex);
4556
4557 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004558 switch (ar->scan.state) {
4559 case ATH10K_SCAN_IDLE:
4560 reinit_completion(&ar->scan.started);
4561 reinit_completion(&ar->scan.completed);
4562 ar->scan.state = ATH10K_SCAN_STARTING;
4563 ar->scan.is_roc = false;
4564 ar->scan.vdev_id = arvif->vdev_id;
4565 ret = 0;
4566 break;
4567 case ATH10K_SCAN_STARTING:
4568 case ATH10K_SCAN_RUNNING:
4569 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004570 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004571 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004572 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004573 spin_unlock_bh(&ar->data_lock);
4574
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004575 if (ret)
4576 goto exit;
4577
Kalle Valo5e3dd152013-06-12 20:52:10 +03004578 memset(&arg, 0, sizeof(arg));
4579 ath10k_wmi_start_scan_init(ar, &arg);
4580 arg.vdev_id = arvif->vdev_id;
4581 arg.scan_id = ATH10K_SCAN_ID;
4582
4583 if (!req->no_cck)
4584 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
4585
4586 if (req->ie_len) {
4587 arg.ie_len = req->ie_len;
4588 memcpy(arg.ie, req->ie, arg.ie_len);
4589 }
4590
4591 if (req->n_ssids) {
4592 arg.n_ssids = req->n_ssids;
4593 for (i = 0; i < arg.n_ssids; i++) {
4594 arg.ssids[i].len = req->ssids[i].ssid_len;
4595 arg.ssids[i].ssid = req->ssids[i].ssid;
4596 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02004597 } else {
4598 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004599 }
4600
4601 if (req->n_channels) {
4602 arg.n_channels = req->n_channels;
4603 for (i = 0; i < arg.n_channels; i++)
4604 arg.channels[i] = req->channels[i]->center_freq;
4605 }
4606
4607 ret = ath10k_start_scan(ar, &arg);
4608 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004609 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004610 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004611 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004612 spin_unlock_bh(&ar->data_lock);
4613 }
4614
4615exit:
4616 mutex_unlock(&ar->conf_mutex);
4617 return ret;
4618}
4619
4620static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
4621 struct ieee80211_vif *vif)
4622{
4623 struct ath10k *ar = hw->priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004624
4625 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004626 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004627 mutex_unlock(&ar->conf_mutex);
Michal Kazior4eb2e162014-10-28 10:23:09 +01004628
4629 cancel_delayed_work_sync(&ar->scan.timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004630}
4631
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004632static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
4633 struct ath10k_vif *arvif,
4634 enum set_key_cmd cmd,
4635 struct ieee80211_key_conf *key)
4636{
4637 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
4638 int ret;
4639
4640 /* 10.1 firmware branch requires default key index to be set to group
4641 * key index after installing it. Otherwise FW/HW Txes corrupted
4642 * frames with multi-vif APs. This is not required for main firmware
4643 * branch (e.g. 636).
4644 *
4645 * FIXME: This has been tested only in AP. It remains unknown if this
4646 * is required for multi-vif STA interfaces on 10.1 */
4647
4648 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
4649 return;
4650
4651 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
4652 return;
4653
4654 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
4655 return;
4656
4657 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4658 return;
4659
4660 if (cmd != SET_KEY)
4661 return;
4662
4663 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4664 key->keyidx);
4665 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004666 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004667 arvif->vdev_id, ret);
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004668}
4669
Kalle Valo5e3dd152013-06-12 20:52:10 +03004670static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
4671 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
4672 struct ieee80211_key_conf *key)
4673{
4674 struct ath10k *ar = hw->priv;
4675 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4676 struct ath10k_peer *peer;
4677 const u8 *peer_addr;
4678 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
4679 key->cipher == WLAN_CIPHER_SUITE_WEP104;
4680 int ret = 0;
Michal Kazior370e5672015-02-18 14:02:26 +01004681 u32 flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004682
Bartosz Markowskid7131c02015-03-10 14:32:19 +01004683 /* this one needs to be done in software */
4684 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
4685 return 1;
4686
Kalle Valo5e3dd152013-06-12 20:52:10 +03004687 if (key->keyidx > WMI_MAX_KEY_INDEX)
4688 return -ENOSPC;
4689
4690 mutex_lock(&ar->conf_mutex);
4691
4692 if (sta)
4693 peer_addr = sta->addr;
4694 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
4695 peer_addr = vif->bss_conf.bssid;
4696 else
4697 peer_addr = vif->addr;
4698
4699 key->hw_key_idx = key->keyidx;
4700
4701 /* the peer should not disappear in mid-way (unless FW goes awry) since
4702 * we already hold conf_mutex. we just make sure its there now. */
4703 spin_lock_bh(&ar->data_lock);
4704 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4705 spin_unlock_bh(&ar->data_lock);
4706
4707 if (!peer) {
4708 if (cmd == SET_KEY) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004709 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03004710 peer_addr);
4711 ret = -EOPNOTSUPP;
4712 goto exit;
4713 } else {
4714 /* if the peer doesn't exist there is no key to disable
4715 * anymore */
4716 goto exit;
4717 }
4718 }
4719
Michal Kazior7cc45732015-03-09 14:24:17 +01004720 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4721 flags |= WMI_KEY_PAIRWISE;
4722 else
4723 flags |= WMI_KEY_GROUP;
4724
Kalle Valo5e3dd152013-06-12 20:52:10 +03004725 if (is_wep) {
4726 if (cmd == SET_KEY)
4727 arvif->wep_keys[key->keyidx] = key;
4728 else
4729 arvif->wep_keys[key->keyidx] = NULL;
4730
4731 if (cmd == DISABLE_KEY)
4732 ath10k_clear_vdev_key(arvif, key);
Michal Kazior370e5672015-02-18 14:02:26 +01004733
Michal Kaziorad325cb2015-02-18 14:02:27 +01004734 /* When WEP keys are uploaded it's possible that there are
4735 * stations associated already (e.g. when merging) without any
4736 * keys. Static WEP needs an explicit per-peer key upload.
4737 */
4738 if (vif->type == NL80211_IFTYPE_ADHOC &&
4739 cmd == SET_KEY)
4740 ath10k_mac_vif_update_wep_key(arvif, key);
4741
Michal Kazior370e5672015-02-18 14:02:26 +01004742 /* 802.1x never sets the def_wep_key_idx so each set_key()
4743 * call changes default tx key.
4744 *
4745 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
4746 * after first set_key().
4747 */
4748 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
4749 flags |= WMI_KEY_TX_USAGE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004750
Michal Kazior7cc45732015-03-09 14:24:17 +01004751 /* mac80211 uploads static WEP keys as groupwise while fw/hw
4752 * requires pairwise keys for non-self peers, i.e. BSSID in STA
4753 * mode and associated stations in AP/IBSS.
4754 *
4755 * Static WEP keys for peer_addr=vif->addr and 802.1X WEP keys
4756 * work fine when mapped directly from mac80211.
4757 *
4758 * Note: When installing first static WEP groupwise key (which
4759 * should be pairwise) def_wep_key_idx isn't known yet (it's
4760 * equal to -1). Since .set_default_unicast_key is called only
4761 * for static WEP it's used to re-upload the key as pairwise.
4762 */
4763 if (arvif->def_wep_key_idx >= 0 &&
4764 memcmp(peer_addr, arvif->vif->addr, ETH_ALEN)) {
4765 flags &= ~WMI_KEY_GROUP;
4766 flags |= WMI_KEY_PAIRWISE;
4767 }
Michal Kazior370e5672015-02-18 14:02:26 +01004768 }
4769
4770 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004771 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004772 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004773 arvif->vdev_id, peer_addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004774 goto exit;
4775 }
4776
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004777 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
4778
Kalle Valo5e3dd152013-06-12 20:52:10 +03004779 spin_lock_bh(&ar->data_lock);
4780 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4781 if (peer && cmd == SET_KEY)
4782 peer->keys[key->keyidx] = key;
4783 else if (peer && cmd == DISABLE_KEY)
4784 peer->keys[key->keyidx] = NULL;
4785 else if (peer == NULL)
4786 /* impossible unless FW goes crazy */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004787 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004788 spin_unlock_bh(&ar->data_lock);
4789
4790exit:
4791 mutex_unlock(&ar->conf_mutex);
4792 return ret;
4793}
4794
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004795static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
4796 struct ieee80211_vif *vif,
4797 int keyidx)
4798{
4799 struct ath10k *ar = hw->priv;
4800 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4801 int ret;
4802
4803 mutex_lock(&arvif->ar->conf_mutex);
4804
4805 if (arvif->ar->state != ATH10K_STATE_ON)
4806 goto unlock;
4807
4808 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
4809 arvif->vdev_id, keyidx);
4810
4811 ret = ath10k_wmi_vdev_set_param(arvif->ar,
4812 arvif->vdev_id,
4813 arvif->ar->wmi.vdev_param->def_keyid,
4814 keyidx);
4815
4816 if (ret) {
4817 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
4818 arvif->vdev_id,
4819 ret);
4820 goto unlock;
4821 }
4822
4823 arvif->def_wep_key_idx = keyidx;
Michal Kazior370e5672015-02-18 14:02:26 +01004824
4825 ret = ath10k_mac_vif_sta_fix_wep_key(arvif);
4826 if (ret) {
4827 ath10k_warn(ar, "failed to fix sta wep key on vdev %i: %d\n",
4828 arvif->vdev_id, ret);
4829 goto unlock;
4830 }
4831
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004832unlock:
4833 mutex_unlock(&arvif->ar->conf_mutex);
4834}
4835
Michal Kazior9797feb2014-02-14 14:49:48 +01004836static void ath10k_sta_rc_update_wk(struct work_struct *wk)
4837{
4838 struct ath10k *ar;
4839 struct ath10k_vif *arvif;
4840 struct ath10k_sta *arsta;
4841 struct ieee80211_sta *sta;
4842 u32 changed, bw, nss, smps;
4843 int err;
4844
4845 arsta = container_of(wk, struct ath10k_sta, update_wk);
4846 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
4847 arvif = arsta->arvif;
4848 ar = arvif->ar;
4849
4850 spin_lock_bh(&ar->data_lock);
4851
4852 changed = arsta->changed;
4853 arsta->changed = 0;
4854
4855 bw = arsta->bw;
4856 nss = arsta->nss;
4857 smps = arsta->smps;
4858
4859 spin_unlock_bh(&ar->data_lock);
4860
4861 mutex_lock(&ar->conf_mutex);
4862
4863 if (changed & IEEE80211_RC_BW_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004864 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004865 sta->addr, bw);
4866
4867 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4868 WMI_PEER_CHAN_WIDTH, bw);
4869 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004870 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004871 sta->addr, bw, err);
4872 }
4873
4874 if (changed & IEEE80211_RC_NSS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004875 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004876 sta->addr, nss);
4877
4878 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4879 WMI_PEER_NSS, nss);
4880 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004881 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004882 sta->addr, nss, err);
4883 }
4884
4885 if (changed & IEEE80211_RC_SMPS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004886 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004887 sta->addr, smps);
4888
4889 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4890 WMI_PEER_SMPS_STATE, smps);
4891 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004892 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004893 sta->addr, smps, err);
4894 }
4895
Janusz Dziedzic55884c02014-12-17 12:30:02 +02004896 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
4897 changed & IEEE80211_RC_NSS_CHANGED) {
4898 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004899 sta->addr);
4900
Michal Kazior590922a2014-10-21 10:10:29 +03004901 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004902 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004903 ath10k_warn(ar, "failed to reassociate station: %pM\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004904 sta->addr);
4905 }
4906
Michal Kazior9797feb2014-02-14 14:49:48 +01004907 mutex_unlock(&ar->conf_mutex);
4908}
4909
Marek Puzyniak7c354242015-03-30 09:51:52 +03004910static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif,
4911 struct ieee80211_sta *sta)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004912{
4913 struct ath10k *ar = arvif->ar;
4914
4915 lockdep_assert_held(&ar->conf_mutex);
4916
Marek Puzyniak7c354242015-03-30 09:51:52 +03004917 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004918 return 0;
4919
4920 if (ar->num_stations >= ar->max_num_stations)
4921 return -ENOBUFS;
4922
4923 ar->num_stations++;
4924
4925 return 0;
4926}
4927
Marek Puzyniak7c354242015-03-30 09:51:52 +03004928static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif,
4929 struct ieee80211_sta *sta)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004930{
4931 struct ath10k *ar = arvif->ar;
4932
4933 lockdep_assert_held(&ar->conf_mutex);
4934
Marek Puzyniak7c354242015-03-30 09:51:52 +03004935 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004936 return;
4937
4938 ar->num_stations--;
4939}
4940
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004941struct ath10k_mac_tdls_iter_data {
4942 u32 num_tdls_stations;
4943 struct ieee80211_vif *curr_vif;
4944};
4945
4946static void ath10k_mac_tdls_vif_stations_count_iter(void *data,
4947 struct ieee80211_sta *sta)
4948{
4949 struct ath10k_mac_tdls_iter_data *iter_data = data;
4950 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
4951 struct ieee80211_vif *sta_vif = arsta->arvif->vif;
4952
4953 if (sta->tdls && sta_vif == iter_data->curr_vif)
4954 iter_data->num_tdls_stations++;
4955}
4956
4957static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw *hw,
4958 struct ieee80211_vif *vif)
4959{
4960 struct ath10k_mac_tdls_iter_data data = {};
4961
4962 data.curr_vif = vif;
4963
4964 ieee80211_iterate_stations_atomic(hw,
4965 ath10k_mac_tdls_vif_stations_count_iter,
4966 &data);
4967 return data.num_tdls_stations;
4968}
4969
4970static void ath10k_mac_tdls_vifs_count_iter(void *data, u8 *mac,
4971 struct ieee80211_vif *vif)
4972{
4973 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4974 int *num_tdls_vifs = data;
4975
4976 if (vif->type != NL80211_IFTYPE_STATION)
4977 return;
4978
4979 if (ath10k_mac_tdls_vif_stations_count(arvif->ar->hw, vif) > 0)
4980 (*num_tdls_vifs)++;
4981}
4982
4983static int ath10k_mac_tdls_vifs_count(struct ieee80211_hw *hw)
4984{
4985 int num_tdls_vifs = 0;
4986
4987 ieee80211_iterate_active_interfaces_atomic(hw,
4988 IEEE80211_IFACE_ITER_NORMAL,
4989 ath10k_mac_tdls_vifs_count_iter,
4990 &num_tdls_vifs);
4991 return num_tdls_vifs;
4992}
4993
Kalle Valo5e3dd152013-06-12 20:52:10 +03004994static int ath10k_sta_state(struct ieee80211_hw *hw,
4995 struct ieee80211_vif *vif,
4996 struct ieee80211_sta *sta,
4997 enum ieee80211_sta_state old_state,
4998 enum ieee80211_sta_state new_state)
4999{
5000 struct ath10k *ar = hw->priv;
5001 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01005002 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005003 int ret = 0;
5004
Michal Kazior76f90022014-02-25 09:29:57 +02005005 if (old_state == IEEE80211_STA_NOTEXIST &&
5006 new_state == IEEE80211_STA_NONE) {
5007 memset(arsta, 0, sizeof(*arsta));
5008 arsta->arvif = arvif;
5009 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
5010 }
5011
Michal Kazior9797feb2014-02-14 14:49:48 +01005012 /* cancel must be done outside the mutex to avoid deadlock */
5013 if ((old_state == IEEE80211_STA_NONE &&
5014 new_state == IEEE80211_STA_NOTEXIST))
5015 cancel_work_sync(&arsta->update_wk);
5016
Kalle Valo5e3dd152013-06-12 20:52:10 +03005017 mutex_lock(&ar->conf_mutex);
5018
5019 if (old_state == IEEE80211_STA_NOTEXIST &&
Michal Kazior077efc82014-10-21 10:10:29 +03005020 new_state == IEEE80211_STA_NONE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03005021 /*
5022 * New station addition.
5023 */
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005024 enum wmi_peer_type peer_type = WMI_PEER_TYPE_DEFAULT;
5025 u32 num_tdls_stations;
5026 u32 num_tdls_vifs;
5027
Michal Kaziorcfd10612014-11-25 15:16:05 +01005028 ath10k_dbg(ar, ATH10K_DBG_MAC,
5029 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
5030 arvif->vdev_id, sta->addr,
5031 ar->num_stations + 1, ar->max_num_stations,
5032 ar->num_peers + 1, ar->max_num_peers);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01005033
Marek Puzyniak7c354242015-03-30 09:51:52 +03005034 ret = ath10k_mac_inc_num_stations(arvif, sta);
Michal Kaziorcfd10612014-11-25 15:16:05 +01005035 if (ret) {
5036 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
5037 ar->max_num_stations);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01005038 goto exit;
5039 }
5040
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005041 if (sta->tdls)
5042 peer_type = WMI_PEER_TYPE_TDLS;
5043
Marek Puzyniak7390ed32015-03-30 09:51:52 +03005044 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr,
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005045 peer_type);
Michal Kaziora52c0282014-11-25 15:16:03 +01005046 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005047 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 -08005048 sta->addr, arvif->vdev_id, ret);
Marek Puzyniak7c354242015-03-30 09:51:52 +03005049 ath10k_mac_dec_num_stations(arvif, sta);
Michal Kaziora52c0282014-11-25 15:16:03 +01005050 goto exit;
5051 }
Michal Kazior077efc82014-10-21 10:10:29 +03005052
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005053 if (!sta->tdls)
5054 goto exit;
5055
5056 num_tdls_stations = ath10k_mac_tdls_vif_stations_count(hw, vif);
5057 num_tdls_vifs = ath10k_mac_tdls_vifs_count(hw);
5058
5059 if (num_tdls_vifs >= ar->max_num_tdls_vdevs &&
5060 num_tdls_stations == 0) {
5061 ath10k_warn(ar, "vdev %i exceeded maximum number of tdls vdevs %i\n",
5062 arvif->vdev_id, ar->max_num_tdls_vdevs);
5063 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5064 ath10k_mac_dec_num_stations(arvif, sta);
5065 ret = -ENOBUFS;
5066 goto exit;
5067 }
5068
5069 if (num_tdls_stations == 0) {
5070 /* This is the first tdls peer in current vif */
5071 enum wmi_tdls_state state = WMI_TDLS_ENABLE_ACTIVE;
5072
5073 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5074 state);
5075 if (ret) {
5076 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
5077 arvif->vdev_id, ret);
5078 ath10k_peer_delete(ar, arvif->vdev_id,
5079 sta->addr);
5080 ath10k_mac_dec_num_stations(arvif, sta);
5081 goto exit;
5082 }
5083 }
5084
5085 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
5086 WMI_TDLS_PEER_STATE_PEERING);
5087 if (ret) {
5088 ath10k_warn(ar,
5089 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
5090 sta->addr, arvif->vdev_id, ret);
5091 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5092 ath10k_mac_dec_num_stations(arvif, sta);
5093
5094 if (num_tdls_stations != 0)
5095 goto exit;
5096 ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5097 WMI_TDLS_DISABLE);
5098 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005099 } else if ((old_state == IEEE80211_STA_NONE &&
5100 new_state == IEEE80211_STA_NOTEXIST)) {
5101 /*
5102 * Existing station deletion.
5103 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005104 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03005105 "mac vdev %d peer delete %pM (sta gone)\n",
5106 arvif->vdev_id, sta->addr);
Michal Kazior077efc82014-10-21 10:10:29 +03005107
Kalle Valo5e3dd152013-06-12 20:52:10 +03005108 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5109 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005110 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02005111 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005112
Marek Puzyniak7c354242015-03-30 09:51:52 +03005113 ath10k_mac_dec_num_stations(arvif, sta);
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005114
5115 if (!sta->tdls)
5116 goto exit;
5117
5118 if (ath10k_mac_tdls_vif_stations_count(hw, vif))
5119 goto exit;
5120
5121 /* This was the last tdls peer in current vif */
5122 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5123 WMI_TDLS_DISABLE);
5124 if (ret) {
5125 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
5126 arvif->vdev_id, ret);
5127 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005128 } else if (old_state == IEEE80211_STA_AUTH &&
5129 new_state == IEEE80211_STA_ASSOC &&
5130 (vif->type == NL80211_IFTYPE_AP ||
5131 vif->type == NL80211_IFTYPE_ADHOC)) {
5132 /*
5133 * New association.
5134 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005135 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03005136 sta->addr);
5137
Michal Kazior590922a2014-10-21 10:10:29 +03005138 ret = ath10k_station_assoc(ar, vif, sta, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005139 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005140 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02005141 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005142 } else if (old_state == IEEE80211_STA_ASSOC &&
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005143 new_state == IEEE80211_STA_AUTHORIZED &&
5144 sta->tdls) {
5145 /*
5146 * Tdls station authorized.
5147 */
5148 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac tdls sta %pM authorized\n",
5149 sta->addr);
5150
5151 ret = ath10k_station_assoc(ar, vif, sta, false);
5152 if (ret) {
5153 ath10k_warn(ar, "failed to associate tdls station %pM for vdev %i: %i\n",
5154 sta->addr, arvif->vdev_id, ret);
5155 goto exit;
5156 }
5157
5158 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
5159 WMI_TDLS_PEER_STATE_CONNECTED);
5160 if (ret)
5161 ath10k_warn(ar, "failed to update tdls peer %pM for vdev %i: %i\n",
5162 sta->addr, arvif->vdev_id, ret);
5163 } else if (old_state == IEEE80211_STA_ASSOC &&
5164 new_state == IEEE80211_STA_AUTH &&
5165 (vif->type == NL80211_IFTYPE_AP ||
5166 vif->type == NL80211_IFTYPE_ADHOC)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03005167 /*
5168 * Disassociation.
5169 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005170 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03005171 sta->addr);
5172
Michal Kazior590922a2014-10-21 10:10:29 +03005173 ret = ath10k_station_disassoc(ar, vif, sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005174 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005175 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02005176 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005177 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01005178exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005179 mutex_unlock(&ar->conf_mutex);
5180 return ret;
5181}
5182
5183static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
Kalle Valo5b07e072014-09-14 12:50:06 +03005184 u16 ac, bool enable)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005185{
5186 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorb0e56152015-01-24 12:14:52 +02005187 struct wmi_sta_uapsd_auto_trig_arg arg = {};
5188 u32 prio = 0, acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005189 u32 value = 0;
5190 int ret = 0;
5191
Michal Kazior548db542013-07-05 16:15:15 +03005192 lockdep_assert_held(&ar->conf_mutex);
5193
Kalle Valo5e3dd152013-06-12 20:52:10 +03005194 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
5195 return 0;
5196
5197 switch (ac) {
5198 case IEEE80211_AC_VO:
5199 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
5200 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005201 prio = 7;
5202 acc = 3;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005203 break;
5204 case IEEE80211_AC_VI:
5205 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
5206 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005207 prio = 5;
5208 acc = 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005209 break;
5210 case IEEE80211_AC_BE:
5211 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
5212 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005213 prio = 2;
5214 acc = 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005215 break;
5216 case IEEE80211_AC_BK:
5217 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
5218 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005219 prio = 0;
5220 acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005221 break;
5222 }
5223
5224 if (enable)
5225 arvif->u.sta.uapsd |= value;
5226 else
5227 arvif->u.sta.uapsd &= ~value;
5228
5229 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5230 WMI_STA_PS_PARAM_UAPSD,
5231 arvif->u.sta.uapsd);
5232 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005233 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005234 goto exit;
5235 }
5236
5237 if (arvif->u.sta.uapsd)
5238 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
5239 else
5240 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
5241
5242 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5243 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
5244 value);
5245 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005246 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005247
Michal Kazior9f9b5742014-12-12 12:41:36 +01005248 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
5249 if (ret) {
5250 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
5251 arvif->vdev_id, ret);
5252 return ret;
5253 }
5254
5255 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
5256 if (ret) {
5257 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
5258 arvif->vdev_id, ret);
5259 return ret;
5260 }
5261
Michal Kaziorb0e56152015-01-24 12:14:52 +02005262 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
5263 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
5264 /* Only userspace can make an educated decision when to send
5265 * trigger frame. The following effectively disables u-UAPSD
5266 * autotrigger in firmware (which is enabled by default
5267 * provided the autotrigger service is available).
5268 */
5269
5270 arg.wmm_ac = acc;
5271 arg.user_priority = prio;
5272 arg.service_interval = 0;
5273 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
5274 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
5275
5276 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
5277 arvif->bssid, &arg, 1);
5278 if (ret) {
5279 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
5280 ret);
5281 return ret;
5282 }
5283 }
5284
Kalle Valo5e3dd152013-06-12 20:52:10 +03005285exit:
5286 return ret;
5287}
5288
5289static int ath10k_conf_tx(struct ieee80211_hw *hw,
5290 struct ieee80211_vif *vif, u16 ac,
5291 const struct ieee80211_tx_queue_params *params)
5292{
5293 struct ath10k *ar = hw->priv;
Michal Kazior5e752e42015-01-19 09:53:41 +01005294 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005295 struct wmi_wmm_params_arg *p = NULL;
5296 int ret;
5297
5298 mutex_lock(&ar->conf_mutex);
5299
5300 switch (ac) {
5301 case IEEE80211_AC_VO:
Michal Kazior5e752e42015-01-19 09:53:41 +01005302 p = &arvif->wmm_params.ac_vo;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005303 break;
5304 case IEEE80211_AC_VI:
Michal Kazior5e752e42015-01-19 09:53:41 +01005305 p = &arvif->wmm_params.ac_vi;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005306 break;
5307 case IEEE80211_AC_BE:
Michal Kazior5e752e42015-01-19 09:53:41 +01005308 p = &arvif->wmm_params.ac_be;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005309 break;
5310 case IEEE80211_AC_BK:
Michal Kazior5e752e42015-01-19 09:53:41 +01005311 p = &arvif->wmm_params.ac_bk;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005312 break;
5313 }
5314
5315 if (WARN_ON(!p)) {
5316 ret = -EINVAL;
5317 goto exit;
5318 }
5319
5320 p->cwmin = params->cw_min;
5321 p->cwmax = params->cw_max;
5322 p->aifs = params->aifs;
5323
5324 /*
5325 * The channel time duration programmed in the HW is in absolute
5326 * microseconds, while mac80211 gives the txop in units of
5327 * 32 microseconds.
5328 */
5329 p->txop = params->txop * 32;
5330
Michal Kazior7fc979a2015-01-28 09:57:28 +02005331 if (ar->wmi.ops->gen_vdev_wmm_conf) {
5332 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
5333 &arvif->wmm_params);
5334 if (ret) {
5335 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
5336 arvif->vdev_id, ret);
5337 goto exit;
5338 }
5339 } else {
5340 /* This won't work well with multi-interface cases but it's
5341 * better than nothing.
5342 */
5343 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
5344 if (ret) {
5345 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
5346 goto exit;
5347 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005348 }
5349
5350 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
5351 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005352 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005353
5354exit:
5355 mutex_unlock(&ar->conf_mutex);
5356 return ret;
5357}
5358
5359#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
5360
5361static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
5362 struct ieee80211_vif *vif,
5363 struct ieee80211_channel *chan,
5364 int duration,
5365 enum ieee80211_roc_type type)
5366{
5367 struct ath10k *ar = hw->priv;
5368 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5369 struct wmi_start_scan_arg arg;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005370 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005371
5372 mutex_lock(&ar->conf_mutex);
5373
5374 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005375 switch (ar->scan.state) {
5376 case ATH10K_SCAN_IDLE:
5377 reinit_completion(&ar->scan.started);
5378 reinit_completion(&ar->scan.completed);
5379 reinit_completion(&ar->scan.on_channel);
5380 ar->scan.state = ATH10K_SCAN_STARTING;
5381 ar->scan.is_roc = true;
5382 ar->scan.vdev_id = arvif->vdev_id;
5383 ar->scan.roc_freq = chan->center_freq;
5384 ret = 0;
5385 break;
5386 case ATH10K_SCAN_STARTING:
5387 case ATH10K_SCAN_RUNNING:
5388 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005389 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005390 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005391 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005392 spin_unlock_bh(&ar->data_lock);
5393
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005394 if (ret)
5395 goto exit;
5396
Michal Kaziordcca0bd2014-11-24 14:58:32 +01005397 duration = max(duration, WMI_SCAN_CHAN_MIN_TIME_MSEC);
5398
Kalle Valo5e3dd152013-06-12 20:52:10 +03005399 memset(&arg, 0, sizeof(arg));
5400 ath10k_wmi_start_scan_init(ar, &arg);
5401 arg.vdev_id = arvif->vdev_id;
5402 arg.scan_id = ATH10K_SCAN_ID;
5403 arg.n_channels = 1;
5404 arg.channels[0] = chan->center_freq;
5405 arg.dwell_time_active = duration;
5406 arg.dwell_time_passive = duration;
5407 arg.max_scan_time = 2 * duration;
5408 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
5409 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
5410
5411 ret = ath10k_start_scan(ar, &arg);
5412 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005413 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005414 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005415 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005416 spin_unlock_bh(&ar->data_lock);
5417 goto exit;
5418 }
5419
5420 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
5421 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005422 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005423
5424 ret = ath10k_scan_stop(ar);
5425 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005426 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005427
Kalle Valo5e3dd152013-06-12 20:52:10 +03005428 ret = -ETIMEDOUT;
5429 goto exit;
5430 }
5431
5432 ret = 0;
5433exit:
5434 mutex_unlock(&ar->conf_mutex);
5435 return ret;
5436}
5437
5438static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
5439{
5440 struct ath10k *ar = hw->priv;
5441
5442 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005443 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005444 mutex_unlock(&ar->conf_mutex);
5445
Michal Kazior4eb2e162014-10-28 10:23:09 +01005446 cancel_delayed_work_sync(&ar->scan.timeout);
5447
Kalle Valo5e3dd152013-06-12 20:52:10 +03005448 return 0;
5449}
5450
5451/*
5452 * Both RTS and Fragmentation threshold are interface-specific
5453 * in ath10k, but device-specific in mac80211.
5454 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03005455
5456static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
5457{
Kalle Valo5e3dd152013-06-12 20:52:10 +03005458 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03005459 struct ath10k_vif *arvif;
5460 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03005461
Michal Kaziorad088bf2013-10-16 15:44:46 +03005462 mutex_lock(&ar->conf_mutex);
5463 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005464 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03005465 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03005466
Michal Kaziorad088bf2013-10-16 15:44:46 +03005467 ret = ath10k_mac_set_rts(arvif, value);
5468 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005469 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03005470 arvif->vdev_id, ret);
5471 break;
5472 }
5473 }
5474 mutex_unlock(&ar->conf_mutex);
5475
5476 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005477}
5478
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02005479static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5480 u32 queues, bool drop)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005481{
5482 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02005483 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005484 int ret;
5485
5486 /* mac80211 doesn't care if we really xmit queued frames or not
5487 * we'll collect those frames either way if we stop/delete vdevs */
5488 if (drop)
5489 return;
5490
Michal Kazior548db542013-07-05 16:15:15 +03005491 mutex_lock(&ar->conf_mutex);
5492
Michal Kazioraffd3212013-07-16 09:54:35 +02005493 if (ar->state == ATH10K_STATE_WEDGED)
5494 goto skip;
5495
Michal Kazioredb82362013-07-05 16:15:14 +03005496 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03005497 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02005498
Michal Kazioredb82362013-07-05 16:15:14 +03005499 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02005500 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03005501 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02005502
Michal Kazior7962b0d2014-10-28 10:34:38 +01005503 skip = (ar->state == ATH10K_STATE_WEDGED) ||
5504 test_bit(ATH10K_FLAG_CRASH_FLUSH,
5505 &ar->dev_flags);
Michal Kazioraffd3212013-07-16 09:54:35 +02005506
5507 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005508 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02005509
5510 if (ret <= 0 || skip)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005511 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
Ben Greear9ba4c782014-02-25 09:29:57 +02005512 skip, ar->state, ret);
Michal Kazior548db542013-07-05 16:15:15 +03005513
Michal Kazioraffd3212013-07-16 09:54:35 +02005514skip:
Michal Kazior548db542013-07-05 16:15:15 +03005515 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005516}
5517
5518/* TODO: Implement this function properly
5519 * For now it is needed to reply to Probe Requests in IBSS mode.
5520 * Propably we need this information from FW.
5521 */
5522static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
5523{
5524 return 1;
5525}
5526
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005527static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
5528 enum ieee80211_reconfig_type reconfig_type)
Michal Kazioraffd3212013-07-16 09:54:35 +02005529{
5530 struct ath10k *ar = hw->priv;
5531
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005532 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
5533 return;
5534
Michal Kazioraffd3212013-07-16 09:54:35 +02005535 mutex_lock(&ar->conf_mutex);
5536
5537 /* If device failed to restart it will be in a different state, e.g.
5538 * ATH10K_STATE_WEDGED */
5539 if (ar->state == ATH10K_STATE_RESTARTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005540 ath10k_info(ar, "device successfully recovered\n");
Michal Kazioraffd3212013-07-16 09:54:35 +02005541 ar->state = ATH10K_STATE_ON;
Michal Kazior7962b0d2014-10-28 10:34:38 +01005542 ieee80211_wake_queues(ar->hw);
Michal Kazioraffd3212013-07-16 09:54:35 +02005543 }
5544
5545 mutex_unlock(&ar->conf_mutex);
5546}
5547
Michal Kazior2e1dea42013-07-31 10:32:40 +02005548static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
5549 struct survey_info *survey)
5550{
5551 struct ath10k *ar = hw->priv;
5552 struct ieee80211_supported_band *sband;
5553 struct survey_info *ar_survey = &ar->survey[idx];
5554 int ret = 0;
5555
5556 mutex_lock(&ar->conf_mutex);
5557
5558 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
5559 if (sband && idx >= sband->n_channels) {
5560 idx -= sband->n_channels;
5561 sband = NULL;
5562 }
5563
5564 if (!sband)
5565 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
5566
5567 if (!sband || idx >= sband->n_channels) {
5568 ret = -ENOENT;
5569 goto exit;
5570 }
5571
5572 spin_lock_bh(&ar->data_lock);
5573 memcpy(survey, ar_survey, sizeof(*survey));
5574 spin_unlock_bh(&ar->data_lock);
5575
5576 survey->channel = &sband->channels[idx];
5577
Felix Fietkaufa1d4df2014-10-23 17:04:28 +03005578 if (ar->rx_channel == survey->channel)
5579 survey->filled |= SURVEY_INFO_IN_USE;
5580
Michal Kazior2e1dea42013-07-31 10:32:40 +02005581exit:
5582 mutex_unlock(&ar->conf_mutex);
5583 return ret;
5584}
5585
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005586/* Check if only one bit set */
5587static int ath10k_check_single_mask(u32 mask)
5588{
5589 int bit;
5590
5591 bit = ffs(mask);
5592 if (!bit)
5593 return 0;
5594
5595 mask &= ~BIT(bit - 1);
5596 if (mask)
5597 return 2;
5598
5599 return 1;
5600}
5601
5602static bool
5603ath10k_default_bitrate_mask(struct ath10k *ar,
5604 enum ieee80211_band band,
5605 const struct cfg80211_bitrate_mask *mask)
5606{
5607 u32 legacy = 0x00ff;
5608 u8 ht = 0xff, i;
5609 u16 vht = 0x3ff;
Ben Greearb116ea12014-11-24 16:22:10 +02005610 u16 nrf = ar->num_rf_chains;
5611
5612 if (ar->cfg_tx_chainmask)
5613 nrf = get_nss_from_chainmask(ar->cfg_tx_chainmask);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005614
5615 switch (band) {
5616 case IEEE80211_BAND_2GHZ:
5617 legacy = 0x00fff;
5618 vht = 0;
5619 break;
5620 case IEEE80211_BAND_5GHZ:
5621 break;
5622 default:
5623 return false;
5624 }
5625
5626 if (mask->control[band].legacy != legacy)
5627 return false;
5628
Ben Greearb116ea12014-11-24 16:22:10 +02005629 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005630 if (mask->control[band].ht_mcs[i] != ht)
5631 return false;
5632
Ben Greearb116ea12014-11-24 16:22:10 +02005633 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005634 if (mask->control[band].vht_mcs[i] != vht)
5635 return false;
5636
5637 return true;
5638}
5639
5640static bool
5641ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
5642 enum ieee80211_band band,
5643 u8 *fixed_nss)
5644{
5645 int ht_nss = 0, vht_nss = 0, i;
5646
5647 /* check legacy */
5648 if (ath10k_check_single_mask(mask->control[band].legacy))
5649 return false;
5650
5651 /* check HT */
5652 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
5653 if (mask->control[band].ht_mcs[i] == 0xff)
5654 continue;
5655 else if (mask->control[band].ht_mcs[i] == 0x00)
5656 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03005657
5658 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005659 }
5660
5661 ht_nss = i;
5662
5663 /* check VHT */
5664 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
5665 if (mask->control[band].vht_mcs[i] == 0x03ff)
5666 continue;
5667 else if (mask->control[band].vht_mcs[i] == 0x0000)
5668 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03005669
5670 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005671 }
5672
5673 vht_nss = i;
5674
5675 if (ht_nss > 0 && vht_nss > 0)
5676 return false;
5677
5678 if (ht_nss)
5679 *fixed_nss = ht_nss;
5680 else if (vht_nss)
5681 *fixed_nss = vht_nss;
5682 else
5683 return false;
5684
5685 return true;
5686}
5687
5688static bool
5689ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
5690 enum ieee80211_band band,
5691 enum wmi_rate_preamble *preamble)
5692{
5693 int legacy = 0, ht = 0, vht = 0, i;
5694
5695 *preamble = WMI_RATE_PREAMBLE_OFDM;
5696
5697 /* check legacy */
5698 legacy = ath10k_check_single_mask(mask->control[band].legacy);
5699 if (legacy > 1)
5700 return false;
5701
5702 /* check HT */
5703 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5704 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
5705 if (ht > 1)
5706 return false;
5707
5708 /* check VHT */
5709 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
5710 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
5711 if (vht > 1)
5712 return false;
5713
5714 /* Currently we support only one fixed_rate */
5715 if ((legacy + ht + vht) != 1)
5716 return false;
5717
5718 if (ht)
5719 *preamble = WMI_RATE_PREAMBLE_HT;
5720 else if (vht)
5721 *preamble = WMI_RATE_PREAMBLE_VHT;
5722
5723 return true;
5724}
5725
5726static bool
Michal Kazior7aa7a722014-08-25 12:09:38 +02005727ath10k_bitrate_mask_rate(struct ath10k *ar,
5728 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005729 enum ieee80211_band band,
5730 u8 *fixed_rate,
5731 u8 *fixed_nss)
5732{
Michal Kazioraf001482015-03-30 09:51:56 +03005733 struct ieee80211_supported_band *sband;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005734 u8 rate = 0, pream = 0, nss = 0, i;
5735 enum wmi_rate_preamble preamble;
5736
5737 /* Check if single rate correct */
5738 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
5739 return false;
5740
5741 pream = preamble;
5742
5743 switch (preamble) {
5744 case WMI_RATE_PREAMBLE_CCK:
5745 case WMI_RATE_PREAMBLE_OFDM:
5746 i = ffs(mask->control[band].legacy) - 1;
Michal Kazioraf001482015-03-30 09:51:56 +03005747 sband = &ar->mac.sbands[band];
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005748
Michal Kazioraf001482015-03-30 09:51:56 +03005749 if (WARN_ON(i >= sband->n_bitrates))
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005750 return false;
5751
Michal Kazioraf001482015-03-30 09:51:56 +03005752 rate = sband->bitrates[i].hw_value;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005753 break;
5754 case WMI_RATE_PREAMBLE_HT:
5755 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5756 if (mask->control[band].ht_mcs[i])
5757 break;
5758
5759 if (i == IEEE80211_HT_MCS_MASK_LEN)
5760 return false;
5761
5762 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
5763 nss = i;
5764 break;
5765 case WMI_RATE_PREAMBLE_VHT:
5766 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
5767 if (mask->control[band].vht_mcs[i])
5768 break;
5769
5770 if (i == NL80211_VHT_NSS_MAX)
5771 return false;
5772
5773 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
5774 nss = i;
5775 break;
5776 }
5777
5778 *fixed_nss = nss + 1;
5779 nss <<= 4;
5780 pream <<= 6;
5781
Michal Kazior7aa7a722014-08-25 12:09:38 +02005782 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 +01005783 pream, nss, rate);
5784
5785 *fixed_rate = pream | nss | rate;
5786
5787 return true;
5788}
5789
Michal Kazior7aa7a722014-08-25 12:09:38 +02005790static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
5791 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005792 enum ieee80211_band band,
5793 u8 *fixed_rate,
5794 u8 *fixed_nss)
5795{
5796 /* First check full NSS mask, if we can simply limit NSS */
5797 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
5798 return true;
5799
5800 /* Next Check single rate is set */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005801 return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005802}
5803
5804static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
5805 u8 fixed_rate,
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005806 u8 fixed_nss,
5807 u8 force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005808{
5809 struct ath10k *ar = arvif->ar;
5810 u32 vdev_param;
5811 int ret = 0;
5812
5813 mutex_lock(&ar->conf_mutex);
5814
5815 if (arvif->fixed_rate == fixed_rate &&
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005816 arvif->fixed_nss == fixed_nss &&
5817 arvif->force_sgi == force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005818 goto exit;
5819
5820 if (fixed_rate == WMI_FIXED_RATE_NONE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005821 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005822
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005823 if (force_sgi)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005824 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005825
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005826 vdev_param = ar->wmi.vdev_param->fixed_rate;
5827 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5828 vdev_param, fixed_rate);
5829 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005830 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005831 fixed_rate, ret);
5832 ret = -EINVAL;
5833 goto exit;
5834 }
5835
5836 arvif->fixed_rate = fixed_rate;
5837
5838 vdev_param = ar->wmi.vdev_param->nss;
5839 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5840 vdev_param, fixed_nss);
5841
5842 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005843 ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005844 fixed_nss, ret);
5845 ret = -EINVAL;
5846 goto exit;
5847 }
5848
5849 arvif->fixed_nss = fixed_nss;
5850
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005851 vdev_param = ar->wmi.vdev_param->sgi;
5852 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5853 force_sgi);
5854
5855 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005856 ath10k_warn(ar, "failed to set sgi param %d: %d\n",
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005857 force_sgi, ret);
5858 ret = -EINVAL;
5859 goto exit;
5860 }
5861
5862 arvif->force_sgi = force_sgi;
5863
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005864exit:
5865 mutex_unlock(&ar->conf_mutex);
5866 return ret;
5867}
5868
5869static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
5870 struct ieee80211_vif *vif,
5871 const struct cfg80211_bitrate_mask *mask)
5872{
5873 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior500ff9f2015-03-31 10:26:21 +00005874 struct cfg80211_chan_def def;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005875 struct ath10k *ar = arvif->ar;
Michal Kazior500ff9f2015-03-31 10:26:21 +00005876 enum ieee80211_band band;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005877 u8 fixed_rate = WMI_FIXED_RATE_NONE;
5878 u8 fixed_nss = ar->num_rf_chains;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005879 u8 force_sgi;
5880
Michal Kazior500ff9f2015-03-31 10:26:21 +00005881 if (ath10k_mac_vif_chan(vif, &def))
5882 return -EPERM;
5883
Ben Greearb116ea12014-11-24 16:22:10 +02005884 if (ar->cfg_tx_chainmask)
5885 fixed_nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
5886
Michal Kazior500ff9f2015-03-31 10:26:21 +00005887 band = def.chan->band;
5888
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005889 force_sgi = mask->control[band].gi;
5890 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
5891 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005892
5893 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005894 if (!ath10k_get_fixed_rate_nss(ar, mask, band,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005895 &fixed_rate,
5896 &fixed_nss))
5897 return -EINVAL;
5898 }
5899
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005900 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005901 ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005902 return -EINVAL;
5903 }
5904
5905 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
5906 fixed_nss, force_sgi);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005907}
5908
Michal Kazior9797feb2014-02-14 14:49:48 +01005909static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
5910 struct ieee80211_vif *vif,
5911 struct ieee80211_sta *sta,
5912 u32 changed)
5913{
5914 struct ath10k *ar = hw->priv;
5915 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5916 u32 bw, smps;
5917
5918 spin_lock_bh(&ar->data_lock);
5919
Michal Kazior7aa7a722014-08-25 12:09:38 +02005920 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior9797feb2014-02-14 14:49:48 +01005921 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
5922 sta->addr, changed, sta->bandwidth, sta->rx_nss,
5923 sta->smps_mode);
5924
5925 if (changed & IEEE80211_RC_BW_CHANGED) {
5926 bw = WMI_PEER_CHWIDTH_20MHZ;
5927
5928 switch (sta->bandwidth) {
5929 case IEEE80211_STA_RX_BW_20:
5930 bw = WMI_PEER_CHWIDTH_20MHZ;
5931 break;
5932 case IEEE80211_STA_RX_BW_40:
5933 bw = WMI_PEER_CHWIDTH_40MHZ;
5934 break;
5935 case IEEE80211_STA_RX_BW_80:
5936 bw = WMI_PEER_CHWIDTH_80MHZ;
5937 break;
5938 case IEEE80211_STA_RX_BW_160:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005939 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005940 sta->bandwidth, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005941 bw = WMI_PEER_CHWIDTH_20MHZ;
5942 break;
5943 }
5944
5945 arsta->bw = bw;
5946 }
5947
5948 if (changed & IEEE80211_RC_NSS_CHANGED)
5949 arsta->nss = sta->rx_nss;
5950
5951 if (changed & IEEE80211_RC_SMPS_CHANGED) {
5952 smps = WMI_PEER_SMPS_PS_NONE;
5953
5954 switch (sta->smps_mode) {
5955 case IEEE80211_SMPS_AUTOMATIC:
5956 case IEEE80211_SMPS_OFF:
5957 smps = WMI_PEER_SMPS_PS_NONE;
5958 break;
5959 case IEEE80211_SMPS_STATIC:
5960 smps = WMI_PEER_SMPS_STATIC;
5961 break;
5962 case IEEE80211_SMPS_DYNAMIC:
5963 smps = WMI_PEER_SMPS_DYNAMIC;
5964 break;
5965 case IEEE80211_SMPS_NUM_MODES:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005966 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005967 sta->smps_mode, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005968 smps = WMI_PEER_SMPS_PS_NONE;
5969 break;
5970 }
5971
5972 arsta->smps = smps;
5973 }
5974
Michal Kazior9797feb2014-02-14 14:49:48 +01005975 arsta->changed |= changed;
5976
5977 spin_unlock_bh(&ar->data_lock);
5978
5979 ieee80211_queue_work(hw, &arsta->update_wk);
5980}
5981
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02005982static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
5983{
5984 /*
5985 * FIXME: Return 0 for time being. Need to figure out whether FW
5986 * has the API to fetch 64-bit local TSF
5987 */
5988
5989 return 0;
5990}
5991
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005992static int ath10k_ampdu_action(struct ieee80211_hw *hw,
5993 struct ieee80211_vif *vif,
5994 enum ieee80211_ampdu_mlme_action action,
5995 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
5996 u8 buf_size)
5997{
Michal Kazior7aa7a722014-08-25 12:09:38 +02005998 struct ath10k *ar = hw->priv;
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005999 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6000
Michal Kazior7aa7a722014-08-25 12:09:38 +02006001 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 +02006002 arvif->vdev_id, sta->addr, tid, action);
6003
6004 switch (action) {
6005 case IEEE80211_AMPDU_RX_START:
6006 case IEEE80211_AMPDU_RX_STOP:
6007 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
6008 * creation/removal. Do we need to verify this?
6009 */
6010 return 0;
6011 case IEEE80211_AMPDU_TX_START:
6012 case IEEE80211_AMPDU_TX_STOP_CONT:
6013 case IEEE80211_AMPDU_TX_STOP_FLUSH:
6014 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
6015 case IEEE80211_AMPDU_TX_OPERATIONAL:
6016 /* Firmware offloads Tx aggregation entirely so deny mac80211
6017 * Tx aggregation requests.
6018 */
6019 return -EOPNOTSUPP;
6020 }
6021
6022 return -EINVAL;
6023}
6024
Michal Kazior500ff9f2015-03-31 10:26:21 +00006025static void
6026ath10k_mac_update_rx_channel(struct ath10k *ar)
6027{
6028 struct cfg80211_chan_def *def = NULL;
6029
6030 /* Both locks are required because ar->rx_channel is modified. This
6031 * allows readers to hold either lock.
6032 */
6033 lockdep_assert_held(&ar->conf_mutex);
6034 lockdep_assert_held(&ar->data_lock);
6035
6036 /* FIXME: Sort of an optimization and a workaround. Peers and vifs are
6037 * on a linked list now. Doing a lookup peer -> vif -> chanctx for each
6038 * ppdu on Rx may reduce performance on low-end systems. It should be
6039 * possible to make tables/hashmaps to speed the lookup up (be vary of
6040 * cpu data cache lines though regarding sizes) but to keep the initial
6041 * implementation simple and less intrusive fallback to the slow lookup
6042 * only for multi-channel cases. Single-channel cases will remain to
6043 * use the old channel derival and thus performance should not be
6044 * affected much.
6045 */
6046 rcu_read_lock();
6047 if (ath10k_mac_num_chanctxs(ar) == 1) {
6048 ieee80211_iter_chan_contexts_atomic(ar->hw,
6049 ath10k_mac_get_any_chandef_iter,
6050 &def);
6051 ar->rx_channel = def->chan;
6052 } else {
6053 ar->rx_channel = NULL;
6054 }
6055 rcu_read_unlock();
6056}
6057
6058static void
6059ath10k_mac_chan_ctx_init(struct ath10k *ar,
6060 struct ath10k_chanctx *arctx,
6061 struct ieee80211_chanctx_conf *conf)
6062{
6063 lockdep_assert_held(&ar->conf_mutex);
6064 lockdep_assert_held(&ar->data_lock);
6065
6066 memset(arctx, 0, sizeof(*arctx));
6067
6068 arctx->conf = *conf;
6069}
6070
6071static int
6072ath10k_mac_op_add_chanctx(struct ieee80211_hw *hw,
6073 struct ieee80211_chanctx_conf *ctx)
6074{
6075 struct ath10k *ar = hw->priv;
6076 struct ath10k_chanctx *arctx = (void *)ctx->drv_priv;
6077
6078 ath10k_dbg(ar, ATH10K_DBG_MAC,
6079 "mac chanctx add freq %hu width %d ptr %p\n",
6080 ctx->def.chan->center_freq, ctx->def.width, ctx);
6081
6082 mutex_lock(&ar->conf_mutex);
6083
6084 spin_lock_bh(&ar->data_lock);
6085 ath10k_mac_chan_ctx_init(ar, arctx, ctx);
6086 ath10k_mac_update_rx_channel(ar);
6087 spin_unlock_bh(&ar->data_lock);
6088
6089 ath10k_recalc_radar_detection(ar);
6090 ath10k_monitor_recalc(ar);
6091
6092 mutex_unlock(&ar->conf_mutex);
6093
6094 return 0;
6095}
6096
6097static void
6098ath10k_mac_op_remove_chanctx(struct ieee80211_hw *hw,
6099 struct ieee80211_chanctx_conf *ctx)
6100{
6101 struct ath10k *ar = hw->priv;
6102
6103 ath10k_dbg(ar, ATH10K_DBG_MAC,
6104 "mac chanctx remove freq %hu width %d ptr %p\n",
6105 ctx->def.chan->center_freq, ctx->def.width, ctx);
6106
6107 mutex_lock(&ar->conf_mutex);
6108
6109 spin_lock_bh(&ar->data_lock);
6110 ath10k_mac_update_rx_channel(ar);
6111 spin_unlock_bh(&ar->data_lock);
6112
6113 ath10k_recalc_radar_detection(ar);
6114 ath10k_monitor_recalc(ar);
6115
6116 mutex_unlock(&ar->conf_mutex);
6117}
6118
6119static void
6120ath10k_mac_op_change_chanctx(struct ieee80211_hw *hw,
6121 struct ieee80211_chanctx_conf *ctx,
6122 u32 changed)
6123{
6124 struct ath10k *ar = hw->priv;
6125 struct ath10k_chanctx *arctx = (void *)ctx->drv_priv;
6126
6127 mutex_lock(&ar->conf_mutex);
6128
6129 ath10k_dbg(ar, ATH10K_DBG_MAC,
6130 "mac chanctx change freq %hu->%hu width %d->%d ptr %p changed %x\n",
6131 arctx->conf.def.chan->center_freq,
6132 ctx->def.chan->center_freq,
6133 arctx->conf.def.width, ctx->def.width,
6134 ctx, changed);
6135
6136 /* This shouldn't really happen because channel switching should use
6137 * switch_vif_chanctx().
6138 */
6139 if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL))
6140 goto unlock;
6141
6142 spin_lock_bh(&ar->data_lock);
6143 arctx->conf = *ctx;
6144 spin_unlock_bh(&ar->data_lock);
6145
6146 ath10k_recalc_radar_detection(ar);
6147
6148 /* FIXME: How to configure Rx chains properly? */
6149
6150 /* No other actions are actually necessary. Firmware maintains channel
6151 * definitions per vdev internally and there's no host-side channel
6152 * context abstraction to configure, e.g. channel width.
6153 */
6154
6155unlock:
6156 mutex_unlock(&ar->conf_mutex);
6157}
6158
6159static int
6160ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
6161 struct ieee80211_vif *vif,
6162 struct ieee80211_chanctx_conf *ctx)
6163{
6164 struct ath10k *ar = hw->priv;
6165 struct ath10k_chanctx *arctx = (void *)ctx->drv_priv;
6166 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6167 int ret;
6168
6169 mutex_lock(&ar->conf_mutex);
6170
6171 ath10k_dbg(ar, ATH10K_DBG_MAC,
6172 "mac chanctx assign ptr %p vdev_id %i\n",
6173 ctx, arvif->vdev_id);
6174
6175 if (WARN_ON(arvif->is_started)) {
6176 mutex_unlock(&ar->conf_mutex);
6177 return -EBUSY;
6178 }
6179
6180 ret = ath10k_vdev_start(arvif, &arctx->conf.def);
6181 if (ret) {
6182 ath10k_warn(ar, "failed to start vdev %i addr %pM on freq %d: %d\n",
6183 arvif->vdev_id, vif->addr,
6184 arctx->conf.def.chan->center_freq, ret);
6185 goto err;
6186 }
6187
6188 arvif->is_started = true;
6189
6190 if (vif->type == NL80211_IFTYPE_MONITOR) {
6191 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, 0, vif->addr);
6192 if (ret) {
6193 ath10k_warn(ar, "failed to up monitor vdev %i: %d\n",
6194 arvif->vdev_id, ret);
6195 goto err_stop;
6196 }
6197
6198 arvif->is_up = true;
6199 }
6200
6201 mutex_unlock(&ar->conf_mutex);
6202 return 0;
6203
6204err_stop:
6205 ath10k_vdev_stop(arvif);
6206 arvif->is_started = false;
6207
6208err:
6209 mutex_unlock(&ar->conf_mutex);
6210 return ret;
6211}
6212
6213static void
6214ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
6215 struct ieee80211_vif *vif,
6216 struct ieee80211_chanctx_conf *ctx)
6217{
6218 struct ath10k *ar = hw->priv;
6219 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6220 int ret;
6221
6222 mutex_lock(&ar->conf_mutex);
6223
6224 ath10k_dbg(ar, ATH10K_DBG_MAC,
6225 "mac chanctx unassign ptr %p vdev_id %i\n",
6226 ctx, arvif->vdev_id);
6227
6228 WARN_ON(!arvif->is_started);
6229
6230 if (vif->type == NL80211_IFTYPE_MONITOR) {
6231 WARN_ON(!arvif->is_up);
6232
6233 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
6234 if (ret)
6235 ath10k_warn(ar, "failed to down monitor vdev %i: %d\n",
6236 arvif->vdev_id, ret);
6237
6238 arvif->is_up = false;
6239 }
6240
6241 ret = ath10k_vdev_stop(arvif);
6242 if (ret)
6243 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
6244 arvif->vdev_id, ret);
6245
6246 arvif->is_started = false;
6247
6248 mutex_unlock(&ar->conf_mutex);
6249}
6250
6251static int
6252ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw,
6253 struct ieee80211_vif_chanctx_switch *vifs,
6254 int n_vifs,
6255 enum ieee80211_chanctx_switch_mode mode)
6256{
6257 struct ath10k *ar = hw->priv;
6258 struct ath10k_vif *arvif;
6259 struct ath10k_chanctx *arctx_new, *arctx_old;
6260 int i;
6261
6262 mutex_lock(&ar->conf_mutex);
6263
6264 ath10k_dbg(ar, ATH10K_DBG_MAC,
6265 "mac chanctx switch n_vifs %d mode %d\n",
6266 n_vifs, mode);
6267
6268 spin_lock_bh(&ar->data_lock);
6269 for (i = 0; i < n_vifs; i++) {
6270 arvif = ath10k_vif_to_arvif(vifs[i].vif);
6271 arctx_new = (void *)vifs[i].new_ctx->drv_priv;
6272 arctx_old = (void *)vifs[i].old_ctx->drv_priv;
6273
6274 ath10k_dbg(ar, ATH10K_DBG_MAC,
6275 "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d ptr %p->%p\n",
6276 arvif->vdev_id,
6277 vifs[i].old_ctx->def.chan->center_freq,
6278 vifs[i].new_ctx->def.chan->center_freq,
6279 vifs[i].old_ctx->def.width,
6280 vifs[i].new_ctx->def.width,
6281 arctx_old, arctx_new);
6282
6283 if (mode == CHANCTX_SWMODE_SWAP_CONTEXTS) {
6284 ath10k_mac_chan_ctx_init(ar, arctx_new,
6285 vifs[i].new_ctx);
6286 }
6287
6288 arctx_new->conf = *vifs[i].new_ctx;
6289
6290 /* FIXME: ath10k_mac_chan_reconfigure() uses current, i.e. not
6291 * yet updated chanctx_conf pointer.
6292 */
6293 arctx_old->conf = *vifs[i].new_ctx;
6294 }
6295 ath10k_mac_update_rx_channel(ar);
6296 spin_unlock_bh(&ar->data_lock);
6297
6298 /* FIXME: Reconfigure only affected vifs */
6299 ath10k_mac_chan_reconfigure(ar);
6300
6301 mutex_unlock(&ar->conf_mutex);
6302 return 0;
6303}
6304
Kalle Valo5e3dd152013-06-12 20:52:10 +03006305static const struct ieee80211_ops ath10k_ops = {
6306 .tx = ath10k_tx,
6307 .start = ath10k_start,
6308 .stop = ath10k_stop,
6309 .config = ath10k_config,
6310 .add_interface = ath10k_add_interface,
6311 .remove_interface = ath10k_remove_interface,
6312 .configure_filter = ath10k_configure_filter,
6313 .bss_info_changed = ath10k_bss_info_changed,
6314 .hw_scan = ath10k_hw_scan,
6315 .cancel_hw_scan = ath10k_cancel_hw_scan,
6316 .set_key = ath10k_set_key,
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02006317 .set_default_unicast_key = ath10k_set_default_unicast_key,
Kalle Valo5e3dd152013-06-12 20:52:10 +03006318 .sta_state = ath10k_sta_state,
6319 .conf_tx = ath10k_conf_tx,
6320 .remain_on_channel = ath10k_remain_on_channel,
6321 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
6322 .set_rts_threshold = ath10k_set_rts_threshold,
Kalle Valo5e3dd152013-06-12 20:52:10 +03006323 .flush = ath10k_flush,
6324 .tx_last_beacon = ath10k_tx_last_beacon,
Ben Greear46acf7b2014-05-16 17:15:38 +03006325 .set_antenna = ath10k_set_antenna,
6326 .get_antenna = ath10k_get_antenna,
Eliad Pellercf2c92d2014-11-04 11:43:54 +02006327 .reconfig_complete = ath10k_reconfig_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02006328 .get_survey = ath10k_get_survey,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01006329 .set_bitrate_mask = ath10k_set_bitrate_mask,
Michal Kazior9797feb2014-02-14 14:49:48 +01006330 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02006331 .get_tsf = ath10k_get_tsf,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02006332 .ampdu_action = ath10k_ampdu_action,
Ben Greear6cddcc72014-09-29 14:41:46 +03006333 .get_et_sset_count = ath10k_debug_get_et_sset_count,
6334 .get_et_stats = ath10k_debug_get_et_stats,
6335 .get_et_strings = ath10k_debug_get_et_strings,
Michal Kazior500ff9f2015-03-31 10:26:21 +00006336 .add_chanctx = ath10k_mac_op_add_chanctx,
6337 .remove_chanctx = ath10k_mac_op_remove_chanctx,
6338 .change_chanctx = ath10k_mac_op_change_chanctx,
6339 .assign_vif_chanctx = ath10k_mac_op_assign_vif_chanctx,
6340 .unassign_vif_chanctx = ath10k_mac_op_unassign_vif_chanctx,
6341 .switch_vif_chanctx = ath10k_mac_op_switch_vif_chanctx,
Kalle Valo43d2a302014-09-10 18:23:30 +03006342
6343 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
6344
Michal Kazior8cd13ca2013-07-16 09:38:54 +02006345#ifdef CONFIG_PM
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +02006346 .suspend = ath10k_wow_op_suspend,
6347 .resume = ath10k_wow_op_resume,
Michal Kazior8cd13ca2013-07-16 09:38:54 +02006348#endif
Rajkumar Manoharanf5045982015-01-12 14:07:27 +02006349#ifdef CONFIG_MAC80211_DEBUGFS
6350 .sta_add_debugfs = ath10k_sta_add_debugfs,
6351#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03006352};
6353
Kalle Valo5e3dd152013-06-12 20:52:10 +03006354#define CHAN2G(_channel, _freq, _flags) { \
6355 .band = IEEE80211_BAND_2GHZ, \
6356 .hw_value = (_channel), \
6357 .center_freq = (_freq), \
6358 .flags = (_flags), \
6359 .max_antenna_gain = 0, \
6360 .max_power = 30, \
6361}
6362
6363#define CHAN5G(_channel, _freq, _flags) { \
6364 .band = IEEE80211_BAND_5GHZ, \
6365 .hw_value = (_channel), \
6366 .center_freq = (_freq), \
6367 .flags = (_flags), \
6368 .max_antenna_gain = 0, \
6369 .max_power = 30, \
6370}
6371
6372static const struct ieee80211_channel ath10k_2ghz_channels[] = {
6373 CHAN2G(1, 2412, 0),
6374 CHAN2G(2, 2417, 0),
6375 CHAN2G(3, 2422, 0),
6376 CHAN2G(4, 2427, 0),
6377 CHAN2G(5, 2432, 0),
6378 CHAN2G(6, 2437, 0),
6379 CHAN2G(7, 2442, 0),
6380 CHAN2G(8, 2447, 0),
6381 CHAN2G(9, 2452, 0),
6382 CHAN2G(10, 2457, 0),
6383 CHAN2G(11, 2462, 0),
6384 CHAN2G(12, 2467, 0),
6385 CHAN2G(13, 2472, 0),
6386 CHAN2G(14, 2484, 0),
6387};
6388
6389static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02006390 CHAN5G(36, 5180, 0),
6391 CHAN5G(40, 5200, 0),
6392 CHAN5G(44, 5220, 0),
6393 CHAN5G(48, 5240, 0),
6394 CHAN5G(52, 5260, 0),
6395 CHAN5G(56, 5280, 0),
6396 CHAN5G(60, 5300, 0),
6397 CHAN5G(64, 5320, 0),
6398 CHAN5G(100, 5500, 0),
6399 CHAN5G(104, 5520, 0),
6400 CHAN5G(108, 5540, 0),
6401 CHAN5G(112, 5560, 0),
6402 CHAN5G(116, 5580, 0),
6403 CHAN5G(120, 5600, 0),
6404 CHAN5G(124, 5620, 0),
6405 CHAN5G(128, 5640, 0),
6406 CHAN5G(132, 5660, 0),
6407 CHAN5G(136, 5680, 0),
6408 CHAN5G(140, 5700, 0),
Peter Oh4a7898f2015-03-18 11:39:18 -07006409 CHAN5G(144, 5720, 0),
Michal Kazior429ff562013-06-26 08:54:54 +02006410 CHAN5G(149, 5745, 0),
6411 CHAN5G(153, 5765, 0),
6412 CHAN5G(157, 5785, 0),
6413 CHAN5G(161, 5805, 0),
6414 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03006415};
6416
Michal Kaziore7b54192014-08-07 11:03:27 +02006417struct ath10k *ath10k_mac_create(size_t priv_size)
Kalle Valo5e3dd152013-06-12 20:52:10 +03006418{
6419 struct ieee80211_hw *hw;
6420 struct ath10k *ar;
6421
Michal Kaziore7b54192014-08-07 11:03:27 +02006422 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006423 if (!hw)
6424 return NULL;
6425
6426 ar = hw->priv;
6427 ar->hw = hw;
6428
6429 return ar;
6430}
6431
6432void ath10k_mac_destroy(struct ath10k *ar)
6433{
6434 ieee80211_free_hw(ar->hw);
6435}
6436
6437static const struct ieee80211_iface_limit ath10k_if_limits[] = {
6438 {
6439 .max = 8,
6440 .types = BIT(NL80211_IFTYPE_STATION)
6441 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02006442 },
6443 {
6444 .max = 3,
6445 .types = BIT(NL80211_IFTYPE_P2P_GO)
6446 },
6447 {
Michal Kazior75d2bd42014-12-12 12:41:39 +01006448 .max = 1,
6449 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
6450 },
6451 {
Michal Kaziord531cb82013-07-31 10:55:13 +02006452 .max = 7,
6453 .types = BIT(NL80211_IFTYPE_AP)
6454 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03006455};
6456
Bartosz Markowskif2595092013-12-10 16:20:39 +01006457static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006458 {
6459 .max = 8,
6460 .types = BIT(NL80211_IFTYPE_AP)
6461 },
6462};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006463
6464static const struct ieee80211_iface_combination ath10k_if_comb[] = {
6465 {
6466 .limits = ath10k_if_limits,
6467 .n_limits = ARRAY_SIZE(ath10k_if_limits),
6468 .max_interfaces = 8,
6469 .num_different_channels = 1,
6470 .beacon_int_infra_match = true,
6471 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01006472};
6473
6474static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006475 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01006476 .limits = ath10k_10x_if_limits,
6477 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006478 .max_interfaces = 8,
6479 .num_different_channels = 1,
6480 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01006481#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006482 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
6483 BIT(NL80211_CHAN_WIDTH_20) |
6484 BIT(NL80211_CHAN_WIDTH_40) |
6485 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006486#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01006487 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03006488};
6489
6490static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
6491{
6492 struct ieee80211_sta_vht_cap vht_cap = {0};
6493 u16 mcs_map;
Michal Kaziorbc657a362015-02-26 11:11:22 +01006494 u32 val;
Michal Kazior8865bee42013-07-24 12:36:46 +02006495 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006496
6497 vht_cap.vht_supported = 1;
6498 vht_cap.cap = ar->vht_cap_info;
6499
Michal Kaziorbc657a362015-02-26 11:11:22 +01006500 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
6501 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
6502 val = ar->num_rf_chains - 1;
6503 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
6504 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
6505
6506 vht_cap.cap |= val;
6507 }
6508
6509 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
6510 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
6511 val = ar->num_rf_chains - 1;
6512 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
6513 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
6514
6515 vht_cap.cap |= val;
6516 }
6517
Michal Kazior8865bee42013-07-24 12:36:46 +02006518 mcs_map = 0;
6519 for (i = 0; i < 8; i++) {
6520 if (i < ar->num_rf_chains)
6521 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
6522 else
6523 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
6524 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03006525
6526 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
6527 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
6528
6529 return vht_cap;
6530}
6531
6532static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
6533{
6534 int i;
6535 struct ieee80211_sta_ht_cap ht_cap = {0};
6536
6537 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
6538 return ht_cap;
6539
6540 ht_cap.ht_supported = 1;
6541 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
6542 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
6543 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
6544 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
6545 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
6546
6547 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
6548 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
6549
6550 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
6551 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
6552
6553 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
6554 u32 smps;
6555
6556 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
6557 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
6558
6559 ht_cap.cap |= smps;
6560 }
6561
6562 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
6563 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
6564
6565 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
6566 u32 stbc;
6567
6568 stbc = ar->ht_cap_info;
6569 stbc &= WMI_HT_CAP_RX_STBC;
6570 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
6571 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
6572 stbc &= IEEE80211_HT_CAP_RX_STBC;
6573
6574 ht_cap.cap |= stbc;
6575 }
6576
6577 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
6578 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
6579
6580 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
6581 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
6582
6583 /* max AMSDU is implicitly taken from vht_cap_info */
6584 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
6585 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
6586
Michal Kazior8865bee42013-07-24 12:36:46 +02006587 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03006588 ht_cap.mcs.rx_mask[i] = 0xFF;
6589
6590 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
6591
6592 return ht_cap;
6593}
6594
Kalle Valo5e3dd152013-06-12 20:52:10 +03006595static void ath10k_get_arvif_iter(void *data, u8 *mac,
6596 struct ieee80211_vif *vif)
6597{
6598 struct ath10k_vif_iter *arvif_iter = data;
6599 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6600
6601 if (arvif->vdev_id == arvif_iter->vdev_id)
6602 arvif_iter->arvif = arvif;
6603}
6604
6605struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
6606{
6607 struct ath10k_vif_iter arvif_iter;
6608 u32 flags;
6609
6610 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
6611 arvif_iter.vdev_id = vdev_id;
6612
6613 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
6614 ieee80211_iterate_active_interfaces_atomic(ar->hw,
6615 flags,
6616 ath10k_get_arvif_iter,
6617 &arvif_iter);
6618 if (!arvif_iter.arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02006619 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006620 return NULL;
6621 }
6622
6623 return arvif_iter.arvif;
6624}
6625
6626int ath10k_mac_register(struct ath10k *ar)
6627{
Johannes Berg3cb10942015-01-22 21:38:45 +01006628 static const u32 cipher_suites[] = {
6629 WLAN_CIPHER_SUITE_WEP40,
6630 WLAN_CIPHER_SUITE_WEP104,
6631 WLAN_CIPHER_SUITE_TKIP,
6632 WLAN_CIPHER_SUITE_CCMP,
6633 WLAN_CIPHER_SUITE_AES_CMAC,
6634 };
Kalle Valo5e3dd152013-06-12 20:52:10 +03006635 struct ieee80211_supported_band *band;
6636 struct ieee80211_sta_vht_cap vht_cap;
6637 struct ieee80211_sta_ht_cap ht_cap;
6638 void *channels;
6639 int ret;
6640
6641 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
6642
6643 SET_IEEE80211_DEV(ar->hw, ar->dev);
6644
6645 ht_cap = ath10k_get_ht_cap(ar);
6646 vht_cap = ath10k_create_vht_cap(ar);
6647
Michal Kaziorc94aa7e2015-03-24 12:38:11 +00006648 BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels) +
6649 ARRAY_SIZE(ath10k_5ghz_channels)) !=
6650 ATH10K_NUM_CHANS);
6651
Kalle Valo5e3dd152013-06-12 20:52:10 +03006652 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
6653 channels = kmemdup(ath10k_2ghz_channels,
6654 sizeof(ath10k_2ghz_channels),
6655 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02006656 if (!channels) {
6657 ret = -ENOMEM;
6658 goto err_free;
6659 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03006660
6661 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
6662 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
6663 band->channels = channels;
6664 band->n_bitrates = ath10k_g_rates_size;
6665 band->bitrates = ath10k_g_rates;
6666 band->ht_cap = ht_cap;
6667
Yanbo Lid68bb122015-01-23 08:18:20 +08006668 /* Enable the VHT support at 2.4 GHz */
6669 band->vht_cap = vht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006670
6671 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
6672 }
6673
6674 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
6675 channels = kmemdup(ath10k_5ghz_channels,
6676 sizeof(ath10k_5ghz_channels),
6677 GFP_KERNEL);
6678 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02006679 ret = -ENOMEM;
6680 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006681 }
6682
6683 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
6684 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
6685 band->channels = channels;
6686 band->n_bitrates = ath10k_a_rates_size;
6687 band->bitrates = ath10k_a_rates;
6688 band->ht_cap = ht_cap;
6689 band->vht_cap = vht_cap;
6690 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
6691 }
6692
6693 ar->hw->wiphy->interface_modes =
6694 BIT(NL80211_IFTYPE_STATION) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01006695 BIT(NL80211_IFTYPE_AP);
6696
Ben Greear46acf7b2014-05-16 17:15:38 +03006697 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
6698 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
6699
Bartosz Markowskid3541812013-12-10 16:20:40 +01006700 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
6701 ar->hw->wiphy->interface_modes |=
Michal Kazior75d2bd42014-12-12 12:41:39 +01006702 BIT(NL80211_IFTYPE_P2P_DEVICE) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01006703 BIT(NL80211_IFTYPE_P2P_CLIENT) |
6704 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006705
6706 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
6707 IEEE80211_HW_SUPPORTS_PS |
6708 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
Kalle Valo5e3dd152013-06-12 20:52:10 +03006709 IEEE80211_HW_MFP_CAPABLE |
6710 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
6711 IEEE80211_HW_HAS_RATE_CONTROL |
Janusz Dziedzic2f0f1122014-02-26 18:42:09 +02006712 IEEE80211_HW_AP_LINK_PS |
Johannes Berg3cb10942015-01-22 21:38:45 +01006713 IEEE80211_HW_SPECTRUM_MGMT |
Michal Kaziorcc9904e2015-03-10 16:22:01 +02006714 IEEE80211_HW_SW_CRYPTO_CONTROL |
Michal Kazior500ff9f2015-03-31 10:26:21 +00006715 IEEE80211_HW_CONNECTION_MONITOR |
6716 IEEE80211_HW_WANT_MONITOR_VIF |
Michal Kazior96d828d2015-03-31 10:26:23 +00006717 IEEE80211_HW_CHANCTX_STA_CSA |
6718 IEEE80211_HW_QUEUE_CONTROL;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006719
Eliad Peller0d8614b2014-09-10 14:07:36 +03006720 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
6721
Kalle Valo5e3dd152013-06-12 20:52:10 +03006722 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
Eliad Peller0d8614b2014-09-10 14:07:36 +03006723 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006724
6725 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
6726 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
6727 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
6728 }
6729
6730 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
6731 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
6732
6733 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01006734 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006735 ar->hw->chanctx_data_size = sizeof(struct ath10k_chanctx);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006736
Kalle Valo5e3dd152013-06-12 20:52:10 +03006737 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
6738
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02006739 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
6740 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
6741
6742 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
6743 * that userspace (e.g. wpa_supplicant/hostapd) can generate
6744 * correct Probe Responses. This is more of a hack advert..
6745 */
6746 ar->hw->wiphy->probe_resp_offload |=
6747 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
6748 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
6749 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
6750 }
6751
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03006752 if (test_bit(WMI_SERVICE_TDLS, ar->wmi.svc_map))
6753 ar->hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
6754
Kalle Valo5e3dd152013-06-12 20:52:10 +03006755 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01006756 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006757 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
6758
6759 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
Rajkumar Manoharan78157a12014-11-17 16:44:15 +02006760 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
6761
Janusz.Dziedzic@tieto.com37a0b392015-03-12 13:11:41 +01006762 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
6763
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +02006764 ret = ath10k_wow_init(ar);
6765 if (ret) {
6766 ath10k_warn(ar, "failed to init wow: %d\n", ret);
6767 goto err_free;
6768 }
6769
Kalle Valo5e3dd152013-06-12 20:52:10 +03006770 /*
6771 * on LL hardware queues are managed entirely by the FW
6772 * so we only advertise to mac we can do the queues thing
6773 */
Michal Kazior96d828d2015-03-31 10:26:23 +00006774 ar->hw->queues = IEEE80211_MAX_QUEUES;
6775
6776 /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is
6777 * something that vdev_ids can't reach so that we don't stop the queue
6778 * accidentally.
6779 */
6780 ar->hw->offchannel_tx_hw_queue = IEEE80211_MAX_QUEUES - 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006781
Kalle Valo5cc7caf2014-12-17 12:20:54 +02006782 switch (ar->wmi.op_version) {
6783 case ATH10K_FW_WMI_OP_VERSION_MAIN:
6784 case ATH10K_FW_WMI_OP_VERSION_TLV:
Bartosz Markowskif2595092013-12-10 16:20:39 +01006785 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
6786 ar->hw->wiphy->n_iface_combinations =
6787 ARRAY_SIZE(ath10k_if_comb);
Michal Kaziorcf850d12014-07-24 20:07:00 +03006788 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
Kalle Valo5cc7caf2014-12-17 12:20:54 +02006789 break;
6790 case ATH10K_FW_WMI_OP_VERSION_10_1:
6791 case ATH10K_FW_WMI_OP_VERSION_10_2:
Rajkumar Manoharan4a16fbe2014-12-17 12:21:12 +02006792 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
Kalle Valo5cc7caf2014-12-17 12:20:54 +02006793 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
6794 ar->hw->wiphy->n_iface_combinations =
6795 ARRAY_SIZE(ath10k_10x_if_comb);
6796 break;
6797 case ATH10K_FW_WMI_OP_VERSION_UNSET:
6798 case ATH10K_FW_WMI_OP_VERSION_MAX:
6799 WARN_ON(1);
6800 ret = -EINVAL;
6801 goto err_free;
Bartosz Markowskif2595092013-12-10 16:20:39 +01006802 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03006803
Michal Kazior7c199992013-07-31 10:47:57 +02006804 ar->hw->netdev_features = NETIF_F_HW_CSUM;
6805
Janusz Dziedzic9702c682013-11-20 09:59:41 +02006806 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
6807 /* Init ath dfs pattern detector */
6808 ar->ath_common.debug_mask = ATH_DBG_DFS;
6809 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
6810 NL80211_DFS_UNSET);
6811
6812 if (!ar->dfs_detector)
Michal Kazior7aa7a722014-08-25 12:09:38 +02006813 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02006814 }
6815
Kalle Valo5e3dd152013-06-12 20:52:10 +03006816 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
6817 ath10k_reg_notifier);
6818 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02006819 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02006820 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006821 }
6822
Johannes Berg3cb10942015-01-22 21:38:45 +01006823 ar->hw->wiphy->cipher_suites = cipher_suites;
6824 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
6825
Kalle Valo5e3dd152013-06-12 20:52:10 +03006826 ret = ieee80211_register_hw(ar->hw);
6827 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02006828 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02006829 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006830 }
6831
6832 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
6833 ret = regulatory_hint(ar->hw->wiphy,
6834 ar->ath_common.regulatory.alpha2);
6835 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02006836 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006837 }
6838
6839 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02006840
6841err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03006842 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02006843err_free:
6844 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
6845 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
6846
Kalle Valo5e3dd152013-06-12 20:52:10 +03006847 return ret;
6848}
6849
6850void ath10k_mac_unregister(struct ath10k *ar)
6851{
6852 ieee80211_unregister_hw(ar->hw);
6853
Janusz Dziedzic9702c682013-11-20 09:59:41 +02006854 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
6855 ar->dfs_detector->exit(ar->dfs_detector);
6856
Kalle Valo5e3dd152013-06-12 20:52:10 +03006857 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
6858 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
6859
6860 SET_IEEE80211_DEV(ar->hw, NULL);
6861}