blob: 069f399e4c2554d7c7ccb6cd511773a9b88e202d [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
Michal Kazior3ae54222015-03-31 10:49:20 +0000123static int ath10k_mac_get_max_vht_mcs_map(u16 mcs_map, int nss)
124{
125 switch ((mcs_map >> (2 * nss)) & 0x3) {
126 case IEEE80211_VHT_MCS_SUPPORT_0_7: return BIT(8) - 1;
127 case IEEE80211_VHT_MCS_SUPPORT_0_8: return BIT(9) - 1;
128 case IEEE80211_VHT_MCS_SUPPORT_0_9: return BIT(10) - 1;
129 }
130 return 0;
131}
132
Michal Kazior45c9abc2015-04-21 20:42:58 +0300133static u32
134ath10k_mac_max_ht_nss(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
135{
136 int nss;
137
138 for (nss = IEEE80211_HT_MCS_MASK_LEN - 1; nss >= 0; nss--)
139 if (ht_mcs_mask[nss])
140 return nss + 1;
141
142 return 1;
143}
144
145static u32
146ath10k_mac_max_vht_nss(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
147{
148 int nss;
149
150 for (nss = NL80211_VHT_NSS_MAX - 1; nss >= 0; nss--)
151 if (vht_mcs_mask[nss])
152 return nss + 1;
153
154 return 1;
155}
156
Kalle Valo5e3dd152013-06-12 20:52:10 +0300157/**********/
158/* Crypto */
159/**********/
160
161static int ath10k_send_key(struct ath10k_vif *arvif,
162 struct ieee80211_key_conf *key,
163 enum set_key_cmd cmd,
Michal Kazior370e5672015-02-18 14:02:26 +0100164 const u8 *macaddr, u32 flags)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300165{
Michal Kazior7aa7a722014-08-25 12:09:38 +0200166 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300167 struct wmi_vdev_install_key_arg arg = {
168 .vdev_id = arvif->vdev_id,
169 .key_idx = key->keyidx,
170 .key_len = key->keylen,
171 .key_data = key->key,
Michal Kazior370e5672015-02-18 14:02:26 +0100172 .key_flags = flags,
Kalle Valo5e3dd152013-06-12 20:52:10 +0300173 .macaddr = macaddr,
174 };
175
Michal Kazior548db542013-07-05 16:15:15 +0300176 lockdep_assert_held(&arvif->ar->conf_mutex);
177
Kalle Valo5e3dd152013-06-12 20:52:10 +0300178 switch (key->cipher) {
179 case WLAN_CIPHER_SUITE_CCMP:
180 arg.key_cipher = WMI_CIPHER_AES_CCM;
Marek Kwaczynskie4e82e92015-01-24 12:14:53 +0200181 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300182 break;
183 case WLAN_CIPHER_SUITE_TKIP:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300184 arg.key_cipher = WMI_CIPHER_TKIP;
185 arg.key_txmic_len = 8;
186 arg.key_rxmic_len = 8;
187 break;
188 case WLAN_CIPHER_SUITE_WEP40:
189 case WLAN_CIPHER_SUITE_WEP104:
190 arg.key_cipher = WMI_CIPHER_WEP;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300191 break;
Johannes Berg3cb10942015-01-22 21:38:45 +0100192 case WLAN_CIPHER_SUITE_AES_CMAC:
Bartosz Markowskid7131c02015-03-10 14:32:19 +0100193 WARN_ON(1);
194 return -EINVAL;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300195 default:
Michal Kazior7aa7a722014-08-25 12:09:38 +0200196 ath10k_warn(ar, "cipher %d is not supported\n", key->cipher);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300197 return -EOPNOTSUPP;
198 }
199
200 if (cmd == DISABLE_KEY) {
201 arg.key_cipher = WMI_CIPHER_NONE;
202 arg.key_data = NULL;
203 }
204
205 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
206}
207
208static int ath10k_install_key(struct ath10k_vif *arvif,
209 struct ieee80211_key_conf *key,
210 enum set_key_cmd cmd,
Michal Kazior370e5672015-02-18 14:02:26 +0100211 const u8 *macaddr, u32 flags)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300212{
213 struct ath10k *ar = arvif->ar;
214 int ret;
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +0300215 unsigned long time_left;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300216
Michal Kazior548db542013-07-05 16:15:15 +0300217 lockdep_assert_held(&ar->conf_mutex);
218
Wolfram Sang16735d02013-11-14 14:32:02 -0800219 reinit_completion(&ar->install_key_done);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300220
Michal Kazior370e5672015-02-18 14:02:26 +0100221 ret = ath10k_send_key(arvif, key, cmd, macaddr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300222 if (ret)
223 return ret;
224
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +0300225 time_left = wait_for_completion_timeout(&ar->install_key_done, 3 * HZ);
226 if (time_left == 0)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300227 return -ETIMEDOUT;
228
229 return 0;
230}
231
232static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
233 const u8 *addr)
234{
235 struct ath10k *ar = arvif->ar;
236 struct ath10k_peer *peer;
237 int ret;
238 int i;
Michal Kazior370e5672015-02-18 14:02:26 +0100239 u32 flags;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300240
241 lockdep_assert_held(&ar->conf_mutex);
242
243 spin_lock_bh(&ar->data_lock);
244 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
245 spin_unlock_bh(&ar->data_lock);
246
247 if (!peer)
248 return -ENOENT;
249
250 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
251 if (arvif->wep_keys[i] == NULL)
252 continue;
Michal Kazior370e5672015-02-18 14:02:26 +0100253
254 flags = 0;
255 flags |= WMI_KEY_PAIRWISE;
256
Michal Kaziorce90b272015-04-10 13:23:21 +0000257 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
258 addr, flags);
259 if (ret)
260 return ret;
261
262 flags = 0;
263 flags |= WMI_KEY_GROUP;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300264
265 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
Michal Kazior370e5672015-02-18 14:02:26 +0100266 addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300267 if (ret)
268 return ret;
269
Sujith Manoharanae167132014-11-25 11:46:59 +0530270 spin_lock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300271 peer->keys[i] = arvif->wep_keys[i];
Sujith Manoharanae167132014-11-25 11:46:59 +0530272 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300273 }
274
Michal Kaziorce90b272015-04-10 13:23:21 +0000275 /* In some cases (notably with static WEP IBSS with multiple keys)
276 * multicast Tx becomes broken. Both pairwise and groupwise keys are
277 * installed already. Using WMI_KEY_TX_USAGE in different combinations
278 * didn't seem help. Using def_keyid vdev parameter seems to be
279 * effective so use that.
280 *
281 * FIXME: Revisit. Perhaps this can be done in a less hacky way.
282 */
283 if (arvif->def_wep_key_idx == -1)
284 return 0;
285
286 ret = ath10k_wmi_vdev_set_param(arvif->ar,
287 arvif->vdev_id,
288 arvif->ar->wmi.vdev_param->def_keyid,
289 arvif->def_wep_key_idx);
290 if (ret) {
291 ath10k_warn(ar, "failed to re-set def wpa key idxon vdev %i: %d\n",
292 arvif->vdev_id, ret);
293 return ret;
294 }
295
Kalle Valo5e3dd152013-06-12 20:52:10 +0300296 return 0;
297}
298
299static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
300 const u8 *addr)
301{
302 struct ath10k *ar = arvif->ar;
303 struct ath10k_peer *peer;
304 int first_errno = 0;
305 int ret;
306 int i;
Michal Kazior370e5672015-02-18 14:02:26 +0100307 u32 flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300308
309 lockdep_assert_held(&ar->conf_mutex);
310
311 spin_lock_bh(&ar->data_lock);
312 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
313 spin_unlock_bh(&ar->data_lock);
314
315 if (!peer)
316 return -ENOENT;
317
318 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
319 if (peer->keys[i] == NULL)
320 continue;
321
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200322 /* key flags are not required to delete the key */
Kalle Valo5e3dd152013-06-12 20:52:10 +0300323 ret = ath10k_install_key(arvif, peer->keys[i],
Michal Kazior370e5672015-02-18 14:02:26 +0100324 DISABLE_KEY, addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300325 if (ret && first_errno == 0)
326 first_errno = ret;
327
328 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200329 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300330 i, ret);
331
Sujith Manoharanae167132014-11-25 11:46:59 +0530332 spin_lock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300333 peer->keys[i] = NULL;
Sujith Manoharanae167132014-11-25 11:46:59 +0530334 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300335 }
336
337 return first_errno;
338}
339
Sujith Manoharan504f6cd2014-11-25 11:46:58 +0530340bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr,
341 u8 keyidx)
342{
343 struct ath10k_peer *peer;
344 int i;
345
346 lockdep_assert_held(&ar->data_lock);
347
348 /* We don't know which vdev this peer belongs to,
349 * since WMI doesn't give us that information.
350 *
351 * FIXME: multi-bss needs to be handled.
352 */
353 peer = ath10k_peer_find(ar, 0, addr);
354 if (!peer)
355 return false;
356
357 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
358 if (peer->keys[i] && peer->keys[i]->keyidx == keyidx)
359 return true;
360 }
361
362 return false;
363}
364
Kalle Valo5e3dd152013-06-12 20:52:10 +0300365static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
366 struct ieee80211_key_conf *key)
367{
368 struct ath10k *ar = arvif->ar;
369 struct ath10k_peer *peer;
370 u8 addr[ETH_ALEN];
371 int first_errno = 0;
372 int ret;
373 int i;
Michal Kazior370e5672015-02-18 14:02:26 +0100374 u32 flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300375
376 lockdep_assert_held(&ar->conf_mutex);
377
378 for (;;) {
379 /* since ath10k_install_key we can't hold data_lock all the
380 * time, so we try to remove the keys incrementally */
381 spin_lock_bh(&ar->data_lock);
382 i = 0;
383 list_for_each_entry(peer, &ar->peers, list) {
384 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
385 if (peer->keys[i] == key) {
Kalle Valob25f32c2014-09-14 12:50:49 +0300386 ether_addr_copy(addr, peer->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300387 peer->keys[i] = NULL;
388 break;
389 }
390 }
391
392 if (i < ARRAY_SIZE(peer->keys))
393 break;
394 }
395 spin_unlock_bh(&ar->data_lock);
396
397 if (i == ARRAY_SIZE(peer->keys))
398 break;
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200399 /* key flags are not required to delete the key */
Michal Kazior370e5672015-02-18 14:02:26 +0100400 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300401 if (ret && first_errno == 0)
402 first_errno = ret;
403
404 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200405 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +0200406 addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300407 }
408
409 return first_errno;
410}
411
Michal Kaziorad325cb2015-02-18 14:02:27 +0100412static int ath10k_mac_vif_update_wep_key(struct ath10k_vif *arvif,
413 struct ieee80211_key_conf *key)
414{
415 struct ath10k *ar = arvif->ar;
416 struct ath10k_peer *peer;
417 int ret;
418
419 lockdep_assert_held(&ar->conf_mutex);
420
421 list_for_each_entry(peer, &ar->peers, list) {
422 if (!memcmp(peer->addr, arvif->vif->addr, ETH_ALEN))
423 continue;
424
425 if (!memcmp(peer->addr, arvif->bssid, ETH_ALEN))
426 continue;
427
428 if (peer->keys[key->keyidx] == key)
429 continue;
430
431 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vif vdev %i update key %i needs update\n",
432 arvif->vdev_id, key->keyidx);
433
434 ret = ath10k_install_peer_wep_keys(arvif, peer->addr);
435 if (ret) {
436 ath10k_warn(ar, "failed to update wep keys on vdev %i for peer %pM: %d\n",
437 arvif->vdev_id, peer->addr, ret);
438 return ret;
439 }
440 }
441
442 return 0;
443}
444
Kalle Valo5e3dd152013-06-12 20:52:10 +0300445/*********************/
446/* General utilities */
447/*********************/
448
449static inline enum wmi_phy_mode
450chan_to_phymode(const struct cfg80211_chan_def *chandef)
451{
452 enum wmi_phy_mode phymode = MODE_UNKNOWN;
453
454 switch (chandef->chan->band) {
455 case IEEE80211_BAND_2GHZ:
456 switch (chandef->width) {
457 case NL80211_CHAN_WIDTH_20_NOHT:
Peter Oh6faab122014-12-18 10:13:00 -0800458 if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM)
459 phymode = MODE_11B;
460 else
461 phymode = MODE_11G;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300462 break;
463 case NL80211_CHAN_WIDTH_20:
464 phymode = MODE_11NG_HT20;
465 break;
466 case NL80211_CHAN_WIDTH_40:
467 phymode = MODE_11NG_HT40;
468 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400469 case NL80211_CHAN_WIDTH_5:
470 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300471 case NL80211_CHAN_WIDTH_80:
472 case NL80211_CHAN_WIDTH_80P80:
473 case NL80211_CHAN_WIDTH_160:
474 phymode = MODE_UNKNOWN;
475 break;
476 }
477 break;
478 case IEEE80211_BAND_5GHZ:
479 switch (chandef->width) {
480 case NL80211_CHAN_WIDTH_20_NOHT:
481 phymode = MODE_11A;
482 break;
483 case NL80211_CHAN_WIDTH_20:
484 phymode = MODE_11NA_HT20;
485 break;
486 case NL80211_CHAN_WIDTH_40:
487 phymode = MODE_11NA_HT40;
488 break;
489 case NL80211_CHAN_WIDTH_80:
490 phymode = MODE_11AC_VHT80;
491 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400492 case NL80211_CHAN_WIDTH_5:
493 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300494 case NL80211_CHAN_WIDTH_80P80:
495 case NL80211_CHAN_WIDTH_160:
496 phymode = MODE_UNKNOWN;
497 break;
498 }
499 break;
500 default:
501 break;
502 }
503
504 WARN_ON(phymode == MODE_UNKNOWN);
505 return phymode;
506}
507
508static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
509{
510/*
511 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
512 * 0 for no restriction
513 * 1 for 1/4 us
514 * 2 for 1/2 us
515 * 3 for 1 us
516 * 4 for 2 us
517 * 5 for 4 us
518 * 6 for 8 us
519 * 7 for 16 us
520 */
521 switch (mpdudensity) {
522 case 0:
523 return 0;
524 case 1:
525 case 2:
526 case 3:
527 /* Our lower layer calculations limit our precision to
528 1 microsecond */
529 return 1;
530 case 4:
531 return 2;
532 case 5:
533 return 4;
534 case 6:
535 return 8;
536 case 7:
537 return 16;
538 default:
539 return 0;
540 }
541}
542
Michal Kazior500ff9f2015-03-31 10:26:21 +0000543int ath10k_mac_vif_chan(struct ieee80211_vif *vif,
544 struct cfg80211_chan_def *def)
545{
546 struct ieee80211_chanctx_conf *conf;
547
548 rcu_read_lock();
549 conf = rcu_dereference(vif->chanctx_conf);
550 if (!conf) {
551 rcu_read_unlock();
552 return -ENOENT;
553 }
554
555 *def = conf->def;
556 rcu_read_unlock();
557
558 return 0;
559}
560
561static void ath10k_mac_num_chanctxs_iter(struct ieee80211_hw *hw,
562 struct ieee80211_chanctx_conf *conf,
563 void *data)
564{
565 int *num = data;
566
567 (*num)++;
568}
569
570static int ath10k_mac_num_chanctxs(struct ath10k *ar)
571{
572 int num = 0;
573
574 ieee80211_iter_chan_contexts_atomic(ar->hw,
575 ath10k_mac_num_chanctxs_iter,
576 &num);
577
578 return num;
579}
580
581static void
582ath10k_mac_get_any_chandef_iter(struct ieee80211_hw *hw,
583 struct ieee80211_chanctx_conf *conf,
584 void *data)
585{
586 struct cfg80211_chan_def **def = data;
587
588 *def = &conf->def;
589}
590
Marek Puzyniak7390ed32015-03-30 09:51:52 +0300591static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr,
592 enum wmi_peer_type peer_type)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300593{
594 int ret;
595
596 lockdep_assert_held(&ar->conf_mutex);
597
Michal Kaziorcfd10612014-11-25 15:16:05 +0100598 if (ar->num_peers >= ar->max_num_peers)
599 return -ENOBUFS;
600
Marek Puzyniak7390ed32015-03-30 09:51:52 +0300601 ret = ath10k_wmi_peer_create(ar, vdev_id, addr, peer_type);
Ben Greear479398b2013-11-04 09:19:34 -0800602 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200603 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200604 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300605 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800606 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300607
608 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800609 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200610 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200611 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300612 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800613 }
Michal Kazior292a7532014-11-25 15:16:04 +0100614
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100615 ar->num_peers++;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300616
617 return 0;
618}
619
Kalle Valo5a13e762014-01-20 11:01:46 +0200620static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
621{
622 struct ath10k *ar = arvif->ar;
623 u32 param;
624 int ret;
625
626 param = ar->wmi.pdev_param->sta_kickout_th;
627 ret = ath10k_wmi_pdev_set_param(ar, param,
628 ATH10K_KICKOUT_THRESHOLD);
629 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200630 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200631 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200632 return ret;
633 }
634
635 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
636 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
637 ATH10K_KEEPALIVE_MIN_IDLE);
638 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200639 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200640 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200641 return ret;
642 }
643
644 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
645 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
646 ATH10K_KEEPALIVE_MAX_IDLE);
647 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200648 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200649 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200650 return ret;
651 }
652
653 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
654 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
655 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
656 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200657 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200658 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200659 return ret;
660 }
661
662 return 0;
663}
664
Vivek Natarajanacab6402014-11-26 09:06:12 +0200665static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
Michal Kazior424121c2013-07-22 14:13:31 +0200666{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200667 struct ath10k *ar = arvif->ar;
668 u32 vdev_param;
669
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200670 vdev_param = ar->wmi.vdev_param->rts_threshold;
671 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200672}
673
674static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
675{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200676 struct ath10k *ar = arvif->ar;
677 u32 vdev_param;
678
Michal Kazior424121c2013-07-22 14:13:31 +0200679 if (value != 0xFFFFFFFF)
680 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
681 ATH10K_FRAGMT_THRESHOLD_MIN,
682 ATH10K_FRAGMT_THRESHOLD_MAX);
683
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200684 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
685 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200686}
687
Kalle Valo5e3dd152013-06-12 20:52:10 +0300688static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
689{
690 int ret;
691
692 lockdep_assert_held(&ar->conf_mutex);
693
694 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
695 if (ret)
696 return ret;
697
698 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
699 if (ret)
700 return ret;
701
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100702 ar->num_peers--;
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100703
Kalle Valo5e3dd152013-06-12 20:52:10 +0300704 return 0;
705}
706
707static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
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 if (peer->vdev_id != vdev_id)
716 continue;
717
Michal Kazior7aa7a722014-08-25 12:09:38 +0200718 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300719 peer->addr, vdev_id);
720
721 list_del(&peer->list);
722 kfree(peer);
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100723 ar->num_peers--;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300724 }
725 spin_unlock_bh(&ar->data_lock);
726}
727
Michal Kaziora96d7742013-07-16 09:38:56 +0200728static void ath10k_peer_cleanup_all(struct ath10k *ar)
729{
730 struct ath10k_peer *peer, *tmp;
731
732 lockdep_assert_held(&ar->conf_mutex);
733
734 spin_lock_bh(&ar->data_lock);
735 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
736 list_del(&peer->list);
737 kfree(peer);
738 }
739 spin_unlock_bh(&ar->data_lock);
Michal Kazior292a7532014-11-25 15:16:04 +0100740
741 ar->num_peers = 0;
Michal Kaziorcfd10612014-11-25 15:16:05 +0100742 ar->num_stations = 0;
Michal Kaziora96d7742013-07-16 09:38:56 +0200743}
744
Marek Puzyniak75d85fd2015-03-30 09:51:53 +0300745static int ath10k_mac_tdls_peer_update(struct ath10k *ar, u32 vdev_id,
746 struct ieee80211_sta *sta,
747 enum wmi_tdls_peer_state state)
748{
749 int ret;
750 struct wmi_tdls_peer_update_cmd_arg arg = {};
751 struct wmi_tdls_peer_capab_arg cap = {};
752 struct wmi_channel_arg chan_arg = {};
753
754 lockdep_assert_held(&ar->conf_mutex);
755
756 arg.vdev_id = vdev_id;
757 arg.peer_state = state;
758 ether_addr_copy(arg.addr, sta->addr);
759
760 cap.peer_max_sp = sta->max_sp;
761 cap.peer_uapsd_queues = sta->uapsd_queues;
762
763 if (state == WMI_TDLS_PEER_STATE_CONNECTED &&
764 !sta->tdls_initiator)
765 cap.is_peer_responder = 1;
766
767 ret = ath10k_wmi_tdls_peer_update(ar, &arg, &cap, &chan_arg);
768 if (ret) {
769 ath10k_warn(ar, "failed to update tdls peer %pM on vdev %i: %i\n",
770 arg.addr, vdev_id, ret);
771 return ret;
772 }
773
774 return 0;
775}
776
Kalle Valo5e3dd152013-06-12 20:52:10 +0300777/************************/
778/* Interface management */
779/************************/
780
Michal Kazior64badcb2014-09-18 11:18:02 +0300781void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
782{
783 struct ath10k *ar = arvif->ar;
784
785 lockdep_assert_held(&ar->data_lock);
786
787 if (!arvif->beacon)
788 return;
789
790 if (!arvif->beacon_buf)
791 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
792 arvif->beacon->len, DMA_TO_DEVICE);
793
Michal Kazioraf213192015-01-29 14:29:52 +0200794 if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED &&
795 arvif->beacon_state != ATH10K_BEACON_SENT))
796 return;
797
Michal Kazior64badcb2014-09-18 11:18:02 +0300798 dev_kfree_skb_any(arvif->beacon);
799
800 arvif->beacon = NULL;
Michal Kazioraf213192015-01-29 14:29:52 +0200801 arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
Michal Kazior64badcb2014-09-18 11:18:02 +0300802}
803
804static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
805{
806 struct ath10k *ar = arvif->ar;
807
808 lockdep_assert_held(&ar->data_lock);
809
810 ath10k_mac_vif_beacon_free(arvif);
811
812 if (arvif->beacon_buf) {
813 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
814 arvif->beacon_buf, arvif->beacon_paddr);
815 arvif->beacon_buf = NULL;
816 }
817}
818
Kalle Valo5e3dd152013-06-12 20:52:10 +0300819static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
820{
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +0300821 unsigned long time_left;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300822
Michal Kazior548db542013-07-05 16:15:15 +0300823 lockdep_assert_held(&ar->conf_mutex);
824
Michal Kazior7962b0d2014-10-28 10:34:38 +0100825 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
826 return -ESHUTDOWN;
827
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +0300828 time_left = wait_for_completion_timeout(&ar->vdev_setup_done,
829 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
830 if (time_left == 0)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300831 return -ETIMEDOUT;
832
833 return 0;
834}
835
Michal Kazior1bbc0972014-04-08 09:45:47 +0300836static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300837{
Michal Kazior500ff9f2015-03-31 10:26:21 +0000838 struct cfg80211_chan_def *chandef = NULL;
Michal Kaziorc930f742014-01-23 11:38:25 +0100839 struct ieee80211_channel *channel = chandef->chan;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300840 struct wmi_vdev_start_request_arg arg = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +0300841 int ret = 0;
842
843 lockdep_assert_held(&ar->conf_mutex);
844
Michal Kazior500ff9f2015-03-31 10:26:21 +0000845 ieee80211_iter_chan_contexts_atomic(ar->hw,
846 ath10k_mac_get_any_chandef_iter,
847 &chandef);
848 if (WARN_ON_ONCE(!chandef))
849 return -ENOENT;
850
851 channel = chandef->chan;
852
Kalle Valo5e3dd152013-06-12 20:52:10 +0300853 arg.vdev_id = vdev_id;
854 arg.channel.freq = channel->center_freq;
Michal Kaziorc930f742014-01-23 11:38:25 +0100855 arg.channel.band_center_freq1 = chandef->center_freq1;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300856
857 /* TODO setup this dynamically, what in case we
858 don't have any vifs? */
Michal Kaziorc930f742014-01-23 11:38:25 +0100859 arg.channel.mode = chan_to_phymode(chandef);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200860 arg.channel.chan_radar =
861 !!(channel->flags & IEEE80211_CHAN_RADAR);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300862
Michal Kazior89c5c842013-10-23 04:02:13 -0700863 arg.channel.min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -0700864 arg.channel.max_power = channel->max_power * 2;
865 arg.channel.max_reg_power = channel->max_reg_power * 2;
866 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300867
Michal Kazior7962b0d2014-10-28 10:34:38 +0100868 reinit_completion(&ar->vdev_setup_done);
869
Kalle Valo5e3dd152013-06-12 20:52:10 +0300870 ret = ath10k_wmi_vdev_start(ar, &arg);
871 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200872 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200873 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300874 return ret;
875 }
876
877 ret = ath10k_vdev_setup_sync(ar);
878 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +0200879 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200880 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300881 return ret;
882 }
883
884 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
885 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200886 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200887 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300888 goto vdev_stop;
889 }
890
891 ar->monitor_vdev_id = vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300892
Michal Kazior7aa7a722014-08-25 12:09:38 +0200893 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300894 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300895 return 0;
896
897vdev_stop:
898 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 stop monitor vdev %i after start failure: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200901 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300902
903 return ret;
904}
905
Michal Kazior1bbc0972014-04-08 09:45:47 +0300906static int ath10k_monitor_vdev_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300907{
908 int ret = 0;
909
910 lockdep_assert_held(&ar->conf_mutex);
911
Marek Puzyniak52fa0192013-09-24 14:06:24 +0200912 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
913 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200914 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200915 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300916
Michal Kazior7962b0d2014-10-28 10:34:38 +0100917 reinit_completion(&ar->vdev_setup_done);
918
Kalle Valo5e3dd152013-06-12 20:52:10 +0300919 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
920 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200921 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200922 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300923
924 ret = ath10k_vdev_setup_sync(ar);
925 if (ret)
Ben Greear60028a82015-02-15 16:50:39 +0200926 ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200927 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300928
Michal Kazior7aa7a722014-08-25 12:09:38 +0200929 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300930 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300931 return ret;
932}
933
Michal Kazior1bbc0972014-04-08 09:45:47 +0300934static int ath10k_monitor_vdev_create(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300935{
936 int bit, ret = 0;
937
938 lockdep_assert_held(&ar->conf_mutex);
939
Ben Greeara9aefb32014-08-12 11:02:19 +0300940 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200941 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +0300942 return -ENOMEM;
943 }
944
Ben Greear16c11172014-09-23 14:17:16 -0700945 bit = __ffs64(ar->free_vdev_map);
Ben Greeara9aefb32014-08-12 11:02:19 +0300946
Ben Greear16c11172014-09-23 14:17:16 -0700947 ar->monitor_vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300948
949 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
950 WMI_VDEV_TYPE_MONITOR,
951 0, ar->mac_addr);
952 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200953 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200954 ar->monitor_vdev_id, ret);
Ben Greeara9aefb32014-08-12 11:02:19 +0300955 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300956 }
957
Ben Greear16c11172014-09-23 14:17:16 -0700958 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
Michal Kazior7aa7a722014-08-25 12:09:38 +0200959 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300960 ar->monitor_vdev_id);
961
Kalle Valo5e3dd152013-06-12 20:52:10 +0300962 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300963}
964
Michal Kazior1bbc0972014-04-08 09:45:47 +0300965static int ath10k_monitor_vdev_delete(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300966{
967 int ret = 0;
968
969 lockdep_assert_held(&ar->conf_mutex);
970
Kalle Valo5e3dd152013-06-12 20:52:10 +0300971 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
972 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200973 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200974 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300975 return ret;
976 }
977
Ben Greear16c11172014-09-23 14:17:16 -0700978 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300979
Michal Kazior7aa7a722014-08-25 12:09:38 +0200980 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300981 ar->monitor_vdev_id);
982 return ret;
983}
984
Michal Kazior1bbc0972014-04-08 09:45:47 +0300985static int ath10k_monitor_start(struct ath10k *ar)
986{
987 int ret;
988
989 lockdep_assert_held(&ar->conf_mutex);
990
Michal Kazior1bbc0972014-04-08 09:45:47 +0300991 ret = ath10k_monitor_vdev_create(ar);
992 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200993 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300994 return ret;
995 }
996
997 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
998 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200999 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +03001000 ath10k_monitor_vdev_delete(ar);
1001 return ret;
1002 }
1003
1004 ar->monitor_started = true;
Michal Kazior7aa7a722014-08-25 12:09:38 +02001005 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
Michal Kazior1bbc0972014-04-08 09:45:47 +03001006
1007 return 0;
1008}
1009
Michal Kazior19337472014-08-28 12:58:16 +02001010static int ath10k_monitor_stop(struct ath10k *ar)
Michal Kazior1bbc0972014-04-08 09:45:47 +03001011{
1012 int ret;
1013
1014 lockdep_assert_held(&ar->conf_mutex);
1015
Michal Kazior1bbc0972014-04-08 09:45:47 +03001016 ret = ath10k_monitor_vdev_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +02001017 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001018 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +02001019 return ret;
1020 }
Michal Kazior1bbc0972014-04-08 09:45:47 +03001021
1022 ret = ath10k_monitor_vdev_delete(ar);
Michal Kazior19337472014-08-28 12:58:16 +02001023 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001024 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +02001025 return ret;
1026 }
Michal Kazior1bbc0972014-04-08 09:45:47 +03001027
1028 ar->monitor_started = false;
Michal Kazior7aa7a722014-08-25 12:09:38 +02001029 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
Michal Kazior19337472014-08-28 12:58:16 +02001030
1031 return 0;
1032}
1033
Vasanthakumar Thiagarajan54846212015-03-02 17:45:28 +05301034static bool ath10k_mac_should_disable_promisc(struct ath10k *ar)
1035{
1036 struct ath10k_vif *arvif;
1037
1038 if (!(ar->filter_flags & FIF_PROMISC_IN_BSS))
1039 return true;
1040
1041 if (!ar->num_started_vdevs)
1042 return false;
1043
1044 list_for_each_entry(arvif, &ar->arvifs, list)
1045 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1046 return false;
1047
1048 ath10k_dbg(ar, ATH10K_DBG_MAC,
1049 "mac disabling promiscuous mode because vdev is started\n");
1050 return true;
1051}
1052
Michal Kazior500ff9f2015-03-31 10:26:21 +00001053static bool ath10k_mac_monitor_vdev_is_needed(struct ath10k *ar)
1054{
1055 int num_ctx;
1056
1057 /* At least one chanctx is required to derive a channel to start
1058 * monitor vdev on.
1059 */
1060 num_ctx = ath10k_mac_num_chanctxs(ar);
1061 if (num_ctx == 0)
1062 return false;
1063
1064 /* If there's already an existing special monitor interface then don't
1065 * bother creating another monitor vdev.
1066 */
1067 if (ar->monitor_arvif)
1068 return false;
1069
1070 return ar->monitor ||
1071 !ath10k_mac_should_disable_promisc(ar) ||
1072 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1073}
1074
1075static bool ath10k_mac_monitor_vdev_is_allowed(struct ath10k *ar)
1076{
1077 int num_ctx;
1078
1079 num_ctx = ath10k_mac_num_chanctxs(ar);
1080
1081 /* FIXME: Current interface combinations and cfg80211/mac80211 code
1082 * shouldn't allow this but make sure to prevent handling the following
1083 * case anyway since multi-channel DFS hasn't been tested at all.
1084 */
1085 if (test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags) && num_ctx > 1)
1086 return false;
1087
1088 return true;
1089}
1090
Michal Kazior19337472014-08-28 12:58:16 +02001091static int ath10k_monitor_recalc(struct ath10k *ar)
1092{
Michal Kazior500ff9f2015-03-31 10:26:21 +00001093 bool needed;
1094 bool allowed;
1095 int ret;
Michal Kazior19337472014-08-28 12:58:16 +02001096
1097 lockdep_assert_held(&ar->conf_mutex);
1098
Michal Kazior500ff9f2015-03-31 10:26:21 +00001099 needed = ath10k_mac_monitor_vdev_is_needed(ar);
1100 allowed = ath10k_mac_monitor_vdev_is_allowed(ar);
Michal Kazior19337472014-08-28 12:58:16 +02001101
1102 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior500ff9f2015-03-31 10:26:21 +00001103 "mac monitor recalc started? %d needed? %d allowed? %d\n",
1104 ar->monitor_started, needed, allowed);
Michal Kazior19337472014-08-28 12:58:16 +02001105
Michal Kazior500ff9f2015-03-31 10:26:21 +00001106 if (WARN_ON(needed && !allowed)) {
1107 if (ar->monitor_started) {
1108 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopping disallowed monitor\n");
1109
1110 ret = ath10k_monitor_stop(ar);
1111 if (ret)
1112 ath10k_warn(ar, "failed to stop disallowed monitor: %d\n", ret);
1113 /* not serious */
1114 }
1115
1116 return -EPERM;
1117 }
1118
1119 if (needed == ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02001120 return 0;
1121
Michal Kazior500ff9f2015-03-31 10:26:21 +00001122 if (needed)
Michal Kazior19337472014-08-28 12:58:16 +02001123 return ath10k_monitor_start(ar);
Michal Kazior500ff9f2015-03-31 10:26:21 +00001124 else
1125 return ath10k_monitor_stop(ar);
Michal Kazior1bbc0972014-04-08 09:45:47 +03001126}
1127
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001128static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
1129{
1130 struct ath10k *ar = arvif->ar;
1131 u32 vdev_param, rts_cts = 0;
1132
1133 lockdep_assert_held(&ar->conf_mutex);
1134
1135 vdev_param = ar->wmi.vdev_param->enable_rtscts;
1136
Rajkumar Manoharan9a5ab0f2015-03-19 16:03:29 +02001137 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001138
1139 if (arvif->num_legacy_stations > 0)
1140 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
1141 WMI_RTSCTS_PROFILE);
Rajkumar Manoharan9a5ab0f2015-03-19 16:03:29 +02001142 else
1143 rts_cts |= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES,
1144 WMI_RTSCTS_PROFILE);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001145
1146 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
1147 rts_cts);
1148}
1149
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001150static int ath10k_start_cac(struct ath10k *ar)
1151{
1152 int ret;
1153
1154 lockdep_assert_held(&ar->conf_mutex);
1155
1156 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1157
Michal Kazior19337472014-08-28 12:58:16 +02001158 ret = ath10k_monitor_recalc(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001159 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001160 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001161 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1162 return ret;
1163 }
1164
Michal Kazior7aa7a722014-08-25 12:09:38 +02001165 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001166 ar->monitor_vdev_id);
1167
1168 return 0;
1169}
1170
1171static int ath10k_stop_cac(struct ath10k *ar)
1172{
1173 lockdep_assert_held(&ar->conf_mutex);
1174
1175 /* CAC is not running - do nothing */
1176 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
1177 return 0;
1178
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001179 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
Michal Kazior1bbc0972014-04-08 09:45:47 +03001180 ath10k_monitor_stop(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001181
Michal Kazior7aa7a722014-08-25 12:09:38 +02001182 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001183
1184 return 0;
1185}
1186
Michal Kazior500ff9f2015-03-31 10:26:21 +00001187static void ath10k_mac_has_radar_iter(struct ieee80211_hw *hw,
1188 struct ieee80211_chanctx_conf *conf,
1189 void *data)
1190{
1191 bool *ret = data;
1192
1193 if (!*ret && conf->radar_enabled)
1194 *ret = true;
1195}
1196
1197static bool ath10k_mac_has_radar_enabled(struct ath10k *ar)
1198{
1199 bool has_radar = false;
1200
1201 ieee80211_iter_chan_contexts_atomic(ar->hw,
1202 ath10k_mac_has_radar_iter,
1203 &has_radar);
1204
1205 return has_radar;
1206}
1207
Michal Kaziord6500972014-04-08 09:56:09 +03001208static void ath10k_recalc_radar_detection(struct ath10k *ar)
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001209{
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001210 int ret;
1211
1212 lockdep_assert_held(&ar->conf_mutex);
1213
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001214 ath10k_stop_cac(ar);
1215
Michal Kazior500ff9f2015-03-31 10:26:21 +00001216 if (!ath10k_mac_has_radar_enabled(ar))
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001217 return;
1218
Michal Kaziord6500972014-04-08 09:56:09 +03001219 if (ar->num_started_vdevs > 0)
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001220 return;
1221
1222 ret = ath10k_start_cac(ar);
1223 if (ret) {
1224 /*
1225 * Not possible to start CAC on current channel so starting
1226 * radiation is not allowed, make this channel DFS_UNAVAILABLE
1227 * by indicating that radar was detected.
1228 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02001229 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001230 ieee80211_radar_detected(ar->hw);
1231 }
1232}
1233
Vasanthakumar Thiagarajan822b7e02015-03-02 17:45:27 +05301234static int ath10k_vdev_stop(struct ath10k_vif *arvif)
1235{
1236 struct ath10k *ar = arvif->ar;
1237 int ret;
1238
1239 lockdep_assert_held(&ar->conf_mutex);
1240
1241 reinit_completion(&ar->vdev_setup_done);
1242
1243 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
1244 if (ret) {
1245 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
1246 arvif->vdev_id, ret);
1247 return ret;
1248 }
1249
1250 ret = ath10k_vdev_setup_sync(ar);
1251 if (ret) {
1252 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
1253 arvif->vdev_id, ret);
1254 return ret;
1255 }
1256
1257 WARN_ON(ar->num_started_vdevs == 0);
1258
1259 if (ar->num_started_vdevs != 0) {
1260 ar->num_started_vdevs--;
1261 ath10k_recalc_radar_detection(ar);
1262 }
1263
1264 return ret;
1265}
1266
Michal Kazior500ff9f2015-03-31 10:26:21 +00001267static int ath10k_vdev_start_restart(struct ath10k_vif *arvif,
1268 const struct cfg80211_chan_def *chandef,
1269 bool restart)
Michal Kazior72654fa2014-04-08 09:56:09 +03001270{
1271 struct ath10k *ar = arvif->ar;
Michal Kazior72654fa2014-04-08 09:56:09 +03001272 struct wmi_vdev_start_request_arg arg = {};
Vasanthakumar Thiagarajan54846212015-03-02 17:45:28 +05301273 int ret = 0, ret2;
Michal Kazior72654fa2014-04-08 09:56:09 +03001274
1275 lockdep_assert_held(&ar->conf_mutex);
1276
1277 reinit_completion(&ar->vdev_setup_done);
1278
1279 arg.vdev_id = arvif->vdev_id;
1280 arg.dtim_period = arvif->dtim_period;
1281 arg.bcn_intval = arvif->beacon_interval;
1282
1283 arg.channel.freq = chandef->chan->center_freq;
1284 arg.channel.band_center_freq1 = chandef->center_freq1;
1285 arg.channel.mode = chan_to_phymode(chandef);
1286
1287 arg.channel.min_power = 0;
1288 arg.channel.max_power = chandef->chan->max_power * 2;
1289 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
1290 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
1291
1292 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1293 arg.ssid = arvif->u.ap.ssid;
1294 arg.ssid_len = arvif->u.ap.ssid_len;
1295 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
1296
1297 /* For now allow DFS for AP mode */
1298 arg.channel.chan_radar =
1299 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
1300 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
1301 arg.ssid = arvif->vif->bss_conf.ssid;
1302 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
1303 }
1304
Michal Kazior7aa7a722014-08-25 12:09:38 +02001305 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior72654fa2014-04-08 09:56:09 +03001306 "mac vdev %d start center_freq %d phymode %s\n",
1307 arg.vdev_id, arg.channel.freq,
1308 ath10k_wmi_phymode_str(arg.channel.mode));
1309
Michal Kaziordc55e302014-07-29 12:53:36 +03001310 if (restart)
1311 ret = ath10k_wmi_vdev_restart(ar, &arg);
1312 else
1313 ret = ath10k_wmi_vdev_start(ar, &arg);
1314
Michal Kazior72654fa2014-04-08 09:56:09 +03001315 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001316 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +03001317 arg.vdev_id, ret);
1318 return ret;
1319 }
1320
1321 ret = ath10k_vdev_setup_sync(ar);
1322 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +02001323 ath10k_warn(ar,
1324 "failed to synchronize setup for vdev %i restart %d: %d\n",
1325 arg.vdev_id, restart, ret);
Michal Kazior72654fa2014-04-08 09:56:09 +03001326 return ret;
1327 }
1328
Michal Kaziord6500972014-04-08 09:56:09 +03001329 ar->num_started_vdevs++;
1330 ath10k_recalc_radar_detection(ar);
1331
Vasanthakumar Thiagarajan54846212015-03-02 17:45:28 +05301332 ret = ath10k_monitor_recalc(ar);
1333 if (ret) {
1334 ath10k_warn(ar, "mac failed to recalc monitor for vdev %i restart %d: %d\n",
1335 arg.vdev_id, restart, ret);
1336 ret2 = ath10k_vdev_stop(arvif);
1337 if (ret2)
1338 ath10k_warn(ar, "mac failed to stop vdev %i restart %d: %d\n",
1339 arg.vdev_id, restart, ret2);
1340 }
1341
Michal Kazior72654fa2014-04-08 09:56:09 +03001342 return ret;
1343}
1344
Michal Kazior500ff9f2015-03-31 10:26:21 +00001345static int ath10k_vdev_start(struct ath10k_vif *arvif,
1346 const struct cfg80211_chan_def *def)
Michal Kaziordc55e302014-07-29 12:53:36 +03001347{
Michal Kazior500ff9f2015-03-31 10:26:21 +00001348 return ath10k_vdev_start_restart(arvif, def, false);
Michal Kaziordc55e302014-07-29 12:53:36 +03001349}
1350
Michal Kazior500ff9f2015-03-31 10:26:21 +00001351static int ath10k_vdev_restart(struct ath10k_vif *arvif,
1352 const struct cfg80211_chan_def *def)
Michal Kaziordc55e302014-07-29 12:53:36 +03001353{
Michal Kazior500ff9f2015-03-31 10:26:21 +00001354 return ath10k_vdev_start_restart(arvif, def, true);
Michal Kaziordc55e302014-07-29 12:53:36 +03001355}
1356
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001357static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
1358 struct sk_buff *bcn)
1359{
1360 struct ath10k *ar = arvif->ar;
1361 struct ieee80211_mgmt *mgmt;
1362 const u8 *p2p_ie;
1363 int ret;
1364
1365 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1366 return 0;
1367
1368 if (arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1369 return 0;
1370
1371 mgmt = (void *)bcn->data;
1372 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1373 mgmt->u.beacon.variable,
1374 bcn->len - (mgmt->u.beacon.variable -
1375 bcn->data));
1376 if (!p2p_ie)
1377 return -ENOENT;
1378
1379 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1380 if (ret) {
1381 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1382 arvif->vdev_id, ret);
1383 return ret;
1384 }
1385
1386 return 0;
1387}
1388
1389static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1390 u8 oui_type, size_t ie_offset)
1391{
1392 size_t len;
1393 const u8 *next;
1394 const u8 *end;
1395 u8 *ie;
1396
1397 if (WARN_ON(skb->len < ie_offset))
1398 return -EINVAL;
1399
1400 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1401 skb->data + ie_offset,
1402 skb->len - ie_offset);
1403 if (!ie)
1404 return -ENOENT;
1405
1406 len = ie[1] + 2;
1407 end = skb->data + skb->len;
1408 next = ie + len;
1409
1410 if (WARN_ON(next > end))
1411 return -EINVAL;
1412
1413 memmove(ie, next, end - next);
1414 skb_trim(skb, skb->len - len);
1415
1416 return 0;
1417}
1418
1419static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1420{
1421 struct ath10k *ar = arvif->ar;
1422 struct ieee80211_hw *hw = ar->hw;
1423 struct ieee80211_vif *vif = arvif->vif;
1424 struct ieee80211_mutable_offsets offs = {};
1425 struct sk_buff *bcn;
1426 int ret;
1427
1428 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1429 return 0;
1430
Michal Kazior81a9a172015-03-05 16:02:17 +02001431 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
1432 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
1433 return 0;
1434
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001435 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1436 if (!bcn) {
1437 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1438 return -EPERM;
1439 }
1440
1441 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1442 if (ret) {
1443 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1444 kfree_skb(bcn);
1445 return ret;
1446 }
1447
1448 /* P2P IE is inserted by firmware automatically (as configured above)
1449 * so remove it from the base beacon template to avoid duplicate P2P
1450 * IEs in beacon frames.
1451 */
1452 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1453 offsetof(struct ieee80211_mgmt,
1454 u.beacon.variable));
1455
1456 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1457 0, NULL, 0);
1458 kfree_skb(bcn);
1459
1460 if (ret) {
1461 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1462 ret);
1463 return ret;
1464 }
1465
1466 return 0;
1467}
1468
1469static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1470{
1471 struct ath10k *ar = arvif->ar;
1472 struct ieee80211_hw *hw = ar->hw;
1473 struct ieee80211_vif *vif = arvif->vif;
1474 struct sk_buff *prb;
1475 int ret;
1476
1477 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1478 return 0;
1479
Michal Kazior81a9a172015-03-05 16:02:17 +02001480 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1481 return 0;
1482
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001483 prb = ieee80211_proberesp_get(hw, vif);
1484 if (!prb) {
1485 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1486 return -EPERM;
1487 }
1488
1489 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1490 kfree_skb(prb);
1491
1492 if (ret) {
1493 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1494 ret);
1495 return ret;
1496 }
1497
1498 return 0;
1499}
1500
Michal Kazior500ff9f2015-03-31 10:26:21 +00001501static int ath10k_mac_vif_fix_hidden_ssid(struct ath10k_vif *arvif)
1502{
1503 struct ath10k *ar = arvif->ar;
1504 struct cfg80211_chan_def def;
1505 int ret;
1506
1507 /* When originally vdev is started during assign_vif_chanctx() some
1508 * information is missing, notably SSID. Firmware revisions with beacon
1509 * offloading require the SSID to be provided during vdev (re)start to
1510 * handle hidden SSID properly.
1511 *
1512 * Vdev restart must be done after vdev has been both started and
1513 * upped. Otherwise some firmware revisions (at least 10.2) fail to
1514 * deliver vdev restart response event causing timeouts during vdev
1515 * syncing in ath10k.
1516 *
1517 * Note: The vdev down/up and template reinstallation could be skipped
1518 * since only wmi-tlv firmware are known to have beacon offload and
1519 * wmi-tlv doesn't seem to misbehave like 10.2 wrt vdev restart
1520 * response delivery. It's probably more robust to keep it as is.
1521 */
1522 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1523 return 0;
1524
1525 if (WARN_ON(!arvif->is_started))
1526 return -EINVAL;
1527
1528 if (WARN_ON(!arvif->is_up))
1529 return -EINVAL;
1530
1531 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
1532 return -EINVAL;
1533
1534 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1535 if (ret) {
1536 ath10k_warn(ar, "failed to bring down ap vdev %i: %d\n",
1537 arvif->vdev_id, ret);
1538 return ret;
1539 }
1540
1541 /* Vdev down reset beacon & presp templates. Reinstall them. Otherwise
1542 * firmware will crash upon vdev up.
1543 */
1544
1545 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1546 if (ret) {
1547 ath10k_warn(ar, "failed to update beacon template: %d\n", ret);
1548 return ret;
1549 }
1550
1551 ret = ath10k_mac_setup_prb_tmpl(arvif);
1552 if (ret) {
1553 ath10k_warn(ar, "failed to update presp template: %d\n", ret);
1554 return ret;
1555 }
1556
1557 ret = ath10k_vdev_restart(arvif, &def);
1558 if (ret) {
1559 ath10k_warn(ar, "failed to restart ap vdev %i: %d\n",
1560 arvif->vdev_id, ret);
1561 return ret;
1562 }
1563
1564 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1565 arvif->bssid);
1566 if (ret) {
1567 ath10k_warn(ar, "failed to bring up ap vdev %i: %d\n",
1568 arvif->vdev_id, ret);
1569 return ret;
1570 }
1571
1572 return 0;
1573}
1574
Kalle Valo5e3dd152013-06-12 20:52:10 +03001575static void ath10k_control_beaconing(struct ath10k_vif *arvif,
Kalle Valo5b07e072014-09-14 12:50:06 +03001576 struct ieee80211_bss_conf *info)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001577{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001578 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001579 int ret = 0;
1580
Michal Kazior548db542013-07-05 16:15:15 +03001581 lockdep_assert_held(&arvif->ar->conf_mutex);
1582
Kalle Valo5e3dd152013-06-12 20:52:10 +03001583 if (!info->enable_beacon) {
Michal Kazior500ff9f2015-03-31 10:26:21 +00001584 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1585 if (ret)
1586 ath10k_warn(ar, "failed to down vdev_id %i: %d\n",
1587 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001588
Michal Kaziorc930f742014-01-23 11:38:25 +01001589 arvif->is_up = false;
Michal Kazior8513d952015-03-09 14:19:24 +01001590
1591 spin_lock_bh(&arvif->ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03001592 ath10k_mac_vif_beacon_free(arvif);
Michal Kazior748afc42014-01-23 12:48:21 +01001593 spin_unlock_bh(&arvif->ar->data_lock);
1594
Kalle Valo5e3dd152013-06-12 20:52:10 +03001595 return;
1596 }
1597
1598 arvif->tx_seq_no = 0x1000;
1599
Michal Kaziorc930f742014-01-23 11:38:25 +01001600 arvif->aid = 0;
Kalle Valob25f32c2014-09-14 12:50:49 +03001601 ether_addr_copy(arvif->bssid, info->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01001602
1603 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1604 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001605 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001606 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001607 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001608 return;
1609 }
Michal Kaziorc930f742014-01-23 11:38:25 +01001610
Michal Kaziorc930f742014-01-23 11:38:25 +01001611 arvif->is_up = true;
1612
Michal Kazior500ff9f2015-03-31 10:26:21 +00001613 ret = ath10k_mac_vif_fix_hidden_ssid(arvif);
1614 if (ret) {
1615 ath10k_warn(ar, "failed to fix hidden ssid for vdev %i, expect trouble: %d\n",
1616 arvif->vdev_id, ret);
1617 return;
1618 }
1619
Michal Kazior7aa7a722014-08-25 12:09:38 +02001620 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001621}
1622
1623static void ath10k_control_ibss(struct ath10k_vif *arvif,
1624 struct ieee80211_bss_conf *info,
1625 const u8 self_peer[ETH_ALEN])
1626{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001627 struct ath10k *ar = arvif->ar;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001628 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001629 int ret = 0;
1630
Michal Kazior548db542013-07-05 16:15:15 +03001631 lockdep_assert_held(&arvif->ar->conf_mutex);
1632
Kalle Valo5e3dd152013-06-12 20:52:10 +03001633 if (!info->ibss_joined) {
Michal Kaziorc930f742014-01-23 11:38:25 +01001634 if (is_zero_ether_addr(arvif->bssid))
Kalle Valo5e3dd152013-06-12 20:52:10 +03001635 return;
1636
Michal Kaziorc930f742014-01-23 11:38:25 +01001637 memset(arvif->bssid, 0, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001638
1639 return;
1640 }
1641
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001642 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1643 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001644 ATH10K_DEFAULT_ATIM);
1645 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001646 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001647 arvif->vdev_id, ret);
1648}
1649
Michal Kazior9f9b5742014-12-12 12:41:36 +01001650static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1651{
1652 struct ath10k *ar = arvif->ar;
1653 u32 param;
1654 u32 value;
1655 int ret;
1656
1657 lockdep_assert_held(&arvif->ar->conf_mutex);
1658
1659 if (arvif->u.sta.uapsd)
1660 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1661 else
1662 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1663
1664 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1665 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1666 if (ret) {
1667 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1668 value, arvif->vdev_id, ret);
1669 return ret;
1670 }
1671
1672 return 0;
1673}
1674
1675static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1676{
1677 struct ath10k *ar = arvif->ar;
1678 u32 param;
1679 u32 value;
1680 int ret;
1681
1682 lockdep_assert_held(&arvif->ar->conf_mutex);
1683
1684 if (arvif->u.sta.uapsd)
1685 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1686 else
1687 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1688
1689 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1690 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1691 param, value);
1692 if (ret) {
1693 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1694 value, arvif->vdev_id, ret);
1695 return ret;
1696 }
1697
1698 return 0;
1699}
1700
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001701static int ath10k_mac_ps_vif_count(struct ath10k *ar)
1702{
1703 struct ath10k_vif *arvif;
1704 int num = 0;
1705
1706 lockdep_assert_held(&ar->conf_mutex);
1707
1708 list_for_each_entry(arvif, &ar->arvifs, list)
1709 if (arvif->ps)
1710 num++;
1711
1712 return num;
1713}
1714
Michal Kaziorad088bf2013-10-16 15:44:46 +03001715static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001716{
Michal Kaziorad088bf2013-10-16 15:44:46 +03001717 struct ath10k *ar = arvif->ar;
Michal Kazior526549a2014-12-12 12:41:37 +01001718 struct ieee80211_vif *vif = arvif->vif;
Michal Kaziorad088bf2013-10-16 15:44:46 +03001719 struct ieee80211_conf *conf = &ar->hw->conf;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001720 enum wmi_sta_powersave_param param;
1721 enum wmi_sta_ps_mode psmode;
1722 int ret;
Michal Kazior526549a2014-12-12 12:41:37 +01001723 int ps_timeout;
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001724 bool enable_ps;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001725
Michal Kazior548db542013-07-05 16:15:15 +03001726 lockdep_assert_held(&arvif->ar->conf_mutex);
1727
Michal Kaziorad088bf2013-10-16 15:44:46 +03001728 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1729 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001730
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001731 enable_ps = arvif->ps;
1732
1733 if (enable_ps && ath10k_mac_ps_vif_count(ar) > 1 &&
1734 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
1735 ar->fw_features)) {
1736 ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
1737 arvif->vdev_id);
1738 enable_ps = false;
1739 }
1740
1741 if (enable_ps) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001742 psmode = WMI_STA_PS_MODE_ENABLED;
1743 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1744
Michal Kazior526549a2014-12-12 12:41:37 +01001745 ps_timeout = conf->dynamic_ps_timeout;
1746 if (ps_timeout == 0) {
1747 /* Firmware doesn't like 0 */
1748 ps_timeout = ieee80211_tu_to_usec(
1749 vif->bss_conf.beacon_int) / 1000;
1750 }
1751
Michal Kaziorad088bf2013-10-16 15:44:46 +03001752 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
Michal Kazior526549a2014-12-12 12:41:37 +01001753 ps_timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001754 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001755 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001756 arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001757 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001758 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001759 } else {
1760 psmode = WMI_STA_PS_MODE_DISABLED;
1761 }
1762
Michal Kazior7aa7a722014-08-25 12:09:38 +02001763 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001764 arvif->vdev_id, psmode ? "enable" : "disable");
1765
Michal Kaziorad088bf2013-10-16 15:44:46 +03001766 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1767 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001768 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001769 psmode, arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001770 return ret;
1771 }
1772
1773 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001774}
1775
Michal Kazior46725b152015-01-28 09:57:49 +02001776static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1777{
1778 struct ath10k *ar = arvif->ar;
1779 struct wmi_sta_keepalive_arg arg = {};
1780 int ret;
1781
1782 lockdep_assert_held(&arvif->ar->conf_mutex);
1783
1784 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1785 return 0;
1786
1787 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1788 return 0;
1789
1790 /* Some firmware revisions have a bug and ignore the `enabled` field.
1791 * Instead use the interval to disable the keepalive.
1792 */
1793 arg.vdev_id = arvif->vdev_id;
1794 arg.enabled = 1;
1795 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1796 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1797
1798 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1799 if (ret) {
1800 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1801 arvif->vdev_id, ret);
1802 return ret;
1803 }
1804
1805 return 0;
1806}
1807
Michal Kazior81a9a172015-03-05 16:02:17 +02001808static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif)
1809{
1810 struct ath10k *ar = arvif->ar;
1811 struct ieee80211_vif *vif = arvif->vif;
1812 int ret;
1813
Michal Kazior8513d952015-03-09 14:19:24 +01001814 lockdep_assert_held(&arvif->ar->conf_mutex);
1815
1816 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)))
1817 return;
1818
Michal Kazior81a9a172015-03-05 16:02:17 +02001819 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1820 return;
1821
1822 if (!vif->csa_active)
1823 return;
1824
1825 if (!arvif->is_up)
1826 return;
1827
1828 if (!ieee80211_csa_is_complete(vif)) {
1829 ieee80211_csa_update_counter(vif);
1830
1831 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1832 if (ret)
1833 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
1834 ret);
1835
1836 ret = ath10k_mac_setup_prb_tmpl(arvif);
1837 if (ret)
1838 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
1839 ret);
1840 } else {
1841 ieee80211_csa_finish(vif);
1842 }
1843}
1844
1845static void ath10k_mac_vif_ap_csa_work(struct work_struct *work)
1846{
1847 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1848 ap_csa_work);
1849 struct ath10k *ar = arvif->ar;
1850
1851 mutex_lock(&ar->conf_mutex);
1852 ath10k_mac_vif_ap_csa_count_down(arvif);
1853 mutex_unlock(&ar->conf_mutex);
1854}
1855
Michal Kaziorcc9904e2015-03-10 16:22:01 +02001856static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac,
1857 struct ieee80211_vif *vif)
1858{
1859 struct sk_buff *skb = data;
1860 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1861 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1862
1863 if (vif->type != NL80211_IFTYPE_STATION)
1864 return;
1865
1866 if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
1867 return;
1868
1869 cancel_delayed_work(&arvif->connection_loss_work);
1870}
1871
1872void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb)
1873{
1874 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1875 IEEE80211_IFACE_ITER_NORMAL,
1876 ath10k_mac_handle_beacon_iter,
1877 skb);
1878}
1879
1880static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac,
1881 struct ieee80211_vif *vif)
1882{
1883 u32 *vdev_id = data;
1884 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1885 struct ath10k *ar = arvif->ar;
1886 struct ieee80211_hw *hw = ar->hw;
1887
1888 if (arvif->vdev_id != *vdev_id)
1889 return;
1890
1891 if (!arvif->is_up)
1892 return;
1893
1894 ieee80211_beacon_loss(vif);
1895
1896 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
1897 * (done by mac80211) succeeds but beacons do not resume then it
1898 * doesn't make sense to continue operation. Queue connection loss work
1899 * which can be cancelled when beacon is received.
1900 */
1901 ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
1902 ATH10K_CONNECTION_LOSS_HZ);
1903}
1904
1905void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id)
1906{
1907 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1908 IEEE80211_IFACE_ITER_NORMAL,
1909 ath10k_mac_handle_beacon_miss_iter,
1910 &vdev_id);
1911}
1912
1913static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work)
1914{
1915 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1916 connection_loss_work.work);
1917 struct ieee80211_vif *vif = arvif->vif;
1918
1919 if (!arvif->is_up)
1920 return;
1921
1922 ieee80211_connection_loss(vif);
1923}
1924
Kalle Valo5e3dd152013-06-12 20:52:10 +03001925/**********************/
1926/* Station management */
1927/**********************/
1928
Michal Kazior590922a2014-10-21 10:10:29 +03001929static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1930 struct ieee80211_vif *vif)
1931{
1932 /* Some firmware revisions have unstable STA powersave when listen
1933 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1934 * generate NullFunc frames properly even if buffered frames have been
1935 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1936 * buffered frames. Often pinging the device from AP would simply fail.
1937 *
1938 * As a workaround set it to 1.
1939 */
1940 if (vif->type == NL80211_IFTYPE_STATION)
1941 return 1;
1942
1943 return ar->hw->conf.listen_interval;
1944}
1945
Kalle Valo5e3dd152013-06-12 20:52:10 +03001946static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001947 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001948 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001949 struct wmi_peer_assoc_complete_arg *arg)
1950{
Michal Kazior590922a2014-10-21 10:10:29 +03001951 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorc51880e2015-03-30 09:51:57 +03001952 u32 aid;
Michal Kazior590922a2014-10-21 10:10:29 +03001953
Michal Kazior548db542013-07-05 16:15:15 +03001954 lockdep_assert_held(&ar->conf_mutex);
1955
Michal Kaziorc51880e2015-03-30 09:51:57 +03001956 if (vif->type == NL80211_IFTYPE_STATION)
1957 aid = vif->bss_conf.aid;
1958 else
1959 aid = sta->aid;
1960
Kalle Valob25f32c2014-09-14 12:50:49 +03001961 ether_addr_copy(arg->addr, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001962 arg->vdev_id = arvif->vdev_id;
Michal Kaziorc51880e2015-03-30 09:51:57 +03001963 arg->peer_aid = aid;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001964 arg->peer_flags |= WMI_PEER_AUTH;
Michal Kazior590922a2014-10-21 10:10:29 +03001965 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001966 arg->peer_num_spatial_streams = 1;
Michal Kazior590922a2014-10-21 10:10:29 +03001967 arg->peer_caps = vif->bss_conf.assoc_capability;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001968}
1969
1970static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001971 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001972 struct wmi_peer_assoc_complete_arg *arg)
1973{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001974 struct ieee80211_bss_conf *info = &vif->bss_conf;
Michal Kazior500ff9f2015-03-31 10:26:21 +00001975 struct cfg80211_chan_def def;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001976 struct cfg80211_bss *bss;
1977 const u8 *rsnie = NULL;
1978 const u8 *wpaie = NULL;
1979
Michal Kazior548db542013-07-05 16:15:15 +03001980 lockdep_assert_held(&ar->conf_mutex);
1981
Michal Kazior500ff9f2015-03-31 10:26:21 +00001982 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
1983 return;
1984
1985 bss = cfg80211_get_bss(ar->hw->wiphy, def.chan, info->bssid, NULL, 0,
1986 IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001987 if (bss) {
1988 const struct cfg80211_bss_ies *ies;
1989
1990 rcu_read_lock();
1991 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1992
1993 ies = rcu_dereference(bss->ies);
1994
1995 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
Kalle Valo5b07e072014-09-14 12:50:06 +03001996 WLAN_OUI_TYPE_MICROSOFT_WPA,
1997 ies->data,
1998 ies->len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001999 rcu_read_unlock();
2000 cfg80211_put_bss(ar->hw->wiphy, bss);
2001 }
2002
2003 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
2004 if (rsnie || wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002005 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002006 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
2007 }
2008
2009 if (wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002010 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002011 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
2012 }
2013}
2014
2015static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
Michal Kazior500ff9f2015-03-31 10:26:21 +00002016 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002017 struct ieee80211_sta *sta,
2018 struct wmi_peer_assoc_complete_arg *arg)
2019{
Michal Kazior45c9abc2015-04-21 20:42:58 +03002020 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002021 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
Michal Kazior500ff9f2015-03-31 10:26:21 +00002022 struct cfg80211_chan_def def;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002023 const struct ieee80211_supported_band *sband;
2024 const struct ieee80211_rate *rates;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002025 enum ieee80211_band band;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002026 u32 ratemask;
Michal Kazior486017c2015-03-30 09:51:54 +03002027 u8 rate;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002028 int i;
2029
Michal Kazior548db542013-07-05 16:15:15 +03002030 lockdep_assert_held(&ar->conf_mutex);
2031
Michal Kazior500ff9f2015-03-31 10:26:21 +00002032 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2033 return;
2034
Michal Kazior45c9abc2015-04-21 20:42:58 +03002035 band = def.chan->band;
2036 sband = ar->hw->wiphy->bands[band];
2037 ratemask = sta->supp_rates[band];
2038 ratemask &= arvif->bitrate_mask.control[band].legacy;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002039 rates = sband->bitrates;
2040
2041 rateset->num_rates = 0;
2042
2043 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
2044 if (!(ratemask & 1))
2045 continue;
2046
Michal Kazior486017c2015-03-30 09:51:54 +03002047 rate = ath10k_mac_bitrate_to_rate(rates->bitrate);
2048 rateset->rates[rateset->num_rates] = rate;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002049 rateset->num_rates++;
2050 }
2051}
2052
Michal Kazior45c9abc2015-04-21 20:42:58 +03002053static bool
2054ath10k_peer_assoc_h_ht_masked(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
2055{
2056 int nss;
2057
2058 for (nss = 0; nss < IEEE80211_HT_MCS_MASK_LEN; nss++)
2059 if (ht_mcs_mask[nss])
2060 return false;
2061
2062 return true;
2063}
2064
2065static bool
2066ath10k_peer_assoc_h_vht_masked(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
2067{
2068 int nss;
2069
2070 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++)
2071 if (vht_mcs_mask[nss])
2072 return false;
2073
2074 return true;
2075}
2076
Kalle Valo5e3dd152013-06-12 20:52:10 +03002077static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
Michal Kazior45c9abc2015-04-21 20:42:58 +03002078 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002079 struct ieee80211_sta *sta,
2080 struct wmi_peer_assoc_complete_arg *arg)
2081{
2082 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002083 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2084 struct cfg80211_chan_def def;
2085 enum ieee80211_band band;
2086 const u8 *ht_mcs_mask;
2087 const u16 *vht_mcs_mask;
2088 int i, n, max_nss;
Kalle Valoaf762c02014-09-14 12:50:17 +03002089 u32 stbc;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002090
Michal Kazior548db542013-07-05 16:15:15 +03002091 lockdep_assert_held(&ar->conf_mutex);
2092
Michal Kazior45c9abc2015-04-21 20:42:58 +03002093 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2094 return;
2095
Kalle Valo5e3dd152013-06-12 20:52:10 +03002096 if (!ht_cap->ht_supported)
2097 return;
2098
Michal Kazior45c9abc2015-04-21 20:42:58 +03002099 band = def.chan->band;
2100 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2101 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2102
2103 if (ath10k_peer_assoc_h_ht_masked(ht_mcs_mask) &&
2104 ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2105 return;
2106
Kalle Valo5e3dd152013-06-12 20:52:10 +03002107 arg->peer_flags |= WMI_PEER_HT;
2108 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2109 ht_cap->ampdu_factor)) - 1;
2110
2111 arg->peer_mpdu_density =
2112 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
2113
2114 arg->peer_ht_caps = ht_cap->cap;
2115 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
2116
2117 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
2118 arg->peer_flags |= WMI_PEER_LDPC;
2119
2120 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
2121 arg->peer_flags |= WMI_PEER_40MHZ;
2122 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
2123 }
2124
Michal Kazior45c9abc2015-04-21 20:42:58 +03002125 if (arvif->bitrate_mask.control[band].gi != NL80211_TXRATE_FORCE_LGI) {
2126 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
2127 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002128
Michal Kazior45c9abc2015-04-21 20:42:58 +03002129 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
2130 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2131 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002132
2133 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
2134 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
2135 arg->peer_flags |= WMI_PEER_STBC;
2136 }
2137
2138 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002139 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
2140 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
2141 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
2142 arg->peer_rate_caps |= stbc;
2143 arg->peer_flags |= WMI_PEER_STBC;
2144 }
2145
Kalle Valo5e3dd152013-06-12 20:52:10 +03002146 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
2147 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
2148 else if (ht_cap->mcs.rx_mask[1])
2149 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
2150
Michal Kazior45c9abc2015-04-21 20:42:58 +03002151 for (i = 0, n = 0, max_nss = 0; i < IEEE80211_HT_MCS_MASK_LEN * 8; i++)
2152 if ((ht_cap->mcs.rx_mask[i / 8] & BIT(i % 8)) &&
2153 (ht_mcs_mask[i / 8] & BIT(i % 8))) {
2154 max_nss = (i / 8) + 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002155 arg->peer_ht_rates.rates[n++] = i;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002156 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002157
Bartosz Markowskifd71f802014-02-10 13:12:55 +01002158 /*
2159 * This is a workaround for HT-enabled STAs which break the spec
2160 * and have no HT capabilities RX mask (no HT RX MCS map).
2161 *
2162 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
2163 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
2164 *
2165 * Firmware asserts if such situation occurs.
2166 */
2167 if (n == 0) {
2168 arg->peer_ht_rates.num_rates = 8;
2169 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
2170 arg->peer_ht_rates.rates[i] = i;
2171 } else {
2172 arg->peer_ht_rates.num_rates = n;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002173 arg->peer_num_spatial_streams = max_nss;
Bartosz Markowskifd71f802014-02-10 13:12:55 +01002174 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002175
Michal Kazior7aa7a722014-08-25 12:09:38 +02002176 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03002177 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002178 arg->peer_ht_rates.num_rates,
2179 arg->peer_num_spatial_streams);
2180}
2181
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002182static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
2183 struct ath10k_vif *arvif,
2184 struct ieee80211_sta *sta)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002185{
2186 u32 uapsd = 0;
2187 u32 max_sp = 0;
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002188 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002189
Michal Kazior548db542013-07-05 16:15:15 +03002190 lockdep_assert_held(&ar->conf_mutex);
2191
Kalle Valo5e3dd152013-06-12 20:52:10 +03002192 if (sta->wme && sta->uapsd_queues) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002193 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002194 sta->uapsd_queues, sta->max_sp);
2195
Kalle Valo5e3dd152013-06-12 20:52:10 +03002196 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2197 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
2198 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
2199 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2200 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
2201 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
2202 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2203 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
2204 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
2205 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2206 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
2207 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
2208
Kalle Valo5e3dd152013-06-12 20:52:10 +03002209 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
2210 max_sp = sta->max_sp;
2211
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002212 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2213 sta->addr,
2214 WMI_AP_PS_PEER_PARAM_UAPSD,
2215 uapsd);
2216 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002217 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002218 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002219 return ret;
2220 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002221
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002222 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2223 sta->addr,
2224 WMI_AP_PS_PEER_PARAM_MAX_SP,
2225 max_sp);
2226 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002227 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002228 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002229 return ret;
2230 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002231
2232 /* TODO setup this based on STA listen interval and
2233 beacon interval. Currently we don't know
2234 sta->listen_interval - mac80211 patch required.
2235 Currently use 10 seconds */
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002236 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
Kalle Valo5b07e072014-09-14 12:50:06 +03002237 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
2238 10);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002239 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002240 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002241 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002242 return ret;
2243 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002244 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002245
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002246 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002247}
2248
Michal Kazior45c9abc2015-04-21 20:42:58 +03002249static u16
2250ath10k_peer_assoc_h_vht_limit(u16 tx_mcs_set,
2251 const u16 vht_mcs_limit[NL80211_VHT_NSS_MAX])
2252{
2253 int idx_limit;
2254 int nss;
2255 u16 mcs_map;
2256 u16 mcs;
2257
2258 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
2259 mcs_map = ath10k_mac_get_max_vht_mcs_map(tx_mcs_set, nss) &
2260 vht_mcs_limit[nss];
2261
2262 if (mcs_map)
2263 idx_limit = fls(mcs_map) - 1;
2264 else
2265 idx_limit = -1;
2266
2267 switch (idx_limit) {
2268 case 0: /* fall through */
2269 case 1: /* fall through */
2270 case 2: /* fall through */
2271 case 3: /* fall through */
2272 case 4: /* fall through */
2273 case 5: /* fall through */
2274 case 6: /* fall through */
2275 default:
2276 /* see ath10k_mac_can_set_bitrate_mask() */
2277 WARN_ON(1);
2278 /* fall through */
2279 case -1:
2280 mcs = IEEE80211_VHT_MCS_NOT_SUPPORTED;
2281 break;
2282 case 7:
2283 mcs = IEEE80211_VHT_MCS_SUPPORT_0_7;
2284 break;
2285 case 8:
2286 mcs = IEEE80211_VHT_MCS_SUPPORT_0_8;
2287 break;
2288 case 9:
2289 mcs = IEEE80211_VHT_MCS_SUPPORT_0_9;
2290 break;
2291 }
2292
2293 tx_mcs_set &= ~(0x3 << (nss * 2));
2294 tx_mcs_set |= mcs << (nss * 2);
2295 }
2296
2297 return tx_mcs_set;
2298}
2299
Kalle Valo5e3dd152013-06-12 20:52:10 +03002300static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
Michal Kazior500ff9f2015-03-31 10:26:21 +00002301 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002302 struct ieee80211_sta *sta,
2303 struct wmi_peer_assoc_complete_arg *arg)
2304{
2305 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002306 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior500ff9f2015-03-31 10:26:21 +00002307 struct cfg80211_chan_def def;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002308 enum ieee80211_band band;
2309 const u16 *vht_mcs_mask;
Sujith Manoharana24b88b2013-10-07 19:51:57 -07002310 u8 ampdu_factor;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002311
Michal Kazior500ff9f2015-03-31 10:26:21 +00002312 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2313 return;
2314
Kalle Valo5e3dd152013-06-12 20:52:10 +03002315 if (!vht_cap->vht_supported)
2316 return;
2317
Michal Kazior45c9abc2015-04-21 20:42:58 +03002318 band = def.chan->band;
2319 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2320
2321 if (ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2322 return;
2323
Kalle Valo5e3dd152013-06-12 20:52:10 +03002324 arg->peer_flags |= WMI_PEER_VHT;
Yanbo Lid68bb122015-01-23 08:18:20 +08002325
Michal Kazior500ff9f2015-03-31 10:26:21 +00002326 if (def.chan->band == IEEE80211_BAND_2GHZ)
Yanbo Lid68bb122015-01-23 08:18:20 +08002327 arg->peer_flags |= WMI_PEER_VHT_2G;
2328
Kalle Valo5e3dd152013-06-12 20:52:10 +03002329 arg->peer_vht_caps = vht_cap->cap;
2330
Sujith Manoharana24b88b2013-10-07 19:51:57 -07002331 ampdu_factor = (vht_cap->cap &
2332 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
2333 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
2334
2335 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
2336 * zero in VHT IE. Using it would result in degraded throughput.
2337 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
2338 * it if VHT max_mpdu is smaller. */
2339 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
2340 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2341 ampdu_factor)) - 1);
2342
Kalle Valo5e3dd152013-06-12 20:52:10 +03002343 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2344 arg->peer_flags |= WMI_PEER_80MHZ;
2345
2346 arg->peer_vht_rates.rx_max_rate =
2347 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
2348 arg->peer_vht_rates.rx_mcs_set =
2349 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
2350 arg->peer_vht_rates.tx_max_rate =
2351 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
Michal Kazior45c9abc2015-04-21 20:42:58 +03002352 arg->peer_vht_rates.tx_mcs_set = ath10k_peer_assoc_h_vht_limit(
2353 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map), vht_mcs_mask);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002354
Michal Kazior7aa7a722014-08-25 12:09:38 +02002355 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03002356 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002357}
2358
2359static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03002360 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002361 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002362 struct wmi_peer_assoc_complete_arg *arg)
2363{
Michal Kazior590922a2014-10-21 10:10:29 +03002364 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2365
Kalle Valo5e3dd152013-06-12 20:52:10 +03002366 switch (arvif->vdev_type) {
2367 case WMI_VDEV_TYPE_AP:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002368 if (sta->wme)
2369 arg->peer_flags |= WMI_PEER_QOS;
2370
2371 if (sta->wme && sta->uapsd_queues) {
2372 arg->peer_flags |= WMI_PEER_APSD;
2373 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
2374 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002375 break;
2376 case WMI_VDEV_TYPE_STA:
Michal Kazior590922a2014-10-21 10:10:29 +03002377 if (vif->bss_conf.qos)
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002378 arg->peer_flags |= WMI_PEER_QOS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002379 break;
Janusz Dziedzic627d9842014-12-17 12:29:54 +02002380 case WMI_VDEV_TYPE_IBSS:
2381 if (sta->wme)
2382 arg->peer_flags |= WMI_PEER_QOS;
2383 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002384 default:
2385 break;
2386 }
Janusz Dziedzic627d9842014-12-17 12:29:54 +02002387
2388 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
2389 sta->addr, !!(arg->peer_flags & WMI_PEER_QOS));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002390}
2391
Michal Kazior8d7aa6b2015-03-30 09:51:57 +03002392static bool ath10k_mac_sta_has_ofdm_only(struct ieee80211_sta *sta)
Michal Kazior91b12082014-12-12 12:41:35 +01002393{
Michal Kazior8d7aa6b2015-03-30 09:51:57 +03002394 return sta->supp_rates[IEEE80211_BAND_2GHZ] >>
2395 ATH10K_MAC_FIRST_OFDM_RATE_IDX;
Michal Kazior91b12082014-12-12 12:41:35 +01002396}
2397
Kalle Valo5e3dd152013-06-12 20:52:10 +03002398static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03002399 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002400 struct ieee80211_sta *sta,
2401 struct wmi_peer_assoc_complete_arg *arg)
2402{
Michal Kazior45c9abc2015-04-21 20:42:58 +03002403 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior500ff9f2015-03-31 10:26:21 +00002404 struct cfg80211_chan_def def;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002405 enum ieee80211_band band;
2406 const u8 *ht_mcs_mask;
2407 const u16 *vht_mcs_mask;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002408 enum wmi_phy_mode phymode = MODE_UNKNOWN;
2409
Michal Kazior500ff9f2015-03-31 10:26:21 +00002410 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2411 return;
2412
Michal Kazior45c9abc2015-04-21 20:42:58 +03002413 band = def.chan->band;
2414 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2415 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2416
2417 switch (band) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002418 case IEEE80211_BAND_2GHZ:
Michal Kazior45c9abc2015-04-21 20:42:58 +03002419 if (sta->vht_cap.vht_supported &&
2420 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
Yanbo Lid68bb122015-01-23 08:18:20 +08002421 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2422 phymode = MODE_11AC_VHT40;
2423 else
2424 phymode = MODE_11AC_VHT20;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002425 } else if (sta->ht_cap.ht_supported &&
2426 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002427 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2428 phymode = MODE_11NG_HT40;
2429 else
2430 phymode = MODE_11NG_HT20;
Michal Kazior8d7aa6b2015-03-30 09:51:57 +03002431 } else if (ath10k_mac_sta_has_ofdm_only(sta)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002432 phymode = MODE_11G;
Michal Kazior91b12082014-12-12 12:41:35 +01002433 } else {
2434 phymode = MODE_11B;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002435 }
2436
2437 break;
2438 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03002439 /*
2440 * Check VHT first.
2441 */
Michal Kazior45c9abc2015-04-21 20:42:58 +03002442 if (sta->vht_cap.vht_supported &&
2443 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03002444 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2445 phymode = MODE_11AC_VHT80;
2446 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2447 phymode = MODE_11AC_VHT40;
2448 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
2449 phymode = MODE_11AC_VHT20;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002450 } else if (sta->ht_cap.ht_supported &&
2451 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2452 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002453 phymode = MODE_11NA_HT40;
2454 else
2455 phymode = MODE_11NA_HT20;
2456 } else {
2457 phymode = MODE_11A;
2458 }
2459
2460 break;
2461 default:
2462 break;
2463 }
2464
Michal Kazior7aa7a722014-08-25 12:09:38 +02002465 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
Kalle Valo38a1d472013-09-08 17:56:14 +03002466 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03002467
Kalle Valo5e3dd152013-06-12 20:52:10 +03002468 arg->peer_phymode = phymode;
2469 WARN_ON(phymode == MODE_UNKNOWN);
2470}
2471
Kalle Valob9ada652013-10-16 15:44:46 +03002472static int ath10k_peer_assoc_prepare(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03002473 struct ieee80211_vif *vif,
Kalle Valob9ada652013-10-16 15:44:46 +03002474 struct ieee80211_sta *sta,
Kalle Valob9ada652013-10-16 15:44:46 +03002475 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002476{
Michal Kazior548db542013-07-05 16:15:15 +03002477 lockdep_assert_held(&ar->conf_mutex);
2478
Kalle Valob9ada652013-10-16 15:44:46 +03002479 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002480
Michal Kazior590922a2014-10-21 10:10:29 +03002481 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
2482 ath10k_peer_assoc_h_crypto(ar, vif, arg);
Michal Kazior500ff9f2015-03-31 10:26:21 +00002483 ath10k_peer_assoc_h_rates(ar, vif, sta, arg);
Michal Kazior45c9abc2015-04-21 20:42:58 +03002484 ath10k_peer_assoc_h_ht(ar, vif, sta, arg);
Michal Kazior500ff9f2015-03-31 10:26:21 +00002485 ath10k_peer_assoc_h_vht(ar, vif, sta, arg);
Michal Kazior590922a2014-10-21 10:10:29 +03002486 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
2487 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002488
Kalle Valob9ada652013-10-16 15:44:46 +03002489 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002490}
2491
Michal Kazior90046f52014-02-14 14:45:51 +01002492static const u32 ath10k_smps_map[] = {
2493 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
2494 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
2495 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
2496 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
2497};
2498
2499static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
2500 const u8 *addr,
2501 const struct ieee80211_sta_ht_cap *ht_cap)
2502{
2503 int smps;
2504
2505 if (!ht_cap->ht_supported)
2506 return 0;
2507
2508 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
2509 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
2510
2511 if (smps >= ARRAY_SIZE(ath10k_smps_map))
2512 return -EINVAL;
2513
2514 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
2515 WMI_PEER_SMPS_STATE,
2516 ath10k_smps_map[smps]);
2517}
2518
Michal Kazior139e1702015-02-15 16:50:42 +02002519static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
2520 struct ieee80211_vif *vif,
2521 struct ieee80211_sta_vht_cap vht_cap)
2522{
2523 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2524 int ret;
2525 u32 param;
2526 u32 value;
2527
2528 if (!(ar->vht_cap_info &
2529 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2530 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
2531 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2532 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
2533 return 0;
2534
2535 param = ar->wmi.vdev_param->txbf;
2536 value = 0;
2537
2538 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
2539 return 0;
2540
2541 /* The following logic is correct. If a remote STA advertises support
2542 * for being a beamformer then we should enable us being a beamformee.
2543 */
2544
2545 if (ar->vht_cap_info &
2546 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2547 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
2548 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
2549 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2550
2551 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
2552 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
2553 }
2554
2555 if (ar->vht_cap_info &
2556 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2557 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
2558 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
2559 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2560
2561 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
2562 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
2563 }
2564
2565 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
2566 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2567
2568 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
2569 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2570
2571 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
2572 if (ret) {
2573 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
2574 value, ret);
2575 return ret;
2576 }
2577
2578 return 0;
2579}
2580
Kalle Valo5e3dd152013-06-12 20:52:10 +03002581/* can be called only in mac80211 callbacks due to `key_count` usage */
2582static void ath10k_bss_assoc(struct ieee80211_hw *hw,
2583 struct ieee80211_vif *vif,
2584 struct ieee80211_bss_conf *bss_conf)
2585{
2586 struct ath10k *ar = hw->priv;
2587 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior90046f52014-02-14 14:45:51 +01002588 struct ieee80211_sta_ht_cap ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02002589 struct ieee80211_sta_vht_cap vht_cap;
Kalle Valob9ada652013-10-16 15:44:46 +03002590 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002591 struct ieee80211_sta *ap_sta;
2592 int ret;
2593
Michal Kazior548db542013-07-05 16:15:15 +03002594 lockdep_assert_held(&ar->conf_mutex);
2595
Michal Kazior077efc82014-10-21 10:10:29 +03002596 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
2597 arvif->vdev_id, arvif->bssid, arvif->aid);
2598
Kalle Valo5e3dd152013-06-12 20:52:10 +03002599 rcu_read_lock();
2600
2601 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
2602 if (!ap_sta) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002603 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02002604 bss_conf->bssid, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002605 rcu_read_unlock();
2606 return;
2607 }
2608
Michal Kazior90046f52014-02-14 14:45:51 +01002609 /* ap_sta must be accessed only within rcu section which must be left
2610 * before calling ath10k_setup_peer_smps() which might sleep. */
2611 ht_cap = ap_sta->ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02002612 vht_cap = ap_sta->vht_cap;
Michal Kazior90046f52014-02-14 14:45:51 +01002613
Michal Kazior590922a2014-10-21 10:10:29 +03002614 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002615 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002616 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002617 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002618 rcu_read_unlock();
2619 return;
2620 }
2621
2622 rcu_read_unlock();
2623
Kalle Valob9ada652013-10-16 15:44:46 +03002624 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2625 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002626 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002627 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03002628 return;
2629 }
2630
Michal Kazior90046f52014-02-14 14:45:51 +01002631 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
2632 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002633 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002634 arvif->vdev_id, ret);
Michal Kazior90046f52014-02-14 14:45:51 +01002635 return;
2636 }
2637
Michal Kazior139e1702015-02-15 16:50:42 +02002638 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2639 if (ret) {
2640 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2641 arvif->vdev_id, bss_conf->bssid, ret);
2642 return;
2643 }
2644
Michal Kazior7aa7a722014-08-25 12:09:38 +02002645 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002646 "mac vdev %d up (associated) bssid %pM aid %d\n",
2647 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
2648
Michal Kazior077efc82014-10-21 10:10:29 +03002649 WARN_ON(arvif->is_up);
2650
Michal Kaziorc930f742014-01-23 11:38:25 +01002651 arvif->aid = bss_conf->aid;
Kalle Valob25f32c2014-09-14 12:50:49 +03002652 ether_addr_copy(arvif->bssid, bss_conf->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01002653
2654 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
2655 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002656 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002657 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01002658 return;
2659 }
2660
2661 arvif->is_up = true;
Michal Kazior0a987fb2015-02-13 13:30:15 +01002662
2663 /* Workaround: Some firmware revisions (tested with qca6174
2664 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2665 * poked with peer param command.
2666 */
2667 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
2668 WMI_PEER_DUMMY_VAR, 1);
2669 if (ret) {
2670 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2671 arvif->bssid, arvif->vdev_id, ret);
2672 return;
2673 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002674}
2675
Kalle Valo5e3dd152013-06-12 20:52:10 +03002676static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
2677 struct ieee80211_vif *vif)
2678{
2679 struct ath10k *ar = hw->priv;
2680 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior139e1702015-02-15 16:50:42 +02002681 struct ieee80211_sta_vht_cap vht_cap = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +03002682 int ret;
2683
Michal Kazior548db542013-07-05 16:15:15 +03002684 lockdep_assert_held(&ar->conf_mutex);
2685
Michal Kazior077efc82014-10-21 10:10:29 +03002686 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
2687 arvif->vdev_id, arvif->bssid);
Kalle Valo60c3daa2013-09-08 17:56:07 +03002688
Kalle Valo5e3dd152013-06-12 20:52:10 +03002689 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kazior077efc82014-10-21 10:10:29 +03002690 if (ret)
2691 ath10k_warn(ar, "faield to down vdev %i: %d\n",
2692 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002693
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02002694 arvif->def_wep_key_idx = -1;
2695
Michal Kazior139e1702015-02-15 16:50:42 +02002696 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2697 if (ret) {
2698 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
2699 arvif->vdev_id, ret);
2700 return;
2701 }
2702
Michal Kaziorc930f742014-01-23 11:38:25 +01002703 arvif->is_up = false;
Michal Kaziorcc9904e2015-03-10 16:22:01 +02002704
2705 cancel_delayed_work_sync(&arvif->connection_loss_work);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002706}
2707
Michal Kazior590922a2014-10-21 10:10:29 +03002708static int ath10k_station_assoc(struct ath10k *ar,
2709 struct ieee80211_vif *vif,
2710 struct ieee80211_sta *sta,
2711 bool reassoc)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002712{
Michal Kazior590922a2014-10-21 10:10:29 +03002713 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valob9ada652013-10-16 15:44:46 +03002714 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002715 int ret = 0;
2716
Michal Kazior548db542013-07-05 16:15:15 +03002717 lockdep_assert_held(&ar->conf_mutex);
2718
Michal Kazior590922a2014-10-21 10:10:29 +03002719 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002720 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002721 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02002722 sta->addr, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03002723 return ret;
2724 }
2725
2726 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2727 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002728 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002729 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002730 return ret;
2731 }
2732
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002733 /* Re-assoc is run only to update supported rates for given station. It
2734 * doesn't make much sense to reconfigure the peer completely.
2735 */
2736 if (!reassoc) {
2737 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
2738 &sta->ht_cap);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002739 if (ret) {
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002740 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002741 arvif->vdev_id, ret);
2742 return ret;
2743 }
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002744
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002745 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
2746 if (ret) {
2747 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
2748 sta->addr, arvif->vdev_id, ret);
2749 return ret;
2750 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002751
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002752 if (!sta->wme) {
2753 arvif->num_legacy_stations++;
2754 ret = ath10k_recalc_rtscts_prot(arvif);
2755 if (ret) {
2756 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2757 arvif->vdev_id, ret);
2758 return ret;
2759 }
2760 }
2761
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02002762 /* Plumb cached keys only for static WEP */
2763 if (arvif->def_wep_key_idx != -1) {
2764 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
2765 if (ret) {
2766 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
2767 arvif->vdev_id, ret);
2768 return ret;
2769 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002770 }
2771 }
2772
Kalle Valo5e3dd152013-06-12 20:52:10 +03002773 return ret;
2774}
2775
Michal Kazior590922a2014-10-21 10:10:29 +03002776static int ath10k_station_disassoc(struct ath10k *ar,
2777 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002778 struct ieee80211_sta *sta)
2779{
Michal Kazior590922a2014-10-21 10:10:29 +03002780 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002781 int ret = 0;
2782
2783 lockdep_assert_held(&ar->conf_mutex);
2784
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002785 if (!sta->wme) {
2786 arvif->num_legacy_stations--;
2787 ret = ath10k_recalc_rtscts_prot(arvif);
2788 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002789 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002790 arvif->vdev_id, ret);
2791 return ret;
2792 }
2793 }
2794
Kalle Valo5e3dd152013-06-12 20:52:10 +03002795 ret = ath10k_clear_peer_keys(arvif, sta->addr);
2796 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002797 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002798 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002799 return ret;
2800 }
2801
2802 return ret;
2803}
2804
2805/**************/
2806/* Regulatory */
2807/**************/
2808
2809static int ath10k_update_channel_list(struct ath10k *ar)
2810{
2811 struct ieee80211_hw *hw = ar->hw;
2812 struct ieee80211_supported_band **bands;
2813 enum ieee80211_band band;
2814 struct ieee80211_channel *channel;
2815 struct wmi_scan_chan_list_arg arg = {0};
2816 struct wmi_channel_arg *ch;
2817 bool passive;
2818 int len;
2819 int ret;
2820 int i;
2821
Michal Kazior548db542013-07-05 16:15:15 +03002822 lockdep_assert_held(&ar->conf_mutex);
2823
Kalle Valo5e3dd152013-06-12 20:52:10 +03002824 bands = hw->wiphy->bands;
2825 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2826 if (!bands[band])
2827 continue;
2828
2829 for (i = 0; i < bands[band]->n_channels; i++) {
2830 if (bands[band]->channels[i].flags &
2831 IEEE80211_CHAN_DISABLED)
2832 continue;
2833
2834 arg.n_channels++;
2835 }
2836 }
2837
2838 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
2839 arg.channels = kzalloc(len, GFP_KERNEL);
2840 if (!arg.channels)
2841 return -ENOMEM;
2842
2843 ch = arg.channels;
2844 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2845 if (!bands[band])
2846 continue;
2847
2848 for (i = 0; i < bands[band]->n_channels; i++) {
2849 channel = &bands[band]->channels[i];
2850
2851 if (channel->flags & IEEE80211_CHAN_DISABLED)
2852 continue;
2853
2854 ch->allow_ht = true;
2855
2856 /* FIXME: when should we really allow VHT? */
2857 ch->allow_vht = true;
2858
2859 ch->allow_ibss =
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002860 !(channel->flags & IEEE80211_CHAN_NO_IR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002861
2862 ch->ht40plus =
2863 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
2864
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002865 ch->chan_radar =
2866 !!(channel->flags & IEEE80211_CHAN_RADAR);
2867
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002868 passive = channel->flags & IEEE80211_CHAN_NO_IR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002869 ch->passive = passive;
2870
2871 ch->freq = channel->center_freq;
Michal Kazior2d667212014-09-18 15:21:21 +02002872 ch->band_center_freq1 = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07002873 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07002874 ch->max_power = channel->max_power * 2;
2875 ch->max_reg_power = channel->max_reg_power * 2;
2876 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002877 ch->reg_class_id = 0; /* FIXME */
2878
2879 /* FIXME: why use only legacy modes, why not any
2880 * HT/VHT modes? Would that even make any
2881 * difference? */
2882 if (channel->band == IEEE80211_BAND_2GHZ)
2883 ch->mode = MODE_11G;
2884 else
2885 ch->mode = MODE_11A;
2886
2887 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
2888 continue;
2889
Michal Kazior7aa7a722014-08-25 12:09:38 +02002890 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002891 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
2892 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002893 ch->freq, ch->max_power, ch->max_reg_power,
2894 ch->max_antenna_gain, ch->mode);
2895
2896 ch++;
2897 }
2898 }
2899
2900 ret = ath10k_wmi_scan_chan_list(ar, &arg);
2901 kfree(arg.channels);
2902
2903 return ret;
2904}
2905
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002906static enum wmi_dfs_region
2907ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
2908{
2909 switch (dfs_region) {
2910 case NL80211_DFS_UNSET:
2911 return WMI_UNINIT_DFS_DOMAIN;
2912 case NL80211_DFS_FCC:
2913 return WMI_FCC_DFS_DOMAIN;
2914 case NL80211_DFS_ETSI:
2915 return WMI_ETSI_DFS_DOMAIN;
2916 case NL80211_DFS_JP:
2917 return WMI_MKK4_DFS_DOMAIN;
2918 }
2919 return WMI_UNINIT_DFS_DOMAIN;
2920}
2921
Michal Kaziorf7843d72013-07-16 09:38:52 +02002922static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002923{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002924 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002925 int ret;
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002926 enum wmi_dfs_region wmi_dfs_reg;
2927 enum nl80211_dfs_regions nl_dfs_reg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002928
Michal Kaziorf7843d72013-07-16 09:38:52 +02002929 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002930
2931 ret = ath10k_update_channel_list(ar);
2932 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002933 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002934
2935 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002936
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002937 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
2938 nl_dfs_reg = ar->dfs_detector->region;
2939 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
2940 } else {
2941 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
2942 }
2943
Kalle Valo5e3dd152013-06-12 20:52:10 +03002944 /* Target allows setting up per-band regdomain but ath_common provides
2945 * a combined one only */
2946 ret = ath10k_wmi_pdev_set_regdomain(ar,
Kalle Valoef8c0012014-02-13 18:13:12 +02002947 regpair->reg_domain,
2948 regpair->reg_domain, /* 2ghz */
2949 regpair->reg_domain, /* 5ghz */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002950 regpair->reg_2ghz_ctl,
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002951 regpair->reg_5ghz_ctl,
2952 wmi_dfs_reg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002953 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002954 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02002955}
Michal Kazior548db542013-07-05 16:15:15 +03002956
Michal Kaziorf7843d72013-07-16 09:38:52 +02002957static void ath10k_reg_notifier(struct wiphy *wiphy,
2958 struct regulatory_request *request)
2959{
2960 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
2961 struct ath10k *ar = hw->priv;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002962 bool result;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002963
2964 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
2965
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002966 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002967 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002968 request->dfs_region);
2969 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
2970 request->dfs_region);
2971 if (!result)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002972 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002973 request->dfs_region);
2974 }
2975
Michal Kaziorf7843d72013-07-16 09:38:52 +02002976 mutex_lock(&ar->conf_mutex);
2977 if (ar->state == ATH10K_STATE_ON)
2978 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03002979 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002980}
2981
2982/***************/
2983/* TX handlers */
2984/***************/
2985
Michal Kazior96d828d2015-03-31 10:26:23 +00002986void ath10k_mac_tx_lock(struct ath10k *ar, int reason)
2987{
2988 lockdep_assert_held(&ar->htt.tx_lock);
2989
2990 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
2991 ar->tx_paused |= BIT(reason);
2992 ieee80211_stop_queues(ar->hw);
2993}
2994
2995static void ath10k_mac_tx_unlock_iter(void *data, u8 *mac,
2996 struct ieee80211_vif *vif)
2997{
2998 struct ath10k *ar = data;
2999 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3000
3001 if (arvif->tx_paused)
3002 return;
3003
3004 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3005}
3006
3007void ath10k_mac_tx_unlock(struct ath10k *ar, int reason)
3008{
3009 lockdep_assert_held(&ar->htt.tx_lock);
3010
3011 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
3012 ar->tx_paused &= ~BIT(reason);
3013
3014 if (ar->tx_paused)
3015 return;
3016
3017 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3018 IEEE80211_IFACE_ITER_RESUME_ALL,
3019 ath10k_mac_tx_unlock_iter,
3020 ar);
3021}
3022
3023void ath10k_mac_vif_tx_lock(struct ath10k_vif *arvif, int reason)
3024{
3025 struct ath10k *ar = arvif->ar;
3026
3027 lockdep_assert_held(&ar->htt.tx_lock);
3028
3029 WARN_ON(reason >= BITS_PER_LONG);
3030 arvif->tx_paused |= BIT(reason);
3031 ieee80211_stop_queue(ar->hw, arvif->vdev_id);
3032}
3033
3034void ath10k_mac_vif_tx_unlock(struct ath10k_vif *arvif, int reason)
3035{
3036 struct ath10k *ar = arvif->ar;
3037
3038 lockdep_assert_held(&ar->htt.tx_lock);
3039
3040 WARN_ON(reason >= BITS_PER_LONG);
3041 arvif->tx_paused &= ~BIT(reason);
3042
3043 if (ar->tx_paused)
3044 return;
3045
3046 if (arvif->tx_paused)
3047 return;
3048
3049 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3050}
3051
Michal Kaziorb4aa5392015-03-31 10:26:24 +00003052static void ath10k_mac_vif_handle_tx_pause(struct ath10k_vif *arvif,
3053 enum wmi_tlv_tx_pause_id pause_id,
3054 enum wmi_tlv_tx_pause_action action)
3055{
3056 struct ath10k *ar = arvif->ar;
3057
3058 lockdep_assert_held(&ar->htt.tx_lock);
3059
3060 switch (pause_id) {
3061 case WMI_TLV_TX_PAUSE_ID_MCC:
3062 case WMI_TLV_TX_PAUSE_ID_P2P_CLI_NOA:
3063 case WMI_TLV_TX_PAUSE_ID_P2P_GO_PS:
3064 case WMI_TLV_TX_PAUSE_ID_AP_PS:
3065 case WMI_TLV_TX_PAUSE_ID_IBSS_PS:
3066 switch (action) {
3067 case WMI_TLV_TX_PAUSE_ACTION_STOP:
3068 ath10k_mac_vif_tx_lock(arvif, pause_id);
3069 break;
3070 case WMI_TLV_TX_PAUSE_ACTION_WAKE:
3071 ath10k_mac_vif_tx_unlock(arvif, pause_id);
3072 break;
3073 default:
3074 ath10k_warn(ar, "received unknown tx pause action %d on vdev %i, ignoring\n",
3075 action, arvif->vdev_id);
3076 break;
3077 }
3078 break;
3079 case WMI_TLV_TX_PAUSE_ID_AP_PEER_PS:
3080 case WMI_TLV_TX_PAUSE_ID_AP_PEER_UAPSD:
3081 case WMI_TLV_TX_PAUSE_ID_STA_ADD_BA:
3082 case WMI_TLV_TX_PAUSE_ID_HOST:
3083 default:
3084 /* FIXME: Some pause_ids aren't vdev specific. Instead they
3085 * target peer_id and tid. Implementing these could improve
3086 * traffic scheduling fairness across multiple connected
3087 * stations in AP/IBSS modes.
3088 */
3089 ath10k_dbg(ar, ATH10K_DBG_MAC,
3090 "mac ignoring unsupported tx pause vdev %i id %d\n",
3091 arvif->vdev_id, pause_id);
3092 break;
3093 }
3094}
3095
3096struct ath10k_mac_tx_pause {
3097 u32 vdev_id;
3098 enum wmi_tlv_tx_pause_id pause_id;
3099 enum wmi_tlv_tx_pause_action action;
3100};
3101
3102static void ath10k_mac_handle_tx_pause_iter(void *data, u8 *mac,
3103 struct ieee80211_vif *vif)
3104{
3105 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3106 struct ath10k_mac_tx_pause *arg = data;
3107
3108 ath10k_mac_vif_handle_tx_pause(arvif, arg->pause_id, arg->action);
3109}
3110
3111void ath10k_mac_handle_tx_pause(struct ath10k *ar, u32 vdev_id,
3112 enum wmi_tlv_tx_pause_id pause_id,
3113 enum wmi_tlv_tx_pause_action action)
3114{
3115 struct ath10k_mac_tx_pause arg = {
3116 .vdev_id = vdev_id,
3117 .pause_id = pause_id,
3118 .action = action,
3119 };
3120
3121 spin_lock_bh(&ar->htt.tx_lock);
3122 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3123 IEEE80211_IFACE_ITER_RESUME_ALL,
3124 ath10k_mac_handle_tx_pause_iter,
3125 &arg);
3126 spin_unlock_bh(&ar->htt.tx_lock);
3127}
3128
Michal Kazior42c3aa62013-10-02 11:03:38 +02003129static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
3130{
3131 if (ieee80211_is_mgmt(hdr->frame_control))
3132 return HTT_DATA_TX_EXT_TID_MGMT;
3133
3134 if (!ieee80211_is_data_qos(hdr->frame_control))
3135 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
3136
3137 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
3138 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
3139
3140 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
3141}
3142
Michal Kazior2b37c292014-09-02 11:00:22 +03003143static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02003144{
Michal Kazior2b37c292014-09-02 11:00:22 +03003145 if (vif)
3146 return ath10k_vif_to_arvif(vif)->vdev_id;
Michal Kaziorddb6ad72013-10-02 11:03:39 +02003147
Michal Kazior1bbc0972014-04-08 09:45:47 +03003148 if (ar->monitor_started)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02003149 return ar->monitor_vdev_id;
3150
Michal Kazior7aa7a722014-08-25 12:09:38 +02003151 ath10k_warn(ar, "failed to resolve vdev id\n");
Michal Kaziorddb6ad72013-10-02 11:03:39 +02003152 return 0;
3153}
3154
Michal Kaziord740d8f2015-03-30 09:51:51 +03003155static enum ath10k_hw_txrx_mode
3156ath10k_tx_h_get_txmode(struct ath10k *ar, struct ieee80211_vif *vif,
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003157 struct ieee80211_sta *sta, struct sk_buff *skb)
Michal Kaziord740d8f2015-03-30 09:51:51 +03003158{
3159 const struct ieee80211_hdr *hdr = (void *)skb->data;
3160 __le16 fc = hdr->frame_control;
3161
3162 if (!vif || vif->type == NL80211_IFTYPE_MONITOR)
3163 return ATH10K_HW_TXRX_RAW;
3164
3165 if (ieee80211_is_mgmt(fc))
3166 return ATH10K_HW_TXRX_MGMT;
3167
3168 /* Workaround:
3169 *
3170 * NullFunc frames are mostly used to ping if a client or AP are still
3171 * reachable and responsive. This implies tx status reports must be
3172 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
3173 * come to a conclusion that the other end disappeared and tear down
3174 * BSS connection or it can never disconnect from BSS/client (which is
3175 * the case).
3176 *
3177 * Firmware with HTT older than 3.0 delivers incorrect tx status for
3178 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
3179 * which seems to deliver correct tx reports for NullFunc frames. The
3180 * downside of using it is it ignores client powersave state so it can
3181 * end up disconnecting sleeping clients in AP mode. It should fix STA
3182 * mode though because AP don't sleep.
3183 */
3184 if (ar->htt.target_version_major < 3 &&
3185 (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc)) &&
3186 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX, ar->fw_features))
3187 return ATH10K_HW_TXRX_MGMT;
3188
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003189 /* Workaround:
3190 *
3191 * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
3192 * NativeWifi txmode - it selects AP key instead of peer key. It seems
3193 * to work with Ethernet txmode so use it.
3194 */
3195 if (ieee80211_is_data_present(fc) && sta && sta->tdls)
3196 return ATH10K_HW_TXRX_ETHERNET;
3197
Michal Kaziord740d8f2015-03-30 09:51:51 +03003198 return ATH10K_HW_TXRX_NATIVE_WIFI;
3199}
3200
Michal Kazior4b604552014-07-21 21:03:09 +03003201/* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
3202 * Control in the header.
Kalle Valo5e3dd152013-06-12 20:52:10 +03003203 */
Michal Kazior4b604552014-07-21 21:03:09 +03003204static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003205{
3206 struct ieee80211_hdr *hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03003207 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003208 u8 *qos_ctl;
3209
3210 if (!ieee80211_is_data_qos(hdr->frame_control))
3211 return;
3212
3213 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02003214 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
3215 skb->data, (void *)qos_ctl - (void *)skb->data);
3216 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Michal Kaziorc21c64d2014-07-21 21:03:10 +03003217
Michal Kazior8bad8dc2015-03-11 14:25:26 +01003218 /* Some firmware revisions don't handle sending QoS NullFunc well.
3219 * These frames are mainly used for CQM purposes so it doesn't really
3220 * matter whether QoS NullFunc or NullFunc are sent.
Michal Kaziorc21c64d2014-07-21 21:03:10 +03003221 */
Michal Kaziorbf0a26d2015-01-24 12:14:51 +02003222 hdr = (void *)skb->data;
Michal Kazior8bad8dc2015-03-11 14:25:26 +01003223 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
Michal Kaziorc21c64d2014-07-21 21:03:10 +03003224 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
Michal Kazior8bad8dc2015-03-11 14:25:26 +01003225
3226 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003227}
3228
Michal Kaziord740d8f2015-03-30 09:51:51 +03003229static void ath10k_tx_h_8023(struct sk_buff *skb)
3230{
3231 struct ieee80211_hdr *hdr;
3232 struct rfc1042_hdr *rfc1042;
3233 struct ethhdr *eth;
3234 size_t hdrlen;
3235 u8 da[ETH_ALEN];
3236 u8 sa[ETH_ALEN];
3237 __be16 type;
3238
3239 hdr = (void *)skb->data;
3240 hdrlen = ieee80211_hdrlen(hdr->frame_control);
3241 rfc1042 = (void *)skb->data + hdrlen;
3242
3243 ether_addr_copy(da, ieee80211_get_DA(hdr));
3244 ether_addr_copy(sa, ieee80211_get_SA(hdr));
3245 type = rfc1042->snap_type;
3246
3247 skb_pull(skb, hdrlen + sizeof(*rfc1042));
3248 skb_push(skb, sizeof(*eth));
3249
3250 eth = (void *)skb->data;
3251 ether_addr_copy(eth->h_dest, da);
3252 ether_addr_copy(eth->h_source, sa);
3253 eth->h_proto = type;
3254}
3255
Michal Kazior4b604552014-07-21 21:03:09 +03003256static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
3257 struct ieee80211_vif *vif,
3258 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003259{
3260 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003261 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3262
3263 /* This is case only for P2P_GO */
3264 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
3265 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
3266 return;
3267
3268 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
3269 spin_lock_bh(&ar->data_lock);
3270 if (arvif->u.ap.noa_data)
3271 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
3272 GFP_ATOMIC))
3273 memcpy(skb_put(skb, arvif->u.ap.noa_len),
3274 arvif->u.ap.noa_data,
3275 arvif->u.ap.noa_len);
3276 spin_unlock_bh(&ar->data_lock);
3277 }
3278}
3279
Michal Kazior8d6d3622014-11-24 14:58:31 +01003280static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar)
3281{
3282 /* FIXME: Not really sure since when the behaviour changed. At some
3283 * point new firmware stopped requiring creation of peer entries for
3284 * offchannel tx (and actually creating them causes issues with wmi-htc
3285 * tx credit replenishment and reliability). Assuming it's at least 3.4
3286 * because that's when the `freq` was introduced to TX_FRM HTT command.
3287 */
3288 return !(ar->htt.target_version_major >= 3 &&
3289 ar->htt.target_version_minor >= 4);
3290}
3291
Michal Kaziord740d8f2015-03-30 09:51:51 +03003292static int ath10k_mac_tx_wmi_mgmt(struct ath10k *ar, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003293{
Michal Kaziord740d8f2015-03-30 09:51:51 +03003294 struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003295 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003296
Michal Kaziord740d8f2015-03-30 09:51:51 +03003297 spin_lock_bh(&ar->data_lock);
3298
3299 if (skb_queue_len(q) == ATH10K_MAX_NUM_MGMT_PENDING) {
3300 ath10k_warn(ar, "wmi mgmt tx queue is full\n");
3301 ret = -ENOSPC;
3302 goto unlock;
Michal Kazior961d4c32013-08-09 10:13:34 +02003303 }
3304
Michal Kaziord740d8f2015-03-30 09:51:51 +03003305 __skb_queue_tail(q, skb);
3306 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
3307
3308unlock:
3309 spin_unlock_bh(&ar->data_lock);
3310
3311 return ret;
3312}
3313
3314static void ath10k_mac_tx(struct ath10k *ar, struct sk_buff *skb)
3315{
3316 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3317 struct ath10k_htt *htt = &ar->htt;
3318 int ret = 0;
3319
3320 switch (cb->txmode) {
3321 case ATH10K_HW_TXRX_RAW:
3322 case ATH10K_HW_TXRX_NATIVE_WIFI:
3323 case ATH10K_HW_TXRX_ETHERNET:
3324 ret = ath10k_htt_tx(htt, skb);
3325 break;
3326 case ATH10K_HW_TXRX_MGMT:
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003327 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
Michal Kaziord740d8f2015-03-30 09:51:51 +03003328 ar->fw_features))
3329 ret = ath10k_mac_tx_wmi_mgmt(ar, skb);
3330 else if (ar->htt.target_version_major >= 3)
3331 ret = ath10k_htt_tx(htt, skb);
3332 else
3333 ret = ath10k_htt_mgmt_tx(htt, skb);
3334 break;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003335 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003336
3337 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003338 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
3339 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003340 ieee80211_free_txskb(ar->hw, skb);
3341 }
3342}
3343
3344void ath10k_offchan_tx_purge(struct ath10k *ar)
3345{
3346 struct sk_buff *skb;
3347
3348 for (;;) {
3349 skb = skb_dequeue(&ar->offchan_tx_queue);
3350 if (!skb)
3351 break;
3352
3353 ieee80211_free_txskb(ar->hw, skb);
3354 }
3355}
3356
3357void ath10k_offchan_tx_work(struct work_struct *work)
3358{
3359 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
3360 struct ath10k_peer *peer;
3361 struct ieee80211_hdr *hdr;
3362 struct sk_buff *skb;
3363 const u8 *peer_addr;
3364 int vdev_id;
3365 int ret;
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +03003366 unsigned long time_left;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003367
3368 /* FW requirement: We must create a peer before FW will send out
3369 * an offchannel frame. Otherwise the frame will be stuck and
3370 * never transmitted. We delete the peer upon tx completion.
3371 * It is unlikely that a peer for offchannel tx will already be
3372 * present. However it may be in some rare cases so account for that.
3373 * Otherwise we might remove a legitimate peer and break stuff. */
3374
3375 for (;;) {
3376 skb = skb_dequeue(&ar->offchan_tx_queue);
3377 if (!skb)
3378 break;
3379
3380 mutex_lock(&ar->conf_mutex);
3381
Michal Kazior7aa7a722014-08-25 12:09:38 +02003382 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003383 skb);
3384
3385 hdr = (struct ieee80211_hdr *)skb->data;
3386 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003387 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003388
3389 spin_lock_bh(&ar->data_lock);
3390 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
3391 spin_unlock_bh(&ar->data_lock);
3392
3393 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03003394 /* FIXME: should this use ath10k_warn()? */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003395 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003396 peer_addr, vdev_id);
3397
3398 if (!peer) {
Marek Puzyniak7390ed32015-03-30 09:51:52 +03003399 ret = ath10k_peer_create(ar, vdev_id, peer_addr,
3400 WMI_PEER_TYPE_DEFAULT);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003401 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003402 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003403 peer_addr, vdev_id, ret);
3404 }
3405
3406 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08003407 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003408 ar->offchan_tx_skb = skb;
3409 spin_unlock_bh(&ar->data_lock);
3410
Michal Kaziord740d8f2015-03-30 09:51:51 +03003411 ath10k_mac_tx(ar, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003412
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +03003413 time_left =
3414 wait_for_completion_timeout(&ar->offchan_tx_completed, 3 * HZ);
3415 if (time_left == 0)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003416 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003417 skb);
3418
3419 if (!peer) {
3420 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
3421 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003422 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003423 peer_addr, vdev_id, ret);
3424 }
3425
3426 mutex_unlock(&ar->conf_mutex);
3427 }
3428}
3429
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003430void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
3431{
3432 struct sk_buff *skb;
3433
3434 for (;;) {
3435 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3436 if (!skb)
3437 break;
3438
3439 ieee80211_free_txskb(ar->hw, skb);
3440 }
3441}
3442
3443void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
3444{
3445 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
3446 struct sk_buff *skb;
3447 int ret;
3448
3449 for (;;) {
3450 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3451 if (!skb)
3452 break;
3453
3454 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01003455 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003456 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02003457 ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01003458 ieee80211_free_txskb(ar->hw, skb);
3459 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003460 }
3461}
3462
Kalle Valo5e3dd152013-06-12 20:52:10 +03003463/************/
3464/* Scanning */
3465/************/
3466
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003467void __ath10k_scan_finish(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003468{
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003469 lockdep_assert_held(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003470
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003471 switch (ar->scan.state) {
3472 case ATH10K_SCAN_IDLE:
3473 break;
3474 case ATH10K_SCAN_RUNNING:
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003475 if (ar->scan.is_roc)
3476 ieee80211_remain_on_channel_expired(ar->hw);
John W. Linvillef6eaf1e2015-01-12 16:07:02 -05003477 /* fall through */
Michal Kazior7305d3e2014-11-24 14:58:33 +01003478 case ATH10K_SCAN_ABORTING:
3479 if (!ar->scan.is_roc)
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003480 ieee80211_scan_completed(ar->hw,
3481 (ar->scan.state ==
3482 ATH10K_SCAN_ABORTING));
3483 /* fall through */
3484 case ATH10K_SCAN_STARTING:
3485 ar->scan.state = ATH10K_SCAN_IDLE;
3486 ar->scan_channel = NULL;
3487 ath10k_offchan_tx_purge(ar);
3488 cancel_delayed_work(&ar->scan.timeout);
3489 complete_all(&ar->scan.completed);
3490 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003491 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003492}
Kalle Valo5e3dd152013-06-12 20:52:10 +03003493
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003494void ath10k_scan_finish(struct ath10k *ar)
3495{
3496 spin_lock_bh(&ar->data_lock);
3497 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003498 spin_unlock_bh(&ar->data_lock);
3499}
3500
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003501static int ath10k_scan_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003502{
3503 struct wmi_stop_scan_arg arg = {
3504 .req_id = 1, /* FIXME */
3505 .req_type = WMI_SCAN_STOP_ONE,
3506 .u.scan_id = ATH10K_SCAN_ID,
3507 };
3508 int ret;
3509
3510 lockdep_assert_held(&ar->conf_mutex);
3511
Kalle Valo5e3dd152013-06-12 20:52:10 +03003512 ret = ath10k_wmi_stop_scan(ar, &arg);
3513 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003514 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003515 goto out;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003516 }
3517
Kalle Valo5e3dd152013-06-12 20:52:10 +03003518 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003519 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003520 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003521 ret = -ETIMEDOUT;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003522 } else if (ret > 0) {
3523 ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003524 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003525
3526out:
3527 /* Scan state should be updated upon scan completion but in case
3528 * firmware fails to deliver the event (for whatever reason) it is
3529 * desired to clean up scan state anyway. Firmware may have just
3530 * dropped the scan completion event delivery due to transport pipe
3531 * being overflown with data and/or it can recover on its own before
3532 * next scan request is submitted.
3533 */
3534 spin_lock_bh(&ar->data_lock);
3535 if (ar->scan.state != ATH10K_SCAN_IDLE)
3536 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003537 spin_unlock_bh(&ar->data_lock);
3538
3539 return ret;
3540}
3541
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003542static void ath10k_scan_abort(struct ath10k *ar)
3543{
3544 int ret;
3545
3546 lockdep_assert_held(&ar->conf_mutex);
3547
3548 spin_lock_bh(&ar->data_lock);
3549
3550 switch (ar->scan.state) {
3551 case ATH10K_SCAN_IDLE:
3552 /* This can happen if timeout worker kicked in and called
3553 * abortion while scan completion was being processed.
3554 */
3555 break;
3556 case ATH10K_SCAN_STARTING:
3557 case ATH10K_SCAN_ABORTING:
Michal Kazior7aa7a722014-08-25 12:09:38 +02003558 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003559 ath10k_scan_state_str(ar->scan.state),
3560 ar->scan.state);
3561 break;
3562 case ATH10K_SCAN_RUNNING:
3563 ar->scan.state = ATH10K_SCAN_ABORTING;
3564 spin_unlock_bh(&ar->data_lock);
3565
3566 ret = ath10k_scan_stop(ar);
3567 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003568 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003569
3570 spin_lock_bh(&ar->data_lock);
3571 break;
3572 }
3573
3574 spin_unlock_bh(&ar->data_lock);
3575}
3576
3577void ath10k_scan_timeout_work(struct work_struct *work)
3578{
3579 struct ath10k *ar = container_of(work, struct ath10k,
3580 scan.timeout.work);
3581
3582 mutex_lock(&ar->conf_mutex);
3583 ath10k_scan_abort(ar);
3584 mutex_unlock(&ar->conf_mutex);
3585}
3586
Kalle Valo5e3dd152013-06-12 20:52:10 +03003587static int ath10k_start_scan(struct ath10k *ar,
3588 const struct wmi_start_scan_arg *arg)
3589{
3590 int ret;
3591
3592 lockdep_assert_held(&ar->conf_mutex);
3593
3594 ret = ath10k_wmi_start_scan(ar, arg);
3595 if (ret)
3596 return ret;
3597
Kalle Valo5e3dd152013-06-12 20:52:10 +03003598 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
3599 if (ret == 0) {
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003600 ret = ath10k_scan_stop(ar);
3601 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003602 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003603
3604 return -ETIMEDOUT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003605 }
3606
Ben Greear2f9eec02015-02-15 16:50:38 +02003607 /* If we failed to start the scan, return error code at
3608 * this point. This is probably due to some issue in the
3609 * firmware, but no need to wedge the driver due to that...
3610 */
3611 spin_lock_bh(&ar->data_lock);
3612 if (ar->scan.state == ATH10K_SCAN_IDLE) {
3613 spin_unlock_bh(&ar->data_lock);
3614 return -EINVAL;
3615 }
3616 spin_unlock_bh(&ar->data_lock);
3617
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003618 /* Add a 200ms margin to account for event/command processing */
3619 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
3620 msecs_to_jiffies(arg->max_scan_time+200));
Kalle Valo5e3dd152013-06-12 20:52:10 +03003621 return 0;
3622}
3623
3624/**********************/
3625/* mac80211 callbacks */
3626/**********************/
3627
3628static void ath10k_tx(struct ieee80211_hw *hw,
3629 struct ieee80211_tx_control *control,
3630 struct sk_buff *skb)
3631{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003632 struct ath10k *ar = hw->priv;
Michal Kazior4b604552014-07-21 21:03:09 +03003633 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3634 struct ieee80211_vif *vif = info->control.vif;
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003635 struct ieee80211_sta *sta = control->sta;
Michal Kazior4b604552014-07-21 21:03:09 +03003636 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Michal Kaziord740d8f2015-03-30 09:51:51 +03003637 __le16 fc = hdr->frame_control;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003638
3639 /* We should disable CCK RATE due to P2P */
3640 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003641 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003642
Michal Kazior4b604552014-07-21 21:03:09 +03003643 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
Michal Kazior6fcafef2015-03-30 09:51:51 +03003644 ATH10K_SKB_CB(skb)->htt.freq = 0;
Michal Kazior4b604552014-07-21 21:03:09 +03003645 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
Michal Kazior2b37c292014-09-02 11:00:22 +03003646 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003647 ATH10K_SKB_CB(skb)->txmode = ath10k_tx_h_get_txmode(ar, vif, sta, skb);
Michal Kaziord740d8f2015-03-30 09:51:51 +03003648 ATH10K_SKB_CB(skb)->is_protected = ieee80211_has_protected(fc);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003649
Michal Kaziord740d8f2015-03-30 09:51:51 +03003650 switch (ATH10K_SKB_CB(skb)->txmode) {
3651 case ATH10K_HW_TXRX_MGMT:
3652 case ATH10K_HW_TXRX_NATIVE_WIFI:
Michal Kazior4b604552014-07-21 21:03:09 +03003653 ath10k_tx_h_nwifi(hw, skb);
Michal Kazior4b604552014-07-21 21:03:09 +03003654 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
3655 ath10k_tx_h_seq_no(vif, skb);
Michal Kaziord740d8f2015-03-30 09:51:51 +03003656 break;
3657 case ATH10K_HW_TXRX_ETHERNET:
3658 ath10k_tx_h_8023(skb);
3659 break;
3660 case ATH10K_HW_TXRX_RAW:
3661 /* FIXME: Packet injection isn't implemented. It should be
3662 * doable with firmware 10.2 on qca988x.
3663 */
3664 WARN_ON_ONCE(1);
3665 ieee80211_free_txskb(hw, skb);
3666 return;
Michal Kaziorcf84bd42013-07-16 11:04:54 +02003667 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003668
Kalle Valo5e3dd152013-06-12 20:52:10 +03003669 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
3670 spin_lock_bh(&ar->data_lock);
Michal Kazior8d6d3622014-11-24 14:58:31 +01003671 ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003672 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003673 spin_unlock_bh(&ar->data_lock);
3674
Michal Kazior8d6d3622014-11-24 14:58:31 +01003675 if (ath10k_mac_need_offchan_tx_work(ar)) {
3676 ATH10K_SKB_CB(skb)->htt.freq = 0;
3677 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003678
Michal Kazior8d6d3622014-11-24 14:58:31 +01003679 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
3680 skb);
3681
3682 skb_queue_tail(&ar->offchan_tx_queue, skb);
3683 ieee80211_queue_work(hw, &ar->offchan_tx_work);
3684 return;
3685 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003686 }
3687
Michal Kaziord740d8f2015-03-30 09:51:51 +03003688 ath10k_mac_tx(ar, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003689}
3690
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003691/* Must not be called with conf_mutex held as workers can use that also. */
Michal Kazior7962b0d2014-10-28 10:34:38 +01003692void ath10k_drain_tx(struct ath10k *ar)
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003693{
3694 /* make sure rcu-protected mac80211 tx path itself is drained */
3695 synchronize_net();
3696
3697 ath10k_offchan_tx_purge(ar);
3698 ath10k_mgmt_over_wmi_tx_purge(ar);
3699
3700 cancel_work_sync(&ar->offchan_tx_work);
3701 cancel_work_sync(&ar->wmi_mgmt_tx_work);
3702}
3703
Michal Kazioraffd3212013-07-16 09:54:35 +02003704void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02003705{
Michal Kaziord9bc4b92014-04-23 19:30:06 +03003706 struct ath10k_vif *arvif;
3707
Michal Kazior818bdd12013-07-16 09:38:57 +02003708 lockdep_assert_held(&ar->conf_mutex);
3709
Michal Kazior19337472014-08-28 12:58:16 +02003710 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
3711 ar->filter_flags = 0;
3712 ar->monitor = false;
Michal Kazior500ff9f2015-03-31 10:26:21 +00003713 ar->monitor_arvif = NULL;
Michal Kazior19337472014-08-28 12:58:16 +02003714
3715 if (ar->monitor_started)
Michal Kazior1bbc0972014-04-08 09:45:47 +03003716 ath10k_monitor_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +02003717
3718 ar->monitor_started = false;
Michal Kazior96d828d2015-03-31 10:26:23 +00003719 ar->tx_paused = 0;
Michal Kazior1bbc0972014-04-08 09:45:47 +03003720
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003721 ath10k_scan_finish(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02003722 ath10k_peer_cleanup_all(ar);
3723 ath10k_core_stop(ar);
3724 ath10k_hif_power_down(ar);
3725
3726 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03003727 list_for_each_entry(arvif, &ar->arvifs, list)
3728 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kazior818bdd12013-07-16 09:38:57 +02003729 spin_unlock_bh(&ar->data_lock);
3730}
3731
Ben Greear46acf7b2014-05-16 17:15:38 +03003732static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
3733{
3734 struct ath10k *ar = hw->priv;
3735
3736 mutex_lock(&ar->conf_mutex);
3737
3738 if (ar->cfg_tx_chainmask) {
3739 *tx_ant = ar->cfg_tx_chainmask;
3740 *rx_ant = ar->cfg_rx_chainmask;
3741 } else {
3742 *tx_ant = ar->supp_tx_chainmask;
3743 *rx_ant = ar->supp_rx_chainmask;
3744 }
3745
3746 mutex_unlock(&ar->conf_mutex);
3747
3748 return 0;
3749}
3750
Ben Greear5572a952014-11-24 16:22:10 +02003751static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
3752{
3753 /* It is not clear that allowing gaps in chainmask
3754 * is helpful. Probably it will not do what user
3755 * is hoping for, so warn in that case.
3756 */
3757 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
3758 return;
3759
3760 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
3761 dbg, cm);
3762}
3763
Ben Greear46acf7b2014-05-16 17:15:38 +03003764static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
3765{
3766 int ret;
3767
3768 lockdep_assert_held(&ar->conf_mutex);
3769
Ben Greear5572a952014-11-24 16:22:10 +02003770 ath10k_check_chain_mask(ar, tx_ant, "tx");
3771 ath10k_check_chain_mask(ar, rx_ant, "rx");
3772
Ben Greear46acf7b2014-05-16 17:15:38 +03003773 ar->cfg_tx_chainmask = tx_ant;
3774 ar->cfg_rx_chainmask = rx_ant;
3775
3776 if ((ar->state != ATH10K_STATE_ON) &&
3777 (ar->state != ATH10K_STATE_RESTARTED))
3778 return 0;
3779
3780 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
3781 tx_ant);
3782 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003783 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03003784 ret, tx_ant);
3785 return ret;
3786 }
3787
3788 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
3789 rx_ant);
3790 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003791 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03003792 ret, rx_ant);
3793 return ret;
3794 }
3795
3796 return 0;
3797}
3798
3799static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
3800{
3801 struct ath10k *ar = hw->priv;
3802 int ret;
3803
3804 mutex_lock(&ar->conf_mutex);
3805 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
3806 mutex_unlock(&ar->conf_mutex);
3807 return ret;
3808}
3809
Kalle Valo5e3dd152013-06-12 20:52:10 +03003810static int ath10k_start(struct ieee80211_hw *hw)
3811{
3812 struct ath10k *ar = hw->priv;
Janusz Dziedzic24ab13e2015-04-01 22:53:18 +03003813 u32 burst_enable;
Michal Kazior818bdd12013-07-16 09:38:57 +02003814 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003815
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003816 /*
3817 * This makes sense only when restarting hw. It is harmless to call
3818 * uncoditionally. This is necessary to make sure no HTT/WMI tx
3819 * commands will be submitted while restarting.
3820 */
3821 ath10k_drain_tx(ar);
3822
Michal Kazior548db542013-07-05 16:15:15 +03003823 mutex_lock(&ar->conf_mutex);
3824
Michal Kaziorc5058f52014-05-26 12:46:03 +03003825 switch (ar->state) {
3826 case ATH10K_STATE_OFF:
3827 ar->state = ATH10K_STATE_ON;
3828 break;
3829 case ATH10K_STATE_RESTARTING:
3830 ath10k_halt(ar);
3831 ar->state = ATH10K_STATE_RESTARTED;
3832 break;
3833 case ATH10K_STATE_ON:
3834 case ATH10K_STATE_RESTARTED:
3835 case ATH10K_STATE_WEDGED:
3836 WARN_ON(1);
Michal Kazior818bdd12013-07-16 09:38:57 +02003837 ret = -EINVAL;
Michal Kaziorae254432014-05-26 12:46:02 +03003838 goto err;
Kalle Valo43d2a302014-09-10 18:23:30 +03003839 case ATH10K_STATE_UTF:
3840 ret = -EBUSY;
3841 goto err;
Michal Kazior818bdd12013-07-16 09:38:57 +02003842 }
3843
3844 ret = ath10k_hif_power_up(ar);
3845 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003846 ath10k_err(ar, "Could not init hif: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003847 goto err_off;
Michal Kazior818bdd12013-07-16 09:38:57 +02003848 }
3849
Kalle Valo43d2a302014-09-10 18:23:30 +03003850 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
Michal Kazior818bdd12013-07-16 09:38:57 +02003851 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003852 ath10k_err(ar, "Could not init core: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003853 goto err_power_down;
Michal Kazior818bdd12013-07-16 09:38:57 +02003854 }
3855
Bartosz Markowski226a3392013-09-26 17:47:16 +02003856 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03003857 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003858 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003859 goto err_core_stop;
3860 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003861
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01003862 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03003863 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003864 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003865 goto err_core_stop;
3866 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003867
Michal Kaziorcf327842015-03-31 10:26:25 +00003868 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
3869 ret = ath10k_wmi_adaptive_qcs(ar, true);
3870 if (ret) {
3871 ath10k_warn(ar, "failed to enable adaptive qcs: %d\n",
3872 ret);
3873 goto err_core_stop;
3874 }
3875 }
3876
Janusz Dziedzic24ab13e2015-04-01 22:53:18 +03003877 if (test_bit(WMI_SERVICE_BURST, ar->wmi.svc_map)) {
3878 burst_enable = ar->wmi.pdev_param->burst_enable;
3879 ret = ath10k_wmi_pdev_set_param(ar, burst_enable, 0);
3880 if (ret) {
3881 ath10k_warn(ar, "failed to disable burst: %d\n", ret);
3882 goto err_core_stop;
3883 }
3884 }
3885
Ben Greear46acf7b2014-05-16 17:15:38 +03003886 if (ar->cfg_tx_chainmask)
3887 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
3888 ar->cfg_rx_chainmask);
3889
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003890 /*
3891 * By default FW set ARP frames ac to voice (6). In that case ARP
3892 * exchange is not working properly for UAPSD enabled AP. ARP requests
3893 * which arrives with access category 0 are processed by network stack
3894 * and send back with access category 0, but FW changes access category
3895 * to 6. Set ARP frames access category to best effort (0) solves
3896 * this problem.
3897 */
3898
3899 ret = ath10k_wmi_pdev_set_param(ar,
3900 ar->wmi.pdev_param->arp_ac_override, 0);
3901 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003902 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003903 ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003904 goto err_core_stop;
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003905 }
3906
Ashok Raj Nagarajan575f1c32015-03-19 16:37:59 +05303907 ret = ath10k_wmi_pdev_set_param(ar,
3908 ar->wmi.pdev_param->ani_enable, 1);
3909 if (ret) {
3910 ath10k_warn(ar, "failed to enable ani by default: %d\n",
3911 ret);
3912 goto err_core_stop;
3913 }
3914
Ashok Raj Nagarajanb3e71d72015-03-19 16:38:00 +05303915 ar->ani_enabled = true;
3916
Michal Kaziord6500972014-04-08 09:56:09 +03003917 ar->num_started_vdevs = 0;
Michal Kaziorf7843d72013-07-16 09:38:52 +02003918 ath10k_regd_update(ar);
3919
Simon Wunderlich855aed12014-08-02 09:12:54 +03003920 ath10k_spectral_start(ar);
Rajkumar Manoharan8515b5c2015-03-15 20:36:22 +05303921 ath10k_thermal_set_throttling(ar);
Simon Wunderlich855aed12014-08-02 09:12:54 +03003922
Michal Kaziorae254432014-05-26 12:46:02 +03003923 mutex_unlock(&ar->conf_mutex);
3924 return 0;
3925
3926err_core_stop:
3927 ath10k_core_stop(ar);
3928
3929err_power_down:
3930 ath10k_hif_power_down(ar);
3931
3932err_off:
3933 ar->state = ATH10K_STATE_OFF;
3934
3935err:
Michal Kazior548db542013-07-05 16:15:15 +03003936 mutex_unlock(&ar->conf_mutex);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01003937 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003938}
3939
3940static void ath10k_stop(struct ieee80211_hw *hw)
3941{
3942 struct ath10k *ar = hw->priv;
3943
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003944 ath10k_drain_tx(ar);
3945
Michal Kazior548db542013-07-05 16:15:15 +03003946 mutex_lock(&ar->conf_mutex);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003947 if (ar->state != ATH10K_STATE_OFF) {
Michal Kazior818bdd12013-07-16 09:38:57 +02003948 ath10k_halt(ar);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003949 ar->state = ATH10K_STATE_OFF;
3950 }
Michal Kazior548db542013-07-05 16:15:15 +03003951 mutex_unlock(&ar->conf_mutex);
3952
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003953 cancel_delayed_work_sync(&ar->scan.timeout);
Michal Kazioraffd3212013-07-16 09:54:35 +02003954 cancel_work_sync(&ar->restart_work);
3955}
3956
Michal Kaziorad088bf2013-10-16 15:44:46 +03003957static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02003958{
Michal Kaziorad088bf2013-10-16 15:44:46 +03003959 struct ath10k_vif *arvif;
3960 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02003961
3962 lockdep_assert_held(&ar->conf_mutex);
3963
Michal Kaziorad088bf2013-10-16 15:44:46 +03003964 list_for_each_entry(arvif, &ar->arvifs, list) {
3965 ret = ath10k_mac_vif_setup_ps(arvif);
3966 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003967 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03003968 break;
3969 }
3970 }
Michal Kazioraffd3212013-07-16 09:54:35 +02003971
Michal Kaziorad088bf2013-10-16 15:44:46 +03003972 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003973}
3974
Michal Kazior500ff9f2015-03-31 10:26:21 +00003975static void ath10k_mac_chan_reconfigure(struct ath10k *ar)
Michal Kaziorc930f742014-01-23 11:38:25 +01003976{
3977 struct ath10k_vif *arvif;
Michal Kazior500ff9f2015-03-31 10:26:21 +00003978 struct cfg80211_chan_def def;
Michal Kaziorc930f742014-01-23 11:38:25 +01003979 int ret;
3980
3981 lockdep_assert_held(&ar->conf_mutex);
3982
Michal Kazior500ff9f2015-03-31 10:26:21 +00003983 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac chan reconfigure\n");
Michal Kaziorc930f742014-01-23 11:38:25 +01003984
3985 /* First stop monitor interface. Some FW versions crash if there's a
3986 * lone monitor interface. */
Michal Kazior1bbc0972014-04-08 09:45:47 +03003987 if (ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02003988 ath10k_monitor_stop(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003989
3990 list_for_each_entry(arvif, &ar->arvifs, list) {
3991 if (!arvif->is_started)
3992 continue;
3993
Michal Kaziordc55e302014-07-29 12:53:36 +03003994 if (!arvif->is_up)
3995 continue;
3996
Michal Kaziorc930f742014-01-23 11:38:25 +01003997 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3998 continue;
3999
Michal Kaziordc55e302014-07-29 12:53:36 +03004000 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kaziorc930f742014-01-23 11:38:25 +01004001 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004002 ath10k_warn(ar, "failed to down vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01004003 arvif->vdev_id, ret);
4004 continue;
4005 }
4006 }
4007
Michal Kaziordc55e302014-07-29 12:53:36 +03004008 /* all vdevs are downed now - attempt to restart and re-up them */
Michal Kaziorc930f742014-01-23 11:38:25 +01004009
4010 list_for_each_entry(arvif, &ar->arvifs, list) {
4011 if (!arvif->is_started)
4012 continue;
4013
4014 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
4015 continue;
4016
Michal Kazior81a9a172015-03-05 16:02:17 +02004017 ret = ath10k_mac_setup_bcn_tmpl(arvif);
4018 if (ret)
4019 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
4020 ret);
4021
4022 ret = ath10k_mac_setup_prb_tmpl(arvif);
4023 if (ret)
4024 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
4025 ret);
4026
Michal Kazior500ff9f2015-03-31 10:26:21 +00004027 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
4028 continue;
4029
4030 ret = ath10k_vdev_restart(arvif, &def);
Michal Kaziorc930f742014-01-23 11:38:25 +01004031 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004032 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01004033 arvif->vdev_id, ret);
4034 continue;
4035 }
4036
4037 if (!arvif->is_up)
4038 continue;
4039
4040 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
4041 arvif->bssid);
4042 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004043 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01004044 arvif->vdev_id, ret);
4045 continue;
4046 }
4047 }
4048
Michal Kazior19337472014-08-28 12:58:16 +02004049 ath10k_monitor_recalc(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01004050}
4051
Michal Kazior7d9d5582014-10-21 10:40:15 +03004052static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
4053{
4054 int ret;
4055 u32 param;
4056
4057 lockdep_assert_held(&ar->conf_mutex);
4058
4059 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
4060
4061 param = ar->wmi.pdev_param->txpower_limit2g;
4062 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
4063 if (ret) {
4064 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
4065 txpower, ret);
4066 return ret;
4067 }
4068
4069 param = ar->wmi.pdev_param->txpower_limit5g;
4070 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
4071 if (ret) {
4072 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
4073 txpower, ret);
4074 return ret;
4075 }
4076
4077 return 0;
4078}
4079
4080static int ath10k_mac_txpower_recalc(struct ath10k *ar)
4081{
4082 struct ath10k_vif *arvif;
4083 int ret, txpower = -1;
4084
4085 lockdep_assert_held(&ar->conf_mutex);
4086
4087 list_for_each_entry(arvif, &ar->arvifs, list) {
4088 WARN_ON(arvif->txpower < 0);
4089
4090 if (txpower == -1)
4091 txpower = arvif->txpower;
4092 else
4093 txpower = min(txpower, arvif->txpower);
4094 }
4095
4096 if (WARN_ON(txpower == -1))
4097 return -EINVAL;
4098
4099 ret = ath10k_mac_txpower_setup(ar, txpower);
4100 if (ret) {
4101 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
4102 txpower, ret);
4103 return ret;
4104 }
4105
4106 return 0;
4107}
4108
Kalle Valo5e3dd152013-06-12 20:52:10 +03004109static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
4110{
Kalle Valo5e3dd152013-06-12 20:52:10 +03004111 struct ath10k *ar = hw->priv;
4112 struct ieee80211_conf *conf = &hw->conf;
4113 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004114
4115 mutex_lock(&ar->conf_mutex);
4116
Michal Kazioraffd3212013-07-16 09:54:35 +02004117 if (changed & IEEE80211_CONF_CHANGE_PS)
4118 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004119
4120 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
Michal Kazior19337472014-08-28 12:58:16 +02004121 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
4122 ret = ath10k_monitor_recalc(ar);
4123 if (ret)
4124 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004125 }
4126
4127 mutex_unlock(&ar->conf_mutex);
4128 return ret;
4129}
4130
Ben Greear5572a952014-11-24 16:22:10 +02004131static u32 get_nss_from_chainmask(u16 chain_mask)
4132{
4133 if ((chain_mask & 0x15) == 0x15)
4134 return 4;
4135 else if ((chain_mask & 0x7) == 0x7)
4136 return 3;
4137 else if ((chain_mask & 0x3) == 0x3)
4138 return 2;
4139 return 1;
4140}
4141
Kalle Valo5e3dd152013-06-12 20:52:10 +03004142/*
4143 * TODO:
4144 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
4145 * because we will send mgmt frames without CCK. This requirement
4146 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
4147 * in the TX packet.
4148 */
4149static int ath10k_add_interface(struct ieee80211_hw *hw,
4150 struct ieee80211_vif *vif)
4151{
4152 struct ath10k *ar = hw->priv;
4153 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4154 enum wmi_sta_powersave_param param;
4155 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02004156 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004157 int bit;
Michal Kazior96d828d2015-03-31 10:26:23 +00004158 int i;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004159 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004160
Johannes Berg848955c2014-11-11 12:48:42 +01004161 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
4162
Kalle Valo5e3dd152013-06-12 20:52:10 +03004163 mutex_lock(&ar->conf_mutex);
4164
Michal Kazior0dbd09e2013-07-31 10:55:14 +02004165 memset(arvif, 0, sizeof(*arvif));
4166
Kalle Valo5e3dd152013-06-12 20:52:10 +03004167 arvif->ar = ar;
4168 arvif->vif = vif;
4169
Ben Greeare63b33f2013-10-22 14:54:14 -07004170 INIT_LIST_HEAD(&arvif->list);
Michal Kazior81a9a172015-03-05 16:02:17 +02004171 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
Michal Kaziorcc9904e2015-03-10 16:22:01 +02004172 INIT_DELAYED_WORK(&arvif->connection_loss_work,
4173 ath10k_mac_vif_sta_connection_loss_work);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03004174
Michal Kazior45c9abc2015-04-21 20:42:58 +03004175 for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) {
4176 arvif->bitrate_mask.control[i].legacy = 0xffffffff;
4177 memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff,
4178 sizeof(arvif->bitrate_mask.control[i].ht_mcs));
4179 memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff,
4180 sizeof(arvif->bitrate_mask.control[i].vht_mcs));
4181 }
4182
Ben Greeara9aefb32014-08-12 11:02:19 +03004183 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004184 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03004185 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03004186 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004187 }
Ben Greear16c11172014-09-23 14:17:16 -07004188 bit = __ffs64(ar->free_vdev_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004189
Ben Greear16c11172014-09-23 14:17:16 -07004190 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
4191 bit, ar->free_vdev_map);
4192
4193 arvif->vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004194 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004195
Kalle Valo5e3dd152013-06-12 20:52:10 +03004196 switch (vif->type) {
Michal Kazior75d2bd42014-12-12 12:41:39 +01004197 case NL80211_IFTYPE_P2P_DEVICE:
4198 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4199 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
4200 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004201 case NL80211_IFTYPE_UNSPECIFIED:
4202 case NL80211_IFTYPE_STATION:
4203 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4204 if (vif->p2p)
4205 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
4206 break;
4207 case NL80211_IFTYPE_ADHOC:
4208 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
4209 break;
4210 case NL80211_IFTYPE_AP:
4211 arvif->vdev_type = WMI_VDEV_TYPE_AP;
4212
4213 if (vif->p2p)
4214 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
4215 break;
4216 case NL80211_IFTYPE_MONITOR:
4217 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
4218 break;
4219 default:
4220 WARN_ON(1);
4221 break;
4222 }
4223
Michal Kazior96d828d2015-03-31 10:26:23 +00004224 /* Using vdev_id as queue number will make it very easy to do per-vif
4225 * tx queue locking. This shouldn't wrap due to interface combinations
4226 * but do a modulo for correctness sake and prevent using offchannel tx
4227 * queues for regular vif tx.
4228 */
4229 vif->cab_queue = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
4230 for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++)
4231 vif->hw_queue[i] = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
4232
Michal Kazior64badcb2014-09-18 11:18:02 +03004233 /* Some firmware revisions don't wait for beacon tx completion before
4234 * sending another SWBA event. This could lead to hardware using old
4235 * (freed) beacon data in some cases, e.g. tx credit starvation
4236 * combined with missed TBTT. This is very very rare.
4237 *
4238 * On non-IOMMU-enabled hosts this could be a possible security issue
4239 * because hw could beacon some random data on the air. On
4240 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
4241 * device would crash.
4242 *
4243 * Since there are no beacon tx completions (implicit nor explicit)
4244 * propagated to host the only workaround for this is to allocate a
4245 * DMA-coherent buffer for a lifetime of a vif and use it for all
4246 * beacon tx commands. Worst case for this approach is some beacons may
4247 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
4248 */
4249 if (vif->type == NL80211_IFTYPE_ADHOC ||
4250 vif->type == NL80211_IFTYPE_AP) {
4251 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
4252 IEEE80211_MAX_FRAME_LEN,
4253 &arvif->beacon_paddr,
Rajkumar Manoharan82d7aba2014-10-10 17:38:27 +05304254 GFP_ATOMIC);
Michal Kazior64badcb2014-09-18 11:18:02 +03004255 if (!arvif->beacon_buf) {
4256 ret = -ENOMEM;
4257 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
4258 ret);
4259 goto err;
4260 }
4261 }
4262
4263 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
4264 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
4265 arvif->beacon_buf ? "single-buf" : "per-skb");
Kalle Valo5e3dd152013-06-12 20:52:10 +03004266
4267 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
4268 arvif->vdev_subtype, vif->addr);
4269 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004270 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004271 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004272 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004273 }
4274
Ben Greear16c11172014-09-23 14:17:16 -07004275 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03004276 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004277
Michal Kazior46725b152015-01-28 09:57:49 +02004278 /* It makes no sense to have firmware do keepalives. mac80211 already
4279 * takes care of this with idle connection polling.
4280 */
4281 ret = ath10k_mac_vif_disable_keepalive(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004282 if (ret) {
Michal Kazior46725b152015-01-28 09:57:49 +02004283 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004284 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004285 goto err_vdev_delete;
4286 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004287
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004288 arvif->def_wep_key_idx = -1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004289
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004290 vdev_param = ar->wmi.vdev_param->tx_encap_type;
4291 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004292 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02004293 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14a2013-10-16 15:44:45 +03004294 if (ret && ret != -EOPNOTSUPP) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004295 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004296 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004297 goto err_vdev_delete;
4298 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004299
Ben Greear5572a952014-11-24 16:22:10 +02004300 if (ar->cfg_tx_chainmask) {
4301 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
4302
4303 vdev_param = ar->wmi.vdev_param->nss;
4304 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4305 nss);
4306 if (ret) {
4307 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
4308 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
4309 ret);
4310 goto err_vdev_delete;
4311 }
4312 }
4313
Michal Kaziore57e0572015-03-24 13:14:03 +00004314 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4315 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
Marek Puzyniak7390ed32015-03-30 09:51:52 +03004316 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr,
4317 WMI_PEER_TYPE_DEFAULT);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004318 if (ret) {
Michal Kaziore57e0572015-03-24 13:14:03 +00004319 ath10k_warn(ar, "failed to create vdev %i peer for AP/IBSS: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004320 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004321 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004322 }
Michal Kaziore57e0572015-03-24 13:14:03 +00004323 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01004324
Michal Kaziore57e0572015-03-24 13:14:03 +00004325 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
Kalle Valo5a13e762014-01-20 11:01:46 +02004326 ret = ath10k_mac_set_kickout(arvif);
4327 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004328 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004329 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +02004330 goto err_peer_delete;
4331 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004332 }
4333
4334 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
4335 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
4336 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4337 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4338 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004339 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004340 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004341 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004342 goto err_peer_delete;
4343 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004344
Michal Kazior9f9b5742014-12-12 12:41:36 +01004345 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004346 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01004347 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004348 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004349 goto err_peer_delete;
4350 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004351
Michal Kazior9f9b5742014-12-12 12:41:36 +01004352 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004353 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01004354 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004355 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004356 goto err_peer_delete;
4357 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004358 }
4359
Michal Kazior424121c2013-07-22 14:13:31 +02004360 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004361 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004362 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03004363 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004364 goto err_peer_delete;
4365 }
Michal Kazior679c54a2013-07-05 16:15:04 +03004366
Michal Kazior424121c2013-07-22 14:13:31 +02004367 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004368 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004369 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03004370 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004371 goto err_peer_delete;
4372 }
Michal Kazior679c54a2013-07-05 16:15:04 +03004373
Michal Kazior7d9d5582014-10-21 10:40:15 +03004374 arvif->txpower = vif->bss_conf.txpower;
4375 ret = ath10k_mac_txpower_recalc(ar);
4376 if (ret) {
4377 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
4378 goto err_peer_delete;
4379 }
4380
Michal Kazior500ff9f2015-03-31 10:26:21 +00004381 if (vif->type == NL80211_IFTYPE_MONITOR) {
4382 ar->monitor_arvif = arvif;
4383 ret = ath10k_monitor_recalc(ar);
4384 if (ret) {
4385 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4386 goto err_peer_delete;
4387 }
4388 }
4389
Kalle Valo5e3dd152013-06-12 20:52:10 +03004390 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004391 return 0;
4392
4393err_peer_delete:
Michal Kaziore57e0572015-03-24 13:14:03 +00004394 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4395 arvif->vdev_type == WMI_VDEV_TYPE_IBSS)
Michal Kazior9dad14a2013-10-16 15:44:45 +03004396 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
4397
4398err_vdev_delete:
4399 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
Ben Greear16c11172014-09-23 14:17:16 -07004400 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03004401 list_del(&arvif->list);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004402
4403err:
Michal Kazior64badcb2014-09-18 11:18:02 +03004404 if (arvif->beacon_buf) {
4405 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
4406 arvif->beacon_buf, arvif->beacon_paddr);
4407 arvif->beacon_buf = NULL;
4408 }
4409
Michal Kazior9dad14a2013-10-16 15:44:45 +03004410 mutex_unlock(&ar->conf_mutex);
4411
Kalle Valo5e3dd152013-06-12 20:52:10 +03004412 return ret;
4413}
4414
Michal Kaziorb4aa5392015-03-31 10:26:24 +00004415static void ath10k_mac_vif_tx_unlock_all(struct ath10k_vif *arvif)
4416{
4417 int i;
4418
4419 for (i = 0; i < BITS_PER_LONG; i++)
4420 ath10k_mac_vif_tx_unlock(arvif, i);
4421}
4422
Kalle Valo5e3dd152013-06-12 20:52:10 +03004423static void ath10k_remove_interface(struct ieee80211_hw *hw,
4424 struct ieee80211_vif *vif)
4425{
4426 struct ath10k *ar = hw->priv;
4427 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4428 int ret;
4429
Michal Kazior81a9a172015-03-05 16:02:17 +02004430 cancel_work_sync(&arvif->ap_csa_work);
Michal Kaziorcc9904e2015-03-10 16:22:01 +02004431 cancel_delayed_work_sync(&arvif->connection_loss_work);
Michal Kazior81a9a172015-03-05 16:02:17 +02004432
Sujith Manoharan5d011f52014-11-25 11:47:00 +05304433 mutex_lock(&ar->conf_mutex);
4434
Michal Kaziored543882013-09-13 14:16:56 +02004435 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03004436 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kaziored543882013-09-13 14:16:56 +02004437 spin_unlock_bh(&ar->data_lock);
4438
Simon Wunderlich855aed12014-08-02 09:12:54 +03004439 ret = ath10k_spectral_vif_stop(arvif);
4440 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004441 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03004442 arvif->vdev_id, ret);
4443
Ben Greear16c11172014-09-23 14:17:16 -07004444 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03004445 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004446
Michal Kaziore57e0572015-03-24 13:14:03 +00004447 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4448 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
Michal Kazior2c512052015-02-15 16:50:40 +02004449 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
4450 vif->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004451 if (ret)
Michal Kaziore57e0572015-03-24 13:14:03 +00004452 ath10k_warn(ar, "failed to submit AP/IBSS self-peer removal on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004453 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004454
4455 kfree(arvif->u.ap.noa_data);
4456 }
4457
Michal Kazior7aa7a722014-08-25 12:09:38 +02004458 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004459 arvif->vdev_id);
4460
Kalle Valo5e3dd152013-06-12 20:52:10 +03004461 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
4462 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004463 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004464 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004465
Michal Kazior2c512052015-02-15 16:50:40 +02004466 /* Some firmware revisions don't notify host about self-peer removal
4467 * until after associated vdev is deleted.
4468 */
Michal Kaziore57e0572015-03-24 13:14:03 +00004469 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4470 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
Michal Kazior2c512052015-02-15 16:50:40 +02004471 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
4472 vif->addr);
4473 if (ret)
4474 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
4475 arvif->vdev_id, ret);
4476
4477 spin_lock_bh(&ar->data_lock);
4478 ar->num_peers--;
4479 spin_unlock_bh(&ar->data_lock);
4480 }
4481
Kalle Valo5e3dd152013-06-12 20:52:10 +03004482 ath10k_peer_cleanup(ar, arvif->vdev_id);
4483
Michal Kazior500ff9f2015-03-31 10:26:21 +00004484 if (vif->type == NL80211_IFTYPE_MONITOR) {
4485 ar->monitor_arvif = NULL;
4486 ret = ath10k_monitor_recalc(ar);
4487 if (ret)
4488 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4489 }
4490
Michal Kaziorb4aa5392015-03-31 10:26:24 +00004491 spin_lock_bh(&ar->htt.tx_lock);
4492 ath10k_mac_vif_tx_unlock_all(arvif);
4493 spin_unlock_bh(&ar->htt.tx_lock);
4494
Kalle Valo5e3dd152013-06-12 20:52:10 +03004495 mutex_unlock(&ar->conf_mutex);
4496}
4497
4498/*
4499 * FIXME: Has to be verified.
4500 */
4501#define SUPPORTED_FILTERS \
4502 (FIF_PROMISC_IN_BSS | \
4503 FIF_ALLMULTI | \
4504 FIF_CONTROL | \
4505 FIF_PSPOLL | \
4506 FIF_OTHER_BSS | \
4507 FIF_BCN_PRBRESP_PROMISC | \
4508 FIF_PROBE_REQ | \
4509 FIF_FCSFAIL)
4510
4511static void ath10k_configure_filter(struct ieee80211_hw *hw,
4512 unsigned int changed_flags,
4513 unsigned int *total_flags,
4514 u64 multicast)
4515{
4516 struct ath10k *ar = hw->priv;
4517 int ret;
4518
4519 mutex_lock(&ar->conf_mutex);
4520
4521 changed_flags &= SUPPORTED_FILTERS;
4522 *total_flags &= SUPPORTED_FILTERS;
4523 ar->filter_flags = *total_flags;
4524
Michal Kazior19337472014-08-28 12:58:16 +02004525 ret = ath10k_monitor_recalc(ar);
4526 if (ret)
4527 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004528
4529 mutex_unlock(&ar->conf_mutex);
4530}
4531
4532static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
4533 struct ieee80211_vif *vif,
4534 struct ieee80211_bss_conf *info,
4535 u32 changed)
4536{
4537 struct ath10k *ar = hw->priv;
4538 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4539 int ret = 0;
Kalle Valoaf762c02014-09-14 12:50:17 +03004540 u32 vdev_param, pdev_param, slottime, preamble;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004541
4542 mutex_lock(&ar->conf_mutex);
4543
4544 if (changed & BSS_CHANGED_IBSS)
4545 ath10k_control_ibss(arvif, info, vif->addr);
4546
4547 if (changed & BSS_CHANGED_BEACON_INT) {
4548 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004549 vdev_param = ar->wmi.vdev_param->beacon_interval;
4550 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004551 arvif->beacon_interval);
Michal Kazior7aa7a722014-08-25 12:09:38 +02004552 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004553 "mac vdev %d beacon_interval %d\n",
4554 arvif->vdev_id, arvif->beacon_interval);
4555
Kalle Valo5e3dd152013-06-12 20:52:10 +03004556 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004557 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004558 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004559 }
4560
4561 if (changed & BSS_CHANGED_BEACON) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004562 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004563 "vdev %d set beacon tx mode to staggered\n",
4564 arvif->vdev_id);
4565
Bartosz Markowski226a3392013-09-26 17:47:16 +02004566 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
4567 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004568 WMI_BEACON_STAGGERED_MODE);
4569 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004570 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004571 arvif->vdev_id, ret);
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02004572
4573 ret = ath10k_mac_setup_bcn_tmpl(arvif);
4574 if (ret)
4575 ath10k_warn(ar, "failed to update beacon template: %d\n",
4576 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004577 }
4578
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02004579 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
4580 ret = ath10k_mac_setup_prb_tmpl(arvif);
4581 if (ret)
4582 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
4583 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004584 }
4585
Michal Kaziorba2479f2015-01-24 12:14:51 +02004586 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004587 arvif->dtim_period = info->dtim_period;
4588
Michal Kazior7aa7a722014-08-25 12:09:38 +02004589 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004590 "mac vdev %d dtim_period %d\n",
4591 arvif->vdev_id, arvif->dtim_period);
4592
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004593 vdev_param = ar->wmi.vdev_param->dtim_period;
4594 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004595 arvif->dtim_period);
4596 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004597 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004598 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004599 }
4600
4601 if (changed & BSS_CHANGED_SSID &&
4602 vif->type == NL80211_IFTYPE_AP) {
4603 arvif->u.ap.ssid_len = info->ssid_len;
4604 if (info->ssid_len)
4605 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
4606 arvif->u.ap.hidden_ssid = info->hidden_ssid;
4607 }
4608
Michal Kazior077efc82014-10-21 10:10:29 +03004609 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
4610 ether_addr_copy(arvif->bssid, info->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004611
4612 if (changed & BSS_CHANGED_BEACON_ENABLED)
4613 ath10k_control_beaconing(arvif, info);
4614
4615 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02004616 arvif->use_cts_prot = info->use_cts_prot;
Michal Kazior7aa7a722014-08-25 12:09:38 +02004617 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02004618 arvif->vdev_id, info->use_cts_prot);
Kalle Valo60c3daa2013-09-08 17:56:07 +03004619
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02004620 ret = ath10k_recalc_rtscts_prot(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004621 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004622 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004623 arvif->vdev_id, ret);
Michal Kaziora87fd4b2015-03-02 11:21:17 +01004624
4625 vdev_param = ar->wmi.vdev_param->protection_mode;
4626 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4627 info->use_cts_prot ? 1 : 0);
4628 if (ret)
4629 ath10k_warn(ar, "failed to set protection mode %d on vdev %i: %d\n",
4630 info->use_cts_prot, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004631 }
4632
4633 if (changed & BSS_CHANGED_ERP_SLOT) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004634 if (info->use_short_slot)
4635 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
4636
4637 else
4638 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
4639
Michal Kazior7aa7a722014-08-25 12:09:38 +02004640 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004641 arvif->vdev_id, slottime);
4642
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004643 vdev_param = ar->wmi.vdev_param->slot_time;
4644 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004645 slottime);
4646 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004647 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004648 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004649 }
4650
4651 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004652 if (info->use_short_preamble)
4653 preamble = WMI_VDEV_PREAMBLE_SHORT;
4654 else
4655 preamble = WMI_VDEV_PREAMBLE_LONG;
4656
Michal Kazior7aa7a722014-08-25 12:09:38 +02004657 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004658 "mac vdev %d preamble %dn",
4659 arvif->vdev_id, preamble);
4660
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004661 vdev_param = ar->wmi.vdev_param->preamble;
4662 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004663 preamble);
4664 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004665 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004666 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004667 }
4668
4669 if (changed & BSS_CHANGED_ASSOC) {
Michal Kaziore556f112014-08-28 12:58:17 +02004670 if (info->assoc) {
4671 /* Workaround: Make sure monitor vdev is not running
4672 * when associating to prevent some firmware revisions
4673 * (e.g. 10.1 and 10.2) from crashing.
4674 */
4675 if (ar->monitor_started)
4676 ath10k_monitor_stop(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004677 ath10k_bss_assoc(hw, vif, info);
Michal Kaziore556f112014-08-28 12:58:17 +02004678 ath10k_monitor_recalc(ar);
Michal Kazior077efc82014-10-21 10:10:29 +03004679 } else {
4680 ath10k_bss_disassoc(hw, vif);
Michal Kaziore556f112014-08-28 12:58:17 +02004681 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004682 }
4683
Michal Kazior7d9d5582014-10-21 10:40:15 +03004684 if (changed & BSS_CHANGED_TXPOWER) {
4685 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
4686 arvif->vdev_id, info->txpower);
4687
4688 arvif->txpower = info->txpower;
4689 ret = ath10k_mac_txpower_recalc(ar);
4690 if (ret)
4691 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
4692 }
4693
Michal Kaziorbf14e652014-12-12 12:41:38 +01004694 if (changed & BSS_CHANGED_PS) {
Michal Kaziorcffb41f2015-02-13 13:30:16 +01004695 arvif->ps = vif->bss_conf.ps;
4696
4697 ret = ath10k_config_ps(ar);
Michal Kaziorbf14e652014-12-12 12:41:38 +01004698 if (ret)
4699 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
4700 arvif->vdev_id, ret);
4701 }
4702
Kalle Valo5e3dd152013-06-12 20:52:10 +03004703 mutex_unlock(&ar->conf_mutex);
4704}
4705
4706static int ath10k_hw_scan(struct ieee80211_hw *hw,
4707 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02004708 struct ieee80211_scan_request *hw_req)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004709{
4710 struct ath10k *ar = hw->priv;
4711 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
David Spinadelc56ef672014-02-05 15:21:13 +02004712 struct cfg80211_scan_request *req = &hw_req->req;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004713 struct wmi_start_scan_arg arg;
4714 int ret = 0;
4715 int i;
4716
4717 mutex_lock(&ar->conf_mutex);
4718
4719 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004720 switch (ar->scan.state) {
4721 case ATH10K_SCAN_IDLE:
4722 reinit_completion(&ar->scan.started);
4723 reinit_completion(&ar->scan.completed);
4724 ar->scan.state = ATH10K_SCAN_STARTING;
4725 ar->scan.is_roc = false;
4726 ar->scan.vdev_id = arvif->vdev_id;
4727 ret = 0;
4728 break;
4729 case ATH10K_SCAN_STARTING:
4730 case ATH10K_SCAN_RUNNING:
4731 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004732 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004733 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004734 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004735 spin_unlock_bh(&ar->data_lock);
4736
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004737 if (ret)
4738 goto exit;
4739
Kalle Valo5e3dd152013-06-12 20:52:10 +03004740 memset(&arg, 0, sizeof(arg));
4741 ath10k_wmi_start_scan_init(ar, &arg);
4742 arg.vdev_id = arvif->vdev_id;
4743 arg.scan_id = ATH10K_SCAN_ID;
4744
4745 if (!req->no_cck)
4746 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
4747
4748 if (req->ie_len) {
4749 arg.ie_len = req->ie_len;
4750 memcpy(arg.ie, req->ie, arg.ie_len);
4751 }
4752
4753 if (req->n_ssids) {
4754 arg.n_ssids = req->n_ssids;
4755 for (i = 0; i < arg.n_ssids; i++) {
4756 arg.ssids[i].len = req->ssids[i].ssid_len;
4757 arg.ssids[i].ssid = req->ssids[i].ssid;
4758 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02004759 } else {
4760 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004761 }
4762
4763 if (req->n_channels) {
4764 arg.n_channels = req->n_channels;
4765 for (i = 0; i < arg.n_channels; i++)
4766 arg.channels[i] = req->channels[i]->center_freq;
4767 }
4768
4769 ret = ath10k_start_scan(ar, &arg);
4770 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004771 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004772 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004773 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004774 spin_unlock_bh(&ar->data_lock);
4775 }
4776
4777exit:
4778 mutex_unlock(&ar->conf_mutex);
4779 return ret;
4780}
4781
4782static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
4783 struct ieee80211_vif *vif)
4784{
4785 struct ath10k *ar = hw->priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004786
4787 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004788 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004789 mutex_unlock(&ar->conf_mutex);
Michal Kazior4eb2e162014-10-28 10:23:09 +01004790
4791 cancel_delayed_work_sync(&ar->scan.timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004792}
4793
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004794static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
4795 struct ath10k_vif *arvif,
4796 enum set_key_cmd cmd,
4797 struct ieee80211_key_conf *key)
4798{
4799 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
4800 int ret;
4801
4802 /* 10.1 firmware branch requires default key index to be set to group
4803 * key index after installing it. Otherwise FW/HW Txes corrupted
4804 * frames with multi-vif APs. This is not required for main firmware
4805 * branch (e.g. 636).
4806 *
Michal Kazior8461baf2015-04-10 13:23:22 +00004807 * This is also needed for 636 fw for IBSS-RSN to work more reliably.
4808 *
4809 * FIXME: It remains unknown if this is required for multi-vif STA
4810 * interfaces on 10.1.
4811 */
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004812
Michal Kazior8461baf2015-04-10 13:23:22 +00004813 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
4814 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004815 return;
4816
4817 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
4818 return;
4819
4820 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
4821 return;
4822
4823 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4824 return;
4825
4826 if (cmd != SET_KEY)
4827 return;
4828
4829 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4830 key->keyidx);
4831 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004832 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004833 arvif->vdev_id, ret);
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004834}
4835
Kalle Valo5e3dd152013-06-12 20:52:10 +03004836static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
4837 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
4838 struct ieee80211_key_conf *key)
4839{
4840 struct ath10k *ar = hw->priv;
4841 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4842 struct ath10k_peer *peer;
4843 const u8 *peer_addr;
4844 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
4845 key->cipher == WLAN_CIPHER_SUITE_WEP104;
4846 int ret = 0;
Michal Kazior29a10002015-04-10 13:05:58 +00004847 int ret2;
Michal Kazior370e5672015-02-18 14:02:26 +01004848 u32 flags = 0;
Michal Kazior29a10002015-04-10 13:05:58 +00004849 u32 flags2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004850
Bartosz Markowskid7131c02015-03-10 14:32:19 +01004851 /* this one needs to be done in software */
4852 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
4853 return 1;
4854
Kalle Valo5e3dd152013-06-12 20:52:10 +03004855 if (key->keyidx > WMI_MAX_KEY_INDEX)
4856 return -ENOSPC;
4857
4858 mutex_lock(&ar->conf_mutex);
4859
4860 if (sta)
4861 peer_addr = sta->addr;
4862 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
4863 peer_addr = vif->bss_conf.bssid;
4864 else
4865 peer_addr = vif->addr;
4866
4867 key->hw_key_idx = key->keyidx;
4868
Michal Kazior7c8cc7e2015-04-01 22:53:19 +03004869 if (is_wep) {
4870 if (cmd == SET_KEY)
4871 arvif->wep_keys[key->keyidx] = key;
4872 else
4873 arvif->wep_keys[key->keyidx] = NULL;
4874 }
4875
Kalle Valo5e3dd152013-06-12 20:52:10 +03004876 /* the peer should not disappear in mid-way (unless FW goes awry) since
4877 * we already hold conf_mutex. we just make sure its there now. */
4878 spin_lock_bh(&ar->data_lock);
4879 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4880 spin_unlock_bh(&ar->data_lock);
4881
4882 if (!peer) {
4883 if (cmd == SET_KEY) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004884 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03004885 peer_addr);
4886 ret = -EOPNOTSUPP;
4887 goto exit;
4888 } else {
4889 /* if the peer doesn't exist there is no key to disable
4890 * anymore */
4891 goto exit;
4892 }
4893 }
4894
Michal Kazior7cc45732015-03-09 14:24:17 +01004895 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4896 flags |= WMI_KEY_PAIRWISE;
4897 else
4898 flags |= WMI_KEY_GROUP;
4899
Kalle Valo5e3dd152013-06-12 20:52:10 +03004900 if (is_wep) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004901 if (cmd == DISABLE_KEY)
4902 ath10k_clear_vdev_key(arvif, key);
Michal Kazior370e5672015-02-18 14:02:26 +01004903
Michal Kaziorad325cb2015-02-18 14:02:27 +01004904 /* When WEP keys are uploaded it's possible that there are
4905 * stations associated already (e.g. when merging) without any
4906 * keys. Static WEP needs an explicit per-peer key upload.
4907 */
4908 if (vif->type == NL80211_IFTYPE_ADHOC &&
4909 cmd == SET_KEY)
4910 ath10k_mac_vif_update_wep_key(arvif, key);
4911
Michal Kazior370e5672015-02-18 14:02:26 +01004912 /* 802.1x never sets the def_wep_key_idx so each set_key()
4913 * call changes default tx key.
4914 *
4915 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
4916 * after first set_key().
4917 */
4918 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
4919 flags |= WMI_KEY_TX_USAGE;
Michal Kazior370e5672015-02-18 14:02:26 +01004920 }
4921
4922 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004923 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004924 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004925 arvif->vdev_id, peer_addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004926 goto exit;
4927 }
4928
Michal Kazior29a10002015-04-10 13:05:58 +00004929 /* mac80211 sets static WEP keys as groupwise while firmware requires
4930 * them to be installed twice as both pairwise and groupwise.
4931 */
4932 if (is_wep && !sta && vif->type == NL80211_IFTYPE_STATION) {
4933 flags2 = flags;
4934 flags2 &= ~WMI_KEY_GROUP;
4935 flags2 |= WMI_KEY_PAIRWISE;
4936
4937 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags2);
4938 if (ret) {
4939 ath10k_warn(ar, "failed to install (ucast) key for vdev %i peer %pM: %d\n",
4940 arvif->vdev_id, peer_addr, ret);
4941 ret2 = ath10k_install_key(arvif, key, DISABLE_KEY,
4942 peer_addr, flags);
4943 if (ret2)
4944 ath10k_warn(ar, "failed to disable (mcast) key for vdev %i peer %pM: %d\n",
4945 arvif->vdev_id, peer_addr, ret2);
4946 goto exit;
4947 }
4948 }
4949
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004950 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
4951
Kalle Valo5e3dd152013-06-12 20:52:10 +03004952 spin_lock_bh(&ar->data_lock);
4953 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4954 if (peer && cmd == SET_KEY)
4955 peer->keys[key->keyidx] = key;
4956 else if (peer && cmd == DISABLE_KEY)
4957 peer->keys[key->keyidx] = NULL;
4958 else if (peer == NULL)
4959 /* impossible unless FW goes crazy */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004960 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004961 spin_unlock_bh(&ar->data_lock);
4962
4963exit:
4964 mutex_unlock(&ar->conf_mutex);
4965 return ret;
4966}
4967
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004968static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
4969 struct ieee80211_vif *vif,
4970 int keyidx)
4971{
4972 struct ath10k *ar = hw->priv;
4973 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4974 int ret;
4975
4976 mutex_lock(&arvif->ar->conf_mutex);
4977
4978 if (arvif->ar->state != ATH10K_STATE_ON)
4979 goto unlock;
4980
4981 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
4982 arvif->vdev_id, keyidx);
4983
4984 ret = ath10k_wmi_vdev_set_param(arvif->ar,
4985 arvif->vdev_id,
4986 arvif->ar->wmi.vdev_param->def_keyid,
4987 keyidx);
4988
4989 if (ret) {
4990 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
4991 arvif->vdev_id,
4992 ret);
4993 goto unlock;
4994 }
4995
4996 arvif->def_wep_key_idx = keyidx;
Michal Kazior370e5672015-02-18 14:02:26 +01004997
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004998unlock:
4999 mutex_unlock(&arvif->ar->conf_mutex);
5000}
5001
Michal Kazior9797feb2014-02-14 14:49:48 +01005002static void ath10k_sta_rc_update_wk(struct work_struct *wk)
5003{
5004 struct ath10k *ar;
5005 struct ath10k_vif *arvif;
5006 struct ath10k_sta *arsta;
5007 struct ieee80211_sta *sta;
Michal Kazior45c9abc2015-04-21 20:42:58 +03005008 struct cfg80211_chan_def def;
5009 enum ieee80211_band band;
5010 const u8 *ht_mcs_mask;
5011 const u16 *vht_mcs_mask;
Michal Kazior9797feb2014-02-14 14:49:48 +01005012 u32 changed, bw, nss, smps;
5013 int err;
5014
5015 arsta = container_of(wk, struct ath10k_sta, update_wk);
5016 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
5017 arvif = arsta->arvif;
5018 ar = arvif->ar;
5019
Michal Kazior45c9abc2015-04-21 20:42:58 +03005020 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
5021 return;
5022
5023 band = def.chan->band;
5024 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
5025 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
5026
Michal Kazior9797feb2014-02-14 14:49:48 +01005027 spin_lock_bh(&ar->data_lock);
5028
5029 changed = arsta->changed;
5030 arsta->changed = 0;
5031
5032 bw = arsta->bw;
5033 nss = arsta->nss;
5034 smps = arsta->smps;
5035
5036 spin_unlock_bh(&ar->data_lock);
5037
5038 mutex_lock(&ar->conf_mutex);
5039
Michal Kazior45c9abc2015-04-21 20:42:58 +03005040 nss = max_t(u32, 1, nss);
5041 nss = min(nss, max(ath10k_mac_max_ht_nss(ht_mcs_mask),
5042 ath10k_mac_max_vht_nss(vht_mcs_mask)));
5043
Michal Kazior9797feb2014-02-14 14:49:48 +01005044 if (changed & IEEE80211_RC_BW_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005045 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01005046 sta->addr, bw);
5047
5048 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5049 WMI_PEER_CHAN_WIDTH, bw);
5050 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005051 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01005052 sta->addr, bw, err);
5053 }
5054
5055 if (changed & IEEE80211_RC_NSS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005056 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01005057 sta->addr, nss);
5058
5059 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5060 WMI_PEER_NSS, nss);
5061 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005062 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01005063 sta->addr, nss, err);
5064 }
5065
5066 if (changed & IEEE80211_RC_SMPS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005067 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01005068 sta->addr, smps);
5069
5070 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5071 WMI_PEER_SMPS_STATE, smps);
5072 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005073 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01005074 sta->addr, smps, err);
5075 }
5076
Janusz Dziedzic55884c02014-12-17 12:30:02 +02005077 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
5078 changed & IEEE80211_RC_NSS_CHANGED) {
5079 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02005080 sta->addr);
5081
Michal Kazior590922a2014-10-21 10:10:29 +03005082 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02005083 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005084 ath10k_warn(ar, "failed to reassociate station: %pM\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02005085 sta->addr);
5086 }
5087
Michal Kazior9797feb2014-02-14 14:49:48 +01005088 mutex_unlock(&ar->conf_mutex);
5089}
5090
Marek Puzyniak7c354242015-03-30 09:51:52 +03005091static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif,
5092 struct ieee80211_sta *sta)
Michal Kaziorcfd10612014-11-25 15:16:05 +01005093{
5094 struct ath10k *ar = arvif->ar;
5095
5096 lockdep_assert_held(&ar->conf_mutex);
5097
Marek Puzyniak7c354242015-03-30 09:51:52 +03005098 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
Michal Kaziorcfd10612014-11-25 15:16:05 +01005099 return 0;
5100
5101 if (ar->num_stations >= ar->max_num_stations)
5102 return -ENOBUFS;
5103
5104 ar->num_stations++;
5105
5106 return 0;
5107}
5108
Marek Puzyniak7c354242015-03-30 09:51:52 +03005109static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif,
5110 struct ieee80211_sta *sta)
Michal Kaziorcfd10612014-11-25 15:16:05 +01005111{
5112 struct ath10k *ar = arvif->ar;
5113
5114 lockdep_assert_held(&ar->conf_mutex);
5115
Marek Puzyniak7c354242015-03-30 09:51:52 +03005116 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
Michal Kaziorcfd10612014-11-25 15:16:05 +01005117 return;
5118
5119 ar->num_stations--;
5120}
5121
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005122struct ath10k_mac_tdls_iter_data {
5123 u32 num_tdls_stations;
5124 struct ieee80211_vif *curr_vif;
5125};
5126
5127static void ath10k_mac_tdls_vif_stations_count_iter(void *data,
5128 struct ieee80211_sta *sta)
5129{
5130 struct ath10k_mac_tdls_iter_data *iter_data = data;
5131 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5132 struct ieee80211_vif *sta_vif = arsta->arvif->vif;
5133
5134 if (sta->tdls && sta_vif == iter_data->curr_vif)
5135 iter_data->num_tdls_stations++;
5136}
5137
5138static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw *hw,
5139 struct ieee80211_vif *vif)
5140{
5141 struct ath10k_mac_tdls_iter_data data = {};
5142
5143 data.curr_vif = vif;
5144
5145 ieee80211_iterate_stations_atomic(hw,
5146 ath10k_mac_tdls_vif_stations_count_iter,
5147 &data);
5148 return data.num_tdls_stations;
5149}
5150
5151static void ath10k_mac_tdls_vifs_count_iter(void *data, u8 *mac,
5152 struct ieee80211_vif *vif)
5153{
5154 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5155 int *num_tdls_vifs = data;
5156
5157 if (vif->type != NL80211_IFTYPE_STATION)
5158 return;
5159
5160 if (ath10k_mac_tdls_vif_stations_count(arvif->ar->hw, vif) > 0)
5161 (*num_tdls_vifs)++;
5162}
5163
5164static int ath10k_mac_tdls_vifs_count(struct ieee80211_hw *hw)
5165{
5166 int num_tdls_vifs = 0;
5167
5168 ieee80211_iterate_active_interfaces_atomic(hw,
5169 IEEE80211_IFACE_ITER_NORMAL,
5170 ath10k_mac_tdls_vifs_count_iter,
5171 &num_tdls_vifs);
5172 return num_tdls_vifs;
5173}
5174
Kalle Valo5e3dd152013-06-12 20:52:10 +03005175static int ath10k_sta_state(struct ieee80211_hw *hw,
5176 struct ieee80211_vif *vif,
5177 struct ieee80211_sta *sta,
5178 enum ieee80211_sta_state old_state,
5179 enum ieee80211_sta_state new_state)
5180{
5181 struct ath10k *ar = hw->priv;
5182 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01005183 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005184 int ret = 0;
5185
Michal Kazior76f90022014-02-25 09:29:57 +02005186 if (old_state == IEEE80211_STA_NOTEXIST &&
5187 new_state == IEEE80211_STA_NONE) {
5188 memset(arsta, 0, sizeof(*arsta));
5189 arsta->arvif = arvif;
5190 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
5191 }
5192
Michal Kazior9797feb2014-02-14 14:49:48 +01005193 /* cancel must be done outside the mutex to avoid deadlock */
5194 if ((old_state == IEEE80211_STA_NONE &&
5195 new_state == IEEE80211_STA_NOTEXIST))
5196 cancel_work_sync(&arsta->update_wk);
5197
Kalle Valo5e3dd152013-06-12 20:52:10 +03005198 mutex_lock(&ar->conf_mutex);
5199
5200 if (old_state == IEEE80211_STA_NOTEXIST &&
Michal Kazior077efc82014-10-21 10:10:29 +03005201 new_state == IEEE80211_STA_NONE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03005202 /*
5203 * New station addition.
5204 */
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005205 enum wmi_peer_type peer_type = WMI_PEER_TYPE_DEFAULT;
5206 u32 num_tdls_stations;
5207 u32 num_tdls_vifs;
5208
Michal Kaziorcfd10612014-11-25 15:16:05 +01005209 ath10k_dbg(ar, ATH10K_DBG_MAC,
5210 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
5211 arvif->vdev_id, sta->addr,
5212 ar->num_stations + 1, ar->max_num_stations,
5213 ar->num_peers + 1, ar->max_num_peers);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01005214
Marek Puzyniak7c354242015-03-30 09:51:52 +03005215 ret = ath10k_mac_inc_num_stations(arvif, sta);
Michal Kaziorcfd10612014-11-25 15:16:05 +01005216 if (ret) {
5217 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
5218 ar->max_num_stations);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01005219 goto exit;
5220 }
5221
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005222 if (sta->tdls)
5223 peer_type = WMI_PEER_TYPE_TDLS;
5224
Marek Puzyniak7390ed32015-03-30 09:51:52 +03005225 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr,
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005226 peer_type);
Michal Kaziora52c0282014-11-25 15:16:03 +01005227 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005228 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 -08005229 sta->addr, arvif->vdev_id, ret);
Marek Puzyniak7c354242015-03-30 09:51:52 +03005230 ath10k_mac_dec_num_stations(arvif, sta);
Michal Kaziora52c0282014-11-25 15:16:03 +01005231 goto exit;
5232 }
Michal Kazior077efc82014-10-21 10:10:29 +03005233
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005234 if (!sta->tdls)
5235 goto exit;
5236
5237 num_tdls_stations = ath10k_mac_tdls_vif_stations_count(hw, vif);
5238 num_tdls_vifs = ath10k_mac_tdls_vifs_count(hw);
5239
5240 if (num_tdls_vifs >= ar->max_num_tdls_vdevs &&
5241 num_tdls_stations == 0) {
5242 ath10k_warn(ar, "vdev %i exceeded maximum number of tdls vdevs %i\n",
5243 arvif->vdev_id, ar->max_num_tdls_vdevs);
5244 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5245 ath10k_mac_dec_num_stations(arvif, sta);
5246 ret = -ENOBUFS;
5247 goto exit;
5248 }
5249
5250 if (num_tdls_stations == 0) {
5251 /* This is the first tdls peer in current vif */
5252 enum wmi_tdls_state state = WMI_TDLS_ENABLE_ACTIVE;
5253
5254 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5255 state);
5256 if (ret) {
5257 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
5258 arvif->vdev_id, ret);
5259 ath10k_peer_delete(ar, arvif->vdev_id,
5260 sta->addr);
5261 ath10k_mac_dec_num_stations(arvif, sta);
5262 goto exit;
5263 }
5264 }
5265
5266 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
5267 WMI_TDLS_PEER_STATE_PEERING);
5268 if (ret) {
5269 ath10k_warn(ar,
5270 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
5271 sta->addr, arvif->vdev_id, ret);
5272 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5273 ath10k_mac_dec_num_stations(arvif, sta);
5274
5275 if (num_tdls_stations != 0)
5276 goto exit;
5277 ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5278 WMI_TDLS_DISABLE);
5279 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005280 } else if ((old_state == IEEE80211_STA_NONE &&
5281 new_state == IEEE80211_STA_NOTEXIST)) {
5282 /*
5283 * Existing station deletion.
5284 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005285 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03005286 "mac vdev %d peer delete %pM (sta gone)\n",
5287 arvif->vdev_id, sta->addr);
Michal Kazior077efc82014-10-21 10:10:29 +03005288
Kalle Valo5e3dd152013-06-12 20:52:10 +03005289 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5290 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005291 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02005292 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005293
Marek Puzyniak7c354242015-03-30 09:51:52 +03005294 ath10k_mac_dec_num_stations(arvif, sta);
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005295
5296 if (!sta->tdls)
5297 goto exit;
5298
5299 if (ath10k_mac_tdls_vif_stations_count(hw, vif))
5300 goto exit;
5301
5302 /* This was the last tdls peer in current vif */
5303 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5304 WMI_TDLS_DISABLE);
5305 if (ret) {
5306 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
5307 arvif->vdev_id, ret);
5308 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005309 } else if (old_state == IEEE80211_STA_AUTH &&
5310 new_state == IEEE80211_STA_ASSOC &&
5311 (vif->type == NL80211_IFTYPE_AP ||
5312 vif->type == NL80211_IFTYPE_ADHOC)) {
5313 /*
5314 * New association.
5315 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005316 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03005317 sta->addr);
5318
Michal Kazior590922a2014-10-21 10:10:29 +03005319 ret = ath10k_station_assoc(ar, vif, sta, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005320 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005321 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02005322 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005323 } else if (old_state == IEEE80211_STA_ASSOC &&
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005324 new_state == IEEE80211_STA_AUTHORIZED &&
5325 sta->tdls) {
5326 /*
5327 * Tdls station authorized.
5328 */
5329 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac tdls sta %pM authorized\n",
5330 sta->addr);
5331
5332 ret = ath10k_station_assoc(ar, vif, sta, false);
5333 if (ret) {
5334 ath10k_warn(ar, "failed to associate tdls station %pM for vdev %i: %i\n",
5335 sta->addr, arvif->vdev_id, ret);
5336 goto exit;
5337 }
5338
5339 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
5340 WMI_TDLS_PEER_STATE_CONNECTED);
5341 if (ret)
5342 ath10k_warn(ar, "failed to update tdls peer %pM for vdev %i: %i\n",
5343 sta->addr, arvif->vdev_id, ret);
5344 } else if (old_state == IEEE80211_STA_ASSOC &&
5345 new_state == IEEE80211_STA_AUTH &&
5346 (vif->type == NL80211_IFTYPE_AP ||
5347 vif->type == NL80211_IFTYPE_ADHOC)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03005348 /*
5349 * Disassociation.
5350 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005351 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03005352 sta->addr);
5353
Michal Kazior590922a2014-10-21 10:10:29 +03005354 ret = ath10k_station_disassoc(ar, vif, sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005355 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005356 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02005357 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005358 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01005359exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005360 mutex_unlock(&ar->conf_mutex);
5361 return ret;
5362}
5363
5364static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
Kalle Valo5b07e072014-09-14 12:50:06 +03005365 u16 ac, bool enable)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005366{
5367 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorb0e56152015-01-24 12:14:52 +02005368 struct wmi_sta_uapsd_auto_trig_arg arg = {};
5369 u32 prio = 0, acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005370 u32 value = 0;
5371 int ret = 0;
5372
Michal Kazior548db542013-07-05 16:15:15 +03005373 lockdep_assert_held(&ar->conf_mutex);
5374
Kalle Valo5e3dd152013-06-12 20:52:10 +03005375 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
5376 return 0;
5377
5378 switch (ac) {
5379 case IEEE80211_AC_VO:
5380 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
5381 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005382 prio = 7;
5383 acc = 3;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005384 break;
5385 case IEEE80211_AC_VI:
5386 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
5387 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005388 prio = 5;
5389 acc = 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005390 break;
5391 case IEEE80211_AC_BE:
5392 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
5393 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005394 prio = 2;
5395 acc = 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005396 break;
5397 case IEEE80211_AC_BK:
5398 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
5399 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005400 prio = 0;
5401 acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005402 break;
5403 }
5404
5405 if (enable)
5406 arvif->u.sta.uapsd |= value;
5407 else
5408 arvif->u.sta.uapsd &= ~value;
5409
5410 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5411 WMI_STA_PS_PARAM_UAPSD,
5412 arvif->u.sta.uapsd);
5413 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005414 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005415 goto exit;
5416 }
5417
5418 if (arvif->u.sta.uapsd)
5419 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
5420 else
5421 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
5422
5423 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5424 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
5425 value);
5426 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005427 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005428
Michal Kazior9f9b5742014-12-12 12:41:36 +01005429 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
5430 if (ret) {
5431 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
5432 arvif->vdev_id, ret);
5433 return ret;
5434 }
5435
5436 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
5437 if (ret) {
5438 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
5439 arvif->vdev_id, ret);
5440 return ret;
5441 }
5442
Michal Kaziorb0e56152015-01-24 12:14:52 +02005443 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
5444 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
5445 /* Only userspace can make an educated decision when to send
5446 * trigger frame. The following effectively disables u-UAPSD
5447 * autotrigger in firmware (which is enabled by default
5448 * provided the autotrigger service is available).
5449 */
5450
5451 arg.wmm_ac = acc;
5452 arg.user_priority = prio;
5453 arg.service_interval = 0;
5454 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
5455 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
5456
5457 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
5458 arvif->bssid, &arg, 1);
5459 if (ret) {
5460 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
5461 ret);
5462 return ret;
5463 }
5464 }
5465
Kalle Valo5e3dd152013-06-12 20:52:10 +03005466exit:
5467 return ret;
5468}
5469
5470static int ath10k_conf_tx(struct ieee80211_hw *hw,
5471 struct ieee80211_vif *vif, u16 ac,
5472 const struct ieee80211_tx_queue_params *params)
5473{
5474 struct ath10k *ar = hw->priv;
Michal Kazior5e752e42015-01-19 09:53:41 +01005475 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005476 struct wmi_wmm_params_arg *p = NULL;
5477 int ret;
5478
5479 mutex_lock(&ar->conf_mutex);
5480
5481 switch (ac) {
5482 case IEEE80211_AC_VO:
Michal Kazior5e752e42015-01-19 09:53:41 +01005483 p = &arvif->wmm_params.ac_vo;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005484 break;
5485 case IEEE80211_AC_VI:
Michal Kazior5e752e42015-01-19 09:53:41 +01005486 p = &arvif->wmm_params.ac_vi;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005487 break;
5488 case IEEE80211_AC_BE:
Michal Kazior5e752e42015-01-19 09:53:41 +01005489 p = &arvif->wmm_params.ac_be;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005490 break;
5491 case IEEE80211_AC_BK:
Michal Kazior5e752e42015-01-19 09:53:41 +01005492 p = &arvif->wmm_params.ac_bk;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005493 break;
5494 }
5495
5496 if (WARN_ON(!p)) {
5497 ret = -EINVAL;
5498 goto exit;
5499 }
5500
5501 p->cwmin = params->cw_min;
5502 p->cwmax = params->cw_max;
5503 p->aifs = params->aifs;
5504
5505 /*
5506 * The channel time duration programmed in the HW is in absolute
5507 * microseconds, while mac80211 gives the txop in units of
5508 * 32 microseconds.
5509 */
5510 p->txop = params->txop * 32;
5511
Michal Kazior7fc979a2015-01-28 09:57:28 +02005512 if (ar->wmi.ops->gen_vdev_wmm_conf) {
5513 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
5514 &arvif->wmm_params);
5515 if (ret) {
5516 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
5517 arvif->vdev_id, ret);
5518 goto exit;
5519 }
5520 } else {
5521 /* This won't work well with multi-interface cases but it's
5522 * better than nothing.
5523 */
5524 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
5525 if (ret) {
5526 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
5527 goto exit;
5528 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005529 }
5530
5531 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
5532 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005533 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005534
5535exit:
5536 mutex_unlock(&ar->conf_mutex);
5537 return ret;
5538}
5539
5540#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
5541
5542static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
5543 struct ieee80211_vif *vif,
5544 struct ieee80211_channel *chan,
5545 int duration,
5546 enum ieee80211_roc_type type)
5547{
5548 struct ath10k *ar = hw->priv;
5549 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5550 struct wmi_start_scan_arg arg;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005551 int ret = 0;
Michal Kaziorfcf98442015-03-31 11:03:47 +00005552 u32 scan_time_msec;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005553
5554 mutex_lock(&ar->conf_mutex);
5555
5556 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005557 switch (ar->scan.state) {
5558 case ATH10K_SCAN_IDLE:
5559 reinit_completion(&ar->scan.started);
5560 reinit_completion(&ar->scan.completed);
5561 reinit_completion(&ar->scan.on_channel);
5562 ar->scan.state = ATH10K_SCAN_STARTING;
5563 ar->scan.is_roc = true;
5564 ar->scan.vdev_id = arvif->vdev_id;
5565 ar->scan.roc_freq = chan->center_freq;
5566 ret = 0;
5567 break;
5568 case ATH10K_SCAN_STARTING:
5569 case ATH10K_SCAN_RUNNING:
5570 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005571 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005572 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005573 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005574 spin_unlock_bh(&ar->data_lock);
5575
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005576 if (ret)
5577 goto exit;
5578
Michal Kaziorfcf98442015-03-31 11:03:47 +00005579 scan_time_msec = ar->hw->wiphy->max_remain_on_channel_duration * 2;
Michal Kaziordcca0bd2014-11-24 14:58:32 +01005580
Kalle Valo5e3dd152013-06-12 20:52:10 +03005581 memset(&arg, 0, sizeof(arg));
5582 ath10k_wmi_start_scan_init(ar, &arg);
5583 arg.vdev_id = arvif->vdev_id;
5584 arg.scan_id = ATH10K_SCAN_ID;
5585 arg.n_channels = 1;
5586 arg.channels[0] = chan->center_freq;
Michal Kaziorfcf98442015-03-31 11:03:47 +00005587 arg.dwell_time_active = scan_time_msec;
5588 arg.dwell_time_passive = scan_time_msec;
5589 arg.max_scan_time = scan_time_msec;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005590 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
5591 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
Michal Kaziordbd3f9f2015-03-31 11:03:48 +00005592 arg.burst_duration_ms = duration;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005593
5594 ret = ath10k_start_scan(ar, &arg);
5595 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005596 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005597 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005598 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005599 spin_unlock_bh(&ar->data_lock);
5600 goto exit;
5601 }
5602
5603 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
5604 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005605 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005606
5607 ret = ath10k_scan_stop(ar);
5608 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005609 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005610
Kalle Valo5e3dd152013-06-12 20:52:10 +03005611 ret = -ETIMEDOUT;
5612 goto exit;
5613 }
5614
Michal Kaziorfcf98442015-03-31 11:03:47 +00005615 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
5616 msecs_to_jiffies(duration));
5617
Kalle Valo5e3dd152013-06-12 20:52:10 +03005618 ret = 0;
5619exit:
5620 mutex_unlock(&ar->conf_mutex);
5621 return ret;
5622}
5623
5624static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
5625{
5626 struct ath10k *ar = hw->priv;
5627
5628 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005629 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005630 mutex_unlock(&ar->conf_mutex);
5631
Michal Kazior4eb2e162014-10-28 10:23:09 +01005632 cancel_delayed_work_sync(&ar->scan.timeout);
5633
Kalle Valo5e3dd152013-06-12 20:52:10 +03005634 return 0;
5635}
5636
5637/*
5638 * Both RTS and Fragmentation threshold are interface-specific
5639 * in ath10k, but device-specific in mac80211.
5640 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03005641
5642static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
5643{
Kalle Valo5e3dd152013-06-12 20:52:10 +03005644 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03005645 struct ath10k_vif *arvif;
5646 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03005647
Michal Kaziorad088bf2013-10-16 15:44:46 +03005648 mutex_lock(&ar->conf_mutex);
5649 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005650 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03005651 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03005652
Michal Kaziorad088bf2013-10-16 15:44:46 +03005653 ret = ath10k_mac_set_rts(arvif, value);
5654 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005655 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03005656 arvif->vdev_id, ret);
5657 break;
5658 }
5659 }
5660 mutex_unlock(&ar->conf_mutex);
5661
5662 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005663}
5664
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02005665static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5666 u32 queues, bool drop)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005667{
5668 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02005669 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005670 int ret;
5671
5672 /* mac80211 doesn't care if we really xmit queued frames or not
5673 * we'll collect those frames either way if we stop/delete vdevs */
5674 if (drop)
5675 return;
5676
Michal Kazior548db542013-07-05 16:15:15 +03005677 mutex_lock(&ar->conf_mutex);
5678
Michal Kazioraffd3212013-07-16 09:54:35 +02005679 if (ar->state == ATH10K_STATE_WEDGED)
5680 goto skip;
5681
Michal Kazioredb82362013-07-05 16:15:14 +03005682 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03005683 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02005684
Michal Kazioredb82362013-07-05 16:15:14 +03005685 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02005686 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03005687 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02005688
Michal Kazior7962b0d2014-10-28 10:34:38 +01005689 skip = (ar->state == ATH10K_STATE_WEDGED) ||
5690 test_bit(ATH10K_FLAG_CRASH_FLUSH,
5691 &ar->dev_flags);
Michal Kazioraffd3212013-07-16 09:54:35 +02005692
5693 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005694 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02005695
5696 if (ret <= 0 || skip)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005697 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
Ben Greear9ba4c782014-02-25 09:29:57 +02005698 skip, ar->state, ret);
Michal Kazior548db542013-07-05 16:15:15 +03005699
Michal Kazioraffd3212013-07-16 09:54:35 +02005700skip:
Michal Kazior548db542013-07-05 16:15:15 +03005701 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005702}
5703
5704/* TODO: Implement this function properly
5705 * For now it is needed to reply to Probe Requests in IBSS mode.
5706 * Propably we need this information from FW.
5707 */
5708static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
5709{
5710 return 1;
5711}
5712
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005713static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
5714 enum ieee80211_reconfig_type reconfig_type)
Michal Kazioraffd3212013-07-16 09:54:35 +02005715{
5716 struct ath10k *ar = hw->priv;
5717
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005718 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
5719 return;
5720
Michal Kazioraffd3212013-07-16 09:54:35 +02005721 mutex_lock(&ar->conf_mutex);
5722
5723 /* If device failed to restart it will be in a different state, e.g.
5724 * ATH10K_STATE_WEDGED */
5725 if (ar->state == ATH10K_STATE_RESTARTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005726 ath10k_info(ar, "device successfully recovered\n");
Michal Kazioraffd3212013-07-16 09:54:35 +02005727 ar->state = ATH10K_STATE_ON;
Michal Kazior7962b0d2014-10-28 10:34:38 +01005728 ieee80211_wake_queues(ar->hw);
Michal Kazioraffd3212013-07-16 09:54:35 +02005729 }
5730
5731 mutex_unlock(&ar->conf_mutex);
5732}
5733
Michal Kazior2e1dea42013-07-31 10:32:40 +02005734static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
5735 struct survey_info *survey)
5736{
5737 struct ath10k *ar = hw->priv;
5738 struct ieee80211_supported_band *sband;
5739 struct survey_info *ar_survey = &ar->survey[idx];
5740 int ret = 0;
5741
5742 mutex_lock(&ar->conf_mutex);
5743
5744 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
5745 if (sband && idx >= sband->n_channels) {
5746 idx -= sband->n_channels;
5747 sband = NULL;
5748 }
5749
5750 if (!sband)
5751 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
5752
5753 if (!sband || idx >= sband->n_channels) {
5754 ret = -ENOENT;
5755 goto exit;
5756 }
5757
5758 spin_lock_bh(&ar->data_lock);
5759 memcpy(survey, ar_survey, sizeof(*survey));
5760 spin_unlock_bh(&ar->data_lock);
5761
5762 survey->channel = &sband->channels[idx];
5763
Felix Fietkaufa1d4df2014-10-23 17:04:28 +03005764 if (ar->rx_channel == survey->channel)
5765 survey->filled |= SURVEY_INFO_IN_USE;
5766
Michal Kazior2e1dea42013-07-31 10:32:40 +02005767exit:
5768 mutex_unlock(&ar->conf_mutex);
5769 return ret;
5770}
5771
Michal Kazior3ae54222015-03-31 10:49:20 +00005772static bool
5773ath10k_mac_bitrate_mask_has_single_rate(struct ath10k *ar,
5774 enum ieee80211_band band,
5775 const struct cfg80211_bitrate_mask *mask)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005776{
Michal Kazior3ae54222015-03-31 10:49:20 +00005777 int num_rates = 0;
5778 int i;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005779
Michal Kazior3ae54222015-03-31 10:49:20 +00005780 num_rates += hweight32(mask->control[band].legacy);
5781
5782 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++)
5783 num_rates += hweight8(mask->control[band].ht_mcs[i]);
5784
5785 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++)
5786 num_rates += hweight16(mask->control[band].vht_mcs[i]);
5787
5788 return num_rates == 1;
5789}
5790
5791static bool
5792ath10k_mac_bitrate_mask_get_single_nss(struct ath10k *ar,
5793 enum ieee80211_band band,
5794 const struct cfg80211_bitrate_mask *mask,
5795 int *nss)
5796{
5797 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
5798 u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
5799 u8 ht_nss_mask = 0;
5800 u8 vht_nss_mask = 0;
5801 int i;
5802
5803 if (mask->control[band].legacy)
5804 return false;
5805
5806 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
5807 if (mask->control[band].ht_mcs[i] == 0)
5808 continue;
5809 else if (mask->control[band].ht_mcs[i] ==
5810 sband->ht_cap.mcs.rx_mask[i])
5811 ht_nss_mask |= BIT(i);
5812 else
5813 return false;
5814 }
5815
5816 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
5817 if (mask->control[band].vht_mcs[i] == 0)
5818 continue;
5819 else if (mask->control[band].vht_mcs[i] ==
5820 ath10k_mac_get_max_vht_mcs_map(vht_mcs_map, i))
5821 vht_nss_mask |= BIT(i);
5822 else
5823 return false;
5824 }
5825
5826 if (ht_nss_mask != vht_nss_mask)
5827 return false;
5828
5829 if (ht_nss_mask == 0)
5830 return false;
5831
5832 if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask)
5833 return false;
5834
5835 *nss = fls(ht_nss_mask);
5836
5837 return true;
5838}
5839
5840static int
5841ath10k_mac_bitrate_mask_get_single_rate(struct ath10k *ar,
5842 enum ieee80211_band band,
5843 const struct cfg80211_bitrate_mask *mask,
5844 u8 *rate, u8 *nss)
5845{
5846 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
5847 int rate_idx;
5848 int i;
5849 u16 bitrate;
5850 u8 preamble;
5851 u8 hw_rate;
5852
5853 if (hweight32(mask->control[band].legacy) == 1) {
5854 rate_idx = ffs(mask->control[band].legacy) - 1;
5855
5856 hw_rate = sband->bitrates[rate_idx].hw_value;
5857 bitrate = sband->bitrates[rate_idx].bitrate;
5858
5859 if (ath10k_mac_bitrate_is_cck(bitrate))
5860 preamble = WMI_RATE_PREAMBLE_CCK;
5861 else
5862 preamble = WMI_RATE_PREAMBLE_OFDM;
5863
5864 *nss = 1;
5865 *rate = preamble << 6 |
5866 (*nss - 1) << 4 |
5867 hw_rate << 0;
5868
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005869 return 0;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005870 }
5871
Michal Kazior3ae54222015-03-31 10:49:20 +00005872 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
5873 if (hweight8(mask->control[band].ht_mcs[i]) == 1) {
5874 *nss = i + 1;
5875 *rate = WMI_RATE_PREAMBLE_HT << 6 |
5876 (*nss - 1) << 4 |
5877 (ffs(mask->control[band].ht_mcs[i]) - 1);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005878
Michal Kazior3ae54222015-03-31 10:49:20 +00005879 return 0;
5880 }
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005881 }
5882
Michal Kazior3ae54222015-03-31 10:49:20 +00005883 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
5884 if (hweight16(mask->control[band].vht_mcs[i]) == 1) {
5885 *nss = i + 1;
5886 *rate = WMI_RATE_PREAMBLE_VHT << 6 |
5887 (*nss - 1) << 4 |
5888 (ffs(mask->control[band].vht_mcs[i]) - 1);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005889
Michal Kazior3ae54222015-03-31 10:49:20 +00005890 return 0;
5891 }
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005892 }
5893
Michal Kazior3ae54222015-03-31 10:49:20 +00005894 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005895}
5896
Michal Kazior3ae54222015-03-31 10:49:20 +00005897static int ath10k_mac_set_fixed_rate_params(struct ath10k_vif *arvif,
5898 u8 rate, u8 nss, u8 sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005899{
5900 struct ath10k *ar = arvif->ar;
5901 u32 vdev_param;
Michal Kazior3ae54222015-03-31 10:49:20 +00005902 int ret;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005903
Michal Kazior3ae54222015-03-31 10:49:20 +00005904 lockdep_assert_held(&ar->conf_mutex);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005905
Michal Kazior3ae54222015-03-31 10:49:20 +00005906 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac set fixed rate params vdev %i rate 0x%02hhx nss %hhu sgi %hhu\n",
5907 arvif->vdev_id, rate, nss, sgi);
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005908
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005909 vdev_param = ar->wmi.vdev_param->fixed_rate;
Michal Kazior3ae54222015-03-31 10:49:20 +00005910 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, rate);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005911 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005912 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
Michal Kazior3ae54222015-03-31 10:49:20 +00005913 rate, ret);
5914 return ret;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005915 }
5916
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005917 vdev_param = ar->wmi.vdev_param->nss;
Michal Kazior3ae54222015-03-31 10:49:20 +00005918 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, nss);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005919 if (ret) {
Michal Kazior3ae54222015-03-31 10:49:20 +00005920 ath10k_warn(ar, "failed to set nss param %d: %d\n", nss, ret);
5921 return ret;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005922 }
5923
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005924 vdev_param = ar->wmi.vdev_param->sgi;
Michal Kazior3ae54222015-03-31 10:49:20 +00005925 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, sgi);
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005926 if (ret) {
Michal Kazior3ae54222015-03-31 10:49:20 +00005927 ath10k_warn(ar, "failed to set sgi param %d: %d\n", sgi, ret);
5928 return ret;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005929 }
5930
Michal Kazior3ae54222015-03-31 10:49:20 +00005931 return 0;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005932}
5933
Michal Kazior45c9abc2015-04-21 20:42:58 +03005934static bool
5935ath10k_mac_can_set_bitrate_mask(struct ath10k *ar,
5936 enum ieee80211_band band,
5937 const struct cfg80211_bitrate_mask *mask)
5938{
5939 int i;
5940 u16 vht_mcs;
5941
5942 /* Due to firmware limitation in WMI_PEER_ASSOC_CMDID it is impossible
5943 * to express all VHT MCS rate masks. Effectively only the following
5944 * ranges can be used: none, 0-7, 0-8 and 0-9.
5945 */
5946 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
5947 vht_mcs = mask->control[band].vht_mcs[i];
5948
5949 switch (vht_mcs) {
5950 case 0:
5951 case BIT(8) - 1:
5952 case BIT(9) - 1:
5953 case BIT(10) - 1:
5954 break;
5955 default:
5956 ath10k_warn(ar, "refusing bitrate mask with missing 0-7 VHT MCS rates\n");
5957 return false;
5958 }
5959 }
5960
5961 return true;
5962}
5963
5964static void ath10k_mac_set_bitrate_mask_iter(void *data,
5965 struct ieee80211_sta *sta)
5966{
5967 struct ath10k_vif *arvif = data;
5968 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5969 struct ath10k *ar = arvif->ar;
5970
5971 if (arsta->arvif != arvif)
5972 return;
5973
5974 spin_lock_bh(&ar->data_lock);
5975 arsta->changed |= IEEE80211_RC_SUPP_RATES_CHANGED;
5976 spin_unlock_bh(&ar->data_lock);
5977
5978 ieee80211_queue_work(ar->hw, &arsta->update_wk);
5979}
5980
Michal Kazior3ae54222015-03-31 10:49:20 +00005981static int ath10k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw,
5982 struct ieee80211_vif *vif,
5983 const struct cfg80211_bitrate_mask *mask)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005984{
5985 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior500ff9f2015-03-31 10:26:21 +00005986 struct cfg80211_chan_def def;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005987 struct ath10k *ar = arvif->ar;
Michal Kazior500ff9f2015-03-31 10:26:21 +00005988 enum ieee80211_band band;
Michal Kazior45c9abc2015-04-21 20:42:58 +03005989 const u8 *ht_mcs_mask;
5990 const u16 *vht_mcs_mask;
Michal Kazior3ae54222015-03-31 10:49:20 +00005991 u8 rate;
5992 u8 nss;
5993 u8 sgi;
5994 int single_nss;
5995 int ret;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005996
Michal Kazior500ff9f2015-03-31 10:26:21 +00005997 if (ath10k_mac_vif_chan(vif, &def))
5998 return -EPERM;
5999
Michal Kazior500ff9f2015-03-31 10:26:21 +00006000 band = def.chan->band;
Michal Kazior45c9abc2015-04-21 20:42:58 +03006001 ht_mcs_mask = mask->control[band].ht_mcs;
6002 vht_mcs_mask = mask->control[band].vht_mcs;
Michal Kazior500ff9f2015-03-31 10:26:21 +00006003
Michal Kazior3ae54222015-03-31 10:49:20 +00006004 sgi = mask->control[band].gi;
6005 if (sgi == NL80211_TXRATE_FORCE_LGI)
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01006006 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01006007
Michal Kazior3ae54222015-03-31 10:49:20 +00006008 if (ath10k_mac_bitrate_mask_has_single_rate(ar, band, mask)) {
6009 ret = ath10k_mac_bitrate_mask_get_single_rate(ar, band, mask,
6010 &rate, &nss);
6011 if (ret) {
6012 ath10k_warn(ar, "failed to get single rate for vdev %i: %d\n",
6013 arvif->vdev_id, ret);
6014 return ret;
6015 }
6016 } else if (ath10k_mac_bitrate_mask_get_single_nss(ar, band, mask,
6017 &single_nss)) {
6018 rate = WMI_FIXED_RATE_NONE;
6019 nss = single_nss;
6020 } else {
6021 rate = WMI_FIXED_RATE_NONE;
Michal Kazior45c9abc2015-04-21 20:42:58 +03006022 nss = min(ar->num_rf_chains,
6023 max(ath10k_mac_max_ht_nss(ht_mcs_mask),
6024 ath10k_mac_max_vht_nss(vht_mcs_mask)));
6025
6026 if (!ath10k_mac_can_set_bitrate_mask(ar, band, mask))
6027 return -EINVAL;
6028
6029 mutex_lock(&ar->conf_mutex);
6030
6031 arvif->bitrate_mask = *mask;
6032 ieee80211_iterate_stations_atomic(ar->hw,
6033 ath10k_mac_set_bitrate_mask_iter,
6034 arvif);
6035
6036 mutex_unlock(&ar->conf_mutex);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01006037 }
6038
Michal Kazior3ae54222015-03-31 10:49:20 +00006039 mutex_lock(&ar->conf_mutex);
6040
6041 ret = ath10k_mac_set_fixed_rate_params(arvif, rate, nss, sgi);
6042 if (ret) {
6043 ath10k_warn(ar, "failed to set fixed rate params on vdev %i: %d\n",
6044 arvif->vdev_id, ret);
6045 goto exit;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01006046 }
6047
Michal Kazior3ae54222015-03-31 10:49:20 +00006048exit:
6049 mutex_unlock(&ar->conf_mutex);
6050
6051 return ret;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01006052}
6053
Michal Kazior9797feb2014-02-14 14:49:48 +01006054static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
6055 struct ieee80211_vif *vif,
6056 struct ieee80211_sta *sta,
6057 u32 changed)
6058{
6059 struct ath10k *ar = hw->priv;
6060 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
6061 u32 bw, smps;
6062
6063 spin_lock_bh(&ar->data_lock);
6064
Michal Kazior7aa7a722014-08-25 12:09:38 +02006065 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior9797feb2014-02-14 14:49:48 +01006066 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
6067 sta->addr, changed, sta->bandwidth, sta->rx_nss,
6068 sta->smps_mode);
6069
6070 if (changed & IEEE80211_RC_BW_CHANGED) {
6071 bw = WMI_PEER_CHWIDTH_20MHZ;
6072
6073 switch (sta->bandwidth) {
6074 case IEEE80211_STA_RX_BW_20:
6075 bw = WMI_PEER_CHWIDTH_20MHZ;
6076 break;
6077 case IEEE80211_STA_RX_BW_40:
6078 bw = WMI_PEER_CHWIDTH_40MHZ;
6079 break;
6080 case IEEE80211_STA_RX_BW_80:
6081 bw = WMI_PEER_CHWIDTH_80MHZ;
6082 break;
6083 case IEEE80211_STA_RX_BW_160:
Michal Kazior7aa7a722014-08-25 12:09:38 +02006084 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02006085 sta->bandwidth, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01006086 bw = WMI_PEER_CHWIDTH_20MHZ;
6087 break;
6088 }
6089
6090 arsta->bw = bw;
6091 }
6092
6093 if (changed & IEEE80211_RC_NSS_CHANGED)
6094 arsta->nss = sta->rx_nss;
6095
6096 if (changed & IEEE80211_RC_SMPS_CHANGED) {
6097 smps = WMI_PEER_SMPS_PS_NONE;
6098
6099 switch (sta->smps_mode) {
6100 case IEEE80211_SMPS_AUTOMATIC:
6101 case IEEE80211_SMPS_OFF:
6102 smps = WMI_PEER_SMPS_PS_NONE;
6103 break;
6104 case IEEE80211_SMPS_STATIC:
6105 smps = WMI_PEER_SMPS_STATIC;
6106 break;
6107 case IEEE80211_SMPS_DYNAMIC:
6108 smps = WMI_PEER_SMPS_DYNAMIC;
6109 break;
6110 case IEEE80211_SMPS_NUM_MODES:
Michal Kazior7aa7a722014-08-25 12:09:38 +02006111 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02006112 sta->smps_mode, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01006113 smps = WMI_PEER_SMPS_PS_NONE;
6114 break;
6115 }
6116
6117 arsta->smps = smps;
6118 }
6119
Michal Kazior9797feb2014-02-14 14:49:48 +01006120 arsta->changed |= changed;
6121
6122 spin_unlock_bh(&ar->data_lock);
6123
6124 ieee80211_queue_work(hw, &arsta->update_wk);
6125}
6126
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02006127static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
6128{
6129 /*
6130 * FIXME: Return 0 for time being. Need to figure out whether FW
6131 * has the API to fetch 64-bit local TSF
6132 */
6133
6134 return 0;
6135}
6136
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02006137static int ath10k_ampdu_action(struct ieee80211_hw *hw,
6138 struct ieee80211_vif *vif,
6139 enum ieee80211_ampdu_mlme_action action,
6140 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
6141 u8 buf_size)
6142{
Michal Kazior7aa7a722014-08-25 12:09:38 +02006143 struct ath10k *ar = hw->priv;
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02006144 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6145
Michal Kazior7aa7a722014-08-25 12:09:38 +02006146 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 +02006147 arvif->vdev_id, sta->addr, tid, action);
6148
6149 switch (action) {
6150 case IEEE80211_AMPDU_RX_START:
6151 case IEEE80211_AMPDU_RX_STOP:
6152 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
6153 * creation/removal. Do we need to verify this?
6154 */
6155 return 0;
6156 case IEEE80211_AMPDU_TX_START:
6157 case IEEE80211_AMPDU_TX_STOP_CONT:
6158 case IEEE80211_AMPDU_TX_STOP_FLUSH:
6159 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
6160 case IEEE80211_AMPDU_TX_OPERATIONAL:
6161 /* Firmware offloads Tx aggregation entirely so deny mac80211
6162 * Tx aggregation requests.
6163 */
6164 return -EOPNOTSUPP;
6165 }
6166
6167 return -EINVAL;
6168}
6169
Michal Kazior500ff9f2015-03-31 10:26:21 +00006170static void
6171ath10k_mac_update_rx_channel(struct ath10k *ar)
6172{
6173 struct cfg80211_chan_def *def = NULL;
6174
6175 /* Both locks are required because ar->rx_channel is modified. This
6176 * allows readers to hold either lock.
6177 */
6178 lockdep_assert_held(&ar->conf_mutex);
6179 lockdep_assert_held(&ar->data_lock);
6180
6181 /* FIXME: Sort of an optimization and a workaround. Peers and vifs are
6182 * on a linked list now. Doing a lookup peer -> vif -> chanctx for each
6183 * ppdu on Rx may reduce performance on low-end systems. It should be
6184 * possible to make tables/hashmaps to speed the lookup up (be vary of
6185 * cpu data cache lines though regarding sizes) but to keep the initial
6186 * implementation simple and less intrusive fallback to the slow lookup
6187 * only for multi-channel cases. Single-channel cases will remain to
6188 * use the old channel derival and thus performance should not be
6189 * affected much.
6190 */
6191 rcu_read_lock();
6192 if (ath10k_mac_num_chanctxs(ar) == 1) {
6193 ieee80211_iter_chan_contexts_atomic(ar->hw,
6194 ath10k_mac_get_any_chandef_iter,
6195 &def);
6196 ar->rx_channel = def->chan;
6197 } else {
6198 ar->rx_channel = NULL;
6199 }
6200 rcu_read_unlock();
6201}
6202
6203static void
6204ath10k_mac_chan_ctx_init(struct ath10k *ar,
6205 struct ath10k_chanctx *arctx,
6206 struct ieee80211_chanctx_conf *conf)
6207{
6208 lockdep_assert_held(&ar->conf_mutex);
6209 lockdep_assert_held(&ar->data_lock);
6210
6211 memset(arctx, 0, sizeof(*arctx));
6212
6213 arctx->conf = *conf;
6214}
6215
6216static int
6217ath10k_mac_op_add_chanctx(struct ieee80211_hw *hw,
6218 struct ieee80211_chanctx_conf *ctx)
6219{
6220 struct ath10k *ar = hw->priv;
6221 struct ath10k_chanctx *arctx = (void *)ctx->drv_priv;
6222
6223 ath10k_dbg(ar, ATH10K_DBG_MAC,
6224 "mac chanctx add freq %hu width %d ptr %p\n",
6225 ctx->def.chan->center_freq, ctx->def.width, ctx);
6226
6227 mutex_lock(&ar->conf_mutex);
6228
6229 spin_lock_bh(&ar->data_lock);
6230 ath10k_mac_chan_ctx_init(ar, arctx, ctx);
6231 ath10k_mac_update_rx_channel(ar);
6232 spin_unlock_bh(&ar->data_lock);
6233
6234 ath10k_recalc_radar_detection(ar);
6235 ath10k_monitor_recalc(ar);
6236
6237 mutex_unlock(&ar->conf_mutex);
6238
6239 return 0;
6240}
6241
6242static void
6243ath10k_mac_op_remove_chanctx(struct ieee80211_hw *hw,
6244 struct ieee80211_chanctx_conf *ctx)
6245{
6246 struct ath10k *ar = hw->priv;
6247
6248 ath10k_dbg(ar, ATH10K_DBG_MAC,
6249 "mac chanctx remove freq %hu width %d ptr %p\n",
6250 ctx->def.chan->center_freq, ctx->def.width, ctx);
6251
6252 mutex_lock(&ar->conf_mutex);
6253
6254 spin_lock_bh(&ar->data_lock);
6255 ath10k_mac_update_rx_channel(ar);
6256 spin_unlock_bh(&ar->data_lock);
6257
6258 ath10k_recalc_radar_detection(ar);
6259 ath10k_monitor_recalc(ar);
6260
6261 mutex_unlock(&ar->conf_mutex);
6262}
6263
6264static void
6265ath10k_mac_op_change_chanctx(struct ieee80211_hw *hw,
6266 struct ieee80211_chanctx_conf *ctx,
6267 u32 changed)
6268{
6269 struct ath10k *ar = hw->priv;
6270 struct ath10k_chanctx *arctx = (void *)ctx->drv_priv;
6271
6272 mutex_lock(&ar->conf_mutex);
6273
6274 ath10k_dbg(ar, ATH10K_DBG_MAC,
6275 "mac chanctx change freq %hu->%hu width %d->%d ptr %p changed %x\n",
6276 arctx->conf.def.chan->center_freq,
6277 ctx->def.chan->center_freq,
6278 arctx->conf.def.width, ctx->def.width,
6279 ctx, changed);
6280
6281 /* This shouldn't really happen because channel switching should use
6282 * switch_vif_chanctx().
6283 */
6284 if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL))
6285 goto unlock;
6286
6287 spin_lock_bh(&ar->data_lock);
6288 arctx->conf = *ctx;
6289 spin_unlock_bh(&ar->data_lock);
6290
6291 ath10k_recalc_radar_detection(ar);
6292
6293 /* FIXME: How to configure Rx chains properly? */
6294
6295 /* No other actions are actually necessary. Firmware maintains channel
6296 * definitions per vdev internally and there's no host-side channel
6297 * context abstraction to configure, e.g. channel width.
6298 */
6299
6300unlock:
6301 mutex_unlock(&ar->conf_mutex);
6302}
6303
6304static int
6305ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
6306 struct ieee80211_vif *vif,
6307 struct ieee80211_chanctx_conf *ctx)
6308{
6309 struct ath10k *ar = hw->priv;
6310 struct ath10k_chanctx *arctx = (void *)ctx->drv_priv;
6311 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6312 int ret;
6313
6314 mutex_lock(&ar->conf_mutex);
6315
6316 ath10k_dbg(ar, ATH10K_DBG_MAC,
6317 "mac chanctx assign ptr %p vdev_id %i\n",
6318 ctx, arvif->vdev_id);
6319
6320 if (WARN_ON(arvif->is_started)) {
6321 mutex_unlock(&ar->conf_mutex);
6322 return -EBUSY;
6323 }
6324
6325 ret = ath10k_vdev_start(arvif, &arctx->conf.def);
6326 if (ret) {
6327 ath10k_warn(ar, "failed to start vdev %i addr %pM on freq %d: %d\n",
6328 arvif->vdev_id, vif->addr,
6329 arctx->conf.def.chan->center_freq, ret);
6330 goto err;
6331 }
6332
6333 arvif->is_started = true;
6334
6335 if (vif->type == NL80211_IFTYPE_MONITOR) {
6336 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, 0, vif->addr);
6337 if (ret) {
6338 ath10k_warn(ar, "failed to up monitor vdev %i: %d\n",
6339 arvif->vdev_id, ret);
6340 goto err_stop;
6341 }
6342
6343 arvif->is_up = true;
6344 }
6345
6346 mutex_unlock(&ar->conf_mutex);
6347 return 0;
6348
6349err_stop:
6350 ath10k_vdev_stop(arvif);
6351 arvif->is_started = false;
6352
6353err:
6354 mutex_unlock(&ar->conf_mutex);
6355 return ret;
6356}
6357
6358static void
6359ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
6360 struct ieee80211_vif *vif,
6361 struct ieee80211_chanctx_conf *ctx)
6362{
6363 struct ath10k *ar = hw->priv;
6364 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6365 int ret;
6366
6367 mutex_lock(&ar->conf_mutex);
6368
6369 ath10k_dbg(ar, ATH10K_DBG_MAC,
6370 "mac chanctx unassign ptr %p vdev_id %i\n",
6371 ctx, arvif->vdev_id);
6372
6373 WARN_ON(!arvif->is_started);
6374
6375 if (vif->type == NL80211_IFTYPE_MONITOR) {
6376 WARN_ON(!arvif->is_up);
6377
6378 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
6379 if (ret)
6380 ath10k_warn(ar, "failed to down monitor vdev %i: %d\n",
6381 arvif->vdev_id, ret);
6382
6383 arvif->is_up = false;
6384 }
6385
6386 ret = ath10k_vdev_stop(arvif);
6387 if (ret)
6388 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
6389 arvif->vdev_id, ret);
6390
6391 arvif->is_started = false;
6392
6393 mutex_unlock(&ar->conf_mutex);
6394}
6395
6396static int
6397ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw,
6398 struct ieee80211_vif_chanctx_switch *vifs,
6399 int n_vifs,
6400 enum ieee80211_chanctx_switch_mode mode)
6401{
6402 struct ath10k *ar = hw->priv;
6403 struct ath10k_vif *arvif;
6404 struct ath10k_chanctx *arctx_new, *arctx_old;
6405 int i;
6406
6407 mutex_lock(&ar->conf_mutex);
6408
6409 ath10k_dbg(ar, ATH10K_DBG_MAC,
6410 "mac chanctx switch n_vifs %d mode %d\n",
6411 n_vifs, mode);
6412
6413 spin_lock_bh(&ar->data_lock);
6414 for (i = 0; i < n_vifs; i++) {
6415 arvif = ath10k_vif_to_arvif(vifs[i].vif);
6416 arctx_new = (void *)vifs[i].new_ctx->drv_priv;
6417 arctx_old = (void *)vifs[i].old_ctx->drv_priv;
6418
6419 ath10k_dbg(ar, ATH10K_DBG_MAC,
6420 "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d ptr %p->%p\n",
6421 arvif->vdev_id,
6422 vifs[i].old_ctx->def.chan->center_freq,
6423 vifs[i].new_ctx->def.chan->center_freq,
6424 vifs[i].old_ctx->def.width,
6425 vifs[i].new_ctx->def.width,
6426 arctx_old, arctx_new);
6427
6428 if (mode == CHANCTX_SWMODE_SWAP_CONTEXTS) {
6429 ath10k_mac_chan_ctx_init(ar, arctx_new,
6430 vifs[i].new_ctx);
6431 }
6432
6433 arctx_new->conf = *vifs[i].new_ctx;
6434
6435 /* FIXME: ath10k_mac_chan_reconfigure() uses current, i.e. not
6436 * yet updated chanctx_conf pointer.
6437 */
6438 arctx_old->conf = *vifs[i].new_ctx;
6439 }
6440 ath10k_mac_update_rx_channel(ar);
6441 spin_unlock_bh(&ar->data_lock);
6442
6443 /* FIXME: Reconfigure only affected vifs */
6444 ath10k_mac_chan_reconfigure(ar);
6445
6446 mutex_unlock(&ar->conf_mutex);
6447 return 0;
6448}
6449
Kalle Valo5e3dd152013-06-12 20:52:10 +03006450static const struct ieee80211_ops ath10k_ops = {
6451 .tx = ath10k_tx,
6452 .start = ath10k_start,
6453 .stop = ath10k_stop,
6454 .config = ath10k_config,
6455 .add_interface = ath10k_add_interface,
6456 .remove_interface = ath10k_remove_interface,
6457 .configure_filter = ath10k_configure_filter,
6458 .bss_info_changed = ath10k_bss_info_changed,
6459 .hw_scan = ath10k_hw_scan,
6460 .cancel_hw_scan = ath10k_cancel_hw_scan,
6461 .set_key = ath10k_set_key,
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02006462 .set_default_unicast_key = ath10k_set_default_unicast_key,
Kalle Valo5e3dd152013-06-12 20:52:10 +03006463 .sta_state = ath10k_sta_state,
6464 .conf_tx = ath10k_conf_tx,
6465 .remain_on_channel = ath10k_remain_on_channel,
6466 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
6467 .set_rts_threshold = ath10k_set_rts_threshold,
Kalle Valo5e3dd152013-06-12 20:52:10 +03006468 .flush = ath10k_flush,
6469 .tx_last_beacon = ath10k_tx_last_beacon,
Ben Greear46acf7b2014-05-16 17:15:38 +03006470 .set_antenna = ath10k_set_antenna,
6471 .get_antenna = ath10k_get_antenna,
Eliad Pellercf2c92d2014-11-04 11:43:54 +02006472 .reconfig_complete = ath10k_reconfig_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02006473 .get_survey = ath10k_get_survey,
Michal Kazior3ae54222015-03-31 10:49:20 +00006474 .set_bitrate_mask = ath10k_mac_op_set_bitrate_mask,
Michal Kazior9797feb2014-02-14 14:49:48 +01006475 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02006476 .get_tsf = ath10k_get_tsf,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02006477 .ampdu_action = ath10k_ampdu_action,
Ben Greear6cddcc72014-09-29 14:41:46 +03006478 .get_et_sset_count = ath10k_debug_get_et_sset_count,
6479 .get_et_stats = ath10k_debug_get_et_stats,
6480 .get_et_strings = ath10k_debug_get_et_strings,
Michal Kazior500ff9f2015-03-31 10:26:21 +00006481 .add_chanctx = ath10k_mac_op_add_chanctx,
6482 .remove_chanctx = ath10k_mac_op_remove_chanctx,
6483 .change_chanctx = ath10k_mac_op_change_chanctx,
6484 .assign_vif_chanctx = ath10k_mac_op_assign_vif_chanctx,
6485 .unassign_vif_chanctx = ath10k_mac_op_unassign_vif_chanctx,
6486 .switch_vif_chanctx = ath10k_mac_op_switch_vif_chanctx,
Kalle Valo43d2a302014-09-10 18:23:30 +03006487
6488 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
6489
Michal Kazior8cd13ca2013-07-16 09:38:54 +02006490#ifdef CONFIG_PM
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +02006491 .suspend = ath10k_wow_op_suspend,
6492 .resume = ath10k_wow_op_resume,
Michal Kazior8cd13ca2013-07-16 09:38:54 +02006493#endif
Rajkumar Manoharanf5045982015-01-12 14:07:27 +02006494#ifdef CONFIG_MAC80211_DEBUGFS
6495 .sta_add_debugfs = ath10k_sta_add_debugfs,
6496#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03006497};
6498
Kalle Valo5e3dd152013-06-12 20:52:10 +03006499#define CHAN2G(_channel, _freq, _flags) { \
6500 .band = IEEE80211_BAND_2GHZ, \
6501 .hw_value = (_channel), \
6502 .center_freq = (_freq), \
6503 .flags = (_flags), \
6504 .max_antenna_gain = 0, \
6505 .max_power = 30, \
6506}
6507
6508#define CHAN5G(_channel, _freq, _flags) { \
6509 .band = IEEE80211_BAND_5GHZ, \
6510 .hw_value = (_channel), \
6511 .center_freq = (_freq), \
6512 .flags = (_flags), \
6513 .max_antenna_gain = 0, \
6514 .max_power = 30, \
6515}
6516
6517static const struct ieee80211_channel ath10k_2ghz_channels[] = {
6518 CHAN2G(1, 2412, 0),
6519 CHAN2G(2, 2417, 0),
6520 CHAN2G(3, 2422, 0),
6521 CHAN2G(4, 2427, 0),
6522 CHAN2G(5, 2432, 0),
6523 CHAN2G(6, 2437, 0),
6524 CHAN2G(7, 2442, 0),
6525 CHAN2G(8, 2447, 0),
6526 CHAN2G(9, 2452, 0),
6527 CHAN2G(10, 2457, 0),
6528 CHAN2G(11, 2462, 0),
6529 CHAN2G(12, 2467, 0),
6530 CHAN2G(13, 2472, 0),
6531 CHAN2G(14, 2484, 0),
6532};
6533
6534static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02006535 CHAN5G(36, 5180, 0),
6536 CHAN5G(40, 5200, 0),
6537 CHAN5G(44, 5220, 0),
6538 CHAN5G(48, 5240, 0),
6539 CHAN5G(52, 5260, 0),
6540 CHAN5G(56, 5280, 0),
6541 CHAN5G(60, 5300, 0),
6542 CHAN5G(64, 5320, 0),
6543 CHAN5G(100, 5500, 0),
6544 CHAN5G(104, 5520, 0),
6545 CHAN5G(108, 5540, 0),
6546 CHAN5G(112, 5560, 0),
6547 CHAN5G(116, 5580, 0),
6548 CHAN5G(120, 5600, 0),
6549 CHAN5G(124, 5620, 0),
6550 CHAN5G(128, 5640, 0),
6551 CHAN5G(132, 5660, 0),
6552 CHAN5G(136, 5680, 0),
6553 CHAN5G(140, 5700, 0),
Peter Oh4a7898f2015-03-18 11:39:18 -07006554 CHAN5G(144, 5720, 0),
Michal Kazior429ff562013-06-26 08:54:54 +02006555 CHAN5G(149, 5745, 0),
6556 CHAN5G(153, 5765, 0),
6557 CHAN5G(157, 5785, 0),
6558 CHAN5G(161, 5805, 0),
6559 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03006560};
6561
Michal Kaziore7b54192014-08-07 11:03:27 +02006562struct ath10k *ath10k_mac_create(size_t priv_size)
Kalle Valo5e3dd152013-06-12 20:52:10 +03006563{
6564 struct ieee80211_hw *hw;
6565 struct ath10k *ar;
6566
Michal Kaziore7b54192014-08-07 11:03:27 +02006567 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006568 if (!hw)
6569 return NULL;
6570
6571 ar = hw->priv;
6572 ar->hw = hw;
6573
6574 return ar;
6575}
6576
6577void ath10k_mac_destroy(struct ath10k *ar)
6578{
6579 ieee80211_free_hw(ar->hw);
6580}
6581
6582static const struct ieee80211_iface_limit ath10k_if_limits[] = {
6583 {
6584 .max = 8,
6585 .types = BIT(NL80211_IFTYPE_STATION)
6586 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02006587 },
6588 {
6589 .max = 3,
6590 .types = BIT(NL80211_IFTYPE_P2P_GO)
6591 },
6592 {
Michal Kazior75d2bd42014-12-12 12:41:39 +01006593 .max = 1,
6594 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
6595 },
6596 {
Michal Kaziord531cb82013-07-31 10:55:13 +02006597 .max = 7,
6598 .types = BIT(NL80211_IFTYPE_AP)
6599 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03006600};
6601
Bartosz Markowskif2595092013-12-10 16:20:39 +01006602static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006603 {
6604 .max = 8,
6605 .types = BIT(NL80211_IFTYPE_AP)
6606 },
6607};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006608
6609static const struct ieee80211_iface_combination ath10k_if_comb[] = {
6610 {
6611 .limits = ath10k_if_limits,
6612 .n_limits = ARRAY_SIZE(ath10k_if_limits),
6613 .max_interfaces = 8,
6614 .num_different_channels = 1,
6615 .beacon_int_infra_match = true,
6616 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01006617};
6618
6619static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006620 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01006621 .limits = ath10k_10x_if_limits,
6622 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006623 .max_interfaces = 8,
6624 .num_different_channels = 1,
6625 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01006626#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006627 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
6628 BIT(NL80211_CHAN_WIDTH_20) |
6629 BIT(NL80211_CHAN_WIDTH_40) |
6630 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006631#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01006632 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03006633};
6634
Michal Kaziorcf327842015-03-31 10:26:25 +00006635static const struct ieee80211_iface_limit ath10k_tlv_if_limit[] = {
6636 {
6637 .max = 2,
6638 .types = BIT(NL80211_IFTYPE_STATION) |
6639 BIT(NL80211_IFTYPE_AP) |
6640 BIT(NL80211_IFTYPE_P2P_CLIENT) |
6641 BIT(NL80211_IFTYPE_P2P_GO),
6642 },
6643 {
6644 .max = 1,
6645 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
6646 },
6647};
6648
6649static const struct ieee80211_iface_limit ath10k_tlv_if_limit_ibss[] = {
6650 {
6651 .max = 1,
6652 .types = BIT(NL80211_IFTYPE_STATION),
6653 },
6654 {
6655 .max = 1,
6656 .types = BIT(NL80211_IFTYPE_ADHOC),
6657 },
6658};
6659
6660/* FIXME: This is not thouroughly tested. These combinations may over- or
6661 * underestimate hw/fw capabilities.
6662 */
6663static struct ieee80211_iface_combination ath10k_tlv_if_comb[] = {
6664 {
6665 .limits = ath10k_tlv_if_limit,
6666 .num_different_channels = 1,
6667 .max_interfaces = 3,
6668 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
6669 },
6670 {
6671 .limits = ath10k_tlv_if_limit_ibss,
6672 .num_different_channels = 1,
6673 .max_interfaces = 2,
6674 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
6675 },
6676};
6677
6678static struct ieee80211_iface_combination ath10k_tlv_qcs_if_comb[] = {
6679 {
6680 .limits = ath10k_tlv_if_limit,
6681 .num_different_channels = 2,
6682 .max_interfaces = 3,
6683 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
6684 },
6685 {
6686 .limits = ath10k_tlv_if_limit_ibss,
6687 .num_different_channels = 1,
6688 .max_interfaces = 2,
6689 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
6690 },
6691};
6692
Kalle Valo5e3dd152013-06-12 20:52:10 +03006693static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
6694{
6695 struct ieee80211_sta_vht_cap vht_cap = {0};
6696 u16 mcs_map;
Michal Kaziorbc657a362015-02-26 11:11:22 +01006697 u32 val;
Michal Kazior8865bee42013-07-24 12:36:46 +02006698 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006699
6700 vht_cap.vht_supported = 1;
6701 vht_cap.cap = ar->vht_cap_info;
6702
Michal Kaziorbc657a362015-02-26 11:11:22 +01006703 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
6704 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
6705 val = ar->num_rf_chains - 1;
6706 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
6707 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
6708
6709 vht_cap.cap |= val;
6710 }
6711
6712 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
6713 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
6714 val = ar->num_rf_chains - 1;
6715 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
6716 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
6717
6718 vht_cap.cap |= val;
6719 }
6720
Michal Kazior8865bee42013-07-24 12:36:46 +02006721 mcs_map = 0;
6722 for (i = 0; i < 8; i++) {
6723 if (i < ar->num_rf_chains)
6724 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
6725 else
6726 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
6727 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03006728
6729 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
6730 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
6731
6732 return vht_cap;
6733}
6734
6735static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
6736{
6737 int i;
6738 struct ieee80211_sta_ht_cap ht_cap = {0};
6739
6740 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
6741 return ht_cap;
6742
6743 ht_cap.ht_supported = 1;
6744 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
6745 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
6746 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
6747 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
6748 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
6749
6750 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
6751 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
6752
6753 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
6754 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
6755
6756 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
6757 u32 smps;
6758
6759 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
6760 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
6761
6762 ht_cap.cap |= smps;
6763 }
6764
6765 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
6766 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
6767
6768 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
6769 u32 stbc;
6770
6771 stbc = ar->ht_cap_info;
6772 stbc &= WMI_HT_CAP_RX_STBC;
6773 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
6774 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
6775 stbc &= IEEE80211_HT_CAP_RX_STBC;
6776
6777 ht_cap.cap |= stbc;
6778 }
6779
6780 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
6781 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
6782
6783 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
6784 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
6785
6786 /* max AMSDU is implicitly taken from vht_cap_info */
6787 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
6788 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
6789
Michal Kazior8865bee42013-07-24 12:36:46 +02006790 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03006791 ht_cap.mcs.rx_mask[i] = 0xFF;
6792
6793 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
6794
6795 return ht_cap;
6796}
6797
Kalle Valo5e3dd152013-06-12 20:52:10 +03006798static void ath10k_get_arvif_iter(void *data, u8 *mac,
6799 struct ieee80211_vif *vif)
6800{
6801 struct ath10k_vif_iter *arvif_iter = data;
6802 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6803
6804 if (arvif->vdev_id == arvif_iter->vdev_id)
6805 arvif_iter->arvif = arvif;
6806}
6807
6808struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
6809{
6810 struct ath10k_vif_iter arvif_iter;
6811 u32 flags;
6812
6813 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
6814 arvif_iter.vdev_id = vdev_id;
6815
6816 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
6817 ieee80211_iterate_active_interfaces_atomic(ar->hw,
6818 flags,
6819 ath10k_get_arvif_iter,
6820 &arvif_iter);
6821 if (!arvif_iter.arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02006822 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006823 return NULL;
6824 }
6825
6826 return arvif_iter.arvif;
6827}
6828
6829int ath10k_mac_register(struct ath10k *ar)
6830{
Johannes Berg3cb10942015-01-22 21:38:45 +01006831 static const u32 cipher_suites[] = {
6832 WLAN_CIPHER_SUITE_WEP40,
6833 WLAN_CIPHER_SUITE_WEP104,
6834 WLAN_CIPHER_SUITE_TKIP,
6835 WLAN_CIPHER_SUITE_CCMP,
6836 WLAN_CIPHER_SUITE_AES_CMAC,
6837 };
Kalle Valo5e3dd152013-06-12 20:52:10 +03006838 struct ieee80211_supported_band *band;
6839 struct ieee80211_sta_vht_cap vht_cap;
6840 struct ieee80211_sta_ht_cap ht_cap;
6841 void *channels;
6842 int ret;
6843
6844 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
6845
6846 SET_IEEE80211_DEV(ar->hw, ar->dev);
6847
6848 ht_cap = ath10k_get_ht_cap(ar);
6849 vht_cap = ath10k_create_vht_cap(ar);
6850
Michal Kaziorc94aa7e2015-03-24 12:38:11 +00006851 BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels) +
6852 ARRAY_SIZE(ath10k_5ghz_channels)) !=
6853 ATH10K_NUM_CHANS);
6854
Kalle Valo5e3dd152013-06-12 20:52:10 +03006855 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
6856 channels = kmemdup(ath10k_2ghz_channels,
6857 sizeof(ath10k_2ghz_channels),
6858 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02006859 if (!channels) {
6860 ret = -ENOMEM;
6861 goto err_free;
6862 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03006863
6864 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
6865 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
6866 band->channels = channels;
6867 band->n_bitrates = ath10k_g_rates_size;
6868 band->bitrates = ath10k_g_rates;
6869 band->ht_cap = ht_cap;
6870
Yanbo Lid68bb122015-01-23 08:18:20 +08006871 /* Enable the VHT support at 2.4 GHz */
6872 band->vht_cap = vht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006873
6874 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
6875 }
6876
6877 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
6878 channels = kmemdup(ath10k_5ghz_channels,
6879 sizeof(ath10k_5ghz_channels),
6880 GFP_KERNEL);
6881 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02006882 ret = -ENOMEM;
6883 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006884 }
6885
6886 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
6887 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
6888 band->channels = channels;
6889 band->n_bitrates = ath10k_a_rates_size;
6890 band->bitrates = ath10k_a_rates;
6891 band->ht_cap = ht_cap;
6892 band->vht_cap = vht_cap;
6893 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
6894 }
6895
6896 ar->hw->wiphy->interface_modes =
6897 BIT(NL80211_IFTYPE_STATION) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01006898 BIT(NL80211_IFTYPE_AP);
6899
Ben Greear46acf7b2014-05-16 17:15:38 +03006900 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
6901 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
6902
Bartosz Markowskid3541812013-12-10 16:20:40 +01006903 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
6904 ar->hw->wiphy->interface_modes |=
Michal Kazior75d2bd42014-12-12 12:41:39 +01006905 BIT(NL80211_IFTYPE_P2P_DEVICE) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01006906 BIT(NL80211_IFTYPE_P2P_CLIENT) |
6907 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006908
6909 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
6910 IEEE80211_HW_SUPPORTS_PS |
6911 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
Kalle Valo5e3dd152013-06-12 20:52:10 +03006912 IEEE80211_HW_MFP_CAPABLE |
6913 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
6914 IEEE80211_HW_HAS_RATE_CONTROL |
Janusz Dziedzic2f0f1122014-02-26 18:42:09 +02006915 IEEE80211_HW_AP_LINK_PS |
Johannes Berg3cb10942015-01-22 21:38:45 +01006916 IEEE80211_HW_SPECTRUM_MGMT |
Michal Kaziorcc9904e2015-03-10 16:22:01 +02006917 IEEE80211_HW_SW_CRYPTO_CONTROL |
Michal Kazior500ff9f2015-03-31 10:26:21 +00006918 IEEE80211_HW_CONNECTION_MONITOR |
Janusz Dziedzic0cd9bc12015-04-10 13:23:23 +00006919 IEEE80211_HW_SUPPORTS_PER_STA_GTK |
Michal Kazior500ff9f2015-03-31 10:26:21 +00006920 IEEE80211_HW_WANT_MONITOR_VIF |
Michal Kazior96d828d2015-03-31 10:26:23 +00006921 IEEE80211_HW_CHANCTX_STA_CSA |
6922 IEEE80211_HW_QUEUE_CONTROL;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006923
Eliad Peller0d8614b2014-09-10 14:07:36 +03006924 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
Janusz Dziedzic0cd9bc12015-04-10 13:23:23 +00006925 ar->hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
Eliad Peller0d8614b2014-09-10 14:07:36 +03006926
Kalle Valo5e3dd152013-06-12 20:52:10 +03006927 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
Eliad Peller0d8614b2014-09-10 14:07:36 +03006928 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006929
6930 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
6931 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
6932 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
6933 }
6934
6935 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
6936 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
6937
6938 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01006939 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006940 ar->hw->chanctx_data_size = sizeof(struct ath10k_chanctx);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006941
Kalle Valo5e3dd152013-06-12 20:52:10 +03006942 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
6943
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02006944 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
6945 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
6946
6947 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
6948 * that userspace (e.g. wpa_supplicant/hostapd) can generate
6949 * correct Probe Responses. This is more of a hack advert..
6950 */
6951 ar->hw->wiphy->probe_resp_offload |=
6952 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
6953 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
6954 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
6955 }
6956
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03006957 if (test_bit(WMI_SERVICE_TDLS, ar->wmi.svc_map))
6958 ar->hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
6959
Kalle Valo5e3dd152013-06-12 20:52:10 +03006960 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01006961 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006962 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
6963
6964 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
Rajkumar Manoharan78157a12014-11-17 16:44:15 +02006965 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
6966
Janusz.Dziedzic@tieto.com37a0b392015-03-12 13:11:41 +01006967 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
6968
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +02006969 ret = ath10k_wow_init(ar);
6970 if (ret) {
6971 ath10k_warn(ar, "failed to init wow: %d\n", ret);
6972 goto err_free;
6973 }
6974
Kalle Valo5e3dd152013-06-12 20:52:10 +03006975 /*
6976 * on LL hardware queues are managed entirely by the FW
6977 * so we only advertise to mac we can do the queues thing
6978 */
Michal Kazior96d828d2015-03-31 10:26:23 +00006979 ar->hw->queues = IEEE80211_MAX_QUEUES;
6980
6981 /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is
6982 * something that vdev_ids can't reach so that we don't stop the queue
6983 * accidentally.
6984 */
6985 ar->hw->offchannel_tx_hw_queue = IEEE80211_MAX_QUEUES - 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006986
Kalle Valo5cc7caf2014-12-17 12:20:54 +02006987 switch (ar->wmi.op_version) {
6988 case ATH10K_FW_WMI_OP_VERSION_MAIN:
Bartosz Markowskif2595092013-12-10 16:20:39 +01006989 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
6990 ar->hw->wiphy->n_iface_combinations =
6991 ARRAY_SIZE(ath10k_if_comb);
Michal Kaziorcf850d12014-07-24 20:07:00 +03006992 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
Kalle Valo5cc7caf2014-12-17 12:20:54 +02006993 break;
Michal Kaziorcf327842015-03-31 10:26:25 +00006994 case ATH10K_FW_WMI_OP_VERSION_TLV:
6995 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
6996 ar->hw->wiphy->iface_combinations =
6997 ath10k_tlv_qcs_if_comb;
6998 ar->hw->wiphy->n_iface_combinations =
6999 ARRAY_SIZE(ath10k_tlv_qcs_if_comb);
7000 } else {
7001 ar->hw->wiphy->iface_combinations = ath10k_tlv_if_comb;
7002 ar->hw->wiphy->n_iface_combinations =
7003 ARRAY_SIZE(ath10k_tlv_if_comb);
7004 }
7005 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
7006 break;
Kalle Valo5cc7caf2014-12-17 12:20:54 +02007007 case ATH10K_FW_WMI_OP_VERSION_10_1:
7008 case ATH10K_FW_WMI_OP_VERSION_10_2:
Rajkumar Manoharan4a16fbe2014-12-17 12:21:12 +02007009 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
Kalle Valo5cc7caf2014-12-17 12:20:54 +02007010 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
7011 ar->hw->wiphy->n_iface_combinations =
7012 ARRAY_SIZE(ath10k_10x_if_comb);
7013 break;
7014 case ATH10K_FW_WMI_OP_VERSION_UNSET:
7015 case ATH10K_FW_WMI_OP_VERSION_MAX:
7016 WARN_ON(1);
7017 ret = -EINVAL;
7018 goto err_free;
Bartosz Markowskif2595092013-12-10 16:20:39 +01007019 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03007020
Michal Kazior7c199992013-07-31 10:47:57 +02007021 ar->hw->netdev_features = NETIF_F_HW_CSUM;
7022
Janusz Dziedzic9702c682013-11-20 09:59:41 +02007023 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
7024 /* Init ath dfs pattern detector */
7025 ar->ath_common.debug_mask = ATH_DBG_DFS;
7026 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
7027 NL80211_DFS_UNSET);
7028
7029 if (!ar->dfs_detector)
Michal Kazior7aa7a722014-08-25 12:09:38 +02007030 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02007031 }
7032
Kalle Valo5e3dd152013-06-12 20:52:10 +03007033 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
7034 ath10k_reg_notifier);
7035 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02007036 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02007037 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03007038 }
7039
Johannes Berg3cb10942015-01-22 21:38:45 +01007040 ar->hw->wiphy->cipher_suites = cipher_suites;
7041 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
7042
Kalle Valo5e3dd152013-06-12 20:52:10 +03007043 ret = ieee80211_register_hw(ar->hw);
7044 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02007045 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02007046 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03007047 }
7048
7049 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
7050 ret = regulatory_hint(ar->hw->wiphy,
7051 ar->ath_common.regulatory.alpha2);
7052 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02007053 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03007054 }
7055
7056 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02007057
7058err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03007059 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02007060err_free:
7061 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
7062 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
7063
Kalle Valo5e3dd152013-06-12 20:52:10 +03007064 return ret;
7065}
7066
7067void ath10k_mac_unregister(struct ath10k *ar)
7068{
7069 ieee80211_unregister_hw(ar->hw);
7070
Janusz Dziedzic9702c682013-11-20 09:59:41 +02007071 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
7072 ar->dfs_detector->exit(ar->dfs_detector);
7073
Kalle Valo5e3dd152013-06-12 20:52:10 +03007074 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
7075 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
7076
7077 SET_IEEE80211_DEV(ar->hw, NULL);
7078}