blob: 49a54a1f07a891f34ae75c8553c36dc0144c5f08 [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}
Kalle Valo5e3dd152013-06-12 20:52:10 +0300156
157/**********/
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;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300256
257 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
Michal Kaziorce90b272015-04-10 13:23:21 +0000258 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;
Maninder Singh19be9e92015-07-16 09:25:33 +0530839 struct ieee80211_channel *channel = NULL;
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
Michal Kazior500ff9f2015-03-31 10:26:21 +00001034static bool ath10k_mac_monitor_vdev_is_needed(struct ath10k *ar)
1035{
1036 int num_ctx;
1037
1038 /* At least one chanctx is required to derive a channel to start
1039 * monitor vdev on.
1040 */
1041 num_ctx = ath10k_mac_num_chanctxs(ar);
1042 if (num_ctx == 0)
1043 return false;
1044
1045 /* If there's already an existing special monitor interface then don't
1046 * bother creating another monitor vdev.
1047 */
1048 if (ar->monitor_arvif)
1049 return false;
1050
1051 return ar->monitor ||
Michal Kazior500ff9f2015-03-31 10:26:21 +00001052 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1053}
1054
1055static bool ath10k_mac_monitor_vdev_is_allowed(struct ath10k *ar)
1056{
1057 int num_ctx;
1058
1059 num_ctx = ath10k_mac_num_chanctxs(ar);
1060
1061 /* FIXME: Current interface combinations and cfg80211/mac80211 code
1062 * shouldn't allow this but make sure to prevent handling the following
1063 * case anyway since multi-channel DFS hasn't been tested at all.
1064 */
1065 if (test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags) && num_ctx > 1)
1066 return false;
1067
1068 return true;
1069}
1070
Michal Kazior19337472014-08-28 12:58:16 +02001071static int ath10k_monitor_recalc(struct ath10k *ar)
1072{
Michal Kazior500ff9f2015-03-31 10:26:21 +00001073 bool needed;
1074 bool allowed;
1075 int ret;
Michal Kazior19337472014-08-28 12:58:16 +02001076
1077 lockdep_assert_held(&ar->conf_mutex);
1078
Michal Kazior500ff9f2015-03-31 10:26:21 +00001079 needed = ath10k_mac_monitor_vdev_is_needed(ar);
1080 allowed = ath10k_mac_monitor_vdev_is_allowed(ar);
Michal Kazior19337472014-08-28 12:58:16 +02001081
1082 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior500ff9f2015-03-31 10:26:21 +00001083 "mac monitor recalc started? %d needed? %d allowed? %d\n",
1084 ar->monitor_started, needed, allowed);
Michal Kazior19337472014-08-28 12:58:16 +02001085
Michal Kazior500ff9f2015-03-31 10:26:21 +00001086 if (WARN_ON(needed && !allowed)) {
1087 if (ar->monitor_started) {
1088 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopping disallowed monitor\n");
1089
1090 ret = ath10k_monitor_stop(ar);
1091 if (ret)
1092 ath10k_warn(ar, "failed to stop disallowed monitor: %d\n", ret);
1093 /* not serious */
1094 }
1095
1096 return -EPERM;
1097 }
1098
1099 if (needed == ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02001100 return 0;
1101
Michal Kazior500ff9f2015-03-31 10:26:21 +00001102 if (needed)
Michal Kazior19337472014-08-28 12:58:16 +02001103 return ath10k_monitor_start(ar);
Michal Kazior500ff9f2015-03-31 10:26:21 +00001104 else
1105 return ath10k_monitor_stop(ar);
Michal Kazior1bbc0972014-04-08 09:45:47 +03001106}
1107
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001108static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
1109{
1110 struct ath10k *ar = arvif->ar;
1111 u32 vdev_param, rts_cts = 0;
1112
1113 lockdep_assert_held(&ar->conf_mutex);
1114
1115 vdev_param = ar->wmi.vdev_param->enable_rtscts;
1116
Rajkumar Manoharan9a5ab0f2015-03-19 16:03:29 +02001117 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001118
1119 if (arvif->num_legacy_stations > 0)
1120 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
1121 WMI_RTSCTS_PROFILE);
Rajkumar Manoharan9a5ab0f2015-03-19 16:03:29 +02001122 else
1123 rts_cts |= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES,
1124 WMI_RTSCTS_PROFILE);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001125
1126 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
1127 rts_cts);
1128}
1129
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001130static int ath10k_start_cac(struct ath10k *ar)
1131{
1132 int ret;
1133
1134 lockdep_assert_held(&ar->conf_mutex);
1135
1136 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1137
Michal Kazior19337472014-08-28 12:58:16 +02001138 ret = ath10k_monitor_recalc(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001139 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001140 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001141 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1142 return ret;
1143 }
1144
Michal Kazior7aa7a722014-08-25 12:09:38 +02001145 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001146 ar->monitor_vdev_id);
1147
1148 return 0;
1149}
1150
1151static int ath10k_stop_cac(struct ath10k *ar)
1152{
1153 lockdep_assert_held(&ar->conf_mutex);
1154
1155 /* CAC is not running - do nothing */
1156 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
1157 return 0;
1158
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001159 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
Michal Kazior1bbc0972014-04-08 09:45:47 +03001160 ath10k_monitor_stop(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001161
Michal Kazior7aa7a722014-08-25 12:09:38 +02001162 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001163
1164 return 0;
1165}
1166
Michal Kazior500ff9f2015-03-31 10:26:21 +00001167static void ath10k_mac_has_radar_iter(struct ieee80211_hw *hw,
1168 struct ieee80211_chanctx_conf *conf,
1169 void *data)
1170{
1171 bool *ret = data;
1172
1173 if (!*ret && conf->radar_enabled)
1174 *ret = true;
1175}
1176
1177static bool ath10k_mac_has_radar_enabled(struct ath10k *ar)
1178{
1179 bool has_radar = false;
1180
1181 ieee80211_iter_chan_contexts_atomic(ar->hw,
1182 ath10k_mac_has_radar_iter,
1183 &has_radar);
1184
1185 return has_radar;
1186}
1187
Michal Kaziord6500972014-04-08 09:56:09 +03001188static void ath10k_recalc_radar_detection(struct ath10k *ar)
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001189{
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001190 int ret;
1191
1192 lockdep_assert_held(&ar->conf_mutex);
1193
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001194 ath10k_stop_cac(ar);
1195
Michal Kazior500ff9f2015-03-31 10:26:21 +00001196 if (!ath10k_mac_has_radar_enabled(ar))
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001197 return;
1198
Michal Kaziord6500972014-04-08 09:56:09 +03001199 if (ar->num_started_vdevs > 0)
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001200 return;
1201
1202 ret = ath10k_start_cac(ar);
1203 if (ret) {
1204 /*
1205 * Not possible to start CAC on current channel so starting
1206 * radiation is not allowed, make this channel DFS_UNAVAILABLE
1207 * by indicating that radar was detected.
1208 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02001209 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001210 ieee80211_radar_detected(ar->hw);
1211 }
1212}
1213
Vasanthakumar Thiagarajan822b7e02015-03-02 17:45:27 +05301214static int ath10k_vdev_stop(struct ath10k_vif *arvif)
Michal Kazior72654fa2014-04-08 09:56:09 +03001215{
1216 struct ath10k *ar = arvif->ar;
Vasanthakumar Thiagarajan822b7e02015-03-02 17:45:27 +05301217 int ret;
1218
1219 lockdep_assert_held(&ar->conf_mutex);
1220
1221 reinit_completion(&ar->vdev_setup_done);
1222
1223 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
1224 if (ret) {
1225 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
1226 arvif->vdev_id, ret);
1227 return ret;
1228 }
1229
1230 ret = ath10k_vdev_setup_sync(ar);
1231 if (ret) {
1232 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
1233 arvif->vdev_id, ret);
1234 return ret;
1235 }
1236
1237 WARN_ON(ar->num_started_vdevs == 0);
1238
1239 if (ar->num_started_vdevs != 0) {
1240 ar->num_started_vdevs--;
1241 ath10k_recalc_radar_detection(ar);
1242 }
1243
1244 return ret;
1245}
1246
Michal Kazior500ff9f2015-03-31 10:26:21 +00001247static int ath10k_vdev_start_restart(struct ath10k_vif *arvif,
1248 const struct cfg80211_chan_def *chandef,
1249 bool restart)
Michal Kazior72654fa2014-04-08 09:56:09 +03001250{
1251 struct ath10k *ar = arvif->ar;
Michal Kazior72654fa2014-04-08 09:56:09 +03001252 struct wmi_vdev_start_request_arg arg = {};
1253 int ret = 0;
1254
1255 lockdep_assert_held(&ar->conf_mutex);
1256
1257 reinit_completion(&ar->vdev_setup_done);
1258
1259 arg.vdev_id = arvif->vdev_id;
1260 arg.dtim_period = arvif->dtim_period;
1261 arg.bcn_intval = arvif->beacon_interval;
1262
1263 arg.channel.freq = chandef->chan->center_freq;
1264 arg.channel.band_center_freq1 = chandef->center_freq1;
1265 arg.channel.mode = chan_to_phymode(chandef);
1266
1267 arg.channel.min_power = 0;
1268 arg.channel.max_power = chandef->chan->max_power * 2;
1269 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
1270 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
1271
1272 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1273 arg.ssid = arvif->u.ap.ssid;
1274 arg.ssid_len = arvif->u.ap.ssid_len;
1275 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
1276
1277 /* For now allow DFS for AP mode */
1278 arg.channel.chan_radar =
1279 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
1280 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
1281 arg.ssid = arvif->vif->bss_conf.ssid;
1282 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
1283 }
1284
Michal Kazior7aa7a722014-08-25 12:09:38 +02001285 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior72654fa2014-04-08 09:56:09 +03001286 "mac vdev %d start center_freq %d phymode %s\n",
1287 arg.vdev_id, arg.channel.freq,
1288 ath10k_wmi_phymode_str(arg.channel.mode));
1289
Michal Kaziordc55e302014-07-29 12:53:36 +03001290 if (restart)
1291 ret = ath10k_wmi_vdev_restart(ar, &arg);
1292 else
1293 ret = ath10k_wmi_vdev_start(ar, &arg);
1294
Michal Kazior72654fa2014-04-08 09:56:09 +03001295 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001296 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +03001297 arg.vdev_id, ret);
1298 return ret;
1299 }
1300
1301 ret = ath10k_vdev_setup_sync(ar);
1302 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +02001303 ath10k_warn(ar,
1304 "failed to synchronize setup for vdev %i restart %d: %d\n",
1305 arg.vdev_id, restart, ret);
Michal Kazior72654fa2014-04-08 09:56:09 +03001306 return ret;
1307 }
1308
Michal Kaziord6500972014-04-08 09:56:09 +03001309 ar->num_started_vdevs++;
1310 ath10k_recalc_radar_detection(ar);
1311
Michal Kazior72654fa2014-04-08 09:56:09 +03001312 return ret;
1313}
1314
Michal Kazior500ff9f2015-03-31 10:26:21 +00001315static int ath10k_vdev_start(struct ath10k_vif *arvif,
1316 const struct cfg80211_chan_def *def)
Michal Kaziordc55e302014-07-29 12:53:36 +03001317{
Michal Kazior500ff9f2015-03-31 10:26:21 +00001318 return ath10k_vdev_start_restart(arvif, def, false);
Michal Kaziordc55e302014-07-29 12:53:36 +03001319}
1320
Michal Kazior500ff9f2015-03-31 10:26:21 +00001321static int ath10k_vdev_restart(struct ath10k_vif *arvif,
1322 const struct cfg80211_chan_def *def)
Michal Kaziordc55e302014-07-29 12:53:36 +03001323{
Michal Kazior500ff9f2015-03-31 10:26:21 +00001324 return ath10k_vdev_start_restart(arvif, def, true);
Michal Kazior72654fa2014-04-08 09:56:09 +03001325}
1326
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001327static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
1328 struct sk_buff *bcn)
1329{
1330 struct ath10k *ar = arvif->ar;
1331 struct ieee80211_mgmt *mgmt;
1332 const u8 *p2p_ie;
1333 int ret;
1334
1335 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1336 return 0;
1337
1338 if (arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1339 return 0;
1340
1341 mgmt = (void *)bcn->data;
1342 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1343 mgmt->u.beacon.variable,
1344 bcn->len - (mgmt->u.beacon.variable -
1345 bcn->data));
1346 if (!p2p_ie)
1347 return -ENOENT;
1348
1349 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1350 if (ret) {
1351 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1352 arvif->vdev_id, ret);
1353 return ret;
1354 }
1355
1356 return 0;
1357}
1358
1359static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1360 u8 oui_type, size_t ie_offset)
1361{
1362 size_t len;
1363 const u8 *next;
1364 const u8 *end;
1365 u8 *ie;
1366
1367 if (WARN_ON(skb->len < ie_offset))
1368 return -EINVAL;
1369
1370 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1371 skb->data + ie_offset,
1372 skb->len - ie_offset);
1373 if (!ie)
1374 return -ENOENT;
1375
1376 len = ie[1] + 2;
1377 end = skb->data + skb->len;
1378 next = ie + len;
1379
1380 if (WARN_ON(next > end))
1381 return -EINVAL;
1382
1383 memmove(ie, next, end - next);
1384 skb_trim(skb, skb->len - len);
1385
1386 return 0;
1387}
1388
1389static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1390{
1391 struct ath10k *ar = arvif->ar;
1392 struct ieee80211_hw *hw = ar->hw;
1393 struct ieee80211_vif *vif = arvif->vif;
1394 struct ieee80211_mutable_offsets offs = {};
1395 struct sk_buff *bcn;
1396 int ret;
1397
1398 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1399 return 0;
1400
Michal Kazior81a9a172015-03-05 16:02:17 +02001401 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
1402 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
1403 return 0;
1404
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001405 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1406 if (!bcn) {
1407 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1408 return -EPERM;
1409 }
1410
1411 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1412 if (ret) {
1413 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1414 kfree_skb(bcn);
1415 return ret;
1416 }
1417
1418 /* P2P IE is inserted by firmware automatically (as configured above)
1419 * so remove it from the base beacon template to avoid duplicate P2P
1420 * IEs in beacon frames.
1421 */
1422 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1423 offsetof(struct ieee80211_mgmt,
1424 u.beacon.variable));
1425
1426 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1427 0, NULL, 0);
1428 kfree_skb(bcn);
1429
1430 if (ret) {
1431 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1432 ret);
1433 return ret;
1434 }
1435
1436 return 0;
1437}
1438
1439static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1440{
1441 struct ath10k *ar = arvif->ar;
1442 struct ieee80211_hw *hw = ar->hw;
1443 struct ieee80211_vif *vif = arvif->vif;
1444 struct sk_buff *prb;
1445 int ret;
1446
1447 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1448 return 0;
1449
Michal Kazior81a9a172015-03-05 16:02:17 +02001450 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1451 return 0;
1452
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001453 prb = ieee80211_proberesp_get(hw, vif);
1454 if (!prb) {
1455 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1456 return -EPERM;
1457 }
1458
1459 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1460 kfree_skb(prb);
1461
1462 if (ret) {
1463 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1464 ret);
1465 return ret;
1466 }
1467
1468 return 0;
1469}
1470
Michal Kazior500ff9f2015-03-31 10:26:21 +00001471static int ath10k_mac_vif_fix_hidden_ssid(struct ath10k_vif *arvif)
1472{
1473 struct ath10k *ar = arvif->ar;
1474 struct cfg80211_chan_def def;
1475 int ret;
1476
1477 /* When originally vdev is started during assign_vif_chanctx() some
1478 * information is missing, notably SSID. Firmware revisions with beacon
1479 * offloading require the SSID to be provided during vdev (re)start to
1480 * handle hidden SSID properly.
1481 *
1482 * Vdev restart must be done after vdev has been both started and
1483 * upped. Otherwise some firmware revisions (at least 10.2) fail to
1484 * deliver vdev restart response event causing timeouts during vdev
1485 * syncing in ath10k.
1486 *
1487 * Note: The vdev down/up and template reinstallation could be skipped
1488 * since only wmi-tlv firmware are known to have beacon offload and
1489 * wmi-tlv doesn't seem to misbehave like 10.2 wrt vdev restart
1490 * response delivery. It's probably more robust to keep it as is.
1491 */
1492 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1493 return 0;
1494
1495 if (WARN_ON(!arvif->is_started))
1496 return -EINVAL;
1497
1498 if (WARN_ON(!arvif->is_up))
1499 return -EINVAL;
1500
1501 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
1502 return -EINVAL;
1503
1504 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1505 if (ret) {
1506 ath10k_warn(ar, "failed to bring down ap vdev %i: %d\n",
1507 arvif->vdev_id, ret);
1508 return ret;
1509 }
1510
1511 /* Vdev down reset beacon & presp templates. Reinstall them. Otherwise
1512 * firmware will crash upon vdev up.
1513 */
1514
1515 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1516 if (ret) {
1517 ath10k_warn(ar, "failed to update beacon template: %d\n", ret);
1518 return ret;
1519 }
1520
1521 ret = ath10k_mac_setup_prb_tmpl(arvif);
1522 if (ret) {
1523 ath10k_warn(ar, "failed to update presp template: %d\n", ret);
1524 return ret;
1525 }
1526
1527 ret = ath10k_vdev_restart(arvif, &def);
1528 if (ret) {
1529 ath10k_warn(ar, "failed to restart ap vdev %i: %d\n",
1530 arvif->vdev_id, ret);
1531 return ret;
1532 }
1533
1534 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1535 arvif->bssid);
1536 if (ret) {
1537 ath10k_warn(ar, "failed to bring up ap vdev %i: %d\n",
1538 arvif->vdev_id, ret);
1539 return ret;
1540 }
1541
1542 return 0;
1543}
1544
Kalle Valo5e3dd152013-06-12 20:52:10 +03001545static void ath10k_control_beaconing(struct ath10k_vif *arvif,
Kalle Valo5b07e072014-09-14 12:50:06 +03001546 struct ieee80211_bss_conf *info)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001547{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001548 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001549 int ret = 0;
1550
Michal Kazior548db542013-07-05 16:15:15 +03001551 lockdep_assert_held(&arvif->ar->conf_mutex);
1552
Kalle Valo5e3dd152013-06-12 20:52:10 +03001553 if (!info->enable_beacon) {
Michal Kazior500ff9f2015-03-31 10:26:21 +00001554 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1555 if (ret)
1556 ath10k_warn(ar, "failed to down vdev_id %i: %d\n",
1557 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001558
Michal Kaziorc930f742014-01-23 11:38:25 +01001559 arvif->is_up = false;
1560
Michal Kazior748afc42014-01-23 12:48:21 +01001561 spin_lock_bh(&arvif->ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03001562 ath10k_mac_vif_beacon_free(arvif);
Michal Kazior748afc42014-01-23 12:48:21 +01001563 spin_unlock_bh(&arvif->ar->data_lock);
1564
Kalle Valo5e3dd152013-06-12 20:52:10 +03001565 return;
1566 }
1567
1568 arvif->tx_seq_no = 0x1000;
1569
Michal Kaziorc930f742014-01-23 11:38:25 +01001570 arvif->aid = 0;
Kalle Valob25f32c2014-09-14 12:50:49 +03001571 ether_addr_copy(arvif->bssid, info->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01001572
1573 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1574 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001575 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001576 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001577 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001578 return;
1579 }
Michal Kaziorc930f742014-01-23 11:38:25 +01001580
Michal Kaziorc930f742014-01-23 11:38:25 +01001581 arvif->is_up = true;
1582
Michal Kazior500ff9f2015-03-31 10:26:21 +00001583 ret = ath10k_mac_vif_fix_hidden_ssid(arvif);
1584 if (ret) {
1585 ath10k_warn(ar, "failed to fix hidden ssid for vdev %i, expect trouble: %d\n",
1586 arvif->vdev_id, ret);
1587 return;
1588 }
1589
Michal Kazior7aa7a722014-08-25 12:09:38 +02001590 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001591}
1592
1593static void ath10k_control_ibss(struct ath10k_vif *arvif,
1594 struct ieee80211_bss_conf *info,
1595 const u8 self_peer[ETH_ALEN])
1596{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001597 struct ath10k *ar = arvif->ar;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001598 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001599 int ret = 0;
1600
Michal Kazior548db542013-07-05 16:15:15 +03001601 lockdep_assert_held(&arvif->ar->conf_mutex);
1602
Kalle Valo5e3dd152013-06-12 20:52:10 +03001603 if (!info->ibss_joined) {
Michal Kaziorc930f742014-01-23 11:38:25 +01001604 if (is_zero_ether_addr(arvif->bssid))
Kalle Valo5e3dd152013-06-12 20:52:10 +03001605 return;
1606
Joe Perches93803b32015-03-02 19:54:49 -08001607 eth_zero_addr(arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001608
1609 return;
1610 }
1611
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001612 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1613 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001614 ATH10K_DEFAULT_ATIM);
1615 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001616 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001617 arvif->vdev_id, ret);
1618}
1619
Michal Kazior9f9b5742014-12-12 12:41:36 +01001620static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1621{
1622 struct ath10k *ar = arvif->ar;
1623 u32 param;
1624 u32 value;
1625 int ret;
1626
1627 lockdep_assert_held(&arvif->ar->conf_mutex);
1628
1629 if (arvif->u.sta.uapsd)
1630 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1631 else
1632 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1633
1634 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1635 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1636 if (ret) {
1637 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1638 value, arvif->vdev_id, ret);
1639 return ret;
1640 }
1641
1642 return 0;
1643}
1644
1645static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1646{
1647 struct ath10k *ar = arvif->ar;
1648 u32 param;
1649 u32 value;
1650 int ret;
1651
1652 lockdep_assert_held(&arvif->ar->conf_mutex);
1653
1654 if (arvif->u.sta.uapsd)
1655 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1656 else
1657 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1658
1659 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1660 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1661 param, value);
1662 if (ret) {
1663 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1664 value, arvif->vdev_id, ret);
1665 return ret;
1666 }
1667
1668 return 0;
1669}
1670
Michal Kazior424f2632015-07-09 13:08:35 +02001671static int ath10k_mac_num_vifs_started(struct ath10k *ar)
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001672{
1673 struct ath10k_vif *arvif;
1674 int num = 0;
1675
1676 lockdep_assert_held(&ar->conf_mutex);
1677
1678 list_for_each_entry(arvif, &ar->arvifs, list)
Michal Kazior424f2632015-07-09 13:08:35 +02001679 if (arvif->is_started)
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001680 num++;
1681
1682 return num;
1683}
1684
Michal Kaziorad088bf2013-10-16 15:44:46 +03001685static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001686{
Michal Kaziorad088bf2013-10-16 15:44:46 +03001687 struct ath10k *ar = arvif->ar;
Michal Kazior526549a2014-12-12 12:41:37 +01001688 struct ieee80211_vif *vif = arvif->vif;
Michal Kaziorad088bf2013-10-16 15:44:46 +03001689 struct ieee80211_conf *conf = &ar->hw->conf;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001690 enum wmi_sta_powersave_param param;
1691 enum wmi_sta_ps_mode psmode;
1692 int ret;
Michal Kazior526549a2014-12-12 12:41:37 +01001693 int ps_timeout;
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001694 bool enable_ps;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001695
Michal Kazior548db542013-07-05 16:15:15 +03001696 lockdep_assert_held(&arvif->ar->conf_mutex);
1697
Michal Kaziorad088bf2013-10-16 15:44:46 +03001698 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1699 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001700
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001701 enable_ps = arvif->ps;
1702
Michal Kazior424f2632015-07-09 13:08:35 +02001703 if (enable_ps && ath10k_mac_num_vifs_started(ar) > 1 &&
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001704 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
1705 ar->fw_features)) {
1706 ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
1707 arvif->vdev_id);
1708 enable_ps = false;
1709 }
1710
Janusz Dziedzic917826b2015-05-18 09:38:17 +00001711 if (!arvif->is_started) {
1712 /* mac80211 can update vif powersave state while disconnected.
1713 * Firmware doesn't behave nicely and consumes more power than
1714 * necessary if PS is disabled on a non-started vdev. Hence
1715 * force-enable PS for non-running vdevs.
1716 */
1717 psmode = WMI_STA_PS_MODE_ENABLED;
1718 } else if (enable_ps) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001719 psmode = WMI_STA_PS_MODE_ENABLED;
1720 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1721
Michal Kazior526549a2014-12-12 12:41:37 +01001722 ps_timeout = conf->dynamic_ps_timeout;
1723 if (ps_timeout == 0) {
1724 /* Firmware doesn't like 0 */
1725 ps_timeout = ieee80211_tu_to_usec(
1726 vif->bss_conf.beacon_int) / 1000;
1727 }
1728
Michal Kaziorad088bf2013-10-16 15:44:46 +03001729 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
Michal Kazior526549a2014-12-12 12:41:37 +01001730 ps_timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001731 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001732 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001733 arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001734 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001735 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001736 } else {
1737 psmode = WMI_STA_PS_MODE_DISABLED;
1738 }
1739
Michal Kazior7aa7a722014-08-25 12:09:38 +02001740 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001741 arvif->vdev_id, psmode ? "enable" : "disable");
1742
Michal Kaziorad088bf2013-10-16 15:44:46 +03001743 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1744 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001745 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001746 psmode, arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001747 return ret;
1748 }
1749
1750 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001751}
1752
Michal Kazior46725b152015-01-28 09:57:49 +02001753static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1754{
1755 struct ath10k *ar = arvif->ar;
1756 struct wmi_sta_keepalive_arg arg = {};
1757 int ret;
1758
1759 lockdep_assert_held(&arvif->ar->conf_mutex);
1760
1761 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1762 return 0;
1763
1764 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1765 return 0;
1766
1767 /* Some firmware revisions have a bug and ignore the `enabled` field.
1768 * Instead use the interval to disable the keepalive.
1769 */
1770 arg.vdev_id = arvif->vdev_id;
1771 arg.enabled = 1;
1772 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1773 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1774
1775 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1776 if (ret) {
1777 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1778 arvif->vdev_id, ret);
1779 return ret;
1780 }
1781
1782 return 0;
1783}
1784
Michal Kazior81a9a172015-03-05 16:02:17 +02001785static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif)
1786{
1787 struct ath10k *ar = arvif->ar;
1788 struct ieee80211_vif *vif = arvif->vif;
1789 int ret;
1790
Michal Kazior8513d952015-03-09 14:19:24 +01001791 lockdep_assert_held(&arvif->ar->conf_mutex);
1792
1793 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)))
1794 return;
1795
Michal Kazior81a9a172015-03-05 16:02:17 +02001796 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1797 return;
1798
1799 if (!vif->csa_active)
1800 return;
1801
1802 if (!arvif->is_up)
1803 return;
1804
1805 if (!ieee80211_csa_is_complete(vif)) {
1806 ieee80211_csa_update_counter(vif);
1807
1808 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1809 if (ret)
1810 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
1811 ret);
1812
1813 ret = ath10k_mac_setup_prb_tmpl(arvif);
1814 if (ret)
1815 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
1816 ret);
1817 } else {
1818 ieee80211_csa_finish(vif);
1819 }
1820}
1821
1822static void ath10k_mac_vif_ap_csa_work(struct work_struct *work)
1823{
1824 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1825 ap_csa_work);
1826 struct ath10k *ar = arvif->ar;
1827
1828 mutex_lock(&ar->conf_mutex);
1829 ath10k_mac_vif_ap_csa_count_down(arvif);
1830 mutex_unlock(&ar->conf_mutex);
1831}
1832
Michal Kaziorcc9904e2015-03-10 16:22:01 +02001833static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac,
1834 struct ieee80211_vif *vif)
1835{
1836 struct sk_buff *skb = data;
1837 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1838 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1839
1840 if (vif->type != NL80211_IFTYPE_STATION)
1841 return;
1842
1843 if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
1844 return;
1845
1846 cancel_delayed_work(&arvif->connection_loss_work);
1847}
1848
1849void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb)
1850{
1851 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1852 IEEE80211_IFACE_ITER_NORMAL,
1853 ath10k_mac_handle_beacon_iter,
1854 skb);
1855}
1856
1857static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac,
1858 struct ieee80211_vif *vif)
1859{
1860 u32 *vdev_id = data;
1861 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1862 struct ath10k *ar = arvif->ar;
1863 struct ieee80211_hw *hw = ar->hw;
1864
1865 if (arvif->vdev_id != *vdev_id)
1866 return;
1867
1868 if (!arvif->is_up)
1869 return;
1870
1871 ieee80211_beacon_loss(vif);
1872
1873 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
1874 * (done by mac80211) succeeds but beacons do not resume then it
1875 * doesn't make sense to continue operation. Queue connection loss work
1876 * which can be cancelled when beacon is received.
1877 */
1878 ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
1879 ATH10K_CONNECTION_LOSS_HZ);
1880}
1881
1882void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id)
1883{
1884 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1885 IEEE80211_IFACE_ITER_NORMAL,
1886 ath10k_mac_handle_beacon_miss_iter,
1887 &vdev_id);
1888}
1889
1890static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work)
1891{
1892 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1893 connection_loss_work.work);
1894 struct ieee80211_vif *vif = arvif->vif;
1895
1896 if (!arvif->is_up)
1897 return;
1898
1899 ieee80211_connection_loss(vif);
1900}
1901
Kalle Valo5e3dd152013-06-12 20:52:10 +03001902/**********************/
1903/* Station management */
1904/**********************/
1905
Michal Kazior590922a2014-10-21 10:10:29 +03001906static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1907 struct ieee80211_vif *vif)
1908{
1909 /* Some firmware revisions have unstable STA powersave when listen
1910 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1911 * generate NullFunc frames properly even if buffered frames have been
1912 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1913 * buffered frames. Often pinging the device from AP would simply fail.
1914 *
1915 * As a workaround set it to 1.
1916 */
1917 if (vif->type == NL80211_IFTYPE_STATION)
1918 return 1;
1919
1920 return ar->hw->conf.listen_interval;
1921}
1922
Kalle Valo5e3dd152013-06-12 20:52:10 +03001923static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001924 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001925 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001926 struct wmi_peer_assoc_complete_arg *arg)
1927{
Michal Kazior590922a2014-10-21 10:10:29 +03001928 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorc51880e2015-03-30 09:51:57 +03001929 u32 aid;
Michal Kazior590922a2014-10-21 10:10:29 +03001930
Michal Kazior548db542013-07-05 16:15:15 +03001931 lockdep_assert_held(&ar->conf_mutex);
1932
Michal Kaziorc51880e2015-03-30 09:51:57 +03001933 if (vif->type == NL80211_IFTYPE_STATION)
1934 aid = vif->bss_conf.aid;
1935 else
1936 aid = sta->aid;
1937
Kalle Valob25f32c2014-09-14 12:50:49 +03001938 ether_addr_copy(arg->addr, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001939 arg->vdev_id = arvif->vdev_id;
Michal Kaziorc51880e2015-03-30 09:51:57 +03001940 arg->peer_aid = aid;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001941 arg->peer_flags |= WMI_PEER_AUTH;
Michal Kazior590922a2014-10-21 10:10:29 +03001942 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001943 arg->peer_num_spatial_streams = 1;
Michal Kazior590922a2014-10-21 10:10:29 +03001944 arg->peer_caps = vif->bss_conf.assoc_capability;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001945}
1946
1947static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001948 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001949 struct wmi_peer_assoc_complete_arg *arg)
1950{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001951 struct ieee80211_bss_conf *info = &vif->bss_conf;
Michal Kazior500ff9f2015-03-31 10:26:21 +00001952 struct cfg80211_chan_def def;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001953 struct cfg80211_bss *bss;
1954 const u8 *rsnie = NULL;
1955 const u8 *wpaie = NULL;
1956
Michal Kazior548db542013-07-05 16:15:15 +03001957 lockdep_assert_held(&ar->conf_mutex);
1958
Michal Kazior500ff9f2015-03-31 10:26:21 +00001959 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
1960 return;
1961
1962 bss = cfg80211_get_bss(ar->hw->wiphy, def.chan, info->bssid, NULL, 0,
1963 IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001964 if (bss) {
1965 const struct cfg80211_bss_ies *ies;
1966
1967 rcu_read_lock();
1968 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1969
1970 ies = rcu_dereference(bss->ies);
1971
1972 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
Kalle Valo5b07e072014-09-14 12:50:06 +03001973 WLAN_OUI_TYPE_MICROSOFT_WPA,
1974 ies->data,
1975 ies->len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001976 rcu_read_unlock();
1977 cfg80211_put_bss(ar->hw->wiphy, bss);
1978 }
1979
1980 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1981 if (rsnie || wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001982 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001983 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1984 }
1985
1986 if (wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001987 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001988 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1989 }
1990}
1991
1992static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
Michal Kazior500ff9f2015-03-31 10:26:21 +00001993 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001994 struct ieee80211_sta *sta,
1995 struct wmi_peer_assoc_complete_arg *arg)
1996{
Michal Kazior45c9abc2015-04-21 20:42:58 +03001997 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001998 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
Michal Kazior500ff9f2015-03-31 10:26:21 +00001999 struct cfg80211_chan_def def;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002000 const struct ieee80211_supported_band *sband;
2001 const struct ieee80211_rate *rates;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002002 enum ieee80211_band band;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002003 u32 ratemask;
Michal Kazior486017c2015-03-30 09:51:54 +03002004 u8 rate;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002005 int i;
2006
Michal Kazior548db542013-07-05 16:15:15 +03002007 lockdep_assert_held(&ar->conf_mutex);
2008
Michal Kazior500ff9f2015-03-31 10:26:21 +00002009 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2010 return;
2011
Michal Kazior45c9abc2015-04-21 20:42:58 +03002012 band = def.chan->band;
2013 sband = ar->hw->wiphy->bands[band];
2014 ratemask = sta->supp_rates[band];
2015 ratemask &= arvif->bitrate_mask.control[band].legacy;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002016 rates = sband->bitrates;
2017
2018 rateset->num_rates = 0;
2019
2020 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
2021 if (!(ratemask & 1))
2022 continue;
2023
Michal Kazior486017c2015-03-30 09:51:54 +03002024 rate = ath10k_mac_bitrate_to_rate(rates->bitrate);
2025 rateset->rates[rateset->num_rates] = rate;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002026 rateset->num_rates++;
2027 }
2028}
2029
Michal Kazior45c9abc2015-04-21 20:42:58 +03002030static bool
2031ath10k_peer_assoc_h_ht_masked(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
2032{
2033 int nss;
2034
2035 for (nss = 0; nss < IEEE80211_HT_MCS_MASK_LEN; nss++)
2036 if (ht_mcs_mask[nss])
2037 return false;
2038
2039 return true;
2040}
2041
2042static bool
2043ath10k_peer_assoc_h_vht_masked(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
2044{
2045 int nss;
2046
2047 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++)
2048 if (vht_mcs_mask[nss])
2049 return false;
2050
2051 return true;
2052}
2053
Kalle Valo5e3dd152013-06-12 20:52:10 +03002054static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
Michal Kazior45c9abc2015-04-21 20:42:58 +03002055 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002056 struct ieee80211_sta *sta,
2057 struct wmi_peer_assoc_complete_arg *arg)
2058{
2059 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002060 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2061 struct cfg80211_chan_def def;
2062 enum ieee80211_band band;
2063 const u8 *ht_mcs_mask;
2064 const u16 *vht_mcs_mask;
2065 int i, n, max_nss;
Kalle Valoaf762c02014-09-14 12:50:17 +03002066 u32 stbc;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002067
Michal Kazior548db542013-07-05 16:15:15 +03002068 lockdep_assert_held(&ar->conf_mutex);
2069
Michal Kazior45c9abc2015-04-21 20:42:58 +03002070 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2071 return;
2072
Kalle Valo5e3dd152013-06-12 20:52:10 +03002073 if (!ht_cap->ht_supported)
2074 return;
2075
Michal Kazior45c9abc2015-04-21 20:42:58 +03002076 band = def.chan->band;
2077 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2078 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2079
2080 if (ath10k_peer_assoc_h_ht_masked(ht_mcs_mask) &&
2081 ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2082 return;
2083
Kalle Valo5e3dd152013-06-12 20:52:10 +03002084 arg->peer_flags |= WMI_PEER_HT;
2085 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2086 ht_cap->ampdu_factor)) - 1;
2087
2088 arg->peer_mpdu_density =
2089 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
2090
2091 arg->peer_ht_caps = ht_cap->cap;
2092 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
2093
2094 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
2095 arg->peer_flags |= WMI_PEER_LDPC;
2096
2097 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
2098 arg->peer_flags |= WMI_PEER_40MHZ;
2099 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
2100 }
2101
Michal Kazior45c9abc2015-04-21 20:42:58 +03002102 if (arvif->bitrate_mask.control[band].gi != NL80211_TXRATE_FORCE_LGI) {
2103 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
2104 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002105
Michal Kazior45c9abc2015-04-21 20:42:58 +03002106 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
2107 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2108 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002109
2110 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
2111 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
2112 arg->peer_flags |= WMI_PEER_STBC;
2113 }
2114
2115 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002116 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
2117 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
2118 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
2119 arg->peer_rate_caps |= stbc;
2120 arg->peer_flags |= WMI_PEER_STBC;
2121 }
2122
Kalle Valo5e3dd152013-06-12 20:52:10 +03002123 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
2124 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
2125 else if (ht_cap->mcs.rx_mask[1])
2126 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
2127
Michal Kazior45c9abc2015-04-21 20:42:58 +03002128 for (i = 0, n = 0, max_nss = 0; i < IEEE80211_HT_MCS_MASK_LEN * 8; i++)
2129 if ((ht_cap->mcs.rx_mask[i / 8] & BIT(i % 8)) &&
2130 (ht_mcs_mask[i / 8] & BIT(i % 8))) {
2131 max_nss = (i / 8) + 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002132 arg->peer_ht_rates.rates[n++] = i;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002133 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002134
Bartosz Markowskifd71f802014-02-10 13:12:55 +01002135 /*
2136 * This is a workaround for HT-enabled STAs which break the spec
2137 * and have no HT capabilities RX mask (no HT RX MCS map).
2138 *
2139 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
2140 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
2141 *
2142 * Firmware asserts if such situation occurs.
2143 */
2144 if (n == 0) {
2145 arg->peer_ht_rates.num_rates = 8;
2146 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
2147 arg->peer_ht_rates.rates[i] = i;
2148 } else {
2149 arg->peer_ht_rates.num_rates = n;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002150 arg->peer_num_spatial_streams = max_nss;
Bartosz Markowskifd71f802014-02-10 13:12:55 +01002151 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002152
Michal Kazior7aa7a722014-08-25 12:09:38 +02002153 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03002154 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002155 arg->peer_ht_rates.num_rates,
2156 arg->peer_num_spatial_streams);
2157}
2158
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002159static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
2160 struct ath10k_vif *arvif,
2161 struct ieee80211_sta *sta)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002162{
2163 u32 uapsd = 0;
2164 u32 max_sp = 0;
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002165 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002166
Michal Kazior548db542013-07-05 16:15:15 +03002167 lockdep_assert_held(&ar->conf_mutex);
2168
Kalle Valo5e3dd152013-06-12 20:52:10 +03002169 if (sta->wme && sta->uapsd_queues) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002170 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002171 sta->uapsd_queues, sta->max_sp);
2172
Kalle Valo5e3dd152013-06-12 20:52:10 +03002173 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2174 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
2175 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
2176 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2177 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
2178 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
2179 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2180 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
2181 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
2182 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2183 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
2184 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
2185
Kalle Valo5e3dd152013-06-12 20:52:10 +03002186 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
2187 max_sp = sta->max_sp;
2188
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002189 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2190 sta->addr,
2191 WMI_AP_PS_PEER_PARAM_UAPSD,
2192 uapsd);
2193 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002194 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002195 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002196 return ret;
2197 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002198
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002199 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2200 sta->addr,
2201 WMI_AP_PS_PEER_PARAM_MAX_SP,
2202 max_sp);
2203 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002204 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002205 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002206 return ret;
2207 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002208
2209 /* TODO setup this based on STA listen interval and
2210 beacon interval. Currently we don't know
2211 sta->listen_interval - mac80211 patch required.
2212 Currently use 10 seconds */
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002213 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
Kalle Valo5b07e072014-09-14 12:50:06 +03002214 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
2215 10);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002216 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002217 ath10k_warn(ar, "failed to set ap ps peer param ageout time 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 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002222
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002223 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002224}
2225
Michal Kazior45c9abc2015-04-21 20:42:58 +03002226static u16
2227ath10k_peer_assoc_h_vht_limit(u16 tx_mcs_set,
2228 const u16 vht_mcs_limit[NL80211_VHT_NSS_MAX])
2229{
2230 int idx_limit;
2231 int nss;
2232 u16 mcs_map;
2233 u16 mcs;
2234
2235 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
2236 mcs_map = ath10k_mac_get_max_vht_mcs_map(tx_mcs_set, nss) &
2237 vht_mcs_limit[nss];
2238
2239 if (mcs_map)
2240 idx_limit = fls(mcs_map) - 1;
2241 else
2242 idx_limit = -1;
2243
2244 switch (idx_limit) {
2245 case 0: /* fall through */
2246 case 1: /* fall through */
2247 case 2: /* fall through */
2248 case 3: /* fall through */
2249 case 4: /* fall through */
2250 case 5: /* fall through */
2251 case 6: /* fall through */
2252 default:
2253 /* see ath10k_mac_can_set_bitrate_mask() */
2254 WARN_ON(1);
2255 /* fall through */
2256 case -1:
2257 mcs = IEEE80211_VHT_MCS_NOT_SUPPORTED;
2258 break;
2259 case 7:
2260 mcs = IEEE80211_VHT_MCS_SUPPORT_0_7;
2261 break;
2262 case 8:
2263 mcs = IEEE80211_VHT_MCS_SUPPORT_0_8;
2264 break;
2265 case 9:
2266 mcs = IEEE80211_VHT_MCS_SUPPORT_0_9;
2267 break;
2268 }
2269
2270 tx_mcs_set &= ~(0x3 << (nss * 2));
2271 tx_mcs_set |= mcs << (nss * 2);
2272 }
2273
2274 return tx_mcs_set;
2275}
2276
Kalle Valo5e3dd152013-06-12 20:52:10 +03002277static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
Michal Kazior500ff9f2015-03-31 10:26:21 +00002278 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002279 struct ieee80211_sta *sta,
2280 struct wmi_peer_assoc_complete_arg *arg)
2281{
2282 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002283 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior500ff9f2015-03-31 10:26:21 +00002284 struct cfg80211_chan_def def;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002285 enum ieee80211_band band;
2286 const u16 *vht_mcs_mask;
Sujith Manoharana24b88b2013-10-07 19:51:57 -07002287 u8 ampdu_factor;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002288
Michal Kazior500ff9f2015-03-31 10:26:21 +00002289 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2290 return;
2291
Kalle Valo5e3dd152013-06-12 20:52:10 +03002292 if (!vht_cap->vht_supported)
2293 return;
2294
Michal Kazior45c9abc2015-04-21 20:42:58 +03002295 band = def.chan->band;
2296 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2297
2298 if (ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2299 return;
2300
Kalle Valo5e3dd152013-06-12 20:52:10 +03002301 arg->peer_flags |= WMI_PEER_VHT;
Yanbo Lid68bb122015-01-23 08:18:20 +08002302
Michal Kazior500ff9f2015-03-31 10:26:21 +00002303 if (def.chan->band == IEEE80211_BAND_2GHZ)
Yanbo Lid68bb122015-01-23 08:18:20 +08002304 arg->peer_flags |= WMI_PEER_VHT_2G;
2305
Kalle Valo5e3dd152013-06-12 20:52:10 +03002306 arg->peer_vht_caps = vht_cap->cap;
2307
Sujith Manoharana24b88b2013-10-07 19:51:57 -07002308 ampdu_factor = (vht_cap->cap &
2309 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
2310 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
2311
2312 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
2313 * zero in VHT IE. Using it would result in degraded throughput.
2314 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
2315 * it if VHT max_mpdu is smaller. */
2316 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
2317 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2318 ampdu_factor)) - 1);
2319
Kalle Valo5e3dd152013-06-12 20:52:10 +03002320 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2321 arg->peer_flags |= WMI_PEER_80MHZ;
2322
2323 arg->peer_vht_rates.rx_max_rate =
2324 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
2325 arg->peer_vht_rates.rx_mcs_set =
2326 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
2327 arg->peer_vht_rates.tx_max_rate =
2328 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
Michal Kazior45c9abc2015-04-21 20:42:58 +03002329 arg->peer_vht_rates.tx_mcs_set = ath10k_peer_assoc_h_vht_limit(
2330 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map), vht_mcs_mask);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002331
Michal Kazior7aa7a722014-08-25 12:09:38 +02002332 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03002333 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002334}
2335
2336static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03002337 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002338 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002339 struct wmi_peer_assoc_complete_arg *arg)
2340{
Michal Kazior590922a2014-10-21 10:10:29 +03002341 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2342
Kalle Valo5e3dd152013-06-12 20:52:10 +03002343 switch (arvif->vdev_type) {
2344 case WMI_VDEV_TYPE_AP:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002345 if (sta->wme)
2346 arg->peer_flags |= WMI_PEER_QOS;
2347
2348 if (sta->wme && sta->uapsd_queues) {
2349 arg->peer_flags |= WMI_PEER_APSD;
2350 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
2351 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002352 break;
2353 case WMI_VDEV_TYPE_STA:
Michal Kazior590922a2014-10-21 10:10:29 +03002354 if (vif->bss_conf.qos)
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002355 arg->peer_flags |= WMI_PEER_QOS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002356 break;
Janusz Dziedzic627d9842014-12-17 12:29:54 +02002357 case WMI_VDEV_TYPE_IBSS:
2358 if (sta->wme)
2359 arg->peer_flags |= WMI_PEER_QOS;
2360 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002361 default:
2362 break;
2363 }
Janusz Dziedzic627d9842014-12-17 12:29:54 +02002364
2365 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
2366 sta->addr, !!(arg->peer_flags & WMI_PEER_QOS));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002367}
2368
Michal Kazior8d7aa6b2015-03-30 09:51:57 +03002369static bool ath10k_mac_sta_has_ofdm_only(struct ieee80211_sta *sta)
Michal Kazior91b12082014-12-12 12:41:35 +01002370{
Michal Kazior8d7aa6b2015-03-30 09:51:57 +03002371 return sta->supp_rates[IEEE80211_BAND_2GHZ] >>
2372 ATH10K_MAC_FIRST_OFDM_RATE_IDX;
Michal Kazior91b12082014-12-12 12:41:35 +01002373}
2374
Kalle Valo5e3dd152013-06-12 20:52:10 +03002375static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03002376 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002377 struct ieee80211_sta *sta,
2378 struct wmi_peer_assoc_complete_arg *arg)
2379{
Michal Kazior45c9abc2015-04-21 20:42:58 +03002380 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior500ff9f2015-03-31 10:26:21 +00002381 struct cfg80211_chan_def def;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002382 enum ieee80211_band band;
2383 const u8 *ht_mcs_mask;
2384 const u16 *vht_mcs_mask;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002385 enum wmi_phy_mode phymode = MODE_UNKNOWN;
2386
Michal Kazior500ff9f2015-03-31 10:26:21 +00002387 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2388 return;
2389
Michal Kazior45c9abc2015-04-21 20:42:58 +03002390 band = def.chan->band;
2391 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2392 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2393
2394 switch (band) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002395 case IEEE80211_BAND_2GHZ:
Michal Kazior45c9abc2015-04-21 20:42:58 +03002396 if (sta->vht_cap.vht_supported &&
2397 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
Yanbo Lid68bb122015-01-23 08:18:20 +08002398 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2399 phymode = MODE_11AC_VHT40;
2400 else
2401 phymode = MODE_11AC_VHT20;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002402 } else if (sta->ht_cap.ht_supported &&
2403 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002404 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2405 phymode = MODE_11NG_HT40;
2406 else
2407 phymode = MODE_11NG_HT20;
Michal Kazior8d7aa6b2015-03-30 09:51:57 +03002408 } else if (ath10k_mac_sta_has_ofdm_only(sta)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002409 phymode = MODE_11G;
Michal Kazior91b12082014-12-12 12:41:35 +01002410 } else {
2411 phymode = MODE_11B;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002412 }
2413
2414 break;
2415 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03002416 /*
2417 * Check VHT first.
2418 */
Michal Kazior45c9abc2015-04-21 20:42:58 +03002419 if (sta->vht_cap.vht_supported &&
2420 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03002421 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2422 phymode = MODE_11AC_VHT80;
2423 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2424 phymode = MODE_11AC_VHT40;
2425 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
2426 phymode = MODE_11AC_VHT20;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002427 } else if (sta->ht_cap.ht_supported &&
2428 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2429 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002430 phymode = MODE_11NA_HT40;
2431 else
2432 phymode = MODE_11NA_HT20;
2433 } else {
2434 phymode = MODE_11A;
2435 }
2436
2437 break;
2438 default:
2439 break;
2440 }
2441
Michal Kazior7aa7a722014-08-25 12:09:38 +02002442 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
Kalle Valo38a1d472013-09-08 17:56:14 +03002443 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03002444
Kalle Valo5e3dd152013-06-12 20:52:10 +03002445 arg->peer_phymode = phymode;
2446 WARN_ON(phymode == MODE_UNKNOWN);
2447}
2448
Kalle Valob9ada652013-10-16 15:44:46 +03002449static int ath10k_peer_assoc_prepare(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03002450 struct ieee80211_vif *vif,
Kalle Valob9ada652013-10-16 15:44:46 +03002451 struct ieee80211_sta *sta,
Kalle Valob9ada652013-10-16 15:44:46 +03002452 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002453{
Michal Kazior548db542013-07-05 16:15:15 +03002454 lockdep_assert_held(&ar->conf_mutex);
2455
Kalle Valob9ada652013-10-16 15:44:46 +03002456 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002457
Michal Kazior590922a2014-10-21 10:10:29 +03002458 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
2459 ath10k_peer_assoc_h_crypto(ar, vif, arg);
Michal Kazior500ff9f2015-03-31 10:26:21 +00002460 ath10k_peer_assoc_h_rates(ar, vif, sta, arg);
Michal Kazior45c9abc2015-04-21 20:42:58 +03002461 ath10k_peer_assoc_h_ht(ar, vif, sta, arg);
Michal Kazior500ff9f2015-03-31 10:26:21 +00002462 ath10k_peer_assoc_h_vht(ar, vif, sta, arg);
Michal Kazior590922a2014-10-21 10:10:29 +03002463 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
2464 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002465
Kalle Valob9ada652013-10-16 15:44:46 +03002466 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002467}
2468
Michal Kazior90046f52014-02-14 14:45:51 +01002469static const u32 ath10k_smps_map[] = {
2470 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
2471 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
2472 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
2473 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
2474};
2475
2476static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
2477 const u8 *addr,
2478 const struct ieee80211_sta_ht_cap *ht_cap)
2479{
2480 int smps;
2481
2482 if (!ht_cap->ht_supported)
2483 return 0;
2484
2485 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
2486 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
2487
2488 if (smps >= ARRAY_SIZE(ath10k_smps_map))
2489 return -EINVAL;
2490
2491 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
2492 WMI_PEER_SMPS_STATE,
2493 ath10k_smps_map[smps]);
2494}
2495
Michal Kazior139e1702015-02-15 16:50:42 +02002496static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
2497 struct ieee80211_vif *vif,
2498 struct ieee80211_sta_vht_cap vht_cap)
2499{
2500 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2501 int ret;
2502 u32 param;
2503 u32 value;
2504
2505 if (!(ar->vht_cap_info &
2506 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2507 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
2508 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2509 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
2510 return 0;
2511
2512 param = ar->wmi.vdev_param->txbf;
2513 value = 0;
2514
2515 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
2516 return 0;
2517
2518 /* The following logic is correct. If a remote STA advertises support
2519 * for being a beamformer then we should enable us being a beamformee.
2520 */
2521
2522 if (ar->vht_cap_info &
2523 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2524 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
2525 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
2526 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2527
2528 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
2529 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
2530 }
2531
2532 if (ar->vht_cap_info &
2533 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2534 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
2535 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
2536 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2537
2538 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
2539 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
2540 }
2541
2542 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
2543 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2544
2545 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
2546 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2547
2548 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
2549 if (ret) {
2550 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
2551 value, ret);
2552 return ret;
2553 }
2554
2555 return 0;
2556}
2557
Kalle Valo5e3dd152013-06-12 20:52:10 +03002558/* can be called only in mac80211 callbacks due to `key_count` usage */
2559static void ath10k_bss_assoc(struct ieee80211_hw *hw,
2560 struct ieee80211_vif *vif,
2561 struct ieee80211_bss_conf *bss_conf)
2562{
2563 struct ath10k *ar = hw->priv;
2564 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior90046f52014-02-14 14:45:51 +01002565 struct ieee80211_sta_ht_cap ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02002566 struct ieee80211_sta_vht_cap vht_cap;
Kalle Valob9ada652013-10-16 15:44:46 +03002567 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002568 struct ieee80211_sta *ap_sta;
2569 int ret;
2570
Michal Kazior548db542013-07-05 16:15:15 +03002571 lockdep_assert_held(&ar->conf_mutex);
2572
Michal Kazior077efc82014-10-21 10:10:29 +03002573 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
2574 arvif->vdev_id, arvif->bssid, arvif->aid);
2575
Kalle Valo5e3dd152013-06-12 20:52:10 +03002576 rcu_read_lock();
2577
2578 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
2579 if (!ap_sta) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002580 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02002581 bss_conf->bssid, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002582 rcu_read_unlock();
2583 return;
2584 }
2585
Michal Kazior90046f52014-02-14 14:45:51 +01002586 /* ap_sta must be accessed only within rcu section which must be left
2587 * before calling ath10k_setup_peer_smps() which might sleep. */
2588 ht_cap = ap_sta->ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02002589 vht_cap = ap_sta->vht_cap;
Michal Kazior90046f52014-02-14 14:45:51 +01002590
Michal Kazior590922a2014-10-21 10:10:29 +03002591 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002592 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002593 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002594 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002595 rcu_read_unlock();
2596 return;
2597 }
2598
2599 rcu_read_unlock();
2600
Kalle Valob9ada652013-10-16 15:44:46 +03002601 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2602 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002603 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002604 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03002605 return;
2606 }
2607
Michal Kazior90046f52014-02-14 14:45:51 +01002608 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
2609 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002610 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002611 arvif->vdev_id, ret);
Michal Kazior90046f52014-02-14 14:45:51 +01002612 return;
2613 }
2614
Michal Kazior139e1702015-02-15 16:50:42 +02002615 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2616 if (ret) {
2617 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2618 arvif->vdev_id, bss_conf->bssid, ret);
2619 return;
2620 }
2621
Michal Kazior7aa7a722014-08-25 12:09:38 +02002622 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002623 "mac vdev %d up (associated) bssid %pM aid %d\n",
2624 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
2625
Michal Kazior077efc82014-10-21 10:10:29 +03002626 WARN_ON(arvif->is_up);
2627
Michal Kaziorc930f742014-01-23 11:38:25 +01002628 arvif->aid = bss_conf->aid;
Kalle Valob25f32c2014-09-14 12:50:49 +03002629 ether_addr_copy(arvif->bssid, bss_conf->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01002630
2631 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
2632 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002633 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002634 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01002635 return;
2636 }
2637
2638 arvif->is_up = true;
Michal Kazior0a987fb2015-02-13 13:30:15 +01002639
2640 /* Workaround: Some firmware revisions (tested with qca6174
2641 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2642 * poked with peer param command.
2643 */
2644 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
2645 WMI_PEER_DUMMY_VAR, 1);
2646 if (ret) {
2647 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2648 arvif->bssid, arvif->vdev_id, ret);
2649 return;
2650 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002651}
2652
Kalle Valo5e3dd152013-06-12 20:52:10 +03002653static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
2654 struct ieee80211_vif *vif)
2655{
2656 struct ath10k *ar = hw->priv;
2657 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior139e1702015-02-15 16:50:42 +02002658 struct ieee80211_sta_vht_cap vht_cap = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +03002659 int ret;
2660
Michal Kazior548db542013-07-05 16:15:15 +03002661 lockdep_assert_held(&ar->conf_mutex);
2662
Michal Kazior077efc82014-10-21 10:10:29 +03002663 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
2664 arvif->vdev_id, arvif->bssid);
Kalle Valo60c3daa2013-09-08 17:56:07 +03002665
Kalle Valo5e3dd152013-06-12 20:52:10 +03002666 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kazior077efc82014-10-21 10:10:29 +03002667 if (ret)
2668 ath10k_warn(ar, "faield to down vdev %i: %d\n",
2669 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002670
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02002671 arvif->def_wep_key_idx = -1;
2672
Michal Kazior139e1702015-02-15 16:50:42 +02002673 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2674 if (ret) {
2675 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
2676 arvif->vdev_id, ret);
2677 return;
2678 }
2679
Michal Kaziorc930f742014-01-23 11:38:25 +01002680 arvif->is_up = false;
Michal Kaziorcc9904e2015-03-10 16:22:01 +02002681
2682 cancel_delayed_work_sync(&arvif->connection_loss_work);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002683}
2684
Michal Kazior590922a2014-10-21 10:10:29 +03002685static int ath10k_station_assoc(struct ath10k *ar,
2686 struct ieee80211_vif *vif,
2687 struct ieee80211_sta *sta,
2688 bool reassoc)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002689{
Michal Kazior590922a2014-10-21 10:10:29 +03002690 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valob9ada652013-10-16 15:44:46 +03002691 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002692 int ret = 0;
2693
Michal Kazior548db542013-07-05 16:15:15 +03002694 lockdep_assert_held(&ar->conf_mutex);
2695
Michal Kazior590922a2014-10-21 10:10:29 +03002696 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002697 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002698 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02002699 sta->addr, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03002700 return ret;
2701 }
2702
2703 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2704 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002705 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002706 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002707 return ret;
2708 }
2709
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002710 /* Re-assoc is run only to update supported rates for given station. It
2711 * doesn't make much sense to reconfigure the peer completely.
2712 */
2713 if (!reassoc) {
2714 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
2715 &sta->ht_cap);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002716 if (ret) {
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002717 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002718 arvif->vdev_id, ret);
2719 return ret;
2720 }
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002721
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002722 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
2723 if (ret) {
2724 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
2725 sta->addr, arvif->vdev_id, ret);
2726 return ret;
2727 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002728
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002729 if (!sta->wme) {
2730 arvif->num_legacy_stations++;
2731 ret = ath10k_recalc_rtscts_prot(arvif);
2732 if (ret) {
2733 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2734 arvif->vdev_id, ret);
2735 return ret;
2736 }
2737 }
2738
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02002739 /* Plumb cached keys only for static WEP */
2740 if (arvif->def_wep_key_idx != -1) {
2741 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
2742 if (ret) {
2743 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
2744 arvif->vdev_id, ret);
2745 return ret;
2746 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002747 }
2748 }
2749
Kalle Valo5e3dd152013-06-12 20:52:10 +03002750 return ret;
2751}
2752
Michal Kazior590922a2014-10-21 10:10:29 +03002753static int ath10k_station_disassoc(struct ath10k *ar,
2754 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002755 struct ieee80211_sta *sta)
2756{
Michal Kazior590922a2014-10-21 10:10:29 +03002757 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002758 int ret = 0;
2759
2760 lockdep_assert_held(&ar->conf_mutex);
2761
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002762 if (!sta->wme) {
2763 arvif->num_legacy_stations--;
2764 ret = ath10k_recalc_rtscts_prot(arvif);
2765 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002766 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002767 arvif->vdev_id, ret);
2768 return ret;
2769 }
2770 }
2771
Kalle Valo5e3dd152013-06-12 20:52:10 +03002772 ret = ath10k_clear_peer_keys(arvif, sta->addr);
2773 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002774 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002775 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002776 return ret;
2777 }
2778
2779 return ret;
2780}
2781
2782/**************/
2783/* Regulatory */
2784/**************/
2785
2786static int ath10k_update_channel_list(struct ath10k *ar)
2787{
2788 struct ieee80211_hw *hw = ar->hw;
2789 struct ieee80211_supported_band **bands;
2790 enum ieee80211_band band;
2791 struct ieee80211_channel *channel;
2792 struct wmi_scan_chan_list_arg arg = {0};
2793 struct wmi_channel_arg *ch;
2794 bool passive;
2795 int len;
2796 int ret;
2797 int i;
2798
Michal Kazior548db542013-07-05 16:15:15 +03002799 lockdep_assert_held(&ar->conf_mutex);
2800
Kalle Valo5e3dd152013-06-12 20:52:10 +03002801 bands = hw->wiphy->bands;
2802 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2803 if (!bands[band])
2804 continue;
2805
2806 for (i = 0; i < bands[band]->n_channels; i++) {
2807 if (bands[band]->channels[i].flags &
2808 IEEE80211_CHAN_DISABLED)
2809 continue;
2810
2811 arg.n_channels++;
2812 }
2813 }
2814
2815 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
2816 arg.channels = kzalloc(len, GFP_KERNEL);
2817 if (!arg.channels)
2818 return -ENOMEM;
2819
2820 ch = arg.channels;
2821 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2822 if (!bands[band])
2823 continue;
2824
2825 for (i = 0; i < bands[band]->n_channels; i++) {
2826 channel = &bands[band]->channels[i];
2827
2828 if (channel->flags & IEEE80211_CHAN_DISABLED)
2829 continue;
2830
2831 ch->allow_ht = true;
2832
2833 /* FIXME: when should we really allow VHT? */
2834 ch->allow_vht = true;
2835
2836 ch->allow_ibss =
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002837 !(channel->flags & IEEE80211_CHAN_NO_IR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002838
2839 ch->ht40plus =
2840 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
2841
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002842 ch->chan_radar =
2843 !!(channel->flags & IEEE80211_CHAN_RADAR);
2844
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002845 passive = channel->flags & IEEE80211_CHAN_NO_IR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002846 ch->passive = passive;
2847
2848 ch->freq = channel->center_freq;
Michal Kazior2d667212014-09-18 15:21:21 +02002849 ch->band_center_freq1 = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07002850 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07002851 ch->max_power = channel->max_power * 2;
2852 ch->max_reg_power = channel->max_reg_power * 2;
2853 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002854 ch->reg_class_id = 0; /* FIXME */
2855
2856 /* FIXME: why use only legacy modes, why not any
2857 * HT/VHT modes? Would that even make any
2858 * difference? */
2859 if (channel->band == IEEE80211_BAND_2GHZ)
2860 ch->mode = MODE_11G;
2861 else
2862 ch->mode = MODE_11A;
2863
2864 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
2865 continue;
2866
Michal Kazior7aa7a722014-08-25 12:09:38 +02002867 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002868 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
2869 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002870 ch->freq, ch->max_power, ch->max_reg_power,
2871 ch->max_antenna_gain, ch->mode);
2872
2873 ch++;
2874 }
2875 }
2876
2877 ret = ath10k_wmi_scan_chan_list(ar, &arg);
2878 kfree(arg.channels);
2879
2880 return ret;
2881}
2882
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002883static enum wmi_dfs_region
2884ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
2885{
2886 switch (dfs_region) {
2887 case NL80211_DFS_UNSET:
2888 return WMI_UNINIT_DFS_DOMAIN;
2889 case NL80211_DFS_FCC:
2890 return WMI_FCC_DFS_DOMAIN;
2891 case NL80211_DFS_ETSI:
2892 return WMI_ETSI_DFS_DOMAIN;
2893 case NL80211_DFS_JP:
2894 return WMI_MKK4_DFS_DOMAIN;
2895 }
2896 return WMI_UNINIT_DFS_DOMAIN;
2897}
2898
Michal Kaziorf7843d72013-07-16 09:38:52 +02002899static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002900{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002901 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002902 int ret;
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002903 enum wmi_dfs_region wmi_dfs_reg;
2904 enum nl80211_dfs_regions nl_dfs_reg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002905
Michal Kaziorf7843d72013-07-16 09:38:52 +02002906 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002907
2908 ret = ath10k_update_channel_list(ar);
2909 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002910 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002911
2912 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002913
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002914 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
2915 nl_dfs_reg = ar->dfs_detector->region;
2916 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
2917 } else {
2918 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
2919 }
2920
Kalle Valo5e3dd152013-06-12 20:52:10 +03002921 /* Target allows setting up per-band regdomain but ath_common provides
2922 * a combined one only */
2923 ret = ath10k_wmi_pdev_set_regdomain(ar,
Kalle Valoef8c0012014-02-13 18:13:12 +02002924 regpair->reg_domain,
2925 regpair->reg_domain, /* 2ghz */
2926 regpair->reg_domain, /* 5ghz */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002927 regpair->reg_2ghz_ctl,
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002928 regpair->reg_5ghz_ctl,
2929 wmi_dfs_reg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002930 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002931 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02002932}
Michal Kazior548db542013-07-05 16:15:15 +03002933
Michal Kaziorf7843d72013-07-16 09:38:52 +02002934static void ath10k_reg_notifier(struct wiphy *wiphy,
2935 struct regulatory_request *request)
2936{
2937 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
2938 struct ath10k *ar = hw->priv;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002939 bool result;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002940
2941 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
2942
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002943 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002944 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002945 request->dfs_region);
2946 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
2947 request->dfs_region);
2948 if (!result)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002949 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002950 request->dfs_region);
2951 }
2952
Michal Kaziorf7843d72013-07-16 09:38:52 +02002953 mutex_lock(&ar->conf_mutex);
2954 if (ar->state == ATH10K_STATE_ON)
2955 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03002956 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002957}
2958
2959/***************/
2960/* TX handlers */
2961/***************/
2962
Michal Kazior96d828d2015-03-31 10:26:23 +00002963void ath10k_mac_tx_lock(struct ath10k *ar, int reason)
2964{
2965 lockdep_assert_held(&ar->htt.tx_lock);
2966
2967 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
2968 ar->tx_paused |= BIT(reason);
2969 ieee80211_stop_queues(ar->hw);
2970}
2971
2972static void ath10k_mac_tx_unlock_iter(void *data, u8 *mac,
2973 struct ieee80211_vif *vif)
2974{
2975 struct ath10k *ar = data;
2976 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2977
2978 if (arvif->tx_paused)
2979 return;
2980
2981 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
2982}
2983
2984void ath10k_mac_tx_unlock(struct ath10k *ar, int reason)
2985{
2986 lockdep_assert_held(&ar->htt.tx_lock);
2987
2988 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
2989 ar->tx_paused &= ~BIT(reason);
2990
2991 if (ar->tx_paused)
2992 return;
2993
2994 ieee80211_iterate_active_interfaces_atomic(ar->hw,
2995 IEEE80211_IFACE_ITER_RESUME_ALL,
2996 ath10k_mac_tx_unlock_iter,
2997 ar);
2998}
2999
3000void ath10k_mac_vif_tx_lock(struct ath10k_vif *arvif, int reason)
3001{
3002 struct ath10k *ar = arvif->ar;
3003
3004 lockdep_assert_held(&ar->htt.tx_lock);
3005
3006 WARN_ON(reason >= BITS_PER_LONG);
3007 arvif->tx_paused |= BIT(reason);
3008 ieee80211_stop_queue(ar->hw, arvif->vdev_id);
3009}
3010
3011void ath10k_mac_vif_tx_unlock(struct ath10k_vif *arvif, int reason)
3012{
3013 struct ath10k *ar = arvif->ar;
3014
3015 lockdep_assert_held(&ar->htt.tx_lock);
3016
3017 WARN_ON(reason >= BITS_PER_LONG);
3018 arvif->tx_paused &= ~BIT(reason);
3019
3020 if (ar->tx_paused)
3021 return;
3022
3023 if (arvif->tx_paused)
3024 return;
3025
3026 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3027}
3028
Michal Kaziorb4aa5392015-03-31 10:26:24 +00003029static void ath10k_mac_vif_handle_tx_pause(struct ath10k_vif *arvif,
3030 enum wmi_tlv_tx_pause_id pause_id,
3031 enum wmi_tlv_tx_pause_action action)
3032{
3033 struct ath10k *ar = arvif->ar;
3034
3035 lockdep_assert_held(&ar->htt.tx_lock);
3036
Michal Kazioracd0b272015-07-09 13:08:38 +02003037 switch (action) {
3038 case WMI_TLV_TX_PAUSE_ACTION_STOP:
3039 ath10k_mac_vif_tx_lock(arvif, pause_id);
Michal Kaziorb4aa5392015-03-31 10:26:24 +00003040 break;
Michal Kazioracd0b272015-07-09 13:08:38 +02003041 case WMI_TLV_TX_PAUSE_ACTION_WAKE:
3042 ath10k_mac_vif_tx_unlock(arvif, pause_id);
3043 break;
Michal Kaziorb4aa5392015-03-31 10:26:24 +00003044 default:
Michal Kazioracd0b272015-07-09 13:08:38 +02003045 ath10k_warn(ar, "received unknown tx pause action %d on vdev %i, ignoring\n",
3046 action, arvif->vdev_id);
Michal Kaziorb4aa5392015-03-31 10:26:24 +00003047 break;
3048 }
3049}
3050
3051struct ath10k_mac_tx_pause {
3052 u32 vdev_id;
3053 enum wmi_tlv_tx_pause_id pause_id;
3054 enum wmi_tlv_tx_pause_action action;
3055};
3056
3057static void ath10k_mac_handle_tx_pause_iter(void *data, u8 *mac,
3058 struct ieee80211_vif *vif)
3059{
3060 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3061 struct ath10k_mac_tx_pause *arg = data;
3062
Michal Kazioracd0b272015-07-09 13:08:38 +02003063 if (arvif->vdev_id != arg->vdev_id)
3064 return;
3065
Michal Kaziorb4aa5392015-03-31 10:26:24 +00003066 ath10k_mac_vif_handle_tx_pause(arvif, arg->pause_id, arg->action);
3067}
3068
Michal Kazioracd0b272015-07-09 13:08:38 +02003069void ath10k_mac_handle_tx_pause_vdev(struct ath10k *ar, u32 vdev_id,
3070 enum wmi_tlv_tx_pause_id pause_id,
3071 enum wmi_tlv_tx_pause_action action)
Michal Kaziorb4aa5392015-03-31 10:26:24 +00003072{
3073 struct ath10k_mac_tx_pause arg = {
3074 .vdev_id = vdev_id,
3075 .pause_id = pause_id,
3076 .action = action,
3077 };
3078
3079 spin_lock_bh(&ar->htt.tx_lock);
3080 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3081 IEEE80211_IFACE_ITER_RESUME_ALL,
3082 ath10k_mac_handle_tx_pause_iter,
3083 &arg);
3084 spin_unlock_bh(&ar->htt.tx_lock);
3085}
3086
Michal Kazior42c3aa62013-10-02 11:03:38 +02003087static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
3088{
3089 if (ieee80211_is_mgmt(hdr->frame_control))
3090 return HTT_DATA_TX_EXT_TID_MGMT;
3091
3092 if (!ieee80211_is_data_qos(hdr->frame_control))
3093 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
3094
3095 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
3096 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
3097
3098 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
3099}
3100
Michal Kazior2b37c292014-09-02 11:00:22 +03003101static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02003102{
Michal Kazior2b37c292014-09-02 11:00:22 +03003103 if (vif)
3104 return ath10k_vif_to_arvif(vif)->vdev_id;
Michal Kaziorddb6ad72013-10-02 11:03:39 +02003105
Michal Kazior1bbc0972014-04-08 09:45:47 +03003106 if (ar->monitor_started)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02003107 return ar->monitor_vdev_id;
3108
Michal Kazior7aa7a722014-08-25 12:09:38 +02003109 ath10k_warn(ar, "failed to resolve vdev id\n");
Michal Kaziorddb6ad72013-10-02 11:03:39 +02003110 return 0;
3111}
3112
Michal Kaziord740d8f2015-03-30 09:51:51 +03003113static enum ath10k_hw_txrx_mode
3114ath10k_tx_h_get_txmode(struct ath10k *ar, struct ieee80211_vif *vif,
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003115 struct ieee80211_sta *sta, struct sk_buff *skb)
Michal Kaziord740d8f2015-03-30 09:51:51 +03003116{
3117 const struct ieee80211_hdr *hdr = (void *)skb->data;
3118 __le16 fc = hdr->frame_control;
3119
3120 if (!vif || vif->type == NL80211_IFTYPE_MONITOR)
3121 return ATH10K_HW_TXRX_RAW;
3122
3123 if (ieee80211_is_mgmt(fc))
3124 return ATH10K_HW_TXRX_MGMT;
3125
3126 /* Workaround:
3127 *
3128 * NullFunc frames are mostly used to ping if a client or AP are still
3129 * reachable and responsive. This implies tx status reports must be
3130 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
3131 * come to a conclusion that the other end disappeared and tear down
3132 * BSS connection or it can never disconnect from BSS/client (which is
3133 * the case).
3134 *
3135 * Firmware with HTT older than 3.0 delivers incorrect tx status for
3136 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
3137 * which seems to deliver correct tx reports for NullFunc frames. The
3138 * downside of using it is it ignores client powersave state so it can
3139 * end up disconnecting sleeping clients in AP mode. It should fix STA
3140 * mode though because AP don't sleep.
3141 */
3142 if (ar->htt.target_version_major < 3 &&
3143 (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc)) &&
3144 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX, ar->fw_features))
3145 return ATH10K_HW_TXRX_MGMT;
3146
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003147 /* Workaround:
3148 *
3149 * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
3150 * NativeWifi txmode - it selects AP key instead of peer key. It seems
3151 * to work with Ethernet txmode so use it.
3152 */
3153 if (ieee80211_is_data_present(fc) && sta && sta->tdls)
3154 return ATH10K_HW_TXRX_ETHERNET;
3155
Michal Kaziord740d8f2015-03-30 09:51:51 +03003156 return ATH10K_HW_TXRX_NATIVE_WIFI;
3157}
3158
Michal Kazior4b604552014-07-21 21:03:09 +03003159/* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
3160 * Control in the header.
Kalle Valo5e3dd152013-06-12 20:52:10 +03003161 */
Michal Kazior4b604552014-07-21 21:03:09 +03003162static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003163{
3164 struct ieee80211_hdr *hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03003165 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003166 u8 *qos_ctl;
3167
3168 if (!ieee80211_is_data_qos(hdr->frame_control))
3169 return;
3170
3171 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02003172 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
3173 skb->data, (void *)qos_ctl - (void *)skb->data);
3174 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Michal Kaziorc21c64d2014-07-21 21:03:10 +03003175
Michal Kazior8bad8dc2015-03-11 14:25:26 +01003176 /* Some firmware revisions don't handle sending QoS NullFunc well.
3177 * These frames are mainly used for CQM purposes so it doesn't really
3178 * matter whether QoS NullFunc or NullFunc are sent.
Michal Kaziorc21c64d2014-07-21 21:03:10 +03003179 */
Michal Kaziorbf0a26d2015-01-24 12:14:51 +02003180 hdr = (void *)skb->data;
Michal Kazior8bad8dc2015-03-11 14:25:26 +01003181 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
Michal Kaziorc21c64d2014-07-21 21:03:10 +03003182 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
Michal Kazior8bad8dc2015-03-11 14:25:26 +01003183
3184 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003185}
3186
Michal Kaziord740d8f2015-03-30 09:51:51 +03003187static void ath10k_tx_h_8023(struct sk_buff *skb)
3188{
3189 struct ieee80211_hdr *hdr;
3190 struct rfc1042_hdr *rfc1042;
3191 struct ethhdr *eth;
3192 size_t hdrlen;
3193 u8 da[ETH_ALEN];
3194 u8 sa[ETH_ALEN];
3195 __be16 type;
3196
3197 hdr = (void *)skb->data;
3198 hdrlen = ieee80211_hdrlen(hdr->frame_control);
3199 rfc1042 = (void *)skb->data + hdrlen;
3200
3201 ether_addr_copy(da, ieee80211_get_DA(hdr));
3202 ether_addr_copy(sa, ieee80211_get_SA(hdr));
3203 type = rfc1042->snap_type;
3204
3205 skb_pull(skb, hdrlen + sizeof(*rfc1042));
3206 skb_push(skb, sizeof(*eth));
3207
3208 eth = (void *)skb->data;
3209 ether_addr_copy(eth->h_dest, da);
3210 ether_addr_copy(eth->h_source, sa);
3211 eth->h_proto = type;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003212}
3213
Michal Kazior4b604552014-07-21 21:03:09 +03003214static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
3215 struct ieee80211_vif *vif,
3216 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003217{
3218 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003219 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3220
3221 /* This is case only for P2P_GO */
3222 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
3223 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
3224 return;
3225
3226 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
3227 spin_lock_bh(&ar->data_lock);
3228 if (arvif->u.ap.noa_data)
3229 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
3230 GFP_ATOMIC))
3231 memcpy(skb_put(skb, arvif->u.ap.noa_len),
3232 arvif->u.ap.noa_data,
3233 arvif->u.ap.noa_len);
3234 spin_unlock_bh(&ar->data_lock);
3235 }
3236}
3237
Michal Kazior8d6d3622014-11-24 14:58:31 +01003238static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar)
3239{
3240 /* FIXME: Not really sure since when the behaviour changed. At some
3241 * point new firmware stopped requiring creation of peer entries for
3242 * offchannel tx (and actually creating them causes issues with wmi-htc
3243 * tx credit replenishment and reliability). Assuming it's at least 3.4
3244 * because that's when the `freq` was introduced to TX_FRM HTT command.
3245 */
3246 return !(ar->htt.target_version_major >= 3 &&
3247 ar->htt.target_version_minor >= 4);
3248}
3249
Michal Kaziord740d8f2015-03-30 09:51:51 +03003250static int ath10k_mac_tx_wmi_mgmt(struct ath10k *ar, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003251{
Michal Kaziord740d8f2015-03-30 09:51:51 +03003252 struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003253 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003254
Michal Kaziord740d8f2015-03-30 09:51:51 +03003255 spin_lock_bh(&ar->data_lock);
3256
3257 if (skb_queue_len(q) == ATH10K_MAX_NUM_MGMT_PENDING) {
3258 ath10k_warn(ar, "wmi mgmt tx queue is full\n");
3259 ret = -ENOSPC;
3260 goto unlock;
Michal Kazior961d4c32013-08-09 10:13:34 +02003261 }
3262
Michal Kaziord740d8f2015-03-30 09:51:51 +03003263 __skb_queue_tail(q, skb);
3264 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
3265
3266unlock:
3267 spin_unlock_bh(&ar->data_lock);
3268
3269 return ret;
3270}
3271
3272static void ath10k_mac_tx(struct ath10k *ar, struct sk_buff *skb)
3273{
3274 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3275 struct ath10k_htt *htt = &ar->htt;
3276 int ret = 0;
3277
3278 switch (cb->txmode) {
3279 case ATH10K_HW_TXRX_RAW:
3280 case ATH10K_HW_TXRX_NATIVE_WIFI:
3281 case ATH10K_HW_TXRX_ETHERNET:
3282 ret = ath10k_htt_tx(htt, skb);
3283 break;
3284 case ATH10K_HW_TXRX_MGMT:
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003285 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
Michal Kaziord740d8f2015-03-30 09:51:51 +03003286 ar->fw_features))
3287 ret = ath10k_mac_tx_wmi_mgmt(ar, skb);
3288 else if (ar->htt.target_version_major >= 3)
3289 ret = ath10k_htt_tx(htt, skb);
3290 else
3291 ret = ath10k_htt_mgmt_tx(htt, skb);
3292 break;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003293 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003294
3295 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003296 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
3297 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003298 ieee80211_free_txskb(ar->hw, skb);
3299 }
3300}
3301
3302void ath10k_offchan_tx_purge(struct ath10k *ar)
3303{
3304 struct sk_buff *skb;
3305
3306 for (;;) {
3307 skb = skb_dequeue(&ar->offchan_tx_queue);
3308 if (!skb)
3309 break;
3310
3311 ieee80211_free_txskb(ar->hw, skb);
3312 }
3313}
3314
3315void ath10k_offchan_tx_work(struct work_struct *work)
3316{
3317 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
3318 struct ath10k_peer *peer;
3319 struct ieee80211_hdr *hdr;
3320 struct sk_buff *skb;
3321 const u8 *peer_addr;
3322 int vdev_id;
3323 int ret;
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +03003324 unsigned long time_left;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003325
3326 /* FW requirement: We must create a peer before FW will send out
3327 * an offchannel frame. Otherwise the frame will be stuck and
3328 * never transmitted. We delete the peer upon tx completion.
3329 * It is unlikely that a peer for offchannel tx will already be
3330 * present. However it may be in some rare cases so account for that.
3331 * Otherwise we might remove a legitimate peer and break stuff. */
3332
3333 for (;;) {
3334 skb = skb_dequeue(&ar->offchan_tx_queue);
3335 if (!skb)
3336 break;
3337
3338 mutex_lock(&ar->conf_mutex);
3339
Michal Kazior7aa7a722014-08-25 12:09:38 +02003340 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003341 skb);
3342
3343 hdr = (struct ieee80211_hdr *)skb->data;
3344 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003345 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003346
3347 spin_lock_bh(&ar->data_lock);
3348 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
3349 spin_unlock_bh(&ar->data_lock);
3350
3351 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03003352 /* FIXME: should this use ath10k_warn()? */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003353 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003354 peer_addr, vdev_id);
3355
3356 if (!peer) {
Marek Puzyniak7390ed32015-03-30 09:51:52 +03003357 ret = ath10k_peer_create(ar, vdev_id, peer_addr,
3358 WMI_PEER_TYPE_DEFAULT);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003359 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003360 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003361 peer_addr, vdev_id, ret);
3362 }
3363
3364 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08003365 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003366 ar->offchan_tx_skb = skb;
3367 spin_unlock_bh(&ar->data_lock);
3368
Michal Kaziord740d8f2015-03-30 09:51:51 +03003369 ath10k_mac_tx(ar, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003370
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +03003371 time_left =
3372 wait_for_completion_timeout(&ar->offchan_tx_completed, 3 * HZ);
3373 if (time_left == 0)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003374 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003375 skb);
3376
3377 if (!peer) {
3378 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
3379 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003380 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003381 peer_addr, vdev_id, ret);
3382 }
3383
3384 mutex_unlock(&ar->conf_mutex);
3385 }
3386}
3387
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003388void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
3389{
3390 struct sk_buff *skb;
3391
3392 for (;;) {
3393 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3394 if (!skb)
3395 break;
3396
3397 ieee80211_free_txskb(ar->hw, skb);
3398 }
3399}
3400
3401void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
3402{
3403 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
3404 struct sk_buff *skb;
3405 int ret;
3406
3407 for (;;) {
3408 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3409 if (!skb)
3410 break;
3411
3412 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01003413 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003414 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02003415 ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01003416 ieee80211_free_txskb(ar->hw, skb);
3417 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003418 }
3419}
3420
Kalle Valo5e3dd152013-06-12 20:52:10 +03003421/************/
3422/* Scanning */
3423/************/
3424
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003425void __ath10k_scan_finish(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003426{
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003427 lockdep_assert_held(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003428
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003429 switch (ar->scan.state) {
3430 case ATH10K_SCAN_IDLE:
3431 break;
3432 case ATH10K_SCAN_RUNNING:
Michal Kazior7305d3e2014-11-24 14:58:33 +01003433 case ATH10K_SCAN_ABORTING:
3434 if (!ar->scan.is_roc)
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003435 ieee80211_scan_completed(ar->hw,
3436 (ar->scan.state ==
3437 ATH10K_SCAN_ABORTING));
Michal Kaziord710e752015-07-09 13:08:36 +02003438 else if (ar->scan.roc_notify)
3439 ieee80211_remain_on_channel_expired(ar->hw);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003440 /* fall through */
3441 case ATH10K_SCAN_STARTING:
3442 ar->scan.state = ATH10K_SCAN_IDLE;
3443 ar->scan_channel = NULL;
3444 ath10k_offchan_tx_purge(ar);
3445 cancel_delayed_work(&ar->scan.timeout);
3446 complete_all(&ar->scan.completed);
3447 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003448 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003449}
Kalle Valo5e3dd152013-06-12 20:52:10 +03003450
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003451void ath10k_scan_finish(struct ath10k *ar)
3452{
3453 spin_lock_bh(&ar->data_lock);
3454 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003455 spin_unlock_bh(&ar->data_lock);
3456}
3457
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003458static int ath10k_scan_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003459{
3460 struct wmi_stop_scan_arg arg = {
3461 .req_id = 1, /* FIXME */
3462 .req_type = WMI_SCAN_STOP_ONE,
3463 .u.scan_id = ATH10K_SCAN_ID,
3464 };
3465 int ret;
3466
3467 lockdep_assert_held(&ar->conf_mutex);
3468
Kalle Valo5e3dd152013-06-12 20:52:10 +03003469 ret = ath10k_wmi_stop_scan(ar, &arg);
3470 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003471 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003472 goto out;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003473 }
3474
Kalle Valo5e3dd152013-06-12 20:52:10 +03003475 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003476 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003477 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003478 ret = -ETIMEDOUT;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003479 } else if (ret > 0) {
3480 ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003481 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003482
3483out:
3484 /* Scan state should be updated upon scan completion but in case
3485 * firmware fails to deliver the event (for whatever reason) it is
3486 * desired to clean up scan state anyway. Firmware may have just
3487 * dropped the scan completion event delivery due to transport pipe
3488 * being overflown with data and/or it can recover on its own before
3489 * next scan request is submitted.
3490 */
3491 spin_lock_bh(&ar->data_lock);
3492 if (ar->scan.state != ATH10K_SCAN_IDLE)
3493 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003494 spin_unlock_bh(&ar->data_lock);
3495
3496 return ret;
3497}
3498
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003499static void ath10k_scan_abort(struct ath10k *ar)
3500{
3501 int ret;
3502
3503 lockdep_assert_held(&ar->conf_mutex);
3504
3505 spin_lock_bh(&ar->data_lock);
3506
3507 switch (ar->scan.state) {
3508 case ATH10K_SCAN_IDLE:
3509 /* This can happen if timeout worker kicked in and called
3510 * abortion while scan completion was being processed.
3511 */
3512 break;
3513 case ATH10K_SCAN_STARTING:
3514 case ATH10K_SCAN_ABORTING:
Michal Kazior7aa7a722014-08-25 12:09:38 +02003515 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003516 ath10k_scan_state_str(ar->scan.state),
3517 ar->scan.state);
3518 break;
3519 case ATH10K_SCAN_RUNNING:
3520 ar->scan.state = ATH10K_SCAN_ABORTING;
3521 spin_unlock_bh(&ar->data_lock);
3522
3523 ret = ath10k_scan_stop(ar);
3524 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003525 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003526
3527 spin_lock_bh(&ar->data_lock);
3528 break;
3529 }
3530
3531 spin_unlock_bh(&ar->data_lock);
3532}
3533
3534void ath10k_scan_timeout_work(struct work_struct *work)
3535{
3536 struct ath10k *ar = container_of(work, struct ath10k,
3537 scan.timeout.work);
3538
3539 mutex_lock(&ar->conf_mutex);
3540 ath10k_scan_abort(ar);
3541 mutex_unlock(&ar->conf_mutex);
3542}
3543
Kalle Valo5e3dd152013-06-12 20:52:10 +03003544static int ath10k_start_scan(struct ath10k *ar,
3545 const struct wmi_start_scan_arg *arg)
3546{
3547 int ret;
3548
3549 lockdep_assert_held(&ar->conf_mutex);
3550
3551 ret = ath10k_wmi_start_scan(ar, arg);
3552 if (ret)
3553 return ret;
3554
Kalle Valo5e3dd152013-06-12 20:52:10 +03003555 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
3556 if (ret == 0) {
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003557 ret = ath10k_scan_stop(ar);
3558 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003559 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003560
3561 return -ETIMEDOUT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003562 }
3563
Ben Greear2f9eec02015-02-15 16:50:38 +02003564 /* If we failed to start the scan, return error code at
3565 * this point. This is probably due to some issue in the
3566 * firmware, but no need to wedge the driver due to that...
3567 */
3568 spin_lock_bh(&ar->data_lock);
3569 if (ar->scan.state == ATH10K_SCAN_IDLE) {
3570 spin_unlock_bh(&ar->data_lock);
3571 return -EINVAL;
3572 }
3573 spin_unlock_bh(&ar->data_lock);
3574
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003575 /* Add a 200ms margin to account for event/command processing */
3576 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
3577 msecs_to_jiffies(arg->max_scan_time+200));
Kalle Valo5e3dd152013-06-12 20:52:10 +03003578 return 0;
3579}
3580
3581/**********************/
3582/* mac80211 callbacks */
3583/**********************/
3584
3585static void ath10k_tx(struct ieee80211_hw *hw,
3586 struct ieee80211_tx_control *control,
3587 struct sk_buff *skb)
3588{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003589 struct ath10k *ar = hw->priv;
Michal Kazior4b604552014-07-21 21:03:09 +03003590 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3591 struct ieee80211_vif *vif = info->control.vif;
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003592 struct ieee80211_sta *sta = control->sta;
Michal Kazior4b604552014-07-21 21:03:09 +03003593 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Michal Kaziord740d8f2015-03-30 09:51:51 +03003594 __le16 fc = hdr->frame_control;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003595
3596 /* We should disable CCK RATE due to P2P */
3597 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003598 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003599
Michal Kazior4b604552014-07-21 21:03:09 +03003600 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
Michal Kazior6fcafef2015-03-30 09:51:51 +03003601 ATH10K_SKB_CB(skb)->htt.freq = 0;
Michal Kazior4b604552014-07-21 21:03:09 +03003602 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
Michal Kazior2b37c292014-09-02 11:00:22 +03003603 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003604 ATH10K_SKB_CB(skb)->txmode = ath10k_tx_h_get_txmode(ar, vif, sta, skb);
Michal Kaziord740d8f2015-03-30 09:51:51 +03003605 ATH10K_SKB_CB(skb)->is_protected = ieee80211_has_protected(fc);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003606
Michal Kaziord740d8f2015-03-30 09:51:51 +03003607 switch (ATH10K_SKB_CB(skb)->txmode) {
3608 case ATH10K_HW_TXRX_MGMT:
3609 case ATH10K_HW_TXRX_NATIVE_WIFI:
Michal Kazior4b604552014-07-21 21:03:09 +03003610 ath10k_tx_h_nwifi(hw, skb);
Michal Kazior4b604552014-07-21 21:03:09 +03003611 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
3612 ath10k_tx_h_seq_no(vif, skb);
Michal Kaziord740d8f2015-03-30 09:51:51 +03003613 break;
3614 case ATH10K_HW_TXRX_ETHERNET:
3615 ath10k_tx_h_8023(skb);
3616 break;
3617 case ATH10K_HW_TXRX_RAW:
3618 /* FIXME: Packet injection isn't implemented. It should be
3619 * doable with firmware 10.2 on qca988x.
3620 */
3621 WARN_ON_ONCE(1);
3622 ieee80211_free_txskb(hw, skb);
3623 return;
Michal Kaziorcf84bd42013-07-16 11:04:54 +02003624 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003625
Kalle Valo5e3dd152013-06-12 20:52:10 +03003626 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
3627 spin_lock_bh(&ar->data_lock);
Michal Kazior8d6d3622014-11-24 14:58:31 +01003628 ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003629 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003630 spin_unlock_bh(&ar->data_lock);
3631
Michal Kazior8d6d3622014-11-24 14:58:31 +01003632 if (ath10k_mac_need_offchan_tx_work(ar)) {
3633 ATH10K_SKB_CB(skb)->htt.freq = 0;
3634 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003635
Michal Kazior8d6d3622014-11-24 14:58:31 +01003636 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
3637 skb);
3638
3639 skb_queue_tail(&ar->offchan_tx_queue, skb);
3640 ieee80211_queue_work(hw, &ar->offchan_tx_work);
3641 return;
3642 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003643 }
3644
Michal Kaziord740d8f2015-03-30 09:51:51 +03003645 ath10k_mac_tx(ar, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003646}
3647
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003648/* Must not be called with conf_mutex held as workers can use that also. */
Michal Kazior7962b0d2014-10-28 10:34:38 +01003649void ath10k_drain_tx(struct ath10k *ar)
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003650{
3651 /* make sure rcu-protected mac80211 tx path itself is drained */
3652 synchronize_net();
3653
3654 ath10k_offchan_tx_purge(ar);
3655 ath10k_mgmt_over_wmi_tx_purge(ar);
3656
3657 cancel_work_sync(&ar->offchan_tx_work);
3658 cancel_work_sync(&ar->wmi_mgmt_tx_work);
3659}
3660
Michal Kazioraffd3212013-07-16 09:54:35 +02003661void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02003662{
Michal Kaziord9bc4b92014-04-23 19:30:06 +03003663 struct ath10k_vif *arvif;
3664
Michal Kazior818bdd12013-07-16 09:38:57 +02003665 lockdep_assert_held(&ar->conf_mutex);
3666
Michal Kazior19337472014-08-28 12:58:16 +02003667 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
3668 ar->filter_flags = 0;
3669 ar->monitor = false;
Michal Kazior500ff9f2015-03-31 10:26:21 +00003670 ar->monitor_arvif = NULL;
Michal Kazior19337472014-08-28 12:58:16 +02003671
3672 if (ar->monitor_started)
Michal Kazior1bbc0972014-04-08 09:45:47 +03003673 ath10k_monitor_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +02003674
3675 ar->monitor_started = false;
Michal Kazior96d828d2015-03-31 10:26:23 +00003676 ar->tx_paused = 0;
Michal Kazior1bbc0972014-04-08 09:45:47 +03003677
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003678 ath10k_scan_finish(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02003679 ath10k_peer_cleanup_all(ar);
3680 ath10k_core_stop(ar);
3681 ath10k_hif_power_down(ar);
3682
3683 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03003684 list_for_each_entry(arvif, &ar->arvifs, list)
3685 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kazior818bdd12013-07-16 09:38:57 +02003686 spin_unlock_bh(&ar->data_lock);
3687}
3688
Ben Greear46acf7b2014-05-16 17:15:38 +03003689static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
3690{
3691 struct ath10k *ar = hw->priv;
3692
3693 mutex_lock(&ar->conf_mutex);
3694
3695 if (ar->cfg_tx_chainmask) {
3696 *tx_ant = ar->cfg_tx_chainmask;
3697 *rx_ant = ar->cfg_rx_chainmask;
3698 } else {
3699 *tx_ant = ar->supp_tx_chainmask;
3700 *rx_ant = ar->supp_rx_chainmask;
3701 }
3702
3703 mutex_unlock(&ar->conf_mutex);
3704
3705 return 0;
3706}
3707
Ben Greear5572a952014-11-24 16:22:10 +02003708static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
3709{
3710 /* It is not clear that allowing gaps in chainmask
3711 * is helpful. Probably it will not do what user
3712 * is hoping for, so warn in that case.
3713 */
3714 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
3715 return;
3716
3717 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
3718 dbg, cm);
3719}
3720
Ben Greear46acf7b2014-05-16 17:15:38 +03003721static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
3722{
3723 int ret;
3724
3725 lockdep_assert_held(&ar->conf_mutex);
3726
Ben Greear5572a952014-11-24 16:22:10 +02003727 ath10k_check_chain_mask(ar, tx_ant, "tx");
3728 ath10k_check_chain_mask(ar, rx_ant, "rx");
3729
Ben Greear46acf7b2014-05-16 17:15:38 +03003730 ar->cfg_tx_chainmask = tx_ant;
3731 ar->cfg_rx_chainmask = rx_ant;
3732
3733 if ((ar->state != ATH10K_STATE_ON) &&
3734 (ar->state != ATH10K_STATE_RESTARTED))
3735 return 0;
3736
3737 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
3738 tx_ant);
3739 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003740 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03003741 ret, tx_ant);
3742 return ret;
3743 }
3744
3745 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
3746 rx_ant);
3747 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003748 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03003749 ret, rx_ant);
3750 return ret;
3751 }
3752
3753 return 0;
3754}
3755
3756static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
3757{
3758 struct ath10k *ar = hw->priv;
3759 int ret;
3760
3761 mutex_lock(&ar->conf_mutex);
3762 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
3763 mutex_unlock(&ar->conf_mutex);
3764 return ret;
3765}
3766
Kalle Valo5e3dd152013-06-12 20:52:10 +03003767static int ath10k_start(struct ieee80211_hw *hw)
3768{
3769 struct ath10k *ar = hw->priv;
Janusz Dziedzic24ab13e2015-04-01 22:53:18 +03003770 u32 burst_enable;
Michal Kazior818bdd12013-07-16 09:38:57 +02003771 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003772
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003773 /*
3774 * This makes sense only when restarting hw. It is harmless to call
3775 * uncoditionally. This is necessary to make sure no HTT/WMI tx
3776 * commands will be submitted while restarting.
3777 */
3778 ath10k_drain_tx(ar);
3779
Michal Kazior548db542013-07-05 16:15:15 +03003780 mutex_lock(&ar->conf_mutex);
3781
Michal Kaziorc5058f52014-05-26 12:46:03 +03003782 switch (ar->state) {
3783 case ATH10K_STATE_OFF:
3784 ar->state = ATH10K_STATE_ON;
3785 break;
3786 case ATH10K_STATE_RESTARTING:
3787 ath10k_halt(ar);
3788 ar->state = ATH10K_STATE_RESTARTED;
3789 break;
3790 case ATH10K_STATE_ON:
3791 case ATH10K_STATE_RESTARTED:
3792 case ATH10K_STATE_WEDGED:
3793 WARN_ON(1);
Michal Kazior818bdd12013-07-16 09:38:57 +02003794 ret = -EINVAL;
Michal Kaziorae254432014-05-26 12:46:02 +03003795 goto err;
Kalle Valo43d2a302014-09-10 18:23:30 +03003796 case ATH10K_STATE_UTF:
3797 ret = -EBUSY;
3798 goto err;
Michal Kazior818bdd12013-07-16 09:38:57 +02003799 }
3800
3801 ret = ath10k_hif_power_up(ar);
3802 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003803 ath10k_err(ar, "Could not init hif: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003804 goto err_off;
Michal Kazior818bdd12013-07-16 09:38:57 +02003805 }
3806
Kalle Valo43d2a302014-09-10 18:23:30 +03003807 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
Michal Kazior818bdd12013-07-16 09:38:57 +02003808 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003809 ath10k_err(ar, "Could not init core: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003810 goto err_power_down;
Michal Kazior818bdd12013-07-16 09:38:57 +02003811 }
3812
Bartosz Markowski226a3392013-09-26 17:47:16 +02003813 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03003814 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003815 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003816 goto err_core_stop;
3817 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003818
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01003819 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03003820 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003821 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003822 goto err_core_stop;
3823 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003824
Michal Kaziorcf327842015-03-31 10:26:25 +00003825 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
3826 ret = ath10k_wmi_adaptive_qcs(ar, true);
3827 if (ret) {
3828 ath10k_warn(ar, "failed to enable adaptive qcs: %d\n",
3829 ret);
3830 goto err_core_stop;
3831 }
3832 }
3833
Janusz Dziedzic24ab13e2015-04-01 22:53:18 +03003834 if (test_bit(WMI_SERVICE_BURST, ar->wmi.svc_map)) {
3835 burst_enable = ar->wmi.pdev_param->burst_enable;
3836 ret = ath10k_wmi_pdev_set_param(ar, burst_enable, 0);
3837 if (ret) {
3838 ath10k_warn(ar, "failed to disable burst: %d\n", ret);
3839 goto err_core_stop;
3840 }
3841 }
3842
Ben Greear46acf7b2014-05-16 17:15:38 +03003843 if (ar->cfg_tx_chainmask)
3844 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
3845 ar->cfg_rx_chainmask);
3846
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003847 /*
3848 * By default FW set ARP frames ac to voice (6). In that case ARP
3849 * exchange is not working properly for UAPSD enabled AP. ARP requests
3850 * which arrives with access category 0 are processed by network stack
3851 * and send back with access category 0, but FW changes access category
3852 * to 6. Set ARP frames access category to best effort (0) solves
3853 * this problem.
3854 */
3855
3856 ret = ath10k_wmi_pdev_set_param(ar,
3857 ar->wmi.pdev_param->arp_ac_override, 0);
3858 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003859 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003860 ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003861 goto err_core_stop;
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003862 }
3863
Ashok Raj Nagarajan575f1c32015-03-19 16:37:59 +05303864 ret = ath10k_wmi_pdev_set_param(ar,
3865 ar->wmi.pdev_param->ani_enable, 1);
3866 if (ret) {
3867 ath10k_warn(ar, "failed to enable ani by default: %d\n",
3868 ret);
3869 goto err_core_stop;
3870 }
3871
Ashok Raj Nagarajanb3e71d72015-03-19 16:38:00 +05303872 ar->ani_enabled = true;
3873
Michal Kaziord6500972014-04-08 09:56:09 +03003874 ar->num_started_vdevs = 0;
Michal Kaziorf7843d72013-07-16 09:38:52 +02003875 ath10k_regd_update(ar);
3876
Simon Wunderlich855aed12014-08-02 09:12:54 +03003877 ath10k_spectral_start(ar);
Rajkumar Manoharan8515b5c2015-03-15 20:36:22 +05303878 ath10k_thermal_set_throttling(ar);
Simon Wunderlich855aed12014-08-02 09:12:54 +03003879
Michal Kaziorae254432014-05-26 12:46:02 +03003880 mutex_unlock(&ar->conf_mutex);
3881 return 0;
3882
3883err_core_stop:
3884 ath10k_core_stop(ar);
3885
3886err_power_down:
3887 ath10k_hif_power_down(ar);
3888
3889err_off:
3890 ar->state = ATH10K_STATE_OFF;
3891
3892err:
Michal Kazior548db542013-07-05 16:15:15 +03003893 mutex_unlock(&ar->conf_mutex);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01003894 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003895}
3896
3897static void ath10k_stop(struct ieee80211_hw *hw)
3898{
3899 struct ath10k *ar = hw->priv;
3900
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003901 ath10k_drain_tx(ar);
3902
Michal Kazior548db542013-07-05 16:15:15 +03003903 mutex_lock(&ar->conf_mutex);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003904 if (ar->state != ATH10K_STATE_OFF) {
Michal Kazior818bdd12013-07-16 09:38:57 +02003905 ath10k_halt(ar);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003906 ar->state = ATH10K_STATE_OFF;
3907 }
Michal Kazior548db542013-07-05 16:15:15 +03003908 mutex_unlock(&ar->conf_mutex);
3909
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003910 cancel_delayed_work_sync(&ar->scan.timeout);
Michal Kazioraffd3212013-07-16 09:54:35 +02003911 cancel_work_sync(&ar->restart_work);
3912}
3913
Michal Kaziorad088bf2013-10-16 15:44:46 +03003914static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02003915{
Michal Kaziorad088bf2013-10-16 15:44:46 +03003916 struct ath10k_vif *arvif;
3917 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02003918
3919 lockdep_assert_held(&ar->conf_mutex);
3920
Michal Kaziorad088bf2013-10-16 15:44:46 +03003921 list_for_each_entry(arvif, &ar->arvifs, list) {
3922 ret = ath10k_mac_vif_setup_ps(arvif);
3923 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003924 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03003925 break;
3926 }
3927 }
Michal Kazioraffd3212013-07-16 09:54:35 +02003928
Michal Kaziorad088bf2013-10-16 15:44:46 +03003929 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003930}
3931
Michal Kazior7d9d5582014-10-21 10:40:15 +03003932static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
3933{
3934 int ret;
3935 u32 param;
3936
3937 lockdep_assert_held(&ar->conf_mutex);
3938
3939 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
3940
3941 param = ar->wmi.pdev_param->txpower_limit2g;
3942 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3943 if (ret) {
3944 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
3945 txpower, ret);
3946 return ret;
3947 }
3948
3949 param = ar->wmi.pdev_param->txpower_limit5g;
3950 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3951 if (ret) {
3952 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
3953 txpower, ret);
3954 return ret;
3955 }
3956
3957 return 0;
3958}
3959
3960static int ath10k_mac_txpower_recalc(struct ath10k *ar)
3961{
3962 struct ath10k_vif *arvif;
3963 int ret, txpower = -1;
3964
3965 lockdep_assert_held(&ar->conf_mutex);
3966
3967 list_for_each_entry(arvif, &ar->arvifs, list) {
3968 WARN_ON(arvif->txpower < 0);
3969
3970 if (txpower == -1)
3971 txpower = arvif->txpower;
3972 else
3973 txpower = min(txpower, arvif->txpower);
3974 }
3975
3976 if (WARN_ON(txpower == -1))
3977 return -EINVAL;
3978
3979 ret = ath10k_mac_txpower_setup(ar, txpower);
3980 if (ret) {
3981 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
3982 txpower, ret);
3983 return ret;
3984 }
3985
3986 return 0;
3987}
3988
Kalle Valo5e3dd152013-06-12 20:52:10 +03003989static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
3990{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003991 struct ath10k *ar = hw->priv;
3992 struct ieee80211_conf *conf = &hw->conf;
3993 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003994
3995 mutex_lock(&ar->conf_mutex);
3996
Michal Kazioraffd3212013-07-16 09:54:35 +02003997 if (changed & IEEE80211_CONF_CHANGE_PS)
3998 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003999
4000 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
Michal Kazior19337472014-08-28 12:58:16 +02004001 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
4002 ret = ath10k_monitor_recalc(ar);
4003 if (ret)
4004 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004005 }
4006
4007 mutex_unlock(&ar->conf_mutex);
4008 return ret;
4009}
4010
Ben Greear5572a952014-11-24 16:22:10 +02004011static u32 get_nss_from_chainmask(u16 chain_mask)
4012{
4013 if ((chain_mask & 0x15) == 0x15)
4014 return 4;
4015 else if ((chain_mask & 0x7) == 0x7)
4016 return 3;
4017 else if ((chain_mask & 0x3) == 0x3)
4018 return 2;
4019 return 1;
4020}
4021
Kalle Valo5e3dd152013-06-12 20:52:10 +03004022/*
4023 * TODO:
4024 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
4025 * because we will send mgmt frames without CCK. This requirement
4026 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
4027 * in the TX packet.
4028 */
4029static int ath10k_add_interface(struct ieee80211_hw *hw,
4030 struct ieee80211_vif *vif)
4031{
4032 struct ath10k *ar = hw->priv;
4033 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4034 enum wmi_sta_powersave_param param;
4035 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02004036 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004037 int bit;
Michal Kazior96d828d2015-03-31 10:26:23 +00004038 int i;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004039 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004040
Johannes Berg848955c2014-11-11 12:48:42 +01004041 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
4042
Kalle Valo5e3dd152013-06-12 20:52:10 +03004043 mutex_lock(&ar->conf_mutex);
4044
Michal Kazior0dbd09e2013-07-31 10:55:14 +02004045 memset(arvif, 0, sizeof(*arvif));
4046
Kalle Valo5e3dd152013-06-12 20:52:10 +03004047 arvif->ar = ar;
4048 arvif->vif = vif;
4049
Ben Greeare63b33f2013-10-22 14:54:14 -07004050 INIT_LIST_HEAD(&arvif->list);
Michal Kazior81a9a172015-03-05 16:02:17 +02004051 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
Michal Kaziorcc9904e2015-03-10 16:22:01 +02004052 INIT_DELAYED_WORK(&arvif->connection_loss_work,
4053 ath10k_mac_vif_sta_connection_loss_work);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03004054
Michal Kazior45c9abc2015-04-21 20:42:58 +03004055 for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) {
4056 arvif->bitrate_mask.control[i].legacy = 0xffffffff;
4057 memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff,
4058 sizeof(arvif->bitrate_mask.control[i].ht_mcs));
4059 memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff,
4060 sizeof(arvif->bitrate_mask.control[i].vht_mcs));
4061 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004062
Ben Greeara9aefb32014-08-12 11:02:19 +03004063 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004064 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03004065 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03004066 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004067 }
Ben Greear16c11172014-09-23 14:17:16 -07004068 bit = __ffs64(ar->free_vdev_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004069
Ben Greear16c11172014-09-23 14:17:16 -07004070 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
4071 bit, ar->free_vdev_map);
4072
4073 arvif->vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004074 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004075
Kalle Valo5e3dd152013-06-12 20:52:10 +03004076 switch (vif->type) {
Michal Kazior75d2bd42014-12-12 12:41:39 +01004077 case NL80211_IFTYPE_P2P_DEVICE:
4078 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4079 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
4080 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004081 case NL80211_IFTYPE_UNSPECIFIED:
4082 case NL80211_IFTYPE_STATION:
4083 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4084 if (vif->p2p)
4085 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
4086 break;
4087 case NL80211_IFTYPE_ADHOC:
4088 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
4089 break;
4090 case NL80211_IFTYPE_AP:
4091 arvif->vdev_type = WMI_VDEV_TYPE_AP;
4092
4093 if (vif->p2p)
4094 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
4095 break;
4096 case NL80211_IFTYPE_MONITOR:
4097 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
4098 break;
4099 default:
4100 WARN_ON(1);
4101 break;
4102 }
4103
Michal Kazior96d828d2015-03-31 10:26:23 +00004104 /* Using vdev_id as queue number will make it very easy to do per-vif
4105 * tx queue locking. This shouldn't wrap due to interface combinations
4106 * but do a modulo for correctness sake and prevent using offchannel tx
4107 * queues for regular vif tx.
4108 */
4109 vif->cab_queue = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
4110 for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++)
4111 vif->hw_queue[i] = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
4112
Michal Kazior64badcb2014-09-18 11:18:02 +03004113 /* Some firmware revisions don't wait for beacon tx completion before
4114 * sending another SWBA event. This could lead to hardware using old
4115 * (freed) beacon data in some cases, e.g. tx credit starvation
4116 * combined with missed TBTT. This is very very rare.
4117 *
4118 * On non-IOMMU-enabled hosts this could be a possible security issue
4119 * because hw could beacon some random data on the air. On
4120 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
4121 * device would crash.
4122 *
4123 * Since there are no beacon tx completions (implicit nor explicit)
4124 * propagated to host the only workaround for this is to allocate a
4125 * DMA-coherent buffer for a lifetime of a vif and use it for all
4126 * beacon tx commands. Worst case for this approach is some beacons may
4127 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
4128 */
4129 if (vif->type == NL80211_IFTYPE_ADHOC ||
4130 vif->type == NL80211_IFTYPE_AP) {
4131 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
4132 IEEE80211_MAX_FRAME_LEN,
4133 &arvif->beacon_paddr,
Rajkumar Manoharan82d7aba2014-10-10 17:38:27 +05304134 GFP_ATOMIC);
Michal Kazior64badcb2014-09-18 11:18:02 +03004135 if (!arvif->beacon_buf) {
4136 ret = -ENOMEM;
4137 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
4138 ret);
4139 goto err;
4140 }
4141 }
4142
4143 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
4144 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
4145 arvif->beacon_buf ? "single-buf" : "per-skb");
Kalle Valo5e3dd152013-06-12 20:52:10 +03004146
4147 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
4148 arvif->vdev_subtype, vif->addr);
4149 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004150 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004151 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004152 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004153 }
4154
Ben Greear16c11172014-09-23 14:17:16 -07004155 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03004156 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004157
Michal Kazior46725b152015-01-28 09:57:49 +02004158 /* It makes no sense to have firmware do keepalives. mac80211 already
4159 * takes care of this with idle connection polling.
4160 */
4161 ret = ath10k_mac_vif_disable_keepalive(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004162 if (ret) {
Michal Kazior46725b152015-01-28 09:57:49 +02004163 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004164 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004165 goto err_vdev_delete;
4166 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004167
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004168 arvif->def_wep_key_idx = -1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004169
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004170 vdev_param = ar->wmi.vdev_param->tx_encap_type;
4171 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004172 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02004173 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14a2013-10-16 15:44:45 +03004174 if (ret && ret != -EOPNOTSUPP) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004175 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004176 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004177 goto err_vdev_delete;
4178 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004179
Ben Greear5572a952014-11-24 16:22:10 +02004180 if (ar->cfg_tx_chainmask) {
4181 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
4182
4183 vdev_param = ar->wmi.vdev_param->nss;
4184 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4185 nss);
4186 if (ret) {
4187 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
4188 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
4189 ret);
4190 goto err_vdev_delete;
4191 }
4192 }
4193
Michal Kaziore57e0572015-03-24 13:14:03 +00004194 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4195 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
Marek Puzyniak7390ed32015-03-30 09:51:52 +03004196 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr,
4197 WMI_PEER_TYPE_DEFAULT);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004198 if (ret) {
Michal Kaziore57e0572015-03-24 13:14:03 +00004199 ath10k_warn(ar, "failed to create vdev %i peer for AP/IBSS: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004200 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004201 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004202 }
Michal Kaziore57e0572015-03-24 13:14:03 +00004203 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01004204
Michal Kaziore57e0572015-03-24 13:14:03 +00004205 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
Kalle Valo5a13e762014-01-20 11:01:46 +02004206 ret = ath10k_mac_set_kickout(arvif);
4207 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004208 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004209 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +02004210 goto err_peer_delete;
4211 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004212 }
4213
4214 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
4215 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
4216 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4217 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4218 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004219 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004220 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004221 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004222 goto err_peer_delete;
4223 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004224
Michal Kazior9f9b5742014-12-12 12:41:36 +01004225 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004226 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01004227 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004228 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004229 goto err_peer_delete;
4230 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004231
Michal Kazior9f9b5742014-12-12 12:41:36 +01004232 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004233 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01004234 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004235 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004236 goto err_peer_delete;
4237 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004238 }
4239
Michal Kazior424121c2013-07-22 14:13:31 +02004240 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004241 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004242 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03004243 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004244 goto err_peer_delete;
4245 }
Michal Kazior679c54a2013-07-05 16:15:04 +03004246
Michal Kazior424121c2013-07-22 14:13:31 +02004247 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004248 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004249 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03004250 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004251 goto err_peer_delete;
4252 }
Michal Kazior679c54a2013-07-05 16:15:04 +03004253
Michal Kazior7d9d5582014-10-21 10:40:15 +03004254 arvif->txpower = vif->bss_conf.txpower;
4255 ret = ath10k_mac_txpower_recalc(ar);
4256 if (ret) {
4257 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
4258 goto err_peer_delete;
4259 }
4260
Michal Kazior500ff9f2015-03-31 10:26:21 +00004261 if (vif->type == NL80211_IFTYPE_MONITOR) {
4262 ar->monitor_arvif = arvif;
4263 ret = ath10k_monitor_recalc(ar);
4264 if (ret) {
4265 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4266 goto err_peer_delete;
4267 }
4268 }
4269
Kalle Valo5e3dd152013-06-12 20:52:10 +03004270 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004271 return 0;
4272
4273err_peer_delete:
Michal Kaziore57e0572015-03-24 13:14:03 +00004274 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4275 arvif->vdev_type == WMI_VDEV_TYPE_IBSS)
Michal Kazior9dad14a2013-10-16 15:44:45 +03004276 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
4277
4278err_vdev_delete:
4279 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
Ben Greear16c11172014-09-23 14:17:16 -07004280 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03004281 list_del(&arvif->list);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004282
4283err:
Michal Kazior64badcb2014-09-18 11:18:02 +03004284 if (arvif->beacon_buf) {
4285 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
4286 arvif->beacon_buf, arvif->beacon_paddr);
4287 arvif->beacon_buf = NULL;
4288 }
4289
Michal Kazior9dad14a2013-10-16 15:44:45 +03004290 mutex_unlock(&ar->conf_mutex);
4291
Kalle Valo5e3dd152013-06-12 20:52:10 +03004292 return ret;
4293}
4294
Michal Kaziorb4aa5392015-03-31 10:26:24 +00004295static void ath10k_mac_vif_tx_unlock_all(struct ath10k_vif *arvif)
4296{
4297 int i;
4298
4299 for (i = 0; i < BITS_PER_LONG; i++)
4300 ath10k_mac_vif_tx_unlock(arvif, i);
4301}
4302
Kalle Valo5e3dd152013-06-12 20:52:10 +03004303static void ath10k_remove_interface(struct ieee80211_hw *hw,
4304 struct ieee80211_vif *vif)
4305{
4306 struct ath10k *ar = hw->priv;
4307 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4308 int ret;
4309
Michal Kazior81a9a172015-03-05 16:02:17 +02004310 cancel_work_sync(&arvif->ap_csa_work);
Michal Kaziorcc9904e2015-03-10 16:22:01 +02004311 cancel_delayed_work_sync(&arvif->connection_loss_work);
Michal Kazior81a9a172015-03-05 16:02:17 +02004312
Sujith Manoharan5d011f52014-11-25 11:47:00 +05304313 mutex_lock(&ar->conf_mutex);
4314
Michal Kaziored543882013-09-13 14:16:56 +02004315 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03004316 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kaziored543882013-09-13 14:16:56 +02004317 spin_unlock_bh(&ar->data_lock);
4318
Simon Wunderlich855aed12014-08-02 09:12:54 +03004319 ret = ath10k_spectral_vif_stop(arvif);
4320 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004321 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03004322 arvif->vdev_id, ret);
4323
Ben Greear16c11172014-09-23 14:17:16 -07004324 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03004325 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004326
Michal Kaziore57e0572015-03-24 13:14:03 +00004327 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4328 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
Michal Kazior2c512052015-02-15 16:50:40 +02004329 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
4330 vif->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004331 if (ret)
Michal Kaziore57e0572015-03-24 13:14:03 +00004332 ath10k_warn(ar, "failed to submit AP/IBSS self-peer removal on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004333 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004334
4335 kfree(arvif->u.ap.noa_data);
4336 }
4337
Michal Kazior7aa7a722014-08-25 12:09:38 +02004338 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004339 arvif->vdev_id);
4340
Kalle Valo5e3dd152013-06-12 20:52:10 +03004341 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
4342 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004343 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004344 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004345
Michal Kazior2c512052015-02-15 16:50:40 +02004346 /* Some firmware revisions don't notify host about self-peer removal
4347 * until after associated vdev is deleted.
4348 */
Michal Kaziore57e0572015-03-24 13:14:03 +00004349 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4350 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
Michal Kazior2c512052015-02-15 16:50:40 +02004351 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
4352 vif->addr);
4353 if (ret)
4354 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
4355 arvif->vdev_id, ret);
4356
4357 spin_lock_bh(&ar->data_lock);
4358 ar->num_peers--;
4359 spin_unlock_bh(&ar->data_lock);
4360 }
4361
Kalle Valo5e3dd152013-06-12 20:52:10 +03004362 ath10k_peer_cleanup(ar, arvif->vdev_id);
4363
Michal Kazior500ff9f2015-03-31 10:26:21 +00004364 if (vif->type == NL80211_IFTYPE_MONITOR) {
4365 ar->monitor_arvif = NULL;
4366 ret = ath10k_monitor_recalc(ar);
4367 if (ret)
4368 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4369 }
4370
Michal Kaziorb4aa5392015-03-31 10:26:24 +00004371 spin_lock_bh(&ar->htt.tx_lock);
4372 ath10k_mac_vif_tx_unlock_all(arvif);
4373 spin_unlock_bh(&ar->htt.tx_lock);
4374
Kalle Valo5e3dd152013-06-12 20:52:10 +03004375 mutex_unlock(&ar->conf_mutex);
4376}
4377
4378/*
4379 * FIXME: Has to be verified.
4380 */
4381#define SUPPORTED_FILTERS \
Johannes Bergdf140462015-04-22 14:40:58 +02004382 (FIF_ALLMULTI | \
Kalle Valo5e3dd152013-06-12 20:52:10 +03004383 FIF_CONTROL | \
4384 FIF_PSPOLL | \
4385 FIF_OTHER_BSS | \
4386 FIF_BCN_PRBRESP_PROMISC | \
4387 FIF_PROBE_REQ | \
4388 FIF_FCSFAIL)
4389
4390static void ath10k_configure_filter(struct ieee80211_hw *hw,
4391 unsigned int changed_flags,
4392 unsigned int *total_flags,
4393 u64 multicast)
4394{
4395 struct ath10k *ar = hw->priv;
4396 int ret;
4397
4398 mutex_lock(&ar->conf_mutex);
4399
4400 changed_flags &= SUPPORTED_FILTERS;
4401 *total_flags &= SUPPORTED_FILTERS;
4402 ar->filter_flags = *total_flags;
4403
Michal Kazior19337472014-08-28 12:58:16 +02004404 ret = ath10k_monitor_recalc(ar);
4405 if (ret)
4406 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004407
4408 mutex_unlock(&ar->conf_mutex);
4409}
4410
4411static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
4412 struct ieee80211_vif *vif,
4413 struct ieee80211_bss_conf *info,
4414 u32 changed)
4415{
4416 struct ath10k *ar = hw->priv;
4417 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4418 int ret = 0;
Kalle Valoaf762c02014-09-14 12:50:17 +03004419 u32 vdev_param, pdev_param, slottime, preamble;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004420
4421 mutex_lock(&ar->conf_mutex);
4422
4423 if (changed & BSS_CHANGED_IBSS)
4424 ath10k_control_ibss(arvif, info, vif->addr);
4425
4426 if (changed & BSS_CHANGED_BEACON_INT) {
4427 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004428 vdev_param = ar->wmi.vdev_param->beacon_interval;
4429 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004430 arvif->beacon_interval);
Michal Kazior7aa7a722014-08-25 12:09:38 +02004431 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004432 "mac vdev %d beacon_interval %d\n",
4433 arvif->vdev_id, arvif->beacon_interval);
4434
Kalle Valo5e3dd152013-06-12 20:52:10 +03004435 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004436 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004437 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004438 }
4439
4440 if (changed & BSS_CHANGED_BEACON) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004441 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004442 "vdev %d set beacon tx mode to staggered\n",
4443 arvif->vdev_id);
4444
Bartosz Markowski226a3392013-09-26 17:47:16 +02004445 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
4446 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004447 WMI_BEACON_STAGGERED_MODE);
4448 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004449 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004450 arvif->vdev_id, ret);
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02004451
4452 ret = ath10k_mac_setup_bcn_tmpl(arvif);
4453 if (ret)
4454 ath10k_warn(ar, "failed to update beacon template: %d\n",
4455 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004456 }
4457
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02004458 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
4459 ret = ath10k_mac_setup_prb_tmpl(arvif);
4460 if (ret)
4461 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
4462 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004463 }
4464
Michal Kaziorba2479f2015-01-24 12:14:51 +02004465 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004466 arvif->dtim_period = info->dtim_period;
4467
Michal Kazior7aa7a722014-08-25 12:09:38 +02004468 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004469 "mac vdev %d dtim_period %d\n",
4470 arvif->vdev_id, arvif->dtim_period);
4471
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004472 vdev_param = ar->wmi.vdev_param->dtim_period;
4473 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004474 arvif->dtim_period);
4475 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004476 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004477 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004478 }
4479
4480 if (changed & BSS_CHANGED_SSID &&
4481 vif->type == NL80211_IFTYPE_AP) {
4482 arvif->u.ap.ssid_len = info->ssid_len;
4483 if (info->ssid_len)
4484 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
4485 arvif->u.ap.hidden_ssid = info->hidden_ssid;
4486 }
4487
Michal Kazior077efc82014-10-21 10:10:29 +03004488 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
4489 ether_addr_copy(arvif->bssid, info->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004490
4491 if (changed & BSS_CHANGED_BEACON_ENABLED)
4492 ath10k_control_beaconing(arvif, info);
4493
4494 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02004495 arvif->use_cts_prot = info->use_cts_prot;
Michal Kazior7aa7a722014-08-25 12:09:38 +02004496 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02004497 arvif->vdev_id, info->use_cts_prot);
Kalle Valo60c3daa2013-09-08 17:56:07 +03004498
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02004499 ret = ath10k_recalc_rtscts_prot(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004500 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004501 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004502 arvif->vdev_id, ret);
Michal Kaziora87fd4b2015-03-02 11:21:17 +01004503
4504 vdev_param = ar->wmi.vdev_param->protection_mode;
4505 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4506 info->use_cts_prot ? 1 : 0);
4507 if (ret)
4508 ath10k_warn(ar, "failed to set protection mode %d on vdev %i: %d\n",
4509 info->use_cts_prot, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004510 }
4511
4512 if (changed & BSS_CHANGED_ERP_SLOT) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004513 if (info->use_short_slot)
4514 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
4515
4516 else
4517 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
4518
Michal Kazior7aa7a722014-08-25 12:09:38 +02004519 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004520 arvif->vdev_id, slottime);
4521
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004522 vdev_param = ar->wmi.vdev_param->slot_time;
4523 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004524 slottime);
4525 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004526 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004527 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004528 }
4529
4530 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004531 if (info->use_short_preamble)
4532 preamble = WMI_VDEV_PREAMBLE_SHORT;
4533 else
4534 preamble = WMI_VDEV_PREAMBLE_LONG;
4535
Michal Kazior7aa7a722014-08-25 12:09:38 +02004536 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004537 "mac vdev %d preamble %dn",
4538 arvif->vdev_id, preamble);
4539
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004540 vdev_param = ar->wmi.vdev_param->preamble;
4541 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004542 preamble);
4543 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004544 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004545 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004546 }
4547
4548 if (changed & BSS_CHANGED_ASSOC) {
Michal Kaziore556f112014-08-28 12:58:17 +02004549 if (info->assoc) {
4550 /* Workaround: Make sure monitor vdev is not running
4551 * when associating to prevent some firmware revisions
4552 * (e.g. 10.1 and 10.2) from crashing.
4553 */
4554 if (ar->monitor_started)
4555 ath10k_monitor_stop(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004556 ath10k_bss_assoc(hw, vif, info);
Michal Kaziore556f112014-08-28 12:58:17 +02004557 ath10k_monitor_recalc(ar);
Michal Kazior077efc82014-10-21 10:10:29 +03004558 } else {
4559 ath10k_bss_disassoc(hw, vif);
Michal Kaziore556f112014-08-28 12:58:17 +02004560 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004561 }
4562
Michal Kazior7d9d5582014-10-21 10:40:15 +03004563 if (changed & BSS_CHANGED_TXPOWER) {
4564 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
4565 arvif->vdev_id, info->txpower);
4566
4567 arvif->txpower = info->txpower;
4568 ret = ath10k_mac_txpower_recalc(ar);
4569 if (ret)
4570 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
4571 }
4572
Michal Kaziorbf14e652014-12-12 12:41:38 +01004573 if (changed & BSS_CHANGED_PS) {
Michal Kaziorcffb41f2015-02-13 13:30:16 +01004574 arvif->ps = vif->bss_conf.ps;
4575
4576 ret = ath10k_config_ps(ar);
Michal Kaziorbf14e652014-12-12 12:41:38 +01004577 if (ret)
4578 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
4579 arvif->vdev_id, ret);
4580 }
4581
Kalle Valo5e3dd152013-06-12 20:52:10 +03004582 mutex_unlock(&ar->conf_mutex);
4583}
4584
4585static int ath10k_hw_scan(struct ieee80211_hw *hw,
4586 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02004587 struct ieee80211_scan_request *hw_req)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004588{
4589 struct ath10k *ar = hw->priv;
4590 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
David Spinadelc56ef672014-02-05 15:21:13 +02004591 struct cfg80211_scan_request *req = &hw_req->req;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004592 struct wmi_start_scan_arg arg;
4593 int ret = 0;
4594 int i;
4595
4596 mutex_lock(&ar->conf_mutex);
4597
4598 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004599 switch (ar->scan.state) {
4600 case ATH10K_SCAN_IDLE:
4601 reinit_completion(&ar->scan.started);
4602 reinit_completion(&ar->scan.completed);
4603 ar->scan.state = ATH10K_SCAN_STARTING;
4604 ar->scan.is_roc = false;
4605 ar->scan.vdev_id = arvif->vdev_id;
4606 ret = 0;
4607 break;
4608 case ATH10K_SCAN_STARTING:
4609 case ATH10K_SCAN_RUNNING:
4610 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004611 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004612 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004613 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004614 spin_unlock_bh(&ar->data_lock);
4615
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004616 if (ret)
4617 goto exit;
4618
Kalle Valo5e3dd152013-06-12 20:52:10 +03004619 memset(&arg, 0, sizeof(arg));
4620 ath10k_wmi_start_scan_init(ar, &arg);
4621 arg.vdev_id = arvif->vdev_id;
4622 arg.scan_id = ATH10K_SCAN_ID;
4623
Kalle Valo5e3dd152013-06-12 20:52:10 +03004624 if (req->ie_len) {
4625 arg.ie_len = req->ie_len;
4626 memcpy(arg.ie, req->ie, arg.ie_len);
4627 }
4628
4629 if (req->n_ssids) {
4630 arg.n_ssids = req->n_ssids;
4631 for (i = 0; i < arg.n_ssids; i++) {
4632 arg.ssids[i].len = req->ssids[i].ssid_len;
4633 arg.ssids[i].ssid = req->ssids[i].ssid;
4634 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02004635 } else {
4636 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004637 }
4638
4639 if (req->n_channels) {
4640 arg.n_channels = req->n_channels;
4641 for (i = 0; i < arg.n_channels; i++)
4642 arg.channels[i] = req->channels[i]->center_freq;
4643 }
4644
4645 ret = ath10k_start_scan(ar, &arg);
4646 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004647 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004648 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004649 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004650 spin_unlock_bh(&ar->data_lock);
4651 }
4652
4653exit:
4654 mutex_unlock(&ar->conf_mutex);
4655 return ret;
4656}
4657
4658static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
4659 struct ieee80211_vif *vif)
4660{
4661 struct ath10k *ar = hw->priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004662
4663 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004664 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004665 mutex_unlock(&ar->conf_mutex);
Michal Kazior4eb2e162014-10-28 10:23:09 +01004666
4667 cancel_delayed_work_sync(&ar->scan.timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004668}
4669
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004670static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
4671 struct ath10k_vif *arvif,
4672 enum set_key_cmd cmd,
4673 struct ieee80211_key_conf *key)
4674{
4675 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
4676 int ret;
4677
4678 /* 10.1 firmware branch requires default key index to be set to group
4679 * key index after installing it. Otherwise FW/HW Txes corrupted
4680 * frames with multi-vif APs. This is not required for main firmware
4681 * branch (e.g. 636).
4682 *
Michal Kazior8461baf2015-04-10 13:23:22 +00004683 * This is also needed for 636 fw for IBSS-RSN to work more reliably.
4684 *
4685 * FIXME: It remains unknown if this is required for multi-vif STA
4686 * interfaces on 10.1.
4687 */
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004688
Michal Kazior8461baf2015-04-10 13:23:22 +00004689 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
4690 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004691 return;
4692
4693 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
4694 return;
4695
4696 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
4697 return;
4698
4699 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4700 return;
4701
4702 if (cmd != SET_KEY)
4703 return;
4704
4705 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4706 key->keyidx);
4707 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004708 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004709 arvif->vdev_id, ret);
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004710}
4711
Kalle Valo5e3dd152013-06-12 20:52:10 +03004712static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
4713 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
4714 struct ieee80211_key_conf *key)
4715{
4716 struct ath10k *ar = hw->priv;
4717 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4718 struct ath10k_peer *peer;
4719 const u8 *peer_addr;
4720 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
4721 key->cipher == WLAN_CIPHER_SUITE_WEP104;
4722 int ret = 0;
Michal Kazior29a10002015-04-10 13:05:58 +00004723 int ret2;
Michal Kazior370e5672015-02-18 14:02:26 +01004724 u32 flags = 0;
Michal Kazior29a10002015-04-10 13:05:58 +00004725 u32 flags2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004726
Bartosz Markowskid7131c02015-03-10 14:32:19 +01004727 /* this one needs to be done in software */
4728 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
4729 return 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004730
4731 if (key->keyidx > WMI_MAX_KEY_INDEX)
4732 return -ENOSPC;
4733
4734 mutex_lock(&ar->conf_mutex);
4735
4736 if (sta)
4737 peer_addr = sta->addr;
4738 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
4739 peer_addr = vif->bss_conf.bssid;
4740 else
4741 peer_addr = vif->addr;
4742
4743 key->hw_key_idx = key->keyidx;
4744
Michal Kazior7c8cc7e2015-04-01 22:53:19 +03004745 if (is_wep) {
4746 if (cmd == SET_KEY)
4747 arvif->wep_keys[key->keyidx] = key;
4748 else
4749 arvif->wep_keys[key->keyidx] = NULL;
4750 }
4751
Kalle Valo5e3dd152013-06-12 20:52:10 +03004752 /* the peer should not disappear in mid-way (unless FW goes awry) since
4753 * we already hold conf_mutex. we just make sure its there now. */
4754 spin_lock_bh(&ar->data_lock);
4755 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4756 spin_unlock_bh(&ar->data_lock);
4757
4758 if (!peer) {
4759 if (cmd == SET_KEY) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004760 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03004761 peer_addr);
4762 ret = -EOPNOTSUPP;
4763 goto exit;
4764 } else {
4765 /* if the peer doesn't exist there is no key to disable
4766 * anymore */
4767 goto exit;
4768 }
4769 }
4770
Michal Kazior7cc45732015-03-09 14:24:17 +01004771 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4772 flags |= WMI_KEY_PAIRWISE;
4773 else
4774 flags |= WMI_KEY_GROUP;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004775
Kalle Valo5e3dd152013-06-12 20:52:10 +03004776 if (is_wep) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004777 if (cmd == DISABLE_KEY)
4778 ath10k_clear_vdev_key(arvif, key);
Michal Kazior370e5672015-02-18 14:02:26 +01004779
Michal Kaziorad325cb2015-02-18 14:02:27 +01004780 /* When WEP keys are uploaded it's possible that there are
4781 * stations associated already (e.g. when merging) without any
4782 * keys. Static WEP needs an explicit per-peer key upload.
4783 */
4784 if (vif->type == NL80211_IFTYPE_ADHOC &&
4785 cmd == SET_KEY)
4786 ath10k_mac_vif_update_wep_key(arvif, key);
4787
Michal Kazior370e5672015-02-18 14:02:26 +01004788 /* 802.1x never sets the def_wep_key_idx so each set_key()
4789 * call changes default tx key.
4790 *
4791 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
4792 * after first set_key().
4793 */
4794 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
4795 flags |= WMI_KEY_TX_USAGE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004796 }
4797
Michal Kazior370e5672015-02-18 14:02:26 +01004798 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004799 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004800 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004801 arvif->vdev_id, peer_addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004802 goto exit;
4803 }
4804
Michal Kazior29a10002015-04-10 13:05:58 +00004805 /* mac80211 sets static WEP keys as groupwise while firmware requires
4806 * them to be installed twice as both pairwise and groupwise.
4807 */
4808 if (is_wep && !sta && vif->type == NL80211_IFTYPE_STATION) {
4809 flags2 = flags;
4810 flags2 &= ~WMI_KEY_GROUP;
4811 flags2 |= WMI_KEY_PAIRWISE;
4812
4813 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags2);
4814 if (ret) {
4815 ath10k_warn(ar, "failed to install (ucast) key for vdev %i peer %pM: %d\n",
4816 arvif->vdev_id, peer_addr, ret);
4817 ret2 = ath10k_install_key(arvif, key, DISABLE_KEY,
4818 peer_addr, flags);
4819 if (ret2)
4820 ath10k_warn(ar, "failed to disable (mcast) key for vdev %i peer %pM: %d\n",
4821 arvif->vdev_id, peer_addr, ret2);
4822 goto exit;
4823 }
4824 }
4825
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004826 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
4827
Kalle Valo5e3dd152013-06-12 20:52:10 +03004828 spin_lock_bh(&ar->data_lock);
4829 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4830 if (peer && cmd == SET_KEY)
4831 peer->keys[key->keyidx] = key;
4832 else if (peer && cmd == DISABLE_KEY)
4833 peer->keys[key->keyidx] = NULL;
4834 else if (peer == NULL)
4835 /* impossible unless FW goes crazy */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004836 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004837 spin_unlock_bh(&ar->data_lock);
4838
4839exit:
4840 mutex_unlock(&ar->conf_mutex);
4841 return ret;
4842}
4843
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004844static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
4845 struct ieee80211_vif *vif,
4846 int keyidx)
4847{
4848 struct ath10k *ar = hw->priv;
4849 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4850 int ret;
4851
4852 mutex_lock(&arvif->ar->conf_mutex);
4853
4854 if (arvif->ar->state != ATH10K_STATE_ON)
4855 goto unlock;
4856
4857 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
4858 arvif->vdev_id, keyidx);
4859
4860 ret = ath10k_wmi_vdev_set_param(arvif->ar,
4861 arvif->vdev_id,
4862 arvif->ar->wmi.vdev_param->def_keyid,
4863 keyidx);
4864
4865 if (ret) {
4866 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
4867 arvif->vdev_id,
4868 ret);
4869 goto unlock;
4870 }
4871
4872 arvif->def_wep_key_idx = keyidx;
Michal Kazior370e5672015-02-18 14:02:26 +01004873
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004874unlock:
4875 mutex_unlock(&arvif->ar->conf_mutex);
4876}
4877
Michal Kazior9797feb2014-02-14 14:49:48 +01004878static void ath10k_sta_rc_update_wk(struct work_struct *wk)
4879{
4880 struct ath10k *ar;
4881 struct ath10k_vif *arvif;
4882 struct ath10k_sta *arsta;
4883 struct ieee80211_sta *sta;
Michal Kazior45c9abc2015-04-21 20:42:58 +03004884 struct cfg80211_chan_def def;
4885 enum ieee80211_band band;
4886 const u8 *ht_mcs_mask;
4887 const u16 *vht_mcs_mask;
Michal Kazior9797feb2014-02-14 14:49:48 +01004888 u32 changed, bw, nss, smps;
4889 int err;
4890
4891 arsta = container_of(wk, struct ath10k_sta, update_wk);
4892 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
4893 arvif = arsta->arvif;
4894 ar = arvif->ar;
4895
Michal Kazior45c9abc2015-04-21 20:42:58 +03004896 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
4897 return;
4898
4899 band = def.chan->band;
4900 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
4901 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
4902
Michal Kazior9797feb2014-02-14 14:49:48 +01004903 spin_lock_bh(&ar->data_lock);
4904
4905 changed = arsta->changed;
4906 arsta->changed = 0;
4907
4908 bw = arsta->bw;
4909 nss = arsta->nss;
4910 smps = arsta->smps;
4911
4912 spin_unlock_bh(&ar->data_lock);
4913
4914 mutex_lock(&ar->conf_mutex);
4915
Michal Kazior45c9abc2015-04-21 20:42:58 +03004916 nss = max_t(u32, 1, nss);
4917 nss = min(nss, max(ath10k_mac_max_ht_nss(ht_mcs_mask),
4918 ath10k_mac_max_vht_nss(vht_mcs_mask)));
4919
Michal Kazior9797feb2014-02-14 14:49:48 +01004920 if (changed & IEEE80211_RC_BW_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004921 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004922 sta->addr, bw);
4923
4924 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4925 WMI_PEER_CHAN_WIDTH, bw);
4926 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004927 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004928 sta->addr, bw, err);
4929 }
4930
4931 if (changed & IEEE80211_RC_NSS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004932 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004933 sta->addr, nss);
4934
4935 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4936 WMI_PEER_NSS, nss);
4937 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004938 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004939 sta->addr, nss, err);
4940 }
4941
4942 if (changed & IEEE80211_RC_SMPS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004943 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004944 sta->addr, smps);
4945
4946 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4947 WMI_PEER_SMPS_STATE, smps);
4948 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004949 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004950 sta->addr, smps, err);
4951 }
4952
Janusz Dziedzic55884c02014-12-17 12:30:02 +02004953 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
4954 changed & IEEE80211_RC_NSS_CHANGED) {
4955 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004956 sta->addr);
4957
Michal Kazior590922a2014-10-21 10:10:29 +03004958 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004959 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004960 ath10k_warn(ar, "failed to reassociate station: %pM\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004961 sta->addr);
4962 }
4963
Michal Kazior9797feb2014-02-14 14:49:48 +01004964 mutex_unlock(&ar->conf_mutex);
4965}
4966
Marek Puzyniak7c354242015-03-30 09:51:52 +03004967static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif,
4968 struct ieee80211_sta *sta)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004969{
4970 struct ath10k *ar = arvif->ar;
4971
4972 lockdep_assert_held(&ar->conf_mutex);
4973
Marek Puzyniak7c354242015-03-30 09:51:52 +03004974 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004975 return 0;
4976
4977 if (ar->num_stations >= ar->max_num_stations)
4978 return -ENOBUFS;
4979
4980 ar->num_stations++;
4981
4982 return 0;
4983}
4984
Marek Puzyniak7c354242015-03-30 09:51:52 +03004985static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif,
4986 struct ieee80211_sta *sta)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004987{
4988 struct ath10k *ar = arvif->ar;
4989
4990 lockdep_assert_held(&ar->conf_mutex);
4991
Marek Puzyniak7c354242015-03-30 09:51:52 +03004992 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004993 return;
4994
4995 ar->num_stations--;
4996}
4997
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004998struct ath10k_mac_tdls_iter_data {
4999 u32 num_tdls_stations;
5000 struct ieee80211_vif *curr_vif;
5001};
5002
5003static void ath10k_mac_tdls_vif_stations_count_iter(void *data,
5004 struct ieee80211_sta *sta)
5005{
5006 struct ath10k_mac_tdls_iter_data *iter_data = data;
5007 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5008 struct ieee80211_vif *sta_vif = arsta->arvif->vif;
5009
5010 if (sta->tdls && sta_vif == iter_data->curr_vif)
5011 iter_data->num_tdls_stations++;
5012}
5013
5014static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw *hw,
5015 struct ieee80211_vif *vif)
5016{
5017 struct ath10k_mac_tdls_iter_data data = {};
5018
5019 data.curr_vif = vif;
5020
5021 ieee80211_iterate_stations_atomic(hw,
5022 ath10k_mac_tdls_vif_stations_count_iter,
5023 &data);
5024 return data.num_tdls_stations;
5025}
5026
5027static void ath10k_mac_tdls_vifs_count_iter(void *data, u8 *mac,
5028 struct ieee80211_vif *vif)
5029{
5030 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5031 int *num_tdls_vifs = data;
5032
5033 if (vif->type != NL80211_IFTYPE_STATION)
5034 return;
5035
5036 if (ath10k_mac_tdls_vif_stations_count(arvif->ar->hw, vif) > 0)
5037 (*num_tdls_vifs)++;
5038}
5039
5040static int ath10k_mac_tdls_vifs_count(struct ieee80211_hw *hw)
5041{
5042 int num_tdls_vifs = 0;
5043
5044 ieee80211_iterate_active_interfaces_atomic(hw,
5045 IEEE80211_IFACE_ITER_NORMAL,
5046 ath10k_mac_tdls_vifs_count_iter,
5047 &num_tdls_vifs);
5048 return num_tdls_vifs;
5049}
5050
Kalle Valo5e3dd152013-06-12 20:52:10 +03005051static int ath10k_sta_state(struct ieee80211_hw *hw,
5052 struct ieee80211_vif *vif,
5053 struct ieee80211_sta *sta,
5054 enum ieee80211_sta_state old_state,
5055 enum ieee80211_sta_state new_state)
5056{
5057 struct ath10k *ar = hw->priv;
5058 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01005059 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005060 int ret = 0;
5061
Michal Kazior76f90022014-02-25 09:29:57 +02005062 if (old_state == IEEE80211_STA_NOTEXIST &&
5063 new_state == IEEE80211_STA_NONE) {
5064 memset(arsta, 0, sizeof(*arsta));
5065 arsta->arvif = arvif;
5066 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
5067 }
5068
Michal Kazior9797feb2014-02-14 14:49:48 +01005069 /* cancel must be done outside the mutex to avoid deadlock */
5070 if ((old_state == IEEE80211_STA_NONE &&
5071 new_state == IEEE80211_STA_NOTEXIST))
5072 cancel_work_sync(&arsta->update_wk);
5073
Kalle Valo5e3dd152013-06-12 20:52:10 +03005074 mutex_lock(&ar->conf_mutex);
5075
5076 if (old_state == IEEE80211_STA_NOTEXIST &&
Michal Kazior077efc82014-10-21 10:10:29 +03005077 new_state == IEEE80211_STA_NONE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03005078 /*
5079 * New station addition.
5080 */
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005081 enum wmi_peer_type peer_type = WMI_PEER_TYPE_DEFAULT;
5082 u32 num_tdls_stations;
5083 u32 num_tdls_vifs;
5084
Michal Kaziorcfd10612014-11-25 15:16:05 +01005085 ath10k_dbg(ar, ATH10K_DBG_MAC,
5086 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
5087 arvif->vdev_id, sta->addr,
5088 ar->num_stations + 1, ar->max_num_stations,
5089 ar->num_peers + 1, ar->max_num_peers);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01005090
Marek Puzyniak7c354242015-03-30 09:51:52 +03005091 ret = ath10k_mac_inc_num_stations(arvif, sta);
Michal Kaziorcfd10612014-11-25 15:16:05 +01005092 if (ret) {
5093 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
5094 ar->max_num_stations);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01005095 goto exit;
5096 }
5097
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005098 if (sta->tdls)
5099 peer_type = WMI_PEER_TYPE_TDLS;
5100
Marek Puzyniak7390ed32015-03-30 09:51:52 +03005101 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr,
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005102 peer_type);
Michal Kaziora52c0282014-11-25 15:16:03 +01005103 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005104 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 -08005105 sta->addr, arvif->vdev_id, ret);
Marek Puzyniak7c354242015-03-30 09:51:52 +03005106 ath10k_mac_dec_num_stations(arvif, sta);
Michal Kaziora52c0282014-11-25 15:16:03 +01005107 goto exit;
5108 }
Michal Kazior077efc82014-10-21 10:10:29 +03005109
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005110 if (!sta->tdls)
5111 goto exit;
Michal Kazior077efc82014-10-21 10:10:29 +03005112
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005113 num_tdls_stations = ath10k_mac_tdls_vif_stations_count(hw, vif);
5114 num_tdls_vifs = ath10k_mac_tdls_vifs_count(hw);
5115
5116 if (num_tdls_vifs >= ar->max_num_tdls_vdevs &&
5117 num_tdls_stations == 0) {
5118 ath10k_warn(ar, "vdev %i exceeded maximum number of tdls vdevs %i\n",
5119 arvif->vdev_id, ar->max_num_tdls_vdevs);
5120 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5121 ath10k_mac_dec_num_stations(arvif, sta);
5122 ret = -ENOBUFS;
5123 goto exit;
5124 }
5125
5126 if (num_tdls_stations == 0) {
5127 /* This is the first tdls peer in current vif */
5128 enum wmi_tdls_state state = WMI_TDLS_ENABLE_ACTIVE;
5129
5130 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5131 state);
Michal Kazior077efc82014-10-21 10:10:29 +03005132 if (ret) {
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005133 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
Michal Kazior077efc82014-10-21 10:10:29 +03005134 arvif->vdev_id, ret);
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005135 ath10k_peer_delete(ar, arvif->vdev_id,
5136 sta->addr);
5137 ath10k_mac_dec_num_stations(arvif, sta);
Michal Kazior077efc82014-10-21 10:10:29 +03005138 goto exit;
5139 }
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005140 }
Michal Kazior077efc82014-10-21 10:10:29 +03005141
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005142 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
5143 WMI_TDLS_PEER_STATE_PEERING);
5144 if (ret) {
5145 ath10k_warn(ar,
5146 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
5147 sta->addr, arvif->vdev_id, ret);
5148 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5149 ath10k_mac_dec_num_stations(arvif, sta);
5150
5151 if (num_tdls_stations != 0)
5152 goto exit;
5153 ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5154 WMI_TDLS_DISABLE);
Michal Kazior077efc82014-10-21 10:10:29 +03005155 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005156 } else if ((old_state == IEEE80211_STA_NONE &&
5157 new_state == IEEE80211_STA_NOTEXIST)) {
5158 /*
5159 * Existing station deletion.
5160 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005161 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03005162 "mac vdev %d peer delete %pM (sta gone)\n",
5163 arvif->vdev_id, sta->addr);
Michal Kazior077efc82014-10-21 10:10:29 +03005164
Kalle Valo5e3dd152013-06-12 20:52:10 +03005165 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5166 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005167 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02005168 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005169
Marek Puzyniak7c354242015-03-30 09:51:52 +03005170 ath10k_mac_dec_num_stations(arvif, sta);
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005171
5172 if (!sta->tdls)
5173 goto exit;
5174
5175 if (ath10k_mac_tdls_vif_stations_count(hw, vif))
5176 goto exit;
5177
5178 /* This was the last tdls peer in current vif */
5179 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5180 WMI_TDLS_DISABLE);
5181 if (ret) {
5182 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
5183 arvif->vdev_id, ret);
5184 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005185 } else if (old_state == IEEE80211_STA_AUTH &&
5186 new_state == IEEE80211_STA_ASSOC &&
5187 (vif->type == NL80211_IFTYPE_AP ||
5188 vif->type == NL80211_IFTYPE_ADHOC)) {
5189 /*
5190 * New association.
5191 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005192 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03005193 sta->addr);
5194
Michal Kazior590922a2014-10-21 10:10:29 +03005195 ret = ath10k_station_assoc(ar, vif, sta, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005196 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005197 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02005198 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005199 } else if (old_state == IEEE80211_STA_ASSOC &&
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005200 new_state == IEEE80211_STA_AUTHORIZED &&
5201 sta->tdls) {
5202 /*
5203 * Tdls station authorized.
5204 */
5205 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac tdls sta %pM authorized\n",
5206 sta->addr);
5207
5208 ret = ath10k_station_assoc(ar, vif, sta, false);
5209 if (ret) {
5210 ath10k_warn(ar, "failed to associate tdls station %pM for vdev %i: %i\n",
5211 sta->addr, arvif->vdev_id, ret);
5212 goto exit;
5213 }
5214
5215 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
5216 WMI_TDLS_PEER_STATE_CONNECTED);
5217 if (ret)
5218 ath10k_warn(ar, "failed to update tdls peer %pM for vdev %i: %i\n",
5219 sta->addr, arvif->vdev_id, ret);
5220 } else if (old_state == IEEE80211_STA_ASSOC &&
5221 new_state == IEEE80211_STA_AUTH &&
5222 (vif->type == NL80211_IFTYPE_AP ||
5223 vif->type == NL80211_IFTYPE_ADHOC)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03005224 /*
5225 * Disassociation.
5226 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005227 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03005228 sta->addr);
5229
Michal Kazior590922a2014-10-21 10:10:29 +03005230 ret = ath10k_station_disassoc(ar, vif, sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005231 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005232 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02005233 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005234 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01005235exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005236 mutex_unlock(&ar->conf_mutex);
5237 return ret;
5238}
5239
5240static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
Kalle Valo5b07e072014-09-14 12:50:06 +03005241 u16 ac, bool enable)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005242{
5243 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorb0e56152015-01-24 12:14:52 +02005244 struct wmi_sta_uapsd_auto_trig_arg arg = {};
5245 u32 prio = 0, acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005246 u32 value = 0;
5247 int ret = 0;
5248
Michal Kazior548db542013-07-05 16:15:15 +03005249 lockdep_assert_held(&ar->conf_mutex);
5250
Kalle Valo5e3dd152013-06-12 20:52:10 +03005251 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
5252 return 0;
5253
5254 switch (ac) {
5255 case IEEE80211_AC_VO:
5256 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
5257 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005258 prio = 7;
5259 acc = 3;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005260 break;
5261 case IEEE80211_AC_VI:
5262 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
5263 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005264 prio = 5;
5265 acc = 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005266 break;
5267 case IEEE80211_AC_BE:
5268 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
5269 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005270 prio = 2;
5271 acc = 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005272 break;
5273 case IEEE80211_AC_BK:
5274 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
5275 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005276 prio = 0;
5277 acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005278 break;
5279 }
5280
5281 if (enable)
5282 arvif->u.sta.uapsd |= value;
5283 else
5284 arvif->u.sta.uapsd &= ~value;
5285
5286 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5287 WMI_STA_PS_PARAM_UAPSD,
5288 arvif->u.sta.uapsd);
5289 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005290 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005291 goto exit;
5292 }
5293
5294 if (arvif->u.sta.uapsd)
5295 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
5296 else
5297 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
5298
5299 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5300 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
5301 value);
5302 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005303 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005304
Michal Kazior9f9b5742014-12-12 12:41:36 +01005305 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
5306 if (ret) {
5307 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
5308 arvif->vdev_id, ret);
5309 return ret;
5310 }
5311
5312 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
5313 if (ret) {
5314 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
5315 arvif->vdev_id, ret);
5316 return ret;
5317 }
5318
Michal Kaziorb0e56152015-01-24 12:14:52 +02005319 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
5320 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
5321 /* Only userspace can make an educated decision when to send
5322 * trigger frame. The following effectively disables u-UAPSD
5323 * autotrigger in firmware (which is enabled by default
5324 * provided the autotrigger service is available).
5325 */
5326
5327 arg.wmm_ac = acc;
5328 arg.user_priority = prio;
5329 arg.service_interval = 0;
5330 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
5331 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
5332
5333 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
5334 arvif->bssid, &arg, 1);
5335 if (ret) {
5336 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
5337 ret);
5338 return ret;
5339 }
5340 }
5341
Kalle Valo5e3dd152013-06-12 20:52:10 +03005342exit:
5343 return ret;
5344}
5345
5346static int ath10k_conf_tx(struct ieee80211_hw *hw,
5347 struct ieee80211_vif *vif, u16 ac,
5348 const struct ieee80211_tx_queue_params *params)
5349{
5350 struct ath10k *ar = hw->priv;
Michal Kazior5e752e42015-01-19 09:53:41 +01005351 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005352 struct wmi_wmm_params_arg *p = NULL;
5353 int ret;
5354
5355 mutex_lock(&ar->conf_mutex);
5356
5357 switch (ac) {
5358 case IEEE80211_AC_VO:
Michal Kazior5e752e42015-01-19 09:53:41 +01005359 p = &arvif->wmm_params.ac_vo;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005360 break;
5361 case IEEE80211_AC_VI:
Michal Kazior5e752e42015-01-19 09:53:41 +01005362 p = &arvif->wmm_params.ac_vi;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005363 break;
5364 case IEEE80211_AC_BE:
Michal Kazior5e752e42015-01-19 09:53:41 +01005365 p = &arvif->wmm_params.ac_be;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005366 break;
5367 case IEEE80211_AC_BK:
Michal Kazior5e752e42015-01-19 09:53:41 +01005368 p = &arvif->wmm_params.ac_bk;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005369 break;
5370 }
5371
5372 if (WARN_ON(!p)) {
5373 ret = -EINVAL;
5374 goto exit;
5375 }
5376
5377 p->cwmin = params->cw_min;
5378 p->cwmax = params->cw_max;
5379 p->aifs = params->aifs;
5380
5381 /*
5382 * The channel time duration programmed in the HW is in absolute
5383 * microseconds, while mac80211 gives the txop in units of
5384 * 32 microseconds.
5385 */
5386 p->txop = params->txop * 32;
5387
Michal Kazior7fc979a2015-01-28 09:57:28 +02005388 if (ar->wmi.ops->gen_vdev_wmm_conf) {
5389 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
5390 &arvif->wmm_params);
5391 if (ret) {
5392 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
5393 arvif->vdev_id, ret);
5394 goto exit;
5395 }
5396 } else {
5397 /* This won't work well with multi-interface cases but it's
5398 * better than nothing.
5399 */
5400 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
5401 if (ret) {
5402 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
5403 goto exit;
5404 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005405 }
5406
5407 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
5408 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005409 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005410
5411exit:
5412 mutex_unlock(&ar->conf_mutex);
5413 return ret;
5414}
5415
5416#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
5417
5418static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
5419 struct ieee80211_vif *vif,
5420 struct ieee80211_channel *chan,
5421 int duration,
5422 enum ieee80211_roc_type type)
5423{
5424 struct ath10k *ar = hw->priv;
5425 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5426 struct wmi_start_scan_arg arg;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005427 int ret = 0;
Michal Kaziorfcf98442015-03-31 11:03:47 +00005428 u32 scan_time_msec;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005429
5430 mutex_lock(&ar->conf_mutex);
5431
5432 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005433 switch (ar->scan.state) {
5434 case ATH10K_SCAN_IDLE:
5435 reinit_completion(&ar->scan.started);
5436 reinit_completion(&ar->scan.completed);
5437 reinit_completion(&ar->scan.on_channel);
5438 ar->scan.state = ATH10K_SCAN_STARTING;
5439 ar->scan.is_roc = true;
5440 ar->scan.vdev_id = arvif->vdev_id;
5441 ar->scan.roc_freq = chan->center_freq;
Michal Kaziord710e752015-07-09 13:08:36 +02005442 ar->scan.roc_notify = true;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005443 ret = 0;
5444 break;
5445 case ATH10K_SCAN_STARTING:
5446 case ATH10K_SCAN_RUNNING:
5447 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005448 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005449 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005450 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005451 spin_unlock_bh(&ar->data_lock);
5452
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005453 if (ret)
5454 goto exit;
5455
Michal Kaziorfcf98442015-03-31 11:03:47 +00005456 scan_time_msec = ar->hw->wiphy->max_remain_on_channel_duration * 2;
Michal Kaziordcca0bd2014-11-24 14:58:32 +01005457
Kalle Valo5e3dd152013-06-12 20:52:10 +03005458 memset(&arg, 0, sizeof(arg));
5459 ath10k_wmi_start_scan_init(ar, &arg);
5460 arg.vdev_id = arvif->vdev_id;
5461 arg.scan_id = ATH10K_SCAN_ID;
5462 arg.n_channels = 1;
5463 arg.channels[0] = chan->center_freq;
Michal Kaziorfcf98442015-03-31 11:03:47 +00005464 arg.dwell_time_active = scan_time_msec;
5465 arg.dwell_time_passive = scan_time_msec;
5466 arg.max_scan_time = scan_time_msec;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005467 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
5468 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
Michal Kaziordbd3f9f2015-03-31 11:03:48 +00005469 arg.burst_duration_ms = duration;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005470
5471 ret = ath10k_start_scan(ar, &arg);
5472 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005473 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005474 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005475 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005476 spin_unlock_bh(&ar->data_lock);
5477 goto exit;
5478 }
5479
5480 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
5481 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005482 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005483
5484 ret = ath10k_scan_stop(ar);
5485 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005486 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005487
Kalle Valo5e3dd152013-06-12 20:52:10 +03005488 ret = -ETIMEDOUT;
5489 goto exit;
5490 }
5491
Michal Kaziorfcf98442015-03-31 11:03:47 +00005492 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
5493 msecs_to_jiffies(duration));
5494
Kalle Valo5e3dd152013-06-12 20:52:10 +03005495 ret = 0;
5496exit:
5497 mutex_unlock(&ar->conf_mutex);
5498 return ret;
5499}
5500
5501static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
5502{
5503 struct ath10k *ar = hw->priv;
5504
5505 mutex_lock(&ar->conf_mutex);
Michal Kaziord710e752015-07-09 13:08:36 +02005506
5507 spin_lock_bh(&ar->data_lock);
5508 ar->scan.roc_notify = false;
5509 spin_unlock_bh(&ar->data_lock);
5510
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005511 ath10k_scan_abort(ar);
Michal Kaziord710e752015-07-09 13:08:36 +02005512
Kalle Valo5e3dd152013-06-12 20:52:10 +03005513 mutex_unlock(&ar->conf_mutex);
5514
Michal Kazior4eb2e162014-10-28 10:23:09 +01005515 cancel_delayed_work_sync(&ar->scan.timeout);
5516
Kalle Valo5e3dd152013-06-12 20:52:10 +03005517 return 0;
5518}
5519
5520/*
5521 * Both RTS and Fragmentation threshold are interface-specific
5522 * in ath10k, but device-specific in mac80211.
5523 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03005524
5525static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
5526{
Kalle Valo5e3dd152013-06-12 20:52:10 +03005527 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03005528 struct ath10k_vif *arvif;
5529 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03005530
Michal Kaziorad088bf2013-10-16 15:44:46 +03005531 mutex_lock(&ar->conf_mutex);
5532 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005533 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03005534 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03005535
Michal Kaziorad088bf2013-10-16 15:44:46 +03005536 ret = ath10k_mac_set_rts(arvif, value);
5537 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005538 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03005539 arvif->vdev_id, ret);
5540 break;
5541 }
5542 }
5543 mutex_unlock(&ar->conf_mutex);
5544
5545 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005546}
5547
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02005548static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5549 u32 queues, bool drop)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005550{
5551 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02005552 bool skip;
Nicholas Mc Guired4298a32015-06-15 14:46:43 +03005553 long time_left;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005554
5555 /* mac80211 doesn't care if we really xmit queued frames or not
5556 * we'll collect those frames either way if we stop/delete vdevs */
5557 if (drop)
5558 return;
5559
Michal Kazior548db542013-07-05 16:15:15 +03005560 mutex_lock(&ar->conf_mutex);
5561
Michal Kazioraffd3212013-07-16 09:54:35 +02005562 if (ar->state == ATH10K_STATE_WEDGED)
5563 goto skip;
5564
Nicholas Mc Guired4298a32015-06-15 14:46:43 +03005565 time_left = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03005566 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02005567
Michal Kazioredb82362013-07-05 16:15:14 +03005568 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02005569 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03005570 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02005571
Michal Kazior7962b0d2014-10-28 10:34:38 +01005572 skip = (ar->state == ATH10K_STATE_WEDGED) ||
5573 test_bit(ATH10K_FLAG_CRASH_FLUSH,
5574 &ar->dev_flags);
Michal Kazioraffd3212013-07-16 09:54:35 +02005575
5576 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005577 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02005578
Nicholas Mc Guired4298a32015-06-15 14:46:43 +03005579 if (time_left == 0 || skip)
5580 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %ld\n",
5581 skip, ar->state, time_left);
Michal Kazior548db542013-07-05 16:15:15 +03005582
Michal Kazioraffd3212013-07-16 09:54:35 +02005583skip:
Michal Kazior548db542013-07-05 16:15:15 +03005584 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005585}
5586
5587/* TODO: Implement this function properly
5588 * For now it is needed to reply to Probe Requests in IBSS mode.
5589 * Propably we need this information from FW.
5590 */
5591static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
5592{
5593 return 1;
5594}
5595
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005596static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
5597 enum ieee80211_reconfig_type reconfig_type)
Michal Kazioraffd3212013-07-16 09:54:35 +02005598{
5599 struct ath10k *ar = hw->priv;
5600
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005601 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
5602 return;
5603
Michal Kazioraffd3212013-07-16 09:54:35 +02005604 mutex_lock(&ar->conf_mutex);
5605
5606 /* If device failed to restart it will be in a different state, e.g.
5607 * ATH10K_STATE_WEDGED */
5608 if (ar->state == ATH10K_STATE_RESTARTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005609 ath10k_info(ar, "device successfully recovered\n");
Michal Kazioraffd3212013-07-16 09:54:35 +02005610 ar->state = ATH10K_STATE_ON;
Michal Kazior7962b0d2014-10-28 10:34:38 +01005611 ieee80211_wake_queues(ar->hw);
Michal Kazioraffd3212013-07-16 09:54:35 +02005612 }
5613
5614 mutex_unlock(&ar->conf_mutex);
5615}
5616
Michal Kazior2e1dea42013-07-31 10:32:40 +02005617static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
5618 struct survey_info *survey)
5619{
5620 struct ath10k *ar = hw->priv;
5621 struct ieee80211_supported_band *sband;
5622 struct survey_info *ar_survey = &ar->survey[idx];
5623 int ret = 0;
5624
5625 mutex_lock(&ar->conf_mutex);
5626
5627 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
5628 if (sband && idx >= sband->n_channels) {
5629 idx -= sband->n_channels;
5630 sband = NULL;
5631 }
5632
5633 if (!sband)
5634 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
5635
5636 if (!sband || idx >= sband->n_channels) {
5637 ret = -ENOENT;
5638 goto exit;
5639 }
5640
5641 spin_lock_bh(&ar->data_lock);
5642 memcpy(survey, ar_survey, sizeof(*survey));
5643 spin_unlock_bh(&ar->data_lock);
5644
5645 survey->channel = &sband->channels[idx];
5646
Felix Fietkaufa1d4df2014-10-23 17:04:28 +03005647 if (ar->rx_channel == survey->channel)
5648 survey->filled |= SURVEY_INFO_IN_USE;
5649
Michal Kazior2e1dea42013-07-31 10:32:40 +02005650exit:
5651 mutex_unlock(&ar->conf_mutex);
5652 return ret;
5653}
5654
Michal Kazior3ae54222015-03-31 10:49:20 +00005655static bool
5656ath10k_mac_bitrate_mask_has_single_rate(struct ath10k *ar,
5657 enum ieee80211_band band,
5658 const struct cfg80211_bitrate_mask *mask)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005659{
Michal Kazior3ae54222015-03-31 10:49:20 +00005660 int num_rates = 0;
5661 int i;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005662
Michal Kazior3ae54222015-03-31 10:49:20 +00005663 num_rates += hweight32(mask->control[band].legacy);
5664
5665 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++)
5666 num_rates += hweight8(mask->control[band].ht_mcs[i]);
5667
5668 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++)
5669 num_rates += hweight16(mask->control[band].vht_mcs[i]);
5670
5671 return num_rates == 1;
5672}
5673
5674static bool
5675ath10k_mac_bitrate_mask_get_single_nss(struct ath10k *ar,
5676 enum ieee80211_band band,
5677 const struct cfg80211_bitrate_mask *mask,
5678 int *nss)
5679{
5680 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
5681 u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
5682 u8 ht_nss_mask = 0;
5683 u8 vht_nss_mask = 0;
5684 int i;
5685
5686 if (mask->control[band].legacy)
5687 return false;
5688
5689 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
5690 if (mask->control[band].ht_mcs[i] == 0)
5691 continue;
5692 else if (mask->control[band].ht_mcs[i] ==
5693 sband->ht_cap.mcs.rx_mask[i])
5694 ht_nss_mask |= BIT(i);
5695 else
5696 return false;
5697 }
5698
5699 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
5700 if (mask->control[band].vht_mcs[i] == 0)
5701 continue;
5702 else if (mask->control[band].vht_mcs[i] ==
5703 ath10k_mac_get_max_vht_mcs_map(vht_mcs_map, i))
5704 vht_nss_mask |= BIT(i);
5705 else
5706 return false;
5707 }
5708
5709 if (ht_nss_mask != vht_nss_mask)
5710 return false;
5711
5712 if (ht_nss_mask == 0)
5713 return false;
5714
5715 if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask)
5716 return false;
5717
5718 *nss = fls(ht_nss_mask);
5719
5720 return true;
5721}
5722
5723static int
5724ath10k_mac_bitrate_mask_get_single_rate(struct ath10k *ar,
5725 enum ieee80211_band band,
5726 const struct cfg80211_bitrate_mask *mask,
5727 u8 *rate, u8 *nss)
5728{
5729 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
5730 int rate_idx;
5731 int i;
5732 u16 bitrate;
5733 u8 preamble;
5734 u8 hw_rate;
5735
5736 if (hweight32(mask->control[band].legacy) == 1) {
5737 rate_idx = ffs(mask->control[band].legacy) - 1;
5738
5739 hw_rate = sband->bitrates[rate_idx].hw_value;
5740 bitrate = sband->bitrates[rate_idx].bitrate;
5741
5742 if (ath10k_mac_bitrate_is_cck(bitrate))
5743 preamble = WMI_RATE_PREAMBLE_CCK;
5744 else
5745 preamble = WMI_RATE_PREAMBLE_OFDM;
5746
5747 *nss = 1;
5748 *rate = preamble << 6 |
5749 (*nss - 1) << 4 |
5750 hw_rate << 0;
5751
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005752 return 0;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005753 }
5754
Michal Kazior3ae54222015-03-31 10:49:20 +00005755 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
5756 if (hweight8(mask->control[band].ht_mcs[i]) == 1) {
5757 *nss = i + 1;
5758 *rate = WMI_RATE_PREAMBLE_HT << 6 |
5759 (*nss - 1) << 4 |
5760 (ffs(mask->control[band].ht_mcs[i]) - 1);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005761
Michal Kazior3ae54222015-03-31 10:49:20 +00005762 return 0;
5763 }
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005764 }
5765
Michal Kazior3ae54222015-03-31 10:49:20 +00005766 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
5767 if (hweight16(mask->control[band].vht_mcs[i]) == 1) {
5768 *nss = i + 1;
5769 *rate = WMI_RATE_PREAMBLE_VHT << 6 |
5770 (*nss - 1) << 4 |
5771 (ffs(mask->control[band].vht_mcs[i]) - 1);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005772
Michal Kazior3ae54222015-03-31 10:49:20 +00005773 return 0;
5774 }
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005775 }
5776
Michal Kazior3ae54222015-03-31 10:49:20 +00005777 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005778}
5779
Michal Kazior3ae54222015-03-31 10:49:20 +00005780static int ath10k_mac_set_fixed_rate_params(struct ath10k_vif *arvif,
5781 u8 rate, u8 nss, u8 sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005782{
5783 struct ath10k *ar = arvif->ar;
5784 u32 vdev_param;
Michal Kazior3ae54222015-03-31 10:49:20 +00005785 int ret;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005786
Michal Kazior3ae54222015-03-31 10:49:20 +00005787 lockdep_assert_held(&ar->conf_mutex);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005788
Michal Kazior3ae54222015-03-31 10:49:20 +00005789 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac set fixed rate params vdev %i rate 0x%02hhx nss %hhu sgi %hhu\n",
5790 arvif->vdev_id, rate, nss, sgi);
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005791
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005792 vdev_param = ar->wmi.vdev_param->fixed_rate;
Michal Kazior3ae54222015-03-31 10:49:20 +00005793 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, rate);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005794 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005795 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
Michal Kazior3ae54222015-03-31 10:49:20 +00005796 rate, ret);
5797 return ret;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005798 }
5799
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005800 vdev_param = ar->wmi.vdev_param->nss;
Michal Kazior3ae54222015-03-31 10:49:20 +00005801 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, nss);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005802 if (ret) {
Michal Kazior3ae54222015-03-31 10:49:20 +00005803 ath10k_warn(ar, "failed to set nss param %d: %d\n", nss, ret);
5804 return ret;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005805 }
5806
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005807 vdev_param = ar->wmi.vdev_param->sgi;
Michal Kazior3ae54222015-03-31 10:49:20 +00005808 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, sgi);
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005809 if (ret) {
Michal Kazior3ae54222015-03-31 10:49:20 +00005810 ath10k_warn(ar, "failed to set sgi param %d: %d\n", sgi, ret);
5811 return ret;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005812 }
5813
Michal Kazior3ae54222015-03-31 10:49:20 +00005814 return 0;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005815}
5816
Michal Kazior45c9abc2015-04-21 20:42:58 +03005817static bool
5818ath10k_mac_can_set_bitrate_mask(struct ath10k *ar,
5819 enum ieee80211_band band,
5820 const struct cfg80211_bitrate_mask *mask)
5821{
5822 int i;
5823 u16 vht_mcs;
5824
5825 /* Due to firmware limitation in WMI_PEER_ASSOC_CMDID it is impossible
5826 * to express all VHT MCS rate masks. Effectively only the following
5827 * ranges can be used: none, 0-7, 0-8 and 0-9.
5828 */
5829 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
5830 vht_mcs = mask->control[band].vht_mcs[i];
5831
5832 switch (vht_mcs) {
5833 case 0:
5834 case BIT(8) - 1:
5835 case BIT(9) - 1:
5836 case BIT(10) - 1:
5837 break;
5838 default:
5839 ath10k_warn(ar, "refusing bitrate mask with missing 0-7 VHT MCS rates\n");
5840 return false;
5841 }
5842 }
5843
5844 return true;
5845}
5846
5847static void ath10k_mac_set_bitrate_mask_iter(void *data,
5848 struct ieee80211_sta *sta)
5849{
5850 struct ath10k_vif *arvif = data;
5851 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5852 struct ath10k *ar = arvif->ar;
5853
5854 if (arsta->arvif != arvif)
5855 return;
5856
5857 spin_lock_bh(&ar->data_lock);
5858 arsta->changed |= IEEE80211_RC_SUPP_RATES_CHANGED;
5859 spin_unlock_bh(&ar->data_lock);
5860
5861 ieee80211_queue_work(ar->hw, &arsta->update_wk);
5862}
5863
Michal Kazior3ae54222015-03-31 10:49:20 +00005864static int ath10k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw,
5865 struct ieee80211_vif *vif,
5866 const struct cfg80211_bitrate_mask *mask)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005867{
5868 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior500ff9f2015-03-31 10:26:21 +00005869 struct cfg80211_chan_def def;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005870 struct ath10k *ar = arvif->ar;
Michal Kazior500ff9f2015-03-31 10:26:21 +00005871 enum ieee80211_band band;
Michal Kazior45c9abc2015-04-21 20:42:58 +03005872 const u8 *ht_mcs_mask;
5873 const u16 *vht_mcs_mask;
Michal Kazior3ae54222015-03-31 10:49:20 +00005874 u8 rate;
5875 u8 nss;
5876 u8 sgi;
5877 int single_nss;
5878 int ret;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005879
Michal Kazior500ff9f2015-03-31 10:26:21 +00005880 if (ath10k_mac_vif_chan(vif, &def))
5881 return -EPERM;
5882
Michal Kazior500ff9f2015-03-31 10:26:21 +00005883 band = def.chan->band;
Michal Kazior45c9abc2015-04-21 20:42:58 +03005884 ht_mcs_mask = mask->control[band].ht_mcs;
5885 vht_mcs_mask = mask->control[band].vht_mcs;
Michal Kazior500ff9f2015-03-31 10:26:21 +00005886
Michal Kazior3ae54222015-03-31 10:49:20 +00005887 sgi = mask->control[band].gi;
5888 if (sgi == NL80211_TXRATE_FORCE_LGI)
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005889 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005890
Michal Kazior3ae54222015-03-31 10:49:20 +00005891 if (ath10k_mac_bitrate_mask_has_single_rate(ar, band, mask)) {
5892 ret = ath10k_mac_bitrate_mask_get_single_rate(ar, band, mask,
5893 &rate, &nss);
5894 if (ret) {
5895 ath10k_warn(ar, "failed to get single rate for vdev %i: %d\n",
5896 arvif->vdev_id, ret);
5897 return ret;
5898 }
5899 } else if (ath10k_mac_bitrate_mask_get_single_nss(ar, band, mask,
5900 &single_nss)) {
5901 rate = WMI_FIXED_RATE_NONE;
5902 nss = single_nss;
5903 } else {
5904 rate = WMI_FIXED_RATE_NONE;
Michal Kazior45c9abc2015-04-21 20:42:58 +03005905 nss = min(ar->num_rf_chains,
5906 max(ath10k_mac_max_ht_nss(ht_mcs_mask),
5907 ath10k_mac_max_vht_nss(vht_mcs_mask)));
5908
5909 if (!ath10k_mac_can_set_bitrate_mask(ar, band, mask))
5910 return -EINVAL;
5911
5912 mutex_lock(&ar->conf_mutex);
5913
5914 arvif->bitrate_mask = *mask;
5915 ieee80211_iterate_stations_atomic(ar->hw,
5916 ath10k_mac_set_bitrate_mask_iter,
5917 arvif);
5918
5919 mutex_unlock(&ar->conf_mutex);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005920 }
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005921
5922 mutex_lock(&ar->conf_mutex);
5923
Michal Kazior3ae54222015-03-31 10:49:20 +00005924 ret = ath10k_mac_set_fixed_rate_params(arvif, rate, nss, sgi);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005925 if (ret) {
Michal Kazior3ae54222015-03-31 10:49:20 +00005926 ath10k_warn(ar, "failed to set fixed rate params on vdev %i: %d\n",
5927 arvif->vdev_id, ret);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005928 goto exit;
5929 }
5930
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005931exit:
5932 mutex_unlock(&ar->conf_mutex);
Michal Kazior3ae54222015-03-31 10:49:20 +00005933
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005934 return ret;
5935}
5936
Michal Kazior9797feb2014-02-14 14:49:48 +01005937static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
5938 struct ieee80211_vif *vif,
5939 struct ieee80211_sta *sta,
5940 u32 changed)
5941{
5942 struct ath10k *ar = hw->priv;
5943 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5944 u32 bw, smps;
5945
5946 spin_lock_bh(&ar->data_lock);
5947
Michal Kazior7aa7a722014-08-25 12:09:38 +02005948 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior9797feb2014-02-14 14:49:48 +01005949 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
5950 sta->addr, changed, sta->bandwidth, sta->rx_nss,
5951 sta->smps_mode);
5952
5953 if (changed & IEEE80211_RC_BW_CHANGED) {
5954 bw = WMI_PEER_CHWIDTH_20MHZ;
5955
5956 switch (sta->bandwidth) {
5957 case IEEE80211_STA_RX_BW_20:
5958 bw = WMI_PEER_CHWIDTH_20MHZ;
5959 break;
5960 case IEEE80211_STA_RX_BW_40:
5961 bw = WMI_PEER_CHWIDTH_40MHZ;
5962 break;
5963 case IEEE80211_STA_RX_BW_80:
5964 bw = WMI_PEER_CHWIDTH_80MHZ;
5965 break;
5966 case IEEE80211_STA_RX_BW_160:
Masanari Iidad939be32015-02-27 23:52:31 +09005967 ath10k_warn(ar, "Invalid bandwidth %d in rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005968 sta->bandwidth, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005969 bw = WMI_PEER_CHWIDTH_20MHZ;
5970 break;
5971 }
5972
5973 arsta->bw = bw;
5974 }
5975
5976 if (changed & IEEE80211_RC_NSS_CHANGED)
5977 arsta->nss = sta->rx_nss;
5978
5979 if (changed & IEEE80211_RC_SMPS_CHANGED) {
5980 smps = WMI_PEER_SMPS_PS_NONE;
5981
5982 switch (sta->smps_mode) {
5983 case IEEE80211_SMPS_AUTOMATIC:
5984 case IEEE80211_SMPS_OFF:
5985 smps = WMI_PEER_SMPS_PS_NONE;
5986 break;
5987 case IEEE80211_SMPS_STATIC:
5988 smps = WMI_PEER_SMPS_STATIC;
5989 break;
5990 case IEEE80211_SMPS_DYNAMIC:
5991 smps = WMI_PEER_SMPS_DYNAMIC;
5992 break;
5993 case IEEE80211_SMPS_NUM_MODES:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005994 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005995 sta->smps_mode, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005996 smps = WMI_PEER_SMPS_PS_NONE;
5997 break;
5998 }
5999
6000 arsta->smps = smps;
6001 }
6002
Michal Kazior9797feb2014-02-14 14:49:48 +01006003 arsta->changed |= changed;
6004
6005 spin_unlock_bh(&ar->data_lock);
6006
6007 ieee80211_queue_work(hw, &arsta->update_wk);
6008}
6009
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02006010static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
6011{
6012 /*
6013 * FIXME: Return 0 for time being. Need to figure out whether FW
6014 * has the API to fetch 64-bit local TSF
6015 */
6016
6017 return 0;
6018}
6019
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02006020static int ath10k_ampdu_action(struct ieee80211_hw *hw,
6021 struct ieee80211_vif *vif,
6022 enum ieee80211_ampdu_mlme_action action,
6023 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
6024 u8 buf_size)
6025{
Michal Kazior7aa7a722014-08-25 12:09:38 +02006026 struct ath10k *ar = hw->priv;
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02006027 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6028
Michal Kazior7aa7a722014-08-25 12:09:38 +02006029 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 +02006030 arvif->vdev_id, sta->addr, tid, action);
6031
6032 switch (action) {
6033 case IEEE80211_AMPDU_RX_START:
6034 case IEEE80211_AMPDU_RX_STOP:
6035 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
6036 * creation/removal. Do we need to verify this?
6037 */
6038 return 0;
6039 case IEEE80211_AMPDU_TX_START:
6040 case IEEE80211_AMPDU_TX_STOP_CONT:
6041 case IEEE80211_AMPDU_TX_STOP_FLUSH:
6042 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
6043 case IEEE80211_AMPDU_TX_OPERATIONAL:
6044 /* Firmware offloads Tx aggregation entirely so deny mac80211
6045 * Tx aggregation requests.
6046 */
6047 return -EOPNOTSUPP;
6048 }
6049
6050 return -EINVAL;
6051}
6052
Michal Kazior500ff9f2015-03-31 10:26:21 +00006053static void
Michal Kaziord7bf4b42015-06-03 12:16:54 +02006054ath10k_mac_update_rx_channel(struct ath10k *ar,
6055 struct ieee80211_chanctx_conf *ctx,
6056 struct ieee80211_vif_chanctx_switch *vifs,
6057 int n_vifs)
Michal Kazior500ff9f2015-03-31 10:26:21 +00006058{
6059 struct cfg80211_chan_def *def = NULL;
6060
6061 /* Both locks are required because ar->rx_channel is modified. This
6062 * allows readers to hold either lock.
6063 */
6064 lockdep_assert_held(&ar->conf_mutex);
6065 lockdep_assert_held(&ar->data_lock);
6066
Michal Kaziord7bf4b42015-06-03 12:16:54 +02006067 WARN_ON(ctx && vifs);
6068 WARN_ON(vifs && n_vifs != 1);
6069
Michal Kazior500ff9f2015-03-31 10:26:21 +00006070 /* FIXME: Sort of an optimization and a workaround. Peers and vifs are
6071 * on a linked list now. Doing a lookup peer -> vif -> chanctx for each
6072 * ppdu on Rx may reduce performance on low-end systems. It should be
6073 * possible to make tables/hashmaps to speed the lookup up (be vary of
6074 * cpu data cache lines though regarding sizes) but to keep the initial
6075 * implementation simple and less intrusive fallback to the slow lookup
6076 * only for multi-channel cases. Single-channel cases will remain to
6077 * use the old channel derival and thus performance should not be
6078 * affected much.
6079 */
6080 rcu_read_lock();
Michal Kaziord7bf4b42015-06-03 12:16:54 +02006081 if (!ctx && ath10k_mac_num_chanctxs(ar) == 1) {
Michal Kazior500ff9f2015-03-31 10:26:21 +00006082 ieee80211_iter_chan_contexts_atomic(ar->hw,
6083 ath10k_mac_get_any_chandef_iter,
6084 &def);
Michal Kaziord7bf4b42015-06-03 12:16:54 +02006085
6086 if (vifs)
6087 def = &vifs[0].new_ctx->def;
6088
Michal Kazior500ff9f2015-03-31 10:26:21 +00006089 ar->rx_channel = def->chan;
Michal Kaziord7bf4b42015-06-03 12:16:54 +02006090 } else if (ctx && ath10k_mac_num_chanctxs(ar) == 0) {
6091 ar->rx_channel = ctx->def.chan;
Michal Kazior500ff9f2015-03-31 10:26:21 +00006092 } else {
6093 ar->rx_channel = NULL;
6094 }
6095 rcu_read_unlock();
6096}
6097
Michal Kazior500ff9f2015-03-31 10:26:21 +00006098static int
6099ath10k_mac_op_add_chanctx(struct ieee80211_hw *hw,
6100 struct ieee80211_chanctx_conf *ctx)
6101{
6102 struct ath10k *ar = hw->priv;
Michal Kazior500ff9f2015-03-31 10:26:21 +00006103
6104 ath10k_dbg(ar, ATH10K_DBG_MAC,
6105 "mac chanctx add freq %hu width %d ptr %p\n",
6106 ctx->def.chan->center_freq, ctx->def.width, ctx);
6107
6108 mutex_lock(&ar->conf_mutex);
6109
6110 spin_lock_bh(&ar->data_lock);
Michal Kaziord7bf4b42015-06-03 12:16:54 +02006111 ath10k_mac_update_rx_channel(ar, ctx, NULL, 0);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006112 spin_unlock_bh(&ar->data_lock);
6113
6114 ath10k_recalc_radar_detection(ar);
6115 ath10k_monitor_recalc(ar);
6116
6117 mutex_unlock(&ar->conf_mutex);
6118
6119 return 0;
6120}
6121
6122static void
6123ath10k_mac_op_remove_chanctx(struct ieee80211_hw *hw,
6124 struct ieee80211_chanctx_conf *ctx)
6125{
6126 struct ath10k *ar = hw->priv;
6127
6128 ath10k_dbg(ar, ATH10K_DBG_MAC,
6129 "mac chanctx remove freq %hu width %d ptr %p\n",
6130 ctx->def.chan->center_freq, ctx->def.width, ctx);
6131
6132 mutex_lock(&ar->conf_mutex);
6133
6134 spin_lock_bh(&ar->data_lock);
Michal Kaziord7bf4b42015-06-03 12:16:54 +02006135 ath10k_mac_update_rx_channel(ar, NULL, NULL, 0);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006136 spin_unlock_bh(&ar->data_lock);
6137
6138 ath10k_recalc_radar_detection(ar);
6139 ath10k_monitor_recalc(ar);
6140
6141 mutex_unlock(&ar->conf_mutex);
6142}
6143
6144static void
6145ath10k_mac_op_change_chanctx(struct ieee80211_hw *hw,
6146 struct ieee80211_chanctx_conf *ctx,
6147 u32 changed)
6148{
6149 struct ath10k *ar = hw->priv;
Michal Kazior500ff9f2015-03-31 10:26:21 +00006150
6151 mutex_lock(&ar->conf_mutex);
6152
6153 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior089ab7a2015-06-03 12:16:55 +02006154 "mac chanctx change freq %hu width %d ptr %p changed %x\n",
6155 ctx->def.chan->center_freq, ctx->def.width, ctx, changed);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006156
6157 /* This shouldn't really happen because channel switching should use
6158 * switch_vif_chanctx().
6159 */
6160 if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL))
6161 goto unlock;
6162
Michal Kazior500ff9f2015-03-31 10:26:21 +00006163 ath10k_recalc_radar_detection(ar);
6164
6165 /* FIXME: How to configure Rx chains properly? */
6166
6167 /* No other actions are actually necessary. Firmware maintains channel
6168 * definitions per vdev internally and there's no host-side channel
6169 * context abstraction to configure, e.g. channel width.
6170 */
6171
6172unlock:
6173 mutex_unlock(&ar->conf_mutex);
6174}
6175
6176static int
6177ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
6178 struct ieee80211_vif *vif,
6179 struct ieee80211_chanctx_conf *ctx)
6180{
6181 struct ath10k *ar = hw->priv;
Michal Kazior500ff9f2015-03-31 10:26:21 +00006182 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6183 int ret;
6184
6185 mutex_lock(&ar->conf_mutex);
6186
6187 ath10k_dbg(ar, ATH10K_DBG_MAC,
6188 "mac chanctx assign ptr %p vdev_id %i\n",
6189 ctx, arvif->vdev_id);
6190
6191 if (WARN_ON(arvif->is_started)) {
6192 mutex_unlock(&ar->conf_mutex);
6193 return -EBUSY;
6194 }
6195
Michal Kazior089ab7a2015-06-03 12:16:55 +02006196 ret = ath10k_vdev_start(arvif, &ctx->def);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006197 if (ret) {
6198 ath10k_warn(ar, "failed to start vdev %i addr %pM on freq %d: %d\n",
6199 arvif->vdev_id, vif->addr,
Michal Kazior089ab7a2015-06-03 12:16:55 +02006200 ctx->def.chan->center_freq, ret);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006201 goto err;
6202 }
6203
6204 arvif->is_started = true;
6205
Michal Kaziorf23e587e2015-07-09 13:08:37 +02006206 ret = ath10k_mac_vif_setup_ps(arvif);
6207 if (ret) {
6208 ath10k_warn(ar, "failed to update vdev %i ps: %d\n",
6209 arvif->vdev_id, ret);
6210 goto err_stop;
6211 }
6212
Michal Kazior500ff9f2015-03-31 10:26:21 +00006213 if (vif->type == NL80211_IFTYPE_MONITOR) {
6214 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, 0, vif->addr);
6215 if (ret) {
6216 ath10k_warn(ar, "failed to up monitor vdev %i: %d\n",
6217 arvif->vdev_id, ret);
6218 goto err_stop;
6219 }
6220
6221 arvif->is_up = true;
6222 }
6223
6224 mutex_unlock(&ar->conf_mutex);
6225 return 0;
6226
6227err_stop:
6228 ath10k_vdev_stop(arvif);
6229 arvif->is_started = false;
Michal Kaziorf23e587e2015-07-09 13:08:37 +02006230 ath10k_mac_vif_setup_ps(arvif);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006231
6232err:
6233 mutex_unlock(&ar->conf_mutex);
6234 return ret;
6235}
6236
6237static void
6238ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
6239 struct ieee80211_vif *vif,
6240 struct ieee80211_chanctx_conf *ctx)
6241{
6242 struct ath10k *ar = hw->priv;
6243 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6244 int ret;
6245
6246 mutex_lock(&ar->conf_mutex);
6247
6248 ath10k_dbg(ar, ATH10K_DBG_MAC,
6249 "mac chanctx unassign ptr %p vdev_id %i\n",
6250 ctx, arvif->vdev_id);
6251
6252 WARN_ON(!arvif->is_started);
6253
6254 if (vif->type == NL80211_IFTYPE_MONITOR) {
6255 WARN_ON(!arvif->is_up);
6256
6257 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
6258 if (ret)
6259 ath10k_warn(ar, "failed to down monitor vdev %i: %d\n",
6260 arvif->vdev_id, ret);
6261
6262 arvif->is_up = false;
6263 }
6264
6265 ret = ath10k_vdev_stop(arvif);
6266 if (ret)
6267 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
6268 arvif->vdev_id, ret);
6269
6270 arvif->is_started = false;
6271
6272 mutex_unlock(&ar->conf_mutex);
6273}
6274
6275static int
6276ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw,
6277 struct ieee80211_vif_chanctx_switch *vifs,
6278 int n_vifs,
6279 enum ieee80211_chanctx_switch_mode mode)
6280{
6281 struct ath10k *ar = hw->priv;
6282 struct ath10k_vif *arvif;
Michal Kazior0e6eb412015-06-03 12:16:56 +02006283 int ret;
Michal Kazior500ff9f2015-03-31 10:26:21 +00006284 int i;
6285
6286 mutex_lock(&ar->conf_mutex);
6287
6288 ath10k_dbg(ar, ATH10K_DBG_MAC,
6289 "mac chanctx switch n_vifs %d mode %d\n",
6290 n_vifs, mode);
6291
Michal Kazior0e6eb412015-06-03 12:16:56 +02006292 /* First stop monitor interface. Some FW versions crash if there's a
6293 * lone monitor interface.
6294 */
6295 if (ar->monitor_started)
6296 ath10k_monitor_stop(ar);
6297
Michal Kazior500ff9f2015-03-31 10:26:21 +00006298 for (i = 0; i < n_vifs; i++) {
6299 arvif = ath10k_vif_to_arvif(vifs[i].vif);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006300
6301 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior089ab7a2015-06-03 12:16:55 +02006302 "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d\n",
Michal Kazior500ff9f2015-03-31 10:26:21 +00006303 arvif->vdev_id,
6304 vifs[i].old_ctx->def.chan->center_freq,
6305 vifs[i].new_ctx->def.chan->center_freq,
6306 vifs[i].old_ctx->def.width,
Michal Kazior089ab7a2015-06-03 12:16:55 +02006307 vifs[i].new_ctx->def.width);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006308
Michal Kazior0e6eb412015-06-03 12:16:56 +02006309 if (WARN_ON(!arvif->is_started))
6310 continue;
6311
6312 if (WARN_ON(!arvif->is_up))
6313 continue;
6314
6315 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
6316 if (ret) {
6317 ath10k_warn(ar, "failed to down vdev %d: %d\n",
6318 arvif->vdev_id, ret);
6319 continue;
Michal Kazior500ff9f2015-03-31 10:26:21 +00006320 }
Michal Kazior500ff9f2015-03-31 10:26:21 +00006321 }
Michal Kazior0e6eb412015-06-03 12:16:56 +02006322
6323 /* All relevant vdevs are downed and associated channel resources
6324 * should be available for the channel switch now.
6325 */
6326
6327 spin_lock_bh(&ar->data_lock);
Michal Kaziord7bf4b42015-06-03 12:16:54 +02006328 ath10k_mac_update_rx_channel(ar, NULL, vifs, n_vifs);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006329 spin_unlock_bh(&ar->data_lock);
6330
Michal Kazior0e6eb412015-06-03 12:16:56 +02006331 for (i = 0; i < n_vifs; i++) {
6332 arvif = ath10k_vif_to_arvif(vifs[i].vif);
6333
6334 if (WARN_ON(!arvif->is_started))
6335 continue;
6336
6337 if (WARN_ON(!arvif->is_up))
6338 continue;
6339
6340 ret = ath10k_mac_setup_bcn_tmpl(arvif);
6341 if (ret)
6342 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
6343 ret);
6344
6345 ret = ath10k_mac_setup_prb_tmpl(arvif);
6346 if (ret)
6347 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
6348 ret);
6349
6350 ret = ath10k_vdev_restart(arvif, &vifs[i].new_ctx->def);
6351 if (ret) {
6352 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
6353 arvif->vdev_id, ret);
6354 continue;
6355 }
6356
6357 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
6358 arvif->bssid);
6359 if (ret) {
6360 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
6361 arvif->vdev_id, ret);
6362 continue;
6363 }
6364 }
6365
6366 ath10k_monitor_recalc(ar);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006367
6368 mutex_unlock(&ar->conf_mutex);
6369 return 0;
6370}
6371
Kalle Valo5e3dd152013-06-12 20:52:10 +03006372static const struct ieee80211_ops ath10k_ops = {
6373 .tx = ath10k_tx,
6374 .start = ath10k_start,
6375 .stop = ath10k_stop,
6376 .config = ath10k_config,
6377 .add_interface = ath10k_add_interface,
6378 .remove_interface = ath10k_remove_interface,
6379 .configure_filter = ath10k_configure_filter,
6380 .bss_info_changed = ath10k_bss_info_changed,
6381 .hw_scan = ath10k_hw_scan,
6382 .cancel_hw_scan = ath10k_cancel_hw_scan,
6383 .set_key = ath10k_set_key,
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02006384 .set_default_unicast_key = ath10k_set_default_unicast_key,
Kalle Valo5e3dd152013-06-12 20:52:10 +03006385 .sta_state = ath10k_sta_state,
6386 .conf_tx = ath10k_conf_tx,
6387 .remain_on_channel = ath10k_remain_on_channel,
6388 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
6389 .set_rts_threshold = ath10k_set_rts_threshold,
Kalle Valo5e3dd152013-06-12 20:52:10 +03006390 .flush = ath10k_flush,
6391 .tx_last_beacon = ath10k_tx_last_beacon,
Ben Greear46acf7b2014-05-16 17:15:38 +03006392 .set_antenna = ath10k_set_antenna,
6393 .get_antenna = ath10k_get_antenna,
Eliad Pellercf2c92d2014-11-04 11:43:54 +02006394 .reconfig_complete = ath10k_reconfig_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02006395 .get_survey = ath10k_get_survey,
Michal Kazior3ae54222015-03-31 10:49:20 +00006396 .set_bitrate_mask = ath10k_mac_op_set_bitrate_mask,
Michal Kazior9797feb2014-02-14 14:49:48 +01006397 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02006398 .get_tsf = ath10k_get_tsf,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02006399 .ampdu_action = ath10k_ampdu_action,
Ben Greear6cddcc72014-09-29 14:41:46 +03006400 .get_et_sset_count = ath10k_debug_get_et_sset_count,
6401 .get_et_stats = ath10k_debug_get_et_stats,
6402 .get_et_strings = ath10k_debug_get_et_strings,
Michal Kazior500ff9f2015-03-31 10:26:21 +00006403 .add_chanctx = ath10k_mac_op_add_chanctx,
6404 .remove_chanctx = ath10k_mac_op_remove_chanctx,
6405 .change_chanctx = ath10k_mac_op_change_chanctx,
6406 .assign_vif_chanctx = ath10k_mac_op_assign_vif_chanctx,
6407 .unassign_vif_chanctx = ath10k_mac_op_unassign_vif_chanctx,
6408 .switch_vif_chanctx = ath10k_mac_op_switch_vif_chanctx,
Kalle Valo43d2a302014-09-10 18:23:30 +03006409
6410 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
6411
Michal Kazior8cd13ca2013-07-16 09:38:54 +02006412#ifdef CONFIG_PM
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +02006413 .suspend = ath10k_wow_op_suspend,
6414 .resume = ath10k_wow_op_resume,
Michal Kazior8cd13ca2013-07-16 09:38:54 +02006415#endif
Rajkumar Manoharanf5045982015-01-12 14:07:27 +02006416#ifdef CONFIG_MAC80211_DEBUGFS
6417 .sta_add_debugfs = ath10k_sta_add_debugfs,
6418#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03006419};
6420
Kalle Valo5e3dd152013-06-12 20:52:10 +03006421#define CHAN2G(_channel, _freq, _flags) { \
6422 .band = IEEE80211_BAND_2GHZ, \
6423 .hw_value = (_channel), \
6424 .center_freq = (_freq), \
6425 .flags = (_flags), \
6426 .max_antenna_gain = 0, \
6427 .max_power = 30, \
6428}
6429
6430#define CHAN5G(_channel, _freq, _flags) { \
6431 .band = IEEE80211_BAND_5GHZ, \
6432 .hw_value = (_channel), \
6433 .center_freq = (_freq), \
6434 .flags = (_flags), \
6435 .max_antenna_gain = 0, \
6436 .max_power = 30, \
6437}
6438
6439static const struct ieee80211_channel ath10k_2ghz_channels[] = {
6440 CHAN2G(1, 2412, 0),
6441 CHAN2G(2, 2417, 0),
6442 CHAN2G(3, 2422, 0),
6443 CHAN2G(4, 2427, 0),
6444 CHAN2G(5, 2432, 0),
6445 CHAN2G(6, 2437, 0),
6446 CHAN2G(7, 2442, 0),
6447 CHAN2G(8, 2447, 0),
6448 CHAN2G(9, 2452, 0),
6449 CHAN2G(10, 2457, 0),
6450 CHAN2G(11, 2462, 0),
6451 CHAN2G(12, 2467, 0),
6452 CHAN2G(13, 2472, 0),
6453 CHAN2G(14, 2484, 0),
6454};
6455
6456static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02006457 CHAN5G(36, 5180, 0),
6458 CHAN5G(40, 5200, 0),
6459 CHAN5G(44, 5220, 0),
6460 CHAN5G(48, 5240, 0),
6461 CHAN5G(52, 5260, 0),
6462 CHAN5G(56, 5280, 0),
6463 CHAN5G(60, 5300, 0),
6464 CHAN5G(64, 5320, 0),
6465 CHAN5G(100, 5500, 0),
6466 CHAN5G(104, 5520, 0),
6467 CHAN5G(108, 5540, 0),
6468 CHAN5G(112, 5560, 0),
6469 CHAN5G(116, 5580, 0),
6470 CHAN5G(120, 5600, 0),
6471 CHAN5G(124, 5620, 0),
6472 CHAN5G(128, 5640, 0),
6473 CHAN5G(132, 5660, 0),
6474 CHAN5G(136, 5680, 0),
6475 CHAN5G(140, 5700, 0),
Peter Oh4a7898f2015-03-18 11:39:18 -07006476 CHAN5G(144, 5720, 0),
Michal Kazior429ff562013-06-26 08:54:54 +02006477 CHAN5G(149, 5745, 0),
6478 CHAN5G(153, 5765, 0),
6479 CHAN5G(157, 5785, 0),
6480 CHAN5G(161, 5805, 0),
6481 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03006482};
6483
Michal Kaziore7b54192014-08-07 11:03:27 +02006484struct ath10k *ath10k_mac_create(size_t priv_size)
Kalle Valo5e3dd152013-06-12 20:52:10 +03006485{
6486 struct ieee80211_hw *hw;
6487 struct ath10k *ar;
6488
Michal Kaziore7b54192014-08-07 11:03:27 +02006489 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006490 if (!hw)
6491 return NULL;
6492
6493 ar = hw->priv;
6494 ar->hw = hw;
6495
6496 return ar;
6497}
6498
6499void ath10k_mac_destroy(struct ath10k *ar)
6500{
6501 ieee80211_free_hw(ar->hw);
6502}
6503
6504static const struct ieee80211_iface_limit ath10k_if_limits[] = {
6505 {
6506 .max = 8,
6507 .types = BIT(NL80211_IFTYPE_STATION)
6508 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02006509 },
6510 {
6511 .max = 3,
6512 .types = BIT(NL80211_IFTYPE_P2P_GO)
6513 },
6514 {
Michal Kazior75d2bd42014-12-12 12:41:39 +01006515 .max = 1,
6516 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
6517 },
6518 {
Michal Kaziord531cb82013-07-31 10:55:13 +02006519 .max = 7,
6520 .types = BIT(NL80211_IFTYPE_AP)
6521 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03006522};
6523
Bartosz Markowskif2595092013-12-10 16:20:39 +01006524static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006525 {
6526 .max = 8,
6527 .types = BIT(NL80211_IFTYPE_AP)
6528 },
6529};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006530
6531static const struct ieee80211_iface_combination ath10k_if_comb[] = {
6532 {
6533 .limits = ath10k_if_limits,
6534 .n_limits = ARRAY_SIZE(ath10k_if_limits),
6535 .max_interfaces = 8,
6536 .num_different_channels = 1,
6537 .beacon_int_infra_match = true,
6538 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01006539};
6540
6541static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006542 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01006543 .limits = ath10k_10x_if_limits,
6544 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006545 .max_interfaces = 8,
6546 .num_different_channels = 1,
6547 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01006548#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006549 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
6550 BIT(NL80211_CHAN_WIDTH_20) |
6551 BIT(NL80211_CHAN_WIDTH_40) |
6552 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006553#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01006554 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03006555};
6556
Michal Kaziorcf327842015-03-31 10:26:25 +00006557static const struct ieee80211_iface_limit ath10k_tlv_if_limit[] = {
6558 {
6559 .max = 2,
Michal Kaziored25b112015-07-09 13:08:39 +02006560 .types = BIT(NL80211_IFTYPE_STATION),
6561 },
6562 {
6563 .max = 2,
6564 .types = BIT(NL80211_IFTYPE_AP) |
Michal Kaziorcf327842015-03-31 10:26:25 +00006565 BIT(NL80211_IFTYPE_P2P_CLIENT) |
6566 BIT(NL80211_IFTYPE_P2P_GO),
6567 },
6568 {
6569 .max = 1,
6570 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
6571 },
6572};
6573
Michal Kaziored25b112015-07-09 13:08:39 +02006574static const struct ieee80211_iface_limit ath10k_tlv_qcs_if_limit[] = {
6575 {
6576 .max = 2,
6577 .types = BIT(NL80211_IFTYPE_STATION),
6578 },
6579 {
6580 .max = 2,
6581 .types = BIT(NL80211_IFTYPE_P2P_CLIENT),
6582 },
6583 {
6584 .max = 1,
6585 .types = BIT(NL80211_IFTYPE_AP) |
6586 BIT(NL80211_IFTYPE_P2P_GO),
6587 },
6588 {
6589 .max = 1,
6590 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
6591 },
6592};
6593
Michal Kaziorcf327842015-03-31 10:26:25 +00006594static const struct ieee80211_iface_limit ath10k_tlv_if_limit_ibss[] = {
6595 {
6596 .max = 1,
6597 .types = BIT(NL80211_IFTYPE_STATION),
6598 },
6599 {
6600 .max = 1,
6601 .types = BIT(NL80211_IFTYPE_ADHOC),
6602 },
6603};
6604
6605/* FIXME: This is not thouroughly tested. These combinations may over- or
6606 * underestimate hw/fw capabilities.
6607 */
6608static struct ieee80211_iface_combination ath10k_tlv_if_comb[] = {
6609 {
6610 .limits = ath10k_tlv_if_limit,
6611 .num_different_channels = 1,
Michal Kaziored25b112015-07-09 13:08:39 +02006612 .max_interfaces = 4,
Michal Kaziorcf327842015-03-31 10:26:25 +00006613 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
6614 },
6615 {
6616 .limits = ath10k_tlv_if_limit_ibss,
6617 .num_different_channels = 1,
6618 .max_interfaces = 2,
6619 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
6620 },
6621};
6622
6623static struct ieee80211_iface_combination ath10k_tlv_qcs_if_comb[] = {
6624 {
6625 .limits = ath10k_tlv_if_limit,
Michal Kaziored25b112015-07-09 13:08:39 +02006626 .num_different_channels = 1,
6627 .max_interfaces = 4,
Michal Kaziorcf327842015-03-31 10:26:25 +00006628 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
6629 },
6630 {
Michal Kaziored25b112015-07-09 13:08:39 +02006631 .limits = ath10k_tlv_qcs_if_limit,
6632 .num_different_channels = 2,
6633 .max_interfaces = 4,
6634 .n_limits = ARRAY_SIZE(ath10k_tlv_qcs_if_limit),
6635 },
6636 {
Michal Kaziorcf327842015-03-31 10:26:25 +00006637 .limits = ath10k_tlv_if_limit_ibss,
6638 .num_different_channels = 1,
6639 .max_interfaces = 2,
6640 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
6641 },
6642};
6643
Raja Manicf36fef2015-06-22 20:22:25 +05306644static const struct ieee80211_iface_limit ath10k_10_4_if_limits[] = {
6645 {
6646 .max = 1,
6647 .types = BIT(NL80211_IFTYPE_STATION),
6648 },
6649 {
6650 .max = 16,
6651 .types = BIT(NL80211_IFTYPE_AP)
6652 },
6653};
6654
6655static const struct ieee80211_iface_combination ath10k_10_4_if_comb[] = {
6656 {
6657 .limits = ath10k_10_4_if_limits,
6658 .n_limits = ARRAY_SIZE(ath10k_10_4_if_limits),
6659 .max_interfaces = 16,
6660 .num_different_channels = 1,
6661 .beacon_int_infra_match = true,
6662#ifdef CONFIG_ATH10K_DFS_CERTIFIED
6663 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
6664 BIT(NL80211_CHAN_WIDTH_20) |
6665 BIT(NL80211_CHAN_WIDTH_40) |
6666 BIT(NL80211_CHAN_WIDTH_80),
6667#endif
6668 },
6669};
6670
Kalle Valo5e3dd152013-06-12 20:52:10 +03006671static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
6672{
6673 struct ieee80211_sta_vht_cap vht_cap = {0};
6674 u16 mcs_map;
Michal Kaziorbc657a362015-02-26 11:11:22 +01006675 u32 val;
Michal Kazior8865bee42013-07-24 12:36:46 +02006676 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006677
6678 vht_cap.vht_supported = 1;
6679 vht_cap.cap = ar->vht_cap_info;
6680
Michal Kaziorbc657a362015-02-26 11:11:22 +01006681 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
6682 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
6683 val = ar->num_rf_chains - 1;
6684 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
6685 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
6686
6687 vht_cap.cap |= val;
6688 }
6689
6690 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
6691 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
6692 val = ar->num_rf_chains - 1;
6693 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
6694 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
6695
6696 vht_cap.cap |= val;
6697 }
6698
Michal Kazior8865bee42013-07-24 12:36:46 +02006699 mcs_map = 0;
6700 for (i = 0; i < 8; i++) {
6701 if (i < ar->num_rf_chains)
6702 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
6703 else
6704 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
6705 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03006706
6707 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
6708 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
6709
6710 return vht_cap;
6711}
6712
6713static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
6714{
6715 int i;
6716 struct ieee80211_sta_ht_cap ht_cap = {0};
6717
6718 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
6719 return ht_cap;
6720
6721 ht_cap.ht_supported = 1;
6722 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
6723 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
6724 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
6725 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
6726 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
6727
6728 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
6729 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
6730
6731 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
6732 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
6733
6734 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
6735 u32 smps;
6736
6737 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
6738 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
6739
6740 ht_cap.cap |= smps;
6741 }
6742
6743 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
6744 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
6745
6746 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
6747 u32 stbc;
6748
6749 stbc = ar->ht_cap_info;
6750 stbc &= WMI_HT_CAP_RX_STBC;
6751 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
6752 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
6753 stbc &= IEEE80211_HT_CAP_RX_STBC;
6754
6755 ht_cap.cap |= stbc;
6756 }
6757
6758 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
6759 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
6760
6761 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
6762 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
6763
6764 /* max AMSDU is implicitly taken from vht_cap_info */
6765 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
6766 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
6767
Michal Kazior8865bee42013-07-24 12:36:46 +02006768 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03006769 ht_cap.mcs.rx_mask[i] = 0xFF;
6770
6771 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
6772
6773 return ht_cap;
6774}
6775
Kalle Valo5e3dd152013-06-12 20:52:10 +03006776static void ath10k_get_arvif_iter(void *data, u8 *mac,
6777 struct ieee80211_vif *vif)
6778{
6779 struct ath10k_vif_iter *arvif_iter = data;
6780 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6781
6782 if (arvif->vdev_id == arvif_iter->vdev_id)
6783 arvif_iter->arvif = arvif;
6784}
6785
6786struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
6787{
6788 struct ath10k_vif_iter arvif_iter;
6789 u32 flags;
6790
6791 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
6792 arvif_iter.vdev_id = vdev_id;
6793
6794 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
6795 ieee80211_iterate_active_interfaces_atomic(ar->hw,
6796 flags,
6797 ath10k_get_arvif_iter,
6798 &arvif_iter);
6799 if (!arvif_iter.arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02006800 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006801 return NULL;
6802 }
6803
6804 return arvif_iter.arvif;
6805}
6806
6807int ath10k_mac_register(struct ath10k *ar)
6808{
Johannes Berg3cb10942015-01-22 21:38:45 +01006809 static const u32 cipher_suites[] = {
6810 WLAN_CIPHER_SUITE_WEP40,
6811 WLAN_CIPHER_SUITE_WEP104,
6812 WLAN_CIPHER_SUITE_TKIP,
6813 WLAN_CIPHER_SUITE_CCMP,
6814 WLAN_CIPHER_SUITE_AES_CMAC,
6815 };
Kalle Valo5e3dd152013-06-12 20:52:10 +03006816 struct ieee80211_supported_band *band;
6817 struct ieee80211_sta_vht_cap vht_cap;
6818 struct ieee80211_sta_ht_cap ht_cap;
6819 void *channels;
6820 int ret;
6821
6822 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
6823
6824 SET_IEEE80211_DEV(ar->hw, ar->dev);
6825
6826 ht_cap = ath10k_get_ht_cap(ar);
6827 vht_cap = ath10k_create_vht_cap(ar);
6828
Michal Kaziorc94aa7e2015-03-24 12:38:11 +00006829 BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels) +
6830 ARRAY_SIZE(ath10k_5ghz_channels)) !=
6831 ATH10K_NUM_CHANS);
6832
Kalle Valo5e3dd152013-06-12 20:52:10 +03006833 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
6834 channels = kmemdup(ath10k_2ghz_channels,
6835 sizeof(ath10k_2ghz_channels),
6836 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02006837 if (!channels) {
6838 ret = -ENOMEM;
6839 goto err_free;
6840 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03006841
6842 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
6843 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
6844 band->channels = channels;
6845 band->n_bitrates = ath10k_g_rates_size;
6846 band->bitrates = ath10k_g_rates;
6847 band->ht_cap = ht_cap;
6848
Yanbo Lid68bb122015-01-23 08:18:20 +08006849 /* Enable the VHT support at 2.4 GHz */
6850 band->vht_cap = vht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006851
6852 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
6853 }
6854
6855 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
6856 channels = kmemdup(ath10k_5ghz_channels,
6857 sizeof(ath10k_5ghz_channels),
6858 GFP_KERNEL);
6859 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02006860 ret = -ENOMEM;
6861 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006862 }
6863
6864 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
6865 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
6866 band->channels = channels;
6867 band->n_bitrates = ath10k_a_rates_size;
6868 band->bitrates = ath10k_a_rates;
6869 band->ht_cap = ht_cap;
6870 band->vht_cap = vht_cap;
6871 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
6872 }
6873
6874 ar->hw->wiphy->interface_modes =
6875 BIT(NL80211_IFTYPE_STATION) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01006876 BIT(NL80211_IFTYPE_AP);
6877
Ben Greear46acf7b2014-05-16 17:15:38 +03006878 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
6879 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
6880
Bartosz Markowskid3541812013-12-10 16:20:40 +01006881 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
6882 ar->hw->wiphy->interface_modes |=
Michal Kazior75d2bd42014-12-12 12:41:39 +01006883 BIT(NL80211_IFTYPE_P2P_DEVICE) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01006884 BIT(NL80211_IFTYPE_P2P_CLIENT) |
6885 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006886
Johannes Berg30686bf2015-06-02 21:39:54 +02006887 ieee80211_hw_set(ar->hw, SIGNAL_DBM);
6888 ieee80211_hw_set(ar->hw, SUPPORTS_PS);
6889 ieee80211_hw_set(ar->hw, SUPPORTS_DYNAMIC_PS);
6890 ieee80211_hw_set(ar->hw, MFP_CAPABLE);
6891 ieee80211_hw_set(ar->hw, REPORTS_TX_ACK_STATUS);
6892 ieee80211_hw_set(ar->hw, HAS_RATE_CONTROL);
6893 ieee80211_hw_set(ar->hw, AP_LINK_PS);
6894 ieee80211_hw_set(ar->hw, SPECTRUM_MGMT);
6895 ieee80211_hw_set(ar->hw, SW_CRYPTO_CONTROL);
6896 ieee80211_hw_set(ar->hw, SUPPORT_FAST_XMIT);
6897 ieee80211_hw_set(ar->hw, CONNECTION_MONITOR);
6898 ieee80211_hw_set(ar->hw, SUPPORTS_PER_STA_GTK);
6899 ieee80211_hw_set(ar->hw, WANT_MONITOR_VIF);
6900 ieee80211_hw_set(ar->hw, CHANCTX_STA_CSA);
6901 ieee80211_hw_set(ar->hw, QUEUE_CONTROL);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006902
Eliad Peller0d8614b2014-09-10 14:07:36 +03006903 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
Janusz Dziedzic0cd9bc12015-04-10 13:23:23 +00006904 ar->hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
Eliad Peller0d8614b2014-09-10 14:07:36 +03006905
Kalle Valo5e3dd152013-06-12 20:52:10 +03006906 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
Eliad Peller0d8614b2014-09-10 14:07:36 +03006907 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006908
6909 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
Johannes Berg30686bf2015-06-02 21:39:54 +02006910 ieee80211_hw_set(ar->hw, AMPDU_AGGREGATION);
6911 ieee80211_hw_set(ar->hw, TX_AMPDU_SETUP_IN_HW);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006912 }
6913
6914 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
6915 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
6916
6917 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01006918 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006919
Kalle Valo5e3dd152013-06-12 20:52:10 +03006920 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
6921
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02006922 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
6923 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
6924
6925 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
6926 * that userspace (e.g. wpa_supplicant/hostapd) can generate
6927 * correct Probe Responses. This is more of a hack advert..
6928 */
6929 ar->hw->wiphy->probe_resp_offload |=
6930 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
6931 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
6932 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
6933 }
6934
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03006935 if (test_bit(WMI_SERVICE_TDLS, ar->wmi.svc_map))
6936 ar->hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
6937
Kalle Valo5e3dd152013-06-12 20:52:10 +03006938 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01006939 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006940 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
6941
6942 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
Rajkumar Manoharan78157a12014-11-17 16:44:15 +02006943 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
6944
Janusz.Dziedzic@tieto.com37a0b392015-03-12 13:11:41 +01006945 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
6946
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +02006947 ret = ath10k_wow_init(ar);
6948 if (ret) {
6949 ath10k_warn(ar, "failed to init wow: %d\n", ret);
6950 goto err_free;
6951 }
6952
Janusz Dziedzicc7025342015-06-15 14:46:41 +03006953 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
6954
Kalle Valo5e3dd152013-06-12 20:52:10 +03006955 /*
6956 * on LL hardware queues are managed entirely by the FW
6957 * so we only advertise to mac we can do the queues thing
6958 */
Michal Kazior96d828d2015-03-31 10:26:23 +00006959 ar->hw->queues = IEEE80211_MAX_QUEUES;
6960
6961 /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is
6962 * something that vdev_ids can't reach so that we don't stop the queue
6963 * accidentally.
6964 */
6965 ar->hw->offchannel_tx_hw_queue = IEEE80211_MAX_QUEUES - 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006966
Kalle Valo5cc7caf2014-12-17 12:20:54 +02006967 switch (ar->wmi.op_version) {
6968 case ATH10K_FW_WMI_OP_VERSION_MAIN:
Bartosz Markowskif2595092013-12-10 16:20:39 +01006969 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
6970 ar->hw->wiphy->n_iface_combinations =
6971 ARRAY_SIZE(ath10k_if_comb);
Michal Kaziorcf850d12014-07-24 20:07:00 +03006972 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
Kalle Valo5cc7caf2014-12-17 12:20:54 +02006973 break;
Michal Kaziorcf327842015-03-31 10:26:25 +00006974 case ATH10K_FW_WMI_OP_VERSION_TLV:
6975 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
6976 ar->hw->wiphy->iface_combinations =
6977 ath10k_tlv_qcs_if_comb;
6978 ar->hw->wiphy->n_iface_combinations =
6979 ARRAY_SIZE(ath10k_tlv_qcs_if_comb);
6980 } else {
6981 ar->hw->wiphy->iface_combinations = ath10k_tlv_if_comb;
6982 ar->hw->wiphy->n_iface_combinations =
6983 ARRAY_SIZE(ath10k_tlv_if_comb);
6984 }
6985 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
6986 break;
Kalle Valo5cc7caf2014-12-17 12:20:54 +02006987 case ATH10K_FW_WMI_OP_VERSION_10_1:
6988 case ATH10K_FW_WMI_OP_VERSION_10_2:
Rajkumar Manoharan4a16fbe2014-12-17 12:21:12 +02006989 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
Kalle Valo5cc7caf2014-12-17 12:20:54 +02006990 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
6991 ar->hw->wiphy->n_iface_combinations =
6992 ARRAY_SIZE(ath10k_10x_if_comb);
6993 break;
Raja Mani9bd21322015-06-22 20:10:09 +05306994 case ATH10K_FW_WMI_OP_VERSION_10_4:
Raja Manicf36fef2015-06-22 20:22:25 +05306995 ar->hw->wiphy->iface_combinations = ath10k_10_4_if_comb;
6996 ar->hw->wiphy->n_iface_combinations =
6997 ARRAY_SIZE(ath10k_10_4_if_comb);
Raja Mani9bd21322015-06-22 20:10:09 +05306998 break;
Kalle Valo5cc7caf2014-12-17 12:20:54 +02006999 case ATH10K_FW_WMI_OP_VERSION_UNSET:
7000 case ATH10K_FW_WMI_OP_VERSION_MAX:
7001 WARN_ON(1);
7002 ret = -EINVAL;
7003 goto err_free;
Bartosz Markowskif2595092013-12-10 16:20:39 +01007004 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03007005
Michal Kazior7c199992013-07-31 10:47:57 +02007006 ar->hw->netdev_features = NETIF_F_HW_CSUM;
7007
Janusz Dziedzic9702c682013-11-20 09:59:41 +02007008 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
7009 /* Init ath dfs pattern detector */
7010 ar->ath_common.debug_mask = ATH_DBG_DFS;
7011 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
7012 NL80211_DFS_UNSET);
7013
7014 if (!ar->dfs_detector)
Michal Kazior7aa7a722014-08-25 12:09:38 +02007015 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02007016 }
7017
Kalle Valo5e3dd152013-06-12 20:52:10 +03007018 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
7019 ath10k_reg_notifier);
7020 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02007021 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02007022 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03007023 }
7024
Johannes Berg3cb10942015-01-22 21:38:45 +01007025 ar->hw->wiphy->cipher_suites = cipher_suites;
7026 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
7027
Kalle Valo5e3dd152013-06-12 20:52:10 +03007028 ret = ieee80211_register_hw(ar->hw);
7029 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02007030 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02007031 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03007032 }
7033
7034 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
7035 ret = regulatory_hint(ar->hw->wiphy,
7036 ar->ath_common.regulatory.alpha2);
7037 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02007038 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03007039 }
7040
7041 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02007042
7043err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03007044 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02007045err_free:
7046 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
7047 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
7048
Kalle Valo5e3dd152013-06-12 20:52:10 +03007049 return ret;
7050}
7051
7052void ath10k_mac_unregister(struct ath10k *ar)
7053{
7054 ieee80211_unregister_hw(ar->hw);
7055
Janusz Dziedzic9702c682013-11-20 09:59:41 +02007056 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
7057 ar->dfs_detector->exit(ar->dfs_detector);
7058
Kalle Valo5e3dd152013-06-12 20:52:10 +03007059 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
7060 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
7061
7062 SET_IEEE80211_DEV(ar->hw, NULL);
7063}