blob: 2134bb2c3adb5fcb29c5c21853f61748cb6ba47a [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"
31#include "wmi-ops.h"
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +020032#include "wow.h"
Kalle Valo5e3dd152013-06-12 20:52:10 +030033
Michal Kaziordcc33092015-03-30 09:51:54 +030034/*********/
35/* Rates */
36/*********/
37
Michal Kaziordcc33092015-03-30 09:51:54 +030038static struct ieee80211_rate ath10k_rates[] = {
Michal Kazior5528e032015-03-30 09:51:56 +030039 { .bitrate = 10,
40 .hw_value = ATH10K_HW_RATE_CCK_LP_1M },
41 { .bitrate = 20,
42 .hw_value = ATH10K_HW_RATE_CCK_LP_2M,
43 .hw_value_short = ATH10K_HW_RATE_CCK_SP_2M,
44 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
45 { .bitrate = 55,
46 .hw_value = ATH10K_HW_RATE_CCK_LP_5_5M,
47 .hw_value_short = ATH10K_HW_RATE_CCK_SP_5_5M,
48 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
49 { .bitrate = 110,
50 .hw_value = ATH10K_HW_RATE_CCK_LP_11M,
51 .hw_value_short = ATH10K_HW_RATE_CCK_SP_11M,
52 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
Michal Kazior5653b392015-03-30 09:51:54 +030053
Michal Kazioraf001482015-03-30 09:51:56 +030054 { .bitrate = 60, .hw_value = ATH10K_HW_RATE_OFDM_6M },
55 { .bitrate = 90, .hw_value = ATH10K_HW_RATE_OFDM_9M },
56 { .bitrate = 120, .hw_value = ATH10K_HW_RATE_OFDM_12M },
57 { .bitrate = 180, .hw_value = ATH10K_HW_RATE_OFDM_18M },
58 { .bitrate = 240, .hw_value = ATH10K_HW_RATE_OFDM_24M },
59 { .bitrate = 360, .hw_value = ATH10K_HW_RATE_OFDM_36M },
60 { .bitrate = 480, .hw_value = ATH10K_HW_RATE_OFDM_48M },
61 { .bitrate = 540, .hw_value = ATH10K_HW_RATE_OFDM_54M },
Michal Kaziordcc33092015-03-30 09:51:54 +030062};
63
Michal Kazior8d7aa6b2015-03-30 09:51:57 +030064#define ATH10K_MAC_FIRST_OFDM_RATE_IDX 4
65
66#define ath10k_a_rates (ath10k_rates + ATH10K_MAC_FIRST_OFDM_RATE_IDX)
67#define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - \
68 ATH10K_MAC_FIRST_OFDM_RATE_IDX)
Michal Kaziordcc33092015-03-30 09:51:54 +030069#define ath10k_g_rates (ath10k_rates + 0)
70#define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
71
Michal Kazior486017c2015-03-30 09:51:54 +030072static bool ath10k_mac_bitrate_is_cck(int bitrate)
73{
74 switch (bitrate) {
75 case 10:
76 case 20:
77 case 55:
78 case 110:
79 return true;
80 }
81
82 return false;
83}
84
85static u8 ath10k_mac_bitrate_to_rate(int bitrate)
86{
87 return DIV_ROUND_UP(bitrate, 5) |
88 (ath10k_mac_bitrate_is_cck(bitrate) ? BIT(7) : 0);
89}
90
Michal Kazior5528e032015-03-30 09:51:56 +030091u8 ath10k_mac_hw_rate_to_idx(const struct ieee80211_supported_band *sband,
92 u8 hw_rate)
93{
94 const struct ieee80211_rate *rate;
95 int i;
96
97 for (i = 0; i < sband->n_bitrates; i++) {
98 rate = &sband->bitrates[i];
99
100 if (rate->hw_value == hw_rate)
101 return i;
102 else if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE &&
103 rate->hw_value_short == hw_rate)
104 return i;
105 }
106
107 return 0;
108}
109
Michal Kazior01cebe12015-03-30 09:51:56 +0300110u8 ath10k_mac_bitrate_to_idx(const struct ieee80211_supported_band *sband,
111 u32 bitrate)
112{
113 int i;
114
115 for (i = 0; i < sband->n_bitrates; i++)
116 if (sband->bitrates[i].bitrate == bitrate)
117 return i;
118
119 return 0;
120}
121
Kalle Valo5e3dd152013-06-12 20:52:10 +0300122/**********/
123/* Crypto */
124/**********/
125
126static int ath10k_send_key(struct ath10k_vif *arvif,
127 struct ieee80211_key_conf *key,
128 enum set_key_cmd cmd,
Michal Kazior370e5672015-02-18 14:02:26 +0100129 const u8 *macaddr, u32 flags)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300130{
Michal Kazior7aa7a722014-08-25 12:09:38 +0200131 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300132 struct wmi_vdev_install_key_arg arg = {
133 .vdev_id = arvif->vdev_id,
134 .key_idx = key->keyidx,
135 .key_len = key->keylen,
136 .key_data = key->key,
Michal Kazior370e5672015-02-18 14:02:26 +0100137 .key_flags = flags,
Kalle Valo5e3dd152013-06-12 20:52:10 +0300138 .macaddr = macaddr,
139 };
140
Michal Kazior548db542013-07-05 16:15:15 +0300141 lockdep_assert_held(&arvif->ar->conf_mutex);
142
Kalle Valo5e3dd152013-06-12 20:52:10 +0300143 switch (key->cipher) {
144 case WLAN_CIPHER_SUITE_CCMP:
145 arg.key_cipher = WMI_CIPHER_AES_CCM;
Marek Kwaczynskie4e82e92015-01-24 12:14:53 +0200146 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300147 break;
148 case WLAN_CIPHER_SUITE_TKIP:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300149 arg.key_cipher = WMI_CIPHER_TKIP;
150 arg.key_txmic_len = 8;
151 arg.key_rxmic_len = 8;
152 break;
153 case WLAN_CIPHER_SUITE_WEP40:
154 case WLAN_CIPHER_SUITE_WEP104:
155 arg.key_cipher = WMI_CIPHER_WEP;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300156 break;
Johannes Berg3cb10942015-01-22 21:38:45 +0100157 case WLAN_CIPHER_SUITE_AES_CMAC:
Bartosz Markowskid7131c02015-03-10 14:32:19 +0100158 WARN_ON(1);
159 return -EINVAL;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300160 default:
Michal Kazior7aa7a722014-08-25 12:09:38 +0200161 ath10k_warn(ar, "cipher %d is not supported\n", key->cipher);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300162 return -EOPNOTSUPP;
163 }
164
165 if (cmd == DISABLE_KEY) {
166 arg.key_cipher = WMI_CIPHER_NONE;
167 arg.key_data = NULL;
168 }
169
170 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
171}
172
173static int ath10k_install_key(struct ath10k_vif *arvif,
174 struct ieee80211_key_conf *key,
175 enum set_key_cmd cmd,
Michal Kazior370e5672015-02-18 14:02:26 +0100176 const u8 *macaddr, u32 flags)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300177{
178 struct ath10k *ar = arvif->ar;
179 int ret;
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +0300180 unsigned long time_left;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300181
Michal Kazior548db542013-07-05 16:15:15 +0300182 lockdep_assert_held(&ar->conf_mutex);
183
Wolfram Sang16735d02013-11-14 14:32:02 -0800184 reinit_completion(&ar->install_key_done);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300185
Michal Kazior370e5672015-02-18 14:02:26 +0100186 ret = ath10k_send_key(arvif, key, cmd, macaddr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300187 if (ret)
188 return ret;
189
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +0300190 time_left = wait_for_completion_timeout(&ar->install_key_done, 3 * HZ);
191 if (time_left == 0)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300192 return -ETIMEDOUT;
193
194 return 0;
195}
196
197static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
198 const u8 *addr)
199{
200 struct ath10k *ar = arvif->ar;
201 struct ath10k_peer *peer;
202 int ret;
203 int i;
Michal Kazior370e5672015-02-18 14:02:26 +0100204 u32 flags;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300205
206 lockdep_assert_held(&ar->conf_mutex);
207
208 spin_lock_bh(&ar->data_lock);
209 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
210 spin_unlock_bh(&ar->data_lock);
211
212 if (!peer)
213 return -ENOENT;
214
215 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
216 if (arvif->wep_keys[i] == NULL)
217 continue;
Michal Kazior370e5672015-02-18 14:02:26 +0100218
219 flags = 0;
220 flags |= WMI_KEY_PAIRWISE;
221
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200222 /* set TX_USAGE flag for default key id */
223 if (arvif->def_wep_key_idx == i)
Michal Kazior370e5672015-02-18 14:02:26 +0100224 flags |= WMI_KEY_TX_USAGE;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300225
226 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
Michal Kazior370e5672015-02-18 14:02:26 +0100227 addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300228 if (ret)
229 return ret;
230
Sujith Manoharanae167132014-11-25 11:46:59 +0530231 spin_lock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300232 peer->keys[i] = arvif->wep_keys[i];
Sujith Manoharanae167132014-11-25 11:46:59 +0530233 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300234 }
235
236 return 0;
237}
238
239static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
240 const u8 *addr)
241{
242 struct ath10k *ar = arvif->ar;
243 struct ath10k_peer *peer;
244 int first_errno = 0;
245 int ret;
246 int i;
Michal Kazior370e5672015-02-18 14:02:26 +0100247 u32 flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300248
249 lockdep_assert_held(&ar->conf_mutex);
250
251 spin_lock_bh(&ar->data_lock);
252 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
253 spin_unlock_bh(&ar->data_lock);
254
255 if (!peer)
256 return -ENOENT;
257
258 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
259 if (peer->keys[i] == NULL)
260 continue;
261
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200262 /* key flags are not required to delete the key */
Kalle Valo5e3dd152013-06-12 20:52:10 +0300263 ret = ath10k_install_key(arvif, peer->keys[i],
Michal Kazior370e5672015-02-18 14:02:26 +0100264 DISABLE_KEY, addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300265 if (ret && first_errno == 0)
266 first_errno = ret;
267
268 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200269 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300270 i, ret);
271
Sujith Manoharanae167132014-11-25 11:46:59 +0530272 spin_lock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300273 peer->keys[i] = NULL;
Sujith Manoharanae167132014-11-25 11:46:59 +0530274 spin_unlock_bh(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300275 }
276
277 return first_errno;
278}
279
Sujith Manoharan504f6cd2014-11-25 11:46:58 +0530280bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr,
281 u8 keyidx)
282{
283 struct ath10k_peer *peer;
284 int i;
285
286 lockdep_assert_held(&ar->data_lock);
287
288 /* We don't know which vdev this peer belongs to,
289 * since WMI doesn't give us that information.
290 *
291 * FIXME: multi-bss needs to be handled.
292 */
293 peer = ath10k_peer_find(ar, 0, addr);
294 if (!peer)
295 return false;
296
297 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
298 if (peer->keys[i] && peer->keys[i]->keyidx == keyidx)
299 return true;
300 }
301
302 return false;
303}
304
Kalle Valo5e3dd152013-06-12 20:52:10 +0300305static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
306 struct ieee80211_key_conf *key)
307{
308 struct ath10k *ar = arvif->ar;
309 struct ath10k_peer *peer;
310 u8 addr[ETH_ALEN];
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 for (;;) {
319 /* since ath10k_install_key we can't hold data_lock all the
320 * time, so we try to remove the keys incrementally */
321 spin_lock_bh(&ar->data_lock);
322 i = 0;
323 list_for_each_entry(peer, &ar->peers, list) {
324 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
325 if (peer->keys[i] == key) {
Kalle Valob25f32c2014-09-14 12:50:49 +0300326 ether_addr_copy(addr, peer->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300327 peer->keys[i] = NULL;
328 break;
329 }
330 }
331
332 if (i < ARRAY_SIZE(peer->keys))
333 break;
334 }
335 spin_unlock_bh(&ar->data_lock);
336
337 if (i == ARRAY_SIZE(peer->keys))
338 break;
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +0200339 /* key flags are not required to delete the key */
Michal Kazior370e5672015-02-18 14:02:26 +0100340 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300341 if (ret && first_errno == 0)
342 first_errno = ret;
343
344 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200345 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +0200346 addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300347 }
348
349 return first_errno;
350}
351
Michal Kazior370e5672015-02-18 14:02:26 +0100352static int ath10k_mac_vif_sta_fix_wep_key(struct ath10k_vif *arvif)
353{
354 struct ath10k *ar = arvif->ar;
355 enum nl80211_iftype iftype = arvif->vif->type;
356 struct ieee80211_key_conf *key;
357 u32 flags = 0;
358 int num = 0;
359 int i;
360 int ret;
361
362 lockdep_assert_held(&ar->conf_mutex);
363
364 if (iftype != NL80211_IFTYPE_STATION)
365 return 0;
366
367 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
368 if (arvif->wep_keys[i]) {
369 key = arvif->wep_keys[i];
370 ++num;
371 }
372 }
373
374 if (num != 1)
375 return 0;
376
377 flags |= WMI_KEY_PAIRWISE;
378 flags |= WMI_KEY_TX_USAGE;
379
380 ret = ath10k_install_key(arvif, key, SET_KEY, arvif->bssid, flags);
381 if (ret) {
382 ath10k_warn(ar, "failed to install key %i on vdev %i: %d\n",
383 key->keyidx, arvif->vdev_id, ret);
384 return ret;
385 }
386
387 return 0;
388}
389
Michal Kaziorad325cb2015-02-18 14:02:27 +0100390static int ath10k_mac_vif_update_wep_key(struct ath10k_vif *arvif,
391 struct ieee80211_key_conf *key)
392{
393 struct ath10k *ar = arvif->ar;
394 struct ath10k_peer *peer;
395 int ret;
396
397 lockdep_assert_held(&ar->conf_mutex);
398
399 list_for_each_entry(peer, &ar->peers, list) {
400 if (!memcmp(peer->addr, arvif->vif->addr, ETH_ALEN))
401 continue;
402
403 if (!memcmp(peer->addr, arvif->bssid, ETH_ALEN))
404 continue;
405
406 if (peer->keys[key->keyidx] == key)
407 continue;
408
409 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vif vdev %i update key %i needs update\n",
410 arvif->vdev_id, key->keyidx);
411
412 ret = ath10k_install_peer_wep_keys(arvif, peer->addr);
413 if (ret) {
414 ath10k_warn(ar, "failed to update wep keys on vdev %i for peer %pM: %d\n",
415 arvif->vdev_id, peer->addr, ret);
416 return ret;
417 }
418 }
419
420 return 0;
421}
422
Kalle Valo5e3dd152013-06-12 20:52:10 +0300423/*********************/
424/* General utilities */
425/*********************/
426
427static inline enum wmi_phy_mode
428chan_to_phymode(const struct cfg80211_chan_def *chandef)
429{
430 enum wmi_phy_mode phymode = MODE_UNKNOWN;
431
432 switch (chandef->chan->band) {
433 case IEEE80211_BAND_2GHZ:
434 switch (chandef->width) {
435 case NL80211_CHAN_WIDTH_20_NOHT:
Peter Oh6faab122014-12-18 10:13:00 -0800436 if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM)
437 phymode = MODE_11B;
438 else
439 phymode = MODE_11G;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300440 break;
441 case NL80211_CHAN_WIDTH_20:
442 phymode = MODE_11NG_HT20;
443 break;
444 case NL80211_CHAN_WIDTH_40:
445 phymode = MODE_11NG_HT40;
446 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400447 case NL80211_CHAN_WIDTH_5:
448 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300449 case NL80211_CHAN_WIDTH_80:
450 case NL80211_CHAN_WIDTH_80P80:
451 case NL80211_CHAN_WIDTH_160:
452 phymode = MODE_UNKNOWN;
453 break;
454 }
455 break;
456 case IEEE80211_BAND_5GHZ:
457 switch (chandef->width) {
458 case NL80211_CHAN_WIDTH_20_NOHT:
459 phymode = MODE_11A;
460 break;
461 case NL80211_CHAN_WIDTH_20:
462 phymode = MODE_11NA_HT20;
463 break;
464 case NL80211_CHAN_WIDTH_40:
465 phymode = MODE_11NA_HT40;
466 break;
467 case NL80211_CHAN_WIDTH_80:
468 phymode = MODE_11AC_VHT80;
469 break;
John W. Linville0f817ed2013-06-27 13:50:09 -0400470 case NL80211_CHAN_WIDTH_5:
471 case NL80211_CHAN_WIDTH_10:
Kalle Valo5e3dd152013-06-12 20:52:10 +0300472 case NL80211_CHAN_WIDTH_80P80:
473 case NL80211_CHAN_WIDTH_160:
474 phymode = MODE_UNKNOWN;
475 break;
476 }
477 break;
478 default:
479 break;
480 }
481
482 WARN_ON(phymode == MODE_UNKNOWN);
483 return phymode;
484}
485
486static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
487{
488/*
489 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
490 * 0 for no restriction
491 * 1 for 1/4 us
492 * 2 for 1/2 us
493 * 3 for 1 us
494 * 4 for 2 us
495 * 5 for 4 us
496 * 6 for 8 us
497 * 7 for 16 us
498 */
499 switch (mpdudensity) {
500 case 0:
501 return 0;
502 case 1:
503 case 2:
504 case 3:
505 /* Our lower layer calculations limit our precision to
506 1 microsecond */
507 return 1;
508 case 4:
509 return 2;
510 case 5:
511 return 4;
512 case 6:
513 return 8;
514 case 7:
515 return 16;
516 default:
517 return 0;
518 }
519}
520
Marek Puzyniak7390ed32015-03-30 09:51:52 +0300521static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr,
522 enum wmi_peer_type peer_type)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300523{
524 int ret;
525
526 lockdep_assert_held(&ar->conf_mutex);
527
Michal Kaziorcfd10612014-11-25 15:16:05 +0100528 if (ar->num_peers >= ar->max_num_peers)
529 return -ENOBUFS;
530
Marek Puzyniak7390ed32015-03-30 09:51:52 +0300531 ret = ath10k_wmi_peer_create(ar, vdev_id, addr, peer_type);
Ben Greear479398b2013-11-04 09:19:34 -0800532 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200533 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200534 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300535 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800536 }
Kalle Valo5e3dd152013-06-12 20:52:10 +0300537
538 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
Ben Greear479398b2013-11-04 09:19:34 -0800539 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200540 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +0200541 addr, vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300542 return ret;
Ben Greear479398b2013-11-04 09:19:34 -0800543 }
Michal Kazior292a7532014-11-25 15:16:04 +0100544
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100545 ar->num_peers++;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300546
547 return 0;
548}
549
Kalle Valo5a13e762014-01-20 11:01:46 +0200550static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
551{
552 struct ath10k *ar = arvif->ar;
553 u32 param;
554 int ret;
555
556 param = ar->wmi.pdev_param->sta_kickout_th;
557 ret = ath10k_wmi_pdev_set_param(ar, param,
558 ATH10K_KICKOUT_THRESHOLD);
559 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200560 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200561 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200562 return ret;
563 }
564
565 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
566 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
567 ATH10K_KEEPALIVE_MIN_IDLE);
568 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200569 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200570 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200571 return ret;
572 }
573
574 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
575 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
576 ATH10K_KEEPALIVE_MAX_IDLE);
577 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200578 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200579 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200580 return ret;
581 }
582
583 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
584 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
585 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
586 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200587 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200588 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +0200589 return ret;
590 }
591
592 return 0;
593}
594
Vivek Natarajanacab6402014-11-26 09:06:12 +0200595static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
Michal Kazior424121c2013-07-22 14:13:31 +0200596{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200597 struct ath10k *ar = arvif->ar;
598 u32 vdev_param;
599
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200600 vdev_param = ar->wmi.vdev_param->rts_threshold;
601 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200602}
603
604static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
605{
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200606 struct ath10k *ar = arvif->ar;
607 u32 vdev_param;
608
Michal Kazior424121c2013-07-22 14:13:31 +0200609 if (value != 0xFFFFFFFF)
610 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
611 ATH10K_FRAGMT_THRESHOLD_MIN,
612 ATH10K_FRAGMT_THRESHOLD_MAX);
613
Bartosz Markowski6d1506e2013-09-26 17:47:15 +0200614 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
615 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
Michal Kazior424121c2013-07-22 14:13:31 +0200616}
617
Kalle Valo5e3dd152013-06-12 20:52:10 +0300618static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
619{
620 int ret;
621
622 lockdep_assert_held(&ar->conf_mutex);
623
624 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
625 if (ret)
626 return ret;
627
628 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
629 if (ret)
630 return ret;
631
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100632 ar->num_peers--;
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100633
Kalle Valo5e3dd152013-06-12 20:52:10 +0300634 return 0;
635}
636
637static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
638{
639 struct ath10k_peer *peer, *tmp;
640
641 lockdep_assert_held(&ar->conf_mutex);
642
643 spin_lock_bh(&ar->data_lock);
644 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
645 if (peer->vdev_id != vdev_id)
646 continue;
647
Michal Kazior7aa7a722014-08-25 12:09:38 +0200648 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300649 peer->addr, vdev_id);
650
651 list_del(&peer->list);
652 kfree(peer);
Bartosz Markowski0e759f32014-01-02 14:38:33 +0100653 ar->num_peers--;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300654 }
655 spin_unlock_bh(&ar->data_lock);
656}
657
Michal Kaziora96d7742013-07-16 09:38:56 +0200658static void ath10k_peer_cleanup_all(struct ath10k *ar)
659{
660 struct ath10k_peer *peer, *tmp;
661
662 lockdep_assert_held(&ar->conf_mutex);
663
664 spin_lock_bh(&ar->data_lock);
665 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
666 list_del(&peer->list);
667 kfree(peer);
668 }
669 spin_unlock_bh(&ar->data_lock);
Michal Kazior292a7532014-11-25 15:16:04 +0100670
671 ar->num_peers = 0;
Michal Kaziorcfd10612014-11-25 15:16:05 +0100672 ar->num_stations = 0;
Michal Kaziora96d7742013-07-16 09:38:56 +0200673}
674
Marek Puzyniak75d85fd2015-03-30 09:51:53 +0300675static int ath10k_mac_tdls_peer_update(struct ath10k *ar, u32 vdev_id,
676 struct ieee80211_sta *sta,
677 enum wmi_tdls_peer_state state)
678{
679 int ret;
680 struct wmi_tdls_peer_update_cmd_arg arg = {};
681 struct wmi_tdls_peer_capab_arg cap = {};
682 struct wmi_channel_arg chan_arg = {};
683
684 lockdep_assert_held(&ar->conf_mutex);
685
686 arg.vdev_id = vdev_id;
687 arg.peer_state = state;
688 ether_addr_copy(arg.addr, sta->addr);
689
690 cap.peer_max_sp = sta->max_sp;
691 cap.peer_uapsd_queues = sta->uapsd_queues;
692
693 if (state == WMI_TDLS_PEER_STATE_CONNECTED &&
694 !sta->tdls_initiator)
695 cap.is_peer_responder = 1;
696
697 ret = ath10k_wmi_tdls_peer_update(ar, &arg, &cap, &chan_arg);
698 if (ret) {
699 ath10k_warn(ar, "failed to update tdls peer %pM on vdev %i: %i\n",
700 arg.addr, vdev_id, ret);
701 return ret;
702 }
703
704 return 0;
705}
706
Kalle Valo5e3dd152013-06-12 20:52:10 +0300707/************************/
708/* Interface management */
709/************************/
710
Michal Kazior64badcb2014-09-18 11:18:02 +0300711void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
712{
713 struct ath10k *ar = arvif->ar;
714
715 lockdep_assert_held(&ar->data_lock);
716
717 if (!arvif->beacon)
718 return;
719
720 if (!arvif->beacon_buf)
721 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
722 arvif->beacon->len, DMA_TO_DEVICE);
723
Michal Kazioraf213192015-01-29 14:29:52 +0200724 if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED &&
725 arvif->beacon_state != ATH10K_BEACON_SENT))
726 return;
727
Michal Kazior64badcb2014-09-18 11:18:02 +0300728 dev_kfree_skb_any(arvif->beacon);
729
730 arvif->beacon = NULL;
Michal Kazioraf213192015-01-29 14:29:52 +0200731 arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
Michal Kazior64badcb2014-09-18 11:18:02 +0300732}
733
734static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
735{
736 struct ath10k *ar = arvif->ar;
737
738 lockdep_assert_held(&ar->data_lock);
739
740 ath10k_mac_vif_beacon_free(arvif);
741
742 if (arvif->beacon_buf) {
743 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
744 arvif->beacon_buf, arvif->beacon_paddr);
745 arvif->beacon_buf = NULL;
746 }
747}
748
Kalle Valo5e3dd152013-06-12 20:52:10 +0300749static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
750{
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +0300751 unsigned long time_left;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300752
Michal Kazior548db542013-07-05 16:15:15 +0300753 lockdep_assert_held(&ar->conf_mutex);
754
Michal Kazior7962b0d2014-10-28 10:34:38 +0100755 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
756 return -ESHUTDOWN;
757
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +0300758 time_left = wait_for_completion_timeout(&ar->vdev_setup_done,
759 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
760 if (time_left == 0)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300761 return -ETIMEDOUT;
762
763 return 0;
764}
765
Michal Kazior1bbc0972014-04-08 09:45:47 +0300766static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300767{
Michal Kaziorc930f742014-01-23 11:38:25 +0100768 struct cfg80211_chan_def *chandef = &ar->chandef;
769 struct ieee80211_channel *channel = chandef->chan;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300770 struct wmi_vdev_start_request_arg arg = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +0300771 int ret = 0;
772
773 lockdep_assert_held(&ar->conf_mutex);
774
Kalle Valo5e3dd152013-06-12 20:52:10 +0300775 arg.vdev_id = vdev_id;
776 arg.channel.freq = channel->center_freq;
Michal Kaziorc930f742014-01-23 11:38:25 +0100777 arg.channel.band_center_freq1 = chandef->center_freq1;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300778
779 /* TODO setup this dynamically, what in case we
780 don't have any vifs? */
Michal Kaziorc930f742014-01-23 11:38:25 +0100781 arg.channel.mode = chan_to_phymode(chandef);
Marek Puzyniake8a50f82013-11-20 09:59:47 +0200782 arg.channel.chan_radar =
783 !!(channel->flags & IEEE80211_CHAN_RADAR);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300784
Michal Kazior89c5c842013-10-23 04:02:13 -0700785 arg.channel.min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -0700786 arg.channel.max_power = channel->max_power * 2;
787 arg.channel.max_reg_power = channel->max_reg_power * 2;
788 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300789
Michal Kazior7962b0d2014-10-28 10:34:38 +0100790 reinit_completion(&ar->vdev_setup_done);
791
Kalle Valo5e3dd152013-06-12 20:52:10 +0300792 ret = ath10k_wmi_vdev_start(ar, &arg);
793 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200794 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200795 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300796 return ret;
797 }
798
799 ret = ath10k_vdev_setup_sync(ar);
800 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +0200801 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200802 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300803 return ret;
804 }
805
806 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
807 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200808 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200809 vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300810 goto vdev_stop;
811 }
812
813 ar->monitor_vdev_id = vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300814
Michal Kazior7aa7a722014-08-25 12:09:38 +0200815 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300816 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300817 return 0;
818
819vdev_stop:
820 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
821 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200822 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200823 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300824
825 return ret;
826}
827
Michal Kazior1bbc0972014-04-08 09:45:47 +0300828static int ath10k_monitor_vdev_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300829{
830 int ret = 0;
831
832 lockdep_assert_held(&ar->conf_mutex);
833
Marek Puzyniak52fa0192013-09-24 14:06:24 +0200834 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
835 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200836 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200837 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300838
Michal Kazior7962b0d2014-10-28 10:34:38 +0100839 reinit_completion(&ar->vdev_setup_done);
840
Kalle Valo5e3dd152013-06-12 20:52:10 +0300841 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
842 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +0200843 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200844 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300845
846 ret = ath10k_vdev_setup_sync(ar);
847 if (ret)
Ben Greear60028a82015-02-15 16:50:39 +0200848 ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200849 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300850
Michal Kazior7aa7a722014-08-25 12:09:38 +0200851 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
Michal Kazior1bbc0972014-04-08 09:45:47 +0300852 ar->monitor_vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300853 return ret;
854}
855
Michal Kazior1bbc0972014-04-08 09:45:47 +0300856static int ath10k_monitor_vdev_create(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300857{
858 int bit, ret = 0;
859
860 lockdep_assert_held(&ar->conf_mutex);
861
Ben Greeara9aefb32014-08-12 11:02:19 +0300862 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200863 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +0300864 return -ENOMEM;
865 }
866
Ben Greear16c11172014-09-23 14:17:16 -0700867 bit = __ffs64(ar->free_vdev_map);
Ben Greeara9aefb32014-08-12 11:02:19 +0300868
Ben Greear16c11172014-09-23 14:17:16 -0700869 ar->monitor_vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300870
871 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
872 WMI_VDEV_TYPE_MONITOR,
873 0, ar->mac_addr);
874 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200875 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200876 ar->monitor_vdev_id, ret);
Ben Greeara9aefb32014-08-12 11:02:19 +0300877 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300878 }
879
Ben Greear16c11172014-09-23 14:17:16 -0700880 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
Michal Kazior7aa7a722014-08-25 12:09:38 +0200881 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300882 ar->monitor_vdev_id);
883
Kalle Valo5e3dd152013-06-12 20:52:10 +0300884 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300885}
886
Michal Kazior1bbc0972014-04-08 09:45:47 +0300887static int ath10k_monitor_vdev_delete(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +0300888{
889 int ret = 0;
890
891 lockdep_assert_held(&ar->conf_mutex);
892
Kalle Valo5e3dd152013-06-12 20:52:10 +0300893 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
894 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200895 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +0200896 ar->monitor_vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300897 return ret;
898 }
899
Ben Greear16c11172014-09-23 14:17:16 -0700900 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300901
Michal Kazior7aa7a722014-08-25 12:09:38 +0200902 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +0300903 ar->monitor_vdev_id);
904 return ret;
905}
906
Michal Kazior1bbc0972014-04-08 09:45:47 +0300907static int ath10k_monitor_start(struct ath10k *ar)
908{
909 int ret;
910
911 lockdep_assert_held(&ar->conf_mutex);
912
Michal Kazior1bbc0972014-04-08 09:45:47 +0300913 ret = ath10k_monitor_vdev_create(ar);
914 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200915 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300916 return ret;
917 }
918
919 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
920 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200921 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300922 ath10k_monitor_vdev_delete(ar);
923 return ret;
924 }
925
926 ar->monitor_started = true;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200927 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
Michal Kazior1bbc0972014-04-08 09:45:47 +0300928
929 return 0;
930}
931
Michal Kazior19337472014-08-28 12:58:16 +0200932static int ath10k_monitor_stop(struct ath10k *ar)
Michal Kazior1bbc0972014-04-08 09:45:47 +0300933{
934 int ret;
935
936 lockdep_assert_held(&ar->conf_mutex);
937
Michal Kazior1bbc0972014-04-08 09:45:47 +0300938 ret = ath10k_monitor_vdev_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200939 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200940 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +0200941 return ret;
942 }
Michal Kazior1bbc0972014-04-08 09:45:47 +0300943
944 ret = ath10k_monitor_vdev_delete(ar);
Michal Kazior19337472014-08-28 12:58:16 +0200945 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +0200946 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
Michal Kazior19337472014-08-28 12:58:16 +0200947 return ret;
948 }
Michal Kazior1bbc0972014-04-08 09:45:47 +0300949
950 ar->monitor_started = false;
Michal Kazior7aa7a722014-08-25 12:09:38 +0200951 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
Michal Kazior19337472014-08-28 12:58:16 +0200952
953 return 0;
954}
955
Vasanthakumar Thiagarajan54846212015-03-02 17:45:28 +0530956static bool ath10k_mac_should_disable_promisc(struct ath10k *ar)
957{
958 struct ath10k_vif *arvif;
959
960 if (!(ar->filter_flags & FIF_PROMISC_IN_BSS))
961 return true;
962
963 if (!ar->num_started_vdevs)
964 return false;
965
966 list_for_each_entry(arvif, &ar->arvifs, list)
967 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
968 return false;
969
970 ath10k_dbg(ar, ATH10K_DBG_MAC,
971 "mac disabling promiscuous mode because vdev is started\n");
972 return true;
973}
974
Michal Kazior19337472014-08-28 12:58:16 +0200975static int ath10k_monitor_recalc(struct ath10k *ar)
976{
977 bool should_start;
978
979 lockdep_assert_held(&ar->conf_mutex);
980
981 should_start = ar->monitor ||
Michal Kaziorbff414c2015-03-09 14:20:55 +0100982 !ath10k_mac_should_disable_promisc(ar) ||
Michal Kazior19337472014-08-28 12:58:16 +0200983 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
984
985 ath10k_dbg(ar, ATH10K_DBG_MAC,
986 "mac monitor recalc started? %d should? %d\n",
987 ar->monitor_started, should_start);
988
989 if (should_start == ar->monitor_started)
990 return 0;
991
992 if (should_start)
993 return ath10k_monitor_start(ar);
Kalle Valod8bb26b2014-09-14 12:50:33 +0300994
995 return ath10k_monitor_stop(ar);
Michal Kazior1bbc0972014-04-08 09:45:47 +0300996}
997
Marek Kwaczynskie81bd102014-03-11 12:58:00 +0200998static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
999{
1000 struct ath10k *ar = arvif->ar;
1001 u32 vdev_param, rts_cts = 0;
1002
1003 lockdep_assert_held(&ar->conf_mutex);
1004
1005 vdev_param = ar->wmi.vdev_param->enable_rtscts;
1006
Rajkumar Manoharan9a5ab0f2015-03-19 16:03:29 +02001007 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001008
1009 if (arvif->num_legacy_stations > 0)
1010 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
1011 WMI_RTSCTS_PROFILE);
Rajkumar Manoharan9a5ab0f2015-03-19 16:03:29 +02001012 else
1013 rts_cts |= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES,
1014 WMI_RTSCTS_PROFILE);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02001015
1016 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
1017 rts_cts);
1018}
1019
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001020static int ath10k_start_cac(struct ath10k *ar)
1021{
1022 int ret;
1023
1024 lockdep_assert_held(&ar->conf_mutex);
1025
1026 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1027
Michal Kazior19337472014-08-28 12:58:16 +02001028 ret = ath10k_monitor_recalc(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001029 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001030 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001031 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1032 return ret;
1033 }
1034
Michal Kazior7aa7a722014-08-25 12:09:38 +02001035 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001036 ar->monitor_vdev_id);
1037
1038 return 0;
1039}
1040
1041static int ath10k_stop_cac(struct ath10k *ar)
1042{
1043 lockdep_assert_held(&ar->conf_mutex);
1044
1045 /* CAC is not running - do nothing */
1046 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
1047 return 0;
1048
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001049 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
Michal Kazior1bbc0972014-04-08 09:45:47 +03001050 ath10k_monitor_stop(ar);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001051
Michal Kazior7aa7a722014-08-25 12:09:38 +02001052 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001053
1054 return 0;
1055}
1056
Michal Kaziord6500972014-04-08 09:56:09 +03001057static void ath10k_recalc_radar_detection(struct ath10k *ar)
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001058{
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001059 int ret;
1060
1061 lockdep_assert_held(&ar->conf_mutex);
1062
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001063 ath10k_stop_cac(ar);
1064
Michal Kaziord6500972014-04-08 09:56:09 +03001065 if (!ar->radar_enabled)
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001066 return;
1067
Michal Kaziord6500972014-04-08 09:56:09 +03001068 if (ar->num_started_vdevs > 0)
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001069 return;
1070
1071 ret = ath10k_start_cac(ar);
1072 if (ret) {
1073 /*
1074 * Not possible to start CAC on current channel so starting
1075 * radiation is not allowed, make this channel DFS_UNAVAILABLE
1076 * by indicating that radar was detected.
1077 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02001078 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02001079 ieee80211_radar_detected(ar->hw);
1080 }
1081}
1082
Vasanthakumar Thiagarajan822b7e02015-03-02 17:45:27 +05301083static int ath10k_vdev_stop(struct ath10k_vif *arvif)
1084{
1085 struct ath10k *ar = arvif->ar;
1086 int ret;
1087
1088 lockdep_assert_held(&ar->conf_mutex);
1089
1090 reinit_completion(&ar->vdev_setup_done);
1091
1092 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
1093 if (ret) {
1094 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
1095 arvif->vdev_id, ret);
1096 return ret;
1097 }
1098
1099 ret = ath10k_vdev_setup_sync(ar);
1100 if (ret) {
1101 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
1102 arvif->vdev_id, ret);
1103 return ret;
1104 }
1105
1106 WARN_ON(ar->num_started_vdevs == 0);
1107
1108 if (ar->num_started_vdevs != 0) {
1109 ar->num_started_vdevs--;
1110 ath10k_recalc_radar_detection(ar);
1111 }
1112
1113 return ret;
1114}
1115
Michal Kaziordc55e302014-07-29 12:53:36 +03001116static int ath10k_vdev_start_restart(struct ath10k_vif *arvif, bool restart)
Michal Kazior72654fa2014-04-08 09:56:09 +03001117{
1118 struct ath10k *ar = arvif->ar;
1119 struct cfg80211_chan_def *chandef = &ar->chandef;
1120 struct wmi_vdev_start_request_arg arg = {};
Vasanthakumar Thiagarajan54846212015-03-02 17:45:28 +05301121 int ret = 0, ret2;
Michal Kazior72654fa2014-04-08 09:56:09 +03001122
1123 lockdep_assert_held(&ar->conf_mutex);
1124
1125 reinit_completion(&ar->vdev_setup_done);
1126
1127 arg.vdev_id = arvif->vdev_id;
1128 arg.dtim_period = arvif->dtim_period;
1129 arg.bcn_intval = arvif->beacon_interval;
1130
1131 arg.channel.freq = chandef->chan->center_freq;
1132 arg.channel.band_center_freq1 = chandef->center_freq1;
1133 arg.channel.mode = chan_to_phymode(chandef);
1134
1135 arg.channel.min_power = 0;
1136 arg.channel.max_power = chandef->chan->max_power * 2;
1137 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
1138 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
1139
1140 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1141 arg.ssid = arvif->u.ap.ssid;
1142 arg.ssid_len = arvif->u.ap.ssid_len;
1143 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
1144
1145 /* For now allow DFS for AP mode */
1146 arg.channel.chan_radar =
1147 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
1148 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
1149 arg.ssid = arvif->vif->bss_conf.ssid;
1150 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
1151 }
1152
Michal Kazior7aa7a722014-08-25 12:09:38 +02001153 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior72654fa2014-04-08 09:56:09 +03001154 "mac vdev %d start center_freq %d phymode %s\n",
1155 arg.vdev_id, arg.channel.freq,
1156 ath10k_wmi_phymode_str(arg.channel.mode));
1157
Michal Kaziordc55e302014-07-29 12:53:36 +03001158 if (restart)
1159 ret = ath10k_wmi_vdev_restart(ar, &arg);
1160 else
1161 ret = ath10k_wmi_vdev_start(ar, &arg);
1162
Michal Kazior72654fa2014-04-08 09:56:09 +03001163 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001164 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
Michal Kazior72654fa2014-04-08 09:56:09 +03001165 arg.vdev_id, ret);
1166 return ret;
1167 }
1168
1169 ret = ath10k_vdev_setup_sync(ar);
1170 if (ret) {
Ben Greear60028a82015-02-15 16:50:39 +02001171 ath10k_warn(ar,
1172 "failed to synchronize setup for vdev %i restart %d: %d\n",
1173 arg.vdev_id, restart, ret);
Michal Kazior72654fa2014-04-08 09:56:09 +03001174 return ret;
1175 }
1176
Michal Kaziord6500972014-04-08 09:56:09 +03001177 ar->num_started_vdevs++;
1178 ath10k_recalc_radar_detection(ar);
1179
Vasanthakumar Thiagarajan54846212015-03-02 17:45:28 +05301180 ret = ath10k_monitor_recalc(ar);
1181 if (ret) {
1182 ath10k_warn(ar, "mac failed to recalc monitor for vdev %i restart %d: %d\n",
1183 arg.vdev_id, restart, ret);
1184 ret2 = ath10k_vdev_stop(arvif);
1185 if (ret2)
1186 ath10k_warn(ar, "mac failed to stop vdev %i restart %d: %d\n",
1187 arg.vdev_id, restart, ret2);
1188 }
1189
Michal Kazior72654fa2014-04-08 09:56:09 +03001190 return ret;
1191}
1192
Michal Kaziordc55e302014-07-29 12:53:36 +03001193static int ath10k_vdev_start(struct ath10k_vif *arvif)
1194{
1195 return ath10k_vdev_start_restart(arvif, false);
1196}
1197
1198static int ath10k_vdev_restart(struct ath10k_vif *arvif)
1199{
1200 return ath10k_vdev_start_restart(arvif, true);
1201}
1202
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001203static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
1204 struct sk_buff *bcn)
1205{
1206 struct ath10k *ar = arvif->ar;
1207 struct ieee80211_mgmt *mgmt;
1208 const u8 *p2p_ie;
1209 int ret;
1210
1211 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1212 return 0;
1213
1214 if (arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1215 return 0;
1216
1217 mgmt = (void *)bcn->data;
1218 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1219 mgmt->u.beacon.variable,
1220 bcn->len - (mgmt->u.beacon.variable -
1221 bcn->data));
1222 if (!p2p_ie)
1223 return -ENOENT;
1224
1225 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1226 if (ret) {
1227 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1228 arvif->vdev_id, ret);
1229 return ret;
1230 }
1231
1232 return 0;
1233}
1234
1235static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1236 u8 oui_type, size_t ie_offset)
1237{
1238 size_t len;
1239 const u8 *next;
1240 const u8 *end;
1241 u8 *ie;
1242
1243 if (WARN_ON(skb->len < ie_offset))
1244 return -EINVAL;
1245
1246 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1247 skb->data + ie_offset,
1248 skb->len - ie_offset);
1249 if (!ie)
1250 return -ENOENT;
1251
1252 len = ie[1] + 2;
1253 end = skb->data + skb->len;
1254 next = ie + len;
1255
1256 if (WARN_ON(next > end))
1257 return -EINVAL;
1258
1259 memmove(ie, next, end - next);
1260 skb_trim(skb, skb->len - len);
1261
1262 return 0;
1263}
1264
1265static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1266{
1267 struct ath10k *ar = arvif->ar;
1268 struct ieee80211_hw *hw = ar->hw;
1269 struct ieee80211_vif *vif = arvif->vif;
1270 struct ieee80211_mutable_offsets offs = {};
1271 struct sk_buff *bcn;
1272 int ret;
1273
1274 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1275 return 0;
1276
Michal Kazior81a9a172015-03-05 16:02:17 +02001277 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
1278 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
1279 return 0;
1280
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001281 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1282 if (!bcn) {
1283 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1284 return -EPERM;
1285 }
1286
1287 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1288 if (ret) {
1289 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1290 kfree_skb(bcn);
1291 return ret;
1292 }
1293
1294 /* P2P IE is inserted by firmware automatically (as configured above)
1295 * so remove it from the base beacon template to avoid duplicate P2P
1296 * IEs in beacon frames.
1297 */
1298 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1299 offsetof(struct ieee80211_mgmt,
1300 u.beacon.variable));
1301
1302 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1303 0, NULL, 0);
1304 kfree_skb(bcn);
1305
1306 if (ret) {
1307 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1308 ret);
1309 return ret;
1310 }
1311
1312 return 0;
1313}
1314
1315static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1316{
1317 struct ath10k *ar = arvif->ar;
1318 struct ieee80211_hw *hw = ar->hw;
1319 struct ieee80211_vif *vif = arvif->vif;
1320 struct sk_buff *prb;
1321 int ret;
1322
1323 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1324 return 0;
1325
Michal Kazior81a9a172015-03-05 16:02:17 +02001326 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1327 return 0;
1328
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02001329 prb = ieee80211_proberesp_get(hw, vif);
1330 if (!prb) {
1331 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1332 return -EPERM;
1333 }
1334
1335 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1336 kfree_skb(prb);
1337
1338 if (ret) {
1339 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1340 ret);
1341 return ret;
1342 }
1343
1344 return 0;
1345}
1346
Kalle Valo5e3dd152013-06-12 20:52:10 +03001347static void ath10k_control_beaconing(struct ath10k_vif *arvif,
Kalle Valo5b07e072014-09-14 12:50:06 +03001348 struct ieee80211_bss_conf *info)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001349{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001350 struct ath10k *ar = arvif->ar;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001351 int ret = 0;
1352
Michal Kazior548db542013-07-05 16:15:15 +03001353 lockdep_assert_held(&arvif->ar->conf_mutex);
1354
Kalle Valo5e3dd152013-06-12 20:52:10 +03001355 if (!info->enable_beacon) {
1356 ath10k_vdev_stop(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01001357
1358 arvif->is_started = false;
1359 arvif->is_up = false;
Michal Kazior8513d952015-03-09 14:19:24 +01001360
1361 spin_lock_bh(&arvif->ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03001362 ath10k_mac_vif_beacon_free(arvif);
Michal Kazior748afc42014-01-23 12:48:21 +01001363 spin_unlock_bh(&arvif->ar->data_lock);
1364
Kalle Valo5e3dd152013-06-12 20:52:10 +03001365 return;
1366 }
1367
1368 arvif->tx_seq_no = 0x1000;
1369
1370 ret = ath10k_vdev_start(arvif);
1371 if (ret)
1372 return;
1373
Michal Kaziorc930f742014-01-23 11:38:25 +01001374 arvif->aid = 0;
Kalle Valob25f32c2014-09-14 12:50:49 +03001375 ether_addr_copy(arvif->bssid, info->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01001376
1377 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1378 arvif->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001379 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001380 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001381 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01001382 ath10k_vdev_stop(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001383 return;
1384 }
Michal Kaziorc930f742014-01-23 11:38:25 +01001385
1386 arvif->is_started = true;
1387 arvif->is_up = true;
1388
Michal Kazior7aa7a722014-08-25 12:09:38 +02001389 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001390}
1391
1392static void ath10k_control_ibss(struct ath10k_vif *arvif,
1393 struct ieee80211_bss_conf *info,
1394 const u8 self_peer[ETH_ALEN])
1395{
Michal Kazior7aa7a722014-08-25 12:09:38 +02001396 struct ath10k *ar = arvif->ar;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001397 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001398 int ret = 0;
1399
Michal Kazior548db542013-07-05 16:15:15 +03001400 lockdep_assert_held(&arvif->ar->conf_mutex);
1401
Kalle Valo5e3dd152013-06-12 20:52:10 +03001402 if (!info->ibss_joined) {
1403 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
1404 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001405 ath10k_warn(ar, "failed to delete IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001406 self_peer, arvif->vdev_id, ret);
1407
Michal Kaziorc930f742014-01-23 11:38:25 +01001408 if (is_zero_ether_addr(arvif->bssid))
Kalle Valo5e3dd152013-06-12 20:52:10 +03001409 return;
1410
Michal Kaziorc930f742014-01-23 11:38:25 +01001411 memset(arvif->bssid, 0, ETH_ALEN);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001412
1413 return;
1414 }
1415
Marek Puzyniak7390ed32015-03-30 09:51:52 +03001416 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer,
1417 WMI_PEER_TYPE_DEFAULT);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001418 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001419 ath10k_warn(ar, "failed to create IBSS self peer %pM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001420 self_peer, arvif->vdev_id, ret);
1421 return;
1422 }
1423
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02001424 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1425 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001426 ATH10K_DEFAULT_ATIM);
1427 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02001428 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001429 arvif->vdev_id, ret);
1430}
1431
Michal Kazior9f9b5742014-12-12 12:41:36 +01001432static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1433{
1434 struct ath10k *ar = arvif->ar;
1435 u32 param;
1436 u32 value;
1437 int ret;
1438
1439 lockdep_assert_held(&arvif->ar->conf_mutex);
1440
1441 if (arvif->u.sta.uapsd)
1442 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1443 else
1444 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1445
1446 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1447 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1448 if (ret) {
1449 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1450 value, arvif->vdev_id, ret);
1451 return ret;
1452 }
1453
1454 return 0;
1455}
1456
1457static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1458{
1459 struct ath10k *ar = arvif->ar;
1460 u32 param;
1461 u32 value;
1462 int ret;
1463
1464 lockdep_assert_held(&arvif->ar->conf_mutex);
1465
1466 if (arvif->u.sta.uapsd)
1467 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1468 else
1469 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1470
1471 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1472 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1473 param, value);
1474 if (ret) {
1475 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1476 value, arvif->vdev_id, ret);
1477 return ret;
1478 }
1479
1480 return 0;
1481}
1482
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001483static int ath10k_mac_ps_vif_count(struct ath10k *ar)
1484{
1485 struct ath10k_vif *arvif;
1486 int num = 0;
1487
1488 lockdep_assert_held(&ar->conf_mutex);
1489
1490 list_for_each_entry(arvif, &ar->arvifs, list)
1491 if (arvif->ps)
1492 num++;
1493
1494 return num;
1495}
1496
Michal Kaziorad088bf2013-10-16 15:44:46 +03001497static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001498{
Michal Kaziorad088bf2013-10-16 15:44:46 +03001499 struct ath10k *ar = arvif->ar;
Michal Kazior526549a2014-12-12 12:41:37 +01001500 struct ieee80211_vif *vif = arvif->vif;
Michal Kaziorad088bf2013-10-16 15:44:46 +03001501 struct ieee80211_conf *conf = &ar->hw->conf;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001502 enum wmi_sta_powersave_param param;
1503 enum wmi_sta_ps_mode psmode;
1504 int ret;
Michal Kazior526549a2014-12-12 12:41:37 +01001505 int ps_timeout;
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001506 bool enable_ps;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001507
Michal Kazior548db542013-07-05 16:15:15 +03001508 lockdep_assert_held(&arvif->ar->conf_mutex);
1509
Michal Kaziorad088bf2013-10-16 15:44:46 +03001510 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1511 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001512
Michal Kaziorcffb41f2015-02-13 13:30:16 +01001513 enable_ps = arvif->ps;
1514
1515 if (enable_ps && ath10k_mac_ps_vif_count(ar) > 1 &&
1516 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
1517 ar->fw_features)) {
1518 ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
1519 arvif->vdev_id);
1520 enable_ps = false;
1521 }
1522
1523 if (enable_ps) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001524 psmode = WMI_STA_PS_MODE_ENABLED;
1525 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1526
Michal Kazior526549a2014-12-12 12:41:37 +01001527 ps_timeout = conf->dynamic_ps_timeout;
1528 if (ps_timeout == 0) {
1529 /* Firmware doesn't like 0 */
1530 ps_timeout = ieee80211_tu_to_usec(
1531 vif->bss_conf.beacon_int) / 1000;
1532 }
1533
Michal Kaziorad088bf2013-10-16 15:44:46 +03001534 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
Michal Kazior526549a2014-12-12 12:41:37 +01001535 ps_timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001536 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001537 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02001538 arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001539 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001540 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001541 } else {
1542 psmode = WMI_STA_PS_MODE_DISABLED;
1543 }
1544
Michal Kazior7aa7a722014-08-25 12:09:38 +02001545 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001546 arvif->vdev_id, psmode ? "enable" : "disable");
1547
Michal Kaziorad088bf2013-10-16 15:44:46 +03001548 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1549 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001550 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02001551 psmode, arvif->vdev_id, ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03001552 return ret;
1553 }
1554
1555 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001556}
1557
Michal Kazior46725b152015-01-28 09:57:49 +02001558static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1559{
1560 struct ath10k *ar = arvif->ar;
1561 struct wmi_sta_keepalive_arg arg = {};
1562 int ret;
1563
1564 lockdep_assert_held(&arvif->ar->conf_mutex);
1565
1566 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1567 return 0;
1568
1569 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1570 return 0;
1571
1572 /* Some firmware revisions have a bug and ignore the `enabled` field.
1573 * Instead use the interval to disable the keepalive.
1574 */
1575 arg.vdev_id = arvif->vdev_id;
1576 arg.enabled = 1;
1577 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1578 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1579
1580 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1581 if (ret) {
1582 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1583 arvif->vdev_id, ret);
1584 return ret;
1585 }
1586
1587 return 0;
1588}
1589
Michal Kazior81a9a172015-03-05 16:02:17 +02001590static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif)
1591{
1592 struct ath10k *ar = arvif->ar;
1593 struct ieee80211_vif *vif = arvif->vif;
1594 int ret;
1595
Michal Kazior8513d952015-03-09 14:19:24 +01001596 lockdep_assert_held(&arvif->ar->conf_mutex);
1597
1598 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)))
1599 return;
1600
Michal Kazior81a9a172015-03-05 16:02:17 +02001601 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1602 return;
1603
1604 if (!vif->csa_active)
1605 return;
1606
1607 if (!arvif->is_up)
1608 return;
1609
1610 if (!ieee80211_csa_is_complete(vif)) {
1611 ieee80211_csa_update_counter(vif);
1612
1613 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1614 if (ret)
1615 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
1616 ret);
1617
1618 ret = ath10k_mac_setup_prb_tmpl(arvif);
1619 if (ret)
1620 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
1621 ret);
1622 } else {
1623 ieee80211_csa_finish(vif);
1624 }
1625}
1626
1627static void ath10k_mac_vif_ap_csa_work(struct work_struct *work)
1628{
1629 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1630 ap_csa_work);
1631 struct ath10k *ar = arvif->ar;
1632
1633 mutex_lock(&ar->conf_mutex);
1634 ath10k_mac_vif_ap_csa_count_down(arvif);
1635 mutex_unlock(&ar->conf_mutex);
1636}
1637
Michal Kaziorcc9904e2015-03-10 16:22:01 +02001638static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac,
1639 struct ieee80211_vif *vif)
1640{
1641 struct sk_buff *skb = data;
1642 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1643 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1644
1645 if (vif->type != NL80211_IFTYPE_STATION)
1646 return;
1647
1648 if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
1649 return;
1650
1651 cancel_delayed_work(&arvif->connection_loss_work);
1652}
1653
1654void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb)
1655{
1656 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1657 IEEE80211_IFACE_ITER_NORMAL,
1658 ath10k_mac_handle_beacon_iter,
1659 skb);
1660}
1661
1662static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac,
1663 struct ieee80211_vif *vif)
1664{
1665 u32 *vdev_id = data;
1666 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1667 struct ath10k *ar = arvif->ar;
1668 struct ieee80211_hw *hw = ar->hw;
1669
1670 if (arvif->vdev_id != *vdev_id)
1671 return;
1672
1673 if (!arvif->is_up)
1674 return;
1675
1676 ieee80211_beacon_loss(vif);
1677
1678 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
1679 * (done by mac80211) succeeds but beacons do not resume then it
1680 * doesn't make sense to continue operation. Queue connection loss work
1681 * which can be cancelled when beacon is received.
1682 */
1683 ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
1684 ATH10K_CONNECTION_LOSS_HZ);
1685}
1686
1687void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id)
1688{
1689 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1690 IEEE80211_IFACE_ITER_NORMAL,
1691 ath10k_mac_handle_beacon_miss_iter,
1692 &vdev_id);
1693}
1694
1695static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work)
1696{
1697 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1698 connection_loss_work.work);
1699 struct ieee80211_vif *vif = arvif->vif;
1700
1701 if (!arvif->is_up)
1702 return;
1703
1704 ieee80211_connection_loss(vif);
1705}
1706
Kalle Valo5e3dd152013-06-12 20:52:10 +03001707/**********************/
1708/* Station management */
1709/**********************/
1710
Michal Kazior590922a2014-10-21 10:10:29 +03001711static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1712 struct ieee80211_vif *vif)
1713{
1714 /* Some firmware revisions have unstable STA powersave when listen
1715 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1716 * generate NullFunc frames properly even if buffered frames have been
1717 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1718 * buffered frames. Often pinging the device from AP would simply fail.
1719 *
1720 * As a workaround set it to 1.
1721 */
1722 if (vif->type == NL80211_IFTYPE_STATION)
1723 return 1;
1724
1725 return ar->hw->conf.listen_interval;
1726}
1727
Kalle Valo5e3dd152013-06-12 20:52:10 +03001728static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001729 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001730 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001731 struct wmi_peer_assoc_complete_arg *arg)
1732{
Michal Kazior590922a2014-10-21 10:10:29 +03001733 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorc51880e2015-03-30 09:51:57 +03001734 u32 aid;
Michal Kazior590922a2014-10-21 10:10:29 +03001735
Michal Kazior548db542013-07-05 16:15:15 +03001736 lockdep_assert_held(&ar->conf_mutex);
1737
Michal Kaziorc51880e2015-03-30 09:51:57 +03001738 if (vif->type == NL80211_IFTYPE_STATION)
1739 aid = vif->bss_conf.aid;
1740 else
1741 aid = sta->aid;
1742
Kalle Valob25f32c2014-09-14 12:50:49 +03001743 ether_addr_copy(arg->addr, sta->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001744 arg->vdev_id = arvif->vdev_id;
Michal Kaziorc51880e2015-03-30 09:51:57 +03001745 arg->peer_aid = aid;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001746 arg->peer_flags |= WMI_PEER_AUTH;
Michal Kazior590922a2014-10-21 10:10:29 +03001747 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001748 arg->peer_num_spatial_streams = 1;
Michal Kazior590922a2014-10-21 10:10:29 +03001749 arg->peer_caps = vif->bss_conf.assoc_capability;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001750}
1751
1752static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03001753 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001754 struct wmi_peer_assoc_complete_arg *arg)
1755{
Kalle Valo5e3dd152013-06-12 20:52:10 +03001756 struct ieee80211_bss_conf *info = &vif->bss_conf;
1757 struct cfg80211_bss *bss;
1758 const u8 *rsnie = NULL;
1759 const u8 *wpaie = NULL;
1760
Michal Kazior548db542013-07-05 16:15:15 +03001761 lockdep_assert_held(&ar->conf_mutex);
1762
Kalle Valo5e3dd152013-06-12 20:52:10 +03001763 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
Dedy Lansky6eb18132015-02-08 15:52:03 +02001764 info->bssid, NULL, 0, IEEE80211_BSS_TYPE_ANY,
1765 IEEE80211_PRIVACY_ANY);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001766 if (bss) {
1767 const struct cfg80211_bss_ies *ies;
1768
1769 rcu_read_lock();
1770 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1771
1772 ies = rcu_dereference(bss->ies);
1773
1774 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
Kalle Valo5b07e072014-09-14 12:50:06 +03001775 WLAN_OUI_TYPE_MICROSOFT_WPA,
1776 ies->data,
1777 ies->len);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001778 rcu_read_unlock();
1779 cfg80211_put_bss(ar->hw->wiphy, bss);
1780 }
1781
1782 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1783 if (rsnie || wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001784 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001785 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1786 }
1787
1788 if (wpaie) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001789 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
Kalle Valo5e3dd152013-06-12 20:52:10 +03001790 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1791 }
1792}
1793
1794static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
1795 struct ieee80211_sta *sta,
1796 struct wmi_peer_assoc_complete_arg *arg)
1797{
1798 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1799 const struct ieee80211_supported_band *sband;
1800 const struct ieee80211_rate *rates;
1801 u32 ratemask;
Michal Kazior486017c2015-03-30 09:51:54 +03001802 u8 rate;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001803 int i;
1804
Michal Kazior548db542013-07-05 16:15:15 +03001805 lockdep_assert_held(&ar->conf_mutex);
1806
Kalle Valo5e3dd152013-06-12 20:52:10 +03001807 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
1808 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
1809 rates = sband->bitrates;
1810
1811 rateset->num_rates = 0;
1812
1813 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1814 if (!(ratemask & 1))
1815 continue;
1816
Michal Kazior486017c2015-03-30 09:51:54 +03001817 rate = ath10k_mac_bitrate_to_rate(rates->bitrate);
1818 rateset->rates[rateset->num_rates] = rate;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001819 rateset->num_rates++;
1820 }
1821}
1822
1823static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1824 struct ieee80211_sta *sta,
1825 struct wmi_peer_assoc_complete_arg *arg)
1826{
1827 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001828 int i, n;
Kalle Valoaf762c02014-09-14 12:50:17 +03001829 u32 stbc;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001830
Michal Kazior548db542013-07-05 16:15:15 +03001831 lockdep_assert_held(&ar->conf_mutex);
1832
Kalle Valo5e3dd152013-06-12 20:52:10 +03001833 if (!ht_cap->ht_supported)
1834 return;
1835
1836 arg->peer_flags |= WMI_PEER_HT;
1837 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1838 ht_cap->ampdu_factor)) - 1;
1839
1840 arg->peer_mpdu_density =
1841 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1842
1843 arg->peer_ht_caps = ht_cap->cap;
1844 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1845
1846 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1847 arg->peer_flags |= WMI_PEER_LDPC;
1848
1849 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1850 arg->peer_flags |= WMI_PEER_40MHZ;
1851 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1852 }
1853
1854 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1855 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1856
1857 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1858 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1859
1860 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1861 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1862 arg->peer_flags |= WMI_PEER_STBC;
1863 }
1864
1865 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03001866 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1867 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1868 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1869 arg->peer_rate_caps |= stbc;
1870 arg->peer_flags |= WMI_PEER_STBC;
1871 }
1872
Kalle Valo5e3dd152013-06-12 20:52:10 +03001873 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1874 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
1875 else if (ht_cap->mcs.rx_mask[1])
1876 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
1877
1878 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
1879 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
1880 arg->peer_ht_rates.rates[n++] = i;
1881
Bartosz Markowskifd71f802014-02-10 13:12:55 +01001882 /*
1883 * This is a workaround for HT-enabled STAs which break the spec
1884 * and have no HT capabilities RX mask (no HT RX MCS map).
1885 *
1886 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1887 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1888 *
1889 * Firmware asserts if such situation occurs.
1890 */
1891 if (n == 0) {
1892 arg->peer_ht_rates.num_rates = 8;
1893 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1894 arg->peer_ht_rates.rates[i] = i;
1895 } else {
1896 arg->peer_ht_rates.num_rates = n;
1897 arg->peer_num_spatial_streams = sta->rx_nss;
1898 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001899
Michal Kazior7aa7a722014-08-25 12:09:38 +02001900 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03001901 arg->addr,
Kalle Valo5e3dd152013-06-12 20:52:10 +03001902 arg->peer_ht_rates.num_rates,
1903 arg->peer_num_spatial_streams);
1904}
1905
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001906static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1907 struct ath10k_vif *arvif,
1908 struct ieee80211_sta *sta)
Kalle Valo5e3dd152013-06-12 20:52:10 +03001909{
1910 u32 uapsd = 0;
1911 u32 max_sp = 0;
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001912 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001913
Michal Kazior548db542013-07-05 16:15:15 +03001914 lockdep_assert_held(&ar->conf_mutex);
1915
Kalle Valo5e3dd152013-06-12 20:52:10 +03001916 if (sta->wme && sta->uapsd_queues) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001917 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03001918 sta->uapsd_queues, sta->max_sp);
1919
Kalle Valo5e3dd152013-06-12 20:52:10 +03001920 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1921 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1922 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1923 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1924 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1925 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1926 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1927 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1928 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1929 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1930 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1931 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1932
Kalle Valo5e3dd152013-06-12 20:52:10 +03001933 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1934 max_sp = sta->max_sp;
1935
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001936 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1937 sta->addr,
1938 WMI_AP_PS_PEER_PARAM_UAPSD,
1939 uapsd);
1940 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001941 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001942 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001943 return ret;
1944 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001945
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001946 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1947 sta->addr,
1948 WMI_AP_PS_PEER_PARAM_MAX_SP,
1949 max_sp);
1950 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001951 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001952 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001953 return ret;
1954 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001955
1956 /* TODO setup this based on STA listen interval and
1957 beacon interval. Currently we don't know
1958 sta->listen_interval - mac80211 patch required.
1959 Currently use 10 seconds */
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001960 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
Kalle Valo5b07e072014-09-14 12:50:06 +03001961 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
1962 10);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001963 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02001964 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02001965 arvif->vdev_id, ret);
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001966 return ret;
1967 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001968 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03001969
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01001970 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001971}
1972
1973static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1974 struct ieee80211_sta *sta,
1975 struct wmi_peer_assoc_complete_arg *arg)
1976{
1977 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001978 u8 ampdu_factor;
Kalle Valo5e3dd152013-06-12 20:52:10 +03001979
1980 if (!vht_cap->vht_supported)
1981 return;
1982
1983 arg->peer_flags |= WMI_PEER_VHT;
Yanbo Lid68bb122015-01-23 08:18:20 +08001984
1985 if (ar->hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ)
1986 arg->peer_flags |= WMI_PEER_VHT_2G;
1987
Kalle Valo5e3dd152013-06-12 20:52:10 +03001988 arg->peer_vht_caps = vht_cap->cap;
1989
Sujith Manoharana24b88b2013-10-07 19:51:57 -07001990 ampdu_factor = (vht_cap->cap &
1991 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1992 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1993
1994 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1995 * zero in VHT IE. Using it would result in degraded throughput.
1996 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1997 * it if VHT max_mpdu is smaller. */
1998 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1999 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2000 ampdu_factor)) - 1);
2001
Kalle Valo5e3dd152013-06-12 20:52:10 +03002002 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2003 arg->peer_flags |= WMI_PEER_80MHZ;
2004
2005 arg->peer_vht_rates.rx_max_rate =
2006 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
2007 arg->peer_vht_rates.rx_mcs_set =
2008 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
2009 arg->peer_vht_rates.tx_max_rate =
2010 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
2011 arg->peer_vht_rates.tx_mcs_set =
2012 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
2013
Michal Kazior7aa7a722014-08-25 12:09:38 +02002014 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03002015 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002016}
2017
2018static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03002019 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002020 struct ieee80211_sta *sta,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002021 struct wmi_peer_assoc_complete_arg *arg)
2022{
Michal Kazior590922a2014-10-21 10:10:29 +03002023 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2024
Kalle Valo5e3dd152013-06-12 20:52:10 +03002025 switch (arvif->vdev_type) {
2026 case WMI_VDEV_TYPE_AP:
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002027 if (sta->wme)
2028 arg->peer_flags |= WMI_PEER_QOS;
2029
2030 if (sta->wme && sta->uapsd_queues) {
2031 arg->peer_flags |= WMI_PEER_APSD;
2032 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
2033 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002034 break;
2035 case WMI_VDEV_TYPE_STA:
Michal Kazior590922a2014-10-21 10:10:29 +03002036 if (vif->bss_conf.qos)
Janusz Dziedzicd3d3ff42014-01-21 07:06:53 +01002037 arg->peer_flags |= WMI_PEER_QOS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002038 break;
Janusz Dziedzic627d9842014-12-17 12:29:54 +02002039 case WMI_VDEV_TYPE_IBSS:
2040 if (sta->wme)
2041 arg->peer_flags |= WMI_PEER_QOS;
2042 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002043 default:
2044 break;
2045 }
Janusz Dziedzic627d9842014-12-17 12:29:54 +02002046
2047 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
2048 sta->addr, !!(arg->peer_flags & WMI_PEER_QOS));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002049}
2050
Michal Kazior8d7aa6b2015-03-30 09:51:57 +03002051static bool ath10k_mac_sta_has_ofdm_only(struct ieee80211_sta *sta)
Michal Kazior91b12082014-12-12 12:41:35 +01002052{
Michal Kazior8d7aa6b2015-03-30 09:51:57 +03002053 return sta->supp_rates[IEEE80211_BAND_2GHZ] >>
2054 ATH10K_MAC_FIRST_OFDM_RATE_IDX;
Michal Kazior91b12082014-12-12 12:41:35 +01002055}
2056
Kalle Valo5e3dd152013-06-12 20:52:10 +03002057static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03002058 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002059 struct ieee80211_sta *sta,
2060 struct wmi_peer_assoc_complete_arg *arg)
2061{
2062 enum wmi_phy_mode phymode = MODE_UNKNOWN;
2063
Kalle Valo5e3dd152013-06-12 20:52:10 +03002064 switch (ar->hw->conf.chandef.chan->band) {
2065 case IEEE80211_BAND_2GHZ:
Yanbo Lid68bb122015-01-23 08:18:20 +08002066 if (sta->vht_cap.vht_supported) {
2067 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2068 phymode = MODE_11AC_VHT40;
2069 else
2070 phymode = MODE_11AC_VHT20;
2071 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002072 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2073 phymode = MODE_11NG_HT40;
2074 else
2075 phymode = MODE_11NG_HT20;
Michal Kazior8d7aa6b2015-03-30 09:51:57 +03002076 } else if (ath10k_mac_sta_has_ofdm_only(sta)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002077 phymode = MODE_11G;
Michal Kazior91b12082014-12-12 12:41:35 +01002078 } else {
2079 phymode = MODE_11B;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002080 }
2081
2082 break;
2083 case IEEE80211_BAND_5GHZ:
Sujith Manoharan7cc45e92013-09-08 18:19:55 +03002084 /*
2085 * Check VHT first.
2086 */
2087 if (sta->vht_cap.vht_supported) {
2088 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2089 phymode = MODE_11AC_VHT80;
2090 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2091 phymode = MODE_11AC_VHT40;
2092 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
2093 phymode = MODE_11AC_VHT20;
2094 } else if (sta->ht_cap.ht_supported) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03002095 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2096 phymode = MODE_11NA_HT40;
2097 else
2098 phymode = MODE_11NA_HT20;
2099 } else {
2100 phymode = MODE_11A;
2101 }
2102
2103 break;
2104 default:
2105 break;
2106 }
2107
Michal Kazior7aa7a722014-08-25 12:09:38 +02002108 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
Kalle Valo38a1d472013-09-08 17:56:14 +03002109 sta->addr, ath10k_wmi_phymode_str(phymode));
Kalle Valo60c3daa2013-09-08 17:56:07 +03002110
Kalle Valo5e3dd152013-06-12 20:52:10 +03002111 arg->peer_phymode = phymode;
2112 WARN_ON(phymode == MODE_UNKNOWN);
2113}
2114
Kalle Valob9ada652013-10-16 15:44:46 +03002115static int ath10k_peer_assoc_prepare(struct ath10k *ar,
Michal Kazior590922a2014-10-21 10:10:29 +03002116 struct ieee80211_vif *vif,
Kalle Valob9ada652013-10-16 15:44:46 +03002117 struct ieee80211_sta *sta,
Kalle Valob9ada652013-10-16 15:44:46 +03002118 struct wmi_peer_assoc_complete_arg *arg)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002119{
Michal Kazior548db542013-07-05 16:15:15 +03002120 lockdep_assert_held(&ar->conf_mutex);
2121
Kalle Valob9ada652013-10-16 15:44:46 +03002122 memset(arg, 0, sizeof(*arg));
Kalle Valo5e3dd152013-06-12 20:52:10 +03002123
Michal Kazior590922a2014-10-21 10:10:29 +03002124 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
2125 ath10k_peer_assoc_h_crypto(ar, vif, arg);
Kalle Valob9ada652013-10-16 15:44:46 +03002126 ath10k_peer_assoc_h_rates(ar, sta, arg);
2127 ath10k_peer_assoc_h_ht(ar, sta, arg);
2128 ath10k_peer_assoc_h_vht(ar, sta, arg);
Michal Kazior590922a2014-10-21 10:10:29 +03002129 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
2130 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002131
Kalle Valob9ada652013-10-16 15:44:46 +03002132 return 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002133}
2134
Michal Kazior90046f52014-02-14 14:45:51 +01002135static const u32 ath10k_smps_map[] = {
2136 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
2137 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
2138 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
2139 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
2140};
2141
2142static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
2143 const u8 *addr,
2144 const struct ieee80211_sta_ht_cap *ht_cap)
2145{
2146 int smps;
2147
2148 if (!ht_cap->ht_supported)
2149 return 0;
2150
2151 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
2152 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
2153
2154 if (smps >= ARRAY_SIZE(ath10k_smps_map))
2155 return -EINVAL;
2156
2157 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
2158 WMI_PEER_SMPS_STATE,
2159 ath10k_smps_map[smps]);
2160}
2161
Michal Kazior139e1702015-02-15 16:50:42 +02002162static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
2163 struct ieee80211_vif *vif,
2164 struct ieee80211_sta_vht_cap vht_cap)
2165{
2166 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2167 int ret;
2168 u32 param;
2169 u32 value;
2170
2171 if (!(ar->vht_cap_info &
2172 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2173 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
2174 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2175 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
2176 return 0;
2177
2178 param = ar->wmi.vdev_param->txbf;
2179 value = 0;
2180
2181 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
2182 return 0;
2183
2184 /* The following logic is correct. If a remote STA advertises support
2185 * for being a beamformer then we should enable us being a beamformee.
2186 */
2187
2188 if (ar->vht_cap_info &
2189 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2190 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
2191 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
2192 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2193
2194 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
2195 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
2196 }
2197
2198 if (ar->vht_cap_info &
2199 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2200 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
2201 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
2202 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2203
2204 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
2205 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
2206 }
2207
2208 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
2209 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2210
2211 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
2212 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2213
2214 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
2215 if (ret) {
2216 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
2217 value, ret);
2218 return ret;
2219 }
2220
2221 return 0;
2222}
2223
Kalle Valo5e3dd152013-06-12 20:52:10 +03002224/* can be called only in mac80211 callbacks due to `key_count` usage */
2225static void ath10k_bss_assoc(struct ieee80211_hw *hw,
2226 struct ieee80211_vif *vif,
2227 struct ieee80211_bss_conf *bss_conf)
2228{
2229 struct ath10k *ar = hw->priv;
2230 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior90046f52014-02-14 14:45:51 +01002231 struct ieee80211_sta_ht_cap ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02002232 struct ieee80211_sta_vht_cap vht_cap;
Kalle Valob9ada652013-10-16 15:44:46 +03002233 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002234 struct ieee80211_sta *ap_sta;
2235 int ret;
2236
Michal Kazior548db542013-07-05 16:15:15 +03002237 lockdep_assert_held(&ar->conf_mutex);
2238
Michal Kazior077efc82014-10-21 10:10:29 +03002239 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
2240 arvif->vdev_id, arvif->bssid, arvif->aid);
2241
Kalle Valo5e3dd152013-06-12 20:52:10 +03002242 rcu_read_lock();
2243
2244 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
2245 if (!ap_sta) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002246 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02002247 bss_conf->bssid, arvif->vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002248 rcu_read_unlock();
2249 return;
2250 }
2251
Michal Kazior90046f52014-02-14 14:45:51 +01002252 /* ap_sta must be accessed only within rcu section which must be left
2253 * before calling ath10k_setup_peer_smps() which might sleep. */
2254 ht_cap = ap_sta->ht_cap;
Michal Kazior139e1702015-02-15 16:50:42 +02002255 vht_cap = ap_sta->vht_cap;
Michal Kazior90046f52014-02-14 14:45:51 +01002256
Michal Kazior590922a2014-10-21 10:10:29 +03002257 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002258 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002259 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002260 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002261 rcu_read_unlock();
2262 return;
2263 }
2264
2265 rcu_read_unlock();
2266
Kalle Valob9ada652013-10-16 15:44:46 +03002267 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2268 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002269 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002270 bss_conf->bssid, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03002271 return;
2272 }
2273
Michal Kazior90046f52014-02-14 14:45:51 +01002274 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
2275 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002276 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002277 arvif->vdev_id, ret);
Michal Kazior90046f52014-02-14 14:45:51 +01002278 return;
2279 }
2280
Michal Kazior139e1702015-02-15 16:50:42 +02002281 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2282 if (ret) {
2283 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2284 arvif->vdev_id, bss_conf->bssid, ret);
2285 return;
2286 }
2287
Michal Kazior7aa7a722014-08-25 12:09:38 +02002288 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002289 "mac vdev %d up (associated) bssid %pM aid %d\n",
2290 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
2291
Michal Kazior077efc82014-10-21 10:10:29 +03002292 WARN_ON(arvif->is_up);
2293
Michal Kaziorc930f742014-01-23 11:38:25 +01002294 arvif->aid = bss_conf->aid;
Kalle Valob25f32c2014-09-14 12:50:49 +03002295 ether_addr_copy(arvif->bssid, bss_conf->bssid);
Michal Kaziorc930f742014-01-23 11:38:25 +01002296
2297 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
2298 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002299 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002300 arvif->vdev_id, ret);
Michal Kaziorc930f742014-01-23 11:38:25 +01002301 return;
2302 }
2303
2304 arvif->is_up = true;
Michal Kazior0a987fb2015-02-13 13:30:15 +01002305
2306 /* Workaround: Some firmware revisions (tested with qca6174
2307 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2308 * poked with peer param command.
2309 */
2310 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
2311 WMI_PEER_DUMMY_VAR, 1);
2312 if (ret) {
2313 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2314 arvif->bssid, arvif->vdev_id, ret);
2315 return;
2316 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002317}
2318
Kalle Valo5e3dd152013-06-12 20:52:10 +03002319static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
2320 struct ieee80211_vif *vif)
2321{
2322 struct ath10k *ar = hw->priv;
2323 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior139e1702015-02-15 16:50:42 +02002324 struct ieee80211_sta_vht_cap vht_cap = {};
Kalle Valo5e3dd152013-06-12 20:52:10 +03002325 int ret;
2326
Michal Kazior548db542013-07-05 16:15:15 +03002327 lockdep_assert_held(&ar->conf_mutex);
2328
Michal Kazior077efc82014-10-21 10:10:29 +03002329 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
2330 arvif->vdev_id, arvif->bssid);
Kalle Valo60c3daa2013-09-08 17:56:07 +03002331
Kalle Valo5e3dd152013-06-12 20:52:10 +03002332 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kazior077efc82014-10-21 10:10:29 +03002333 if (ret)
2334 ath10k_warn(ar, "faield to down vdev %i: %d\n",
2335 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002336
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02002337 arvif->def_wep_key_idx = -1;
2338
Michal Kazior139e1702015-02-15 16:50:42 +02002339 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2340 if (ret) {
2341 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
2342 arvif->vdev_id, ret);
2343 return;
2344 }
2345
Michal Kaziorc930f742014-01-23 11:38:25 +01002346 arvif->is_up = false;
Michal Kaziorcc9904e2015-03-10 16:22:01 +02002347
2348 cancel_delayed_work_sync(&arvif->connection_loss_work);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002349}
2350
Michal Kazior590922a2014-10-21 10:10:29 +03002351static int ath10k_station_assoc(struct ath10k *ar,
2352 struct ieee80211_vif *vif,
2353 struct ieee80211_sta *sta,
2354 bool reassoc)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002355{
Michal Kazior590922a2014-10-21 10:10:29 +03002356 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valob9ada652013-10-16 15:44:46 +03002357 struct wmi_peer_assoc_complete_arg peer_arg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002358 int ret = 0;
2359
Michal Kazior548db542013-07-05 16:15:15 +03002360 lockdep_assert_held(&ar->conf_mutex);
2361
Michal Kazior590922a2014-10-21 10:10:29 +03002362 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002363 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002364 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02002365 sta->addr, arvif->vdev_id, ret);
Kalle Valob9ada652013-10-16 15:44:46 +03002366 return ret;
2367 }
2368
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02002369 peer_arg.peer_reassoc = reassoc;
Kalle Valob9ada652013-10-16 15:44:46 +03002370 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2371 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002372 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002373 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002374 return ret;
2375 }
2376
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002377 /* Re-assoc is run only to update supported rates for given station. It
2378 * doesn't make much sense to reconfigure the peer completely.
2379 */
2380 if (!reassoc) {
2381 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
2382 &sta->ht_cap);
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002383 if (ret) {
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002384 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002385 arvif->vdev_id, ret);
2386 return ret;
2387 }
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002388
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002389 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
2390 if (ret) {
2391 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
2392 sta->addr, arvif->vdev_id, ret);
2393 return ret;
2394 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002395
Michal Kaziorb1ecde32014-10-21 10:10:29 +03002396 if (!sta->wme) {
2397 arvif->num_legacy_stations++;
2398 ret = ath10k_recalc_rtscts_prot(arvif);
2399 if (ret) {
2400 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2401 arvif->vdev_id, ret);
2402 return ret;
2403 }
2404 }
2405
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02002406 /* Plumb cached keys only for static WEP */
2407 if (arvif->def_wep_key_idx != -1) {
2408 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
2409 if (ret) {
2410 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
2411 arvif->vdev_id, ret);
2412 return ret;
2413 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002414 }
2415 }
2416
Kalle Valo5e3dd152013-06-12 20:52:10 +03002417 return ret;
2418}
2419
Michal Kazior590922a2014-10-21 10:10:29 +03002420static int ath10k_station_disassoc(struct ath10k *ar,
2421 struct ieee80211_vif *vif,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002422 struct ieee80211_sta *sta)
2423{
Michal Kazior590922a2014-10-21 10:10:29 +03002424 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002425 int ret = 0;
2426
2427 lockdep_assert_held(&ar->conf_mutex);
2428
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002429 if (!sta->wme) {
2430 arvif->num_legacy_stations--;
2431 ret = ath10k_recalc_rtscts_prot(arvif);
2432 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002433 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02002434 arvif->vdev_id, ret);
2435 return ret;
2436 }
2437 }
2438
Kalle Valo5e3dd152013-06-12 20:52:10 +03002439 ret = ath10k_clear_peer_keys(arvif, sta->addr);
2440 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002441 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02002442 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002443 return ret;
2444 }
2445
2446 return ret;
2447}
2448
2449/**************/
2450/* Regulatory */
2451/**************/
2452
2453static int ath10k_update_channel_list(struct ath10k *ar)
2454{
2455 struct ieee80211_hw *hw = ar->hw;
2456 struct ieee80211_supported_band **bands;
2457 enum ieee80211_band band;
2458 struct ieee80211_channel *channel;
2459 struct wmi_scan_chan_list_arg arg = {0};
2460 struct wmi_channel_arg *ch;
2461 bool passive;
2462 int len;
2463 int ret;
2464 int i;
2465
Michal Kazior548db542013-07-05 16:15:15 +03002466 lockdep_assert_held(&ar->conf_mutex);
2467
Kalle Valo5e3dd152013-06-12 20:52:10 +03002468 bands = hw->wiphy->bands;
2469 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2470 if (!bands[band])
2471 continue;
2472
2473 for (i = 0; i < bands[band]->n_channels; i++) {
2474 if (bands[band]->channels[i].flags &
2475 IEEE80211_CHAN_DISABLED)
2476 continue;
2477
2478 arg.n_channels++;
2479 }
2480 }
2481
2482 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
2483 arg.channels = kzalloc(len, GFP_KERNEL);
2484 if (!arg.channels)
2485 return -ENOMEM;
2486
2487 ch = arg.channels;
2488 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2489 if (!bands[band])
2490 continue;
2491
2492 for (i = 0; i < bands[band]->n_channels; i++) {
2493 channel = &bands[band]->channels[i];
2494
2495 if (channel->flags & IEEE80211_CHAN_DISABLED)
2496 continue;
2497
2498 ch->allow_ht = true;
2499
2500 /* FIXME: when should we really allow VHT? */
2501 ch->allow_vht = true;
2502
2503 ch->allow_ibss =
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002504 !(channel->flags & IEEE80211_CHAN_NO_IR);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002505
2506 ch->ht40plus =
2507 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
2508
Marek Puzyniake8a50f82013-11-20 09:59:47 +02002509 ch->chan_radar =
2510 !!(channel->flags & IEEE80211_CHAN_RADAR);
2511
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02002512 passive = channel->flags & IEEE80211_CHAN_NO_IR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002513 ch->passive = passive;
2514
2515 ch->freq = channel->center_freq;
Michal Kazior2d667212014-09-18 15:21:21 +02002516 ch->band_center_freq1 = channel->center_freq;
Michal Kazior89c5c842013-10-23 04:02:13 -07002517 ch->min_power = 0;
Michal Kazior02256932013-10-23 04:02:14 -07002518 ch->max_power = channel->max_power * 2;
2519 ch->max_reg_power = channel->max_reg_power * 2;
2520 ch->max_antenna_gain = channel->max_antenna_gain * 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002521 ch->reg_class_id = 0; /* FIXME */
2522
2523 /* FIXME: why use only legacy modes, why not any
2524 * HT/VHT modes? Would that even make any
2525 * difference? */
2526 if (channel->band == IEEE80211_BAND_2GHZ)
2527 ch->mode = MODE_11G;
2528 else
2529 ch->mode = MODE_11A;
2530
2531 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
2532 continue;
2533
Michal Kazior7aa7a722014-08-25 12:09:38 +02002534 ath10k_dbg(ar, ATH10K_DBG_WMI,
Kalle Valo60c3daa2013-09-08 17:56:07 +03002535 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
2536 ch - arg.channels, arg.n_channels,
Kalle Valo5e3dd152013-06-12 20:52:10 +03002537 ch->freq, ch->max_power, ch->max_reg_power,
2538 ch->max_antenna_gain, ch->mode);
2539
2540 ch++;
2541 }
2542 }
2543
2544 ret = ath10k_wmi_scan_chan_list(ar, &arg);
2545 kfree(arg.channels);
2546
2547 return ret;
2548}
2549
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002550static enum wmi_dfs_region
2551ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
2552{
2553 switch (dfs_region) {
2554 case NL80211_DFS_UNSET:
2555 return WMI_UNINIT_DFS_DOMAIN;
2556 case NL80211_DFS_FCC:
2557 return WMI_FCC_DFS_DOMAIN;
2558 case NL80211_DFS_ETSI:
2559 return WMI_ETSI_DFS_DOMAIN;
2560 case NL80211_DFS_JP:
2561 return WMI_MKK4_DFS_DOMAIN;
2562 }
2563 return WMI_UNINIT_DFS_DOMAIN;
2564}
2565
Michal Kaziorf7843d72013-07-16 09:38:52 +02002566static void ath10k_regd_update(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002567{
Kalle Valo5e3dd152013-06-12 20:52:10 +03002568 struct reg_dmn_pair_mapping *regpair;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002569 int ret;
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002570 enum wmi_dfs_region wmi_dfs_reg;
2571 enum nl80211_dfs_regions nl_dfs_reg;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002572
Michal Kaziorf7843d72013-07-16 09:38:52 +02002573 lockdep_assert_held(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002574
2575 ret = ath10k_update_channel_list(ar);
2576 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002577 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002578
2579 regpair = ar->ath_common.regulatory.regpair;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002580
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002581 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
2582 nl_dfs_reg = ar->dfs_detector->region;
2583 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
2584 } else {
2585 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
2586 }
2587
Kalle Valo5e3dd152013-06-12 20:52:10 +03002588 /* Target allows setting up per-band regdomain but ath_common provides
2589 * a combined one only */
2590 ret = ath10k_wmi_pdev_set_regdomain(ar,
Kalle Valoef8c0012014-02-13 18:13:12 +02002591 regpair->reg_domain,
2592 regpair->reg_domain, /* 2ghz */
2593 regpair->reg_domain, /* 5ghz */
Kalle Valo5e3dd152013-06-12 20:52:10 +03002594 regpair->reg_2ghz_ctl,
Marek Puzyniak821af6a2014-03-21 17:46:57 +02002595 regpair->reg_5ghz_ctl,
2596 wmi_dfs_reg);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002597 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002598 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
Michal Kaziorf7843d72013-07-16 09:38:52 +02002599}
Michal Kazior548db542013-07-05 16:15:15 +03002600
Michal Kaziorf7843d72013-07-16 09:38:52 +02002601static void ath10k_reg_notifier(struct wiphy *wiphy,
2602 struct regulatory_request *request)
2603{
2604 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
2605 struct ath10k *ar = hw->priv;
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002606 bool result;
Michal Kaziorf7843d72013-07-16 09:38:52 +02002607
2608 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
2609
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002610 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002611 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002612 request->dfs_region);
2613 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
2614 request->dfs_region);
2615 if (!result)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002616 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
Janusz Dziedzic9702c682013-11-20 09:59:41 +02002617 request->dfs_region);
2618 }
2619
Michal Kaziorf7843d72013-07-16 09:38:52 +02002620 mutex_lock(&ar->conf_mutex);
2621 if (ar->state == ATH10K_STATE_ON)
2622 ath10k_regd_update(ar);
Michal Kazior548db542013-07-05 16:15:15 +03002623 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002624}
2625
2626/***************/
2627/* TX handlers */
2628/***************/
2629
Michal Kazior42c3aa62013-10-02 11:03:38 +02002630static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
2631{
2632 if (ieee80211_is_mgmt(hdr->frame_control))
2633 return HTT_DATA_TX_EXT_TID_MGMT;
2634
2635 if (!ieee80211_is_data_qos(hdr->frame_control))
2636 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2637
2638 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
2639 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2640
2641 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
2642}
2643
Michal Kazior2b37c292014-09-02 11:00:22 +03002644static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002645{
Michal Kazior2b37c292014-09-02 11:00:22 +03002646 if (vif)
2647 return ath10k_vif_to_arvif(vif)->vdev_id;
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002648
Michal Kazior1bbc0972014-04-08 09:45:47 +03002649 if (ar->monitor_started)
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002650 return ar->monitor_vdev_id;
2651
Michal Kazior7aa7a722014-08-25 12:09:38 +02002652 ath10k_warn(ar, "failed to resolve vdev id\n");
Michal Kaziorddb6ad72013-10-02 11:03:39 +02002653 return 0;
2654}
2655
Michal Kaziord740d8f2015-03-30 09:51:51 +03002656static enum ath10k_hw_txrx_mode
2657ath10k_tx_h_get_txmode(struct ath10k *ar, struct ieee80211_vif *vif,
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03002658 struct ieee80211_sta *sta, struct sk_buff *skb)
Michal Kaziord740d8f2015-03-30 09:51:51 +03002659{
2660 const struct ieee80211_hdr *hdr = (void *)skb->data;
2661 __le16 fc = hdr->frame_control;
2662
2663 if (!vif || vif->type == NL80211_IFTYPE_MONITOR)
2664 return ATH10K_HW_TXRX_RAW;
2665
2666 if (ieee80211_is_mgmt(fc))
2667 return ATH10K_HW_TXRX_MGMT;
2668
2669 /* Workaround:
2670 *
2671 * NullFunc frames are mostly used to ping if a client or AP are still
2672 * reachable and responsive. This implies tx status reports must be
2673 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
2674 * come to a conclusion that the other end disappeared and tear down
2675 * BSS connection or it can never disconnect from BSS/client (which is
2676 * the case).
2677 *
2678 * Firmware with HTT older than 3.0 delivers incorrect tx status for
2679 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
2680 * which seems to deliver correct tx reports for NullFunc frames. The
2681 * downside of using it is it ignores client powersave state so it can
2682 * end up disconnecting sleeping clients in AP mode. It should fix STA
2683 * mode though because AP don't sleep.
2684 */
2685 if (ar->htt.target_version_major < 3 &&
2686 (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc)) &&
2687 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX, ar->fw_features))
2688 return ATH10K_HW_TXRX_MGMT;
2689
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03002690 /* Workaround:
2691 *
2692 * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
2693 * NativeWifi txmode - it selects AP key instead of peer key. It seems
2694 * to work with Ethernet txmode so use it.
2695 */
2696 if (ieee80211_is_data_present(fc) && sta && sta->tdls)
2697 return ATH10K_HW_TXRX_ETHERNET;
2698
Michal Kaziord740d8f2015-03-30 09:51:51 +03002699 return ATH10K_HW_TXRX_NATIVE_WIFI;
2700}
2701
Michal Kazior4b604552014-07-21 21:03:09 +03002702/* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
2703 * Control in the header.
Kalle Valo5e3dd152013-06-12 20:52:10 +03002704 */
Michal Kazior4b604552014-07-21 21:03:09 +03002705static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002706{
2707 struct ieee80211_hdr *hdr = (void *)skb->data;
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002708 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002709 u8 *qos_ctl;
2710
2711 if (!ieee80211_is_data_qos(hdr->frame_control))
2712 return;
2713
2714 qos_ctl = ieee80211_get_qos_ctl(hdr);
Michal Kaziorba0ccd72013-07-22 14:25:28 +02002715 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
2716 skb->data, (void *)qos_ctl - (void *)skb->data);
2717 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002718
Michal Kazior8bad8dc2015-03-11 14:25:26 +01002719 /* Some firmware revisions don't handle sending QoS NullFunc well.
2720 * These frames are mainly used for CQM purposes so it doesn't really
2721 * matter whether QoS NullFunc or NullFunc are sent.
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002722 */
Michal Kaziorbf0a26d2015-01-24 12:14:51 +02002723 hdr = (void *)skb->data;
Michal Kazior8bad8dc2015-03-11 14:25:26 +01002724 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
Michal Kaziorc21c64d2014-07-21 21:03:10 +03002725 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
Michal Kazior8bad8dc2015-03-11 14:25:26 +01002726
2727 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002728}
2729
Michal Kaziord740d8f2015-03-30 09:51:51 +03002730static void ath10k_tx_h_8023(struct sk_buff *skb)
2731{
2732 struct ieee80211_hdr *hdr;
2733 struct rfc1042_hdr *rfc1042;
2734 struct ethhdr *eth;
2735 size_t hdrlen;
2736 u8 da[ETH_ALEN];
2737 u8 sa[ETH_ALEN];
2738 __be16 type;
2739
2740 hdr = (void *)skb->data;
2741 hdrlen = ieee80211_hdrlen(hdr->frame_control);
2742 rfc1042 = (void *)skb->data + hdrlen;
2743
2744 ether_addr_copy(da, ieee80211_get_DA(hdr));
2745 ether_addr_copy(sa, ieee80211_get_SA(hdr));
2746 type = rfc1042->snap_type;
2747
2748 skb_pull(skb, hdrlen + sizeof(*rfc1042));
2749 skb_push(skb, sizeof(*eth));
2750
2751 eth = (void *)skb->data;
2752 ether_addr_copy(eth->h_dest, da);
2753 ether_addr_copy(eth->h_source, sa);
2754 eth->h_proto = type;
2755}
2756
Michal Kazior4b604552014-07-21 21:03:09 +03002757static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
2758 struct ieee80211_vif *vif,
2759 struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002760{
2761 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002762 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2763
2764 /* This is case only for P2P_GO */
2765 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
2766 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
2767 return;
2768
2769 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
2770 spin_lock_bh(&ar->data_lock);
2771 if (arvif->u.ap.noa_data)
2772 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
2773 GFP_ATOMIC))
2774 memcpy(skb_put(skb, arvif->u.ap.noa_len),
2775 arvif->u.ap.noa_data,
2776 arvif->u.ap.noa_len);
2777 spin_unlock_bh(&ar->data_lock);
2778 }
2779}
2780
Michal Kazior8d6d3622014-11-24 14:58:31 +01002781static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar)
2782{
2783 /* FIXME: Not really sure since when the behaviour changed. At some
2784 * point new firmware stopped requiring creation of peer entries for
2785 * offchannel tx (and actually creating them causes issues with wmi-htc
2786 * tx credit replenishment and reliability). Assuming it's at least 3.4
2787 * because that's when the `freq` was introduced to TX_FRM HTT command.
2788 */
2789 return !(ar->htt.target_version_major >= 3 &&
2790 ar->htt.target_version_minor >= 4);
2791}
2792
Michal Kaziord740d8f2015-03-30 09:51:51 +03002793static int ath10k_mac_tx_wmi_mgmt(struct ath10k *ar, struct sk_buff *skb)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002794{
Michal Kaziord740d8f2015-03-30 09:51:51 +03002795 struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002796 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002797
Michal Kaziord740d8f2015-03-30 09:51:51 +03002798 spin_lock_bh(&ar->data_lock);
2799
2800 if (skb_queue_len(q) == ATH10K_MAX_NUM_MGMT_PENDING) {
2801 ath10k_warn(ar, "wmi mgmt tx queue is full\n");
2802 ret = -ENOSPC;
2803 goto unlock;
Michal Kazior961d4c32013-08-09 10:13:34 +02002804 }
2805
Michal Kaziord740d8f2015-03-30 09:51:51 +03002806 __skb_queue_tail(q, skb);
2807 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
2808
2809unlock:
2810 spin_unlock_bh(&ar->data_lock);
2811
2812 return ret;
2813}
2814
2815static void ath10k_mac_tx(struct ath10k *ar, struct sk_buff *skb)
2816{
2817 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
2818 struct ath10k_htt *htt = &ar->htt;
2819 int ret = 0;
2820
2821 switch (cb->txmode) {
2822 case ATH10K_HW_TXRX_RAW:
2823 case ATH10K_HW_TXRX_NATIVE_WIFI:
2824 case ATH10K_HW_TXRX_ETHERNET:
2825 ret = ath10k_htt_tx(htt, skb);
2826 break;
2827 case ATH10K_HW_TXRX_MGMT:
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002828 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
Michal Kaziord740d8f2015-03-30 09:51:51 +03002829 ar->fw_features))
2830 ret = ath10k_mac_tx_wmi_mgmt(ar, skb);
2831 else if (ar->htt.target_version_major >= 3)
2832 ret = ath10k_htt_tx(htt, skb);
2833 else
2834 ret = ath10k_htt_mgmt_tx(htt, skb);
2835 break;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002836 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03002837
2838 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002839 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
2840 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002841 ieee80211_free_txskb(ar->hw, skb);
2842 }
2843}
2844
2845void ath10k_offchan_tx_purge(struct ath10k *ar)
2846{
2847 struct sk_buff *skb;
2848
2849 for (;;) {
2850 skb = skb_dequeue(&ar->offchan_tx_queue);
2851 if (!skb)
2852 break;
2853
2854 ieee80211_free_txskb(ar->hw, skb);
2855 }
2856}
2857
2858void ath10k_offchan_tx_work(struct work_struct *work)
2859{
2860 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
2861 struct ath10k_peer *peer;
2862 struct ieee80211_hdr *hdr;
2863 struct sk_buff *skb;
2864 const u8 *peer_addr;
2865 int vdev_id;
2866 int ret;
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +03002867 unsigned long time_left;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002868
2869 /* FW requirement: We must create a peer before FW will send out
2870 * an offchannel frame. Otherwise the frame will be stuck and
2871 * never transmitted. We delete the peer upon tx completion.
2872 * It is unlikely that a peer for offchannel tx will already be
2873 * present. However it may be in some rare cases so account for that.
2874 * Otherwise we might remove a legitimate peer and break stuff. */
2875
2876 for (;;) {
2877 skb = skb_dequeue(&ar->offchan_tx_queue);
2878 if (!skb)
2879 break;
2880
2881 mutex_lock(&ar->conf_mutex);
2882
Michal Kazior7aa7a722014-08-25 12:09:38 +02002883 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002884 skb);
2885
2886 hdr = (struct ieee80211_hdr *)skb->data;
2887 peer_addr = ieee80211_get_DA(hdr);
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002888 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002889
2890 spin_lock_bh(&ar->data_lock);
2891 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
2892 spin_unlock_bh(&ar->data_lock);
2893
2894 if (peer)
Kalle Valo60c3daa2013-09-08 17:56:07 +03002895 /* FIXME: should this use ath10k_warn()? */
Michal Kazior7aa7a722014-08-25 12:09:38 +02002896 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002897 peer_addr, vdev_id);
2898
2899 if (!peer) {
Marek Puzyniak7390ed32015-03-30 09:51:52 +03002900 ret = ath10k_peer_create(ar, vdev_id, peer_addr,
2901 WMI_PEER_TYPE_DEFAULT);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002902 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002903 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002904 peer_addr, vdev_id, ret);
2905 }
2906
2907 spin_lock_bh(&ar->data_lock);
Wolfram Sang16735d02013-11-14 14:32:02 -08002908 reinit_completion(&ar->offchan_tx_completed);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002909 ar->offchan_tx_skb = skb;
2910 spin_unlock_bh(&ar->data_lock);
2911
Michal Kaziord740d8f2015-03-30 09:51:51 +03002912 ath10k_mac_tx(ar, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002913
Nicholas Mc Guire8e9904f52015-03-30 15:39:19 +03002914 time_left =
2915 wait_for_completion_timeout(&ar->offchan_tx_completed, 3 * HZ);
2916 if (time_left == 0)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002917 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002918 skb);
2919
2920 if (!peer) {
2921 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
2922 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02002923 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03002924 peer_addr, vdev_id, ret);
2925 }
2926
2927 mutex_unlock(&ar->conf_mutex);
2928 }
2929}
2930
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002931void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
2932{
2933 struct sk_buff *skb;
2934
2935 for (;;) {
2936 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2937 if (!skb)
2938 break;
2939
2940 ieee80211_free_txskb(ar->hw, skb);
2941 }
2942}
2943
2944void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
2945{
2946 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
2947 struct sk_buff *skb;
2948 int ret;
2949
2950 for (;;) {
2951 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2952 if (!skb)
2953 break;
2954
2955 ret = ath10k_wmi_mgmt_tx(ar, skb);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002956 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02002957 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02002958 ret);
Michal Kazior5fb5e412013-10-28 07:18:13 +01002959 ieee80211_free_txskb(ar->hw, skb);
2960 }
Bartosz Markowski5e00d312013-09-26 17:47:12 +02002961 }
2962}
2963
Kalle Valo5e3dd152013-06-12 20:52:10 +03002964/************/
2965/* Scanning */
2966/************/
2967
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002968void __ath10k_scan_finish(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03002969{
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002970 lockdep_assert_held(&ar->data_lock);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002971
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002972 switch (ar->scan.state) {
2973 case ATH10K_SCAN_IDLE:
2974 break;
2975 case ATH10K_SCAN_RUNNING:
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002976 if (ar->scan.is_roc)
2977 ieee80211_remain_on_channel_expired(ar->hw);
John W. Linvillef6eaf1e2015-01-12 16:07:02 -05002978 /* fall through */
Michal Kazior7305d3e2014-11-24 14:58:33 +01002979 case ATH10K_SCAN_ABORTING:
2980 if (!ar->scan.is_roc)
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002981 ieee80211_scan_completed(ar->hw,
2982 (ar->scan.state ==
2983 ATH10K_SCAN_ABORTING));
2984 /* fall through */
2985 case ATH10K_SCAN_STARTING:
2986 ar->scan.state = ATH10K_SCAN_IDLE;
2987 ar->scan_channel = NULL;
2988 ath10k_offchan_tx_purge(ar);
2989 cancel_delayed_work(&ar->scan.timeout);
2990 complete_all(&ar->scan.completed);
2991 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03002992 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002993}
Kalle Valo5e3dd152013-06-12 20:52:10 +03002994
Michal Kazior5c81c7f2014-08-05 14:54:44 +02002995void ath10k_scan_finish(struct ath10k *ar)
2996{
2997 spin_lock_bh(&ar->data_lock);
2998 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03002999 spin_unlock_bh(&ar->data_lock);
3000}
3001
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003002static int ath10k_scan_stop(struct ath10k *ar)
Kalle Valo5e3dd152013-06-12 20:52:10 +03003003{
3004 struct wmi_stop_scan_arg arg = {
3005 .req_id = 1, /* FIXME */
3006 .req_type = WMI_SCAN_STOP_ONE,
3007 .u.scan_id = ATH10K_SCAN_ID,
3008 };
3009 int ret;
3010
3011 lockdep_assert_held(&ar->conf_mutex);
3012
Kalle Valo5e3dd152013-06-12 20:52:10 +03003013 ret = ath10k_wmi_stop_scan(ar, &arg);
3014 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003015 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003016 goto out;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003017 }
3018
Kalle Valo5e3dd152013-06-12 20:52:10 +03003019 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003020 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003021 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003022 ret = -ETIMEDOUT;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003023 } else if (ret > 0) {
3024 ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003025 }
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003026
3027out:
3028 /* Scan state should be updated upon scan completion but in case
3029 * firmware fails to deliver the event (for whatever reason) it is
3030 * desired to clean up scan state anyway. Firmware may have just
3031 * dropped the scan completion event delivery due to transport pipe
3032 * being overflown with data and/or it can recover on its own before
3033 * next scan request is submitted.
3034 */
3035 spin_lock_bh(&ar->data_lock);
3036 if (ar->scan.state != ATH10K_SCAN_IDLE)
3037 __ath10k_scan_finish(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003038 spin_unlock_bh(&ar->data_lock);
3039
3040 return ret;
3041}
3042
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003043static void ath10k_scan_abort(struct ath10k *ar)
3044{
3045 int ret;
3046
3047 lockdep_assert_held(&ar->conf_mutex);
3048
3049 spin_lock_bh(&ar->data_lock);
3050
3051 switch (ar->scan.state) {
3052 case ATH10K_SCAN_IDLE:
3053 /* This can happen if timeout worker kicked in and called
3054 * abortion while scan completion was being processed.
3055 */
3056 break;
3057 case ATH10K_SCAN_STARTING:
3058 case ATH10K_SCAN_ABORTING:
Michal Kazior7aa7a722014-08-25 12:09:38 +02003059 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003060 ath10k_scan_state_str(ar->scan.state),
3061 ar->scan.state);
3062 break;
3063 case ATH10K_SCAN_RUNNING:
3064 ar->scan.state = ATH10K_SCAN_ABORTING;
3065 spin_unlock_bh(&ar->data_lock);
3066
3067 ret = ath10k_scan_stop(ar);
3068 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003069 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003070
3071 spin_lock_bh(&ar->data_lock);
3072 break;
3073 }
3074
3075 spin_unlock_bh(&ar->data_lock);
3076}
3077
3078void ath10k_scan_timeout_work(struct work_struct *work)
3079{
3080 struct ath10k *ar = container_of(work, struct ath10k,
3081 scan.timeout.work);
3082
3083 mutex_lock(&ar->conf_mutex);
3084 ath10k_scan_abort(ar);
3085 mutex_unlock(&ar->conf_mutex);
3086}
3087
Kalle Valo5e3dd152013-06-12 20:52:10 +03003088static int ath10k_start_scan(struct ath10k *ar,
3089 const struct wmi_start_scan_arg *arg)
3090{
3091 int ret;
3092
3093 lockdep_assert_held(&ar->conf_mutex);
3094
3095 ret = ath10k_wmi_start_scan(ar, arg);
3096 if (ret)
3097 return ret;
3098
Kalle Valo5e3dd152013-06-12 20:52:10 +03003099 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
3100 if (ret == 0) {
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003101 ret = ath10k_scan_stop(ar);
3102 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003103 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003104
3105 return -ETIMEDOUT;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003106 }
3107
Ben Greear2f9eec02015-02-15 16:50:38 +02003108 /* If we failed to start the scan, return error code at
3109 * this point. This is probably due to some issue in the
3110 * firmware, but no need to wedge the driver due to that...
3111 */
3112 spin_lock_bh(&ar->data_lock);
3113 if (ar->scan.state == ATH10K_SCAN_IDLE) {
3114 spin_unlock_bh(&ar->data_lock);
3115 return -EINVAL;
3116 }
3117 spin_unlock_bh(&ar->data_lock);
3118
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003119 /* Add a 200ms margin to account for event/command processing */
3120 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
3121 msecs_to_jiffies(arg->max_scan_time+200));
Kalle Valo5e3dd152013-06-12 20:52:10 +03003122 return 0;
3123}
3124
3125/**********************/
3126/* mac80211 callbacks */
3127/**********************/
3128
3129static void ath10k_tx(struct ieee80211_hw *hw,
3130 struct ieee80211_tx_control *control,
3131 struct sk_buff *skb)
3132{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003133 struct ath10k *ar = hw->priv;
Michal Kazior4b604552014-07-21 21:03:09 +03003134 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3135 struct ieee80211_vif *vif = info->control.vif;
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003136 struct ieee80211_sta *sta = control->sta;
Michal Kazior4b604552014-07-21 21:03:09 +03003137 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Michal Kaziord740d8f2015-03-30 09:51:51 +03003138 __le16 fc = hdr->frame_control;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003139
3140 /* We should disable CCK RATE due to P2P */
3141 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003142 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003143
Michal Kazior4b604552014-07-21 21:03:09 +03003144 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
Michal Kazior6fcafef2015-03-30 09:51:51 +03003145 ATH10K_SKB_CB(skb)->htt.freq = 0;
Michal Kazior4b604552014-07-21 21:03:09 +03003146 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
Michal Kazior2b37c292014-09-02 11:00:22 +03003147 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03003148 ATH10K_SKB_CB(skb)->txmode = ath10k_tx_h_get_txmode(ar, vif, sta, skb);
Michal Kaziord740d8f2015-03-30 09:51:51 +03003149 ATH10K_SKB_CB(skb)->is_protected = ieee80211_has_protected(fc);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003150
Michal Kaziord740d8f2015-03-30 09:51:51 +03003151 switch (ATH10K_SKB_CB(skb)->txmode) {
3152 case ATH10K_HW_TXRX_MGMT:
3153 case ATH10K_HW_TXRX_NATIVE_WIFI:
Michal Kazior4b604552014-07-21 21:03:09 +03003154 ath10k_tx_h_nwifi(hw, skb);
Michal Kazior4b604552014-07-21 21:03:09 +03003155 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
3156 ath10k_tx_h_seq_no(vif, skb);
Michal Kaziord740d8f2015-03-30 09:51:51 +03003157 break;
3158 case ATH10K_HW_TXRX_ETHERNET:
3159 ath10k_tx_h_8023(skb);
3160 break;
3161 case ATH10K_HW_TXRX_RAW:
3162 /* FIXME: Packet injection isn't implemented. It should be
3163 * doable with firmware 10.2 on qca988x.
3164 */
3165 WARN_ON_ONCE(1);
3166 ieee80211_free_txskb(hw, skb);
3167 return;
Michal Kaziorcf84bd42013-07-16 11:04:54 +02003168 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003169
Kalle Valo5e3dd152013-06-12 20:52:10 +03003170 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
3171 spin_lock_bh(&ar->data_lock);
Michal Kazior8d6d3622014-11-24 14:58:31 +01003172 ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq;
Bartosz Markowski5e00d312013-09-26 17:47:12 +02003173 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003174 spin_unlock_bh(&ar->data_lock);
3175
Michal Kazior8d6d3622014-11-24 14:58:31 +01003176 if (ath10k_mac_need_offchan_tx_work(ar)) {
3177 ATH10K_SKB_CB(skb)->htt.freq = 0;
3178 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003179
Michal Kazior8d6d3622014-11-24 14:58:31 +01003180 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
3181 skb);
3182
3183 skb_queue_tail(&ar->offchan_tx_queue, skb);
3184 ieee80211_queue_work(hw, &ar->offchan_tx_work);
3185 return;
3186 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003187 }
3188
Michal Kaziord740d8f2015-03-30 09:51:51 +03003189 ath10k_mac_tx(ar, skb);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003190}
3191
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003192/* Must not be called with conf_mutex held as workers can use that also. */
Michal Kazior7962b0d2014-10-28 10:34:38 +01003193void ath10k_drain_tx(struct ath10k *ar)
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003194{
3195 /* make sure rcu-protected mac80211 tx path itself is drained */
3196 synchronize_net();
3197
3198 ath10k_offchan_tx_purge(ar);
3199 ath10k_mgmt_over_wmi_tx_purge(ar);
3200
3201 cancel_work_sync(&ar->offchan_tx_work);
3202 cancel_work_sync(&ar->wmi_mgmt_tx_work);
3203}
3204
Michal Kazioraffd3212013-07-16 09:54:35 +02003205void ath10k_halt(struct ath10k *ar)
Michal Kazior818bdd12013-07-16 09:38:57 +02003206{
Michal Kaziord9bc4b92014-04-23 19:30:06 +03003207 struct ath10k_vif *arvif;
3208
Michal Kazior818bdd12013-07-16 09:38:57 +02003209 lockdep_assert_held(&ar->conf_mutex);
3210
Michal Kazior19337472014-08-28 12:58:16 +02003211 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
3212 ar->filter_flags = 0;
3213 ar->monitor = false;
3214
3215 if (ar->monitor_started)
Michal Kazior1bbc0972014-04-08 09:45:47 +03003216 ath10k_monitor_stop(ar);
Michal Kazior19337472014-08-28 12:58:16 +02003217
3218 ar->monitor_started = false;
Michal Kazior1bbc0972014-04-08 09:45:47 +03003219
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003220 ath10k_scan_finish(ar);
Michal Kazior818bdd12013-07-16 09:38:57 +02003221 ath10k_peer_cleanup_all(ar);
3222 ath10k_core_stop(ar);
3223 ath10k_hif_power_down(ar);
3224
3225 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03003226 list_for_each_entry(arvif, &ar->arvifs, list)
3227 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kazior818bdd12013-07-16 09:38:57 +02003228 spin_unlock_bh(&ar->data_lock);
3229}
3230
Ben Greear46acf7b2014-05-16 17:15:38 +03003231static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
3232{
3233 struct ath10k *ar = hw->priv;
3234
3235 mutex_lock(&ar->conf_mutex);
3236
3237 if (ar->cfg_tx_chainmask) {
3238 *tx_ant = ar->cfg_tx_chainmask;
3239 *rx_ant = ar->cfg_rx_chainmask;
3240 } else {
3241 *tx_ant = ar->supp_tx_chainmask;
3242 *rx_ant = ar->supp_rx_chainmask;
3243 }
3244
3245 mutex_unlock(&ar->conf_mutex);
3246
3247 return 0;
3248}
3249
Ben Greear5572a952014-11-24 16:22:10 +02003250static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
3251{
3252 /* It is not clear that allowing gaps in chainmask
3253 * is helpful. Probably it will not do what user
3254 * is hoping for, so warn in that case.
3255 */
3256 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
3257 return;
3258
3259 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
3260 dbg, cm);
3261}
3262
Ben Greear46acf7b2014-05-16 17:15:38 +03003263static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
3264{
3265 int ret;
3266
3267 lockdep_assert_held(&ar->conf_mutex);
3268
Ben Greear5572a952014-11-24 16:22:10 +02003269 ath10k_check_chain_mask(ar, tx_ant, "tx");
3270 ath10k_check_chain_mask(ar, rx_ant, "rx");
3271
Ben Greear46acf7b2014-05-16 17:15:38 +03003272 ar->cfg_tx_chainmask = tx_ant;
3273 ar->cfg_rx_chainmask = rx_ant;
3274
3275 if ((ar->state != ATH10K_STATE_ON) &&
3276 (ar->state != ATH10K_STATE_RESTARTED))
3277 return 0;
3278
3279 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
3280 tx_ant);
3281 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003282 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03003283 ret, tx_ant);
3284 return ret;
3285 }
3286
3287 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
3288 rx_ant);
3289 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003290 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
Ben Greear46acf7b2014-05-16 17:15:38 +03003291 ret, rx_ant);
3292 return ret;
3293 }
3294
3295 return 0;
3296}
3297
3298static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
3299{
3300 struct ath10k *ar = hw->priv;
3301 int ret;
3302
3303 mutex_lock(&ar->conf_mutex);
3304 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
3305 mutex_unlock(&ar->conf_mutex);
3306 return ret;
3307}
3308
Kalle Valo5e3dd152013-06-12 20:52:10 +03003309static int ath10k_start(struct ieee80211_hw *hw)
3310{
3311 struct ath10k *ar = hw->priv;
Michal Kazior818bdd12013-07-16 09:38:57 +02003312 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003313
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003314 /*
3315 * This makes sense only when restarting hw. It is harmless to call
3316 * uncoditionally. This is necessary to make sure no HTT/WMI tx
3317 * commands will be submitted while restarting.
3318 */
3319 ath10k_drain_tx(ar);
3320
Michal Kazior548db542013-07-05 16:15:15 +03003321 mutex_lock(&ar->conf_mutex);
3322
Michal Kaziorc5058f52014-05-26 12:46:03 +03003323 switch (ar->state) {
3324 case ATH10K_STATE_OFF:
3325 ar->state = ATH10K_STATE_ON;
3326 break;
3327 case ATH10K_STATE_RESTARTING:
3328 ath10k_halt(ar);
3329 ar->state = ATH10K_STATE_RESTARTED;
3330 break;
3331 case ATH10K_STATE_ON:
3332 case ATH10K_STATE_RESTARTED:
3333 case ATH10K_STATE_WEDGED:
3334 WARN_ON(1);
Michal Kazior818bdd12013-07-16 09:38:57 +02003335 ret = -EINVAL;
Michal Kaziorae254432014-05-26 12:46:02 +03003336 goto err;
Kalle Valo43d2a302014-09-10 18:23:30 +03003337 case ATH10K_STATE_UTF:
3338 ret = -EBUSY;
3339 goto err;
Michal Kazior818bdd12013-07-16 09:38:57 +02003340 }
3341
3342 ret = ath10k_hif_power_up(ar);
3343 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003344 ath10k_err(ar, "Could not init hif: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003345 goto err_off;
Michal Kazior818bdd12013-07-16 09:38:57 +02003346 }
3347
Kalle Valo43d2a302014-09-10 18:23:30 +03003348 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
Michal Kazior818bdd12013-07-16 09:38:57 +02003349 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003350 ath10k_err(ar, "Could not init core: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003351 goto err_power_down;
Michal Kazior818bdd12013-07-16 09:38:57 +02003352 }
3353
Bartosz Markowski226a3392013-09-26 17:47:16 +02003354 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03003355 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003356 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003357 goto err_core_stop;
3358 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003359
Michal Kaziorc4dd0d02013-11-13 11:05:10 +01003360 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
Michal Kaziorae254432014-05-26 12:46:02 +03003361 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003362 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003363 goto err_core_stop;
3364 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003365
Ben Greear46acf7b2014-05-16 17:15:38 +03003366 if (ar->cfg_tx_chainmask)
3367 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
3368 ar->cfg_rx_chainmask);
3369
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003370 /*
3371 * By default FW set ARP frames ac to voice (6). In that case ARP
3372 * exchange is not working properly for UAPSD enabled AP. ARP requests
3373 * which arrives with access category 0 are processed by network stack
3374 * and send back with access category 0, but FW changes access category
3375 * to 6. Set ARP frames access category to best effort (0) solves
3376 * this problem.
3377 */
3378
3379 ret = ath10k_wmi_pdev_set_param(ar,
3380 ar->wmi.pdev_param->arp_ac_override, 0);
3381 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003382 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003383 ret);
Michal Kaziorae254432014-05-26 12:46:02 +03003384 goto err_core_stop;
Marek Puzyniakab6258e2014-01-29 15:03:31 +02003385 }
3386
Ashok Raj Nagarajan575f1c32015-03-19 16:37:59 +05303387 ret = ath10k_wmi_pdev_set_param(ar,
3388 ar->wmi.pdev_param->ani_enable, 1);
3389 if (ret) {
3390 ath10k_warn(ar, "failed to enable ani by default: %d\n",
3391 ret);
3392 goto err_core_stop;
3393 }
3394
Ashok Raj Nagarajanb3e71d72015-03-19 16:38:00 +05303395 ar->ani_enabled = true;
3396
Michal Kaziord6500972014-04-08 09:56:09 +03003397 ar->num_started_vdevs = 0;
Michal Kaziorf7843d72013-07-16 09:38:52 +02003398 ath10k_regd_update(ar);
3399
Simon Wunderlich855aed12014-08-02 09:12:54 +03003400 ath10k_spectral_start(ar);
Rajkumar Manoharan8515b5c2015-03-15 20:36:22 +05303401 ath10k_thermal_set_throttling(ar);
Simon Wunderlich855aed12014-08-02 09:12:54 +03003402
Michal Kaziorae254432014-05-26 12:46:02 +03003403 mutex_unlock(&ar->conf_mutex);
3404 return 0;
3405
3406err_core_stop:
3407 ath10k_core_stop(ar);
3408
3409err_power_down:
3410 ath10k_hif_power_down(ar);
3411
3412err_off:
3413 ar->state = ATH10K_STATE_OFF;
3414
3415err:
Michal Kazior548db542013-07-05 16:15:15 +03003416 mutex_unlock(&ar->conf_mutex);
Michal Kaziorc60bdd82014-01-29 07:26:31 +01003417 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003418}
3419
3420static void ath10k_stop(struct ieee80211_hw *hw)
3421{
3422 struct ath10k *ar = hw->priv;
3423
Michal Kaziorbca7baf2014-05-26 12:46:03 +03003424 ath10k_drain_tx(ar);
3425
Michal Kazior548db542013-07-05 16:15:15 +03003426 mutex_lock(&ar->conf_mutex);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003427 if (ar->state != ATH10K_STATE_OFF) {
Michal Kazior818bdd12013-07-16 09:38:57 +02003428 ath10k_halt(ar);
Michal Kaziorc5058f52014-05-26 12:46:03 +03003429 ar->state = ATH10K_STATE_OFF;
3430 }
Michal Kazior548db542013-07-05 16:15:15 +03003431 mutex_unlock(&ar->conf_mutex);
3432
Michal Kazior5c81c7f2014-08-05 14:54:44 +02003433 cancel_delayed_work_sync(&ar->scan.timeout);
Michal Kazioraffd3212013-07-16 09:54:35 +02003434 cancel_work_sync(&ar->restart_work);
3435}
3436
Michal Kaziorad088bf2013-10-16 15:44:46 +03003437static int ath10k_config_ps(struct ath10k *ar)
Michal Kazioraffd3212013-07-16 09:54:35 +02003438{
Michal Kaziorad088bf2013-10-16 15:44:46 +03003439 struct ath10k_vif *arvif;
3440 int ret = 0;
Michal Kazioraffd3212013-07-16 09:54:35 +02003441
3442 lockdep_assert_held(&ar->conf_mutex);
3443
Michal Kaziorad088bf2013-10-16 15:44:46 +03003444 list_for_each_entry(arvif, &ar->arvifs, list) {
3445 ret = ath10k_mac_vif_setup_ps(arvif);
3446 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003447 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
Michal Kaziorad088bf2013-10-16 15:44:46 +03003448 break;
3449 }
3450 }
Michal Kazioraffd3212013-07-16 09:54:35 +02003451
Michal Kaziorad088bf2013-10-16 15:44:46 +03003452 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003453}
3454
Michal Kaziorc930f742014-01-23 11:38:25 +01003455static const char *chandef_get_width(enum nl80211_chan_width width)
3456{
3457 switch (width) {
3458 case NL80211_CHAN_WIDTH_20_NOHT:
3459 return "20 (noht)";
3460 case NL80211_CHAN_WIDTH_20:
3461 return "20";
3462 case NL80211_CHAN_WIDTH_40:
3463 return "40";
3464 case NL80211_CHAN_WIDTH_80:
3465 return "80";
3466 case NL80211_CHAN_WIDTH_80P80:
3467 return "80+80";
3468 case NL80211_CHAN_WIDTH_160:
3469 return "160";
3470 case NL80211_CHAN_WIDTH_5:
3471 return "5";
3472 case NL80211_CHAN_WIDTH_10:
3473 return "10";
3474 }
3475 return "?";
3476}
3477
3478static void ath10k_config_chan(struct ath10k *ar)
3479{
3480 struct ath10k_vif *arvif;
Michal Kaziorc930f742014-01-23 11:38:25 +01003481 int ret;
3482
3483 lockdep_assert_held(&ar->conf_mutex);
3484
Michal Kazior7aa7a722014-08-25 12:09:38 +02003485 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziorc930f742014-01-23 11:38:25 +01003486 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
3487 ar->chandef.chan->center_freq,
3488 ar->chandef.center_freq1,
3489 ar->chandef.center_freq2,
3490 chandef_get_width(ar->chandef.width));
3491
3492 /* First stop monitor interface. Some FW versions crash if there's a
3493 * lone monitor interface. */
Michal Kazior1bbc0972014-04-08 09:45:47 +03003494 if (ar->monitor_started)
Michal Kazior19337472014-08-28 12:58:16 +02003495 ath10k_monitor_stop(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003496
3497 list_for_each_entry(arvif, &ar->arvifs, list) {
3498 if (!arvif->is_started)
3499 continue;
3500
Michal Kaziordc55e302014-07-29 12:53:36 +03003501 if (!arvif->is_up)
3502 continue;
3503
Michal Kaziorc930f742014-01-23 11:38:25 +01003504 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3505 continue;
3506
Michal Kaziordc55e302014-07-29 12:53:36 +03003507 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
Michal Kaziorc930f742014-01-23 11:38:25 +01003508 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003509 ath10k_warn(ar, "failed to down vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003510 arvif->vdev_id, ret);
3511 continue;
3512 }
3513 }
3514
Michal Kaziordc55e302014-07-29 12:53:36 +03003515 /* all vdevs are downed now - attempt to restart and re-up them */
Michal Kaziorc930f742014-01-23 11:38:25 +01003516
3517 list_for_each_entry(arvif, &ar->arvifs, list) {
3518 if (!arvif->is_started)
3519 continue;
3520
3521 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3522 continue;
3523
Michal Kazior81a9a172015-03-05 16:02:17 +02003524 ret = ath10k_mac_setup_bcn_tmpl(arvif);
3525 if (ret)
3526 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
3527 ret);
3528
3529 ret = ath10k_mac_setup_prb_tmpl(arvif);
3530 if (ret)
3531 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
3532 ret);
3533
Michal Kaziordc55e302014-07-29 12:53:36 +03003534 ret = ath10k_vdev_restart(arvif);
Michal Kaziorc930f742014-01-23 11:38:25 +01003535 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003536 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003537 arvif->vdev_id, ret);
3538 continue;
3539 }
3540
3541 if (!arvif->is_up)
3542 continue;
3543
3544 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
3545 arvif->bssid);
3546 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003547 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
Michal Kaziorc930f742014-01-23 11:38:25 +01003548 arvif->vdev_id, ret);
3549 continue;
3550 }
3551 }
3552
Michal Kazior19337472014-08-28 12:58:16 +02003553 ath10k_monitor_recalc(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003554}
3555
Michal Kazior7d9d5582014-10-21 10:40:15 +03003556static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
3557{
3558 int ret;
3559 u32 param;
3560
3561 lockdep_assert_held(&ar->conf_mutex);
3562
3563 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
3564
3565 param = ar->wmi.pdev_param->txpower_limit2g;
3566 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3567 if (ret) {
3568 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
3569 txpower, ret);
3570 return ret;
3571 }
3572
3573 param = ar->wmi.pdev_param->txpower_limit5g;
3574 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3575 if (ret) {
3576 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
3577 txpower, ret);
3578 return ret;
3579 }
3580
3581 return 0;
3582}
3583
3584static int ath10k_mac_txpower_recalc(struct ath10k *ar)
3585{
3586 struct ath10k_vif *arvif;
3587 int ret, txpower = -1;
3588
3589 lockdep_assert_held(&ar->conf_mutex);
3590
3591 list_for_each_entry(arvif, &ar->arvifs, list) {
3592 WARN_ON(arvif->txpower < 0);
3593
3594 if (txpower == -1)
3595 txpower = arvif->txpower;
3596 else
3597 txpower = min(txpower, arvif->txpower);
3598 }
3599
3600 if (WARN_ON(txpower == -1))
3601 return -EINVAL;
3602
3603 ret = ath10k_mac_txpower_setup(ar, txpower);
3604 if (ret) {
3605 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
3606 txpower, ret);
3607 return ret;
3608 }
3609
3610 return 0;
3611}
3612
Kalle Valo5e3dd152013-06-12 20:52:10 +03003613static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
3614{
Kalle Valo5e3dd152013-06-12 20:52:10 +03003615 struct ath10k *ar = hw->priv;
3616 struct ieee80211_conf *conf = &hw->conf;
3617 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003618
3619 mutex_lock(&ar->conf_mutex);
3620
3621 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003622 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kaziord6500972014-04-08 09:56:09 +03003623 "mac config channel %dMHz flags 0x%x radar %d\n",
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003624 conf->chandef.chan->center_freq,
Michal Kaziord6500972014-04-08 09:56:09 +03003625 conf->chandef.chan->flags,
3626 conf->radar_enabled);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003627
Kalle Valo5e3dd152013-06-12 20:52:10 +03003628 spin_lock_bh(&ar->data_lock);
3629 ar->rx_channel = conf->chandef.chan;
3630 spin_unlock_bh(&ar->data_lock);
Marek Puzyniake8a50f82013-11-20 09:59:47 +02003631
Michal Kaziord6500972014-04-08 09:56:09 +03003632 ar->radar_enabled = conf->radar_enabled;
3633 ath10k_recalc_radar_detection(ar);
Michal Kaziorc930f742014-01-23 11:38:25 +01003634
3635 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
3636 ar->chandef = conf->chandef;
3637 ath10k_config_chan(ar);
3638 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003639 }
3640
Michal Kazioraffd3212013-07-16 09:54:35 +02003641 if (changed & IEEE80211_CONF_CHANGE_PS)
3642 ath10k_config_ps(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003643
3644 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
Michal Kazior19337472014-08-28 12:58:16 +02003645 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
3646 ret = ath10k_monitor_recalc(ar);
3647 if (ret)
3648 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003649 }
3650
3651 mutex_unlock(&ar->conf_mutex);
3652 return ret;
3653}
3654
Ben Greear5572a952014-11-24 16:22:10 +02003655static u32 get_nss_from_chainmask(u16 chain_mask)
3656{
3657 if ((chain_mask & 0x15) == 0x15)
3658 return 4;
3659 else if ((chain_mask & 0x7) == 0x7)
3660 return 3;
3661 else if ((chain_mask & 0x3) == 0x3)
3662 return 2;
3663 return 1;
3664}
3665
Kalle Valo5e3dd152013-06-12 20:52:10 +03003666/*
3667 * TODO:
3668 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
3669 * because we will send mgmt frames without CCK. This requirement
3670 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
3671 * in the TX packet.
3672 */
3673static int ath10k_add_interface(struct ieee80211_hw *hw,
3674 struct ieee80211_vif *vif)
3675{
3676 struct ath10k *ar = hw->priv;
3677 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3678 enum wmi_sta_powersave_param param;
3679 int ret = 0;
Kalle Valo5a13e762014-01-20 11:01:46 +02003680 u32 value;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003681 int bit;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003682 u32 vdev_param;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003683
Johannes Berg848955c2014-11-11 12:48:42 +01003684 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
3685
Kalle Valo5e3dd152013-06-12 20:52:10 +03003686 mutex_lock(&ar->conf_mutex);
3687
Michal Kazior0dbd09e2013-07-31 10:55:14 +02003688 memset(arvif, 0, sizeof(*arvif));
3689
Kalle Valo5e3dd152013-06-12 20:52:10 +03003690 arvif->ar = ar;
3691 arvif->vif = vif;
3692
Ben Greeare63b33f2013-10-22 14:54:14 -07003693 INIT_LIST_HEAD(&arvif->list);
Michal Kazior81a9a172015-03-05 16:02:17 +02003694 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
Michal Kaziorcc9904e2015-03-10 16:22:01 +02003695 INIT_DELAYED_WORK(&arvif->connection_loss_work,
3696 ath10k_mac_vif_sta_connection_loss_work);
Michal Kaziorcc4827b2013-10-16 15:44:45 +03003697
Ben Greeara9aefb32014-08-12 11:02:19 +03003698 if (ar->free_vdev_map == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003699 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003700 ret = -EBUSY;
Michal Kazior9dad14a2013-10-16 15:44:45 +03003701 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003702 }
Ben Greear16c11172014-09-23 14:17:16 -07003703 bit = __ffs64(ar->free_vdev_map);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003704
Ben Greear16c11172014-09-23 14:17:16 -07003705 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
3706 bit, ar->free_vdev_map);
3707
3708 arvif->vdev_id = bit;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003709 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003710
Kalle Valo5e3dd152013-06-12 20:52:10 +03003711 switch (vif->type) {
Michal Kazior75d2bd42014-12-12 12:41:39 +01003712 case NL80211_IFTYPE_P2P_DEVICE:
3713 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3714 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
3715 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003716 case NL80211_IFTYPE_UNSPECIFIED:
3717 case NL80211_IFTYPE_STATION:
3718 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3719 if (vif->p2p)
3720 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
3721 break;
3722 case NL80211_IFTYPE_ADHOC:
3723 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
3724 break;
3725 case NL80211_IFTYPE_AP:
3726 arvif->vdev_type = WMI_VDEV_TYPE_AP;
3727
3728 if (vif->p2p)
3729 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
3730 break;
3731 case NL80211_IFTYPE_MONITOR:
3732 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
3733 break;
3734 default:
3735 WARN_ON(1);
3736 break;
3737 }
3738
Michal Kazior64badcb2014-09-18 11:18:02 +03003739 /* Some firmware revisions don't wait for beacon tx completion before
3740 * sending another SWBA event. This could lead to hardware using old
3741 * (freed) beacon data in some cases, e.g. tx credit starvation
3742 * combined with missed TBTT. This is very very rare.
3743 *
3744 * On non-IOMMU-enabled hosts this could be a possible security issue
3745 * because hw could beacon some random data on the air. On
3746 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
3747 * device would crash.
3748 *
3749 * Since there are no beacon tx completions (implicit nor explicit)
3750 * propagated to host the only workaround for this is to allocate a
3751 * DMA-coherent buffer for a lifetime of a vif and use it for all
3752 * beacon tx commands. Worst case for this approach is some beacons may
3753 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
3754 */
3755 if (vif->type == NL80211_IFTYPE_ADHOC ||
3756 vif->type == NL80211_IFTYPE_AP) {
3757 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
3758 IEEE80211_MAX_FRAME_LEN,
3759 &arvif->beacon_paddr,
Rajkumar Manoharan82d7aba2014-10-10 17:38:27 +05303760 GFP_ATOMIC);
Michal Kazior64badcb2014-09-18 11:18:02 +03003761 if (!arvif->beacon_buf) {
3762 ret = -ENOMEM;
3763 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
3764 ret);
3765 goto err;
3766 }
3767 }
3768
3769 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
3770 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
3771 arvif->beacon_buf ? "single-buf" : "per-skb");
Kalle Valo5e3dd152013-06-12 20:52:10 +03003772
3773 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
3774 arvif->vdev_subtype, vif->addr);
3775 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003776 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003777 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003778 goto err;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003779 }
3780
Ben Greear16c11172014-09-23 14:17:16 -07003781 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
Michal Kazior05791192013-10-16 15:44:45 +03003782 list_add(&arvif->list, &ar->arvifs);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003783
Michal Kazior46725b152015-01-28 09:57:49 +02003784 /* It makes no sense to have firmware do keepalives. mac80211 already
3785 * takes care of this with idle connection polling.
3786 */
3787 ret = ath10k_mac_vif_disable_keepalive(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003788 if (ret) {
Michal Kazior46725b152015-01-28 09:57:49 +02003789 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003790 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003791 goto err_vdev_delete;
3792 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003793
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02003794 arvif->def_wep_key_idx = -1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003795
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02003796 vdev_param = ar->wmi.vdev_param->tx_encap_type;
3797 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03003798 ATH10K_HW_TXRX_NATIVE_WIFI);
Bartosz Markowskiebc9abd2013-10-15 09:26:20 +02003799 /* 10.X firmware does not support this VDEV parameter. Do not warn */
Michal Kazior9dad14a2013-10-16 15:44:45 +03003800 if (ret && ret != -EOPNOTSUPP) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003801 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003802 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003803 goto err_vdev_delete;
3804 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003805
Ben Greear5572a952014-11-24 16:22:10 +02003806 if (ar->cfg_tx_chainmask) {
3807 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
3808
3809 vdev_param = ar->wmi.vdev_param->nss;
3810 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3811 nss);
3812 if (ret) {
3813 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
3814 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
3815 ret);
3816 goto err_vdev_delete;
3817 }
3818 }
3819
Kalle Valo5e3dd152013-06-12 20:52:10 +03003820 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
Marek Puzyniak7390ed32015-03-30 09:51:52 +03003821 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr,
3822 WMI_PEER_TYPE_DEFAULT);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003823 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003824 ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003825 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003826 goto err_vdev_delete;
Kalle Valo5e3dd152013-06-12 20:52:10 +03003827 }
Marek Puzyniakcdf07402013-12-30 09:07:51 +01003828
Kalle Valo5a13e762014-01-20 11:01:46 +02003829 ret = ath10k_mac_set_kickout(arvif);
3830 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003831 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003832 arvif->vdev_id, ret);
Kalle Valo5a13e762014-01-20 11:01:46 +02003833 goto err_peer_delete;
3834 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003835 }
3836
3837 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
3838 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
3839 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3840 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3841 param, value);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003842 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003843 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003844 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003845 goto err_peer_delete;
3846 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003847
Michal Kazior9f9b5742014-12-12 12:41:36 +01003848 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003849 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01003850 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003851 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003852 goto err_peer_delete;
3853 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003854
Michal Kazior9f9b5742014-12-12 12:41:36 +01003855 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003856 if (ret) {
Michal Kazior9f9b5742014-12-12 12:41:36 +01003857 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003858 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003859 goto err_peer_delete;
3860 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03003861 }
3862
Michal Kazior424121c2013-07-22 14:13:31 +02003863 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003864 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003865 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003866 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003867 goto err_peer_delete;
3868 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003869
Michal Kazior424121c2013-07-22 14:13:31 +02003870 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003871 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02003872 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
Michal Kazior679c54a2013-07-05 16:15:04 +03003873 arvif->vdev_id, ret);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003874 goto err_peer_delete;
3875 }
Michal Kazior679c54a2013-07-05 16:15:04 +03003876
Michal Kazior7d9d5582014-10-21 10:40:15 +03003877 arvif->txpower = vif->bss_conf.txpower;
3878 ret = ath10k_mac_txpower_recalc(ar);
3879 if (ret) {
3880 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3881 goto err_peer_delete;
3882 }
3883
Kalle Valo5e3dd152013-06-12 20:52:10 +03003884 mutex_unlock(&ar->conf_mutex);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003885 return 0;
3886
3887err_peer_delete:
3888 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
3889 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
3890
3891err_vdev_delete:
3892 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
Ben Greear16c11172014-09-23 14:17:16 -07003893 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003894 list_del(&arvif->list);
Michal Kazior9dad14a2013-10-16 15:44:45 +03003895
3896err:
Michal Kazior64badcb2014-09-18 11:18:02 +03003897 if (arvif->beacon_buf) {
3898 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
3899 arvif->beacon_buf, arvif->beacon_paddr);
3900 arvif->beacon_buf = NULL;
3901 }
3902
Michal Kazior9dad14a2013-10-16 15:44:45 +03003903 mutex_unlock(&ar->conf_mutex);
3904
Kalle Valo5e3dd152013-06-12 20:52:10 +03003905 return ret;
3906}
3907
3908static void ath10k_remove_interface(struct ieee80211_hw *hw,
3909 struct ieee80211_vif *vif)
3910{
3911 struct ath10k *ar = hw->priv;
3912 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3913 int ret;
3914
Michal Kazior81a9a172015-03-05 16:02:17 +02003915 cancel_work_sync(&arvif->ap_csa_work);
Michal Kaziorcc9904e2015-03-10 16:22:01 +02003916 cancel_delayed_work_sync(&arvif->connection_loss_work);
Michal Kazior81a9a172015-03-05 16:02:17 +02003917
Sujith Manoharan5d011f52014-11-25 11:47:00 +05303918 mutex_lock(&ar->conf_mutex);
3919
Michal Kaziored543882013-09-13 14:16:56 +02003920 spin_lock_bh(&ar->data_lock);
Michal Kazior64badcb2014-09-18 11:18:02 +03003921 ath10k_mac_vif_beacon_cleanup(arvif);
Michal Kaziored543882013-09-13 14:16:56 +02003922 spin_unlock_bh(&ar->data_lock);
3923
Simon Wunderlich855aed12014-08-02 09:12:54 +03003924 ret = ath10k_spectral_vif_stop(arvif);
3925 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003926 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
Simon Wunderlich855aed12014-08-02 09:12:54 +03003927 arvif->vdev_id, ret);
3928
Ben Greear16c11172014-09-23 14:17:16 -07003929 ar->free_vdev_map |= 1LL << arvif->vdev_id;
Michal Kazior05791192013-10-16 15:44:45 +03003930 list_del(&arvif->list);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003931
3932 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
Michal Kazior2c512052015-02-15 16:50:40 +02003933 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
3934 vif->addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003935 if (ret)
Michal Kazior2c512052015-02-15 16:50:40 +02003936 ath10k_warn(ar, "failed to submit AP self-peer removal on vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003937 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003938
3939 kfree(arvif->u.ap.noa_data);
3940 }
3941
Michal Kazior7aa7a722014-08-25 12:09:38 +02003942 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03003943 arvif->vdev_id);
3944
Kalle Valo5e3dd152013-06-12 20:52:10 +03003945 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
3946 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02003947 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02003948 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03003949
Michal Kazior2c512052015-02-15 16:50:40 +02003950 /* Some firmware revisions don't notify host about self-peer removal
3951 * until after associated vdev is deleted.
3952 */
3953 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3954 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
3955 vif->addr);
3956 if (ret)
3957 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
3958 arvif->vdev_id, ret);
3959
3960 spin_lock_bh(&ar->data_lock);
3961 ar->num_peers--;
3962 spin_unlock_bh(&ar->data_lock);
3963 }
3964
Kalle Valo5e3dd152013-06-12 20:52:10 +03003965 ath10k_peer_cleanup(ar, arvif->vdev_id);
3966
3967 mutex_unlock(&ar->conf_mutex);
3968}
3969
3970/*
3971 * FIXME: Has to be verified.
3972 */
3973#define SUPPORTED_FILTERS \
3974 (FIF_PROMISC_IN_BSS | \
3975 FIF_ALLMULTI | \
3976 FIF_CONTROL | \
3977 FIF_PSPOLL | \
3978 FIF_OTHER_BSS | \
3979 FIF_BCN_PRBRESP_PROMISC | \
3980 FIF_PROBE_REQ | \
3981 FIF_FCSFAIL)
3982
3983static void ath10k_configure_filter(struct ieee80211_hw *hw,
3984 unsigned int changed_flags,
3985 unsigned int *total_flags,
3986 u64 multicast)
3987{
3988 struct ath10k *ar = hw->priv;
3989 int ret;
3990
3991 mutex_lock(&ar->conf_mutex);
3992
3993 changed_flags &= SUPPORTED_FILTERS;
3994 *total_flags &= SUPPORTED_FILTERS;
3995 ar->filter_flags = *total_flags;
3996
Michal Kazior19337472014-08-28 12:58:16 +02003997 ret = ath10k_monitor_recalc(ar);
3998 if (ret)
3999 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004000
4001 mutex_unlock(&ar->conf_mutex);
4002}
4003
4004static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
4005 struct ieee80211_vif *vif,
4006 struct ieee80211_bss_conf *info,
4007 u32 changed)
4008{
4009 struct ath10k *ar = hw->priv;
4010 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4011 int ret = 0;
Kalle Valoaf762c02014-09-14 12:50:17 +03004012 u32 vdev_param, pdev_param, slottime, preamble;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004013
4014 mutex_lock(&ar->conf_mutex);
4015
4016 if (changed & BSS_CHANGED_IBSS)
4017 ath10k_control_ibss(arvif, info, vif->addr);
4018
4019 if (changed & BSS_CHANGED_BEACON_INT) {
4020 arvif->beacon_interval = info->beacon_int;
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004021 vdev_param = ar->wmi.vdev_param->beacon_interval;
4022 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004023 arvif->beacon_interval);
Michal Kazior7aa7a722014-08-25 12:09:38 +02004024 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004025 "mac vdev %d beacon_interval %d\n",
4026 arvif->vdev_id, arvif->beacon_interval);
4027
Kalle Valo5e3dd152013-06-12 20:52:10 +03004028 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004029 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004030 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004031 }
4032
4033 if (changed & BSS_CHANGED_BEACON) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004034 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004035 "vdev %d set beacon tx mode to staggered\n",
4036 arvif->vdev_id);
4037
Bartosz Markowski226a3392013-09-26 17:47:16 +02004038 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
4039 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004040 WMI_BEACON_STAGGERED_MODE);
4041 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004042 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004043 arvif->vdev_id, ret);
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02004044
4045 ret = ath10k_mac_setup_bcn_tmpl(arvif);
4046 if (ret)
4047 ath10k_warn(ar, "failed to update beacon template: %d\n",
4048 ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004049 }
4050
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02004051 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
4052 ret = ath10k_mac_setup_prb_tmpl(arvif);
4053 if (ret)
4054 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
4055 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004056 }
4057
Michal Kaziorba2479f2015-01-24 12:14:51 +02004058 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004059 arvif->dtim_period = info->dtim_period;
4060
Michal Kazior7aa7a722014-08-25 12:09:38 +02004061 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004062 "mac vdev %d dtim_period %d\n",
4063 arvif->vdev_id, arvif->dtim_period);
4064
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004065 vdev_param = ar->wmi.vdev_param->dtim_period;
4066 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004067 arvif->dtim_period);
4068 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004069 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004070 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004071 }
4072
4073 if (changed & BSS_CHANGED_SSID &&
4074 vif->type == NL80211_IFTYPE_AP) {
4075 arvif->u.ap.ssid_len = info->ssid_len;
4076 if (info->ssid_len)
4077 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
4078 arvif->u.ap.hidden_ssid = info->hidden_ssid;
4079 }
4080
Michal Kazior077efc82014-10-21 10:10:29 +03004081 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
4082 ether_addr_copy(arvif->bssid, info->bssid);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004083
4084 if (changed & BSS_CHANGED_BEACON_ENABLED)
4085 ath10k_control_beaconing(arvif, info);
4086
4087 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02004088 arvif->use_cts_prot = info->use_cts_prot;
Michal Kazior7aa7a722014-08-25 12:09:38 +02004089 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02004090 arvif->vdev_id, info->use_cts_prot);
Kalle Valo60c3daa2013-09-08 17:56:07 +03004091
Marek Kwaczynskie81bd102014-03-11 12:58:00 +02004092 ret = ath10k_recalc_rtscts_prot(arvif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004093 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004094 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004095 arvif->vdev_id, ret);
Michal Kaziora87fd4b2015-03-02 11:21:17 +01004096
4097 vdev_param = ar->wmi.vdev_param->protection_mode;
4098 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4099 info->use_cts_prot ? 1 : 0);
4100 if (ret)
4101 ath10k_warn(ar, "failed to set protection mode %d on vdev %i: %d\n",
4102 info->use_cts_prot, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004103 }
4104
4105 if (changed & BSS_CHANGED_ERP_SLOT) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004106 if (info->use_short_slot)
4107 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
4108
4109 else
4110 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
4111
Michal Kazior7aa7a722014-08-25 12:09:38 +02004112 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004113 arvif->vdev_id, slottime);
4114
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004115 vdev_param = ar->wmi.vdev_param->slot_time;
4116 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004117 slottime);
4118 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004119 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004120 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004121 }
4122
4123 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004124 if (info->use_short_preamble)
4125 preamble = WMI_VDEV_PREAMBLE_SHORT;
4126 else
4127 preamble = WMI_VDEV_PREAMBLE_LONG;
4128
Michal Kazior7aa7a722014-08-25 12:09:38 +02004129 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004130 "mac vdev %d preamble %dn",
4131 arvif->vdev_id, preamble);
4132
Bartosz Markowski6d1506e2013-09-26 17:47:15 +02004133 vdev_param = ar->wmi.vdev_param->preamble;
4134 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
Kalle Valo5e3dd152013-06-12 20:52:10 +03004135 preamble);
4136 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004137 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004138 arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004139 }
4140
4141 if (changed & BSS_CHANGED_ASSOC) {
Michal Kaziore556f112014-08-28 12:58:17 +02004142 if (info->assoc) {
4143 /* Workaround: Make sure monitor vdev is not running
4144 * when associating to prevent some firmware revisions
4145 * (e.g. 10.1 and 10.2) from crashing.
4146 */
4147 if (ar->monitor_started)
4148 ath10k_monitor_stop(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004149 ath10k_bss_assoc(hw, vif, info);
Michal Kaziore556f112014-08-28 12:58:17 +02004150 ath10k_monitor_recalc(ar);
Michal Kazior077efc82014-10-21 10:10:29 +03004151 } else {
4152 ath10k_bss_disassoc(hw, vif);
Michal Kaziore556f112014-08-28 12:58:17 +02004153 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004154 }
4155
Michal Kazior7d9d5582014-10-21 10:40:15 +03004156 if (changed & BSS_CHANGED_TXPOWER) {
4157 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
4158 arvif->vdev_id, info->txpower);
4159
4160 arvif->txpower = info->txpower;
4161 ret = ath10k_mac_txpower_recalc(ar);
4162 if (ret)
4163 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
4164 }
4165
Michal Kaziorbf14e652014-12-12 12:41:38 +01004166 if (changed & BSS_CHANGED_PS) {
Michal Kaziorcffb41f2015-02-13 13:30:16 +01004167 arvif->ps = vif->bss_conf.ps;
4168
4169 ret = ath10k_config_ps(ar);
Michal Kaziorbf14e652014-12-12 12:41:38 +01004170 if (ret)
4171 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
4172 arvif->vdev_id, ret);
4173 }
4174
Kalle Valo5e3dd152013-06-12 20:52:10 +03004175 mutex_unlock(&ar->conf_mutex);
4176}
4177
4178static int ath10k_hw_scan(struct ieee80211_hw *hw,
4179 struct ieee80211_vif *vif,
David Spinadelc56ef672014-02-05 15:21:13 +02004180 struct ieee80211_scan_request *hw_req)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004181{
4182 struct ath10k *ar = hw->priv;
4183 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
David Spinadelc56ef672014-02-05 15:21:13 +02004184 struct cfg80211_scan_request *req = &hw_req->req;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004185 struct wmi_start_scan_arg arg;
4186 int ret = 0;
4187 int i;
4188
4189 mutex_lock(&ar->conf_mutex);
4190
4191 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004192 switch (ar->scan.state) {
4193 case ATH10K_SCAN_IDLE:
4194 reinit_completion(&ar->scan.started);
4195 reinit_completion(&ar->scan.completed);
4196 ar->scan.state = ATH10K_SCAN_STARTING;
4197 ar->scan.is_roc = false;
4198 ar->scan.vdev_id = arvif->vdev_id;
4199 ret = 0;
4200 break;
4201 case ATH10K_SCAN_STARTING:
4202 case ATH10K_SCAN_RUNNING:
4203 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004204 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004205 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004206 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004207 spin_unlock_bh(&ar->data_lock);
4208
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004209 if (ret)
4210 goto exit;
4211
Kalle Valo5e3dd152013-06-12 20:52:10 +03004212 memset(&arg, 0, sizeof(arg));
4213 ath10k_wmi_start_scan_init(ar, &arg);
4214 arg.vdev_id = arvif->vdev_id;
4215 arg.scan_id = ATH10K_SCAN_ID;
4216
4217 if (!req->no_cck)
4218 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
4219
4220 if (req->ie_len) {
4221 arg.ie_len = req->ie_len;
4222 memcpy(arg.ie, req->ie, arg.ie_len);
4223 }
4224
4225 if (req->n_ssids) {
4226 arg.n_ssids = req->n_ssids;
4227 for (i = 0; i < arg.n_ssids; i++) {
4228 arg.ssids[i].len = req->ssids[i].ssid_len;
4229 arg.ssids[i].ssid = req->ssids[i].ssid;
4230 }
Michal Kaziordcd4a562013-07-31 10:55:12 +02004231 } else {
4232 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004233 }
4234
4235 if (req->n_channels) {
4236 arg.n_channels = req->n_channels;
4237 for (i = 0; i < arg.n_channels; i++)
4238 arg.channels[i] = req->channels[i]->center_freq;
4239 }
4240
4241 ret = ath10k_start_scan(ar, &arg);
4242 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004243 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004244 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004245 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004246 spin_unlock_bh(&ar->data_lock);
4247 }
4248
4249exit:
4250 mutex_unlock(&ar->conf_mutex);
4251 return ret;
4252}
4253
4254static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
4255 struct ieee80211_vif *vif)
4256{
4257 struct ath10k *ar = hw->priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004258
4259 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02004260 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004261 mutex_unlock(&ar->conf_mutex);
Michal Kazior4eb2e162014-10-28 10:23:09 +01004262
4263 cancel_delayed_work_sync(&ar->scan.timeout);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004264}
4265
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004266static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
4267 struct ath10k_vif *arvif,
4268 enum set_key_cmd cmd,
4269 struct ieee80211_key_conf *key)
4270{
4271 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
4272 int ret;
4273
4274 /* 10.1 firmware branch requires default key index to be set to group
4275 * key index after installing it. Otherwise FW/HW Txes corrupted
4276 * frames with multi-vif APs. This is not required for main firmware
4277 * branch (e.g. 636).
4278 *
4279 * FIXME: This has been tested only in AP. It remains unknown if this
4280 * is required for multi-vif STA interfaces on 10.1 */
4281
4282 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
4283 return;
4284
4285 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
4286 return;
4287
4288 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
4289 return;
4290
4291 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4292 return;
4293
4294 if (cmd != SET_KEY)
4295 return;
4296
4297 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4298 key->keyidx);
4299 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004300 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004301 arvif->vdev_id, ret);
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004302}
4303
Kalle Valo5e3dd152013-06-12 20:52:10 +03004304static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
4305 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
4306 struct ieee80211_key_conf *key)
4307{
4308 struct ath10k *ar = hw->priv;
4309 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4310 struct ath10k_peer *peer;
4311 const u8 *peer_addr;
4312 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
4313 key->cipher == WLAN_CIPHER_SUITE_WEP104;
4314 int ret = 0;
Michal Kazior370e5672015-02-18 14:02:26 +01004315 u32 flags = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004316
Bartosz Markowskid7131c02015-03-10 14:32:19 +01004317 /* this one needs to be done in software */
4318 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
4319 return 1;
4320
Kalle Valo5e3dd152013-06-12 20:52:10 +03004321 if (key->keyidx > WMI_MAX_KEY_INDEX)
4322 return -ENOSPC;
4323
4324 mutex_lock(&ar->conf_mutex);
4325
4326 if (sta)
4327 peer_addr = sta->addr;
4328 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
4329 peer_addr = vif->bss_conf.bssid;
4330 else
4331 peer_addr = vif->addr;
4332
4333 key->hw_key_idx = key->keyidx;
4334
4335 /* the peer should not disappear in mid-way (unless FW goes awry) since
4336 * we already hold conf_mutex. we just make sure its there now. */
4337 spin_lock_bh(&ar->data_lock);
4338 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4339 spin_unlock_bh(&ar->data_lock);
4340
4341 if (!peer) {
4342 if (cmd == SET_KEY) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004343 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
Kalle Valo5e3dd152013-06-12 20:52:10 +03004344 peer_addr);
4345 ret = -EOPNOTSUPP;
4346 goto exit;
4347 } else {
4348 /* if the peer doesn't exist there is no key to disable
4349 * anymore */
4350 goto exit;
4351 }
4352 }
4353
Michal Kazior7cc45732015-03-09 14:24:17 +01004354 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4355 flags |= WMI_KEY_PAIRWISE;
4356 else
4357 flags |= WMI_KEY_GROUP;
4358
Kalle Valo5e3dd152013-06-12 20:52:10 +03004359 if (is_wep) {
4360 if (cmd == SET_KEY)
4361 arvif->wep_keys[key->keyidx] = key;
4362 else
4363 arvif->wep_keys[key->keyidx] = NULL;
4364
4365 if (cmd == DISABLE_KEY)
4366 ath10k_clear_vdev_key(arvif, key);
Michal Kazior370e5672015-02-18 14:02:26 +01004367
Michal Kaziorad325cb2015-02-18 14:02:27 +01004368 /* When WEP keys are uploaded it's possible that there are
4369 * stations associated already (e.g. when merging) without any
4370 * keys. Static WEP needs an explicit per-peer key upload.
4371 */
4372 if (vif->type == NL80211_IFTYPE_ADHOC &&
4373 cmd == SET_KEY)
4374 ath10k_mac_vif_update_wep_key(arvif, key);
4375
Michal Kazior370e5672015-02-18 14:02:26 +01004376 /* 802.1x never sets the def_wep_key_idx so each set_key()
4377 * call changes default tx key.
4378 *
4379 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
4380 * after first set_key().
4381 */
4382 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
4383 flags |= WMI_KEY_TX_USAGE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004384
Michal Kazior7cc45732015-03-09 14:24:17 +01004385 /* mac80211 uploads static WEP keys as groupwise while fw/hw
4386 * requires pairwise keys for non-self peers, i.e. BSSID in STA
4387 * mode and associated stations in AP/IBSS.
4388 *
4389 * Static WEP keys for peer_addr=vif->addr and 802.1X WEP keys
4390 * work fine when mapped directly from mac80211.
4391 *
4392 * Note: When installing first static WEP groupwise key (which
4393 * should be pairwise) def_wep_key_idx isn't known yet (it's
4394 * equal to -1). Since .set_default_unicast_key is called only
4395 * for static WEP it's used to re-upload the key as pairwise.
4396 */
4397 if (arvif->def_wep_key_idx >= 0 &&
4398 memcmp(peer_addr, arvif->vif->addr, ETH_ALEN)) {
4399 flags &= ~WMI_KEY_GROUP;
4400 flags |= WMI_KEY_PAIRWISE;
4401 }
Michal Kazior370e5672015-02-18 14:02:26 +01004402 }
4403
4404 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004405 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004406 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
Ben Greear69244e52014-02-27 18:50:00 +02004407 arvif->vdev_id, peer_addr, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004408 goto exit;
4409 }
4410
Michal Kaziorcfb27d22013-12-02 09:06:36 +01004411 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
4412
Kalle Valo5e3dd152013-06-12 20:52:10 +03004413 spin_lock_bh(&ar->data_lock);
4414 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4415 if (peer && cmd == SET_KEY)
4416 peer->keys[key->keyidx] = key;
4417 else if (peer && cmd == DISABLE_KEY)
4418 peer->keys[key->keyidx] = NULL;
4419 else if (peer == NULL)
4420 /* impossible unless FW goes crazy */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004421 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004422 spin_unlock_bh(&ar->data_lock);
4423
4424exit:
4425 mutex_unlock(&ar->conf_mutex);
4426 return ret;
4427}
4428
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004429static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
4430 struct ieee80211_vif *vif,
4431 int keyidx)
4432{
4433 struct ath10k *ar = hw->priv;
4434 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4435 int ret;
4436
4437 mutex_lock(&arvif->ar->conf_mutex);
4438
4439 if (arvif->ar->state != ATH10K_STATE_ON)
4440 goto unlock;
4441
4442 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
4443 arvif->vdev_id, keyidx);
4444
4445 ret = ath10k_wmi_vdev_set_param(arvif->ar,
4446 arvif->vdev_id,
4447 arvif->ar->wmi.vdev_param->def_keyid,
4448 keyidx);
4449
4450 if (ret) {
4451 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
4452 arvif->vdev_id,
4453 ret);
4454 goto unlock;
4455 }
4456
4457 arvif->def_wep_key_idx = keyidx;
Michal Kazior370e5672015-02-18 14:02:26 +01004458
4459 ret = ath10k_mac_vif_sta_fix_wep_key(arvif);
4460 if (ret) {
4461 ath10k_warn(ar, "failed to fix sta wep key on vdev %i: %d\n",
4462 arvif->vdev_id, ret);
4463 goto unlock;
4464 }
4465
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02004466unlock:
4467 mutex_unlock(&arvif->ar->conf_mutex);
4468}
4469
Michal Kazior9797feb2014-02-14 14:49:48 +01004470static void ath10k_sta_rc_update_wk(struct work_struct *wk)
4471{
4472 struct ath10k *ar;
4473 struct ath10k_vif *arvif;
4474 struct ath10k_sta *arsta;
4475 struct ieee80211_sta *sta;
4476 u32 changed, bw, nss, smps;
4477 int err;
4478
4479 arsta = container_of(wk, struct ath10k_sta, update_wk);
4480 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
4481 arvif = arsta->arvif;
4482 ar = arvif->ar;
4483
4484 spin_lock_bh(&ar->data_lock);
4485
4486 changed = arsta->changed;
4487 arsta->changed = 0;
4488
4489 bw = arsta->bw;
4490 nss = arsta->nss;
4491 smps = arsta->smps;
4492
4493 spin_unlock_bh(&ar->data_lock);
4494
4495 mutex_lock(&ar->conf_mutex);
4496
4497 if (changed & IEEE80211_RC_BW_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004498 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004499 sta->addr, bw);
4500
4501 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4502 WMI_PEER_CHAN_WIDTH, bw);
4503 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004504 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004505 sta->addr, bw, err);
4506 }
4507
4508 if (changed & IEEE80211_RC_NSS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004509 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004510 sta->addr, nss);
4511
4512 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4513 WMI_PEER_NSS, nss);
4514 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004515 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004516 sta->addr, nss, err);
4517 }
4518
4519 if (changed & IEEE80211_RC_SMPS_CHANGED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004520 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004521 sta->addr, smps);
4522
4523 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4524 WMI_PEER_SMPS_STATE, smps);
4525 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004526 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
Michal Kazior9797feb2014-02-14 14:49:48 +01004527 sta->addr, smps, err);
4528 }
4529
Janusz Dziedzic55884c02014-12-17 12:30:02 +02004530 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
4531 changed & IEEE80211_RC_NSS_CHANGED) {
4532 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004533 sta->addr);
4534
Michal Kazior590922a2014-10-21 10:10:29 +03004535 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004536 if (err)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004537 ath10k_warn(ar, "failed to reassociate station: %pM\n",
Chun-Yeow Yeoh44d6fa92014-03-07 10:19:30 +02004538 sta->addr);
4539 }
4540
Michal Kazior9797feb2014-02-14 14:49:48 +01004541 mutex_unlock(&ar->conf_mutex);
4542}
4543
Marek Puzyniak7c354242015-03-30 09:51:52 +03004544static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif,
4545 struct ieee80211_sta *sta)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004546{
4547 struct ath10k *ar = arvif->ar;
4548
4549 lockdep_assert_held(&ar->conf_mutex);
4550
Marek Puzyniak7c354242015-03-30 09:51:52 +03004551 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004552 return 0;
4553
4554 if (ar->num_stations >= ar->max_num_stations)
4555 return -ENOBUFS;
4556
4557 ar->num_stations++;
4558
4559 return 0;
4560}
4561
Marek Puzyniak7c354242015-03-30 09:51:52 +03004562static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif,
4563 struct ieee80211_sta *sta)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004564{
4565 struct ath10k *ar = arvif->ar;
4566
4567 lockdep_assert_held(&ar->conf_mutex);
4568
Marek Puzyniak7c354242015-03-30 09:51:52 +03004569 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
Michal Kaziorcfd10612014-11-25 15:16:05 +01004570 return;
4571
4572 ar->num_stations--;
4573}
4574
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004575struct ath10k_mac_tdls_iter_data {
4576 u32 num_tdls_stations;
4577 struct ieee80211_vif *curr_vif;
4578};
4579
4580static void ath10k_mac_tdls_vif_stations_count_iter(void *data,
4581 struct ieee80211_sta *sta)
4582{
4583 struct ath10k_mac_tdls_iter_data *iter_data = data;
4584 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
4585 struct ieee80211_vif *sta_vif = arsta->arvif->vif;
4586
4587 if (sta->tdls && sta_vif == iter_data->curr_vif)
4588 iter_data->num_tdls_stations++;
4589}
4590
4591static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw *hw,
4592 struct ieee80211_vif *vif)
4593{
4594 struct ath10k_mac_tdls_iter_data data = {};
4595
4596 data.curr_vif = vif;
4597
4598 ieee80211_iterate_stations_atomic(hw,
4599 ath10k_mac_tdls_vif_stations_count_iter,
4600 &data);
4601 return data.num_tdls_stations;
4602}
4603
4604static void ath10k_mac_tdls_vifs_count_iter(void *data, u8 *mac,
4605 struct ieee80211_vif *vif)
4606{
4607 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4608 int *num_tdls_vifs = data;
4609
4610 if (vif->type != NL80211_IFTYPE_STATION)
4611 return;
4612
4613 if (ath10k_mac_tdls_vif_stations_count(arvif->ar->hw, vif) > 0)
4614 (*num_tdls_vifs)++;
4615}
4616
4617static int ath10k_mac_tdls_vifs_count(struct ieee80211_hw *hw)
4618{
4619 int num_tdls_vifs = 0;
4620
4621 ieee80211_iterate_active_interfaces_atomic(hw,
4622 IEEE80211_IFACE_ITER_NORMAL,
4623 ath10k_mac_tdls_vifs_count_iter,
4624 &num_tdls_vifs);
4625 return num_tdls_vifs;
4626}
4627
Kalle Valo5e3dd152013-06-12 20:52:10 +03004628static int ath10k_sta_state(struct ieee80211_hw *hw,
4629 struct ieee80211_vif *vif,
4630 struct ieee80211_sta *sta,
4631 enum ieee80211_sta_state old_state,
4632 enum ieee80211_sta_state new_state)
4633{
4634 struct ath10k *ar = hw->priv;
4635 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01004636 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004637 int ret = 0;
4638
Michal Kazior76f90022014-02-25 09:29:57 +02004639 if (old_state == IEEE80211_STA_NOTEXIST &&
4640 new_state == IEEE80211_STA_NONE) {
4641 memset(arsta, 0, sizeof(*arsta));
4642 arsta->arvif = arvif;
4643 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
4644 }
4645
Michal Kazior9797feb2014-02-14 14:49:48 +01004646 /* cancel must be done outside the mutex to avoid deadlock */
4647 if ((old_state == IEEE80211_STA_NONE &&
4648 new_state == IEEE80211_STA_NOTEXIST))
4649 cancel_work_sync(&arsta->update_wk);
4650
Kalle Valo5e3dd152013-06-12 20:52:10 +03004651 mutex_lock(&ar->conf_mutex);
4652
4653 if (old_state == IEEE80211_STA_NOTEXIST &&
Michal Kazior077efc82014-10-21 10:10:29 +03004654 new_state == IEEE80211_STA_NONE) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004655 /*
4656 * New station addition.
4657 */
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004658 enum wmi_peer_type peer_type = WMI_PEER_TYPE_DEFAULT;
4659 u32 num_tdls_stations;
4660 u32 num_tdls_vifs;
4661
Michal Kaziorcfd10612014-11-25 15:16:05 +01004662 ath10k_dbg(ar, ATH10K_DBG_MAC,
4663 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
4664 arvif->vdev_id, sta->addr,
4665 ar->num_stations + 1, ar->max_num_stations,
4666 ar->num_peers + 1, ar->max_num_peers);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004667
Marek Puzyniak7c354242015-03-30 09:51:52 +03004668 ret = ath10k_mac_inc_num_stations(arvif, sta);
Michal Kaziorcfd10612014-11-25 15:16:05 +01004669 if (ret) {
4670 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
4671 ar->max_num_stations);
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004672 goto exit;
4673 }
4674
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004675 if (sta->tdls)
4676 peer_type = WMI_PEER_TYPE_TDLS;
4677
Marek Puzyniak7390ed32015-03-30 09:51:52 +03004678 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr,
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004679 peer_type);
Michal Kaziora52c0282014-11-25 15:16:03 +01004680 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004681 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 -08004682 sta->addr, arvif->vdev_id, ret);
Marek Puzyniak7c354242015-03-30 09:51:52 +03004683 ath10k_mac_dec_num_stations(arvif, sta);
Michal Kaziora52c0282014-11-25 15:16:03 +01004684 goto exit;
4685 }
Michal Kazior077efc82014-10-21 10:10:29 +03004686
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004687 if (vif->type == NL80211_IFTYPE_STATION &&
4688 !sta->tdls) {
Michal Kazior077efc82014-10-21 10:10:29 +03004689 WARN_ON(arvif->is_started);
4690
4691 ret = ath10k_vdev_start(arvif);
4692 if (ret) {
4693 ath10k_warn(ar, "failed to start vdev %i: %d\n",
4694 arvif->vdev_id, ret);
4695 WARN_ON(ath10k_peer_delete(ar, arvif->vdev_id,
4696 sta->addr));
Marek Puzyniak7c354242015-03-30 09:51:52 +03004697 ath10k_mac_dec_num_stations(arvif, sta);
Michal Kazior077efc82014-10-21 10:10:29 +03004698 goto exit;
4699 }
4700
4701 arvif->is_started = true;
4702 }
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004703
4704 if (!sta->tdls)
4705 goto exit;
4706
4707 num_tdls_stations = ath10k_mac_tdls_vif_stations_count(hw, vif);
4708 num_tdls_vifs = ath10k_mac_tdls_vifs_count(hw);
4709
4710 if (num_tdls_vifs >= ar->max_num_tdls_vdevs &&
4711 num_tdls_stations == 0) {
4712 ath10k_warn(ar, "vdev %i exceeded maximum number of tdls vdevs %i\n",
4713 arvif->vdev_id, ar->max_num_tdls_vdevs);
4714 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
4715 ath10k_mac_dec_num_stations(arvif, sta);
4716 ret = -ENOBUFS;
4717 goto exit;
4718 }
4719
4720 if (num_tdls_stations == 0) {
4721 /* This is the first tdls peer in current vif */
4722 enum wmi_tdls_state state = WMI_TDLS_ENABLE_ACTIVE;
4723
4724 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
4725 state);
4726 if (ret) {
4727 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
4728 arvif->vdev_id, ret);
4729 ath10k_peer_delete(ar, arvif->vdev_id,
4730 sta->addr);
4731 ath10k_mac_dec_num_stations(arvif, sta);
4732 goto exit;
4733 }
4734 }
4735
4736 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
4737 WMI_TDLS_PEER_STATE_PEERING);
4738 if (ret) {
4739 ath10k_warn(ar,
4740 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
4741 sta->addr, arvif->vdev_id, ret);
4742 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
4743 ath10k_mac_dec_num_stations(arvif, sta);
4744
4745 if (num_tdls_stations != 0)
4746 goto exit;
4747 ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
4748 WMI_TDLS_DISABLE);
4749 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004750 } else if ((old_state == IEEE80211_STA_NONE &&
4751 new_state == IEEE80211_STA_NOTEXIST)) {
4752 /*
4753 * Existing station deletion.
4754 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004755 ath10k_dbg(ar, ATH10K_DBG_MAC,
Kalle Valo60c3daa2013-09-08 17:56:07 +03004756 "mac vdev %d peer delete %pM (sta gone)\n",
4757 arvif->vdev_id, sta->addr);
Michal Kazior077efc82014-10-21 10:10:29 +03004758
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004759 if (vif->type == NL80211_IFTYPE_STATION &&
4760 !sta->tdls) {
Michal Kazior077efc82014-10-21 10:10:29 +03004761 WARN_ON(!arvif->is_started);
4762
4763 ret = ath10k_vdev_stop(arvif);
4764 if (ret)
4765 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
4766 arvif->vdev_id, ret);
4767
4768 arvif->is_started = false;
4769 }
4770
Kalle Valo5e3dd152013-06-12 20:52:10 +03004771 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
4772 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004773 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004774 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004775
Marek Puzyniak7c354242015-03-30 09:51:52 +03004776 ath10k_mac_dec_num_stations(arvif, sta);
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004777
4778 if (!sta->tdls)
4779 goto exit;
4780
4781 if (ath10k_mac_tdls_vif_stations_count(hw, vif))
4782 goto exit;
4783
4784 /* This was the last tdls peer in current vif */
4785 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
4786 WMI_TDLS_DISABLE);
4787 if (ret) {
4788 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
4789 arvif->vdev_id, ret);
4790 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03004791 } else if (old_state == IEEE80211_STA_AUTH &&
4792 new_state == IEEE80211_STA_ASSOC &&
4793 (vif->type == NL80211_IFTYPE_AP ||
4794 vif->type == NL80211_IFTYPE_ADHOC)) {
4795 /*
4796 * New association.
4797 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004798 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004799 sta->addr);
4800
Michal Kazior590922a2014-10-21 10:10:29 +03004801 ret = ath10k_station_assoc(ar, vif, sta, false);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004802 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004803 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004804 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004805 } else if (old_state == IEEE80211_STA_ASSOC &&
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03004806 new_state == IEEE80211_STA_AUTHORIZED &&
4807 sta->tdls) {
4808 /*
4809 * Tdls station authorized.
4810 */
4811 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac tdls sta %pM authorized\n",
4812 sta->addr);
4813
4814 ret = ath10k_station_assoc(ar, vif, sta, false);
4815 if (ret) {
4816 ath10k_warn(ar, "failed to associate tdls station %pM for vdev %i: %i\n",
4817 sta->addr, arvif->vdev_id, ret);
4818 goto exit;
4819 }
4820
4821 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
4822 WMI_TDLS_PEER_STATE_CONNECTED);
4823 if (ret)
4824 ath10k_warn(ar, "failed to update tdls peer %pM for vdev %i: %i\n",
4825 sta->addr, arvif->vdev_id, ret);
4826 } else if (old_state == IEEE80211_STA_ASSOC &&
4827 new_state == IEEE80211_STA_AUTH &&
4828 (vif->type == NL80211_IFTYPE_AP ||
4829 vif->type == NL80211_IFTYPE_ADHOC)) {
Kalle Valo5e3dd152013-06-12 20:52:10 +03004830 /*
4831 * Disassociation.
4832 */
Michal Kazior7aa7a722014-08-25 12:09:38 +02004833 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
Kalle Valo60c3daa2013-09-08 17:56:07 +03004834 sta->addr);
4835
Michal Kazior590922a2014-10-21 10:10:29 +03004836 ret = ath10k_station_disassoc(ar, vif, sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004837 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004838 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
Ben Greear69244e52014-02-27 18:50:00 +02004839 sta->addr, arvif->vdev_id, ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004840 }
Bartosz Markowski0e759f32014-01-02 14:38:33 +01004841exit:
Kalle Valo5e3dd152013-06-12 20:52:10 +03004842 mutex_unlock(&ar->conf_mutex);
4843 return ret;
4844}
4845
4846static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
Kalle Valo5b07e072014-09-14 12:50:06 +03004847 u16 ac, bool enable)
Kalle Valo5e3dd152013-06-12 20:52:10 +03004848{
4849 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Michal Kaziorb0e56152015-01-24 12:14:52 +02004850 struct wmi_sta_uapsd_auto_trig_arg arg = {};
4851 u32 prio = 0, acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004852 u32 value = 0;
4853 int ret = 0;
4854
Michal Kazior548db542013-07-05 16:15:15 +03004855 lockdep_assert_held(&ar->conf_mutex);
4856
Kalle Valo5e3dd152013-06-12 20:52:10 +03004857 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
4858 return 0;
4859
4860 switch (ac) {
4861 case IEEE80211_AC_VO:
4862 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
4863 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004864 prio = 7;
4865 acc = 3;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004866 break;
4867 case IEEE80211_AC_VI:
4868 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
4869 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004870 prio = 5;
4871 acc = 2;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004872 break;
4873 case IEEE80211_AC_BE:
4874 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
4875 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004876 prio = 2;
4877 acc = 1;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004878 break;
4879 case IEEE80211_AC_BK:
4880 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
4881 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
Michal Kaziorb0e56152015-01-24 12:14:52 +02004882 prio = 0;
4883 acc = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004884 break;
4885 }
4886
4887 if (enable)
4888 arvif->u.sta.uapsd |= value;
4889 else
4890 arvif->u.sta.uapsd &= ~value;
4891
4892 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4893 WMI_STA_PS_PARAM_UAPSD,
4894 arvif->u.sta.uapsd);
4895 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02004896 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004897 goto exit;
4898 }
4899
4900 if (arvif->u.sta.uapsd)
4901 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
4902 else
4903 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4904
4905 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4906 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
4907 value);
4908 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02004909 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004910
Michal Kazior9f9b5742014-12-12 12:41:36 +01004911 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
4912 if (ret) {
4913 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
4914 arvif->vdev_id, ret);
4915 return ret;
4916 }
4917
4918 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
4919 if (ret) {
4920 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
4921 arvif->vdev_id, ret);
4922 return ret;
4923 }
4924
Michal Kaziorb0e56152015-01-24 12:14:52 +02004925 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
4926 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
4927 /* Only userspace can make an educated decision when to send
4928 * trigger frame. The following effectively disables u-UAPSD
4929 * autotrigger in firmware (which is enabled by default
4930 * provided the autotrigger service is available).
4931 */
4932
4933 arg.wmm_ac = acc;
4934 arg.user_priority = prio;
4935 arg.service_interval = 0;
4936 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4937 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4938
4939 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
4940 arvif->bssid, &arg, 1);
4941 if (ret) {
4942 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
4943 ret);
4944 return ret;
4945 }
4946 }
4947
Kalle Valo5e3dd152013-06-12 20:52:10 +03004948exit:
4949 return ret;
4950}
4951
4952static int ath10k_conf_tx(struct ieee80211_hw *hw,
4953 struct ieee80211_vif *vif, u16 ac,
4954 const struct ieee80211_tx_queue_params *params)
4955{
4956 struct ath10k *ar = hw->priv;
Michal Kazior5e752e42015-01-19 09:53:41 +01004957 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
Kalle Valo5e3dd152013-06-12 20:52:10 +03004958 struct wmi_wmm_params_arg *p = NULL;
4959 int ret;
4960
4961 mutex_lock(&ar->conf_mutex);
4962
4963 switch (ac) {
4964 case IEEE80211_AC_VO:
Michal Kazior5e752e42015-01-19 09:53:41 +01004965 p = &arvif->wmm_params.ac_vo;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004966 break;
4967 case IEEE80211_AC_VI:
Michal Kazior5e752e42015-01-19 09:53:41 +01004968 p = &arvif->wmm_params.ac_vi;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004969 break;
4970 case IEEE80211_AC_BE:
Michal Kazior5e752e42015-01-19 09:53:41 +01004971 p = &arvif->wmm_params.ac_be;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004972 break;
4973 case IEEE80211_AC_BK:
Michal Kazior5e752e42015-01-19 09:53:41 +01004974 p = &arvif->wmm_params.ac_bk;
Kalle Valo5e3dd152013-06-12 20:52:10 +03004975 break;
4976 }
4977
4978 if (WARN_ON(!p)) {
4979 ret = -EINVAL;
4980 goto exit;
4981 }
4982
4983 p->cwmin = params->cw_min;
4984 p->cwmax = params->cw_max;
4985 p->aifs = params->aifs;
4986
4987 /*
4988 * The channel time duration programmed in the HW is in absolute
4989 * microseconds, while mac80211 gives the txop in units of
4990 * 32 microseconds.
4991 */
4992 p->txop = params->txop * 32;
4993
Michal Kazior7fc979a2015-01-28 09:57:28 +02004994 if (ar->wmi.ops->gen_vdev_wmm_conf) {
4995 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
4996 &arvif->wmm_params);
4997 if (ret) {
4998 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
4999 arvif->vdev_id, ret);
5000 goto exit;
5001 }
5002 } else {
5003 /* This won't work well with multi-interface cases but it's
5004 * better than nothing.
5005 */
5006 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
5007 if (ret) {
5008 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
5009 goto exit;
5010 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005011 }
5012
5013 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
5014 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005015 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005016
5017exit:
5018 mutex_unlock(&ar->conf_mutex);
5019 return ret;
5020}
5021
5022#define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
5023
5024static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
5025 struct ieee80211_vif *vif,
5026 struct ieee80211_channel *chan,
5027 int duration,
5028 enum ieee80211_roc_type type)
5029{
5030 struct ath10k *ar = hw->priv;
5031 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5032 struct wmi_start_scan_arg arg;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005033 int ret = 0;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005034
5035 mutex_lock(&ar->conf_mutex);
5036
5037 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005038 switch (ar->scan.state) {
5039 case ATH10K_SCAN_IDLE:
5040 reinit_completion(&ar->scan.started);
5041 reinit_completion(&ar->scan.completed);
5042 reinit_completion(&ar->scan.on_channel);
5043 ar->scan.state = ATH10K_SCAN_STARTING;
5044 ar->scan.is_roc = true;
5045 ar->scan.vdev_id = arvif->vdev_id;
5046 ar->scan.roc_freq = chan->center_freq;
5047 ret = 0;
5048 break;
5049 case ATH10K_SCAN_STARTING:
5050 case ATH10K_SCAN_RUNNING:
5051 case ATH10K_SCAN_ABORTING:
Kalle Valo5e3dd152013-06-12 20:52:10 +03005052 ret = -EBUSY;
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005053 break;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005054 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005055 spin_unlock_bh(&ar->data_lock);
5056
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005057 if (ret)
5058 goto exit;
5059
Michal Kaziordcca0bd2014-11-24 14:58:32 +01005060 duration = max(duration, WMI_SCAN_CHAN_MIN_TIME_MSEC);
5061
Kalle Valo5e3dd152013-06-12 20:52:10 +03005062 memset(&arg, 0, sizeof(arg));
5063 ath10k_wmi_start_scan_init(ar, &arg);
5064 arg.vdev_id = arvif->vdev_id;
5065 arg.scan_id = ATH10K_SCAN_ID;
5066 arg.n_channels = 1;
5067 arg.channels[0] = chan->center_freq;
5068 arg.dwell_time_active = duration;
5069 arg.dwell_time_passive = duration;
5070 arg.max_scan_time = 2 * duration;
5071 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
5072 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
5073
5074 ret = ath10k_start_scan(ar, &arg);
5075 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005076 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005077 spin_lock_bh(&ar->data_lock);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005078 ar->scan.state = ATH10K_SCAN_IDLE;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005079 spin_unlock_bh(&ar->data_lock);
5080 goto exit;
5081 }
5082
5083 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
5084 if (ret == 0) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005085 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005086
5087 ret = ath10k_scan_stop(ar);
5088 if (ret)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005089 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005090
Kalle Valo5e3dd152013-06-12 20:52:10 +03005091 ret = -ETIMEDOUT;
5092 goto exit;
5093 }
5094
5095 ret = 0;
5096exit:
5097 mutex_unlock(&ar->conf_mutex);
5098 return ret;
5099}
5100
5101static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
5102{
5103 struct ath10k *ar = hw->priv;
5104
5105 mutex_lock(&ar->conf_mutex);
Michal Kazior5c81c7f2014-08-05 14:54:44 +02005106 ath10k_scan_abort(ar);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005107 mutex_unlock(&ar->conf_mutex);
5108
Michal Kazior4eb2e162014-10-28 10:23:09 +01005109 cancel_delayed_work_sync(&ar->scan.timeout);
5110
Kalle Valo5e3dd152013-06-12 20:52:10 +03005111 return 0;
5112}
5113
5114/*
5115 * Both RTS and Fragmentation threshold are interface-specific
5116 * in ath10k, but device-specific in mac80211.
5117 */
Kalle Valo5e3dd152013-06-12 20:52:10 +03005118
5119static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
5120{
Kalle Valo5e3dd152013-06-12 20:52:10 +03005121 struct ath10k *ar = hw->priv;
Michal Kaziorad088bf2013-10-16 15:44:46 +03005122 struct ath10k_vif *arvif;
5123 int ret = 0;
Michal Kazior548db542013-07-05 16:15:15 +03005124
Michal Kaziorad088bf2013-10-16 15:44:46 +03005125 mutex_lock(&ar->conf_mutex);
5126 list_for_each_entry(arvif, &ar->arvifs, list) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005127 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03005128 arvif->vdev_id, value);
Kalle Valo60c3daa2013-09-08 17:56:07 +03005129
Michal Kaziorad088bf2013-10-16 15:44:46 +03005130 ret = ath10k_mac_set_rts(arvif, value);
5131 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005132 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
Michal Kaziorad088bf2013-10-16 15:44:46 +03005133 arvif->vdev_id, ret);
5134 break;
5135 }
5136 }
5137 mutex_unlock(&ar->conf_mutex);
5138
5139 return ret;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005140}
5141
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02005142static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5143 u32 queues, bool drop)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005144{
5145 struct ath10k *ar = hw->priv;
Michal Kazioraffd3212013-07-16 09:54:35 +02005146 bool skip;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005147 int ret;
5148
5149 /* mac80211 doesn't care if we really xmit queued frames or not
5150 * we'll collect those frames either way if we stop/delete vdevs */
5151 if (drop)
5152 return;
5153
Michal Kazior548db542013-07-05 16:15:15 +03005154 mutex_lock(&ar->conf_mutex);
5155
Michal Kazioraffd3212013-07-16 09:54:35 +02005156 if (ar->state == ATH10K_STATE_WEDGED)
5157 goto skip;
5158
Michal Kazioredb82362013-07-05 16:15:14 +03005159 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
Kalle Valo5e3dd152013-06-12 20:52:10 +03005160 bool empty;
Michal Kazioraffd3212013-07-16 09:54:35 +02005161
Michal Kazioredb82362013-07-05 16:15:14 +03005162 spin_lock_bh(&ar->htt.tx_lock);
Michal Kazior0945baf2013-09-18 14:43:18 +02005163 empty = (ar->htt.num_pending_tx == 0);
Michal Kazioredb82362013-07-05 16:15:14 +03005164 spin_unlock_bh(&ar->htt.tx_lock);
Michal Kazioraffd3212013-07-16 09:54:35 +02005165
Michal Kazior7962b0d2014-10-28 10:34:38 +01005166 skip = (ar->state == ATH10K_STATE_WEDGED) ||
5167 test_bit(ATH10K_FLAG_CRASH_FLUSH,
5168 &ar->dev_flags);
Michal Kazioraffd3212013-07-16 09:54:35 +02005169
5170 (empty || skip);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005171 }), ATH10K_FLUSH_TIMEOUT_HZ);
Michal Kazioraffd3212013-07-16 09:54:35 +02005172
5173 if (ret <= 0 || skip)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005174 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
Ben Greear9ba4c782014-02-25 09:29:57 +02005175 skip, ar->state, ret);
Michal Kazior548db542013-07-05 16:15:15 +03005176
Michal Kazioraffd3212013-07-16 09:54:35 +02005177skip:
Michal Kazior548db542013-07-05 16:15:15 +03005178 mutex_unlock(&ar->conf_mutex);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005179}
5180
5181/* TODO: Implement this function properly
5182 * For now it is needed to reply to Probe Requests in IBSS mode.
5183 * Propably we need this information from FW.
5184 */
5185static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
5186{
5187 return 1;
5188}
5189
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005190static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
5191 enum ieee80211_reconfig_type reconfig_type)
Michal Kazioraffd3212013-07-16 09:54:35 +02005192{
5193 struct ath10k *ar = hw->priv;
5194
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005195 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
5196 return;
5197
Michal Kazioraffd3212013-07-16 09:54:35 +02005198 mutex_lock(&ar->conf_mutex);
5199
5200 /* If device failed to restart it will be in a different state, e.g.
5201 * ATH10K_STATE_WEDGED */
5202 if (ar->state == ATH10K_STATE_RESTARTED) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005203 ath10k_info(ar, "device successfully recovered\n");
Michal Kazioraffd3212013-07-16 09:54:35 +02005204 ar->state = ATH10K_STATE_ON;
Michal Kazior7962b0d2014-10-28 10:34:38 +01005205 ieee80211_wake_queues(ar->hw);
Michal Kazioraffd3212013-07-16 09:54:35 +02005206 }
5207
5208 mutex_unlock(&ar->conf_mutex);
5209}
5210
Michal Kazior2e1dea42013-07-31 10:32:40 +02005211static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
5212 struct survey_info *survey)
5213{
5214 struct ath10k *ar = hw->priv;
5215 struct ieee80211_supported_band *sband;
5216 struct survey_info *ar_survey = &ar->survey[idx];
5217 int ret = 0;
5218
5219 mutex_lock(&ar->conf_mutex);
5220
5221 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
5222 if (sband && idx >= sband->n_channels) {
5223 idx -= sband->n_channels;
5224 sband = NULL;
5225 }
5226
5227 if (!sband)
5228 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
5229
5230 if (!sband || idx >= sband->n_channels) {
5231 ret = -ENOENT;
5232 goto exit;
5233 }
5234
5235 spin_lock_bh(&ar->data_lock);
5236 memcpy(survey, ar_survey, sizeof(*survey));
5237 spin_unlock_bh(&ar->data_lock);
5238
5239 survey->channel = &sband->channels[idx];
5240
Felix Fietkaufa1d4df2014-10-23 17:04:28 +03005241 if (ar->rx_channel == survey->channel)
5242 survey->filled |= SURVEY_INFO_IN_USE;
5243
Michal Kazior2e1dea42013-07-31 10:32:40 +02005244exit:
5245 mutex_unlock(&ar->conf_mutex);
5246 return ret;
5247}
5248
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005249/* Check if only one bit set */
5250static int ath10k_check_single_mask(u32 mask)
5251{
5252 int bit;
5253
5254 bit = ffs(mask);
5255 if (!bit)
5256 return 0;
5257
5258 mask &= ~BIT(bit - 1);
5259 if (mask)
5260 return 2;
5261
5262 return 1;
5263}
5264
5265static bool
5266ath10k_default_bitrate_mask(struct ath10k *ar,
5267 enum ieee80211_band band,
5268 const struct cfg80211_bitrate_mask *mask)
5269{
5270 u32 legacy = 0x00ff;
5271 u8 ht = 0xff, i;
5272 u16 vht = 0x3ff;
Ben Greearb116ea12014-11-24 16:22:10 +02005273 u16 nrf = ar->num_rf_chains;
5274
5275 if (ar->cfg_tx_chainmask)
5276 nrf = get_nss_from_chainmask(ar->cfg_tx_chainmask);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005277
5278 switch (band) {
5279 case IEEE80211_BAND_2GHZ:
5280 legacy = 0x00fff;
5281 vht = 0;
5282 break;
5283 case IEEE80211_BAND_5GHZ:
5284 break;
5285 default:
5286 return false;
5287 }
5288
5289 if (mask->control[band].legacy != legacy)
5290 return false;
5291
Ben Greearb116ea12014-11-24 16:22:10 +02005292 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005293 if (mask->control[band].ht_mcs[i] != ht)
5294 return false;
5295
Ben Greearb116ea12014-11-24 16:22:10 +02005296 for (i = 0; i < nrf; i++)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005297 if (mask->control[band].vht_mcs[i] != vht)
5298 return false;
5299
5300 return true;
5301}
5302
5303static bool
5304ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
5305 enum ieee80211_band band,
5306 u8 *fixed_nss)
5307{
5308 int ht_nss = 0, vht_nss = 0, i;
5309
5310 /* check legacy */
5311 if (ath10k_check_single_mask(mask->control[band].legacy))
5312 return false;
5313
5314 /* check HT */
5315 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
5316 if (mask->control[band].ht_mcs[i] == 0xff)
5317 continue;
5318 else if (mask->control[band].ht_mcs[i] == 0x00)
5319 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03005320
5321 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005322 }
5323
5324 ht_nss = i;
5325
5326 /* check VHT */
5327 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
5328 if (mask->control[band].vht_mcs[i] == 0x03ff)
5329 continue;
5330 else if (mask->control[band].vht_mcs[i] == 0x0000)
5331 break;
Kalle Valod8bb26b2014-09-14 12:50:33 +03005332
5333 return false;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005334 }
5335
5336 vht_nss = i;
5337
5338 if (ht_nss > 0 && vht_nss > 0)
5339 return false;
5340
5341 if (ht_nss)
5342 *fixed_nss = ht_nss;
5343 else if (vht_nss)
5344 *fixed_nss = vht_nss;
5345 else
5346 return false;
5347
5348 return true;
5349}
5350
5351static bool
5352ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
5353 enum ieee80211_band band,
5354 enum wmi_rate_preamble *preamble)
5355{
5356 int legacy = 0, ht = 0, vht = 0, i;
5357
5358 *preamble = WMI_RATE_PREAMBLE_OFDM;
5359
5360 /* check legacy */
5361 legacy = ath10k_check_single_mask(mask->control[band].legacy);
5362 if (legacy > 1)
5363 return false;
5364
5365 /* check HT */
5366 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5367 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
5368 if (ht > 1)
5369 return false;
5370
5371 /* check VHT */
5372 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
5373 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
5374 if (vht > 1)
5375 return false;
5376
5377 /* Currently we support only one fixed_rate */
5378 if ((legacy + ht + vht) != 1)
5379 return false;
5380
5381 if (ht)
5382 *preamble = WMI_RATE_PREAMBLE_HT;
5383 else if (vht)
5384 *preamble = WMI_RATE_PREAMBLE_VHT;
5385
5386 return true;
5387}
5388
5389static bool
Michal Kazior7aa7a722014-08-25 12:09:38 +02005390ath10k_bitrate_mask_rate(struct ath10k *ar,
5391 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005392 enum ieee80211_band band,
5393 u8 *fixed_rate,
5394 u8 *fixed_nss)
5395{
Michal Kazioraf001482015-03-30 09:51:56 +03005396 struct ieee80211_supported_band *sband;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005397 u8 rate = 0, pream = 0, nss = 0, i;
5398 enum wmi_rate_preamble preamble;
5399
5400 /* Check if single rate correct */
5401 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
5402 return false;
5403
5404 pream = preamble;
5405
5406 switch (preamble) {
5407 case WMI_RATE_PREAMBLE_CCK:
5408 case WMI_RATE_PREAMBLE_OFDM:
5409 i = ffs(mask->control[band].legacy) - 1;
Michal Kazioraf001482015-03-30 09:51:56 +03005410 sband = &ar->mac.sbands[band];
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005411
Michal Kazioraf001482015-03-30 09:51:56 +03005412 if (WARN_ON(i >= sband->n_bitrates))
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005413 return false;
5414
Michal Kazioraf001482015-03-30 09:51:56 +03005415 rate = sband->bitrates[i].hw_value;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005416 break;
5417 case WMI_RATE_PREAMBLE_HT:
5418 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
5419 if (mask->control[band].ht_mcs[i])
5420 break;
5421
5422 if (i == IEEE80211_HT_MCS_MASK_LEN)
5423 return false;
5424
5425 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
5426 nss = i;
5427 break;
5428 case WMI_RATE_PREAMBLE_VHT:
5429 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
5430 if (mask->control[band].vht_mcs[i])
5431 break;
5432
5433 if (i == NL80211_VHT_NSS_MAX)
5434 return false;
5435
5436 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
5437 nss = i;
5438 break;
5439 }
5440
5441 *fixed_nss = nss + 1;
5442 nss <<= 4;
5443 pream <<= 6;
5444
Michal Kazior7aa7a722014-08-25 12:09:38 +02005445 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac fixed rate pream 0x%02x nss 0x%02x rate 0x%02x\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005446 pream, nss, rate);
5447
5448 *fixed_rate = pream | nss | rate;
5449
5450 return true;
5451}
5452
Michal Kazior7aa7a722014-08-25 12:09:38 +02005453static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
5454 const struct cfg80211_bitrate_mask *mask,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005455 enum ieee80211_band band,
5456 u8 *fixed_rate,
5457 u8 *fixed_nss)
5458{
5459 /* First check full NSS mask, if we can simply limit NSS */
5460 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
5461 return true;
5462
5463 /* Next Check single rate is set */
Michal Kazior7aa7a722014-08-25 12:09:38 +02005464 return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005465}
5466
5467static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
5468 u8 fixed_rate,
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005469 u8 fixed_nss,
5470 u8 force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005471{
5472 struct ath10k *ar = arvif->ar;
5473 u32 vdev_param;
5474 int ret = 0;
5475
5476 mutex_lock(&ar->conf_mutex);
5477
5478 if (arvif->fixed_rate == fixed_rate &&
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005479 arvif->fixed_nss == fixed_nss &&
5480 arvif->force_sgi == force_sgi)
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005481 goto exit;
5482
5483 if (fixed_rate == WMI_FIXED_RATE_NONE)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005484 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005485
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005486 if (force_sgi)
Michal Kazior7aa7a722014-08-25 12:09:38 +02005487 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005488
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005489 vdev_param = ar->wmi.vdev_param->fixed_rate;
5490 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5491 vdev_param, fixed_rate);
5492 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005493 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005494 fixed_rate, ret);
5495 ret = -EINVAL;
5496 goto exit;
5497 }
5498
5499 arvif->fixed_rate = fixed_rate;
5500
5501 vdev_param = ar->wmi.vdev_param->nss;
5502 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5503 vdev_param, fixed_nss);
5504
5505 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005506 ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005507 fixed_nss, ret);
5508 ret = -EINVAL;
5509 goto exit;
5510 }
5511
5512 arvif->fixed_nss = fixed_nss;
5513
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005514 vdev_param = ar->wmi.vdev_param->sgi;
5515 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5516 force_sgi);
5517
5518 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005519 ath10k_warn(ar, "failed to set sgi param %d: %d\n",
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005520 force_sgi, ret);
5521 ret = -EINVAL;
5522 goto exit;
5523 }
5524
5525 arvif->force_sgi = force_sgi;
5526
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005527exit:
5528 mutex_unlock(&ar->conf_mutex);
5529 return ret;
5530}
5531
5532static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
5533 struct ieee80211_vif *vif,
5534 const struct cfg80211_bitrate_mask *mask)
5535{
5536 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5537 struct ath10k *ar = arvif->ar;
5538 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
5539 u8 fixed_rate = WMI_FIXED_RATE_NONE;
5540 u8 fixed_nss = ar->num_rf_chains;
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005541 u8 force_sgi;
5542
Ben Greearb116ea12014-11-24 16:22:10 +02005543 if (ar->cfg_tx_chainmask)
5544 fixed_nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
5545
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005546 force_sgi = mask->control[band].gi;
5547 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
5548 return -EINVAL;
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005549
5550 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005551 if (!ath10k_get_fixed_rate_nss(ar, mask, band,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005552 &fixed_rate,
5553 &fixed_nss))
5554 return -EINVAL;
5555 }
5556
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005557 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005558 ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
Janusz Dziedzic9f81f722014-01-17 20:04:14 +01005559 return -EINVAL;
5560 }
5561
5562 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
5563 fixed_nss, force_sgi);
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005564}
5565
Michal Kazior9797feb2014-02-14 14:49:48 +01005566static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
5567 struct ieee80211_vif *vif,
5568 struct ieee80211_sta *sta,
5569 u32 changed)
5570{
5571 struct ath10k *ar = hw->priv;
5572 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5573 u32 bw, smps;
5574
5575 spin_lock_bh(&ar->data_lock);
5576
Michal Kazior7aa7a722014-08-25 12:09:38 +02005577 ath10k_dbg(ar, ATH10K_DBG_MAC,
Michal Kazior9797feb2014-02-14 14:49:48 +01005578 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
5579 sta->addr, changed, sta->bandwidth, sta->rx_nss,
5580 sta->smps_mode);
5581
5582 if (changed & IEEE80211_RC_BW_CHANGED) {
5583 bw = WMI_PEER_CHWIDTH_20MHZ;
5584
5585 switch (sta->bandwidth) {
5586 case IEEE80211_STA_RX_BW_20:
5587 bw = WMI_PEER_CHWIDTH_20MHZ;
5588 break;
5589 case IEEE80211_STA_RX_BW_40:
5590 bw = WMI_PEER_CHWIDTH_40MHZ;
5591 break;
5592 case IEEE80211_STA_RX_BW_80:
5593 bw = WMI_PEER_CHWIDTH_80MHZ;
5594 break;
5595 case IEEE80211_STA_RX_BW_160:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005596 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005597 sta->bandwidth, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005598 bw = WMI_PEER_CHWIDTH_20MHZ;
5599 break;
5600 }
5601
5602 arsta->bw = bw;
5603 }
5604
5605 if (changed & IEEE80211_RC_NSS_CHANGED)
5606 arsta->nss = sta->rx_nss;
5607
5608 if (changed & IEEE80211_RC_SMPS_CHANGED) {
5609 smps = WMI_PEER_SMPS_PS_NONE;
5610
5611 switch (sta->smps_mode) {
5612 case IEEE80211_SMPS_AUTOMATIC:
5613 case IEEE80211_SMPS_OFF:
5614 smps = WMI_PEER_SMPS_PS_NONE;
5615 break;
5616 case IEEE80211_SMPS_STATIC:
5617 smps = WMI_PEER_SMPS_STATIC;
5618 break;
5619 case IEEE80211_SMPS_DYNAMIC:
5620 smps = WMI_PEER_SMPS_DYNAMIC;
5621 break;
5622 case IEEE80211_SMPS_NUM_MODES:
Michal Kazior7aa7a722014-08-25 12:09:38 +02005623 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
Kalle Valobe6546f2014-03-25 14:18:51 +02005624 sta->smps_mode, sta->addr);
Michal Kazior9797feb2014-02-14 14:49:48 +01005625 smps = WMI_PEER_SMPS_PS_NONE;
5626 break;
5627 }
5628
5629 arsta->smps = smps;
5630 }
5631
Michal Kazior9797feb2014-02-14 14:49:48 +01005632 arsta->changed |= changed;
5633
5634 spin_unlock_bh(&ar->data_lock);
5635
5636 ieee80211_queue_work(hw, &arsta->update_wk);
5637}
5638
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02005639static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
5640{
5641 /*
5642 * FIXME: Return 0 for time being. Need to figure out whether FW
5643 * has the API to fetch 64-bit local TSF
5644 */
5645
5646 return 0;
5647}
5648
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005649static int ath10k_ampdu_action(struct ieee80211_hw *hw,
5650 struct ieee80211_vif *vif,
5651 enum ieee80211_ampdu_mlme_action action,
5652 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
5653 u8 buf_size)
5654{
Michal Kazior7aa7a722014-08-25 12:09:38 +02005655 struct ath10k *ar = hw->priv;
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005656 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5657
Michal Kazior7aa7a722014-08-25 12:09:38 +02005658 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 +02005659 arvif->vdev_id, sta->addr, tid, action);
5660
5661 switch (action) {
5662 case IEEE80211_AMPDU_RX_START:
5663 case IEEE80211_AMPDU_RX_STOP:
5664 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
5665 * creation/removal. Do we need to verify this?
5666 */
5667 return 0;
5668 case IEEE80211_AMPDU_TX_START:
5669 case IEEE80211_AMPDU_TX_STOP_CONT:
5670 case IEEE80211_AMPDU_TX_STOP_FLUSH:
5671 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
5672 case IEEE80211_AMPDU_TX_OPERATIONAL:
5673 /* Firmware offloads Tx aggregation entirely so deny mac80211
5674 * Tx aggregation requests.
5675 */
5676 return -EOPNOTSUPP;
5677 }
5678
5679 return -EINVAL;
5680}
5681
Kalle Valo5e3dd152013-06-12 20:52:10 +03005682static const struct ieee80211_ops ath10k_ops = {
5683 .tx = ath10k_tx,
5684 .start = ath10k_start,
5685 .stop = ath10k_stop,
5686 .config = ath10k_config,
5687 .add_interface = ath10k_add_interface,
5688 .remove_interface = ath10k_remove_interface,
5689 .configure_filter = ath10k_configure_filter,
5690 .bss_info_changed = ath10k_bss_info_changed,
5691 .hw_scan = ath10k_hw_scan,
5692 .cancel_hw_scan = ath10k_cancel_hw_scan,
5693 .set_key = ath10k_set_key,
SenthilKumar Jegadeesan627613f2015-01-29 13:50:38 +02005694 .set_default_unicast_key = ath10k_set_default_unicast_key,
Kalle Valo5e3dd152013-06-12 20:52:10 +03005695 .sta_state = ath10k_sta_state,
5696 .conf_tx = ath10k_conf_tx,
5697 .remain_on_channel = ath10k_remain_on_channel,
5698 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
5699 .set_rts_threshold = ath10k_set_rts_threshold,
Kalle Valo5e3dd152013-06-12 20:52:10 +03005700 .flush = ath10k_flush,
5701 .tx_last_beacon = ath10k_tx_last_beacon,
Ben Greear46acf7b2014-05-16 17:15:38 +03005702 .set_antenna = ath10k_set_antenna,
5703 .get_antenna = ath10k_get_antenna,
Eliad Pellercf2c92d2014-11-04 11:43:54 +02005704 .reconfig_complete = ath10k_reconfig_complete,
Michal Kazior2e1dea42013-07-31 10:32:40 +02005705 .get_survey = ath10k_get_survey,
Janusz Dziedzic51ab1a02014-01-08 09:08:33 +01005706 .set_bitrate_mask = ath10k_set_bitrate_mask,
Michal Kazior9797feb2014-02-14 14:49:48 +01005707 .sta_rc_update = ath10k_sta_rc_update,
Chun-Yeow Yeoh26ebbcc2014-02-25 09:29:54 +02005708 .get_tsf = ath10k_get_tsf,
Michal Kazioraa5b4fb2014-07-23 12:20:33 +02005709 .ampdu_action = ath10k_ampdu_action,
Ben Greear6cddcc72014-09-29 14:41:46 +03005710 .get_et_sset_count = ath10k_debug_get_et_sset_count,
5711 .get_et_stats = ath10k_debug_get_et_stats,
5712 .get_et_strings = ath10k_debug_get_et_strings,
Kalle Valo43d2a302014-09-10 18:23:30 +03005713
5714 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
5715
Michal Kazior8cd13ca2013-07-16 09:38:54 +02005716#ifdef CONFIG_PM
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +02005717 .suspend = ath10k_wow_op_suspend,
5718 .resume = ath10k_wow_op_resume,
Michal Kazior8cd13ca2013-07-16 09:38:54 +02005719#endif
Rajkumar Manoharanf5045982015-01-12 14:07:27 +02005720#ifdef CONFIG_MAC80211_DEBUGFS
5721 .sta_add_debugfs = ath10k_sta_add_debugfs,
5722#endif
Kalle Valo5e3dd152013-06-12 20:52:10 +03005723};
5724
Kalle Valo5e3dd152013-06-12 20:52:10 +03005725#define CHAN2G(_channel, _freq, _flags) { \
5726 .band = IEEE80211_BAND_2GHZ, \
5727 .hw_value = (_channel), \
5728 .center_freq = (_freq), \
5729 .flags = (_flags), \
5730 .max_antenna_gain = 0, \
5731 .max_power = 30, \
5732}
5733
5734#define CHAN5G(_channel, _freq, _flags) { \
5735 .band = IEEE80211_BAND_5GHZ, \
5736 .hw_value = (_channel), \
5737 .center_freq = (_freq), \
5738 .flags = (_flags), \
5739 .max_antenna_gain = 0, \
5740 .max_power = 30, \
5741}
5742
5743static const struct ieee80211_channel ath10k_2ghz_channels[] = {
5744 CHAN2G(1, 2412, 0),
5745 CHAN2G(2, 2417, 0),
5746 CHAN2G(3, 2422, 0),
5747 CHAN2G(4, 2427, 0),
5748 CHAN2G(5, 2432, 0),
5749 CHAN2G(6, 2437, 0),
5750 CHAN2G(7, 2442, 0),
5751 CHAN2G(8, 2447, 0),
5752 CHAN2G(9, 2452, 0),
5753 CHAN2G(10, 2457, 0),
5754 CHAN2G(11, 2462, 0),
5755 CHAN2G(12, 2467, 0),
5756 CHAN2G(13, 2472, 0),
5757 CHAN2G(14, 2484, 0),
5758};
5759
5760static const struct ieee80211_channel ath10k_5ghz_channels[] = {
Michal Kazior429ff562013-06-26 08:54:54 +02005761 CHAN5G(36, 5180, 0),
5762 CHAN5G(40, 5200, 0),
5763 CHAN5G(44, 5220, 0),
5764 CHAN5G(48, 5240, 0),
5765 CHAN5G(52, 5260, 0),
5766 CHAN5G(56, 5280, 0),
5767 CHAN5G(60, 5300, 0),
5768 CHAN5G(64, 5320, 0),
5769 CHAN5G(100, 5500, 0),
5770 CHAN5G(104, 5520, 0),
5771 CHAN5G(108, 5540, 0),
5772 CHAN5G(112, 5560, 0),
5773 CHAN5G(116, 5580, 0),
5774 CHAN5G(120, 5600, 0),
5775 CHAN5G(124, 5620, 0),
5776 CHAN5G(128, 5640, 0),
5777 CHAN5G(132, 5660, 0),
5778 CHAN5G(136, 5680, 0),
5779 CHAN5G(140, 5700, 0),
Peter Oh4a7898f2015-03-18 11:39:18 -07005780 CHAN5G(144, 5720, 0),
Michal Kazior429ff562013-06-26 08:54:54 +02005781 CHAN5G(149, 5745, 0),
5782 CHAN5G(153, 5765, 0),
5783 CHAN5G(157, 5785, 0),
5784 CHAN5G(161, 5805, 0),
5785 CHAN5G(165, 5825, 0),
Kalle Valo5e3dd152013-06-12 20:52:10 +03005786};
5787
Michal Kaziore7b54192014-08-07 11:03:27 +02005788struct ath10k *ath10k_mac_create(size_t priv_size)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005789{
5790 struct ieee80211_hw *hw;
5791 struct ath10k *ar;
5792
Michal Kaziore7b54192014-08-07 11:03:27 +02005793 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005794 if (!hw)
5795 return NULL;
5796
5797 ar = hw->priv;
5798 ar->hw = hw;
5799
5800 return ar;
5801}
5802
5803void ath10k_mac_destroy(struct ath10k *ar)
5804{
5805 ieee80211_free_hw(ar->hw);
5806}
5807
5808static const struct ieee80211_iface_limit ath10k_if_limits[] = {
5809 {
5810 .max = 8,
5811 .types = BIT(NL80211_IFTYPE_STATION)
5812 | BIT(NL80211_IFTYPE_P2P_CLIENT)
Michal Kaziord531cb82013-07-31 10:55:13 +02005813 },
5814 {
5815 .max = 3,
5816 .types = BIT(NL80211_IFTYPE_P2P_GO)
5817 },
5818 {
Michal Kazior75d2bd42014-12-12 12:41:39 +01005819 .max = 1,
5820 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
5821 },
5822 {
Michal Kaziord531cb82013-07-31 10:55:13 +02005823 .max = 7,
5824 .types = BIT(NL80211_IFTYPE_AP)
5825 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03005826};
5827
Bartosz Markowskif2595092013-12-10 16:20:39 +01005828static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005829 {
5830 .max = 8,
5831 .types = BIT(NL80211_IFTYPE_AP)
5832 },
5833};
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005834
5835static const struct ieee80211_iface_combination ath10k_if_comb[] = {
5836 {
5837 .limits = ath10k_if_limits,
5838 .n_limits = ARRAY_SIZE(ath10k_if_limits),
5839 .max_interfaces = 8,
5840 .num_different_channels = 1,
5841 .beacon_int_infra_match = true,
5842 },
Bartosz Markowskif2595092013-12-10 16:20:39 +01005843};
5844
5845static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005846 {
Bartosz Markowskif2595092013-12-10 16:20:39 +01005847 .limits = ath10k_10x_if_limits,
5848 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005849 .max_interfaces = 8,
5850 .num_different_channels = 1,
5851 .beacon_int_infra_match = true,
Bartosz Markowskif2595092013-12-10 16:20:39 +01005852#ifdef CONFIG_ATH10K_DFS_CERTIFIED
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005853 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
5854 BIT(NL80211_CHAN_WIDTH_20) |
5855 BIT(NL80211_CHAN_WIDTH_40) |
5856 BIT(NL80211_CHAN_WIDTH_80),
Marek Puzyniake8a50f82013-11-20 09:59:47 +02005857#endif
Bartosz Markowskif2595092013-12-10 16:20:39 +01005858 },
Kalle Valo5e3dd152013-06-12 20:52:10 +03005859};
5860
5861static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
5862{
5863 struct ieee80211_sta_vht_cap vht_cap = {0};
5864 u16 mcs_map;
Michal Kaziorbc657a362015-02-26 11:11:22 +01005865 u32 val;
Michal Kazior8865bee42013-07-24 12:36:46 +02005866 int i;
Kalle Valo5e3dd152013-06-12 20:52:10 +03005867
5868 vht_cap.vht_supported = 1;
5869 vht_cap.cap = ar->vht_cap_info;
5870
Michal Kaziorbc657a362015-02-26 11:11:22 +01005871 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
5872 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
5873 val = ar->num_rf_chains - 1;
5874 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
5875 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
5876
5877 vht_cap.cap |= val;
5878 }
5879
5880 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
5881 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
5882 val = ar->num_rf_chains - 1;
5883 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
5884 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
5885
5886 vht_cap.cap |= val;
5887 }
5888
Michal Kazior8865bee42013-07-24 12:36:46 +02005889 mcs_map = 0;
5890 for (i = 0; i < 8; i++) {
5891 if (i < ar->num_rf_chains)
5892 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
5893 else
5894 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
5895 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03005896
5897 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
5898 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
5899
5900 return vht_cap;
5901}
5902
5903static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
5904{
5905 int i;
5906 struct ieee80211_sta_ht_cap ht_cap = {0};
5907
5908 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
5909 return ht_cap;
5910
5911 ht_cap.ht_supported = 1;
5912 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
5913 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
5914 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
5915 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
5916 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
5917
5918 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
5919 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
5920
5921 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
5922 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
5923
5924 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
5925 u32 smps;
5926
5927 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
5928 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
5929
5930 ht_cap.cap |= smps;
5931 }
5932
5933 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
5934 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
5935
5936 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
5937 u32 stbc;
5938
5939 stbc = ar->ht_cap_info;
5940 stbc &= WMI_HT_CAP_RX_STBC;
5941 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
5942 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
5943 stbc &= IEEE80211_HT_CAP_RX_STBC;
5944
5945 ht_cap.cap |= stbc;
5946 }
5947
5948 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
5949 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
5950
5951 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
5952 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
5953
5954 /* max AMSDU is implicitly taken from vht_cap_info */
5955 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
5956 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
5957
Michal Kazior8865bee42013-07-24 12:36:46 +02005958 for (i = 0; i < ar->num_rf_chains; i++)
Kalle Valo5e3dd152013-06-12 20:52:10 +03005959 ht_cap.mcs.rx_mask[i] = 0xFF;
5960
5961 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
5962
5963 return ht_cap;
5964}
5965
Kalle Valo5e3dd152013-06-12 20:52:10 +03005966static void ath10k_get_arvif_iter(void *data, u8 *mac,
5967 struct ieee80211_vif *vif)
5968{
5969 struct ath10k_vif_iter *arvif_iter = data;
5970 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5971
5972 if (arvif->vdev_id == arvif_iter->vdev_id)
5973 arvif_iter->arvif = arvif;
5974}
5975
5976struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
5977{
5978 struct ath10k_vif_iter arvif_iter;
5979 u32 flags;
5980
5981 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
5982 arvif_iter.vdev_id = vdev_id;
5983
5984 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
5985 ieee80211_iterate_active_interfaces_atomic(ar->hw,
5986 flags,
5987 ath10k_get_arvif_iter,
5988 &arvif_iter);
5989 if (!arvif_iter.arvif) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02005990 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
Kalle Valo5e3dd152013-06-12 20:52:10 +03005991 return NULL;
5992 }
5993
5994 return arvif_iter.arvif;
5995}
5996
5997int ath10k_mac_register(struct ath10k *ar)
5998{
Johannes Berg3cb10942015-01-22 21:38:45 +01005999 static const u32 cipher_suites[] = {
6000 WLAN_CIPHER_SUITE_WEP40,
6001 WLAN_CIPHER_SUITE_WEP104,
6002 WLAN_CIPHER_SUITE_TKIP,
6003 WLAN_CIPHER_SUITE_CCMP,
6004 WLAN_CIPHER_SUITE_AES_CMAC,
6005 };
Kalle Valo5e3dd152013-06-12 20:52:10 +03006006 struct ieee80211_supported_band *band;
6007 struct ieee80211_sta_vht_cap vht_cap;
6008 struct ieee80211_sta_ht_cap ht_cap;
6009 void *channels;
6010 int ret;
6011
6012 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
6013
6014 SET_IEEE80211_DEV(ar->hw, ar->dev);
6015
6016 ht_cap = ath10k_get_ht_cap(ar);
6017 vht_cap = ath10k_create_vht_cap(ar);
6018
6019 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
6020 channels = kmemdup(ath10k_2ghz_channels,
6021 sizeof(ath10k_2ghz_channels),
6022 GFP_KERNEL);
Michal Kaziord6015b22013-07-22 14:13:30 +02006023 if (!channels) {
6024 ret = -ENOMEM;
6025 goto err_free;
6026 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03006027
6028 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
6029 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
6030 band->channels = channels;
6031 band->n_bitrates = ath10k_g_rates_size;
6032 band->bitrates = ath10k_g_rates;
6033 band->ht_cap = ht_cap;
6034
Yanbo Lid68bb122015-01-23 08:18:20 +08006035 /* Enable the VHT support at 2.4 GHz */
6036 band->vht_cap = vht_cap;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006037
6038 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
6039 }
6040
6041 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
6042 channels = kmemdup(ath10k_5ghz_channels,
6043 sizeof(ath10k_5ghz_channels),
6044 GFP_KERNEL);
6045 if (!channels) {
Michal Kaziord6015b22013-07-22 14:13:30 +02006046 ret = -ENOMEM;
6047 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006048 }
6049
6050 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
6051 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
6052 band->channels = channels;
6053 band->n_bitrates = ath10k_a_rates_size;
6054 band->bitrates = ath10k_a_rates;
6055 band->ht_cap = ht_cap;
6056 band->vht_cap = vht_cap;
6057 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
6058 }
6059
6060 ar->hw->wiphy->interface_modes =
6061 BIT(NL80211_IFTYPE_STATION) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01006062 BIT(NL80211_IFTYPE_AP);
6063
Ben Greear46acf7b2014-05-16 17:15:38 +03006064 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
6065 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
6066
Bartosz Markowskid3541812013-12-10 16:20:40 +01006067 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
6068 ar->hw->wiphy->interface_modes |=
Michal Kazior75d2bd42014-12-12 12:41:39 +01006069 BIT(NL80211_IFTYPE_P2P_DEVICE) |
Bartosz Markowskid3541812013-12-10 16:20:40 +01006070 BIT(NL80211_IFTYPE_P2P_CLIENT) |
6071 BIT(NL80211_IFTYPE_P2P_GO);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006072
6073 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
6074 IEEE80211_HW_SUPPORTS_PS |
6075 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
Kalle Valo5e3dd152013-06-12 20:52:10 +03006076 IEEE80211_HW_MFP_CAPABLE |
6077 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
6078 IEEE80211_HW_HAS_RATE_CONTROL |
Janusz Dziedzic2f0f1122014-02-26 18:42:09 +02006079 IEEE80211_HW_AP_LINK_PS |
Johannes Berg3cb10942015-01-22 21:38:45 +01006080 IEEE80211_HW_SPECTRUM_MGMT |
Michal Kaziorcc9904e2015-03-10 16:22:01 +02006081 IEEE80211_HW_SW_CRYPTO_CONTROL |
6082 IEEE80211_HW_CONNECTION_MONITOR;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006083
Eliad Peller0d8614b2014-09-10 14:07:36 +03006084 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
6085
Kalle Valo5e3dd152013-06-12 20:52:10 +03006086 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
Eliad Peller0d8614b2014-09-10 14:07:36 +03006087 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006088
6089 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
6090 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
6091 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
6092 }
6093
6094 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
6095 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
6096
6097 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
Michal Kazior9797feb2014-02-14 14:49:48 +01006098 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
Kalle Valo5e3dd152013-06-12 20:52:10 +03006099
Kalle Valo5e3dd152013-06-12 20:52:10 +03006100 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
6101
Michal Kaziorfbb8f1b2015-01-13 16:30:12 +02006102 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
6103 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
6104
6105 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
6106 * that userspace (e.g. wpa_supplicant/hostapd) can generate
6107 * correct Probe Responses. This is more of a hack advert..
6108 */
6109 ar->hw->wiphy->probe_resp_offload |=
6110 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
6111 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
6112 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
6113 }
6114
Marek Puzyniak75d85fd2015-03-30 09:51:53 +03006115 if (test_bit(WMI_SERVICE_TDLS, ar->wmi.svc_map))
6116 ar->hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
6117
Kalle Valo5e3dd152013-06-12 20:52:10 +03006118 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Michal Kaziorc2df44b2014-01-23 11:38:26 +01006119 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006120 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
6121
6122 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
Rajkumar Manoharan78157a12014-11-17 16:44:15 +02006123 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
6124
Janusz.Dziedzic@tieto.com37a0b392015-03-12 13:11:41 +01006125 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
6126
Janusz Dziedzic5fd3ac32015-03-23 17:32:53 +02006127 ret = ath10k_wow_init(ar);
6128 if (ret) {
6129 ath10k_warn(ar, "failed to init wow: %d\n", ret);
6130 goto err_free;
6131 }
6132
Kalle Valo5e3dd152013-06-12 20:52:10 +03006133 /*
6134 * on LL hardware queues are managed entirely by the FW
6135 * so we only advertise to mac we can do the queues thing
6136 */
6137 ar->hw->queues = 4;
6138
Kalle Valo5cc7caf2014-12-17 12:20:54 +02006139 switch (ar->wmi.op_version) {
6140 case ATH10K_FW_WMI_OP_VERSION_MAIN:
6141 case ATH10K_FW_WMI_OP_VERSION_TLV:
Bartosz Markowskif2595092013-12-10 16:20:39 +01006142 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
6143 ar->hw->wiphy->n_iface_combinations =
6144 ARRAY_SIZE(ath10k_if_comb);
Michal Kaziorcf850d12014-07-24 20:07:00 +03006145 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
Kalle Valo5cc7caf2014-12-17 12:20:54 +02006146 break;
6147 case ATH10K_FW_WMI_OP_VERSION_10_1:
6148 case ATH10K_FW_WMI_OP_VERSION_10_2:
Rajkumar Manoharan4a16fbe2014-12-17 12:21:12 +02006149 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
Kalle Valo5cc7caf2014-12-17 12:20:54 +02006150 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
6151 ar->hw->wiphy->n_iface_combinations =
6152 ARRAY_SIZE(ath10k_10x_if_comb);
6153 break;
6154 case ATH10K_FW_WMI_OP_VERSION_UNSET:
6155 case ATH10K_FW_WMI_OP_VERSION_MAX:
6156 WARN_ON(1);
6157 ret = -EINVAL;
6158 goto err_free;
Bartosz Markowskif2595092013-12-10 16:20:39 +01006159 }
Kalle Valo5e3dd152013-06-12 20:52:10 +03006160
Michal Kazior7c199992013-07-31 10:47:57 +02006161 ar->hw->netdev_features = NETIF_F_HW_CSUM;
6162
Janusz Dziedzic9702c682013-11-20 09:59:41 +02006163 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
6164 /* Init ath dfs pattern detector */
6165 ar->ath_common.debug_mask = ATH_DBG_DFS;
6166 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
6167 NL80211_DFS_UNSET);
6168
6169 if (!ar->dfs_detector)
Michal Kazior7aa7a722014-08-25 12:09:38 +02006170 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
Janusz Dziedzic9702c682013-11-20 09:59:41 +02006171 }
6172
Kalle Valo5e3dd152013-06-12 20:52:10 +03006173 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
6174 ath10k_reg_notifier);
6175 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02006176 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02006177 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006178 }
6179
Johannes Berg3cb10942015-01-22 21:38:45 +01006180 ar->hw->wiphy->cipher_suites = cipher_suites;
6181 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
6182
Kalle Valo5e3dd152013-06-12 20:52:10 +03006183 ret = ieee80211_register_hw(ar->hw);
6184 if (ret) {
Michal Kazior7aa7a722014-08-25 12:09:38 +02006185 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
Michal Kaziord6015b22013-07-22 14:13:30 +02006186 goto err_free;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006187 }
6188
6189 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
6190 ret = regulatory_hint(ar->hw->wiphy,
6191 ar->ath_common.regulatory.alpha2);
6192 if (ret)
Michal Kaziord6015b22013-07-22 14:13:30 +02006193 goto err_unregister;
Kalle Valo5e3dd152013-06-12 20:52:10 +03006194 }
6195
6196 return 0;
Michal Kaziord6015b22013-07-22 14:13:30 +02006197
6198err_unregister:
Kalle Valo5e3dd152013-06-12 20:52:10 +03006199 ieee80211_unregister_hw(ar->hw);
Michal Kaziord6015b22013-07-22 14:13:30 +02006200err_free:
6201 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
6202 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
6203
Kalle Valo5e3dd152013-06-12 20:52:10 +03006204 return ret;
6205}
6206
6207void ath10k_mac_unregister(struct ath10k *ar)
6208{
6209 ieee80211_unregister_hw(ar->hw);
6210
Janusz Dziedzic9702c682013-11-20 09:59:41 +02006211 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
6212 ar->dfs_detector->exit(ar->dfs_detector);
6213
Kalle Valo5e3dd152013-06-12 20:52:10 +03006214 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
6215 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
6216
6217 SET_IEEE80211_DEV(ar->hw, NULL);
6218}