blob: acd222f3b89950557effac8170c811b6c7c78c1d [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{
601 int ret;
602
603 lockdep_assert_held(&ar->conf_mutex);
604
Michal Kaziorcfd10612014-11-25 15:16:05 +0100605 if (ar->num_peers >= ar->max_num_peers)
606 return -ENOBUFS;
607
Marek Puzyniak7390ed32015-03-30 09:51:52 +0300608 ret = ath10k_wmi_peer_create(ar, vdev_id, addr, peer_type);
Ben Greear479398b2013-11-04 09:19:34 -0800609 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200610 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200611 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300612 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800613 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300614
615 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800616 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200617 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200618 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300619 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800620 }
Michal Kazior292a7532014-11-25 15:16:04 +0100621
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100622 ar->num_peers++;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300623
624 return 0;
625}
626
Kalle Valo5a13e762014-01-20 11:01:46 +0200627static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
628{
629 struct ath10k *ar = arvif->ar;
630 u32 param;
631 int ret;
632
633 param = ar->wmi.pdev_param->sta_kickout_th;
634 ret = ath10k_wmi_pdev_set_param(ar, param,
635 ATH10K_KICKOUT_THRESHOLD);
636 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200637 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200638 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200639 return ret;
640 }
641
642 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
643 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
644 ATH10K_KEEPALIVE_MIN_IDLE);
645 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200646 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200647 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200648 return ret;
649 }
650
651 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
652 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
653 ATH10K_KEEPALIVE_MAX_IDLE);
654 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200655 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200656 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200657 return ret;
658 }
659
660 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
661 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
662 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
663 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200664 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200665 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200666 return ret;
667 }
668
669 return 0;
670}
671
Vivek Natarajanacab6402014-11-26 09:06:12 +0200672static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
Michal Kazior424121c2013-07-22 14:13:31 +0200673{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200674 struct ath10k *ar = arvif->ar;
675 u32 vdev_param;
676
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200677 vdev_param = ar->wmi.vdev_param->rts_threshold;
678 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200679}
680
681static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
682{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200683 struct ath10k *ar = arvif->ar;
684 u32 vdev_param;
685
Michal Kazior424121c2013-07-22 14:13:31 +0200686 if (value != 0xFFFFFFFF)
687 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
688 ATH10K_FRAGMT_THRESHOLD_MIN,
689 ATH10K_FRAGMT_THRESHOLD_MAX);
690
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200691 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
692 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200693}
694
Kalle Valo5e3dd152013-06-12 20:52:10 +0300695static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
696{
697 int ret;
698
699 lockdep_assert_held(&ar->conf_mutex);
700
701 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
702 if (ret)
703 return ret;
704
705 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
706 if (ret)
707 return ret;
708
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100709 ar->num_peers--;
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100710
Kalle Valo5e3dd152013-06-12 20:52:10 +0300711 return 0;
712}
713
714static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
715{
716 struct ath10k_peer *peer, *tmp;
717
718 lockdep_assert_held(&ar->conf_mutex);
719
720 spin_lock_bh(&ar->data_lock);
721 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
722 if (peer->vdev_id != vdev_id)
723 continue;
724
Michal Kazior7aa7a722014-08-25 12:09:38 +0200725 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300726 peer->addr, vdev_id);
727
728 list_del(&peer->list);
729 kfree(peer);
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100730 ar->num_peers--;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300731 }
732 spin_unlock_bh(&ar->data_lock);
733}
734
Michal Kaziora96d7742013-07-16 09:38:56 +0200735static void ath10k_peer_cleanup_all(struct ath10k *ar)
736{
737 struct ath10k_peer *peer, *tmp;
738
739 lockdep_assert_held(&ar->conf_mutex);
740
741 spin_lock_bh(&ar->data_lock);
742 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
743 list_del(&peer->list);
744 kfree(peer);
745 }
746 spin_unlock_bh(&ar->data_lock);
Michal Kazior292a7532014-11-25 15:16:04 +0100747
748 ar->num_peers = 0;
Michal Kaziorcfd10612014-11-25 15:16:05 +0100749 ar->num_stations = 0;
Michal Kaziora96d7742013-07-16 09:38:56 +0200750}
751
Marek Puzyniak75d85fd2015-03-30 09:51:53 +0300752static int ath10k_mac_tdls_peer_update(struct ath10k *ar, u32 vdev_id,
753 struct ieee80211_sta *sta,
754 enum wmi_tdls_peer_state state)
755{
756 int ret;
757 struct wmi_tdls_peer_update_cmd_arg arg = {};
758 struct wmi_tdls_peer_capab_arg cap = {};
759 struct wmi_channel_arg chan_arg = {};
760
761 lockdep_assert_held(&ar->conf_mutex);
762
763 arg.vdev_id = vdev_id;
764 arg.peer_state = state;
765 ether_addr_copy(arg.addr, sta->addr);
766
767 cap.peer_max_sp = sta->max_sp;
768 cap.peer_uapsd_queues = sta->uapsd_queues;
769
770 if (state == WMI_TDLS_PEER_STATE_CONNECTED &&
771 !sta->tdls_initiator)
772 cap.is_peer_responder = 1;
773
774 ret = ath10k_wmi_tdls_peer_update(ar, &arg, &cap, &chan_arg);
775 if (ret) {
776 ath10k_warn(ar, "failed to update tdls peer %pM on vdev %i: %i\n",
777 arg.addr, vdev_id, ret);
778 return ret;
779 }
780
781 return 0;
782}
783
Kalle Valo5e3dd152013-06-12 20:52:10 +0300784/************************/
785/* Interface management */
786/************************/
787
Michal Kazior64badcb2014-09-18 11:18:02 +0300788void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
789{
790 struct ath10k *ar = arvif->ar;
791
792 lockdep_assert_held(&ar->data_lock);
793
794 if (!arvif->beacon)
795 return;
796
797 if (!arvif->beacon_buf)
798 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
799 arvif->beacon->len, DMA_TO_DEVICE);
800
Michal Kazioraf213192015-01-29 14:29:52 +0200801 if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED &&
802 arvif->beacon_state != ATH10K_BEACON_SENT))
803 return;
804
Michal Kazior64badcb2014-09-18 11:18:02 +0300805 dev_kfree_skb_any(arvif->beacon);
806
807 arvif->beacon = NULL;
Michal Kazioraf213192015-01-29 14:29:52 +0200808 arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
Michal Kazior64badcb2014-09-18 11:18:02 +0300809}
810
811static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
812{
813 struct ath10k *ar = arvif->ar;
814
815 lockdep_assert_held(&ar->data_lock);
816
817 ath10k_mac_vif_beacon_free(arvif);
818
819 if (arvif->beacon_buf) {
820 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
821 arvif->beacon_buf, arvif->beacon_paddr);
822 arvif->beacon_buf = NULL;
823 }
824}
825
Kalle Valo5e3dd152013-06-12 20:52:10 +0300826static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
827{
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +0300828 unsigned long time_left;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300829
Michal Kazior548db542013-07-05 16:15:15 +0300830 lockdep_assert_held(&ar->conf_mutex);
831
Michal Kazior7962b0d2014-10-28 10:34:38 +0100832 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
833 return -ESHUTDOWN;
834
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +0300835 time_left = wait_for_completion_timeout(&ar->vdev_setup_done,
836 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
837 if (time_left == 0)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300838 return -ETIMEDOUT;
839
840 return 0;
841}
842
Michal Kazior1bbc0972014-04-08 09:45:47 +0300843static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300844{
Michal Kazior500ff9f2015-03-31 10:26:21 +0000845 struct cfg80211_chan_def *chandef = NULL;
Maninder Singh19be9e92015-07-16 09:25:33 +0530846 struct ieee80211_channel *channel = NULL;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300847 struct wmi_vdev_start_request_arg arg = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +0300848 int ret = 0;
849
850 lockdep_assert_held(&ar->conf_mutex);
851
Michal Kazior500ff9f2015-03-31 10:26:21 +0000852 ieee80211_iter_chan_contexts_atomic(ar->hw,
853 ath10k_mac_get_any_chandef_iter,
854 &chandef);
855 if (WARN_ON_ONCE(!chandef))
856 return -ENOENT;
857
858 channel = chandef->chan;
859
Kalle Valo5e3dd152013-06-12 20:52:10 +0300860 arg.vdev_id = vdev_id;
861 arg.channel.freq = channel->center_freq;
Michal Kaziorc930f742014-01-23 11:38:25 +0100862 arg.channel.band_center_freq1 = chandef->center_freq1;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300863
864 /* TODO setup this dynamically, what in case we
865 don't have any vifs? */
Michal Kaziorc930f742014-01-23 11:38:25 +0100866 arg.channel.mode = chan_to_phymode(chandef);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200867 arg.channel.chan_radar =
868 !!(channel->flags & IEEE80211_CHAN_RADAR);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300869
Michal Kazior89c5c842013-10-23 04:02:13 -0700870 arg.channel.min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -0700871 arg.channel.max_power = channel->max_power * 2;
872 arg.channel.max_reg_power = channel->max_reg_power * 2;
873 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300874
Michal Kazior7962b0d2014-10-28 10:34:38 +0100875 reinit_completion(&ar->vdev_setup_done);
876
Kalle Valo5e3dd152013-06-12 20:52:10 +0300877 ret = ath10k_wmi_vdev_start(ar, &arg);
878 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200879 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200880 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300881 return ret;
882 }
883
884 ret = ath10k_vdev_setup_sync(ar);
885 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +0200886 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200887 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300888 return ret;
889 }
890
891 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
892 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200893 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200894 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300895 goto vdev_stop;
896 }
897
898 ar->monitor_vdev_id = vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300899
Michal Kazior7aa7a722014-08-25 12:09:38 +0200900 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300901 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300902 return 0;
903
904vdev_stop:
905 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
906 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200907 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200908 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300909
910 return ret;
911}
912
Michal Kazior1bbc0972014-04-08 09:45:47 +0300913static int ath10k_monitor_vdev_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300914{
915 int ret = 0;
916
917 lockdep_assert_held(&ar->conf_mutex);
918
Marek Puzyniak52fa0192013-09-24 14:06:24 +0200919 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
920 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200921 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200922 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300923
Michal Kazior7962b0d2014-10-28 10:34:38 +0100924 reinit_completion(&ar->vdev_setup_done);
925
Kalle Valo5e3dd152013-06-12 20:52:10 +0300926 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
927 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200928 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200929 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300930
931 ret = ath10k_vdev_setup_sync(ar);
932 if (ret)
Ben Greear60028a82015-02-15 16:50:39 +0200933 ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200934 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300935
Michal Kazior7aa7a722014-08-25 12:09:38 +0200936 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300937 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300938 return ret;
939}
940
Michal Kazior1bbc0972014-04-08 09:45:47 +0300941static int ath10k_monitor_vdev_create(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300942{
943 int bit, ret = 0;
944
945 lockdep_assert_held(&ar->conf_mutex);
946
Ben Greeara9aefb32014-08-12 11:02:19 +0300947 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200948 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +0300949 return -ENOMEM;
950 }
951
Ben Greear16c11172014-09-23 14:17:16 -0700952 bit = __ffs64(ar->free_vdev_map);
Ben Greeara9aefb32014-08-12 11:02:19 +0300953
Ben Greear16c11172014-09-23 14:17:16 -0700954 ar->monitor_vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300955
956 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
957 WMI_VDEV_TYPE_MONITOR,
958 0, ar->mac_addr);
959 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200960 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200961 ar->monitor_vdev_id, ret);
Ben Greeara9aefb32014-08-12 11:02:19 +0300962 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300963 }
964
Ben Greear16c11172014-09-23 14:17:16 -0700965 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
Michal Kazior7aa7a722014-08-25 12:09:38 +0200966 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300967 ar->monitor_vdev_id);
968
Kalle Valo5e3dd152013-06-12 20:52:10 +0300969 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300970}
971
Michal Kazior1bbc0972014-04-08 09:45:47 +0300972static int ath10k_monitor_vdev_delete(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300973{
974 int ret = 0;
975
976 lockdep_assert_held(&ar->conf_mutex);
977
Kalle Valo5e3dd152013-06-12 20:52:10 +0300978 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
979 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200980 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200981 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300982 return ret;
983 }
984
Ben Greear16c11172014-09-23 14:17:16 -0700985 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300986
Michal Kazior7aa7a722014-08-25 12:09:38 +0200987 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300988 ar->monitor_vdev_id);
989 return ret;
990}
991
Michal Kazior1bbc0972014-04-08 09:45:47 +0300992static int ath10k_monitor_start(struct ath10k *ar)
993{
994 int ret;
995
996 lockdep_assert_held(&ar->conf_mutex);
997
Michal Kazior1bbc0972014-04-08 09:45:47 +0300998 ret = ath10k_monitor_vdev_create(ar);
999 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001000 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +03001001 return ret;
1002 }
1003
1004 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
1005 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001006 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +03001007 ath10k_monitor_vdev_delete(ar);
1008 return ret;
1009 }
1010
1011 ar->monitor_started = true;
Michal Kazior7aa7a722014-08-25 12:09:38 +02001012 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
Michal Kazior1bbc0972014-04-08 09:45:47 +03001013
1014 return 0;
1015}
1016
Michal Kazior19337472014-08-28 12:58:16 +02001017static int ath10k_monitor_stop(struct ath10k *ar)
Michal Kazior1bbc0972014-04-08 09:45:47 +03001018{
1019 int ret;
1020
1021 lockdep_assert_held(&ar->conf_mutex);
1022
Michal Kazior1bbc0972014-04-08 09:45:47 +03001023 ret = ath10k_monitor_vdev_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +02001024 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001025 ath10k_warn(ar, "failed to stop 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 ret = ath10k_monitor_vdev_delete(ar);
Michal Kazior19337472014-08-28 12:58:16 +02001030 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001031 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +02001032 return ret;
1033 }
Michal Kazior1bbc0972014-04-08 09:45:47 +03001034
1035 ar->monitor_started = false;
Michal Kazior7aa7a722014-08-25 12:09:38 +02001036 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
Michal Kazior19337472014-08-28 12:58:16 +02001037
1038 return 0;
1039}
1040
Michal Kazior500ff9f2015-03-31 10:26:21 +00001041static bool ath10k_mac_monitor_vdev_is_needed(struct ath10k *ar)
1042{
1043 int num_ctx;
1044
1045 /* At least one chanctx is required to derive a channel to start
1046 * monitor vdev on.
1047 */
1048 num_ctx = ath10k_mac_num_chanctxs(ar);
1049 if (num_ctx == 0)
1050 return false;
1051
1052 /* If there's already an existing special monitor interface then don't
1053 * bother creating another monitor vdev.
1054 */
1055 if (ar->monitor_arvif)
1056 return false;
1057
1058 return ar->monitor ||
Michal Kazior500ff9f2015-03-31 10:26:21 +00001059 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1060}
1061
1062static bool ath10k_mac_monitor_vdev_is_allowed(struct ath10k *ar)
1063{
1064 int num_ctx;
1065
1066 num_ctx = ath10k_mac_num_chanctxs(ar);
1067
1068 /* FIXME: Current interface combinations and cfg80211/mac80211 code
1069 * shouldn't allow this but make sure to prevent handling the following
1070 * case anyway since multi-channel DFS hasn't been tested at all.
1071 */
1072 if (test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags) && num_ctx > 1)
1073 return false;
1074
1075 return true;
1076}
1077
Michal Kazior19337472014-08-28 12:58:16 +02001078static int ath10k_monitor_recalc(struct ath10k *ar)
1079{
Michal Kazior500ff9f2015-03-31 10:26:21 +00001080 bool needed;
1081 bool allowed;
1082 int ret;
Michal Kazior19337472014-08-28 12:58:16 +02001083
1084 lockdep_assert_held(&ar->conf_mutex);
1085
Michal Kazior500ff9f2015-03-31 10:26:21 +00001086 needed = ath10k_mac_monitor_vdev_is_needed(ar);
1087 allowed = ath10k_mac_monitor_vdev_is_allowed(ar);
Michal Kazior19337472014-08-28 12:58:16 +02001088
1089 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior500ff9f2015-03-31 10:26:21 +00001090 "mac monitor recalc started? %d needed? %d allowed? %d\n",
1091 ar->monitor_started, needed, allowed);
Michal Kazior19337472014-08-28 12:58:16 +02001092
Michal Kazior500ff9f2015-03-31 10:26:21 +00001093 if (WARN_ON(needed && !allowed)) {
1094 if (ar->monitor_started) {
1095 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopping disallowed monitor\n");
1096
1097 ret = ath10k_monitor_stop(ar);
1098 if (ret)
1099 ath10k_warn(ar, "failed to stop disallowed monitor: %d\n", ret);
1100 /* not serious */
1101 }
1102
1103 return -EPERM;
1104 }
1105
1106 if (needed == ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02001107 return 0;
1108
Michal Kazior500ff9f2015-03-31 10:26:21 +00001109 if (needed)
Michal Kazior19337472014-08-28 12:58:16 +02001110 return ath10k_monitor_start(ar);
Michal Kazior500ff9f2015-03-31 10:26:21 +00001111 else
1112 return ath10k_monitor_stop(ar);
Michal Kazior1bbc0972014-04-08 09:45:47 +03001113}
1114
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001115static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
1116{
1117 struct ath10k *ar = arvif->ar;
1118 u32 vdev_param, rts_cts = 0;
1119
1120 lockdep_assert_held(&ar->conf_mutex);
1121
1122 vdev_param = ar->wmi.vdev_param->enable_rtscts;
1123
Rajkumar Manoharan9a5ab0f2015-03-19 16:03:29 +02001124 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001125
1126 if (arvif->num_legacy_stations > 0)
1127 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
1128 WMI_RTSCTS_PROFILE);
Rajkumar Manoharan9a5ab0f2015-03-19 16:03:29 +02001129 else
1130 rts_cts |= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES,
1131 WMI_RTSCTS_PROFILE);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001132
1133 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
1134 rts_cts);
1135}
1136
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001137static int ath10k_start_cac(struct ath10k *ar)
1138{
1139 int ret;
1140
1141 lockdep_assert_held(&ar->conf_mutex);
1142
1143 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1144
Michal Kazior19337472014-08-28 12:58:16 +02001145 ret = ath10k_monitor_recalc(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001146 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001147 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001148 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1149 return ret;
1150 }
1151
Michal Kazior7aa7a722014-08-25 12:09:38 +02001152 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001153 ar->monitor_vdev_id);
1154
1155 return 0;
1156}
1157
1158static int ath10k_stop_cac(struct ath10k *ar)
1159{
1160 lockdep_assert_held(&ar->conf_mutex);
1161
1162 /* CAC is not running - do nothing */
1163 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
1164 return 0;
1165
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001166 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
Michal Kazior1bbc0972014-04-08 09:45:47 +03001167 ath10k_monitor_stop(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001168
Michal Kazior7aa7a722014-08-25 12:09:38 +02001169 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001170
1171 return 0;
1172}
1173
Michal Kazior500ff9f2015-03-31 10:26:21 +00001174static void ath10k_mac_has_radar_iter(struct ieee80211_hw *hw,
1175 struct ieee80211_chanctx_conf *conf,
1176 void *data)
1177{
1178 bool *ret = data;
1179
1180 if (!*ret && conf->radar_enabled)
1181 *ret = true;
1182}
1183
1184static bool ath10k_mac_has_radar_enabled(struct ath10k *ar)
1185{
1186 bool has_radar = false;
1187
1188 ieee80211_iter_chan_contexts_atomic(ar->hw,
1189 ath10k_mac_has_radar_iter,
1190 &has_radar);
1191
1192 return has_radar;
1193}
1194
Michal Kaziord6500972014-04-08 09:56:09 +03001195static void ath10k_recalc_radar_detection(struct ath10k *ar)
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001196{
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001197 int ret;
1198
1199 lockdep_assert_held(&ar->conf_mutex);
1200
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001201 ath10k_stop_cac(ar);
1202
Michal Kazior500ff9f2015-03-31 10:26:21 +00001203 if (!ath10k_mac_has_radar_enabled(ar))
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001204 return;
1205
Michal Kaziord6500972014-04-08 09:56:09 +03001206 if (ar->num_started_vdevs > 0)
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001207 return;
1208
1209 ret = ath10k_start_cac(ar);
1210 if (ret) {
1211 /*
1212 * Not possible to start CAC on current channel so starting
1213 * radiation is not allowed, make this channel DFS_UNAVAILABLE
1214 * by indicating that radar was detected.
1215 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02001216 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001217 ieee80211_radar_detected(ar->hw);
1218 }
1219}
1220
Vasanthakumar Thiagarajan822b7e02015-03-02 17:45:27 +05301221static int ath10k_vdev_stop(struct ath10k_vif *arvif)
Michal Kazior72654fa2014-04-08 09:56:09 +03001222{
1223 struct ath10k *ar = arvif->ar;
Vasanthakumar Thiagarajan822b7e02015-03-02 17:45:27 +05301224 int ret;
1225
1226 lockdep_assert_held(&ar->conf_mutex);
1227
1228 reinit_completion(&ar->vdev_setup_done);
1229
1230 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
1231 if (ret) {
1232 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
1233 arvif->vdev_id, ret);
1234 return ret;
1235 }
1236
1237 ret = ath10k_vdev_setup_sync(ar);
1238 if (ret) {
1239 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
1240 arvif->vdev_id, ret);
1241 return ret;
1242 }
1243
1244 WARN_ON(ar->num_started_vdevs == 0);
1245
1246 if (ar->num_started_vdevs != 0) {
1247 ar->num_started_vdevs--;
1248 ath10k_recalc_radar_detection(ar);
1249 }
1250
1251 return ret;
1252}
1253
Michal Kazior500ff9f2015-03-31 10:26:21 +00001254static int ath10k_vdev_start_restart(struct ath10k_vif *arvif,
1255 const struct cfg80211_chan_def *chandef,
1256 bool restart)
Michal Kazior72654fa2014-04-08 09:56:09 +03001257{
1258 struct ath10k *ar = arvif->ar;
Michal Kazior72654fa2014-04-08 09:56:09 +03001259 struct wmi_vdev_start_request_arg arg = {};
1260 int ret = 0;
1261
1262 lockdep_assert_held(&ar->conf_mutex);
1263
1264 reinit_completion(&ar->vdev_setup_done);
1265
1266 arg.vdev_id = arvif->vdev_id;
1267 arg.dtim_period = arvif->dtim_period;
1268 arg.bcn_intval = arvif->beacon_interval;
1269
1270 arg.channel.freq = chandef->chan->center_freq;
1271 arg.channel.band_center_freq1 = chandef->center_freq1;
1272 arg.channel.mode = chan_to_phymode(chandef);
1273
1274 arg.channel.min_power = 0;
1275 arg.channel.max_power = chandef->chan->max_power * 2;
1276 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
1277 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
1278
1279 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1280 arg.ssid = arvif->u.ap.ssid;
1281 arg.ssid_len = arvif->u.ap.ssid_len;
1282 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
1283
1284 /* For now allow DFS for AP mode */
1285 arg.channel.chan_radar =
1286 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
1287 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
1288 arg.ssid = arvif->vif->bss_conf.ssid;
1289 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
1290 }
1291
Michal Kazior7aa7a722014-08-25 12:09:38 +02001292 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior72654fa2014-04-08 09:56:09 +03001293 "mac vdev %d start center_freq %d phymode %s\n",
1294 arg.vdev_id, arg.channel.freq,
1295 ath10k_wmi_phymode_str(arg.channel.mode));
1296
Michal Kaziordc55e302014-07-29 12:53:36 +03001297 if (restart)
1298 ret = ath10k_wmi_vdev_restart(ar, &arg);
1299 else
1300 ret = ath10k_wmi_vdev_start(ar, &arg);
1301
Michal Kazior72654fa2014-04-08 09:56:09 +03001302 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001303 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +03001304 arg.vdev_id, ret);
1305 return ret;
1306 }
1307
1308 ret = ath10k_vdev_setup_sync(ar);
1309 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +02001310 ath10k_warn(ar,
1311 "failed to synchronize setup for vdev %i restart %d: %d\n",
1312 arg.vdev_id, restart, ret);
Michal Kazior72654fa2014-04-08 09:56:09 +03001313 return ret;
1314 }
1315
Michal Kaziord6500972014-04-08 09:56:09 +03001316 ar->num_started_vdevs++;
1317 ath10k_recalc_radar_detection(ar);
1318
Michal Kazior72654fa2014-04-08 09:56:09 +03001319 return ret;
1320}
1321
Michal Kazior500ff9f2015-03-31 10:26:21 +00001322static int ath10k_vdev_start(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, false);
Michal Kaziordc55e302014-07-29 12:53:36 +03001326}
1327
Michal Kazior500ff9f2015-03-31 10:26:21 +00001328static int ath10k_vdev_restart(struct ath10k_vif *arvif,
1329 const struct cfg80211_chan_def *def)
Michal Kaziordc55e302014-07-29 12:53:36 +03001330{
Michal Kazior500ff9f2015-03-31 10:26:21 +00001331 return ath10k_vdev_start_restart(arvif, def, true);
Michal Kazior72654fa2014-04-08 09:56:09 +03001332}
1333
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001334static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
1335 struct sk_buff *bcn)
1336{
1337 struct ath10k *ar = arvif->ar;
1338 struct ieee80211_mgmt *mgmt;
1339 const u8 *p2p_ie;
1340 int ret;
1341
1342 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1343 return 0;
1344
1345 if (arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1346 return 0;
1347
1348 mgmt = (void *)bcn->data;
1349 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1350 mgmt->u.beacon.variable,
1351 bcn->len - (mgmt->u.beacon.variable -
1352 bcn->data));
1353 if (!p2p_ie)
1354 return -ENOENT;
1355
1356 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1357 if (ret) {
1358 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1359 arvif->vdev_id, ret);
1360 return ret;
1361 }
1362
1363 return 0;
1364}
1365
1366static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1367 u8 oui_type, size_t ie_offset)
1368{
1369 size_t len;
1370 const u8 *next;
1371 const u8 *end;
1372 u8 *ie;
1373
1374 if (WARN_ON(skb->len < ie_offset))
1375 return -EINVAL;
1376
1377 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1378 skb->data + ie_offset,
1379 skb->len - ie_offset);
1380 if (!ie)
1381 return -ENOENT;
1382
1383 len = ie[1] + 2;
1384 end = skb->data + skb->len;
1385 next = ie + len;
1386
1387 if (WARN_ON(next > end))
1388 return -EINVAL;
1389
1390 memmove(ie, next, end - next);
1391 skb_trim(skb, skb->len - len);
1392
1393 return 0;
1394}
1395
1396static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1397{
1398 struct ath10k *ar = arvif->ar;
1399 struct ieee80211_hw *hw = ar->hw;
1400 struct ieee80211_vif *vif = arvif->vif;
1401 struct ieee80211_mutable_offsets offs = {};
1402 struct sk_buff *bcn;
1403 int ret;
1404
1405 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1406 return 0;
1407
Michal Kazior81a9a172015-03-05 16:02:17 +02001408 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
1409 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
1410 return 0;
1411
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001412 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1413 if (!bcn) {
1414 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1415 return -EPERM;
1416 }
1417
1418 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1419 if (ret) {
1420 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1421 kfree_skb(bcn);
1422 return ret;
1423 }
1424
1425 /* P2P IE is inserted by firmware automatically (as configured above)
1426 * so remove it from the base beacon template to avoid duplicate P2P
1427 * IEs in beacon frames.
1428 */
1429 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1430 offsetof(struct ieee80211_mgmt,
1431 u.beacon.variable));
1432
1433 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1434 0, NULL, 0);
1435 kfree_skb(bcn);
1436
1437 if (ret) {
1438 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1439 ret);
1440 return ret;
1441 }
1442
1443 return 0;
1444}
1445
1446static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1447{
1448 struct ath10k *ar = arvif->ar;
1449 struct ieee80211_hw *hw = ar->hw;
1450 struct ieee80211_vif *vif = arvif->vif;
1451 struct sk_buff *prb;
1452 int ret;
1453
1454 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1455 return 0;
1456
Michal Kazior81a9a172015-03-05 16:02:17 +02001457 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1458 return 0;
1459
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001460 prb = ieee80211_proberesp_get(hw, vif);
1461 if (!prb) {
1462 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1463 return -EPERM;
1464 }
1465
1466 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1467 kfree_skb(prb);
1468
1469 if (ret) {
1470 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1471 ret);
1472 return ret;
1473 }
1474
1475 return 0;
1476}
1477
Michal Kazior500ff9f2015-03-31 10:26:21 +00001478static int ath10k_mac_vif_fix_hidden_ssid(struct ath10k_vif *arvif)
1479{
1480 struct ath10k *ar = arvif->ar;
1481 struct cfg80211_chan_def def;
1482 int ret;
1483
1484 /* When originally vdev is started during assign_vif_chanctx() some
1485 * information is missing, notably SSID. Firmware revisions with beacon
1486 * offloading require the SSID to be provided during vdev (re)start to
1487 * handle hidden SSID properly.
1488 *
1489 * Vdev restart must be done after vdev has been both started and
1490 * upped. Otherwise some firmware revisions (at least 10.2) fail to
1491 * deliver vdev restart response event causing timeouts during vdev
1492 * syncing in ath10k.
1493 *
1494 * Note: The vdev down/up and template reinstallation could be skipped
1495 * since only wmi-tlv firmware are known to have beacon offload and
1496 * wmi-tlv doesn't seem to misbehave like 10.2 wrt vdev restart
1497 * response delivery. It's probably more robust to keep it as is.
1498 */
1499 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1500 return 0;
1501
1502 if (WARN_ON(!arvif->is_started))
1503 return -EINVAL;
1504
1505 if (WARN_ON(!arvif->is_up))
1506 return -EINVAL;
1507
1508 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
1509 return -EINVAL;
1510
1511 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1512 if (ret) {
1513 ath10k_warn(ar, "failed to bring down ap vdev %i: %d\n",
1514 arvif->vdev_id, ret);
1515 return ret;
1516 }
1517
1518 /* Vdev down reset beacon & presp templates. Reinstall them. Otherwise
1519 * firmware will crash upon vdev up.
1520 */
1521
1522 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1523 if (ret) {
1524 ath10k_warn(ar, "failed to update beacon template: %d\n", ret);
1525 return ret;
1526 }
1527
1528 ret = ath10k_mac_setup_prb_tmpl(arvif);
1529 if (ret) {
1530 ath10k_warn(ar, "failed to update presp template: %d\n", ret);
1531 return ret;
1532 }
1533
1534 ret = ath10k_vdev_restart(arvif, &def);
1535 if (ret) {
1536 ath10k_warn(ar, "failed to restart ap vdev %i: %d\n",
1537 arvif->vdev_id, ret);
1538 return ret;
1539 }
1540
1541 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1542 arvif->bssid);
1543 if (ret) {
1544 ath10k_warn(ar, "failed to bring up ap vdev %i: %d\n",
1545 arvif->vdev_id, ret);
1546 return ret;
1547 }
1548
1549 return 0;
1550}
1551
Kalle Valo5e3dd152013-06-12 20:52:10 +03001552static void ath10k_control_beaconing(struct ath10k_vif *arvif,
Kalle Valo5b07e072014-09-14 12:50:06 +03001553 struct ieee80211_bss_conf *info)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001554{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001555 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001556 int ret = 0;
1557
Michal Kazior548db542013-07-05 16:15:15 +03001558 lockdep_assert_held(&arvif->ar->conf_mutex);
1559
Kalle Valo5e3dd152013-06-12 20:52:10 +03001560 if (!info->enable_beacon) {
Michal Kazior500ff9f2015-03-31 10:26:21 +00001561 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1562 if (ret)
1563 ath10k_warn(ar, "failed to down vdev_id %i: %d\n",
1564 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001565
Michal Kaziorc930f742014-01-23 11:38:25 +01001566 arvif->is_up = false;
1567
Michal Kazior748afc42014-01-23 12:48:21 +01001568 spin_lock_bh(&arvif->ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03001569 ath10k_mac_vif_beacon_free(arvif);
Michal Kazior748afc42014-01-23 12:48:21 +01001570 spin_unlock_bh(&arvif->ar->data_lock);
1571
Kalle Valo5e3dd152013-06-12 20:52:10 +03001572 return;
1573 }
1574
1575 arvif->tx_seq_no = 0x1000;
1576
Michal Kaziorc930f742014-01-23 11:38:25 +01001577 arvif->aid = 0;
Kalle Valob25f32c2014-09-14 12:50:49 +03001578 ether_addr_copy(arvif->bssid, info->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01001579
1580 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1581 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001582 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001583 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001584 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001585 return;
1586 }
Michal Kaziorc930f742014-01-23 11:38:25 +01001587
Michal Kaziorc930f742014-01-23 11:38:25 +01001588 arvif->is_up = true;
1589
Michal Kazior500ff9f2015-03-31 10:26:21 +00001590 ret = ath10k_mac_vif_fix_hidden_ssid(arvif);
1591 if (ret) {
1592 ath10k_warn(ar, "failed to fix hidden ssid for vdev %i, expect trouble: %d\n",
1593 arvif->vdev_id, ret);
1594 return;
1595 }
1596
Michal Kazior7aa7a722014-08-25 12:09:38 +02001597 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001598}
1599
1600static void ath10k_control_ibss(struct ath10k_vif *arvif,
1601 struct ieee80211_bss_conf *info,
1602 const u8 self_peer[ETH_ALEN])
1603{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001604 struct ath10k *ar = arvif->ar;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001605 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001606 int ret = 0;
1607
Michal Kazior548db542013-07-05 16:15:15 +03001608 lockdep_assert_held(&arvif->ar->conf_mutex);
1609
Kalle Valo5e3dd152013-06-12 20:52:10 +03001610 if (!info->ibss_joined) {
Michal Kaziorc930f742014-01-23 11:38:25 +01001611 if (is_zero_ether_addr(arvif->bssid))
Kalle Valo5e3dd152013-06-12 20:52:10 +03001612 return;
1613
Joe Perches93803b32015-03-02 19:54:49 -08001614 eth_zero_addr(arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001615
1616 return;
1617 }
1618
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001619 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1620 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001621 ATH10K_DEFAULT_ATIM);
1622 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001623 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001624 arvif->vdev_id, ret);
1625}
1626
Michal Kazior9f9b5742014-12-12 12:41:36 +01001627static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1628{
1629 struct ath10k *ar = arvif->ar;
1630 u32 param;
1631 u32 value;
1632 int ret;
1633
1634 lockdep_assert_held(&arvif->ar->conf_mutex);
1635
1636 if (arvif->u.sta.uapsd)
1637 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1638 else
1639 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1640
1641 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1642 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1643 if (ret) {
1644 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1645 value, arvif->vdev_id, ret);
1646 return ret;
1647 }
1648
1649 return 0;
1650}
1651
1652static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1653{
1654 struct ath10k *ar = arvif->ar;
1655 u32 param;
1656 u32 value;
1657 int ret;
1658
1659 lockdep_assert_held(&arvif->ar->conf_mutex);
1660
1661 if (arvif->u.sta.uapsd)
1662 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1663 else
1664 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1665
1666 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1667 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1668 param, value);
1669 if (ret) {
1670 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1671 value, arvif->vdev_id, ret);
1672 return ret;
1673 }
1674
1675 return 0;
1676}
1677
Michal Kazior424f2632015-07-09 13:08:35 +02001678static int ath10k_mac_num_vifs_started(struct ath10k *ar)
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001679{
1680 struct ath10k_vif *arvif;
1681 int num = 0;
1682
1683 lockdep_assert_held(&ar->conf_mutex);
1684
1685 list_for_each_entry(arvif, &ar->arvifs, list)
Michal Kazior424f2632015-07-09 13:08:35 +02001686 if (arvif->is_started)
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001687 num++;
1688
1689 return num;
1690}
1691
Michal Kaziorad088bf2013-10-16 15:44:46 +03001692static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001693{
Michal Kaziorad088bf2013-10-16 15:44:46 +03001694 struct ath10k *ar = arvif->ar;
Michal Kazior526549a2014-12-12 12:41:37 +01001695 struct ieee80211_vif *vif = arvif->vif;
Michal Kaziorad088bf2013-10-16 15:44:46 +03001696 struct ieee80211_conf *conf = &ar->hw->conf;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001697 enum wmi_sta_powersave_param param;
1698 enum wmi_sta_ps_mode psmode;
1699 int ret;
Michal Kazior526549a2014-12-12 12:41:37 +01001700 int ps_timeout;
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001701 bool enable_ps;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001702
Michal Kazior548db542013-07-05 16:15:15 +03001703 lockdep_assert_held(&arvif->ar->conf_mutex);
1704
Michal Kaziorad088bf2013-10-16 15:44:46 +03001705 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1706 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001707
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001708 enable_ps = arvif->ps;
1709
Michal Kazior424f2632015-07-09 13:08:35 +02001710 if (enable_ps && ath10k_mac_num_vifs_started(ar) > 1 &&
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001711 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
1712 ar->fw_features)) {
1713 ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
1714 arvif->vdev_id);
1715 enable_ps = false;
1716 }
1717
Janusz Dziedzic917826b2015-05-18 09:38:17 +00001718 if (!arvif->is_started) {
1719 /* mac80211 can update vif powersave state while disconnected.
1720 * Firmware doesn't behave nicely and consumes more power than
1721 * necessary if PS is disabled on a non-started vdev. Hence
1722 * force-enable PS for non-running vdevs.
1723 */
1724 psmode = WMI_STA_PS_MODE_ENABLED;
1725 } else if (enable_ps) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001726 psmode = WMI_STA_PS_MODE_ENABLED;
1727 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1728
Michal Kazior526549a2014-12-12 12:41:37 +01001729 ps_timeout = conf->dynamic_ps_timeout;
1730 if (ps_timeout == 0) {
1731 /* Firmware doesn't like 0 */
1732 ps_timeout = ieee80211_tu_to_usec(
1733 vif->bss_conf.beacon_int) / 1000;
1734 }
1735
Michal Kaziorad088bf2013-10-16 15:44:46 +03001736 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
Michal Kazior526549a2014-12-12 12:41:37 +01001737 ps_timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001738 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001739 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001740 arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001741 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001742 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001743 } else {
1744 psmode = WMI_STA_PS_MODE_DISABLED;
1745 }
1746
Michal Kazior7aa7a722014-08-25 12:09:38 +02001747 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001748 arvif->vdev_id, psmode ? "enable" : "disable");
1749
Michal Kaziorad088bf2013-10-16 15:44:46 +03001750 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1751 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001752 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001753 psmode, arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001754 return ret;
1755 }
1756
1757 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001758}
1759
Michal Kazior46725b152015-01-28 09:57:49 +02001760static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1761{
1762 struct ath10k *ar = arvif->ar;
1763 struct wmi_sta_keepalive_arg arg = {};
1764 int ret;
1765
1766 lockdep_assert_held(&arvif->ar->conf_mutex);
1767
1768 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1769 return 0;
1770
1771 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1772 return 0;
1773
1774 /* Some firmware revisions have a bug and ignore the `enabled` field.
1775 * Instead use the interval to disable the keepalive.
1776 */
1777 arg.vdev_id = arvif->vdev_id;
1778 arg.enabled = 1;
1779 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1780 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1781
1782 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1783 if (ret) {
1784 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1785 arvif->vdev_id, ret);
1786 return ret;
1787 }
1788
1789 return 0;
1790}
1791
Michal Kazior81a9a172015-03-05 16:02:17 +02001792static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif)
1793{
1794 struct ath10k *ar = arvif->ar;
1795 struct ieee80211_vif *vif = arvif->vif;
1796 int ret;
1797
Michal Kazior8513d952015-03-09 14:19:24 +01001798 lockdep_assert_held(&arvif->ar->conf_mutex);
1799
1800 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)))
1801 return;
1802
Michal Kazior81a9a172015-03-05 16:02:17 +02001803 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1804 return;
1805
1806 if (!vif->csa_active)
1807 return;
1808
1809 if (!arvif->is_up)
1810 return;
1811
1812 if (!ieee80211_csa_is_complete(vif)) {
1813 ieee80211_csa_update_counter(vif);
1814
1815 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1816 if (ret)
1817 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
1818 ret);
1819
1820 ret = ath10k_mac_setup_prb_tmpl(arvif);
1821 if (ret)
1822 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
1823 ret);
1824 } else {
1825 ieee80211_csa_finish(vif);
1826 }
1827}
1828
1829static void ath10k_mac_vif_ap_csa_work(struct work_struct *work)
1830{
1831 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1832 ap_csa_work);
1833 struct ath10k *ar = arvif->ar;
1834
1835 mutex_lock(&ar->conf_mutex);
1836 ath10k_mac_vif_ap_csa_count_down(arvif);
1837 mutex_unlock(&ar->conf_mutex);
1838}
1839
Michal Kaziorcc9904e2015-03-10 16:22:01 +02001840static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac,
1841 struct ieee80211_vif *vif)
1842{
1843 struct sk_buff *skb = data;
1844 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1845 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1846
1847 if (vif->type != NL80211_IFTYPE_STATION)
1848 return;
1849
1850 if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
1851 return;
1852
1853 cancel_delayed_work(&arvif->connection_loss_work);
1854}
1855
1856void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb)
1857{
1858 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1859 IEEE80211_IFACE_ITER_NORMAL,
1860 ath10k_mac_handle_beacon_iter,
1861 skb);
1862}
1863
1864static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac,
1865 struct ieee80211_vif *vif)
1866{
1867 u32 *vdev_id = data;
1868 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1869 struct ath10k *ar = arvif->ar;
1870 struct ieee80211_hw *hw = ar->hw;
1871
1872 if (arvif->vdev_id != *vdev_id)
1873 return;
1874
1875 if (!arvif->is_up)
1876 return;
1877
1878 ieee80211_beacon_loss(vif);
1879
1880 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
1881 * (done by mac80211) succeeds but beacons do not resume then it
1882 * doesn't make sense to continue operation. Queue connection loss work
1883 * which can be cancelled when beacon is received.
1884 */
1885 ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
1886 ATH10K_CONNECTION_LOSS_HZ);
1887}
1888
1889void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id)
1890{
1891 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1892 IEEE80211_IFACE_ITER_NORMAL,
1893 ath10k_mac_handle_beacon_miss_iter,
1894 &vdev_id);
1895}
1896
1897static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work)
1898{
1899 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1900 connection_loss_work.work);
1901 struct ieee80211_vif *vif = arvif->vif;
1902
1903 if (!arvif->is_up)
1904 return;
1905
1906 ieee80211_connection_loss(vif);
1907}
1908
Kalle Valo5e3dd152013-06-12 20:52:10 +03001909/**********************/
1910/* Station management */
1911/**********************/
1912
Michal Kazior590922a2014-10-21 10:10:29 +03001913static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1914 struct ieee80211_vif *vif)
1915{
1916 /* Some firmware revisions have unstable STA powersave when listen
1917 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1918 * generate NullFunc frames properly even if buffered frames have been
1919 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1920 * buffered frames. Often pinging the device from AP would simply fail.
1921 *
1922 * As a workaround set it to 1.
1923 */
1924 if (vif->type == NL80211_IFTYPE_STATION)
1925 return 1;
1926
1927 return ar->hw->conf.listen_interval;
1928}
1929
Kalle Valo5e3dd152013-06-12 20:52:10 +03001930static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001931 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001932 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001933 struct wmi_peer_assoc_complete_arg *arg)
1934{
Michal Kazior590922a2014-10-21 10:10:29 +03001935 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorc51880e2015-03-30 09:51:57 +03001936 u32 aid;
Michal Kazior590922a2014-10-21 10:10:29 +03001937
Michal Kazior548db542013-07-05 16:15:15 +03001938 lockdep_assert_held(&ar->conf_mutex);
1939
Michal Kaziorc51880e2015-03-30 09:51:57 +03001940 if (vif->type == NL80211_IFTYPE_STATION)
1941 aid = vif->bss_conf.aid;
1942 else
1943 aid = sta->aid;
1944
Kalle Valob25f32c2014-09-14 12:50:49 +03001945 ether_addr_copy(arg->addr, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001946 arg->vdev_id = arvif->vdev_id;
Michal Kaziorc51880e2015-03-30 09:51:57 +03001947 arg->peer_aid = aid;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001948 arg->peer_flags |= WMI_PEER_AUTH;
Michal Kazior590922a2014-10-21 10:10:29 +03001949 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001950 arg->peer_num_spatial_streams = 1;
Michal Kazior590922a2014-10-21 10:10:29 +03001951 arg->peer_caps = vif->bss_conf.assoc_capability;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001952}
1953
1954static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001955 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001956 struct wmi_peer_assoc_complete_arg *arg)
1957{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001958 struct ieee80211_bss_conf *info = &vif->bss_conf;
Michal Kazior500ff9f2015-03-31 10:26:21 +00001959 struct cfg80211_chan_def def;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001960 struct cfg80211_bss *bss;
1961 const u8 *rsnie = NULL;
1962 const u8 *wpaie = NULL;
1963
Michal Kazior548db542013-07-05 16:15:15 +03001964 lockdep_assert_held(&ar->conf_mutex);
1965
Michal Kazior500ff9f2015-03-31 10:26:21 +00001966 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
1967 return;
1968
1969 bss = cfg80211_get_bss(ar->hw->wiphy, def.chan, info->bssid, NULL, 0,
1970 IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001971 if (bss) {
1972 const struct cfg80211_bss_ies *ies;
1973
1974 rcu_read_lock();
1975 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1976
1977 ies = rcu_dereference(bss->ies);
1978
1979 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
Kalle Valo5b07e072014-09-14 12:50:06 +03001980 WLAN_OUI_TYPE_MICROSOFT_WPA,
1981 ies->data,
1982 ies->len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001983 rcu_read_unlock();
1984 cfg80211_put_bss(ar->hw->wiphy, bss);
1985 }
1986
1987 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1988 if (rsnie || wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001989 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001990 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1991 }
1992
1993 if (wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001994 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001995 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1996 }
1997}
1998
1999static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
Michal Kazior500ff9f2015-03-31 10:26:21 +00002000 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002001 struct ieee80211_sta *sta,
2002 struct wmi_peer_assoc_complete_arg *arg)
2003{
Michal Kazior45c9abc2015-04-21 20:42:58 +03002004 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002005 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
Michal Kazior500ff9f2015-03-31 10:26:21 +00002006 struct cfg80211_chan_def def;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002007 const struct ieee80211_supported_band *sband;
2008 const struct ieee80211_rate *rates;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002009 enum ieee80211_band band;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002010 u32 ratemask;
Michal Kazior486017c2015-03-30 09:51:54 +03002011 u8 rate;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002012 int i;
2013
Michal Kazior548db542013-07-05 16:15:15 +03002014 lockdep_assert_held(&ar->conf_mutex);
2015
Michal Kazior500ff9f2015-03-31 10:26:21 +00002016 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2017 return;
2018
Michal Kazior45c9abc2015-04-21 20:42:58 +03002019 band = def.chan->band;
2020 sband = ar->hw->wiphy->bands[band];
2021 ratemask = sta->supp_rates[band];
2022 ratemask &= arvif->bitrate_mask.control[band].legacy;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002023 rates = sband->bitrates;
2024
2025 rateset->num_rates = 0;
2026
2027 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
2028 if (!(ratemask & 1))
2029 continue;
2030
Michal Kazior486017c2015-03-30 09:51:54 +03002031 rate = ath10k_mac_bitrate_to_rate(rates->bitrate);
2032 rateset->rates[rateset->num_rates] = rate;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002033 rateset->num_rates++;
2034 }
2035}
2036
Michal Kazior45c9abc2015-04-21 20:42:58 +03002037static bool
2038ath10k_peer_assoc_h_ht_masked(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
2039{
2040 int nss;
2041
2042 for (nss = 0; nss < IEEE80211_HT_MCS_MASK_LEN; nss++)
2043 if (ht_mcs_mask[nss])
2044 return false;
2045
2046 return true;
2047}
2048
2049static bool
2050ath10k_peer_assoc_h_vht_masked(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
2051{
2052 int nss;
2053
2054 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++)
2055 if (vht_mcs_mask[nss])
2056 return false;
2057
2058 return true;
2059}
2060
Kalle Valo5e3dd152013-06-12 20:52:10 +03002061static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
Michal Kazior45c9abc2015-04-21 20:42:58 +03002062 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002063 struct ieee80211_sta *sta,
2064 struct wmi_peer_assoc_complete_arg *arg)
2065{
2066 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002067 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2068 struct cfg80211_chan_def def;
2069 enum ieee80211_band band;
2070 const u8 *ht_mcs_mask;
2071 const u16 *vht_mcs_mask;
2072 int i, n, max_nss;
Kalle Valoaf762c02014-09-14 12:50:17 +03002073 u32 stbc;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002074
Michal Kazior548db542013-07-05 16:15:15 +03002075 lockdep_assert_held(&ar->conf_mutex);
2076
Michal Kazior45c9abc2015-04-21 20:42:58 +03002077 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2078 return;
2079
Kalle Valo5e3dd152013-06-12 20:52:10 +03002080 if (!ht_cap->ht_supported)
2081 return;
2082
Michal Kazior45c9abc2015-04-21 20:42:58 +03002083 band = def.chan->band;
2084 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2085 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2086
2087 if (ath10k_peer_assoc_h_ht_masked(ht_mcs_mask) &&
2088 ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2089 return;
2090
Kalle Valo5e3dd152013-06-12 20:52:10 +03002091 arg->peer_flags |= WMI_PEER_HT;
2092 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2093 ht_cap->ampdu_factor)) - 1;
2094
2095 arg->peer_mpdu_density =
2096 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
2097
2098 arg->peer_ht_caps = ht_cap->cap;
2099 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
2100
2101 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
2102 arg->peer_flags |= WMI_PEER_LDPC;
2103
2104 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
2105 arg->peer_flags |= WMI_PEER_40MHZ;
2106 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
2107 }
2108
Michal Kazior45c9abc2015-04-21 20:42:58 +03002109 if (arvif->bitrate_mask.control[band].gi != NL80211_TXRATE_FORCE_LGI) {
2110 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
2111 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002112
Michal Kazior45c9abc2015-04-21 20:42:58 +03002113 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
2114 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2115 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002116
2117 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
2118 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
2119 arg->peer_flags |= WMI_PEER_STBC;
2120 }
2121
2122 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002123 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
2124 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
2125 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
2126 arg->peer_rate_caps |= stbc;
2127 arg->peer_flags |= WMI_PEER_STBC;
2128 }
2129
Kalle Valo5e3dd152013-06-12 20:52:10 +03002130 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
2131 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
2132 else if (ht_cap->mcs.rx_mask[1])
2133 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
2134
Michal Kazior45c9abc2015-04-21 20:42:58 +03002135 for (i = 0, n = 0, max_nss = 0; i < IEEE80211_HT_MCS_MASK_LEN * 8; i++)
2136 if ((ht_cap->mcs.rx_mask[i / 8] & BIT(i % 8)) &&
2137 (ht_mcs_mask[i / 8] & BIT(i % 8))) {
2138 max_nss = (i / 8) + 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002139 arg->peer_ht_rates.rates[n++] = i;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002140 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002141
Bartosz Markowskifd71f802014-02-10 13:12:55 +01002142 /*
2143 * This is a workaround for HT-enabled STAs which break the spec
2144 * and have no HT capabilities RX mask (no HT RX MCS map).
2145 *
2146 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
2147 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
2148 *
2149 * Firmware asserts if such situation occurs.
2150 */
2151 if (n == 0) {
2152 arg->peer_ht_rates.num_rates = 8;
2153 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
2154 arg->peer_ht_rates.rates[i] = i;
2155 } else {
2156 arg->peer_ht_rates.num_rates = n;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002157 arg->peer_num_spatial_streams = max_nss;
Bartosz Markowskifd71f802014-02-10 13:12:55 +01002158 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002159
Michal Kazior7aa7a722014-08-25 12:09:38 +02002160 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03002161 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002162 arg->peer_ht_rates.num_rates,
2163 arg->peer_num_spatial_streams);
2164}
2165
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002166static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
2167 struct ath10k_vif *arvif,
2168 struct ieee80211_sta *sta)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002169{
2170 u32 uapsd = 0;
2171 u32 max_sp = 0;
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002172 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002173
Michal Kazior548db542013-07-05 16:15:15 +03002174 lockdep_assert_held(&ar->conf_mutex);
2175
Kalle Valo5e3dd152013-06-12 20:52:10 +03002176 if (sta->wme && sta->uapsd_queues) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002177 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002178 sta->uapsd_queues, sta->max_sp);
2179
Kalle Valo5e3dd152013-06-12 20:52:10 +03002180 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2181 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
2182 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
2183 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2184 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
2185 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
2186 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2187 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
2188 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
2189 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2190 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
2191 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
2192
Kalle Valo5e3dd152013-06-12 20:52:10 +03002193 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
2194 max_sp = sta->max_sp;
2195
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002196 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2197 sta->addr,
2198 WMI_AP_PS_PEER_PARAM_UAPSD,
2199 uapsd);
2200 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002201 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002202 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002203 return ret;
2204 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002205
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002206 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2207 sta->addr,
2208 WMI_AP_PS_PEER_PARAM_MAX_SP,
2209 max_sp);
2210 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002211 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002212 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002213 return ret;
2214 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002215
2216 /* TODO setup this based on STA listen interval and
2217 beacon interval. Currently we don't know
2218 sta->listen_interval - mac80211 patch required.
2219 Currently use 10 seconds */
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002220 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
Kalle Valo5b07e072014-09-14 12:50:06 +03002221 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
2222 10);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002223 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002224 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002225 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002226 return ret;
2227 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002228 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002229
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002230 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002231}
2232
Michal Kazior45c9abc2015-04-21 20:42:58 +03002233static u16
2234ath10k_peer_assoc_h_vht_limit(u16 tx_mcs_set,
2235 const u16 vht_mcs_limit[NL80211_VHT_NSS_MAX])
2236{
2237 int idx_limit;
2238 int nss;
2239 u16 mcs_map;
2240 u16 mcs;
2241
2242 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
2243 mcs_map = ath10k_mac_get_max_vht_mcs_map(tx_mcs_set, nss) &
2244 vht_mcs_limit[nss];
2245
2246 if (mcs_map)
2247 idx_limit = fls(mcs_map) - 1;
2248 else
2249 idx_limit = -1;
2250
2251 switch (idx_limit) {
2252 case 0: /* fall through */
2253 case 1: /* fall through */
2254 case 2: /* fall through */
2255 case 3: /* fall through */
2256 case 4: /* fall through */
2257 case 5: /* fall through */
2258 case 6: /* fall through */
2259 default:
2260 /* see ath10k_mac_can_set_bitrate_mask() */
2261 WARN_ON(1);
2262 /* fall through */
2263 case -1:
2264 mcs = IEEE80211_VHT_MCS_NOT_SUPPORTED;
2265 break;
2266 case 7:
2267 mcs = IEEE80211_VHT_MCS_SUPPORT_0_7;
2268 break;
2269 case 8:
2270 mcs = IEEE80211_VHT_MCS_SUPPORT_0_8;
2271 break;
2272 case 9:
2273 mcs = IEEE80211_VHT_MCS_SUPPORT_0_9;
2274 break;
2275 }
2276
2277 tx_mcs_set &= ~(0x3 << (nss * 2));
2278 tx_mcs_set |= mcs << (nss * 2);
2279 }
2280
2281 return tx_mcs_set;
2282}
2283
Kalle Valo5e3dd152013-06-12 20:52:10 +03002284static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
Michal Kazior500ff9f2015-03-31 10:26:21 +00002285 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002286 struct ieee80211_sta *sta,
2287 struct wmi_peer_assoc_complete_arg *arg)
2288{
2289 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002290 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior500ff9f2015-03-31 10:26:21 +00002291 struct cfg80211_chan_def def;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002292 enum ieee80211_band band;
2293 const u16 *vht_mcs_mask;
Sujith Manoharana24b88b2013-10-07 19:51:57 -07002294 u8 ampdu_factor;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002295
Michal Kazior500ff9f2015-03-31 10:26:21 +00002296 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2297 return;
2298
Kalle Valo5e3dd152013-06-12 20:52:10 +03002299 if (!vht_cap->vht_supported)
2300 return;
2301
Michal Kazior45c9abc2015-04-21 20:42:58 +03002302 band = def.chan->band;
2303 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2304
2305 if (ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2306 return;
2307
Kalle Valo5e3dd152013-06-12 20:52:10 +03002308 arg->peer_flags |= WMI_PEER_VHT;
Yanbo Lid68bb122015-01-23 08:18:20 +08002309
Michal Kazior500ff9f2015-03-31 10:26:21 +00002310 if (def.chan->band == IEEE80211_BAND_2GHZ)
Yanbo Lid68bb122015-01-23 08:18:20 +08002311 arg->peer_flags |= WMI_PEER_VHT_2G;
2312
Kalle Valo5e3dd152013-06-12 20:52:10 +03002313 arg->peer_vht_caps = vht_cap->cap;
2314
Sujith Manoharana24b88b2013-10-07 19:51:57 -07002315 ampdu_factor = (vht_cap->cap &
2316 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
2317 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
2318
2319 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
2320 * zero in VHT IE. Using it would result in degraded throughput.
2321 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
2322 * it if VHT max_mpdu is smaller. */
2323 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
2324 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2325 ampdu_factor)) - 1);
2326
Kalle Valo5e3dd152013-06-12 20:52:10 +03002327 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2328 arg->peer_flags |= WMI_PEER_80MHZ;
2329
2330 arg->peer_vht_rates.rx_max_rate =
2331 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
2332 arg->peer_vht_rates.rx_mcs_set =
2333 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
2334 arg->peer_vht_rates.tx_max_rate =
2335 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
Michal Kazior45c9abc2015-04-21 20:42:58 +03002336 arg->peer_vht_rates.tx_mcs_set = ath10k_peer_assoc_h_vht_limit(
2337 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map), vht_mcs_mask);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002338
Michal Kazior7aa7a722014-08-25 12:09:38 +02002339 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03002340 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002341}
2342
2343static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03002344 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002345 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002346 struct wmi_peer_assoc_complete_arg *arg)
2347{
Michal Kazior590922a2014-10-21 10:10:29 +03002348 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2349
Kalle Valo5e3dd152013-06-12 20:52:10 +03002350 switch (arvif->vdev_type) {
2351 case WMI_VDEV_TYPE_AP:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002352 if (sta->wme)
2353 arg->peer_flags |= WMI_PEER_QOS;
2354
2355 if (sta->wme && sta->uapsd_queues) {
2356 arg->peer_flags |= WMI_PEER_APSD;
2357 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
2358 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002359 break;
2360 case WMI_VDEV_TYPE_STA:
Michal Kazior590922a2014-10-21 10:10:29 +03002361 if (vif->bss_conf.qos)
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002362 arg->peer_flags |= WMI_PEER_QOS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002363 break;
Janusz Dziedzic627d9842014-12-17 12:29:54 +02002364 case WMI_VDEV_TYPE_IBSS:
2365 if (sta->wme)
2366 arg->peer_flags |= WMI_PEER_QOS;
2367 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002368 default:
2369 break;
2370 }
Janusz Dziedzic627d9842014-12-17 12:29:54 +02002371
2372 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
2373 sta->addr, !!(arg->peer_flags & WMI_PEER_QOS));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002374}
2375
Michal Kazior8d7aa6b2015-03-30 09:51:57 +03002376static bool ath10k_mac_sta_has_ofdm_only(struct ieee80211_sta *sta)
Michal Kazior91b12082014-12-12 12:41:35 +01002377{
Michal Kazior8d7aa6b2015-03-30 09:51:57 +03002378 return sta->supp_rates[IEEE80211_BAND_2GHZ] >>
2379 ATH10K_MAC_FIRST_OFDM_RATE_IDX;
Michal Kazior91b12082014-12-12 12:41:35 +01002380}
2381
Kalle Valo5e3dd152013-06-12 20:52:10 +03002382static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03002383 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002384 struct ieee80211_sta *sta,
2385 struct wmi_peer_assoc_complete_arg *arg)
2386{
Michal Kazior45c9abc2015-04-21 20:42:58 +03002387 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior500ff9f2015-03-31 10:26:21 +00002388 struct cfg80211_chan_def def;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002389 enum ieee80211_band band;
2390 const u8 *ht_mcs_mask;
2391 const u16 *vht_mcs_mask;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002392 enum wmi_phy_mode phymode = MODE_UNKNOWN;
2393
Michal Kazior500ff9f2015-03-31 10:26:21 +00002394 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2395 return;
2396
Michal Kazior45c9abc2015-04-21 20:42:58 +03002397 band = def.chan->band;
2398 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2399 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2400
2401 switch (band) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002402 case IEEE80211_BAND_2GHZ:
Michal Kazior45c9abc2015-04-21 20:42:58 +03002403 if (sta->vht_cap.vht_supported &&
2404 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
Yanbo Lid68bb122015-01-23 08:18:20 +08002405 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2406 phymode = MODE_11AC_VHT40;
2407 else
2408 phymode = MODE_11AC_VHT20;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002409 } else if (sta->ht_cap.ht_supported &&
2410 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002411 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2412 phymode = MODE_11NG_HT40;
2413 else
2414 phymode = MODE_11NG_HT20;
Michal Kazior8d7aa6b2015-03-30 09:51:57 +03002415 } else if (ath10k_mac_sta_has_ofdm_only(sta)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002416 phymode = MODE_11G;
Michal Kazior91b12082014-12-12 12:41:35 +01002417 } else {
2418 phymode = MODE_11B;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002419 }
2420
2421 break;
2422 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03002423 /*
2424 * Check VHT first.
2425 */
Michal Kazior45c9abc2015-04-21 20:42:58 +03002426 if (sta->vht_cap.vht_supported &&
2427 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03002428 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2429 phymode = MODE_11AC_VHT80;
2430 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2431 phymode = MODE_11AC_VHT40;
2432 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
2433 phymode = MODE_11AC_VHT20;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002434 } else if (sta->ht_cap.ht_supported &&
2435 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2436 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002437 phymode = MODE_11NA_HT40;
2438 else
2439 phymode = MODE_11NA_HT20;
2440 } else {
2441 phymode = MODE_11A;
2442 }
2443
2444 break;
2445 default:
2446 break;
2447 }
2448
Michal Kazior7aa7a722014-08-25 12:09:38 +02002449 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
Kalle Valo38a1d472013-09-08 17:56:14 +03002450 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03002451
Kalle Valo5e3dd152013-06-12 20:52:10 +03002452 arg->peer_phymode = phymode;
2453 WARN_ON(phymode == MODE_UNKNOWN);
2454}
2455
Kalle Valob9ada652013-10-16 15:44:46 +03002456static int ath10k_peer_assoc_prepare(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03002457 struct ieee80211_vif *vif,
Kalle Valob9ada652013-10-16 15:44:46 +03002458 struct ieee80211_sta *sta,
Kalle Valob9ada652013-10-16 15:44:46 +03002459 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002460{
Michal Kazior548db542013-07-05 16:15:15 +03002461 lockdep_assert_held(&ar->conf_mutex);
2462
Kalle Valob9ada652013-10-16 15:44:46 +03002463 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002464
Michal Kazior590922a2014-10-21 10:10:29 +03002465 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
2466 ath10k_peer_assoc_h_crypto(ar, vif, arg);
Michal Kazior500ff9f2015-03-31 10:26:21 +00002467 ath10k_peer_assoc_h_rates(ar, vif, sta, arg);
Michal Kazior45c9abc2015-04-21 20:42:58 +03002468 ath10k_peer_assoc_h_ht(ar, vif, sta, arg);
Michal Kazior500ff9f2015-03-31 10:26:21 +00002469 ath10k_peer_assoc_h_vht(ar, vif, sta, arg);
Michal Kazior590922a2014-10-21 10:10:29 +03002470 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
2471 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002472
Kalle Valob9ada652013-10-16 15:44:46 +03002473 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002474}
2475
Michal Kazior90046f52014-02-14 14:45:51 +01002476static const u32 ath10k_smps_map[] = {
2477 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
2478 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
2479 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
2480 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
2481};
2482
2483static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
2484 const u8 *addr,
2485 const struct ieee80211_sta_ht_cap *ht_cap)
2486{
2487 int smps;
2488
2489 if (!ht_cap->ht_supported)
2490 return 0;
2491
2492 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
2493 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
2494
2495 if (smps >= ARRAY_SIZE(ath10k_smps_map))
2496 return -EINVAL;
2497
2498 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
2499 WMI_PEER_SMPS_STATE,
2500 ath10k_smps_map[smps]);
2501}
2502
Michal Kazior139e1702015-02-15 16:50:42 +02002503static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
2504 struct ieee80211_vif *vif,
2505 struct ieee80211_sta_vht_cap vht_cap)
2506{
2507 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2508 int ret;
2509 u32 param;
2510 u32 value;
2511
2512 if (!(ar->vht_cap_info &
2513 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2514 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
2515 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2516 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
2517 return 0;
2518
2519 param = ar->wmi.vdev_param->txbf;
2520 value = 0;
2521
2522 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
2523 return 0;
2524
2525 /* The following logic is correct. If a remote STA advertises support
2526 * for being a beamformer then we should enable us being a beamformee.
2527 */
2528
2529 if (ar->vht_cap_info &
2530 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2531 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
2532 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
2533 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2534
2535 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
2536 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
2537 }
2538
2539 if (ar->vht_cap_info &
2540 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2541 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
2542 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
2543 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2544
2545 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
2546 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
2547 }
2548
2549 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
2550 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2551
2552 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
2553 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2554
2555 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
2556 if (ret) {
2557 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
2558 value, ret);
2559 return ret;
2560 }
2561
2562 return 0;
2563}
2564
Kalle Valo5e3dd152013-06-12 20:52:10 +03002565/* can be called only in mac80211 callbacks due to `key_count` usage */
2566static void ath10k_bss_assoc(struct ieee80211_hw *hw,
2567 struct ieee80211_vif *vif,
2568 struct ieee80211_bss_conf *bss_conf)
2569{
2570 struct ath10k *ar = hw->priv;
2571 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior90046f52014-02-14 14:45:51 +01002572 struct ieee80211_sta_ht_cap ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02002573 struct ieee80211_sta_vht_cap vht_cap;
Kalle Valob9ada652013-10-16 15:44:46 +03002574 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002575 struct ieee80211_sta *ap_sta;
2576 int ret;
2577
Michal Kazior548db542013-07-05 16:15:15 +03002578 lockdep_assert_held(&ar->conf_mutex);
2579
Michal Kazior077efc82014-10-21 10:10:29 +03002580 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
2581 arvif->vdev_id, arvif->bssid, arvif->aid);
2582
Kalle Valo5e3dd152013-06-12 20:52:10 +03002583 rcu_read_lock();
2584
2585 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
2586 if (!ap_sta) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002587 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02002588 bss_conf->bssid, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002589 rcu_read_unlock();
2590 return;
2591 }
2592
Michal Kazior90046f52014-02-14 14:45:51 +01002593 /* ap_sta must be accessed only within rcu section which must be left
2594 * before calling ath10k_setup_peer_smps() which might sleep. */
2595 ht_cap = ap_sta->ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02002596 vht_cap = ap_sta->vht_cap;
Michal Kazior90046f52014-02-14 14:45:51 +01002597
Michal Kazior590922a2014-10-21 10:10:29 +03002598 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002599 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002600 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002601 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002602 rcu_read_unlock();
2603 return;
2604 }
2605
2606 rcu_read_unlock();
2607
Kalle Valob9ada652013-10-16 15:44:46 +03002608 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2609 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002610 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002611 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03002612 return;
2613 }
2614
Michal Kazior90046f52014-02-14 14:45:51 +01002615 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
2616 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002617 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002618 arvif->vdev_id, ret);
Michal Kazior90046f52014-02-14 14:45:51 +01002619 return;
2620 }
2621
Michal Kazior139e1702015-02-15 16:50:42 +02002622 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2623 if (ret) {
2624 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2625 arvif->vdev_id, bss_conf->bssid, ret);
2626 return;
2627 }
2628
Michal Kazior7aa7a722014-08-25 12:09:38 +02002629 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002630 "mac vdev %d up (associated) bssid %pM aid %d\n",
2631 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
2632
Michal Kazior077efc82014-10-21 10:10:29 +03002633 WARN_ON(arvif->is_up);
2634
Michal Kaziorc930f742014-01-23 11:38:25 +01002635 arvif->aid = bss_conf->aid;
Kalle Valob25f32c2014-09-14 12:50:49 +03002636 ether_addr_copy(arvif->bssid, bss_conf->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01002637
2638 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
2639 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002640 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002641 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01002642 return;
2643 }
2644
2645 arvif->is_up = true;
Michal Kazior0a987fb2015-02-13 13:30:15 +01002646
2647 /* Workaround: Some firmware revisions (tested with qca6174
2648 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2649 * poked with peer param command.
2650 */
2651 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
2652 WMI_PEER_DUMMY_VAR, 1);
2653 if (ret) {
2654 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2655 arvif->bssid, arvif->vdev_id, ret);
2656 return;
2657 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002658}
2659
Kalle Valo5e3dd152013-06-12 20:52:10 +03002660static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
2661 struct ieee80211_vif *vif)
2662{
2663 struct ath10k *ar = hw->priv;
2664 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior139e1702015-02-15 16:50:42 +02002665 struct ieee80211_sta_vht_cap vht_cap = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +03002666 int ret;
2667
Michal Kazior548db542013-07-05 16:15:15 +03002668 lockdep_assert_held(&ar->conf_mutex);
2669
Michal Kazior077efc82014-10-21 10:10:29 +03002670 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
2671 arvif->vdev_id, arvif->bssid);
Kalle Valo60c3daa2013-09-08 17:56:07 +03002672
Kalle Valo5e3dd152013-06-12 20:52:10 +03002673 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kazior077efc82014-10-21 10:10:29 +03002674 if (ret)
2675 ath10k_warn(ar, "faield to down vdev %i: %d\n",
2676 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002677
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02002678 arvif->def_wep_key_idx = -1;
2679
Michal Kazior139e1702015-02-15 16:50:42 +02002680 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2681 if (ret) {
2682 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
2683 arvif->vdev_id, ret);
2684 return;
2685 }
2686
Michal Kaziorc930f742014-01-23 11:38:25 +01002687 arvif->is_up = false;
Michal Kaziorcc9904e2015-03-10 16:22:01 +02002688
2689 cancel_delayed_work_sync(&arvif->connection_loss_work);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002690}
2691
Michal Kazior590922a2014-10-21 10:10:29 +03002692static int ath10k_station_assoc(struct ath10k *ar,
2693 struct ieee80211_vif *vif,
2694 struct ieee80211_sta *sta,
2695 bool reassoc)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002696{
Michal Kazior590922a2014-10-21 10:10:29 +03002697 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valob9ada652013-10-16 15:44:46 +03002698 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002699 int ret = 0;
2700
Michal Kazior548db542013-07-05 16:15:15 +03002701 lockdep_assert_held(&ar->conf_mutex);
2702
Michal Kazior590922a2014-10-21 10:10:29 +03002703 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002704 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002705 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02002706 sta->addr, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03002707 return ret;
2708 }
2709
2710 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2711 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002712 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002713 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002714 return ret;
2715 }
2716
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002717 /* Re-assoc is run only to update supported rates for given station. It
2718 * doesn't make much sense to reconfigure the peer completely.
2719 */
2720 if (!reassoc) {
2721 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
2722 &sta->ht_cap);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002723 if (ret) {
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002724 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002725 arvif->vdev_id, ret);
2726 return ret;
2727 }
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002728
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002729 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
2730 if (ret) {
2731 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
2732 sta->addr, arvif->vdev_id, ret);
2733 return ret;
2734 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002735
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002736 if (!sta->wme) {
2737 arvif->num_legacy_stations++;
2738 ret = ath10k_recalc_rtscts_prot(arvif);
2739 if (ret) {
2740 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2741 arvif->vdev_id, ret);
2742 return ret;
2743 }
2744 }
2745
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02002746 /* Plumb cached keys only for static WEP */
2747 if (arvif->def_wep_key_idx != -1) {
2748 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
2749 if (ret) {
2750 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
2751 arvif->vdev_id, ret);
2752 return ret;
2753 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002754 }
2755 }
2756
Kalle Valo5e3dd152013-06-12 20:52:10 +03002757 return ret;
2758}
2759
Michal Kazior590922a2014-10-21 10:10:29 +03002760static int ath10k_station_disassoc(struct ath10k *ar,
2761 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002762 struct ieee80211_sta *sta)
2763{
Michal Kazior590922a2014-10-21 10:10:29 +03002764 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002765 int ret = 0;
2766
2767 lockdep_assert_held(&ar->conf_mutex);
2768
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002769 if (!sta->wme) {
2770 arvif->num_legacy_stations--;
2771 ret = ath10k_recalc_rtscts_prot(arvif);
2772 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002773 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002774 arvif->vdev_id, ret);
2775 return ret;
2776 }
2777 }
2778
Kalle Valo5e3dd152013-06-12 20:52:10 +03002779 ret = ath10k_clear_peer_keys(arvif, sta->addr);
2780 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002781 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002782 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002783 return ret;
2784 }
2785
2786 return ret;
2787}
2788
2789/**************/
2790/* Regulatory */
2791/**************/
2792
2793static int ath10k_update_channel_list(struct ath10k *ar)
2794{
2795 struct ieee80211_hw *hw = ar->hw;
2796 struct ieee80211_supported_band **bands;
2797 enum ieee80211_band band;
2798 struct ieee80211_channel *channel;
2799 struct wmi_scan_chan_list_arg arg = {0};
2800 struct wmi_channel_arg *ch;
2801 bool passive;
2802 int len;
2803 int ret;
2804 int i;
2805
Michal Kazior548db542013-07-05 16:15:15 +03002806 lockdep_assert_held(&ar->conf_mutex);
2807
Kalle Valo5e3dd152013-06-12 20:52:10 +03002808 bands = hw->wiphy->bands;
2809 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2810 if (!bands[band])
2811 continue;
2812
2813 for (i = 0; i < bands[band]->n_channels; i++) {
2814 if (bands[band]->channels[i].flags &
2815 IEEE80211_CHAN_DISABLED)
2816 continue;
2817
2818 arg.n_channels++;
2819 }
2820 }
2821
2822 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
2823 arg.channels = kzalloc(len, GFP_KERNEL);
2824 if (!arg.channels)
2825 return -ENOMEM;
2826
2827 ch = arg.channels;
2828 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2829 if (!bands[band])
2830 continue;
2831
2832 for (i = 0; i < bands[band]->n_channels; i++) {
2833 channel = &bands[band]->channels[i];
2834
2835 if (channel->flags & IEEE80211_CHAN_DISABLED)
2836 continue;
2837
2838 ch->allow_ht = true;
2839
2840 /* FIXME: when should we really allow VHT? */
2841 ch->allow_vht = true;
2842
2843 ch->allow_ibss =
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002844 !(channel->flags & IEEE80211_CHAN_NO_IR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002845
2846 ch->ht40plus =
2847 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
2848
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002849 ch->chan_radar =
2850 !!(channel->flags & IEEE80211_CHAN_RADAR);
2851
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002852 passive = channel->flags & IEEE80211_CHAN_NO_IR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002853 ch->passive = passive;
2854
2855 ch->freq = channel->center_freq;
Michal Kazior2d667212014-09-18 15:21:21 +02002856 ch->band_center_freq1 = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07002857 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07002858 ch->max_power = channel->max_power * 2;
2859 ch->max_reg_power = channel->max_reg_power * 2;
2860 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002861 ch->reg_class_id = 0; /* FIXME */
2862
2863 /* FIXME: why use only legacy modes, why not any
2864 * HT/VHT modes? Would that even make any
2865 * difference? */
2866 if (channel->band == IEEE80211_BAND_2GHZ)
2867 ch->mode = MODE_11G;
2868 else
2869 ch->mode = MODE_11A;
2870
2871 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
2872 continue;
2873
Michal Kazior7aa7a722014-08-25 12:09:38 +02002874 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002875 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
2876 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002877 ch->freq, ch->max_power, ch->max_reg_power,
2878 ch->max_antenna_gain, ch->mode);
2879
2880 ch++;
2881 }
2882 }
2883
2884 ret = ath10k_wmi_scan_chan_list(ar, &arg);
2885 kfree(arg.channels);
2886
2887 return ret;
2888}
2889
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002890static enum wmi_dfs_region
2891ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
2892{
2893 switch (dfs_region) {
2894 case NL80211_DFS_UNSET:
2895 return WMI_UNINIT_DFS_DOMAIN;
2896 case NL80211_DFS_FCC:
2897 return WMI_FCC_DFS_DOMAIN;
2898 case NL80211_DFS_ETSI:
2899 return WMI_ETSI_DFS_DOMAIN;
2900 case NL80211_DFS_JP:
2901 return WMI_MKK4_DFS_DOMAIN;
2902 }
2903 return WMI_UNINIT_DFS_DOMAIN;
2904}
2905
Michal Kaziorf7843d72013-07-16 09:38:52 +02002906static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002907{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002908 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002909 int ret;
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002910 enum wmi_dfs_region wmi_dfs_reg;
2911 enum nl80211_dfs_regions nl_dfs_reg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002912
Michal Kaziorf7843d72013-07-16 09:38:52 +02002913 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002914
2915 ret = ath10k_update_channel_list(ar);
2916 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002917 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002918
2919 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002920
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002921 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
2922 nl_dfs_reg = ar->dfs_detector->region;
2923 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
2924 } else {
2925 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
2926 }
2927
Kalle Valo5e3dd152013-06-12 20:52:10 +03002928 /* Target allows setting up per-band regdomain but ath_common provides
2929 * a combined one only */
2930 ret = ath10k_wmi_pdev_set_regdomain(ar,
Kalle Valoef8c0012014-02-13 18:13:12 +02002931 regpair->reg_domain,
2932 regpair->reg_domain, /* 2ghz */
2933 regpair->reg_domain, /* 5ghz */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002934 regpair->reg_2ghz_ctl,
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002935 regpair->reg_5ghz_ctl,
2936 wmi_dfs_reg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002937 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002938 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02002939}
Michal Kazior548db542013-07-05 16:15:15 +03002940
Michal Kaziorf7843d72013-07-16 09:38:52 +02002941static void ath10k_reg_notifier(struct wiphy *wiphy,
2942 struct regulatory_request *request)
2943{
2944 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
2945 struct ath10k *ar = hw->priv;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002946 bool result;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002947
2948 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
2949
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002950 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002951 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002952 request->dfs_region);
2953 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
2954 request->dfs_region);
2955 if (!result)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002956 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002957 request->dfs_region);
2958 }
2959
Michal Kaziorf7843d72013-07-16 09:38:52 +02002960 mutex_lock(&ar->conf_mutex);
2961 if (ar->state == ATH10K_STATE_ON)
2962 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03002963 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002964}
2965
2966/***************/
2967/* TX handlers */
2968/***************/
2969
Michal Kazior96d828d2015-03-31 10:26:23 +00002970void ath10k_mac_tx_lock(struct ath10k *ar, int reason)
2971{
2972 lockdep_assert_held(&ar->htt.tx_lock);
2973
2974 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
2975 ar->tx_paused |= BIT(reason);
2976 ieee80211_stop_queues(ar->hw);
2977}
2978
2979static void ath10k_mac_tx_unlock_iter(void *data, u8 *mac,
2980 struct ieee80211_vif *vif)
2981{
2982 struct ath10k *ar = data;
2983 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2984
2985 if (arvif->tx_paused)
2986 return;
2987
2988 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
2989}
2990
2991void ath10k_mac_tx_unlock(struct ath10k *ar, int reason)
2992{
2993 lockdep_assert_held(&ar->htt.tx_lock);
2994
2995 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
2996 ar->tx_paused &= ~BIT(reason);
2997
2998 if (ar->tx_paused)
2999 return;
3000
3001 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3002 IEEE80211_IFACE_ITER_RESUME_ALL,
3003 ath10k_mac_tx_unlock_iter,
3004 ar);
3005}
3006
3007void ath10k_mac_vif_tx_lock(struct ath10k_vif *arvif, int reason)
3008{
3009 struct ath10k *ar = arvif->ar;
3010
3011 lockdep_assert_held(&ar->htt.tx_lock);
3012
3013 WARN_ON(reason >= BITS_PER_LONG);
3014 arvif->tx_paused |= BIT(reason);
3015 ieee80211_stop_queue(ar->hw, arvif->vdev_id);
3016}
3017
3018void ath10k_mac_vif_tx_unlock(struct ath10k_vif *arvif, int reason)
3019{
3020 struct ath10k *ar = arvif->ar;
3021
3022 lockdep_assert_held(&ar->htt.tx_lock);
3023
3024 WARN_ON(reason >= BITS_PER_LONG);
3025 arvif->tx_paused &= ~BIT(reason);
3026
3027 if (ar->tx_paused)
3028 return;
3029
3030 if (arvif->tx_paused)
3031 return;
3032
3033 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3034}
3035
Michal Kaziorb4aa5392015-03-31 10:26:24 +00003036static void ath10k_mac_vif_handle_tx_pause(struct ath10k_vif *arvif,
3037 enum wmi_tlv_tx_pause_id pause_id,
3038 enum wmi_tlv_tx_pause_action action)
3039{
3040 struct ath10k *ar = arvif->ar;
3041
3042 lockdep_assert_held(&ar->htt.tx_lock);
3043
Michal Kazioracd0b272015-07-09 13:08:38 +02003044 switch (action) {
3045 case WMI_TLV_TX_PAUSE_ACTION_STOP:
3046 ath10k_mac_vif_tx_lock(arvif, pause_id);
Michal Kaziorb4aa5392015-03-31 10:26:24 +00003047 break;
Michal Kazioracd0b272015-07-09 13:08:38 +02003048 case WMI_TLV_TX_PAUSE_ACTION_WAKE:
3049 ath10k_mac_vif_tx_unlock(arvif, pause_id);
3050 break;
Michal Kaziorb4aa5392015-03-31 10:26:24 +00003051 default:
Michal Kazioracd0b272015-07-09 13:08:38 +02003052 ath10k_warn(ar, "received unknown tx pause action %d on vdev %i, ignoring\n",
3053 action, arvif->vdev_id);
Michal Kaziorb4aa5392015-03-31 10:26:24 +00003054 break;
3055 }
3056}
3057
3058struct ath10k_mac_tx_pause {
3059 u32 vdev_id;
3060 enum wmi_tlv_tx_pause_id pause_id;
3061 enum wmi_tlv_tx_pause_action action;
3062};
3063
3064static void ath10k_mac_handle_tx_pause_iter(void *data, u8 *mac,
3065 struct ieee80211_vif *vif)
3066{
3067 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3068 struct ath10k_mac_tx_pause *arg = data;
3069
Michal Kazioracd0b272015-07-09 13:08:38 +02003070 if (arvif->vdev_id != arg->vdev_id)
3071 return;
3072
Michal Kaziorb4aa5392015-03-31 10:26:24 +00003073 ath10k_mac_vif_handle_tx_pause(arvif, arg->pause_id, arg->action);
3074}
3075
Michal Kazioracd0b272015-07-09 13:08:38 +02003076void ath10k_mac_handle_tx_pause_vdev(struct ath10k *ar, u32 vdev_id,
3077 enum wmi_tlv_tx_pause_id pause_id,
3078 enum wmi_tlv_tx_pause_action action)
Michal Kaziorb4aa5392015-03-31 10:26:24 +00003079{
3080 struct ath10k_mac_tx_pause arg = {
3081 .vdev_id = vdev_id,
3082 .pause_id = pause_id,
3083 .action = action,
3084 };
3085
3086 spin_lock_bh(&ar->htt.tx_lock);
3087 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3088 IEEE80211_IFACE_ITER_RESUME_ALL,
3089 ath10k_mac_handle_tx_pause_iter,
3090 &arg);
3091 spin_unlock_bh(&ar->htt.tx_lock);
3092}
3093
Michal Kazior42c3aa62013-10-02 11:03:38 +02003094static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
3095{
3096 if (ieee80211_is_mgmt(hdr->frame_control))
3097 return HTT_DATA_TX_EXT_TID_MGMT;
3098
3099 if (!ieee80211_is_data_qos(hdr->frame_control))
3100 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
3101
3102 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
3103 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
3104
3105 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
3106}
3107
Michal Kazior2b37c292014-09-02 11:00:22 +03003108static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02003109{
Michal Kazior2b37c292014-09-02 11:00:22 +03003110 if (vif)
3111 return ath10k_vif_to_arvif(vif)->vdev_id;
Michal Kaziorddb6ad72013-10-02 11:03:39 +02003112
Michal Kazior1bbc0972014-04-08 09:45:47 +03003113 if (ar->monitor_started)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02003114 return ar->monitor_vdev_id;
3115
Michal Kazior7aa7a722014-08-25 12:09:38 +02003116 ath10k_warn(ar, "failed to resolve vdev id\n");
Michal Kaziorddb6ad72013-10-02 11:03:39 +02003117 return 0;
3118}
3119
Michal Kaziord740d8f2015-03-30 09:51:51 +03003120static enum ath10k_hw_txrx_mode
3121ath10k_tx_h_get_txmode(struct ath10k *ar, struct ieee80211_vif *vif,
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003122 struct ieee80211_sta *sta, struct sk_buff *skb)
Michal Kaziord740d8f2015-03-30 09:51:51 +03003123{
3124 const struct ieee80211_hdr *hdr = (void *)skb->data;
3125 __le16 fc = hdr->frame_control;
3126
3127 if (!vif || vif->type == NL80211_IFTYPE_MONITOR)
3128 return ATH10K_HW_TXRX_RAW;
3129
3130 if (ieee80211_is_mgmt(fc))
3131 return ATH10K_HW_TXRX_MGMT;
3132
3133 /* Workaround:
3134 *
3135 * NullFunc frames are mostly used to ping if a client or AP are still
3136 * reachable and responsive. This implies tx status reports must be
3137 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
3138 * come to a conclusion that the other end disappeared and tear down
3139 * BSS connection or it can never disconnect from BSS/client (which is
3140 * the case).
3141 *
3142 * Firmware with HTT older than 3.0 delivers incorrect tx status for
3143 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
3144 * which seems to deliver correct tx reports for NullFunc frames. The
3145 * downside of using it is it ignores client powersave state so it can
3146 * end up disconnecting sleeping clients in AP mode. It should fix STA
3147 * mode though because AP don't sleep.
3148 */
3149 if (ar->htt.target_version_major < 3 &&
3150 (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc)) &&
3151 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX, ar->fw_features))
3152 return ATH10K_HW_TXRX_MGMT;
3153
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003154 /* Workaround:
3155 *
3156 * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
3157 * NativeWifi txmode - it selects AP key instead of peer key. It seems
3158 * to work with Ethernet txmode so use it.
David Liuccec9032015-07-24 20:25:32 +03003159 *
3160 * FIXME: Check if raw mode works with TDLS.
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003161 */
3162 if (ieee80211_is_data_present(fc) && sta && sta->tdls)
3163 return ATH10K_HW_TXRX_ETHERNET;
3164
David Liuccec9032015-07-24 20:25:32 +03003165 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
3166 return ATH10K_HW_TXRX_RAW;
3167
Michal Kaziord740d8f2015-03-30 09:51:51 +03003168 return ATH10K_HW_TXRX_NATIVE_WIFI;
3169}
3170
David Liuccec9032015-07-24 20:25:32 +03003171static bool ath10k_tx_h_use_hwcrypto(struct ieee80211_vif *vif,
3172 struct sk_buff *skb) {
3173 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3174 const u32 mask = IEEE80211_TX_INTFL_DONT_ENCRYPT |
3175 IEEE80211_TX_CTL_INJECTED;
3176 if ((info->flags & mask) == mask)
3177 return false;
3178 if (vif)
3179 return !ath10k_vif_to_arvif(vif)->nohwcrypt;
3180 return true;
3181}
3182
Michal Kazior4b604552014-07-21 21:03:09 +03003183/* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
3184 * Control in the header.
Kalle Valo5e3dd152013-06-12 20:52:10 +03003185 */
Michal Kazior4b604552014-07-21 21:03:09 +03003186static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003187{
3188 struct ieee80211_hdr *hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03003189 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003190 u8 *qos_ctl;
3191
3192 if (!ieee80211_is_data_qos(hdr->frame_control))
3193 return;
3194
3195 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02003196 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
3197 skb->data, (void *)qos_ctl - (void *)skb->data);
3198 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Michal Kaziorc21c64d2014-07-21 21:03:10 +03003199
Michal Kazior8bad8dc2015-03-11 14:25:26 +01003200 /* Some firmware revisions don't handle sending QoS NullFunc well.
3201 * These frames are mainly used for CQM purposes so it doesn't really
3202 * matter whether QoS NullFunc or NullFunc are sent.
Michal Kaziorc21c64d2014-07-21 21:03:10 +03003203 */
Michal Kaziorbf0a26d2015-01-24 12:14:51 +02003204 hdr = (void *)skb->data;
Michal Kazior8bad8dc2015-03-11 14:25:26 +01003205 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
Michal Kaziorc21c64d2014-07-21 21:03:10 +03003206 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
Michal Kazior8bad8dc2015-03-11 14:25:26 +01003207
3208 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003209}
3210
Michal Kaziord740d8f2015-03-30 09:51:51 +03003211static void ath10k_tx_h_8023(struct sk_buff *skb)
3212{
3213 struct ieee80211_hdr *hdr;
3214 struct rfc1042_hdr *rfc1042;
3215 struct ethhdr *eth;
3216 size_t hdrlen;
3217 u8 da[ETH_ALEN];
3218 u8 sa[ETH_ALEN];
3219 __be16 type;
3220
3221 hdr = (void *)skb->data;
3222 hdrlen = ieee80211_hdrlen(hdr->frame_control);
3223 rfc1042 = (void *)skb->data + hdrlen;
3224
3225 ether_addr_copy(da, ieee80211_get_DA(hdr));
3226 ether_addr_copy(sa, ieee80211_get_SA(hdr));
3227 type = rfc1042->snap_type;
3228
3229 skb_pull(skb, hdrlen + sizeof(*rfc1042));
3230 skb_push(skb, sizeof(*eth));
3231
3232 eth = (void *)skb->data;
3233 ether_addr_copy(eth->h_dest, da);
3234 ether_addr_copy(eth->h_source, sa);
3235 eth->h_proto = type;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003236}
3237
Michal Kazior4b604552014-07-21 21:03:09 +03003238static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
3239 struct ieee80211_vif *vif,
3240 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003241{
3242 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003243 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3244
3245 /* This is case only for P2P_GO */
3246 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
3247 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
3248 return;
3249
3250 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
3251 spin_lock_bh(&ar->data_lock);
3252 if (arvif->u.ap.noa_data)
3253 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
3254 GFP_ATOMIC))
3255 memcpy(skb_put(skb, arvif->u.ap.noa_len),
3256 arvif->u.ap.noa_data,
3257 arvif->u.ap.noa_len);
3258 spin_unlock_bh(&ar->data_lock);
3259 }
3260}
3261
Michal Kazior8d6d3622014-11-24 14:58:31 +01003262static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar)
3263{
3264 /* FIXME: Not really sure since when the behaviour changed. At some
3265 * point new firmware stopped requiring creation of peer entries for
3266 * offchannel tx (and actually creating them causes issues with wmi-htc
3267 * tx credit replenishment and reliability). Assuming it's at least 3.4
3268 * because that's when the `freq` was introduced to TX_FRM HTT command.
3269 */
3270 return !(ar->htt.target_version_major >= 3 &&
3271 ar->htt.target_version_minor >= 4);
3272}
3273
Michal Kaziord740d8f2015-03-30 09:51:51 +03003274static int ath10k_mac_tx_wmi_mgmt(struct ath10k *ar, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003275{
Michal Kaziord740d8f2015-03-30 09:51:51 +03003276 struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003277 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003278
Michal Kaziord740d8f2015-03-30 09:51:51 +03003279 spin_lock_bh(&ar->data_lock);
3280
3281 if (skb_queue_len(q) == ATH10K_MAX_NUM_MGMT_PENDING) {
3282 ath10k_warn(ar, "wmi mgmt tx queue is full\n");
3283 ret = -ENOSPC;
3284 goto unlock;
Michal Kazior961d4c32013-08-09 10:13:34 +02003285 }
3286
Michal Kaziord740d8f2015-03-30 09:51:51 +03003287 __skb_queue_tail(q, skb);
3288 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
3289
3290unlock:
3291 spin_unlock_bh(&ar->data_lock);
3292
3293 return ret;
3294}
3295
3296static void ath10k_mac_tx(struct ath10k *ar, struct sk_buff *skb)
3297{
3298 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3299 struct ath10k_htt *htt = &ar->htt;
3300 int ret = 0;
3301
3302 switch (cb->txmode) {
3303 case ATH10K_HW_TXRX_RAW:
3304 case ATH10K_HW_TXRX_NATIVE_WIFI:
3305 case ATH10K_HW_TXRX_ETHERNET:
3306 ret = ath10k_htt_tx(htt, skb);
3307 break;
3308 case ATH10K_HW_TXRX_MGMT:
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003309 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
Michal Kaziord740d8f2015-03-30 09:51:51 +03003310 ar->fw_features))
3311 ret = ath10k_mac_tx_wmi_mgmt(ar, skb);
3312 else if (ar->htt.target_version_major >= 3)
3313 ret = ath10k_htt_tx(htt, skb);
3314 else
3315 ret = ath10k_htt_mgmt_tx(htt, skb);
3316 break;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003317 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003318
3319 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003320 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
3321 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003322 ieee80211_free_txskb(ar->hw, skb);
3323 }
3324}
3325
3326void ath10k_offchan_tx_purge(struct ath10k *ar)
3327{
3328 struct sk_buff *skb;
3329
3330 for (;;) {
3331 skb = skb_dequeue(&ar->offchan_tx_queue);
3332 if (!skb)
3333 break;
3334
3335 ieee80211_free_txskb(ar->hw, skb);
3336 }
3337}
3338
3339void ath10k_offchan_tx_work(struct work_struct *work)
3340{
3341 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
3342 struct ath10k_peer *peer;
3343 struct ieee80211_hdr *hdr;
3344 struct sk_buff *skb;
3345 const u8 *peer_addr;
3346 int vdev_id;
3347 int ret;
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +03003348 unsigned long time_left;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003349
3350 /* FW requirement: We must create a peer before FW will send out
3351 * an offchannel frame. Otherwise the frame will be stuck and
3352 * never transmitted. We delete the peer upon tx completion.
3353 * It is unlikely that a peer for offchannel tx will already be
3354 * present. However it may be in some rare cases so account for that.
3355 * Otherwise we might remove a legitimate peer and break stuff. */
3356
3357 for (;;) {
3358 skb = skb_dequeue(&ar->offchan_tx_queue);
3359 if (!skb)
3360 break;
3361
3362 mutex_lock(&ar->conf_mutex);
3363
Michal Kazior7aa7a722014-08-25 12:09:38 +02003364 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003365 skb);
3366
3367 hdr = (struct ieee80211_hdr *)skb->data;
3368 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003369 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003370
3371 spin_lock_bh(&ar->data_lock);
3372 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
3373 spin_unlock_bh(&ar->data_lock);
3374
3375 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03003376 /* FIXME: should this use ath10k_warn()? */
Michal Kazior7aa7a722014-08-25 12:09:38 +02003377 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003378 peer_addr, vdev_id);
3379
3380 if (!peer) {
Marek Puzyniak7390ed32015-03-30 09:51:52 +03003381 ret = ath10k_peer_create(ar, vdev_id, peer_addr,
3382 WMI_PEER_TYPE_DEFAULT);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003383 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003384 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003385 peer_addr, vdev_id, ret);
3386 }
3387
3388 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08003389 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003390 ar->offchan_tx_skb = skb;
3391 spin_unlock_bh(&ar->data_lock);
3392
Michal Kaziord740d8f2015-03-30 09:51:51 +03003393 ath10k_mac_tx(ar, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003394
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +03003395 time_left =
3396 wait_for_completion_timeout(&ar->offchan_tx_completed, 3 * HZ);
3397 if (time_left == 0)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003398 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003399 skb);
3400
3401 if (!peer) {
3402 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
3403 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003404 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003405 peer_addr, vdev_id, ret);
3406 }
3407
3408 mutex_unlock(&ar->conf_mutex);
3409 }
3410}
3411
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003412void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
3413{
3414 struct sk_buff *skb;
3415
3416 for (;;) {
3417 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3418 if (!skb)
3419 break;
3420
3421 ieee80211_free_txskb(ar->hw, skb);
3422 }
3423}
3424
3425void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
3426{
3427 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
3428 struct sk_buff *skb;
3429 int ret;
3430
3431 for (;;) {
3432 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3433 if (!skb)
3434 break;
3435
3436 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01003437 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003438 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02003439 ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01003440 ieee80211_free_txskb(ar->hw, skb);
3441 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003442 }
3443}
3444
Kalle Valo5e3dd152013-06-12 20:52:10 +03003445/************/
3446/* Scanning */
3447/************/
3448
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003449void __ath10k_scan_finish(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003450{
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003451 lockdep_assert_held(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003452
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003453 switch (ar->scan.state) {
3454 case ATH10K_SCAN_IDLE:
3455 break;
3456 case ATH10K_SCAN_RUNNING:
Michal Kazior7305d3e2014-11-24 14:58:33 +01003457 case ATH10K_SCAN_ABORTING:
3458 if (!ar->scan.is_roc)
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003459 ieee80211_scan_completed(ar->hw,
3460 (ar->scan.state ==
3461 ATH10K_SCAN_ABORTING));
Michal Kaziord710e752015-07-09 13:08:36 +02003462 else if (ar->scan.roc_notify)
3463 ieee80211_remain_on_channel_expired(ar->hw);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003464 /* fall through */
3465 case ATH10K_SCAN_STARTING:
3466 ar->scan.state = ATH10K_SCAN_IDLE;
3467 ar->scan_channel = NULL;
3468 ath10k_offchan_tx_purge(ar);
3469 cancel_delayed_work(&ar->scan.timeout);
3470 complete_all(&ar->scan.completed);
3471 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003472 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003473}
Kalle Valo5e3dd152013-06-12 20:52:10 +03003474
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003475void ath10k_scan_finish(struct ath10k *ar)
3476{
3477 spin_lock_bh(&ar->data_lock);
3478 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003479 spin_unlock_bh(&ar->data_lock);
3480}
3481
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003482static int ath10k_scan_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003483{
3484 struct wmi_stop_scan_arg arg = {
3485 .req_id = 1, /* FIXME */
3486 .req_type = WMI_SCAN_STOP_ONE,
3487 .u.scan_id = ATH10K_SCAN_ID,
3488 };
3489 int ret;
3490
3491 lockdep_assert_held(&ar->conf_mutex);
3492
Kalle Valo5e3dd152013-06-12 20:52:10 +03003493 ret = ath10k_wmi_stop_scan(ar, &arg);
3494 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003495 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003496 goto out;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003497 }
3498
Kalle Valo5e3dd152013-06-12 20:52:10 +03003499 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003500 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003501 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003502 ret = -ETIMEDOUT;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003503 } else if (ret > 0) {
3504 ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003505 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003506
3507out:
3508 /* Scan state should be updated upon scan completion but in case
3509 * firmware fails to deliver the event (for whatever reason) it is
3510 * desired to clean up scan state anyway. Firmware may have just
3511 * dropped the scan completion event delivery due to transport pipe
3512 * being overflown with data and/or it can recover on its own before
3513 * next scan request is submitted.
3514 */
3515 spin_lock_bh(&ar->data_lock);
3516 if (ar->scan.state != ATH10K_SCAN_IDLE)
3517 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003518 spin_unlock_bh(&ar->data_lock);
3519
3520 return ret;
3521}
3522
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003523static void ath10k_scan_abort(struct ath10k *ar)
3524{
3525 int ret;
3526
3527 lockdep_assert_held(&ar->conf_mutex);
3528
3529 spin_lock_bh(&ar->data_lock);
3530
3531 switch (ar->scan.state) {
3532 case ATH10K_SCAN_IDLE:
3533 /* This can happen if timeout worker kicked in and called
3534 * abortion while scan completion was being processed.
3535 */
3536 break;
3537 case ATH10K_SCAN_STARTING:
3538 case ATH10K_SCAN_ABORTING:
Michal Kazior7aa7a722014-08-25 12:09:38 +02003539 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003540 ath10k_scan_state_str(ar->scan.state),
3541 ar->scan.state);
3542 break;
3543 case ATH10K_SCAN_RUNNING:
3544 ar->scan.state = ATH10K_SCAN_ABORTING;
3545 spin_unlock_bh(&ar->data_lock);
3546
3547 ret = ath10k_scan_stop(ar);
3548 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003549 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003550
3551 spin_lock_bh(&ar->data_lock);
3552 break;
3553 }
3554
3555 spin_unlock_bh(&ar->data_lock);
3556}
3557
3558void ath10k_scan_timeout_work(struct work_struct *work)
3559{
3560 struct ath10k *ar = container_of(work, struct ath10k,
3561 scan.timeout.work);
3562
3563 mutex_lock(&ar->conf_mutex);
3564 ath10k_scan_abort(ar);
3565 mutex_unlock(&ar->conf_mutex);
3566}
3567
Kalle Valo5e3dd152013-06-12 20:52:10 +03003568static int ath10k_start_scan(struct ath10k *ar,
3569 const struct wmi_start_scan_arg *arg)
3570{
3571 int ret;
3572
3573 lockdep_assert_held(&ar->conf_mutex);
3574
3575 ret = ath10k_wmi_start_scan(ar, arg);
3576 if (ret)
3577 return ret;
3578
Kalle Valo5e3dd152013-06-12 20:52:10 +03003579 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
3580 if (ret == 0) {
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003581 ret = ath10k_scan_stop(ar);
3582 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003583 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003584
3585 return -ETIMEDOUT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003586 }
3587
Ben Greear2f9eec02015-02-15 16:50:38 +02003588 /* If we failed to start the scan, return error code at
3589 * this point. This is probably due to some issue in the
3590 * firmware, but no need to wedge the driver due to that...
3591 */
3592 spin_lock_bh(&ar->data_lock);
3593 if (ar->scan.state == ATH10K_SCAN_IDLE) {
3594 spin_unlock_bh(&ar->data_lock);
3595 return -EINVAL;
3596 }
3597 spin_unlock_bh(&ar->data_lock);
3598
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003599 /* Add a 200ms margin to account for event/command processing */
3600 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
3601 msecs_to_jiffies(arg->max_scan_time+200));
Kalle Valo5e3dd152013-06-12 20:52:10 +03003602 return 0;
3603}
3604
3605/**********************/
3606/* mac80211 callbacks */
3607/**********************/
3608
3609static void ath10k_tx(struct ieee80211_hw *hw,
3610 struct ieee80211_tx_control *control,
3611 struct sk_buff *skb)
3612{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003613 struct ath10k *ar = hw->priv;
Michal Kazior4b604552014-07-21 21:03:09 +03003614 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3615 struct ieee80211_vif *vif = info->control.vif;
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003616 struct ieee80211_sta *sta = control->sta;
Michal Kazior4b604552014-07-21 21:03:09 +03003617 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Michal Kaziord740d8f2015-03-30 09:51:51 +03003618 __le16 fc = hdr->frame_control;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003619
3620 /* We should disable CCK RATE due to P2P */
3621 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003622 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003623
Michal Kazior4b604552014-07-21 21:03:09 +03003624 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
Michal Kazior6fcafef2015-03-30 09:51:51 +03003625 ATH10K_SKB_CB(skb)->htt.freq = 0;
Michal Kazior4b604552014-07-21 21:03:09 +03003626 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
David Liuccec9032015-07-24 20:25:32 +03003627 ATH10K_SKB_CB(skb)->htt.nohwcrypt = !ath10k_tx_h_use_hwcrypto(vif, skb);
Michal Kazior2b37c292014-09-02 11:00:22 +03003628 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003629 ATH10K_SKB_CB(skb)->txmode = ath10k_tx_h_get_txmode(ar, vif, sta, skb);
Michal Kaziord740d8f2015-03-30 09:51:51 +03003630 ATH10K_SKB_CB(skb)->is_protected = ieee80211_has_protected(fc);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003631
Michal Kaziord740d8f2015-03-30 09:51:51 +03003632 switch (ATH10K_SKB_CB(skb)->txmode) {
3633 case ATH10K_HW_TXRX_MGMT:
3634 case ATH10K_HW_TXRX_NATIVE_WIFI:
Michal Kazior4b604552014-07-21 21:03:09 +03003635 ath10k_tx_h_nwifi(hw, skb);
Michal Kazior4b604552014-07-21 21:03:09 +03003636 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
3637 ath10k_tx_h_seq_no(vif, skb);
Michal Kaziord740d8f2015-03-30 09:51:51 +03003638 break;
3639 case ATH10K_HW_TXRX_ETHERNET:
3640 ath10k_tx_h_8023(skb);
3641 break;
3642 case ATH10K_HW_TXRX_RAW:
David Liuccec9032015-07-24 20:25:32 +03003643 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
3644 WARN_ON_ONCE(1);
3645 ieee80211_free_txskb(hw, skb);
3646 return;
3647 }
Michal Kaziorcf84bd42013-07-16 11:04:54 +02003648 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003649
Kalle Valo5e3dd152013-06-12 20:52:10 +03003650 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
3651 spin_lock_bh(&ar->data_lock);
Michal Kazior8d6d3622014-11-24 14:58:31 +01003652 ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003653 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003654 spin_unlock_bh(&ar->data_lock);
3655
Michal Kazior8d6d3622014-11-24 14:58:31 +01003656 if (ath10k_mac_need_offchan_tx_work(ar)) {
3657 ATH10K_SKB_CB(skb)->htt.freq = 0;
3658 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003659
Michal Kazior8d6d3622014-11-24 14:58:31 +01003660 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
3661 skb);
3662
3663 skb_queue_tail(&ar->offchan_tx_queue, skb);
3664 ieee80211_queue_work(hw, &ar->offchan_tx_work);
3665 return;
3666 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003667 }
3668
Michal Kaziord740d8f2015-03-30 09:51:51 +03003669 ath10k_mac_tx(ar, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003670}
3671
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003672/* Must not be called with conf_mutex held as workers can use that also. */
Michal Kazior7962b0d2014-10-28 10:34:38 +01003673void ath10k_drain_tx(struct ath10k *ar)
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003674{
3675 /* make sure rcu-protected mac80211 tx path itself is drained */
3676 synchronize_net();
3677
3678 ath10k_offchan_tx_purge(ar);
3679 ath10k_mgmt_over_wmi_tx_purge(ar);
3680
3681 cancel_work_sync(&ar->offchan_tx_work);
3682 cancel_work_sync(&ar->wmi_mgmt_tx_work);
3683}
3684
Michal Kazioraffd3212013-07-16 09:54:35 +02003685void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02003686{
Michal Kaziord9bc4b92014-04-23 19:30:06 +03003687 struct ath10k_vif *arvif;
3688
Michal Kazior818bdd12013-07-16 09:38:57 +02003689 lockdep_assert_held(&ar->conf_mutex);
3690
Michal Kazior19337472014-08-28 12:58:16 +02003691 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
3692 ar->filter_flags = 0;
3693 ar->monitor = false;
Michal Kazior500ff9f2015-03-31 10:26:21 +00003694 ar->monitor_arvif = NULL;
Michal Kazior19337472014-08-28 12:58:16 +02003695
3696 if (ar->monitor_started)
Michal Kazior1bbc0972014-04-08 09:45:47 +03003697 ath10k_monitor_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +02003698
3699 ar->monitor_started = false;
Michal Kazior96d828d2015-03-31 10:26:23 +00003700 ar->tx_paused = 0;
Michal Kazior1bbc0972014-04-08 09:45:47 +03003701
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003702 ath10k_scan_finish(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02003703 ath10k_peer_cleanup_all(ar);
3704 ath10k_core_stop(ar);
3705 ath10k_hif_power_down(ar);
3706
3707 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03003708 list_for_each_entry(arvif, &ar->arvifs, list)
3709 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kazior818bdd12013-07-16 09:38:57 +02003710 spin_unlock_bh(&ar->data_lock);
3711}
3712
Ben Greear46acf7b2014-05-16 17:15:38 +03003713static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
3714{
3715 struct ath10k *ar = hw->priv;
3716
3717 mutex_lock(&ar->conf_mutex);
3718
3719 if (ar->cfg_tx_chainmask) {
3720 *tx_ant = ar->cfg_tx_chainmask;
3721 *rx_ant = ar->cfg_rx_chainmask;
3722 } else {
3723 *tx_ant = ar->supp_tx_chainmask;
3724 *rx_ant = ar->supp_rx_chainmask;
3725 }
3726
3727 mutex_unlock(&ar->conf_mutex);
3728
3729 return 0;
3730}
3731
Ben Greear5572a952014-11-24 16:22:10 +02003732static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
3733{
3734 /* It is not clear that allowing gaps in chainmask
3735 * is helpful. Probably it will not do what user
3736 * is hoping for, so warn in that case.
3737 */
3738 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
3739 return;
3740
3741 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
3742 dbg, cm);
3743}
3744
Ben Greear46acf7b2014-05-16 17:15:38 +03003745static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
3746{
3747 int ret;
3748
3749 lockdep_assert_held(&ar->conf_mutex);
3750
Ben Greear5572a952014-11-24 16:22:10 +02003751 ath10k_check_chain_mask(ar, tx_ant, "tx");
3752 ath10k_check_chain_mask(ar, rx_ant, "rx");
3753
Ben Greear46acf7b2014-05-16 17:15:38 +03003754 ar->cfg_tx_chainmask = tx_ant;
3755 ar->cfg_rx_chainmask = rx_ant;
3756
3757 if ((ar->state != ATH10K_STATE_ON) &&
3758 (ar->state != ATH10K_STATE_RESTARTED))
3759 return 0;
3760
3761 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
3762 tx_ant);
3763 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003764 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03003765 ret, tx_ant);
3766 return ret;
3767 }
3768
3769 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
3770 rx_ant);
3771 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003772 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03003773 ret, rx_ant);
3774 return ret;
3775 }
3776
3777 return 0;
3778}
3779
3780static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
3781{
3782 struct ath10k *ar = hw->priv;
3783 int ret;
3784
3785 mutex_lock(&ar->conf_mutex);
3786 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
3787 mutex_unlock(&ar->conf_mutex);
3788 return ret;
3789}
3790
Kalle Valo5e3dd152013-06-12 20:52:10 +03003791static int ath10k_start(struct ieee80211_hw *hw)
3792{
3793 struct ath10k *ar = hw->priv;
Janusz Dziedzic24ab13e2015-04-01 22:53:18 +03003794 u32 burst_enable;
Michal Kazior818bdd12013-07-16 09:38:57 +02003795 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003796
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003797 /*
3798 * This makes sense only when restarting hw. It is harmless to call
3799 * uncoditionally. This is necessary to make sure no HTT/WMI tx
3800 * commands will be submitted while restarting.
3801 */
3802 ath10k_drain_tx(ar);
3803
Michal Kazior548db542013-07-05 16:15:15 +03003804 mutex_lock(&ar->conf_mutex);
3805
Michal Kaziorc5058f52014-05-26 12:46:03 +03003806 switch (ar->state) {
3807 case ATH10K_STATE_OFF:
3808 ar->state = ATH10K_STATE_ON;
3809 break;
3810 case ATH10K_STATE_RESTARTING:
3811 ath10k_halt(ar);
3812 ar->state = ATH10K_STATE_RESTARTED;
3813 break;
3814 case ATH10K_STATE_ON:
3815 case ATH10K_STATE_RESTARTED:
3816 case ATH10K_STATE_WEDGED:
3817 WARN_ON(1);
Michal Kazior818bdd12013-07-16 09:38:57 +02003818 ret = -EINVAL;
Michal Kaziorae254432014-05-26 12:46:02 +03003819 goto err;
Kalle Valo43d2a302014-09-10 18:23:30 +03003820 case ATH10K_STATE_UTF:
3821 ret = -EBUSY;
3822 goto err;
Michal Kazior818bdd12013-07-16 09:38:57 +02003823 }
3824
3825 ret = ath10k_hif_power_up(ar);
3826 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003827 ath10k_err(ar, "Could not init hif: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003828 goto err_off;
Michal Kazior818bdd12013-07-16 09:38:57 +02003829 }
3830
Kalle Valo43d2a302014-09-10 18:23:30 +03003831 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
Michal Kazior818bdd12013-07-16 09:38:57 +02003832 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003833 ath10k_err(ar, "Could not init core: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003834 goto err_power_down;
Michal Kazior818bdd12013-07-16 09:38:57 +02003835 }
3836
Bartosz Markowski226a3392013-09-26 17:47:16 +02003837 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03003838 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003839 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003840 goto err_core_stop;
3841 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003842
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01003843 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03003844 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003845 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003846 goto err_core_stop;
3847 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003848
Michal Kaziorcf327842015-03-31 10:26:25 +00003849 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
3850 ret = ath10k_wmi_adaptive_qcs(ar, true);
3851 if (ret) {
3852 ath10k_warn(ar, "failed to enable adaptive qcs: %d\n",
3853 ret);
3854 goto err_core_stop;
3855 }
3856 }
3857
Janusz Dziedzic24ab13e2015-04-01 22:53:18 +03003858 if (test_bit(WMI_SERVICE_BURST, ar->wmi.svc_map)) {
3859 burst_enable = ar->wmi.pdev_param->burst_enable;
3860 ret = ath10k_wmi_pdev_set_param(ar, burst_enable, 0);
3861 if (ret) {
3862 ath10k_warn(ar, "failed to disable burst: %d\n", ret);
3863 goto err_core_stop;
3864 }
3865 }
3866
Ben Greear46acf7b2014-05-16 17:15:38 +03003867 if (ar->cfg_tx_chainmask)
3868 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
3869 ar->cfg_rx_chainmask);
3870
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003871 /*
3872 * By default FW set ARP frames ac to voice (6). In that case ARP
3873 * exchange is not working properly for UAPSD enabled AP. ARP requests
3874 * which arrives with access category 0 are processed by network stack
3875 * and send back with access category 0, but FW changes access category
3876 * to 6. Set ARP frames access category to best effort (0) solves
3877 * this problem.
3878 */
3879
3880 ret = ath10k_wmi_pdev_set_param(ar,
3881 ar->wmi.pdev_param->arp_ac_override, 0);
3882 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003883 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003884 ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003885 goto err_core_stop;
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003886 }
3887
Ashok Raj Nagarajan575f1c32015-03-19 16:37:59 +05303888 ret = ath10k_wmi_pdev_set_param(ar,
3889 ar->wmi.pdev_param->ani_enable, 1);
3890 if (ret) {
3891 ath10k_warn(ar, "failed to enable ani by default: %d\n",
3892 ret);
3893 goto err_core_stop;
3894 }
3895
Ashok Raj Nagarajanb3e71d72015-03-19 16:38:00 +05303896 ar->ani_enabled = true;
3897
Michal Kaziord6500972014-04-08 09:56:09 +03003898 ar->num_started_vdevs = 0;
Michal Kaziorf7843d72013-07-16 09:38:52 +02003899 ath10k_regd_update(ar);
3900
Simon Wunderlich855aed12014-08-02 09:12:54 +03003901 ath10k_spectral_start(ar);
Rajkumar Manoharan8515b5c2015-03-15 20:36:22 +05303902 ath10k_thermal_set_throttling(ar);
Simon Wunderlich855aed12014-08-02 09:12:54 +03003903
Michal Kaziorae254432014-05-26 12:46:02 +03003904 mutex_unlock(&ar->conf_mutex);
3905 return 0;
3906
3907err_core_stop:
3908 ath10k_core_stop(ar);
3909
3910err_power_down:
3911 ath10k_hif_power_down(ar);
3912
3913err_off:
3914 ar->state = ATH10K_STATE_OFF;
3915
3916err:
Michal Kazior548db542013-07-05 16:15:15 +03003917 mutex_unlock(&ar->conf_mutex);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01003918 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003919}
3920
3921static void ath10k_stop(struct ieee80211_hw *hw)
3922{
3923 struct ath10k *ar = hw->priv;
3924
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003925 ath10k_drain_tx(ar);
3926
Michal Kazior548db542013-07-05 16:15:15 +03003927 mutex_lock(&ar->conf_mutex);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003928 if (ar->state != ATH10K_STATE_OFF) {
Michal Kazior818bdd12013-07-16 09:38:57 +02003929 ath10k_halt(ar);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003930 ar->state = ATH10K_STATE_OFF;
3931 }
Michal Kazior548db542013-07-05 16:15:15 +03003932 mutex_unlock(&ar->conf_mutex);
3933
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003934 cancel_delayed_work_sync(&ar->scan.timeout);
Michal Kazioraffd3212013-07-16 09:54:35 +02003935 cancel_work_sync(&ar->restart_work);
3936}
3937
Michal Kaziorad088bf2013-10-16 15:44:46 +03003938static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02003939{
Michal Kaziorad088bf2013-10-16 15:44:46 +03003940 struct ath10k_vif *arvif;
3941 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02003942
3943 lockdep_assert_held(&ar->conf_mutex);
3944
Michal Kaziorad088bf2013-10-16 15:44:46 +03003945 list_for_each_entry(arvif, &ar->arvifs, list) {
3946 ret = ath10k_mac_vif_setup_ps(arvif);
3947 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003948 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03003949 break;
3950 }
3951 }
Michal Kazioraffd3212013-07-16 09:54:35 +02003952
Michal Kaziorad088bf2013-10-16 15:44:46 +03003953 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003954}
3955
Michal Kazior7d9d5582014-10-21 10:40:15 +03003956static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
3957{
3958 int ret;
3959 u32 param;
3960
3961 lockdep_assert_held(&ar->conf_mutex);
3962
3963 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
3964
3965 param = ar->wmi.pdev_param->txpower_limit2g;
3966 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3967 if (ret) {
3968 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
3969 txpower, ret);
3970 return ret;
3971 }
3972
3973 param = ar->wmi.pdev_param->txpower_limit5g;
3974 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3975 if (ret) {
3976 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
3977 txpower, ret);
3978 return ret;
3979 }
3980
3981 return 0;
3982}
3983
3984static int ath10k_mac_txpower_recalc(struct ath10k *ar)
3985{
3986 struct ath10k_vif *arvif;
3987 int ret, txpower = -1;
3988
3989 lockdep_assert_held(&ar->conf_mutex);
3990
3991 list_for_each_entry(arvif, &ar->arvifs, list) {
3992 WARN_ON(arvif->txpower < 0);
3993
3994 if (txpower == -1)
3995 txpower = arvif->txpower;
3996 else
3997 txpower = min(txpower, arvif->txpower);
3998 }
3999
4000 if (WARN_ON(txpower == -1))
4001 return -EINVAL;
4002
4003 ret = ath10k_mac_txpower_setup(ar, txpower);
4004 if (ret) {
4005 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
4006 txpower, ret);
4007 return ret;
4008 }
4009
4010 return 0;
4011}
4012
Kalle Valo5e3dd152013-06-12 20:52:10 +03004013static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
4014{
Kalle Valo5e3dd152013-06-12 20:52:10 +03004015 struct ath10k *ar = hw->priv;
4016 struct ieee80211_conf *conf = &hw->conf;
4017 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004018
4019 mutex_lock(&ar->conf_mutex);
4020
Michal Kazioraffd3212013-07-16 09:54:35 +02004021 if (changed & IEEE80211_CONF_CHANGE_PS)
4022 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004023
4024 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
Michal Kazior19337472014-08-28 12:58:16 +02004025 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
4026 ret = ath10k_monitor_recalc(ar);
4027 if (ret)
4028 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004029 }
4030
4031 mutex_unlock(&ar->conf_mutex);
4032 return ret;
4033}
4034
Ben Greear5572a952014-11-24 16:22:10 +02004035static u32 get_nss_from_chainmask(u16 chain_mask)
4036{
4037 if ((chain_mask & 0x15) == 0x15)
4038 return 4;
4039 else if ((chain_mask & 0x7) == 0x7)
4040 return 3;
4041 else if ((chain_mask & 0x3) == 0x3)
4042 return 2;
4043 return 1;
4044}
4045
Kalle Valo5e3dd152013-06-12 20:52:10 +03004046/*
4047 * TODO:
4048 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
4049 * because we will send mgmt frames without CCK. This requirement
4050 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
4051 * in the TX packet.
4052 */
4053static int ath10k_add_interface(struct ieee80211_hw *hw,
4054 struct ieee80211_vif *vif)
4055{
4056 struct ath10k *ar = hw->priv;
4057 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4058 enum wmi_sta_powersave_param param;
4059 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02004060 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004061 int bit;
Michal Kazior96d828d2015-03-31 10:26:23 +00004062 int i;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004063 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004064
Johannes Berg848955c2014-11-11 12:48:42 +01004065 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
4066
Kalle Valo5e3dd152013-06-12 20:52:10 +03004067 mutex_lock(&ar->conf_mutex);
4068
Michal Kazior0dbd09e2013-07-31 10:55:14 +02004069 memset(arvif, 0, sizeof(*arvif));
4070
Kalle Valo5e3dd152013-06-12 20:52:10 +03004071 arvif->ar = ar;
4072 arvif->vif = vif;
4073
Ben Greeare63b33f2013-10-22 14:54:14 -07004074 INIT_LIST_HEAD(&arvif->list);
Michal Kazior81a9a172015-03-05 16:02:17 +02004075 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
Michal Kaziorcc9904e2015-03-10 16:22:01 +02004076 INIT_DELAYED_WORK(&arvif->connection_loss_work,
4077 ath10k_mac_vif_sta_connection_loss_work);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03004078
Michal Kazior45c9abc2015-04-21 20:42:58 +03004079 for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) {
4080 arvif->bitrate_mask.control[i].legacy = 0xffffffff;
4081 memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff,
4082 sizeof(arvif->bitrate_mask.control[i].ht_mcs));
4083 memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff,
4084 sizeof(arvif->bitrate_mask.control[i].vht_mcs));
4085 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004086
Ben Greeara9aefb32014-08-12 11:02:19 +03004087 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004088 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03004089 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03004090 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004091 }
Ben Greear16c11172014-09-23 14:17:16 -07004092 bit = __ffs64(ar->free_vdev_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004093
Ben Greear16c11172014-09-23 14:17:16 -07004094 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
4095 bit, ar->free_vdev_map);
4096
4097 arvif->vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004098 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004099
Kalle Valo5e3dd152013-06-12 20:52:10 +03004100 switch (vif->type) {
Michal Kazior75d2bd42014-12-12 12:41:39 +01004101 case NL80211_IFTYPE_P2P_DEVICE:
4102 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4103 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
4104 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004105 case NL80211_IFTYPE_UNSPECIFIED:
4106 case NL80211_IFTYPE_STATION:
4107 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4108 if (vif->p2p)
4109 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
4110 break;
4111 case NL80211_IFTYPE_ADHOC:
4112 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
4113 break;
4114 case NL80211_IFTYPE_AP:
4115 arvif->vdev_type = WMI_VDEV_TYPE_AP;
4116
4117 if (vif->p2p)
4118 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
4119 break;
4120 case NL80211_IFTYPE_MONITOR:
4121 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
4122 break;
4123 default:
4124 WARN_ON(1);
4125 break;
4126 }
4127
Michal Kazior96d828d2015-03-31 10:26:23 +00004128 /* Using vdev_id as queue number will make it very easy to do per-vif
4129 * tx queue locking. This shouldn't wrap due to interface combinations
4130 * but do a modulo for correctness sake and prevent using offchannel tx
4131 * queues for regular vif tx.
4132 */
4133 vif->cab_queue = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
4134 for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++)
4135 vif->hw_queue[i] = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
4136
Michal Kazior64badcb2014-09-18 11:18:02 +03004137 /* Some firmware revisions don't wait for beacon tx completion before
4138 * sending another SWBA event. This could lead to hardware using old
4139 * (freed) beacon data in some cases, e.g. tx credit starvation
4140 * combined with missed TBTT. This is very very rare.
4141 *
4142 * On non-IOMMU-enabled hosts this could be a possible security issue
4143 * because hw could beacon some random data on the air. On
4144 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
4145 * device would crash.
4146 *
4147 * Since there are no beacon tx completions (implicit nor explicit)
4148 * propagated to host the only workaround for this is to allocate a
4149 * DMA-coherent buffer for a lifetime of a vif and use it for all
4150 * beacon tx commands. Worst case for this approach is some beacons may
4151 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
4152 */
4153 if (vif->type == NL80211_IFTYPE_ADHOC ||
4154 vif->type == NL80211_IFTYPE_AP) {
4155 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
4156 IEEE80211_MAX_FRAME_LEN,
4157 &arvif->beacon_paddr,
Rajkumar Manoharan82d7aba2014-10-10 17:38:27 +05304158 GFP_ATOMIC);
Michal Kazior64badcb2014-09-18 11:18:02 +03004159 if (!arvif->beacon_buf) {
4160 ret = -ENOMEM;
4161 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
4162 ret);
4163 goto err;
4164 }
4165 }
David Liuccec9032015-07-24 20:25:32 +03004166 if (test_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags))
4167 arvif->nohwcrypt = true;
4168
4169 if (arvif->nohwcrypt &&
4170 !test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
4171 ath10k_warn(ar, "cryptmode module param needed for sw crypto\n");
4172 goto err;
4173 }
Michal Kazior64badcb2014-09-18 11:18:02 +03004174
4175 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
4176 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
4177 arvif->beacon_buf ? "single-buf" : "per-skb");
Kalle Valo5e3dd152013-06-12 20:52:10 +03004178
4179 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
4180 arvif->vdev_subtype, vif->addr);
4181 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004182 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004183 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004184 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004185 }
4186
Ben Greear16c11172014-09-23 14:17:16 -07004187 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03004188 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004189
Michal Kazior46725b152015-01-28 09:57:49 +02004190 /* It makes no sense to have firmware do keepalives. mac80211 already
4191 * takes care of this with idle connection polling.
4192 */
4193 ret = ath10k_mac_vif_disable_keepalive(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004194 if (ret) {
Michal Kazior46725b152015-01-28 09:57:49 +02004195 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004196 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004197 goto err_vdev_delete;
4198 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004199
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004200 arvif->def_wep_key_idx = -1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004201
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004202 vdev_param = ar->wmi.vdev_param->tx_encap_type;
4203 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004204 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02004205 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14a2013-10-16 15:44:45 +03004206 if (ret && ret != -EOPNOTSUPP) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004207 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004208 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004209 goto err_vdev_delete;
4210 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004211
Ben Greear5572a952014-11-24 16:22:10 +02004212 if (ar->cfg_tx_chainmask) {
4213 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
4214
4215 vdev_param = ar->wmi.vdev_param->nss;
4216 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4217 nss);
4218 if (ret) {
4219 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
4220 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
4221 ret);
4222 goto err_vdev_delete;
4223 }
4224 }
4225
Michal Kaziore57e0572015-03-24 13:14:03 +00004226 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4227 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
Marek Puzyniak7390ed32015-03-30 09:51:52 +03004228 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr,
4229 WMI_PEER_TYPE_DEFAULT);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004230 if (ret) {
Michal Kaziore57e0572015-03-24 13:14:03 +00004231 ath10k_warn(ar, "failed to create vdev %i peer for AP/IBSS: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004232 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004233 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004234 }
Michal Kaziore57e0572015-03-24 13:14:03 +00004235 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01004236
Michal Kaziore57e0572015-03-24 13:14:03 +00004237 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
Kalle Valo5a13e762014-01-20 11:01:46 +02004238 ret = ath10k_mac_set_kickout(arvif);
4239 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004240 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004241 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +02004242 goto err_peer_delete;
4243 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004244 }
4245
4246 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
4247 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
4248 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4249 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4250 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004251 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004252 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004253 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004254 goto err_peer_delete;
4255 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004256
Michal Kazior9f9b5742014-12-12 12:41:36 +01004257 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004258 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01004259 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004260 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004261 goto err_peer_delete;
4262 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004263
Michal Kazior9f9b5742014-12-12 12:41:36 +01004264 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004265 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01004266 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004267 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004268 goto err_peer_delete;
4269 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004270 }
4271
Michal Kazior424121c2013-07-22 14:13:31 +02004272 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004273 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004274 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03004275 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004276 goto err_peer_delete;
4277 }
Michal Kazior679c54a2013-07-05 16:15:04 +03004278
Michal Kazior424121c2013-07-22 14:13:31 +02004279 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004280 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004281 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03004282 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004283 goto err_peer_delete;
4284 }
Michal Kazior679c54a2013-07-05 16:15:04 +03004285
Michal Kazior7d9d5582014-10-21 10:40:15 +03004286 arvif->txpower = vif->bss_conf.txpower;
4287 ret = ath10k_mac_txpower_recalc(ar);
4288 if (ret) {
4289 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
4290 goto err_peer_delete;
4291 }
4292
Michal Kazior500ff9f2015-03-31 10:26:21 +00004293 if (vif->type == NL80211_IFTYPE_MONITOR) {
4294 ar->monitor_arvif = arvif;
4295 ret = ath10k_monitor_recalc(ar);
4296 if (ret) {
4297 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4298 goto err_peer_delete;
4299 }
4300 }
4301
Kalle Valo5e3dd152013-06-12 20:52:10 +03004302 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004303 return 0;
4304
4305err_peer_delete:
Michal Kaziore57e0572015-03-24 13:14:03 +00004306 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4307 arvif->vdev_type == WMI_VDEV_TYPE_IBSS)
Michal Kazior9dad14a2013-10-16 15:44:45 +03004308 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
4309
4310err_vdev_delete:
4311 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
Ben Greear16c11172014-09-23 14:17:16 -07004312 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03004313 list_del(&arvif->list);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004314
4315err:
Michal Kazior64badcb2014-09-18 11:18:02 +03004316 if (arvif->beacon_buf) {
4317 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
4318 arvif->beacon_buf, arvif->beacon_paddr);
4319 arvif->beacon_buf = NULL;
4320 }
4321
Michal Kazior9dad14a2013-10-16 15:44:45 +03004322 mutex_unlock(&ar->conf_mutex);
4323
Kalle Valo5e3dd152013-06-12 20:52:10 +03004324 return ret;
4325}
4326
Michal Kaziorb4aa5392015-03-31 10:26:24 +00004327static void ath10k_mac_vif_tx_unlock_all(struct ath10k_vif *arvif)
4328{
4329 int i;
4330
4331 for (i = 0; i < BITS_PER_LONG; i++)
4332 ath10k_mac_vif_tx_unlock(arvif, i);
4333}
4334
Kalle Valo5e3dd152013-06-12 20:52:10 +03004335static void ath10k_remove_interface(struct ieee80211_hw *hw,
4336 struct ieee80211_vif *vif)
4337{
4338 struct ath10k *ar = hw->priv;
4339 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4340 int ret;
4341
Michal Kazior81a9a172015-03-05 16:02:17 +02004342 cancel_work_sync(&arvif->ap_csa_work);
Michal Kaziorcc9904e2015-03-10 16:22:01 +02004343 cancel_delayed_work_sync(&arvif->connection_loss_work);
Michal Kazior81a9a172015-03-05 16:02:17 +02004344
Sujith Manoharan5d011f52014-11-25 11:47:00 +05304345 mutex_lock(&ar->conf_mutex);
4346
Michal Kaziored543882013-09-13 14:16:56 +02004347 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03004348 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kaziored543882013-09-13 14:16:56 +02004349 spin_unlock_bh(&ar->data_lock);
4350
Simon Wunderlich855aed12014-08-02 09:12:54 +03004351 ret = ath10k_spectral_vif_stop(arvif);
4352 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004353 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03004354 arvif->vdev_id, ret);
4355
Ben Greear16c11172014-09-23 14:17:16 -07004356 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03004357 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004358
Michal Kaziore57e0572015-03-24 13:14:03 +00004359 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4360 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
Michal Kazior2c512052015-02-15 16:50:40 +02004361 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
4362 vif->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004363 if (ret)
Michal Kaziore57e0572015-03-24 13:14:03 +00004364 ath10k_warn(ar, "failed to submit AP/IBSS self-peer removal on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004365 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004366
4367 kfree(arvif->u.ap.noa_data);
4368 }
4369
Michal Kazior7aa7a722014-08-25 12:09:38 +02004370 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004371 arvif->vdev_id);
4372
Kalle Valo5e3dd152013-06-12 20:52:10 +03004373 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
4374 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004375 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004376 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004377
Michal Kazior2c512052015-02-15 16:50:40 +02004378 /* Some firmware revisions don't notify host about self-peer removal
4379 * until after associated vdev is deleted.
4380 */
Michal Kaziore57e0572015-03-24 13:14:03 +00004381 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4382 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
Michal Kazior2c512052015-02-15 16:50:40 +02004383 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
4384 vif->addr);
4385 if (ret)
4386 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
4387 arvif->vdev_id, ret);
4388
4389 spin_lock_bh(&ar->data_lock);
4390 ar->num_peers--;
4391 spin_unlock_bh(&ar->data_lock);
4392 }
4393
Kalle Valo5e3dd152013-06-12 20:52:10 +03004394 ath10k_peer_cleanup(ar, arvif->vdev_id);
4395
Michal Kazior500ff9f2015-03-31 10:26:21 +00004396 if (vif->type == NL80211_IFTYPE_MONITOR) {
4397 ar->monitor_arvif = NULL;
4398 ret = ath10k_monitor_recalc(ar);
4399 if (ret)
4400 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4401 }
4402
Michal Kaziorb4aa5392015-03-31 10:26:24 +00004403 spin_lock_bh(&ar->htt.tx_lock);
4404 ath10k_mac_vif_tx_unlock_all(arvif);
4405 spin_unlock_bh(&ar->htt.tx_lock);
4406
Kalle Valo5e3dd152013-06-12 20:52:10 +03004407 mutex_unlock(&ar->conf_mutex);
4408}
4409
4410/*
4411 * FIXME: Has to be verified.
4412 */
4413#define SUPPORTED_FILTERS \
Johannes Bergdf140462015-04-22 14:40:58 +02004414 (FIF_ALLMULTI | \
Kalle Valo5e3dd152013-06-12 20:52:10 +03004415 FIF_CONTROL | \
4416 FIF_PSPOLL | \
4417 FIF_OTHER_BSS | \
4418 FIF_BCN_PRBRESP_PROMISC | \
4419 FIF_PROBE_REQ | \
4420 FIF_FCSFAIL)
4421
4422static void ath10k_configure_filter(struct ieee80211_hw *hw,
4423 unsigned int changed_flags,
4424 unsigned int *total_flags,
4425 u64 multicast)
4426{
4427 struct ath10k *ar = hw->priv;
4428 int ret;
4429
4430 mutex_lock(&ar->conf_mutex);
4431
4432 changed_flags &= SUPPORTED_FILTERS;
4433 *total_flags &= SUPPORTED_FILTERS;
4434 ar->filter_flags = *total_flags;
4435
Michal Kazior19337472014-08-28 12:58:16 +02004436 ret = ath10k_monitor_recalc(ar);
4437 if (ret)
4438 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004439
4440 mutex_unlock(&ar->conf_mutex);
4441}
4442
4443static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
4444 struct ieee80211_vif *vif,
4445 struct ieee80211_bss_conf *info,
4446 u32 changed)
4447{
4448 struct ath10k *ar = hw->priv;
4449 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4450 int ret = 0;
Kalle Valoaf762c02014-09-14 12:50:17 +03004451 u32 vdev_param, pdev_param, slottime, preamble;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004452
4453 mutex_lock(&ar->conf_mutex);
4454
4455 if (changed & BSS_CHANGED_IBSS)
4456 ath10k_control_ibss(arvif, info, vif->addr);
4457
4458 if (changed & BSS_CHANGED_BEACON_INT) {
4459 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004460 vdev_param = ar->wmi.vdev_param->beacon_interval;
4461 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004462 arvif->beacon_interval);
Michal Kazior7aa7a722014-08-25 12:09:38 +02004463 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004464 "mac vdev %d beacon_interval %d\n",
4465 arvif->vdev_id, arvif->beacon_interval);
4466
Kalle Valo5e3dd152013-06-12 20:52:10 +03004467 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004468 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004469 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004470 }
4471
4472 if (changed & BSS_CHANGED_BEACON) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004473 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004474 "vdev %d set beacon tx mode to staggered\n",
4475 arvif->vdev_id);
4476
Bartosz Markowski226a3392013-09-26 17:47:16 +02004477 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
4478 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004479 WMI_BEACON_STAGGERED_MODE);
4480 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004481 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004482 arvif->vdev_id, ret);
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02004483
4484 ret = ath10k_mac_setup_bcn_tmpl(arvif);
4485 if (ret)
4486 ath10k_warn(ar, "failed to update beacon template: %d\n",
4487 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004488 }
4489
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02004490 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
4491 ret = ath10k_mac_setup_prb_tmpl(arvif);
4492 if (ret)
4493 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
4494 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004495 }
4496
Michal Kaziorba2479f2015-01-24 12:14:51 +02004497 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004498 arvif->dtim_period = info->dtim_period;
4499
Michal Kazior7aa7a722014-08-25 12:09:38 +02004500 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004501 "mac vdev %d dtim_period %d\n",
4502 arvif->vdev_id, arvif->dtim_period);
4503
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004504 vdev_param = ar->wmi.vdev_param->dtim_period;
4505 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004506 arvif->dtim_period);
4507 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004508 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004509 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004510 }
4511
4512 if (changed & BSS_CHANGED_SSID &&
4513 vif->type == NL80211_IFTYPE_AP) {
4514 arvif->u.ap.ssid_len = info->ssid_len;
4515 if (info->ssid_len)
4516 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
4517 arvif->u.ap.hidden_ssid = info->hidden_ssid;
4518 }
4519
Michal Kazior077efc82014-10-21 10:10:29 +03004520 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
4521 ether_addr_copy(arvif->bssid, info->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004522
4523 if (changed & BSS_CHANGED_BEACON_ENABLED)
4524 ath10k_control_beaconing(arvif, info);
4525
4526 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02004527 arvif->use_cts_prot = info->use_cts_prot;
Michal Kazior7aa7a722014-08-25 12:09:38 +02004528 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02004529 arvif->vdev_id, info->use_cts_prot);
Kalle Valo60c3daa2013-09-08 17:56:07 +03004530
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02004531 ret = ath10k_recalc_rtscts_prot(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004532 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004533 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004534 arvif->vdev_id, ret);
Michal Kaziora87fd4b2015-03-02 11:21:17 +01004535
4536 vdev_param = ar->wmi.vdev_param->protection_mode;
4537 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4538 info->use_cts_prot ? 1 : 0);
4539 if (ret)
4540 ath10k_warn(ar, "failed to set protection mode %d on vdev %i: %d\n",
4541 info->use_cts_prot, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004542 }
4543
4544 if (changed & BSS_CHANGED_ERP_SLOT) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004545 if (info->use_short_slot)
4546 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
4547
4548 else
4549 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
4550
Michal Kazior7aa7a722014-08-25 12:09:38 +02004551 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004552 arvif->vdev_id, slottime);
4553
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004554 vdev_param = ar->wmi.vdev_param->slot_time;
4555 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004556 slottime);
4557 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004558 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004559 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004560 }
4561
4562 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004563 if (info->use_short_preamble)
4564 preamble = WMI_VDEV_PREAMBLE_SHORT;
4565 else
4566 preamble = WMI_VDEV_PREAMBLE_LONG;
4567
Michal Kazior7aa7a722014-08-25 12:09:38 +02004568 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004569 "mac vdev %d preamble %dn",
4570 arvif->vdev_id, preamble);
4571
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004572 vdev_param = ar->wmi.vdev_param->preamble;
4573 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004574 preamble);
4575 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004576 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004577 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004578 }
4579
4580 if (changed & BSS_CHANGED_ASSOC) {
Michal Kaziore556f112014-08-28 12:58:17 +02004581 if (info->assoc) {
4582 /* Workaround: Make sure monitor vdev is not running
4583 * when associating to prevent some firmware revisions
4584 * (e.g. 10.1 and 10.2) from crashing.
4585 */
4586 if (ar->monitor_started)
4587 ath10k_monitor_stop(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004588 ath10k_bss_assoc(hw, vif, info);
Michal Kaziore556f112014-08-28 12:58:17 +02004589 ath10k_monitor_recalc(ar);
Michal Kazior077efc82014-10-21 10:10:29 +03004590 } else {
4591 ath10k_bss_disassoc(hw, vif);
Michal Kaziore556f112014-08-28 12:58:17 +02004592 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004593 }
4594
Michal Kazior7d9d5582014-10-21 10:40:15 +03004595 if (changed & BSS_CHANGED_TXPOWER) {
4596 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
4597 arvif->vdev_id, info->txpower);
4598
4599 arvif->txpower = info->txpower;
4600 ret = ath10k_mac_txpower_recalc(ar);
4601 if (ret)
4602 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
4603 }
4604
Michal Kaziorbf14e652014-12-12 12:41:38 +01004605 if (changed & BSS_CHANGED_PS) {
Michal Kaziorcffb41f2015-02-13 13:30:16 +01004606 arvif->ps = vif->bss_conf.ps;
4607
4608 ret = ath10k_config_ps(ar);
Michal Kaziorbf14e652014-12-12 12:41:38 +01004609 if (ret)
4610 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
4611 arvif->vdev_id, ret);
4612 }
4613
Kalle Valo5e3dd152013-06-12 20:52:10 +03004614 mutex_unlock(&ar->conf_mutex);
4615}
4616
4617static int ath10k_hw_scan(struct ieee80211_hw *hw,
4618 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02004619 struct ieee80211_scan_request *hw_req)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004620{
4621 struct ath10k *ar = hw->priv;
4622 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
David Spinadelc56ef672014-02-05 15:21:13 +02004623 struct cfg80211_scan_request *req = &hw_req->req;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004624 struct wmi_start_scan_arg arg;
4625 int ret = 0;
4626 int i;
4627
4628 mutex_lock(&ar->conf_mutex);
4629
4630 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004631 switch (ar->scan.state) {
4632 case ATH10K_SCAN_IDLE:
4633 reinit_completion(&ar->scan.started);
4634 reinit_completion(&ar->scan.completed);
4635 ar->scan.state = ATH10K_SCAN_STARTING;
4636 ar->scan.is_roc = false;
4637 ar->scan.vdev_id = arvif->vdev_id;
4638 ret = 0;
4639 break;
4640 case ATH10K_SCAN_STARTING:
4641 case ATH10K_SCAN_RUNNING:
4642 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004643 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004644 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004645 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004646 spin_unlock_bh(&ar->data_lock);
4647
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004648 if (ret)
4649 goto exit;
4650
Kalle Valo5e3dd152013-06-12 20:52:10 +03004651 memset(&arg, 0, sizeof(arg));
4652 ath10k_wmi_start_scan_init(ar, &arg);
4653 arg.vdev_id = arvif->vdev_id;
4654 arg.scan_id = ATH10K_SCAN_ID;
4655
Kalle Valo5e3dd152013-06-12 20:52:10 +03004656 if (req->ie_len) {
4657 arg.ie_len = req->ie_len;
4658 memcpy(arg.ie, req->ie, arg.ie_len);
4659 }
4660
4661 if (req->n_ssids) {
4662 arg.n_ssids = req->n_ssids;
4663 for (i = 0; i < arg.n_ssids; i++) {
4664 arg.ssids[i].len = req->ssids[i].ssid_len;
4665 arg.ssids[i].ssid = req->ssids[i].ssid;
4666 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02004667 } else {
4668 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004669 }
4670
4671 if (req->n_channels) {
4672 arg.n_channels = req->n_channels;
4673 for (i = 0; i < arg.n_channels; i++)
4674 arg.channels[i] = req->channels[i]->center_freq;
4675 }
4676
4677 ret = ath10k_start_scan(ar, &arg);
4678 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004679 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004680 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004681 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004682 spin_unlock_bh(&ar->data_lock);
4683 }
4684
4685exit:
4686 mutex_unlock(&ar->conf_mutex);
4687 return ret;
4688}
4689
4690static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
4691 struct ieee80211_vif *vif)
4692{
4693 struct ath10k *ar = hw->priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004694
4695 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004696 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004697 mutex_unlock(&ar->conf_mutex);
Michal Kazior4eb2e162014-10-28 10:23:09 +01004698
4699 cancel_delayed_work_sync(&ar->scan.timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004700}
4701
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004702static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
4703 struct ath10k_vif *arvif,
4704 enum set_key_cmd cmd,
4705 struct ieee80211_key_conf *key)
4706{
4707 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
4708 int ret;
4709
4710 /* 10.1 firmware branch requires default key index to be set to group
4711 * key index after installing it. Otherwise FW/HW Txes corrupted
4712 * frames with multi-vif APs. This is not required for main firmware
4713 * branch (e.g. 636).
4714 *
Michal Kazior8461baf2015-04-10 13:23:22 +00004715 * This is also needed for 636 fw for IBSS-RSN to work more reliably.
4716 *
4717 * FIXME: It remains unknown if this is required for multi-vif STA
4718 * interfaces on 10.1.
4719 */
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004720
Michal Kazior8461baf2015-04-10 13:23:22 +00004721 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
4722 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004723 return;
4724
4725 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
4726 return;
4727
4728 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
4729 return;
4730
4731 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4732 return;
4733
4734 if (cmd != SET_KEY)
4735 return;
4736
4737 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4738 key->keyidx);
4739 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004740 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004741 arvif->vdev_id, ret);
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004742}
4743
Kalle Valo5e3dd152013-06-12 20:52:10 +03004744static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
4745 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
4746 struct ieee80211_key_conf *key)
4747{
4748 struct ath10k *ar = hw->priv;
4749 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4750 struct ath10k_peer *peer;
4751 const u8 *peer_addr;
4752 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
4753 key->cipher == WLAN_CIPHER_SUITE_WEP104;
4754 int ret = 0;
Michal Kazior29a10002015-04-10 13:05:58 +00004755 int ret2;
Michal Kazior370e5672015-02-18 14:02:26 +01004756 u32 flags = 0;
Michal Kazior29a10002015-04-10 13:05:58 +00004757 u32 flags2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004758
Bartosz Markowskid7131c02015-03-10 14:32:19 +01004759 /* this one needs to be done in software */
4760 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
4761 return 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004762
David Liuccec9032015-07-24 20:25:32 +03004763 if (arvif->nohwcrypt)
4764 return 1;
4765
Kalle Valo5e3dd152013-06-12 20:52:10 +03004766 if (key->keyidx > WMI_MAX_KEY_INDEX)
4767 return -ENOSPC;
4768
4769 mutex_lock(&ar->conf_mutex);
4770
4771 if (sta)
4772 peer_addr = sta->addr;
4773 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
4774 peer_addr = vif->bss_conf.bssid;
4775 else
4776 peer_addr = vif->addr;
4777
4778 key->hw_key_idx = key->keyidx;
4779
Michal Kazior7c8cc7e2015-04-01 22:53:19 +03004780 if (is_wep) {
4781 if (cmd == SET_KEY)
4782 arvif->wep_keys[key->keyidx] = key;
4783 else
4784 arvif->wep_keys[key->keyidx] = NULL;
4785 }
4786
Kalle Valo5e3dd152013-06-12 20:52:10 +03004787 /* the peer should not disappear in mid-way (unless FW goes awry) since
4788 * we already hold conf_mutex. we just make sure its there now. */
4789 spin_lock_bh(&ar->data_lock);
4790 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4791 spin_unlock_bh(&ar->data_lock);
4792
4793 if (!peer) {
4794 if (cmd == SET_KEY) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004795 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03004796 peer_addr);
4797 ret = -EOPNOTSUPP;
4798 goto exit;
4799 } else {
4800 /* if the peer doesn't exist there is no key to disable
4801 * anymore */
4802 goto exit;
4803 }
4804 }
4805
Michal Kazior7cc45732015-03-09 14:24:17 +01004806 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4807 flags |= WMI_KEY_PAIRWISE;
4808 else
4809 flags |= WMI_KEY_GROUP;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004810
Kalle Valo5e3dd152013-06-12 20:52:10 +03004811 if (is_wep) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004812 if (cmd == DISABLE_KEY)
4813 ath10k_clear_vdev_key(arvif, key);
Michal Kazior370e5672015-02-18 14:02:26 +01004814
Michal Kaziorad325cb2015-02-18 14:02:27 +01004815 /* When WEP keys are uploaded it's possible that there are
4816 * stations associated already (e.g. when merging) without any
4817 * keys. Static WEP needs an explicit per-peer key upload.
4818 */
4819 if (vif->type == NL80211_IFTYPE_ADHOC &&
4820 cmd == SET_KEY)
4821 ath10k_mac_vif_update_wep_key(arvif, key);
4822
Michal Kazior370e5672015-02-18 14:02:26 +01004823 /* 802.1x never sets the def_wep_key_idx so each set_key()
4824 * call changes default tx key.
4825 *
4826 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
4827 * after first set_key().
4828 */
4829 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
4830 flags |= WMI_KEY_TX_USAGE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004831 }
4832
Michal Kazior370e5672015-02-18 14:02:26 +01004833 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004834 if (ret) {
David Liuccec9032015-07-24 20:25:32 +03004835 WARN_ON(ret > 0);
Michal Kazior7aa7a722014-08-25 12:09:38 +02004836 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004837 arvif->vdev_id, peer_addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004838 goto exit;
4839 }
4840
Michal Kazior29a10002015-04-10 13:05:58 +00004841 /* mac80211 sets static WEP keys as groupwise while firmware requires
4842 * them to be installed twice as both pairwise and groupwise.
4843 */
4844 if (is_wep && !sta && vif->type == NL80211_IFTYPE_STATION) {
4845 flags2 = flags;
4846 flags2 &= ~WMI_KEY_GROUP;
4847 flags2 |= WMI_KEY_PAIRWISE;
4848
4849 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags2);
4850 if (ret) {
David Liuccec9032015-07-24 20:25:32 +03004851 WARN_ON(ret > 0);
Michal Kazior29a10002015-04-10 13:05:58 +00004852 ath10k_warn(ar, "failed to install (ucast) key for vdev %i peer %pM: %d\n",
4853 arvif->vdev_id, peer_addr, ret);
4854 ret2 = ath10k_install_key(arvif, key, DISABLE_KEY,
4855 peer_addr, flags);
David Liuccec9032015-07-24 20:25:32 +03004856 if (ret2) {
4857 WARN_ON(ret2 > 0);
Michal Kazior29a10002015-04-10 13:05:58 +00004858 ath10k_warn(ar, "failed to disable (mcast) key for vdev %i peer %pM: %d\n",
4859 arvif->vdev_id, peer_addr, ret2);
David Liuccec9032015-07-24 20:25:32 +03004860 }
Michal Kazior29a10002015-04-10 13:05:58 +00004861 goto exit;
4862 }
4863 }
4864
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004865 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
4866
Kalle Valo5e3dd152013-06-12 20:52:10 +03004867 spin_lock_bh(&ar->data_lock);
4868 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4869 if (peer && cmd == SET_KEY)
4870 peer->keys[key->keyidx] = key;
4871 else if (peer && cmd == DISABLE_KEY)
4872 peer->keys[key->keyidx] = NULL;
4873 else if (peer == NULL)
4874 /* impossible unless FW goes crazy */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004875 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004876 spin_unlock_bh(&ar->data_lock);
4877
4878exit:
4879 mutex_unlock(&ar->conf_mutex);
4880 return ret;
4881}
4882
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004883static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
4884 struct ieee80211_vif *vif,
4885 int keyidx)
4886{
4887 struct ath10k *ar = hw->priv;
4888 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4889 int ret;
4890
4891 mutex_lock(&arvif->ar->conf_mutex);
4892
4893 if (arvif->ar->state != ATH10K_STATE_ON)
4894 goto unlock;
4895
4896 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
4897 arvif->vdev_id, keyidx);
4898
4899 ret = ath10k_wmi_vdev_set_param(arvif->ar,
4900 arvif->vdev_id,
4901 arvif->ar->wmi.vdev_param->def_keyid,
4902 keyidx);
4903
4904 if (ret) {
4905 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
4906 arvif->vdev_id,
4907 ret);
4908 goto unlock;
4909 }
4910
4911 arvif->def_wep_key_idx = keyidx;
Michal Kazior370e5672015-02-18 14:02:26 +01004912
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004913unlock:
4914 mutex_unlock(&arvif->ar->conf_mutex);
4915}
4916
Michal Kazior9797feb2014-02-14 14:49:48 +01004917static void ath10k_sta_rc_update_wk(struct work_struct *wk)
4918{
4919 struct ath10k *ar;
4920 struct ath10k_vif *arvif;
4921 struct ath10k_sta *arsta;
4922 struct ieee80211_sta *sta;
Michal Kazior45c9abc2015-04-21 20:42:58 +03004923 struct cfg80211_chan_def def;
4924 enum ieee80211_band band;
4925 const u8 *ht_mcs_mask;
4926 const u16 *vht_mcs_mask;
Michal Kazior9797feb2014-02-14 14:49:48 +01004927 u32 changed, bw, nss, smps;
4928 int err;
4929
4930 arsta = container_of(wk, struct ath10k_sta, update_wk);
4931 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
4932 arvif = arsta->arvif;
4933 ar = arvif->ar;
4934
Michal Kazior45c9abc2015-04-21 20:42:58 +03004935 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
4936 return;
4937
4938 band = def.chan->band;
4939 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
4940 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
4941
Michal Kazior9797feb2014-02-14 14:49:48 +01004942 spin_lock_bh(&ar->data_lock);
4943
4944 changed = arsta->changed;
4945 arsta->changed = 0;
4946
4947 bw = arsta->bw;
4948 nss = arsta->nss;
4949 smps = arsta->smps;
4950
4951 spin_unlock_bh(&ar->data_lock);
4952
4953 mutex_lock(&ar->conf_mutex);
4954
Michal Kazior45c9abc2015-04-21 20:42:58 +03004955 nss = max_t(u32, 1, nss);
4956 nss = min(nss, max(ath10k_mac_max_ht_nss(ht_mcs_mask),
4957 ath10k_mac_max_vht_nss(vht_mcs_mask)));
4958
Michal Kazior9797feb2014-02-14 14:49:48 +01004959 if (changed & IEEE80211_RC_BW_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004960 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004961 sta->addr, bw);
4962
4963 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4964 WMI_PEER_CHAN_WIDTH, bw);
4965 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004966 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004967 sta->addr, bw, err);
4968 }
4969
4970 if (changed & IEEE80211_RC_NSS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004971 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004972 sta->addr, nss);
4973
4974 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4975 WMI_PEER_NSS, nss);
4976 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004977 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004978 sta->addr, nss, err);
4979 }
4980
4981 if (changed & IEEE80211_RC_SMPS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004982 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004983 sta->addr, smps);
4984
4985 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4986 WMI_PEER_SMPS_STATE, smps);
4987 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004988 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004989 sta->addr, smps, err);
4990 }
4991
Janusz Dziedzic55884c02014-12-17 12:30:02 +02004992 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
4993 changed & IEEE80211_RC_NSS_CHANGED) {
4994 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004995 sta->addr);
4996
Michal Kazior590922a2014-10-21 10:10:29 +03004997 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004998 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004999 ath10k_warn(ar, "failed to reassociate station: %pM\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02005000 sta->addr);
5001 }
5002
Michal Kazior9797feb2014-02-14 14:49:48 +01005003 mutex_unlock(&ar->conf_mutex);
5004}
5005
Marek Puzyniak7c354242015-03-30 09:51:52 +03005006static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif,
5007 struct ieee80211_sta *sta)
Michal Kaziorcfd10612014-11-25 15:16:05 +01005008{
5009 struct ath10k *ar = arvif->ar;
5010
5011 lockdep_assert_held(&ar->conf_mutex);
5012
Marek Puzyniak7c354242015-03-30 09:51:52 +03005013 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
Michal Kaziorcfd10612014-11-25 15:16:05 +01005014 return 0;
5015
5016 if (ar->num_stations >= ar->max_num_stations)
5017 return -ENOBUFS;
5018
5019 ar->num_stations++;
5020
5021 return 0;
5022}
5023
Marek Puzyniak7c354242015-03-30 09:51:52 +03005024static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif,
5025 struct ieee80211_sta *sta)
Michal Kaziorcfd10612014-11-25 15:16:05 +01005026{
5027 struct ath10k *ar = arvif->ar;
5028
5029 lockdep_assert_held(&ar->conf_mutex);
5030
Marek Puzyniak7c354242015-03-30 09:51:52 +03005031 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
Michal Kaziorcfd10612014-11-25 15:16:05 +01005032 return;
5033
5034 ar->num_stations--;
5035}
5036
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005037struct ath10k_mac_tdls_iter_data {
5038 u32 num_tdls_stations;
5039 struct ieee80211_vif *curr_vif;
5040};
5041
5042static void ath10k_mac_tdls_vif_stations_count_iter(void *data,
5043 struct ieee80211_sta *sta)
5044{
5045 struct ath10k_mac_tdls_iter_data *iter_data = data;
5046 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5047 struct ieee80211_vif *sta_vif = arsta->arvif->vif;
5048
5049 if (sta->tdls && sta_vif == iter_data->curr_vif)
5050 iter_data->num_tdls_stations++;
5051}
5052
5053static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw *hw,
5054 struct ieee80211_vif *vif)
5055{
5056 struct ath10k_mac_tdls_iter_data data = {};
5057
5058 data.curr_vif = vif;
5059
5060 ieee80211_iterate_stations_atomic(hw,
5061 ath10k_mac_tdls_vif_stations_count_iter,
5062 &data);
5063 return data.num_tdls_stations;
5064}
5065
5066static void ath10k_mac_tdls_vifs_count_iter(void *data, u8 *mac,
5067 struct ieee80211_vif *vif)
5068{
5069 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5070 int *num_tdls_vifs = data;
5071
5072 if (vif->type != NL80211_IFTYPE_STATION)
5073 return;
5074
5075 if (ath10k_mac_tdls_vif_stations_count(arvif->ar->hw, vif) > 0)
5076 (*num_tdls_vifs)++;
5077}
5078
5079static int ath10k_mac_tdls_vifs_count(struct ieee80211_hw *hw)
5080{
5081 int num_tdls_vifs = 0;
5082
5083 ieee80211_iterate_active_interfaces_atomic(hw,
5084 IEEE80211_IFACE_ITER_NORMAL,
5085 ath10k_mac_tdls_vifs_count_iter,
5086 &num_tdls_vifs);
5087 return num_tdls_vifs;
5088}
5089
Kalle Valo5e3dd152013-06-12 20:52:10 +03005090static int ath10k_sta_state(struct ieee80211_hw *hw,
5091 struct ieee80211_vif *vif,
5092 struct ieee80211_sta *sta,
5093 enum ieee80211_sta_state old_state,
5094 enum ieee80211_sta_state new_state)
5095{
5096 struct ath10k *ar = hw->priv;
5097 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01005098 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005099 int ret = 0;
5100
Michal Kazior76f90022014-02-25 09:29:57 +02005101 if (old_state == IEEE80211_STA_NOTEXIST &&
5102 new_state == IEEE80211_STA_NONE) {
5103 memset(arsta, 0, sizeof(*arsta));
5104 arsta->arvif = arvif;
5105 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
5106 }
5107
Michal Kazior9797feb2014-02-14 14:49:48 +01005108 /* cancel must be done outside the mutex to avoid deadlock */
5109 if ((old_state == IEEE80211_STA_NONE &&
5110 new_state == IEEE80211_STA_NOTEXIST))
5111 cancel_work_sync(&arsta->update_wk);
5112
Kalle Valo5e3dd152013-06-12 20:52:10 +03005113 mutex_lock(&ar->conf_mutex);
5114
5115 if (old_state == IEEE80211_STA_NOTEXIST &&
Michal Kazior077efc82014-10-21 10:10:29 +03005116 new_state == IEEE80211_STA_NONE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03005117 /*
5118 * New station addition.
5119 */
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005120 enum wmi_peer_type peer_type = WMI_PEER_TYPE_DEFAULT;
5121 u32 num_tdls_stations;
5122 u32 num_tdls_vifs;
5123
Michal Kaziorcfd10612014-11-25 15:16:05 +01005124 ath10k_dbg(ar, ATH10K_DBG_MAC,
5125 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
5126 arvif->vdev_id, sta->addr,
5127 ar->num_stations + 1, ar->max_num_stations,
5128 ar->num_peers + 1, ar->max_num_peers);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01005129
Marek Puzyniak7c354242015-03-30 09:51:52 +03005130 ret = ath10k_mac_inc_num_stations(arvif, sta);
Michal Kaziorcfd10612014-11-25 15:16:05 +01005131 if (ret) {
5132 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
5133 ar->max_num_stations);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01005134 goto exit;
5135 }
5136
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005137 if (sta->tdls)
5138 peer_type = WMI_PEER_TYPE_TDLS;
5139
Marek Puzyniak7390ed32015-03-30 09:51:52 +03005140 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr,
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005141 peer_type);
Michal Kaziora52c0282014-11-25 15:16:03 +01005142 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005143 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 -08005144 sta->addr, arvif->vdev_id, ret);
Marek Puzyniak7c354242015-03-30 09:51:52 +03005145 ath10k_mac_dec_num_stations(arvif, sta);
Michal Kaziora52c0282014-11-25 15:16:03 +01005146 goto exit;
5147 }
Michal Kazior077efc82014-10-21 10:10:29 +03005148
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005149 if (!sta->tdls)
5150 goto exit;
Michal Kazior077efc82014-10-21 10:10:29 +03005151
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005152 num_tdls_stations = ath10k_mac_tdls_vif_stations_count(hw, vif);
5153 num_tdls_vifs = ath10k_mac_tdls_vifs_count(hw);
5154
5155 if (num_tdls_vifs >= ar->max_num_tdls_vdevs &&
5156 num_tdls_stations == 0) {
5157 ath10k_warn(ar, "vdev %i exceeded maximum number of tdls vdevs %i\n",
5158 arvif->vdev_id, ar->max_num_tdls_vdevs);
5159 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5160 ath10k_mac_dec_num_stations(arvif, sta);
5161 ret = -ENOBUFS;
5162 goto exit;
5163 }
5164
5165 if (num_tdls_stations == 0) {
5166 /* This is the first tdls peer in current vif */
5167 enum wmi_tdls_state state = WMI_TDLS_ENABLE_ACTIVE;
5168
5169 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5170 state);
Michal Kazior077efc82014-10-21 10:10:29 +03005171 if (ret) {
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005172 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
Michal Kazior077efc82014-10-21 10:10:29 +03005173 arvif->vdev_id, ret);
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005174 ath10k_peer_delete(ar, arvif->vdev_id,
5175 sta->addr);
5176 ath10k_mac_dec_num_stations(arvif, sta);
Michal Kazior077efc82014-10-21 10:10:29 +03005177 goto exit;
5178 }
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005179 }
Michal Kazior077efc82014-10-21 10:10:29 +03005180
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005181 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
5182 WMI_TDLS_PEER_STATE_PEERING);
5183 if (ret) {
5184 ath10k_warn(ar,
5185 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
5186 sta->addr, arvif->vdev_id, ret);
5187 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5188 ath10k_mac_dec_num_stations(arvif, sta);
5189
5190 if (num_tdls_stations != 0)
5191 goto exit;
5192 ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5193 WMI_TDLS_DISABLE);
Michal Kazior077efc82014-10-21 10:10:29 +03005194 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005195 } else if ((old_state == IEEE80211_STA_NONE &&
5196 new_state == IEEE80211_STA_NOTEXIST)) {
5197 /*
5198 * Existing station deletion.
5199 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005200 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03005201 "mac vdev %d peer delete %pM (sta gone)\n",
5202 arvif->vdev_id, sta->addr);
Michal Kazior077efc82014-10-21 10:10:29 +03005203
Kalle Valo5e3dd152013-06-12 20:52:10 +03005204 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5205 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005206 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02005207 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005208
Marek Puzyniak7c354242015-03-30 09:51:52 +03005209 ath10k_mac_dec_num_stations(arvif, sta);
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005210
5211 if (!sta->tdls)
5212 goto exit;
5213
5214 if (ath10k_mac_tdls_vif_stations_count(hw, vif))
5215 goto exit;
5216
5217 /* This was the last tdls peer in current vif */
5218 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5219 WMI_TDLS_DISABLE);
5220 if (ret) {
5221 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
5222 arvif->vdev_id, ret);
5223 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005224 } else if (old_state == IEEE80211_STA_AUTH &&
5225 new_state == IEEE80211_STA_ASSOC &&
5226 (vif->type == NL80211_IFTYPE_AP ||
5227 vif->type == NL80211_IFTYPE_ADHOC)) {
5228 /*
5229 * New association.
5230 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005231 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03005232 sta->addr);
5233
Michal Kazior590922a2014-10-21 10:10:29 +03005234 ret = ath10k_station_assoc(ar, vif, sta, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005235 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005236 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02005237 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005238 } else if (old_state == IEEE80211_STA_ASSOC &&
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005239 new_state == IEEE80211_STA_AUTHORIZED &&
5240 sta->tdls) {
5241 /*
5242 * Tdls station authorized.
5243 */
5244 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac tdls sta %pM authorized\n",
5245 sta->addr);
5246
5247 ret = ath10k_station_assoc(ar, vif, sta, false);
5248 if (ret) {
5249 ath10k_warn(ar, "failed to associate tdls station %pM for vdev %i: %i\n",
5250 sta->addr, arvif->vdev_id, ret);
5251 goto exit;
5252 }
5253
5254 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
5255 WMI_TDLS_PEER_STATE_CONNECTED);
5256 if (ret)
5257 ath10k_warn(ar, "failed to update tdls peer %pM for vdev %i: %i\n",
5258 sta->addr, arvif->vdev_id, ret);
5259 } else if (old_state == IEEE80211_STA_ASSOC &&
5260 new_state == IEEE80211_STA_AUTH &&
5261 (vif->type == NL80211_IFTYPE_AP ||
5262 vif->type == NL80211_IFTYPE_ADHOC)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03005263 /*
5264 * Disassociation.
5265 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005266 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03005267 sta->addr);
5268
Michal Kazior590922a2014-10-21 10:10:29 +03005269 ret = ath10k_station_disassoc(ar, vif, sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005270 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005271 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02005272 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005273 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01005274exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005275 mutex_unlock(&ar->conf_mutex);
5276 return ret;
5277}
5278
5279static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
Kalle Valo5b07e072014-09-14 12:50:06 +03005280 u16 ac, bool enable)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005281{
5282 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorb0e56152015-01-24 12:14:52 +02005283 struct wmi_sta_uapsd_auto_trig_arg arg = {};
5284 u32 prio = 0, acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005285 u32 value = 0;
5286 int ret = 0;
5287
Michal Kazior548db542013-07-05 16:15:15 +03005288 lockdep_assert_held(&ar->conf_mutex);
5289
Kalle Valo5e3dd152013-06-12 20:52:10 +03005290 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
5291 return 0;
5292
5293 switch (ac) {
5294 case IEEE80211_AC_VO:
5295 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
5296 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005297 prio = 7;
5298 acc = 3;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005299 break;
5300 case IEEE80211_AC_VI:
5301 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
5302 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005303 prio = 5;
5304 acc = 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005305 break;
5306 case IEEE80211_AC_BE:
5307 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
5308 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005309 prio = 2;
5310 acc = 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005311 break;
5312 case IEEE80211_AC_BK:
5313 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
5314 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005315 prio = 0;
5316 acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005317 break;
5318 }
5319
5320 if (enable)
5321 arvif->u.sta.uapsd |= value;
5322 else
5323 arvif->u.sta.uapsd &= ~value;
5324
5325 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5326 WMI_STA_PS_PARAM_UAPSD,
5327 arvif->u.sta.uapsd);
5328 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005329 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005330 goto exit;
5331 }
5332
5333 if (arvif->u.sta.uapsd)
5334 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
5335 else
5336 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
5337
5338 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5339 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
5340 value);
5341 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005342 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005343
Michal Kazior9f9b5742014-12-12 12:41:36 +01005344 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
5345 if (ret) {
5346 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
5347 arvif->vdev_id, ret);
5348 return ret;
5349 }
5350
5351 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
5352 if (ret) {
5353 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
5354 arvif->vdev_id, ret);
5355 return ret;
5356 }
5357
Michal Kaziorb0e56152015-01-24 12:14:52 +02005358 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
5359 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
5360 /* Only userspace can make an educated decision when to send
5361 * trigger frame. The following effectively disables u-UAPSD
5362 * autotrigger in firmware (which is enabled by default
5363 * provided the autotrigger service is available).
5364 */
5365
5366 arg.wmm_ac = acc;
5367 arg.user_priority = prio;
5368 arg.service_interval = 0;
5369 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
5370 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
5371
5372 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
5373 arvif->bssid, &arg, 1);
5374 if (ret) {
5375 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
5376 ret);
5377 return ret;
5378 }
5379 }
5380
Kalle Valo5e3dd152013-06-12 20:52:10 +03005381exit:
5382 return ret;
5383}
5384
5385static int ath10k_conf_tx(struct ieee80211_hw *hw,
5386 struct ieee80211_vif *vif, u16 ac,
5387 const struct ieee80211_tx_queue_params *params)
5388{
5389 struct ath10k *ar = hw->priv;
Michal Kazior5e752e42015-01-19 09:53:41 +01005390 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005391 struct wmi_wmm_params_arg *p = NULL;
5392 int ret;
5393
5394 mutex_lock(&ar->conf_mutex);
5395
5396 switch (ac) {
5397 case IEEE80211_AC_VO:
Michal Kazior5e752e42015-01-19 09:53:41 +01005398 p = &arvif->wmm_params.ac_vo;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005399 break;
5400 case IEEE80211_AC_VI:
Michal Kazior5e752e42015-01-19 09:53:41 +01005401 p = &arvif->wmm_params.ac_vi;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005402 break;
5403 case IEEE80211_AC_BE:
Michal Kazior5e752e42015-01-19 09:53:41 +01005404 p = &arvif->wmm_params.ac_be;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005405 break;
5406 case IEEE80211_AC_BK:
Michal Kazior5e752e42015-01-19 09:53:41 +01005407 p = &arvif->wmm_params.ac_bk;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005408 break;
5409 }
5410
5411 if (WARN_ON(!p)) {
5412 ret = -EINVAL;
5413 goto exit;
5414 }
5415
5416 p->cwmin = params->cw_min;
5417 p->cwmax = params->cw_max;
5418 p->aifs = params->aifs;
5419
5420 /*
5421 * The channel time duration programmed in the HW is in absolute
5422 * microseconds, while mac80211 gives the txop in units of
5423 * 32 microseconds.
5424 */
5425 p->txop = params->txop * 32;
5426
Michal Kazior7fc979a2015-01-28 09:57:28 +02005427 if (ar->wmi.ops->gen_vdev_wmm_conf) {
5428 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
5429 &arvif->wmm_params);
5430 if (ret) {
5431 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
5432 arvif->vdev_id, ret);
5433 goto exit;
5434 }
5435 } else {
5436 /* This won't work well with multi-interface cases but it's
5437 * better than nothing.
5438 */
5439 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
5440 if (ret) {
5441 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
5442 goto exit;
5443 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005444 }
5445
5446 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
5447 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005448 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005449
5450exit:
5451 mutex_unlock(&ar->conf_mutex);
5452 return ret;
5453}
5454
5455#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
5456
5457static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
5458 struct ieee80211_vif *vif,
5459 struct ieee80211_channel *chan,
5460 int duration,
5461 enum ieee80211_roc_type type)
5462{
5463 struct ath10k *ar = hw->priv;
5464 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5465 struct wmi_start_scan_arg arg;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005466 int ret = 0;
Michal Kaziorfcf98442015-03-31 11:03:47 +00005467 u32 scan_time_msec;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005468
5469 mutex_lock(&ar->conf_mutex);
5470
5471 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005472 switch (ar->scan.state) {
5473 case ATH10K_SCAN_IDLE:
5474 reinit_completion(&ar->scan.started);
5475 reinit_completion(&ar->scan.completed);
5476 reinit_completion(&ar->scan.on_channel);
5477 ar->scan.state = ATH10K_SCAN_STARTING;
5478 ar->scan.is_roc = true;
5479 ar->scan.vdev_id = arvif->vdev_id;
5480 ar->scan.roc_freq = chan->center_freq;
Michal Kaziord710e752015-07-09 13:08:36 +02005481 ar->scan.roc_notify = true;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005482 ret = 0;
5483 break;
5484 case ATH10K_SCAN_STARTING:
5485 case ATH10K_SCAN_RUNNING:
5486 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005487 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005488 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005489 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005490 spin_unlock_bh(&ar->data_lock);
5491
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005492 if (ret)
5493 goto exit;
5494
Michal Kaziorfcf98442015-03-31 11:03:47 +00005495 scan_time_msec = ar->hw->wiphy->max_remain_on_channel_duration * 2;
Michal Kaziordcca0bd2014-11-24 14:58:32 +01005496
Kalle Valo5e3dd152013-06-12 20:52:10 +03005497 memset(&arg, 0, sizeof(arg));
5498 ath10k_wmi_start_scan_init(ar, &arg);
5499 arg.vdev_id = arvif->vdev_id;
5500 arg.scan_id = ATH10K_SCAN_ID;
5501 arg.n_channels = 1;
5502 arg.channels[0] = chan->center_freq;
Michal Kaziorfcf98442015-03-31 11:03:47 +00005503 arg.dwell_time_active = scan_time_msec;
5504 arg.dwell_time_passive = scan_time_msec;
5505 arg.max_scan_time = scan_time_msec;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005506 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
5507 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
Michal Kaziordbd3f9f2015-03-31 11:03:48 +00005508 arg.burst_duration_ms = duration;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005509
5510 ret = ath10k_start_scan(ar, &arg);
5511 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005512 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005513 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005514 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005515 spin_unlock_bh(&ar->data_lock);
5516 goto exit;
5517 }
5518
5519 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
5520 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005521 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005522
5523 ret = ath10k_scan_stop(ar);
5524 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005525 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005526
Kalle Valo5e3dd152013-06-12 20:52:10 +03005527 ret = -ETIMEDOUT;
5528 goto exit;
5529 }
5530
Michal Kaziorfcf98442015-03-31 11:03:47 +00005531 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
5532 msecs_to_jiffies(duration));
5533
Kalle Valo5e3dd152013-06-12 20:52:10 +03005534 ret = 0;
5535exit:
5536 mutex_unlock(&ar->conf_mutex);
5537 return ret;
5538}
5539
5540static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
5541{
5542 struct ath10k *ar = hw->priv;
5543
5544 mutex_lock(&ar->conf_mutex);
Michal Kaziord710e752015-07-09 13:08:36 +02005545
5546 spin_lock_bh(&ar->data_lock);
5547 ar->scan.roc_notify = false;
5548 spin_unlock_bh(&ar->data_lock);
5549
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005550 ath10k_scan_abort(ar);
Michal Kaziord710e752015-07-09 13:08:36 +02005551
Kalle Valo5e3dd152013-06-12 20:52:10 +03005552 mutex_unlock(&ar->conf_mutex);
5553
Michal Kazior4eb2e162014-10-28 10:23:09 +01005554 cancel_delayed_work_sync(&ar->scan.timeout);
5555
Kalle Valo5e3dd152013-06-12 20:52:10 +03005556 return 0;
5557}
5558
5559/*
5560 * Both RTS and Fragmentation threshold are interface-specific
5561 * in ath10k, but device-specific in mac80211.
5562 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03005563
5564static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
5565{
Kalle Valo5e3dd152013-06-12 20:52:10 +03005566 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03005567 struct ath10k_vif *arvif;
5568 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03005569
Michal Kaziorad088bf2013-10-16 15:44:46 +03005570 mutex_lock(&ar->conf_mutex);
5571 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005572 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03005573 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03005574
Michal Kaziorad088bf2013-10-16 15:44:46 +03005575 ret = ath10k_mac_set_rts(arvif, value);
5576 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005577 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03005578 arvif->vdev_id, ret);
5579 break;
5580 }
5581 }
5582 mutex_unlock(&ar->conf_mutex);
5583
5584 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005585}
5586
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02005587static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5588 u32 queues, bool drop)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005589{
5590 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02005591 bool skip;
Nicholas Mc Guired4298a32015-06-15 14:46:43 +03005592 long time_left;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005593
5594 /* mac80211 doesn't care if we really xmit queued frames or not
5595 * we'll collect those frames either way if we stop/delete vdevs */
5596 if (drop)
5597 return;
5598
Michal Kazior548db542013-07-05 16:15:15 +03005599 mutex_lock(&ar->conf_mutex);
5600
Michal Kazioraffd3212013-07-16 09:54:35 +02005601 if (ar->state == ATH10K_STATE_WEDGED)
5602 goto skip;
5603
Nicholas Mc Guired4298a32015-06-15 14:46:43 +03005604 time_left = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03005605 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02005606
Michal Kazioredb82362013-07-05 16:15:14 +03005607 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02005608 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03005609 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02005610
Michal Kazior7962b0d2014-10-28 10:34:38 +01005611 skip = (ar->state == ATH10K_STATE_WEDGED) ||
5612 test_bit(ATH10K_FLAG_CRASH_FLUSH,
5613 &ar->dev_flags);
Michal Kazioraffd3212013-07-16 09:54:35 +02005614
5615 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005616 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02005617
Nicholas Mc Guired4298a32015-06-15 14:46:43 +03005618 if (time_left == 0 || skip)
5619 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %ld\n",
5620 skip, ar->state, time_left);
Michal Kazior548db542013-07-05 16:15:15 +03005621
Michal Kazioraffd3212013-07-16 09:54:35 +02005622skip:
Michal Kazior548db542013-07-05 16:15:15 +03005623 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005624}
5625
5626/* TODO: Implement this function properly
5627 * For now it is needed to reply to Probe Requests in IBSS mode.
5628 * Propably we need this information from FW.
5629 */
5630static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
5631{
5632 return 1;
5633}
5634
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005635static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
5636 enum ieee80211_reconfig_type reconfig_type)
Michal Kazioraffd3212013-07-16 09:54:35 +02005637{
5638 struct ath10k *ar = hw->priv;
5639
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005640 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
5641 return;
5642
Michal Kazioraffd3212013-07-16 09:54:35 +02005643 mutex_lock(&ar->conf_mutex);
5644
5645 /* If device failed to restart it will be in a different state, e.g.
5646 * ATH10K_STATE_WEDGED */
5647 if (ar->state == ATH10K_STATE_RESTARTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005648 ath10k_info(ar, "device successfully recovered\n");
Michal Kazioraffd3212013-07-16 09:54:35 +02005649 ar->state = ATH10K_STATE_ON;
Michal Kazior7962b0d2014-10-28 10:34:38 +01005650 ieee80211_wake_queues(ar->hw);
Michal Kazioraffd3212013-07-16 09:54:35 +02005651 }
5652
5653 mutex_unlock(&ar->conf_mutex);
5654}
5655
Michal Kazior2e1dea42013-07-31 10:32:40 +02005656static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
5657 struct survey_info *survey)
5658{
5659 struct ath10k *ar = hw->priv;
5660 struct ieee80211_supported_band *sband;
5661 struct survey_info *ar_survey = &ar->survey[idx];
5662 int ret = 0;
5663
5664 mutex_lock(&ar->conf_mutex);
5665
5666 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
5667 if (sband && idx >= sband->n_channels) {
5668 idx -= sband->n_channels;
5669 sband = NULL;
5670 }
5671
5672 if (!sband)
5673 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
5674
5675 if (!sband || idx >= sband->n_channels) {
5676 ret = -ENOENT;
5677 goto exit;
5678 }
5679
5680 spin_lock_bh(&ar->data_lock);
5681 memcpy(survey, ar_survey, sizeof(*survey));
5682 spin_unlock_bh(&ar->data_lock);
5683
5684 survey->channel = &sband->channels[idx];
5685
Felix Fietkaufa1d4df2014-10-23 17:04:28 +03005686 if (ar->rx_channel == survey->channel)
5687 survey->filled |= SURVEY_INFO_IN_USE;
5688
Michal Kazior2e1dea42013-07-31 10:32:40 +02005689exit:
5690 mutex_unlock(&ar->conf_mutex);
5691 return ret;
5692}
5693
Michal Kazior3ae54222015-03-31 10:49:20 +00005694static bool
5695ath10k_mac_bitrate_mask_has_single_rate(struct ath10k *ar,
5696 enum ieee80211_band band,
5697 const struct cfg80211_bitrate_mask *mask)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005698{
Michal Kazior3ae54222015-03-31 10:49:20 +00005699 int num_rates = 0;
5700 int i;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005701
Michal Kazior3ae54222015-03-31 10:49:20 +00005702 num_rates += hweight32(mask->control[band].legacy);
5703
5704 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++)
5705 num_rates += hweight8(mask->control[band].ht_mcs[i]);
5706
5707 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++)
5708 num_rates += hweight16(mask->control[band].vht_mcs[i]);
5709
5710 return num_rates == 1;
5711}
5712
5713static bool
5714ath10k_mac_bitrate_mask_get_single_nss(struct ath10k *ar,
5715 enum ieee80211_band band,
5716 const struct cfg80211_bitrate_mask *mask,
5717 int *nss)
5718{
5719 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
5720 u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
5721 u8 ht_nss_mask = 0;
5722 u8 vht_nss_mask = 0;
5723 int i;
5724
5725 if (mask->control[band].legacy)
5726 return false;
5727
5728 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
5729 if (mask->control[band].ht_mcs[i] == 0)
5730 continue;
5731 else if (mask->control[band].ht_mcs[i] ==
5732 sband->ht_cap.mcs.rx_mask[i])
5733 ht_nss_mask |= BIT(i);
5734 else
5735 return false;
5736 }
5737
5738 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
5739 if (mask->control[band].vht_mcs[i] == 0)
5740 continue;
5741 else if (mask->control[band].vht_mcs[i] ==
5742 ath10k_mac_get_max_vht_mcs_map(vht_mcs_map, i))
5743 vht_nss_mask |= BIT(i);
5744 else
5745 return false;
5746 }
5747
5748 if (ht_nss_mask != vht_nss_mask)
5749 return false;
5750
5751 if (ht_nss_mask == 0)
5752 return false;
5753
5754 if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask)
5755 return false;
5756
5757 *nss = fls(ht_nss_mask);
5758
5759 return true;
5760}
5761
5762static int
5763ath10k_mac_bitrate_mask_get_single_rate(struct ath10k *ar,
5764 enum ieee80211_band band,
5765 const struct cfg80211_bitrate_mask *mask,
5766 u8 *rate, u8 *nss)
5767{
5768 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
5769 int rate_idx;
5770 int i;
5771 u16 bitrate;
5772 u8 preamble;
5773 u8 hw_rate;
5774
5775 if (hweight32(mask->control[band].legacy) == 1) {
5776 rate_idx = ffs(mask->control[band].legacy) - 1;
5777
5778 hw_rate = sband->bitrates[rate_idx].hw_value;
5779 bitrate = sband->bitrates[rate_idx].bitrate;
5780
5781 if (ath10k_mac_bitrate_is_cck(bitrate))
5782 preamble = WMI_RATE_PREAMBLE_CCK;
5783 else
5784 preamble = WMI_RATE_PREAMBLE_OFDM;
5785
5786 *nss = 1;
5787 *rate = preamble << 6 |
5788 (*nss - 1) << 4 |
5789 hw_rate << 0;
5790
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005791 return 0;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005792 }
5793
Michal Kazior3ae54222015-03-31 10:49:20 +00005794 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
5795 if (hweight8(mask->control[band].ht_mcs[i]) == 1) {
5796 *nss = i + 1;
5797 *rate = WMI_RATE_PREAMBLE_HT << 6 |
5798 (*nss - 1) << 4 |
5799 (ffs(mask->control[band].ht_mcs[i]) - 1);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005800
Michal Kazior3ae54222015-03-31 10:49:20 +00005801 return 0;
5802 }
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005803 }
5804
Michal Kazior3ae54222015-03-31 10:49:20 +00005805 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
5806 if (hweight16(mask->control[band].vht_mcs[i]) == 1) {
5807 *nss = i + 1;
5808 *rate = WMI_RATE_PREAMBLE_VHT << 6 |
5809 (*nss - 1) << 4 |
5810 (ffs(mask->control[band].vht_mcs[i]) - 1);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005811
Michal Kazior3ae54222015-03-31 10:49:20 +00005812 return 0;
5813 }
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005814 }
5815
Michal Kazior3ae54222015-03-31 10:49:20 +00005816 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005817}
5818
Michal Kazior3ae54222015-03-31 10:49:20 +00005819static int ath10k_mac_set_fixed_rate_params(struct ath10k_vif *arvif,
5820 u8 rate, u8 nss, u8 sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005821{
5822 struct ath10k *ar = arvif->ar;
5823 u32 vdev_param;
Michal Kazior3ae54222015-03-31 10:49:20 +00005824 int ret;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005825
Michal Kazior3ae54222015-03-31 10:49:20 +00005826 lockdep_assert_held(&ar->conf_mutex);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005827
Michal Kazior3ae54222015-03-31 10:49:20 +00005828 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac set fixed rate params vdev %i rate 0x%02hhx nss %hhu sgi %hhu\n",
5829 arvif->vdev_id, rate, nss, sgi);
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005830
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005831 vdev_param = ar->wmi.vdev_param->fixed_rate;
Michal Kazior3ae54222015-03-31 10:49:20 +00005832 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, rate);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005833 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005834 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
Michal Kazior3ae54222015-03-31 10:49:20 +00005835 rate, ret);
5836 return ret;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005837 }
5838
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005839 vdev_param = ar->wmi.vdev_param->nss;
Michal Kazior3ae54222015-03-31 10:49:20 +00005840 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, nss);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005841 if (ret) {
Michal Kazior3ae54222015-03-31 10:49:20 +00005842 ath10k_warn(ar, "failed to set nss param %d: %d\n", nss, ret);
5843 return ret;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005844 }
5845
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005846 vdev_param = ar->wmi.vdev_param->sgi;
Michal Kazior3ae54222015-03-31 10:49:20 +00005847 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, sgi);
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005848 if (ret) {
Michal Kazior3ae54222015-03-31 10:49:20 +00005849 ath10k_warn(ar, "failed to set sgi param %d: %d\n", sgi, ret);
5850 return ret;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005851 }
5852
Michal Kazior3ae54222015-03-31 10:49:20 +00005853 return 0;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005854}
5855
Michal Kazior45c9abc2015-04-21 20:42:58 +03005856static bool
5857ath10k_mac_can_set_bitrate_mask(struct ath10k *ar,
5858 enum ieee80211_band band,
5859 const struct cfg80211_bitrate_mask *mask)
5860{
5861 int i;
5862 u16 vht_mcs;
5863
5864 /* Due to firmware limitation in WMI_PEER_ASSOC_CMDID it is impossible
5865 * to express all VHT MCS rate masks. Effectively only the following
5866 * ranges can be used: none, 0-7, 0-8 and 0-9.
5867 */
5868 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
5869 vht_mcs = mask->control[band].vht_mcs[i];
5870
5871 switch (vht_mcs) {
5872 case 0:
5873 case BIT(8) - 1:
5874 case BIT(9) - 1:
5875 case BIT(10) - 1:
5876 break;
5877 default:
5878 ath10k_warn(ar, "refusing bitrate mask with missing 0-7 VHT MCS rates\n");
5879 return false;
5880 }
5881 }
5882
5883 return true;
5884}
5885
5886static void ath10k_mac_set_bitrate_mask_iter(void *data,
5887 struct ieee80211_sta *sta)
5888{
5889 struct ath10k_vif *arvif = data;
5890 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5891 struct ath10k *ar = arvif->ar;
5892
5893 if (arsta->arvif != arvif)
5894 return;
5895
5896 spin_lock_bh(&ar->data_lock);
5897 arsta->changed |= IEEE80211_RC_SUPP_RATES_CHANGED;
5898 spin_unlock_bh(&ar->data_lock);
5899
5900 ieee80211_queue_work(ar->hw, &arsta->update_wk);
5901}
5902
Michal Kazior3ae54222015-03-31 10:49:20 +00005903static int ath10k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw,
5904 struct ieee80211_vif *vif,
5905 const struct cfg80211_bitrate_mask *mask)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005906{
5907 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior500ff9f2015-03-31 10:26:21 +00005908 struct cfg80211_chan_def def;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005909 struct ath10k *ar = arvif->ar;
Michal Kazior500ff9f2015-03-31 10:26:21 +00005910 enum ieee80211_band band;
Michal Kazior45c9abc2015-04-21 20:42:58 +03005911 const u8 *ht_mcs_mask;
5912 const u16 *vht_mcs_mask;
Michal Kazior3ae54222015-03-31 10:49:20 +00005913 u8 rate;
5914 u8 nss;
5915 u8 sgi;
5916 int single_nss;
5917 int ret;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005918
Michal Kazior500ff9f2015-03-31 10:26:21 +00005919 if (ath10k_mac_vif_chan(vif, &def))
5920 return -EPERM;
5921
Michal Kazior500ff9f2015-03-31 10:26:21 +00005922 band = def.chan->band;
Michal Kazior45c9abc2015-04-21 20:42:58 +03005923 ht_mcs_mask = mask->control[band].ht_mcs;
5924 vht_mcs_mask = mask->control[band].vht_mcs;
Michal Kazior500ff9f2015-03-31 10:26:21 +00005925
Michal Kazior3ae54222015-03-31 10:49:20 +00005926 sgi = mask->control[band].gi;
5927 if (sgi == NL80211_TXRATE_FORCE_LGI)
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005928 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005929
Michal Kazior3ae54222015-03-31 10:49:20 +00005930 if (ath10k_mac_bitrate_mask_has_single_rate(ar, band, mask)) {
5931 ret = ath10k_mac_bitrate_mask_get_single_rate(ar, band, mask,
5932 &rate, &nss);
5933 if (ret) {
5934 ath10k_warn(ar, "failed to get single rate for vdev %i: %d\n",
5935 arvif->vdev_id, ret);
5936 return ret;
5937 }
5938 } else if (ath10k_mac_bitrate_mask_get_single_nss(ar, band, mask,
5939 &single_nss)) {
5940 rate = WMI_FIXED_RATE_NONE;
5941 nss = single_nss;
5942 } else {
5943 rate = WMI_FIXED_RATE_NONE;
Michal Kazior45c9abc2015-04-21 20:42:58 +03005944 nss = min(ar->num_rf_chains,
5945 max(ath10k_mac_max_ht_nss(ht_mcs_mask),
5946 ath10k_mac_max_vht_nss(vht_mcs_mask)));
5947
5948 if (!ath10k_mac_can_set_bitrate_mask(ar, band, mask))
5949 return -EINVAL;
5950
5951 mutex_lock(&ar->conf_mutex);
5952
5953 arvif->bitrate_mask = *mask;
5954 ieee80211_iterate_stations_atomic(ar->hw,
5955 ath10k_mac_set_bitrate_mask_iter,
5956 arvif);
5957
5958 mutex_unlock(&ar->conf_mutex);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005959 }
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005960
5961 mutex_lock(&ar->conf_mutex);
5962
Michal Kazior3ae54222015-03-31 10:49:20 +00005963 ret = ath10k_mac_set_fixed_rate_params(arvif, rate, nss, sgi);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005964 if (ret) {
Michal Kazior3ae54222015-03-31 10:49:20 +00005965 ath10k_warn(ar, "failed to set fixed rate params on vdev %i: %d\n",
5966 arvif->vdev_id, ret);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005967 goto exit;
5968 }
5969
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005970exit:
5971 mutex_unlock(&ar->conf_mutex);
Michal Kazior3ae54222015-03-31 10:49:20 +00005972
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005973 return ret;
5974}
5975
Michal Kazior9797feb2014-02-14 14:49:48 +01005976static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
5977 struct ieee80211_vif *vif,
5978 struct ieee80211_sta *sta,
5979 u32 changed)
5980{
5981 struct ath10k *ar = hw->priv;
5982 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5983 u32 bw, smps;
5984
5985 spin_lock_bh(&ar->data_lock);
5986
Michal Kazior7aa7a722014-08-25 12:09:38 +02005987 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior9797feb2014-02-14 14:49:48 +01005988 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
5989 sta->addr, changed, sta->bandwidth, sta->rx_nss,
5990 sta->smps_mode);
5991
5992 if (changed & IEEE80211_RC_BW_CHANGED) {
5993 bw = WMI_PEER_CHWIDTH_20MHZ;
5994
5995 switch (sta->bandwidth) {
5996 case IEEE80211_STA_RX_BW_20:
5997 bw = WMI_PEER_CHWIDTH_20MHZ;
5998 break;
5999 case IEEE80211_STA_RX_BW_40:
6000 bw = WMI_PEER_CHWIDTH_40MHZ;
6001 break;
6002 case IEEE80211_STA_RX_BW_80:
6003 bw = WMI_PEER_CHWIDTH_80MHZ;
6004 break;
6005 case IEEE80211_STA_RX_BW_160:
Masanari Iidad939be32015-02-27 23:52:31 +09006006 ath10k_warn(ar, "Invalid bandwidth %d in rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02006007 sta->bandwidth, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01006008 bw = WMI_PEER_CHWIDTH_20MHZ;
6009 break;
6010 }
6011
6012 arsta->bw = bw;
6013 }
6014
6015 if (changed & IEEE80211_RC_NSS_CHANGED)
6016 arsta->nss = sta->rx_nss;
6017
6018 if (changed & IEEE80211_RC_SMPS_CHANGED) {
6019 smps = WMI_PEER_SMPS_PS_NONE;
6020
6021 switch (sta->smps_mode) {
6022 case IEEE80211_SMPS_AUTOMATIC:
6023 case IEEE80211_SMPS_OFF:
6024 smps = WMI_PEER_SMPS_PS_NONE;
6025 break;
6026 case IEEE80211_SMPS_STATIC:
6027 smps = WMI_PEER_SMPS_STATIC;
6028 break;
6029 case IEEE80211_SMPS_DYNAMIC:
6030 smps = WMI_PEER_SMPS_DYNAMIC;
6031 break;
6032 case IEEE80211_SMPS_NUM_MODES:
Michal Kazior7aa7a722014-08-25 12:09:38 +02006033 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02006034 sta->smps_mode, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01006035 smps = WMI_PEER_SMPS_PS_NONE;
6036 break;
6037 }
6038
6039 arsta->smps = smps;
6040 }
6041
Michal Kazior9797feb2014-02-14 14:49:48 +01006042 arsta->changed |= changed;
6043
6044 spin_unlock_bh(&ar->data_lock);
6045
6046 ieee80211_queue_work(hw, &arsta->update_wk);
6047}
6048
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02006049static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
6050{
6051 /*
6052 * FIXME: Return 0 for time being. Need to figure out whether FW
6053 * has the API to fetch 64-bit local TSF
6054 */
6055
6056 return 0;
6057}
6058
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02006059static int ath10k_ampdu_action(struct ieee80211_hw *hw,
6060 struct ieee80211_vif *vif,
6061 enum ieee80211_ampdu_mlme_action action,
6062 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
6063 u8 buf_size)
6064{
Michal Kazior7aa7a722014-08-25 12:09:38 +02006065 struct ath10k *ar = hw->priv;
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02006066 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6067
Michal Kazior7aa7a722014-08-25 12:09:38 +02006068 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 +02006069 arvif->vdev_id, sta->addr, tid, action);
6070
6071 switch (action) {
6072 case IEEE80211_AMPDU_RX_START:
6073 case IEEE80211_AMPDU_RX_STOP:
6074 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
6075 * creation/removal. Do we need to verify this?
6076 */
6077 return 0;
6078 case IEEE80211_AMPDU_TX_START:
6079 case IEEE80211_AMPDU_TX_STOP_CONT:
6080 case IEEE80211_AMPDU_TX_STOP_FLUSH:
6081 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
6082 case IEEE80211_AMPDU_TX_OPERATIONAL:
6083 /* Firmware offloads Tx aggregation entirely so deny mac80211
6084 * Tx aggregation requests.
6085 */
6086 return -EOPNOTSUPP;
6087 }
6088
6089 return -EINVAL;
6090}
6091
Michal Kazior500ff9f2015-03-31 10:26:21 +00006092static void
Michal Kaziord7bf4b42015-06-03 12:16:54 +02006093ath10k_mac_update_rx_channel(struct ath10k *ar,
6094 struct ieee80211_chanctx_conf *ctx,
6095 struct ieee80211_vif_chanctx_switch *vifs,
6096 int n_vifs)
Michal Kazior500ff9f2015-03-31 10:26:21 +00006097{
6098 struct cfg80211_chan_def *def = NULL;
6099
6100 /* Both locks are required because ar->rx_channel is modified. This
6101 * allows readers to hold either lock.
6102 */
6103 lockdep_assert_held(&ar->conf_mutex);
6104 lockdep_assert_held(&ar->data_lock);
6105
Michal Kaziord7bf4b42015-06-03 12:16:54 +02006106 WARN_ON(ctx && vifs);
6107 WARN_ON(vifs && n_vifs != 1);
6108
Michal Kazior500ff9f2015-03-31 10:26:21 +00006109 /* FIXME: Sort of an optimization and a workaround. Peers and vifs are
6110 * on a linked list now. Doing a lookup peer -> vif -> chanctx for each
6111 * ppdu on Rx may reduce performance on low-end systems. It should be
6112 * possible to make tables/hashmaps to speed the lookup up (be vary of
6113 * cpu data cache lines though regarding sizes) but to keep the initial
6114 * implementation simple and less intrusive fallback to the slow lookup
6115 * only for multi-channel cases. Single-channel cases will remain to
6116 * use the old channel derival and thus performance should not be
6117 * affected much.
6118 */
6119 rcu_read_lock();
Michal Kaziord7bf4b42015-06-03 12:16:54 +02006120 if (!ctx && ath10k_mac_num_chanctxs(ar) == 1) {
Michal Kazior500ff9f2015-03-31 10:26:21 +00006121 ieee80211_iter_chan_contexts_atomic(ar->hw,
6122 ath10k_mac_get_any_chandef_iter,
6123 &def);
Michal Kaziord7bf4b42015-06-03 12:16:54 +02006124
6125 if (vifs)
6126 def = &vifs[0].new_ctx->def;
6127
Michal Kazior500ff9f2015-03-31 10:26:21 +00006128 ar->rx_channel = def->chan;
Michal Kaziord7bf4b42015-06-03 12:16:54 +02006129 } else if (ctx && ath10k_mac_num_chanctxs(ar) == 0) {
6130 ar->rx_channel = ctx->def.chan;
Michal Kazior500ff9f2015-03-31 10:26:21 +00006131 } else {
6132 ar->rx_channel = NULL;
6133 }
6134 rcu_read_unlock();
6135}
6136
Michal Kazior500ff9f2015-03-31 10:26:21 +00006137static int
6138ath10k_mac_op_add_chanctx(struct ieee80211_hw *hw,
6139 struct ieee80211_chanctx_conf *ctx)
6140{
6141 struct ath10k *ar = hw->priv;
Michal Kazior500ff9f2015-03-31 10:26:21 +00006142
6143 ath10k_dbg(ar, ATH10K_DBG_MAC,
6144 "mac chanctx add freq %hu width %d ptr %p\n",
6145 ctx->def.chan->center_freq, ctx->def.width, ctx);
6146
6147 mutex_lock(&ar->conf_mutex);
6148
6149 spin_lock_bh(&ar->data_lock);
Michal Kaziord7bf4b42015-06-03 12:16:54 +02006150 ath10k_mac_update_rx_channel(ar, ctx, NULL, 0);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006151 spin_unlock_bh(&ar->data_lock);
6152
6153 ath10k_recalc_radar_detection(ar);
6154 ath10k_monitor_recalc(ar);
6155
6156 mutex_unlock(&ar->conf_mutex);
6157
6158 return 0;
6159}
6160
6161static void
6162ath10k_mac_op_remove_chanctx(struct ieee80211_hw *hw,
6163 struct ieee80211_chanctx_conf *ctx)
6164{
6165 struct ath10k *ar = hw->priv;
6166
6167 ath10k_dbg(ar, ATH10K_DBG_MAC,
6168 "mac chanctx remove freq %hu width %d ptr %p\n",
6169 ctx->def.chan->center_freq, ctx->def.width, ctx);
6170
6171 mutex_lock(&ar->conf_mutex);
6172
6173 spin_lock_bh(&ar->data_lock);
Michal Kaziord7bf4b42015-06-03 12:16:54 +02006174 ath10k_mac_update_rx_channel(ar, NULL, NULL, 0);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006175 spin_unlock_bh(&ar->data_lock);
6176
6177 ath10k_recalc_radar_detection(ar);
6178 ath10k_monitor_recalc(ar);
6179
6180 mutex_unlock(&ar->conf_mutex);
6181}
6182
6183static void
6184ath10k_mac_op_change_chanctx(struct ieee80211_hw *hw,
6185 struct ieee80211_chanctx_conf *ctx,
6186 u32 changed)
6187{
6188 struct ath10k *ar = hw->priv;
Michal Kazior500ff9f2015-03-31 10:26:21 +00006189
6190 mutex_lock(&ar->conf_mutex);
6191
6192 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior089ab7a2015-06-03 12:16:55 +02006193 "mac chanctx change freq %hu width %d ptr %p changed %x\n",
6194 ctx->def.chan->center_freq, ctx->def.width, ctx, changed);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006195
6196 /* This shouldn't really happen because channel switching should use
6197 * switch_vif_chanctx().
6198 */
6199 if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL))
6200 goto unlock;
6201
Michal Kazior500ff9f2015-03-31 10:26:21 +00006202 ath10k_recalc_radar_detection(ar);
6203
6204 /* FIXME: How to configure Rx chains properly? */
6205
6206 /* No other actions are actually necessary. Firmware maintains channel
6207 * definitions per vdev internally and there's no host-side channel
6208 * context abstraction to configure, e.g. channel width.
6209 */
6210
6211unlock:
6212 mutex_unlock(&ar->conf_mutex);
6213}
6214
6215static int
6216ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
6217 struct ieee80211_vif *vif,
6218 struct ieee80211_chanctx_conf *ctx)
6219{
6220 struct ath10k *ar = hw->priv;
Michal Kazior500ff9f2015-03-31 10:26:21 +00006221 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6222 int ret;
6223
6224 mutex_lock(&ar->conf_mutex);
6225
6226 ath10k_dbg(ar, ATH10K_DBG_MAC,
6227 "mac chanctx assign ptr %p vdev_id %i\n",
6228 ctx, arvif->vdev_id);
6229
6230 if (WARN_ON(arvif->is_started)) {
6231 mutex_unlock(&ar->conf_mutex);
6232 return -EBUSY;
6233 }
6234
Michal Kazior089ab7a2015-06-03 12:16:55 +02006235 ret = ath10k_vdev_start(arvif, &ctx->def);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006236 if (ret) {
6237 ath10k_warn(ar, "failed to start vdev %i addr %pM on freq %d: %d\n",
6238 arvif->vdev_id, vif->addr,
Michal Kazior089ab7a2015-06-03 12:16:55 +02006239 ctx->def.chan->center_freq, ret);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006240 goto err;
6241 }
6242
6243 arvif->is_started = true;
6244
Michal Kaziorf23e587e2015-07-09 13:08:37 +02006245 ret = ath10k_mac_vif_setup_ps(arvif);
6246 if (ret) {
6247 ath10k_warn(ar, "failed to update vdev %i ps: %d\n",
6248 arvif->vdev_id, ret);
6249 goto err_stop;
6250 }
6251
Michal Kazior500ff9f2015-03-31 10:26:21 +00006252 if (vif->type == NL80211_IFTYPE_MONITOR) {
6253 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, 0, vif->addr);
6254 if (ret) {
6255 ath10k_warn(ar, "failed to up monitor vdev %i: %d\n",
6256 arvif->vdev_id, ret);
6257 goto err_stop;
6258 }
6259
6260 arvif->is_up = true;
6261 }
6262
6263 mutex_unlock(&ar->conf_mutex);
6264 return 0;
6265
6266err_stop:
6267 ath10k_vdev_stop(arvif);
6268 arvif->is_started = false;
Michal Kaziorf23e587e2015-07-09 13:08:37 +02006269 ath10k_mac_vif_setup_ps(arvif);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006270
6271err:
6272 mutex_unlock(&ar->conf_mutex);
6273 return ret;
6274}
6275
6276static void
6277ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
6278 struct ieee80211_vif *vif,
6279 struct ieee80211_chanctx_conf *ctx)
6280{
6281 struct ath10k *ar = hw->priv;
6282 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6283 int ret;
6284
6285 mutex_lock(&ar->conf_mutex);
6286
6287 ath10k_dbg(ar, ATH10K_DBG_MAC,
6288 "mac chanctx unassign ptr %p vdev_id %i\n",
6289 ctx, arvif->vdev_id);
6290
6291 WARN_ON(!arvif->is_started);
6292
6293 if (vif->type == NL80211_IFTYPE_MONITOR) {
6294 WARN_ON(!arvif->is_up);
6295
6296 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
6297 if (ret)
6298 ath10k_warn(ar, "failed to down monitor vdev %i: %d\n",
6299 arvif->vdev_id, ret);
6300
6301 arvif->is_up = false;
6302 }
6303
6304 ret = ath10k_vdev_stop(arvif);
6305 if (ret)
6306 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
6307 arvif->vdev_id, ret);
6308
6309 arvif->is_started = false;
6310
6311 mutex_unlock(&ar->conf_mutex);
6312}
6313
6314static int
6315ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw,
6316 struct ieee80211_vif_chanctx_switch *vifs,
6317 int n_vifs,
6318 enum ieee80211_chanctx_switch_mode mode)
6319{
6320 struct ath10k *ar = hw->priv;
6321 struct ath10k_vif *arvif;
Michal Kazior0e6eb412015-06-03 12:16:56 +02006322 int ret;
Michal Kazior500ff9f2015-03-31 10:26:21 +00006323 int i;
6324
6325 mutex_lock(&ar->conf_mutex);
6326
6327 ath10k_dbg(ar, ATH10K_DBG_MAC,
6328 "mac chanctx switch n_vifs %d mode %d\n",
6329 n_vifs, mode);
6330
Michal Kazior0e6eb412015-06-03 12:16:56 +02006331 /* First stop monitor interface. Some FW versions crash if there's a
6332 * lone monitor interface.
6333 */
6334 if (ar->monitor_started)
6335 ath10k_monitor_stop(ar);
6336
Michal Kazior500ff9f2015-03-31 10:26:21 +00006337 for (i = 0; i < n_vifs; i++) {
6338 arvif = ath10k_vif_to_arvif(vifs[i].vif);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006339
6340 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior089ab7a2015-06-03 12:16:55 +02006341 "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d\n",
Michal Kazior500ff9f2015-03-31 10:26:21 +00006342 arvif->vdev_id,
6343 vifs[i].old_ctx->def.chan->center_freq,
6344 vifs[i].new_ctx->def.chan->center_freq,
6345 vifs[i].old_ctx->def.width,
Michal Kazior089ab7a2015-06-03 12:16:55 +02006346 vifs[i].new_ctx->def.width);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006347
Michal Kazior0e6eb412015-06-03 12:16:56 +02006348 if (WARN_ON(!arvif->is_started))
6349 continue;
6350
6351 if (WARN_ON(!arvif->is_up))
6352 continue;
6353
6354 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
6355 if (ret) {
6356 ath10k_warn(ar, "failed to down vdev %d: %d\n",
6357 arvif->vdev_id, ret);
6358 continue;
Michal Kazior500ff9f2015-03-31 10:26:21 +00006359 }
Michal Kazior500ff9f2015-03-31 10:26:21 +00006360 }
Michal Kazior0e6eb412015-06-03 12:16:56 +02006361
6362 /* All relevant vdevs are downed and associated channel resources
6363 * should be available for the channel switch now.
6364 */
6365
6366 spin_lock_bh(&ar->data_lock);
Michal Kaziord7bf4b42015-06-03 12:16:54 +02006367 ath10k_mac_update_rx_channel(ar, NULL, vifs, n_vifs);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006368 spin_unlock_bh(&ar->data_lock);
6369
Michal Kazior0e6eb412015-06-03 12:16:56 +02006370 for (i = 0; i < n_vifs; i++) {
6371 arvif = ath10k_vif_to_arvif(vifs[i].vif);
6372
6373 if (WARN_ON(!arvif->is_started))
6374 continue;
6375
6376 if (WARN_ON(!arvif->is_up))
6377 continue;
6378
6379 ret = ath10k_mac_setup_bcn_tmpl(arvif);
6380 if (ret)
6381 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
6382 ret);
6383
6384 ret = ath10k_mac_setup_prb_tmpl(arvif);
6385 if (ret)
6386 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
6387 ret);
6388
6389 ret = ath10k_vdev_restart(arvif, &vifs[i].new_ctx->def);
6390 if (ret) {
6391 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
6392 arvif->vdev_id, ret);
6393 continue;
6394 }
6395
6396 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
6397 arvif->bssid);
6398 if (ret) {
6399 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
6400 arvif->vdev_id, ret);
6401 continue;
6402 }
6403 }
6404
6405 ath10k_monitor_recalc(ar);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006406
6407 mutex_unlock(&ar->conf_mutex);
6408 return 0;
6409}
6410
Kalle Valo5e3dd152013-06-12 20:52:10 +03006411static const struct ieee80211_ops ath10k_ops = {
6412 .tx = ath10k_tx,
6413 .start = ath10k_start,
6414 .stop = ath10k_stop,
6415 .config = ath10k_config,
6416 .add_interface = ath10k_add_interface,
6417 .remove_interface = ath10k_remove_interface,
6418 .configure_filter = ath10k_configure_filter,
6419 .bss_info_changed = ath10k_bss_info_changed,
6420 .hw_scan = ath10k_hw_scan,
6421 .cancel_hw_scan = ath10k_cancel_hw_scan,
6422 .set_key = ath10k_set_key,
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02006423 .set_default_unicast_key = ath10k_set_default_unicast_key,
Kalle Valo5e3dd152013-06-12 20:52:10 +03006424 .sta_state = ath10k_sta_state,
6425 .conf_tx = ath10k_conf_tx,
6426 .remain_on_channel = ath10k_remain_on_channel,
6427 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
6428 .set_rts_threshold = ath10k_set_rts_threshold,
Kalle Valo5e3dd152013-06-12 20:52:10 +03006429 .flush = ath10k_flush,
6430 .tx_last_beacon = ath10k_tx_last_beacon,
Ben Greear46acf7b2014-05-16 17:15:38 +03006431 .set_antenna = ath10k_set_antenna,
6432 .get_antenna = ath10k_get_antenna,
Eliad Pellercf2c92d2014-11-04 11:43:54 +02006433 .reconfig_complete = ath10k_reconfig_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02006434 .get_survey = ath10k_get_survey,
Michal Kazior3ae54222015-03-31 10:49:20 +00006435 .set_bitrate_mask = ath10k_mac_op_set_bitrate_mask,
Michal Kazior9797feb2014-02-14 14:49:48 +01006436 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02006437 .get_tsf = ath10k_get_tsf,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02006438 .ampdu_action = ath10k_ampdu_action,
Ben Greear6cddcc72014-09-29 14:41:46 +03006439 .get_et_sset_count = ath10k_debug_get_et_sset_count,
6440 .get_et_stats = ath10k_debug_get_et_stats,
6441 .get_et_strings = ath10k_debug_get_et_strings,
Michal Kazior500ff9f2015-03-31 10:26:21 +00006442 .add_chanctx = ath10k_mac_op_add_chanctx,
6443 .remove_chanctx = ath10k_mac_op_remove_chanctx,
6444 .change_chanctx = ath10k_mac_op_change_chanctx,
6445 .assign_vif_chanctx = ath10k_mac_op_assign_vif_chanctx,
6446 .unassign_vif_chanctx = ath10k_mac_op_unassign_vif_chanctx,
6447 .switch_vif_chanctx = ath10k_mac_op_switch_vif_chanctx,
Kalle Valo43d2a302014-09-10 18:23:30 +03006448
6449 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
6450
Michal Kazior8cd13ca2013-07-16 09:38:54 +02006451#ifdef CONFIG_PM
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +02006452 .suspend = ath10k_wow_op_suspend,
6453 .resume = ath10k_wow_op_resume,
Michal Kazior8cd13ca2013-07-16 09:38:54 +02006454#endif
Rajkumar Manoharanf5045982015-01-12 14:07:27 +02006455#ifdef CONFIG_MAC80211_DEBUGFS
6456 .sta_add_debugfs = ath10k_sta_add_debugfs,
6457#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03006458};
6459
Kalle Valo5e3dd152013-06-12 20:52:10 +03006460#define CHAN2G(_channel, _freq, _flags) { \
6461 .band = IEEE80211_BAND_2GHZ, \
6462 .hw_value = (_channel), \
6463 .center_freq = (_freq), \
6464 .flags = (_flags), \
6465 .max_antenna_gain = 0, \
6466 .max_power = 30, \
6467}
6468
6469#define CHAN5G(_channel, _freq, _flags) { \
6470 .band = IEEE80211_BAND_5GHZ, \
6471 .hw_value = (_channel), \
6472 .center_freq = (_freq), \
6473 .flags = (_flags), \
6474 .max_antenna_gain = 0, \
6475 .max_power = 30, \
6476}
6477
6478static const struct ieee80211_channel ath10k_2ghz_channels[] = {
6479 CHAN2G(1, 2412, 0),
6480 CHAN2G(2, 2417, 0),
6481 CHAN2G(3, 2422, 0),
6482 CHAN2G(4, 2427, 0),
6483 CHAN2G(5, 2432, 0),
6484 CHAN2G(6, 2437, 0),
6485 CHAN2G(7, 2442, 0),
6486 CHAN2G(8, 2447, 0),
6487 CHAN2G(9, 2452, 0),
6488 CHAN2G(10, 2457, 0),
6489 CHAN2G(11, 2462, 0),
6490 CHAN2G(12, 2467, 0),
6491 CHAN2G(13, 2472, 0),
6492 CHAN2G(14, 2484, 0),
6493};
6494
6495static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02006496 CHAN5G(36, 5180, 0),
6497 CHAN5G(40, 5200, 0),
6498 CHAN5G(44, 5220, 0),
6499 CHAN5G(48, 5240, 0),
6500 CHAN5G(52, 5260, 0),
6501 CHAN5G(56, 5280, 0),
6502 CHAN5G(60, 5300, 0),
6503 CHAN5G(64, 5320, 0),
6504 CHAN5G(100, 5500, 0),
6505 CHAN5G(104, 5520, 0),
6506 CHAN5G(108, 5540, 0),
6507 CHAN5G(112, 5560, 0),
6508 CHAN5G(116, 5580, 0),
6509 CHAN5G(120, 5600, 0),
6510 CHAN5G(124, 5620, 0),
6511 CHAN5G(128, 5640, 0),
6512 CHAN5G(132, 5660, 0),
6513 CHAN5G(136, 5680, 0),
6514 CHAN5G(140, 5700, 0),
Peter Oh4a7898f2015-03-18 11:39:18 -07006515 CHAN5G(144, 5720, 0),
Michal Kazior429ff562013-06-26 08:54:54 +02006516 CHAN5G(149, 5745, 0),
6517 CHAN5G(153, 5765, 0),
6518 CHAN5G(157, 5785, 0),
6519 CHAN5G(161, 5805, 0),
6520 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03006521};
6522
Michal Kaziore7b54192014-08-07 11:03:27 +02006523struct ath10k *ath10k_mac_create(size_t priv_size)
Kalle Valo5e3dd152013-06-12 20:52:10 +03006524{
6525 struct ieee80211_hw *hw;
6526 struct ath10k *ar;
6527
Michal Kaziore7b54192014-08-07 11:03:27 +02006528 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006529 if (!hw)
6530 return NULL;
6531
6532 ar = hw->priv;
6533 ar->hw = hw;
6534
6535 return ar;
6536}
6537
6538void ath10k_mac_destroy(struct ath10k *ar)
6539{
6540 ieee80211_free_hw(ar->hw);
6541}
6542
6543static const struct ieee80211_iface_limit ath10k_if_limits[] = {
6544 {
6545 .max = 8,
6546 .types = BIT(NL80211_IFTYPE_STATION)
6547 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02006548 },
6549 {
6550 .max = 3,
6551 .types = BIT(NL80211_IFTYPE_P2P_GO)
6552 },
6553 {
Michal Kazior75d2bd42014-12-12 12:41:39 +01006554 .max = 1,
6555 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
6556 },
6557 {
Michal Kaziord531cb82013-07-31 10:55:13 +02006558 .max = 7,
6559 .types = BIT(NL80211_IFTYPE_AP)
6560 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03006561};
6562
Bartosz Markowskif2595092013-12-10 16:20:39 +01006563static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006564 {
6565 .max = 8,
6566 .types = BIT(NL80211_IFTYPE_AP)
6567 },
6568};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006569
6570static const struct ieee80211_iface_combination ath10k_if_comb[] = {
6571 {
6572 .limits = ath10k_if_limits,
6573 .n_limits = ARRAY_SIZE(ath10k_if_limits),
6574 .max_interfaces = 8,
6575 .num_different_channels = 1,
6576 .beacon_int_infra_match = true,
6577 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01006578};
6579
6580static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006581 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01006582 .limits = ath10k_10x_if_limits,
6583 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006584 .max_interfaces = 8,
6585 .num_different_channels = 1,
6586 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01006587#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006588 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
6589 BIT(NL80211_CHAN_WIDTH_20) |
6590 BIT(NL80211_CHAN_WIDTH_40) |
6591 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006592#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01006593 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03006594};
6595
Michal Kaziorcf327842015-03-31 10:26:25 +00006596static const struct ieee80211_iface_limit ath10k_tlv_if_limit[] = {
6597 {
6598 .max = 2,
Michal Kaziored25b112015-07-09 13:08:39 +02006599 .types = BIT(NL80211_IFTYPE_STATION),
6600 },
6601 {
6602 .max = 2,
6603 .types = BIT(NL80211_IFTYPE_AP) |
Michal Kaziorcf327842015-03-31 10:26:25 +00006604 BIT(NL80211_IFTYPE_P2P_CLIENT) |
6605 BIT(NL80211_IFTYPE_P2P_GO),
6606 },
6607 {
6608 .max = 1,
6609 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
6610 },
6611};
6612
Michal Kaziored25b112015-07-09 13:08:39 +02006613static const struct ieee80211_iface_limit ath10k_tlv_qcs_if_limit[] = {
6614 {
6615 .max = 2,
6616 .types = BIT(NL80211_IFTYPE_STATION),
6617 },
6618 {
6619 .max = 2,
6620 .types = BIT(NL80211_IFTYPE_P2P_CLIENT),
6621 },
6622 {
6623 .max = 1,
6624 .types = BIT(NL80211_IFTYPE_AP) |
6625 BIT(NL80211_IFTYPE_P2P_GO),
6626 },
6627 {
6628 .max = 1,
6629 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
6630 },
6631};
6632
Michal Kaziorcf327842015-03-31 10:26:25 +00006633static const struct ieee80211_iface_limit ath10k_tlv_if_limit_ibss[] = {
6634 {
6635 .max = 1,
6636 .types = BIT(NL80211_IFTYPE_STATION),
6637 },
6638 {
6639 .max = 1,
6640 .types = BIT(NL80211_IFTYPE_ADHOC),
6641 },
6642};
6643
6644/* FIXME: This is not thouroughly tested. These combinations may over- or
6645 * underestimate hw/fw capabilities.
6646 */
6647static struct ieee80211_iface_combination ath10k_tlv_if_comb[] = {
6648 {
6649 .limits = ath10k_tlv_if_limit,
6650 .num_different_channels = 1,
Michal Kaziored25b112015-07-09 13:08:39 +02006651 .max_interfaces = 4,
Michal Kaziorcf327842015-03-31 10:26:25 +00006652 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
6653 },
6654 {
6655 .limits = ath10k_tlv_if_limit_ibss,
6656 .num_different_channels = 1,
6657 .max_interfaces = 2,
6658 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
6659 },
6660};
6661
6662static struct ieee80211_iface_combination ath10k_tlv_qcs_if_comb[] = {
6663 {
6664 .limits = ath10k_tlv_if_limit,
Michal Kaziored25b112015-07-09 13:08:39 +02006665 .num_different_channels = 1,
6666 .max_interfaces = 4,
Michal Kaziorcf327842015-03-31 10:26:25 +00006667 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
6668 },
6669 {
Michal Kaziored25b112015-07-09 13:08:39 +02006670 .limits = ath10k_tlv_qcs_if_limit,
6671 .num_different_channels = 2,
6672 .max_interfaces = 4,
6673 .n_limits = ARRAY_SIZE(ath10k_tlv_qcs_if_limit),
6674 },
6675 {
Michal Kaziorcf327842015-03-31 10:26:25 +00006676 .limits = ath10k_tlv_if_limit_ibss,
6677 .num_different_channels = 1,
6678 .max_interfaces = 2,
6679 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
6680 },
6681};
6682
Raja Manicf36fef2015-06-22 20:22:25 +05306683static const struct ieee80211_iface_limit ath10k_10_4_if_limits[] = {
6684 {
6685 .max = 1,
6686 .types = BIT(NL80211_IFTYPE_STATION),
6687 },
6688 {
6689 .max = 16,
6690 .types = BIT(NL80211_IFTYPE_AP)
6691 },
6692};
6693
6694static const struct ieee80211_iface_combination ath10k_10_4_if_comb[] = {
6695 {
6696 .limits = ath10k_10_4_if_limits,
6697 .n_limits = ARRAY_SIZE(ath10k_10_4_if_limits),
6698 .max_interfaces = 16,
6699 .num_different_channels = 1,
6700 .beacon_int_infra_match = true,
6701#ifdef CONFIG_ATH10K_DFS_CERTIFIED
6702 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
6703 BIT(NL80211_CHAN_WIDTH_20) |
6704 BIT(NL80211_CHAN_WIDTH_40) |
6705 BIT(NL80211_CHAN_WIDTH_80),
6706#endif
6707 },
6708};
6709
Kalle Valo5e3dd152013-06-12 20:52:10 +03006710static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
6711{
6712 struct ieee80211_sta_vht_cap vht_cap = {0};
6713 u16 mcs_map;
Michal Kaziorbc657a362015-02-26 11:11:22 +01006714 u32 val;
Michal Kazior8865bee42013-07-24 12:36:46 +02006715 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006716
6717 vht_cap.vht_supported = 1;
6718 vht_cap.cap = ar->vht_cap_info;
6719
Michal Kaziorbc657a362015-02-26 11:11:22 +01006720 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
6721 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
6722 val = ar->num_rf_chains - 1;
6723 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
6724 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
6725
6726 vht_cap.cap |= val;
6727 }
6728
6729 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
6730 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
6731 val = ar->num_rf_chains - 1;
6732 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
6733 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
6734
6735 vht_cap.cap |= val;
6736 }
6737
Michal Kazior8865bee42013-07-24 12:36:46 +02006738 mcs_map = 0;
6739 for (i = 0; i < 8; i++) {
6740 if (i < ar->num_rf_chains)
6741 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
6742 else
6743 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
6744 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03006745
6746 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
6747 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
6748
6749 return vht_cap;
6750}
6751
6752static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
6753{
6754 int i;
6755 struct ieee80211_sta_ht_cap ht_cap = {0};
6756
6757 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
6758 return ht_cap;
6759
6760 ht_cap.ht_supported = 1;
6761 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
6762 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
6763 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
6764 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
6765 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
6766
6767 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
6768 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
6769
6770 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
6771 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
6772
6773 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
6774 u32 smps;
6775
6776 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
6777 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
6778
6779 ht_cap.cap |= smps;
6780 }
6781
6782 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
6783 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
6784
6785 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
6786 u32 stbc;
6787
6788 stbc = ar->ht_cap_info;
6789 stbc &= WMI_HT_CAP_RX_STBC;
6790 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
6791 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
6792 stbc &= IEEE80211_HT_CAP_RX_STBC;
6793
6794 ht_cap.cap |= stbc;
6795 }
6796
6797 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
6798 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
6799
6800 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
6801 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
6802
6803 /* max AMSDU is implicitly taken from vht_cap_info */
6804 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
6805 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
6806
Michal Kazior8865bee42013-07-24 12:36:46 +02006807 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03006808 ht_cap.mcs.rx_mask[i] = 0xFF;
6809
6810 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
6811
6812 return ht_cap;
6813}
6814
Kalle Valo5e3dd152013-06-12 20:52:10 +03006815static void ath10k_get_arvif_iter(void *data, u8 *mac,
6816 struct ieee80211_vif *vif)
6817{
6818 struct ath10k_vif_iter *arvif_iter = data;
6819 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6820
6821 if (arvif->vdev_id == arvif_iter->vdev_id)
6822 arvif_iter->arvif = arvif;
6823}
6824
6825struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
6826{
6827 struct ath10k_vif_iter arvif_iter;
6828 u32 flags;
6829
6830 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
6831 arvif_iter.vdev_id = vdev_id;
6832
6833 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
6834 ieee80211_iterate_active_interfaces_atomic(ar->hw,
6835 flags,
6836 ath10k_get_arvif_iter,
6837 &arvif_iter);
6838 if (!arvif_iter.arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02006839 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006840 return NULL;
6841 }
6842
6843 return arvif_iter.arvif;
6844}
6845
6846int ath10k_mac_register(struct ath10k *ar)
6847{
Johannes Berg3cb10942015-01-22 21:38:45 +01006848 static const u32 cipher_suites[] = {
6849 WLAN_CIPHER_SUITE_WEP40,
6850 WLAN_CIPHER_SUITE_WEP104,
6851 WLAN_CIPHER_SUITE_TKIP,
6852 WLAN_CIPHER_SUITE_CCMP,
6853 WLAN_CIPHER_SUITE_AES_CMAC,
6854 };
Kalle Valo5e3dd152013-06-12 20:52:10 +03006855 struct ieee80211_supported_band *band;
6856 struct ieee80211_sta_vht_cap vht_cap;
6857 struct ieee80211_sta_ht_cap ht_cap;
6858 void *channels;
6859 int ret;
6860
6861 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
6862
6863 SET_IEEE80211_DEV(ar->hw, ar->dev);
6864
6865 ht_cap = ath10k_get_ht_cap(ar);
6866 vht_cap = ath10k_create_vht_cap(ar);
6867
Michal Kaziorc94aa7e2015-03-24 12:38:11 +00006868 BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels) +
6869 ARRAY_SIZE(ath10k_5ghz_channels)) !=
6870 ATH10K_NUM_CHANS);
6871
Kalle Valo5e3dd152013-06-12 20:52:10 +03006872 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
6873 channels = kmemdup(ath10k_2ghz_channels,
6874 sizeof(ath10k_2ghz_channels),
6875 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02006876 if (!channels) {
6877 ret = -ENOMEM;
6878 goto err_free;
6879 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03006880
6881 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
6882 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
6883 band->channels = channels;
6884 band->n_bitrates = ath10k_g_rates_size;
6885 band->bitrates = ath10k_g_rates;
6886 band->ht_cap = ht_cap;
6887
Yanbo Lid68bb122015-01-23 08:18:20 +08006888 /* Enable the VHT support at 2.4 GHz */
6889 band->vht_cap = vht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006890
6891 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
6892 }
6893
6894 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
6895 channels = kmemdup(ath10k_5ghz_channels,
6896 sizeof(ath10k_5ghz_channels),
6897 GFP_KERNEL);
6898 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02006899 ret = -ENOMEM;
6900 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006901 }
6902
6903 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
6904 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
6905 band->channels = channels;
6906 band->n_bitrates = ath10k_a_rates_size;
6907 band->bitrates = ath10k_a_rates;
6908 band->ht_cap = ht_cap;
6909 band->vht_cap = vht_cap;
6910 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
6911 }
6912
6913 ar->hw->wiphy->interface_modes =
6914 BIT(NL80211_IFTYPE_STATION) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01006915 BIT(NL80211_IFTYPE_AP);
6916
Ben Greear46acf7b2014-05-16 17:15:38 +03006917 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
6918 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
6919
Bartosz Markowskid3541812013-12-10 16:20:40 +01006920 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
6921 ar->hw->wiphy->interface_modes |=
Michal Kazior75d2bd42014-12-12 12:41:39 +01006922 BIT(NL80211_IFTYPE_P2P_DEVICE) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01006923 BIT(NL80211_IFTYPE_P2P_CLIENT) |
6924 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006925
Johannes Berg30686bf2015-06-02 21:39:54 +02006926 ieee80211_hw_set(ar->hw, SIGNAL_DBM);
6927 ieee80211_hw_set(ar->hw, SUPPORTS_PS);
6928 ieee80211_hw_set(ar->hw, SUPPORTS_DYNAMIC_PS);
6929 ieee80211_hw_set(ar->hw, MFP_CAPABLE);
6930 ieee80211_hw_set(ar->hw, REPORTS_TX_ACK_STATUS);
6931 ieee80211_hw_set(ar->hw, HAS_RATE_CONTROL);
6932 ieee80211_hw_set(ar->hw, AP_LINK_PS);
6933 ieee80211_hw_set(ar->hw, SPECTRUM_MGMT);
Johannes Berg30686bf2015-06-02 21:39:54 +02006934 ieee80211_hw_set(ar->hw, SUPPORT_FAST_XMIT);
6935 ieee80211_hw_set(ar->hw, CONNECTION_MONITOR);
6936 ieee80211_hw_set(ar->hw, SUPPORTS_PER_STA_GTK);
6937 ieee80211_hw_set(ar->hw, WANT_MONITOR_VIF);
6938 ieee80211_hw_set(ar->hw, CHANCTX_STA_CSA);
6939 ieee80211_hw_set(ar->hw, QUEUE_CONTROL);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006940
David Liuccec9032015-07-24 20:25:32 +03006941 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
6942 ieee80211_hw_set(ar->hw, SW_CRYPTO_CONTROL);
6943
Eliad Peller0d8614b2014-09-10 14:07:36 +03006944 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
Janusz Dziedzic0cd9bc12015-04-10 13:23:23 +00006945 ar->hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
Eliad Peller0d8614b2014-09-10 14:07:36 +03006946
Kalle Valo5e3dd152013-06-12 20:52:10 +03006947 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
Eliad Peller0d8614b2014-09-10 14:07:36 +03006948 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006949
6950 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
Johannes Berg30686bf2015-06-02 21:39:54 +02006951 ieee80211_hw_set(ar->hw, AMPDU_AGGREGATION);
6952 ieee80211_hw_set(ar->hw, TX_AMPDU_SETUP_IN_HW);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006953 }
6954
6955 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
6956 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
6957
6958 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01006959 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006960
Kalle Valo5e3dd152013-06-12 20:52:10 +03006961 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
6962
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02006963 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
6964 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
6965
6966 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
6967 * that userspace (e.g. wpa_supplicant/hostapd) can generate
6968 * correct Probe Responses. This is more of a hack advert..
6969 */
6970 ar->hw->wiphy->probe_resp_offload |=
6971 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
6972 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
6973 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
6974 }
6975
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03006976 if (test_bit(WMI_SERVICE_TDLS, ar->wmi.svc_map))
6977 ar->hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
6978
Kalle Valo5e3dd152013-06-12 20:52:10 +03006979 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01006980 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006981 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
6982
6983 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
Rajkumar Manoharan78157a12014-11-17 16:44:15 +02006984 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
6985
Janusz.Dziedzic@tieto.com37a0b392015-03-12 13:11:41 +01006986 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
6987
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +02006988 ret = ath10k_wow_init(ar);
6989 if (ret) {
6990 ath10k_warn(ar, "failed to init wow: %d\n", ret);
6991 goto err_free;
6992 }
6993
Janusz Dziedzicc7025342015-06-15 14:46:41 +03006994 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
6995
Kalle Valo5e3dd152013-06-12 20:52:10 +03006996 /*
6997 * on LL hardware queues are managed entirely by the FW
6998 * so we only advertise to mac we can do the queues thing
6999 */
Michal Kazior96d828d2015-03-31 10:26:23 +00007000 ar->hw->queues = IEEE80211_MAX_QUEUES;
7001
7002 /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is
7003 * something that vdev_ids can't reach so that we don't stop the queue
7004 * accidentally.
7005 */
7006 ar->hw->offchannel_tx_hw_queue = IEEE80211_MAX_QUEUES - 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03007007
Kalle Valo5cc7caf2014-12-17 12:20:54 +02007008 switch (ar->wmi.op_version) {
7009 case ATH10K_FW_WMI_OP_VERSION_MAIN:
Bartosz Markowskif2595092013-12-10 16:20:39 +01007010 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
7011 ar->hw->wiphy->n_iface_combinations =
7012 ARRAY_SIZE(ath10k_if_comb);
Michal Kaziorcf850d12014-07-24 20:07:00 +03007013 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
Kalle Valo5cc7caf2014-12-17 12:20:54 +02007014 break;
Michal Kaziorcf327842015-03-31 10:26:25 +00007015 case ATH10K_FW_WMI_OP_VERSION_TLV:
7016 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
7017 ar->hw->wiphy->iface_combinations =
7018 ath10k_tlv_qcs_if_comb;
7019 ar->hw->wiphy->n_iface_combinations =
7020 ARRAY_SIZE(ath10k_tlv_qcs_if_comb);
7021 } else {
7022 ar->hw->wiphy->iface_combinations = ath10k_tlv_if_comb;
7023 ar->hw->wiphy->n_iface_combinations =
7024 ARRAY_SIZE(ath10k_tlv_if_comb);
7025 }
7026 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
7027 break;
Kalle Valo5cc7caf2014-12-17 12:20:54 +02007028 case ATH10K_FW_WMI_OP_VERSION_10_1:
7029 case ATH10K_FW_WMI_OP_VERSION_10_2:
Rajkumar Manoharan4a16fbe2014-12-17 12:21:12 +02007030 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
Kalle Valo5cc7caf2014-12-17 12:20:54 +02007031 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
7032 ar->hw->wiphy->n_iface_combinations =
7033 ARRAY_SIZE(ath10k_10x_if_comb);
7034 break;
Raja Mani9bd21322015-06-22 20:10:09 +05307035 case ATH10K_FW_WMI_OP_VERSION_10_4:
Raja Manicf36fef2015-06-22 20:22:25 +05307036 ar->hw->wiphy->iface_combinations = ath10k_10_4_if_comb;
7037 ar->hw->wiphy->n_iface_combinations =
7038 ARRAY_SIZE(ath10k_10_4_if_comb);
Raja Mani9bd21322015-06-22 20:10:09 +05307039 break;
Kalle Valo5cc7caf2014-12-17 12:20:54 +02007040 case ATH10K_FW_WMI_OP_VERSION_UNSET:
7041 case ATH10K_FW_WMI_OP_VERSION_MAX:
7042 WARN_ON(1);
7043 ret = -EINVAL;
7044 goto err_free;
Bartosz Markowskif2595092013-12-10 16:20:39 +01007045 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03007046
David Liuccec9032015-07-24 20:25:32 +03007047 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
7048 ar->hw->netdev_features = NETIF_F_HW_CSUM;
Michal Kazior7c199992013-07-31 10:47:57 +02007049
Janusz Dziedzic9702c682013-11-20 09:59:41 +02007050 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
7051 /* Init ath dfs pattern detector */
7052 ar->ath_common.debug_mask = ATH_DBG_DFS;
7053 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
7054 NL80211_DFS_UNSET);
7055
7056 if (!ar->dfs_detector)
Michal Kazior7aa7a722014-08-25 12:09:38 +02007057 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02007058 }
7059
Kalle Valo5e3dd152013-06-12 20:52:10 +03007060 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
7061 ath10k_reg_notifier);
7062 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02007063 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02007064 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03007065 }
7066
Johannes Berg3cb10942015-01-22 21:38:45 +01007067 ar->hw->wiphy->cipher_suites = cipher_suites;
7068 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
7069
Kalle Valo5e3dd152013-06-12 20:52:10 +03007070 ret = ieee80211_register_hw(ar->hw);
7071 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02007072 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02007073 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03007074 }
7075
7076 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
7077 ret = regulatory_hint(ar->hw->wiphy,
7078 ar->ath_common.regulatory.alpha2);
7079 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02007080 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03007081 }
7082
7083 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02007084
7085err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03007086 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02007087err_free:
7088 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
7089 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
7090
Kalle Valo5e3dd152013-06-12 20:52:10 +03007091 return ret;
7092}
7093
7094void ath10k_mac_unregister(struct ath10k *ar)
7095{
7096 ieee80211_unregister_hw(ar->hw);
7097
Janusz Dziedzic9702c682013-11-20 09:59:41 +02007098 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
7099 ar->dfs_detector->exit(ar->dfs_detector);
7100
Kalle Valo5e3dd152013-06-12 20:52:10 +03007101 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
7102 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
7103
7104 SET_IEEE80211_DEV(ar->hw, NULL);
7105}