blob: 3bb9ea8a69039d491dadb70d0fe363da782f4cde [file] [log] [blame]
Kalle Valo5e3dd152013-06-12 20:52:10 +03001/*
2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include "mac.h"
19
20#include <net/mac80211.h>
21#include <linux/etherdevice.h>
22
Michal Kazior8cd13ca2013-07-16 09:38:54 +020023#include "hif.h"
Kalle Valo5e3dd152013-06-12 20:52:10 +030024#include "core.h"
25#include "debug.h"
26#include "wmi.h"
27#include "htt.h"
28#include "txrx.h"
Kalle Valo43d2a302014-09-10 18:23:30 +030029#include "testmode.h"
Michal Kaziord7579d12014-12-03 10:10:54 +020030#include "wmi.h"
Michal Kaziorb4aa5392015-03-31 10:26:24 +000031#include "wmi-tlv.h"
Michal Kaziord7579d12014-12-03 10:10:54 +020032#include "wmi-ops.h"
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +020033#include "wow.h"
Kalle Valo5e3dd152013-06-12 20:52:10 +030034
Michal Kaziordcc33092015-03-30 09:51:54 +030035/*********/
36/* Rates */
37/*********/
38
Michal Kaziordcc33092015-03-30 09:51:54 +030039static struct ieee80211_rate ath10k_rates[] = {
Michal Kazior5528e032015-03-30 09:51:56 +030040 { .bitrate = 10,
41 .hw_value = ATH10K_HW_RATE_CCK_LP_1M },
42 { .bitrate = 20,
43 .hw_value = ATH10K_HW_RATE_CCK_LP_2M,
44 .hw_value_short = ATH10K_HW_RATE_CCK_SP_2M,
45 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
46 { .bitrate = 55,
47 .hw_value = ATH10K_HW_RATE_CCK_LP_5_5M,
48 .hw_value_short = ATH10K_HW_RATE_CCK_SP_5_5M,
49 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
50 { .bitrate = 110,
51 .hw_value = ATH10K_HW_RATE_CCK_LP_11M,
52 .hw_value_short = ATH10K_HW_RATE_CCK_SP_11M,
53 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
Michal Kazior5653b392015-03-30 09:51:54 +030054
Michal Kazioraf001482015-03-30 09:51:56 +030055 { .bitrate = 60, .hw_value = ATH10K_HW_RATE_OFDM_6M },
56 { .bitrate = 90, .hw_value = ATH10K_HW_RATE_OFDM_9M },
57 { .bitrate = 120, .hw_value = ATH10K_HW_RATE_OFDM_12M },
58 { .bitrate = 180, .hw_value = ATH10K_HW_RATE_OFDM_18M },
59 { .bitrate = 240, .hw_value = ATH10K_HW_RATE_OFDM_24M },
60 { .bitrate = 360, .hw_value = ATH10K_HW_RATE_OFDM_36M },
61 { .bitrate = 480, .hw_value = ATH10K_HW_RATE_OFDM_48M },
62 { .bitrate = 540, .hw_value = ATH10K_HW_RATE_OFDM_54M },
Michal Kaziordcc33092015-03-30 09:51:54 +030063};
64
Michal Kazior8d7aa6b2015-03-30 09:51:57 +030065#define ATH10K_MAC_FIRST_OFDM_RATE_IDX 4
66
67#define ath10k_a_rates (ath10k_rates + ATH10K_MAC_FIRST_OFDM_RATE_IDX)
68#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - \
69 ATH10K_MAC_FIRST_OFDM_RATE_IDX)
Michal Kaziordcc33092015-03-30 09:51:54 +030070#define ath10k_g_rates (ath10k_rates + 0)
71#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
72
Michal Kazior486017c2015-03-30 09:51:54 +030073static bool ath10k_mac_bitrate_is_cck(int bitrate)
74{
75 switch (bitrate) {
76 case 10:
77 case 20:
78 case 55:
79 case 110:
80 return true;
81 }
82
83 return false;
84}
85
86static u8 ath10k_mac_bitrate_to_rate(int bitrate)
87{
88 return DIV_ROUND_UP(bitrate, 5) |
89 (ath10k_mac_bitrate_is_cck(bitrate) ? BIT(7) : 0);
90}
91
Michal Kazior5528e032015-03-30 09:51:56 +030092u8 ath10k_mac_hw_rate_to_idx(const struct ieee80211_supported_band *sband,
93 u8 hw_rate)
94{
95 const struct ieee80211_rate *rate;
96 int i;
97
98 for (i = 0; i < sband->n_bitrates; i++) {
99 rate = &sband->bitrates[i];
100
101 if (rate->hw_value == hw_rate)
102 return i;
103 else if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE &&
104 rate->hw_value_short == hw_rate)
105 return i;
106 }
107
108 return 0;
109}
110
Michal Kazior01cebe12015-03-30 09:51:56 +0300111u8 ath10k_mac_bitrate_to_idx(const struct ieee80211_supported_band *sband,
112 u32 bitrate)
113{
114 int i;
115
116 for (i = 0; i < sband->n_bitrates; i++)
117 if (sband->bitrates[i].bitrate == bitrate)
118 return i;
119
120 return 0;
121}
122
Michal Kazior3ae54222015-03-31 10:49:20 +0000123static int ath10k_mac_get_max_vht_mcs_map(u16 mcs_map, int nss)
124{
125 switch ((mcs_map >> (2 * nss)) & 0x3) {
126 case IEEE80211_VHT_MCS_SUPPORT_0_7: return BIT(8) - 1;
127 case IEEE80211_VHT_MCS_SUPPORT_0_8: return BIT(9) - 1;
128 case IEEE80211_VHT_MCS_SUPPORT_0_9: return BIT(10) - 1;
129 }
130 return 0;
131}
132
Michal Kazior45c9abc2015-04-21 20:42:58 +0300133static u32
134ath10k_mac_max_ht_nss(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
135{
136 int nss;
137
138 for (nss = IEEE80211_HT_MCS_MASK_LEN - 1; nss >= 0; nss--)
139 if (ht_mcs_mask[nss])
140 return nss + 1;
141
142 return 1;
143}
144
145static u32
146ath10k_mac_max_vht_nss(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
147{
148 int nss;
149
150 for (nss = NL80211_VHT_NSS_MAX - 1; nss >= 0; nss--)
151 if (vht_mcs_mask[nss])
152 return nss + 1;
153
154 return 1;
155}
Kalle Valo5e3dd152013-06-12 20:52:10 +0300156
157/**********/
158/* Crypto */
159/**********/
160
161static int ath10k_send_key(struct ath10k_vif *arvif,
162 struct ieee80211_key_conf *key,
163 enum set_key_cmd cmd,
Michal Kazior370e5672015-02-18 14:02:26 +0100164 const u8 *macaddr, u32 flags)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300165{
Michal Kazior7aa7a722014-08-25 12:09:38 +0200166 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300167 struct wmi_vdev_install_key_arg arg = {
168 .vdev_id = arvif->vdev_id,
169 .key_idx = key->keyidx,
170 .key_len = key->keylen,
171 .key_data = key->key,
Michal Kazior370e5672015-02-18 14:02:26 +0100172 .key_flags = flags,
Kalle Valo5e3dd152013-06-12 20:52:10 +0300173 .macaddr = macaddr,
174 };
175
Michal Kazior548db542013-07-05 16:15:15 +0300176 lockdep_assert_held(&arvif->ar->conf_mutex);
177
Kalle Valo5e3dd152013-06-12 20:52:10 +0300178 switch (key->cipher) {
179 case WLAN_CIPHER_SUITE_CCMP:
180 arg.key_cipher = WMI_CIPHER_AES_CCM;
Marek Kwaczynskie4e82e92015-01-24 12:14:53 +0200181 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300182 break;
183 case WLAN_CIPHER_SUITE_TKIP:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300184 arg.key_cipher = WMI_CIPHER_TKIP;
185 arg.key_txmic_len = 8;
186 arg.key_rxmic_len = 8;
187 break;
188 case WLAN_CIPHER_SUITE_WEP40:
189 case WLAN_CIPHER_SUITE_WEP104:
190 arg.key_cipher = WMI_CIPHER_WEP;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300191 break;
Johannes Berg3cb10942015-01-22 21:38:45 +0100192 case WLAN_CIPHER_SUITE_AES_CMAC:
Bartosz Markowskid7131c02015-03-10 14:32:19 +0100193 WARN_ON(1);
194 return -EINVAL;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300195 default:
Michal Kazior7aa7a722014-08-25 12:09:38 +0200196 ath10k_warn(ar, "cipher %d is not supported\n", key->cipher);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300197 return -EOPNOTSUPP;
198 }
199
David Liuccec9032015-07-24 20:25:32 +0300200 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
201 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
202 }
203
Kalle Valo5e3dd152013-06-12 20:52:10 +0300204 if (cmd == DISABLE_KEY) {
205 arg.key_cipher = WMI_CIPHER_NONE;
206 arg.key_data = NULL;
207 }
208
209 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
210}
211
212static int ath10k_install_key(struct ath10k_vif *arvif,
213 struct ieee80211_key_conf *key,
214 enum set_key_cmd cmd,
Michal Kazior370e5672015-02-18 14:02:26 +0100215 const u8 *macaddr, u32 flags)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300216{
217 struct ath10k *ar = arvif->ar;
218 int ret;
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +0300219 unsigned long time_left;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300220
Michal Kazior548db542013-07-05 16:15:15 +0300221 lockdep_assert_held(&ar->conf_mutex);
222
Wolfram Sang16735d02013-11-14 14:32:02 -0800223 reinit_completion(&ar->install_key_done);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300224
David Liuccec9032015-07-24 20:25:32 +0300225 if (arvif->nohwcrypt)
226 return 1;
227
Michal Kazior370e5672015-02-18 14:02:26 +0100228 ret = ath10k_send_key(arvif, key, cmd, macaddr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300229 if (ret)
230 return ret;
231
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +0300232 time_left = wait_for_completion_timeout(&ar->install_key_done, 3 * HZ);
233 if (time_left == 0)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300234 return -ETIMEDOUT;
235
236 return 0;
237}
238
239static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
240 const u8 *addr)
241{
242 struct ath10k *ar = arvif->ar;
243 struct ath10k_peer *peer;
244 int ret;
245 int i;
Michal Kazior370e5672015-02-18 14:02:26 +0100246 u32 flags;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300247
248 lockdep_assert_held(&ar->conf_mutex);
249
250 spin_lock_bh(&ar->data_lock);
251 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
252 spin_unlock_bh(&ar->data_lock);
253
254 if (!peer)
255 return -ENOENT;
256
257 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
258 if (arvif->wep_keys[i] == NULL)
259 continue;
Michal Kazior370e5672015-02-18 14:02:26 +0100260
261 flags = 0;
262 flags |= WMI_KEY_PAIRWISE;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300263
264 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
Michal Kaziorce90b272015-04-10 13:23:21 +0000265 addr, flags);
David Liuccec9032015-07-24 20:25:32 +0300266 if (ret < 0)
Michal Kaziorce90b272015-04-10 13:23:21 +0000267 return ret;
268
269 flags = 0;
270 flags |= WMI_KEY_GROUP;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300271
272 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
Michal Kazior370e5672015-02-18 14:02:26 +0100273 addr, flags);
David Liuccec9032015-07-24 20:25:32 +0300274 if (ret < 0)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300275 return ret;
276
Sujith Manoharanae167132014-11-25 11:46:59 +0530277 spin_lock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300278 peer->keys[i] = arvif->wep_keys[i];
Sujith Manoharanae167132014-11-25 11:46:59 +0530279 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300280 }
281
Michal Kaziorce90b272015-04-10 13:23:21 +0000282 /* In some cases (notably with static WEP IBSS with multiple keys)
283 * multicast Tx becomes broken. Both pairwise and groupwise keys are
284 * installed already. Using WMI_KEY_TX_USAGE in different combinations
285 * didn't seem help. Using def_keyid vdev parameter seems to be
286 * effective so use that.
287 *
288 * FIXME: Revisit. Perhaps this can be done in a less hacky way.
289 */
290 if (arvif->def_wep_key_idx == -1)
291 return 0;
292
293 ret = ath10k_wmi_vdev_set_param(arvif->ar,
294 arvif->vdev_id,
295 arvif->ar->wmi.vdev_param->def_keyid,
296 arvif->def_wep_key_idx);
297 if (ret) {
298 ath10k_warn(ar, "failed to re-set def wpa key idxon vdev %i: %d\n",
299 arvif->vdev_id, ret);
300 return ret;
301 }
302
Kalle Valo5e3dd152013-06-12 20:52:10 +0300303 return 0;
304}
305
306static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
307 const u8 *addr)
308{
309 struct ath10k *ar = arvif->ar;
310 struct ath10k_peer *peer;
311 int first_errno = 0;
312 int ret;
313 int i;
Michal Kazior370e5672015-02-18 14:02:26 +0100314 u32 flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300315
316 lockdep_assert_held(&ar->conf_mutex);
317
318 spin_lock_bh(&ar->data_lock);
319 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
320 spin_unlock_bh(&ar->data_lock);
321
322 if (!peer)
323 return -ENOENT;
324
325 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
326 if (peer->keys[i] == NULL)
327 continue;
328
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200329 /* key flags are not required to delete the key */
Kalle Valo5e3dd152013-06-12 20:52:10 +0300330 ret = ath10k_install_key(arvif, peer->keys[i],
Michal Kazior370e5672015-02-18 14:02:26 +0100331 DISABLE_KEY, addr, flags);
David Liuccec9032015-07-24 20:25:32 +0300332 if (ret < 0 && first_errno == 0)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300333 first_errno = ret;
334
David Liuccec9032015-07-24 20:25:32 +0300335 if (ret < 0)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200336 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300337 i, ret);
338
Sujith Manoharanae167132014-11-25 11:46:59 +0530339 spin_lock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300340 peer->keys[i] = NULL;
Sujith Manoharanae167132014-11-25 11:46:59 +0530341 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300342 }
343
344 return first_errno;
345}
346
Sujith Manoharan504f6cd2014-11-25 11:46:58 +0530347bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr,
348 u8 keyidx)
349{
350 struct ath10k_peer *peer;
351 int i;
352
353 lockdep_assert_held(&ar->data_lock);
354
355 /* We don't know which vdev this peer belongs to,
356 * since WMI doesn't give us that information.
357 *
358 * FIXME: multi-bss needs to be handled.
359 */
360 peer = ath10k_peer_find(ar, 0, addr);
361 if (!peer)
362 return false;
363
364 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
365 if (peer->keys[i] && peer->keys[i]->keyidx == keyidx)
366 return true;
367 }
368
369 return false;
370}
371
Kalle Valo5e3dd152013-06-12 20:52:10 +0300372static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
373 struct ieee80211_key_conf *key)
374{
375 struct ath10k *ar = arvif->ar;
376 struct ath10k_peer *peer;
377 u8 addr[ETH_ALEN];
378 int first_errno = 0;
379 int ret;
380 int i;
Michal Kazior370e5672015-02-18 14:02:26 +0100381 u32 flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300382
383 lockdep_assert_held(&ar->conf_mutex);
384
385 for (;;) {
386 /* since ath10k_install_key we can't hold data_lock all the
387 * time, so we try to remove the keys incrementally */
388 spin_lock_bh(&ar->data_lock);
389 i = 0;
390 list_for_each_entry(peer, &ar->peers, list) {
391 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
392 if (peer->keys[i] == key) {
Kalle Valob25f32c2014-09-14 12:50:49 +0300393 ether_addr_copy(addr, peer->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300394 peer->keys[i] = NULL;
395 break;
396 }
397 }
398
399 if (i < ARRAY_SIZE(peer->keys))
400 break;
401 }
402 spin_unlock_bh(&ar->data_lock);
403
404 if (i == ARRAY_SIZE(peer->keys))
405 break;
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200406 /* key flags are not required to delete the key */
Michal Kazior370e5672015-02-18 14:02:26 +0100407 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr, flags);
David Liuccec9032015-07-24 20:25:32 +0300408 if (ret < 0 && first_errno == 0)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300409 first_errno = ret;
410
411 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200412 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +0200413 addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300414 }
415
416 return first_errno;
417}
418
Michal Kaziorad325cb2015-02-18 14:02:27 +0100419static int ath10k_mac_vif_update_wep_key(struct ath10k_vif *arvif,
420 struct ieee80211_key_conf *key)
421{
422 struct ath10k *ar = arvif->ar;
423 struct ath10k_peer *peer;
424 int ret;
425
426 lockdep_assert_held(&ar->conf_mutex);
427
428 list_for_each_entry(peer, &ar->peers, list) {
429 if (!memcmp(peer->addr, arvif->vif->addr, ETH_ALEN))
430 continue;
431
432 if (!memcmp(peer->addr, arvif->bssid, ETH_ALEN))
433 continue;
434
435 if (peer->keys[key->keyidx] == key)
436 continue;
437
438 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vif vdev %i update key %i needs update\n",
439 arvif->vdev_id, key->keyidx);
440
441 ret = ath10k_install_peer_wep_keys(arvif, peer->addr);
442 if (ret) {
443 ath10k_warn(ar, "failed to update wep keys on vdev %i for peer %pM: %d\n",
444 arvif->vdev_id, peer->addr, ret);
445 return ret;
446 }
447 }
448
449 return 0;
450}
451
Kalle Valo5e3dd152013-06-12 20:52:10 +0300452/*********************/
453/* General utilities */
454/*********************/
455
456static inline enum wmi_phy_mode
457chan_to_phymode(const struct cfg80211_chan_def *chandef)
458{
459 enum wmi_phy_mode phymode = MODE_UNKNOWN;
460
461 switch (chandef->chan->band) {
462 case IEEE80211_BAND_2GHZ:
463 switch (chandef->width) {
464 case NL80211_CHAN_WIDTH_20_NOHT:
Peter Oh6faab122014-12-18 10:13:00 -0800465 if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM)
466 phymode = MODE_11B;
467 else
468 phymode = MODE_11G;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300469 break;
470 case NL80211_CHAN_WIDTH_20:
471 phymode = MODE_11NG_HT20;
472 break;
473 case NL80211_CHAN_WIDTH_40:
474 phymode = MODE_11NG_HT40;
475 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400476 case NL80211_CHAN_WIDTH_5:
477 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300478 case NL80211_CHAN_WIDTH_80:
479 case NL80211_CHAN_WIDTH_80P80:
480 case NL80211_CHAN_WIDTH_160:
481 phymode = MODE_UNKNOWN;
482 break;
483 }
484 break;
485 case IEEE80211_BAND_5GHZ:
486 switch (chandef->width) {
487 case NL80211_CHAN_WIDTH_20_NOHT:
488 phymode = MODE_11A;
489 break;
490 case NL80211_CHAN_WIDTH_20:
491 phymode = MODE_11NA_HT20;
492 break;
493 case NL80211_CHAN_WIDTH_40:
494 phymode = MODE_11NA_HT40;
495 break;
496 case NL80211_CHAN_WIDTH_80:
497 phymode = MODE_11AC_VHT80;
498 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400499 case NL80211_CHAN_WIDTH_5:
500 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300501 case NL80211_CHAN_WIDTH_80P80:
502 case NL80211_CHAN_WIDTH_160:
503 phymode = MODE_UNKNOWN;
504 break;
505 }
506 break;
507 default:
508 break;
509 }
510
511 WARN_ON(phymode == MODE_UNKNOWN);
512 return phymode;
513}
514
515static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
516{
517/*
518 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
519 * 0 for no restriction
520 * 1 for 1/4 us
521 * 2 for 1/2 us
522 * 3 for 1 us
523 * 4 for 2 us
524 * 5 for 4 us
525 * 6 for 8 us
526 * 7 for 16 us
527 */
528 switch (mpdudensity) {
529 case 0:
530 return 0;
531 case 1:
532 case 2:
533 case 3:
534 /* Our lower layer calculations limit our precision to
535 1 microsecond */
536 return 1;
537 case 4:
538 return 2;
539 case 5:
540 return 4;
541 case 6:
542 return 8;
543 case 7:
544 return 16;
545 default:
546 return 0;
547 }
548}
549
Michal Kazior500ff9f2015-03-31 10:26:21 +0000550int ath10k_mac_vif_chan(struct ieee80211_vif *vif,
551 struct cfg80211_chan_def *def)
552{
553 struct ieee80211_chanctx_conf *conf;
554
555 rcu_read_lock();
556 conf = rcu_dereference(vif->chanctx_conf);
557 if (!conf) {
558 rcu_read_unlock();
559 return -ENOENT;
560 }
561
562 *def = conf->def;
563 rcu_read_unlock();
564
565 return 0;
566}
567
568static void ath10k_mac_num_chanctxs_iter(struct ieee80211_hw *hw,
569 struct ieee80211_chanctx_conf *conf,
570 void *data)
571{
572 int *num = data;
573
574 (*num)++;
575}
576
577static int ath10k_mac_num_chanctxs(struct ath10k *ar)
578{
579 int num = 0;
580
581 ieee80211_iter_chan_contexts_atomic(ar->hw,
582 ath10k_mac_num_chanctxs_iter,
583 &num);
584
585 return num;
586}
587
588static void
589ath10k_mac_get_any_chandef_iter(struct ieee80211_hw *hw,
590 struct ieee80211_chanctx_conf *conf,
591 void *data)
592{
593 struct cfg80211_chan_def **def = data;
594
595 *def = &conf->def;
596}
597
Marek Puzyniak7390ed32015-03-30 09:51:52 +0300598static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr,
599 enum wmi_peer_type peer_type)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300600{
Michal Kaziore04cafb2015-08-05 12:15:24 +0200601 struct ath10k_vif *arvif;
602 int num_peers = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300603 int ret;
604
605 lockdep_assert_held(&ar->conf_mutex);
606
Michal Kaziore04cafb2015-08-05 12:15:24 +0200607 num_peers = ar->num_peers;
608
609 /* Each vdev consumes a peer entry as well */
610 list_for_each_entry(arvif, &ar->arvifs, list)
611 num_peers++;
612
613 if (num_peers >= ar->max_num_peers)
Michal Kaziorcfd10612014-11-25 15:16:05 +0100614 return -ENOBUFS;
615
Marek Puzyniak7390ed32015-03-30 09:51:52 +0300616 ret = ath10k_wmi_peer_create(ar, vdev_id, addr, peer_type);
Ben Greear479398b2013-11-04 09:19:34 -0800617 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200618 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200619 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300620 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800621 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300622
623 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800624 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200625 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200626 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300627 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800628 }
Michal Kazior292a7532014-11-25 15:16:04 +0100629
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100630 ar->num_peers++;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300631
632 return 0;
633}
634
Kalle Valo5a13e762014-01-20 11:01:46 +0200635static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
636{
637 struct ath10k *ar = arvif->ar;
638 u32 param;
639 int ret;
640
641 param = ar->wmi.pdev_param->sta_kickout_th;
642 ret = ath10k_wmi_pdev_set_param(ar, param,
643 ATH10K_KICKOUT_THRESHOLD);
644 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200645 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200646 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200647 return ret;
648 }
649
650 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
651 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
652 ATH10K_KEEPALIVE_MIN_IDLE);
653 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200654 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200655 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200656 return ret;
657 }
658
659 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
660 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
661 ATH10K_KEEPALIVE_MAX_IDLE);
662 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200663 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200664 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200665 return ret;
666 }
667
668 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
669 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
670 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
671 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200672 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200673 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200674 return ret;
675 }
676
677 return 0;
678}
679
Vivek Natarajanacab6402014-11-26 09:06:12 +0200680static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
Michal Kazior424121c2013-07-22 14:13:31 +0200681{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200682 struct ath10k *ar = arvif->ar;
683 u32 vdev_param;
684
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200685 vdev_param = ar->wmi.vdev_param->rts_threshold;
686 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200687}
688
Kalle Valo5e3dd152013-06-12 20:52:10 +0300689static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
690{
691 int ret;
692
693 lockdep_assert_held(&ar->conf_mutex);
694
695 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
696 if (ret)
697 return ret;
698
699 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
700 if (ret)
701 return ret;
702
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100703 ar->num_peers--;
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100704
Kalle Valo5e3dd152013-06-12 20:52:10 +0300705 return 0;
706}
707
708static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
709{
710 struct ath10k_peer *peer, *tmp;
711
712 lockdep_assert_held(&ar->conf_mutex);
713
714 spin_lock_bh(&ar->data_lock);
715 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
716 if (peer->vdev_id != vdev_id)
717 continue;
718
Michal Kazior7aa7a722014-08-25 12:09:38 +0200719 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300720 peer->addr, vdev_id);
721
722 list_del(&peer->list);
723 kfree(peer);
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100724 ar->num_peers--;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300725 }
726 spin_unlock_bh(&ar->data_lock);
727}
728
Michal Kaziora96d7742013-07-16 09:38:56 +0200729static void ath10k_peer_cleanup_all(struct ath10k *ar)
730{
731 struct ath10k_peer *peer, *tmp;
732
733 lockdep_assert_held(&ar->conf_mutex);
734
735 spin_lock_bh(&ar->data_lock);
736 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
737 list_del(&peer->list);
738 kfree(peer);
739 }
740 spin_unlock_bh(&ar->data_lock);
Michal Kazior292a7532014-11-25 15:16:04 +0100741
742 ar->num_peers = 0;
Michal Kaziorcfd10612014-11-25 15:16:05 +0100743 ar->num_stations = 0;
Michal Kaziora96d7742013-07-16 09:38:56 +0200744}
745
Marek Puzyniak75d85fd2015-03-30 09:51:53 +0300746static int ath10k_mac_tdls_peer_update(struct ath10k *ar, u32 vdev_id,
747 struct ieee80211_sta *sta,
748 enum wmi_tdls_peer_state state)
749{
750 int ret;
751 struct wmi_tdls_peer_update_cmd_arg arg = {};
752 struct wmi_tdls_peer_capab_arg cap = {};
753 struct wmi_channel_arg chan_arg = {};
754
755 lockdep_assert_held(&ar->conf_mutex);
756
757 arg.vdev_id = vdev_id;
758 arg.peer_state = state;
759 ether_addr_copy(arg.addr, sta->addr);
760
761 cap.peer_max_sp = sta->max_sp;
762 cap.peer_uapsd_queues = sta->uapsd_queues;
763
764 if (state == WMI_TDLS_PEER_STATE_CONNECTED &&
765 !sta->tdls_initiator)
766 cap.is_peer_responder = 1;
767
768 ret = ath10k_wmi_tdls_peer_update(ar, &arg, &cap, &chan_arg);
769 if (ret) {
770 ath10k_warn(ar, "failed to update tdls peer %pM on vdev %i: %i\n",
771 arg.addr, vdev_id, ret);
772 return ret;
773 }
774
775 return 0;
776}
777
Kalle Valo5e3dd152013-06-12 20:52:10 +0300778/************************/
779/* Interface management */
780/************************/
781
Michal Kazior64badcb2014-09-18 11:18:02 +0300782void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
783{
784 struct ath10k *ar = arvif->ar;
785
786 lockdep_assert_held(&ar->data_lock);
787
788 if (!arvif->beacon)
789 return;
790
791 if (!arvif->beacon_buf)
792 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
793 arvif->beacon->len, DMA_TO_DEVICE);
794
Michal Kazioraf213192015-01-29 14:29:52 +0200795 if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED &&
796 arvif->beacon_state != ATH10K_BEACON_SENT))
797 return;
798
Michal Kazior64badcb2014-09-18 11:18:02 +0300799 dev_kfree_skb_any(arvif->beacon);
800
801 arvif->beacon = NULL;
Michal Kazioraf213192015-01-29 14:29:52 +0200802 arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
Michal Kazior64badcb2014-09-18 11:18:02 +0300803}
804
805static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
806{
807 struct ath10k *ar = arvif->ar;
808
809 lockdep_assert_held(&ar->data_lock);
810
811 ath10k_mac_vif_beacon_free(arvif);
812
813 if (arvif->beacon_buf) {
814 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
815 arvif->beacon_buf, arvif->beacon_paddr);
816 arvif->beacon_buf = NULL;
817 }
818}
819
Kalle Valo5e3dd152013-06-12 20:52:10 +0300820static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
821{
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +0300822 unsigned long time_left;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300823
Michal Kazior548db542013-07-05 16:15:15 +0300824 lockdep_assert_held(&ar->conf_mutex);
825
Michal Kazior7962b0d2014-10-28 10:34:38 +0100826 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
827 return -ESHUTDOWN;
828
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +0300829 time_left = wait_for_completion_timeout(&ar->vdev_setup_done,
830 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
831 if (time_left == 0)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300832 return -ETIMEDOUT;
833
834 return 0;
835}
836
Michal Kazior1bbc0972014-04-08 09:45:47 +0300837static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300838{
Michal Kazior500ff9f2015-03-31 10:26:21 +0000839 struct cfg80211_chan_def *chandef = NULL;
Maninder Singh19be9e92015-07-16 09:25:33 +0530840 struct ieee80211_channel *channel = NULL;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300841 struct wmi_vdev_start_request_arg arg = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +0300842 int ret = 0;
843
844 lockdep_assert_held(&ar->conf_mutex);
845
Michal Kazior500ff9f2015-03-31 10:26:21 +0000846 ieee80211_iter_chan_contexts_atomic(ar->hw,
847 ath10k_mac_get_any_chandef_iter,
848 &chandef);
849 if (WARN_ON_ONCE(!chandef))
850 return -ENOENT;
851
852 channel = chandef->chan;
853
Kalle Valo5e3dd152013-06-12 20:52:10 +0300854 arg.vdev_id = vdev_id;
855 arg.channel.freq = channel->center_freq;
Michal Kaziorc930f742014-01-23 11:38:25 +0100856 arg.channel.band_center_freq1 = chandef->center_freq1;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300857
858 /* TODO setup this dynamically, what in case we
859 don't have any vifs? */
Michal Kaziorc930f742014-01-23 11:38:25 +0100860 arg.channel.mode = chan_to_phymode(chandef);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200861 arg.channel.chan_radar =
862 !!(channel->flags & IEEE80211_CHAN_RADAR);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300863
Michal Kazior89c5c842013-10-23 04:02:13 -0700864 arg.channel.min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -0700865 arg.channel.max_power = channel->max_power * 2;
866 arg.channel.max_reg_power = channel->max_reg_power * 2;
867 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300868
Michal Kazior7962b0d2014-10-28 10:34:38 +0100869 reinit_completion(&ar->vdev_setup_done);
870
Kalle Valo5e3dd152013-06-12 20:52:10 +0300871 ret = ath10k_wmi_vdev_start(ar, &arg);
872 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200873 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200874 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300875 return ret;
876 }
877
878 ret = ath10k_vdev_setup_sync(ar);
879 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +0200880 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200881 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300882 return ret;
883 }
884
885 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
886 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200887 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200888 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300889 goto vdev_stop;
890 }
891
892 ar->monitor_vdev_id = vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300893
Michal Kazior7aa7a722014-08-25 12:09:38 +0200894 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300895 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300896 return 0;
897
898vdev_stop:
899 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
900 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200901 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200902 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300903
904 return ret;
905}
906
Michal Kazior1bbc0972014-04-08 09:45:47 +0300907static int ath10k_monitor_vdev_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300908{
909 int ret = 0;
910
911 lockdep_assert_held(&ar->conf_mutex);
912
Marek Puzyniak52fa0192013-09-24 14:06:24 +0200913 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
914 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200915 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200916 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300917
Michal Kazior7962b0d2014-10-28 10:34:38 +0100918 reinit_completion(&ar->vdev_setup_done);
919
Kalle Valo5e3dd152013-06-12 20:52:10 +0300920 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
921 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200922 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200923 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300924
925 ret = ath10k_vdev_setup_sync(ar);
926 if (ret)
Ben Greear60028a82015-02-15 16:50:39 +0200927 ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200928 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300929
Michal Kazior7aa7a722014-08-25 12:09:38 +0200930 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300931 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300932 return ret;
933}
934
Michal Kazior1bbc0972014-04-08 09:45:47 +0300935static int ath10k_monitor_vdev_create(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300936{
937 int bit, ret = 0;
938
939 lockdep_assert_held(&ar->conf_mutex);
940
Ben Greeara9aefb32014-08-12 11:02:19 +0300941 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200942 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +0300943 return -ENOMEM;
944 }
945
Ben Greear16c11172014-09-23 14:17:16 -0700946 bit = __ffs64(ar->free_vdev_map);
Ben Greeara9aefb32014-08-12 11:02:19 +0300947
Ben Greear16c11172014-09-23 14:17:16 -0700948 ar->monitor_vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300949
950 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
951 WMI_VDEV_TYPE_MONITOR,
952 0, ar->mac_addr);
953 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200954 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200955 ar->monitor_vdev_id, ret);
Ben Greeara9aefb32014-08-12 11:02:19 +0300956 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300957 }
958
Ben Greear16c11172014-09-23 14:17:16 -0700959 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
Michal Kazior7aa7a722014-08-25 12:09:38 +0200960 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300961 ar->monitor_vdev_id);
962
Kalle Valo5e3dd152013-06-12 20:52:10 +0300963 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300964}
965
Michal Kazior1bbc0972014-04-08 09:45:47 +0300966static int ath10k_monitor_vdev_delete(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300967{
968 int ret = 0;
969
970 lockdep_assert_held(&ar->conf_mutex);
971
Kalle Valo5e3dd152013-06-12 20:52:10 +0300972 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
973 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200974 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200975 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300976 return ret;
977 }
978
Ben Greear16c11172014-09-23 14:17:16 -0700979 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300980
Michal Kazior7aa7a722014-08-25 12:09:38 +0200981 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300982 ar->monitor_vdev_id);
983 return ret;
984}
985
Michal Kazior1bbc0972014-04-08 09:45:47 +0300986static int ath10k_monitor_start(struct ath10k *ar)
987{
988 int ret;
989
990 lockdep_assert_held(&ar->conf_mutex);
991
Michal Kazior1bbc0972014-04-08 09:45:47 +0300992 ret = ath10k_monitor_vdev_create(ar);
993 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200994 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300995 return ret;
996 }
997
998 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
999 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001000 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +03001001 ath10k_monitor_vdev_delete(ar);
1002 return ret;
1003 }
1004
1005 ar->monitor_started = true;
Michal Kazior7aa7a722014-08-25 12:09:38 +02001006 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
Michal Kazior1bbc0972014-04-08 09:45:47 +03001007
1008 return 0;
1009}
1010
Michal Kazior19337472014-08-28 12:58:16 +02001011static int ath10k_monitor_stop(struct ath10k *ar)
Michal Kazior1bbc0972014-04-08 09:45:47 +03001012{
1013 int ret;
1014
1015 lockdep_assert_held(&ar->conf_mutex);
1016
Michal Kazior1bbc0972014-04-08 09:45:47 +03001017 ret = ath10k_monitor_vdev_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +02001018 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001019 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +02001020 return ret;
1021 }
Michal Kazior1bbc0972014-04-08 09:45:47 +03001022
1023 ret = ath10k_monitor_vdev_delete(ar);
Michal Kazior19337472014-08-28 12:58:16 +02001024 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001025 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +02001026 return ret;
1027 }
Michal Kazior1bbc0972014-04-08 09:45:47 +03001028
1029 ar->monitor_started = false;
Michal Kazior7aa7a722014-08-25 12:09:38 +02001030 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
Michal Kazior19337472014-08-28 12:58:16 +02001031
1032 return 0;
1033}
1034
Michal Kazior500ff9f2015-03-31 10:26:21 +00001035static bool ath10k_mac_monitor_vdev_is_needed(struct ath10k *ar)
1036{
1037 int num_ctx;
1038
1039 /* At least one chanctx is required to derive a channel to start
1040 * monitor vdev on.
1041 */
1042 num_ctx = ath10k_mac_num_chanctxs(ar);
1043 if (num_ctx == 0)
1044 return false;
1045
1046 /* If there's already an existing special monitor interface then don't
1047 * bother creating another monitor vdev.
1048 */
1049 if (ar->monitor_arvif)
1050 return false;
1051
1052 return ar->monitor ||
Michal Kazior500ff9f2015-03-31 10:26:21 +00001053 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1054}
1055
1056static bool ath10k_mac_monitor_vdev_is_allowed(struct ath10k *ar)
1057{
1058 int num_ctx;
1059
1060 num_ctx = ath10k_mac_num_chanctxs(ar);
1061
1062 /* FIXME: Current interface combinations and cfg80211/mac80211 code
1063 * shouldn't allow this but make sure to prevent handling the following
1064 * case anyway since multi-channel DFS hasn't been tested at all.
1065 */
1066 if (test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags) && num_ctx > 1)
1067 return false;
1068
1069 return true;
1070}
1071
Michal Kazior19337472014-08-28 12:58:16 +02001072static int ath10k_monitor_recalc(struct ath10k *ar)
1073{
Michal Kazior500ff9f2015-03-31 10:26:21 +00001074 bool needed;
1075 bool allowed;
1076 int ret;
Michal Kazior19337472014-08-28 12:58:16 +02001077
1078 lockdep_assert_held(&ar->conf_mutex);
1079
Michal Kazior500ff9f2015-03-31 10:26:21 +00001080 needed = ath10k_mac_monitor_vdev_is_needed(ar);
1081 allowed = ath10k_mac_monitor_vdev_is_allowed(ar);
Michal Kazior19337472014-08-28 12:58:16 +02001082
1083 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior500ff9f2015-03-31 10:26:21 +00001084 "mac monitor recalc started? %d needed? %d allowed? %d\n",
1085 ar->monitor_started, needed, allowed);
Michal Kazior19337472014-08-28 12:58:16 +02001086
Michal Kazior500ff9f2015-03-31 10:26:21 +00001087 if (WARN_ON(needed && !allowed)) {
1088 if (ar->monitor_started) {
1089 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopping disallowed monitor\n");
1090
1091 ret = ath10k_monitor_stop(ar);
1092 if (ret)
1093 ath10k_warn(ar, "failed to stop disallowed monitor: %d\n", ret);
1094 /* not serious */
1095 }
1096
1097 return -EPERM;
1098 }
1099
1100 if (needed == ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02001101 return 0;
1102
Michal Kazior500ff9f2015-03-31 10:26:21 +00001103 if (needed)
Michal Kazior19337472014-08-28 12:58:16 +02001104 return ath10k_monitor_start(ar);
Michal Kazior500ff9f2015-03-31 10:26:21 +00001105 else
1106 return ath10k_monitor_stop(ar);
Michal Kazior1bbc0972014-04-08 09:45:47 +03001107}
1108
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001109static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
1110{
1111 struct ath10k *ar = arvif->ar;
1112 u32 vdev_param, rts_cts = 0;
1113
1114 lockdep_assert_held(&ar->conf_mutex);
1115
1116 vdev_param = ar->wmi.vdev_param->enable_rtscts;
1117
Rajkumar Manoharan9a5ab0f2015-03-19 16:03:29 +02001118 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001119
1120 if (arvif->num_legacy_stations > 0)
1121 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
1122 WMI_RTSCTS_PROFILE);
Rajkumar Manoharan9a5ab0f2015-03-19 16:03:29 +02001123 else
1124 rts_cts |= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES,
1125 WMI_RTSCTS_PROFILE);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001126
1127 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
1128 rts_cts);
1129}
1130
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001131static int ath10k_start_cac(struct ath10k *ar)
1132{
1133 int ret;
1134
1135 lockdep_assert_held(&ar->conf_mutex);
1136
1137 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1138
Michal Kazior19337472014-08-28 12:58:16 +02001139 ret = ath10k_monitor_recalc(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001140 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001141 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001142 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1143 return ret;
1144 }
1145
Michal Kazior7aa7a722014-08-25 12:09:38 +02001146 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001147 ar->monitor_vdev_id);
1148
1149 return 0;
1150}
1151
1152static int ath10k_stop_cac(struct ath10k *ar)
1153{
1154 lockdep_assert_held(&ar->conf_mutex);
1155
1156 /* CAC is not running - do nothing */
1157 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
1158 return 0;
1159
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001160 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
Michal Kazior1bbc0972014-04-08 09:45:47 +03001161 ath10k_monitor_stop(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001162
Michal Kazior7aa7a722014-08-25 12:09:38 +02001163 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001164
1165 return 0;
1166}
1167
Michal Kazior500ff9f2015-03-31 10:26:21 +00001168static void ath10k_mac_has_radar_iter(struct ieee80211_hw *hw,
1169 struct ieee80211_chanctx_conf *conf,
1170 void *data)
1171{
1172 bool *ret = data;
1173
1174 if (!*ret && conf->radar_enabled)
1175 *ret = true;
1176}
1177
1178static bool ath10k_mac_has_radar_enabled(struct ath10k *ar)
1179{
1180 bool has_radar = false;
1181
1182 ieee80211_iter_chan_contexts_atomic(ar->hw,
1183 ath10k_mac_has_radar_iter,
1184 &has_radar);
1185
1186 return has_radar;
1187}
1188
Michal Kaziord6500972014-04-08 09:56:09 +03001189static void ath10k_recalc_radar_detection(struct ath10k *ar)
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001190{
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001191 int ret;
1192
1193 lockdep_assert_held(&ar->conf_mutex);
1194
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001195 ath10k_stop_cac(ar);
1196
Michal Kazior500ff9f2015-03-31 10:26:21 +00001197 if (!ath10k_mac_has_radar_enabled(ar))
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001198 return;
1199
Michal Kaziord6500972014-04-08 09:56:09 +03001200 if (ar->num_started_vdevs > 0)
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001201 return;
1202
1203 ret = ath10k_start_cac(ar);
1204 if (ret) {
1205 /*
1206 * Not possible to start CAC on current channel so starting
1207 * radiation is not allowed, make this channel DFS_UNAVAILABLE
1208 * by indicating that radar was detected.
1209 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02001210 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001211 ieee80211_radar_detected(ar->hw);
1212 }
1213}
1214
Vasanthakumar Thiagarajan822b7e02015-03-02 17:45:27 +05301215static int ath10k_vdev_stop(struct ath10k_vif *arvif)
Michal Kazior72654fa2014-04-08 09:56:09 +03001216{
1217 struct ath10k *ar = arvif->ar;
Vasanthakumar Thiagarajan822b7e02015-03-02 17:45:27 +05301218 int ret;
1219
1220 lockdep_assert_held(&ar->conf_mutex);
1221
1222 reinit_completion(&ar->vdev_setup_done);
1223
1224 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
1225 if (ret) {
1226 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
1227 arvif->vdev_id, ret);
1228 return ret;
1229 }
1230
1231 ret = ath10k_vdev_setup_sync(ar);
1232 if (ret) {
1233 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
1234 arvif->vdev_id, ret);
1235 return ret;
1236 }
1237
1238 WARN_ON(ar->num_started_vdevs == 0);
1239
1240 if (ar->num_started_vdevs != 0) {
1241 ar->num_started_vdevs--;
1242 ath10k_recalc_radar_detection(ar);
1243 }
1244
1245 return ret;
1246}
1247
Michal Kazior500ff9f2015-03-31 10:26:21 +00001248static int ath10k_vdev_start_restart(struct ath10k_vif *arvif,
1249 const struct cfg80211_chan_def *chandef,
1250 bool restart)
Michal Kazior72654fa2014-04-08 09:56:09 +03001251{
1252 struct ath10k *ar = arvif->ar;
Michal Kazior72654fa2014-04-08 09:56:09 +03001253 struct wmi_vdev_start_request_arg arg = {};
1254 int ret = 0;
1255
1256 lockdep_assert_held(&ar->conf_mutex);
1257
1258 reinit_completion(&ar->vdev_setup_done);
1259
1260 arg.vdev_id = arvif->vdev_id;
1261 arg.dtim_period = arvif->dtim_period;
1262 arg.bcn_intval = arvif->beacon_interval;
1263
1264 arg.channel.freq = chandef->chan->center_freq;
1265 arg.channel.band_center_freq1 = chandef->center_freq1;
1266 arg.channel.mode = chan_to_phymode(chandef);
1267
1268 arg.channel.min_power = 0;
1269 arg.channel.max_power = chandef->chan->max_power * 2;
1270 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
1271 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
1272
1273 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1274 arg.ssid = arvif->u.ap.ssid;
1275 arg.ssid_len = arvif->u.ap.ssid_len;
1276 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
1277
1278 /* For now allow DFS for AP mode */
1279 arg.channel.chan_radar =
1280 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
1281 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
1282 arg.ssid = arvif->vif->bss_conf.ssid;
1283 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
1284 }
1285
Michal Kazior7aa7a722014-08-25 12:09:38 +02001286 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior72654fa2014-04-08 09:56:09 +03001287 "mac vdev %d start center_freq %d phymode %s\n",
1288 arg.vdev_id, arg.channel.freq,
1289 ath10k_wmi_phymode_str(arg.channel.mode));
1290
Michal Kaziordc55e302014-07-29 12:53:36 +03001291 if (restart)
1292 ret = ath10k_wmi_vdev_restart(ar, &arg);
1293 else
1294 ret = ath10k_wmi_vdev_start(ar, &arg);
1295
Michal Kazior72654fa2014-04-08 09:56:09 +03001296 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001297 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +03001298 arg.vdev_id, ret);
1299 return ret;
1300 }
1301
1302 ret = ath10k_vdev_setup_sync(ar);
1303 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +02001304 ath10k_warn(ar,
1305 "failed to synchronize setup for vdev %i restart %d: %d\n",
1306 arg.vdev_id, restart, ret);
Michal Kazior72654fa2014-04-08 09:56:09 +03001307 return ret;
1308 }
1309
Michal Kaziord6500972014-04-08 09:56:09 +03001310 ar->num_started_vdevs++;
1311 ath10k_recalc_radar_detection(ar);
1312
Michal Kazior72654fa2014-04-08 09:56:09 +03001313 return ret;
1314}
1315
Michal Kazior500ff9f2015-03-31 10:26:21 +00001316static int ath10k_vdev_start(struct ath10k_vif *arvif,
1317 const struct cfg80211_chan_def *def)
Michal Kaziordc55e302014-07-29 12:53:36 +03001318{
Michal Kazior500ff9f2015-03-31 10:26:21 +00001319 return ath10k_vdev_start_restart(arvif, def, false);
Michal Kaziordc55e302014-07-29 12:53:36 +03001320}
1321
Michal Kazior500ff9f2015-03-31 10:26:21 +00001322static int ath10k_vdev_restart(struct ath10k_vif *arvif,
1323 const struct cfg80211_chan_def *def)
Michal Kaziordc55e302014-07-29 12:53:36 +03001324{
Michal Kazior500ff9f2015-03-31 10:26:21 +00001325 return ath10k_vdev_start_restart(arvif, def, true);
Michal Kazior72654fa2014-04-08 09:56:09 +03001326}
1327
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001328static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
1329 struct sk_buff *bcn)
1330{
1331 struct ath10k *ar = arvif->ar;
1332 struct ieee80211_mgmt *mgmt;
1333 const u8 *p2p_ie;
1334 int ret;
1335
1336 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1337 return 0;
1338
1339 if (arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1340 return 0;
1341
1342 mgmt = (void *)bcn->data;
1343 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1344 mgmt->u.beacon.variable,
1345 bcn->len - (mgmt->u.beacon.variable -
1346 bcn->data));
1347 if (!p2p_ie)
1348 return -ENOENT;
1349
1350 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1351 if (ret) {
1352 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1353 arvif->vdev_id, ret);
1354 return ret;
1355 }
1356
1357 return 0;
1358}
1359
1360static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1361 u8 oui_type, size_t ie_offset)
1362{
1363 size_t len;
1364 const u8 *next;
1365 const u8 *end;
1366 u8 *ie;
1367
1368 if (WARN_ON(skb->len < ie_offset))
1369 return -EINVAL;
1370
1371 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1372 skb->data + ie_offset,
1373 skb->len - ie_offset);
1374 if (!ie)
1375 return -ENOENT;
1376
1377 len = ie[1] + 2;
1378 end = skb->data + skb->len;
1379 next = ie + len;
1380
1381 if (WARN_ON(next > end))
1382 return -EINVAL;
1383
1384 memmove(ie, next, end - next);
1385 skb_trim(skb, skb->len - len);
1386
1387 return 0;
1388}
1389
1390static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1391{
1392 struct ath10k *ar = arvif->ar;
1393 struct ieee80211_hw *hw = ar->hw;
1394 struct ieee80211_vif *vif = arvif->vif;
1395 struct ieee80211_mutable_offsets offs = {};
1396 struct sk_buff *bcn;
1397 int ret;
1398
1399 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1400 return 0;
1401
Michal Kazior81a9a172015-03-05 16:02:17 +02001402 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
1403 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
1404 return 0;
1405
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001406 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1407 if (!bcn) {
1408 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1409 return -EPERM;
1410 }
1411
1412 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1413 if (ret) {
1414 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1415 kfree_skb(bcn);
1416 return ret;
1417 }
1418
1419 /* P2P IE is inserted by firmware automatically (as configured above)
1420 * so remove it from the base beacon template to avoid duplicate P2P
1421 * IEs in beacon frames.
1422 */
1423 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1424 offsetof(struct ieee80211_mgmt,
1425 u.beacon.variable));
1426
1427 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1428 0, NULL, 0);
1429 kfree_skb(bcn);
1430
1431 if (ret) {
1432 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1433 ret);
1434 return ret;
1435 }
1436
1437 return 0;
1438}
1439
1440static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1441{
1442 struct ath10k *ar = arvif->ar;
1443 struct ieee80211_hw *hw = ar->hw;
1444 struct ieee80211_vif *vif = arvif->vif;
1445 struct sk_buff *prb;
1446 int ret;
1447
1448 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1449 return 0;
1450
Michal Kazior81a9a172015-03-05 16:02:17 +02001451 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1452 return 0;
1453
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001454 prb = ieee80211_proberesp_get(hw, vif);
1455 if (!prb) {
1456 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1457 return -EPERM;
1458 }
1459
1460 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1461 kfree_skb(prb);
1462
1463 if (ret) {
1464 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1465 ret);
1466 return ret;
1467 }
1468
1469 return 0;
1470}
1471
Michal Kazior500ff9f2015-03-31 10:26:21 +00001472static int ath10k_mac_vif_fix_hidden_ssid(struct ath10k_vif *arvif)
1473{
1474 struct ath10k *ar = arvif->ar;
1475 struct cfg80211_chan_def def;
1476 int ret;
1477
1478 /* When originally vdev is started during assign_vif_chanctx() some
1479 * information is missing, notably SSID. Firmware revisions with beacon
1480 * offloading require the SSID to be provided during vdev (re)start to
1481 * handle hidden SSID properly.
1482 *
1483 * Vdev restart must be done after vdev has been both started and
1484 * upped. Otherwise some firmware revisions (at least 10.2) fail to
1485 * deliver vdev restart response event causing timeouts during vdev
1486 * syncing in ath10k.
1487 *
1488 * Note: The vdev down/up and template reinstallation could be skipped
1489 * since only wmi-tlv firmware are known to have beacon offload and
1490 * wmi-tlv doesn't seem to misbehave like 10.2 wrt vdev restart
1491 * response delivery. It's probably more robust to keep it as is.
1492 */
1493 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1494 return 0;
1495
1496 if (WARN_ON(!arvif->is_started))
1497 return -EINVAL;
1498
1499 if (WARN_ON(!arvif->is_up))
1500 return -EINVAL;
1501
1502 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
1503 return -EINVAL;
1504
1505 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1506 if (ret) {
1507 ath10k_warn(ar, "failed to bring down ap vdev %i: %d\n",
1508 arvif->vdev_id, ret);
1509 return ret;
1510 }
1511
1512 /* Vdev down reset beacon & presp templates. Reinstall them. Otherwise
1513 * firmware will crash upon vdev up.
1514 */
1515
1516 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1517 if (ret) {
1518 ath10k_warn(ar, "failed to update beacon template: %d\n", ret);
1519 return ret;
1520 }
1521
1522 ret = ath10k_mac_setup_prb_tmpl(arvif);
1523 if (ret) {
1524 ath10k_warn(ar, "failed to update presp template: %d\n", ret);
1525 return ret;
1526 }
1527
1528 ret = ath10k_vdev_restart(arvif, &def);
1529 if (ret) {
1530 ath10k_warn(ar, "failed to restart ap vdev %i: %d\n",
1531 arvif->vdev_id, ret);
1532 return ret;
1533 }
1534
1535 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1536 arvif->bssid);
1537 if (ret) {
1538 ath10k_warn(ar, "failed to bring up ap vdev %i: %d\n",
1539 arvif->vdev_id, ret);
1540 return ret;
1541 }
1542
1543 return 0;
1544}
1545
Kalle Valo5e3dd152013-06-12 20:52:10 +03001546static void ath10k_control_beaconing(struct ath10k_vif *arvif,
Kalle Valo5b07e072014-09-14 12:50:06 +03001547 struct ieee80211_bss_conf *info)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001548{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001549 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001550 int ret = 0;
1551
Michal Kazior548db542013-07-05 16:15:15 +03001552 lockdep_assert_held(&arvif->ar->conf_mutex);
1553
Kalle Valo5e3dd152013-06-12 20:52:10 +03001554 if (!info->enable_beacon) {
Michal Kazior500ff9f2015-03-31 10:26:21 +00001555 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1556 if (ret)
1557 ath10k_warn(ar, "failed to down vdev_id %i: %d\n",
1558 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001559
Michal Kaziorc930f742014-01-23 11:38:25 +01001560 arvif->is_up = false;
1561
Michal Kazior748afc42014-01-23 12:48:21 +01001562 spin_lock_bh(&arvif->ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03001563 ath10k_mac_vif_beacon_free(arvif);
Michal Kazior748afc42014-01-23 12:48:21 +01001564 spin_unlock_bh(&arvif->ar->data_lock);
1565
Kalle Valo5e3dd152013-06-12 20:52:10 +03001566 return;
1567 }
1568
1569 arvif->tx_seq_no = 0x1000;
1570
Michal Kaziorc930f742014-01-23 11:38:25 +01001571 arvif->aid = 0;
Kalle Valob25f32c2014-09-14 12:50:49 +03001572 ether_addr_copy(arvif->bssid, info->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01001573
1574 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1575 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001576 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001577 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001578 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001579 return;
1580 }
Michal Kaziorc930f742014-01-23 11:38:25 +01001581
Michal Kaziorc930f742014-01-23 11:38:25 +01001582 arvif->is_up = true;
1583
Michal Kazior500ff9f2015-03-31 10:26:21 +00001584 ret = ath10k_mac_vif_fix_hidden_ssid(arvif);
1585 if (ret) {
1586 ath10k_warn(ar, "failed to fix hidden ssid for vdev %i, expect trouble: %d\n",
1587 arvif->vdev_id, ret);
1588 return;
1589 }
1590
Michal Kazior7aa7a722014-08-25 12:09:38 +02001591 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001592}
1593
1594static void ath10k_control_ibss(struct ath10k_vif *arvif,
1595 struct ieee80211_bss_conf *info,
1596 const u8 self_peer[ETH_ALEN])
1597{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001598 struct ath10k *ar = arvif->ar;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001599 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001600 int ret = 0;
1601
Michal Kazior548db542013-07-05 16:15:15 +03001602 lockdep_assert_held(&arvif->ar->conf_mutex);
1603
Kalle Valo5e3dd152013-06-12 20:52:10 +03001604 if (!info->ibss_joined) {
Michal Kaziorc930f742014-01-23 11:38:25 +01001605 if (is_zero_ether_addr(arvif->bssid))
Kalle Valo5e3dd152013-06-12 20:52:10 +03001606 return;
1607
Joe Perches93803b32015-03-02 19:54:49 -08001608 eth_zero_addr(arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001609
1610 return;
1611 }
1612
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001613 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1614 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001615 ATH10K_DEFAULT_ATIM);
1616 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001617 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001618 arvif->vdev_id, ret);
1619}
1620
Michal Kazior9f9b5742014-12-12 12:41:36 +01001621static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1622{
1623 struct ath10k *ar = arvif->ar;
1624 u32 param;
1625 u32 value;
1626 int ret;
1627
1628 lockdep_assert_held(&arvif->ar->conf_mutex);
1629
1630 if (arvif->u.sta.uapsd)
1631 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1632 else
1633 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1634
1635 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1636 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1637 if (ret) {
1638 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1639 value, arvif->vdev_id, ret);
1640 return ret;
1641 }
1642
1643 return 0;
1644}
1645
1646static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1647{
1648 struct ath10k *ar = arvif->ar;
1649 u32 param;
1650 u32 value;
1651 int ret;
1652
1653 lockdep_assert_held(&arvif->ar->conf_mutex);
1654
1655 if (arvif->u.sta.uapsd)
1656 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1657 else
1658 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1659
1660 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1661 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1662 param, value);
1663 if (ret) {
1664 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1665 value, arvif->vdev_id, ret);
1666 return ret;
1667 }
1668
1669 return 0;
1670}
1671
Michal Kazior424f2632015-07-09 13:08:35 +02001672static int ath10k_mac_num_vifs_started(struct ath10k *ar)
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001673{
1674 struct ath10k_vif *arvif;
1675 int num = 0;
1676
1677 lockdep_assert_held(&ar->conf_mutex);
1678
1679 list_for_each_entry(arvif, &ar->arvifs, list)
Michal Kazior424f2632015-07-09 13:08:35 +02001680 if (arvif->is_started)
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001681 num++;
1682
1683 return num;
1684}
1685
Michal Kaziorad088bf2013-10-16 15:44:46 +03001686static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001687{
Michal Kaziorad088bf2013-10-16 15:44:46 +03001688 struct ath10k *ar = arvif->ar;
Michal Kazior526549a2014-12-12 12:41:37 +01001689 struct ieee80211_vif *vif = arvif->vif;
Michal Kaziorad088bf2013-10-16 15:44:46 +03001690 struct ieee80211_conf *conf = &ar->hw->conf;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001691 enum wmi_sta_powersave_param param;
1692 enum wmi_sta_ps_mode psmode;
1693 int ret;
Michal Kazior526549a2014-12-12 12:41:37 +01001694 int ps_timeout;
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001695 bool enable_ps;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001696
Michal Kazior548db542013-07-05 16:15:15 +03001697 lockdep_assert_held(&arvif->ar->conf_mutex);
1698
Michal Kaziorad088bf2013-10-16 15:44:46 +03001699 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1700 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001701
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001702 enable_ps = arvif->ps;
1703
Michal Kazior424f2632015-07-09 13:08:35 +02001704 if (enable_ps && ath10k_mac_num_vifs_started(ar) > 1 &&
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001705 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
1706 ar->fw_features)) {
1707 ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
1708 arvif->vdev_id);
1709 enable_ps = false;
1710 }
1711
Janusz Dziedzic917826b2015-05-18 09:38:17 +00001712 if (!arvif->is_started) {
1713 /* mac80211 can update vif powersave state while disconnected.
1714 * Firmware doesn't behave nicely and consumes more power than
1715 * necessary if PS is disabled on a non-started vdev. Hence
1716 * force-enable PS for non-running vdevs.
1717 */
1718 psmode = WMI_STA_PS_MODE_ENABLED;
1719 } else if (enable_ps) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001720 psmode = WMI_STA_PS_MODE_ENABLED;
1721 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1722
Michal Kazior526549a2014-12-12 12:41:37 +01001723 ps_timeout = conf->dynamic_ps_timeout;
1724 if (ps_timeout == 0) {
1725 /* Firmware doesn't like 0 */
1726 ps_timeout = ieee80211_tu_to_usec(
1727 vif->bss_conf.beacon_int) / 1000;
1728 }
1729
Michal Kaziorad088bf2013-10-16 15:44:46 +03001730 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
Michal Kazior526549a2014-12-12 12:41:37 +01001731 ps_timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001732 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001733 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001734 arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001735 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001736 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001737 } else {
1738 psmode = WMI_STA_PS_MODE_DISABLED;
1739 }
1740
Michal Kazior7aa7a722014-08-25 12:09:38 +02001741 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001742 arvif->vdev_id, psmode ? "enable" : "disable");
1743
Michal Kaziorad088bf2013-10-16 15:44:46 +03001744 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1745 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001746 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001747 psmode, arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001748 return ret;
1749 }
1750
1751 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001752}
1753
Michal Kazior46725b152015-01-28 09:57:49 +02001754static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1755{
1756 struct ath10k *ar = arvif->ar;
1757 struct wmi_sta_keepalive_arg arg = {};
1758 int ret;
1759
1760 lockdep_assert_held(&arvif->ar->conf_mutex);
1761
1762 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1763 return 0;
1764
1765 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1766 return 0;
1767
1768 /* Some firmware revisions have a bug and ignore the `enabled` field.
1769 * Instead use the interval to disable the keepalive.
1770 */
1771 arg.vdev_id = arvif->vdev_id;
1772 arg.enabled = 1;
1773 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1774 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1775
1776 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1777 if (ret) {
1778 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1779 arvif->vdev_id, ret);
1780 return ret;
1781 }
1782
1783 return 0;
1784}
1785
Michal Kazior81a9a172015-03-05 16:02:17 +02001786static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif)
1787{
1788 struct ath10k *ar = arvif->ar;
1789 struct ieee80211_vif *vif = arvif->vif;
1790 int ret;
1791
Michal Kazior8513d952015-03-09 14:19:24 +01001792 lockdep_assert_held(&arvif->ar->conf_mutex);
1793
1794 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)))
1795 return;
1796
Michal Kazior81a9a172015-03-05 16:02:17 +02001797 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1798 return;
1799
1800 if (!vif->csa_active)
1801 return;
1802
1803 if (!arvif->is_up)
1804 return;
1805
1806 if (!ieee80211_csa_is_complete(vif)) {
1807 ieee80211_csa_update_counter(vif);
1808
1809 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1810 if (ret)
1811 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
1812 ret);
1813
1814 ret = ath10k_mac_setup_prb_tmpl(arvif);
1815 if (ret)
1816 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
1817 ret);
1818 } else {
1819 ieee80211_csa_finish(vif);
1820 }
1821}
1822
1823static void ath10k_mac_vif_ap_csa_work(struct work_struct *work)
1824{
1825 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1826 ap_csa_work);
1827 struct ath10k *ar = arvif->ar;
1828
1829 mutex_lock(&ar->conf_mutex);
1830 ath10k_mac_vif_ap_csa_count_down(arvif);
1831 mutex_unlock(&ar->conf_mutex);
1832}
1833
Michal Kaziorcc9904e2015-03-10 16:22:01 +02001834static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac,
1835 struct ieee80211_vif *vif)
1836{
1837 struct sk_buff *skb = data;
1838 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1839 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1840
1841 if (vif->type != NL80211_IFTYPE_STATION)
1842 return;
1843
1844 if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
1845 return;
1846
1847 cancel_delayed_work(&arvif->connection_loss_work);
1848}
1849
1850void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb)
1851{
1852 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1853 IEEE80211_IFACE_ITER_NORMAL,
1854 ath10k_mac_handle_beacon_iter,
1855 skb);
1856}
1857
1858static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac,
1859 struct ieee80211_vif *vif)
1860{
1861 u32 *vdev_id = data;
1862 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1863 struct ath10k *ar = arvif->ar;
1864 struct ieee80211_hw *hw = ar->hw;
1865
1866 if (arvif->vdev_id != *vdev_id)
1867 return;
1868
1869 if (!arvif->is_up)
1870 return;
1871
1872 ieee80211_beacon_loss(vif);
1873
1874 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
1875 * (done by mac80211) succeeds but beacons do not resume then it
1876 * doesn't make sense to continue operation. Queue connection loss work
1877 * which can be cancelled when beacon is received.
1878 */
1879 ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
1880 ATH10K_CONNECTION_LOSS_HZ);
1881}
1882
1883void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id)
1884{
1885 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1886 IEEE80211_IFACE_ITER_NORMAL,
1887 ath10k_mac_handle_beacon_miss_iter,
1888 &vdev_id);
1889}
1890
1891static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work)
1892{
1893 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1894 connection_loss_work.work);
1895 struct ieee80211_vif *vif = arvif->vif;
1896
1897 if (!arvif->is_up)
1898 return;
1899
1900 ieee80211_connection_loss(vif);
1901}
1902
Kalle Valo5e3dd152013-06-12 20:52:10 +03001903/**********************/
1904/* Station management */
1905/**********************/
1906
Michal Kazior590922a2014-10-21 10:10:29 +03001907static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1908 struct ieee80211_vif *vif)
1909{
1910 /* Some firmware revisions have unstable STA powersave when listen
1911 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1912 * generate NullFunc frames properly even if buffered frames have been
1913 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1914 * buffered frames. Often pinging the device from AP would simply fail.
1915 *
1916 * As a workaround set it to 1.
1917 */
1918 if (vif->type == NL80211_IFTYPE_STATION)
1919 return 1;
1920
1921 return ar->hw->conf.listen_interval;
1922}
1923
Kalle Valo5e3dd152013-06-12 20:52:10 +03001924static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001925 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001926 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001927 struct wmi_peer_assoc_complete_arg *arg)
1928{
Michal Kazior590922a2014-10-21 10:10:29 +03001929 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorc51880e2015-03-30 09:51:57 +03001930 u32 aid;
Michal Kazior590922a2014-10-21 10:10:29 +03001931
Michal Kazior548db542013-07-05 16:15:15 +03001932 lockdep_assert_held(&ar->conf_mutex);
1933
Michal Kaziorc51880e2015-03-30 09:51:57 +03001934 if (vif->type == NL80211_IFTYPE_STATION)
1935 aid = vif->bss_conf.aid;
1936 else
1937 aid = sta->aid;
1938
Kalle Valob25f32c2014-09-14 12:50:49 +03001939 ether_addr_copy(arg->addr, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001940 arg->vdev_id = arvif->vdev_id;
Michal Kaziorc51880e2015-03-30 09:51:57 +03001941 arg->peer_aid = aid;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001942 arg->peer_flags |= WMI_PEER_AUTH;
Michal Kazior590922a2014-10-21 10:10:29 +03001943 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001944 arg->peer_num_spatial_streams = 1;
Michal Kazior590922a2014-10-21 10:10:29 +03001945 arg->peer_caps = vif->bss_conf.assoc_capability;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001946}
1947
1948static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001949 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001950 struct wmi_peer_assoc_complete_arg *arg)
1951{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001952 struct ieee80211_bss_conf *info = &vif->bss_conf;
Michal Kazior500ff9f2015-03-31 10:26:21 +00001953 struct cfg80211_chan_def def;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001954 struct cfg80211_bss *bss;
1955 const u8 *rsnie = NULL;
1956 const u8 *wpaie = NULL;
1957
Michal Kazior548db542013-07-05 16:15:15 +03001958 lockdep_assert_held(&ar->conf_mutex);
1959
Michal Kazior500ff9f2015-03-31 10:26:21 +00001960 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
1961 return;
1962
1963 bss = cfg80211_get_bss(ar->hw->wiphy, def.chan, info->bssid, NULL, 0,
1964 IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001965 if (bss) {
1966 const struct cfg80211_bss_ies *ies;
1967
1968 rcu_read_lock();
1969 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1970
1971 ies = rcu_dereference(bss->ies);
1972
1973 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
Kalle Valo5b07e072014-09-14 12:50:06 +03001974 WLAN_OUI_TYPE_MICROSOFT_WPA,
1975 ies->data,
1976 ies->len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001977 rcu_read_unlock();
1978 cfg80211_put_bss(ar->hw->wiphy, bss);
1979 }
1980
1981 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1982 if (rsnie || wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001983 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001984 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1985 }
1986
1987 if (wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001988 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001989 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1990 }
1991}
1992
1993static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
Michal Kazior500ff9f2015-03-31 10:26:21 +00001994 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001995 struct ieee80211_sta *sta,
1996 struct wmi_peer_assoc_complete_arg *arg)
1997{
Michal Kazior45c9abc2015-04-21 20:42:58 +03001998 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001999 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
Michal Kazior500ff9f2015-03-31 10:26:21 +00002000 struct cfg80211_chan_def def;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002001 const struct ieee80211_supported_band *sband;
2002 const struct ieee80211_rate *rates;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002003 enum ieee80211_band band;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002004 u32 ratemask;
Michal Kazior486017c2015-03-30 09:51:54 +03002005 u8 rate;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002006 int i;
2007
Michal Kazior548db542013-07-05 16:15:15 +03002008 lockdep_assert_held(&ar->conf_mutex);
2009
Michal Kazior500ff9f2015-03-31 10:26:21 +00002010 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2011 return;
2012
Michal Kazior45c9abc2015-04-21 20:42:58 +03002013 band = def.chan->band;
2014 sband = ar->hw->wiphy->bands[band];
2015 ratemask = sta->supp_rates[band];
2016 ratemask &= arvif->bitrate_mask.control[band].legacy;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002017 rates = sband->bitrates;
2018
2019 rateset->num_rates = 0;
2020
2021 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
2022 if (!(ratemask & 1))
2023 continue;
2024
Michal Kazior486017c2015-03-30 09:51:54 +03002025 rate = ath10k_mac_bitrate_to_rate(rates->bitrate);
2026 rateset->rates[rateset->num_rates] = rate;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002027 rateset->num_rates++;
2028 }
2029}
2030
Michal Kazior45c9abc2015-04-21 20:42:58 +03002031static bool
2032ath10k_peer_assoc_h_ht_masked(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
2033{
2034 int nss;
2035
2036 for (nss = 0; nss < IEEE80211_HT_MCS_MASK_LEN; nss++)
2037 if (ht_mcs_mask[nss])
2038 return false;
2039
2040 return true;
2041}
2042
2043static bool
2044ath10k_peer_assoc_h_vht_masked(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
2045{
2046 int nss;
2047
2048 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++)
2049 if (vht_mcs_mask[nss])
2050 return false;
2051
2052 return true;
2053}
2054
Kalle Valo5e3dd152013-06-12 20:52:10 +03002055static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
Michal Kazior45c9abc2015-04-21 20:42:58 +03002056 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002057 struct ieee80211_sta *sta,
2058 struct wmi_peer_assoc_complete_arg *arg)
2059{
2060 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002061 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2062 struct cfg80211_chan_def def;
2063 enum ieee80211_band band;
2064 const u8 *ht_mcs_mask;
2065 const u16 *vht_mcs_mask;
2066 int i, n, max_nss;
Kalle Valoaf762c02014-09-14 12:50:17 +03002067 u32 stbc;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002068
Michal Kazior548db542013-07-05 16:15:15 +03002069 lockdep_assert_held(&ar->conf_mutex);
2070
Michal Kazior45c9abc2015-04-21 20:42:58 +03002071 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2072 return;
2073
Kalle Valo5e3dd152013-06-12 20:52:10 +03002074 if (!ht_cap->ht_supported)
2075 return;
2076
Michal Kazior45c9abc2015-04-21 20:42:58 +03002077 band = def.chan->band;
2078 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2079 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2080
2081 if (ath10k_peer_assoc_h_ht_masked(ht_mcs_mask) &&
2082 ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2083 return;
2084
Kalle Valo5e3dd152013-06-12 20:52:10 +03002085 arg->peer_flags |= WMI_PEER_HT;
2086 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2087 ht_cap->ampdu_factor)) - 1;
2088
2089 arg->peer_mpdu_density =
2090 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
2091
2092 arg->peer_ht_caps = ht_cap->cap;
2093 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
2094
2095 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
2096 arg->peer_flags |= WMI_PEER_LDPC;
2097
2098 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
2099 arg->peer_flags |= WMI_PEER_40MHZ;
2100 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
2101 }
2102
Michal Kazior45c9abc2015-04-21 20:42:58 +03002103 if (arvif->bitrate_mask.control[band].gi != NL80211_TXRATE_FORCE_LGI) {
2104 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
2105 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002106
Michal Kazior45c9abc2015-04-21 20:42:58 +03002107 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
2108 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2109 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002110
2111 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
2112 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
2113 arg->peer_flags |= WMI_PEER_STBC;
2114 }
2115
2116 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002117 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
2118 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
2119 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
2120 arg->peer_rate_caps |= stbc;
2121 arg->peer_flags |= WMI_PEER_STBC;
2122 }
2123
Kalle Valo5e3dd152013-06-12 20:52:10 +03002124 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
2125 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
2126 else if (ht_cap->mcs.rx_mask[1])
2127 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
2128
Michal Kazior45c9abc2015-04-21 20:42:58 +03002129 for (i = 0, n = 0, max_nss = 0; i < IEEE80211_HT_MCS_MASK_LEN * 8; i++)
2130 if ((ht_cap->mcs.rx_mask[i / 8] & BIT(i % 8)) &&
2131 (ht_mcs_mask[i / 8] & BIT(i % 8))) {
2132 max_nss = (i / 8) + 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002133 arg->peer_ht_rates.rates[n++] = i;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002134 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002135
Bartosz Markowskifd71f802014-02-10 13:12:55 +01002136 /*
2137 * This is a workaround for HT-enabled STAs which break the spec
2138 * and have no HT capabilities RX mask (no HT RX MCS map).
2139 *
2140 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
2141 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
2142 *
2143 * Firmware asserts if such situation occurs.
2144 */
2145 if (n == 0) {
2146 arg->peer_ht_rates.num_rates = 8;
2147 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
2148 arg->peer_ht_rates.rates[i] = i;
2149 } else {
2150 arg->peer_ht_rates.num_rates = n;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002151 arg->peer_num_spatial_streams = max_nss;
Bartosz Markowskifd71f802014-02-10 13:12:55 +01002152 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002153
Michal Kazior7aa7a722014-08-25 12:09:38 +02002154 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03002155 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002156 arg->peer_ht_rates.num_rates,
2157 arg->peer_num_spatial_streams);
2158}
2159
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002160static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
2161 struct ath10k_vif *arvif,
2162 struct ieee80211_sta *sta)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002163{
2164 u32 uapsd = 0;
2165 u32 max_sp = 0;
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002166 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002167
Michal Kazior548db542013-07-05 16:15:15 +03002168 lockdep_assert_held(&ar->conf_mutex);
2169
Kalle Valo5e3dd152013-06-12 20:52:10 +03002170 if (sta->wme && sta->uapsd_queues) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002171 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002172 sta->uapsd_queues, sta->max_sp);
2173
Kalle Valo5e3dd152013-06-12 20:52:10 +03002174 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2175 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
2176 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
2177 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2178 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
2179 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
2180 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2181 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
2182 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
2183 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2184 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
2185 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
2186
Kalle Valo5e3dd152013-06-12 20:52:10 +03002187 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
2188 max_sp = sta->max_sp;
2189
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002190 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2191 sta->addr,
2192 WMI_AP_PS_PEER_PARAM_UAPSD,
2193 uapsd);
2194 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002195 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002196 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002197 return ret;
2198 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002199
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002200 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2201 sta->addr,
2202 WMI_AP_PS_PEER_PARAM_MAX_SP,
2203 max_sp);
2204 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002205 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002206 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002207 return ret;
2208 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002209
2210 /* TODO setup this based on STA listen interval and
2211 beacon interval. Currently we don't know
2212 sta->listen_interval - mac80211 patch required.
2213 Currently use 10 seconds */
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002214 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
Kalle Valo5b07e072014-09-14 12:50:06 +03002215 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
2216 10);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002217 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002218 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002219 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002220 return ret;
2221 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002222 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002223
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002224 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002225}
2226
Michal Kazior45c9abc2015-04-21 20:42:58 +03002227static u16
2228ath10k_peer_assoc_h_vht_limit(u16 tx_mcs_set,
2229 const u16 vht_mcs_limit[NL80211_VHT_NSS_MAX])
2230{
2231 int idx_limit;
2232 int nss;
2233 u16 mcs_map;
2234 u16 mcs;
2235
2236 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
2237 mcs_map = ath10k_mac_get_max_vht_mcs_map(tx_mcs_set, nss) &
2238 vht_mcs_limit[nss];
2239
2240 if (mcs_map)
2241 idx_limit = fls(mcs_map) - 1;
2242 else
2243 idx_limit = -1;
2244
2245 switch (idx_limit) {
2246 case 0: /* fall through */
2247 case 1: /* fall through */
2248 case 2: /* fall through */
2249 case 3: /* fall through */
2250 case 4: /* fall through */
2251 case 5: /* fall through */
2252 case 6: /* fall through */
2253 default:
2254 /* see ath10k_mac_can_set_bitrate_mask() */
2255 WARN_ON(1);
2256 /* fall through */
2257 case -1:
2258 mcs = IEEE80211_VHT_MCS_NOT_SUPPORTED;
2259 break;
2260 case 7:
2261 mcs = IEEE80211_VHT_MCS_SUPPORT_0_7;
2262 break;
2263 case 8:
2264 mcs = IEEE80211_VHT_MCS_SUPPORT_0_8;
2265 break;
2266 case 9:
2267 mcs = IEEE80211_VHT_MCS_SUPPORT_0_9;
2268 break;
2269 }
2270
2271 tx_mcs_set &= ~(0x3 << (nss * 2));
2272 tx_mcs_set |= mcs << (nss * 2);
2273 }
2274
2275 return tx_mcs_set;
2276}
2277
Kalle Valo5e3dd152013-06-12 20:52:10 +03002278static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
Michal Kazior500ff9f2015-03-31 10:26:21 +00002279 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002280 struct ieee80211_sta *sta,
2281 struct wmi_peer_assoc_complete_arg *arg)
2282{
2283 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002284 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior500ff9f2015-03-31 10:26:21 +00002285 struct cfg80211_chan_def def;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002286 enum ieee80211_band band;
2287 const u16 *vht_mcs_mask;
Sujith Manoharana24b88b2013-10-07 19:51:57 -07002288 u8 ampdu_factor;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002289
Michal Kazior500ff9f2015-03-31 10:26:21 +00002290 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2291 return;
2292
Kalle Valo5e3dd152013-06-12 20:52:10 +03002293 if (!vht_cap->vht_supported)
2294 return;
2295
Michal Kazior45c9abc2015-04-21 20:42:58 +03002296 band = def.chan->band;
2297 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2298
2299 if (ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2300 return;
2301
Kalle Valo5e3dd152013-06-12 20:52:10 +03002302 arg->peer_flags |= WMI_PEER_VHT;
Yanbo Lid68bb122015-01-23 08:18:20 +08002303
Michal Kazior500ff9f2015-03-31 10:26:21 +00002304 if (def.chan->band == IEEE80211_BAND_2GHZ)
Yanbo Lid68bb122015-01-23 08:18:20 +08002305 arg->peer_flags |= WMI_PEER_VHT_2G;
2306
Kalle Valo5e3dd152013-06-12 20:52:10 +03002307 arg->peer_vht_caps = vht_cap->cap;
2308
Sujith Manoharana24b88b2013-10-07 19:51:57 -07002309 ampdu_factor = (vht_cap->cap &
2310 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
2311 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
2312
2313 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
2314 * zero in VHT IE. Using it would result in degraded throughput.
2315 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
2316 * it if VHT max_mpdu is smaller. */
2317 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
2318 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2319 ampdu_factor)) - 1);
2320
Kalle Valo5e3dd152013-06-12 20:52:10 +03002321 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2322 arg->peer_flags |= WMI_PEER_80MHZ;
2323
2324 arg->peer_vht_rates.rx_max_rate =
2325 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
2326 arg->peer_vht_rates.rx_mcs_set =
2327 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
2328 arg->peer_vht_rates.tx_max_rate =
2329 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
Michal Kazior45c9abc2015-04-21 20:42:58 +03002330 arg->peer_vht_rates.tx_mcs_set = ath10k_peer_assoc_h_vht_limit(
2331 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map), vht_mcs_mask);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002332
Michal Kazior7aa7a722014-08-25 12:09:38 +02002333 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03002334 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002335}
2336
2337static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03002338 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002339 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002340 struct wmi_peer_assoc_complete_arg *arg)
2341{
Michal Kazior590922a2014-10-21 10:10:29 +03002342 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2343
Kalle Valo5e3dd152013-06-12 20:52:10 +03002344 switch (arvif->vdev_type) {
2345 case WMI_VDEV_TYPE_AP:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002346 if (sta->wme)
2347 arg->peer_flags |= WMI_PEER_QOS;
2348
2349 if (sta->wme && sta->uapsd_queues) {
2350 arg->peer_flags |= WMI_PEER_APSD;
2351 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
2352 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002353 break;
2354 case WMI_VDEV_TYPE_STA:
Michal Kazior590922a2014-10-21 10:10:29 +03002355 if (vif->bss_conf.qos)
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002356 arg->peer_flags |= WMI_PEER_QOS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002357 break;
Janusz Dziedzic627d9842014-12-17 12:29:54 +02002358 case WMI_VDEV_TYPE_IBSS:
2359 if (sta->wme)
2360 arg->peer_flags |= WMI_PEER_QOS;
2361 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002362 default:
2363 break;
2364 }
Janusz Dziedzic627d9842014-12-17 12:29:54 +02002365
2366 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
2367 sta->addr, !!(arg->peer_flags & WMI_PEER_QOS));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002368}
2369
Michal Kazior8d7aa6b2015-03-30 09:51:57 +03002370static bool ath10k_mac_sta_has_ofdm_only(struct ieee80211_sta *sta)
Michal Kazior91b12082014-12-12 12:41:35 +01002371{
Michal Kazior8d7aa6b2015-03-30 09:51:57 +03002372 return sta->supp_rates[IEEE80211_BAND_2GHZ] >>
2373 ATH10K_MAC_FIRST_OFDM_RATE_IDX;
Michal Kazior91b12082014-12-12 12:41:35 +01002374}
2375
Kalle Valo5e3dd152013-06-12 20:52:10 +03002376static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03002377 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002378 struct ieee80211_sta *sta,
2379 struct wmi_peer_assoc_complete_arg *arg)
2380{
Michal Kazior45c9abc2015-04-21 20:42:58 +03002381 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior500ff9f2015-03-31 10:26:21 +00002382 struct cfg80211_chan_def def;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002383 enum ieee80211_band band;
2384 const u8 *ht_mcs_mask;
2385 const u16 *vht_mcs_mask;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002386 enum wmi_phy_mode phymode = MODE_UNKNOWN;
2387
Michal Kazior500ff9f2015-03-31 10:26:21 +00002388 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2389 return;
2390
Michal Kazior45c9abc2015-04-21 20:42:58 +03002391 band = def.chan->band;
2392 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2393 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2394
2395 switch (band) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002396 case IEEE80211_BAND_2GHZ:
Michal Kazior45c9abc2015-04-21 20:42:58 +03002397 if (sta->vht_cap.vht_supported &&
2398 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
Yanbo Lid68bb122015-01-23 08:18:20 +08002399 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2400 phymode = MODE_11AC_VHT40;
2401 else
2402 phymode = MODE_11AC_VHT20;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002403 } else if (sta->ht_cap.ht_supported &&
2404 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002405 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2406 phymode = MODE_11NG_HT40;
2407 else
2408 phymode = MODE_11NG_HT20;
Michal Kazior8d7aa6b2015-03-30 09:51:57 +03002409 } else if (ath10k_mac_sta_has_ofdm_only(sta)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002410 phymode = MODE_11G;
Michal Kazior91b12082014-12-12 12:41:35 +01002411 } else {
2412 phymode = MODE_11B;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002413 }
2414
2415 break;
2416 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03002417 /*
2418 * Check VHT first.
2419 */
Michal Kazior45c9abc2015-04-21 20:42:58 +03002420 if (sta->vht_cap.vht_supported &&
2421 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03002422 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2423 phymode = MODE_11AC_VHT80;
2424 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2425 phymode = MODE_11AC_VHT40;
2426 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
2427 phymode = MODE_11AC_VHT20;
Michal Kazior45c9abc2015-04-21 20:42:58 +03002428 } else if (sta->ht_cap.ht_supported &&
2429 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2430 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002431 phymode = MODE_11NA_HT40;
2432 else
2433 phymode = MODE_11NA_HT20;
2434 } else {
2435 phymode = MODE_11A;
2436 }
2437
2438 break;
2439 default:
2440 break;
2441 }
2442
Michal Kazior7aa7a722014-08-25 12:09:38 +02002443 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
Kalle Valo38a1d472013-09-08 17:56:14 +03002444 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03002445
Kalle Valo5e3dd152013-06-12 20:52:10 +03002446 arg->peer_phymode = phymode;
2447 WARN_ON(phymode == MODE_UNKNOWN);
2448}
2449
Kalle Valob9ada652013-10-16 15:44:46 +03002450static int ath10k_peer_assoc_prepare(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03002451 struct ieee80211_vif *vif,
Kalle Valob9ada652013-10-16 15:44:46 +03002452 struct ieee80211_sta *sta,
Kalle Valob9ada652013-10-16 15:44:46 +03002453 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002454{
Michal Kazior548db542013-07-05 16:15:15 +03002455 lockdep_assert_held(&ar->conf_mutex);
2456
Kalle Valob9ada652013-10-16 15:44:46 +03002457 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002458
Michal Kazior590922a2014-10-21 10:10:29 +03002459 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
2460 ath10k_peer_assoc_h_crypto(ar, vif, arg);
Michal Kazior500ff9f2015-03-31 10:26:21 +00002461 ath10k_peer_assoc_h_rates(ar, vif, sta, arg);
Michal Kazior45c9abc2015-04-21 20:42:58 +03002462 ath10k_peer_assoc_h_ht(ar, vif, sta, arg);
Michal Kazior500ff9f2015-03-31 10:26:21 +00002463 ath10k_peer_assoc_h_vht(ar, vif, sta, arg);
Michal Kazior590922a2014-10-21 10:10:29 +03002464 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
2465 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002466
Kalle Valob9ada652013-10-16 15:44:46 +03002467 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002468}
2469
Michal Kazior90046f52014-02-14 14:45:51 +01002470static const u32 ath10k_smps_map[] = {
2471 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
2472 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
2473 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
2474 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
2475};
2476
2477static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
2478 const u8 *addr,
2479 const struct ieee80211_sta_ht_cap *ht_cap)
2480{
2481 int smps;
2482
2483 if (!ht_cap->ht_supported)
2484 return 0;
2485
2486 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
2487 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
2488
2489 if (smps >= ARRAY_SIZE(ath10k_smps_map))
2490 return -EINVAL;
2491
2492 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
2493 WMI_PEER_SMPS_STATE,
2494 ath10k_smps_map[smps]);
2495}
2496
Michal Kazior139e1702015-02-15 16:50:42 +02002497static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
2498 struct ieee80211_vif *vif,
2499 struct ieee80211_sta_vht_cap vht_cap)
2500{
2501 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2502 int ret;
2503 u32 param;
2504 u32 value;
2505
Vivek Natarajan08e75ea2015-08-04 10:45:11 +05302506 if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_AFTER_ASSOC)
2507 return 0;
2508
Michal Kazior139e1702015-02-15 16:50:42 +02002509 if (!(ar->vht_cap_info &
2510 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2511 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
2512 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2513 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
2514 return 0;
2515
2516 param = ar->wmi.vdev_param->txbf;
2517 value = 0;
2518
2519 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
2520 return 0;
2521
2522 /* The following logic is correct. If a remote STA advertises support
2523 * for being a beamformer then we should enable us being a beamformee.
2524 */
2525
2526 if (ar->vht_cap_info &
2527 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2528 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
2529 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
2530 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2531
2532 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
2533 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
2534 }
2535
2536 if (ar->vht_cap_info &
2537 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2538 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
2539 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
2540 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2541
2542 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
2543 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
2544 }
2545
2546 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
2547 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2548
2549 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
2550 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2551
2552 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
2553 if (ret) {
2554 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
2555 value, ret);
2556 return ret;
2557 }
2558
2559 return 0;
2560}
2561
Kalle Valo5e3dd152013-06-12 20:52:10 +03002562/* can be called only in mac80211 callbacks due to `key_count` usage */
2563static void ath10k_bss_assoc(struct ieee80211_hw *hw,
2564 struct ieee80211_vif *vif,
2565 struct ieee80211_bss_conf *bss_conf)
2566{
2567 struct ath10k *ar = hw->priv;
2568 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior90046f52014-02-14 14:45:51 +01002569 struct ieee80211_sta_ht_cap ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02002570 struct ieee80211_sta_vht_cap vht_cap;
Kalle Valob9ada652013-10-16 15:44:46 +03002571 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002572 struct ieee80211_sta *ap_sta;
2573 int ret;
2574
Michal Kazior548db542013-07-05 16:15:15 +03002575 lockdep_assert_held(&ar->conf_mutex);
2576
Michal Kazior077efc82014-10-21 10:10:29 +03002577 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
2578 arvif->vdev_id, arvif->bssid, arvif->aid);
2579
Kalle Valo5e3dd152013-06-12 20:52:10 +03002580 rcu_read_lock();
2581
2582 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
2583 if (!ap_sta) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002584 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02002585 bss_conf->bssid, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002586 rcu_read_unlock();
2587 return;
2588 }
2589
Michal Kazior90046f52014-02-14 14:45:51 +01002590 /* ap_sta must be accessed only within rcu section which must be left
2591 * before calling ath10k_setup_peer_smps() which might sleep. */
2592 ht_cap = ap_sta->ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02002593 vht_cap = ap_sta->vht_cap;
Michal Kazior90046f52014-02-14 14:45:51 +01002594
Michal Kazior590922a2014-10-21 10:10:29 +03002595 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002596 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002597 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002598 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002599 rcu_read_unlock();
2600 return;
2601 }
2602
2603 rcu_read_unlock();
2604
Kalle Valob9ada652013-10-16 15:44:46 +03002605 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2606 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002607 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002608 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03002609 return;
2610 }
2611
Michal Kazior90046f52014-02-14 14:45:51 +01002612 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
2613 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002614 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002615 arvif->vdev_id, ret);
Michal Kazior90046f52014-02-14 14:45:51 +01002616 return;
2617 }
2618
Michal Kazior139e1702015-02-15 16:50:42 +02002619 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2620 if (ret) {
2621 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2622 arvif->vdev_id, bss_conf->bssid, ret);
2623 return;
2624 }
2625
Michal Kazior7aa7a722014-08-25 12:09:38 +02002626 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002627 "mac vdev %d up (associated) bssid %pM aid %d\n",
2628 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
2629
Michal Kazior077efc82014-10-21 10:10:29 +03002630 WARN_ON(arvif->is_up);
2631
Michal Kaziorc930f742014-01-23 11:38:25 +01002632 arvif->aid = bss_conf->aid;
Kalle Valob25f32c2014-09-14 12:50:49 +03002633 ether_addr_copy(arvif->bssid, bss_conf->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01002634
2635 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
2636 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002637 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002638 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01002639 return;
2640 }
2641
2642 arvif->is_up = true;
Michal Kazior0a987fb2015-02-13 13:30:15 +01002643
2644 /* Workaround: Some firmware revisions (tested with qca6174
2645 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2646 * poked with peer param command.
2647 */
2648 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
2649 WMI_PEER_DUMMY_VAR, 1);
2650 if (ret) {
2651 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2652 arvif->bssid, arvif->vdev_id, ret);
2653 return;
2654 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002655}
2656
Kalle Valo5e3dd152013-06-12 20:52:10 +03002657static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
2658 struct ieee80211_vif *vif)
2659{
2660 struct ath10k *ar = hw->priv;
2661 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior139e1702015-02-15 16:50:42 +02002662 struct ieee80211_sta_vht_cap vht_cap = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +03002663 int ret;
2664
Michal Kazior548db542013-07-05 16:15:15 +03002665 lockdep_assert_held(&ar->conf_mutex);
2666
Michal Kazior077efc82014-10-21 10:10:29 +03002667 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
2668 arvif->vdev_id, arvif->bssid);
Kalle Valo60c3daa2013-09-08 17:56:07 +03002669
Kalle Valo5e3dd152013-06-12 20:52:10 +03002670 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kazior077efc82014-10-21 10:10:29 +03002671 if (ret)
2672 ath10k_warn(ar, "faield to down vdev %i: %d\n",
2673 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002674
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02002675 arvif->def_wep_key_idx = -1;
2676
Michal Kazior139e1702015-02-15 16:50:42 +02002677 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2678 if (ret) {
2679 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
2680 arvif->vdev_id, ret);
2681 return;
2682 }
2683
Michal Kaziorc930f742014-01-23 11:38:25 +01002684 arvif->is_up = false;
Michal Kaziorcc9904e2015-03-10 16:22:01 +02002685
2686 cancel_delayed_work_sync(&arvif->connection_loss_work);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002687}
2688
Michal Kazior590922a2014-10-21 10:10:29 +03002689static int ath10k_station_assoc(struct ath10k *ar,
2690 struct ieee80211_vif *vif,
2691 struct ieee80211_sta *sta,
2692 bool reassoc)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002693{
Michal Kazior590922a2014-10-21 10:10:29 +03002694 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valob9ada652013-10-16 15:44:46 +03002695 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002696 int ret = 0;
2697
Michal Kazior548db542013-07-05 16:15:15 +03002698 lockdep_assert_held(&ar->conf_mutex);
2699
Michal Kazior590922a2014-10-21 10:10:29 +03002700 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002701 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002702 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02002703 sta->addr, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03002704 return ret;
2705 }
2706
2707 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2708 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002709 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002710 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002711 return ret;
2712 }
2713
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002714 /* Re-assoc is run only to update supported rates for given station. It
2715 * doesn't make much sense to reconfigure the peer completely.
2716 */
2717 if (!reassoc) {
2718 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
2719 &sta->ht_cap);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002720 if (ret) {
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002721 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002722 arvif->vdev_id, ret);
2723 return ret;
2724 }
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002725
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002726 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
2727 if (ret) {
2728 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
2729 sta->addr, arvif->vdev_id, ret);
2730 return ret;
2731 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002732
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002733 if (!sta->wme) {
2734 arvif->num_legacy_stations++;
2735 ret = ath10k_recalc_rtscts_prot(arvif);
2736 if (ret) {
2737 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2738 arvif->vdev_id, ret);
2739 return ret;
2740 }
2741 }
2742
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02002743 /* Plumb cached keys only for static WEP */
2744 if (arvif->def_wep_key_idx != -1) {
2745 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
2746 if (ret) {
2747 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
2748 arvif->vdev_id, ret);
2749 return ret;
2750 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002751 }
2752 }
2753
Kalle Valo5e3dd152013-06-12 20:52:10 +03002754 return ret;
2755}
2756
Michal Kazior590922a2014-10-21 10:10:29 +03002757static int ath10k_station_disassoc(struct ath10k *ar,
2758 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002759 struct ieee80211_sta *sta)
2760{
Michal Kazior590922a2014-10-21 10:10:29 +03002761 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002762 int ret = 0;
2763
2764 lockdep_assert_held(&ar->conf_mutex);
2765
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002766 if (!sta->wme) {
2767 arvif->num_legacy_stations--;
2768 ret = ath10k_recalc_rtscts_prot(arvif);
2769 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002770 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002771 arvif->vdev_id, ret);
2772 return ret;
2773 }
2774 }
2775
Kalle Valo5e3dd152013-06-12 20:52:10 +03002776 ret = ath10k_clear_peer_keys(arvif, sta->addr);
2777 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002778 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002779 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002780 return ret;
2781 }
2782
2783 return ret;
2784}
2785
2786/**************/
2787/* Regulatory */
2788/**************/
2789
2790static int ath10k_update_channel_list(struct ath10k *ar)
2791{
2792 struct ieee80211_hw *hw = ar->hw;
2793 struct ieee80211_supported_band **bands;
2794 enum ieee80211_band band;
2795 struct ieee80211_channel *channel;
2796 struct wmi_scan_chan_list_arg arg = {0};
2797 struct wmi_channel_arg *ch;
2798 bool passive;
2799 int len;
2800 int ret;
2801 int i;
2802
Michal Kazior548db542013-07-05 16:15:15 +03002803 lockdep_assert_held(&ar->conf_mutex);
2804
Kalle Valo5e3dd152013-06-12 20:52:10 +03002805 bands = hw->wiphy->bands;
2806 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2807 if (!bands[band])
2808 continue;
2809
2810 for (i = 0; i < bands[band]->n_channels; i++) {
2811 if (bands[band]->channels[i].flags &
2812 IEEE80211_CHAN_DISABLED)
2813 continue;
2814
2815 arg.n_channels++;
2816 }
2817 }
2818
2819 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
2820 arg.channels = kzalloc(len, GFP_KERNEL);
2821 if (!arg.channels)
2822 return -ENOMEM;
2823
2824 ch = arg.channels;
2825 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2826 if (!bands[band])
2827 continue;
2828
2829 for (i = 0; i < bands[band]->n_channels; i++) {
2830 channel = &bands[band]->channels[i];
2831
2832 if (channel->flags & IEEE80211_CHAN_DISABLED)
2833 continue;
2834
2835 ch->allow_ht = true;
2836
2837 /* FIXME: when should we really allow VHT? */
2838 ch->allow_vht = true;
2839
2840 ch->allow_ibss =
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002841 !(channel->flags & IEEE80211_CHAN_NO_IR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002842
2843 ch->ht40plus =
2844 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
2845
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002846 ch->chan_radar =
2847 !!(channel->flags & IEEE80211_CHAN_RADAR);
2848
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002849 passive = channel->flags & IEEE80211_CHAN_NO_IR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002850 ch->passive = passive;
2851
2852 ch->freq = channel->center_freq;
Michal Kazior2d667212014-09-18 15:21:21 +02002853 ch->band_center_freq1 = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07002854 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07002855 ch->max_power = channel->max_power * 2;
2856 ch->max_reg_power = channel->max_reg_power * 2;
2857 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002858 ch->reg_class_id = 0; /* FIXME */
2859
2860 /* FIXME: why use only legacy modes, why not any
2861 * HT/VHT modes? Would that even make any
2862 * difference? */
2863 if (channel->band == IEEE80211_BAND_2GHZ)
2864 ch->mode = MODE_11G;
2865 else
2866 ch->mode = MODE_11A;
2867
2868 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
2869 continue;
2870
Michal Kazior7aa7a722014-08-25 12:09:38 +02002871 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002872 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
2873 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002874 ch->freq, ch->max_power, ch->max_reg_power,
2875 ch->max_antenna_gain, ch->mode);
2876
2877 ch++;
2878 }
2879 }
2880
2881 ret = ath10k_wmi_scan_chan_list(ar, &arg);
2882 kfree(arg.channels);
2883
2884 return ret;
2885}
2886
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002887static enum wmi_dfs_region
2888ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
2889{
2890 switch (dfs_region) {
2891 case NL80211_DFS_UNSET:
2892 return WMI_UNINIT_DFS_DOMAIN;
2893 case NL80211_DFS_FCC:
2894 return WMI_FCC_DFS_DOMAIN;
2895 case NL80211_DFS_ETSI:
2896 return WMI_ETSI_DFS_DOMAIN;
2897 case NL80211_DFS_JP:
2898 return WMI_MKK4_DFS_DOMAIN;
2899 }
2900 return WMI_UNINIT_DFS_DOMAIN;
2901}
2902
Michal Kaziorf7843d72013-07-16 09:38:52 +02002903static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002904{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002905 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002906 int ret;
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002907 enum wmi_dfs_region wmi_dfs_reg;
2908 enum nl80211_dfs_regions nl_dfs_reg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002909
Michal Kaziorf7843d72013-07-16 09:38:52 +02002910 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002911
2912 ret = ath10k_update_channel_list(ar);
2913 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002914 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002915
2916 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002917
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002918 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
2919 nl_dfs_reg = ar->dfs_detector->region;
2920 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
2921 } else {
2922 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
2923 }
2924
Kalle Valo5e3dd152013-06-12 20:52:10 +03002925 /* Target allows setting up per-band regdomain but ath_common provides
2926 * a combined one only */
2927 ret = ath10k_wmi_pdev_set_regdomain(ar,
Kalle Valoef8c0012014-02-13 18:13:12 +02002928 regpair->reg_domain,
2929 regpair->reg_domain, /* 2ghz */
2930 regpair->reg_domain, /* 5ghz */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002931 regpair->reg_2ghz_ctl,
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002932 regpair->reg_5ghz_ctl,
2933 wmi_dfs_reg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002934 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002935 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02002936}
Michal Kazior548db542013-07-05 16:15:15 +03002937
Michal Kaziorf7843d72013-07-16 09:38:52 +02002938static void ath10k_reg_notifier(struct wiphy *wiphy,
2939 struct regulatory_request *request)
2940{
2941 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
2942 struct ath10k *ar = hw->priv;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002943 bool result;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002944
2945 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
2946
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002947 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002948 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002949 request->dfs_region);
2950 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
2951 request->dfs_region);
2952 if (!result)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002953 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002954 request->dfs_region);
2955 }
2956
Michal Kaziorf7843d72013-07-16 09:38:52 +02002957 mutex_lock(&ar->conf_mutex);
2958 if (ar->state == ATH10K_STATE_ON)
2959 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03002960 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002961}
2962
2963/***************/
2964/* TX handlers */
2965/***************/
2966
Michal Kazior96d828d2015-03-31 10:26:23 +00002967void ath10k_mac_tx_lock(struct ath10k *ar, int reason)
2968{
2969 lockdep_assert_held(&ar->htt.tx_lock);
2970
2971 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
2972 ar->tx_paused |= BIT(reason);
2973 ieee80211_stop_queues(ar->hw);
2974}
2975
2976static void ath10k_mac_tx_unlock_iter(void *data, u8 *mac,
2977 struct ieee80211_vif *vif)
2978{
2979 struct ath10k *ar = data;
2980 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2981
2982 if (arvif->tx_paused)
2983 return;
2984
2985 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
2986}
2987
2988void ath10k_mac_tx_unlock(struct ath10k *ar, int reason)
2989{
2990 lockdep_assert_held(&ar->htt.tx_lock);
2991
2992 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
2993 ar->tx_paused &= ~BIT(reason);
2994
2995 if (ar->tx_paused)
2996 return;
2997
2998 ieee80211_iterate_active_interfaces_atomic(ar->hw,
2999 IEEE80211_IFACE_ITER_RESUME_ALL,
3000 ath10k_mac_tx_unlock_iter,
3001 ar);
Michal Kazior3a73d1a2015-08-06 14:46:54 +02003002
3003 ieee80211_wake_queue(ar->hw, ar->hw->offchannel_tx_hw_queue);
Michal Kazior96d828d2015-03-31 10:26:23 +00003004}
3005
3006void ath10k_mac_vif_tx_lock(struct ath10k_vif *arvif, int reason)
3007{
3008 struct ath10k *ar = arvif->ar;
3009
3010 lockdep_assert_held(&ar->htt.tx_lock);
3011
3012 WARN_ON(reason >= BITS_PER_LONG);
3013 arvif->tx_paused |= BIT(reason);
3014 ieee80211_stop_queue(ar->hw, arvif->vdev_id);
3015}
3016
3017void ath10k_mac_vif_tx_unlock(struct ath10k_vif *arvif, int reason)
3018{
3019 struct ath10k *ar = arvif->ar;
3020
3021 lockdep_assert_held(&ar->htt.tx_lock);
3022
3023 WARN_ON(reason >= BITS_PER_LONG);
3024 arvif->tx_paused &= ~BIT(reason);
3025
3026 if (ar->tx_paused)
3027 return;
3028
3029 if (arvif->tx_paused)
3030 return;
3031
3032 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3033}
3034
Michal Kaziorb4aa5392015-03-31 10:26:24 +00003035static void ath10k_mac_vif_handle_tx_pause(struct ath10k_vif *arvif,
3036 enum wmi_tlv_tx_pause_id pause_id,
3037 enum wmi_tlv_tx_pause_action action)
3038{
3039 struct ath10k *ar = arvif->ar;
3040
3041 lockdep_assert_held(&ar->htt.tx_lock);
3042
Michal Kazioracd0b272015-07-09 13:08:38 +02003043 switch (action) {
3044 case WMI_TLV_TX_PAUSE_ACTION_STOP:
3045 ath10k_mac_vif_tx_lock(arvif, pause_id);
Michal Kaziorb4aa5392015-03-31 10:26:24 +00003046 break;
Michal Kazioracd0b272015-07-09 13:08:38 +02003047 case WMI_TLV_TX_PAUSE_ACTION_WAKE:
3048 ath10k_mac_vif_tx_unlock(arvif, pause_id);
3049 break;
Michal Kaziorb4aa5392015-03-31 10:26:24 +00003050 default:
Michal Kazioracd0b272015-07-09 13:08:38 +02003051 ath10k_warn(ar, "received unknown tx pause action %d on vdev %i, ignoring\n",
3052 action, arvif->vdev_id);
Michal Kaziorb4aa5392015-03-31 10:26:24 +00003053 break;
3054 }
3055}
3056
3057struct ath10k_mac_tx_pause {
3058 u32 vdev_id;
3059 enum wmi_tlv_tx_pause_id pause_id;
3060 enum wmi_tlv_tx_pause_action action;
3061};
3062
3063static void ath10k_mac_handle_tx_pause_iter(void *data, u8 *mac,
3064 struct ieee80211_vif *vif)
3065{
3066 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3067 struct ath10k_mac_tx_pause *arg = data;
3068
Michal Kazioracd0b272015-07-09 13:08:38 +02003069 if (arvif->vdev_id != arg->vdev_id)
3070 return;
3071
Michal Kaziorb4aa5392015-03-31 10:26:24 +00003072 ath10k_mac_vif_handle_tx_pause(arvif, arg->pause_id, arg->action);
3073}
3074
Michal Kazioracd0b272015-07-09 13:08:38 +02003075void ath10k_mac_handle_tx_pause_vdev(struct ath10k *ar, u32 vdev_id,
3076 enum wmi_tlv_tx_pause_id pause_id,
3077 enum wmi_tlv_tx_pause_action action)
Michal Kaziorb4aa5392015-03-31 10:26:24 +00003078{
3079 struct ath10k_mac_tx_pause arg = {
3080 .vdev_id = vdev_id,
3081 .pause_id = pause_id,
3082 .action = action,
3083 };
3084
3085 spin_lock_bh(&ar->htt.tx_lock);
3086 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3087 IEEE80211_IFACE_ITER_RESUME_ALL,
3088 ath10k_mac_handle_tx_pause_iter,
3089 &arg);
3090 spin_unlock_bh(&ar->htt.tx_lock);
3091}
3092
Michal Kazior42c3aa62013-10-02 11:03:38 +02003093static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
3094{
3095 if (ieee80211_is_mgmt(hdr->frame_control))
3096 return HTT_DATA_TX_EXT_TID_MGMT;
3097
3098 if (!ieee80211_is_data_qos(hdr->frame_control))
3099 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
3100
3101 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
3102 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
3103
3104 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
3105}
3106
Michal Kazior2b37c292014-09-02 11:00:22 +03003107static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02003108{
Michal Kazior2b37c292014-09-02 11:00:22 +03003109 if (vif)
3110 return ath10k_vif_to_arvif(vif)->vdev_id;
Michal Kaziorddb6ad72013-10-02 11:03:39 +02003111
Michal Kazior1bbc0972014-04-08 09:45:47 +03003112 if (ar->monitor_started)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02003113 return ar->monitor_vdev_id;
3114
Michal Kazior7aa7a722014-08-25 12:09:38 +02003115 ath10k_warn(ar, "failed to resolve vdev id\n");
Michal Kaziorddb6ad72013-10-02 11:03:39 +02003116 return 0;
3117}
3118
Michal Kaziord740d8f2015-03-30 09:51:51 +03003119static enum ath10k_hw_txrx_mode
3120ath10k_tx_h_get_txmode(struct ath10k *ar, struct ieee80211_vif *vif,
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003121 struct ieee80211_sta *sta, struct sk_buff *skb)
Michal Kaziord740d8f2015-03-30 09:51:51 +03003122{
3123 const struct ieee80211_hdr *hdr = (void *)skb->data;
3124 __le16 fc = hdr->frame_control;
3125
3126 if (!vif || vif->type == NL80211_IFTYPE_MONITOR)
3127 return ATH10K_HW_TXRX_RAW;
3128
3129 if (ieee80211_is_mgmt(fc))
3130 return ATH10K_HW_TXRX_MGMT;
3131
3132 /* Workaround:
3133 *
3134 * NullFunc frames are mostly used to ping if a client or AP are still
3135 * reachable and responsive. This implies tx status reports must be
3136 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
3137 * come to a conclusion that the other end disappeared and tear down
3138 * BSS connection or it can never disconnect from BSS/client (which is
3139 * the case).
3140 *
3141 * Firmware with HTT older than 3.0 delivers incorrect tx status for
3142 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
3143 * which seems to deliver correct tx reports for NullFunc frames. The
3144 * downside of using it is it ignores client powersave state so it can
3145 * end up disconnecting sleeping clients in AP mode. It should fix STA
3146 * mode though because AP don't sleep.
3147 */
3148 if (ar->htt.target_version_major < 3 &&
3149 (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc)) &&
3150 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX, ar->fw_features))
3151 return ATH10K_HW_TXRX_MGMT;
3152
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003153 /* Workaround:
3154 *
3155 * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
3156 * NativeWifi txmode - it selects AP key instead of peer key. It seems
3157 * to work with Ethernet txmode so use it.
David Liuccec9032015-07-24 20:25:32 +03003158 *
3159 * FIXME: Check if raw mode works with TDLS.
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003160 */
3161 if (ieee80211_is_data_present(fc) && sta && sta->tdls)
3162 return ATH10K_HW_TXRX_ETHERNET;
3163
David Liuccec9032015-07-24 20:25:32 +03003164 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
3165 return ATH10K_HW_TXRX_RAW;
3166
Michal Kaziord740d8f2015-03-30 09:51:51 +03003167 return ATH10K_HW_TXRX_NATIVE_WIFI;
3168}
3169
David Liuccec9032015-07-24 20:25:32 +03003170static bool ath10k_tx_h_use_hwcrypto(struct ieee80211_vif *vif,
3171 struct sk_buff *skb) {
3172 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3173 const u32 mask = IEEE80211_TX_INTFL_DONT_ENCRYPT |
3174 IEEE80211_TX_CTL_INJECTED;
3175 if ((info->flags & mask) == mask)
3176 return false;
3177 if (vif)
3178 return !ath10k_vif_to_arvif(vif)->nohwcrypt;
3179 return true;
3180}
3181
Michal Kazior4b604552014-07-21 21:03:09 +03003182/* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
3183 * Control in the header.
Kalle Valo5e3dd152013-06-12 20:52:10 +03003184 */
Michal Kazior4b604552014-07-21 21:03:09 +03003185static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003186{
3187 struct ieee80211_hdr *hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03003188 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003189 u8 *qos_ctl;
3190
3191 if (!ieee80211_is_data_qos(hdr->frame_control))
3192 return;
3193
3194 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02003195 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
3196 skb->data, (void *)qos_ctl - (void *)skb->data);
3197 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Michal Kaziorc21c64d2014-07-21 21:03:10 +03003198
Michal Kazior8bad8dc2015-03-11 14:25:26 +01003199 /* Some firmware revisions don't handle sending QoS NullFunc well.
3200 * These frames are mainly used for CQM purposes so it doesn't really
3201 * matter whether QoS NullFunc or NullFunc are sent.
Michal Kaziorc21c64d2014-07-21 21:03:10 +03003202 */
Michal Kaziorbf0a26d2015-01-24 12:14:51 +02003203 hdr = (void *)skb->data;
Michal Kazior8bad8dc2015-03-11 14:25:26 +01003204 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
Michal Kaziorc21c64d2014-07-21 21:03:10 +03003205 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
Michal Kazior8bad8dc2015-03-11 14:25:26 +01003206
3207 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003208}
3209
Michal Kaziord740d8f2015-03-30 09:51:51 +03003210static void ath10k_tx_h_8023(struct sk_buff *skb)
3211{
3212 struct ieee80211_hdr *hdr;
3213 struct rfc1042_hdr *rfc1042;
3214 struct ethhdr *eth;
3215 size_t hdrlen;
3216 u8 da[ETH_ALEN];
3217 u8 sa[ETH_ALEN];
3218 __be16 type;
3219
3220 hdr = (void *)skb->data;
3221 hdrlen = ieee80211_hdrlen(hdr->frame_control);
3222 rfc1042 = (void *)skb->data + hdrlen;
3223
3224 ether_addr_copy(da, ieee80211_get_DA(hdr));
3225 ether_addr_copy(sa, ieee80211_get_SA(hdr));
3226 type = rfc1042->snap_type;
3227
3228 skb_pull(skb, hdrlen + sizeof(*rfc1042));
3229 skb_push(skb, sizeof(*eth));
3230
3231 eth = (void *)skb->data;
3232 ether_addr_copy(eth->h_dest, da);
3233 ether_addr_copy(eth->h_source, sa);
3234 eth->h_proto = type;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003235}
3236
Michal Kazior4b604552014-07-21 21:03:09 +03003237static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
3238 struct ieee80211_vif *vif,
3239 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003240{
3241 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003242 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3243
3244 /* This is case only for P2P_GO */
3245 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
3246 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
3247 return;
3248
3249 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
3250 spin_lock_bh(&ar->data_lock);
3251 if (arvif->u.ap.noa_data)
3252 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
3253 GFP_ATOMIC))
3254 memcpy(skb_put(skb, arvif->u.ap.noa_len),
3255 arvif->u.ap.noa_data,
3256 arvif->u.ap.noa_len);
3257 spin_unlock_bh(&ar->data_lock);
3258 }
3259}
3260
Michal Kazior8d6d3622014-11-24 14:58:31 +01003261static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar)
3262{
3263 /* FIXME: Not really sure since when the behaviour changed. At some
3264 * point new firmware stopped requiring creation of peer entries for
3265 * offchannel tx (and actually creating them causes issues with wmi-htc
3266 * tx credit replenishment and reliability). Assuming it's at least 3.4
3267 * because that's when the `freq` was introduced to TX_FRM HTT command.
3268 */
3269 return !(ar->htt.target_version_major >= 3 &&
3270 ar->htt.target_version_minor >= 4);
3271}
3272
Michal Kaziord740d8f2015-03-30 09:51:51 +03003273static int ath10k_mac_tx_wmi_mgmt(struct ath10k *ar, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003274{
Michal Kaziord740d8f2015-03-30 09:51:51 +03003275 struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003276 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003277
Michal Kaziord740d8f2015-03-30 09:51:51 +03003278 spin_lock_bh(&ar->data_lock);
3279
3280 if (skb_queue_len(q) == ATH10K_MAX_NUM_MGMT_PENDING) {
3281 ath10k_warn(ar, "wmi mgmt tx queue is full\n");
3282 ret = -ENOSPC;
3283 goto unlock;
Michal Kazior961d4c32013-08-09 10:13:34 +02003284 }
3285
Michal Kaziord740d8f2015-03-30 09:51:51 +03003286 __skb_queue_tail(q, skb);
3287 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
3288
3289unlock:
3290 spin_unlock_bh(&ar->data_lock);
3291
3292 return ret;
3293}
3294
3295static void ath10k_mac_tx(struct ath10k *ar, struct sk_buff *skb)
3296{
3297 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3298 struct ath10k_htt *htt = &ar->htt;
3299 int ret = 0;
3300
3301 switch (cb->txmode) {
3302 case ATH10K_HW_TXRX_RAW:
3303 case ATH10K_HW_TXRX_NATIVE_WIFI:
3304 case ATH10K_HW_TXRX_ETHERNET:
3305 ret = ath10k_htt_tx(htt, skb);
3306 break;
3307 case ATH10K_HW_TXRX_MGMT:
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003308 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
Michal Kaziord740d8f2015-03-30 09:51:51 +03003309 ar->fw_features))
3310 ret = ath10k_mac_tx_wmi_mgmt(ar, skb);
3311 else if (ar->htt.target_version_major >= 3)
3312 ret = ath10k_htt_tx(htt, skb);
3313 else
3314 ret = ath10k_htt_mgmt_tx(htt, skb);
3315 break;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003316 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003317
3318 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003319 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
3320 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003321 ieee80211_free_txskb(ar->hw, skb);
3322 }
3323}
3324
3325void ath10k_offchan_tx_purge(struct ath10k *ar)
3326{
3327 struct sk_buff *skb;
3328
3329 for (;;) {
3330 skb = skb_dequeue(&ar->offchan_tx_queue);
3331 if (!skb)
3332 break;
3333
3334 ieee80211_free_txskb(ar->hw, skb);
3335 }
3336}
3337
3338void ath10k_offchan_tx_work(struct work_struct *work)
3339{
3340 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
3341 struct ath10k_peer *peer;
3342 struct ieee80211_hdr *hdr;
3343 struct sk_buff *skb;
3344 const u8 *peer_addr;
3345 int vdev_id;
3346 int ret;
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +03003347 unsigned long time_left;
Michal Kazioradaeed72015-08-05 12:15:23 +02003348 bool tmp_peer_created = false;
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);
Michal Kazioradaeed72015-08-05 12:15:23 +02003386 tmp_peer_created = (ret == 0);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003387 }
3388
3389 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08003390 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003391 ar->offchan_tx_skb = skb;
3392 spin_unlock_bh(&ar->data_lock);
3393
Michal Kaziord740d8f2015-03-30 09:51:51 +03003394 ath10k_mac_tx(ar, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003395
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +03003396 time_left =
3397 wait_for_completion_timeout(&ar->offchan_tx_completed, 3 * HZ);
3398 if (time_left == 0)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003399 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003400 skb);
3401
Michal Kazioradaeed72015-08-05 12:15:23 +02003402 if (!peer && tmp_peer_created) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03003403 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
3404 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003405 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03003406 peer_addr, vdev_id, ret);
3407 }
3408
3409 mutex_unlock(&ar->conf_mutex);
3410 }
3411}
3412
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003413void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
3414{
3415 struct sk_buff *skb;
3416
3417 for (;;) {
3418 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3419 if (!skb)
3420 break;
3421
3422 ieee80211_free_txskb(ar->hw, skb);
3423 }
3424}
3425
3426void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
3427{
3428 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
3429 struct sk_buff *skb;
3430 int ret;
3431
3432 for (;;) {
3433 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3434 if (!skb)
3435 break;
3436
3437 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01003438 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003439 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02003440 ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01003441 ieee80211_free_txskb(ar->hw, skb);
3442 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003443 }
3444}
3445
Kalle Valo5e3dd152013-06-12 20:52:10 +03003446/************/
3447/* Scanning */
3448/************/
3449
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003450void __ath10k_scan_finish(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003451{
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003452 lockdep_assert_held(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003453
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003454 switch (ar->scan.state) {
3455 case ATH10K_SCAN_IDLE:
3456 break;
3457 case ATH10K_SCAN_RUNNING:
Michal Kazior7305d3e2014-11-24 14:58:33 +01003458 case ATH10K_SCAN_ABORTING:
3459 if (!ar->scan.is_roc)
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003460 ieee80211_scan_completed(ar->hw,
3461 (ar->scan.state ==
3462 ATH10K_SCAN_ABORTING));
Michal Kaziord710e752015-07-09 13:08:36 +02003463 else if (ar->scan.roc_notify)
3464 ieee80211_remain_on_channel_expired(ar->hw);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003465 /* fall through */
3466 case ATH10K_SCAN_STARTING:
3467 ar->scan.state = ATH10K_SCAN_IDLE;
3468 ar->scan_channel = NULL;
3469 ath10k_offchan_tx_purge(ar);
3470 cancel_delayed_work(&ar->scan.timeout);
3471 complete_all(&ar->scan.completed);
3472 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003473 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003474}
Kalle Valo5e3dd152013-06-12 20:52:10 +03003475
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003476void ath10k_scan_finish(struct ath10k *ar)
3477{
3478 spin_lock_bh(&ar->data_lock);
3479 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003480 spin_unlock_bh(&ar->data_lock);
3481}
3482
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003483static int ath10k_scan_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003484{
3485 struct wmi_stop_scan_arg arg = {
3486 .req_id = 1, /* FIXME */
3487 .req_type = WMI_SCAN_STOP_ONE,
3488 .u.scan_id = ATH10K_SCAN_ID,
3489 };
3490 int ret;
3491
3492 lockdep_assert_held(&ar->conf_mutex);
3493
Kalle Valo5e3dd152013-06-12 20:52:10 +03003494 ret = ath10k_wmi_stop_scan(ar, &arg);
3495 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003496 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003497 goto out;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003498 }
3499
Kalle Valo5e3dd152013-06-12 20:52:10 +03003500 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003501 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003502 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003503 ret = -ETIMEDOUT;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003504 } else if (ret > 0) {
3505 ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003506 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003507
3508out:
3509 /* Scan state should be updated upon scan completion but in case
3510 * firmware fails to deliver the event (for whatever reason) it is
3511 * desired to clean up scan state anyway. Firmware may have just
3512 * dropped the scan completion event delivery due to transport pipe
3513 * being overflown with data and/or it can recover on its own before
3514 * next scan request is submitted.
3515 */
3516 spin_lock_bh(&ar->data_lock);
3517 if (ar->scan.state != ATH10K_SCAN_IDLE)
3518 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003519 spin_unlock_bh(&ar->data_lock);
3520
3521 return ret;
3522}
3523
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003524static void ath10k_scan_abort(struct ath10k *ar)
3525{
3526 int ret;
3527
3528 lockdep_assert_held(&ar->conf_mutex);
3529
3530 spin_lock_bh(&ar->data_lock);
3531
3532 switch (ar->scan.state) {
3533 case ATH10K_SCAN_IDLE:
3534 /* This can happen if timeout worker kicked in and called
3535 * abortion while scan completion was being processed.
3536 */
3537 break;
3538 case ATH10K_SCAN_STARTING:
3539 case ATH10K_SCAN_ABORTING:
Michal Kazior7aa7a722014-08-25 12:09:38 +02003540 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003541 ath10k_scan_state_str(ar->scan.state),
3542 ar->scan.state);
3543 break;
3544 case ATH10K_SCAN_RUNNING:
3545 ar->scan.state = ATH10K_SCAN_ABORTING;
3546 spin_unlock_bh(&ar->data_lock);
3547
3548 ret = ath10k_scan_stop(ar);
3549 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003550 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003551
3552 spin_lock_bh(&ar->data_lock);
3553 break;
3554 }
3555
3556 spin_unlock_bh(&ar->data_lock);
3557}
3558
3559void ath10k_scan_timeout_work(struct work_struct *work)
3560{
3561 struct ath10k *ar = container_of(work, struct ath10k,
3562 scan.timeout.work);
3563
3564 mutex_lock(&ar->conf_mutex);
3565 ath10k_scan_abort(ar);
3566 mutex_unlock(&ar->conf_mutex);
3567}
3568
Kalle Valo5e3dd152013-06-12 20:52:10 +03003569static int ath10k_start_scan(struct ath10k *ar,
3570 const struct wmi_start_scan_arg *arg)
3571{
3572 int ret;
3573
3574 lockdep_assert_held(&ar->conf_mutex);
3575
3576 ret = ath10k_wmi_start_scan(ar, arg);
3577 if (ret)
3578 return ret;
3579
Kalle Valo5e3dd152013-06-12 20:52:10 +03003580 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
3581 if (ret == 0) {
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003582 ret = ath10k_scan_stop(ar);
3583 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003584 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003585
3586 return -ETIMEDOUT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003587 }
3588
Ben Greear2f9eec02015-02-15 16:50:38 +02003589 /* If we failed to start the scan, return error code at
3590 * this point. This is probably due to some issue in the
3591 * firmware, but no need to wedge the driver due to that...
3592 */
3593 spin_lock_bh(&ar->data_lock);
3594 if (ar->scan.state == ATH10K_SCAN_IDLE) {
3595 spin_unlock_bh(&ar->data_lock);
3596 return -EINVAL;
3597 }
3598 spin_unlock_bh(&ar->data_lock);
3599
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003600 /* Add a 200ms margin to account for event/command processing */
3601 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
3602 msecs_to_jiffies(arg->max_scan_time+200));
Kalle Valo5e3dd152013-06-12 20:52:10 +03003603 return 0;
3604}
3605
3606/**********************/
3607/* mac80211 callbacks */
3608/**********************/
3609
3610static void ath10k_tx(struct ieee80211_hw *hw,
3611 struct ieee80211_tx_control *control,
3612 struct sk_buff *skb)
3613{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003614 struct ath10k *ar = hw->priv;
Michal Kazior4b604552014-07-21 21:03:09 +03003615 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3616 struct ieee80211_vif *vif = info->control.vif;
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003617 struct ieee80211_sta *sta = control->sta;
Michal Kazior4b604552014-07-21 21:03:09 +03003618 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Michal Kaziord740d8f2015-03-30 09:51:51 +03003619 __le16 fc = hdr->frame_control;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003620
3621 /* We should disable CCK RATE due to P2P */
3622 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003623 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003624
Michal Kazior4b604552014-07-21 21:03:09 +03003625 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
Michal Kazior6fcafef2015-03-30 09:51:51 +03003626 ATH10K_SKB_CB(skb)->htt.freq = 0;
Michal Kazior4b604552014-07-21 21:03:09 +03003627 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
David Liuccec9032015-07-24 20:25:32 +03003628 ATH10K_SKB_CB(skb)->htt.nohwcrypt = !ath10k_tx_h_use_hwcrypto(vif, skb);
Michal Kazior2b37c292014-09-02 11:00:22 +03003629 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003630 ATH10K_SKB_CB(skb)->txmode = ath10k_tx_h_get_txmode(ar, vif, sta, skb);
Michal Kaziord740d8f2015-03-30 09:51:51 +03003631 ATH10K_SKB_CB(skb)->is_protected = ieee80211_has_protected(fc);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003632
Michal Kaziord740d8f2015-03-30 09:51:51 +03003633 switch (ATH10K_SKB_CB(skb)->txmode) {
3634 case ATH10K_HW_TXRX_MGMT:
3635 case ATH10K_HW_TXRX_NATIVE_WIFI:
Michal Kazior4b604552014-07-21 21:03:09 +03003636 ath10k_tx_h_nwifi(hw, skb);
Michal Kazior4b604552014-07-21 21:03:09 +03003637 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
3638 ath10k_tx_h_seq_no(vif, skb);
Michal Kaziord740d8f2015-03-30 09:51:51 +03003639 break;
3640 case ATH10K_HW_TXRX_ETHERNET:
3641 ath10k_tx_h_8023(skb);
3642 break;
3643 case ATH10K_HW_TXRX_RAW:
David Liuccec9032015-07-24 20:25:32 +03003644 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
3645 WARN_ON_ONCE(1);
3646 ieee80211_free_txskb(hw, skb);
3647 return;
3648 }
Michal Kaziorcf84bd42013-07-16 11:04:54 +02003649 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003650
Kalle Valo5e3dd152013-06-12 20:52:10 +03003651 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
3652 spin_lock_bh(&ar->data_lock);
Michal Kazior8d6d3622014-11-24 14:58:31 +01003653 ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003654 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003655 spin_unlock_bh(&ar->data_lock);
3656
Michal Kazior8d6d3622014-11-24 14:58:31 +01003657 if (ath10k_mac_need_offchan_tx_work(ar)) {
3658 ATH10K_SKB_CB(skb)->htt.freq = 0;
3659 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003660
Michal Kazior8d6d3622014-11-24 14:58:31 +01003661 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
3662 skb);
3663
3664 skb_queue_tail(&ar->offchan_tx_queue, skb);
3665 ieee80211_queue_work(hw, &ar->offchan_tx_work);
3666 return;
3667 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003668 }
3669
Michal Kaziord740d8f2015-03-30 09:51:51 +03003670 ath10k_mac_tx(ar, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003671}
3672
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003673/* Must not be called with conf_mutex held as workers can use that also. */
Michal Kazior7962b0d2014-10-28 10:34:38 +01003674void ath10k_drain_tx(struct ath10k *ar)
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003675{
3676 /* make sure rcu-protected mac80211 tx path itself is drained */
3677 synchronize_net();
3678
3679 ath10k_offchan_tx_purge(ar);
3680 ath10k_mgmt_over_wmi_tx_purge(ar);
3681
3682 cancel_work_sync(&ar->offchan_tx_work);
3683 cancel_work_sync(&ar->wmi_mgmt_tx_work);
3684}
3685
Michal Kazioraffd3212013-07-16 09:54:35 +02003686void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02003687{
Michal Kaziord9bc4b92014-04-23 19:30:06 +03003688 struct ath10k_vif *arvif;
3689
Michal Kazior818bdd12013-07-16 09:38:57 +02003690 lockdep_assert_held(&ar->conf_mutex);
3691
Michal Kazior19337472014-08-28 12:58:16 +02003692 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
3693 ar->filter_flags = 0;
3694 ar->monitor = false;
Michal Kazior500ff9f2015-03-31 10:26:21 +00003695 ar->monitor_arvif = NULL;
Michal Kazior19337472014-08-28 12:58:16 +02003696
3697 if (ar->monitor_started)
Michal Kazior1bbc0972014-04-08 09:45:47 +03003698 ath10k_monitor_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +02003699
3700 ar->monitor_started = false;
Michal Kazior96d828d2015-03-31 10:26:23 +00003701 ar->tx_paused = 0;
Michal Kazior1bbc0972014-04-08 09:45:47 +03003702
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003703 ath10k_scan_finish(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02003704 ath10k_peer_cleanup_all(ar);
3705 ath10k_core_stop(ar);
3706 ath10k_hif_power_down(ar);
3707
3708 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03003709 list_for_each_entry(arvif, &ar->arvifs, list)
3710 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kazior818bdd12013-07-16 09:38:57 +02003711 spin_unlock_bh(&ar->data_lock);
3712}
3713
Ben Greear46acf7b2014-05-16 17:15:38 +03003714static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
3715{
3716 struct ath10k *ar = hw->priv;
3717
3718 mutex_lock(&ar->conf_mutex);
3719
3720 if (ar->cfg_tx_chainmask) {
3721 *tx_ant = ar->cfg_tx_chainmask;
3722 *rx_ant = ar->cfg_rx_chainmask;
3723 } else {
3724 *tx_ant = ar->supp_tx_chainmask;
3725 *rx_ant = ar->supp_rx_chainmask;
3726 }
3727
3728 mutex_unlock(&ar->conf_mutex);
3729
3730 return 0;
3731}
3732
Ben Greear5572a952014-11-24 16:22:10 +02003733static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
3734{
3735 /* It is not clear that allowing gaps in chainmask
3736 * is helpful. Probably it will not do what user
3737 * is hoping for, so warn in that case.
3738 */
3739 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
3740 return;
3741
3742 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
3743 dbg, cm);
3744}
3745
Ben Greear46acf7b2014-05-16 17:15:38 +03003746static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
3747{
3748 int ret;
3749
3750 lockdep_assert_held(&ar->conf_mutex);
3751
Ben Greear5572a952014-11-24 16:22:10 +02003752 ath10k_check_chain_mask(ar, tx_ant, "tx");
3753 ath10k_check_chain_mask(ar, rx_ant, "rx");
3754
Ben Greear46acf7b2014-05-16 17:15:38 +03003755 ar->cfg_tx_chainmask = tx_ant;
3756 ar->cfg_rx_chainmask = rx_ant;
3757
3758 if ((ar->state != ATH10K_STATE_ON) &&
3759 (ar->state != ATH10K_STATE_RESTARTED))
3760 return 0;
3761
3762 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
3763 tx_ant);
3764 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003765 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03003766 ret, tx_ant);
3767 return ret;
3768 }
3769
3770 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
3771 rx_ant);
3772 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003773 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03003774 ret, rx_ant);
3775 return ret;
3776 }
3777
3778 return 0;
3779}
3780
3781static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
3782{
3783 struct ath10k *ar = hw->priv;
3784 int ret;
3785
3786 mutex_lock(&ar->conf_mutex);
3787 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
3788 mutex_unlock(&ar->conf_mutex);
3789 return ret;
3790}
3791
Kalle Valo5e3dd152013-06-12 20:52:10 +03003792static int ath10k_start(struct ieee80211_hw *hw)
3793{
3794 struct ath10k *ar = hw->priv;
Janusz Dziedzic24ab13e2015-04-01 22:53:18 +03003795 u32 burst_enable;
Michal Kazior818bdd12013-07-16 09:38:57 +02003796 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003797
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003798 /*
3799 * This makes sense only when restarting hw. It is harmless to call
3800 * uncoditionally. This is necessary to make sure no HTT/WMI tx
3801 * commands will be submitted while restarting.
3802 */
3803 ath10k_drain_tx(ar);
3804
Michal Kazior548db542013-07-05 16:15:15 +03003805 mutex_lock(&ar->conf_mutex);
3806
Michal Kaziorc5058f52014-05-26 12:46:03 +03003807 switch (ar->state) {
3808 case ATH10K_STATE_OFF:
3809 ar->state = ATH10K_STATE_ON;
3810 break;
3811 case ATH10K_STATE_RESTARTING:
3812 ath10k_halt(ar);
3813 ar->state = ATH10K_STATE_RESTARTED;
3814 break;
3815 case ATH10K_STATE_ON:
3816 case ATH10K_STATE_RESTARTED:
3817 case ATH10K_STATE_WEDGED:
3818 WARN_ON(1);
Michal Kazior818bdd12013-07-16 09:38:57 +02003819 ret = -EINVAL;
Michal Kaziorae254432014-05-26 12:46:02 +03003820 goto err;
Kalle Valo43d2a302014-09-10 18:23:30 +03003821 case ATH10K_STATE_UTF:
3822 ret = -EBUSY;
3823 goto err;
Michal Kazior818bdd12013-07-16 09:38:57 +02003824 }
3825
3826 ret = ath10k_hif_power_up(ar);
3827 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003828 ath10k_err(ar, "Could not init hif: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003829 goto err_off;
Michal Kazior818bdd12013-07-16 09:38:57 +02003830 }
3831
Kalle Valo43d2a302014-09-10 18:23:30 +03003832 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
Michal Kazior818bdd12013-07-16 09:38:57 +02003833 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003834 ath10k_err(ar, "Could not init core: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003835 goto err_power_down;
Michal Kazior818bdd12013-07-16 09:38:57 +02003836 }
3837
Bartosz Markowski226a3392013-09-26 17:47:16 +02003838 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03003839 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003840 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003841 goto err_core_stop;
3842 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003843
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01003844 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03003845 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003846 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003847 goto err_core_stop;
3848 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003849
Michal Kaziorcf327842015-03-31 10:26:25 +00003850 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
3851 ret = ath10k_wmi_adaptive_qcs(ar, true);
3852 if (ret) {
3853 ath10k_warn(ar, "failed to enable adaptive qcs: %d\n",
3854 ret);
3855 goto err_core_stop;
3856 }
3857 }
3858
Janusz Dziedzic24ab13e2015-04-01 22:53:18 +03003859 if (test_bit(WMI_SERVICE_BURST, ar->wmi.svc_map)) {
3860 burst_enable = ar->wmi.pdev_param->burst_enable;
3861 ret = ath10k_wmi_pdev_set_param(ar, burst_enable, 0);
3862 if (ret) {
3863 ath10k_warn(ar, "failed to disable burst: %d\n", ret);
3864 goto err_core_stop;
3865 }
3866 }
3867
Ben Greear46acf7b2014-05-16 17:15:38 +03003868 if (ar->cfg_tx_chainmask)
3869 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
3870 ar->cfg_rx_chainmask);
3871
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003872 /*
3873 * By default FW set ARP frames ac to voice (6). In that case ARP
3874 * exchange is not working properly for UAPSD enabled AP. ARP requests
3875 * which arrives with access category 0 are processed by network stack
3876 * and send back with access category 0, but FW changes access category
3877 * to 6. Set ARP frames access category to best effort (0) solves
3878 * this problem.
3879 */
3880
3881 ret = ath10k_wmi_pdev_set_param(ar,
3882 ar->wmi.pdev_param->arp_ac_override, 0);
3883 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003884 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003885 ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003886 goto err_core_stop;
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003887 }
3888
Ashok Raj Nagarajan575f1c32015-03-19 16:37:59 +05303889 ret = ath10k_wmi_pdev_set_param(ar,
3890 ar->wmi.pdev_param->ani_enable, 1);
3891 if (ret) {
3892 ath10k_warn(ar, "failed to enable ani by default: %d\n",
3893 ret);
3894 goto err_core_stop;
3895 }
3896
Ashok Raj Nagarajanb3e71d72015-03-19 16:38:00 +05303897 ar->ani_enabled = true;
3898
Michal Kaziord6500972014-04-08 09:56:09 +03003899 ar->num_started_vdevs = 0;
Michal Kaziorf7843d72013-07-16 09:38:52 +02003900 ath10k_regd_update(ar);
3901
Simon Wunderlich855aed12014-08-02 09:12:54 +03003902 ath10k_spectral_start(ar);
Rajkumar Manoharan8515b5c2015-03-15 20:36:22 +05303903 ath10k_thermal_set_throttling(ar);
Simon Wunderlich855aed12014-08-02 09:12:54 +03003904
Michal Kaziorae254432014-05-26 12:46:02 +03003905 mutex_unlock(&ar->conf_mutex);
3906 return 0;
3907
3908err_core_stop:
3909 ath10k_core_stop(ar);
3910
3911err_power_down:
3912 ath10k_hif_power_down(ar);
3913
3914err_off:
3915 ar->state = ATH10K_STATE_OFF;
3916
3917err:
Michal Kazior548db542013-07-05 16:15:15 +03003918 mutex_unlock(&ar->conf_mutex);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01003919 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003920}
3921
3922static void ath10k_stop(struct ieee80211_hw *hw)
3923{
3924 struct ath10k *ar = hw->priv;
3925
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003926 ath10k_drain_tx(ar);
3927
Michal Kazior548db542013-07-05 16:15:15 +03003928 mutex_lock(&ar->conf_mutex);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003929 if (ar->state != ATH10K_STATE_OFF) {
Michal Kazior818bdd12013-07-16 09:38:57 +02003930 ath10k_halt(ar);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003931 ar->state = ATH10K_STATE_OFF;
3932 }
Michal Kazior548db542013-07-05 16:15:15 +03003933 mutex_unlock(&ar->conf_mutex);
3934
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003935 cancel_delayed_work_sync(&ar->scan.timeout);
Michal Kazioraffd3212013-07-16 09:54:35 +02003936 cancel_work_sync(&ar->restart_work);
3937}
3938
Michal Kaziorad088bf2013-10-16 15:44:46 +03003939static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02003940{
Michal Kaziorad088bf2013-10-16 15:44:46 +03003941 struct ath10k_vif *arvif;
3942 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02003943
3944 lockdep_assert_held(&ar->conf_mutex);
3945
Michal Kaziorad088bf2013-10-16 15:44:46 +03003946 list_for_each_entry(arvif, &ar->arvifs, list) {
3947 ret = ath10k_mac_vif_setup_ps(arvif);
3948 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003949 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03003950 break;
3951 }
3952 }
Michal Kazioraffd3212013-07-16 09:54:35 +02003953
Michal Kaziorad088bf2013-10-16 15:44:46 +03003954 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003955}
3956
Michal Kazior7d9d5582014-10-21 10:40:15 +03003957static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
3958{
3959 int ret;
3960 u32 param;
3961
3962 lockdep_assert_held(&ar->conf_mutex);
3963
3964 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
3965
3966 param = ar->wmi.pdev_param->txpower_limit2g;
3967 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3968 if (ret) {
3969 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
3970 txpower, ret);
3971 return ret;
3972 }
3973
3974 param = ar->wmi.pdev_param->txpower_limit5g;
3975 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3976 if (ret) {
3977 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
3978 txpower, ret);
3979 return ret;
3980 }
3981
3982 return 0;
3983}
3984
3985static int ath10k_mac_txpower_recalc(struct ath10k *ar)
3986{
3987 struct ath10k_vif *arvif;
3988 int ret, txpower = -1;
3989
3990 lockdep_assert_held(&ar->conf_mutex);
3991
3992 list_for_each_entry(arvif, &ar->arvifs, list) {
3993 WARN_ON(arvif->txpower < 0);
3994
3995 if (txpower == -1)
3996 txpower = arvif->txpower;
3997 else
3998 txpower = min(txpower, arvif->txpower);
3999 }
4000
4001 if (WARN_ON(txpower == -1))
4002 return -EINVAL;
4003
4004 ret = ath10k_mac_txpower_setup(ar, txpower);
4005 if (ret) {
4006 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
4007 txpower, ret);
4008 return ret;
4009 }
4010
4011 return 0;
4012}
4013
Kalle Valo5e3dd152013-06-12 20:52:10 +03004014static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
4015{
Kalle Valo5e3dd152013-06-12 20:52:10 +03004016 struct ath10k *ar = hw->priv;
4017 struct ieee80211_conf *conf = &hw->conf;
4018 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004019
4020 mutex_lock(&ar->conf_mutex);
4021
Michal Kazioraffd3212013-07-16 09:54:35 +02004022 if (changed & IEEE80211_CONF_CHANGE_PS)
4023 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004024
4025 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
Michal Kazior19337472014-08-28 12:58:16 +02004026 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
4027 ret = ath10k_monitor_recalc(ar);
4028 if (ret)
4029 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004030 }
4031
4032 mutex_unlock(&ar->conf_mutex);
4033 return ret;
4034}
4035
Ben Greear5572a952014-11-24 16:22:10 +02004036static u32 get_nss_from_chainmask(u16 chain_mask)
4037{
4038 if ((chain_mask & 0x15) == 0x15)
4039 return 4;
4040 else if ((chain_mask & 0x7) == 0x7)
4041 return 3;
4042 else if ((chain_mask & 0x3) == 0x3)
4043 return 2;
4044 return 1;
4045}
4046
Vivek Natarajana48e2cc2015-08-04 10:45:12 +05304047static int ath10k_mac_set_txbf_conf(struct ath10k_vif *arvif)
4048{
4049 u32 value = 0;
4050 struct ath10k *ar = arvif->ar;
4051
4052 if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_BEFORE_ASSOC)
4053 return 0;
4054
4055 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
4056 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE))
4057 value |= SM((ar->num_rf_chains - 1), WMI_TXBF_STS_CAP_OFFSET);
4058
4059 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
4060 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE))
4061 value |= SM((ar->num_rf_chains - 1), WMI_BF_SOUND_DIM_OFFSET);
4062
4063 if (!value)
4064 return 0;
4065
4066 if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
4067 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
4068
4069 if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
4070 value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFER |
4071 WMI_VDEV_PARAM_TXBF_SU_TX_BFER);
4072
4073 if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
4074 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
4075
4076 if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
4077 value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFEE |
4078 WMI_VDEV_PARAM_TXBF_SU_TX_BFEE);
4079
4080 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4081 ar->wmi.vdev_param->txbf, value);
4082}
4083
Kalle Valo5e3dd152013-06-12 20:52:10 +03004084/*
4085 * TODO:
4086 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
4087 * because we will send mgmt frames without CCK. This requirement
4088 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
4089 * in the TX packet.
4090 */
4091static int ath10k_add_interface(struct ieee80211_hw *hw,
4092 struct ieee80211_vif *vif)
4093{
4094 struct ath10k *ar = hw->priv;
4095 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4096 enum wmi_sta_powersave_param param;
4097 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02004098 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004099 int bit;
Michal Kazior96d828d2015-03-31 10:26:23 +00004100 int i;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004101 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004102
Johannes Berg848955c2014-11-11 12:48:42 +01004103 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
4104
Kalle Valo5e3dd152013-06-12 20:52:10 +03004105 mutex_lock(&ar->conf_mutex);
4106
Michal Kazior0dbd09e2013-07-31 10:55:14 +02004107 memset(arvif, 0, sizeof(*arvif));
4108
Kalle Valo5e3dd152013-06-12 20:52:10 +03004109 arvif->ar = ar;
4110 arvif->vif = vif;
4111
Ben Greeare63b33f2013-10-22 14:54:14 -07004112 INIT_LIST_HEAD(&arvif->list);
Michal Kazior81a9a172015-03-05 16:02:17 +02004113 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
Michal Kaziorcc9904e2015-03-10 16:22:01 +02004114 INIT_DELAYED_WORK(&arvif->connection_loss_work,
4115 ath10k_mac_vif_sta_connection_loss_work);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03004116
Michal Kazior45c9abc2015-04-21 20:42:58 +03004117 for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) {
4118 arvif->bitrate_mask.control[i].legacy = 0xffffffff;
4119 memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff,
4120 sizeof(arvif->bitrate_mask.control[i].ht_mcs));
4121 memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff,
4122 sizeof(arvif->bitrate_mask.control[i].vht_mcs));
4123 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004124
Michal Kaziore04cafb2015-08-05 12:15:24 +02004125 if (ar->num_peers >= ar->max_num_peers) {
4126 ath10k_warn(ar, "refusing vdev creation due to insufficient peer entry resources in firmware\n");
4127 return -ENOBUFS;
4128 }
4129
Ben Greeara9aefb32014-08-12 11:02:19 +03004130 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004131 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03004132 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03004133 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004134 }
Ben Greear16c11172014-09-23 14:17:16 -07004135 bit = __ffs64(ar->free_vdev_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004136
Ben Greear16c11172014-09-23 14:17:16 -07004137 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
4138 bit, ar->free_vdev_map);
4139
4140 arvif->vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004141 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004142
Kalle Valo5e3dd152013-06-12 20:52:10 +03004143 switch (vif->type) {
Michal Kazior75d2bd42014-12-12 12:41:39 +01004144 case NL80211_IFTYPE_P2P_DEVICE:
4145 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4146 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
4147 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004148 case NL80211_IFTYPE_UNSPECIFIED:
4149 case NL80211_IFTYPE_STATION:
4150 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4151 if (vif->p2p)
4152 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
4153 break;
4154 case NL80211_IFTYPE_ADHOC:
4155 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
4156 break;
4157 case NL80211_IFTYPE_AP:
4158 arvif->vdev_type = WMI_VDEV_TYPE_AP;
4159
4160 if (vif->p2p)
4161 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
4162 break;
4163 case NL80211_IFTYPE_MONITOR:
4164 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
4165 break;
4166 default:
4167 WARN_ON(1);
4168 break;
4169 }
4170
Michal Kazior96d828d2015-03-31 10:26:23 +00004171 /* Using vdev_id as queue number will make it very easy to do per-vif
4172 * tx queue locking. This shouldn't wrap due to interface combinations
4173 * but do a modulo for correctness sake and prevent using offchannel tx
4174 * queues for regular vif tx.
4175 */
4176 vif->cab_queue = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
4177 for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++)
4178 vif->hw_queue[i] = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
4179
Michal Kazior64badcb2014-09-18 11:18:02 +03004180 /* Some firmware revisions don't wait for beacon tx completion before
4181 * sending another SWBA event. This could lead to hardware using old
4182 * (freed) beacon data in some cases, e.g. tx credit starvation
4183 * combined with missed TBTT. This is very very rare.
4184 *
4185 * On non-IOMMU-enabled hosts this could be a possible security issue
4186 * because hw could beacon some random data on the air. On
4187 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
4188 * device would crash.
4189 *
4190 * Since there are no beacon tx completions (implicit nor explicit)
4191 * propagated to host the only workaround for this is to allocate a
4192 * DMA-coherent buffer for a lifetime of a vif and use it for all
4193 * beacon tx commands. Worst case for this approach is some beacons may
4194 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
4195 */
4196 if (vif->type == NL80211_IFTYPE_ADHOC ||
4197 vif->type == NL80211_IFTYPE_AP) {
4198 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
4199 IEEE80211_MAX_FRAME_LEN,
4200 &arvif->beacon_paddr,
Rajkumar Manoharan82d7aba2014-10-10 17:38:27 +05304201 GFP_ATOMIC);
Michal Kazior64badcb2014-09-18 11:18:02 +03004202 if (!arvif->beacon_buf) {
4203 ret = -ENOMEM;
4204 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
4205 ret);
4206 goto err;
4207 }
4208 }
David Liuccec9032015-07-24 20:25:32 +03004209 if (test_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags))
4210 arvif->nohwcrypt = true;
4211
4212 if (arvif->nohwcrypt &&
4213 !test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
4214 ath10k_warn(ar, "cryptmode module param needed for sw crypto\n");
4215 goto err;
4216 }
Michal Kazior64badcb2014-09-18 11:18:02 +03004217
4218 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
4219 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
4220 arvif->beacon_buf ? "single-buf" : "per-skb");
Kalle Valo5e3dd152013-06-12 20:52:10 +03004221
4222 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
4223 arvif->vdev_subtype, vif->addr);
4224 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004225 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004226 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004227 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004228 }
4229
Ben Greear16c11172014-09-23 14:17:16 -07004230 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03004231 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004232
Michal Kazior46725b152015-01-28 09:57:49 +02004233 /* It makes no sense to have firmware do keepalives. mac80211 already
4234 * takes care of this with idle connection polling.
4235 */
4236 ret = ath10k_mac_vif_disable_keepalive(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004237 if (ret) {
Michal Kazior46725b152015-01-28 09:57:49 +02004238 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004239 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004240 goto err_vdev_delete;
4241 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004242
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004243 arvif->def_wep_key_idx = -1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004244
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004245 vdev_param = ar->wmi.vdev_param->tx_encap_type;
4246 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004247 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02004248 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14a2013-10-16 15:44:45 +03004249 if (ret && ret != -EOPNOTSUPP) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004250 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004251 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004252 goto err_vdev_delete;
4253 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004254
Ben Greear5572a952014-11-24 16:22:10 +02004255 if (ar->cfg_tx_chainmask) {
4256 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
4257
4258 vdev_param = ar->wmi.vdev_param->nss;
4259 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4260 nss);
4261 if (ret) {
4262 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
4263 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
4264 ret);
4265 goto err_vdev_delete;
4266 }
4267 }
4268
Michal Kaziore57e0572015-03-24 13:14:03 +00004269 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4270 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
Marek Puzyniak7390ed32015-03-30 09:51:52 +03004271 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr,
4272 WMI_PEER_TYPE_DEFAULT);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004273 if (ret) {
Michal Kaziore57e0572015-03-24 13:14:03 +00004274 ath10k_warn(ar, "failed to create vdev %i peer for AP/IBSS: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004275 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004276 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004277 }
Michal Kaziore57e0572015-03-24 13:14:03 +00004278 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01004279
Michal Kaziore57e0572015-03-24 13:14:03 +00004280 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
Kalle Valo5a13e762014-01-20 11:01:46 +02004281 ret = ath10k_mac_set_kickout(arvif);
4282 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004283 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004284 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +02004285 goto err_peer_delete;
4286 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004287 }
4288
4289 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
4290 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
4291 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4292 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4293 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004294 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004295 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004296 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004297 goto err_peer_delete;
4298 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004299
Michal Kazior9f9b5742014-12-12 12:41:36 +01004300 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004301 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01004302 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004303 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004304 goto err_peer_delete;
4305 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004306
Michal Kazior9f9b5742014-12-12 12:41:36 +01004307 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004308 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01004309 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004310 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004311 goto err_peer_delete;
4312 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004313 }
4314
Vivek Natarajana48e2cc2015-08-04 10:45:12 +05304315 ret = ath10k_mac_set_txbf_conf(arvif);
4316 if (ret) {
4317 ath10k_warn(ar, "failed to set txbf for vdev %d: %d\n",
4318 arvif->vdev_id, ret);
4319 goto err_peer_delete;
4320 }
4321
Michal Kazior424121c2013-07-22 14:13:31 +02004322 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004323 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004324 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03004325 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004326 goto err_peer_delete;
4327 }
Michal Kazior679c54a2013-07-05 16:15:04 +03004328
Michal Kazior7d9d5582014-10-21 10:40:15 +03004329 arvif->txpower = vif->bss_conf.txpower;
4330 ret = ath10k_mac_txpower_recalc(ar);
4331 if (ret) {
4332 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
4333 goto err_peer_delete;
4334 }
4335
Michal Kazior500ff9f2015-03-31 10:26:21 +00004336 if (vif->type == NL80211_IFTYPE_MONITOR) {
4337 ar->monitor_arvif = arvif;
4338 ret = ath10k_monitor_recalc(ar);
4339 if (ret) {
4340 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4341 goto err_peer_delete;
4342 }
4343 }
4344
Michal Kazior6d2d51e2015-08-07 09:08:21 +02004345 spin_lock_bh(&ar->htt.tx_lock);
4346 if (!ar->tx_paused)
4347 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
4348 spin_unlock_bh(&ar->htt.tx_lock);
4349
Kalle Valo5e3dd152013-06-12 20:52:10 +03004350 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004351 return 0;
4352
4353err_peer_delete:
Michal Kaziore57e0572015-03-24 13:14:03 +00004354 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4355 arvif->vdev_type == WMI_VDEV_TYPE_IBSS)
Michal Kazior9dad14a2013-10-16 15:44:45 +03004356 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
4357
4358err_vdev_delete:
4359 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
Ben Greear16c11172014-09-23 14:17:16 -07004360 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03004361 list_del(&arvif->list);
Michal Kazior9dad14a2013-10-16 15:44:45 +03004362
4363err:
Michal Kazior64badcb2014-09-18 11:18:02 +03004364 if (arvif->beacon_buf) {
4365 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
4366 arvif->beacon_buf, arvif->beacon_paddr);
4367 arvif->beacon_buf = NULL;
4368 }
4369
Michal Kazior9dad14a2013-10-16 15:44:45 +03004370 mutex_unlock(&ar->conf_mutex);
4371
Kalle Valo5e3dd152013-06-12 20:52:10 +03004372 return ret;
4373}
4374
Michal Kaziorb4aa5392015-03-31 10:26:24 +00004375static void ath10k_mac_vif_tx_unlock_all(struct ath10k_vif *arvif)
4376{
4377 int i;
4378
4379 for (i = 0; i < BITS_PER_LONG; i++)
4380 ath10k_mac_vif_tx_unlock(arvif, i);
4381}
4382
Kalle Valo5e3dd152013-06-12 20:52:10 +03004383static void ath10k_remove_interface(struct ieee80211_hw *hw,
4384 struct ieee80211_vif *vif)
4385{
4386 struct ath10k *ar = hw->priv;
4387 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4388 int ret;
4389
Michal Kazior81a9a172015-03-05 16:02:17 +02004390 cancel_work_sync(&arvif->ap_csa_work);
Michal Kaziorcc9904e2015-03-10 16:22:01 +02004391 cancel_delayed_work_sync(&arvif->connection_loss_work);
Michal Kazior81a9a172015-03-05 16:02:17 +02004392
Sujith Manoharan5d011f52014-11-25 11:47:00 +05304393 mutex_lock(&ar->conf_mutex);
4394
Michal Kaziored543882013-09-13 14:16:56 +02004395 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03004396 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kaziored543882013-09-13 14:16:56 +02004397 spin_unlock_bh(&ar->data_lock);
4398
Simon Wunderlich855aed12014-08-02 09:12:54 +03004399 ret = ath10k_spectral_vif_stop(arvif);
4400 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004401 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03004402 arvif->vdev_id, ret);
4403
Ben Greear16c11172014-09-23 14:17:16 -07004404 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03004405 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004406
Michal Kaziore57e0572015-03-24 13:14:03 +00004407 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4408 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
Michal Kazior2c512052015-02-15 16:50:40 +02004409 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
4410 vif->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004411 if (ret)
Michal Kaziore57e0572015-03-24 13:14:03 +00004412 ath10k_warn(ar, "failed to submit AP/IBSS self-peer removal on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004413 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004414
4415 kfree(arvif->u.ap.noa_data);
4416 }
4417
Michal Kazior7aa7a722014-08-25 12:09:38 +02004418 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004419 arvif->vdev_id);
4420
Kalle Valo5e3dd152013-06-12 20:52:10 +03004421 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
4422 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004423 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004424 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004425
Michal Kazior2c512052015-02-15 16:50:40 +02004426 /* Some firmware revisions don't notify host about self-peer removal
4427 * until after associated vdev is deleted.
4428 */
Michal Kaziore57e0572015-03-24 13:14:03 +00004429 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4430 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
Michal Kazior2c512052015-02-15 16:50:40 +02004431 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
4432 vif->addr);
4433 if (ret)
4434 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
4435 arvif->vdev_id, ret);
4436
4437 spin_lock_bh(&ar->data_lock);
4438 ar->num_peers--;
4439 spin_unlock_bh(&ar->data_lock);
4440 }
4441
Kalle Valo5e3dd152013-06-12 20:52:10 +03004442 ath10k_peer_cleanup(ar, arvif->vdev_id);
4443
Michal Kazior500ff9f2015-03-31 10:26:21 +00004444 if (vif->type == NL80211_IFTYPE_MONITOR) {
4445 ar->monitor_arvif = NULL;
4446 ret = ath10k_monitor_recalc(ar);
4447 if (ret)
4448 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4449 }
4450
Michal Kaziorb4aa5392015-03-31 10:26:24 +00004451 spin_lock_bh(&ar->htt.tx_lock);
4452 ath10k_mac_vif_tx_unlock_all(arvif);
4453 spin_unlock_bh(&ar->htt.tx_lock);
4454
Kalle Valo5e3dd152013-06-12 20:52:10 +03004455 mutex_unlock(&ar->conf_mutex);
4456}
4457
4458/*
4459 * FIXME: Has to be verified.
4460 */
4461#define SUPPORTED_FILTERS \
Johannes Bergdf140462015-04-22 14:40:58 +02004462 (FIF_ALLMULTI | \
Kalle Valo5e3dd152013-06-12 20:52:10 +03004463 FIF_CONTROL | \
4464 FIF_PSPOLL | \
4465 FIF_OTHER_BSS | \
4466 FIF_BCN_PRBRESP_PROMISC | \
4467 FIF_PROBE_REQ | \
4468 FIF_FCSFAIL)
4469
4470static void ath10k_configure_filter(struct ieee80211_hw *hw,
4471 unsigned int changed_flags,
4472 unsigned int *total_flags,
4473 u64 multicast)
4474{
4475 struct ath10k *ar = hw->priv;
4476 int ret;
4477
4478 mutex_lock(&ar->conf_mutex);
4479
4480 changed_flags &= SUPPORTED_FILTERS;
4481 *total_flags &= SUPPORTED_FILTERS;
4482 ar->filter_flags = *total_flags;
4483
Michal Kazior19337472014-08-28 12:58:16 +02004484 ret = ath10k_monitor_recalc(ar);
4485 if (ret)
4486 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004487
4488 mutex_unlock(&ar->conf_mutex);
4489}
4490
4491static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
4492 struct ieee80211_vif *vif,
4493 struct ieee80211_bss_conf *info,
4494 u32 changed)
4495{
4496 struct ath10k *ar = hw->priv;
4497 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4498 int ret = 0;
Kalle Valoaf762c02014-09-14 12:50:17 +03004499 u32 vdev_param, pdev_param, slottime, preamble;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004500
4501 mutex_lock(&ar->conf_mutex);
4502
4503 if (changed & BSS_CHANGED_IBSS)
4504 ath10k_control_ibss(arvif, info, vif->addr);
4505
4506 if (changed & BSS_CHANGED_BEACON_INT) {
4507 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004508 vdev_param = ar->wmi.vdev_param->beacon_interval;
4509 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004510 arvif->beacon_interval);
Michal Kazior7aa7a722014-08-25 12:09:38 +02004511 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004512 "mac vdev %d beacon_interval %d\n",
4513 arvif->vdev_id, arvif->beacon_interval);
4514
Kalle Valo5e3dd152013-06-12 20:52:10 +03004515 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004516 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004517 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004518 }
4519
4520 if (changed & BSS_CHANGED_BEACON) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004521 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004522 "vdev %d set beacon tx mode to staggered\n",
4523 arvif->vdev_id);
4524
Bartosz Markowski226a3392013-09-26 17:47:16 +02004525 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
4526 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004527 WMI_BEACON_STAGGERED_MODE);
4528 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004529 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004530 arvif->vdev_id, ret);
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02004531
4532 ret = ath10k_mac_setup_bcn_tmpl(arvif);
4533 if (ret)
4534 ath10k_warn(ar, "failed to update beacon template: %d\n",
4535 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004536 }
4537
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02004538 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
4539 ret = ath10k_mac_setup_prb_tmpl(arvif);
4540 if (ret)
4541 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
4542 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004543 }
4544
Michal Kaziorba2479f2015-01-24 12:14:51 +02004545 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004546 arvif->dtim_period = info->dtim_period;
4547
Michal Kazior7aa7a722014-08-25 12:09:38 +02004548 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004549 "mac vdev %d dtim_period %d\n",
4550 arvif->vdev_id, arvif->dtim_period);
4551
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004552 vdev_param = ar->wmi.vdev_param->dtim_period;
4553 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004554 arvif->dtim_period);
4555 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004556 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004557 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004558 }
4559
4560 if (changed & BSS_CHANGED_SSID &&
4561 vif->type == NL80211_IFTYPE_AP) {
4562 arvif->u.ap.ssid_len = info->ssid_len;
4563 if (info->ssid_len)
4564 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
4565 arvif->u.ap.hidden_ssid = info->hidden_ssid;
4566 }
4567
Michal Kazior077efc82014-10-21 10:10:29 +03004568 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
4569 ether_addr_copy(arvif->bssid, info->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004570
4571 if (changed & BSS_CHANGED_BEACON_ENABLED)
4572 ath10k_control_beaconing(arvif, info);
4573
4574 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02004575 arvif->use_cts_prot = info->use_cts_prot;
Michal Kazior7aa7a722014-08-25 12:09:38 +02004576 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02004577 arvif->vdev_id, info->use_cts_prot);
Kalle Valo60c3daa2013-09-08 17:56:07 +03004578
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02004579 ret = ath10k_recalc_rtscts_prot(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004580 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004581 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004582 arvif->vdev_id, ret);
Michal Kaziora87fd4b2015-03-02 11:21:17 +01004583
4584 vdev_param = ar->wmi.vdev_param->protection_mode;
4585 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4586 info->use_cts_prot ? 1 : 0);
4587 if (ret)
4588 ath10k_warn(ar, "failed to set protection mode %d on vdev %i: %d\n",
4589 info->use_cts_prot, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004590 }
4591
4592 if (changed & BSS_CHANGED_ERP_SLOT) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004593 if (info->use_short_slot)
4594 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
4595
4596 else
4597 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
4598
Michal Kazior7aa7a722014-08-25 12:09:38 +02004599 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004600 arvif->vdev_id, slottime);
4601
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004602 vdev_param = ar->wmi.vdev_param->slot_time;
4603 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004604 slottime);
4605 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004606 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004607 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004608 }
4609
4610 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004611 if (info->use_short_preamble)
4612 preamble = WMI_VDEV_PREAMBLE_SHORT;
4613 else
4614 preamble = WMI_VDEV_PREAMBLE_LONG;
4615
Michal Kazior7aa7a722014-08-25 12:09:38 +02004616 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004617 "mac vdev %d preamble %dn",
4618 arvif->vdev_id, preamble);
4619
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004620 vdev_param = ar->wmi.vdev_param->preamble;
4621 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004622 preamble);
4623 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004624 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004625 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004626 }
4627
4628 if (changed & BSS_CHANGED_ASSOC) {
Michal Kaziore556f112014-08-28 12:58:17 +02004629 if (info->assoc) {
4630 /* Workaround: Make sure monitor vdev is not running
4631 * when associating to prevent some firmware revisions
4632 * (e.g. 10.1 and 10.2) from crashing.
4633 */
4634 if (ar->monitor_started)
4635 ath10k_monitor_stop(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004636 ath10k_bss_assoc(hw, vif, info);
Michal Kaziore556f112014-08-28 12:58:17 +02004637 ath10k_monitor_recalc(ar);
Michal Kazior077efc82014-10-21 10:10:29 +03004638 } else {
4639 ath10k_bss_disassoc(hw, vif);
Michal Kaziore556f112014-08-28 12:58:17 +02004640 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004641 }
4642
Michal Kazior7d9d5582014-10-21 10:40:15 +03004643 if (changed & BSS_CHANGED_TXPOWER) {
4644 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
4645 arvif->vdev_id, info->txpower);
4646
4647 arvif->txpower = info->txpower;
4648 ret = ath10k_mac_txpower_recalc(ar);
4649 if (ret)
4650 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
4651 }
4652
Michal Kaziorbf14e652014-12-12 12:41:38 +01004653 if (changed & BSS_CHANGED_PS) {
Michal Kaziorcffb41f2015-02-13 13:30:16 +01004654 arvif->ps = vif->bss_conf.ps;
4655
4656 ret = ath10k_config_ps(ar);
Michal Kaziorbf14e652014-12-12 12:41:38 +01004657 if (ret)
4658 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
4659 arvif->vdev_id, ret);
4660 }
4661
Kalle Valo5e3dd152013-06-12 20:52:10 +03004662 mutex_unlock(&ar->conf_mutex);
4663}
4664
4665static int ath10k_hw_scan(struct ieee80211_hw *hw,
4666 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02004667 struct ieee80211_scan_request *hw_req)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004668{
4669 struct ath10k *ar = hw->priv;
4670 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
David Spinadelc56ef672014-02-05 15:21:13 +02004671 struct cfg80211_scan_request *req = &hw_req->req;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004672 struct wmi_start_scan_arg arg;
4673 int ret = 0;
4674 int i;
4675
4676 mutex_lock(&ar->conf_mutex);
4677
4678 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004679 switch (ar->scan.state) {
4680 case ATH10K_SCAN_IDLE:
4681 reinit_completion(&ar->scan.started);
4682 reinit_completion(&ar->scan.completed);
4683 ar->scan.state = ATH10K_SCAN_STARTING;
4684 ar->scan.is_roc = false;
4685 ar->scan.vdev_id = arvif->vdev_id;
4686 ret = 0;
4687 break;
4688 case ATH10K_SCAN_STARTING:
4689 case ATH10K_SCAN_RUNNING:
4690 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004691 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004692 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004693 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004694 spin_unlock_bh(&ar->data_lock);
4695
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004696 if (ret)
4697 goto exit;
4698
Kalle Valo5e3dd152013-06-12 20:52:10 +03004699 memset(&arg, 0, sizeof(arg));
4700 ath10k_wmi_start_scan_init(ar, &arg);
4701 arg.vdev_id = arvif->vdev_id;
4702 arg.scan_id = ATH10K_SCAN_ID;
4703
Kalle Valo5e3dd152013-06-12 20:52:10 +03004704 if (req->ie_len) {
4705 arg.ie_len = req->ie_len;
4706 memcpy(arg.ie, req->ie, arg.ie_len);
4707 }
4708
4709 if (req->n_ssids) {
4710 arg.n_ssids = req->n_ssids;
4711 for (i = 0; i < arg.n_ssids; i++) {
4712 arg.ssids[i].len = req->ssids[i].ssid_len;
4713 arg.ssids[i].ssid = req->ssids[i].ssid;
4714 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02004715 } else {
4716 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004717 }
4718
4719 if (req->n_channels) {
4720 arg.n_channels = req->n_channels;
4721 for (i = 0; i < arg.n_channels; i++)
4722 arg.channels[i] = req->channels[i]->center_freq;
4723 }
4724
4725 ret = ath10k_start_scan(ar, &arg);
4726 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004727 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004728 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004729 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004730 spin_unlock_bh(&ar->data_lock);
4731 }
4732
4733exit:
4734 mutex_unlock(&ar->conf_mutex);
4735 return ret;
4736}
4737
4738static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
4739 struct ieee80211_vif *vif)
4740{
4741 struct ath10k *ar = hw->priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004742
4743 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004744 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004745 mutex_unlock(&ar->conf_mutex);
Michal Kazior4eb2e162014-10-28 10:23:09 +01004746
4747 cancel_delayed_work_sync(&ar->scan.timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004748}
4749
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004750static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
4751 struct ath10k_vif *arvif,
4752 enum set_key_cmd cmd,
4753 struct ieee80211_key_conf *key)
4754{
4755 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
4756 int ret;
4757
4758 /* 10.1 firmware branch requires default key index to be set to group
4759 * key index after installing it. Otherwise FW/HW Txes corrupted
4760 * frames with multi-vif APs. This is not required for main firmware
4761 * branch (e.g. 636).
4762 *
Michal Kazior8461baf2015-04-10 13:23:22 +00004763 * This is also needed for 636 fw for IBSS-RSN to work more reliably.
4764 *
4765 * FIXME: It remains unknown if this is required for multi-vif STA
4766 * interfaces on 10.1.
4767 */
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004768
Michal Kazior8461baf2015-04-10 13:23:22 +00004769 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
4770 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004771 return;
4772
4773 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
4774 return;
4775
4776 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
4777 return;
4778
4779 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4780 return;
4781
4782 if (cmd != SET_KEY)
4783 return;
4784
4785 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4786 key->keyidx);
4787 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004788 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004789 arvif->vdev_id, ret);
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004790}
4791
Kalle Valo5e3dd152013-06-12 20:52:10 +03004792static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
4793 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
4794 struct ieee80211_key_conf *key)
4795{
4796 struct ath10k *ar = hw->priv;
4797 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4798 struct ath10k_peer *peer;
4799 const u8 *peer_addr;
4800 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
4801 key->cipher == WLAN_CIPHER_SUITE_WEP104;
4802 int ret = 0;
Michal Kazior29a10002015-04-10 13:05:58 +00004803 int ret2;
Michal Kazior370e5672015-02-18 14:02:26 +01004804 u32 flags = 0;
Michal Kazior29a10002015-04-10 13:05:58 +00004805 u32 flags2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004806
Bartosz Markowskid7131c02015-03-10 14:32:19 +01004807 /* this one needs to be done in software */
4808 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
4809 return 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004810
David Liuccec9032015-07-24 20:25:32 +03004811 if (arvif->nohwcrypt)
4812 return 1;
4813
Kalle Valo5e3dd152013-06-12 20:52:10 +03004814 if (key->keyidx > WMI_MAX_KEY_INDEX)
4815 return -ENOSPC;
4816
4817 mutex_lock(&ar->conf_mutex);
4818
4819 if (sta)
4820 peer_addr = sta->addr;
4821 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
4822 peer_addr = vif->bss_conf.bssid;
4823 else
4824 peer_addr = vif->addr;
4825
4826 key->hw_key_idx = key->keyidx;
4827
Michal Kazior7c8cc7e2015-04-01 22:53:19 +03004828 if (is_wep) {
4829 if (cmd == SET_KEY)
4830 arvif->wep_keys[key->keyidx] = key;
4831 else
4832 arvif->wep_keys[key->keyidx] = NULL;
4833 }
4834
Kalle Valo5e3dd152013-06-12 20:52:10 +03004835 /* the peer should not disappear in mid-way (unless FW goes awry) since
4836 * we already hold conf_mutex. we just make sure its there now. */
4837 spin_lock_bh(&ar->data_lock);
4838 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4839 spin_unlock_bh(&ar->data_lock);
4840
4841 if (!peer) {
4842 if (cmd == SET_KEY) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004843 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03004844 peer_addr);
4845 ret = -EOPNOTSUPP;
4846 goto exit;
4847 } else {
4848 /* if the peer doesn't exist there is no key to disable
4849 * anymore */
4850 goto exit;
4851 }
4852 }
4853
Michal Kazior7cc45732015-03-09 14:24:17 +01004854 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4855 flags |= WMI_KEY_PAIRWISE;
4856 else
4857 flags |= WMI_KEY_GROUP;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004858
Kalle Valo5e3dd152013-06-12 20:52:10 +03004859 if (is_wep) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004860 if (cmd == DISABLE_KEY)
4861 ath10k_clear_vdev_key(arvif, key);
Michal Kazior370e5672015-02-18 14:02:26 +01004862
Michal Kaziorad325cb2015-02-18 14:02:27 +01004863 /* When WEP keys are uploaded it's possible that there are
4864 * stations associated already (e.g. when merging) without any
4865 * keys. Static WEP needs an explicit per-peer key upload.
4866 */
4867 if (vif->type == NL80211_IFTYPE_ADHOC &&
4868 cmd == SET_KEY)
4869 ath10k_mac_vif_update_wep_key(arvif, key);
4870
Michal Kazior370e5672015-02-18 14:02:26 +01004871 /* 802.1x never sets the def_wep_key_idx so each set_key()
4872 * call changes default tx key.
4873 *
4874 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
4875 * after first set_key().
4876 */
4877 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
4878 flags |= WMI_KEY_TX_USAGE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004879 }
4880
Michal Kazior370e5672015-02-18 14:02:26 +01004881 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004882 if (ret) {
David Liuccec9032015-07-24 20:25:32 +03004883 WARN_ON(ret > 0);
Michal Kazior7aa7a722014-08-25 12:09:38 +02004884 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004885 arvif->vdev_id, peer_addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004886 goto exit;
4887 }
4888
Michal Kazior29a10002015-04-10 13:05:58 +00004889 /* mac80211 sets static WEP keys as groupwise while firmware requires
4890 * them to be installed twice as both pairwise and groupwise.
4891 */
4892 if (is_wep && !sta && vif->type == NL80211_IFTYPE_STATION) {
4893 flags2 = flags;
4894 flags2 &= ~WMI_KEY_GROUP;
4895 flags2 |= WMI_KEY_PAIRWISE;
4896
4897 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags2);
4898 if (ret) {
David Liuccec9032015-07-24 20:25:32 +03004899 WARN_ON(ret > 0);
Michal Kazior29a10002015-04-10 13:05:58 +00004900 ath10k_warn(ar, "failed to install (ucast) key for vdev %i peer %pM: %d\n",
4901 arvif->vdev_id, peer_addr, ret);
4902 ret2 = ath10k_install_key(arvif, key, DISABLE_KEY,
4903 peer_addr, flags);
David Liuccec9032015-07-24 20:25:32 +03004904 if (ret2) {
4905 WARN_ON(ret2 > 0);
Michal Kazior29a10002015-04-10 13:05:58 +00004906 ath10k_warn(ar, "failed to disable (mcast) key for vdev %i peer %pM: %d\n",
4907 arvif->vdev_id, peer_addr, ret2);
David Liuccec9032015-07-24 20:25:32 +03004908 }
Michal Kazior29a10002015-04-10 13:05:58 +00004909 goto exit;
4910 }
4911 }
4912
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004913 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
4914
Kalle Valo5e3dd152013-06-12 20:52:10 +03004915 spin_lock_bh(&ar->data_lock);
4916 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4917 if (peer && cmd == SET_KEY)
4918 peer->keys[key->keyidx] = key;
4919 else if (peer && cmd == DISABLE_KEY)
4920 peer->keys[key->keyidx] = NULL;
4921 else if (peer == NULL)
4922 /* impossible unless FW goes crazy */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004923 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004924 spin_unlock_bh(&ar->data_lock);
4925
4926exit:
4927 mutex_unlock(&ar->conf_mutex);
4928 return ret;
4929}
4930
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004931static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
4932 struct ieee80211_vif *vif,
4933 int keyidx)
4934{
4935 struct ath10k *ar = hw->priv;
4936 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4937 int ret;
4938
4939 mutex_lock(&arvif->ar->conf_mutex);
4940
4941 if (arvif->ar->state != ATH10K_STATE_ON)
4942 goto unlock;
4943
4944 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
4945 arvif->vdev_id, keyidx);
4946
4947 ret = ath10k_wmi_vdev_set_param(arvif->ar,
4948 arvif->vdev_id,
4949 arvif->ar->wmi.vdev_param->def_keyid,
4950 keyidx);
4951
4952 if (ret) {
4953 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
4954 arvif->vdev_id,
4955 ret);
4956 goto unlock;
4957 }
4958
4959 arvif->def_wep_key_idx = keyidx;
Michal Kazior370e5672015-02-18 14:02:26 +01004960
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004961unlock:
4962 mutex_unlock(&arvif->ar->conf_mutex);
4963}
4964
Michal Kazior9797feb2014-02-14 14:49:48 +01004965static void ath10k_sta_rc_update_wk(struct work_struct *wk)
4966{
4967 struct ath10k *ar;
4968 struct ath10k_vif *arvif;
4969 struct ath10k_sta *arsta;
4970 struct ieee80211_sta *sta;
Michal Kazior45c9abc2015-04-21 20:42:58 +03004971 struct cfg80211_chan_def def;
4972 enum ieee80211_band band;
4973 const u8 *ht_mcs_mask;
4974 const u16 *vht_mcs_mask;
Michal Kazior9797feb2014-02-14 14:49:48 +01004975 u32 changed, bw, nss, smps;
4976 int err;
4977
4978 arsta = container_of(wk, struct ath10k_sta, update_wk);
4979 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
4980 arvif = arsta->arvif;
4981 ar = arvif->ar;
4982
Michal Kazior45c9abc2015-04-21 20:42:58 +03004983 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
4984 return;
4985
4986 band = def.chan->band;
4987 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
4988 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
4989
Michal Kazior9797feb2014-02-14 14:49:48 +01004990 spin_lock_bh(&ar->data_lock);
4991
4992 changed = arsta->changed;
4993 arsta->changed = 0;
4994
4995 bw = arsta->bw;
4996 nss = arsta->nss;
4997 smps = arsta->smps;
4998
4999 spin_unlock_bh(&ar->data_lock);
5000
5001 mutex_lock(&ar->conf_mutex);
5002
Michal Kazior45c9abc2015-04-21 20:42:58 +03005003 nss = max_t(u32, 1, nss);
5004 nss = min(nss, max(ath10k_mac_max_ht_nss(ht_mcs_mask),
5005 ath10k_mac_max_vht_nss(vht_mcs_mask)));
5006
Michal Kazior9797feb2014-02-14 14:49:48 +01005007 if (changed & IEEE80211_RC_BW_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005008 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01005009 sta->addr, bw);
5010
5011 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5012 WMI_PEER_CHAN_WIDTH, bw);
5013 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005014 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01005015 sta->addr, bw, err);
5016 }
5017
5018 if (changed & IEEE80211_RC_NSS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005019 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01005020 sta->addr, nss);
5021
5022 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5023 WMI_PEER_NSS, nss);
5024 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005025 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01005026 sta->addr, nss, err);
5027 }
5028
5029 if (changed & IEEE80211_RC_SMPS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005030 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01005031 sta->addr, smps);
5032
5033 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5034 WMI_PEER_SMPS_STATE, smps);
5035 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005036 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01005037 sta->addr, smps, err);
5038 }
5039
Janusz Dziedzic55884c02014-12-17 12:30:02 +02005040 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
5041 changed & IEEE80211_RC_NSS_CHANGED) {
5042 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02005043 sta->addr);
5044
Michal Kazior590922a2014-10-21 10:10:29 +03005045 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02005046 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005047 ath10k_warn(ar, "failed to reassociate station: %pM\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02005048 sta->addr);
5049 }
5050
Michal Kazior9797feb2014-02-14 14:49:48 +01005051 mutex_unlock(&ar->conf_mutex);
5052}
5053
Marek Puzyniak7c354242015-03-30 09:51:52 +03005054static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif,
5055 struct ieee80211_sta *sta)
Michal Kaziorcfd10612014-11-25 15:16:05 +01005056{
5057 struct ath10k *ar = arvif->ar;
5058
5059 lockdep_assert_held(&ar->conf_mutex);
5060
Marek Puzyniak7c354242015-03-30 09:51:52 +03005061 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
Michal Kaziorcfd10612014-11-25 15:16:05 +01005062 return 0;
5063
5064 if (ar->num_stations >= ar->max_num_stations)
5065 return -ENOBUFS;
5066
5067 ar->num_stations++;
5068
5069 return 0;
5070}
5071
Marek Puzyniak7c354242015-03-30 09:51:52 +03005072static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif,
5073 struct ieee80211_sta *sta)
Michal Kaziorcfd10612014-11-25 15:16:05 +01005074{
5075 struct ath10k *ar = arvif->ar;
5076
5077 lockdep_assert_held(&ar->conf_mutex);
5078
Marek Puzyniak7c354242015-03-30 09:51:52 +03005079 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
Michal Kaziorcfd10612014-11-25 15:16:05 +01005080 return;
5081
5082 ar->num_stations--;
5083}
5084
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005085struct ath10k_mac_tdls_iter_data {
5086 u32 num_tdls_stations;
5087 struct ieee80211_vif *curr_vif;
5088};
5089
5090static void ath10k_mac_tdls_vif_stations_count_iter(void *data,
5091 struct ieee80211_sta *sta)
5092{
5093 struct ath10k_mac_tdls_iter_data *iter_data = data;
5094 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5095 struct ieee80211_vif *sta_vif = arsta->arvif->vif;
5096
5097 if (sta->tdls && sta_vif == iter_data->curr_vif)
5098 iter_data->num_tdls_stations++;
5099}
5100
5101static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw *hw,
5102 struct ieee80211_vif *vif)
5103{
5104 struct ath10k_mac_tdls_iter_data data = {};
5105
5106 data.curr_vif = vif;
5107
5108 ieee80211_iterate_stations_atomic(hw,
5109 ath10k_mac_tdls_vif_stations_count_iter,
5110 &data);
5111 return data.num_tdls_stations;
5112}
5113
5114static void ath10k_mac_tdls_vifs_count_iter(void *data, u8 *mac,
5115 struct ieee80211_vif *vif)
5116{
5117 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5118 int *num_tdls_vifs = data;
5119
5120 if (vif->type != NL80211_IFTYPE_STATION)
5121 return;
5122
5123 if (ath10k_mac_tdls_vif_stations_count(arvif->ar->hw, vif) > 0)
5124 (*num_tdls_vifs)++;
5125}
5126
5127static int ath10k_mac_tdls_vifs_count(struct ieee80211_hw *hw)
5128{
5129 int num_tdls_vifs = 0;
5130
5131 ieee80211_iterate_active_interfaces_atomic(hw,
5132 IEEE80211_IFACE_ITER_NORMAL,
5133 ath10k_mac_tdls_vifs_count_iter,
5134 &num_tdls_vifs);
5135 return num_tdls_vifs;
5136}
5137
Kalle Valo5e3dd152013-06-12 20:52:10 +03005138static int ath10k_sta_state(struct ieee80211_hw *hw,
5139 struct ieee80211_vif *vif,
5140 struct ieee80211_sta *sta,
5141 enum ieee80211_sta_state old_state,
5142 enum ieee80211_sta_state new_state)
5143{
5144 struct ath10k *ar = hw->priv;
5145 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01005146 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005147 int ret = 0;
5148
Michal Kazior76f90022014-02-25 09:29:57 +02005149 if (old_state == IEEE80211_STA_NOTEXIST &&
5150 new_state == IEEE80211_STA_NONE) {
5151 memset(arsta, 0, sizeof(*arsta));
5152 arsta->arvif = arvif;
5153 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
5154 }
5155
Michal Kazior9797feb2014-02-14 14:49:48 +01005156 /* cancel must be done outside the mutex to avoid deadlock */
5157 if ((old_state == IEEE80211_STA_NONE &&
5158 new_state == IEEE80211_STA_NOTEXIST))
5159 cancel_work_sync(&arsta->update_wk);
5160
Kalle Valo5e3dd152013-06-12 20:52:10 +03005161 mutex_lock(&ar->conf_mutex);
5162
5163 if (old_state == IEEE80211_STA_NOTEXIST &&
Michal Kazior077efc82014-10-21 10:10:29 +03005164 new_state == IEEE80211_STA_NONE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03005165 /*
5166 * New station addition.
5167 */
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005168 enum wmi_peer_type peer_type = WMI_PEER_TYPE_DEFAULT;
5169 u32 num_tdls_stations;
5170 u32 num_tdls_vifs;
5171
Michal Kaziorcfd10612014-11-25 15:16:05 +01005172 ath10k_dbg(ar, ATH10K_DBG_MAC,
5173 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
5174 arvif->vdev_id, sta->addr,
5175 ar->num_stations + 1, ar->max_num_stations,
5176 ar->num_peers + 1, ar->max_num_peers);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01005177
Marek Puzyniak7c354242015-03-30 09:51:52 +03005178 ret = ath10k_mac_inc_num_stations(arvif, sta);
Michal Kaziorcfd10612014-11-25 15:16:05 +01005179 if (ret) {
5180 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
5181 ar->max_num_stations);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01005182 goto exit;
5183 }
5184
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005185 if (sta->tdls)
5186 peer_type = WMI_PEER_TYPE_TDLS;
5187
Marek Puzyniak7390ed32015-03-30 09:51:52 +03005188 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr,
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005189 peer_type);
Michal Kaziora52c0282014-11-25 15:16:03 +01005190 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005191 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 -08005192 sta->addr, arvif->vdev_id, ret);
Marek Puzyniak7c354242015-03-30 09:51:52 +03005193 ath10k_mac_dec_num_stations(arvif, sta);
Michal Kaziora52c0282014-11-25 15:16:03 +01005194 goto exit;
5195 }
Michal Kazior077efc82014-10-21 10:10:29 +03005196
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005197 if (!sta->tdls)
5198 goto exit;
Michal Kazior077efc82014-10-21 10:10:29 +03005199
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005200 num_tdls_stations = ath10k_mac_tdls_vif_stations_count(hw, vif);
5201 num_tdls_vifs = ath10k_mac_tdls_vifs_count(hw);
5202
5203 if (num_tdls_vifs >= ar->max_num_tdls_vdevs &&
5204 num_tdls_stations == 0) {
5205 ath10k_warn(ar, "vdev %i exceeded maximum number of tdls vdevs %i\n",
5206 arvif->vdev_id, ar->max_num_tdls_vdevs);
5207 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5208 ath10k_mac_dec_num_stations(arvif, sta);
5209 ret = -ENOBUFS;
5210 goto exit;
5211 }
5212
5213 if (num_tdls_stations == 0) {
5214 /* This is the first tdls peer in current vif */
5215 enum wmi_tdls_state state = WMI_TDLS_ENABLE_ACTIVE;
5216
5217 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5218 state);
Michal Kazior077efc82014-10-21 10:10:29 +03005219 if (ret) {
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005220 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
Michal Kazior077efc82014-10-21 10:10:29 +03005221 arvif->vdev_id, ret);
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005222 ath10k_peer_delete(ar, arvif->vdev_id,
5223 sta->addr);
5224 ath10k_mac_dec_num_stations(arvif, sta);
Michal Kazior077efc82014-10-21 10:10:29 +03005225 goto exit;
5226 }
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005227 }
Michal Kazior077efc82014-10-21 10:10:29 +03005228
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005229 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
5230 WMI_TDLS_PEER_STATE_PEERING);
5231 if (ret) {
5232 ath10k_warn(ar,
5233 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
5234 sta->addr, arvif->vdev_id, ret);
5235 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5236 ath10k_mac_dec_num_stations(arvif, sta);
5237
5238 if (num_tdls_stations != 0)
5239 goto exit;
5240 ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5241 WMI_TDLS_DISABLE);
Michal Kazior077efc82014-10-21 10:10:29 +03005242 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005243 } else if ((old_state == IEEE80211_STA_NONE &&
5244 new_state == IEEE80211_STA_NOTEXIST)) {
5245 /*
5246 * Existing station deletion.
5247 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005248 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03005249 "mac vdev %d peer delete %pM (sta gone)\n",
5250 arvif->vdev_id, sta->addr);
Michal Kazior077efc82014-10-21 10:10:29 +03005251
Kalle Valo5e3dd152013-06-12 20:52:10 +03005252 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5253 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005254 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02005255 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005256
Marek Puzyniak7c354242015-03-30 09:51:52 +03005257 ath10k_mac_dec_num_stations(arvif, sta);
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005258
5259 if (!sta->tdls)
5260 goto exit;
5261
5262 if (ath10k_mac_tdls_vif_stations_count(hw, vif))
5263 goto exit;
5264
5265 /* This was the last tdls peer in current vif */
5266 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5267 WMI_TDLS_DISABLE);
5268 if (ret) {
5269 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
5270 arvif->vdev_id, ret);
5271 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005272 } else if (old_state == IEEE80211_STA_AUTH &&
5273 new_state == IEEE80211_STA_ASSOC &&
5274 (vif->type == NL80211_IFTYPE_AP ||
5275 vif->type == NL80211_IFTYPE_ADHOC)) {
5276 /*
5277 * New association.
5278 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005279 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03005280 sta->addr);
5281
Michal Kazior590922a2014-10-21 10:10:29 +03005282 ret = ath10k_station_assoc(ar, vif, sta, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005283 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005284 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02005285 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005286 } else if (old_state == IEEE80211_STA_ASSOC &&
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03005287 new_state == IEEE80211_STA_AUTHORIZED &&
5288 sta->tdls) {
5289 /*
5290 * Tdls station authorized.
5291 */
5292 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac tdls sta %pM authorized\n",
5293 sta->addr);
5294
5295 ret = ath10k_station_assoc(ar, vif, sta, false);
5296 if (ret) {
5297 ath10k_warn(ar, "failed to associate tdls station %pM for vdev %i: %i\n",
5298 sta->addr, arvif->vdev_id, ret);
5299 goto exit;
5300 }
5301
5302 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
5303 WMI_TDLS_PEER_STATE_CONNECTED);
5304 if (ret)
5305 ath10k_warn(ar, "failed to update tdls peer %pM for vdev %i: %i\n",
5306 sta->addr, arvif->vdev_id, ret);
5307 } else if (old_state == IEEE80211_STA_ASSOC &&
5308 new_state == IEEE80211_STA_AUTH &&
5309 (vif->type == NL80211_IFTYPE_AP ||
5310 vif->type == NL80211_IFTYPE_ADHOC)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03005311 /*
5312 * Disassociation.
5313 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005314 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03005315 sta->addr);
5316
Michal Kazior590922a2014-10-21 10:10:29 +03005317 ret = ath10k_station_disassoc(ar, vif, sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005318 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005319 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02005320 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005321 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01005322exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005323 mutex_unlock(&ar->conf_mutex);
5324 return ret;
5325}
5326
5327static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
Kalle Valo5b07e072014-09-14 12:50:06 +03005328 u16 ac, bool enable)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005329{
5330 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorb0e56152015-01-24 12:14:52 +02005331 struct wmi_sta_uapsd_auto_trig_arg arg = {};
5332 u32 prio = 0, acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005333 u32 value = 0;
5334 int ret = 0;
5335
Michal Kazior548db542013-07-05 16:15:15 +03005336 lockdep_assert_held(&ar->conf_mutex);
5337
Kalle Valo5e3dd152013-06-12 20:52:10 +03005338 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
5339 return 0;
5340
5341 switch (ac) {
5342 case IEEE80211_AC_VO:
5343 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
5344 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005345 prio = 7;
5346 acc = 3;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005347 break;
5348 case IEEE80211_AC_VI:
5349 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
5350 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005351 prio = 5;
5352 acc = 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005353 break;
5354 case IEEE80211_AC_BE:
5355 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
5356 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005357 prio = 2;
5358 acc = 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005359 break;
5360 case IEEE80211_AC_BK:
5361 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
5362 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02005363 prio = 0;
5364 acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005365 break;
5366 }
5367
5368 if (enable)
5369 arvif->u.sta.uapsd |= value;
5370 else
5371 arvif->u.sta.uapsd &= ~value;
5372
5373 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5374 WMI_STA_PS_PARAM_UAPSD,
5375 arvif->u.sta.uapsd);
5376 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005377 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005378 goto exit;
5379 }
5380
5381 if (arvif->u.sta.uapsd)
5382 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
5383 else
5384 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
5385
5386 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5387 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
5388 value);
5389 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005390 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005391
Michal Kazior9f9b5742014-12-12 12:41:36 +01005392 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
5393 if (ret) {
5394 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
5395 arvif->vdev_id, ret);
5396 return ret;
5397 }
5398
5399 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
5400 if (ret) {
5401 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
5402 arvif->vdev_id, ret);
5403 return ret;
5404 }
5405
Michal Kaziorb0e56152015-01-24 12:14:52 +02005406 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
5407 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
5408 /* Only userspace can make an educated decision when to send
5409 * trigger frame. The following effectively disables u-UAPSD
5410 * autotrigger in firmware (which is enabled by default
5411 * provided the autotrigger service is available).
5412 */
5413
5414 arg.wmm_ac = acc;
5415 arg.user_priority = prio;
5416 arg.service_interval = 0;
5417 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
5418 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
5419
5420 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
5421 arvif->bssid, &arg, 1);
5422 if (ret) {
5423 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
5424 ret);
5425 return ret;
5426 }
5427 }
5428
Kalle Valo5e3dd152013-06-12 20:52:10 +03005429exit:
5430 return ret;
5431}
5432
5433static int ath10k_conf_tx(struct ieee80211_hw *hw,
5434 struct ieee80211_vif *vif, u16 ac,
5435 const struct ieee80211_tx_queue_params *params)
5436{
5437 struct ath10k *ar = hw->priv;
Michal Kazior5e752e42015-01-19 09:53:41 +01005438 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005439 struct wmi_wmm_params_arg *p = NULL;
5440 int ret;
5441
5442 mutex_lock(&ar->conf_mutex);
5443
5444 switch (ac) {
5445 case IEEE80211_AC_VO:
Michal Kazior5e752e42015-01-19 09:53:41 +01005446 p = &arvif->wmm_params.ac_vo;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005447 break;
5448 case IEEE80211_AC_VI:
Michal Kazior5e752e42015-01-19 09:53:41 +01005449 p = &arvif->wmm_params.ac_vi;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005450 break;
5451 case IEEE80211_AC_BE:
Michal Kazior5e752e42015-01-19 09:53:41 +01005452 p = &arvif->wmm_params.ac_be;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005453 break;
5454 case IEEE80211_AC_BK:
Michal Kazior5e752e42015-01-19 09:53:41 +01005455 p = &arvif->wmm_params.ac_bk;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005456 break;
5457 }
5458
5459 if (WARN_ON(!p)) {
5460 ret = -EINVAL;
5461 goto exit;
5462 }
5463
5464 p->cwmin = params->cw_min;
5465 p->cwmax = params->cw_max;
5466 p->aifs = params->aifs;
5467
5468 /*
5469 * The channel time duration programmed in the HW is in absolute
5470 * microseconds, while mac80211 gives the txop in units of
5471 * 32 microseconds.
5472 */
5473 p->txop = params->txop * 32;
5474
Michal Kazior7fc979a2015-01-28 09:57:28 +02005475 if (ar->wmi.ops->gen_vdev_wmm_conf) {
5476 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
5477 &arvif->wmm_params);
5478 if (ret) {
5479 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
5480 arvif->vdev_id, ret);
5481 goto exit;
5482 }
5483 } else {
5484 /* This won't work well with multi-interface cases but it's
5485 * better than nothing.
5486 */
5487 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
5488 if (ret) {
5489 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
5490 goto exit;
5491 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005492 }
5493
5494 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
5495 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005496 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005497
5498exit:
5499 mutex_unlock(&ar->conf_mutex);
5500 return ret;
5501}
5502
5503#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
5504
5505static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
5506 struct ieee80211_vif *vif,
5507 struct ieee80211_channel *chan,
5508 int duration,
5509 enum ieee80211_roc_type type)
5510{
5511 struct ath10k *ar = hw->priv;
5512 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5513 struct wmi_start_scan_arg arg;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005514 int ret = 0;
Michal Kaziorfcf98442015-03-31 11:03:47 +00005515 u32 scan_time_msec;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005516
5517 mutex_lock(&ar->conf_mutex);
5518
5519 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005520 switch (ar->scan.state) {
5521 case ATH10K_SCAN_IDLE:
5522 reinit_completion(&ar->scan.started);
5523 reinit_completion(&ar->scan.completed);
5524 reinit_completion(&ar->scan.on_channel);
5525 ar->scan.state = ATH10K_SCAN_STARTING;
5526 ar->scan.is_roc = true;
5527 ar->scan.vdev_id = arvif->vdev_id;
5528 ar->scan.roc_freq = chan->center_freq;
Michal Kaziord710e752015-07-09 13:08:36 +02005529 ar->scan.roc_notify = true;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005530 ret = 0;
5531 break;
5532 case ATH10K_SCAN_STARTING:
5533 case ATH10K_SCAN_RUNNING:
5534 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005535 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005536 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005537 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005538 spin_unlock_bh(&ar->data_lock);
5539
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005540 if (ret)
5541 goto exit;
5542
Michal Kaziorfcf98442015-03-31 11:03:47 +00005543 scan_time_msec = ar->hw->wiphy->max_remain_on_channel_duration * 2;
Michal Kaziordcca0bd2014-11-24 14:58:32 +01005544
Kalle Valo5e3dd152013-06-12 20:52:10 +03005545 memset(&arg, 0, sizeof(arg));
5546 ath10k_wmi_start_scan_init(ar, &arg);
5547 arg.vdev_id = arvif->vdev_id;
5548 arg.scan_id = ATH10K_SCAN_ID;
5549 arg.n_channels = 1;
5550 arg.channels[0] = chan->center_freq;
Michal Kaziorfcf98442015-03-31 11:03:47 +00005551 arg.dwell_time_active = scan_time_msec;
5552 arg.dwell_time_passive = scan_time_msec;
5553 arg.max_scan_time = scan_time_msec;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005554 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
5555 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
Michal Kaziordbd3f9f2015-03-31 11:03:48 +00005556 arg.burst_duration_ms = duration;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005557
5558 ret = ath10k_start_scan(ar, &arg);
5559 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005560 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005561 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005562 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005563 spin_unlock_bh(&ar->data_lock);
5564 goto exit;
5565 }
5566
5567 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
5568 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005569 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005570
5571 ret = ath10k_scan_stop(ar);
5572 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005573 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005574
Kalle Valo5e3dd152013-06-12 20:52:10 +03005575 ret = -ETIMEDOUT;
5576 goto exit;
5577 }
5578
Michal Kaziorfcf98442015-03-31 11:03:47 +00005579 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
5580 msecs_to_jiffies(duration));
5581
Kalle Valo5e3dd152013-06-12 20:52:10 +03005582 ret = 0;
5583exit:
5584 mutex_unlock(&ar->conf_mutex);
5585 return ret;
5586}
5587
5588static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
5589{
5590 struct ath10k *ar = hw->priv;
5591
5592 mutex_lock(&ar->conf_mutex);
Michal Kaziord710e752015-07-09 13:08:36 +02005593
5594 spin_lock_bh(&ar->data_lock);
5595 ar->scan.roc_notify = false;
5596 spin_unlock_bh(&ar->data_lock);
5597
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005598 ath10k_scan_abort(ar);
Michal Kaziord710e752015-07-09 13:08:36 +02005599
Kalle Valo5e3dd152013-06-12 20:52:10 +03005600 mutex_unlock(&ar->conf_mutex);
5601
Michal Kazior4eb2e162014-10-28 10:23:09 +01005602 cancel_delayed_work_sync(&ar->scan.timeout);
5603
Kalle Valo5e3dd152013-06-12 20:52:10 +03005604 return 0;
5605}
5606
5607/*
5608 * Both RTS and Fragmentation threshold are interface-specific
5609 * in ath10k, but device-specific in mac80211.
5610 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03005611
5612static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
5613{
Kalle Valo5e3dd152013-06-12 20:52:10 +03005614 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03005615 struct ath10k_vif *arvif;
5616 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03005617
Michal Kaziorad088bf2013-10-16 15:44:46 +03005618 mutex_lock(&ar->conf_mutex);
5619 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005620 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03005621 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03005622
Michal Kaziorad088bf2013-10-16 15:44:46 +03005623 ret = ath10k_mac_set_rts(arvif, value);
5624 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005625 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03005626 arvif->vdev_id, ret);
5627 break;
5628 }
5629 }
5630 mutex_unlock(&ar->conf_mutex);
5631
5632 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005633}
5634
Michal Kazior92092fe2015-08-03 11:16:43 +02005635static int ath10k_mac_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
5636{
5637 /* Even though there's a WMI enum for fragmentation threshold no known
5638 * firmware actually implements it. Moreover it is not possible to rely
5639 * frame fragmentation to mac80211 because firmware clears the "more
5640 * fragments" bit in frame control making it impossible for remote
5641 * devices to reassemble frames.
5642 *
5643 * Hence implement a dummy callback just to say fragmentation isn't
5644 * supported. This effectively prevents mac80211 from doing frame
5645 * fragmentation in software.
5646 */
5647 return -EOPNOTSUPP;
5648}
5649
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02005650static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5651 u32 queues, bool drop)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005652{
5653 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02005654 bool skip;
Nicholas Mc Guired4298a32015-06-15 14:46:43 +03005655 long time_left;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005656
5657 /* mac80211 doesn't care if we really xmit queued frames or not
5658 * we'll collect those frames either way if we stop/delete vdevs */
5659 if (drop)
5660 return;
5661
Michal Kazior548db542013-07-05 16:15:15 +03005662 mutex_lock(&ar->conf_mutex);
5663
Michal Kazioraffd3212013-07-16 09:54:35 +02005664 if (ar->state == ATH10K_STATE_WEDGED)
5665 goto skip;
5666
Nicholas Mc Guired4298a32015-06-15 14:46:43 +03005667 time_left = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03005668 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02005669
Michal Kazioredb82362013-07-05 16:15:14 +03005670 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02005671 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03005672 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02005673
Michal Kazior7962b0d2014-10-28 10:34:38 +01005674 skip = (ar->state == ATH10K_STATE_WEDGED) ||
5675 test_bit(ATH10K_FLAG_CRASH_FLUSH,
5676 &ar->dev_flags);
Michal Kazioraffd3212013-07-16 09:54:35 +02005677
5678 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005679 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02005680
Nicholas Mc Guired4298a32015-06-15 14:46:43 +03005681 if (time_left == 0 || skip)
5682 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %ld\n",
5683 skip, ar->state, time_left);
Michal Kazior548db542013-07-05 16:15:15 +03005684
Michal Kazioraffd3212013-07-16 09:54:35 +02005685skip:
Michal Kazior548db542013-07-05 16:15:15 +03005686 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005687}
5688
5689/* TODO: Implement this function properly
5690 * For now it is needed to reply to Probe Requests in IBSS mode.
5691 * Propably we need this information from FW.
5692 */
5693static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
5694{
5695 return 1;
5696}
5697
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005698static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
5699 enum ieee80211_reconfig_type reconfig_type)
Michal Kazioraffd3212013-07-16 09:54:35 +02005700{
5701 struct ath10k *ar = hw->priv;
5702
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005703 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
5704 return;
5705
Michal Kazioraffd3212013-07-16 09:54:35 +02005706 mutex_lock(&ar->conf_mutex);
5707
5708 /* If device failed to restart it will be in a different state, e.g.
5709 * ATH10K_STATE_WEDGED */
5710 if (ar->state == ATH10K_STATE_RESTARTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005711 ath10k_info(ar, "device successfully recovered\n");
Michal Kazioraffd3212013-07-16 09:54:35 +02005712 ar->state = ATH10K_STATE_ON;
Michal Kazior7962b0d2014-10-28 10:34:38 +01005713 ieee80211_wake_queues(ar->hw);
Michal Kazioraffd3212013-07-16 09:54:35 +02005714 }
5715
5716 mutex_unlock(&ar->conf_mutex);
5717}
5718
Michal Kazior2e1dea42013-07-31 10:32:40 +02005719static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
5720 struct survey_info *survey)
5721{
5722 struct ath10k *ar = hw->priv;
5723 struct ieee80211_supported_band *sband;
5724 struct survey_info *ar_survey = &ar->survey[idx];
5725 int ret = 0;
5726
5727 mutex_lock(&ar->conf_mutex);
5728
5729 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
5730 if (sband && idx >= sband->n_channels) {
5731 idx -= sband->n_channels;
5732 sband = NULL;
5733 }
5734
5735 if (!sband)
5736 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
5737
5738 if (!sband || idx >= sband->n_channels) {
5739 ret = -ENOENT;
5740 goto exit;
5741 }
5742
5743 spin_lock_bh(&ar->data_lock);
5744 memcpy(survey, ar_survey, sizeof(*survey));
5745 spin_unlock_bh(&ar->data_lock);
5746
5747 survey->channel = &sband->channels[idx];
5748
Felix Fietkaufa1d4df2014-10-23 17:04:28 +03005749 if (ar->rx_channel == survey->channel)
5750 survey->filled |= SURVEY_INFO_IN_USE;
5751
Michal Kazior2e1dea42013-07-31 10:32:40 +02005752exit:
5753 mutex_unlock(&ar->conf_mutex);
5754 return ret;
5755}
5756
Michal Kazior3ae54222015-03-31 10:49:20 +00005757static bool
5758ath10k_mac_bitrate_mask_has_single_rate(struct ath10k *ar,
5759 enum ieee80211_band band,
5760 const struct cfg80211_bitrate_mask *mask)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005761{
Michal Kazior3ae54222015-03-31 10:49:20 +00005762 int num_rates = 0;
5763 int i;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005764
Michal Kazior3ae54222015-03-31 10:49:20 +00005765 num_rates += hweight32(mask->control[band].legacy);
5766
5767 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++)
5768 num_rates += hweight8(mask->control[band].ht_mcs[i]);
5769
5770 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++)
5771 num_rates += hweight16(mask->control[band].vht_mcs[i]);
5772
5773 return num_rates == 1;
5774}
5775
5776static bool
5777ath10k_mac_bitrate_mask_get_single_nss(struct ath10k *ar,
5778 enum ieee80211_band band,
5779 const struct cfg80211_bitrate_mask *mask,
5780 int *nss)
5781{
5782 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
5783 u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
5784 u8 ht_nss_mask = 0;
5785 u8 vht_nss_mask = 0;
5786 int i;
5787
5788 if (mask->control[band].legacy)
5789 return false;
5790
5791 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
5792 if (mask->control[band].ht_mcs[i] == 0)
5793 continue;
5794 else if (mask->control[band].ht_mcs[i] ==
5795 sband->ht_cap.mcs.rx_mask[i])
5796 ht_nss_mask |= BIT(i);
5797 else
5798 return false;
5799 }
5800
5801 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
5802 if (mask->control[band].vht_mcs[i] == 0)
5803 continue;
5804 else if (mask->control[band].vht_mcs[i] ==
5805 ath10k_mac_get_max_vht_mcs_map(vht_mcs_map, i))
5806 vht_nss_mask |= BIT(i);
5807 else
5808 return false;
5809 }
5810
5811 if (ht_nss_mask != vht_nss_mask)
5812 return false;
5813
5814 if (ht_nss_mask == 0)
5815 return false;
5816
5817 if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask)
5818 return false;
5819
5820 *nss = fls(ht_nss_mask);
5821
5822 return true;
5823}
5824
5825static int
5826ath10k_mac_bitrate_mask_get_single_rate(struct ath10k *ar,
5827 enum ieee80211_band band,
5828 const struct cfg80211_bitrate_mask *mask,
5829 u8 *rate, u8 *nss)
5830{
5831 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
5832 int rate_idx;
5833 int i;
5834 u16 bitrate;
5835 u8 preamble;
5836 u8 hw_rate;
5837
5838 if (hweight32(mask->control[band].legacy) == 1) {
5839 rate_idx = ffs(mask->control[band].legacy) - 1;
5840
5841 hw_rate = sband->bitrates[rate_idx].hw_value;
5842 bitrate = sband->bitrates[rate_idx].bitrate;
5843
5844 if (ath10k_mac_bitrate_is_cck(bitrate))
5845 preamble = WMI_RATE_PREAMBLE_CCK;
5846 else
5847 preamble = WMI_RATE_PREAMBLE_OFDM;
5848
5849 *nss = 1;
5850 *rate = preamble << 6 |
5851 (*nss - 1) << 4 |
5852 hw_rate << 0;
5853
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005854 return 0;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005855 }
5856
Michal Kazior3ae54222015-03-31 10:49:20 +00005857 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
5858 if (hweight8(mask->control[band].ht_mcs[i]) == 1) {
5859 *nss = i + 1;
5860 *rate = WMI_RATE_PREAMBLE_HT << 6 |
5861 (*nss - 1) << 4 |
5862 (ffs(mask->control[band].ht_mcs[i]) - 1);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005863
Michal Kazior3ae54222015-03-31 10:49:20 +00005864 return 0;
5865 }
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005866 }
5867
Michal Kazior3ae54222015-03-31 10:49:20 +00005868 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
5869 if (hweight16(mask->control[band].vht_mcs[i]) == 1) {
5870 *nss = i + 1;
5871 *rate = WMI_RATE_PREAMBLE_VHT << 6 |
5872 (*nss - 1) << 4 |
5873 (ffs(mask->control[band].vht_mcs[i]) - 1);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005874
Michal Kazior3ae54222015-03-31 10:49:20 +00005875 return 0;
5876 }
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005877 }
5878
Michal Kazior3ae54222015-03-31 10:49:20 +00005879 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005880}
5881
Michal Kazior3ae54222015-03-31 10:49:20 +00005882static int ath10k_mac_set_fixed_rate_params(struct ath10k_vif *arvif,
5883 u8 rate, u8 nss, u8 sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005884{
5885 struct ath10k *ar = arvif->ar;
5886 u32 vdev_param;
Michal Kazior3ae54222015-03-31 10:49:20 +00005887 int ret;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005888
Michal Kazior3ae54222015-03-31 10:49:20 +00005889 lockdep_assert_held(&ar->conf_mutex);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005890
Michal Kazior3ae54222015-03-31 10:49:20 +00005891 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac set fixed rate params vdev %i rate 0x%02hhx nss %hhu sgi %hhu\n",
5892 arvif->vdev_id, rate, nss, sgi);
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005893
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005894 vdev_param = ar->wmi.vdev_param->fixed_rate;
Michal Kazior3ae54222015-03-31 10:49:20 +00005895 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, rate);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005896 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005897 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
Michal Kazior3ae54222015-03-31 10:49:20 +00005898 rate, ret);
5899 return ret;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005900 }
5901
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005902 vdev_param = ar->wmi.vdev_param->nss;
Michal Kazior3ae54222015-03-31 10:49:20 +00005903 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, nss);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005904 if (ret) {
Michal Kazior3ae54222015-03-31 10:49:20 +00005905 ath10k_warn(ar, "failed to set nss param %d: %d\n", nss, ret);
5906 return ret;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005907 }
5908
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005909 vdev_param = ar->wmi.vdev_param->sgi;
Michal Kazior3ae54222015-03-31 10:49:20 +00005910 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, sgi);
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005911 if (ret) {
Michal Kazior3ae54222015-03-31 10:49:20 +00005912 ath10k_warn(ar, "failed to set sgi param %d: %d\n", sgi, ret);
5913 return ret;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005914 }
5915
Michal Kazior3ae54222015-03-31 10:49:20 +00005916 return 0;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005917}
5918
Michal Kazior45c9abc2015-04-21 20:42:58 +03005919static bool
5920ath10k_mac_can_set_bitrate_mask(struct ath10k *ar,
5921 enum ieee80211_band band,
5922 const struct cfg80211_bitrate_mask *mask)
5923{
5924 int i;
5925 u16 vht_mcs;
5926
5927 /* Due to firmware limitation in WMI_PEER_ASSOC_CMDID it is impossible
5928 * to express all VHT MCS rate masks. Effectively only the following
5929 * ranges can be used: none, 0-7, 0-8 and 0-9.
5930 */
5931 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
5932 vht_mcs = mask->control[band].vht_mcs[i];
5933
5934 switch (vht_mcs) {
5935 case 0:
5936 case BIT(8) - 1:
5937 case BIT(9) - 1:
5938 case BIT(10) - 1:
5939 break;
5940 default:
5941 ath10k_warn(ar, "refusing bitrate mask with missing 0-7 VHT MCS rates\n");
5942 return false;
5943 }
5944 }
5945
5946 return true;
5947}
5948
5949static void ath10k_mac_set_bitrate_mask_iter(void *data,
5950 struct ieee80211_sta *sta)
5951{
5952 struct ath10k_vif *arvif = data;
5953 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5954 struct ath10k *ar = arvif->ar;
5955
5956 if (arsta->arvif != arvif)
5957 return;
5958
5959 spin_lock_bh(&ar->data_lock);
5960 arsta->changed |= IEEE80211_RC_SUPP_RATES_CHANGED;
5961 spin_unlock_bh(&ar->data_lock);
5962
5963 ieee80211_queue_work(ar->hw, &arsta->update_wk);
5964}
5965
Michal Kazior3ae54222015-03-31 10:49:20 +00005966static int ath10k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw,
5967 struct ieee80211_vif *vif,
5968 const struct cfg80211_bitrate_mask *mask)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005969{
5970 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior500ff9f2015-03-31 10:26:21 +00005971 struct cfg80211_chan_def def;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005972 struct ath10k *ar = arvif->ar;
Michal Kazior500ff9f2015-03-31 10:26:21 +00005973 enum ieee80211_band band;
Michal Kazior45c9abc2015-04-21 20:42:58 +03005974 const u8 *ht_mcs_mask;
5975 const u16 *vht_mcs_mask;
Michal Kazior3ae54222015-03-31 10:49:20 +00005976 u8 rate;
5977 u8 nss;
5978 u8 sgi;
5979 int single_nss;
5980 int ret;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005981
Michal Kazior500ff9f2015-03-31 10:26:21 +00005982 if (ath10k_mac_vif_chan(vif, &def))
5983 return -EPERM;
5984
Michal Kazior500ff9f2015-03-31 10:26:21 +00005985 band = def.chan->band;
Michal Kazior45c9abc2015-04-21 20:42:58 +03005986 ht_mcs_mask = mask->control[band].ht_mcs;
5987 vht_mcs_mask = mask->control[band].vht_mcs;
Michal Kazior500ff9f2015-03-31 10:26:21 +00005988
Michal Kazior3ae54222015-03-31 10:49:20 +00005989 sgi = mask->control[band].gi;
5990 if (sgi == NL80211_TXRATE_FORCE_LGI)
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005991 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005992
Michal Kazior3ae54222015-03-31 10:49:20 +00005993 if (ath10k_mac_bitrate_mask_has_single_rate(ar, band, mask)) {
5994 ret = ath10k_mac_bitrate_mask_get_single_rate(ar, band, mask,
5995 &rate, &nss);
5996 if (ret) {
5997 ath10k_warn(ar, "failed to get single rate for vdev %i: %d\n",
5998 arvif->vdev_id, ret);
5999 return ret;
6000 }
6001 } else if (ath10k_mac_bitrate_mask_get_single_nss(ar, band, mask,
6002 &single_nss)) {
6003 rate = WMI_FIXED_RATE_NONE;
6004 nss = single_nss;
6005 } else {
6006 rate = WMI_FIXED_RATE_NONE;
Michal Kazior45c9abc2015-04-21 20:42:58 +03006007 nss = min(ar->num_rf_chains,
6008 max(ath10k_mac_max_ht_nss(ht_mcs_mask),
6009 ath10k_mac_max_vht_nss(vht_mcs_mask)));
6010
6011 if (!ath10k_mac_can_set_bitrate_mask(ar, band, mask))
6012 return -EINVAL;
6013
6014 mutex_lock(&ar->conf_mutex);
6015
6016 arvif->bitrate_mask = *mask;
6017 ieee80211_iterate_stations_atomic(ar->hw,
6018 ath10k_mac_set_bitrate_mask_iter,
6019 arvif);
6020
6021 mutex_unlock(&ar->conf_mutex);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01006022 }
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01006023
6024 mutex_lock(&ar->conf_mutex);
6025
Michal Kazior3ae54222015-03-31 10:49:20 +00006026 ret = ath10k_mac_set_fixed_rate_params(arvif, rate, nss, sgi);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01006027 if (ret) {
Michal Kazior3ae54222015-03-31 10:49:20 +00006028 ath10k_warn(ar, "failed to set fixed rate params on vdev %i: %d\n",
6029 arvif->vdev_id, ret);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01006030 goto exit;
6031 }
6032
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01006033exit:
6034 mutex_unlock(&ar->conf_mutex);
Michal Kazior3ae54222015-03-31 10:49:20 +00006035
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01006036 return ret;
6037}
6038
Michal Kazior9797feb2014-02-14 14:49:48 +01006039static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
6040 struct ieee80211_vif *vif,
6041 struct ieee80211_sta *sta,
6042 u32 changed)
6043{
6044 struct ath10k *ar = hw->priv;
6045 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
6046 u32 bw, smps;
6047
6048 spin_lock_bh(&ar->data_lock);
6049
Michal Kazior7aa7a722014-08-25 12:09:38 +02006050 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior9797feb2014-02-14 14:49:48 +01006051 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
6052 sta->addr, changed, sta->bandwidth, sta->rx_nss,
6053 sta->smps_mode);
6054
6055 if (changed & IEEE80211_RC_BW_CHANGED) {
6056 bw = WMI_PEER_CHWIDTH_20MHZ;
6057
6058 switch (sta->bandwidth) {
6059 case IEEE80211_STA_RX_BW_20:
6060 bw = WMI_PEER_CHWIDTH_20MHZ;
6061 break;
6062 case IEEE80211_STA_RX_BW_40:
6063 bw = WMI_PEER_CHWIDTH_40MHZ;
6064 break;
6065 case IEEE80211_STA_RX_BW_80:
6066 bw = WMI_PEER_CHWIDTH_80MHZ;
6067 break;
6068 case IEEE80211_STA_RX_BW_160:
Masanari Iidad939be32015-02-27 23:52:31 +09006069 ath10k_warn(ar, "Invalid bandwidth %d in rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02006070 sta->bandwidth, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01006071 bw = WMI_PEER_CHWIDTH_20MHZ;
6072 break;
6073 }
6074
6075 arsta->bw = bw;
6076 }
6077
6078 if (changed & IEEE80211_RC_NSS_CHANGED)
6079 arsta->nss = sta->rx_nss;
6080
6081 if (changed & IEEE80211_RC_SMPS_CHANGED) {
6082 smps = WMI_PEER_SMPS_PS_NONE;
6083
6084 switch (sta->smps_mode) {
6085 case IEEE80211_SMPS_AUTOMATIC:
6086 case IEEE80211_SMPS_OFF:
6087 smps = WMI_PEER_SMPS_PS_NONE;
6088 break;
6089 case IEEE80211_SMPS_STATIC:
6090 smps = WMI_PEER_SMPS_STATIC;
6091 break;
6092 case IEEE80211_SMPS_DYNAMIC:
6093 smps = WMI_PEER_SMPS_DYNAMIC;
6094 break;
6095 case IEEE80211_SMPS_NUM_MODES:
Michal Kazior7aa7a722014-08-25 12:09:38 +02006096 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02006097 sta->smps_mode, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01006098 smps = WMI_PEER_SMPS_PS_NONE;
6099 break;
6100 }
6101
6102 arsta->smps = smps;
6103 }
6104
Michal Kazior9797feb2014-02-14 14:49:48 +01006105 arsta->changed |= changed;
6106
6107 spin_unlock_bh(&ar->data_lock);
6108
6109 ieee80211_queue_work(hw, &arsta->update_wk);
6110}
6111
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02006112static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
6113{
6114 /*
6115 * FIXME: Return 0 for time being. Need to figure out whether FW
6116 * has the API to fetch 64-bit local TSF
6117 */
6118
6119 return 0;
6120}
6121
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02006122static int ath10k_ampdu_action(struct ieee80211_hw *hw,
6123 struct ieee80211_vif *vif,
6124 enum ieee80211_ampdu_mlme_action action,
6125 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
6126 u8 buf_size)
6127{
Michal Kazior7aa7a722014-08-25 12:09:38 +02006128 struct ath10k *ar = hw->priv;
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02006129 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6130
Michal Kazior7aa7a722014-08-25 12:09:38 +02006131 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 +02006132 arvif->vdev_id, sta->addr, tid, action);
6133
6134 switch (action) {
6135 case IEEE80211_AMPDU_RX_START:
6136 case IEEE80211_AMPDU_RX_STOP:
6137 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
6138 * creation/removal. Do we need to verify this?
6139 */
6140 return 0;
6141 case IEEE80211_AMPDU_TX_START:
6142 case IEEE80211_AMPDU_TX_STOP_CONT:
6143 case IEEE80211_AMPDU_TX_STOP_FLUSH:
6144 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
6145 case IEEE80211_AMPDU_TX_OPERATIONAL:
6146 /* Firmware offloads Tx aggregation entirely so deny mac80211
6147 * Tx aggregation requests.
6148 */
6149 return -EOPNOTSUPP;
6150 }
6151
6152 return -EINVAL;
6153}
6154
Michal Kazior500ff9f2015-03-31 10:26:21 +00006155static void
Michal Kaziord7bf4b42015-06-03 12:16:54 +02006156ath10k_mac_update_rx_channel(struct ath10k *ar,
6157 struct ieee80211_chanctx_conf *ctx,
6158 struct ieee80211_vif_chanctx_switch *vifs,
6159 int n_vifs)
Michal Kazior500ff9f2015-03-31 10:26:21 +00006160{
6161 struct cfg80211_chan_def *def = NULL;
6162
6163 /* Both locks are required because ar->rx_channel is modified. This
6164 * allows readers to hold either lock.
6165 */
6166 lockdep_assert_held(&ar->conf_mutex);
6167 lockdep_assert_held(&ar->data_lock);
6168
Michal Kaziord7bf4b42015-06-03 12:16:54 +02006169 WARN_ON(ctx && vifs);
6170 WARN_ON(vifs && n_vifs != 1);
6171
Michal Kazior500ff9f2015-03-31 10:26:21 +00006172 /* FIXME: Sort of an optimization and a workaround. Peers and vifs are
6173 * on a linked list now. Doing a lookup peer -> vif -> chanctx for each
6174 * ppdu on Rx may reduce performance on low-end systems. It should be
6175 * possible to make tables/hashmaps to speed the lookup up (be vary of
6176 * cpu data cache lines though regarding sizes) but to keep the initial
6177 * implementation simple and less intrusive fallback to the slow lookup
6178 * only for multi-channel cases. Single-channel cases will remain to
6179 * use the old channel derival and thus performance should not be
6180 * affected much.
6181 */
6182 rcu_read_lock();
Michal Kaziord7bf4b42015-06-03 12:16:54 +02006183 if (!ctx && ath10k_mac_num_chanctxs(ar) == 1) {
Michal Kazior500ff9f2015-03-31 10:26:21 +00006184 ieee80211_iter_chan_contexts_atomic(ar->hw,
6185 ath10k_mac_get_any_chandef_iter,
6186 &def);
Michal Kaziord7bf4b42015-06-03 12:16:54 +02006187
6188 if (vifs)
6189 def = &vifs[0].new_ctx->def;
6190
Michal Kazior500ff9f2015-03-31 10:26:21 +00006191 ar->rx_channel = def->chan;
Michal Kaziord7bf4b42015-06-03 12:16:54 +02006192 } else if (ctx && ath10k_mac_num_chanctxs(ar) == 0) {
6193 ar->rx_channel = ctx->def.chan;
Michal Kazior500ff9f2015-03-31 10:26:21 +00006194 } else {
6195 ar->rx_channel = NULL;
6196 }
6197 rcu_read_unlock();
6198}
6199
Michal Kazior500ff9f2015-03-31 10:26:21 +00006200static int
6201ath10k_mac_op_add_chanctx(struct ieee80211_hw *hw,
6202 struct ieee80211_chanctx_conf *ctx)
6203{
6204 struct ath10k *ar = hw->priv;
Michal Kazior500ff9f2015-03-31 10:26:21 +00006205
6206 ath10k_dbg(ar, ATH10K_DBG_MAC,
6207 "mac chanctx add freq %hu width %d ptr %p\n",
6208 ctx->def.chan->center_freq, ctx->def.width, ctx);
6209
6210 mutex_lock(&ar->conf_mutex);
6211
6212 spin_lock_bh(&ar->data_lock);
Michal Kaziord7bf4b42015-06-03 12:16:54 +02006213 ath10k_mac_update_rx_channel(ar, ctx, NULL, 0);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006214 spin_unlock_bh(&ar->data_lock);
6215
6216 ath10k_recalc_radar_detection(ar);
6217 ath10k_monitor_recalc(ar);
6218
6219 mutex_unlock(&ar->conf_mutex);
6220
6221 return 0;
6222}
6223
6224static void
6225ath10k_mac_op_remove_chanctx(struct ieee80211_hw *hw,
6226 struct ieee80211_chanctx_conf *ctx)
6227{
6228 struct ath10k *ar = hw->priv;
6229
6230 ath10k_dbg(ar, ATH10K_DBG_MAC,
6231 "mac chanctx remove freq %hu width %d ptr %p\n",
6232 ctx->def.chan->center_freq, ctx->def.width, ctx);
6233
6234 mutex_lock(&ar->conf_mutex);
6235
6236 spin_lock_bh(&ar->data_lock);
Michal Kaziord7bf4b42015-06-03 12:16:54 +02006237 ath10k_mac_update_rx_channel(ar, NULL, NULL, 0);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006238 spin_unlock_bh(&ar->data_lock);
6239
6240 ath10k_recalc_radar_detection(ar);
6241 ath10k_monitor_recalc(ar);
6242
6243 mutex_unlock(&ar->conf_mutex);
6244}
6245
6246static void
6247ath10k_mac_op_change_chanctx(struct ieee80211_hw *hw,
6248 struct ieee80211_chanctx_conf *ctx,
6249 u32 changed)
6250{
6251 struct ath10k *ar = hw->priv;
Michal Kazior500ff9f2015-03-31 10:26:21 +00006252
6253 mutex_lock(&ar->conf_mutex);
6254
6255 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior089ab7a2015-06-03 12:16:55 +02006256 "mac chanctx change freq %hu width %d ptr %p changed %x\n",
6257 ctx->def.chan->center_freq, ctx->def.width, ctx, changed);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006258
6259 /* This shouldn't really happen because channel switching should use
6260 * switch_vif_chanctx().
6261 */
6262 if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL))
6263 goto unlock;
6264
Michal Kazior500ff9f2015-03-31 10:26:21 +00006265 ath10k_recalc_radar_detection(ar);
6266
6267 /* FIXME: How to configure Rx chains properly? */
6268
6269 /* No other actions are actually necessary. Firmware maintains channel
6270 * definitions per vdev internally and there's no host-side channel
6271 * context abstraction to configure, e.g. channel width.
6272 */
6273
6274unlock:
6275 mutex_unlock(&ar->conf_mutex);
6276}
6277
6278static int
6279ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
6280 struct ieee80211_vif *vif,
6281 struct ieee80211_chanctx_conf *ctx)
6282{
6283 struct ath10k *ar = hw->priv;
Michal Kazior500ff9f2015-03-31 10:26:21 +00006284 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6285 int ret;
6286
6287 mutex_lock(&ar->conf_mutex);
6288
6289 ath10k_dbg(ar, ATH10K_DBG_MAC,
6290 "mac chanctx assign ptr %p vdev_id %i\n",
6291 ctx, arvif->vdev_id);
6292
6293 if (WARN_ON(arvif->is_started)) {
6294 mutex_unlock(&ar->conf_mutex);
6295 return -EBUSY;
6296 }
6297
Michal Kazior089ab7a2015-06-03 12:16:55 +02006298 ret = ath10k_vdev_start(arvif, &ctx->def);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006299 if (ret) {
6300 ath10k_warn(ar, "failed to start vdev %i addr %pM on freq %d: %d\n",
6301 arvif->vdev_id, vif->addr,
Michal Kazior089ab7a2015-06-03 12:16:55 +02006302 ctx->def.chan->center_freq, ret);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006303 goto err;
6304 }
6305
6306 arvif->is_started = true;
6307
Michal Kaziorf23e587e2015-07-09 13:08:37 +02006308 ret = ath10k_mac_vif_setup_ps(arvif);
6309 if (ret) {
6310 ath10k_warn(ar, "failed to update vdev %i ps: %d\n",
6311 arvif->vdev_id, ret);
6312 goto err_stop;
6313 }
6314
Michal Kazior500ff9f2015-03-31 10:26:21 +00006315 if (vif->type == NL80211_IFTYPE_MONITOR) {
6316 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, 0, vif->addr);
6317 if (ret) {
6318 ath10k_warn(ar, "failed to up monitor vdev %i: %d\n",
6319 arvif->vdev_id, ret);
6320 goto err_stop;
6321 }
6322
6323 arvif->is_up = true;
6324 }
6325
6326 mutex_unlock(&ar->conf_mutex);
6327 return 0;
6328
6329err_stop:
6330 ath10k_vdev_stop(arvif);
6331 arvif->is_started = false;
Michal Kaziorf23e587e2015-07-09 13:08:37 +02006332 ath10k_mac_vif_setup_ps(arvif);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006333
6334err:
6335 mutex_unlock(&ar->conf_mutex);
6336 return ret;
6337}
6338
6339static void
6340ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
6341 struct ieee80211_vif *vif,
6342 struct ieee80211_chanctx_conf *ctx)
6343{
6344 struct ath10k *ar = hw->priv;
6345 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6346 int ret;
6347
6348 mutex_lock(&ar->conf_mutex);
6349
6350 ath10k_dbg(ar, ATH10K_DBG_MAC,
6351 "mac chanctx unassign ptr %p vdev_id %i\n",
6352 ctx, arvif->vdev_id);
6353
6354 WARN_ON(!arvif->is_started);
6355
6356 if (vif->type == NL80211_IFTYPE_MONITOR) {
6357 WARN_ON(!arvif->is_up);
6358
6359 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
6360 if (ret)
6361 ath10k_warn(ar, "failed to down monitor vdev %i: %d\n",
6362 arvif->vdev_id, ret);
6363
6364 arvif->is_up = false;
6365 }
6366
6367 ret = ath10k_vdev_stop(arvif);
6368 if (ret)
6369 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
6370 arvif->vdev_id, ret);
6371
6372 arvif->is_started = false;
6373
6374 mutex_unlock(&ar->conf_mutex);
6375}
6376
6377static int
6378ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw,
6379 struct ieee80211_vif_chanctx_switch *vifs,
6380 int n_vifs,
6381 enum ieee80211_chanctx_switch_mode mode)
6382{
6383 struct ath10k *ar = hw->priv;
6384 struct ath10k_vif *arvif;
Michal Kazior0e6eb412015-06-03 12:16:56 +02006385 int ret;
Michal Kazior500ff9f2015-03-31 10:26:21 +00006386 int i;
6387
6388 mutex_lock(&ar->conf_mutex);
6389
6390 ath10k_dbg(ar, ATH10K_DBG_MAC,
6391 "mac chanctx switch n_vifs %d mode %d\n",
6392 n_vifs, mode);
6393
Michal Kazior0e6eb412015-06-03 12:16:56 +02006394 /* First stop monitor interface. Some FW versions crash if there's a
6395 * lone monitor interface.
6396 */
6397 if (ar->monitor_started)
6398 ath10k_monitor_stop(ar);
6399
Michal Kazior500ff9f2015-03-31 10:26:21 +00006400 for (i = 0; i < n_vifs; i++) {
6401 arvif = ath10k_vif_to_arvif(vifs[i].vif);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006402
6403 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior089ab7a2015-06-03 12:16:55 +02006404 "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d\n",
Michal Kazior500ff9f2015-03-31 10:26:21 +00006405 arvif->vdev_id,
6406 vifs[i].old_ctx->def.chan->center_freq,
6407 vifs[i].new_ctx->def.chan->center_freq,
6408 vifs[i].old_ctx->def.width,
Michal Kazior089ab7a2015-06-03 12:16:55 +02006409 vifs[i].new_ctx->def.width);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006410
Michal Kazior0e6eb412015-06-03 12:16:56 +02006411 if (WARN_ON(!arvif->is_started))
6412 continue;
6413
6414 if (WARN_ON(!arvif->is_up))
6415 continue;
6416
6417 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
6418 if (ret) {
6419 ath10k_warn(ar, "failed to down vdev %d: %d\n",
6420 arvif->vdev_id, ret);
6421 continue;
Michal Kazior500ff9f2015-03-31 10:26:21 +00006422 }
Michal Kazior500ff9f2015-03-31 10:26:21 +00006423 }
Michal Kazior0e6eb412015-06-03 12:16:56 +02006424
6425 /* All relevant vdevs are downed and associated channel resources
6426 * should be available for the channel switch now.
6427 */
6428
6429 spin_lock_bh(&ar->data_lock);
Michal Kaziord7bf4b42015-06-03 12:16:54 +02006430 ath10k_mac_update_rx_channel(ar, NULL, vifs, n_vifs);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006431 spin_unlock_bh(&ar->data_lock);
6432
Michal Kazior0e6eb412015-06-03 12:16:56 +02006433 for (i = 0; i < n_vifs; i++) {
6434 arvif = ath10k_vif_to_arvif(vifs[i].vif);
6435
6436 if (WARN_ON(!arvif->is_started))
6437 continue;
6438
6439 if (WARN_ON(!arvif->is_up))
6440 continue;
6441
6442 ret = ath10k_mac_setup_bcn_tmpl(arvif);
6443 if (ret)
6444 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
6445 ret);
6446
6447 ret = ath10k_mac_setup_prb_tmpl(arvif);
6448 if (ret)
6449 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
6450 ret);
6451
6452 ret = ath10k_vdev_restart(arvif, &vifs[i].new_ctx->def);
6453 if (ret) {
6454 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
6455 arvif->vdev_id, ret);
6456 continue;
6457 }
6458
6459 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
6460 arvif->bssid);
6461 if (ret) {
6462 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
6463 arvif->vdev_id, ret);
6464 continue;
6465 }
6466 }
6467
6468 ath10k_monitor_recalc(ar);
Michal Kazior500ff9f2015-03-31 10:26:21 +00006469
6470 mutex_unlock(&ar->conf_mutex);
6471 return 0;
6472}
6473
Kalle Valo5e3dd152013-06-12 20:52:10 +03006474static const struct ieee80211_ops ath10k_ops = {
6475 .tx = ath10k_tx,
6476 .start = ath10k_start,
6477 .stop = ath10k_stop,
6478 .config = ath10k_config,
6479 .add_interface = ath10k_add_interface,
6480 .remove_interface = ath10k_remove_interface,
6481 .configure_filter = ath10k_configure_filter,
6482 .bss_info_changed = ath10k_bss_info_changed,
6483 .hw_scan = ath10k_hw_scan,
6484 .cancel_hw_scan = ath10k_cancel_hw_scan,
6485 .set_key = ath10k_set_key,
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02006486 .set_default_unicast_key = ath10k_set_default_unicast_key,
Kalle Valo5e3dd152013-06-12 20:52:10 +03006487 .sta_state = ath10k_sta_state,
6488 .conf_tx = ath10k_conf_tx,
6489 .remain_on_channel = ath10k_remain_on_channel,
6490 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
6491 .set_rts_threshold = ath10k_set_rts_threshold,
Michal Kazior92092fe2015-08-03 11:16:43 +02006492 .set_frag_threshold = ath10k_mac_op_set_frag_threshold,
Kalle Valo5e3dd152013-06-12 20:52:10 +03006493 .flush = ath10k_flush,
6494 .tx_last_beacon = ath10k_tx_last_beacon,
Ben Greear46acf7b2014-05-16 17:15:38 +03006495 .set_antenna = ath10k_set_antenna,
6496 .get_antenna = ath10k_get_antenna,
Eliad Pellercf2c92d2014-11-04 11:43:54 +02006497 .reconfig_complete = ath10k_reconfig_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02006498 .get_survey = ath10k_get_survey,
Michal Kazior3ae54222015-03-31 10:49:20 +00006499 .set_bitrate_mask = ath10k_mac_op_set_bitrate_mask,
Michal Kazior9797feb2014-02-14 14:49:48 +01006500 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02006501 .get_tsf = ath10k_get_tsf,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02006502 .ampdu_action = ath10k_ampdu_action,
Ben Greear6cddcc72014-09-29 14:41:46 +03006503 .get_et_sset_count = ath10k_debug_get_et_sset_count,
6504 .get_et_stats = ath10k_debug_get_et_stats,
6505 .get_et_strings = ath10k_debug_get_et_strings,
Michal Kazior500ff9f2015-03-31 10:26:21 +00006506 .add_chanctx = ath10k_mac_op_add_chanctx,
6507 .remove_chanctx = ath10k_mac_op_remove_chanctx,
6508 .change_chanctx = ath10k_mac_op_change_chanctx,
6509 .assign_vif_chanctx = ath10k_mac_op_assign_vif_chanctx,
6510 .unassign_vif_chanctx = ath10k_mac_op_unassign_vif_chanctx,
6511 .switch_vif_chanctx = ath10k_mac_op_switch_vif_chanctx,
Kalle Valo43d2a302014-09-10 18:23:30 +03006512
6513 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
6514
Michal Kazior8cd13ca2013-07-16 09:38:54 +02006515#ifdef CONFIG_PM
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +02006516 .suspend = ath10k_wow_op_suspend,
6517 .resume = ath10k_wow_op_resume,
Michal Kazior8cd13ca2013-07-16 09:38:54 +02006518#endif
Rajkumar Manoharanf5045982015-01-12 14:07:27 +02006519#ifdef CONFIG_MAC80211_DEBUGFS
6520 .sta_add_debugfs = ath10k_sta_add_debugfs,
6521#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03006522};
6523
Kalle Valo5e3dd152013-06-12 20:52:10 +03006524#define CHAN2G(_channel, _freq, _flags) { \
6525 .band = IEEE80211_BAND_2GHZ, \
6526 .hw_value = (_channel), \
6527 .center_freq = (_freq), \
6528 .flags = (_flags), \
6529 .max_antenna_gain = 0, \
6530 .max_power = 30, \
6531}
6532
6533#define CHAN5G(_channel, _freq, _flags) { \
6534 .band = IEEE80211_BAND_5GHZ, \
6535 .hw_value = (_channel), \
6536 .center_freq = (_freq), \
6537 .flags = (_flags), \
6538 .max_antenna_gain = 0, \
6539 .max_power = 30, \
6540}
6541
6542static const struct ieee80211_channel ath10k_2ghz_channels[] = {
6543 CHAN2G(1, 2412, 0),
6544 CHAN2G(2, 2417, 0),
6545 CHAN2G(3, 2422, 0),
6546 CHAN2G(4, 2427, 0),
6547 CHAN2G(5, 2432, 0),
6548 CHAN2G(6, 2437, 0),
6549 CHAN2G(7, 2442, 0),
6550 CHAN2G(8, 2447, 0),
6551 CHAN2G(9, 2452, 0),
6552 CHAN2G(10, 2457, 0),
6553 CHAN2G(11, 2462, 0),
6554 CHAN2G(12, 2467, 0),
6555 CHAN2G(13, 2472, 0),
6556 CHAN2G(14, 2484, 0),
6557};
6558
6559static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02006560 CHAN5G(36, 5180, 0),
6561 CHAN5G(40, 5200, 0),
6562 CHAN5G(44, 5220, 0),
6563 CHAN5G(48, 5240, 0),
6564 CHAN5G(52, 5260, 0),
6565 CHAN5G(56, 5280, 0),
6566 CHAN5G(60, 5300, 0),
6567 CHAN5G(64, 5320, 0),
6568 CHAN5G(100, 5500, 0),
6569 CHAN5G(104, 5520, 0),
6570 CHAN5G(108, 5540, 0),
6571 CHAN5G(112, 5560, 0),
6572 CHAN5G(116, 5580, 0),
6573 CHAN5G(120, 5600, 0),
6574 CHAN5G(124, 5620, 0),
6575 CHAN5G(128, 5640, 0),
6576 CHAN5G(132, 5660, 0),
6577 CHAN5G(136, 5680, 0),
6578 CHAN5G(140, 5700, 0),
Peter Oh4a7898f2015-03-18 11:39:18 -07006579 CHAN5G(144, 5720, 0),
Michal Kazior429ff562013-06-26 08:54:54 +02006580 CHAN5G(149, 5745, 0),
6581 CHAN5G(153, 5765, 0),
6582 CHAN5G(157, 5785, 0),
6583 CHAN5G(161, 5805, 0),
6584 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03006585};
6586
Michal Kaziore7b54192014-08-07 11:03:27 +02006587struct ath10k *ath10k_mac_create(size_t priv_size)
Kalle Valo5e3dd152013-06-12 20:52:10 +03006588{
6589 struct ieee80211_hw *hw;
6590 struct ath10k *ar;
6591
Michal Kaziore7b54192014-08-07 11:03:27 +02006592 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006593 if (!hw)
6594 return NULL;
6595
6596 ar = hw->priv;
6597 ar->hw = hw;
6598
6599 return ar;
6600}
6601
6602void ath10k_mac_destroy(struct ath10k *ar)
6603{
6604 ieee80211_free_hw(ar->hw);
6605}
6606
6607static const struct ieee80211_iface_limit ath10k_if_limits[] = {
6608 {
6609 .max = 8,
6610 .types = BIT(NL80211_IFTYPE_STATION)
6611 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02006612 },
6613 {
6614 .max = 3,
6615 .types = BIT(NL80211_IFTYPE_P2P_GO)
6616 },
6617 {
Michal Kazior75d2bd42014-12-12 12:41:39 +01006618 .max = 1,
6619 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
6620 },
6621 {
Michal Kaziord531cb82013-07-31 10:55:13 +02006622 .max = 7,
6623 .types = BIT(NL80211_IFTYPE_AP)
6624 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03006625};
6626
Bartosz Markowskif2595092013-12-10 16:20:39 +01006627static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006628 {
6629 .max = 8,
6630 .types = BIT(NL80211_IFTYPE_AP)
6631 },
6632};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006633
6634static const struct ieee80211_iface_combination ath10k_if_comb[] = {
6635 {
6636 .limits = ath10k_if_limits,
6637 .n_limits = ARRAY_SIZE(ath10k_if_limits),
6638 .max_interfaces = 8,
6639 .num_different_channels = 1,
6640 .beacon_int_infra_match = true,
6641 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01006642};
6643
6644static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006645 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01006646 .limits = ath10k_10x_if_limits,
6647 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006648 .max_interfaces = 8,
6649 .num_different_channels = 1,
6650 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01006651#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006652 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
6653 BIT(NL80211_CHAN_WIDTH_20) |
6654 BIT(NL80211_CHAN_WIDTH_40) |
6655 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02006656#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01006657 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03006658};
6659
Michal Kaziorcf327842015-03-31 10:26:25 +00006660static const struct ieee80211_iface_limit ath10k_tlv_if_limit[] = {
6661 {
6662 .max = 2,
Michal Kaziored25b112015-07-09 13:08:39 +02006663 .types = BIT(NL80211_IFTYPE_STATION),
6664 },
6665 {
6666 .max = 2,
6667 .types = BIT(NL80211_IFTYPE_AP) |
Michal Kaziorcf327842015-03-31 10:26:25 +00006668 BIT(NL80211_IFTYPE_P2P_CLIENT) |
6669 BIT(NL80211_IFTYPE_P2P_GO),
6670 },
6671 {
6672 .max = 1,
6673 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
6674 },
6675};
6676
Michal Kaziored25b112015-07-09 13:08:39 +02006677static const struct ieee80211_iface_limit ath10k_tlv_qcs_if_limit[] = {
6678 {
6679 .max = 2,
6680 .types = BIT(NL80211_IFTYPE_STATION),
6681 },
6682 {
6683 .max = 2,
6684 .types = BIT(NL80211_IFTYPE_P2P_CLIENT),
6685 },
6686 {
6687 .max = 1,
6688 .types = BIT(NL80211_IFTYPE_AP) |
6689 BIT(NL80211_IFTYPE_P2P_GO),
6690 },
6691 {
6692 .max = 1,
6693 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
6694 },
6695};
6696
Michal Kaziorcf327842015-03-31 10:26:25 +00006697static const struct ieee80211_iface_limit ath10k_tlv_if_limit_ibss[] = {
6698 {
6699 .max = 1,
6700 .types = BIT(NL80211_IFTYPE_STATION),
6701 },
6702 {
6703 .max = 1,
6704 .types = BIT(NL80211_IFTYPE_ADHOC),
6705 },
6706};
6707
6708/* FIXME: This is not thouroughly tested. These combinations may over- or
6709 * underestimate hw/fw capabilities.
6710 */
6711static struct ieee80211_iface_combination ath10k_tlv_if_comb[] = {
6712 {
6713 .limits = ath10k_tlv_if_limit,
6714 .num_different_channels = 1,
Michal Kaziored25b112015-07-09 13:08:39 +02006715 .max_interfaces = 4,
Michal Kaziorcf327842015-03-31 10:26:25 +00006716 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
6717 },
6718 {
6719 .limits = ath10k_tlv_if_limit_ibss,
6720 .num_different_channels = 1,
6721 .max_interfaces = 2,
6722 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
6723 },
6724};
6725
6726static struct ieee80211_iface_combination ath10k_tlv_qcs_if_comb[] = {
6727 {
6728 .limits = ath10k_tlv_if_limit,
Michal Kaziored25b112015-07-09 13:08:39 +02006729 .num_different_channels = 1,
6730 .max_interfaces = 4,
Michal Kaziorcf327842015-03-31 10:26:25 +00006731 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
6732 },
6733 {
Michal Kaziored25b112015-07-09 13:08:39 +02006734 .limits = ath10k_tlv_qcs_if_limit,
6735 .num_different_channels = 2,
6736 .max_interfaces = 4,
6737 .n_limits = ARRAY_SIZE(ath10k_tlv_qcs_if_limit),
6738 },
6739 {
Michal Kaziorcf327842015-03-31 10:26:25 +00006740 .limits = ath10k_tlv_if_limit_ibss,
6741 .num_different_channels = 1,
6742 .max_interfaces = 2,
6743 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
6744 },
6745};
6746
Raja Manicf36fef2015-06-22 20:22:25 +05306747static const struct ieee80211_iface_limit ath10k_10_4_if_limits[] = {
6748 {
6749 .max = 1,
6750 .types = BIT(NL80211_IFTYPE_STATION),
6751 },
6752 {
6753 .max = 16,
6754 .types = BIT(NL80211_IFTYPE_AP)
6755 },
6756};
6757
6758static const struct ieee80211_iface_combination ath10k_10_4_if_comb[] = {
6759 {
6760 .limits = ath10k_10_4_if_limits,
6761 .n_limits = ARRAY_SIZE(ath10k_10_4_if_limits),
6762 .max_interfaces = 16,
6763 .num_different_channels = 1,
6764 .beacon_int_infra_match = true,
6765#ifdef CONFIG_ATH10K_DFS_CERTIFIED
6766 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
6767 BIT(NL80211_CHAN_WIDTH_20) |
6768 BIT(NL80211_CHAN_WIDTH_40) |
6769 BIT(NL80211_CHAN_WIDTH_80),
6770#endif
6771 },
6772};
6773
Kalle Valo5e3dd152013-06-12 20:52:10 +03006774static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
6775{
6776 struct ieee80211_sta_vht_cap vht_cap = {0};
6777 u16 mcs_map;
Michal Kaziorbc657a362015-02-26 11:11:22 +01006778 u32 val;
Michal Kazior8865bee42013-07-24 12:36:46 +02006779 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006780
6781 vht_cap.vht_supported = 1;
6782 vht_cap.cap = ar->vht_cap_info;
6783
Michal Kaziorbc657a362015-02-26 11:11:22 +01006784 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
6785 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
6786 val = ar->num_rf_chains - 1;
6787 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
6788 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
6789
6790 vht_cap.cap |= val;
6791 }
6792
6793 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
6794 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
6795 val = ar->num_rf_chains - 1;
6796 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
6797 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
6798
6799 vht_cap.cap |= val;
6800 }
6801
Michal Kazior8865bee42013-07-24 12:36:46 +02006802 mcs_map = 0;
6803 for (i = 0; i < 8; i++) {
6804 if (i < ar->num_rf_chains)
6805 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
6806 else
6807 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
6808 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03006809
6810 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
6811 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
6812
6813 return vht_cap;
6814}
6815
6816static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
6817{
6818 int i;
6819 struct ieee80211_sta_ht_cap ht_cap = {0};
6820
6821 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
6822 return ht_cap;
6823
6824 ht_cap.ht_supported = 1;
6825 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
6826 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
6827 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
6828 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
6829 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
6830
6831 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
6832 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
6833
6834 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
6835 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
6836
6837 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
6838 u32 smps;
6839
6840 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
6841 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
6842
6843 ht_cap.cap |= smps;
6844 }
6845
6846 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
6847 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
6848
6849 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
6850 u32 stbc;
6851
6852 stbc = ar->ht_cap_info;
6853 stbc &= WMI_HT_CAP_RX_STBC;
6854 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
6855 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
6856 stbc &= IEEE80211_HT_CAP_RX_STBC;
6857
6858 ht_cap.cap |= stbc;
6859 }
6860
6861 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
6862 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
6863
6864 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
6865 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
6866
6867 /* max AMSDU is implicitly taken from vht_cap_info */
6868 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
6869 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
6870
Michal Kazior8865bee42013-07-24 12:36:46 +02006871 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03006872 ht_cap.mcs.rx_mask[i] = 0xFF;
6873
6874 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
6875
6876 return ht_cap;
6877}
6878
Kalle Valo5e3dd152013-06-12 20:52:10 +03006879static void ath10k_get_arvif_iter(void *data, u8 *mac,
6880 struct ieee80211_vif *vif)
6881{
6882 struct ath10k_vif_iter *arvif_iter = data;
6883 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6884
6885 if (arvif->vdev_id == arvif_iter->vdev_id)
6886 arvif_iter->arvif = arvif;
6887}
6888
6889struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
6890{
6891 struct ath10k_vif_iter arvif_iter;
6892 u32 flags;
6893
6894 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
6895 arvif_iter.vdev_id = vdev_id;
6896
6897 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
6898 ieee80211_iterate_active_interfaces_atomic(ar->hw,
6899 flags,
6900 ath10k_get_arvif_iter,
6901 &arvif_iter);
6902 if (!arvif_iter.arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02006903 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006904 return NULL;
6905 }
6906
6907 return arvif_iter.arvif;
6908}
6909
6910int ath10k_mac_register(struct ath10k *ar)
6911{
Johannes Berg3cb10942015-01-22 21:38:45 +01006912 static const u32 cipher_suites[] = {
6913 WLAN_CIPHER_SUITE_WEP40,
6914 WLAN_CIPHER_SUITE_WEP104,
6915 WLAN_CIPHER_SUITE_TKIP,
6916 WLAN_CIPHER_SUITE_CCMP,
6917 WLAN_CIPHER_SUITE_AES_CMAC,
6918 };
Kalle Valo5e3dd152013-06-12 20:52:10 +03006919 struct ieee80211_supported_band *band;
6920 struct ieee80211_sta_vht_cap vht_cap;
6921 struct ieee80211_sta_ht_cap ht_cap;
6922 void *channels;
6923 int ret;
6924
6925 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
6926
6927 SET_IEEE80211_DEV(ar->hw, ar->dev);
6928
6929 ht_cap = ath10k_get_ht_cap(ar);
6930 vht_cap = ath10k_create_vht_cap(ar);
6931
Michal Kaziorc94aa7e2015-03-24 12:38:11 +00006932 BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels) +
6933 ARRAY_SIZE(ath10k_5ghz_channels)) !=
6934 ATH10K_NUM_CHANS);
6935
Kalle Valo5e3dd152013-06-12 20:52:10 +03006936 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
6937 channels = kmemdup(ath10k_2ghz_channels,
6938 sizeof(ath10k_2ghz_channels),
6939 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02006940 if (!channels) {
6941 ret = -ENOMEM;
6942 goto err_free;
6943 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03006944
6945 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
6946 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
6947 band->channels = channels;
6948 band->n_bitrates = ath10k_g_rates_size;
6949 band->bitrates = ath10k_g_rates;
6950 band->ht_cap = ht_cap;
6951
Yanbo Lid68bb122015-01-23 08:18:20 +08006952 /* Enable the VHT support at 2.4 GHz */
6953 band->vht_cap = vht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006954
6955 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
6956 }
6957
6958 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
6959 channels = kmemdup(ath10k_5ghz_channels,
6960 sizeof(ath10k_5ghz_channels),
6961 GFP_KERNEL);
6962 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02006963 ret = -ENOMEM;
6964 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006965 }
6966
6967 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
6968 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
6969 band->channels = channels;
6970 band->n_bitrates = ath10k_a_rates_size;
6971 band->bitrates = ath10k_a_rates;
6972 band->ht_cap = ht_cap;
6973 band->vht_cap = vht_cap;
6974 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
6975 }
6976
6977 ar->hw->wiphy->interface_modes =
6978 BIT(NL80211_IFTYPE_STATION) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01006979 BIT(NL80211_IFTYPE_AP);
6980
Ben Greear46acf7b2014-05-16 17:15:38 +03006981 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
6982 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
6983
Bartosz Markowskid3541812013-12-10 16:20:40 +01006984 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
6985 ar->hw->wiphy->interface_modes |=
Michal Kazior75d2bd42014-12-12 12:41:39 +01006986 BIT(NL80211_IFTYPE_P2P_DEVICE) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01006987 BIT(NL80211_IFTYPE_P2P_CLIENT) |
6988 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006989
Johannes Berg30686bf2015-06-02 21:39:54 +02006990 ieee80211_hw_set(ar->hw, SIGNAL_DBM);
6991 ieee80211_hw_set(ar->hw, SUPPORTS_PS);
6992 ieee80211_hw_set(ar->hw, SUPPORTS_DYNAMIC_PS);
6993 ieee80211_hw_set(ar->hw, MFP_CAPABLE);
6994 ieee80211_hw_set(ar->hw, REPORTS_TX_ACK_STATUS);
6995 ieee80211_hw_set(ar->hw, HAS_RATE_CONTROL);
6996 ieee80211_hw_set(ar->hw, AP_LINK_PS);
6997 ieee80211_hw_set(ar->hw, SPECTRUM_MGMT);
Johannes Berg30686bf2015-06-02 21:39:54 +02006998 ieee80211_hw_set(ar->hw, SUPPORT_FAST_XMIT);
6999 ieee80211_hw_set(ar->hw, CONNECTION_MONITOR);
7000 ieee80211_hw_set(ar->hw, SUPPORTS_PER_STA_GTK);
7001 ieee80211_hw_set(ar->hw, WANT_MONITOR_VIF);
7002 ieee80211_hw_set(ar->hw, CHANCTX_STA_CSA);
7003 ieee80211_hw_set(ar->hw, QUEUE_CONTROL);
Kalle Valo5e3dd152013-06-12 20:52:10 +03007004
David Liuccec9032015-07-24 20:25:32 +03007005 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
7006 ieee80211_hw_set(ar->hw, SW_CRYPTO_CONTROL);
7007
Eliad Peller0d8614b2014-09-10 14:07:36 +03007008 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
Janusz Dziedzic0cd9bc12015-04-10 13:23:23 +00007009 ar->hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
Eliad Peller0d8614b2014-09-10 14:07:36 +03007010
Kalle Valo5e3dd152013-06-12 20:52:10 +03007011 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
Eliad Peller0d8614b2014-09-10 14:07:36 +03007012 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03007013
7014 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
Johannes Berg30686bf2015-06-02 21:39:54 +02007015 ieee80211_hw_set(ar->hw, AMPDU_AGGREGATION);
7016 ieee80211_hw_set(ar->hw, TX_AMPDU_SETUP_IN_HW);
Kalle Valo5e3dd152013-06-12 20:52:10 +03007017 }
7018
7019 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
7020 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
7021
7022 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01007023 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03007024
Kalle Valo5e3dd152013-06-12 20:52:10 +03007025 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
7026
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02007027 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
7028 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
7029
7030 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
7031 * that userspace (e.g. wpa_supplicant/hostapd) can generate
7032 * correct Probe Responses. This is more of a hack advert..
7033 */
7034 ar->hw->wiphy->probe_resp_offload |=
7035 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
7036 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
7037 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
7038 }
7039
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03007040 if (test_bit(WMI_SERVICE_TDLS, ar->wmi.svc_map))
7041 ar->hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
7042
Kalle Valo5e3dd152013-06-12 20:52:10 +03007043 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01007044 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03007045 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
7046
7047 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
Rajkumar Manoharan78157a12014-11-17 16:44:15 +02007048 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
7049
Janusz.Dziedzic@tieto.com37a0b392015-03-12 13:11:41 +01007050 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
7051
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +02007052 ret = ath10k_wow_init(ar);
7053 if (ret) {
7054 ath10k_warn(ar, "failed to init wow: %d\n", ret);
7055 goto err_free;
7056 }
7057
Janusz Dziedzicc7025342015-06-15 14:46:41 +03007058 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
7059
Kalle Valo5e3dd152013-06-12 20:52:10 +03007060 /*
7061 * on LL hardware queues are managed entirely by the FW
7062 * so we only advertise to mac we can do the queues thing
7063 */
Michal Kazior96d828d2015-03-31 10:26:23 +00007064 ar->hw->queues = IEEE80211_MAX_QUEUES;
7065
7066 /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is
7067 * something that vdev_ids can't reach so that we don't stop the queue
7068 * accidentally.
7069 */
7070 ar->hw->offchannel_tx_hw_queue = IEEE80211_MAX_QUEUES - 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03007071
Kalle Valo5cc7caf2014-12-17 12:20:54 +02007072 switch (ar->wmi.op_version) {
7073 case ATH10K_FW_WMI_OP_VERSION_MAIN:
Bartosz Markowskif2595092013-12-10 16:20:39 +01007074 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
7075 ar->hw->wiphy->n_iface_combinations =
7076 ARRAY_SIZE(ath10k_if_comb);
Michal Kaziorcf850d12014-07-24 20:07:00 +03007077 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
Kalle Valo5cc7caf2014-12-17 12:20:54 +02007078 break;
Michal Kaziorcf327842015-03-31 10:26:25 +00007079 case ATH10K_FW_WMI_OP_VERSION_TLV:
7080 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
7081 ar->hw->wiphy->iface_combinations =
7082 ath10k_tlv_qcs_if_comb;
7083 ar->hw->wiphy->n_iface_combinations =
7084 ARRAY_SIZE(ath10k_tlv_qcs_if_comb);
7085 } else {
7086 ar->hw->wiphy->iface_combinations = ath10k_tlv_if_comb;
7087 ar->hw->wiphy->n_iface_combinations =
7088 ARRAY_SIZE(ath10k_tlv_if_comb);
7089 }
7090 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
7091 break;
Kalle Valo5cc7caf2014-12-17 12:20:54 +02007092 case ATH10K_FW_WMI_OP_VERSION_10_1:
7093 case ATH10K_FW_WMI_OP_VERSION_10_2:
Rajkumar Manoharan4a16fbe2014-12-17 12:21:12 +02007094 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
Kalle Valo5cc7caf2014-12-17 12:20:54 +02007095 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
7096 ar->hw->wiphy->n_iface_combinations =
7097 ARRAY_SIZE(ath10k_10x_if_comb);
7098 break;
Raja Mani9bd21322015-06-22 20:10:09 +05307099 case ATH10K_FW_WMI_OP_VERSION_10_4:
Raja Manicf36fef2015-06-22 20:22:25 +05307100 ar->hw->wiphy->iface_combinations = ath10k_10_4_if_comb;
7101 ar->hw->wiphy->n_iface_combinations =
7102 ARRAY_SIZE(ath10k_10_4_if_comb);
Raja Mani9bd21322015-06-22 20:10:09 +05307103 break;
Kalle Valo5cc7caf2014-12-17 12:20:54 +02007104 case ATH10K_FW_WMI_OP_VERSION_UNSET:
7105 case ATH10K_FW_WMI_OP_VERSION_MAX:
7106 WARN_ON(1);
7107 ret = -EINVAL;
7108 goto err_free;
Bartosz Markowskif2595092013-12-10 16:20:39 +01007109 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03007110
David Liuccec9032015-07-24 20:25:32 +03007111 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
7112 ar->hw->netdev_features = NETIF_F_HW_CSUM;
Michal Kazior7c199992013-07-31 10:47:57 +02007113
Janusz Dziedzic9702c682013-11-20 09:59:41 +02007114 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
7115 /* Init ath dfs pattern detector */
7116 ar->ath_common.debug_mask = ATH_DBG_DFS;
7117 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
7118 NL80211_DFS_UNSET);
7119
7120 if (!ar->dfs_detector)
Michal Kazior7aa7a722014-08-25 12:09:38 +02007121 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02007122 }
7123
Kalle Valo5e3dd152013-06-12 20:52:10 +03007124 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
7125 ath10k_reg_notifier);
7126 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02007127 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02007128 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03007129 }
7130
Johannes Berg3cb10942015-01-22 21:38:45 +01007131 ar->hw->wiphy->cipher_suites = cipher_suites;
7132 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
7133
Kalle Valo5e3dd152013-06-12 20:52:10 +03007134 ret = ieee80211_register_hw(ar->hw);
7135 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02007136 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02007137 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03007138 }
7139
7140 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
7141 ret = regulatory_hint(ar->hw->wiphy,
7142 ar->ath_common.regulatory.alpha2);
7143 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02007144 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03007145 }
7146
7147 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02007148
7149err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03007150 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02007151err_free:
7152 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
7153 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
7154
Kalle Valo5e3dd152013-06-12 20:52:10 +03007155 return ret;
7156}
7157
7158void ath10k_mac_unregister(struct ath10k *ar)
7159{
7160 ieee80211_unregister_hw(ar->hw);
7161
Janusz Dziedzic9702c682013-11-20 09:59:41 +02007162 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
7163 ar->dfs_detector->exit(ar->dfs_detector);
7164
Kalle Valo5e3dd152013-06-12 20:52:10 +03007165 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
7166 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
7167
7168 SET_IEEE80211_DEV(ar->hw, NULL);
7169}