blob: 96f4285e93b8dd9d34d2e47d2e5975f9c040d1e9 [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
David Liuccec9032015-07-24 20:25:32 +0300200 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
201 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
202 }
203
Kalle Valo5e3dd152013-06-12 20:52:10 +0300204 if (cmd == DISABLE_KEY) {
205 arg.key_cipher = WMI_CIPHER_NONE;
206 arg.key_data = NULL;
207 }
208
209 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
210}
211
212static int ath10k_install_key(struct ath10k_vif *arvif,
213 struct ieee80211_key_conf *key,
214 enum set_key_cmd cmd,
Michal Kazior370e5672015-02-18 14:02:26 +0100215 const u8 *macaddr, u32 flags)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300216{
217 struct ath10k *ar = arvif->ar;
218 int ret;
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +0300219 unsigned long time_left;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300220
Michal Kazior548db542013-07-05 16:15:15 +0300221 lockdep_assert_held(&ar->conf_mutex);
222
Wolfram Sang16735d02013-11-14 14:32:02 -0800223 reinit_completion(&ar->install_key_done);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300224
David Liuccec9032015-07-24 20:25:32 +0300225 if (arvif->nohwcrypt)
226 return 1;
227
Michal Kazior370e5672015-02-18 14:02:26 +0100228 ret = ath10k_send_key(arvif, key, cmd, macaddr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300229 if (ret)
230 return ret;
231
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +0300232 time_left = wait_for_completion_timeout(&ar->install_key_done, 3 * HZ);
233 if (time_left == 0)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300234 return -ETIMEDOUT;
235
236 return 0;
237}
238
239static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
240 const u8 *addr)
241{
242 struct ath10k *ar = arvif->ar;
243 struct ath10k_peer *peer;
244 int ret;
245 int i;
Michal Kazior370e5672015-02-18 14:02:26 +0100246 u32 flags;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300247
248 lockdep_assert_held(&ar->conf_mutex);
249
250 spin_lock_bh(&ar->data_lock);
251 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
252 spin_unlock_bh(&ar->data_lock);
253
254 if (!peer)
255 return -ENOENT;
256
257 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
258 if (arvif->wep_keys[i] == NULL)
259 continue;
Michal Kazior370e5672015-02-18 14:02:26 +0100260
261 flags = 0;
262 flags |= WMI_KEY_PAIRWISE;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300263
264 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
Michal Kaziorce90b272015-04-10 13:23:21 +0000265 addr, flags);
David Liuccec9032015-07-24 20:25:32 +0300266 if (ret < 0)
Michal Kaziorce90b272015-04-10 13:23:21 +0000267 return ret;
268
269 flags = 0;
270 flags |= WMI_KEY_GROUP;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300271
272 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
Michal Kazior370e5672015-02-18 14:02:26 +0100273 addr, flags);
David Liuccec9032015-07-24 20:25:32 +0300274 if (ret < 0)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300275 return ret;
276
Sujith Manoharanae167132014-11-25 11:46:59 +0530277 spin_lock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300278 peer->keys[i] = arvif->wep_keys[i];
Sujith Manoharanae167132014-11-25 11:46:59 +0530279 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300280 }
281
Michal Kaziorce90b272015-04-10 13:23:21 +0000282 /* In some cases (notably with static WEP IBSS with multiple keys)
283 * multicast Tx becomes broken. Both pairwise and groupwise keys are
284 * installed already. Using WMI_KEY_TX_USAGE in different combinations
285 * didn't seem help. Using def_keyid vdev parameter seems to be
286 * effective so use that.
287 *
288 * FIXME: Revisit. Perhaps this can be done in a less hacky way.
289 */
290 if (arvif->def_wep_key_idx == -1)
291 return 0;
292
293 ret = ath10k_wmi_vdev_set_param(arvif->ar,
294 arvif->vdev_id,
295 arvif->ar->wmi.vdev_param->def_keyid,
296 arvif->def_wep_key_idx);
297 if (ret) {
298 ath10k_warn(ar, "failed to re-set def wpa key idxon vdev %i: %d\n",
299 arvif->vdev_id, ret);
300 return ret;
301 }
302
Kalle Valo5e3dd152013-06-12 20:52:10 +0300303 return 0;
304}
305
306static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
307 const u8 *addr)
308{
309 struct ath10k *ar = arvif->ar;
310 struct ath10k_peer *peer;
311 int first_errno = 0;
312 int ret;
313 int i;
Michal Kazior370e5672015-02-18 14:02:26 +0100314 u32 flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300315
316 lockdep_assert_held(&ar->conf_mutex);
317
318 spin_lock_bh(&ar->data_lock);
319 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
320 spin_unlock_bh(&ar->data_lock);
321
322 if (!peer)
323 return -ENOENT;
324
325 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
326 if (peer->keys[i] == NULL)
327 continue;
328
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200329 /* key flags are not required to delete the key */
Kalle Valo5e3dd152013-06-12 20:52:10 +0300330 ret = ath10k_install_key(arvif, peer->keys[i],
Michal Kazior370e5672015-02-18 14:02:26 +0100331 DISABLE_KEY, addr, flags);
David Liuccec9032015-07-24 20:25:32 +0300332 if (ret < 0 && first_errno == 0)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300333 first_errno = ret;
334
David Liuccec9032015-07-24 20:25:32 +0300335 if (ret < 0)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200336 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300337 i, ret);
338
Sujith Manoharanae167132014-11-25 11:46:59 +0530339 spin_lock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300340 peer->keys[i] = NULL;
Sujith Manoharanae167132014-11-25 11:46:59 +0530341 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300342 }
343
344 return first_errno;
345}
346
Sujith Manoharan504f6cd2014-11-25 11:46:58 +0530347bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr,
348 u8 keyidx)
349{
350 struct ath10k_peer *peer;
351 int i;
352
353 lockdep_assert_held(&ar->data_lock);
354
355 /* We don't know which vdev this peer belongs to,
356 * since WMI doesn't give us that information.
357 *
358 * FIXME: multi-bss needs to be handled.
359 */
360 peer = ath10k_peer_find(ar, 0, addr);
361 if (!peer)
362 return false;
363
364 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
365 if (peer->keys[i] && peer->keys[i]->keyidx == keyidx)
366 return true;
367 }
368
369 return false;
370}
371
Kalle Valo5e3dd152013-06-12 20:52:10 +0300372static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
373 struct ieee80211_key_conf *key)
374{
375 struct ath10k *ar = arvif->ar;
376 struct ath10k_peer *peer;
377 u8 addr[ETH_ALEN];
378 int first_errno = 0;
379 int ret;
380 int i;
Michal Kazior370e5672015-02-18 14:02:26 +0100381 u32 flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300382
383 lockdep_assert_held(&ar->conf_mutex);
384
385 for (;;) {
386 /* since ath10k_install_key we can't hold data_lock all the
387 * time, so we try to remove the keys incrementally */
388 spin_lock_bh(&ar->data_lock);
389 i = 0;
390 list_for_each_entry(peer, &ar->peers, list) {
391 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
392 if (peer->keys[i] == key) {
Kalle Valob25f32c2014-09-14 12:50:49 +0300393 ether_addr_copy(addr, peer->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300394 peer->keys[i] = NULL;
395 break;
396 }
397 }
398
399 if (i < ARRAY_SIZE(peer->keys))
400 break;
401 }
402 spin_unlock_bh(&ar->data_lock);
403
404 if (i == ARRAY_SIZE(peer->keys))
405 break;
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200406 /* key flags are not required to delete the key */
Michal Kazior370e5672015-02-18 14:02:26 +0100407 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr, flags);
David Liuccec9032015-07-24 20:25:32 +0300408 if (ret < 0 && first_errno == 0)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300409 first_errno = ret;
410
411 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200412 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +0200413 addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300414 }
415
416 return first_errno;
417}
418
Michal Kaziorad325cb2015-02-18 14:02:27 +0100419static int ath10k_mac_vif_update_wep_key(struct ath10k_vif *arvif,
420 struct ieee80211_key_conf *key)
421{
422 struct ath10k *ar = arvif->ar;
423 struct ath10k_peer *peer;
424 int ret;
425
426 lockdep_assert_held(&ar->conf_mutex);
427
428 list_for_each_entry(peer, &ar->peers, list) {
429 if (!memcmp(peer->addr, arvif->vif->addr, ETH_ALEN))
430 continue;
431
432 if (!memcmp(peer->addr, arvif->bssid, ETH_ALEN))
433 continue;
434
435 if (peer->keys[key->keyidx] == key)
436 continue;
437
438 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vif vdev %i update key %i needs update\n",
439 arvif->vdev_id, key->keyidx);
440
441 ret = ath10k_install_peer_wep_keys(arvif, peer->addr);
442 if (ret) {
443 ath10k_warn(ar, "failed to update wep keys on vdev %i for peer %pM: %d\n",
444 arvif->vdev_id, peer->addr, ret);
445 return ret;
446 }
447 }
448
449 return 0;
450}
451
Kalle Valo5e3dd152013-06-12 20:52:10 +0300452/*********************/
453/* General utilities */
454/*********************/
455
456static inline enum wmi_phy_mode
457chan_to_phymode(const struct cfg80211_chan_def *chandef)
458{
459 enum wmi_phy_mode phymode = MODE_UNKNOWN;
460
461 switch (chandef->chan->band) {
462 case IEEE80211_BAND_2GHZ:
463 switch (chandef->width) {
464 case NL80211_CHAN_WIDTH_20_NOHT:
Peter Oh6faab122014-12-18 10:13:00 -0800465 if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM)
466 phymode = MODE_11B;
467 else
468 phymode = MODE_11G;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300469 break;
470 case NL80211_CHAN_WIDTH_20:
471 phymode = MODE_11NG_HT20;
472 break;
473 case NL80211_CHAN_WIDTH_40:
474 phymode = MODE_11NG_HT40;
475 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400476 case NL80211_CHAN_WIDTH_5:
477 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300478 case NL80211_CHAN_WIDTH_80:
479 case NL80211_CHAN_WIDTH_80P80:
480 case NL80211_CHAN_WIDTH_160:
481 phymode = MODE_UNKNOWN;
482 break;
483 }
484 break;
485 case IEEE80211_BAND_5GHZ:
486 switch (chandef->width) {
487 case NL80211_CHAN_WIDTH_20_NOHT:
488 phymode = MODE_11A;
489 break;
490 case NL80211_CHAN_WIDTH_20:
491 phymode = MODE_11NA_HT20;
492 break;
493 case NL80211_CHAN_WIDTH_40:
494 phymode = MODE_11NA_HT40;
495 break;
496 case NL80211_CHAN_WIDTH_80:
497 phymode = MODE_11AC_VHT80;
498 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400499 case NL80211_CHAN_WIDTH_5:
500 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300501 case NL80211_CHAN_WIDTH_80P80:
502 case NL80211_CHAN_WIDTH_160:
503 phymode = MODE_UNKNOWN;
504 break;
505 }
506 break;
507 default:
508 break;
509 }
510
511 WARN_ON(phymode == MODE_UNKNOWN);
512 return phymode;
513}
514
515static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
516{
517/*
518 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
519 * 0 for no restriction
520 * 1 for 1/4 us
521 * 2 for 1/2 us
522 * 3 for 1 us
523 * 4 for 2 us
524 * 5 for 4 us
525 * 6 for 8 us
526 * 7 for 16 us
527 */
528 switch (mpdudensity) {
529 case 0:
530 return 0;
531 case 1:
532 case 2:
533 case 3:
534 /* Our lower layer calculations limit our precision to
535 1 microsecond */
536 return 1;
537 case 4:
538 return 2;
539 case 5:
540 return 4;
541 case 6:
542 return 8;
543 case 7:
544 return 16;
545 default:
546 return 0;
547 }
548}
549
Michal Kazior500ff9f2015-03-31 10:26:21 +0000550int ath10k_mac_vif_chan(struct ieee80211_vif *vif,
551 struct cfg80211_chan_def *def)
552{
553 struct ieee80211_chanctx_conf *conf;
554
555 rcu_read_lock();
556 conf = rcu_dereference(vif->chanctx_conf);
557 if (!conf) {
558 rcu_read_unlock();
559 return -ENOENT;
560 }
561
562 *def = conf->def;
563 rcu_read_unlock();
564
565 return 0;
566}
567
568static void ath10k_mac_num_chanctxs_iter(struct ieee80211_hw *hw,
569 struct ieee80211_chanctx_conf *conf,
570 void *data)
571{
572 int *num = data;
573
574 (*num)++;
575}
576
577static int ath10k_mac_num_chanctxs(struct ath10k *ar)
578{
579 int num = 0;
580
581 ieee80211_iter_chan_contexts_atomic(ar->hw,
582 ath10k_mac_num_chanctxs_iter,
583 &num);
584
585 return num;
586}
587
588static void
589ath10k_mac_get_any_chandef_iter(struct ieee80211_hw *hw,
590 struct ieee80211_chanctx_conf *conf,
591 void *data)
592{
593 struct cfg80211_chan_def **def = data;
594
595 *def = &conf->def;
596}
597
Marek Puzyniak7390ed32015-03-30 09:51:52 +0300598static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr,
599 enum wmi_peer_type peer_type)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300600{
Michal Kaziore04cafb2015-08-05 12:15:24 +0200601 struct ath10k_vif *arvif;
602 int num_peers = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300603 int ret;
604
605 lockdep_assert_held(&ar->conf_mutex);
606
Michal Kaziore04cafb2015-08-05 12:15:24 +0200607 num_peers = ar->num_peers;
608
609 /* Each vdev consumes a peer entry as well */
610 list_for_each_entry(arvif, &ar->arvifs, list)
611 num_peers++;
612
613 if (num_peers >= ar->max_num_peers)
Michal Kaziorcfd10612014-11-25 15:16:05 +0100614 return -ENOBUFS;
615
Marek Puzyniak7390ed32015-03-30 09:51:52 +0300616 ret = ath10k_wmi_peer_create(ar, vdev_id, addr, peer_type);
Ben Greear479398b2013-11-04 09:19:34 -0800617 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200618 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200619 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300620 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800621 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300622
623 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800624 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200625 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200626 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300627 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800628 }
Michal Kazior292a7532014-11-25 15:16:04 +0100629
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100630 ar->num_peers++;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300631
632 return 0;
633}
634
Kalle Valo5a13e762014-01-20 11:01:46 +0200635static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
636{
637 struct ath10k *ar = arvif->ar;
638 u32 param;
639 int ret;
640
641 param = ar->wmi.pdev_param->sta_kickout_th;
642 ret = ath10k_wmi_pdev_set_param(ar, param,
643 ATH10K_KICKOUT_THRESHOLD);
644 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200645 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200646 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200647 return ret;
648 }
649
650 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
651 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
652 ATH10K_KEEPALIVE_MIN_IDLE);
653 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200654 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200655 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200656 return ret;
657 }
658
659 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
660 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
661 ATH10K_KEEPALIVE_MAX_IDLE);
662 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200663 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200664 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200665 return ret;
666 }
667
668 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
669 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
670 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
671 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200672 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200673 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200674 return ret;
675 }
676
677 return 0;
678}
679
Vivek Natarajanacab6402014-11-26 09:06:12 +0200680static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
Michal Kazior424121c2013-07-22 14:13:31 +0200681{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200682 struct ath10k *ar = arvif->ar;
683 u32 vdev_param;
684
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200685 vdev_param = ar->wmi.vdev_param->rts_threshold;
686 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200687}
688
Kalle Valo5e3dd152013-06-12 20:52:10 +0300689static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
690{
691 int ret;
692
693 lockdep_assert_held(&ar->conf_mutex);
694
695 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
696 if (ret)
697 return ret;
698
699 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
700 if (ret)
701 return ret;
702
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100703 ar->num_peers--;
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100704
Kalle Valo5e3dd152013-06-12 20:52:10 +0300705 return 0;
706}
707
708static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
709{
710 struct ath10k_peer *peer, *tmp;
711
712 lockdep_assert_held(&ar->conf_mutex);
713
714 spin_lock_bh(&ar->data_lock);
715 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
716 if (peer->vdev_id != vdev_id)
717 continue;
718
Michal Kazior7aa7a722014-08-25 12:09:38 +0200719 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300720 peer->addr, vdev_id);
721
722 list_del(&peer->list);
723 kfree(peer);
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100724 ar->num_peers--;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300725 }
726 spin_unlock_bh(&ar->data_lock);
727}
728
Michal Kaziora96d7742013-07-16 09:38:56 +0200729static void ath10k_peer_cleanup_all(struct ath10k *ar)
730{
731 struct ath10k_peer *peer, *tmp;
732
733 lockdep_assert_held(&ar->conf_mutex);
734
735 spin_lock_bh(&ar->data_lock);
736 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
737 list_del(&peer->list);
738 kfree(peer);
739 }
740 spin_unlock_bh(&ar->data_lock);
Michal Kazior292a7532014-11-25 15:16:04 +0100741
742 ar->num_peers = 0;
Michal Kaziorcfd10612014-11-25 15:16:05 +0100743 ar->num_stations = 0;
Michal Kaziora96d7742013-07-16 09:38:56 +0200744}
745
Marek Puzyniak75d85fd2015-03-30 09:51:53 +0300746static int ath10k_mac_tdls_peer_update(struct ath10k *ar, u32 vdev_id,
747 struct ieee80211_sta *sta,
748 enum wmi_tdls_peer_state state)
749{
750 int ret;
751 struct wmi_tdls_peer_update_cmd_arg arg = {};
752 struct wmi_tdls_peer_capab_arg cap = {};
753 struct wmi_channel_arg chan_arg = {};
754
755 lockdep_assert_held(&ar->conf_mutex);
756
757 arg.vdev_id = vdev_id;
758 arg.peer_state = state;
759 ether_addr_copy(arg.addr, sta->addr);
760
761 cap.peer_max_sp = sta->max_sp;
762 cap.peer_uapsd_queues = sta->uapsd_queues;
763
764 if (state == WMI_TDLS_PEER_STATE_CONNECTED &&
765 !sta->tdls_initiator)
766 cap.is_peer_responder = 1;
767
768 ret = ath10k_wmi_tdls_peer_update(ar, &arg, &cap, &chan_arg);
769 if (ret) {
770 ath10k_warn(ar, "failed to update tdls peer %pM on vdev %i: %i\n",
771 arg.addr, vdev_id, ret);
772 return ret;
773 }
774
775 return 0;
776}
777
Kalle Valo5e3dd152013-06-12 20:52:10 +0300778/************************/
779/* Interface management */
780/************************/
781
Michal Kazior64badcb2014-09-18 11:18:02 +0300782void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
783{
784 struct ath10k *ar = arvif->ar;
785
786 lockdep_assert_held(&ar->data_lock);
787
788 if (!arvif->beacon)
789 return;
790
791 if (!arvif->beacon_buf)
792 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
793 arvif->beacon->len, DMA_TO_DEVICE);
794
Michal Kazioraf213192015-01-29 14:29:52 +0200795 if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED &&
796 arvif->beacon_state != ATH10K_BEACON_SENT))
797 return;
798
Michal Kazior64badcb2014-09-18 11:18:02 +0300799 dev_kfree_skb_any(arvif->beacon);
800
801 arvif->beacon = NULL;
Michal Kazioraf213192015-01-29 14:29:52 +0200802 arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
Michal Kazior64badcb2014-09-18 11:18:02 +0300803}
804
805static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
806{
807 struct ath10k *ar = arvif->ar;
808
809 lockdep_assert_held(&ar->data_lock);
810
811 ath10k_mac_vif_beacon_free(arvif);
812
813 if (arvif->beacon_buf) {
814 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
815 arvif->beacon_buf, arvif->beacon_paddr);
816 arvif->beacon_buf = NULL;
817 }
818}
819
Kalle Valo5e3dd152013-06-12 20:52:10 +0300820static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
821{
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +0300822 unsigned long time_left;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300823
Michal Kazior548db542013-07-05 16:15:15 +0300824 lockdep_assert_held(&ar->conf_mutex);
825
Michal Kazior7962b0d2014-10-28 10:34:38 +0100826 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
827 return -ESHUTDOWN;
828
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +0300829 time_left = wait_for_completion_timeout(&ar->vdev_setup_done,
830 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
831 if (time_left == 0)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300832 return -ETIMEDOUT;
833
834 return 0;
835}
836
Michal Kazior1bbc0972014-04-08 09:45:47 +0300837static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300838{
Michal Kazior500ff9f2015-03-31 10:26:21 +0000839 struct cfg80211_chan_def *chandef = NULL;
Maninder Singh19be9e92015-07-16 09:25:33 +0530840 struct ieee80211_channel *channel = NULL;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300841 struct wmi_vdev_start_request_arg arg = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +0300842 int ret = 0;
843
844 lockdep_assert_held(&ar->conf_mutex);
845
Michal Kazior500ff9f2015-03-31 10:26:21 +0000846 ieee80211_iter_chan_contexts_atomic(ar->hw,
847 ath10k_mac_get_any_chandef_iter,
848 &chandef);
849 if (WARN_ON_ONCE(!chandef))
850 return -ENOENT;
851
852 channel = chandef->chan;
853
Kalle Valo5e3dd152013-06-12 20:52:10 +0300854 arg.vdev_id = vdev_id;
855 arg.channel.freq = channel->center_freq;
Michal Kaziorc930f742014-01-23 11:38:25 +0100856 arg.channel.band_center_freq1 = chandef->center_freq1;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300857
858 /* TODO setup this dynamically, what in case we
859 don't have any vifs? */
Michal Kaziorc930f742014-01-23 11:38:25 +0100860 arg.channel.mode = chan_to_phymode(chandef);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200861 arg.channel.chan_radar =
862 !!(channel->flags & IEEE80211_CHAN_RADAR);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300863
Michal Kazior89c5c842013-10-23 04:02:13 -0700864 arg.channel.min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -0700865 arg.channel.max_power = channel->max_power * 2;
866 arg.channel.max_reg_power = channel->max_reg_power * 2;
867 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300868
Michal Kazior7962b0d2014-10-28 10:34:38 +0100869 reinit_completion(&ar->vdev_setup_done);
870
Kalle Valo5e3dd152013-06-12 20:52:10 +0300871 ret = ath10k_wmi_vdev_start(ar, &arg);
872 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200873 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200874 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300875 return ret;
876 }
877
878 ret = ath10k_vdev_setup_sync(ar);
879 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +0200880 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200881 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300882 return ret;
883 }
884
885 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
886 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200887 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200888 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300889 goto vdev_stop;
890 }
891
892 ar->monitor_vdev_id = vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300893
Michal Kazior7aa7a722014-08-25 12:09:38 +0200894 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300895 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300896 return 0;
897
898vdev_stop:
899 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
900 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200901 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200902 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300903
904 return ret;
905}
906
Michal Kazior1bbc0972014-04-08 09:45:47 +0300907static int ath10k_monitor_vdev_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300908{
909 int ret = 0;
910
911 lockdep_assert_held(&ar->conf_mutex);
912
Marek Puzyniak52fa0192013-09-24 14:06:24 +0200913 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
914 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200915 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200916 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300917
Michal Kazior7962b0d2014-10-28 10:34:38 +0100918 reinit_completion(&ar->vdev_setup_done);
919
Kalle Valo5e3dd152013-06-12 20:52:10 +0300920 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
921 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200922 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200923 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300924
925 ret = ath10k_vdev_setup_sync(ar);
926 if (ret)
Ben Greear60028a82015-02-15 16:50:39 +0200927 ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200928 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300929
Michal Kazior7aa7a722014-08-25 12:09:38 +0200930 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300931 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300932 return ret;
933}
934
Michal Kazior1bbc0972014-04-08 09:45:47 +0300935static int ath10k_monitor_vdev_create(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300936{
937 int bit, ret = 0;
938
939 lockdep_assert_held(&ar->conf_mutex);
940
Ben Greeara9aefb32014-08-12 11:02:19 +0300941 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200942 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +0300943 return -ENOMEM;
944 }
945
Ben Greear16c11172014-09-23 14:17:16 -0700946 bit = __ffs64(ar->free_vdev_map);
Ben Greeara9aefb32014-08-12 11:02:19 +0300947
Ben Greear16c11172014-09-23 14:17:16 -0700948 ar->monitor_vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300949
950 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
951 WMI_VDEV_TYPE_MONITOR,
952 0, ar->mac_addr);
953 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200954 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200955 ar->monitor_vdev_id, ret);
Ben Greeara9aefb32014-08-12 11:02:19 +0300956 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300957 }
958
Ben Greear16c11172014-09-23 14:17:16 -0700959 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
Michal Kazior7aa7a722014-08-25 12:09:38 +0200960 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300961 ar->monitor_vdev_id);
962
Kalle Valo5e3dd152013-06-12 20:52:10 +0300963 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300964}
965
Michal Kazior1bbc0972014-04-08 09:45:47 +0300966static int ath10k_monitor_vdev_delete(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300967{
968 int ret = 0;
969
970 lockdep_assert_held(&ar->conf_mutex);
971
Kalle Valo5e3dd152013-06-12 20:52:10 +0300972 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
973 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200974 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200975 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300976 return ret;
977 }
978
Ben Greear16c11172014-09-23 14:17:16 -0700979 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300980
Michal Kazior7aa7a722014-08-25 12:09:38 +0200981 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300982 ar->monitor_vdev_id);
983 return ret;
984}
985
Michal Kazior1bbc0972014-04-08 09:45:47 +0300986static int ath10k_monitor_start(struct ath10k *ar)
987{
988 int ret;
989
990 lockdep_assert_held(&ar->conf_mutex);
991
Michal Kazior1bbc0972014-04-08 09:45:47 +0300992 ret = ath10k_monitor_vdev_create(ar);
993 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200994 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300995 return ret;
996 }
997
998 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
999 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001000 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +03001001 ath10k_monitor_vdev_delete(ar);
1002 return ret;
1003 }
1004
1005 ar->monitor_started = true;
Michal Kazior7aa7a722014-08-25 12:09:38 +02001006 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
Michal Kazior1bbc0972014-04-08 09:45:47 +03001007
1008 return 0;
1009}
1010
Michal Kazior19337472014-08-28 12:58:16 +02001011static int ath10k_monitor_stop(struct ath10k *ar)
Michal Kazior1bbc0972014-04-08 09:45:47 +03001012{
1013 int ret;
1014
1015 lockdep_assert_held(&ar->conf_mutex);
1016
Michal Kazior1bbc0972014-04-08 09:45:47 +03001017 ret = ath10k_monitor_vdev_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +02001018 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001019 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +02001020 return ret;
1021 }
Michal Kazior1bbc0972014-04-08 09:45:47 +03001022
1023 ret = ath10k_monitor_vdev_delete(ar);
Michal Kazior19337472014-08-28 12:58:16 +02001024 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001025 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +02001026 return ret;
1027 }
Michal Kazior1bbc0972014-04-08 09:45:47 +03001028
1029 ar->monitor_started = false;
Michal Kazior7aa7a722014-08-25 12:09:38 +02001030 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
Michal Kazior19337472014-08-28 12:58:16 +02001031
1032 return 0;
1033}
1034
Michal Kazior500ff9f2015-03-31 10:26:21 +00001035static bool ath10k_mac_monitor_vdev_is_needed(struct ath10k *ar)
1036{
1037 int num_ctx;
1038
1039 /* At least one chanctx is required to derive a channel to start
1040 * monitor vdev on.
1041 */
1042 num_ctx = ath10k_mac_num_chanctxs(ar);
1043 if (num_ctx == 0)
1044 return false;
1045
1046 /* If there's already an existing special monitor interface then don't
1047 * bother creating another monitor vdev.
1048 */
1049 if (ar->monitor_arvif)
1050 return false;
1051
1052 return ar->monitor ||
Michal Kazior500ff9f2015-03-31 10:26:21 +00001053 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1054}
1055
1056static bool ath10k_mac_monitor_vdev_is_allowed(struct ath10k *ar)
1057{
1058 int num_ctx;
1059
1060 num_ctx = ath10k_mac_num_chanctxs(ar);
1061
1062 /* FIXME: Current interface combinations and cfg80211/mac80211 code
1063 * shouldn't allow this but make sure to prevent handling the following
1064 * case anyway since multi-channel DFS hasn't been tested at all.
1065 */
1066 if (test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags) && num_ctx > 1)
1067 return false;
1068
1069 return true;
1070}
1071
Michal Kazior19337472014-08-28 12:58:16 +02001072static int ath10k_monitor_recalc(struct ath10k *ar)
1073{
Michal Kazior500ff9f2015-03-31 10:26:21 +00001074 bool needed;
1075 bool allowed;
1076 int ret;
Michal Kazior19337472014-08-28 12:58:16 +02001077
1078 lockdep_assert_held(&ar->conf_mutex);
1079
Michal Kazior500ff9f2015-03-31 10:26:21 +00001080 needed = ath10k_mac_monitor_vdev_is_needed(ar);
1081 allowed = ath10k_mac_monitor_vdev_is_allowed(ar);
Michal Kazior19337472014-08-28 12:58:16 +02001082
1083 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior500ff9f2015-03-31 10:26:21 +00001084 "mac monitor recalc started? %d needed? %d allowed? %d\n",
1085 ar->monitor_started, needed, allowed);
Michal Kazior19337472014-08-28 12:58:16 +02001086
Michal Kazior500ff9f2015-03-31 10:26:21 +00001087 if (WARN_ON(needed && !allowed)) {
1088 if (ar->monitor_started) {
1089 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopping disallowed monitor\n");
1090
1091 ret = ath10k_monitor_stop(ar);
1092 if (ret)
1093 ath10k_warn(ar, "failed to stop disallowed monitor: %d\n", ret);
1094 /* not serious */
1095 }
1096
1097 return -EPERM;
1098 }
1099
1100 if (needed == ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02001101 return 0;
1102
Michal Kazior500ff9f2015-03-31 10:26:21 +00001103 if (needed)
Michal Kazior19337472014-08-28 12:58:16 +02001104 return ath10k_monitor_start(ar);
Michal Kazior500ff9f2015-03-31 10:26:21 +00001105 else
1106 return ath10k_monitor_stop(ar);
Michal Kazior1bbc0972014-04-08 09:45:47 +03001107}
1108
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001109static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
1110{
1111 struct ath10k *ar = arvif->ar;
1112 u32 vdev_param, rts_cts = 0;
1113
1114 lockdep_assert_held(&ar->conf_mutex);
1115
1116 vdev_param = ar->wmi.vdev_param->enable_rtscts;
1117
Rajkumar Manoharan9a5ab0f2015-03-19 16:03:29 +02001118 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001119
1120 if (arvif->num_legacy_stations > 0)
1121 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
1122 WMI_RTSCTS_PROFILE);
Rajkumar Manoharan9a5ab0f2015-03-19 16:03:29 +02001123 else
1124 rts_cts |= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES,
1125 WMI_RTSCTS_PROFILE);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001126
1127 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
1128 rts_cts);
1129}
1130
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001131static int ath10k_start_cac(struct ath10k *ar)
1132{
1133 int ret;
1134
1135 lockdep_assert_held(&ar->conf_mutex);
1136
1137 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1138
Michal Kazior19337472014-08-28 12:58:16 +02001139 ret = ath10k_monitor_recalc(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001140 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001141 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001142 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1143 return ret;
1144 }
1145
Michal Kazior7aa7a722014-08-25 12:09:38 +02001146 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001147 ar->monitor_vdev_id);
1148
1149 return 0;
1150}
1151
1152static int ath10k_stop_cac(struct ath10k *ar)
1153{
1154 lockdep_assert_held(&ar->conf_mutex);
1155
1156 /* CAC is not running - do nothing */
1157 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
1158 return 0;
1159
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001160 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
Michal Kazior1bbc0972014-04-08 09:45:47 +03001161 ath10k_monitor_stop(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001162
Michal Kazior7aa7a722014-08-25 12:09:38 +02001163 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001164
1165 return 0;
1166}
1167
Michal Kazior500ff9f2015-03-31 10:26:21 +00001168static void ath10k_mac_has_radar_iter(struct ieee80211_hw *hw,
1169 struct ieee80211_chanctx_conf *conf,
1170 void *data)
1171{
1172 bool *ret = data;
1173
1174 if (!*ret && conf->radar_enabled)
1175 *ret = true;
1176}
1177
1178static bool ath10k_mac_has_radar_enabled(struct ath10k *ar)
1179{
1180 bool has_radar = false;
1181
1182 ieee80211_iter_chan_contexts_atomic(ar->hw,
1183 ath10k_mac_has_radar_iter,
1184 &has_radar);
1185
1186 return has_radar;
1187}
1188
Michal Kaziord6500972014-04-08 09:56:09 +03001189static void ath10k_recalc_radar_detection(struct ath10k *ar)
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001190{
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001191 int ret;
1192
1193 lockdep_assert_held(&ar->conf_mutex);
1194
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001195 ath10k_stop_cac(ar);
1196
Michal Kazior500ff9f2015-03-31 10:26:21 +00001197 if (!ath10k_mac_has_radar_enabled(ar))
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001198 return;
1199
Michal Kaziord6500972014-04-08 09:56:09 +03001200 if (ar->num_started_vdevs > 0)
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001201 return;
1202
1203 ret = ath10k_start_cac(ar);
1204 if (ret) {
1205 /*
1206 * Not possible to start CAC on current channel so starting
1207 * radiation is not allowed, make this channel DFS_UNAVAILABLE
1208 * by indicating that radar was detected.
1209 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02001210 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001211 ieee80211_radar_detected(ar->hw);
1212 }
1213}
1214
Vasanthakumar Thiagarajan822b7e02015-03-02 17:45:27 +05301215static int ath10k_vdev_stop(struct ath10k_vif *arvif)
Michal Kazior72654fa2014-04-08 09:56:09 +03001216{
1217 struct ath10k *ar = arvif->ar;
Vasanthakumar Thiagarajan822b7e02015-03-02 17:45:27 +05301218 int ret;
1219
1220 lockdep_assert_held(&ar->conf_mutex);
1221
1222 reinit_completion(&ar->vdev_setup_done);
1223
1224 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
1225 if (ret) {
1226 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
1227 arvif->vdev_id, ret);
1228 return ret;
1229 }
1230
1231 ret = ath10k_vdev_setup_sync(ar);
1232 if (ret) {
1233 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
1234 arvif->vdev_id, ret);
1235 return ret;
1236 }
1237
1238 WARN_ON(ar->num_started_vdevs == 0);
1239
1240 if (ar->num_started_vdevs != 0) {
1241 ar->num_started_vdevs--;
1242 ath10k_recalc_radar_detection(ar);
1243 }
1244
1245 return ret;
1246}
1247
Michal Kazior500ff9f2015-03-31 10:26:21 +00001248static int ath10k_vdev_start_restart(struct ath10k_vif *arvif,
1249 const struct cfg80211_chan_def *chandef,
1250 bool restart)
Michal Kazior72654fa2014-04-08 09:56:09 +03001251{
1252 struct ath10k *ar = arvif->ar;
Michal Kazior72654fa2014-04-08 09:56:09 +03001253 struct wmi_vdev_start_request_arg arg = {};
1254 int ret = 0;
1255
1256 lockdep_assert_held(&ar->conf_mutex);
1257
1258 reinit_completion(&ar->vdev_setup_done);
1259
1260 arg.vdev_id = arvif->vdev_id;
1261 arg.dtim_period = arvif->dtim_period;
1262 arg.bcn_intval = arvif->beacon_interval;
1263
1264 arg.channel.freq = chandef->chan->center_freq;
1265 arg.channel.band_center_freq1 = chandef->center_freq1;
1266 arg.channel.mode = chan_to_phymode(chandef);
1267
1268 arg.channel.min_power = 0;
1269 arg.channel.max_power = chandef->chan->max_power * 2;
1270 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
1271 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
1272
1273 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1274 arg.ssid = arvif->u.ap.ssid;
1275 arg.ssid_len = arvif->u.ap.ssid_len;
1276 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
1277
1278 /* For now allow DFS for AP mode */
1279 arg.channel.chan_radar =
1280 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
1281 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
1282 arg.ssid = arvif->vif->bss_conf.ssid;
1283 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
1284 }
1285
Michal Kazior7aa7a722014-08-25 12:09:38 +02001286 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior72654fa2014-04-08 09:56:09 +03001287 "mac vdev %d start center_freq %d phymode %s\n",
1288 arg.vdev_id, arg.channel.freq,
1289 ath10k_wmi_phymode_str(arg.channel.mode));
1290
Michal Kaziordc55e302014-07-29 12:53:36 +03001291 if (restart)
1292 ret = ath10k_wmi_vdev_restart(ar, &arg);
1293 else
1294 ret = ath10k_wmi_vdev_start(ar, &arg);
1295
Michal Kazior72654fa2014-04-08 09:56:09 +03001296 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001297 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +03001298 arg.vdev_id, ret);
1299 return ret;
1300 }
1301
1302 ret = ath10k_vdev_setup_sync(ar);
1303 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +02001304 ath10k_warn(ar,
1305 "failed to synchronize setup for vdev %i restart %d: %d\n",
1306 arg.vdev_id, restart, ret);
Michal Kazior72654fa2014-04-08 09:56:09 +03001307 return ret;
1308 }
1309
Michal Kaziord6500972014-04-08 09:56:09 +03001310 ar->num_started_vdevs++;
1311 ath10k_recalc_radar_detection(ar);
1312
Michal Kazior72654fa2014-04-08 09:56:09 +03001313 return ret;
1314}
1315
Michal Kazior500ff9f2015-03-31 10:26:21 +00001316static int ath10k_vdev_start(struct ath10k_vif *arvif,
1317 const struct cfg80211_chan_def *def)
Michal Kaziordc55e302014-07-29 12:53:36 +03001318{
Michal Kazior500ff9f2015-03-31 10:26:21 +00001319 return ath10k_vdev_start_restart(arvif, def, false);
Michal Kaziordc55e302014-07-29 12:53:36 +03001320}
1321
Michal Kazior500ff9f2015-03-31 10:26:21 +00001322static int ath10k_vdev_restart(struct ath10k_vif *arvif,
1323 const struct cfg80211_chan_def *def)
Michal Kaziordc55e302014-07-29 12:53:36 +03001324{
Michal Kazior500ff9f2015-03-31 10:26:21 +00001325 return ath10k_vdev_start_restart(arvif, def, true);
Michal Kazior72654fa2014-04-08 09:56:09 +03001326}
1327
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001328static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
1329 struct sk_buff *bcn)
1330{
1331 struct ath10k *ar = arvif->ar;
1332 struct ieee80211_mgmt *mgmt;
1333 const u8 *p2p_ie;
1334 int ret;
1335
1336 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1337 return 0;
1338
1339 if (arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1340 return 0;
1341
1342 mgmt = (void *)bcn->data;
1343 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1344 mgmt->u.beacon.variable,
1345 bcn->len - (mgmt->u.beacon.variable -
1346 bcn->data));
1347 if (!p2p_ie)
1348 return -ENOENT;
1349
1350 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1351 if (ret) {
1352 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1353 arvif->vdev_id, ret);
1354 return ret;
1355 }
1356
1357 return 0;
1358}
1359
1360static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1361 u8 oui_type, size_t ie_offset)
1362{
1363 size_t len;
1364 const u8 *next;
1365 const u8 *end;
1366 u8 *ie;
1367
1368 if (WARN_ON(skb->len < ie_offset))
1369 return -EINVAL;
1370
1371 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1372 skb->data + ie_offset,
1373 skb->len - ie_offset);
1374 if (!ie)
1375 return -ENOENT;
1376
1377 len = ie[1] + 2;
1378 end = skb->data + skb->len;
1379 next = ie + len;
1380
1381 if (WARN_ON(next > end))
1382 return -EINVAL;
1383
1384 memmove(ie, next, end - next);
1385 skb_trim(skb, skb->len - len);
1386
1387 return 0;
1388}
1389
1390static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1391{
1392 struct ath10k *ar = arvif->ar;
1393 struct ieee80211_hw *hw = ar->hw;
1394 struct ieee80211_vif *vif = arvif->vif;
1395 struct ieee80211_mutable_offsets offs = {};
1396 struct sk_buff *bcn;
1397 int ret;
1398
1399 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1400 return 0;
1401
Michal Kazior81a9a172015-03-05 16:02:17 +02001402 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
1403 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
1404 return 0;
1405
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001406 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1407 if (!bcn) {
1408 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1409 return -EPERM;
1410 }
1411
1412 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1413 if (ret) {
1414 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1415 kfree_skb(bcn);
1416 return ret;
1417 }
1418
1419 /* P2P IE is inserted by firmware automatically (as configured above)
1420 * so remove it from the base beacon template to avoid duplicate P2P
1421 * IEs in beacon frames.
1422 */
1423 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1424 offsetof(struct ieee80211_mgmt,
1425 u.beacon.variable));
1426
1427 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1428 0, NULL, 0);
1429 kfree_skb(bcn);
1430
1431 if (ret) {
1432 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1433 ret);
1434 return ret;
1435 }
1436
1437 return 0;
1438}
1439
1440static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1441{
1442 struct ath10k *ar = arvif->ar;
1443 struct ieee80211_hw *hw = ar->hw;
1444 struct ieee80211_vif *vif = arvif->vif;
1445 struct sk_buff *prb;
1446 int ret;
1447
1448 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1449 return 0;
1450
Michal Kazior81a9a172015-03-05 16:02:17 +02001451 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1452 return 0;
1453
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001454 prb = ieee80211_proberesp_get(hw, vif);
1455 if (!prb) {
1456 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1457 return -EPERM;
1458 }
1459
1460 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1461 kfree_skb(prb);
1462
1463 if (ret) {
1464 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1465 ret);
1466 return ret;
1467 }
1468
1469 return 0;
1470}
1471
Michal Kazior500ff9f2015-03-31 10:26:21 +00001472static int ath10k_mac_vif_fix_hidden_ssid(struct ath10k_vif *arvif)
1473{
1474 struct ath10k *ar = arvif->ar;
1475 struct cfg80211_chan_def def;
1476 int ret;
1477
1478 /* When originally vdev is started during assign_vif_chanctx() some
1479 * information is missing, notably SSID. Firmware revisions with beacon
1480 * offloading require the SSID to be provided during vdev (re)start to
1481 * handle hidden SSID properly.
1482 *
1483 * Vdev restart must be done after vdev has been both started and
1484 * upped. Otherwise some firmware revisions (at least 10.2) fail to
1485 * deliver vdev restart response event causing timeouts during vdev
1486 * syncing in ath10k.
1487 *
1488 * Note: The vdev down/up and template reinstallation could be skipped
1489 * since only wmi-tlv firmware are known to have beacon offload and
1490 * wmi-tlv doesn't seem to misbehave like 10.2 wrt vdev restart
1491 * response delivery. It's probably more robust to keep it as is.
1492 */
1493 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1494 return 0;
1495
1496 if (WARN_ON(!arvif->is_started))
1497 return -EINVAL;
1498
1499 if (WARN_ON(!arvif->is_up))
1500 return -EINVAL;
1501
1502 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
1503 return -EINVAL;
1504
1505 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1506 if (ret) {
1507 ath10k_warn(ar, "failed to bring down ap vdev %i: %d\n",
1508 arvif->vdev_id, ret);
1509 return ret;
1510 }
1511
1512 /* Vdev down reset beacon & presp templates. Reinstall them. Otherwise
1513 * firmware will crash upon vdev up.
1514 */
1515
1516 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1517 if (ret) {
1518 ath10k_warn(ar, "failed to update beacon template: %d\n", ret);
1519 return ret;
1520 }
1521
1522 ret = ath10k_mac_setup_prb_tmpl(arvif);
1523 if (ret) {
1524 ath10k_warn(ar, "failed to update presp template: %d\n", ret);
1525 return ret;
1526 }
1527
1528 ret = ath10k_vdev_restart(arvif, &def);
1529 if (ret) {
1530 ath10k_warn(ar, "failed to restart ap vdev %i: %d\n",
1531 arvif->vdev_id, ret);
1532 return ret;
1533 }
1534
1535 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1536 arvif->bssid);
1537 if (ret) {
1538 ath10k_warn(ar, "failed to bring up ap vdev %i: %d\n",
1539 arvif->vdev_id, ret);
1540 return ret;
1541 }
1542
1543 return 0;
1544}
1545
Kalle Valo5e3dd152013-06-12 20:52:10 +03001546static void ath10k_control_beaconing(struct ath10k_vif *arvif,
Kalle Valo5b07e072014-09-14 12:50:06 +03001547 struct ieee80211_bss_conf *info)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001548{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001549 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001550 int ret = 0;
1551
Michal Kazior548db542013-07-05 16:15:15 +03001552 lockdep_assert_held(&arvif->ar->conf_mutex);
1553
Kalle Valo5e3dd152013-06-12 20:52:10 +03001554 if (!info->enable_beacon) {
Michal Kazior500ff9f2015-03-31 10:26:21 +00001555 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1556 if (ret)
1557 ath10k_warn(ar, "failed to down vdev_id %i: %d\n",
1558 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001559
Michal Kaziorc930f742014-01-23 11:38:25 +01001560 arvif->is_up = false;
1561
Michal Kazior748afc42014-01-23 12:48:21 +01001562 spin_lock_bh(&arvif->ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03001563 ath10k_mac_vif_beacon_free(arvif);
Michal Kazior748afc42014-01-23 12:48:21 +01001564 spin_unlock_bh(&arvif->ar->data_lock);
1565
Kalle Valo5e3dd152013-06-12 20:52:10 +03001566 return;
1567 }
1568
1569 arvif->tx_seq_no = 0x1000;
1570
Michal Kaziorc930f742014-01-23 11:38:25 +01001571 arvif->aid = 0;
Kalle Valob25f32c2014-09-14 12:50:49 +03001572 ether_addr_copy(arvif->bssid, info->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01001573
1574 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1575 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001576 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001577 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001578 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001579 return;
1580 }
Michal Kaziorc930f742014-01-23 11:38:25 +01001581
Michal Kaziorc930f742014-01-23 11:38:25 +01001582 arvif->is_up = true;
1583
Michal Kazior500ff9f2015-03-31 10:26:21 +00001584 ret = ath10k_mac_vif_fix_hidden_ssid(arvif);
1585 if (ret) {
1586 ath10k_warn(ar, "failed to fix hidden ssid for vdev %i, expect trouble: %d\n",
1587 arvif->vdev_id, ret);
1588 return;
1589 }
1590
Michal Kazior7aa7a722014-08-25 12:09:38 +02001591 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001592}
1593
1594static void ath10k_control_ibss(struct ath10k_vif *arvif,
1595 struct ieee80211_bss_conf *info,
1596 const u8 self_peer[ETH_ALEN])
1597{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001598 struct ath10k *ar = arvif->ar;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001599 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001600 int ret = 0;
1601
Michal Kazior548db542013-07-05 16:15:15 +03001602 lockdep_assert_held(&arvif->ar->conf_mutex);
1603
Kalle Valo5e3dd152013-06-12 20:52:10 +03001604 if (!info->ibss_joined) {
Michal Kaziorc930f742014-01-23 11:38:25 +01001605 if (is_zero_ether_addr(arvif->bssid))
Kalle Valo5e3dd152013-06-12 20:52:10 +03001606 return;
1607
Joe Perches93803b32015-03-02 19:54:49 -08001608 eth_zero_addr(arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001609
1610 return;
1611 }
1612
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001613 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1614 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001615 ATH10K_DEFAULT_ATIM);
1616 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001617 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001618 arvif->vdev_id, ret);
1619}
1620
Michal Kazior9f9b5742014-12-12 12:41:36 +01001621static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1622{
1623 struct ath10k *ar = arvif->ar;
1624 u32 param;
1625 u32 value;
1626 int ret;
1627
1628 lockdep_assert_held(&arvif->ar->conf_mutex);
1629
1630 if (arvif->u.sta.uapsd)
1631 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1632 else
1633 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1634
1635 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1636 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1637 if (ret) {
1638 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1639 value, arvif->vdev_id, ret);
1640 return ret;
1641 }
1642
1643 return 0;
1644}
1645
1646static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1647{
1648 struct ath10k *ar = arvif->ar;
1649 u32 param;
1650 u32 value;
1651 int ret;
1652
1653 lockdep_assert_held(&arvif->ar->conf_mutex);
1654
1655 if (arvif->u.sta.uapsd)
1656 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1657 else
1658 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1659
1660 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1661 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1662 param, value);
1663 if (ret) {
1664 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1665 value, arvif->vdev_id, ret);
1666 return ret;
1667 }
1668
1669 return 0;
1670}
1671
Michal Kazior424f2632015-07-09 13:08:35 +02001672static int ath10k_mac_num_vifs_started(struct ath10k *ar)
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001673{
1674 struct ath10k_vif *arvif;
1675 int num = 0;
1676
1677 lockdep_assert_held(&ar->conf_mutex);
1678
1679 list_for_each_entry(arvif, &ar->arvifs, list)
Michal Kazior424f2632015-07-09 13:08:35 +02001680 if (arvif->is_started)
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001681 num++;
1682
1683 return num;
1684}
1685
Michal Kaziorad088bf2013-10-16 15:44:46 +03001686static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001687{
Michal Kaziorad088bf2013-10-16 15:44:46 +03001688 struct ath10k *ar = arvif->ar;
Michal Kazior526549a2014-12-12 12:41:37 +01001689 struct ieee80211_vif *vif = arvif->vif;
Michal Kaziorad088bf2013-10-16 15:44:46 +03001690 struct ieee80211_conf *conf = &ar->hw->conf;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001691 enum wmi_sta_powersave_param param;
1692 enum wmi_sta_ps_mode psmode;
1693 int ret;
Michal Kazior526549a2014-12-12 12:41:37 +01001694 int ps_timeout;
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001695 bool enable_ps;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001696
Michal Kazior548db542013-07-05 16:15:15 +03001697 lockdep_assert_held(&arvif->ar->conf_mutex);
1698
Michal Kaziorad088bf2013-10-16 15:44:46 +03001699 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1700 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001701
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001702 enable_ps = arvif->ps;
1703
Michal Kazior424f2632015-07-09 13:08:35 +02001704 if (enable_ps && ath10k_mac_num_vifs_started(ar) > 1 &&
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001705 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
1706 ar->fw_features)) {
1707 ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
1708 arvif->vdev_id);
1709 enable_ps = false;
1710 }
1711
Janusz Dziedzic917826b2015-05-18 09:38:17 +00001712 if (!arvif->is_started) {
1713 /* mac80211 can update vif powersave state while disconnected.
1714 * Firmware doesn't behave nicely and consumes more power than
1715 * necessary if PS is disabled on a non-started vdev. Hence
1716 * force-enable PS for non-running vdevs.
1717 */
1718 psmode = WMI_STA_PS_MODE_ENABLED;
1719 } else if (enable_ps) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001720 psmode = WMI_STA_PS_MODE_ENABLED;
1721 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1722
Michal Kazior526549a2014-12-12 12:41:37 +01001723 ps_timeout = conf->dynamic_ps_timeout;
1724 if (ps_timeout == 0) {
1725 /* Firmware doesn't like 0 */
1726 ps_timeout = ieee80211_tu_to_usec(
1727 vif->bss_conf.beacon_int) / 1000;
1728 }
1729
Michal Kaziorad088bf2013-10-16 15:44:46 +03001730 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
Michal Kazior526549a2014-12-12 12:41:37 +01001731 ps_timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001732 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001733 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001734 arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001735 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001736 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001737 } else {
1738 psmode = WMI_STA_PS_MODE_DISABLED;
1739 }
1740
Michal Kazior7aa7a722014-08-25 12:09:38 +02001741 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001742 arvif->vdev_id, psmode ? "enable" : "disable");
1743
Michal Kaziorad088bf2013-10-16 15:44:46 +03001744 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1745 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001746 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001747 psmode, arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001748 return ret;
1749 }
1750
1751 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001752}
1753
Michal Kazior46725b152015-01-28 09:57:49 +02001754static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1755{
1756 struct ath10k *ar = arvif->ar;
1757 struct wmi_sta_keepalive_arg arg = {};
1758 int ret;
1759
1760 lockdep_assert_held(&arvif->ar->conf_mutex);
1761
1762 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1763 return 0;
1764
1765 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1766 return 0;
1767
1768 /* Some firmware revisions have a bug and ignore the `enabled` field.
1769 * Instead use the interval to disable the keepalive.
1770 */
1771 arg.vdev_id = arvif->vdev_id;
1772 arg.enabled = 1;
1773 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1774 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1775
1776 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1777 if (ret) {
1778 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1779 arvif->vdev_id, ret);
1780 return ret;
1781 }
1782
1783 return 0;
1784}
1785
Michal Kazior81a9a172015-03-05 16:02:17 +02001786static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif)
1787{
1788 struct ath10k *ar = arvif->ar;
1789 struct ieee80211_vif *vif = arvif->vif;
1790 int ret;
1791
Michal Kazior8513d952015-03-09 14:19:24 +01001792 lockdep_assert_held(&arvif->ar->conf_mutex);
1793
1794 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)))
1795 return;
1796
Michal Kazior81a9a172015-03-05 16:02:17 +02001797 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1798 return;
1799
1800 if (!vif->csa_active)
1801 return;
1802
1803 if (!arvif->is_up)
1804 return;
1805
1806 if (!ieee80211_csa_is_complete(vif)) {
1807 ieee80211_csa_update_counter(vif);
1808
1809 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1810 if (ret)
1811 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
1812 ret);
1813
1814 ret = ath10k_mac_setup_prb_tmpl(arvif);
1815 if (ret)
1816 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
1817 ret);
1818 } else {
1819 ieee80211_csa_finish(vif);
1820 }
1821}
1822
1823static void ath10k_mac_vif_ap_csa_work(struct work_struct *work)
1824{
1825 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1826 ap_csa_work);
1827 struct ath10k *ar = arvif->ar;
1828
1829 mutex_lock(&ar->conf_mutex);
1830 ath10k_mac_vif_ap_csa_count_down(arvif);
1831 mutex_unlock(&ar->conf_mutex);
1832}
1833
Michal Kaziorcc9904e2015-03-10 16:22:01 +02001834static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac,
1835 struct ieee80211_vif *vif)
1836{
1837 struct sk_buff *skb = data;
1838 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1839 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1840
1841 if (vif->type != NL80211_IFTYPE_STATION)
1842 return;
1843
1844 if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
1845 return;
1846
1847 cancel_delayed_work(&arvif->connection_loss_work);
1848}
1849
1850void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb)
1851{
1852 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1853 IEEE80211_IFACE_ITER_NORMAL,
1854 ath10k_mac_handle_beacon_iter,
1855 skb);
1856}
1857
1858static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac,
1859 struct ieee80211_vif *vif)
1860{
1861 u32 *vdev_id = data;
1862 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1863 struct ath10k *ar = arvif->ar;
1864 struct ieee80211_hw *hw = ar->hw;
1865
1866 if (arvif->vdev_id != *vdev_id)
1867 return;
1868
1869 if (!arvif->is_up)
1870 return;
1871
1872 ieee80211_beacon_loss(vif);
1873
1874 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
1875 * (done by mac80211) succeeds but beacons do not resume then it
1876 * doesn't make sense to continue operation. Queue connection loss work
1877 * which can be cancelled when beacon is received.
1878 */
1879 ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
1880 ATH10K_CONNECTION_LOSS_HZ);
1881}
1882
1883void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id)
1884{
1885 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1886 IEEE80211_IFACE_ITER_NORMAL,
1887 ath10k_mac_handle_beacon_miss_iter,
1888 &vdev_id);
1889}
1890
1891static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work)
1892{
1893 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1894 connection_loss_work.work);
1895 struct ieee80211_vif *vif = arvif->vif;
1896
1897 if (!arvif->is_up)
1898 return;
1899
1900 ieee80211_connection_loss(vif);
1901}
1902
Kalle Valo5e3dd152013-06-12 20:52:10 +03001903/**********************/
1904/* Station management */
1905/**********************/
1906
Michal Kazior590922a2014-10-21 10:10:29 +03001907static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1908 struct ieee80211_vif *vif)
1909{
1910 /* Some firmware revisions have unstable STA powersave when listen
1911 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1912 * generate NullFunc frames properly even if buffered frames have been
1913 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1914 * buffered frames. Often pinging the device from AP would simply fail.
1915 *
1916 * As a workaround set it to 1.
1917 */
1918 if (vif->type == NL80211_IFTYPE_STATION)
1919 return 1;
1920
1921 return ar->hw->conf.listen_interval;
1922}
1923
Kalle Valo5e3dd152013-06-12 20:52:10 +03001924static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001925 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001926 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001927 struct wmi_peer_assoc_complete_arg *arg)
1928{
Michal Kazior590922a2014-10-21 10:10:29 +03001929 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorc51880e2015-03-30 09:51:57 +03001930 u32 aid;
Michal Kazior590922a2014-10-21 10:10:29 +03001931
Michal Kazior548db542013-07-05 16:15:15 +03001932 lockdep_assert_held(&ar->conf_mutex);
1933
Michal Kaziorc51880e2015-03-30 09:51:57 +03001934 if (vif->type == NL80211_IFTYPE_STATION)
1935 aid = vif->bss_conf.aid;
1936 else
1937 aid = sta->aid;
1938
Kalle Valob25f32c2014-09-14 12:50:49 +03001939 ether_addr_copy(arg->addr, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001940 arg->vdev_id = arvif->vdev_id;
Michal Kaziorc51880e2015-03-30 09:51:57 +03001941 arg->peer_aid = aid;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001942 arg->peer_flags |= WMI_PEER_AUTH;
Michal Kazior590922a2014-10-21 10:10:29 +03001943 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001944 arg->peer_num_spatial_streams = 1;
Michal Kazior590922a2014-10-21 10:10:29 +03001945 arg->peer_caps = vif->bss_conf.assoc_capability;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001946}
1947
1948static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001949 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001950 struct wmi_peer_assoc_complete_arg *arg)
1951{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001952 struct ieee80211_bss_conf *info = &vif->bss_conf;
Michal Kazior500ff9f2015-03-31 10:26:21 +00001953 struct cfg80211_chan_def def;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001954 struct cfg80211_bss *bss;
1955 const u8 *rsnie = NULL;
1956 const u8 *wpaie = NULL;
1957
Michal Kazior548db542013-07-05 16:15:15 +03001958 lockdep_assert_held(&ar->conf_mutex);
1959
Michal Kazior500ff9f2015-03-31 10:26:21 +00001960 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
1961 return;
1962
1963 bss = cfg80211_get_bss(ar->hw->wiphy, def.chan, info->bssid, NULL, 0,
1964 IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001965 if (bss) {
1966 const struct cfg80211_bss_ies *ies;
1967
1968 rcu_read_lock();
1969 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1970
1971 ies = rcu_dereference(bss->ies);
1972
1973 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
Kalle Valo5b07e072014-09-14 12:50:06 +03001974 WLAN_OUI_TYPE_MICROSOFT_WPA,
1975 ies->data,
1976 ies->len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001977 rcu_read_unlock();
1978 cfg80211_put_bss(ar->hw->wiphy, bss);
1979 }
1980
1981 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1982 if (rsnie || wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001983 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001984 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1985 }
1986
1987 if (wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001988 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001989 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1990 }
1991}
1992
1993static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
Michal Kazior500ff9f2015-03-31 10:26:21 +00001994 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001995 struct ieee80211_sta *sta,
1996 struct wmi_peer_assoc_complete_arg *arg)
1997{
Michal Kazior45c9abc2015-04-21 20:42:58 +03001998 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001999 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
Michal Kazior500ff9f2015-03-31 10:26:21 +00002000 struct cfg80211_chan_def def;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002001 const struct ieee80211_supported_band *sband;
2002 const struct ieee80211_rate *rates;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002003 enum ieee80211_band band;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002004 u32 ratemask;
Michal Kazior486017c2015-03-30 09:51:54 +03002005 u8 rate;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002006 int i;
2007
Michal Kazior548db542013-07-05 16:15:15 +03002008 lockdep_assert_held(&ar->conf_mutex);
2009
Michal Kazior500ff9f2015-03-31 10:26:21 +00002010 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2011 return;
2012
Michal Kazior45c9abc2015-04-21 20:42:58 +03002013 band = def.chan->band;
2014 sband = ar->hw->wiphy->bands[band];
2015 ratemask = sta->supp_rates[band];
2016 ratemask &= arvif->bitrate_mask.control[band].legacy;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002017 rates = sband->bitrates;
2018
2019 rateset->num_rates = 0;
2020
2021 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
2022 if (!(ratemask & 1))
2023 continue;
2024
Michal Kazior486017c2015-03-30 09:51:54 +03002025 rate = ath10k_mac_bitrate_to_rate(rates->bitrate);
2026 rateset->rates[rateset->num_rates] = rate;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002027 rateset->num_rates++;
2028 }
2029}
2030
Michal Kazior45c9abc2015-04-21 20:42:58 +03002031static bool
2032ath10k_peer_assoc_h_ht_masked(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
2033{
2034 int nss;
2035
2036 for (nss = 0; nss < IEEE80211_HT_MCS_MASK_LEN; nss++)
2037 if (ht_mcs_mask[nss])
2038 return false;
2039
2040 return true;
2041}
2042
2043static bool
2044ath10k_peer_assoc_h_vht_masked(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
2045{
2046 int nss;
2047
2048 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++)
2049 if (vht_mcs_mask[nss])
2050 return false;
2051
2052 return true;
2053}
2054
Kalle Valo5e3dd152013-06-12 20:52:10 +03002055static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
Michal Kazior45c9abc2015-04-21 20:42:58 +03002056 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002057 struct ieee80211_sta *sta,
2058 struct wmi_peer_assoc_complete_arg *arg)
2059{
2060 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002061 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2062 struct cfg80211_chan_def def;
2063 enum ieee80211_band band;
2064 const u8 *ht_mcs_mask;
2065 const u16 *vht_mcs_mask;
2066 int i, n, max_nss;
Kalle Valoaf762c02014-09-14 12:50:17 +03002067 u32 stbc;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002068
Michal Kazior548db542013-07-05 16:15:15 +03002069 lockdep_assert_held(&ar->conf_mutex);
2070
Michal Kazior45c9abc2015-04-21 20:42:58 +03002071 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2072 return;
2073
Kalle Valo5e3dd152013-06-12 20:52:10 +03002074 if (!ht_cap->ht_supported)
2075 return;
2076
Michal Kazior45c9abc2015-04-21 20:42:58 +03002077 band = def.chan->band;
2078 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2079 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2080
2081 if (ath10k_peer_assoc_h_ht_masked(ht_mcs_mask) &&
2082 ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2083 return;
2084
Kalle Valo5e3dd152013-06-12 20:52:10 +03002085 arg->peer_flags |= WMI_PEER_HT;
2086 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2087 ht_cap->ampdu_factor)) - 1;
2088
2089 arg->peer_mpdu_density =
2090 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
2091
2092 arg->peer_ht_caps = ht_cap->cap;
2093 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
2094
2095 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
2096 arg->peer_flags |= WMI_PEER_LDPC;
2097
2098 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
2099 arg->peer_flags |= WMI_PEER_40MHZ;
2100 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
2101 }
2102
Michal Kazior45c9abc2015-04-21 20:42:58 +03002103 if (arvif->bitrate_mask.control[band].gi != NL80211_TXRATE_FORCE_LGI) {
2104 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
2105 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002106
Michal Kazior45c9abc2015-04-21 20:42:58 +03002107 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
2108 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2109 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002110
2111 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
2112 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
2113 arg->peer_flags |= WMI_PEER_STBC;
2114 }
2115
2116 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002117 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
2118 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
2119 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
2120 arg->peer_rate_caps |= stbc;
2121 arg->peer_flags |= WMI_PEER_STBC;
2122 }
2123
Kalle Valo5e3dd152013-06-12 20:52:10 +03002124 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
2125 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
2126 else if (ht_cap->mcs.rx_mask[1])
2127 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
2128
Michal Kazior45c9abc2015-04-21 20:42:58 +03002129 for (i = 0, n = 0, max_nss = 0; i < IEEE80211_HT_MCS_MASK_LEN * 8; i++)
2130 if ((ht_cap->mcs.rx_mask[i / 8] & BIT(i % 8)) &&
2131 (ht_mcs_mask[i / 8] & BIT(i % 8))) {
2132 max_nss = (i / 8) + 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002133 arg->peer_ht_rates.rates[n++] = i;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002134 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002135
Bartosz Markowskifd71f802014-02-10 13:12:55 +01002136 /*
2137 * This is a workaround for HT-enabled STAs which break the spec
2138 * and have no HT capabilities RX mask (no HT RX MCS map).
2139 *
2140 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
2141 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
2142 *
2143 * Firmware asserts if such situation occurs.
2144 */
2145 if (n == 0) {
2146 arg->peer_ht_rates.num_rates = 8;
2147 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
2148 arg->peer_ht_rates.rates[i] = i;
2149 } else {
2150 arg->peer_ht_rates.num_rates = n;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002151 arg->peer_num_spatial_streams = max_nss;
Bartosz Markowskifd71f802014-02-10 13:12:55 +01002152 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002153
Michal Kazior7aa7a722014-08-25 12:09:38 +02002154 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03002155 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002156 arg->peer_ht_rates.num_rates,
2157 arg->peer_num_spatial_streams);
2158}
2159
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002160static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
2161 struct ath10k_vif *arvif,
2162 struct ieee80211_sta *sta)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002163{
2164 u32 uapsd = 0;
2165 u32 max_sp = 0;
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002166 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002167
Michal Kazior548db542013-07-05 16:15:15 +03002168 lockdep_assert_held(&ar->conf_mutex);
2169
Kalle Valo5e3dd152013-06-12 20:52:10 +03002170 if (sta->wme && sta->uapsd_queues) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002171 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002172 sta->uapsd_queues, sta->max_sp);
2173
Kalle Valo5e3dd152013-06-12 20:52:10 +03002174 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2175 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
2176 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
2177 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2178 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
2179 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
2180 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2181 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
2182 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
2183 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2184 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
2185 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
2186
Kalle Valo5e3dd152013-06-12 20:52:10 +03002187 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
2188 max_sp = sta->max_sp;
2189
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002190 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2191 sta->addr,
2192 WMI_AP_PS_PEER_PARAM_UAPSD,
2193 uapsd);
2194 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002195 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002196 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002197 return ret;
2198 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002199
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002200 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2201 sta->addr,
2202 WMI_AP_PS_PEER_PARAM_MAX_SP,
2203 max_sp);
2204 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002205 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002206 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002207 return ret;
2208 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002209
2210 /* TODO setup this based on STA listen interval and
2211 beacon interval. Currently we don't know
2212 sta->listen_interval - mac80211 patch required.
2213 Currently use 10 seconds */
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002214 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
Kalle Valo5b07e072014-09-14 12:50:06 +03002215 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
2216 10);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002217 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002218 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002219 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002220 return ret;
2221 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002222 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002223
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002224 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002225}
2226
Michal Kazior45c9abc2015-04-21 20:42:58 +03002227static u16
2228ath10k_peer_assoc_h_vht_limit(u16 tx_mcs_set,
2229 const u16 vht_mcs_limit[NL80211_VHT_NSS_MAX])
2230{
2231 int idx_limit;
2232 int nss;
2233 u16 mcs_map;
2234 u16 mcs;
2235
2236 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
2237 mcs_map = ath10k_mac_get_max_vht_mcs_map(tx_mcs_set, nss) &
2238 vht_mcs_limit[nss];
2239
2240 if (mcs_map)
2241 idx_limit = fls(mcs_map) - 1;
2242 else
2243 idx_limit = -1;
2244
2245 switch (idx_limit) {
2246 case 0: /* fall through */
2247 case 1: /* fall through */
2248 case 2: /* fall through */
2249 case 3: /* fall through */
2250 case 4: /* fall through */
2251 case 5: /* fall through */
2252 case 6: /* fall through */
2253 default:
2254 /* see ath10k_mac_can_set_bitrate_mask() */
2255 WARN_ON(1);
2256 /* fall through */
2257 case -1:
2258 mcs = IEEE80211_VHT_MCS_NOT_SUPPORTED;
2259 break;
2260 case 7:
2261 mcs = IEEE80211_VHT_MCS_SUPPORT_0_7;
2262 break;
2263 case 8:
2264 mcs = IEEE80211_VHT_MCS_SUPPORT_0_8;
2265 break;
2266 case 9:
2267 mcs = IEEE80211_VHT_MCS_SUPPORT_0_9;
2268 break;
2269 }
2270
2271 tx_mcs_set &= ~(0x3 << (nss * 2));
2272 tx_mcs_set |= mcs << (nss * 2);
2273 }
2274
2275 return tx_mcs_set;
2276}
2277
Kalle Valo5e3dd152013-06-12 20:52:10 +03002278static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
Michal Kazior500ff9f2015-03-31 10:26:21 +00002279 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002280 struct ieee80211_sta *sta,
2281 struct wmi_peer_assoc_complete_arg *arg)
2282{
2283 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002284 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior500ff9f2015-03-31 10:26:21 +00002285 struct cfg80211_chan_def def;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002286 enum ieee80211_band band;
2287 const u16 *vht_mcs_mask;
Sujith Manoharana24b88b2013-10-07 19:51:57 -07002288 u8 ampdu_factor;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002289
Michal Kazior500ff9f2015-03-31 10:26:21 +00002290 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2291 return;
2292
Kalle Valo5e3dd152013-06-12 20:52:10 +03002293 if (!vht_cap->vht_supported)
2294 return;
2295
Michal Kazior45c9abc2015-04-21 20:42:58 +03002296 band = def.chan->band;
2297 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2298
2299 if (ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2300 return;
2301
Kalle Valo5e3dd152013-06-12 20:52:10 +03002302 arg->peer_flags |= WMI_PEER_VHT;
Yanbo Lid68bb122015-01-23 08:18:20 +08002303
Michal Kazior500ff9f2015-03-31 10:26:21 +00002304 if (def.chan->band == IEEE80211_BAND_2GHZ)
Yanbo Lid68bb122015-01-23 08:18:20 +08002305 arg->peer_flags |= WMI_PEER_VHT_2G;
2306
Kalle Valo5e3dd152013-06-12 20:52:10 +03002307 arg->peer_vht_caps = vht_cap->cap;
2308
Sujith Manoharana24b88b2013-10-07 19:51:57 -07002309 ampdu_factor = (vht_cap->cap &
2310 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
2311 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
2312
2313 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
2314 * zero in VHT IE. Using it would result in degraded throughput.
2315 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
2316 * it if VHT max_mpdu is smaller. */
2317 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
2318 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2319 ampdu_factor)) - 1);
2320
Kalle Valo5e3dd152013-06-12 20:52:10 +03002321 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2322 arg->peer_flags |= WMI_PEER_80MHZ;
2323
2324 arg->peer_vht_rates.rx_max_rate =
2325 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
2326 arg->peer_vht_rates.rx_mcs_set =
2327 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
2328 arg->peer_vht_rates.tx_max_rate =
2329 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
Michal Kazior45c9abc2015-04-21 20:42:58 +03002330 arg->peer_vht_rates.tx_mcs_set = ath10k_peer_assoc_h_vht_limit(
2331 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map), vht_mcs_mask);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002332
Michal Kazior7aa7a722014-08-25 12:09:38 +02002333 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03002334 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002335}
2336
2337static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03002338 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002339 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002340 struct wmi_peer_assoc_complete_arg *arg)
2341{
Michal Kazior590922a2014-10-21 10:10:29 +03002342 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2343
Kalle Valo5e3dd152013-06-12 20:52:10 +03002344 switch (arvif->vdev_type) {
2345 case WMI_VDEV_TYPE_AP:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002346 if (sta->wme)
2347 arg->peer_flags |= WMI_PEER_QOS;
2348
2349 if (sta->wme && sta->uapsd_queues) {
2350 arg->peer_flags |= WMI_PEER_APSD;
2351 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
2352 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002353 break;
2354 case WMI_VDEV_TYPE_STA:
Michal Kazior590922a2014-10-21 10:10:29 +03002355 if (vif->bss_conf.qos)
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002356 arg->peer_flags |= WMI_PEER_QOS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002357 break;
Janusz Dziedzic627d9842014-12-17 12:29:54 +02002358 case WMI_VDEV_TYPE_IBSS:
2359 if (sta->wme)
2360 arg->peer_flags |= WMI_PEER_QOS;
2361 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002362 default:
2363 break;
2364 }
Janusz Dziedzic627d9842014-12-17 12:29:54 +02002365
2366 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
2367 sta->addr, !!(arg->peer_flags & WMI_PEER_QOS));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002368}
2369
Michal Kazior8d7aa6b2015-03-30 09:51:57 +03002370static bool ath10k_mac_sta_has_ofdm_only(struct ieee80211_sta *sta)
Michal Kazior91b12082014-12-12 12:41:35 +01002371{
Michal Kazior8d7aa6b2015-03-30 09:51:57 +03002372 return sta->supp_rates[IEEE80211_BAND_2GHZ] >>
2373 ATH10K_MAC_FIRST_OFDM_RATE_IDX;
Michal Kazior91b12082014-12-12 12:41:35 +01002374}
2375
Kalle Valo5e3dd152013-06-12 20:52:10 +03002376static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03002377 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002378 struct ieee80211_sta *sta,
2379 struct wmi_peer_assoc_complete_arg *arg)
2380{
Michal Kazior45c9abc2015-04-21 20:42:58 +03002381 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior500ff9f2015-03-31 10:26:21 +00002382 struct cfg80211_chan_def def;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002383 enum ieee80211_band band;
2384 const u8 *ht_mcs_mask;
2385 const u16 *vht_mcs_mask;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002386 enum wmi_phy_mode phymode = MODE_UNKNOWN;
2387
Michal Kazior500ff9f2015-03-31 10:26:21 +00002388 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2389 return;
2390
Michal Kazior45c9abc2015-04-21 20:42:58 +03002391 band = def.chan->band;
2392 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2393 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2394
2395 switch (band) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002396 case IEEE80211_BAND_2GHZ:
Michal Kazior45c9abc2015-04-21 20:42:58 +03002397 if (sta->vht_cap.vht_supported &&
2398 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
Yanbo Lid68bb122015-01-23 08:18:20 +08002399 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2400 phymode = MODE_11AC_VHT40;
2401 else
2402 phymode = MODE_11AC_VHT20;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002403 } else if (sta->ht_cap.ht_supported &&
2404 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002405 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2406 phymode = MODE_11NG_HT40;
2407 else
2408 phymode = MODE_11NG_HT20;
Michal Kazior8d7aa6b2015-03-30 09:51:57 +03002409 } else if (ath10k_mac_sta_has_ofdm_only(sta)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002410 phymode = MODE_11G;
Michal Kazior91b12082014-12-12 12:41:35 +01002411 } else {
2412 phymode = MODE_11B;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002413 }
2414
2415 break;
2416 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03002417 /*
2418 * Check VHT first.
2419 */
Michal Kazior45c9abc2015-04-21 20:42:58 +03002420 if (sta->vht_cap.vht_supported &&
2421 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03002422 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2423 phymode = MODE_11AC_VHT80;
2424 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2425 phymode = MODE_11AC_VHT40;
2426 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
2427 phymode = MODE_11AC_VHT20;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002428 } else if (sta->ht_cap.ht_supported &&
2429 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2430 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002431 phymode = MODE_11NA_HT40;
2432 else
2433 phymode = MODE_11NA_HT20;
2434 } else {
2435 phymode = MODE_11A;
2436 }
2437
2438 break;
2439 default:
2440 break;
2441 }
2442
Michal Kazior7aa7a722014-08-25 12:09:38 +02002443 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
Kalle Valo38a1d472013-09-08 17:56:14 +03002444 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03002445
Kalle Valo5e3dd152013-06-12 20:52:10 +03002446 arg->peer_phymode = phymode;
2447 WARN_ON(phymode == MODE_UNKNOWN);
2448}
2449
Kalle Valob9ada652013-10-16 15:44:46 +03002450static int ath10k_peer_assoc_prepare(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03002451 struct ieee80211_vif *vif,
Kalle Valob9ada652013-10-16 15:44:46 +03002452 struct ieee80211_sta *sta,
Kalle Valob9ada652013-10-16 15:44:46 +03002453 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002454{
Michal Kazior548db542013-07-05 16:15:15 +03002455 lockdep_assert_held(&ar->conf_mutex);
2456
Kalle Valob9ada652013-10-16 15:44:46 +03002457 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002458
Michal Kazior590922a2014-10-21 10:10:29 +03002459 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
2460 ath10k_peer_assoc_h_crypto(ar, vif, arg);
Michal Kazior500ff9f2015-03-31 10:26:21 +00002461 ath10k_peer_assoc_h_rates(ar, vif, sta, arg);
Michal Kazior45c9abc2015-04-21 20:42:58 +03002462 ath10k_peer_assoc_h_ht(ar, vif, sta, arg);
Michal Kazior500ff9f2015-03-31 10:26:21 +00002463 ath10k_peer_assoc_h_vht(ar, vif, sta, arg);
Michal Kazior590922a2014-10-21 10:10:29 +03002464 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
2465 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002466
Kalle Valob9ada652013-10-16 15:44:46 +03002467 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002468}
2469
Michal Kazior90046f52014-02-14 14:45:51 +01002470static const u32 ath10k_smps_map[] = {
2471 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
2472 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
2473 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
2474 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
2475};
2476
2477static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
2478 const u8 *addr,
2479 const struct ieee80211_sta_ht_cap *ht_cap)
2480{
2481 int smps;
2482
2483 if (!ht_cap->ht_supported)
2484 return 0;
2485
2486 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
2487 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
2488
2489 if (smps >= ARRAY_SIZE(ath10k_smps_map))
2490 return -EINVAL;
2491
2492 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
2493 WMI_PEER_SMPS_STATE,
2494 ath10k_smps_map[smps]);
2495}
2496
Michal Kazior139e1702015-02-15 16:50:42 +02002497static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
2498 struct ieee80211_vif *vif,
2499 struct ieee80211_sta_vht_cap vht_cap)
2500{
2501 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2502 int ret;
2503 u32 param;
2504 u32 value;
2505
Vivek Natarajan08e75ea2015-08-04 10:45:11 +05302506 if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_AFTER_ASSOC)
2507 return 0;
2508
Michal Kazior139e1702015-02-15 16:50:42 +02002509 if (!(ar->vht_cap_info &
2510 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2511 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
2512 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2513 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
2514 return 0;
2515
2516 param = ar->wmi.vdev_param->txbf;
2517 value = 0;
2518
2519 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
2520 return 0;
2521
2522 /* The following logic is correct. If a remote STA advertises support
2523 * for being a beamformer then we should enable us being a beamformee.
2524 */
2525
2526 if (ar->vht_cap_info &
2527 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2528 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
2529 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
2530 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2531
2532 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
2533 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
2534 }
2535
2536 if (ar->vht_cap_info &
2537 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2538 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
2539 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
2540 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2541
2542 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
2543 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
2544 }
2545
2546 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
2547 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2548
2549 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
2550 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2551
2552 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
2553 if (ret) {
2554 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
2555 value, ret);
2556 return ret;
2557 }
2558
2559 return 0;
2560}
2561
Kalle Valo5e3dd152013-06-12 20:52:10 +03002562/* can be called only in mac80211 callbacks due to `key_count` usage */
2563static void ath10k_bss_assoc(struct ieee80211_hw *hw,
2564 struct ieee80211_vif *vif,
2565 struct ieee80211_bss_conf *bss_conf)
2566{
2567 struct ath10k *ar = hw->priv;
2568 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior90046f52014-02-14 14:45:51 +01002569 struct ieee80211_sta_ht_cap ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02002570 struct ieee80211_sta_vht_cap vht_cap;
Kalle Valob9ada652013-10-16 15:44:46 +03002571 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002572 struct ieee80211_sta *ap_sta;
2573 int ret;
2574
Michal Kazior548db542013-07-05 16:15:15 +03002575 lockdep_assert_held(&ar->conf_mutex);
2576
Michal Kazior077efc82014-10-21 10:10:29 +03002577 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
2578 arvif->vdev_id, arvif->bssid, arvif->aid);
2579
Kalle Valo5e3dd152013-06-12 20:52:10 +03002580 rcu_read_lock();
2581
2582 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
2583 if (!ap_sta) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002584 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02002585 bss_conf->bssid, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002586 rcu_read_unlock();
2587 return;
2588 }
2589
Michal Kazior90046f52014-02-14 14:45:51 +01002590 /* ap_sta must be accessed only within rcu section which must be left
2591 * before calling ath10k_setup_peer_smps() which might sleep. */
2592 ht_cap = ap_sta->ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02002593 vht_cap = ap_sta->vht_cap;
Michal Kazior90046f52014-02-14 14:45:51 +01002594
Michal Kazior590922a2014-10-21 10:10:29 +03002595 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002596 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002597 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002598 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002599 rcu_read_unlock();
2600 return;
2601 }
2602
2603 rcu_read_unlock();
2604
Kalle Valob9ada652013-10-16 15:44:46 +03002605 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2606 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002607 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002608 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03002609 return;
2610 }
2611
Michal Kazior90046f52014-02-14 14:45:51 +01002612 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
2613 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002614 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002615 arvif->vdev_id, ret);
Michal Kazior90046f52014-02-14 14:45:51 +01002616 return;
2617 }
2618
Michal Kazior139e1702015-02-15 16:50:42 +02002619 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2620 if (ret) {
2621 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2622 arvif->vdev_id, bss_conf->bssid, ret);
2623 return;
2624 }
2625
Michal Kazior7aa7a722014-08-25 12:09:38 +02002626 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002627 "mac vdev %d up (associated) bssid %pM aid %d\n",
2628 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
2629
Michal Kazior077efc82014-10-21 10:10:29 +03002630 WARN_ON(arvif->is_up);
2631
Michal Kaziorc930f742014-01-23 11:38:25 +01002632 arvif->aid = bss_conf->aid;
Kalle Valob25f32c2014-09-14 12:50:49 +03002633 ether_addr_copy(arvif->bssid, bss_conf->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01002634
2635 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
2636 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002637 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002638 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01002639 return;
2640 }
2641
2642 arvif->is_up = true;
Michal Kazior0a987fb2015-02-13 13:30:15 +01002643
2644 /* Workaround: Some firmware revisions (tested with qca6174
2645 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2646 * poked with peer param command.
2647 */
2648 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
2649 WMI_PEER_DUMMY_VAR, 1);
2650 if (ret) {
2651 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2652 arvif->bssid, arvif->vdev_id, ret);
2653 return;
2654 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002655}
2656
Kalle Valo5e3dd152013-06-12 20:52:10 +03002657static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
2658 struct ieee80211_vif *vif)
2659{
2660 struct ath10k *ar = hw->priv;
2661 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior139e1702015-02-15 16:50:42 +02002662 struct ieee80211_sta_vht_cap vht_cap = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +03002663 int ret;
2664
Michal Kazior548db542013-07-05 16:15:15 +03002665 lockdep_assert_held(&ar->conf_mutex);
2666
Michal Kazior077efc82014-10-21 10:10:29 +03002667 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
2668 arvif->vdev_id, arvif->bssid);
Kalle Valo60c3daa2013-09-08 17:56:07 +03002669
Kalle Valo5e3dd152013-06-12 20:52:10 +03002670 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kazior077efc82014-10-21 10:10:29 +03002671 if (ret)
2672 ath10k_warn(ar, "faield to down vdev %i: %d\n",
2673 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002674
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02002675 arvif->def_wep_key_idx = -1;
2676
Michal Kazior139e1702015-02-15 16:50:42 +02002677 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2678 if (ret) {
2679 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
2680 arvif->vdev_id, ret);
2681 return;
2682 }
2683
Michal Kaziorc930f742014-01-23 11:38:25 +01002684 arvif->is_up = false;
Michal Kaziorcc9904e2015-03-10 16:22:01 +02002685
2686 cancel_delayed_work_sync(&arvif->connection_loss_work);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002687}
2688
Michal Kazior590922a2014-10-21 10:10:29 +03002689static int ath10k_station_assoc(struct ath10k *ar,
2690 struct ieee80211_vif *vif,
2691 struct ieee80211_sta *sta,
2692 bool reassoc)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002693{
Michal Kazior590922a2014-10-21 10:10:29 +03002694 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valob9ada652013-10-16 15:44:46 +03002695 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002696 int ret = 0;
2697
Michal Kazior548db542013-07-05 16:15:15 +03002698 lockdep_assert_held(&ar->conf_mutex);
2699
Michal Kazior590922a2014-10-21 10:10:29 +03002700 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002701 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002702 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02002703 sta->addr, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03002704 return ret;
2705 }
2706
2707 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2708 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002709 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002710 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002711 return ret;
2712 }
2713
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002714 /* Re-assoc is run only to update supported rates for given station. It
2715 * doesn't make much sense to reconfigure the peer completely.
2716 */
2717 if (!reassoc) {
2718 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
2719 &sta->ht_cap);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002720 if (ret) {
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002721 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002722 arvif->vdev_id, ret);
2723 return ret;
2724 }
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002725
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002726 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
2727 if (ret) {
2728 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
2729 sta->addr, arvif->vdev_id, ret);
2730 return ret;
2731 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002732
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002733 if (!sta->wme) {
2734 arvif->num_legacy_stations++;
2735 ret = ath10k_recalc_rtscts_prot(arvif);
2736 if (ret) {
2737 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2738 arvif->vdev_id, ret);
2739 return ret;
2740 }
2741 }
2742
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02002743 /* Plumb cached keys only for static WEP */
2744 if (arvif->def_wep_key_idx != -1) {
2745 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
2746 if (ret) {
2747 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
2748 arvif->vdev_id, ret);
2749 return ret;
2750 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002751 }
2752 }
2753
Kalle Valo5e3dd152013-06-12 20:52:10 +03002754 return ret;
2755}
2756
Michal Kazior590922a2014-10-21 10:10:29 +03002757static int ath10k_station_disassoc(struct ath10k *ar,
2758 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002759 struct ieee80211_sta *sta)
2760{
Michal Kazior590922a2014-10-21 10:10:29 +03002761 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002762 int ret = 0;
2763
2764 lockdep_assert_held(&ar->conf_mutex);
2765
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002766 if (!sta->wme) {
2767 arvif->num_legacy_stations--;
2768 ret = ath10k_recalc_rtscts_prot(arvif);
2769 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002770 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002771 arvif->vdev_id, ret);
2772 return ret;
2773 }
2774 }
2775
Kalle Valo5e3dd152013-06-12 20:52:10 +03002776 ret = ath10k_clear_peer_keys(arvif, sta->addr);
2777 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002778 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002779 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002780 return ret;
2781 }
2782
2783 return ret;
2784}
2785
2786/**************/
2787/* Regulatory */
2788/**************/
2789
2790static int ath10k_update_channel_list(struct ath10k *ar)
2791{
2792 struct ieee80211_hw *hw = ar->hw;
2793 struct ieee80211_supported_band **bands;
2794 enum ieee80211_band band;
2795 struct ieee80211_channel *channel;
2796 struct wmi_scan_chan_list_arg arg = {0};
2797 struct wmi_channel_arg *ch;
2798 bool passive;
2799 int len;
2800 int ret;
2801 int i;
2802
Michal Kazior548db542013-07-05 16:15:15 +03002803 lockdep_assert_held(&ar->conf_mutex);
2804
Kalle Valo5e3dd152013-06-12 20:52:10 +03002805 bands = hw->wiphy->bands;
2806 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2807 if (!bands[band])
2808 continue;
2809
2810 for (i = 0; i < bands[band]->n_channels; i++) {
2811 if (bands[band]->channels[i].flags &
2812 IEEE80211_CHAN_DISABLED)
2813 continue;
2814
2815 arg.n_channels++;
2816 }
2817 }
2818
2819 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
2820 arg.channels = kzalloc(len, GFP_KERNEL);
2821 if (!arg.channels)
2822 return -ENOMEM;
2823
2824 ch = arg.channels;
2825 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2826 if (!bands[band])
2827 continue;
2828
2829 for (i = 0; i < bands[band]->n_channels; i++) {
2830 channel = &bands[band]->channels[i];
2831
2832 if (channel->flags & IEEE80211_CHAN_DISABLED)
2833 continue;
2834
2835 ch->allow_ht = true;
2836
2837 /* FIXME: when should we really allow VHT? */
2838 ch->allow_vht = true;
2839
2840 ch->allow_ibss =
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002841 !(channel->flags & IEEE80211_CHAN_NO_IR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002842
2843 ch->ht40plus =
2844 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
2845
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002846 ch->chan_radar =
2847 !!(channel->flags & IEEE80211_CHAN_RADAR);
2848
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002849 passive = channel->flags & IEEE80211_CHAN_NO_IR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002850 ch->passive = passive;
2851
2852 ch->freq = channel->center_freq;
Michal Kazior2d667212014-09-18 15:21:21 +02002853 ch->band_center_freq1 = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07002854 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07002855 ch->max_power = channel->max_power * 2;
2856 ch->max_reg_power = channel->max_reg_power * 2;
2857 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002858 ch->reg_class_id = 0; /* FIXME */
2859
2860 /* FIXME: why use only legacy modes, why not any
2861 * HT/VHT modes? Would that even make any
2862 * difference? */
2863 if (channel->band == IEEE80211_BAND_2GHZ)
2864 ch->mode = MODE_11G;
2865 else
2866 ch->mode = MODE_11A;
2867
2868 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
2869 continue;
2870
Michal Kazior7aa7a722014-08-25 12:09:38 +02002871 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002872 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
2873 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002874 ch->freq, ch->max_power, ch->max_reg_power,
2875 ch->max_antenna_gain, ch->mode);
2876
2877 ch++;
2878 }
2879 }
2880
2881 ret = ath10k_wmi_scan_chan_list(ar, &arg);
2882 kfree(arg.channels);
2883
2884 return ret;
2885}
2886
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002887static enum wmi_dfs_region
2888ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
2889{
2890 switch (dfs_region) {
2891 case NL80211_DFS_UNSET:
2892 return WMI_UNINIT_DFS_DOMAIN;
2893 case NL80211_DFS_FCC:
2894 return WMI_FCC_DFS_DOMAIN;
2895 case NL80211_DFS_ETSI:
2896 return WMI_ETSI_DFS_DOMAIN;
2897 case NL80211_DFS_JP:
2898 return WMI_MKK4_DFS_DOMAIN;
2899 }
2900 return WMI_UNINIT_DFS_DOMAIN;
2901}
2902
Michal Kaziorf7843d72013-07-16 09:38:52 +02002903static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002904{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002905 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002906 int ret;
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002907 enum wmi_dfs_region wmi_dfs_reg;
2908 enum nl80211_dfs_regions nl_dfs_reg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002909
Michal Kaziorf7843d72013-07-16 09:38:52 +02002910 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002911
2912 ret = ath10k_update_channel_list(ar);
2913 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002914 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002915
2916 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002917
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002918 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
2919 nl_dfs_reg = ar->dfs_detector->region;
2920 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
2921 } else {
2922 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
2923 }
2924
Kalle Valo5e3dd152013-06-12 20:52:10 +03002925 /* Target allows setting up per-band regdomain but ath_common provides
2926 * a combined one only */
2927 ret = ath10k_wmi_pdev_set_regdomain(ar,
Kalle Valoef8c0012014-02-13 18:13:12 +02002928 regpair->reg_domain,
2929 regpair->reg_domain, /* 2ghz */
2930 regpair->reg_domain, /* 5ghz */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002931 regpair->reg_2ghz_ctl,
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002932 regpair->reg_5ghz_ctl,
2933 wmi_dfs_reg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002934 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002935 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02002936}
Michal Kazior548db542013-07-05 16:15:15 +03002937
Michal Kaziorf7843d72013-07-16 09:38:52 +02002938static void ath10k_reg_notifier(struct wiphy *wiphy,
2939 struct regulatory_request *request)
2940{
2941 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
2942 struct ath10k *ar = hw->priv;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002943 bool result;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002944
2945 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
2946
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002947 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002948 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002949 request->dfs_region);
2950 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
2951 request->dfs_region);
2952 if (!result)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002953 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002954 request->dfs_region);
2955 }
2956
Michal Kaziorf7843d72013-07-16 09:38:52 +02002957 mutex_lock(&ar->conf_mutex);
2958 if (ar->state == ATH10K_STATE_ON)
2959 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03002960 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002961}
2962
2963/***************/
2964/* TX handlers */
2965/***************/
2966
Michal Kazior96d828d2015-03-31 10:26:23 +00002967void ath10k_mac_tx_lock(struct ath10k *ar, int reason)
2968{
2969 lockdep_assert_held(&ar->htt.tx_lock);
2970
2971 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
2972 ar->tx_paused |= BIT(reason);
2973 ieee80211_stop_queues(ar->hw);
2974}
2975
2976static void ath10k_mac_tx_unlock_iter(void *data, u8 *mac,
2977 struct ieee80211_vif *vif)
2978{
2979 struct ath10k *ar = data;
2980 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2981
2982 if (arvif->tx_paused)
2983 return;
2984
2985 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
2986}
2987
2988void ath10k_mac_tx_unlock(struct ath10k *ar, int reason)
2989{
2990 lockdep_assert_held(&ar->htt.tx_lock);
2991
2992 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
2993 ar->tx_paused &= ~BIT(reason);
2994
2995 if (ar->tx_paused)
2996 return;
2997
2998 ieee80211_iterate_active_interfaces_atomic(ar->hw,
2999 IEEE80211_IFACE_ITER_RESUME_ALL,
3000 ath10k_mac_tx_unlock_iter,
3001 ar);
3002}
3003
3004void ath10k_mac_vif_tx_lock(struct ath10k_vif *arvif, int reason)
3005{
3006 struct ath10k *ar = arvif->ar;
3007
3008 lockdep_assert_held(&ar->htt.tx_lock);
3009
3010 WARN_ON(reason >= BITS_PER_LONG);
3011 arvif->tx_paused |= BIT(reason);
3012 ieee80211_stop_queue(ar->hw, arvif->vdev_id);
3013}
3014
3015void ath10k_mac_vif_tx_unlock(struct ath10k_vif *arvif, int reason)
3016{
3017 struct ath10k *ar = arvif->ar;
3018
3019 lockdep_assert_held(&ar->htt.tx_lock);
3020
3021 WARN_ON(reason >= BITS_PER_LONG);
3022 arvif->tx_paused &= ~BIT(reason);
3023
3024 if (ar->tx_paused)
3025 return;
3026
3027 if (arvif->tx_paused)
3028 return;
3029
3030 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3031}
3032
Michal Kaziorb4aa5392015-03-31 10:26:24 +00003033static void ath10k_mac_vif_handle_tx_pause(struct ath10k_vif *arvif,
3034 enum wmi_tlv_tx_pause_id pause_id,
3035 enum wmi_tlv_tx_pause_action action)
3036{
3037 struct ath10k *ar = arvif->ar;
3038
3039 lockdep_assert_held(&ar->htt.tx_lock);
3040
Michal Kazioracd0b272015-07-09 13:08:38 +02003041 switch (action) {
3042 case WMI_TLV_TX_PAUSE_ACTION_STOP:
3043 ath10k_mac_vif_tx_lock(arvif, pause_id);
Michal Kaziorb4aa5392015-03-31 10:26:24 +00003044 break;
Michal Kazioracd0b272015-07-09 13:08:38 +02003045 case WMI_TLV_TX_PAUSE_ACTION_WAKE:
3046 ath10k_mac_vif_tx_unlock(arvif, pause_id);
3047 break;
Michal Kaziorb4aa5392015-03-31 10:26:24 +00003048 default:
Michal Kazioracd0b272015-07-09 13:08:38 +02003049 ath10k_warn(ar, "received unknown tx pause action %d on vdev %i, ignoring\n",
3050 action, arvif->vdev_id);
Michal Kaziorb4aa5392015-03-31 10:26:24 +00003051 break;
3052 }
3053}
3054
3055struct ath10k_mac_tx_pause {
3056 u32 vdev_id;
3057 enum wmi_tlv_tx_pause_id pause_id;
3058 enum wmi_tlv_tx_pause_action action;
3059};
3060
3061static void ath10k_mac_handle_tx_pause_iter(void *data, u8 *mac,
3062 struct ieee80211_vif *vif)
3063{
3064 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3065 struct ath10k_mac_tx_pause *arg = data;
3066
Michal Kazioracd0b272015-07-09 13:08:38 +02003067 if (arvif->vdev_id != arg->vdev_id)
3068 return;
3069
Michal Kaziorb4aa5392015-03-31 10:26:24 +00003070 ath10k_mac_vif_handle_tx_pause(arvif, arg->pause_id, arg->action);
3071}
3072
Michal Kazioracd0b272015-07-09 13:08:38 +02003073void ath10k_mac_handle_tx_pause_vdev(struct ath10k *ar, u32 vdev_id,
3074 enum wmi_tlv_tx_pause_id pause_id,
3075 enum wmi_tlv_tx_pause_action action)
Michal Kaziorb4aa5392015-03-31 10:26:24 +00003076{
3077 struct ath10k_mac_tx_pause arg = {
3078 .vdev_id = vdev_id,
3079 .pause_id = pause_id,
3080 .action = action,
3081 };
3082
3083 spin_lock_bh(&ar->htt.tx_lock);
3084 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3085 IEEE80211_IFACE_ITER_RESUME_ALL,
3086 ath10k_mac_handle_tx_pause_iter,
3087 &arg);
3088 spin_unlock_bh(&ar->htt.tx_lock);
3089}
3090
Michal Kazior42c3aa62013-10-02 11:03:38 +02003091static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
3092{
3093 if (ieee80211_is_mgmt(hdr->frame_control))
3094 return HTT_DATA_TX_EXT_TID_MGMT;
3095
3096 if (!ieee80211_is_data_qos(hdr->frame_control))
3097 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
3098
3099 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
3100 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
3101
3102 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
3103}
3104
Michal Kazior2b37c292014-09-02 11:00:22 +03003105static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02003106{
Michal Kazior2b37c292014-09-02 11:00:22 +03003107 if (vif)
3108 return ath10k_vif_to_arvif(vif)->vdev_id;
Michal Kaziorddb6ad72013-10-02 11:03:39 +02003109
Michal Kazior1bbc0972014-04-08 09:45:47 +03003110 if (ar->monitor_started)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02003111 return ar->monitor_vdev_id;
3112
Michal Kazior7aa7a722014-08-25 12:09:38 +02003113 ath10k_warn(ar, "failed to resolve vdev id\n");
Michal Kaziorddb6ad72013-10-02 11:03:39 +02003114 return 0;
3115}
3116
Michal Kaziord740d8f2015-03-30 09:51:51 +03003117static enum ath10k_hw_txrx_mode
3118ath10k_tx_h_get_txmode(struct ath10k *ar, struct ieee80211_vif *vif,
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003119 struct ieee80211_sta *sta, struct sk_buff *skb)
Michal Kaziord740d8f2015-03-30 09:51:51 +03003120{
3121 const struct ieee80211_hdr *hdr = (void *)skb->data;
3122 __le16 fc = hdr->frame_control;
3123
3124 if (!vif || vif->type == NL80211_IFTYPE_MONITOR)
3125 return ATH10K_HW_TXRX_RAW;
3126
3127 if (ieee80211_is_mgmt(fc))
3128 return ATH10K_HW_TXRX_MGMT;
3129
3130 /* Workaround:
3131 *
3132 * NullFunc frames are mostly used to ping if a client or AP are still
3133 * reachable and responsive. This implies tx status reports must be
3134 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
3135 * come to a conclusion that the other end disappeared and tear down
3136 * BSS connection or it can never disconnect from BSS/client (which is
3137 * the case).
3138 *
3139 * Firmware with HTT older than 3.0 delivers incorrect tx status for
3140 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
3141 * which seems to deliver correct tx reports for NullFunc frames. The
3142 * downside of using it is it ignores client powersave state so it can
3143 * end up disconnecting sleeping clients in AP mode. It should fix STA
3144 * mode though because AP don't sleep.
3145 */
3146 if (ar->htt.target_version_major < 3 &&
3147 (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc)) &&
3148 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX, ar->fw_features))
3149 return ATH10K_HW_TXRX_MGMT;
3150
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003151 /* Workaround:
3152 *
3153 * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
3154 * NativeWifi txmode - it selects AP key instead of peer key. It seems
3155 * to work with Ethernet txmode so use it.
David Liuccec9032015-07-24 20:25:32 +03003156 *
3157 * FIXME: Check if raw mode works with TDLS.
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003158 */
3159 if (ieee80211_is_data_present(fc) && sta && sta->tdls)
3160 return ATH10K_HW_TXRX_ETHERNET;
3161
David Liuccec9032015-07-24 20:25:32 +03003162 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
3163 return ATH10K_HW_TXRX_RAW;
3164
Michal Kaziord740d8f2015-03-30 09:51:51 +03003165 return ATH10K_HW_TXRX_NATIVE_WIFI;
3166}
3167
David Liuccec9032015-07-24 20:25:32 +03003168static bool ath10k_tx_h_use_hwcrypto(struct ieee80211_vif *vif,
3169 struct sk_buff *skb) {
3170 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3171 const u32 mask = IEEE80211_TX_INTFL_DONT_ENCRYPT |
3172 IEEE80211_TX_CTL_INJECTED;
3173 if ((info->flags & mask) == mask)
3174 return false;
3175 if (vif)
3176 return !ath10k_vif_to_arvif(vif)->nohwcrypt;
3177 return true;
3178}
3179
Michal Kazior4b604552014-07-21 21:03:09 +03003180/* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
3181 * Control in the header.
Kalle Valo5e3dd152013-06-12 20:52:10 +03003182 */
Michal Kazior4b604552014-07-21 21:03:09 +03003183static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003184{
3185 struct ieee80211_hdr *hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03003186 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003187 u8 *qos_ctl;
3188
3189 if (!ieee80211_is_data_qos(hdr->frame_control))
3190 return;
3191
3192 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02003193 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
3194 skb->data, (void *)qos_ctl - (void *)skb->data);
3195 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Michal Kaziorc21c64d2014-07-21 21:03:10 +03003196
Michal Kazior8bad8dc2015-03-11 14:25:26 +01003197 /* Some firmware revisions don't handle sending QoS NullFunc well.
3198 * These frames are mainly used for CQM purposes so it doesn't really
3199 * matter whether QoS NullFunc or NullFunc are sent.
Michal Kaziorc21c64d2014-07-21 21:03:10 +03003200 */
Michal Kaziorbf0a26d2015-01-24 12:14:51 +02003201 hdr = (void *)skb->data;
Michal Kazior8bad8dc2015-03-11 14:25:26 +01003202 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
Michal Kaziorc21c64d2014-07-21 21:03:10 +03003203 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
Michal Kazior8bad8dc2015-03-11 14:25:26 +01003204
3205 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003206}
3207
Michal Kaziord740d8f2015-03-30 09:51:51 +03003208static void ath10k_tx_h_8023(struct sk_buff *skb)
3209{
3210 struct ieee80211_hdr *hdr;
3211 struct rfc1042_hdr *rfc1042;
3212 struct ethhdr *eth;
3213 size_t hdrlen;
3214 u8 da[ETH_ALEN];
3215 u8 sa[ETH_ALEN];
3216 __be16 type;
3217
3218 hdr = (void *)skb->data;
3219 hdrlen = ieee80211_hdrlen(hdr->frame_control);
3220 rfc1042 = (void *)skb->data + hdrlen;
3221
3222 ether_addr_copy(da, ieee80211_get_DA(hdr));
3223 ether_addr_copy(sa, ieee80211_get_SA(hdr));
3224 type = rfc1042->snap_type;
3225
3226 skb_pull(skb, hdrlen + sizeof(*rfc1042));
3227 skb_push(skb, sizeof(*eth));
3228
3229 eth = (void *)skb->data;
3230 ether_addr_copy(eth->h_dest, da);
3231 ether_addr_copy(eth->h_source, sa);
3232 eth->h_proto = type;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003233}
3234
Michal Kazior4b604552014-07-21 21:03:09 +03003235static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
3236 struct ieee80211_vif *vif,
3237 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003238{
3239 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003240 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3241
3242 /* This is case only for P2P_GO */
3243 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
3244 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
3245 return;
3246
3247 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
3248 spin_lock_bh(&ar->data_lock);
3249 if (arvif->u.ap.noa_data)
3250 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
3251 GFP_ATOMIC))
3252 memcpy(skb_put(skb, arvif->u.ap.noa_len),
3253 arvif->u.ap.noa_data,
3254 arvif->u.ap.noa_len);
3255 spin_unlock_bh(&ar->data_lock);
3256 }
3257}
3258
Michal Kazior8d6d3622014-11-24 14:58:31 +01003259static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar)
3260{
3261 /* FIXME: Not really sure since when the behaviour changed. At some
3262 * point new firmware stopped requiring creation of peer entries for
3263 * offchannel tx (and actually creating them causes issues with wmi-htc
3264 * tx credit replenishment and reliability). Assuming it's at least 3.4
3265 * because that's when the `freq` was introduced to TX_FRM HTT command.
3266 */
3267 return !(ar->htt.target_version_major >= 3 &&
3268 ar->htt.target_version_minor >= 4);
3269}
3270
Michal Kaziord740d8f2015-03-30 09:51:51 +03003271static int ath10k_mac_tx_wmi_mgmt(struct ath10k *ar, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003272{
Michal Kaziord740d8f2015-03-30 09:51:51 +03003273 struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003274 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003275
Michal Kaziord740d8f2015-03-30 09:51:51 +03003276 spin_lock_bh(&ar->data_lock);
3277
3278 if (skb_queue_len(q) == ATH10K_MAX_NUM_MGMT_PENDING) {
3279 ath10k_warn(ar, "wmi mgmt tx queue is full\n");
3280 ret = -ENOSPC;
3281 goto unlock;
Michal Kazior961d4c32013-08-09 10:13:34 +02003282 }
3283
Michal Kaziord740d8f2015-03-30 09:51:51 +03003284 __skb_queue_tail(q, skb);
3285 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
3286
3287unlock:
3288 spin_unlock_bh(&ar->data_lock);
3289
3290 return ret;
3291}
3292
3293static void ath10k_mac_tx(struct ath10k *ar, struct sk_buff *skb)
3294{
3295 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3296 struct ath10k_htt *htt = &ar->htt;
3297 int ret = 0;
3298
3299 switch (cb->txmode) {
3300 case ATH10K_HW_TXRX_RAW:
3301 case ATH10K_HW_TXRX_NATIVE_WIFI:
3302 case ATH10K_HW_TXRX_ETHERNET:
3303 ret = ath10k_htt_tx(htt, skb);
3304 break;
3305 case ATH10K_HW_TXRX_MGMT:
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003306 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
Michal Kaziord740d8f2015-03-30 09:51:51 +03003307 ar->fw_features))
3308 ret = ath10k_mac_tx_wmi_mgmt(ar, skb);
3309 else if (ar->htt.target_version_major >= 3)
3310 ret = ath10k_htt_tx(htt, skb);
3311 else
3312 ret = ath10k_htt_mgmt_tx(htt, skb);
3313 break;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003314 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003315
3316 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003317 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
3318 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003319 ieee80211_free_txskb(ar->hw, skb);
3320 }
3321}
3322
3323void ath10k_offchan_tx_purge(struct ath10k *ar)
3324{
3325 struct sk_buff *skb;
3326
3327 for (;;) {
3328 skb = skb_dequeue(&ar->offchan_tx_queue);
3329 if (!skb)
3330 break;
3331
3332 ieee80211_free_txskb(ar->hw, skb);
3333 }
3334}
3335
3336void ath10k_offchan_tx_work(struct work_struct *work)
3337{
3338 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
3339 struct ath10k_peer *peer;
3340 struct ieee80211_hdr *hdr;
3341 struct sk_buff *skb;
3342 const u8 *peer_addr;
3343 int vdev_id;
3344 int ret;
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +03003345 unsigned long time_left;
Michal Kazioradaeed72015-08-05 12:15:23 +02003346 bool tmp_peer_created = false;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003347
3348 /* FW requirement: We must create a peer before FW will send out
3349 * an offchannel frame. Otherwise the frame will be stuck and
3350 * never transmitted. We delete the peer upon tx completion.
3351 * It is unlikely that a peer for offchannel tx will already be
3352 * present. However it may be in some rare cases so account for that.
3353 * Otherwise we might remove a legitimate peer and break stuff. */
3354
3355 for (;;) {
3356 skb = skb_dequeue(&ar->offchan_tx_queue);
3357 if (!skb)
3358 break;
3359
3360 mutex_lock(&ar->conf_mutex);
3361
Michal Kazior7aa7a722014-08-25 12:09:38 +02003362 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003363 skb);
3364
3365 hdr = (struct ieee80211_hdr *)skb->data;
3366 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003367 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003368
3369 spin_lock_bh(&ar->data_lock);
3370 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
3371 spin_unlock_bh(&ar->data_lock);
3372
3373 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03003374 /* FIXME: should this use ath10k_warn()? */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003375 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003376 peer_addr, vdev_id);
3377
3378 if (!peer) {
Marek Puzyniak7390ed32015-03-30 09:51:52 +03003379 ret = ath10k_peer_create(ar, vdev_id, peer_addr,
3380 WMI_PEER_TYPE_DEFAULT);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003381 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003382 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003383 peer_addr, vdev_id, ret);
Michal Kazioradaeed72015-08-05 12:15:23 +02003384 tmp_peer_created = (ret == 0);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003385 }
3386
3387 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08003388 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003389 ar->offchan_tx_skb = skb;
3390 spin_unlock_bh(&ar->data_lock);
3391
Michal Kaziord740d8f2015-03-30 09:51:51 +03003392 ath10k_mac_tx(ar, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003393
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +03003394 time_left =
3395 wait_for_completion_timeout(&ar->offchan_tx_completed, 3 * HZ);
3396 if (time_left == 0)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003397 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003398 skb);
3399
Michal Kazioradaeed72015-08-05 12:15:23 +02003400 if (!peer && tmp_peer_created) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003401 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
3402 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003403 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003404 peer_addr, vdev_id, ret);
3405 }
3406
3407 mutex_unlock(&ar->conf_mutex);
3408 }
3409}
3410
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003411void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
3412{
3413 struct sk_buff *skb;
3414
3415 for (;;) {
3416 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3417 if (!skb)
3418 break;
3419
3420 ieee80211_free_txskb(ar->hw, skb);
3421 }
3422}
3423
3424void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
3425{
3426 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
3427 struct sk_buff *skb;
3428 int ret;
3429
3430 for (;;) {
3431 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3432 if (!skb)
3433 break;
3434
3435 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01003436 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003437 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02003438 ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01003439 ieee80211_free_txskb(ar->hw, skb);
3440 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003441 }
3442}
3443
Kalle Valo5e3dd152013-06-12 20:52:10 +03003444/************/
3445/* Scanning */
3446/************/
3447
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003448void __ath10k_scan_finish(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003449{
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003450 lockdep_assert_held(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003451
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003452 switch (ar->scan.state) {
3453 case ATH10K_SCAN_IDLE:
3454 break;
3455 case ATH10K_SCAN_RUNNING:
Michal Kazior7305d3e2014-11-24 14:58:33 +01003456 case ATH10K_SCAN_ABORTING:
3457 if (!ar->scan.is_roc)
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003458 ieee80211_scan_completed(ar->hw,
3459 (ar->scan.state ==
3460 ATH10K_SCAN_ABORTING));
Michal Kaziord710e752015-07-09 13:08:36 +02003461 else if (ar->scan.roc_notify)
3462 ieee80211_remain_on_channel_expired(ar->hw);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003463 /* fall through */
3464 case ATH10K_SCAN_STARTING:
3465 ar->scan.state = ATH10K_SCAN_IDLE;
3466 ar->scan_channel = NULL;
3467 ath10k_offchan_tx_purge(ar);
3468 cancel_delayed_work(&ar->scan.timeout);
3469 complete_all(&ar->scan.completed);
3470 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003471 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003472}
Kalle Valo5e3dd152013-06-12 20:52:10 +03003473
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003474void ath10k_scan_finish(struct ath10k *ar)
3475{
3476 spin_lock_bh(&ar->data_lock);
3477 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003478 spin_unlock_bh(&ar->data_lock);
3479}
3480
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003481static int ath10k_scan_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003482{
3483 struct wmi_stop_scan_arg arg = {
3484 .req_id = 1, /* FIXME */
3485 .req_type = WMI_SCAN_STOP_ONE,
3486 .u.scan_id = ATH10K_SCAN_ID,
3487 };
3488 int ret;
3489
3490 lockdep_assert_held(&ar->conf_mutex);
3491
Kalle Valo5e3dd152013-06-12 20:52:10 +03003492 ret = ath10k_wmi_stop_scan(ar, &arg);
3493 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003494 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003495 goto out;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003496 }
3497
Kalle Valo5e3dd152013-06-12 20:52:10 +03003498 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003499 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003500 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003501 ret = -ETIMEDOUT;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003502 } else if (ret > 0) {
3503 ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003504 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003505
3506out:
3507 /* Scan state should be updated upon scan completion but in case
3508 * firmware fails to deliver the event (for whatever reason) it is
3509 * desired to clean up scan state anyway. Firmware may have just
3510 * dropped the scan completion event delivery due to transport pipe
3511 * being overflown with data and/or it can recover on its own before
3512 * next scan request is submitted.
3513 */
3514 spin_lock_bh(&ar->data_lock);
3515 if (ar->scan.state != ATH10K_SCAN_IDLE)
3516 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003517 spin_unlock_bh(&ar->data_lock);
3518
3519 return ret;
3520}
3521
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003522static void ath10k_scan_abort(struct ath10k *ar)
3523{
3524 int ret;
3525
3526 lockdep_assert_held(&ar->conf_mutex);
3527
3528 spin_lock_bh(&ar->data_lock);
3529
3530 switch (ar->scan.state) {
3531 case ATH10K_SCAN_IDLE:
3532 /* This can happen if timeout worker kicked in and called
3533 * abortion while scan completion was being processed.
3534 */
3535 break;
3536 case ATH10K_SCAN_STARTING:
3537 case ATH10K_SCAN_ABORTING:
Michal Kazior7aa7a722014-08-25 12:09:38 +02003538 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003539 ath10k_scan_state_str(ar->scan.state),
3540 ar->scan.state);
3541 break;
3542 case ATH10K_SCAN_RUNNING:
3543 ar->scan.state = ATH10K_SCAN_ABORTING;
3544 spin_unlock_bh(&ar->data_lock);
3545
3546 ret = ath10k_scan_stop(ar);
3547 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003548 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003549
3550 spin_lock_bh(&ar->data_lock);
3551 break;
3552 }
3553
3554 spin_unlock_bh(&ar->data_lock);
3555}
3556
3557void ath10k_scan_timeout_work(struct work_struct *work)
3558{
3559 struct ath10k *ar = container_of(work, struct ath10k,
3560 scan.timeout.work);
3561
3562 mutex_lock(&ar->conf_mutex);
3563 ath10k_scan_abort(ar);
3564 mutex_unlock(&ar->conf_mutex);
3565}
3566
Kalle Valo5e3dd152013-06-12 20:52:10 +03003567static int ath10k_start_scan(struct ath10k *ar,
3568 const struct wmi_start_scan_arg *arg)
3569{
3570 int ret;
3571
3572 lockdep_assert_held(&ar->conf_mutex);
3573
3574 ret = ath10k_wmi_start_scan(ar, arg);
3575 if (ret)
3576 return ret;
3577
Kalle Valo5e3dd152013-06-12 20:52:10 +03003578 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
3579 if (ret == 0) {
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003580 ret = ath10k_scan_stop(ar);
3581 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003582 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003583
3584 return -ETIMEDOUT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003585 }
3586
Ben Greear2f9eec02015-02-15 16:50:38 +02003587 /* If we failed to start the scan, return error code at
3588 * this point. This is probably due to some issue in the
3589 * firmware, but no need to wedge the driver due to that...
3590 */
3591 spin_lock_bh(&ar->data_lock);
3592 if (ar->scan.state == ATH10K_SCAN_IDLE) {
3593 spin_unlock_bh(&ar->data_lock);
3594 return -EINVAL;
3595 }
3596 spin_unlock_bh(&ar->data_lock);
3597
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003598 /* Add a 200ms margin to account for event/command processing */
3599 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
3600 msecs_to_jiffies(arg->max_scan_time+200));
Kalle Valo5e3dd152013-06-12 20:52:10 +03003601 return 0;
3602}
3603
3604/**********************/
3605/* mac80211 callbacks */
3606/**********************/
3607
3608static void ath10k_tx(struct ieee80211_hw *hw,
3609 struct ieee80211_tx_control *control,
3610 struct sk_buff *skb)
3611{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003612 struct ath10k *ar = hw->priv;
Michal Kazior4b604552014-07-21 21:03:09 +03003613 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3614 struct ieee80211_vif *vif = info->control.vif;
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003615 struct ieee80211_sta *sta = control->sta;
Michal Kazior4b604552014-07-21 21:03:09 +03003616 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Michal Kaziord740d8f2015-03-30 09:51:51 +03003617 __le16 fc = hdr->frame_control;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003618
3619 /* We should disable CCK RATE due to P2P */
3620 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003621 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003622
Michal Kazior4b604552014-07-21 21:03:09 +03003623 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
Michal Kazior6fcafef2015-03-30 09:51:51 +03003624 ATH10K_SKB_CB(skb)->htt.freq = 0;
Michal Kazior4b604552014-07-21 21:03:09 +03003625 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
David Liuccec9032015-07-24 20:25:32 +03003626 ATH10K_SKB_CB(skb)->htt.nohwcrypt = !ath10k_tx_h_use_hwcrypto(vif, skb);
Michal Kazior2b37c292014-09-02 11:00:22 +03003627 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003628 ATH10K_SKB_CB(skb)->txmode = ath10k_tx_h_get_txmode(ar, vif, sta, skb);
Michal Kaziord740d8f2015-03-30 09:51:51 +03003629 ATH10K_SKB_CB(skb)->is_protected = ieee80211_has_protected(fc);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003630
Michal Kaziord740d8f2015-03-30 09:51:51 +03003631 switch (ATH10K_SKB_CB(skb)->txmode) {
3632 case ATH10K_HW_TXRX_MGMT:
3633 case ATH10K_HW_TXRX_NATIVE_WIFI:
Michal Kazior4b604552014-07-21 21:03:09 +03003634 ath10k_tx_h_nwifi(hw, skb);
Michal Kazior4b604552014-07-21 21:03:09 +03003635 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
3636 ath10k_tx_h_seq_no(vif, skb);
Michal Kaziord740d8f2015-03-30 09:51:51 +03003637 break;
3638 case ATH10K_HW_TXRX_ETHERNET:
3639 ath10k_tx_h_8023(skb);
3640 break;
3641 case ATH10K_HW_TXRX_RAW:
David Liuccec9032015-07-24 20:25:32 +03003642 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
3643 WARN_ON_ONCE(1);
3644 ieee80211_free_txskb(hw, skb);
3645 return;
3646 }
Michal Kaziorcf84bd42013-07-16 11:04:54 +02003647 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003648
Kalle Valo5e3dd152013-06-12 20:52:10 +03003649 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
3650 spin_lock_bh(&ar->data_lock);
Michal Kazior8d6d3622014-11-24 14:58:31 +01003651 ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003652 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003653 spin_unlock_bh(&ar->data_lock);
3654
Michal Kazior8d6d3622014-11-24 14:58:31 +01003655 if (ath10k_mac_need_offchan_tx_work(ar)) {
3656 ATH10K_SKB_CB(skb)->htt.freq = 0;
3657 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003658
Michal Kazior8d6d3622014-11-24 14:58:31 +01003659 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
3660 skb);
3661
3662 skb_queue_tail(&ar->offchan_tx_queue, skb);
3663 ieee80211_queue_work(hw, &ar->offchan_tx_work);
3664 return;
3665 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003666 }
3667
Michal Kaziord740d8f2015-03-30 09:51:51 +03003668 ath10k_mac_tx(ar, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003669}
3670
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003671/* Must not be called with conf_mutex held as workers can use that also. */
Michal Kazior7962b0d2014-10-28 10:34:38 +01003672void ath10k_drain_tx(struct ath10k *ar)
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003673{
3674 /* make sure rcu-protected mac80211 tx path itself is drained */
3675 synchronize_net();
3676
3677 ath10k_offchan_tx_purge(ar);
3678 ath10k_mgmt_over_wmi_tx_purge(ar);
3679
3680 cancel_work_sync(&ar->offchan_tx_work);
3681 cancel_work_sync(&ar->wmi_mgmt_tx_work);
3682}
3683
Michal Kazioraffd3212013-07-16 09:54:35 +02003684void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02003685{
Michal Kaziord9bc4b92014-04-23 19:30:06 +03003686 struct ath10k_vif *arvif;
3687
Michal Kazior818bdd12013-07-16 09:38:57 +02003688 lockdep_assert_held(&ar->conf_mutex);
3689
Michal Kazior19337472014-08-28 12:58:16 +02003690 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
3691 ar->filter_flags = 0;
3692 ar->monitor = false;
Michal Kazior500ff9f2015-03-31 10:26:21 +00003693 ar->monitor_arvif = NULL;
Michal Kazior19337472014-08-28 12:58:16 +02003694
3695 if (ar->monitor_started)
Michal Kazior1bbc0972014-04-08 09:45:47 +03003696 ath10k_monitor_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +02003697
3698 ar->monitor_started = false;
Michal Kazior96d828d2015-03-31 10:26:23 +00003699 ar->tx_paused = 0;
Michal Kazior1bbc0972014-04-08 09:45:47 +03003700
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003701 ath10k_scan_finish(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02003702 ath10k_peer_cleanup_all(ar);
3703 ath10k_core_stop(ar);
3704 ath10k_hif_power_down(ar);
3705
3706 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03003707 list_for_each_entry(arvif, &ar->arvifs, list)
3708 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kazior818bdd12013-07-16 09:38:57 +02003709 spin_unlock_bh(&ar->data_lock);
3710}
3711
Ben Greear46acf7b2014-05-16 17:15:38 +03003712static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
3713{
3714 struct ath10k *ar = hw->priv;
3715
3716 mutex_lock(&ar->conf_mutex);
3717
3718 if (ar->cfg_tx_chainmask) {
3719 *tx_ant = ar->cfg_tx_chainmask;
3720 *rx_ant = ar->cfg_rx_chainmask;
3721 } else {
3722 *tx_ant = ar->supp_tx_chainmask;
3723 *rx_ant = ar->supp_rx_chainmask;
3724 }
3725
3726 mutex_unlock(&ar->conf_mutex);
3727
3728 return 0;
3729}
3730
Ben Greear5572a952014-11-24 16:22:10 +02003731static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
3732{
3733 /* It is not clear that allowing gaps in chainmask
3734 * is helpful. Probably it will not do what user
3735 * is hoping for, so warn in that case.
3736 */
3737 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
3738 return;
3739
3740 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
3741 dbg, cm);
3742}
3743
Ben Greear46acf7b2014-05-16 17:15:38 +03003744static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
3745{
3746 int ret;
3747
3748 lockdep_assert_held(&ar->conf_mutex);
3749
Ben Greear5572a952014-11-24 16:22:10 +02003750 ath10k_check_chain_mask(ar, tx_ant, "tx");
3751 ath10k_check_chain_mask(ar, rx_ant, "rx");
3752
Ben Greear46acf7b2014-05-16 17:15:38 +03003753 ar->cfg_tx_chainmask = tx_ant;
3754 ar->cfg_rx_chainmask = rx_ant;
3755
3756 if ((ar->state != ATH10K_STATE_ON) &&
3757 (ar->state != ATH10K_STATE_RESTARTED))
3758 return 0;
3759
3760 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
3761 tx_ant);
3762 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003763 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03003764 ret, tx_ant);
3765 return ret;
3766 }
3767
3768 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
3769 rx_ant);
3770 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003771 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03003772 ret, rx_ant);
3773 return ret;
3774 }
3775
3776 return 0;
3777}
3778
3779static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
3780{
3781 struct ath10k *ar = hw->priv;
3782 int ret;
3783
3784 mutex_lock(&ar->conf_mutex);
3785 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
3786 mutex_unlock(&ar->conf_mutex);
3787 return ret;
3788}
3789
Kalle Valo5e3dd152013-06-12 20:52:10 +03003790static int ath10k_start(struct ieee80211_hw *hw)
3791{
3792 struct ath10k *ar = hw->priv;
Janusz Dziedzic24ab13e2015-04-01 22:53:18 +03003793 u32 burst_enable;
Michal Kazior818bdd12013-07-16 09:38:57 +02003794 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003795
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003796 /*
3797 * This makes sense only when restarting hw. It is harmless to call
3798 * uncoditionally. This is necessary to make sure no HTT/WMI tx
3799 * commands will be submitted while restarting.
3800 */
3801 ath10k_drain_tx(ar);
3802
Michal Kazior548db542013-07-05 16:15:15 +03003803 mutex_lock(&ar->conf_mutex);
3804
Michal Kaziorc5058f52014-05-26 12:46:03 +03003805 switch (ar->state) {
3806 case ATH10K_STATE_OFF:
3807 ar->state = ATH10K_STATE_ON;
3808 break;
3809 case ATH10K_STATE_RESTARTING:
3810 ath10k_halt(ar);
3811 ar->state = ATH10K_STATE_RESTARTED;
3812 break;
3813 case ATH10K_STATE_ON:
3814 case ATH10K_STATE_RESTARTED:
3815 case ATH10K_STATE_WEDGED:
3816 WARN_ON(1);
Michal Kazior818bdd12013-07-16 09:38:57 +02003817 ret = -EINVAL;
Michal Kaziorae254432014-05-26 12:46:02 +03003818 goto err;
Kalle Valo43d2a302014-09-10 18:23:30 +03003819 case ATH10K_STATE_UTF:
3820 ret = -EBUSY;
3821 goto err;
Michal Kazior818bdd12013-07-16 09:38:57 +02003822 }
3823
3824 ret = ath10k_hif_power_up(ar);
3825 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003826 ath10k_err(ar, "Could not init hif: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003827 goto err_off;
Michal Kazior818bdd12013-07-16 09:38:57 +02003828 }
3829
Kalle Valo43d2a302014-09-10 18:23:30 +03003830 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
Michal Kazior818bdd12013-07-16 09:38:57 +02003831 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003832 ath10k_err(ar, "Could not init core: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003833 goto err_power_down;
Michal Kazior818bdd12013-07-16 09:38:57 +02003834 }
3835
Bartosz Markowski226a3392013-09-26 17:47:16 +02003836 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03003837 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003838 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003839 goto err_core_stop;
3840 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003841
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01003842 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03003843 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003844 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003845 goto err_core_stop;
3846 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003847
Michal Kaziorcf327842015-03-31 10:26:25 +00003848 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
3849 ret = ath10k_wmi_adaptive_qcs(ar, true);
3850 if (ret) {
3851 ath10k_warn(ar, "failed to enable adaptive qcs: %d\n",
3852 ret);
3853 goto err_core_stop;
3854 }
3855 }
3856
Janusz Dziedzic24ab13e2015-04-01 22:53:18 +03003857 if (test_bit(WMI_SERVICE_BURST, ar->wmi.svc_map)) {
3858 burst_enable = ar->wmi.pdev_param->burst_enable;
3859 ret = ath10k_wmi_pdev_set_param(ar, burst_enable, 0);
3860 if (ret) {
3861 ath10k_warn(ar, "failed to disable burst: %d\n", ret);
3862 goto err_core_stop;
3863 }
3864 }
3865
Ben Greear46acf7b2014-05-16 17:15:38 +03003866 if (ar->cfg_tx_chainmask)
3867 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
3868 ar->cfg_rx_chainmask);
3869
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003870 /*
3871 * By default FW set ARP frames ac to voice (6). In that case ARP
3872 * exchange is not working properly for UAPSD enabled AP. ARP requests
3873 * which arrives with access category 0 are processed by network stack
3874 * and send back with access category 0, but FW changes access category
3875 * to 6. Set ARP frames access category to best effort (0) solves
3876 * this problem.
3877 */
3878
3879 ret = ath10k_wmi_pdev_set_param(ar,
3880 ar->wmi.pdev_param->arp_ac_override, 0);
3881 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003882 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003883 ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003884 goto err_core_stop;
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003885 }
3886
Ashok Raj Nagarajan575f1c32015-03-19 16:37:59 +05303887 ret = ath10k_wmi_pdev_set_param(ar,
3888 ar->wmi.pdev_param->ani_enable, 1);
3889 if (ret) {
3890 ath10k_warn(ar, "failed to enable ani by default: %d\n",
3891 ret);
3892 goto err_core_stop;
3893 }
3894
Ashok Raj Nagarajanb3e71d72015-03-19 16:38:00 +05303895 ar->ani_enabled = true;
3896
Michal Kaziord6500972014-04-08 09:56:09 +03003897 ar->num_started_vdevs = 0;
Michal Kaziorf7843d72013-07-16 09:38:52 +02003898 ath10k_regd_update(ar);
3899
Simon Wunderlich855aed12014-08-02 09:12:54 +03003900 ath10k_spectral_start(ar);
Rajkumar Manoharan8515b5c2015-03-15 20:36:22 +05303901 ath10k_thermal_set_throttling(ar);
Simon Wunderlich855aed12014-08-02 09:12:54 +03003902
Michal Kaziorae254432014-05-26 12:46:02 +03003903 mutex_unlock(&ar->conf_mutex);
3904 return 0;
3905
3906err_core_stop:
3907 ath10k_core_stop(ar);
3908
3909err_power_down:
3910 ath10k_hif_power_down(ar);
3911
3912err_off:
3913 ar->state = ATH10K_STATE_OFF;
3914
3915err:
Michal Kazior548db542013-07-05 16:15:15 +03003916 mutex_unlock(&ar->conf_mutex);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01003917 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003918}
3919
3920static void ath10k_stop(struct ieee80211_hw *hw)
3921{
3922 struct ath10k *ar = hw->priv;
3923
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003924 ath10k_drain_tx(ar);
3925
Michal Kazior548db542013-07-05 16:15:15 +03003926 mutex_lock(&ar->conf_mutex);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003927 if (ar->state != ATH10K_STATE_OFF) {
Michal Kazior818bdd12013-07-16 09:38:57 +02003928 ath10k_halt(ar);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003929 ar->state = ATH10K_STATE_OFF;
3930 }
Michal Kazior548db542013-07-05 16:15:15 +03003931 mutex_unlock(&ar->conf_mutex);
3932
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003933 cancel_delayed_work_sync(&ar->scan.timeout);
Michal Kazioraffd3212013-07-16 09:54:35 +02003934 cancel_work_sync(&ar->restart_work);
3935}
3936
Michal Kaziorad088bf2013-10-16 15:44:46 +03003937static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02003938{
Michal Kaziorad088bf2013-10-16 15:44:46 +03003939 struct ath10k_vif *arvif;
3940 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02003941
3942 lockdep_assert_held(&ar->conf_mutex);
3943
Michal Kaziorad088bf2013-10-16 15:44:46 +03003944 list_for_each_entry(arvif, &ar->arvifs, list) {
3945 ret = ath10k_mac_vif_setup_ps(arvif);
3946 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003947 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03003948 break;
3949 }
3950 }
Michal Kazioraffd3212013-07-16 09:54:35 +02003951
Michal Kaziorad088bf2013-10-16 15:44:46 +03003952 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003953}
3954
Michal Kazior7d9d5582014-10-21 10:40:15 +03003955static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
3956{
3957 int ret;
3958 u32 param;
3959
3960 lockdep_assert_held(&ar->conf_mutex);
3961
3962 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
3963
3964 param = ar->wmi.pdev_param->txpower_limit2g;
3965 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3966 if (ret) {
3967 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
3968 txpower, ret);
3969 return ret;
3970 }
3971
3972 param = ar->wmi.pdev_param->txpower_limit5g;
3973 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3974 if (ret) {
3975 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
3976 txpower, ret);
3977 return ret;
3978 }
3979
3980 return 0;
3981}
3982
3983static int ath10k_mac_txpower_recalc(struct ath10k *ar)
3984{
3985 struct ath10k_vif *arvif;
3986 int ret, txpower = -1;
3987
3988 lockdep_assert_held(&ar->conf_mutex);
3989
3990 list_for_each_entry(arvif, &ar->arvifs, list) {
3991 WARN_ON(arvif->txpower < 0);
3992
3993 if (txpower == -1)
3994 txpower = arvif->txpower;
3995 else
3996 txpower = min(txpower, arvif->txpower);
3997 }
3998
3999 if (WARN_ON(txpower == -1))
4000 return -EINVAL;
4001
4002 ret = ath10k_mac_txpower_setup(ar, txpower);
4003 if (ret) {
4004 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
4005 txpower, ret);
4006 return ret;
4007 }
4008
4009 return 0;
4010}
4011
Kalle Valo5e3dd152013-06-12 20:52:10 +03004012static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
4013{
Kalle Valo5e3dd152013-06-12 20:52:10 +03004014 struct ath10k *ar = hw->priv;
4015 struct ieee80211_conf *conf = &hw->conf;
4016 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004017
4018 mutex_lock(&ar->conf_mutex);
4019
Michal Kazioraffd3212013-07-16 09:54:35 +02004020 if (changed & IEEE80211_CONF_CHANGE_PS)
4021 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004022
4023 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
Michal Kazior19337472014-08-28 12:58:16 +02004024 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
4025 ret = ath10k_monitor_recalc(ar);
4026 if (ret)
4027 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004028 }
4029
4030 mutex_unlock(&ar->conf_mutex);
4031 return ret;
4032}
4033
Ben Greear5572a952014-11-24 16:22:10 +02004034static u32 get_nss_from_chainmask(u16 chain_mask)
4035{
4036 if ((chain_mask & 0x15) == 0x15)
4037 return 4;
4038 else if ((chain_mask & 0x7) == 0x7)
4039 return 3;
4040 else if ((chain_mask & 0x3) == 0x3)
4041 return 2;
4042 return 1;
4043}
4044
Vivek Natarajana48e2cc2015-08-04 10:45:12 +05304045static int ath10k_mac_set_txbf_conf(struct ath10k_vif *arvif)
4046{
4047 u32 value = 0;
4048 struct ath10k *ar = arvif->ar;
4049
4050 if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_BEFORE_ASSOC)
4051 return 0;
4052
4053 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
4054 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE))
4055 value |= SM((ar->num_rf_chains - 1), WMI_TXBF_STS_CAP_OFFSET);
4056
4057 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
4058 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE))
4059 value |= SM((ar->num_rf_chains - 1), WMI_BF_SOUND_DIM_OFFSET);
4060
4061 if (!value)
4062 return 0;
4063
4064 if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
4065 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
4066
4067 if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
4068 value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFER |
4069 WMI_VDEV_PARAM_TXBF_SU_TX_BFER);
4070
4071 if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
4072 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
4073
4074 if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
4075 value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFEE |
4076 WMI_VDEV_PARAM_TXBF_SU_TX_BFEE);
4077
4078 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4079 ar->wmi.vdev_param->txbf, value);
4080}
4081
Kalle Valo5e3dd152013-06-12 20:52:10 +03004082/*
4083 * TODO:
4084 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
4085 * because we will send mgmt frames without CCK. This requirement
4086 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
4087 * in the TX packet.
4088 */
4089static int ath10k_add_interface(struct ieee80211_hw *hw,
4090 struct ieee80211_vif *vif)
4091{
4092 struct ath10k *ar = hw->priv;
4093 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4094 enum wmi_sta_powersave_param param;
4095 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02004096 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004097 int bit;
Michal Kazior96d828d2015-03-31 10:26:23 +00004098 int i;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004099 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004100
Johannes Berg848955c2014-11-11 12:48:42 +01004101 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
4102
Kalle Valo5e3dd152013-06-12 20:52:10 +03004103 mutex_lock(&ar->conf_mutex);
4104
Michal Kazior0dbd09e2013-07-31 10:55:14 +02004105 memset(arvif, 0, sizeof(*arvif));
4106
Kalle Valo5e3dd152013-06-12 20:52:10 +03004107 arvif->ar = ar;
4108 arvif->vif = vif;
4109
Ben Greeare63b33f2013-10-22 14:54:14 -07004110 INIT_LIST_HEAD(&arvif->list);
Michal Kazior81a9a172015-03-05 16:02:17 +02004111 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
Michal Kaziorcc9904e2015-03-10 16:22:01 +02004112 INIT_DELAYED_WORK(&arvif->connection_loss_work,
4113 ath10k_mac_vif_sta_connection_loss_work);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03004114
Michal Kazior45c9abc2015-04-21 20:42:58 +03004115 for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) {
4116 arvif->bitrate_mask.control[i].legacy = 0xffffffff;
4117 memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff,
4118 sizeof(arvif->bitrate_mask.control[i].ht_mcs));
4119 memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff,
4120 sizeof(arvif->bitrate_mask.control[i].vht_mcs));
4121 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004122
Michal Kaziore04cafb2015-08-05 12:15:24 +02004123 if (ar->num_peers >= ar->max_num_peers) {
4124 ath10k_warn(ar, "refusing vdev creation due to insufficient peer entry resources in firmware\n");
4125 return -ENOBUFS;
4126 }
4127
Ben Greeara9aefb32014-08-12 11:02:19 +03004128 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004129 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03004130 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03004131 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004132 }
Ben Greear16c11172014-09-23 14:17:16 -07004133 bit = __ffs64(ar->free_vdev_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004134
Ben Greear16c11172014-09-23 14:17:16 -07004135 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
4136 bit, ar->free_vdev_map);
4137
4138 arvif->vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004139 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004140
Kalle Valo5e3dd152013-06-12 20:52:10 +03004141 switch (vif->type) {
Michal Kazior75d2bd42014-12-12 12:41:39 +01004142 case NL80211_IFTYPE_P2P_DEVICE:
4143 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4144 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
4145 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004146 case NL80211_IFTYPE_UNSPECIFIED:
4147 case NL80211_IFTYPE_STATION:
4148 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4149 if (vif->p2p)
4150 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
4151 break;
4152 case NL80211_IFTYPE_ADHOC:
4153 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
4154 break;
4155 case NL80211_IFTYPE_AP:
4156 arvif->vdev_type = WMI_VDEV_TYPE_AP;
4157
4158 if (vif->p2p)
4159 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
4160 break;
4161 case NL80211_IFTYPE_MONITOR:
4162 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
4163 break;
4164 default:
4165 WARN_ON(1);
4166 break;
4167 }
4168
Michal Kazior96d828d2015-03-31 10:26:23 +00004169 /* Using vdev_id as queue number will make it very easy to do per-vif
4170 * tx queue locking. This shouldn't wrap due to interface combinations
4171 * but do a modulo for correctness sake and prevent using offchannel tx
4172 * queues for regular vif tx.
4173 */
4174 vif->cab_queue = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
4175 for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++)
4176 vif->hw_queue[i] = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
4177
Michal Kazior64badcb2014-09-18 11:18:02 +03004178 /* Some firmware revisions don't wait for beacon tx completion before
4179 * sending another SWBA event. This could lead to hardware using old
4180 * (freed) beacon data in some cases, e.g. tx credit starvation
4181 * combined with missed TBTT. This is very very rare.
4182 *
4183 * On non-IOMMU-enabled hosts this could be a possible security issue
4184 * because hw could beacon some random data on the air. On
4185 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
4186 * device would crash.
4187 *
4188 * Since there are no beacon tx completions (implicit nor explicit)
4189 * propagated to host the only workaround for this is to allocate a
4190 * DMA-coherent buffer for a lifetime of a vif and use it for all
4191 * beacon tx commands. Worst case for this approach is some beacons may
4192 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
4193 */
4194 if (vif->type == NL80211_IFTYPE_ADHOC ||
4195 vif->type == NL80211_IFTYPE_AP) {
4196 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
4197 IEEE80211_MAX_FRAME_LEN,
4198 &arvif->beacon_paddr,
Rajkumar Manoharan82d7aba2014-10-10 17:38:27 +05304199 GFP_ATOMIC);
Michal Kazior64badcb2014-09-18 11:18:02 +03004200 if (!arvif->beacon_buf) {
4201 ret = -ENOMEM;
4202 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
4203 ret);
4204 goto err;
4205 }
4206 }
David Liuccec9032015-07-24 20:25:32 +03004207 if (test_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags))
4208 arvif->nohwcrypt = true;
4209
4210 if (arvif->nohwcrypt &&
4211 !test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
4212 ath10k_warn(ar, "cryptmode module param needed for sw crypto\n");
4213 goto err;
4214 }
Michal Kazior64badcb2014-09-18 11:18:02 +03004215
4216 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
4217 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
4218 arvif->beacon_buf ? "single-buf" : "per-skb");
Kalle Valo5e3dd152013-06-12 20:52:10 +03004219
4220 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
4221 arvif->vdev_subtype, vif->addr);
4222 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004223 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004224 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004225 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004226 }
4227
Ben Greear16c11172014-09-23 14:17:16 -07004228 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03004229 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004230
Michal Kazior46725b152015-01-28 09:57:49 +02004231 /* It makes no sense to have firmware do keepalives. mac80211 already
4232 * takes care of this with idle connection polling.
4233 */
4234 ret = ath10k_mac_vif_disable_keepalive(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004235 if (ret) {
Michal Kazior46725b152015-01-28 09:57:49 +02004236 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004237 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004238 goto err_vdev_delete;
4239 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004240
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004241 arvif->def_wep_key_idx = -1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004242
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004243 vdev_param = ar->wmi.vdev_param->tx_encap_type;
4244 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004245 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02004246 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14a2013-10-16 15:44:45 +03004247 if (ret && ret != -EOPNOTSUPP) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004248 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004249 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004250 goto err_vdev_delete;
4251 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004252
Ben Greear5572a952014-11-24 16:22:10 +02004253 if (ar->cfg_tx_chainmask) {
4254 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
4255
4256 vdev_param = ar->wmi.vdev_param->nss;
4257 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4258 nss);
4259 if (ret) {
4260 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
4261 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
4262 ret);
4263 goto err_vdev_delete;
4264 }
4265 }
4266
Michal Kaziore57e0572015-03-24 13:14:03 +00004267 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4268 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
Marek Puzyniak7390ed32015-03-30 09:51:52 +03004269 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr,
4270 WMI_PEER_TYPE_DEFAULT);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004271 if (ret) {
Michal Kaziore57e0572015-03-24 13:14:03 +00004272 ath10k_warn(ar, "failed to create vdev %i peer for AP/IBSS: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004273 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004274 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004275 }
Michal Kaziore57e0572015-03-24 13:14:03 +00004276 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01004277
Michal Kaziore57e0572015-03-24 13:14:03 +00004278 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
Kalle Valo5a13e762014-01-20 11:01:46 +02004279 ret = ath10k_mac_set_kickout(arvif);
4280 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004281 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004282 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +02004283 goto err_peer_delete;
4284 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004285 }
4286
4287 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
4288 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
4289 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4290 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4291 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004292 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004293 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004294 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004295 goto err_peer_delete;
4296 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004297
Michal Kazior9f9b5742014-12-12 12:41:36 +01004298 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004299 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01004300 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004301 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004302 goto err_peer_delete;
4303 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004304
Michal Kazior9f9b5742014-12-12 12:41:36 +01004305 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004306 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01004307 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004308 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004309 goto err_peer_delete;
4310 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004311 }
4312
Vivek Natarajana48e2cc2015-08-04 10:45:12 +05304313 ret = ath10k_mac_set_txbf_conf(arvif);
4314 if (ret) {
4315 ath10k_warn(ar, "failed to set txbf for vdev %d: %d\n",
4316 arvif->vdev_id, ret);
4317 goto err_peer_delete;
4318 }
4319
Michal Kazior424121c2013-07-22 14:13:31 +02004320 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004321 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004322 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03004323 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004324 goto err_peer_delete;
4325 }
Michal Kazior679c54a2013-07-05 16:15:04 +03004326
Michal Kazior7d9d5582014-10-21 10:40:15 +03004327 arvif->txpower = vif->bss_conf.txpower;
4328 ret = ath10k_mac_txpower_recalc(ar);
4329 if (ret) {
4330 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
4331 goto err_peer_delete;
4332 }
4333
Michal Kazior500ff9f2015-03-31 10:26:21 +00004334 if (vif->type == NL80211_IFTYPE_MONITOR) {
4335 ar->monitor_arvif = arvif;
4336 ret = ath10k_monitor_recalc(ar);
4337 if (ret) {
4338 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4339 goto err_peer_delete;
4340 }
4341 }
4342
Kalle Valo5e3dd152013-06-12 20:52:10 +03004343 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004344 return 0;
4345
4346err_peer_delete:
Michal Kaziore57e0572015-03-24 13:14:03 +00004347 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4348 arvif->vdev_type == WMI_VDEV_TYPE_IBSS)
Michal Kazior9dad14a2013-10-16 15:44:45 +03004349 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
4350
4351err_vdev_delete:
4352 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
Ben Greear16c11172014-09-23 14:17:16 -07004353 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03004354 list_del(&arvif->list);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004355
4356err:
Michal Kazior64badcb2014-09-18 11:18:02 +03004357 if (arvif->beacon_buf) {
4358 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
4359 arvif->beacon_buf, arvif->beacon_paddr);
4360 arvif->beacon_buf = NULL;
4361 }
4362
Michal Kazior9dad14a2013-10-16 15:44:45 +03004363 mutex_unlock(&ar->conf_mutex);
4364
Kalle Valo5e3dd152013-06-12 20:52:10 +03004365 return ret;
4366}
4367
Michal Kaziorb4aa5392015-03-31 10:26:24 +00004368static void ath10k_mac_vif_tx_unlock_all(struct ath10k_vif *arvif)
4369{
4370 int i;
4371
4372 for (i = 0; i < BITS_PER_LONG; i++)
4373 ath10k_mac_vif_tx_unlock(arvif, i);
4374}
4375
Kalle Valo5e3dd152013-06-12 20:52:10 +03004376static void ath10k_remove_interface(struct ieee80211_hw *hw,
4377 struct ieee80211_vif *vif)
4378{
4379 struct ath10k *ar = hw->priv;
4380 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4381 int ret;
4382
Michal Kazior81a9a172015-03-05 16:02:17 +02004383 cancel_work_sync(&arvif->ap_csa_work);
Michal Kaziorcc9904e2015-03-10 16:22:01 +02004384 cancel_delayed_work_sync(&arvif->connection_loss_work);
Michal Kazior81a9a172015-03-05 16:02:17 +02004385
Sujith Manoharan5d011f52014-11-25 11:47:00 +05304386 mutex_lock(&ar->conf_mutex);
4387
Michal Kaziored543882013-09-13 14:16:56 +02004388 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03004389 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kaziored543882013-09-13 14:16:56 +02004390 spin_unlock_bh(&ar->data_lock);
4391
Simon Wunderlich855aed12014-08-02 09:12:54 +03004392 ret = ath10k_spectral_vif_stop(arvif);
4393 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004394 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03004395 arvif->vdev_id, ret);
4396
Ben Greear16c11172014-09-23 14:17:16 -07004397 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03004398 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004399
Michal Kaziore57e0572015-03-24 13:14:03 +00004400 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4401 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
Michal Kazior2c512052015-02-15 16:50:40 +02004402 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
4403 vif->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004404 if (ret)
Michal Kaziore57e0572015-03-24 13:14:03 +00004405 ath10k_warn(ar, "failed to submit AP/IBSS self-peer removal on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004406 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004407
4408 kfree(arvif->u.ap.noa_data);
4409 }
4410
Michal Kazior7aa7a722014-08-25 12:09:38 +02004411 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004412 arvif->vdev_id);
4413
Kalle Valo5e3dd152013-06-12 20:52:10 +03004414 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
4415 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004416 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004417 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004418
Michal Kazior2c512052015-02-15 16:50:40 +02004419 /* Some firmware revisions don't notify host about self-peer removal
4420 * until after associated vdev is deleted.
4421 */
Michal Kaziore57e0572015-03-24 13:14:03 +00004422 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4423 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
Michal Kazior2c512052015-02-15 16:50:40 +02004424 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
4425 vif->addr);
4426 if (ret)
4427 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
4428 arvif->vdev_id, ret);
4429
4430 spin_lock_bh(&ar->data_lock);
4431 ar->num_peers--;
4432 spin_unlock_bh(&ar->data_lock);
4433 }
4434
Kalle Valo5e3dd152013-06-12 20:52:10 +03004435 ath10k_peer_cleanup(ar, arvif->vdev_id);
4436
Michal Kazior500ff9f2015-03-31 10:26:21 +00004437 if (vif->type == NL80211_IFTYPE_MONITOR) {
4438 ar->monitor_arvif = NULL;
4439 ret = ath10k_monitor_recalc(ar);
4440 if (ret)
4441 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4442 }
4443
Michal Kaziorb4aa5392015-03-31 10:26:24 +00004444 spin_lock_bh(&ar->htt.tx_lock);
4445 ath10k_mac_vif_tx_unlock_all(arvif);
4446 spin_unlock_bh(&ar->htt.tx_lock);
4447
Kalle Valo5e3dd152013-06-12 20:52:10 +03004448 mutex_unlock(&ar->conf_mutex);
4449}
4450
4451/*
4452 * FIXME: Has to be verified.
4453 */
4454#define SUPPORTED_FILTERS \
Johannes Bergdf140462015-04-22 14:40:58 +02004455 (FIF_ALLMULTI | \
Kalle Valo5e3dd152013-06-12 20:52:10 +03004456 FIF_CONTROL | \
4457 FIF_PSPOLL | \
4458 FIF_OTHER_BSS | \
4459 FIF_BCN_PRBRESP_PROMISC | \
4460 FIF_PROBE_REQ | \
4461 FIF_FCSFAIL)
4462
4463static void ath10k_configure_filter(struct ieee80211_hw *hw,
4464 unsigned int changed_flags,
4465 unsigned int *total_flags,
4466 u64 multicast)
4467{
4468 struct ath10k *ar = hw->priv;
4469 int ret;
4470
4471 mutex_lock(&ar->conf_mutex);
4472
4473 changed_flags &= SUPPORTED_FILTERS;
4474 *total_flags &= SUPPORTED_FILTERS;
4475 ar->filter_flags = *total_flags;
4476
Michal Kazior19337472014-08-28 12:58:16 +02004477 ret = ath10k_monitor_recalc(ar);
4478 if (ret)
4479 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004480
4481 mutex_unlock(&ar->conf_mutex);
4482}
4483
4484static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
4485 struct ieee80211_vif *vif,
4486 struct ieee80211_bss_conf *info,
4487 u32 changed)
4488{
4489 struct ath10k *ar = hw->priv;
4490 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4491 int ret = 0;
Kalle Valoaf762c02014-09-14 12:50:17 +03004492 u32 vdev_param, pdev_param, slottime, preamble;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004493
4494 mutex_lock(&ar->conf_mutex);
4495
4496 if (changed & BSS_CHANGED_IBSS)
4497 ath10k_control_ibss(arvif, info, vif->addr);
4498
4499 if (changed & BSS_CHANGED_BEACON_INT) {
4500 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004501 vdev_param = ar->wmi.vdev_param->beacon_interval;
4502 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004503 arvif->beacon_interval);
Michal Kazior7aa7a722014-08-25 12:09:38 +02004504 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004505 "mac vdev %d beacon_interval %d\n",
4506 arvif->vdev_id, arvif->beacon_interval);
4507
Kalle Valo5e3dd152013-06-12 20:52:10 +03004508 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004509 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004510 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004511 }
4512
4513 if (changed & BSS_CHANGED_BEACON) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004514 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004515 "vdev %d set beacon tx mode to staggered\n",
4516 arvif->vdev_id);
4517
Bartosz Markowski226a3392013-09-26 17:47:16 +02004518 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
4519 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004520 WMI_BEACON_STAGGERED_MODE);
4521 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004522 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004523 arvif->vdev_id, ret);
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02004524
4525 ret = ath10k_mac_setup_bcn_tmpl(arvif);
4526 if (ret)
4527 ath10k_warn(ar, "failed to update beacon template: %d\n",
4528 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004529 }
4530
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02004531 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
4532 ret = ath10k_mac_setup_prb_tmpl(arvif);
4533 if (ret)
4534 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
4535 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004536 }
4537
Michal Kaziorba2479f2015-01-24 12:14:51 +02004538 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004539 arvif->dtim_period = info->dtim_period;
4540
Michal Kazior7aa7a722014-08-25 12:09:38 +02004541 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004542 "mac vdev %d dtim_period %d\n",
4543 arvif->vdev_id, arvif->dtim_period);
4544
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004545 vdev_param = ar->wmi.vdev_param->dtim_period;
4546 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004547 arvif->dtim_period);
4548 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004549 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004550 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004551 }
4552
4553 if (changed & BSS_CHANGED_SSID &&
4554 vif->type == NL80211_IFTYPE_AP) {
4555 arvif->u.ap.ssid_len = info->ssid_len;
4556 if (info->ssid_len)
4557 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
4558 arvif->u.ap.hidden_ssid = info->hidden_ssid;
4559 }
4560
Michal Kazior077efc82014-10-21 10:10:29 +03004561 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
4562 ether_addr_copy(arvif->bssid, info->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004563
4564 if (changed & BSS_CHANGED_BEACON_ENABLED)
4565 ath10k_control_beaconing(arvif, info);
4566
4567 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02004568 arvif->use_cts_prot = info->use_cts_prot;
Michal Kazior7aa7a722014-08-25 12:09:38 +02004569 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02004570 arvif->vdev_id, info->use_cts_prot);
Kalle Valo60c3daa2013-09-08 17:56:07 +03004571
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02004572 ret = ath10k_recalc_rtscts_prot(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004573 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004574 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004575 arvif->vdev_id, ret);
Michal Kaziora87fd4b2015-03-02 11:21:17 +01004576
4577 vdev_param = ar->wmi.vdev_param->protection_mode;
4578 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4579 info->use_cts_prot ? 1 : 0);
4580 if (ret)
4581 ath10k_warn(ar, "failed to set protection mode %d on vdev %i: %d\n",
4582 info->use_cts_prot, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004583 }
4584
4585 if (changed & BSS_CHANGED_ERP_SLOT) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004586 if (info->use_short_slot)
4587 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
4588
4589 else
4590 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
4591
Michal Kazior7aa7a722014-08-25 12:09:38 +02004592 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004593 arvif->vdev_id, slottime);
4594
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004595 vdev_param = ar->wmi.vdev_param->slot_time;
4596 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004597 slottime);
4598 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004599 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004600 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004601 }
4602
4603 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004604 if (info->use_short_preamble)
4605 preamble = WMI_VDEV_PREAMBLE_SHORT;
4606 else
4607 preamble = WMI_VDEV_PREAMBLE_LONG;
4608
Michal Kazior7aa7a722014-08-25 12:09:38 +02004609 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004610 "mac vdev %d preamble %dn",
4611 arvif->vdev_id, preamble);
4612
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004613 vdev_param = ar->wmi.vdev_param->preamble;
4614 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004615 preamble);
4616 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004617 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004618 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004619 }
4620
4621 if (changed & BSS_CHANGED_ASSOC) {
Michal Kaziore556f112014-08-28 12:58:17 +02004622 if (info->assoc) {
4623 /* Workaround: Make sure monitor vdev is not running
4624 * when associating to prevent some firmware revisions
4625 * (e.g. 10.1 and 10.2) from crashing.
4626 */
4627 if (ar->monitor_started)
4628 ath10k_monitor_stop(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004629 ath10k_bss_assoc(hw, vif, info);
Michal Kaziore556f112014-08-28 12:58:17 +02004630 ath10k_monitor_recalc(ar);
Michal Kazior077efc82014-10-21 10:10:29 +03004631 } else {
4632 ath10k_bss_disassoc(hw, vif);
Michal Kaziore556f112014-08-28 12:58:17 +02004633 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004634 }
4635
Michal Kazior7d9d5582014-10-21 10:40:15 +03004636 if (changed & BSS_CHANGED_TXPOWER) {
4637 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
4638 arvif->vdev_id, info->txpower);
4639
4640 arvif->txpower = info->txpower;
4641 ret = ath10k_mac_txpower_recalc(ar);
4642 if (ret)
4643 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
4644 }
4645
Michal Kaziorbf14e652014-12-12 12:41:38 +01004646 if (changed & BSS_CHANGED_PS) {
Michal Kaziorcffb41f2015-02-13 13:30:16 +01004647 arvif->ps = vif->bss_conf.ps;
4648
4649 ret = ath10k_config_ps(ar);
Michal Kaziorbf14e652014-12-12 12:41:38 +01004650 if (ret)
4651 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
4652 arvif->vdev_id, ret);
4653 }
4654
Kalle Valo5e3dd152013-06-12 20:52:10 +03004655 mutex_unlock(&ar->conf_mutex);
4656}
4657
4658static int ath10k_hw_scan(struct ieee80211_hw *hw,
4659 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02004660 struct ieee80211_scan_request *hw_req)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004661{
4662 struct ath10k *ar = hw->priv;
4663 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
David Spinadelc56ef672014-02-05 15:21:13 +02004664 struct cfg80211_scan_request *req = &hw_req->req;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004665 struct wmi_start_scan_arg arg;
4666 int ret = 0;
4667 int i;
4668
4669 mutex_lock(&ar->conf_mutex);
4670
4671 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004672 switch (ar->scan.state) {
4673 case ATH10K_SCAN_IDLE:
4674 reinit_completion(&ar->scan.started);
4675 reinit_completion(&ar->scan.completed);
4676 ar->scan.state = ATH10K_SCAN_STARTING;
4677 ar->scan.is_roc = false;
4678 ar->scan.vdev_id = arvif->vdev_id;
4679 ret = 0;
4680 break;
4681 case ATH10K_SCAN_STARTING:
4682 case ATH10K_SCAN_RUNNING:
4683 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004684 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004685 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004686 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004687 spin_unlock_bh(&ar->data_lock);
4688
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004689 if (ret)
4690 goto exit;
4691
Kalle Valo5e3dd152013-06-12 20:52:10 +03004692 memset(&arg, 0, sizeof(arg));
4693 ath10k_wmi_start_scan_init(ar, &arg);
4694 arg.vdev_id = arvif->vdev_id;
4695 arg.scan_id = ATH10K_SCAN_ID;
4696
Kalle Valo5e3dd152013-06-12 20:52:10 +03004697 if (req->ie_len) {
4698 arg.ie_len = req->ie_len;
4699 memcpy(arg.ie, req->ie, arg.ie_len);
4700 }
4701
4702 if (req->n_ssids) {
4703 arg.n_ssids = req->n_ssids;
4704 for (i = 0; i < arg.n_ssids; i++) {
4705 arg.ssids[i].len = req->ssids[i].ssid_len;
4706 arg.ssids[i].ssid = req->ssids[i].ssid;
4707 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02004708 } else {
4709 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004710 }
4711
4712 if (req->n_channels) {
4713 arg.n_channels = req->n_channels;
4714 for (i = 0; i < arg.n_channels; i++)
4715 arg.channels[i] = req->channels[i]->center_freq;
4716 }
4717
4718 ret = ath10k_start_scan(ar, &arg);
4719 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004720 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004721 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004722 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004723 spin_unlock_bh(&ar->data_lock);
4724 }
4725
4726exit:
4727 mutex_unlock(&ar->conf_mutex);
4728 return ret;
4729}
4730
4731static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
4732 struct ieee80211_vif *vif)
4733{
4734 struct ath10k *ar = hw->priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004735
4736 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004737 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004738 mutex_unlock(&ar->conf_mutex);
Michal Kazior4eb2e162014-10-28 10:23:09 +01004739
4740 cancel_delayed_work_sync(&ar->scan.timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004741}
4742
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004743static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
4744 struct ath10k_vif *arvif,
4745 enum set_key_cmd cmd,
4746 struct ieee80211_key_conf *key)
4747{
4748 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
4749 int ret;
4750
4751 /* 10.1 firmware branch requires default key index to be set to group
4752 * key index after installing it. Otherwise FW/HW Txes corrupted
4753 * frames with multi-vif APs. This is not required for main firmware
4754 * branch (e.g. 636).
4755 *
Michal Kazior8461baf2015-04-10 13:23:22 +00004756 * This is also needed for 636 fw for IBSS-RSN to work more reliably.
4757 *
4758 * FIXME: It remains unknown if this is required for multi-vif STA
4759 * interfaces on 10.1.
4760 */
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004761
Michal Kazior8461baf2015-04-10 13:23:22 +00004762 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
4763 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004764 return;
4765
4766 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
4767 return;
4768
4769 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
4770 return;
4771
4772 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4773 return;
4774
4775 if (cmd != SET_KEY)
4776 return;
4777
4778 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4779 key->keyidx);
4780 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004781 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004782 arvif->vdev_id, ret);
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004783}
4784
Kalle Valo5e3dd152013-06-12 20:52:10 +03004785static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
4786 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
4787 struct ieee80211_key_conf *key)
4788{
4789 struct ath10k *ar = hw->priv;
4790 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4791 struct ath10k_peer *peer;
4792 const u8 *peer_addr;
4793 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
4794 key->cipher == WLAN_CIPHER_SUITE_WEP104;
4795 int ret = 0;
Michal Kazior29a10002015-04-10 13:05:58 +00004796 int ret2;
Michal Kazior370e5672015-02-18 14:02:26 +01004797 u32 flags = 0;
Michal Kazior29a10002015-04-10 13:05:58 +00004798 u32 flags2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004799
Bartosz Markowskid7131c02015-03-10 14:32:19 +01004800 /* this one needs to be done in software */
4801 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
4802 return 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004803
David Liuccec9032015-07-24 20:25:32 +03004804 if (arvif->nohwcrypt)
4805 return 1;
4806
Kalle Valo5e3dd152013-06-12 20:52:10 +03004807 if (key->keyidx > WMI_MAX_KEY_INDEX)
4808 return -ENOSPC;
4809
4810 mutex_lock(&ar->conf_mutex);
4811
4812 if (sta)
4813 peer_addr = sta->addr;
4814 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
4815 peer_addr = vif->bss_conf.bssid;
4816 else
4817 peer_addr = vif->addr;
4818
4819 key->hw_key_idx = key->keyidx;
4820
Michal Kazior7c8cc7e2015-04-01 22:53:19 +03004821 if (is_wep) {
4822 if (cmd == SET_KEY)
4823 arvif->wep_keys[key->keyidx] = key;
4824 else
4825 arvif->wep_keys[key->keyidx] = NULL;
4826 }
4827
Kalle Valo5e3dd152013-06-12 20:52:10 +03004828 /* the peer should not disappear in mid-way (unless FW goes awry) since
4829 * we already hold conf_mutex. we just make sure its there now. */
4830 spin_lock_bh(&ar->data_lock);
4831 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4832 spin_unlock_bh(&ar->data_lock);
4833
4834 if (!peer) {
4835 if (cmd == SET_KEY) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004836 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03004837 peer_addr);
4838 ret = -EOPNOTSUPP;
4839 goto exit;
4840 } else {
4841 /* if the peer doesn't exist there is no key to disable
4842 * anymore */
4843 goto exit;
4844 }
4845 }
4846
Michal Kazior7cc45732015-03-09 14:24:17 +01004847 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4848 flags |= WMI_KEY_PAIRWISE;
4849 else
4850 flags |= WMI_KEY_GROUP;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004851
Kalle Valo5e3dd152013-06-12 20:52:10 +03004852 if (is_wep) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004853 if (cmd == DISABLE_KEY)
4854 ath10k_clear_vdev_key(arvif, key);
Michal Kazior370e5672015-02-18 14:02:26 +01004855
Michal Kaziorad325cb2015-02-18 14:02:27 +01004856 /* When WEP keys are uploaded it's possible that there are
4857 * stations associated already (e.g. when merging) without any
4858 * keys. Static WEP needs an explicit per-peer key upload.
4859 */
4860 if (vif->type == NL80211_IFTYPE_ADHOC &&
4861 cmd == SET_KEY)
4862 ath10k_mac_vif_update_wep_key(arvif, key);
4863
Michal Kazior370e5672015-02-18 14:02:26 +01004864 /* 802.1x never sets the def_wep_key_idx so each set_key()
4865 * call changes default tx key.
4866 *
4867 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
4868 * after first set_key().
4869 */
4870 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
4871 flags |= WMI_KEY_TX_USAGE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004872 }
4873
Michal Kazior370e5672015-02-18 14:02:26 +01004874 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004875 if (ret) {
David Liuccec9032015-07-24 20:25:32 +03004876 WARN_ON(ret > 0);
Michal Kazior7aa7a722014-08-25 12:09:38 +02004877 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004878 arvif->vdev_id, peer_addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004879 goto exit;
4880 }
4881
Michal Kazior29a10002015-04-10 13:05:58 +00004882 /* mac80211 sets static WEP keys as groupwise while firmware requires
4883 * them to be installed twice as both pairwise and groupwise.
4884 */
4885 if (is_wep && !sta && vif->type == NL80211_IFTYPE_STATION) {
4886 flags2 = flags;
4887 flags2 &= ~WMI_KEY_GROUP;
4888 flags2 |= WMI_KEY_PAIRWISE;
4889
4890 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags2);
4891 if (ret) {
David Liuccec9032015-07-24 20:25:32 +03004892 WARN_ON(ret > 0);
Michal Kazior29a10002015-04-10 13:05:58 +00004893 ath10k_warn(ar, "failed to install (ucast) key for vdev %i peer %pM: %d\n",
4894 arvif->vdev_id, peer_addr, ret);
4895 ret2 = ath10k_install_key(arvif, key, DISABLE_KEY,
4896 peer_addr, flags);
David Liuccec9032015-07-24 20:25:32 +03004897 if (ret2) {
4898 WARN_ON(ret2 > 0);
Michal Kazior29a10002015-04-10 13:05:58 +00004899 ath10k_warn(ar, "failed to disable (mcast) key for vdev %i peer %pM: %d\n",
4900 arvif->vdev_id, peer_addr, ret2);
David Liuccec9032015-07-24 20:25:32 +03004901 }
Michal Kazior29a10002015-04-10 13:05:58 +00004902 goto exit;
4903 }
4904 }
4905
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004906 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
4907
Kalle Valo5e3dd152013-06-12 20:52:10 +03004908 spin_lock_bh(&ar->data_lock);
4909 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4910 if (peer && cmd == SET_KEY)
4911 peer->keys[key->keyidx] = key;
4912 else if (peer && cmd == DISABLE_KEY)
4913 peer->keys[key->keyidx] = NULL;
4914 else if (peer == NULL)
4915 /* impossible unless FW goes crazy */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004916 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004917 spin_unlock_bh(&ar->data_lock);
4918
4919exit:
4920 mutex_unlock(&ar->conf_mutex);
4921 return ret;
4922}
4923
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004924static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
4925 struct ieee80211_vif *vif,
4926 int keyidx)
4927{
4928 struct ath10k *ar = hw->priv;
4929 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4930 int ret;
4931
4932 mutex_lock(&arvif->ar->conf_mutex);
4933
4934 if (arvif->ar->state != ATH10K_STATE_ON)
4935 goto unlock;
4936
4937 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
4938 arvif->vdev_id, keyidx);
4939
4940 ret = ath10k_wmi_vdev_set_param(arvif->ar,
4941 arvif->vdev_id,
4942 arvif->ar->wmi.vdev_param->def_keyid,
4943 keyidx);
4944
4945 if (ret) {
4946 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
4947 arvif->vdev_id,
4948 ret);
4949 goto unlock;
4950 }
4951
4952 arvif->def_wep_key_idx = keyidx;
Michal Kazior370e5672015-02-18 14:02:26 +01004953
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004954unlock:
4955 mutex_unlock(&arvif->ar->conf_mutex);
4956}
4957
Michal Kazior9797feb2014-02-14 14:49:48 +01004958static void ath10k_sta_rc_update_wk(struct work_struct *wk)
4959{
4960 struct ath10k *ar;
4961 struct ath10k_vif *arvif;
4962 struct ath10k_sta *arsta;
4963 struct ieee80211_sta *sta;
Michal Kazior45c9abc2015-04-21 20:42:58 +03004964 struct cfg80211_chan_def def;
4965 enum ieee80211_band band;
4966 const u8 *ht_mcs_mask;
4967 const u16 *vht_mcs_mask;
Michal Kazior9797feb2014-02-14 14:49:48 +01004968 u32 changed, bw, nss, smps;
4969 int err;
4970
4971 arsta = container_of(wk, struct ath10k_sta, update_wk);
4972 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
4973 arvif = arsta->arvif;
4974 ar = arvif->ar;
4975
Michal Kazior45c9abc2015-04-21 20:42:58 +03004976 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
4977 return;
4978
4979 band = def.chan->band;
4980 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
4981 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
4982
Michal Kazior9797feb2014-02-14 14:49:48 +01004983 spin_lock_bh(&ar->data_lock);
4984
4985 changed = arsta->changed;
4986 arsta->changed = 0;
4987
4988 bw = arsta->bw;
4989 nss = arsta->nss;
4990 smps = arsta->smps;
4991
4992 spin_unlock_bh(&ar->data_lock);
4993
4994 mutex_lock(&ar->conf_mutex);
4995
Michal Kazior45c9abc2015-04-21 20:42:58 +03004996 nss = max_t(u32, 1, nss);
4997 nss = min(nss, max(ath10k_mac_max_ht_nss(ht_mcs_mask),
4998 ath10k_mac_max_vht_nss(vht_mcs_mask)));
4999
Michal Kazior9797feb2014-02-14 14:49:48 +01005000 if (changed & IEEE80211_RC_BW_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005001 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01005002 sta->addr, bw);
5003
5004 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5005 WMI_PEER_CHAN_WIDTH, bw);
5006 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005007 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01005008 sta->addr, bw, err);
5009 }
5010
5011 if (changed & IEEE80211_RC_NSS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005012 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01005013 sta->addr, nss);
5014
5015 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5016 WMI_PEER_NSS, nss);
5017 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005018 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01005019 sta->addr, nss, err);
5020 }
5021
5022 if (changed & IEEE80211_RC_SMPS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005023 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01005024 sta->addr, smps);
5025
5026 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5027 WMI_PEER_SMPS_STATE, smps);
5028 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005029 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01005030 sta->addr, smps, err);
5031 }
5032
Janusz Dziedzic55884c02014-12-17 12:30:02 +02005033 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
5034 changed & IEEE80211_RC_NSS_CHANGED) {
5035 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02005036 sta->addr);
5037
Michal Kazior590922a2014-10-21 10:10:29 +03005038 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02005039 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005040 ath10k_warn(ar, "failed to reassociate station: %pM\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02005041 sta->addr);
5042 }
5043
Michal Kazior9797feb2014-02-14 14:49:48 +01005044 mutex_unlock(&ar->conf_mutex);
5045}
5046
Marek Puzyniak7c354242015-03-30 09:51:52 +03005047static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif,
5048 struct ieee80211_sta *sta)
Michal Kaziorcfd10612014-11-25 15:16:05 +01005049{
5050 struct ath10k *ar = arvif->ar;
5051
5052 lockdep_assert_held(&ar->conf_mutex);
5053
Marek Puzyniak7c354242015-03-30 09:51:52 +03005054 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
Michal Kaziorcfd10612014-11-25 15:16:05 +01005055 return 0;
5056
5057 if (ar->num_stations >= ar->max_num_stations)
5058 return -ENOBUFS;
5059
5060 ar->num_stations++;
5061
5062 return 0;
5063}
5064
Marek Puzyniak7c354242015-03-30 09:51:52 +03005065static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif,
5066 struct ieee80211_sta *sta)
Michal Kaziorcfd10612014-11-25 15:16:05 +01005067{
5068 struct ath10k *ar = arvif->ar;
5069
5070 lockdep_assert_held(&ar->conf_mutex);
5071
Marek Puzyniak7c354242015-03-30 09:51:52 +03005072 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
Michal Kaziorcfd10612014-11-25 15:16:05 +01005073 return;
5074
5075 ar->num_stations--;
5076}
5077
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005078struct ath10k_mac_tdls_iter_data {
5079 u32 num_tdls_stations;
5080 struct ieee80211_vif *curr_vif;
5081};
5082
5083static void ath10k_mac_tdls_vif_stations_count_iter(void *data,
5084 struct ieee80211_sta *sta)
5085{
5086 struct ath10k_mac_tdls_iter_data *iter_data = data;
5087 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5088 struct ieee80211_vif *sta_vif = arsta->arvif->vif;
5089
5090 if (sta->tdls && sta_vif == iter_data->curr_vif)
5091 iter_data->num_tdls_stations++;
5092}
5093
5094static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw *hw,
5095 struct ieee80211_vif *vif)
5096{
5097 struct ath10k_mac_tdls_iter_data data = {};
5098
5099 data.curr_vif = vif;
5100
5101 ieee80211_iterate_stations_atomic(hw,
5102 ath10k_mac_tdls_vif_stations_count_iter,
5103 &data);
5104 return data.num_tdls_stations;
5105}
5106
5107static void ath10k_mac_tdls_vifs_count_iter(void *data, u8 *mac,
5108 struct ieee80211_vif *vif)
5109{
5110 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5111 int *num_tdls_vifs = data;
5112
5113 if (vif->type != NL80211_IFTYPE_STATION)
5114 return;
5115
5116 if (ath10k_mac_tdls_vif_stations_count(arvif->ar->hw, vif) > 0)
5117 (*num_tdls_vifs)++;
5118}
5119
5120static int ath10k_mac_tdls_vifs_count(struct ieee80211_hw *hw)
5121{
5122 int num_tdls_vifs = 0;
5123
5124 ieee80211_iterate_active_interfaces_atomic(hw,
5125 IEEE80211_IFACE_ITER_NORMAL,
5126 ath10k_mac_tdls_vifs_count_iter,
5127 &num_tdls_vifs);
5128 return num_tdls_vifs;
5129}
5130
Kalle Valo5e3dd152013-06-12 20:52:10 +03005131static int ath10k_sta_state(struct ieee80211_hw *hw,
5132 struct ieee80211_vif *vif,
5133 struct ieee80211_sta *sta,
5134 enum ieee80211_sta_state old_state,
5135 enum ieee80211_sta_state new_state)
5136{
5137 struct ath10k *ar = hw->priv;
5138 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01005139 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005140 int ret = 0;
5141
Michal Kazior76f90022014-02-25 09:29:57 +02005142 if (old_state == IEEE80211_STA_NOTEXIST &&
5143 new_state == IEEE80211_STA_NONE) {
5144 memset(arsta, 0, sizeof(*arsta));
5145 arsta->arvif = arvif;
5146 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
5147 }
5148
Michal Kazior9797feb2014-02-14 14:49:48 +01005149 /* cancel must be done outside the mutex to avoid deadlock */
5150 if ((old_state == IEEE80211_STA_NONE &&
5151 new_state == IEEE80211_STA_NOTEXIST))
5152 cancel_work_sync(&arsta->update_wk);
5153
Kalle Valo5e3dd152013-06-12 20:52:10 +03005154 mutex_lock(&ar->conf_mutex);
5155
5156 if (old_state == IEEE80211_STA_NOTEXIST &&
Michal Kazior077efc82014-10-21 10:10:29 +03005157 new_state == IEEE80211_STA_NONE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03005158 /*
5159 * New station addition.
5160 */
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005161 enum wmi_peer_type peer_type = WMI_PEER_TYPE_DEFAULT;
5162 u32 num_tdls_stations;
5163 u32 num_tdls_vifs;
5164
Michal Kaziorcfd10612014-11-25 15:16:05 +01005165 ath10k_dbg(ar, ATH10K_DBG_MAC,
5166 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
5167 arvif->vdev_id, sta->addr,
5168 ar->num_stations + 1, ar->max_num_stations,
5169 ar->num_peers + 1, ar->max_num_peers);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01005170
Marek Puzyniak7c354242015-03-30 09:51:52 +03005171 ret = ath10k_mac_inc_num_stations(arvif, sta);
Michal Kaziorcfd10612014-11-25 15:16:05 +01005172 if (ret) {
5173 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
5174 ar->max_num_stations);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01005175 goto exit;
5176 }
5177
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005178 if (sta->tdls)
5179 peer_type = WMI_PEER_TYPE_TDLS;
5180
Marek Puzyniak7390ed32015-03-30 09:51:52 +03005181 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr,
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005182 peer_type);
Michal Kaziora52c0282014-11-25 15:16:03 +01005183 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005184 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 -08005185 sta->addr, arvif->vdev_id, ret);
Marek Puzyniak7c354242015-03-30 09:51:52 +03005186 ath10k_mac_dec_num_stations(arvif, sta);
Michal Kaziora52c0282014-11-25 15:16:03 +01005187 goto exit;
5188 }
Michal Kazior077efc82014-10-21 10:10:29 +03005189
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005190 if (!sta->tdls)
5191 goto exit;
Michal Kazior077efc82014-10-21 10:10:29 +03005192
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005193 num_tdls_stations = ath10k_mac_tdls_vif_stations_count(hw, vif);
5194 num_tdls_vifs = ath10k_mac_tdls_vifs_count(hw);
5195
5196 if (num_tdls_vifs >= ar->max_num_tdls_vdevs &&
5197 num_tdls_stations == 0) {
5198 ath10k_warn(ar, "vdev %i exceeded maximum number of tdls vdevs %i\n",
5199 arvif->vdev_id, ar->max_num_tdls_vdevs);
5200 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5201 ath10k_mac_dec_num_stations(arvif, sta);
5202 ret = -ENOBUFS;
5203 goto exit;
5204 }
5205
5206 if (num_tdls_stations == 0) {
5207 /* This is the first tdls peer in current vif */
5208 enum wmi_tdls_state state = WMI_TDLS_ENABLE_ACTIVE;
5209
5210 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5211 state);
Michal Kazior077efc82014-10-21 10:10:29 +03005212 if (ret) {
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005213 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
Michal Kazior077efc82014-10-21 10:10:29 +03005214 arvif->vdev_id, ret);
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005215 ath10k_peer_delete(ar, arvif->vdev_id,
5216 sta->addr);
5217 ath10k_mac_dec_num_stations(arvif, sta);
Michal Kazior077efc82014-10-21 10:10:29 +03005218 goto exit;
5219 }
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005220 }
Michal Kazior077efc82014-10-21 10:10:29 +03005221
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005222 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
5223 WMI_TDLS_PEER_STATE_PEERING);
5224 if (ret) {
5225 ath10k_warn(ar,
5226 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
5227 sta->addr, arvif->vdev_id, ret);
5228 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5229 ath10k_mac_dec_num_stations(arvif, sta);
5230
5231 if (num_tdls_stations != 0)
5232 goto exit;
5233 ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5234 WMI_TDLS_DISABLE);
Michal Kazior077efc82014-10-21 10:10:29 +03005235 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005236 } else if ((old_state == IEEE80211_STA_NONE &&
5237 new_state == IEEE80211_STA_NOTEXIST)) {
5238 /*
5239 * Existing station deletion.
5240 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005241 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03005242 "mac vdev %d peer delete %pM (sta gone)\n",
5243 arvif->vdev_id, sta->addr);
Michal Kazior077efc82014-10-21 10:10:29 +03005244
Kalle Valo5e3dd152013-06-12 20:52:10 +03005245 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5246 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005247 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02005248 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005249
Marek Puzyniak7c354242015-03-30 09:51:52 +03005250 ath10k_mac_dec_num_stations(arvif, sta);
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005251
5252 if (!sta->tdls)
5253 goto exit;
5254
5255 if (ath10k_mac_tdls_vif_stations_count(hw, vif))
5256 goto exit;
5257
5258 /* This was the last tdls peer in current vif */
5259 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5260 WMI_TDLS_DISABLE);
5261 if (ret) {
5262 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
5263 arvif->vdev_id, ret);
5264 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005265 } else if (old_state == IEEE80211_STA_AUTH &&
5266 new_state == IEEE80211_STA_ASSOC &&
5267 (vif->type == NL80211_IFTYPE_AP ||
5268 vif->type == NL80211_IFTYPE_ADHOC)) {
5269 /*
5270 * New association.
5271 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005272 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03005273 sta->addr);
5274
Michal Kazior590922a2014-10-21 10:10:29 +03005275 ret = ath10k_station_assoc(ar, vif, sta, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005276 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005277 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02005278 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005279 } else if (old_state == IEEE80211_STA_ASSOC &&
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005280 new_state == IEEE80211_STA_AUTHORIZED &&
5281 sta->tdls) {
5282 /*
5283 * Tdls station authorized.
5284 */
5285 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac tdls sta %pM authorized\n",
5286 sta->addr);
5287
5288 ret = ath10k_station_assoc(ar, vif, sta, false);
5289 if (ret) {
5290 ath10k_warn(ar, "failed to associate tdls station %pM for vdev %i: %i\n",
5291 sta->addr, arvif->vdev_id, ret);
5292 goto exit;
5293 }
5294
5295 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
5296 WMI_TDLS_PEER_STATE_CONNECTED);
5297 if (ret)
5298 ath10k_warn(ar, "failed to update tdls peer %pM for vdev %i: %i\n",
5299 sta->addr, arvif->vdev_id, ret);
5300 } else if (old_state == IEEE80211_STA_ASSOC &&
5301 new_state == IEEE80211_STA_AUTH &&
5302 (vif->type == NL80211_IFTYPE_AP ||
5303 vif->type == NL80211_IFTYPE_ADHOC)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03005304 /*
5305 * Disassociation.
5306 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005307 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03005308 sta->addr);
5309
Michal Kazior590922a2014-10-21 10:10:29 +03005310 ret = ath10k_station_disassoc(ar, vif, sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005311 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005312 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02005313 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005314 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01005315exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005316 mutex_unlock(&ar->conf_mutex);
5317 return ret;
5318}
5319
5320static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
Kalle Valo5b07e072014-09-14 12:50:06 +03005321 u16 ac, bool enable)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005322{
5323 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorb0e56152015-01-24 12:14:52 +02005324 struct wmi_sta_uapsd_auto_trig_arg arg = {};
5325 u32 prio = 0, acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005326 u32 value = 0;
5327 int ret = 0;
5328
Michal Kazior548db542013-07-05 16:15:15 +03005329 lockdep_assert_held(&ar->conf_mutex);
5330
Kalle Valo5e3dd152013-06-12 20:52:10 +03005331 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
5332 return 0;
5333
5334 switch (ac) {
5335 case IEEE80211_AC_VO:
5336 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
5337 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005338 prio = 7;
5339 acc = 3;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005340 break;
5341 case IEEE80211_AC_VI:
5342 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
5343 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005344 prio = 5;
5345 acc = 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005346 break;
5347 case IEEE80211_AC_BE:
5348 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
5349 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005350 prio = 2;
5351 acc = 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005352 break;
5353 case IEEE80211_AC_BK:
5354 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
5355 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005356 prio = 0;
5357 acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005358 break;
5359 }
5360
5361 if (enable)
5362 arvif->u.sta.uapsd |= value;
5363 else
5364 arvif->u.sta.uapsd &= ~value;
5365
5366 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5367 WMI_STA_PS_PARAM_UAPSD,
5368 arvif->u.sta.uapsd);
5369 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005370 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005371 goto exit;
5372 }
5373
5374 if (arvif->u.sta.uapsd)
5375 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
5376 else
5377 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
5378
5379 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5380 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
5381 value);
5382 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005383 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005384
Michal Kazior9f9b5742014-12-12 12:41:36 +01005385 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
5386 if (ret) {
5387 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
5388 arvif->vdev_id, ret);
5389 return ret;
5390 }
5391
5392 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
5393 if (ret) {
5394 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
5395 arvif->vdev_id, ret);
5396 return ret;
5397 }
5398
Michal Kaziorb0e56152015-01-24 12:14:52 +02005399 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
5400 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
5401 /* Only userspace can make an educated decision when to send
5402 * trigger frame. The following effectively disables u-UAPSD
5403 * autotrigger in firmware (which is enabled by default
5404 * provided the autotrigger service is available).
5405 */
5406
5407 arg.wmm_ac = acc;
5408 arg.user_priority = prio;
5409 arg.service_interval = 0;
5410 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
5411 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
5412
5413 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
5414 arvif->bssid, &arg, 1);
5415 if (ret) {
5416 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
5417 ret);
5418 return ret;
5419 }
5420 }
5421
Kalle Valo5e3dd152013-06-12 20:52:10 +03005422exit:
5423 return ret;
5424}
5425
5426static int ath10k_conf_tx(struct ieee80211_hw *hw,
5427 struct ieee80211_vif *vif, u16 ac,
5428 const struct ieee80211_tx_queue_params *params)
5429{
5430 struct ath10k *ar = hw->priv;
Michal Kazior5e752e42015-01-19 09:53:41 +01005431 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005432 struct wmi_wmm_params_arg *p = NULL;
5433 int ret;
5434
5435 mutex_lock(&ar->conf_mutex);
5436
5437 switch (ac) {
5438 case IEEE80211_AC_VO:
Michal Kazior5e752e42015-01-19 09:53:41 +01005439 p = &arvif->wmm_params.ac_vo;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005440 break;
5441 case IEEE80211_AC_VI:
Michal Kazior5e752e42015-01-19 09:53:41 +01005442 p = &arvif->wmm_params.ac_vi;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005443 break;
5444 case IEEE80211_AC_BE:
Michal Kazior5e752e42015-01-19 09:53:41 +01005445 p = &arvif->wmm_params.ac_be;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005446 break;
5447 case IEEE80211_AC_BK:
Michal Kazior5e752e42015-01-19 09:53:41 +01005448 p = &arvif->wmm_params.ac_bk;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005449 break;
5450 }
5451
5452 if (WARN_ON(!p)) {
5453 ret = -EINVAL;
5454 goto exit;
5455 }
5456
5457 p->cwmin = params->cw_min;
5458 p->cwmax = params->cw_max;
5459 p->aifs = params->aifs;
5460
5461 /*
5462 * The channel time duration programmed in the HW is in absolute
5463 * microseconds, while mac80211 gives the txop in units of
5464 * 32 microseconds.
5465 */
5466 p->txop = params->txop * 32;
5467
Michal Kazior7fc979a2015-01-28 09:57:28 +02005468 if (ar->wmi.ops->gen_vdev_wmm_conf) {
5469 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
5470 &arvif->wmm_params);
5471 if (ret) {
5472 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
5473 arvif->vdev_id, ret);
5474 goto exit;
5475 }
5476 } else {
5477 /* This won't work well with multi-interface cases but it's
5478 * better than nothing.
5479 */
5480 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
5481 if (ret) {
5482 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
5483 goto exit;
5484 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005485 }
5486
5487 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
5488 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005489 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005490
5491exit:
5492 mutex_unlock(&ar->conf_mutex);
5493 return ret;
5494}
5495
5496#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
5497
5498static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
5499 struct ieee80211_vif *vif,
5500 struct ieee80211_channel *chan,
5501 int duration,
5502 enum ieee80211_roc_type type)
5503{
5504 struct ath10k *ar = hw->priv;
5505 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5506 struct wmi_start_scan_arg arg;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005507 int ret = 0;
Michal Kaziorfcf98442015-03-31 11:03:47 +00005508 u32 scan_time_msec;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005509
5510 mutex_lock(&ar->conf_mutex);
5511
5512 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005513 switch (ar->scan.state) {
5514 case ATH10K_SCAN_IDLE:
5515 reinit_completion(&ar->scan.started);
5516 reinit_completion(&ar->scan.completed);
5517 reinit_completion(&ar->scan.on_channel);
5518 ar->scan.state = ATH10K_SCAN_STARTING;
5519 ar->scan.is_roc = true;
5520 ar->scan.vdev_id = arvif->vdev_id;
5521 ar->scan.roc_freq = chan->center_freq;
Michal Kaziord710e752015-07-09 13:08:36 +02005522 ar->scan.roc_notify = true;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005523 ret = 0;
5524 break;
5525 case ATH10K_SCAN_STARTING:
5526 case ATH10K_SCAN_RUNNING:
5527 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005528 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005529 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005530 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005531 spin_unlock_bh(&ar->data_lock);
5532
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005533 if (ret)
5534 goto exit;
5535
Michal Kaziorfcf98442015-03-31 11:03:47 +00005536 scan_time_msec = ar->hw->wiphy->max_remain_on_channel_duration * 2;
Michal Kaziordcca0bd2014-11-24 14:58:32 +01005537
Kalle Valo5e3dd152013-06-12 20:52:10 +03005538 memset(&arg, 0, sizeof(arg));
5539 ath10k_wmi_start_scan_init(ar, &arg);
5540 arg.vdev_id = arvif->vdev_id;
5541 arg.scan_id = ATH10K_SCAN_ID;
5542 arg.n_channels = 1;
5543 arg.channels[0] = chan->center_freq;
Michal Kaziorfcf98442015-03-31 11:03:47 +00005544 arg.dwell_time_active = scan_time_msec;
5545 arg.dwell_time_passive = scan_time_msec;
5546 arg.max_scan_time = scan_time_msec;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005547 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
5548 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
Michal Kaziordbd3f9f2015-03-31 11:03:48 +00005549 arg.burst_duration_ms = duration;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005550
5551 ret = ath10k_start_scan(ar, &arg);
5552 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005553 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005554 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005555 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005556 spin_unlock_bh(&ar->data_lock);
5557 goto exit;
5558 }
5559
5560 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
5561 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005562 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005563
5564 ret = ath10k_scan_stop(ar);
5565 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005566 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005567
Kalle Valo5e3dd152013-06-12 20:52:10 +03005568 ret = -ETIMEDOUT;
5569 goto exit;
5570 }
5571
Michal Kaziorfcf98442015-03-31 11:03:47 +00005572 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
5573 msecs_to_jiffies(duration));
5574
Kalle Valo5e3dd152013-06-12 20:52:10 +03005575 ret = 0;
5576exit:
5577 mutex_unlock(&ar->conf_mutex);
5578 return ret;
5579}
5580
5581static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
5582{
5583 struct ath10k *ar = hw->priv;
5584
5585 mutex_lock(&ar->conf_mutex);
Michal Kaziord710e752015-07-09 13:08:36 +02005586
5587 spin_lock_bh(&ar->data_lock);
5588 ar->scan.roc_notify = false;
5589 spin_unlock_bh(&ar->data_lock);
5590
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005591 ath10k_scan_abort(ar);
Michal Kaziord710e752015-07-09 13:08:36 +02005592
Kalle Valo5e3dd152013-06-12 20:52:10 +03005593 mutex_unlock(&ar->conf_mutex);
5594
Michal Kazior4eb2e162014-10-28 10:23:09 +01005595 cancel_delayed_work_sync(&ar->scan.timeout);
5596
Kalle Valo5e3dd152013-06-12 20:52:10 +03005597 return 0;
5598}
5599
5600/*
5601 * Both RTS and Fragmentation threshold are interface-specific
5602 * in ath10k, but device-specific in mac80211.
5603 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03005604
5605static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
5606{
Kalle Valo5e3dd152013-06-12 20:52:10 +03005607 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03005608 struct ath10k_vif *arvif;
5609 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03005610
Michal Kaziorad088bf2013-10-16 15:44:46 +03005611 mutex_lock(&ar->conf_mutex);
5612 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005613 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03005614 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03005615
Michal Kaziorad088bf2013-10-16 15:44:46 +03005616 ret = ath10k_mac_set_rts(arvif, value);
5617 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005618 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03005619 arvif->vdev_id, ret);
5620 break;
5621 }
5622 }
5623 mutex_unlock(&ar->conf_mutex);
5624
5625 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005626}
5627
Michal Kazior92092fe2015-08-03 11:16:43 +02005628static int ath10k_mac_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
5629{
5630 /* Even though there's a WMI enum for fragmentation threshold no known
5631 * firmware actually implements it. Moreover it is not possible to rely
5632 * frame fragmentation to mac80211 because firmware clears the "more
5633 * fragments" bit in frame control making it impossible for remote
5634 * devices to reassemble frames.
5635 *
5636 * Hence implement a dummy callback just to say fragmentation isn't
5637 * supported. This effectively prevents mac80211 from doing frame
5638 * fragmentation in software.
5639 */
5640 return -EOPNOTSUPP;
5641}
5642
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02005643static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5644 u32 queues, bool drop)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005645{
5646 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02005647 bool skip;
Nicholas Mc Guired4298a32015-06-15 14:46:43 +03005648 long time_left;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005649
5650 /* mac80211 doesn't care if we really xmit queued frames or not
5651 * we'll collect those frames either way if we stop/delete vdevs */
5652 if (drop)
5653 return;
5654
Michal Kazior548db542013-07-05 16:15:15 +03005655 mutex_lock(&ar->conf_mutex);
5656
Michal Kazioraffd3212013-07-16 09:54:35 +02005657 if (ar->state == ATH10K_STATE_WEDGED)
5658 goto skip;
5659
Nicholas Mc Guired4298a32015-06-15 14:46:43 +03005660 time_left = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03005661 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02005662
Michal Kazioredb82362013-07-05 16:15:14 +03005663 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02005664 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03005665 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02005666
Michal Kazior7962b0d2014-10-28 10:34:38 +01005667 skip = (ar->state == ATH10K_STATE_WEDGED) ||
5668 test_bit(ATH10K_FLAG_CRASH_FLUSH,
5669 &ar->dev_flags);
Michal Kazioraffd3212013-07-16 09:54:35 +02005670
5671 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005672 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02005673
Nicholas Mc Guired4298a32015-06-15 14:46:43 +03005674 if (time_left == 0 || skip)
5675 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %ld\n",
5676 skip, ar->state, time_left);
Michal Kazior548db542013-07-05 16:15:15 +03005677
Michal Kazioraffd3212013-07-16 09:54:35 +02005678skip:
Michal Kazior548db542013-07-05 16:15:15 +03005679 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005680}
5681
5682/* TODO: Implement this function properly
5683 * For now it is needed to reply to Probe Requests in IBSS mode.
5684 * Propably we need this information from FW.
5685 */
5686static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
5687{
5688 return 1;
5689}
5690
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005691static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
5692 enum ieee80211_reconfig_type reconfig_type)
Michal Kazioraffd3212013-07-16 09:54:35 +02005693{
5694 struct ath10k *ar = hw->priv;
5695
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005696 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
5697 return;
5698
Michal Kazioraffd3212013-07-16 09:54:35 +02005699 mutex_lock(&ar->conf_mutex);
5700
5701 /* If device failed to restart it will be in a different state, e.g.
5702 * ATH10K_STATE_WEDGED */
5703 if (ar->state == ATH10K_STATE_RESTARTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005704 ath10k_info(ar, "device successfully recovered\n");
Michal Kazioraffd3212013-07-16 09:54:35 +02005705 ar->state = ATH10K_STATE_ON;
Michal Kazior7962b0d2014-10-28 10:34:38 +01005706 ieee80211_wake_queues(ar->hw);
Michal Kazioraffd3212013-07-16 09:54:35 +02005707 }
5708
5709 mutex_unlock(&ar->conf_mutex);
5710}
5711
Michal Kazior2e1dea42013-07-31 10:32:40 +02005712static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
5713 struct survey_info *survey)
5714{
5715 struct ath10k *ar = hw->priv;
5716 struct ieee80211_supported_band *sband;
5717 struct survey_info *ar_survey = &ar->survey[idx];
5718 int ret = 0;
5719
5720 mutex_lock(&ar->conf_mutex);
5721
5722 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
5723 if (sband && idx >= sband->n_channels) {
5724 idx -= sband->n_channels;
5725 sband = NULL;
5726 }
5727
5728 if (!sband)
5729 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
5730
5731 if (!sband || idx >= sband->n_channels) {
5732 ret = -ENOENT;
5733 goto exit;
5734 }
5735
5736 spin_lock_bh(&ar->data_lock);
5737 memcpy(survey, ar_survey, sizeof(*survey));
5738 spin_unlock_bh(&ar->data_lock);
5739
5740 survey->channel = &sband->channels[idx];
5741
Felix Fietkaufa1d4df2014-10-23 17:04:28 +03005742 if (ar->rx_channel == survey->channel)
5743 survey->filled |= SURVEY_INFO_IN_USE;
5744
Michal Kazior2e1dea42013-07-31 10:32:40 +02005745exit:
5746 mutex_unlock(&ar->conf_mutex);
5747 return ret;
5748}
5749
Michal Kazior3ae54222015-03-31 10:49:20 +00005750static bool
5751ath10k_mac_bitrate_mask_has_single_rate(struct ath10k *ar,
5752 enum ieee80211_band band,
5753 const struct cfg80211_bitrate_mask *mask)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005754{
Michal Kazior3ae54222015-03-31 10:49:20 +00005755 int num_rates = 0;
5756 int i;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005757
Michal Kazior3ae54222015-03-31 10:49:20 +00005758 num_rates += hweight32(mask->control[band].legacy);
5759
5760 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++)
5761 num_rates += hweight8(mask->control[band].ht_mcs[i]);
5762
5763 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++)
5764 num_rates += hweight16(mask->control[band].vht_mcs[i]);
5765
5766 return num_rates == 1;
5767}
5768
5769static bool
5770ath10k_mac_bitrate_mask_get_single_nss(struct ath10k *ar,
5771 enum ieee80211_band band,
5772 const struct cfg80211_bitrate_mask *mask,
5773 int *nss)
5774{
5775 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
5776 u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
5777 u8 ht_nss_mask = 0;
5778 u8 vht_nss_mask = 0;
5779 int i;
5780
5781 if (mask->control[band].legacy)
5782 return false;
5783
5784 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
5785 if (mask->control[band].ht_mcs[i] == 0)
5786 continue;
5787 else if (mask->control[band].ht_mcs[i] ==
5788 sband->ht_cap.mcs.rx_mask[i])
5789 ht_nss_mask |= BIT(i);
5790 else
5791 return false;
5792 }
5793
5794 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
5795 if (mask->control[band].vht_mcs[i] == 0)
5796 continue;
5797 else if (mask->control[band].vht_mcs[i] ==
5798 ath10k_mac_get_max_vht_mcs_map(vht_mcs_map, i))
5799 vht_nss_mask |= BIT(i);
5800 else
5801 return false;
5802 }
5803
5804 if (ht_nss_mask != vht_nss_mask)
5805 return false;
5806
5807 if (ht_nss_mask == 0)
5808 return false;
5809
5810 if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask)
5811 return false;
5812
5813 *nss = fls(ht_nss_mask);
5814
5815 return true;
5816}
5817
5818static int
5819ath10k_mac_bitrate_mask_get_single_rate(struct ath10k *ar,
5820 enum ieee80211_band band,
5821 const struct cfg80211_bitrate_mask *mask,
5822 u8 *rate, u8 *nss)
5823{
5824 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
5825 int rate_idx;
5826 int i;
5827 u16 bitrate;
5828 u8 preamble;
5829 u8 hw_rate;
5830
5831 if (hweight32(mask->control[band].legacy) == 1) {
5832 rate_idx = ffs(mask->control[band].legacy) - 1;
5833
5834 hw_rate = sband->bitrates[rate_idx].hw_value;
5835 bitrate = sband->bitrates[rate_idx].bitrate;
5836
5837 if (ath10k_mac_bitrate_is_cck(bitrate))
5838 preamble = WMI_RATE_PREAMBLE_CCK;
5839 else
5840 preamble = WMI_RATE_PREAMBLE_OFDM;
5841
5842 *nss = 1;
5843 *rate = preamble << 6 |
5844 (*nss - 1) << 4 |
5845 hw_rate << 0;
5846
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005847 return 0;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005848 }
5849
Michal Kazior3ae54222015-03-31 10:49:20 +00005850 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
5851 if (hweight8(mask->control[band].ht_mcs[i]) == 1) {
5852 *nss = i + 1;
5853 *rate = WMI_RATE_PREAMBLE_HT << 6 |
5854 (*nss - 1) << 4 |
5855 (ffs(mask->control[band].ht_mcs[i]) - 1);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005856
Michal Kazior3ae54222015-03-31 10:49:20 +00005857 return 0;
5858 }
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005859 }
5860
Michal Kazior3ae54222015-03-31 10:49:20 +00005861 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
5862 if (hweight16(mask->control[band].vht_mcs[i]) == 1) {
5863 *nss = i + 1;
5864 *rate = WMI_RATE_PREAMBLE_VHT << 6 |
5865 (*nss - 1) << 4 |
5866 (ffs(mask->control[band].vht_mcs[i]) - 1);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005867
Michal Kazior3ae54222015-03-31 10:49:20 +00005868 return 0;
5869 }
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005870 }
5871
Michal Kazior3ae54222015-03-31 10:49:20 +00005872 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005873}
5874
Michal Kazior3ae54222015-03-31 10:49:20 +00005875static int ath10k_mac_set_fixed_rate_params(struct ath10k_vif *arvif,
5876 u8 rate, u8 nss, u8 sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005877{
5878 struct ath10k *ar = arvif->ar;
5879 u32 vdev_param;
Michal Kazior3ae54222015-03-31 10:49:20 +00005880 int ret;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005881
Michal Kazior3ae54222015-03-31 10:49:20 +00005882 lockdep_assert_held(&ar->conf_mutex);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005883
Michal Kazior3ae54222015-03-31 10:49:20 +00005884 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac set fixed rate params vdev %i rate 0x%02hhx nss %hhu sgi %hhu\n",
5885 arvif->vdev_id, rate, nss, sgi);
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005886
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005887 vdev_param = ar->wmi.vdev_param->fixed_rate;
Michal Kazior3ae54222015-03-31 10:49:20 +00005888 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, rate);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005889 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005890 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
Michal Kazior3ae54222015-03-31 10:49:20 +00005891 rate, ret);
5892 return ret;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005893 }
5894
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005895 vdev_param = ar->wmi.vdev_param->nss;
Michal Kazior3ae54222015-03-31 10:49:20 +00005896 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, nss);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005897 if (ret) {
Michal Kazior3ae54222015-03-31 10:49:20 +00005898 ath10k_warn(ar, "failed to set nss param %d: %d\n", nss, ret);
5899 return ret;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005900 }
5901
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005902 vdev_param = ar->wmi.vdev_param->sgi;
Michal Kazior3ae54222015-03-31 10:49:20 +00005903 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, sgi);
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005904 if (ret) {
Michal Kazior3ae54222015-03-31 10:49:20 +00005905 ath10k_warn(ar, "failed to set sgi param %d: %d\n", sgi, ret);
5906 return ret;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005907 }
5908
Michal Kazior3ae54222015-03-31 10:49:20 +00005909 return 0;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005910}
5911
Michal Kazior45c9abc2015-04-21 20:42:58 +03005912static bool
5913ath10k_mac_can_set_bitrate_mask(struct ath10k *ar,
5914 enum ieee80211_band band,
5915 const struct cfg80211_bitrate_mask *mask)
5916{
5917 int i;
5918 u16 vht_mcs;
5919
5920 /* Due to firmware limitation in WMI_PEER_ASSOC_CMDID it is impossible
5921 * to express all VHT MCS rate masks. Effectively only the following
5922 * ranges can be used: none, 0-7, 0-8 and 0-9.
5923 */
5924 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
5925 vht_mcs = mask->control[band].vht_mcs[i];
5926
5927 switch (vht_mcs) {
5928 case 0:
5929 case BIT(8) - 1:
5930 case BIT(9) - 1:
5931 case BIT(10) - 1:
5932 break;
5933 default:
5934 ath10k_warn(ar, "refusing bitrate mask with missing 0-7 VHT MCS rates\n");
5935 return false;
5936 }
5937 }
5938
5939 return true;
5940}
5941
5942static void ath10k_mac_set_bitrate_mask_iter(void *data,
5943 struct ieee80211_sta *sta)
5944{
5945 struct ath10k_vif *arvif = data;
5946 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5947 struct ath10k *ar = arvif->ar;
5948
5949 if (arsta->arvif != arvif)
5950 return;
5951
5952 spin_lock_bh(&ar->data_lock);
5953 arsta->changed |= IEEE80211_RC_SUPP_RATES_CHANGED;
5954 spin_unlock_bh(&ar->data_lock);
5955
5956 ieee80211_queue_work(ar->hw, &arsta->update_wk);
5957}
5958
Michal Kazior3ae54222015-03-31 10:49:20 +00005959static int ath10k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw,
5960 struct ieee80211_vif *vif,
5961 const struct cfg80211_bitrate_mask *mask)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005962{
5963 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior500ff9f2015-03-31 10:26:21 +00005964 struct cfg80211_chan_def def;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005965 struct ath10k *ar = arvif->ar;
Michal Kazior500ff9f2015-03-31 10:26:21 +00005966 enum ieee80211_band band;
Michal Kazior45c9abc2015-04-21 20:42:58 +03005967 const u8 *ht_mcs_mask;
5968 const u16 *vht_mcs_mask;
Michal Kazior3ae54222015-03-31 10:49:20 +00005969 u8 rate;
5970 u8 nss;
5971 u8 sgi;
5972 int single_nss;
5973 int ret;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005974
Michal Kazior500ff9f2015-03-31 10:26:21 +00005975 if (ath10k_mac_vif_chan(vif, &def))
5976 return -EPERM;
5977
Michal Kazior500ff9f2015-03-31 10:26:21 +00005978 band = def.chan->band;
Michal Kazior45c9abc2015-04-21 20:42:58 +03005979 ht_mcs_mask = mask->control[band].ht_mcs;
5980 vht_mcs_mask = mask->control[band].vht_mcs;
Michal Kazior500ff9f2015-03-31 10:26:21 +00005981
Michal Kazior3ae54222015-03-31 10:49:20 +00005982 sgi = mask->control[band].gi;
5983 if (sgi == NL80211_TXRATE_FORCE_LGI)
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005984 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005985
Michal Kazior3ae54222015-03-31 10:49:20 +00005986 if (ath10k_mac_bitrate_mask_has_single_rate(ar, band, mask)) {
5987 ret = ath10k_mac_bitrate_mask_get_single_rate(ar, band, mask,
5988 &rate, &nss);
5989 if (ret) {
5990 ath10k_warn(ar, "failed to get single rate for vdev %i: %d\n",
5991 arvif->vdev_id, ret);
5992 return ret;
5993 }
5994 } else if (ath10k_mac_bitrate_mask_get_single_nss(ar, band, mask,
5995 &single_nss)) {
5996 rate = WMI_FIXED_RATE_NONE;
5997 nss = single_nss;
5998 } else {
5999 rate = WMI_FIXED_RATE_NONE;
Michal Kazior45c9abc2015-04-21 20:42:58 +03006000 nss = min(ar->num_rf_chains,
6001 max(ath10k_mac_max_ht_nss(ht_mcs_mask),
6002 ath10k_mac_max_vht_nss(vht_mcs_mask)));
6003
6004 if (!ath10k_mac_can_set_bitrate_mask(ar, band, mask))
6005 return -EINVAL;
6006
6007 mutex_lock(&ar->conf_mutex);
6008
6009 arvif->bitrate_mask = *mask;
6010 ieee80211_iterate_stations_atomic(ar->hw,
6011 ath10k_mac_set_bitrate_mask_iter,
6012 arvif);
6013
6014 mutex_unlock(&ar->conf_mutex);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01006015 }
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01006016
6017 mutex_lock(&ar->conf_mutex);
6018
Michal Kazior3ae54222015-03-31 10:49:20 +00006019 ret = ath10k_mac_set_fixed_rate_params(arvif, rate, nss, sgi);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01006020 if (ret) {
Michal Kazior3ae54222015-03-31 10:49:20 +00006021 ath10k_warn(ar, "failed to set fixed rate params on vdev %i: %d\n",
6022 arvif->vdev_id, ret);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01006023 goto exit;
6024 }
6025
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01006026exit:
6027 mutex_unlock(&ar->conf_mutex);
Michal Kazior3ae54222015-03-31 10:49:20 +00006028
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01006029 return ret;
6030}
6031
Michal Kazior9797feb2014-02-14 14:49:48 +01006032static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
6033 struct ieee80211_vif *vif,
6034 struct ieee80211_sta *sta,
6035 u32 changed)
6036{
6037 struct ath10k *ar = hw->priv;
6038 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
6039 u32 bw, smps;
6040
6041 spin_lock_bh(&ar->data_lock);
6042
Michal Kazior7aa7a722014-08-25 12:09:38 +02006043 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior9797feb2014-02-14 14:49:48 +01006044 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
6045 sta->addr, changed, sta->bandwidth, sta->rx_nss,
6046 sta->smps_mode);
6047
6048 if (changed & IEEE80211_RC_BW_CHANGED) {
6049 bw = WMI_PEER_CHWIDTH_20MHZ;
6050
6051 switch (sta->bandwidth) {
6052 case IEEE80211_STA_RX_BW_20:
6053 bw = WMI_PEER_CHWIDTH_20MHZ;
6054 break;
6055 case IEEE80211_STA_RX_BW_40:
6056 bw = WMI_PEER_CHWIDTH_40MHZ;
6057 break;
6058 case IEEE80211_STA_RX_BW_80:
6059 bw = WMI_PEER_CHWIDTH_80MHZ;
6060 break;
6061 case IEEE80211_STA_RX_BW_160:
Masanari Iidad939be32015-02-27 23:52:31 +09006062 ath10k_warn(ar, "Invalid bandwidth %d in rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02006063 sta->bandwidth, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01006064 bw = WMI_PEER_CHWIDTH_20MHZ;
6065 break;
6066 }
6067
6068 arsta->bw = bw;
6069 }
6070
6071 if (changed & IEEE80211_RC_NSS_CHANGED)
6072 arsta->nss = sta->rx_nss;
6073
6074 if (changed & IEEE80211_RC_SMPS_CHANGED) {
6075 smps = WMI_PEER_SMPS_PS_NONE;
6076
6077 switch (sta->smps_mode) {
6078 case IEEE80211_SMPS_AUTOMATIC:
6079 case IEEE80211_SMPS_OFF:
6080 smps = WMI_PEER_SMPS_PS_NONE;
6081 break;
6082 case IEEE80211_SMPS_STATIC:
6083 smps = WMI_PEER_SMPS_STATIC;
6084 break;
6085 case IEEE80211_SMPS_DYNAMIC:
6086 smps = WMI_PEER_SMPS_DYNAMIC;
6087 break;
6088 case IEEE80211_SMPS_NUM_MODES:
Michal Kazior7aa7a722014-08-25 12:09:38 +02006089 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02006090 sta->smps_mode, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01006091 smps = WMI_PEER_SMPS_PS_NONE;
6092 break;
6093 }
6094
6095 arsta->smps = smps;
6096 }
6097
Michal Kazior9797feb2014-02-14 14:49:48 +01006098 arsta->changed |= changed;
6099
6100 spin_unlock_bh(&ar->data_lock);
6101
6102 ieee80211_queue_work(hw, &arsta->update_wk);
6103}
6104
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02006105static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
6106{
6107 /*
6108 * FIXME: Return 0 for time being. Need to figure out whether FW
6109 * has the API to fetch 64-bit local TSF
6110 */
6111
6112 return 0;
6113}
6114
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02006115static int ath10k_ampdu_action(struct ieee80211_hw *hw,
6116 struct ieee80211_vif *vif,
6117 enum ieee80211_ampdu_mlme_action action,
6118 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
6119 u8 buf_size)
6120{
Michal Kazior7aa7a722014-08-25 12:09:38 +02006121 struct ath10k *ar = hw->priv;
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02006122 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6123
Michal Kazior7aa7a722014-08-25 12:09:38 +02006124 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 +02006125 arvif->vdev_id, sta->addr, tid, action);
6126
6127 switch (action) {
6128 case IEEE80211_AMPDU_RX_START:
6129 case IEEE80211_AMPDU_RX_STOP:
6130 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
6131 * creation/removal. Do we need to verify this?
6132 */
6133 return 0;
6134 case IEEE80211_AMPDU_TX_START:
6135 case IEEE80211_AMPDU_TX_STOP_CONT:
6136 case IEEE80211_AMPDU_TX_STOP_FLUSH:
6137 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
6138 case IEEE80211_AMPDU_TX_OPERATIONAL:
6139 /* Firmware offloads Tx aggregation entirely so deny mac80211
6140 * Tx aggregation requests.
6141 */
6142 return -EOPNOTSUPP;
6143 }
6144
6145 return -EINVAL;
6146}
6147
Michal Kazior500ff9f2015-03-31 10:26:21 +00006148static void
Michal Kaziord7bf4b42015-06-03 12:16:54 +02006149ath10k_mac_update_rx_channel(struct ath10k *ar,
6150 struct ieee80211_chanctx_conf *ctx,
6151 struct ieee80211_vif_chanctx_switch *vifs,
6152 int n_vifs)
Michal Kazior500ff9f2015-03-31 10:26:21 +00006153{
6154 struct cfg80211_chan_def *def = NULL;
6155
6156 /* Both locks are required because ar->rx_channel is modified. This
6157 * allows readers to hold either lock.
6158 */
6159 lockdep_assert_held(&ar->conf_mutex);
6160 lockdep_assert_held(&ar->data_lock);
6161
Michal Kaziord7bf4b42015-06-03 12:16:54 +02006162 WARN_ON(ctx && vifs);
6163 WARN_ON(vifs && n_vifs != 1);
6164
Michal Kazior500ff9f2015-03-31 10:26:21 +00006165 /* FIXME: Sort of an optimization and a workaround. Peers and vifs are
6166 * on a linked list now. Doing a lookup peer -> vif -> chanctx for each
6167 * ppdu on Rx may reduce performance on low-end systems. It should be
6168 * possible to make tables/hashmaps to speed the lookup up (be vary of
6169 * cpu data cache lines though regarding sizes) but to keep the initial
6170 * implementation simple and less intrusive fallback to the slow lookup
6171 * only for multi-channel cases. Single-channel cases will remain to
6172 * use the old channel derival and thus performance should not be
6173 * affected much.
6174 */
6175 rcu_read_lock();
Michal Kaziord7bf4b42015-06-03 12:16:54 +02006176 if (!ctx && ath10k_mac_num_chanctxs(ar) == 1) {
Michal Kazior500ff9f2015-03-31 10:26:21 +00006177 ieee80211_iter_chan_contexts_atomic(ar->hw,
6178 ath10k_mac_get_any_chandef_iter,
6179 &def);
Michal Kaziord7bf4b42015-06-03 12:16:54 +02006180
6181 if (vifs)
6182 def = &vifs[0].new_ctx->def;
6183
Michal Kazior500ff9f2015-03-31 10:26:21 +00006184 ar->rx_channel = def->chan;
Michal Kaziord7bf4b42015-06-03 12:16:54 +02006185 } else if (ctx && ath10k_mac_num_chanctxs(ar) == 0) {
6186 ar->rx_channel = ctx->def.chan;
Michal Kazior500ff9f2015-03-31 10:26:21 +00006187 } else {
6188 ar->rx_channel = NULL;
6189 }
6190 rcu_read_unlock();
6191}
6192
Michal Kazior500ff9f2015-03-31 10:26:21 +00006193static int
6194ath10k_mac_op_add_chanctx(struct ieee80211_hw *hw,
6195 struct ieee80211_chanctx_conf *ctx)
6196{
6197 struct ath10k *ar = hw->priv;
Michal Kazior500ff9f2015-03-31 10:26:21 +00006198
6199 ath10k_dbg(ar, ATH10K_DBG_MAC,
6200 "mac chanctx add freq %hu width %d ptr %p\n",
6201 ctx->def.chan->center_freq, ctx->def.width, ctx);
6202
6203 mutex_lock(&ar->conf_mutex);
6204
6205 spin_lock_bh(&ar->data_lock);
Michal Kaziord7bf4b42015-06-03 12:16:54 +02006206 ath10k_mac_update_rx_channel(ar, ctx, NULL, 0);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006207 spin_unlock_bh(&ar->data_lock);
6208
6209 ath10k_recalc_radar_detection(ar);
6210 ath10k_monitor_recalc(ar);
6211
6212 mutex_unlock(&ar->conf_mutex);
6213
6214 return 0;
6215}
6216
6217static void
6218ath10k_mac_op_remove_chanctx(struct ieee80211_hw *hw,
6219 struct ieee80211_chanctx_conf *ctx)
6220{
6221 struct ath10k *ar = hw->priv;
6222
6223 ath10k_dbg(ar, ATH10K_DBG_MAC,
6224 "mac chanctx remove freq %hu width %d ptr %p\n",
6225 ctx->def.chan->center_freq, ctx->def.width, ctx);
6226
6227 mutex_lock(&ar->conf_mutex);
6228
6229 spin_lock_bh(&ar->data_lock);
Michal Kaziord7bf4b42015-06-03 12:16:54 +02006230 ath10k_mac_update_rx_channel(ar, NULL, NULL, 0);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006231 spin_unlock_bh(&ar->data_lock);
6232
6233 ath10k_recalc_radar_detection(ar);
6234 ath10k_monitor_recalc(ar);
6235
6236 mutex_unlock(&ar->conf_mutex);
6237}
6238
6239static void
6240ath10k_mac_op_change_chanctx(struct ieee80211_hw *hw,
6241 struct ieee80211_chanctx_conf *ctx,
6242 u32 changed)
6243{
6244 struct ath10k *ar = hw->priv;
Michal Kazior500ff9f2015-03-31 10:26:21 +00006245
6246 mutex_lock(&ar->conf_mutex);
6247
6248 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior089ab7a2015-06-03 12:16:55 +02006249 "mac chanctx change freq %hu width %d ptr %p changed %x\n",
6250 ctx->def.chan->center_freq, ctx->def.width, ctx, changed);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006251
6252 /* This shouldn't really happen because channel switching should use
6253 * switch_vif_chanctx().
6254 */
6255 if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL))
6256 goto unlock;
6257
Michal Kazior500ff9f2015-03-31 10:26:21 +00006258 ath10k_recalc_radar_detection(ar);
6259
6260 /* FIXME: How to configure Rx chains properly? */
6261
6262 /* No other actions are actually necessary. Firmware maintains channel
6263 * definitions per vdev internally and there's no host-side channel
6264 * context abstraction to configure, e.g. channel width.
6265 */
6266
6267unlock:
6268 mutex_unlock(&ar->conf_mutex);
6269}
6270
6271static int
6272ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
6273 struct ieee80211_vif *vif,
6274 struct ieee80211_chanctx_conf *ctx)
6275{
6276 struct ath10k *ar = hw->priv;
Michal Kazior500ff9f2015-03-31 10:26:21 +00006277 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6278 int ret;
6279
6280 mutex_lock(&ar->conf_mutex);
6281
6282 ath10k_dbg(ar, ATH10K_DBG_MAC,
6283 "mac chanctx assign ptr %p vdev_id %i\n",
6284 ctx, arvif->vdev_id);
6285
6286 if (WARN_ON(arvif->is_started)) {
6287 mutex_unlock(&ar->conf_mutex);
6288 return -EBUSY;
6289 }
6290
Michal Kazior089ab7a2015-06-03 12:16:55 +02006291 ret = ath10k_vdev_start(arvif, &ctx->def);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006292 if (ret) {
6293 ath10k_warn(ar, "failed to start vdev %i addr %pM on freq %d: %d\n",
6294 arvif->vdev_id, vif->addr,
Michal Kazior089ab7a2015-06-03 12:16:55 +02006295 ctx->def.chan->center_freq, ret);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006296 goto err;
6297 }
6298
6299 arvif->is_started = true;
6300
Michal Kaziorf23e587e2015-07-09 13:08:37 +02006301 ret = ath10k_mac_vif_setup_ps(arvif);
6302 if (ret) {
6303 ath10k_warn(ar, "failed to update vdev %i ps: %d\n",
6304 arvif->vdev_id, ret);
6305 goto err_stop;
6306 }
6307
Michal Kazior500ff9f2015-03-31 10:26:21 +00006308 if (vif->type == NL80211_IFTYPE_MONITOR) {
6309 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, 0, vif->addr);
6310 if (ret) {
6311 ath10k_warn(ar, "failed to up monitor vdev %i: %d\n",
6312 arvif->vdev_id, ret);
6313 goto err_stop;
6314 }
6315
6316 arvif->is_up = true;
6317 }
6318
6319 mutex_unlock(&ar->conf_mutex);
6320 return 0;
6321
6322err_stop:
6323 ath10k_vdev_stop(arvif);
6324 arvif->is_started = false;
Michal Kaziorf23e587e2015-07-09 13:08:37 +02006325 ath10k_mac_vif_setup_ps(arvif);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006326
6327err:
6328 mutex_unlock(&ar->conf_mutex);
6329 return ret;
6330}
6331
6332static void
6333ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
6334 struct ieee80211_vif *vif,
6335 struct ieee80211_chanctx_conf *ctx)
6336{
6337 struct ath10k *ar = hw->priv;
6338 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6339 int ret;
6340
6341 mutex_lock(&ar->conf_mutex);
6342
6343 ath10k_dbg(ar, ATH10K_DBG_MAC,
6344 "mac chanctx unassign ptr %p vdev_id %i\n",
6345 ctx, arvif->vdev_id);
6346
6347 WARN_ON(!arvif->is_started);
6348
6349 if (vif->type == NL80211_IFTYPE_MONITOR) {
6350 WARN_ON(!arvif->is_up);
6351
6352 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
6353 if (ret)
6354 ath10k_warn(ar, "failed to down monitor vdev %i: %d\n",
6355 arvif->vdev_id, ret);
6356
6357 arvif->is_up = false;
6358 }
6359
6360 ret = ath10k_vdev_stop(arvif);
6361 if (ret)
6362 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
6363 arvif->vdev_id, ret);
6364
6365 arvif->is_started = false;
6366
6367 mutex_unlock(&ar->conf_mutex);
6368}
6369
6370static int
6371ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw,
6372 struct ieee80211_vif_chanctx_switch *vifs,
6373 int n_vifs,
6374 enum ieee80211_chanctx_switch_mode mode)
6375{
6376 struct ath10k *ar = hw->priv;
6377 struct ath10k_vif *arvif;
Michal Kazior0e6eb412015-06-03 12:16:56 +02006378 int ret;
Michal Kazior500ff9f2015-03-31 10:26:21 +00006379 int i;
6380
6381 mutex_lock(&ar->conf_mutex);
6382
6383 ath10k_dbg(ar, ATH10K_DBG_MAC,
6384 "mac chanctx switch n_vifs %d mode %d\n",
6385 n_vifs, mode);
6386
Michal Kazior0e6eb412015-06-03 12:16:56 +02006387 /* First stop monitor interface. Some FW versions crash if there's a
6388 * lone monitor interface.
6389 */
6390 if (ar->monitor_started)
6391 ath10k_monitor_stop(ar);
6392
Michal Kazior500ff9f2015-03-31 10:26:21 +00006393 for (i = 0; i < n_vifs; i++) {
6394 arvif = ath10k_vif_to_arvif(vifs[i].vif);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006395
6396 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior089ab7a2015-06-03 12:16:55 +02006397 "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d\n",
Michal Kazior500ff9f2015-03-31 10:26:21 +00006398 arvif->vdev_id,
6399 vifs[i].old_ctx->def.chan->center_freq,
6400 vifs[i].new_ctx->def.chan->center_freq,
6401 vifs[i].old_ctx->def.width,
Michal Kazior089ab7a2015-06-03 12:16:55 +02006402 vifs[i].new_ctx->def.width);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006403
Michal Kazior0e6eb412015-06-03 12:16:56 +02006404 if (WARN_ON(!arvif->is_started))
6405 continue;
6406
6407 if (WARN_ON(!arvif->is_up))
6408 continue;
6409
6410 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
6411 if (ret) {
6412 ath10k_warn(ar, "failed to down vdev %d: %d\n",
6413 arvif->vdev_id, ret);
6414 continue;
Michal Kazior500ff9f2015-03-31 10:26:21 +00006415 }
Michal Kazior500ff9f2015-03-31 10:26:21 +00006416 }
Michal Kazior0e6eb412015-06-03 12:16:56 +02006417
6418 /* All relevant vdevs are downed and associated channel resources
6419 * should be available for the channel switch now.
6420 */
6421
6422 spin_lock_bh(&ar->data_lock);
Michal Kaziord7bf4b42015-06-03 12:16:54 +02006423 ath10k_mac_update_rx_channel(ar, NULL, vifs, n_vifs);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006424 spin_unlock_bh(&ar->data_lock);
6425
Michal Kazior0e6eb412015-06-03 12:16:56 +02006426 for (i = 0; i < n_vifs; i++) {
6427 arvif = ath10k_vif_to_arvif(vifs[i].vif);
6428
6429 if (WARN_ON(!arvif->is_started))
6430 continue;
6431
6432 if (WARN_ON(!arvif->is_up))
6433 continue;
6434
6435 ret = ath10k_mac_setup_bcn_tmpl(arvif);
6436 if (ret)
6437 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
6438 ret);
6439
6440 ret = ath10k_mac_setup_prb_tmpl(arvif);
6441 if (ret)
6442 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
6443 ret);
6444
6445 ret = ath10k_vdev_restart(arvif, &vifs[i].new_ctx->def);
6446 if (ret) {
6447 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
6448 arvif->vdev_id, ret);
6449 continue;
6450 }
6451
6452 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
6453 arvif->bssid);
6454 if (ret) {
6455 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
6456 arvif->vdev_id, ret);
6457 continue;
6458 }
6459 }
6460
6461 ath10k_monitor_recalc(ar);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006462
6463 mutex_unlock(&ar->conf_mutex);
6464 return 0;
6465}
6466
Kalle Valo5e3dd152013-06-12 20:52:10 +03006467static const struct ieee80211_ops ath10k_ops = {
6468 .tx = ath10k_tx,
6469 .start = ath10k_start,
6470 .stop = ath10k_stop,
6471 .config = ath10k_config,
6472 .add_interface = ath10k_add_interface,
6473 .remove_interface = ath10k_remove_interface,
6474 .configure_filter = ath10k_configure_filter,
6475 .bss_info_changed = ath10k_bss_info_changed,
6476 .hw_scan = ath10k_hw_scan,
6477 .cancel_hw_scan = ath10k_cancel_hw_scan,
6478 .set_key = ath10k_set_key,
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02006479 .set_default_unicast_key = ath10k_set_default_unicast_key,
Kalle Valo5e3dd152013-06-12 20:52:10 +03006480 .sta_state = ath10k_sta_state,
6481 .conf_tx = ath10k_conf_tx,
6482 .remain_on_channel = ath10k_remain_on_channel,
6483 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
6484 .set_rts_threshold = ath10k_set_rts_threshold,
Michal Kazior92092fe2015-08-03 11:16:43 +02006485 .set_frag_threshold = ath10k_mac_op_set_frag_threshold,
Kalle Valo5e3dd152013-06-12 20:52:10 +03006486 .flush = ath10k_flush,
6487 .tx_last_beacon = ath10k_tx_last_beacon,
Ben Greear46acf7b2014-05-16 17:15:38 +03006488 .set_antenna = ath10k_set_antenna,
6489 .get_antenna = ath10k_get_antenna,
Eliad Pellercf2c92d2014-11-04 11:43:54 +02006490 .reconfig_complete = ath10k_reconfig_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02006491 .get_survey = ath10k_get_survey,
Michal Kazior3ae54222015-03-31 10:49:20 +00006492 .set_bitrate_mask = ath10k_mac_op_set_bitrate_mask,
Michal Kazior9797feb2014-02-14 14:49:48 +01006493 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02006494 .get_tsf = ath10k_get_tsf,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02006495 .ampdu_action = ath10k_ampdu_action,
Ben Greear6cddcc72014-09-29 14:41:46 +03006496 .get_et_sset_count = ath10k_debug_get_et_sset_count,
6497 .get_et_stats = ath10k_debug_get_et_stats,
6498 .get_et_strings = ath10k_debug_get_et_strings,
Michal Kazior500ff9f2015-03-31 10:26:21 +00006499 .add_chanctx = ath10k_mac_op_add_chanctx,
6500 .remove_chanctx = ath10k_mac_op_remove_chanctx,
6501 .change_chanctx = ath10k_mac_op_change_chanctx,
6502 .assign_vif_chanctx = ath10k_mac_op_assign_vif_chanctx,
6503 .unassign_vif_chanctx = ath10k_mac_op_unassign_vif_chanctx,
6504 .switch_vif_chanctx = ath10k_mac_op_switch_vif_chanctx,
Kalle Valo43d2a302014-09-10 18:23:30 +03006505
6506 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
6507
Michal Kazior8cd13ca2013-07-16 09:38:54 +02006508#ifdef CONFIG_PM
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +02006509 .suspend = ath10k_wow_op_suspend,
6510 .resume = ath10k_wow_op_resume,
Michal Kazior8cd13ca2013-07-16 09:38:54 +02006511#endif
Rajkumar Manoharanf5045982015-01-12 14:07:27 +02006512#ifdef CONFIG_MAC80211_DEBUGFS
6513 .sta_add_debugfs = ath10k_sta_add_debugfs,
6514#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03006515};
6516
Kalle Valo5e3dd152013-06-12 20:52:10 +03006517#define CHAN2G(_channel, _freq, _flags) { \
6518 .band = IEEE80211_BAND_2GHZ, \
6519 .hw_value = (_channel), \
6520 .center_freq = (_freq), \
6521 .flags = (_flags), \
6522 .max_antenna_gain = 0, \
6523 .max_power = 30, \
6524}
6525
6526#define CHAN5G(_channel, _freq, _flags) { \
6527 .band = IEEE80211_BAND_5GHZ, \
6528 .hw_value = (_channel), \
6529 .center_freq = (_freq), \
6530 .flags = (_flags), \
6531 .max_antenna_gain = 0, \
6532 .max_power = 30, \
6533}
6534
6535static const struct ieee80211_channel ath10k_2ghz_channels[] = {
6536 CHAN2G(1, 2412, 0),
6537 CHAN2G(2, 2417, 0),
6538 CHAN2G(3, 2422, 0),
6539 CHAN2G(4, 2427, 0),
6540 CHAN2G(5, 2432, 0),
6541 CHAN2G(6, 2437, 0),
6542 CHAN2G(7, 2442, 0),
6543 CHAN2G(8, 2447, 0),
6544 CHAN2G(9, 2452, 0),
6545 CHAN2G(10, 2457, 0),
6546 CHAN2G(11, 2462, 0),
6547 CHAN2G(12, 2467, 0),
6548 CHAN2G(13, 2472, 0),
6549 CHAN2G(14, 2484, 0),
6550};
6551
6552static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02006553 CHAN5G(36, 5180, 0),
6554 CHAN5G(40, 5200, 0),
6555 CHAN5G(44, 5220, 0),
6556 CHAN5G(48, 5240, 0),
6557 CHAN5G(52, 5260, 0),
6558 CHAN5G(56, 5280, 0),
6559 CHAN5G(60, 5300, 0),
6560 CHAN5G(64, 5320, 0),
6561 CHAN5G(100, 5500, 0),
6562 CHAN5G(104, 5520, 0),
6563 CHAN5G(108, 5540, 0),
6564 CHAN5G(112, 5560, 0),
6565 CHAN5G(116, 5580, 0),
6566 CHAN5G(120, 5600, 0),
6567 CHAN5G(124, 5620, 0),
6568 CHAN5G(128, 5640, 0),
6569 CHAN5G(132, 5660, 0),
6570 CHAN5G(136, 5680, 0),
6571 CHAN5G(140, 5700, 0),
Peter Oh4a7898f2015-03-18 11:39:18 -07006572 CHAN5G(144, 5720, 0),
Michal Kazior429ff562013-06-26 08:54:54 +02006573 CHAN5G(149, 5745, 0),
6574 CHAN5G(153, 5765, 0),
6575 CHAN5G(157, 5785, 0),
6576 CHAN5G(161, 5805, 0),
6577 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03006578};
6579
Michal Kaziore7b54192014-08-07 11:03:27 +02006580struct ath10k *ath10k_mac_create(size_t priv_size)
Kalle Valo5e3dd152013-06-12 20:52:10 +03006581{
6582 struct ieee80211_hw *hw;
6583 struct ath10k *ar;
6584
Michal Kaziore7b54192014-08-07 11:03:27 +02006585 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006586 if (!hw)
6587 return NULL;
6588
6589 ar = hw->priv;
6590 ar->hw = hw;
6591
6592 return ar;
6593}
6594
6595void ath10k_mac_destroy(struct ath10k *ar)
6596{
6597 ieee80211_free_hw(ar->hw);
6598}
6599
6600static const struct ieee80211_iface_limit ath10k_if_limits[] = {
6601 {
6602 .max = 8,
6603 .types = BIT(NL80211_IFTYPE_STATION)
6604 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02006605 },
6606 {
6607 .max = 3,
6608 .types = BIT(NL80211_IFTYPE_P2P_GO)
6609 },
6610 {
Michal Kazior75d2bd42014-12-12 12:41:39 +01006611 .max = 1,
6612 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
6613 },
6614 {
Michal Kaziord531cb82013-07-31 10:55:13 +02006615 .max = 7,
6616 .types = BIT(NL80211_IFTYPE_AP)
6617 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03006618};
6619
Bartosz Markowskif2595092013-12-10 16:20:39 +01006620static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006621 {
6622 .max = 8,
6623 .types = BIT(NL80211_IFTYPE_AP)
6624 },
6625};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006626
6627static const struct ieee80211_iface_combination ath10k_if_comb[] = {
6628 {
6629 .limits = ath10k_if_limits,
6630 .n_limits = ARRAY_SIZE(ath10k_if_limits),
6631 .max_interfaces = 8,
6632 .num_different_channels = 1,
6633 .beacon_int_infra_match = true,
6634 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01006635};
6636
6637static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006638 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01006639 .limits = ath10k_10x_if_limits,
6640 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006641 .max_interfaces = 8,
6642 .num_different_channels = 1,
6643 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01006644#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006645 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
6646 BIT(NL80211_CHAN_WIDTH_20) |
6647 BIT(NL80211_CHAN_WIDTH_40) |
6648 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006649#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01006650 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03006651};
6652
Michal Kaziorcf327842015-03-31 10:26:25 +00006653static const struct ieee80211_iface_limit ath10k_tlv_if_limit[] = {
6654 {
6655 .max = 2,
Michal Kaziored25b112015-07-09 13:08:39 +02006656 .types = BIT(NL80211_IFTYPE_STATION),
6657 },
6658 {
6659 .max = 2,
6660 .types = BIT(NL80211_IFTYPE_AP) |
Michal Kaziorcf327842015-03-31 10:26:25 +00006661 BIT(NL80211_IFTYPE_P2P_CLIENT) |
6662 BIT(NL80211_IFTYPE_P2P_GO),
6663 },
6664 {
6665 .max = 1,
6666 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
6667 },
6668};
6669
Michal Kaziored25b112015-07-09 13:08:39 +02006670static const struct ieee80211_iface_limit ath10k_tlv_qcs_if_limit[] = {
6671 {
6672 .max = 2,
6673 .types = BIT(NL80211_IFTYPE_STATION),
6674 },
6675 {
6676 .max = 2,
6677 .types = BIT(NL80211_IFTYPE_P2P_CLIENT),
6678 },
6679 {
6680 .max = 1,
6681 .types = BIT(NL80211_IFTYPE_AP) |
6682 BIT(NL80211_IFTYPE_P2P_GO),
6683 },
6684 {
6685 .max = 1,
6686 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
6687 },
6688};
6689
Michal Kaziorcf327842015-03-31 10:26:25 +00006690static const struct ieee80211_iface_limit ath10k_tlv_if_limit_ibss[] = {
6691 {
6692 .max = 1,
6693 .types = BIT(NL80211_IFTYPE_STATION),
6694 },
6695 {
6696 .max = 1,
6697 .types = BIT(NL80211_IFTYPE_ADHOC),
6698 },
6699};
6700
6701/* FIXME: This is not thouroughly tested. These combinations may over- or
6702 * underestimate hw/fw capabilities.
6703 */
6704static struct ieee80211_iface_combination ath10k_tlv_if_comb[] = {
6705 {
6706 .limits = ath10k_tlv_if_limit,
6707 .num_different_channels = 1,
Michal Kaziored25b112015-07-09 13:08:39 +02006708 .max_interfaces = 4,
Michal Kaziorcf327842015-03-31 10:26:25 +00006709 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
6710 },
6711 {
6712 .limits = ath10k_tlv_if_limit_ibss,
6713 .num_different_channels = 1,
6714 .max_interfaces = 2,
6715 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
6716 },
6717};
6718
6719static struct ieee80211_iface_combination ath10k_tlv_qcs_if_comb[] = {
6720 {
6721 .limits = ath10k_tlv_if_limit,
Michal Kaziored25b112015-07-09 13:08:39 +02006722 .num_different_channels = 1,
6723 .max_interfaces = 4,
Michal Kaziorcf327842015-03-31 10:26:25 +00006724 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
6725 },
6726 {
Michal Kaziored25b112015-07-09 13:08:39 +02006727 .limits = ath10k_tlv_qcs_if_limit,
6728 .num_different_channels = 2,
6729 .max_interfaces = 4,
6730 .n_limits = ARRAY_SIZE(ath10k_tlv_qcs_if_limit),
6731 },
6732 {
Michal Kaziorcf327842015-03-31 10:26:25 +00006733 .limits = ath10k_tlv_if_limit_ibss,
6734 .num_different_channels = 1,
6735 .max_interfaces = 2,
6736 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
6737 },
6738};
6739
Raja Manicf36fef2015-06-22 20:22:25 +05306740static const struct ieee80211_iface_limit ath10k_10_4_if_limits[] = {
6741 {
6742 .max = 1,
6743 .types = BIT(NL80211_IFTYPE_STATION),
6744 },
6745 {
6746 .max = 16,
6747 .types = BIT(NL80211_IFTYPE_AP)
6748 },
6749};
6750
6751static const struct ieee80211_iface_combination ath10k_10_4_if_comb[] = {
6752 {
6753 .limits = ath10k_10_4_if_limits,
6754 .n_limits = ARRAY_SIZE(ath10k_10_4_if_limits),
6755 .max_interfaces = 16,
6756 .num_different_channels = 1,
6757 .beacon_int_infra_match = true,
6758#ifdef CONFIG_ATH10K_DFS_CERTIFIED
6759 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
6760 BIT(NL80211_CHAN_WIDTH_20) |
6761 BIT(NL80211_CHAN_WIDTH_40) |
6762 BIT(NL80211_CHAN_WIDTH_80),
6763#endif
6764 },
6765};
6766
Kalle Valo5e3dd152013-06-12 20:52:10 +03006767static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
6768{
6769 struct ieee80211_sta_vht_cap vht_cap = {0};
6770 u16 mcs_map;
Michal Kaziorbc657a362015-02-26 11:11:22 +01006771 u32 val;
Michal Kazior8865bee42013-07-24 12:36:46 +02006772 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006773
6774 vht_cap.vht_supported = 1;
6775 vht_cap.cap = ar->vht_cap_info;
6776
Michal Kaziorbc657a362015-02-26 11:11:22 +01006777 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
6778 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
6779 val = ar->num_rf_chains - 1;
6780 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
6781 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
6782
6783 vht_cap.cap |= val;
6784 }
6785
6786 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
6787 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
6788 val = ar->num_rf_chains - 1;
6789 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
6790 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
6791
6792 vht_cap.cap |= val;
6793 }
6794
Michal Kazior8865bee42013-07-24 12:36:46 +02006795 mcs_map = 0;
6796 for (i = 0; i < 8; i++) {
6797 if (i < ar->num_rf_chains)
6798 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
6799 else
6800 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
6801 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03006802
6803 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
6804 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
6805
6806 return vht_cap;
6807}
6808
6809static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
6810{
6811 int i;
6812 struct ieee80211_sta_ht_cap ht_cap = {0};
6813
6814 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
6815 return ht_cap;
6816
6817 ht_cap.ht_supported = 1;
6818 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
6819 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
6820 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
6821 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
6822 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
6823
6824 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
6825 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
6826
6827 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
6828 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
6829
6830 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
6831 u32 smps;
6832
6833 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
6834 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
6835
6836 ht_cap.cap |= smps;
6837 }
6838
6839 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
6840 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
6841
6842 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
6843 u32 stbc;
6844
6845 stbc = ar->ht_cap_info;
6846 stbc &= WMI_HT_CAP_RX_STBC;
6847 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
6848 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
6849 stbc &= IEEE80211_HT_CAP_RX_STBC;
6850
6851 ht_cap.cap |= stbc;
6852 }
6853
6854 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
6855 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
6856
6857 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
6858 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
6859
6860 /* max AMSDU is implicitly taken from vht_cap_info */
6861 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
6862 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
6863
Michal Kazior8865bee42013-07-24 12:36:46 +02006864 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03006865 ht_cap.mcs.rx_mask[i] = 0xFF;
6866
6867 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
6868
6869 return ht_cap;
6870}
6871
Kalle Valo5e3dd152013-06-12 20:52:10 +03006872static void ath10k_get_arvif_iter(void *data, u8 *mac,
6873 struct ieee80211_vif *vif)
6874{
6875 struct ath10k_vif_iter *arvif_iter = data;
6876 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6877
6878 if (arvif->vdev_id == arvif_iter->vdev_id)
6879 arvif_iter->arvif = arvif;
6880}
6881
6882struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
6883{
6884 struct ath10k_vif_iter arvif_iter;
6885 u32 flags;
6886
6887 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
6888 arvif_iter.vdev_id = vdev_id;
6889
6890 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
6891 ieee80211_iterate_active_interfaces_atomic(ar->hw,
6892 flags,
6893 ath10k_get_arvif_iter,
6894 &arvif_iter);
6895 if (!arvif_iter.arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02006896 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006897 return NULL;
6898 }
6899
6900 return arvif_iter.arvif;
6901}
6902
6903int ath10k_mac_register(struct ath10k *ar)
6904{
Johannes Berg3cb10942015-01-22 21:38:45 +01006905 static const u32 cipher_suites[] = {
6906 WLAN_CIPHER_SUITE_WEP40,
6907 WLAN_CIPHER_SUITE_WEP104,
6908 WLAN_CIPHER_SUITE_TKIP,
6909 WLAN_CIPHER_SUITE_CCMP,
6910 WLAN_CIPHER_SUITE_AES_CMAC,
6911 };
Kalle Valo5e3dd152013-06-12 20:52:10 +03006912 struct ieee80211_supported_band *band;
6913 struct ieee80211_sta_vht_cap vht_cap;
6914 struct ieee80211_sta_ht_cap ht_cap;
6915 void *channels;
6916 int ret;
6917
6918 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
6919
6920 SET_IEEE80211_DEV(ar->hw, ar->dev);
6921
6922 ht_cap = ath10k_get_ht_cap(ar);
6923 vht_cap = ath10k_create_vht_cap(ar);
6924
Michal Kaziorc94aa7e2015-03-24 12:38:11 +00006925 BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels) +
6926 ARRAY_SIZE(ath10k_5ghz_channels)) !=
6927 ATH10K_NUM_CHANS);
6928
Kalle Valo5e3dd152013-06-12 20:52:10 +03006929 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
6930 channels = kmemdup(ath10k_2ghz_channels,
6931 sizeof(ath10k_2ghz_channels),
6932 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02006933 if (!channels) {
6934 ret = -ENOMEM;
6935 goto err_free;
6936 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03006937
6938 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
6939 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
6940 band->channels = channels;
6941 band->n_bitrates = ath10k_g_rates_size;
6942 band->bitrates = ath10k_g_rates;
6943 band->ht_cap = ht_cap;
6944
Yanbo Lid68bb122015-01-23 08:18:20 +08006945 /* Enable the VHT support at 2.4 GHz */
6946 band->vht_cap = vht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006947
6948 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
6949 }
6950
6951 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
6952 channels = kmemdup(ath10k_5ghz_channels,
6953 sizeof(ath10k_5ghz_channels),
6954 GFP_KERNEL);
6955 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02006956 ret = -ENOMEM;
6957 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006958 }
6959
6960 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
6961 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
6962 band->channels = channels;
6963 band->n_bitrates = ath10k_a_rates_size;
6964 band->bitrates = ath10k_a_rates;
6965 band->ht_cap = ht_cap;
6966 band->vht_cap = vht_cap;
6967 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
6968 }
6969
6970 ar->hw->wiphy->interface_modes =
6971 BIT(NL80211_IFTYPE_STATION) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01006972 BIT(NL80211_IFTYPE_AP);
6973
Ben Greear46acf7b2014-05-16 17:15:38 +03006974 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
6975 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
6976
Bartosz Markowskid3541812013-12-10 16:20:40 +01006977 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
6978 ar->hw->wiphy->interface_modes |=
Michal Kazior75d2bd42014-12-12 12:41:39 +01006979 BIT(NL80211_IFTYPE_P2P_DEVICE) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01006980 BIT(NL80211_IFTYPE_P2P_CLIENT) |
6981 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006982
Johannes Berg30686bf2015-06-02 21:39:54 +02006983 ieee80211_hw_set(ar->hw, SIGNAL_DBM);
6984 ieee80211_hw_set(ar->hw, SUPPORTS_PS);
6985 ieee80211_hw_set(ar->hw, SUPPORTS_DYNAMIC_PS);
6986 ieee80211_hw_set(ar->hw, MFP_CAPABLE);
6987 ieee80211_hw_set(ar->hw, REPORTS_TX_ACK_STATUS);
6988 ieee80211_hw_set(ar->hw, HAS_RATE_CONTROL);
6989 ieee80211_hw_set(ar->hw, AP_LINK_PS);
6990 ieee80211_hw_set(ar->hw, SPECTRUM_MGMT);
Johannes Berg30686bf2015-06-02 21:39:54 +02006991 ieee80211_hw_set(ar->hw, SUPPORT_FAST_XMIT);
6992 ieee80211_hw_set(ar->hw, CONNECTION_MONITOR);
6993 ieee80211_hw_set(ar->hw, SUPPORTS_PER_STA_GTK);
6994 ieee80211_hw_set(ar->hw, WANT_MONITOR_VIF);
6995 ieee80211_hw_set(ar->hw, CHANCTX_STA_CSA);
6996 ieee80211_hw_set(ar->hw, QUEUE_CONTROL);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006997
David Liuccec9032015-07-24 20:25:32 +03006998 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
6999 ieee80211_hw_set(ar->hw, SW_CRYPTO_CONTROL);
7000
Eliad Peller0d8614b2014-09-10 14:07:36 +03007001 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
Janusz Dziedzic0cd9bc12015-04-10 13:23:23 +00007002 ar->hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
Eliad Peller0d8614b2014-09-10 14:07:36 +03007003
Kalle Valo5e3dd152013-06-12 20:52:10 +03007004 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
Eliad Peller0d8614b2014-09-10 14:07:36 +03007005 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03007006
7007 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
Johannes Berg30686bf2015-06-02 21:39:54 +02007008 ieee80211_hw_set(ar->hw, AMPDU_AGGREGATION);
7009 ieee80211_hw_set(ar->hw, TX_AMPDU_SETUP_IN_HW);
Kalle Valo5e3dd152013-06-12 20:52:10 +03007010 }
7011
7012 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
7013 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
7014
7015 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01007016 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03007017
Kalle Valo5e3dd152013-06-12 20:52:10 +03007018 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
7019
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02007020 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
7021 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
7022
7023 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
7024 * that userspace (e.g. wpa_supplicant/hostapd) can generate
7025 * correct Probe Responses. This is more of a hack advert..
7026 */
7027 ar->hw->wiphy->probe_resp_offload |=
7028 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
7029 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
7030 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
7031 }
7032
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03007033 if (test_bit(WMI_SERVICE_TDLS, ar->wmi.svc_map))
7034 ar->hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
7035
Kalle Valo5e3dd152013-06-12 20:52:10 +03007036 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01007037 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03007038 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
7039
7040 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
Rajkumar Manoharan78157a12014-11-17 16:44:15 +02007041 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
7042
Janusz.Dziedzic@tieto.com37a0b392015-03-12 13:11:41 +01007043 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
7044
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +02007045 ret = ath10k_wow_init(ar);
7046 if (ret) {
7047 ath10k_warn(ar, "failed to init wow: %d\n", ret);
7048 goto err_free;
7049 }
7050
Janusz Dziedzicc7025342015-06-15 14:46:41 +03007051 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
7052
Kalle Valo5e3dd152013-06-12 20:52:10 +03007053 /*
7054 * on LL hardware queues are managed entirely by the FW
7055 * so we only advertise to mac we can do the queues thing
7056 */
Michal Kazior96d828d2015-03-31 10:26:23 +00007057 ar->hw->queues = IEEE80211_MAX_QUEUES;
7058
7059 /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is
7060 * something that vdev_ids can't reach so that we don't stop the queue
7061 * accidentally.
7062 */
7063 ar->hw->offchannel_tx_hw_queue = IEEE80211_MAX_QUEUES - 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03007064
Kalle Valo5cc7caf2014-12-17 12:20:54 +02007065 switch (ar->wmi.op_version) {
7066 case ATH10K_FW_WMI_OP_VERSION_MAIN:
Bartosz Markowskif2595092013-12-10 16:20:39 +01007067 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
7068 ar->hw->wiphy->n_iface_combinations =
7069 ARRAY_SIZE(ath10k_if_comb);
Michal Kaziorcf850d12014-07-24 20:07:00 +03007070 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
Kalle Valo5cc7caf2014-12-17 12:20:54 +02007071 break;
Michal Kaziorcf327842015-03-31 10:26:25 +00007072 case ATH10K_FW_WMI_OP_VERSION_TLV:
7073 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
7074 ar->hw->wiphy->iface_combinations =
7075 ath10k_tlv_qcs_if_comb;
7076 ar->hw->wiphy->n_iface_combinations =
7077 ARRAY_SIZE(ath10k_tlv_qcs_if_comb);
7078 } else {
7079 ar->hw->wiphy->iface_combinations = ath10k_tlv_if_comb;
7080 ar->hw->wiphy->n_iface_combinations =
7081 ARRAY_SIZE(ath10k_tlv_if_comb);
7082 }
7083 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
7084 break;
Kalle Valo5cc7caf2014-12-17 12:20:54 +02007085 case ATH10K_FW_WMI_OP_VERSION_10_1:
7086 case ATH10K_FW_WMI_OP_VERSION_10_2:
Rajkumar Manoharan4a16fbe2014-12-17 12:21:12 +02007087 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
Kalle Valo5cc7caf2014-12-17 12:20:54 +02007088 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
7089 ar->hw->wiphy->n_iface_combinations =
7090 ARRAY_SIZE(ath10k_10x_if_comb);
7091 break;
Raja Mani9bd21322015-06-22 20:10:09 +05307092 case ATH10K_FW_WMI_OP_VERSION_10_4:
Raja Manicf36fef2015-06-22 20:22:25 +05307093 ar->hw->wiphy->iface_combinations = ath10k_10_4_if_comb;
7094 ar->hw->wiphy->n_iface_combinations =
7095 ARRAY_SIZE(ath10k_10_4_if_comb);
Raja Mani9bd21322015-06-22 20:10:09 +05307096 break;
Kalle Valo5cc7caf2014-12-17 12:20:54 +02007097 case ATH10K_FW_WMI_OP_VERSION_UNSET:
7098 case ATH10K_FW_WMI_OP_VERSION_MAX:
7099 WARN_ON(1);
7100 ret = -EINVAL;
7101 goto err_free;
Bartosz Markowskif2595092013-12-10 16:20:39 +01007102 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03007103
David Liuccec9032015-07-24 20:25:32 +03007104 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
7105 ar->hw->netdev_features = NETIF_F_HW_CSUM;
Michal Kazior7c199992013-07-31 10:47:57 +02007106
Janusz Dziedzic9702c682013-11-20 09:59:41 +02007107 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
7108 /* Init ath dfs pattern detector */
7109 ar->ath_common.debug_mask = ATH_DBG_DFS;
7110 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
7111 NL80211_DFS_UNSET);
7112
7113 if (!ar->dfs_detector)
Michal Kazior7aa7a722014-08-25 12:09:38 +02007114 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02007115 }
7116
Kalle Valo5e3dd152013-06-12 20:52:10 +03007117 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
7118 ath10k_reg_notifier);
7119 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02007120 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02007121 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03007122 }
7123
Johannes Berg3cb10942015-01-22 21:38:45 +01007124 ar->hw->wiphy->cipher_suites = cipher_suites;
7125 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
7126
Kalle Valo5e3dd152013-06-12 20:52:10 +03007127 ret = ieee80211_register_hw(ar->hw);
7128 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02007129 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02007130 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03007131 }
7132
7133 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
7134 ret = regulatory_hint(ar->hw->wiphy,
7135 ar->ath_common.regulatory.alpha2);
7136 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02007137 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03007138 }
7139
7140 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02007141
7142err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03007143 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02007144err_free:
7145 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
7146 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
7147
Kalle Valo5e3dd152013-06-12 20:52:10 +03007148 return ret;
7149}
7150
7151void ath10k_mac_unregister(struct ath10k *ar)
7152{
7153 ieee80211_unregister_hw(ar->hw);
7154
Janusz Dziedzic9702c682013-11-20 09:59:41 +02007155 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
7156 ar->dfs_detector->exit(ar->dfs_detector);
7157
Kalle Valo5e3dd152013-06-12 20:52:10 +03007158 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
7159 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
7160
7161 SET_IEEE80211_DEV(ar->hw, NULL);
7162}